PageRenderTime 80ms CodeModel.GetById 32ms RepoModel.GetById 0ms app.codeStats 0ms

/doubango/tinyDEMO/publish.c

https://gitlab.com/iwan.aucamp/doubango
C | 117 lines | 78 code | 12 blank | 27 comment | 6 complexity | aba8645a924c4507da92248b28ef3561 MD5 | raw file
  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. {
  39. if(_event->sipmessage){
  40. if(TSIP_MESSAGE_IS_RESPONSE(_event->sipmessage)){
  41. TSK_DEBUG_INFO("Event: Answer to outgoing PUBLISH. Code=%d and phrase=%s",
  42. _event->sipmessage->line.response.status_code, _event->sipmessage->line.response.reason_phrase);
  43. }
  44. else{
  45. // request
  46. }
  47. }
  48. break;
  49. }
  50. case tsip_ao_unpublish: /* Answer to outgoing unPUBLISH */
  51. {
  52. if(_event->sipmessage){
  53. if(TSIP_MESSAGE_IS_RESPONSE(_event->sipmessage)){
  54. TSK_DEBUG_INFO("Event: Answer to outgoing UNPUBLISH. Code=%d and phrase=%s",
  55. _event->sipmessage->line.response.status_code, _event->sipmessage->line.response.reason_phrase);
  56. }
  57. else{
  58. // request
  59. }
  60. }
  61. break;
  62. }
  63. /* Server events (For whose dev. Server Side IMS Services) */
  64. case tsip_i_publish: /* Incoming PUBLISH */
  65. case tsip_i_unpublish: /* Incoming unPUBLISH */
  66. {
  67. TSK_DEBUG_WARN("Event not support by Client Framework.");
  68. break;
  69. }
  70. default:
  71. { /* Any other event */
  72. TSK_DEBUG_WARN("%d not a valid SIP Subscription event.", pub_event->type);
  73. break;
  74. }
  75. }
  76. return 0;
  77. }
  78. tsip_ssession_id_t publish_handle_cmd(cmd_type_t cmd, const opts_L_t* opts)
  79. {
  80. const session_t* session = tsk_null;
  81. tsip_ssession_id_t id = TSIP_SSESSION_INVALID_ID;
  82. if(!(session = session_handle_cmd(cmd, opts))){
  83. goto bail;
  84. }
  85. else{
  86. id = tsip_ssession_get_id(session->handle);
  87. }
  88. switch(cmd){
  89. case cmd_publish:
  90. { /* Send SIP PUBLISH */
  91. tsip_action_handle_t* action_config = action_get_config(opts);
  92. tsip_api_publish_send_publish(session->handle,
  93. TSIP_ACTION_SET_CONFIG(action_config),
  94. /* Any other TSIP_ACTION_SET_*() macros */
  95. TSIP_ACTION_SET_NULL());
  96. TSK_OBJECT_SAFE_FREE(action_config);
  97. break;
  98. }
  99. default:
  100. /* already handled by session_handle_cmd() */
  101. break;
  102. }
  103. bail:
  104. return id;
  105. }