Coverage Report

Created: 2024-02-25 06:34

/src/kamailio/src/core/parser/parse_allow.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (c) 2004 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 :: Allow header
23
 *
24
 * \ingroup parser
25
 */
26
27
28
#include <stdlib.h>
29
#include <string.h>
30
#include "../dprint.h"
31
#include "../mem/mem.h"
32
#include "parse_allow.h"
33
#include "parse_methods.h"
34
#include "msg_parser.h"
35
36
37
/*! \brief
38
 * This method is used to parse Allow header.
39
 *
40
 * \param _hf message header field
41
 * \return 0 on success, -1 on failure.
42
 */
43
int parse_allow_header(struct hdr_field *_hf)
44
0
{
45
0
  struct allow_body *ab = 0;
46
47
0
  if(!_hf) {
48
0
    LM_ERR("invalid parameter value\n");
49
0
    return -1;
50
0
  }
51
52
  /* maybe the header is already parsed! */
53
0
  if(_hf->parsed) {
54
0
    return 0;
55
0
  }
56
57
0
  ab = (struct allow_body *)pkg_malloc(sizeof(struct allow_body));
58
0
  if(ab == 0) {
59
0
    PKG_MEM_ERROR;
60
0
    return -1;
61
0
  }
62
0
  memset(ab, '\0', sizeof(struct allow_body));
63
64
0
  if(parse_methods(&(_hf->body), &(ab->allow)) != 0) {
65
0
    LM_ERR("bad allow body header\n");
66
0
    goto error;
67
0
  }
68
69
0
  ab->allow_all = 0;
70
0
  _hf->parsed = (void *)ab;
71
0
  return 0;
72
73
0
error:
74
0
  if(ab)
75
0
    pkg_free(ab);
76
0
  return -1;
77
0
}
78
79
/*!
80
 * \brief This method is used to parse all Allow HF body.
81
 * \param msg sip msg
82
 * \return 0 on success,-1 on failure.
83
 */
84
int parse_allow(struct sip_msg *msg)
85
0
{
86
0
  unsigned int allow;
87
0
  struct hdr_field *hdr;
88
89
  /* maybe the header is already parsed! */
90
0
  if(msg->allow && msg->allow->parsed) {
91
0
    return 0;
92
0
  }
93
94
  /* parse to the end in order to get all ALLOW headers */
95
0
  if(parse_headers(msg, HDR_EOH_F, 0) == -1 || !msg->allow) {
96
0
    return -1;
97
0
  }
98
0
  allow = 0;
99
100
0
  for(hdr = msg->allow; hdr; hdr = next_sibling_hdr(hdr)) {
101
0
    if(hdr->parsed == 0) {
102
0
      if(parse_allow_header(hdr) < 0) {
103
0
        return -1;
104
0
      }
105
0
    }
106
107
0
    allow |= ((struct allow_body *)hdr->parsed)->allow;
108
0
  }
109
110
0
  ((struct allow_body *)msg->allow->parsed)->allow_all = allow;
111
0
  return 0;
112
0
}
113
114
115
/*
116
 * Release memory
117
 */
118
void free_allow_body(struct allow_body **ab)
119
0
{
120
0
  if(ab && *ab) {
121
0
    pkg_free(*ab);
122
0
    *ab = 0;
123
0
  }
124
0
}
125
126
127
void free_allow_header(struct hdr_field *hf)
128
0
{
129
0
  free_allow_body((struct allow_body **)(void *)(&(hf->parsed)));
130
0
}