Kannel: Open Source WAP and SMS gateway  svn-r5285
bearerbox.h File Reference
#include "gwlib/gwlib.h"
#include "msg.h"
#include "smscconn.h"
#include "bb_store.h"

Go to the source code of this file.

Macros

#define DEFAULT_OUTGOING_SMS_QLENGTH   1000000
 

Enumerations

enum  {
  BB_RUNNING = 0, BB_ISOLATED = 1, BB_SUSPENDED = 2, BB_SHUTDOWN = 3,
  BB_DEAD = 4, BB_FULL = 5
}
 
enum  { BBSTATUS_HTML = 0, BBSTATUS_TEXT = 1, BBSTATUS_WML = 2, BBSTATUS_XML = 3 }
 

Functions

int smsbox_start (Cfg *config)
 
int smsbox_restart (Cfg *config)
 
int wapbox_start (Cfg *config)
 
Octstrboxc_status (int status_type)
 
int boxc_incoming_wdp_queue (void)
 
void boxc_cleanup (void)
 
int route_incoming_to_boxc (Msg *msg)
 
int udp_start (Cfg *config)
 
int udp_shutdown (void)
 
int udp_die (void)
 
int udp_addwdp (Msg *msg)
 
int udp_outgoing_queue (void)
 
int smsc2_start (Cfg *config)
 
int smsc2_restart (Cfg *config)
 
int smsc2_graceful_restart (Cfg *config)
 
void smsc2_suspend (void)
 
void smsc2_resume (int is_init)
 
int smsc2_shutdown (void)
 
void smsc2_cleanup (void)
 
Octstrsmsc2_status (int status_type)
 
long smsc2_rout (Msg *msg, int resend)
 
int smsc2_stop_smsc (Octstr *id)
 
int smsc2_restart_smsc (Octstr *id)
 
int smsc2_add_smsc (Octstr *id)
 
int smsc2_remove_smsc (Octstr *id)
 
int smsc2_reload_lists (void)
 
int httpadmin_start (Cfg *config)
 
void httpadmin_stop (void)
 
void bb_alog_init (const Octstr *format)
 
void bb_alog_shutdown (void)
 
void bb_alog_sms (SMSCConn *conn, Msg *sms, const char *message)
 
int bb_shutdown (void)
 
int bb_isolate (void)
 
int bb_suspend (void)
 
int bb_resume (void)
 
int bb_restart (void)
 
int bb_graceful_restart (void)
 
int bb_flush_dlr (void)
 
int bb_stop_smsc (Octstr *id)
 
int bb_add_smsc (Octstr *id)
 
int bb_remove_smsc (Octstr *id)
 
int bb_restart_smsc (Octstr *id)
 
int bb_remove_message (Octstr *id)
 
int bb_reload_lists (void)
 
int bb_reload_smsc_groups (void)
 
Octstrbb_print_status (int status_type)
 
char * bb_status_linebreak (int status_type)
 

Macro Definition Documentation

◆ DEFAULT_OUTGOING_SMS_QLENGTH

#define DEFAULT_OUTGOING_SMS_QLENGTH   1000000

Definition at line 69 of file bearerbox.h.

Referenced by init_bearerbox().

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
BB_RUNNING 
BB_ISOLATED 
BB_SUSPENDED 
BB_SHUTDOWN 
BB_DEAD 
BB_FULL 

Definition at line 73 of file bearerbox.h.

73  {
74  BB_RUNNING = 0,
75  BB_ISOLATED = 1, /* do not receive new messgaes from UDP/SMSC */
76  BB_SUSPENDED = 2, /* do not transfer any messages */
77  BB_SHUTDOWN = 3,
78  BB_DEAD = 4,
79  BB_FULL = 5 /* message queue too long, do not accept new messages */
80 };

◆ anonymous enum

anonymous enum
Enumerator
BBSTATUS_HTML 
BBSTATUS_TEXT 
BBSTATUS_WML 
BBSTATUS_XML 

Definition at line 84 of file bearerbox.h.

84  {
85  BBSTATUS_HTML = 0,
86  BBSTATUS_TEXT = 1,
87  BBSTATUS_WML = 2,
88  BBSTATUS_XML = 3
89 };

Function Documentation

◆ bb_add_smsc()

int bb_add_smsc ( Octstr id)

Definition at line 938 of file bearerbox.c.

References smsc2_add_smsc().

Referenced by httpd_add_smsc().

939 {
940  return smsc2_add_smsc(id);
941 }
int smsc2_add_smsc(Octstr *id)
Definition: bb_smscconn.c:1112

◆ bb_alog_init()

void bb_alog_init ( const Octstr format)

Definition at line 359 of file bb_alog.c.

References custom_log_format, gw_assert(), and octstr_duplicate.

Referenced by init_bearerbox().

360 {
361  gw_assert(format != NULL);
362 
364 }
gw_assert(wtls_machine->packet_to_send !=NULL)
#define octstr_duplicate(ostr)
Definition: octstr.h:187
static Octstr * custom_log_format
Definition: bb_alog.c:70

◆ bb_alog_shutdown()

void bb_alog_shutdown ( void  )

Definition at line 367 of file bb_alog.c.

References custom_log_format, and octstr_destroy().

Referenced by main().

368 {
370  custom_log_format = NULL;
371 }
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
static Octstr * custom_log_format
Definition: bb_alog.c:70

◆ bb_alog_sms()

void bb_alog_sms ( SMSCConn conn,
Msg sms,
const char *  message 
)

Definition at line 374 of file bb_alog.c.

References alog(), custom_log_format, DC_8BIT, DC_UCS2, get_pattern(), gw_assert(), msg, octstr_binary_to_hex(), octstr_convert_printable(), octstr_create, octstr_destroy(), octstr_duplicate, octstr_get_cstr, octstr_imm(), octstr_len(), smscconn_id(), smscconn_name(), and text.

Referenced by bb_smscconn_receive(), bb_smscconn_receive_internal(), bb_smscconn_send_failed(), bb_smscconn_sent(), and handle_pdu().

375 {
376  Octstr *text = NULL;
377 
378  gw_assert(msg_type(msg) == sms);
379 
380  /* if we don't have any custom log, then use our "default" one */
381 
382  if (custom_log_format == NULL) {
383  Octstr *udh;
384  const Octstr *cid;
385 
386  text = msg->sms.msgdata ? octstr_duplicate(msg->sms.msgdata) : octstr_create("");
387  udh = msg->sms.udhdata ? octstr_duplicate(msg->sms.udhdata) : octstr_create("");
388 
389  if (conn && smscconn_id(conn))
390  cid = smscconn_id(conn);
391  else if (conn && smscconn_name(conn))
392  cid = smscconn_name(conn);
393  else if (msg->sms.smsc_id)
394  cid = msg->sms.smsc_id;
395  else
396  cid = octstr_imm("");
397 
398  if ((msg->sms.coding == DC_8BIT || msg->sms.coding == DC_UCS2))
400  else
402  octstr_binary_to_hex(udh, 1);
403 
404  alog("%s [SMSC:%s] [SVC:%s] [ACT:%s] [BINF:%s] [FID:%s] [META:%s] [from:%s] [to:%s] [flags:%ld:%ld:%ld:%ld:%ld] "
405  "[msg:%ld:%s] [udh:%ld:%s]",
406  message,
407  octstr_get_cstr(cid),
408  msg->sms.service ? octstr_get_cstr(msg->sms.service) : "",
409  msg->sms.account ? octstr_get_cstr(msg->sms.account) : "",
410  msg->sms.binfo ? octstr_get_cstr(msg->sms.binfo) : "",
411  msg->sms.foreign_id ? octstr_get_cstr(msg->sms.foreign_id) : "",
412  msg->sms.meta_data ? octstr_get_cstr(msg->sms.meta_data) : "",
413  msg->sms.sender ? octstr_get_cstr(msg->sms.sender) : "",
414  msg->sms.receiver ? octstr_get_cstr(msg->sms.receiver) : "",
415  msg->sms.mclass, msg->sms.coding, msg->sms.mwi, msg->sms.compress,
416  msg->sms.dlr_mask,
417  octstr_len(msg->sms.msgdata), octstr_get_cstr(text),
418  octstr_len(msg->sms.udhdata), octstr_get_cstr(udh)
419  );
420 
421  octstr_destroy(udh);
422  } else {
423  text = get_pattern(conn, msg, message);
424  alog("%s", octstr_get_cstr(text));
425  }
426 
428 }
gw_assert(wtls_machine->packet_to_send !=NULL)
msg_type
Definition: msg.h:73
const Octstr * smscconn_name(SMSCConn *conn)
Definition: smscconn.c:493
#define DC_8BIT
Definition: sms.h:111
static Octstr * get_pattern(SMSCConn *conn, Msg *msg, const char *message)
Definition: bb_alog.c:117
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
void octstr_binary_to_hex(Octstr *ostr, int uppercase)
Definition: octstr.c:465
void octstr_convert_printable(Octstr *ostr)
Definition: octstr.c:864
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:283
char * text
Definition: smsc_cimd2.c:921
const Octstr * smscconn_id(SMSCConn *conn)
Definition: smscconn.c:500
#define octstr_duplicate(ostr)
Definition: octstr.h:187
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
#define octstr_create(cstr)
Definition: octstr.h:125
long octstr_len(const Octstr *ostr)
Definition: octstr.c:342
Definition: octstr.c:118
void alog(const char *fmt,...)
Definition: accesslog.c:206
static XMLRPCDocument * msg
Definition: test_xmlrpc.c:86
static Octstr * custom_log_format
Definition: bb_alog.c:70
#define DC_UCS2
Definition: sms.h:112

◆ bb_flush_dlr()

int bb_flush_dlr ( void  )

Definition at line 916 of file bearerbox.c.

References bb_status, BB_SUSPENDED, and dlr_flush().

Referenced by httpd_flush_dlr().

917 {
918  /* beware that mutex locking is done in dlr_foobar() routines */
919  if (bb_status != BB_SUSPENDED) {
920  return -1;
921  }
922  dlr_flush();
923  return 0;
924 }
volatile sig_atomic_t bb_status
Definition: bearerbox.c:132
void dlr_flush(void)
Definition: dlr.c:491

◆ bb_graceful_restart()

int bb_graceful_restart ( void  )

Definition at line 954 of file bearerbox.c.

References cfg, cfg_create(), cfg_filename, cfg_read(), error(), info(), octstr_get_cstr, smsbox_restart(), and smsc2_graceful_restart().

Referenced by httpd_graceful_restart(), and main().

955 {
956  Cfg *cfg;
957 
958  info(0, "Reloading configuration resource `%s'.", octstr_get_cstr(cfg_filename));
960  if (cfg_read(cfg) == -1) {
961  error(0, "Error processing configuration resource `%s'. Continue with existing configuration.",
963  return -1;
964  }
965 
968  return 0;
969 }
void error(int err, const char *fmt,...)
Definition: log.c:648
void info(int err, const char *fmt,...)
Definition: log.c:672
int smsc2_graceful_restart(Cfg *cfg)
Definition: bb_smscconn.c:1522
static Cfg * cfg
Definition: opensmppbox.c:95
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
Cfg * cfg_create(Octstr *filename)
Definition: cfg.c:318
int cfg_read(Cfg *cfg)
Definition: cfg.c:452
Definition: cfg.c:164
int smsbox_restart(Cfg *cfg)
Definition: bb_boxc.c:1301
Octstr * cfg_filename
Definition: bearerbox.c:130

◆ bb_isolate()

int bb_isolate ( void  )

Definition at line 861 of file bearerbox.c.

References BB_ISOLATED, BB_RUNNING, bb_status, BB_SUSPENDED, gwlist_add_producer(), gwlist_remove_producer(), isolated, mutex_lock, mutex_unlock, smsc2_suspend(), status_mutex, and suspended.

Referenced by httpd_isolate().

862 {
866  return -1;
867  }
868  if (bb_status == BB_RUNNING) {
869  smsc2_suspend();
871  } else
873 
876  return 0;
877 }
volatile sig_atomic_t bb_status
Definition: bearerbox.c:132
List * suspended
Definition: bearerbox.c:122
#define mutex_unlock(m)
Definition: thread.h:136
static Mutex * status_mutex
Definition: bearerbox.c:147
List * isolated
Definition: bearerbox.c:127
void gwlist_remove_producer(List *list)
Definition: list.c:401
void smsc2_suspend(void)
Definition: bb_smscconn.c:1251
void gwlist_add_producer(List *list)
Definition: list.c:383
#define mutex_lock(m)
Definition: thread.h:130

◆ bb_print_status()

Octstr* bb_print_status ( int  status_type)

Definition at line 998 of file bearerbox.c.

References append_status, BB_FULL, BB_ISOLATED, BB_RUNNING, bb_status, bb_status_linebreak(), BB_SUSPENDED, BBSTATUS_HTML, BBSTATUS_WML, BBSTATUS_XML, boxc_incoming_wdp_queue(), boxc_status(), counter_value(), dlr_messages(), dlr_type(), gwlist_len(), incoming_dlr_counter, incoming_dlr_load, incoming_sms, incoming_sms_counter, incoming_sms_load, incoming_wdp, incoming_wdp_counter, load_get(), octstr_append_cstr(), octstr_create, octstr_destroy(), octstr_format(), octstr_get_cstr, outgoing_dlr_counter, outgoing_dlr_load, outgoing_sms, outgoing_sms_counter, outgoing_sms_load, outgoing_wdp, outgoing_wdp_counter, smsc2_status(), start_time, store_messages, udp_outgoing_queue(), and version_report_string().

Referenced by httpd_status().

999 {
1000  char *s, *lb;
1001  char *frmt, *footer;
1002  Octstr *ret, *str, *version;
1003  time_t t;
1004 
1005  if ((lb = bb_status_linebreak(status_type)) == NULL)
1006  return octstr_create("Un-supported format");
1007 
1008  t = time(NULL) - start_time;
1009 
1010  if (bb_status == BB_RUNNING)
1011  s = "running";
1012  else if (bb_status == BB_ISOLATED)
1013  s = "isolated";
1014  else if (bb_status == BB_SUSPENDED)
1015  s = "suspended";
1016  else if (bb_status == BB_FULL)
1017  s = "filled";
1018  else
1019  s = "going down";
1020 
1021  version = version_report_string("bearerbox");
1022 
1023  if (status_type == BBSTATUS_HTML) {
1024  frmt = "%s</p>\n\n"
1025  " <p>Status: %s, uptime %ldd %ldh %ldm %lds</p>\n\n"
1026  " <p>WDP: received %ld (%ld queued), sent %ld "
1027  "(%ld queued)</p>\n\n"
1028  " <p>SMS: received %ld (%ld queued), sent %ld "
1029  "(%ld queued), store size %ld<br>\n"
1030  " SMS: inbound (%.2f,%.2f,%.2f) msg/sec, "
1031  "outbound (%.2f,%.2f,%.2f) msg/sec</p>\n\n"
1032  " <p>DLR: received %ld, sent %ld<br>\n"
1033  " DLR: inbound (%.2f,%.2f,%.2f) msg/sec, outbound (%.2f,%.2f,%.2f) msg/sec<br>\n"
1034  " DLR: %ld queued, using %s storage</p>\n\n";
1035  footer = "<p>";
1036  } else if (status_type == BBSTATUS_WML) {
1037  frmt = "%s</p>\n\n"
1038  " <p>Status: %s, uptime %ldd %ldh %ldm %lds</p>\n\n"
1039  " <p>WDP: received %ld (%ld queued)<br/>\n"
1040  " WDP: sent %ld (%ld queued)</p>\n\n"
1041  " <p>SMS: received %ld (%ld queued)<br/>\n"
1042  " SMS: sent %ld (%ld queued)<br/>\n"
1043  " SMS: store size %ld<br/>\n"
1044  " SMS: inbound (%.2f,%.2f,%.2f) msg/sec<br/>\n"
1045  " SMS: outbound (%.2f,%.2f,%.2f) msg/sec</p>\n"
1046  " <p>DLR: received %ld<br/>\n"
1047  " DLR: sent %ld<br/>\n"
1048  " DLR: inbound (%.2f,%.2f,%.2f) msg/sec<br/>\n"
1049  " DLR: outbound (%.2f,%.2f,%.2f) msg/sec<br/>\n"
1050  " DLR: %ld queued<br/>\n"
1051  " DLR: using %s storage</p>\n\n";
1052  footer = "<p>";
1053  } else if (status_type == BBSTATUS_XML) {
1054  frmt = "<version>%s</version>\n"
1055  "<status>%s, uptime %ldd %ldh %ldm %lds</status>\n"
1056  "\t<wdp>\n\t\t<received><total>%ld</total><queued>%ld</queued>"
1057  "</received>\n\t\t<sent><total>%ld</total><queued>%ld</queued>"
1058  "</sent>\n\t</wdp>\n"
1059  "\t<sms>\n\t\t<received><total>%ld</total><queued>%ld</queued>"
1060  "</received>\n\t\t<sent><total>%ld</total><queued>%ld</queued>"
1061  "</sent>\n\t\t<storesize>%ld</storesize>\n\t\t"
1062  "<inbound>%.2f,%.2f,%.2f</inbound>\n\t\t"
1063  "<outbound>%.2f,%.2f,%.2f</outbound>\n\t\t"
1064  "</sms>\n"
1065  "\t<dlr>\n\t\t<received><total>%ld</total></received>\n\t\t"
1066  "<sent><total>%ld</total></sent>\n\t\t"
1067  "<inbound>%.2f,%.2f,%.2f</inbound>\n\t\t"
1068  "<outbound>%.2f,%.2f,%.2f</outbound>\n\t\t"
1069  "<queued>%ld</queued>\n\t\t<storage>%s</storage>\n\t</dlr>\n";
1070  footer = "";
1071  } else {
1072  frmt = "%s\n\nStatus: %s, uptime %ldd %ldh %ldm %lds\n\n"
1073  "WDP: received %ld (%ld queued), sent %ld (%ld queued)\n\n"
1074  "SMS: received %ld (%ld queued), sent %ld (%ld queued), store size %ld\n"
1075  "SMS: inbound (%.2f,%.2f,%.2f) msg/sec, "
1076  "outbound (%.2f,%.2f,%.2f) msg/sec\n\n"
1077  "DLR: received %ld, sent %ld\n"
1078  "DLR: inbound (%.2f,%.2f,%.2f) msg/sec, outbound (%.2f,%.2f,%.2f) msg/sec\n"
1079  "DLR: %ld queued, using %s storage\n\n";
1080  footer = "";
1081  }
1082 
1083  ret = octstr_format(frmt,
1084  octstr_get_cstr(version),
1085  s, t/3600/24, t/3600%24, t/60%60, t%60,
1091  store_messages(),
1097  dlr_messages(), dlr_type());
1098 
1099  octstr_destroy(version);
1100 
1101  append_status(ret, str, boxc_status, status_type);
1102  append_status(ret, str, smsc2_status, status_type);
1103  octstr_append_cstr(ret, footer);
1104 
1105  return ret;
1106 }
volatile sig_atomic_t bb_status
Definition: bearerbox.c:132
Counter * incoming_dlr_counter
Definition: bearerbox.c:92
int boxc_incoming_wdp_queue(void)
Definition: bb_boxc.c:1493
Counter * incoming_wdp_counter
Definition: bearerbox.c:94
List * outgoing_sms
Definition: bearerbox.c:85
Load * outgoing_sms_load
Definition: bearerbox.c:102
Load * incoming_sms_load
Definition: bearerbox.c:103
char * bb_status_linebreak(int status_type)
Definition: bearerbox.c:1109
long gwlist_len(List *list)
Definition: list.c:166
long(* store_messages)(void)
Definition: bb_store.c:71
List * incoming_wdp
Definition: bearerbox.c:87
void octstr_append_cstr(Octstr *ostr, const char *cstr)
Definition: octstr.c:1511
double load_get(Load *load, int pos)
Definition: load.c:191
int udp_outgoing_queue(void)
Definition: bb_udp.c:460
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
static time_t start_time
Definition: bearerbox.c:148
Load * incoming_dlr_load
Definition: bearerbox.c:104
List * incoming_sms
Definition: bearerbox.c:84
const char * dlr_type(void)
Definition: dlr.c:319
Counter * outgoing_sms_counter
Definition: bearerbox.c:91
Load * outgoing_dlr_load
Definition: bearerbox.c:105
Octstr * octstr_format(const char *fmt,...)
Definition: octstr.c:2464
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
Counter * incoming_sms_counter
Definition: bearerbox.c:90
#define octstr_create(cstr)
Definition: octstr.h:125
unsigned long counter_value(Counter *counter)
Definition: counter.c:145
Counter * outgoing_dlr_counter
Definition: bearerbox.c:93
#define append_status(r, s, f, x)
Definition: bearerbox.c:995
Definition: octstr.c:118
List * outgoing_wdp
Definition: bearerbox.c:88
Octstr * boxc_status(int status_type)
Definition: bb_boxc.c:1369
Counter * outgoing_wdp_counter
Definition: bearerbox.c:95
Octstr * version_report_string(const char *boxname)
Definition: utils.c:549
Octstr * smsc2_status(int status_type)
Definition: bb_smscconn.c:1354
long dlr_messages(void)
Definition: dlr.c:308

