Kannel: Open Source WAP and SMS gateway  $Revision: 5037 $
smsc_p.h File Reference
#include <stddef.h>
#include <stdio.h>
#include <signal.h>
#include <time.h>
#include "smsc.h"

Go to the source code of this file.

Data Structures

struct  SMSCenter
 

Macros

#define DIAL_PREFIX_MAX_LEN   1024
 

Enumerations

enum  {
  SMSC_TYPE_DELETED, SMSC_TYPE_CIMD, SMSC_TYPE_EMI_X25, SMSC_TYPE_SEMA_X28,
  SMSC_TYPE_OIS
}
 

Functions

SMSCentersmscenter_construct (void)
 
void smscenter_destruct (SMSCenter *smsc)
 
int smscenter_read_into_buffer (SMSCenter *)
 
void smscenter_remove_from_buffer (SMSCenter *smsc, size_t n)
 
int smscenter_submit_msg (SMSCenter *smsc, Msg *msg)
 
int smscenter_receive_msg (SMSCenter *smsc, Msg **msg)
 
int smscenter_pending_smsmessage (SMSCenter *smsc)
 
SMSCentercimd_open (char *hostname, int port, char *username, char *password)
 
int cimd_reopen (SMSCenter *smsc)
 
int cimd_close (SMSCenter *smsc)
 
int cimd_pending_smsmessage (SMSCenter *smsc)
 
int cimd_submit_msg (SMSCenter *smsc, Msg *msg)
 
int cimd_receive_msg (SMSCenter *smsc, Msg **msg)
 
SMSCenteremi_open (char *phonenum, char *serialdevice, char *username, char *password)
 
int emi_reopen (SMSCenter *smsc)
 
int emi_close (SMSCenter *smsc)
 
SMSCenteremi_open_ip (char *hostname, int port, char *username, char *password, int receive_port, char *allow_ip, int our_port)
 
int emi_reopen_ip (SMSCenter *smsc)
 
int emi_close_ip (SMSCenter *smsc)
 
int emi_pending_smsmessage (SMSCenter *smsc)
 
int emi_submit_msg (SMSCenter *smsc, Msg *msg)
 
int emi_receive_msg (SMSCenter *smsc, Msg **msg)
 
SMSCentersema_open (char *smscnua, char *homenua, char *serialdevice, int waitreport)
 
int sema_reopen (SMSCenter *smsc)
 
int sema_close (SMSCenter *smsc)
 
int sema_pending_smsmessage (SMSCenter *smsc)
 
int sema_submit_msg (SMSCenter *smsc, Msg *msg)
 
int sema_receive_msg (SMSCenter *smsc, Msg **msg)
 
SMSCenterois_open (int receiveport, const char *hostname, int port, int debug_level)
 
int ois_reopen (SMSCenter *smsc)
 
int ois_close (SMSCenter *smsc)
 
int ois_pending_smsmessage (SMSCenter *smsc)
 
int ois_submit_msg (SMSCenter *smsc, const Msg *msg)
 
int ois_receive_msg (SMSCenter *smsc, Msg **msg)
 
void ois_delete_queue (SMSCenter *smsc)
 

Macro Definition Documentation

#define DIAL_PREFIX_MAX_LEN   1024

Definition at line 90 of file smsc_p.h.

Enumeration Type Documentation

anonymous enum
Enumerator
SMSC_TYPE_DELETED 
SMSC_TYPE_CIMD 
SMSC_TYPE_EMI_X25 
SMSC_TYPE_SEMA_X28 
SMSC_TYPE_OIS 

Definition at line 79 of file smsc_p.h.

Function Documentation

int cimd_close ( SMSCenter smsc)

Definition at line 228 of file smsc_cimd.c.

References debug(), error(), SMSCenter::socket, and write_to_socket().

Referenced by cimd_open_connection(), cimd_reopen(), and smsc_close().

229 {
230 
231  char *cbuff = NULL;
232  int sum;
233  int ret;
234 
235  if (smsc->socket == -1) {
236  debug("bb.sms.cimd", 0, "Trying to close cimd while already closed!");
237  return 0;
238  }
239  cbuff = gw_malloc(2 * 1024);
240 
241  sprintf(cbuff, "%c%s%c%s%c%c", 0x02, "02", 0x09, "11", 0x03, 0x0A);
242 
243  sum = write_to_socket(smsc->socket, cbuff);
244  if (sum < 0) goto error;
245 
246  /* this time we don't block waiting for acknowledge */
247  recv(smsc->socket, cbuff, 2*1024, 0);
248 
249  gw_free(cbuff);
250 
251  ret = close(smsc->socket);
252  smsc->socket = -1;
253  return ret;
254 
255 error:
256  gw_free(cbuff);
257  return -1;
258 }
void error(int err, const char *fmt,...)
Definition: log.c:612
int write_to_socket(int socket, char *str)
Definition: socket.c:345
int socket
Definition: smsc_p.h:115
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:690
SMSCenter* cimd_open ( char *  hostname,
int  port,
char *  username,
char *  password 
)

Definition at line 174 of file smsc_cimd.c.

References SMSCenter::cimd_hostname, cimd_open_connection(), SMSCenter::cimd_password, SMSCenter::cimd_port, SMSCenter::cimd_username, error(), SMSCenter::hostname, SMSCenter::name, port, SMSC_TYPE_CIMD, smscenter_construct(), smscenter_destruct(), and SMSCenter::type.

Referenced by smsc_open().

175 {
176 
177  SMSCenter *smsc = NULL;
178  int ret = 0;
179 
180  /* create a SMSCenter structure */
181  smsc = smscenter_construct();
182  if (smsc == NULL) goto error;
183  smsc->type = SMSC_TYPE_CIMD;
184  smsc->cimd_hostname = gw_strdup(hostname);
185  smsc->hostname = gw_strdup(hostname); /* Needed by read_into_buffer() */
186  smsc->cimd_port = port;
187  smsc->cimd_username = gw_strdup(username);
188  smsc->cimd_password = gw_strdup(password);
189 
190  ret = cimd_open_connection(smsc);
191  if (ret < 0)
192  goto error;
193 
194  sprintf(smsc->name, "CIMD:%s:%d:%s", smsc->cimd_hostname,
195  smsc->cimd_port, smsc->cimd_username);
196  return smsc;
197 
198 error:
199  error(0, "cimd_open: could not open!");
200  smscenter_destruct(smsc);
201  return NULL;
202 }
void error(int err, const char *fmt,...)
Definition: log.c:612
unsigned char * username
Definition: test_cimd2.c:99
static int port
Definition: fakesmsc.c:120
unsigned char * password
Definition: test_cimd2.c:100
static int cimd_open_connection(SMSCenter *smsc)
Definition: smsc_cimd.c:104
SMSCenter * smscenter_construct(void)
Definition: smsc.c:101
void smscenter_destruct(SMSCenter *smsc)
Definition: smsc.c:168
Octstr * hostname
Definition: fakewap.c:232
int cimd_port
Definition: smsc_p.h:138
char * cimd_hostname
Definition: smsc_p.h:137
int type
Definition: smsc_p.h:93
char * cimd_username
Definition: smsc_p.h:139
char name[1024]
Definition: smsc_p.h:96
char * hostname
Definition: smsc_p.h:121
char * cimd_password
Definition: smsc_p.h:140
int cimd_pending_smsmessage ( SMSCenter smsc)

Definition at line 264 of file smsc_cimd.c.

References SMSCenter::buffer, SMSCenter::buflen, SMSCenter::cimd_last_spoke, connect_tcpip(), debug(), error(), smscenter_read_into_buffer(), smscenter_remove_from_buffer(), SMSCenter::socket, and write_to_socket().

Referenced by smscenter_pending_smsmessage().

265 {
266 
267  char *tmpbuff = NULL, *newline = NULL;
268  int ret = 0;
269  time_t thetime = 0;
270 
271  /* check for input sanity */
272  if (smsc == NULL)
273  goto error;
274 
275  /* we can only query every 5 seconds */
276  thetime = time(NULL);
277  if ((smsc->cimd_last_spoke + 5) > thetime) goto no_messages;
278  smsc->cimd_last_spoke = thetime;
279 
280  /* allocate some spare space */
281  tmpbuff = gw_malloc(10 * 1024);
282  memset(tmpbuff, 0, 10*1024);
283 
284  sprintf(tmpbuff, "%c%s%c%s%c%c",
285  0x02, /* stx */
286  "05", 0x09, /* request for message, tab */
287  "11", /* dummy chksum */
288  0x03, 0x0A); /* etx, lf */
289 
290  /* send the poll message to determine if we have messages in queue */
291  ret = write_to_socket(smsc->socket, tmpbuff);
292  if (ret < 0) {
293  debug("bb.sms.cimd", 0, "sending poll message failed");
294  goto error;
295  }
296  /* block while waiting for answer that dataset ends to a 0x0A */
297  for (;;) {
298 
299  newline = memchr(smsc->buffer, 0x0A, smsc->buflen);
300  if (newline != NULL) break;
301 
302  newline = memchr(smsc->buffer, 0x03, smsc->buflen);
303  if (newline != NULL) break;
304 
305  ret = smscenter_read_into_buffer(smsc);
306  if (ret <= 0) {
307  debug("bb.sms.cimd", 0, "read_into_buffer failed!, ret=%d", ret);
308  goto error;
309  }
310 
311  usleep(500);
312 
313  /* Reconnect if no results in 30 seconds */
314  if (time(NULL) > (thetime + 30)) {
315 
316  error(0, "timeout occurred, maybe the connection was broken?");
317 
318  /* Reconnect if neccessary, this catches most of them */
319  /* XXX this is an ugly kludge, but then again,
320  CIMD 1.3 is an ugly kludge. */
321  connect_tcpip(smsc);
322  goto no_messages;
323 
324  }
325 
326  }
327 
328  /* if we got an nck, cut the message out and return 0 */
329  newline = memchr(smsc->buffer, 0x15, smsc->buflen);
330  if (newline != NULL) {
331  newline = memchr(smsc->buffer, 0x0A, smsc->buflen);
332  if (newline == NULL)
333  newline = memchr(smsc->buffer, 0x03, smsc->buflen);
334  smscenter_remove_from_buffer(smsc, newline - smsc->buffer + 1);
335  goto no_messages;
336  }
337 
338  /* miracle of miracles, we got a message */
339  gw_free(tmpbuff);
340  return 1;
341 
342 no_messages:
343  gw_free(tmpbuff);
344  return 0;
345 
346 error:
347 
348  debug("bb.sms.cimd", 0, "smscenter_pending_smsmessage: returning error");
349  gw_free(tmpbuff);
350  return -1;
351 }
void error(int err, const char *fmt,...)
Definition: log.c:612
static int connect_tcpip(SMSCenter *smsc)
Definition: smsc_cimd.c:561
size_t buflen
Definition: smsc_p.h:186
int smscenter_read_into_buffer(SMSCenter *smsc)
Definition: smsc.c:348
int write_to_socket(int socket, char *str)
Definition: socket.c:345
void smscenter_remove_from_buffer(SMSCenter *smsc, size_t n)
Definition: smsc.c:412
int socket
Definition: smsc_p.h:115
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:690
char * buffer
Definition: smsc_p.h:184
time_t cimd_last_spoke
Definition: smsc_p.h:141
int cimd_receive_msg ( SMSCenter smsc,
Msg **  msg 
)

