Kannel: Open Source WAP and SMS gateway  $Revision: 5037 $
smscconn_p.h File Reference
#include <signal.h>
#include "gwlib/gwlib.h"
#include "gwlib/regex.h"
#include "smscconn.h"
#include "load.h"

Go to the source code of this file.

Data Structures

struct  smscconn
 

Functions

int smsc_wrapper_create (SMSCConn *conn, CfgGroup *cfg)
 
int smsc_fake_create (SMSCConn *conn, CfgGroup *cfg)
 
int smsc_cimd2_create (SMSCConn *conn, CfgGroup *cfg)
 
int smsc_emi2_create (SMSCConn *conn, CfgGroup *cfg)
 
int smsc_http_create (SMSCConn *conn, CfgGroup *cfg)
 
int smsc_smpp_create (SMSCConn *conn, CfgGroup *cfg)
 
int smsc_cgw_create (SMSCConn *conn, CfgGroup *cfg)
 
int smsc_at2_create (SMSCConn *conn, CfgGroup *cfg)
 
int smsc_smasi_create (SMSCConn *conn, CfgGroup *cfg)
 
int smsc_oisd_create (SMSCConn *conn, CfgGroup *cfg)
 
int smsc_loopback_create (SMSCConn *conn, CfgGroup *cfg)
 

Function Documentation

int smsc_at2_create ( SMSCConn conn,
CfgGroup cfg 
)

Definition at line 1519 of file smsc_at.c.

References at2_add_msg_cb(), AT2_DEFAULT_SMS_POLL_INTERVAL, at2_device_thread(), at2_queued_cb(), at2_read_modems(), at2_shutdown_cb(), at2_start_cb(), cfg_get, cfg_get_bool(), cfg_get_configfile(), cfg_get_integer(), PrivAT2data::configfile, PrivAT2data::conn, smscconn::connect_time, smscconn::data, PrivAT2data::device, PrivAT2data::device_thread, error(), PrivAT2data::fd, gw_prioqueue_create(), gw_prioqueue_destroy(), gwlist_create, gwthread_create, PrivAT2data::ilb, info(), PrivAT2data::is_serial, PrivAT2data::keepalive, PrivAT2data::lines, PrivAT2data::load, load_add_interval(), load_create_real(), PrivAT2data::login_prompt, PrivAT2data::max_error_count, PrivAT2data::modem, PrivAT2data::my_number, ModemDef::name, PrivAT2data::name, smscconn::name, O_DESTROY, octstr_compare(), octstr_create, octstr_duplicate, octstr_format(), octstr_get_cstr, octstr_imm(), octstr_len(), octstr_str_compare(), PrivAT2data::outgoing_queue, PrivAT2data::password, PrivAT2data::password_prompt, PrivAT2data::pending_incoming_messages, PrivAT2data::phase2plus, PrivAT2data::pin, PrivAT2data::pin_ready, smscconn::queued, PrivAT2data::rawtcp_host, PrivAT2data::rawtcp_port, smscconn::send_msg, PrivAT2data::shutdown, smscconn::shutdown, PrivAT2data::sms_center, PrivAT2data::sms_memory_poll_interval, sms_priority_compare(), SMSCCONN_CONNECTING, SMSCCONN_DEAD, SMSCCONN_KILLED_CANNOT_CONNECT, PrivAT2data::speed, smscconn::start_conn, smscconn::status, PrivAT2data::use_telnet, PrivAT2data::username, PrivAT2data::validityperiod, and smscconn::why_killed.

Referenced by smscconn_create().

