Kannel: Open Source WAP and SMS gateway  svn-r5335
xidris.c File Reference
#include "gwlib/gwlib.h"
#include "smscconn.h"
#include "smscconn_p.h"
#include "bb_smscconn_cb.h"
#include "msg.h"
#include "sms.h"
#include "dlr.h"
#include "urltrans.h"
#include "meta_data.h"
#include "../smsc_http_p.h"

Go to the source code of this file.

Functions

static Octstrparse_xml_tag (Octstr *body, Octstr *tag)
 
static int xidris_send_sms (SMSCConn *conn, Msg *sms)
 
static void xidris_parse_reply (SMSCConn *conn, Msg *msg, int status, List *headers, Octstr *body)
 
static void xidris_receive_sms (SMSCConn *conn, HTTPClient *client, List *headers, Octstr *body, List *cgivars)
 
static int xidris_init (SMSCConn *conn, CfgGroup *cfg)
 

Variables

struct smsc_http_fn_callbacks smsc_http_xidris_callback
 

Function Documentation

◆ parse_xml_tag()

static Octstr* parse_xml_tag ( Octstr body,
Octstr tag 
)
static

Definition at line 80 of file xidris.c.

References octstr_copy, octstr_destroy(), octstr_format(), octstr_get_cstr, octstr_len(), octstr_search(), octstr_strip_blanks(), and octstr_strip_crlfs().

Referenced by xidris_parse_reply().

81 {
82  Octstr *stag, *etag, *ret;
83  int spos, epos;
84 
85  stag = octstr_format("<%s>", octstr_get_cstr(tag));
86  if ((spos = octstr_search(body, stag, 0)) == -1) {
87  octstr_destroy(stag);
88  return NULL;
89  }
90  etag = octstr_format("</%s>", octstr_get_cstr(tag));
91  if ((epos = octstr_search(body, etag, spos+octstr_len(stag))) == -1) {
92  octstr_destroy(stag);
93  octstr_destroy(etag);
94  return NULL;
95  }
96 
97  ret = octstr_copy(body, spos+octstr_len(stag), epos+1 - (spos+octstr_len(etag)));
99  octstr_strip_crlfs(ret);
100 
101  octstr_destroy(stag);
102  octstr_destroy(etag);
103 
104  return ret;
105 }
long octstr_search(const Octstr *haystack, const Octstr *needle, long pos)
Definition: octstr.c:1070
void octstr_strip_blanks(Octstr *text)
Definition: octstr.c:1346
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
#define octstr_copy(ostr, from, len)
Definition: octstr.h:178
Octstr * octstr_format(const char *fmt,...)
Definition: octstr.c:2464
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
void octstr_strip_crlfs(Octstr *text)
Definition: octstr.c:1378
long octstr_len(const Octstr *ostr)
Definition: octstr.c:342
Definition: octstr.c:118

◆ xidris_init()

static int xidris_init ( SMSCConn conn,
CfgGroup cfg 
)
static

Definition at line 327 of file xidris.c.

References smscconn::data, error(), smscconn::id, octstr_get_cstr, conndata::password, and conndata::username.

328 {
329  ConnData *conndata = conn->data;
330 
331  if (conndata->username == NULL || conndata->password == NULL) {
332  error(0, "HTTP[%s]: 'username' and 'password' required for Xidris http smsc",
333  octstr_get_cstr(conn->id));
334  return -1;
335  }
336 
337  return 0;
338 }
void error(int err, const char *fmt,...)
Definition: log.c:648
Octstr * id
Definition: smscconn_p.h:174
void * data
Definition: smscconn_p.h:250
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
Octstr * password
Definition: smsc_http_p.h:98
Octstr * username
Definition: smsc_http_p.h:97

◆ xidris_parse_reply()

static void xidris_parse_reply ( SMSCConn conn,
Msg msg,
int  status,
List headers,
Octstr body 
)
static

Definition at line 171 of file xidris.c.

