Kannel: Open Source WAP and SMS gateway  svn-r5335
dlr_spool.c File Reference
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <dirent.h>
#include <errno.h>
#include "gwlib/gwlib.h"
#include "dlr_p.h"
#include "sms.h"
#include "bb_store.h"

Go to the source code of this file.

Macros

#define MD5_DIGEST_LEN   32
 
#define SHA1_DIGEST_LEN   40
 
#define OUR_DIGEST_LEN   MD5_DIGEST_LEN
 
#define MAX_DIRS   100
 
#define MAP(to, from)
 
#define MAP(to, from)
 

Functions

static Octstrour_hash_func (Octstr *os)
 
static int non_verified_file (const char *filename, const struct stat *sb, int tflag, void *ftwbuf)
 
static int unlink_file (const char *filename, const struct stat *sb, int tflag, void *ftwbuf)
 
static int for_each_file (const Octstr *dir_s, int ignore_err, int(*cb)(const char *, const struct stat *, int, void *))
 
static Octstrget_msg_filename (const Octstr *dir_s, const Octstr *hash, const Octstr *dst)
 
static Octstrget_msg_surrogate (const Octstr *dir_s, const Octstr *hash, const Octstr *dst, Octstr **filename)
 
static void dlr_spool_add (struct dlr_entry *dlr)
 
static struct dlr_entrydlr_spool_get (const Octstr *smsc, const Octstr *ts, const Octstr *dst)
 
static void dlr_spool_remove (const Octstr *smsc, const Octstr *ts, const Octstr *dst)
 
static void dlr_spool_shutdown ()
 
static long dlr_spool_messages (void)
 
static void dlr_spool_flush (void)
 
struct dlr_storagedlr_init_spool (Cfg *cfg)
 

Variables

static Octstrspool_dir = NULL
 
static Countercounter
 
static struct dlr_storage handles
 

Macro Definition Documentation

◆ MAP [1/2]

#define MAP (   to,
  from 
)
Value:
to = from; \
from = NULL;
static Octstr * from
Definition: mtbatch.c:95

Referenced by dlr_spool_add(), and dlr_spool_get().

◆ MAP [2/2]

#define MAP (   to,
  from 
)
Value:
to = from; \
from = NULL;
static Octstr * from
Definition: mtbatch.c:95

◆ MAX_DIRS

#define MAX_DIRS   100

Definition at line 93 of file dlr_spool.c.

Referenced by dlr_spool_add(), dlr_spool_get(), and dlr_spool_remove().

◆ MD5_DIGEST_LEN

#define MD5_DIGEST_LEN   32

Definition at line 84 of file dlr_spool.c.

◆ OUR_DIGEST_LEN

#define OUR_DIGEST_LEN   MD5_DIGEST_LEN

Definition at line 89 of file dlr_spool.c.

Referenced by get_msg_filename().

◆ SHA1_DIGEST_LEN

#define SHA1_DIGEST_LEN   40

Definition at line 85 of file dlr_spool.c.

Function Documentation

◆ dlr_init_spool()

struct dlr_storage* dlr_init_spool ( Cfg cfg)

Definition at line 602 of file dlr_spool.c.

References cfg, cfg_get, cfg_get_single_group(), counter, counter_create(), for_each_file(), handles, non_verified_file(), octstr_imm(), panic, and spool_dir.

Referenced by dlr_init().

