Kannel: Open Source WAP and SMS gateway  svn-r5335
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:552
#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:559
#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:1530
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:1316
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:1259
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:1510
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:1386
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:1362
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:1174

◆ bb_reload_smsc_groups()

int bb_reload_smsc_groups ( void  )

Definition at line 627 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().

628 {
629  debug("bb.sms", 0, "Reloading smsc groups list from config resource");
632  if (cfg_read(cfg_reloaded) == -1) {
633  warning(0, "Error opening configuration file %s", octstr_get_cstr(cfg_filename));
634  return -1;
635  }
638 
639  return 0;
640 }
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:645
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:1234
#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:1276
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:1259
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 1527 of file bb_boxc.c.

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

Referenced by main().

1528 {
1531  box_allow_ip = NULL;
1532  box_deny_ip = NULL;
1534  boxid = NULL;
1536  smsbox_interface = NULL;
1537 }
void counter_destroy(Counter *counter)
Definition: counter.c:110
static Octstr * box_deny_ip
Definition: bb_boxc.c:126
static Octstr * smsbox_interface
Definition: bb_boxc.c:118
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
static Counter * boxid
Definition: bb_boxc.c:129
static Octstr * box_allow_ip
Definition: bb_boxc.c:125

◆ boxc_incoming_wdp_queue()

int boxc_incoming_wdp_queue ( void  )

Definition at line 1510 of file bb_boxc.c.

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

Referenced by bb_print_status().

1511 {
1512  int i, q = 0;
1513  Boxc *boxc;
1514 
1515  if (wapbox_list) {
1517  for(i=0; i < gwlist_len(wapbox_list); i++) {
1518  boxc = gwlist_get(wapbox_list, i);
1519  q += gwlist_len(boxc->incoming);
1520  }
1522  }
1523  return q;
1524 }
List * incoming
Definition: opensmppbox.c:154
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 1386 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().

1387 {
1388  Octstr *tmp;
1389  char *lb, *ws;
1390  int i, boxes, para = 0;
1391  time_t orig, t;
1392  Boxc *bi;
1393 
1394  orig = time(NULL);
1395 
1396  /*
1397  * XXX: this will cause segmentation fault if this is called
1398  * between 'destroy_list and setting list to NULL calls.
1399  * Ok, this has to be fixed, but now I am too tired.
1400  */
1401 
1402  if ((lb = bb_status_linebreak(status_type))==NULL)
1403  return octstr_create("Un-supported format");
1404 
1405  if (status_type == BBSTATUS_HTML)
1406  ws = "&nbsp;&nbsp;&nbsp;&nbsp;";
1407  else if (status_type == BBSTATUS_TEXT)
1408  ws = " ";
1409  else
1410  ws = "";
1411 
1412  if (status_type == BBSTATUS_HTML || status_type == BBSTATUS_WML)
1413  para = 1;
1414 
1415  if (status_type == BBSTATUS_XML) {
1416  tmp = octstr_create ("");
1417  octstr_append_cstr(tmp, "<boxes>\n\t");
1418  }
1419  else
1420  tmp = octstr_format("%sBox connections:%s", para ? "<p>" : "", lb);
1421  boxes = 0;
1422 
1423  if (wapbox_list) {
1425  for(i=0; i < gwlist_len(wapbox_list); i++) {
1426  bi = gwlist_get(wapbox_list, i);
1427  if (bi->alive == 0)
1428  continue;
1429  t = orig - bi->connect_time;
1430  if (status_type == BBSTATUS_XML)
1432  "<box>\n\t\t<type>wapbox</type>\n\t\t<IP>%s</IP>\n"
1433  "\t\t<status>on-line %ldd %ldh %ldm %lds</status>\n"
1434  "\t\t<ssl>%s</ssl>\n\t</box>\n",
1436  t/3600/24, t/3600%24, t/60%60, t%60,
1437 #ifdef HAVE_LIBSSL
1438  conn_get_ssl(bi->conn) != NULL ? "yes" : "no"
1439 #else
1440  "not installed"
1441 #endif
1442  );
1443  else
1445  "%swapbox, IP %s (on-line %ldd %ldh %ldm %lds) %s %s",
1446  ws, octstr_get_cstr(bi->client_ip),
1447  t/3600/24, t/3600%24, t/60%60, t%60,
1448 #ifdef HAVE_LIBSSL
1449  conn_get_ssl(bi->conn) != NULL ? "using SSL" : "",
1450 #else
1451  "",
1452 #endif
1453  lb);
1454  boxes++;
1455  }
1457  }
1458  if (smsbox_list) {
1460  for(i=0; i < gwlist_len(smsbox_list); i++) {
1461  bi = gwlist_get(smsbox_list, i);
1462  if (bi->alive == 0)
1463  continue;
1464  t = orig - bi->connect_time;
1465  if (status_type == BBSTATUS_XML)
1466  octstr_format_append(tmp, "<box>\n\t\t<type>smsbox</type>\n"
1467  "\t\t<id>%s</id>\n\t\t<IP>%s</IP>\n"
1468  "\t\t<queue>%ld</queue>\n"
1469  "\t\t<status>on-line %ldd %ldh %ldm %lds</status>\n"
1470  "\t\t<ssl>%s</ssl>\n\t</box>",
1471  (bi->boxc_id ? octstr_get_cstr(bi->boxc_id) : ""),
1473  gwlist_len(bi->incoming) + dict_key_count(bi->sent),
1474  t/3600/24, t/3600%24, t/60%60, t%60,
1475 #ifdef HAVE_LIBSSL
1476  conn_get_ssl(bi->conn) != NULL ? "yes" : "no"
1477 #else
1478  "not installed"
1479 #endif
1480  );
1481  else
1482  octstr_format_append(tmp, "%ssmsbox:%s, IP %s (%ld queued), (on-line %ldd %ldh %ldm %lds) %s %s",
1483  ws, (bi->boxc_id ? octstr_get_cstr(bi->boxc_id) : "(none)"),
1485  t/3600/24, t/3600%24, t/60%60, t%60,
1486 #ifdef HAVE_LIBSSL
1487  conn_get_ssl(bi->conn) != NULL ? "using SSL" : "",
1488 #else
1489  "",
1490 #endif
1491  lb);
1492  boxes++;
1493  }
1495  }
1496  if (boxes == 0 && status_type != BBSTATUS_XML) {
1497  octstr_destroy(tmp);
1498  tmp = octstr_format("%sNo boxes connected", para ? "<p>" : "");
1499  }
1500  if (para)
1501  octstr_append_cstr(tmp, "</p>");
1502  if (status_type == BBSTATUS_XML)
1503  octstr_append_cstr(tmp, "</boxes>\n");
1504  else
1505  octstr_append_cstr(tmp, "\n\n");
1506  return tmp;
1507 }
Connection * conn
Definition: bb_boxc.c:136
List * incoming
Definition: opensmppbox.c:154
char * bb_status_linebreak(int status_type)
Definition: bearerbox.c:1109
Octstr * client_ip
Definition: opensmppbox.c:153
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:159
void gwlist_unlock(List *list)
Definition: list.c:354
Octstr * boxc_id
Definition: opensmppbox.c:160
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:151
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:157

