Initial Commit

- initial default booting image
This commit is contained in:
2026-11-06 20:45:42 +01:00
commit b8783708ae
15201 changed files with 602532 additions and 0 deletions

View File

@@ -0,0 +1,393 @@
From 1631a6c1f50e152b8a45d8279c96086e5636795b Mon Sep 17 00:00:00 2001
From: Christos Tsantilas <christos@chtsanti.net>
Date: Fri, 25 Jan 2019 06:42:22 -0800
Subject: [PATCH] Required fixes to compile and run under cygwin
[Retrieved (and backported) from:
https://github.com/c-icap/c-icap-server/commit/1631a6c1f50e152b8a45d8279c96086e5636795b,
which has the side effect of fixing the build with the musl C library]
Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
[Bernd: rebased for 0.5.14]
Signed-off-by: Bernd Kuhls <bernd@kuhls.net>
---
Makefile.am | 2 +-
configure.ac | 10 +++++++---
header.c | 34 ----------------------------------
include/header.h | 8 --------
modules/Makefile.am | 34 ++++++++++++++++++++--------------
modules/bdb_tables.c | 17 +++++++++++++++--
modules/shared_cache.c | 12 ++++++++++++
modules/sys_logger.c | 13 +++++++++++++
services/echo/Makefile.am | 10 ++++++++--
services/ex-206/Makefile.am | 10 ++++++++--
utils/c-icap-mkbdb.c | 8 ++++----
11 files changed, 88 insertions(+), 70 deletions(-)
diff --git a/Makefile.am b/Makefile.am
index 4c34033..ab80f4f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -53,7 +53,7 @@ c_icap_SOURCES = aserver.c request.c cfg_param.c \
libicapapi_la_CFLAGS= $(INVISIBILITY_CFLAG) -I$(srcdir)/include/ -Iinclude/ @ZLIB_ADD_FLAG@ @OPENSSL_ADD_FLAG@ @BZLIB_ADD_FLAG@ @BROTLI_ADD_FLAG@ @ZSTD_ADD_FLAG@ @PCRE_ADD_FLAG@ -DCI_BUILD_LIB
libicapapi_la_LIBADD = @ZLIB_ADD_LDADD@ @BZLIB_ADD_LDADD@ @BROTLI_ADD_LDADD@ @ZSTD_ADD_LDADD@ @PCRE_ADD_LDADD@ @DL_ADD_FLAG@ @THREADS_LDADD@ @OPENSSL_ADD_LDADD@
-libicapapi_la_LDFLAGS= -shared -version-info @CICAPLIB_VERSION@ @THREADS_LDFLAGS@
+libicapapi_la_LDFLAGS= -shared -version-info @CICAPLIB_VERSION@ @LIBS_LDFLAGS@ @THREADS_LDFLAGS@
export EXT_PROGRAMS_MKLIB = @ZLIB_LNDIR_LDADD@ @BZLIB_LNDIR_LDADD@ @BROTLI_LNDIR_LDADD@ @ZSTD_LNDIR_LDADD@ @PCRE_LNDIR_LDADD@ @OPENSSL_LNDIR_LDADD@
diff --git a/configure.ac b/configure.ac
index 405571b..8059cb7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -45,12 +45,14 @@ case "$host_os" in
CFLAGS="-D_REENTRANT $CFLAGS"
THREADS_LDADD="-lpthread"
THREADS_LDFLAGS=""
+ LIBS_LDFLAGS=""
;;
solaris2.*)
CFLAGS="-D_REENTRANT -D_POSIX_PTHREAD_SEMANTICS $CFLAGS"
LIBS="-lsocket -lnsl -lrt $LIBS"
THREADS_LDADD="-lpthread"
THREADS_LDFLAGS=""
+ LIBS_LDFLAGS=""
;;
freebsd5*)
## If I understand how all those threading models works correctly
@@ -69,6 +71,7 @@ case "$host_os" in
CFLAGS="-pthread -D_THREAD_SAFE $CFLAGS"
THREADS_LDADD="-XCClinker -lc_r"
THREADS_LDFLAGS=""
+ LIBS_LDFLAGS=""
## FreeBSD has pthreads rwlocks from version 3 (I think)
# AC_DEFINE(HAVE_PTHREADS_RWLOCK,1,[Define HAVE_PTHREADS_RWLOCK if pthreads library supports rwlocks])
## 1:1 threads
@@ -82,24 +85,28 @@ case "$host_os" in
CFLAGS="-D_THREAD_SAFE $CFLAGS"
THREADS_LDADD="-XCClinker -lthr"
THREADS_LDFLAGS=""
+ LIBS_LDFLAGS=""
;;
cygwin*)
CFLAGS="-D_REENTRANT $CFLAGS"
THREADS_LDADD="-lpthread"
THREADS_LDFLAGS="";
+ LIBS_LDFLAGS="-no-undefined"
iscygwin="yes"
;;
*)
CFLAGS="-D_REENTRANT $CFLAGS"
THREADS_LDADD="-lpthread"
THREADS_LDFLAGS=""
+ LIBS_LDFLAGS=""
;;
esac
TEST_LIBS="$TEST_LIBS $THREADS_LDADD"
AC_SUBST(THREADS_LDADD)
AC_SUBST(THREADS_LDFLAGS)
+AC_SUBST(LIBS_LDFLAGS)
AC_DEFINE_UNQUOTED(C_ICAP_CONFIGURE_OPTIONS, "$ac_configure_args",
[configure command line used to configure c-icap])
@@ -984,9 +991,6 @@ LIBS="$LIBS $EXTRALIBS"
#Configure common flags
MODULES_LIBADD=""
-if test a"$iscygwin" != a; then
- MODULES_LIBADD="-L../../ -licapapi"
-fi
MODULES_CFLAGS="$INVISIBILITY_CFLAG -DCI_BUILD_MODULE"
AC_SUBST(MODULES_LIBADD)
AC_SUBST(MODULES_CFLAGS)
diff --git a/header.c b/header.c
index 807a2e0..266b958 100644
--- a/header.c
+++ b/header.c
@@ -110,21 +110,6 @@ const struct ci_error_code ci_error_codes[] = {
{505, "Unsupported version"} /*ICAP version not supported by server. */
};
-/*
-#ifdef __CYGWIN__
-int ci_error_code(int ec){
- return (ec >= EC_100 && ec < EC_MAX ? ci_error_codes[ec].code:1000);
-}
-
-const char *unknownerrorcode = "UNKNOWN ERROR CODE";
-
-const char *ci_error_code_string(int ec){
- return (ec >= EC_100 && ec < EC_MAX?ci_error_codes[ec].str:unknownerrorcode);
-}
-#endif
-*/
-
-
const char *ci_encaps_entities[] = {
"req-hdr",
"res-hdr",
@@ -134,25 +119,6 @@ const char *ci_encaps_entities[] = {
"opt-body"
};
-#ifdef __CYGWIN__
-
-const char *unknownentity = "UNKNOWN";
-const char *unknownmethod = "UNKNOWN";
-
-const char *ci_method_string(int method)
-{
- return (method <= ICAP_RESPMOD
- && method >= ICAP_OPTIONS ? CI_Methods[method] : unknownmethod);
-}
-
-
-const char *ci_encaps_entity_string(int e)
-{
- return (e <= ICAP_OPT_BODY
- && e >= ICAP_REQ_HDR ? CI_EncapsEntities[e] : unknownentity);
-}
-#endif
-
ci_headers_list_t *ci_headers_create()
{
ci_headers_list_t *h;
diff --git a/include/header.h b/include/header.h
index 4cab365..ed2de88 100644
--- a/include/header.h
+++ b/include/header.h
@@ -52,16 +52,8 @@ enum ci_encapsulated_entities {ICAP_REQ_HDR, ICAP_RES_HDR,
};
CI_DECLARE_DATA extern const char *ci_encaps_entities[];
-#ifdef __CYGWIN__
-
-const char *ci_encaps_entity_string(int e);
-
-#else
-
#define ci_encaps_entity_string(e) (e <= ICAP_OPT_BODY && e >= ICAP_REQ_HDR?ci_encaps_entities[e]:"UNKNOWN")
-#endif
-
/**
\typedef ci_headers_list_t
\ingroup HEADERS
diff --git a/modules/Makefile.am b/modules/Makefile.am
index e6e9270..2d43a60 100644
--- a/modules/Makefile.am
+++ b/modules/Makefile.am
@@ -21,38 +21,44 @@ endif
AM_CPPFLAGS=-I$(top_srcdir)/ -I$(top_srcdir)/include/ -I$(top_builddir)/include/
-sys_logger_la_LIBADD = @MODULES_LIBADD@
+if ISCYGWIN
+MODS_LIB_ADD=$(top_builddir)/libicapapi.la
+else
+MODS_LIB_ADD=
+endif
+
+sys_logger_la_LIBADD = $(MODS_LIB_ADD)
sys_logger_la_CFLAGS= @MODULES_CFLAGS@ @OPENSSL_ADD_FLAG@
-sys_logger_la_LDFLAGS= -module -avoid-version
+sys_logger_la_LDFLAGS= -module -avoid-version @LIBS_LDFLAGS@
sys_logger_la_SOURCES = sys_logger.c
-dnsbl_tables_la_LIBADD = @MODULES_LIBADD@
+dnsbl_tables_la_LIBADD = $(MODS_LIB_ADD)
dnsbl_tables_la_CFLAGS= @MODULES_CFLAGS@ @OPENSSL_ADD_FLAG@
-dnsbl_tables_la_LDFLAGS= -module -avoid-version
+dnsbl_tables_la_LDFLAGS= -module -avoid-version @LIBS_LDFLAGS@
dnsbl_tables_la_SOURCES = dnsbl_tables.c
-perl_handler_la_LIBADD = @MODULES_LIBADD@ @perllib@ -L@perlcore@ -lperl
+perl_handler_la_LIBADD = $(MODS_LIB_ADD) @perllib@ -L@perlcore@ -lperl
perl_handler_la_CFLAGS= @MODULES_CFLAGS@ @perlccflags@ -I@perlcore@
-perl_handler_la_LDFLAGS= -module -avoid-version @perlldflags@
+perl_handler_la_LDFLAGS= -module -avoid-version @LIBS_LDFLAGS@ @perlldflags@
perl_handler_la_SOURCES = perl_handler.c
-bdb_tables_la_LIBADD = @MODULES_LIBADD@ @BDB_ADD_LDADD@
+bdb_tables_la_LIBADD = $(MODS_LIB_ADD) @BDB_ADD_LDADD@
bdb_tables_la_CFLAGS= @MODULES_CFLAGS@ @BDB_ADD_FLAG@
-bdb_tables_la_LDFLAGS= -module -avoid-version
+bdb_tables_la_LDFLAGS= -module -avoid-version @LIBS_LDFLAGS@
bdb_tables_la_SOURCES = bdb_tables.c
-ldap_module_la_LIBADD = @MODULES_LIBADD@ @LDAP_ADD_LDADD@ $(top_builddir)/libicapapi.la
+ldap_module_la_LIBADD = $(MODS_LIB_ADD) @LDAP_ADD_LDADD@
ldap_module_la_CFLAGS= @MODULES_CFLAGS@ @LDAP_ADD_FLAG@
-ldap_module_la_LDFLAGS= -module -avoid-version
+ldap_module_la_LDFLAGS= -module -avoid-version @LIBS_LDFLAGS@
ldap_module_la_SOURCES = ldap_module.c
-memcached_cache_la_LIBADD= @MODULES_LIBADD@ @MEMCACHED_ADD_LDADD@
+memcached_cache_la_LIBADD= $(MODS_LIB_ADD) @MEMCACHED_ADD_LDADD@
memcached_cache_la_CFLAGS= @MODULES_CFLAGS@ @MEMCACHED_ADD_FLAG@
-memcached_cache_la_LDFLAGS= -module -avoid-version
+memcached_cache_la_LDFLAGS= -module -avoid-version @LIBS_LDFLAGS@
memcached_cache_la_SOURCES= memcached.c
-shared_cache_la_LIBADD= @MODULES_LIBADD@
+shared_cache_la_LIBADD= $(MODS_LIB_ADD)
shared_cache_la_CFLAGS= @OPENSSL_ADD_FLAG@
-shared_cache_la_LDFLAGS= -module -avoid-version
+shared_cache_la_LDFLAGS= -module -avoid-version @LIBS_LDFLAGS@
shared_cache_la_SOURCES= shared_cache.c
diff --git a/modules/bdb_tables.c b/modules/bdb_tables.c
index b8459be..1e908a9 100644
--- a/modules/bdb_tables.c
+++ b/modules/bdb_tables.c
@@ -176,8 +176,8 @@ void *bdb_table_open(struct ci_lookup_table *table)
/*We can not fork a Berkeley DB table, so we have to
open bdb tables for every child, on childs start-up procedure*/
- register_command_extend("openBDBtable", CHILD_START_CMD, table,
- command_real_open_table);
+ ci_command_register_action("openBDBtable", CHILD_START_CMD, table,
+ command_real_open_table);
return table->data;
}
@@ -257,3 +257,16 @@ void bdb_table_release_result(struct ci_lookup_table *table,void **val)
{
ci_buffer_free(val);
}
+
+ #ifdef __CYGWIN__
+#include <w32api/windows.h>
+void ci_command_register_action(const char *name, int type, void *data,
+ void (*command_action) (const char *name, int type, void *data))
+ {
+ typedef void (*RA)(const char *, int, void *, void(*)(const char *, int, void *));
+ RA fn;
+ fn = (RA)GetProcAddress(GetModuleHandle(NULL), "ci_command_register_action");
+ if (fn)
+ (*fn)(name, type, data, command_action);
+ }
+#endif
diff --git a/modules/shared_cache.c b/modules/shared_cache.c
index 103b760..a79d51a 100644
--- a/modules/shared_cache.c
+++ b/modules/shared_cache.c
@@ -345,3 +345,15 @@ void ci_shared_cache_destroy(struct ci_cache *cache)
ci_shared_mem_detach(&data->id);
}
+#ifdef __CYGWIN__
+#include <w32api/windows.h>
+void ci_command_register_action(const char *name, int type, void *data,
+ void (*command_action) (const char *name, int type, void *data))
+ {
+ typedef void (*RA)(const char *, int, void *, void(*)(const char *, int, void *));
+ RA fn;
+ fn = (RA)GetProcAddress(GetModuleHandle(NULL), "ci_command_register_action");
+ if (fn)
+ (*fn)(name, type, data, command_action);
+ }
+#endif
diff --git a/modules/sys_logger.c b/modules/sys_logger.c
index 1c47753..1764b0d 100644
--- a/modules/sys_logger.c
+++ b/modules/sys_logger.c
@@ -60,7 +60,20 @@ int cfg_syslog_access(const char *directive, const char **argv, void *setdata);
functions declared in log.c. This file is not included in c-icap library
but defined in primary c-icap binary.
*/
+#ifdef __CYGWIN__
+#include <w32api/windows.h>
+char *logformat_fmt(const char *name)
+{
+ typedef char* (*LF_FMT)(const char *);
+ LF_FMT fn;
+ fn = (LF_FMT)GetProcAddress(GetModuleHandle(NULL), "logformat_fmt");
+ if (fn)
+ return (*fn)(name);
+ return NULL;
+}
+#else
extern char *logformat_fmt(const char *name);
+#endif
/*Configuration Table .....*/
static struct ci_conf_entry conf_variables[] = {
diff --git a/services/echo/Makefile.am b/services/echo/Makefile.am
index 402c8f9..7d701b1 100644
--- a/services/echo/Makefile.am
+++ b/services/echo/Makefile.am
@@ -3,9 +3,15 @@ pkglib_LTLIBRARIES=srv_echo.la
AM_CPPFLAGS=-I$(top_srcdir)/ -I$(top_srcdir)/include/ -I$(top_builddir)/include/
-srv_echo_la_LIBADD = @MODULES_LIBADD@
+if ISCYGWIN
+MODS_LIB_ADD=$(top_builddir)/libicapapi.la
+else
+MODS_LIB_ADD=
+endif
+
+srv_echo_la_LIBADD = $(MODS_LIB_ADD)
srv_echo_la_CFLAGS= @MODULES_CFLAGS@ @OPENSSL_ADD_FLAG@
-srv_echo_la_LDFLAGS= -module -avoid-version
+srv_echo_la_LDFLAGS= -module -avoid-version @LIBS_LDFLAGS@
srv_echo_la_SOURCES = srv_echo.c
diff --git a/services/ex-206/Makefile.am b/services/ex-206/Makefile.am
index 44bbf21..ff73399 100644
--- a/services/ex-206/Makefile.am
+++ b/services/ex-206/Makefile.am
@@ -3,8 +3,14 @@ pkglib_LTLIBRARIES=srv_ex206.la
AM_CPPFLAGS=-I$(top_srcdir)/ -I$(top_srcdir)/include/ -I$(top_builddir)/include/
-srv_ex206_la_LIBADD = @MODULES_LIBADD@
+if ISCYGWIN
+MODS_LIB_ADD=$(top_builddir)/libicapapi.la
+else
+MODS_LIB_ADD=
+endif
+
+srv_ex206_la_LIBADD = $(MODS_LIB_ADD)
srv_ex206_la_CFLAGS= @MODULES_CFLAGS@ @OPENSSL_ADD_FLAG@
-srv_ex206_la_LDFLAGS= -module -avoid-version
+srv_ex206_la_LDFLAGS= -module -avoid-version @LIBS_LDFLAGS@
srv_ex206_la_SOURCES = srv_ex206.c
diff --git a/utils/c-icap-mkbdb.c b/utils/c-icap-mkbdb.c
index c29a46f..326ee1c 100644
--- a/utils/c-icap-mkbdb.c
+++ b/utils/c-icap-mkbdb.c
@@ -23,7 +23,7 @@ char *dbfile = NULL;
int DUMP_MODE = 0;
int VERSION_MODE = 0;
int USE_DBTREE = 0;
-long int PAGE_SIZE;
+long int DB_PAGE_SIZE;
ci_mem_allocator_t *allocator = NULL;
int cfg_set_type(const char *directive, const char **argv, void *setdata);
@@ -52,7 +52,7 @@ static struct ci_options_entry options[] = {
"The type of values"
},
{
- "-p", "page_size", &PAGE_SIZE, ci_cfg_size_long,
+ "-p", "page_size", &DB_PAGE_SIZE, ci_cfg_size_long,
"The page size to use for the database"
},
{
@@ -107,8 +107,8 @@ int open_db(char *path)
return 0;
}
- if (PAGE_SIZE > 512 && PAGE_SIZE <= 64*1024)
- db->set_pagesize(db, (uint32_t)PAGE_SIZE);
+ if (DB_PAGE_SIZE > 512 && DB_PAGE_SIZE <= 64*1024)
+ db->set_pagesize(db, (uint32_t)DB_PAGE_SIZE);
if ((ret = db->open(db, NULL, path, NULL,
(USE_DBTREE ? DB_BTREE : DB_HASH),

View File

@@ -0,0 +1,25 @@
From ae8a1bc4979c797bb1f152fc92cfe6bc05a44594 Mon Sep 17 00:00:00 2001
From: Christos Tsantilas <christos@chtsanti.net>
Date: Tue, 20 Nov 2018 17:10:16 +0200
Subject: [PATCH] Fix compile warning about missing stdio.h include file
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Upstream: https://github.com/c-icap/c-icap-server/commit/ae8a1bc4979c797bb1f152fc92cfe6bc05a44594
---
tests/test_base64.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/tests/test_base64.c b/tests/test_base64.c
index 8a4a76c..7692197 100644
--- a/tests/test_base64.c
+++ b/tests/test_base64.c
@@ -1,5 +1,6 @@
#include "common.h"
#include "simple_api.h"
+#include <stdio.h>
int main(int argc, char *argv[])
--
2.47.1

View File

@@ -0,0 +1,35 @@
From 9ca4e5e2bd5fdf1d15a862faf8d4d1ddc0664bd0 Mon Sep 17 00:00:00 2001
From: Christos Tsantilas <christos@chtsanti.net>
Date: Fri, 21 Feb 2025 13:34:06 +0200
Subject: [PATCH] Fix http_auth_method::release_authentication_header method
declaration
Requires a "char *" argument.
Reported with PR#72 at github:
https://github.com/c-icap/c-icap-server/pull/72
Upstream: 48a221b0197727b26f90c00544fa19c67d0f5d47
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
[Bernd: rebased for 0.5.14]
Signed-off-by: Bernd Kuhls <bernd@kuhls.net>
---
http_auth.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/http_auth.c b/http_auth.c
index 1883b55..b831bb1 100644
--- a/http_auth.c
+++ b/http_auth.c
@@ -62,7 +62,7 @@ int http_authenticate(ci_request_t * req, char *use_method)
authenticator_module_t **authenticators;
void *method_data;
const char *auth_str, *method_str, *username;
- char *auth_header = NULL;
+ const char *auth_header = NULL;
int len, res;
if (ALLOW_REMOTE_PROXY_USERS && !use_method) {
--
2.51.0

View File

@@ -0,0 +1,233 @@
From 608392c023b00e9e512f012eab295995127c577a Mon Sep 17 00:00:00 2001
From: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Date: Sun, 7 Sep 2025 17:45:00 +0200
Subject: [PATCH] Fix module operation prototypes to fix GCC 15.x build
Upstream: N/A, code has completely changed upstream
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
---
default_acl.c | 4 ++--
http_auth.c | 8 ++++----
include/module.h | 8 ++++----
modules/bdb_tables.c | 4 ++--
modules/dnsbl_tables.c | 4 ++--
modules/ldap_module.c | 4 ++--
modules/memcached.c | 4 ++--
modules/shared_cache.c | 4 ++--
8 files changed, 20 insertions(+), 20 deletions(-)
diff --git a/default_acl.c b/default_acl.c
index 135176a..cb84d9d 100644
--- a/default_acl.c
+++ b/default_acl.c
@@ -34,7 +34,7 @@
/* Default Authenticator definitions */
int default_acl_init(struct ci_server_conf *server_conf);
int default_acl_post_init(struct ci_server_conf *server_conf);
-void default_acl_release();
+void default_acl_release(struct ci_server_conf *server_conf);
int default_acl_client_match(ci_request_t *req);
int default_acl_request_match(ci_request_t *req);
@@ -75,7 +75,7 @@ int default_acl_post_init(struct ci_server_conf *server_conf)
return 1;
}
-void default_acl_release()
+void default_acl_release(struct ci_server_conf *server_conf)
{
ci_access_entry_release(acl_access_list);
ci_access_entry_release(acl_connection_access_list);
diff --git a/http_auth.c b/http_auth.c
index b831bb1..0000b12 100644
--- a/http_auth.c
+++ b/http_auth.c
@@ -378,7 +378,7 @@ static struct ci_conf_entry basic_conf_params[] = {
};
int basic_post_init(struct ci_server_conf *server_conf);
-void basic_close();
+void basic_close(struct ci_server_conf *);
struct http_basic_auth_data *basic_create_auth_data(const char *auth_line,
const char **username);
void basic_release_auth_data(struct http_basic_auth_data *data);
@@ -409,7 +409,7 @@ int basic_post_init(struct ci_server_conf *server_conf)
return 1;
}
-void basic_close()
+void basic_close(struct ci_server_conf *)
{
if (basic_authentication) {
free(basic_authentication);
@@ -468,7 +468,7 @@ static struct ci_conf_entry basic_simple_db_conf_variables[] = {
};
int basic_simple_db_post_init(struct ci_server_conf *server_conf);
-void basic_simple_db_close();
+void basic_simple_db_close(struct ci_server_conf *server_conf);
int basic_simple_db_athenticate(struct http_basic_auth_data *data, const char *usedb);
@@ -495,7 +495,7 @@ int basic_simple_db_post_init(struct ci_server_conf *server_conf)
return 1;
}
-void basic_simple_db_close()
+void basic_simple_db_close(struct ci_server_conf *server_conf)
{
if (users_db) {
ci_lookup_table_destroy(users_db);
diff --git a/include/module.h b/include/module.h
index 0e57586..21124df 100644
--- a/include/module.h
+++ b/include/module.h
@@ -63,7 +63,7 @@ typedef struct common_module {
const char *name;
int (*init_module)(struct ci_server_conf *server_conf);
int (*post_init_module)(struct ci_server_conf *server_conf);
- void (*close_module)();
+ void (*close_module)(struct ci_server_conf *);
struct ci_conf_entry *conf_table;
} common_module_t;
@@ -81,7 +81,7 @@ typedef struct access_control_module {
const char *name;
int (*init_access_controller)(struct ci_server_conf *server_conf);
int (*post_init_access_controller)(struct ci_server_conf *server_conf);
- void (*release_access_controller)();
+ void (*release_access_controller)(struct ci_server_conf *);
int (*client_access)(ci_request_t *req);
int (*request_access)(ci_request_t *req);
struct ci_conf_entry *conf_table;
@@ -92,7 +92,7 @@ typedef struct http_auth_method {
const char *name;
int (*init_auth_method)(struct ci_server_conf *server_conf);
int (*post_init_auth_method)(struct ci_server_conf *server_conf);
- void (*close_auth_method)();
+ void (*close_auth_method)(struct ci_server_conf *);
void *(*create_auth_data)(const char *authorization_header,const char **username);
void (*release_auth_data)(void *data);
char *(*authentication_header)();
@@ -106,7 +106,7 @@ typedef struct authenticator_module {
const char *method;
int (*init_authenticator)(struct ci_server_conf *server_conf);
int (*post_init_authenticator)(struct ci_server_conf *server_conf);
- void (*close_authenticator)();
+ void (*close_authenticator)(struct ci_server_conf *);
int (*authenticate)(void *data, const char *usedb);
struct ci_conf_entry *conf_table;
} authenticator_module_t;
diff --git a/modules/bdb_tables.c b/modules/bdb_tables.c
index 1e908a9..c205278 100644
--- a/modules/bdb_tables.c
+++ b/modules/bdb_tables.c
@@ -9,7 +9,7 @@
int init_bdb_tables(struct ci_server_conf *server_conf);
-void release_bdb_tables();
+void release_bdb_tables(struct ci_server_conf *server_conf);
CI_DECLARE_MOD_DATA common_module_t module = {
"bdb_tables",
@@ -41,7 +41,7 @@ int init_bdb_tables(struct ci_server_conf *server_conf)
return (ci_lookup_table_type_register(&bdb_table_type) != NULL);
}
-void release_bdb_tables()
+void release_bdb_tables(struct ci_server_conf *server_conf)
{
ci_lookup_table_type_unregister(&bdb_table_type);
}
diff --git a/modules/dnsbl_tables.c b/modules/dnsbl_tables.c
index 328c6fb..a90c715 100644
--- a/modules/dnsbl_tables.c
+++ b/modules/dnsbl_tables.c
@@ -10,7 +10,7 @@
int init_dnsbl_tables(struct ci_server_conf *server_conf);
-void release_dnsbl_tables();
+void release_dnsbl_tables(struct ci_server_conf *server_conf);
CI_DECLARE_MOD_DATA common_module_t module = {
"dnsbl_tables",
@@ -42,7 +42,7 @@ int init_dnsbl_tables(struct ci_server_conf *server_conf)
return (ci_lookup_table_type_register(&dnsbl_table_type) != NULL);
}
-void release_dnsbl_tables()
+void release_dnsbl_tables(struct ci_server_conf *server_conf)
{
ci_lookup_table_type_unregister(&dnsbl_table_type);
}
diff --git a/modules/ldap_module.c b/modules/ldap_module.c
index 97e36d8..96668a9 100644
--- a/modules/ldap_module.c
+++ b/modules/ldap_module.c
@@ -19,7 +19,7 @@ static int init_ldap_pools();
static void release_ldap_pools();
int init_ldap_module(struct ci_server_conf *server_conf);
-void release_ldap_module();
+void release_ldap_module(struct ci_server_conf *server_conf);
CI_DECLARE_MOD_DATA common_module_t module = {
"ldap_module",
@@ -76,7 +76,7 @@ int init_ldap_module(struct ci_server_conf *server_conf)
return 1;
}
-void release_ldap_module()
+void release_ldap_module(struct ci_server_conf *server_conf)
{
release_ldap_pools();
ci_lookup_table_type_unregister(&ldap_table_type);
diff --git a/modules/memcached.c b/modules/memcached.c
index 8f15fbd..b1bbe5a 100644
--- a/modules/memcached.c
+++ b/modules/memcached.c
@@ -61,7 +61,7 @@ static struct ci_conf_entry mc_conf_variables[] = {
static int mc_module_init(struct ci_server_conf *server_conf);
static int mc_module_post_init(struct ci_server_conf *server_conf);
-static void mc_module_release();
+static void mc_module_release(struct ci_server_conf *server_conf);
CI_DECLARE_MOD_DATA common_module_t module = {
"memcached",
mc_module_init,
@@ -209,7 +209,7 @@ int mc_module_post_init(struct ci_server_conf *server_conf)
return 1;
}
-void mc_module_release()
+void mc_module_release(struct ci_server_conf *server_conf)
{
memcached_pool_destroy(MC_POOL);
memcached_free(MC);
diff --git a/modules/shared_cache.c b/modules/shared_cache.c
index a79d51a..49a3784 100644
--- a/modules/shared_cache.c
+++ b/modules/shared_cache.c
@@ -9,7 +9,7 @@
#include <assert.h>
static int init_shared_cache(struct ci_server_conf *server_conf);
-static void release_shared_cache();
+static void release_shared_cache(struct ci_server_conf *server_conf);
CI_DECLARE_MOD_DATA common_module_t module = {
"shared_cache",
@@ -26,7 +26,7 @@ static int init_shared_cache(struct ci_server_conf *server_conf)
return 1;
}
-static void release_shared_cache()
+static void release_shared_cache(struct ci_server_conf *server_conf)
{
}
--
2.51.0

View File

@@ -0,0 +1,47 @@
From 8ef8966237865ec699ab16d208ff56edaac4ff7b Mon Sep 17 00:00:00 2001
From: Christos Tsantilas <christos@chtsanti.net>
Date: Fri, 1 Nov 2019 08:00:52 -0700
Subject: [PATCH] Fix integer printing in various printf to avoid warnings
about integer sizes
Upstream: https://github.com/c-icap/c-icap-server/commit/8ef8966237865ec699ab16d208ff56edaac4ff7b
[Bernd: partially backported to 0.5.10]
Signed-off-by: Bernd Kuhls <bernd@kuhls.net>
---
mpmt_server.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/mpmt_server.c b/mpmt_server.c
index a30d55d4..9b178a66 100644
--- a/mpmt_server.c
+++ b/mpmt_server.c
@@ -74,7 +74,7 @@ typedef struct server_decl {
ci_thread_mutex_t threads_list_mtx;
server_decl_t **threads_list = NULL;
-ci_thread_t listener_thread_id = -1;
+ci_thread_t listener_thread_id;
int listener_running = 0;
ci_thread_cond_t free_server_cond;
@@ -242,8 +242,8 @@ static void cancel_all_threads()
for (i=0; i<CI_CONF.THREADS_PER_CHILD; i++) {
if (threads_list[i] != NULL) { /* if the i thread is still alive*/
if (!threads_list[i]->running) { /*if the i thread is not running any more*/
- ci_debug_printf(5, "Cancel server %d, thread_id %lu (%d)\n",
- threads_list[i]->srv_id, threads_list[i]->srv_pthread,
+ ci_debug_printf(5, "Cancel server %" PRIu64 ", thread_id %" PRIu64 " (%d)\n",
+ (uint64_t)threads_list[i]->srv_id, (uint64_t)threads_list[i]->srv_pthread,
i);
ci_thread_join(threads_list[i]->srv_pthread);
release_thread_i(i);
@@ -252,7 +252,7 @@ static void cancel_all_threads()
/*The thread is still running, and we have a timeout for waiting
the thread to exit. */
if (wait_for_workers <= 2) {
- ci_debug_printf(5, "Thread %ld still running near the timeout. Try to kill it\n", threads_list[i]->srv_pthread);
+ ci_debug_printf(5, "Thread %" PRIu64 " still running near the timeout. Try to kill it\n", (uint64_t)threads_list[i]->srv_pthread);
pthread_kill( threads_list[i]->srv_pthread, SIGTERM);
}
}

View File

@@ -0,0 +1,569 @@
From: Boyuan Yang <byang@debian.org>
Date: Sat, 29 Jul 2023 19:13:16 -0400
Subject: Backport pcre2 support
Bug-Debian: https://bugs.debian.org/1000077
Upstream: https://github.com/c-icap/c-icap-server/commit/888a98ff382d782729f000876b4e81f08d9046d3
Downloaded from
https://sources.debian.org/src/c-icap/1%3A0.5.10-7/debian/patches/0005-Backport-pcre2-support.patch
[Bernd: rebased for 0.5.14]
Signed-off-by: Bernd Kuhls <bernd@kuhls.net>
---
Makefile.am | 16 +++-
aserver.c | 2 +
configure.ac | 51 ++++++++++++-
include/ci_regex.h | 43 ++++++++++-
regex.c | 210 ++++++++++++++++++++++++++++++++++++++++++++++++-----
types_ops.c | 4 +-
6 files changed, 296 insertions(+), 30 deletions(-)
diff --git a/Makefile.am b/Makefile.am
index acfa0d0..ebdf51c 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -22,11 +22,23 @@ bin_PROGRAMS = c-icap
bin_SCRIPTS = c-icap-config c-icap-libicapapi-config
+UTIL_FLAGS=
+UTIL_LDADD=
UTIL_LIB_SOURCES=net_io.c util.c os/unix/net_io.c os/unix/proc_mutex.c os/unix/shared_mem.c os/unix/threads.c os/unix/utilfunc.c os/unix/dlib.c
if USE_OPENSSL
UTIL_LIB_SOURCES += openssl/net_io_ssl.c
endif
+
if USE_REGEX
+if USE_PCRE2
+UTIL_FLAGS += @PCRE2_ADD_FLAG@
+UTIL_LDADD += @PCRE2_ADD_LDADD@
+endif
+if USE_PCRE
+UTIL_FLAGS += @PCRE_ADD_FLAG@
+UTIL_LDADD += @PCRE_ADD_LDADD@
+endif
+
UTIL_LIB_SOURCES += regex.c
endif
UTIL_SOURCES=os/unix/proc_utils.c
@@ -50,9 +62,9 @@ c_icap_SOURCES = aserver.c request.c cfg_param.c \
# libicapapi ......
-libicapapi_la_CFLAGS= $(INVISIBILITY_CFLAG) -I$(srcdir)/include/ -Iinclude/ @ZLIB_ADD_FLAG@ @OPENSSL_ADD_FLAG@ @BZLIB_ADD_FLAG@ @BROTLI_ADD_FLAG@ @ZSTD_ADD_FLAG@ @PCRE_ADD_FLAG@ -DCI_BUILD_LIB
+libicapapi_la_CFLAGS= $(INVISIBILITY_CFLAG) -I$(srcdir)/include/ -Iinclude/ @ZLIB_ADD_FLAG@ @OPENSSL_ADD_FLAG@ @BZLIB_ADD_FLAG@ @BROTLI_ADD_FLAG@ @ZSTD_ADD_FLAG@ $(UTIL_FLAG) -DCI_BUILD_LIB
-libicapapi_la_LIBADD = @ZLIB_ADD_LDADD@ @BZLIB_ADD_LDADD@ @BROTLI_ADD_LDADD@ @ZSTD_ADD_LDADD@ @PCRE_ADD_LDADD@ @DL_ADD_FLAG@ @THREADS_LDADD@ @OPENSSL_ADD_LDADD@
+libicapapi_la_LIBADD = @ZLIB_ADD_LDADD@ @BZLIB_ADD_LDADD@ @BROTLI_ADD_LDADD@ @ZSTD_ADD_LDADD@ $(UTIL_LDADD) @DL_ADD_FLAG@ @THREADS_LDADD@ @OPENSSL_ADD_LDADD@
libicapapi_la_LDFLAGS= -shared -version-info @CICAPLIB_VERSION@ @LIBS_LDFLAGS@ @THREADS_LDFLAGS@
export EXT_PROGRAMS_MKLIB = @ZLIB_LNDIR_LDADD@ @BZLIB_LNDIR_LDADD@ @BROTLI_LNDIR_LDADD@ @ZSTD_LNDIR_LDADD@ @PCRE_LNDIR_LDADD@ @OPENSSL_LNDIR_LDADD@
diff --git a/aserver.c b/aserver.c
index 9eaa609..990be9d 100644
--- a/aserver.c
+++ b/aserver.c
@@ -29,6 +29,7 @@
#endif
#include "txtTemplate.h"
#include "commands.h"
+#include "ci_regex.h"
/*
extern char *PIDFILE;
@@ -142,6 +143,7 @@ int main(int argc, char **argv)
}
ci_txt_template_init();
ci_txt_template_set_dir(DATADIR"templates");
+ ci_regex_memory_init();
commands_init();
if (!(CI_CONF.MAGIC_DB = ci_magic_db_load(CI_CONF.magics_file))) {
diff --git a/configure.ac b/configure.ac
index 2144011..08a937f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -246,6 +246,7 @@ AC_ARG_ENABLE(rpath,
#Routines used for checking libraries
AC_DEFUN([ICFG_STATE_SAVE],[
#save state
+ICFG_OLD_CPPFLAGS=$CPPFLAGS
ICFG_OLD_CFLAGS=$CFLAGS
ICFG_OLD_LDFLAGS=$LDFLAGS
ICFG_OLD_LIBS=$LIBS
@@ -253,7 +254,8 @@ ICFG_OLD_LIBS=$LIBS
#Routines used for checking libraries
AC_DEFUN([ICFG_STATE_ROLLBACK],[
-#save state
+#rollback saved state
+CPPFLAGS=$ICFG_OLD_CPPFLAGS
CFLAGS=$ICFG_OLD_CFLAGS
LDFLAGS=$ICFG_OLD_LDFLAGS
LIBS=$ICFG_OLD_LIBS
@@ -650,6 +652,45 @@ if test a"$libmemcached" != "ano"; then
ICFG_STATE_ROLLBACK
fi
+# Check for PCRE2 regex library
+AC_ARG_WITH(pcre2,
+[ --with-pcre2 Path to PCRE2 library],
+[
+case "$withval" in
+ yes)
+ pcre2=yes;
+ ;;
+ no)
+ pcre2=no;
+ ;;
+ *)
+ pcre2=yes;
+ pcre2path=$withval;
+ ;;
+ esac
+],
+[ pcre2=yes]
+)
+
+if test a"$pcre2" != "ano"; then
+ ICFG_STATE_SAVE(PCRE2)
+ CPPFLAGS="$CPPFLAGS -DPCRE2_CODE_UNIT_WIDTH=8"
+ if test "a$pcre2path" != "a"; then
+ CFLAGS="$CFLAGS -I$pcre2path/include"
+ LDFLAGS="$LDFLAGS -L$pcre2path/lib"
+ fi
+ AC_CHECK_HEADERS(pcre2.h,
+ AC_CHECK_LIB(pcre2-8, pcre2_match_8,[pcre2=yes],[pcre2=no]),
+ [pcre2=no]
+ )
+
+ if test "a$pcre2" = "ayes"; then
+ AC_DEFINE(HAVE_PCRE2,1,[Define HAVE_PCRE2 if pcre2 installed])
+ ICFG_BUILD_FLAGS(PCRE2, "$pcre2path", "-lpcre2-8")
+ fi
+ ICFG_STATE_ROLLBACK
+fi
+
# Check for PCRE regex library
AC_ARG_WITH(pcre,
[ --with-pcre Path to PCRE library],
@@ -670,7 +711,7 @@ case "$withval" in
[ pcre=yes]
)
-if test a"$pcre" != "ano"; then
+if test a"$pcre" != "ano" -a a"$pcre2" != "ayes"; then
ICFG_STATE_SAVE(PCRE)
if test "a$pcrepath" != "a"; then
CFLAGS="$CFLAGS -I$pcrepath/include"
@@ -714,7 +755,7 @@ AC_CHECK_HEADERS(regex.h,
)
USE_REGEX=0
-if test "a$pcre" = "ayes" -o "a$posix_regex" = "ayes"; then
+if test "a$pcre2" = "ayes" -o "a$pcre" = "ayes" -o "a$posix_regex" = "ayes"; then
USE_REGEX=1
fi
AC_SUBST(USE_REGEX)
@@ -1001,7 +1042,9 @@ AM_CONDITIONAL(ISCYGWIN,[test a"$iscygwin" != a])
# Now determine which modules will going to build .....
AM_CONDITIONAL(USE_OPENSSL, [test a"$openssl" != "ano"])
-AM_CONDITIONAL(USE_REGEX, [test a"$pcre" = "ayes" -o a"$posix_regex" = "ayes"])
+AM_CONDITIONAL(USE_PCRE2, [test a"$pcre2" = "ayes"])
+AM_CONDITIONAL(USE_PCRE, [test a"$pcre" = "ayes"])
+AM_CONDITIONAL(USE_REGEX, [test a"$pcre2" = "ayes" -o a"$pcre" = "ayes" -o a"$posix_regex" = "ayes"])
AM_CONDITIONAL(USEPERL,[test a"$perlcore" != a])
AM_CONDITIONAL(USEBDB, [test a"$libdb" != ano])
AM_CONDITIONAL(USELDAP, [test a"$libldap" != ano])
diff --git a/include/ci_regex.h b/include/ci_regex.h
index 27afc9c..df7b77a 100644
--- a/include/ci_regex.h
+++ b/include/ci_regex.h
@@ -33,18 +33,57 @@ struct ci_regex_match {
size_t s;
size_t e;
};
-typedef struct ci_regex_match ci_regex_matches_t[10];
+#define CI_REGEX_SUBMATCHES 10
+typedef struct ci_regex_match ci_regex_matches_t[CI_REGEX_SUBMATCHES];
typedef struct ci_regex_replace_part {
const void *user_data;
ci_regex_matches_t matches;
} ci_regex_replace_part_t;
-#define ci_regex_create_match_list() ci_list_create(32768, sizeof(ci_regex_replace_part_t))
+/**
+ \brief Builds a regex match list to store regex matches.
+ * The regex match list is a ci_list_t object which stores ci_regex_replace_part
+ * objects as items.
+ \ingroup UTILITY
+ */
+#define ci_regex_create_match_list() ci_list_create(1024, sizeof(ci_regex_replace_part_t))
+
+/**
+ \brief Parses a regex expresion having the form /regex/flags
+ \ingroup UTILITY
+ *
+ */
CI_DECLARE_FUNC(char *) ci_regex_parse(const char *str, int *flags, int *recursive);
+
+/**
+ \brief Compiles a regex expresion into an internal form.
+ \param regex_str The regex string normally returned by ci_regex_parse function
+ \param regex_flags The regex flags built using the ci_regex_parse
+ \ingroup UTILITY
+ */
CI_DECLARE_FUNC(ci_regex_t) ci_regex_build(const char *regex_str, int regex_flags);
+
+/**
+ * Releases objects built using the ci_regex_build
+ \ingroup UTILITY
+ */
CI_DECLARE_FUNC(void) ci_regex_free(ci_regex_t regex);
+
+/**
+ * Matchs a compiled regex expresion of type ci_regex_t against the given string.
+ \param regex The compiled regex expresion
+ \param str The string to match against
+ \param len The str string length. For '\0' terminated strings set it to -1
+ \param recurs If it is not NULL matches recursivelly
+ \param matches The regex match list to store matches. It can be NULL
+ \param user_data pointer to user data to store with matches in rege match list.
+ \ingroup UTILITY
+ */
CI_DECLARE_FUNC(int) ci_regex_apply(const ci_regex_t regex, const char *str, int len, int recurs, ci_list_t *matches, const void *user_data);
+
+CI_DECLARE_FUNC(void) ci_regex_memory_init();
+
#ifdef __cplusplus
}
#endif
diff --git a/regex.c b/regex.c
index 82277df..de9b387 100644
--- a/regex.c
+++ b/regex.c
@@ -1,14 +1,107 @@
#include "common.h"
#include "debug.h"
#include "array.h"
+#include "mem.h"
#include "ci_regex.h"
-#ifdef HAVE_PCRE
+#if defined(HAVE_PCRE2)
+#define PCRE2_CODE_UNIT_WIDTH 8 // TODO: make it configurable via configure
+#include <pcre2.h>
+#elif defined(HAVE_PCRE)
#include <pcre.h>
#else
#include <regex.h>
#endif
+#if defined(HAVE_PCRE2)
+pcre2_general_context *pcre2GenContext = NULL;
+pcre2_match_context *pcre2MatchContext = NULL;
+
+void *pcre2_malloc(PCRE2_SIZE size, void *udata)
+{
+ void *p = ci_buffer_alloc(size);
+ return p;
+}
+
+void pcre2_free(void *p, void *udata)
+{
+ ci_buffer_free(p);
+}
+
+struct {
+ char *name;
+ uint32_t flag;
+} pcre2_flags[] = {
+ {"ANCHORED", 0x80000000u},
+ {"NO_UTF_CHECK", 0x40000000u},
+ {"ENDANCHORED", 0x20000000u},
+ {"ALLOW_EMPTY_CLASS", 0x00000001u},
+ {"ALT_BSUX", 0x00000002u},
+ {"AUTO_CALLOUT", 0x00000004u},
+ {"CASELESS", 0x00000008u},
+ {"DOLLAR_ENDONLY", 0x00000010u},
+ {"DOTALL", 0x00000020u},
+ {"DUPNAMES", 0x00000040u},
+ {"EXTENDED", 0x00000080u},
+ {"FIRSTLINE", 0x00000100u},
+ {"MATCH_UNSET_BACKREF", 0x00000200u},
+ {"MULTILINE", 0x00000400u},
+ {"NEVER_UCP", 0x00000800u},
+ {"NEVER_UTF", 0x00001000u},
+ {"NO_AUTO_CAPTURE", 0x00002000u},
+ {"NO_AUTO_POSSESS", 0x00004000u},
+ {"NO_DOTSTAR_ANCHOR", 0x00008000u},
+ {"NO_START_OPTIMIZE", 0x00010000u},
+ {"UCP", 0x00020000u},
+ {"UNGREEDY", 0x00040000u},
+ {"UTF", 0x00080000u},
+ {"NEVER_BACKSLASH_C", 0x00100000u},
+ {"ALT_CIRCUMFLEX", 0x00200000u},
+ {"ALT_VERBNAMES", 0x00400000u},
+ {"USE_OFFSET_LIMIT", 0x00800000u},
+ {"EXTENDED_MORE", 0x01000000u},
+ {"LITERAL", 0x02000000u},
+ {"MATCH_INVALID_UTF", 0x04000000u},
+ {NULL, 0}
+};
+
+int pcre2_flag_parse(const char **f)
+{
+ const char *s = (*f);
+ if (*s != '<')
+ return 0;
+ s++;
+ const char *e = strchr(s, '>');
+ if (e)
+ *f = e;
+ else {
+ e = s + strlen(s);
+ *f = e - 1;
+ }
+ size_t len = e - s;
+ e--;
+ if (!len)
+ return 0;
+
+ int i;
+ for (i = 0; pcre2_flags[i].name != NULL; i++) {
+ if (strncmp(pcre2_flags[i].name, s, len) == 0)
+ return pcre2_flags[i].flag;
+ }
+ return 0;
+}
+
+#endif
+
+void ci_regex_memory_init()
+{
+#if defined(HAVE_PCRE2)
+ pcre2GenContext = pcre2_general_context_create(pcre2_malloc, pcre2_free, NULL);
+ pcre2MatchContext = pcre2_match_context_create(pcre2GenContext);
+#endif
+}
+
+
char *ci_regex_parse(const char *str, int *flags, int *recursive)
{
@@ -29,7 +122,10 @@ char *ci_regex_parse(const char *str, int *flags, int *recursive)
s[slen] = '\0';
*flags = 0;
-#ifdef HAVE_PCRE
+#if defined(HAVE_PCRE2)
+ *flags |= PCRE2_NEWLINE_ANY;
+ *flags |= PCRE2_NEWLINE_ANYCRLF;
+#elif defined(HAVE_PCRE)
*flags |= PCRE_NEWLINE_ANY;
*flags |= PCRE_NEWLINE_ANYCRLF;
#else
@@ -38,7 +134,27 @@ char *ci_regex_parse(const char *str, int *flags, int *recursive)
#endif
while (*e != '\0') {
-#ifdef HAVE_PCRE
+#if defined(HAVE_PCRE2)
+ if (*e == 'i')
+ *flags = *flags | PCRE2_CASELESS;
+ else if (*e == 'm')
+ *flags |= PCRE2_MULTILINE;
+ else if (*e == 's')
+ *flags |= PCRE2_DOTALL;
+ else if (*e == 'x')
+ *flags |= PCRE2_EXTENDED;
+ else if (*e == 'A')
+ *flags |= PCRE2_ANCHORED;
+ else if (*e == 'D')
+ *flags |= PCRE2_DOLLAR_ENDONLY;
+ else if (*e == 'U')
+ *flags |= PCRE2_UNGREEDY;
+ else if (*e == 'u')
+ *flags |= PCRE2_UTF | PCRE2_UCP;
+ else if (*e == '<') {
+ *flags |= pcre2_flag_parse(&e);
+ }
+#elif defined(HAVE_PCRE)
if (*e == 'i')
*flags = *flags | PCRE_CASELESS;
else if (*e == 'm')
@@ -74,7 +190,19 @@ char *ci_regex_parse(const char *str, int *flags, int *recursive)
ci_regex_t ci_regex_build(const char *regex_str, int regex_flags)
{
-#ifdef HAVE_PCRE
+#if defined(HAVE_PCRE2)
+ pcre2_code *re;
+ int errcode;
+ PCRE2_SIZE erroffset;
+ re = pcre2_compile((PCRE2_SPTR)regex_str, PCRE2_ZERO_TERMINATED, (uint32_t)regex_flags, &errcode, &erroffset, NULL);
+ if (re == NULL) {
+ PCRE2_UCHAR errbuf[256];
+ pcre2_get_error_message(errcode, errbuf, sizeof(errbuf));
+ ci_debug_printf(2, "PCRE2 compilation of '%s' failed at offset %d: %s\n", regex_str, (int)erroffset, errbuf);
+ return NULL;
+ }
+ return (ci_regex_t)re;
+#elif defined(HAVE_PCRE)
pcre *re;
const char *error;
int erroffset;
@@ -103,7 +231,9 @@ ci_regex_t ci_regex_build(const char *regex_str, int regex_flags)
void ci_regex_free(ci_regex_t regex)
{
-#ifdef HAVE_PCRE
+#if defined(HAVE_PCRE2)
+ pcre2_code_free((pcre2_code *)regex);
+#elif defined(HAVE_PCRE)
pcre_free((pcre *)regex);
#else
regfree((regex_t *)regex);
@@ -112,7 +242,7 @@ void ci_regex_free(ci_regex_t regex)
}
#ifdef HAVE_PCRE
-#define OVECCOUNT 30 /* should be a multiple of 3 */
+#define OVECCOUNT (3*CI_REGEX_SUBMATCHES) /* should be a multiple of 3 */
#endif
int ci_regex_apply(const ci_regex_t regex, const char *str, int len, int recurs, ci_list_t *matches, const void *user_data)
@@ -120,14 +250,42 @@ int ci_regex_apply(const ci_regex_t regex, const char *str, int len, int recurs,
int count = 0, i;
ci_regex_replace_part_t parts;
- if (!str)
+ if (!str || len == 0)
return 0;
-#ifdef HAVE_PCRE
+#if defined(HAVE_PCRE2)
+ PCRE2_SIZE offset = 0;
+ pcre2_match_data *match_data = pcre2_match_data_create_from_pattern(regex, pcre2GenContext);
+ do {
+ int str_length = len > 0 ? len : PCRE2_ZERO_TERMINATED;
+ int rcaptures = pcre2_match(regex, (PCRE2_SPTR)str, str_length, offset, 0, match_data, pcre2MatchContext);
+ if (rcaptures >= 0)
+ count++;
+ if (rcaptures > 0 && matches) {
+ PCRE2_SIZE *ovector = pcre2_get_ovector_pointer(match_data);
+ for (i = 0; i < rcaptures && i < CI_REGEX_SUBMATCHES; i++) {
+ _CI_ASSERT(ovector[2*i+1] >= ovector[2*i]);
+ if (matches) {
+ parts.user_data = user_data;
+ memset(parts.matches, 0, sizeof(ci_regex_matches_t));
+ ci_debug_printf(9, "\t sub-match pattern (pos:%d-%d): '%.*s'\n", (int)ovector[2*i], (int)ovector[2*i+1], (int)(ovector[2*i + 1] - ovector[2*i]), str+ovector[2*i]);
+ parts.matches[i].s = ovector[2*i];
+ parts.matches[i].e = ovector[2*i+1];
+ }
+ ci_list_push_back(matches, (void *)&parts);
+ }
+ offset = ovector[1]; /*Assert that it is less than strlen(str)?*/
+ } else if (rcaptures < 0) {
+ /* maybe check and report the exact error?*/
+ offset = 0;
+ } /* the rcaptures==0 not possible for our case, but maybe check and warn?*/
+ } while (recurs && offset > 0);
+ pcre2_match_data_free(match_data);
+#elif defined(HAVE_PCRE)
int ovector[OVECCOUNT];
int rc;
int offset = 0;
- int str_length = len >=0 ? len : strlen(str);
+ int str_length = len > 0 ? len : strlen(str);
do {
memset(ovector, 0, sizeof(ovector));
rc = pcre_exec(regex, NULL, str, str_length, offset, 0, ovector, OVECCOUNT);
@@ -139,7 +297,7 @@ int ci_regex_apply(const ci_regex_t regex, const char *str, int len, int recurs,
if (matches) {
parts.user_data = user_data;
memset(parts.matches, 0, sizeof(ci_regex_matches_t));
- for (i = 0; i < 10 && ovector[2*i+1] > ovector[2*i]; ++i) {
+ for (i = 0; i < CI_REGEX_SUBMATCHES && ovector[2*i+1] > ovector[2*i]; ++i) {
ci_debug_printf(9, "\t sub-match pattern (pos:%d-%d): '%.*s'\n", ovector[2*i], ovector[2*i+1], ovector[2*i + 1] - ovector[2*i], str+ovector[2*i]);
parts.matches[i].s = ovector[2*i];
parts.matches[i].e = ovector[2*i+1];
@@ -151,17 +309,27 @@ int ci_regex_apply(const ci_regex_t regex, const char *str, int len, int recurs,
#else
int retcode;
- regmatch_t pmatch[10];
+ regmatch_t pmatch[CI_REGEX_SUBMATCHES];
+ char *tmpS = NULL;
+ const char *s;
+ if (len > 0 && len < strlen(str)) {
+ tmpS = ci_buffer_alloc(len + 1);
+ _CI_ASSERT(tmpS);
+ memcpy(tmpS, str, len);
+ tmpS[len] = '\0';
+ s = tmpS;
+ } else
+ s = str;
do {
- if ((retcode = regexec(regex, str, 10, pmatch, 0)) == 0) {
+ if ((retcode = regexec(regex, s, CI_REGEX_SUBMATCHES, pmatch, 0)) == 0) {
++count;
- ci_debug_printf(9, "Match pattern (pos:%d-%d): '%.*s'\n", pmatch[0].rm_so, pmatch[0].rm_eo, pmatch[0].rm_eo - pmatch[0].rm_so, str+pmatch[0].rm_so);
+ ci_debug_printf(9, "Match pattern (pos:%d-%d): '%.*s'\n", pmatch[0].rm_so, pmatch[0].rm_eo, pmatch[0].rm_eo - pmatch[0].rm_so, s+pmatch[0].rm_so);
if (matches) {
parts.user_data = user_data;
memset(parts.matches, 0, sizeof(ci_regex_matches_t));
- for (i = 0; i < 10 && pmatch[i].rm_eo > pmatch[i].rm_so; ++i) {
- ci_debug_printf(9, "\t sub-match pattern (pos:%d-%d): '%.*s'\n", pmatch[i].rm_so, pmatch[i].rm_eo, pmatch[i].rm_eo - pmatch[i].rm_so, str+pmatch[i].rm_so);
+ for (i = 0; i < CI_REGEX_SUBMATCHES && pmatch[i].rm_eo > pmatch[i].rm_so; ++i) {
+ ci_debug_printf(9, "\t sub-match pattern (pos:%d-%d): '%.*s'\n", pmatch[i].rm_so, pmatch[i].rm_eo, pmatch[i].rm_eo - pmatch[i].rm_so, s+pmatch[i].rm_so);
parts.matches[i].s = pmatch[i].rm_so;
parts.matches[i].e = pmatch[i].rm_eo;
}
@@ -169,14 +337,16 @@ int ci_regex_apply(const ci_regex_t regex, const char *str, int len, int recurs,
}
if (pmatch[0].rm_so >= 0 && pmatch[0].rm_eo >= 0 && pmatch[0].rm_so != pmatch[0].rm_eo) {
- str += pmatch[0].rm_eo;
- ci_debug_printf(8, "I will check again starting from: %s\n", str);
+ s += pmatch[0].rm_eo;
+ ci_debug_printf(8, "I will check again starting from: %s\n", s);
} else /*stop here*/
- str = NULL;
+ s = NULL;
}
- } while (recurs && str && *str != '\0' && retcode == 0);
+ } while (recurs && s && *s != '\0' && retcode == 0);
+ if (tmpS)
+ ci_buffer_free(tmpS);
#endif
- ci_debug_printf(5, "ci_regex_apply matches count: %d\n", count);
+ ci_debug_printf(5, "ci_regex_apply string '%s' matches count: %d\n", str, count);
return count;
}
diff --git a/types_ops.c b/types_ops.c
index 78798c6..1310d4b 100644
--- a/types_ops.c
+++ b/types_ops.c
@@ -273,7 +273,7 @@ int regex_cmp(const void *key1, const void *key2)
struct ci_acl_regex *reg = (struct ci_acl_regex *)key1;
if (!key2)
return -1;
- return (ci_regex_apply(reg->preg, (const char *)key2, strlen(key2), 0, NULL, NULL) == 0 ? 1 : 0);
+ return (ci_regex_apply(reg->preg, (const char *)key2, -1, 0, NULL, NULL) == 0 ? 1 : 0);
}
int regex_equal(const void *key1, const void *key2)
@@ -281,7 +281,7 @@ int regex_equal(const void *key1, const void *key2)
struct ci_acl_regex *reg = (struct ci_acl_regex *)key1;
if (!key2)
return 0;
- return ci_regex_apply(reg->preg, (const char *)key2, strlen(key2), 0, NULL, NULL) != 0;
+ return ci_regex_apply(reg->preg, (const char *)key2, -1, 0, NULL, NULL) != 0;
}
size_t regex_len(const void *key)

View File

@@ -0,0 +1,50 @@
From: Boyuan Yang <byang@debian.org>
Date: Sat, 29 Jul 2023 19:34:51 -0400
Subject: Add missing _CI_ASSERT macro for pcre2 patch
Upstream: https://github.com/c-icap/c-icap-server/commit/9d4b75b2a044669cbe4570f95f0f8f00f09b0d21
Downloaded from
https://sources.debian.org/src/c-icap/1%3A0.5.10-7/debian/patches/0007-Add-missing-_CI_ASSERT-macro-for-pcre2-patch.patch
Signed-off-by: Bernd Kuhls <bernd@kuhls.net>
---
debug.c | 10 ++++++++++
include/debug.h | 3 +++
2 files changed, 13 insertions(+)
diff --git a/debug.c b/debug.c
index 8a3bf6d..4f34a87 100644
--- a/debug.c
+++ b/debug.c
@@ -47,6 +47,16 @@ void __ldebug_printf(int i, const char *format, ...)
}
#endif
+void ci_debug_abort(const char *file, int line, const char *function, const char *mesg)
+{
+ ci_debug_printf(1, "Abort at %s, %d, %s: \'%s\'\n", file, line, function, mesg);
+ fflush(stderr);
+ fflush(stdout);
+ abort();
+}
+
+void (*__ci_debug_abort)(const char *file, int line, const char *function, const char *mesg) = ci_debug_abort;
+
/*
void debug_print_request(ci_request_t *req){
int i,j;
diff --git a/include/debug.h b/include/debug.h
index 9373ec9..990cce7 100644
--- a/include/debug.h
+++ b/include/debug.h
@@ -44,6 +44,9 @@ CI_DECLARE_DATA extern void (*__log_error)(void *req, const char *format,... );
#define ci_debug_printf(i, args...) if(i<=CI_DEBUG_LEVEL){ if(__log_error) (*__log_error)(NULL,args); if(CI_DEBUG_STDOUT) printf(args);}
#endif
+CI_DECLARE_DATA extern void (*__ci_debug_abort)(const char *file, int line, const char *function, const char *mesg);
+#define _CI_ASSERT(expression) {if (!(expression)) (*__ci_debug_abort)(__FILE__, __LINE__, __func__, #expression);}
+
#ifdef __cplusplus
}
#endif

21
package/c-icap/Config.in Normal file
View File

@@ -0,0 +1,21 @@
config BR2_PACKAGE_C_ICAP
bool "c-icap"
depends on !BR2_STATIC_LIBS
depends on BR2_TOOLCHAIN_HAS_THREADS
depends on BR2_USE_MMU # fork()
# the libmemcached code uses <crypt.h>
select BR2_PACKAGE_LIBXCRYPT if \
BR2_PACKAGE_LIBMEMCACHED && BR2_TOOLCHAIN_USES_GLIBC
help
c-icap is an implementation of an ICAP server. It can be
used with HTTP proxies that support the ICAP protocol to
implement content adaptation and filtering services. Most
of the commercial HTTP proxies must support the ICAP
protocol. The open source Squid 3.x proxy server supports
it.
http://c-icap.sourceforge.net/
comment "c-icap needs a toolchain w/ threads and dynamic library"
depends on BR2_USE_MMU
depends on BR2_STATIC_LIBS || !BR2_TOOLCHAIN_HAS_THREADS

27
package/c-icap/S96cicap Normal file
View File

@@ -0,0 +1,27 @@
#!/bin/sh
# (Re)create directories
mkdir -p /var/run/c-icap
mkdir -p /var/log/c-icap
case "$1" in
start)
printf "Starting c-icap server: "
start-stop-daemon -S -q -b -m -p /var/run/c-icap.pid \
-x /usr/bin/c-icap -- -N
[ $? == 0 ] && echo "OK" || echo "FAIL"
;;
stop)
printf "Stopping c-icap server: "
start-stop-daemon -K -q -p /var/run/c-icap.pid
[ $? = 0 ] && echo "OK" || echo "FAIL"
;;
restart|reload)
$0 stop
sleep 1
$0 start
;;
*)
echo "Usage: /etc/init.d/S96cicap {start|stop|restart|reload}"
exit 1
esac

View File

@@ -0,0 +1,6 @@
# Retrieved from https://sourceforge.net/projects/c-icap/files/c-icap/0.5.x/
md5 f678d20ae30cad41b08437b441752e31 c_icap-0.5.14.tar.gz
sha1 db5e72065a3219410adfdbc5378b40b01e21ec36 c_icap-0.5.14.tar.gz
# Locally calculated
sha256 28c30c97b1892a1a8938db6cdad806a73016c57ae181e232d33f347d5d700ec5 c_icap-0.5.14.tar.gz
sha256 36b6d3fa47916943fd5fec313c584784946047ec1337a78b440e5992cb595f89 COPYING

104
package/c-icap/c-icap.mk Normal file
View File

@@ -0,0 +1,104 @@
################################################################################
#
# c-icap
#
################################################################################
C_ICAP_VERSION = 0.5.14
C_ICAP_SOURCE = c_icap-$(C_ICAP_VERSION).tar.gz
C_ICAP_SITE = http://downloads.sourceforge.net/c-icap
C_ICAP_LICENSE = LGPL-2.1+
C_ICAP_LICENSE_FILES = COPYING
C_ICAP_CPE_ID_VALID = YES
C_ICAP_INSTALL_STAGING = YES
C_ICAP_CONFIG_SCRIPTS = c-icap-config c-icap-libicapapi-config
C_ICAP_CONF_OPTS = \
--without-pcre \
--without-perl \
--without-zstd \
--enable-large-files \
--enable-ipv6
# Pre-seed cache variables for tests done with AC_TRY_RUN that are not
# cross-compile friendly
C_ICAP_CONF_ENV = ac_cv_10031b_ipc_sem=yes ac_cv_fcntl=yes
# c-icap adds '-Wl,-rpath -Wl,/usr/lib' to the link command line. This
# causes the linker to search for libraries that are listed as NEEDED
# in the libicapapi.so ELF header in host libraries, which breaks the
# build. The affected library is libz. Forcing AUTORECONF adds -lz to
# the link command line, and that makes the linker look first in
# sysroot, thus avoiding the build breakage.
C_ICAP_AUTORECONF = YES
ifeq ($(BR2_PACKAGE_BERKELEYDB),y)
C_ICAP_CONF_OPTS += --with-bdb
C_ICAP_DEPENDENCIES += berkeleydb
else
C_ICAP_CONF_OPTS += --without-bdb
endif
ifeq ($(BR2_PACKAGE_BZIP2),y)
C_ICAP_CONF_OPTS += --with-bzlib
C_ICAP_DEPENDENCIES += bzip2
else
C_ICAP_CONF_OPTS += --without-bzlib
endif
ifeq ($(BR2_PACKAGE_LIBMEMCACHED),y)
C_ICAP_CONF_OPTS += --with-memcached
C_ICAP_DEPENDENCIES += libmemcached $(if $(BR2_PACKAGE_LIBXCRYPT),libxcrypt)
else
C_ICAP_CONF_OPTS += --without-memcached
endif
ifeq ($(BR2_PACKAGE_OPENLDAP),y)
C_ICAP_CONF_OPTS += --with-ldap
C_ICAP_DEPENDENCIES += openldap
else
C_ICAP_CONF_OPTS += --without-ldap
endif
ifeq ($(BR2_PACKAGE_OPENSSL),y)
C_ICAP_CONF_OPTS += --with-openssl
C_ICAP_DEPENDENCIES += openssl
else
C_ICAP_CONF_OPTS += --without-openssl
endif
ifeq ($(BR2_PACKAGE_PCRE2),y)
C_ICAP_CONF_OPTS += --with-pcre2
C_ICAP_DEPENDENCIES += pcre2
else
C_ICAP_CONF_OPTS += --without-pcre2
endif
ifeq ($(BR2_PACKAGE_ZLIB),y)
C_ICAP_CONF_OPTS += --with-zlib
C_ICAP_DEPENDENCIES += zlib
else
C_ICAP_CONF_OPTS += --without-zlib
endif
define C_ICAP_INSTALL_INIT_SYSV
$(INSTALL) -m 0755 -D package/c-icap/S96cicap $(TARGET_DIR)/etc/init.d/S96cicap
endef
# Tweak the installation:
# - Removed unneeded sample configuration files (c-icap.*.default),
# since some real ones are also installed
# - Tweak some paths in the c-icap.conf configuration file
# - Tweak the -config scripts, because the generic
# <pkg>_CONFIG_SCRIPTS logic doesn't tweak them enough
define C_ICAP_TUNE_INSTALLATION
$(RM) -f $(TARGET_DIR)/etc/c-icap.*.default
$(SED) 's%/usr/etc/%/etc/%' $(TARGET_DIR)/etc/c-icap.conf
$(SED) 's%/usr/var/%/var/%' $(TARGET_DIR)/etc/c-icap.conf
$(SED) 's%INCDIR=.*%INCDIR=$(STAGING_DIR)/usr/include%' \
$(STAGING_DIR)/usr/bin/{c-icap,c-icap-libicapapi}-config
$(SED) 's%INCDIR2=.*%INCDIR2=$(STAGING_DIR)/usr/include/c_icap%' \
$(STAGING_DIR)/usr/bin/{c-icap,c-icap-libicapapi}-config
$(SED) 's%-L$$LIBDIR %%' $(STAGING_DIR)/usr/bin/c-icap-libicapapi-config
endef
C_ICAP_POST_INSTALL_TARGET_HOOKS += C_ICAP_TUNE_INSTALLATION
$(eval $(autotools-package))