Kannel: Open Source WAP and SMS gateway  $Revision: 5037 $
bb_smscconn_cb.h File Reference
#include "msg.h"
#include "smscconn.h"

Go to the source code of this file.

Enumerations

enum  {
  SMSCCONN_SUCCESS = 0, SMSCCONN_QUEUED, SMSCCONN_FAILED_SHUTDOWN, SMSCCONN_FAILED_REJECTED,
  SMSCCONN_FAILED_MALFORMED, SMSCCONN_FAILED_TEMPORARILY, SMSCCONN_FAILED_DISCARDED, SMSCCONN_FAILED_QFULL,
  SMSCCONN_FAILED_EXPIRED
}
 

Functions

void bb_smscconn_ready (SMSCConn *conn)
 
void bb_smscconn_connected (SMSCConn *conn)
 
void bb_smscconn_killed (void)
 
void bb_smscconn_sent (SMSCConn *conn, Msg *sms, Octstr *reply)
 
void bb_smscconn_send_failed (SMSCConn *conn, Msg *sms, int reason, Octstr *reply)
 
long bb_smscconn_receive (SMSCConn *conn, Msg *sms)
 

Enumeration Type Documentation

anonymous enum
Enumerator
SMSCCONN_SUCCESS 
SMSCCONN_QUEUED 
SMSCCONN_FAILED_SHUTDOWN 
SMSCCONN_FAILED_REJECTED 
SMSCCONN_FAILED_MALFORMED 
SMSCCONN_FAILED_TEMPORARILY 
SMSCCONN_FAILED_DISCARDED 
SMSCCONN_FAILED_QFULL 
SMSCCONN_FAILED_EXPIRED 

Definition at line 107 of file bb_smscconn_cb.h.

Function Documentation

void bb_smscconn_connected ( SMSCConn conn)

Definition at line 192 of file bb_smscconn.c.

References gwthread_wakeup(), and router_thread.

Referenced by at2_device_thread(), cgw_open_send_connection(), cgw_sender(), fake_listener(), handle_pdu(), httpsmsc_send_cb(), io_thread(), open_send_connection(), reconnect(), and soap_listener().

193 {
194  if (router_thread >= 0)
196 }
static long router_thread
Definition: bb_smscconn.c:149
void gwthread_wakeup(long thread)
void bb_smscconn_killed ( void  )

Definition at line 199 of file bb_smscconn.c.

References gwlist_remove_producer().

Referenced by at2_device_thread(), cgw_sender(), cimd2_shutdown_cb(), emi2_sender(), fake_listener(), httpsmsc_receiver(), httpsmsc_sender(), io_thread(), oisd_shutdown_cb(), shutdown_cb(), soap_listener(), and wrapper_sender().

200 {
201  /* NOTE: after status has been set to SMSCCONN_DEAD, bearerbox
202  * is free to release/delete 'conn'
203  */
206 }
List * flow_threads
Definition: bearerbox.c:116
List * incoming_sms
Definition: bearerbox.c:84
void gwlist_remove_producer(List *list)
Definition: list.c:401
void bb_smscconn_ready ( SMSCConn conn)

Definition at line 185 of file bb_smscconn.c.

References gwlist_add_producer().

Referenced by smscconn_create().

186 {
189 }
List * flow_threads
Definition: bearerbox.c:116
List * incoming_sms
Definition: bearerbox.c:84
void gwlist_add_producer(List *list)
Definition: list.c:383
long bb_smscconn_receive ( SMSCConn conn,
Msg sms 
)

Definition at line 478 of file bb_smscconn.c.

