Kannel: Open Source WAP and SMS gateway  svn-r5335
bearerbox.c File Reference
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <string.h>
#include <signal.h>
#include <unistd.h>
#include "gwlib/gwlib.h"
#include "msg.h"
#include "bearerbox.h"
#include "shared.h"
#include "dlr.h"
#include "load.h"

Go to the source code of this file.

Macros

#define append_status(r, s, f, x)
 

Enumerations

enum  { BB_GRACEFUL_RESTART = 1, BB_CHECKLEAKS = 2, BB_LOGREOPEN = 3 }
 

Functions

static void set_shutdown_status (void)
 
static void signal_handler (int signum)
 
static void setup_signal_handlers (void)
 
static int start_smsc (Cfg *cfg)
 
static void wdp_router (void *arg)
 
static int start_wap (Cfg *cfg)
 
static int start_udp (Cfg *cfg)
 
static int check_config (Cfg *cfg)
 
static int check_args (int i, int argc, char **argv)
 
static Cfginit_bearerbox (Cfg *cfg)
 
static void empty_msg_lists (void)
 
static void dispatch_into_queue (Msg *msg)
 
int main (int argc, char **argv)
 
int bb_shutdown (void)
 
int bb_isolate (void)
 
int bb_suspend (void)
 
int bb_resume (void)
 
int bb_flush_dlr (void)
 
int bb_stop_smsc (Octstr *id)
 
int bb_restart_smsc (Octstr *id)
 
int bb_add_smsc (Octstr *id)
 
int bb_remove_smsc (Octstr *id)
 
int bb_restart (void)
 
int bb_graceful_restart (void)
 
int bb_reload_lists (void)
 
int bb_remove_message (Octstr *message_id)
 
Octstrbb_print_status (int status_type)
 
char * bb_status_linebreak (int status_type)
 

Variables

Listincoming_sms
 
Listoutgoing_sms
 
Listincoming_wdp
 
Listoutgoing_wdp
 
Counterincoming_sms_counter
 
Counteroutgoing_sms_counter
 
Counterincoming_dlr_counter
 
Counteroutgoing_dlr_counter
 
Counterincoming_wdp_counter
 
Counteroutgoing_wdp_counter
 
long max_incoming_sms_qlength
 
long max_outgoing_sms_qlength
 
Loadoutgoing_sms_load
 
Loadincoming_sms_load
 
Loadincoming_dlr_load
 
Loadoutgoing_dlr_load
 
Listflow_threads
 
Listsuspended
 
Listisolated
 
Octstrcfg_filename
 
volatile sig_atomic_t bb_status
 
static volatile sig_atomic_t bb_todo = 0
 
static Mutexstatus_mutex
 
static time_t start_time
 
volatile sig_atomic_t restart = 0
 

Macro Definition Documentation

◆ append_status

