Kannel: Open Source WAP and SMS gateway  $Revision: 5037 $
emimsg.h File Reference
#include "gwlib/gwlib.h"

Go to the source code of this file.

Data Structures

struct  emimsg
 

Enumerations

enum  {
  E01_ADC, E01_OADC, E01_AC, E01_MT,
  E01_AMSG, SZ01
}
 
enum  {
  E50_ADC, E50_OADC, E50_AC, E50_NRQ,
  E50_NADC, E50_NT, E50_NPID, E50_LRQ,
  E50_LRAD, E50_LPID, E50_DD, E50_DDT,
  E50_VP, E50_RPID, E50_SCTS, E50_DST,
  E50_RSN, E50_DSCTS, E50_MT, E50_NB,
  E50_NMSG =20, E50_AMSG =20, E50_TMSG =20, E50_MMS,
  E50_PR, E50_DCS, E50_MCLS, E50_RPI,
  E50_CPG, E50_RPLY, E50_OTOA, E50_HPLMN,
  E50_XSER, E50_RES4, E50_RES5, SZ50
}
 
enum  {
  E60_OADC, E60_OTON, E60_ONPI, E60_STYP,
  E60_PWD, E60_NPWD, E60_VERS, E60_LADC,
  E60_LTON, E60_LNPI, E60_OPID, E60_RES1,
  SZ60
}
 

Functions

struct emimsgemimsg_create_op (int ot, int trn, Octstr *whoami)
 
struct emimsgemimsg_create_reply (int ot, int trn, int positive, Octstr *whoami)
 
void emimsg_destroy (struct emimsg *emimsg)
 
struct emimsgemimsg_duplicate (struct emimsg *emimsg)
 
struct emimsgget_fields (Octstr *message, Octstr *whoami)
 
int emimsg_send (Connection *conn, struct emimsg *emimsg, Octstr *whoami)
 

Enumeration Type Documentation

anonymous enum
Enumerator
E01_ADC 
E01_OADC 
E01_AC 
E01_MT 
E01_AMSG 
SZ01 

Definition at line 80 of file emimsg.h.

80  {
82 };
Definition: emimsg.h:81
Definition: emimsg.h:81
Definition: emimsg.h:81
Definition: emimsg.h:81
anonymous enum
Enumerator
E50_ADC 
E50_OADC 
E50_AC 
E50_NRQ 
E50_NADC 
E50_NT 
E50_NPID 
E50_LRQ 
E50_LRAD 
E50_LPID 
E50_DD 
E50_DDT 
E50_VP 
E50_RPID 
E50_SCTS 
E50_DST 
E50_RSN 
E50_DSCTS 
E50_MT 
E50_NB 
E50_NMSG 
E50_AMSG 
E50_TMSG 
E50_MMS 
E50_PR 
E50_DCS 
E50_MCLS 
E50_RPI 
E50_CPG 
E50_RPLY 
E50_OTOA 
E50_HPLMN 
E50_XSER 
E50_RES4 
E50_RES5 
SZ50 

Definition at line 86 of file emimsg.h.

86  {
92 };
Definition: emimsg.h:87
Definition: emimsg.h:87
Definition: emimsg.h:89
Definition: emimsg.h:90
Definition: emimsg.h:91
Definition: emimsg.h:88
Definition: emimsg.h:89
Definition: emimsg.h:88
Definition: emimsg.h:87
Definition: emimsg.h:88
Definition: emimsg.h:87
Definition: emimsg.h:90
Definition: emimsg.h:88
Definition: emimsg.h:90
Definition: emimsg.h:90
Definition: emimsg.h:87
Definition: emimsg.h:90
Definition: emimsg.h:89
anonymous enum
Enumerator
E60_OADC 
E60_OTON 
E60_ONPI 
E60_STYP 
E60_PWD 
E60_NPWD 
E60_VERS 
E60_LADC 
E60_LTON 
E60_LNPI 
E60_OPID 
E60_RES1 
SZ60 

Definition at line 95 of file emimsg.h.

Function Documentation

struct emimsg* emimsg_create_op ( int  ot,
int  trn,
Octstr whoami 
)

Definition at line 166 of file emimsg.c.

References emimsg_create_withlen(), field_count_op(), emimsg::or, emimsg::ot, and emimsg::trn.

Referenced by get_fields(), make_emi31(), make_emi60(), and msg_to_emimsg().

167 {
168  int len;
169  struct emimsg *ret;
170 
171  len = field_count_op(ot, whoami);
172  if (len < 0)
173  return NULL;
174  ret = emimsg_create_withlen(len);
175  ret->ot = ot;
176  ret->or = 'O';
177  ret->trn = trn;
178  return ret;
179 }
char or
Definition: emimsg.h:72
int trn
Definition: emimsg.h:71
Definition: emimsg.h:70
static struct emimsg * emimsg_create_withlen(int len)
Definition: emimsg.c:153
int ot
Definition: emimsg.h:73
static int field_count_op(int ot, Octstr *whoami)
Definition: emimsg.c:111
struct emimsg* emimsg_create_reply ( int  ot,
int  trn,
int  positive,
Octstr whoami 
)

