Kannel: Open Source WAP and SMS gateway  $Revision: 5037 $
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 (void)
 
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

#define DEFAULT_OUTGOING_SMS_QLENGTH   1000000

Definition at line 69 of file bearerbox.h.

Referenced by init_bearerbox().

Enumeration Type Documentation

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
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

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
void bb_alog_init ( const Octstr format)

Definition at line 359 of file bb_alog.c.

References gw_assert(), and octstr_duplicate.

Referenced by init_bearerbox().

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

Definition at line 367 of file bb_alog.c.

References octstr_destroy().

Referenced by main().

368 {
370  custom_log_format = NULL;
371 }
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:322
static Octstr * custom_log_format
Definition: bb_alog.c:70
void bb_alog_sms ( SMSCConn conn,
Msg sms,
const char *  message 
)

Definition at line 374 of file bb_alog.c.

References alog(), DC_8BIT, DC_UCS2, get_pattern(), gw_assert(), 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))
399  octstr_binary_to_hex(text, 1);
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 
427  octstr_destroy(text);
428 }
msg_type
Definition: msg.h:73
const Octstr * smscconn_name(SMSCConn *conn)
Definition: smscconn.c:493
#define DC_8BIT
Definition: sms.h:111
static Octstr * get_pattern(SMSCConn *conn, Msg *msg, const char *message)
Definition: bb_alog.c:117
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
void octstr_binary_to_hex(Octstr *ostr, int uppercase)
Definition: octstr.c:463
void octstr_convert_printable(Octstr *ostr)
Definition: octstr.c:862
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:281
char * text
Definition: smsc_cimd2.c:921
const Octstr * smscconn_id(SMSCConn *conn)
Definition: smscconn.c:500
#define octstr_duplicate(ostr)
Definition: octstr.h:187
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:322
#define octstr_create(cstr)
Definition: octstr.h:125
gw_assert(wtls_machine->packet_to_send!=NULL)
long octstr_len(const Octstr *ostr)
Definition: octstr.c:340
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
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
int bb_graceful_restart ( void  )

Definition at line 954 of file bearerbox.c.

References smsc2_graceful_restart().

Referenced by httpd_graceful_restart(), and main().

955 {
956  return smsc2_graceful_restart();
957 }
int smsc2_graceful_restart(void)
Definition: bb_smscconn.c:1522
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(), mutex_lock, mutex_unlock, and smsc2_suspend().

Referenced by httpd_isolate().

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

Definition at line 986 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(), load_get(), octstr_append_cstr(), octstr_create, octstr_destroy(), octstr_format(), octstr_get_cstr, smsc2_status(), start_time, store_messages, udp_outgoing_queue(), and version_report_string().

Referenced by httpd_status().

987 {
988  char *s, *lb;
989  char *frmt, *footer;
990  Octstr *ret, *str, *version;
991  time_t t;
992 
993  if ((lb = bb_status_linebreak(status_type)) == NULL)
994  return octstr_create("Un-supported format");
995 
996  t = time(NULL) - start_time;
997 
998  if (bb_status == BB_RUNNING)
999  s = "running";
1000  else if (bb_status == BB_ISOLATED)
1001  s = "isolated";
1002  else if (bb_status == BB_SUSPENDED)
1003  s = "suspended";
1004  else if (bb_status == BB_FULL)
1005  s = "filled";
1006  else
1007  s = "going down";
1008 
1009  version = version_report_string("bearerbox");
1010 
1011  if (status_type == BBSTATUS_HTML) {
1012  frmt = "%s</p>\n\n"
1013  " <p>Status: %s, uptime %ldd %ldh %ldm %lds</p>\n\n"
1014  " <p>WDP: received %ld (%ld queued), sent %ld "
1015  "(%ld queued)</p>\n\n"
1016  " <p>SMS: received %ld (%ld queued), sent %ld "
1017  "(%ld queued), store size %ld<br>\n"
1018  " SMS: inbound (%.2f,%.2f,%.2f) msg/sec, "
1019  "outbound (%.2f,%.2f,%.2f) msg/sec</p>\n\n"
1020  " <p>DLR: received %ld, sent %ld<br>\n"
1021  " DLR: inbound (%.2f,%.2f,%.2f) msg/sec, outbound (%.2f,%.2f,%.2f) msg/sec<br>\n"
1022  " DLR: %ld queued, using %s storage</p>\n\n";
1023  footer = "<p>";
1024  } else if (status_type == BBSTATUS_WML) {
1025  frmt = "%s</p>\n\n"
1026  " <p>Status: %s, uptime %ldd %ldh %ldm %lds</p>\n\n"
1027  " <p>WDP: received %ld (%ld queued)<br/>\n"
1028  " WDP: sent %ld (%ld queued)</p>\n\n"
1029  " <p>SMS: received %ld (%ld queued)<br/>\n"
1030  " SMS: sent %ld (%ld queued)<br/>\n"
1031  " SMS: store size %ld<br/>\n"
1032  " SMS: inbound (%.2f,%.2f,%.2f) msg/sec<br/>\n"
1033  " SMS: outbound (%.2f,%.2f,%.2f) msg/sec</p>\n"
1034  " <p>DLR: received %ld<br/>\n"
1035  " DLR: sent %ld<br/>\n"
1036  " DLR: inbound (%.2f,%.2f,%.2f) msg/sec<br/>\n"
1037  " DLR: outbound (%.2f,%.2f,%.2f) msg/sec<br/>\n"
1038  " DLR: %ld queued<br/>\n"
1039  " DLR: using %s storage</p>\n\n";
1040  footer = "<p>";
1041  } else if (status_type == BBSTATUS_XML) {
1042  frmt = "<version>%s</version>\n"
1043  "<status>%s, uptime %ldd %ldh %ldm %lds</status>\n"
1044  "\t<wdp>\n\t\t<received><total>%ld</total><queued>%ld</queued>"
1045  "</received>\n\t\t<sent><total>%ld</total><queued>%ld</queued>"
1046  "</sent>\n\t</wdp>\n"
1047  "\t<sms>\n\t\t<received><total>%ld</total><queued>%ld</queued>"
1048  "</received>\n\t\t<sent><total>%ld</total><queued>%ld</queued>"
1049  "</sent>\n\t\t<storesize>%ld</storesize>\n\t\t"
1050  "<inbound>%.2f,%.2f,%.2f</inbound>\n\t\t"
1051  "<outbound>%.2f,%.2f,%.2f</outbound>\n\t\t"
1052  "</sms>\n"
1053  "\t<dlr>\n\t\t<received><total>%ld</total></received>\n\t\t"
1054  "<sent><total>%ld</total></sent>\n\t\t"
1055  "<inbound>%.2f,%.2f,%.2f</inbound>\n\t\t"
1056  "<outbound>%.2f,%.2f,%.2f</outbound>\n\t\t"
1057  "<queued>%ld</queued>\n\t\t<storage>%s</storage>\n\t</dlr>\n";
1058  footer = "";
1059  } else {
1060  frmt = "%s\n\nStatus: %s, uptime %ldd %ldh %ldm %lds\n\n"
1061  "WDP: received %ld (%ld queued), sent %ld (%ld queued)\n\n"
1062  "SMS: received %ld (%ld queued), sent %ld (%ld queued), store size %ld\n"
1063  "SMS: inbound (%.2f,%.2f,%.2f) msg/sec, "
1064  "outbound (%.2f,%.2f,%.2f) msg/sec\n\n"
1065  "DLR: received %ld, sent %ld\n"
1066  "DLR: inbound (%.2f,%.2f,%.2f) msg/sec, outbound (%.2f,%.2f,%.2f) msg/sec\n"
1067  "DLR: %ld queued, using %s storage\n\n";
1068  footer = "";
1069  }
1070 
1071  ret = octstr_format(frmt,
1072  octstr_get_cstr(version),
1073  s, t/3600/24, t/3600%24, t/60%60, t%60,
1079  store_messages(),
1085  dlr_messages(), dlr_type());
1086 
1087  octstr_destroy(version);
1088 
1089  append_status(ret, str, boxc_status, status_type);
1090  append_status(ret, str, smsc2_status, status_type);
1091  octstr_append_cstr(ret, footer);
1092 
1093  return ret;
1094 }
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:1472
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:1097
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:1509
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:2462
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:322
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:983
Definition: octstr.c:118
List * outgoing_wdp
Definition: bearerbox.c:88
Octstr * boxc_status(int status_type)
Definition: bb_boxc.c:1348
Counter * outgoing_wdp_counter
Definition: bearerbox.c:95
Octstr * version_report_string(const char *boxname)
Definition: utils.c:549
Octstr * smsc2_status(int status_type)
Definition: bb_smscconn.c:1354
long dlr_messages(void)
Definition: dlr.c:308
int bb_reload_lists ( void  )