#define append_status (   r,
  s,
  f,
 
)
Value:
{ s = f(x); octstr_append(r, s); \
octstr_destroy(s); }
void octstr_append(Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:1504

Definition at line 995 of file bearerbox.c.

Referenced by bb_print_status().

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
BB_GRACEFUL_RESTART 
BB_CHECKLEAKS 
BB_LOGREOPEN 

Definition at line 137 of file bearerbox.c.

137  {
139  BB_CHECKLEAKS = 2,
140  BB_LOGREOPEN = 3
141 };

Function Documentation

◆ bb_add_smsc()

int bb_add_smsc ( Octstr id)

Definition at line 938 of file bearerbox.c.

References smsc2_add_smsc().

Referenced by httpd_add_smsc().

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

◆ bb_flush_dlr()

int bb_flush_dlr ( void  )

Definition at line 916 of file bearerbox.c.

References bb_status, BB_SUSPENDED, and dlr_flush().

Referenced by httpd_flush_dlr().

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

◆ bb_graceful_restart()

int bb_graceful_restart ( void  )

Definition at line 954 of file bearerbox.c.

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

Referenced by httpd_graceful_restart(), and main().

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

◆ bb_isolate()

int bb_isolate ( void  )

Definition at line 861 of file bearerbox.c.

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

Referenced by httpd_isolate().

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

◆ bb_print_status()

Octstr* bb_print_status ( int  status_type)

Definition at line 998 of file bearerbox.c.

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

Referenced by httpd_status().

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

◆ bb_reload_lists()

int bb_reload_lists ( void  )

Definition at line 971 of file bearerbox.c.

References smsc2_reload_lists().

Referenced by httpd_reload_lists().

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

◆ bb_remove_message()

int bb_remove_message ( Octstr message_id)

Definition at line 976 of file bearerbox.c.

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

Referenced by httpd_remove_message().

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

◆ bb_remove_smsc()

int bb_remove_smsc ( Octstr id)

Definition at line 943 of file bearerbox.c.

References smsc2_remove_smsc().

Referenced by httpd_remove_smsc().

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

◆ bb_restart()

int bb_restart ( void  )

Definition at line 948 of file bearerbox.c.

References bb_shutdown(), and restart.

Referenced by httpd_graceful_restart(), and httpd_restart().

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

◆ bb_restart_smsc()

int bb_restart_smsc ( Octstr id)

Definition at line 933 of file bearerbox.c.

References smsc2_restart_smsc().

Referenced by httpd_restart_smsc().

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

◆ bb_resume()

int bb_resume ( void  )

Definition at line 898 of file bearerbox.c.

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

Referenced by httpd_resume().

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

◆ bb_shutdown()

int bb_shutdown ( void  )

Definition at line 832 of file bearerbox.c.

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

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

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

◆ bb_status_linebreak()

char* bb_status_linebreak ( int  status_type)

Definition at line 1109 of file bearerbox.c.

References BBSTATUS_HTML, BBSTATUS_TEXT, BBSTATUS_WML, and BBSTATUS_XML.

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

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

◆ bb_stop_smsc()

int bb_stop_smsc ( Octstr id)

Definition at line 927 of file bearerbox.c.

References smsc2_stop_smsc().

Referenced by httpd_stop_smsc().

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

◆ bb_suspend()

int bb_suspend ( void  )

Definition at line 880 of file bearerbox.c.

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

Referenced by httpd_suspend().

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

◆ check_args()

static int check_args ( int  i,
int  argc,
char **  argv 
)
static

Definition at line 362 of file bearerbox.c.

References BB_ISOLATED, bb_status, and BB_SUSPENDED.

Referenced by main().

363 {
364  if (strcmp(argv[i], "-S")==0 || strcmp(argv[i], "--suspended")==0)
366  else if (strcmp(argv[i], "-I")==0 || strcmp(argv[i], "--isolated")==0)
368  else
369  return -1;
370 
371  return 0;
372 }
volatile sig_atomic_t bb_status
Definition: bearerbox.c:132

◆ check_config()

static int check_config ( Cfg cfg)
static

Definition at line 321 of file bearerbox.c.

References cfg, cfg_get_integer(), cfg_get_single_group(), error(), octstr_imm(), and warning().

Referenced by init_bearerbox().

322 {
323  CfgGroup *grp;
324  long smsp, wapp;
325 
326  grp = cfg_get_single_group(cfg, octstr_imm("core"));
327  if (grp == NULL)
328  return -1;
329 
330  if (cfg_get_integer(&smsp, grp, octstr_imm("smsbox-port")) == -1)
331  smsp = -1;
332  if (cfg_get_integer(&wapp, grp, octstr_imm("wapbox-port")) == -1)
333  wapp = -1;
334 
335 #ifndef NO_SMS
336  grp = cfg_get_single_group(cfg, octstr_imm("smsbox"));
337  if (smsp != -1 && grp == NULL) {
338  error(0, "No 'smsbox' group in configuration, but smsbox-port set");
339  return -1;
340  }
341 #else
342  warning(0, "Kannel was compiled without SMS support");
343 #endif
344 
345 #ifndef NO_WAP
346  grp = cfg_get_single_group(cfg, octstr_imm("wapbox"));
347  if (wapp != -1 && grp == NULL) {
348  error(0, "No 'wapbox' group in configuration, but wapbox-port set");
349  return -1;
350  }
351 #else
352  warning(0, "Kannel was compiled without WAP support");
353 #endif
354 
355  return 0;
356 }
void error(int err, const char *fmt,...)
Definition: log.c:648
static Cfg * cfg
Definition: opensmppbox.c:95
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:283
void warning(int err, const char *fmt,...)
Definition: log.c:660
int cfg_get_integer(long *n, CfgGroup *grp, Octstr *varname)
Definition: cfg.c:742
Definition: cfg.c:73
CfgGroup * cfg_get_single_group(Cfg *cfg, Octstr *name)
Definition: cfg.c:639

◆ dispatch_into_queue()

static void dispatch_into_queue ( Msg msg)
static

Definition at line 665 of file bearerbox.c.

References error(), gw_assert(), gwlist_append(), incoming_sms, mo, msg, msg_destroy(), mt_push, mt_reply, outgoing_sms, report_mo, report_mt, UUID_STR_LEN, and uuid_unparse().

Referenced by main().

666 {
667  char id[UUID_STR_LEN + 1];
668 
669  gw_assert(msg != NULL),
670  gw_assert(msg_type(msg) == sms);
671 
672  switch (msg->sms.sms_type) {
673  case mt_push:
674  case mt_reply:
675  case report_mt:
677  break;
678  case mo:
679  case report_mo:
681  break;
682  default:
683  uuid_unparse(msg->sms.id, id);
684  error(0, "Not handled sms_type %ld within store for message ID %s",
685  msg->sms.sms_type, id);
686  msg_destroy(msg);
687  break;
688  }
689 }
void error(int err, const char *fmt,...)
Definition: log.c:648
List * outgoing_sms
Definition: bearerbox.c:85
gw_assert(wtls_machine->packet_to_send !=NULL)
Definition: msg.h:106
void gwlist_append(List *list, void *item)
Definition: list.c:179
Definition: msg.h:109
msg_type
Definition: msg.h:73
void uuid_unparse(const uuid_t uu, char *out)
Definition: gw_uuid.c:562
Definition: msg.h:110
Definition: msg.h:108
List * incoming_sms
Definition: bearerbox.c:84
void msg_destroy(Msg *msg)
Definition: msg.c:132
#define UUID_STR_LEN
Definition: gw_uuid.h:19
Definition: msg.h:107
static XMLRPCDocument * msg
Definition: test_xmlrpc.c:86

◆ empty_msg_lists()

static void empty_msg_lists ( void  )
static

Definition at line 612 of file bearerbox.c.

References counter_destroy(), counter_value(), debug(), gwlist_destroy(), gwlist_extract_first(), gwlist_len(), incoming_dlr_counter, incoming_dlr_load, incoming_sms, incoming_sms_counter, incoming_sms_load, incoming_wdp, incoming_wdp_counter, info(), load_destroy(), msg, msg_destroy(), msg_destroy_item(), outgoing_dlr_counter, outgoing_dlr_load, outgoing_sms, outgoing_sms_counter, outgoing_sms_load, outgoing_wdp, outgoing_wdp_counter, and warning().

Referenced by main().

613 {
614  Msg *msg;
615 
616 #ifndef NO_WAP
618  warning(0, "Remaining WDP: %ld incoming, %ld outgoing",
620 
621  info(0, "Total WDP messages: received %ld, sent %ld",
624 #endif
625 
626  while ((msg = gwlist_extract_first(incoming_wdp)) != NULL)
627  msg_destroy(msg);
628  while ((msg = gwlist_extract_first(outgoing_wdp)) != NULL)
629  msg_destroy(msg);
630 
633 
636 
637 #ifndef NO_SMS
638  /* XXX we should record these so that they are not forever lost... */
640  debug("bb", 0, "Remaining SMS: %ld incoming, %ld outgoing",
642 
643  info(0, "Total SMS messages: received %ld, dlr %ld, sent %ld, dlr %ld",
648 #endif
649 
652 
657 
662 }
Counter * incoming_dlr_counter
Definition: bearerbox.c:92
void info(int err, const char *fmt,...)
Definition: log.c:672
Counter * incoming_wdp_counter
Definition: bearerbox.c:94
List * outgoing_sms
Definition: bearerbox.c:85
Load * outgoing_sms_load
Definition: bearerbox.c:102
void counter_destroy(Counter *counter)
Definition: counter.c:110
Load * incoming_sms_load
Definition: bearerbox.c:103
long gwlist_len(List *list)
Definition: list.c:166
List * incoming_wdp
Definition: bearerbox.c:87
void msg_destroy_item(void *msg)
Definition: msg.c:147
Definition: msg.h:79
void * gwlist_extract_first(List *list)
Definition: list.c:305
Load * incoming_dlr_load
Definition: bearerbox.c:104
List * incoming_sms
Definition: bearerbox.c:84
Counter * outgoing_sms_counter
Definition: bearerbox.c:91
void msg_destroy(Msg *msg)
Definition: msg.c:132
Load * outgoing_dlr_load
Definition: bearerbox.c:105
void warning(int err, const char *fmt,...)
Definition: log.c:660
Counter * incoming_sms_counter
Definition: bearerbox.c:90
unsigned long counter_value(Counter *counter)
Definition: counter.c:145
Counter * outgoing_dlr_counter
Definition: bearerbox.c:93
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:726
void load_destroy(Load *load)
Definition: load.c:145
List * outgoing_wdp
Definition: bearerbox.c:88
Counter * outgoing_wdp_counter
Definition: bearerbox.c:95
static XMLRPCDocument * msg
Definition: test_xmlrpc.c:86
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)
Definition: list.c:145

◆ init_bearerbox()

static Cfg* init_bearerbox ( Cfg cfg)
static

Definition at line 375 of file bearerbox.c.

References alog_open(), bb_alog_init(), cfg, cfg_get, cfg_get_bool(), cfg_get_integer(), cfg_get_list(), cfg_get_multi_group(), cfg_get_single_group(), check_config(), conn_config_ssl(), counter_create(), DEFAULT_OUTGOING_SMS_QLENGTH, GW_NON_EXCL, gwlist_create, gwlist_destroy(), http_set_client_timeout(), http_use_proxy(), httpadmin_start(), incoming_dlr_counter, incoming_dlr_load, incoming_sms, incoming_sms_counter, incoming_sms_load, incoming_wdp, incoming_wdp_counter, lf, load_add_interval(), load_create, log_open(), log_set_syslog(), log_set_syslog_facility(), max_incoming_sms_qlength, max_outgoing_sms_qlength, msg_pack(), msg_unpack_wrapper(), mutex_create, octstr_case_compare(), octstr_compare(), octstr_create, octstr_destroy(), octstr_destroy_item(), octstr_get_cstr, octstr_imm(), octstr_len(), octstr_parse_long(), outgoing_dlr_counter, outgoing_dlr_load, outgoing_sms, outgoing_sms_counter, outgoing_sms_load, outgoing_wdp, outgoing_wdp_counter, panic, setup_signal_handlers(), start_smsc(), start_udp(), start_wap(), status_mutex, store_init(), and warning().

Referenced by main().

376 {
377  CfgGroup *grp;
378  Octstr *log, *val;
379  long loglevel, store_dump_freq, value;
380  int lf, m;
381 #ifdef HAVE_LIBSSL
382  Octstr *ssl_server_cert_file;
383  Octstr *ssl_server_key_file;
384  int ssl_enabled = 0;
385 #endif /* HAVE_LIBSSL */
386  Octstr *http_proxy_host = NULL;
387  long http_proxy_port = -1;
388  int http_proxy_ssl = 0;
389  List *http_proxy_exceptions = NULL;
390  Octstr *http_proxy_username = NULL;
391  Octstr *http_proxy_password = NULL;
392  Octstr *http_proxy_exceptions_regex = NULL;
393 
394  /* defaults: use localtime and markers for access-log */
395  lf = m = 1;
396 
397  grp = cfg_get_single_group(cfg, octstr_imm("core"));
398 
399  log = cfg_get(grp, octstr_imm("log-file"));
400  if (log != NULL) {
401  if (cfg_get_integer(&loglevel, grp, octstr_imm("log-level")) == -1)
402  loglevel = 0;
403  log_open(octstr_get_cstr(log), loglevel, GW_NON_EXCL);
404  octstr_destroy(log);
405  }
406  if ((val = cfg_get(grp, octstr_imm("syslog-level"))) != NULL) {
407  long level;
408  Octstr *facility;
409  if ((facility = cfg_get(grp, octstr_imm("syslog-facility"))) != NULL) {
411  octstr_destroy(facility);
412  }
413  if (octstr_compare(val, octstr_imm("none")) == 0) {
414  log_set_syslog(NULL, 0);
415  } else if (octstr_parse_long(&level, val, 0, 10) > 0) {
416  log_set_syslog("bearerbox", level);
417  }
418  octstr_destroy(val);
419  } else {
420  log_set_syslog(NULL, 0);
421  }
422 
423  if (check_config(cfg) == -1)
424  panic(0, "Cannot start with corrupted configuration");
425 
426  /* determine which timezone we use for access logging */
427  if ((log = cfg_get(grp, octstr_imm("access-log-time"))) != NULL) {
428  lf = (octstr_case_compare(log, octstr_imm("gmt")) == 0) ? 0 : 1;
429  octstr_destroy(log);
430  }
431 
432  /* should predefined markers be used, ie. prefixing timestamp */
433  cfg_get_bool(&m, grp, octstr_imm("access-log-clean"));
434 
435  /* custom access-log format */
436  if ((log = cfg_get(grp, octstr_imm("access-log-format"))) != NULL) {
437  bb_alog_init(log);
438  octstr_destroy(log);
439  }
440 
441  /* open access-log file */
442  if ((log = cfg_get(grp, octstr_imm("access-log"))) != NULL) {
443  alog_open(octstr_get_cstr(log), lf, m ? 0 : 1);
444  octstr_destroy(log);
445  }
446 
447  if (cfg_get_integer(&store_dump_freq, grp,
448  octstr_imm("store-dump-freq")) == -1)
449  store_dump_freq = -1;
450 
451  log = cfg_get(grp, octstr_imm("store-file"));
452  /* initialize the store file */
453  if (log != NULL) {
454  warning(0, "'store-file' option deprecated, please use 'store-location' and 'store-type' instead.");
455  val = octstr_create("file");
456  } else {
457  log = cfg_get(grp, octstr_imm("store-location"));
458  val = cfg_get(grp, octstr_imm("store-type"));
459  }
460  if (store_init(cfg, val, log, store_dump_freq, msg_pack, msg_unpack_wrapper) == -1)
461  panic(0, "Could not start with store init failed.");
462  octstr_destroy(val);
463  octstr_destroy(log);
464 
465  cfg_get_integer(&http_proxy_port, grp, octstr_imm("http-proxy-port"));
466 #ifdef HAVE_LIBSSL
467  cfg_get_bool(&http_proxy_ssl, grp, octstr_imm("http-proxy-ssl"));
468 #endif /* HAVE_LIBSSL */
469 
470  http_proxy_host = cfg_get(grp,
471  octstr_imm("http-proxy-host"));
472  http_proxy_username = cfg_get(grp,
473  octstr_imm("http-proxy-username"));
474  http_proxy_password = cfg_get(grp,
475  octstr_imm("http-proxy-password"));
476  http_proxy_exceptions = cfg_get_list(grp,
477  octstr_imm("http-proxy-exceptions"));
478  http_proxy_exceptions_regex = cfg_get(grp,
479  octstr_imm("http-proxy-exceptions-regex"));
480 
481  conn_config_ssl (grp);
482 
483  /*
484  * Make sure we have "ssl-server-cert-file" and "ssl-server-key-file" specified
485  * in the core group since we need it to run SSL-enabled internal box
486  * connections configured via "smsbox-port-ssl = yes" and "wapbox-port-ssl = yes".
487  * Check only these, because for "admin-port-ssl" and "sendsms-port-ssl" for the
488  * SSL-enabled HTTP servers are probed within gw/bb_http.c:httpadmin_start()
489  */
490 #ifdef HAVE_LIBSSL
491  ssl_server_cert_file = cfg_get(grp, octstr_imm("ssl-server-cert-file"));
492  ssl_server_key_file = cfg_get(grp, octstr_imm("ssl-server-key-file"));
493  if (ssl_server_cert_file != NULL && ssl_server_key_file != NULL) {
494  /* we are fine, at least files are specified in the configuration */
495  } else {
496  cfg_get_bool(&ssl_enabled, grp, octstr_imm("smsbox-port-ssl"));
497  cfg_get_bool(&ssl_enabled, grp, octstr_imm("wapbox-port-ssl"));
498  if (ssl_enabled) {
499  panic(0, "You MUST specify cert and key files within core group for SSL-enabled inter-box connections!");
500  }
501  }
502  octstr_destroy(ssl_server_cert_file);
503  octstr_destroy(ssl_server_key_file);
504 #endif /* HAVE_LIBSSL */
505 
506  /* if all seems to be OK by the first glimpse, real start-up */
507 
512 
519 
521 
523  /* add 60,300,-1 entries */
528  /* add 60,300,-1 entries */
533  /* add 60,300,-1 entries to dlr */
538  /* add 60,300,-1 entries to dlr */
542 
544 
545  /* http-admin is REQUIRED */
547 
549  octstr_imm("maximum-queue-length")) == -1)
551  else {
552  warning(0, "Option 'maximum-queue-length' is deprecated! Please use"
553  " 'sms-incoming-queue-limit' instead!");
554  }
555 
556  if (max_incoming_sms_qlength == -1 &&
558  octstr_imm("sms-incoming-queue-limit")) == -1)
560 
562  octstr_imm("sms-outgoing-queue-limit")) == -1)
564 
565  if (max_outgoing_sms_qlength < 0)
567 
568  if (cfg_get_integer(&value, grp, octstr_imm("http-timeout")) == 0)
570 #ifndef NO_SMS
571  {
572  List *list;
573 
574  list = cfg_get_multi_group(cfg, octstr_imm("smsc"));
575  if (list != NULL) {
576  gwlist_destroy(list, NULL);
577  if (start_smsc(cfg) == -1) {
578  panic(0, "Unable to start SMSCs.");
579  return NULL;
580  }
581  }
582  }
583 #endif
584 
585 #ifndef NO_WAP
586  grp = cfg_get_single_group(cfg, octstr_imm("core"));
587  val = cfg_get(grp, octstr_imm("wdp-interface-name"));
588  if (val != NULL && octstr_len(val) > 0)
589  start_udp(cfg);
590  octstr_destroy(val);
591 
592  if (cfg_get_single_group(cfg, octstr_imm("wapbox")) != NULL)
593  start_wap(cfg);
594 #endif
595 
596  if (http_proxy_host != NULL && http_proxy_port > 0) {
597  http_use_proxy(http_proxy_host, http_proxy_port, http_proxy_ssl,
598  http_proxy_exceptions, http_proxy_username,
599  http_proxy_password, http_proxy_exceptions_regex);
600  }
601 
602  octstr_destroy(http_proxy_host);
603  octstr_destroy(http_proxy_username);
604  octstr_destroy(http_proxy_password);
605  octstr_destroy(http_proxy_exceptions_regex);
606  gwlist_destroy(http_proxy_exceptions, octstr_destroy_item);
607 
608  return cfg;
609 }
Counter * incoming_dlr_counter
Definition: bearerbox.c:92
int httpadmin_start(Cfg *cfg)
Definition: bb_http.c:557
static int start_wap(Cfg *cfg)
Definition: bearerbox.c:285
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
static int check_config(Cfg *cfg)
Definition: bearerbox.c:321
List * cfg_get_list(CfgGroup *grp, Octstr *varname)
Definition: cfg.c:790
#define mutex_create()
Definition: thread.h:96
List * incoming_wdp
Definition: bearerbox.c:87
Msg * msg_unpack_wrapper(Octstr *os)
Definition: msg.c:256
int load_add_interval(Load *load, int interval)
Definition: load.c:111
#define cfg_get(grp, varname)
Definition: cfg.h:86
static Mutex * status_mutex
Definition: bearerbox.c:147
static Cfg * cfg
Definition: opensmppbox.c:95
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
void bb_alog_init(const Octstr *format)
Definition: bb_alog.c:359
long max_outgoing_sms_qlength
Definition: bearerbox.c:99
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:283
#define DEFAULT_OUTGOING_SMS_QLENGTH
Definition: bearerbox.h:69
Counter * counter_create(void)
Definition: counter.c:94
Load * incoming_dlr_load
Definition: bearerbox.c:104
void conn_config_ssl(CfgGroup *grp)
Definition: conn.c:1546
long max_incoming_sms_qlength
Definition: bearerbox.c:98
List * incoming_sms
Definition: bearerbox.c:84
int store_init(Cfg *cfg, const Octstr *type, const Octstr *fname, long dump_freq, void *pack_func, void *unpack_func)
Definition: bb_store.c:82
List * cfg_get_multi_group(Cfg *cfg, Octstr *name)
Definition: cfg.c:645
Counter * outgoing_sms_counter
Definition: bearerbox.c:91
static int start_smsc(Cfg *cfg)
Definition: bearerbox.c:235
int octstr_case_compare(const Octstr *os1, const Octstr *os2)
Definition: octstr.c:903
Load * outgoing_dlr_load
Definition: bearerbox.c:105
void warning(int err, const char *fmt,...)
Definition: log.c:660
void log_set_syslog_facility(char *facility)
Definition: log.c:278
void alog_open(char *fname, int use_localtm, int use_markers)
Definition: accesslog.c:129
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
Counter * incoming_sms_counter
Definition: bearerbox.c:90
#define octstr_create(cstr)
Definition: octstr.h:125
void octstr_destroy_item(void *os)
Definition: octstr.c:336
#define load_create()
Definition: load.h:78
void log_set_syslog(const char *ident, int syslog_level)
Definition: log.c:284
Counter * outgoing_dlr_counter
Definition: bearerbox.c:93
int log_open(char *filename, int level, enum excl_state excl)
Definition: log.c:375
long octstr_len(const Octstr *ostr)
Definition: octstr.c:342
int cfg_get_bool(int *n, CfgGroup *grp, Octstr *varname)
Definition: cfg.c:759
Definition: octstr.c:118
void http_use_proxy(Octstr *hostname, int port, int ssl, List *exceptions, Octstr *username, Octstr *password, Octstr *exceptions_regex)
Definition: http.c:268
int cfg_get_integer(long *n, CfgGroup *grp, Octstr *varname)
Definition: cfg.c:742
static void setup_signal_handlers(void)
Definition: bearerbox.c:212
#define panic
Definition: log.h:87
Definition: cfg.c:73
long octstr_parse_long(long *nump, Octstr *ostr, long pos, int base)
Definition: octstr.c:749
Octstr * msg_pack(Msg *msg)
Definition: msg.c:181
#define gwlist_create()
Definition: list.h:136
List * outgoing_wdp
Definition: bearerbox.c:88
Counter * outgoing_wdp_counter
Definition: bearerbox.c:95
CfgGroup * cfg_get_single_group(Cfg *cfg, Octstr *name)
Definition: cfg.c:639
void http_set_client_timeout(long timeout)
Definition: http.c:1751
Definition: list.c:102
static Octstr * lf
Definition: smsc_smasi.c:222
static int start_udp(Cfg *cfg)
Definition: bearerbox.c:303
int octstr_compare(const Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:871
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)
Definition: list.c:145

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 692 of file bearerbox.c.

