You are viewing a plain text version of this content. The canonical link for it is here.
Posted to rivet-dev@tcl.apache.org by da...@apache.org on 2002/02/23 11:55:56 UTC

cvs commit: tcl-rivet/src/buildscripts LICENSE findapxs.tcl

davidw      02/02/23 02:55:56

  Modified:    .        ChangeLog
               src      TclWeb.h TclWebapache.c mod_rivet.c rivetCore.c
               src/buildscripts LICENSE findapxs.tcl
  Log:
  * src/TclWebapache.c: Added functions: TclWeb_PrepareUpload,
    TclWeb_UploadChannel, TclWeb_UploadSave, TclWeb_UploadData,
    TclWeb_UploadSize, TclWeb_UploadType, TclWeb_UploadFilename,
    TclWeb_UploadNames.
  
  * src/rivetCore.c (Rivet_Upload): Offloaded functionality to
    TclWebApache.c.
  
  Revision  Changes    Path
  1.35      +10 -0     tcl-rivet/ChangeLog
  
  Index: ChangeLog
  ===================================================================
  RCS file: /home/cvs/tcl-rivet/ChangeLog,v
  retrieving revision 1.34
  retrieving revision 1.35
  diff -u -r1.34 -r1.35
  --- ChangeLog	17 Feb 2002 19:40:13 -0000	1.34
  +++ ChangeLog	23 Feb 2002 10:55:56 -0000	1.35
  @@ -1,3 +1,13 @@
  +2002-02-23  David N. Welton  <da...@dedasys.com>
  +
  +	* src/TclWebapache.c: Added functions: TclWeb_PrepareUpload,
  +	TclWeb_UploadChannel, TclWeb_UploadSave, TclWeb_UploadData,
  +	TclWeb_UploadSize, TclWeb_UploadType, TclWeb_UploadFilename,
  +	TclWeb_UploadNames.
  +
  +	* src/rivetCore.c (Rivet_Upload): Offloaded functionality to
  +	TclWebApache.c.
  +
   2002-02-17  Damon J. Courtney <da...@unreality.com>
   
   	* src/make.tcl
  
  
  
  1.10      +116 -2    tcl-rivet/src/TclWeb.h
  
  Index: TclWeb.h
  ===================================================================
  RCS file: /home/cvs/tcl-rivet/src/TclWeb.h,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- TclWeb.h	12 Feb 2002 11:09:58 -0000	1.9
  +++ TclWeb.h	23 Feb 2002 10:55:56 -0000	1.10
  @@ -5,7 +5,7 @@
    * 	Common API layer.
    */
   
  -/* $Id: TclWeb.h,v 1.9 2002/02/12 11:09:58 davidw Exp $ */
  +/* $Id: TclWeb.h,v 1.10 2002/02/23 10:55:56 davidw Exp $ */
   
   /* Error wrappers  */
   #define ER1 "<hr><p><code><pre>\n"
  @@ -18,6 +18,7 @@
       Tcl_Interp *interp;
       request_rec *req;
       ApacheRequest *apachereq;
  +    ApacheUpload *upload;
       int headers_printed; 	/* has the header been printed yet? */
       int headers_set;       /* has the header been set yet? */
       int content_sent;
  @@ -98,7 +99,120 @@
   
   int TclWeb_GetEnvVars(Tcl_Obj *envvar, TclWebRequest *req);
   
  -/* upload stuff goes here */
  +/*
  + *-----------------------------------------------------------------------------
  + *
  + * TclWeb_PrepareUpload --
  + *
  + * Do any preperation necessary for file uploads.  This must be
  + * performed before other upload operations.
  + *
  + * Results:
  + *
  + * Stores, if necessary, additional, initialized information in the
  + * TclWebRequest structure.
  + *
  + *-----------------------------------------------------------------------------
  + */
  +
  +int TclWeb_PrepareUpload(char *varname, TclWebRequest *req);
  +
  +/*
  + *-----------------------------------------------------------------------------
  + *
  + * TclWeb_UploadChannel --
  + *
  + * Takes the address of a Tcl_Channel and uses it to create a channel
  + * pointing to the upload data.
  + *
  + * Results:
  + *
  + * 'chan' points to a FileChannel containing the uploaded data.
  + *
  + *-----------------------------------------------------------------------------
  + */
  +
  +int TclWeb_UploadChannel(char *varname, Tcl_Channel *chan, TclWebRequest *req);
  +
  +/*
  + *-----------------------------------------------------------------------------
  + *
  + * TclWeb_UploadSave --
  + *
  + * Saves the uploaded file in 'filename'.
  + *
  + *-----------------------------------------------------------------------------
  + */
  +
  +int TclWeb_UploadSave(char *varname, Tcl_Obj *filename, TclWebRequest *req);
  +
  +/*
  + *-----------------------------------------------------------------------------
  + *
  + * TclWeb_UploadData --
  + *
  + * Fills in the 'data' Tcl_Obj with the uploaded data.
  + *
  + *-----------------------------------------------------------------------------
  + */
  +
  +int TclWeb_UploadData(char *varname, Tcl_Obj *data, TclWebRequest *req);
  +
  +/*
  + *-----------------------------------------------------------------------------
  + *
  + * TclWeb_UploadSize --
  + *
  + * Stores, in 'sz' the size of the data uploaded.
  + *
  + *-----------------------------------------------------------------------------
  + */
  +
  +int TclWeb_UploadSize(Tcl_Obj *sz, TclWebRequest *req);
  +
  +/*
  + *-----------------------------------------------------------------------------
  + *
  + * TclWeb_UploadType --
  + *
  + * Stores, in 'type' the mime type of the file uploaded.
  + *
  + *-----------------------------------------------------------------------------
  + */
  +
  +int TclWeb_UploadType(Tcl_Obj *type, TclWebRequest *req);
  +
  +/*
  + *-----------------------------------------------------------------------------
  + *
  + * TclWeb_UploadFilename --
  + *
  + * Get the original filename of the uploaded data, on the client side.
  + *
  + * Results:
  + *
  + * Stores the filename in 'filename'.
  + *
  + *-----------------------------------------------------------------------------
  + */
  +
  +int TclWeb_UploadFilename(Tcl_Obj *filename, TclWebRequest *req);
  +
  +/*
  + *-----------------------------------------------------------------------------
  + *
  + * TclWeb_UploadNames --
  + *
  + * Fetch names of all the uploaded variables.
  + *
  + * Results:
  + *
  + * Stores the names of the variables in the list 'names'.
  + *
  + *-----------------------------------------------------------------------------
  + */
  +
  +int TclWeb_UploadNames(Tcl_Obj *names, TclWebRequest *req);
   
   int TclWeb_Escape(char *out, char *in, int len, void *var);
   
  
  
  
  1.12      +133 -1    tcl-rivet/src/TclWebapache.c
  
  Index: TclWebapache.c
  ===================================================================
  RCS file: /home/cvs/tcl-rivet/src/TclWebapache.c,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- TclWebapache.c	12 Feb 2002 11:09:58 -0000	1.11
  +++ TclWebapache.c	23 Feb 2002 10:55:56 -0000	1.12
  @@ -7,7 +7,7 @@
    * operations.
    */
   
  -/* $Id: TclWebapache.c,v 1.11 2002/02/12 11:09:58 davidw Exp $ */
  +/* $Id: TclWebapache.c,v 1.12 2002/02/23 10:55:56 davidw Exp $ */
   
   #include <tcl.h>
   
  @@ -19,6 +19,8 @@
   extern module rivet_module;
   #define TCLWEBPOOL req->req->pool
   
  +#define BUFSZ 4096
  +
   int
   TclWeb_InitRequest(TclWebRequest *req, Tcl_Interp *interp, void *arg)
   {
  @@ -439,6 +441,136 @@
   TclWeb_StringToUtfToObj(char *in, TclWebRequest *req)
   {
       return Tcl_NewStringObj(TclWeb_StringToUtf(in, req), -1);
  +}
  +
  +int TclWeb_PrepareUpload(char *varname, TclWebRequest *req)
  +{
  +    req->upload = ApacheUpload_find(req->apachereq->upload, varname);
  +    if (req->upload == NULL) {
  +	return TCL_ERROR;
  +    } else {
  +	return TCL_OK;
  +    }
  +}
  +
  +int TclWeb_UploadChannel(char *varname, Tcl_Channel *chan, TclWebRequest *req)
  +{
  +    if (ApacheUpload_FILE(req->upload) != NULL)
  +    {
  +	/* create and return a file channel */
  +	*chan = Tcl_MakeFileChannel(
  +	    (ClientData)fileno(ApacheUpload_FILE(req->upload)),
  +	    TCL_READABLE);
  +	Tcl_RegisterChannel(req->interp, *chan);
  +	return TCL_OK;
  +    } else {
  +	return TCL_ERROR;
  +    }
  +}
  +
  +int TclWeb_UploadSave(char *varname, Tcl_Obj *filename, TclWebRequest *req)
  +{
  +    int sz;
  +    char savebuffer[BUFSZ];
  +    Tcl_Channel chan;
  +    Tcl_Channel savechan;
  +
  +   savechan = Tcl_OpenFileChannel(req->interp, Tcl_GetString(filename),
  +				   "w", 0600);
  +    if (savechan == NULL) {
  +	return TCL_ERROR;
  +    } else {
  +	Tcl_SetChannelOption(req->interp, savechan,
  +			     "-translation", "binary");
  +    }
  +
  +    chan = Tcl_MakeFileChannel(
  +	(ClientData)fileno(ApacheUpload_FILE(req->upload)),
  +	TCL_READABLE);
  +    Tcl_SetChannelOption(req->interp, chan, "-translation", "binary");
  +
  +    while ((sz = Tcl_Read(chan, savebuffer, BUFSZ)))
  +    {
  +	if (sz == -1)
  +	{
  +	    Tcl_AddErrorInfo(req->interp, Tcl_PosixError(req->interp));
  +	    return TCL_ERROR;
  +	}
  +
  +	Tcl_Write(savechan, savebuffer, sz);
  +	if (sz < 4096) {
  +	    break;
  +	}
  +    }
  +    Tcl_Close(req->interp, savechan);
  +    return TCL_OK;
  +}
  +
  +int TclWeb_UploadData(char *varname, Tcl_Obj *data, TclWebRequest *req)
  +{
  +    rivet_server_conf *rsc = NULL;
  +
  +    rsc  = RIVET_SERVER_CONF( req->req->server->module_config );
  +    /* this sucks - we should use the hook, but I want to
  +       get everything fixed and working first */
  +    if (rsc->upload_files_to_var)
  +    {
  +	char *bytes = NULL;
  +	Tcl_Channel chan = NULL;
  +
  +	bytes = Tcl_Alloc((unsigned)ApacheUpload_size(req->upload));
  +	chan = Tcl_MakeFileChannel(
  +	    (ClientData)fileno(ApacheUpload_FILE(req->upload)),
  +	    TCL_READABLE);
  +	Tcl_SetChannelOption(req->interp, chan,
  +			     "-translation", "binary");
  +	Tcl_SetChannelOption(req->interp, chan, "-encoding", "binary");
  +	/* Put data in a variable  */
  +	Tcl_ReadChars(chan, data, ApacheUpload_size(req->upload), 0);
  +    } else {
  +	Tcl_AppendResult(req->interp,
  +			 "RivetServerConf UploadFilesToVar is not set", NULL);
  +	return TCL_ERROR;
  +    }
  +    return TCL_OK;
  +}
  +
  +int TclWeb_UploadSize(Tcl_Obj *sz, TclWebRequest *req)
  +{
  +   Tcl_SetIntObj(sz, ApacheUpload_size(req->upload));
  +   return TCL_OK;
  +}
  +
  +int TclWeb_UploadType(Tcl_Obj *type, TclWebRequest *req)
  +{
  +   /* If there is a type, return it, if not, return blank. */
  +   Tcl_SetStringObj(type, ApacheUpload_type(req->upload)
  +		    ? ApacheUpload_type(req->upload) : "", -1);
  +   return TCL_OK;
  +}
  +
  +int TclWeb_UploadFilename(Tcl_Obj *filename, TclWebRequest *req)
  +{
  +   Tcl_SetStringObj(filename,
  +		    TclWeb_StringToUtf(req->upload->filename,
  +				       req), -1);
  +   return TCL_OK;
  +}
  +
  +int TclWeb_UploadNames(Tcl_Obj *names, TclWebRequest *req)
  +{
  +   ApacheUpload *upload;
  +
  +   upload = ApacheRequest_upload(req->apachereq);
  +   while (upload)
  +   {
  +       Tcl_ListObjAppendElement(
  +	   req->interp, names,
  +	   TclWeb_StringToUtfToObj(upload->name,req));
  +       upload = upload->next;
  +   }
  +
  +   return TCL_OK;
   }
   
   
  
  
  
  1.32      +3 -3      tcl-rivet/src/mod_rivet.c
  
  Index: mod_rivet.c
  ===================================================================
  RCS file: /home/cvs/tcl-rivet/src/mod_rivet.c,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- mod_rivet.c	12 Feb 2002 11:09:58 -0000	1.31
  +++ mod_rivet.c	23 Feb 2002 10:55:56 -0000	1.32
  @@ -55,7 +55,7 @@
    * originally written at the National Center for Supercomputing Applications,
    * University of Illinois, Urbana-Champaign.  */
   
  -/* $Id: mod_rivet.c,v 1.31 2002/02/12 11:09:58 davidw Exp $  */
  +/* $Id: mod_rivet.c,v 1.32 2002/02/23 10:55:56 davidw Exp $  */
   
   /* mod_rivet.c by David Welton <da...@apache.org>
    *            and Damon Courtney <da...@unreality.com>
  @@ -119,7 +119,7 @@
   #endif /* 0 */
   
   
  -/* Calls Tcl_EvalObj() and checks for errors
  +/* Calls Tcl_EvalObjEx() and checks for errors
    * Prints the error buffer if any.
    */
   
  @@ -131,7 +131,7 @@
       rivet_interp_globals *globals = Tcl_GetAssocData(interp, "rivet", NULL);
   
       conf = Rivet_GetConf(r);
  -    if (Tcl_EvalObj(interp, outbuf) == TCL_ERROR)
  +    if (Tcl_EvalObjEx(interp, outbuf, 0) == TCL_ERROR)
       {
   	Tcl_Obj *errscript =
   	    conf->rivet_error_script ? conf->rivet_error_script : NULL;
  
  
  
  1.16      +24 -89    tcl-rivet/src/rivetCore.c
  
  Index: rivetCore.c
  ===================================================================
  RCS file: /home/cvs/tcl-rivet/src/rivetCore.c,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- rivetCore.c	12 Feb 2002 11:09:58 -0000	1.15
  +++ rivetCore.c	23 Feb 2002 10:55:56 -0000	1.16
  @@ -2,7 +2,7 @@
    * rivetCore.c - Core commands which are compiled into mod_rivet itself.
    */
   
  -/* $Id: rivetCore.c,v 1.15 2002/02/12 11:09:58 davidw Exp $ */
  +/* $Id: rivetCore.c,v 1.16 2002/02/23 10:55:56 davidw Exp $ */
   
   #include "httpd.h"
   #include "http_config.h"
  @@ -23,8 +23,6 @@
   #include "rivet.h"
   #include "TclWeb.h"
   
  -#define BUFSZ 4096
  -
   #define ENV_ARRAY_NAME "env"
   #define COOKIES_ARRAY_NAME "cookies"
   
  @@ -436,10 +434,7 @@
   {
       char *command = NULL;
       Tcl_Obj *result = NULL;
  -    ApacheUpload *upload;
       rivet_interp_globals *globals = Tcl_GetAssocData(interp, "rivet", NULL);
  -    rivet_server_conf *rsc =
  -	RIVET_SERVER_CONF( globals->r->server->module_config );
   
       if (objc < 2 || objc > 5)
       {
  @@ -455,95 +450,48 @@
   	if (objc < 4)
   	{
   	    Tcl_WrongNumArgs(interp, 2, objv,
  -		"varname channel|save filename|var varname");
  +			     "varname channel|save filename|var varname");
   	    return TCL_ERROR;
   	}
   	varname = Tcl_GetString(objv[2]);
  -	upload = ApacheUpload_find(globals->req->apachereq->upload, varname);
  -	if (upload != NULL) /* make sure we have an upload */
  +
  +	if (TclWeb_PrepareUpload(varname, globals->req) == TCL_OK)
   	{
   	    Tcl_Channel chan;
   	    char *method = Tcl_GetString(objv[3]);
  +
   	    if (!strcmp(method, "channel"))
   	    {
  -		if (ApacheUpload_FILE(upload) != NULL)
  -		{
  -		    /* create and return a file channel */
  -		    char *channelname = NULL;
  -		    chan = Tcl_MakeFileChannel(
  -			(ClientData)fileno(ApacheUpload_FILE(upload)),
  -			TCL_READABLE);
  -		    Tcl_RegisterChannel(interp, chan);
  -		    channelname = Tcl_GetChannelName(chan);
  -		    Tcl_SetStringObj(result, channelname, -1);
  +		char *channelname = NULL;
  +
  +		if (TclWeb_UploadChannel(varname, &chan, globals->req) != TCL_OK) {
  +		    return TCL_ERROR;
   		}
  +		channelname = Tcl_GetChannelName(chan);
  +		Tcl_SetStringObj(result, channelname, -1);
   	    } else if (!strcmp(method, "save")) {
   		/* save data to a specified filename  */
  -
  -		int sz;
  -		char savebuffer[BUFSZ];
  -		Tcl_Channel savechan = NULL;
  -		Tcl_Channel chan = NULL;
  -		if (objc != 5)
  -		{
  +		if (objc != 5) {
   		    Tcl_WrongNumArgs(interp, 4, objv, "filename");
   		    return TCL_ERROR;
   		}
   
  -		savechan = Tcl_OpenFileChannel(interp, Tcl_GetString(objv[4]),
  -						"w", 0600);
  -		if (savechan == NULL)
  +		if (TclWeb_UploadSave(varname, objv[4], globals->req) != TCL_OK) {
   		    return TCL_ERROR;
  -		else
  -		    Tcl_SetChannelOption(interp, savechan,
  -			"-translation", "binary");
  -
  -		chan = Tcl_MakeFileChannel(
  -			(ClientData)fileno(ApacheUpload_FILE(upload)),
  -			TCL_READABLE);
  -		Tcl_SetChannelOption(interp, chan, "-translation", "binary");
  -
  -		while ((sz = Tcl_Read(chan, savebuffer, BUFSZ)))
  -		{
  -		    if (sz == -1)
  -		    {
  -			Tcl_AddErrorInfo(interp, Tcl_PosixError(interp));
  -			return TCL_ERROR;
  -		    }
  -
  -		    Tcl_Write(savechan, savebuffer, sz);
  -		    if (sz < 4096)
  -			break;
   		}
  -		Tcl_Close(interp, savechan);
  -		Tcl_SetIntObj(result, 1);
   	    } else if (!strcmp(method, "data")) {
   		/* this sucks - we should use the hook, but I want to
                      get everything fixed and working first */
  -		if (rsc->upload_files_to_var)
  -		{
  -		    char *bytes = NULL;
  -		    Tcl_Channel chan = NULL;
  -
  -		    bytes = Tcl_Alloc((unsigned)ApacheUpload_size(upload));
  -		    chan = Tcl_MakeFileChannel(
  -			(ClientData)fileno(ApacheUpload_FILE(upload)),
  -			TCL_READABLE);
  -		    Tcl_SetChannelOption(interp, chan,
  -			"-translation", "binary");
  -		    Tcl_SetChannelOption(interp, chan, "-encoding", "binary");
  -		    /* Put data in a variable  */
  -		    Tcl_ReadChars(chan, result, ApacheUpload_size(upload), 0);
  -		} else {
  -		    Tcl_AppendResult(interp,
  -			"RivetServerConf UploadFilesToVar is not set", NULL);
  +
  +		if (TclWeb_UploadData(varname, result, globals->req) != TCL_OK) {
   		    return TCL_ERROR;
   		}
   	    }
   	} else {
  -	    /* no variable found  */
  -	    Tcl_SetStringObj(result, "", -1);
  +	    Tcl_AddErrorInfo(interp, "variable doesn't exist");
  +	    return TCL_ERROR;
   	}
  +
       } else if (!strcmp(command, "info")) {
   	char *varname = NULL;
   	char *infotype = NULL;
  @@ -556,25 +504,18 @@
   	varname = Tcl_GetString(objv[2]);
   	infotype = Tcl_GetString(objv[3]);
   
  -	upload = ApacheUpload_find(globals->req->apachereq->upload, varname);
  -	if (upload != NULL)
  +	if (TclWeb_PrepareUpload(varname, globals->req) == TCL_OK)
   	{
   	    if (!strcmp(infotype, "exists"))
   	    {
  +		/* if we've made it this far, it must exist */
   		Tcl_SetIntObj(result, 1);
   	    } else if (!strcmp(infotype, "size")) {
  -		Tcl_SetIntObj(result, ApacheUpload_size(upload));
  +		TclWeb_UploadSize(result, globals->req);
   	    } else if (!strcmp(infotype, "type")) {
  -		char *type = NULL;
  -		type = (char *)ApacheUpload_type(upload);
  -		if (type)
  -		    Tcl_SetStringObj(result, type, -1);
  -		else
  -		    Tcl_SetStringObj(result, "", -1);
  +		TclWeb_UploadType(result, globals->req);
   	    } else if (!strcmp(infotype, "filename")) {
  -		Tcl_SetStringObj(result,
  -				 TclWeb_StringToUtf(upload->filename,
  -						    globals->req), -1);
  +		TclWeb_UploadFilename(result, globals->req);
   	    } else {
   		Tcl_AddErrorInfo(interp,"unknown upload info command, should "
   			"be exists|size|type|filename");
  @@ -589,13 +530,7 @@
   	    }
   	}
       } else if (!strcmp(command, "names")) {
  -	upload = ApacheRequest_upload(globals->req->apachereq);
  -	while (upload)
  -	{
  -	    Tcl_ListObjAppendElement(interp, result,
  -				     TclWeb_StringToUtfToObj(upload->name, globals->req));
  -	    upload = upload->next;
  -	}
  +	TclWeb_UploadNames(result, globals->req);
       } else {
   	Tcl_WrongNumArgs(interp, 1, objv, "upload get|info|names");
   	return TCL_ERROR;
  
  
  
  1.2       +1 -5      tcl-rivet/src/buildscripts/LICENSE
  
  Index: LICENSE
  ===================================================================
  RCS file: /home/cvs/tcl-rivet/src/buildscripts/LICENSE,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- LICENSE	19 Sep 2001 13:20:18 -0000	1.1
  +++ LICENSE	23 Feb 2002 10:55:56 -0000	1.2
  @@ -50,8 +50,4 @@
    * individuals on behalf of the Apache Software Foundation.  For more
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
  - *
  - * Portions of this software are based upon public domain software
  - * originally written at the National Center for Supercomputing Applications,
  - * University of Illinois, Urbana-Champaign.  */
  -
  + */
  
  
  
  1.2       +1 -0      tcl-rivet/src/buildscripts/findapxs.tcl
  
  Index: findapxs.tcl
  ===================================================================
  RCS file: /home/cvs/tcl-rivet/src/buildscripts/findapxs.tcl,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- findapxs.tcl	17 Feb 2002 19:40:13 -0000	1.1
  +++ findapxs.tcl	23 Feb 2002 10:55:56 -0000	1.2
  @@ -1,6 +1,7 @@
   set apxsDirList {
       /usr/local/apache/bin
       /usr/local/etc/apache/bin
  +    /usr/bin/
   }
   
   proc FindAPXS {{apxs ""}} {
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: rivet-dev-unsubscribe@tcl.apache.org
For additional commands, e-mail: rivet-dev-help@tcl.apache.org