/src/opensips/parser/parse_nameaddr.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (C) 2001-2003 FhG Fokus |
3 | | * |
4 | | * This file is part of opensips, a free SIP server. |
5 | | * |
6 | | * opensips 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 | | * opensips 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 | | |
26 | | #include <string.h> |
27 | | #include "../dprint.h" |
28 | | #include "parse_nameaddr.h" |
29 | | #include "parser_f.h" |
30 | | #include "../ut.h" |
31 | | |
32 | | |
33 | | /* |
34 | | * Parse name-addr part, the given string can be longer, |
35 | | * parsing will stop when closing > is found |
36 | | */ |
37 | | int parse_nameaddr(str* _s, name_addr_t* _a) |
38 | 0 | { |
39 | 0 | char* uri_end; |
40 | |
|
41 | 0 | if (!_s || !_a) { |
42 | 0 | LM_ERR("invalid parameter value\n"); |
43 | 0 | return -1; |
44 | 0 | } |
45 | | |
46 | 0 | _a->name.s = _s->s; |
47 | |
|
48 | 0 | _a->uri.s = find_not_quoted(_s, '<'); |
49 | 0 | if (_a->uri.s) { |
50 | 0 | _a->name.len = _a->uri.s - _a->name.s; |
51 | 0 | _a->uri.s++; /* We will skip < character */ |
52 | 0 | } else { |
53 | 0 | LM_ERR("no < found\n"); |
54 | 0 | return -3; |
55 | 0 | } |
56 | | |
57 | 0 | _a->uri.len = _s->len - _a->name.len - 1; |
58 | 0 | uri_end = find_not_quoted(&_a->uri, '>'); |
59 | |
|
60 | 0 | if (!uri_end) { |
61 | 0 | LM_ERR("no > found\n"); |
62 | 0 | return -4; |
63 | 0 | } |
64 | | |
65 | | /* Total length of the field including <> */ |
66 | 0 | _a->len = uri_end - _a->name.s + 1; |
67 | |
|
68 | 0 | _a->uri.len = uri_end - _a->uri.s; |
69 | 0 | return 0; |
70 | 0 | } |
71 | | |
72 | | |
73 | | /* |
74 | | * Print a name-addr structure, just for debugging |
75 | | */ |
76 | | void print_nameaddr(FILE* _o, name_addr_t* _a) |
77 | 0 | { |
78 | 0 | fprintf(_o, "---name-addr---\n"); |
79 | 0 | fprintf(_o, "name: '%.*s'\n", _a->name.len, ZSW(_a->name.s)); |
80 | 0 | fprintf(_o, "uri : '%.*s'\n", _a->uri.len, ZSW(_a->uri.s)); |
81 | 0 | fprintf(_o, "len : %d\n", _a->len); |
82 | 0 | fprintf(_o, "---/name-addr---\n"); |
83 | 0 | } |