parse_nameaddr.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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-03-24 Created by janakj
  25. * 2003-04-26 ZSW (jiri)
  26. */
  27. /*! \file
  28. * \brief Parser :: Parse name-addr part
  29. *
  30. * \ingroup parser
  31. */
  32. #include <string.h>
  33. #include "../dprint.h"
  34. #include "parse_nameaddr.h"
  35. #include "parser_f.h"
  36. #include "../ut.h"
  37. /*! \brief
  38. * Parse name-addr part, the given string can be longer,
  39. * parsing will stop when closing > is found
  40. */
  41. int parse_nameaddr(str* _s, name_addr_t* _a)
  42. {
  43. char* uri_end;
  44. if (!_s || !_a) {
  45. return -1;
  46. }
  47. _a->name.s = _s->s;
  48. _a->uri.s = find_not_quoted(_s, '<');
  49. if (_a->uri.s) {
  50. _a->name.len = _a->uri.s - _a->name.s;
  51. _a->uri.s++; /* We will skip < character */
  52. } else {
  53. return -3;
  54. }
  55. _a->uri.len = _s->len - _a->name.len - 1;
  56. uri_end = find_not_quoted(&_a->uri, '>');
  57. if (!uri_end) {
  58. return -4;
  59. }
  60. /* Total length of the field including <> */
  61. _a->len = uri_end - _a->name.s + 1;
  62. _a->uri.len = uri_end - _a->uri.s;
  63. return 0;
  64. }
  65. /*! \brief
  66. * Print a name-addr structure, just for debugging
  67. */
  68. void print_nameaddr(FILE* _o, name_addr_t* _a)
  69. {
  70. fprintf(_o, "---name-addr---\n");
  71. fprintf(_o, "name: '%.*s'\n", _a->name.len, ZSW(_a->name.s));
  72. fprintf(_o, "uri : '%.*s'\n", _a->uri.len, ZSW(_a->uri.s));
  73. fprintf(_o, "len : %d\n", _a->len);
  74. fprintf(_o, "---/name-addr---\n");
  75. }