Definition at line 470 of file smsc_cimd.c.

References SMSCenter::buffer, SMSCenter::buflen, SMSCenter::cimd_last_spoke, debug(), error(), msg_create, octstr_create, parse_cimd_to_iso88591(), send_acknowledge(), smscenter_remove_from_buffer(), and text.

Referenced by smscenter_receive_msg().

471 {
472 
473  char *tmpbuff = NULL, *sender = NULL;
474  char *receiver = NULL, *text = NULL, *scts = NULL;
475  char *tmpchar = NULL;
476 
477  debug("bb.sms.cimd", 0, "cimd_receive_smsmessage: starting");
478 
479  /* the PENDING function has previously requested for
480  the message and checked that it safely found its
481  way into the memory buffer (smsc->buffer) */
482 
483  /* we want to temporarily store some data */
484  tmpbuff = gw_malloc(10 * 1024);
485  sender = gw_malloc(10 * 1024);
486  receiver = gw_malloc(10 * 1024);
487  text = gw_malloc(10 * 1024);
488  scts = gw_malloc(10 * 1024);
489 
490  memset(tmpbuff, 0, 10 * 1024);
491  memset(sender, 0, 10 * 1024);
492  memset(receiver, 0, 10 * 1024);
493  memset(text, 0, 10 * 1024);
494  memset(scts, 0, 10 * 1024);
495 
496  /* cut the raw message out from the message buffer */
497  tmpchar = memchr(smsc->buffer, 0x0A, smsc->buflen);
498  if (tmpchar == NULL) {
499  tmpchar = memchr(smsc->buffer, 0x03, smsc->buflen);
500  if (tmpchar == NULL) goto error;
501  }
502 
503  strncpy(tmpbuff, smsc->buffer, tmpchar - smsc->buffer);
504  smscenter_remove_from_buffer(smsc, tmpchar - smsc->buffer + 1);
505 
506  /* Parse the raw message */
507  sscanf(tmpbuff,
508  "\x02\x06\tC:05\t%[^\t]\t%[^\t]\t%[^\t]\t%[^\t]\t11\x03\x0A",
509  receiver, sender, text, scts);
510 
511  sscanf(tmpbuff,
512  "\x02\x06\tC:05\t%[^\t]\t%[^\t]\t%[^\t]\t%[^\t]\t11\x03",
513  receiver, sender, text, scts);
514 
515  /* Translate from the CIMD character set to iso8859-1 */
516  parse_cimd_to_iso88591(text, tmpbuff, 10*1024);
517  strncpy(text, tmpbuff, 480);
518 
519  /* create a smsmessage structure out of the components */
520  *msg = msg_create(sms);
521  if (*msg == NULL) return -1;
522  (*msg)->sms.sender = octstr_create(sender);
523  (*msg)->sms.receiver = octstr_create(receiver);
524  (*msg)->sms.msgdata = octstr_create(text);
525 
526  /* Send acknowledge */
527  send_acknowledge(smsc);
528 
529  /* We got a message so we can instantly check for a new one. */
530  smsc->cimd_last_spoke -= 5;
531 
532  /* Free and Finish */
533 
534  gw_free(tmpbuff);
535  gw_free(sender);
536  gw_free(receiver);
537  gw_free(text);
538  gw_free(scts);
539 
540  debug("bb.sms.cimd", 0, "cimd_receive_smsmessage: return ok");
541 
542  return 1;
543 
544 error:
545  debug("bb.sms.cimd", 0, "cimd_receive_smsmessage: failed");
546  gw_free(tmpbuff);
547  gw_free(sender);
548  gw_free(receiver);
549  gw_free(text);
550  gw_free(scts);
551 
552  debug("bb.sms.cimd", 0, "cimd_receive_smsmessage: return failed");
553 
554  return -1;
555 }
void error(int err, const char *fmt,...)
Definition: log.c:612
size_t buflen
Definition: smsc_p.h:186
#define msg_create(type)
Definition: msg.h:136
char * text
Definition: smsc_cimd2.c:921
static int send_acknowledge(SMSCenter *smsc)
Definition: smsc_cimd.c:640
void smscenter_remove_from_buffer(SMSCenter *smsc, size_t n)
Definition: smsc.c:412
static int parse_cimd_to_iso88591(char *from, char *to, int length)
Definition: smsc_cimd.c:923
#define octstr_create(cstr)
Definition: octstr.h:125
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:690
char * buffer
Definition: smsc_p.h:184
time_t cimd_last_spoke
Definition: smsc_p.h:141
int cimd_reopen ( SMSCenter smsc)

Definition at line 210 of file smsc_cimd.c.

References cimd_close(), cimd_open_connection(), and error().

Referenced by smsc_reopen().

211 {
212 
213  cimd_close(smsc);
214 
215  if (cimd_open_connection(smsc) < 0) {
216  error(0, "Failed to re-open the connection!");
217  return -1;
218  }
219  return 0;
220 }
void error(int err, const char *fmt,...)
Definition: log.c:612
static int cimd_open_connection(SMSCenter *smsc)
Definition: smsc_cimd.c:104
int cimd_close(SMSCenter *smsc)
Definition: smsc_cimd.c:228
int cimd_submit_msg ( SMSCenter smsc,
Msg msg 
)

Definition at line 358 of file smsc_cimd.c.

References SMSCenter::alt_charset, SMSCenter::buffer, debug(), error(), expect_acknowledge(), octstr_append_from_hex(), octstr_create, octstr_get_cstr, octstr_get_many_chars(), octstr_len(), parse_iso88591_to_cimd(), send_acknowledge(), SMSCenter::socket, warning(), and write_to_socket().

Referenced by smscenter_submit_msg().

359 {
360 
361  char *tmpbuff = NULL, *tmptext = NULL;
362  char msgtext[1024];
363  int ret;
364  int cmd = 0, err = 0;
365 
366  /* Fix these by implementing a could-not-send-because-
367  protocol-does-not-allow in smsc.c or smsgateway.c */
368  if (octstr_len(msg->sms.msgdata) + octstr_len(msg->sms.udhdata) < 1) {
369  if (msg->sms.msgdata == NULL)
370  msg->sms.msgdata = octstr_create("");
371  octstr_append_from_hex(msg->sms.msgdata, "20");
372  }
373  if (octstr_len(msg->sms.sender) < 1) {
374  warning(0, "cimd_submit_smsmessage: ignoring message with 0-length field");
375  goto okay; /* THIS IS NOT OKAY!!!! XXX */
376  }
377  if (octstr_len(msg->sms.receiver) < 1) {
378  warning(0, "cimd_submit_smsmessage: ignoring message with 0-length field");
379  goto okay; /* THIS IS NOT OKAY!!!! XXX */
380  }
381 
382  tmpbuff = gw_malloc(10 * 1024);
383  tmptext = gw_malloc(10 * 1024);
384 
385  memset(tmpbuff, 0, 10*1024);
386  memset(tmptext, 0, 10*1024);
387  memset(msgtext, 0, sizeof(msgtext));
388 
389  if (octstr_len(msg->sms.udhdata)) {
390  octstr_get_many_chars(msgtext, msg->sms.udhdata, 0, octstr_len(msg->sms.udhdata));
391  octstr_get_many_chars(msgtext + octstr_len(msg->sms.udhdata),
392  msg->sms.msgdata, 0,
393  140 - octstr_len(msg->sms.udhdata));
394  } else {
395  octstr_get_many_chars(msgtext, msg->sms.msgdata, 0,
396  octstr_len(msg->sms.msgdata));
397  }
398 
399  /* XXX parse_iso88591_to_cimd should use Octstr
400  * directly, or get a char* and a length, instead of using NUL
401  * terminated strings.
402  */
403  parse_iso88591_to_cimd(msgtext, tmptext, 10*1024, smsc->alt_charset);
404 
405  /* If messages has UDHs, add the magic number 31 to the right spot */
406  sprintf(tmpbuff, "%c%s%c%s%c%s%c%s%c%s%c%s%c%s%c%c",
407  0x02,
408  "03", 0x09,
409  octstr_get_cstr(msg->sms.receiver), 0x09,
410  tmptext, 0x09,
411  "", 0x09,
412  "", 0x09,
413  (octstr_len(msg->sms.udhdata)) ? "31" : "", 0x09,
414  "11", 0x03, 0x0A);
415 
416  ret = write_to_socket(smsc->socket, tmpbuff);
417  if (ret < 0) {
418  debug("bb.sms.cimd", 0, "cimd_submit_smsmessage: socket write error");
419  goto error;
420  }
421 
422  /* The Nokia SMSC MAY be configured to send delivery
423  information, which we then will HAVE to acknowledge.
424  Naturally the CIMD 1.3 protocol does not include any
425  kind of negotiation mechanism. */
426  ret = expect_acknowledge(smsc, &cmd, &err);
427 
428  if (ret >= 1) {
429 
430  if (cmd == 4) {
431  send_acknowledge(smsc);
432  goto okay;
433  } else if (cmd == 3) {
434  goto okay;
435  }
436 
437  } else if (ret == 0) {
438 
439  if (cmd == 4) {
440  send_acknowledge(smsc);
441  goto okay; /* FIXME XXX THIS IS BOGUS, FIX SMSGATEWAY.C */
442  goto error;
443  } else if (cmd == 3) {
444  goto okay; /* FIXME XXX THIS IS BOGUS, FIX SMSGATEWAY.C */
445  goto error;
446  } else {
447  error(0, "Unexpected behaviour from the CIMD server");
448  debug("bb.sms.cimd", 0, "cimd_submit_smsmessage: acknowledge was <%i>", ret);
449  debug("bb.sms.cimd", 0, "cimd_submit_smsmessage: buffer==<%s>", smsc->buffer);
450  goto error;
451  }
452 
453  }
454 
455 okay:
456  gw_free(tmpbuff);
457  gw_free(tmptext);
458  return 0;
459 
460 error:
461  debug("bb.sms.cimd", 0, "cimd_submit_smsmessage: returning error");
462  gw_free(tmpbuff);
463  gw_free(tmptext);
464  return -1;
465 
466 }
void error(int err, const char *fmt,...)
Definition: log.c:612
void octstr_append_from_hex(Octstr *ostr, char *hex)
Definition: octstr.c:449
static int parse_iso88591_to_cimd(char *from, char *to, int length, int alt_charset)
Definition: smsc_cimd.c:767
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
int write_to_socket(int socket, char *str)
Definition: socket.c:345
static int send_acknowledge(SMSCenter *smsc)
Definition: smsc_cimd.c:640
void warning(int err, const char *fmt,...)
Definition: log.c:624
#define octstr_create(cstr)
Definition: octstr.h:125
int socket
Definition: smsc_p.h:115
long octstr_len(const Octstr *ostr)
Definition: octstr.c:340
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:690
char * buffer
Definition: smsc_p.h:184
long alt_charset
Definition: smsc_p.h:106
void octstr_get_many_chars(char *buf, Octstr *ostr, long pos, long len)
Definition: octstr.c:423
static int expect_acknowledge(SMSCenter *smsc, int *cmd, int *err)
Definition: smsc_cimd.c:672
int emi_close ( SMSCenter smsc)

