Kannel: Open Source WAP and SMS gateway  svn-r5335
shared.h File Reference
#include "gwlib/gwlib.h"
#include "msg.h"

Go to the source code of this file.

Macros

#define INFINITE_TIME   -1
 

Enumerations

enum  program_status { starting_up, running, shutting_down }
 

Functions

Connectionconnect_to_bearerbox_real (Octstr *host, int port, int ssl, Octstr *our_host)
 
void connect_to_bearerbox (Octstr *host, int port, int ssl, Octstr *our_host)
 
void close_connection_to_bearerbox_real (Connection *conn)
 
void close_connection_to_bearerbox (void)
 
int read_from_bearerbox_real (Connection *conn, Msg **msg, double seconds)
 
int read_from_bearerbox (Msg **msg, double seconds)
 
void write_to_bearerbox_real (Connection *conn, Msg *pmsg)
 
void write_to_bearerbox (Msg *msg)
 
int deliver_to_bearerbox_real (Connection *conn, Msg *msg)
 
int deliver_to_bearerbox (Msg *msg)
 
Octstrparse_date (Octstr *date)
 
int restart_box (char **argv)
 

Variables

enum program_status program_status
 

Macro Definition Documentation

◆ INFINITE_TIME

#define INFINITE_TIME   -1

Definition at line 73 of file shared.h.

Referenced by main(), and read_messages_from_bearerbox().

Enumeration Type Documentation

◆ program_status

Enumerator
starting_up 
running 
shutting_down 

Definition at line 79 of file shared.h.

