Skip to content

Commit 58b0190

Browse files
committed
Merge remote-tracking branch 'upstream/master' into pr_github_actions
2 parents fff57ac + b8dee70 commit 58b0190

File tree

118 files changed

+3129
-1358
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+3129
-1358
lines changed

Makefile.defs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,9 @@ ifeq ($(CC_NAME:clang=gcc),gcc)
247247
#if gcc use gcc arch
248248
predef_macros:=$(shell $(CC) -dM -E -x c $(CC_EXTRA_OPTS) $(extra_defs) \
249249
$(CFLAGS) /dev/null)
250+
stdatomics_support:=$(shell printf '\43include <stdatomic.h>' | $(CC) -dM -E -x c $(CC_EXTRA_OPTS) $(extra_defs) \
251+
$(CFLAGS) /dev/stdin >/dev/null 2>/dev/null && printf '%sDHAVE_STDATOMIC' '-')
252+
DEFS+=$(stdatomics_support)
250253

251254
ifneq ($(strip $(filter $(i386_macros), $(predef_macros))),)
252255
CC_ARCH=i386

action.c

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,7 @@ int do_action(struct action* a, struct sip_msg* msg)
817817
script_trace("core", "xdbg", msg, a->file, a->line) ;
818818
if (a->elem[0].type == SCRIPTVAR_ELEM_ST)
819819
{
820-
ret = xdbg(msg, a->elem[0].u.data, val.rs.s);
820+
ret = xdbg(msg, a->elem[0].u.data);
821821
if (ret < 0)
822822
{
823823
LM_ERR("error while printing xdbg message\n");
@@ -861,7 +861,7 @@ int do_action(struct action* a, struct sip_msg* msg)
861861
ret=E_BUG;
862862
break;
863863
}
864-
ret = xlog_1(msg,a->elem[0].u.data, val.rs.s);
864+
ret = xlog_1(msg,a->elem[0].u.data);
865865
if (ret < 0)
866866
{
867867
LM_ERR("error while printing xlog message\n");
@@ -1190,3 +1190,81 @@ int route_params_run(struct sip_msg *msg, pv_param_t *ip, pv_value_t *res)
11901190
route_params[route_rec_level].params,
11911191
route_params[route_rec_level].extra);
11921192
}
1193+
1194+
1195+
static const char *_sip_msg_buf =
1196+
"DUMMY sip:[email protected] SIP/2.0\r\n"
1197+
"Via: SIP/2.0/UDP 127.0.0.1;branch=z9hG4bKdummy\r\n"
1198+
"To: <sip:[email protected]>\r\n"
1199+
"From: <sip:[email protected]>;tag=1\r\n"
1200+
"Call-ID: dummy-1\r\n"
1201+
"CSeq: 1 DUMMY\r\n\r\n";
1202+
static struct sip_msg* dummy_static_req= NULL;
1203+
static int dummy_static_in_used = 0;
1204+
1205+
struct sip_msg* get_dummy_sip_msg(void)
1206+
{
1207+
struct sip_msg* req;
1208+
1209+
if (dummy_static_req == NULL || dummy_static_in_used) {
1210+
/* if the static request is not yet allocated, or the static
1211+
* request is already in used (nested calls?), we better allocate
1212+
* a new structure */
1213+
LM_DBG("allocating new sip msg\n");
1214+
req = (struct sip_msg*)pkg_malloc(sizeof(struct sip_msg));
1215+
if(req == NULL)
1216+
{
1217+
LM_ERR("No more memory\n");
1218+
return NULL;
1219+
}
1220+
memset( req, 0, sizeof(struct sip_msg));
1221+
1222+
req->buf = (char*)_sip_msg_buf;
1223+
req->len = strlen(_sip_msg_buf);
1224+
req->rcv.src_ip.af = AF_INET;
1225+
req->rcv.dst_ip.af = AF_INET;
1226+
1227+
parse_msg((char*)_sip_msg_buf, strlen(_sip_msg_buf), req);
1228+
parse_headers( req, HDR_EOH_F, 0);
1229+
if (dummy_static_req==NULL) {
1230+
dummy_static_req = req;
1231+
dummy_static_in_used = 1;
1232+
LM_DBG("setting as static to %p\n",req);
1233+
}
1234+
} else {
1235+
/* reuse the static request */
1236+
req = dummy_static_req;
1237+
LM_DBG("reusing the static sip msg %p\n",req);
1238+
}
1239+
1240+
return req;
1241+
}
1242+
1243+
void release_dummy_sip_msg( struct sip_msg* req)
1244+
{
1245+
struct hdr_field* hdrs;
1246+
1247+
if (req==dummy_static_req) {
1248+
/* for the static request, just strip out the potential
1249+
* changes (lumps, new_uri, dst_uri, etc), but keep the parsed
1250+
* list of headers (this never changes) */
1251+
LM_DBG("cleaning the static sip msg %p\n",req);
1252+
hdrs = req->headers;
1253+
req->headers = NULL;
1254+
free_sip_msg(req);
1255+
req->headers = hdrs;
1256+
req->msg_cb = NULL;
1257+
req->new_uri.s = req->dst_uri.s = req->path_vec.s = NULL;
1258+
req->new_uri.len = req->dst_uri.len = req->path_vec.len = 0;
1259+
req->set_global_address.s = req->set_global_port.s = NULL;
1260+
req->set_global_address.len = req->set_global_port.len = 0;
1261+
req->add_rm = req->body_lumps = NULL;
1262+
req->reply_lump = NULL;
1263+
dummy_static_in_used = 0;
1264+
} else {
1265+
LM_DBG("freeing allocated sip msg %p\n",req);
1266+
/* is was an 100% allocated request */
1267+
free_sip_msg(req);
1268+
pkg_free(req);
1269+
}
1270+
}