References alog_close(), alog_reopen(), bb_alog_shutdown(), BB_CHECKLEAKS, BB_DEAD, BB_GRACEFUL_RESTART, bb_graceful_restart(), BB_ISOLATED, BB_LOGREOPEN, BB_RUNNING, BB_SHUTDOWN, bb_shutdown(), bb_status, BB_SUSPENDED, bb_todo, boxc_cleanup(), cfg, cfg_create(), cfg_destroy(), cfg_filename, cfg_read(), check_args(), dispatch_into_queue(), dlr_init(), dlr_shutdown(), empty_msg_lists(), flow_threads, get_and_set_debugs(), gwlib_init(), gwlib_shutdown(), gwlist_add_producer(), gwlist_consume(), gwlist_create, gwlist_destroy(), gwlist_producer_count(), gwlist_remove_producer(), gwthread_sleep(), gwthread_wakeup_all(), httpadmin_stop(), info(), init_bearerbox(), isolated, log_reopen(), mutex_destroy(), octstr_create, octstr_destroy(), octstr_get_cstr, panic, report_versions(), restart, restart_box(), smsc2_cleanup(), smsc2_resume(), start_time, status_mutex, store_load, store_shutdown, suspended, and warning().

693 {
694  int cf_index;
695  Cfg *cfg;
696 
698 
699  gwlib_init();
700  start_time = time(NULL);
701 
706 
707  cf_index = get_and_set_debugs(argc, argv, check_args);
708 
709  if (argv[cf_index] == NULL)
710  cfg_filename = octstr_create("kannel.conf");
711  else
712  cfg_filename = octstr_create(argv[cf_index]);
714 
715  if (cfg_read(cfg) == -1)
716  panic(0, "Couldn't read configuration from `%s'.", octstr_get_cstr(cfg_filename));
717 
718  dlr_init(cfg);
719 
720  report_versions("bearerbox");
721 
723 
724  if (init_bearerbox(cfg) == NULL)
725  panic(0, "Initialization failed.");
726 
727  info(0, "----------------------------------------");
728  info(0, GW_NAME " bearerbox II version %s starting", GW_VERSION);
729 
730  gwthread_sleep(5.0); /* give time to threads to register themselves */
731 
732  if (store_load(dispatch_into_queue) == -1)
733  panic(0, "Cannot start with store-file failing");
734 
735  info(0, "MAIN: Start-up done, entering mainloop");
736  if (bb_status == BB_SUSPENDED) {
737  info(0, "Gateway is now SUSPENDED by startup arguments");
738  } else if (bb_status == BB_ISOLATED) {
739  info(0, "Gateway is now ISOLATED by startup arguments");
741  } else {
742  smsc2_resume(1);
745  }
746 
747  while (bb_status != BB_SHUTDOWN && bb_status != BB_DEAD &&
749  /* debug("bb", 0, "Main Thread: going to sleep."); */
750  /*
751  * Not infinite sleep here, because we should notice
752  * when all "flow threads" are dead and shutting bearerbox
753  * down.
754  * XXX if all "flow threads" call gwthread_wakeup(MAIN_THREAD_ID),
755  * we can enter infinite sleep then.
756  */
757  gwthread_sleep(10.0);
758  /* debug("bb", 0, "Main Thread: woken up."); */
759 
760  if (bb_todo == 0) {
761  continue;
762  }
763 
765  warning(0, "SIGHUP received, re-opening logs and gracefully restarting.");
766  log_reopen();
767  alog_reopen();
770  }
771 
772  if (bb_todo & BB_LOGREOPEN) {
773  warning(0, "SIGUSR2 received, re-opening logs.");
774  log_reopen();
775  alog_reopen();
777  }
778 
779  if (bb_todo & BB_CHECKLEAKS) {
780  warning(0, "SIGQUIT received, reporting memory usage.");
781  gw_check_leaks();
783  }
784  }
785 
786  if (bb_status == BB_SHUTDOWN || bb_status == BB_DEAD)
787  warning(0, "Killing signal or HTTP admin command received, shutting down...");
788 
789  /* call shutdown */
790  bb_shutdown();
791 
792  /* wake up any sleeping threads */
794 
795  /* wait until flow threads exit */
796  while (gwlist_consume(flow_threads) != NULL)
797  ;
798 
799  info(0, "All flow threads have died, killing core");
800  bb_status = BB_DEAD;
801  httpadmin_stop();
802 
803  boxc_cleanup();
804  smsc2_cleanup();
805  store_shutdown();
806  empty_msg_lists();
808  gwlist_destroy(suspended, NULL);
809  gwlist_destroy(isolated, NULL);
811 
812  alog_close(); /* if we have any */
814  cfg_destroy(cfg);
816  dlr_shutdown();
817 
818  /* now really restart */
819  if (restart)
820  restart_box(argv);
821 
822  gwlib_shutdown();
823 
824  return 0;
825 }
volatile sig_atomic_t bb_status
Definition: bearerbox.c:132
void info(int err, const char *fmt,...)
Definition: log.c:672
static void dispatch_into_queue(Msg *msg)
Definition: bearerbox.c:665
List * suspended
Definition: bearerbox.c:122
void smsc2_cleanup(void)
Definition: bb_smscconn.c:1314
void log_reopen(void)
Definition: log.c:297
static void empty_msg_lists(void)
Definition: bearerbox.c:612
static int check_args(int i, int argc, char **argv)
Definition: bearerbox.c:362
int restart_box(char **argv)
Definition: shared.c:279
static Mutex * status_mutex
Definition: bearerbox.c:147
static volatile sig_atomic_t bb_todo
Definition: bearerbox.c:143
static Cfg * cfg
Definition: opensmppbox.c:95
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
static time_t start_time
Definition: bearerbox.c:148
Cfg * cfg_create(Octstr *filename)
Definition: cfg.c:318
int cfg_read(Cfg *cfg)
Definition: cfg.c:452
List * isolated
Definition: bearerbox.c:127
void bb_alog_shutdown(void)
Definition: bb_alog.c:367
Definition: cfg.c:164
void cfg_destroy(Cfg *cfg)
Definition: cfg.c:331
void gwlist_remove_producer(List *list)
Definition: list.c:401
void httpadmin_stop(void)
Definition: bb_http.c:618
void warning(int err, const char *fmt,...)
Definition: log.c:660
int bb_graceful_restart(void)
Definition: bearerbox.c:954
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
volatile sig_atomic_t restart
Definition: bearerbox.c:149
#define octstr_create(cstr)
Definition: octstr.h:125
void gwthread_sleep(double seconds)
void mutex_destroy(Mutex *mutex)
Definition: thread.c:97
void boxc_cleanup(void)
Definition: bb_boxc.c:1527
void alog_reopen(void)
Definition: accesslog.c:85
void(* store_shutdown)(void)
Definition: bb_store.c:76
void report_versions(const char *boxname)
Definition: utils.c:539
void dlr_init(Cfg *cfg)
Definition: dlr.c:233
int bb_shutdown(void)
Definition: bearerbox.c:832
void * gwlist_consume(List *list)
Definition: list.c:427
Octstr * cfg_filename
Definition: bearerbox.c:130
#define panic
Definition: log.h:87
int(* store_load)(void(*receive_msg)(Msg *))
Definition: bb_store.c:74
List * flow_threads
Definition: bearerbox.c:116
void alog_close(void)
Definition: accesslog.c:111
void gwlib_shutdown(void)
Definition: gwlib.c:94
#define gwlist_create()
Definition: list.h:136
void gwlib_init(void)
Definition: gwlib.c:78
void smsc2_resume(int is_init)
Definition: bb_smscconn.c:1234
void gwlist_add_producer(List *list)
Definition: list.c:383
int get_and_set_debugs(int argc, char **argv, int(*find_own)(int index, int argc, char **argv))
Definition: utils.c:626
void gwthread_wakeup_all(void)
void dlr_shutdown()
Definition: dlr.c:299
static Cfg * init_bearerbox(Cfg *cfg)
Definition: bearerbox.c:375
int gwlist_producer_count(List *list)
Definition: list.c:391
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)
Definition: list.c:145

