Coverage Report

Created: 2025-08-29 06:53

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