action.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,8 @@ void route_params_push_level(char *rt_name, void *params, void *extra, param_get
9191
void route_params_pop_level(void);
9292
int route_params_run(struct sip_msg *msg, pv_param_t *ip, pv_value_t *res);
9393

94+
95+
struct sip_msg* get_dummy_sip_msg(void);
96+
void release_dummy_sip_msg( struct sip_msg* req);
97+
9498
#endif

atomic.h

Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
/*
2+
* Copyright (C) 2006 kernel.org
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+
21+
/*!
22+
* \file
23+
* \brief Assembler routines for atomic operations
24+
*
25+
* ======================== Deprecation Notice (2020) =========================
26+
* Although the C11 standard is available for nearly 10 years now and would
27+
* help us remove this file in favour of libc's stdatomic.h, some old and
28+
* popular OS'es for VoIP unfortunately have extended periods of support.
29+
* For example, CentOS 7 has a 10-year lifetime: 2014 - 2024!
30+
*
31+
* Several of the above-mentioned OS'es use old gcc builds (4.8 or older), with
32+
* partial support for C11, so stdatomic.h is not present. Dropping support
33+
* for these OS'es would affect a significant number of OpenSIPS deployments,
34+
* which is undesirable, at least for now.
35+
* ============================================================================
36+
*/
37+
38+
#ifndef _ATOMIC_OPS_H_
39+
#define _ATOMIC_OPS_H_
40+
41+
/************************* i386 & x86_64 ARCH ****************************/
42+
43+
#if defined(__CPU_i386) || defined(__CPU_x86_64)
44+
#if defined(__SMP_yes)
45+
#define LOCK "lock ; "
46+
#else
47+
#define LOCK ""
48+
#endif
49+
#endif
50+
51+
#if defined(__CPU_i386)
52+
53+
/*! \brief
54+
* atomic_set - set atomic variable
55+
* @v: pointer of type atomic_t
56+
* @i: required value
57+
*
58+
* Atomically sets the value of @v to @i.
59+
*/
60+
#define atomic_set(v,i) (((v)->counter) = (i))
61+
62+
/*! \brief
63+
* Make sure gcc doesn't try to be clever and move things around
64+
* on us. We need to use _exactly_ the address the user gave us,
65+
* not some alias that contains the same information.
66+
*/
67+
typedef struct { volatile unsigned int counter; } atomic_t;
68+
69+
/*! \brief
70+
* atomic_add - add integer to atomic variable
71+
* @i: integer value to add
72+
* @v: pointer of type atomic_t
73+
*
74+
* Atomically adds @i to @v.
75+
*/
76+
static __inline__ void atomic_add(int i, atomic_t *v)
77+
{
78+
__asm__ __volatile__(
79+
LOCK "addl %1,%0"
80+
:"=m" (v->counter)
81+
:"ir" (i), "m" (v->counter));
82+
}
83+
84+
/*! \brief
85+
* atomic_sub - subtract the atomic variable
86+
* @i: integer value to subtract
87+
* @v: pointer of type atomic_t
88+
*
89+
* Atomically subtracts @i from @v.
90+
*/
91+
static __inline__ void atomic_sub(int i, atomic_t *v)
92+
{
93+
__asm__ __volatile__(
94+
LOCK "subl %1,%0"
95+
:"=m" (v->counter)
96+
:"ir" (i), "m" (v->counter));
97+
}
98+
99+
/*! \brief
100+
* atomic_inc - increment atomic variable
101+
* @v: pointer of type atomic_t
102+
*
103+
* Atomically increments @v by 1.
104+
*/
105+
static __inline__ void atomic_inc(atomic_t *v)
106+
{
107+
__asm__ __volatile__(
108+
LOCK "incl %0"
109+
:"=m" (v->counter)
110+
:"m" (v->counter));
111+
}
112+
113+
/*! \brief
114+
* atomic_dec - decrement atomic variable
115+
* @v: pointer of type atomic_t
116+
*
117+
* Atomically decrements @v by 1.
118+
*/
119+
static __inline__ void atomic_dec(atomic_t *v)
120+
{
121+
__asm__ __volatile__(
122+
LOCK "decl %0"
123+
:"=m" (v->counter)
124+
:"m" (v->counter));
125+
}
126+
127+
#undef NO_ATOMIC_OPS
128+
129+
#elif defined(__CPU_x86_64) /* __CPU_i386 */
130+
131+
/*! \brief
132+
* Make sure gcc doesn't try to be clever and move things around
133+
* on us. We need to use _exactly_ the address the user gave us,
134+
* not some alias that contains the same information.
135+
*/
136+
typedef struct { volatile unsigned long counter; } atomic_t;
137+
138+
/*! \brief
139+
* atomic_set - set atomic variable
140+
* @v: pointer of type atomic_t
141+
* @i: required value
142+
*
143+
* Atomically sets the value of @v to @i.
144+
*/
145+
#define atomic_set(v,i) (((v)->counter) = (i))
146+
147+
/*! \brief
148+
* atomic_add - add integer to atomic variable
149+
* @i: integer value to add
150+
* @v: pointer of type atomic_t
151+
*
152+
* Atomically adds @i to @v.
153+
*/
154+
static __inline__ void atomic_add(unsigned long i, atomic_t *v)
155+
{
156+
__asm__ __volatile__(
157+
LOCK "addq %1,%0"
158+
:"=m" (v->counter)
159+
:"er" (i), "m" (v->counter));
160+
}
161+
162+
/*! \brief
163+
* atomic_sub - subtract the atomic variable
164+
* @i: integer value to subtract
165+
* @v: pointer of type atomic_t
166+
*
167+
* Atomically subtracts @i from @v.
168+
*/
169+
static __inline__ void atomic_sub(unsigned long i, atomic_t *v)
170+
{
171+
__asm__ __volatile__(
172+
LOCK "subq %1,%0"
173+
:"=m" (v->counter)
174+
:"er" (i), "m" (v->counter));
175+
}
176+
177+
/*! \brief
178+
* atomic_inc - increment atomic variable
179+
* @v: pointer of type atomic_t
180+
*
181+
* Atomically increments @v by 1.
182+
*/
183+
static __inline__ void atomic_inc(atomic_t *v)
184+
{
185+
__asm__ __volatile__(
186+
LOCK "incq %0"
187+
:"=m" (v->counter)
188+
:"m" (v->counter));
189+
}
190+
191+
/*! \brief
192+
* atomic_dec - decrement atomic variable
193+
* @v: pointer of type atomic_t
194+
*
195+
* Atomically decrements @v by 1.
196+
*/
197+
static __inline__ void atomic_dec(atomic_t *v)
198+
{
199+
__asm__ __volatile__(
200+
LOCK "decq %0"
201+
:"=m" (v->counter)
202+
:"m" (v->counter));
203+
}
204+
205+
#undef NO_ATOMIC_OPS
206+
207+
/************************* other ARCH ****************************/
208+
209+
#else
210+
211+
#define NO_ATOMIC_OPS
212+
213+
#endif
214+
215+
/* C11 stdatomics wrappers */
216+
#define atomic_init(a, v) atomic_set(a, v)
217+
#define atomic_store(a, v) atomic_set(a, v)
218+
#define atomic_load(a) ((a)->counter)
219+
#define atomic_fetch_add(a, v) \
220+
if ((long)(v) >= 0L) \
221+
atomic_add(v, a);\
222+
else \
223+
atomic_sub(-(v), a);
224+
225+
#endif

cachedb/cachedb_id.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,8 @@ static int parse_cachedb_url(struct cachedb_id* id, const str* url)
270270
case ST_DB:
271271
switch(url->s[i]) {
272272
case '?':
273-
if (dupl_string(&id->database, begin, url->s + i) < 0) goto err;
273+
if (url->s + i > begin &&
274+
dupl_string(&id->database, begin, url->s + i) < 0) goto err;
274275
if (url->s + i + 1 == url->s + len) {
275276
st = ST_OPTIONS;
276277
break;

cachedb/cachedb_id.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828

2929
#include "../str.h"
3030

31+
#define CACHEDB_TLS_DOM_PARAM "tls_domain="
32+
#define CACHEDB_TLS_DOM_PARAM_LEN (sizeof(CACHEDB_TLS_DOM_PARAM)-1)
33+
3134
/** Structure representing a database ID */
3235
struct cachedb_id {
3336
char* scheme; /**< URL scheme */

0 commit comments

Comments
 (0)