1520 {
1522  Octstr *modem_type_string;
1523  long portno; /* has to be long because of cfg_get_integer */
1524 
1525  privdata = gw_malloc(sizeof(PrivAT2data));
1526  memset(privdata, 0, sizeof(PrivAT2data));
1529 
1530  privdata->configfile = cfg_get_configfile(cfg);
1531 
1532  privdata->device = cfg_get(cfg, octstr_imm("device"));
1533  if (privdata->device == NULL) {
1534  error(0, "AT2[-]: 'device' missing in at2 configuration.");
1535  goto error;
1536  }
1537 
1538  if (octstr_str_compare(privdata->device, "rawtcp") == 0) {
1539  privdata->rawtcp_host = cfg_get(cfg, octstr_imm("host"));
1540  if (privdata->rawtcp_host == NULL) {
1541  error(0, "AT2[-]: 'host' missing in at2 rawtcp configuration.");
1542  goto error;
1543  }
1544  if (cfg_get_integer(&portno, cfg, octstr_imm("port")) == -1) {
1545  error(0, "AT2[-]: 'port' missing in at2 rawtcp configuration.");
1546  goto error;
1547  }
1548  privdata->rawtcp_port = portno;
1549  privdata->is_serial = 0;
1550  privdata->use_telnet = 0;
1551  } else if (octstr_str_compare(privdata->device, "telnet") == 0) {
1552  privdata->rawtcp_host = cfg_get(cfg, octstr_imm("host"));
1553  if (privdata->rawtcp_host == NULL) {
1554  error(0, "AT2[-]: 'host' missing in at2 telnet configuration.");
1555  goto error;
1556  }
1557  if (cfg_get_integer(&portno, cfg, octstr_imm("port")) == -1) {
1558  error(0, "AT2[-]: 'port' missing in at2 telnet configuration.");
1559  goto error;
1560  }
1561  privdata->rawtcp_port = portno;
1562  privdata->is_serial = 0;
1563  privdata->use_telnet = 1;
1564  } else {
1565  privdata->is_serial = 1;
1566  privdata->use_telnet = 0;
1567  }
1568 
1569  privdata->name = cfg_get(cfg, octstr_imm("smsc-id"));
1570  if (privdata->name == NULL) {
1571  privdata->name = octstr_duplicate(privdata->device);
1572  }
1573 
1574  privdata->speed = 0;
1575  cfg_get_integer(&privdata->speed, cfg, octstr_imm("speed"));
1576 
1577  privdata->keepalive = 0;
1578  cfg_get_integer(&privdata->keepalive, cfg, octstr_imm("keepalive"));
1579 
1580  cfg_get_bool(&privdata->sms_memory_poll_interval, cfg, octstr_imm("sim-buffering"));
1581  if (privdata->sms_memory_poll_interval) {
1582  if (privdata->keepalive)
1583  privdata->sms_memory_poll_interval = privdata->keepalive;
1584  else
1586  }
1587 
1588  privdata->my_number = cfg_get(cfg, octstr_imm("my-number"));
1589  privdata->sms_center = cfg_get(cfg, octstr_imm("sms-center"));
1590  privdata->username = cfg_get(cfg, octstr_imm("smsc-username"));
1591  privdata->password = cfg_get(cfg, octstr_imm("smsc-password"));
1592  privdata->login_prompt = cfg_get(cfg, octstr_imm("login-prompt"));
1593  privdata->password_prompt = cfg_get(cfg, octstr_imm("password-prompt"));
1594  modem_type_string = cfg_get(cfg, octstr_imm("modemtype"));
1595 
1596  privdata->modem = NULL;
1597 
1598  if (modem_type_string != NULL) {
1599  if (octstr_compare(modem_type_string, octstr_imm("auto")) == 0 ||
1600  octstr_compare(modem_type_string, octstr_imm("autodetect")) == 0)
1601  O_DESTROY(modem_type_string);
1602  }
1603 
1604  if (octstr_len(modem_type_string) == 0) {
1605  info(0, "AT2[%s]: configuration doesn't show modemtype. will autodetect",
1606  octstr_get_cstr(privdata->name));
1607  } else {
1608  info(0, "AT2[%s]: configuration shows modemtype <%s>",
1609  octstr_get_cstr(privdata->name),
1610  octstr_get_cstr(modem_type_string));
1611  privdata->modem = at2_read_modems(privdata, privdata->configfile,
1612  modem_type_string, 0);
1613  if (privdata->modem == NULL) {
1614  info(0, "AT2[%s]: modemtype not found, revert to autodetect",
1615  octstr_get_cstr(privdata->name));
1616  } else {
1617  info(0, "AT2[%s]: read modem definition for <%s>",
1618  octstr_get_cstr(privdata->name),
1619  octstr_get_cstr(privdata->modem->name));
1620  }
1621  O_DESTROY(modem_type_string);
1622  }
1623 
1624  privdata->ilb = octstr_create("");
1625  privdata->fd = -1;
1626  privdata->lines = NULL;
1627  privdata->pin = cfg_get(cfg, octstr_imm("pin"));
1628  privdata->pin_ready = 0;
1629  privdata->conn = conn;
1630  privdata->phase2plus = 0;
1631  privdata->validityperiod = cfg_get(cfg, octstr_imm("validityperiod"));
1632  if (cfg_get_integer((long *) &privdata->max_error_count, cfg, octstr_imm("max-error-count")) == -1)
1633  privdata->max_error_count = -1;
1634 
1635  privdata->load = load_create_real(0);
1636  load_add_interval(privdata->load, 1);
1637 
1638  conn->data = privdata;
1639  conn->name = octstr_format("AT2[%s]", octstr_get_cstr(privdata->name));
1640  conn->status = SMSCCONN_CONNECTING;
1641  conn->connect_time = time(NULL);
1642 
1643  privdata->shutdown = 0;
1644 
1645  if ((privdata->device_thread = gwthread_create(at2_device_thread, conn)) == -1) {
1646  privdata->shutdown = 1;
1647  goto error;
1648  }
1649 
1650  conn->shutdown = at2_shutdown_cb;
1651  conn->queued = at2_queued_cb;
1652  conn->start_conn = at2_start_cb;
1653  conn->send_msg = at2_add_msg_cb;
1654  return 0;
1655 
1656 error:
1657  error(0, "AT2[%s]: Failed to create at2 smsc connection",
1658  octstr_len(privdata->name) ? octstr_get_cstr(privdata->name) : "");
1659  if (privdata != NULL) {
1660  gw_prioqueue_destroy(privdata->outgoing_queue, NULL);
1661  }
1662  gw_free(privdata);
1664  conn->status = SMSCCONN_DEAD;
1665  info(0, "AT2[%s]: exiting", octstr_get_cstr(privdata->name));
1666  return -1;
1667 }
Octstr * name
Definition: smscconn_p.h:173
void error(int err, const char *fmt,...)
Definition: log.c:612
long device_thread
Definition: smsc_at.h:123
static void at2_device_thread(void *arg)
Definition: smsc_at.c:1282
void info(int err, const char *fmt,...)
Definition: log.c:636
Octstr * my_number
Definition: smsc_at.h:137
static long at2_queued_cb(SMSCConn *conn)
Definition: smsc_at.c:1484
Octstr * ilb
Definition: smsc_at.h:129
Octstr * password_prompt
Definition: smsc_at.h:144
gw_prioqueue_t * outgoing_queue
Definition: smsc_at.h:121
#define AT2_DEFAULT_SMS_POLL_INTERVAL
Definition: smsc_at.h:94
int use_telnet
Definition: smsc_at.h:153
void * data
Definition: smscconn_p.h:249
Octstr * cfg_get_configfile(CfgGroup *grp)
Definition: cfg.c:713
long keepalive
Definition: smsc_at.h:127
int load_add_interval(Load *load, int interval)
Definition: load.c:111
#define cfg_get(grp, varname)
Definition: cfg.h:86
Load * load_create_real(int heuristic)
Definition: load.c:97
Octstr * login_prompt
Definition: smsc_at.h:143
ModemDef * modem
Definition: smsc_at.h:122
Octstr * configfile
Definition: smsc_at.h:140
int phase2plus
Definition: smsc_at.h:134
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
void(* start_conn)(SMSCConn *conn)
Definition: smscconn_p.h:245
Octstr * pin
Definition: smsc_at.h:131
Octstr * validityperiod
Definition: smsc_at.h:135
int shutdown
Definition: smsc_at.h:124
int sms_memory_poll_interval
Definition: smsc_at.h:145
smscconn_killed_t why_killed
Definition: smscconn_p.h:153
int pin_ready
Definition: smsc_at.h:132
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:281
long speed
Definition: smsc_at.h:126
int sms_priority_compare(const void *a, const void *b)
Definition: sms.c:395
static int at2_shutdown_cb(SMSCConn *conn, int finish_sending)
Definition: smsc_at.c:1454
int rawtcp_port
Definition: smsc_at.h:151
static ModemDef * at2_read_modems(PrivAT2data *privdata, Octstr *file, Octstr *id, int idnumber)
Definition: smsc_at.c:2758
time_t connect_time
Definition: smscconn_p.h:155
static int at2_add_msg_cb(SMSCConn *conn, Msg *sms)
Definition: smsc_at.c:1508
#define octstr_duplicate(ostr)
Definition: octstr.h:187
Octstr * octstr_format(const char *fmt,...)
Definition: octstr.c:2462
#define gwthread_create(func, arg)
Definition: gwthread.h:90
#define octstr_create(cstr)
Definition: octstr.h:125
#define O_DESTROY(a)
Definition: smsbox.c:97
gw_prioqueue_t * gw_prioqueue_create(int(*cmp)(const void *, const void *))
Definition: gw-prioqueue.c:174
Octstr * sms_center
Definition: smsc_at.h:138
int is_serial
Definition: smsc_at.h:152
Octstr * name
Definition: smsc_at.h:101
long max_error_count
Definition: smsc_at.h:149
Octstr * rawtcp_host
Definition: smsc_at.h:150
long octstr_len(const Octstr *ostr)
Definition: octstr.c:340
int cfg_get_bool(int *n, CfgGroup *grp, Octstr *varname)
Definition: cfg.c:756
void gw_prioqueue_destroy(gw_prioqueue_t *queue, void(*item_destroy)(void *))
Definition: gw-prioqueue.c:201
Octstr * name
Definition: smsc_at.h:139
Octstr * lines
Definition: smsc_at.h:130
Definition: octstr.c:118
List * pending_incoming_messages
Definition: smsc_at.h:148
int(* shutdown)(SMSCConn *conn, int finish_sending)
Definition: smscconn_p.h:229
int cfg_get_integer(long *n, CfgGroup *grp, Octstr *varname)
Definition: cfg.c:739
int octstr_str_compare(const Octstr *ostr, const char *str)
Definition: octstr.c:971
smscconn_status_t status
Definition: smscconn_p.h:151
Octstr * password
Definition: smsc_at.h:142
#define gwlist_create()
Definition: list.h:136
long(* queued)(SMSCConn *conn)
Definition: smscconn_p.h:240
int(* send_msg)(SMSCConn *conn, Msg *msg)
Definition: smscconn_p.h:235
static void at2_start_cb(SMSCConn *conn)
Definition: smsc_at.c:1495
Octstr * device
Definition: smsc_at.h:125
Octstr * username
Definition: smsc_at.h:141
Load * load
Definition: smsc_at.h:154
SMSCConn * conn
Definition: smsc_at.h:133
int octstr_compare(const Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:869
int smsc_cgw_create ( SMSCConn conn,
CfgGroup cfg 
)

Definition at line 431 of file smsc_cgw.c.

References allow_ip, privdata::allow_ip, privdata::appname, cfg_get, cfg_get_integer(), cgw_add_msg_cb(), CGW_DEFPORT, cgw_listener(), cgw_open_listening_socket(), cgw_queued_cb(), cgw_sender(), cgw_shutdown_cb(), cgw_start_cb(), CGW_TRN_MAX, privdata::check_time, smscconn::connect_time, smscconn::data, deny_ip, privdata::deny_ip, privdata::dlr, error(), gwlist_create, gwlist_destroy(), gwthread_create, host, privdata::host, info(), privdata::listening_socket, smscconn::name, privdata::nexttrn, octstr_create, octstr_destroy(), octstr_format(), octstr_imm(), our_port, privdata::our_port, privdata::outgoing_queue, privdata::port, smscconn::queued, privdata::receiver_thread, privdata::rport, smscconn::send_msg, privdata::sender_thread, privdata::sendtime, privdata::shutdown, smscconn::shutdown, SMSCCONN_CONNECTING, SMSCCONN_DEAD, SMSCCONN_KILLED_CANNOT_CONNECT, smscconn::start_conn, smscconn::status, privdata::waitack, and smscconn::why_killed.

Referenced by smscconn_create().

432 {
434  Octstr *allow_ip, *deny_ip, *host, *appname;
435  long portno, our_port, waitack;
436  int i;
437 
438  privdata = gw_malloc(sizeof(PrivData));
439  privdata->outgoing_queue = gwlist_create();
440  privdata->listening_socket = -1;
441 
442  if (cfg_get_integer(&portno, cfg, octstr_imm("port")) == -1)
443  portno = 0;
444  privdata->port = portno;
445 
446  if (cfg_get_integer(&portno, cfg, octstr_imm("receive-port")) < 0)
447  portno = 0;
448  privdata->rport = portno;
449 
450  host = cfg_get(cfg, octstr_imm("host"));
451  appname = cfg_get(cfg, octstr_imm("appname"));
452 
453  if (cfg_get_integer(&our_port, cfg, octstr_imm("our-port")) == -1)
454  privdata->our_port = 0; /* 0 means use any port */
455  else
456  privdata->our_port = our_port;
457 
458  allow_ip = cfg_get(cfg, octstr_imm("connect-allow-ip"));
459  if (allow_ip)
460  deny_ip = octstr_create("*.*.*.*");
461  else
462  deny_ip = NULL;
463 
464  if (cfg_get_integer(&waitack, cfg, octstr_imm("wait-ack")) < 0)
465  privdata->waitack = 60;
466  else
467  privdata->waitack = waitack;
468 
469  if (privdata->port <= 0 || privdata->port > 65535) {
470  info(1, "No port defined for cgw -> using default (%d)", CGW_DEFPORT);
471  privdata->port = CGW_DEFPORT;
472  }
473 
474 
475  if (host == NULL) {
476  error(0, "'host' missing in cgw configuration.");
477  goto error;
478  }
479 
480  if (appname == NULL)
481  appname = octstr_create("send");
482 
483  privdata->allow_ip = allow_ip;
484  privdata->deny_ip = deny_ip;
485  privdata->host = host;
486  privdata->appname = appname;
487  privdata->nexttrn = 0;
488  privdata->check_time = 0;
489 
490  for (i = 0; i < CGW_TRN_MAX; i++) {
491  privdata->sendtime[i] = 0;
492  privdata->dlr[i] = 0;
493  }
494 
495  if (privdata->rport > 0 && cgw_open_listening_socket(conn,privdata) < 0) {
496  gw_free(privdata);
497  privdata = NULL;
498  goto error;
499  }
500 
501 
502  conn->data = privdata;
503 
504  conn->name = octstr_format("CGW:%d", privdata->port);
505 
506  privdata->shutdown = 0;
507 
508  conn->status = SMSCCONN_CONNECTING;
509  conn->connect_time = time(NULL);
510 
511  if (privdata->rport > 0 && (privdata->receiver_thread = gwthread_create(cgw_listener, conn)) == -1)
512  goto error;
513 
514  if ((privdata->sender_thread = gwthread_create(cgw_sender, conn)) == -1) {
515  privdata->shutdown = 1;
516  goto error;
517  }
518 
519  conn->shutdown = cgw_shutdown_cb;
520  conn->queued = cgw_queued_cb;
521  conn->start_conn = cgw_start_cb;
522  conn->send_msg = cgw_add_msg_cb;
523 
524  return 0;
525 
526 error:
527  error(0, "Failed to create CGW smsc connection");
528  if (privdata != NULL)
529  gwlist_destroy(privdata->outgoing_queue, NULL);
530 
531  gw_free(privdata);
532  octstr_destroy(host);
533  octstr_destroy(allow_ip);
534  octstr_destroy(deny_ip);
535  octstr_destroy(appname);
536 
538  conn->status = SMSCCONN_DEAD;
539  info(0, "exiting");
540  return -1;
541 }
#define CGW_DEFPORT
Definition: smsc_cgw.c:123
int port
Definition: smsc_cgw.c:159
Octstr * name
Definition: smscconn_p.h:173
void error(int err, const char *fmt,...)
Definition: log.c:612
void info(int err, const char *fmt,...)
Definition: log.c:636
static long our_port
Definition: radius_acct.c:87
static void cgw_start_cb(SMSCConn *conn)
Definition: smsc_cgw.c:588
void * data
Definition: smscconn_p.h:249
int waitack
Definition: smsc_cgw.c:171
List * outgoing_queue
Definition: smsc_cgw.c:153
static Octstr * host
Definition: fakesmsc.c:121
#define cfg_get(grp, varname)
Definition: cfg.h:86
static int cgw_add_msg_cb(SMSCConn *conn, Msg *sms)
Definition: smsc_cgw.c:549
void(* start_conn)(SMSCConn *conn)
Definition: smscconn_p.h:245
smscconn_killed_t why_killed
Definition: smscconn_p.h:153
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:281
static int cgw_shutdown_cb(SMSCConn *conn, int finish_sending)
Definition: smsc_cgw.c:562
time_t connect_time
Definition: smscconn_p.h:155
static Octstr * deny_ip
Definition: bb_udp.c:112
Octstr * allow_ip
Definition: smsc_cgw.c:164
Octstr * host
Definition: smsc_cgw.c:163
Octstr * octstr_format(const char *fmt,...)
Definition: octstr.c:2462
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:322
int rport
Definition: smsc_cgw.c:160
#define gwthread_create(func, arg)
Definition: gwthread.h:90
#define octstr_create(cstr)
Definition: octstr.h:125
long check_time
Definition: smsc_cgw.c:173
#define CGW_TRN_MAX
Definition: smsc_cgw.c:125
static void cgw_sender(void *arg)
Definition: smsc_cgw.c:616
static Octstr * allow_ip
Definition: bb_udp.c:111
int shutdown
Definition: smsc_cgw.c:156
long sender_thread
Definition: smsc_cgw.c:155
static long cgw_queued_cb(SMSCConn *conn)
Definition: smsc_cgw.c:599
Definition: octstr.c:118
int(* shutdown)(SMSCConn *conn, int finish_sending)
Definition: smscconn_p.h:229
int cfg_get_integer(long *n, CfgGroup *grp, Octstr *varname)
Definition: cfg.c:739
smscconn_status_t status
Definition: smscconn_p.h:151
#define gwlist_create()
Definition: list.h:136
long(* queued)(SMSCConn *conn)
Definition: smscconn_p.h:240
int(* send_msg)(SMSCConn *conn, Msg *msg)
Definition: smscconn_p.h:235
long receiver_thread
Definition: smsc_cgw.c:154
int listening_socket
Definition: smsc_cgw.c:157
Octstr * appname
Definition: smsc_cgw.c:165
time_t sendtime[CGW_TRN_MAX]
Definition: smsc_cgw.c:168
int our_port
Definition: smsc_cgw.c:161
static void cgw_listener(void *arg)
Definition: smsc_cgw.c:967
Octstr * deny_ip
Definition: smsc_cgw.c:164
static int cgw_open_listening_socket(SMSCConn *conn, PrivData *privdata)
Definition: smsc_cgw.c:945
int dlr[CGW_TRN_MAX]
Definition: smsc_cgw.c:169
int nexttrn
Definition: smsc_cgw.c:172
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)
Definition: list.c:145
int smsc_cimd2_create ( SMSCConn conn,
CfgGroup cfg 
)

Definition at line 2321 of file smsc_cimd2.c.

References cfg_get, cfg_get_bool(), cfg_get_integer(), cimd2_add_msg_cb(), cimd2_destroy(), cimd2_queued_cb(), cimd2_shutdown_cb(), cimd2_start_cb(), cimd2_stop_cb(), privdata::conn, smscconn::data, debug(), error(), gwlist_add_producer(), gwlist_create, gwthread_create, gwthread_join(), gwthread_wakeup(), privdata::host, smscconn::id, privdata::inbuffer, privdata::io_thread, io_thread(), smscconn::is_stopped, privdata::keepalive, maxlen, privdata::my_number, smscconn::name, privdata::next_ping, privdata::no_dlr, octstr_create, octstr_format(), octstr_get_cstr, octstr_imm(), octstr_len(), octstr_truncate(), ok, privdata::our_port, privdata::outgoing_queue, P_PASSWORD, P_USER_IDENTITY, parm_maxlen(), privdata::password, privdata::port, smscconn::queued, privdata::quitting, privdata::receive_seq, privdata::received, smscconn::send_msg, privdata::send_seq, smscconn::shutdown, privdata::socket, smscconn::start_conn, smscconn::stop_conn, privdata::stopped, privdata::username, and warning().

Referenced by smscconn_create().

