Coverage Report

Created: 2024-02-25 06:34

/src/kamailio/src/core/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 Kamailio, a free SIP server.
5
 *
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
10
 *
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.
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
/*! \file
22
 * \brief Parser :: Remote-party-id: header parser
23
 *
24
 * \ingroup parser
25
 */
26
27
#include "parse_from.h"
28
#include "parse_to.h"
29
#include <stdlib.h>
30
#include <string.h>
31
#include "../dprint.h"
32
#include "msg_parser.h"
33
#include "../ut.h"
34
#include "../mem/mem.h"
35
36
37
/*! \brief
38
 * This method is used to parse RPID header.
39
 *
40
 * params: msg : sip msg
41
 * returns 0 on success,
42
 *        -1 on failure.
43
 */
44
int parse_rpid_header(struct sip_msg *msg)
45
0
{
46
0
  struct to_body *rpid_b;
47
48
0
  if(!msg->rpid && (parse_headers(msg, HDR_RPID_F, 0) == -1 || !msg->rpid)) {
49
0
    goto error;
50
0
  }
51
52
  /* maybe the header is already parsed! */
53
0
  if(msg->rpid->parsed)
54
0
    return 0;
55
56
  /* needs to parse it */
57
  /* first, get some memory */
58
0
  rpid_b = pkg_malloc(sizeof(struct to_body));
59
0
  if(rpid_b == 0) {
60
0
    PKG_MEM_ERROR;
61
0
    goto error;
62
0
  }
63
64
  /* now parse it!! */
65
0
  memset(rpid_b, 0, sizeof(struct to_body));
66
0
  parse_to(msg->rpid->body.s, msg->rpid->body.s + msg->rpid->body.len + 1,
67
0
      rpid_b);
68
0
  if(rpid_b->error == PARSE_ERROR) {
69
0
    LM_ERR("bad rpid header\n");
70
0
    free_to(rpid_b);
71
0
    goto error;
72
0
  }
73
0
  msg->rpid->parsed = rpid_b;
74
75
0
  return 0;
76
0
error:
77
0
  return -1;
78
0
}