parse_to.c 18 KB

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