summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBertrand Jacquin <beber@meleeweb.net>2012-12-04 20:24:44 +0100
committerBertrand Jacquin <beber@meleeweb.net>2012-12-04 20:24:44 +0100
commitdfa0b3c9f4206cad6515941566774d57ba6d24c7 (patch)
treee8e010db0cc19d688245c923ed06f2d632e22b70
parent[FEATURE] Implement rewrite AuthUserFile. (diff)
downloadmod_virtualvalue-dfa0b3c9f4206cad6515941566774d57ba6d24c7.tar.gz
[BUILD] Split code to al_<apache mod>.{c,h} to be more readable
-rw-r--r--Makefile19
-rw-r--r--al_alias.c30
-rw-r--r--al_alias.h6
-rw-r--r--al_authn_file.c30
-rw-r--r--al_authn_file.h6
-rw-r--r--al_core.c77
-rw-r--r--al_core.h10
-rw-r--r--al_dumb.c19
-rw-r--r--al_dumb.h6
-rw-r--r--al_php5.c32
-rw-r--r--al_php5.h6
-rw-r--r--mod_virtualvalue.c242
-rw-r--r--mod_virtualvalue.h39
13 files changed, 294 insertions, 228 deletions
diff --git a/Makefile b/Makefile
index 21eaefa..e8e000d 100644
--- a/Makefile
+++ b/Makefile
@@ -6,8 +6,21 @@ NAME = mod_virtualvalue
VERSION = $(shell sh -c 'git describe --tags --dirty=-dev 2> /dev/null')
SRC = \
+ al_alias.c \
+ al_authn_file.c \
+ al_core.c \
+ al_dumb.c \
+ al_php5.c \
mod_virtualvalue.c
+HEADER = \
+ al_alias.h \
+ al_authn_file.h \
+ al_core.h \
+ al_dumb.h \
+ al_php5.h \
+ mod_virtualvalue.h
+
DOC_FILES = \
test/vhost.conf
@@ -87,11 +100,11 @@ strip: strip-shared
$(NAME).a: $(SRC:c=o)
$(call quiet_cmd,AR,$@)
- $(Q)$(AR) cru $@ $<
+ $(Q)$(AR) cru $@ $^
$(NAME).so: $(SRC:c=o)
$(call quiet_cmd,LD,$@)
- $(Q)$(LD) -shared -z now -o $@ $< $(SPEC_LDFLAGS) $(LDFLAGS) -soname $@
+ $(Q)$(LD) -shared -z now -o $@ $^ $(SPEC_LDFLAGS) $(LDFLAGS) -soname $@
%.o: %.c
$(call quiet_cmd,CC,$@)
@@ -101,7 +114,7 @@ $(NAME).so: $(SRC:c=o)
$(call quiet_cmd,STRIP,$@)
$(Q)$(STRIP) $(STRIP_FLAGS) -o $@ $<
-$(NAME)-$(VERSION).tar: $(SRC) $(EXTRA_FILES) $(DOC_FILES)
+$(NAME)-$(VERSION).tar: $(SRC) $(HEADER) $(EXTRA_FILES) $(DOC_FILES)
$(call quiet_cmd,TAR,$@)
$(Q)$(TAR) cf $@ \
--transform "s,^,$(NAME)-$(VERSION)/," \
diff --git a/al_alias.c b/al_alias.c
new file mode 100644
index 0000000..c933083
--- /dev/null
+++ b/al_alias.c
@@ -0,0 +1,30 @@
+#include <httpd.h>
+#include <http_config.h>
+
+#include "mod_virtualvalue.h"
+#include "al_core.h"
+
+#include "al_alias.h"
+
+int vv_alter_scriptalias (int argc __U__, char **argv, request_rec *r) {
+ char *scriptalias;
+
+ if (!strstr(r->uri, argv[0]))
+ return (DECLINED);
+
+ scriptalias = vv_flat_arg (argv[1], r);
+
+ if (!scriptalias) {
+ VV_error("%s", "Can't build ScriptAlias");
+ return (DECLINED);
+ }
+
+ vv_core_docroot (r, scriptalias);
+
+ r->handler = "cgi-script";
+ apr_table_setn (r->notes, "alias-forced-type", r->handler);
+
+ VV_debug ("ScriptAlias: %s", scriptalias);
+
+ return (OK);
+}
diff --git a/al_alias.h b/al_alias.h
new file mode 100644
index 0000000..f7021f3
--- /dev/null
+++ b/al_alias.h
@@ -0,0 +1,6 @@
+#ifndef AL_ALIAS_H
+#define AL_ALIAS_H
+
+int vv_alter_scriptalias (int, char **, request_rec *);
+
+#endif /* AL_ALIAS_H */
diff --git a/al_authn_file.c b/al_authn_file.c
new file mode 100644
index 0000000..f5ced25
--- /dev/null
+++ b/al_authn_file.c
@@ -0,0 +1,30 @@
+#include <httpd.h>
+#include <http_config.h>
+
+#include "mod_virtualvalue.h"
+#include "al_authn_file.h"
+
+/* As declared in modules/aaa/mod_authn_file.c */
+extern module AP_MODULE_DECLARE_DATA authn_file_module;
+
+struct authn_file_config_rec {
+ char *pwfile;
+};
+
+int vv_alter_authuserfile (int argc __U__, char **argv, request_rec *r) {
+ struct authn_file_config_rec *conf;
+ char *authuserfile;
+
+ conf = ap_get_module_config(r->per_dir_config, &authn_file_module);
+ authuserfile = vv_flat_arg (argv[0], r);
+
+ if (!authuserfile) {
+ VV_error ("%s", "Can't build AuthUserFile");
+ return (DECLINED);
+ }
+
+ conf->pwfile = authuserfile;
+ ap_set_module_config (r->per_dir_config, &authn_file_module, conf);
+
+ return (OK);
+}
diff --git a/al_authn_file.h b/al_authn_file.h
new file mode 100644
index 0000000..eece7cc
--- /dev/null
+++ b/al_authn_file.h
@@ -0,0 +1,6 @@
+#ifndef AL_AUTHN_FILE_H
+#define AL_AUTHN_FILE_H
+
+int vv_alter_authuserfile (int, char **, request_rec *);
+
+#endif /* AL_AUTHN_FILE_H */
diff --git a/al_core.c b/al_core.c
new file mode 100644
index 0000000..ae35bb2
--- /dev/null
+++ b/al_core.c
@@ -0,0 +1,77 @@
+#include <httpd.h>
+#include <http_core.h>
+
+#include <apr_strings.h>
+
+#include "mod_virtualvalue.h"
+#include "al_core.h"
+
+int vv_core_docroot (request_rec *r, char *n_root) {
+ request_rec *top;
+ core_server_config *core;
+
+ /* First define the filename based on docroot */
+ if (r->uri)
+ r->filename = apr_pstrcat(r->pool, n_root, r->uri, NULL);
+ else
+ r->filename = apr_pstrcat(r->pool, n_root, NULL);
+
+ /* Then, also define core DOCUMENT_ROOT,
+ * so PHP and CGI have a correct DOCUMENT_ROOT env variable */
+ top = (r->main)? r->main : r;
+ core = (core_server_config *) ap_get_module_config (r->server->module_config, &core_module);
+
+ core->ap_document_root = apr_pstrdup(top->pool, n_root);
+
+ return (OK);
+}
+
+int vv_alter_docroot (int argc __U__, char **argv, request_rec *r) {
+ char *docroot;
+
+ docroot = vv_flat_arg (argv[0], r);
+
+ if (!docroot) {
+ VV_error("%s", "Can't build DocumentRoot");
+ return (DECLINED);
+ }
+
+ vv_core_docroot (r, docroot);
+
+ VV_debug("DocumentRoot: %s", docroot);
+
+ return (OK);
+}
+
+int vv_alter_serveradmin (int argc __U__, char **argv, request_rec *r) {
+ char *serveradmin;
+
+ serveradmin = vv_flat_arg (argv[0], r);
+
+ if (!serveradmin) {
+ VV_error ("%s", "Can't build ServerAdmin");
+ return (DECLINED);
+ }
+
+ r->server->server_admin = serveradmin;
+
+ VV_debug ("ServerAdmin: %s", serveradmin);
+
+ return (OK);
+}
+
+int vv_alter_servername (int argc __U__, char **argv, request_rec *r) {
+ char *servername;
+
+ servername = vv_flat_arg (argv[0], r);
+
+ if (!servername) {
+ VV_error ("%s", "Can't build ServerName");
+ return (DECLINED);
+ }
+
+ r->server->server_hostname = servername;
+ VV_debug ("ServerName: %s", servername);
+
+ return (OK);
+}
diff --git a/al_core.h b/al_core.h
new file mode 100644
index 0000000..c25abf5
--- /dev/null
+++ b/al_core.h
@@ -0,0 +1,10 @@
+#ifndef AL_CORE_H
+#define AL_CORE_H
+
+int vv_core_docroot (request_rec *, char *);
+
+int vv_alter_docroot (int, char **, request_rec *);
+int vv_alter_serveradmin (int, char **, request_rec *);
+int vv_alter_servername (int, char **, request_rec *);
+
+#endif /* AL_CORE_H */
diff --git a/al_dumb.c b/al_dumb.c
new file mode 100644
index 0000000..443abc8
--- /dev/null
+++ b/al_dumb.c
@@ -0,0 +1,19 @@
+#include <httpd.h>
+#include <http_config.h>
+
+#include "mod_virtualvalue.h"
+#include "al_dumb.h"
+
+int vv_echo (int argc __U__, char **argv, request_rec *r) {
+ char *s2;
+
+ VV_error("%s", "");
+ VV_error("Original: %s", argv[0]);
+
+ s2 = vv_flat_arg (argv[0], r);
+
+ VV_error("Translat: %s", s2);
+ VV_error("%s", "");
+
+ return (OK);
+}
diff --git a/al_dumb.h b/al_dumb.h
new file mode 100644
index 0000000..b37225b
--- /dev/null
+++ b/al_dumb.h
@@ -0,0 +1,6 @@
+#ifndef AL_DUMB_H
+#define AL_DUMB_H
+
+int vv_echo (int, char **, request_rec *);
+
+#endif /* AL_DUMB_H */
diff --git a/al_php5.c b/al_php5.c
new file mode 100644
index 0000000..6e75028
--- /dev/null
+++ b/al_php5.c
@@ -0,0 +1,32 @@
+#ifdef HAVE_PHP
+
+#include <httpd.h>
+#include <http_config.h>
+
+#include <zend.h>
+#include <zend_qsort.h>
+#include <zend_API.h>
+#include <zend_ini.h>
+#include <zend_alloc.h>
+#include <zend_operators.h>
+
+#include <php.h>
+#include <php_ini.h>
+
+#include "mod_virtualvalue.h"
+#include "al_php5.h"
+
+int vv_php_alter_ini (int argc __U__, char **argv, request_rec *r) {
+ char *arg;
+
+ VV_debug("Translating %s %s", argv[0], argv[1]);
+ arg = vv_flat_arg (argv[1], r);
+
+ if (zend_alter_ini_entry(argv[0], strlen(argv[0]) + 1, arg, strlen(arg), PHP_INI_SYSTEM, PHP_INI_STAGE_STARTUP) == -1)
+ VV_error("zend_alter_ini_entry() failed (%s %s)", argv[0], arg);
+
+ VV_debug("Altered to %s %s", argv[0], arg);
+
+ return (OK);
+}
+#endif /* HAVE_PHP */
diff --git a/al_php5.h b/al_php5.h
new file mode 100644
index 0000000..61f7150
--- /dev/null
+++ b/al_php5.h
@@ -0,0 +1,6 @@
+#ifndef AL_PHP5_H
+#define AL_PHP5_H
+
+int vv_php_alter_ini (int, char **, request_rec *);
+
+#endif /* AL_PHP5_H */
diff --git a/mod_virtualvalue.c b/mod_virtualvalue.c
index 58f5e0c..d7455d7 100644
--- a/mod_virtualvalue.c
+++ b/mod_virtualvalue.c
@@ -5,77 +5,27 @@
* mod_virtualvalue
*/
-#define CORE_PRIVATE
-
-#include "apr_strings.h"
-#include "apr_fnmatch.h"
-#include "apr_strings.h"
-#include "apr_lib.h"
-
-#define APR_WANT_STRFUNC
-#include "apr_want.h"
-
-#include "ap_config.h"
#include "httpd.h"
-#include "http_config.h"
-#include "http_core.h"
#include "http_request.h"
-#include "http_protocol.h"
#include "http_log.h"
-#include "http_main.h"
-#include "util_script.h"
-#include "mod_core.h"
+#include "apr_strings.h"
#include <sys/stat.h>
-#ifdef HAVE_PHP
- #include <zend.h>
- #include <zend_qsort.h>
- #include <zend_API.h>
- #include <zend_ini.h>
- #include <zend_alloc.h>
- #include <zend_operators.h>
-
- #include <php.h>
- #include <php_ini.h>
-#endif /* HAVE_PHP */
-
-module AP_MODULE_DECLARE_DATA virtualvalue_module;
-
-#define DEFAULT_MAX_SIZE 8192
-#define DEFAULT_MAX_SEARCH 1024
+#include "mod_virtualvalue.h"
-#define HAVE___ATTRIBUTE__ 1
-
-#if HAVE___ATTRIBUTE__
-# define __UNUSED__ __attribute__((unused))
-# define __U__ __attribute__((unused))
-#else
-# define __UNUSED__
-# define __U__
-#endif /* HAVE___ATTRIBUTE__ */
+#include "al_alias.h"
+#include "al_authn_file.h"
+#include "al_core.h"
+#include "al_dumb.h"
+#include "al_php5.h"
#ifdef DEBUG
-#warning DEBUG is ON, this will slow every processing. You are warned !
-# define VV_debug(fmt, args...) \
- do { \
- fprintf (stderr, "%s+%i %*s(): DEBUG ", __FILE__, __LINE__, 20, __func__); \
- fprintf (stderr, fmt, ##args); \
- fprintf (stderr, "\n"); \
- fflush (stderr); \
- } while(0)
-#else
-# define VV_debug(fmt, args...) { }
+# warning DEBUG is ON, this will slow every processing. You are warned !
#endif /* DEBUG */
-#define VV_error(fmt, args...) \
-do { \
- fprintf (stderr, "%s+%i %*s(): ERROR ", __FILE__, __LINE__, 20, __func__); \
- fprintf (stderr, fmt, ##args); \
- fprintf (stderr, "\n"); \
- fflush (stderr); \
-} while(0)
+module AP_MODULE_DECLARE_DATA virtualvalue_module;
typedef struct {
char *tok;
@@ -137,16 +87,6 @@ static virtualvalue_var_t *vv_var_append (virtualvalue_var_t *list, virtualvalue
return list;
}
-#ifdef HAVE_PHP
-static int vv_php_alter_ini (int argc, char **argv, request_rec *r);
-#endif /* HAVE_PHP */
-static int vv_alter_docroot (int argc, char **argv, request_rec *r);
-static int vv_alter_scriptalias (int argc, char **argv, request_rec *r);
-static int vv_alter_serveradmin (int argc, char **argv, request_rec *r);
-static int vv_alter_servername (int argc, char **argv, request_rec *r);
-static int vv_alter_authuserfile (int argc, char **argv, request_rec *r);
-static int vv_echo (int argc, char **argv, request_rec *r);
-
static const char *vv_replace_HTTP (char *full __U__, char *search, request_rec *r);
static const char *vv_replace_ENV (char *full __U__, char *search, request_rec *r);
static const char *vv_replace_SYM (char *full __U__, char *search, request_rec *r);
@@ -158,14 +98,14 @@ token_t token_tab[] = {
{ "php_value" , 9 , vv_php_alter_ini },
{ "php_flag" , 8 , vv_php_alter_ini },
{ "php_admin_value" , 15, vv_php_alter_ini },
- { "php_admin_flag" , 14, vv_php_alter_ini },
+ { "php_admin_flag" , 14, vv_php_alter_ini }, // mod_php5
#endif /* HAVE_PHP */
- { "DocumentRoot" , 13, vv_alter_docroot },
- { "ScriptAlias" , 12, vv_alter_scriptalias },
- { "ServerAdmin" , 12, vv_alter_serveradmin },
- { "ServerName" , 11, vv_alter_servername },
- { "AuthUserFile" , 13, vv_alter_authuserfile },
- { "echo" , 5 , vv_echo },
+ { "DocumentRoot" , 13, vv_alter_docroot }, // core
+ { "ScriptAlias" , 12, vv_alter_scriptalias }, // mod_alias
+ { "ServerAdmin" , 12, vv_alter_serveradmin }, // core
+ { "ServerName" , 11, vv_alter_servername }, // core
+ { "AuthUserFile" , 13, vv_alter_authuserfile }, // mod_authn_file
+ { "echo" , 5 , vv_echo }, // generic
{ NULL , 0 , NULL }
};
@@ -249,7 +189,7 @@ static const char *vv_replace_SYM (char *full __U__, char *search, request_rec *
return (real);
}
-static char *vv_flat_arg (char *s1, request_rec *r) {
+char *vv_flat_arg (char *s1, request_rec *r) {
char *c, *end;
const char *s2;
@@ -292,154 +232,6 @@ static char *vv_flat_arg (char *s1, request_rec *r) {
return apr_pstrndup(r->pool, final, strlen(final));
}
-static int vv_echo (int argc __U__, char **argv, request_rec *r) {
- char *s2;
-
- VV_error("%s", "");
- VV_error("Original: %s", argv[0]);
-
- s2 = vv_flat_arg (argv[0], r);
-
- VV_error("Translat: %s", s2);
- VV_error("%s", "");
-
- return (OK);
-}
-
-#ifdef HAVE_PHP
-static int vv_php_alter_ini (int argc __U__, char **argv, request_rec *r) {
- char *arg;
-
- VV_debug("Translating %s %s", argv[0], argv[1]);
- arg = vv_flat_arg (argv[1], r);
-
- if (zend_alter_ini_entry(argv[0], strlen(argv[0]) + 1, arg, strlen(arg), PHP_INI_SYSTEM, PHP_INI_STAGE_STARTUP) == -1)
- VV_error("zend_alter_ini_entry() failed (%s %s)", argv[0], arg);
-
- VV_debug("Altered to %s %s", argv[0], arg);
-
- return (OK);
-}
-#endif /* HAVE_PHP */
-
-static int vv_core_docroot (request_rec *r, char *n_root) {
- request_rec *top;
- core_server_config *core;
-
- /* First define the filename based on docroot */
- if (r->uri)
- r->filename = apr_pstrcat(r->pool, n_root, r->uri, NULL);
- else
- r->filename = apr_pstrcat(r->pool, n_root, NULL);
-
- /* Then, also define core DOCUMENT_ROOT,
- * so PHP and CGI have a correct DOCUMENT_ROOT env variable */
- top = (r->main)? r->main : r;
- core = (core_server_config *) ap_get_module_config (r->server->module_config, &core_module);
-
- core->ap_document_root = apr_pstrdup(top->pool, n_root);
-
- return (OK);
-}
-
-static int vv_alter_docroot (int argc __U__, char **argv, request_rec *r) {
- char *docroot;
-
- docroot = vv_flat_arg (argv[0], r);
-
- if (!docroot) {
- VV_error("%s", "Can't build DocumentRoot");
- return (DECLINED);
- }
-
- vv_core_docroot (r, docroot);
-
- VV_debug("DocumentRoot: %s", docroot);
-
- return (OK);
-}
-
-static int vv_alter_scriptalias (int argc __U__, char **argv, request_rec *r) {
- char *scriptalias;
-
- if (!strstr(r->uri, argv[0]))
- return (DECLINED);
-
- scriptalias = vv_flat_arg (argv[1], r);
-
- if (!scriptalias) {
- VV_error("%s", "Can't build ScriptAlias");
- return (DECLINED);
- }
-
- vv_core_docroot (r, scriptalias);
-
- r->handler = "cgi-script";
- apr_table_setn (r->notes, "alias-forced-type", r->handler);
-
- VV_debug ("ScriptAlias: %s", scriptalias);
-
- return (OK);
-}
-
-static int vv_alter_serveradmin (int argc __U__, char **argv, request_rec *r) {
- char *serveradmin;
-
- serveradmin = vv_flat_arg (argv[0], r);
-
- if (!serveradmin) {
- VV_error ("%s", "Can't build ServerAdmin");
- return (DECLINED);
- }
-
- r->server->server_admin = serveradmin;
-
- VV_debug ("ServerAdmin: %s", serveradmin);
-
- return (OK);
-}
-
-static int vv_alter_servername (int argc __U__, char **argv, request_rec *r) {
- char *servername;
-
- servername = vv_flat_arg (argv[0], r);
-
- if (!servername) {
- VV_error ("%s", "Can't build ServerName");
- return (DECLINED);
- }
-
- r->server->server_hostname = servername;
- VV_debug ("ServerName: %s", servername);
-
- return (OK);
-}
-
-/* As declared in modules/aaa/mod_authn_file.c */
-extern module AP_MODULE_DECLARE_DATA authn_file_module;
-
-struct authn_file_config_rec {
- char *pwfile;
-};
-
-static int vv_alter_authuserfile (int argc __U__, char **argv, request_rec *r) {
- struct authn_file_config_rec *conf;
- char *authuserfile;
-
- conf = ap_get_module_config(r->per_dir_config, &authn_file_module);
- authuserfile = vv_flat_arg (argv[0], r);
-
- if (!authuserfile) {
- VV_error ("%s", "Can't build AuthUserFile");
- return (DECLINED);
- }
-
- conf->pwfile = authuserfile;
- ap_set_module_config (r->per_dir_config, &authn_file_module, conf);
-
- return (OK);
-}
-
static void *vv_create_server_config (apr_pool_t *p, server_rec *s __U__) {
virtualvalue_cfg_t *cfg = (virtualvalue_cfg_t *)apr_pcalloc(p, sizeof(virtualvalue_cfg_t));
diff --git a/mod_virtualvalue.h b/mod_virtualvalue.h
new file mode 100644
index 0000000..7c1270a
--- /dev/null
+++ b/mod_virtualvalue.h
@@ -0,0 +1,39 @@
+#ifndef MOD_VIRTUALVALUE_H
+#define MOD_VIRTUALVALUE_H
+
+#define DEFAULT_MAX_SIZE 8192
+#define DEFAULT_MAX_SEARCH 1024
+
+#define HAVE___ATTRIBUTE__ 1
+
+#if HAVE___ATTRIBUTE__
+# define __UNUSED__ __attribute__((unused))
+# define __U__ __attribute__((unused))
+#else
+# define __UNUSED__
+# define __U__
+#endif /* HAVE___ATTRIBUTE__ */
+
+#ifdef DEBUG
+# define VV_debug(fmt, args...) \
+ do { \
+ fprintf (stderr, "%s+%i %*s(): DEBUG ", __FILE__, __LINE__, 20, __func__); \
+ fprintf (stderr, fmt, ##args); \
+ fprintf (stderr, "\n"); \
+ fflush (stderr); \
+ } while(0)
+#else
+# define VV_debug(fmt, args...) { }
+#endif /* DEBUG */
+
+#define VV_error(fmt, args...) \
+do { \
+ fprintf (stderr, "%s+%i %*s(): ERROR ", __FILE__, __LINE__, 20, __func__); \
+ fprintf (stderr, fmt, ##args); \
+ fprintf (stderr, "\n"); \
+ fflush (stderr); \
+} while(0)
+
+char *vv_flat_arg (char *, request_rec *);
+
+#endif /* MOD_VIRTUALVALUE_H */