Definition at line 194 of file smsc_emi_x25.c.

References emi_close_ip().

Referenced by emi_reopen(), and smsc_close().

195 {
196  return emi_close_ip(smsc);
197 }
int emi_close_ip(SMSCenter *smsc)
Definition: smsc_emi_x25.c:302
int emi_close_ip ( SMSCenter smsc)

Definition at line 302 of file smsc_emi_x25.c.

References SMSCenter::emi_fd, and info().

Referenced by emi_close(), and emi_reopen_ip().

303 {
304 
305  if (smsc->emi_fd == -1) {
306  info(0, "Trying to close already closed EMI, ignoring");
307  return 0;
308  }
309  close(smsc->emi_fd);
310  smsc->emi_fd = -1;
311 
312  return 0;
313 }
void info(int err, const char *fmt,...)
Definition: log.c:636
int emi_fd
Definition: smsc_p.h:145
SMSCenter* emi_open ( char *  phonenum,
char *  serialdevice,
char *  username,
char *  password 
)

Definition at line 153 of file smsc_emi_x25.c.

References SMSCenter::emi_current_msg_number, emi_open_connection(), SMSCenter::emi_password, SMSCenter::emi_phonenum, SMSCenter::emi_serialdevice, SMSCenter::emi_username, error(), SMSCenter::name, SMSC_TYPE_EMI_X25, smscenter_construct(), smscenter_destruct(), and SMSCenter::type.

Referenced by smsc_open().

154 {
155  SMSCenter *smsc;
156 
157  smsc = smscenter_construct();
158  if (smsc == NULL)
159  goto error;
160 
161  smsc->type = SMSC_TYPE_EMI_X25;
162 
163  smsc->emi_phonenum = gw_strdup(phonenum);
164  smsc->emi_serialdevice = gw_strdup(serialdevice);
165  smsc->emi_username = gw_strdup(username);
166  smsc->emi_password = gw_strdup(password);
167 
168  smsc->emi_current_msg_number = 0;
169 
170  if (emi_open_connection(smsc) < 0)
171  goto error;
172 
173  sprintf(smsc->name, "EMI:%s:%s", smsc->emi_phonenum,
174  smsc->emi_username);
175  return smsc;
176 
177 error:
178  error(0, "emi_open failed");
179  smscenter_destruct(smsc);
180  return NULL;
181 }
void error(int err, const char *fmt,...)
Definition: log.c:612
char * emi_password
Definition: smsc_p.h:152
unsigned char * username
Definition: test_cimd2.c:99
unsigned char * password
Definition: test_cimd2.c:100
char * emi_phonenum
Definition: smsc_p.h:147
SMSCenter * smscenter_construct(void)
Definition: smsc.c:101
char * emi_username
Definition: smsc_p.h:151
void smscenter_destruct(SMSCenter *smsc)
Definition: smsc.c:168
char * emi_serialdevice
Definition: smsc_p.h:148
static int emi_open_connection(SMSCenter *smsc)
Definition: smsc_emi_x25.c:138
int type
Definition: smsc_p.h:93
char name[1024]
Definition: smsc_p.h:96
int emi_current_msg_number
Definition: smsc_p.h:153
SMSCenter* emi_open_ip ( char *  hostname,
int  port,
char *  username,
char *  password,
int  receive_port,
char *  allow_ip,
int  our_port 
)
int emi_pending_smsmessage ( SMSCenter smsc)

Definition at line 319 of file smsc_emi_x25.c.

References get_data(), guarantee_link(), memorybuffer_cut_rawmessage(), memorybuffer_has_rawmessage(), and memorybuffer_insert_data().

Referenced by smscenter_pending_smsmessage().

320 {
321 
322  char *tmpbuff;
323  int n = 0;
324  /* time_t timenow; */
325 
326  /* Block until we have a connection */
327  guarantee_link(smsc);
328 
329  /* If we have MO-message, then act (return 1) */
330  if (memorybuffer_has_rawmessage(smsc, 52, 'O') > 0 ||
331  memorybuffer_has_rawmessage(smsc, 1, 'O') > 0 )
332  return 1;
333 
334  tmpbuff = gw_malloc(10 * 1024);
335  memset(tmpbuff, 0, 10*1024);
336 
337  /* check for data */
338  n = get_data(smsc, tmpbuff, 10 * 1024);
339  if (n > 0)
340  memorybuffer_insert_data(smsc, tmpbuff, n);
341 
342  /* delete all ACKs/NACKs/whatever */
343  while (memorybuffer_has_rawmessage(smsc, 51, 'R') > 0 ||
344  memorybuffer_has_rawmessage(smsc, 1, 'R') > 0)
345  memorybuffer_cut_rawmessage(smsc, tmpbuff, 10*1024);
346 
347  gw_free(tmpbuff);
348 
349  /* If we have MO-message, then act (return 1) */
350 
351  if (memorybuffer_has_rawmessage(smsc, 52, 'O') > 0 ||
352  memorybuffer_has_rawmessage(smsc, 1, 'O') > 0)
353  return 1;
354 
355  /*
356  time(&timenow);
357  if( (smsc->emi_last_spoke + 60*20) < timenow) {
358  time(&smsc->emi_last_spoke);
359  }
360  */
361 
362  return 0;
363 
364 }
static int memorybuffer_insert_data(SMSCenter *smsc, char *buff, int length)
Definition: smsc_emi_x25.c:811
static int guarantee_link(SMSCenter *smsc)
Definition: smsc_emi_x25.c:449
static int memorybuffer_cut_rawmessage(SMSCenter *smsc, char *buff, int length)
Definition: smsc_emi_x25.c:857
static int get_data(SMSCenter *smsc, char *buff, int length)
Definition: smsc_emi_x25.c:660
static int memorybuffer_has_rawmessage(SMSCenter *smsc, int type, char auth)
Definition: smsc_emi_x25.c:828
int emi_receive_msg ( SMSCenter smsc,
Msg **  msg 
)

Definition at line 408 of file smsc_emi_x25.c.

References acknowledge_from_rawmessage(), error(), memorybuffer_cut_rawmessage(), msg, msg_destroy(), and parse_rawmessage_to_msg().

Referenced by smscenter_receive_msg().

409 {
410  char *tmpbuff;
411  Msg *msg = NULL;
412 
413  *tmsg = NULL;
414 
415  tmpbuff = gw_malloc(10 * 1024);
416  memset(tmpbuff, 0, 10*1024);
417 
418  /* get and delete message from buffer */
419  memorybuffer_cut_rawmessage(smsc, tmpbuff, 10*1024);
420  parse_rawmessage_to_msg(smsc, &msg, tmpbuff, strlen(tmpbuff));
421 
422  /* yeah yeah, I got the message... */
423  acknowledge_from_rawmessage(smsc, tmpbuff, strlen(tmpbuff));
424 
425  /* return with the joyful news */
426  gw_free(tmpbuff);
427 
428  if (msg == NULL) goto error;
429 
430  *tmsg = msg;
431 
432  return 1;
433 
434 error:
435  gw_free(tmpbuff);
436  msg_destroy(msg);
437  return -1;
438 }
void error(int err, const char *fmt,...)
Definition: log.c:612
static int acknowledge_from_rawmessage(SMSCenter *smsc, char *rawmessage, int length)
Definition: smsc_emi_x25.c:964
Definition: msg.h:79
static int memorybuffer_cut_rawmessage(SMSCenter *smsc, char *buff, int length)
Definition: smsc_emi_x25.c:857
static int parse_rawmessage_to_msg(SMSCenter *smsc, Msg **msg, char *rawmessage, int length)
Definition: smsc_emi_x25.c:895
void msg_destroy(Msg *msg)
Definition: msg.c:132
static XMLRPCDocument * msg
Definition: test_xmlrpc.c:86
int emi_reopen ( SMSCenter smsc)

Definition at line 183 of file smsc_emi_x25.c.

References emi_close(), emi_open_connection(), and error().

Referenced by smsc_reopen().

184 {
185  emi_close(smsc);
186 
187  if (emi_open_connection(smsc) < 0) {
188  error(0, "emi_reopen failed");
189  return -1;
190  }
191  return 0;
192 }
void error(int err, const char *fmt,...)
Definition: log.c:612
static int emi_open_connection(SMSCenter *smsc)
Definition: smsc_emi_x25.c:138
int emi_close(SMSCenter *smsc)
Definition: smsc_emi_x25.c:194
int emi_reopen_ip ( SMSCenter smsc)

Definition at line 294 of file smsc_emi_x25.c.

References emi_close_ip(), and emi_open_connection_ip().

295 {
296  emi_close_ip(smsc);
297 
298  return emi_open_connection_ip(smsc);
299 }
static int emi_open_connection_ip(SMSCenter *smsc)
Definition: smsc_emi_x25.c:276
int emi_close_ip(SMSCenter *smsc)
Definition: smsc_emi_x25.c:302
int emi_submit_msg ( SMSCenter smsc,
Msg msg 
)

Definition at line 372 of file smsc_emi_x25.c.

References debug(), error(), info(), parse_msg_to_rawmessage(), put_data(), and wait_for_ack().

Referenced by smscenter_submit_msg().