2322 {
2323  PrivData *pdata;
2324  int ok;
2325  int maxlen;
2326 
2327  pdata = gw_malloc(sizeof(PrivData));
2328  conn->data = pdata;
2329  pdata->conn = conn;
2330 
2331  pdata->no_dlr = 0;
2332  pdata->quitting = 0;
2333  pdata->socket = -1;
2334  pdata->received = gwlist_create();
2335  pdata->inbuffer = octstr_create("");
2336  pdata->send_seq = 1;
2337  pdata->receive_seq = 0;
2338  pdata->outgoing_queue = gwlist_create();
2339  pdata->stopped = gwlist_create();
2341 
2342  if (conn->is_stopped)
2343  gwlist_add_producer(pdata->stopped);
2344 
2345  pdata->host = cfg_get(grp, octstr_imm("host"));
2346  if (cfg_get_integer(&(pdata->port), grp, octstr_imm("port")) == -1)
2347  pdata->port = 0;
2348  if (cfg_get_integer(&(pdata->our_port), grp, octstr_imm("our-port")) == -1)
2349  pdata->our_port = 0;
2350  pdata->username = cfg_get(grp, octstr_imm("smsc-username"));
2351  pdata->password = cfg_get(grp, octstr_imm("smsc-password"));
2352  pdata->my_number = cfg_get(grp, octstr_imm("my-number"));
2353  if (cfg_get_integer(&(pdata->keepalive), grp,octstr_imm("keepalive")) == -1)
2354  pdata->keepalive = 0;
2355 
2356  cfg_get_bool(&pdata->no_dlr, grp, octstr_imm("no-dlr"));
2357 
2358  /* Check that config is OK */
2359  ok = 1;
2360  if (pdata->host == NULL) {
2361  error(0,"CIMD2[%s]: Configuration file doesn't specify host",
2362  octstr_get_cstr(conn->id));
2363  ok = 0;
2364  }
2365  if (pdata->port == 0) {
2366  error(0,"CIMD2[%s]: Configuration file doesn't specify port",
2367  octstr_get_cstr(conn->id));
2368  ok = 0;
2369  }
2370  if (pdata->username == NULL) {
2371  error(0, "CIMD2[%s]: Configuration file doesn't specify username.",
2372  octstr_get_cstr(conn->id));
2373  ok = 0;
2374  }
2375  if (pdata->password == NULL) {
2376  error(0, "CIMD2[%s]: Configuration file doesn't specify password.",
2377  octstr_get_cstr(conn->id));
2378  ok = 0;
2379  }
2380 
2381  if (!ok) {
2382  cimd2_destroy(pdata);
2383  return -1;
2384  }
2385 
2386  conn->name = octstr_format("CIMD2:%s:%d:%s",
2387  octstr_get_cstr(pdata->host),
2388  pdata->port,
2389  octstr_get_cstr(pdata->username));
2390 
2391 
2392  if (pdata->keepalive > 0) {
2393  debug("bb.sms.cimd2", 0, "CIMD2[%s]: Keepalive set to %ld seconds",
2394  octstr_get_cstr(conn->id),
2395  pdata->keepalive);
2396  pdata->next_ping = time(NULL) + pdata->keepalive;
2397  }
2398 
2399  maxlen = parm_maxlen(P_USER_IDENTITY);
2400  if (octstr_len(pdata->username) > maxlen) {
2401  octstr_truncate(pdata->username, maxlen);
2402  warning(0, "CIMD2[%s]: Truncating username to %d chars",
2403  octstr_get_cstr(conn->id),
2404  maxlen);
2405  }
2406 
2407  maxlen = parm_maxlen(P_PASSWORD);
2408  if (octstr_len(pdata->password) > maxlen) {
2409  octstr_truncate(pdata->password, maxlen);
2410  warning(0, "CIMD2[%s]: Truncating password to %d chars",
2411  octstr_get_cstr(conn->id),
2412  maxlen);
2413  }
2414 
2415  pdata->io_thread = gwthread_create(io_thread, conn);
2416 
2417  if (pdata->io_thread == -1) {
2418 
2419  error(0,"CIMD2[%s]: Couldn't start I/O thread.",
2420  octstr_get_cstr(conn->id));
2421  pdata->quitting = 1;
2422  gwthread_wakeup(pdata->io_thread);
2423  gwthread_join(pdata->io_thread);
2424  cimd2_destroy(pdata);
2425  return -1;
2426  }
2427 
2428  conn->send_msg = cimd2_add_msg_cb;
2429  conn->shutdown = cimd2_shutdown_cb;
2430  conn->queued = cimd2_queued_cb;
2431  conn->start_conn = cimd2_start_cb;
2432  conn->stop_conn = cimd2_stop_cb;
2433 
2434  return 0;
2435 }
int port
Definition: smsc_cgw.c:159
Octstr * name
Definition: smscconn_p.h:173
void error(int err, const char *fmt,...)
Definition: log.c:612
Octstr * inbuffer
Definition: smsc_cimd2.c:112
Octstr * id
Definition: smscconn_p.h:174
void gwthread_join(long thread)
void * data
Definition: smscconn_p.h:249
List * outgoing_queue
Definition: smsc_cgw.c:153
void(* stop_conn)(SMSCConn *conn)
Definition: smscconn_p.h:246
static int parm_maxlen(int parmno)
Definition: smsc_cimd2.c:287
int socket
Definition: smsc_cimd2.c:108
Octstr * password
Definition: smsc_cimd2.c:100
#define cfg_get(grp, varname)
Definition: cfg.h:86
int io_thread
Definition: smsc_cimd2.c:119
static int cimd2_shutdown_cb(SMSCConn *conn, int finish_sending)
Definition: smsc_cimd2.c:2252
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
void(* start_conn)(SMSCConn *conn)
Definition: smscconn_p.h:245
List * stopped
Definition: smsc_cimd2.c:121
int receive_seq
Definition: smsc_cimd2.c:110
time_t next_ping
Definition: smsc_cimd2.c:115
static void io_thread(void *arg)
Definition: smsc_cimd2.c:2164
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:281
Octstr * my_number
Definition: smsc_cimd2.c:105
static void cimd2_start_cb(SMSCConn *conn)
Definition: smsc_cimd2.c:2294
Octstr * username
Definition: smsc_cimd2.c:99
void warning(int err, const char *fmt,...)
Definition: log.c:624
Octstr * host
Definition: smsc_cgw.c:163
int quitting
Definition: smsc_cimd2.c:120
Octstr * octstr_format(const char *fmt,...)
Definition: octstr.c:2462
#define gwthread_create(func, arg)
Definition: gwthread.h:90
#define octstr_create(cstr)
Definition: octstr.h:125
volatile sig_atomic_t is_stopped
Definition: smscconn_p.h:169
int send_seq
Definition: smsc_cimd2.c:109
int no_dlr
Definition: smsc_cimd2.c:106
int maxlen
Definition: smsc_cimd2.c:214
long octstr_len(const Octstr *ostr)
Definition: octstr.c:340
int cfg_get_bool(int *n, CfgGroup *grp, Octstr *varname)
Definition: cfg.c:756
static int cimd2_add_msg_cb(SMSCConn *conn, Msg *sms)
Definition: smsc_cimd2.c:2239
int(* shutdown)(SMSCConn *conn, int finish_sending)
Definition: smscconn_p.h:229
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:690
int cfg_get_integer(long *n, CfgGroup *grp, Octstr *varname)
Definition: cfg.c:739
Definition: wtp_tid.h:82
void gwthread_wakeup(long thread)
static long cimd2_queued_cb(SMSCConn *conn)
Definition: smsc_cimd2.c:2313
List * received
Definition: smsc_cimd2.c:113
#define gwlist_create()
Definition: list.h:136
long(* queued)(SMSCConn *conn)
Definition: smscconn_p.h:240
void octstr_truncate(Octstr *ostr, int new_len)
Definition: octstr.c:1325
int(* send_msg)(SMSCConn *conn, Msg *msg)
Definition: smscconn_p.h:235
void gwlist_add_producer(List *list)
Definition: list.c:383
int our_port
Definition: smsc_cgw.c:161
long keepalive
Definition: smsc_cimd2.c:104
static void cimd2_destroy(PrivData *pdata)
Definition: smsc_cimd2.c:1929
static void cimd2_stop_cb(SMSCConn *conn)
Definition: smsc_cimd2.c:2305
SMSCConn * conn
Definition: smsc_cimd2.c:118
int smsc_emi2_create ( SMSCConn conn,
CfgGroup cfg 
)

Definition at line 1612 of file smsc_emi.c.

References add_msg_cb(), allow_ip, privdata::allow_ip, privdata::alt_charset, privdata::alt_host, privdata::alt_port, privdata::can_write, cfg_get, cfg_get_integer(), privdata::check_time, smscconn::connect_time, smscconn::data, deny_ip, privdata::deny_ip, emi2_listener(), EMI2_MAX_TRN, emi2_open_listening_socket(), emi2_sender(), error(), privdata::flowcontrol, gw_prioqueue_create(), gw_prioqueue_destroy(), gwthread_create, gwthread_join(), gwthread_wakeup(), host, privdata::host, privdata::idle_timeout, info(), privdata::keepalive, privdata::last_activity_time, privdata::listening_socket, privdata::my_number, privdata::nadc, privdata::name, smscconn::name, privdata::npid, octstr_append(), octstr_append_char(), octstr_append_decimal(), octstr_create, octstr_destroy(), octstr_format(), octstr_get_cstr, octstr_imm(), octstr_len(), smscconn::our_host, our_port, privdata::our_port, privdata::outgoing_queue, privdata::password, privdata::port, privdata::priv_nexttrn, smscconn::queued, queued_cb(), privdata::receiver_thread, privdata::rport, smscconn::send_msg, privdata::sender_thread, privdata::sendtime, privdata::shutdown, smscconn::shutdown, shutdown_cb(), privdata::slots, sms_priority_compare(), SMSCCONN_CONNECTING, SMSCCONN_DEAD, SMSCCONN_KILLED_CANNOT_CONNECT, start_cb(), smscconn::start_conn, smscconn::status, privdata::unacked, privdata::username, privdata::waitack, privdata::waitack_expire, warning(), smscconn::why_killed, and privdata::window.

Referenced by smscconn_create().

