subscribe.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * Copyright (C) 2009 Mamadou Diop.
  3. *
  4. * Contact: Mamadou Diop <diopmamadou(at)doubango.org>
  5. *
  6. * This file is part of Open Source Doubango Framework.
  7. *
  8. * DOUBANGO is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * DOUBANGO is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with DOUBANGO.
  20. *
  21. */
  22. #include "subscribe.h"
  23. extern ctx_t* ctx;
  24. extern const session_t* session_handle_cmd(cmd_type_t , const opts_L_t*);
  25. int subscribe_handle_event(const tsip_event_t *_event)
  26. {
  27. const tsip_subscribe_event_t* sub_event = TSIP_SUBSCRIBE_EVENT(_event);
  28. const session_t* session;
  29. tsip_ssession_id_t sid;
  30. /* Find associated session */
  31. sid = tsip_ssession_get_id(_event->ss);
  32. if(!(session = session_get_by_sid(ctx->sessions, sid))) {
  33. TSK_DEBUG_WARN("Failed to match session event.");
  34. return -1;
  35. }
  36. switch(sub_event->type) {
  37. case tsip_ao_subscribe: { /* Answer to outgoing SUBSCRIBE */
  38. if(_event->sipmessage) {
  39. if(TSIP_MESSAGE_IS_RESPONSE(_event->sipmessage)) {
  40. TSK_DEBUG_INFO("Event: Answer to outgoing SUBSCRIBE. Code=%d and phrase=%s",
  41. _event->sipmessage->line.response.status_code, _event->sipmessage->line.response.reason_phrase);
  42. }
  43. else {
  44. // request
  45. }
  46. }
  47. break;
  48. }
  49. case tsip_ao_unsubscribe: { /* Answer to outgoing unSUBSCRIBE */
  50. if(_event->sipmessage) {
  51. if(TSIP_MESSAGE_IS_RESPONSE(_event->sipmessage)) {
  52. TSK_DEBUG_INFO("Event: Answer to outgoing unSUBSCRIBE. Code=%d and phrase=%s",
  53. _event->sipmessage->line.response.status_code, _event->sipmessage->line.response.reason_phrase);
  54. }
  55. else {
  56. // request
  57. }
  58. }
  59. break;
  60. }
  61. case tsip_i_notify: { /* Incoming NOTIFY */
  62. TSK_DEBUG_INFO("Event: Incoming NOTIFY.");
  63. if(TSIP_MESSAGE_HAS_CONTENT(_event->sipmessage)) {
  64. const tsk_buffer_t* content = TSIP_MESSAGE_CONTENT(_event->sipmessage);
  65. TSK_DEBUG_INFO("NOTIFY Content-Type: %s", TSIP_MESSAGE_CONTENT_TYPE(_event->sipmessage));
  66. TSK_DEBUG_INFO("NOTIFY Content: %s", content->data);
  67. }
  68. break;
  69. }
  70. /* Server events (For whose dev. Server Side IMS Services) */
  71. case tsip_i_subscribe: /* Incoming SUBSCRIBE */
  72. case tsip_i_unsubscribe: { /* Incoming unSUBSCRIBE */
  73. TSK_DEBUG_WARN("Event not support by Client Framework.");
  74. break;
  75. }
  76. default: {
  77. /* Any other event */
  78. TSK_DEBUG_WARN("%d not a valid SIP Subscription event.", sub_event->type);
  79. break;
  80. }
  81. }
  82. return 0;
  83. }
  84. tsip_ssession_id_t subscribe_handle_cmd(cmd_type_t cmd, const opts_L_t* opts)
  85. {
  86. const session_t* session = tsk_null;
  87. tsip_ssession_id_t id = TSIP_SSESSION_INVALID_ID;
  88. if(!(session = session_handle_cmd(cmd, opts))) {
  89. goto bail;
  90. }
  91. else {
  92. id = tsip_ssession_get_id(session->handle);
  93. }
  94. switch(cmd) {
  95. case cmd_subscribe: {
  96. /* Send SIP SUBSCRIBE */
  97. tsip_action_handle_t* action_config = action_get_config(opts);
  98. tsip_api_subscribe_send_subscribe(session->handle,
  99. TSIP_ACTION_SET_CONFIG(action_config),
  100. /* Any other TSIP_ACTION_SET_*() macros */
  101. TSIP_ACTION_SET_NULL());
  102. TSK_OBJECT_SAFE_FREE(action_config);
  103. break;
  104. }
  105. default:
  106. /* already handled by session_handle_cmd() */
  107. break;
  108. }
  109. bail:
  110. return id;
  111. }