Kannel: Open Source WAP and SMS gateway  $Revision: 5037 $
bb_alog.c File Reference
#include "gwlib/gwlib.h"
#include "msg.h"
#include "sms.h"
#include "bearerbox.h"
#include "smscconn.h"

Go to the source code of this file.

Functions

static Octstrget_pattern (SMSCConn *conn, Msg *msg, const char *message)
 
void bb_alog_init (const Octstr *format)
 
void bb_alog_shutdown (void)
 
void bb_alog_sms (SMSCConn *conn, Msg *msg, const char *message)
 

Variables

static Octstrcustom_log_format = NULL
 

Function Documentation

void bb_alog_init ( const Octstr format)

Definition at line 359 of file bb_alog.c.

References gw_assert(), and octstr_duplicate.

Referenced by init_bearerbox().

360 {
361  gw_assert(format != NULL);
362 
364 }
#define octstr_duplicate(ostr)
Definition: octstr.h:187
gw_assert(wtls_machine->packet_to_send!=NULL)
static Octstr * custom_log_format
Definition: bb_alog.c:70
void bb_alog_shutdown ( void  )

Definition at line 367 of file bb_alog.c.

References octstr_destroy().

Referenced by main().

368 {
370  custom_log_format = NULL;
371 }
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:322
static Octstr * custom_log_format
Definition: bb_alog.c:70
void bb_alog_sms ( SMSCConn conn,
Msg msg,
const char *  message 
)

Definition at line 374 of file bb_alog.c.

References alog(), DC_8BIT, DC_UCS2, get_pattern(), gw_assert(), octstr_binary_to_hex(), octstr_convert_printable(), octstr_create, octstr_destroy(), octstr_duplicate, octstr_get_cstr, octstr_imm(), octstr_len(), smscconn_id(), smscconn_name(), and text.

Referenced by bb_smscconn_receive(), bb_smscconn_receive_internal(), bb_smscconn_send_failed(), bb_smscconn_sent(), and handle_pdu().

375 {
376  Octstr *text = NULL;
377 
378  gw_assert(msg_type(msg) == sms);
379 
380  /* if we don't have any custom log, then use our "default" one */
381 
382  if (custom_log_format == NULL) {
383  Octstr *udh;
384  const Octstr *cid;
385 
386  text = msg->sms.msgdata ? octstr_duplicate(msg->sms.msgdata) : octstr_create("");
387  udh = msg->sms.udhdata ? octstr_duplicate(msg->sms.udhdata) : octstr_create("");
388 
389  if (conn && smscconn_id(conn))
390  cid = smscconn_id(conn);
391  else if (conn && smscconn_name(conn))
392  cid = smscconn_name(conn);
393  else if (msg->sms.smsc_id)
394  cid = msg->sms.smsc_id;
395  else
396  cid = octstr_imm("");
397 
398  if ((msg->sms.coding == DC_8BIT || msg->sms.coding == DC_UCS2))
399  octstr_binary_to_hex(text, 1);
400  else
402  octstr_binary_to_hex(udh, 1);
403 
404  alog("%s [SMSC:%s] [SVC:%s] [ACT:%s] [BINF:%s] [FID:%s] [META:%s] [from:%s] [to:%s] [flags:%ld:%ld:%ld:%ld:%ld] "
405  "[msg:%ld:%s] [udh:%ld:%s]",
406  message,
407  octstr_get_cstr(cid),
408  msg->sms.service ? octstr_get_cstr(msg->sms.service) : "",
409  msg->sms.account ? octstr_get_cstr(msg->sms.account) : "",
410  msg->sms.binfo ? octstr_get_cstr(msg->sms.binfo) : "",
411  msg->sms.foreign_id ? octstr_get_cstr(msg->sms.foreign_id) : "",
412  msg->sms.meta_data ? octstr_get_cstr(msg->sms.meta_data) : "",
413  msg->sms.sender ? octstr_get_cstr(msg->sms.sender) : "",
414  msg->sms.receiver ? octstr_get_cstr(msg->sms.receiver) : "",
415  msg->sms.mclass, msg->sms.coding, msg->sms.mwi, msg->sms.compress,
416  msg->sms.dlr_mask,
417  octstr_len(msg->sms.msgdata), octstr_get_cstr(text),
418  octstr_len(msg->sms.udhdata), octstr_get_cstr(udh)
419  );
420 
421  octstr_destroy(udh);
422  } else {
423  text = get_pattern(conn, msg, message);
424  alog("%s", octstr_get_cstr(text));
425  }
426 
427  octstr_destroy(text);
428 }
msg_type
Definition: msg.h:73
const Octstr * smscconn_name(SMSCConn *conn)
Definition: smscconn.c:493
#define DC_8BIT
Definition: sms.h:111
static Octstr * get_pattern(SMSCConn *conn, Msg *msg, const char *message)
Definition: bb_alog.c:117
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
void octstr_binary_to_hex(Octstr *ostr, int uppercase)
Definition: octstr.c:463
void octstr_convert_printable(Octstr *ostr)
Definition: octstr.c:862
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:281
char * text
Definition: smsc_cimd2.c:921
const Octstr * smscconn_id(SMSCConn *conn)
Definition: smscconn.c:500
#define octstr_duplicate(ostr)
Definition: octstr.h:187
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:322
#define octstr_create(cstr)
Definition: octstr.h:125
gw_assert(wtls_machine->packet_to_send!=NULL)
long octstr_len(const Octstr *ostr)
Definition: octstr.c:340
Definition: octstr.c:118
void alog(const char *fmt,...)
Definition: accesslog.c:206
static Octstr * custom_log_format
Definition: bb_alog.c:70
#define DC_UCS2
Definition: sms.h:112
static Octstr* get_pattern ( SMSCConn conn,
Msg msg,
const char *  message 
)
static

