Kannel: Open Source WAP and SMS gateway  svn-r5335
smscconn.c File Reference
#include <signal.h>
#include <time.h>
#include "gwlib/gwlib.h"
#include "gwlib/gw-regex.h"
#include "smscconn.h"
#include "smscconn_p.h"
#include "bb_smscconn_cb.h"
#include "sms.h"

Go to the source code of this file.

Macros

#define SMSCCONN_RECONNECT_DELAY   10.0
 
#define OCTSTR(os)   octstr_imm(#os)
 
#define GET_OPTIONAL_VAL(x, n)   x = cfg_get(grp, octstr_imm(n))
 
#define SPLIT_OPTIONAL_VAL(x, n)
 
#define GET_OPTIONAL_VAL(x, n)
 
#define SPLIT_OPTIONAL_VAL(x, n)
 
#define GET_OPTIONAL_REGEX(x, n)
 

Functions

static void init_reroute (SMSCConn *conn, CfgGroup *grp)
 
unsigned int smscconn_instances (CfgGroup *grp)
 
SMSCConnsmscconn_create (CfgGroup *grp, int start_as_stopped)
 
void smscconn_shutdown (SMSCConn *conn, int finish_sending)
 
static void pattern_route_destroy (void *arg)
 
int smscconn_destroy (SMSCConn *conn)
 
int smscconn_stop (SMSCConn *conn)
 
void smscconn_start (SMSCConn *conn)
 
const Octstrsmscconn_name (SMSCConn *conn)
 
const Octstrsmscconn_id (SMSCConn *conn)
 
const Octstrsmscconn_admin_id (SMSCConn *conn)
 
int smscconn_usable (SMSCConn *conn, Msg *msg)
 
int smscconn_send (SMSCConn *conn, Msg *msg)
 
int smscconn_status (SMSCConn *conn)
 
int smscconn_info (SMSCConn *conn, StatusInfo *infotable)
 
void smscconn_reconfig (SMSCConn *conn, CfgGroup *grp)
 

Variables

Countersplit_msg_counter
 

Macro Definition Documentation

◆ GET_OPTIONAL_REGEX

#define GET_OPTIONAL_REGEX (   x,
 
)
Value:
gw_regex_destroy(x); \
if ((tmp = cfg_get(grp, octstr_imm(n))) != NULL) { \
if ((x = gw_regex_comp(tmp, REG_EXTENDED)) == NULL) \
error(0, "Could not compile pattern '%s'", octstr_get_cstr(tmp)); \
octstr_destroy(tmp); \
}
#define cfg_get(grp, varname)
Definition: cfg.h:86
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:283

Referenced by smscconn_reconfig().

◆ GET_OPTIONAL_VAL [1/2]

#define GET_OPTIONAL_VAL (   x,
 
)    x = cfg_get(grp, octstr_imm(n))

◆ GET_OPTIONAL_VAL [2/2]

#define GET_OPTIONAL_VAL (   x,
 
)
Value:
x = cfg_get(grp, octstr_imm(n))
#define cfg_get(grp, varname)
Definition: cfg.h:86
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:283
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324

◆ OCTSTR

#define OCTSTR (   os)    octstr_imm(#os)

Referenced by smscconn_create().

◆ SMSCCONN_RECONNECT_DELAY

#define SMSCCONN_RECONNECT_DELAY   10.0

Definition at line 80 of file smscconn.c.

Referenced by smscconn_create().

◆ SPLIT_OPTIONAL_VAL [1/2]

#define SPLIT_OPTIONAL_VAL (   x,
 
)
Value:
do { \
Octstr *tmp = cfg_get(grp, octstr_imm(n)); \
if (tmp) x = octstr_split(tmp, octstr_imm(";")); \
else x = NULL; \
octstr_destroy(tmp); \
}while(0)
#define cfg_get(grp, varname)
Definition: cfg.h:86
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:283
List * octstr_split(const Octstr *os, const Octstr *sep)
Definition: octstr.c:1640

Referenced by smscconn_create(), and smscconn_reconfig().

◆ SPLIT_OPTIONAL_VAL [2/2]

#define SPLIT_OPTIONAL_VAL (   x,
 
)
Value:
if ((tmp = cfg_get(grp, octstr_imm(n))) != NULL) \
x = octstr_split(tmp, octstr_imm(";")); \
else \
x = NULL; \
octstr_destroy(tmp);
#define cfg_get(grp, varname)
Definition: cfg.h:86
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:283
void octstr_destroy_item(void *os)
Definition: octstr.c:336
List * octstr_split(const Octstr *os, const Octstr *sep)
Definition: octstr.c:1640
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)
Definition: list.c:145

Function Documentation

◆ init_reroute()

static void init_reroute ( SMSCConn conn,
CfgGroup grp 
)
static

Definition at line 87 of file smscconn.c.

References cfg_get, cfg_get_bool(), debug(), dict_create(), dict_put_once(), error(), grp_dump(), gwlist_append(), gwlist_create, gwlist_destroy(), gwlist_extract_first(), gwlist_get(), gwlist_len(), smscconn::id, pattern_route::id, info(), octstr_destroy(), octstr_destroy_item(), octstr_duplicate, octstr_get_cstr, octstr_imm(), octstr_split(), octstr_strip_blanks(), panic, pattern_route::re, smscconn::reroute, smscconn::reroute_by_receiver, smscconn::reroute_by_receiver_regex, smscconn::reroute_dlr, and smscconn::reroute_to_smsc.

Referenced by smscconn_create(), and smscconn_reconfig().

