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/27 13:48:22 UTC
cvs commit: jakarta-tomcat-4.0/connectors/src/webapplib Makefile wa_callback.c wa_callback.h wa.h wa_host.c wa_provider_info.c
pier 00/11/27 04:48:18
Modified: connectors/src/webapplib wa.h wa_host.c wa_provider_info.c
Added: connectors/src/webapplib Makefile wa_callback.c
wa_callback.h
Log:
Better specification of callback information
Revision Changes Path
1.3 +2 -90 jakarta-tomcat-4.0/connectors/src/webapplib/wa.h
Index: wa.h
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/connectors/src/webapplib/wa.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- wa.h 2000/11/27 03:49:15 1.2
+++ wa.h 2000/11/27 12:48:04 1.3
@@ -55,7 +55,7 @@
* *
* ========================================================================= */
-// CVS $Id: wa.h,v 1.2 2000/11/27 03:49:15 pier Exp $
+// CVS $Id: wa.h,v 1.3 2000/11/27 12:48:04 pier Exp $
// Author: Pier Fumagalli <ma...@eng.sun.com>
#ifndef _WA_H_
@@ -94,94 +94,6 @@
#include <wa_connection.h>
#include <wa_provider.h>
#include <wa_request.h>
-
-/**
- * The wa_callbacks structure contains function pointers for callbacks to the
- * web server.
- */
-struct wa_callbacks {
- /**
- * Log data on the web server log file.
- *
- * @param file The source file of this log entry.
- * @param line The line number within the source file of this log entry.
- * @param data The web-server specific data (wa_request->data).
- * @param fmt The format string (printf style).
- * @param ... All other parameters (if any) depending on the format.
- */
- void (*log)(void *data, const char *file, int line, const char *fmt, ...);
-
- /**
- * Allocate memory while processing a request.
- *
- * @param data The web-server specific data (wa_request->data).
- * @param size The size in bytes of the memory to allocate.
- * @return A pointer to the allocated memory or NULL.
- */
- void *(*alloc)(void *data, int size);
-
- /**
- * Read part of the request content.
- *
- * @param data The web-server specific data (wa_request->data).
- * @param buf The buffer that will hold the data.
- * @param len The buffer length.
- * @return The number of bytes read, 0 on end of file or -1 on error.
- */
- int (*read)(void *data, char *buf, int len);
-
- /**
- * Set the HTTP response status code.
- *
- * @param data The web-server specific data (wa_request->data).
- * @param status The HTTP status code for the response.
- * @return TRUE on success, FALSE otherwise
- */
- boolean (*setstatus)(void *data, int status);
-
- /**
- * Set the HTTP response mime content type.
- *
- * @param data The web-server specific data (wa_request->data).
- * @param type The mime content type of the HTTP response.
- * @return TRUE on success, FALSE otherwise
- */
- boolean (*settype)(void *data, char *type);
-
- /**
- * Set an HTTP mime header.
- *
- * @param data The web-server specific data (wa_request->data).
- * @param name The mime header name.
- * @param value The mime header value.
- * @return TRUE on success, FALSE otherwise
- */
- boolean (*setheader)(void *data, char *name, char *value);
-
- /**
- * Commit the first part of the response (status and headers).
- *
- * @param data The web-server specific data (wa_request->data).
- * @return TRUE on success, FALSE otherwise
- */
- boolean (*commit)(void *data);
-
- /**
- * Write part of the response data back to the client.
- *
- * @param buf The buffer holding the data to be written.
- * @param len The number of characters to be written.
- * @return The number of characters written to the client or -1 on error.
- */
- int (*write)(void *data, char *buf, int len);
-
- /**
- * Flush any unwritten response data to the client.
- *
- * @param data The web-server specific data (wa_request->data).
- * @return TRUE on success, FALSE otherwise
- */
- boolean (*flush)(void *);
-};
+#include <wa_callback.h>
#endif // ifdef _WA_H_
1.3 +2 -2 jakarta-tomcat-4.0/connectors/src/webapplib/wa_host.c
Index: wa_host.c
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/connectors/src/webapplib/wa_host.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- wa_host.c 2000/11/27 03:49:17 1.2
+++ wa_host.c 2000/11/27 12:48:10 1.3
@@ -55,13 +55,13 @@
* *
* ========================================================================= */
-// CVS $Id: wa_host.c,v 1.2 2000/11/27 03:49:17 pier Exp $
+// CVS $Id: wa_host.c,v 1.3 2000/11/27 12:48:10 pier Exp $
// Author: Pier Fumagalli <ma...@eng.sun.com>
#include <wa.h>
/* The list of configured hosts */
-static wa_host *wa_hosts=NULL;
+wa_host *wa_hosts=NULL;
/**
* Create configuration for a new host.
1.3 +80 -7 jakarta-tomcat-4.0/connectors/src/webapplib/wa_provider_info.c
Index: wa_provider_info.c
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/connectors/src/webapplib/wa_provider_info.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- wa_provider_info.c 2000/11/27 03:49:19 1.2
+++ wa_provider_info.c 2000/11/27 12:48:11 1.3
@@ -55,7 +55,7 @@
* *
* ========================================================================= */
-// CVS $Id: wa_provider_info.c,v 1.2 2000/11/27 03:49:19 pier Exp $
+// CVS $Id: wa_provider_info.c,v 1.3 2000/11/27 12:48:11 pier Exp $
// Author: Pier Fumagalli <ma...@eng.sun.com>
#include <wa.h>
@@ -71,7 +71,7 @@
char buf[1024];
if(conn==NULL) return("Null connection specified");
- sprintf(buf, "Extra parameters: %s", (char *)conn->conf);
+ sprintf(buf, "%s", (char *)conn->conf);
return(strdup(buf));
}
@@ -98,11 +98,84 @@
}
void wa_info_handle(wa_request *req, wa_callbacks *cb) {
- (*cb->setstatus)(req->data,200);
- (*cb->settype)(req->data,"text/html");
- (*cb->commit)(req->data);
- (*cb->write)(req->data,"<HTML><BODY>TEST</BODY></HTML>",30);
- (*cb->flush)(req->data);
+ int x=0;
+ wa_connection *conn=wa_connections;
+ wa_host *host=wa_hosts;
+
+ wa_callback_setstatus(cb,req,200);
+ wa_callback_settype(cb,req,"text/html");
+ wa_callback_commit(cb,req);
+ wa_callback_printf(cb,req,"<html>\n");
+ wa_callback_printf(cb,req," <head>\n");
+ wa_callback_printf(cb,req," <title>mod_webapp: status</title>\n");
+ wa_callback_printf(cb,req," </head>\n");
+ wa_callback_printf(cb,req," <body>\n");
+
+ // Dump configured hosts and applications
+ while (conn!=NULL) {
+ char *desc=NULL;
+
+ wa_callback_printf(cb,req," <dl>\n");
+ wa_callback_printf(cb,req," <dt><b>Connection: %s</b></dt>\n",
+ conn->name);
+ 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)
+ wa_callback_printf(cb,req," (Descr.: "%s")\n",desc);
+ wa_callback_printf(cb,req," </dd>\n");
+ conn=conn->next;
+ wa_callback_printf(cb,req," </dl>\n");
+ }
+
+
+ // Dump configured hosts and applications
+ while (host!=NULL) {
+ wa_application *appl=host->apps;
+
+ wa_callback_printf(cb,req," <dl>\n");
+ wa_callback_printf(cb,req," <dt><b>Host: %s:%d</b></dt>\n",
+ host->name,host->port);
+ while (appl!=NULL) {
+ wa_callback_printf(cb,req," <dd>\n");
+ wa_callback_printf(cb,req," Application "%s"\n",
+ appl->name);
+ wa_callback_printf(cb,req," mounted under "%s"\n",
+ appl->path);
+ wa_callback_printf(cb,req," using connection "%s"\n",
+ appl->conn->name);
+ wa_callback_printf(cb,req," </dd>\n");
+ appl=appl->next;
+ }
+ host=host->next;
+ wa_callback_printf(cb,req," </dl>\n");
+ }
+
+ // Dump the first line of the request
+ wa_callback_printf(cb,req," <dl>\n");
+ 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);
+
+ // 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]);
+
+ // Finish the request dump
+ wa_callback_printf(cb,req," </code>\n");
+ wa_callback_printf(cb,req," </dd>\n");
+ wa_callback_printf(cb,req," </dl>\n");
+
+ // Finish the page
+ wa_callback_printf(cb,req," </body>\n");
+ wa_callback_printf(cb,req,"<html>\n");
+ wa_callback_flush(cb,req);
}
wa_provider wa_provider_info = {
1.1 jakarta-tomcat-4.0/connectors/src/webapplib/Makefile
Index: Makefile
===================================================================
include ../Makedefs
OBJS = wa_callback.o wa_connection.o wa_host.o wa_provider.o wa_provider_info.o wa_request.o
all: test libwebapp.a
clean:
rm -f $(OBJS) libwebapp.a
libwebapp.a: $(OBJS)
ar -cr libwebapp.a $(OBJS)
test: $(OBJS) wa.c
$(CC) $(CFLAGS) $(INCLUDES) wa.c -o test
rm -f test
1.1 jakarta-tomcat-4.0/connectors/src/webapplib/wa_callback.c
Index: wa_callback.c
===================================================================
/* ========================================================================= *
* *
* The Apache Software License, Version 1.1 *
* *
* Copyright (c) 1999, 2000 The Apache Software Foundation. *
* All rights reserved. *
* *
* ========================================================================= *
* *
* Redistribution and use in source and binary forms, with or without modi- *
* fication, are permitted provided that the following conditions are met: *
* *
* 1. Redistributions of source code must retain the above copyright notice *
* notice, this list of conditions and the following disclaimer. *
* *
* 2. Redistributions in binary form must reproduce the above copyright *
* notice, this list of conditions and the following disclaimer in the *
* documentation and/or other materials provided with the distribution. *
* *
* 3. The end-user documentation included with the redistribution, if any, *
* must include the following acknowlegement: *
* *
* "This product includes software developed by the Apache Software *
* Foundation <http://www.apache.org/>." *
* *
* Alternately, this acknowlegement may appear in the software itself, if *
* and wherever such third-party acknowlegements normally appear. *
* *
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software *
* Foundation" must not be used to endorse or promote products derived *
* from this software without prior written permission. For written *
* permission, please contact <ap...@apache.org>. *
* *
* 5. Products derived from this software may not be called "Apache" nor may *
* "Apache" appear in their names without prior written permission of the *
* Apache Software Foundation. *
* *
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES *
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY *
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL *
* THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY *
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL *
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS *
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) *
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, *
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN *
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
* POSSIBILITY OF SUCH DAMAGE. *
* *
* ========================================================================= *
* *
* This software consists of voluntary contributions made by many indivi- *
* duals on behalf of the Apache Software Foundation. For more information *
* on the Apache Software Foundation, please see <http://www.apache.org/>. *
* *
* ========================================================================= */
// CVS $Id: wa_callback.c,v 1.1 2000/11/27 12:48:09 pier Exp $
// Author: Pier Fumagalli <ma...@eng.sun.com>
#include <wa.h>
// Allocate memory while processing a request.
void *wa_callback_alloc(wa_callbacks *c, wa_request *r, int size) {
return((*c->alloc)(r->data, size));
}
// Read part of the request content.
int wa_callback_read(wa_callbacks *c, wa_request *r, char *buf, int size) {
return((*c->read)(r->data,buf,size));
}
// Set the HTTP response status code.
boolean wa_callback_setstatus(wa_callbacks *c, wa_request *r, int status) {
return((*c->setstatus)(r->data,status));
}
// Set the HTTP response mime content type.
boolean wa_callback_settype(wa_callbacks *c, wa_request *r, char *type) {
return((*c->settype)(r->data,type));
}
// Set an HTTP mime header.
boolean wa_callback_setheader(wa_callbacks *c,wa_request *r,char *n,char *v) {
return((*c->setheader)(r->data,n,v));
}
// Commit the first part of the response (status and headers).
boolean wa_callback_commit(wa_callbacks *c, wa_request *r) {
return((*c->commit)(r->data));
}
// Write part of the response data back to the client.
int wa_callback_write(wa_callbacks *c, wa_request *r, char *buf, int size) {
return((*c->write)(r->data,buf,size));
}
// Write part of the response data back to the client.
int wa_callback_printf(wa_callbacks *c, wa_request *r, const char *fmt, ...) {
va_list ap;
char buf[1024];
int ret;
va_start(ap,fmt);
ret=vsnprintf(buf,1024,fmt,ap);
va_end(ap);
if (ret<0) return(-1);
return(wa_callback_write(c,r,buf,ret));
}
// Flush any unwritten response data to the client.
boolean wa_callback_flush(wa_callbacks *c, wa_request *r) {
return((*c->flush)(r->data));
}
1.1 jakarta-tomcat-4.0/connectors/src/webapplib/wa_callback.h
Index: wa_callback.h
===================================================================
/* ========================================================================= *
* *
* The Apache Software License, Version 1.1 *
* *
* Copyright (c) 1999, 2000 The Apache Software Foundation. *
* All rights reserved. *
* *
* ========================================================================= *
* *
* Redistribution and use in source and binary forms, with or without modi- *
* fication, are permitted provided that the following conditions are met: *
* *
* 1. Redistributions of source code must retain the above copyright notice *
* notice, this list of conditions and the following disclaimer. *
* *
* 2. Redistributions in binary form must reproduce the above copyright *
* notice, this list of conditions and the following disclaimer in the *
* documentation and/or other materials provided with the distribution. *
* *
* 3. The end-user documentation included with the redistribution, if any, *
* must include the following acknowlegement: *
* *
* "This product includes software developed by the Apache Software *
* Foundation <http://www.apache.org/>." *
* *
* Alternately, this acknowlegement may appear in the software itself, if *
* and wherever such third-party acknowlegements normally appear. *
* *
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software *
* Foundation" must not be used to endorse or promote products derived *
* from this software without prior written permission. For written *
* permission, please contact <ap...@apache.org>. *
* *
* 5. Products derived from this software may not be called "Apache" nor may *
* "Apache" appear in their names without prior written permission of the *
* Apache Software Foundation. *
* *
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES *
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY *
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL *
* THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY *
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL *
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS *
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) *
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, *
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN *
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
* POSSIBILITY OF SUCH DAMAGE. *
* *
* ========================================================================= *
* *
* This software consists of voluntary contributions made by many indivi- *
* duals on behalf of the Apache Software Foundation. For more information *
* on the Apache Software Foundation, please see <http://www.apache.org/>. *
* *
* ========================================================================= */
// CVS $Id: wa_callback.h,v 1.1 2000/11/27 12:48:09 pier Exp $
// Author: Pier Fumagalli <ma...@eng.sun.com>
#ifndef _WA_CALLBACK_H_
#define _WA_CALLBACK_H_
/**
* The wa_callbacks structure contains function pointers for callbacks to the
* web server.
*/
struct wa_callbacks {
/**
* Log data on the web server log file.
*
* @param file The source file of this log entry.
* @param line The line number within the source file of this log entry.
* @param data The web-server specific data (wa_request->data).
* @param fmt The format string (printf style).
* @param ... All other parameters (if any) depending on the format.
*/
void (*log)(void *data, const char *file, int line, const char *fmt, ...);
/**
* Allocate memory while processing a request.
*
* @param data The web-server specific data (wa_request->data).
* @param size The size in bytes of the memory to allocate.
* @return A pointer to the allocated memory or NULL.
*/
void *(*alloc)(void *data, int size);
/**
* Read part of the request content.
*
* @param data The web-server specific data (wa_request->data).
* @param buf The buffer that will hold the data.
* @param len The buffer length.
* @return The number of bytes read, 0 on end of file or -1 on error.
*/
int (*read)(void *data, char *buf, int len);
/**
* Set the HTTP response status code.
*
* @param data The web-server specific data (wa_request->data).
* @param status The HTTP status code for the response.
* @return TRUE on success, FALSE otherwise
*/
boolean (*setstatus)(void *data, int status);
/**
* Set the HTTP response mime content type.
*
* @param data The web-server specific data (wa_request->data).
* @param type The mime content type of the HTTP response.
* @return TRUE on success, FALSE otherwise
*/
boolean (*settype)(void *data, char *type);
/**
* Set an HTTP mime header.
*
* @param data The web-server specific data (wa_request->data).
* @param name The mime header name.
* @param value The mime header value.
* @return TRUE on success, FALSE otherwise
*/
boolean (*setheader)(void *data, char *name, char *value);
/**
* Commit the first part of the response (status and headers).
*
* @param data The web-server specific data (wa_request->data).
* @return TRUE on success, FALSE otherwise
*/
boolean (*commit)(void *data);
/**
* Write part of the response data back to the client.
*
* @param buf The buffer holding the data to be written.
* @param len The number of characters to be written.
* @return The number of characters written to the client or -1 on error.
*/
int (*write)(void *data, char *buf, int len);
/**
* Flush any unwritten response data to the client.
*
* @param data The web-server specific data (wa_request->data).
* @return TRUE on success, FALSE otherwise
*/
boolean (*flush)(void *);
};
/* Function prototype declaration */
// Allocate memory while processing a request.
void *wa_callback_alloc(wa_callbacks *, wa_request *, int);
// Read part of the request content.
int wa_callback_read(wa_callbacks *, wa_request *, char *, int);
// Set the HTTP response status code.
boolean wa_callback_setstatus(wa_callbacks *, wa_request *, int);
// Set the HTTP response mime content type.
boolean wa_callback_settype(wa_callbacks *, wa_request *, char *);
// Set an HTTP mime header.
boolean wa_callback_setheader(wa_callbacks *, wa_request *, char *, char *);
// Commit the first part of the response (status and headers).
boolean wa_callback_commit(wa_callbacks *, wa_request *);
// Write part of the response data back to the client.
int wa_callback_write(wa_callbacks *, wa_request *, char *, int);
// Write part of the response data back to the client.
int wa_callback_printf(wa_callbacks *, wa_request *, const char *, ...);
// Flush any unwritten response data to the client.
boolean wa_callback_flush(wa_callbacks *, wa_request *);
#endif // ifdef _WA_CALLBACK_H_