References bb_smscconn_send_failed(), bb_smscconn_sent(), code, dlr_add(), DLR_IS_ENABLED_DEVICE, error(), HTTP_ACCEPTED, HTTP_OK, smscconn::id, msg, octstr_case_compare(), octstr_create, octstr_destroy(), octstr_dump, octstr_duplicate, octstr_get_cstr, octstr_imm(), parse_xml_tag(), SMSCCONN_FAILED_MALFORMED, and SMSCCONN_FAILED_REJECTED.

173 {
174  Octstr *code, *desc, *mid;
175 
176  if (status == HTTP_OK || status == HTTP_ACCEPTED) {
177  /* now parse the XML document for error code */
178  code = parse_xml_tag(body, octstr_imm("status"));
179  desc = parse_xml_tag(body, octstr_imm("description"));
180 
181  /* The following parsing assumes we get only *one* message id in the
182  * response XML. Which is ok, since we garantee via previous concat
183  * splitting, that we only pass PDUs of 1 SMS size to SMSC. */
184  mid = parse_xml_tag(body, octstr_imm("message_id"));
185 
186  if (octstr_case_compare(code, octstr_imm("0")) == 0 && mid != NULL) {
187  /* ensure the message id gets logged */
188  msg->sms.binfo = octstr_duplicate(mid);
189 
190  /* SMSC ACK.. now we have the message id. */
191  if (DLR_IS_ENABLED_DEVICE(msg->sms.dlr_mask))
192  dlr_add(conn->id, mid, msg, 0);
193 
194  octstr_destroy(mid);
195  bb_smscconn_sent(conn, msg, NULL);
196 
197  } else {
198  error(0, "HTTP[%s]: Message not accepted. Status code <%s> "
199  "description `%s'.", octstr_get_cstr(conn->id),
203  }
204  } else {
205  error(0, "HTTP[%s]: Message was rejected. SMSC response was:",
206  octstr_get_cstr(conn->id));
207  octstr_dump(body, 0);
210  }
211 }
void error(int err, const char *fmt,...)
Definition: log.c:648
Octstr * id
Definition: smscconn_p.h:174
int code
Definition: smsc_cimd2.c:346
void dlr_add(const Octstr *smsc, const Octstr *ts, Msg *msg, int use_dst)
Definition: dlr.c:330
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:283
Definition: http.h:142
#define octstr_duplicate(ostr)
Definition: octstr.h:187
#define octstr_dump(ostr, level,...)
Definition: octstr.h:564
int octstr_case_compare(const Octstr *os1, const Octstr *os2)
Definition: octstr.c:903
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
#define octstr_create(cstr)
Definition: octstr.h:125
Definition: octstr.c:118
void bb_smscconn_sent(SMSCConn *conn, Msg *sms, Octstr *reply)
Definition: bb_smscconn.c:281
static Octstr * parse_xml_tag(Octstr *body, Octstr *tag)
Definition: xidris.c:80
void bb_smscconn_send_failed(SMSCConn *conn, Msg *sms, int reason, Octstr *reply)
Definition: bb_smscconn.c:329
#define DLR_IS_ENABLED_DEVICE(dlr)
Definition: dlr.h:82
static XMLRPCDocument * msg
Definition: test_xmlrpc.c:86

◆ xidris_receive_sms()

static void xidris_receive_sms ( SMSCConn conn,
HTTPClient client,
List headers,
Octstr body,
List cgivars 
)
static

Definition at line 214 of file xidris.c.

References account, bb_smscconn_receive(), client(), coding, smscconn::data, debug(), DLR_BUFFERED, DLR_FAIL, dlr_find(), DLR_SUCCESS, error(), from, gwlist_create, HTTP_BAD_REQUEST, http_cgi_variable(), http_destroy_headers(), HTTP_FORBIDDEN, HTTP_OK, http_send_reply(), HTTP_UNAUTHORIZED, smscconn::id, msg, msg_create, octstr_compare(), octstr_create, octstr_destroy(), octstr_duplicate, octstr_get_cstr, octstr_imm(), conndata::password, report_mo, text, and conndata::username.

216 {
217  ConnData *conndata = conn->data;
218  Octstr *user, *pass, *from, *to, *text, *account, *binfo;
219  Octstr *state, *mid, *dest;
220  Octstr *retmsg;
222  List *reply_headers;
223  int ret, status;
224 
225  mclass = mwi = coding = validity = deferred = 0;
226  retmsg = NULL;
227 
228  /* generic values */
229  user = http_cgi_variable(cgivars, "app_id");
230  pass = http_cgi_variable(cgivars, "key");
231 
232  /* MO specific values */
233  from = http_cgi_variable(cgivars, "source_addr");
234  to = http_cgi_variable(cgivars, "dest_addr");
235  text = http_cgi_variable(cgivars, "message");
236  account = http_cgi_variable(cgivars, "operator");
237  binfo = http_cgi_variable(cgivars, "tariff");
238 
239  /* DLR (callback) specific values */
240  state = http_cgi_variable(cgivars, "state");
241  mid = http_cgi_variable(cgivars, "message_id");
242  dest = http_cgi_variable(cgivars, "dest_addr");
243 
244  debug("smsc.http.xidris", 0, "HTTP[%s]: Received a request",
245  octstr_get_cstr(conn->id));
246 
247  if (user == NULL || pass == NULL ||
248  octstr_compare(user, conndata->username) != 0 ||
249  octstr_compare(pass, conndata->password) != 0) {
250  error(0, "HTTP[%s]: Authorization failure. username was <%s>.",
251  octstr_get_cstr(conn->id), octstr_get_cstr(user));
252  retmsg = octstr_create("Authorization failed for MO submission.");
254  }
255  else if (state != NULL && mid != NULL && dest != NULL) { /* a DLR message */
256  Msg *dlrmsg;
257  int dlrstat = -1;
258 
259  if (octstr_compare(state, octstr_imm("DELIVRD")) == 0)
260  dlrstat = DLR_SUCCESS;
261  else if (octstr_compare(state, octstr_imm("ACCEPTD")) == 0)
262  dlrstat = DLR_BUFFERED;
263  else
264  dlrstat = DLR_FAIL;
265 
266  dlrmsg = dlr_find(conn->id,
267  mid, /* smsc message id */
268  dest, /* destination */
269  dlrstat, 0);
270 
271  if (dlrmsg != NULL) {
272  dlrmsg->sms.msgdata = octstr_duplicate(mid);
273  dlrmsg->sms.sms_type = report_mo;
274 
275  ret = bb_smscconn_receive(conn, dlrmsg);
276  status = (ret == 0 ? HTTP_OK : HTTP_FORBIDDEN);
277  } else {
278  error(0,"HTTP[%s]: got DLR but could not find message or was not interested "
279  "in it id<%s> dst<%s>, type<%d>",
280  octstr_get_cstr(conn->id), octstr_get_cstr(mid),
281  octstr_get_cstr(dest), dlrstat);
282  status = HTTP_OK;
283  }
284 
285  }
286  else if (from == NULL || to == NULL || text == NULL) {
287  error(0, "HTTP[%s]: Insufficient args.",
288  octstr_get_cstr(conn->id));
289  retmsg = octstr_create("Insufficient arguments, rejected.");
291  }
292  else {
293  Msg *msg;
294  msg = msg_create(sms);
295 
296  debug("smsc.http.xidris", 0, "HTTP[%s]: Received new MO SMS.",
297  octstr_get_cstr(conn->id));
298 
299  msg->sms.sender = octstr_duplicate(from);
300  msg->sms.receiver = octstr_duplicate(to);
301  msg->sms.msgdata = octstr_duplicate(text);
302  msg->sms.account = octstr_duplicate(account);
303  msg->sms.binfo = octstr_duplicate(binfo);
304 
305  msg->sms.smsc_id = octstr_duplicate(conn->id);
306  msg->sms.time = time(NULL);
307  msg->sms.mclass = mclass;
308  msg->sms.mwi = mwi;
309  msg->sms.coding = coding;
310  msg->sms.validity = time(NULL) + validity * 60;
311  msg->sms.deferred = time(NULL) + deferred * 60;
312 
313  ret = bb_smscconn_receive(conn, msg);
314  status = (ret == 0 ? HTTP_OK : HTTP_FORBIDDEN);
315  }
316 
317  reply_headers = gwlist_create();
318  debug("smsc.http.xidris", 0, "HTTP[%s]: Sending reply with HTTP status <%d>.",
319  octstr_get_cstr(conn->id), status);
320 
321  http_send_reply(client, status, reply_headers, retmsg);
322 
323  octstr_destroy(retmsg);
324  http_destroy_headers(reply_headers);
325 }
Octstr * to
Definition: generic.c:110
void error(int err, const char *fmt,...)
Definition: log.c:648
static int coding
Definition: mtbatch.c:102
Octstr * validity
Definition: generic.c:125
Definition: msg.h:109
Octstr * id
Definition: smscconn_p.h:174
void * data
Definition: smscconn_p.h:250
static void client(int port)
Definition: test_udp.c:77
Octstr * deferred
Definition: generic.c:126
#define msg_create(type)
Definition: msg.h:136
Msg * dlr_find(const Octstr *smsc, const Octstr *ts, const Octstr *dst, int typ, int use_dst)
Definition: dlr.c:387
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
Octstr * http_cgi_variable(List *list, char *name)
Definition: http.c:2836
void http_destroy_headers(List *headers)
Definition: http.c:2879
#define DLR_SUCCESS
Definition: dlr.h:72
static Octstr * from
Definition: mtbatch.c:95
Octstr * binfo
Definition: generic.c:115
void http_send_reply(HTTPClient *client, int status, List *headers, Octstr *body)
Definition: http.c:2695
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:283
Definition: http.h:142
Definition: msg.h:79
long bb_smscconn_receive(SMSCConn *conn, Msg *sms)
Definition: bb_smscconn.c:477
char * text
Definition: smsc_cimd2.c:921
#define octstr_duplicate(ostr)
Definition: octstr.h:187
Octstr * mclass
Definition: generic.c:122
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
#define octstr_create(cstr)
Definition: octstr.h:125
Octstr * mwi
Definition: generic.c:123
Definition: octstr.c:118
Octstr * password
Definition: smsc_http_p.h:98
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:726
#define gwlist_create()
Definition: list.h:136
Octstr * username
Definition: smsc_http_p.h:97
#define DLR_BUFFERED
Definition: dlr.h:74
Definition: list.c:102
static Octstr * account
Definition: mtbatch.c:94
static XMLRPCDocument * msg
Definition: test_xmlrpc.c:86
#define DLR_FAIL
Definition: dlr.h:73
int octstr_compare(const Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:871

◆ xidris_send_sms()

static int xidris_send_sms ( SMSCConn conn,
Msg sms 
)
static

Definition at line 108 of file xidris.c.

References smscconn::data, debug(), fields_to_dcs(), gwlist_create, http_destroy_headers(), HTTP_METHOD_GET, conndata::http_ref, http_start_request(), smscconn::id, octstr_append(), octstr_destroy(), octstr_duplicate, octstr_format(), octstr_format_append(), octstr_get_cstr, octstr_imm(), octstr_len(), octstr_url_decode(), conndata::password, conndata::send_url, url, and conndata::username.

109 {
110  ConnData *conndata = conn->data;
111  Octstr *url, *new_msg;
112  List *headers;
113  int dcs, esm_class;
114 
115  url = new_msg = NULL;
116  dcs = esm_class = 0;
117 
118  /* format the URL for call */
119  url = octstr_format("%S?"
120  "app_id=%E&key=%E&dest_addr=%E&source_addr=%E",
122  conndata->password, sms->sms.receiver, sms->sms.sender);
123 
124  if (octstr_len(sms->sms.udhdata)) {
125  /* RAW additions for binary (8bit) msgs */
126 
127  /* set the data coding scheme (DCS) and ESM class fields */
128  dcs = fields_to_dcs(sms, sms->sms.alt_dcs);
129  /* ESM_CLASS_SUBMIT_STORE_AND_FORWARD_MODE |
130  ESM_CLASS_SUBMIT_UDH_INDICATOR */
131  esm_class = 0x03 | 0x40;
132 
133  /* prepend UDH header to message block */
134  new_msg = octstr_duplicate(sms->sms.udhdata);
135  octstr_append(new_msg, sms->sms.msgdata);
136 
137  octstr_format_append(url, "&type=200&dcs=%d&esm=%d&message=%H",
138  dcs, esm_class, new_msg);
139  } else {
140  /* additions for text (7bit) msgs */
141 
142  octstr_format_append(url, "&type=%E&message=%E",
143  (sms->sms.mclass ? octstr_imm("1") : octstr_imm("0")),
144  sms->sms.msgdata);
145  }
146 
147  /*
148  * We use &account=<foobar> from sendsms interface to encode any additionaly
149  * proxied parameters, ie. billing information.
150  */
151  if (octstr_len(sms->sms.account)) {
152  octstr_url_decode(sms->sms.account);
153  octstr_format_append(url, "&%s", octstr_get_cstr(sms->sms.account));
154  }
155 
156  headers = gwlist_create();
157  debug("smsc.http.xidris", 0, "HTTP[%s]: Sending request <%s>",
159 
161  NULL, 0, sms, NULL);
162 
164  octstr_destroy(new_msg);
165  http_destroy_headers(headers);
166 
167  return 0;
168 }
void octstr_append(Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:1504
Octstr * id
Definition: smscconn_p.h:174
void * data
Definition: smscconn_p.h:250
HTTPCaller * http_ref
Definition: smsc_http_p.h:86
int octstr_url_decode(Octstr *ostr)
Definition: octstr.c:1746
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
void http_destroy_headers(List *headers)
Definition: http.c:2879
void http_start_request(HTTPCaller *caller, int method, Octstr *url, List *headers, Octstr *body, int follow, void *id, Octstr *certkeyfile)
Definition: http.c:1760
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:283
#define octstr_duplicate(ostr)
Definition: octstr.h:187
Octstr * octstr_format(const char *fmt,...)
Definition: octstr.c:2464
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
int fields_to_dcs(Msg *msg, int mode)
Definition: sms.c:73
long octstr_len(const Octstr *ostr)
Definition: octstr.c:342
Definition: octstr.c:118
Octstr * password
Definition: smsc_http_p.h:98
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:726
void octstr_format_append(Octstr *os, const char *fmt,...)
Definition: octstr.c:2507
#define gwlist_create()
Definition: list.h:136
Octstr * username
Definition: smsc_http_p.h:97
Octstr * send_url
Definition: smsc_http_p.h:93
static Octstr * url
Definition: test_xmlrpc.c:84
Definition: list.c:102

Variable Documentation

◆ smsc_http_xidris_callback

struct smsc_http_fn_callbacks smsc_http_xidris_callback
Initial value:
= {
.init = xidris_init,
.send_sms = xidris_send_sms,
.parse_reply = xidris_parse_reply,
.receive_sms = xidris_receive_sms,
}
static void xidris_receive_sms(SMSCConn *conn, HTTPClient *client, List *headers, Octstr *body, List *cgivars)
Definition: xidris.c:214
static int xidris_send_sms(SMSCConn *conn, Msg *sms)
Definition: xidris.c:108
static void xidris_parse_reply(SMSCConn *conn, Msg *msg, int status, List *headers, Octstr *body)
Definition: xidris.c:171
static int xidris_init(SMSCConn *conn, CfgGroup *cfg)
Definition: xidris.c:327

Definition at line 340 of file xidris.c.

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