From 6b49fd74838d674011e18fcddcf497ba073052a2 Mon Sep 17 00:00:00 2001
From: Daniel Stenberg <daniel@haxx.se>
Date: Fri, 5 Nov 2004 14:43:35 +0000
Subject: [PATCH] Tim Sneddon's VMS fix for huge HTTP POSTs

---
 CHANGES                               |  5 +++++
 RELEASE-NOTES                         |  5 ++++-
 lib/http.c                            |  9 +++++----
 lib/http.h                            |  9 +++++++++
 packages/vms/config-vms.h_with_ssl    | 10 ++++++++++
 packages/vms/config-vms.h_without_ssl | 10 ++++++++++
 6 files changed, 43 insertions(+), 5 deletions(-)

diff --git a/CHANGES b/CHANGES
index c675f7003..e9ea6a32d 100644
--- a/CHANGES
+++ b/CHANGES
@@ -6,6 +6,11 @@
 
                                   Changelog
 
+Daniel (5 November 2004)
+- Tim Sneddon made libcurl send no more than 64K in a single first chunk when
+  doing a huge POST on VMS, as this is a system limitation. Default on general
+  systems is 100K.
+
 Daniel (4 November 2004)
 - Andres Garcia made it build on mingw againa, my --retry code broke the build.
 
diff --git a/RELEASE-NOTES b/RELEASE-NOTES
index c66eb8fe1..48b2607db 100644
--- a/RELEASE-NOTES
+++ b/RELEASE-NOTES
@@ -17,6 +17,7 @@ This release includes the following changes:
 
 This release includes the following bugfixes:
 
+ o huge POSTs on VMS
  o configure no longer uses pkg-config on cross-compiles
  o potential gzip decompress memory leak
  o "-C - --fail" on a HTTP page already downloaded
@@ -27,11 +28,13 @@ Other curl-related news since the previous public release:
 
  o pycurl 7.12.2: http://pycurl.sf.net/
  o TclCurl 0.12.2: http://personal1.iddeo.es/andresgarci/tclcurl/english/
+ o libcurl.NET 1.1: http://www.seasideresearch.com/downloads.html
 
 This release would not have looked like this without help, code, reports and
 advice from friends like these:
 
  Peter Wullinger, Guillaume Arluison, Alexander Krasnostavsky, Mohun Biswas,
- Tomas Pospisek, Gisle Vanem, Dan Fandrich, Paul Nolan
+ Tomas Pospisek, Gisle Vanem, Dan Fandrich, Paul Nolan, Andres Garcia,
+ Tim Sneddon
 
         Thanks! (and sorry if I forgot to mention someone)