88 {
89  Octstr *rule;
90  long i;
91 
92  if (cfg_get_bool(&conn->reroute_dlr, grp, octstr_imm("reroute-dlr")) == -1)
93  conn->reroute_dlr = 0;
94  info(0, "DLR rerouting for smsc id <%s> %s.", octstr_get_cstr(conn->id), (conn->reroute_dlr?"enabled":"disabled"));
95 
96  if (cfg_get_bool(&conn->reroute, grp, octstr_imm("reroute")) != -1) {
97  debug("smscconn",0,"Adding general internal routing for smsc id <%s>",
98  octstr_get_cstr(conn->id));
99  return;
100  }
101 
102  if ((conn->reroute_to_smsc = cfg_get(grp, octstr_imm("reroute-smsc-id"))) != NULL) {
103  /* reroute all messages to a specific smsc-id */
104  debug("smscconn",0,"Adding internal routing: smsc id <%s> to smsc id <%s>",
106  return;
107  }
108 
109  if ((rule = cfg_get(grp, octstr_imm("reroute-receiver"))) != NULL) {
110  List *routes;
111 
112  /* create hash dictionary for this smsc-id */
113  conn->reroute_by_receiver = dict_create(100, (void(*)(void *)) octstr_destroy);
114 
115  routes = octstr_split(rule, octstr_imm(";"));
116  for (i = 0; i < gwlist_len(routes); i++) {
117  Octstr *item = gwlist_get(routes, i);
118  Octstr *smsc, *receiver;
119  List *receivers;
120 
121  /* first word is the smsc-id, all other are the receivers */
122  receivers = octstr_split(item, octstr_imm(","));
123  smsc = gwlist_extract_first(receivers);
124  if (smsc)
125  octstr_strip_blanks(smsc);
126 
127  while((receiver = gwlist_extract_first(receivers))) {
129  debug("smscconn",0,"Adding internal routing for smsc id <%s>: "
130  "receiver <%s> to smsc id <%s>",
132  octstr_get_cstr(smsc));
134  panic(0, "Could not set internal routing for smsc id <%s>: "
135  "receiver <%s> to smsc id <%s>, because receiver has already routing entry!",
137  octstr_get_cstr(smsc));
139  }
140  octstr_destroy(smsc);
142  }
143  octstr_destroy(rule);
145  }
146 
147  if ((rule = cfg_get(grp, octstr_imm("reroute-receiver-regex"))) != NULL) {
148  List *routes;
149 
150  /* create list with regex patterns and smsc-id */
152 
153  routes = octstr_split(rule, octstr_imm(";"));
154  for (i = 0; i < gwlist_len(routes); i++) {
155  Octstr *item = gwlist_get(routes, i);
156  Octstr *smsc, *receiver;
157  List *receivers;
158  regex_t *re;
159  pattern_route *r;
160 
161  /* first word is the smsc-id, all other are receiver regex */
162  receivers = octstr_split(item, octstr_imm(","));
163  smsc = gwlist_extract_first(receivers);
164  if (smsc)
165  octstr_strip_blanks(smsc);
166 
167  while ((receiver = gwlist_extract_first(receivers))) {
169 
170  if ((re = gw_regex_comp(receiver, REG_EXTENDED)) == NULL) {
171  grp_dump(grp);
172  error(0, "Could not compile regex pattern '%s', skipping.", octstr_get_cstr(receiver));
174  continue;
175  }
176 
177  r = gw_malloc(sizeof(pattern_route));
178  r->id = octstr_duplicate(smsc);
179  r->re = re;
180 
181  debug("smscconn",0,"Adding internal routing for smsc id <%s>: "
182  "receiver-regex <%s> to smsc id <%s>",
184  octstr_get_cstr(smsc));
187  }
188  octstr_destroy(smsc);
190  }
191  octstr_destroy(rule);
193  }
194 }
Dict * dict_create(long size_hint, void(*destroy_value)(void *))
Definition: dict.c:192
void error(int err, const char *fmt,...)
Definition: log.c:648
void info(int err, const char *fmt,...)
Definition: log.c:672
regex_t * re
Definition: smscconn_p.h:255
void gwlist_append(List *list, void *item)
Definition: list.c:179
List * reroute_by_receiver_regex
Definition: smscconn_p.h:208
Octstr * id
Definition: smscconn_p.h:174
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
Octstr * id
Definition: smscconn_p.h:256
Dict * reroute_by_receiver
Definition: smscconn_p.h:207
void octstr_strip_blanks(Octstr *text)
Definition: octstr.c:1346
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:283
Octstr * reroute_to_smsc
Definition: smscconn_p.h:209
void * gwlist_extract_first(List *list)
Definition: list.c:305
void grp_dump(CfgGroup *grp)
Definition: cfg.c:811
int reroute
Definition: smscconn_p.h:206
#define octstr_duplicate(ostr)
Definition: octstr.h:187
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
void octstr_destroy_item(void *os)
Definition: octstr.c:336
int cfg_get_bool(int *n, CfgGroup *grp, Octstr *varname)
Definition: cfg.c:759
Definition: octstr.c:118
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:726
#define panic
Definition: log.h:87
#define gwlist_create()
Definition: list.h:136
int dict_put_once(Dict *dict, Octstr *key, void *value)
Definition: dict.c:271
int reroute_dlr
Definition: smscconn_p.h:210
List * octstr_split(const Octstr *os, const Octstr *sep)
Definition: octstr.c:1640
Definition: list.c:102
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)
Definition: list.c:145

◆ pattern_route_destroy()

static void pattern_route_destroy ( void *  arg)
static

Definition at line 455 of file smscconn.c.

References pattern_route::id, octstr_destroy(), and pattern_route::re.

Referenced by smscconn_destroy(), and smscconn_reconfig().

456 {
457  pattern_route *r = arg;
458  gw_regex_destroy(r->re);
459  octstr_destroy(r->id);
460  gw_free(r);
461 }
regex_t * re
Definition: smscconn_p.h:255
Octstr * id
Definition: smscconn_p.h:256
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324

◆ smscconn_admin_id()

const Octstr* smscconn_admin_id ( SMSCConn conn)

Definition at line 566 of file smscconn.c.

References smscconn::admin_id, and gw_assert().

Referenced by smsc2_status().

567 {
568  gw_assert(conn != NULL);
569  return conn->admin_id;
570 }
gw_assert(wtls_machine->packet_to_send !=NULL)
Octstr * admin_id
Definition: smscconn_p.h:176

◆ smscconn_create()

SMSCConn* smscconn_create ( CfgGroup grp,
int  start_as_stopped 
)

Definition at line 210 of file smscconn.c.

References smscconn::admin_id, smscconn::allowed_prefix, smscconn::allowed_prefix_regex, smscconn::allowed_smsc_id, smscconn::allowed_smsc_id_regex, smscconn::alt_dcs, bb_smscconn_ready(), cfg_get, cfg_get_bool(), cfg_get_group_checksum(), cfg_get_integer(), smscconn::chksum, smscconn::chksum_conn, smscconn::connect_time, counter_create(), smscconn::dead_start, smscconn::denied_prefix, smscconn::denied_prefix_regex, smscconn::denied_smsc_id, smscconn::denied_smsc_id_regex, error(), smscconn::failed, smscconn::flow_mutex, GET_OPTIONAL_VAL, gw_assert(), GW_EXCL, smscconn::id, smscconn::incoming_dlr_load, smscconn::incoming_sms_load, info(), init_reroute(), smscconn::is_stopped, load_add_interval(), load_create, smscconn::log_file, smscconn::log_idx, smscconn::log_level, log_open(), MAX_SMS_OCTETS, smscconn::max_sms_octets, mutex_create, OCTSTR, octstr_compare(), octstr_destroy(), octstr_duplicate, octstr_get_cstr, octstr_imm(), octstr_parse_double(), smscconn::our_host, smscconn::outgoing_dlr_load, smscconn::outgoing_sms_load, panic, smscconn::preferred_prefix, smscconn::preferred_prefix_regex, smscconn::preferred_smsc_id, smscconn::received, smscconn::received_dlr, smscconn::reconnect_delay, smscconn::send_msg, smscconn::sent, smscconn::sent_dlr, smsc_at2_create(), smsc_cgw_create(), smsc_cimd2_create(), smsc_emi2_create(), smsc_fake_create(), smsc_http_create(), smsc_loopback_create(), smsc_oisd_create(), smsc_smasi_create(), smsc_smpp_create(), smsc_wrapper_create(), SMSCCONN_ALIVE, SMSCCONN_CONNECTING, smscconn_destroy(), SMSCCONN_RECONNECT_DELAY, SPLIT_OPTIONAL_VAL, smscconn::status, smscconn::throughput, smscconn::unified_prefix, warning(), and smscconn::why_killed.

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

