Kannel: Open Source WAP and SMS gateway  $Revision: 5037 $
test_si.c File Reference
#include <stdio.h>
#include "gwlib/gwlib.h"
#include "gw/wap_push_si_compiler.h"

Go to the source code of this file.

Functions

static void help (void)
 
int main (int argc, char **argv)
 

Variables

Octstrcharset = NULL
 
Octstrfile_name = NULL
 

Function Documentation

static void help ( void  )
static

Definition at line 71 of file test_si.c.

References info().

Referenced by main().

72 {
73  info(0, "Usage test_si [option] si_source");
74  info(0, "where options are");
75  info(0, "-h print this text");
76  info(0, "-f file output binary to the file");
77  info(0, "-c charset charset given by http");
78  info(0, "-v level set log level for stderr logging");
79 }
void info(int err, const char *fmt,...)
Definition: log.c:636
int main ( int  argc,
char **  argv 
)

Definition at line 81 of file test_si.c.

References debug(), error(), file, getopt(), gwlib_init(), gwlib_shutdown(), help(), log_set_output_level(), octstr_append(), octstr_create, octstr_destroy(), octstr_dump, octstr_format(), octstr_imm(), octstr_pretty_print(), octstr_read_file(), optarg, optind, panic, and si_compile().

82 {
83  int opt,
84  file,
85  have_charset,
86  ret;
87  FILE *fp;
88  Octstr *output,
89  *si_doc,
90  *si_binary;
91 
92  gwlib_init();
93  file = 0;
94  have_charset = 0;
95  fp = NULL;
96 
97  while ((opt = getopt(argc, argv, "hf:c:v:")) != EOF) {
98  switch (opt) {
99  case 'h':
100  help();
101  exit(1);
102  break;
103 
104  case 'f':
105  file = 1;
107  fp = fopen(optarg, "a");
108  if (fp == NULL)
109  panic(0, "Cannot open output file");
110  break;
111 
112  case 'c':
113  have_charset = 1;
115  break;
116 
117  case 'v':
119  break;
120 
121  case '?':
122  default:
123  error(0, "Invalid option %c", opt);
124  help();
125  panic(0, "Stopping");
126  break;
127  }
128  }
129 
130  if (optind >= argc) {
131  error(0, "Missing arguments");
132  help();
133  panic(0, "Stopping");
134  }
135 
136  si_doc = octstr_read_file(argv[optind]);
137  if (si_doc == NULL)
138  panic(0, "Cannot read the si document");
139 
140  if (!have_charset)
141  charset = NULL;
142  ret = si_compile(si_doc, charset, &si_binary);
143  output = octstr_format("%s", "si compiler returned %d\n", ret);
144 
145  if (ret == 0) {
146  if (fp == NULL)
147  fp = stdout;
148  octstr_append(output, octstr_imm("content being\n"));
149  octstr_append(output, si_binary);
150  }
151 
152  if (file)
153  octstr_pretty_print(fp, output);
154  else {
155  debug("test.si", 0, "si binary was");
156  octstr_dump(si_binary, 0);
157  }
158 
159  if (have_charset)
161  if (file) {
162  fclose(fp);
164  }
165 
166  octstr_destroy(si_doc);
167  octstr_destroy(si_binary);
168  octstr_destroy(output);
169  gwlib_shutdown();
170  return 0;
171 }
void error(int err, const char *fmt,...)
Definition: log.c:612
void octstr_append(Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:1502
int optind
Definition: attgetopt.c:80
int si_compile(Octstr *si_doc, Octstr *charset, Octstr **si_binary)
FILE * file
Definition: log.c:133
Octstr * charset
Definition: test_si.c:68
int getopt(int argc, char **argv, char *opts)
Definition: attgetopt.c:84
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:281
void log_set_output_level(enum output_level level)
Definition: log.c:217
#define octstr_dump(ostr, level,...)
Definition: octstr.h:564
Octstr * octstr_format(const char *fmt,...)
Definition: octstr.c:2462
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:322
#define octstr_create(cstr)
Definition: octstr.h:125
Octstr * octstr_read_file(const char *filename)
Definition: octstr.c:1546
Definition: octstr.c:118
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:690
char * optarg
Definition: attgetopt.c:82
#define panic
Definition: log.h:87
void gwlib_shutdown(void)
Definition: gwlib.c:94
void gwlib_init(void)
Definition: gwlib.c:78
int octstr_pretty_print(FILE *f, Octstr *ostr)
Definition: octstr.c:1204
static void help(void)
Definition: test_si.c:71
Octstr * file_name
Definition: test_si.c:69

Variable Documentation

Octstr* charset = NULL

Definition at line 68 of file test_si.c.

Octstr* file_name = NULL

Definition at line 69 of file test_si.c.

See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.