2
0

parse_nameaddr.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Copyright (C) 2001-2003 FhG Fokus
  3. *
  4. * This file is part of ser, a free SIP server.
  5. *
  6. * ser 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 2 of the License, or
  9. * (at your option) any later version
  10. *
  11. * ser 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 this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. *
  20. * History
  21. * --------
  22. * 2003-03-24 Created by janakj
  23. * 2003-04-26 ZSW (jiri)
  24. */
  25. /*! \file
  26. * \brief Parser :: Parse name-addr part
  27. *
  28. * \ingroup parser
  29. */
  30. #include <string.h>
  31. #include "../dprint.h"
  32. #include "parse_nameaddr.h"
  33. #include "parser_f.h"
  34. #include "../ut.h"
  35. /*! \brief
  36. * Parse name-addr part, the given string can be longer,
  37. * parsing will stop when closing > is found
  38. */
  39. int parse_nameaddr(str* _s, name_addr_t* _a)
  40. {
  41. char* uri_end;
  42. if (!_s || !_a) {
  43. return -1;
  44. }
  45. _a->name.s = _s->s;
  46. _a->uri.s = find_not_quoted(_s, '<');
  47. if (_a->uri.s) {
  48. _a->name.len = _a->uri.s - _a->name.s;
  49. _a->uri.s++; /* We will skip < character */
  50. } else {
  51. return -3;
  52. }
  53. _a->uri.len = _s->len - _a->name.len - 1;
  54. uri_end = find_not_quoted(&_a->uri, '>');
  55. if (!uri_end) {
  56. return -4;
  57. }
  58. /* Total length of the field including <> */
  59. _a->len = uri_end - _a->name.s + 1;
  60. _a->uri.len = uri_end - _a->uri.s;
  61. return 0;
  62. }
  63. /*! \brief
  64. * Print a name-addr structure, just for debugging
  65. */
  66. void print_nameaddr(FILE* _o, name_addr_t* _a)
  67. {
  68. fprintf(_o, "---name-addr---\n");
  69. fprintf(_o, "name: '%.*s'\n", _a->name.len, ZSW(_a->name.s));
  70. fprintf(_o, "uri : '%.*s'\n", _a->uri.len, ZSW(_a->uri.s));
  71. fprintf(_o, "len : %d\n", _a->len);
  72. fprintf(_o, "---/name-addr---\n");
  73. }