perl.cvs.mod_parrot
[Top] [All Lists]

[svn:mod_parrot] r363 - in mod_parrot/trunk: include src

Subject: [svn:mod_parrot] r363 - in mod_parrot/trunk: include src
From: jhorwitz@xxxxxxxxxxxx
Date: Sat, 19 Jul 2008 12:22:47 -0700 (PDT)
Newsgroups: perl.cvs.mod_parrot

Author: jhorwitz
Date: Sat Jul 19 12:22:46 2008
New Revision: 363

Modified:
   mod_parrot/trunk/include/mod_parrot.h
   mod_parrot/trunk/include/modparrot_config.h
   mod_parrot/trunk/src/modparrot_config.c
   mod_parrot/trunk/src/module.c

Log:
first pass at proxy functions for TAKE1, TAKE2 and TAKE3 directive types


Modified: mod_parrot/trunk/include/mod_parrot.h
==============================================================================
--- mod_parrot/trunk/include/mod_parrot.h       (original)
+++ mod_parrot/trunk/include/mod_parrot.h       Sat Jul 19 12:22:46 2008
@@ -16,6 +16,7 @@
  */
 
 #include "httpd.h"
+#include "http_config.h"
 
 /* apache handler name */
 #define MODPARROT_MAGIC "parrot-code"

Modified: mod_parrot/trunk/include/modparrot_config.h
==============================================================================
--- mod_parrot/trunk/include/modparrot_config.h (original)
+++ mod_parrot/trunk/include/modparrot_config.h Sat Jul 19 12:22:46 2008
@@ -73,6 +73,13 @@
 };
 typedef struct modparrot_dir_config modparrot_dir_config;
 
+struct modparrot_module_cmd_data
+{
+    Parrot_PMC func;     /* parrot callback sub */
+    Parrot_PMC cmd_data; /* directive-specific cmd_data */
+};
+typedef struct modparrot_module_cmd_data modparrot_module_cmd_data;
+
 void modparrot_recalc_options(modparrot_srv_config *);
 
 void *create_modparrot_srv_config(apr_pool_t *, server_rec *);
@@ -112,3 +119,11 @@
 const char *modparrot_cmd_add_type(cmd_parms *, void *, const char *, const 
char *);
 const char *modparrot_cmd_add_handler(cmd_parms *, void *, const char *, const 
char *);
 const char *modparrot_cmd_options(cmd_parms *, void *, const char *);
+
+/* for HLL apache modules */
+const char *modparrot_module_cmd_take1(cmd_parms *, void *, const char *);
+const char *modparrot_module_cmd_take12(cmd_parms *, void *, const char *,
+    const char*);
+const char *modparrot_module_cmd_take123(cmd_parms *, void *, const char *,
+    const char *, const char*);
+

Modified: mod_parrot/trunk/src/modparrot_config.c
==============================================================================
--- mod_parrot/trunk/src/modparrot_config.c     (original)
+++ mod_parrot/trunk/src/modparrot_config.c     Sat Jul 19 12:22:46 2008
@@ -298,6 +298,7 @@
     cfg = GET_SERVER_CONFIG(cmd);
     l = (modparrot_handler_info *)apr_array_push(cfg->preload);
 
+    /* XXX how do we get the context if we've already started? */
     if (!mp_is_started) {
         ctxp = modparrot_startup(cmd->pool, cmd->server);
     }
@@ -558,3 +559,70 @@
     }
     return errmsg;
 }