◆ set_shutdown_status()

static void set_shutdown_status ( void  )
static

Definition at line 154 of file bearerbox.c.

References BB_ISOLATED, BB_SHUTDOWN, bb_status, BB_SUSPENDED, gwlist_remove_producer(), isolated, and suspended.

Referenced by bb_shutdown().

155 {
156  sig_atomic_t old = bb_status;
158 
159  if (old == BB_SUSPENDED)
161  if (old == BB_SUSPENDED || old == BB_ISOLATED)
163 }
volatile sig_atomic_t bb_status
Definition: bearerbox.c:132
List * suspended
Definition: bearerbox.c:122
List * isolated
Definition: bearerbox.c:127
void gwlist_remove_producer(List *list)
Definition: list.c:401

◆ setup_signal_handlers()

static void setup_signal_handlers ( void  )
static

Definition at line 212 of file bearerbox.c.

References signal_handler().

Referenced by init_bearerbox().

213 {
214  struct sigaction act;
215 
216  act.sa_handler = signal_handler;
217  sigemptyset(&act.sa_mask);
218  act.sa_flags = 0;
219  sigaction(SIGINT, &act, NULL);
220  sigaction(SIGTERM, &act, NULL);
221  sigaction(SIGQUIT, &act, NULL);
222  sigaction(SIGHUP, &act, NULL);
223  sigaction(SIGPIPE, &act, NULL);
224  sigaction(SIGUSR2, &act, NULL);
225 }
static void signal_handler(int signum)
Definition: bearerbox.c:170