◆ bb_reload_lists()

int bb_reload_lists ( void  )

Definition at line 971 of file bearerbox.c.

References smsc2_reload_lists().

Referenced by httpd_reload_lists().

972 {
973  return smsc2_reload_lists();
974 }
int smsc2_reload_lists(void)
Definition: bb_smscconn.c:1166

◆ bb_reload_smsc_groups()

int bb_reload_smsc_groups ( void  )

Definition at line 628 of file bb_smscconn.c.

References cfg_create(), cfg_destroy(), cfg_filename, cfg_get_multi_group(), cfg_read(), cfg_reloaded, debug(), gwlist_destroy(), octstr_get_cstr, octstr_imm(), smsc_groups, and warning().

Referenced by smsc2_add_smsc(), and smsc2_restart_smsc().

629 {
630  debug("bb.sms", 0, "Reloading smsc groups list from config resource");
633  if (cfg_read(cfg_reloaded) == -1) {
634  warning(0, "Error opening configuration file %s", octstr_get_cstr(cfg_filename));
635  return -1;
636  }
639 
640  return 0;
641 }
static Cfg * cfg_reloaded
Definition: bb_smscconn.c:130
static List * smsc_groups
Definition: bb_smscconn.c:131
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
Cfg * cfg_create(Octstr *filename)
Definition: cfg.c:318
int cfg_read(Cfg *cfg)
Definition: cfg.c:452
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:283
void cfg_destroy(Cfg *cfg)
Definition: cfg.c:331
Octstr * cfg_filename
Definition: bearerbox.c:130
List * cfg_get_multi_group(Cfg *cfg, Octstr *name)
Definition: cfg.c:643
void warning(int err, const char *fmt,...)
Definition: log.c:660
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:726
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)
Definition: list.c:145

◆ bb_remove_message()

int bb_remove_message ( Octstr id)

Definition at line 976 of file bearerbox.c.

References ack_failed, error(), msg, msg_create, msg_destroy(), octstr_get_cstr, store_save, and uuid_parse().

Referenced by httpd_remove_message().

977 {
978  Msg *msg;
979  int ret;
980 
981  msg = msg_create(ack);
982  msg->ack.nack = ack_failed;
983  msg->ack.time = time(NULL);
984  uuid_parse(octstr_get_cstr(message_id), msg->ack.id);
985  ret = store_save(msg);
986  msg_destroy(msg);
987  if (ret != 0) {
988  error(0, "Could not delete message %s", octstr_get_cstr(message_id));
989  return -1;
990  }
991  return 0;
992 }
void error(int err, const char *fmt,...)
Definition: log.c:648
#define msg_create(type)
Definition: msg.h:136
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
int uuid_parse(const char *in, uuid_t uu)
Definition: gw_uuid.c:476
Definition: msg.h:79
void msg_destroy(Msg *msg)
Definition: msg.c:132
int(* store_save)(Msg *msg)
Definition: bb_store.c:72
static XMLRPCDocument * msg
Definition: test_xmlrpc.c:86

◆ bb_remove_smsc()

int bb_remove_smsc ( Octstr id)

Definition at line 943 of file bearerbox.c.

References smsc2_remove_smsc().

Referenced by httpd_remove_smsc().

944 {
945  return smsc2_remove_smsc(id);
946 }
int smsc2_remove_smsc(Octstr *id)
Definition: bb_smscconn.c:1083

◆ bb_restart()

int bb_restart ( void  )

Definition at line 948 of file bearerbox.c.

References bb_shutdown(), and restart.

Referenced by httpd_graceful_restart(), and httpd_restart().

949 {
950  restart = 1;
951  return bb_shutdown();
952 }
volatile sig_atomic_t restart
Definition: bearerbox.c:149
int bb_shutdown(void)
Definition: bearerbox.c:832

◆ bb_restart_smsc()

int bb_restart_smsc ( Octstr id)

Definition at line 933 of file bearerbox.c.

References smsc2_restart_smsc().

Referenced by httpd_restart_smsc().

934 {
935  return smsc2_restart_smsc(id);
936 }
int smsc2_restart_smsc(Octstr *id)
Definition: bb_smscconn.c:998

◆ bb_resume()

int bb_resume ( void  )

Definition at line 898 of file bearerbox.c.

References BB_ISOLATED, BB_RUNNING, bb_status, BB_SUSPENDED, gwlist_remove_producer(), isolated, mutex_lock, mutex_unlock, smsc2_resume(), status_mutex, and suspended.

Referenced by httpd_resume().

899 {
903  return -1;
904  }
905  if (bb_status == BB_SUSPENDED)
907 
908  smsc2_resume(0);
912  return 0;
913 }
volatile sig_atomic_t bb_status
Definition: bearerbox.c:132
List * suspended
Definition: bearerbox.c:122
#define mutex_unlock(m)
Definition: thread.h:136
static Mutex * status_mutex
Definition: bearerbox.c:147
List * isolated
Definition: bearerbox.c:127
void gwlist_remove_producer(List *list)
Definition: list.c:401
void smsc2_resume(int is_init)
Definition: bb_smscconn.c:1226
#define mutex_lock(m)
Definition: thread.h:130

◆ bb_shutdown()

int bb_shutdown ( void  )

Definition at line 832 of file bearerbox.c.

References debug(), mutex_lock, mutex_unlock, set_shutdown_status(), smsc2_shutdown(), status_mutex, and udp_shutdown().

Referenced by bb_restart(), httpadmin_run(), httpd_shutdown(), and main().

833 {
834  static int called = 0;
835 
837 
838  if (called) {
840  return -1;
841  }
842  debug("bb", 0, "Shutting down " GW_NAME "...");
843 
844  called = 1;
847 
848 #ifndef NO_SMS
849  debug("bb", 0, "shutting down smsc");
850  smsc2_shutdown();
851 #endif
852 #ifndef NO_WAP
853  debug("bb", 0, "shutting down udp");
854  udp_shutdown();
855 #endif
856 
857  return 0;
858 }
static void set_shutdown_status(void)
Definition: bearerbox.c:154
#define mutex_unlock(m)
Definition: thread.h:136
static Mutex * status_mutex
Definition: bearerbox.c:147
int udp_shutdown(void)
Definition: bb_udp.c:424
int smsc2_shutdown(void)
Definition: bb_smscconn.c:1268
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:726
#define mutex_lock(m)
Definition: thread.h:130

◆ bb_status_linebreak()

char* bb_status_linebreak ( int  status_type)

Definition at line 1109 of file bearerbox.c.

References BBSTATUS_HTML, BBSTATUS_TEXT, BBSTATUS_WML, and BBSTATUS_XML.

Referenced by bb_print_status(), boxc_status(), httpd_serve(), and smsc2_status().

1110 {
1111  switch (status_type) {
1112  case BBSTATUS_HTML:
1113  return "<br>\n";
1114  case BBSTATUS_WML:
1115  return "<br/>\n";
1116  case BBSTATUS_TEXT:
1117  return "\n";
1118  case BBSTATUS_XML:
1119  return "\n";
1120  default:
1121  return NULL;
1122  }
1123 }

◆ bb_stop_smsc()

int bb_stop_smsc ( Octstr id)

Definition at line 927 of file bearerbox.c.

References smsc2_stop_smsc().

Referenced by httpd_stop_smsc().

928 {
929  return smsc2_stop_smsc(id);
930 }
int smsc2_stop_smsc(Octstr *id)
Definition: bb_smscconn.c:968

◆ bb_suspend()

int bb_suspend ( void  )

Definition at line 880 of file bearerbox.c.

References BB_ISOLATED, BB_RUNNING, bb_status, BB_SUSPENDED, gwlist_add_producer(), isolated, mutex_lock, mutex_unlock, smsc2_suspend(), status_mutex, and suspended.

Referenced by httpd_suspend().

881 {
883  if (bb_status != BB_RUNNING && bb_status != BB_ISOLATED) {
885  return -1;
886  }
887  if (bb_status != BB_ISOLATED) {
888  smsc2_suspend();
890  }
894  return 0;
895 }
volatile sig_atomic_t bb_status
Definition: bearerbox.c:132
List * suspended
Definition: bearerbox.c:122
#define mutex_unlock(m)
Definition: thread.h:136
static Mutex * status_mutex
Definition: bearerbox.c:147
List * isolated
Definition: bearerbox.c:127
void smsc2_suspend(void)
Definition: bb_smscconn.c:1251
void gwlist_add_producer(List *list)
Definition: list.c:383
#define mutex_lock(m)
Definition: thread.h:130

◆ boxc_cleanup()

void boxc_cleanup ( void  )

Definition at line 1510 of file bb_boxc.c.

References box_allow_ip, box_deny_ip, boxid, counter_destroy(), octstr_destroy(), and smsbox_interface.

Referenced by main().

1511 {
1514  box_allow_ip = NULL;
1515  box_deny_ip = NULL;
1517  boxid = NULL;
1519  smsbox_interface = NULL;
1520 }
void counter_destroy(Counter *counter)
Definition: counter.c:110
static Octstr * box_deny_ip
Definition: bb_boxc.c:125
static Octstr * smsbox_interface
Definition: bb_boxc.c:117
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
static Counter * boxid
Definition: bb_boxc.c:128
static Octstr * box_allow_ip
Definition: bb_boxc.c:124

◆ boxc_incoming_wdp_queue()

int boxc_incoming_wdp_queue ( void  )

Definition at line 1493 of file bb_boxc.c.

References gwlist_get(), gwlist_len(), gwlist_lock(), gwlist_unlock(), _boxc::incoming, and wapbox_list.

Referenced by bb_print_status().

1494 {
1495  int i, q = 0;
1496  Boxc *boxc;
1497 
1498  if (wapbox_list) {
1500  for(i=0; i < gwlist_len(wapbox_list); i++) {
1501  boxc = gwlist_get(wapbox_list, i);
1502  q += gwlist_len(boxc->incoming);
1503  }
1505  }
1506  return q;
1507 }
List * incoming
Definition: opensmppbox.c:153
long gwlist_len(List *list)
Definition: list.c:166
void * gwlist_get(List *list, long pos)
Definition: list.c:292
void gwlist_unlock(List *list)
Definition: list.c:354
void gwlist_lock(List *list)
Definition: list.c:347
static List * wapbox_list
Definition: bb_boxc.c:105

◆ boxc_status()

Octstr* boxc_status ( int  status_type)

Definition at line 1369 of file bb_boxc.c.

References _boxc::alive, bb_status_linebreak(), BBSTATUS_HTML, BBSTATUS_TEXT, BBSTATUS_WML, BBSTATUS_XML, _boxc::boxc_id, _boxc::client_ip, _boxc::conn, _boxc::connect_time, dict_key_count(), gw_rwlock_rdlock(), gw_rwlock_unlock(), gwlist_get(), gwlist_len(), gwlist_lock(), gwlist_unlock(), _boxc::incoming, octstr_append_cstr(), octstr_create, octstr_destroy(), octstr_format(), octstr_format_append(), octstr_get_cstr, _boxc::sent, smsbox_list, smsbox_list_rwlock, and wapbox_list.

Referenced by bb_print_status().

1370 {
1371  Octstr *tmp;
1372  char *lb, *ws;
1373  int i, boxes, para = 0;
1374  time_t orig, t;
1375  Boxc *bi;
1376 
1377  orig = time(NULL);
1378 
1379  /*
1380  * XXX: this will cause segmentation fault if this is called
1381  * between 'destroy_list and setting list to NULL calls.
1382  * Ok, this has to be fixed, but now I am too tired.
1383  */
1384 
1385  if ((lb = bb_status_linebreak(status_type))==NULL)
1386  return octstr_create("Un-supported format");
1387 
1388  if (status_type == BBSTATUS_HTML)
1389  ws = "&nbsp;&nbsp;&nbsp;&nbsp;";
1390  else if (status_type == BBSTATUS_TEXT)
1391  ws = " ";
1392  else
1393  ws = "";
1394 
1395  if (status_type == BBSTATUS_HTML || status_type == BBSTATUS_WML)
1396  para = 1;
1397 
1398  if (status_type == BBSTATUS_XML) {
1399  tmp = octstr_create ("");
1400  octstr_append_cstr(tmp, "<boxes>\n\t");
1401  }
1402  else
1403  tmp = octstr_format("%sBox connections:%s", para ? "<p>" : "", lb);
1404  boxes = 0;
1405 
1406  if (wapbox_list) {
1408  for(i=0; i < gwlist_len(wapbox_list); i++) {
1409  bi = gwlist_get(wapbox_list, i);
1410  if (bi->alive == 0)
1411  continue;
1412  t = orig - bi->connect_time;
1413  if (status_type == BBSTATUS_XML)
1415  "<box>\n\t\t<type>wapbox</type>\n\t\t<IP>%s</IP>\n"
1416  "\t\t<status>on-line %ldd %ldh %ldm %lds</status>\n"
1417  "\t\t<ssl>%s</ssl>\n\t</box>\n",
1419  t/3600/24, t/3600%24, t/60%60, t%60,
1420 #ifdef HAVE_LIBSSL
1421  conn_get_ssl(bi->conn) != NULL ? "yes" : "no"
1422 #else
1423  "not installed"
1424 #endif
1425  );
1426  else
1428  "%swapbox, IP %s (on-line %ldd %ldh %ldm %lds) %s %s",
1429  ws, octstr_get_cstr(bi->client_ip),
1430  t/3600/24, t/3600%24, t/60%60, t%60,
1431 #ifdef HAVE_LIBSSL
1432  conn_get_ssl(bi->conn) != NULL ? "using SSL" : "",
1433 #else
1434  "",
1435 #endif
1436  lb);
1437  boxes++;
1438  }
1440  }
1441  if (smsbox_list) {
1443  for(i=0; i < gwlist_len(smsbox_list); i++) {
1444  bi = gwlist_get(smsbox_list, i);
1445  if (bi->alive == 0)
1446  continue;
1447  t = orig - bi->connect_time;
1448  if (status_type == BBSTATUS_XML)
1449  octstr_format_append(tmp, "<box>\n\t\t<type>smsbox</type>\n"
1450  "\t\t<id>%s</id>\n\t\t<IP>%s</IP>\n"
1451  "\t\t<queue>%ld</queue>\n"
1452  "\t\t<status>on-line %ldd %ldh %ldm %lds</status>\n"
1453  "\t\t<ssl>%s</ssl>\n\t</box>",
1454  (bi->boxc_id ? octstr_get_cstr(bi->boxc_id) : ""),
1456  gwlist_len(bi->incoming) + dict_key_count(bi->sent),
1457  t/3600/24, t/3600%24, t/60%60, t%60,
1458 #ifdef HAVE_LIBSSL
1459  conn_get_ssl(bi->conn) != NULL ? "yes" : "no"
1460 #else
1461  "not installed"
1462 #endif
1463  );
1464  else
1465  octstr_format_append(tmp, "%ssmsbox:%s, IP %s (%ld queued), (on-line %ldd %ldh %ldm %lds) %s %s",
1466  ws, (bi->boxc_id ? octstr_get_cstr(bi->boxc_id) : "(none)"),
1468  t/3600/24, t/3600%24, t/60%60, t%60,
1469 #ifdef HAVE_LIBSSL
1470  conn_get_ssl(bi->conn) != NULL ? "using SSL" : "",
1471 #else
1472  "",
1473 #endif
1474  lb);
1475  boxes++;
1476  }
1478  }
1479  if (boxes == 0 && status_type != BBSTATUS_XML) {
1480  octstr_destroy(tmp);
1481  tmp = octstr_format("%sNo boxes connected", para ? "<p>" : "");
1482  }
1483  if (para)
1484  octstr_append_cstr(tmp, "</p>");
1485  if (status_type == BBSTATUS_XML)
1486  octstr_append_cstr(tmp, "</boxes>\n");
1487  else
1488  octstr_append_cstr(tmp, "\n\n");
1489  return tmp;
1490 }
Connection * conn
Definition: bb_boxc.c:135
List * incoming
Definition: opensmppbox.c:153
char * bb_status_linebreak(int status_type)
Definition: bearerbox.c:1109
Octstr * client_ip
Definition: opensmppbox.c:152
static RWLock * smsbox_list_rwlock
Definition: bb_boxc.c:107
long gwlist_len(List *list)
Definition: list.c:166
void * gwlist_get(List *list, long pos)
Definition: list.c:292
int gw_rwlock_rdlock(RWLock *lock)
Definition: gw-rwlock.c:134
void octstr_append_cstr(Octstr *ostr, const char *cstr)
Definition: octstr.c:1511
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
volatile sig_atomic_t alive
Definition: opensmppbox.c:158
void gwlist_unlock(List *list)
Definition: list.c:354
Octstr * boxc_id
Definition: opensmppbox.c:159
long dict_key_count(Dict *dict)
Definition: dict.c:335
int gw_rwlock_unlock(RWLock *lock)
Definition: gw-rwlock.c:155
time_t connect_time
Definition: opensmppbox.c:150
Octstr * octstr_format(const char *fmt,...)
Definition: octstr.c:2464
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
#define octstr_create(cstr)
Definition: octstr.h:125
void gwlist_lock(List *list)
Definition: list.c:347
Definition: octstr.c:118
void octstr_format_append(Octstr *os, const char *fmt,...)
Definition: octstr.c:2507
static List * smsbox_list
Definition: bb_boxc.c:106
static List * wapbox_list
Definition: bb_boxc.c:105
Dict * sent
Definition: opensmppbox.c:156

