Kannel: Open Source WAP and SMS gateway  $Revision: 5037 $
dlr.c File Reference
#include <ctype.h>
#include <time.h>
#include <errno.h>
#include <limits.h>
#include <string.h>
#include <unistd.h>
#include "gwlib/gwlib.h"
#include "sms.h"
#include "dlr.h"
#include "dlr_p.h"
#include "meta_data.h"

Go to the source code of this file.

Macros

#define O_DELETE(a)   { if (a) octstr_destroy(a); a = NULL; }
 
#define O_DELETE(a)   { if (a) octstr_destroy(a); a = NULL; }
 
#define O_SET(x, val)   if (octstr_len(val) > 0) { x = val; val = NULL; }
 

Functions

struct dlr_entrydlr_entry_create (void)
 
struct dlr_entrydlr_entry_duplicate (const struct dlr_entry *dlr)
 
void dlr_entry_destroy (struct dlr_entry *dlr)
 
struct dlr_db_fieldsdlr_db_fields_create (CfgGroup *grp)
 
void dlr_db_fields_destroy (struct dlr_db_fields *fields)
 
void dlr_init (Cfg *cfg)
 
void dlr_shutdown ()
 
long dlr_messages (void)
 
const char * dlr_type (void)
 
void dlr_add (const Octstr *smsc, const Octstr *ts, Msg *msg, int use_dst)
 
Msgdlr_find (const Octstr *smsc, const Octstr *ts, const Octstr *dst, int typ, int use_dst)
 
void dlr_flush (void)
 
Msgcreate_dlr_from_msg (const Octstr *smsc, const Msg *msg, const Octstr *reply, long stat)
 

Variables

static struct dlr_storagehandles = NULL
 

Macro Definition Documentation

#define O_DELETE (   a)    { if (a) octstr_destroy(a); a = NULL; }
#define O_DELETE (   a)    { if (a) octstr_destroy(a); a = NULL; }
#define O_SET (   x,
  val 
)    if (octstr_len(val) > 0) { x = val; val = NULL; }

Referenced by dlr_find().

Function Documentation

Msg* create_dlr_from_msg ( const Octstr smsc,
const Msg msg,
const Octstr reply,
long  stat 
)

Definition at line 501 of file dlr.c.

References debug(), DLR_IS_ENABLED, dlr_mask, gw_assert(), meta_data_set_value(), METADATA_ORIG_MSG_GROUP, METADATA_ORIG_MSG_GROUP_DLR_MASK, msg_create, octstr_create, octstr_destroy(), octstr_duplicate, octstr_format(), octstr_get_cstr, octstr_imm(), and report_mo.

Referenced by bb_smscconn_send_failed(), and bb_smscconn_sent().