◆ signal_handler()

static void signal_handler ( int  signum)
static

Definition at line 170 of file bearerbox.c.

References BB_CHECKLEAKS, BB_DEAD, BB_GRACEFUL_RESTART, BB_LOGREOPEN, BB_SHUTDOWN, bb_status, bb_todo, gwthread_shouldhandlesignal(), and panic.

Referenced by setup_signal_handlers().

171 {
172  /* On some implementations (i.e. linuxthreads), signals are delivered
173  * to all threads. We only want to handle each signal once for the
174  * entire box, and we let the gwthread wrapper take care of choosing
175  * one.
176  */
177  if (!gwthread_shouldhandlesignal(signum))
178  return;
179 
180  switch (signum) {
181  case SIGINT:
182  case SIGTERM:
183  if (bb_status != BB_SHUTDOWN && bb_status != BB_DEAD) {
185  }
186  else if (bb_status == BB_SHUTDOWN) {
187  bb_status = BB_DEAD;
188  }
189  else if (bb_status == BB_DEAD) {
190  panic(0, "Cannot die by its own will");
191  }
192  break;
193 
194  case SIGHUP:
196  break;
197 
198  case SIGUSR2:
200  break;
201 
202  /*
203  * It would be more proper to use SIGUSR1 for this, but on some
204  * platforms that's reserved by the pthread support.
205  */
206  case SIGQUIT:
208  break;
209  }
210 }
volatile sig_atomic_t bb_status
Definition: bearerbox.c:132
static volatile sig_atomic_t bb_todo
Definition: bearerbox.c:143
int gwthread_shouldhandlesignal(int signal)
#define panic
Definition: log.h:87