373 {
374  char *tmpbuff = NULL;
375 
376  if (smsc == NULL) goto error;
377  if (omsg == NULL) goto error;
378 
379  tmpbuff = gw_malloc(10 * 1024);
380  memset(tmpbuff, 0, 10*1024);
381 
382  if (parse_msg_to_rawmessage(smsc, omsg, tmpbuff, 10*1024) < 1)
383  goto error;
384 
385  if (put_data(smsc, tmpbuff, strlen(tmpbuff), 0) < 0) {
386  info(0, "put_data failed!");
387  goto error;
388  }
389 
390  wait_for_ack(smsc, 51);
391 
392  /* smsc->emi_current_msg_number += 1; */
393  debug("bb.sms.emi", 0, "Submit Ok...");
394 
395  gw_free(tmpbuff);
396  return 0;
397 
398 error:
399  debug("bb.sms.emi", 0, "Submit Error...");
400 
401  gw_free(tmpbuff);
402  return -1;
403 }
void error(int err, const char *fmt,...)
Definition: log.c:612
void info(int err, const char *fmt,...)
Definition: log.c:636
static int parse_msg_to_rawmessage(SMSCenter *smsc, Msg *msg, char *rawmessage, int length)
static int wait_for_ack(SMSCenter *smsc, int op_type)
Definition: smsc_emi_x25.c:621
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:690
static int put_data(SMSCenter *smsc, char *buff, int length, int is_backup)
Definition: smsc_emi_x25.c:755
int ois_close ( SMSCenter smsc)

Definition at line 263 of file smsc_ois.c.

References SMSCenter::buflen, ois_debug_level, ois_disconnect_all(), OIS_FLAG_DEBUG, SMSCenter::ois_flags, ois_swap_buffering(), SAY, SMSC_TYPE_OIS, smscenter_remove_from_buffer(), SMSCenter::type, and warning().

Referenced by ois_open_listener(), ois_reopen(), and smsc_close().

264 {
266  SAY(2, "ois_close");
267 
268  if (smsc->type != SMSC_TYPE_OIS) {
269  warning(0, "ois_close: closing a not-ois connection...");
270  }
271 
272  ois_swap_buffering(smsc);
274  ois_swap_buffering(smsc);
276  SAY(4, "ois_close: ois_disconnect_all");
277  ois_disconnect_all(smsc);
278 
279  return 0;
280 }
int ois_debug_level
Definition: smsc_ois.c:136
static void ois_swap_buffering(SMSCenter *smsc)
Definition: smsc_ois.c:1668
int ois_flags
Definition: smsc_p.h:175
size_t buflen
Definition: smsc_p.h:186
#define SAY(d, s)
Definition: smsc_ois.c:141
void smscenter_remove_from_buffer(SMSCenter *smsc, size_t n)
Definition: smsc.c:412
void warning(int err, const char *fmt,...)
Definition: log.c:624
#define OIS_FLAG_DEBUG
Definition: smsc_ois.c:160
static void ois_disconnect_all(SMSCenter *smsc)
Definition: smsc_ois.c:574
int type
Definition: smsc_p.h:93
void ois_delete_queue ( SMSCenter smsc)

Definition at line 423 of file smsc_ois.c.

References msg, ois_debug_level, OIS_FLAG_DEBUG, SMSCenter::ois_flags, ois_receive_msg(), and SAY.

Referenced by smscenter_destruct().

424 {
425  Msg *msg;
426 
428  SAY(2, "ois_delete_queue");
429 
430  while (ois_receive_msg(smsc, &msg) > 0) {
431  gw_free(msg);
432  }
433  return;
434 }
int ois_debug_level
Definition: smsc_ois.c:136
int ois_receive_msg(SMSCenter *smsc, Msg **msg)
Definition: smsc_ois.c:396
int ois_flags
Definition: smsc_p.h:175
#define SAY(d, s)
Definition: smsc_ois.c:141
Definition: msg.h:79
#define OIS_FLAG_DEBUG
Definition: smsc_ois.c:160
static XMLRPCDocument * msg
Definition: test_xmlrpc.c:86
SMSCenter* ois_open ( int  receiveport,
const char *  hostname,
int  port,
int  debug_level 
)

Definition at line 222 of file smsc_ois.c.

References error(), SMSCenter::hostname, SMSCenter::name, ois_debug_level, OIS_FLAG_DEBUG, SMSCenter::ois_flags, ois_open_listener(), port, SMSCenter::port, SMSCenter::receive_port, SAY, SMSC_TYPE_OIS, smscenter_construct(), smscenter_destruct(), and SMSCenter::type.

Referenced by smsc_open().

223 {
224  SMSCenter *smsc;
225  int ret;
226 
227  ois_debug_level = debug_level & OIS_FLAG_DEBUG;
228  SAY(2, "ois_open");
229 
230  /* create a SMSCenter structure */
231 
232  smsc = smscenter_construct();
233  if (smsc == NULL) {
234  goto error;
235  }
236 
237  smsc->type = SMSC_TYPE_OIS;
238  smsc->receive_port = receiveport;
239  smsc->hostname = gw_strdup(hostname);
240  smsc->port = port;
241  smsc->ois_flags = ois_debug_level;
242 
243  ret = ois_open_listener(smsc);
244  if (ret < 0) {
245  goto error;
246  }
247  sprintf(smsc->name, "OIS:TCP/X.25-Translator:localhost:%d:TCP:%.512s:%d",
248  smsc->receive_port, smsc->hostname, smsc->port);
249 
250  return smsc;
251 
252  error:
253  error(0, "ois_open: could not open");
254  smscenter_destruct(smsc);
255  return NULL;
256 }
void error(int err, const char *fmt,...)
Definition: log.c:612
int ois_debug_level
Definition: smsc_ois.c:136
int ois_flags
Definition: smsc_p.h:175
#define SAY(d, s)
Definition: smsc_ois.c:141
int receive_port
Definition: smsc_p.h:123
static int port
Definition: fakesmsc.c:120
int port
Definition: smsc_p.h:122
SMSCenter * smscenter_construct(void)
Definition: smsc.c:101
void smscenter_destruct(SMSCenter *smsc)
Definition: smsc.c:168
Octstr * hostname
Definition: fakewap.c:232
static int ois_open_listener(SMSCenter *smsc)
Definition: smsc_ois.c:448
#define OIS_FLAG_DEBUG
Definition: smsc_ois.c:160
int type
Definition: smsc_p.h:93
char name[1024]
Definition: smsc_p.h:96
char * hostname
Definition: smsc_p.h:121
int ois_pending_smsmessage ( SMSCenter smsc)

Definition at line 318 of file smsc_ois.c.

References SMSCenter::ois_ack_debt, ois_check_incoming(), ois_check_input(), ois_debug_level, OIS_FLAG_DEBUG, SMSCenter::ois_flags, OIS_NOWAIT, SMSCenter::ois_socket, ois_swap_buffering(), SAY, SMSCenter::socket, and warning().

Referenced by smscenter_pending_smsmessage().

319 {
320  int ret;
321 
323  SAY(8, "ois_pending_smsmessage");
324 
325  ret = ois_check_incoming(smsc, OIS_NOWAIT);
326  if (ret == 0 && smsc->socket != -1) {
327  ret = ois_check_input(smsc, OIS_NOWAIT);
328  }
329  if (ret == 0 && smsc->ois_socket != -1) {
330  ois_swap_buffering(smsc);
331  ret = ois_check_input(smsc, OIS_NOWAIT);
332  ois_swap_buffering(smsc);
333  if (smsc->ois_socket == -1 && smsc->ois_ack_debt != 0) {
334  warning(0, "ois_pending_smsmessage: missing %d ack(s)...",
335  smsc->ois_ack_debt);
336  }
337  }
338  return ret;
339 }
int ois_ack_debt
Definition: smsc_p.h:174
int ois_debug_level
Definition: smsc_ois.c:136
static void ois_swap_buffering(SMSCenter *smsc)
Definition: smsc_ois.c:1668
static int ois_check_input(SMSCenter *smsc, long wait_usec)
Definition: smsc_ois.c:644
int ois_flags
Definition: smsc_p.h:175
static int ois_check_incoming(SMSCenter *smsc, long wait_usec)
Definition: smsc_ois.c:721
#define SAY(d, s)
Definition: smsc_ois.c:141
void warning(int err, const char *fmt,...)
Definition: log.c:624
#define OIS_FLAG_DEBUG
Definition: smsc_ois.c:160
int socket
Definition: smsc_p.h:115
#define OIS_NOWAIT
Definition: smsc_ois.c:151
int ois_socket
Definition: smsc_p.h:177
int ois_receive_msg ( SMSCenter smsc,
Msg **  msg 
)

Definition at line 396 of file smsc_ois.c.

References ois_listentry::msg, ois_listentry::next, ois_debug_level, OIS_FLAG_DEBUG, OIS_FLAG_ERROR, SMSCenter::ois_flags, SMSCenter::ois_received_mo, and SAY.

Referenced by ois_delete_queue(), and smscenter_receive_msg().

397 {
398  ois_listentry *item;
399 
401  SAY(2, "ois_receive_msg");
402 
403  item = smsc->ois_received_mo;
404  if (item == NULL) { /* no mo messages */
405  if ((smsc->ois_flags & OIS_FLAG_ERROR) == 0) {
406  return 0; /* should actually not happen */
407  } else {
408  return -1; /* error pending, reopen? */
409  }
410  } else { /* we have a message waiting */
411  smsc->ois_received_mo = item->next;
412  *msg = item->msg;
413  gw_free(item);
414  return 1; /* got the message */
415  }
416 }
int ois_debug_level
Definition: smsc_ois.c:136
struct ois_listentry * next
Definition: smsc_ois.c:156
int ois_flags
Definition: smsc_p.h:175
#define SAY(d, s)
Definition: smsc_ois.c:141
void * ois_received_mo
Definition: smsc_p.h:173
#define OIS_FLAG_ERROR
Definition: smsc_ois.c:161
#define OIS_FLAG_DEBUG
Definition: smsc_ois.c:160
int ois_reopen ( SMSCenter smsc)

Definition at line 287 of file smsc_ois.c.

References error(), ois_close(), ois_debug_level, OIS_FLAG_DEBUG, SMSCenter::ois_flags, ois_open_listener(), SAY, SMSC_TYPE_OIS, and SMSCenter::type.

Referenced by smsc_reopen().

