Kannel: Open Source WAP and SMS gateway  $Revision: 5037 $
xidris.c File Reference
#include "gwlib/gwlib.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

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

Definition at line 70 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().

71 {
72  Octstr *stag, *etag, *ret;
73  int spos, epos;
74 
75  stag = octstr_format("<%s>", octstr_get_cstr(tag));
76  if ((spos = octstr_search(body, stag, 0)) == -1) {
77  octstr_destroy(stag);
78  return NULL;
79  }
80  etag = octstr_format("</%s>", octstr_get_cstr(tag));
81  if ((epos = octstr_search(body, etag, spos+octstr_len(stag))) == -1) {
82  octstr_destroy(stag);
83  octstr_destroy(etag);
84  return NULL;
85  }
86 
87  ret = octstr_copy(body, spos+octstr_len(stag), epos+1 - (spos+octstr_len(etag)));
89  octstr_strip_crlfs(ret);
90 
91  octstr_destroy(stag);
92  octstr_destroy(etag);
93 
94  return ret;
95 }
long octstr_search(const Octstr *haystack, const Octstr *needle, long pos)
Definition: octstr.c:1068
void octstr_strip_blanks(Octstr *text)
Definition: octstr.c:1344
#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:2462
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:322
void octstr_strip_crlfs(Octstr *text)
Definition: octstr.c:1376
long octstr_len(const Octstr *ostr)
Definition: octstr.c:340
Definition: octstr.c:118
static int xidris_init ( SMSCConn conn,
CfgGroup cfg 
)
static

Definition at line 317 of file xidris.c.

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

318 {
319  ConnData *conndata = conn->data;
320 
321  if (conndata->username == NULL || conndata->password == NULL) {
322  error(0, "HTTP[%s]: 'username' and 'password' required for Xidris http smsc",
323  octstr_get_cstr(conn->id));
324  return -1;
325  }
326 
327  return 0;
328 }
void error(int err, const char *fmt,...)
Definition: log.c:612
Octstr * id
Definition: smscconn_p.h:174
void * data
Definition: smscconn_p.h:249
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
Octstr * password
Definition: smsc_http.c:155
Octstr * username
Definition: smsc_http.c:154
static void xidris_parse_reply ( SMSCConn conn,
Msg msg,
int  status,
List headers,
Octstr body 
)
static

Definition at line 161 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, 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.

