0001-Required-fixes-to-compile-and-run-under-cygwin.patch 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. From 1631a6c1f50e152b8a45d8279c96086e5636795b Mon Sep 17 00:00:00 2001
  2. From: Christos Tsantilas <christos@chtsanti.net>
  3. Date: Fri, 25 Jan 2019 06:42:22 -0800
  4. Subject: [PATCH] Required fixes to compile and run under cygwin
  5. [Retrieved (and backported) from:
  6. https://github.com/c-icap/c-icap-server/commit/1631a6c1f50e152b8a45d8279c96086e5636795b,
  7. which has the side effect of fixing the build with the musl C library]
  8. Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
  9. ---
  10. Makefile.am | 2 +-
  11. configure.ac | 10 +++++++---
  12. header.c | 34 ----------------------------------
  13. include/header.h | 8 --------
  14. modules/Makefile.am | 34 ++++++++++++++++++++--------------
  15. modules/bdb_tables.c | 17 +++++++++++++++--
  16. modules/shared_cache.c | 12 ++++++++++++
  17. modules/sys_logger.c | 13 +++++++++++++
  18. services/echo/Makefile.am | 10 ++++++++--
  19. services/ex-206/Makefile.am | 10 ++++++++--
  20. utils/c-icap-mkbdb.c | 8 ++++----
  21. 11 files changed, 88 insertions(+), 70 deletions(-)
  22. diff --git a/Makefile.am b/Makefile.am
  23. index 4c34033..ab80f4f 100644
  24. --- a/Makefile.am
  25. +++ b/Makefile.am
  26. @@ -53,7 +53,7 @@ c_icap_SOURCES = aserver.c request.c cfg_param.c \
  27. libicapapi_la_CFLAGS= $(INVISIBILITY_CFLAG) -I$(srcdir)/include/ -Iinclude/ @ZLIB_ADD_FLAG@ @OPENSSL_ADD_FLAG@ @BZLIB_ADD_FLAG@ @BROTLI_ADD_FLAG@ @PCRE_ADD_FLAG@ -DCI_BUILD_LIB
  28. libicapapi_la_LIBADD = @ZLIB_ADD_LDADD@ @BZLIB_ADD_LDADD@ @BROTLI_ADD_LDADD@ @PCRE_ADD_LDADD@ @DL_ADD_FLAG@ @THREADS_LDADD@ @OPENSSL_ADD_LDADD@
  29. -libicapapi_la_LDFLAGS= -shared -version-info @CICAPLIB_VERSION@ @THREADS_LDFLAGS@
  30. +libicapapi_la_LDFLAGS= -shared -version-info @CICAPLIB_VERSION@ @LIBS_LDFLAGS@ @THREADS_LDFLAGS@
  31. export EXT_PROGRAMS_MKLIB = @ZLIB_LNDIR_LDADD@ @BZLIB_LNDIR_LDADD@ @BROTLI_LNDIR_LDADD@ @PCRE_LNDIR_LDADD@ @OPENSSL_LNDIR_LDADD@
  32. diff --git a/configure.ac b/configure.ac
  33. index 405571b..8059cb7 100644
  34. --- a/configure.ac
  35. +++ b/configure.ac
  36. @@ -45,12 +45,14 @@ case "$host_os" in
  37. CFLAGS="-D_REENTRANT $CFLAGS"
  38. THREADS_LDADD="-lpthread"
  39. THREADS_LDFLAGS=""
  40. + LIBS_LDFLAGS=""
  41. ;;
  42. solaris2.*)
  43. CFLAGS="-D_REENTRANT -D_POSIX_PTHREAD_SEMANTICS $CFLAGS"
  44. LIBS="-lsocket -lnsl -lrt $LIBS"
  45. THREADS_LDADD="-lpthread"
  46. THREADS_LDFLAGS=""
  47. + LIBS_LDFLAGS=""
  48. ;;
  49. freebsd5*)
  50. ## If I understand how all those threading models works correctly
  51. @@ -69,6 +71,7 @@ case "$host_os" in
  52. CFLAGS="-pthread -D_THREAD_SAFE $CFLAGS"
  53. THREADS_LDADD="-XCClinker -lc_r"
  54. THREADS_LDFLAGS=""
  55. + LIBS_LDFLAGS=""
  56. ## FreeBSD has pthreads rwlocks from version 3 (I think)
  57. # AC_DEFINE(HAVE_PTHREADS_RWLOCK,1,[Define HAVE_PTHREADS_RWLOCK if pthreads library supports rwlocks])
  58. ## 1:1 threads
  59. @@ -82,24 +85,28 @@ case "$host_os" in
  60. CFLAGS="-D_THREAD_SAFE $CFLAGS"
  61. THREADS_LDADD="-XCClinker -lthr"
  62. THREADS_LDFLAGS=""
  63. + LIBS_LDFLAGS=""
  64. ;;
  65. cygwin*)
  66. CFLAGS="-D_REENTRANT $CFLAGS"
  67. THREADS_LDADD="-lpthread"
  68. THREADS_LDFLAGS="";
  69. + LIBS_LDFLAGS="-no-undefined"
  70. iscygwin="yes"
  71. ;;
  72. *)
  73. CFLAGS="-D_REENTRANT $CFLAGS"
  74. THREADS_LDADD="-lpthread"
  75. THREADS_LDFLAGS=""
  76. + LIBS_LDFLAGS=""
  77. ;;
  78. esac
  79. TEST_LIBS="$TEST_LIBS $THREADS_LDADD"
  80. AC_SUBST(THREADS_LDADD)
  81. AC_SUBST(THREADS_LDFLAGS)
  82. +AC_SUBST(LIBS_LDFLAGS)
  83. AC_DEFINE_UNQUOTED(C_ICAP_CONFIGURE_OPTIONS, "$ac_configure_args",
  84. [configure command line used to configure c-icap])
  85. @@ -984,9 +991,6 @@ LIBS="$LIBS $EXTRALIBS"
  86. #Configure common flags
  87. MODULES_LIBADD=""
  88. -if test a"$iscygwin" != a; then
  89. - MODULES_LIBADD="-L../../ -licapapi"
  90. -fi
  91. MODULES_CFLAGS="$INVISIBILITY_CFLAG -DCI_BUILD_MODULE"
  92. AC_SUBST(MODULES_LIBADD)
  93. AC_SUBST(MODULES_CFLAGS)
  94. diff --git a/header.c b/header.c
  95. index 807a2e0..266b958 100644
  96. --- a/header.c
  97. +++ b/header.c
  98. @@ -110,21 +110,6 @@ const struct ci_error_code ci_error_codes[] = {
  99. {505, "Unsupported version"} /*ICAP version not supported by server. */
  100. };
  101. -/*
  102. -#ifdef __CYGWIN__
  103. -int ci_error_code(int ec){
  104. - return (ec >= EC_100 && ec < EC_MAX ? ci_error_codes[ec].code:1000);
  105. -}
  106. -
  107. -const char *unknownerrorcode = "UNKNOWN ERROR CODE";
  108. -
  109. -const char *ci_error_code_string(int ec){
  110. - return (ec >= EC_100 && ec < EC_MAX?ci_error_codes[ec].str:unknownerrorcode);
  111. -}
  112. -#endif
  113. -*/
  114. -
  115. -
  116. const char *ci_encaps_entities[] = {
  117. "req-hdr",
  118. "res-hdr",
  119. @@ -134,25 +119,6 @@ const char *ci_encaps_entities[] = {
  120. "opt-body"
  121. };
  122. -#ifdef __CYGWIN__
  123. -
  124. -const char *unknownentity = "UNKNOWN";
  125. -const char *unknownmethod = "UNKNOWN";
  126. -
  127. -const char *ci_method_string(int method)
  128. -{
  129. - return (method <= ICAP_RESPMOD
  130. - && method >= ICAP_OPTIONS ? CI_Methods[method] : unknownmethod);
  131. -}
  132. -
  133. -
  134. -const char *ci_encaps_entity_string(int e)
  135. -{
  136. - return (e <= ICAP_OPT_BODY
  137. - && e >= ICAP_REQ_HDR ? CI_EncapsEntities[e] : unknownentity);
  138. -}
  139. -#endif
  140. -
  141. ci_headers_list_t *ci_headers_create()
  142. {
  143. ci_headers_list_t *h;
  144. diff --git a/include/header.h b/include/header.h
  145. index 4cab365..ed2de88 100644
  146. --- a/include/header.h
  147. +++ b/include/header.h
  148. @@ -52,16 +52,8 @@ enum ci_encapsulated_entities {ICAP_REQ_HDR, ICAP_RES_HDR,
  149. };
  150. CI_DECLARE_DATA extern const char *ci_encaps_entities[];
  151. -#ifdef __CYGWIN__
  152. -
  153. -const char *ci_encaps_entity_string(int e);
  154. -
  155. -#else
  156. -
  157. #define ci_encaps_entity_string(e) (e <= ICAP_OPT_BODY && e >= ICAP_REQ_HDR?ci_encaps_entities[e]:"UNKNOWN")
  158. -#endif
  159. -
  160. /**
  161. \typedef ci_headers_list_t
  162. \ingroup HEADERS
  163. diff --git a/modules/Makefile.am b/modules/Makefile.am
  164. index e6e9270..2d43a60 100644
  165. --- a/modules/Makefile.am
  166. +++ b/modules/Makefile.am
  167. @@ -21,38 +21,44 @@ endif
  168. AM_CPPFLAGS=-I$(top_srcdir)/ -I$(top_srcdir)/include/ -I$(top_builddir)/include/
  169. -sys_logger_la_LIBADD = @MODULES_LIBADD@
  170. +if ISCYGWIN
  171. +MODS_LIB_ADD=$(top_builddir)/libicapapi.la
  172. +else
  173. +MODS_LIB_ADD=
  174. +endif
  175. +
  176. +sys_logger_la_LIBADD = $(MODS_LIB_ADD)
  177. sys_logger_la_CFLAGS= @MODULES_CFLAGS@ @OPENSSL_ADD_FLAG@
  178. -sys_logger_la_LDFLAGS= -module -avoid-version
  179. +sys_logger_la_LDFLAGS= -module -avoid-version @LIBS_LDFLAGS@
  180. sys_logger_la_SOURCES = sys_logger.c
  181. -dnsbl_tables_la_LIBADD = @MODULES_LIBADD@
  182. +dnsbl_tables_la_LIBADD = $(MODS_LIB_ADD)
  183. dnsbl_tables_la_CFLAGS= @MODULES_CFLAGS@ @OPENSSL_ADD_FLAG@
  184. -dnsbl_tables_la_LDFLAGS= -module -avoid-version
  185. +dnsbl_tables_la_LDFLAGS= -module -avoid-version @LIBS_LDFLAGS@
  186. dnsbl_tables_la_SOURCES = dnsbl_tables.c
  187. -perl_handler_la_LIBADD = @MODULES_LIBADD@ @perllib@ -L@perlcore@ -lperl
  188. +perl_handler_la_LIBADD = $(MODS_LIB_ADD) @perllib@ -L@perlcore@ -lperl
  189. perl_handler_la_CFLAGS= @MODULES_CFLAGS@ @perlccflags@ -I@perlcore@
  190. -perl_handler_la_LDFLAGS= -module -avoid-version @perlldflags@
  191. +perl_handler_la_LDFLAGS= -module -avoid-version @LIBS_LDFLAGS@ @perlldflags@
  192. perl_handler_la_SOURCES = perl_handler.c
  193. -bdb_tables_la_LIBADD = @MODULES_LIBADD@ @BDB_ADD_LDADD@
  194. +bdb_tables_la_LIBADD = $(MODS_LIB_ADD) @BDB_ADD_LDADD@
  195. bdb_tables_la_CFLAGS= @MODULES_CFLAGS@ @BDB_ADD_FLAG@
  196. -bdb_tables_la_LDFLAGS= -module -avoid-version
  197. +bdb_tables_la_LDFLAGS= -module -avoid-version @LIBS_LDFLAGS@
  198. bdb_tables_la_SOURCES = bdb_tables.c
  199. -ldap_module_la_LIBADD = @MODULES_LIBADD@ @LDAP_ADD_LDADD@ $(top_builddir)/libicapapi.la
  200. +ldap_module_la_LIBADD = $(MODS_LIB_ADD) @LDAP_ADD_LDADD@
  201. ldap_module_la_CFLAGS= @MODULES_CFLAGS@ @LDAP_ADD_FLAG@
  202. -ldap_module_la_LDFLAGS= -module -avoid-version
  203. +ldap_module_la_LDFLAGS= -module -avoid-version @LIBS_LDFLAGS@
  204. ldap_module_la_SOURCES = ldap_module.c
  205. -memcached_cache_la_LIBADD= @MODULES_LIBADD@ @MEMCACHED_ADD_LDADD@
  206. +memcached_cache_la_LIBADD= $(MODS_LIB_ADD) @MEMCACHED_ADD_LDADD@
  207. memcached_cache_la_CFLAGS= @MODULES_CFLAGS@ @MEMCACHED_ADD_FLAG@
  208. -memcached_cache_la_LDFLAGS= -module -avoid-version
  209. +memcached_cache_la_LDFLAGS= -module -avoid-version @LIBS_LDFLAGS@
  210. memcached_cache_la_SOURCES= memcached.c
  211. -shared_cache_la_LIBADD= @MODULES_LIBADD@
  212. +shared_cache_la_LIBADD= $(MODS_LIB_ADD)
  213. shared_cache_la_CFLAGS= @OPENSSL_ADD_FLAG@
  214. -shared_cache_la_LDFLAGS= -module -avoid-version
  215. +shared_cache_la_LDFLAGS= -module -avoid-version @LIBS_LDFLAGS@
  216. shared_cache_la_SOURCES= shared_cache.c
  217. diff --git a/modules/bdb_tables.c b/modules/bdb_tables.c
  218. index b8459be..1e908a9 100644
  219. --- a/modules/bdb_tables.c
  220. +++ b/modules/bdb_tables.c
  221. @@ -176,8 +176,8 @@ void *bdb_table_open(struct ci_lookup_table *table)
  222. /*We can not fork a Berkeley DB table, so we have to
  223. open bdb tables for every child, on childs start-up procedure*/
  224. - register_command_extend("openBDBtable", CHILD_START_CMD, table,
  225. - command_real_open_table);
  226. + ci_command_register_action("openBDBtable", CHILD_START_CMD, table,
  227. + command_real_open_table);
  228. return table->data;
  229. }
  230. @@ -257,3 +257,16 @@ void bdb_table_release_result(struct ci_lookup_table *table,void **val)
  231. {
  232. ci_buffer_free(val);
  233. }
  234. +
  235. + #ifdef __CYGWIN__
  236. +#include <w32api/windows.h>
  237. +void ci_command_register_action(const char *name, int type, void *data,
  238. + void (*command_action) (const char *name, int type, void *data))
  239. + {
  240. + typedef void (*RA)(const char *, int, void *, void(*)(const char *, int, void *));
  241. + RA fn;
  242. + fn = (RA)GetProcAddress(GetModuleHandle(NULL), "ci_command_register_action");
  243. + if (fn)
  244. + (*fn)(name, type, data, command_action);
  245. + }
  246. +#endif
  247. diff --git a/modules/shared_cache.c b/modules/shared_cache.c
  248. index 103b760..a79d51a 100644
  249. --- a/modules/shared_cache.c
  250. +++ b/modules/shared_cache.c
  251. @@ -345,3 +345,15 @@ void ci_shared_cache_destroy(struct ci_cache *cache)
  252. ci_shared_mem_detach(&data->id);
  253. }
  254. +#ifdef __CYGWIN__
  255. +#include <w32api/windows.h>
  256. +void ci_command_register_action(const char *name, int type, void *data,
  257. + void (*command_action) (const char *name, int type, void *data))
  258. + {
  259. + typedef void (*RA)(const char *, int, void *, void(*)(const char *, int, void *));
  260. + RA fn;
  261. + fn = (RA)GetProcAddress(GetModuleHandle(NULL), "ci_command_register_action");
  262. + if (fn)
  263. + (*fn)(name, type, data, command_action);
  264. + }
  265. +#endif
  266. diff --git a/modules/sys_logger.c b/modules/sys_logger.c
  267. index 1c47753..1764b0d 100644
  268. --- a/modules/sys_logger.c
  269. +++ b/modules/sys_logger.c
  270. @@ -60,7 +60,20 @@ int cfg_syslog_access(const char *directive, const char **argv, void *setdata);
  271. functions declared in log.c. This file is not included in c-icap library
  272. but defined in primary c-icap binary.
  273. */
  274. +#ifdef __CYGWIN__
  275. +#include <w32api/windows.h>
  276. +char *logformat_fmt(const char *name)
  277. +{
  278. + typedef char* (*LF_FMT)(const char *);
  279. + LF_FMT fn;
  280. + fn = (LF_FMT)GetProcAddress(GetModuleHandle(NULL), "logformat_fmt");
  281. + if (fn)
  282. + return (*fn)(name);
  283. + return NULL;
  284. +}
  285. +#else
  286. extern char *logformat_fmt(const char *name);
  287. +#endif
  288. /*Configuration Table .....*/
  289. static struct ci_conf_entry conf_variables[] = {
  290. diff --git a/services/echo/Makefile.am b/services/echo/Makefile.am
  291. index 402c8f9..7d701b1 100644
  292. --- a/services/echo/Makefile.am
  293. +++ b/services/echo/Makefile.am
  294. @@ -3,9 +3,15 @@ pkglib_LTLIBRARIES=srv_echo.la
  295. AM_CPPFLAGS=-I$(top_srcdir)/ -I$(top_srcdir)/include/ -I$(top_builddir)/include/
  296. -srv_echo_la_LIBADD = @MODULES_LIBADD@
  297. +if ISCYGWIN
  298. +MODS_LIB_ADD=$(top_builddir)/libicapapi.la
  299. +else
  300. +MODS_LIB_ADD=
  301. +endif
  302. +
  303. +srv_echo_la_LIBADD = $(MODS_LIB_ADD)
  304. srv_echo_la_CFLAGS= @MODULES_CFLAGS@ @OPENSSL_ADD_FLAG@
  305. -srv_echo_la_LDFLAGS= -module -avoid-version
  306. +srv_echo_la_LDFLAGS= -module -avoid-version @LIBS_LDFLAGS@
  307. srv_echo_la_SOURCES = srv_echo.c
  308. diff --git a/services/ex-206/Makefile.am b/services/ex-206/Makefile.am
  309. index 44bbf21..ff73399 100644
  310. --- a/services/ex-206/Makefile.am
  311. +++ b/services/ex-206/Makefile.am
  312. @@ -3,8 +3,14 @@ pkglib_LTLIBRARIES=srv_ex206.la
  313. AM_CPPFLAGS=-I$(top_srcdir)/ -I$(top_srcdir)/include/ -I$(top_builddir)/include/
  314. -srv_ex206_la_LIBADD = @MODULES_LIBADD@
  315. +if ISCYGWIN
  316. +MODS_LIB_ADD=$(top_builddir)/libicapapi.la
  317. +else
  318. +MODS_LIB_ADD=
  319. +endif
  320. +
  321. +srv_ex206_la_LIBADD = $(MODS_LIB_ADD)
  322. srv_ex206_la_CFLAGS= @MODULES_CFLAGS@ @OPENSSL_ADD_FLAG@
  323. -srv_ex206_la_LDFLAGS= -module -avoid-version
  324. +srv_ex206_la_LDFLAGS= -module -avoid-version @LIBS_LDFLAGS@
  325. srv_ex206_la_SOURCES = srv_ex206.c
  326. diff --git a/utils/c-icap-mkbdb.c b/utils/c-icap-mkbdb.c
  327. index c29a46f..326ee1c 100644
  328. --- a/utils/c-icap-mkbdb.c
  329. +++ b/utils/c-icap-mkbdb.c
  330. @@ -23,7 +23,7 @@ char *dbfile = NULL;
  331. int DUMP_MODE = 0;
  332. int VERSION_MODE = 0;
  333. int USE_DBTREE = 0;
  334. -long int PAGE_SIZE;
  335. +long int DB_PAGE_SIZE;
  336. ci_mem_allocator_t *allocator = NULL;
  337. int cfg_set_type(const char *directive, const char **argv, void *setdata);
  338. @@ -52,7 +52,7 @@ static struct ci_options_entry options[] = {
  339. "The type of values"
  340. },
  341. {
  342. - "-p", "page_size", &PAGE_SIZE, ci_cfg_size_long,
  343. + "-p", "page_size", &DB_PAGE_SIZE, ci_cfg_size_long,
  344. "The page size to use for the database"
  345. },
  346. {
  347. @@ -107,8 +107,8 @@ int open_db(char *path)
  348. return 0;
  349. }
  350. - if (PAGE_SIZE > 512 && PAGE_SIZE <= 64*1024)
  351. - db->set_pagesize(db, (uint32_t)PAGE_SIZE);
  352. + if (DB_PAGE_SIZE > 512 && DB_PAGE_SIZE <= 64*1024)
  353. + db->set_pagesize(db, (uint32_t)DB_PAGE_SIZE);
  354. if ((ret = db->open(db, NULL, path, NULL,
  355. (USE_DBTREE ? DB_BTREE : DB_HASH),