diff --git a/lib/http.c b/lib/http.c
index 1de316b2f..9b51cc7d6 100644
--- a/lib/http.c
+++ b/lib/http.c
@@ -1925,14 +1925,15 @@ CURLcode Curl_http(struct connectdata *conn)
       if(data->set.postfields) {
 
         if((data->state.authhost.done || data->state.authproxy.done )
-           && (postsize < (100*1024))) {
+           && (postsize < MAX_INITIAL_POST_SIZE)) {
           /* If we're not done with the authentication phase, we don't expect
              to actually send off any data yet. Hence, we delay the sending of
              the body until we receive that friendly 100-continue response */
 
-          /* The post data is less than 100K, then append it to the header.
-             This limit is no magic limit but only set to prevent really huge
-             POSTs to get the data duplicated with malloc() and family. */
+          /* The post data is less than MAX_INITIAL_PORT_SIZE, then append it
+             to the header. This limit is no magic limit but only set to
+             prevent really huge POSTs to get the data duplicated with
+             malloc() and family. */
 
           result = add_buffer(req_buffer, "\r\n", 2); /* end of headers! */
           if(result)
diff --git a/lib/http.h b/lib/http.h
index 80c180798..d321333fe 100644
--- a/lib/http.h
+++ b/lib/http.h
@@ -57,5 +57,14 @@ int Curl_http_should_fail(struct connectdata *conn);
    public curl/curl.h header. */
 #define CURLAUTH_PICKNONE (1<<30) /* don't use auth */
 
+/* MAX_INITIAL_POST_SIZE indicates the number of kilobytes that will be sent
+   in the initial part of a multi-part POST message. This is primarily for
+   OpenVMS where the maximum number of bytes allowed per I/O is 64K.  For
+   other systems that do not define this, the default is (as it was
+   previously) 100K. */
+#ifndef MAX_INITIAL_POST_SIZE
+#define MAX_INITIAL_POST_SIZE (100*1024)
+#endif
+
 #endif
 #endif
diff --git a/packages/vms/config-vms.h_with_ssl b/packages/vms/config-vms.h_with_ssl
index b9d251f78..9d8e522b7 100755
--- a/packages/vms/config-vms.h_with_ssl
+++ b/packages/vms/config-vms.h_with_ssl
@@ -2,6 +2,7 @@
 /* MSK, 03/09/04, Seems to work for all platforms I've built on so far.    */
 /*      Added HAVE_SYS_IOCTL_H, IOCTL_3_ARGS and SIZEOF_CURL_OFF_T defines */
 /* MSK, 06/04/04, Added HAVE_INET_NTOP                                     */
+/* TES, 11/05/04, Added MAX_INITIAL_POST_SIZE, HAVE_BASENAME               */
 
 /* Define cpu-machine-OS */
 #ifdef __ALPHA
@@ -14,6 +15,12 @@
 #endif
 #endif
 
+/* Define to set number of kilobytes in initial POST message. On VMS systems
+   this is important as the default is 100 and the maximum amount of data
+   transferable in a VMS $QIO is 64K. All VMS versions prior to Alpha/I64
+   V8.2 and TCP/IP V5.5 are affected by this. */
+#define MAX_INITIAL_POST_SIZE (60*1024)
+
 /* Define if you have the ANSI C header files.  */
 #define STDC_HEADERS 1
 
@@ -32,6 +39,9 @@
 /* Define if you have the geteuid function.  */
 #define HAVE_GETEUID 1
 
+/* Define if you have the basename function. */
+#define HAVE_BASENAME 1
+
 /* Define if you have the gethostbyaddr function.  */
 #define HAVE_GETHOSTBYADDR 1
 
diff --git a/packages/vms/config-vms.h_without_ssl b/packages/vms/config-vms.h_without_ssl
index 1b49b5fdd..0d7eee7c8 100755
--- a/packages/vms/config-vms.h_without_ssl
+++ b/packages/vms/config-vms.h_without_ssl
@@ -2,6 +2,7 @@
 /* MSK, 03/09/04, Seems to work for all platforms I've built on so far.    */
 /*      Added HAVE_SYS_IOCTL_H, IOCTL_3_ARGS and SIZEOF_CURL_OFF_T defines */
 /* MSK, 06/04/04, Added HAVE_INET_NTOP                                     */
+/* TES, 10/06/04, Added MAX_INITIAL_POST_SIZE, HAVE_BASENAME               */
 
 /* Define cpu-machine-OS */
 #ifdef __ALPHA
@@ -14,6 +15,12 @@
 #endif
 #endif
 
+/* Define to set the number of kilobytes per POST message. On VMS systems
+   this is important as the default is 100 and the maximum amount of data
+   transferable in a VMS QIO is 64K. All VMS versions prior to Alpha/I64 V8.2
+   and TCP/IP V5.5 are affected by this. */
+#define MAX_INITIAL_POST_SIZE (60*1024)
+
 /* Define if you have the ANSI C header files.  */
 #define STDC_HEADERS 1
 
@@ -32,6 +39,9 @@
 /* Define if you have the geteuid function.  */
 #define HAVE_GETEUID 1
 
+/* Define if you have the basename function. */
+#define HAVE_BASENAME 1
+
 /* Define if you have the gethostbyaddr function.  */
 #define HAVE_GETHOSTBYADDR 1
 
-- 
2.40.0