◆ start_smsc()

static int start_smsc ( Cfg cfg)
static

Definition at line 235 of file bearerbox.c.

References cfg, error(), smsbox_start(), and smsc2_start().

Referenced by init_bearerbox().

236 {
237  static int started = 0;
238 
239  if (started)
240  return 0;
241 
242  if (smsbox_start(cfg) == -1) {
243  error(0, "Unable to start smsbox module.");
244  return -1;
245  }
246 
247  if (smsc2_start(cfg) == -1) {
248  error(0, "Unable to start smsc module.");
249  return -1;
250  }
251 
252  started = 1;
253  return 0;
254 }
void error(int err, const char *fmt,...)
Definition: log.c:648
static Cfg * cfg
Definition: opensmppbox.c:95
int smsbox_start(Cfg *cfg)
Definition: bb_boxc.c:1250
int smsc2_start(Cfg *cfg)
Definition: bb_smscconn.c:806

◆ start_udp()

static int start_udp ( Cfg cfg)
static

Definition at line 303 of file bearerbox.c.

References cfg, start_wap(), and udp_start().

Referenced by init_bearerbox().

304 {
305  static int started = 0;
306 
307  if (started)
308  return 0;
309 
310  udp_start(cfg);
311 
312  start_wap(cfg);
313  started = 1;
314  return 0;
315 }
static int start_wap(Cfg *cfg)
Definition: bearerbox.c:285
static Cfg * cfg
Definition: opensmppbox.c:95
int udp_start(Cfg *cfg)
Definition: bb_udp.c:323

