Main Page | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

smscconn_p.h File Reference

#include <signal.h>
#include "gwlib/gwlib.h"
#include "gwlib/regex.h"
#include "smscconn.h"

Include dependency graph for smscconn_p.h:

Include dependency graph

This graph shows which files directly or indirectly include this file:

Included by dependency graph

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)


Function Documentation

int smsc_at2_create SMSCConn conn,
CfgGroup cfg
 

Definition at line 1464 of file smsc_at.c.

References at2_device_thread(), at2_read_modems(), 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::login_prompt, PrivAT2data::max_error_count, PrivAT2data::modem, PrivAT2data::my_number, smscconn::name, ModemDef::name, PrivAT2data::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, smscconn::shutdown, PrivAT2data::shutdown, PrivAT2data::sms_center, PrivAT2data::sms_memory_poll_interval, sms_priority_compare(), SMSCConn, PrivAT2data::speed, smscconn::start_conn, smscconn::status, PrivAT2data::use_telnet, PrivAT2data::username, PrivAT2data::validityperiod, and smscconn::why_killed.

Referenced by smscconn_create().

01465 {
01466     PrivAT2data *privdata;
01467     Octstr *modem_type_string;
01468     long portno;   /* has to be long because of cfg_get_integer */
01469 
01470     privdata = gw_malloc(sizeof(PrivAT2data));
01471     privdata->outgoing_queue = gw_prioqueue_create(sms_priority_compare);
01472     privdata->pending_incoming_messages = gwlist_create();
01473 
01474     privdata->configfile = cfg_get_configfile(cfg);
01475 
01476     privdata->device = cfg_get(cfg, octstr_imm("device"));
01477     if (privdata->device == NULL) {
01478         error(0, "AT2[-]: 'device' missing in at2 configuration.");
01479         goto error;
01480     }
01481     
01482     if (octstr_str_compare(privdata->device, "rawtcp") == 0) {
01483         privdata->rawtcp_host = cfg_get(cfg, octstr_imm("host"));
01484         if (privdata->rawtcp_host == NULL) {
01485             error(0, "AT2[-]: 'host' missing in at2 rawtcp configuration.");
01486             goto error;
01487         }
01488         if (cfg_get_integer(&portno, cfg, octstr_imm("port")) == -1) {
01489             error(0, "AT2[-]: 'port' missing in at2 rawtcp configuration.");
01490             goto error;
01491         }
01492         privdata->rawtcp_port = portno;
01493         privdata->is_serial = 0;
01494         privdata->use_telnet = 0;
01495     }
01496     else if (octstr_str_compare(privdata->device, "telnet") == 0) {
01497         privdata->rawtcp_host = cfg_get(cfg, octstr_imm("host"));
01498         if (privdata->rawtcp_host == NULL) {
01499             error(0, "AT2[-]: 'host' missing in at2 telnet configuration.");
01500             goto error;
01501         }
01502         if (cfg_get_integer(&portno, cfg, octstr_imm("port")) == -1) {
01503             error(0, "AT2[-]: 'port' missing in at2 telnet configuration.");
01504             goto error;
01505         }
01506         privdata->rawtcp_port = portno;
01507         privdata->is_serial = 0;
01508         privdata->use_telnet = 1;
01509     }else {
01510         privdata->is_serial = 1;
01511         privdata->use_telnet = 0;
01512     }
01513 
01514     privdata->name = cfg_get(cfg, octstr_imm("smsc-id"));
01515     if (privdata->name == NULL) {
01516         privdata->name = octstr_duplicate(privdata->device);
01517     }
01518 
01519     privdata->speed = 0;
01520     cfg_get_integer(&privdata->speed, cfg, octstr_imm("speed"));
01521 
01522     privdata->keepalive = 0;
01523     cfg_get_integer(&privdata->keepalive, cfg, octstr_imm("keepalive"));
01524 
01525     cfg_get_bool(&privdata->sms_memory_poll_interval, cfg, octstr_imm("sim-buffering"));
01526     if (privdata->sms_memory_poll_interval) {
01527         if (privdata->keepalive)
01528             privdata->sms_memory_poll_interval = privdata->keepalive;
01529         else
01530             privdata->sms_memory_poll_interval = AT2_DEFAULT_SMS_POLL_INTERVAL;
01531     }
01532 
01533     privdata->my_number       = cfg_get(cfg, octstr_imm("my-number"));
01534     privdata->sms_center      = cfg_get(cfg, octstr_imm("sms-center"));
01535     privdata->username        = cfg_get(cfg, octstr_imm("smsc-username"));
01536     privdata->password        = cfg_get(cfg, octstr_imm("smsc-password"));
01537     privdata->login_prompt    = cfg_get(cfg, octstr_imm("login-prompt"));
01538     privdata->password_prompt = cfg_get(cfg, octstr_imm("password-prompt"));
01539     modem_type_string = cfg_get(cfg, octstr_imm("modemtype"));
01540 
01541     privdata->modem = NULL;
01542 
01543     if (modem_type_string != NULL) {
01544         if (octstr_compare(modem_type_string, octstr_imm("auto")) == 0 ||
01545             octstr_compare(modem_type_string, octstr_imm("autodetect")) == 0)
01546             O_DESTROY(modem_type_string);
01547     }
01548 
01549     if (octstr_len(modem_type_string) == 0) {
01550         info(0, "AT2[%s]: configuration doesn't show modemtype. will autodetect",
01551              octstr_get_cstr(privdata->name));
01552     } else {
01553         info(0, "AT2[%s]: configuration shows modemtype <%s>",
01554              octstr_get_cstr(privdata->name),
01555              octstr_get_cstr(modem_type_string));
01556         privdata->modem = at2_read_modems(privdata, privdata->configfile,
01557                                           modem_type_string, 0);
01558         if (privdata->modem == NULL) {
01559             info(0, "AT2[%s]: modemtype not found, revert to autodetect",
01560                  octstr_get_cstr(privdata->name));
01561         } else {
01562             info(0, "AT2[%s]: read modem definition for <%s>",
01563                  octstr_get_cstr(privdata->name),
01564                  octstr_get_cstr(privdata->modem->name));
01565         }
01566         O_DESTROY(modem_type_string);
01567     }
01568 
01569     privdata->ilb = octstr_create("");
01570     privdata->fd = -1;
01571     privdata->lines = NULL;
01572     privdata->pin = cfg_get(cfg, octstr_imm("pin"));
01573     privdata->pin_ready = 0;
01574     privdata->conn = conn;
01575     privdata->phase2plus = 0;
01576     privdata->validityperiod = cfg_get(cfg, octstr_imm("validityperiod"));
01577     if (cfg_get_integer((long *) &privdata->max_error_count,  cfg, octstr_imm("max-error-count")) == -1)
01578         privdata->max_error_count = -1;
01579 
01580     conn->data = privdata;
01581     conn->name = octstr_format("AT2[%s]", octstr_get_cstr(privdata->name));
01582     conn->status = SMSCCONN_CONNECTING;
01583 
01584     privdata->shutdown = 0;
01585 
01586     conn->status = SMSCCONN_CONNECTING;
01587     conn->connect_time = time(NULL);
01588 
01589     if ((privdata->device_thread = gwthread_create(at2_device_thread, conn)) == -1) {
01590         privdata->shutdown = 1;
01591         goto error;
01592     }
01593 
01594     conn->shutdown = at2_shutdown_cb;
01595     conn->queued = at2_queued_cb;
01596     conn->start_conn = at2_start_cb;
01597     conn->send_msg = at2_add_msg_cb;
01598     return 0;
01599 
01600 error:
01601     error(0, "AT2[%s]: Failed to create at2 smsc connection",
01602           octstr_len(privdata->name) ? octstr_get_cstr(privdata->name) : "");
01603     if (privdata != NULL) {
01604         gw_prioqueue_destroy(privdata->outgoing_queue, NULL);
01605     }
01606     gw_free(privdata);
01607     conn->why_killed = SMSCCONN_KILLED_CANNOT_CONNECT;
01608     conn->status = SMSCCONN_DEAD;
01609     info(0, "AT2[%s]: exiting", octstr_get_cstr(privdata->name));
01610     return -1;
01611 }