1613 {
1614  PrivData *privdata;
1615  Octstr *allow_ip, *deny_ip, *host, *alt_host;
1616  long portno, our_port, keepalive, flowcontrol, waitack,
1617  idle_timeout, alt_portno, alt_charset, waitack_expire;
1618  long window;
1619  /* has to be long because of cfg_get_integer */
1620  int i;
1621 
1622  allow_ip = deny_ip = host = alt_host = NULL;
1623 
1624  privdata = gw_malloc(sizeof(PrivData));
1626  privdata->listening_socket = -1;
1627  privdata->can_write = 1;
1628  privdata->priv_nexttrn = 0;
1629  privdata->last_activity_time = 0;
1630  privdata->check_time = 0;
1631 
1632  host = cfg_get(cfg, octstr_imm("host"));
1633  if (host == NULL) {
1634  error(0, "EMI2[-]: 'host' missing in emi2 configuration.");
1635  goto error;
1636  }
1637  privdata->host = host;
1638 
1639  if (cfg_get_integer(&portno, cfg, octstr_imm("port")) == -1)
1640  portno = 0;
1641  privdata->port = portno;
1642  if (privdata->port <= 0 || privdata->port > 65535) {
1643  error(0, "EMI2[%s]: 'port' missing/invalid in emi2 configuration.",
1644  octstr_get_cstr(host));
1645  goto error;
1646  }
1647 
1648  if (cfg_get_integer(&our_port, cfg, octstr_imm("our-port")) == -1)
1649  privdata->our_port = 0; /* 0 means use any port */
1650  else
1651  privdata->our_port = our_port;
1652 
1653  privdata->name = cfg_get(cfg, octstr_imm("smsc-id"));
1654  if(privdata->name == NULL) {
1655  privdata->name = octstr_create("");
1656 
1657  /* Add our_host */
1658  if(octstr_len(conn->our_host)) {
1659  octstr_append(privdata->name, conn->our_host);
1660  }
1661 
1662  /* Add our_port */
1663  if(privdata->our_port != 0) {
1664  /* if we have our_port but not our_host, add kannel:our_port */
1665  if(octstr_len(privdata->name) == 0) {
1666  octstr_append(privdata->name, octstr_imm("kannel"));
1667  }
1668  octstr_append_char(privdata->name, ':');
1669  octstr_append_decimal(privdata->name, privdata->our_port);
1670  } else {
1671  if(octstr_len(privdata->name) != 0) {
1672  octstr_append(privdata->name, octstr_imm(":*"));
1673  }
1674  }
1675 
1676  /* if we have our_host neither our_port */
1677  if(octstr_len(privdata->name) != 0)
1678  octstr_append(privdata->name, octstr_imm("->"));
1679 
1680  octstr_append(privdata->name, privdata->host);
1681  octstr_append_char(privdata->name, ':');
1682  octstr_append_decimal(privdata->name, privdata->port);
1683  }
1684 
1685 
1686  if (cfg_get_integer(&idle_timeout, cfg, octstr_imm("idle-timeout")) == -1)
1687  idle_timeout = 0;
1688 
1689  privdata->idle_timeout = idle_timeout;
1690 
1691  alt_host = cfg_get(cfg, octstr_imm("alt-host"));
1692  privdata->alt_host = alt_host;
1693 
1694  if (cfg_get_integer(&portno, cfg, octstr_imm("receive-port")) < 0)
1695  portno = 0;
1696  privdata->rport = portno;
1697 
1698  if (cfg_get_integer(&alt_portno, cfg, octstr_imm("alt-port")) < 0)
1699  alt_portno = 0;
1700  privdata->alt_port = alt_portno;
1701 
1702  allow_ip = cfg_get(cfg, octstr_imm("connect-allow-ip"));
1703  if (allow_ip)
1704  deny_ip = octstr_create("*.*.*.*");
1705  else
1706  deny_ip = NULL;
1707  privdata->username = cfg_get(cfg, octstr_imm("smsc-username"));
1708  privdata->password = cfg_get(cfg, octstr_imm("smsc-password"));
1709 
1710  privdata->my_number = cfg_get(cfg, octstr_imm("my-number"));
1711 
1712  privdata->npid = cfg_get(cfg, octstr_imm("notification-pid"));
1713  privdata->nadc = cfg_get(cfg, octstr_imm("notification-addr"));
1714 
1715  if ( (privdata->username == NULL && privdata->my_number == NULL)
1716  || cfg_get_integer(&keepalive, cfg, octstr_imm("keepalive")) < 0)
1717  privdata->keepalive = 0;
1718  else
1719  privdata->keepalive = keepalive;
1720 
1721  if (cfg_get_integer(&flowcontrol, cfg, octstr_imm("flow-control")) < 0)
1722  privdata->flowcontrol = 0;
1723  else
1724  privdata->flowcontrol = flowcontrol;
1725  if (privdata->flowcontrol < 0 || privdata->flowcontrol > 1) {
1726  error(0, "EMI2[%s]: 'flow-control' invalid in emi2 configuration.",
1727  octstr_get_cstr(privdata->name));
1728  goto error;
1729  }
1730 
1731  if (cfg_get_integer(&window, cfg, octstr_imm("window")) < 0)
1732  privdata->window = EMI2_MAX_TRN;
1733  else
1734  privdata->window = window;
1735  if (privdata->window > EMI2_MAX_TRN) {
1736  warning(0, "EMI2[%s]: Value of 'window' should be lesser or equal to %d..",
1737  octstr_get_cstr(privdata->name), EMI2_MAX_TRN);
1738  privdata->window = EMI2_MAX_TRN;
1739  }
1740 
1741  if (cfg_get_integer(&waitack, cfg, octstr_imm("wait-ack")) < 0)
1742  privdata->waitack = 60;
1743  else
1744  privdata->waitack = waitack;
1745  if (privdata->waitack < 30 ) {
1746  error(0, "EMI2[%s]: 'wait-ack' invalid in emi2 configuration.",
1747  octstr_get_cstr(privdata->name));
1748  goto error;
1749  }
1750 
1751  if (cfg_get_integer(&waitack_expire, cfg, octstr_imm("wait-ack-expire")) < 0)
1752  privdata->waitack_expire = 0;
1753  else
1754  privdata->waitack_expire = waitack_expire;
1755  if (privdata->waitack_expire >3 ) {
1756  error(0, "EMI2[%s]: 'wait-ack-expire' invalid in emi2 configuration.",
1757  octstr_get_cstr(privdata->name));
1758  goto error;
1759  }
1760 
1761  if (privdata->rport < 0 || privdata->rport > 65535) {
1762  error(0, "EMI2[%s]: 'receive-port' missing/invalid in emi2 configuration.",
1763  octstr_get_cstr(privdata->name));
1764  goto error;
1765  }
1766 
1767  if (cfg_get_integer(&alt_charset, cfg, octstr_imm("alt-charset")) < 0)
1768  privdata->alt_charset = 0;
1769  else
1770  privdata->alt_charset = alt_charset;
1771 
1772  privdata->allow_ip = allow_ip;
1773  privdata->deny_ip = deny_ip;
1774 
1775  if (privdata->rport > 0 && emi2_open_listening_socket(conn,privdata) < 0) {
1776  gw_free(privdata);
1777  privdata = NULL;
1778  goto error;
1779  }
1780 
1781  conn->data = privdata;
1782 
1783  conn->name = octstr_format("EMI2:%S:%d:%S", privdata->host, privdata->port,
1784  privdata->username ? privdata->username : octstr_imm("null"));
1785 
1786  privdata->shutdown = 0;
1787 
1788  for (i = 0; i < EMI2_MAX_TRN; i++)
1789  privdata->slots[i].sendtime = 0;
1790  privdata->unacked = 0;
1791 
1792  conn->status = SMSCCONN_CONNECTING;
1793  conn->connect_time = time(NULL);
1794 
1795  if ( privdata->rport > 0 && (privdata->receiver_thread =
1796  gwthread_create(emi2_listener, conn)) == -1)
1797  goto error;
1798 
1799  if ((privdata->sender_thread = gwthread_create(emi2_sender, conn)) == -1) {
1800  privdata->shutdown = 1;
1801  if (privdata->rport > 0) {
1802  gwthread_wakeup(privdata->receiver_thread);
1803  gwthread_join(privdata->receiver_thread);
1804  }
1805  goto error;
1806  }
1807 
1808  conn->shutdown = shutdown_cb;
1809  conn->queued = queued_cb;
1810  conn->start_conn = start_cb;
1811  conn->send_msg = add_msg_cb;
1812 
1813  return 0;
1814 
1815 error:
1816  error(0, "EMI2[%s]: Failed to create emi2 smsc connection",
1817  (privdata ? octstr_get_cstr(privdata->name) : "-"));
1818  if (privdata != NULL) {
1819  gw_prioqueue_destroy(privdata->outgoing_queue, NULL);
1820  }
1821  gw_free(privdata);
1822  octstr_destroy(allow_ip);
1823  octstr_destroy(deny_ip);
1824  octstr_destroy(host);
1826  conn->status = SMSCCONN_DEAD;
1827  info(0, "EMI2[%s]: exiting", (privdata ? octstr_get_cstr(privdata->name) : "-"));
1828  return -1;
1829 }
int port
Definition: smsc_cgw.c:159
Octstr * name
Definition: smscconn_p.h:173
void error(int err, const char *fmt,...)
Definition: log.c:612
void info(int err, const char *fmt,...)
Definition: log.c:636
static long our_port
Definition: radius_acct.c:87
time_t last_activity_time
Definition: smsc_emi.c:126
int window
Definition: smsc_emi.c:121
void octstr_append(Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:1502
void gwthread_join(long thread)
void * data
Definition: smscconn_p.h:249
int priv_nexttrn
Definition: smsc_emi.c:123
int waitack
Definition: smsc_cgw.c:171
List * outgoing_queue
Definition: smsc_cgw.c:153
void octstr_append_char(Octstr *ostr, int ch)
Definition: octstr.c:1515
Octstr * password
Definition: smsc_cimd2.c:100
static Octstr * host
Definition: fakesmsc.c:121
Octstr * npid
Definition: smsc_emi.c:132
#define cfg_get(grp, varname)
Definition: cfg.h:86
int can_write
Definition: smsc_emi.c:122
Octstr * our_host
Definition: smscconn_p.h:192
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
void(* start_conn)(SMSCConn *conn)
Definition: smscconn_p.h:245
int flowcontrol
Definition: smsc_emi.c:118
static int shutdown_cb(SMSCConn *conn, int finish_sending)
Definition: smsc_emi.c:1559
smscconn_killed_t why_killed
Definition: smscconn_p.h:153
static void emi2_sender(void *arg)
Definition: smsc_emi.c:1357
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:281
int sms_priority_compare(const void *a, const void *b)
Definition: sms.c:395
static int emi2_open_listening_socket(SMSCConn *conn, PrivData *privdata)
Definition: smsc_emi.c:1459
Octstr * my_number
Definition: smsc_cimd2.c:105
#define EMI2_MAX_TRN
Definition: smsc_emi.c:93
time_t connect_time
Definition: smscconn_p.h:155
static Octstr * deny_ip
Definition: bb_udp.c:112
Octstr * username
Definition: smsc_cimd2.c:99
Octstr * allow_ip
Definition: smsc_cgw.c:164
void warning(int err, const char *fmt,...)
Definition: log.c:624
Octstr * host
Definition: smsc_cgw.c:163
Octstr * octstr_format(const char *fmt,...)
Definition: octstr.c:2462
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:322
int rport
Definition: smsc_cgw.c:160
#define gwthread_create(func, arg)
Definition: gwthread.h:90
#define octstr_create(cstr)
Definition: octstr.h:125
long check_time
Definition: smsc_cgw.c:173
Octstr * name
Definition: smsc_emi.c:96
gw_prioqueue_t * gw_prioqueue_create(int(*cmp)(const void *, const void *))
Definition: gw-prioqueue.c:174
static int add_msg_cb(SMSCConn *conn, Msg *sms)
Definition: smsc_emi.c:1546
static Octstr * allow_ip
Definition: bb_udp.c:111
int alt_port
Definition: smsc_emi.c:103
int shutdown
Definition: smsc_cgw.c:156
long sender_thread
Definition: smsc_cgw.c:155
long octstr_len(const Octstr *ostr)
Definition: octstr.c:340
void octstr_append_decimal(Octstr *ostr, long value)
Definition: octstr.c:1974
void gw_prioqueue_destroy(gw_prioqueue_t *queue, void(*item_destroy)(void *))
Definition: gw-prioqueue.c:201
int alt_charset
Definition: smsc_emi.c:134
int waitack_expire
Definition: smsc_emi.c:120
Definition: octstr.c:118
int(* shutdown)(SMSCConn *conn, int finish_sending)
Definition: smscconn_p.h:229
struct privdata::@22 slots[EMI2_MAX_TRN]
int cfg_get_integer(long *n, CfgGroup *grp, Octstr *varname)
Definition: cfg.c:739
static void emi2_listener(void *arg)
Definition: smsc_emi.c:1479
static void start_cb(SMSCConn *conn)
Definition: smsc_emi.c:1586
Octstr * nadc
Definition: smsc_emi.c:133
void gwthread_wakeup(long thread)
smscconn_status_t status
Definition: smscconn_p.h:151
Octstr * alt_host
Definition: smsc_emi.c:108
long(* queued)(SMSCConn *conn)
Definition: smscconn_p.h:240
int(* send_msg)(SMSCConn *conn, Msg *msg)
Definition: smscconn_p.h:235
long receiver_thread
Definition: smsc_cgw.c:154
int listening_socket
Definition: smsc_cgw.c:157
int unacked
Definition: smsc_cgw.c:170
int idle_timeout
Definition: smsc_emi.c:130
time_t sendtime[CGW_TRN_MAX]
Definition: smsc_cgw.c:168
int our_port
Definition: smsc_cgw.c:161
static long queued_cb(SMSCConn *conn)
Definition: smsc_emi.c:1598
Octstr * deny_ip
Definition: smsc_cgw.c:164
long keepalive
Definition: smsc_cimd2.c:104
int smsc_fake_create ( SMSCConn conn,
CfgGroup cfg 
)

Definition at line 534 of file smsc_fake.c.

References add_msg_cb(), allow_ip, privdata::allow_ip, cfg_get, cfg_get_integer(), smscconn::connect_time, privdata::connection_thread, smscconn::data, deny_ip, privdata::deny_ip, error(), fake_listener(), fake_open_connection(), gwlist_create, gwlist_destroy(), gwthread_create, privdata::listening_socket, smscconn::name, octstr_create, octstr_destroy(), octstr_format(), octstr_imm(), privdata::outgoing_queue, privdata::port, smscconn::queued, queued_cb(), smscconn::send_msg, privdata::shutdown, smscconn::shutdown, shutdown_cb(), SMSCCONN_CONNECTING, SMSCCONN_DEAD, SMSCCONN_KILLED_CANNOT_CONNECT, start_cb(), smscconn::start_conn, smscconn::status, and smscconn::why_killed.

Referenced by smscconn_create().

535 {
536  PrivData *privdata = NULL;
538  long portno; /* has to be long because of cfg_get_integer */
539 
540  if (cfg_get_integer(&portno, cfg, octstr_imm("port")) == -1)
541  portno = 0;
542  allow_ip = cfg_get(cfg, octstr_imm("connect-allow-ip"));
543  if (allow_ip)
544  deny_ip = octstr_create("*.*.*.*");
545  else
546  deny_ip = NULL;
547 
548  if (portno == 0) {
549  error(0, "'port' invalid in 'fake' record.");
550  goto error;
551  }
552  privdata = gw_malloc(sizeof(PrivData));
553  privdata->listening_socket = -1;
554 
555  privdata->port = portno;
556  privdata->allow_ip = allow_ip;
557  privdata->deny_ip = deny_ip;
558 
559  if (fake_open_connection(conn, privdata) < 0) {
560  gw_free(privdata);
561  privdata = NULL;
562  goto error;
563  }
564 
565  conn->data = privdata;
566 
567  conn->name = octstr_format("FAKE:%d", privdata->port);
568 
569  privdata->outgoing_queue = gwlist_create();
570  privdata->shutdown = 0;
571 
572  conn->status = SMSCCONN_CONNECTING;
573  conn->connect_time = time(NULL);
574 
575  if ((privdata->connection_thread = gwthread_create(fake_listener, conn)) == -1)
576  goto error;
577 
578  conn->shutdown = shutdown_cb;
579  conn->queued = queued_cb;
580  conn->start_conn = start_cb;
581  conn->send_msg = add_msg_cb;
582 
583  return 0;
584 
585 error:
586  error(0, "Failed to create fake smsc connection");
587  if (privdata != NULL) {
588  gwlist_destroy(privdata->outgoing_queue, NULL);
589  if (close(privdata->listening_socket == -1)) {
590  error(errno, "smsc_fake: closing listening socket port %d failed",
591  privdata->listening_socket);
592  }
593  }
594  gw_free(privdata);
595  octstr_destroy(allow_ip);
596  octstr_destroy(deny_ip);
598  conn->status = SMSCCONN_DEAD;
599  return -1;
600 }
int port
Definition: smsc_cgw.c:159
Octstr * name
Definition: smscconn_p.h:173
void error(int err, const char *fmt,...)
Definition: log.c:612
void * data
Definition: smscconn_p.h:249
List * outgoing_queue
Definition: smsc_cgw.c:153
static void start_cb(SMSCConn *conn)
Definition: smsc_fake.c:510
#define cfg_get(grp, varname)
Definition: cfg.h:86
void(* start_conn)(SMSCConn *conn)
Definition: smscconn_p.h:245
smscconn_killed_t why_killed
Definition: smscconn_p.h:153
static void fake_listener(void *arg)
Definition: smsc_fake.c:358
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:281
static int shutdown_cb(SMSCConn *conn, int finish_sending)
Definition: smsc_fake.c:480
time_t connect_time
Definition: smscconn_p.h:155
static Octstr * deny_ip
Definition: bb_udp.c:112
Octstr * allow_ip
Definition: smsc_cgw.c:164
Octstr * octstr_format(const char *fmt,...)
Definition: octstr.c:2462
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:322
#define gwthread_create(func, arg)
Definition: gwthread.h:90
#define octstr_create(cstr)
Definition: octstr.h:125
long connection_thread
Definition: smsc_fake.c:83
static Octstr * allow_ip
Definition: bb_udp.c:111
int shutdown
Definition: smsc_cgw.c:156
static int add_msg_cb(SMSCConn *conn, Msg *sms)
Definition: smsc_fake.c:451
Definition: octstr.c:118
int(* shutdown)(SMSCConn *conn, int finish_sending)
Definition: smscconn_p.h:229
int cfg_get_integer(long *n, CfgGroup *grp, Octstr *varname)
Definition: cfg.c:739
smscconn_status_t status
Definition: smscconn_p.h:151
#define gwlist_create()
Definition: list.h:136
long(* queued)(SMSCConn *conn)
Definition: smscconn_p.h:240
int(* send_msg)(SMSCConn *conn, Msg *msg)
Definition: smscconn_p.h:235
int listening_socket
Definition: smsc_cgw.c:157
static int fake_open_connection(SMSCConn *conn, PrivData *privdata)
Definition: smsc_fake.c:91
Octstr * deny_ip
Definition: smsc_cgw.c:164
static long queued_cb(SMSCConn *conn)
Definition: smsc_fake.c:520
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)
Definition: list.c:145
int smsc_http_create ( SMSCConn conn,
CfgGroup cfg 
)

