Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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
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
00088 if (f==0) {
00089 LM_CRIT("null callback function\n");
00090 return E_BUG;
00091 }
00092
00093
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