References bb_alog_sms(), bb_smscconn_receive_internal(), black_list_receiver_regex, black_list_sender_regex, concat_complete, concat_error, concat_handling_check_and_handle(), concat_none, concat_pending, counter_increase(), gw_rwlock_rdlock(), gw_rwlock_unlock(), handle_concatenated_mo, smscconn::id, smscconn::incoming_sms_load, info(), load_increase, mo, msg_destroy(), normalize_number(), numhash_find_number(), octstr_create, octstr_get_cstr, panic, smscconn::received, report_mo, SMSCCONN_FAILED_REJECTED, SMSCCONN_FAILED_TEMPORARILY, SMSCCONN_SUCCESS, store_save, smscconn::unified_prefix, white_list_receiver_regex, and white_list_sender_regex.

Referenced by at2_wait_modem_command(), bb_smscconn_send_failed(), bb_smscconn_sent(), brunet_receive_sms(), cgw_handle_op(), clickatell_receive_sms(), generic_receive_sms(), handle_operation(), handle_pdu(), io_thread(), kannel_receive_sms(), main_connection_loop(), msg_cb(), msg_to_bb(), soap_parse_dlr(), soap_parse_mo(), wrapper_receiver(), and xidris_receive_sms().

479 {
480  char *uf;
481  int ret;
482 
483  /*
484  * first check whether msgdata data is NULL and set it to empty
485  * because seems too much kannels parts rely on msgdata not to be NULL.
486  */
487  if (sms->sms.msgdata == NULL)
488  sms->sms.msgdata = octstr_create("");
489 
490  /*
491  * First normalize in smsc level and then on global level.
492  * In outbound direction it's vise versa, hence first global then smsc.
493  */
494  uf = (conn && conn->unified_prefix) ? octstr_get_cstr(conn->unified_prefix) : NULL;
495  normalize_number(uf, &(sms->sms.sender));
496 
498  normalize_number(uf, &(sms->sms.sender));
499 
500  /*
501  * We don't perform white/black-listing for DLRs.
502  * Fix sms type if not set already.
503  */
504  if (sms->sms.sms_type != report_mo) {
505  sms->sms.sms_type = mo;
506 
508  if (white_list_sender &&
509  numhash_find_number(white_list_sender, sms->sms.sender) < 1) {
511  info(0, "Number <%s> is not in white-list, message discarded",
512  octstr_get_cstr(sms->sms.sender));
513  bb_alog_sms(conn, sms, "REJECTED Receive SMS - not white-listed SMS");
514  msg_destroy(sms);
516  }
517 
519  gw_regex_match_pre(white_list_sender_regex, sms->sms.sender) == 0) {
521  info(0, "Number <%s> is not in white-list, message discarded",
522  octstr_get_cstr(sms->sms.sender));
523  bb_alog_sms(conn, sms, "REJECTED Receive SMS - not white-regex-listed SMS");
524  msg_destroy(sms);
526  }
527 
528  if (black_list_sender &&
529  numhash_find_number(black_list_sender, sms->sms.sender) == 1) {
531  info(0, "Number <%s> is in black-list, message discarded",
532  octstr_get_cstr(sms->sms.sender));
533  bb_alog_sms(conn, sms, "REJECTED Receive SMS - black-listed SMS");
534  msg_destroy(sms);
536  }
537 
539  gw_regex_match_pre(black_list_sender_regex, sms->sms.sender) == 0) {
541  info(0, "Number <%s> is not in black-list, message discarded",
542  octstr_get_cstr(sms->sms.sender));
543  bb_alog_sms(conn, sms, "REJECTED Receive SMS - black-regex-listed SMS");
544  msg_destroy(sms);
546  }
547 
548  if (white_list_receiver &&
549  numhash_find_number(white_list_receiver, sms->sms.receiver) < 1) {
551  info(0, "Number <%s> is not in white-list-receiver, message discarded",
552  octstr_get_cstr(sms->sms.receiver));
553  bb_alog_sms(conn, sms, "REJECTED Receive SMS - not white-listed SMS");
554  msg_destroy(sms);
556  }
557 
559  gw_regex_match_pre(white_list_receiver_regex, sms->sms.receiver) == 0) {
561  info(0, "Number <%s> is not in white-list-receiver, message discarded",
562  octstr_get_cstr(sms->sms.receiver));
563  bb_alog_sms(conn, sms, "REJECTED Receive SMS - not white-regex-listed SMS");
564  msg_destroy(sms);
566  }
567 
568  if (black_list_receiver &&
569  numhash_find_number(black_list_receiver, sms->sms.receiver) == 1) {
571  info(0, "Number <%s> is in black-list-receiver, message discarded",
572  octstr_get_cstr(sms->sms.receiver));
573  bb_alog_sms(conn, sms, "REJECTED Receive SMS - black-listed SMS");
574  msg_destroy(sms);
576  }
577 
579  gw_regex_match_pre(black_list_receiver_regex, sms->sms.receiver) == 0) {
581  info(0, "Number <%s> is not in black-list-receiver, message discarded",
582  octstr_get_cstr(sms->sms.receiver));
583  bb_alog_sms(conn, sms, "REJECTED Receive SMS - black-regex-listed SMS");
584  msg_destroy(sms);
586  }
588  }
589 
590  /* write to store (if enabled) */
591  if (store_save(sms) == -1) {
592  msg_destroy(sms);
594  }
595 
596  /* Before routing to some box or re-routing, do concatenation handling
597  * and replace copy as such.
598  */
599  if (handle_concatenated_mo && sms->sms.sms_type == mo) {
600  ret = concat_handling_check_and_handle(&sms, (conn ? conn->id : NULL));
601  switch(ret) {
602  case concat_pending:
605  if (conn != NULL) {
606  counter_increase(conn->received);
608  }
609  return SMSCCONN_SUCCESS;
610  case concat_complete:
611  /* Combined sms received! save new one since it is now combined. */
612  break;
613  case concat_error:
614  /* failed to save, go away. */
615  msg_destroy(sms);
617  case concat_none:
618  break;
619  default:
620  panic(0, "Internal error: Unhandled concat result.");
621  break;
622  }
623  }
624 
625  return bb_smscconn_receive_internal(conn, sms);
626 }
Load * incoming_sms_load
Definition: smscconn_p.h:215
void bb_alog_sms(SMSCConn *conn, Msg *msg, const char *message)
Definition: bb_alog.c:374
void info(int err, const char *fmt,...)
Definition: log.c:636
Counter * incoming_sms_counter
Definition: bearerbox.c:90
Definition: msg.h:106
static regex_t * white_list_sender_regex
Definition: bb_smscconn.c:144
Definition: msg.h:109
Octstr * id
Definition: smscconn_p.h:174
static regex_t * black_list_receiver_regex
Definition: bb_smscconn.c:147
int gw_rwlock_rdlock(RWLock *lock)
Definition: gw-rwlock.c:134
static long bb_smscconn_receive_internal(SMSCConn *conn, Msg *sms)
Definition: bb_smscconn.c:417
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
static RWLock white_black_list_lock
Definition: bb_smscconn.c:134
Load * incoming_sms_load
Definition: bearerbox.c:103
unsigned long counter_increase(Counter *counter)
Definition: counter.c:123
static Numhash * white_list_sender
Definition: bb_smscconn.c:140
int numhash_find_number(Numhash *table, Octstr *nro)
Definition: numhash.c:218
static Numhash * black_list_sender
Definition: bb_smscconn.c:139
Octstr * unified_prefix
Definition: smscconn_p.h:190
void msg_destroy(Msg *msg)
Definition: msg.c:132
int gw_rwlock_unlock(RWLock *lock)
Definition: gw-rwlock.c:155
#define octstr_create(cstr)
Definition: octstr.h:125
static regex_t * white_list_receiver_regex
Definition: bb_smscconn.c:146
Counter * received
Definition: smscconn_p.h:162
#define load_increase(load)
Definition: load.h:94
static Numhash * white_list_receiver
Definition: bb_smscconn.c:142
#define panic
Definition: log.h:87
int normalize_number(char *dial_prefixes, Octstr **number)
Definition: utils.c:882
int(* store_save)(Msg *msg)
Definition: bb_store.c:72
static Octstr * unified_prefix
Definition: bb_smscconn.c:132
static regex_t * black_list_sender_regex
Definition: bb_smscconn.c:145
static volatile sig_atomic_t handle_concatenated_mo
Definition: bb_smscconn.c:162
static Numhash * black_list_receiver
Definition: bb_smscconn.c:141
static int concat_handling_check_and_handle(Msg **msg, Octstr *smscid)
Definition: bb_smscconn.c:2154
void bb_smscconn_send_failed ( SMSCConn conn,
Msg sms,
int  reason,
Octstr reply 
)

