Coverage Report

Created: 2025-04-11 06:59

/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
47.2k
{
40
47.2k
  char *t, *m, *m_end;
41
42
47.2k
  cb->error=PARSE_ERROR;
43
47.2k
  t=buf;
44
45
47.2k
  cb->number.s=t;
46
47.2k
  t=eat_token_end(t, end);
47
47.2k
  if (t>=end) goto error;
48
47.2k
  cb->number.len=t-cb->number.s;
49
50
47.2k
  m=eat_space_end(t, end);
51
47.2k
  m_end=eat_token_end(m, end);
52
53
47.2k
  if (m_end>=end) {
54
38
      LM_ERR("method terminated unexpectedly\n");
55
38
      goto error;
56
38
  }
57
47.2k
  if (m_end==m){
58
    /* null method*/
59
17
    LM_ERR("no method found\n");
60
17
    goto error;
61
17
  }
62
47.1k
  cb->method.s=m;
63
47.1k
  t=m_end;
64
47.1k
  cb->method.len=t-cb->method.s;
65
66
  /* cache the method id */
67
47.1k
  if(parse_method(cb->method.s, t, (unsigned int*)&cb->method_id)==0)
68
207
  {
69
207
    LM_ERR("cannot parse the method\n");
70
207
    goto error;
71
207
  }
72
73
  /* there may be trailing LWS
74
   * (it was not my idea to put it in SIP; -jiri )
75
   */
76
46.9k
  t=eat_lws_end(t, end);
77
  /*check if the header ends here*/
78
46.9k
  if (t>=end) {
79
284
    LM_ERR("strange EoHF\n");
80
284
    goto error;
81
284
  }
82
46.6k
  if (*t=='\r' && t+1<end && *(t+1)=='\n') {
83
235
      cb->error=PARSE_OK;
84
235
      return t+2;
85
235
  }
86
46.4k
  if (*t=='\n') {
87
46.3k
      cb->error=PARSE_OK;
88
46.3k
      return t+1;
89
46.3k
  }
90
83
  LM_ERR("expecting CSeq EoL\n");
91
92
642
error:
93
642
  LM_ERR("bad cseq\n");
94
642
  return t;
95
83
}
96
97
98
void free_cseq(struct cseq_body* cb)
99
46.6k
{
100
46.6k
  pkg_free(cb);
101
46.6k
}