+
+static Parrot_PMC make_cmd_args_array(Parrot_Interp interp, apr_pool_t *p,
+    int nargs, ...)
+{
+    va_list ap;
+    Parrot_PMC args;
+    int i=0, typenum;
+
+    typenum = Parrot_PMC_typenum(interp, "SArray");
+    args = (Parrot_PMC)Parrot_PMC_new(interp, typenum);
+    Parrot_register_pmc(interp, args);
+    Parrot_PMC_set_intval(interp, args, nargs);
+
+    va_start(ap, nargs);
+    for (i = 0; i < nargs; i++) {
+        char *arg = va_arg(ap, char *);
+        Parrot_PMC_set_cstring_intkey(interp, args, i, arg);
+    }
+    va_end(ap);
+
+    return(args);
+}
+
+const char *modparrot_module_cmd_take1(cmd_parms *cmd, void *mconfig,
+                                       const char *arg)
+{
+    modparrot_context *ctxp;
+    Parrot_PMC args;
+    modparrot_module_cmd_data *data = cmd->cmd->cmd_data;
+    int ret;
+
+    ctxp = modparrot_startup(cmd->pool, cmd->server);
+    args = make_cmd_args_array(ctxp->interp, cmd->pool, 1, arg);
+    ret = Parrot_call_sub_ret_int(ctxp->interp, data->func, "IP", args);
+    return NULL;
+}
+
+const char *modparrot_module_cmd_take12(cmd_parms *cmd, void *mconfig,
+                                       const char *arg1,
+                                       const char *arg2)
+{
+    modparrot_context *ctxp;
+    Parrot_PMC args;
+    modparrot_module_cmd_data *data = cmd->cmd->cmd_data;
+    int ret;
+
+    ctxp = modparrot_startup(cmd->pool, cmd->server);
+    args = make_cmd_args_array(ctxp->interp, cmd->pool, 2, arg1, arg2);
+    ret = Parrot_call_sub_ret_int(ctxp->interp, data->func, "IP", args);
+    return NULL;
+}
+
+const char *modparrot_module_cmd_take123(cmd_parms *cmd, void *mconfig,
+                                       const char *arg1,
+                                       const char *arg2,
+                                       const char *arg3)
+{
+    modparrot_context *ctxp;
+    Parrot_PMC args;
+    modparrot_module_cmd_data *data = cmd->cmd->cmd_data;
+    int ret;
+
+    ctxp = modparrot_startup(cmd->pool, cmd->server);
+    args = make_cmd_args_array(ctxp->interp, cmd->pool, 3, arg1, arg2, arg3);
+    ret = Parrot_call_sub_ret_int(ctxp->interp, data->func, "IP", args);
+    return NULL;
+}

Modified: mod_parrot/trunk/src/module.c
==============================================================================
--- mod_parrot/trunk/src/module.c       (original)
+++ mod_parrot/trunk/src/module.c       Sat Jul 19 12:22:46 2008
@@ -75,6 +75,9 @@
     for (i = 0; i < num; i++) {
         Parrot_PMC val;
         Parrot_PMC cmd;
+        modparrot_module_cmd_data *data =
+            (modparrot_module_cmd_data *)apr_pcalloc(p,
+                sizeof(modparrot_module_cmd_data));
         cmd = Parrot_PMC_get_pmc_keyed_int(interp, cmd_array, i);
         val = Parrot_PMC_get_pmc_keyed_str(interp, cmd,
                                         MAKE_PARROT_STRING("name"));
@@ -84,11 +87,19 @@
                                         MAKE_PARROT_STRING("args_how"));
         cmds[i].args_how = Parrot_PMC_get_intval(interp, val);
 
-        val = Parrot_PMC_get_pmc_keyed_str(interp, cmd,
-                                        MAKE_PARROT_STRING("func"));
-        /* XXX need proxy function */
-        /* cmds[i].func = Parrot_PMC_get_cstring(interp, val); */
-        cmds[i].func = NULL;
+        switch(cmds[i].args_how) {
+            case TAKE1:
+                cmds[i].func = modparrot_module_cmd_take1;
+                break;
+            case TAKE12:
+                cmds[i].func = modparrot_module_cmd_take12;
+                break;
+            case TAKE123:
+                cmds[i].func = modparrot_module_cmd_take123;
+                break;
+            default: /* XXX how do we error out here??? */
+                break;
+        }
 
         val = Parrot_PMC_get_pmc_keyed_str(interp, cmd,
                                         MAKE_PARROT_STRING("req_override"));
@@ -97,6 +108,12 @@
         val = Parrot_PMC_get_pmc_keyed_str(interp, cmd,
                                         MAKE_PARROT_STRING("errmsg"));
         cmds[i].errmsg = Parrot_PMC_get_cstring(interp, val);
+
+        data->func = Parrot_PMC_get_pmc_keyed_str(interp, cmd,
+                                        MAKE_PARROT_STRING("func"));
+        data->cmd_data = Parrot_PMC_get_pmc_keyed_str(interp, cmd,
+                                        MAKE_PARROT_STRING("cmd_data"));
+        cmds[i].cmd_data = data;
     }
 
     modp->version       = MODULE_MAGIC_NUMBER_MAJOR;

<Prev in Thread] Current Thread [Next in Thread>
  • [svn:mod_parrot] r363 - in mod_parrot/trunk: include src, jhorwitz <=