Kannel: Open Source WAP and SMS gateway  svn-r5335
bb_store.h File Reference

Go to the source code of this file.

Macros

#define BB_STORE_DEFAULT_DUMP_FREQ   10
 

Functions

int store_init (Cfg *cfg, const Octstr *type, const Octstr *fname, long dump_freq, void *pack_func, void *unpack_func)
 
Octstrstore_status (int status_type)
 
int store_spool_init (const Octstr *fname)
 
int store_file_init (const Octstr *fname, long dump_freq)
 

Variables

long(* store_messages )(void)
 
int(* store_save )(Msg *msg)
 
int(* store_save_ack )(Msg *msg, ack_status_t status)
 
int(* store_load )(void(*receive_msg)(Msg *))
 
int(* store_dump )(void)
 
Octstr *(* store_msg_pack )(Msg *msg)
 
Msg *(* store_msg_unpack )(Octstr *os)
 
void(* store_shutdown )(void)
 
void(* store_for_each_message )(void(*callback_fn)(Msg *, void *), void *data)
 

Macro Definition Documentation

◆ BB_STORE_DEFAULT_DUMP_FREQ

#define BB_STORE_DEFAULT_DUMP_FREQ   10

Definition at line 66 of file bb_store.h.

Referenced by store_file_init().

Function Documentation

◆ store_file_init()

int store_file_init ( const Octstr fname,
long  dump_freq 
)

Definition at line 515 of file bb_store_file.c.

References active, bakfile, BB_STORE_DEFAULT_DUMP_FREQ, dict_create(), dump_frequency, file_mutex, filename, gwlist_add_producer(), gwlist_create, loaded, msg_destroy_item(), mutex_create, newfile, octstr_duplicate, octstr_format(), octstr_get_cstr, octstr_len(), panic, sms_dict, store_dump, store_file_dump(), store_file_for_each_message(), store_file_load(), store_file_messages(), store_file_save(), store_file_save_ack(), store_file_shutdown(), store_for_each_message, store_load, store_messages, store_save, store_save_ack, and store_shutdown.

Referenced by store_init().

516 {
517  /* Initialize function pointers */
525 
526  if (fname == NULL)
527  return 0; /* we are done */
528 
529  if (octstr_len(fname) > (FILENAME_MAX-5))
530  panic(0, "Store file filename too long: `%s', failed to init.",
531  octstr_get_cstr(fname));
532 
533  filename = octstr_duplicate(fname);
536 
538 
539  if (dump_freq > 0)
540  dump_frequency = dump_freq;
541  else
543 
545  active = 1;
546 
547  loaded = gwlist_create();
549 
550  return 0;
551 }
Dict * dict_create(long size_hint, void(*destroy_value)(void *))
Definition: dict.c:192
static long store_file_messages(void)
static void store_file_shutdown(void)
int(* store_save_ack)(Msg *msg, ack_status_t status)
Definition: bb_store.c:73
#define mutex_create()
Definition: thread.h:96
static long dump_frequency
Definition: bb_store_file.c:93
static List * loaded
Definition: bb_store_file.c:99
long(* store_messages)(void)
Definition: bb_store.c:71
static int store_file_dump(void)
static int active
Definition: bb_store_file.c:97
int(* store_dump)(void)
Definition: bb_store.c:75
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
void(* store_for_each_message)(void(*callback_fn)(Msg *msg, void *data), void *data)
Definition: bb_store.c:79
static Octstr * filename
Definition: bb_store_file.c:88
static Octstr * newfile
Definition: bb_store_file.c:89
void msg_destroy_item(void *msg)
Definition: msg.c:147
#define BB_STORE_DEFAULT_DUMP_FREQ
Definition: bb_store.h:66
static Dict * sms_dict
Definition: bb_store_file.c:95
static int store_file_save_ack(Msg *msg, ack_status_t status)
#define octstr_duplicate(ostr)
Definition: octstr.h:187
static int store_file_save(Msg *msg)
Octstr * octstr_format(const char *fmt,...)
Definition: octstr.c:2464
static Mutex * file_mutex
Definition: bb_store_file.c:91
void(* store_shutdown)(void)
Definition: bb_store.c:76
long octstr_len(const Octstr *ostr)
Definition: octstr.c:342
static void store_file_for_each_message(void(*callback_fn)(Msg *msg, void *data), void *data)
#define panic
Definition: log.h:87
int(* store_load)(void(*receive_msg)(Msg *))
Definition: bb_store.c:74
#define gwlist_create()
Definition: list.h:136
static Octstr * bakfile
Definition: bb_store_file.c:90
int(* store_save)(Msg *msg)
Definition: bb_store.c:72
static int store_file_load(void(*receive_msg)(Msg *))
void gwlist_add_producer(List *list)
Definition: list.c:383

