2
* Copyright (C) 2013 Hugh Waite
4
* This file is part of Kamailio, a free SIP server.
6
* Kamailio 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
11
* Kamailio 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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
* 2013-03-06 Created (hpw)
25
/** Parser :: Parse P-Asserted-Identity: header.
30
#include "parse_ppi_pai.h"
33
#include "../dprint.h"
34
#include "msg_parser.h"
35
#include "parse_uri.h"
37
#include "../mem/mem.h"
40
* A P-Asserted-Identity or P-Preferred-Identity header value is an addr-spec or name-addr
41
* There can be only one of any URI scheme (sip(s), tel etc), which may occur on separate
42
* headers or can be comma separated in a single header.
43
* RFC3325 only mentions sip(s) and tel schemes, but there is no reason why other schemes
44
* cannot be used in the future.
50
#define NUM_PAI_BODIES 10
51
int parse_pai_ppi_body(char *buf, int len, p_id_body_t **body)
53
static to_body_t uri_b[NUM_PAI_BODIES]; /* Temporary storage */
57
memset(uri_b, 0, NUM_PAI_BODIES * sizeof(to_body_t));
59
tmp = parse_addr_spec(buf, buf+len, &uri_b[num_uri], 1);
60
if (uri_b[num_uri].error == PARSE_ERROR)
62
LM_ERR("Error parsing PAI/PPI body %u '%.*s'\n", num_uri, len, buf);
66
while ((*tmp == ',') && (num_uri < NUM_PAI_BODIES))
69
tmp = parse_addr_spec(tmp, buf+len, &uri_b[num_uri], 1);
70
if (uri_b[num_uri].error == PARSE_ERROR)
72
LM_ERR("Error parsing PAI/PPI body %u '%.*s'\n", num_uri, len, buf);
77
if (num_uri >= NUM_PAI_BODIES)
79
LM_WARN("Too many bodies in PAI/PPI header '%.*s'\n", len, buf);
80
LM_WARN("Ignoring bodies beyond %u\n", NUM_PAI_BODIES);
82
*body = pkg_malloc(sizeof(p_id_body_t) + num_uri * sizeof(to_body_t));
85
LM_ERR("No pkg memory for pai/ppi body\n");
88
memset(*body, 0, sizeof(p_id_body_t));
89
(*body)->id = (to_body_t*)((char*)(*body) + sizeof(p_id_body_t));
90
(*body)->num_ids = num_uri;
91
for (i=0; i< num_uri; i++)
93
memcpy(&(*body)->id[i], &uri_b[i], sizeof(to_body_t));
98
int free_pai_ppi_body(p_id_body_t *pid_b)
108
* \brief Parse all P-Asserted-Identity headers
109
* \param msg The SIP message structure
110
* \return 0 on success, -1 on failure
112
int parse_pai_header(struct sip_msg* const msg)
115
p_id_body_t **prev_pid_b;
121
if (parse_headers(msg, HDR_PAI_F, 0) < 0)
123
LM_ERR("Error parsing PAI header\n");
131
if ( msg->pai->parsed )
134
vp = &msg->pai->parsed;
135
prev_pid_b = (p_id_body_t**)vp;
137
for (hf = msg->pai; hf != NULL; hf = next_sibling_hdr(hf))
139
if (parse_pai_ppi_body(hf->body.s, hf->body.len, &pai_b) < 0)
143
hf->parsed = (void*)pai_b;
145
prev_pid_b = &pai_b->next;
147
if (parse_headers(msg, HDR_PAI_F, 1) < 0)
149
LM_ERR("Error looking for subsequent PAI header");
157
* \brief Parse all P-Preferred-Identity headers
158
* \param msg The SIP message structure
159
* \return 0 on success, -1 on failure
161
int parse_ppi_header(struct sip_msg* const msg)
163
p_id_body_t *ppi_b, *prev_pidb;
168
if (parse_headers(msg, HDR_PPI_F, 0) < 0)
170
LM_ERR("Error parsing PPI header\n");
178
if ( msg->ppi->parsed )
181
if (parse_pai_ppi_body(msg->ppi->body.s, msg->ppi->body.len, &ppi_b) < 0)
185
msg->ppi->parsed = (void*)ppi_b;
187
if (parse_headers(msg, HDR_PPI_F, 1) < 0)
189
LM_ERR("Error looking for subsequent PPI header");
195
if ((hf = next_sibling_hdr(hf)) != NULL)
197
if (parse_pai_ppi_body(hf->body.s, hf->body.len, &ppi_b) < 0)
201
hf->parsed = (void*)ppi_b;
203
if (parse_headers(msg, HDR_PPI_F, 1) < 0)
205
LM_ERR("Error looking for subsequent PPI header");
208
prev_pidb->next = ppi_b;