Kannel: Open Source WAP and SMS gateway  svn-r5335
smsc_loopback.c File Reference
#include "gwlib/gwlib.h"
#include "smscconn.h"
#include "smscconn_p.h"
#include "bb_smscconn_cb.h"
#include "dlr.h"

Go to the source code of this file.

Macros

#define O_DESTROY(a)   { octstr_destroy(a); a = NULL; }
 

Functions

static int msg_cb (SMSCConn *conn, Msg *msg)
 
static int shutdown_cb (SMSCConn *conn, int finish_sending)
 
static void start_cb (SMSCConn *conn)
 
static long queued_cb (SMSCConn *conn)
 
int smsc_loopback_create (SMSCConn *conn, CfgGroup *cfg)
 

Macro Definition Documentation

◆ O_DESTROY

#define O_DESTROY (   a)    { octstr_destroy(a); a = NULL; }

Definition at line 73 of file smsc_loopback.c.

Referenced by msg_cb().

Function Documentation

◆ msg_cb()

static int msg_cb ( SMSCConn conn,
Msg msg 
)
static

Definition at line 76 of file smsc_loopback.c.

References bb_smscconn_receive(), bb_smscconn_sent(), dlr_add(), DLR_IS_ENABLED_DEVICE, smscconn::id, mo, msg, msg_duplicate(), MSG_PARAM_UNDEFINED, O_DESTROY, octstr_create, octstr_destroy(), octstr_duplicate, smscconn::reroute_to_smsc, uuid_clear(), uuid_generate(), uuid_is_null(), UUID_STR_LEN, and uuid_unparse().

Referenced by smsc_loopback_create().

77 {
78  Msg *sms;
79 
80  /* create duplicates first */
81  sms = msg_duplicate(msg);
82 
83  /* store temporary DLR data for SMSC ACK */
84  if (DLR_IS_ENABLED_DEVICE(msg->sms.dlr_mask) && !uuid_is_null(sms->sms.id)) {
85  Octstr *mid;
86  char id[UUID_STR_LEN + 1];
87 
88  uuid_unparse(sms->sms.id, id);
89  mid = octstr_create(id);
90 
91  dlr_add(conn->id, mid, sms, 0);
92 
93  octstr_destroy(mid);
94  }
95 
96  /*
97  * Inform abstraction layer of sent event,
98  * it will also take care of DLR SMSC events.
99  */
100  bb_smscconn_sent(conn, sms, NULL);
101 
102  /* now change msg type to reflect flow type */
103  sms = msg_duplicate(msg);
104  sms->sms.sms_type = mo;
105 
106  /* Since this is a new MO now, make sure that the
107  * values we have still from the MT are cleaned. */
108  uuid_clear(sms->sms.id);
109  uuid_generate(sms->sms.id);
110  O_DESTROY(sms->sms.boxc_id);
111  sms->sms.dlr_mask = MSG_PARAM_UNDEFINED;
112  O_DESTROY(sms->sms.dlr_url);
113 
114  /*
115  * If there is a reroute-smsc-id in the config group,
116  * then let's use that value, otherwise assign the
117  * smsc-id canonical name for the MO.
118  * This re-assignment of the smsc-id provides some
119  * MO routing capabilities, i.e. via smsbox-route group.
120  */
121  octstr_destroy(sms->sms.smsc_id);
122 
123  if (conn->reroute_to_smsc) {
124  sms->sms.smsc_id = octstr_duplicate(conn->reroute_to_smsc);
125  } else {
126  sms->sms.smsc_id = octstr_duplicate(conn->id);
127  }
128 
129  /* now pass back again as MO to the abstraction layer */
130  bb_smscconn_receive(conn, sms);
131 
132  return 0;
133 }
Msg * msg_duplicate(Msg *msg)
Definition: msg.c:111
Definition: msg.h:106
Octstr * id
Definition: smscconn_p.h:174
void uuid_unparse(const uuid_t uu, char *out)
Definition: gw_uuid.c:562
void uuid_generate(uuid_t out)
Definition: gw_uuid.c:393
void dlr_add(const Octstr *smsc, const Octstr *ts, Msg *msg, int use_dst)
Definition: dlr.c:330
#define O_DESTROY(a)
Definition: smsc_loopback.c:73
Definition: msg.h:79
Octstr * reroute_to_smsc
Definition: smscconn_p.h:209
long bb_smscconn_receive(SMSCConn *conn, Msg *sms)
Definition: bb_smscconn.c:477
int uuid_is_null(const uuid_t uu)
Definition: gw_uuid.c:413
#define octstr_duplicate(ostr)
Definition: octstr.h:187
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
#define octstr_create(cstr)
Definition: octstr.h:125
#define UUID_STR_LEN
Definition: gw_uuid.h:19
Definition: octstr.c:118
void bb_smscconn_sent(SMSCConn *conn, Msg *sms, Octstr *reply)
Definition: bb_smscconn.c:281
#define MSG_PARAM_UNDEFINED
Definition: msg.h:71
#define DLR_IS_ENABLED_DEVICE(dlr)
Definition: dlr.h:82
static XMLRPCDocument * msg
Definition: test_xmlrpc.c:86
void uuid_clear(uuid_t uu)
Definition: gw_uuid.c:105

