You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by js...@apache.org on 2006/11/23 20:26:40 UTC

svn commit: r478647 - /incubator/tuscany/cpp/sca/runtime/extensions/rest/service/httpd/src/tuscany/sca/rest/ModREST.cpp

Author: jsdelfino
Date: Thu Nov 23 11:26:39 2006
New Revision: 478647

URL: http://svn.apache.org/viewvc?view=rev&rev=478647
Log:
Changed the HTTPD configuration commands to allow the Tuscany runtime install directory to be configured on a server basis, and the other configuration (tuscany system root and search path) to be configured on a location/directory basis. Also added temporary HTML generation to the HTTPD handler to print the current configuration.

Modified:
    incubator/tuscany/cpp/sca/runtime/extensions/rest/service/httpd/src/tuscany/sca/rest/ModREST.cpp

Modified: incubator/tuscany/cpp/sca/runtime/extensions/rest/service/httpd/src/tuscany/sca/rest/ModREST.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sca/runtime/extensions/rest/service/httpd/src/tuscany/sca/rest/ModREST.cpp?view=diff&rev=478647&r1=478646&r2=478647
==============================================================================
--- incubator/tuscany/cpp/sca/runtime/extensions/rest/service/httpd/src/tuscany/sca/rest/ModREST.cpp (original)
+++ incubator/tuscany/cpp/sca/runtime/extensions/rest/service/httpd/src/tuscany/sca/rest/ModREST.cpp Thu Nov 23 11:26:39 2006
@@ -39,26 +39,30 @@
 {                                                                                   
 
 /* Configuration structure populated by apache2.conf */
-typedef struct rest_config_rec
+typedef struct rest_server_config_rec
 {
     char * home;
+} rest_server_config_rec_t;
+
+typedef struct rest_dir_config_rec
+{
     char * root;
     char * path;
     char * component;
-} rest_config_rec_t;
+} rest_dir_config_rec_t;
 
-extern module AP_MODULE_DECLARE_DATA rest_module;
+extern module AP_MODULE_DECLARE_DATA sca_rest_module;
 
 static const char *rest_set_home(cmd_parms *cmd, void *dummy, 
                         const char *arg);
                         
