Main Page | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

test_sl.c

Go to the documentation of this file.
00001 /* ==================================================================== 
00002  * The Kannel Software License, Version 1.0 
00003  * 
00004  * Copyright (c) 2001-2008 Kannel Group  
00005  * Copyright (c) 1998-2001 WapIT Ltd.   
00006  * All rights reserved. 
00007  * 
00008  * Redistribution and use in source and binary forms, with or without 
00009  * modification, are permitted provided that the following conditions 
00010  * are met: 
00011  * 
00012  * 1. Redistributions of source code must retain the above copyright 
00013  *    notice, this list of conditions and the following disclaimer. 
00014  * 
00015  * 2. Redistributions in binary form must reproduce the above copyright 
00016  *    notice, this list of conditions and the following disclaimer in 
00017  *    the documentation and/or other materials provided with the 
00018  *    distribution. 
00019  * 
00020  * 3. The end-user documentation included with the redistribution, 
00021  *    if any, must include the following acknowledgment: 
00022  *       "This product includes software developed by the 
00023  *        Kannel Group (http://www.kannel.org/)." 
00024  *    Alternately, this acknowledgment may appear in the software itself, 
00025  *    if and wherever such third-party acknowledgments normally appear. 
00026  * 
00027  * 4. The names "Kannel" and "Kannel Group" must not be used to 
00028  *    endorse or promote products derived from this software without 
00029  *    prior written permission. For written permission, please  
00030  *    contact org@kannel.org. 
00031  * 
00032  * 5. Products derived from this software may not be called "Kannel", 
00033  *    nor may "Kannel" appear in their name, without prior written 
00034  *    permission of the Kannel Group. 
00035  * 
00036  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 
00037  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 
00038  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
00039  * DISCLAIMED.  IN NO EVENT SHALL THE KANNEL GROUP OR ITS CONTRIBUTORS 
00040  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,  
00041  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT  
00042  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR  
00043  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,  
00044  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE  
00045  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,  
00046  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
00047  * ==================================================================== 
00048  * 
00049  * This software consists of voluntary contributions made by many 
00050  * individuals on behalf of the Kannel Group.  For more information on  
00051  * the Kannel Group, please see <http://www.kannel.org/>. 
00052  * 
00053  * Portions of this software are based upon software originally written at  
00054  * WapIT Ltd., Helsinki, Finland for the Kannel project.  
00055  */ 
00056 
00057 /*
00058  * test_sl.c: A simple program to test sl tokenizer
00059  *
00060  * By Aarno Syvänen for Wiral Ltd
00061  */
00062 
00063 #include <stdio.h>
00064 
00065 #include "gwlib/gwlib.h"
00066 #include "gw/wap_push_sl_compiler.h"
00067 
00068 Octstr *charset = NULL;
00069 Octstr *file_name = NULL;
00070 
00071 static void help (void)
00072 {
00073     info(0, "Usage test_sl [option] sl_source");
00074     info(0, "where options are");
00075     info(0, "-h print this text");
00076     info(0, "-f file output binary to the file");
00077     info(0, "-c charset charset given by http");
00078     info(0, "-v level set log level for stderr logging");
00079 }
00080 
00081 int main(int argc, char **argv)
00082 {
00083     int opt,
00084         file,
00085         have_charset,
00086         ret;
00087     FILE *fp;
00088     Octstr *output,
00089            *sl_doc,
00090            *sl_binary;
00091 
00092     gwlib_init();
00093     file = 0;
00094     have_charset = 0;
00095     fp = NULL;
00096 
00097     while ((opt = getopt(argc, argv, "hf:c:v:")) != EOF) {
00098         switch (opt) {
00099         case 'h':
00100         help();
00101             exit(1);
00102     break;
00103 
00104         case 'f':
00105         file = 1;
00106         file_name = octstr_create(optarg);
00107             fp = fopen(optarg, "a");
00108             if (fp == NULL)
00109             panic(0, "Cannot open output file");
00110     break;
00111 
00112         case 'c':
00113         have_charset = 1;
00114         charset = octstr_create(optarg);
00115     break;
00116 
00117         case 'v':
00118         log_set_output_level(atoi(optarg));
00119     break;
00120 
00121         case '?':
00122         default:
00123         error(0, "Invalid option %c", opt);
00124             help();
00125             panic(0, "Stopping");
00126     break;
00127         }
00128     }
00129 
00130     if (optind >= argc) {
00131         error(0, "Missing arguments");
00132         help();
00133         panic(0, "Stopping");
00134     }
00135 
00136     sl_doc = octstr_read_file(argv[optind]);
00137     if (sl_doc == NULL)
00138         panic(0, "Cannot read the sl document");
00139 
00140     if (!have_charset)
00141         charset = NULL;
00142     ret = sl_compile(sl_doc, charset, &sl_binary);
00143     output = octstr_format("%s", "sl compiler returned %d\n", ret);
00144 
00145     if (ret == 0) {
00146         if (fp == NULL)
00147         fp = stdout;
00148         octstr_append(output, octstr_imm("content being\n"));
00149         octstr_append(output, sl_binary);
00150     }
00151 
00152     if (file)
00153         octstr_pretty_print(fp, output);
00154     else {
00155         debug("test.sl", 0, "sl binary was");
00156         octstr_dump(sl_binary, 0);
00157     }
00158 
00159     if (have_charset)
00160         octstr_destroy(charset);
00161     if (file) {
00162         fclose(fp);
00163         octstr_destroy(file_name);
00164     }
00165     
00166     octstr_destroy(sl_doc);
00167     octstr_destroy(sl_binary);
00168     octstr_destroy(output);
00169     gwlib_shutdown();
00170     return 0;
00171 }
00172 
00173 
00174 
00175 
00176 
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.