Here is the call graph for this function:

int smsc_cgw_create SMSCConn conn,
CfgGroup cfg
 

Definition at line 431 of file smsc_cgw.c.

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

Referenced by smscconn_create().

00432 {
00433     PrivData *privdata;
00434     Octstr *allow_ip, *deny_ip, *host, *appname;
00435     long portno, our_port, waitack;
00436     int i;
00437 
00438     privdata = gw_malloc(sizeof(PrivData));
00439     privdata->outgoing_queue = gwlist_create();
00440     privdata->listening_socket = -1;
00441 
00442     if (cfg_get_integer(&portno, cfg, octstr_imm("port")) == -1)
00443         portno = 0;
00444     privdata->port = portno;
00445 
00446     if (cfg_get_integer(&portno, cfg, octstr_imm("receive-port")) < 0)
00447         portno = 0;
00448     privdata->rport = portno;
00449 
00450     host = cfg_get(cfg, octstr_imm("host"));
00451     appname = cfg_get(cfg, octstr_imm("appname"));
00452 
00453     if (cfg_get_integer(&our_port, cfg, octstr_imm("our-port")) == -1)
00454         privdata->our_port = 0;     /* 0 means use any port */
00455     else
00456         privdata->our_port = our_port;
00457 
00458     allow_ip = cfg_get(cfg, octstr_imm("connect-allow-ip"));
00459     if (allow_ip)
00460         deny_ip = octstr_create("*.*.*.*");
00461     else
00462         deny_ip = NULL;
00463 
00464     if (cfg_get_integer(&waitack, cfg, octstr_imm("wait-ack")) < 0)
00465         privdata->waitack = 60;
00466     else
00467         privdata->waitack = waitack;
00468 
00469     if (privdata->port <= 0 || privdata->port > 65535) {
00470         info(1, "No port defined for cgw -> using default (%d)", CGW_DEFPORT);
00471         privdata->port = CGW_DEFPORT;
00472     }
00473 
00474 
00475     if (host == NULL) {
00476         error(0, "'host' missing in cgw configuration.");
00477         goto error;
00478     }
00479 
00480     if (appname == NULL)
00481         appname = octstr_create("send");
00482 
00483     privdata->allow_ip = allow_ip;
00484     privdata->deny_ip = deny_ip;
00485     privdata->host = host;
00486     privdata->appname = appname;
00487     privdata->nexttrn = 0;
00488     privdata->check_time = 0;
00489 
00490     for (i = 0; i < CGW_TRN_MAX; i++) {
00491         privdata->sendtime[i] = 0;
00492         privdata->dlr[i] = 0;
00493     }
00494 
00495     if (privdata->rport > 0 && cgw_open_listening_socket(conn,privdata) < 0) {
00496         gw_free(privdata);
00497         privdata = NULL;
00498         goto error;
00499     }
00500 
00501 
00502     conn->data = privdata;
00503 
00504     conn->name = octstr_format("CGW:%d", privdata->port);
00505 
00506     privdata->shutdown = 0;
00507 
00508     conn->status = SMSCCONN_CONNECTING;
00509     conn->connect_time = time(NULL);
00510 
00511     if (privdata->rport > 0 && (privdata->receiver_thread = gwthread_create(cgw_listener, conn)) == -1)
00512         goto error;
00513 
00514     if ((privdata->sender_thread = gwthread_create(cgw_sender, conn)) == -1) {
00515         privdata->shutdown = 1;
00516         goto error;
00517     }
00518 
00519     conn->shutdown = cgw_shutdown_cb;
00520     conn->queued = cgw_queued_cb;
00521     conn->start_conn = cgw_start_cb;
00522     conn->send_msg = cgw_add_msg_cb;
00523 
00524     return 0;
00525 
00526 error:
00527     error(0, "Failed to create CGW smsc connection");
00528     if (privdata != NULL)
00529         gwlist_destroy(privdata->outgoing_queue, NULL);
00530 
00531     gw_free(privdata);
00532     octstr_destroy(host);
00533     octstr_destroy(allow_ip);
00534     octstr_destroy(deny_ip);
00535     octstr_destroy(appname);
00536 
00537     conn->why_killed = SMSCCONN_KILLED_CANNOT_CONNECT;
00538     conn->status = SMSCCONN_DEAD;
00539     info(0, "exiting");
00540     return -1;
00541 }

Here is the call graph for this function:

int smsc_cimd2_create SMSCConn conn,
CfgGroup cfg
 

Definition at line 2319 of file smsc_cimd2.c.

References cfg_get, cfg_get_bool(), cfg_get_integer(), cimd2_destroy(), privdata::conn, smscconn::data, debug(), error(), gwlist_add_producer(), gwlist_create, gwthread_create, gwthread_join(), gwthread_wakeup(), privdata::host, smscconn::id, privdata::inbuffer, io_thread(), privdata::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, PrivData, smscconn::queued, privdata::quitting, privdata::receive_seq, privdata::received, smscconn::send_msg, privdata::send_seq, smscconn::shutdown, SMSCConn, privdata::socket, smscconn::start_conn, smscconn::stop_conn, privdata::stopped, privdata::username, and warning().

Referenced by smscconn_create().