211 {
212  SMSCConn *conn;
213  Octstr *smsc_type;
214  int ret;
215  Octstr *allowed_smsc_id_regex;
216  Octstr *denied_smsc_id_regex;
217  Octstr *allowed_prefix_regex;
218  Octstr *denied_prefix_regex;
219  Octstr *preferred_prefix_regex;
220  Octstr *tmp;
221 
222  if (grp == NULL)
223  return NULL;
224 
225  conn = gw_malloc(sizeof(*conn));
226  memset(conn, 0, sizeof(*conn));
227 
228  conn->why_killed = SMSCCONN_ALIVE;
229  conn->status = SMSCCONN_CONNECTING;
230  conn->connect_time = -1;
231  conn->is_stopped = start_as_stopped;
232 
233 #define OCTSTR(os) octstr_imm(#os)
234 
235  /* checksum of the whole config, without instance multiplier */
236  conn->chksum = cfg_get_group_checksum(grp,
237  NULL
238  );
239 
240  /* checksum of the connection related part, without routing
241  * and without instance multiplier */
243  OCTSTR(denied-smsc-id),
244  OCTSTR(allowed-smsc-id),
245  OCTSTR(preferred-smsc-id),
246  OCTSTR(allowed-prefix),
247  OCTSTR(denied-prefix),
248  OCTSTR(preferred-prefix),
249  OCTSTR(unified-prefix),
250  OCTSTR(reroute),
251  OCTSTR(reroute-smsc-id),
252  OCTSTR(reroute-receiver),
253  OCTSTR(reroute-receiver-regex),
254  OCTSTR(reroute-dlr),
255  OCTSTR(allowed-smsc-id-regex),
256  OCTSTR(denied-smsc-id-regex),
257  OCTSTR(preferred-smsc-id-regex),
258  OCTSTR(allowed-prefix-regex),
259  OCTSTR(denied-prefix-regex),
260  OCTSTR(preferred-prefix-regex),
261  NULL
262  );
263 
264  conn->received = counter_create();
265  conn->received_dlr = counter_create();
266  conn->sent = counter_create();
267  conn->sent_dlr = counter_create();
268  conn->failed = counter_create();
269  conn->flow_mutex = mutex_create();
270 
271  conn->outgoing_sms_load = load_create();
272  /* add 60,300,-1 entries */
276 
277  conn->incoming_sms_load = load_create();
278  /* add 60,300,-1 entries */
282 
283  conn->incoming_dlr_load = load_create();
284  /* add 60,300,-1 entries to dlr */
288 
289  conn->outgoing_dlr_load = load_create();
290  /* add 60,300,-1 entries to dlr */
294 
295 
296 #define GET_OPTIONAL_VAL(x, n) x = cfg_get(grp, octstr_imm(n))
297 #define SPLIT_OPTIONAL_VAL(x, n) \
298  do { \
299  Octstr *tmp = cfg_get(grp, octstr_imm(n)); \
300  if (tmp) x = octstr_split(tmp, octstr_imm(";")); \
301  else x = NULL; \
302  octstr_destroy(tmp); \
303  }while(0)
304 
305  GET_OPTIONAL_VAL(conn->id, "smsc-id");
306  SPLIT_OPTIONAL_VAL(conn->allowed_smsc_id, "allowed-smsc-id");
307  SPLIT_OPTIONAL_VAL(conn->denied_smsc_id, "denied-smsc-id");
308  SPLIT_OPTIONAL_VAL(conn->preferred_smsc_id, "preferred-smsc-id");
309  GET_OPTIONAL_VAL(conn->allowed_prefix, "allowed-prefix");
310  GET_OPTIONAL_VAL(conn->denied_prefix, "denied-prefix");
311  GET_OPTIONAL_VAL(conn->preferred_prefix, "preferred-prefix");
312  GET_OPTIONAL_VAL(conn->unified_prefix, "unified-prefix");
313  GET_OPTIONAL_VAL(conn->our_host, "our-host");
314  GET_OPTIONAL_VAL(conn->log_file, "log-file");
315  cfg_get_bool(&conn->alt_dcs, grp, octstr_imm("alt-dcs"));
316 
317  GET_OPTIONAL_VAL(allowed_smsc_id_regex, "allowed-smsc-id-regex");
318  if (allowed_smsc_id_regex != NULL)
319  if ((conn->allowed_smsc_id_regex = gw_regex_comp(allowed_smsc_id_regex, REG_EXTENDED)) == NULL)
320  panic(0, "Could not compile pattern '%s'", octstr_get_cstr(allowed_smsc_id_regex));
321  GET_OPTIONAL_VAL(denied_smsc_id_regex, "denied-smsc-id-regex");
322  if (denied_smsc_id_regex != NULL)
323  if ((conn->denied_smsc_id_regex = gw_regex_comp(denied_smsc_id_regex, REG_EXTENDED)) == NULL)
324  panic(0, "Could not compile pattern '%s'", octstr_get_cstr(denied_smsc_id_regex));
325  GET_OPTIONAL_VAL(allowed_prefix_regex, "allowed-prefix-regex");
326  if (allowed_prefix_regex != NULL)
327  if ((conn->allowed_prefix_regex = gw_regex_comp(allowed_prefix_regex, REG_EXTENDED)) == NULL)
328  panic(0, "Could not compile pattern '%s'", octstr_get_cstr(allowed_prefix_regex));
329  GET_OPTIONAL_VAL(denied_prefix_regex, "denied-prefix-regex");
330  if (denied_prefix_regex != NULL)
331  if ((conn->denied_prefix_regex = gw_regex_comp(denied_prefix_regex, REG_EXTENDED)) == NULL)
332  panic(0, "Could not compile pattern '%s'", octstr_get_cstr(denied_prefix_regex));
333  GET_OPTIONAL_VAL(preferred_prefix_regex, "preferred-prefix-regex");
334  if (preferred_prefix_regex != NULL)
335  if ((conn->preferred_prefix_regex = gw_regex_comp(preferred_prefix_regex, REG_EXTENDED)) == NULL)
336  panic(0, "Could not compile pattern '%s'", octstr_get_cstr(preferred_prefix_regex));
337 
338  if ((tmp = cfg_get(grp, octstr_imm("throughput"))) != NULL) {
339  if (octstr_parse_double(&conn->throughput, tmp, 0) == -1)
340  conn->throughput = 0;
341  octstr_destroy(tmp);
342  info(0, "Set throughput to %.3f for smsc id <%s>", conn->throughput, octstr_get_cstr(conn->id));
343  }
344  /* Sets the admin_id. Equals to connection id if empty */
345  GET_OPTIONAL_VAL(conn->admin_id, "smsc-admin-id");
346  if (conn->admin_id == NULL)
347  conn->admin_id = octstr_duplicate(conn->id);
348 
349  /* configure the internal rerouting rules for this smsc id */
350  init_reroute(conn, grp);
351 
352  if (cfg_get_integer(&conn->log_level, grp, octstr_imm("log-level")) == -1)
353  conn->log_level = 0;
354 
355  if (cfg_get_integer(&conn->max_sms_octets, grp, octstr_imm("max-sms-octets")) == -1)
357 
358  if (cfg_get_bool(&conn->dead_start, grp, octstr_imm("dead-start")) == -1)
359  conn->dead_start = 0; /* default to connect at start-up time */
360 
361  /* open a smsc-id specific log-file in exlusive mode */
362  if (conn->log_file)
363  conn->log_idx = log_open(octstr_get_cstr(conn->log_file),
364  conn->log_level, GW_EXCL);
365 #undef GET_OPTIONAL_VAL
366 #undef SPLIT_OPTIONAL_VAL
367 
368  if (conn->allowed_smsc_id && conn->denied_smsc_id)
369  warning(0, "Both 'allowed-smsc-id' and 'denied-smsc-id' set, deny-list "
370  "automatically ignored");
371  if (conn->allowed_smsc_id_regex && conn->denied_smsc_id_regex)
372  warning(0, "Both 'allowed-smsc-id_regex' and 'denied-smsc-id_regex' set, deny-regex "
373  "automatically ignored");
374 
375  if (cfg_get_integer(&conn->reconnect_delay, grp,
376  octstr_imm("reconnect-delay")) == -1)
378 
379  smsc_type = cfg_get(grp, octstr_imm("smsc"));
380  if (smsc_type == NULL) {
381  error(0, "Required field 'smsc' missing for smsc group.");
382  smscconn_destroy(conn);
383  octstr_destroy(smsc_type);
384  return NULL;
385  }
386 
387  if (octstr_compare(smsc_type, octstr_imm("fake")) == 0)
388  ret = smsc_fake_create(conn, grp);
389  else if (octstr_compare(smsc_type, octstr_imm("cimd2")) == 0)
390  ret = smsc_cimd2_create(conn, grp);
391  else if (octstr_compare(smsc_type, octstr_imm("emi")) == 0)
392  ret = smsc_emi2_create(conn, grp);
393  else if (octstr_compare(smsc_type, octstr_imm("http")) == 0)
394  ret = smsc_http_create(conn, grp);
395  else if (octstr_compare(smsc_type, octstr_imm("smpp")) == 0)
396  ret = smsc_smpp_create(conn, grp);
397  else if (octstr_compare(smsc_type, octstr_imm("at")) == 0)
398  ret = smsc_at2_create(conn,grp);
399  else if (octstr_compare(smsc_type, octstr_imm("cgw")) == 0)
400  ret = smsc_cgw_create(conn,grp);
401  else if (octstr_compare(smsc_type, octstr_imm("smasi")) == 0)
402  ret = smsc_smasi_create(conn, grp);
403  else if (octstr_compare(smsc_type, octstr_imm("oisd")) == 0)
404  ret = smsc_oisd_create(conn, grp);
405  else if (octstr_compare(smsc_type, octstr_imm("loopback")) == 0)
406  ret = smsc_loopback_create(conn, grp);
407 #ifdef HAVE_GSOAP
408  else if (octstr_compare(smsc_type, octstr_imm("parlayx")) == 0)
409  ret = smsc_soap_parlayx_create(conn, grp);
410 #endif
411  else
412  ret = smsc_wrapper_create(conn, grp);
413 
414  octstr_destroy(smsc_type);
415  if (ret == -1) {
416  smscconn_destroy(conn);
417  return NULL;
418  }
419  gw_assert(conn->send_msg != NULL);
420 
421  bb_smscconn_ready(conn);
422 
423  return conn;
424 }
Load * incoming_sms_load
Definition: smscconn_p.h:216
void error(int err, const char *fmt,...)
Definition: log.c:648
int smsc_oisd_create(SMSCConn *conn, CfgGroup *grp)
Definition: smsc_oisd.c:1498
void info(int err, const char *fmt,...)
Definition: log.c:672
#define MAX_SMS_OCTETS
Definition: sms.h:129
int smsc_cgw_create(SMSCConn *conn, CfgGroup *cfg)
Definition: smsc_cgw.c:431
regex_t * allowed_smsc_id_regex
Definition: smscconn_p.h:180
long max_sms_octets
Definition: smscconn_p.h:213
void bb_smscconn_ready(SMSCConn *conn)
Definition: bb_smscconn.c:185
int smscconn_destroy(SMSCConn *conn)
Definition: smscconn.c:464
int smsc_cimd2_create(SMSCConn *conn, CfgGroup *grp)
Definition: smsc_cimd2.c:2321
gw_assert(wtls_machine->packet_to_send !=NULL)
int alt_dcs
Definition: smscconn_p.h:201
int dead_start
Definition: smscconn_p.h:211
Octstr * id
Definition: smscconn_p.h:174
Counter * failed
Definition: smscconn_p.h:166
#define mutex_create()
Definition: thread.h:96
Octstr * denied_prefix
Definition: smscconn_p.h:186
int load_add_interval(Load *load, int interval)
Definition: load.c:111
Octstr * cfg_get_group_checksum(CfgGroup *grp,...)
Definition: cfg.c:666
int log_idx
Definition: smscconn_p.h:197
int smsc_emi2_create(SMSCConn *conn, CfgGroup *cfg)
Definition: smsc_emi.c:1629
#define cfg_get(grp, varname)
Definition: cfg.h:86
Octstr * allowed_prefix
Definition: smscconn_p.h:184
Octstr * our_host
Definition: smscconn_p.h:192
int smsc_wrapper_create(SMSCConn *conn, CfgGroup *cfg)
Definition: smsc_wrapper.c:397
long log_level
Definition: smscconn_p.h:196
List * denied_smsc_id
Definition: smscconn_p.h:178
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
int smsc_http_create(SMSCConn *conn, CfgGroup *cfg)
Definition: smsc_http.c:489
#define OCTSTR(os)
Definition: log.h:74
long reconnect_delay
Definition: smscconn_p.h:199
int smsc_at2_create(SMSCConn *conn, CfgGroup *cfg)
Definition: smsc_at.c:1519
long octstr_parse_double(double *nump, Octstr *ostr, long pos)
Definition: octstr.c:782
regex_t * preferred_prefix_regex
Definition: smscconn_p.h:189
Octstr * log_file
Definition: smscconn_p.h:195
#define SPLIT_OPTIONAL_VAL(x, n)
Load * outgoing_sms_load
Definition: smscconn_p.h:215
int smsc_smasi_create(SMSCConn *conn, CfgGroup *config)
Definition: smsc_smasi.c:1129
smscconn_killed_t why_killed
Definition: smscconn_p.h:153
regex_t * allowed_prefix_regex
Definition: smscconn_p.h:185
Counter * sent
Definition: smscconn_p.h:164
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:283
Counter * received_dlr
Definition: smscconn_p.h:163
Counter * counter_create(void)
Definition: counter.c:94
Octstr * chksum_conn
Definition: smscconn_p.h:172
Octstr * admin_id
Definition: smscconn_p.h:176
List * preferred_smsc_id
Definition: smscconn_p.h:179
Octstr * unified_prefix
Definition: smscconn_p.h:190
Octstr * chksum
Definition: smscconn_p.h:171
time_t connect_time
Definition: smscconn_p.h:155
#define octstr_duplicate(ostr)
Definition: octstr.h:187
double throughput
Definition: smscconn_p.h:203
int smsc_loopback_create(SMSCConn *conn, CfgGroup *cfg)
Mutex * flow_mutex
Definition: smscconn_p.h:157
static void init_reroute(SMSCConn *conn, CfgGroup *grp)
Definition: smscconn.c:87
Octstr * preferred_prefix
Definition: smscconn_p.h:188
regex_t * denied_prefix_regex
Definition: smscconn_p.h:187
void warning(int err, const char *fmt,...)
Definition: log.c:660
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
#define load_create()
Definition: load.h:78
#define GET_OPTIONAL_VAL(x, n)
#define SMSCCONN_RECONNECT_DELAY
Definition: smscconn.c:80
volatile sig_atomic_t is_stopped
Definition: smscconn_p.h:169
List * allowed_smsc_id
Definition: smscconn_p.h:177
int smsc_smpp_create(SMSCConn *conn, CfgGroup *grp)
Definition: smsc_smpp.c:2599
Counter * received
Definition: smscconn_p.h:162
int smsc_fake_create(SMSCConn *conn, CfgGroup *cfg)
Definition: smsc_fake.c:540
Counter * sent_dlr
Definition: smscconn_p.h:165
int log_open(char *filename, int level, enum excl_state excl)
Definition: log.c:375
int cfg_get_bool(int *n, CfgGroup *grp, Octstr *varname)
Definition: cfg.c:759
Definition: octstr.c:118
Load * outgoing_dlr_load
Definition: smscconn_p.h:218
int cfg_get_integer(long *n, CfgGroup *grp, Octstr *varname)
Definition: cfg.c:742
#define panic
Definition: log.h:87
smscconn_status_t status
Definition: smscconn_p.h:151
Load * incoming_dlr_load
Definition: smscconn_p.h:217
int(* send_msg)(SMSCConn *conn, Msg *msg)
Definition: smscconn_p.h:236
regex_t * denied_smsc_id_regex
Definition: smscconn_p.h:181
int octstr_compare(const Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:871

◆ smscconn_destroy()

int smscconn_destroy ( SMSCConn conn)

Definition at line 464 of file smscconn.c.

References smscconn::admin_id, smscconn::allowed_prefix, smscconn::allowed_prefix_regex, smscconn::allowed_smsc_id, smscconn::allowed_smsc_id_regex, smscconn::chksum, smscconn::chksum_conn, counter_destroy(), smscconn::denied_prefix, smscconn::denied_prefix_regex, smscconn::denied_smsc_id, smscconn::denied_smsc_id_regex, dict_destroy(), smscconn::failed, smscconn::flow_mutex, gwlist_destroy(), smscconn::id, smscconn::incoming_dlr_load, smscconn::incoming_sms_load, load_destroy(), smscconn::log_file, mutex_destroy(), mutex_lock, mutex_unlock, smscconn::name, octstr_destroy(), octstr_destroy_item(), smscconn::our_host, smscconn::outgoing_dlr_load, smscconn::outgoing_sms_load, pattern_route_destroy(), smscconn::preferred_prefix, smscconn::preferred_prefix_regex, smscconn::preferred_smsc_id, smscconn::received, smscconn::received_dlr, smscconn::reroute_by_receiver, smscconn::reroute_by_receiver_regex, smscconn::reroute_to_smsc, smscconn::sent, smscconn::sent_dlr, SMSCCONN_DEAD, smscconn::status, and smscconn::unified_prefix.

Referenced by smsc2_cleanup(), smsc2_graceful_restart(), smsc2_remove_smsc(), smsc2_restart_smsc(), and smscconn_create().

465 {
466  if (conn == NULL)
467  return 0;
468  if (conn->status != SMSCCONN_DEAD)
469  return -1;
470  mutex_lock(conn->flow_mutex);
471 
472  counter_destroy(conn->received);
474  counter_destroy(conn->sent);
475  counter_destroy(conn->sent_dlr);
476  counter_destroy(conn->failed);
477 
482 
483  octstr_destroy(conn->name);
484  octstr_destroy(conn->id);
485  octstr_destroy(conn->admin_id);
493  octstr_destroy(conn->our_host);
494  octstr_destroy(conn->log_file);
495  octstr_destroy(conn->chksum);
497 
498  if (conn->denied_smsc_id_regex != NULL) gw_regex_destroy(conn->denied_smsc_id_regex);
499  if (conn->allowed_smsc_id_regex != NULL) gw_regex_destroy(conn->allowed_smsc_id_regex);
500  if (conn->preferred_prefix_regex != NULL) gw_regex_destroy(conn->preferred_prefix_regex);
501  if (conn->denied_prefix_regex != NULL) gw_regex_destroy(conn->denied_prefix_regex);
502  if (conn->allowed_prefix_regex != NULL) gw_regex_destroy(conn->allowed_prefix_regex);
503 
507 
508  mutex_unlock(conn->flow_mutex);
509  mutex_destroy(conn->flow_mutex);
510 
511  gw_free(conn);
512  return 0;
513 }
Load * incoming_sms_load
Definition: smscconn_p.h:216
Octstr * name
Definition: smscconn_p.h:173
regex_t * allowed_smsc_id_regex
Definition: smscconn_p.h:180
void counter_destroy(Counter *counter)
Definition: counter.c:110
#define mutex_unlock(m)
Definition: thread.h:136
List * reroute_by_receiver_regex
Definition: smscconn_p.h:208
Octstr * id
Definition: smscconn_p.h:174
Counter * failed
Definition: smscconn_p.h:166
Octstr * denied_prefix
Definition: smscconn_p.h:186
Octstr * allowed_prefix
Definition: smscconn_p.h:184
static void pattern_route_destroy(void *arg)
Definition: smscconn.c:455
Dict * reroute_by_receiver
Definition: smscconn_p.h:207
Octstr * our_host
Definition: smscconn_p.h:192
List * denied_smsc_id
Definition: smscconn_p.h:178
regex_t * preferred_prefix_regex
Definition: smscconn_p.h:189
Octstr * log_file
Definition: smscconn_p.h:195
Load * outgoing_sms_load
Definition: smscconn_p.h:215
regex_t * allowed_prefix_regex
Definition: smscconn_p.h:185
Counter * sent
Definition: smscconn_p.h:164
Counter * received_dlr
Definition: smscconn_p.h:163
Octstr * reroute_to_smsc
Definition: smscconn_p.h:209
Octstr * chksum_conn
Definition: smscconn_p.h:172
Octstr * admin_id
Definition: smscconn_p.h:176
List * preferred_smsc_id
Definition: smscconn_p.h:179
Octstr * unified_prefix
Definition: smscconn_p.h:190
Octstr * chksum
Definition: smscconn_p.h:171
Mutex * flow_mutex
Definition: smscconn_p.h:157
Octstr * preferred_prefix
Definition: smscconn_p.h:188
regex_t * denied_prefix_regex
Definition: smscconn_p.h:187
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
void octstr_destroy_item(void *os)
Definition: octstr.c:336
void mutex_destroy(Mutex *mutex)
Definition: thread.c:97
List * allowed_smsc_id
Definition: smscconn_p.h:177
Counter * received
Definition: smscconn_p.h:162
Counter * sent_dlr
Definition: smscconn_p.h:165
void dict_destroy(Dict *dict)
Definition: dict.c:215
Load * outgoing_dlr_load
Definition: smscconn_p.h:218
void load_destroy(Load *load)
Definition: load.c:145
smscconn_status_t status
Definition: smscconn_p.h:151
Load * incoming_dlr_load
Definition: smscconn_p.h:217
regex_t * denied_smsc_id_regex
Definition: smscconn_p.h:181
#define mutex_lock(m)
Definition: thread.h:130
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)
Definition: list.c:145

