tmsrp_parser_header_Max-Expires.rl 3.7 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_Max_Expires.c
  21. * @brief MSRP 'Max-Expires' header.
  22. */
  23. #include "tinymsrp/headers/tmsrp_header_Max-Expires.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_Max_Expires;
  33. # Includes
  34. include tmsrp_machine_utils "./ragel/tmsrp_machine_utils.rl";
  35. action tag{
  36. tag_start = p;
  37. }
  38. action parse_value{
  39. TSK_PARSER_SET_INTEGER_EX(hdr_Max_Expires->value, int64_t, atoi64)
  40. }
  41. #// "Max-Expires:" SP 1*DIGIT
  42. Max_Expires = "Max-Expires:"i SP DIGIT+>tag %parse_value;
  43. # Entry point
  44. main := Max_Expires :>CRLF?;
  45. }%%
  46. tmsrp_header_Max_Expires_t* tmsrp_header_Max_Expires_create(int64_t value)
  47. {
  48. return tsk_object_new(TMSRP_HEADER_MAX_EXPIRES_VA_ARGS(value));
  49. }
  50. tmsrp_header_Max_Expires_t* tmsrp_header_Max_Expires_create_null()
  51. {
  52. return tmsrp_header_Max_Expires_create(-1);
  53. }
  54. int tmsrp_header_Max_Expires_tostring(const tmsrp_header_t* header, tsk_buffer_t* output)
  55. {
  56. if(header){
  57. const tmsrp_header_Max_Expires_t *Max_Expires = (const tmsrp_header_Max_Expires_t *)header;
  58. if(Max_Expires->value>=0){
  59. return tsk_buffer_append_2(output, "%lld", Max_Expires->value);
  60. }
  61. return 0;
  62. }
  63. return -1;
  64. }
  65. tmsrp_header_Max_Expires_t *tmsrp_header_Max_Expires_parse(const char *data, tsk_size_t size)
  66. {
  67. int cs = 0;
  68. const char *p = data;
  69. const char *pe = p + size;
  70. const char *eof = pe;
  71. tmsrp_header_Max_Expires_t *hdr_Max_Expires = tmsrp_header_Max_Expires_create_null();
  72. const char *tag_start = tsk_null;
  73. TSK_RAGEL_DISABLE_WARNINGS_BEGIN()
  74. %%write data;
  75. (void)(eof);
  76. (void)(tmsrp_machine_parser_header_Max_Expires_first_final);
  77. (void)(tmsrp_machine_parser_header_Max_Expires_error);
  78. (void)(tmsrp_machine_parser_header_Max_Expires_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 'Max-Expires' header.");
  84. TSK_OBJECT_SAFE_FREE(hdr_Max_Expires);
  85. }
  86. return hdr_Max_Expires;
  87. }
  88. //========================================================
  89. // Max-Expires header object definition
  90. //
  91. static tsk_object_t* tmsrp_header_Max_Expires_ctor(tsk_object_t *self, va_list * app)
  92. {
  93. tmsrp_header_Max_Expires_t *Max_Expires = self;
  94. if(Max_Expires){
  95. TMSRP_HEADER(Max_Expires)->type = tmsrp_htype_Max_Expires;
  96. TMSRP_HEADER(Max_Expires)->tostring = tmsrp_header_Max_Expires_tostring;
  97. Max_Expires->value = va_arg(*app, int64_t);
  98. }
  99. else{
  100. TSK_DEBUG_ERROR("Failed to create new Max-Expires header.");
  101. }
  102. return self;
  103. }
  104. static tsk_object_t* tmsrp_header_Max_Expires_dtor(tsk_object_t *self)
  105. {
  106. tmsrp_header_Max_Expires_t *Max_Expires = self;
  107. if(Max_Expires){
  108. }
  109. else{
  110. TSK_DEBUG_ERROR("Null Max-Expires header.");
  111. }
  112. return self;
  113. }
  114. static const tsk_object_def_t tmsrp_header_Max_Expires_def_s =
  115. {
  116. sizeof(tmsrp_header_Max_Expires_t),
  117. tmsrp_header_Max_Expires_ctor,
  118. tmsrp_header_Max_Expires_dtor,
  119. tsk_null
  120. };
  121. const tsk_object_def_t *tmsrp_header_Max_Expires_def_t = &tmsrp_header_Max_Expires_def_s;