2
0

parse_to.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782
  1. /*
  2. * $Id$
  3. *
  4. * Copyright (C) 2001-2003 Fhg Fokus
  5. *
  6. * This file is part of ser, a free SIP server.
  7. *
  8. * ser 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 2 of the License, or
  11. * (at your option) any later version
  12. *
  13. * For a license to use the ser software under conditions
  14. * other than those described here, or to purchase support for this
  15. * software, please contact iptel.org by e-mail at the following addresses:
  16. * [email protected]
  17. *
  18. * ser is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  26. */
  27. #include "parse_to.h"
  28. #include <stdlib.h>
  29. #include <string.h>
  30. #include "../dprint.h"
  31. #include "msg_parser.h"
  32. #include "../ut.h"
  33. #include "../mem/mem.h"
  34. enum {
  35. TAG_PARAM = 400, GENERAL_PARAM
  36. };
  37. enum {
  38. START_TO, DISPLAY_QUOTED, E_DISPLAY_QUOTED, DISPLAY_TOKEN,
  39. S_URI_ENCLOSED, URI_ENCLOSED, E_URI_ENCLOSED,
  40. URI_OR_TOKEN, MAYBE_URI_END, END, F_CR, F_LF, F_CRLF
  41. };
  42. enum {
  43. S_PARA_NAME=20, PARA_NAME, S_EQUAL, S_PARA_VALUE, TAG1, TAG2,
  44. TAG3, PARA_VALUE_TOKEN , PARA_VALUE_QUOTED, E_PARA_VALUE
  45. };
  46. #define add_param( _param , _body ) \
  47. do{\
  48. DBG("DEBUG: add_param: %.*s=%.*s\n",param->name.len,param->name.s,\
  49. param->value.len,param->value.s);\
  50. if (!(_body)->param_lst) (_body)->param_lst=(_param);\
  51. else (_body)->last_param->next=(_param);\
  52. (_body)->last_param =(_param);\
  53. if ((_param)->type==TAG_PARAM)\
  54. memcpy(&((_body)->tag_value),&((_param)->value),sizeof(str));\
  55. }while(0);
  56. static /*inline*/ char* parse_to_param(char *buffer, char *end,
  57. struct to_body *to_b,
  58. int *returned_status)
  59. {
  60. struct to_param *param;
  61. int status;
  62. int saved_status;
  63. char *tmp;
  64. param=0;
  65. status=E_PARA_VALUE;
  66. saved_status=E_PARA_VALUE;
  67. for( tmp=buffer; tmp<end; tmp++)
  68. {
  69. switch(*tmp)
  70. {
  71. case ' ':
  72. case '\t':
  73. switch (status)
  74. {
  75. case TAG3:
  76. param->type=TAG_PARAM;
  77. case PARA_NAME:
  78. case TAG1:
  79. case TAG2:
  80. param->name.len = tmp-param->name.s;
  81. status = S_EQUAL;
  82. break;
  83. case PARA_VALUE_TOKEN:
  84. param->value.len = tmp-param->value.s;
  85. status = E_PARA_VALUE;
  86. add_param( param , to_b );
  87. break;
  88. case F_CRLF:
  89. case F_LF:
  90. case F_CR:
  91. /*previous=crlf and now =' '*/
  92. status=saved_status;
  93. break;
  94. }
  95. break;
  96. case '\n':
  97. switch (status)
  98. {
  99. case S_PARA_NAME:
  100. case S_EQUAL:
  101. case S_PARA_VALUE:
  102. case E_PARA_VALUE:
  103. saved_status=status;
  104. status=F_LF;
  105. break;
  106. case TAG3:
  107. param->type=TAG_PARAM;
  108. case PARA_NAME:
  109. case TAG1:
  110. case TAG2:
  111. param->name.len = tmp-param->name.s;
  112. saved_status = S_EQUAL;
  113. status = F_LF;
  114. break;
  115. case PARA_VALUE_TOKEN:
  116. param->value.len = tmp-param->value.s;
  117. saved_status = E_PARA_VALUE;
  118. status = F_LF;
  119. add_param( param , to_b );
  120. break;
  121. case F_CR:
  122. status=F_CRLF;
  123. break;
  124. case F_CRLF:
  125. case F_LF:
  126. status=saved_status;
  127. goto endofheader;
  128. default:
  129. LOG( L_ERR , "ERROR: parse_to_param : "
  130. "unexpected char [%c] in status %d: <<%.*s>> .\n",
  131. *tmp,status, (int)(tmp-buffer), buffer);
  132. }
  133. break;
  134. case '\r':
  135. switch (status)
  136. {
  137. case S_PARA_NAME:
  138. case S_EQUAL:
  139. case S_PARA_VALUE:
  140. case E_PARA_VALUE:
  141. saved_status=status;
  142. status=F_CR;
  143. break;
  144. case TAG3:
  145. param->type=TAG_PARAM;
  146. case PARA_NAME:
  147. case TAG1:
  148. case TAG2:
  149. param->name.len = tmp-param->name.s;
  150. saved_status = S_EQUAL;
  151. status = F_CR;
  152. break;
  153. case PARA_VALUE_TOKEN:
  154. param->value.len = tmp-param->value.s;
  155. saved_status = E_PARA_VALUE;
  156. status = F_CR;
  157. add_param( param , to_b );
  158. break;
  159. case F_CRLF:
  160. case F_CR:
  161. case F_LF:
  162. status=saved_status;
  163. goto endofheader;
  164. default:
  165. LOG( L_ERR , "ERROR: parse_to_param : "
  166. "unexpected char [%c] in status %d: <<%.*s>> .\n",
  167. *tmp,status, (int)(tmp-buffer), buffer);
  168. goto error;
  169. }
  170. break;
  171. case 0:
  172. switch (status)
  173. {
  174. #ifndef NO_PINGTEL_TAG_HACK
  175. case TAG3:
  176. param->type = TAG_PARAM;
  177. param->name.len = 3;
  178. status = S_EQUAL;
  179. case S_EQUAL:
  180. case S_PARA_VALUE:
  181. saved_status=status;
  182. goto endofheader;
  183. #endif
  184. case PARA_VALUE_TOKEN:
  185. status = E_PARA_VALUE;
  186. param->value.len = tmp-param->value.s;
  187. add_param( param , to_b );
  188. case E_PARA_VALUE:
  189. saved_status = status;
  190. goto endofheader;
  191. break;
  192. default:
  193. LOG( L_ERR , "ERROR: parse_to_param : "
  194. "unexpected char [%c] in status %d: <<%.*s>> .\n",
  195. *tmp,status, (int)(tmp-buffer), buffer);
  196. goto error;
  197. }
  198. break;
  199. case '\\':
  200. switch (status)
  201. {
  202. case PARA_VALUE_QUOTED:
  203. switch (*(tmp+1))
  204. {
  205. case '\r':
  206. case '\n':
  207. break;
  208. default:
  209. tmp++;
  210. }
  211. default:
  212. LOG( L_ERR , "ERROR: parse_to_param : "
  213. "unexpected char [%c] in status %d: <<%.*s>> .\n",
  214. *tmp,status, (int)(tmp-buffer), buffer);
  215. goto error;
  216. }
  217. break;
  218. case '"':
  219. switch (status)
  220. {
  221. case S_PARA_VALUE:
  222. param->value.s = tmp+1;
  223. status = PARA_VALUE_QUOTED;
  224. break;
  225. case PARA_VALUE_QUOTED:
  226. param->value.len=tmp-param->value.s-1 ;
  227. add_param( param , to_b );
  228. status = E_PARA_VALUE;
  229. break;
  230. case F_CRLF:
  231. case F_LF:
  232. case F_CR:
  233. /*previous=crlf and now !=' '*/
  234. goto endofheader;
  235. default:
  236. LOG( L_ERR , "ERROR: parse_to_param :"
  237. "unexpected char [%c] in status %d: <<%.*s>> .\n",
  238. *tmp,status,(int)(tmp-buffer), buffer);
  239. goto error;
  240. }
  241. break;
  242. case ';' :
  243. switch (status)
  244. {
  245. case PARA_VALUE_QUOTED:
  246. break;
  247. #ifndef NO_PINGTEL_TAG_HACK
  248. case TAG3:
  249. param->type = TAG_PARAM;
  250. param->name.len = 3;
  251. case S_EQUAL:
  252. case S_PARA_VALUE:
  253. if (param->type==TAG_PARAM)
  254. param->value.s = tmp;
  255. else {
  256. LOG( L_ERR , "ERROR: parse_to_param : unexpected "
  257. "char [%c] in status %d: <<%.*s>> .\n",
  258. *tmp,status, (int)(tmp-buffer), buffer);
  259. goto error;
  260. }
  261. #endif
  262. case PARA_VALUE_TOKEN:
  263. param->value.len=tmp-param->value.s;
  264. add_param(param,to_b);
  265. case E_PARA_VALUE:
  266. param = (struct to_param*)
  267. pkg_malloc(sizeof(struct to_param));
  268. if (!param){
  269. LOG( L_ERR , "ERROR: parse_to_param"
  270. " - out of memory\n" );
  271. goto error;
  272. }
  273. memset(param,0,sizeof(struct to_param));
  274. param->type=GENERAL_PARAM;
  275. status = S_PARA_NAME;
  276. break;
  277. case F_CRLF:
  278. case F_LF:
  279. case F_CR:
  280. /*previous=crlf and now !=' '*/
  281. goto endofheader;
  282. default:
  283. LOG( L_ERR , "ERROR: parse_to_param :"
  284. "unexpected char [%c] in status %d: <<%.*s>> .\n",
  285. *tmp,status, (int)(tmp-buffer), buffer);
  286. goto error;
  287. }
  288. break;
  289. case 'T':
  290. case 't' :
  291. switch (status)
  292. {
  293. case PARA_VALUE_QUOTED:
  294. case PARA_VALUE_TOKEN:
  295. case PARA_NAME:
  296. break;
  297. case S_PARA_NAME:
  298. param->name.s = tmp;
  299. status = TAG1;
  300. break;
  301. case S_PARA_VALUE:
  302. param->value.s = tmp;
  303. status = PARA_VALUE_TOKEN;
  304. break;
  305. case TAG1:
  306. case TAG2:
  307. case TAG3:
  308. status = PARA_NAME;
  309. break;
  310. case F_CRLF:
  311. case F_LF:
  312. case F_CR:
  313. /*previous=crlf and now !=' '*/
  314. goto endofheader;
  315. default:
  316. LOG( L_ERR , "ERROR: parse_to_param :"
  317. "unexpected char [%c] in status %d: <<%.*s>> .\n",
  318. *tmp,status, (int)(tmp-buffer), buffer);
  319. goto error;
  320. }
  321. break;
  322. case 'A':
  323. case 'a' :
  324. switch (status)
  325. {
  326. case PARA_VALUE_QUOTED:
  327. case PARA_VALUE_TOKEN:
  328. case PARA_NAME:
  329. break;
  330. case S_PARA_NAME:
  331. param->name.s = tmp;
  332. status = PARA_NAME;
  333. break;
  334. case S_PARA_VALUE:
  335. param->value.s = tmp;
  336. status = PARA_VALUE_TOKEN;
  337. break;
  338. case TAG1:
  339. status = TAG2;
  340. break;
  341. case TAG2:
  342. case TAG3:
  343. status = PARA_NAME;
  344. break;
  345. case F_CRLF:
  346. case F_LF:
  347. case F_CR:
  348. /*previous=crlf and now !=' '*/
  349. goto endofheader;
  350. default:
  351. LOG( L_ERR , "ERROR: parse_to_param : "
  352. "unexpected char [%c] in status %d: <<%.*s>> .\n",
  353. *tmp,status, (int)(tmp-buffer), buffer);
  354. goto error;
  355. }
  356. break;
  357. case 'G':
  358. case 'g' :
  359. switch (status)
  360. {
  361. case PARA_VALUE_QUOTED:
  362. case PARA_VALUE_TOKEN:
  363. case PARA_NAME:
  364. break;
  365. case S_PARA_NAME:
  366. param->name.s = tmp;
  367. status = PARA_NAME;
  368. break;
  369. case S_PARA_VALUE:
  370. param->value.s = tmp;
  371. status = PARA_VALUE_TOKEN;
  372. break;
  373. case TAG1:
  374. case TAG3:
  375. status = PARA_NAME;
  376. break;
  377. case TAG2:
  378. status = TAG3;
  379. break;
  380. case F_CRLF:
  381. case F_LF:
  382. case F_CR:
  383. /*previous=crlf and now !=' '*/
  384. goto endofheader;
  385. default:
  386. LOG( L_ERR , "ERROR: parse_to_param : "
  387. "unexpected char [%c] in status %d: <<%.*s>> .\n",
  388. *tmp,status, (int)(tmp-buffer), buffer);
  389. goto error;
  390. }
  391. break;
  392. case '=':
  393. switch (status)
  394. {
  395. case PARA_VALUE_QUOTED:
  396. break;
  397. case TAG3:
  398. param->type=TAG_PARAM;
  399. case PARA_NAME:
  400. case TAG1:
  401. case TAG2:
  402. param->name.len = tmp-param->name.s;
  403. status = S_PARA_VALUE;
  404. break;
  405. case S_EQUAL:
  406. status = S_PARA_VALUE;
  407. break;
  408. case F_CRLF:
  409. case F_LF:
  410. case F_CR:
  411. /*previous=crlf and now !=' '*/
  412. goto endofheader;
  413. default:
  414. LOG( L_ERR , "ERROR: parse_to_param : "
  415. "unexpected char [%c] in status %d: <<%.*s>> .\n",
  416. *tmp,status, (int)(tmp-buffer), buffer);
  417. goto error;
  418. }
  419. break;
  420. default:
  421. switch (status)
  422. {
  423. case TAG1:
  424. case TAG2:
  425. case TAG3:
  426. status = PARA_NAME;
  427. break;
  428. case PARA_VALUE_TOKEN:
  429. case PARA_NAME:
  430. case PARA_VALUE_QUOTED:
  431. break;
  432. case S_PARA_NAME:
  433. param->name.s = tmp;
  434. status = PARA_NAME;
  435. break;
  436. case S_PARA_VALUE:
  437. param->value.s = tmp;
  438. status = PARA_VALUE_TOKEN;
  439. break;
  440. case F_CRLF:
  441. case F_LF:
  442. case F_CR:
  443. /*previous=crlf and now !=' '*/
  444. goto endofheader;
  445. default:
  446. DBG("DEBUG: parse_to_param: "
  447. "spitting out [%c] in status %d\n",*tmp,status );
  448. goto error;
  449. }
  450. }/*switch*/
  451. }/*for*/
  452. endofheader:
  453. #ifndef NO_PINGTEL_TAG_HACK
  454. if (param->type==TAG_PARAM
  455. && (saved_status==S_EQUAL||saved_status==S_PARA_VALUE) ) {
  456. saved_status = E_PARA_VALUE;
  457. param->value.s= 0;
  458. param->value.len=0;
  459. add_param(param, to_b);
  460. }
  461. #endif
  462. *returned_status=saved_status;
  463. return tmp;
  464. error:
  465. if (param) pkg_free(param);
  466. to_b->error=PARSE_ERROR;
  467. *returned_status = status;
  468. return tmp;
  469. }
  470. char* parse_to(char* buffer, char *end, struct to_body *to_b)
  471. {
  472. int status;
  473. int saved_status;
  474. char *tmp,*foo;
  475. status=START_TO;
  476. to_b->error=PARSE_OK;
  477. to_b->uri.len = 0;
  478. to_b->uri.s= 0;
  479. foo=0;
  480. for( tmp=buffer; tmp<end; tmp++)
  481. {
  482. switch(*tmp)
  483. {
  484. case ' ':
  485. case '\t':
  486. switch (status)
  487. {
  488. case F_CRLF:
  489. case F_LF:
  490. case F_CR:
  491. /*previous=crlf and now =' '*/
  492. status=saved_status;
  493. break;
  494. case URI_ENCLOSED:
  495. to_b->uri.len = tmp - to_b->uri.s;
  496. status = E_URI_ENCLOSED;
  497. break;
  498. case URI_OR_TOKEN:
  499. foo = tmp;
  500. status = MAYBE_URI_END;
  501. break;
  502. }
  503. break;
  504. case '\n':
  505. switch (status)
  506. {
  507. case URI_OR_TOKEN:
  508. foo = tmp;
  509. status = MAYBE_URI_END;
  510. case MAYBE_URI_END:
  511. case DISPLAY_TOKEN:
  512. case E_DISPLAY_QUOTED:
  513. case END:
  514. saved_status=status;
  515. status=F_LF;
  516. break;
  517. case F_CR:
  518. status=F_CRLF;
  519. break;
  520. case F_CRLF:
  521. case F_LF:
  522. status=saved_status;
  523. goto endofheader;
  524. default:
  525. LOG( L_ERR , "ERROR: parse_to : unexpected char [%c] "
  526. "in status %d: <<%.*s>> .\n",
  527. *tmp,status, (int)(tmp-buffer), buffer);
  528. }
  529. break;
  530. case '\r':
  531. switch (status)
  532. {
  533. case URI_OR_TOKEN:
  534. foo = tmp;
  535. status = MAYBE_URI_END;
  536. case MAYBE_URI_END:
  537. case DISPLAY_TOKEN:
  538. case E_DISPLAY_QUOTED:
  539. case END:
  540. saved_status=status;
  541. status=F_CR;
  542. break;
  543. case F_CRLF:
  544. case F_CR:
  545. case F_LF:
  546. status=saved_status;
  547. goto endofheader;
  548. default:
  549. LOG( L_ERR , "ERROR: parse_to : unexpected char [%c] "
  550. "in status %d: <<%.*s>> .\n",
  551. *tmp,status, (int)(tmp-buffer), buffer);
  552. goto error;
  553. }
  554. break;
  555. case 0:
  556. switch (status)
  557. {
  558. case URI_OR_TOKEN:
  559. case MAYBE_URI_END:
  560. to_b->uri.len = tmp - to_b->uri.s;
  561. case END:
  562. saved_status = status = END;
  563. goto endofheader;
  564. default:
  565. LOG( L_ERR , "ERROR: parse_to : unexpected char [%c] "
  566. "in status %d: <<%.*s>> .\n",
  567. *tmp,status, (int)(tmp-buffer), buffer);
  568. goto error;
  569. }
  570. break;
  571. case '\\':
  572. switch (status)
  573. {
  574. case DISPLAY_QUOTED:
  575. switch (*(tmp+1))
  576. {
  577. case '\n':
  578. case '\r':
  579. break;
  580. default:
  581. tmp++;
  582. }
  583. default:
  584. LOG( L_ERR , "ERROR: parse_to : unexpected char [%c] "
  585. "in status %d: <<%.*s>> .\n",
  586. *tmp,status, (int)(tmp-buffer), buffer);
  587. goto error;
  588. }
  589. break;
  590. case '<':
  591. switch (status)
  592. {
  593. case START_TO:
  594. to_b->body.s=tmp;
  595. status = S_URI_ENCLOSED;
  596. break;
  597. case DISPLAY_QUOTED:
  598. break;
  599. case E_DISPLAY_QUOTED:
  600. case URI_OR_TOKEN:
  601. case DISPLAY_TOKEN:
  602. case MAYBE_URI_END:
  603. status = S_URI_ENCLOSED;
  604. break;
  605. case F_CRLF:
  606. case F_LF:
  607. case F_CR:
  608. /*previous=crlf and now !=' '*/
  609. goto endofheader;
  610. default:
  611. LOG( L_ERR , "ERROR: parse_to : unexpected char [%c] "
  612. "in status %d: <<%.*s>> .\n",
  613. *tmp,status, (int)(tmp-buffer), buffer);
  614. goto error;
  615. }
  616. break;
  617. case '>':
  618. switch (status)
  619. {
  620. case DISPLAY_QUOTED:
  621. break;
  622. case URI_ENCLOSED:
  623. to_b->uri.len = tmp - to_b->uri.s;
  624. case E_URI_ENCLOSED:
  625. status = END;
  626. foo = 0;
  627. break;
  628. case F_CRLF:
  629. case F_LF:
  630. case F_CR:
  631. /*previous=crlf and now !=' '*/
  632. goto endofheader;
  633. default:
  634. LOG( L_ERR , "ERROR: parse_to : unexpected char [%c] "
  635. "in status %d: <<%.*s>> .\n",
  636. *tmp,status, (int)(tmp-buffer), buffer);
  637. goto error;
  638. }
  639. break;
  640. case '"':
  641. switch (status)
  642. {
  643. case START_TO:
  644. to_b->body.s = tmp;
  645. status = DISPLAY_QUOTED;
  646. break;
  647. case DISPLAY_QUOTED:
  648. status = E_DISPLAY_QUOTED;
  649. break;
  650. case F_CRLF:
  651. case F_LF:
  652. case F_CR:
  653. /*previous=crlf and now !=' '*/
  654. goto endofheader;
  655. default:
  656. LOG( L_ERR , "ERROR: parse_to : unexpected char [%c] "
  657. "in status %d: <<%.*s>> .\n",
  658. *tmp,status, (int)(tmp-buffer), buffer);
  659. goto error;
  660. }
  661. break;
  662. case ';' :
  663. switch (status)
  664. {
  665. case DISPLAY_QUOTED:
  666. case URI_ENCLOSED:
  667. break;
  668. case URI_OR_TOKEN:
  669. foo = tmp;
  670. case MAYBE_URI_END:
  671. to_b->uri.len = foo - to_b->uri.s;
  672. case END:
  673. to_b->body.len = tmp-to_b->body.s;
  674. tmp = parse_to_param(tmp,end,to_b,&saved_status);
  675. goto endofheader;
  676. case F_CRLF:
  677. case F_LF:
  678. case F_CR:
  679. /*previous=crlf and now !=' '*/
  680. goto endofheader;
  681. default:
  682. LOG( L_ERR , "ERROR: parse_to : unexpected char [%c] "
  683. "in status %d: <<%.*s>> .\n",
  684. *tmp,status, (int)(tmp-buffer), buffer);
  685. goto error;
  686. }
  687. break;
  688. default:
  689. switch (status)
  690. {
  691. case START_TO:
  692. to_b->uri.s = to_b->body.s = tmp;
  693. status = URI_OR_TOKEN;;
  694. break;
  695. case S_URI_ENCLOSED:
  696. to_b->uri.s=tmp;
  697. status=URI_ENCLOSED;
  698. break;
  699. case MAYBE_URI_END:
  700. status = DISPLAY_TOKEN;
  701. case DISPLAY_QUOTED:
  702. case DISPLAY_TOKEN:
  703. case URI_ENCLOSED:
  704. case URI_OR_TOKEN:
  705. break;
  706. case F_CRLF:
  707. case F_LF:
  708. case F_CR:
  709. /*previous=crlf and now !=' '*/
  710. goto endofheader;
  711. default:
  712. DBG("DEBUG:parse_to: spitting out [%c] in status %d\n",
  713. *tmp,status );
  714. goto error;
  715. }
  716. }/*char switch*/
  717. }/*for*/
  718. endofheader:
  719. status=saved_status;
  720. DBG("end of header reached, state=%d\n", status);
  721. /* check if error*/
  722. switch(status){
  723. case MAYBE_URI_END:
  724. to_b->uri.len = foo - to_b->uri.s;
  725. case END:
  726. to_b->body.len = tmp - to_b->body.s;
  727. case E_PARA_VALUE:
  728. break;
  729. default:
  730. LOG(L_ERR, "ERROR: parse_to: invalid To - unexpected "
  731. "end of header in state %d\n", status);
  732. goto error;
  733. }
  734. return tmp;
  735. error:
  736. to_b->error=PARSE_ERROR;
  737. return tmp;
  738. }
  739. void free_to(struct to_body* tb)
  740. {
  741. struct to_param *tp=tb->param_lst;
  742. struct to_param *foo;
  743. while (tp){
  744. foo = tp->next;
  745. pkg_free(tp);
  746. tp=foo;
  747. }
  748. pkg_free(tb);
  749. }