Coverage Report

Created: 2025-07-18 06:32

/src/opensips/parser/parse_pai.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (C) 2006 Juha Heinanen
3
 *
4
 *
5
 * This file is part of opensips, a free SIP server.
6
 *
7
 * opensips is free software; you can redistribute it and/or modify
8
 * it under the terms of the GNU General Public License as published by
9
 * the Free Software Foundation; either version 2 of the License, or
10
 * (at your option) any later version
11
 *
12
 * opensips is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
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 P-Asserted-Identity header (RFC 3325).
35
 *
36
 * params: msg : sip msg
37
 * returns 0 on success,
38
 *        -1 on failure.
39
 */
40
int parse_pai_header( struct sip_msg *msg )
41
0
{
42
0
  struct to_body* pai_b;
43
44
0
  if ( !msg->pai &&
45
0
    (parse_headers(msg, HDR_PAI_F,0)==-1 || !msg->pai)) {
46
0
    goto error;
47
0
  }
48
49
  /* maybe the header is already parsed! */
50
0
  if (msg->pai->parsed)
51
0
    return 0;
52
53
  /* bad luck! :-( - we have to parse it */
54
  /* first, get some memory */
55
0
  pai_b = pkg_malloc(sizeof(struct to_body));
56
0
  if (pai_b == NULL) {
57
0
    LM_ERR("out of pkg memory\n");
58
0
    goto error;
59
0
  }
60
61
  /* now parse it as a multi name-addr/addr-spec instance header !! */
62
0
  parse_multi_to( msg->pai->body.s, msg->pai->body.s + msg->pai->body.len+1,
63
0
    pai_b);
64
0
  if (pai_b->error == PARSE_ERROR) {
65
0
    LM_ERR("failed to parse P-Asserted-Identity header\n");
66
0
    pkg_free(pai_b);
67
0
    set_err_info(OSER_EC_PARSER, OSER_EL_MEDIUM,
68
0
      "error parsing PAI header");
69
0
    set_err_reply(400, "bad header");
70
0
    goto error;
71
0
  }
72
73
  /* check header validity */
74
0
  msg->pai->parsed = pai_b;
75
76
0
  return 0;
77
0
error:
78
0
  return -1;
79
0
}