tmsrp_parser_header_Failure-Report.rl 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. * Copyright (C) 2009-2015 Mamadou DIOP.
  3. *
  4. * This file is part of Open Source Doubango Framework.
  5. *
  6. * DOUBANGO is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * DOUBANGO is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with DOUBANGO.
  18. *
  19. */
  20. /**@file tmsrp_header_Failure_Report.c
  21. * @brief MSRP 'Failure-Report' header.
  22. */
  23. #include "tinymsrp/headers/tmsrp_header_Failure-Report.h"
  24. #include "tsk_debug.h"
  25. #include "tsk_memory.h"
  26. #include "tsk_string.h"
  27. #include <string.h>
  28. /***********************************
  29. * Ragel state machine.
  30. */
  31. %%{
  32. machine tmsrp_machine_parser_header_Failure_Report;
  33. # Includes
  34. include tmsrp_machine_utils "./ragel/tmsrp_machine_utils.rl";
  35. action is_yes{
  36. hdr_Failure_Report->type = freport_yes;
  37. }
  38. action is_no{
  39. hdr_Failure_Report->type = freport_no;
  40. }
  41. action ispartial{
  42. hdr_Failure_Report->type = freport_partial;
  43. }
  44. #// "Failure-Report:" ( "yes" / "no" / "partial" )
  45. Failure_Report = "Failure-Report:"i SP ("yes"i %is_yes | "no"i %is_no | "partial"i %ispartial);
  46. # Entry point
  47. main := Failure_Report :>CRLF?;
  48. }%%
  49. tmsrp_header_Failure_Report_t* tmsrp_header_Failure_Report_create(tmsrp_freport_type_t freport_type)
  50. {
  51. return tsk_object_new(TMSRP_HEADER_FAILURE_REPORT_VA_ARGS(freport_type));
  52. }
  53. tmsrp_header_Failure_Report_t* tmsrp_header_Failure_Report_create_null()
  54. {
  55. return tmsrp_header_Failure_Report_create(freport_yes);
  56. }
  57. int tmsrp_header_Failure_Report_tostring(const tmsrp_header_t* header, tsk_buffer_t* output)
  58. {
  59. if(header){
  60. const tmsrp_header_Failure_Report_t *Failure_Report = (const tmsrp_header_Failure_Report_t *)header;
  61. const char* value = (Failure_Report->type == freport_yes) ? "yes" : (Failure_Report->type == freport_no ? "no" : "partial");
  62. return tsk_buffer_append(output, value, tsk_strlen(value));
  63. }
  64. return -1;
  65. }
  66. tmsrp_header_Failure_Report_t *tmsrp_header_Failure_Report_parse(const char *data, tsk_size_t size)
  67. {
  68. int cs = 0;
  69. const char *p = data;
  70. const char *pe = p + size;
  71. const char *eof = pe;
  72. tmsrp_header_Failure_Report_t *hdr_Failure_Report = tmsrp_header_Failure_Report_create_null();
  73. TSK_RAGEL_DISABLE_WARNINGS_BEGIN()
  74. %%write data;
  75. (void)(eof);
  76. (void)(tmsrp_machine_parser_header_Failure_Report_first_final);
  77. (void)(tmsrp_machine_parser_header_Failure_Report_error);
  78. (void)(tmsrp_machine_parser_header_Failure_Report_en_main);
  79. %%write init;
  80. %%write exec;
  81. TSK_RAGEL_DISABLE_WARNINGS_END()
  82. if( cs < %%{ write first_final; }%% ){
  83. TSK_DEBUG_ERROR("Failed to parse 'Failure-Report' header.");
  84. TSK_OBJECT_SAFE_FREE(hdr_Failure_Report);
  85. }
  86. return hdr_Failure_Report;
  87. }
  88. //========================================================
  89. // Failure_Report header object definition
  90. //
  91. static tsk_object_t* tmsrp_header_Failure_Report_ctor(tsk_object_t *self, va_list * app)
  92. {
  93. tmsrp_header_Failure_Report_t *Failure_Report = self;
  94. if(Failure_Report){
  95. TMSRP_HEADER(Failure_Report)->type = tmsrp_htype_Failure_Report;
  96. TMSRP_HEADER(Failure_Report)->tostring = tmsrp_header_Failure_Report_tostring;
  97. Failure_Report->type = va_arg(*app, tmsrp_freport_type_t);
  98. }
  99. else{
  100. TSK_DEBUG_ERROR("Failed to create new Failure-Report header.");
  101. }
  102. return self;
  103. }
  104. static tsk_object_t* tmsrp_header_Failure_Report_dtor(tsk_object_t *self)
  105. {
  106. tmsrp_header_Failure_Report_t *Failure_Report = self;
  107. if(Failure_Report){
  108. }
  109. else{
  110. TSK_DEBUG_ERROR("Null Failure-Report header.");
  111. }
  112. return self;
  113. }
  114. static const tsk_object_def_t tmsrp_header_Failure_Report_def_s =
  115. {
  116. sizeof(tmsrp_header_Failure_Report_t),
  117. tmsrp_header_Failure_Report_ctor,
  118. tmsrp_header_Failure_Report_dtor,
  119. tsk_null
  120. };
  121. const tsk_object_def_t *tmsrp_header_Failure_Report_def_t = &tmsrp_header_Failure_Report_def_s;