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

Go to the source code of this file.

Functions

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

Function Documentation

static void help ( void  )
static

Definition at line 69 of file test_pap.c.

References info().

Referenced by main().

70 {
71  info(0, "Usage test_pap [option] pap_source");
72  info(0, "where options are");
73  info(0, "-h print this text");
74  info(0, "-v level set log level for stderr logging");
75  info(0, "-l log wap event to this file");
76 }
void info(int err, const char *fmt,...)
Definition: log.c:636
int main ( int  argc,
char **  argv 
)

Definition at line 78 of file test_pap.c.

References debug(), error(), getopt(), GW_DEBUG, GW_NON_EXCL, gwlib_init(), gwlib_shutdown(), help(), log_open(), log_set_output_level(), octstr_create, octstr_destroy(), octstr_get_cstr, octstr_read_file(), optarg, optind, panic, pap_compile(), wap_event_destroy(), and wap_event_dump().

79 {
80  int opt,
81  ret;
82  Octstr *pap_doc,
83  *log_file;
84  WAPEvent *e;
85 
86  log_file = NULL;
87  gwlib_init();
88 
89  while ((opt = getopt(argc, argv, "h:v:l:")) != EOF) {
90  switch (opt) {
91  case 'h':
92  help();
93  exit(1);
94  break;
95 
96  case 'v':
98  break;
99 
100  case 'l':
101  octstr_destroy(log_file);
102  log_file = octstr_create(optarg);
103  break;
104 
105  case '?':
106  default:
107  error(0, "Invalid option %c", opt);
108  help();
109  panic(0, "Stopping");
110  break;
111  }
112  }
113 
114  if (optind >= argc) {
115  error(0, "Missing arguments");
116  help();
117  panic(0, "Stopping");
118  }
119 
120  if (log_file != NULL) {
122  octstr_destroy(log_file);
123  }
124 
125  pap_doc = octstr_read_file(argv[optind]);
126  if (pap_doc == NULL)
127  panic(0, "Cannot read the pap document");
128 
129  e = NULL;
130  ret = pap_compile(pap_doc, &e);
131 
132  if (ret < 0) {
133  debug("test.pap", 0, "Unable to compile the pap document, rc %d", ret);
134  return 1;
135  }
136 
137  debug("test.pap", 0, "Compiling successfull, wap event being:\n");
138  wap_event_dump(e);
139 
141  octstr_destroy(pap_doc);
142  gwlib_shutdown();
143  return 0;
144 }
void error(int err, const char *fmt,...)
Definition: log.c:612
int optind
Definition: attgetopt.c:80
static void help(void)
Definition: test_pap.c:69
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
void wap_event_dump(WAPEvent *event)
Definition: wap_events.c:181
int getopt(int argc, char **argv, char *opts)
Definition: attgetopt.c:84
void log_set_output_level(enum output_level level)
Definition: log.c:217
Definition: log.h:69
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
int log_open(char *filename, int level, enum excl_state excl)
Definition: log.c:339
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 pap_compile(Octstr *pap_content, WAPEvent **e)
void wap_event_destroy(WAPEvent *event)
Definition: wap_events.c:102
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.