Definition at line 881 of file smsc_http.c.

References conndata::allow_ip, conndata::alt_charset, conndata::callbacks, cfg_get, cfg_get_bool(), cfg_get_integer(), conndata_destroy(), smscconn::connect_time, counter_create(), conndata::data, smscconn::data, smsc_http_fn_callbacks::destroy, conndata::dlr_url, error(), gwlist_add_producer(), gwlist_create, gwthread_create, http_caller_create(), http_open_port(), conndata::http_ref, httpsmsc_queued(), httpsmsc_receiver(), httpsmsc_send(), httpsmsc_send_cb(), httpsmsc_sender(), httpsmsc_shutdown(), smscconn::id, info(), smsc_http_fn_callbacks::init, conndata::max_pending_sends, conndata::msg_to_send, smscconn::name, conndata::no_coding, conndata::no_sender, conndata::no_sep, octstr_case_compare(), octstr_destroy(), octstr_format(), octstr_get_cstr, octstr_imm(), conndata::open_sends, panic, conndata::password, conndata::port, conndata::proxy, smscconn::queued, conndata::receive_thread, semaphore_create(), conndata::send_cb_thread, smscconn::send_msg, conndata::send_url, conndata::sender_thread, conndata::shutdown, smscconn::shutdown, smsc_http_brunet_callback, smsc_http_clickatell_callback, smsc_http_generic_callback, smsc_http_kannel_callback, smsc_http_wapme_callback, smsc_http_xidris_callback, SMSCCONN_ACTIVE, SMSCCONN_ACTIVE_RECV, SMSCCONN_DEAD, SMSCCONN_KILLED_CANNOT_CONNECT, ssl, smscconn::status, conndata::system_id, type, conndata::username, warning(), and smscconn::why_killed.

Referenced by smscconn_create().

882 {
883  ConnData *conndata = NULL;
884  Octstr *type;
885  int ssl = 0; /* indicate if SSL-enabled server should be used */
886  long max_ps;
887 
888  if ((type = cfg_get(cfg, octstr_imm("system-type"))) == NULL) {
889  error(0, "HTTP[%s]: 'system-type' missing in smsc 'http' record.",
890  octstr_get_cstr(conn->id));
891  octstr_destroy(type);
892  return -1;
893  }
894 
895  conndata = gw_malloc(sizeof(ConnData));
896  /* reset conndata */
897  memset(conndata, 0, sizeof(ConnData));
898 
899  conn->data = conndata;
900  conndata->http_ref = NULL;
901  conndata->data = NULL;
902 
903  if (cfg_get_integer(&conndata->port, cfg, octstr_imm("port")) == -1) {
904  warning(0, "HTTP[%s]: 'port' not set in smsc 'http' group.",
905  octstr_get_cstr(conn->id));
906  conndata->port = -1;
907  }
908 
909  conndata->allow_ip = cfg_get(cfg, octstr_imm("connect-allow-ip"));
910  conndata->send_url = cfg_get(cfg, octstr_imm("send-url"));
911  conndata->username = cfg_get(cfg, octstr_imm("smsc-username"));
912  conndata->password = cfg_get(cfg, octstr_imm("smsc-password"));
913  conndata->system_id = cfg_get(cfg, octstr_imm("system-id"));
914  cfg_get_bool(&conndata->no_sender, cfg, octstr_imm("no-sender"));
915  cfg_get_bool(&conndata->no_coding, cfg, octstr_imm("no-coding"));
916  cfg_get_bool(&conndata->no_sep, cfg, octstr_imm("no-sep"));
917  conndata->proxy = cfg_get(cfg, octstr_imm("system-id"));
918  cfg_get_bool(&ssl, cfg, octstr_imm("use-ssl"));
919  conndata->dlr_url = cfg_get(cfg, octstr_imm("dlr-url"));
920  conndata->alt_charset = cfg_get(cfg, octstr_imm("alt-charset"));
921 
922  if (cfg_get_integer(&max_ps, cfg, octstr_imm("max-pending-submits")) == -1 || max_ps < 1)
923  max_ps = 10;
924 
925  conndata->max_pending_sends = semaphore_create(max_ps);
926 
927  if (conndata->port <= 0 && conndata->send_url == NULL) {
928  error(0, "Sender and receiver disabled. Dummy SMSC not allowed.");
929  goto error;
930  }
931  if (conndata->send_url == NULL)
932  panic(0, "HTTP[%s]: Sending not allowed. No 'send-url' specified.",
933  octstr_get_cstr(conn->id));
934 
935  if (octstr_case_compare(type, octstr_imm("kannel")) == 0) {
936  if (conndata->username == NULL || conndata->password == NULL) {
937  error(0, "HTTP[%s]: 'username' and 'password' required for Kannel http smsc",
938  octstr_get_cstr(conn->id));
939  goto error;
940  }
942  } else if (octstr_case_compare(type, octstr_imm("brunet")) == 0) {
944  } else if (octstr_case_compare(type, octstr_imm("xidris")) == 0) {
946  } else if (octstr_case_compare(type, octstr_imm("generic")) == 0) {
948  } else if (octstr_case_compare(type, octstr_imm("clickatell")) == 0) {
950  } else if (octstr_case_compare(type, octstr_imm("wapme")) == 0) {
951  conndata->callbacks = &smsc_http_wapme_callback;
952  }
953  /*
954  * ADD NEW HTTP SMSC TYPES HERE
955  */
956  else {
957  error(0, "HTTP[%s]: system-type '%s' unknown smsc 'http' record.",
958  octstr_get_cstr(conn->id), octstr_get_cstr(type));
959  goto error;
960  }
961 
962  if (conndata->callbacks != NULL && conndata->callbacks->init != NULL && conndata->callbacks->init(conn, cfg)) {
963  error(0, "HTTP[%s]: submodule '%s' init failed.", octstr_get_cstr(conn->id), octstr_get_cstr(type));
964  goto error;
965  }
966 
967  conndata->open_sends = counter_create();
968  conndata->msg_to_send = gwlist_create();
969  gwlist_add_producer(conndata->msg_to_send);
970  conndata->http_ref = http_caller_create();
971 
972  conn->name = octstr_format("HTTP%s:%S:%d", (ssl?"S":""), type, conndata->port);
973 
974  if (conndata->send_url != NULL) {
975  conn->status = SMSCCONN_ACTIVE;
976  } else {
978  }
979 
980 
981  conn->connect_time = time(NULL);
982 
983  conn->shutdown = httpsmsc_shutdown;
984  conn->queued = httpsmsc_queued;
985  conn->send_msg = httpsmsc_send;
986 
987  conndata->shutdown = 0;
988 
989  /* start receiver thread */
990  if (conndata->port > 0) {
991  if (http_open_port(conndata->port, ssl) == -1)
992  goto error;
993  if ((conndata->receive_thread = gwthread_create(httpsmsc_receiver, conn)) == -1)
994  goto error;
995  } else
996  conndata->receive_thread = -1;
997 
998  /* start sender threads */
999  if (conndata->send_url) {
1000  if ((conndata->send_cb_thread =
1001  gwthread_create(httpsmsc_send_cb, conn)) == -1)
1002  goto error;
1003  if ((conndata->sender_thread =
1004  gwthread_create(httpsmsc_sender, conn)) == -1)
1005  goto error;
1006  }
1007  else {
1008  conndata->send_cb_thread = conndata->sender_thread = -1;
1009  }
1010 
1011  info(0, "HTTP[%s]: Initiated and ready", octstr_get_cstr(conn->id));
1012 
1013  octstr_destroy(type);
1014  return 0;
1015 
1016 error:
1017  error(0, "HTTP[%s]: Failed to create HTTP SMSC connection",
1018  octstr_get_cstr(conn->id));
1019 
1020  if (conndata->callbacks != NULL && conndata->callbacks->destroy != NULL)
1021  conndata->callbacks->destroy(conn);
1022  conn->data = NULL;
1023  conndata_destroy(conndata);
1025  conn->status = SMSCCONN_DEAD;
1026  octstr_destroy(type);
1027  return -1;
1028 }
Octstr * name
Definition: smscconn_p.h:173
void error(int err, const char *fmt,...)
Definition: log.c:612
struct smsc_http_fn_callbacks smsc_http_wapme_callback
Definition: wapme.c:123
void info(int err, const char *fmt,...)
Definition: log.c:636
Octstr * dlr_url
Definition: smsc_http.c:151
void * data
Definition: smsc_http.c:170
static void httpsmsc_receiver(void *arg)
Definition: smsc_http.c:200
static void conndata_destroy(ConnData *conndata)
Definition: smsc_http.c:174
struct smsc_http_fn_callbacks smsc_http_xidris_callback
Definition: xidris.c:330
Octstr * alt_charset
Definition: smsc_http.c:161
long receive_thread
Definition: smsc_http.c:144
int ssl
int no_sep
Definition: smsc_http.c:159
Semaphore * semaphore_create(long n)
Definition: semaphore.c:81
Octstr * id
Definition: smscconn_p.h:174
void * data
Definition: smscconn_p.h:249
HTTPCaller * http_ref
Definition: smsc_http.c:143
struct smsc_http_fn_callbacks smsc_http_kannel_callback
Definition: smsc_http.c:800
int type
Definition: smsc_cimd2.c:215
Octstr * allow_ip
Definition: smsc_http.c:149
#define cfg_get(grp, varname)
Definition: cfg.h:86
struct smsc_http_fn_callbacks smsc_http_clickatell_callback
Definition: clickatell.c:308
Octstr * proxy
Definition: smsc_http.c:160
Octstr * system_id
Definition: smsc_http.c:156
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
void(* destroy)(SMSCConn *conn)
Definition: smsc_http.c:136
smscconn_killed_t why_killed
Definition: smscconn_p.h:153
struct smsc_http_fn_callbacks smsc_http_brunet_callback
Definition: brunet.c:317
volatile int shutdown
Definition: smsc_http.c:147
long port
Definition: smsc_http.c:148
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:281
Counter * open_sends
Definition: smsc_http.c:152
int no_coding
Definition: smsc_http.c:158
List * msg_to_send
Definition: smsc_http.c:162
Counter * counter_create(void)
Definition: counter.c:94
static void httpsmsc_send_cb(void *arg)
Definition: smsc_http.c:351
time_t connect_time
Definition: smscconn_p.h:155
struct smsc_http_fn_callbacks smsc_http_generic_callback
Definition: generic.c:608
int octstr_case_compare(const Octstr *os1, const Octstr *os2)
Definition: octstr.c:901
long sender_thread
Definition: smsc_http.c:146
void warning(int err, const char *fmt,...)
Definition: log.c:624
Octstr * octstr_format(const char *fmt,...)
Definition: octstr.c:2462
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:322
#define gwthread_create(func, arg)
Definition: gwthread.h:90
int no_sender
Definition: smsc_http.c:157
static int httpsmsc_shutdown(SMSCConn *conn, int finish_sending)
Definition: smsc_http.c:846
int http_open_port(int port, int ssl)
Definition: http.c:2498
Semaphore * max_pending_sends
Definition: smsc_http.c:153
int cfg_get_bool(int *n, CfgGroup *grp, Octstr *varname)
Definition: cfg.c:756
int(* init)(SMSCConn *conn, CfgGroup *cfg)
Definition: smsc_http.c:135
Definition: octstr.c:118
static long httpsmsc_queued(SMSCConn *conn)
Definition: smsc_http.c:835
int(* shutdown)(SMSCConn *conn, int finish_sending)
Definition: smscconn_p.h:229
Octstr * password
Definition: smsc_http.c:155
int cfg_get_integer(long *n, CfgGroup *grp, Octstr *varname)
Definition: cfg.c:739
#define panic
Definition: log.h:87
smscconn_status_t status
Definition: smscconn_p.h:151
HTTPCaller * http_caller_create(void)
Definition: http.c:897
#define gwlist_create()
Definition: list.h:136
long(* queued)(SMSCConn *conn)
Definition: smscconn_p.h:240
int(* send_msg)(SMSCConn *conn, Msg *msg)
Definition: smscconn_p.h:235
Octstr * username
Definition: smsc_http.c:154
static int httpsmsc_send(SMSCConn *conn, Msg *msg)
Definition: smsc_http.c:810
Octstr * send_url
Definition: smsc_http.c:150
void gwlist_add_producer(List *list)
Definition: list.c:383
static void httpsmsc_sender(void *arg)
Definition: smsc_http.c:281
struct smsc_http_fn_callbacks * callbacks
Definition: smsc_http.c:167
long send_cb_thread
Definition: smsc_http.c:145
int smsc_loopback_create ( SMSCConn conn,
CfgGroup cfg 
)