02320 {
02321     PrivData *pdata;
02322     int ok;
02323     int maxlen;
02324 
02325     pdata = gw_malloc(sizeof(PrivData));
02326     conn->data = pdata;
02327     pdata->conn = conn;
02328    
02329     pdata->no_dlr = 0;
02330     pdata->quitting = 0;
02331     pdata->socket = -1;
02332     pdata->received = gwlist_create();
02333     pdata->inbuffer = octstr_create("");
02334     pdata->send_seq = 1;
02335     pdata->receive_seq = 0;
02336     pdata->outgoing_queue = gwlist_create();
02337     pdata->stopped = gwlist_create();
02338     gwlist_add_producer(pdata->outgoing_queue);
02339 
02340     if (conn->is_stopped)
02341       gwlist_add_producer(pdata->stopped);
02342 
02343     pdata->host = cfg_get(grp, octstr_imm("host"));
02344     if (cfg_get_integer(&(pdata->port), grp, octstr_imm("port")) == -1)
02345       pdata->port = 0;
02346     if (cfg_get_integer(&(pdata->our_port), grp, octstr_imm("our-port")) == -1)
02347       pdata->our_port = 0;
02348     pdata->username = cfg_get(grp, octstr_imm("smsc-username"));
02349     pdata->password = cfg_get(grp, octstr_imm("smsc-password"));
02350     pdata->my_number = cfg_get(grp, octstr_imm("my-number"));
02351     if (cfg_get_integer(&(pdata->keepalive), grp,octstr_imm("keepalive")) == -1)
02352         pdata->keepalive = 0;
02353 
02354     cfg_get_bool(&pdata->no_dlr, grp, octstr_imm("no-dlr"));
02355     
02356     /* Check that config is OK */
02357     ok = 1;
02358     if (pdata->host == NULL) {
02359         error(0,"CIMD2[%s]: Configuration file doesn't specify host",
02360               octstr_get_cstr(conn->id));
02361         ok = 0;
02362     }
02363     if (pdata->port == 0) {
02364         error(0,"CIMD2[%s]: Configuration file doesn't specify port",
02365               octstr_get_cstr(conn->id));
02366         ok = 0;
02367     }
02368     if (pdata->username == NULL) {
02369         error(0, "CIMD2[%s]: Configuration file doesn't specify username.",
02370               octstr_get_cstr(conn->id));
02371         ok = 0;
02372     }
02373     if (pdata->password == NULL) {
02374         error(0, "CIMD2[%s]: Configuration file doesn't specify password.",
02375               octstr_get_cstr(conn->id));
02376         ok = 0;
02377     }
02378 
02379     if (!ok) {
02380         cimd2_destroy(pdata);
02381         return -1;
02382     }
02383 
02384     conn->name = octstr_format("CIMD2:%s:%d:%s",
02385                      octstr_get_cstr(pdata->host),
02386                      pdata->port,
02387                      octstr_get_cstr(pdata->username));
02388 
02389 
02390     if (pdata->keepalive > 0) {
02391       debug("bb.sms.cimd2", 0, "CIMD2[%s]: Keepalive set to %ld seconds", 
02392             octstr_get_cstr(conn->id),
02393             pdata->keepalive);
02394         pdata->next_ping = time(NULL) + pdata->keepalive;
02395     }
02396 
02397     maxlen = parm_maxlen(P_USER_IDENTITY);
02398     if (octstr_len(pdata->username) > maxlen) {
02399         octstr_truncate(pdata->username, maxlen);
02400         warning(0, "CIMD2[%s]: Truncating username to %d chars", 
02401                 octstr_get_cstr(conn->id),
02402                 maxlen);
02403     }
02404 
02405     maxlen = parm_maxlen(P_PASSWORD);
02406     if (octstr_len(pdata->password) > maxlen) {
02407         octstr_truncate(pdata->password, maxlen);
02408         warning(0, "CIMD2[%s]: Truncating password to %d chars", 
02409                 octstr_get_cstr(conn->id),
02410                 maxlen);
02411     }
02412 
02413     pdata->io_thread = gwthread_create(io_thread, conn);
02414 
02415     if (pdata->io_thread == -1) {  
02416 
02417         error(0,"CIMD2[%s]: Couldn't start I/O thread.",
02418               octstr_get_cstr(conn->id));
02419         pdata->quitting = 1;
02420         gwthread_wakeup(pdata->io_thread);
02421         gwthread_join(pdata->io_thread);
02422         cimd2_destroy(pdata);
02423         return -1;  
02424     } 
02425 
02426     conn->send_msg = cimd2_add_msg_cb;
02427     conn->shutdown = cimd2_shutdown_cb;
02428     conn->queued = cimd2_queued_cb;
02429     conn->start_conn = cimd2_start_cb;
02430     conn->stop_conn = cimd2_stop_cb;
02431 
02432     return 0;
02433 }

Here is the call graph for this function:

int smsc_emi2_create SMSCConn conn,
CfgGroup cfg
 

Definition at line 1612 of file smsc_emi.c.

References 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, 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(), privdata::host, privdata::idle_timeout, info(), privdata::keepalive, privdata::last_activity_time, privdata::listening_socket, privdata::my_number, privdata::nadc, smscconn::name, privdata::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, privdata::our_port, privdata::outgoing_queue, privdata::password, privdata::port, privdata::priv_nexttrn, PrivData, smscconn::queued, privdata::receiver_thread, privdata::rport, smscconn::send_msg, privdata::sender_thread, privdata::sendtime, smscconn::shutdown, privdata::shutdown, privdata::slots, sms_priority_compare(), SMSCConn, 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().