◆ httpadmin_start()

int httpadmin_start ( Cfg config)

Definition at line 544 of file bb_http.c.

References cfg, cfg_get, cfg_get_bool(), cfg_get_integer(), cfg_get_single_group(), gwthread_create, ha_allow_ip, ha_deny_ip, ha_interface, ha_password, ha_port, ha_status_pw, http_open_port_if(), httpadmin_run(), httpadmin_running, octstr_destroy(), octstr_imm(), panic, and ssl.

Referenced by init_bearerbox().

545 {
546  CfgGroup *grp;
547  int ssl = 0;
548 #ifdef HAVE_LIBSSL
549  Octstr *ssl_server_cert_file;
550  Octstr *ssl_server_key_file;
551 #endif /* HAVE_LIBSSL */
552 
553  if (httpadmin_running) return -1;
554 
555 
556  grp = cfg_get_single_group(cfg, octstr_imm("core"));
557  if (cfg_get_integer(&ha_port, grp, octstr_imm("admin-port")) == -1)
558  panic(0, "Missing admin-port variable, cannot start HTTP admin");
559 
560  ha_interface = cfg_get(grp, octstr_imm("admin-interface"));
561  ha_password = cfg_get(grp, octstr_imm("admin-password"));
562  if (ha_password == NULL)
563  panic(0, "You MUST set HTTP admin-password");
564 
565  ha_status_pw = cfg_get(grp, octstr_imm("status-password"));
566 
567  ha_allow_ip = cfg_get(grp, octstr_imm("admin-allow-ip"));
568  ha_deny_ip = cfg_get(grp, octstr_imm("admin-deny-ip"));
569 
570 #ifdef HAVE_LIBSSL
571  cfg_get_bool(&ssl, grp, octstr_imm("admin-port-ssl"));
572 
573  /*
574  * check if SSL is desired for HTTP servers and then
575  * load SSL client and SSL server public certificates
576  * and private keys
577  */
578  ssl_server_cert_file = cfg_get(grp, octstr_imm("ssl-server-cert-file"));
579  ssl_server_key_file = cfg_get(grp, octstr_imm("ssl-server-key-file"));
580  if (ssl_server_cert_file != NULL && ssl_server_key_file != NULL) {
581  /* we are fine here, the following call is now in conn_config_ssl(),
582  * so there is no reason to do this twice.
583 
584  use_global_server_certkey_file(ssl_server_cert_file,
585  ssl_server_key_file);
586  */
587  } else if (ssl) {
588  panic(0, "You MUST specify cert and key files within core group for SSL-enabled HTTP servers!");
589  }
590 
591  octstr_destroy(ssl_server_cert_file);
592  octstr_destroy(ssl_server_key_file);
593 #endif /* HAVE_LIBSSL */
594 
596 
597  if (gwthread_create(httpadmin_run, NULL) == -1)
598  panic(0, "Failed to start a new thread for HTTP admin");
599 
600  httpadmin_running = 1;
601  return 0;
602 }
static long ha_port
Definition: bb_http.c:82
static Octstr * ha_deny_ip
Definition: bb_http.c:87
int ssl
static Octstr * ha_allow_ip
Definition: bb_http.c:86
static Octstr * ha_status_pw
Definition: bb_http.c:85
#define cfg_get(grp, varname)
Definition: cfg.h:86
static volatile sig_atomic_t httpadmin_running
Definition: bb_http.c:80
static Cfg * cfg
Definition: opensmppbox.c:95
static Octstr * ha_password
Definition: bb_http.c:84
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:283
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
#define gwthread_create(func, arg)
Definition: gwthread.h:90
static Octstr * ha_interface
Definition: bb_http.c:83
int http_open_port_if(int port, int ssl, Octstr *interface)
Definition: http.c:2482
int cfg_get_bool(int *n, CfgGroup *grp, Octstr *varname)
Definition: cfg.c:757
Definition: octstr.c:118
int cfg_get_integer(long *n, CfgGroup *grp, Octstr *varname)
Definition: cfg.c:740
#define panic
Definition: log.h:87
Definition: cfg.c:73
CfgGroup * cfg_get_single_group(Cfg *cfg, Octstr *name)
Definition: cfg.c:637
static void httpadmin_run(void *arg)
Definition: bb_http.c:512

◆ httpadmin_stop()

void httpadmin_stop ( void  )

Definition at line 605 of file bb_http.c.

References gwthread_join_every(), ha_allow_ip, ha_deny_ip, ha_interface, ha_password, ha_status_pw, http_close_all_ports(), httpadmin_run(), and octstr_destroy().

Referenced by main().

606 {
614  ha_password = NULL;
615  ha_status_pw = NULL;
616  ha_allow_ip = NULL;
617  ha_deny_ip = NULL;
618 }
static Octstr * ha_deny_ip
Definition: bb_http.c:87
static Octstr * ha_allow_ip
Definition: bb_http.c:86
static Octstr * ha_status_pw
Definition: bb_http.c:85
void gwthread_join_every(gwthread_func_t *func)
static Octstr * ha_password
Definition: bb_http.c:84
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
static Octstr * ha_interface
Definition: bb_http.c:83
void http_close_all_ports(void)
Definition: http.c:2525
static void httpadmin_run(void *arg)
Definition: bb_http.c:512

◆ route_incoming_to_boxc()

int route_incoming_to_boxc ( Msg msg)

Definition at line 1532 of file bb_boxc.c.

References _boxc::boxc_id, dict_get(), gw_assert(), gw_rand(), gw_rwlock_rdlock(), gw_rwlock_unlock(), gwlist_get(), gwlist_len(), gwlist_produce(), _boxc::incoming, incoming_sms, _boxc::load, max_incoming_sms_qlength, msg, octstr_destroy(), octstr_format(), octstr_get_cstr, octstr_len(), _boxc::routable, smsbox_by_id, smsbox_by_receiver, smsbox_by_smsc, smsbox_by_smsc_receiver, smsbox_list, smsbox_list_rwlock, and warning().

Referenced by bb_smscconn_receive_internal(), and sms_to_smsboxes().

1533 {
1534  Boxc *bc = NULL;
1535  Octstr *s, *r, *rs, *boxc_id = NULL;
1536  long len, b, i;
1537  int full_found = 0;
1538 
1539  gw_assert(msg_type(msg) == sms);
1540 
1541  /* msg_dump(msg, 0); */
1542 
1543  /* Check we have at least one smsbox connected! */
1545  if (gwlist_len(smsbox_list) == 0) {
1547  warning(0, "smsbox_list empty!");
1548  if (max_incoming_sms_qlength < 0 || max_incoming_sms_qlength > gwlist_len(incoming_sms)) {
1550  return 0;
1551  } else {
1552  return -1;
1553  }
1554  }
1555 
1556  /*
1557  * Do we have a specific smsbox-id route to pass this msg to?
1558  */
1559  if (octstr_len(msg->sms.boxc_id) > 0) {
1560  boxc_id = msg->sms.boxc_id;
1561  } else {
1562  /*
1563  * Check if we have a "smsbox-route" for this msg.
1564  * Where the shortcode route has a higher priority then the smsc-id rule.
1565  * Highest priority has the combined <shortcode>:<smsc-id> route.
1566  */
1567  Octstr *os = octstr_format("%s:%s",
1568  octstr_get_cstr(msg->sms.receiver),
1569  octstr_get_cstr(msg->sms.smsc_id));
1570  s = (msg->sms.smsc_id ? dict_get(smsbox_by_smsc, msg->sms.smsc_id) : NULL);
1571  r = (msg->sms.receiver ? dict_get(smsbox_by_receiver, msg->sms.receiver) : NULL);
1572  rs = (os ? dict_get(smsbox_by_smsc_receiver, os) : NULL);
1573  octstr_destroy(os);
1574 
1575  if (rs)
1576  boxc_id = rs;
1577  else if (r)
1578  boxc_id = r;
1579  else if (s)
1580  boxc_id = s;
1581  }
1582 
1583  /* We have a specific smsbox-id to use */
1584  if (boxc_id != NULL) {
1585 
1586  List *boxc_id_list = dict_get(smsbox_by_id, boxc_id);
1587  if (gwlist_len(boxc_id_list) == 0) {
1588  /*
1589  * something is wrong, this was the smsbox connection we used
1590  * for sending, so it seems this smsbox is gone
1591  */
1592  warning(0, "Could not route message to smsbox id <%s>, smsbox is gone!",
1593  octstr_get_cstr(boxc_id));
1595  if (max_incoming_sms_qlength < 0 || max_incoming_sms_qlength > gwlist_len(incoming_sms)) {
1597  return 0;
1598  } else {
1599  return -1;
1600  }
1601  }
1602 
1603  /*
1604  * Take random smsbox from list, as long as it has space we will use it,
1605  * otherwise check the next one.
1606  */
1607  len = gwlist_len(boxc_id_list);
1608  b = gw_rand() % len;
1609 
1610  for (i = 0; i < len; i++) {
1611  bc = gwlist_get(boxc_id_list, (i+b) % len);
1612 
1613  if (bc != NULL && max_incoming_sms_qlength > 0 &&
1615  bc = NULL;
1616  }
1617 
1618  if (bc != NULL) {
1619  break;
1620  }
1621  }
1622 
1623  if (bc != NULL) {
1624  bc->load++;
1625  gwlist_produce(bc->incoming, msg);
1627  return 1; /* we are done */
1628  }
1629  else {
1630  /*
1631  * we have routing defined, but no smsbox connected at the moment.
1632  * put msg into global incoming queue and wait until smsbox with
1633  * such boxc_id connected.
1634  */
1636  if (max_incoming_sms_qlength < 0 || max_incoming_sms_qlength > gwlist_len(incoming_sms)) {
1638  return 0;
1639  } else {
1640  return -1;
1641  }
1642  }
1643  }
1644 
1645  /*
1646  * Ok, none of the specific routing things applied previously,
1647  * so route it to a random smsbox.
1648  * Take random smsbox from list, as long as it has space we will
1649  * use it, therwise check the next one.
1650  */
1651  len = gwlist_len(smsbox_list);
1652  b = gw_rand() % len;
1653 
1654  for (i = 0; i < len; i++) {
1655  bc = gwlist_get(smsbox_list, (i+b) % len);
1656 
1657  if (bc->boxc_id != NULL || bc->routable == 0)
1658  bc = NULL;
1659 
1660  if (bc != NULL && max_incoming_sms_qlength > 0 &&
1662  full_found = 1;
1663  bc = NULL;
1664  }
1665 
1666  if (bc != NULL) {
1667  break;
1668  }
1669  }
1670 
1671  if (bc != NULL) {
1672  bc->load++;
1673  gwlist_produce(bc->incoming, msg);
1674  }
1675 
1677 
1678  if (bc == NULL && full_found == 0) {
1679  warning(0, "smsbox_list empty!");
1680  if (max_incoming_sms_qlength < 0 || max_incoming_sms_qlength > gwlist_len(incoming_sms)) {
1682  return 0;
1683  } else {
1684  return -1;
1685  }
1686  } else if (bc == NULL && full_found == 1) {
1687  return -1;
1688  }
1689 
1690  return 1;
1691 }
List * incoming
Definition: opensmppbox.c:153
gw_assert(wtls_machine->packet_to_send !=NULL)
static Dict * smsbox_by_smsc
Definition: bb_boxc.c:111
void gwlist_produce(List *list, void *item)
Definition: list.c:411
static RWLock * smsbox_list_rwlock
Definition: bb_boxc.c:107
long gwlist_len(List *list)
Definition: list.c:166
void * gwlist_get(List *list, long pos)
Definition: list.c:292
msg_type
Definition: msg.h:73
int load
Definition: opensmppbox.c:147
List * incoming_sms
Definition: bearerbox.c:84
int gw_rwlock_rdlock(RWLock *lock)
Definition: gw-rwlock.c:134
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
static Dict * smsbox_by_receiver
Definition: bb_boxc.c:112
long max_incoming_sms_qlength
Definition: bearerbox.c:98
Octstr * boxc_id
Definition: opensmppbox.c:159
void * dict_get(Dict *dict, Octstr *key)
Definition: dict.c:286
static Dict * smsbox_by_id
Definition: bb_boxc.c:110
int gw_rwlock_unlock(RWLock *lock)
Definition: gw-rwlock.c:155
void warning(int err, const char *fmt,...)
Definition: log.c:660
Octstr * octstr_format(const char *fmt,...)
Definition: octstr.c:2464
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
static Dict * smsbox_by_smsc_receiver
Definition: bb_boxc.c:113
long octstr_len(const Octstr *ostr)
Definition: octstr.c:342
Definition: octstr.c:118
static List * smsbox_list
Definition: bb_boxc.c:106
volatile int routable
Definition: opensmppbox.c:166
int gw_rand(void)
Definition: protected.c:174
Definition: list.c:102
static XMLRPCDocument * msg
Definition: test_xmlrpc.c:86

◆ smsbox_restart()

int smsbox_restart ( Cfg config)

Definition at line 1301 of file bb_boxc.c.

References cfg, dict_create(), dict_destroy(), gw_rwlock_unlock(), gw_rwlock_wrlock(), init_smsbox_routes(), octstr_destroy(), smsbox_by_receiver, smsbox_by_smsc, smsbox_by_smsc_receiver, smsbox_list_rwlock, and smsbox_running.

Referenced by bb_graceful_restart().

1302 {
1303  if (!smsbox_running) return -1;
1304 
1309  smsbox_by_smsc = dict_create(30, (void(*)(void *)) octstr_destroy);
1310  smsbox_by_receiver = dict_create(50, (void(*)(void *)) octstr_destroy);
1311  smsbox_by_smsc_receiver = dict_create(50, (void(*)(void *)) octstr_destroy);
1312  init_smsbox_routes(cfg, 1);
1314 
1315  return 0;
1316 }
Dict * dict_create(long size_hint, void(*destroy_value)(void *))
Definition: dict.c:192
static volatile sig_atomic_t smsbox_running
Definition: bb_boxc.c:103
static Dict * smsbox_by_smsc
Definition: bb_boxc.c:111
static RWLock * smsbox_list_rwlock
Definition: bb_boxc.c:107
int gw_rwlock_wrlock(RWLock *lock)
Definition: gw-rwlock.c:177
static Cfg * cfg
Definition: opensmppbox.c:95
static Dict * smsbox_by_receiver
Definition: bb_boxc.c:112
int gw_rwlock_unlock(RWLock *lock)
Definition: gw-rwlock.c:155
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
static Dict * smsbox_by_smsc_receiver
Definition: bb_boxc.c:113
static void init_smsbox_routes(Cfg *cfg, int reload)
Definition: bb_boxc.c:1122
void dict_destroy(Dict *dict)
Definition: dict.c:215

◆ smsbox_start()

int smsbox_start ( Cfg config)

Definition at line 1236 of file bb_boxc.c.

References box_allow_ip, box_deny_ip, boxc_gwlist_destroy(), boxid, cfg, cfg_get, cfg_get_bool(), cfg_get_integer(), cfg_get_single_group(), counter_create(), debug(), dict_create(), error(), gw_rwlock_create(), gwlist_add_producer(), gwlist_create, gwthread_create, info(), init_smsbox_routes(), octstr_create, octstr_destroy(), octstr_imm(), outgoing_sms, panic, sms_dequeue_thread, sms_to_smsboxes(), smsbox_by_id, smsbox_by_receiver, smsbox_by_smsc, smsbox_by_smsc_receiver, smsbox_interface, smsbox_list, smsbox_list_rwlock, SMSBOX_MAX_PENDING, smsbox_max_pending, smsbox_port, smsbox_port_ssl, smsbox_running, and smsboxc_run().