◆ smscconn_id()

const Octstr* smscconn_id ( SMSCConn conn)

Definition at line 559 of file smscconn.c.

References gw_assert(), and smscconn::id.

Referenced by bb_alog_sms(), get_pattern(), and smsc2_status().

560 {
561  gw_assert(conn != NULL);
562  return conn->id;
563 }
gw_assert(wtls_machine->packet_to_send !=NULL)
Octstr * id
Definition: smscconn_p.h:174

◆ smscconn_info()

int smscconn_info ( SMSCConn conn,
StatusInfo infotable 
)

Definition at line 732 of file smscconn.c.

References smscconn::connect_time, counter_value(), smsc_state::failed, smscconn::failed, smscconn::flow_mutex, smsc_state::is_stopped, smscconn::is_stopped, smsc_state::killed, smsc_state::load, smscconn::load, mutex_lock, mutex_unlock, smsc_state::online, smsc_state::queued, smscconn::queued, smsc_state::received, smscconn::received, smsc_state::received_dlr, smscconn::received_dlr, smsc_state::sent, smscconn::sent, smsc_state::sent_dlr, smscconn::sent_dlr, smsc_state::status, smscconn::status, and smscconn::why_killed.

Referenced by smsc2_rout(), and smsc2_status().

733 {
734  if (conn == NULL || infotable == NULL)
735  return -1;
736 
737  mutex_lock(conn->flow_mutex);
738 
739  infotable->status = conn->status;
740  infotable->killed = conn->why_killed;
741  infotable->is_stopped = conn->is_stopped;
742  infotable->online = time(NULL) - conn->connect_time;
743 
744  infotable->sent = counter_value(conn->sent);
745  infotable->received = counter_value(conn->received);
746  infotable->sent_dlr = counter_value(conn->sent_dlr);
747  infotable->received_dlr = counter_value(conn->received_dlr);
748  infotable->failed = counter_value(conn->failed);
749 
750  if (conn->queued)
751  infotable->queued = conn->queued(conn);
752  else
753  infotable->queued = -1;
754 
755  infotable->load = conn->load;
756 
757  mutex_unlock(conn->flow_mutex);
758 
759  return 0;
760 }
long online
Definition: smscconn.h:122
unsigned long received_dlr
Definition: smscconn.h:117
#define mutex_unlock(m)
Definition: thread.h:136
Counter * failed
Definition: smscconn_p.h:166
smscconn_status_t status
Definition: smscconn.h:113
smscconn_killed_t killed
Definition: smscconn.h:114
unsigned long sent_dlr
Definition: smscconn.h:119
long queued
Definition: smscconn.h:121
smscconn_killed_t why_killed
Definition: smscconn_p.h:153
Counter * sent
Definition: smscconn_p.h:164
Counter * received_dlr
Definition: smscconn_p.h:163
unsigned long sent
Definition: smscconn.h:118
unsigned long failed
Definition: smscconn.h:120
int is_stopped
Definition: smscconn.h:115
time_t connect_time
Definition: smscconn_p.h:155
Mutex * flow_mutex
Definition: smscconn_p.h:157
unsigned long counter_value(Counter *counter)
Definition: counter.c:145
int load
Definition: smscconn.h:123
volatile sig_atomic_t is_stopped
Definition: smscconn_p.h:169
Counter * received
Definition: smscconn_p.h:162
Counter * sent_dlr
Definition: smscconn_p.h:165
smscconn_status_t status
Definition: smscconn_p.h:151
long(* queued)(SMSCConn *conn)
Definition: smscconn_p.h:241
#define mutex_lock(m)
Definition: thread.h:130
unsigned long received
Definition: smscconn.h:116
int load
Definition: smscconn_p.h:152