603 {
604  CfgGroup *grp;
605 
606  if (!(grp = cfg_get_single_group(cfg, octstr_imm("core"))))
607  panic(0, "DLR: spool: group 'core' is not specified!");
608 
609  if (!(spool_dir = cfg_get(grp, octstr_imm("dlr-spool"))))
610  panic(0, "DLR: spool: directive 'dlr-spool' is not specified!");
611 
612 #ifdef HAVE_LIBSSL
613  OpenSSL_add_all_digests();
614 #endif
615 
617 
618  /* we need to traverse the DLR spool to determine how
619  * many entries we have. */
620 #ifdef VERIFIED
621  for_each_file(spool_dir, 1, verified_file);
622 #else
624 #endif
625 
626  return &handles;
627 }
static Octstr * spool_dir
Definition: dlr_spool.c:107
static Counter * counter
Definition: dlr_spool.c:112
#define cfg_get(grp, varname)
Definition: cfg.h:86
static Cfg * cfg
Definition: opensmppbox.c:95
static int for_each_file(const Octstr *dir_s, int ignore_err, int(*cb)(const char *, const struct stat *, int, void *))
Definition: dlr_spool.c:252
static struct dlr_storage handles
Definition: dlr_spool.c:588
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:283
Counter * counter_create(void)
Definition: counter.c:94
#define panic
Definition: log.h:87
Definition: cfg.c:73
CfgGroup * cfg_get_single_group(Cfg *cfg, Octstr *name)
Definition: cfg.c:639
static int non_verified_file(const char *filename, const struct stat *sb, int tflag, void *ftwbuf)
Definition: dlr_spool.c:204

◆ dlr_spool_add()

static void dlr_spool_add ( struct dlr_entry dlr)
static

Definition at line 369 of file dlr_spool.c.

References dlr_entry::boxc_id, counter, counter_increase(), dlr_entry::destination, dlr_entry_destroy(), error(), filename, MAP, dlr_entry::mask, MAX_DIRS, msg, msg_create, msg_destroy(), octstr_append(), octstr_binary_to_hex(), octstr_destroy(), octstr_duplicate, octstr_format(), octstr_get_cstr, octstr_hash_key(), octstr_len(), our_hash_func(), report_mt, dlr_entry::service, dlr_entry::smsc, dlr_entry::source, spool_dir, store_msg_pack, dlr_entry::timestamp, and dlr_entry::url.