01613 {
01614     PrivData *privdata;
01615     Octstr *allow_ip, *deny_ip, *host, *alt_host;
01616     long portno, our_port, keepalive, flowcontrol, waitack, 
01617          idle_timeout, alt_portno, alt_charset, waitack_expire;
01618     long window;
01619         /* has to be long because of cfg_get_integer */
01620     int i;
01621 
01622     allow_ip = deny_ip = host = alt_host = NULL; 
01623 
01624     privdata = gw_malloc(sizeof(PrivData));
01625     privdata->outgoing_queue = gw_prioqueue_create(sms_priority_compare);
01626     privdata->listening_socket = -1;
01627     privdata->can_write = 1;
01628     privdata->priv_nexttrn = 0;
01629     privdata->last_activity_time = 0;
01630     privdata->check_time = 0;
01631     
01632     host = cfg_get(cfg, octstr_imm("host"));
01633     if (host == NULL) {
01634     error(0, "EMI2[-]: 'host' missing in emi2 configuration.");
01635     goto error;
01636     }
01637     privdata->host = host;
01638 
01639     if (cfg_get_integer(&portno, cfg, octstr_imm("port")) == -1)
01640     portno = 0;
01641     privdata->port = portno;
01642     if (privdata->port <= 0 || privdata->port > 65535) {
01643     error(0, "EMI2[%s]: 'port' missing/invalid in emi2 configuration.",
01644           octstr_get_cstr(host));
01645     goto error;
01646     }
01647 
01648     if (cfg_get_integer(&our_port, cfg, octstr_imm("our-port")) == -1)
01649     privdata->our_port = 0; /* 0 means use any port */
01650     else
01651     privdata->our_port = our_port;
01652 
01653     privdata->name = cfg_get(cfg, octstr_imm("smsc-id"));
01654     if(privdata->name == NULL) {
01655     privdata->name = octstr_create("");
01656 
01657     /* Add our_host */
01658     if(octstr_len(conn->our_host)) {
01659         octstr_append(privdata->name, conn->our_host);
01660     }
01661 
01662     /* Add our_port */
01663     if(privdata->our_port != 0) {
01664         /* if we have our_port but not our_host, add kannel:our_port */
01665         if(octstr_len(privdata->name) == 0) {
01666         octstr_append(privdata->name, octstr_imm("kannel"));
01667         }
01668         octstr_append_char(privdata->name, ':');
01669         octstr_append_decimal(privdata->name, privdata->our_port);
01670     } else {
01671         if(octstr_len(privdata->name) != 0) {
01672         octstr_append(privdata->name, octstr_imm(":*"));
01673         }
01674     }
01675         
01676     /* if we have our_host neither our_port */
01677     if(octstr_len(privdata->name) != 0)
01678         octstr_append(privdata->name, octstr_imm("->"));
01679 
01680     octstr_append(privdata->name, privdata->host);
01681     octstr_append_char(privdata->name, ':');
01682     octstr_append_decimal(privdata->name, privdata->port);
01683     }
01684 
01685 
01686     if (cfg_get_integer(&idle_timeout, cfg, octstr_imm("idle-timeout")) == -1)
01687     idle_timeout = 0;
01688     
01689     privdata->idle_timeout = idle_timeout;
01690 
01691     alt_host = cfg_get(cfg, octstr_imm("alt-host"));
01692     privdata->alt_host = alt_host;
01693 
01694     if (cfg_get_integer(&portno, cfg, octstr_imm("receive-port")) < 0)
01695     portno = 0;
01696     privdata->rport = portno;
01697 
01698     if (cfg_get_integer(&alt_portno, cfg, octstr_imm("alt-port")) < 0) 
01699     alt_portno = 0;
01700     privdata->alt_port = alt_portno;
01701 
01702     allow_ip = cfg_get(cfg, octstr_imm("connect-allow-ip"));
01703     if (allow_ip)
01704     deny_ip = octstr_create("*.*.*.*");
01705     else
01706     deny_ip = NULL;
01707     privdata->username = cfg_get(cfg, octstr_imm("smsc-username"));
01708     privdata->password = cfg_get(cfg, octstr_imm("smsc-password"));
01709 
01710     privdata->my_number = cfg_get(cfg, octstr_imm("my-number"));
01711 
01712     privdata->npid = cfg_get(cfg, octstr_imm("notification-pid"));
01713     privdata->nadc = cfg_get(cfg, octstr_imm("notification-addr"));
01714     
01715     if ( (privdata->username == NULL && privdata->my_number == NULL)
01716          || cfg_get_integer(&keepalive, cfg, octstr_imm("keepalive")) < 0)
01717     privdata->keepalive = 0;
01718     else
01719     privdata->keepalive = keepalive;
01720 
01721     if (cfg_get_integer(&flowcontrol, cfg, octstr_imm("flow-control")) < 0)
01722     privdata->flowcontrol = 0;
01723     else
01724     privdata->flowcontrol = flowcontrol;
01725     if (privdata->flowcontrol < 0 || privdata->flowcontrol > 1) {
01726     error(0, "EMI2[%s]: 'flow-control' invalid in emi2 configuration.",
01727           octstr_get_cstr(privdata->name));
01728     goto error;
01729     }
01730 
01731     if (cfg_get_integer(&window, cfg, octstr_imm("window")) < 0)
01732     privdata->window = EMI2_MAX_TRN;
01733     else
01734     privdata->window = window;
01735     if (privdata->window > EMI2_MAX_TRN) {
01736     warning(0, "EMI2[%s]: Value of 'window' should be lesser or equal to %d..", 
01737         octstr_get_cstr(privdata->name), EMI2_MAX_TRN);
01738     privdata->window = EMI2_MAX_TRN;
01739     }
01740 
01741     if (cfg_get_integer(&waitack, cfg, octstr_imm("wait-ack")) < 0)
01742     privdata->waitack = 60;
01743     else
01744     privdata->waitack = waitack;
01745     if (privdata->waitack < 30 ) {
01746     error(0, "EMI2[%s]: 'wait-ack' invalid in emi2 configuration.",
01747           octstr_get_cstr(privdata->name));
01748     goto error;
01749     }
01750 
01751     if (cfg_get_integer(&waitack_expire, cfg, octstr_imm("wait-ack-expire")) < 0)
01752     privdata->waitack_expire = 0;
01753     else
01754     privdata->waitack_expire = waitack_expire;
01755     if (privdata->waitack_expire >3  ) {
01756     error(0, "EMI2[%s]: 'wait-ack-expire' invalid in emi2 configuration.",
01757           octstr_get_cstr(privdata->name));
01758     goto error;
01759     }
01760 
01761     if (privdata->rport < 0 || privdata->rport > 65535) {
01762     error(0, "EMI2[%s]: 'receive-port' missing/invalid in emi2 configuration.",
01763           octstr_get_cstr(privdata->name));
01764     goto error;
01765     }
01766 
01767     if (cfg_get_integer(&alt_charset, cfg, octstr_imm("alt-charset")) < 0)
01768         privdata->alt_charset = 0;
01769     else
01770         privdata->alt_charset = alt_charset;    
01771 
01772     privdata->allow_ip = allow_ip;
01773     privdata->deny_ip = deny_ip;
01774 
01775     if (privdata->rport > 0 && emi2_open_listening_socket(conn,privdata) < 0) {
01776     gw_free(privdata);
01777     privdata = NULL;
01778     goto error;
01779     }
01780 
01781     conn->data = privdata;
01782 
01783     conn->name = octstr_format("EMI2:%S:%d:%S", privdata->host, privdata->port,
01784                                privdata->username ? privdata->username : octstr_imm("null"));
01785 
01786     privdata->shutdown = 0;
01787 
01788     for (i = 0; i < EMI2_MAX_TRN; i++)
01789     privdata->slots[i].sendtime = 0;
01790     privdata->unacked = 0;
01791 
01792     conn->status = SMSCCONN_CONNECTING;
01793     conn->connect_time = time(NULL);
01794 
01795     if ( privdata->rport > 0 && (privdata->receiver_thread =
01796       gwthread_create(emi2_listener, conn)) == -1)
01797       goto error;
01798 
01799     if ((privdata->sender_thread = gwthread_create(emi2_sender, conn)) == -1) {
01800     privdata->shutdown = 1;
01801     if (privdata->rport > 0) {
01802         gwthread_wakeup(privdata->receiver_thread);
01803         gwthread_join(privdata->receiver_thread);
01804     }
01805     goto error;
01806     }
01807 
01808     conn->shutdown = shutdown_cb;
01809     conn->queued = queued_cb;
01810     conn->start_conn = start_cb;
01811     conn->send_msg = add_msg_cb;
01812 
01813     return 0;
01814 
01815 error:
01816     error(0, "EMI2[%s]: Failed to create emi2 smsc connection",
01817       octstr_get_cstr(privdata->name));
01818     if (privdata != NULL) {
01819     gw_prioqueue_destroy(privdata->outgoing_queue, NULL);
01820     }
01821     gw_free(privdata);
01822     octstr_destroy(allow_ip);
01823     octstr_destroy(deny_ip);
01824     octstr_destroy(host);
01825     conn->why_killed = SMSCCONN_KILLED_CANNOT_CONNECT;
01826     conn->status = SMSCCONN_DEAD;
01827     info(0, "EMI2[%s]: exiting", octstr_get_cstr(privdata->name));
01828     return -1;
01829 }

Here is the call graph for this function:

int smsc_fake_create SMSCConn conn,
CfgGroup cfg
 

Definition at line 514 of file smsc_fake.c.

References privdata::allow_ip, cfg_get, cfg_get_integer(), smscconn::connect_time, privdata::connection_thread, smscconn::data, 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, PrivData, smscconn::queued, smscconn::send_msg, smscconn::shutdown, privdata::shutdown, SMSCConn, smscconn::start_conn, smscconn::status, and smscconn::why_killed.

Referenced by smscconn_create().

00515 {
00516     PrivData *privdata = NULL;
00517     Octstr *allow_ip, *deny_ip;
00518     long portno;   /* has to be long because of cfg_get_integer */
00519 
00520     if (cfg_get_integer(&portno, cfg, octstr_imm("port")) == -1)
00521         portno = 0;
00522     allow_ip = cfg_get(cfg, octstr_imm("connect-allow-ip"));
00523     if (allow_ip)
00524         deny_ip = octstr_create("*.*.*.*");
00525     else
00526         deny_ip = NULL;
00527 
00528     if (portno == 0) {
00529         error(0, "'port' invalid in 'fake' record.");
00530         goto error;
00531     }
00532     privdata = gw_malloc(sizeof(PrivData));
00533     privdata->listening_socket = -1;
00534 
00535     privdata->port = portno;
00536     privdata->allow_ip = allow_ip;
00537     privdata->deny_ip = deny_ip;
00538 
00539     if (fake_open_connection(conn, privdata) < 0) {
00540         gw_free(privdata);
00541         privdata = NULL;
00542         goto error;
00543     }
00544 
00545     conn->data = privdata;
00546 
00547     conn->name = octstr_format("FAKE:%d", privdata->port);
00548 
00549     privdata->outgoing_queue = gwlist_create();
00550     privdata->shutdown = 0;
00551 
00552     conn->status = SMSCCONN_CONNECTING;
00553     conn->connect_time = time(NULL);
00554 
00555     if ((privdata->connection_thread = gwthread_create(fake_listener, conn)) == -1)
00556         goto error;
00557 
00558     conn->shutdown = shutdown_cb;
00559     conn->queued = queued_cb;
00560     conn->start_conn = start_cb;
00561     conn->send_msg = add_msg_cb;
00562 
00563     return 0;
00564 
00565 error:
00566     error(0, "Failed to create fake smsc connection");
00567     if (privdata != NULL) {
00568         gwlist_destroy(privdata->outgoing_queue, NULL);
00569         if (close(privdata->listening_socket == -1)) {
00570             error(errno, "smsc_fake: closing listening socket port %d failed",
00571                   privdata->listening_socket);
00572         }
00573     }
00574     gw_free(privdata);
00575     octstr_destroy(allow_ip);
00576     octstr_destroy(deny_ip);
00577     conn->why_killed = SMSCCONN_KILLED_CANNOT_CONNECT;
00578     conn->status = SMSCCONN_DEAD;
00579     return -1;
00580 }