Definition at line 165 of file smsc_loopback.c.

References smscconn::connect_time, smscconn::data, smscconn::id, msg_cb(), smscconn::name, octstr_format(), smscconn::queued, queued_cb(), smscconn::send_msg, smscconn::shutdown, shutdown_cb(), SMSCCONN_CONNECTING, start_cb(), smscconn::start_conn, and smscconn::status.

Referenced by smscconn_create().

166 {
167  conn->data = NULL;
168  conn->name = octstr_format("LOOPBACK:%S", conn->id);
169 
170  conn->status = SMSCCONN_CONNECTING;
171  conn->connect_time = time(NULL);
172 
173  conn->shutdown = shutdown_cb;
174  conn->queued = queued_cb;
175  conn->start_conn = start_cb;
176  conn->send_msg = msg_cb;
177 
178  return 0;
179 }
Octstr * name
Definition: smscconn_p.h:173
static int msg_cb(SMSCConn *conn, Msg *msg)
Definition: smsc_loopback.c:76
static int shutdown_cb(SMSCConn *conn, int finish_sending)
Octstr * id
Definition: smscconn_p.h:174
void * data
Definition: smscconn_p.h:249
static void start_cb(SMSCConn *conn)
void(* start_conn)(SMSCConn *conn)
Definition: smscconn_p.h:245
time_t connect_time
Definition: smscconn_p.h:155
Octstr * octstr_format(const char *fmt,...)
Definition: octstr.c:2462
int(* shutdown)(SMSCConn *conn, int finish_sending)
Definition: smscconn_p.h:229
smscconn_status_t status
Definition: smscconn_p.h:151
long(* queued)(SMSCConn *conn)
Definition: smscconn_p.h:240
int(* send_msg)(SMSCConn *conn, Msg *msg)
Definition: smscconn_p.h:235
static long queued_cb(SMSCConn *conn)
int smsc_oisd_create ( SMSCConn conn,
CfgGroup cfg 
)

Definition at line 1498 of file smsc_oisd.c.

References cfg_get, cfg_get_bool(), cfg_get_integer(), privdata::conn, smscconn::data, debug(), error(), gwlist_add_producer(), gwlist_create, gwthread_create, gwthread_join(), gwthread_wakeup(), privdata::host, smscconn::id, privdata::inbuffer, privdata::io_thread, io_thread(), smscconn::is_stopped, privdata::keepalive, privdata::my_number, smscconn::name, privdata::next_ping, privdata::no_dlr, octstr_create, octstr_format(), octstr_get_cstr, octstr_imm(), oisd_add_msg_cb(), oisd_destroy(), oisd_queued_cb(), oisd_shutdown_cb(), oisd_start_cb(), oisd_stop_cb(), ok, privdata::outgoing_queue, privdata::port, smscconn::queued, privdata::quitting, privdata::received, smscconn::send_msg, privdata::send_seq, smscconn::shutdown, SMS_PARAM_UNDEFINED, privdata::socket, smscconn::start_conn, smscconn::stop_conn, privdata::stopped, and privdata::validityperiod.

Referenced by smscconn_create().

1499 {
1500  PrivData *pdata;
1501  int ok;
1502 
1503  pdata = gw_malloc(sizeof(PrivData));
1504  conn->data = pdata;
1505  pdata->conn = conn;
1506 
1507  pdata->no_dlr = 0;
1508  pdata->quitting = 0;
1509  pdata->socket = -1;
1510  pdata->received = gwlist_create();
1511  pdata->inbuffer = octstr_create("");
1512  pdata->send_seq = 1;
1513  pdata->outgoing_queue = gwlist_create();
1514  pdata->stopped = gwlist_create();
1516 
1517  if (conn->is_stopped)
1518  gwlist_add_producer(pdata->stopped);
1519 
1520  pdata->host = cfg_get(grp, octstr_imm("host"));
1521  if (cfg_get_integer(&(pdata->port), grp, octstr_imm("port")) == -1)
1522  pdata->port = 0;
1523  pdata->my_number = cfg_get(grp, octstr_imm("my-number"));
1524  if (cfg_get_integer(&(pdata->keepalive), grp, octstr_imm("keepalive")) == -1)
1525  pdata->keepalive = 0;
1526  if (cfg_get_integer(&(pdata->validityperiod), grp, octstr_imm("validityperiod")) == -1)
1528 
1529  cfg_get_bool(&pdata->no_dlr, grp, octstr_imm("no-dlr"));
1530 
1531  /* Check that config is OK */
1532  ok = 1;
1533  if (pdata->host == NULL) {
1534  error(0, "OISD[%s]: Configuration file doesn't specify host",
1535  octstr_get_cstr(conn->id));
1536  ok = 0;
1537  }
1538  if (pdata->port == 0) {
1539  error(0, "OISD[%s]: Configuration file doesn't specify port",
1540  octstr_get_cstr(conn->id));
1541  ok = 0;
1542  }
1543  if (pdata->my_number == NULL && pdata->keepalive > 0) {
1544  error(0, "OISD[%s]: Configuration file doesn't specify my-number.",
1545  octstr_get_cstr(conn->id));
1546  ok = 0;
1547  }
1548 
1549  if (!ok) {
1550  oisd_destroy(pdata);
1551  return -1;
1552  }
1553 
1554  conn->name = octstr_format("OISD:%s:%d",
1555  octstr_get_cstr(pdata->host),
1556  pdata->port);
1557 
1558 
1559  if (pdata->keepalive > 0) {
1560  debug("bb.sms.oisd", 0, "OISD[%s]: Keepalive set to %ld seconds",
1561  octstr_get_cstr(conn->id),
1562  pdata->keepalive);
1563  pdata->next_ping = time(NULL) + pdata->keepalive;
1564  }
1565 
1566  if (pdata->validityperiod > 0) {
1567  debug("bb.sms.oisd", 0, "OISD[%s]: Validity-Period set to %ld",
1568  octstr_get_cstr(conn->id),
1569  pdata->validityperiod);
1570  }
1571 
1572  pdata->io_thread = gwthread_create(io_thread, conn);
1573 
1574  if (pdata->io_thread == -1) {
1575 
1576  error(0, "OISD[%s]: Couldn't start I/O thread.",
1577  octstr_get_cstr(conn->id));
1578  pdata->quitting = 1;
1579  gwthread_wakeup(pdata->io_thread);
1580  gwthread_join(pdata->io_thread);
1581  oisd_destroy(pdata);
1582  return -1;
1583  }
1584 
1585  conn->send_msg = oisd_add_msg_cb;
1586  conn->shutdown = oisd_shutdown_cb;
1587  conn->queued = oisd_queued_cb;
1588  conn->start_conn = oisd_start_cb;
1589  conn->stop_conn = oisd_stop_cb;
1590 
1591  return 0;
1592 }
int port
Definition: smsc_cgw.c:159
Octstr * name
Definition: smscconn_p.h:173
void error(int err, const char *fmt,...)
Definition: log.c:612
Octstr * inbuffer
Definition: smsc_cimd2.c:112
static void io_thread(void *arg)
Definition: smsc_oisd.c:1344
static void oisd_stop_cb(SMSCConn *conn)
Definition: smsc_oisd.c:1482
Octstr * id
Definition: smscconn_p.h:174
void gwthread_join(long thread)
long validityperiod
Definition: smsc_oisd.c:94
void * data
Definition: smscconn_p.h:249
List * outgoing_queue
Definition: smsc_cgw.c:153
void(* stop_conn)(SMSCConn *conn)
Definition: smscconn_p.h:246
int socket
Definition: smsc_cimd2.c:108
#define cfg_get(grp, varname)
Definition: cfg.h:86
int io_thread
Definition: smsc_cimd2.c:119
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
void(* start_conn)(SMSCConn *conn)
Definition: smscconn_p.h:245
List * stopped
Definition: smsc_cimd2.c:121
time_t next_ping
Definition: smsc_cimd2.c:115
static int oisd_add_msg_cb(SMSCConn *conn, Msg *sms)
Definition: smsc_oisd.c:1418
static void oisd_start_cb(SMSCConn *conn)
Definition: smsc_oisd.c:1471
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:281
Octstr * my_number
Definition: smsc_cimd2.c:105
static void oisd_destroy(PrivData *pdata)
Definition: smsc_oisd.c:1128
Octstr * host
Definition: smsc_cgw.c:163
int quitting
Definition: smsc_cimd2.c:120
Octstr * octstr_format(const char *fmt,...)
Definition: octstr.c:2462
#define gwthread_create(func, arg)
Definition: gwthread.h:90
#define octstr_create(cstr)
Definition: octstr.h:125
#define SMS_PARAM_UNDEFINED
Definition: sms.h:91
volatile sig_atomic_t is_stopped
Definition: smscconn_p.h:169
static long oisd_queued_cb(SMSCConn *conn)
Definition: smsc_oisd.c:1490
int send_seq
Definition: smsc_cimd2.c:109
int no_dlr
Definition: smsc_cimd2.c:106
int cfg_get_bool(int *n, CfgGroup *grp, Octstr *varname)
Definition: cfg.c:756
int(* shutdown)(SMSCConn *conn, int finish_sending)
Definition: smscconn_p.h:229
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:690
int cfg_get_integer(long *n, CfgGroup *grp, Octstr *varname)
Definition: cfg.c:739
Definition: wtp_tid.h:82
void gwthread_wakeup(long thread)
List * received
Definition: smsc_cimd2.c:113
#define gwlist_create()
Definition: list.h:136
long(* queued)(SMSCConn *conn)
Definition: smscconn_p.h:240
int(* send_msg)(SMSCConn *conn, Msg *msg)
Definition: smscconn_p.h:235
void gwlist_add_producer(List *list)
Definition: list.c:383
long keepalive
Definition: smsc_cimd2.c:104
static int oisd_shutdown_cb(SMSCConn *conn, int finish_sending)
Definition: smsc_oisd.c:1430
SMSCConn * conn
Definition: smsc_cimd2.c:118
int smsc_smasi_create ( SMSCConn conn,
CfgGroup cfg 
)

Definition at line 1129 of file smsc_smasi.c.

References SMASI::conn, smscconn::data, error(), gwthread_create, smscconn::id, init_configuration(), octstr_create, octstr_get_cstr, panic, smscconn::queued, queued_cb(), smscconn::send_msg, send_msg_cb(), smscconn::shutdown, shutdown_cb(), smasi_create(), smasi_destroy(), smasi_thread(), SMSCCONN_CONNECTING, smscconn::status, and SMASI::thread_handle.

Referenced by smscconn_create().