288 {
289  int ret;
290 
292  SAY(2, "ois_reopen");
293 
294  ois_close(smsc);
295 
296  if (smsc->type == SMSC_TYPE_OIS) {
297  ret = ois_open_listener(smsc);
298  if (ret < 0) {
299  goto error;
300  }
301  } else {
302  error(0, "ois_reopen: wrong smsc type");
303  goto error;
304  }
305  return 0;
306 
307  error:
308  error(0, "ois_reopen: could not open");
309  return -1;
310 }
void error(int err, const char *fmt,...)
Definition: log.c:612
int ois_debug_level
Definition: smsc_ois.c:136
int ois_flags
Definition: smsc_p.h:175
#define SAY(d, s)
Definition: smsc_ois.c:141
int ois_close(SMSCenter *smsc)
Definition: smsc_ois.c:263
static int ois_open_listener(SMSCenter *smsc)
Definition: smsc_ois.c:448
#define OIS_FLAG_DEBUG
Definition: smsc_ois.c:160
int type
Definition: smsc_p.h:93
int ois_submit_msg ( SMSCenter smsc,
const Msg msg 
)

Definition at line 346 of file smsc_ois.c.

References error(), SMSCenter::ois_ack_debt, SMSCenter::ois_alive, ois_debug_level, ois_disconnect(), OIS_FLAG_DEBUG, SMSCenter::ois_flags, ois_open_sender(), ois_submit_sm_invoke(), ois_swap_buffering(), SAY, SMSCenter::socket, and warning().

Referenced by smscenter_submit_msg().

347 {
348  int ret;
349 
351  SAY(2, "ois_submit_msg");
352  ois_swap_buffering(smsc);
353 
354  if (msg_type((Msg *)msg) != sms) {
355  error(0, "ois_submit_msg: can not handle message types other than smart_msg");
356  goto error;
357  }
358 
359  if (smsc->socket == -1) {
360  ret = ois_open_sender(smsc);
361  if (ret < 0) {
362  goto error;
363  }
364  }
365 
366  ret = ois_submit_sm_invoke(smsc, msg);
367  if (ret < 0) {
368  goto error_close;
369  }
370 
371  ++smsc->ois_ack_debt;
372  time(&smsc->ois_alive);
373  ret = 0;
374  goto out;
375 
376  error_close:
377  if (smsc->ois_ack_debt != 0) {
378  warning(0, "ois_submit_msg: missing %d ack(s)...",
379  smsc->ois_ack_debt);
380  }
381  SAY(4, "ois_submit_msg: ois_disconnect in error_close");
382  ois_disconnect(smsc);
383  error:
384  SAY(2, "ois_submit_msg error");
385  ret = -1;
386  out:
387  ois_swap_buffering(smsc);
388  return ret;
389 }
int ois_ack_debt
Definition: smsc_p.h:174
void error(int err, const char *fmt,...)
Definition: log.c:612
int ois_debug_level
Definition: smsc_ois.c:136
static void ois_swap_buffering(SMSCenter *smsc)
Definition: smsc_ois.c:1668
static int ois_open_sender(SMSCenter *smsc)
Definition: smsc_ois.c:475
int ois_flags
Definition: smsc_p.h:175
msg_type
Definition: msg.h:73
#define SAY(d, s)
Definition: smsc_ois.c:141
Definition: msg.h:79
static void ois_disconnect(SMSCenter *smsc)
Definition: smsc_ois.c:595
void warning(int err, const char *fmt,...)
Definition: log.c:624
#define OIS_FLAG_DEBUG
Definition: smsc_ois.c:160
int socket
Definition: smsc_p.h:115
static int ois_submit_sm_invoke(SMSCenter *smsc, const Msg *msg)
Definition: smsc_ois.c:808
time_t ois_alive
Definition: smsc_p.h:171
int sema_close ( SMSCenter smsc)

Definition at line 199 of file smsc_sema.c.

References SMSCenter::sema_fd, SMSCenter::sema_mo, sema_msglist_free(), and SMSCenter::sema_mt.

Referenced by smsc_close().

200 {
201  if(smsc->sema_fd > 0)
202  close(smsc->sema_fd);
203  /*deallocate*/
204  sema_msglist_free(smsc->sema_mt);
205  sema_msglist_free(smsc->sema_mo);
206  return 0;
207 }
struct sema_msglist * sema_mo
Definition: smsc_p.h:166
int sema_fd
Definition: smsc_p.h:167
static void sema_msglist_free(sema_msglist *mlist)
Definition: smsc_sema.c:440
struct sema_msglist * sema_mt
Definition: smsc_p.h:166
SMSCenter* sema_open ( char *  smscnua,
char *  homenua,
char *  serialdevice,
int  waitreport 
)

Definition at line 113 of file smsc_sema.c.

References debug(), error(), SMSCenter::name, SMSCenter::sema_fd, SMSCenter::sema_homenua, SMSCenter::sema_mo, sema_msglist_new(), SMSCenter::sema_mt, SMSCenter::sema_serialdevice, SMSCenter::sema_smscnua, sema_wait_report, SMSC_TYPE_SEMA_X28, smscenter_construct(), smscenter_destruct(), SMSCenter::type, X28_close_send_link(), X28_open_data_link(), and X28_open_send_link().

Referenced by smsc_open().

115 {
116  SMSCenter *smsc;
117  int nret = -1;
118 
119  smsc = smscenter_construct();
120  if(smsc == NULL)
121  goto error;
122 
123  sprintf(smsc->name, "SEMA:X28:");
124 
125  smsc->type = SMSC_TYPE_SEMA_X28;
126  smsc->sema_smscnua = gw_strdup(smscnua);
127  smsc->sema_homenua = gw_strdup(homenua);
128  smsc->sema_serialdevice = gw_strdup(serialdevice);
129  sema_wait_report = waitreport;
130 
131  smsc->sema_mt = sema_msglist_new();
132  if(smsc->sema_mt == NULL) goto error;
133 
134  smsc->sema_mo = sema_msglist_new();
135  if(smsc->sema_mo == NULL) goto error;
136 
137  /* Open the device properly. Remember to set the
138  access codes correctly. */
139  debug("smsc.sema", 0, "sema_open: open datalink");
141  if(smsc->sema_fd == -1) goto error;
142 
143  /* test the outgoing callX28 to smsc center */
144  debug("smsc.sema", 0, "sema_open: test send link");
145  nret = X28_open_send_link(smsc->sema_fd, smsc->sema_smscnua);
146  if(nret < 1){
147  sleep(2);
148  nret = X28_open_send_link(smsc->sema_fd, smsc->sema_smscnua);
149  if(nret < 1)
150  goto error;
151  }
153  return smsc;
154 
155 error:
156  error(0, "sema_open: could not open");
157  smscenter_destruct(smsc);
158  return NULL;
159 }
void error(int err, const char *fmt,...)
Definition: log.c:612
static int X28_close_send_link(int padfd)
Definition: smsc_sema.c:564
struct sema_msglist * sema_mo
Definition: smsc_p.h:166
int sema_fd
Definition: smsc_p.h:167
SMSCenter * smscenter_construct(void)
Definition: smsc.c:101
void smscenter_destruct(SMSCenter *smsc)
Definition: smsc.c:168
char * sema_smscnua
Definition: smsc_p.h:163
static sema_msglist * sema_msglist_new(void)
Definition: smsc_sema.c:428
static int sema_wait_report
Definition: smsc_sema.c:110
char * sema_serialdevice
Definition: smsc_p.h:165
struct sema_msglist * sema_mt
Definition: smsc_p.h:166
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:690
char * sema_homenua
Definition: smsc_p.h:164
int type
Definition: smsc_p.h:93
static int X28_open_data_link(char *device)
Definition: smsc_sema.c:518
static int X28_open_send_link(int padfd, char *nua)
Definition: smsc_sema.c:611
char name[1024]
Definition: smsc_p.h:96
int sema_pending_smsmessage ( SMSCenter smsc)

Definition at line 365 of file smsc_sema.c.

References SMSCenter::buffer, debug(), error(), sema_msglist::first, SMSCenter::sema_fd, SMSCenter::sema_mo, sema_msg_session_mo(), SMSCenter::sema_serialdevice, X28_data_read(), X28_msg_pop(), and X28_reopen_data_link().

Referenced by smscenter_pending_smsmessage().

366 {
367 
368  char data[1024];
369  int ret = 0;
370  char clrbuff[]="CLR\0";
371  char errbuff[]="ERR\0";
372  /* struct sema_msg* smsg = NULL;*/
373 
374  /* Receive raw data */
375  ret = X28_data_read(smsc->sema_fd, smsc->buffer);
376  if(ret == -1) {
377  ret = X28_reopen_data_link(smsc->sema_fd, smsc->sema_serialdevice);
378  if(ret == -1) goto error;
379  return 0;
380  }
381 
382  /* Interpret the raw data */
383  memset(data,0,sizeof(data));
384  while(X28_msg_pop(smsc->buffer, data) == 0 ) {
385  if(strlen(data) > 0){
386  if(strstr(data,clrbuff) != NULL ||
387  strstr(data,errbuff) != NULL){
388  debug("smsc.sema", 0, "sema_pending_msg: Radio Pad Command line-%s",data);
389  }
390  else{
391 
392  ret = sema_msg_session_mo(smsc, data);
393  if(ret == -1) goto error;
394  }
395  memset(data,0,sizeof(data));
396  }
397  }
398 
399  /* Signal that we got a MO message if mo list is not empty*/
400  if(smsc->sema_mo->first != NULL){
401  return 1;
402  }
403 
404 
405  return 0;
406 
407 error:
408  error(0,"sema_pending message: device file error");
409  return -1;
410 }
void error(int err, const char *fmt,...)
Definition: log.c:612
struct sema_msglist * sema_mo
Definition: smsc_p.h:166
int sema_fd
Definition: smsc_p.h:167
static int sema_msg_session_mo(SMSCenter *smsc, char *cbuff)
Definition: smsc_sema.c:1173
static int X28_data_read(int padfd, char *cbuffer)
Definition: smsc_sema.c:713
static int X28_msg_pop(char *from, char *to)
Definition: smsc_sema.c:804
Octstr * data
Definition: smsc_cimd2.c:446
char * sema_serialdevice
Definition: smsc_p.h:165
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:690
char * buffer
Definition: smsc_p.h:184
sema_msg * first
Definition: smsc_sema.h:132
static int X28_reopen_data_link(int oldpadfd, char *device)
Definition: smsc_sema.c:551
int sema_receive_msg ( SMSCenter smsc,
Msg **  msg 
)

Definition at line 323 of file smsc_sema.c.

References DC_8BIT, sm_deliver_invoke::destadd, error(), msg_create, sema_msg::msgbody, octstr_create, octstr_create_from_data, octstr_duplicate, octstr_get_cstr, octstr_len(), sm_deliver_invoke::origadd, SMSCenter::sema_mo, sema_msg_free(), sema_msglist_pop(), and sm_deliver_invoke::shortmsg.

