File: ul_callback.h

package info (click to toggle)
kamailio 4.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 56,100 kB
  • sloc: ansic: 552,832; xml: 166,484; sh: 8,659; makefile: 7,676; sql: 6,235; perl: 3,487; yacc: 3,428; python: 1,457; cpp: 1,219; php: 1,047; java: 449; pascal: 194; cs: 40; awk: 27
file content (127 lines) | stat: -rw-r--r-- 4,811 bytes parent folder | download | duplicates (2)
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
/*
 * $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
 * 
 */

#ifndef _UL_CALLBACKS_H
#define _UL_CALLBACKS_H

#include "../../dprint.h"

/* forward declaration for ucontact_t */
struct ucontact;
struct impurecord;

#define UL_CONTACT_INSERT      	(1<<0)
#define UL_CONTACT_UPDATE      	(1<<1)
#define UL_CONTACT_DELETE      	(1<<2)
#define UL_CONTACT_EXPIRE      	(1<<3)
#define UL_IMPU_REG_NC_DELETE	(1<<4)		/* reg, no contacts - deleted */
#define UL_IMPU_NR_DELETE		(1<<5)		/* Not registered - deleted */
#define UL_IMPU_UNREG_EXPIRED	(1<<6)		/* Unregistered time expired */
#define UL_IMPU_DELETE			(1<<7)		/* explicit impu delete - for example thru API */
#define UL_IMPU_INSERT		   	(1<<8)		/* new IMPU record has been added */
#define UL_IMPU_UPDATE		   	(1<<9)		/* IMPU record has been updated */
#define UL_IMPU_NEW_CONTACT		(1<<10)		/* a new contact has been inserted for this IMPU */
#define UL_IMPU_UPDATE_CONTACT		(1<<11)		/* a new contact has been inserted for this IMPU */
#define UL_IMPU_DELETE_CONTACT		(1<<12)		/* a new contact has been inserted for this IMPU */
#define UL_IMPU_EXPIRE_CONTACT		(1<<13)		/* a new contact has been inserted for this IMPU */
#define ULCB_MAX               	((1<<14)-1)

/*! \brief callback function prototype */
typedef void (ul_cb) (struct impurecord* r, struct ucontact *c, int type, void *param);
/*! \brief register callback function prototype */
typedef int (*register_ulcb_t)( struct impurecord* r, struct ucontact *c, int cb_types, ul_cb f, void *param);


struct ul_callback {
	int id;                      /*!< id of this callback - useless */
	int types;                   /*!< types of events that trigger the callback*/
	ul_cb* callback;             /*!< callback function */
	void *param;                 /*!< param to be passed to callback function */
	struct ul_callback* next;
};

struct ulcb_head_list {
	struct ul_callback *first;
	int reg_types;
};


extern struct ulcb_head_list*  ulcb_list;


static inline int exists_ulcb_type(struct ulcb_head_list* list, int types) {
	if (list==NULL)
		return (ulcb_list->reg_types|types);
	else
		return (list->reg_types|types);
}

int init_ulcb_list(void);

void destroy_ulcb_list(void);


/*! \brief register a callback for several types of events */
int register_ulcb( struct impurecord* r, struct ucontact* c, int types, ul_cb f, void *param );

/*! \brief run all transaction callbacks for an event type */
static inline void run_ul_callbacks( struct ulcb_head_list* cb_list, int type , struct impurecord *r, struct ucontact *c)
{
	struct ul_callback *cbp;

	if (cb_list == NULL) { //must be for global list
		cb_list = ulcb_list;
	}

	for (cbp=cb_list->first; cbp; cbp=cbp->next)  {
		if(cbp->types&type) {
			LM_DBG("impurecord=%p, contact=%p, callback type %d/%d, id %d entered\n",
				r, c, type, cbp->types, cbp->id );
			cbp->callback( r, c, type, cbp->param );
		}
	}
}

#endif