You are viewing a plain text version of this content. The canonical link for it is here.
Posted to mod_dtcl-cvs@tcl.apache.org by da...@apache.org on 2001/03/09 19:32:31 UTC

cvs commit: mod_dtcl apache_request.c apache_request.h mod_dtcl.c

davidw      01/03/09 10:32:30

  Modified:    .        apache_request.c apache_request.h mod_dtcl.c
  Log:
  Added file upload hook to apreq.
  
  Added hook to mod_dtcl to allow file uploads to a Tcl variable.
  
  Revision  Changes    Path
  1.2       +19 -9     mod_dtcl/apache_request.c
  
  Index: apache_request.c
  ===================================================================
  RCS file: /home/cvs/mod_dtcl/apache_request.c,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- apache_request.c	2000/12/19 11:59:10	1.1
  +++ apache_request.c	2001/03/09 18:32:28	1.2
  @@ -203,6 +203,8 @@
       req->upload = NULL;
       req->post_max = -1;
       req->disable_uploads = 0;
  +//    req->ApacheUploadHook = NULL;
  +//    req->hookptr = NULL;
       req->parsed = 0;
       req->r = r;
   
  @@ -377,6 +379,7 @@
   	const char *cd, *param=NULL, *filename=NULL;
   	char buff[FILLUNIT];
   	int blen;
  +	int wlen; 
   
   	if (!header) {
   	    return OK;
  @@ -417,27 +420,34 @@
   		upload = ApacheUpload_new(req);
   		req->upload = upload;
   	    }
  -
  -	    if (!(upload->fp = ApacheRequest_tmpfile(req))) {
  -		return HTTP_INTERNAL_SERVER_ERROR;
  -	    }
  + 	    if (req->ApacheUploadHook == NULL) {
  +		if (!(upload->fp = ApacheRequest_tmpfile(req))) {
  +		    return HTTP_INTERNAL_SERVER_ERROR;
  +		}
  +	    }  
   
   	    upload->info = header;
   	    upload->filename = ap_pstrdup(req->r->pool, filename);
   	    upload->name = ap_pstrdup(req->r->pool, param);
   
   	    while ((blen = multipart_buffer_read(mbuff, buff, sizeof(buff)))) {
  -		/* write the file */
  -	        /* XXX: do better error-checking on the fwrite? */
  -		upload->size += fwrite(buff, 1, blen, upload->fp); 	
  +		if (req->ApacheUploadHook != NULL) {
  +		    wlen = req->ApacheUploadHook(req->hookptr, buff, blen);
  +		} else {
  +		    wlen = fwrite(buff, 1, blen, upload->fp);
  +		}
  +		if (wlen != blen) {
  +		    return HTTP_INTERNAL_SERVER_ERROR;
  +		}
  +		upload->size += wlen;
   	    }
   
  -	    if (upload->size > 0) {
  + 	    if (upload->size > 0 && (req->ApacheUploadHook == NULL)) {
   		fseek(upload->fp, 0, 0);
   	    }
   	    else {
   		upload->fp = NULL;
  -	    }
  +	    }  
   	}
       }
   
  
  
  
  1.2       +3 -0      mod_dtcl/apache_request.h
  
  Index: apache_request.h
  ===================================================================
  RCS file: /home/cvs/mod_dtcl/apache_request.h,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- apache_request.h	2000/12/19 11:59:10	1.1
  +++ apache_request.h	2001/03/09 18:32:28	1.2
  @@ -19,6 +19,8 @@
       int parsed;
       int post_max;
       int disable_uploads;
  +    int (*ApacheUploadHook)(void *ptr, char *buf, int len);
  +    void *hookptr; /* data for UploadHook */
       request_rec *r;
   } ApacheRequest;
   
  @@ -75,6 +77,7 @@
   FILE *ApacheRequest_tmpfile(ApacheRequest *req);
   ApacheUpload *ApacheUpload_new(ApacheRequest *req);
   ApacheUpload *ApacheUpload_find(ApacheUpload *upload, char *name);
  +
   
   #define ApacheRequest_upload(req) \
       ((req->parsed || (ApacheRequest_parse(req) == OK)) ? req->upload : NULL)
  
  
  
  1.21      +33 -16    mod_dtcl/mod_dtcl.c
  
  Index: mod_dtcl.c
  ===================================================================
  RCS file: /home/cvs/mod_dtcl/mod_dtcl.c,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- mod_dtcl.c	2001/03/01 18:31:30	1.20
  +++ mod_dtcl.c	2001/03/09 18:32:28	1.21
  @@ -58,7 +58,7 @@
    * University of Illinois, Urbana-Champaign.
    */
   
  -/* $Id: mod_dtcl.c,v 1.20 2001/03/01 18:31:30 davidw Exp $  */
  +/* $Id: mod_dtcl.c,v 1.21 2001/03/09 18:32:28 davidw Exp $  */
   
   /* mod_dtcl.c by David Welton <da...@apache.org> - originally mod_include.  */
   /* See http://tcl.apache.org/mod_dtcl/credits.ttml for additional credits. */
  @@ -325,6 +325,18 @@
   #endif
   }
   
  +/* Function to be used should we desire to upload files to a variable */
  +int dtcl_upload_hook(void *ptr, char *buf, int len)
  +{
  +    Tcl_Interp *interp = ptr;
  +    Tcl_ObjSetVar2(interp,
  +		   Tcl_NewStringObj("::request::UPLOAD", -1),
  +		   Tcl_NewStringObj("data", -1),
  +		   Tcl_NewByteArrayObj(buf, len),
  +		   TCL_APPEND_VALUE);
  +    return len;
  +}  
  +
   /* Load, cache and eval a Tcl file  */
   
   int send_tcl_file(request_rec *r, char *filename, struct stat *finfo)
  @@ -407,7 +419,7 @@
       }
   #else
       Tcl_EvalFile(interp, r->filename);
  -#endif
  +#endif /* 1 */
       print_headers(global_rr);
       flush_output_buffer(global_rr);
   
  @@ -691,6 +703,12 @@
   
       /* Apache Request stuff */
       req = ApacheRequest_new(r);
  +//    if (upload_files_to_var)
  +//    {
  +    req->hookptr = interp;
  +    req->ApacheUploadHook = dtcl_upload_hook; 
  +//    }
  +
       ApacheRequest___parse(req);
       
       /* take results and create tcl variables from them */
  @@ -712,18 +730,14 @@
   	}
   	
       }
  -    upload = req->upload;
  +   upload = req->upload;
  +
   //    while (upload)
       if (upload)
       {
   	char *type = NULL;
   	char *channelname = NULL;
   	Tcl_Channel chan;
  -/* 	Tcl_ObjSetVar2(interp,
  -		       Tcl_NewStringObj("::request::UPLOAD", -1),
  -		       Tcl_NewStringObj("data", -1),
  -		       Tcl_NewByteArrayObj(acum, acumlen),
  -		       0);  */
   
   	/* The name of the file uploaded  */
   	Tcl_ObjSetVar2(interp,
  @@ -752,14 +766,17 @@
   			   Tcl_NewStringObj(type, -1), /* kill end of line */
   			   0);
   	}
  -	chan = Tcl_MakeFileChannel((ClientData *)fileno(upload->fp), TCL_READABLE);
  -	Tcl_RegisterChannel(interp, chan);
  -	channelname = Tcl_GetChannelName(chan);
  -	Tcl_ObjSetVar2(interp,
  -		       Tcl_NewStringObj("::request::UPLOAD", -1),
  -		       Tcl_NewStringObj("channelname", -1),
  -		       Tcl_NewStringObj(channelname, -1), /* kill end of line */
  -		       0);
  +	if (!upload_files_to_var)
  +	{
  +	    chan = Tcl_MakeFileChannel((ClientData *)fileno(upload->fp), TCL_READABLE);
  +	    Tcl_RegisterChannel(interp, chan);
  +	    channelname = Tcl_GetChannelName(chan);
  +	    Tcl_ObjSetVar2(interp,
  +			   Tcl_NewStringObj("::request::UPLOAD", -1),
  +			   Tcl_NewStringObj("channelname", -1),
  +			   Tcl_NewStringObj(channelname, -1), /* kill end of line */
  +			   0);
  +	}
   	
   //	upload = upload->next;
       }