Definition at line 959 of file bearerbox.c.

References smsc2_reload_lists().

Referenced by httpd_reload_lists().

960 {
961  return smsc2_reload_lists();
962 }
int smsc2_reload_lists(void)
Definition: bb_smscconn.c:1166
int bb_reload_smsc_groups ( void  )

Definition at line 628 of file bb_smscconn.c.

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

Referenced by smsc2_add_smsc(), smsc2_graceful_restart(), and smsc2_restart_smsc().

629 {
630  debug("bb.sms", 0, "Reloading smsc groups list from config resource");
633  if (cfg_read(cfg_reloaded) == -1) {
634  warning(0, "Error opening configuration file %s", octstr_get_cstr(cfg_filename));
635  return -1;
636  }
639 
640  return 0;
641 }
static Cfg * cfg_reloaded
Definition: bb_smscconn.c:130
static List * smsc_groups
Definition: bb_smscconn.c:131
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
Cfg * cfg_create(Octstr *filename)
Definition: cfg.c:318
int cfg_read(Cfg *cfg)
Definition: cfg.c:452
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:281
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:642
void warning(int err, const char *fmt,...)
Definition: log.c:624
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:690
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)
Definition: list.c:145
int bb_remove_message ( Octstr id)

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

965 {
966  Msg *msg;
967  int ret;
968 
969  msg = msg_create(ack);
970  msg->ack.nack = ack_failed;
971  msg->ack.time = time(NULL);
972  uuid_parse(octstr_get_cstr(message_id), msg->ack.id);
973  ret = store_save(msg);
974  msg_destroy(msg);
975  if (ret != 0) {
976  error(0, "Could not delete message %s", octstr_get_cstr(message_id));
977  return -1;
978  }
979  return 0;
980 }
void error(int err, const char *fmt,...)
Definition: log.c:612
#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:475
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
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
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
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
int bb_resume ( void  )

Definition at line 898 of file bearerbox.c.

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

Referenced by httpd_resume().

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

Definition at line 832 of file bearerbox.c.

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

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

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

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

1098 {
1099  switch (status_type) {
1100  case BBSTATUS_HTML:
1101  return "<br>\n";
1102  case BBSTATUS_WML:
1103  return "<br/>\n";
1104  case BBSTATUS_TEXT:
1105  return "\n";
1106  case BBSTATUS_XML:
1107  return "\n";
1108  default:
1109  return NULL;
1110  }
1111 }
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
int bb_suspend ( void  )

Definition at line 880 of file bearerbox.c.

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

Referenced by httpd_suspend().

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

Definition at line 1489 of file bb_boxc.c.

References counter_destroy(), and octstr_destroy().

Referenced by main().

1490 {
1493  box_allow_ip = NULL;
1494  box_deny_ip = NULL;
1496  boxid = NULL;
1498  smsbox_interface = NULL;
1499 }
void counter_destroy(Counter *counter)
Definition: counter.c:110
static Octstr * box_deny_ip
Definition: bb_boxc.c:125
static Octstr * smsbox_interface
Definition: bb_boxc.c:117
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:322
static Counter * boxid
Definition: bb_boxc.c:128
static Octstr * box_allow_ip
Definition: bb_boxc.c:124
int boxc_incoming_wdp_queue ( void  )