Definition at line 328 of file bb_smscconn.c.

References ack_failed, bb_alog_sms(), bb_smscconn_receive(), bb_smscconn_send_failed(), counter_increase(), create_dlr_from_msg(), DLR_IS_FAIL, DLR_IS_SMSC_FAIL, DLR_SMSC_FAIL, smscconn::failed, gwlist_produce(), handle_split(), smscconn::id, msg_destroy(), smscconn::name, octstr_create, octstr_destroy(), octstr_insert_data(), report_mt, sms_resend_retry, SMSCCONN_ACTIVE, SMSCCONN_FAILED_DISCARDED, SMSCCONN_FAILED_EXPIRED, SMSCCONN_FAILED_REJECTED, SMSCCONN_FAILED_SHUTDOWN, SMSCCONN_FAILED_TEMPORARILY, smscconn_status(), store_save_ack, and warning().

Referenced by at2_send_one_message(), at2_shutdown_cb(), bb_smscconn_send_failed(), brunet_parse_reply(), cgw_handle_op(), cgw_open_send_connection(), cgw_sender(), cgw_shutdown_cb(), cimd2_shutdown_cb(), cimd2_submit_msg(), clickatell_parse_reply(), do_queue_cleanup(), emi2_handle_smscreq(), emi2_sender(), fake_listener(), generic_parse_reply(), handle_pdu(), handle_split(), httpsmsc_send_cb(), httpsmsc_sender(), io_thread(), kannel_parse_reply(), main_connection_loop(), oisd_shutdown_cb(), oisd_submit_msg(), open_send_connection(), reconnect(), send_messages(), shutdown_cb(), sms_send(), smsc2_rout(), soap_listener(), soap_read_response(), soap_send_loop(), soap_shutdown_cb(), wapme_smsproxy_parse_reply(), wrapper_sender(), wrapper_shutdown(), and xidris_parse_reply().