◆ start_wap()

static int start_wap ( Cfg cfg)
static

Definition at line 285 of file bearerbox.c.

References cfg, debug(), gwthread_create, panic, wapbox_start(), and wdp_router().

Referenced by init_bearerbox(), and start_udp().

286 {
287  static int started = 0;
288 
289  if (started)
290  return 0;
291 
292  wapbox_start(cfg);
293 
294  debug("bb", 0, "starting WDP router");
295  if (gwthread_create(wdp_router, NULL) == -1)
296  panic(0, "Failed to start a new thread for WDP routing");
297 
298  started = 1;
299  return 0;
300 }
static void wdp_router(void *arg)
Definition: bearerbox.c:257
static Cfg * cfg
Definition: opensmppbox.c:95
#define gwthread_create(func, arg)
Definition: gwthread.h:90
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:726
int wapbox_start(Cfg *cfg)
Definition: bb_boxc.c:1339
#define panic
Definition: log.h:87

◆ wdp_router()

static void wdp_router ( void *  arg)
static

Definition at line 257 of file bearerbox.c.

References BB_DEAD, bb_status, flow_threads, gw_assert(), gwlist_add_producer(), gwlist_consume(), gwlist_remove_producer(), msg, outgoing_wdp, udp_addwdp(), and udp_die().