◆ httpadmin_start()

int httpadmin_start ( Cfg config)

Definition at line 557 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().

558 {
559  CfgGroup *grp;
560  int ssl = 0;
561 #ifdef HAVE_LIBSSL
562  Octstr *ssl_server_cert_file;
563  Octstr *ssl_server_key_file;
564 #endif /* HAVE_LIBSSL */
565 
566  if (httpadmin_running) return -1;
567 
568 
569  grp = cfg_get_single_group(cfg, octstr_imm("core"));
570  if (cfg_get_integer(&ha_port, grp, octstr_imm("admin-port")) == -1)
571  panic(0, "Missing admin-port variable, cannot start HTTP admin");
572 
573  ha_interface = cfg_get(grp, octstr_imm("admin-interface"));
574  ha_password = cfg_get(grp, octstr_imm("admin-password"));
575  if (ha_password == NULL)
576  panic(0, "You MUST set HTTP admin-password");
577 
578  ha_status_pw = cfg_get(grp, octstr_imm("status-password"));
579 
580  ha_allow_ip = cfg_get(grp, octstr_imm("admin-allow-ip"));
581  ha_deny_ip = cfg_get(grp, octstr_imm("admin-deny-ip"));
582 
583 #ifdef HAVE_LIBSSL
584  cfg_get_bool(&ssl, grp, octstr_imm("admin-port-ssl"));
585 
586  /*
587  * check if SSL is desired for HTTP servers and then
588  * load SSL client and SSL server public certificates
589  * and private keys
590  */
591  ssl_server_cert_file = cfg_get(grp, octstr_imm("ssl-server-cert-file"));
592  ssl_server_key_file = cfg_get(grp, octstr_imm("ssl-server-key-file"));
593  if (ssl_server_cert_file != NULL && ssl_server_key_file != NULL) {
594  /* we are fine here, the following call is now in conn_config_ssl(),
595  * so there is no reason to do this twice.
596 
597  use_global_server_certkey_file(ssl_server_cert_file,
598  ssl_server_key_file);
599  */
600  } else if (ssl) {
601  panic(0, "You MUST specify cert and key files within core group for SSL-enabled HTTP servers!");
602  }
603 
604  octstr_destroy(ssl_server_cert_file);
605  octstr_destroy(ssl_server_key_file);
606 #endif /* HAVE_LIBSSL */
607 
609 
610  if (gwthread_create(httpadmin_run, NULL) == -1)
611  panic(0, "Failed to start a new thread for HTTP admin");
612 
613  httpadmin_running = 1;
614  return 0;
615 }
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:2483
int cfg_get_bool(int *n, CfgGroup *grp, Octstr *varname)
Definition: cfg.c:759
Definition: octstr.c:118
int cfg_get_integer(long *n, CfgGroup *grp, Octstr *varname)
Definition: cfg.c:742
#define panic
Definition: log.h:87
Definition: cfg.c:73
CfgGroup * cfg_get_single_group(Cfg *cfg, Octstr *name)
Definition: cfg.c:639
static void httpadmin_run(void *arg)
Definition: bb_http.c:525

◆ httpadmin_stop()

void httpadmin_stop ( void  )

Definition at line 618 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().

619 {
627  ha_password = NULL;
628  ha_status_pw = NULL;
629  ha_allow_ip = NULL;
630  ha_deny_ip = NULL;
631 }
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:2526
static void httpadmin_run(void *arg)
Definition: bb_http.c:525

◆ route_incoming_to_boxc()

int route_incoming_to_boxc ( Msg msg)

Definition at line 1549 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_default, 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().