Definition at line 199 of file emimsg.c.

References emimsg_create_reply_s(), emimsg::fields, and octstr_create.

Referenced by handle_operation().

201 {
202  struct emimsg *ret;
203 
204  ret = emimsg_create_reply_s(ot, trn, positive, whoami);
205  if (ret) {
206  if (positive)
207  ret->fields[0] = octstr_create("A");
208  else
209  ret->fields[0] = octstr_create("N");
210  }
211  return ret;
212 }
int trn
Definition: emimsg.h:71
Definition: emimsg.h:70
#define octstr_create(cstr)
Definition: octstr.h:125
int ot
Definition: emimsg.h:73
Octstr ** fields
Definition: emimsg.h:75
static struct emimsg * emimsg_create_reply_s(int ot, int trn, int positive, Octstr *whoami)
Definition: emimsg.c:182
void emimsg_destroy ( struct emimsg emimsg)

Definition at line 215 of file emimsg.c.

References emimsg::fields, emimsg::num_fields, and octstr_destroy().

Referenced by emi2_do_send(), emi2_handle_smscreq(), emi2_keepalive_handling(), emi2_receiver(), get_fields(), handle_operation(), open_send_connection(), and wait_for_ack().

216 {
217  int len;
218 
219  len = emimsg->num_fields;
220  while (--len >= 0) {
221  octstr_destroy(emimsg->fields[len]); /* octstr_destroy(NULL) is ok */
222  emimsg->fields[len] = NULL;
223  }
224  gw_free(emimsg->fields);
225  gw_free(emimsg);
226 }
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:322
Octstr ** fields
Definition: emimsg.h:75
int num_fields
Definition: emimsg.h:74
struct emimsg* emimsg_duplicate ( struct emimsg emimsg)

Definition at line 229 of file emimsg.c.

References emimsg::fields, emimsg::num_fields, octstr_duplicate, emimsg::or, emimsg::ot, and emimsg::trn.

230 {
231  int len;
232  struct emimsg *ret;
233 
234  len = emimsg->num_fields;
235  if (len < 0)
236  return NULL;
237  ret = gw_malloc(sizeof(struct emimsg));
238  ret->fields = gw_malloc(len * sizeof(Octstr *));
239  ret->num_fields = len;
240  while (--len >= 0)
241  ret->fields[len] = octstr_duplicate(emimsg->fields[len]);
242  ret->ot = emimsg->ot;
243  ret->or = emimsg->or;
244  ret->trn = emimsg->trn;
245 
246  return ret;
247 }
char or
Definition: emimsg.h:72
int trn
Definition: emimsg.h:71
#define octstr_duplicate(ostr)
Definition: octstr.h:187
int ot
Definition: emimsg.h:73
Definition: octstr.c:118
Octstr ** fields
Definition: emimsg.h:75
int num_fields
Definition: emimsg.h:74
int emimsg_send ( Connection conn,
struct emimsg emimsg,
Octstr whoami 
)

Definition at line 368 of file emimsg.c.

References conn_write(), debug(), emimsg_tostring(), error(), octstr_destroy(), octstr_get_cstr, and emimsg::ot.

Referenced by emi2_emimsg_send().

369 {
370  Octstr *string;
371 
372  string = emimsg_tostring(emimsg);
373  if (!string) {
374  error(0, "EMI2[%s]: emimsg_send: conversion to string failed",
375  octstr_get_cstr(whoami));
376  return -1;
377  }
378  if (emimsg->ot == 60)
379  debug("smsc.emi2", 0, "EMI2[%s]: Sending operation type 60, message with "
380  "password not shown in log file.", octstr_get_cstr(whoami));
381  else
382  debug("smsc.emi2", 0, "EMI2[%s]: emi2 sending packet: <%s>",
383  octstr_get_cstr(whoami), octstr_get_cstr(string));
384  if (conn_write(conn, string) == -1) {
385  octstr_destroy(string);
386  error(0, "EMI2[%s]: emimsg_send: write failed",
387  octstr_get_cstr(whoami));
388  return -1;
389  }
390  octstr_destroy(string);
391  return 1;
392 }
void error(int err, const char *fmt,...)
Definition: log.c:612
static Octstr * emimsg_tostring(struct emimsg *emimsg)
Definition: emimsg.c:266
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
int conn_write(Connection *conn, Octstr *data)
Definition: conn.c:1043
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:322
int ot
Definition: emimsg.h:73
Definition: octstr.c:118
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:690
struct emimsg* get_fields ( Octstr message,
Octstr whoami 
)

Definition at line 290 of file emimsg.c.

References calculate_checksum(), debug(), emi_strerror(), emimsg_create_op(), emimsg_create_reply_s(), emimsg_destroy(), error(), emimsg::fields, emimsg::num_fields, octstr_copy, octstr_get_char(), octstr_get_cstr, octstr_len(), octstr_parse_long(), octstr_search_char(), emimsg::or, emimsg::ot, emimsg::trn, and warning().