329 {
330  if (sms->sms.split_parts != NULL) {
331  handle_split(conn, sms, reason);
332  octstr_destroy(reply);
333  return;
334  }
335 
336  switch (reason) {
338  /*
339  * Check if SMSC link alive and if so increase resend_try and set resend_time.
340  * If SMSC link is not active don't increase resend_try and don't set resend_time
341  * because we don't want to delay messages due to a broken connection.
342  */
343  if (conn && smscconn_status(conn) == SMSCCONN_ACTIVE) {
344  /*
345  * Check if sms_resend_retry set and this msg has exceeded a limit also
346  * honor "single shot" with sms_resend_retry set to zero.
347  */
348  if (sms_resend_retry >= 0 && sms->sms.resend_try >= sms_resend_retry) {
349  warning(0, "Maximum retries for message exceeded, discarding it!");
351  octstr_create("Retries Exceeded"));
352  break;
353  }
354  sms->sms.resend_try = (sms->sms.resend_try > 0 ? sms->sms.resend_try + 1 : 1);
355  time(&sms->sms.resend_time);
356  }
358  break;
359 
362  break;
363 
364  default:
365  /* write NACK to store file */
367 
368  if (conn) counter_increase(conn->failed);
369  if (reason == SMSCCONN_FAILED_DISCARDED) {
370  if (sms->sms.sms_type != report_mt)
371  bb_alog_sms(conn, sms, "DISCARDED SMS");
372  else
373  bb_alog_sms(conn, sms, "DISCARDED DLR");
374  }
375  else if (reason == SMSCCONN_FAILED_EXPIRED) {
376  if (sms->sms.sms_type != report_mt)
377  bb_alog_sms(conn, sms, "EXPIRED SMS");
378  else
379  bb_alog_sms(conn, sms, "EXPIRED DLR");
380  }
381  else if (reason == SMSCCONN_FAILED_REJECTED) {
382  if (sms->sms.sms_type != report_mt)
383  bb_alog_sms(conn, sms, "REJECTED Send SMS");
384  else
385  bb_alog_sms(conn, sms, "REJECTED Send DLR");
386  }
387  else {
388  if (sms->sms.sms_type != report_mt)
389  bb_alog_sms(conn, sms, "FAILED Send SMS");
390  else
391  bb_alog_sms(conn, sms, "FAILED Send DLR");
392  }
393 
394  /* generate relay confirmancy message */
395  if (DLR_IS_SMSC_FAIL(sms->sms.dlr_mask) ||
396  DLR_IS_FAIL(sms->sms.dlr_mask)) {
397  Msg *dlrmsg;
398 
399  if (reply == NULL)
400  reply = octstr_create("");
401 
402  octstr_insert_data(reply, 0, "NACK/", 5);
403  dlrmsg = create_dlr_from_msg((conn ? (conn->id?conn->id:conn->name) : NULL), sms,
404  reply, DLR_SMSC_FAIL);
405  if (dlrmsg != NULL) {
406  bb_smscconn_receive(conn, dlrmsg);
407  }
408  }
409 
410  msg_destroy(sms);
411  break;
412  }
413 
414  octstr_destroy(reply);
415 }
Octstr * name
Definition: smscconn_p.h:173
void bb_alog_sms(SMSCConn *conn, Msg *msg, const char *message)
Definition: bb_alog.c:374
void gwlist_produce(List *list, void *item)
Definition: list.c:411
Octstr * id
Definition: smscconn_p.h:174
int(* store_save_ack)(Msg *msg, ack_status_t status)
Definition: bb_store.c:73
Counter * failed
Definition: smscconn_p.h:166
Msg * create_dlr_from_msg(const Octstr *smsc, const Msg *msg, const Octstr *reply, long stat)
Definition: dlr.c:501
#define DLR_IS_FAIL(dlr)
Definition: dlr.h:87
List * outgoing_sms
Definition: bearerbox.c:85
static long sms_resend_retry
Definition: bb_smscconn.c:153
Definition: msg.h:110
void octstr_insert_data(Octstr *ostr, long pos, const char *data, long len)
Definition: octstr.c:1459
unsigned long counter_increase(Counter *counter)
Definition: counter.c:123
#define DLR_IS_SMSC_FAIL(dlr)
Definition: dlr.h:90
Definition: msg.h:79
int smscconn_status(SMSCConn *conn)
Definition: smscconn.c:665
long bb_smscconn_receive(SMSCConn *conn, Msg *sms)
Definition: bb_smscconn.c:478
void msg_destroy(Msg *msg)
Definition: msg.c:132
void warning(int err, const char *fmt,...)
Definition: log.c:624
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:322
#define octstr_create(cstr)
Definition: octstr.h:125
#define DLR_SMSC_FAIL
Definition: dlr.h:76
static void handle_split(SMSCConn *conn, Msg *msg, long reason)
Definition: bb_smscconn.c:209
void bb_smscconn_send_failed(SMSCConn *conn, Msg *sms, int reason, Octstr *reply)
Definition: bb_smscconn.c:328
void bb_smscconn_sent ( SMSCConn conn,
Msg sms,
Octstr reply 
)

