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 128 129 130 131 132
|
/*
* $Id$
*
* XMPP Module
* This file is part of Kamailio, a free SIP server.
*
* Copyright (C) 2006 Voice Sistem S.R.L.
*
* 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
*
*
*/
/*! \file
* \brief Kamailio XMPP :: API
* \ingroup xmpp
*/
#include <stdlib.h>
#include <string.h>
#include "../../dprint.h"
#include "../../error.h"
#include "../../mem/shm_mem.h"
#include "xmpp_api.h"
xmpp_cb_list_t *_xmpp_cb_list = 0;
int init_xmpp_cb_list(void)
{
_xmpp_cb_list = (xmpp_cb_list_t*)shm_malloc(sizeof(xmpp_cb_list_t));
if (_xmpp_cb_list==0) {
LM_CRIT("no more shared memory\n");
return -1;
}
memset(_xmpp_cb_list, 0, sizeof(xmpp_cb_list_t));
return 0;
}
void destroy_xmpp_cb_list(void)
{
xmpp_callback_t *it, *it1;
if (_xmpp_cb_list==0)
return;
for(it=_xmpp_cb_list->first; it; ) {
it1 = it;
it = it->next;
shm_free(it1);
}
shm_free(_xmpp_cb_list);
_xmpp_cb_list = 0;
}
/*! \brief register a callback function 'f' for 'types' mask of events;
*/
int register_xmpp_cb( int types, xmpp_cb_f f, void *param )
{
xmpp_callback_t *it;
if(_xmpp_cb_list==0)
{
LM_CRIT("null callback list\n");
return E_BUG;
}
/* check null functions */
if (f==0) {
LM_CRIT("null callback function\n");
return E_BUG;
}
/* build callback structure */
if (!(it=(xmpp_callback_t*)shm_malloc(sizeof(xmpp_callback_t))))
{
LM_ERR("no more share memory\n");
return E_OUT_OF_MEM;
}
memset(it, 0, sizeof(xmpp_callback_t));
it->next = _xmpp_cb_list->first;
_xmpp_cb_list->first = it;
_xmpp_cb_list->types |= types;
it->cbf = f;
it->cbp = param;
it->types = types;
return 1;
}
int bind_xmpp(xmpp_api_t* api)
{
if (api==NULL)
{
LM_ERR("invalid parameter value\n");
return -1;
}
api->register_callback = register_xmpp_cb;
api->xpacket = xmpp_send_xpacket;
api->xmessage = xmpp_send_xmessage;
api->xsubscribe = xmpp_send_xsubscribe;
api->xnotify = xmpp_send_xnotify;
api->decode_uri_sip_xmpp = decode_uri_sip_xmpp;
api->encode_uri_sip_xmpp = encode_uri_sip_xmpp;
api->decode_uri_xmpp_sip = decode_uri_xmpp_sip;
api->encode_uri_xmpp_sip = encode_uri_xmpp_sip;
return 0;
}
|