Kannel: Open Source WAP and SMS gateway  svn-r5335
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

◆ status_cb()

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, msg, 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:562
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:283
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:2507
Definition: msg.h:107
static XMLRPCDocument * msg
Definition: test_xmlrpc.c:86
Octstr * status
Definition: bb_store.c:108

◆ 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_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 *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().

◆ 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.