register.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 "register.h"
  23. extern ctx_t* ctx;
  24. extern const session_t* session_handle_cmd(cmd_type_t , const opts_L_t*);
  25. int register_handle_event(const tsip_event_t *_event)
  26. {
  27. const tsip_register_event_t* reg_event = TSIP_REGISTER_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(reg_event->type) {
  37. case tsip_ao_register: { /* Answer to outgoing REGISTER */
  38. if(_event->sipmessage) {
  39. if(TSIP_MESSAGE_IS_RESPONSE(_event->sipmessage)) {
  40. TSK_DEBUG_INFO("Event: Answer to outgoing REGISTER. 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_unregister: { /* Answer to outgoing unREGISTER */
  50. if(_event->sipmessage) {
  51. if(TSIP_MESSAGE_IS_RESPONSE(_event->sipmessage)) {
  52. TSK_DEBUG_INFO("Event: Answer to outgoing unREGISTER. 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_register: /* Incoming REGISTER */
  63. case tsip_i_unregister: { /* Incoming unREGISTER */
  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 Registration event.", reg_event->type);
  70. break;
  71. }
  72. }
  73. return 0;
  74. }
  75. tsip_ssession_id_t register_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. /* action config */
  86. /* Execute command */
  87. switch(cmd) {
  88. case cmd_register: {
  89. /* Send SIP REGISTER */
  90. tsip_action_handle_t* action_config = action_get_config(opts);
  91. tsip_api_register_send_register(session->handle,
  92. TSIP_ACTION_SET_CONFIG(action_config),
  93. /* Any other TSIP_ACTION_SET_*() macros */
  94. TSIP_ACTION_SET_NULL());
  95. TSK_OBJECT_SAFE_FREE(action_config);
  96. break;
  97. }
  98. default:
  99. /* already handled by session_handle_cmd() */
  100. break;
  101. }
  102. bail:
  103. return id;
  104. }