Coverage Report

Created: 2025-10-10 06:06

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/opensips/parser/parse_cseq.c
Line
Count
Source
1
/*
2
 * Copyright (C) 2001-2003 FhG Fokus
3
 *
4
 * This file is part of opensips, a free SIP server.
5
 *
6
 * opensips 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
 * opensips 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
 * History:
21
 * --------
22
 * 2003-02-28 scratchpad compatibility abandoned (jiri)
23
 * 2003-01-22 zero-termination in CSeq eliminated (jiri)
24
 */
25
26
27
#include "../dprint.h"
28
#include "parse_cseq.h"
29
#include "parser_f.h"  /* eat_space_end and so on */
30
#include "parse_def.h"
31
#include "parse_methods.h"
32
#include "../mem/mem.h"
33
34
/*
35
 * Parse CSeq header field
36
 */
37
38
char* parse_cseq(char *buf, char* end, struct cseq_body* cb)
39
41.2k
{
40
41.2k
  char *t, *m, *m_end;
41
42
41.2k
  cb->error=PARSE_ERROR;
43
41.2k
  t=buf;
44
45
41.2k
  cb->number.s=t;
46
41.2k
  t=eat_token_end(t, end);
47
41.2k
  if (t>=end) goto error;
48
41.2k
  cb->number.len=t-cb->number.s;
49
50
41.2k
  m=eat_space_end(t, end);
51
41.2k
  m_end=eat_token_end(m, end);
52
53
41.2k
  if (m_end>=end) {
54
48
      LM_ERR("method terminated unexpectedly\n");
55
48
      goto error;
56
48
  }
57
41.1k
  if (m_end==m){
58
    /* null method*/
59
16
    LM_ERR("no method found\n");
60
16
    goto error;
61
16
  }
62
41.1k
  cb->method.s=m;
63
41.1k
  t=m_end;
64
41.1k
  cb->method.len=t-cb->method.s;
65
66
  /* cache the method id */
67
41.1k
  if(parse_method(cb->method.s, t, (unsigned int*)&cb->method_id)==0)
68
179
  {
69
179
    LM_ERR("cannot parse the method\n");
70
179
    goto error;
71
179
  }
72
73
  /* there may be trailing LWS
74
   * (it was not my idea to put it in SIP; -jiri )
75
   */
76
40.9k
  t=eat_lws_end(t, end);
77
  /*check if the header ends here*/
78
40.9k
  if (t>=end) {
79
241
    LM_ERR("strange EoHF\n");
80
241
    goto error;
81
241
  }
82
40.7k
  if (*t=='\r' && t+1<end && *(t+1)=='\n') {
83
446
      cb->error=PARSE_OK;
84
446
      return t+2;
85
446
  }
86
40.2k
  if (*t=='\n') {
87
40.2k
      cb->error=PARSE_OK;
88
40.2k
      return t+1;
89
40.2k
  }
90
74
  LM_ERR("expecting CSeq EoL\n");
91
92
567
error:
93
567
  LM_ERR("bad cseq\n");
94
567
  return t;
95
74
}
96
97
98
void free_cseq(struct cseq_body* cb)
99
40.6k
{
100
40.6k
  pkg_free(cb);
101
40.6k
}