pua_callback.h

00001 /*
00002  * $Id: pua_callback.c,v 1.2 2007/02/20 13:40:09 anca_vamanu Exp $
00003  *
00004  * pua module - presence user agent module
00005  *
00006  * Copyright (C) 2007 Voice Sistem S.R.L.
00007  *
00008  * This file is part of Kamailio, a free SIP server.
00009  *
00010  * Kamailio is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version
00014  *
00015  * Kamailio is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License 
00021  * along with this program; if not, write to the Free Software 
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023  */
00024 
00025 #ifndef PUA_CBACK
00026 #define PUA_CBACK
00027 
00028 #include "../../parser/parse_fline.h"
00029 #include "../pua/hash.h"
00030 
00031 #define PUACB_MAX               (1<<9)
00032 
00033 /* callback function prototype */
00034 typedef int (pua_cb)(ua_pres_t* hentity, struct sip_msg*);
00035 /* register callback function prototype */
00036 typedef int (*register_puacb_t)(int types, pua_cb f, void* param );
00037 
00038 
00039 struct pua_callback {
00040         int id;                      /* id of this callback - useless */
00041         int types;                   /* types of events that trigger the callback*/
00042         pua_cb* callback;             /* callback function */
00043         void* param;
00044         struct pua_callback* next;
00045 };
00046 
00047 struct puacb_head_list {
00048         struct pua_callback *first;
00049         int reg_types;
00050 };
00051 
00052 
00053 extern struct puacb_head_list*  puacb_list;
00054 
00055 int init_puacb_list(void);
00056 
00057 void destroy_puacb_list(void);
00058 
00059 
00060 /* register a callback for several types of events */
00061 int register_puacb( int types, pua_cb f, void* param );
00062 
00063 /* run all transaction callbacks for an event type */
00064 static inline void run_pua_callbacks(ua_pres_t* hentity, struct sip_msg* msg)
00065 {
00066         struct pua_callback *cbp;
00067 
00068         for (cbp= puacb_list->first; cbp; cbp=cbp->next)  {
00069                 if(cbp->types & hentity->flag) 
00070                 {       
00071                         LM_DBG("found callback\n");
00072                         cbp->callback(hentity, msg);
00073                 }
00074         }
00075 }
00076 
00077 /* Q: should I call the registered callback functions when the modules refreshes a request? */
00078 #endif