📄 dlr.c
字号:
/* ==================================================================== * The Kannel Software License, Version 1.0 * * Copyright (c) 2001-2004 Kannel Group * Copyright (c) 1998-2001 WapIT Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Kannel Group (http://www.kannel.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Kannel" and "Kannel Group" must not be used to * endorse or promote products derived from this software without * prior written permission. For written permission, please * contact org@kannel.org. * * 5. Products derived from this software may not be called "Kannel", * nor may "Kannel" appear in their name, without prior written * permission of the Kannel Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE KANNEL GROUP OR ITS CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Kannel Group. For more information on * the Kannel Group, please see <http://www.kannel.org/>. * * Portions of this software are based upon software originally written at * WapIT Ltd., Helsinki, Finland for the Kannel project. */ /* * gw/dlr.c * * Implementation of handling delivery reports (DLRs) * * Andreas Fink <andreas@fink.org>, 18.08.2001 * Stipe Tolj <tolj@wapme-systems.de>, 22.03.2002 * Alexander Malysh <a.malysh@centrium.de> 2003 * * Changes: * 2001-12-17: andreas@fink.org: * implemented use of mutex to avoid two mysql calls to run at the same time * 2002-03-22: tolj@wapme-systems.de: * added more abstraction to fit for several other storage types * 2002-08-04: tolj@wapme-systems.de: * added simple database library (sdb) support * 2002-11-14: tolj@wapme-systems.de: * added re-routing info for DLRs to route via bearerbox to the same smsbox * instance. This is required if you use state conditioned smsboxes or smppboxes * via one bearerbox. Previously bearerbox was simple ignoring to which smsbox * connection a msg is passed. Now we can route the messages inside bearerbox. */ #include <ctype.h>#include <time.h>#include <errno.h>#include <limits.h>#include <string.h>#include <unistd.h>#include "gwlib/gwlib.h"#include "sms.h"#include "dlr.h"#include "dlr_p.h"/* Our callback functions */static struct dlr_storage *handles = NULL;/* * Function to allocate a new struct dlr_entry entry * and intialize it to zero */struct dlr_entry *dlr_entry_create(void){ struct dlr_entry *dlr; dlr = gw_malloc(sizeof(*dlr)); gw_assert(dlr != NULL); /* set all values to NULL */ memset(dlr, 0, sizeof(*dlr)); return dlr;}/* * Duplicate dlr entry */struct dlr_entry *dlr_entry_duplicate(const struct dlr_entry *dlr){ struct dlr_entry *ret; if (dlr == NULL) return NULL; ret = dlr_entry_create(); ret->smsc = octstr_duplicate(dlr->smsc); ret->timestamp = octstr_duplicate(dlr->timestamp); ret->source = octstr_duplicate(dlr->source); ret->destination = octstr_duplicate(dlr->destination); ret->service = octstr_duplicate(dlr->service); ret->url = octstr_duplicate(dlr->url); ret->boxc_id = octstr_duplicate(dlr->boxc_id); ret->mask = dlr->mask; return ret;}/* * Function to destroy the struct dlr_entry entry */void dlr_entry_destroy(struct dlr_entry *dlr){ /* sanity check */ if (dlr == NULL) return;#define O_DELETE(a) { if (a) octstr_destroy(a); a = NULL; } O_DELETE(dlr->smsc); O_DELETE(dlr->timestamp); O_DELETE(dlr->source); O_DELETE(dlr->destination); O_DELETE(dlr->service); O_DELETE(dlr->url); O_DELETE(dlr->boxc_id);#undef O_DELETE dlr->mask = 0; gw_free(dlr);}/* * Load all configuration directives that are common for all database * types that use the 'dlr-db' group to define which attributes are * used in the table */struct dlr_db_fields *dlr_db_fields_create(CfgGroup *grp){ struct dlr_db_fields *ret = NULL; ret = gw_malloc(sizeof(*ret)); gw_assert(ret != NULL); memset(ret, 0, sizeof(*ret)); if (!(ret->table = cfg_get(grp, octstr_imm("table")))) panic(0, "DLR: DB: directive 'table' is not specified!"); if (!(ret->field_smsc = cfg_get(grp, octstr_imm("field-smsc")))) panic(0, "DLR: DB: directive 'field-smsc' is not specified!"); if (!(ret->field_ts = cfg_get(grp, octstr_imm("field-timestamp")))) panic(0, "DLR: DB: directive 'field-timestamp' is not specified!"); if (!(ret->field_src = cfg_get(grp, octstr_imm("field-source")))) panic(0, "DLR: DB: directive 'field-source' is not specified!"); if (!(ret->field_dst = cfg_get(grp, octstr_imm("field-destination")))) panic(0, "DLR: DB: directive 'field-destination' is not specified!"); if (!(ret->field_serv = cfg_get(grp, octstr_imm("field-service")))) panic(0, "DLR: DB: directive 'field-service' is not specified!"); if (!(ret->field_url = cfg_get(grp, octstr_imm("field-url")))) panic(0, "DLR: DB: directive 'field-url' is not specified!"); if (!(ret->field_mask = cfg_get(grp, octstr_imm("field-mask")))) panic(0, "DLR: DB: directive 'field-mask' is not specified!"); if (!(ret->field_status = cfg_get(grp, octstr_imm("field-status")))) panic(0, "DLR: DB: directive 'field-status' is not specified!"); if (!(ret->field_boxc = cfg_get(grp, octstr_imm("field-boxc-id")))) panic(0, "DLR: DB: directive 'field-boxc-id' is not specified!"); return ret;}void dlr_db_fields_destroy(struct dlr_db_fields *fields){ /* sanity check */ if (fields == NULL) return;#define O_DELETE(a) { if (a) octstr_destroy(a); a = NULL; } O_DELETE(fields->table); O_DELETE(fields->field_smsc); O_DELETE(fields->field_ts); O_DELETE(fields->field_src); O_DELETE(fields->field_dst); O_DELETE(fields->field_serv); O_DELETE(fields->field_url); O_DELETE(fields->field_mask); O_DELETE(fields->field_status); O_DELETE(fields->field_boxc);#undef O_DELETE gw_free(fields);}/* * Initialize specifically dlr storage. If defined storage is unknown * then panic. */void dlr_init(Cfg* cfg){ CfgGroup *grp; Octstr *dlr_type; /* check which DLR storage type we are using */ grp = cfg_get_single_group(cfg, octstr_imm("core")); if(grp == NULL) panic(0, "DLR: can't find group core"); dlr_type = cfg_get(grp, octstr_imm("dlr-storage")); /* * assume we are using internal memory in case no directive
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -