2005-03-23 05:55:16 +00:00
|
|
|
/*
|
|
|
|
* Mbuni - Open Source MMS Gateway
|
|
|
|
*
|
|
|
|
* Mbuni sample billing handler module
|
|
|
|
*
|
2008-07-10 09:46:58 +00:00
|
|
|
* Copyright (C) 2003 - 2008, Digital Solutions Ltd. - http://www.dsmagic.com
|
2005-03-23 05:55:16 +00:00
|
|
|
*
|
|
|
|
* Paul Bagyenda <bagyenda@dsmagic.com>
|
|
|
|
*
|
|
|
|
* This program is free software, distributed under the terms of
|
|
|
|
* the GNU General Public License, with a few exceptions granted (see LICENSE)
|
|
|
|
*/
|
|
|
|
|
2005-03-10 08:01:02 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "mms_billing.h"
|
|
|
|
|
|
|
|
/* This module provides a basic biller and CDR implementation. Totally no frills, but a basis
|
|
|
|
* for implementing a 'real' module.
|
|
|
|
* It does CDR but no billing (of course).
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
static void *mms_billingmodule_init(char *settings)
|
|
|
|
{
|
|
|
|
return fopen(settings, "a"); /* Settings is interpreted as a file name. */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int mms_billingmodule_fini(void *module_data)
|
|
|
|
{
|
|
|
|
return module_data ? fclose(module_data) : -1;
|
|
|
|
}
|
|
|
|
|
2007-08-29 13:33:11 +00:00
|
|
|
static int mms_billmsg(Octstr *from, List *to, unsigned long msg_size, Octstr *vaspid, Octstr *msgid, void *module_data)
|
2005-03-10 08:01:02 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mms_logcdr(MmsCdrStruct *cdr)
|
|
|
|
{
|
|
|
|
if (cdr && cdr->module_data) {
|
|
|
|
char buf[CBUFSIZE];
|
|
|
|
struct tm tm;
|
|
|
|
|
|
|
|
localtime_r(&cdr->sdate, &tm);
|
|
|
|
gw_strftime(buf, sizeof buf, "%Y-%m-%d %H:%M:%S", &tm);
|
2008-06-24 16:08:55 +00:00
|
|
|
fprintf(cdr->module_data, "%s\t%.128s\t%.128s\t%.128s\t%.256s\t%.256s\t%ld\n",
|
|
|
|
buf,
|
|
|
|
cdr->src_interface[0] ? cdr->src_interface : "MM2",
|
|
|
|
cdr->dst_interface[0] ? cdr->dst_interface : "MM2",
|
2008-06-24 10:01:03 +00:00
|
|
|
cdr->from, cdr->to, cdr->msgid, cdr->msg_size);
|
2005-03-10 08:01:02 +00:00
|
|
|
fflush(cdr->module_data);
|
|
|
|
} else
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-06-24 10:01:03 +00:00
|
|
|
MmsCdrStruct *make_cdr_struct(void *module_data, time_t sdate, char *from, char *to, char *msgid,
|
2008-06-24 16:08:55 +00:00
|
|
|
char *vaspid, char *src_int, char *dst_int, unsigned long msg_size)
|
2008-06-24 10:01:03 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
MmsCdrStruct *cdr = gw_malloc(sizeof *cdr);
|
|
|
|
|
|
|
|
cdr->module_data = module_data;
|
|
|
|
cdr->sdate = sdate;
|
|
|
|
strncpy(cdr->from, from ? from : "", sizeof cdr->from);
|
|
|
|
strncpy(cdr->to, to ? to : "", sizeof cdr->to);
|
|
|
|
strncpy(cdr->msgid, msgid ? msgid : "", sizeof cdr->msgid);
|
|
|
|
strncpy(cdr->vaspid, vaspid ? vaspid : "", sizeof cdr->vaspid);
|
|
|
|
strncpy(cdr->src_interface, src_int ? src_int : "MM2", sizeof cdr->src_interface);
|
2008-06-24 16:08:55 +00:00
|
|
|
strncpy(cdr->dst_interface, dst_int ? dst_int : "MM2", sizeof cdr->dst_interface);
|
2008-06-24 10:01:03 +00:00
|
|
|
|
|
|
|
cdr->msg_size = msg_size;
|
|
|
|
|
|
|
|
return cdr;
|
|
|
|
}
|
|
|
|
|
2005-03-10 08:01:02 +00:00
|
|
|
/* The function itself. */
|
|
|
|
MmsBillingFuncStruct mms_billfuncs = {
|
|
|
|
mms_billingmodule_init,
|
|
|
|
mms_logcdr,
|
|
|
|
mms_billmsg,
|
|
|
|
mms_billingmodule_fini
|
|
|
|
};
|