Referenced by smscenter_receive_msg().

324 {
325 
326  struct sema_msg *rmsg = NULL;
327  struct sm_deliver_invoke *recieve_sm = NULL;
328 
329  while(sema_msglist_pop(smsc->sema_mo, &rmsg) == 1 ) {
330 
331  *msg = msg_create(sms);
332  if(*msg==NULL) goto error;
333 
334  recieve_sm = (struct sm_deliver_invoke*) rmsg->msgbody;
335  if(recieve_sm==NULL) goto error;
336 
337  /* as IA5(8 bit character) is the default line encoding used by X28
338  * and we do not support other line encoding scheme like binary or
339  * hex encoding
340  */
341  (*msg)->sms.coding = DC_8BIT;
342  /* OIS in X28 implementation does not include udh field */
343 
344  (*msg)->sms.sender = octstr_create_from_data(
345  octstr_get_cstr(recieve_sm->origadd) +2,
346  octstr_len(recieve_sm->origadd)-2);
347  (*msg)->sms.receiver = octstr_create_from_data(
348  octstr_get_cstr(recieve_sm->destadd) +2,
349  octstr_len(recieve_sm->destadd)-2);
350 
351  (*msg)->sms.msgdata = octstr_duplicate(recieve_sm->shortmsg);
352  (*msg)->sms.udhdata = octstr_create("");
353  gw_free(recieve_sm);
354  sema_msg_free(rmsg);
355  rmsg = NULL;
356  }
357  return 1;
358 
359 error:
360  error(0, "sema_receive_msg: can not create Smart Msg");
361  return -1;
362 }
Octstr * shortmsg
Definition: smsc_sema.h:216
void error(int err, const char *fmt,...)
Definition: log.c:612
Octstr * destadd
Definition: smsc_sema.h:205
struct sema_msglist * sema_mo
Definition: smsc_p.h:166
#define DC_8BIT
Definition: sms.h:111
#define msg_create(type)
Definition: msg.h:136
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
static int sema_msglist_pop(sema_msglist *plist, sema_msg **msg)
Definition: smsc_sema.c:487
Octstr * origadd
Definition: smsc_sema.h:208
#define octstr_duplicate(ostr)
Definition: octstr.h:187
#define octstr_create(cstr)
Definition: octstr.h:125
long octstr_len(const Octstr *ostr)
Definition: octstr.c:340
void * msgbody
Definition: smsc_sema.h:124
static int sema_msg_free(sema_msg *msg)
Definition: smsc_sema.c:422
#define octstr_create_from_data(data, len)
Definition: octstr.h:134
int sema_reopen ( SMSCenter smsc)

Definition at line 162 of file smsc_sema.c.

References SMSCenter::buffer, debug(), error(), SMSCenter::sema_fd, SMSCenter::sema_mo, sema_msglist_free(), sema_msglist_new(), SMSCenter::sema_mt, SMSCenter::sema_serialdevice, SMSCenter::sema_smscnua, X28_close_send_link(), X28_open_send_link(), and X28_reopen_data_link().

Referenced by smsc_reopen().

163 {
164  int nret = 0;
165 
166  debug("smsc.sema", 0, "reopening the connection");
167 
168  /*deallocate*/
169  sema_msglist_free(smsc->sema_mt);
170  sema_msglist_free(smsc->sema_mo);
171  /*reallocate*/
172  smsc->sema_mt = sema_msglist_new();
173  if(smsc->sema_mt == NULL) goto error;
174  smsc->sema_mo = sema_msglist_new();
175  if(smsc->sema_mo == NULL) goto error;
176  memset(smsc->buffer,0,sizeof(smsc->buffer));
177 
178  /* Open the device properly. Remember to set the
179  access codes correctly. */
181  if(smsc->sema_fd == -1){
182  error(0,"sema_reopen_data_link: device file error");
183  goto error;
184  }
185  /*test outgoing call to the smsc */
186  nret = X28_open_send_link(smsc->sema_fd, smsc->sema_smscnua);
187  if(nret < 1){
188  error(0,"test send data link failed");
189  goto error;
190  }
192  return 0;
193 error:
194  error(0, "sema_reopen_data_link: failed");
195  return -1;
196 
197 }
void error(int err, const char *fmt,...)
Definition: log.c:612
static int X28_close_send_link(int padfd)
Definition: smsc_sema.c:564
struct sema_msglist * sema_mo
Definition: smsc_p.h:166
int sema_fd
Definition: smsc_p.h:167
static void sema_msglist_free(sema_msglist *mlist)
Definition: smsc_sema.c:440
char * sema_smscnua
Definition: smsc_p.h:163
static sema_msglist * sema_msglist_new(void)
Definition: smsc_sema.c:428
char * sema_serialdevice
Definition: smsc_p.h:165
struct sema_msglist * sema_mt
Definition: smsc_p.h:166
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:690
char * buffer
Definition: smsc_p.h:184
static int X28_open_send_link(int padfd, char *nua)
Definition: smsc_sema.c:611
static int X28_reopen_data_link(int oldpadfd, char *device)
Definition: smsc_sema.c:551
int sema_submit_msg ( SMSCenter smsc,
Msg msg 
)

Definition at line 210 of file smsc_sema.c.

References sm_submit_invoke::DCS, debug(), sema_msg::encodetype, error(), increment_counter(), info(), LINE_ENCODE_IA5, sema_msg::msgbody, sm_submit_invoke::msisdn, sm_submit_invoke::msisdnlen, octstr_copy, octstr_create_from_data, octstr_len(), sema_msg::optref, sm_submit_invoke::origadd, sm_submit_invoke::origaddlen, sm_submit_invoke::priority, sm_submit_invoke::protocal, sm_submit_invoke::replypath, sema_counter, sema_msg_free(), sema_msg_new(), sema_msg_session_mt(), sema_wait_report, SESSION_MT_RECEIVE_ERR, SESSION_MT_RECEIVE_SUCCESS, SESSION_MT_RECEIVE_TIMEOUT, sm_submit_invoke::shortmsg, sm_submit_invoke::smerefnum, sm_submit_invoke::smereftype, sm_submit_invoke::smscrefnum, sm_submit_invoke::statusreportrequest, sm_submit_invoke::textsizeoctect, sm_submit_invoke::textsizeseptet, sema_msg::type, sm_submit_invoke::validperiodrela, and sm_submit_invoke::validperiodtype.

Referenced by smscenter_submit_msg().

211 {
212  int nret = 0;
213  struct sema_msg *lmsg = NULL;
214  struct sm_submit_invoke *submit_sm = NULL;
215  char x28sender[2] = "A3";
216 
217  /* Validate msg */
218  if(smsc == NULL){
219  error(0,"sema_submit_msg: SMSC is empty");
220  goto error;
221  }
222  if(msg == NULL){
223  error(0, "sema_submit_msg: Msg is empty");
224  goto error;
225  }
226 
227  if(msg_type(msg) != sms) {
228  error(0, "sema_submit_sms: Msg is WRONG TYPE");
229  goto error;
230  }
231  /* user data header is not supported in sm2000 X25 access
232  if(msg->sms.coding == DC_7BIT ...|| DC_UNDEF?){
233  error(0, "sema_submit_sms: submit invoke support in IA5 encoding(8 bits chars)");
234  goto error;
235  }
236 
237  if(octstr_len(msg->sms.udhdata)){
238  error(0, "sema_submit_sms: submit invoke not support in IA5 encoding ");
239  goto error;
240  }
241  */
242  lmsg = sema_msg_new();
243 
244  submit_sm = gw_malloc(sizeof(struct sm_submit_invoke));
245  memset(submit_sm, 0, sizeof(struct sm_submit_invoke));
246 
247  lmsg->type = 'S';
248  lmsg->encodetype = LINE_ENCODE_IA5;
249 
250  /* set operation reference */
252  memcpy(lmsg->optref,sema_counter,4);
253  /*set sme reference number*/
255  memcpy(submit_sm->smerefnum, sema_counter, 4);
256  /*we send as not key type*/
257  submit_sm->smereftype= 2; /*key type is 1*/
258  /*we set prority as normal*/
259  submit_sm->priority = 1; /*0 is high*/
260  /*set valid period type as relative*/
261  submit_sm->validperiodtype = 2; /* 1 is absolute */
262  /*time*/
263  submit_sm->validperiodrela = 1; /* from 0 to 143 , fomula is (V+1)*5 min*/
264  /*send msg without 00 header*/
265  submit_sm->msisdnlen= octstr_len(msg->sms.receiver);
266  submit_sm->msisdn = octstr_copy(msg->sms.receiver,0,submit_sm->msisdnlen);
267  /* X25 access will always append sender during data transfer */
268  submit_sm->origaddlen= 2; /* we need only to orignate address type */
269  submit_sm->origadd = octstr_create_from_data(x28sender,2);
270  /*data encoding scheme ,support only IA5 in current version*/
271  submit_sm->DCS = 15; /*gsm is 0 ,IA5 is 15*/
272  /*protocal ,support only default value 0 in current version*/
273  submit_sm->protocal = 0;
274  /*replypath*/
275  submit_sm->replypath= 0; /*gateway do not pay for reply*/
276  /*status report*/
277  if(sema_wait_report > 0)
278  submit_sm->statusreportrequest =4; /* deliver success, in bin form 00000100*/
279  else
280  submit_sm->statusreportrequest = 0;/* no report */
281  /* we support submit invoke only in IA5 line encoding*/
282  submit_sm->textsizeoctect = submit_sm->textsizeseptet =
283  octstr_len(msg->sms.msgdata);
284  /*copy msg buffer*/
285  submit_sm->shortmsg = octstr_copy(msg->sms.msgdata,
286  0, submit_sm->textsizeoctect);
287 
288  memset(submit_sm->smscrefnum,0,sizeof(submit_sm->smscrefnum));
289  /*pack the message body in 2kmsg*/
290  lmsg->msgbody = submit_sm;
291  nret = sema_msg_session_mt(smsc, lmsg);
292 
293  gw_free(submit_sm);
294  submit_sm = NULL;
295  sema_msg_free(lmsg);
296  lmsg = NULL;
297 
298 
299  if(nret == SESSION_MT_RECEIVE_SUCCESS){
300  debug("smsc.sema", 0, "sema_submit_msg: message is successfully delivered");
301  return 1; /*success*/
302  }
303  else if(nret == SESSION_MT_RECEIVE_TIMEOUT){
304  info(0, "sema_submit msg: session timed out without return");
305  return 0;
306  }
307  else if(nret == SESSION_MT_RECEIVE_ERR){
308  info(0, "sema_submit msg: smsc says submit failed!");
309  return 0;
310  }
311 
312  return 1;
313 
314 error:
315  if(submit_sm)
316  gw_free(submit_sm);
317  if(lmsg)
318  sema_msg_free(lmsg);
319  return -1;
320 }
#define SESSION_MT_RECEIVE_ERR
Definition: smsc_sema.h:105
void error(int err, const char *fmt,...)
Definition: log.c:612
void info(int err, const char *fmt,...)
Definition: log.c:636
unsigned int statusreportrequest
Definition: smsc_sema.h:185
unsigned int textsizeoctect
Definition: smsc_sema.h:191
#define LINE_ENCODE_IA5
Definition: smsc_sema.h:92
unsigned int origaddlen
Definition: smsc_sema.h:177
unsigned int smereftype
Definition: smsc_sema.h:174
unsigned char optref[4]
Definition: smsc_sema.h:120
static int sema_msg_session_mt(SMSCenter *smsc, sema_msg *pmsg)
Definition: smsc_sema.c:940
msg_type
Definition: msg.h:73
unsigned int validperiodtype
Definition: smsc_sema.h:180
unsigned char smscrefnum[4]
Definition: smsc_sema.h:194
unsigned int validperiodrela
Definition: smsc_sema.h:182
#define octstr_copy(ostr, from, len)
Definition: octstr.h:178
unsigned int priority
Definition: smsc_sema.h:176
unsigned char type
Definition: smsc_sema.h:118
static void increment_counter(void)
Definition: smsc_sema.c:1858
unsigned int msisdnlen
Definition: smsc_sema.h:172
Octstr * msisdn
Definition: smsc_sema.h:173
#define SESSION_MT_RECEIVE_SUCCESS
Definition: smsc_sema.h:107
static unsigned char sema_counter[4]
Definition: smsc_sema.c:109
int encodetype
Definition: smsc_sema.h:121
unsigned int protocal
Definition: smsc_sema.h:188
unsigned int textsizeseptet
Definition: smsc_sema.h:190
unsigned int DCS
Definition: smsc_sema.h:184
Octstr * origadd
Definition: smsc_sema.h:178
static int sema_wait_report
Definition: smsc_sema.c:110
long octstr_len(const Octstr *ostr)
Definition: octstr.c:340
unsigned int replypath
Definition: smsc_sema.h:189
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:690
void * msgbody
Definition: smsc_sema.h:124
unsigned char smerefnum[4]
Definition: smsc_sema.h:175
static int sema_msg_free(sema_msg *msg)
Definition: smsc_sema.c:422
static sema_msg * sema_msg_new(void)
Definition: smsc_sema.c:414
Octstr * shortmsg
Definition: smsc_sema.h:192
#define octstr_create_from_data(data, len)
Definition: octstr.h:134
#define SESSION_MT_RECEIVE_TIMEOUT
Definition: smsc_sema.h:106
SMSCenter* smscenter_construct ( void  )

