Skip to content

Commit b439e6d

Browse files
Merge remote-tracking branch 'refs/remotes/origin/0.0.5' into 0.0.5
2 parents 796f67f + 98eb916 commit b439e6d

4 files changed

Lines changed: 63 additions & 9 deletions

File tree

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
[![OSS-Fuzz](https://github.com/OpenSIPS/opensips/actions/workflows/cifuzz.yml/badge.svg?branch=master)](https://github.com/OpenSIPS/opensips/actions/workflows/cifuzz.yml?query=branch%3Amaster++)
44
[![Cross Platform Builds](https://github.com/OpenSIPS/opensips/actions/workflows/multiarch.yml/badge.svg?branch=master)](https://github.com/OpenSIPS/opensips/actions/workflows/multiarch.yml?query=branch%3Amaster++)
55
[![Coverity Scan Build Status](https://scan.coverity.com/projects/7580/badge.svg)](https://scan.coverity.com/projects/opensips-opensips)
6-
[![Code Quality: Cpp](https://img.shields.io/lgtm/grade/cpp/g/OpenSIPS/opensips.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/OpenSIPS/opensips/context:cpp)
7-
[![Total Alerts](https://img.shields.io/lgtm/alerts/g/OpenSIPS/opensips.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/OpenSIPS/opensips/alerts)
86

97
# Welcome to OpenSIPS Project
108

modules/regex/regex_mod.c

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,36 @@
4040
#include <stdlib.h>
4141
#include <string.h>
4242
#include <sys/stat.h>
43+
#ifdef PCRE2_LIB
4344
#define PCRE2_CODE_UNIT_WIDTH 8
45+
#define PCRE2_ERR int
4446
#include <pcre2.h>
47+
#else
48+
#define pcre2_code pcre
49+
#define PCRE2_SIZE int
50+
#define PCRE2_ERR const char *
51+
#define PCRE2_CASELESS PCRE_CASELESS
52+
#define PCRE2_MULTILINE PCRE_MULTILINE
53+
#define PCRE2_DOTALL PCRE_DOTALL
54+
#define PCRE2_EXTENDED PCRE_EXTENDED
55+
#define PCRE2_ERROR_NOMATCH PCRE_ERROR_NOMATCH
56+
#define PCRE2_UCHAR unsigned char
57+
#define PCRE2_SPTR char *
58+
#define pcre2_pattern_info(subst_comp, flag, ret) \
59+
pcre_fullinfo(subst_comp, NULL, PCRE_INFO_CAPTURECOUNT, ret);
60+
#define pcre2_compile(pattern, _, flags, error, erroffset, ctx) \
61+
pcre_compile(pattern, flags, error, erroffset, NULL)
62+
#define pcre2_code_free pcre_free
63+
#define pcre2_get_error_message(error, error_str, error_str_len) \
64+
do { \
65+
int _len = strlen(error); \
66+
if (_len > error_str_len - 1) \
67+
_len = error_str_len - 1; \
68+
memcpy(error_str, error, _len); \
69+
error_str[_len] = '\0'; \
70+
} while (0)
71+
#include <pcre.h>
72+
#endif
4573
#include "../../sr_module.h"
4674
#include "../../dprint.h"
4775
#include "../../pt.h"
@@ -284,7 +312,7 @@ static int load_pcres(int action)
284312
pcre2_code *pcre_tmp = NULL;
285313
size_t pcre_size;
286314
int pcre_rc;
287-
int pcre_error;
315+
PCRE2_ERR pcre_error;
288316
PCRE2_UCHAR pcre_error_str[ERROR_BUF_SIZE];
289317
PCRE2_SIZE pcre_erroffset;
290318
int num_pcres_tmp = 0;
@@ -437,7 +465,7 @@ static int load_pcres(int action)
437465
pcre_tmp = pcre2_compile((PCRE2_SPTR)patterns[i], PCRE2_ZERO_TERMINATED, pcre_options, &pcre_error, &pcre_erroffset, NULL);
438466
if (pcre_tmp == NULL) {
439467
pcre2_get_error_message(pcre_error, pcre_error_str, sizeof(pcre_error_str));
440-
LM_ERR("pcre_tmp compilation of '%s' failed at offset %zu: %s\n", patterns[i], pcre_erroffset, pcre_error_str);
468+
LM_ERR("pcre_tmp compilation of '%s' failed at offset %lu: %s\n", patterns[i], (unsigned long)pcre_erroffset, pcre_error_str);
441469
goto err;
442470
}
443471
pcre_rc = pcre2_pattern_info(pcre_tmp, PCRE2_INFO_SIZE, &pcre_size);
@@ -561,10 +589,12 @@ static int w_pcre_match(struct sip_msg* _msg, str* string, str* _regex_s)
561589
{
562590
pcre2_code *pcre_re = NULL;
563591
int pcre_rc;
564-
int pcre_error;
592+
PCRE2_ERR pcre_error;
565593
PCRE2_UCHAR pcre_error_str[ERROR_BUF_SIZE];
566594
PCRE2_SIZE pcre_erroffset;
595+
#ifdef PCRE2_LIB
567596
pcre2_match_data *match_data;
597+
#endif
568598
str regex;
569599

570600
if (pkg_nt_str_dup(&regex, _regex_s) < 0)
@@ -573,11 +603,22 @@ static int w_pcre_match(struct sip_msg* _msg, str* string, str* _regex_s)
573603
pcre_re = pcre2_compile((PCRE2_SPTR)regex.s, PCRE2_ZERO_TERMINATED, pcre_options, &pcre_error, &pcre_erroffset, NULL);
574604
if (pcre_re == NULL) {
575605
pcre2_get_error_message(pcre_error, pcre_error_str, sizeof(pcre_error_str));
576-
LM_ERR("pcre_re compilation of '%s' failed at offset %zu: %s\n", regex.s, pcre_erroffset, pcre_error_str);
606+
LM_ERR("pcre_re compilation of '%s' failed at offset %lu: %s\n", regex.s, (unsigned long)pcre_erroffset, pcre_error_str);
577607
pkg_free(regex.s);
578608
return -4;
579609
}
580610

611+
#ifndef PCRE2_LIB
612+
pcre_rc = pcre_exec(
613+
pcre_re, /* the compiled pattern */
614+
NULL, /* no extra data - we didn't study the pattern */
615+
string->s, /* the subject string */
616+
string->len, /* the length of the subject */
617+
0, /* start at offset 0 in the subject */
618+
0, /* default options */
619+
NULL, /* output vector for substring information */
620+
0); /* number of elements in the output vector */
621+
#else
581622
match_data = pcre2_match_data_create(0, NULL); // no captures needed
582623

583624
pcre_rc = pcre2_match(
@@ -590,6 +631,7 @@ static int w_pcre_match(struct sip_msg* _msg, str* string, str* _regex_s)
590631
NULL); /* match context */
591632

592633
pcre2_match_data_free(match_data);
634+
#endif
593635

594636
/* Matching failed: handle error cases */
595637
if (pcre_rc < 0) {
@@ -618,7 +660,9 @@ static int w_pcre_match_group(struct sip_msg* _msg, str* string, int* _num_pcre)
618660
{
619661
int num_pcre;
620662
int pcre_rc;
663+
#ifdef PCRE2_LIB
621664
pcre2_match_data *match_data;
665+
#endif
622666

623667
/* Check if group matching feature is enabled */
624668
if (file == NULL) {
@@ -638,6 +682,17 @@ static int w_pcre_match_group(struct sip_msg* _msg, str* string, int* _num_pcre)
638682

639683
lock_get(reload_lock);
640684

685+
#ifndef PCRE2_LIB
686+
pcre_rc = pcre_exec(
687+
(*pcres_addr)[num_pcre], /* the compiled pattern */
688+
NULL, /* no extra data - we didn't study the pattern */
689+
string->s, /* the subject string */
690+
string->len, /* the length of the subject */
691+
0, /* start at offset 0 in the subject */
692+
0, /* default options */
693+
NULL, /* output vector for substring information */
694+
0); /* number of elements in the output vector */
695+
#else
641696
match_data = pcre2_match_data_create(0, NULL); // no captures needed
642697

643698
pcre_rc = pcre2_match(
@@ -650,6 +705,7 @@ static int w_pcre_match_group(struct sip_msg* _msg, str* string, int* _num_pcre)
650705
0); /* match context */
651706

652707
pcre2_match_data_free(match_data);
708+
#endif
653709

654710
lock_release(reload_lock);
655711

scripts/build/apt_requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ libxml2-dev
2727
make
2828
odbcinst
2929
patch
30-
python3-dev
30+
python-dev-is-python3
3131
unixodbc
3232
unixodbc-dev
3333
uuid-dev

scripts/build/install_depends.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ PKGS=$(cat "$(dirname $0)/apt_requirements.txt")
99
_PKGS=""
1010
for pkg in ${PKGS}
1111
do
12-
if [ "${BUILD_OS}" != "ubuntu:18.04" -a "${pkg}" = python3-dev ]
12+
if [ "${BUILD_OS}" = "ubuntu:18.04" -a "${pkg}" = "python-dev-is-python3" ]
1313
then
14-
pkg="python-dev-is-python3"
14+
pkg="python3-dev"
1515
fi
1616
if [ "${BUILD_OS%:*}" = "debian" -a "${pkg}" = libmysqlclient-dev ]
1717
then

0 commit comments

Comments
 (0)