Kannel: Open Source WAP and SMS gateway  $Revision: 5037 $
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

#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().

#define MAP (   to,
  from 
)
Value:
to = from; \
from = NULL;
static Octstr * from
Definition: mtbatch.c:95
#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().

#define MD5_DIGEST_LEN   32

Definition at line 84 of file dlr_spool.c.

#define OUR_DIGEST_LEN   MD5_DIGEST_LEN

Definition at line 89 of file dlr_spool.c.

Referenced by get_msg_filename().

#define SHA1_DIGEST_LEN   40

Definition at line 85 of file dlr_spool.c.

Function Documentation

struct dlr_storage* dlr_init_spool ( Cfg cfg)

Definition at line 607 of file dlr_spool.c.

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

Referenced by dlr_init().

608 {
609  CfgGroup *grp;
610 
611  if (!(grp = cfg_get_single_group(cfg, octstr_imm("core"))))
612  panic(0, "DLR: spool: group 'core' is not specified!");
613 
614  if (!(spool_dir = cfg_get(grp, octstr_imm("dlr-spool"))))
615  panic(0, "DLR: spool: directive 'dlr-spool' is not specified!");
616 
617 #ifdef HAVE_LIBSSL
618  OpenSSL_add_all_digests();
619 #endif
620 
622 
623  /* we need to traverse the DLR spool to determine how
624  * many entries we have. */
625 #ifdef VERIFIED
626  for_each_file(spool_dir, 1, verified_file);
627 #else
629 #endif
630 
631  return &handles;
632 }
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 int for_each_file(const Octstr *dir_s, int ignore_err, int(*cb)(const char *, const struct stat *, int, void *))
Definition: dlr_spool.c:259
static struct dlr_storage handles
Definition: dlr_spool.c:593
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:281
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:636
static int non_verified_file(const char *filename, const struct stat *sb, int tflag, void *ftwbuf)
Definition: dlr_spool.c:211
static void dlr_spool_add ( struct dlr_entry dlr)
static

Definition at line 376 of file dlr_spool.c.

References dlr_entry::boxc_id, 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, store_msg_pack, dlr_entry::timestamp, and dlr_entry::url.

377 {
378  Msg *msg;
379  Octstr *os, *hash, *dir, *filename;
380  int fd;
381  size_t wrc;
382 
383 #define MAP(to, from) \
384  to = from; \
385  from = NULL;
386 
387  /* create a common message structure to contain our values */
388  msg = msg_create(sms);
389  msg->sms.sms_type = report_mt;
390  MAP(msg->sms.smsc_id, dlr->smsc);
391  MAP(msg->sms.foreign_id, dlr->timestamp);
392  MAP(msg->sms.sender, dlr->source);
393  MAP(msg->sms.receiver, dlr->destination);
394  MAP(msg->sms.service, dlr->service);
395  MAP(msg->sms.dlr_url, dlr->url);
396  MAP(msg->sms.boxc_id, dlr->boxc_id);
397  msg->sms.dlr_mask = dlr->mask;
398 
399  /* we got all values, destroy the structure now */
400  dlr_entry_destroy(dlr);
401 
402  /* create hash value */
403  os = octstr_duplicate(msg->sms.smsc_id);
404  octstr_append(os, msg->sms.foreign_id);
405  hash = our_hash_func(os);
406  octstr_destroy(os);
407 
408  /* target directory */
409  dir = octstr_format("%S/%ld", spool_dir, octstr_hash_key(hash) % MAX_DIRS);
410  if (mkdir(octstr_get_cstr(dir), S_IRUSR|S_IWUSR|S_IXUSR) == -1 && errno != EEXIST) {
411  error(errno, "Could not create directory `%s'.", octstr_get_cstr(dir));
412  octstr_destroy(dir);
413  octstr_destroy(hash);
414  return;
415  }
416 
417  /*
418  * Now also add the hex value of the destination.
419  * This will be the part we look later into while
420  * DLR resolving.
421  */
422  os = octstr_duplicate(msg->sms.receiver);
423  octstr_binary_to_hex(os, 0);
424  octstr_append(hash, os);
425  octstr_destroy(os);
426 
427  /* target file */
428  filename = octstr_format("%S/%S", dir, hash);
429  octstr_destroy(dir);
430  octstr_destroy(hash);
431  if ((fd = open(octstr_get_cstr(filename), O_CREAT|O_EXCL|O_WRONLY, S_IRUSR|S_IWUSR)) == -1) {
432  error(errno, "Could not open file `%s'.", octstr_get_cstr(filename));
433  octstr_destroy(filename);
434  return;
435  }
436 
437  /* pack and write content to file */
438  os = store_msg_pack(msg);
439  msg_destroy(msg);
440  for (wrc = 0; wrc < octstr_len(os); ) {
441  size_t rc = write(fd, octstr_get_cstr(os) + wrc, octstr_len(os) - wrc);
442  if (rc == -1) {
443  /* remove file */
444  error(errno, "Could not write DLR message to `%s'.", octstr_get_cstr(filename));
445  close(fd);
446  if (unlink(octstr_get_cstr(filename)) == -1)
447  error(errno, "Oops, Could not remove failed file `%s'.", octstr_get_cstr(filename));
448  octstr_destroy(os);
449  octstr_destroy(filename);
450  return;
451  }
452  wrc += rc;
453  }
454  close(fd);
456  octstr_destroy(filename);
457  octstr_destroy(os);
458 }
void error(int err, const char *fmt,...)
Definition: log.c:612
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:1502
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:463
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:2521
Octstr * octstr_format(const char *fmt,...)
Definition: octstr.c:2462
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:322
char filename[FILENAME_MAX+1]
Definition: log.c:135
Octstr *(* store_msg_pack)(Msg *msg)
Definition: bb_store.c:77
long octstr_len(const Octstr *ostr)
Definition: octstr.c:340
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
static void dlr_spool_flush ( void  )
static