Referenced by start_smsc().

1237 {
1238  CfgGroup *grp;
1239 
1240  if (smsbox_running) return -1;
1241 
1242  debug("bb", 0, "starting smsbox connection module");
1243 
1244  grp = cfg_get_single_group(cfg, octstr_imm("core"));
1245  if (cfg_get_integer(&smsbox_port, grp, octstr_imm("smsbox-port")) == -1) {
1246  error(0, "Missing smsbox-port variable, cannot start smsboxes");
1247  return -1;
1248  }
1249 #ifdef HAVE_LIBSSL
1250  cfg_get_bool(&smsbox_port_ssl, grp, octstr_imm("smsbox-port-ssl"));
1251 #endif /* HAVE_LIBSSL */
1252 
1253  if (smsbox_port_ssl)
1254  debug("bb", 0, "smsbox connection module is SSL-enabled");
1255 
1256  smsbox_interface = cfg_get(grp, octstr_imm("smsbox-interface"));
1257 
1258  if (cfg_get_integer(&smsbox_max_pending, grp, octstr_imm("smsbox-max-pending")) == -1) {
1260  info(0, "BOXC: 'smsbox-max-pending' not set, using default (%ld).", smsbox_max_pending);
1261  }
1262 
1263  box_allow_ip = cfg_get(grp, octstr_imm("box-allow-ip"));
1264  if (box_allow_ip == NULL)
1266  box_deny_ip = cfg_get(grp, octstr_imm("box-deny-ip"));
1267  if (box_deny_ip == NULL)
1268  box_deny_ip = octstr_create("");
1269  if (box_allow_ip != NULL && box_deny_ip == NULL)
1270  info(0, "Box connection allowed IPs defined without any denied...");
1271 
1272  smsbox_list = gwlist_create(); /* have a list of connections */
1274  if (!boxid)
1275  boxid = counter_create();
1276 
1277  /* the smsbox routing specific inits */
1278  smsbox_by_id = dict_create(10, (void(*)(void *)) boxc_gwlist_destroy);
1279  smsbox_by_smsc = dict_create(30, (void(*)(void *)) octstr_destroy);
1280  smsbox_by_receiver = dict_create(50, (void(*)(void *)) octstr_destroy);
1281  smsbox_by_smsc_receiver = dict_create(50, (void(*)(void *)) octstr_destroy);
1282 
1283  /* load the defined smsbox routing rules */
1284  init_smsbox_routes(cfg, 0);
1285 
1288 
1289  smsbox_running = 1;
1290 
1291  if ((sms_dequeue_thread = gwthread_create(sms_to_smsboxes, NULL)) == -1)
1292  panic(0, "Failed to start a new thread for smsbox routing");
1293 
1294  if (gwthread_create(smsboxc_run, NULL) == -1)
1295  panic(0, "Failed to start a new thread for smsbox connections");
1296 
1297  return 0;
1298 }
Dict * dict_create(long size_hint, void(*destroy_value)(void *))
Definition: dict.c:192
static volatile sig_atomic_t smsbox_running
Definition: bb_boxc.c:103
void error(int err, const char *fmt,...)
Definition: log.c:648
void info(int err, const char *fmt,...)
Definition: log.c:672
static void sms_to_smsboxes(void *arg)
Definition: bb_boxc.c:1694
static Dict * smsbox_by_smsc
Definition: bb_boxc.c:111
static RWLock * smsbox_list_rwlock
Definition: bb_boxc.c:107
#define cfg_get(grp, varname)
Definition: cfg.h:86
static int smsbox_port_ssl
Definition: bb_boxc.c:116
RWLock * gw_rwlock_create(void)
Definition: gw-rwlock.c:77
static Cfg * cfg
Definition: opensmppbox.c:95
static Octstr * box_deny_ip
Definition: bb_boxc.c:125
static Dict * smsbox_by_receiver
Definition: bb_boxc.c:112
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:283
Counter * counter_create(void)
Definition: counter.c:94
List * outgoing_sms
Definition: bearerbox.c:85
static Dict * smsbox_by_id
Definition: bb_boxc.c:110
static Octstr * smsbox_interface
Definition: bb_boxc.c:117
static void smsboxc_run(void *arg)
Definition: bb_boxc.c:1017
static void boxc_gwlist_destroy(List *list)
Definition: bb_boxc.c:1767
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
#define gwthread_create(func, arg)
Definition: gwthread.h:90
#define octstr_create(cstr)
Definition: octstr.h:125
static long smsbox_max_pending
Definition: bb_boxc.c:122
static Dict * smsbox_by_smsc_receiver
Definition: bb_boxc.c:113
static Counter * boxid
Definition: bb_boxc.c:128
static void init_smsbox_routes(Cfg *cfg, int reload)
Definition: bb_boxc.c:1122
int cfg_get_bool(int *n, CfgGroup *grp, Octstr *varname)
Definition: cfg.c:757
static long smsbox_port
Definition: bb_boxc.c:115
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:726
int cfg_get_integer(long *n, CfgGroup *grp, Octstr *varname)
Definition: cfg.c:740
#define panic
Definition: log.h:87
Definition: cfg.c:73
static Octstr * box_allow_ip
Definition: bb_boxc.c:124
static List * smsbox_list
Definition: bb_boxc.c:106
#define gwlist_create()
Definition: list.h:136
static long sms_dequeue_thread
Definition: bb_boxc.c:131
CfgGroup * cfg_get_single_group(Cfg *cfg, Octstr *name)
Definition: cfg.c:637
void gwlist_add_producer(List *list)
Definition: list.c:383
#define SMSBOX_MAX_PENDING
Definition: bb_boxc.c:83

◆ smsc2_add_smsc()

int smsc2_add_smsc ( Octstr id)

Definition at line 1112 of file bb_smscconn.c.

References bb_reload_smsc_groups(), cfg_get, smscconn::dead_start, error(), gw_rwlock_unlock(), gw_rwlock_wrlock(), gwlist_add_producer(), gwlist_append(), gwlist_get(), gwlist_len(), gwlist_remove_producer(), octstr_compare(), octstr_get_cstr, octstr_imm(), smsc2_find(), smsc_groups, smsc_list, smsc_list_lock, smsc_running, smscconn_create(), smscconn_shutdown(), smscconn_start(), and warning().

Referenced by bb_add_smsc().

1113 {
1114  CfgGroup *grp;
1115  SMSCConn *conn;
1116  Octstr *smscid = NULL;
1117  long i;
1118  int success = 0;
1119 
1120  if (!smsc_running)
1121  return -1;
1122 
1124  if (bb_reload_smsc_groups() != 0) {
1126  return -1;
1127  }
1128 
1129  if (smsc2_find(id, 0) != -1) {
1130  warning(0, "Could not add already existing SMSC %s", octstr_get_cstr(id));
1132  return -1;
1133  }
1134 
1136  grp = NULL;
1137  for (i = 0; i < gwlist_len(smsc_groups) &&
1138  (grp = gwlist_get(smsc_groups, i)) != NULL; i++) {
1139  smscid = cfg_get(grp, octstr_imm("smsc-admin-id"));
1140  if (smscid == NULL)
1141  smscid = cfg_get(grp, octstr_imm("smsc-id"));
1142 
1143  if (smscid != NULL && octstr_compare(smscid, id) == 0) {
1144  conn = smscconn_create(grp, 1);
1145  if (conn != NULL) {
1146  gwlist_append(smsc_list, conn);
1147  if (conn->dead_start) {
1148  /* Shutdown connection if it's not configured to connect at start-up time */
1149  smscconn_shutdown(conn, 0);
1150  } else {
1151  smscconn_start(conn);
1152  }
1153  success = 1;
1154  }
1155  }
1156  }
1159  if (success == 0) {
1160  error(0, "SMSC %s not found", octstr_get_cstr(id));
1161  return -1;
1162  }
1163  return 0;
1164 }
void error(int err, const char *fmt,...)
Definition: log.c:648
static List * smsc_groups
Definition: bb_smscconn.c:131
void gwlist_append(List *list, void *item)
Definition: list.c:179
int dead_start
Definition: smscconn_p.h:210
void smscconn_shutdown(SMSCConn *conn, int finish_sending)
Definition: smscconn.c:378
static RWLock smsc_list_lock
Definition: bb_smscconn.c:129
long gwlist_len(List *list)
Definition: list.c:166
int gw_rwlock_wrlock(RWLock *lock)
Definition: gw-rwlock.c:177
void * gwlist_get(List *list, long pos)
Definition: list.c:292
#define cfg_get(grp, varname)
Definition: cfg.h:86
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:283
void gwlist_remove_producer(List *list)
Definition: list.c:401
int bb_reload_smsc_groups()
Definition: bb_smscconn.c:628
int gw_rwlock_unlock(RWLock *lock)
Definition: gw-rwlock.c:155
void warning(int err, const char *fmt,...)
Definition: log.c:660
Definition: octstr.c:118
Definition: cfg.c:73
SMSCConn * smscconn_create(CfgGroup *grp, int start_as_stopped)
Definition: smscconn.c:162
void gwlist_add_producer(List *list)
Definition: list.c:383
static volatile sig_atomic_t smsc_running
Definition: bb_smscconn.c:127
void smscconn_start(SMSCConn *conn)
Definition: smscconn.c:477
static List * smsc_list
Definition: bb_smscconn.c:128
int octstr_compare(const Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:871
static long smsc2_find(Octstr *id, long start)
Definition: bb_smscconn.c:948

◆ smsc2_cleanup()

void smsc2_cleanup ( void  )

Definition at line 1306 of file bb_smscconn.c.

References black_list_receiver, black_list_receiver_regex, black_list_receiver_url, black_list_sender, black_list_sender_regex, black_list_sender_url, concat_handling_cleanup(), counter_destroy(), debug(), gw_rwlock_destroy(), gw_rwlock_unlock(), gw_rwlock_wrlock(), gwlist_destroy(), gwlist_get(), gwlist_len(), numhash_destroy(), octstr_destroy(), smsc_groups, smsc_list, smsc_list_lock, smsc_running, smscconn_destroy(), split_msg_counter, unified_prefix, white_black_list_lock, white_list_receiver, white_list_receiver_regex, white_list_receiver_url, white_list_sender, white_list_sender_regex, and white_list_sender_url.

Referenced by main().

1307 {
1308  SMSCConn *conn;
1309  long i;
1310 
1311  if (!smsc_running)
1312  return;
1313 
1314  debug("smscconn", 0, "final clean-up for SMSCConn");
1315 
1317  for (i = 0; i < gwlist_len(smsc_list); i++) {
1318  conn = gwlist_get(smsc_list, i);
1319  smscconn_destroy(conn);
1320  }
1321  gwlist_destroy(smsc_list, NULL);
1322  smsc_list = NULL;
1324  gwlist_destroy(smsc_groups, NULL);
1330  if (white_list_sender_regex != NULL)
1331  gw_regex_destroy(white_list_sender_regex);
1332  if (black_list_sender_regex != NULL)
1333  gw_regex_destroy(black_list_sender_regex);
1338  if (white_list_receiver_regex != NULL)
1339  gw_regex_destroy(white_list_receiver_regex);
1340  if (black_list_receiver_regex != NULL)
1341  gw_regex_destroy(black_list_receiver_regex);
1342  /* destroy msg split counter */
1346 
1347  /* Stop concat handling */
1349 
1350  smsc_running = 0;
1351 }
static List * smsc_groups
Definition: bb_smscconn.c:131
int smscconn_destroy(SMSCConn *conn)
Definition: smscconn.c:406
void counter_destroy(Counter *counter)
Definition: counter.c:110
static regex_t * white_list_sender_regex
Definition: bb_smscconn.c:144
static RWLock smsc_list_lock
Definition: bb_smscconn.c:129
long gwlist_len(List *list)
Definition: list.c:166
void gw_rwlock_destroy(RWLock *lock)
Definition: gw-rwlock.c:112
int gw_rwlock_wrlock(RWLock *lock)
Definition: gw-rwlock.c:177
void * gwlist_get(List *list, long pos)
Definition: list.c:292
static regex_t * black_list_receiver_regex
Definition: bb_smscconn.c:147
void numhash_destroy(Numhash *table)
Definition: numhash.c:275
static RWLock white_black_list_lock
Definition: bb_smscconn.c:134
static Numhash * white_list_sender
Definition: bb_smscconn.c:140
static Octstr * black_list_receiver_url
Definition: bb_smscconn.c:137
static Numhash * black_list_sender
Definition: bb_smscconn.c:139
static void concat_handling_cleanup(void)
Definition: bb_smscconn.c:2037
int gw_rwlock_unlock(RWLock *lock)
Definition: gw-rwlock.c:155
Counter * split_msg_counter
Definition: bb_smscconn.c:159
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
static regex_t * white_list_receiver_regex
Definition: bb_smscconn.c:146
static Octstr * white_list_sender_url
Definition: bb_smscconn.c:136
static Numhash * white_list_receiver
Definition: bb_smscconn.c:142
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:726
static Octstr * unified_prefix
Definition: bb_smscconn.c:132
static Octstr * black_list_sender_url
Definition: bb_smscconn.c:135
static Octstr * white_list_receiver_url
Definition: bb_smscconn.c:138
static regex_t * black_list_sender_regex
Definition: bb_smscconn.c:145
static volatile sig_atomic_t smsc_running
Definition: bb_smscconn.c:127
static Numhash * black_list_receiver
Definition: bb_smscconn.c:141
static List * smsc_list
Definition: bb_smscconn.c:128
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)
Definition: list.c:145

◆ smsc2_graceful_restart()

int smsc2_graceful_restart ( Cfg config)

Definition at line 1522 of file bb_smscconn.c.

References cfg, cfg_get_multi_group(), cmp_conn_grp_checksum(), cmp_conn_grp_id(), cmp_rout_grp_checksum(), gw_rwlock_unlock(), gw_rwlock_wrlock(), gwlist_add_producer(), gwlist_append(), gwlist_create, gwlist_delete(), gwlist_destroy(), gwlist_extract_first(), gwlist_get(), gwlist_len(), gwlist_remove_producer(), gwlist_search_all(), gwlist_search_equal(), gwthread_sleep(), gwthread_wakeup(), smscconn::id, info(), octstr_get_cstr, octstr_imm(), router_thread, smsc_groups, smsc_list, smsc_list_lock, smsc_running, smscconn_create(), smscconn_destroy(), smscconn_instances(), smscconn_reconfig(), smscconn_shutdown(), and smscconn_start().

Referenced by bb_graceful_restart().