-static const char *rest_set_path(cmd_parms *cmd, void *dummy, 
+static const char *rest_set_path(cmd_parms *cmd, void *conf, 
                         const char *arg);
                         
-static const char *rest_set_root(cmd_parms *cmd, void *dummy, 
+static const char *rest_set_root(cmd_parms *cmd, void *conf, 
                         const char *arg);
                         
-static const char *rest_set_component(cmd_parms *cmd, void *dummy, 
+static const char *rest_set_component(cmd_parms *cmd, void *conf, 
                         const char *arg);
 
 static void* rest_create_svr(apr_pool_t *p, server_rec *s);
@@ -67,35 +71,32 @@
 static const char *rest_set_home(cmd_parms *cmd, void *dummy, 
                         const char *arg)
 {
-    rest_config_rec_t *conf = (rest_config_rec_t*)ap_get_module_config(
-                        cmd->server->module_config, &rest_module);
+    rest_server_config_rec_t *conf = (rest_server_config_rec_t*)ap_get_module_config(
+                        cmd->server->module_config, &sca_rest_module);
     conf->home = apr_pstrdup(cmd->pool, arg);
     return NULL;
 }
 
-static const char *rest_set_path(cmd_parms *cmd, void *dummy, 
+static const char *rest_set_path(cmd_parms *cmd, void *c, 
                         const char *arg)
 {
-    rest_config_rec_t *conf = (rest_config_rec_t*)ap_get_module_config(
-                        cmd->server->module_config, &rest_module);
+    rest_dir_config_rec_t *conf = (rest_dir_config_rec_t*)c;
     conf->path = apr_pstrdup(cmd->pool, arg);
     return NULL;
 }
 
-static const char *rest_set_root(cmd_parms *cmd, void *dummy, 
+static const char *rest_set_root(cmd_parms *cmd, void *c, 
                         const char *arg)
 {
-    rest_config_rec_t *conf = (rest_config_rec_t*)ap_get_module_config(
-                        cmd->server->module_config, &rest_module);
+    rest_dir_config_rec_t *conf = (rest_dir_config_rec_t*)c;
     conf->root = apr_pstrdup(cmd->pool, arg);
     return NULL;
 }
 
-static const char *rest_set_component(cmd_parms *cmd, void *dummy, 
+static const char *rest_set_component(cmd_parms *cmd, void *c, 
                         const char *arg)
 {
-    rest_config_rec_t *conf = (rest_config_rec_t*)ap_get_module_config(
-                        cmd->server->module_config, &rest_module);
+    rest_dir_config_rec_t *conf = (rest_dir_config_rec_t*)c;
     conf->component = apr_pstrdup(cmd->pool, arg);
     return NULL;
 }
@@ -103,7 +104,7 @@
 
 static const command_rec rest_module_cmds[] = 
 {
-    AP_INIT_TAKE1("TuscanyHome", (const char*(*)())rest_set_home, NULL, ACCESS_CONF,
+    AP_INIT_TAKE1("TuscanyHome", (const char*(*)())rest_set_home, NULL, RSRC_CONF,
                   "Tuscany home directory"),
     AP_INIT_TAKE1("TuscanyPath", (const char*(*)())rest_set_path, NULL, ACCESS_CONF,
                   "Tuscany SCA composite search path"),
@@ -115,8 +116,57 @@
 };
 
 
-static int rest_handler(request_rec *r)
+static int rest_handler(request_rec *request)
 {
+    
+    if (strcmp(request->handler, "sca_rest_module"))
+    {
+        return DECLINED;
+    }
+    
+    // Set up the read policy
+    int rc = ap_setup_client_block(request, REQUEST_CHUNKED_DECHUNK);
+    if (rc != OK)
+    {
+        return rc;
+    }
+    ap_should_client_block(request);
+    
+    const char* http_version = request->protocol;
+    
+    const char* content_type = apr_table_get(request->headers_in, "Content-Type");
+    request->content_type = content_type;
+    
+    int content_length = request->remaining;
+    if (request->read_chunked == true && content_length == 0)
+    {
+        content_length = -1;
+        request->chunked = true;
+    }
+
+    // Set the content type    
+    ap_set_content_type(request, "text/html");
+    
+    // Send the response document
+    ap_rputs("<html><body><p>mod_rest works!", request);
+
+    rest_server_config_rec_t* server_conf = (rest_server_config_rec_t*)ap_get_module_config(request->server->module_config, &sca_rest_module);
+    ap_rprintf(request, "<p>home: %s", server_conf->home);
+
+    rest_dir_config_rec_t* dir_conf = (rest_dir_config_rec_t*)ap_get_module_config(request->per_dir_config, &sca_rest_module);
+    ap_rprintf(request, "<p>root: %s", dir_conf->root);
+    if (dir_conf->path)
+    {
+        ap_rprintf(request, "<p>path: %s", dir_conf->path);
+    }
+    if (dir_conf->path)
+    {
+        ap_rprintf(request, "<p>component: %s", dir_conf->component);
+    }
+    
+    ap_rputs("</body></html>", request);
+    
+    //return HTTP_INTERNAL_SERVER_ERROR;
     return OK;
 }
 
@@ -128,10 +178,9 @@
 
 static void rest_child_init(apr_pool_t* p, server_rec* svr_rec)
 {
-    rest_config_rec_t *conf = (rest_config_rec_t*)ap_get_module_config(
-                        svr_rec->module_config, &rest_module); 
+    rest_server_config_rec_t *conf = (rest_server_config_rec_t*)ap_get_module_config(
+                        svr_rec->module_config, &sca_rest_module); 
 
-    
     if(false)
     {
         fprintf(stderr, "[Tuscany] Due to one or more errors mod_rest loading"
@@ -147,26 +196,31 @@
     ap_hook_child_init(rest_child_init, NULL, NULL, APR_HOOK_MIDDLE);
 }
 
-static void* rest_create_svr(apr_pool_t *p, server_rec *s)
+static void *rest_create_dir_config(apr_pool_t *p, char *dirspec)
 {
-    rest_config_rec_t* conf = (rest_config_rec_t* )apr_palloc(p, sizeof(*conf));
-    conf->home = NULL;
+    rest_dir_config_rec_t* conf = (rest_dir_config_rec_t* )apr_palloc(p, sizeof(*conf));
     conf->path = NULL;
     conf->root = NULL;
     conf->component = NULL;
     return conf;
 }
 
-module AP_MODULE_DECLARE_DATA rest_module =
+static void* rest_create_server_config(apr_pool_t *p, server_rec *s)
+{
+    rest_server_config_rec_t* conf = (rest_server_config_rec_t* )apr_palloc(p, sizeof(*conf));
+    conf->home = NULL;
+    return conf;
+}
+
+module AP_MODULE_DECLARE_DATA sca_rest_module =
 {
     STANDARD20_MODULE_STUFF,
-    NULL,                       /* dir config creater */
+    rest_create_dir_config,         /* dir config */
     NULL,                       /* dir merger --- default is to override */
-    rest_create_svr,        /* server config */
+    rest_create_server_config,        /* server config */
     NULL,                       /* merge server config */
     rest_module_cmds,         /* command table */
     register_hooks              /* register_hooks */
 };
-
 
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org