Here is the call graph for this function:

int smsc_http_create SMSCConn conn,
CfgGroup cfg
 

Definition at line 1597 of file smsc_http.c.

References conndata::allow_ip, conndata::alt_charset, cfg_get, cfg_get_bool(), cfg_get_integer(), ConnData, conndata_destroy(), smscconn::connect_time, smscconn::data, conndata::dlr_url, error(), gwthread_create, http_caller_create(), http_open_port_if(), conndata::http_ref, httpsmsc_receiver(), httpsmsc_send_cb(), smscconn::id, info(), 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, smscconn::our_host, panic, conndata::parse_reply, conndata::password, conndata::permfail_regex, conndata::port, conndata::proxy, smscconn::queued, conndata::receive_sms, conndata::receive_thread, conndata::send_cb_thread, smscconn::send_msg, conndata::send_sms, conndata::send_url, conndata::shutdown, smscconn::shutdown, SMSCConn, ssl, smscconn::status, conndata::success_regex, conndata::system_id, conndata::tempfail_regex, type, conndata::username, and smscconn::why_killed.

Referenced by smscconn_create().

01598 {
01599     ConnData *conndata = NULL;
01600     Octstr *type;
01601     long portno;   /* has to be long because of cfg_get_integer */
01602     int ssl = 0;   /* indicate if SSL-enabled server should be used */
01603     Octstr *os;
01604 
01605     if (cfg_get_integer(&portno, cfg, octstr_imm("port")) == -1) {
01606         error(0, "HTTP[%s]: 'port' invalid in smsc 'http' record.",
01607               octstr_get_cstr(conn->id));
01608         return -1;
01609     }
01610     cfg_get_bool(&ssl, cfg, octstr_imm("use-ssl"));
01611     if ((type = cfg_get(cfg, octstr_imm("system-type")))==NULL) {
01612         error(0, "HTTP[%s]: 'type' missing in smsc 'http' record.",
01613               octstr_get_cstr(conn->id));
01614         octstr_destroy(type);
01615         return -1;
01616     }
01617     conndata = gw_malloc(sizeof(ConnData));
01618     conndata->http_ref = NULL;
01619     conndata->success_regex = 
01620         conndata->permfail_regex = conndata->tempfail_regex = NULL;
01621 
01622     conndata->allow_ip = cfg_get(cfg, octstr_imm("connect-allow-ip"));
01623     conndata->send_url = cfg_get(cfg, octstr_imm("send-url"));
01624     conndata->dlr_url = cfg_get(cfg, octstr_imm("dlr-url"));
01625     conndata->username = cfg_get(cfg, octstr_imm("smsc-username"));
01626     conndata->password = cfg_get(cfg, octstr_imm("smsc-password"));
01627     conndata->system_id = cfg_get(cfg, octstr_imm("system-id"));
01628     cfg_get_bool(&conndata->no_sender, cfg, octstr_imm("no-sender"));
01629     cfg_get_bool(&conndata->no_coding, cfg, octstr_imm("no-coding"));
01630     cfg_get_bool(&conndata->no_sep, cfg, octstr_imm("no-sep"));
01631     conndata->proxy = cfg_get(cfg, octstr_imm("system-id"));
01632     conndata->alt_charset = cfg_get(cfg, octstr_imm("alt-charset"));
01633 
01634     if (conndata->send_url == NULL)
01635         panic(0, "HTTP[%s]: Sending not allowed. No 'send-url' specified.",
01636               octstr_get_cstr(conn->id));
01637 
01638     if (octstr_case_compare(type, octstr_imm("kannel")) == 0) {
01639         if (conndata->username == NULL || conndata->password == NULL) {
01640             error(0, "HTTP[%s]: 'username' and 'password' required for Kannel http smsc",
01641                   octstr_get_cstr(conn->id));
01642             goto error;
01643         }
01644         conndata->receive_sms = kannel_receive_sms;
01645         conndata->send_sms = kannel_send_sms;
01646         conndata->parse_reply = kannel_parse_reply;
01647     }
01648     else if (octstr_case_compare(type, octstr_imm("brunet")) == 0) {
01649         if (conndata->username == NULL) {
01650             error(0, "HTTP[%s]: 'username' (=CustomerId) required for bruNET http smsc",
01651                   octstr_get_cstr(conn->id));
01652             goto error;
01653         }
01654         conndata->receive_sms = brunet_receive_sms;
01655         conndata->send_sms = brunet_send_sms;
01656         conndata->parse_reply = brunet_parse_reply;
01657     }
01658     else if (octstr_case_compare(type, octstr_imm("xidris")) == 0) {
01659         if (conndata->username == NULL || conndata->password == NULL) {
01660             error(0, "HTTP[%s]: 'username' and 'password' required for Xidris http smsc",
01661                   octstr_get_cstr(conn->id));
01662             goto error;
01663         }
01664         conndata->receive_sms = xidris_receive_sms;
01665         conndata->send_sms = xidris_send_sms;
01666         conndata->parse_reply = xidris_parse_reply;
01667     }
01668     else if (octstr_case_compare(type, octstr_imm("wapme")) == 0) {
01669         if (conndata->username == NULL || conndata->password == NULL) {
01670             error(0, "HTTP[%s]: 'username' and 'password' required for Wapme http smsc",
01671                   octstr_get_cstr(conn->id));
01672             goto error;
01673         }
01674         conndata->receive_sms = kannel_receive_sms; /* emulate sendsms interface */
01675         conndata->send_sms = wapme_smsproxy_send_sms;
01676         conndata->parse_reply = wapme_smsproxy_parse_reply;
01677     }
01678     else if (octstr_case_compare(type, octstr_imm("clickatell")) == 0) {
01679         /* no required data checks here? */
01680         conndata->receive_sms = clickatell_receive_sms;
01681         conndata->send_sms = clickatell_send_sms;
01682         conndata->parse_reply = clickatell_parse_reply;
01683     }
01684     else if (octstr_case_compare(type, octstr_imm("generic")) == 0) {
01685         /* we need at least the criteria for a successfull sent */
01686         if ((os = cfg_get(cfg, octstr_imm("status-success-regex"))) == NULL) {
01687             error(0, "HTTP[%s]: 'status-success-regex' required for generic http smsc",
01688                   octstr_get_cstr(conn->id));
01689             goto error;
01690         }
01691         conndata->receive_sms = kannel_receive_sms; /* emulate sendsms interface */
01692         conndata->send_sms = generic_send_sms;
01693         conndata->parse_reply = generic_parse_reply;
01694 
01695         /* pre-compile regex expressions */
01696         if (os != NULL) {   /* this is implicite due to the above if check */
01697             if ((conndata->success_regex = gw_regex_comp(os, REG_EXTENDED)) == NULL)
01698                 panic(0, "Could not compile regex pattern '%s'", octstr_get_cstr(os));
01699             octstr_destroy(os);
01700         }
01701         if ((os = cfg_get(cfg, octstr_imm("status-permfail-regex"))) != NULL) {
01702             if ((conndata->permfail_regex = gw_regex_comp(os, REG_EXTENDED)) == NULL)
01703                 panic(0, "Could not compile regex pattern '%s'", octstr_get_cstr(os));
01704             octstr_destroy(os);
01705         }
01706         if ((os = cfg_get(cfg, octstr_imm("status-tempfail-regex"))) != NULL) {
01707             if ((conndata->tempfail_regex = gw_regex_comp(os, REG_EXTENDED)) == NULL)
01708                 panic(0, "Could not compile regex pattern '%s'", octstr_get_cstr(os));
01709             octstr_destroy(os);
01710         }
01711     }
01712     /*
01713      * ADD NEW HTTP SMSC TYPES HERE
01714      */
01715     else {
01716     error(0, "HTTP[%s]: system-type '%s' unknown smsc 'http' record.",
01717           octstr_get_cstr(conn->id), octstr_get_cstr(type));
01718 
01719     goto error;
01720     }   
01721     conndata->open_sends = 0;
01722     conndata->http_ref = http_caller_create();
01723     
01724     conn->data = conndata;
01725     conn->name = octstr_format("HTTP:%S", type);
01726     conn->status = SMSCCONN_ACTIVE;
01727     conn->connect_time = time(NULL);
01728 
01729     conn->shutdown = httpsmsc_shutdown;
01730     conn->queued = httpsmsc_queued;
01731     conn->send_msg = httpsmsc_send;
01732 
01733     if (http_open_port_if(portno, ssl, conn->our_host)==-1)
01734     goto error;
01735 
01736     conndata->port = portno;
01737     conndata->shutdown = 0;
01738     
01739     if ((conndata->receive_thread =
01740      gwthread_create(httpsmsc_receiver, conn)) == -1)
01741     goto error;
01742 
01743     if ((conndata->send_cb_thread =
01744      gwthread_create(httpsmsc_send_cb, conn)) == -1)
01745     goto error;
01746 
01747     info(0, "HTTP[%s]: Initiated and ready", octstr_get_cstr(conn->id));
01748     
01749     octstr_destroy(type);
01750     return 0;
01751 
01752 error:
01753     error(0, "HTTP[%s]: Failed to create http smsc connection",
01754           octstr_get_cstr(conn->id));
01755 
01756     conn->data = NULL;
01757     conndata_destroy(conndata);
01758     conn->why_killed = SMSCCONN_KILLED_CANNOT_CONNECT;
01759     conn->status = SMSCCONN_DEAD;
01760     octstr_destroy(type);
01761     return -1;
01762 }