1550 {
1551  Boxc *bc = NULL;
1552  Octstr *s, *r, *rs, *boxc_id = NULL;
1553  long len, b, i;
1554  int full_found = 0;
1555 
1556  gw_assert(msg_type(msg) == sms);
1557 
1558  /* msg_dump(msg, 0); */
1559 
1560  /* Check we have at least one smsbox connected! */
1562  if (gwlist_len(smsbox_list) == 0) {
1564  warning(0, "smsbox_list empty!");
1565  if (max_incoming_sms_qlength < 0 || max_incoming_sms_qlength > gwlist_len(incoming_sms)) {
1567  return 0;
1568  } else {
1569  return -1;
1570  }
1571  }
1572 
1573  /*
1574  * Do we have a specific smsbox-id route to pass this msg to?
1575  */
1576  if (octstr_len(msg->sms.boxc_id) > 0) {
1577  boxc_id = msg->sms.boxc_id;
1578  } else {
1579  /*
1580  * Check if we have a "smsbox-route" for this msg.
1581  * Where the shortcode route has a higher priority then the smsc-id rule.
1582  * Highest priority has the combined <shortcode>:<smsc-id> route.
1583  */
1584  Octstr *os = octstr_format("%s:%s",
1585  octstr_get_cstr(msg->sms.receiver),
1586  octstr_get_cstr(msg->sms.smsc_id));
1587  s = (msg->sms.smsc_id ? dict_get(smsbox_by_smsc, msg->sms.smsc_id) : NULL);
1588  r = (msg->sms.receiver ? dict_get(smsbox_by_receiver, msg->sms.receiver) : NULL);
1589  rs = (os ? dict_get(smsbox_by_smsc_receiver, os) : NULL);
1590  octstr_destroy(os);
1591 
1592  if (rs)
1593  boxc_id = rs;
1594  else if (r)
1595  boxc_id = r;
1596  else if (s)
1597  boxc_id = s;
1598  else if (smsbox_by_default)
1599  boxc_id = smsbox_by_default;
1600  }
1601 
1602  /* We have a specific smsbox-id to use */
1603  if (boxc_id != NULL) {
1604 
1605  List *boxc_id_list = dict_get(smsbox_by_id, boxc_id);
1606  if (gwlist_len(boxc_id_list) == 0) {
1607  /*
1608  * something is wrong, this was the smsbox connection we used
1609  * for sending, so it seems this smsbox is gone
1610  */
1611  warning(0, "Could not route message to smsbox id <%s>, smsbox is gone!",
1612  octstr_get_cstr(boxc_id));
1614  if (max_incoming_sms_qlength < 0 || max_incoming_sms_qlength > gwlist_len(incoming_sms)) {
1616  return 0;
1617  } else {
1618  return -1;
1619  }
1620  }
1621 
1622  /*
1623  * Take random smsbox from list, as long as it has space we will use it,
1624  * otherwise check the next one.
1625  */
1626  len = gwlist_len(boxc_id_list);
1627  b = gw_rand() % len;
1628 
1629  for (i = 0; i < len; i++) {
1630  bc = gwlist_get(boxc_id_list, (i+b) % len);
1631 
1632  if (bc != NULL && max_incoming_sms_qlength > 0 &&
1634  bc = NULL;
1635  }
1636 
1637  if (bc != NULL) {
1638  break;
1639  }
1640  }
1641 
1642  if (bc != NULL) {
1643  bc->load++;
1644  gwlist_produce(bc->incoming, msg);
1646  return 1; /* we are done */
1647  }
1648  else {
1649  /*
1650  * we have routing defined, but no smsbox connected at the moment.
1651  * put msg into global incoming queue and wait until smsbox with
1652  * such boxc_id connected.
1653  */
1655  if (max_incoming_sms_qlength < 0 || max_incoming_sms_qlength > gwlist_len(incoming_sms)) {
1657  return 0;
1658  } else {
1659  return -1;
1660  }
1661  }
1662  }
1663 
1664  /*
1665  * Ok, none of the specific routing things applied previously,
1666  * so route it to a random smsbox.
1667  * Take random smsbox from list, as long as it has space we will
1668  * use it, therwise check the next one.
1669  */
1670  len = gwlist_len(smsbox_list);
1671  b = gw_rand() % len;
1672 
1673  for (i = 0; i < len; i++) {
1674  bc = gwlist_get(smsbox_list, (i+b) % len);
1675 
1676  if (bc->boxc_id != NULL || bc->routable == 0)
1677  bc = NULL;
1678 
1679  if (bc != NULL && max_incoming_sms_qlength > 0 &&
1681  full_found = 1;
1682  bc = NULL;
1683  }
1684 
1685  if (bc != NULL) {
1686  break;
1687  }
1688  }
1689 
1690  if (bc != NULL) {
1691  bc->load++;
1692  gwlist_produce(bc->incoming, msg);
1693  }
1694 
1696 
1697  if (bc == NULL && full_found == 0) {
1698  warning(0, "smsbox_list empty!");
1699  if (max_incoming_sms_qlength < 0 || max_incoming_sms_qlength > gwlist_len(incoming_sms)) {
1701  return 0;
1702  } else {
1703  return -1;
1704  }
1705  } else if (bc == NULL && full_found == 1) {
1706  return -1;
1707  }
1708 
1709  return 1;
1710 }
List * incoming
Definition: opensmppbox.c:154
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:148
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 Octstr * smsbox_by_default
Definition: bb_boxc.c:114
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:160
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:167
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 1316 of file bb_boxc.c.

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

Referenced by bb_graceful_restart().

1317 {
1318  if (!smsbox_running) return -1;
1319 
1324  smsbox_by_smsc = dict_create(30, (void(*)(void *)) octstr_destroy);
1325  smsbox_by_receiver = dict_create(50, (void(*)(void *)) octstr_destroy);
1326  smsbox_by_smsc_receiver = dict_create(50, (void(*)(void *)) octstr_destroy);
1328  smsbox_by_default = NULL;
1329  init_smsbox_routes(cfg, 1);
1331 
1332  return 0;
1333 }
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 Octstr * smsbox_by_default
Definition: bb_boxc.c:114
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:1125
void dict_destroy(Dict *dict)
Definition: dict.c:215

