dlg_cb.h

00001 /*
00002  * $Id$
00003  *
00004  * Copyright (C) 2006 Voice Sistem SRLs
00005  *
00006  * This file is part of Kamailio, a free SIP server.
00007  *
00008  * Kamailio is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version
00012  *
00013  * Kamailio is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License 
00019  * along with this program; if not, write to the Free Software 
00020  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021  *
00022  * History:
00023  * --------
00024  * 2006-04-11  initial version (bogdan)
00025  * 2008-04-04  added direction reporting in dlg callbacks (bogdan)
00026  * 2008-04-14  added new type of callback to be triggered when dialogs are 
00027  *              loaded from DB (bogdan)
00028  * 2008-04-17  added new type of callback to be triggered right before the
00029  *              dialog is destroyed (deleted from memory) (bogdan)
00030  */
00031 
00032 #ifndef _DIALOG_DLG_CB_H_
00033 #define _DIALOG_DLG_CB_H_
00034 
00035 #include "../../parser/msg_parser.h"
00036 
00037 struct dlg_cell;
00038 
00039 struct dlg_cb_params {
00040         struct sip_msg* req;       /* sip request msg related to the callback event */
00041     struct sip_msg* rpl;       /* sip reply msg related to the callback event */
00042         unsigned int direction;    /* direction of the sip msg */
00043         void *dlg_data;            /* generic paramter, specific to callback */
00044         void **param;              /* parameter passed at callback registration*/
00045 };
00046 
00047 /* callback function prototype */
00048 typedef void (dialog_cb) (struct dlg_cell* dlg, int type, 
00049                 struct dlg_cb_params * params);
00050 /* function to free the callback param */
00051 typedef void (param_free_cb) (void *param);
00052 /* register callback function prototype */
00053 typedef int (*register_dlgcb_f)(struct dlg_cell* dlg, int cb_types,
00054                 dialog_cb f, void *param, param_free_cb ff);
00055 
00056 /* method to set a variable within a dialog */
00057 typedef int (*set_dlg_variable_f)( struct dlg_cell* dlg,
00058                                    str* key,
00059                                    str* val);
00060 /* method to get a variable from a dialog */
00061 typedef str* (*get_dlg_variable_f)( struct dlg_cell* dlg,
00062                                     str* key);
00063 
00064 #define DLGCB_LOADED          (1<<0)
00065 #define DLGCB_CREATED         (1<<1)
00066 #define DLGCB_FAILED          (1<<2)
00067 #define DLGCB_CONFIRMED_NA    (1<<3)
00068 #define DLGCB_CONFIRMED       (1<<4)
00069 #define DLGCB_REQ_WITHIN      (1<<5)
00070 #define DLGCB_TERMINATED      (1<<6)
00071 #define DLGCB_EXPIRED         (1<<7)
00072 #define DLGCB_EARLY           (1<<8)
00073 #define DLGCB_RESPONSE_FWDED  (1<<9)
00074 #define DLGCB_RESPONSE_WITHIN (1<<10)
00075 #define DLGCB_MI_CONTEXT      (1<<11)
00076 #define DLGCB_RPC_CONTEXT     (1<<12)
00077 #define DLGCB_DESTROY         (1<<13)
00078 #define DLGCB_SPIRALED        (1<<14)
00079 #define DLGCB_TERMINATED_CONFIRMED (1<<15)
00080 
00081 struct dlg_callback {
00082         int types;
00083         dialog_cb* callback;
00084         void *param;
00085         param_free_cb* callback_param_free;
00086         struct dlg_callback* next;
00087 };
00088 
00089 
00090 struct dlg_head_cbl {
00091         struct dlg_callback *first;
00092         int types;
00093 };
00094 
00095 
00096 void destroy_dlg_callbacks(unsigned int type);
00097 
00098 void destroy_dlg_callbacks_list(struct dlg_callback *cb);
00099 
00100 int register_dlgcb( struct dlg_cell* dlg, int types, dialog_cb f, void *param, param_free_cb ff);
00101 
00102 void run_create_callbacks(struct dlg_cell *dlg, struct sip_msg *msg);
00103 
00104 void run_dlg_callbacks( int type ,
00105                         struct dlg_cell *dlg,
00106                         struct sip_msg *req,
00107                         struct sip_msg *rpl,
00108                         unsigned int dir,
00109                         void *dlg_data);
00110 
00111 void run_load_callbacks( void );
00112 
00113 
00119 static inline struct sip_msg *dlg_get_valid_msg(struct dlg_cb_params *cb_params)
00120 {
00121         struct sip_msg *msg;
00122 
00123         if (cb_params == NULL) {
00124                 LM_ERR("no dialog parameters given\n");
00125                 return NULL;
00126         }
00127 
00128         msg = cb_params->req;
00129         if (msg == NULL) {
00130                 msg = cb_params->rpl;
00131                 if (msg == NULL || msg == FAKED_REPLY) {
00132                         return NULL;
00133                 }
00134         }
00135 
00136         return msg;
00137 };
00138 
00139 #endif