publish.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 "publish.h"
  23. extern ctx_t* ctx;
  24. extern const session_t* session_handle_cmd(cmd_type_t , const opts_L_t*);
  25. int publish_handle_event(const tsip_event_t *_event)
  26. {
  27. const tsip_publish_event_t* pub_event = TSIP_PUBLISH_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(pub_event->type) {
  37. case tsip_ao_publish: { /* Answer to outgoing PUBLISH */
  38. if(_event->sipmessage) {
  39. if(TSIP_MESSAGE_IS_RESPONSE(_event->sipmessage)) {
  40. TSK_DEBUG_INFO("Event: Answer to outgoing PUBLISH. 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_unpublish: { /* Answer to outgoing unPUBLISH */
  50. if(_event->sipmessage) {
  51. if(TSIP_MESSAGE_IS_RESPONSE(_event->sipmessage)) {
  52. TSK_DEBUG_INFO("Event: Answer to outgoing UNPUBLISH. 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. /* Server events (For whose dev. Server Side IMS Services) */
  62. case tsip_i_publish: /* Incoming PUBLISH */
  63. case tsip_i_unpublish: { /* Incoming unPUBLISH */
  64. TSK_DEBUG_WARN("Event not support by Client Framework.");
  65. break;
  66. }
  67. default: {
  68. /* Any other event */
  69. TSK_DEBUG_WARN("%d not a valid SIP Subscription event.", pub_event->type);
  70. break;
  71. }
  72. }
  73. return 0;
  74. }
  75. tsip_ssession_id_t publish_handle_cmd(cmd_type_t cmd, const opts_L_t* opts)
  76. {
  77. const session_t* session = tsk_null;
  78. tsip_ssession_id_t id = TSIP_SSESSION_INVALID_ID;
  79. if(!(session = session_handle_cmd(cmd, opts))) {
  80. goto bail;
  81. }
  82. else {
  83. id = tsip_ssession_get_id(session->handle);
  84. }
  85. switch(cmd) {
  86. case cmd_publish: {
  87. /* Send SIP PUBLISH */
  88. tsip_action_handle_t* action_config = action_get_config(opts);
  89. tsip_api_publish_send_publish(session->handle,
  90. TSIP_ACTION_SET_CONFIG(action_config),
  91. /* Any other TSIP_ACTION_SET_*() macros */
  92. TSIP_ACTION_SET_NULL());
  93. TSK_OBJECT_SAFE_FREE(action_config);
  94. break;
  95. }
  96. default:
  97. /* already handled by session_handle_cmd() */
  98. break;
  99. }
  100. bail:
  101. return id;
  102. }