rx_authdata.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. * $Id$
  3. *
  4. * Copyright (C) 2012 Smile Communications, [email protected]
  5. * Copyright (C) 2012 Smile Communications, [email protected]
  6. *
  7. * The initial version of this code was written by Dragos Vingarzan
  8. * (dragos(dot)vingarzan(at)fokus(dot)fraunhofer(dot)de and the
  9. * Fruanhofer Institute. It was and still is maintained in a separate
  10. * branch of the original SER. We are therefore migrating it to
  11. * Kamailio/SR and look forward to maintaining it from here on out.
  12. * 2011/2012 Smile Communications, Pty. Ltd.
  13. * ported/maintained/improved by
  14. * Jason Penton (jason(dot)penton(at)smilecoms.com and
  15. * Richard Good (richard(dot)good(at)smilecoms.com) as part of an
  16. * effort to add full IMS support to Kamailio/SR using a new and
  17. * improved architecture
  18. *
  19. * NB: Alot of this code was originally part of OpenIMSCore,
  20. * FhG Fokus.
  21. * Copyright (C) 2004-2006 FhG Fokus
  22. * Thanks for great work! This is an effort to
  23. * break apart the various CSCF functions into logically separate
  24. * components. We hope this will drive wider use. We also feel
  25. * that in this way the architecture is more complete and thereby easier
  26. * to manage in the Kamailio/SR environment
  27. *
  28. * This file is part of Kamailio, a free SIP server.
  29. *
  30. * Kamailio is free software; you can redistribute it and/or modify
  31. * it under the terms of the GNU General Public License as published by
  32. * the Free Software Foundation; either version 2 of the License, or
  33. * (at your option) any later version
  34. *
  35. * Kamailio is distributed in the hope that it will be useful,
  36. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  37. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  38. * GNU General Public License for more details.
  39. *
  40. * You should have received a copy of the GNU General Public License
  41. * along with this program; if not, write to the Free Software
  42. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  43. *
  44. *
  45. *
  46. * History:
  47. * --------
  48. * 2011-02-02 initial version (jason.penton)
  49. */
  50. #include "../../sr_module.h"
  51. #include "../../ut.h"
  52. #include "../../mem/shm_mem.h"
  53. #include "../../parser/contact/parse_contact.h"
  54. #include "../../locking.h"
  55. #include "../tm/tm_load.h"
  56. #include "../../modules/dialog_ng/dlg_load.h"
  57. #include "../../modules/dialog_ng/dlg_hash.h"
  58. #include "../ims_usrloc_pcscf/usrloc.h"
  59. #include "../../mem/shm_mem.h"
  60. #include "../../parser/sdp/sdp_helpr_funcs.h"
  61. #include "../../parser/sdp/sdp.h"
  62. #include "../../parser/parse_rr.h"
  63. #include "../cdp/cdp_load.h"
  64. #include "rx_authdata.h"
  65. #include "rx_avp.h"
  66. #include "../../lib/ims/ims_getters.h"
  67. #include "mod.h"
  68. int create_new_regsessiondata(str* domain, str* aor, rx_authsessiondata_t** session_data) {
  69. int len = (domain->len + 1) + aor->len + sizeof(rx_authsessiondata_t);
  70. rx_authsessiondata_t* p_session_data = shm_malloc(len);
  71. if (!p_session_data) {
  72. LM_ERR("no more shm memory\n");
  73. return -1;
  74. }
  75. memset(p_session_data, 0, len);
  76. p_session_data->subscribed_to_signaling_path_status = 1;
  77. char* p = (char*)(p_session_data + 1);
  78. p_session_data->domain.s = p;
  79. memcpy(p, domain->s, domain->len);
  80. p_session_data->domain.len = domain->len;
  81. p += domain->len;
  82. *p++ = '\0';
  83. p_session_data->registration_aor.s = p;
  84. memcpy(p, aor->s, aor->len);
  85. p_session_data->registration_aor.len = aor->len;
  86. p += aor->len;
  87. if (p != (((char*)p_session_data) + len)) {
  88. LM_ERR("buffer over/underflow\n");
  89. shm_free(p_session_data);
  90. p_session_data = 0;
  91. return -1;
  92. }
  93. *session_data = p_session_data;
  94. return 1;
  95. }
  96. int create_new_callsessiondata(str* callid, str* ftag, str* ttag, rx_authsessiondata_t** session_data) {
  97. int len = callid->len + ftag->len + ttag->len + sizeof(rx_authsessiondata_t);
  98. rx_authsessiondata_t* call_session_data = shm_malloc(len);
  99. if (!call_session_data){
  100. LM_ERR("no more shm mem trying to create call_session_data of size %d\n", len);
  101. return -1;
  102. }
  103. memset(call_session_data, 0, len);
  104. call_session_data->subscribed_to_signaling_path_status = 0; //this is for a media session not regitration
  105. char *p = (char*)(call_session_data + 1);
  106. if (callid && callid->len>0 && callid->s) {
  107. LM_DBG("Copying callid [%.*s] into call session data\n", callid->len, callid->s);
  108. call_session_data->callid.s = p;
  109. memcpy(call_session_data->callid.s, callid->s, callid->len);
  110. call_session_data->callid.len = callid->len;
  111. p+=callid->len;
  112. }
  113. if (ftag && ftag->len > 0 && ftag->s) {
  114. LM_DBG("Copying ftag [%.*s] into call session data\n", ftag->len, ftag->s);
  115. call_session_data->ftag.s = p;
  116. memcpy(call_session_data->ftag.s, ftag->s, ftag->len);
  117. call_session_data->ftag.len = ftag->len;
  118. p += ftag->len;
  119. }
  120. if (ttag && ttag->len > 0 && ttag->s) {
  121. LM_DBG("Copying ttag [%.*s] into call session data\n", ttag->len, ttag->s);
  122. call_session_data->ttag.s = p;
  123. memcpy(call_session_data->ttag.s, ttag->s, ttag->len);
  124. call_session_data->ttag.len = ttag->len;
  125. p += ttag->len;
  126. }
  127. if (p != ((char*)(call_session_data) + len)) {
  128. LM_ERR("buffer under/overflow\n");
  129. shm_free(call_session_data);
  130. return -1;
  131. }
  132. *session_data = call_session_data;
  133. return 1;
  134. }