370 {
371  Msg *msg;
372  Octstr *os, *hash, *dir, *filename;
373  int fd;
374  size_t wrc;
375 
376 #define MAP(to, from) \
377  to = from; \
378  from = NULL;
379 
380  /* create a common message structure to contain our values */
381  msg = msg_create(sms);
382  msg->sms.sms_type = report_mt;
383  MAP(msg->sms.smsc_id, dlr->smsc);
384  MAP(msg->sms.foreign_id, dlr->timestamp);
385  MAP(msg->sms.sender, dlr->source);
386  MAP(msg->sms.receiver, dlr->destination);
387  MAP(msg->sms.service, dlr->service);
388  MAP(msg->sms.dlr_url, dlr->url);
389  MAP(msg->sms.boxc_id, dlr->boxc_id);
390  msg->sms.dlr_mask = dlr->mask;
391 
392  /* we got all values, destroy the structure now */
393  dlr_entry_destroy(dlr);
394 
395  /* create hash value */
396  os = octstr_duplicate(msg->sms.smsc_id);
397  octstr_append(os, msg->sms.foreign_id);
398  hash = our_hash_func(os);
399  octstr_destroy(os);
400 
401  /* target directory */
402  dir = octstr_format("%S/%ld", spool_dir, octstr_hash_key(hash) % MAX_DIRS);
403  if (mkdir(octstr_get_cstr(dir), S_IRUSR|S_IWUSR|S_IXUSR) == -1 && errno != EEXIST) {
404  error(errno, "Could not create directory `%s'.", octstr_get_cstr(dir));
405  octstr_destroy(dir);
406  octstr_destroy(hash);
407  msg_destroy(msg);
408  return;
409  }
410 
411  /*
412  * Now also add the hex value of the destination.
413  * This will be the part we look later into while
414  * DLR resolving.
415  */
416  os = octstr_duplicate(msg->sms.receiver);
417  octstr_binary_to_hex(os, 0);
418  octstr_append(hash, os);
419  octstr_destroy(os);
420 
421  /* target file */
422  filename = octstr_format("%S/%S", dir, hash);
423  octstr_destroy(dir);
424  octstr_destroy(hash);
425  if ((fd = open(octstr_get_cstr(filename), O_CREAT|O_EXCL|O_WRONLY, S_IRUSR|S_IWUSR)) == -1) {
426  error(errno, "Could not open file `%s'.", octstr_get_cstr(filename));
428  msg_destroy(msg);
429  return;
430  }
431 
432  /* pack and write content to file */
433  os = store_msg_pack(msg);
434  msg_destroy(msg);
435  for (wrc = 0; wrc < octstr_len(os); ) {
436  size_t rc = write(fd, octstr_get_cstr(os) + wrc, octstr_len(os) - wrc);
437  if (rc == -1) {
438  /* remove file */
439  error(errno, "Could not write DLR message to `%s'.", octstr_get_cstr(filename));
440  close(fd);
441  if (unlink(octstr_get_cstr(filename)) == -1)
442  error(errno, "Oops, Could not remove failed file `%s'.", octstr_get_cstr(filename));
443  octstr_destroy(os);
445  return;
446  }
447  wrc += rc;
448  }
449  close(fd);
452  octstr_destroy(os);
453 }
void error(int err, const char *fmt,...)
Definition: log.c:648
Octstr * url
Definition: dlr_p.h:84
static Octstr * spool_dir
Definition: dlr_spool.c:107
Octstr * service
Definition: dlr_p.h:83
static Octstr * our_hash_func(Octstr *os)
Definition: dlr_spool.c:123
void octstr_append(Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:1504
Octstr * boxc_id
Definition: dlr_p.h:85
static Counter * counter
Definition: dlr_spool.c:112
#define msg_create(type)
Definition: msg.h:136
Definition: msg.h:110
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
void octstr_binary_to_hex(Octstr *ostr, int uppercase)
Definition: octstr.c:465
unsigned long counter_increase(Counter *counter)
Definition: counter.c:123
Definition: msg.h:79
Octstr * source
Definition: dlr_p.h:81
#define octstr_duplicate(ostr)
Definition: octstr.h:187
void msg_destroy(Msg *msg)
Definition: msg.c:132
#define MAX_DIRS
Definition: dlr_spool.c:93
Octstr * timestamp
Definition: dlr_p.h:80
unsigned long octstr_hash_key(Octstr *ostr)
Definition: octstr.c:2523
Octstr * octstr_format(const char *fmt,...)
Definition: octstr.c:2464
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
char filename[FILENAME_MAX+1]
Definition: log.c:171
Octstr *(* store_msg_pack)(Msg *msg)
Definition: bb_store.c:77
long octstr_len(const Octstr *ostr)
Definition: octstr.c:342
Octstr * destination
Definition: dlr_p.h:82
Definition: octstr.c:118
#define MAP(to, from)
void dlr_entry_destroy(struct dlr_entry *dlr)
Definition: dlr.c:142
Octstr * smsc
Definition: dlr_p.h:79
int mask
Definition: dlr_p.h:86
static XMLRPCDocument * msg
Definition: test_xmlrpc.c:86

◆ dlr_spool_flush()

static void dlr_spool_flush ( void  )
static

Definition at line 577 of file dlr_spool.c.

References counter, counter_set(), for_each_file(), spool_dir, and unlink_file().

578 {
580  counter_set(counter, 0);
581 }
static Octstr * spool_dir
Definition: dlr_spool.c:107
static Counter * counter
Definition: dlr_spool.c:112
unsigned long counter_set(Counter *counter, unsigned long n)
Definition: counter.c:167
static int for_each_file(const Octstr *dir_s, int ignore_err, int(*cb)(const char *, const struct stat *, int, void *))
Definition: dlr_spool.c:252
static int unlink_file(const char *filename, const struct stat *sb, int tflag, void *ftwbuf)
Definition: dlr_spool.c:224

◆ dlr_spool_get()

static struct dlr_entry* dlr_spool_get ( const Octstr smsc,
const Octstr ts,
const Octstr dst 
)
static

Definition at line 459 of file dlr_spool.c.

References dlr_entry::boxc_id, dlr_entry::destination, dlr_entry_create(), error(), filename, get_msg_surrogate(), MAP, dlr_entry::mask, MAX_DIRS, msg, msg_destroy(), octstr_append(), octstr_destroy(), octstr_duplicate, octstr_format(), octstr_get_cstr, octstr_hash_key(), our_hash_func(), dlr_entry::service, dlr_entry::smsc, dlr_entry::source, spool_dir, store_msg_unpack, dlr_entry::timestamp, and dlr_entry::url.

460 {
461  struct dlr_entry *ret = NULL;
462  Octstr *os, *hash, *dir, *filename = NULL;
463  Msg *msg;
464 
465  /* determine target dir and filename via hash */
466  os = octstr_duplicate(smsc);
467  octstr_append(os, ts);
468  hash = our_hash_func(os);
469  octstr_destroy(os);
470 
471  /* determine target dir */
472  dir = octstr_format("%S/%ld", spool_dir, octstr_hash_key(hash) % MAX_DIRS);
473 
474  /* get content of msg surrogate */
475  os = get_msg_surrogate(dir, hash, dst, &filename);
476  octstr_destroy(dir);
477  octstr_destroy(hash);
478 
479  /* if there was no content */
480  if (os == NULL) {
482  return NULL;
483  }
484 
485  /* unpack */
486  if ((msg = store_msg_unpack(os)) == NULL) {
487  octstr_destroy(os);
488  error(0, "Could not unpack DLR message `%s'", octstr_get_cstr(filename));
490  return ret;
491  }
492 
493  octstr_destroy(os);
495 
496 #define MAP(to, from) \
497  to = from; \
498  from = NULL;
499 
500  /* map values to a struct dlr_entry */
501  ret = dlr_entry_create();
502  MAP(ret->smsc, msg->sms.smsc_id);
503  MAP(ret->timestamp, msg->sms.foreign_id);
504  MAP(ret->source, msg->sms.sender);
505  MAP(ret->destination, msg->sms.receiver);
506  MAP(ret->service, msg->sms.service);
507  MAP(ret->url, msg->sms.dlr_url);
508  MAP(ret->boxc_id, msg->sms.boxc_id);
509  ret->mask = msg->sms.dlr_mask;
510 
511  msg_destroy(msg);
512 
513  return ret;
514 }
void error(int err, const char *fmt,...)
Definition: log.c:648
Octstr * url
Definition: dlr_p.h:84
static Octstr * spool_dir
Definition: dlr_spool.c:107
Octstr * service
Definition: dlr_p.h:83
static Octstr * our_hash_func(Octstr *os)
Definition: dlr_spool.c:123
void octstr_append(Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:1504
struct dlr_entry * dlr_entry_create(void)
Definition: dlr.c:103
Octstr * boxc_id
Definition: dlr_p.h:85
Msg *(* store_msg_unpack)(Octstr *os)
Definition: bb_store.c:78
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
Definition: msg.h:79
static Octstr * get_msg_surrogate(const Octstr *dir_s, const Octstr *hash, const Octstr *dst, Octstr **filename)
Definition: dlr_spool.c:351
Octstr * source
Definition: dlr_p.h:81
#define octstr_duplicate(ostr)
Definition: octstr.h:187
void msg_destroy(Msg *msg)
Definition: msg.c:132
#define MAX_DIRS
Definition: dlr_spool.c:93
Octstr * timestamp
Definition: dlr_p.h:80
unsigned long octstr_hash_key(Octstr *ostr)
Definition: octstr.c:2523
Octstr * octstr_format(const char *fmt,...)
Definition: octstr.c:2464
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
char filename[FILENAME_MAX+1]
Definition: log.c:171
Octstr * destination
Definition: dlr_p.h:82
Definition: octstr.c:118
#define MAP(to, from)
Definition: dlr_p.h:78
Octstr * smsc
Definition: dlr_p.h:79
int mask
Definition: dlr_p.h:86
static XMLRPCDocument * msg
Definition: test_xmlrpc.c:86

◆ dlr_spool_messages()

static long dlr_spool_messages ( void  )
static

Definition at line 568 of file dlr_spool.c.

References counter, and counter_value().

569 {
570  return counter_value(counter);
571 }
static Counter * counter
Definition: dlr_spool.c:112
unsigned long counter_value(Counter *counter)
Definition: counter.c:145

◆ dlr_spool_remove()

static void dlr_spool_remove ( const Octstr smsc,
const Octstr ts,
const Octstr dst 
)
static

Definition at line 520 of file dlr_spool.c.

References counter, counter_decrease(), error(), filename, get_msg_filename(), MAX_DIRS, octstr_append(), octstr_destroy(), octstr_duplicate, octstr_format(), octstr_get_cstr, octstr_hash_key(), our_hash_func(), dlr_entry::smsc, and spool_dir.

521 {
522  Octstr *os, *hash, *dir, *filename;
523 
524  /* determine target dir and filename via hash */
525  os = octstr_duplicate(smsc);
526  octstr_append(os, ts);
527  hash = our_hash_func(os);
528  octstr_destroy(os);
529 
530  /* determine target dir */
531  dir = octstr_format("%S/%ld", spool_dir, octstr_hash_key(hash) % MAX_DIRS);
532 
533  /* get msg surrogate filename */
534  filename = get_msg_filename(dir, hash, dst);
535  octstr_destroy(dir);
536  octstr_destroy(hash);
537 
538  /* if there was no filename, then we didn't find it */
539  if (filename == NULL) {
540  return;
541  }
542 
543  /* remove the file from the file system */
544  if (unlink(octstr_get_cstr(filename)) == -1) {
545  error(errno, "Could not unlink file `%s'.", octstr_get_cstr(filename));
547  return;
548  }
549 
552 }
void error(int err, const char *fmt,...)
Definition: log.c:648
static Octstr * spool_dir
Definition: dlr_spool.c:107
static Octstr * our_hash_func(Octstr *os)
Definition: dlr_spool.c:123
void octstr_append(Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:1504
static Counter * counter
Definition: dlr_spool.c:112
unsigned long counter_decrease(Counter *counter)
Definition: counter.c:155
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
#define octstr_duplicate(ostr)
Definition: octstr.h:187
#define MAX_DIRS
Definition: dlr_spool.c:93
unsigned long octstr_hash_key(Octstr *ostr)
Definition: octstr.c:2523
Octstr * octstr_format(const char *fmt,...)
Definition: octstr.c:2464
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
char filename[FILENAME_MAX+1]
Definition: log.c:171
Definition: octstr.c:118
static Octstr * get_msg_filename(const Octstr *dir_s, const Octstr *hash, const Octstr *dst)
Definition: dlr_spool.c:300
Octstr * smsc
Definition: dlr_p.h:79

◆ dlr_spool_shutdown()

static void dlr_spool_shutdown ( )
static

Definition at line 558 of file dlr_spool.c.

References counter, counter_destroy(), octstr_destroy(), and spool_dir.

559 {
562 }
static Octstr * spool_dir
Definition: dlr_spool.c:107
void counter_destroy(Counter *counter)
Definition: counter.c:110
static Counter * counter
Definition: dlr_spool.c:112
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324

◆ for_each_file()

static int for_each_file ( const Octstr dir_s,
int  ignore_err,
int(*)(const char *, const struct stat *, int, void *)  cb 
)
static

Definition at line 252 of file dlr_spool.c.

References error(), filename, octstr_destroy(), octstr_format(), and octstr_get_cstr.

Referenced by dlr_init_spool(), and dlr_spool_flush().

254 {
255  DIR *dir;
256  struct dirent *ent;
257  int ret = 0;
258 #ifndef _DIRENT_HAVE_D_TYPE
259  struct stat stat;
260 #endif
261 
262  if ((dir = opendir(octstr_get_cstr(dir_s))) == NULL) {
263  error(errno, "Could not open directory `%s'", octstr_get_cstr(dir_s));
264  return -1;
265  }
266  while ((ent = readdir(dir)) != NULL) {
267  Octstr *filename;
268  if (!(strcmp((char*)ent->d_name, "." ) != 0 && strcmp((char*)ent->d_name, ".." ) != 0))
269  continue;
270  filename = octstr_format("%S/%s", dir_s, ent->d_name);
271 #ifdef _DIRENT_HAVE_D_TYPE
272  if (ent->d_type == DT_DIR && for_each_file(filename, ignore_err, cb) == -1) {
273  ret = -1;
274  } else if (ent->d_type == DT_REG && cb != NULL) {
275  cb(octstr_get_cstr(filename), NULL, 0, NULL);
276  }
277 #else
278  if (lstat(octstr_get_cstr(filename), &stat) == -1) {
279  if (!ignore_err)
280  error(errno, "Could not get stat for `%s'", octstr_get_cstr(filename));
281  ret = -1;
282  } else if (S_ISDIR(stat.st_mode) && for_each_file(filename, ignore_err, cb) == -1) {
283  ret = -1;
284  } else if (S_ISREG(stat.st_mode) && cb != NULL)
285  cb(octstr_get_cstr(filename), &stat, 0, NULL);
286 #endif
288  if (ret == -1 && ignore_err)
289  ret = 0;
290  else if (ret == -1)
291  break;
292  }
293  closedir(dir);
294 
295  return ret;
296 }
void error(int err, const char *fmt,...)
Definition: log.c:648
static int for_each_file(const Octstr *dir_s, int ignore_err, int(*cb)(const char *, const struct stat *, int, void *))
Definition: dlr_spool.c:252
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
Octstr * octstr_format(const char *fmt,...)
Definition: octstr.c:2464
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
char filename[FILENAME_MAX+1]
Definition: log.c:171
Definition: octstr.c:118

◆ get_msg_filename()

static Octstr* get_msg_filename ( const Octstr dir_s,
const Octstr hash,
const Octstr dst 
)
static

Definition at line 300 of file dlr_spool.c.

References error(), found, octstr_copy, octstr_create, octstr_destroy(), octstr_format(), octstr_get_cstr, octstr_len(), octstr_ncompare(), octstr_search(), and OUR_DIGEST_LEN.

Referenced by dlr_spool_remove(), and get_msg_surrogate().

301 {
302  Octstr *ret;
303  DIR *dir;
304  struct dirent *ent;
305 
306  if ((dir = opendir(octstr_get_cstr(dir_s))) == NULL) {
307  error(errno, "Could not open directory `%s'", octstr_get_cstr(dir_s));
308  return NULL;
309  }
310 
311  while ((ent = readdir(dir)) != NULL) {
312  Octstr *fname = octstr_create((char*)ent->d_name);
313 
314  if (octstr_ncompare(fname, hash, OUR_DIGEST_LEN) == 0) {
315  Octstr *addr;
316  long addr_len, pos;
317 
318  /* this is a candidate */
319  if (dst == NULL)
320  goto found;
321 
322  /* check for the destination address suffix part */
323  if ((addr_len = (octstr_len(fname) - OUR_DIGEST_LEN)) < 0 ||
324  (pos = (addr_len - octstr_len(dst))) < 0) {
325  octstr_destroy(fname);
326  continue;
327  }
328  addr = octstr_copy(fname, OUR_DIGEST_LEN, addr_len);
329 
330  /* if not found, then bail out*/
331  if (octstr_search(addr, dst, pos) == -1) {
332  octstr_destroy(addr);
333  octstr_destroy(fname);
334  continue;
335  }
336  octstr_destroy(addr);
337 found:
338  /* found it */
339  closedir(dir);
340  ret = octstr_format("%S/%S", dir_s, fname);
341  octstr_destroy(fname);
342  return ret;
343  }
344  octstr_destroy(fname);
345  }
346  closedir(dir);
347 
348  return NULL;
349 }
void error(int err, const char *fmt,...)
Definition: log.c:648
long octstr_search(const Octstr *haystack, const Octstr *needle, long pos)
Definition: octstr.c:1070
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
#define octstr_copy(ostr, from, len)
Definition: octstr.h:178
static struct pid_list * found
int octstr_ncompare(const Octstr *ostr1, const Octstr *ostr2, long n)
Definition: octstr.c:952
Octstr * octstr_format(const char *fmt,...)
Definition: octstr.c:2464
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
#define octstr_create(cstr)
Definition: octstr.h:125
long octstr_len(const Octstr *ostr)
Definition: octstr.c:342
Definition: octstr.c:118
#define OUR_DIGEST_LEN
Definition: dlr_spool.c:89

◆ get_msg_surrogate()

static Octstr* get_msg_surrogate ( const Octstr dir_s,
const Octstr hash,
const Octstr dst,
Octstr **  filename 
)
static

Definition at line 351 of file dlr_spool.c.

References filename, get_msg_filename(), octstr_get_cstr, and octstr_read_file().

Referenced by dlr_spool_get().

353 {
354  /* get our msg filename */
355  if ((*filename = get_msg_filename(dir_s, hash, dst)) == NULL)
356  return NULL;
357 
359 }
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
char filename[FILENAME_MAX+1]
Definition: log.c:171
Octstr * octstr_read_file(const char *filename)
Definition: octstr.c:1548
static Octstr * get_msg_filename(const Octstr *dir_s, const Octstr *hash, const Octstr *dst)
Definition: dlr_spool.c:300

◆ non_verified_file()

static int non_verified_file ( const char *  filename,
const struct stat *  sb,
int  tflag,
void *  ftwbuf 
)
static

Definition at line 204 of file dlr_spool.c.

References counter, and counter_increase().

Referenced by dlr_init_spool().

205 {
206 #endif
207 
209 
210  return 0;
211 }
static Counter * counter
Definition: dlr_spool.c:112
unsigned long counter_increase(Counter *counter)
Definition: counter.c:123

◆ our_hash_func()

static Octstr* our_hash_func ( Octstr os)
static

Definition at line 123 of file dlr_spool.c.

References md5digest(), octstr_binary_to_hex(), octstr_create_from_data, octstr_get_cstr, and octstr_len().

Referenced by dlr_spool_add(), dlr_spool_get(), dlr_spool_remove(), and main().

124 {
125 #ifdef HAVE_LIBSSL
126  /* use openssl's SHA1 */
127  unsigned char hash[20];
128  Octstr *ret;
129 
130  memset(hash, 0, sizeof(hash));
131 
132  SHA1((const unsigned char *)octstr_get_cstr(os), octstr_len(os), hash);
133 
134  ret = octstr_create_from_data((const char*)hash, sizeof(hash));
135  octstr_binary_to_hex(ret, 0);
136  return ret;
137 #else
138  /* fallback to our own MD5 if we don't have openssl available */
139  return md5digest(os);
140 #endif
141 }
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
void octstr_binary_to_hex(Octstr *ostr, int uppercase)
Definition: octstr.c:465
long octstr_len(const Octstr *ostr)
Definition: octstr.c:342
Definition: octstr.c:118
#define octstr_create_from_data(data, len)
Definition: octstr.h:134
Octstr * md5digest(Octstr *data)
Definition: md5.c:406

◆ unlink_file()

static int unlink_file ( const char *  filename,
const struct stat *  sb,
int  tflag,
void *  ftwbuf 
)
static

Definition at line 224 of file dlr_spool.c.

References error(), and filename.

Referenced by dlr_spool_flush().

225 {
226 #endif
227 
228  /* remove the file from the file system */
229  if (unlink(filename) == -1) {
230  error(errno, "Could not unlink file `%s'.", filename);
231  }
232 
233  return 0;
234 }
void error(int err, const char *fmt,...)
Definition: log.c:648
char filename[FILENAME_MAX+1]
Definition: log.c:171

Variable Documentation

◆ counter

◆ handles

struct dlr_storage handles
static
Initial value:
= {
.type = "spool",
.dlr_add = dlr_spool_add,
.dlr_get = dlr_spool_get,
.dlr_remove = dlr_spool_remove,
.dlr_shutdown = dlr_spool_shutdown,
.dlr_messages = dlr_spool_messages,
.dlr_flush = dlr_spool_flush
}
static void dlr_spool_shutdown()
Definition: dlr_spool.c:558
static void dlr_spool_flush(void)
Definition: dlr_spool.c:577
static long dlr_spool_messages(void)
Definition: dlr_spool.c:568
static void dlr_spool_remove(const Octstr *smsc, const Octstr *ts, const Octstr *dst)
Definition: dlr_spool.c:520
static void dlr_spool_add(struct dlr_entry *dlr)
Definition: dlr_spool.c:369
static struct dlr_entry * dlr_spool_get(const Octstr *smsc, const Octstr *ts, const Octstr *dst)
Definition: dlr_spool.c:459

Definition at line 588 of file dlr_spool.c.

Referenced by dlr_init_spool().

◆ spool_dir

Octstr* spool_dir = NULL
static
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.