◆ smscconn_instances()

unsigned int smscconn_instances ( CfgGroup grp)

Definition at line 197 of file smscconn.c.

References cfg_get_integer(), and octstr_imm().

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

198 {
199  long i;
200 
201  if (cfg_get_integer(&i, grp, octstr_imm("instances")) == -1)
202  i = 1;
203  else if (i < 0)
204  i = 0;
205 
206  return i;
207 }
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:283
int cfg_get_integer(long *n, CfgGroup *grp, Octstr *varname)
Definition: cfg.c:742

◆ smscconn_name()

const Octstr* smscconn_name ( SMSCConn conn)

Definition at line 552 of file smscconn.c.

References gw_assert(), and smscconn::name.

Referenced by bb_alog_sms(), get_pattern(), and smsc2_status().

553 {
554  gw_assert(conn != NULL);
555  return conn->name;
556 }
Octstr * name
Definition: smscconn_p.h:173
gw_assert(wtls_machine->packet_to_send !=NULL)

◆ smscconn_reconfig()

void smscconn_reconfig ( SMSCConn conn,
CfgGroup grp 
)

Definition at line 763 of file smscconn.c.

References smscconn::allowed_prefix, smscconn::allowed_prefix_regex, smscconn::allowed_smsc_id, smscconn::allowed_smsc_id_regex, cfg_get_group_checksum(), smscconn::chksum, smscconn::denied_prefix, smscconn::denied_prefix_regex, smscconn::denied_smsc_id, smscconn::denied_smsc_id_regex, dict_destroy(), GET_OPTIONAL_REGEX, GET_OPTIONAL_VAL, gw_assert(), gwlist_destroy(), init_reroute(), octstr_destroy(), pattern_route_destroy(), smscconn::preferred_prefix, smscconn::preferred_prefix_regex, smscconn::preferred_smsc_id, smscconn::preferred_smsc_id_regex, smscconn::reroute_by_receiver, smscconn::reroute_by_receiver_regex, smscconn::reroute_to_smsc, SPLIT_OPTIONAL_VAL, and smscconn::unified_prefix.