1523 {
1524  CfgGroup *grp;
1525  SMSCConn *conn;
1526  List *keep, *add, *remove;
1527  List *l;
1528  int i, m;
1529 
1530  if (!smsc_running)
1531  return -1;
1532 
1534 
1535  /* load the smsc groups from the config resource */
1536  gwlist_destroy(smsc_groups, NULL);
1538 
1539  /* List of SMSCConn that we keep running */
1540  keep = gwlist_create();
1541 
1542  /* List of CfgGroup that we will add */
1543  add = gwlist_create();
1544 
1545  /* List of SMSCConnn that we will shutdown */
1546  remove = gwlist_create();
1547 
1548  /*
1549  * Loop through the loaded smsc groups
1550  */
1551  for (i = 0; i < gwlist_len(smsc_groups) &&
1552  (grp = gwlist_get(smsc_groups, i)) != NULL; i++) {
1553  /*
1554  * 1st check: Search for the same md5 hash of the whole group.
1555  * If we find it, then this group is already running, and no
1556  * routing information has changed, bail out.
1557  */
1558  if ((l = gwlist_search_all(smsc_list, grp, cmp_conn_grp_checksum)) != NULL) {
1559  while ((conn = gwlist_extract_first(l)) != NULL) {
1560  gwlist_append(keep, conn);
1561  }
1562  gwlist_destroy(l, NULL);
1563  continue;
1564  }
1565  /*
1566  * 2nd check: Search for the same md5 hash minus the routing
1567  * information. If we find it, then this group is already running
1568  * and the routing information changed, we'll apply only the new
1569  * routing information.
1570  */
1571  if ((l = gwlist_search_all(smsc_list, grp, cmp_rout_grp_checksum)) != NULL) {
1572  while ((conn = gwlist_extract_first(l)) != NULL) {
1573  gwlist_append(keep, conn);
1574  smscconn_reconfig(conn, grp);
1575  info(0, "Re-configured routing for smsc-id `%s'.", octstr_get_cstr(conn->id));
1576  }
1577  gwlist_destroy(l, NULL);
1578  continue;
1579  }
1580  /*
1581  * 3rd check: if the smsc-id is NOT in the running list, then
1582  * this is a new group, add it. If the smsc-id IS found, then
1583  * mark it/them to be removed, and add the new group.
1584  */
1585  if ((l = gwlist_search_all(smsc_list, grp, cmp_conn_grp_id)) == NULL) {
1586  gwlist_append(add, grp);
1587  continue;
1588  } else {
1589  while ((conn = gwlist_extract_first(l)) != NULL) {
1590  /* add them to the remove list only
1591  * if they are not yet present inside. */
1592  if (gwlist_search_equal(remove, conn) != -1)
1593  gwlist_append(remove, conn);
1594  }
1595  gwlist_destroy(l, NULL);
1596  gwlist_append(add, grp);
1597  continue;
1598  }
1599  }
1600 
1601  /*
1602  * TODO Effectively a change in the 'instances' multiplier will result in a
1603  * disconnect of all running instances, and re-connecting the number of
1604  * configured instances. The reason for this is that the change in the
1605  * 'instances' value causes the md5 hash to be different for that connection.
1606  * We MAY exclude the 'instances' directive from the while md5 checksum, this
1607  * makes the down-grading easier, allowing the rest to keep running. But the
1608  * up-grading is more difficult, since we can't use the 'add' list here, it
1609  * would create too much instances.
1610  */
1611 
1612  /*
1613  * We may have running smsc-ids now, that haven't been
1614  * re-loaded from the new config, hence add them to be removed.
1615  */
1616  for (i = 0; i < gwlist_len(smsc_list) &&
1617  (conn = gwlist_get(smsc_list, i)) != NULL; i++) {
1618  /* if this is already in the remove list, bail out. */
1619  if (gwlist_search_equal(remove, conn) != -1)
1620  continue;
1621  /* if this is in the keep list, bail out. */
1622  if (gwlist_search_equal(keep, conn) != -1)
1623  continue;
1624  /* mark it to be removed */
1625  gwlist_append(remove, conn);
1626  }
1627  gwlist_destroy(keep, NULL);
1628 
1629  /*
1630  * Stop any connections from the remove list.
1631  *
1632  * The smscconn_shutdown() only initiates the shutdown,
1633  * it is not guaranteed that the SMSC connection is stopped
1634  * and the status is SMSCCONN_DEAD when we return from the
1635  * function call. Therefore we pass the connection to a
1636  * retry list, in order to cleanly destroy all connection
1637  * structures that have been stopped and reached SMSSCONN_DEAD.
1638  */
1639  l = gwlist_create();
1641  while ((conn = gwlist_extract_first(remove)) != NULL) {
1642  if ((i = gwlist_search_equal(smsc_list, conn)) != -1) {
1643  gwlist_delete(smsc_list, i, 1);
1644  smscconn_shutdown(conn, 0);
1645  /* if smsc is still in shutdown, then add to retry list */
1646  if (smscconn_destroy(conn) == -1)
1647  gwlist_append(l, conn);
1648  }
1649  }
1651  gwlist_destroy(remove, NULL);
1652 
1653  /*
1654  * Start any connections from the add list.
1655  */
1657  while ((grp = gwlist_extract_first(add)) != NULL) {
1658  /* multiple instances for the same group? */
1659  m = smscconn_instances(grp);
1660  for (i = 0; i < m; i++) {
1661  conn = smscconn_create(grp, 1);
1662  if (conn != NULL) {
1663  gwlist_append(smsc_list, conn);
1664  if (conn->dead_start) {
1665  /* Shutdown connection if it's not configured to connect at start-up time */
1666  smscconn_shutdown(conn, 0);
1667  } else {
1668  smscconn_start(conn);
1669  }
1670  }
1671  }
1672  }
1674  gwlist_destroy(add, NULL);
1675 
1677 
1678  /* wake-up the router */
1679  if (router_thread >= 0)
1681 
1682  /*
1683  * We may still have pending connections in the retry list
1684  * that haven't been destroyed yet.
1685  */
1686  while ((conn = gwlist_extract_first(l)) != NULL) {
1687  if (smscconn_destroy(conn) == -1) {
1688  gwlist_append(l, conn);
1689  gwthread_sleep(2);
1690  }
1691  }
1692  gwlist_destroy(l, NULL);
1693 
1694  return 0;
1695 }
void info(int err, const char *fmt,...)
Definition: log.c:672
long gwlist_search_equal(List *list, void *item)
Definition: list.c:534
static List * smsc_groups
Definition: bb_smscconn.c:131
static long router_thread
Definition: bb_smscconn.c:149
int smscconn_destroy(SMSCConn *conn)
Definition: smscconn.c:406
void gwlist_append(List *list, void *item)
Definition: list.c:179
void smscconn_shutdown(SMSCConn *conn, int finish_sending)
Definition: smscconn.c:378
static RWLock smsc_list_lock
Definition: bb_smscconn.c:129
Octstr * id
Definition: smscconn_p.h:174
long gwlist_len(List *list)
Definition: list.c:166
int gw_rwlock_wrlock(RWLock *lock)
Definition: gw-rwlock.c:177
void * gwlist_get(List *list, long pos)
Definition: list.c:292
static int cmp_conn_grp_id(void *a, void *b)
Definition: bb_smscconn.c:788
static Cfg * cfg
Definition: opensmppbox.c:95
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
unsigned int smscconn_instances(CfgGroup *grp)
Definition: smscconn.c:149
List * gwlist_search_all(List *list, void *pattern, int(*cmp)(void *, void *))
Definition: list.c:508
void smscconn_reconfig(SMSCConn *conn, CfgGroup *grp)
Definition: smscconn.c:704
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:283
void * gwlist_extract_first(List *list)
Definition: list.c:305
void gwlist_delete(List *list, long pos, long count)
Definition: list.c:232
void gwlist_remove_producer(List *list)
Definition: list.c:401
static int cmp_conn_grp_checksum(void *a, void *b)
Definition: bb_smscconn.c:735
List * cfg_get_multi_group(Cfg *cfg, Octstr *name)
Definition: cfg.c:643
int gw_rwlock_unlock(RWLock *lock)
Definition: gw-rwlock.c:155
void gwthread_sleep(double seconds)
static int cmp_rout_grp_checksum(void *a, void *b)
Definition: bb_smscconn.c:752
void gwthread_wakeup(long thread)
Definition: cfg.c:73
#define gwlist_create()
Definition: list.h:136
SMSCConn * smscconn_create(CfgGroup *grp, int start_as_stopped)
Definition: smscconn.c:162
void gwlist_add_producer(List *list)
Definition: list.c:383
static volatile sig_atomic_t smsc_running
Definition: bb_smscconn.c:127
Definition: list.c:102
void smscconn_start(SMSCConn *conn)
Definition: smscconn.c:477
static List * smsc_list
Definition: bb_smscconn.c:128
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)
Definition: list.c:145

◆ smsc2_reload_lists()

int smsc2_reload_lists ( void  )

Definition at line 1166 of file bb_smscconn.c.

References black_list_receiver, black_list_receiver_url, black_list_sender, black_list_sender_url, error(), gw_rwlock_unlock(), gw_rwlock_wrlock(), numhash_create(), numhash_destroy(), octstr_get_cstr, white_black_list_lock, white_list_receiver, white_list_receiver_url, white_list_sender, and white_list_sender_url.

Referenced by bb_reload_lists().

1167 {
1168  Numhash *tmp;
1169  int rc = 1;
1170 
1171  if (white_list_sender_url != NULL) {
1173  if (white_list_sender == NULL) {
1174  error(0, "Unable to reload white_list."),
1175  rc = -1;
1176  } else {
1179  white_list_sender = tmp;
1181  }
1182  }
1183 
1184  if (black_list_sender_url != NULL) {
1186  if (black_list_sender == NULL) {
1187  error(0, "Unable to reload black_list");
1188  rc = -1;
1189  } else {
1192  black_list_sender = tmp;
1194  }
1195  }
1196 
1197  if (white_list_receiver_url != NULL) {
1199  if (white_list_receiver == NULL) {
1200  error(0, "Unable to reload white_list."),
1201  rc = -1;
1202  } else {
1205  white_list_receiver = tmp;
1207  }
1208  }
1209 
1210  if (black_list_receiver_url != NULL) {
1212  if (black_list_receiver == NULL) {
1213  error(0, "Unable to reload black_list");
1214  rc = -1;
1215  } else {
1218  black_list_receiver = tmp;
1220  }
1221  }
1222 
1223  return rc;
1224 }
void error(int err, const char *fmt,...)
Definition: log.c:648
int gw_rwlock_wrlock(RWLock *lock)
Definition: gw-rwlock.c:177
void numhash_destroy(Numhash *table)
Definition: numhash.c:275
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
static RWLock white_black_list_lock
Definition: bb_smscconn.c:134
Numhash * numhash_create(const char *seek_url)
Definition: numhash.c:313
static Numhash * white_list_sender
Definition: bb_smscconn.c:140
static Octstr * black_list_receiver_url
Definition: bb_smscconn.c:137
static Numhash * black_list_sender
Definition: bb_smscconn.c:139
int gw_rwlock_unlock(RWLock *lock)
Definition: gw-rwlock.c:155
static Octstr * white_list_sender_url
Definition: bb_smscconn.c:136
static Numhash * white_list_receiver
Definition: bb_smscconn.c:142
static Octstr * black_list_sender_url
Definition: bb_smscconn.c:135
static Octstr * white_list_receiver_url
Definition: bb_smscconn.c:138
static Numhash * black_list_receiver
Definition: bb_smscconn.c:141

◆ smsc2_remove_smsc()

int smsc2_remove_smsc ( Octstr id)

Definition at line 1083 of file bb_smscconn.c.

References error(), gw_rwlock_unlock(), gw_rwlock_wrlock(), gwlist_add_producer(), gwlist_delete(), gwlist_get(), gwlist_remove_producer(), octstr_get_cstr, smsc2_find(), smsc_list, smsc_list_lock, smsc_running, smscconn_destroy(), and smscconn_shutdown().

Referenced by bb_remove_smsc().

1084 {
1085  SMSCConn *conn;
1086  long i = -1;
1087  int success = 0;
1088 
1089  if (!smsc_running)
1090  return -1;
1091 
1093 
1095  while((i = smsc2_find(id, ++i)) != -1) {
1096  conn = gwlist_get(smsc_list, i);
1097  gwlist_delete(smsc_list, i, 1);
1098  smscconn_shutdown(conn, 0);
1099  smscconn_destroy(conn);
1100  success = 1;
1101  }
1103 
1105  if (success == 0) {
1106  error(0, "SMSC %s not found", octstr_get_cstr(id));
1107  return -1;
1108  }
1109  return 0;
1110 }
void error(int err, const char *fmt,...)
Definition: log.c:648
int smscconn_destroy(SMSCConn *conn)
Definition: smscconn.c:406
void smscconn_shutdown(SMSCConn *conn, int finish_sending)
Definition: smscconn.c:378
static RWLock smsc_list_lock
Definition: bb_smscconn.c:129
int gw_rwlock_wrlock(RWLock *lock)
Definition: gw-rwlock.c:177
void * gwlist_get(List *list, long pos)
Definition: list.c:292
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
void gwlist_delete(List *list, long pos, long count)
Definition: list.c:232
void gwlist_remove_producer(List *list)
Definition: list.c:401
int gw_rwlock_unlock(RWLock *lock)
Definition: gw-rwlock.c:155
void gwlist_add_producer(List *list)
Definition: list.c:383
static volatile sig_atomic_t smsc_running
Definition: bb_smscconn.c:127
static List * smsc_list
Definition: bb_smscconn.c:128
static long smsc2_find(Octstr *id, long start)
Definition: bb_smscconn.c:948

◆ smsc2_restart()

int smsc2_restart ( Cfg config)

◆ smsc2_restart_smsc()

int smsc2_restart_smsc ( Octstr id)

Definition at line 998 of file bb_smscconn.c.

References bb_reload_smsc_groups(), cfg_get, error(), gw_rwlock_unlock(), gw_rwlock_wrlock(), gwlist_delete(), gwlist_get(), gwlist_insert(), gwlist_len(), gwthread_wakeup(), info(), octstr_compare(), octstr_destroy(), octstr_get_cstr, octstr_imm(), router_thread, smsc2_find(), smsc_groups, smsc_list, smsc_list_lock, smsc_running, smscconn_create(), SMSCCONN_DEAD, smscconn_destroy(), smscconn_start(), smscconn_status(), and warning().

Referenced by bb_restart_smsc().

