-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmohq_common.h
130 lines (112 loc) · 3.97 KB
/
mohq_common.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
* Copyright (C) 2013-21 Robert Boisvert
*
* This file is part of the mohqueue module for Kamailio, a free SIP server.
*
* The mohqueue module is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version
*
* The mohqueue module is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifndef MOHQ_COMMON_H
#define MOHQ_COMMON_H
#include <assert.h>
#include <sys/stat.h>
#include "../rr/api.h"
#if VERSIONVAL < 5000000
#include "../../data_lump.h"
#include "../../data_lump_rpl.h"
#include "../../dprint.h"
#include "../../dset.h"
#include "../../flags.h"
#include "../../hashes.h"
#include "../../locking.h"
#include "../../lvalue.h"
#include "../../mod_fix.h"
#include "../../rpc.h"
#include "../../rpc_lookup.h"
#include "../../sr_module.h"
#include "../../str.h"
#include "../../mem/mem.h"
#include "../../mem/shm_mem.h"
#include "../../parser/hf.h"
#include "../../parser/msg_parser.h"
#include "../../parser/contact/parse_contact.h"
#include "../../parser/parse_expires.h"
#include "../../parser/parse_from.h"
#include "../../parser/parse_rr.h"
#include "../../parser/sdp/sdp.h"
#else
#include "../../core/data_lump.h"
#include "../../core/data_lump_rpl.h"
#include "../../core/dprint.h"
#include "../../core/dset.h"
#include "../../core/flags.h"
#include "../../core/hashes.h"
#include "../../core/locking.h"
#include "../../core/lvalue.h"
#include "../../core/mem/mem.h"
#include "../../core/mem/shm_mem.h"
#include "../../core/mod_fix.h"
#include "../../core/parser/hf.h"
#include "../../core/parser/msg_parser.h"
#include "../../core/parser/contact/parse_contact.h"
#include "../../core/parser/parse_expires.h"
#include "../../core/parser/parse_from.h"
#include "../../core/parser/parse_rr.h"
#include "../../core/parser/sdp/sdp.h"
#include "../../core/rpc.h"
#include "../../core/rpc_lookup.h"
#include "../../core/sr_module.h"
#include "../../core/str.h"
#endif
#include "../../lib/srdb1/db.h"
#include "../../modules/sl/sl.h"
#include "../../modules/tm/tm_load.h"
/* convenience macros */
#define MOHQ_STRUCT_PTR_OFFSET( struct1, cast1, offset1 ) \
(cast1)(struct1) + (offset1)
#define MOHQ_STR_COPY( str1, str2 ) \
memcpy((str1)->s, (str2)->s, (str2)->len ); \
(str1)->len = (str2)->len;
#define MOHQ_STR_APPEND( str1, str2 ) \
memcpy((str1)->s + (str1)->len, (str2)->s, (str2)->len); \
(str1)->len += (str2)->len;
#define MOHQ_STR_APPEND_L( str1, str1_lim, s2, s2_len ) \
if ((str1)->len + (s2_len) >= (str1_lim)) { \
LM_ERR( "Failed to append to str: too long!\n" ); \
} else { \
MOHQ_STR_APPEND((str1), (s2), (s2_len)); \
(str1_lim) -= (s2_len); \
}
#define MOHQ_STR_COPY_CSTR( str1, cstr1 ) \
memcpy((str1)->s + (str1)->len, (cstr1), strlen((cstr1))); \
(str1)->len += strlen((cstr1));
#define MOHQ_STR_APPEND_CSTR( str1, cstr1 ) \
MOHQ_STR_COPY_CSTR((str1), (cstr1))
#define MOHQ_STR_APPEND_CSTR_L( str1, str1_lim, cstr1 ) \
if ((str1)->len + strlen(cstr1) >= (str1_lim)) { \
LM_ERR( "Failed to append to str: too long!\n" ); \
} else { \
MOHQ_STR_APPEND_CSTR((str1), (cstr1)); \
}
/* STR_EQ assumes we're not using str pointers, which is obnoxious */
#define MOHQ_STR_EQ( str1, str2 ) \
(((str1)->len == (str2)->len) && \
memcmp((str1)->s, (str2)->s, (str1)->len) == 0)
#define MOHQ_STR_EMPTY( str1 ) \
(((str1) != NULL && ((str1)->s == NULL || (str1)->len <= 0 )) \
|| (str1) == NULL )
#define MOHQ_HEADER_EMPTY( hdr1 ) \
((hdr1) == NULL || MOHQ_STR_EMPTY( &(hdr1)->body ))
#endif /* MOHQ_COMMON_H */