mirror of
https://git.openwrt.org/feed/telephony.git
synced 2025-01-09 04:09:47 +08:00
kamailio: backport and move to PCRE2
Backport merged patch and move package to PCRE2 as PCRE is EOL and won't receive any security updates anymore. Additional patch are backported to minimize changes to the backport patches. Only patch 010 required adaptation due to a fix backported in 5.7 in the same place where the patch fixed some whitespace issue. Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
This commit is contained in:
parent
231910de5f
commit
ac4ad7f6fc
@ -10,7 +10,7 @@ include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=kamailio
|
||||
PKG_VERSION:=5.7.2
|
||||
PKG_RELEASE:=1
|
||||
PKG_RELEASE:=2
|
||||
|
||||
PKG_SOURCE_URL:=https://www.kamailio.org/pub/kamailio/$(PKG_VERSION)/src
|
||||
PKG_SOURCE:=kamailio-$(PKG_VERSION)_src.tar.gz
|
||||
@ -521,7 +521,7 @@ $(eval $(call BuildKamailioModule,db_text,Text DB-backend,,,dbtext/kamailio))
|
||||
$(eval $(call BuildKamailioModule,db_unixodbc,UnixODBC DB-backend,,+unixodbc))
|
||||
$(eval $(call BuildKamailioModule,debugger,Interactive config file debugger,,))
|
||||
$(eval $(call BuildKamailioModule,dialog,Dialog support,,+kamailio-mod-rr +kamailio-mod-tm))
|
||||
$(eval $(call BuildKamailioModule,dialplan,Dialplan management,,+libpcre))
|
||||
$(eval $(call BuildKamailioModule,dialplan,Dialplan management,,+libpcre2))
|
||||
$(eval $(call BuildKamailioModule,dispatcher,Dispatcher,,))
|
||||
$(eval $(call BuildKamailioModule,diversion,Diversion header insertion,,))
|
||||
$(eval $(call BuildKamailioModule,dlgs,Track active calls in stateless mode,,))
|
||||
@ -562,7 +562,7 @@ $(eval $(call BuildKamailioModule,jsonrpcs,JSONRPC server over HTTP,,+libevent2)
|
||||
$(eval $(call BuildKamailioModule,keepalive,SIP keepalive monitoring,,+kamailio-mod-tm,,))
|
||||
$(eval $(call BuildKamailioModule,kemix,KEMI extensions,,,))
|
||||
$(eval $(call BuildKamailioModule,kex,Core extensions,,))
|
||||
$(eval $(call BuildKamailioModule,lcr,Least Cost Routing,,+kamailio-mod-tm +libpcre))
|
||||
$(eval $(call BuildKamailioModule,lcr,Least Cost Routing,,+kamailio-mod-tm +libpcre2))
|
||||
$(eval $(call BuildKamailioModule,ldap,LDAP connector,,+libopenldap))
|
||||
$(eval $(call BuildKamailioModule,log_custom,Logging to custom backends,,))
|
||||
$(eval $(call BuildKamailioModule,lost,HELD and LOST routing,,+kamailio-mod-http-client,))
|
||||
@ -610,7 +610,7 @@ $(eval $(call BuildKamailioModule,pv,Pseudo-Variables,,))
|
||||
$(eval $(call BuildKamailioModule,pv_headers,Flexible SIP header management,,))
|
||||
$(eval $(call BuildKamailioModule,qos,QoS control,,+kamailio-mod-dialog))
|
||||
$(eval $(call BuildKamailioModule,ratelimit,Traffic shapping,,))
|
||||
$(eval $(call BuildKamailioModule,regex,Regular Expression,,+libpcre))
|
||||
$(eval $(call BuildKamailioModule,regex,Regular Expression,,+libpcre2))
|
||||
$(eval $(call BuildKamailioModule,registrar,SIP Registrar,,+kamailio-mod-usrloc))
|
||||
$(eval $(call BuildKamailioModule,rls,Resource List Server,,+kamailio-mod-presence +kamailio-mod-pua +kamailio-mod-tm,))
|
||||
$(eval $(call BuildKamailioModule,rr,Record-Route and Route,,))
|
||||
|
File diff suppressed because it is too large
Load Diff
456
net/kamailio/patches/011-dialplan-migrate-to-pcre2.patch
Normal file
456
net/kamailio/patches/011-dialplan-migrate-to-pcre2.patch
Normal file
@ -0,0 +1,456 @@
|
||||
From 374227b15ff7fbed8660beb93d52da15dcb4ba9e Mon Sep 17 00:00:00 2001
|
||||
From: Victor Seva <linuxmaniac@torreviejawireless.org>
|
||||
Date: Mon, 21 Aug 2023 12:27:43 +0200
|
||||
Subject: [PATCH] dialplan: migrate to pcre2
|
||||
|
||||
---
|
||||
src/modules/dialplan/Makefile | 11 +---
|
||||
src/modules/dialplan/dialplan.c | 5 ++
|
||||
src/modules/dialplan/dialplan.h | 20 ++++---
|
||||
src/modules/dialplan/dp_db.c | 103 +++++++++++++++++++-------------
|
||||
src/modules/dialplan/dp_repl.c | 56 +++++++++++------
|
||||
5 files changed, 121 insertions(+), 74 deletions(-)
|
||||
|
||||
--- a/src/modules/dialplan/Makefile
|
||||
+++ b/src/modules/dialplan/Makefile
|
||||
@@ -6,20 +6,15 @@ auto_gen=
|
||||
NAME=dialplan.so
|
||||
|
||||
ifeq ($(CROSS_COMPILE),)
|
||||
-PCRE_BUILDER = $(shell \
|
||||
- if pkg-config --exists libcre; then \
|
||||
- echo 'pkg-config libpcre'; \
|
||||
- else \
|
||||
- which pcre-config; \
|
||||
- fi)
|
||||
+PCRE_BUILDER = $(shell command -v pcre2-config)
|
||||
endif
|
||||
|
||||
ifeq ($(PCRE_BUILDER),)
|
||||
PCREDEFS=-I$(LOCALBASE)/include
|
||||
- PCRELIBS=-L$(LOCALBASE)/lib -lpcre
|
||||
+ PCRELIBS=-L$(LOCALBASE)/lib -lpcre2-8
|
||||
else
|
||||
PCREDEFS = $(shell $(PCRE_BUILDER) --cflags)
|
||||
- PCRELIBS = $(shell $(PCRE_BUILDER) --libs)
|
||||
+ PCRELIBS = $(shell $(PCRE_BUILDER) --libs8)
|
||||
endif
|
||||
DEFS+=$(PCREDEFS)
|
||||
LIBS=$(PCRELIBS)
|
||||
--- a/src/modules/dialplan/dialplan.c
|
||||
+++ b/src/modules/dialplan/dialplan.c
|
||||
@@ -5,6 +5,8 @@
|
||||
*
|
||||
* Copyright (C) 2014 Olle E. Johansson, Edvina AB
|
||||
*
|
||||
+ * Copyright (C) 2023 Victor Seva
|
||||
+ *
|
||||
* This file is part of Kamailio, a free SIP server.
|
||||
*
|
||||
* Kamailio is free software; you can redistribute it and/or modify
|
||||
@@ -79,6 +81,9 @@ static int ki_dp_translate_vars(
|
||||
int dp_replace_fixup(void **param, int param_no);
|
||||
int dp_replace_fixup_free(void **param, int param_no);
|
||||
|
||||
+pcre2_general_context *dpl_gctx = NULL;
|
||||
+pcre2_compile_context *dpl_ctx = NULL;
|
||||
+
|
||||
str dp_attr_pvar_s = STR_NULL;
|
||||
pv_spec_t *dp_attr_pvar = NULL;
|
||||
|
||||
--- a/src/modules/dialplan/dialplan.h
|
||||
+++ b/src/modules/dialplan/dialplan.h
|
||||
@@ -13,8 +13,8 @@
|
||||
* 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
|
||||
+ * 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
|
||||
*
|
||||
*/
|
||||
@@ -30,7 +30,8 @@
|
||||
#ifndef _DP_DIALPLAN_H
|
||||
#define _DP_DIALPLAN_H
|
||||
|
||||
-#include <pcre.h>
|
||||
+#define PCRE2_CODE_UNIT_WIDTH 8
|
||||
+#include <pcre2.h>
|
||||
#include "../../core/pvar.h"
|
||||
#include "../../core/parser/msg_parser.h"
|
||||
|
||||
@@ -43,6 +44,9 @@
|
||||
#define DP_TFLAGS_PV_MATCH (1 << 0)
|
||||
#define DP_TFLAGS_PV_SUBST (1 << 1)
|
||||
|
||||
+extern pcre2_general_context *dpl_gctx;
|
||||
+extern pcre2_compile_context *dpl_ctx;
|
||||
+
|
||||
typedef struct dpl_node
|
||||
{
|
||||
int dpid; /* dialplan id */
|
||||
@@ -52,8 +56,8 @@ typedef struct dpl_node
|
||||
str match_exp; /* match-first string */
|
||||
str subst_exp; /* match string with subtitution groupping */
|
||||
str repl_exp; /* replacement expression string */
|
||||
- pcre *match_comp; /* compiled matching expression */
|
||||
- pcre *subst_comp; /* compiled substitution expression */
|
||||
+ pcre2_code *match_comp; /* compiled matching expression */
|
||||
+ pcre2_code *subst_comp; /* compiled substitution expression */
|
||||
struct subst_expr *repl_comp; /* compiled replacement */
|
||||
str attrs; /* attributes string */
|
||||
unsigned int tflags; /* flags for type of values for matching */
|
||||
@@ -103,8 +107,8 @@ struct subst_expr *repl_exp_parse(str su
|
||||
void repl_expr_free(struct subst_expr *se);
|
||||
int dp_translate_helper(
|
||||
sip_msg_t *msg, str *user_name, str *repl_user, dpl_id_p idp, str *);
|
||||
-int rule_translate(
|
||||
- sip_msg_t *msg, str *instr, dpl_node_t *rule, pcre *subst_comp, str *);
|
||||
+int rule_translate(sip_msg_t *msg, str *instr, dpl_node_t *rule,
|
||||
+ pcre2_code *subst_comp, str *);
|
||||
|
||||
-pcre *reg_ex_comp(const char *pattern, int *cap_cnt, int mtype);
|
||||
+pcre2_code *reg_ex_comp(const char *pattern, int *cap_cnt, int mtype);
|
||||
#endif
|
||||
--- a/src/modules/dialplan/dp_db.c
|
||||
+++ b/src/modules/dialplan/dp_db.c
|
||||
@@ -196,11 +196,31 @@ void dp_disconnect_db(void)
|
||||
}
|
||||
}
|
||||
|
||||
+static void *pcre2_malloc(size_t size, void *ext)
|
||||
+{
|
||||
+ return shm_malloc(size);
|
||||
+}
|
||||
+
|
||||
+static void pcre2_free(void *ptr, void *ext)
|
||||
+{
|
||||
+ shm_free(ptr);
|
||||
+ ptr = NULL;
|
||||
+}
|
||||
|
||||
int init_data(void)
|
||||
{
|
||||
int *p;
|
||||
|
||||
+ if((dpl_gctx = pcre2_general_context_create(pcre2_malloc, pcre2_free, NULL))
|
||||
+ == NULL) {
|
||||
+ LM_ERR("pcre2 general context creation failed\n");
|
||||
+ return -1;
|
||||
+ }
|
||||
+ if((dpl_ctx = pcre2_compile_context_create(dpl_gctx)) == NULL) {
|
||||
+ LM_ERR("pcre2 compile context creation failed\n");
|
||||
+ return -1;
|
||||
+ }
|
||||
+
|
||||
dp_rules_hash = (dpl_id_p *)shm_malloc(2 * sizeof(dpl_id_p));
|
||||
if(!dp_rules_hash) {
|
||||
LM_ERR("out of shm memory\n");
|
||||
@@ -227,6 +247,14 @@ int init_data(void)
|
||||
|
||||
void destroy_data(void)
|
||||
{
|
||||
+ if(dpl_ctx) {
|
||||
+ pcre2_compile_context_free(dpl_ctx);
|
||||
+ }
|
||||
+
|
||||
+ if(dpl_gctx) {
|
||||
+ pcre2_general_context_free(dpl_gctx);
|
||||
+ }
|
||||
+
|
||||
if(dp_rules_hash) {
|
||||
destroy_hash(0);
|
||||
destroy_hash(1);
|
||||
@@ -373,55 +401,50 @@ int dpl_str_to_shm(str src, str *dest, i
|
||||
|
||||
|
||||
/* Compile pcre pattern
|
||||
- * if mtype==0 - return pointer to shm copy of result
|
||||
- * if mtype==1 - return pcre pointer that has to be pcre_free() */
|
||||
-pcre *reg_ex_comp(const char *pattern, int *cap_cnt, int mtype)
|
||||
-{
|
||||
- pcre *re, *result;
|
||||
- const char *error;
|
||||
- int rc, err_offset;
|
||||
- size_t size;
|
||||
+ * if mtype==0 - return pointer using shm
|
||||
+ * if mtype==1 - return pcre2_code pointer that has to be pcre2_code_free() */
|
||||
+pcre2_code *reg_ex_comp(const char *pattern, int *cap_cnt, int mtype)
|
||||
+{
|
||||
+ pcre2_code *re;
|
||||
+ int pcre_error_num = 0;
|
||||
+ char pcre_error[128];
|
||||
+ size_t pcre_erroffset;
|
||||
+ int rc;
|
||||
|
||||
- re = pcre_compile(pattern, 0, &error, &err_offset, NULL);
|
||||
+ re = pcre2_compile((PCRE2_SPTR)pattern, PCRE2_ZERO_TERMINATED, 0,
|
||||
+ &pcre_error_num, &pcre_erroffset, mtype == 0 ? dpl_ctx : NULL);
|
||||
if(re == NULL) {
|
||||
- LM_ERR("PCRE compilation of '%s' failed at offset %d: %s\n", pattern,
|
||||
- err_offset, error);
|
||||
- return (pcre *)0;
|
||||
- }
|
||||
- rc = pcre_fullinfo(re, NULL, PCRE_INFO_SIZE, &size);
|
||||
- if(rc != 0) {
|
||||
- pcre_free(re);
|
||||
- LM_ERR("pcre_fullinfo on compiled pattern '%s' yielded error: %d\n",
|
||||
- pattern, rc);
|
||||
- return (pcre *)0;
|
||||
+ switch(pcre2_get_error_message(
|
||||
+ pcre_error_num, (PCRE2_UCHAR *)pcre_error, 128)) {
|
||||
+ case PCRE2_ERROR_NOMEMORY:
|
||||
+ snprintf(pcre_error, 128,
|
||||
+ "unknown error[%d]: pcre2 error buffer too small",
|
||||
+ pcre_error_num);
|
||||
+ break;
|
||||
+ case PCRE2_ERROR_BADDATA:
|
||||
+ snprintf(pcre_error, 128, "unknown pcre2 error[%d]",
|
||||
+ pcre_error_num);
|
||||
+ break;
|
||||
+ }
|
||||
+ LM_ERR("PCRE compilation of '%s' failed at offset %zu: %s\n", pattern,
|
||||
+ pcre_erroffset, pcre_error);
|
||||
+ return NULL;
|
||||
}
|
||||
- rc = pcre_fullinfo(re, NULL, PCRE_INFO_CAPTURECOUNT, cap_cnt);
|
||||
+ rc = pcre2_pattern_info(re, PCRE2_INFO_CAPTURECOUNT, cap_cnt);
|
||||
if(rc != 0) {
|
||||
- pcre_free(re);
|
||||
+ pcre2_code_free(re);
|
||||
LM_ERR("pcre_fullinfo on compiled pattern '%s' yielded error: %d\n",
|
||||
pattern, rc);
|
||||
- return (pcre *)0;
|
||||
- }
|
||||
- if(mtype == 0) {
|
||||
- result = (pcre *)shm_malloc(size);
|
||||
- if(result == NULL) {
|
||||
- pcre_free(re);
|
||||
- LM_ERR("not enough shared memory for compiled PCRE pattern\n");
|
||||
- return (pcre *)0;
|
||||
- }
|
||||
- memcpy(result, re, size);
|
||||
- pcre_free(re);
|
||||
- return result;
|
||||
- } else {
|
||||
- return re;
|
||||
+ return NULL;
|
||||
}
|
||||
+ return re;
|
||||
}
|
||||
|
||||
|
||||
/*compile the expressions, and if ok, build the rule */
|
||||
dpl_node_t *build_rule(db_val_t *values)
|
||||
{
|
||||
- pcre *match_comp, *subst_comp;
|
||||
+ pcre2_code *match_comp, *subst_comp;
|
||||
struct subst_expr *repl_comp;
|
||||
dpl_node_t *new_rule;
|
||||
str match_exp, subst_exp, repl_exp, attrs;
|
||||
@@ -544,9 +567,9 @@ dpl_node_t *build_rule(db_val_t *values)
|
||||
|
||||
err:
|
||||
if(match_comp)
|
||||
- shm_free(match_comp);
|
||||
+ pcre2_code_free(match_comp);
|
||||
if(subst_comp)
|
||||
- shm_free(subst_comp);
|
||||
+ pcre2_code_free(subst_comp);
|
||||
if(repl_comp)
|
||||
repl_expr_free(repl_comp);
|
||||
if(new_rule)
|
||||
@@ -692,10 +715,10 @@ void destroy_rule(dpl_node_t *rule)
|
||||
LM_DBG("destroying rule with priority %i\n", rule->pr);
|
||||
|
||||
if(rule->match_comp)
|
||||
- shm_free(rule->match_comp);
|
||||
+ pcre2_code_free(rule->match_comp);
|
||||
|
||||
if(rule->subst_comp)
|
||||
- shm_free(rule->subst_comp);
|
||||
+ pcre2_code_free(rule->subst_comp);
|
||||
|
||||
/*destroy repl_exp*/
|
||||
if(rule->repl_comp)
|
||||
--- a/src/modules/dialplan/dp_repl.c
|
||||
+++ b/src/modules/dialplan/dp_repl.c
|
||||
@@ -15,8 +15,8 @@
|
||||
* 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
|
||||
+ * 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
|
||||
*
|
||||
*/
|
||||
@@ -38,7 +38,7 @@
|
||||
|
||||
typedef struct dpl_dyn_pcre
|
||||
{
|
||||
- pcre *re;
|
||||
+ pcre2_code *re;
|
||||
int cnt;
|
||||
str expr;
|
||||
|
||||
@@ -186,9 +186,10 @@ int dpl_detect_avp_indx(const pv_elem_p
|
||||
return 0;
|
||||
}
|
||||
|
||||
-pcre *dpl_dyn_pcre_comp(sip_msg_t *msg, str *expr, str *vexpr, int *cap_cnt)
|
||||
+pcre2_code *dpl_dyn_pcre_comp(
|
||||
+ sip_msg_t *msg, str *expr, str *vexpr, int *cap_cnt)
|
||||
{
|
||||
- pcre *re = NULL;
|
||||
+ pcre2_code *re = NULL;
|
||||
int ccnt = 0;
|
||||
|
||||
if(expr == NULL || expr->s == NULL || expr->len <= 0 || vexpr == NULL
|
||||
@@ -225,7 +226,7 @@ dpl_dyn_pcre_p dpl_dynamic_pcre_list(sip
|
||||
dpl_dyn_pcre_p rt = NULL;
|
||||
struct str_list *l = NULL;
|
||||
struct str_list *t = NULL;
|
||||
- pcre *re = NULL;
|
||||
+ pcre2_code *re = NULL;
|
||||
int cnt = 0;
|
||||
str vexpr = STR_NULL;
|
||||
|
||||
@@ -294,7 +295,7 @@ error:
|
||||
while(re_list) {
|
||||
rt = re_list->next;
|
||||
if(re_list->re)
|
||||
- pcre_free(re_list->re);
|
||||
+ pcre2_code_free(re_list->re);
|
||||
pkg_free(re_list);
|
||||
re_list = rt;
|
||||
}
|
||||
@@ -400,15 +401,16 @@ error:
|
||||
#define MAX_PHONE_NB_DIGITS 127
|
||||
static char dp_output_buf[MAX_PHONE_NB_DIGITS + 1];
|
||||
int rule_translate(sip_msg_t *msg, str *instr, dpl_node_t *rule,
|
||||
- pcre *subst_comp, str *result)
|
||||
+ pcre2_code *subst_comp, str *result)
|
||||
{
|
||||
int repl_nb, offset, match_nb, rc, cap_cnt;
|
||||
struct replace_with token;
|
||||
struct subst_expr *repl_comp;
|
||||
+ pcre2_match_data *pcre_md = NULL;
|
||||
str match;
|
||||
pv_value_t sv;
|
||||
str *uri;
|
||||
- int ovector[3 * (MAX_REPLACE_WITH + 1)];
|
||||
+ PCRE2_SIZE *ovector = NULL;
|
||||
char *p;
|
||||
int size;
|
||||
|
||||
@@ -424,7 +426,7 @@ int rule_translate(sip_msg_t *msg, str *
|
||||
|
||||
if(subst_comp) {
|
||||
/*just in case something went wrong at load time*/
|
||||
- rc = pcre_fullinfo(subst_comp, NULL, PCRE_INFO_CAPTURECOUNT, &cap_cnt);
|
||||
+ rc = pcre2_pattern_info(subst_comp, PCRE2_INFO_CAPTURECOUNT, &cap_cnt);
|
||||
if(rc != 0) {
|
||||
LM_ERR("pcre_fullinfo on compiled pattern yielded error: %d\n", rc);
|
||||
return -1;
|
||||
@@ -441,15 +443,19 @@ int rule_translate(sip_msg_t *msg, str *
|
||||
}
|
||||
|
||||
/*search for the pattern from the compiled subst_exp*/
|
||||
- if(pcre_exec(subst_comp, NULL, instr->s, instr->len, 0, 0, ovector,
|
||||
- 3 * (MAX_REPLACE_WITH + 1))
|
||||
+ pcre_md = pcre2_match_data_create_from_pattern(subst_comp, NULL);
|
||||
+ if(pcre2_match(subst_comp, (PCRE2_SPTR)instr->s, (PCRE2_SIZE)instr->len,
|
||||
+ 0, 0, pcre_md, NULL)
|
||||
<= 0) {
|
||||
LM_DBG("the string %.*s matched "
|
||||
"the match_exp %.*s but not the subst_exp %.*s!\n",
|
||||
instr->len, instr->s, rule->match_exp.len,
|
||||
rule->match_exp.s, rule->subst_exp.len, rule->subst_exp.s);
|
||||
+ if(pcre_md)
|
||||
+ pcre2_match_data_free(pcre_md);
|
||||
return -1;
|
||||
}
|
||||
+ ovector = pcre2_get_ovector_pointer(pcre_md);
|
||||
}
|
||||
|
||||
/*simply copy from the replacing string*/
|
||||
@@ -463,6 +469,8 @@ int rule_translate(sip_msg_t *msg, str *
|
||||
memcpy(result->s, repl_comp->replacement.s, repl_comp->replacement.len);
|
||||
result->len = repl_comp->replacement.len;
|
||||
result->s[result->len] = '\0';
|
||||
+ if(pcre_md)
|
||||
+ pcre2_match_data_free(pcre_md);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -571,11 +579,15 @@ int rule_translate(sip_msg_t *msg, str *
|
||||
}
|
||||
|
||||
result->s[result->len] = '\0';
|
||||
+ if(pcre_md)
|
||||
+ pcre2_match_data_free(pcre_md);
|
||||
return 0;
|
||||
|
||||
error:
|
||||
result->s = 0;
|
||||
result->len = 0;
|
||||
+ if(pcre_md)
|
||||
+ pcre2_match_data_free(pcre_md);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -584,6 +596,7 @@ static char dp_attrs_buf[DP_MAX_ATTRS_LE
|
||||
int dp_translate_helper(
|
||||
sip_msg_t *msg, str *input, str *output, dpl_id_p idp, str *attrs)
|
||||
{
|
||||
+ pcre2_match_data *pcre_md = NULL;
|
||||
dpl_node_p rulep;
|
||||
dpl_index_p indexp;
|
||||
int user_len, rez;
|
||||
@@ -624,21 +637,28 @@ search_rule:
|
||||
rez = -1;
|
||||
do {
|
||||
if(rez < 0) {
|
||||
- rez = pcre_exec(re_list->re, NULL, input->s,
|
||||
- input->len, 0, 0, NULL, 0);
|
||||
+ pcre_md = pcre2_match_data_create_from_pattern(
|
||||
+ re_list->re, NULL);
|
||||
+ rez = pcre2_match(re_list->re, (PCRE2_SPTR)input->s,
|
||||
+ (PCRE2_SIZE)input->len, 0, 0, pcre_md,
|
||||
+ NULL);
|
||||
LM_DBG("match check: [%.*s] %d\n",
|
||||
re_list->expr.len, re_list->expr.s, rez);
|
||||
} else
|
||||
LM_DBG("match check skipped: [%.*s] %d\n",
|
||||
re_list->expr.len, re_list->expr.s, rez);
|
||||
rt = re_list->next;
|
||||
- pcre_free(re_list->re);
|
||||
+ pcre2_match_data_free(pcre_md);
|
||||
+ pcre2_code_free(re_list->re);
|
||||
pkg_free(re_list);
|
||||
re_list = rt;
|
||||
} while(re_list);
|
||||
} else {
|
||||
- rez = pcre_exec(rulep->match_comp, NULL, input->s,
|
||||
- input->len, 0, 0, NULL, 0);
|
||||
+ pcre_md = pcre2_match_data_create_from_pattern(
|
||||
+ rulep->match_comp, NULL);
|
||||
+ rez = pcre2_match(rulep->match_comp, (PCRE2_SPTR)input->s,
|
||||
+ (PCRE2_SIZE)input->len, 0, 0, pcre_md, 0);
|
||||
+ pcre2_match_data_free(pcre_md);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -728,7 +748,7 @@ repl:
|
||||
LM_DBG("subst check skipped: [%.*s] %d\n", re_list->expr.len,
|
||||
re_list->expr.s, rez);
|
||||
rt = re_list->next;
|
||||
- pcre_free(re_list->re);
|
||||
+ pcre2_code_free(re_list->re);
|
||||
pkg_free(re_list);
|
||||
re_list = rt;
|
||||
} while(re_list);
|
@ -0,0 +1,510 @@
|
||||
From ecc2c9e54fa8f24c1e96860c1f59b43f2e1e8b7a Mon Sep 17 00:00:00 2001
|
||||
From: Victor Seva <linuxmaniac@torreviejawireless.org>
|
||||
Date: Wed, 17 May 2023 16:36:55 +0200
|
||||
Subject: [PATCH] lcr: clang-format for coherent indentation and coding style
|
||||
|
||||
---
|
||||
src/modules/lcr/lcr_mod.c | 125 +++++++++++++++++++++-----------------
|
||||
src/modules/lcr/lcr_rpc.c | 65 ++++++++++----------
|
||||
2 files changed, 102 insertions(+), 88 deletions(-)
|
||||
|
||||
--- a/src/modules/lcr/lcr_mod.c
|
||||
+++ b/src/modules/lcr/lcr_mod.c
|
||||
@@ -259,7 +259,8 @@ static int inactivate_gw(struct sip_msg
|
||||
static int defunct_gw(struct sip_msg *_m, char *_s1, char *_s2);
|
||||
static int from_gw_1(struct sip_msg *_m, char *_s1, char *_s2);
|
||||
static int from_gw_3(struct sip_msg *_m, char *_s1, char *_s2, char *_s3);
|
||||
-static int from_gw_4(struct sip_msg *_m, char *_s1, char *_s2, char *_s3, char *_s4);
|
||||
+static int from_gw_4(
|
||||
+ struct sip_msg *_m, char *_s1, char *_s2, char *_s3, char *_s4);
|
||||
static int from_any_gw_0(struct sip_msg *_m, char *_s1, char *_s2);
|
||||
static int from_any_gw_2(struct sip_msg *_m, char *_s1, char *_s2);
|
||||
static int from_any_gw_3(struct sip_msg *_m, char *_s1, char *_s2, char *_s3);
|
||||
@@ -554,7 +555,8 @@ static int mod_init(void)
|
||||
LM_ERR("malformed or non AVP definition <%s>\n", rule_id_avp_param);
|
||||
return -1;
|
||||
}
|
||||
- if(pv_get_avp_name(0, &(avp_spec->pvp), &rule_id_avp, &avp_flags) != 0) {
|
||||
+ if(pv_get_avp_name(0, &(avp_spec->pvp), &rule_id_avp, &avp_flags)
|
||||
+ != 0) {
|
||||
LM_ERR("invalid AVP definition <%s>\n", rule_id_avp_param);
|
||||
return -1;
|
||||
}
|
||||
@@ -680,18 +682,21 @@ static int mod_init(void)
|
||||
LM_ERR("unable to open database connection\n");
|
||||
return -1;
|
||||
}
|
||||
- if(db_check_table_version(&lcr_dbf, dbh, &lcr_rule_table,
|
||||
- LCR_RULE_TABLE_VERSION) < 0) {
|
||||
+ if(db_check_table_version(
|
||||
+ &lcr_dbf, dbh, &lcr_rule_table, LCR_RULE_TABLE_VERSION)
|
||||
+ < 0) {
|
||||
DB_TABLE_VERSION_ERROR(lcr_rule_table);
|
||||
goto dberror;
|
||||
}
|
||||
if(db_check_table_version(&lcr_dbf, dbh, &lcr_rule_target_table,
|
||||
- LCR_RULE_TARGET_TABLE_VERSION) < 0) {
|
||||
+ LCR_RULE_TARGET_TABLE_VERSION)
|
||||
+ < 0) {
|
||||
DB_TABLE_VERSION_ERROR(lcr_rule_target_table);
|
||||
goto dberror;
|
||||
}
|
||||
- if (db_check_table_version(&lcr_dbf, dbh, &lcr_gw_table,
|
||||
- LCR_GW_TABLE_VERSION) < 0) {
|
||||
+ if(db_check_table_version(
|
||||
+ &lcr_dbf, dbh, &lcr_gw_table, LCR_GW_TABLE_VERSION)
|
||||
+ < 0) {
|
||||
DB_TABLE_VERSION_ERROR(lcr_gw_table);
|
||||
goto dberror;
|
||||
}
|
||||
@@ -923,20 +928,24 @@ static int comp_gws(const void *_g1, con
|
||||
/*
|
||||
* Compare a gateway using IP address and the src port
|
||||
*/
|
||||
-static struct gw_info * find_gateway_by_ip_and_port(struct gw_info * gw, struct gw_info * gws) {
|
||||
+static struct gw_info *find_gateway_by_ip_and_port(
|
||||
+ struct gw_info *gw, struct gw_info *gws)
|
||||
+{
|
||||
int tmp = 0, gw_index = 0, i;
|
||||
|
||||
- for (i = 1; i <= gws[0].ip_addr.u.addr32[0]; i++) {
|
||||
- tmp = memcmp(gws[i].ip_addr.u.addr, gw->ip_addr.u.addr, gws[i].ip_addr.len);
|
||||
- if (gws[i].ip_addr.af == gw->ip_addr.af &&
|
||||
- gws[i].ip_addr.len == gw->ip_addr.len &&
|
||||
- tmp == 0 && /* a comparison of the IP address value */
|
||||
- gws[i].port == gw->port) {
|
||||
- gw_index = i;
|
||||
- break;
|
||||
+ for(i = 1; i <= gws[0].ip_addr.u.addr32[0]; i++) {
|
||||
+ tmp = memcmp(
|
||||
+ gws[i].ip_addr.u.addr, gw->ip_addr.u.addr, gws[i].ip_addr.len);
|
||||
+ if(gws[i].ip_addr.af == gw->ip_addr.af
|
||||
+ && gws[i].ip_addr.len == gw->ip_addr.len && tmp == 0
|
||||
+ && /* a comparison of the IP address value */
|
||||
+ gws[i].port == gw->port) {
|
||||
+ gw_index = i;
|
||||
+ break;
|
||||
}
|
||||
}
|
||||
- if (gw_index != 0) return &(gws[gw_index]);
|
||||
+ if(gw_index != 0)
|
||||
+ return &(gws[gw_index]);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@@ -1074,7 +1083,7 @@ static int insert_gws(db1_res_t *res, st
|
||||
row = RES_ROWS(res) + i;
|
||||
if((VAL_NULL(ROW_VALUES(row) + 12) == 1)
|
||||
|| ((VAL_TYPE(ROW_VALUES(row) + 12) != DB1_INT)
|
||||
- && (VAL_TYPE(ROW_VALUES(row) + 12) != DB1_UINT))) {
|
||||
+ && (VAL_TYPE(ROW_VALUES(row) + 12) != DB1_UINT))) {
|
||||
LM_ERR("lcr_gw id at row <%u> is null or not int\n", i);
|
||||
return 0;
|
||||
}
|
||||
@@ -1501,8 +1510,7 @@ int reload_tables()
|
||||
|
||||
if((VAL_NULL(ROW_VALUES(row)) == 1)
|
||||
|| ((VAL_TYPE(ROW_VALUES(row)) != DB1_INT)
|
||||
- && (VAL_TYPE(ROW_VALUES(row))
|
||||
- != DB1_UINT))) {
|
||||
+ && (VAL_TYPE(ROW_VALUES(row)) != DB1_UINT))) {
|
||||
LM_ERR("lcr rule id at row <%u> is null or not int\n", i);
|
||||
goto err;
|
||||
}
|
||||
@@ -1544,8 +1552,8 @@ int reload_tables()
|
||||
|
||||
if((VAL_NULL(ROW_VALUES(row) + 3) == 1)
|
||||
|| ((VAL_TYPE(ROW_VALUES(row) + 3) != DB1_INT)
|
||||
- && (VAL_TYPE(ROW_VALUES(row) + 3)
|
||||
- != DB1_UINT))) {
|
||||
+ && (VAL_TYPE(ROW_VALUES(row) + 3)
|
||||
+ != DB1_UINT))) {
|
||||
LM_ERR("lcr rule <%u> stopper is NULL or not int\n",
|
||||
rule_id);
|
||||
goto err;
|
||||
@@ -1558,8 +1566,8 @@ int reload_tables()
|
||||
|
||||
if((VAL_NULL(ROW_VALUES(row) + 4) == 1)
|
||||
|| ((VAL_TYPE(ROW_VALUES(row) + 4) != DB1_INT)
|
||||
- && (VAL_TYPE(ROW_VALUES(row) + 4)
|
||||
- != DB1_UINT))) {
|
||||
+ && (VAL_TYPE(ROW_VALUES(row) + 4)
|
||||
+ != DB1_UINT))) {
|
||||
LM_ERR("lcr rule <%u> enabled is NULL or not int\n",
|
||||
rule_id);
|
||||
goto err;
|
||||
@@ -1769,8 +1777,7 @@ int reload_tables()
|
||||
row = RES_ROWS(res) + i;
|
||||
if((VAL_NULL(ROW_VALUES(row)) == 1)
|
||||
|| ((VAL_TYPE(ROW_VALUES(row)) != DB1_INT)
|
||||
- && (VAL_TYPE(ROW_VALUES(row))
|
||||
- != DB1_UINT))) {
|
||||
+ && (VAL_TYPE(ROW_VALUES(row)) != DB1_UINT))) {
|
||||
LM_ERR("lcr_rule_target rule_id at row <%u> is null "
|
||||
"or not int\n",
|
||||
i);
|
||||
@@ -1779,8 +1786,8 @@ int reload_tables()
|
||||
rule_id = (unsigned int)VAL_INT(ROW_VALUES(row));
|
||||
if((VAL_NULL(ROW_VALUES(row) + 1) == 1)
|
||||
|| ((VAL_TYPE(ROW_VALUES(row) + 1) != DB1_INT)
|
||||
- && (VAL_TYPE(ROW_VALUES(row) + 1)
|
||||
- != DB1_UINT))) {
|
||||
+ && (VAL_TYPE(ROW_VALUES(row) + 1)
|
||||
+ != DB1_UINT))) {
|
||||
LM_ERR("lcr_rule_target gw_id at row <%u> is null "
|
||||
"or not int\n",
|
||||
i);
|
||||
@@ -1789,8 +1796,8 @@ int reload_tables()
|
||||
gw_id = (unsigned int)VAL_INT(ROW_VALUES(row) + 1);
|
||||
if((VAL_NULL(ROW_VALUES(row) + 2) == 1)
|
||||
|| ((VAL_TYPE(ROW_VALUES(row) + 2) != DB1_INT)
|
||||
- && (VAL_TYPE(ROW_VALUES(row) + 2)
|
||||
- != DB1_UINT))) {
|
||||
+ && (VAL_TYPE(ROW_VALUES(row) + 2)
|
||||
+ != DB1_UINT))) {
|
||||
LM_ERR("lcr_rule_target priority at row <%u> is null "
|
||||
"or not int\n",
|
||||
i);
|
||||
@@ -1805,8 +1812,8 @@ int reload_tables()
|
||||
}
|
||||
if((VAL_NULL(ROW_VALUES(row) + 3) == 1)
|
||||
|| ((VAL_TYPE(ROW_VALUES(row) + 3) != DB1_INT)
|
||||
- && (VAL_TYPE(ROW_VALUES(row) + 3)
|
||||
- != DB1_UINT))) {
|
||||
+ && (VAL_TYPE(ROW_VALUES(row) + 3)
|
||||
+ != DB1_UINT))) {
|
||||
LM_ERR("lcr_rule_target weight at row <%u> is null "
|
||||
"or not int\n",
|
||||
i);
|
||||
@@ -2087,10 +2094,10 @@ void add_gws_into_avps(struct gw_info *g
|
||||
if(5 /* gw_index */ + 5 /* scheme */ + 4 /* strip */ + prefix_len
|
||||
+ tag_len + 1 /* @ */
|
||||
+ ((hostname_len > IP6_MAX_STR_SIZE + 2)
|
||||
- ? hostname_len
|
||||
- : IP6_MAX_STR_SIZE + 2)
|
||||
+ ? hostname_len
|
||||
+ : IP6_MAX_STR_SIZE + 2)
|
||||
+ 6 /* port */ + params_len /* params */
|
||||
- + 15 /* transport */ + 10 /* flags */
|
||||
+ + 15 /* transport */ + 10 /* flags */
|
||||
+ 7 /* separators */
|
||||
+ 10 /* rule_id */
|
||||
> MAX_URI_LEN) {
|
||||
@@ -2174,7 +2181,7 @@ int load_gws_dummy(int lcr_id, str *ruri
|
||||
if((rule->from_uri_len != 0)
|
||||
&& (pcre_exec(rule->from_uri_re, NULL, from_uri->s,
|
||||
from_uri->len, 0, 0, NULL, 0)
|
||||
- < 0))
|
||||
+ < 0))
|
||||
goto next;
|
||||
|
||||
if((from_uri->len > 0) && (rule->mt_tvalue_len > 0)) {
|
||||
@@ -2339,7 +2346,7 @@ static int ki_load_gws_furi(
|
||||
if((rule->from_uri_len != 0)
|
||||
&& (pcre_exec(rule->from_uri_re, NULL, from_uri->s,
|
||||
from_uri->len, 0, 0, NULL, 0)
|
||||
- < 0)) {
|
||||
+ < 0)) {
|
||||
LM_DBG("from uri <%.*s> did not match to from regex <%.*s>\n",
|
||||
from_uri->len, from_uri->s, rule->from_uri_len,
|
||||
rule->from_uri);
|
||||
@@ -2375,7 +2382,7 @@ static int ki_load_gws_furi(
|
||||
if((rule->request_uri_len != 0)
|
||||
&& (pcre_exec(rule->request_uri_re, NULL, request_uri->s,
|
||||
request_uri->len, 0, 0, NULL, 0)
|
||||
- < 0)) {
|
||||
+ < 0)) {
|
||||
LM_DBG("request uri <%.*s> did not match to request regex "
|
||||
"<%.*s>\n",
|
||||
request_uri->len, request_uri->s, rule->request_uri_len,
|
||||
@@ -2549,7 +2556,8 @@ static int generate_uris(struct sip_msg
|
||||
return 0; /* No more gateways left */
|
||||
|
||||
decode_avp_value(gw_uri_val.s.s, gw_index, &scheme, &strip, &prefix,
|
||||
- &tmp_tag, addr, &hostname, &port, ¶ms, &transport, flags, rule_id);
|
||||
+ &tmp_tag, addr, &hostname, &port, ¶ms, &transport, flags,
|
||||
+ rule_id);
|
||||
|
||||
if(addr->af != 0) {
|
||||
addr_str.s = ip_addr2a(addr);
|
||||
@@ -2560,8 +2568,8 @@ static int generate_uris(struct sip_msg
|
||||
|
||||
if(scheme.len + r_uri_user->len - strip + prefix.len + 1 /* @ */
|
||||
+ ((hostname.len > IP6_MAX_STR_SIZE + 2)
|
||||
- ? hostname.len
|
||||
- : IP6_MAX_STR_SIZE + 2)
|
||||
+ ? hostname.len
|
||||
+ : IP6_MAX_STR_SIZE + 2)
|
||||
+ 1 /* : */ + port.len + params.len + transport.len
|
||||
+ 1 /* null */
|
||||
> MAX_URI_LEN) {
|
||||
@@ -2992,7 +3000,7 @@ static int ki_next_gw(sip_msg_t *_m)
|
||||
if(rule_id_avp_param) {
|
||||
val.n = rule_id;
|
||||
add_avp(rule_id_avp_type, rule_id_avp, val);
|
||||
- LM_DBG("added rule_id_avp <%u>\n", (unsigned int)val.n);
|
||||
+ LM_DBG("added rule_id_avp <%u>\n", (unsigned int)val.n);
|
||||
}
|
||||
|
||||
/* Add index of selected gw to defunct gw AVP */
|
||||
@@ -3018,7 +3026,8 @@ static int next_gw(struct sip_msg *_m, c
|
||||
* Checks if request comes from ip address of a gateway
|
||||
*/
|
||||
static int do_from_gw(struct sip_msg *_m, unsigned int lcr_id,
|
||||
- struct ip_addr *src_addr, uri_transport transport, unsigned int src_port)
|
||||
+ struct ip_addr *src_addr, uri_transport transport,
|
||||
+ unsigned int src_port)
|
||||
{
|
||||
struct gw_info *res, gw, *gws;
|
||||
int_str val;
|
||||
@@ -3032,18 +3041,20 @@ static int do_from_gw(struct sip_msg *_m
|
||||
}
|
||||
|
||||
gw.ip_addr = *src_addr;
|
||||
- if (src_port != 0) {
|
||||
+ if(src_port != 0) {
|
||||
/* Search for gw based on its ip address and port */
|
||||
gw.port = src_port;
|
||||
res = find_gateway_by_ip_and_port(&gw, gws);
|
||||
} else {
|
||||
/* Search for gw based on its ip address */
|
||||
- res = (struct gw_info *)bsearch(&gw, &(gws[1]), gws[0].ip_addr.u.addr32[0],
|
||||
- sizeof(struct gw_info), comp_gws);
|
||||
+ res = (struct gw_info *)bsearch(&gw, &(gws[1]),
|
||||
+ gws[0].ip_addr.u.addr32[0], sizeof(struct gw_info), comp_gws);
|
||||
}
|
||||
|
||||
/* Store tag and flags and return result */
|
||||
- if((res != NULL) && ((transport == PROTO_NONE) || (res->transport_code == transport))) {
|
||||
+ if((res != NULL)
|
||||
+ && ((transport == PROTO_NONE)
|
||||
+ || (res->transport_code == transport))) {
|
||||
LM_DBG("request came from gw\n");
|
||||
if(tag_avp_param) {
|
||||
val.s.s = res->tag;
|
||||
@@ -3178,8 +3189,8 @@ static int from_gw_3(
|
||||
return ki_from_gw_addr_port(_m, lcr_id, &addr_str, transport, 0);
|
||||
}
|
||||
|
||||
-static int from_gw_4(
|
||||
- struct sip_msg *_m, char *_lcr_id, char *_addr, char *_transport, char *_src_port)
|
||||
+static int from_gw_4(struct sip_msg *_m, char *_lcr_id, char *_addr,
|
||||
+ char *_transport, char *_src_port)
|
||||
{
|
||||
int lcr_id;
|
||||
str addr_str;
|
||||
@@ -3202,7 +3213,7 @@ static int from_gw_4(
|
||||
LM_ERR("invalid transport parameter %s\n", _lcr_id);
|
||||
return -1;
|
||||
}
|
||||
- tmp=0;
|
||||
+ tmp = 0;
|
||||
src_port = strtol(_src_port, &tmp, 10);
|
||||
if((tmp == 0) || (*tmp) || (tmp == _src_port)) {
|
||||
LM_ERR("invalid port parameter %s\n", _src_port);
|
||||
@@ -3243,8 +3254,8 @@ static int from_any_gw_0(struct sip_msg
|
||||
* Checks if request comes from ip address of a gateway taking source
|
||||
* IP address, transport protocol and source port from parameters.
|
||||
*/
|
||||
-static int ki_from_any_gw_addr_port(sip_msg_t *_m, str *addr_str, int transport,
|
||||
- int src_port)
|
||||
+static int ki_from_any_gw_addr_port(
|
||||
+ sip_msg_t *_m, str *addr_str, int transport, int src_port)
|
||||
{
|
||||
unsigned int i;
|
||||
struct ip_addr *ip, src_addr;
|
||||
@@ -3307,7 +3318,8 @@ static int from_any_gw_2(struct sip_msg
|
||||
return ki_from_any_gw_addr_port(_m, &addr_str, transport, 0);
|
||||
}
|
||||
|
||||
-static int from_any_gw_3(struct sip_msg *_m, char *_addr, char *_transport, char *_src_port)
|
||||
+static int from_any_gw_3(
|
||||
+ struct sip_msg *_m, char *_addr, char *_transport, char *_src_port)
|
||||
{
|
||||
str addr_str;
|
||||
uri_transport transport;
|
||||
@@ -3323,7 +3335,7 @@ static int from_any_gw_3(struct sip_msg
|
||||
LM_ERR("invalid transport parameter %s\n", _transport);
|
||||
return -1;
|
||||
}
|
||||
- tmp=0;
|
||||
+ tmp = 0;
|
||||
src_port = strtol(_src_port, &tmp, 10);
|
||||
if((tmp == 0) || (*tmp) || (tmp == _src_port)) {
|
||||
LM_ERR("invalid port parameter %s\n", _src_port);
|
||||
@@ -3355,8 +3367,9 @@ static int do_to_gw(struct sip_msg *_m,
|
||||
sizeof(struct gw_info), comp_gws);
|
||||
|
||||
/* Return result */
|
||||
- if((res != NULL) && ((transport == PROTO_NONE)
|
||||
- || (res->transport_code == transport))) {
|
||||
+ if((res != NULL)
|
||||
+ && ((transport == PROTO_NONE)
|
||||
+ || (res->transport_code == transport))) {
|
||||
LM_DBG("request goes to gw\n");
|
||||
return 1;
|
||||
} else {
|
||||
--- a/src/modules/lcr/lcr_rpc.c
|
||||
+++ b/src/modules/lcr/lcr_rpc.c
|
||||
@@ -48,7 +48,8 @@ static void reload(rpc_t *rpc, void *c)
|
||||
static const char *dump_gws_doc[2] = {"Dump the contents of lcr_gws table.", 0};
|
||||
|
||||
|
||||
-static void dump_gw(rpc_t *rpc, void *st, struct gw_info *gw, unsigned int gw_index, unsigned int lcr_id)
|
||||
+static void dump_gw(rpc_t *rpc, void *st, struct gw_info *gw,
|
||||
+ unsigned int gw_index, unsigned int lcr_id)
|
||||
{
|
||||
str scheme, gw_name, hostname, params, transport;
|
||||
str prefix, tag;
|
||||
@@ -72,14 +73,10 @@ static void dump_gw(rpc_t *rpc, void *st
|
||||
break;
|
||||
case AF_INET6:
|
||||
rpc->struct_printf(st, "ip_addr", "%x:%x:%x:%x:%x:%x:%x:%x",
|
||||
- gw->ip_addr.u.addr16[0],
|
||||
- gw->ip_addr.u.addr16[1],
|
||||
- gw->ip_addr.u.addr16[2],
|
||||
- gw->ip_addr.u.addr16[3],
|
||||
- gw->ip_addr.u.addr16[4],
|
||||
- gw->ip_addr.u.addr16[5],
|
||||
- gw->ip_addr.u.addr16[6],
|
||||
- gw->ip_addr.u.addr16[7]);
|
||||
+ gw->ip_addr.u.addr16[0], gw->ip_addr.u.addr16[1],
|
||||
+ gw->ip_addr.u.addr16[2], gw->ip_addr.u.addr16[3],
|
||||
+ gw->ip_addr.u.addr16[4], gw->ip_addr.u.addr16[5],
|
||||
+ gw->ip_addr.u.addr16[6], gw->ip_addr.u.addr16[7]);
|
||||
break;
|
||||
case 0:
|
||||
rpc->struct_add(st, "s", "ip_addr", "0.0.0.0");
|
||||
@@ -99,11 +96,10 @@ static void dump_gw(rpc_t *rpc, void *st
|
||||
prefix.len = gw->prefix_len;
|
||||
tag.s = gw->tag;
|
||||
tag.len = gw->tag_len;
|
||||
- start = int2strbuf(
|
||||
- gw->defunct_until, &(buf[0]), INT2STR_MAX_LEN, &len);
|
||||
- rpc->struct_add(st, "dSSdds", "strip", gw->strip, "prefix",
|
||||
- &prefix, "tag", &tag, "flags", gw->flags, "state",
|
||||
- gw->state, "defunct_until", start);
|
||||
+ start = int2strbuf(gw->defunct_until, &(buf[0]), INT2STR_MAX_LEN, &len);
|
||||
+ rpc->struct_add(st, "dSSdds", "strip", gw->strip, "prefix", &prefix, "tag",
|
||||
+ &tag, "flags", gw->flags, "state", gw->state, "defunct_until",
|
||||
+ start);
|
||||
}
|
||||
|
||||
static void dump_gws(rpc_t *rpc, void *c)
|
||||
@@ -119,7 +115,7 @@ static void dump_gws(rpc_t *rpc, void *c
|
||||
gws = gw_pt[j];
|
||||
|
||||
for(i = 1; i <= gws[0].ip_addr.u.addr32[0]; i++) {
|
||||
- if (srec==NULL) {
|
||||
+ if(srec == NULL) {
|
||||
/* We create one array per lcr_id */
|
||||
if(rpc->add(c, "{", &rec) < 0)
|
||||
return;
|
||||
@@ -143,7 +139,7 @@ static void dump_rules(rpc_t *rpc, void
|
||||
int i, j;
|
||||
int _filter_by_prefix = 0;
|
||||
int _lcr_id = 0;
|
||||
- str _prefix = {NULL,0};
|
||||
+ str _prefix = {NULL, 0};
|
||||
struct rule_info **rules, *rule;
|
||||
struct target *t;
|
||||
void *rec = NULL;
|
||||
@@ -151,29 +147,32 @@ static void dump_rules(rpc_t *rpc, void
|
||||
void *st, *sst, *ssst;
|
||||
str prefix, from_uri, request_uri;
|
||||
|
||||
- if (rpc->scan(c, "d", &_lcr_id)>0) {
|
||||
- if (rpc->scan(c, ".S", &_prefix)>0) {
|
||||
+ if(rpc->scan(c, "d", &_lcr_id) > 0) {
|
||||
+ if(rpc->scan(c, ".S", &_prefix) > 0) {
|
||||
_filter_by_prefix = 1;
|
||||
}
|
||||
}
|
||||
|
||||
for(j = 1; j <= lcr_count_param; j++) {
|
||||
|
||||
- if (_lcr_id && _lcr_id!=j) continue;
|
||||
+ if(_lcr_id && _lcr_id != j)
|
||||
+ continue;
|
||||
|
||||
rules = rule_pt[j];
|
||||
|
||||
for(i = 0; i < lcr_rule_hash_size_param; i++) {
|
||||
rule = rules[i];
|
||||
while(rule) {
|
||||
- if (_filter_by_prefix && _prefix.len && _prefix.s) {
|
||||
- if (_prefix.len < rule->prefix_len ||
|
||||
- strncmp(_prefix.s, rule->prefix, rule->prefix_len)!=0) {
|
||||
+ if(_filter_by_prefix && _prefix.len && _prefix.s) {
|
||||
+ if(_prefix.len < rule->prefix_len
|
||||
+ || strncmp(_prefix.s, rule->prefix,
|
||||
+ rule->prefix_len)
|
||||
+ != 0) {
|
||||
rule = rule->next;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
- if (srec==NULL) {
|
||||
+ if(srec == NULL) {
|
||||
/* We create one array per lcr_id */
|
||||
if(rpc->add(c, "{", &rec) < 0)
|
||||
return;
|
||||
@@ -192,11 +191,11 @@ static void dump_rules(rpc_t *rpc, void
|
||||
rule->rule_id, "prefix", &prefix, "from_uri", &from_uri,
|
||||
"request_uri", &request_uri, "stopper", rule->stopper);
|
||||
t = rule->targets;
|
||||
- if (t) {
|
||||
- if (rpc->struct_add(st, "[", "gw", &sst) < 0)
|
||||
+ if(t) {
|
||||
+ if(rpc->struct_add(st, "[", "gw", &sst) < 0)
|
||||
return;
|
||||
while(t) {
|
||||
- if (rpc->array_add(sst, "{", &ssst) < 0)
|
||||
+ if(rpc->array_add(sst, "{", &ssst) < 0)
|
||||
return;
|
||||
rpc->struct_add(ssst, "ddd", "gw_index", t->gw_index,
|
||||
"priority", t->priority, "weight", t->weight);
|
||||
@@ -210,10 +209,10 @@ static void dump_rules(rpc_t *rpc, void
|
||||
/* Mark the end of rule array */
|
||||
srec = NULL;
|
||||
|
||||
- if (_filter_by_prefix)
|
||||
+ if(_filter_by_prefix)
|
||||
continue;
|
||||
rule = rules[lcr_rule_hash_size_param];
|
||||
- if (rule) {
|
||||
+ if(rule) {
|
||||
if(rpc->struct_add(rec, "[", "prefix_len", &st) < 0)
|
||||
return;
|
||||
while(rule) {
|
||||
@@ -222,7 +221,8 @@ static void dump_rules(rpc_t *rpc, void
|
||||
}
|
||||
}
|
||||
}
|
||||
- if (rec==NULL) rpc->fault(c, 404, "Empty reply");
|
||||
+ if(rec == NULL)
|
||||
+ rpc->fault(c, 404, "Empty reply");
|
||||
}
|
||||
|
||||
|
||||
@@ -269,8 +269,9 @@ static void load_gws(rpc_t *rpc, void *c
|
||||
|
||||
ret = rpc->scan(c, "dS*SS", &lcr_id, &uri_user, &caller_uri, &request_uri);
|
||||
if(ret == -1) {
|
||||
- rpc->fault(c, 400, "parameter error; if using cli, remember to prefix "
|
||||
- "numeric uri_user param value with 's:'");
|
||||
+ rpc->fault(c, 400,
|
||||
+ "parameter error; if using cli, remember to prefix "
|
||||
+ "numeric uri_user param value with 's:'");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -289,7 +290,7 @@ static void load_gws(rpc_t *rpc, void *c
|
||||
|
||||
gws = gw_pt[lcr_id];
|
||||
for(j = 0; j < gw_count; j++) {
|
||||
- if (rec==NULL) {
|
||||
+ if(rec == NULL) {
|
||||
if(rpc->add(c, "[", &rec) < 0)
|
||||
return;
|
||||
}
|
51
net/kamailio/patches/021-lcr-typos.patch
Normal file
51
net/kamailio/patches/021-lcr-typos.patch
Normal file
@ -0,0 +1,51 @@
|
||||
From 70a9ea2b1e5cceeaf050356e7baf00127a58567d Mon Sep 17 00:00:00 2001
|
||||
From: =?UTF-8?q?=D0=94=D0=B8=D0=BB=D1=8F=D0=BD=20=D0=9F=D0=B0=D0=BB=D0=B0?=
|
||||
=?UTF-8?q?=D1=83=D0=B7=D0=BE=D0=B2?= <git-dpa@aegee.org>
|
||||
Date: Mon, 8 May 2023 13:13:49 +0200
|
||||
Subject: [PATCH] lcr: typos
|
||||
|
||||
---
|
||||
src/modules/lcr/doc/lcr_admin.xml | 2 +-
|
||||
src/modules/lcr/lcr_mod.c | 6 +++---
|
||||
2 files changed, 4 insertions(+), 4 deletions(-)
|
||||
|
||||
--- a/src/modules/lcr/doc/lcr_admin.xml
|
||||
+++ b/src/modules/lcr/doc/lcr_admin.xml
|
||||
@@ -1641,7 +1641,7 @@ if (to_any_gw("192.55.66.2", 1)) {
|
||||
<para>
|
||||
Causes lcr module to dump the contents of its
|
||||
in-memory lcr_rule and lcr_rule_target tables.
|
||||
- Rules can be filetered by lcr_id or lcr_id and prefix.
|
||||
+ Rules can be filtered by lcr_id or lcr_id and prefix.
|
||||
The filters are passed as optional parameters.
|
||||
</para>
|
||||
<para>Parameters:</para>
|
||||
--- a/src/modules/lcr/lcr_mod.c
|
||||
+++ b/src/modules/lcr/lcr_mod.c
|
||||
@@ -188,7 +188,7 @@ unsigned int lcr_gw_count_param = DEF_LC
|
||||
/* can gws be defuncted */
|
||||
static unsigned int defunct_capability_param = 0;
|
||||
|
||||
-/* dont strip or tag param */
|
||||
+/* don't strip or tag param */
|
||||
static int dont_strip_or_prefix_flag_param = -1;
|
||||
|
||||
/* ping related params */
|
||||
@@ -846,7 +846,7 @@ static int comp_matched(const void *m1,
|
||||
if(mi1->priority < mi2->priority)
|
||||
return 1;
|
||||
if(mi1->priority == mi2->priority) {
|
||||
- /* Sort by randomized weigth */
|
||||
+ /* Sort by randomized weight */
|
||||
if(mi1->weight > mi2->weight)
|
||||
return 1;
|
||||
if(mi1->weight == mi2->weight)
|
||||
@@ -863,7 +863,7 @@ static int comp_matched(const void *m1,
|
||||
if(mi1->priority < mi2->priority)
|
||||
return 1;
|
||||
if(mi1->priority == mi2->priority) {
|
||||
- /* Sort by randomized weigth */
|
||||
+ /* Sort by randomized weight */
|
||||
if(mi1->weight > mi2->weight)
|
||||
return 1;
|
||||
if(mi1->weight == mi2->weight)
|
508
net/kamailio/patches/022-lcr-pcre2-migration.patch
Normal file
508
net/kamailio/patches/022-lcr-pcre2-migration.patch
Normal file
@ -0,0 +1,508 @@
|
||||
From e3e2c41e8c46a13bad18dd40fd9e3540020dd5eb Mon Sep 17 00:00:00 2001
|
||||
From: Victor Seva <linuxmaniac@torreviejawireless.org>
|
||||
Date: Mon, 21 Aug 2023 13:30:36 +0200
|
||||
Subject: [PATCH] lcr: pcre2 migration
|
||||
|
||||
---
|
||||
src/modules/lcr/Makefile | 12 +--
|
||||
src/modules/lcr/hash.c | 24 ++---
|
||||
src/modules/lcr/hash.h | 10 +-
|
||||
src/modules/lcr/lcr_mod.c | 187 +++++++++++++++++++++++++-------------
|
||||
src/modules/lcr/lcr_mod.h | 8 +-
|
||||
5 files changed, 150 insertions(+), 91 deletions(-)
|
||||
|
||||
--- a/src/modules/lcr/Makefile
|
||||
+++ b/src/modules/lcr/Makefile
|
||||
@@ -9,20 +9,15 @@ auto_gen=
|
||||
NAME=lcr.so
|
||||
|
||||
ifeq ($(CROSS_COMPILE),)
|
||||
-PCRE_BUILDER = $(shell \
|
||||
- if pkg-config --exists libcre; then \
|
||||
- echo 'pkg-config libpcre'; \
|
||||
- else \
|
||||
- which pcre-config; \
|
||||
- fi)
|
||||
+PCRE_BUILDER = $(shell command -v pcre2-config)
|
||||
endif
|
||||
|
||||
ifeq ($(PCRE_BUILDER),)
|
||||
PCREDEFS=-I$(LOCALBASE)/include
|
||||
- PCRELIBS=-L$(LOCALBASE)/lib -lpcre
|
||||
+ PCRELIBS=-L$(LOCALBASE)/lib -lpcre2-8
|
||||
else
|
||||
PCREDEFS = $(shell $(PCRE_BUILDER) --cflags)
|
||||
- PCRELIBS = $(shell $(PCRE_BUILDER) --libs)
|
||||
+ PCRELIBS = $(shell $(PCRE_BUILDER) --libs8)
|
||||
endif
|
||||
|
||||
DEFS+=$(PCREDEFS)
|
||||
@@ -31,4 +26,3 @@ LIBS+=$(PCRELIBS)
|
||||
SERLIBPATH=../../lib
|
||||
SER_LIBS+=$(SERLIBPATH)/srdb1/srdb1
|
||||
include ../../Makefile.modules
|
||||
-
|
||||
--- a/src/modules/lcr/hash.c
|
||||
+++ b/src/modules/lcr/hash.c
|
||||
@@ -15,8 +15,8 @@
|
||||
* 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
|
||||
+ * 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
|
||||
*/
|
||||
|
||||
@@ -36,10 +36,10 @@
|
||||
/* Add lcr entry into hash table */
|
||||
int rule_hash_table_insert(struct rule_info **hash_table, unsigned int lcr_id,
|
||||
unsigned int rule_id, unsigned short prefix_len, char *prefix,
|
||||
- unsigned short from_uri_len, char *from_uri, pcre *from_uri_re,
|
||||
+ unsigned short from_uri_len, char *from_uri, pcre2_code *from_uri_re,
|
||||
unsigned short mt_tvalue_len, char *mt_tvalue,
|
||||
- unsigned short request_uri_len, char *request_uri, pcre *request_uri_re,
|
||||
- unsigned short stopper)
|
||||
+ unsigned short request_uri_len, char *request_uri,
|
||||
+ pcre2_code *request_uri_re, unsigned short stopper)
|
||||
{
|
||||
struct rule_info *rule;
|
||||
str prefix_str;
|
||||
@@ -50,9 +50,9 @@ int rule_hash_table_insert(struct rule_i
|
||||
if(rule == NULL) {
|
||||
SHM_MEM_ERROR_FMT("for rule hash table entry\n");
|
||||
if(from_uri_re)
|
||||
- shm_free(from_uri_re);
|
||||
+ pcre2_code_free(from_uri_re);
|
||||
if(request_uri_re)
|
||||
- shm_free(request_uri_re);
|
||||
+ pcre2_code_free(request_uri_re);
|
||||
return 0;
|
||||
}
|
||||
memset(rule, 0, sizeof(struct rule_info));
|
||||
@@ -99,9 +99,9 @@ int rule_hash_table_insert(struct rule_i
|
||||
if(rid == NULL) {
|
||||
PKG_MEM_ERROR_FMT("for rule_id hash table entry\n");
|
||||
if(from_uri_re)
|
||||
- shm_free(from_uri_re);
|
||||
+ pcre2_code_free(from_uri_re);
|
||||
if(request_uri_re)
|
||||
- shm_free(request_uri_re);
|
||||
+ pcre2_code_free(request_uri_re);
|
||||
shm_free(rule);
|
||||
return 0;
|
||||
}
|
||||
@@ -180,7 +180,7 @@ int rule_hash_table_insert_target(struct
|
||||
}
|
||||
|
||||
|
||||
-/*
|
||||
+/*
|
||||
* Return pointer to lcr hash table entry to which given prefix hashes to.
|
||||
*/
|
||||
struct rule_info *rule_hash_table_lookup(
|
||||
@@ -209,10 +209,10 @@ void rule_hash_table_contents_free(struc
|
||||
r = hash_table[i];
|
||||
while(r) {
|
||||
if(r->from_uri_re) {
|
||||
- shm_free(r->from_uri_re);
|
||||
+ pcre2_code_free(r->from_uri_re);
|
||||
}
|
||||
if(r->request_uri_re)
|
||||
- shm_free(r->request_uri_re);
|
||||
+ pcre2_code_free(r->request_uri_re);
|
||||
t = r->targets;
|
||||
while(t) {
|
||||
next_t = t->next;
|
||||
--- a/src/modules/lcr/hash.h
|
||||
+++ b/src/modules/lcr/hash.h
|
||||
@@ -15,8 +15,8 @@
|
||||
* 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
|
||||
+ * 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
|
||||
*/
|
||||
|
||||
@@ -34,10 +34,10 @@
|
||||
|
||||
int rule_hash_table_insert(struct rule_info **hash_table, unsigned int lcr_id,
|
||||
unsigned int rule_id, unsigned short prefix_len, char *prefix,
|
||||
- unsigned short from_uri_len, char *from_uri, pcre *from_uri_re,
|
||||
+ unsigned short from_uri_len, char *from_uri, pcre2_code *from_uri_re,
|
||||
unsigned short mt_tvalue_len, char *mt_tvalue,
|
||||
- unsigned short request_uri_len, char *request_uri, pcre *request_uri_re,
|
||||
- unsigned short stopper);
|
||||
+ unsigned short request_uri_len, char *request_uri,
|
||||
+ pcre2_code *request_uri_re, unsigned short stopper);
|
||||
|
||||
int rule_hash_table_insert_target(struct rule_info **hash_table,
|
||||
struct gw_info *gws, unsigned int rule_id, unsigned int gw_id,
|
||||
--- a/src/modules/lcr/lcr_mod.c
|
||||
+++ b/src/modules/lcr/lcr_mod.c
|
||||
@@ -16,8 +16,8 @@
|
||||
* 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
|
||||
+ * 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
|
||||
*
|
||||
*/
|
||||
@@ -43,7 +43,8 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <arpa/inet.h>
|
||||
-#include <pcre.h>
|
||||
+#define PCRE2_CODE_UNIT_WIDTH 8
|
||||
+#include <pcre2.h>
|
||||
#include "../../core/locking.h"
|
||||
#include "../../core/sr_module.h"
|
||||
#include "../../core/dprint.h"
|
||||
@@ -204,6 +205,9 @@ static unsigned int priority_ordering_pa
|
||||
/* mtree tree name */
|
||||
str mtree_param = {"lcr", 3};
|
||||
|
||||
+static pcre2_general_context *lcr_gctx = NULL;
|
||||
+static pcre2_compile_context *lcr_ctx = NULL;
|
||||
+
|
||||
/*
|
||||
* Other module types and variables
|
||||
*/
|
||||
@@ -364,7 +368,7 @@ static param_export_t params[] = {
|
||||
* Module interface
|
||||
*/
|
||||
struct module_exports exports = {
|
||||
- "lcr",
|
||||
+ "lcr",
|
||||
DEFAULT_DLFLAGS, /* dlopen flags */
|
||||
cmds, /* Exported functions */
|
||||
params, /* Exported parameters */
|
||||
@@ -422,6 +426,16 @@ static void lcr_db_close(void)
|
||||
}
|
||||
}
|
||||
|
||||
+static void *pcre2_malloc(size_t size, void *ext)
|
||||
+{
|
||||
+ return shm_malloc(size);
|
||||
+}
|
||||
+
|
||||
+static void pcre2_free(void *ptr, void *ext)
|
||||
+{
|
||||
+ shm_free(ptr);
|
||||
+ ptr = NULL;
|
||||
+}
|
||||
|
||||
/*
|
||||
* Module initialization function that is called before the main process forks
|
||||
@@ -703,7 +717,15 @@ static int mod_init(void)
|
||||
lcr_db_close();
|
||||
|
||||
/* rule shared memory */
|
||||
-
|
||||
+ if((lcr_gctx = pcre2_general_context_create(pcre2_malloc, pcre2_free, NULL))
|
||||
+ == NULL) {
|
||||
+ LM_ERR("pcre2 general context creation failed\n");
|
||||
+ goto err;
|
||||
+ }
|
||||
+ if((lcr_ctx = pcre2_compile_context_create(lcr_gctx)) == NULL) {
|
||||
+ LM_ERR("pcre2 compile context creation failed\n");
|
||||
+ goto err;
|
||||
+ }
|
||||
/* rule hash table pointer table */
|
||||
/* pointer at index 0 points to temp rule hash table */
|
||||
rule_pt = (struct rule_info ***)shm_malloc(
|
||||
@@ -779,6 +801,12 @@ dberror:
|
||||
lcr_db_close();
|
||||
|
||||
err:
|
||||
+ if(lcr_ctx) {
|
||||
+ pcre2_compile_context_free(lcr_ctx);
|
||||
+ }
|
||||
+ if(lcr_gctx) {
|
||||
+ pcre2_general_context_free(lcr_gctx);
|
||||
+ }
|
||||
free_shared_memory();
|
||||
return -1;
|
||||
}
|
||||
@@ -794,7 +822,12 @@ static int child_init(int rank)
|
||||
static void destroy(void)
|
||||
{
|
||||
lcr_db_close();
|
||||
-
|
||||
+ if(lcr_ctx) {
|
||||
+ pcre2_compile_context_free(lcr_ctx);
|
||||
+ }
|
||||
+ if(lcr_gctx) {
|
||||
+ pcre2_general_context_free(lcr_gctx);
|
||||
+ }
|
||||
free_shared_memory();
|
||||
}
|
||||
|
||||
@@ -875,33 +908,32 @@ static int comp_matched(const void *m1,
|
||||
|
||||
|
||||
/* Compile pattern into shared memory and return pointer to it. */
|
||||
-static pcre *reg_ex_comp(const char *pattern)
|
||||
+static pcre2_code *reg_ex_comp(const char *pattern)
|
||||
{
|
||||
- pcre *re, *result;
|
||||
- const char *error;
|
||||
- int rc, err_offset;
|
||||
- size_t size;
|
||||
-
|
||||
- re = pcre_compile(pattern, 0, &error, &err_offset, NULL);
|
||||
- if(re == NULL) {
|
||||
- LM_ERR("pcre compilation of '%s' failed at offset %d: %s\n", pattern,
|
||||
- err_offset, error);
|
||||
- return (pcre *)0;
|
||||
- }
|
||||
- rc = pcre_fullinfo(re, NULL, PCRE_INFO_SIZE, &size);
|
||||
- if(rc != 0) {
|
||||
- LM_ERR("pcre_fullinfo on compiled pattern '%s' yielded error: %d\n",
|
||||
- pattern, rc);
|
||||
- return (pcre *)0;
|
||||
- }
|
||||
- result = (pcre *)shm_malloc(size);
|
||||
+ pcre2_code *result;
|
||||
+ int pcre_error_num = 0;
|
||||
+ char pcre_error[128];
|
||||
+ size_t pcre_erroffset;
|
||||
+
|
||||
+ result = pcre2_compile((PCRE2_SPTR)pattern, PCRE2_ZERO_TERMINATED, 0,
|
||||
+ &pcre_error_num, &pcre_erroffset, lcr_ctx);
|
||||
if(result == NULL) {
|
||||
- pcre_free(re);
|
||||
- SHM_MEM_ERROR_FMT("for compiled PCRE pattern\n");
|
||||
- return (pcre *)0;
|
||||
+ switch(pcre2_get_error_message(
|
||||
+ pcre_error_num, (PCRE2_UCHAR *)pcre_error, 128)) {
|
||||
+ case PCRE2_ERROR_NOMEMORY:
|
||||
+ snprintf(pcre_error, 128,
|
||||
+ "unknown error[%d]: pcre2 error buffer too small",
|
||||
+ pcre_error_num);
|
||||
+ break;
|
||||
+ case PCRE2_ERROR_BADDATA:
|
||||
+ snprintf(pcre_error, 128, "unknown pcre2 error[%d]",
|
||||
+ pcre_error_num);
|
||||
+ break;
|
||||
+ }
|
||||
+ LM_ERR("pcre compilation of '%s' failed at offset %zu: %s\n", pattern,
|
||||
+ pcre_erroffset, pcre_error);
|
||||
+ return NULL;
|
||||
}
|
||||
- memcpy(result, re, size);
|
||||
- pcre_free(re);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -950,7 +982,7 @@ static struct gw_info *find_gateway_by_i
|
||||
return NULL;
|
||||
}
|
||||
|
||||
-/*
|
||||
+/*
|
||||
* Insert gw info into index i or gws table
|
||||
*/
|
||||
static int insert_gw(struct gw_info *gws, unsigned int i, unsigned int gw_id,
|
||||
@@ -1024,7 +1056,7 @@ static int insert_gw(struct gw_info *gws
|
||||
|
||||
|
||||
/*
|
||||
- * Insert prefix_len into list pointed by last rule hash table entry
|
||||
+ * Insert prefix_len into list pointed by last rule hash table entry
|
||||
* if not there already. Keep list in decending prefix_len order.
|
||||
*/
|
||||
static int prefix_len_insert(
|
||||
@@ -1414,7 +1446,7 @@ int reload_tables()
|
||||
db_key_t gw_cols[13];
|
||||
db_key_t rule_cols[7];
|
||||
db_key_t target_cols[4];
|
||||
- pcre *from_uri_re, *request_uri_re;
|
||||
+ pcre2_code *from_uri_re, *request_uri_re;
|
||||
struct gw_info *gws, *gw_pt_tmp;
|
||||
struct rule_info **rules, **rule_pt_tmp;
|
||||
|
||||
@@ -2129,11 +2161,12 @@ void add_gws_into_avps(struct gw_info *g
|
||||
int load_gws_dummy(int lcr_id, str *ruri_user, str *from_uri, str *request_uri,
|
||||
unsigned int *gw_indexes)
|
||||
{
|
||||
- int i, j;
|
||||
+ int i, j, rc;
|
||||
unsigned int gw_index, now, dex;
|
||||
struct rule_info **rules, *rule, *pl;
|
||||
struct gw_info *gws;
|
||||
struct target *t;
|
||||
+ pcre2_match_data *pcre_md = NULL;
|
||||
struct matched_gw_info matched_gws[MAX_NO_OF_GWS + 1];
|
||||
struct sip_uri furi;
|
||||
struct usr_avp *avp;
|
||||
@@ -2178,12 +2211,18 @@ int load_gws_dummy(int lcr_id, str *ruri
|
||||
|| strncmp(rule->prefix, ruri_user->s, pl->prefix_len))
|
||||
goto next;
|
||||
|
||||
- if((rule->from_uri_len != 0)
|
||||
- && (pcre_exec(rule->from_uri_re, NULL, from_uri->s,
|
||||
- from_uri->len, 0, 0, NULL, 0)
|
||||
- < 0))
|
||||
- goto next;
|
||||
-
|
||||
+ if(rule->from_uri_len != 0) {
|
||||
+ pcre_md = pcre2_match_data_create_from_pattern(
|
||||
+ rule->from_uri_re, NULL);
|
||||
+ rc = pcre2_match(rule->from_uri_re, (PCRE2_SPTR)from_uri->s,
|
||||
+ (PCRE2_SIZE)from_uri->len, 0, 0, pcre_md, NULL);
|
||||
+ if(pcre_md) {
|
||||
+ pcre2_match_data_free(pcre_md);
|
||||
+ pcre_md = NULL;
|
||||
+ }
|
||||
+ if(rc < 0)
|
||||
+ goto next;
|
||||
+ }
|
||||
if((from_uri->len > 0) && (rule->mt_tvalue_len > 0)) {
|
||||
if(mtree_api.mt_match(&msg, &mtree_param, &(furi.user), 2)
|
||||
== -1) {
|
||||
@@ -2216,9 +2255,16 @@ int load_gws_dummy(int lcr_id, str *ruri
|
||||
"param has not been given.\n");
|
||||
return -1;
|
||||
}
|
||||
- if(pcre_exec(rule->request_uri_re, NULL, request_uri->s,
|
||||
- request_uri->len, 0, 0, NULL, 0)
|
||||
- < 0)
|
||||
+ pcre_md = pcre2_match_data_create_from_pattern(
|
||||
+ rule->request_uri_re, NULL);
|
||||
+ rc = pcre2_match(rule->request_uri_re,
|
||||
+ (PCRE2_SPTR)request_uri->s,
|
||||
+ (PCRE2_SIZE)request_uri->len, 0, 0, pcre_md, NULL);
|
||||
+ if(pcre_md) {
|
||||
+ pcre2_match_data_free(pcre_md);
|
||||
+ pcre_md = NULL;
|
||||
+ }
|
||||
+ if(rc < 0)
|
||||
goto next;
|
||||
}
|
||||
|
||||
@@ -2282,9 +2328,10 @@ static int ki_load_gws_furi(
|
||||
sip_msg_t *_m, int lcr_id, str *ruri_user, str *from_uri)
|
||||
{
|
||||
str *request_uri;
|
||||
- int i, j;
|
||||
+ int i, j, rc;
|
||||
unsigned int gw_index, now, dex;
|
||||
int_str val;
|
||||
+ pcre2_match_data *pcre_md = NULL;
|
||||
struct matched_gw_info matched_gws[MAX_NO_OF_GWS + 1];
|
||||
struct rule_info **rules, *rule, *pl;
|
||||
struct gw_info *gws;
|
||||
@@ -2343,14 +2390,22 @@ static int ki_load_gws_furi(
|
||||
goto next;
|
||||
|
||||
/* Match from uri */
|
||||
- if((rule->from_uri_len != 0)
|
||||
- && (pcre_exec(rule->from_uri_re, NULL, from_uri->s,
|
||||
- from_uri->len, 0, 0, NULL, 0)
|
||||
- < 0)) {
|
||||
- LM_DBG("from uri <%.*s> did not match to from regex <%.*s>\n",
|
||||
- from_uri->len, from_uri->s, rule->from_uri_len,
|
||||
- rule->from_uri);
|
||||
- goto next;
|
||||
+ if(rule->from_uri_len != 0) {
|
||||
+ pcre_md = pcre2_match_data_create_from_pattern(
|
||||
+ rule->from_uri_re, NULL);
|
||||
+ rc = pcre2_match(rule->from_uri_re, (PCRE2_SPTR)from_uri->s,
|
||||
+ (PCRE2_SIZE)from_uri->len, 0, 0, pcre_md, NULL);
|
||||
+ if(pcre_md) {
|
||||
+ pcre2_match_data_free(pcre_md);
|
||||
+ pcre_md = NULL;
|
||||
+ }
|
||||
+ if(rc < 0) {
|
||||
+ LM_DBG("from uri <%.*s> did not match to from regex "
|
||||
+ "<%.*s>\n",
|
||||
+ from_uri->len, from_uri->s, rule->from_uri_len,
|
||||
+ rule->from_uri);
|
||||
+ goto next;
|
||||
+ }
|
||||
}
|
||||
|
||||
/* Match from uri user */
|
||||
@@ -2379,15 +2434,23 @@ static int ki_load_gws_furi(
|
||||
}
|
||||
|
||||
/* Match request uri */
|
||||
- if((rule->request_uri_len != 0)
|
||||
- && (pcre_exec(rule->request_uri_re, NULL, request_uri->s,
|
||||
- request_uri->len, 0, 0, NULL, 0)
|
||||
- < 0)) {
|
||||
- LM_DBG("request uri <%.*s> did not match to request regex "
|
||||
- "<%.*s>\n",
|
||||
- request_uri->len, request_uri->s, rule->request_uri_len,
|
||||
- rule->request_uri);
|
||||
- goto next;
|
||||
+ if(rule->request_uri_len != 0) {
|
||||
+ pcre_md = pcre2_match_data_create_from_pattern(
|
||||
+ rule->request_uri_re, NULL);
|
||||
+ rc = pcre2_match(rule->request_uri_re,
|
||||
+ (PCRE2_SPTR)request_uri->s,
|
||||
+ (PCRE2_SIZE)request_uri->len, 0, 0, pcre_md, NULL);
|
||||
+ if(pcre_md) {
|
||||
+ pcre2_match_data_free(pcre_md);
|
||||
+ pcre_md = NULL;
|
||||
+ }
|
||||
+ if(rc < 0) {
|
||||
+ LM_DBG("request uri <%.*s> did not match to request regex "
|
||||
+ "<%.*s>\n",
|
||||
+ request_uri->len, request_uri->s,
|
||||
+ rule->request_uri_len, rule->request_uri);
|
||||
+ goto next;
|
||||
+ }
|
||||
}
|
||||
|
||||
/* Load gws associated with this rule */
|
||||
@@ -3015,7 +3078,7 @@ static int ki_next_gw(sip_msg_t *_m)
|
||||
}
|
||||
|
||||
/**
|
||||
- *
|
||||
+ *
|
||||
*/
|
||||
static int next_gw(struct sip_msg *_m, char *_s1, char *_s2)
|
||||
{
|
||||
--- a/src/modules/lcr/lcr_mod.h
|
||||
+++ b/src/modules/lcr/lcr_mod.h
|
||||
@@ -2,6 +2,7 @@
|
||||
* Various lcr related constant, types, and external variables
|
||||
*
|
||||
* Copyright (C) 2005-2014 Juha Heinanen
|
||||
+ * Copyright (C) 2023 Victor Seva
|
||||
*
|
||||
* This file is part of Kamailio, a free SIP server.
|
||||
*
|
||||
@@ -33,7 +34,8 @@
|
||||
#define LCR_MOD_H
|
||||
|
||||
#include <stdio.h>
|
||||
-#include <pcre.h>
|
||||
+#define PCRE2_CODE_UNIT_WIDTH 8
|
||||
+#include <pcre2.h>
|
||||
#include "../../core/locking.h"
|
||||
#include "../../core/parser/parse_uri.h"
|
||||
#include "../../core/ip_addr.h"
|
||||
@@ -60,10 +62,10 @@ struct rule_info
|
||||
unsigned short from_uri_len;
|
||||
char mt_tvalue[MAX_MT_TVALUE_LEN + 1];
|
||||
unsigned short mt_tvalue_len;
|
||||
- pcre *from_uri_re;
|
||||
+ pcre2_code *from_uri_re;
|
||||
char request_uri[MAX_URI_LEN + 1];
|
||||
unsigned short request_uri_len;
|
||||
- pcre *request_uri_re;
|
||||
+ pcre2_code *request_uri_re;
|
||||
unsigned short stopper;
|
||||
unsigned int enabled;
|
||||
struct target *targets;
|
@ -0,0 +1,715 @@
|
||||
From fb7c59cafceb35628d40c727dbfa2990335b922a Mon Sep 17 00:00:00 2001
|
||||
From: Victor Seva <linuxmaniac@torreviejawireless.org>
|
||||
Date: Wed, 17 May 2023 16:37:10 +0200
|
||||
Subject: [PATCH] regex: clang-format for coherent indentation and coding style
|
||||
|
||||
---
|
||||
src/modules/regex/regex_mod.c | 313 ++++++++++++++++------------------
|
||||
1 file changed, 150 insertions(+), 163 deletions(-)
|
||||
|
||||
--- a/src/modules/regex/regex_mod.c
|
||||
+++ b/src/modules/regex/regex_mod.c
|
||||
@@ -49,9 +49,9 @@ MODULE_VERSION
|
||||
#define START 0
|
||||
#define RELOAD 1
|
||||
|
||||
-#define FILE_MAX_LINE 500 /*!< Max line size in the file */
|
||||
-#define MAX_GROUPS 20 /*!< Max number of groups */
|
||||
-#define GROUP_MAX_SIZE 8192 /*!< Max size of a group */
|
||||
+#define FILE_MAX_LINE 500 /*!< Max line size in the file */
|
||||
+#define MAX_GROUPS 20 /*!< Max number of groups */
|
||||
+#define GROUP_MAX_SIZE 8192 /*!< Max size of a group */
|
||||
|
||||
|
||||
static int regex_init_rpc(void);
|
||||
@@ -66,12 +66,12 @@ gen_lock_t *reload_lock;
|
||||
* Module exported parameter variables
|
||||
*/
|
||||
static char *file;
|
||||
-static int max_groups = MAX_GROUPS;
|
||||
-static int group_max_size = GROUP_MAX_SIZE;
|
||||
-static int pcre_caseless = 0;
|
||||
-static int pcre_multiline = 0;
|
||||
-static int pcre_dotall = 0;
|
||||
-static int pcre_extended = 0;
|
||||
+static int max_groups = MAX_GROUPS;
|
||||
+static int group_max_size = GROUP_MAX_SIZE;
|
||||
+static int pcre_caseless = 0;
|
||||
+static int pcre_multiline = 0;
|
||||
+static int pcre_dotall = 0;
|
||||
+static int pcre_extended = 0;
|
||||
|
||||
|
||||
/*
|
||||
@@ -100,119 +100,117 @@ static void free_shared_memory(void);
|
||||
/*
|
||||
* Script functions
|
||||
*/
|
||||
-static int w_pcre_match(struct sip_msg* _msg, char* _s1, char* _s2);
|
||||
-static int w_pcre_match_group(struct sip_msg* _msg, char* _s1, char* _s2);
|
||||
+static int w_pcre_match(struct sip_msg *_msg, char *_s1, char *_s2);
|
||||
+static int w_pcre_match_group(struct sip_msg *_msg, char *_s1, char *_s2);
|
||||
|
||||
|
||||
/*
|
||||
* Exported functions
|
||||
*/
|
||||
-static cmd_export_t cmds[] =
|
||||
-{
|
||||
- { "pcre_match", (cmd_function)w_pcre_match, 2, fixup_spve_spve, 0,
|
||||
- REQUEST_ROUTE|FAILURE_ROUTE|ONREPLY_ROUTE|BRANCH_ROUTE|LOCAL_ROUTE },
|
||||
- { "pcre_match_group", (cmd_function)w_pcre_match_group, 2, fixup_spve_spve, 0,
|
||||
- REQUEST_ROUTE|FAILURE_ROUTE|ONREPLY_ROUTE|BRANCH_ROUTE|LOCAL_ROUTE },
|
||||
- { "pcre_match_group", (cmd_function)w_pcre_match_group, 1, fixup_spve_null, 0,
|
||||
- REQUEST_ROUTE|FAILURE_ROUTE|ONREPLY_ROUTE|BRANCH_ROUTE|LOCAL_ROUTE },
|
||||
- { 0, 0, 0, 0, 0, 0 }
|
||||
-};
|
||||
+static cmd_export_t cmds[] = {
|
||||
+ {"pcre_match", (cmd_function)w_pcre_match, 2, fixup_spve_spve, 0,
|
||||
+ REQUEST_ROUTE | FAILURE_ROUTE | ONREPLY_ROUTE | BRANCH_ROUTE
|
||||
+ | LOCAL_ROUTE},
|
||||
+ {"pcre_match_group", (cmd_function)w_pcre_match_group, 2,
|
||||
+ fixup_spve_spve, 0,
|
||||
+ REQUEST_ROUTE | FAILURE_ROUTE | ONREPLY_ROUTE | BRANCH_ROUTE
|
||||
+ | LOCAL_ROUTE},
|
||||
+ {"pcre_match_group", (cmd_function)w_pcre_match_group, 1,
|
||||
+ fixup_spve_null, 0,
|
||||
+ REQUEST_ROUTE | FAILURE_ROUTE | ONREPLY_ROUTE | BRANCH_ROUTE
|
||||
+ | LOCAL_ROUTE},
|
||||
+ {0, 0, 0, 0, 0, 0}};
|
||||
|
||||
|
||||
/*
|
||||
* Exported parameters
|
||||
*/
|
||||
-static param_export_t params[] = {
|
||||
- {"file", PARAM_STRING, &file },
|
||||
- {"max_groups", INT_PARAM, &max_groups },
|
||||
- {"group_max_size", INT_PARAM, &group_max_size },
|
||||
- {"pcre_caseless", INT_PARAM, &pcre_caseless },
|
||||
- {"pcre_multiline", INT_PARAM, &pcre_multiline },
|
||||
- {"pcre_dotall", INT_PARAM, &pcre_dotall },
|
||||
- {"pcre_extended", INT_PARAM, &pcre_extended },
|
||||
- {0, 0, 0}
|
||||
-};
|
||||
+static param_export_t params[] = {{"file", PARAM_STRING, &file},
|
||||
+ {"max_groups", INT_PARAM, &max_groups},
|
||||
+ {"group_max_size", INT_PARAM, &group_max_size},
|
||||
+ {"pcre_caseless", INT_PARAM, &pcre_caseless},
|
||||
+ {"pcre_multiline", INT_PARAM, &pcre_multiline},
|
||||
+ {"pcre_dotall", INT_PARAM, &pcre_dotall},
|
||||
+ {"pcre_extended", INT_PARAM, &pcre_extended}, {0, 0, 0}};
|
||||
|
||||
|
||||
/*
|
||||
* Module interface
|
||||
*/
|
||||
struct module_exports exports = {
|
||||
- "regex", /*!< module name */
|
||||
- DEFAULT_DLFLAGS, /*!< dlopen flags */
|
||||
- cmds, /*!< exported functions */
|
||||
- params, /*!< exported parameters */
|
||||
- 0, /*!< exported RPC functions */
|
||||
- 0, /*!< exported pseudo-variables */
|
||||
- 0, /*!< response handling function */
|
||||
- mod_init, /*!< module initialization function */
|
||||
- 0, /*!< per-child init function */
|
||||
- destroy /*!< destroy function */
|
||||
+ "regex", /*!< module name */
|
||||
+ DEFAULT_DLFLAGS, /*!< dlopen flags */
|
||||
+ cmds, /*!< exported functions */
|
||||
+ params, /*!< exported parameters */
|
||||
+ 0, /*!< exported RPC functions */
|
||||
+ 0, /*!< exported pseudo-variables */
|
||||
+ 0, /*!< response handling function */
|
||||
+ mod_init, /*!< module initialization function */
|
||||
+ 0, /*!< per-child init function */
|
||||
+ destroy /*!< destroy function */
|
||||
};
|
||||
|
||||
|
||||
-
|
||||
/*! \brief
|
||||
* Init module function
|
||||
*/
|
||||
static int mod_init(void)
|
||||
{
|
||||
- if(regex_init_rpc()<0)
|
||||
- {
|
||||
+ if(regex_init_rpc() < 0) {
|
||||
LM_ERR("failed to register RPC commands\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Group matching feature */
|
||||
- if (file == NULL) {
|
||||
+ if(file == NULL) {
|
||||
LM_NOTICE("'file' parameter is not set, group matching disabled\n");
|
||||
} else {
|
||||
/* Create and init the lock */
|
||||
reload_lock = lock_alloc();
|
||||
- if (reload_lock == NULL) {
|
||||
+ if(reload_lock == NULL) {
|
||||
LM_ERR("cannot allocate reload_lock\n");
|
||||
goto err;
|
||||
}
|
||||
- if (lock_init(reload_lock) == NULL) {
|
||||
+ if(lock_init(reload_lock) == NULL) {
|
||||
LM_ERR("cannot init the reload_lock\n");
|
||||
lock_dealloc(reload_lock);
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* PCRE options */
|
||||
- if (pcre_caseless != 0) {
|
||||
+ if(pcre_caseless != 0) {
|
||||
LM_DBG("PCRE CASELESS enabled\n");
|
||||
pcre_options = pcre_options | PCRE_CASELESS;
|
||||
}
|
||||
- if (pcre_multiline != 0) {
|
||||
+ if(pcre_multiline != 0) {
|
||||
LM_DBG("PCRE MULTILINE enabled\n");
|
||||
pcre_options = pcre_options | PCRE_MULTILINE;
|
||||
}
|
||||
- if (pcre_dotall != 0) {
|
||||
+ if(pcre_dotall != 0) {
|
||||
LM_DBG("PCRE DOTALL enabled\n");
|
||||
pcre_options = pcre_options | PCRE_DOTALL;
|
||||
}
|
||||
- if (pcre_extended != 0) {
|
||||
+ if(pcre_extended != 0) {
|
||||
LM_DBG("PCRE EXTENDED enabled\n");
|
||||
pcre_options = pcre_options | PCRE_EXTENDED;
|
||||
}
|
||||
LM_DBG("PCRE options: %i\n", pcre_options);
|
||||
|
||||
/* Pointer to pcres */
|
||||
- if ((pcres_addr = shm_malloc(sizeof(pcre **))) == 0) {
|
||||
+ if((pcres_addr = shm_malloc(sizeof(pcre **))) == 0) {
|
||||
LM_ERR("no memory for pcres_addr\n");
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* Integer containing the number of pcres */
|
||||
- if ((num_pcres = shm_malloc(sizeof(int))) == 0) {
|
||||
+ if((num_pcres = shm_malloc(sizeof(int))) == 0) {
|
||||
LM_ERR("no memory for num_pcres\n");
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* Load the pcres */
|
||||
LM_DBG("loading pcres...\n");
|
||||
- if (load_pcres(START)) {
|
||||
+ if(load_pcres(START)) {
|
||||
LM_ERR("failed to load pcres\n");
|
||||
goto err;
|
||||
}
|
||||
@@ -251,21 +249,21 @@ static int load_pcres(int action)
|
||||
/* Get the lock */
|
||||
lock_get(reload_lock);
|
||||
|
||||
- if (!(f = fopen(file, "r"))) {
|
||||
+ if(!(f = fopen(file, "r"))) {
|
||||
LM_ERR("could not open file '%s'\n", file);
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* Array containing each pattern in the file */
|
||||
- if ((patterns = pkg_malloc(sizeof(char*) * max_groups)) == 0) {
|
||||
+ if((patterns = pkg_malloc(sizeof(char *) * max_groups)) == 0) {
|
||||
LM_ERR("no more memory for patterns\n");
|
||||
fclose(f);
|
||||
goto err;
|
||||
}
|
||||
- memset(patterns, 0, sizeof(char*) * max_groups);
|
||||
+ memset(patterns, 0, sizeof(char *) * max_groups);
|
||||
|
||||
- for (i=0; i<max_groups; i++) {
|
||||
- if ((patterns[i] = pkg_malloc(sizeof(char) * group_max_size)) == 0) {
|
||||
+ for(i = 0; i < max_groups; i++) {
|
||||
+ if((patterns[i] = pkg_malloc(sizeof(char) * group_max_size)) == 0) {
|
||||
LM_ERR("no more memory for patterns[%d]\n", i);
|
||||
fclose(f);
|
||||
goto err;
|
||||
@@ -276,26 +274,27 @@ static int load_pcres(int action)
|
||||
/* Read the file and extract the patterns */
|
||||
memset(line, 0, FILE_MAX_LINE);
|
||||
i = -1;
|
||||
- while (fgets(line, FILE_MAX_LINE-4, f) != NULL) {
|
||||
+ while(fgets(line, FILE_MAX_LINE - 4, f) != NULL) {
|
||||
|
||||
/* Ignore comments and lines starting by space, tab, CR, LF */
|
||||
- if(isspace(line[0]) || line[0]=='#') {
|
||||
+ if(isspace(line[0]) || line[0] == '#') {
|
||||
memset(line, 0, FILE_MAX_LINE);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* First group */
|
||||
- if (i == -1 && line[0] != '[') {
|
||||
- LM_ERR("first group must be initialized with [0] before any regular expression\n");
|
||||
+ if(i == -1 && line[0] != '[') {
|
||||
+ LM_ERR("first group must be initialized with [0] before any "
|
||||
+ "regular expression\n");
|
||||
fclose(f);
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* New group */
|
||||
- if (line[0] == '[') {
|
||||
+ if(line[0] == '[') {
|
||||
i++;
|
||||
/* Check if there are more patterns than the max value */
|
||||
- if (i >= max_groups) {
|
||||
+ if(i >= max_groups) {
|
||||
LM_ERR("max patterns exceeded\n");
|
||||
fclose(f);
|
||||
goto err;
|
||||
@@ -309,14 +308,14 @@ static int load_pcres(int action)
|
||||
|
||||
llen = strlen(line);
|
||||
/* Check if the patter size is too big (aprox) */
|
||||
- if (strlen(patterns[i]) + llen >= group_max_size - 4) {
|
||||
+ if(strlen(patterns[i]) + llen >= group_max_size - 4) {
|
||||
LM_ERR("pattern max file exceeded\n");
|
||||
fclose(f);
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* Append ')' at the end of the line */
|
||||
- if (line[llen - 1] == '\n') {
|
||||
+ if(line[llen - 1] == '\n') {
|
||||
line[llen - 1] = ')';
|
||||
line[llen] = '\n';
|
||||
line[llen + 1] = '\0';
|
||||
@@ -328,7 +327,7 @@ static int load_pcres(int action)
|
||||
|
||||
/* Append '(' at the beginning of the line */
|
||||
llen = strlen(patterns[i]);
|
||||
- memcpy(patterns[i]+llen, "(", 1);
|
||||
+ memcpy(patterns[i] + llen, "(", 1);
|
||||
llen++;
|
||||
|
||||
/* Append the line to the current pattern (including the ending 0) */
|
||||
@@ -340,16 +339,16 @@ static int load_pcres(int action)
|
||||
|
||||
fclose(f);
|
||||
|
||||
- if(num_pcres_tmp==0) {
|
||||
+ if(num_pcres_tmp == 0) {
|
||||
LM_ERR("no expressions in the file\n");
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* Fix the patterns */
|
||||
- for (i=0; i < num_pcres_tmp; i++) {
|
||||
+ for(i = 0; i < num_pcres_tmp; i++) {
|
||||
|
||||
/* Convert empty groups in unmatcheable regular expression ^$ */
|
||||
- if (strlen(patterns[i]) == 1) {
|
||||
+ if(strlen(patterns[i]) == 1) {
|
||||
patterns[i][0] = '^';
|
||||
patterns[i][1] = '$';
|
||||
patterns[i][2] = '\0';
|
||||
@@ -357,13 +356,13 @@ static int load_pcres(int action)
|
||||
}
|
||||
|
||||
/* Delete possible '\n' at the end of the pattern */
|
||||
- if (patterns[i][strlen(patterns[i])-1] == '\n') {
|
||||
- patterns[i][strlen(patterns[i])-1] = '\0';
|
||||
+ if(patterns[i][strlen(patterns[i]) - 1] == '\n') {
|
||||
+ patterns[i][strlen(patterns[i]) - 1] = '\0';
|
||||
}
|
||||
|
||||
/* Replace '\n' with '|' (except at the end of the pattern) */
|
||||
- for (j=0; j < strlen(patterns[i]); j++) {
|
||||
- if (patterns[i][j] == '\n' && j != strlen(patterns[i])-1) {
|
||||
+ for(j = 0; j < strlen(patterns[i]); j++) {
|
||||
+ if(patterns[i][j] == '\n' && j != strlen(patterns[i]) - 1) {
|
||||
patterns[i][j] = '|';
|
||||
}
|
||||
}
|
||||
@@ -374,38 +373,38 @@ static int load_pcres(int action)
|
||||
|
||||
/* Log the group patterns */
|
||||
LM_INFO("num groups = %d\n", num_pcres_tmp);
|
||||
- for (i=0; i < num_pcres_tmp; i++) {
|
||||
- LM_INFO("<group[%d]>%s</group[%d]> (size = %i)\n", i, patterns[i],
|
||||
- i, (int)strlen(patterns[i]));
|
||||
+ for(i = 0; i < num_pcres_tmp; i++) {
|
||||
+ LM_INFO("<group[%d]>%s</group[%d]> (size = %i)\n", i, patterns[i], i,
|
||||
+ (int)strlen(patterns[i]));
|
||||
}
|
||||
|
||||
/* Temporal pointer of pcres */
|
||||
- if ((pcres_tmp = pkg_malloc(sizeof(pcre *) * num_pcres_tmp)) == 0) {
|
||||
+ if((pcres_tmp = pkg_malloc(sizeof(pcre *) * num_pcres_tmp)) == 0) {
|
||||
LM_ERR("no more memory for pcres_tmp\n");
|
||||
goto err;
|
||||
}
|
||||
- for (i=0; i<num_pcres_tmp; i++) {
|
||||
+ for(i = 0; i < num_pcres_tmp; i++) {
|
||||
pcres_tmp[i] = NULL;
|
||||
}
|
||||
|
||||
/* Compile the patters */
|
||||
- for (i=0; i<num_pcres_tmp; i++) {
|
||||
+ for(i = 0; i < num_pcres_tmp; i++) {
|
||||
|
||||
- pcre_tmp = pcre_compile(patterns[i], pcre_options, &pcre_error,
|
||||
- &pcre_erroffset, NULL);
|
||||
- if (pcre_tmp == NULL) {
|
||||
+ pcre_tmp = pcre_compile(
|
||||
+ patterns[i], pcre_options, &pcre_error, &pcre_erroffset, NULL);
|
||||
+ if(pcre_tmp == NULL) {
|
||||
LM_ERR("pcre_tmp compilation of '%s' failed at offset %d: %s\n",
|
||||
patterns[i], pcre_erroffset, pcre_error);
|
||||
goto err;
|
||||
}
|
||||
pcre_rc = pcre_fullinfo(pcre_tmp, NULL, PCRE_INFO_SIZE, &pcre_size);
|
||||
- if (pcre_rc) {
|
||||
+ if(pcre_rc) {
|
||||
printf("pcre_fullinfo on compiled pattern[%i] yielded error: %d\n",
|
||||
i, pcre_rc);
|
||||
goto err;
|
||||
}
|
||||
|
||||
- if ((pcres_tmp[i] = pkg_malloc(pcre_size)) == 0) {
|
||||
+ if((pcres_tmp[i] = pkg_malloc(pcre_size)) == 0) {
|
||||
LM_ERR("no more memory for pcres_tmp[%i]\n", i);
|
||||
goto err;
|
||||
}
|
||||
@@ -417,22 +416,22 @@ static int load_pcres(int action)
|
||||
}
|
||||
|
||||
/* Copy to shared memory */
|
||||
- if (action == RELOAD) {
|
||||
- for(i=0; i<*num_pcres; i++) { /* Use the previous num_pcres value */
|
||||
- if (pcres[i]) {
|
||||
+ if(action == RELOAD) {
|
||||
+ for(i = 0; i < *num_pcres; i++) { /* Use the previous num_pcres value */
|
||||
+ if(pcres[i]) {
|
||||
shm_free(pcres[i]);
|
||||
}
|
||||
}
|
||||
shm_free(pcres);
|
||||
}
|
||||
- if ((pcres = shm_malloc(sizeof(pcre *) * num_pcres_tmp)) == 0) {
|
||||
+ if((pcres = shm_malloc(sizeof(pcre *) * num_pcres_tmp)) == 0) {
|
||||
LM_ERR("no more memory for pcres\n");
|
||||
goto err;
|
||||
}
|
||||
memset(pcres, 0, sizeof(pcre *) * num_pcres_tmp);
|
||||
- for (i=0; i<num_pcres_tmp; i++) {
|
||||
+ for(i = 0; i < num_pcres_tmp; i++) {
|
||||
pcre_rc = pcre_fullinfo(pcres_tmp[i], NULL, PCRE_INFO_SIZE, &pcre_size);
|
||||
- if ((pcres[i] = shm_malloc(pcre_size)) == 0) {
|
||||
+ if((pcres[i] = shm_malloc(pcre_size)) == 0) {
|
||||
LM_ERR("no more memory for pcres[%i]\n", i);
|
||||
goto err;
|
||||
}
|
||||
@@ -442,12 +441,12 @@ static int load_pcres(int action)
|
||||
*pcres_addr = pcres;
|
||||
|
||||
/* Free used memory */
|
||||
- for (i=0; i<num_pcres_tmp; i++) {
|
||||
+ for(i = 0; i < num_pcres_tmp; i++) {
|
||||
pkg_free(pcres_tmp[i]);
|
||||
}
|
||||
pkg_free(pcres_tmp);
|
||||
/* Free allocated slots for unused patterns */
|
||||
- for (i = num_pcres_tmp; i < max_groups; i++) {
|
||||
+ for(i = num_pcres_tmp; i < max_groups; i++) {
|
||||
pkg_free(patterns[i]);
|
||||
}
|
||||
pkg_free(patterns);
|
||||
@@ -456,26 +455,26 @@ static int load_pcres(int action)
|
||||
return 0;
|
||||
|
||||
err:
|
||||
- if (patterns) {
|
||||
- for(i=0; i<max_groups; i++) {
|
||||
- if (patterns[i]) {
|
||||
+ if(patterns) {
|
||||
+ for(i = 0; i < max_groups; i++) {
|
||||
+ if(patterns[i]) {
|
||||
pkg_free(patterns[i]);
|
||||
}
|
||||
}
|
||||
pkg_free(patterns);
|
||||
}
|
||||
- if (pcres_tmp) {
|
||||
- for (i=0; i<num_pcres_tmp; i++) {
|
||||
- if (pcres_tmp[i]) {
|
||||
+ if(pcres_tmp) {
|
||||
+ for(i = 0; i < num_pcres_tmp; i++) {
|
||||
+ if(pcres_tmp[i]) {
|
||||
pkg_free(pcres_tmp[i]);
|
||||
}
|
||||
}
|
||||
pkg_free(pcres_tmp);
|
||||
}
|
||||
- if (reload_lock) {
|
||||
+ if(reload_lock) {
|
||||
lock_release(reload_lock);
|
||||
}
|
||||
- if (action == START) {
|
||||
+ if(action == START) {
|
||||
free_shared_memory();
|
||||
}
|
||||
return -1;
|
||||
@@ -486,9 +485,9 @@ static void free_shared_memory(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
- if (pcres) {
|
||||
- for(i=0; i<*num_pcres; i++) {
|
||||
- if (pcres[i]) {
|
||||
+ if(pcres) {
|
||||
+ for(i = 0; i < *num_pcres; i++) {
|
||||
+ if(pcres[i]) {
|
||||
shm_free(pcres[i]);
|
||||
}
|
||||
}
|
||||
@@ -496,21 +495,21 @@ static void free_shared_memory(void)
|
||||
pcres = NULL;
|
||||
}
|
||||
|
||||
- if (num_pcres) {
|
||||
+ if(num_pcres) {
|
||||
shm_free(num_pcres);
|
||||
num_pcres = NULL;
|
||||
}
|
||||
|
||||
- if (pcres_addr) {
|
||||
+ if(pcres_addr) {
|
||||
shm_free(pcres_addr);
|
||||
pcres_addr = NULL;
|
||||
}
|
||||
|
||||
- if (reload_lock) {
|
||||
+ if(reload_lock) {
|
||||
lock_destroy(reload_lock);
|
||||
lock_dealloc(reload_lock);
|
||||
reload_lock = NULL;
|
||||
- }
|
||||
+ }
|
||||
}
|
||||
|
||||
|
||||
@@ -519,32 +518,32 @@ static void free_shared_memory(void)
|
||||
*/
|
||||
|
||||
/*! \brief Return true if the argument matches the regular expression parameter */
|
||||
-static int ki_pcre_match(sip_msg_t* msg, str* string, str* regex)
|
||||
+static int ki_pcre_match(sip_msg_t *msg, str *string, str *regex)
|
||||
{
|
||||
pcre *pcre_re = NULL;
|
||||
int pcre_rc;
|
||||
const char *pcre_error;
|
||||
int pcre_erroffset;
|
||||
|
||||
- pcre_re = pcre_compile(regex->s, pcre_options, &pcre_error, &pcre_erroffset, NULL);
|
||||
- if (pcre_re == NULL) {
|
||||
+ pcre_re = pcre_compile(
|
||||
+ regex->s, pcre_options, &pcre_error, &pcre_erroffset, NULL);
|
||||
+ if(pcre_re == NULL) {
|
||||
LM_ERR("pcre_re compilation of '%s' failed at offset %d: %s\n",
|
||||
regex->s, pcre_erroffset, pcre_error);
|
||||
return -4;
|
||||
}
|
||||
|
||||
- pcre_rc = pcre_exec(
|
||||
- pcre_re, /* the compiled pattern */
|
||||
- NULL, /* no extra data - we didn't study the pattern */
|
||||
- string->s, /* the matching string */
|
||||
- (int)(string->len), /* the length of the subject */
|
||||
- 0, /* start at offset 0 in the string */
|
||||
- 0, /* default options */
|
||||
- NULL, /* output vector for substring information */
|
||||
- 0); /* number of elements in the output vector */
|
||||
+ pcre_rc = pcre_exec(pcre_re, /* the compiled pattern */
|
||||
+ NULL, /* no extra data - we didn't study the pattern */
|
||||
+ string->s, /* the matching string */
|
||||
+ (int)(string->len), /* the length of the subject */
|
||||
+ 0, /* start at offset 0 in the string */
|
||||
+ 0, /* default options */
|
||||
+ NULL, /* output vector for substring information */
|
||||
+ 0); /* number of elements in the output vector */
|
||||
|
||||
/* Matching failed: handle error cases */
|
||||
- if (pcre_rc < 0) {
|
||||
+ if(pcre_rc < 0) {
|
||||
switch(pcre_rc) {
|
||||
case PCRE_ERROR_NOMATCH:
|
||||
LM_DBG("'%s' doesn't match '%s'\n", string->s, regex->s);
|
||||
@@ -562,28 +561,26 @@ static int ki_pcre_match(sip_msg_t* msg,
|
||||
}
|
||||
|
||||
/*! \brief Return true if the argument matches the regular expression parameter */
|
||||
-static int w_pcre_match(struct sip_msg* _msg, char* _s1, char* _s2)
|
||||
+static int w_pcre_match(struct sip_msg *_msg, char *_s1, char *_s2)
|
||||
{
|
||||
str string;
|
||||
str regex;
|
||||
|
||||
- if (_s1 == NULL) {
|
||||
+ if(_s1 == NULL) {
|
||||
LM_ERR("bad parameters\n");
|
||||
return -2;
|
||||
}
|
||||
|
||||
- if (_s2 == NULL) {
|
||||
+ if(_s2 == NULL) {
|
||||
LM_ERR("bad parameters\n");
|
||||
return -2;
|
||||
}
|
||||
|
||||
- if (fixup_get_svalue(_msg, (gparam_p)_s1, &string))
|
||||
- {
|
||||
+ if(fixup_get_svalue(_msg, (gparam_p)_s1, &string)) {
|
||||
LM_ERR("cannot print the format for string\n");
|
||||
return -3;
|
||||
}
|
||||
- if (fixup_get_svalue(_msg, (gparam_p)_s2, ®ex))
|
||||
- {
|
||||
+ if(fixup_get_svalue(_msg, (gparam_p)_s2, ®ex)) {
|
||||
LM_ERR("cannot print the format for regex\n");
|
||||
return -3;
|
||||
}
|
||||
@@ -592,17 +589,17 @@ static int w_pcre_match(struct sip_msg*
|
||||
}
|
||||
|
||||
/*! \brief Return true if the string argument matches the pattern group parameter */
|
||||
-static int ki_pcre_match_group(sip_msg_t* _msg, str* string, int num_pcre)
|
||||
+static int ki_pcre_match_group(sip_msg_t *_msg, str *string, int num_pcre)
|
||||
{
|
||||
int pcre_rc;
|
||||
|
||||
/* Check if group matching feature is enabled */
|
||||
- if (file == NULL) {
|
||||
+ if(file == NULL) {
|
||||
LM_ERR("group matching is disabled\n");
|
||||
return -2;
|
||||
}
|
||||
|
||||
- if (num_pcre >= *num_pcres) {
|
||||
+ if(num_pcre >= *num_pcres) {
|
||||
LM_ERR("invalid pcre index '%i', there are %i pcres\n", num_pcre,
|
||||
*num_pcres);
|
||||
return -4;
|
||||
@@ -610,20 +607,19 @@ static int ki_pcre_match_group(sip_msg_t
|
||||
|
||||
lock_get(reload_lock);
|
||||
|
||||
- pcre_rc = pcre_exec(
|
||||
- (*pcres_addr)[num_pcre], /* the compiled pattern */
|
||||
- NULL, /* no extra data - we didn't study the pattern */
|
||||
- string->s, /* the matching string */
|
||||
- (int)(string->len), /* the length of the subject */
|
||||
- 0, /* start at offset 0 in the string */
|
||||
- 0, /* default options */
|
||||
- NULL, /* output vector for substring information */
|
||||
- 0); /* number of elements in the output vector */
|
||||
+ pcre_rc = pcre_exec((*pcres_addr)[num_pcre], /* the compiled pattern */
|
||||
+ NULL, /* no extra data - we didn't study the pattern */
|
||||
+ string->s, /* the matching string */
|
||||
+ (int)(string->len), /* the length of the subject */
|
||||
+ 0, /* start at offset 0 in the string */
|
||||
+ 0, /* default options */
|
||||
+ NULL, /* output vector for substring information */
|
||||
+ 0); /* number of elements in the output vector */
|
||||
|
||||
lock_release(reload_lock);
|
||||
|
||||
/* Matching failed: handle error cases */
|
||||
- if (pcre_rc < 0) {
|
||||
+ if(pcre_rc < 0) {
|
||||
switch(pcre_rc) {
|
||||
case PCRE_ERROR_NOMATCH:
|
||||
LM_DBG("'%s' doesn't match pcres[%i]\n", string->s, num_pcre);
|
||||
@@ -640,29 +636,27 @@ static int ki_pcre_match_group(sip_msg_t
|
||||
}
|
||||
|
||||
/*! \brief Return true if the string argument matches the pattern group parameter */
|
||||
-static int w_pcre_match_group(struct sip_msg* _msg, char* _s1, char* _s2)
|
||||
+static int w_pcre_match_group(struct sip_msg *_msg, char *_s1, char *_s2)
|
||||
{
|
||||
str string, group;
|
||||
unsigned int num_pcre = 0;
|
||||
|
||||
- if (_s1 == NULL) {
|
||||
+ if(_s1 == NULL) {
|
||||
LM_ERR("bad parameters\n");
|
||||
return -3;
|
||||
}
|
||||
|
||||
- if (_s2 == NULL) {
|
||||
+ if(_s2 == NULL) {
|
||||
num_pcre = 0;
|
||||
} else {
|
||||
- if (fixup_get_svalue(_msg, (gparam_p)_s2, &group))
|
||||
- {
|
||||
+ if(fixup_get_svalue(_msg, (gparam_p)_s2, &group)) {
|
||||
LM_ERR("cannot print the format for second param\n");
|
||||
return -5;
|
||||
}
|
||||
str2int(&group, &num_pcre);
|
||||
}
|
||||
|
||||
- if (fixup_get_svalue(_msg, (gparam_p)_s1, &string))
|
||||
- {
|
||||
+ if(fixup_get_svalue(_msg, (gparam_p)_s1, &string)) {
|
||||
LM_ERR("cannot print the format for first param\n");
|
||||
return -5;
|
||||
}
|
||||
@@ -676,42 +670,35 @@ static int w_pcre_match_group(struct sip
|
||||
*/
|
||||
|
||||
/*! \brief Reload pcres by reading the file again */
|
||||
-void regex_rpc_reload(rpc_t* rpc, void* ctx)
|
||||
+void regex_rpc_reload(rpc_t *rpc, void *ctx)
|
||||
{
|
||||
/* Check if group matching feature is enabled */
|
||||
- if (file == NULL) {
|
||||
+ if(file == NULL) {
|
||||
LM_NOTICE("'file' parameter is not set, group matching disabled\n");
|
||||
rpc->fault(ctx, 500, "Group matching not enabled");
|
||||
return;
|
||||
}
|
||||
LM_INFO("reloading pcres...\n");
|
||||
- if (load_pcres(RELOAD)) {
|
||||
+ if(load_pcres(RELOAD)) {
|
||||
LM_ERR("failed to reload pcres\n");
|
||||
rpc->fault(ctx, 500, "Failed to reload");
|
||||
return;
|
||||
}
|
||||
LM_INFO("reload success\n");
|
||||
-
|
||||
}
|
||||
|
||||
-static const char* regex_rpc_reload_doc[2] = {
|
||||
- "Reload regex file",
|
||||
- 0
|
||||
-};
|
||||
+static const char *regex_rpc_reload_doc[2] = {"Reload regex file", 0};
|
||||
|
||||
rpc_export_t regex_rpc_cmds[] = {
|
||||
- {"regex.reload", regex_rpc_reload,
|
||||
- regex_rpc_reload_doc, 0},
|
||||
- {0, 0, 0, 0}
|
||||
-};
|
||||
+ {"regex.reload", regex_rpc_reload, regex_rpc_reload_doc, 0},
|
||||
+ {0, 0, 0, 0}};
|
||||
|
||||
/**
|
||||
* register RPC commands
|
||||
*/
|
||||
static int regex_init_rpc(void)
|
||||
{
|
||||
- if (rpc_register_array(regex_rpc_cmds)!=0)
|
||||
- {
|
||||
+ if(rpc_register_array(regex_rpc_cmds) != 0) {
|
||||
LM_ERR("failed to register RPC commands\n");
|
||||
return -1;
|
||||
}
|
39
net/kamailio/patches/031-regex-typos.patch
Normal file
39
net/kamailio/patches/031-regex-typos.patch
Normal file
@ -0,0 +1,39 @@
|
||||
From 650b109dbcfe2c3083e09c987bae7ca39e4a19d2 Mon Sep 17 00:00:00 2001
|
||||
From: =?UTF-8?q?=D0=94=D0=B8=D0=BB=D1=8F=D0=BD=20=D0=9F=D0=B0=D0=BB=D0=B0?=
|
||||
=?UTF-8?q?=D1=83=D0=B7=D0=BE=D0=B2?= <git-dpa@aegee.org>
|
||||
Date: Wed, 21 Jun 2023 21:34:21 +0200
|
||||
Subject: [PATCH] regex: typos
|
||||
|
||||
---
|
||||
src/modules/regex/regex_mod.c | 6 +++---
|
||||
1 file changed, 3 insertions(+), 3 deletions(-)
|
||||
|
||||
--- a/src/modules/regex/regex_mod.c
|
||||
+++ b/src/modules/regex/regex_mod.c
|
||||
@@ -230,7 +230,7 @@ static void destroy(void)
|
||||
}
|
||||
|
||||
|
||||
-/*! \brief Convert the file content into regular expresions and store them in pcres */
|
||||
+/*! \brief Convert the file content into regular expressions and store them in pcres */
|
||||
static int load_pcres(int action)
|
||||
{
|
||||
int i, j;
|
||||
@@ -307,7 +307,7 @@ static int load_pcres(int action)
|
||||
}
|
||||
|
||||
llen = strlen(line);
|
||||
- /* Check if the patter size is too big (aprox) */
|
||||
+ /* Check if the pattern size is too big (approx) */
|
||||
if(strlen(patterns[i]) + llen >= group_max_size - 4) {
|
||||
LM_ERR("pattern max file exceeded\n");
|
||||
fclose(f);
|
||||
@@ -387,7 +387,7 @@ static int load_pcres(int action)
|
||||
pcres_tmp[i] = NULL;
|
||||
}
|
||||
|
||||
- /* Compile the patters */
|
||||
+ /* Compile the patterns */
|
||||
for(i = 0; i < num_pcres_tmp; i++) {
|
||||
|
||||
pcre_tmp = pcre_compile(
|
@ -0,0 +1,44 @@
|
||||
From 5c7de00bc0826cf739577010ba7b4882e83819cc Mon Sep 17 00:00:00 2001
|
||||
From: Victor Seva <linuxmaniac@torreviejawireless.org>
|
||||
Date: Wed, 9 Aug 2023 10:52:47 +0000
|
||||
Subject: [PATCH] regex: convert to memory error logging helper
|
||||
|
||||
---
|
||||
src/modules/regex/regex_mod.c | 8 ++++----
|
||||
1 file changed, 4 insertions(+), 4 deletions(-)
|
||||
|
||||
--- a/src/modules/regex/regex_mod.c
|
||||
+++ b/src/modules/regex/regex_mod.c
|
||||
@@ -198,13 +198,13 @@ static int mod_init(void)
|
||||
|
||||
/* Pointer to pcres */
|
||||
if((pcres_addr = shm_malloc(sizeof(pcre **))) == 0) {
|
||||
- LM_ERR("no memory for pcres_addr\n");
|
||||
+ SHM_MEM_ERROR;
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* Integer containing the number of pcres */
|
||||
if((num_pcres = shm_malloc(sizeof(int))) == 0) {
|
||||
- LM_ERR("no memory for num_pcres\n");
|
||||
+ SHM_MEM_ERROR;
|
||||
goto err;
|
||||
}
|
||||
|
||||
@@ -425,14 +425,14 @@ static int load_pcres(int action)
|
||||
shm_free(pcres);
|
||||
}
|
||||
if((pcres = shm_malloc(sizeof(pcre *) * num_pcres_tmp)) == 0) {
|
||||
- LM_ERR("no more memory for pcres\n");
|
||||
+ SHM_MEM_ERROR;
|
||||
goto err;
|
||||
}
|
||||
memset(pcres, 0, sizeof(pcre *) * num_pcres_tmp);
|
||||
for(i = 0; i < num_pcres_tmp; i++) {
|
||||
pcre_rc = pcre_fullinfo(pcres_tmp[i], NULL, PCRE_INFO_SIZE, &pcre_size);
|
||||
if((pcres[i] = shm_malloc(pcre_size)) == 0) {
|
||||
- LM_ERR("no more memory for pcres[%i]\n", i);
|
||||
+ SHM_MEM_ERROR;
|
||||
goto err;
|
||||
}
|
||||
memcpy(pcres[i], pcres_tmp[i], pcre_size);
|
433
net/kamailio/patches/033-regex-migration-to-pcre2.patch
Normal file
433
net/kamailio/patches/033-regex-migration-to-pcre2.patch
Normal file
@ -0,0 +1,433 @@
|
||||
From 325c7a34fca74770a4351e00e27fcae75d57852e Mon Sep 17 00:00:00 2001
|
||||
From: Victor Seva <linuxmaniac@torreviejawireless.org>
|
||||
Date: Wed, 9 Aug 2023 10:48:41 +0000
|
||||
Subject: [PATCH] regex: migration to pcre2
|
||||
|
||||
---
|
||||
src/modules/regex/Makefile | 11 +-
|
||||
src/modules/regex/regex_mod.c | 240 ++++++++++++++++++++++------------
|
||||
2 files changed, 158 insertions(+), 93 deletions(-)
|
||||
|
||||
--- a/src/modules/regex/Makefile
|
||||
+++ b/src/modules/regex/Makefile
|
||||
@@ -5,20 +5,15 @@ auto_gen=
|
||||
NAME=regex.so
|
||||
|
||||
ifeq ($(CROSS_COMPILE),)
|
||||
-PCRE_BUILDER = $(shell \
|
||||
- if pkg-config --exists libcre; then \
|
||||
- echo 'pkg-config libpcre'; \
|
||||
- else \
|
||||
- which pcre-config; \
|
||||
- fi)
|
||||
+PCRE_BUILDER = $(shell command -v pcre2-config)
|
||||
endif
|
||||
|
||||
ifeq ($(PCRE_BUILDER),)
|
||||
PCREDEFS=-I$(LOCALBASE)/include
|
||||
- PCRELIBS=-L$(LOCALBASE)/lib -lpcre
|
||||
+ PCRELIBS=-L$(LOCALBASE)/lib -lpcre2-8
|
||||
else
|
||||
PCREDEFS = $(shell $(PCRE_BUILDER) --cflags)
|
||||
- PCRELIBS = $(shell $(PCRE_BUILDER) --libs)
|
||||
+ PCRELIBS = $(shell $(PCRE_BUILDER) --libs8)
|
||||
endif
|
||||
|
||||
DEFS+=$(PCREDEFS)
|
||||
--- a/src/modules/regex/regex_mod.c
|
||||
+++ b/src/modules/regex/regex_mod.c
|
||||
@@ -2,6 +2,7 @@
|
||||
* regex module - pcre operations
|
||||
*
|
||||
* Copyright (C) 2008 Iñaki Baz Castillo
|
||||
+ * Copyright (C) 2023 Victor Seva
|
||||
*
|
||||
* This file is part of Kamailio, a free SIP server.
|
||||
*
|
||||
@@ -25,6 +26,7 @@
|
||||
* \file
|
||||
* \brief REGEX :: Perl-compatible regular expressions using PCRE library
|
||||
* Copyright (C) 2008 Iñaki Baz Castillo
|
||||
+ * Copyright (C) 2023 Victor Seva
|
||||
* \ingroup regex
|
||||
*/
|
||||
|
||||
@@ -32,7 +34,8 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
-#include <pcre.h>
|
||||
+#define PCRE2_CODE_UNIT_WIDTH 8
|
||||
+#include <pcre2.h>
|
||||
#include "../../core/sr_module.h"
|
||||
#include "../../core/dprint.h"
|
||||
#include "../../core/pt.h"
|
||||
@@ -77,8 +80,11 @@ static int pcre_extended = 0;
|
||||
/*
|
||||
* Module internal parameter variables
|
||||
*/
|
||||
-static pcre **pcres;
|
||||
-static pcre ***pcres_addr;
|
||||
+static pcre2_general_context *pcres_gctx = NULL;
|
||||
+static pcre2_match_context *pcres_mctx = NULL;
|
||||
+static pcre2_compile_context *pcres_ctx = NULL;
|
||||
+static pcre2_code **pcres;
|
||||
+static pcre2_code ***pcres_addr;
|
||||
static int *num_pcres;
|
||||
static int pcre_options = 0x00000000;
|
||||
|
||||
@@ -151,6 +157,17 @@ struct module_exports exports = {
|
||||
};
|
||||
|
||||
|
||||
+static void *pcre2_malloc(size_t size, void *ext)
|
||||
+{
|
||||
+ return shm_malloc(size);
|
||||
+}
|
||||
+
|
||||
+static void pcre2_free(void *ptr, void *ext)
|
||||
+{
|
||||
+ shm_free(ptr);
|
||||
+ ptr = NULL;
|
||||
+}
|
||||
+
|
||||
/*! \brief
|
||||
* Init module function
|
||||
*/
|
||||
@@ -180,24 +197,39 @@ static int mod_init(void)
|
||||
/* PCRE options */
|
||||
if(pcre_caseless != 0) {
|
||||
LM_DBG("PCRE CASELESS enabled\n");
|
||||
- pcre_options = pcre_options | PCRE_CASELESS;
|
||||
+ pcre_options = pcre_options | PCRE2_CASELESS;
|
||||
}
|
||||
if(pcre_multiline != 0) {
|
||||
LM_DBG("PCRE MULTILINE enabled\n");
|
||||
- pcre_options = pcre_options | PCRE_MULTILINE;
|
||||
+ pcre_options = pcre_options | PCRE2_MULTILINE;
|
||||
}
|
||||
if(pcre_dotall != 0) {
|
||||
LM_DBG("PCRE DOTALL enabled\n");
|
||||
- pcre_options = pcre_options | PCRE_DOTALL;
|
||||
+ pcre_options = pcre_options | PCRE2_DOTALL;
|
||||
}
|
||||
if(pcre_extended != 0) {
|
||||
LM_DBG("PCRE EXTENDED enabled\n");
|
||||
- pcre_options = pcre_options | PCRE_EXTENDED;
|
||||
+ pcre_options = pcre_options | PCRE2_EXTENDED;
|
||||
}
|
||||
LM_DBG("PCRE options: %i\n", pcre_options);
|
||||
|
||||
+ if((pcres_gctx = pcre2_general_context_create(
|
||||
+ pcre2_malloc, pcre2_free, NULL))
|
||||
+ == NULL) {
|
||||
+ LM_ERR("pcre2 general context creation failed\n");
|
||||
+ return -1;
|
||||
+ }
|
||||
+ if((pcres_ctx = pcre2_compile_context_create(pcres_gctx)) == NULL) {
|
||||
+ LM_ERR("pcre2 compile context creation failed\n");
|
||||
+ return -1;
|
||||
+ }
|
||||
+ if((pcres_mctx = pcre2_match_context_create(pcres_gctx)) == NULL) {
|
||||
+ LM_ERR("pcre2 match context creation failed\n");
|
||||
+ return -1;
|
||||
+ }
|
||||
+
|
||||
/* Pointer to pcres */
|
||||
- if((pcres_addr = shm_malloc(sizeof(pcre **))) == 0) {
|
||||
+ if((pcres_addr = shm_malloc(sizeof(pcre2_code **))) == 0) {
|
||||
SHM_MEM_ERROR;
|
||||
goto err;
|
||||
}
|
||||
@@ -227,6 +259,18 @@ err:
|
||||
static void destroy(void)
|
||||
{
|
||||
free_shared_memory();
|
||||
+
|
||||
+ if(pcres_ctx) {
|
||||
+ pcre2_compile_context_free(pcres_ctx);
|
||||
+ }
|
||||
+
|
||||
+ if(pcres_mctx) {
|
||||
+ pcre2_match_context_free(pcres_mctx);
|
||||
+ }
|
||||
+
|
||||
+ if(pcres_gctx) {
|
||||
+ pcre2_general_context_free(pcres_gctx);
|
||||
+ }
|
||||
}
|
||||
|
||||
|
||||
@@ -237,13 +281,11 @@ static int load_pcres(int action)
|
||||
FILE *f;
|
||||
char line[FILE_MAX_LINE];
|
||||
char **patterns = NULL;
|
||||
- pcre *pcre_tmp = NULL;
|
||||
- size_t pcre_size;
|
||||
- int pcre_rc;
|
||||
- const char *pcre_error;
|
||||
- int pcre_erroffset;
|
||||
+ int pcre_error_num = 0;
|
||||
+ char pcre_error[128];
|
||||
+ size_t pcre_erroffset;
|
||||
int num_pcres_tmp = 0;
|
||||
- pcre **pcres_tmp = NULL;
|
||||
+ pcre2_code **pcres_tmp = NULL;
|
||||
int llen;
|
||||
|
||||
/* Get the lock */
|
||||
@@ -379,38 +421,34 @@ static int load_pcres(int action)
|
||||
}
|
||||
|
||||
/* Temporal pointer of pcres */
|
||||
- if((pcres_tmp = pkg_malloc(sizeof(pcre *) * num_pcres_tmp)) == 0) {
|
||||
+ if((pcres_tmp = pkg_malloc(sizeof(pcre2_code *) * num_pcres_tmp)) == 0) {
|
||||
LM_ERR("no more memory for pcres_tmp\n");
|
||||
goto err;
|
||||
}
|
||||
- for(i = 0; i < num_pcres_tmp; i++) {
|
||||
- pcres_tmp[i] = NULL;
|
||||
- }
|
||||
+ memset(pcres_tmp, 0, sizeof(pcre2_code *) * num_pcres_tmp);
|
||||
|
||||
/* Compile the patterns */
|
||||
for(i = 0; i < num_pcres_tmp; i++) {
|
||||
-
|
||||
- pcre_tmp = pcre_compile(
|
||||
- patterns[i], pcre_options, &pcre_error, &pcre_erroffset, NULL);
|
||||
- if(pcre_tmp == NULL) {
|
||||
- LM_ERR("pcre_tmp compilation of '%s' failed at offset %d: %s\n",
|
||||
+ pcres_tmp[i] = pcre2_compile((PCRE2_SPTR)patterns[i],
|
||||
+ PCRE2_ZERO_TERMINATED, pcre_options, &pcre_error_num,
|
||||
+ &pcre_erroffset, pcres_ctx);
|
||||
+ if(pcres_tmp[i] == NULL) {
|
||||
+ switch(pcre2_get_error_message(
|
||||
+ pcre_error_num, (PCRE2_UCHAR *)pcre_error, 128)) {
|
||||
+ case PCRE2_ERROR_NOMEMORY:
|
||||
+ snprintf(pcre_error, 128,
|
||||
+ "unknown error[%d]: pcre2 error buffer too small",
|
||||
+ pcre_error_num);
|
||||
+ break;
|
||||
+ case PCRE2_ERROR_BADDATA:
|
||||
+ snprintf(pcre_error, 128, "unknown pcre2 error[%d]",
|
||||
+ pcre_error_num);
|
||||
+ break;
|
||||
+ }
|
||||
+ LM_ERR("pcre_tmp compilation of '%s' failed at offset %zu: %s\n",
|
||||
patterns[i], pcre_erroffset, pcre_error);
|
||||
goto err;
|
||||
}
|
||||
- pcre_rc = pcre_fullinfo(pcre_tmp, NULL, PCRE_INFO_SIZE, &pcre_size);
|
||||
- if(pcre_rc) {
|
||||
- printf("pcre_fullinfo on compiled pattern[%i] yielded error: %d\n",
|
||||
- i, pcre_rc);
|
||||
- goto err;
|
||||
- }
|
||||
-
|
||||
- if((pcres_tmp[i] = pkg_malloc(pcre_size)) == 0) {
|
||||
- LM_ERR("no more memory for pcres_tmp[%i]\n", i);
|
||||
- goto err;
|
||||
- }
|
||||
-
|
||||
- memcpy(pcres_tmp[i], pcre_tmp, pcre_size);
|
||||
- pcre_free(pcre_tmp);
|
||||
pkg_free(patterns[i]);
|
||||
patterns[i] = NULL;
|
||||
}
|
||||
@@ -419,31 +457,15 @@ static int load_pcres(int action)
|
||||
if(action == RELOAD) {
|
||||
for(i = 0; i < *num_pcres; i++) { /* Use the previous num_pcres value */
|
||||
if(pcres[i]) {
|
||||
- shm_free(pcres[i]);
|
||||
+ pcre2_code_free(pcres[i]);
|
||||
}
|
||||
}
|
||||
shm_free(pcres);
|
||||
}
|
||||
- if((pcres = shm_malloc(sizeof(pcre *) * num_pcres_tmp)) == 0) {
|
||||
- SHM_MEM_ERROR;
|
||||
- goto err;
|
||||
- }
|
||||
- memset(pcres, 0, sizeof(pcre *) * num_pcres_tmp);
|
||||
- for(i = 0; i < num_pcres_tmp; i++) {
|
||||
- pcre_rc = pcre_fullinfo(pcres_tmp[i], NULL, PCRE_INFO_SIZE, &pcre_size);
|
||||
- if((pcres[i] = shm_malloc(pcre_size)) == 0) {
|
||||
- SHM_MEM_ERROR;
|
||||
- goto err;
|
||||
- }
|
||||
- memcpy(pcres[i], pcres_tmp[i], pcre_size);
|
||||
- }
|
||||
*num_pcres = num_pcres_tmp;
|
||||
+ *pcres = *pcres_tmp;
|
||||
*pcres_addr = pcres;
|
||||
|
||||
- /* Free used memory */
|
||||
- for(i = 0; i < num_pcres_tmp; i++) {
|
||||
- pkg_free(pcres_tmp[i]);
|
||||
- }
|
||||
pkg_free(pcres_tmp);
|
||||
/* Free allocated slots for unused patterns */
|
||||
for(i = num_pcres_tmp; i < max_groups; i++) {
|
||||
@@ -466,7 +488,7 @@ err:
|
||||
if(pcres_tmp) {
|
||||
for(i = 0; i < num_pcres_tmp; i++) {
|
||||
if(pcres_tmp[i]) {
|
||||
- pkg_free(pcres_tmp[i]);
|
||||
+ pcre2_code_free(pcres_tmp[i]);
|
||||
}
|
||||
}
|
||||
pkg_free(pcres_tmp);
|
||||
@@ -520,42 +542,73 @@ static void free_shared_memory(void)
|
||||
/*! \brief Return true if the argument matches the regular expression parameter */
|
||||
static int ki_pcre_match(sip_msg_t *msg, str *string, str *regex)
|
||||
{
|
||||
- pcre *pcre_re = NULL;
|
||||
+ pcre2_code *pcre_re = NULL;
|
||||
+ pcre2_match_data *pcre_md = NULL;
|
||||
int pcre_rc;
|
||||
- const char *pcre_error;
|
||||
- int pcre_erroffset;
|
||||
+ int pcre_error_num = 0;
|
||||
+ char pcre_error[128];
|
||||
+ size_t pcre_erroffset;
|
||||
|
||||
- pcre_re = pcre_compile(
|
||||
- regex->s, pcre_options, &pcre_error, &pcre_erroffset, NULL);
|
||||
+ pcre_re = pcre2_compile((PCRE2_SPTR)regex->s, PCRE2_ZERO_TERMINATED,
|
||||
+ pcre_options, &pcre_error_num, &pcre_erroffset, pcres_ctx);
|
||||
if(pcre_re == NULL) {
|
||||
- LM_ERR("pcre_re compilation of '%s' failed at offset %d: %s\n",
|
||||
+ switch(pcre2_get_error_message(
|
||||
+ pcre_error_num, (PCRE2_UCHAR *)pcre_error, 128)) {
|
||||
+ case PCRE2_ERROR_NOMEMORY:
|
||||
+ snprintf(pcre_error, 128,
|
||||
+ "unknown error[%d]: pcre2 error buffer too small",
|
||||
+ pcre_error_num);
|
||||
+ break;
|
||||
+ case PCRE2_ERROR_BADDATA:
|
||||
+ snprintf(pcre_error, 128, "unknown pcre2 error[%d]",
|
||||
+ pcre_error_num);
|
||||
+ break;
|
||||
+ }
|
||||
+ LM_ERR("pcre_re compilation of '%s' failed at offset %zu: %s\n",
|
||||
regex->s, pcre_erroffset, pcre_error);
|
||||
return -4;
|
||||
}
|
||||
|
||||
- pcre_rc = pcre_exec(pcre_re, /* the compiled pattern */
|
||||
- NULL, /* no extra data - we didn't study the pattern */
|
||||
- string->s, /* the matching string */
|
||||
- (int)(string->len), /* the length of the subject */
|
||||
- 0, /* start at offset 0 in the string */
|
||||
- 0, /* default options */
|
||||
- NULL, /* output vector for substring information */
|
||||
- 0); /* number of elements in the output vector */
|
||||
+ pcre_md = pcre2_match_data_create_from_pattern(pcre_re, pcres_gctx);
|
||||
+ pcre_rc = pcre2_match(pcre_re, /* the compiled pattern */
|
||||
+ (PCRE2_SPTR)string->s, /* the matching string */
|
||||
+ (PCRE2_SIZE)(string->len), /* the length of the subject */
|
||||
+ 0, /* start at offset 0 in the string */
|
||||
+ 0, /* default options */
|
||||
+ pcre_md, /* the match data block */
|
||||
+ pcres_mctx); /* a match context; NULL means use defaults */
|
||||
|
||||
/* Matching failed: handle error cases */
|
||||
if(pcre_rc < 0) {
|
||||
switch(pcre_rc) {
|
||||
- case PCRE_ERROR_NOMATCH:
|
||||
+ case PCRE2_ERROR_NOMATCH:
|
||||
LM_DBG("'%s' doesn't match '%s'\n", string->s, regex->s);
|
||||
break;
|
||||
default:
|
||||
- LM_DBG("matching error '%d'\n", pcre_rc);
|
||||
+ switch(pcre2_get_error_message(
|
||||
+ pcre_rc, (PCRE2_UCHAR *)pcre_error, 128)) {
|
||||
+ case PCRE2_ERROR_NOMEMORY:
|
||||
+ snprintf(pcre_error, 128,
|
||||
+ "unknown error[%d]: pcre2 error buffer too "
|
||||
+ "small",
|
||||
+ pcre_rc);
|
||||
+ break;
|
||||
+ case PCRE2_ERROR_BADDATA:
|
||||
+ snprintf(pcre_error, 128, "unknown pcre2 error[%d]",
|
||||
+ pcre_rc);
|
||||
+ break;
|
||||
+ }
|
||||
+ LM_ERR("matching error:'%s' failed[%d]\n", pcre_error, pcre_rc);
|
||||
break;
|
||||
}
|
||||
- pcre_free(pcre_re);
|
||||
+ if(pcre_md)
|
||||
+ pcre2_match_data_free(pcre_md);
|
||||
+ pcre2_code_free(pcre_re);
|
||||
return -1;
|
||||
}
|
||||
- pcre_free(pcre_re);
|
||||
+ if(pcre_md)
|
||||
+ pcre2_match_data_free(pcre_md);
|
||||
+ pcre2_code_free(pcre_re);
|
||||
LM_DBG("'%s' matches '%s'\n", string->s, regex->s);
|
||||
return 1;
|
||||
}
|
||||
@@ -592,6 +645,8 @@ static int w_pcre_match(struct sip_msg *
|
||||
static int ki_pcre_match_group(sip_msg_t *_msg, str *string, int num_pcre)
|
||||
{
|
||||
int pcre_rc;
|
||||
+ pcre2_match_data *pcre_md = NULL;
|
||||
+ char pcre_error[128];
|
||||
|
||||
/* Check if group matching feature is enabled */
|
||||
if(file == NULL) {
|
||||
@@ -606,26 +661,41 @@ static int ki_pcre_match_group(sip_msg_t
|
||||
}
|
||||
|
||||
lock_get(reload_lock);
|
||||
-
|
||||
- pcre_rc = pcre_exec((*pcres_addr)[num_pcre], /* the compiled pattern */
|
||||
- NULL, /* no extra data - we didn't study the pattern */
|
||||
- string->s, /* the matching string */
|
||||
- (int)(string->len), /* the length of the subject */
|
||||
- 0, /* start at offset 0 in the string */
|
||||
- 0, /* default options */
|
||||
- NULL, /* output vector for substring information */
|
||||
- 0); /* number of elements in the output vector */
|
||||
+ pcre_md = pcre2_match_data_create_from_pattern(
|
||||
+ (*pcres_addr)[num_pcre], pcres_gctx);
|
||||
+ pcre_rc = pcre2_match((*pcres_addr)[num_pcre], /* the compiled pattern */
|
||||
+ (PCRE2_SPTR)string->s, /* the matching string */
|
||||
+ (PCRE2_SIZE)(string->len), /* the length of the subject */
|
||||
+ 0, /* start at offset 0 in the string */
|
||||
+ 0, /* default options */
|
||||
+ pcre_md, /* the match data block */
|
||||
+ pcres_mctx); /* a match context; NULL means use defaults */
|
||||
|
||||
lock_release(reload_lock);
|
||||
+ if(pcre_md)
|
||||
+ pcre2_match_data_free(pcre_md);
|
||||
|
||||
/* Matching failed: handle error cases */
|
||||
if(pcre_rc < 0) {
|
||||
switch(pcre_rc) {
|
||||
- case PCRE_ERROR_NOMATCH:
|
||||
+ case PCRE2_ERROR_NOMATCH:
|
||||
LM_DBG("'%s' doesn't match pcres[%i]\n", string->s, num_pcre);
|
||||
break;
|
||||
default:
|
||||
- LM_DBG("matching error '%d'\n", pcre_rc);
|
||||
+ switch(pcre2_get_error_message(
|
||||
+ pcre_rc, (PCRE2_UCHAR *)pcre_error, 128)) {
|
||||
+ case PCRE2_ERROR_NOMEMORY:
|
||||
+ snprintf(pcre_error, 128,
|
||||
+ "unknown error[%d]: pcre2 error buffer too "
|
||||
+ "small",
|
||||
+ pcre_rc);
|
||||
+ break;
|
||||
+ case PCRE2_ERROR_BADDATA:
|
||||
+ snprintf(pcre_error, 128, "unknown pcre2 error[%d]",
|
||||
+ pcre_rc);
|
||||
+ break;
|
||||
+ }
|
||||
+ LM_ERR("matching error:'%s' failed[%d]\n", pcre_error, pcre_rc);
|
||||
break;
|
||||
}
|
||||
return -1;
|
Loading…
Reference in New Issue
Block a user