999 {
1000  CfgGroup *grp;
1001  SMSCConn *conn, *new_conn;
1002  Octstr *smscid = NULL;
1003  long i = -1;
1004  int hit;
1005  int num = 0;
1006  int success = 0;
1007 
1008  if (!smsc_running)
1009  return -1;
1010 
1012 
1013  if (bb_reload_smsc_groups() != 0) {
1015  return -1;
1016  }
1017  /* find the specific smsc via id */
1018  while((i = smsc2_find(id, ++i)) != -1) {
1019  long group_index;
1020  /* check if smsc has online status already */
1021  conn = gwlist_get(smsc_list, i);
1022  if (conn != NULL && smscconn_status(conn) != SMSCCONN_DEAD) {
1023  warning(0, "HTTP: Could not re-start already running smsc-id `%s'",
1024  octstr_get_cstr(id));
1025  continue;
1026  }
1027  /* find the group with equal smsc (admin-)id */
1028  hit = -1;
1029  grp = NULL;
1030  for (group_index = 0; group_index < gwlist_len(smsc_groups) &&
1031  (grp = gwlist_get(smsc_groups, group_index)) != NULL; group_index++) {
1032  smscid = cfg_get(grp, octstr_imm("smsc-admin-id"));
1033  if (smscid == NULL)
1034  smscid = cfg_get(grp, octstr_imm("smsc-id"));
1035  if (smscid != NULL && octstr_compare(smscid, id) == 0) {
1036  if (hit < 0)
1037  hit = 0;
1038  if (hit == num)
1039  break;
1040  else
1041  hit++;
1042  }
1043  octstr_destroy(smscid);
1044  smscid = NULL;
1045  }
1046  octstr_destroy(smscid);
1047  if (hit != num) {
1048  /* config group not found */
1049  error(0, "HTTP: Could not find config for smsc-id `%s'", octstr_get_cstr(id));
1050  break;
1051  }
1052 
1053  info(0,"HTTP: Re-starting smsc-id `%s'", octstr_get_cstr(id));
1054 
1055  new_conn = smscconn_create(grp, 1);
1056  if (new_conn == NULL) {
1057  error(0, "Start of SMSC connection failed, smsc-id `%s'", octstr_get_cstr(id));
1058  continue; /* keep old connection on the list */
1059  }
1060 
1061  /* drop old connection from the active smsc list */
1062  gwlist_delete(smsc_list, i, 1);
1063  /* destroy the connection */
1064  smscconn_destroy(conn);
1065  gwlist_insert(smsc_list, i, new_conn);
1066  smscconn_start(new_conn);
1067  success = 1;
1068  num++;
1069  }
1070 
1072 
1073  if (success == 0) {
1074  error(0, "SMSC %s not found", octstr_get_cstr(id));
1075  return -1;
1076  }
1077  /* wake-up the router */
1078  if (router_thread >= 0)
1080  return 0;
1081 }
void error(int err, const char *fmt,...)
Definition: log.c:648
void info(int err, const char *fmt,...)
Definition: log.c:672
static List * smsc_groups
Definition: bb_smscconn.c:131
static long router_thread
Definition: bb_smscconn.c:149
int smscconn_destroy(SMSCConn *conn)
Definition: smscconn.c:406
static RWLock smsc_list_lock
Definition: bb_smscconn.c:129
long gwlist_len(List *list)
Definition: list.c:166
int gw_rwlock_wrlock(RWLock *lock)
Definition: gw-rwlock.c:177
void * gwlist_get(List *list, long pos)
Definition: list.c:292
#define cfg_get(grp, varname)
Definition: cfg.h:86
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:283
int smscconn_status(SMSCConn *conn)
Definition: smscconn.c:665
void gwlist_delete(List *list, long pos, long count)
Definition: list.c:232
int bb_reload_smsc_groups()
Definition: bb_smscconn.c:628
int gw_rwlock_unlock(RWLock *lock)
Definition: gw-rwlock.c:155
void warning(int err, const char *fmt,...)
Definition: log.c:660
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
void gwlist_insert(List *list, long pos, void *item)
Definition: list.c:214
Definition: octstr.c:118
void gwthread_wakeup(long thread)
Definition: cfg.c:73
SMSCConn * smscconn_create(CfgGroup *grp, int start_as_stopped)
Definition: smscconn.c:162
static volatile sig_atomic_t smsc_running
Definition: bb_smscconn.c:127
void smscconn_start(SMSCConn *conn)
Definition: smscconn.c:477
static List * smsc_list
Definition: bb_smscconn.c:128
int octstr_compare(const Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:871
static long smsc2_find(Octstr *id, long start)
Definition: bb_smscconn.c:948

◆ smsc2_resume()

void smsc2_resume ( int  is_init)

Definition at line 1226 of file bb_smscconn.c.

References smscconn::dead_start, gw_rwlock_rdlock(), gw_rwlock_unlock(), gwlist_get(), gwlist_len(), gwthread_wakeup(), router_thread, smsc_list, smsc_list_lock, smsc_running, smscconn_shutdown(), and smscconn_start().

Referenced by bb_resume(), and main().

1227 {
1228  SMSCConn *conn;
1229  long i;
1230 
1231  if (!smsc_running)
1232  return;
1233 
1235  for (i = 0; i < gwlist_len(smsc_list); i++) {
1236  conn = gwlist_get(smsc_list, i);
1237  if (!is_init || !conn->dead_start) {
1238  smscconn_start(conn);
1239  } else {
1240  /* Shutdown the connections that are not configured to start at boot */
1241  smscconn_shutdown(conn, 0);
1242  }
1243  }
1245 
1246  if (router_thread >= 0)
1248 }
static long router_thread
Definition: bb_smscconn.c:149
int dead_start
Definition: smscconn_p.h:210
void smscconn_shutdown(SMSCConn *conn, int finish_sending)
Definition: smscconn.c:378
static RWLock smsc_list_lock
Definition: bb_smscconn.c:129
long gwlist_len(List *list)
Definition: list.c:166
void * gwlist_get(List *list, long pos)
Definition: list.c:292
int gw_rwlock_rdlock(RWLock *lock)
Definition: gw-rwlock.c:134
int gw_rwlock_unlock(RWLock *lock)
Definition: gw-rwlock.c:155
void gwthread_wakeup(long thread)
static volatile sig_atomic_t smsc_running
Definition: bb_smscconn.c:127
void smscconn_start(SMSCConn *conn)
Definition: smscconn.c:477
static List * smsc_list
Definition: bb_smscconn.c:128

◆ smsc2_rout()

long smsc2_rout ( Msg msg,
int  resend 
)

Definition at line 1708 of file bb_smscconn.c.

References BB_SHUTDOWN, bb_smscconn_send_failed(), bb_status, black_list_receiver, black_list_receiver_regex, black_list_sender, black_list_sender_regex, debug(), error(), gw_rand(), gw_rwlock_rdlock(), gw_rwlock_unlock(), gwlist_get(), gwlist_len(), gwlist_produce(), gwlist_search_equal(), info(), smsc_state::load, max_outgoing_sms_qlength, msg, msg_destroy(), msg_duplicate(), normalize_number(), numhash_find_number(), octstr_create, octstr_get_cstr, outgoing_sms, smsc_state::queued, SMS_PARAM_UNDEFINED, smsc2_rout(), split_parts::smsc_conn, smsc_list, smsc_list_lock, SMSCCONN_ACTIVE, SMSCCONN_FAILED_DISCARDED, SMSCCONN_FAILED_EXPIRED, SMSCCONN_FAILED_QFULL, SMSCCONN_FAILED_REJECTED, smscconn_info(), SMSCCONN_QUEUED, smscconn_send(), SMSCCONN_SUCCESS, smscconn_usable(), smsc_state::status, unified_prefix, warning(), white_black_list_lock, white_list_receiver, white_list_receiver_regex, white_list_sender, and white_list_sender_regex.

Referenced by deliver_sms_to_queue(), route_incoming_to_smsc(), sms_router(), and smsc2_rout().

1709 {
1710  StatusInfo stat;
1711  SMSCConn *conn, *best_preferred, *best_ok;
1712  long bp_load, bo_load;
1713  int i, s, ret, bad_found, full_found;
1714  long max_queue, queue_length;
1715  char *uf;
1716 
1717  /* XXX handle ack here? */
1718  if (msg_type(msg) != sms) {
1719  error(0, "Attempt to route non SMS message through smsc2_rout!");
1721  }
1722 
1723  /* check if validity period has expired */
1724  if (msg->sms.validity != SMS_PARAM_UNDEFINED && time(NULL) > msg->sms.validity) {
1726  return SMSCCONN_FAILED_EXPIRED;
1727  }
1728 
1729  /* unify prefix of receiver, in case of it has not been
1730  * already done */
1732  normalize_number(uf, &(msg->sms.receiver));
1733 
1734  /* check for white/back-listed sender/receiver */
1736  if (white_list_sender && numhash_find_number(white_list_sender, msg->sms.sender) < 1) {
1738  info(0, "Number <%s> is not in white-list-sender, message rejected",
1739  octstr_get_cstr(msg->sms.sender));
1740  bb_smscconn_send_failed(NULL, msg_duplicate(msg), SMSCCONN_FAILED_REJECTED, octstr_create("sender not in white-list"));
1741  return SMSCCONN_FAILED_REJECTED;
1742  }
1743 
1744  if (white_list_sender_regex && gw_regex_match_pre(white_list_sender_regex, msg->sms.sender) == 0) {
1746  info(0, "Number <%s> is not in white-list-sender, message rejected",
1747  octstr_get_cstr(msg->sms.sender));
1748  bb_smscconn_send_failed(NULL, msg_duplicate(msg), SMSCCONN_FAILED_REJECTED, octstr_create("sender not in white-list"));
1749  return SMSCCONN_FAILED_REJECTED;
1750  }
1751 
1752  if (black_list_sender && numhash_find_number(black_list_sender, msg->sms.sender) == 1) {
1754  info(0, "Number <%s> is in black-list-sender, message rejected",
1755  octstr_get_cstr(msg->sms.sender));
1757  return SMSCCONN_FAILED_REJECTED;
1758  }
1759 
1760  if (black_list_sender_regex && gw_regex_match_pre(black_list_sender_regex, msg->sms.sender) != 0) {
1762  info(0, "Number <%s> is in black-list-sender, message rejected",
1763  octstr_get_cstr(msg->sms.sender));
1765  return SMSCCONN_FAILED_REJECTED;
1766  }
1767 
1768  if (white_list_receiver && numhash_find_number(white_list_receiver, msg->sms.receiver) < 1) {
1770  info(0, "Number <%s> is not in white-list-receiver, message rejected",
1771  octstr_get_cstr(msg->sms.receiver));
1772  bb_smscconn_send_failed(NULL, msg_duplicate(msg), SMSCCONN_FAILED_REJECTED, octstr_create("receiver not in white-list"));
1773  return SMSCCONN_FAILED_REJECTED;
1774  }
1775 
1776  if (white_list_receiver_regex && gw_regex_match_pre(white_list_receiver_regex, msg->sms.receiver) == 0) {
1778  info(0, "Number <%s> is not in white-list-receiver, message rejected",
1779  octstr_get_cstr(msg->sms.receiver));
1780  bb_smscconn_send_failed(NULL, msg_duplicate(msg), SMSCCONN_FAILED_REJECTED, octstr_create("receiver not in white-list"));
1781  return SMSCCONN_FAILED_REJECTED;
1782  }
1783 
1784  if (black_list_receiver && numhash_find_number(black_list_receiver, msg->sms.receiver) == 1) {
1786  info(0, "Number <%s> is in black-list-receiver, message rejected",
1787  octstr_get_cstr(msg->sms.receiver));
1789  return SMSCCONN_FAILED_REJECTED;
1790  }
1791 
1792  if (black_list_receiver_regex && gw_regex_match_pre(black_list_receiver_regex, msg->sms.receiver) != 0) {
1794  info(0, "Number <%s> is in black-list-receiver, message rejected",
1795  octstr_get_cstr(msg->sms.receiver));
1797  return SMSCCONN_FAILED_REJECTED;
1798  }
1800 
1801  /* select in which list to add this
1802  * start - from random SMSCConn, as they are all 'equal'
1803  */
1805  if (gwlist_len(smsc_list) == 0) {
1806  warning(0, "No SMSCes to receive message");
1809  }
1810 
1811  best_preferred = best_ok = NULL;
1812  bad_found = full_found = 0;
1813  bp_load = bo_load = queue_length = 0;
1814 
1815  if (msg->sms.split_parts == NULL) {
1816  /*
1817  * if global queue not empty then 20% reserved for old msgs
1818  * and 80% for new msgs. So we can guarantee that old msgs find
1819  * place in the SMSC's queue.
1820  */
1821  if (gwlist_len(outgoing_sms) > 0) {
1822  max_queue = (resend ? max_outgoing_sms_qlength :
1823  max_outgoing_sms_qlength * 0.8);
1824  } else
1825  max_queue = max_outgoing_sms_qlength;
1826 
1827  s = gw_rand() % gwlist_len(smsc_list);
1828 
1829  conn = NULL;
1830  for (i = 0; i < gwlist_len(smsc_list); i++) {
1831  conn = gwlist_get(smsc_list, (i+s) % gwlist_len(smsc_list));
1832 
1833  smscconn_info(conn, &stat);
1834  queue_length += (stat.queued > 0 ? stat.queued : 0);
1835 
1836  ret = smscconn_usable(conn,msg);
1837  if (ret == -1)
1838  continue;
1839 
1840  /* if we already have a preferred one, skip non-preferred */
1841  if (ret != 1 && best_preferred)
1842  continue;
1843 
1844  /* If connection is not currently answering ... */
1845  if (stat.status != SMSCCONN_ACTIVE) {
1846  bad_found = 1;
1847  continue;
1848  }
1849  /* check queue length */
1850  if (stat.queued > max_queue) {
1851  full_found = 1;
1852  continue;
1853  }
1854  if (ret == 1) { /* preferred */
1855  if (best_preferred == NULL || stat.load < bp_load) {
1856  best_preferred = conn;
1857  bp_load = stat.load;
1858  continue;
1859  }
1860  }
1861  if (best_ok == NULL || stat.load < bo_load) {
1862  best_ok = conn;
1863  bo_load = stat.load;
1864  }
1865  }
1866  queue_length += gwlist_len(outgoing_sms);
1867  if (max_outgoing_sms_qlength > 0 && !resend &&
1868  queue_length > gwlist_len(smsc_list) * max_outgoing_sms_qlength) {
1870  debug("bb.sms", 0, "sum(#queues) limit");
1871  return SMSCCONN_FAILED_QFULL;
1872  }
1873  } else {
1874  struct split_parts *parts = msg->sms.split_parts;
1875  /* check whether this SMSCConn still on the list */
1876  if (gwlist_search_equal(smsc_list, parts->smsc_conn) != -1)
1877  best_preferred = parts->smsc_conn;
1878  }
1879 
1880  if (best_preferred)
1881  ret = smscconn_send(best_preferred, msg);
1882  else if (best_ok)
1883  ret = smscconn_send(best_ok, msg);
1884  else if (bad_found) {
1888  return SMSCCONN_QUEUED;
1889  }
1890  debug("bb.sms", 0, "bad_found queue full");
1891  return SMSCCONN_FAILED_QFULL; /* queue full */
1892  } else if (full_found) {
1894  debug("bb.sms", 0, "full_found queue full");
1895  return SMSCCONN_FAILED_QFULL;
1896  } else {
1898  if (bb_status == BB_SHUTDOWN) {
1899  msg_destroy(msg);
1900  return SMSCCONN_QUEUED;
1901  }
1902  warning(0, "Cannot find SMSCConn for message to <%s>, rejected.",
1903  octstr_get_cstr(msg->sms.receiver));
1906  }
1907 
1909  /* check the status of sending operation */
1910  if (ret == -1)
1911  return smsc2_rout(msg, resend); /* re-try */
1912 
1913  msg_destroy(msg);
1914  return SMSCCONN_SUCCESS;
1915 }
void error(int err, const char *fmt,...)
Definition: log.c:648
void info(int err, const char *fmt,...)
Definition: log.c:672
Msg * msg_duplicate(Msg *msg)
Definition: msg.c:111
long gwlist_search_equal(List *list, void *item)
Definition: list.c:534
static regex_t * white_list_sender_regex
Definition: bb_smscconn.c:144
void gwlist_produce(List *list, void *item)
Definition: list.c:411
static RWLock smsc_list_lock
Definition: bb_smscconn.c:129
long gwlist_len(List *list)
Definition: list.c:166
void * gwlist_get(List *list, long pos)
Definition: list.c:292
msg_type
Definition: msg.h:73
static regex_t * black_list_receiver_regex
Definition: bb_smscconn.c:147
List * outgoing_sms
Definition: bearerbox.c:85
long max_outgoing_sms_qlength
Definition: bearerbox.c:99
int gw_rwlock_rdlock(RWLock *lock)
Definition: gw-rwlock.c:134
smscconn_status_t status
Definition: smscconn.h:113
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
static RWLock white_black_list_lock
Definition: bb_smscconn.c:134
long queued
Definition: smscconn.h:121
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
void msg_destroy(Msg *msg)
Definition: msg.c:132
int gw_rwlock_unlock(RWLock *lock)
Definition: gw-rwlock.c:155
void warning(int err, const char *fmt,...)
Definition: log.c:660
#define octstr_create(cstr)
Definition: octstr.h:125
static regex_t * white_list_receiver_regex
Definition: bb_smscconn.c:146
#define SMS_PARAM_UNDEFINED
Definition: sms.h:91
int load
Definition: smscconn.h:123
int smscconn_send(SMSCConn *conn, Msg *msg)
Definition: smscconn.c:596
void * smsc_conn
Definition: msg.h:98
static Numhash * white_list_receiver
Definition: bb_smscconn.c:142
int smscconn_usable(SMSCConn *conn, Msg *msg)
Definition: smscconn.c:514
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:726
volatile sig_atomic_t bb_status
Definition: bearerbox.c:132
int normalize_number(char *dial_prefixes, Octstr **number)
Definition: utils.c:882
void bb_smscconn_send_failed(SMSCConn *conn, Msg *sms, int reason, Octstr *reply)
Definition: bb_smscconn.c:328
static Octstr * unified_prefix
Definition: bb_smscconn.c:132
int smscconn_info(SMSCConn *conn, StatusInfo *infotable)
Definition: smscconn.c:673
static regex_t * black_list_sender_regex
Definition: bb_smscconn.c:145
int gw_rand(void)
Definition: protected.c:174
static Numhash * black_list_receiver
Definition: bb_smscconn.c:141
static XMLRPCDocument * msg
Definition: test_xmlrpc.c:86
static List * smsc_list
Definition: bb_smscconn.c:128
long smsc2_rout(Msg *msg, int resend)
Definition: bb_smscconn.c:1708

◆ smsc2_shutdown()

int smsc2_shutdown ( void  )

Definition at line 1268 of file bb_smscconn.c.

References concat_handling_shutdown(), gw_rwlock_rdlock(), gw_rwlock_unlock(), gwlist_get(), gwlist_len(), gwlist_remove_producer(), gwthread_wakeup(), incoming_sms, router_thread, smpp_pdu_shutdown(), smsc_list, smsc_list_lock, smsc_running, and smscconn_shutdown().

Referenced by bb_shutdown().

1269 {
1270  SMSCConn *conn;
1271  long i;
1272 
1273  if (!smsc_running)
1274  return -1;
1275 
1276  /* stop concat handling */
1278 
1279  /* Call shutdown for all SMSC Connections; they should
1280  * handle that they quit, by emptying queues and then dying off
1281  */
1283  for(i=0; i < gwlist_len(smsc_list); i++) {
1284  conn = gwlist_get(smsc_list, i);
1285  smscconn_shutdown(conn, 1);
1286  }
1288  if (router_thread >= 0)
1290 
1291  /* start avalanche by calling shutdown */
1292 
1293  /* XXX shouldn'w we be sure that all smsces have closed their
1294  * receive thingies? Is this guaranteed by setting bb_status
1295  * to shutdown before calling these?
1296  */
1298 
1299  /* shutdown low levele PDU things */
1301 
1302  return 0;
1303 }
static long router_thread
Definition: bb_smscconn.c:149
void smscconn_shutdown(SMSCConn *conn, int finish_sending)
Definition: smscconn.c:378
static RWLock smsc_list_lock
Definition: bb_smscconn.c:129
long gwlist_len(List *list)
Definition: list.c:166
void * gwlist_get(List *list, long pos)
Definition: list.c:292
int gw_rwlock_rdlock(RWLock *lock)
Definition: gw-rwlock.c:134
List * incoming_sms
Definition: bearerbox.c:84
int smpp_pdu_shutdown(void)
Definition: smpp_pdu.c:314
void gwlist_remove_producer(List *list)
Definition: list.c:401
int gw_rwlock_unlock(RWLock *lock)
Definition: gw-rwlock.c:155
void gwthread_wakeup(long thread)
static void concat_handling_shutdown(void)
Definition: bb_smscconn.c:2024
static volatile sig_atomic_t smsc_running
Definition: bb_smscconn.c:127
static List * smsc_list
Definition: bb_smscconn.c:128

◆ smsc2_start()

int smsc2_start ( Cfg config)

Definition at line 806 of file bb_smscconn.c.

References black_list_receiver, black_list_receiver_regex, black_list_receiver_url, black_list_sender, black_list_sender_regex, black_list_sender_url, cfg, cfg_get, cfg_get_bool(), cfg_get_integer(), cfg_get_multi_group(), cfg_get_single_group(), cfg_reloaded, concat_handling_init(), concatenated_mo_timeout, counter_create(), gw_rwlock_init_static(), gwlist_add_producer(), gwlist_append(), gwlist_create, gwlist_get(), gwlist_len(), gwlist_remove_producer(), gwthread_create, handle_concatenated_mo, incoming_sms, info(), numhash_create(), octstr_destroy(), octstr_get_cstr, octstr_imm(), panic, router_thread, smpp_pdu_init(), sms_resend_frequency, sms_resend_retry, sms_router(), smsc_groups, smsc_list, smsc_list_lock, smsc_running, smscconn_create(), smscconn_instances(), split_msg_counter, unified_prefix, warning(), white_black_list_lock, white_list_receiver, white_list_receiver_regex, white_list_receiver_url, white_list_sender, white_list_sender_regex, and white_list_sender_url.

Referenced by start_smsc().

