This patch against Webware's 0.8.1 mod_webkit allows Authorisation Information to be passed to the Webware Application server. It also contains a patch from recent Webware CVS adding support for If-Modified-Since HTTP-Header processing. It also fixes loads of compiler warnings - mostly by removing unused code. --md@hudora.de --- marshal.c?rev=1.1 Sun Oct 26 14:05:13 2003 +++ marshal.c Sun Oct 26 13:54:13 2003 @@ -17,11 +17,6 @@ */ -WFILE* new_item() -{ - WFILE* wf; -} - char* expand_memory(WFILE* p, long add) @@ -29,7 +24,6 @@ char* newptr; long currsize; long newsize = 0; - char log_msg[500]; //log_message("Expanding Memory",p->r); @@ -59,7 +53,6 @@ insert_data(WFILE* dest, WFILE* src) { long src_len, dest_avail, len_need; - char logmsg[500]; //log_message("inserting data", dest->r); @@ -82,8 +75,6 @@ char c; WFILE *p; { - int size, newsize; - char* newptr; // log_message("In w_more", p->r); if (p->str == NULL) @@ -104,7 +95,7 @@ void w_string(s, n, p) - char *s; + const char *s; int n; WFILE *p; { @@ -148,7 +139,7 @@ void -write_string( char* s, long len, WFILE* p){ +write_string(const char* s, long len, WFILE* p){ w_byte(TYPE_STRING, p); w_long(len, p); @@ -159,7 +150,7 @@ void write_integer(int number, WFILE* wf) { - long x,y; + long x; x = (long)number; #if SIZEOF_LONG > 4 long y = x>>31; --- mod_webkit.h?rev=1.1 Sun Oct 26 14:07:12 2003 +++ mod_webkit.h Sun Oct 26 13:53:52 2003 @@ -32,12 +32,12 @@ typedef struct { /* -/* FILE *fp; -/* int error; -/* int depth; -/* /* If fp == NULL, the following are valid: */ -/* PyObject *str; -*/ + * FILE *fp; + * int error; + * int depth; + * // If fp == NULL, the following are valid: + * PyObject *str; + */ char *str; char *ptr; @@ -48,3 +48,11 @@ int log_message(char* msg, request_rec* r); + +//from marshall.c +void w_byte(char c, WFILE* p); +void w_string(const char *s, int n, WFILE *p); +void w_long(long x, WFILE *p); +void write_string(const char* s, long len, WFILE* p); +void write_integer(int number, WFILE* wf); +void insert_data(WFILE* dest, WFILE* src); --- mod_webkit.c?rev=1.1 Sun Oct 26 15:39:05 2003 +++ mod_webkit.c Sun Oct 26 17:30:34 2003 @@ -3,6 +3,7 @@ Apache module for the WebKit Python Application Server author: Jay Love (jsliv@jslove.org) +Patch by md@hudora.de adding support for authorisation headers. ********************************************************************/ @@ -107,7 +108,6 @@ char *word1, char *word2) { wkcfg* cfg; - int port; cfg = (wkcfg *) mconfig; @@ -128,7 +128,6 @@ static const char *handle_maxconnectattempts(cmd_parms *cmd, void *mconfig, char *word1) { wkcfg* cfg; - int attempts; cfg = (wkcfg *) mconfig; @@ -145,7 +144,6 @@ static const char *handle_connectretrydelay(cmd_parms *cmd, void *mconfig, char *word1) { wkcfg* cfg; - int attempts; cfg = (wkcfg *) mconfig; @@ -172,7 +170,6 @@ { wkcfg *cfg; - char *dname = dirspec; /* * Allocate the space for our record from the pool supplied. @@ -196,10 +193,10 @@ -/* ====================================================== */ -/* Initialize the WFILE structure +/* ====================================================== + * Initialize the WFILE structure * This is used by the marshalling functions. -/* ======================================================= */ + * ======================================================= */ WFILE* setup_WFILE(request_rec* r) { WFILE* wf = NULL; @@ -223,58 +220,12 @@ } -/*============================================================================ */ -// Copied from Apache:The definitive guide -// This reads input from the client. -// It's a quick fix. Input from the client needs to go directly to the appserver, -// and not be buffered here. -// -// NOTE: This isn't used anymore -/* =============================================================== */ -static int util_read(request_rec* r, char **rbuf) -{ - int rc; - - // log_message("In util_read", r); - if ((rc = ap_setup_client_block(r, REQUEST_CHUNKED_ERROR)) != OK) { - return rc; - } - - - if (ap_should_client_block(r)) { - char argsbuffer[HUGE_STRING_LENGTH]; - int rsize, len_read, rpos=0; - long length = r->remaining; - - *rbuf = ap_pcalloc(r->pool, length+1); - ap_hard_timeout("util_read", r); - while ((len_read = ap_get_client_block(r, argsbuffer, sizeof(argsbuffer))) >0 ) { - ap_reset_timeout(r); - if ((rpos + len_read) > length) { - rsize = length - rpos; - } - else { - rsize = len_read; - } - memcpy((char*)*rbuf + rpos, argsbuffer, rsize); - } - ap_kill_timeout(r); - } - return rc; -} - - - - - - - -/* ========================================================================= */ -/* Open a socket to appserver host */ -/* Taken from apache jserv. -/* -/* ======================================================================== */ +/* ========================================================================= + * Open a socket to appserver host + * Taken from apache jserv. + * + * ======================================================================== */ static int wksock_open(request_rec *r, unsigned long address, int port, wkcfg* cfg) { struct sockaddr_in addr; int sock; @@ -327,22 +278,6 @@ } -//is there data available on a socket? -//stolen from apache jserv, not used right now -static int data_available(int sock) { - fd_set fdset; - struct timeval tv; - int rv; - do { - FD_ZERO(&fdset); - FD_SET(sock, &fdset); - tv.tv_sec = 0; - tv.tv_usec = 0; - rv = ap_select(sock+1, &fdset, NULL, NULL, &tv); - } while( rv<0 && errno == EINTR); - return (int) (rv == 1); -} - /* Handles one attempt to transact with the app server. Returns one of the following @@ -481,16 +416,10 @@ long length; wkcfg *cfg; - char** env; WFILE* env_dict=NULL; - char* content; int i; - int con_length; char msgbuf[MAX_STRING_LEN]; - int debugint; int conn_attempt = 0; - int conn_attempt_delay = 1; - int max_conn_attempt=10; WFILE* whole_dict=NULL; WFILE* int_dict = NULL; const char *value; @@ -520,6 +449,7 @@ ap_add_common_vars(r); + // @@ to my understanding ap_add_common_vars() already calls ap_add_cgi_vars() ap_add_cgi_vars(r); @@ -542,8 +472,27 @@ if (value !=NULL) write_string(value, strlen(value), env_dict); else w_byte(TYPE_NONE, env_dict); } - w_byte(TYPE_NULL, env_dict); + // If the "If-Modified-Since" HTTP header is present, + // add it to the environment. Servlets may inspect this + // value and, if the object has not changed, + // return "Status: 304" and no body. + key = "If-Modified-Since"; + value = ap_table_get(r->headers_in, key); + if (value && *value) { + write_string(key, strlen(key), env_dict); + write_string(value, strlen(value), env_dict); + } + /* apache refuses to put authorisation information into the enviroment + - so we will get it ourselfs */ + key = "Authorization"; + value = ap_table_get(r->headers_in, key); + if (value && *value) { + write_string("X-HTTP_AUTHORIZATION", 20, env_dict); + write_string(value, strlen(value), env_dict); + } + //end dictionary + w_byte(TYPE_NULL, env_dict); // log_message("Built env dictionary", r); @@ -599,7 +548,6 @@ //========================================================== /* Initialize WebKit Module */ static void wk_init(server_rec *s, pool *p) { - int ret; #if MODULE_MAGIC_NUMBER >= 19980527 /* Tell apache we're here */