PageRenderTime 35ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/doubango/tinySIP/src/headers/tsip_header_Date.c

https://gitlab.com/iwan.aucamp/doubango
C | 466 lines | 350 code | 61 blank | 55 comment | 32 complexity | e3cdadc78d5fe02b056a4f6598974450 MD5 | raw file
  1. /* #line 1 "./ragel/tsip_parser_header_Date.rl" */
  2. /*
  3. * Copyright (C) 2010-2011 Mamadou Diop.
  4. *
  5. * Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
  6. *
  7. * This file is part of Open Source Doubango Framework.
  8. *
  9. * DOUBANGO is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation, either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * DOUBANGO is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with DOUBANGO.
  21. *
  22. */
  23. /**@file tsip_header_Date.c
  24. * @brief SIP DUmmy header.
  25. *
  26. * @author Mamadou Diop <diopmamadou(at)doubango[dot]org>
  27. *
  28. */
  29. #include "tinysip/headers/tsip_header_Date.h"
  30. #include "tinysip/parsers/tsip_parser_uri.h"
  31. #include "tsk_debug.h"
  32. #include "tsk_memory.h"
  33. #include <string.h>
  34. /***********************************
  35. * Ragel state machine.
  36. */
  37. /* #line 96 "./ragel/tsip_parser_header_Date.rl" */
  38. tsip_header_Date_t* tsip_header_Date_create(const char* wkday, const char* month, int8_t day, int16_t year, int8_t h, int8_t m, int8_t s)
  39. {
  40. return tsk_object_new(TSIP_HEADER_DATE_VA_ARGS(wkday, month, day, year, h, m, s));
  41. }
  42. tsip_header_Date_t* tsip_header_Date_create_null()
  43. {
  44. return tsip_header_Date_create(tsk_null, tsk_null, -1, -1, -1, -1, -1);
  45. }
  46. int tsip_header_Date_serialize(const tsip_header_t* header, tsk_buffer_t* output)
  47. {
  48. /* Date: Wed, 28 Apr 2010 23:42:50 GMT */
  49. if(header){
  50. const tsip_header_Date_t *Date = (const tsip_header_Date_t *)header;
  51. if(Date->month){
  52. tsk_buffer_append_2(output, "%s, %d %s %d %d:%d:%d GMT",
  53. Date->wkday, Date->day, Date->month, Date->year, Date->time.h, Date->time.m, Date->time.s);
  54. }
  55. return 0;
  56. }
  57. return -1;
  58. }
  59. tsip_header_Date_t *tsip_header_Date_parse(const char *data, tsk_size_t size)
  60. {
  61. int cs = 0;
  62. const char *p = data;
  63. const char *pe = p + size;
  64. const char *eof = pe;
  65. tsip_header_Date_t *hdr_Date = tsip_header_Date_create_null();
  66. const char *tag_start = tsk_null;
  67. /* #line 87 "./src/headers/tsip_header_Date.c" */
  68. static const char _tsip_machine_parser_header_Date_actions[] = {
  69. 0, 1, 0, 1, 1, 1, 2, 1,
  70. 3, 1, 4, 1, 5, 1, 6, 1,
  71. 7, 1, 8
  72. };
  73. static const unsigned char _tsip_machine_parser_header_Date_key_offsets[] = {
  74. 0, 0, 2, 4, 6, 8, 11, 24,
  75. 25, 27, 39, 41, 43, 44, 45, 47,
  76. 49, 50, 66, 70, 72, 73, 75, 77,
  77. 79, 81, 82, 84, 86, 87, 89, 91,
  78. 92, 94, 96, 97, 99, 101, 103, 104,
  79. 105, 107, 109, 111, 113, 115, 119, 121,
  80. 125, 127, 131, 133, 135, 137, 139, 141,
  81. 143, 145, 147, 151, 153, 157, 159, 161,
  82. 163, 165
  83. };
  84. static const char _tsip_machine_parser_header_Date_trans_keys[] = {
  85. 68, 100, 65, 97, 84, 116, 69, 101,
  86. 9, 32, 58, 9, 13, 32, 70, 77,
  87. 83, 84, 87, 102, 109, 115, 116, 119,
  88. 10, 9, 32, 9, 32, 70, 77, 83,
  89. 84, 87, 102, 109, 115, 116, 119, 82,
  90. 114, 73, 105, 44, 32, 48, 57, 48,
  91. 57, 32, 65, 68, 70, 74, 77, 78,
  92. 79, 83, 97, 100, 102, 106, 109, 110,
  93. 111, 115, 80, 85, 112, 117, 82, 114,
  94. 32, 48, 57, 48, 57, 48, 57, 48,
  95. 57, 32, 48, 57, 48, 57, 58, 48,
  96. 57, 48, 57, 58, 48, 57, 48, 57,
  97. 32, 71, 103, 77, 109, 84, 116, 13,
  98. 10, 71, 103, 69, 101, 67, 99, 69,
  99. 101, 66, 98, 65, 85, 97, 117, 78,
  100. 110, 76, 78, 108, 110, 65, 97, 82,
  101. 89, 114, 121, 79, 111, 86, 118, 67,
  102. 99, 84, 116, 69, 101, 80, 112, 79,
  103. 111, 78, 110, 65, 85, 97, 117, 84,
  104. 116, 72, 85, 104, 117, 85, 117, 69,
  105. 101, 69, 101, 68, 100, 0
  106. };
  107. static const char _tsip_machine_parser_header_Date_single_lengths[] = {
  108. 0, 2, 2, 2, 2, 3, 13, 1,
  109. 2, 12, 2, 2, 1, 1, 0, 0,
  110. 1, 16, 4, 2, 1, 0, 0, 0,
  111. 0, 1, 0, 0, 1, 0, 0, 1,
  112. 0, 0, 1, 2, 2, 2, 1, 1,
  113. 2, 2, 2, 2, 2, 4, 2, 4,
  114. 2, 4, 2, 2, 2, 2, 2, 2,
  115. 2, 2, 4, 2, 4, 2, 2, 2,
  116. 2, 0
  117. };
  118. static const char _tsip_machine_parser_header_Date_range_lengths[] = {
  119. 0, 0, 0, 0, 0, 0, 0, 0,
  120. 0, 0, 0, 0, 0, 0, 1, 1,
  121. 0, 0, 0, 0, 0, 1, 1, 1,
  122. 1, 0, 1, 1, 0, 1, 1, 0,
  123. 1, 1, 0, 0, 0, 0, 0, 0,
  124. 0, 0, 0, 0, 0, 0, 0, 0,
  125. 0, 0, 0, 0, 0, 0, 0, 0,
  126. 0, 0, 0, 0, 0, 0, 0, 0,
  127. 0, 0
  128. };
  129. static const short _tsip_machine_parser_header_Date_index_offsets[] = {
  130. 0, 0, 3, 6, 9, 12, 16, 30,
  131. 32, 35, 48, 51, 54, 56, 58, 60,
  132. 62, 64, 81, 86, 89, 91, 93, 95,
  133. 97, 99, 101, 103, 105, 107, 109, 111,
  134. 113, 115, 117, 119, 122, 125, 128, 130,
  135. 132, 135, 138, 141, 144, 147, 152, 155,
  136. 160, 163, 168, 171, 174, 177, 180, 183,
  137. 186, 189, 192, 197, 200, 205, 208, 211,
  138. 214, 217
  139. };
  140. static const char _tsip_machine_parser_header_Date_indicies[] = {
  141. 0, 0, 1, 2, 2, 1, 3, 3,
  142. 1, 4, 4, 1, 4, 4, 5, 1,
  143. 5, 6, 5, 7, 8, 9, 10, 11,
  144. 7, 8, 9, 10, 11, 1, 12, 1,
  145. 13, 13, 1, 13, 13, 7, 8, 9,
  146. 10, 11, 7, 8, 9, 10, 11, 1,
  147. 14, 14, 1, 15, 15, 1, 16, 1,
  148. 17, 1, 18, 1, 19, 1, 20, 1,
  149. 21, 22, 23, 24, 25, 26, 27, 28,
  150. 21, 22, 23, 24, 25, 26, 27, 28,
  151. 1, 29, 30, 29, 30, 1, 31, 31,
  152. 1, 32, 1, 33, 1, 34, 1, 35,
  153. 1, 36, 1, 37, 1, 38, 1, 39,
  154. 1, 40, 1, 41, 1, 42, 1, 43,
  155. 1, 44, 1, 45, 1, 46, 1, 47,
  156. 47, 1, 48, 48, 1, 49, 49, 1,
  157. 50, 1, 51, 1, 31, 31, 1, 52,
  158. 52, 1, 31, 31, 1, 53, 53, 1,
  159. 31, 31, 1, 54, 55, 54, 55, 1,
  160. 31, 31, 1, 31, 31, 31, 31, 1,
  161. 56, 56, 1, 31, 31, 31, 31, 1,
  162. 57, 57, 1, 31, 31, 1, 58, 58,
  163. 1, 31, 31, 1, 59, 59, 1, 31,
  164. 31, 1, 60, 60, 1, 15, 15, 1,
  165. 61, 60, 61, 60, 1, 15, 15, 1,
  166. 62, 63, 62, 63, 1, 15, 15, 1,
  167. 15, 15, 1, 64, 64, 1, 15, 15,
  168. 1, 1, 0
  169. };
  170. static const char _tsip_machine_parser_header_Date_trans_targs[] = {
  171. 2, 0, 3, 4, 5, 6, 7, 10,
  172. 56, 58, 60, 63, 8, 9, 11, 12,
  173. 13, 14, 15, 16, 17, 18, 41, 43,
  174. 45, 48, 50, 52, 54, 19, 40, 20,
  175. 21, 22, 23, 24, 25, 26, 27, 28,
  176. 29, 30, 31, 32, 33, 34, 35, 36,
  177. 37, 38, 39, 65, 42, 44, 46, 47,
  178. 49, 51, 53, 55, 57, 59, 61, 62,
  179. 64
  180. };
  181. static const char _tsip_machine_parser_header_Date_trans_actions[] = {
  182. 0, 0, 0, 0, 0, 0, 0, 1,
  183. 1, 1, 1, 1, 0, 0, 0, 0,
  184. 3, 0, 1, 0, 5, 1, 1, 1,
  185. 1, 1, 1, 1, 1, 0, 0, 0,
  186. 7, 1, 0, 0, 0, 9, 1, 0,
  187. 11, 1, 0, 13, 1, 0, 15, 0,
  188. 0, 0, 0, 17, 0, 0, 0, 0,
  189. 0, 0, 0, 0, 0, 0, 0, 0,
  190. 0
  191. };
  192. static const int tsip_machine_parser_header_Date_start = 1;
  193. static const int tsip_machine_parser_header_Date_first_final = 65;
  194. static const int tsip_machine_parser_header_Date_error = 0;
  195. static const int tsip_machine_parser_header_Date_en_main = 1;
  196. /* #line 134 "./ragel/tsip_parser_header_Date.rl" */
  197. (void)(eof);
  198. (void)(tsip_machine_parser_header_Date_first_final);
  199. (void)(tsip_machine_parser_header_Date_error);
  200. (void)(tsip_machine_parser_header_Date_en_main);
  201. /* #line 234 "./src/headers/tsip_header_Date.c" */
  202. {
  203. cs = tsip_machine_parser_header_Date_start;
  204. }
  205. /* #line 139 "./ragel/tsip_parser_header_Date.rl" */
  206. /* #line 241 "./src/headers/tsip_header_Date.c" */
  207. {
  208. int _klen;
  209. unsigned int _trans;
  210. const char *_acts;
  211. unsigned int _nacts;
  212. const char *_keys;
  213. if ( p == pe )
  214. goto _test_eof;
  215. if ( cs == 0 )
  216. goto _out;
  217. _resume:
  218. _keys = _tsip_machine_parser_header_Date_trans_keys + _tsip_machine_parser_header_Date_key_offsets[cs];
  219. _trans = _tsip_machine_parser_header_Date_index_offsets[cs];
  220. _klen = _tsip_machine_parser_header_Date_single_lengths[cs];
  221. if ( _klen > 0 ) {
  222. const char *_lower = _keys;
  223. const char *_mid;
  224. const char *_upper = _keys + _klen - 1;
  225. while (1) {
  226. if ( _upper < _lower )
  227. break;
  228. _mid = _lower + ((_upper-_lower) >> 1);
  229. if ( (*p) < *_mid )
  230. _upper = _mid - 1;
  231. else if ( (*p) > *_mid )
  232. _lower = _mid + 1;
  233. else {
  234. _trans += (_mid - _keys);
  235. goto _match;
  236. }
  237. }
  238. _keys += _klen;
  239. _trans += _klen;
  240. }
  241. _klen = _tsip_machine_parser_header_Date_range_lengths[cs];
  242. if ( _klen > 0 ) {
  243. const char *_lower = _keys;
  244. const char *_mid;
  245. const char *_upper = _keys + (_klen<<1) - 2;
  246. while (1) {
  247. if ( _upper < _lower )
  248. break;
  249. _mid = _lower + (((_upper-_lower) >> 1) & ~1);
  250. if ( (*p) < _mid[0] )
  251. _upper = _mid - 2;
  252. else if ( (*p) > _mid[1] )
  253. _lower = _mid + 2;
  254. else {
  255. _trans += ((_mid - _keys)>>1);
  256. goto _match;
  257. }
  258. }
  259. _trans += _klen;
  260. }
  261. _match:
  262. _trans = _tsip_machine_parser_header_Date_indicies[_trans];
  263. cs = _tsip_machine_parser_header_Date_trans_targs[_trans];
  264. if ( _tsip_machine_parser_header_Date_trans_actions[_trans] == 0 )
  265. goto _again;
  266. _acts = _tsip_machine_parser_header_Date_actions + _tsip_machine_parser_header_Date_trans_actions[_trans];
  267. _nacts = (unsigned int) *_acts++;
  268. while ( _nacts-- > 0 )
  269. {
  270. switch ( *_acts++ )
  271. {
  272. case 0:
  273. /* #line 50 "./ragel/tsip_parser_header_Date.rl" */
  274. {
  275. tag_start = p;
  276. }
  277. break;
  278. case 1:
  279. /* #line 54 "./ragel/tsip_parser_header_Date.rl" */
  280. {
  281. TSK_PARSER_SET_STRING(hdr_Date->wkday);
  282. }
  283. break;
  284. case 2:
  285. /* #line 58 "./ragel/tsip_parser_header_Date.rl" */
  286. {
  287. TSK_PARSER_SET_INTEGER(hdr_Date->day);
  288. }
  289. break;
  290. case 3:
  291. /* #line 62 "./ragel/tsip_parser_header_Date.rl" */
  292. {
  293. TSK_PARSER_SET_STRING(hdr_Date->month);
  294. }
  295. break;
  296. case 4:
  297. /* #line 66 "./ragel/tsip_parser_header_Date.rl" */
  298. {
  299. TSK_PARSER_SET_INTEGER(hdr_Date->year);
  300. }
  301. break;
  302. case 5:
  303. /* #line 70 "./ragel/tsip_parser_header_Date.rl" */
  304. {
  305. TSK_PARSER_SET_INTEGER(hdr_Date->time.h);
  306. }
  307. break;
  308. case 6:
  309. /* #line 74 "./ragel/tsip_parser_header_Date.rl" */
  310. {
  311. TSK_PARSER_SET_INTEGER(hdr_Date->time.m);
  312. }
  313. break;
  314. case 7:
  315. /* #line 78 "./ragel/tsip_parser_header_Date.rl" */
  316. {
  317. TSK_PARSER_SET_INTEGER(hdr_Date->time.s);
  318. }
  319. break;
  320. case 8:
  321. /* #line 82 "./ragel/tsip_parser_header_Date.rl" */
  322. {
  323. }
  324. break;
  325. /* #line 368 "./src/headers/tsip_header_Date.c" */
  326. }
  327. }
  328. _again:
  329. if ( cs == 0 )
  330. goto _out;
  331. if ( ++p != pe )
  332. goto _resume;
  333. _test_eof: {}
  334. _out: {}
  335. }
  336. /* #line 140 "./ragel/tsip_parser_header_Date.rl" */
  337. if( cs <
  338. /* #line 384 "./src/headers/tsip_header_Date.c" */
  339. 65
  340. /* #line 141 "./ragel/tsip_parser_header_Date.rl" */
  341. ){
  342. TSK_DEBUG_ERROR("Failed to parse 'Date' header.");
  343. TSK_OBJECT_SAFE_FREE(hdr_Date);
  344. }
  345. return hdr_Date;
  346. }
  347. //========================================================
  348. // Date header object definition
  349. //
  350. static tsk_object_t* tsip_header_Date_ctor(tsk_object_t *self, va_list * app)
  351. {
  352. tsip_header_Date_t *Date = self;
  353. if(Date){
  354. const char* wkday;
  355. const char* month;
  356. TSIP_HEADER(Date)->type = tsip_htype_Date;
  357. TSIP_HEADER(Date)->serialize = tsip_header_Date_serialize;
  358. Date->day = Date->time.h = Date->time.m = Date->time.s = -1;
  359. Date->year = -1;
  360. if((wkday = va_arg(*app, const char*))){
  361. month = va_arg(*app, const char*);
  362. Date->wkday = tsk_strdup(wkday);
  363. Date->month = tsk_strdup(month);
  364. #if defined __GNUC__
  365. Date->day = (int8_t)va_arg(*app, int);
  366. Date->year = (int16_t)va_arg(*app, int);
  367. Date->time.h = (int8_t)va_arg(*app, int);
  368. Date->time.m = (int8_t)va_arg(*app, int);
  369. Date->time.s = (int8_t)va_arg(*app, int);
  370. #else
  371. Date->day = va_arg(*app, int8_t);
  372. Date->year = va_arg(*app, int16_t);
  373. Date->time.h = va_arg(*app, int8_t);
  374. Date->time.m = va_arg(*app, int8_t);
  375. Date->time.s = va_arg(*app, int8_t);
  376. #endif
  377. }
  378. }
  379. else{
  380. TSK_DEBUG_ERROR("Failed to create new Date header.");
  381. }
  382. return self;
  383. }
  384. static tsk_object_t* tsip_header_Date_dtor(tsk_object_t *self)
  385. {
  386. tsip_header_Date_t *Date = self;
  387. if(Date){
  388. TSK_FREE(Date->wkday);
  389. TSK_FREE(Date->month);
  390. TSK_OBJECT_SAFE_FREE(TSIP_HEADER_PARAMS(Date));
  391. }
  392. else{
  393. TSK_DEBUG_ERROR("Null Date header.");
  394. }
  395. return self;
  396. }
  397. static const tsk_object_def_t tsip_header_Date_def_s =
  398. {
  399. sizeof(tsip_header_Date_t),
  400. tsip_header_Date_ctor,
  401. tsip_header_Date_dtor,
  402. tsk_null
  403. };
  404. const tsk_object_def_t *tsip_header_Date_def_t = &tsip_header_Date_def_s;