Definition at line 582 of file dlr_spool.c.

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

583 {
585  counter_set(counter, 0);
586 }
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:259
static int unlink_file(const char *filename, const struct stat *sb, int tflag, void *ftwbuf)
Definition: dlr_spool.c:231
static struct dlr_entry* dlr_spool_get ( const Octstr smsc,
const Octstr ts,
const Octstr dst 
)
static

Definition at line 464 of file dlr_spool.c.

References dlr_entry::boxc_id, dlr_entry::destination, dlr_entry_create(), error(), 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, store_msg_unpack, dlr_entry::timestamp, and dlr_entry::url.

465 {
466  struct dlr_entry *ret = NULL;
467  Octstr *os, *hash, *dir, *filename = NULL;
468  Msg *msg;
469 
470  /* determine target dir and filename via hash */
471  os = octstr_duplicate(smsc);
472  octstr_append(os, ts);
473  hash = our_hash_func(os);
474  octstr_destroy(os);
475 
476  /* determine target dir */
477  dir = octstr_format("%S/%ld", spool_dir, octstr_hash_key(hash) % MAX_DIRS);
478 
479  /* get content of msg surrogate */
480  os = get_msg_surrogate(dir, hash, dst, &filename);
481  octstr_destroy(dir);
482  octstr_destroy(hash);
483 
484  /* if there was no content */
485  if (os == NULL) {
486  octstr_destroy(filename);
487  return NULL;
488  }
489 
490  /* unpack */
491  if ((msg = store_msg_unpack(os)) == NULL) {
492  octstr_destroy(os);
493  error(0, "Could not unpack DLR message `%s'", octstr_get_cstr(filename));
494  octstr_destroy(filename);
495  return ret;
496  }
497 
498  octstr_destroy(os);
499  octstr_destroy(filename);
500 
501 #define MAP(to, from) \
502  to = from; \
503  from = NULL;
504 
505  /* map values to a struct dlr_entry */
506  ret = dlr_entry_create();
507  MAP(ret->smsc, msg->sms.smsc_id);
508  MAP(ret->timestamp, msg->sms.foreign_id);
509  MAP(ret->source, msg->sms.sender);
510  MAP(ret->destination, msg->sms.receiver);
511  MAP(ret->service, msg->sms.service);
512  MAP(ret->url, msg->sms.dlr_url);
513  MAP(ret->boxc_id, msg->sms.boxc_id);
514  ret->mask = msg->sms.dlr_mask;
515 
516  msg_destroy(msg);
517 
518  return ret;
519 }
void error(int err, const char *fmt,...)
Definition: log.c:612
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:1502
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:358
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:2521
Octstr * octstr_format(const char *fmt,...)
Definition: octstr.c:2462
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:322
char filename[FILENAME_MAX+1]
Definition: log.c:135
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
static long dlr_spool_messages ( void  )
static

Definition at line 573 of file dlr_spool.c.

References counter_value().

574 {
575  return counter_value(counter);
576 }
static Counter * counter
Definition: dlr_spool.c:112
unsigned long counter_value(Counter *counter)
Definition: counter.c:145
static void dlr_spool_remove ( const Octstr smsc,
const Octstr ts,
const Octstr dst 
)
static

Definition at line 525 of file dlr_spool.c.

References counter_decrease(), error(), filename, get_msg_filename(), MAX_DIRS, octstr_append(), octstr_destroy(), octstr_duplicate, octstr_format(), octstr_get_cstr, octstr_hash_key(), and our_hash_func().