502 {
503  Msg *dlrmsg;
504 
505  if (msg == NULL)
506  return NULL;
507 
508  /* generate DLR */
509  debug("dlr.dlr", 0,"SMSC[%s]: creating DLR message",
510  (smsc ? octstr_get_cstr(smsc) : "UNKNOWN"));
511 
512  dlrmsg = msg_create(sms);
513  gw_assert(dlrmsg != NULL);
514 
515  dlrmsg->sms.service = octstr_duplicate(msg->sms.service);
516  dlrmsg->sms.dlr_mask = stat;
517  dlrmsg->sms.sms_type = report_mo;
518  dlrmsg->sms.smsc_id = octstr_duplicate(smsc ? smsc : msg->sms.smsc_id);
519  dlrmsg->sms.sender = octstr_duplicate(msg->sms.sender);
520  dlrmsg->sms.receiver = octstr_duplicate(msg->sms.receiver);
521  dlrmsg->sms.dlr_url = octstr_duplicate(msg->sms.dlr_url);
522  dlrmsg->sms.msgdata = octstr_duplicate(reply);
523  dlrmsg->sms.boxc_id = octstr_duplicate(msg->sms.boxc_id);
524  dlrmsg->sms.foreign_id = octstr_duplicate(msg->sms.foreign_id);
525  time(&dlrmsg->sms.time);
526  dlrmsg->sms.meta_data = octstr_duplicate(msg->sms.meta_data);
527 
528  /* add original DLR bit-mask, as we do in dlr_find() */
529  if (DLR_IS_ENABLED(msg->sms.dlr_mask)) {
530  Octstr *dlr_mask = octstr_format("%ld", msg->sms.dlr_mask);
531  if (dlrmsg->sms.meta_data == NULL)
532  dlrmsg->sms.meta_data = octstr_create("");
533  meta_data_set_value(dlrmsg->sms.meta_data, METADATA_ORIG_MSG_GROUP,
535  octstr_destroy(dlr_mask);
536  }
537 
538  debug("dlr.dlr", 0,"SMSC[%s]: DLR = %s",
539  (smsc ? octstr_get_cstr(smsc) : "UNKNOWN"),
540  (dlrmsg->sms.dlr_url ? octstr_get_cstr(dlrmsg->sms.dlr_url) : ""));
541 
542  return dlrmsg;
543 }
static Octstr * dlr_mask
Definition: test_ppg.c:106
#define METADATA_ORIG_MSG_GROUP_DLR_MASK
Definition: meta_data.h:74
Definition: msg.h:109
int meta_data_set_value(Octstr *data, const char *group, const Octstr *key, const Octstr *value, int replace)
Definition: meta_data.c:324
#define msg_create(type)
Definition: msg.h:136
#define DLR_IS_ENABLED(dlr)
Definition: dlr.h:81
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:281
Definition: msg.h:79
#define octstr_duplicate(ostr)
Definition: octstr.h:187
#define METADATA_ORIG_MSG_GROUP
Definition: meta_data.h:73
Octstr * octstr_format(const char *fmt,...)
Definition: octstr.c:2462
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:322
#define octstr_create(cstr)
Definition: octstr.h:125
gw_assert(wtls_machine->packet_to_send!=NULL)
Definition: octstr.c:118
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:690
void dlr_add ( const Octstr smsc,
const Octstr ts,
Msg msg,
int  use_dst 
)

Definition at line 330 of file dlr.c.

References dlr_entry::boxc_id, debug(), dlr_entry::destination, dlr_storage::dlr_add, dlr_entry_create(), DLR_IS_ENABLED, dlr_type(), gw_assert(), dlr_entry::mask, octstr_create, octstr_destroy(), octstr_duplicate, octstr_get_cstr, octstr_len(), split_parts::orig, dlr_entry::service, dlr_entry::smsc, dlr_entry::source, split, dlr_entry::timestamp, dlr_entry::url, dlr_entry::use_dst, and warning().

Referenced by add_msg_cb(), at2_send_one_message(), cgw_handle_op(), cimd2_submit_msg(), clickatell_parse_reply(), emi2_handle_smscreq(), generic_parse_reply(), handle_pdu(), kannel_parse_reply(), msg_cb(), oisd_submit_msg(), soap_read_response(), and xidris_parse_reply().

331 {
332  struct dlr_entry *dlr = NULL;
333 
334  /* Add the foreign_id so all SMSC modules can use it.
335  * Obey also the original message in the split_parts list. */
336  if (msg->sms.foreign_id != NULL)
337  octstr_destroy(msg->sms.foreign_id);
338  msg->sms.foreign_id = octstr_duplicate(ts);
339  if (msg->sms.split_parts != NULL) {
340  struct split_parts *split = msg->sms.split_parts;
341  if (split->orig->sms.foreign_id != NULL)
342  octstr_destroy(split->orig->sms.foreign_id);
343  split->orig->sms.foreign_id = octstr_duplicate(ts);
344  }
345 
346  if (octstr_len(smsc) == 0) {
347  warning(0, "DLR[%s]: Can't add a dlr without smsc-id", dlr_type());
348  return;
349  }
350 
351  /* sanity check */
352  if (handles == NULL || handles->dlr_add == NULL || msg == NULL)
353  return;
354 
355  /* check if delivery receipt requested */
356  if (!DLR_IS_ENABLED(msg->sms.dlr_mask))
357  return;
358 
359  /* allocate new struct dlr_entry struct */
360  dlr = dlr_entry_create();
361  gw_assert(dlr != NULL);
362 
363  /* now copy all values, we are interested in */
364  dlr->smsc = (smsc ? octstr_duplicate(smsc) : octstr_create(""));
365  dlr->timestamp = (ts ? octstr_duplicate(ts) : octstr_create(""));
366  dlr->source = (msg->sms.sender ? octstr_duplicate(msg->sms.sender) : octstr_create(""));
367  dlr->destination = (msg->sms.receiver ? octstr_duplicate(msg->sms.receiver) : octstr_create(""));
368  dlr->service = (msg->sms.service ? octstr_duplicate(msg->sms.service) : octstr_create(""));
369  dlr->url = (msg->sms.dlr_url ? octstr_duplicate(msg->sms.dlr_url) : octstr_create(""));
370  dlr->boxc_id = (msg->sms.boxc_id ? octstr_duplicate(msg->sms.boxc_id) : octstr_create(""));
371  dlr->mask = msg->sms.dlr_mask;
372  dlr->use_dst = use_dst;
373 
374  debug("dlr.dlr", 0, "DLR[%s]: Adding DLR smsc=%s, ts=%s, src=%s, dst=%s, mask=%d, boxc=%s",
377 
378  /* call registered function */
379  handles->dlr_add(dlr);
380 }
Octstr * url
Definition: dlr_p.h:84
Octstr * service
Definition: dlr_p.h:83
struct dlr_entry * dlr_entry_create(void)
Definition: dlr.c:103
Octstr * boxc_id
Definition: dlr_p.h:85
void(* dlr_add)(struct dlr_entry *entry)
Definition: dlr_p.h:117
#define DLR_IS_ENABLED(dlr)
Definition: dlr.h:81
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
static struct dlr_storage * handles
Definition: dlr.c:97
Octstr * source
Definition: dlr_p.h:81
const char * dlr_type(void)
Definition: dlr.c:319
#define octstr_duplicate(ostr)
Definition: octstr.h:187
void warning(int err, const char *fmt,...)
Definition: log.c:624
Octstr * timestamp
Definition: dlr_p.h:80
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:322
#define octstr_create(cstr)
Definition: octstr.h:125
gw_assert(wtls_machine->packet_to_send!=NULL)
long octstr_len(const Octstr *ostr)
Definition: octstr.c:340
Octstr * destination
Definition: dlr_p.h:82
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:690
static List * split
Definition: test_http.c:88
Msg * orig
Definition: msg.h:92
Definition: dlr_p.h:78
Octstr * smsc
Definition: dlr_p.h:79
int mask
Definition: dlr_p.h:86
int use_dst
Definition: dlr_p.h:87
struct dlr_db_fields* dlr_db_fields_create ( CfgGroup grp)

Definition at line 169 of file dlr.c.

References cfg_get, cfg_get_integer(), dlr_db_fields::field_boxc, dlr_db_fields::field_dst, dlr_db_fields::field_mask, dlr_db_fields::field_serv, dlr_db_fields::field_smsc, dlr_db_fields::field_src, dlr_db_fields::field_status, dlr_db_fields::field_ts, dlr_db_fields::field_url, gw_assert(), octstr_imm(), panic, dlr_db_fields::table, and dlr_db_fields::ttl.

170 {
171  struct dlr_db_fields *ret = NULL;
172 
173  ret = gw_malloc(sizeof(*ret));
174  gw_assert(ret != NULL);
175  memset(ret, 0, sizeof(*ret));
176 
177  if (!(ret->table = cfg_get(grp, octstr_imm("table"))))
178  panic(0, "DLR: DB: directive 'table' is not specified!");
179  ret->ttl = 0;
180  if (cfg_get_integer(&ret->ttl, grp, octstr_imm("ttl")) == -1 || ret->ttl < 0)
181  ret->ttl = 0;
182  if (!(ret->field_smsc = cfg_get(grp, octstr_imm("field-smsc"))))
183  panic(0, "DLR: DB: directive 'field-smsc' is not specified!");
184  if (!(ret->field_ts = cfg_get(grp, octstr_imm("field-timestamp"))))
185  panic(0, "DLR: DB: directive 'field-timestamp' is not specified!");
186  if (!(ret->field_src = cfg_get(grp, octstr_imm("field-source"))))
187  panic(0, "DLR: DB: directive 'field-source' is not specified!");
188  if (!(ret->field_dst = cfg_get(grp, octstr_imm("field-destination"))))
189  panic(0, "DLR: DB: directive 'field-destination' is not specified!");
190  if (!(ret->field_serv = cfg_get(grp, octstr_imm("field-service"))))
191  panic(0, "DLR: DB: directive 'field-service' is not specified!");
192  if (!(ret->field_url = cfg_get(grp, octstr_imm("field-url"))))
193  panic(0, "DLR: DB: directive 'field-url' is not specified!");
194  if (!(ret->field_mask = cfg_get(grp, octstr_imm("field-mask"))))
195  panic(0, "DLR: DB: directive 'field-mask' is not specified!");
196  if (!(ret->field_status = cfg_get(grp, octstr_imm("field-status"))))
197  panic(0, "DLR: DB: directive 'field-status' is not specified!");
198  if (!(ret->field_boxc = cfg_get(grp, octstr_imm("field-boxc-id"))))
199  panic(0, "DLR: DB: directive 'field-boxc-id' is not specified!");
200 
201  return ret;
202 }
Octstr * field_boxc
Definition: dlr_p.h:160
#define cfg_get(grp, varname)
Definition: cfg.h:86
Octstr * field_src
Definition: dlr_p.h:154
Octstr * field_url
Definition: dlr_p.h:157
Octstr * field_status
Definition: dlr_p.h:159
Octstr * table
Definition: dlr_p.h:150
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:281
Octstr * field_serv
Definition: dlr_p.h:156
gw_assert(wtls_machine->packet_to_send!=NULL)
Octstr * field_smsc
Definition: dlr_p.h:152
int cfg_get_integer(long *n, CfgGroup *grp, Octstr *varname)
Definition: cfg.c:739
#define panic
Definition: log.h:87
Octstr * field_ts
Definition: dlr_p.h:153
Octstr * field_dst
Definition: dlr_p.h:155
Octstr * field_mask
Definition: dlr_p.h:158
long ttl
Definition: dlr_p.h:151
void dlr_db_fields_destroy ( struct dlr_db_fields fields)

Definition at line 204 of file dlr.c.

References dlr_db_fields::field_boxc, dlr_db_fields::field_dst, dlr_db_fields::field_mask, dlr_db_fields::field_serv, dlr_db_fields::field_smsc, dlr_db_fields::field_src, dlr_db_fields::field_status, dlr_db_fields::field_ts, dlr_db_fields::field_url, O_DELETE, and dlr_db_fields::table.

205 {
206  /* sanity check */
207  if (fields == NULL)
208  return;
209 
210 #define O_DELETE(a) { if (a) octstr_destroy(a); a = NULL; }
211 
212  O_DELETE(fields->table);
213  O_DELETE(fields->field_smsc);
214  O_DELETE(fields->field_ts);
215  O_DELETE(fields->field_src);
216  O_DELETE(fields->field_dst);
217  O_DELETE(fields->field_serv);
218  O_DELETE(fields->field_url);
219  O_DELETE(fields->field_mask);
220  O_DELETE(fields->field_status);
221  O_DELETE(fields->field_boxc);
222 
223 #undef O_DELETE
224 
225  gw_free(fields);
226 }
Octstr * field_boxc
Definition: dlr_p.h:160
Octstr * field_src
Definition: dlr_p.h:154
Octstr * field_url
Definition: dlr_p.h:157
Octstr * field_status
Definition: dlr_p.h:159
Octstr * table
Definition: dlr_p.h:150
Octstr * field_serv
Definition: dlr_p.h:156
Octstr * field_smsc
Definition: dlr_p.h:152
#define O_DELETE(a)
Octstr * field_ts
Definition: dlr_p.h:153
Octstr * field_dst
Definition: dlr_p.h:155
Octstr * field_mask
Definition: dlr_p.h:158
struct dlr_entry* dlr_entry_create ( void  )

Definition at line 103 of file dlr.c.

References gw_assert().

Referenced by dlr_add(), dlr_entry_duplicate(), and dlr_spool_get().

104 {
105  struct dlr_entry *dlr;
106 
107  dlr = gw_malloc(sizeof(*dlr));
108  gw_assert(dlr != NULL);
109 
110  /* set all values to NULL */
111  memset(dlr, 0, sizeof(*dlr));
112 
113  return dlr;
114 }
gw_assert(wtls_machine->packet_to_send!=NULL)
Definition: dlr_p.h:78
void dlr_entry_destroy ( struct dlr_entry dlr)

Definition at line 142 of file dlr.c.

References dlr_entry::boxc_id, dlr_entry::destination, dlr_entry::mask, O_DELETE, dlr_entry::service, dlr_entry::smsc, dlr_entry::source, dlr_entry::timestamp, and dlr_entry::url.

Referenced by dlr_find(), dlr_mem_flush(), dlr_mem_remove(), dlr_mem_shutdown(), and dlr_spool_add().

143 {
144  /* sanity check */
145  if (dlr == NULL)
146  return;
147 
148 #define O_DELETE(a) { if (a) octstr_destroy(a); a = NULL; }
149 
150  O_DELETE(dlr->smsc);
151  O_DELETE(dlr->timestamp);
152  O_DELETE(dlr->source);
153  O_DELETE(dlr->destination);
154  O_DELETE(dlr->service);
155  O_DELETE(dlr->url);
156  O_DELETE(dlr->boxc_id);
157 
158 #undef O_DELETE
159 
160  dlr->mask = 0;
161  gw_free(dlr);
162 }
Octstr * url
Definition: dlr_p.h:84
Octstr * service
Definition: dlr_p.h:83
Octstr * boxc_id
Definition: dlr_p.h:85
Octstr * source
Definition: dlr_p.h:81
Octstr * timestamp
Definition: dlr_p.h:80
Octstr * destination
Definition: dlr_p.h:82
#define O_DELETE(a)
Octstr * smsc
Definition: dlr_p.h:79
int mask
Definition: dlr_p.h:86
struct dlr_entry* dlr_entry_duplicate ( const struct dlr_entry dlr)

Definition at line 119 of file dlr.c.

References dlr_entry::boxc_id, dlr_entry::destination, dlr_entry_create(), dlr_entry::mask, octstr_duplicate, dlr_entry::service, dlr_entry::smsc, dlr_entry::source, dlr_entry::timestamp, and dlr_entry::url.

Referenced by dlr_mem_get().

120 {
121  struct dlr_entry *ret;
122 
123  if (dlr == NULL)
124  return NULL;
125 
126  ret = dlr_entry_create();
127  ret->smsc = octstr_duplicate(dlr->smsc);
128  ret->timestamp = octstr_duplicate(dlr->timestamp);
129  ret->source = octstr_duplicate(dlr->source);
131  ret->service = octstr_duplicate(dlr->service);
132  ret->url = octstr_duplicate(dlr->url);
133  ret->boxc_id = octstr_duplicate(dlr->boxc_id);
134  ret->mask = dlr->mask;
135 
136  return ret;
137 }
Octstr * url
Definition: dlr_p.h:84
Octstr * service
Definition: dlr_p.h:83
struct dlr_entry * dlr_entry_create(void)
Definition: dlr.c:103
Octstr * boxc_id
Definition: dlr_p.h:85
Octstr * source
Definition: dlr_p.h:81
#define octstr_duplicate(ostr)
Definition: octstr.h:187
Octstr * timestamp
Definition: dlr_p.h:80
Octstr * destination
Definition: dlr_p.h:82
Definition: dlr_p.h:78
Octstr * smsc
Definition: dlr_p.h:79
int mask
Definition: dlr_p.h:86
Msg* dlr_find ( const Octstr smsc,
const Octstr ts,
const Octstr dst,
int  typ,
int  use_dst 
)

Definition at line 387 of file dlr.c.

References dlr_entry::boxc_id, debug(), dlr_entry::destination, dlr_entry_destroy(), dlr_storage::dlr_get, DLR_IS_NOT_FINAL, DLR_IS_SUCCESS_OR_FAIL, dlr_mask, dlr_storage::dlr_remove, dlr_type(), dlr_storage::dlr_update, dlr_entry::mask, meta_data_set_value(), METADATA_ORIG_MSG_GROUP, METADATA_ORIG_MSG_GROUP_DLR_MASK, MIN_DST_LEN, msg, msg_create, O_SET, octstr_create, octstr_delete(), octstr_destroy(), octstr_duplicate, octstr_format(), octstr_get_cstr, octstr_imm(), octstr_len(), report_mo, dlr_entry::service, dlr_entry::smsc, dlr_entry::source, dlr_entry::url, and warning().

Referenced by at2_pdu_decode_report_sm(), cgw_handle_op(), cimd2_accept_delivery_report_message(), clickatell_receive_sms(), generic_receive_sms(), handle_dlr(), handle_operation(), kannel_receive_sms(), main_connection_loop(), oisd_accept_delivery_report_message(), soap_parse_dlr(), and xidris_receive_sms().

388 {
389  Msg *msg = NULL;
390  struct dlr_entry *dlr = NULL;
391  Octstr *dst_min = NULL;
392  Octstr *dlr_mask;
393 
394  if(octstr_len(smsc) == 0) {
395  warning(0, "DLR[%s]: Can't find a dlr without smsc-id", dlr_type());
396  return NULL;
397  }
398 
399  /* check if we have handler registered */
400  if (handles == NULL || handles->dlr_get == NULL)
401  return NULL;
402 
403  if (use_dst && dst) {
404  dst_min = octstr_duplicate(dst);
405  int len = octstr_len(dst);
406 
407  if (len > MIN_DST_LEN)
408  octstr_delete(dst_min, 0, len - MIN_DST_LEN);
409  }
410  debug("dlr.dlr", 0, "DLR[%s]: Looking for DLR smsc=%s, ts=%s, dst=%s, type=%d",
411  dlr_type(), octstr_get_cstr(smsc), octstr_get_cstr(ts), octstr_get_cstr(dst), typ);
412 
413  dlr = handles->dlr_get(smsc, ts, dst_min);
414  if (dlr == NULL) {
415  warning(0, "DLR[%s]: DLR from SMSC<%s> for DST<%s> not found.",
416  dlr_type(), octstr_get_cstr(smsc), octstr_get_cstr(dst));
417  return NULL;
418  }
419 
420 #define O_SET(x, val) if (octstr_len(val) > 0) { x = val; val = NULL; }
421 
422  if ((typ & dlr->mask) > 0) {
423  /* its an entry we are interested in */
424  msg = msg_create(sms);
425  msg->sms.sms_type = report_mo;
426  msg->sms.dlr_mask = typ;
427  O_SET(msg->sms.service, dlr->service);
428  O_SET(msg->sms.smsc_id, dlr->smsc);
429  O_SET(msg->sms.receiver, dlr->destination);
430  O_SET(msg->sms.sender, dlr->source);
431  /* if dlr_url was present, recode it here again */
432  O_SET(msg->sms.dlr_url, dlr->url);
433  /* add the foreign_id */
434  msg->sms.foreign_id = octstr_duplicate(ts);
435  /*
436  * insert original message to the data segment
437  * later in the smsc module
438  */
439  msg->sms.msgdata = NULL;
440  /*
441  * If a boxc_id is available, then instruct bearerbox to
442  * route this msg back to originating smsbox
443  */
444  O_SET(msg->sms.boxc_id, dlr->boxc_id);
445  /*
446  * We will provide the DLR request bitmask in the DLR going back
447  * to the smsbox connection for processing. This allows smsbox
448  * connection type applications to avoid temporary storing and
449  * resolving data to pull up this information.
450  */
451  dlr_mask = octstr_format("%ld", dlr->mask);
452  msg->sms.meta_data = octstr_create("");
453  meta_data_set_value(msg->sms.meta_data, METADATA_ORIG_MSG_GROUP,
455  octstr_destroy(dlr_mask);
456 
457  time(&msg->sms.time);
458  debug("dlr.dlr", 0, "DLR[%s]: created DLR message for URL <%s>",
459  dlr_type(), (msg->sms.dlr_url?octstr_get_cstr(msg->sms.dlr_url):""));
460  } else {
461  debug("dlr.dlr", 0, "DLR[%s]: Ignoring DLR message because of mask type=%d dlr->mask=%d", dlr_type(), typ, dlr->mask);
462  /* ok that was a status report but we where not interested in having it */
463  msg = NULL;
464  }
465 
466 #undef O_SET
467 
468  /* check for end status and if so remove from storage */
469  if (DLR_IS_NOT_FINAL(typ) && DLR_IS_SUCCESS_OR_FAIL(dlr->mask)) {
470  debug("dlr.dlr", 0, "DLR[%s]: DLR not destroyed, still waiting for other delivery report", dlr_type());
471  /* update dlr entry status if function defined */
472  if (handles != NULL && handles->dlr_update != NULL){
473  handles->dlr_update(smsc, ts, dst_min, typ);
474  }
475  } else {
476  if (handles != NULL && handles->dlr_remove != NULL){
477  /* it's not good for internal storage, but better for all others */
478  handles->dlr_remove(smsc, ts, dst_min);
479  } else {
480  warning(0, "DLR[%s]: Storage don't have remove operation defined", dlr_type());
481  }
482  }
483 
484  /* destroy struct dlr_entry */
485  dlr_entry_destroy(dlr);
486  octstr_destroy(dst_min);
487 
488  return msg;
489 }
static Octstr * dlr_mask
Definition: test_ppg.c:106
#define METADATA_ORIG_MSG_GROUP_DLR_MASK
Definition: meta_data.h:74
Octstr * url
Definition: dlr_p.h:84
void(* dlr_update)(const Octstr *smsc, const Octstr *ts, const Octstr *dst, int status)
Definition: dlr_p.h:130
Octstr * service
Definition: dlr_p.h:83
Definition: msg.h:109
Octstr * boxc_id
Definition: dlr_p.h:85
int meta_data_set_value(Octstr *data, const char *group, const Octstr *key, const Octstr *value, int replace)
Definition: meta_data.c:324
#define MIN_DST_LEN
Definition: dlr_p.h:74
#define msg_create(type)
Definition: msg.h:136
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
static struct dlr_storage * handles
Definition: dlr.c:97
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:281
Definition: msg.h:79
void octstr_delete(Octstr *ostr1, long pos, long len)
Definition: octstr.c:1525
Octstr * source
Definition: dlr_p.h:81
struct dlr_entry *(* dlr_get)(const Octstr *smsc, const Octstr *ts, const Octstr *dst)
Definition: dlr_p.h:122
const char * dlr_type(void)
Definition: dlr.c:319
#define octstr_duplicate(ostr)
Definition: octstr.h:187
#define METADATA_ORIG_MSG_GROUP
Definition: meta_data.h:73
void warning(int err, const char *fmt,...)
Definition: log.c:624
Octstr * octstr_format(const char *fmt,...)
Definition: octstr.c:2462
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:322
#define octstr_create(cstr)
Definition: octstr.h:125
long octstr_len(const Octstr *ostr)
Definition: octstr.c:340
Octstr * destination
Definition: dlr_p.h:82
Definition: octstr.c:118
#define DLR_IS_NOT_FINAL(dlr)
Definition: dlr.h:84
void dlr_entry_destroy(struct dlr_entry *dlr)
Definition: dlr.c:142
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:690
#define O_SET(x, val)
Definition: dlr_p.h:78
Octstr * smsc
Definition: dlr_p.h:79
int mask
Definition: dlr_p.h:86
void(* dlr_remove)(const Octstr *smsc, const Octstr *ts, const Octstr *dst)
Definition: dlr_p.h:126
#define DLR_IS_SUCCESS_OR_FAIL(dlr)
Definition: dlr.h:85
static XMLRPCDocument * msg
Definition: test_xmlrpc.c:86
int use_dst
Definition: dlr_p.h:87
void dlr_flush ( void  )

Definition at line 491 of file dlr.c.

References dlr_storage::dlr_flush, dlr_messages(), dlr_type(), and info().

Referenced by bb_flush_dlr().

492 {
493  info(0, "Flushing all %ld queued DLR messages in %s storage", dlr_messages(),
494  dlr_type());
495 
496  if (handles != NULL && handles->dlr_flush != NULL)
497  handles->dlr_flush();
498 }
void info(int err, const char *fmt,...)
Definition: log.c:636
static struct dlr_storage * handles
Definition: dlr.c:97
void(* dlr_flush)(void)
Definition: dlr_p.h:138
const char * dlr_type(void)
Definition: dlr.c:319
long dlr_messages(void)
Definition: dlr.c:308
void dlr_init ( Cfg cfg)

Definition at line 233 of file dlr.c.

References cfg_get, cfg_get_single_group(), dlr_storage::dlr_add, dlr_storage::dlr_get, dlr_init_cass(), dlr_init_mem(), dlr_init_mssql(), dlr_init_mysql(), dlr_init_oracle(), dlr_init_pgsql(), dlr_init_redis(), dlr_init_sdb(), dlr_init_spool(), dlr_init_sqlite3(), dlr_storage::dlr_remove, dlr_type(), info(), octstr_compare(), octstr_destroy(), octstr_get_cstr, octstr_imm(), panic, dlr_storage::type, and warning().

Referenced by main().

234 {
235  CfgGroup *grp;
236  Octstr *dlr_type;
237 
238  /* check which DLR storage type we are using */
239  grp = cfg_get_single_group(cfg, octstr_imm("core"));
240  if(grp == NULL)
241  panic(0, "DLR: can't find group core");
242 
243  dlr_type = cfg_get(grp, octstr_imm("dlr-storage"));
244 
245  /*
246  * assume we are using internal memory in case no directive
247  * has been specified, warn the user anyway
248  */
249  if (dlr_type == NULL) {
250  dlr_type = octstr_imm("internal");
251  warning(0, "DLR: using default 'internal' for storage type.");
252  }
253 
254  /* call the sub-init routine */
255  if (octstr_compare(dlr_type, octstr_imm("spool")) == 0) {
256  handles = dlr_init_spool(cfg);
257  } else if (octstr_compare(dlr_type, octstr_imm("mysql")) == 0) {
258  handles = dlr_init_mysql(cfg);
259  } else if (octstr_compare(dlr_type, octstr_imm("sdb")) == 0) {
260  handles = dlr_init_sdb(cfg);
261  } else if (octstr_compare(dlr_type, octstr_imm("oracle")) == 0) {
262  handles = dlr_init_oracle(cfg);
263  } else if (octstr_compare(dlr_type, octstr_imm("internal")) == 0) {
264  handles = dlr_init_mem(cfg);
265  } else if (octstr_compare(dlr_type, octstr_imm("pgsql")) == 0) {
266  handles = dlr_init_pgsql(cfg);
267  } else if (octstr_compare(dlr_type, octstr_imm("mssql")) == 0) {
268  handles = dlr_init_mssql(cfg);
269  } else if (octstr_compare(dlr_type, octstr_imm("sqlite3")) == 0) {
270  handles = dlr_init_sqlite3(cfg);
271  } else if (octstr_compare(dlr_type, octstr_imm("redis")) == 0) {
272  handles = dlr_init_redis(cfg);
273  } else if (octstr_compare(dlr_type, octstr_imm("cassandra")) == 0) {
274  handles = dlr_init_cass(cfg);
275  }
276 
277  /*
278  * add aditional types here
279  */
280 
281  if (handles == NULL) {
282  panic(0, "DLR: storage type '%s' is not supported!", octstr_get_cstr(dlr_type));
283  }
284 
285  /* check needed function pointers */
286  if (handles->dlr_add == NULL || handles->dlr_get == NULL || handles->dlr_remove == NULL)
287  panic(0, "DLR: storage type '%s' don't implement needed functions", octstr_get_cstr(dlr_type));
288 
289  /* get info from storage */
290  info(0, "DLR using storage type: %s", handles->type);
291 
292  /* cleanup */
293  octstr_destroy(dlr_type);
294 }
const char * type
Definition: dlr_p.h:112
void info(int err, const char *fmt,...)
Definition: log.c:636
struct dlr_storage * dlr_init_sdb(Cfg *cfg)
Definition: dlr_sdb.c:477
#define cfg_get(grp, varname)
Definition: cfg.h:86
struct dlr_storage * dlr_init_mem(Cfg *cfg)
Definition: dlr_mem.c:206
void(* dlr_add)(struct dlr_entry *entry)
Definition: dlr_p.h:117
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
struct dlr_storage * dlr_init_oracle(Cfg *cfg)
Definition: dlr_oracle.c:428
struct dlr_storage * dlr_init_pgsql(Cfg *cfg)
Definition: dlr_pgsql.c:420
static struct dlr_storage * handles
Definition: dlr.c:97
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:281
struct dlr_entry *(* dlr_get)(const Octstr *smsc, const Octstr *ts, const Octstr *dst)
Definition: dlr_p.h:122
const char * dlr_type(void)
Definition: dlr.c:319
struct dlr_storage * dlr_init_sqlite3(Cfg *cfg)
Definition: dlr_sqlite3.c:421
void warning(int err, const char *fmt,...)
Definition: log.c:624
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:322
struct dlr_storage * dlr_init_spool(Cfg *cfg)
Definition: dlr_spool.c:607
struct dlr_storage * dlr_init_redis(Cfg *cfg)
Definition: dlr_redis.c:569
struct dlr_storage * dlr_init_mysql(Cfg *cfg)
Definition: dlr_mysql.c:470
struct dlr_storage * dlr_init_mssql(Cfg *cfg)
Definition: dlr_mssql.c:394
Definition: octstr.c:118
struct dlr_storage * dlr_init_cass(Cfg *cfg)
Definition: dlr_cass.c:427
#define panic
Definition: log.h:87
Definition: cfg.c:73
CfgGroup * cfg_get_single_group(Cfg *cfg, Octstr *name)
Definition: cfg.c:636
void(* dlr_remove)(const Octstr *smsc, const Octstr *ts, const Octstr *dst)
Definition: dlr_p.h:126
int octstr_compare(const Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:869
long dlr_messages ( void  )

Definition at line 308 of file dlr.c.

References dlr_storage::dlr_messages.

Referenced by bb_print_status(), and dlr_flush().

309 {
310  if (handles != NULL && handles->dlr_messages != NULL)
311  return handles->dlr_messages();
312 
313  return -1;
314 }
long(* dlr_messages)(void)
Definition: dlr_p.h:134
static struct dlr_storage * handles
Definition: dlr.c:97
void dlr_shutdown ( void  )

Definition at line 299 of file dlr.c.

References dlr_storage::dlr_shutdown.

Referenced by main().

300 {
301  if (handles != NULL && handles->dlr_shutdown != NULL)
303 }
static struct dlr_storage * handles
Definition: dlr.c:97
void(* dlr_shutdown)(void)
Definition: dlr_p.h:142
const char* dlr_type ( void  )

Definition at line 319 of file dlr.c.

References dlr_storage::type.

Referenced by bb_print_status(), dlr_add(), dlr_find(), dlr_flush(), and dlr_init().

320 {
321  if (handles != NULL && handles->type != NULL)
322  return handles->type;
323 
324  return "unknown";
325 }
const char * type
Definition: dlr_p.h:112
static struct dlr_storage * handles
Definition: dlr.c:97

Variable Documentation

struct dlr_storage* handles = NULL
static

Definition at line 97 of file dlr.c.

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