Definition at line 117 of file bb_alog.c.

References DC_8BIT, DC_UCS2, gw_assert(), gw_gmtime(), gwlist_create, gwlist_destroy(), gwlist_get(), gwlist_len(), MSG_PARAM_UNDEFINED, octstr_append(), octstr_append_char(), octstr_append_cstr(), octstr_append_data(), octstr_append_decimal(), octstr_binary_to_hex(), octstr_convert_printable(), octstr_create, octstr_destroy(), octstr_destroy_item(), octstr_duplicate, octstr_format_append(), octstr_get_char(), octstr_get_cstr, octstr_len(), octstr_split_words(), report_mo, smscconn_id(), smscconn_name(), text, uuid_is_null(), UUID_STR_LEN, uuid_unparse(), and warning().

Referenced by bb_alog_sms().

118 {
119  int nextarg, j;
120  struct tm tm;
121  int num_words;
122  List *word_list;
123  Octstr *result;
124  const char *pattern;
125  Octstr *temp, *text, *udh;
126  size_t n;
127  long i;
128 
129  text = msg->sms.msgdata ? octstr_duplicate(msg->sms.msgdata) : octstr_create("");
130  udh = msg->sms.udhdata ? octstr_duplicate(msg->sms.udhdata) : octstr_create("");
131  if ((msg->sms.coding == DC_8BIT || msg->sms.coding == DC_UCS2))
132  octstr_binary_to_hex(text, 1);
133  else
135  octstr_binary_to_hex(udh, 1);
136 
137  if (octstr_len(text)) {
138  word_list = octstr_split_words(text);
139  num_words = gwlist_len(word_list);
140  } else {
141  word_list = gwlist_create();
142  num_words = 0;
143  }
144 
145  result = octstr_create("");
147 
148  nextarg = 1;
149 
150  while (*pattern != '\0') {
151  n = strcspn(pattern, "%");
152  octstr_append_data(result, pattern, n);
153  pattern += n;
154  gw_assert(*pattern == '%' || *pattern == '\0');
155  if (*pattern == '\0')
156  break;
157 
158  pattern++;
159 
160  switch (*pattern) {
161  case 'k':
162  if (num_words <= 0)
163  break;
164  octstr_append(result, gwlist_get(word_list, 0));
165  break;
166 
167  case 's':
168  if (nextarg >= num_words)
169  break;
170  octstr_append(result, gwlist_get(word_list, nextarg));
171  ++nextarg;
172  break;
173 
174  case 'S':
175  if (nextarg >= num_words)
176  break;
177  temp = gwlist_get(word_list, nextarg);
178  for (i = 0; i < octstr_len(temp); ++i) {
179  if (octstr_get_char(temp, i) == '*')
180  octstr_append_char(result, '~');
181  else
182  octstr_append_char(result, octstr_get_char(temp, i));
183  }
184  ++nextarg;
185  break;
186 
187  case 'r':
188  for (j = nextarg; j < num_words; ++j) {
189  if (j != nextarg)
190  octstr_append_char(result, '+');
191  octstr_append(result, gwlist_get(word_list, j));
192  }
193  break;
194 
195  case 'l':
196  if (message)
197  octstr_append_cstr(result, message);
198  break;
199 
200  case 'P':
201  if (msg->sms.receiver)
202  octstr_append(result, msg->sms.receiver);
203  break;
204 
205  case 'p':
206  if (msg->sms.sender)
207  octstr_append(result, msg->sms.sender);
208  break;
209 
210  case 'a':
211  for (j = 0; j < num_words; ++j) {
212  if (j > 0)
213  octstr_append_char(result, ' ');
214  octstr_append(result, gwlist_get(word_list, j));
215  }
216  break;
217 
218  case 'b':
219  if (text)
220  octstr_append(result, text);
221  break;
222 
223  case 'L':
224  octstr_append_decimal(result, octstr_len(msg->sms.msgdata));
225  break;
226 
227  case 't':
228  tm = gw_gmtime(msg->sms.time);
229  octstr_format_append(result, "%04d-%02d-%02d %02d:%02d:%02d",
230  tm.tm_year + 1900,
231  tm.tm_mon + 1,
232  tm.tm_mday,
233  tm.tm_hour,
234  tm.tm_min,
235  tm.tm_sec);
236  break;
237 
238  case 'T':
239  if (msg->sms.time != MSG_PARAM_UNDEFINED)
240  octstr_format_append(result, "%ld", msg->sms.time);
241  break;
242 
243  case 'i':
244  if (conn && smscconn_id(conn))
245  octstr_append(result, smscconn_id(conn));
246  else if (conn && smscconn_name(conn))
247  octstr_append(result, smscconn_name(conn));
248  else if (msg->sms.smsc_id)
249  octstr_append(result, msg->sms.smsc_id);
250  break;
251 
252  case 'I':
253  if (!uuid_is_null(msg->sms.id)) {
254  char id[UUID_STR_LEN + 1];
255  uuid_unparse(msg->sms.id, id);
256  octstr_append_cstr(result, id);
257  }
258  break;
259 
260  case 'n':
261  if (msg->sms.service != NULL)
262  octstr_append(result, msg->sms.service);
263  break;
264 
265  case 'd':
266  octstr_append_decimal(result, msg->sms.dlr_mask);
267  break;
268 
269  case 'R':
270  if (msg->sms.dlr_url != NULL)
271  octstr_append(result, msg->sms.dlr_url);
272  break;
273 
274  case 'N':
275  if (msg->sms.sms_type == report_mo && text != NULL)
276  octstr_append(result, text);
277  break;
278 
279  case 'D': /* meta_data */
280  if (msg->sms.meta_data != NULL)
281  octstr_append(result, msg->sms.meta_data);
282  break;
283 
284  case 'c':
285  octstr_append_decimal(result, msg->sms.coding);
286  break;
287 
288  case 'm':
289  octstr_append_decimal(result, msg->sms.mclass);
290  break;
291 
292  case 'C':
293  octstr_append_decimal(result, msg->sms.compress);
294  break;
295 
296  case 'M':
297  octstr_append_decimal(result, msg->sms.mwi);
298  break;
299 
300  case 'u':
301  if (octstr_len(udh)) {
302  octstr_append(result, udh);
303  }
304  break;
305 
306  case 'U':
307  octstr_append_decimal(result, octstr_len(msg->sms.udhdata));
308  break;
309 
310  case 'B': /* billing identifier/information */
311  if (octstr_len(msg->sms.binfo)) {
312  octstr_append(result, msg->sms.binfo);
313  }
314  break;
315 
316  case 'A': /* account */
317  if (octstr_len(msg->sms.account)) {
318  octstr_append(result, msg->sms.account);
319  }
320  break;
321 
322  case 'F': /* the foreign (smsc-provided) message ID */
323  if (msg->sms.foreign_id != NULL)
324  octstr_append(result, msg->sms.foreign_id);
325  break;
326 
327  case 'x': /* the boxc_id, hence the smsbox-id of the message */
328  if (msg->sms.boxc_id != NULL)
329  octstr_append(result, msg->sms.boxc_id);
330  break;
331 
332  /* XXX add more here if needed */
333 
334  case '%':
335  octstr_format_append(result, "%%");
336  break;
337 
338  default:
339  warning(0, "Unknown escape code (%%%c) within custom-log-format, skipping!", *pattern);
340  octstr_format_append(result, "%%%c", *pattern);
341  break;
342  } /* switch(...) */
343 
344  pattern++;
345  } /* for ... */
346 
348  octstr_destroy(text);
349  octstr_destroy(udh);
350 
351  return result;
352 }
void octstr_append_data(Octstr *ostr, const char *data, long len)
Definition: octstr.c:1495
void octstr_append(Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:1502
struct tm gw_gmtime(time_t t)
Definition: protected.c:137
Definition: msg.h:109
long gwlist_len(List *list)
Definition: list.c:166
void * gwlist_get(List *list, long pos)
Definition: list.c:292
void octstr_append_char(Octstr *ostr, int ch)
Definition: octstr.c:1515
const Octstr * smscconn_name(SMSCConn *conn)
Definition: smscconn.c:493
#define DC_8BIT
Definition: sms.h:111
void uuid_unparse(const uuid_t uu, char *out)
Definition: gw_uuid.c:561
void octstr_append_cstr(Octstr *ostr, const char *cstr)
Definition: octstr.c:1509
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
void octstr_binary_to_hex(Octstr *ostr, int uppercase)
Definition: octstr.c:463
void octstr_convert_printable(Octstr *ostr)
Definition: octstr.c:862
char * text
Definition: smsc_cimd2.c:921
int uuid_is_null(const uuid_t uu)
Definition: gw_uuid.c:412
const Octstr * smscconn_id(SMSCConn *conn)
Definition: smscconn.c:500
#define octstr_duplicate(ostr)
Definition: octstr.h:187
void warning(int err, const char *fmt,...)
Definition: log.c:624
List * octstr_split_words(const Octstr *ostr)
Definition: octstr.c:1600
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:322
#define octstr_create(cstr)
Definition: octstr.h:125
void octstr_destroy_item(void *os)
Definition: octstr.c:334
gw_assert(wtls_machine->packet_to_send!=NULL)
#define UUID_STR_LEN
Definition: gw_uuid.h:19
long octstr_len(const Octstr *ostr)
Definition: octstr.c:340
void octstr_append_decimal(Octstr *ostr, long value)
Definition: octstr.c:1974
Definition: octstr.c:118
#define MSG_PARAM_UNDEFINED
Definition: msg.h:71
void octstr_format_append(Octstr *os, const char *fmt,...)
Definition: octstr.c:2505
#define gwlist_create()
Definition: list.h:136
int octstr_get_char(const Octstr *ostr, long pos)
Definition: octstr.c:404
Definition: list.c:102
static Octstr * custom_log_format
Definition: bb_alog.c:70
#define DC_UCS2
Definition: sms.h:112
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)
Definition: list.c:145

Variable Documentation

Octstr* custom_log_format = NULL
static

Definition at line 70 of file bb_alog.c.

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