tsip_parser_header_P_Access_Network_Info.rl 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*
  2. * Copyright (C) 2010-2011 Mamadou Diop.
  3. *
  4. * Contact: Mamadou Diop <diopmamadou(at)doubango[dot]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. /**@file tsip_header_P_Access_Network_Info.c
  23. * @brief SIP P_Access_Network_Info header as per RFC 3455.
  24. *
  25. * Header field where proxy ACK BYE CAN INV OPT REG
  26. ___________________________________________________________
  27. P-Access-Network-Info dr - o - o o o
  28. Header field SUB NOT PRA INF UPD MSG REF
  29. ___________________________________________________________
  30. P-Access-Network-Info o o o o o o o
  31. *
  32. * @author Mamadou Diop <diopmamadou(at)doubango[dot]org>
  33. *
  34. */
  35. #include "tinysip/headers/tsip_header_P_Access_Network_Info.h"
  36. #include "tinysip/parsers/tsip_parser_uri.h"
  37. #include "tsk_debug.h"
  38. #include "tsk_memory.h"
  39. #include <string.h>
  40. /***********************************
  41. * Ragel state machine.
  42. */
  43. %%{
  44. machine tsip_machine_parser_header_P_Access_Network_Info;
  45. # Includes
  46. include tsip_machine_utils "./ragel/tsip_machine_utils.rl";
  47. action tag{
  48. tag_start = p;
  49. }
  50. action parse_value{
  51. TSK_PARSER_SET_STRING(hdr_ani->value);
  52. }
  53. action eob{
  54. }
  55. P_Access_Network_Info = "P-Access-Network-Info"i HCOLON (any*)>tag %parse_value;
  56. # Entry point
  57. main := P_Access_Network_Info :>CRLF @eob;
  58. }%%
  59. tsip_header_P_Access_Network_Info_t* tsip_header_P_Access_Network_Info_create(const char* value)
  60. {
  61. return tsk_object_new(TSIP_HEADER_P_ACCESS_NETWORK_INFO_VA_ARGS(value));
  62. }
  63. tsip_header_P_Access_Network_Info_t* tsip_header_P_Access_Network_Info_create_null()
  64. {
  65. return tsip_header_P_Access_Network_Info_create(tsk_null);
  66. }
  67. int tsip_header_P_Access_Network_Info_serialize(const tsip_header_t* header, tsk_buffer_t* output)
  68. {
  69. if(header){
  70. const tsip_header_P_Access_Network_Info_t *P_Access_Network_Info = (const tsip_header_P_Access_Network_Info_t *)header;
  71. if(P_Access_Network_Info->value){
  72. tsk_buffer_append(output, P_Access_Network_Info->value, tsk_strlen(P_Access_Network_Info->value));
  73. }
  74. return 0;
  75. }
  76. return -1;
  77. }
  78. tsip_header_P_Access_Network_Info_t *tsip_header_P_Access_Network_Info_parse(const char *data, tsk_size_t size)
  79. {
  80. int cs = 0;
  81. const char *p = data;
  82. const char *pe = p + size;
  83. const char *eof = pe;
  84. tsip_header_P_Access_Network_Info_t *hdr_ani = tsip_header_P_Access_Network_Info_create_null();
  85. const char *tag_start = tsk_null;
  86. %%write data;
  87. (void)(eof);
  88. (void)(tsip_machine_parser_header_P_Access_Network_Info_first_final);
  89. (void)(tsip_machine_parser_header_P_Access_Network_Info_error);
  90. (void)(tsip_machine_parser_header_P_Access_Network_Info_en_main);
  91. %%write init;
  92. %%write exec;
  93. if( cs < %%{ write first_final; }%% ){
  94. TSK_DEBUG_ERROR("Failed to parse 'P-Access-Network-Info' header.");
  95. TSK_OBJECT_SAFE_FREE(hdr_ani);
  96. }
  97. return hdr_ani;
  98. }
  99. //========================================================
  100. // P_Access_Network_Info header object definition
  101. //
  102. static tsk_object_t* tsip_header_P_Access_Network_Info_ctor(tsk_object_t *self, va_list * app)
  103. {
  104. tsip_header_P_Access_Network_Info_t *P_Access_Network_Info = self;
  105. if(P_Access_Network_Info){
  106. P_Access_Network_Info->value = tsk_strdup(va_arg(*app, const char *));
  107. TSIP_HEADER(P_Access_Network_Info)->type = tsip_htype_P_Access_Network_Info;
  108. TSIP_HEADER(P_Access_Network_Info)->serialize = tsip_header_P_Access_Network_Info_serialize;
  109. }
  110. else{
  111. TSK_DEBUG_ERROR("Failed to create new P_Access_Network_Info header.");
  112. }
  113. return self;
  114. }
  115. static tsk_object_t* tsip_header_P_Access_Network_Info_dtor(tsk_object_t *self)
  116. {
  117. tsip_header_P_Access_Network_Info_t *P_Access_Network_Info = self;
  118. if(P_Access_Network_Info){
  119. TSK_FREE(P_Access_Network_Info->value);
  120. }
  121. else{
  122. TSK_DEBUG_ERROR("Null P_Access_Network_Info header.");
  123. }
  124. return self;
  125. }
  126. static const tsk_object_def_t tsip_header_P_Access_Network_Info_def_s =
  127. {
  128. sizeof(tsip_header_P_Access_Network_Info_t),
  129. tsip_header_P_Access_Network_Info_ctor,
  130. tsip_header_P_Access_Network_Info_dtor,
  131. tsk_null
  132. };
  133. const tsk_object_def_t *tsip_header_P_Access_Network_Info_def_t = &tsip_header_P_Access_Network_Info_def_s;