Here is the call graph for this function:

int smsc_oisd_create SMSCConn conn,
CfgGroup cfg
 

Definition at line 1497 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, io_thread(), privdata::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_destroy(), ok, privdata::outgoing_queue, privdata::port, PrivData, smscconn::queued, privdata::quitting, privdata::received, smscconn::send_msg, privdata::send_seq, smscconn::shutdown, SMSCConn, privdata::socket, smscconn::start_conn, smscconn::stop_conn, privdata::stopped, and privdata::validityperiod.

Referenced by smscconn_create().

01498 {
01499     PrivData *pdata;
01500     int ok;
01501 
01502     pdata = gw_malloc(sizeof(PrivData));
01503     conn->data = pdata;
01504     pdata->conn = conn;
01505 
01506     pdata->no_dlr = 0;
01507     pdata->quitting = 0;
01508     pdata->socket = -1;
01509     pdata->received = gwlist_create();
01510     pdata->inbuffer = octstr_create("");
01511     pdata->send_seq = 1;
01512     pdata->outgoing_queue = gwlist_create();
01513     pdata->stopped = gwlist_create();
01514     gwlist_add_producer(pdata->outgoing_queue);
01515 
01516     if (conn->is_stopped)
01517         gwlist_add_producer(pdata->stopped);
01518 
01519     pdata->host = cfg_get(grp, octstr_imm("host"));
01520     if (cfg_get_integer(&(pdata->port), grp, octstr_imm("port")) == -1)
01521         pdata->port = 0;
01522     pdata->my_number = cfg_get(grp, octstr_imm("my-number"));
01523     if (cfg_get_integer(&(pdata->keepalive), grp, octstr_imm("keepalive")) == -1)
01524         pdata->keepalive = 0;
01525     if (cfg_get_integer(&(pdata->validityperiod), grp, octstr_imm("validityperiod")) == -1)
01526         pdata->validityperiod = 0;
01527 
01528     cfg_get_bool(&pdata->no_dlr, grp, octstr_imm("no-dlr"));
01529 
01530     /* Check that config is OK */
01531     ok = 1;
01532     if (pdata->host == NULL) {
01533         error(0, "OISD[%s]: Configuration file doesn't specify host",
01534               octstr_get_cstr(conn->id));
01535         ok = 0;
01536     }
01537     if (pdata->port == 0) {
01538         error(0, "OISD[%s]: Configuration file doesn't specify port",
01539               octstr_get_cstr(conn->id));
01540         ok = 0;
01541     }
01542     if (pdata->my_number == NULL && pdata->keepalive > 0) {
01543         error(0, "OISD[%s]: Configuration file doesn't specify my-number.",
01544               octstr_get_cstr(conn->id));
01545         ok = 0;
01546     }
01547 
01548     if (!ok) {
01549         oisd_destroy(pdata);
01550         return -1;
01551     }
01552 
01553     conn->name = octstr_format("OISD:%s:%d",
01554                      octstr_get_cstr(pdata->host),
01555                      pdata->port);
01556 
01557 
01558     if (pdata->keepalive > 0) {
01559         debug("bb.sms.oisd", 0, "OISD[%s]: Keepalive set to %ld seconds",
01560               octstr_get_cstr(conn->id),
01561               pdata->keepalive);
01562         pdata->next_ping = time(NULL) + pdata->keepalive;
01563     }
01564 
01565     if (pdata->validityperiod > 0) {
01566         debug("bb.sms.oisd", 0, "OISD[%s]: Validity-Period set to %ld",
01567               octstr_get_cstr(conn->id),
01568               pdata->validityperiod);
01569     }
01570 
01571     pdata->io_thread = gwthread_create(io_thread, conn);
01572 
01573     if (pdata->io_thread == -1) {
01574 
01575         error(0, "OISD[%s]: Couldn't start I/O thread.",
01576               octstr_get_cstr(conn->id));
01577         pdata->quitting = 1;
01578         gwthread_wakeup(pdata->io_thread);
01579         gwthread_join(pdata->io_thread);
01580         oisd_destroy(pdata);
01581         return -1;
01582     }
01583 
01584     conn->send_msg = oisd_add_msg_cb;
01585     conn->shutdown = oisd_shutdown_cb;
01586     conn->queued = oisd_queued_cb;
01587     conn->start_conn = oisd_start_cb;
01588     conn->stop_conn = oisd_stop_cb;
01589 
01590     return 0;
01591 }

Here is the call graph for this function:

int smsc_smasi_create SMSCConn conn,
CfgGroup cfg
 

Definition at line 1131 of file smsc_smasi.c.

References assign, colon, comma, SMASI::conn, cr, smscconn::data, error(), gwthread_create, smscconn::id, init_configuration(), lf, octstr_create, octstr_get_cstr, panic, smscconn::queued, smscconn::send_msg, smscconn::shutdown, smasi_create(), smasi_destroy(), smasi_thread(), SMSCConn, smscconn::status, and SMASI::thread_handle.

Referenced by smscconn_create().