◆ smsbox_start()

int smsbox_start ( Cfg config)

Definition at line 1250 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_default, 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().

1251 {
1252  CfgGroup *grp;
1253 
1254  if (smsbox_running) return -1;
1255 
1256  debug("bb", 0, "starting smsbox connection module");
1257 
1258  grp = cfg_get_single_group(cfg, octstr_imm("core"));
1259  if (cfg_get_integer(&smsbox_port, grp, octstr_imm("smsbox-port")) == -1) {
1260  error(0, "Missing smsbox-port variable, cannot start smsboxes");
1261  return -1;
1262  }
1263 #ifdef HAVE_LIBSSL
1264  cfg_get_bool(&smsbox_port_ssl, grp, octstr_imm("smsbox-port-ssl"));
1265 #endif /* HAVE_LIBSSL */
1266 
1267  if (smsbox_port_ssl)
1268  debug("bb", 0, "smsbox connection module is SSL-enabled");
1269 
1270  smsbox_interface = cfg_get(grp, octstr_imm("smsbox-interface"));
1271 
1272  if (cfg_get_integer(&smsbox_max_pending, grp, octstr_imm("smsbox-max-pending")) == -1) {
1274  info(0, "BOXC: 'smsbox-max-pending' not set, using default (%ld).", smsbox_max_pending);
1275  }
1276 
1277  box_allow_ip = cfg_get(grp, octstr_imm("box-allow-ip"));
1278  if (box_allow_ip == NULL)
1280  box_deny_ip = cfg_get(grp, octstr_imm("box-deny-ip"));
1281  if (box_deny_ip == NULL)
1282  box_deny_ip = octstr_create("");
1283  if (box_allow_ip != NULL && box_deny_ip == NULL)
1284  info(0, "Box connection allowed IPs defined without any denied...");
1285 
1286  smsbox_list = gwlist_create(); /* have a list of connections */
1288  if (!boxid)
1289  boxid = counter_create();
1290 
1291  /* the smsbox routing specific inits */
1292  smsbox_by_id = dict_create(10, (void(*)(void *)) boxc_gwlist_destroy);
1293  smsbox_by_smsc = dict_create(30, (void(*)(void *)) octstr_destroy);
1294  smsbox_by_receiver = dict_create(50, (void(*)(void *)) octstr_destroy);
1295  smsbox_by_smsc_receiver = dict_create(50, (void(*)(void *)) octstr_destroy);
1296  smsbox_by_default = NULL;
1297 
1298  /* load the defined smsbox routing rules */
1299  init_smsbox_routes(cfg, 0);
1300 
1303 
1304  smsbox_running = 1;
1305 
1306  if ((sms_dequeue_thread = gwthread_create(sms_to_smsboxes, NULL)) == -1)
1307  panic(0, "Failed to start a new thread for smsbox routing");
1308 
1309  if (gwthread_create(smsboxc_run, NULL) == -1)
1310  panic(0, "Failed to start a new thread for smsbox connections");
1311 
1312  return 0;
1313 }
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:1713
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:117
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:126
static Octstr * smsbox_by_default
Definition: bb_boxc.c:114
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:118
static void smsboxc_run(void *arg)
Definition: bb_boxc.c:1018
static void boxc_gwlist_destroy(List *list)
Definition: bb_boxc.c:1786
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:123
static Dict * smsbox_by_smsc_receiver
Definition: bb_boxc.c:113
static Counter * boxid
Definition: bb_boxc.c:129
static void init_smsbox_routes(Cfg *cfg, int reload)
Definition: bb_boxc.c:1125
int cfg_get_bool(int *n, CfgGroup *grp, Octstr *varname)
Definition: cfg.c:759
static long smsbox_port
Definition: bb_boxc.c:116
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:742
#define panic
Definition: log.h:87
Definition: cfg.c:73
static Octstr * box_allow_ip
Definition: bb_boxc.c:125
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:132
CfgGroup * cfg_get_single_group(Cfg *cfg, Octstr *name)
Definition: cfg.c:639
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_destroy(), octstr_get_cstr, octstr_imm(), smsc2_find(), smsc_groups, smsc_list, smsc_list_lock, smsc_running, smscconn_create(), smscconn_instances(), smscconn_shutdown(), smscconn_start(), and warning().

Referenced by bb_add_smsc().

1113 {
1114  CfgGroup *grp;
1115  SMSCConn *conn = NULL;
1116  Octstr *smscid = NULL;
1117  long i, m, j;
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  /* multiple instances for the same group? */
1145  m = smscconn_instances(grp);
1146  for (j = 0; j < m; j++) {
1147  conn = smscconn_create(grp, 1);
1148  if (conn != NULL) {
1149  gwlist_append(smsc_list, conn);
1150  if (conn->dead_start) {
1151  /* Shutdown connection if it's not configured to connect at start-up time */
1152  smscconn_shutdown(conn, 0);
1153  } else {
1154  smscconn_start(conn);
1155  }
1156  success = 1;
1157  } else {
1158  error(0, "Cannot start with SMSC %s connection failing", octstr_get_cstr(id));
1159  }
1160  }
1161  }
1162  octstr_destroy(smscid);
1163  smscid = NULL;
1164  }
1167  if (success == 0) {
1168  error(0, "SMSC %s not found", octstr_get_cstr(id));
1169  return -1;
1170  }
1171  return 0;
1172 }
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:211
void smscconn_shutdown(SMSCConn *conn, int finish_sending)
Definition: smscconn.c:427
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
unsigned int smscconn_instances(CfgGroup *grp)
Definition: smscconn.c:197
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:627
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
Definition: octstr.c:118
Definition: cfg.c:73
SMSCConn * smscconn_create(CfgGroup *grp, int start_as_stopped)
Definition: smscconn.c:210
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:536
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 1314 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().

