1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
|
/*
* $Id$
*
* Copyright (C) 2012 Smile Communications, jason.penton@smilecoms.com
* Copyright (C) 2012 Smile Communications, richard.good@smilecoms.com
*
* The initial version of this code was written by Dragos Vingarzan
* (dragos(dot)vingarzan(at)fokus(dot)fraunhofer(dot)de and the
* Fruanhofer Institute. It was and still is maintained in a separate
* branch of the original SER. We are therefore migrating it to
* Kamailio/SR and look forward to maintaining it from here on out.
* 2011/2012 Smile Communications, Pty. Ltd.
* ported/maintained/improved by
* Jason Penton (jason(dot)penton(at)smilecoms.com and
* Richard Good (richard(dot)good(at)smilecoms.com) as part of an
* effort to add full IMS support to Kamailio/SR using a new and
* improved architecture
*
* NB: Alot of this code was originally part of OpenIMSCore,
* FhG Fokus.
* Copyright (C) 2004-2006 FhG Fokus
* Thanks for great work! This is an effort to
* break apart the various CSCF functions into logically separate
* components. We hope this will drive wider use. We also feel
* that in this way the architecture is more complete and thereby easier
* to manage in the Kamailio/SR environment
*
* This file is part of Kamailio, a free SIP server.
*
* Kamailio is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version
*
* Kamailio is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*
* History:
* --------
* 2004-03-16 created (bogdan)
*/
/*! \file
* \brief USRLOC - Callback functions
* \ingroup usrloc
*
* - Module: \ref usrloc
*/
#include <stdlib.h>
#include "../../dprint.h"
#include "../../error.h"
#include "../../mem/shm_mem.h"
#include "ul_callback.h"
#include "ucontact.h"
struct ulcb_head_list* ulcb_list = 0;
int init_ulcb_list(void)
{
ulcb_list = (struct ulcb_head_list*)shm_malloc
( sizeof(struct ulcb_head_list) );
if (ulcb_list==0) {
LM_CRIT("no more shared mem\n");
return -1;
}
ulcb_list->first = 0;
ulcb_list->reg_types = 0;
return 1;
}
void destroy_ulcb_list(void)
{
struct ul_callback *cbp, *cbp_tmp;
if (!ulcb_list)
return;
for( cbp=ulcb_list->first; cbp ; ) {
cbp_tmp = cbp;
cbp = cbp->next;
if (cbp_tmp->param) shm_free( cbp_tmp->param );
shm_free( cbp_tmp );
}
shm_free(ulcb_list);
}
/*! \brief
register a callback function 'f' for 'types' mask of events;
*/
int register_ulcb( struct impurecord* r, struct ucontact* c, int types, ul_cb f, void *param )
{
struct ul_callback *cbp;
int contact_cb=0;
int impurecord_cb=0;
struct ulcb_head_list* cb_list=0;
if (types & UL_IMPU_INSERT) {
if (types != UL_IMPU_INSERT) {
LM_CRIT("UL_IMPU_INSERT type must be registered alone!\n");
return -1;
}
cb_list = ulcb_list;
} else if (types & UL_CONTACT_INSERT) {
if (types != UL_CONTACT_INSERT) {
LM_CRIT("UL_CONTACT_INSERT type must be registered alone!\n");
return -1;
}
cb_list = ulcb_list;
} else {
contact_cb = (types & UL_CONTACT_DELETE)
|| (types & UL_CONTACT_EXPIRE) || (types & UL_CONTACT_UPDATE);
impurecord_cb = (types & UL_IMPU_DELETE)
|| (types & UL_IMPU_UPDATE)
|| (types & UL_IMPU_REG_NC_DELETE)
|| (types & UL_IMPU_NR_DELETE)
|| (types & UL_IMPU_UNREG_EXPIRED)
|| (types & UL_IMPU_UPDATE_CONTACT)
|| (types & UL_IMPU_DELETE_CONTACT)
|| (types & UL_IMPU_EXPIRE_CONTACT)
|| (types & UL_IMPU_NEW_CONTACT);
if (contact_cb && impurecord_cb) {
LM_CRIT("can't register IMPU and Contact callback in same call\n");
return -1;
}
if (contact_cb && !c) {
LM_CRIT("no contact provided for contact callback\n");
return -1;
}
if (impurecord_cb && !r) {
LM_CRIT("no impurecord provided for contact callback\n");
return -1;
}
}
/* are the callback types valid?... */
if ( types<0 || types>ULCB_MAX ) {
LM_CRIT("invalid callback types: mask=%d\n",types);
return E_BUG;
}
/* we don't register null functions */
if (f==0) {
LM_CRIT("null callback function\n");
return E_BUG;
}
if (contact_cb) {
LM_DBG("installing callback for SCSCF contact with type [%d]\n", types);
cb_list = c->cbs;
} else if (impurecord_cb) {
LM_DBG("installing callback for SCSCF IMPU record with type [%d]\n", types);
cb_list = r->cbs;
}
/* build a new callback structure */
if (!(cbp=(struct ul_callback*)shm_malloc(sizeof( struct ul_callback)))) {
LM_ERR("no more share mem\n");
return E_OUT_OF_MEM;
}
/* link it into the proper place... */
cbp->next = cb_list->first;
cb_list->first = cbp;
cb_list->reg_types |= types;
/* ... and fill it up */
cbp->callback = f;
cbp->param = param;
cbp->types = types;
if (cbp->next)
cbp->id = cbp->next->id+1;
else
cbp->id = 0;
return 1;
}
|