Definition at line 1472 of file bb_boxc.c.

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

Referenced by bb_print_status().

1473 {
1474  int i, q = 0;
1475  Boxc *boxc;
1476 
1477  if (wapbox_list) {
1479  for(i=0; i < gwlist_len(wapbox_list); i++) {
1480  boxc = gwlist_get(wapbox_list, i);
1481  q += gwlist_len(boxc->incoming);
1482  }
1484  }
1485  return q;
1486 }
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
Definition: bb_boxc.c:134
void gwlist_lock(List *list)
Definition: list.c:347
static List * wapbox_list
Definition: bb_boxc.c:105
List * incoming
Definition: bb_boxc.c:141
Octstr* boxc_status ( int  status_type)

Definition at line 1348 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, and _boxc::sent.

Referenced by bb_print_status().

1349 {
1350  Octstr *tmp;
1351  char *lb, *ws;
1352  int i, boxes, para = 0;
1353  time_t orig, t;
1354  Boxc *bi;
1355 
1356  orig = time(NULL);
1357 
1358  /*
1359  * XXX: this will cause segmentation fault if this is called
1360  * between 'destroy_list and setting list to NULL calls.
1361  * Ok, this has to be fixed, but now I am too tired.
1362  */
1363 
1364  if ((lb = bb_status_linebreak(status_type))==NULL)
1365  return octstr_create("Un-supported format");
1366 
1367  if (status_type == BBSTATUS_HTML)
1368  ws = "&nbsp;&nbsp;&nbsp;&nbsp;";
1369  else if (status_type == BBSTATUS_TEXT)
1370  ws = " ";
1371  else
1372  ws = "";
1373 
1374  if (status_type == BBSTATUS_HTML || status_type == BBSTATUS_WML)
1375  para = 1;
1376 
1377  if (status_type == BBSTATUS_XML) {
1378  tmp = octstr_create ("");
1379  octstr_append_cstr(tmp, "<boxes>\n\t");
1380  }
1381  else
1382  tmp = octstr_format("%sBox connections:%s", para ? "<p>" : "", lb);
1383  boxes = 0;
1384 
1385  if (wapbox_list) {
1387  for(i=0; i < gwlist_len(wapbox_list); i++) {
1388  bi = gwlist_get(wapbox_list, i);
1389  if (bi->alive == 0)
1390  continue;
1391  t = orig - bi->connect_time;
1392  if (status_type == BBSTATUS_XML)
1394  "<box>\n\t\t<type>wapbox</type>\n\t\t<IP>%s</IP>\n"
1395  "\t\t<status>on-line %ldd %ldh %ldm %lds</status>\n"
1396  "\t\t<ssl>%s</ssl>\n\t</box>\n",
1398  t/3600/24, t/3600%24, t/60%60, t%60,
1399 #ifdef HAVE_LIBSSL
1400  conn_get_ssl(bi->conn) != NULL ? "yes" : "no"
1401 #else
1402  "not installed"
1403 #endif
1404  );
1405  else
1407  "%swapbox, IP %s (on-line %ldd %ldh %ldm %lds) %s %s",
1408  ws, octstr_get_cstr(bi->client_ip),
1409  t/3600/24, t/3600%24, t/60%60, t%60,
1410 #ifdef HAVE_LIBSSL
1411  conn_get_ssl(bi->conn) != NULL ? "using SSL" : "",
1412 #else
1413  "",
1414 #endif
1415  lb);
1416  boxes++;
1417  }
1419  }
1420  if (smsbox_list) {
1422  for(i=0; i < gwlist_len(smsbox_list); i++) {
1423  bi = gwlist_get(smsbox_list, i);
1424  if (bi->alive == 0)
1425  continue;
1426  t = orig - bi->connect_time;
1427  if (status_type == BBSTATUS_XML)
1428  octstr_format_append(tmp, "<box>\n\t\t<type>smsbox</type>\n"
1429  "\t\t<id>%s</id>\n\t\t<IP>%s</IP>\n"
1430  "\t\t<queue>%ld</queue>\n"
1431  "\t\t<status>on-line %ldd %ldh %ldm %lds</status>\n"
1432  "\t\t<ssl>%s</ssl>\n\t</box>",
1433  (bi->boxc_id ? octstr_get_cstr(bi->boxc_id) : ""),
1435  gwlist_len(bi->incoming) + dict_key_count(bi->sent),
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
1444  octstr_format_append(tmp, "%ssmsbox:%s, IP %s (%ld queued), (on-line %ldd %ldh %ldm %lds) %s %s",
1445  ws, (bi->boxc_id ? octstr_get_cstr(bi->boxc_id) : "(none)"),
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 (boxes == 0 && status_type != BBSTATUS_XML) {
1459  octstr_destroy(tmp);
1460  tmp = octstr_format("%sNo boxes connected", para ? "<p>" : "");
1461  }
1462  if (para)
1463  octstr_append_cstr(tmp, "</p>");
1464  if (status_type == BBSTATUS_XML)
1465  octstr_append_cstr(tmp, "</boxes>\n");
1466  else
1467  octstr_append_cstr(tmp, "\n\n");
1468  return tmp;
1469 }
Connection * conn
Definition: bb_boxc.c:135
char * bb_status_linebreak(int status_type)
Definition: bearerbox.c:1097
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:1509
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
volatile sig_atomic_t alive
Definition: bb_boxc.c:146
void gwlist_unlock(List *list)
Definition: list.c:354
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: bb_boxc.c:139
Octstr * boxc_id
Definition: bb_boxc.c:147
Octstr * octstr_format(const char *fmt,...)
Definition: octstr.c:2462
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:322
#define octstr_create(cstr)
Definition: octstr.h:125
Definition: bb_boxc.c:134
Dict * sent
Definition: bb_boxc.c:144
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:2505
static List * smsbox_list
Definition: bb_boxc.c:106
static List * wapbox_list
Definition: bb_boxc.c:105
Octstr * client_ip
Definition: bb_boxc.c:140
List * incoming
Definition: bb_boxc.c:141
int httpadmin_start ( Cfg config)

Definition at line 542 of file bb_http.c.

References cfg_get, cfg_get_bool(), cfg_get_integer(), cfg_get_single_group(), gwthread_create, ha_port, http_open_port_if(), httpadmin_run(), httpadmin_running, octstr_destroy(), octstr_imm(), panic, and ssl.

Referenced by init_bearerbox().

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

Definition at line 603 of file bb_http.c.

References gwthread_join_every(), http_close_all_ports(), httpadmin_run(), and octstr_destroy().

Referenced by main().

604 {
612  ha_password = NULL;
613  ha_status_pw = NULL;
614  ha_allow_ip = NULL;
615  ha_deny_ip = NULL;
616 }
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:322
static Octstr * ha_interface
Definition: bb_http.c:83
void http_close_all_ports(void)
Definition: http.c:2515
static void httpadmin_run(void *arg)
Definition: bb_http.c:510
int route_incoming_to_boxc ( Msg msg)

Definition at line 1511 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, _boxc::load, max_incoming_sms_qlength, octstr_destroy(), octstr_format(), octstr_get_cstr, octstr_len(), _boxc::routable, and warning().

Referenced by bb_smscconn_receive_internal(), and sms_to_smsboxes().

1512 {
1513  Boxc *bc = NULL;
1514  Octstr *s, *r, *rs, *boxc_id = NULL;
1515  long len, b, i;
1516  int full_found = 0;
1517 
1518  gw_assert(msg_type(msg) == sms);
1519 
1520  /* msg_dump(msg, 0); */
1521 
1522  /* Check we have at least one smsbox connected! */
1524  if (gwlist_len(smsbox_list) == 0) {
1526  warning(0, "smsbox_list empty!");
1527  if (max_incoming_sms_qlength < 0 || max_incoming_sms_qlength > gwlist_len(incoming_sms)) {
1529  return 0;
1530  } else {
1531  return -1;
1532  }
1533  }
1534 
1535  /*
1536  * Do we have a specific smsbox-id route to pass this msg to?
1537  */
1538  if (octstr_len(msg->sms.boxc_id) > 0) {
1539  boxc_id = msg->sms.boxc_id;
1540  } else {
1541  /*
1542  * Check if we have a "smsbox-route" for this msg.
1543  * Where the shortcode route has a higher priority then the smsc-id rule.
1544  * Highest priority has the combined <shortcode>:<smsc-id> route.
1545  */
1546  Octstr *os = octstr_format("%s:%s",
1547  octstr_get_cstr(msg->sms.receiver),
1548  octstr_get_cstr(msg->sms.smsc_id));
1549  s = (msg->sms.smsc_id ? dict_get(smsbox_by_smsc, msg->sms.smsc_id) : NULL);
1550  r = (msg->sms.receiver ? dict_get(smsbox_by_receiver, msg->sms.receiver) : NULL);
1551  rs = (os ? dict_get(smsbox_by_smsc_receiver, os) : NULL);
1552  octstr_destroy(os);
1553 
1554  if (rs)
1555  boxc_id = rs;
1556  else if (r)
1557  boxc_id = r;
1558  else if (s)
1559  boxc_id = s;
1560  }
1561 
1562  /* We have a specific smsbox-id to use */
1563  if (boxc_id != NULL) {
1564 
1565  List *boxc_id_list = dict_get(smsbox_by_id, boxc_id);
1566  if (gwlist_len(boxc_id_list) == 0) {
1567  /*
1568  * something is wrong, this was the smsbox connection we used
1569  * for sending, so it seems this smsbox is gone
1570  */
1571  warning(0, "Could not route message to smsbox id <%s>, smsbox is gone!",
1572  octstr_get_cstr(boxc_id));
1574  if (max_incoming_sms_qlength < 0 || max_incoming_sms_qlength > gwlist_len(incoming_sms)) {
1576  return 0;
1577  } else {
1578  return -1;
1579  }
1580  }
1581 
1582  /*
1583  * Take random smsbox from list, as long as it has space we will use it,
1584  * otherwise check the next one.
1585  */
1586  len = gwlist_len(boxc_id_list);
1587  b = gw_rand() % len;
1588 
1589  for (i = 0; i < len; i++) {
1590  bc = gwlist_get(boxc_id_list, (i+b) % len);
1591 
1592  if (bc != NULL && max_incoming_sms_qlength > 0 &&
1594  bc = NULL;
1595  }
1596 
1597  if (bc != NULL) {
1598  break;
1599  }
1600  }
1601 
1602  if (bc != NULL) {
1603  bc->load++;
1604  gwlist_produce(bc->incoming, msg);
1606  return 1; /* we are done */
1607  }
1608  else {
1609  /*
1610  * we have routing defined, but no smsbox connected at the moment.
1611  * put msg into global incoming queue and wait until smsbox with
1612  * such boxc_id connected.
1613  */
1615  if (max_incoming_sms_qlength < 0 || max_incoming_sms_qlength > gwlist_len(incoming_sms)) {
1617  return 0;
1618  } else {
1619  return -1;
1620  }
1621  }
1622  }
1623 
1624  /*
1625  * Ok, none of the specific routing things applied previously,
1626  * so route it to a random smsbox.
1627  * Take random smsbox from list, as long as it has space we will
1628  * use it, therwise check the next one.
1629  */
1630  len = gwlist_len(smsbox_list);
1631  b = gw_rand() % len;
1632 
1633  for (i = 0; i < len; i++) {
1634  bc = gwlist_get(smsbox_list, (i+b) % len);
1635 
1636  if (bc->boxc_id != NULL || bc->routable == 0)
1637  bc = NULL;
1638 
1639  if (bc != NULL && max_incoming_sms_qlength > 0 &&
1641  full_found = 1;
1642  bc = NULL;
1643  }
1644 
1645  if (bc != NULL) {
1646  break;
1647  }
1648  }
1649 
1650  if (bc != NULL) {
1651  bc->load++;
1652  gwlist_produce(bc->incoming, msg);
1653  }
1654 
1656 
1657  if (bc == NULL && full_found == 0) {
1658  warning(0, "smsbox_list empty!");
1659  if (max_incoming_sms_qlength < 0 || max_incoming_sms_qlength > gwlist_len(incoming_sms)) {
1661  return 0;
1662  } else {
1663  return -1;
1664  }
1665  } else if (bc == NULL && full_found == 1) {
1666  return -1;
1667  }
1668 
1669  return 1;
1670 }
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: bb_boxc.c:138
List * incoming_sms
Definition: bearerbox.c:84
int gw_rwlock_rdlock(RWLock *lock)
Definition: gw-rwlock.c:134
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
static Dict * smsbox_by_receiver
Definition: bb_boxc.c:112
long max_incoming_sms_qlength
Definition: bearerbox.c:98
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:624
Octstr * boxc_id
Definition: bb_boxc.c:147
Octstr * octstr_format(const char *fmt,...)
Definition: octstr.c:2462
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:322
Definition: bb_boxc.c:134
gw_assert(wtls_machine->packet_to_send!=NULL)
static Dict * smsbox_by_smsc_receiver
Definition: bb_boxc.c:113
long octstr_len(const Octstr *ostr)
Definition: octstr.c:340
Definition: octstr.c:118
static List * smsbox_list
Definition: bb_boxc.c:106
volatile int routable
Definition: bb_boxc.c:149
int gw_rand(void)
Definition: protected.c:174
Definition: list.c:102
List * incoming
Definition: bb_boxc.c:141
int smsbox_restart ( Cfg config)

Definition at line 1292 of file bb_boxc.c.

References smsbox_running.

1293 {
1294  if (!smsbox_running) return -1;
1295 
1296  /* send new config to clients */
1297 
1298  return 0;
1299 }
static volatile sig_atomic_t smsbox_running
Definition: bb_boxc.c:103
int smsbox_start ( Cfg config)

Definition at line 1227 of file bb_boxc.c.

References boxc_gwlist_destroy(), 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(), panic, sms_dequeue_thread, sms_to_smsboxes(), SMSBOX_MAX_PENDING, smsbox_max_pending, smsbox_port, smsbox_port_ssl, smsbox_running, and smsboxc_run().

Referenced by start_smsc().

1228 {
1229  CfgGroup *grp;
1230 
1231  if (smsbox_running) return -1;
1232 
1233  debug("bb", 0, "starting smsbox connection module");
1234 
1235  grp = cfg_get_single_group(cfg, octstr_imm("core"));
1236  if (cfg_get_integer(&smsbox_port, grp, octstr_imm("smsbox-port")) == -1) {
1237  error(0, "Missing smsbox-port variable, cannot start smsboxes");
1238  return -1;
1239  }
1240 #ifdef HAVE_LIBSSL
1241  cfg_get_bool(&smsbox_port_ssl, grp, octstr_imm("smsbox-port-ssl"));
1242 #endif /* HAVE_LIBSSL */
1243 
1244  if (smsbox_port_ssl)
1245  debug("bb", 0, "smsbox connection module is SSL-enabled");
1246 
1247  smsbox_interface = cfg_get(grp, octstr_imm("smsbox-interface"));
1248 
1249  if (cfg_get_integer(&smsbox_max_pending, grp, octstr_imm("smsbox-max-pending")) == -1) {
1251  info(0, "BOXC: 'smsbox-max-pending' not set, using default (%ld).", smsbox_max_pending);
1252  }
1253 
1254  box_allow_ip = cfg_get(grp, octstr_imm("box-allow-ip"));
1255  if (box_allow_ip == NULL)
1257  box_deny_ip = cfg_get(grp, octstr_imm("box-deny-ip"));
1258  if (box_deny_ip == NULL)
1259  box_deny_ip = octstr_create("");
1260  if (box_allow_ip != NULL && box_deny_ip == NULL)
1261  info(0, "Box connection allowed IPs defined without any denied...");
1262 
1263  smsbox_list = gwlist_create(); /* have a list of connections */
1265  if (!boxid)
1266  boxid = counter_create();
1267 
1268  /* the smsbox routing specific inits */
1269  smsbox_by_id = dict_create(10, (void(*)(void *)) boxc_gwlist_destroy);
1270  smsbox_by_smsc = dict_create(30, (void(*)(void *)) octstr_destroy);
1271  smsbox_by_receiver = dict_create(50, (void(*)(void *)) octstr_destroy);
1272  smsbox_by_smsc_receiver = dict_create(50, (void(*)(void *)) octstr_destroy);
1273 
1274  /* load the defined smsbox routing rules */
1276 
1279 
1280  smsbox_running = 1;
1281 
1282  if ((sms_dequeue_thread = gwthread_create(sms_to_smsboxes, NULL)) == -1)
1283  panic(0, "Failed to start a new thread for smsbox routing");
1284 
1285  if (gwthread_create(smsboxc_run, NULL) == -1)
1286  panic(0, "Failed to start a new thread for smsbox connections");
1287 
1288  return 0;
1289 }
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:612
void info(int err, const char *fmt,...)
Definition: log.c:636
static void sms_to_smsboxes(void *arg)
Definition: bb_boxc.c:1673
static Dict * smsbox_by_smsc
Definition: bb_boxc.c:111
static RWLock * smsbox_list_rwlock
Definition: bb_boxc.c:107
#define cfg_get(grp, varname)
Definition: cfg.h:86
static int smsbox_port_ssl
Definition: bb_boxc.c:116
RWLock * gw_rwlock_create(void)
Definition: gw-rwlock.c:77
static Octstr * box_deny_ip
Definition: bb_boxc.c:125
static Dict * smsbox_by_receiver
Definition: bb_boxc.c:112
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:281
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 void init_smsbox_routes(Cfg *cfg)
Definition: bb_boxc.c:1119
static Octstr * smsbox_interface
Definition: bb_boxc.c:117
static void smsboxc_run(void *arg)
Definition: bb_boxc.c:1017
static void boxc_gwlist_destroy(List *list)
Definition: bb_boxc.c:1746
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:322
#define gwthread_create(func, arg)
Definition: gwthread.h:90
#define octstr_create(cstr)
Definition: octstr.h:125
static long smsbox_max_pending
Definition: bb_boxc.c:122
static Dict * smsbox_by_smsc_receiver
Definition: bb_boxc.c:113
static Counter * boxid
Definition: bb_boxc.c:128
static Cfg * cfg
Definition: smsbox.c:115
int cfg_get_bool(int *n, CfgGroup *grp, Octstr *varname)
Definition: cfg.c:756
static long smsbox_port
Definition: bb_boxc.c:115
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:690
int cfg_get_integer(long *n, CfgGroup *grp, Octstr *varname)
Definition: cfg.c:739
#define panic
Definition: log.h:87
Definition: cfg.c:73
static Octstr * box_allow_ip
Definition: bb_boxc.c:124
static List * smsbox_list
Definition: bb_boxc.c:106
#define gwlist_create()
Definition: list.h:136
static long sms_dequeue_thread
Definition: bb_boxc.c:131
CfgGroup * cfg_get_single_group(Cfg *cfg, Octstr *name)
Definition: cfg.c:636
void gwlist_add_producer(List *list)
Definition: list.c:383
#define SMSBOX_MAX_PENDING
Definition: bb_boxc.c:83
int smsc2_add_smsc ( Octstr id)

Definition at line 1112 of file bb_smscconn.c.

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

Referenced by bb_add_smsc().

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

Definition at line 1306 of file bb_smscconn.c.

References black_list_receiver_regex, black_list_sender_regex, 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_running, smscconn_destroy(), white_list_receiver_regex, and white_list_sender_regex.

Referenced by main().

1307 {
1308  SMSCConn *conn;
1309  long i;
1310 
1311  if (!smsc_running)
1312  return;
1313 
1314  debug("smscconn", 0, "final clean-up for SMSCConn");
1315 
1317  for (i = 0; i < gwlist_len(smsc_list); i++) {
1318  conn = gwlist_get(smsc_list, i);
1319  smscconn_destroy(conn);
1320  }
1321  gwlist_destroy(smsc_list, NULL);
1322  smsc_list = NULL;
1324  gwlist_destroy(smsc_groups, NULL);
1330  if (white_list_sender_regex != NULL)
1331  gw_regex_destroy(white_list_sender_regex);
1332  if (black_list_sender_regex != NULL)
1333  gw_regex_destroy(black_list_sender_regex);
1338  if (white_list_receiver_regex != NULL)
1339  gw_regex_destroy(white_list_receiver_regex);
1340  if (black_list_receiver_regex != NULL)
1341  gw_regex_destroy(black_list_receiver_regex);
1342  /* destroy msg split counter */
1346 
1347  /* Stop concat handling */
1349 
1350  smsc_running = 0;
1351 }
static List * smsc_groups
Definition: bb_smscconn.c:131
int smscconn_destroy(SMSCConn *conn)
Definition: smscconn.c:406
void counter_destroy(Counter *counter)
Definition: counter.c:110
static regex_t * white_list_sender_regex
Definition: bb_smscconn.c:144
static RWLock smsc_list_lock
Definition: bb_smscconn.c:129
long gwlist_len(List *list)
Definition: list.c:166
void gw_rwlock_destroy(RWLock *lock)
Definition: gw-rwlock.c:112
int gw_rwlock_wrlock(RWLock *lock)
Definition: gw-rwlock.c:177
void * gwlist_get(List *list, long pos)
Definition: list.c:292
static regex_t * black_list_receiver_regex
Definition: bb_smscconn.c:147
void numhash_destroy(Numhash *table)
Definition: numhash.c:275
static RWLock white_black_list_lock
Definition: bb_smscconn.c:134
static Numhash * white_list_sender
Definition: bb_smscconn.c:140
static Octstr * black_list_receiver_url
Definition: bb_smscconn.c:137
static Numhash * black_list_sender
Definition: bb_smscconn.c:139
static void concat_handling_cleanup(void)
Definition: bb_smscconn.c:2039
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:322
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:690
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
int smsc2_graceful_restart ( void  )

Definition at line 1522 of file bb_smscconn.c.

References bb_reload_smsc_groups(), 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, router_thread, smsc_running, smscconn_create(), smscconn_destroy(), smscconn_instances(), smscconn_reconfig(), smscconn_shutdown(), and smscconn_start().

Referenced by bb_graceful_restart().

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

Definition at line 1166 of file bb_smscconn.c.

References error(), gw_rwlock_unlock(), gw_rwlock_wrlock(), numhash_create(), numhash_destroy(), and octstr_get_cstr.

Referenced by bb_reload_lists().

1167 {
1168  Numhash *tmp;
1169  int rc = 1;
1170 
1171  if (white_list_sender_url != NULL) {
1173  if (white_list_sender == NULL) {
1174  error(0, "Unable to reload white_list."),
1175  rc = -1;
1176  } else {
1179  white_list_sender = tmp;
1181  }
1182  }
1183 
1184  if (black_list_sender_url != NULL) {
1186  if (black_list_sender == NULL) {
1187  error(0, "Unable to reload black_list");
1188  rc = -1;
1189  } else {
1192  black_list_sender = tmp;
1194  }
1195  }
1196 
1197  if (white_list_receiver_url != NULL) {
1199  if (white_list_receiver == NULL) {
1200  error(0, "Unable to reload white_list."),
1201  rc = -1;
1202  } else {
1205  white_list_receiver = tmp;
1207  }
1208  }
1209 
1210  if (black_list_receiver_url != NULL) {
1212  if (black_list_receiver == NULL) {
1213  error(0, "Unable to reload black_list");
1214  rc = -1;
1215  } else {
1218  black_list_sender = tmp;
1220  }
1221  }
1222 
1223  return rc;
1224 }
void error(int err, const char *fmt,...)
Definition: log.c:612
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
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_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:612
int smscconn_destroy(SMSCConn *conn)
Definition: smscconn.c:406
void smscconn_shutdown(SMSCConn *conn, int finish_sending)
Definition: smscconn.c:378
static RWLock smsc_list_lock
Definition: bb_smscconn.c:129
int gw_rwlock_wrlock(RWLock *lock)
Definition: gw-rwlock.c:177
void * gwlist_get(List *list, long pos)
Definition: list.c:292
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
void gwlist_delete(List *list, long pos, long count)
Definition: list.c:232
void gwlist_remove_producer(List *list)
Definition: list.c:401
int gw_rwlock_unlock(RWLock *lock)
Definition: gw-rwlock.c:155
void gwlist_add_producer(List *list)
Definition: list.c:383
static volatile sig_atomic_t smsc_running
Definition: bb_smscconn.c:127
static List * smsc_list
Definition: bb_smscconn.c:128
static long smsc2_find(Octstr *id, long start)
Definition: bb_smscconn.c:948
int smsc2_restart ( Cfg config)
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_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:612
void info(int err, const char *fmt,...)
Definition: log.c:636
static List * smsc_groups
Definition: bb_smscconn.c:131
static long router_thread
Definition: bb_smscconn.c:149
int smscconn_destroy(SMSCConn *conn)
Definition: smscconn.c:406
static RWLock smsc_list_lock
Definition: bb_smscconn.c:129
long gwlist_len(List *list)
Definition: list.c:166
int gw_rwlock_wrlock(RWLock *lock)
Definition: gw-rwlock.c:177
void * gwlist_get(List *list, long pos)
Definition: list.c:292
#define cfg_get(grp, varname)
Definition: cfg.h:86
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:281
int smscconn_status(SMSCConn *conn)
Definition: smscconn.c:665
void gwlist_delete(List *list, long pos, long count)
Definition: list.c:232
int bb_reload_smsc_groups()
Definition: bb_smscconn.c:628
int gw_rwlock_unlock(RWLock *lock)
Definition: gw-rwlock.c:155
void warning(int err, const char *fmt,...)
Definition: log.c:624
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:322
void gwlist_insert(List *list, long pos, void *item)
Definition: list.c:214
Definition: octstr.c:118
void gwthread_wakeup(long thread)
Definition: cfg.c:73
SMSCConn * smscconn_create(CfgGroup *grp, int start_as_stopped)
Definition: smscconn.c:162
static volatile sig_atomic_t smsc_running
Definition: bb_smscconn.c:127
void smscconn_start(SMSCConn *conn)
Definition: smscconn.c:477
static List * smsc_list
Definition: bb_smscconn.c:128
int octstr_compare(const Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:869
static long smsc2_find(Octstr *id, long start)
Definition: bb_smscconn.c:948
void smsc2_resume ( int  is_init)

Definition at line 1226 of file bb_smscconn.c.

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

Referenced by bb_resume(), and main().

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

Definition at line 1710 of file bb_smscconn.c.

References BB_SHUTDOWN, bb_smscconn_send_failed(), bb_status, black_list_receiver_regex, 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_destroy(), msg_duplicate(), normalize_number(), numhash_find_number(), octstr_create, octstr_get_cstr, smsc_state::queued, SMS_PARAM_UNDEFINED, smsc2_rout(), split_parts::smsc_conn, 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, warning(), white_list_receiver_regex, and white_list_sender_regex.

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

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

Definition at line 1268 of file bb_smscconn.c.

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

Referenced by bb_shutdown().

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

Definition at line 806 of file bb_smscconn.c.

References black_list_receiver_regex, black_list_sender_regex, cfg_get, cfg_get_bool(), cfg_get_integer(), cfg_get_multi_group(), cfg_get_single_group(), 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, 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_running, smscconn_create(), smscconn_instances(), warning(), white_list_receiver_regex, and white_list_sender_regex.

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:636
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
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
List * incoming_sms
Definition: bearerbox.c:84
static RWLock white_black_list_lock
Definition: bb_smscconn.c:134
unsigned int smscconn_instances(CfgGroup *grp)
Definition: smscconn.c:149
Numhash * numhash_create(const char *seek_url)
Definition: numhash.c:313
static Numhash * white_list_sender
Definition: bb_smscconn.c:140
static Octstr * black_list_receiver_url
Definition: bb_smscconn.c:137
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:281
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:2016
List * cfg_get_multi_group(Cfg *cfg, Octstr *name)
Definition: cfg.c:642
static void sms_router(void *arg)
Definition: bb_smscconn.c:651
Counter * split_msg_counter
Definition: bb_smscconn.c:159
void warning(int err, const char *fmt,...)
Definition: log.c:624
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:322
#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 Cfg * cfg
Definition: smsbox.c:115
static Numhash * white_list_receiver
Definition: bb_smscconn.c:142
int cfg_get_bool(int *n, CfgGroup *grp, Octstr *varname)
Definition: cfg.c:756
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:739
#define panic
Definition: log.h:87
Definition: cfg.c:73
int smpp_pdu_init(Cfg *cfg)
Definition: smpp_pdu.c:150
#define gwlist_create()
Definition: list.h:136
SMSCConn * smscconn_create(CfgGroup *grp, int start_as_stopped)
Definition: smscconn.c:162
void gw_rwlock_init_static(RWLock *lock)
Definition: gw-rwlock.c:96
static Octstr * unified_prefix
Definition: bb_smscconn.c:132
static Octstr * black_list_sender_url
Definition: bb_smscconn.c:135
static Octstr * white_list_receiver_url
Definition: bb_smscconn.c:138
CfgGroup * cfg_get_single_group(Cfg *cfg, Octstr *name)
Definition: cfg.c:636
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
Octstr* smsc2_status ( int  status_type)

Definition at line 1354 of file bb_smscconn.c.

References bb_status_linebreak(), BBSTATUS_HTML, BBSTATUS_TEXT, BBSTATUS_WML, BBSTATUS_XML, smsc_state::failed, 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(), smsc_state::online, smscconn::outgoing_dlr_load, smscconn::outgoing_sms_load, smsc_state::queued, smsc_state::received, smsc_state::received_dlr, smsc_state::sent, smsc_state::sent_dlr, smsc_running, SMSCCONN_ACTIVE, SMSCCONN_ACTIVE_RECV, smscconn_admin_id(), SMSCCONN_CONNECTING, SMSCCONN_DEAD, SMSCCONN_DISCONNECTED, smscconn_id(), smscconn_info(), smscconn_name(), SMSCCONN_RECONNECTING, and smsc_state::status.

Referenced by bb_print_status().

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

Definition at line 1251 of file bb_smscconn.c.

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

Referenced by bb_isolate(), and bb_suspend().

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

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);
406  gwlist_produce(udpc->outgoing_list, msg);
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:322
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
Octstr * udp_get_ip(Octstr *addr)
Definition: socket.c:557
int octstr_compare(const Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:869
int udp_die ( void  )

Definition at line 434 of file bb_udp.c.

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

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:322
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:690
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
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, and udp_running.

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
int udp_shutdown ( void  )

Definition at line 424 of file bb_udp.c.

References debug(), gwlist_remove_producer(), 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:690
static volatile sig_atomic_t udp_running
Definition: bb_udp.c:96
int udp_start ( Cfg config)

Definition at line 323 of file bb_udp.c.

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

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:612
void info(int err, const char *fmt,...)
Definition: log.c:636
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
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:281
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:322
static int add_service(int port, char *interface_name)
Definition: bb_udp.c:292
static Octstr * allow_ip
Definition: bb_udp.c:111
static Cfg * cfg
Definition: smsbox.c:115
Definition: octstr.c:118
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:690
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:636
void gwlist_add_producer(List *list)
Definition: list.c:383
List * octstr_split(const Octstr *os, const Octstr *sep)
Definition: octstr.c:1638
Definition: list.c:102
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)
Definition: list.c:145
int wapbox_start ( Cfg config)

Definition at line 1305 of file bb_boxc.c.

References 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(), panic, wapbox_port, wapbox_port_ssl, wapbox_running, wapboxc_run(), and wdp_to_wapboxes().

Referenced by start_wap().

1306 {
1307  CfgGroup *grp;
1308 
1309  if (wapbox_running) return -1;
1310 
1311  debug("bb", 0, "starting wapbox connection module");
1312 
1313  grp = cfg_get_single_group(cfg, octstr_imm("core"));
1314 
1315  if (cfg_get_integer(&wapbox_port, grp, octstr_imm("wapbox-port")) == -1) {
1316  error(0, "Missing wapbox-port variable, cannot start WAP");
1317  return -1;
1318  }
1319 #ifdef HAVE_LIBSSL
1320  cfg_get_bool(&wapbox_port_ssl, grp, octstr_imm("wapbox-port-ssl"));
1321 #endif /* HAVE_LIBSSL */
1322 
1323  box_allow_ip = cfg_get(grp, octstr_imm("box-allow-ip"));
1324  if (box_allow_ip == NULL)
1326  box_deny_ip = cfg_get(grp, octstr_imm("box-deny-ip"));
1327  if (box_deny_ip == NULL)
1328  box_deny_ip = octstr_create("");
1329  if (box_allow_ip != NULL && box_deny_ip == NULL)
1330  info(0, "Box connection allowed IPs defined without any denied...");
1331 
1332  wapbox_list = gwlist_create(); /* have a list of connections */
1334  if (!boxid)
1335  boxid = counter_create();
1336 
1337  if (gwthread_create(wdp_to_wapboxes, NULL) == -1)
1338  panic(0, "Failed to start a new thread for wapbox routing");
1339 
1341  panic(0, "Failed to start a new thread for wapbox connections");
1342 
1343  wapbox_running = 1;
1344  return 0;
1345 }
void error(int err, const char *fmt,...)
Definition: log.c:612
void info(int err, const char *fmt,...)
Definition: log.c:636
List * outgoing_wdp
Definition: bearerbox.c:88
static int wapbox_port_ssl
Definition: bb_boxc.c:119
#define cfg_get(grp, varname)
Definition: cfg.h:86
static Octstr * box_deny_ip
Definition: bb_boxc.c:125
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:281
Counter * counter_create(void)
Definition: counter.c:94
static void wapboxc_run(void *arg)
Definition: bb_boxc.c:1074
#define gwthread_create(func, arg)
Definition: gwthread.h:90
#define octstr_create(cstr)
Definition: octstr.h:125
static Counter * boxid
Definition: bb_boxc.c:128
static Cfg * cfg
Definition: smsbox.c:115
int cfg_get_bool(int *n, CfgGroup *grp, Octstr *varname)
Definition: cfg.c:756
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:690
int cfg_get_integer(long *n, CfgGroup *grp, Octstr *varname)
Definition: cfg.c:739
#define panic
Definition: log.h:87
Definition: cfg.c:73
static Octstr * box_allow_ip
Definition: bb_boxc.c:124
static void wdp_to_wapboxes(void *arg)
Definition: bb_boxc.c:923
#define gwlist_create()
Definition: list.h:136
static List * wapbox_list
Definition: bb_boxc.c:105
CfgGroup * cfg_get_single_group(Cfg *cfg, Octstr *name)
Definition: cfg.c:636
void gwlist_add_producer(List *list)
Definition: list.c:383
static volatile sig_atomic_t wapbox_running
Definition: bb_boxc.c:104
static long wapbox_port
Definition: bb_boxc.c:118
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.