Kannel: Open Source WAP and SMS gateway  $Revision: 5037 $
test_boxc.c
Go to the documentation of this file.
1 /* ====================================================================
2  * The Kannel Software License, Version 1.0
3  *
4  * Copyright (c) 2001-2016 Kannel Group
5  * Copyright (c) 1998-2001 WapIT Ltd.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Kannel Group (http://www.kannel.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Kannel" and "Kannel Group" must not be used to
28  * endorse or promote products derived from this software without
29  * prior written permission. For written permission, please
30  * contact org@kannel.org.
31  *
32  * 5. Products derived from this software may not be called "Kannel",
33  * nor may "Kannel" appear in their name, without prior written
34  * permission of the Kannel Group.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE KANNEL GROUP OR ITS CONTRIBUTORS
40  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
41  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
42  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
43  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
44  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
45  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
46  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
47  * ====================================================================
48  *
49  * This software consists of voluntary contributions made by many
50  * individuals on behalf of the Kannel Group. For more information on
51  * the Kannel Group, please see <http://www.kannel.org/>.
52  *
53  * Portions of this software are based upon software originally written at
54  * WapIT Ltd., Helsinki, Finland for the Kannel project.
55  */
56 
57 /*
58  * test_boxc.c - test boxc connection module of bearerbox
59  *
60  * Stipe Tolj <stolj@wapme.de>
61  */
62 
63 #include "gwlib/gwlib.h"
64 #include "gw/msg.h"
65 #include "gw/shared.h"
66 
67 static void help(void)
68 {
69  info(0, "Usage: test_boxc [options] ...");
70  info(0, "where options are:");
71  info(0, "-v number");
72  info(0, " set log level for stderr logging");
73  info(0, "-h hostname");
74  info(0, " hostname where bearerbox is running (default: localhost)");
75  info(0, "-p number");
76  info(0, " port for smsbox connections on bearerbox host (default: 13001)");
77  info(0, "-c number");
78  info(0, " numer of sequential connections that are made and closed (default: 1)");
79 }
80 
81 /* global variables */
82 static unsigned long port = 13001;
83 static unsigned int no_conn = 1;
84 static Octstr *host;
85 
86 static void run_connects(void)
87 {
88  unsigned int i;
89  Msg *msg;
90 
91  for (i = 1; i <= no_conn; i++) {
92 
93  /* connect to Kannel's bearerbox */
94  connect_to_bearerbox(host, port, 0, NULL);
95 
96  /* identify ourself to bearerbox */
97  msg = msg_create(admin);
98  msg->admin.command = cmd_identify;
99  msg->admin.boxc_id = octstr_create("test-smsbox");
100  write_to_bearerbox(msg);
101 
102  /* do something, like passing MT messages */
103 
104  /* close connection and shutdown */
106  }
107 }
108 
109 int main(int argc, char **argv)
110 {
111  int opt;
112 
113  gwlib_init();
114 
115  host = octstr_create("localhost");
116 
117  while ((opt = getopt(argc, argv, "v:h:p:c:")) != EOF) {
118  switch (opt) {
119  case 'v':
121  break;
122 
123  case 'h':
124  octstr_destroy(host);
125  host = octstr_create(optarg);
126  break;
127 
128  case 'p':
129  port = atoi(optarg);
130  break;
131 
132  case 'c':
133  no_conn = atoi(optarg);
134  break;
135 
136  case '?':
137  default:
138  error(0, "Invalid option %c", opt);
139  help();
140  panic(0, "Stopping.");
141  }
142  }
143 
144  if (!optind) {
145  help();
146  exit(0);
147  }
148 
149  run_connects();
150 
151  octstr_destroy(host);
152 
153  gwlib_shutdown();
154 
155  return 0;
156 }
157 
static unsigned int no_conn
Definition: test_boxc.c:83
void error(int err, const char *fmt,...)
Definition: log.c:612
void info(int err, const char *fmt,...)
Definition: log.c:636
int main(int argc, char **argv)
Definition: test_boxc.c:109
Definition: http.c:1998
static Octstr * host
Definition: test_boxc.c:84
int optind
Definition: attgetopt.c:80
#define msg_create(type)
Definition: msg.h:136
static void help(void)
Definition: test_boxc.c:67
int getopt(int argc, char **argv, char *opts)
Definition: attgetopt.c:84
Definition: msg.h:79
void log_set_output_level(enum output_level level)
Definition: log.c:217
void connect_to_bearerbox(Octstr *host, int port, int ssl, Octstr *our_host)
Definition: shared.c:108
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:322
#define octstr_create(cstr)
Definition: octstr.h:125
void close_connection_to_bearerbox(void)
Definition: shared.c:122
void write_to_bearerbox(Msg *pmsg)
Definition: shared.c:142
Definition: octstr.c:118
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
static void run_connects(void)
Definition: test_boxc.c:86
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.