01132 {
01133     SMASI *smasi = NULL;
01134 
01135     /* Initialize data encoding subsystem. */
01136     colon = octstr_create(":3a");
01137     assign = octstr_create(":3d");
01138     comma = octstr_create(":2c");
01139     cr = octstr_create(":0a");
01140     lf = octstr_create(":0d");
01141 
01142     /* Create main SMASI structure and initialize it with configuration
01143      * settings.
01144      */
01145     smasi = smasi_create(conn);
01146 
01147     if (init_configuration(smasi, config) != 0)
01148         panic(0, "SMASI SMSC module configuration invalid.");
01149 
01150     conn->status = SMSCCONN_CONNECTING;
01151 
01152     /* Port is always set to a configured value or defaults to 21500.
01153      * Therefore, threads are always started.
01154      */
01155     smasi->thread_handle = gwthread_create(smasi_thread, smasi);
01156 
01157     if (smasi->thread_handle == -1) {
01158         error(0, "SMASI[%s]: Couldn't start SMASI thread.",
01159               octstr_get_cstr(smasi->conn->id));
01160         smasi_destroy(conn->data);
01161         return -1;
01162     } 
01163 
01164     /* Setup control function pointers. */
01165     conn->shutdown = shutdown_cb;
01166     conn->queued = queued_cb;
01167     conn->send_msg = send_msg_cb;
01168 
01169     return 0;
01170 }

Here is the call graph for this function:

int smsc_smpp_create SMSCConn conn,
CfgGroup cfg
 

Definition at line 1966 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(), gwthread_create, gwthread_join(), gwthread_wakeup(), smscconn::id, io_arg_create(), io_thread(), smscconn::name, octstr_destroy(), octstr_duplicate, octstr_format(), octstr_get_cstr, octstr_imm(), octstr_len(), ok, panic, password, port, smscconn::queued, SMPP::quitting, SMPP::receiver, smscconn::send_msg, smscconn::shutdown, smpp_create(), smpp_destroy(), SMSCConn, smscconn::status, SMPP::transmitter, username, and warning().

Referenced by smscconn_create().

01967 {
01968     Octstr *host;
01969     long port;
01970     long receive_port;
01971     Octstr *username;
01972     Octstr *password;
01973     Octstr *system_id;
01974     Octstr *system_type;
01975     Octstr *address_range;
01976     long source_addr_ton;
01977     long source_addr_npi;
01978     long dest_addr_ton;
01979     long dest_addr_npi;
01980     Octstr *my_number;
01981     Octstr *service_type;
01982     SMPP *smpp;
01983     int ok;
01984     int transceiver_mode;
01985     Octstr *smsc_id;
01986     long enquire_link_interval;
01987     long max_pending_submits;
01988     long version;
01989     long priority;
01990     long validity;
01991     long smpp_msg_id_type;
01992     int autodetect_addr;
01993     Octstr *alt_charset;
01994     Octstr *alt_addr_charset;
01995     long connection_timeout, wait_ack, wait_ack_action;
01996 
01997     my_number = alt_addr_charset = alt_charset = NULL;
01998     transceiver_mode = 0;
01999     autodetect_addr = 1;
02000  
02001     host = cfg_get(grp, octstr_imm("host")); 
02002     if (cfg_get_integer(&port, grp, octstr_imm("port")) == -1) 
02003         port = 0; 
02004     if (cfg_get_integer(&receive_port, grp, octstr_imm("receive-port")) == -1) 
02005         receive_port = 0; 
02006     cfg_get_bool(&transceiver_mode, grp, octstr_imm("transceiver-mode")); 
02007     username = cfg_get(grp, octstr_imm("smsc-username")); 
02008     password = cfg_get(grp, octstr_imm("smsc-password")); 
02009     system_type = cfg_get(grp, octstr_imm("system-type")); 
02010     address_range = cfg_get(grp, octstr_imm("address-range")); 
02011     my_number = cfg_get(grp, octstr_imm("my-number")); 
02012     service_type = cfg_get(grp, octstr_imm("service-type")); 
02013      
02014     system_id = cfg_get(grp, octstr_imm("system-id")); 
02015     if (system_id != NULL) { 
02016         warning(0, "SMPP: obsolete system-id variable is set, " 
02017                "use smsc-username instead."); 
02018         if (username == NULL) { 
02019             warning(0, "SMPP: smsc-username not set, using system-id instead"); 
02020             username = system_id; 
02021         } else 
02022             octstr_destroy(system_id); 
02023     } 
02024 
02025     /* 
02026      * check if timing values have been configured, otherwise
02027      * use the predefined default values.
02028      */
02029     if (cfg_get_integer(&enquire_link_interval, grp, 
02030                         octstr_imm("enquire-link-interval")) == -1)
02031         enquire_link_interval = SMPP_ENQUIRE_LINK_INTERVAL;
02032     if (cfg_get_integer(&max_pending_submits, grp, 
02033                         octstr_imm("max-pending-submits")) == -1)
02034         max_pending_submits = SMPP_MAX_PENDING_SUBMITS;
02035  
02036     /* Check that config is OK */ 
02037     ok = 1; 
02038     if (host == NULL) { 
02039         error(0,"SMPP: Configuration file doesn't specify host"); 
02040         ok = 0; 
02041     }     
02042     if (username == NULL) { 
02043         error(0, "SMPP: Configuration file doesn't specify username."); 
02044         ok = 0; 
02045     } 
02046     if (password == NULL) { 
02047         error(0, "SMPP: Configuration file doesn't specify password."); 
02048         ok = 0; 
02049     } 
02050     if (system_type == NULL) { 
02051         error(0, "SMPP: Configuration file doesn't specify system-type."); 
02052         ok = 0; 
02053     } 
02054     if (octstr_len(service_type) > 6) {
02055             error(0, "SMPP: Service type must be 6 characters or less.");
02056             ok = 0;
02057     }
02058 
02059     if (!ok) 
02060         return -1; 
02061  
02062     /* if the ton and npi values are forced, set them, else set them to -1 */ 
02063     if (cfg_get_integer(&source_addr_ton, grp, 
02064                         octstr_imm("source-addr-ton")) == -1) 
02065         source_addr_ton = -1; 
02066     if (cfg_get_integer(&source_addr_npi, grp, 
02067                         octstr_imm("source-addr-npi")) == -1) 
02068         source_addr_npi = -1; 
02069     if (cfg_get_integer(&dest_addr_ton, grp, 
02070                         octstr_imm("dest-addr-ton")) == -1) 
02071         dest_addr_ton = -1; 
02072     if (cfg_get_integer(&dest_addr_npi, grp, 
02073                         octstr_imm("dest-addr-npi")) == -1) 
02074         dest_addr_npi = -1; 
02075 
02076     /* if source addr autodetection should be used set this to 1 */
02077     if (cfg_get_bool(&autodetect_addr, grp, octstr_imm("source-addr-autodetect")) == -1)
02078         autodetect_addr = 1; /* default is autodetect if no option defined */
02079 
02080     /* check for any specified interface version */
02081     if (cfg_get_integer(&version, grp, octstr_imm("interface-version")) == -1)
02082         version = SMPP_DEFAULT_VERSION;
02083     else
02084         /* convert decimal to BCD */
02085         version = ((version / 10) << 4) + (version % 10);
02086 
02087     /* check for any specified priority value in range [0-5] */
02088     if (cfg_get_integer(&priority, grp, octstr_imm("priority")) == -1)
02089         priority = SMPP_DEFAULT_PRIORITY;
02090     else if (priority < 0 || priority > 3)
02091         panic(0, "SMPP: Invalid value for priority directive in configuraton (allowed range 0-3).");
02092 
02093     /* check for message validity period */
02094     if (cfg_get_integer(&validity, grp, octstr_imm("validityperiod")) == -1)
02095         validity = -1;
02096     else if (validity < 0)
02097         panic(0, "SMPP: Invalid value for validity period (allowed value >= 0).");
02098 
02099     /* set the msg_id type variable for this SMSC */
02100     if (cfg_get_integer(&smpp_msg_id_type, grp, octstr_imm("msg-id-type")) == -1) {
02101         /* 
02102          * defaults to C string "as-is" style 
02103          */
02104         smpp_msg_id_type = -1; 
02105     } else {
02106         if (smpp_msg_id_type < 0 || smpp_msg_id_type > 3)
02107             panic(0,"SMPP: Invalid value for msg-id-type directive in configuraton"); 
02108     }
02109 
02110     /* check for an alternative charset */
02111     alt_charset = cfg_get(grp, octstr_imm("alt-charset"));
02112     alt_addr_charset = cfg_get(grp, octstr_imm("alt-addr-charset"));
02113     
02114     /* check for connection timeout */
02115     if (cfg_get_integer(&connection_timeout, grp, octstr_imm("connection-timeout")) == -1)
02116         connection_timeout = SMPP_DEFAULT_CONNECTION_TIMEOUT;
02117 
02118     /* check if wait-ack timeout set */
02119     if (cfg_get_integer(&wait_ack, grp, octstr_imm("wait-ack")) == -1)
02120         wait_ack = SMPP_DEFAULT_WAITACK;
02121 
02122     if (cfg_get_integer(&wait_ack_action, grp, octstr_imm("wait-ack-expire")) == -1)
02123         wait_ack_action = SMPP_WAITACK_REQUEUE;
02124         
02125     if (wait_ack_action > 0x03 || wait_ack_action < 0)
02126         panic(0, "SMPP: Invalid wait-ack-expire directive in configuration.");
02127 
02128     smpp = smpp_create(conn, host, port, receive_port, system_type,  
02129                        username, password, address_range,
02130                        source_addr_ton, source_addr_npi, dest_addr_ton,  
02131                        dest_addr_npi, enquire_link_interval, 
02132                        max_pending_submits, version, priority, validity, my_number, 
02133                        smpp_msg_id_type, autodetect_addr, alt_charset, alt_addr_charset,
02134                        service_type, connection_timeout, wait_ack, wait_ack_action); 
02135  
02136     cfg_get_integer(&smpp->bind_addr_ton, grp, octstr_imm("bind-addr-ton"));
02137     cfg_get_integer(&smpp->bind_addr_npi, grp, octstr_imm("bind-addr-npi"));
02138 
02139     conn->data = smpp; 
02140     conn->name = octstr_format("SMPP:%S:%d/%d:%S:%S",  
02141                                host, port, 
02142                                (receive_port ? receive_port : port),  
02143                                username, system_type); 
02144  
02145     smsc_id = cfg_get(grp, octstr_imm("smsc-id")); 
02146     if (smsc_id == NULL) { 
02147         conn->id = octstr_duplicate(conn->name); 
02148     } 
02149 
02150     octstr_destroy(host); 
02151     octstr_destroy(username); 
02152     octstr_destroy(password); 
02153     octstr_destroy(system_type); 
02154     octstr_destroy(address_range); 
02155     octstr_destroy(my_number); 
02156     octstr_destroy(smsc_id);
02157     octstr_destroy(alt_charset); 
02158     octstr_destroy(alt_addr_charset);
02159     octstr_destroy(service_type);
02160 
02161     conn->status = SMSCCONN_CONNECTING; 
02162        
02163     /* 
02164      * I/O threads are only started if the corresponding ports 
02165      * have been configured with positive numbers. Use 0 to  
02166      * disable the creation of the corresponding thread. 
02167      */ 
02168     if (port != 0) 
02169         smpp->transmitter = gwthread_create(io_thread, io_arg_create(smpp,  
02170                                            (transceiver_mode ? 2 : 1))); 
02171     if (receive_port != 0) 
02172         smpp->receiver = gwthread_create(io_thread, io_arg_create(smpp, 0)); 
02173      
02174     if ((port != 0 && smpp->transmitter == -1) ||  
02175         (receive_port != 0 && smpp->receiver == -1)) { 
02176         error(0, "SMPP[%s]: Couldn't start I/O threads.",
02177               octstr_get_cstr(smpp->conn->id)); 
02178         smpp->quitting = 1; 
02179         if (smpp->transmitter != -1) { 
02180             gwthread_wakeup(smpp->transmitter); 
02181             gwthread_join(smpp->transmitter); 
02182         } 
02183         if (smpp->receiver != -1) { 
02184             gwthread_wakeup(smpp->receiver); 
02185             gwthread_join(smpp->receiver); 
02186         } 
02187         smpp_destroy(conn->data); 
02188         return -1; 
02189     } 
02190  
02191     conn->shutdown = shutdown_cb; 
02192     conn->queued = queued_cb; 
02193     conn->send_msg = send_msg_cb; 
02194  
02195     return 0; 
02196 }