Definition at line 101 of file smsc.c.

References SMSCenter::allowed_prefix, SMSCenter::alt_charset, SMSCenter::buffer, SMSCenter::buflen, SMSCenter::bufsize, SMSCenter::cimd_hostname, SMSCenter::cimd_password, SMSCenter::cimd_port, SMSCenter::cimd_username, SMSCenter::denied_prefix, SMSCenter::emi_password, SMSCenter::emi_phonenum, SMSCenter::emi_serialdevice, SMSCenter::emi_username, SMSCenter::hostname, SMSCenter::id, SMSCenter::keepalive, SMSCenter::killed, SMSCenter::mutex, mutex_create, SMSCenter::name, SMSCenter::ois_ack_debt, SMSCenter::ois_alive, SMSCenter::ois_alive2, SMSCenter::ois_buffer, SMSCenter::ois_buflen, SMSCenter::ois_bufsize, SMSCenter::ois_flags, SMSCenter::ois_listening_socket, SMSCenter::ois_received_mo, SMSCenter::ois_socket, SMSCenter::port, SMSCenter::preferred_prefix, SMSCenter::sema_fd, SMSCenter::sema_homenua, SMSCenter::sema_serialdevice, SMSCenter::sema_smscnua, SMSC_TYPE_DELETED, SMSCenter::socket, and SMSCenter::type.

Referenced by cimd_open(), emi_open(), ois_open(), and sema_open().

102 {
103  SMSCenter *smsc;
104  static int next_id = 1;
105 
106  smsc = gw_malloc(sizeof(SMSCenter));
107 
108  smsc->killed = 0;
109  smsc->type = SMSC_TYPE_DELETED;
110  smsc->preferred_prefix = NULL;
111  smsc->allowed_prefix = NULL;
112  smsc->denied_prefix = NULL;
113  smsc->alt_charset = 0;
114  smsc->keepalive = 0;
115 
116  smsc->mutex = mutex_create();
117 
118  sprintf(smsc->name, "Unknown SMSC");
119  smsc->id = next_id++;
120 
121  /* FAKE */
122  smsc->hostname = NULL;
123  smsc->port = -1;
124  smsc->socket = -1;
125 
126  /* CIMD */
127  smsc->cimd_hostname = NULL;
128  smsc->cimd_port = -1;
129  smsc->cimd_username = NULL;
130  smsc->cimd_password = NULL;
131 
132  /* EMI_X25 */
133  smsc->emi_phonenum = NULL;
134  smsc->emi_serialdevice = NULL;
135  smsc->emi_username = NULL;
136  smsc->emi_password = NULL;
137 
138  /* SEMA SMS2000 */
139  smsc->sema_smscnua = NULL;
140  smsc->sema_homenua = NULL;
141  smsc->sema_serialdevice = NULL;
142  smsc->sema_fd = -1;
143 
144  /* SEMA SMS2000 OIS X.25 */
145  smsc->ois_alive = 0;
146  smsc->ois_alive2 = 0;
147  smsc->ois_received_mo = NULL;
148  smsc->ois_ack_debt = 0;
149  smsc->ois_flags = 0;
150  smsc->ois_listening_socket = -1;
151  smsc->ois_socket = -1;
152  smsc->ois_buflen = 0;
153  smsc->ois_bufsize = 0;
154  smsc->ois_buffer = 0;
155 
156  /* add new SMSCes here */
157 
158  /* Memory */
159  smsc->buflen = 0;
160  smsc->bufsize = 10*1024;
161  smsc->buffer = gw_malloc(smsc->bufsize);
162  memset(smsc->buffer, 0, smsc->bufsize);
163 
164  return smsc;
165 }
int ois_ack_debt
Definition: smsc_p.h:174
size_t bufsize
Definition: smsc_p.h:185
volatile sig_atomic_t killed
Definition: smsc_p.h:112
int id
Definition: smsc_p.h:97
char * preferred_prefix
Definition: smsc_p.h:100
char * emi_password
Definition: smsc_p.h:152
size_t ois_bufsize
Definition: smsc_p.h:179
int ois_flags
Definition: smsc_p.h:175
int sema_fd
Definition: smsc_p.h:167
#define mutex_create()
Definition: thread.h:96
size_t buflen
Definition: smsc_p.h:186
Mutex * mutex
Definition: smsc_p.h:109
void * ois_received_mo
Definition: smsc_p.h:173
int port
Definition: smsc_p.h:122
int ois_listening_socket
Definition: smsc_p.h:176
char * allowed_prefix
Definition: smsc_p.h:101
char * emi_phonenum
Definition: smsc_p.h:147
char * emi_username
Definition: smsc_p.h:151
char * sema_smscnua
Definition: smsc_p.h:163
char * emi_serialdevice
Definition: smsc_p.h:148
char * denied_prefix
Definition: smsc_p.h:102
int socket
Definition: smsc_p.h:115
char * sema_serialdevice
Definition: smsc_p.h:165
size_t ois_buflen
Definition: smsc_p.h:180
int cimd_port
Definition: smsc_p.h:138
char * ois_buffer
Definition: smsc_p.h:178
char * cimd_hostname
Definition: smsc_p.h:137
time_t ois_alive2
Definition: smsc_p.h:172
char * sema_homenua
Definition: smsc_p.h:164
int type
Definition: smsc_p.h:93
char * buffer
Definition: smsc_p.h:184
char * cimd_username
Definition: smsc_p.h:139
long alt_charset
Definition: smsc_p.h:106
char name[1024]
Definition: smsc_p.h:96
char * hostname
Definition: smsc_p.h:121
char * cimd_password
Definition: smsc_p.h:140
int ois_socket
Definition: smsc_p.h:177
int keepalive
Definition: smsc_p.h:118
time_t ois_alive
Definition: smsc_p.h:171
void smscenter_destruct ( SMSCenter smsc)

Definition at line 168 of file smsc.c.

References SMSCenter::buffer, SMSCenter::cimd_hostname, SMSCenter::cimd_password, SMSCenter::cimd_username, SMSCenter::emi_password, SMSCenter::emi_phonenum, SMSCenter::emi_serialdevice, SMSCenter::emi_username, SMSCenter::hostname, SMSCenter::mutex, mutex_destroy(), SMSCenter::ois_buffer, ois_delete_queue(), SMSCenter::sema_homenua, SMSCenter::sema_serialdevice, and SMSCenter::sema_smscnua.

Referenced by cimd_open(), emi_open(), ois_open(), and sema_open().

169 {
170  if (smsc == NULL)
171  return;
172 
173  /* FAKE */
174  gw_free(smsc->hostname);
175 
176  /* CIMD */
177  gw_free(smsc->cimd_hostname);
178  gw_free(smsc->cimd_username);
179  gw_free(smsc->cimd_password);
180 
181  /* EMI_X25 */
182  gw_free(smsc->emi_phonenum);
183  gw_free(smsc->emi_serialdevice);
184  gw_free(smsc->emi_username);
185  gw_free(smsc->emi_password);
186 
187  /* SEMA */
188  gw_free(smsc->sema_smscnua);
189  gw_free(smsc->sema_homenua);
190  gw_free(smsc->sema_serialdevice);
191 
192  /* OIS */
193  ois_delete_queue(smsc);
194  gw_free(smsc->ois_buffer);
195 
196  /* add new SMSCes here */
197 
198  /* Other fields */
199  mutex_destroy(smsc->mutex);
200 
201  /* Memory */
202  gw_free(smsc->buffer);
203  gw_free(smsc);
204 }
char * emi_password
Definition: smsc_p.h:152
Mutex * mutex
Definition: smsc_p.h:109
char * emi_phonenum
Definition: smsc_p.h:147
char * emi_username
Definition: smsc_p.h:151
char * sema_smscnua
Definition: smsc_p.h:163
void mutex_destroy(Mutex *mutex)
Definition: thread.c:97
char * emi_serialdevice
Definition: smsc_p.h:148
char * sema_serialdevice
Definition: smsc_p.h:165
char * ois_buffer
Definition: smsc_p.h:178
char * cimd_hostname
Definition: smsc_p.h:137
char * sema_homenua
Definition: smsc_p.h:164
void ois_delete_queue(SMSCenter *smsc)
Definition: smsc_ois.c:423
char * buffer
Definition: smsc_p.h:184
char * cimd_username
Definition: smsc_p.h:139
char * hostname
Definition: smsc_p.h:121
char * cimd_password
Definition: smsc_p.h:140
int smscenter_pending_smsmessage ( SMSCenter smsc)