526 {
527  Octstr *os, *hash, *dir, *filename;
528 
529  /* determine target dir and filename via hash */
530  os = octstr_duplicate(smsc);
531  octstr_append(os, ts);
532  hash = our_hash_func(os);
533  octstr_destroy(os);
534 
535  /* determine target dir */
536  dir = octstr_format("%S/%ld", spool_dir, octstr_hash_key(hash) % MAX_DIRS);
537 
538  /* get msg surrogate filename */
539  filename = get_msg_filename(dir, hash, dst);
540  octstr_destroy(dir);
541  octstr_destroy(hash);
542 
543  /* if there was no filename, then we didn't find it */
544  if (filename == NULL) {
545  return;
546  }
547 
548  /* remove the file from the file system */
549  if (unlink(octstr_get_cstr(filename)) == -1) {
550  error(errno, "Could not unlink file `%s'.", octstr_get_cstr(filename));
551  octstr_destroy(filename);
552  return;
553  }
554 
556  octstr_destroy(filename);
557 }
void error(int err, const char *fmt,...)
Definition: log.c:612
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:1502
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:2521
Octstr * octstr_format(const char *fmt,...)
Definition: octstr.c:2462
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:322
char filename[FILENAME_MAX+1]
Definition: log.c:135
Definition: octstr.c:118
static Octstr * get_msg_filename(const Octstr *dir_s, const Octstr *hash, const Octstr *dst)
Definition: dlr_spool.c:307
static void dlr_spool_shutdown ( )
static

Definition at line 563 of file dlr_spool.c.

References counter_destroy(), and octstr_destroy().

564 {
567 }
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:322
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 259 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().

261 {
262  DIR *dir;
263  struct dirent *ent;
264  int ret = 0;
265 #ifndef _DIRENT_HAVE_D_TYPE
266  struct stat stat;
267 #endif
268 
269  if ((dir = opendir(octstr_get_cstr(dir_s))) == NULL) {
270  error(errno, "Could not open directory `%s'", octstr_get_cstr(dir_s));
271  return -1;
272  }
273  while ((ent = readdir(dir)) != NULL) {
274  Octstr *filename;
275  if (!(strcmp((char*)ent->d_name, "." ) != 0 && strcmp((char*)ent->d_name, ".." ) != 0))
276  continue;
277  filename = octstr_format("%S/%s", dir_s, ent->d_name);
278 #ifdef _DIRENT_HAVE_D_TYPE
279  if (ent->d_type == DT_DIR && for_each_file(filename, ignore_err, cb) == -1) {
280  ret = -1;
281  } else if (ent->d_type == DT_REG && cb != NULL) {
282  cb(octstr_get_cstr(filename), NULL, 0, NULL);
283  }
284 #else
285  if (lstat(octstr_get_cstr(filename), &stat) == -1) {
286  if (!ignore_err)
287  error(errno, "Could not get stat for `%s'", octstr_get_cstr(filename));
288  ret = -1;
289  } else if (S_ISDIR(stat.st_mode) && for_each_file(filename, ignore_err, cb) == -1) {
290  ret = -1;
291  } else if (S_ISREG(stat.st_mode) && cb != NULL)
292  cb(octstr_get_cstr(filename), &stat, 0, NULL);
293 #endif
294  octstr_destroy(filename);
295  if (ret == -1 && ignore_err)
296  ret = 0;
297  else if (ret == -1)
298  break;
299  }
300  closedir(dir);
301 
302  return ret;
303 }
void error(int err, const char *fmt,...)
Definition: log.c:612
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:259
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
Octstr * octstr_format(const char *fmt,...)
Definition: octstr.c:2462
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:322
char filename[FILENAME_MAX+1]
Definition: log.c:135
Definition: octstr.c:118
static Octstr* get_msg_filename ( const Octstr dir_s,
const Octstr hash,
const Octstr dst 
)
static

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

308 {
309  Octstr *ret;
310  DIR *dir;
311  struct dirent *ent;
312 
313  if ((dir = opendir(octstr_get_cstr(dir_s))) == NULL) {
314  error(errno, "Could not open directory `%s'", octstr_get_cstr(dir_s));
315  return NULL;
316  }
317 
318  while ((ent = readdir(dir)) != NULL) {
319  Octstr *fname = octstr_create((char*)ent->d_name);
320 
321  if (octstr_ncompare(fname, hash, OUR_DIGEST_LEN) == 0) {
322  Octstr *addr;
323  long addr_len, pos;
324 
325  /* this is a candidate */
326  if (dst == NULL)
327  goto found;
328 
329  /* check for the destination address suffix part */
330  if ((addr_len = (octstr_len(fname) - OUR_DIGEST_LEN)) < 0 ||
331  (pos = (addr_len - octstr_len(dst))) < 0) {
332  octstr_destroy(fname);
333  continue;
334  }
335  addr = octstr_copy(fname, OUR_DIGEST_LEN, addr_len);
336 
337  /* if not found, then bail out*/
338  if (octstr_search(addr, dst, pos) == -1) {
339  octstr_destroy(addr);
340  octstr_destroy(fname);
341  continue;
342  }
343  octstr_destroy(addr);
344 found:
345  /* found it */
346  closedir(dir);
347  ret = octstr_format("%S/%S", dir_s, fname);
348  octstr_destroy(fname);
349  return ret;
350  }
351  octstr_destroy(fname);
352  }
353  closedir(dir);
354 
355  return NULL;
356 }
void error(int err, const char *fmt,...)
Definition: log.c:612
long octstr_search(const Octstr *haystack, const Octstr *needle, long pos)
Definition: octstr.c:1068
#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:950
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
Definition: octstr.c:118
#define OUR_DIGEST_LEN
Definition: dlr_spool.c:89
static Octstr* get_msg_surrogate ( const Octstr dir_s,
const Octstr hash,
const Octstr dst,
Octstr **  filename 
)
static