Referenced by smsc2_graceful_restart().

764 {
765  Octstr *tmp;
766 
767  gw_assert(conn != NULL);
768 
769  if (grp == NULL)
770  return;
771 
772 #define GET_OPTIONAL_VAL(x, n) \
773  octstr_destroy(x); \
774  x = cfg_get(grp, octstr_imm(n))
775 #define SPLIT_OPTIONAL_VAL(x, n) \
776  gwlist_destroy(x, octstr_destroy_item); \
777  if ((tmp = cfg_get(grp, octstr_imm(n))) != NULL) \
778  x = octstr_split(tmp, octstr_imm(";")); \
779  else \
780  x = NULL; \
781  octstr_destroy(tmp);
782 #define GET_OPTIONAL_REGEX(x, n) \
783  gw_regex_destroy(x); \
784  if ((tmp = cfg_get(grp, octstr_imm(n))) != NULL) { \
785  if ((x = gw_regex_comp(tmp, REG_EXTENDED)) == NULL) \
786  error(0, "Could not compile pattern '%s'", octstr_get_cstr(tmp)); \
787  octstr_destroy(tmp); \
788  }
789 
790  SPLIT_OPTIONAL_VAL(conn->allowed_smsc_id, "allowed-smsc-id");
791  SPLIT_OPTIONAL_VAL(conn->denied_smsc_id, "denied-smsc-id");
792  SPLIT_OPTIONAL_VAL(conn->preferred_smsc_id, "preferred-smsc-id");
793  GET_OPTIONAL_VAL(conn->allowed_prefix, "allowed-prefix");
794  GET_OPTIONAL_VAL(conn->denied_prefix, "denied-prefix");
795  GET_OPTIONAL_VAL(conn->preferred_prefix, "preferred-prefix");
796  GET_OPTIONAL_VAL(conn->unified_prefix, "unified-prefix");
797  GET_OPTIONAL_REGEX(conn->allowed_smsc_id_regex, "allowed-smsc-id-regex");
798  GET_OPTIONAL_REGEX(conn->denied_smsc_id_regex, "denied-smsc-id-regex");
799  GET_OPTIONAL_REGEX(conn->preferred_smsc_id_regex, "preferred-smsc-id-regex");
800  GET_OPTIONAL_REGEX(conn->allowed_prefix_regex, "allowed-prefix-regex");
801  GET_OPTIONAL_REGEX(conn->denied_prefix_regex, "denied-prefix-regex");
802  GET_OPTIONAL_REGEX(conn->preferred_prefix_regex, "preferred-prefix-regex");
803 
807  init_reroute(conn, grp);
808 
809  /*
810  * Since we applied changes, we need to re-compute
811  * at least the overall checksum. The other one
812  * is not changed as the routing values are excluded.
813  * also the checksum hash values.
814  */
815  octstr_destroy(conn->chksum);
816  conn->chksum = cfg_get_group_checksum(grp, NULL);
817 }
regex_t * allowed_smsc_id_regex
Definition: smscconn_p.h:180
gw_assert(wtls_machine->packet_to_send !=NULL)
List * reroute_by_receiver_regex
Definition: smscconn_p.h:208
Octstr * denied_prefix
Definition: smscconn_p.h:186
Octstr * cfg_get_group_checksum(CfgGroup *grp,...)
Definition: cfg.c:666
Octstr * allowed_prefix
Definition: smscconn_p.h:184
static void pattern_route_destroy(void *arg)
Definition: smscconn.c:455
Dict * reroute_by_receiver
Definition: smscconn_p.h:207
List * denied_smsc_id
Definition: smscconn_p.h:178
regex_t * preferred_prefix_regex
Definition: smscconn_p.h:189
#define SPLIT_OPTIONAL_VAL(x, n)
regex_t * allowed_prefix_regex
Definition: smscconn_p.h:185
regex_t * preferred_smsc_id_regex
Definition: smscconn_p.h:182
Octstr * reroute_to_smsc
Definition: smscconn_p.h:209
List * preferred_smsc_id
Definition: smscconn_p.h:179
Octstr * unified_prefix
Definition: smscconn_p.h:190
Octstr * chksum
Definition: smscconn_p.h:171
static void init_reroute(SMSCConn *conn, CfgGroup *grp)
Definition: smscconn.c:87
Octstr * preferred_prefix
Definition: smscconn_p.h:188
regex_t * denied_prefix_regex
Definition: smscconn_p.h:187
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
#define GET_OPTIONAL_VAL(x, n)
List * allowed_smsc_id
Definition: smscconn_p.h:177
void dict_destroy(Dict *dict)
Definition: dict.c:215
Definition: octstr.c:118
regex_t * denied_smsc_id_regex
Definition: smscconn_p.h:181
#define GET_OPTIONAL_REGEX(x, n)
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)
Definition: list.c:145

◆ smscconn_send()

int smscconn_send ( SMSCConn conn,
Msg msg 
)

Definition at line 655 of file smscconn.c.

References counter_create(), counter_destroy(), counter_increase(), counter_increase_with(), counter_set(), debug(), smscconn::flow_mutex, gw_assert(), gwlist_destroy(), gwlist_get(), gwlist_len(), smscconn::max_sms_octets, msg, msg_destroy_item(), msg_duplicate(), mutex_lock, mutex_unlock, normalize_number(), octstr_get_cstr, smscconn::send_msg, sms_split(), SMSCCONN_ALIVE, SMSCCONN_DEAD, SMSCCONN_FAILED_REJECTED, SMSCCONN_SUCCESS, split, split_msg_counter, smscconn::status, smscconn::unified_prefix, warning(), and smscconn::why_killed.