1130 {
1131  SMASI *smasi = NULL;
1132 
1133  /* Initialize data encoding subsystem. */
1134  colon = octstr_create(":3a");
1135  assign = octstr_create(":3d");
1136  comma = octstr_create(":2c");
1137  cr = octstr_create(":0a");
1138  lf = octstr_create(":0d");
1139 
1140  /* Create main SMASI structure and initialize it with configuration
1141  * settings.
1142  */
1143  smasi = smasi_create(conn);
1144 
1145  if (init_configuration(smasi, config) != 0)
1146  panic(0, "SMASI SMSC module configuration invalid.");
1147 
1148  conn->status = SMSCCONN_CONNECTING;
1149 
1150  /* Port is always set to a configured value or defaults to 21500.
1151  * Therefore, threads are always started.
1152  */
1153  smasi->thread_handle = gwthread_create(smasi_thread, smasi);
1154 
1155  if (smasi->thread_handle == -1) {
1156  error(0, "SMASI[%s]: Couldn't start SMASI thread.",
1157  octstr_get_cstr(smasi->conn->id));
1158  smasi_destroy(conn->data);
1159  return -1;
1160  }
1161 
1162  /* Setup control function pointers. */
1163  conn->shutdown = shutdown_cb;
1164  conn->queued = queued_cb;
1165  conn->send_msg = send_msg_cb;
1166 
1167  return 0;
1168 }
void error(int err, const char *fmt,...)
Definition: log.c:612
static Octstr * cr
Definition: smsc_smasi.c:221
SMSCConn * conn
Definition: smsc_smasi.c:136
Octstr * id
Definition: smscconn_p.h:174
void * data
Definition: smscconn_p.h:249
static int shutdown_cb(SMSCConn *conn, int finish_sending)
Definition: smsc_smasi.c:1034
static Octstr * comma
Definition: smsc_smasi.c:220
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
static SMASI * smasi_create(SMSCConn *conn)
Definition: smsc_smasi.c:159
static void smasi_destroy(SMASI *smasi)
Definition: smsc_smasi.c:192
#define gwthread_create(func, arg)
Definition: gwthread.h:90
#define octstr_create(cstr)
Definition: octstr.h:125
static Octstr * colon
Definition: smsc_smasi.c:218
static int init_configuration(SMASI *smasi, CfgGroup *config)
Definition: smsc_smasi.c:1071
int(* shutdown)(SMSCConn *conn, int finish_sending)
Definition: smscconn_p.h:229
static int send_msg_cb(SMSCConn *conn, Msg *msg)
Definition: smsc_smasi.c:1023
#define panic
Definition: log.h:87
smscconn_status_t status
Definition: smscconn_p.h:151
int thread_handle
Definition: smsc_smasi.c:137
long(* queued)(SMSCConn *conn)
Definition: smscconn_p.h:240
int(* send_msg)(SMSCConn *conn, Msg *msg)
Definition: smscconn_p.h:235
static void smasi_thread(void *arg)
Definition: smsc_smasi.c:911
static Octstr * lf
Definition: smsc_smasi.c:222
static long queued_cb(SMSCConn *conn)
Definition: smsc_smasi.c:1012
static Octstr * assign
Definition: smsc_smasi.c:219
int smsc_smpp_create ( SMSCConn conn,
CfgGroup cfg 
)

Definition at line 2561 of file smsc_smpp.c.

References SMPP::bind_addr_npi, SMPP::bind_addr_ton, cfg_get, cfg_get_bool(), cfg_get_integer(), SMPP::conn, smscconn::data, error(), ESM_CLASS_SUBMIT_DEFAULT_SMSC_MODE, ESM_CLASS_SUBMIT_STORE_AND_FORWARD_MODE, gwthread_create, gwthread_join(), gwthread_wakeup(), host, smscconn::id, io_arg_create(), io_thread(), SMPP::log_format, smscconn::name, octstr_destroy(), octstr_duplicate, octstr_format(), octstr_get_cstr, octstr_imm(), octstr_len(), ok, our_port, panic, password, port, smscconn::queued, queued_cb(), SMPP::quitting, SMPP::receiver, smscconn::send_msg, send_msg_cb(), smscconn::shutdown, shutdown_cb(), smpp_create(), SMPP_DEFAULT_CONNECTION_TIMEOUT, SMPP_DEFAULT_PORT, SMPP_DEFAULT_PRIORITY, SMPP_DEFAULT_VERSION, SMPP_DEFAULT_WAITACK, smpp_destroy(), SMPP_ENQUIRE_LINK_INTERVAL, SMPP_MAX_PENDING_SUBMITS, SMPP_PDU_DUMP_MULTILINE, SMPP_WAITACK_REQUEUE, SMS_PARAM_UNDEFINED, smsc_id, SMSCCONN_CONNECTING, SMPP::ssl_client_certkey_file, smscconn::status, SMPP::transmitter, SMPP::use_ssl, username, and warning().

Referenced by smscconn_create().

2562 {
2563  Octstr *host;
2564  long port;
2565  long receive_port;
2566  Octstr *username;
2567  Octstr *password;
2568  Octstr *system_id;
2569  Octstr *system_type;
2570  Octstr *address_range;
2571  long source_addr_ton;
2572  long source_addr_npi;
2573  long dest_addr_ton;
2574  long dest_addr_npi;
2575  long our_port;
2576  long our_receiver_port;
2577  Octstr *my_number;
2578  Octstr *service_type;
2579  SMPP *smpp;
2580  int ok;
2581  int transceiver_mode;
2582  Octstr *smsc_id;
2583  long enquire_link_interval;
2584  long max_pending_submits;
2585  long version;
2586  long priority;
2587  long validity;
2588  long smpp_msg_id_type;
2589  int autodetect_addr;
2590  Octstr *alt_charset;
2591  Octstr *alt_addr_charset;
2592  long connection_timeout, wait_ack, wait_ack_action;
2593  long esm_class;
2594 
2595  my_number = alt_addr_charset = alt_charset = NULL;
2596  transceiver_mode = 0;
2597  autodetect_addr = 1;
2598 
2599  host = cfg_get(grp, octstr_imm("host"));
2600  if (cfg_get_integer(&port, grp, octstr_imm("port")) == -1)
2601  port = 0;
2602  if (cfg_get_integer(&receive_port, grp, octstr_imm("receive-port")) == -1)
2603  receive_port = 0;
2604 
2605  if (cfg_get_integer(&our_port, grp, octstr_imm("our-port")) == -1)
2606  our_port = 0;
2607  if (cfg_get_integer(&our_receiver_port, grp, octstr_imm("our-receiver-port")) == -1)
2608  our_receiver_port = 0;
2609 
2610  cfg_get_bool(&transceiver_mode, grp, octstr_imm("transceiver-mode"));
2611  username = cfg_get(grp, octstr_imm("smsc-username"));
2612  password = cfg_get(grp, octstr_imm("smsc-password"));
2613  system_type = cfg_get(grp, octstr_imm("system-type"));
2614  address_range = cfg_get(grp, octstr_imm("address-range"));
2615  my_number = cfg_get(grp, octstr_imm("my-number"));
2616  service_type = cfg_get(grp, octstr_imm("service-type"));
2617 
2618  system_id = cfg_get(grp, octstr_imm("system-id"));
2619  if (system_id != NULL) {
2620  warning(0, "SMPP: obsolete system-id variable is set, "
2621  "use smsc-username instead.");
2622  if (username == NULL) {
2623  warning(0, "SMPP: smsc-username not set, using system-id instead");
2624  username = system_id;
2625  } else
2626  octstr_destroy(system_id);
2627  }
2628 
2629  /*
2630  * check if timing values have been configured, otherwise
2631  * use the predefined default values.
2632  */
2633  if (cfg_get_integer(&enquire_link_interval, grp,
2634  octstr_imm("enquire-link-interval")) == -1)
2635  enquire_link_interval = SMPP_ENQUIRE_LINK_INTERVAL;
2636  if (cfg_get_integer(&max_pending_submits, grp,
2637  octstr_imm("max-pending-submits")) == -1)
2638  max_pending_submits = SMPP_MAX_PENDING_SUBMITS;
2639 
2640  /* Check that config is OK */
2641  ok = 1;
2642  if (host == NULL) {
2643  error(0, "SMPP: Configuration file doesn't specify host");
2644  ok = 0;
2645  }
2646  if (port == 0 && receive_port == 0) {
2647  port = SMPP_DEFAULT_PORT;
2648  warning(0, "SMPP: Configuration file doesn't specify port or receive-port. "
2649  "Using 'port = %ld' as default.", port);
2650  }
2651  if (port != 0 && receive_port != 0) {
2652  error(0, "SMPP: Configuration file can only have port or receive-port. "
2653  "Usage of both in one group is deprecated!");
2654  ok = 0;
2655  }
2656  if (username == NULL) {
2657  error(0, "SMPP: Configuration file doesn't specify username.");
2658  ok = 0;
2659  }
2660  if (password == NULL) {
2661  error(0, "SMPP: Configuration file doesn't specify password.");
2662  ok = 0;
2663  }
2664  if (system_type == NULL) {
2665  error(0, "SMPP: Configuration file doesn't specify system-type.");
2666  ok = 0;
2667  }
2668  if (octstr_len(service_type) > 6) {
2669  error(0, "SMPP: Service type must be 6 characters or less.");
2670  ok = 0;
2671  }
2672  if (transceiver_mode && receive_port != 0) {
2673  warning(0, "SMPP: receive-port for transceiver mode defined, ignoring.");
2674  receive_port = 0;
2675  }
2676 
2677  if (!ok)
2678  return -1;
2679 
2680  /* if the ton and npi values are forced, set them, else set them to -1 */
2681  if (cfg_get_integer(&source_addr_ton, grp,
2682  octstr_imm("source-addr-ton")) == -1)
2683  source_addr_ton = -1;
2684  if (cfg_get_integer(&source_addr_npi, grp,
2685  octstr_imm("source-addr-npi")) == -1)
2686  source_addr_npi = -1;
2687  if (cfg_get_integer(&dest_addr_ton, grp,
2688  octstr_imm("dest-addr-ton")) == -1)
2689  dest_addr_ton = -1;
2690  if (cfg_get_integer(&dest_addr_npi, grp,
2691  octstr_imm("dest-addr-npi")) == -1)
2692  dest_addr_npi = -1;
2693 
2694  /* if source addr autodetection should be used set this to 1 */
2695  if (cfg_get_bool(&autodetect_addr, grp, octstr_imm("source-addr-autodetect")) == -1)
2696  autodetect_addr = 1; /* default is autodetect if no option defined */
2697 
2698  /* check for any specified interface version */
2699  if (cfg_get_integer(&version, grp, octstr_imm("interface-version")) == -1)
2700  version = SMPP_DEFAULT_VERSION;
2701  else
2702  /* convert decimal to BCD */
2703  version = ((version / 10) << 4) + (version % 10);
2704 
2705  /* check for any specified priority value in range [0-5] */
2706  if (cfg_get_integer(&priority, grp, octstr_imm("priority")) == -1)
2707  priority = SMPP_DEFAULT_PRIORITY;
2708  else if (priority < 0 || priority > 3)
2709  panic(0, "SMPP: Invalid value for priority directive in configuraton (allowed range 0-3).");
2710 
2711  /* check for message validity period */
2712  if (cfg_get_integer(&validity, grp, octstr_imm("validityperiod")) == -1)
2713  validity = SMS_PARAM_UNDEFINED;
2714  else if (validity < 0)
2715  panic(0, "SMPP: Invalid value for validity period (allowed value >= 0).");
2716 
2717  /* set the msg_id type variable for this SMSC */
2718  if (cfg_get_integer(&smpp_msg_id_type, grp, octstr_imm("msg-id-type")) == -1) {
2719  /*
2720  * defaults to C string "as-is" style
2721  */
2722  smpp_msg_id_type = -1;
2723  } else {
2724  if (smpp_msg_id_type < 0 || smpp_msg_id_type > 3)
2725  panic(0,"SMPP: Invalid value for msg-id-type directive in configuraton");
2726  }
2727 
2728  /* check for an alternative charset */
2729  alt_charset = cfg_get(grp, octstr_imm("alt-charset"));
2730  alt_addr_charset = cfg_get(grp, octstr_imm("alt-addr-charset"));
2731 
2732  /* check for connection timeout */
2733  if (cfg_get_integer(&connection_timeout, grp, octstr_imm("connection-timeout")) == -1)
2734  connection_timeout = SMPP_DEFAULT_CONNECTION_TIMEOUT;
2735 
2736  /* check if wait-ack timeout set */
2737  if (cfg_get_integer(&wait_ack, grp, octstr_imm("wait-ack")) == -1)
2738  wait_ack = SMPP_DEFAULT_WAITACK;
2739 
2740  if (cfg_get_integer(&wait_ack_action, grp, octstr_imm("wait-ack-expire")) == -1)
2741  wait_ack_action = SMPP_WAITACK_REQUEUE;
2742  else if (wait_ack_action > 0x03 || wait_ack_action < 0)
2743  panic(0, "SMPP: Invalid wait-ack-expire directive in configuration.");
2744 
2745  if (cfg_get_integer(&esm_class, grp, octstr_imm("esm-class")) == -1) {
2747  } else if ( esm_class != ESM_CLASS_SUBMIT_DEFAULT_SMSC_MODE &&
2749  error(0, "SMPP: Invalid esm_class mode '%ld' in configuration. Switching to \"Store and Forward\".",
2750  esm_class);
2752  }
2753 
2754  smpp = smpp_create(conn, host, port, receive_port, our_port, our_receiver_port, system_type,
2755  username, password, address_range,
2756  source_addr_ton, source_addr_npi, dest_addr_ton,
2757  dest_addr_npi, enquire_link_interval,
2758  max_pending_submits, version, priority, validity, my_number,
2759  smpp_msg_id_type, autodetect_addr, alt_charset, alt_addr_charset,
2760  service_type, connection_timeout, wait_ack, wait_ack_action, esm_class);
2761 
2762  cfg_get_integer(&smpp->bind_addr_ton, grp, octstr_imm("bind-addr-ton"));
2763  cfg_get_integer(&smpp->bind_addr_npi, grp, octstr_imm("bind-addr-npi"));
2764 
2765  cfg_get_bool(&smpp->use_ssl, grp, octstr_imm("use-ssl"));
2766  if (smpp->use_ssl)
2767 #ifndef HAVE_LIBSSL
2768  panic(0, "SMPP: Can not use 'use-ssl' without SSL support compiled in.");
2769 #else
2770  smpp->ssl_client_certkey_file = cfg_get(grp, octstr_imm("ssl-client-certkey-file"));
2771 #endif
2772 
2773  conn->data = smpp;
2774  conn->name = octstr_format("%sSMPP:%S:%d/%d:%S:%S",
2775  (smpp->use_ssl ? "S" : ""), host, port,
2776  (!receive_port && transceiver_mode ? port : receive_port),
2777  username, system_type);
2778 
2779  smsc_id = cfg_get(grp, octstr_imm("smsc-id"));
2780  if (smsc_id == NULL) {
2781  conn->id = octstr_duplicate(conn->name);
2782  }
2783 
2784  if (cfg_get_integer(&smpp->log_format, grp, octstr_imm("log-format")) == -1)
2786 
2787  octstr_destroy(host);
2788  octstr_destroy(username);
2789  octstr_destroy(password);
2790  octstr_destroy(system_type);
2791  octstr_destroy(address_range);
2792  octstr_destroy(my_number);
2793  octstr_destroy(smsc_id);
2794  octstr_destroy(alt_charset);
2795  octstr_destroy(alt_addr_charset);
2796  octstr_destroy(service_type);
2797 
2798  conn->status = SMSCCONN_CONNECTING;
2799 
2800  /*
2801  * I/O threads are only started if the corresponding ports
2802  * have been configured with positive numbers. Use 0 to
2803  * disable the creation of the corresponding thread.
2804  */
2805  if (port != 0)
2807  (transceiver_mode ? 2 : 1)));
2808  if (receive_port != 0)
2809  smpp->receiver = gwthread_create(io_thread, io_arg_create(smpp, 0));
2810 
2811  if ((port != 0 && smpp->transmitter == -1) ||
2812  (receive_port != 0 && smpp->receiver == -1)) {
2813  error(0, "SMPP[%s]: Couldn't start I/O threads.",
2814  octstr_get_cstr(smpp->conn->id));
2815  smpp->quitting = 1;
2816  if (smpp->transmitter != -1) {
2818  gwthread_join(smpp->transmitter);
2819  }
2820  if (smpp->receiver != -1) {
2821  gwthread_wakeup(smpp->receiver);
2822  gwthread_join(smpp->receiver);
2823  }
2824  smpp_destroy(conn->data);
2825  conn->data = NULL;
2826  return -1;
2827  }
2828 
2829  conn->shutdown = shutdown_cb;
2830  conn->queued = queued_cb;
2831  conn->send_msg = send_msg_cb;
2832 
2833  return 0;
2834 }
Octstr * name
Definition: smscconn_p.h:173
void error(int err, const char *fmt,...)
Definition: log.c:612
static long our_port
Definition: radius_acct.c:87
static long queued_cb(SMSCConn *conn)
Definition: smsc_smpp.c:2499
long bind_addr_npi
Definition: smsc_smpp.c:164
Octstr * id
Definition: smscconn_p.h:174
void gwthread_join(long thread)
void * data
Definition: smscconn_p.h:249
static struct io_arg * io_arg_create(SMPP *smpp, int transmitter)
Definition: smsc_smpp.c:2193
#define SMPP_ENQUIRE_LINK_INTERVAL
Definition: smsc_smpp.c:119
SMSCConn * conn
Definition: smsc_smpp.c:186
#define SMPP_DEFAULT_CONNECTION_TIMEOUT
Definition: smsc_smpp.c:124
static Octstr * host
Definition: fakesmsc.c:121
#define cfg_get(grp, varname)
Definition: cfg.h:86
long bind_addr_ton
Definition: smsc_smpp.c:163
#define ESM_CLASS_SUBMIT_DEFAULT_SMSC_MODE
Definition: smpp_pdu.h:136
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
static void io_thread(void *arg)
Definition: smsc_smpp.c:2273
unsigned char * username
Definition: test_cimd2.c:99
int use_ssl
Definition: smsc_smpp.c:167
static int port
Definition: fakesmsc.c:120
static int shutdown_cb(SMSCConn *conn, int finish_sending)
Definition: smsc_smpp.c:2521
unsigned char * password
Definition: test_cimd2.c:100
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:281
long receiver
Definition: smsc_smpp.c:145
#define SMPP_DEFAULT_VERSION
Definition: smsc_smpp.c:121
static void smpp_destroy(SMPP *smpp)
Definition: smsc_smpp.c:293
static int send_msg_cb(SMSCConn *conn, Msg *msg)
Definition: smsc_smpp.c:2510
static SMPP * smpp_create(SMSCConn *conn, Octstr *host, int transmit_port, int receive_port, int our_port, int our_receiver_port, Octstr *system_type, Octstr *username, Octstr *password, Octstr *address_range, int source_addr_ton, int source_addr_npi, int dest_addr_ton, int dest_addr_npi, int enquire_link_interval, int max_pending_submits, int version, int priority, int validity, Octstr *my_number, int smpp_msg_id_type, int autodetect_addr, Octstr *alt_charset, Octstr *alt_addr_charset, Octstr *service_type, long connection_timeout, long wait_ack, int wait_ack_action, int esm_class)
Definition: smsc_smpp.c:227
#define ESM_CLASS_SUBMIT_STORE_AND_FORWARD_MODE
Definition: smpp_pdu.h:139
#define octstr_duplicate(ostr)
Definition: octstr.h:187
static Octstr * smsc_id
Definition: mtbatch.c:98
#define SMPP_DEFAULT_PORT
Definition: smsc_smpp.c:127
void warning(int err, const char *fmt,...)
Definition: log.c:624
#define SMPP_MAX_PENDING_SUBMITS
Definition: smsc_smpp.c:120
Octstr * octstr_format(const char *fmt,...)
Definition: octstr.c:2462
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:322
#define gwthread_create(func, arg)
Definition: gwthread.h:90
#define SMS_PARAM_UNDEFINED
Definition: sms.h:91
long log_format
Definition: smsc_smpp.c:184
long octstr_len(const Octstr *ostr)
Definition: octstr.c:340
int cfg_get_bool(int *n, CfgGroup *grp, Octstr *varname)
Definition: cfg.c:756
Definition: octstr.c:118
int(* shutdown)(SMSCConn *conn, int finish_sending)
Definition: smscconn_p.h:229
int cfg_get_integer(long *n, CfgGroup *grp, Octstr *varname)
Definition: cfg.c:739
Definition: wtp_tid.h:82
#define SMPP_DEFAULT_WAITACK
Definition: smsc_smpp.c:125
#define panic
Definition: log.h:87
void gwthread_wakeup(long thread)
smscconn_status_t status
Definition: smscconn_p.h:151
long(* queued)(SMSCConn *conn)
Definition: smscconn_p.h:240
int(* send_msg)(SMSCConn *conn, Msg *msg)
Definition: smscconn_p.h:235
#define SMPP_DEFAULT_PRIORITY
Definition: smsc_smpp.c:122
#define SMPP_WAITACK_REQUEUE
Definition: smsc_smpp.c:134
long transmitter
Definition: smsc_smpp.c:144
volatile int quitting
Definition: smsc_smpp.c:169
Octstr * ssl_client_certkey_file
Definition: smsc_smpp.c:168
int smsc_wrapper_create ( SMSCConn conn,
CfgGroup cfg 
)