Definition at line 358 of file dlr_spool.c.

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

Referenced by dlr_spool_get().

360 {
361  /* get our msg filename */
362  if ((*filename = get_msg_filename(dir_s, hash, dst)) == NULL)
363  return NULL;
364 
365  return octstr_read_file(octstr_get_cstr(*filename));
366 }
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
Octstr * octstr_read_file(const char *filename)
Definition: octstr.c:1546
static Octstr * get_msg_filename(const Octstr *dir_s, const Octstr *hash, const Octstr *dst)
Definition: dlr_spool.c:307
static int non_verified_file ( const char *  filename,
const struct stat *  sb,
int  tflag,
void *  ftwbuf 
)
static

Definition at line 211 of file dlr_spool.c.

References counter_increase().

Referenced by dlr_init_spool().

212 {
213 #endif
214 
216 
217  return 0;
218 }
static Counter * counter
Definition: dlr_spool.c:112
unsigned long counter_increase(Counter *counter)
Definition: counter.c:123
static Octstr* our_hash_func ( Octstr os)
static

Definition at line 123 of file dlr_spool.c.

References EVP_MAX_MD_SIZE, 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  EVP_MD_CTX mdctx;
128  const EVP_MD *md;
129  unsigned char md_value[EVP_MAX_MD_SIZE];
130  unsigned int md_len;
131  Octstr *ret;
132 
133  md = EVP_get_digestbyname("sha1");
134 
135  EVP_MD_CTX_init(&mdctx);
136  EVP_DigestInit_ex(&mdctx, md, NULL);
137  EVP_DigestUpdate(&mdctx, octstr_get_cstr(os), octstr_len(os));
138  EVP_DigestFinal_ex(&mdctx, md_value, &md_len);
139  EVP_MD_CTX_cleanup(&mdctx);
140 
141  ret = octstr_create_from_data((char*) md_value, md_len);
142  octstr_binary_to_hex(ret, 0);
143  return ret;
144 #else
145  /* fallback to our own MD5 if we don't have openssl available */
146  return md5digest(os);
147 #endif
148 }
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
void octstr_binary_to_hex(Octstr *ostr, int uppercase)
Definition: octstr.c:463
long octstr_len(const Octstr *ostr)
Definition: octstr.c:340
Definition: octstr.c:118
#define EVP_MAX_MD_SIZE
Definition: test_hmac.c:82
#define octstr_create_from_data(data, len)
Definition: octstr.h:134
Octstr * md5digest(Octstr *data)
Definition: md5.c:406
static int unlink_file ( const char *  filename,
const struct stat *  sb,
int  tflag,
void *  ftwbuf 
)
static

Definition at line 231 of file dlr_spool.c.

References error().

Referenced by dlr_spool_flush().

232 {
233 #endif
234 
235  /* remove the file from the file system */
236  if (unlink(filename) == -1) {
237  error(errno, "Could not unlink file `%s'.", filename);
238  }
239 
240  return 0;
241 }
void error(int err, const char *fmt,...)
Definition: log.c:612
char filename[FILENAME_MAX+1]
Definition: log.c:135

Variable Documentation

Counter* counter
static

Definition at line 112 of file dlr_spool.c.

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:563
static void dlr_spool_flush(void)
Definition: dlr_spool.c:582
static long dlr_spool_messages(void)
Definition: dlr_spool.c:573
static void dlr_spool_remove(const Octstr *smsc, const Octstr *ts, const Octstr *dst)
Definition: dlr_spool.c:525
static void dlr_spool_add(struct dlr_entry *dlr)
Definition: dlr_spool.c:376
static struct dlr_entry * dlr_spool_get(const Octstr *smsc, const Octstr *ts, const Octstr *dst)
Definition: dlr_spool.c:464

Definition at line 593 of file dlr_spool.c.

Referenced by dlr_init_spool().

Octstr* spool_dir = NULL
static

Definition at line 107 of file dlr_spool.c.

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