/src/opensips/parser/parse_rpid.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (C) 2001-2003 Juha Heinanen |
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 | | */ |
21 | | |
22 | | #include "parse_from.h" |
23 | | #include "parse_to.h" |
24 | | #include <stdlib.h> |
25 | | #include <string.h> |
26 | | #include "../dprint.h" |
27 | | #include "msg_parser.h" |
28 | | #include "../ut.h" |
29 | | #include "../errinfo.h" |
30 | | #include "../mem/mem.h" |
31 | | |
32 | | |
33 | | /* |
34 | | * This method is used to parse RPID header. |
35 | | * |
36 | | * params: msg : sip msg |
37 | | * returns 0 on success, |
38 | | * -1 on failure. |
39 | | */ |
40 | | int parse_rpid_header( struct sip_msg *msg ) |
41 | 0 | { |
42 | 0 | struct to_body* rpid_b; |
43 | |
|
44 | 0 | if ( !msg->rpid && (parse_headers(msg, HDR_RPID_F, 0)==-1 || !msg->rpid)) { |
45 | 0 | goto error; |
46 | 0 | } |
47 | | |
48 | | /* maybe the header is already parsed! */ |
49 | 0 | if (msg->rpid->parsed) |
50 | 0 | return 0; |
51 | | |
52 | | /* bad luck! :-( - we have to parse it */ |
53 | | /* first, get some memory */ |
54 | 0 | rpid_b = pkg_malloc(sizeof(struct to_body)); |
55 | 0 | if (rpid_b == 0) { |
56 | 0 | LM_ERR("out of pkg_memory\n"); |
57 | 0 | goto error; |
58 | 0 | } |
59 | | |
60 | | /* now parse it!! */ |
61 | 0 | parse_to(msg->rpid->body.s,msg->rpid->body.s+msg->rpid->body.len+1,rpid_b); |
62 | 0 | if (rpid_b->error == PARSE_ERROR) { |
63 | 0 | LM_ERR("bad rpid header\n"); |
64 | 0 | pkg_free(rpid_b); |
65 | 0 | set_err_info(OSER_EC_PARSER, OSER_EL_MEDIUM, |
66 | 0 | "error parsing RPID header"); |
67 | 0 | set_err_reply(400, "bad header"); |
68 | 0 | goto error; |
69 | 0 | } |
70 | 0 | msg->rpid->parsed = rpid_b; |
71 | |
|
72 | 0 | return 0; |
73 | 0 | error: |
74 | 0 | return -1; |
75 | 0 | } |