00001 00002 /* 00003 * $Id: xmpp_api.c 4585 2008-08-06 08:20:30Z klaus_darilion $ 00004 * 00005 * XMPP Module 00006 * This file is part of Kamailio, a free SIP server. 00007 * 00008 * Copyright (C) 2006 Voice Sistem S.R.L. 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 */ 00026 /*! \file 00027 * \brief Kamailio XMPP :: API 00028 * \ingroup xmpp 00029 */ 00030 00031 00032 #include <stdlib.h> 00033 #include <string.h> 00034 00035 #include "../../dprint.h" 00036 #include "../../error.h" 00037 #include "../../mem/shm_mem.h" 00038 #include "xmpp_api.h" 00039 00040 00041 xmpp_cb_list_t *_xmpp_cb_list = 0; 00042 00043 00044 int init_xmpp_cb_list(void) 00045 { 00046 _xmpp_cb_list = (xmpp_cb_list_t*)shm_malloc(sizeof(xmpp_cb_list_t)); 00047 if (_xmpp_cb_list==0) { 00048 LM_CRIT("no more shared memory\n"); 00049 return -1; 00050 } 00051 memset(_xmpp_cb_list, 0, sizeof(xmpp_cb_list_t)); 00052 return 0; 00053 } 00054 00055 00056 void destroy_xmpp_cb_list(void) 00057 { 00058 xmpp_callback_t *it, *it1; 00059 00060 if (_xmpp_cb_list==0) 00061 return; 00062 00063 for(it=_xmpp_cb_list->first; it; ) { 00064 it1 = it; 00065 it = it->next; 00066 shm_free(it1); 00067 } 00068 00069 shm_free(_xmpp_cb_list); 00070 _xmpp_cb_list = 0; 00071 } 00072 00073 00074 00075 /*! \brief register a callback function 'f' for 'types' mask of events; 00076 */ 00077 int register_xmpp_cb( int types, xmpp_cb_f f, void *param ) 00078 { 00079 xmpp_callback_t *it; 00080 00081 if(_xmpp_cb_list==0) 00082 { 00083 LM_CRIT("null callback list\n"); 00084 return E_BUG; 00085 } 00086 00087 /* check null functions */ 00088 if (f==0) { 00089 LM_CRIT("null callback function\n"); 00090 return E_BUG; 00091 } 00092 00093 /* build callback structure */ 00094 if (!(it=(xmpp_callback_t*)shm_malloc(sizeof(xmpp_callback_t)))) 00095 { 00096 LM_ERR("no more share memory\n"); 00097 return E_OUT_OF_MEM; 00098 } 00099 00100 memset(it, 0, sizeof(xmpp_callback_t)); 00101 it->next = _xmpp_cb_list->first; 00102 _xmpp_cb_list->first = it; 00103 _xmpp_cb_list->types |= types; 00104 00105 it->cbf = f; 00106 it->cbp = param; 00107 it->types = types; 00108 00109 return 1; 00110 } 00111 00112 00113 int bind_xmpp(xmpp_api_t* api) 00114 { 00115 if (api==NULL) 00116 { 00117 LM_ERR("invalid parameter value\n"); 00118 return -1; 00119 } 00120 api->register_callback = register_xmpp_cb; 00121 api->xpacket = xmpp_send_xpacket; 00122 api->xmessage = xmpp_send_xmessage; 00123 api->xsubscribe = xmpp_send_xsubscribe; 00124 api->xnotify = xmpp_send_xnotify; 00125 api->decode_uri_sip_xmpp = decode_uri_sip_xmpp; 00126 api->encode_uri_sip_xmpp = encode_uri_sip_xmpp; 00127 api->decode_uri_xmpp_sip = decode_uri_xmpp_sip; 00128 api->encode_uri_xmpp_sip = encode_uri_xmpp_sip; 00129 00130 return 0; 00131 } 00132
1.5.6