Referenced by smsc2_rout().

656 {
657  int ret = -1;
658  List *parts = NULL;
659 
660  gw_assert(conn != NULL);
661  mutex_lock(conn->flow_mutex);
662  if (conn->status == SMSCCONN_DEAD || conn->why_killed != SMSCCONN_ALIVE) {
663  mutex_unlock(conn->flow_mutex);
664  return -1;
665  }
666 
667  /* if this a retry of splitted message, don't unify prefix and don't try to split */
668  if (msg->sms.split_parts == NULL) {
669  /* normalize the destination number for this smsc */
670  char *uf = conn->unified_prefix ? octstr_get_cstr(conn->unified_prefix) : NULL;
671  normalize_number(uf, &(msg->sms.receiver));
672 
673  /* split msg */
674  parts = sms_split(msg, NULL, NULL, NULL, NULL, 1,
675  counter_increase(split_msg_counter) & 0xff, 0xff, conn->max_sms_octets);
676  if (gwlist_len(parts) == 1) {
677  /* don't create split_parts of sms fit into one */
679  parts = NULL;
680  }
681  }
682 
683  if (parts == NULL)
684  ret = conn->send_msg(conn, msg);
685  else {
686  long i, parts_len = gwlist_len(parts);
687  struct split_parts *split = gw_malloc(sizeof(*split));
688  /* must duplicate, because smsc2_route will destroy this msg */
689  split->orig = msg_duplicate(msg);
690  split->parts_left = counter_create();
691  split->status = SMSCCONN_SUCCESS;
692  counter_set(split->parts_left, parts_len);
693  split->smsc_conn = conn;
694  debug("bb.sms.splits", 0, "new split_parts created %p", split);
695  for (i = 0; i < parts_len; i++) {
696  msg = gwlist_get(parts, i);
697  msg->sms.split_parts = split;
698  ret = conn->send_msg(conn, msg);
699  if (ret < 0) {
700  if (i == 0) {
701  counter_destroy(split->parts_left);
703  gw_free(split);
704  mutex_unlock(conn->flow_mutex);
705  return ret;
706  }
707  /*
708  * Some parts were sent. So handle this within
709  * bb_smscconn_XXX().
710  */
712  counter_increase_with(split->parts_left, -(parts_len - i));
713  warning(0, "Could not send all parts of a split message");
714  break;
715  }
716  }
718  }
719  mutex_unlock(conn->flow_mutex);
720  return ret;
721 }
Msg * msg_duplicate(Msg *msg)
Definition: msg.c:111
long max_sms_octets
Definition: smscconn_p.h:213
gw_assert(wtls_machine->packet_to_send !=NULL)
void counter_destroy(Counter *counter)
Definition: counter.c:110
#define mutex_unlock(m)
Definition: thread.h:136
long gwlist_len(List *list)
Definition: list.c:166
void * gwlist_get(List *list, long pos)
Definition: list.c:292
unsigned long counter_set(Counter *counter, unsigned long n)
Definition: counter.c:167
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
List * sms_split(Msg *orig, Octstr *header, Octstr *footer, Octstr *nonlast_suffix, Octstr *split_chars, int catenate, unsigned long msg_sequence, int max_messages, int max_octets)
Definition: sms.c:309
unsigned long counter_increase(Counter *counter)
Definition: counter.c:123
smscconn_killed_t why_killed
Definition: smscconn_p.h:153
void msg_destroy_item(void *msg)
Definition: msg.c:147
Counter * counter_create(void)
Definition: counter.c:94
Octstr * unified_prefix
Definition: smscconn_p.h:190
unsigned long counter_increase_with(Counter *counter, unsigned long value)
Definition: counter.c:134
Mutex * flow_mutex
Definition: smscconn_p.h:157
void warning(int err, const char *fmt,...)
Definition: log.c:660
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:726
static List * split
Definition: test_http.c:88
smscconn_status_t status
Definition: smscconn_p.h:151
int normalize_number(char *dial_prefixes, Octstr **number)
Definition: utils.c:882
int(* send_msg)(SMSCConn *conn, Msg *msg)
Definition: smscconn_p.h:236
#define mutex_lock(m)
Definition: thread.h:130
Definition: list.c:102
static XMLRPCDocument * msg
Definition: test_xmlrpc.c:86
Counter * split_msg_counter
Definition: bb_smscconn.c:159
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)
Definition: list.c:145

◆ smscconn_shutdown()

void smscconn_shutdown ( SMSCConn conn,
int  finish_sending 
)

Definition at line 427 of file smscconn.c.

References smscconn::flow_mutex, gw_assert(), mutex_lock, mutex_unlock, smscconn::shutdown, SMSCCONN_DEAD, SMSCCONN_KILLED_SHUTDOWN, smscconn::status, and smscconn::why_killed.

Referenced by sms_receive(), sms_send(), smsc2_add_smsc(), smsc2_graceful_restart(), smsc2_remove_smsc(), smsc2_resume(), smsc2_shutdown(), and smsc2_stop_smsc().

428 {
429  gw_assert(conn != NULL);
430 
431  mutex_lock(conn->flow_mutex);
432  if (conn->status == SMSCCONN_DEAD) {
433  mutex_unlock(conn->flow_mutex);
434  return;
435  }
436 
437  /* Call SMSC specific destroyer */
438  if (conn->shutdown) {
439  /*
440  * we must unlock here, because module manipulate their state
441  * and will try to lock this mutex.Otherwise we have deadlock!
442  */
443  mutex_unlock(conn->flow_mutex);
444  conn->shutdown(conn, finish_sending);
445  }
446  else {
448  mutex_unlock(conn->flow_mutex);
449  }
450 
451  return;
452 }
gw_assert(wtls_machine->packet_to_send !=NULL)
#define mutex_unlock(m)
Definition: thread.h:136
smscconn_killed_t why_killed
Definition: smscconn_p.h:153
Mutex * flow_mutex
Definition: smscconn_p.h:157
int(* shutdown)(SMSCConn *conn, int finish_sending)
Definition: smscconn_p.h:230
smscconn_status_t status
Definition: smscconn_p.h:151
#define mutex_lock(m)
Definition: thread.h:130

◆ smscconn_start()

void smscconn_start ( SMSCConn conn)

Definition at line 536 of file smscconn.c.

References smscconn::flow_mutex, gw_assert(), smscconn::is_stopped, mutex_lock, mutex_unlock, SMSCCONN_DEAD, smscconn::start_conn, and smscconn::status.

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

537 {
538  gw_assert(conn != NULL);
539  mutex_lock(conn->flow_mutex);
540  if (conn->status == SMSCCONN_DEAD || conn->is_stopped == 0) {
541  mutex_unlock(conn->flow_mutex);
542  return;
543  }
544  conn->is_stopped = 0;
545  mutex_unlock(conn->flow_mutex);
546 
547  if (conn->start_conn)
548  conn->start_conn(conn);
549 }
gw_assert(wtls_machine->packet_to_send !=NULL)
#define mutex_unlock(m)
Definition: thread.h:136
void(* start_conn)(SMSCConn *conn)
Definition: smscconn_p.h:246
Mutex * flow_mutex
Definition: smscconn_p.h:157
volatile sig_atomic_t is_stopped
Definition: smscconn_p.h:169
smscconn_status_t status
Definition: smscconn_p.h:151
#define mutex_lock(m)
Definition: thread.h:130

◆ smscconn_status()

int smscconn_status ( SMSCConn conn)

Definition at line 724 of file smscconn.c.

References gw_assert(), and smscconn::status.

Referenced by bb_smscconn_send_failed(), handle_split(), smsc2_restart_smsc(), and smsc2_stop_smsc().