1315 {
1316  SMSCConn *conn;
1317  long i;
1318 
1319  if (!smsc_running)
1320  return;
1321 
1322  debug("smscconn", 0, "final clean-up for SMSCConn");
1323 
1325  for (i = 0; i < gwlist_len(smsc_list); i++) {
1326  conn = gwlist_get(smsc_list, i);
1327  smscconn_destroy(conn);
1328  }
1329  gwlist_destroy(smsc_list, NULL);
1330  smsc_list = NULL;
1332  gwlist_destroy(smsc_groups, NULL);
1338  if (white_list_sender_regex != NULL)
1339  gw_regex_destroy(white_list_sender_regex);
1340  if (black_list_sender_regex != NULL)
1341  gw_regex_destroy(black_list_sender_regex);
1346  if (white_list_receiver_regex != NULL)
1347  gw_regex_destroy(white_list_receiver_regex);
1348  if (black_list_receiver_regex != NULL)
1349  gw_regex_destroy(black_list_receiver_regex);
1350  /* destroy msg split counter */
1354 
1355  /* Stop concat handling */
1357 
1358  smsc_running = 0;
1359 }
static List * smsc_groups
Definition: bb_smscconn.c:131
int smscconn_destroy(SMSCConn *conn)
Definition: smscconn.c:464
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:2066
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 1530 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().

1531 {
1532  CfgGroup *grp;
1533  SMSCConn *conn;
1534  List *keep, *add, *remove;
1535  List *l;
1536  int i, m;
1537 
1538  if (!smsc_running)
1539  return -1;
1540 
1542 
1543  /* load the smsc groups from the config resource */
1544  gwlist_destroy(smsc_groups, NULL);
1546 
1547  /* List of SMSCConn that we keep running */
1548  keep = gwlist_create();
1549 
1550  /* List of CfgGroup that we will add */
1551  add = gwlist_create();
1552 
1553  /* List of SMSCConnn that we will shutdown */
1554  remove = gwlist_create();
1555 
1556  /*
1557  * Loop through the loaded smsc groups
1558  */
1559  for (i = 0; i < gwlist_len(smsc_groups) &&
1560  (grp = gwlist_get(smsc_groups, i)) != NULL; i++) {
1561  /*
1562  * 1st check: Search for the same md5 hash of the whole group.
1563  * If we find it, then this group is already running, and no
1564  * routing information has changed, bail out.
1565  */
1566  if ((l = gwlist_search_all(smsc_list, grp, cmp_conn_grp_checksum)) != NULL) {
1567  while ((conn = gwlist_extract_first(l)) != NULL) {
1568  gwlist_append(keep, conn);
1569  }
1570  gwlist_destroy(l, NULL);
1571  continue;
1572  }
1573  /*
1574  * 2nd check: Search for the same md5 hash minus the routing
1575  * information. If we find it, then this group is already running
1576  * and the routing information changed, we'll apply only the new
1577  * routing information.
1578  */
1579  if ((l = gwlist_search_all(smsc_list, grp, cmp_rout_grp_checksum)) != NULL) {
1580  while ((conn = gwlist_extract_first(l)) != NULL) {
1581  gwlist_append(keep, conn);
1582  smscconn_reconfig(conn, grp);
1583  info(0, "Re-configured routing for smsc-id `%s'.", octstr_get_cstr(conn->id));
1584  }
1585  gwlist_destroy(l, NULL);
1586  continue;
1587  }
1588  /*
1589  * 3rd check: if the smsc-id is NOT in the running list, then
1590  * this is a new group, add it. If the smsc-id IS found, then
1591  * mark it/them to be removed, and add the new group.
1592  */
1593  if ((l = gwlist_search_all(smsc_list, grp, cmp_conn_grp_id)) == NULL) {
1594  gwlist_append(add, grp);
1595  continue;
1596  } else {
1597  while ((conn = gwlist_extract_first(l)) != NULL) {
1598  /* add them to the remove list only
1599  * if they are not yet present inside. */
1600  if (gwlist_search_equal(remove, conn) != -1)
1601  gwlist_append(remove, conn);
1602  }
1603  gwlist_destroy(l, NULL);
1604  gwlist_append(add, grp);
1605  continue;
1606  }
1607  }
1608 
1609  /*
1610  * TODO Effectively a change in the 'instances' multiplier will result in a
1611  * disconnect of all running instances, and re-connecting the number of
1612  * configured instances. The reason for this is that the change in the
1613  * 'instances' value causes the md5 hash to be different for that connection.
1614  * We MAY exclude the 'instances' directive from the while md5 checksum, this
1615  * makes the down-grading easier, allowing the rest to keep running. But the
1616  * up-grading is more difficult, since we can't use the 'add' list here, it
1617  * would create too much instances.
1618  */
1619 
1620  /*
1621  * We may have running smsc-ids now, that haven't been
1622  * re-loaded from the new config, hence add them to be removed.
1623  */
1624  for (i = 0; i < gwlist_len(smsc_list) &&
1625  (conn = gwlist_get(smsc_list, i)) != NULL; i++) {
1626  /* if this is already in the remove list, bail out. */
1627  if (gwlist_search_equal(remove, conn) != -1)
1628  continue;
1629  /* if this is in the keep list, bail out. */
1630  if (gwlist_search_equal(keep, conn) != -1)
1631  continue;
1632  /* mark it to be removed */
1633  gwlist_append(remove, conn);
1634  }
1635  gwlist_destroy(keep, NULL);
1636 
1637  /*
1638  * Stop any connections from the remove list.
1639  *
1640  * The smscconn_shutdown() only initiates the shutdown,
1641  * it is not guaranteed that the SMSC connection is stopped
1642  * and the status is SMSCCONN_DEAD when we return from the
1643  * function call. Therefore we pass the connection to a
1644  * retry list, in order to cleanly destroy all connection
1645  * structures that have been stopped and reached SMSSCONN_DEAD.
1646  */
1647  l = gwlist_create();
1649  while ((conn = gwlist_extract_first(remove)) != NULL) {
1650  if ((i = gwlist_search_equal(smsc_list, conn)) != -1) {
1651  gwlist_delete(smsc_list, i, 1);
1652  smscconn_shutdown(conn, 0);
1653  /* if smsc is still in shutdown, then add to retry list */
1654  if (smscconn_destroy(conn) == -1)
1655  gwlist_append(l, conn);
1656  }
1657  }
1659  gwlist_destroy(remove, NULL);
1660 
1661  /*
1662  * Start any connections from the add list.
1663  */
1665  while ((grp = gwlist_extract_first(add)) != NULL) {
1666  /* multiple instances for the same group? */
1667  m = smscconn_instances(grp);
1668  for (i = 0; i < m; i++) {
1669  conn = smscconn_create(grp, 1);
1670  if (conn != NULL) {
1671  gwlist_append(smsc_list, conn);
1672  if (conn->dead_start) {
1673  /* Shutdown connection if it's not configured to connect at start-up time */
1674  smscconn_shutdown(conn, 0);
1675  } else {
1676  smscconn_start(conn);
1677  }
1678  }
1679  }
1680  }
1682  gwlist_destroy(add, NULL);
1683 
1685 
1686  /* wake-up the router */
1687  if (router_thread >= 0)
1689 
1690  /*
1691  * We may still have pending connections in the retry list
1692  * that haven't been destroyed yet.
1693  */
1694  while ((conn = gwlist_extract_first(l)) != NULL) {
1695  if (smscconn_destroy(conn) == -1) {
1696  gwlist_append(l, conn);
1697  gwthread_sleep(2);
1698  }
1699  }
1700  gwlist_destroy(l, NULL);
1701 
1702  return 0;
1703 }
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:464
void gwlist_append(List *list, void *item)
Definition: list.c:179
void smscconn_shutdown(SMSCConn *conn, int finish_sending)
Definition: smscconn.c:427
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:197
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:763
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:734
List * cfg_get_multi_group(Cfg *cfg, Octstr *name)
Definition: cfg.c:645
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:751
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:210
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:536
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 1174 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().

