sl_cb.c

Go to the documentation of this file.
00001 /*
00002  * $Id: sl_cb.c 4763 2008-08-28 14:35:03Z henningw $
00003  *
00004  * Copyright (C) 2006 Voice Sistem SRL
00005  *
00006  * This file is part of Kamailio, a free SIP server.
00007  *
00008  * Kamailio is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU General Public License
00010  * as published by the Free Software Foundation; either version 2
00011  * of the License, or (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-03-29  first version (bogdan)
00025  */
00026 
00027 /*!
00028  * \file
00029  * \brief SL :: callbacks
00030  * \ingroup sl
00031  * - Module: \ref sl
00032  */
00033 
00034 #include "../../mem/mem.h"
00035 #include "sl_cb.h"
00036 
00037 /*! callback list head */
00038 struct sl_callback* slcb_hl = 0;
00039 
00040 
00041 /*! cleanup callback list */
00042 void destroy_slcb_lists(void)
00043 {
00044    struct sl_callback *cbp, *cbp_tmp;
00045 
00046    for( cbp=slcb_hl; cbp ; ) {
00047       cbp_tmp = cbp;
00048       cbp = cbp->next;
00049       pkg_free( cbp_tmp );
00050    }
00051 }
00052 
00053 
00054 /*! register a SL callback */
00055 int register_slcb(unsigned int types, sl_cb_t f, void *param )
00056 {
00057    struct sl_callback *cbp;
00058 
00059    /* build a new callback structure */
00060    if (!(cbp=pkg_malloc( sizeof( struct sl_callback)))) {
00061       LM_ERR("out of pkg. mem\n");
00062       return -1;
00063    }
00064 
00065    /* fill it up */
00066    cbp->types = types;
00067    cbp->callback = f;
00068    cbp->param = param;
00069    /* link it at the beginning of the list */
00070    cbp->next = slcb_hl;
00071    slcb_hl = cbp;
00072    /* set next id */
00073    if (cbp->next)
00074       cbp->id = cbp->next->id+1;
00075    else
00076       cbp->id = 0;
00077 
00078    return 0;
00079 }
00080 
00081 
00082 /*! run SL callbacks */
00083 void run_sl_callbacks( unsigned int types, struct sip_msg *req, str *buffer,
00084                      int code, str *reason, union sockaddr_union *to )
00085 {
00086    static struct sl_cb_param cb_params;
00087    struct sl_callback *cbp;
00088 
00089    cb_params.buffer = buffer;
00090    cb_params.code = code;
00091    cb_params.reason = reason;
00092    cb_params.dst = to;
00093 
00094    for ( cbp=slcb_hl ; cbp ; cbp=cbp->next ) {
00095       if (types&cbp->types) {
00096          cb_params.param = cbp->param;
00097          LM_DBG("callback id %d entered\n", cbp->id );
00098             cbp->callback( types&cbp->types, req, &cb_params);
00099       }
00100    }
00101 }

Generated on Thu May 24 12:00:30 2012 for Kamailio - The Open Source SIP Server by  doxygen 1.5.6