Definition at line 279 of file bb_smscconn.c.

References ack_success, bb_alog_sms(), bb_smscconn_receive(), counter_increase(), create_dlr_from_msg(), DLR_IS_SMSC_SUCCESS, DLR_SMSC_SUCCESS, handle_split(), smscconn::id, load_increase, msg_destroy(), smscconn::name, octstr_create, octstr_destroy(), octstr_insert_data(), smscconn::outgoing_dlr_load, smscconn::outgoing_sms_load, report_mt, smscconn::sent, smscconn::sent_dlr, SMSCCONN_SUCCESS, and store_save_ack.

Referenced by at2_send_one_message(), brunet_parse_reply(), cgw_handle_op(), cimd2_submit_msg(), clickatell_parse_reply(), emi2_handle_smscreq(), generic_parse_reply(), handle_pdu(), handle_split(), kannel_parse_reply(), main_connection_loop(), msg_cb(), oisd_submit_msg(), sms_send(), soap_read_response(), wapme_smsproxy_parse_reply(), and xidris_parse_reply().

280 {
281  if (sms->sms.split_parts != NULL) {
282  handle_split(conn, sms, SMSCCONN_SUCCESS);
283  octstr_destroy(reply);
284  return;
285  }
286 
287  /* write ACK to store file */
289 
290  if (sms->sms.sms_type != report_mt) {
291  bb_alog_sms(conn, sms, "Sent SMS");
294  if (conn != NULL) {
295  counter_increase(conn->sent);
297  }
298  } else {
299  bb_alog_sms(conn, sms, "Sent DLR");
302  if (conn != NULL) {
303  counter_increase(conn->sent_dlr);
305  }
306  }
307 
308  /* generate relay confirmancy message */
309  if (DLR_IS_SMSC_SUCCESS(sms->sms.dlr_mask)) {
310  Msg *dlrmsg;
311 
312  if (reply == NULL)
313  reply = octstr_create("");
314 
315  octstr_insert_data(reply, 0, "ACK/", 4);
316  dlrmsg = create_dlr_from_msg((conn->id?conn->id:conn->name), sms,
317  reply, DLR_SMSC_SUCCESS);
318  if (dlrmsg != NULL) {
319  bb_smscconn_receive(conn, dlrmsg);
320  }
321  }
322 
323  msg_destroy(sms);
324  octstr_destroy(reply);
325 }
Octstr * name
Definition: smscconn_p.h:173
void bb_alog_sms(SMSCConn *conn, Msg *msg, const char *message)
Definition: bb_alog.c:374
Load * outgoing_dlr_load
Definition: bearerbox.c:105
Counter * outgoing_sms_counter
Definition: bearerbox.c:91
Octstr * id
Definition: smscconn_p.h:174
int(* store_save_ack)(Msg *msg, ack_status_t status)
Definition: bb_store.c:73
Msg * create_dlr_from_msg(const Octstr *smsc, const Msg *msg, const Octstr *reply, long stat)
Definition: dlr.c:501
Definition: msg.h:110
void octstr_insert_data(Octstr *ostr, long pos, const char *data, long len)
Definition: octstr.c:1459
unsigned long counter_increase(Counter *counter)
Definition: counter.c:123
Load * outgoing_sms_load
Definition: smscconn_p.h:214
Counter * outgoing_dlr_counter
Definition: bearerbox.c:93
Counter * sent
Definition: smscconn_p.h:164
Definition: msg.h:79
long bb_smscconn_receive(SMSCConn *conn, Msg *sms)
Definition: bb_smscconn.c:478
void msg_destroy(Msg *msg)
Definition: msg.c:132
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:322
#define octstr_create(cstr)
Definition: octstr.h:125
#define DLR_IS_SMSC_SUCCESS(dlr)
Definition: dlr.h:89
static void handle_split(SMSCConn *conn, Msg *msg, long reason)
Definition: bb_smscconn.c:209
Load * outgoing_sms_load
Definition: bearerbox.c:102
Counter * sent_dlr
Definition: smscconn_p.h:165
#define load_increase(load)
Definition: load.h:94
Load * outgoing_dlr_load
Definition: smscconn_p.h:217
#define DLR_SMSC_SUCCESS
Definition: dlr.h:75
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.