You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by pi...@locus.apache.org on 2000/11/29 13:23:22 UTC
cvs commit: jakarta-tomcat-4.0/connectors/webapplib Makefile wa.h wa_provider.h wa_provider_info.c wa_request.c wa_request.h
pier 00/11/29 04:23:19
Modified: connectors/apache-1.3 mod_webapp.c
connectors/webapplib Makefile wa.h wa_provider.h
wa_provider_info.c wa_request.c wa_request.h
Log:
Changed names in webapp request structure.
Major cleanup of the provider API.
Bugfix (memory leaks!)
Revision Changes Path
1.4 +24 -37 jakarta-tomcat-4.0/connectors/apache-1.3/mod_webapp.c
Index: mod_webapp.c
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/connectors/apache-1.3/mod_webapp.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- mod_webapp.c 2000/11/27 12:50:00 1.3
+++ mod_webapp.c 2000/11/29 12:22:43 1.4
@@ -55,7 +55,7 @@
* *
* ========================================================================= */
-// CVS $Id: mod_webapp.c,v 1.3 2000/11/27 12:50:00 pier Exp $
+// CVS $Id: mod_webapp.c,v 1.4 2000/11/29 12:22:43 pier Exp $
// Author: Pier Fumagalli <ma...@eng.sun.com>
#include <httpd.h>
@@ -155,7 +155,7 @@
// Create a new request structure
req=(wa_request *)ap_palloc(r->pool,sizeof(wa_request));
req->host=host;
- req->application=appl;
+ req->appl=appl;
// Set the webapp request structure into Apache's request structure
ap_set_module_config(r->request_config, &webapp_module, req);
@@ -177,10 +177,10 @@
// Set up basic parameters in the request structure
req->data=r;
- req->method=(char *)r->method;
- req->uri=r->uri;
- req->arguments=r->args;
- req->protocol=r->protocol;
+ req->meth=(char *)r->method;
+ req->ruri=r->uri;
+ req->args=r->args;
+ req->prot=r->protocol;
// Copy headers into webapp request structure
if (r->headers_in!=NULL) {
@@ -190,21 +190,21 @@
int x=0;
// Allocate memory for pointers
- req->header_count=count;
- req->header_names=(char **)ap_palloc(r->pool,count*sizeof(char *));
- req->header_values=(char **)ap_palloc(r->pool,count*sizeof(char *));
+ req->hnum=count;
+ req->hnam=(char **)ap_palloc(r->pool,count*sizeof(char *));
+ req->hval=(char **)ap_palloc(r->pool,count*sizeof(char *));
// Copy header pointers one by one
for (x=0; x<count;x++) {
if (ele[x].key==NULL) continue;
- req->header_names[x]=ele[x].key;
- req->header_values[x]=ele[x].val;
+ req->hnam[x]=ele[x].key;
+ req->hval[x]=ele[x].val;
}
} else {
fprintf(stderr,"NO HEADERS\n");
- req->header_count=0;
- req->header_names=NULL;
- req->header_values=NULL;
+ req->hnum=0;
+ req->hnam=NULL;
+ req->hval=NULL;
}
// Try to handle the request
@@ -220,28 +220,23 @@
}
/**
- * Destroy webapp connections.
+ * Initialize webapp connections.
+ *
+ * @param s The server_rec structure associated with the main server.
+ * @param p The pool for memory allocation (it never gets cleaned).
*/
-static void webapp_destroy(void *k) {
+static void webapp_exit(server_rec *s, pool *p) {
+ // Destroy connections
wa_connection_destroy();
}
/**
* Initialize webapp connections.
+ *
+ * @param s The server_rec structure associated with the main server.
+ * @param p The pool for memory allocation (it never gets cleaned).
*/
static void webapp_init(server_rec *s, pool *p) {
- // Register our cleanup function
-#ifdef WIN32
- // Under Win32 we clean up when the process exits, since web server
- // children are threads (sockets, connections and all the rest resides
- // in the same memory space.
- ap_register_cleanup(p, NULL, webapp_destroy, ap_null_cleanup);
-#else
- // Under UNIX we clean up when a child exists, since web server children
- // are processes, and not threads.
- ap_register_cleanup(p, NULL, ap_null_cleanup, webapp_destroy);
-#endif
-
// Initialize connections
wa_connection_init();
}
@@ -469,11 +464,7 @@
/* Apache module declaration */
module webapp_module = {
STANDARD_MODULE_STUFF,
-#ifdef WIN32
- webapp_init, /* module initializer */
-#else
NULL, /* module initializer */
-#endif
NULL, /* per-directory config creator */
NULL, /* dir config merger */
NULL, /* server config creator */
@@ -488,11 +479,7 @@
NULL, /* [8] fixups */
NULL, /* [10] logger */
NULL, /* [3] header parser */
-#ifdef WIN32
- NULL, /* child initializer */
-#else
webapp_init, /* child initializer */
-#endif
- NULL, /* child exit/cleanup */
+ webapp_exit, /* child exit/cleanup */
NULL /* [1] post read_request handling */
};
1.3 +2 -2 jakarta-tomcat-4.0/connectors/webapplib/Makefile
Index: Makefile
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/connectors/webapplib/Makefile,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Makefile 2000/11/29 09:01:37 1.2
+++ Makefile 2000/11/29 12:22:57 1.3
@@ -55,13 +55,13 @@
# #
# ========================================================================= #
-# CVS $Id: Makefile,v 1.2 2000/11/29 09:01:37 pier Exp $
+# CVS $Id: Makefile,v 1.3 2000/11/29 12:22:57 pier Exp $
# Author: Pier Fumagalli <ma...@eng.sun.com>
include ../Makedefs
OBJS = wa_callback.o wa_connection.o wa_host.o wa_provider.o wa_request.o \
- wa_provider_info.o
+ wa_provider_info.o wa_provider_warp.o
all: libwebapp.a
1.4 +7 -1 jakarta-tomcat-4.0/connectors/webapplib/wa.h
Index: wa.h
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/connectors/webapplib/wa.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- wa.h 2000/11/27 12:48:04 1.3
+++ wa.h 2000/11/29 12:23:00 1.4
@@ -55,7 +55,7 @@
* *
* ========================================================================= */
-// CVS $Id: wa.h,v 1.3 2000/11/27 12:48:04 pier Exp $
+// CVS $Id: wa.h,v 1.4 2000/11/29 12:23:00 pier Exp $
// Author: Pier Fumagalli <ma...@eng.sun.com>
#ifndef _WA_H_
@@ -64,8 +64,14 @@
/* Generic includes */
#include <stdio.h>
#include <stdlib.h>
+#include <unistd.h>
#include <stdarg.h>
#include <string.h>
+#include <netdb.h>
+#include <errno.h>
+#include <sys/errno.h>
+#include <sys/types.h>
+#include <sys/socket.h>
/* Define TRUE and FALSE */
#ifndef TRUE
1.3 +3 -3 jakarta-tomcat-4.0/connectors/webapplib/wa_provider.h
Index: wa_provider.h
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/connectors/webapplib/wa_provider.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- wa_provider.h 2000/11/27 03:49:18 1.2
+++ wa_provider.h 2000/11/29 12:23:02 1.3
@@ -55,7 +55,7 @@
* *
* ========================================================================= */
-// CVS $Id: wa_provider.h,v 1.2 2000/11/27 03:49:18 pier Exp $
+// CVS $Id: wa_provider.h,v 1.3 2000/11/29 12:23:02 pier Exp $
// Author: Pier Fumagalli <ma...@eng.sun.com>
#ifndef _WA_PROVIDER_H_
@@ -73,10 +73,10 @@
void (*init) (wa_connection *);
// Clean up a connection
void (*destroy) (wa_connection *);
- // Get a descriptive string on a connection (based on wa_connection->conf)
- char *(*describe) (wa_connection *);
// Handle an HTTP request
void (*handle) (wa_request *, wa_callbacks *);
+ // Get a descriptive string on a connection (based on wa_connection->conf)
+ int (*describe) (wa_connection *, char *, int);
};
/* The list of all compiled in providers */
1.4 +53 -36 jakarta-tomcat-4.0/connectors/webapplib/wa_provider_info.c
Index: wa_provider_info.c
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/connectors/webapplib/wa_provider_info.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- wa_provider_info.c 2000/11/27 12:48:11 1.3
+++ wa_provider_info.c 2000/11/29 12:23:04 1.4
@@ -55,11 +55,19 @@
* *
* ========================================================================= */
-// CVS $Id: wa_provider_info.c,v 1.3 2000/11/27 12:48:11 pier Exp $
+// CVS $Id: wa_provider_info.c,v 1.4 2000/11/29 12:23:04 pier Exp $
// Author: Pier Fumagalli <ma...@eng.sun.com>
#include <wa.h>
+/**
+ * Configure a connection with the parameter from the web server configuration
+ * file.
+ *
+ * @param conn The connection to configure.
+ * @param param The extra parameter from web server configuration.
+ * @return An error message or NULL.
+ */
static const char *wa_info_configure(wa_connection *conn, char *param) {
if(conn==NULL) return("Connection not specified");
if (param==NULL) conn->conf=strdup("[No data supplied]");
@@ -67,36 +75,43 @@
return(NULL);
}
-static char *wa_info_describe(wa_connection *conn) {
- char buf[1024];
-
- if(conn==NULL) return("Null connection specified");
- sprintf(buf, "%s", (char *)conn->conf);
- return(strdup(buf));
-}
-
+/**
+ * Describe the configuration member found in a connection.
+ *
+ * @param conn The connection for wich a description must be produced.
+ * @param buf The buffer where the description must be stored.
+ * @param len The buffer length.
+ * @return The number of bytes written to the buffer.
+ */
+static int wa_info_describe(wa_connection *conn, char *buf, int len) {
+ if ((buf==NULL)||(len==0)) return(0);
+
+ if(conn==NULL) return(strlcpy(buf,"Null connection specified",len));
+ return(strlcpy(buf,conn->conf,len));
+}
+
+/**
+ * Initialize a connection.
+ *
+ * @param conn The connection to initialize.
+ */
void wa_info_init(wa_connection *conn) {
}
+/**
+ * Destroys a connection.
+ *
+ * @param conn The connection to destroy.
+ */
void wa_info_destroy(wa_connection *conn) {
}
-void wa_info_printf(wa_request *req, wa_callbacks *cb, const char *fmt, ...) {
- va_list ap;
- char buf[1024];
- int ret;
- int tmp;
-
- va_start(ap,fmt);
- ret=vsnprintf(buf, 1024, fmt, ap);
- va_end(ap);
- if (ret<0) return;
-
- if ((tmp=(*cb->write)(req->data,buf,ret))!=ret) {
- (*cb->log)(req->data,WA_LOG,"Returned %d transmitted %d",tmp,ret);
- }
-}
-
+/**
+ * Handle a connection from the web server.
+ *
+ * @param req The request data.
+ * @param cb The web-server callback information.
+ */
void wa_info_handle(wa_request *req, wa_callbacks *cb) {
int x=0;
wa_connection *conn=wa_connections;
@@ -113,7 +128,7 @@
// Dump configured hosts and applications
while (conn!=NULL) {
- char *desc=NULL;
+ char desc[1024];
wa_callback_printf(cb,req," <dl>\n");
wa_callback_printf(cb,req," <dt><b>Connection: %s</b></dt>\n",
@@ -121,9 +136,10 @@
wa_callback_printf(cb,req," <dd>\n");
wa_callback_printf(cb,req," Provider "%s"\n",
conn->prov->name);
- desc=(*conn->prov->describe)(conn);
- if (desc!=NULL)
+ if ((*conn->prov->describe)(conn,desc,1024)>0)
wa_callback_printf(cb,req," (Descr.: "%s")\n",desc);
+ else
+ wa_callback_printf(cb,req," (No description available)\n");
wa_callback_printf(cb,req," </dd>\n");
conn=conn->next;
wa_callback_printf(cb,req," </dl>\n");
@@ -157,15 +173,15 @@
wa_callback_printf(cb,req," <dt><b>This request:</b></dt>\n");
wa_callback_printf(cb,req," <dd>\n");
wa_callback_printf(cb,req," <code>\n");
- wa_callback_printf(cb,req," %s",req->method);
- wa_callback_printf(cb,req," %s",req->uri);
- if (req->arguments!=NULL) wa_callback_printf(cb,req,"?%s",req->arguments);
- wa_callback_printf(cb,req," %s<br>\n",req->protocol);
+ wa_callback_printf(cb,req," %s",req->meth);
+ wa_callback_printf(cb,req," %s",req->ruri);
+ if (req->args!=NULL) wa_callback_printf(cb,req,"?%s",req->args);
+ wa_callback_printf(cb,req," %s<br>\n",req->prot);
// Dump the first line of the request
- for (x=0; x<req->header_count; x++)
- wa_callback_printf(cb,req," %s: %s<br>",req->header_names[x],
- req->header_values[x]);
+ for (x=0; x<req->hnum; x++)
+ wa_callback_printf(cb,req," %s: %s<br>",req->hnam[x],
+ req->hval[x]);
// Finish the request dump
wa_callback_printf(cb,req," </code>\n");
@@ -178,11 +194,12 @@
wa_callback_flush(cb,req);
}
+/** WebAppLib plugin description. */
wa_provider wa_provider_info = {
"info",
wa_info_configure,
wa_info_init,
wa_info_destroy,
- wa_info_describe,
wa_info_handle,
+ wa_info_describe,
};
1.3 +6 -6 jakarta-tomcat-4.0/connectors/webapplib/wa_request.c
Index: wa_request.c
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/connectors/webapplib/wa_request.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- wa_request.c 2000/11/27 03:49:19 1.2
+++ wa_request.c 2000/11/29 12:23:07 1.3
@@ -55,7 +55,7 @@
* *
* ========================================================================= */
-// CVS $Id: wa_request.c,v 1.2 2000/11/27 03:49:19 pier Exp $
+// CVS $Id: wa_request.c,v 1.3 2000/11/29 12:23:07 pier Exp $
// Author: Pier Fumagalli <ma...@eng.sun.com>
#include <wa.h>
@@ -66,11 +66,11 @@
if (cb==NULL) return("Callback structure pointer is NULL");
if (req==NULL) return("Request structure pointer is NULL");
if (req->host==NULL) return("Web application host is NULL");
- if (req->application==NULL) return("Web application structure is NULL");
- if (req->method==NULL) return("Request method is NULL");
- if (req->uri==NULL) return("Request URI is NULL ");
- if (req->protocol==NULL) return("Request protocol is NULL");
+ if (req->appl==NULL) return("Web application structure is NULL");
+ if (req->meth==NULL) return("Request method is NULL");
+ if (req->ruri==NULL) return("Request URI is NULL ");
+ if (req->prot==NULL) return("Request protocol is NULL");
- (*req->application->conn->prov->handle)(req,cb);
+ (*req->appl->conn->prov->handle)(req,cb);
return(NULL);
}
1.3 +11 -11 jakarta-tomcat-4.0/connectors/webapplib/wa_request.h
Index: wa_request.h
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/connectors/webapplib/wa_request.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- wa_request.h 2000/11/27 03:49:20 1.2
+++ wa_request.h 2000/11/29 12:23:09 1.3
@@ -55,7 +55,7 @@
* *
* ========================================================================= */
-// CVS $Id: wa_request.h,v 1.2 2000/11/27 03:49:20 pier Exp $
+// CVS $Id: wa_request.h,v 1.3 2000/11/29 12:23:09 pier Exp $
// Author: Pier Fumagalli <ma...@eng.sun.com>
#ifndef _WA_REQUEST_H_
@@ -65,16 +65,16 @@
* The wa_request structure embodies an HTTP request.
*/
struct wa_request {
- wa_host *host; // The host handling the request
- wa_application *application; // The application that needs to be called
- void *data; // The web-server specific callback data
- char *method; // The HTTP method (GET, POST)
- char *uri; // The HTTP URI requested
- char *arguments; // The HTTP query arguments
- char *protocol; // The HTTP protocol (HTTP/1.0, HTTP/1.1)
- int header_count; // The number of headers in this request
- char **header_names; // The array of header names
- char **header_values; // The array of header values
+ wa_host *host; // The host handling the request
+ wa_application *appl; // The application that needs to be called
+ void *data; // The web-server specific callback data
+ char *meth; // The HTTP method (GET, POST)
+ char *ruri; // The HTTP URI requested
+ char *args; // The HTTP query arguments
+ char *prot; // The HTTP protocol (HTTP/1.0, HTTP/1.1)
+ int hnum; // The number of headers in this request
+ char **hnam; // The array of header names
+ char **hval; // The array of header values
};
/* Function prototype declaration */