163 {
164  Octstr *code, *desc, *mid;
165 
166  if (status == HTTP_OK || status == HTTP_ACCEPTED) {
167  /* now parse the XML document for error code */
168  code = parse_xml_tag(body, octstr_imm("status"));
169  desc = parse_xml_tag(body, octstr_imm("description"));
170 
171  /* The following parsing assumes we get only *one* message id in the
172  * response XML. Which is ok, since we garantee via previous concat
173  * splitting, that we only pass PDUs of 1 SMS size to SMSC. */
174  mid = parse_xml_tag(body, octstr_imm("message_id"));
175 
176  if (octstr_case_compare(code, octstr_imm("0")) == 0 && mid != NULL) {
177  /* ensure the message id gets logged */
178  msg->sms.binfo = octstr_duplicate(mid);
179 
180  /* SMSC ACK.. now we have the message id. */
181  if (DLR_IS_ENABLED_DEVICE(msg->sms.dlr_mask))
182  dlr_add(conn->id, mid, msg, 0);
183 
184  octstr_destroy(mid);
185  bb_smscconn_sent(conn, msg, NULL);
186 
187  } else {
188  error(0, "HTTP[%s]: Message not accepted. Status code <%s> "
189  "description `%s'.", octstr_get_cstr(conn->id),
190  octstr_get_cstr(code), octstr_get_cstr(desc));
191  bb_smscconn_send_failed(conn, msg,
193  }
194  } else {
195  error(0, "HTTP[%s]: Message was rejected. SMSC response was:",
196  octstr_get_cstr(conn->id));
197  octstr_dump(body, 0);
198  bb_smscconn_send_failed(conn, msg,
200  }
201 }
void error(int err, const char *fmt,...)
Definition: log.c:612
Octstr * id
Definition: smscconn_p.h:174
int code
Definition: smsc_cimd2.c:346
#define DLR_IS_ENABLED_DEVICE(dlr)
Definition: dlr.h:82
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:281
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:901
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:322
#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:279
static Octstr * parse_xml_tag(Octstr *body, Octstr *tag)
Definition: xidris.c:70
void bb_smscconn_send_failed(SMSCConn *conn, Msg *sms, int reason, Octstr *reply)
Definition: bb_smscconn.c:328
static void xidris_receive_sms ( SMSCConn conn,
HTTPClient client,
List headers,
Octstr body,
List cgivars 
)
static

Definition at line 204 of file xidris.c.

References account, bb_smscconn_receive(), 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.

206 {
207  ConnData *conndata = conn->data;
208  Octstr *user, *pass, *from, *to, *text, *account, *binfo;
209  Octstr *state, *mid, *dest;
210  Octstr *retmsg;
212  List *reply_headers;
213  int ret, status;
214 
215  mclass = mwi = coding = validity = deferred = 0;
216  retmsg = NULL;
217 
218  /* generic values */
219  user = http_cgi_variable(cgivars, "app_id");
220  pass = http_cgi_variable(cgivars, "key");
221 
222  /* MO specific values */
223  from = http_cgi_variable(cgivars, "source_addr");
224  to = http_cgi_variable(cgivars, "dest_addr");
225  text = http_cgi_variable(cgivars, "message");
226  account = http_cgi_variable(cgivars, "operator");
227  binfo = http_cgi_variable(cgivars, "tariff");
228 
229  /* DLR (callback) specific values */
230  state = http_cgi_variable(cgivars, "state");
231  mid = http_cgi_variable(cgivars, "message_id");
232  dest = http_cgi_variable(cgivars, "dest_addr");
233 
234  debug("smsc.http.xidris", 0, "HTTP[%s]: Received a request",
235  octstr_get_cstr(conn->id));
236 
237  if (user == NULL || pass == NULL ||
238  octstr_compare(user, conndata->username) != 0 ||
239  octstr_compare(pass, conndata->password) != 0) {
240  error(0, "HTTP[%s]: Authorization failure. username was <%s>.",
241  octstr_get_cstr(conn->id), octstr_get_cstr(user));
242  retmsg = octstr_create("Authorization failed for MO submission.");
243  status = HTTP_UNAUTHORIZED;
244  }
245  else if (state != NULL && mid != NULL && dest != NULL) { /* a DLR message */
246  Msg *dlrmsg;
247  int dlrstat = -1;
248 
249  if (octstr_compare(state, octstr_imm("DELIVRD")) == 0)
250  dlrstat = DLR_SUCCESS;
251  else if (octstr_compare(state, octstr_imm("ACCEPTD")) == 0)
252  dlrstat = DLR_BUFFERED;
253  else
254  dlrstat = DLR_FAIL;
255 
256  dlrmsg = dlr_find(conn->id,
257  mid, /* smsc message id */
258  dest, /* destination */
259  dlrstat, 0);
260 
261  if (dlrmsg != NULL) {
262  dlrmsg->sms.msgdata = octstr_duplicate(mid);
263  dlrmsg->sms.sms_type = report_mo;
264 
265  ret = bb_smscconn_receive(conn, dlrmsg);
266  status = (ret == 0 ? HTTP_OK : HTTP_FORBIDDEN);
267  } else {
268  error(0,"HTTP[%s]: got DLR but could not find message or was not interested "
269  "in it id<%s> dst<%s>, type<%d>",
270  octstr_get_cstr(conn->id), octstr_get_cstr(mid),
271  octstr_get_cstr(dest), dlrstat);
272  status = HTTP_OK;
273  }
274 
275  }
276  else if (from == NULL || to == NULL || text == NULL) {
277  error(0, "HTTP[%s]: Insufficient args.",
278  octstr_get_cstr(conn->id));
279  retmsg = octstr_create("Insufficient arguments, rejected.");
280  status = HTTP_BAD_REQUEST;
281  }
282  else {
283  Msg *msg;
284  msg = msg_create(sms);
285 
286  debug("smsc.http.xidris", 0, "HTTP[%s]: Received new MO SMS.",
287  octstr_get_cstr(conn->id));
288 
289  msg->sms.sender = octstr_duplicate(from);
290  msg->sms.receiver = octstr_duplicate(to);
291  msg->sms.msgdata = octstr_duplicate(text);
292  msg->sms.account = octstr_duplicate(account);
293  msg->sms.binfo = octstr_duplicate(binfo);
294 
295  msg->sms.smsc_id = octstr_duplicate(conn->id);
296  msg->sms.time = time(NULL);
297  msg->sms.mclass = mclass;
298  msg->sms.mwi = mwi;
299  msg->sms.coding = coding;
300  msg->sms.validity = time(NULL) + validity * 60;
301  msg->sms.deferred = time(NULL) + deferred * 60;
302 
303  ret = bb_smscconn_receive(conn, msg);
304  status = (ret == 0 ? HTTP_OK : HTTP_FORBIDDEN);
305  }
306 
307  reply_headers = gwlist_create();
308  debug("smsc.http.xidris", 0, "HTTP[%s]: Sending reply with HTTP status <%d>.",
309  octstr_get_cstr(conn->id), status);
310 
311  http_send_reply(client, status, reply_headers, retmsg);
312 
313  octstr_destroy(retmsg);
314  http_destroy_headers(reply_headers);
315 }
Octstr * to
Definition: generic.c:100
void error(int err, const char *fmt,...)
Definition: log.c:612
Octstr * validity
Definition: generic.c:115
Definition: msg.h:109
Octstr * id
Definition: smscconn_p.h:174
void * data
Definition: smscconn_p.h:249
Octstr * deferred
Definition: generic.c:116
#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:2813
void http_destroy_headers(List *headers)
Definition: http.c:2856
#define DLR_SUCCESS
Definition: dlr.h:72
static Octstr * from
Definition: mtbatch.c:95
Octstr * binfo
Definition: generic.c:105
void http_send_reply(HTTPClient *client, int status, List *headers, Octstr *body)
Definition: http.c:2671
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:281
Definition: http.h:142
Definition: msg.h:79
long bb_smscconn_receive(SMSCConn *conn, Msg *sms)
Definition: bb_smscconn.c:478
char * text
Definition: smsc_cimd2.c:921
#define octstr_duplicate(ostr)
Definition: octstr.h:187
Octstr * mclass
Definition: generic.c:112
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:322
#define octstr_create(cstr)
Definition: octstr.h:125
Octstr * coding
Definition: generic.c:114
Octstr * mwi
Definition: generic.c:113
Definition: octstr.c:118
Octstr * password
Definition: smsc_http.c:155
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:690
#define gwlist_create()
Definition: list.h:136
Octstr * username
Definition: smsc_http.c:154
#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:869
static int xidris_send_sms ( SMSCConn conn,
Msg sms 
)
static

Definition at line 98 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.

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

Variable Documentation

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:204
static int xidris_send_sms(SMSCConn *conn, Msg *sms)
Definition: xidris.c:98
static void xidris_parse_reply(SMSCConn *conn, Msg *msg, int status, List *headers, Octstr *body)
Definition: xidris.c:161
static int xidris_init(SMSCConn *conn, CfgGroup *cfg)
Definition: xidris.c:317

Definition at line 330 of file xidris.c.

Referenced by smsc_http_create().

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