◆ queued_cb()

static long queued_cb ( SMSCConn conn)
static

Definition at line 156 of file smsc_loopback.c.

References smscconn::load.

Referenced by smsc_loopback_create().

157 {
158  long ret = 0;
159 
160  conn->load = ret;
161  return ret;
162 }
int load
Definition: smscconn_p.h:152

◆ shutdown_cb()

static int shutdown_cb ( SMSCConn conn,
int  finish_sending 
)
static

Definition at line 136 of file smsc_loopback.c.

References bb_smscconn_killed(), debug(), smscconn::name, octstr_get_cstr, SMSCCONN_DEAD, SMSCCONN_KILLED_SHUTDOWN, smscconn::status, and smscconn::why_killed.

Referenced by smsc_loopback_create().

137 {
138  debug("smsc.loopback", 0, "Shutting down SMSCConn %s",
139  octstr_get_cstr(conn->name));
140 
142  conn->status = SMSCCONN_DEAD;
144 
145  return 0;
146 }
Octstr * name
Definition: smscconn_p.h:173
void bb_smscconn_killed(void)
Definition: bb_smscconn.c:199
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
smscconn_killed_t why_killed
Definition: smscconn_p.h:153
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:726
smscconn_status_t status
Definition: smscconn_p.h:151

◆ smsc_loopback_create()

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:250
static void start_cb(SMSCConn *conn)
void(* start_conn)(SMSCConn *conn)
Definition: smscconn_p.h:246
time_t connect_time
Definition: smscconn_p.h:155
Octstr * octstr_format(const char *fmt,...)
Definition: octstr.c:2464
int(* shutdown)(SMSCConn *conn, int finish_sending)
Definition: smscconn_p.h:230
smscconn_status_t status
Definition: smscconn_p.h:151
long(* queued)(SMSCConn *conn)
Definition: smscconn_p.h:241
int(* send_msg)(SMSCConn *conn, Msg *msg)
Definition: smscconn_p.h:236
static long queued_cb(SMSCConn *conn)

◆ start_cb()

static void start_cb ( SMSCConn conn)
static

Definition at line 149 of file smsc_loopback.c.

References smscconn::connect_time, SMSCCONN_ACTIVE, and smscconn::status.

Referenced by smsc_loopback_create().

150 {
151  conn->status = SMSCCONN_ACTIVE;
152  conn->connect_time = time(NULL);
153 }
time_t connect_time
Definition: smscconn_p.h:155
smscconn_status_t status
Definition: smscconn_p.h:151
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.