Kannel: Open Source WAP and SMS gateway  svn-r5335
test_urltrans.c File Reference
#include <stdlib.h>
#include <unistd.h>
#include "gwlib/gwlib.h"
#include "gw/urltrans.h"

Go to the source code of this file.

Functions

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

Function Documentation

◆ help()

static void help ( void  )
static

Definition at line 69 of file test_urltrans.c.

References info().

Referenced by main().

69  {
70  info(0, "Usage: test_urltrans [-r repeats] foo.smsconf pattern ...\n"
71  "where -r means the number of times the test should be\n"
72  "repeated.");
73 }
void info(int err, const char *fmt,...)
Definition: log.c:672

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 75 of file test_urltrans.c.

References cfg, cfg_create(), cfg_destroy(), cfg_read(), error(), getopt(), gwlib_init(), gwlib_shutdown(), help(), info(), msg, msg_create, msg_destroy(), name, octstr_create, octstr_destroy(), optarg, optind, panic, urltrans_add_cfg(), urltrans_create(), urltrans_destroy(), urltrans_find(), and urltrans_type().

75  {
76  int i, opt;
77  long repeats;
78  URLTranslationList *list;
79  URLTranslation *t;
80  Cfg *cfg;
81  Octstr *name;
82 
83  gwlib_init();
84 
85  repeats = 1;
86 
87  while ((opt = getopt(argc, argv, "hr:")) != EOF) {
88  switch (opt) {
89  case 'r':
90  repeats = atoi(optarg);
91  break;
92 
93  case 'h':
94  help();
95  exit(0);
96 
97  case '?':
98  default:
99  error(0, "Invalid option %c", opt);
100  help();
101  panic(0, "Stopping.");
102  }
103  }
104 
105  if (optind + 1 >= argc) {
106  error(0, "Missing arguments.");
107  help();
108  panic(0, "Stopping.");
109  }
110  name = octstr_create(argv[optind]);
111  cfg = cfg_create(name);
113  if (cfg_read(cfg) == -1)
114  panic(0, "Couldn't read configuration file.");
115 
116  list = urltrans_create();
117  if (urltrans_add_cfg(list, cfg) == -1)
118  panic(0, "Error parsing configuration.");
119 
120  while (repeats-- > 0) {
121  for (i = optind + 1; i < argc; ++i) {
122  Msg *msg = msg_create(sms);
123  msg->sms.msgdata = octstr_create(argv[i]);
124  t = urltrans_find(list, msg);
125  info(0, "type = %d", urltrans_type(t));
126  msg_destroy(msg);
127  }
128  }
129  urltrans_destroy(list);
130  cfg_destroy(cfg);
131 
132  gwlib_shutdown();
133 
134  return 0;
135 }
int urltrans_add_cfg(URLTranslationList *trans, Cfg *cfg)
Definition: urltrans.c:230
void error(int err, const char *fmt,...)
Definition: log.c:648
void info(int err, const char *fmt,...)
Definition: log.c:672
URLTranslation * urltrans_find(URLTranslationList *trans, Msg *msg)
Definition: urltrans.c:257
int optind
Definition: attgetopt.c:80
#define msg_create(type)
Definition: msg.h:136
static Cfg * cfg
Definition: opensmppbox.c:95
Cfg * cfg_create(Octstr *filename)
Definition: cfg.c:318
int cfg_read(Cfg *cfg)
Definition: cfg.c:452
int getopt(int argc, char **argv, char *opts)
Definition: attgetopt.c:84
Definition: msg.h:79
Definition: cfg.c:164
void cfg_destroy(Cfg *cfg)
Definition: cfg.c:331
void msg_destroy(Msg *msg)
Definition: msg.c:132
char * name
Definition: smsc_cimd2.c:212
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
#define octstr_create(cstr)
Definition: octstr.h:125
int urltrans_type(URLTranslation *t)
Definition: urltrans.c:795
static void help(void)
Definition: test_urltrans.c:69
Definition: octstr.c:118
URLTranslationList * urltrans_create(void)
Definition: urltrans.c:184
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
void urltrans_destroy(URLTranslationList *trans)
Definition: urltrans.c:196
static XMLRPCDocument * msg
Definition: test_xmlrpc.c:86
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.