xmpp_api.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * $Id$
  3. *
  4. * XMPP Module
  5. * This file is part of Kamailio, a free SIP server.
  6. *
  7. * Copyright (C) 2006 Voice Sistem S.R.L.
  8. *
  9. * Kamailio is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version
  13. *
  14. * Kamailio is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. *
  23. *
  24. */
  25. /*! \file
  26. * \brief Kamailio XMPP :: API
  27. * \ingroup xmpp
  28. */
  29. #include <stdlib.h>
  30. #include <string.h>
  31. #include "../../dprint.h"
  32. #include "../../error.h"
  33. #include "../../mem/shm_mem.h"
  34. #include "xmpp_api.h"
  35. xmpp_cb_list_t *_xmpp_cb_list = 0;
  36. int init_xmpp_cb_list(void)
  37. {
  38. _xmpp_cb_list = (xmpp_cb_list_t*)shm_malloc(sizeof(xmpp_cb_list_t));
  39. if (_xmpp_cb_list==0) {
  40. LM_CRIT("no more shared memory\n");
  41. return -1;
  42. }
  43. memset(_xmpp_cb_list, 0, sizeof(xmpp_cb_list_t));
  44. return 0;
  45. }
  46. void destroy_xmpp_cb_list(void)
  47. {
  48. xmpp_callback_t *it, *it1;
  49. if (_xmpp_cb_list==0)
  50. return;
  51. for(it=_xmpp_cb_list->first; it; ) {
  52. it1 = it;
  53. it = it->next;
  54. shm_free(it1);
  55. }
  56. shm_free(_xmpp_cb_list);
  57. _xmpp_cb_list = 0;
  58. }
  59. /*! \brief register a callback function 'f' for 'types' mask of events;
  60. */
  61. int register_xmpp_cb( int types, xmpp_cb_f f, void *param )
  62. {
  63. xmpp_callback_t *it;
  64. if(_xmpp_cb_list==0)
  65. {
  66. LM_CRIT("null callback list\n");
  67. return E_BUG;
  68. }
  69. /* check null functions */
  70. if (f==0) {
  71. LM_CRIT("null callback function\n");
  72. return E_BUG;
  73. }
  74. /* build callback structure */
  75. if (!(it=(xmpp_callback_t*)shm_malloc(sizeof(xmpp_callback_t))))
  76. {
  77. LM_ERR("no more share memory\n");
  78. return E_OUT_OF_MEM;
  79. }
  80. memset(it, 0, sizeof(xmpp_callback_t));
  81. it->next = _xmpp_cb_list->first;
  82. _xmpp_cb_list->first = it;
  83. _xmpp_cb_list->types |= types;
  84. it->cbf = f;
  85. it->cbp = param;
  86. it->types = types;
  87. return 1;
  88. }
  89. int bind_xmpp(xmpp_api_t* api)
  90. {
  91. if (api==NULL)
  92. {
  93. LM_ERR("invalid parameter value\n");
  94. return -1;
  95. }
  96. api->register_callback = register_xmpp_cb;
  97. api->xpacket = xmpp_send_xpacket;
  98. api->xmessage = xmpp_send_xmessage;
  99. api->xsubscribe = xmpp_send_xsubscribe;
  100. api->xnotify = xmpp_send_xnotify;
  101. api->decode_uri_sip_xmpp = decode_uri_sip_xmpp;
  102. api->encode_uri_sip_xmpp = encode_uri_sip_xmpp;
  103. api->decode_uri_xmpp_sip = decode_uri_xmpp_sip;
  104. api->encode_uri_xmpp_sip = encode_uri_xmpp_sip;
  105. return 0;
  106. }