1175 {
1176  Numhash *tmp;
1177  int rc = 1;
1178 
1179  if (white_list_sender_url != NULL) {
1181  if (white_list_sender == NULL) {
1182  error(0, "Unable to reload white_list."),
1183  rc = -1;
1184  } else {
1187  white_list_sender = tmp;
1189  }
1190  }
1191 
1192  if (black_list_sender_url != NULL) {
1194  if (black_list_sender == NULL) {
1195  error(0, "Unable to reload black_list");
1196  rc = -1;
1197  } else {
1200  black_list_sender = tmp;
1202  }
1203  }
1204 
1205  if (white_list_receiver_url != NULL) {
1207  if (white_list_receiver == NULL) {
1208  error(0, "Unable to reload white_list."),
1209  rc = -1;
1210  } else {
1213  white_list_receiver = tmp;
1215  }
1216  }
1217 
1218  if (black_list_receiver_url != NULL) {
1220  if (black_list_receiver == NULL) {
1221  error(0, "Unable to reload black_list");
1222  rc = -1;
1223  } else {
1226  black_list_receiver = tmp;
1228  }
1229  }
1230 
1231  return rc;
1232 }
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:464
void smscconn_shutdown(SMSCConn *conn, int finish_sending)
Definition: smscconn.c:427
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:464
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:724
void gwlist_delete(List *list, long pos, long count)
Definition: list.c:232
int bb_reload_smsc_groups()
Definition: bb_smscconn.c:627
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:210
static volatile sig_atomic_t smsc_running
Definition: bb_smscconn.c:127
void smscconn_start(SMSCConn *conn)
Definition: smscconn.c:536
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 1234 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().

1235 {
1236  SMSCConn *conn;
1237  long i;
1238 
1239  if (!smsc_running)
1240  return;
1241 
1243  for (i = 0; i < gwlist_len(smsc_list); i++) {
1244  conn = gwlist_get(smsc_list, i);
1245  if (!is_init || !conn->dead_start) {
1246  smscconn_start(conn);
1247  } else {
1248  /* Shutdown the connections that are not configured to start at boot */
1249  smscconn_shutdown(conn, 0);
1250  }
1251  }
1253 
1254  if (router_thread >= 0)
1256 }
static long router_thread
Definition: bb_smscconn.c:149
int dead_start
Definition: smscconn_p.h:211
void smscconn_shutdown(SMSCConn *conn, int finish_sending)
Definition: smscconn.c:427
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:536
static List * smsc_list
Definition: bb_smscconn.c:128

◆ smsc2_rout()

long smsc2_rout ( Msg msg,
int  resend 
)

Definition at line 1716 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().

