Kannel: Open Source WAP and SMS gateway  $Revision: 5037 $
bb_store.c File Reference
#include "gw-config.h"
#include "gwlib/gwlib.h"
#include "msg.h"
#include "bearerbox.h"
#include "bb_store.h"

Go to the source code of this file.

Data Structures

struct  status
 

Functions

int store_init (Cfg *cfg, const Octstr *type, const Octstr *fname, long dump_freq, void *pack_func, void *unpack_func)
 
static void status_cb (Msg *msg, void *d)
 
Octstrstore_status (int status_type)
 

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)
 
void(* store_shutdown )(void)
 
Octstr *(* store_msg_pack )(Msg *msg)
 
Msg *(* store_msg_unpack )(Octstr *os)
 
void(* store_for_each_message )(void(*callback_fn)(Msg *msg, void *data), void *data)
 

Function Documentation

static void status_cb ( Msg msg,
void *  d 
)
static

Definition at line 111 of file bb_store.c.

References status::data, status::format, gw_gmtime(), gw_localtime(), mo, mt_push, mt_reply, octstr_format_append(), octstr_get_cstr, octstr_imm(), report_mo, report_mt, status::status, UUID_STR_LEN, and uuid_unparse().

Referenced by store_status().

112 {
113  struct status *data = d;
114  struct tm tm;
115  char id[UUID_STR_LEN + 1];
116 
117  if (msg == NULL)
118  return;
119 
120  /* transform the time value */
121 #if LOG_TIMESTAMP_LOCALTIME
122  tm = gw_localtime(msg->sms.time);
123 #else
124  tm = gw_gmtime(msg->sms.time);
125 #endif
126 
127  uuid_unparse(msg->sms.id, id);
128 
129  octstr_format_append(data->status, data->format,
130  id,
131  (msg->sms.sms_type == mo ? "MO" :
132  msg->sms.sms_type == mt_push ? "MT-PUSH" :
133  msg->sms.sms_type == mt_reply ? "MT-REPLY" :
134  msg->sms.sms_type == report_mo ? "DLR-MO" :
135  msg->sms.sms_type == report_mt ? "DLR-MT" : ""),
136  tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
137  tm.tm_hour, tm.tm_min, tm.tm_sec,
138  (msg->sms.sender ? octstr_get_cstr(msg->sms.sender) : ""),
139  (msg->sms.receiver ? octstr_get_cstr(msg->sms.receiver) : ""),
140  (msg->sms.smsc_id ? octstr_get_cstr(msg->sms.smsc_id) : ""),
141  (msg->sms.boxc_id ? octstr_get_cstr(msg->sms.boxc_id) : ""),
142  msg->sms.mclass, msg->sms.coding, msg->sms.mwi, msg->sms.compress,
143  msg->sms.dlr_mask,
144  (msg->sms.udhdata ? msg->sms.udhdata : octstr_imm("")),
145  (msg->sms.msgdata ? msg->sms.msgdata : octstr_imm("")));
146 }
Definition: msg.h:106
struct tm gw_gmtime(time_t t)
Definition: protected.c:137
Definition: msg.h:109
const char * format
Definition: bb_store.c:107
void uuid_unparse(const uuid_t uu, char *out)
Definition: gw_uuid.c:561
Definition: msg.h:110
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
Definition: msg.h:108
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:281
void * data
#define UUID_STR_LEN
Definition: gw_uuid.h:19
struct tm gw_localtime(time_t t)
Definition: protected.c:121
void octstr_format_append(Octstr *os, const char *fmt,...)
Definition: octstr.c:2505
Definition: msg.h:107
Octstr * status
Definition: bb_store.c:108
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 error(), octstr_str_compare(), store_file_init(), store_msg_pack, store_msg_unpack, and store_spool_init().

Referenced by init_bearerbox(), 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:612
Msg *(* store_msg_unpack)(Octstr *os)
Definition: bb_store.c:78
Octstr *(* store_msg_pack)(Msg *msg)
Definition: bb_store.c:77
int octstr_str_compare(const Octstr *ostr, const char *str)
Definition: octstr.c:971
int store_spool_init(const Octstr *fname)
int store_file_init(const Octstr *fname, long dump_freq)
Octstr* store_status ( int  status_type)

Definition at line 148 of file bb_store.c.

References BBSTATUS_HTML, BBSTATUS_XML, status::format, format(), octstr_append_cstr(), octstr_create, status::status, 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:1509
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

int(* store_dump) (void)

Definition at line 75 of file bb_store.c.

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

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

Definition at line 79 of file bb_store.c.

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

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

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

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

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

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.