Coverage Report

Created: 2024-06-18 06:21

/src/kamailio/src/core/parser/parse_to.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (C) 2001-2003 Fhg Fokus
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
22
/** Parser :: Parse To: header.
23
 * @file
24
 * @ingroup parser
25
 */
26
27
#include "parse_to.h"
28
#include "parse_addr_spec.h"
29
#include <stdlib.h>
30
#include <string.h>
31
#include "../dprint.h"
32
#include "msg_parser.h"
33
#include "parse_uri.h"
34
#include "../ut.h"
35
#include "../mem/mem.h"
36
37
38
char *parse_to(
39
    char *const buffer, const char *const end, struct to_body *const to_b)
40
25.8k
{
41
25.8k
  return parse_addr_spec(buffer, end, to_b, 0);
42
25.8k
}
43
44
45
int parse_to_header(struct sip_msg *const msg)
46
30.4k
{
47
30.4k
  if(!msg->to && (parse_headers(msg, HDR_TO_F, 0) == -1 || !msg->to)) {
48
21.8k
    LM_ERR("bad msg or missing TO header\n");
49
21.8k
    return -1;
50
21.8k
  }
51
52
  // HDR_TO_T is automatically parsed (get_hdr_field in parser/msg_parser.c)
53
  // so check only ptr validity
54
8.65k
  if(msg->to->parsed)
55
8.65k
    return 0;
56
0
  else
57
0
    return -1;
58
8.65k
}
59
60
sip_uri_t *parse_to_uri(sip_msg_t *const msg)
61
15.2k
{
62
15.2k
  to_body_t *tb = NULL;
63
64
15.2k
  if(msg == NULL)
65
0
    return NULL;
66
67
15.2k
  if(parse_to_header(msg) < 0) {
68
10.9k
    LM_ERR("cannot parse TO header\n");
69
10.9k
    return NULL;
70
10.9k
  }
71
72
4.32k
  if(msg->to == NULL || get_to(msg) == NULL)
73
0
    return NULL;
74
75
4.32k
  tb = get_to(msg);
76
77
4.32k
  if(tb->parsed_uri.user.s != NULL || tb->parsed_uri.host.s != NULL)
78
0
    return &tb->parsed_uri;
79
80
4.32k
  if(parse_uri(tb->uri.s, tb->uri.len, &tb->parsed_uri) < 0) {
81
1.50k
    LM_ERR("failed to parse To uri\n");
82
1.50k
    memset(&tb->parsed_uri, 0, sizeof(struct sip_uri));
83
1.50k
    return NULL;
84
1.50k
  }
85
86
2.81k
  return &tb->parsed_uri;
87
4.32k
}