◆ store_init()

int store_init ( Cfg cfg,
const Octstr type,
const Octstr fname,
long  dump_freq,
void *  pack_func,
void *  unpack_func 
)

Definition at line 82 of file bb_store.c.

References cfg, error(), octstr_str_compare(), store_file_init(), store_msg_pack, store_msg_unpack, store_spool_init(), and type.

Referenced by init_bearerbox(), init_smppbox(), and main().

84 {
85  int ret;
86 
87  store_msg_pack = pack_func;
88  store_msg_unpack = unpack_func;
89 
90  if (type == NULL || octstr_str_compare(type, "file") == 0) {
91  ret = store_file_init(fname, dump_freq);
92  } else if (octstr_str_compare(type, "spool") == 0) {
93  ret = store_spool_init(fname);
94 #ifdef HAVE_REDIS
95  } else if (octstr_str_compare(type, "redis") == 0) {
96  ret = store_redis_init(cfg);
97 #endif
98  } else {
99  error(0, "Unknown 'store-type' defined.");
100  ret = -1;
101  }
102 
103  return ret;
104 }
void error(int err, const char *fmt,...)
Definition: log.c:648
int type
Definition: smsc_cimd2.c:215
Msg *(* store_msg_unpack)(Octstr *os)
Definition: bb_store.c:78
static Cfg * cfg
Definition: opensmppbox.c:95
Octstr *(* store_msg_pack)(Msg *msg)
Definition: bb_store.c:77
int octstr_str_compare(const Octstr *ostr, const char *str)
Definition: octstr.c:973
int store_spool_init(const Octstr *fname)
int store_file_init(const Octstr *fname, long dump_freq)

◆ store_spool_init()

int store_spool_init ( const Octstr fname)

Init functions for different store types.

Definition at line 338 of file bb_store_spool.c.

References counter, counter_create(), error(), gwlist_add_producer(), gwlist_create, loaded, octstr_duplicate, octstr_get_cstr, spool, store_dump, store_for_each_message, store_load, store_messages, store_save, store_save_ack, store_shutdown, store_spool_dump(), store_spool_for_each_message(), store_spool_load(), store_spool_messages(), store_spool_save(), store_spool_save_ack(), and store_spool_shutdown().

Referenced by store_init().

339 {
340  DIR *dir;
341 
349 
350  if (store_dir == NULL)
351  return 0;
352 
353  /* check if we can open directory */
354  if ((dir = opendir(octstr_get_cstr(store_dir))) == NULL) {
355  error(errno, "Could not open directory `%s'", octstr_get_cstr(store_dir));
356  return -1;
357  }
358  closedir(dir);
359 
360  loaded = gwlist_create();
362  spool = octstr_duplicate(store_dir);
364 
365  return 0;
366 }
void error(int err, const char *fmt,...)
Definition: log.c:648
static Octstr * spool
static void store_spool_shutdown()
int(* store_save_ack)(Msg *msg, ack_status_t status)
Definition: bb_store.c:73
long(* store_messages)(void)
Definition: bb_store.c:71
int(* store_dump)(void)
Definition: bb_store.c:75
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
void(* store_for_each_message)(void(*callback_fn)(Msg *msg, void *data), void *data)
Definition: bb_store.c:79
static long store_spool_messages()
static void store_spool_for_each_message(void(*callback_fn)(Msg *msg, void *data), void *data)
Counter * counter_create(void)
Definition: counter.c:94
static int store_spool_save(Msg *msg)
static int store_spool_dump()
#define octstr_duplicate(ostr)
Definition: octstr.h:187
static List * loaded
static int store_spool_save_ack(Msg *msg, ack_status_t status)
void(* store_shutdown)(void)
Definition: bb_store.c:76
static int store_spool_load(void(*receive_msg)(Msg *))
int(* store_load)(void(*receive_msg)(Msg *))
Definition: bb_store.c:74
#define gwlist_create()
Definition: list.h:136
int(* store_save)(Msg *msg)
Definition: bb_store.c:72
void gwlist_add_producer(List *list)
Definition: list.c:383
static Counter * counter

◆ store_status()

Octstr* store_status ( int  status_type)

Definition at line 148 of file bb_store.c.

