tmsrp_parser_header_Success-Report.rl 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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_Success_Report.c
  21. * @brief MSRP 'Success-Report' header.
  22. */
  23. #include "tinymsrp/headers/tmsrp_header_Success-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_Success_Report;
  33. # Includes
  34. include tmsrp_machine_utils "./ragel/tmsrp_machine_utils.rl";
  35. action is_yes{
  36. hdr_Success_Report->yes = 1;
  37. }
  38. action is_no{
  39. hdr_Success_Report->yes = 0;
  40. }
  41. #// "Success-Report:" ( "yes" / "no" )
  42. Success_Report = "Success-Report:"i SP ("yes"i %is_yes | "no"i %is_no);
  43. # Entry point
  44. main := Success_Report :>CRLF?;
  45. }%%
  46. tmsrp_header_Success_Report_t* tmsrp_header_Success_Report_create(tsk_bool_t isSuccess)
  47. {
  48. return tsk_object_new(TMSRP_HEADER_SUCCESS_REPORT_VA_ARGS(isSuccess));
  49. }
  50. tmsrp_header_Success_Report_t* tmsrp_header_Success_Report_create_null()
  51. {
  52. return tmsrp_header_Success_Report_create(tsk_false);
  53. }
  54. int tmsrp_header_Success_Report_tostring(const tmsrp_header_t* header, tsk_buffer_t* output)
  55. {
  56. if(header){
  57. const tmsrp_header_Success_Report_t *Success_Report = (const tmsrp_header_Success_Report_t *)header;
  58. const char* value = Success_Report->yes ? "yes" : "no";
  59. return tsk_buffer_append(output, value, tsk_strlen(value));
  60. }
  61. return -1;
  62. }
  63. tmsrp_header_Success_Report_t *tmsrp_header_Success_Report_parse(const char *data, tsk_size_t size)
  64. {
  65. int cs = 0;
  66. const char *p = data;
  67. const char *pe = p + size;
  68. const char *eof = pe;
  69. tmsrp_header_Success_Report_t *hdr_Success_Report = tmsrp_header_Success_Report_create_null();
  70. TSK_RAGEL_DISABLE_WARNINGS_BEGIN()
  71. %%write data;
  72. (void)(eof);
  73. (void)(tmsrp_machine_parser_header_Success_Report_first_final);
  74. (void)(tmsrp_machine_parser_header_Success_Report_error);
  75. (void)(tmsrp_machine_parser_header_Success_Report_en_main);
  76. %%write init;
  77. %%write exec;
  78. TSK_RAGEL_DISABLE_WARNINGS_END()
  79. if( cs < %%{ write first_final; }%% ){
  80. TSK_DEBUG_ERROR("Failed to parse 'Success-Report' header.");
  81. TSK_OBJECT_SAFE_FREE(hdr_Success_Report);
  82. }
  83. return hdr_Success_Report;
  84. }
  85. //========================================================
  86. // Success_Report header object definition
  87. //
  88. static tsk_object_t* tmsrp_header_Success_Report_ctor(tsk_object_t *self, va_list * app)
  89. {
  90. tmsrp_header_Success_Report_t *Success_Report = self;
  91. if(Success_Report){
  92. TMSRP_HEADER(Success_Report)->type = tmsrp_htype_Success_Report;
  93. TMSRP_HEADER(Success_Report)->tostring = tmsrp_header_Success_Report_tostring;
  94. Success_Report->yes = va_arg(*app, tsk_bool_t) ? 1 : 0;
  95. }
  96. else{
  97. TSK_DEBUG_ERROR("Failed to create new Success-Report header.");
  98. }
  99. return self;
  100. }
  101. static tsk_object_t* tmsrp_header_Success_Report_dtor(tsk_object_t *self)
  102. {
  103. tmsrp_header_Success_Report_t *Success_Report = self;
  104. if(Success_Report){
  105. }
  106. else{
  107. TSK_DEBUG_ERROR("Null Success-Report header.");
  108. }
  109. return self;
  110. }
  111. static const tsk_object_def_t tmsrp_header_Success_Report_def_s =
  112. {
  113. sizeof(tmsrp_header_Success_Report_t),
  114. tmsrp_header_Success_Report_ctor,
  115. tmsrp_header_Success_Report_dtor,
  116. tsk_null
  117. };
  118. const tsk_object_def_t *tmsrp_header_Success_Report_def_t = &tmsrp_header_Success_Report_def_s;