Kannel: Open Source WAP and SMS gateway  svn-r5335
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

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

◆ bb_smscconn_connected()

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)

◆ bb_smscconn_killed()

void bb_smscconn_killed ( void  )

Definition at line 199 of file bb_smscconn.c.

References flow_threads, gwlist_remove_producer(), and incoming_sms.

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

◆ bb_smscconn_ready()

void bb_smscconn_ready ( SMSCConn conn)

Definition at line 185 of file bb_smscconn.c.

References flow_threads, gwlist_add_producer(), and incoming_sms.

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

◆ bb_smscconn_receive()

long bb_smscconn_receive ( SMSCConn conn,
Msg sms 
)

Definition at line 477 of file bb_smscconn.c.

References bb_alog_sms(), bb_smscconn_receive_internal(), black_list_receiver, black_list_receiver_regex, black_list_sender, 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, incoming_sms_counter, incoming_sms_load, 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, unified_prefix, smscconn::unified_prefix, white_black_list_lock, white_list_receiver, white_list_receiver_regex, white_list_sender, 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().

478 {
479  char *uf;
480  int ret;
481 
482  /*
483  * first check whether msgdata data is NULL and set it to empty
484  * because seems too much kannels parts rely on msgdata not to be NULL.
485  */
486  if (sms->sms.msgdata == NULL)
487  sms->sms.msgdata = octstr_create("");
488 
489  /*
490  * First normalize in smsc level and then on global level.
491  * In outbound direction it's vise versa, hence first global then smsc.
492  */
493  uf = (conn && conn->unified_prefix) ? octstr_get_cstr(conn->unified_prefix) : NULL;
494  normalize_number(uf, &(sms->sms.sender));
495 
497  normalize_number(uf, &(sms->sms.sender));
498 
499  /*
500  * We don't perform white/black-listing for DLRs.
501  * Fix sms type if not set already.
502  */
503  if (sms->sms.sms_type != report_mo) {
504  sms->sms.sms_type = mo;
505 
507  if (white_list_sender &&
508  numhash_find_number(white_list_sender, sms->sms.sender) < 1) {
510  info(0, "Number <%s> is not in white-list-sender, message discarded",
511  octstr_get_cstr(sms->sms.sender));
512  bb_alog_sms(conn, sms, "REJECTED Receive SMS - not white-listed SMS");
513  msg_destroy(sms);
515  }
516 
518  gw_regex_match_pre(white_list_sender_regex, sms->sms.sender) == 0) {
520  info(0, "Number <%s> is not in white-list-sender, message discarded",
521  octstr_get_cstr(sms->sms.sender));
522  bb_alog_sms(conn, sms, "REJECTED Receive SMS - not white-regex-listed SMS");
523  msg_destroy(sms);
525  }
526 
527  if (black_list_sender &&
528  numhash_find_number(black_list_sender, sms->sms.sender) == 1) {
530  info(0, "Number <%s> is in black-list-sender, message discarded",
531  octstr_get_cstr(sms->sms.sender));
532  bb_alog_sms(conn, sms, "REJECTED Receive SMS - black-listed SMS");
533  msg_destroy(sms);
535  }
536 
538  gw_regex_match_pre(black_list_sender_regex, sms->sms.sender) != 0) {
540  info(0, "Number <%s> is in black-list-sender, message discarded",
541  octstr_get_cstr(sms->sms.sender));
542  bb_alog_sms(conn, sms, "REJECTED Receive SMS - black-regex-listed SMS");
543  msg_destroy(sms);
545  }
546 
547  if (white_list_receiver &&
548  numhash_find_number(white_list_receiver, sms->sms.receiver) < 1) {
550  info(0, "Number <%s> is not in white-list-receiver, message discarded",
551  octstr_get_cstr(sms->sms.receiver));
552  bb_alog_sms(conn, sms, "REJECTED Receive SMS - not white-listed SMS");
553  msg_destroy(sms);
555  }
556 
558  gw_regex_match_pre(white_list_receiver_regex, sms->sms.receiver) == 0) {
560  info(0, "Number <%s> is not in white-list-receiver, message discarded",
561  octstr_get_cstr(sms->sms.receiver));
562  bb_alog_sms(conn, sms, "REJECTED Receive SMS - not white-regex-listed SMS");
563  msg_destroy(sms);
565  }
566 
567  if (black_list_receiver &&
568  numhash_find_number(black_list_receiver, sms->sms.receiver) == 1) {
570  info(0, "Number <%s> is in black-list-receiver, message discarded",
571  octstr_get_cstr(sms->sms.receiver));
572  bb_alog_sms(conn, sms, "REJECTED Receive SMS - black-listed SMS");
573  msg_destroy(sms);
575  }
576 
578  gw_regex_match_pre(black_list_receiver_regex, sms->sms.receiver) != 0) {
580  info(0, "Number <%s> is in black-list-receiver, message discarded",
581  octstr_get_cstr(sms->sms.receiver));
582  bb_alog_sms(conn, sms, "REJECTED Receive SMS - black-regex-listed SMS");
583  msg_destroy(sms);
585  }
587  }
588 
589  /* write to store (if enabled) */
590  if (store_save(sms) == -1) {
591  msg_destroy(sms);
593  }
594 
595  /* Before routing to some box or re-routing, do concatenation handling
596  * and replace copy as such.
597  */
598  if (handle_concatenated_mo && sms->sms.sms_type == mo) {
599  ret = concat_handling_check_and_handle(&sms, (conn ? conn->id : NULL));
600  switch(ret) {
601  case concat_pending:
604  if (conn != NULL) {
605  counter_increase(conn->received);
607  }
608  return SMSCCONN_SUCCESS;
609  case concat_complete:
610  /* Combined sms received! save new one since it is now combined. */
611  break;
612  case concat_error:
613  /* failed to save, go away. */
614  msg_destroy(sms);
616  case concat_none:
617  break;
618  default:
619  panic(0, "Internal error: Unhandled concat result.");
620  break;
621  }
622  }
623 
624  return bb_smscconn_receive_internal(conn, sms);
625 }
Load * incoming_sms_load
Definition: smscconn_p.h:216
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:672
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:416
#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:2181

