You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tcl.apache.org by mx...@apache.org on 2019/12/30 02:11:17 UTC
[tcl-rivet] branch uploadcmdfix updated: reorganized upload command,
adding copyright statements to files in src/request/
This is an automated email from the ASF dual-hosted git repository.
mxmanghi pushed a commit to branch uploadcmdfix
in repository https://gitbox.apache.org/repos/asf/tcl-rivet.git
The following commit(s) were added to refs/heads/uploadcmdfix by this push:
new 91285e5 reorganized upload command,adding copyright statements to files in src/request/
91285e5 is described below
commit 91285e5d8866cd8d2b6d141f76c8ba024c6b0140
Author: Massimo Manghi <mx...@apache.org>
AuthorDate: Mon Dec 30 03:11:03 2019 +0100
reorganized upload command,adding copyright statements to files in src/request/
---
ChangeLog | 8 ++++++
src/mod_rivet_ng/TclWebapache.c | 32 +++++++++++-------------
src/mod_rivet_ng/mod_rivet.c | 2 +-
src/mod_rivet_ng/mod_rivet.h | 2 +-
src/mod_rivet_ng/rivetCore.c | 47 +++++++++++++++++++----------------
src/mod_rivet_ng/rivet_types.h | 15 ++++++-----
src/request/apache_multipart_buffer.c | 30 +++++++++++++---------
src/request/apache_multipart_buffer.h | 42 +++++++++++++++++--------------
src/request/apache_request.c | 37 +++++++++++++++------------
src/request/apache_request.h | 33 ++++++++++++++++++------
tests/runtests.tcl | 2 --
tests/upload.rvt | 25 ++++++++++++++++++-
tests/upload.test | 6 ++---
13 files changed, 170 insertions(+), 111 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 36212c6..c369491 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2019-12-30 Massimo Manghi <mx...@apache.org>
+ * src/mod_rivet_ng/rivetCore.c: fixed bug in 'upload filename' that
+ caused segfaults instead of Tcl errors when called without arguments
+ * src/request/: Adding latest Copyright statements to files in this
+ directory
+ * tests/upload.rvt,upload.test: revised upload tests (need expansion
+ to test multiple uploads)
+
2019-12-06 Massimo Manghi <mx...@apache.org>
* src/mod_rivet_ng/rivetCore.c: expanded error info data in Rivet_Upload
diff --git a/src/mod_rivet_ng/TclWebapache.c b/src/mod_rivet_ng/TclWebapache.c
index c5c1a38..98c90d5 100644
--- a/src/mod_rivet_ng/TclWebapache.c
+++ b/src/mod_rivet_ng/TclWebapache.c
@@ -19,8 +19,6 @@
under the License.
*/
-/* $Id$ */
-
/* Rivet config */
#ifdef HAVE_CONFIG_H
@@ -664,20 +662,18 @@ int TclWeb_PrepareUpload(char *varname, TclWebRequest *req)
int TclWeb_UploadChannel(char *varname, Tcl_Channel *chan, TclWebRequest *req)
{
- *chan = Tcl_OpenFileChannel (req->interp, req->upload->tempname, "r", 0);
+ *chan = Tcl_OpenFileChannel(req->interp, req->upload->tempname, "r", 0);
if (chan == NULL) {
- return TCL_ERROR;
- } else {
- if (Tcl_SetChannelOption(req->interp, *chan,
- "-translation", "binary") == TCL_ERROR) {
- return TCL_ERROR;
- }
- if (Tcl_SetChannelOption(req->interp, *chan,
- "-encoding", "binary") == TCL_ERROR) {
return TCL_ERROR;
- }
- Tcl_RegisterChannel (req->interp, *chan);
- return TCL_OK;
+ } else {
+ if (Tcl_SetChannelOption(req->interp,*chan,"-translation","binary") == TCL_ERROR) {
+ return TCL_ERROR;
+ }
+ if (Tcl_SetChannelOption(req->interp,*chan,"-encoding","binary") == TCL_ERROR) {
+ return TCL_ERROR;
+ }
+ Tcl_RegisterChannel(req->interp, *chan);
+ return TCL_OK;
}
}
@@ -766,10 +762,10 @@ int TclWeb_UploadNames(Tcl_Obj *names, TclWebRequest *req)
upload = ApacheRequest_upload(req->apachereq);
while (upload)
{
- Tcl_ListObjAppendElement(
- req->interp, names,
- TclWeb_StringToUtfToObj(upload->name,req));
- upload = upload->next;
+ Tcl_ListObjAppendElement(
+ req->interp, names,
+ TclWeb_StringToUtfToObj(upload->name,req));
+ upload = upload->next;
}
return TCL_OK;
diff --git a/src/mod_rivet_ng/mod_rivet.c b/src/mod_rivet_ng/mod_rivet.c
index d3dbc5c..91550eb 100644
--- a/src/mod_rivet_ng/mod_rivet.c
+++ b/src/mod_rivet_ng/mod_rivet.c
@@ -327,7 +327,7 @@ Rivet_ServerInit (apr_pool_t *pPool, apr_pool_t *pLog, apr_pool_t *pTemp, server
apr_pool_userdata_set((const void *)1, userdata_key,
apr_pool_cleanup_null, server->process->pool);
- ap_log_error(APLOG_MARK,APLOG_INFO,0,server,
+ ap_log_error(APLOG_MARK,APLOG_DEBUG,0,server,
"first post_config run: not initializing Tcl stuff");
return OK; /* This would be the first time through */
diff --git a/src/mod_rivet_ng/mod_rivet.h b/src/mod_rivet_ng/mod_rivet.h
index 88f9b8a..2a43998 100644
--- a/src/mod_rivet_ng/mod_rivet.h
+++ b/src/mod_rivet_ng/mod_rivet.h
@@ -227,7 +227,7 @@ typedef struct _thread_worker_private {
request_rec* r; /* current request_rec */
TclWebRequest* req;
//Tcl_Obj* request_init;
- Tcl_Obj* request_cleanup;
+ //Tcl_Obj* request_cleanup;
rivet_server_conf* running_conf; /* running configuration */
running_scripts* running; /* (per request) running conf scripts */
int thread_exit; /* Thread exit code */
diff --git a/src/mod_rivet_ng/rivetCore.c b/src/mod_rivet_ng/rivetCore.c
index cd34660..bb7dcf6 100644
--- a/src/mod_rivet_ng/rivetCore.c
+++ b/src/mod_rivet_ng/rivetCore.c
@@ -1039,6 +1039,7 @@ TCL_CMD_HEADER( Rivet_Upload )
{
char* varname = NULL;
int subcommandindex;
+ int upload_prepared = 0;
Tcl_Obj* result = NULL;
@@ -1048,18 +1049,19 @@ TCL_CMD_HEADER( Rivet_Upload )
* - subcommand integer progressive index
* - subcommand required (minimum) number of arguments
*
- *----+----------------------------------------+-------+
- * | argv[1] argv[2] argv[3] | argc |
- *----+----------------------------------------+-------+
- * | upload channel uploadname | 3 |
- * | upload save uploadname filename | 4 |
- * | upload data uploadname | 3 |
- * | upload exists uploadname | 3 |
- * | upload size uploadname | 3 |
- * | upload type | 2 |
- * | upload filename uploadname | 3 |
- * | upload tempname uploadname | 3 |
- * | upload names | 2 |
+ * +----------------------------------------+-------+
+ * | argv[1] argv[2] argv[3] | argc |
+ * +----------------------------------------+-------+
+ * | upload channel uploadname | 3 |
+ * | upload save uploadname filename | 4 |
+ * | upload data uploadname | 3 |
+ * | upload exists uploadname | 3 |
+ * | upload size uploadname | 3 |
+ * | upload type uploadname | 3 |
+ * | upload filename uploadname | 3 |
+ * | upload tempname uploadname | 3 |
+ * | upload names | 2 |
+ * +----------------------------------------+-------+
*
* a subcommand first optional argument must be the name
* of an upload
@@ -1090,10 +1092,10 @@ TCL_CMD_HEADER( Rivet_Upload )
NAMES
};
- static CONST84 int cmds_objc[] = { 3,4,3,3,3,2,3,3,2 };
+ static CONST84 int cmds_objc[] = { 3,4,3,3,3,3,3,3,2 };
int expected_objc;
- rivet_thread_private* private;
+ rivet_thread_private* private;
THREAD_PRIVATE_DATA(private)
CHECK_REQUEST_REC(private,"::rivet::upload")
@@ -1122,13 +1124,18 @@ TCL_CMD_HEADER( Rivet_Upload )
if (objc >= 3) {
varname = Tcl_GetString(objv[2]);
+
+ /* TclWeb_PrepareUpload calls ApacheUpload_find and returns
+ * TCL_OK if the named upload exists in the current request */
+
if (TclWeb_PrepareUpload(varname, private->req) != TCL_OK)
{
Tcl_AddErrorInfo(interp, "Unable to find the upload named '");
Tcl_AppendObjToErrorInfo(interp,Tcl_NewStringObj(varname,-1));
Tcl_AppendObjToErrorInfo(interp,Tcl_NewStringObj("'",-1));
return TCL_ERROR;
- }
+ }
+ upload_prepared = 1;
}
result = Tcl_NewObj();
@@ -1163,14 +1170,10 @@ TCL_CMD_HEADER( Rivet_Upload )
return TCL_ERROR;
}
break;
- case EXISTS:
- if (TclWeb_PrepareUpload(varname, private->req) != TCL_OK)
- {
- Tcl_SetIntObj(result, 0);
- } else {
- Tcl_SetIntObj(result, 1);
- }
+ case EXISTS: {
+ Tcl_SetIntObj(result,upload_prepared);
break;
+ }
case SIZE:
TclWeb_UploadSize(result, private->req);
break;
diff --git a/src/mod_rivet_ng/rivet_types.h b/src/mod_rivet_ng/rivet_types.h
index 787a15f..6d24ff4 100644
--- a/src/mod_rivet_ng/rivet_types.h
+++ b/src/mod_rivet_ng/rivet_types.h
@@ -1,5 +1,5 @@
/* -- rivet_types.h: this file should collect all the basic types used
- * in mod_rivet and other related code
+ * in mod_rivet and other related code
*/
/*
@@ -21,10 +21,8 @@
under the License.
*/
-/* $Id$ */
-
-#ifndef __RIVET_TYPES_H__
-#define __RIVET_TYPES_H__
+#ifndef __rivet_types_h__
+#define __rivet_types_h__
#include <httpd.h>
#include <tcl.h>
@@ -76,7 +74,7 @@ typedef struct _ApacheRequest {
int (*upload_hook)(void *ptr, char *buf, int len, ApacheUpload *upload);
void* hook_data;
const char* temp_dir;
- char* raw_post; /* Raw post data. */
+ char* raw_post; /* Raw post data. */
request_rec* r;
int nargs;
} ApacheRequest;
@@ -87,10 +85,11 @@ typedef struct TclWebRequest {
ApacheRequest* apachereq;
ApacheUpload* upload;
int headers_printed; /* has the header been printed yet? */
- int headers_set; /* has the header been set yet? */
+ int headers_set; /* has the header been set yet? */
int content_sent;
int environment_set; /* have we setup the environment variables? */
char* charset;
} TclWebRequest;
-#endif
+#endif /* __rivet_types_h__ */
+
diff --git a/src/request/apache_multipart_buffer.c b/src/request/apache_multipart_buffer.c
index 484b8f3..14a3ac9 100644
--- a/src/request/apache_multipart_buffer.c
+++ b/src/request/apache_multipart_buffer.c
@@ -1,16 +1,22 @@
-/* Copyright -2004 The Apache Software Foundation
+/* apache_multipart_buffer.c -- form multipart data handling */
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
*/
/* Rivet config */
diff --git a/src/request/apache_multipart_buffer.h b/src/request/apache_multipart_buffer.h
index b899a46..6aa8662 100644
--- a/src/request/apache_multipart_buffer.h
+++ b/src/request/apache_multipart_buffer.h
@@ -1,22 +1,26 @@
-/* Copyright 2008 The Apache Software Foundation
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
+/* apache_multipart_buffer.h -- form multipart data handling */
+
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
*/
-/* $Id$ */
-
-#ifndef _APACHE_MULTIPART_BUFFER_H
-#define _APACHE_MULTIPART_BUFFER_H
+#ifndef __apache_multipart_buffer_h__
+#define __apache_multipart_buffer_h__
#include "apache_request.h"
@@ -46,7 +50,7 @@ typedef struct _multipart_buffer {
} multipart_buffer;
multipart_buffer* multipart_buffer_new(char* boundary,apr_off_t length,request_rec* r);
-///*table*/apr_table_t *multipart_buffer_headers(multipart_buffer *self);
+// /*table*/apr_table_t *multipart_buffer_headers(multipart_buffer *self);
size_t multipart_buffer_read(multipart_buffer* self,char* buf,size_t bytes);
char* multipart_buffer_read_body(multipart_buffer *self);
apr_table_t* multipart_buffer_headers(multipart_buffer *self);
@@ -56,4 +60,4 @@ int multipart_buffer_eof(multipart_buffer *self);
}
#endif
-#endif
+#endif /*__apache_multipart_buffer_h__ */
diff --git a/src/request/apache_request.c b/src/request/apache_request.c
index b370273..7f7b4fb 100644
--- a/src/request/apache_request.c
+++ b/src/request/apache_request.c
@@ -1,16 +1,22 @@
-/* Copyright 2000-2004 The Apache Software Foundation
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
+/* apache_request.c -- Apache multipart form data handling */
+
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
*/
#include <errno.h>
@@ -564,9 +570,8 @@ ApacheRequest_parse_multipart(ApacheRequest *req,const char* ct)
#ifdef DEBUG
ap_log_rerror(REQ_ERROR,"Silently dropping remaining '%ld' bytes", r->remaining);
#endif
- do { } while ( ap_get_client_block(r, buff, sizeof(buff)) > 0 );
-
- return OK;
+ do { } while ( ap_get_client_block(r, buff, sizeof(buff)) > 0 );
+ return OK;
}
if ((cd = apr_table_get(header, "Content-Disposition"))) {
diff --git a/src/request/apache_request.h b/src/request/apache_request.h
index 22b8058..af84334 100644
--- a/src/request/apache_request.h
+++ b/src/request/apache_request.h
@@ -1,5 +1,26 @@
-#ifndef _APACHE_REQUEST_H
-#define _APACHE_REQUEST_H
+/* apache_request.h -- mod_rivet upload request functions */
+
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+*/
+
+#ifndef __apache_request_h__
+#define __apache_request_h__
#include "httpd.h"
#include "http_config.h"
@@ -93,11 +114,9 @@ ApacheUpload *ApacheUpload_find(ApacheUpload *upload, char *name);
#define ApacheUpload_size(upload) ((upload)->size)
-#define ApacheUpload_info(upload, key) \
-apr_table_get((upload)->info, (key))
+#define ApacheUpload_info(upload, key) apr_table_get((upload)->info, (key))
-#define ApacheUpload_type(upload) \
-ApacheUpload_info((upload), "Content-Type")
+#define ApacheUpload_type(upload) ApacheUpload_info((upload), "Content-Type")
#define ApacheRequest_set_post_max(req, max) ((req)->post_max = (max))
#define ApacheRequest_set_temp_dir(req, dir) ((req)->temp_dir = (dir))
@@ -122,4 +141,4 @@ char *ApacheRequest_expires(ApacheRequest *req, char *time_str);
#define REQ_DEBUG(a)
#endif
-#endif /* _APACHE_REQUEST_H */
+#endif /* __apache_request_h__ */
diff --git a/tests/runtests.tcl b/tests/runtests.tcl
index eaa9ee0..87ff358 100755
--- a/tests/runtests.tcl
+++ b/tests/runtests.tcl
@@ -16,8 +16,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-# $Id$
-
set auto_path [linsert $auto_path 0 [file join [file dirname [info script]] apachetest]]
puts stderr "runtests.tcl is running with auto_path: $auto_path"
diff --git a/tests/upload.rvt b/tests/upload.rvt
index 5e84818..b9b5c40 100644
--- a/tests/upload.rvt
+++ b/tests/upload.rvt
@@ -1 +1,24 @@
-<? puts "[::rivet::upload names] [::rivet::upload exists uploadtest] [::rivet::upload size uploadtest] -[::rivet::upload type uploadtest]- [::rivet::upload filename uploadtest]" ?>
+<?
+ set names_res [catch { set up_names [::rivet::upload names] }]
+ set exists_res [catch { set up_exists [::rivet::upload exists uploadtest] }]
+ set size_res [catch { set up_size [::rivet::upload size uploadtest] }]
+ set type_res [catch { set up_type [::rivet::upload type uploadtest] }]
+ set filen_res [catch { set up_filen [::rivet::upload filename uploadtest] }]
+
+ if {$names_res || $exists_res || $size_res || $type_res || $filen_res } {
+ puts [join [list $names_res $exists_res $size_res $type_res $filen_res] "|"]
+ } else {
+ puts [join [list $up_names $up_exists $up_size $up_type $up_filen] "|"]
+ }
+
+
+ #if {[catch {
+ # puts [join [list [::rivet::upload names] \
+ # [::rivet::upload exists uploadtest] \
+ # [::rivet::upload size uploadtest] \
+ # [::rivet::upload type uploadtest] \
+ # [::rivet::upload filename uploadtest]] "|"]
+ # } e einfo]} {
+ # puts "Error $e: $einfo"
+ #}
+?>
diff --git a/tests/upload.test b/tests/upload.test
index 7b1ea9a..07ea699 100644
--- a/tests/upload.test
+++ b/tests/upload.test
@@ -1,4 +1,3 @@
-# $Id$
set testfilename1 upload.rvt
@@ -11,13 +10,12 @@ set testfilename1 upload.rvt
set outputData "--$bound\r\nContent-Disposition: form-data; name=\"uploadtest\"; filename=\"AngeloFish.jpg\"\r\n\r\n$data\n--${bound}--"
- set page [::http::geturl "${urlbase}$testfilename1" \
- -type "multipart/form-data; boundary=$bound" -query $outputData]
+ set page [::http::geturl "${urlbase}$testfilename1" -type "multipart/form-data; boundary=$bound" -query $outputData]
set ret [string trim [::http::data $page]]
::http::cleanup $page
set ret
-} {uploadtest 1 42747 -- AngeloFish.jpg}
+} {uploadtest|1|42747||AngeloFish.jpg}
set testfilename1 uploadsave.rvt
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@tcl.apache.org
For additional commands, e-mail: commits-help@tcl.apache.org