Definition at line 302 of file smsc.c.

References cimd_pending_smsmessage(), emi_pending_smsmessage(), error(), ois_pending_smsmessage(), sema_pending_smsmessage(), SMSC_TYPE_CIMD, SMSC_TYPE_EMI_X25, SMSC_TYPE_OIS, SMSC_TYPE_SEMA_X28, smscenter_lock(), smscenter_unlock(), and SMSCenter::type.

Referenced by sms_receive().

303 {
304  int ret;
305 
306  smscenter_lock(smsc);
307 
308  switch (smsc->type) {
309 
310  case SMSC_TYPE_CIMD:
311  ret = cimd_pending_smsmessage(smsc);
312  if (ret == -1)
313  goto error;
314  break;
315 
316  case SMSC_TYPE_EMI_X25:
317  ret = emi_pending_smsmessage(smsc);
318  if (ret == -1)
319  goto error;
320  break;
321 
322  case SMSC_TYPE_SEMA_X28:
323  ret = sema_pending_smsmessage(smsc);
324  if (ret == -1)
325  goto error;
326  break;
327 
328  case SMSC_TYPE_OIS:
329  ret = ois_pending_smsmessage(smsc);
330  if (ret == -1)
331  goto error;
332  break;
333 
334  default:
335  goto error;
336  }
337 
338  smscenter_unlock(smsc);
339  return ret;
340 
341 error:
342  error(0, "smscenter_pending_smsmessage is failing");
343  smscenter_unlock(smsc);
344  return -1;
345 }
int ois_pending_smsmessage(SMSCenter *smsc)
Definition: smsc_ois.c:318
void error(int err, const char *fmt,...)
Definition: log.c:612
int emi_pending_smsmessage(SMSCenter *smsc)
Definition: smsc_emi_x25.c:319
int sema_pending_smsmessage(SMSCenter *smsc)
Definition: smsc_sema.c:365
static void smscenter_lock(SMSCenter *smsc)
Definition: smsc.c:422
int type
Definition: smsc_p.h:93
int cimd_pending_smsmessage(SMSCenter *smsc)
Definition: smsc_cimd.c:264
static void smscenter_unlock(SMSCenter *smsc)
Definition: smsc.c:433
int smscenter_read_into_buffer ( SMSCenter )

Definition at line 348 of file smsc.c.

References SMSCenter::buffer, SMSCenter::buflen, SMSCenter::bufsize, error(), SMSCenter::hostname, MAX_READ_INTO_BUFFER, SMSCenter::port, and SMSCenter::socket.

Referenced by cimd_open_connection(), cimd_pending_smsmessage(), connect_tcpip(), expect_acknowledge(), and ois_read_into_buffer().

349 {
350  char *p;
351  int ret;
352  fd_set read_fd;
353  struct timeval tv, tvinit;
354  size_t bytes_read;
355 
356  tvinit.tv_sec = 0;
357  tvinit.tv_usec = 1000;
358 
359  bytes_read = 0;
360  for (;;) {
361  FD_ZERO(&read_fd);
362  FD_SET(smsc->socket, &read_fd);
363  tv = tvinit;
364  ret = select(smsc->socket + 1, &read_fd, NULL, NULL, &tv);
365  if (ret == -1) {
366  if (errno == EINTR) goto got_data;
367  if (errno == EAGAIN) goto got_data;
368  error(errno, "Error doing select for socket");
369  goto error;
370  } else if (ret == 0)
371  goto got_data;
372 
373  if (smsc->buflen == smsc->bufsize) {
374  p = gw_realloc(smsc->buffer, smsc->bufsize * 2);
375  smsc->buffer = p;
376  smsc->bufsize *= 2;
377  }
378 
379  ret = read(smsc->socket,
380  smsc->buffer + smsc->buflen,
381  1);
382  if (ret == -1) {
383  error(errno, "Reading from `%s' port `%d' failed.",
384  smsc->hostname, smsc->port);
385  goto error;
386  }
387  if (ret == 0)
388  goto eof;
389  smsc->buflen += ret;
390  bytes_read += ret;
391  if (bytes_read >= MAX_READ_INTO_BUFFER)
392  break;
393  }
394 
395 eof:
396  ret = 0;
397  goto unblock;
398 
399 got_data:
400  ret = 1;
401  goto unblock;
402 
403 error:
404  ret = -1;
405  goto unblock;
406 
407 unblock:
408  return ret;
409 }
void error(int err, const char *fmt,...)
Definition: log.c:612
#define MAX_READ_INTO_BUFFER
Definition: smsc.c:84
int smscenter_receive_msg ( SMSCenter smsc,
Msg **  msg 
)

Definition at line 251 of file smsc.c.

References cimd_receive_msg(), emi_receive_msg(), error(), ois_receive_msg(), sema_receive_msg(), SMSC_TYPE_CIMD, SMSC_TYPE_EMI_X25, SMSC_TYPE_OIS, SMSC_TYPE_SEMA_X28, smscenter_lock(), smscenter_unlock(), and SMSCenter::type.

Referenced by sms_receive().

252 {
253  int ret;
254 
255  smscenter_lock(smsc);
256 
257  switch (smsc->type) {
258 
259  case SMSC_TYPE_CIMD:
260  ret = cimd_receive_msg(smsc, msg);
261  if (ret == -1)
262  goto error;
263  break;
264 
265  case SMSC_TYPE_EMI_X25:
266  ret = emi_receive_msg(smsc, msg);
267  if (ret == -1)
268  goto error;
269  break;
270 
271  case SMSC_TYPE_OIS:
272  ret = ois_receive_msg(smsc, msg);
273  if (ret == -1)
274  goto error;
275  break;
276 
277 
278  case SMSC_TYPE_SEMA_X28:
279  ret = sema_receive_msg(smsc, msg);
280  if (ret == -1)
281  goto error;
282  break;
283 
284  default:
285  goto error;
286 
287  }
288  smscenter_unlock(smsc);
289 
290  /* If the SMSC didn't set the timestamp, set it here. */
291  if (ret == 1 && msg_type(*msg) == sms && (*msg)->sms.time == 0)
292  time(&(*msg)->sms.time);
293 
294  return ret;
295 
296 error:
297  smscenter_unlock(smsc);
298  return -1;
299 }
void error(int err, const char *fmt,...)
Definition: log.c:612
int sema_receive_msg(SMSCenter *smsc, Msg **msg)
Definition: smsc_sema.c:323
int ois_receive_msg(SMSCenter *smsc, Msg **msg)
Definition: smsc_ois.c:396
int cimd_receive_msg(SMSCenter *smsc, Msg **msg)
Definition: smsc_cimd.c:470
msg_type
Definition: msg.h:73
int emi_receive_msg(SMSCenter *smsc, Msg **tmsg)
Definition: smsc_emi_x25.c:408
static void smscenter_lock(SMSCenter *smsc)
Definition: smsc.c:422
int type
Definition: smsc_p.h:93
static void smscenter_unlock(SMSCenter *smsc)
Definition: smsc.c:433
void smscenter_remove_from_buffer ( SMSCenter smsc,
size_t  n 
)

Definition at line 412 of file smsc.c.

References SMSCenter::buffer, and SMSCenter::buflen.

Referenced by cimd_open_connection(), cimd_pending_smsmessage(), cimd_receive_msg(), connect_tcpip(), expect_acknowledge(), ois_close(), ois_extract_line_from_buffer(), and ois_extract_msg_from_buffer().

413 {
414  memmove(smsc->buffer, smsc->buffer + n, smsc->buflen - n);
415  smsc->buflen -= n;
416 }
size_t buflen
Definition: smsc_p.h:186
char * buffer
Definition: smsc_p.h:184
int smscenter_submit_msg ( SMSCenter smsc,
Msg msg 
)

Definition at line 209 of file smsc.c.

References cimd_submit_msg(), emi_submit_msg(), error(), ois_submit_msg(), sema_submit_msg(), SMSC_TYPE_CIMD, SMSC_TYPE_EMI_X25, SMSC_TYPE_OIS, SMSC_TYPE_SEMA_X28, smscenter_lock(), smscenter_unlock(), and SMSCenter::type.

Referenced by sms_send().

210 {
211  smscenter_lock(smsc);
212 
213  switch (smsc->type) {
214 
215  case SMSC_TYPE_CIMD:
216  if (cimd_submit_msg(smsc, msg) == -1)
217  goto error;
218  break;
219 
220  case SMSC_TYPE_EMI_X25:
221  if (emi_submit_msg(smsc, msg) == -1)
222  goto error;
223  break;
224 
225  case SMSC_TYPE_SEMA_X28:
226  if (sema_submit_msg(smsc, msg) == -1)
227  goto error;
228  break;
229 
230  case SMSC_TYPE_OIS:
231  if (ois_submit_msg(smsc, msg) == -1)
232  goto error;
233  break;
234 
235  /* add new SMSCes here */
236 
237  default:
238  goto error;
239  }
240 
241  smscenter_unlock(smsc);
242  return 0;
243 
244 error:
245  smscenter_unlock(smsc);
246  return -1;
247 }
void error(int err, const char *fmt,...)
Definition: log.c:612
int cimd_submit_msg(SMSCenter *smsc, Msg *msg)
Definition: smsc_cimd.c:358
int ois_submit_msg(SMSCenter *smsc, const Msg *msg)
Definition: smsc_ois.c:346
int emi_submit_msg(SMSCenter *smsc, Msg *omsg)
Definition: smsc_emi_x25.c:372
int sema_submit_msg(SMSCenter *smsc, Msg *msg)
Definition: smsc_sema.c:210
static void smscenter_lock(SMSCenter *smsc)
Definition: smsc.c:422
int type
Definition: smsc_p.h:93
static void smscenter_unlock(SMSCenter *smsc)
Definition: smsc.c:433
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.