Definition at line 397 of file smsc_wrapper.c.

References smscconn::connect_time, smscconn::data, error(), gwlist_add_producer(), gwlist_create, gwthread_create, smscconn::is_stopped, mutex_create, smscconn::name, octstr_create, smsc_wrapper::outgoing_queue, smscconn::queued, smsc_wrapper::receiver_thread, smsc_wrapper::reconnect_mutex, smscconn::send_msg, smsc_wrapper::sender_thread, smscconn::shutdown, smsc_wrapper::smsc, smsc_name(), smsc_open(), SMSCCONN_ACTIVE, SMSCCONN_DEAD, SMSCCONN_KILLED_CANNOT_CONNECT, smscwrapper_destroy(), smscconn::start_conn, smscconn::status, smscconn::stop_conn, smsc_wrapper::stopped, smscconn::why_killed, wrapper_add_msg(), wrapper_queued(), wrapper_receiver(), wrapper_sender(), wrapper_shutdown(), wrapper_start(), and wrapper_stop().

Referenced by smscconn_create().

398 {
399  /* 1. Call smsc_open()
400  * 2. create sender/receiver threads
401  * 3. fill up the conn
402  *
403  * XXX open() SHOULD be done in distinct thread, not here!
404  */
405 
406  SmscWrapper *wrap;
407 
408  wrap = gw_malloc(sizeof(SmscWrapper));
409  wrap->smsc = NULL;
410  conn->data = wrap;
411  conn->send_msg = wrapper_add_msg;
412 
413 
414  wrap->outgoing_queue = gwlist_create();
415  wrap->stopped = gwlist_create();
416  wrap->reconnect_mutex = mutex_create();
418 
419  if ((wrap->smsc = smsc_open(cfg)) == NULL)
420  goto error;
421 
422  conn->name = octstr_create(smsc_name(wrap->smsc));
423  conn->status = SMSCCONN_ACTIVE;
424  conn->connect_time = time(NULL);
425 
426  if (conn->is_stopped)
428 
429 
430  /* XXX here we could fail things... specially if the second one
431  * fails.. so fix this ASAP
432  *
433  * moreover, open should be in sender/receiver, so that we can continue
434  * while trying to open... maybe move this, or just wait for new
435  * implementations of various SMSC protocols
436  */
437 
438  if ((wrap->receiver_thread = gwthread_create(wrapper_receiver, conn))==-1)
439  goto error;
440 
441  if ((wrap->sender_thread = gwthread_create(wrapper_sender, conn))==-1)
442  goto error;
443 
444  conn->shutdown = wrapper_shutdown;
445  conn->queued = wrapper_queued;
446  conn->stop_conn = wrapper_stop;
447  conn->start_conn = wrapper_start;
448 
449  return 0;
450 
451 error:
452  error(0, "Failed to create Smsc wrapper");
453  conn->data = NULL;
454  smscwrapper_destroy(wrap);
456  conn->status = SMSCCONN_DEAD;
457  return -1;
458 }
Octstr * name
Definition: smscconn_p.h:173
void error(int err, const char *fmt,...)
Definition: log.c:612
List * outgoing_queue
Definition: smsc_wrapper.c:76
List * stopped
Definition: smsc_wrapper.c:77
void * data
Definition: smscconn_p.h:249
#define mutex_create()
Definition: thread.h:96
char * smsc_name(SMSCenter *smsc)
Definition: smsc.c:643
void(* stop_conn)(SMSCConn *conn)
Definition: smscconn_p.h:246
static void wrapper_sender(void *arg)
Definition: smsc_wrapper.c:258
long receiver_thread
Definition: smsc_wrapper.c:78
void(* start_conn)(SMSCConn *conn)
Definition: smscconn_p.h:245
static void wrapper_stop(SMSCConn *conn)
Definition: smsc_wrapper.c:368
Mutex * reconnect_mutex
Definition: smsc_wrapper.c:80
static int wrapper_add_msg(SMSCConn *conn, Msg *sms)
Definition: smsc_wrapper.c:337
SMSCenter * smsc
Definition: smsc_wrapper.c:75
smscconn_killed_t why_killed
Definition: smscconn_p.h:153
SMSCenter * smsc_open(CfgGroup *grp)
Definition: smsc.c:444
static void smscwrapper_destroy(SmscWrapper *wrap)
Definition: smsc_wrapper.c:84
time_t connect_time
Definition: smscconn_p.h:155
static void wrapper_start(SMSCConn *conn)
Definition: smsc_wrapper.c:377
#define gwthread_create(func, arg)
Definition: gwthread.h:90
#define octstr_create(cstr)
Definition: octstr.h:125
static int wrapper_shutdown(SMSCConn *conn, int finish_sending)
Definition: smsc_wrapper.c:349
volatile sig_atomic_t is_stopped
Definition: smscconn_p.h:169
static void wrapper_receiver(void *arg)
Definition: smsc_wrapper.c:191
int(* shutdown)(SMSCConn *conn, int finish_sending)
Definition: smscconn_p.h:229
smscconn_status_t status
Definition: smscconn_p.h:151
#define gwlist_create()
Definition: list.h:136
long(* queued)(SMSCConn *conn)
Definition: smscconn_p.h:240
int(* send_msg)(SMSCConn *conn, Msg *msg)
Definition: smscconn_p.h:235
long sender_thread
Definition: smsc_wrapper.c:79
void gwlist_add_producer(List *list)
Definition: list.c:383
static long wrapper_queued(SMSCConn *conn)
Definition: smsc_wrapper.c:386
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.