1717 {
1718  StatusInfo stat;
1719  SMSCConn *conn, *best_preferred, *best_ok;
1720  long bp_load, bo_load;
1721  int i, s, ret, bad_found, full_found;
1722  long max_queue, queue_length;
1723  char *uf;
1724 
1725  /* XXX handle ack here? */
1726  if (msg_type(msg) != sms) {
1727  error(0, "Attempt to route non SMS message through smsc2_rout!");
1729  }
1730 
1731  /* check if validity period has expired */
1732  if (msg->sms.validity != SMS_PARAM_UNDEFINED && time(NULL) > msg->sms.validity) {
1734  return SMSCCONN_FAILED_EXPIRED;
1735  }
1736 
1737  /* unify prefix of receiver, in case of it has not been
1738  * already done */
1740  normalize_number(uf, &(msg->sms.receiver));
1741 
1742  /* check for white/back-listed sender/receiver */
1744  if (white_list_sender && numhash_find_number(white_list_sender, msg->sms.sender) < 1) {
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 (white_list_sender_regex && gw_regex_match_pre(white_list_sender_regex, msg->sms.sender) == 0) {
1754  info(0, "Number <%s> is not in white-list-sender, message rejected",
1755  octstr_get_cstr(msg->sms.sender));
1756  bb_smscconn_send_failed(NULL, msg_duplicate(msg), SMSCCONN_FAILED_REJECTED, octstr_create("sender not in white-list"));
1757  return SMSCCONN_FAILED_REJECTED;
1758  }
1759 
1760  if (black_list_sender && numhash_find_number(black_list_sender, msg->sms.sender) == 1) {
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 (black_list_sender_regex && gw_regex_match_pre(black_list_sender_regex, msg->sms.sender) != 0) {
1770  info(0, "Number <%s> is in black-list-sender, message rejected",
1771  octstr_get_cstr(msg->sms.sender));
1773  return SMSCCONN_FAILED_REJECTED;
1774  }
1775 
1776  if (white_list_receiver && numhash_find_number(white_list_receiver, msg->sms.receiver) < 1) {
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 (white_list_receiver_regex && gw_regex_match_pre(white_list_receiver_regex, msg->sms.receiver) == 0) {
1786  info(0, "Number <%s> is not in white-list-receiver, message rejected",
1787  octstr_get_cstr(msg->sms.receiver));
1788  bb_smscconn_send_failed(NULL, msg_duplicate(msg), SMSCCONN_FAILED_REJECTED, octstr_create("receiver not in white-list"));
1789  return SMSCCONN_FAILED_REJECTED;
1790  }
1791 
1792  if (black_list_receiver && numhash_find_number(black_list_receiver, msg->sms.receiver) == 1) {
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  }
1799 
1800  if (black_list_receiver_regex && gw_regex_match_pre(black_list_receiver_regex, msg->sms.receiver) != 0) {
1802  info(0, "Number <%s> is in black-list-receiver, message rejected",
1803  octstr_get_cstr(msg->sms.receiver));
1805  return SMSCCONN_FAILED_REJECTED;
1806  }
1808 
1809  /* select in which list to add this
1810  * start - from random SMSCConn, as they are all 'equal'
1811  */
1813  if (gwlist_len(smsc_list) == 0) {
1814  warning(0, "No SMSCes to receive message");
1817  }
1818 
1819  best_preferred = best_ok = NULL;
1820  bad_found = full_found = 0;
1821  bp_load = bo_load = queue_length = 0;
1822 
1823  if (msg->sms.split_parts == NULL) {
1824  /*
1825  * if global queue not empty then 20% reserved for old msgs
1826  * and 80% for new msgs. So we can guarantee that old msgs find
1827  * place in the SMSC's queue.
1828  */
1829  if (gwlist_len(outgoing_sms) > 0) {
1830  max_queue = (resend ? max_outgoing_sms_qlength :
1831  max_outgoing_sms_qlength * 0.8);
1832  } else
1833  max_queue = max_outgoing_sms_qlength;
1834 
1835  s = gw_rand() % gwlist_len(smsc_list);
1836 
1837  conn = NULL;
1838  for (i = 0; i < gwlist_len(smsc_list); i++) {
1839  conn = gwlist_get(smsc_list, (i+s) % gwlist_len(smsc_list));
1840 
1841  smscconn_info(conn, &stat);
1842  queue_length += (stat.queued > 0 ? stat.queued : 0);
1843 
1844  ret = smscconn_usable(conn,msg);
1845  if (ret == -1)
1846  continue;
1847 
1848  /* if we already have a preferred one, skip non-preferred */
1849  if (ret != 1 && best_preferred)
1850  continue;
1851 
1852  /* If connection is not currently answering ... */
1853  if (stat.status != SMSCCONN_ACTIVE) {
1854  bad_found = 1;
1855  continue;
1856  }
1857  /* check queue length */
1858  if (stat.queued > max_queue) {
1859  full_found = 1;
1860  continue;
1861  }
1862  if (ret == 1) { /* preferred */
1863  if (best_preferred == NULL || stat.load < bp_load) {
1864  best_preferred = conn;
1865  bp_load = stat.load;
1866  continue;
1867  }
1868  }
1869  if (best_ok == NULL || stat.load < bo_load) {
1870  best_ok = conn;
1871  bo_load = stat.load;
1872  }
1873  }
1874  queue_length += gwlist_len(outgoing_sms);
1875  if (max_outgoing_sms_qlength > 0 && !resend &&
1876  queue_length > gwlist_len(smsc_list) * max_outgoing_sms_qlength) {
1878  debug("bb.sms", 0, "sum(#queues) limit");
1879  return SMSCCONN_FAILED_QFULL;
1880  }
1881  } else {
1882  struct split_parts *parts = msg->sms.split_parts;
1883  /* check whether this SMSCConn still on the list */
1884  if (gwlist_search_equal(smsc_list, parts->smsc_conn) != -1)
1885  best_preferred = parts->smsc_conn;
1886  }
1887 
1888  if (best_preferred)
1889  ret = smscconn_send(best_preferred, msg);
1890  else if (best_ok)
1891  ret = smscconn_send(best_ok, msg);
1892  else if (bad_found) {
1896  return SMSCCONN_QUEUED;
1897  }
1898  debug("bb.sms", 0, "bad_found queue full");
1899  return SMSCCONN_FAILED_QFULL; /* queue full */
1900  } else if (full_found) {
1902  debug("bb.sms", 0, "full_found queue full");
1903  return SMSCCONN_FAILED_QFULL;
1904  } else {
1906  if (bb_status == BB_SHUTDOWN) {
1907  msg_destroy(msg);
1908  return SMSCCONN_QUEUED;
1909  }
1910  warning(0, "Cannot find SMSCConn for message to <%s>, rejected.",
1911  octstr_get_cstr(msg->sms.receiver));
1914  }
1915 
1917  /* check the status of sending operation */
1918  if (ret == -1)
1919  return smsc2_rout(msg, resend); /* re-try */
1920 
1921  msg_destroy(msg);
1922  return SMSCCONN_SUCCESS;
1923 }
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:655
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:573
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:329
static Octstr * unified_prefix
Definition: bb_smscconn.c:132
int smscconn_info(SMSCConn *conn, StatusInfo *infotable)
Definition: smscconn.c:732
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:1716

◆ smsc2_shutdown()

int smsc2_shutdown ( void  )

Definition at line 1276 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().

1277 {
1278  SMSCConn *conn;
1279  long i;
1280 
1281  if (!smsc_running)
1282  return -1;
1283 
1284  /* stop concat handling */
1286 
1287  /* Call shutdown for all SMSC Connections; they should
1288  * handle that they quit, by emptying queues and then dying off
1289  */
1291  for(i=0; i < gwlist_len(smsc_list); i++) {
1292  conn = gwlist_get(smsc_list, i);
1293  smscconn_shutdown(conn, 1);
1294  }
1296  if (router_thread >= 0)
1298 
1299  /* start avalanche by calling shutdown */
1300 
1301  /* XXX shouldn'w we be sure that all smsces have closed their
1302  * receive thingies? Is this guaranteed by setting bb_status
1303  * to shutdown before calling these?
1304  */
1306 
1307  /* shutdown low levele PDU things */
1309 
1310  return 0;
1311 }
static long router_thread
Definition: bb_smscconn.c:149
void smscconn_shutdown(SMSCConn *conn, int finish_sending)
Definition: smscconn.c:427
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:2053
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:197
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:2043
List * cfg_get_multi_group(Cfg *cfg, Octstr *name)
Definition: cfg.c:645
static void sms_router(void *arg)
Definition: bb_smscconn.c:650
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:759
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:742
#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:210
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:639
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 1362 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().

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

1260 {
1261  SMSCConn *conn;
1262  long i;
1263 
1264  if (!smsc_running)
1265  return;
1266 
1268  for (i = 0; i < gwlist_len(smsc_list); i++) {
1269  conn = gwlist_get(smsc_list, i);
1270  smscconn_stop(conn);
1271  }
1273 }
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:516
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:639
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 1339 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().

1340 {
1341  CfgGroup *grp;
1342 
1343  if (wapbox_running) return -1;
1344 
1345  debug("bb", 0, "starting wapbox connection module");
1346 
1347  grp = cfg_get_single_group(cfg, octstr_imm("core"));
1348 
1349  if (cfg_get_integer(&wapbox_port, grp, octstr_imm("wapbox-port")) == -1) {
1350  error(0, "Missing wapbox-port variable, cannot start WAP");
1351  return -1;
1352  }
1353 #ifdef HAVE_LIBSSL
1354  cfg_get_bool(&wapbox_port_ssl, grp, octstr_imm("wapbox-port-ssl"));
1355 #endif /* HAVE_LIBSSL */
1356 
1357  if (box_allow_ip == NULL) {
1358  box_allow_ip = cfg_get(grp, octstr_imm("box-allow-ip"));
1359  if (box_allow_ip == NULL)
1361  }
1362  if (box_deny_ip == NULL) {
1363  box_deny_ip = cfg_get(grp, octstr_imm("box-deny-ip"));
1364  if (box_deny_ip == NULL)
1365  box_deny_ip = octstr_create("");
1366  }
1367  if (box_allow_ip != NULL && box_deny_ip == NULL)
1368  info(0, "Box connection allowed IPs defined without any denied...");
1369 
1370  wapbox_list = gwlist_create(); /* have a list of connections */
1372  if (!boxid)
1373  boxid = counter_create();
1374 
1375  if (gwthread_create(wdp_to_wapboxes, NULL) == -1)
1376  panic(0, "Failed to start a new thread for wapbox routing");
1377 
1379  panic(0, "Failed to start a new thread for wapbox connections");
1380 
1381  wapbox_running = 1;
1382  return 0;
1383 }
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:120
#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:126
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:1077
#define gwthread_create(func, arg)
Definition: gwthread.h:90
#define octstr_create(cstr)
Definition: octstr.h:125
static Counter * boxid
Definition: bb_boxc.c:129
int cfg_get_bool(int *n, CfgGroup *grp, Octstr *varname)
Definition: cfg.c:759
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:742
#define panic
Definition: log.h:87
Definition: cfg.c:73
static Octstr * box_allow_ip
Definition: bb_boxc.c:125
static void wdp_to_wapboxes(void *arg)
Definition: bb_boxc.c:924
#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:639
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:119
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.