725 {
726  gw_assert(conn != NULL);
727 
728  return conn->status;
729 }
gw_assert(wtls_machine->packet_to_send !=NULL)
smscconn_status_t status
Definition: smscconn_p.h:151

◆ smscconn_stop()

int smscconn_stop ( SMSCConn conn)

Definition at line 516 of file smscconn.c.

References smscconn::flow_mutex, gw_assert(), smscconn::is_stopped, mutex_lock, mutex_unlock, SMSCCONN_ALIVE, SMSCCONN_DEAD, smscconn::status, smscconn::stop_conn, and smscconn::why_killed.

Referenced by smsc2_suspend().

517 {
518  gw_assert(conn != NULL);
519  mutex_lock(conn->flow_mutex);
520  if (conn->status == SMSCCONN_DEAD || conn->is_stopped != 0
521  || conn->why_killed != SMSCCONN_ALIVE)
522  {
523  mutex_unlock(conn->flow_mutex);
524  return -1;
525  }
526  conn->is_stopped = 1;
527  mutex_unlock(conn->flow_mutex);
528 
529  if (conn->stop_conn)
530  conn->stop_conn(conn);
531 
532  return 0;
533 }
gw_assert(wtls_machine->packet_to_send !=NULL)
#define mutex_unlock(m)
Definition: thread.h:136
void(* stop_conn)(SMSCConn *conn)
Definition: smscconn_p.h:247
smscconn_killed_t why_killed
Definition: smscconn_p.h:153
Mutex * flow_mutex
Definition: smscconn_p.h:157
volatile sig_atomic_t is_stopped
Definition: smscconn_p.h:169
smscconn_status_t status
Definition: smscconn_p.h:151
#define mutex_lock(m)
Definition: thread.h:130

◆ smscconn_usable()

int smscconn_usable ( SMSCConn conn,
Msg msg 
)

Definition at line 573 of file smscconn.c.

References smscconn::allowed_prefix, smscconn::allowed_prefix_regex, smscconn::allowed_smsc_id, smscconn::allowed_smsc_id_regex, smscconn::denied_prefix, smscconn::denied_prefix_regex, smscconn::denied_smsc_id, smscconn::denied_smsc_id_regex, does_prefix_match(), gw_assert(), gwlist_search(), msg, octstr_item_match(), smscconn::preferred_prefix, smscconn::preferred_prefix_regex, smscconn::preferred_smsc_id, SMSCCONN_ACTIVE_RECV, SMSCCONN_ALIVE, SMSCCONN_DEAD, smscconn::status, and smscconn::why_killed.

Referenced by smsc2_rout().

574 {
575  gw_assert(conn != NULL);
576  gw_assert(msg != NULL && msg_type(msg) == sms);
577 
578  /* dead transmitter or active receiver connections are not feasible */
579  if (conn->status == SMSCCONN_DEAD || conn->status == SMSCCONN_ACTIVE_RECV ||
580  conn->why_killed != SMSCCONN_ALIVE)
581  return -1;
582 
583  /* if allowed-smsc-id set, then only allow this SMSC if message
584  * smsc-id matches any of its allowed SMSCes
585  */
586  if (conn->allowed_smsc_id && (msg->sms.smsc_id == NULL ||
587  gwlist_search(conn->allowed_smsc_id, msg->sms.smsc_id, octstr_item_match) == NULL)) {
588  return -1;
589  }
590  /* ..if no allowed-smsc-id set but denied-smsc-id and message smsc-id
591  * is set, deny message if smsc-ids match */
592  else if (conn->denied_smsc_id && msg->sms.smsc_id != NULL &&
593  gwlist_search(conn->denied_smsc_id, msg->sms.smsc_id, octstr_item_match) != NULL) {
594  return -1;
595  }
596 
597  if (conn->allowed_smsc_id_regex) {
598  if (msg->sms.smsc_id == NULL)
599  return -1;
600 
601  if (gw_regex_match_pre(conn->allowed_smsc_id_regex, msg->sms.smsc_id) == 0)
602  return -1;
603  }
604  else if (conn->denied_smsc_id_regex && msg->sms.smsc_id != NULL) {
605  if (gw_regex_match_pre(conn->denied_smsc_id_regex, msg->sms.smsc_id) == 1)
606  return -1;
607  }
608 
609  /* Have allowed */
610  if (conn->allowed_prefix && !conn->denied_prefix &&
611  (does_prefix_match(conn->allowed_prefix, msg->sms.receiver) != 1))
612  return -1;
613 
614  if (conn->allowed_prefix_regex && !conn->denied_prefix_regex &&
615  gw_regex_match_pre(conn->allowed_prefix_regex, msg->sms.receiver) == 0)
616  return -1;
617 
618  /* Have denied */
619  if (conn->denied_prefix && !conn->allowed_prefix &&
620  (does_prefix_match(conn->denied_prefix, msg->sms.receiver) == 1))
621  return -1;
622 
623  if (conn->denied_prefix_regex && !conn->allowed_prefix_regex &&
624  gw_regex_match_pre(conn->denied_prefix_regex, msg->sms.receiver) == 1)
625  return -1;
626 
627  /* Have allowed and denied */
628  if (conn->denied_prefix && conn->allowed_prefix &&
629  (does_prefix_match(conn->allowed_prefix, msg->sms.receiver) != 1) &&
630  (does_prefix_match(conn->denied_prefix, msg->sms.receiver) == 1))
631  return -1;
632 
633  if (conn->allowed_prefix_regex && conn->denied_prefix_regex &&
634  gw_regex_match_pre(conn->allowed_prefix_regex, msg->sms.receiver) == 0 &&
635  gw_regex_match_pre(conn->denied_prefix_regex, msg->sms.receiver) == 1)
636  return -1;
637 
638  /* then see if it is preferred one */
639  if (conn->preferred_smsc_id && msg->sms.smsc_id != NULL &&
640  gwlist_search(conn->preferred_smsc_id, msg->sms.smsc_id, octstr_item_match) != NULL)
641  return 1;
642 
643  if (conn->preferred_prefix &&
644  does_prefix_match(conn->preferred_prefix, msg->sms.receiver) == 1)
645  return 1;
646 
647  if (conn->preferred_prefix_regex &&
648  gw_regex_match_pre(conn->preferred_prefix_regex, msg->sms.receiver) == 1)
649  return 1;
650 
651  return 0;
652 }
regex_t * allowed_smsc_id_regex
Definition: smscconn_p.h:180
void * gwlist_search(List *list, void *pattern, int(*cmp)(void *, void *))
Definition: list.c:486
gw_assert(wtls_machine->packet_to_send !=NULL)
Octstr * denied_prefix
Definition: smscconn_p.h:186
msg_type
Definition: msg.h:73
Octstr * allowed_prefix
Definition: smscconn_p.h:184
List * denied_smsc_id
Definition: smscconn_p.h:178
regex_t * preferred_prefix_regex
Definition: smscconn_p.h:189
smscconn_killed_t why_killed
Definition: smscconn_p.h:153
regex_t * allowed_prefix_regex
Definition: smscconn_p.h:185
int does_prefix_match(Octstr *prefix, Octstr *number)
Definition: utils.c:850
List * preferred_smsc_id
Definition: smscconn_p.h:179
int octstr_item_match(void *item, void *pattern)
Definition: octstr.c:1661
Octstr * preferred_prefix
Definition: smscconn_p.h:188
regex_t * denied_prefix_regex
Definition: smscconn_p.h:187
List * allowed_smsc_id
Definition: smscconn_p.h:177
smscconn_status_t status
Definition: smscconn_p.h:151
regex_t * denied_smsc_id_regex
Definition: smscconn_p.h:181
static XMLRPCDocument * msg
Definition: test_xmlrpc.c:86

Variable Documentation

◆ split_msg_counter

Counter* split_msg_counter

Definition at line 159 of file bb_smscconn.c.

Referenced by smsc2_cleanup(), smsc2_start(), and smscconn_send().

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