Kannel: Open Source WAP and SMS gateway  svn-r5335
test_ota.c File Reference
#include <stdio.h>
#include "gwlib/gwlib.h"
#include "gw/ota_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

◆ help()

static void help ( void  )
static

Definition at line 71 of file test_ota.c.

References info().

Referenced by main().

72 {
73  info(0, "Usage test_ota [options] ota_source");
74  info(0, "where options are");
75  info(0, "-h - print this text");
76  info(0, "-f <file> - output binary to 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:672

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 81 of file test_ota.c.

References charset, debug(), error(), file, file_name, getopt(), gwlib_init(), gwlib_shutdown(), help(), log_set_output_level(), octstr_create, octstr_destroy(), octstr_dump, octstr_print(), octstr_read_file(), optarg, optind, ota_compile(), and panic.

82 {
83  int opt, file, have_charset, ret;
84  FILE *fp;
85  Octstr *ota_doc, *ota_binary;
86 
87  file = 0;
88  have_charset = 0;
89  fp = NULL;
90 
91  gwlib_init();
92 
93  while ((opt = getopt(argc, argv, "hf:c:v:")) != EOF) {
94  switch (opt) {
95  case 'h':
96  help();
97  exit(1);
98  break;
99 
100  case 'f':
101  file = 1;
103  fp = fopen(optarg, "a");
104  if (fp == NULL)
105  panic(0, "Cannot open output file");
106  break;
107 
108  case 'c':
109  have_charset = 1;
111  break;
112 
113  case 'v':
115  break;
116 
117  case '?':
118  default:
119  error(0, "Invalid option %c", opt);
120  help();
121  panic(0, "Stopping");
122  break;
123  }
124  }
125 
126  if (optind >= argc) {
127  error(0, "Missing arguments");
128  help();
129  panic(0, "Stopping");
130  }
131 
132  ota_doc = octstr_read_file(argv[optind]);
133  if (ota_doc == NULL)
134  panic(0, "Cannot read the ota document");
135 
136  if (!have_charset)
137  charset = NULL;
138 
139  /* run compiler */
140  ret = ota_compile(ota_doc, charset, &ota_binary);
141  debug("test.ota", 0, "ota compiler returned %d", ret);
142 
143  if (ret == 0) {
144  if (fp == NULL)
145  fp = stdout;
146 
147  if (file) {
148  octstr_print(fp, ota_binary);
149  } else {
150  debug("test.ota", 0, "ota binary was");
151  octstr_dump(ota_binary, 0);
152  }
153  }
154 
155  if (have_charset)
157  if (file) {
158  fclose(fp);
160  }
161 
162  octstr_destroy(ota_doc);
163  if (ret == 0)
164  octstr_destroy(ota_binary);
165 
166  gwlib_shutdown();
167  return 0;
168 }
void error(int err, const char *fmt,...)
Definition: log.c:648
int ota_compile(Octstr *ota_doc, Octstr *charset, Octstr **ota_binary)
Definition: ota_compiler.c:473
int optind
Definition: attgetopt.c:80
int octstr_print(FILE *f, Octstr *ostr)
Definition: octstr.c:1191
Octstr * charset
Definition: test_ota.c:68
FILE * file
Definition: log.c:169
int getopt(int argc, char **argv, char *opts)
Definition: attgetopt.c:84
void log_set_output_level(enum output_level level)
Definition: log.c:253
#define octstr_dump(ostr, level,...)
Definition: octstr.h:564
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
#define octstr_create(cstr)
Definition: octstr.h:125
static void help(void)
Definition: test_ota.c:71
Octstr * octstr_read_file(const char *filename)
Definition: octstr.c:1548
Definition: octstr.c:118
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:726
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
Octstr * file_name
Definition: test_ota.c:69

Variable Documentation

◆ charset

◆ file_name

Octstr* file_name = NULL

Definition at line 69 of file test_ota.c.

Referenced by main().

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