◆ bb_smscconn_send_failed()

void bb_smscconn_send_failed ( SMSCConn conn,
Msg sms,
int  reason,
Octstr reply 
)

Definition at line 329 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(), outgoing_sms, reply(), 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(), wrapper_sender(), wrapper_shutdown(), and xidris_parse_reply().

330 {
331  if (sms->sms.split_parts != NULL) {
332  handle_split(conn, sms, reason, 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) || DLR_IS_FAIL(sms->sms.dlr_mask)) {
396  Msg *dlrmsg;
397 
398  if (reply == NULL)
399  reply = octstr_create("");
400 
401  octstr_insert_data(reply, 0, "NACK/", 5);
402  dlrmsg = create_dlr_from_msg((conn ? (conn->id?conn->id:conn->name) : NULL), sms,
404  if (dlrmsg != NULL) {
405  bb_smscconn_receive(conn, dlrmsg);
406  }
407  }
408 
409  msg_destroy(sms);
410  break;
411  }
412 
414 }
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
List * outgoing_sms
Definition: bearerbox.c:85
static long sms_resend_retry
Definition: bb_smscconn.c:153
#define DLR_IS_SMSC_FAIL(dlr)
Definition: dlr.h:90
Definition: msg.h:110
void octstr_insert_data(Octstr *ostr, long pos, const char *data, long len)
Definition: octstr.c:1461
static void handle_split(SMSCConn *conn, Msg *msg, long reason, Octstr *reply)
Definition: bb_smscconn.c:209
unsigned long counter_increase(Counter *counter)
Definition: counter.c:123
Definition: msg.h:79
int smscconn_status(SMSCConn *conn)
Definition: smscconn.c:724
long bb_smscconn_receive(SMSCConn *conn, Msg *sms)
Definition: bb_smscconn.c:477
void msg_destroy(Msg *msg)
Definition: msg.c:132
void warning(int err, const char *fmt,...)
Definition: log.c:660
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
#define octstr_create(cstr)
Definition: octstr.h:125
#define DLR_SMSC_FAIL
Definition: dlr.h:76
void bb_smscconn_send_failed(SMSCConn *conn, Msg *sms, int reason, Octstr *reply)
Definition: bb_smscconn.c:329
#define DLR_IS_FAIL(dlr)
Definition: dlr.h:87
static void reply(HTTPClient *c, List *push_headers)

◆ bb_smscconn_sent()

void bb_smscconn_sent ( SMSCConn conn,
Msg sms,
Octstr reply 
)

Definition at line 281 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(), outgoing_dlr_counter, outgoing_dlr_load, smscconn::outgoing_dlr_load, outgoing_sms_counter, outgoing_sms_load, smscconn::outgoing_sms_load, reply(), 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(), and xidris_parse_reply().

282 {
283  if (sms->sms.split_parts != NULL) {
284  handle_split(conn, sms, SMSCCONN_SUCCESS, reply);
285  return;
286  }
287 
288  /* write ACK to store file */
290 
291  if (sms->sms.sms_type != report_mt) {
292  bb_alog_sms(conn, sms, "Sent SMS");
295  if (conn != NULL) {
296  counter_increase(conn->sent);
298  }
299  } else {
300  bb_alog_sms(conn, sms, "Sent DLR");
303  if (conn != NULL) {
304  counter_increase(conn->sent_dlr);
306  }
307  }
308 
309  /* generate relay confirmancy message */
310  if (DLR_IS_SMSC_SUCCESS(sms->sms.dlr_mask)) {
311  Msg *dlrmsg;
312 
313  if (reply == NULL)
314  reply = octstr_create("");
315 
316  octstr_insert_data(reply, 0, "ACK/", 4);
317  dlrmsg = create_dlr_from_msg((conn->id?conn->id:conn->name), sms,
319  if (dlrmsg != NULL) {
320  bb_smscconn_receive(conn, dlrmsg);
321  }
322  }
323 
324  msg_destroy(sms);
326 }
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:1461
static void handle_split(SMSCConn *conn, Msg *msg, long reason, Octstr *reply)
Definition: bb_smscconn.c:209
unsigned long counter_increase(Counter *counter)
Definition: counter.c:123
Load * outgoing_sms_load
Definition: smscconn_p.h:215
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:477
void msg_destroy(Msg *msg)
Definition: msg.c:132
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
#define octstr_create(cstr)
Definition: octstr.h:125
#define DLR_IS_SMSC_SUCCESS(dlr)
Definition: dlr.h:89
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:218
#define DLR_SMSC_SUCCESS
Definition: dlr.h:75
static void reply(HTTPClient *c, List *push_headers)
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.