tsip_parser_header_P_Charging_Function_Addresses.rl 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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_Charging_Function_Addresses.c
  23. * @brief SIP P-Charging-Function-Addresses header as per RFC 3455.
  24. *
  25. * @author Mamadou Diop <diopmamadou(at)doubango[dot]org>
  26. *
  27. */
  28. #include "tinysip/headers/tsip_header_P_Charging_Function_Addresses.h"
  29. #include "tinysip/parsers/tsip_parser_uri.h"
  30. #include "tsk_debug.h"
  31. #include "tsk_memory.h"
  32. #include "tsk_time.h"
  33. #include <string.h>
  34. /***********************************
  35. * Ragel state machine.
  36. */
  37. %%{
  38. machine tsip_machine_parser_header_P_Charging_Function_Addresses;
  39. # Includes
  40. include tsip_machine_utils "./ragel/tsip_machine_utils.rl";
  41. action tag{
  42. tag_start = p;
  43. }
  44. action create_p_charging_function_addresses{
  45. if(!curr_p_charging_function_addresses){
  46. curr_p_charging_function_addresses = tsip_header_P_Charging_Function_Addresses_create();
  47. }
  48. }
  49. action parse_ccf{
  50. if(!curr_p_charging_function_addresses->ccf){
  51. TSK_PARSER_SET_STRING(curr_p_charging_function_addresses->ccf);
  52. }
  53. }
  54. action parse_ecf{
  55. if(!curr_p_charging_function_addresses->ecf){
  56. TSK_PARSER_SET_STRING(curr_p_charging_function_addresses->ecf);
  57. }
  58. }
  59. action parse_param{
  60. if(curr_p_charging_function_addresses){
  61. TSK_PARSER_ADD_PARAM(TSIP_HEADER_PARAMS(curr_p_charging_function_addresses));
  62. }
  63. }
  64. action add_p_charging_function_addresses{
  65. if(curr_p_charging_function_addresses){
  66. tsk_list_push_back_data(hdr_p_charging_function_addressess, ((void**) &curr_p_charging_function_addresses));
  67. }
  68. }
  69. action eob{
  70. }
  71. ccf = "ccf"i EQUAL gen_value;
  72. ecf = "ecf"i EQUAL gen_value;
  73. charge_addr_params = (ccf>tag %parse_ccf | ecf>tag %parse_ecf | generic_param>tag %parse_param) >create_p_charging_function_addresses %add_p_charging_function_addresses;
  74. P_Charging_Addr = "P-Charging-Function-Addresses"i HCOLON charge_addr_params ( SEMI charge_addr_params )*;
  75. P_Charging_Function_Addresses = P_Charging_Addr;
  76. # Entry point
  77. main := P_Charging_Function_Addresses :>CRLF @eob;
  78. }%%
  79. tsip_header_P_Charging_Function_Addresses_t* tsip_header_P_Charging_Function_Addresses_create()
  80. {
  81. return tsk_object_new(tsip_header_P_Charging_Function_Addresses_def_t);
  82. }
  83. int tsip_header_P_Charging_Function_Addresses_serialize(const tsip_header_t* header, tsk_buffer_t* output)
  84. {
  85. if(header){
  86. const tsip_header_P_Charging_Function_Addresses_t *P_Charging_Function_Addresses = (const tsip_header_P_Charging_Function_Addresses_t *)header;
  87. return tsk_buffer_append_2(output, "%s%s%s%s%s",
  88. P_Charging_Function_Addresses->ecf ? "ecf=" : "",
  89. P_Charging_Function_Addresses->ecf ? P_Charging_Function_Addresses->ecf : "",
  90. (P_Charging_Function_Addresses->ecf && P_Charging_Function_Addresses->ccf) ? ";" : "",
  91. P_Charging_Function_Addresses->ccf ? "ccf=" : "",
  92. P_Charging_Function_Addresses->ccf ? P_Charging_Function_Addresses->ccf : ""
  93. );
  94. }
  95. return -1;
  96. }
  97. tsip_header_P_Charging_Function_Addressess_L_t *tsip_header_P_Charging_Function_Addresses_parse(const char *data, tsk_size_t size)
  98. {
  99. int cs = 0;
  100. const char *p = data;
  101. const char *pe = p + size;
  102. const char *eof = pe;
  103. tsip_header_P_Charging_Function_Addressess_L_t *hdr_p_charging_function_addressess = tsk_list_create();
  104. const char *tag_start = tsk_null;
  105. tsip_header_P_Charging_Function_Addresses_t *curr_p_charging_function_addresses = 0;
  106. %%write data;
  107. (void)(eof);
  108. (void)(tsip_machine_parser_header_P_Charging_Function_Addresses_first_final);
  109. (void)(tsip_machine_parser_header_P_Charging_Function_Addresses_error);
  110. (void)(tsip_machine_parser_header_P_Charging_Function_Addresses_en_main);
  111. %%write init;
  112. %%write exec;
  113. if( cs < %%{ write first_final; }%% ){
  114. TSK_DEBUG_ERROR("Failed to parse 'P-Charging-Function-Addresses' header.");
  115. TSK_OBJECT_SAFE_FREE(curr_p_charging_function_addresses);
  116. TSK_OBJECT_SAFE_FREE(hdr_p_charging_function_addressess);
  117. }
  118. return hdr_p_charging_function_addressess;
  119. }
  120. //========================================================
  121. // P_Charging_Function_Addresses header object definition
  122. //
  123. static tsk_object_t* tsip_header_P_Charging_Function_Addresses_ctor(tsk_object_t *self, va_list * app)
  124. {
  125. tsip_header_P_Charging_Function_Addresses_t *P_Charging_Function_Addresses = self;
  126. if(P_Charging_Function_Addresses){
  127. TSIP_HEADER(P_Charging_Function_Addresses)->type = tsip_htype_P_Charging_Function_Addresses;
  128. TSIP_HEADER(P_Charging_Function_Addresses)->serialize = tsip_header_P_Charging_Function_Addresses_serialize;
  129. }
  130. else{
  131. TSK_DEBUG_ERROR("Failed to create new P_Charging_Function_Addresses header.");
  132. }
  133. return self;
  134. }
  135. static tsk_object_t* tsip_header_P_Charging_Function_Addresses_dtor(tsk_object_t *self)
  136. {
  137. tsip_header_P_Charging_Function_Addresses_t *P_Charging_Function_Addresses = self;
  138. if(P_Charging_Function_Addresses){
  139. TSK_FREE(P_Charging_Function_Addresses->ecf);
  140. TSK_FREE(P_Charging_Function_Addresses->ccf);
  141. TSK_OBJECT_SAFE_FREE(TSIP_HEADER_PARAMS(P_Charging_Function_Addresses));
  142. }
  143. else{
  144. TSK_DEBUG_ERROR("Null P_Charging_Function_Addresses header.");
  145. }
  146. return self;
  147. }
  148. static const tsk_object_def_t tsip_header_P_Charging_Function_Addresses_def_s =
  149. {
  150. sizeof(tsip_header_P_Charging_Function_Addresses_t),
  151. tsip_header_P_Charging_Function_Addresses_ctor,
  152. tsip_header_P_Charging_Function_Addresses_dtor,
  153. tsk_null
  154. };
  155. const tsk_object_def_t *tsip_header_P_Charging_Function_Addresses_def_t = &tsip_header_P_Charging_Function_Addresses_def_s;