Referenced by start_wap().

258 {
259  Msg *msg;
260 
262 
263  while (bb_status != BB_DEAD) {
264 
265  if ((msg = gwlist_consume(outgoing_wdp)) == NULL)
266  break;
267 
268  gw_assert(msg_type(msg) == wdp_datagram);
269 
270  /*
271  if (msg->list == sms)
272  smsc_addwdp(msg);
273  else
274  */
275 
276  udp_addwdp(msg);
277  }
278  udp_die();
279  /* smsc_endwdp(); */
280 
282 }
volatile sig_atomic_t bb_status
Definition: bearerbox.c:132
gw_assert(wtls_machine->packet_to_send !=NULL)
int udp_addwdp(Msg *msg)
Definition: bb_udp.c:385
msg_type
Definition: msg.h:73
int udp_die(void)
Definition: bb_udp.c:434
Definition: msg.h:79
void gwlist_remove_producer(List *list)
Definition: list.c:401
void * gwlist_consume(List *list)
Definition: list.c:427
List * flow_threads
Definition: bearerbox.c:116
List * outgoing_wdp
Definition: bearerbox.c:88
void gwlist_add_producer(List *list)
Definition: list.c:383
static XMLRPCDocument * msg
Definition: test_xmlrpc.c:86

Variable Documentation

◆ bb_status

◆ bb_todo

volatile sig_atomic_t bb_todo = 0
static

Definition at line 143 of file bearerbox.c.

Referenced by main(), and signal_handler().

◆ cfg_filename

Octstr* cfg_filename

Definition at line 130 of file bearerbox.c.

Referenced by bb_graceful_restart(), bb_reload_smsc_groups(), and main().

◆ flow_threads

List* flow_threads

Definition at line 116 of file bearerbox.c.

Referenced by main(), and wdp_router().

◆ incoming_dlr_counter

Counter* incoming_dlr_counter

◆ incoming_dlr_load

Load* incoming_dlr_load

◆ incoming_sms

◆ incoming_sms_counter

Counter* incoming_sms_counter

◆ incoming_sms_load

◆ incoming_wdp

List* incoming_wdp

Definition at line 87 of file bearerbox.c.

Referenced by bb_print_status(), empty_msg_lists(), and init_bearerbox().

◆ incoming_wdp_counter

Counter* incoming_wdp_counter

Definition at line 94 of file bearerbox.c.

Referenced by bb_print_status(), empty_msg_lists(), and init_bearerbox().

◆ isolated

List* isolated

Definition at line 127 of file bearerbox.c.

Referenced by bb_isolate(), bb_resume(), bb_suspend(), main(), set_shutdown_status(), and udp_receiver().

◆ max_incoming_sms_qlength

long max_incoming_sms_qlength

Definition at line 98 of file bearerbox.c.

Referenced by concat_handling_init(), init_bearerbox(), and route_incoming_to_boxc().

◆ max_outgoing_sms_qlength

long max_outgoing_sms_qlength

Definition at line 99 of file bearerbox.c.

Referenced by init_bearerbox(), and smsc2_rout().

◆ outgoing_dlr_counter

Counter* outgoing_dlr_counter

Definition at line 93 of file bearerbox.c.

Referenced by bb_print_status(), bb_smscconn_sent(), empty_msg_lists(), and init_bearerbox().

◆ outgoing_dlr_load

Load* outgoing_dlr_load

Definition at line 105 of file bearerbox.c.

Referenced by bb_print_status(), bb_smscconn_sent(), empty_msg_lists(), and init_bearerbox().

◆ outgoing_sms

◆ outgoing_sms_counter

Counter* outgoing_sms_counter

Definition at line 91 of file bearerbox.c.

Referenced by bb_print_status(), bb_smscconn_sent(), empty_msg_lists(), and init_bearerbox().

◆ outgoing_sms_load

Load* outgoing_sms_load

Definition at line 102 of file bearerbox.c.

Referenced by bb_print_status(), bb_smscconn_sent(), empty_msg_lists(), and init_bearerbox().

◆ outgoing_wdp

List* outgoing_wdp

Definition at line 88 of file bearerbox.c.

Referenced by bb_print_status(), empty_msg_lists(), init_bearerbox(), and wdp_router().

◆ outgoing_wdp_counter

Counter* outgoing_wdp_counter

Definition at line 95 of file bearerbox.c.

Referenced by bb_print_status(), empty_msg_lists(), and init_bearerbox().

◆ restart

volatile sig_atomic_t restart = 0

Definition at line 149 of file bearerbox.c.

Referenced by bb_restart(), and main().

◆ start_time

time_t start_time
static

Definition at line 148 of file bearerbox.c.

Referenced by bb_print_status(), and main().

◆ status_mutex

Mutex* status_mutex
static

Definition at line 147 of file bearerbox.c.

Referenced by bb_isolate(), bb_resume(), bb_shutdown(), bb_suspend(), init_bearerbox(), and main().

◆ suspended

See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.