807 {
808  CfgGroup *grp;
809  SMSCConn *conn;
810  Octstr *os;
811  int i, j, m;
812 
813  if (smsc_running) return -1;
814 
815  /* at start-up time there is no reloaded config */
816  cfg_reloaded = NULL;
817 
818  /* create split sms counter */
820 
821  /* create smsc list and rwlock for it */
824 
825  grp = cfg_get_single_group(cfg, octstr_imm("core"));
826  unified_prefix = cfg_get(grp, octstr_imm("unified-prefix"));
827 
831  if ((white_list_sender_url = cfg_get(grp, octstr_imm("white-list"))) != NULL) /* TODO deprecated, remove */
832  warning(0, "Option 'white-list' is deprecated! Please use 'white-list-sender' instead!");
833  else
834  white_list_sender_url = cfg_get(grp, octstr_imm("white-list-sender"));
835  if (white_list_sender_url != NULL) {
837  panic(0, "Could not get white-list at URL <%s>",
839  }
840  if ((os = cfg_get(grp, octstr_imm("white-list-regex"))) != NULL) /* TODO deprecated, remove */
841  warning(0, "Option 'white-list-regex' is deprecated! Please use 'white-list-sender-regex' instead!");
842  else
843  os = cfg_get(grp, octstr_imm("white-list-sender-regex"));
844  if (os != NULL) {
845  if ((white_list_sender_regex = gw_regex_comp(os, REG_EXTENDED)) == NULL)
846  panic(0, "Could not compile pattern '%s'", octstr_get_cstr(os));
847  octstr_destroy(os);
848  }
849 
850  if ((black_list_sender_url = cfg_get(grp, octstr_imm("black-list"))) != NULL) /* TODO deprecated, remove */
851  warning(0, "Option 'black-list' is deprecated! Please use 'black-list-sender' instead!");
852  else
853  black_list_sender_url = cfg_get(grp, octstr_imm("black-list-sender"));
854  if (black_list_sender_url != NULL) {
856  panic(0, "Could not get black-list at URL <%s>",
858  }
859  if ((os = cfg_get(grp, octstr_imm("black-list-regex"))) != NULL) /* TODO deprecated, remove */
860  warning(0, "Option 'black-list-regex' is deprecated! Please use 'black-list-sender-regex' instead!");
861  else
862  os = cfg_get(grp, octstr_imm("black-list-sender-regex"));
863  if (os != NULL) {
864  if ((black_list_sender_regex = gw_regex_comp(os, REG_EXTENDED)) == NULL)
865  panic(0, "Could not compile pattern '%s'", octstr_get_cstr(os));
866  octstr_destroy(os);
867  }
868 
871  white_list_receiver_url = cfg_get(grp, octstr_imm("white-list-receiver"));
872  if (white_list_receiver_url != NULL) {
874  panic(0, "Could not get white-list-receiver at URL <%s>",
876  }
877  if ((os = cfg_get(grp, octstr_imm("white-list-receiver-regex"))) != NULL) {
878  if ((white_list_receiver_regex = gw_regex_comp(os, REG_EXTENDED)) == NULL)
879  panic(0, "Could not compile pattern '%s'", octstr_get_cstr(os));
880  octstr_destroy(os);
881  }
882 
883  black_list_receiver_url = cfg_get(grp, octstr_imm("black-list-receiver"));
884  if (black_list_receiver_url != NULL) {
886  panic(0, "Could not get black-list-receiver at URL <%s>",
888  }
889  if ((os = cfg_get(grp, octstr_imm("black-list-receiver-regex"))) != NULL) {
890  if ((black_list_receiver_regex = gw_regex_comp(os, REG_EXTENDED)) == NULL)
891  panic(0, "Could not compile pattern '%s'", octstr_get_cstr(os));
892  octstr_destroy(os);
893  }
894 
896  octstr_imm("sms-resend-freq")) == -1 || sms_resend_frequency <= 0) {
898  }
899  info(0, "Set SMS resend frequency to %ld seconds.", sms_resend_frequency);
900 
901  if (cfg_get_integer(&sms_resend_retry, grp, octstr_imm("sms-resend-retry")) == -1) {
902  sms_resend_retry = -1;
903  info(0, "SMS resend retry set to unlimited.");
904  }
905  else
906  info(0, "SMS resend retry set to %ld.", sms_resend_retry);
907 
908  if (cfg_get_bool((int*)&handle_concatenated_mo, grp, octstr_imm("sms-combine-concatenated-mo")) == -1)
909  handle_concatenated_mo = 1; /* default is TRUE. */
910 
911  if (cfg_get_integer(&concatenated_mo_timeout, grp, octstr_imm("sms-combine-concatenated-mo-timeout")) == -1)
913 
916 
917  /* initialize low level PDUs */
918  if (smpp_pdu_init(cfg) == -1)
919  panic(0, "Connot start with PDU init failed.");
920 
923  for (i = 0; i < gwlist_len(smsc_groups) &&
924  (grp = gwlist_get(smsc_groups, i)) != NULL; i++) {
925  /* multiple instances for the same group? */
926  m = smscconn_instances(grp);
927  for (j = 0; j < m; j++) {
928  conn = smscconn_create(grp, 1);
929  if (conn == NULL)
930  panic(0, "Cannot start with SMSC connection failing");
931  gwlist_append(smsc_list, conn);
932  }
933  }
935 
936  if ((router_thread = gwthread_create(sms_router, NULL)) == -1)
937  panic(0, "Failed to start a new thread for SMS routing");
938 
940  smsc_running = 1;
941  return 0;
942 }
void info(int err, const char *fmt,...)
Definition: log.c:672
static Cfg * cfg_reloaded
Definition: bb_smscconn.c:130
static long concatenated_mo_timeout
Definition: bb_smscconn.c:164
static List * smsc_groups
Definition: bb_smscconn.c:131
static long router_thread
Definition: bb_smscconn.c:149
void gwlist_append(List *list, void *item)
Definition: list.c:179
static regex_t * white_list_sender_regex
Definition: bb_smscconn.c:144
static RWLock smsc_list_lock
Definition: bb_smscconn.c:129
long gwlist_len(List *list)
Definition: list.c:166
void * gwlist_get(List *list, long pos)
Definition: list.c:292
#define cfg_get(grp, varname)
Definition: cfg.h:86
static regex_t * black_list_receiver_regex
Definition: bb_smscconn.c:147
static long sms_resend_retry
Definition: bb_smscconn.c:153
static Cfg * cfg
Definition: opensmppbox.c:95
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
List * incoming_sms
Definition: bearerbox.c:84
static RWLock white_black_list_lock
Definition: bb_smscconn.c:134
unsigned int smscconn_instances(CfgGroup *grp)
Definition: smscconn.c:149
Numhash * numhash_create(const char *seek_url)
Definition: numhash.c:313
static Numhash * white_list_sender
Definition: bb_smscconn.c:140
static Octstr * black_list_receiver_url
Definition: bb_smscconn.c:137
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:283
Counter * counter_create(void)
Definition: counter.c:94
static Numhash * black_list_sender
Definition: bb_smscconn.c:139
void gwlist_remove_producer(List *list)
Definition: list.c:401
static void concat_handling_init(void)
Definition: bb_smscconn.c:2014
List * cfg_get_multi_group(Cfg *cfg, Octstr *name)
Definition: cfg.c:643
static void sms_router(void *arg)
Definition: bb_smscconn.c:651
Counter * split_msg_counter
Definition: bb_smscconn.c:159
void warning(int err, const char *fmt,...)
Definition: log.c:660
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
#define gwthread_create(func, arg)
Definition: gwthread.h:90
static regex_t * white_list_receiver_regex
Definition: bb_smscconn.c:146
static Octstr * white_list_sender_url
Definition: bb_smscconn.c:136
static Numhash * white_list_receiver
Definition: bb_smscconn.c:142
int cfg_get_bool(int *n, CfgGroup *grp, Octstr *varname)
Definition: cfg.c:757
Definition: octstr.c:118
static long sms_resend_frequency
Definition: bb_smscconn.c:152
int cfg_get_integer(long *n, CfgGroup *grp, Octstr *varname)
Definition: cfg.c:740
#define panic
Definition: log.h:87
Definition: cfg.c:73
int smpp_pdu_init(Cfg *cfg)
Definition: smpp_pdu.c:184
#define gwlist_create()
Definition: list.h:136
SMSCConn * smscconn_create(CfgGroup *grp, int start_as_stopped)
Definition: smscconn.c:162
void gw_rwlock_init_static(RWLock *lock)
Definition: gw-rwlock.c:96
static Octstr * unified_prefix
Definition: bb_smscconn.c:132
static Octstr * black_list_sender_url
Definition: bb_smscconn.c:135
static Octstr * white_list_receiver_url
Definition: bb_smscconn.c:138
CfgGroup * cfg_get_single_group(Cfg *cfg, Octstr *name)
Definition: cfg.c:637
void gwlist_add_producer(List *list)
Definition: list.c:383
static regex_t * black_list_sender_regex
Definition: bb_smscconn.c:145
static volatile sig_atomic_t smsc_running
Definition: bb_smscconn.c:127
static volatile sig_atomic_t handle_concatenated_mo
Definition: bb_smscconn.c:162
static Numhash * black_list_receiver
Definition: bb_smscconn.c:141
static List * smsc_list
Definition: bb_smscconn.c:128

◆ smsc2_status()

Octstr* smsc2_status ( int  status_type)

Definition at line 1354 of file bb_smscconn.c.

References bb_status_linebreak(), BBSTATUS_HTML, BBSTATUS_TEXT, BBSTATUS_WML, BBSTATUS_XML, gw_rwlock_rdlock(), gw_rwlock_unlock(), gwlist_get(), gwlist_len(), smscconn::incoming_dlr_load, smscconn::incoming_sms_load, info(), load_get(), octstr_append(), octstr_append_cstr(), octstr_create, octstr_format(), octstr_format_append(), octstr_imm(), smscconn::outgoing_dlr_load, smscconn::outgoing_sms_load, smsc_list, smsc_list_lock, smsc_running, SMSCCONN_ACTIVE, SMSCCONN_ACTIVE_RECV, smscconn_admin_id(), SMSCCONN_CONNECTING, SMSCCONN_DEAD, SMSCCONN_DISCONNECTED, smscconn_id(), smscconn_info(), smscconn_name(), and SMSCCONN_RECONNECTING.

Referenced by bb_print_status().

1355 {
1356  Octstr *tmp;
1357  char tmp3[64];
1358  char *lb;
1359  long i;
1360  int para = 0;
1361  SMSCConn *conn;
1362  StatusInfo info;
1363  const Octstr *conn_id = NULL;
1364  const Octstr *conn_admin_id = NULL;
1365  const Octstr *conn_name = NULL;
1366  float incoming_sms_load_0, incoming_sms_load_1, incoming_sms_load_2;
1367  float outgoing_sms_load_0, outgoing_sms_load_1, outgoing_sms_load_2;
1368  float incoming_dlr_load_0, incoming_dlr_load_1, incoming_dlr_load_2;
1369  float outgoing_dlr_load_0, outgoing_dlr_load_1, outgoing_dlr_load_2;
1370 
1371  if ((lb = bb_status_linebreak(status_type)) == NULL)
1372  return octstr_create("Un-supported format");
1373 
1374  if (status_type == BBSTATUS_HTML || status_type == BBSTATUS_WML)
1375  para = 1;
1376 
1377  if (!smsc_running) {
1378  if (status_type == BBSTATUS_XML)
1379  return octstr_create ("<smscs>\n\t<count>0</count>\n</smscs>");
1380  else
1381  return octstr_format("%sNo SMSC connections%s\n\n", para ? "<p>" : "",
1382  para ? "</p>" : "");
1383  }
1384 
1385  if (status_type != BBSTATUS_XML)
1386  tmp = octstr_format("%sSMSC connections:%s", para ? "<p>" : "", lb);
1387  else
1388  tmp = octstr_format("<smscs><count>%d</count>\n\t", gwlist_len(smsc_list));
1389 
1391  for (i = 0; i < gwlist_len(smsc_list); i++) {
1392  incoming_sms_load_0 = incoming_sms_load_1 = incoming_sms_load_2 = 0.0;
1393  outgoing_sms_load_0 = outgoing_sms_load_1 = outgoing_sms_load_2 = 0.0;
1394  incoming_dlr_load_0 = incoming_dlr_load_1 = incoming_dlr_load_2 = 0.0;
1395  outgoing_dlr_load_0 = outgoing_dlr_load_1 = outgoing_dlr_load_2 = 0.0;
1396  conn = gwlist_get(smsc_list, i);
1397 
1398  if ((smscconn_info(conn, &info) == -1)) {
1399  /*
1400  * we do not delete SMSCs from the list
1401  * this way we can show in the status which links are dead
1402  */
1403  continue;
1404  }
1405 
1406  conn_id = conn ? smscconn_id(conn) : octstr_imm("unknown");
1407  conn_id = conn_id ? conn_id : octstr_imm("unknown");
1408  conn_admin_id = conn ? smscconn_admin_id(conn) : octstr_imm("unknown");
1409  conn_admin_id = conn_admin_id ? conn_admin_id : octstr_imm("unknown");
1410  conn_name = conn ? smscconn_name(conn) : octstr_imm("unknown");
1411 
1412  if (status_type == BBSTATUS_HTML) {
1413  octstr_append_cstr(tmp, "&nbsp;&nbsp;&nbsp;&nbsp;<b>");
1414  octstr_append(tmp, conn_id);
1415  octstr_append_cstr(tmp, "</b>[");
1416  octstr_append(tmp, conn_admin_id);
1417  octstr_append_cstr(tmp, "]&nbsp;&nbsp;&nbsp;&nbsp;");
1418  } else if (status_type == BBSTATUS_TEXT) {
1419  octstr_append_cstr(tmp, " ");
1420  octstr_append(tmp, conn_id);
1421  octstr_append_cstr(tmp, "[");
1422  octstr_append(tmp, conn_admin_id);
1423  octstr_append_cstr(tmp, "] ");
1424  }
1425  if (status_type == BBSTATUS_XML) {
1426  octstr_append_cstr(tmp, "<smsc>\n\t\t<name>");
1427  octstr_append(tmp, conn_name);
1428  octstr_append_cstr(tmp, "</name>\n\t\t<admin-id>");
1429  octstr_append(tmp, conn_admin_id);
1430  octstr_append_cstr(tmp, "</admin-id>\n\t\t<id>");
1431  octstr_append(tmp, conn_id);
1432  octstr_append_cstr(tmp, "</id>\n\t\t");
1433  } else
1434  octstr_append(tmp, conn_name);
1435 
1436  switch (info.status) {
1437  case SMSCCONN_ACTIVE:
1438  case SMSCCONN_ACTIVE_RECV:
1439  sprintf(tmp3, "online %lds", info.online);
1440  incoming_sms_load_0 = load_get(conn->incoming_sms_load,0);
1441  incoming_sms_load_1 = load_get(conn->incoming_sms_load,1);
1442  incoming_sms_load_2 = load_get(conn->incoming_sms_load,2);
1443  outgoing_sms_load_0 = load_get(conn->outgoing_sms_load,0);
1444  outgoing_sms_load_1 = load_get(conn->outgoing_sms_load,1);
1445  outgoing_sms_load_2 = load_get(conn->outgoing_sms_load,2);
1446  incoming_dlr_load_0 = load_get(conn->incoming_dlr_load,0);
1447  incoming_dlr_load_1 = load_get(conn->incoming_dlr_load,1);
1448  incoming_dlr_load_2 = load_get(conn->incoming_dlr_load,2);
1449  outgoing_dlr_load_0 = load_get(conn->outgoing_dlr_load,0);
1450  outgoing_dlr_load_1 = load_get(conn->outgoing_dlr_load,1);
1451  outgoing_dlr_load_2 = load_get(conn->outgoing_dlr_load,2);
1452  break;
1453  case SMSCCONN_DISCONNECTED:
1454  sprintf(tmp3, "disconnected");
1455  break;
1456  case SMSCCONN_CONNECTING:
1457  sprintf(tmp3, "connecting");
1458  break;
1459  case SMSCCONN_RECONNECTING:
1460  sprintf(tmp3, "re-connecting");
1461  break;
1462  case SMSCCONN_DEAD:
1463  sprintf(tmp3, "dead");
1464  break;
1465  default:
1466  sprintf(tmp3, "unknown");
1467  break;
1468  }
1469 
1470  if (status_type == BBSTATUS_XML)
1471  octstr_format_append(tmp, "<status>%s</status>\n"
1472  "\t\t<failed>%ld</failed>\n"
1473  "\t\t<queued>%ld</queued>\n"
1474  "\t\t<sms>\n"
1475  "\t\t\t<received>%ld</received>\n"
1476  "\t\t\t<sent>%ld</sent>\n"
1477  "\t\t\t<inbound>%.2f,%.2f,%.2f</inbound>\n"
1478  "\t\t\t<outbound>%.2f,%.2f,%.2f</outbound>\n"
1479  "\t\t</sms>\n\t\t<dlr>\n"
1480  "\t\t\t<received>%ld</received>\n"
1481  "\t\t\t<sent>%ld</sent>\n"
1482  "\t\t\t<inbound>%.2f,%.2f,%.2f</inbound>\n"
1483  "\t\t\t<outbound>%.2f,%.2f,%.2f</outbound>\n"
1484  "\t\t</dlr>\n"
1485  "\t</smsc>\n", tmp3,
1486  info.failed, info.queued, info.received, info.sent,
1487  incoming_sms_load_0, incoming_sms_load_1, incoming_sms_load_2,
1488  outgoing_sms_load_0, outgoing_sms_load_1, outgoing_sms_load_2,
1489  info.received_dlr, info.sent_dlr,
1490  incoming_dlr_load_0, incoming_dlr_load_1, incoming_dlr_load_2,
1491  outgoing_dlr_load_0, outgoing_dlr_load_1, outgoing_dlr_load_2);
1492  else
1493  octstr_format_append(tmp, " (%s, rcvd: sms %ld (%.2f,%.2f,%.2f) / dlr %ld (%.2f,%.2f,%.2f), "
1494  "sent: sms %ld (%.2f,%.2f,%.2f) / dlr %ld (%.2f,%.2f,%.2f), failed %ld, "
1495  "queued %ld msgs)%s",
1496  tmp3,
1497  info.received,
1498  incoming_sms_load_0, incoming_sms_load_1, incoming_sms_load_2,
1499  info.received_dlr,
1500  incoming_dlr_load_0, incoming_dlr_load_1, incoming_dlr_load_2,
1501  info.sent,
1502  outgoing_sms_load_0, outgoing_sms_load_1, outgoing_sms_load_2,
1503  info.sent_dlr,
1504  outgoing_dlr_load_0, outgoing_dlr_load_1, outgoing_dlr_load_2,
1505  info.failed,
1506  info.queued,
1507  lb);
1508  }
1509 
1511 
1512  if (para)
1513  octstr_append_cstr(tmp, "</p>");
1514  if (status_type == BBSTATUS_XML)
1515  octstr_append_cstr(tmp, "</smscs>\n");
1516  else
1517  octstr_append_cstr(tmp, "\n\n");
1518  return tmp;
1519 }
Load * incoming_sms_load
Definition: smscconn_p.h:215
void info(int err, const char *fmt,...)
Definition: log.c:672
char * bb_status_linebreak(int status_type)
Definition: bearerbox.c:1109
void octstr_append(Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:1504
static RWLock smsc_list_lock
Definition: bb_smscconn.c:129
long gwlist_len(List *list)
Definition: list.c:166
void * gwlist_get(List *list, long pos)
Definition: list.c:292
const Octstr * smscconn_name(SMSCConn *conn)
Definition: smscconn.c:493
int gw_rwlock_rdlock(RWLock *lock)
Definition: gw-rwlock.c:134
void octstr_append_cstr(Octstr *ostr, const char *cstr)
Definition: octstr.c:1511
double load_get(Load *load, int pos)
Definition: load.c:191
Load * outgoing_sms_load
Definition: smscconn_p.h:214
const Octstr * smscconn_admin_id(SMSCConn *conn)
Definition: smscconn.c:507
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:283
const Octstr * smscconn_id(SMSCConn *conn)
Definition: smscconn.c:500
int gw_rwlock_unlock(RWLock *lock)
Definition: gw-rwlock.c:155
Octstr * octstr_format(const char *fmt,...)
Definition: octstr.c:2464
#define octstr_create(cstr)
Definition: octstr.h:125
Definition: octstr.c:118
Load * outgoing_dlr_load
Definition: smscconn_p.h:217
void octstr_format_append(Octstr *os, const char *fmt,...)
Definition: octstr.c:2507
Load * incoming_dlr_load
Definition: smscconn_p.h:216
int smscconn_info(SMSCConn *conn, StatusInfo *infotable)
Definition: smscconn.c:673
static volatile sig_atomic_t smsc_running
Definition: bb_smscconn.c:127
static List * smsc_list
Definition: bb_smscconn.c:128

◆ smsc2_stop_smsc()

int smsc2_stop_smsc ( Octstr id)

Definition at line 968 of file bb_smscconn.c.

References error(), gw_rwlock_rdlock(), gw_rwlock_unlock(), gwlist_get(), info(), octstr_get_cstr, smsc2_find(), smsc_list, smsc_list_lock, smsc_running, SMSCCONN_DEAD, smscconn_shutdown(), and smscconn_status().

Referenced by bb_stop_smsc().

969 {
970  SMSCConn *conn;
971  long i = -1;
972  int success = 0;
973 
974  if (!smsc_running)
975  return -1;
976 
978  /* find the specific smsc via id */
979  while((i = smsc2_find(id, ++i)) != -1) {
980  conn = gwlist_get(smsc_list, i);
981  if (conn != NULL && smscconn_status(conn) == SMSCCONN_DEAD) {
982  info(0, "HTTP: Could not shutdown already dead smsc-id `%s'",
983  octstr_get_cstr(id));
984  } else {
985  info(0,"HTTP: Shutting down smsc-id `%s'", octstr_get_cstr(id));
986  smscconn_shutdown(conn, 1); /* shutdown the smsc */
987  success = 1;
988  }
989  }
991  if (success == 0) {
992  error(0, "SMSC %s not found", octstr_get_cstr(id));
993  return -1;
994  }
995  return 0;
996 }
void error(int err, const char *fmt,...)
Definition: log.c:648
void info(int err, const char *fmt,...)
Definition: log.c:672
void smscconn_shutdown(SMSCConn *conn, int finish_sending)
Definition: smscconn.c:378
static RWLock smsc_list_lock
Definition: bb_smscconn.c:129
void * gwlist_get(List *list, long pos)
Definition: list.c:292
int gw_rwlock_rdlock(RWLock *lock)
Definition: gw-rwlock.c:134
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
int smscconn_status(SMSCConn *conn)
Definition: smscconn.c:665
int gw_rwlock_unlock(RWLock *lock)
Definition: gw-rwlock.c:155
static volatile sig_atomic_t smsc_running
Definition: bb_smscconn.c:127
static List * smsc_list
Definition: bb_smscconn.c:128
static long smsc2_find(Octstr *id, long start)
Definition: bb_smscconn.c:948

◆ smsc2_suspend()

void smsc2_suspend ( void  )

Definition at line 1251 of file bb_smscconn.c.

References gw_rwlock_rdlock(), gw_rwlock_unlock(), gwlist_get(), gwlist_len(), smsc_list, smsc_list_lock, smsc_running, and smscconn_stop().

Referenced by bb_isolate(), and bb_suspend().

1252 {
1253  SMSCConn *conn;
1254  long i;
1255 
1256  if (!smsc_running)
1257  return;
1258 
1260  for (i = 0; i < gwlist_len(smsc_list); i++) {
1261  conn = gwlist_get(smsc_list, i);
1262  smscconn_stop(conn);
1263  }
1265 }
static RWLock smsc_list_lock
Definition: bb_smscconn.c:129
long gwlist_len(List *list)
Definition: list.c:166
void * gwlist_get(List *list, long pos)
Definition: list.c:292
int gw_rwlock_rdlock(RWLock *lock)
Definition: gw-rwlock.c:134
int smscconn_stop(SMSCConn *conn)
Definition: smscconn.c:457
int gw_rwlock_unlock(RWLock *lock)
Definition: gw-rwlock.c:155
static volatile sig_atomic_t smsc_running
Definition: bb_smscconn.c:127
static List * smsc_list
Definition: bb_smscconn.c:128

◆ udp_addwdp()

int udp_addwdp ( Msg msg)

Definition at line 385 of file bb_udp.c.

References _udpc::addr, gwlist_get(), gwlist_len(), gwlist_lock(), gwlist_produce(), gwlist_unlock(), msg, octstr_compare(), octstr_destroy(), _udpc::outgoing_list, udp_get_ip(), udp_get_port(), udp_running, and udpc_list.

Referenced by wdp_router().

386 {
387  int i;
388  Udpc *udpc, *def_udpc;
389  Octstr *ip;
390 
391  def_udpc = NULL;
392  if (!udp_running) return -1;
393  assert(msg != NULL);
394  assert(msg_type(msg) == wdp_datagram);
395 
397  /* select in which list to add this */
398  for (i=0; i < gwlist_len(udpc_list); i++) {
399  udpc = gwlist_get(udpc_list, i);
400 
401  if (msg->wdp_datagram.source_port == udp_get_port(udpc->addr)) {
402  def_udpc = udpc;
403  ip = udp_get_ip(udpc->addr);
404  if (octstr_compare(msg->wdp_datagram.source_address, ip) == 0) {
405  octstr_destroy(ip);
408  return 0;
409  }
410  octstr_destroy(ip);
411  }
412  }
413 
414  if (NULL != def_udpc) {
415  gwlist_produce(def_udpc->outgoing_list, msg);
417  return 0;
418  }
419 
421  return -1;
422 }
void gwlist_produce(List *list, void *item)
Definition: list.c:411
long gwlist_len(List *list)
Definition: list.c:166
int udp_get_port(Octstr *addr)
Definition: socket.c:547
void * gwlist_get(List *list, long pos)
Definition: list.c:292
msg_type
Definition: msg.h:73
static List * udpc_list
Definition: bb_udp.c:97
void gwlist_unlock(List *list)
Definition: list.c:354
Definition: bb_udp.c:100
List * outgoing_list
Definition: bb_udp.c:103
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
Octstr * addr
Definition: bb_udp.c:102
void gwlist_lock(List *list)
Definition: list.c:347
Definition: octstr.c:118
static volatile sig_atomic_t udp_running
Definition: bb_udp.c:96
static XMLRPCDocument * msg
Definition: test_xmlrpc.c:86
Octstr * udp_get_ip(Octstr *addr)
Definition: socket.c:557
int octstr_compare(const Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:871

◆ udp_die()

int udp_die ( void  )

Definition at line 434 of file bb_udp.c.

References allow_ip, debug(), deny_ip, gwlist_consume(), gwlist_destroy(), gwlist_remove_producer(), octstr_destroy(), _udpc::outgoing_list, udp_running, and udpc_list.

Referenced by wdp_router().

435 {
436  Udpc *udpc;
437 
438  if (!udp_running) return -1;
439 
440  /*
441  * remove producers from all outgoing lists.
442  */
443  debug("bb.udp", 0, "udp_die: removing producers from udp-lists");
444 
445  while((udpc = gwlist_consume(udpc_list)) != NULL) {
447  }
448  gwlist_destroy(udpc_list, NULL);
449  udp_running = 0;
450 
453  allow_ip = NULL;
454  deny_ip = NULL;
455 
456  return 0;
457 }
static List * udpc_list
Definition: bb_udp.c:97
Definition: bb_udp.c:100
void gwlist_remove_producer(List *list)
Definition: list.c:401
List * outgoing_list
Definition: bb_udp.c:103
static Octstr * deny_ip
Definition: bb_udp.c:112
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
static Octstr * allow_ip
Definition: bb_udp.c:111
void * gwlist_consume(List *list)
Definition: list.c:427
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:726
static volatile sig_atomic_t udp_running
Definition: bb_udp.c:96
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)
Definition: list.c:145

◆ udp_outgoing_queue()

int udp_outgoing_queue ( void  )

Definition at line 460 of file bb_udp.c.

References gwlist_get(), gwlist_len(), gwlist_lock(), gwlist_unlock(), _udpc::outgoing_list, udp_running, and udpc_list.

Referenced by bb_print_status().

461 {
462  int i, q = 0;
463  Udpc *udpc;
464 
465  if (!udp_running || udpc_list == NULL)
466  return 0;
467 
469  for (i=0; i < gwlist_len(udpc_list); i++) {
470  udpc = gwlist_get(udpc_list, i);
471  q += gwlist_len(udpc->outgoing_list);
472  }
474  return q;
475 }
long gwlist_len(List *list)
Definition: list.c:166
void * gwlist_get(List *list, long pos)
Definition: list.c:292
static List * udpc_list
Definition: bb_udp.c:97
void gwlist_unlock(List *list)
Definition: list.c:354
Definition: bb_udp.c:100
List * outgoing_list
Definition: bb_udp.c:103
void gwlist_lock(List *list)
Definition: list.c:347
static volatile sig_atomic_t udp_running
Definition: bb_udp.c:96

◆ udp_shutdown()

int udp_shutdown ( void  )

Definition at line 424 of file bb_udp.c.

References debug(), gwlist_remove_producer(), incoming_wdp, and udp_running.

Referenced by bb_shutdown().

425 {
426  if (!udp_running) return -1;
427 
428  debug("bb.thread", 0, "udp_shutdown: Starting avalanche");
430  return 0;
431 }
List * incoming_wdp
Definition: bearerbox.c:87
void gwlist_remove_producer(List *list)
Definition: list.c:401
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:726
static volatile sig_atomic_t udp_running
Definition: bb_udp.c:96

◆ udp_start()

int udp_start ( Cfg config)

Definition at line 323 of file bb_udp.c.

References add_service(), allow_ip, cfg, cfg_get, cfg_get_single_group(), debug(), deny_ip, error(), gwlist_add_producer(), gwlist_create, gwlist_destroy(), gwlist_extract_first(), gwlist_len(), incoming_wdp, info(), octstr_destroy(), octstr_get_cstr, octstr_imm(), octstr_split(), udp_running, and udpc_list.

Referenced by start_udp().

324 {
325  CfgGroup *grp;
326  Octstr *iface;
327  List *ifs;
328  int allow_wtls;
329 
330  if (udp_running) return -1;
331 
332  debug("bb.udp", 0, "starting UDP sender/receiver module");
333 
334  grp = cfg_get_single_group(cfg, octstr_imm("core"));
335  iface = cfg_get(grp, octstr_imm("wdp-interface-name"));
336  if (iface == NULL) {
337  error(0, "Missing wdp-interface-name variable, cannot start UDP");
338  return -1;
339  }
340 
341  allow_ip = cfg_get(grp, octstr_imm("udp-allow-ip"));
342  deny_ip = cfg_get(grp, octstr_imm("udp-deny-ip"));
343 
344  /* we'll activate WTLS as soon as we have a 'wtls' config group */
345  grp = cfg_get_single_group(cfg, octstr_imm("wtls"));
346  allow_wtls = grp != NULL ? 1 : 0;
347 
348  udpc_list = gwlist_create(); /* have a list of running systems */
349 
350  ifs = octstr_split(iface, octstr_imm(";"));
351  octstr_destroy(iface);
352  while (gwlist_len(ifs) > 0) {
353  iface = gwlist_extract_first(ifs);
354  info(0, "Adding interface %s", octstr_get_cstr(iface));
355  add_service(9200, octstr_get_cstr(iface)); /* wsp */
356  add_service(9201, octstr_get_cstr(iface)); /* wsp/wtp */
357 
358 #ifdef HAVE_WTLS_OPENSSL
359  if (allow_wtls) {
360  add_service(9202, octstr_get_cstr(iface)); /* wsp/wtls */
361  add_service(9203, octstr_get_cstr(iface)); /* wsp/wtp/wtls */
362  }
363 #else
364  if (allow_wtls)
365  error(0, "These is a 'wtls' group in configuration, but no WTLS support compiled in!");
366 #endif
367  /* add_service(9204, octstr_get_cstr(interface_name)); * vcard */
368  /* add_service(9205, octstr_get_cstr(interface_name)); * vcal */
369  /* add_service(9206, octstr_get_cstr(interface_name)); * vcard/wtls */
370  /* add_service(9207, octstr_get_cstr(interface_name)); * vcal/wtls */
371  octstr_destroy(iface);
372  }
373  gwlist_destroy(ifs, NULL);
374 
376  udp_running = 1;
377  return 0;
378 }
void error(int err, const char *fmt,...)
Definition: log.c:648
void info(int err, const char *fmt,...)
Definition: log.c:672
long gwlist_len(List *list)
Definition: list.c:166
List * incoming_wdp
Definition: bearerbox.c:87
#define cfg_get(grp, varname)
Definition: cfg.h:86
static List * udpc_list
Definition: bb_udp.c:97
static Cfg * cfg
Definition: opensmppbox.c:95
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:283
void * gwlist_extract_first(List *list)
Definition: list.c:305
static Octstr * deny_ip
Definition: bb_udp.c:112
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
static int add_service(int port, char *interface_name)
Definition: bb_udp.c:292
static Octstr * allow_ip
Definition: bb_udp.c:111
Definition: octstr.c:118
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:726
Definition: cfg.c:73
static volatile sig_atomic_t udp_running
Definition: bb_udp.c:96
#define gwlist_create()
Definition: list.h:136
CfgGroup * cfg_get_single_group(Cfg *cfg, Octstr *name)
Definition: cfg.c:637
void gwlist_add_producer(List *list)
Definition: list.c:383
List * octstr_split(const Octstr *os, const Octstr *sep)
Definition: octstr.c:1640
Definition: list.c:102
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)
Definition: list.c:145

◆ wapbox_start()

int wapbox_start ( Cfg config)

Definition at line 1322 of file bb_boxc.c.

References box_allow_ip, box_deny_ip, boxid, cfg, cfg_get, cfg_get_bool(), cfg_get_integer(), cfg_get_single_group(), counter_create(), debug(), error(), gwlist_add_producer(), gwlist_create, gwthread_create, info(), octstr_create, octstr_imm(), outgoing_wdp, panic, wapbox_list, wapbox_port, wapbox_port_ssl, wapbox_running, wapboxc_run(), and wdp_to_wapboxes().

Referenced by start_wap().

1323 {
1324  CfgGroup *grp;
1325 
1326  if (wapbox_running) return -1;
1327 
1328  debug("bb", 0, "starting wapbox connection module");
1329 
1330  grp = cfg_get_single_group(cfg, octstr_imm("core"));
1331 
1332  if (cfg_get_integer(&wapbox_port, grp, octstr_imm("wapbox-port")) == -1) {
1333  error(0, "Missing wapbox-port variable, cannot start WAP");
1334  return -1;
1335  }
1336 #ifdef HAVE_LIBSSL
1337  cfg_get_bool(&wapbox_port_ssl, grp, octstr_imm("wapbox-port-ssl"));
1338 #endif /* HAVE_LIBSSL */
1339 
1340  if (box_allow_ip == NULL) {
1341  box_allow_ip = cfg_get(grp, octstr_imm("box-allow-ip"));
1342  if (box_allow_ip == NULL)
1344  }
1345  if (box_deny_ip == NULL) {
1346  box_deny_ip = cfg_get(grp, octstr_imm("box-deny-ip"));
1347  if (box_deny_ip == NULL)
1348  box_deny_ip = octstr_create("");
1349  }
1350  if (box_allow_ip != NULL && box_deny_ip == NULL)
1351  info(0, "Box connection allowed IPs defined without any denied...");
1352 
1353  wapbox_list = gwlist_create(); /* have a list of connections */
1355  if (!boxid)
1356  boxid = counter_create();
1357 
1358  if (gwthread_create(wdp_to_wapboxes, NULL) == -1)
1359  panic(0, "Failed to start a new thread for wapbox routing");
1360 
1362  panic(0, "Failed to start a new thread for wapbox connections");
1363 
1364  wapbox_running = 1;
1365  return 0;
1366 }
void error(int err, const char *fmt,...)
Definition: log.c:648
void info(int err, const char *fmt,...)
Definition: log.c:672
List * outgoing_wdp
Definition: bearerbox.c:88
static int wapbox_port_ssl
Definition: bb_boxc.c:119
#define cfg_get(grp, varname)
Definition: cfg.h:86
static Cfg * cfg
Definition: opensmppbox.c:95
static Octstr * box_deny_ip
Definition: bb_boxc.c:125
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:283
Counter * counter_create(void)
Definition: counter.c:94
static void wapboxc_run(void *arg)
Definition: bb_boxc.c:1074
#define gwthread_create(func, arg)
Definition: gwthread.h:90
#define octstr_create(cstr)
Definition: octstr.h:125
static Counter * boxid
Definition: bb_boxc.c:128
int cfg_get_bool(int *n, CfgGroup *grp, Octstr *varname)
Definition: cfg.c:757
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:726
int cfg_get_integer(long *n, CfgGroup *grp, Octstr *varname)
Definition: cfg.c:740
#define panic
Definition: log.h:87
Definition: cfg.c:73
static Octstr * box_allow_ip
Definition: bb_boxc.c:124
static void wdp_to_wapboxes(void *arg)
Definition: bb_boxc.c:923
#define gwlist_create()
Definition: list.h:136
static List * wapbox_list
Definition: bb_boxc.c:105
CfgGroup * cfg_get_single_group(Cfg *cfg, Octstr *name)
Definition: cfg.c:637
void gwlist_add_producer(List *list)
Definition: list.c:383
static volatile sig_atomic_t wapbox_running
Definition: bb_boxc.c:104
static long wapbox_port
Definition: bb_boxc.c:118
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.