Here is the call graph for this function:

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, SmscWrapper, smscwrapper_destroy(), smscconn::start_conn, smscconn::status, smscconn::stop_conn, smsc_wrapper::stopped, smscconn::why_killed, wrapper_receiver(), and wrapper_sender().

Referenced by smscconn_create().

00398 {
00399     /* 1. Call smsc_open()
00400      * 2. create sender/receiver threads
00401      * 3. fill up the conn
00402      *
00403      * XXX open() SHOULD be done in distinct thread, not here!
00404      */
00405 
00406     SmscWrapper *wrap;
00407 
00408     wrap = gw_malloc(sizeof(SmscWrapper));
00409     wrap->smsc = NULL;
00410     conn->data = wrap;
00411     conn->send_msg = wrapper_add_msg;
00412     
00413     
00414     wrap->outgoing_queue = gwlist_create();
00415     wrap->stopped = gwlist_create();
00416     wrap->reconnect_mutex = mutex_create();
00417     gwlist_add_producer(wrap->outgoing_queue);
00418     
00419     if ((wrap->smsc = smsc_open(cfg)) == NULL)
00420     goto error;
00421 
00422     conn->name = octstr_create(smsc_name(wrap->smsc));
00423     conn->status = SMSCCONN_ACTIVE;
00424     conn->connect_time = time(NULL);
00425 
00426     if (conn->is_stopped)
00427     gwlist_add_producer(wrap->stopped);
00428     
00429 
00430     /* XXX here we could fail things... specially if the second one
00431      *     fails.. so fix this ASAP
00432      *
00433      * moreover, open should be in sender/receiver, so that we can continue
00434      * while trying to open... maybe move this, or just wait for new
00435      * implementations of various SMSC protocols
00436      */
00437     
00438     if ((wrap->receiver_thread = gwthread_create(wrapper_receiver, conn))==-1)
00439     goto error;
00440 
00441     if ((wrap->sender_thread = gwthread_create(wrapper_sender, conn))==-1)
00442     goto error;
00443 
00444     conn->shutdown = wrapper_shutdown;
00445     conn->queued = wrapper_queued;
00446     conn->stop_conn = wrapper_stop;
00447     conn->start_conn = wrapper_start;
00448     
00449     return 0;
00450 
00451 error:
00452     error(0, "Failed to create Smsc wrapper");
00453     conn->data = NULL;
00454     smscwrapper_destroy(wrap);
00455     conn->why_killed = SMSCCONN_KILLED_CANNOT_CONNECT;
00456     conn->status = SMSCCONN_DEAD;
00457     return -1;
00458 }

Here is the call graph for this function:

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