References BBSTATUS_HTML, BBSTATUS_XML, status::data, format(), octstr_append_cstr(), octstr_create, status_cb(), and store_for_each_message.

Referenced by httpd_store_status().

149 {
150  Octstr *ret = octstr_create("");
151  const char *format;
152  struct status data;
153 
154  /* check if we are active */
155  if (store_for_each_message == NULL)
156  return ret;
157 
158  /* set the type based header */
159  if (status_type == BBSTATUS_HTML) {
160  octstr_append_cstr(ret, "<table border=1>\n"
161  "<tr><td>SMS ID</td><td>Type</td><td>Time</td><td>Sender</td><td>Receiver</td>"
162  "<td>SMSC ID</td><td>BOX ID</td><td>Flags</td>"
163  "<td>UDH</td><td>Message</td>"
164  "</tr>\n");
165 
166  format = "<tr><td>%s</td><td>%s</td>"
167  "<td>%04d-%02d-%02d %02d:%02d:%02d</td>"
168  "<td>%s</td><td>%s</td><td>%s</td>"
169  "<td>%s</td><td>%ld:%ld:%ld:%ld:%ld</td><td>%E</td><td>%E</td></tr>\n";
170  } else if (status_type == BBSTATUS_XML) {
171  format = "\t<message>\n\t<id>%s</id>\n\t<type>%s</type>\n\t"
172  "<time>%04d-%02d-%02d %02d:%02d:%02d</time>\n\t"
173  "<sender>%s</sender>\n\t"
174  "<receiver>%s</receiver>\n\t<smsc-id>%s</smsc-id>\n\t"
175  "<box-id>%s</box-id>\n\t"
176  "<flags>%ld:%ld:%ld:%ld:%ld</flags>\n\t"
177  "<udh-data>%E</udh-data>\n\t<msg-data>%E</msg-data>\n\t"
178  "</message>\n";
179  } else {
180  octstr_append_cstr(ret, "[SMS ID] [Type] [Time] [Sender] [Receiver] [SMSC ID] [BOX ID] [Flags] [UDH] [Message]\n");
181  format = "[%s] [%s] [%04d-%02d-%02d %02d:%02d:%02d] [%s] [%s] [%s] [%s] [%ld:%ld:%ld:%ld:%ld] [%E] [%E]\n";
182  }
183 
184  data.format = format;
185  data.status = ret;
186 
188 
189  /* set the type based footer */
190  if (status_type == BBSTATUS_HTML) {
191  octstr_append_cstr(ret,"</table>");
192  }
193 
194  return ret;
195 }
static void format(char *buf, const char *fmt)
Definition: accesslog.c:174
void octstr_append_cstr(Octstr *ostr, const char *cstr)
Definition: octstr.c:1511
void(* store_for_each_message)(void(*callback_fn)(Msg *msg, void *data), void *data)
Definition: bb_store.c:79
#define octstr_create(cstr)
Definition: octstr.h:125
void * data
Definition: octstr.c:118
static void status_cb(Msg *msg, void *d)
Definition: bb_store.c:111

Variable Documentation

◆ store_dump

int(* store_dump) (void)

Definition at line 75 of file bb_store.c.

Referenced by store_dumper(), store_file_init(), and store_spool_init().

◆ store_for_each_message

void(* store_for_each_message) (void(*callback_fn)(Msg *, void *), void *data)

Definition at line 79 of file bb_store.c.

Referenced by store_file_init(), store_spool_init(), and store_status().

◆ store_load

int(* store_load) (void(*receive_msg)(Msg *))

Definition at line 74 of file bb_store.c.

Referenced by main(), store_file_init(), and store_spool_init().

◆ store_messages

long(* store_messages) (void)

Definition at line 71 of file bb_store.c.

Referenced by bb_print_status(), store_file_init(), and store_spool_init().

◆ store_msg_pack

Octstr*(* store_msg_pack) (Msg *msg)

Definition at line 77 of file bb_store.c.

Referenced by dlr_spool_add(), store_init(), store_spool_save(), and write_msg().

◆ store_msg_unpack

Msg*(* store_msg_unpack) (Octstr *os)

Definition at line 78 of file bb_store.c.

Referenced by dispatch(), dlr_spool_get(), read_msg(), status_cb(), and store_init().

◆ store_save

◆ store_save_ack

◆ store_shutdown

void(* store_shutdown) (void)

Definition at line 76 of file bb_store.c.

Referenced by main(), store_file_init(), and store_spool_init().

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