4
* Copyright (C) 2006 Juha Heinanen
6
* This file is part of Kamailio, a free SIP server.
8
* Kamailio 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
13
* Kamailio 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.
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
25
* \brief P-Preferred-Identity header parser
29
#include "parse_ppi.h"
30
#include "../../parser/parse_to.h"
31
#include "../../parser/parse_uri.h"
34
#include "../../dprint.h"
35
#include "../../parser/msg_parser.h"
37
#include "../../mem/mem.h"
41
* \brief This method is used to parse P-Preferred-Identity header (RFC 3325).
43
* Currently only one name-addr / addr-spec is supported in the header
44
* and it must contain a sip or sips URI.
46
* \return 0 on success, -1 on failure.
48
int parse_ppi_header( struct sip_msg *msg )
50
struct to_body* ppi_b;
53
(parse_headers(msg, HDR_PPI_F,0)==-1 || !msg->ppi)) {
57
/* maybe the header is already parsed! */
61
/* bad luck! :-( - we have to parse it */
62
/* first, get some memory */
63
ppi_b = pkg_malloc(sizeof(struct to_body));
65
LM_ERR("out of pkg_memory\n");
70
memset(ppi_b, 0, sizeof(struct to_body));
71
parse_to(msg->ppi->body.s,
72
msg->ppi->body.s + msg->ppi->body.len+1,
74
if (ppi_b->error == PARSE_ERROR) {
75
LM_ERR("bad P-Preferred-Identity header\n");
79
msg->ppi->parsed = ppi_b;
88
* \brief Parse P-Preferred-Identity header URI
90
struct sip_uri *parse_ppi_uri(struct sip_msg *msg)
92
struct to_body *tb = NULL;
97
if(parse_ppi_header(msg)<0)
99
LM_ERR("cannot parse P-P-I header\n");
103
if(msg->ppi==NULL || get_ppi(msg)==NULL)
108
if(tb->parsed_uri.user.s!=NULL || tb->parsed_uri.host.s!=NULL)
109
return &tb->parsed_uri;
111
if (parse_uri(tb->uri.s, tb->uri.len , &tb->parsed_uri)<0)
113
LM_ERR("failed to parse P-P-I URI\n");
114
memset(&tb->parsed_uri, 0, sizeof(struct sip_uri));
118
return &tb->parsed_uri;