79  {
81  running,
Definition: shared.h:81
program_status
Definition: shared.h:79

Function Documentation

◆ close_connection_to_bearerbox()

void close_connection_to_bearerbox ( void  )

Definition at line 122 of file shared.c.

References bb_conn, and close_connection_to_bearerbox_real().

Referenced by main(), and run_connects().

123 {
125  bb_conn = NULL;
126 }
void close_connection_to_bearerbox_real(Connection *conn)
Definition: shared.c:116
static Connection * bb_conn
Definition: shared.c:80

◆ close_connection_to_bearerbox_real()

void close_connection_to_bearerbox_real ( Connection conn)

Definition at line 116 of file shared.c.

References conn_destroy().

Referenced by close_connection_to_bearerbox().

117 {
118  conn_destroy(conn);
119 }
void conn_destroy(Connection *conn)
Definition: conn.c:627

◆ connect_to_bearerbox()

void connect_to_bearerbox ( Octstr host,
int  port,
int  ssl,
Octstr our_host 
)

Definition at line 108 of file shared.c.

References bb_conn, connect_to_bearerbox_real(), host, our_host, panic, and ssl.

Referenced by main(), and run_connects().

109 {
111  if (bb_conn == NULL)
112  panic(0, "Couldn't connect to the bearerbox.");
113 }
Definition: http.c:2014
Connection * connect_to_bearerbox_real(Octstr *host, int port, int ssl, Octstr *our_host)
Definition: shared.c:83
int ssl
static Octstr * host
Definition: fakesmsc.c:122
static Octstr * our_host
Definition: radius_acct.c:86
#define panic
Definition: log.h:87
static Connection * bb_conn
Definition: shared.c:80

◆ connect_to_bearerbox_real()

Connection* connect_to_bearerbox_real ( Octstr host,
int  port,
int  ssl,
Octstr our_host 
)

Definition at line 83 of file shared.c.

References conn_open_tcp(), host, info(), octstr_get_cstr, our_host, and ssl.

Referenced by connect_to_bearerbox(), run_smppbox(), run_sqlbox(), and sql_to_bearerbox().

84 {
85  Connection *conn;
86 
87 #ifdef HAVE_LIBSSL
88  if (ssl)
89  conn = conn_open_ssl(host, port, NULL, our_host);
90  /* XXX add certkeyfile to be given to conn_open_ssl */
91  else
92 #endif /* HAVE_LIBSSL */
93  conn = conn_open_tcp(host, port, our_host);
94  if (conn == NULL)
95  return NULL;
96 
97  if (ssl)
98  info(0, "Connected to bearerbox at %s port %d using SSL.",
100  else
101  info(0, "Connected to bearerbox at %s port %d.",
103 
104  return conn;
105 }
void info(int err, const char *fmt,...)
Definition: log.c:672
Definition: http.c:2014
Connection * conn_open_tcp(Octstr *host, int port, Octstr *our_host)
Definition: conn.c:496
int ssl
static Octstr * host
Definition: fakesmsc.c:122
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
static Octstr * our_host
Definition: radius_acct.c:86

◆ deliver_to_bearerbox()

int deliver_to_bearerbox ( Msg msg)

Definition at line 166 of file shared.c.

References bb_conn, deliver_to_bearerbox_real(), and msg.

Referenced by send_message().

167 {
169 }
int deliver_to_bearerbox_real(Connection *conn, Msg *msg)
Definition: shared.c:148
static XMLRPCDocument * msg
Definition: test_xmlrpc.c:86
static Connection * bb_conn
Definition: shared.c:80

◆ deliver_to_bearerbox_real()

int deliver_to_bearerbox_real ( Connection conn,
Msg msg 
)

Definition at line 148 of file shared.c.

References conn_write_withlen(), error(), msg, msg_destroy(), msg_pack(), and octstr_destroy().

Referenced by deliver_to_bearerbox().

149 {
150 
151  Octstr *pack;
152 
153  pack = msg_pack(msg);
154  if (conn_write_withlen(conn, pack) == -1) {
155  error(0, "Couldn't deliver Msg to bearerbox.");
156  octstr_destroy(pack);
157  return -1;
158  }
159 
160  octstr_destroy(pack);
161  msg_destroy(msg);
162  return 0;
163 }
void error(int err, const char *fmt,...)
Definition: log.c:648
void msg_destroy(Msg *msg)
Definition: msg.c:132
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
int conn_write_withlen(Connection *conn, Octstr *data)
Definition: conn.c:1075
Definition: octstr.c:118
Octstr * msg_pack(Msg *msg)
Definition: msg.c:181
static XMLRPCDocument * msg
Definition: test_xmlrpc.c:86

◆ parse_date()

Octstr* parse_date ( Octstr date)

Definition at line 232 of file shared.c.

References date(), error(), octstr_get_char(), octstr_parse_long(), and warning().

Referenced by parse_progress_note_value(), parse_push_message_value(), parse_push_response_value(), and tokenize_date().

233 {
234  long date_value;
235 
236  if (octstr_get_char(date, 4) != '-')
237  goto error;
238  if (octstr_get_char(date, 7) != '-')
239  goto error;
240  if (octstr_get_char(date, 10) != 'T')
241  goto error;
242  if (octstr_get_char(date, 13) != ':')
243  goto error;
244  if (octstr_get_char(date, 16) != ':')
245  goto error;
246  if (octstr_get_char(date, 19) != 'Z')
247  goto error;
248 
249  if (octstr_parse_long(&date_value, date, 0, 10) < 0)
250  goto error;
251  if (octstr_parse_long(&date_value, date, 5, 10) < 0)
252  goto error;
253  if (date_value < 1 || date_value > 12)
254  goto error;
255  if (octstr_parse_long(&date_value, date, 8, 10) < 0)
256  goto error;
257  if (date_value < 1 || date_value > 31)
258  goto error;
259  if (octstr_parse_long(&date_value, date, 11, 10) < 0)
260  goto error;
261  if (date_value < 0 || date_value > 23)
262  goto error;
263  if (octstr_parse_long(&date_value, date, 14, 10) < 0)
264  goto error;
265  if (date_value < 0 || date_value > 59)
266  goto error;
267  if (date_value < 0 || date_value > 59)
268  goto error;
269  if (octstr_parse_long(&date_value, date, 17, 10) < 0)
270  goto error;
271 
272  return date;
273 
274 error:
275  warning(0, "parse_date: not an ISO date");
276  return NULL;
277 }
void error(int err, const char *fmt,...)
Definition: log.c:648
void warning(int err, const char *fmt,...)
Definition: log.c:660
long octstr_parse_long(long *nump, Octstr *ostr, long pos, int base)
Definition: octstr.c:749
static int date(int hex)
int octstr_get_char(const Octstr *ostr, long pos)
Definition: octstr.c:406

◆ read_from_bearerbox()

int read_from_bearerbox ( Msg **  msg,
double  seconds 
)

Definition at line 220 of file shared.c.

References bb_conn, msg, and read_from_bearerbox_real().

Referenced by main(), and read_messages_from_bearerbox().

221 {
222  return read_from_bearerbox_real(bb_conn, msg, seconds);
223 }
int read_from_bearerbox_real(Connection *conn, Msg **msg, double seconds)
Definition: shared.c:172
static XMLRPCDocument * msg
Definition: test_xmlrpc.c:86
static Connection * bb_conn
Definition: shared.c:80

◆ read_from_bearerbox_real()

int read_from_bearerbox_real ( Connection conn,
Msg **  msg,
double  seconds 
)

Definition at line 172 of file shared.c.

References conn_eof(), conn_error(), conn_read_withlen(), conn_wait(), error(), msg, msg_unpack, octstr_destroy(), and shutting_down.

Referenced by read_from_bearerbox(), and read_from_box().

173 {
174  int ret;
175  Octstr *pack;
176 
177  pack = NULL;
178  *msg = NULL;
179  while (program_status != shutting_down) {
180  pack = conn_read_withlen(conn);
181  gw_claim_area(pack);
182  if (pack != NULL)
183  break;
184 
185  if (conn_error(conn)) {
186  error(0, "Error reading from bearerbox, disconnecting.");
187  return -1;
188  }
189  if (conn_eof(conn)) {
190  error(0, "Connection closed by the bearerbox.");
191  return -1;
192  }
193 
194  ret = conn_wait(conn, seconds);
195  if (ret < 0) {
196  error(0, "Connection to bearerbox broke.");
197  return -1;
198  }
199  else if (ret == 1) {
200  /* debug("gwlib.gwlib", 0, "Connection to bearerbox timed out after %.2f seconds.", seconds); */
201  return 1;
202  }
203  }
204 
205  if (pack == NULL)
206  return -1;
207 
208  *msg = msg_unpack(pack);
209  octstr_destroy(pack);
210 
211  if (*msg == NULL) {
212  error(0, "Failed to unpack data!");
213  return -1;
214  }
215 
216  return 0;
217 }
void error(int err, const char *fmt,...)
Definition: log.c:648
#define msg_unpack(os)
Definition: msg.h:183
program_status
Definition: shared.h:79
int conn_eof(Connection *conn)
Definition: conn.c:705
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
Octstr * conn_read_withlen(Connection *conn)
Definition: conn.c:1169
Definition: octstr.c:118
int conn_wait(Connection *conn, double seconds)
Definition: conn.c:904
int conn_error(Connection *conn)
Definition: conn.c:716
static XMLRPCDocument * msg
Definition: test_xmlrpc.c:86

◆ restart_box()

int restart_box ( char **  argv)

Definition at line 279 of file shared.c.

References error(), and gwthread_sleep().

Referenced by main().

280 {
281  int rc;
282 
283  if (!(rc = fork())) {
284  /*
285  * Sleep a while in order to get father
286  * process time to cleanup things
287  */
288  gwthread_sleep(1.0);
289  if (execvp(argv[0],argv) == -1)
290  error(errno, "Unable to start new process.");
291  } else if (rc == -1)
292  error(errno, "Could not restart, exiting...");
293 
294  return rc == -1 ? -1 : 0;
295 }
void error(int err, const char *fmt,...)
Definition: log.c:648
void gwthread_sleep(double seconds)

◆ write_to_bearerbox()

void write_to_bearerbox ( Msg msg)

Definition at line 142 of file shared.c.

References bb_conn, and write_to_bearerbox_real().

Referenced by dispatch_datagram(), identify_to_bearerbox(), main(), obey_request_thread(), run_connects(), and send_message().

143 {
145 }
void write_to_bearerbox_real(Connection *conn, Msg *pmsg)
Definition: shared.c:129
static Connection * bb_conn
Definition: shared.c:80

◆ write_to_bearerbox_real()

void write_to_bearerbox_real ( Connection conn,
Msg pmsg 
)

Definition at line 129 of file shared.c.

References conn_write_withlen(), error(), msg_destroy(), msg_pack(), and octstr_destroy().

Referenced by send_msg(), and write_to_bearerbox().

130 {
131  Octstr *pack;
132 
133  pack = msg_pack(pmsg);
134  if (conn_write_withlen(conn, pack) == -1)
135  error(0, "Couldn't write Msg to bearerbox.");
136 
137  msg_destroy(pmsg);
138  octstr_destroy(pack);
139 }
void error(int err, const char *fmt,...)
Definition: log.c:648
void msg_destroy(Msg *msg)
Definition: msg.c:132
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
int conn_write_withlen(Connection *conn, Octstr *data)
Definition: conn.c:1075
Definition: octstr.c:118
Octstr * msg_pack(Msg *msg)
Definition: msg.c:181

Variable Documentation

◆ program_status

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