Referenced by emi2_handle_smscreq(), emi2_receiver(), main(), and wait_for_ack().

291 {
292  long trn, len, ot, checksum; /* because of Octstr_parse_long... */
293  char or, posit;
294  long fieldno, pos, pos2;
295  struct emimsg *result = NULL;
296 
297  debug("smsc.emi2", 0, "EMI2[%s]: emi2 parsing packet: <%s>",
298  octstr_get_cstr(whoami), octstr_get_cstr(message));
299  if (octstr_get_char(message, 0) != 2 ||
300  octstr_get_char(message, octstr_len(message) - 1) != 3)
301  goto error;
302  if (octstr_parse_long(&trn, message, 1, 10) != 3)
303  goto error;
304  if (octstr_parse_long(&len, message, 4, 10) != 9)
305  goto error;
306  if (octstr_len(message) != len + 2) /* +2 for start/end markers */
307  goto error;
308  if ( (or = octstr_get_char(message, 10)) != 'O' && or != 'R')
309  goto error;
310  if (octstr_parse_long(&ot, message, 12, 10) != 14)
311  goto error;
312  if (or == 'O')
313  result = emimsg_create_op(ot, trn, whoami);
314  else {
315  posit = octstr_get_char(message, 15);
316  if (posit == 'A')
317  result = emimsg_create_reply_s(ot, trn, 1, whoami);
318  else if (posit == 'N')
319  result = emimsg_create_reply_s(ot, trn, 0, whoami);
320  else
321  goto error;
322  }
323  if (result == NULL)
324  goto error;
325  pos2 = 14;
326  for (fieldno = 0; fieldno < result->num_fields; fieldno++) {
327  pos = pos2 + 1;
328  if ( (pos2 = octstr_search_char(message, '/', pos)) == -1)
329  goto error;
330  if (pos2 > pos)
331  result->fields[fieldno] = octstr_copy(message, pos, pos2 - pos);
332  }
333  if (octstr_search_char(message, '/', pos2 + 1) != -1) {
334  int extrafields = 0;
335 
336  pos = pos2;
337  while ((pos = octstr_search_char(message, '/', pos + 1)) != -1) {
338  extrafields++;
339  pos2 = pos;
340  }
341  /* The extra fields are ignored */
342  warning(0, "get_fields: EMI message of type %d/%c has %d more fields "
343  "than expected.", result->ot, result->or, extrafields);
344  }
345  if (octstr_parse_long(&checksum, message, pos2 + 1, 16) !=
346  octstr_len(message) - 1 || checksum != calculate_checksum(message))
347  goto error;
348  if (result->or == 'R' && octstr_get_char(result->fields[0], 0) == 'N') {
349  long errcode;
350  if (!result->fields[1] ||
351  octstr_parse_long(&errcode, result->fields[1], 0, 10) != 2)
352  goto error;
353  error(0, "EMI2[%s]: Got negative ack. op:%d, trn:%d, error:%ld (%s), message:%s",
354  octstr_get_cstr(whoami),
355  result->ot, result->trn, errcode, emi_strerror(errcode),
356  result->fields[2] ? octstr_get_cstr(result->fields[2]) : "");
357  }
358  return result;
359 error:
360  error(0, "EMI2[%s]: Invalid EMI packet: %s", octstr_get_cstr(whoami),
361  octstr_get_cstr(message));
362  if (result)
363  emimsg_destroy(result);
364  return NULL;
365 }
void error(int err, const char *fmt,...)
Definition: log.c:612
char or
Definition: emimsg.h:72
void emimsg_destroy(struct emimsg *emimsg)
Definition: emimsg.c:215
int trn
Definition: emimsg.h:71
struct emimsg * emimsg_create_op(int ot, int trn, Octstr *whoami)
Definition: emimsg.c:166
Definition: emimsg.h:70
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
#define octstr_copy(ostr, from, len)
Definition: octstr.h:178
long octstr_search_char(const Octstr *ostr, int ch, long pos)
Definition: octstr.c:1010
static int calculate_checksum(Octstr *message)
Definition: emimsg.c:252
void warning(int err, const char *fmt,...)
Definition: log.c:624
static char * emi_strerror(int errnum)
Definition: emimsg.c:67
long octstr_len(const Octstr *ostr)
Definition: octstr.c:340
int ot
Definition: emimsg.h:73
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:690
Octstr ** fields
Definition: emimsg.h:75
long octstr_parse_long(long *nump, Octstr *ostr, long pos, int base)
Definition: octstr.c:747
int octstr_get_char(const Octstr *ostr, long pos)
Definition: octstr.c:404
static struct emimsg * emimsg_create_reply_s(int ot, int trn, int positive, Octstr *whoami)
Definition: emimsg.c:182
int num_fields
Definition: emimsg.h:74
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.