diff -Naur curl.orig/include/curl/curl.h curl/include/curl/curl.h
--- curl.orig/include/curl/curl.h	2007-07-02 13:49:19.140794000 +0200
+++ curl/include/curl/curl.h	2007-07-17 22:05:46.745214000 +0200
@@ -502,6 +502,9 @@
 #define CURLOPTTYPE_FUNCTIONPOINT 20000
 #define CURLOPTTYPE_OFF_T         30000
 
+#define CURLOPTION_NUMBER(opt)  ((int) (opt) % 10000)
+#define CURLOPTION_TYPE(opt)    ((int) (opt) - CURLOPTION_NUMBER(opt))
+
 /* name is uppercase CURLOPT_<name>,
    type is one of the defined CURLOPTTYPE_<type>
    number is unique identifier */
@@ -517,7 +520,8 @@
  */
 #if defined(__STDC__) || defined(_MSC_VER) || defined(__cplusplus) || \
   defined(__HP_aCC) || defined(__BORLANDC__) || defined(__LCC__) || \
-  defined(__POCC__) || defined(__SALFORDC__) || defined(__HIGHC__)
+  defined(__POCC__) || defined(__SALFORDC__) || defined(__HIGHC__) || \
+  defined(__ILEC400__)
   /* This compiler is believed to have an ISO compatible preprocessor */
 #define CURL_ISOCPP
 #else
diff -Naur curl.orig/include/curl/mprintf.h curl/include/curl/mprintf.h
--- curl.orig/include/curl/mprintf.h	2006-10-30 17:26:24.000000000 +0100
+++ curl/include/curl/mprintf.h	2007-06-12 12:39:30.902906000 +0200
@@ -44,6 +44,16 @@
 CURL_EXTERN char *curl_mvaprintf(const char *format, va_list args);
 
 #ifdef _MPRINTF_REPLACE
+# undef printf
+# undef fprintf
+# undef sprintf
+# undef vsprintf
+# undef snprintf
+# undef vprintf
+# undef vfprintf
+# undef vsnprintf
+# undef aprintf
+# undef vaprintf
 # define printf curl_mprintf
 # define fprintf curl_mfprintf
 #ifdef CURLDEBUG
diff -Naur curl.orig/lib/config-os400.h curl/lib/config-os400.h
--- curl.orig/lib/config-os400.h	1970-01-01 01:00:00.000000000 +0100
+++ curl/lib/config-os400.h	2007-07-17 21:43:27.198054000 +0200
@@ -0,0 +1,562 @@
+/* ================================================================ */
+/*    lib/config-os400.h - Hand crafted config file for OS/400      */
+/* ================================================================ */
+
+#pragma enum(int)
+
+#undef PACKAGE
+
+/* Version number of this archive. */
+#undef VERSION
+
+/* Define if you have the getpass function.  */
+#undef HAVE_GETPASS
+
+/* Define cpu-machine-OS */
+#define OS "OS/400"
+
+/* Define if you have the gethostbyaddr_r() function with 5 arguments */
+#define HAVE_GETHOSTBYADDR_R_5
+
+/* Define if you have the gethostbyaddr_r() function with 7 arguments */
+#undef HAVE_GETHOSTBYADDR_R_7
+
+/* Define if you have the gethostbyaddr_r() function with 8 arguments */
+#undef HAVE_GETHOSTBYADDR_R_8
+
+/* Define if you have the gethostbyname_r() function with 3 arguments */
+#define HAVE_GETHOSTBYNAME_R_3
+
+/* Define if you have the gethostbyname_r() function with 5 arguments */
+#undef HAVE_GETHOSTBYNAME_R_5
+
+/* Define if you have the gethostbyname_r() function with 6 arguments */
+#undef HAVE_GETHOSTBYNAME_R_6
+
+/* Define if you have the inet_ntoa_r function declared. */
+#define HAVE_INET_NTOA_R_DECL
+
+/* Define if the inet_ntoa_r function returns an int. */
+#define HAVE_INT_INET_NTOA_R
+
+/* Define if you need the _REENTRANT define for some functions */
+#undef NEED_REENTRANT
+
+/* Define if you have the Kerberos4 libraries (including -ldes) */
+#undef HAVE_KRB4
+
+/* Define if you want to enable IPv6 support */
+#define ENABLE_IPV6
+
+/* Define this to 'int' if ssize_t is not an available typedefed type */
+#undef ssize_t
+
+/* Define this to 'int' if socklen_t is not an available typedefed type */
+#undef socklen_t
+
+/* Define this as a suitable file to read random data from */
+#undef RANDOM_FILE
+
+/* Define this to your Entropy Gathering Daemon socket pathname */
+#undef EGD_SOCKET
+
+/* Set to explicitly specify we don't want to use thread-safe functions */
+#undef DISABLED_THREADSAFE
+
+/* Define if you have the <alloca.h> header file. */
+#undef HAVE_ALLOCA_H
+
+/* Define if you have the <arpa/inet.h> header file. */
+#define HAVE_ARPA_INET_H
+
+/* Define if you have the `closesocket' function. */
+#undef HAVE_CLOSESOCKET
+
+/* Define if you have the <crypto.h> header file. */
+#undef HAVE_CRYPTO_H
+
+/* Define if you have the <des.h> header file. */
+#undef HAVE_DES_H
+
+/* Define if you have the <dlfcn.h> header file. */
+#undef HAVE_DLFCN_H
+
+/* Define if you have the `dlopen' function. */
+#undef HAVE_DLOPEN
+
+/* Define if you have the <err.h> header file. */
+#undef HAVE_ERR_H
+
+/* Define if you have the <fcntl.h> header file. */
+#define HAVE_FCNTL_H
+
+/* Define if getaddrinfo exists and works */
+/* OS400 has no ASCII version of this procedure. */
+#undef HAVE_GETADDRINFO
+
+/* Define if you have the `geteuid' function. */
+#define HAVE_GETEUID
+
+/* Define if you have the `gethostbyaddr' function. */
+#define HAVE_GETHOSTBYADDR
+
+/* Define if you have the `gethostbyaddr_r' function. */
+#define HAVE_GETHOSTBYADDR_R
+
+/* Define if you have the `gethostbyname_r' function. */
+#define HAVE_GETHOSTBYNAME_R
+
+/* Define if you have the `gethostname' function. */
+#define HAVE_GETHOSTNAME
+
+/* Define if you have the <getopt.h> header file. */
+#undef HAVE_GETOPT_H
+
+/* Define if you have the `getpass_r' function. */
+#undef HAVE_GETPASS_R
+
+/* Define if you have the `getpwuid' function. */
+#define HAVE_GETPWUID
+
+/* Define if you have the `getservbyname' function. */
+#define HAVE_GETSERVBYNAME
+
+/* Define if you have the `gettimeofday' function. */
+#define HAVE_GETTIMEOFDAY
+
+/* Define if you have the `timeval' struct. */
+#define HAVE_STRUCT_TIMEVAL
+
+/* Define if you have the `inet_addr' function. */
+#define HAVE_INET_ADDR
+
+/* Define if you have the `inet_ntoa' function. */
+#define HAVE_INET_NTOA
+
+/* Define if you have the `inet_ntoa_r' function. */
+#define HAVE_INET_NTOA_R
+
+/* Define if you have the <inttypes.h> header file. */
+#define HAVE_INTTYPES_H
+
+/* Define if you have the <io.h> header file. */
+#undef HAVE_IO_H
+
+/* Define if you have the `krb_get_our_ip_for_realm' function. */
+#undef HAVE_KRB_GET_OUR_IP_FOR_REALM
+
+/* Define if you have the <krb.h> header file. */
+#undef HAVE_KRB_H
+
+/* Define if you have the `crypto' library (-lcrypto). */
+#undef HAVE_LIBCRYPTO
+
+/* Define if you have the `dl' library (-ldl). */
+#undef HAVE_LIBDL
+
+/* Define if you have the `nsl' library (-lnsl). */
+#undef HAVE_LIBNSL
+
+/* Define if you have the `resolv' library (-lresolv). */
+#undef HAVE_LIBRESOLV
+
+/* Define if you have the `resolve' library (-lresolve). */
+#undef HAVE_LIBRESOLVE
+
+/* Define if you have the `socket' library (-lsocket). */
+#undef HAVE_LIBSOCKET
+
+/* Define if you have the `ssl' library (-lssl). */
+#undef HAVE_LIBSSL
+
+/* Define if you have GSS API. */
+#define HAVE_GSSAPI
+
+/* Define if you have the `ucb' library (-lucb). */
+#undef HAVE_LIBUCB
+
+/* Define if you have the `localtime_r' function. */
+#define HAVE_LOCALTIME_R
+
+/* Define if you have the <malloc.h> header file. */
+#define HAVE_MALLOC_H
+
+/* Define if you need the malloc.h header file even with stdlib.h  */
+/* #define NEED_MALLOC_H 1 */
+
+/* Define if you have the <memory.h> header file. */
+#undef HAVE_MEMORY_H
+
+/* Define if you have the <netdb.h> header file. */
+#define HAVE_NETDB_H
+
+/* Define if you have the <netinet/if_ether.h> header file. */
+#undef HAVE_NETINET_IF_ETHER_H
+
+/* Define if you have the <netinet/in.h> header file. */
+#define HAVE_NETINET_IN_H
+
+/* Define if you have the <net/if.h> header file. */
+#define HAVE_NET_IF_H
+
+/* Define if you have the <openssl/crypto.h> header file. */
+#undef HAVE_OPENSSL_CRYPTO_H
+
+/* Define if you have the <openssl/err.h> header file. */
+#undef HAVE_OPENSSL_ERR_H
+
+/* Define if you have the <openssl/pem.h> header file. */
+#undef HAVE_OPENSSL_PEM_H
+
+/* Define if you have the <openssl/rsa.h> header file. */
+#undef HAVE_OPENSSL_RSA_H
+
+/* Define if you have the <openssl/ssl.h> header file. */
+#undef HAVE_OPENSSL_SSL_H
+
+/* Define if you have the <openssl/x509.h> header file. */
+#undef HAVE_OPENSSL_X509_H
+
+/* Define if you have the <pem.h> header file. */
+#undef HAVE_PEM_H
+
+/* Define if you have the `perror' function. */
+#define HAVE_PERROR
+
+/* Define if you have the <pwd.h> header file. */
+#define HAVE_PWD_H
+
+/* Define if you have the `RAND_egd' function. */
+#undef HAVE_RAND_EGD
+
+/* Define if you have the `RAND_screen' function. */
+#undef HAVE_RAND_SCREEN
+
+/* Define if you have the `RAND_status' function. */
+#undef HAVE_RAND_STATUS
+
+/* Define if you have the <rsa.h> header file. */
+#undef HAVE_RSA_H
+
+/* Define if you have the `select' function. */
+#define HAVE_SELECT
+
+/* Define if you have the `setvbuf' function. */
+#define HAVE_SETVBUF
+
+/* Define if you have the <sgtty.h> header file. */
+#undef HAVE_SGTTY_H
+
+/* Define if you have the `sigaction' function. */
+#define HAVE_SIGACTION
+
+/* Define if you have the `signal' function. */
+#undef HAVE_SIGNAL
+
+/* Define if you have the <signal.h> header file. */
+#define HAVE_SIGNAL_H
+
+/* Define if sig_atomic_t is an available typedef. */
+#define HAVE_SIG_ATOMIC_T
+
+/* Define if sig_atomic_t is already defined as volatile. */
+#undef HAVE_SIG_ATOMIC_T_VOLATILE
+
+/* Define if you have the `socket' function. */
+#define HAVE_SOCKET
+
+/* Define if you have the <ssl.h> header file. */
+#undef HAVE_SSL_H
+
+/* Define if you have the <stdint.h> header file. */
+#undef HAVE_STDINT_H
+
+/* Define if you have the <stdlib.h> header file. */
+#define HAVE_STDLIB_H
+
+/* Define if you have the `strcasecmp' function. */
+#undef HAVE_STRCASECMP
+
+/* Define if you have the `strcmpi' function. */
+#undef HAVE_STRCMPI
+
+/* Define if you have the `strdup' function. */
+#undef HAVE_STRDUP
+
+/* Define if you have the `strftime' function. */
+#define HAVE_STRFTIME
+
+/* Define if you have the `stricmp' function. */
+#undef HAVE_STRICMP
+
+/* Define if you have the <strings.h> header file. */
+#define HAVE_STRINGS_H
+
+/* Define if you have the <string.h> header file. */
+#define HAVE_STRING_H
+
+/* Define if you have the `strlcat' function. */
+#undef HAVE_STRLCAT
+
+/* Define if you have the `strlcpy' function. */
+#undef HAVE_STRLCPY
+
+/* Define if you have the `strstr' function. */
+#define HAVE_STRSTR
+
+/* Define if you have the `strtok_r' function. */
+#define HAVE_STRTOK_R
+
+/* Define if you have the `strtoll' function. */
+#define HAVE_STRTOLL
+
+/* Define if you have the <sys/param.h> header file. */
+#define HAVE_SYS_PARAM_H
+
+/* Define if you have the <sys/select.h> header file. */
+#undef HAVE_SYS_SELECT_H
+
+/* Define if you have the <sys/socket.h> header file. */
+#define HAVE_SYS_SOCKET_H
+
+/* Define if you have the <sys/sockio.h> header file. */
+#undef HAVE_SYS_SOCKIO_H
+
+/* Define if you have the <sys/stat.h> header file. */
+#define HAVE_SYS_STAT_H
+
+/* Define if you have the <sys/time.h> header file. */
+#define HAVE_SYS_TIME_H
+
+/* Define if you have the <sys/types.h> header file. */
+#define HAVE_SYS_TYPES_H
+
+/* Define if you have the <sys/ioctl.h> header file. */
+#define HAVE_SYS_IOCTL_H
+
+/* Define if you have the `tcgetattr' function. */
+#undef HAVE_TCGETATTR
+
+/* Define if you have the `tcsetattr' function. */
+#undef HAVE_TCSETATTR
+
+/* Define if you have the <termios.h> header file. */
+#undef HAVE_TERMIOS_H
+
+/* Define if you have the <termio.h> header file. */
+#undef HAVE_TERMIO_H
+
+/* Define if you have the <time.h> header file. */
+#define HAVE_TIME_H
+
+/* Define if you have the `uname' function. */
+#undef HAVE_UNAME
+
+/* Define if you have the <unistd.h> header file. */
+#define HAVE_UNISTD_H
+
+/* Define if you have the <winsock.h> header file. */
+#undef HAVE_WINSOCK_H
+
+/* Define if you have the <x509.h> header file. */
+#undef HAVE_X509_H
+
+/* Name of package */
+#undef PACKAGE
+
+/* Define as the return type of signal handlers (`int' or `void'). */
+#define RETSIGTYPE void
+
+/* The size of a `long double', as computed by sizeof. */
+#define SIZEOF_LONG_DOUBLE      8
+
+/* The size of a `long long', as computed by sizeof. */
+#define SIZEOF_LONG_LONG        8
+
+/* Define if you have the ANSI C header files. */
+#define STDC_HEADERS
+
+/* Define if you can safely include both <sys/time.h> and <time.h>. */
+#define TIME_WITH_SYS_TIME
+
+/* Version number of package */
+#undef VERSION
+
+/* Number of bits in a file offset, on hosts where this is settable. */
+#undef _FILE_OFFSET_BITS
+
+/* Define for large files, on AIX-style hosts. */
+#undef _LARGE_FILES
+
+/* Define to empty if `const' does not conform to ANSI C. */
+#undef const
+
+/* type to use in place of in_addr_t if not defined */
+#define in_addr_t       unsigned long
+
+/* Define to `unsigned' if <sys/types.h> does not define. */
+#undef size_t
+
+#define IOCTL_3_ARGS
+
+#define HAVE_FIONBIO
+
+/* to disable LDAP */
+#undef CURL_DISABLE_LDAP
+
+/* Define if you have the getnameinfo function. */
+/* OS400 has no ASCII version of this procedure. */
+#undef HAVE_GETNAMEINFO
+
+/* Define to the type qualifier of arg 1 for getnameinfo. */
+#define GETNAMEINFO_QUAL_ARG1 const
+
+/* Define to the type of arg 1 for getnameinfo. */
+#define GETNAMEINFO_TYPE_ARG1 struct sockaddr *
+
+/* Define to the type of arg 2 for getnameinfo. */
+#define GETNAMEINFO_TYPE_ARG2 socklen_t
+
+/* Define to the type of args 4 and 6 for getnameinfo. */
+#define GETNAMEINFO_TYPE_ARG46 socklen_t
+
+/* Define to the type of arg 7 for getnameinfo. */
+#define GETNAMEINFO_TYPE_ARG7 int
+
+/* Define if you have the recv function. */
+#define HAVE_RECV
+
+/* Define to the type of arg 1 for recv. */
+#define RECV_TYPE_ARG1 int
+
+/* Define to the type of arg 2 for recv. */
+#define RECV_TYPE_ARG2 char *
+
+/* Define to the type of arg 3 for recv. */
+#define RECV_TYPE_ARG3 int
+
+/* Define to the type of arg 4 for recv. */
+#define RECV_TYPE_ARG4 int
+
+/* Define to the function return type for recv. */
+#define RECV_TYPE_RETV int
+
+/* Define if you have the send function. */
+#define HAVE_SEND
+
+/* Define to the type of arg 1 for send. */
+#define SEND_TYPE_ARG1 int
+
+/* Define to the type qualifier of arg 2 for send. */
+#define SEND_QUAL_ARG2
+
+/* Define to the type of arg 2 for send. */
+#define SEND_TYPE_ARG2 char *
+
+/* Define to the type of arg 3 for send. */
+#define SEND_TYPE_ARG3 int
+
+/* Define to the type of arg 4 for send. */
+#define SEND_TYPE_ARG4 int
+
+/* Define to the function return type for send. */
+#define SEND_TYPE_RETV int
+
+/* Define to use the QsoSSL package. */
+#define USE_QSOSSL
+
+/* Use the system keyring as the default CA bundle. */
+#define CURL_CA_BUNDLE  "/QIBM/UserData/ICSS/Cert/Server/DEFAULT.KDB"
+
+
+/* OS/400 netdb.h does not define NI_MAXHOST. */
+#define NI_MAXHOST      1025
+
+/* OS/400 netdb.h does not define NI_MAXSERV. */
+#define NI_MAXSERV      32
+
+/* OS/400 does not define the ifr_dstaddr union member. */
+#define ifr_dstaddr     ifr_addr
+
+/* No OS/400 header file defines u_int32_t. */
+#define u_int32_t       unsigned long
+
+
+/* Additional support for OS/400. */
+
+#define __ptr128                /* No teraspace. */
+#define qadrt_use_inline
+#define qadrt_use_fputc_inline  /* Bug in include file: this is needed. */
+
+#include <sys/socket.h>
+#include <netdb.h>
+#include <qsossl.h>
+#include <gssapi.h>
+
+extern int      Curl_getaddrinfo_a(const char * nodename, const char * servname,
+                                   const struct addrinfo * hints,
+                                   struct addrinfo * * res);
+#define getaddrinfo             Curl_getaddrinfo_a
+
+
+extern int      Curl_getnameinfo_a(const struct sockaddr * sa, socklen_t salen,
+                                   char * nodename, socklen_t nodenamelen,
+                                   char * servname, socklen_t servnamelen,
+                                   int flags);
+#define getnameinfo             Curl_getnameinfo_a
+
+
+extern int      Curl_inet_ntoa_r_a(struct in_addr internet_address,
+                                   char * output_buffer,
+                                   int output_buffer_length);
+#define inet_ntoa_r             Curl_inet_ntoa_r_a
+
+
+extern int      Curl_SSL_Init_Application_a(SSLInitApp * init_app);
+#define SSL_Init_Application    Curl_SSL_Init_Application_a
+
+
+extern int      Curl_SSL_Init_a(SSLInit * init);
+#define SSL_Init                Curl_SSL_Init_a
+
+
+extern char *   Curl_SSL_Strerror_a(int sslreturnvalue, SSLErrorMsg * serrmsgp);
+#define SSL_Strerror            Curl_SSL_Strerror_a
+
+
+extern OM_uint32 Curl_gss_import_name_a(OM_uint32 * minor_status,
+                                        gss_buffer_t in_name,
+                                        gss_OID in_name_type,
+                                        gss_name_t * out_name);
+#define gss_import_name         Curl_gss_import_name_a
+
+
+extern OM_uint32 Curl_gss_display_status_a(OM_uint32 * minor_status,
+                                           OM_uint32 status_value,
+                                           int status_type, gss_OID mech_type,
+                                           gss_msg_ctx_t * message_context,
+                                           gss_buffer_t status_string);
+#define gss_display_status      Curl_gss_display_status_a
+
+
+extern OM_uint32 Curl_gss_init_sec_context_a(OM_uint32 * minor_status,
+                                             gss_cred_id_t cred_handle,
+                                             gss_ctx_id_t * context_handle,
+                                             gss_name_t target_name,
+                                             gss_OID mech_type,
+                                             gss_flags_t req_flags,
+                                             OM_uint32 time_req,
+                                             gss_channel_bindings_t
+                                             input_chan_bindings,  
+                                             gss_buffer_t input_token,
+                                             gss_OID * actual_mech_type,
+                                             gss_buffer_t output_token,
+                                             gss_flags_t * ret_flags,
+                                             OM_uint32 * time_rec);
+#define gss_init_sec_context    Curl_gss_init_sec_context_a
+
+
+extern OM_uint32 Curl_gss_delete_sec_context_a(OM_uint32 * minor_status,
+                                               gss_ctx_id_t * context_handle,
+                                               gss_buffer_t output_token);
+#define gss_delete_sec_context  Curl_gss_delete_sec_context_a
diff -Naur curl.orig/lib/easy.c curl/lib/easy.c
--- curl.orig/lib/easy.c	2007-07-12 12:18:27.017588000 +0200
+++ curl/lib/easy.c	2007-07-13 18:00:23.907175000 +0200
@@ -579,7 +579,8 @@
     outcurl->state.headersize=HEADERSIZE;
 
     /* copy all userdefined values */
-    outcurl->set = data->set;
+    if (Curl_dupset(outcurl, data) != CURLE_OK)
+      break;
 
     if(data->state.used_interface == Curl_if_multi)
       outcurl->state.connc = data->state.connc;
@@ -654,6 +655,7 @@
         Curl_rm_connc(outcurl->state.connc);
       if(outcurl->state.headerbuff)
         free(outcurl->state.headerbuff);
+      Curl_freeset(outcurl);
       if(outcurl->change.url)
         free(outcurl->change.url);
       if(outcurl->change.referer)
@@ -696,10 +698,10 @@
   data->set.err  = stderr;  /* default stderr to stderr */
 
   /* use fwrite as default function to store output */
-  data->set.fwrite = (curl_write_callback)fwrite;
+  data->set.fwrite_func = (curl_write_callback)fwrite;
 
   /* use fread as default function to read input */
-  data->set.fread = (curl_read_callback)fread;
+  data->set.fread_func = (curl_read_callback)fread;
 
   data->set.infilesize = -1; /* we don't know any size */
   data->set.postfieldsize = -1;
diff -Naur curl.orig/lib/escape.c curl/lib/escape.c
--- curl.orig/lib/escape.c	2006-10-17 23:32:56.000000000 +0200
+++ curl/lib/escape.c	2007-07-17 22:08:30.788939000 +0200
@@ -75,9 +75,27 @@
   length = alloc-1;
   while(length--) {
     in = *string;
-    if(!(in >= 'a' && in <= 'z') &&
-       !(in >= 'A' && in <= 'Z') &&
-       !(in >= '0' && in <= '9')) {
+
+    /* Portable character check (remember EBCDIC). Do not use isalnum() because
+       its behavior is altered by the current locale. */
+
+    switch (in) {
+    case '0': case '1': case '2': case '3': case '4':
+    case '5': case '6': case '7': case '8': case '9':
+    case 'a': case 'b': case 'c': case 'd': case 'e':
+    case 'f': case 'g': case 'h': case 'i': case 'j':
+    case 'k': case 'l': case 'm': case 'n': case 'o':
+    case 'p': case 'q': case 'r': case 's': case 't':
+    case 'u': case 'v': case 'w': case 'x': case 'y': case 'z':
+    case 'A': case 'B': case 'C': case 'D': case 'E':
+    case 'F': case 'G': case 'H': case 'I': case 'J':
+    case 'K': case 'L': case 'M': case 'N': case 'O':
+    case 'P': case 'Q': case 'R': case 'S': case 'T':
+    case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z':
+      /* just copy this */
+      ns[strindex++]=in;
+      break;
+    default:
       /* encode it */
       newlen += 2; /* the size grows with two, since this'll become a %XX */
       if(newlen > alloc) {
@@ -105,10 +123,7 @@
       snprintf(&ns[strindex], 4, "%%%02X", in);
 
       strindex+=3;
-    }
-    else {
-      /* just copy this */
-      ns[strindex++]=in;
+      break;
     }
     string++;
   }
diff -Naur curl.orig/lib/file.c curl/lib/file.c
--- curl.orig/lib/file.c	2007-06-28 14:27:37.691637000 +0200
+++ curl/lib/file.c	2007-07-13 18:25:51.965938000 +0200
@@ -205,7 +205,7 @@
    * Since FILE: doesn't do the full init, we need to provide some extra
    * assignments here.
    */
-  conn->fread = data->set.fread;
+  conn->fread_func = data->set.fread_func;
   conn->fread_in = data->set.in;
   conn->data->reqdata.upload_fromhere = buf;
 
diff -Naur curl.orig/lib/formdata.c curl/lib/formdata.c
--- curl.orig/lib/formdata.c	2007-03-31 23:01:18.000000000 +0200
+++ curl/lib/formdata.c	2007-07-16 21:12:32.260811000 +0200
@@ -50,7 +50,7 @@
 
 Content-Disposition: form-data; name="PTRCONTENTS_+_CONTENTSLENGTH_+_CONTENTTYPE"
 Content-Type: text/plain
-vlue for PTRCOTNENTS + CONTENTSLENGTH + CONTENTTYPE
+vlue for PTRCONTENTS + CONTENTSLENGTH + CONTENTTYPE
 (or you might see v^@lue at the start)
 
 Content-Disposition: form-data; name="FILE1_+_CONTENTTYPE"; filename="inet_ntoa_r.h"
@@ -1495,7 +1495,7 @@
 }
 
 
-int main()
+int main(int argc, argv_item_t argv[])
 {
   char name1[] = "simple_COPYCONTENTS";
   char name2[] = "COPYCONTENTS_+_CONTENTTYPE";
@@ -1513,7 +1513,7 @@
   char value3[] = "value for PTRNAME + NAMELENGTH + COPYNAME + CONTENTSLENGTH";
   char value4[] = "value for simple PTRCONTENTS";
   char value5[] = "value for PTRCONTENTS + CONTENTSLENGTH";
-  char value6[] = "value for PTRCOTNENTS + CONTENTSLENGTH + CONTENTTYPE";
+  char value6[] = "value for PTRCONTENTS + CONTENTSLENGTH + CONTENTTYPE";
   char value7[] = "inet_ntoa_r.h";
   char value8[] = "Makefile.b32";
   char type2[] = "image/gif";
@@ -1521,11 +1521,11 @@
   char type7[] = "text/html";
   int name3length = strlen(name3);
   int value3length = strlen(value3);
-  int value5length = strlen(value4);
-  int value6length = strlen(value5);
+  int value5length = strlen(value5);
+  int value6length = strlen(value6);
   int errors = 0;
   CURLcode rc;
-  size_t size;
+  curl_off_t size;
   size_t nread;
   char buffer[4096];
   struct curl_httppost *httppost=NULL;
@@ -1535,6 +1535,9 @@
   struct FormData *form;
   struct Form formread;
 
+  (void) argc;
+  (void) argv;
+
   if (FormAddTest("simple COPYCONTENTS test", &httppost, &last_post,
                   CURLFORM_COPYNAME, name1, CURLFORM_COPYCONTENTS, value1,
                   CURLFORM_END))
@@ -1621,7 +1624,9 @@
     fwrite(buffer, nread, 1, stdout);
   } while(1);
 
-  fprintf(stdout, "size: %d\n", size);
+  fprintf(stdout, "size: ");
+  fprintf(stdout, CURL_FORMAT_OFF_T, size);
+  fprintf(stdout, "\n");
   if (errors)
     fprintf(stdout, "\n==> %d Test(s) failed!\n", errors);
   else
diff -Naur curl.orig/lib/ftp.c curl/lib/ftp.c
--- curl.orig/lib/ftp.c	2007-07-16 11:46:32.639151000 +0200
+++ curl/lib/ftp.c	2007-07-16 11:46:56.923878000 +0200
@@ -1477,7 +1477,7 @@
         readthisamountnow = BUFSIZE;
 
       actuallyread = (curl_off_t)
-        conn->fread(data->state.buffer, 1, (size_t)readthisamountnow,
+        conn->fread_func(data->state.buffer, 1, (size_t)readthisamountnow,
                     conn->fread_in);
 
       passed += actuallyread;
diff -Naur curl.orig/lib/http.c curl/lib/http.c
--- curl.orig/lib/http.c	2007-07-11 18:44:06.726523000 +0200
+++ curl/lib/http.c	2007-07-11 18:42:40.572479000 +0200
@@ -790,7 +790,7 @@
       /* move backup data into focus and continue on that */
       http->postdata = http->backup.postdata;
       http->postsize = http->backup.postsize;
-      conn->fread =    http->backup.fread;
+      conn->fread_func = http->backup.fread_func;
       conn->fread_in = http->backup.fread_in;
 
       http->sending++; /* move one step up */
@@ -940,13 +940,13 @@
         ptr = in->buffer + amount;
 
         /* backup the currently set pointers */
-        http->backup.fread = conn->fread;
+        http->backup.fread_func = conn->fread_func;
         http->backup.fread_in = conn->fread_in;
         http->backup.postdata = http->postdata;
         http->backup.postsize = http->postsize;
 
         /* set the new pointers for the request-sending */
-        conn->fread = (curl_read_callback)readmoredata;
+        conn->fread_func = (curl_read_callback)readmoredata;
         conn->fread_in = (void *)conn;
         http->postdata = ptr;
         http->postsize = (curl_off_t)size;
@@ -1588,6 +1588,18 @@
   (void)numsocks;
   return GETSOCK_BLANK;
 }
+#else
+#ifdef USE_QSOSSL
+int Curl_https_getsock(struct connectdata *conn,
+                       curl_socket_t *socks,
+                       int numsocks)
+{
+  (void)conn;
+  (void)socks;
+  (void)numsocks;
+  return GETSOCK_BLANK;
+}
+#endif
 #endif
 #endif
 #endif
@@ -1606,7 +1618,7 @@
   (void)premature; /* not used */
 
   /* set the proper values (possibly modified on POST) */
-  conn->fread = data->set.fread; /* restore */
+  conn->fread_func = data->set.fread_func; /* restore */
   conn->fread_in = data->set.in; /* restore */
 
   if (http == NULL)
@@ -1991,7 +2003,7 @@
           readthisamountnow = BUFSIZE;
 
         actuallyread =
-          data->set.fread(data->state.buffer, 1, (size_t)readthisamountnow,
+          data->set.fread_func(data->state.buffer, 1, (size_t)readthisamountnow,
                           data->set.in);
 
         passed += actuallyread;
@@ -2246,7 +2258,7 @@
       }
 
       /* set the read function to read from the generated form data */
-      conn->fread = (curl_read_callback)Curl_FormReader;
+      conn->fread_func = (curl_read_callback)Curl_FormReader;
       conn->fread_in = &http->form;
 
       http->sending = HTTPSEND_BODY;
@@ -2446,7 +2458,7 @@
 
           http->sending = HTTPSEND_BODY;
 
-          conn->fread = (curl_read_callback)readmoredata;
+          conn->fread_func = (curl_read_callback)readmoredata;
           conn->fread_in = (void *)conn;
 
           /* set the upload size to the progress meter */
diff -Naur curl.orig/lib/inet_ntop.c curl/lib/inet_ntop.c
--- curl.orig/lib/inet_ntop.c	2007-07-02 13:49:19.359543000 +0200
+++ curl/lib/inet_ntop.c	2007-07-02 13:47:49.344494000 +0200
@@ -73,7 +73,12 @@
   return (char *)memmove(dst, ptr, strlen(ptr)+1);
 
 #elif defined(HAVE_INET_NTOA_R)
+
+#if defined(HAVE_INT_INET_NTOA_R)
+  return inet_ntoa_r(*(struct in_addr*)src, dst, size)? NULL: dst;
+#else
   return inet_ntoa_r(*(struct in_addr*)src, dst, size);
+#endif
 
 #else
   const char *addr = inet_ntoa(*(struct in_addr*)src);
diff -Naur curl.orig/lib/krb5.c curl/lib/krb5.c
--- curl.orig/lib/krb5.c	2007-07-13 10:32:55.323573000 +0200
+++ curl/lib/krb5.c	2007-07-13 10:36:47.073672000 +0200
@@ -155,7 +155,7 @@
   char *p;
   const char *host = conn->dns_entry->addr->ai_canonname;
   ssize_t nread;
-  unsigned int l = sizeof(conn->local_addr);
+  socklen_t l = sizeof(conn->local_addr);
   struct SessionHandle *data = conn->data;
   CURLcode result;
   const char *service = "ftp", *srv_host = "host";
diff -Naur curl.orig/lib/memdebug.c curl/lib/memdebug.c
--- curl.orig/lib/memdebug.c	2007-06-28 14:27:37.832241000 +0200
+++ curl/lib/memdebug.c	2007-07-17 20:07:39.087971000 +0200
@@ -47,7 +47,10 @@
 
 struct memdebug {
   size_t size;
-  double mem[1];
+  union {
+    double d;
+    void * p;
+  } mem[1];
   /* I'm hoping this is the thing with the strictest alignment
    * requirements.  That also means we waste some space :-( */
 };
diff -Naur curl.orig/lib/qssl.c curl/lib/qssl.c
--- curl.orig/lib/qssl.c	1970-01-01 01:00:00.000000000 +0100
+++ curl/lib/qssl.c	2007-07-13 18:25:08.357121000 +0200
@@ -0,0 +1,496 @@
+/***************************************************************************
+ *                                  _   _ ____  _
+ *  Project                     ___| | | |  _ \| |
+ *                             / __| | | | |_) | |
+ *                            | (__| |_| |  _ <| |___
+ *                             \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id: qssl.c,v 1.28 2007-01-05 23:11:16 bagder Exp $
+ ***************************************************************************/
+
+#include "setup.h"
+
+#ifdef USE_QSOSSL
+#include <qsossl.h>
+#include <errno.h>
+#include <string.h>
+
+#include <curl/curl.h>
+#include "urldata.h"
+#include "sendf.h"
+#include "qssl.h"
+#include "sslgen.h"
+#include "connect.h" /* for the connect timeout */
+#include "select.h"
+#include "memory.h"
+/* The last #include file should be: */
+#include "memdebug.h"
+
+
+static bool qsossl_inited = FALSE;
+
+
+int Curl_qsossl_init(void)
+
+{
+  /* Nothing to do here. We must have connection data to initialize ssl, so
+   * defer.
+   */
+
+  return 1;
+}
+
+
+void Curl_qsossl_cleanup(void)
+
+{
+  /* Nothing to do. */
+}
+
+
+static CURLcode Curl_qsossl_init_session(struct SessionHandle * data)
+
+{
+  int rc;
+  char * certname;
+  SSLInit initstr;
+  SSLInitApp initappstr;
+
+  /* Initialize the job for SSL according to the current parameters.
+   * QsoSSL offers two ways to do it: SSL_Init_Application() that uses an
+   *  application identifier to select certificates in the main certificate
+   *  store, and SSL_Init() that uses named keyring files and a password.
+   * It is not possible to have different keyrings for the CAs and the
+   *  local certificate. We thus use the certificate name to identify the
+   *  keyring if given, else the CA file name.
+   * If the key file name is given, it is taken as the password for the
+   *  keyring in certificate file.
+   * We first try to SSL_Init_Application(), then SSL_Init() if it failed.
+   */
+
+  certname = data->set.cert;
+
+  if (!certname) {
+    certname = data->set.ssl.CAfile;
+
+    if (!certname)
+      return CURLE_OK;          /* Use previous setup. */
+    }
+
+  memset((char *) &initappstr, 0, sizeof initappstr);
+  initappstr.applicationID = certname;
+  initappstr.applicationIDLen = strlen(certname);
+  initappstr.protocol = SSL_VERSION_CURRENT;
+  initappstr.sessionType = SSL_REGISTERED_AS_CLIENT;
+  rc = SSL_Init_Application(&initappstr);
+
+  if (rc == SSL_ERROR_NOT_REGISTERED) {
+    initstr.keyringFileName = certname;
+    initstr.keyringPassword = data->set.key;
+    initstr.cipherSuiteList = NULL;    /* Use default. */
+    initstr.cipherSuiteListLen = 0;
+    rc = SSL_Init(&initstr);
+    }
+
+  switch (rc) {
+
+  case 0:                             /* No error. */
+    break;
+
+  case SSL_ERROR_IO:
+    failf(data, "SSL_Init() I/O error: %s\n", strerror(errno));
+    return CURLE_SSL_CONNECT_ERROR;
+
+  case SSL_ERROR_BAD_CIPHER_SUITE:
+    return CURLE_SSL_CIPHER;
+
+  case SSL_ERROR_KEYPASSWORD_EXPIRED:
+  case SSL_ERROR_NOT_REGISTERED:
+    return CURLE_SSL_CONNECT_ERROR;
+
+  case SSL_ERROR_NO_KEYRING:
+    return CURLE_SSL_CACERT;
+
+  case SSL_ERROR_CERT_EXPIRED:
+    return CURLE_SSL_CERTPROBLEM;
+
+  default:
+    failf(data, "SSL_Init(): %s\n", SSL_Strerror(rc, NULL));
+    return CURLE_SSL_CONNECT_ERROR;
+  }
+
+  return CURLE_OK;
+}
+
+
+static CURLcode Curl_qsossl_create(struct connectdata * conn, int sockindex)
+
+{
+  SSLHandle * h;
+  struct ssl_connect_data * connssl = &conn->ssl[sockindex];
+
+  h = SSL_Create(conn->sock[sockindex], SSL_ENCRYPT);
+
+  if (!h) {
+    failf(conn->data, "SSL_Create() I/O error: %s\n", strerror(errno));
+    return CURLE_SSL_CONNECT_ERROR;
+    }
+
+  connssl->handle = h;
+  return CURLE_OK;
+}
+
+
+static int Curl_qsossl_trap_cert(SSLHandle * h)
+
+{
+	return 1;       /* Accept certificate. */
+}
+
+
+static CURLcode Curl_qsossl_handshake(struct connectdata * conn, int sockindex)
+
+{
+  int rc;
+  struct SessionHandle * data = conn->data;
+  struct ssl_connect_data * connssl = &conn->ssl[sockindex];
+  SSLHandle * h = connssl->handle;
+  long timeout_ms;
+
+  h->exitPgm = NULL;
+
+  if (!data->set.ssl.verifyhost)
+    h->exitPgm = Curl_qsossl_trap_cert;
+
+  if (data->set.connecttimeout) {
+    timeout_ms = data->set.connecttimeout;
+
+    if (data->set.timeout)
+      if (timeout_ms > data->set.timeout)
+        timeout_ms = data->set.timeout;
+    }
+  else if (data->set.timeout)
+    timeout_ms = data->set.timeout;
+  else
+    timeout_ms = DEFAULT_CONNECT_TIMEOUT;
+
+  /* SSL_Handshake() timeout resolution is second, so round up. */
+
+  h->timeout = (timeout_ms + 1000 - 1) / 1000;
+
+  /* Set-up protocol. */
+
+  switch(data->set.ssl.version) {
+
+  default:
+  case CURL_SSLVERSION_DEFAULT:
+    h->protocol = SSL_VERSION_CURRENT;
+    break;
+
+  case CURL_SSLVERSION_TLSv1:
+    h->protocol = TLS_VERSION_1;
+    break;
+
+  case CURL_SSLVERSION_SSLv2:
+    h->protocol = SSL_VERSION_2;
+    break;
+
+  case CURL_SSLVERSION_SSLv3:
+    h->protocol = SSL_VERSION_3;
+    break;
+  }
+
+  rc = SSL_Handshake(h, SSL_HANDSHAKE_AS_CLIENT);
+
+  switch (rc) {
+
+  case 0:                             /* No error. */
+    break;
+
+  case SSL_ERROR_BAD_CERTIFICATE:
+  case SSL_ERROR_BAD_CERT_SIG:
+  case SSL_ERROR_NOT_TRUSTED_ROOT:
+    return CURLE_SSL_PEER_CERTIFICATE;
+
+  case SSL_ERROR_BAD_CIPHER_SUITE:
+  case SSL_ERROR_NO_CIPHERS:
+    return CURLE_SSL_CIPHER;
+
+  case SSL_ERROR_CERTIFICATE_REJECTED:
+  case SSL_ERROR_CERT_EXPIRED:
+  case SSL_ERROR_NO_CERTIFICATE:
+    return CURLE_SSL_CERTPROBLEM;
+
+  case SSL_ERROR_IO:
+    failf(data, "SSL_Handshake(): %s\n", SSL_Strerror(rc, NULL));
+    return CURLE_SSL_CONNECT_ERROR;
+
+  default:
+    failf(data, "SSL_Init(): %s\n", SSL_Strerror(rc, NULL));
+    return CURLE_SSL_CONNECT_ERROR;
+  }
+
+  return CURLE_OK;
+}
+
+
+CURLcode Curl_qsossl_connect(struct connectdata * conn, int sockindex)
+
+{
+  struct SessionHandle * data = conn->data;
+  struct ssl_connect_data * connssl = &conn->ssl[sockindex];
+  int rc;
+
+  rc = Curl_qsossl_init_session(data);
+
+  if (rc == CURLE_OK) {
+    rc = Curl_qsossl_create(conn, sockindex);
+
+    if (rc == CURLE_OK)
+      rc = Curl_qsossl_handshake(conn, sockindex);
+    else {
+      SSL_Destroy(connssl->handle);
+      connssl->handle = NULL;
+      connssl->use = FALSE;
+    }
+  }
+
+  return rc;
+}
+
+
+static int Curl_qsossl_close_one(struct ssl_connect_data * conn,
+                                 struct SessionHandle * data)
+
+{
+  int rc;
+
+  if (!conn->handle)
+    return 0;
+
+  rc = SSL_Destroy(conn->handle);
+
+  if(rc) {
+    if (rc == SSL_ERROR_IO) {
+      failf(data, "SSL_Destroy() I/O error: %s\n", strerror(errno));
+      return -1;
+    }
+
+    /* An SSL error. */
+    failf(data, "SSL_Destroy() returned error %d\n", SSL_Strerror(rc, NULL));
+    return -1;
+  }
+
+  conn->use = FALSE;    /* get back to ordinary socket usage */
+  conn->handle = NULL;
+  return 0;
+}
+
+
+void Curl_qsossl_close(struct connectdata * conn)
+
+{
+  struct SessionHandle * data = conn->data;
+  struct ssl_connect_data * connssl = conn->ssl;
+
+  if(connssl->use)
+    (void) Curl_qsossl_close_one(connssl, data);
+
+  connssl++;
+
+  if(connssl->use)
+    (void) Curl_qsossl_close_one(connssl, data);
+}
+
+
+int Curl_qsossl_close_all(struct SessionHandle * data)
+
+{
+  /* Unimplemented. */
+  (void) data;
+  return 0;
+}
+
+
+int Curl_qsossl_shutdown(struct connectdata * conn, int sockindex)
+
+{
+  struct ssl_connect_data * connssl = &conn->ssl[sockindex];
+  struct SessionHandle *data = conn->data;
+  ssize_t nread;
+  int what;
+  int rc;
+  char buf[120];
+
+  if (!connssl->handle)
+    return 0;
+
+  if (data->set.ftp_ccc != CURLFTPSSL_CCC_ACTIVE)
+    return 0;
+
+  if (Curl_qsossl_close_one(connssl, data))
+    return -1;
+
+  rc = 0;
+
+  what = Curl_socket_ready(conn->sock[sockindex],
+                           CURL_SOCKET_BAD, SSL_SHUTDOWN_TIMEOUT);
+
+  for (;;) {
+    if (what < 0) {
+      /* anything that gets here is fatally bad */
+      failf(data, "select/poll on SSL socket, errno: %d", SOCKERRNO);
+      rc = -1;
+      break;
+    }
+
+    if (!what) {                                /* timeout */
+      failf(data, "SSL shutdown timeout");
+      break;
+    }
+
+    /* Something to read, let's do it and hope that it is the close
+       notify alert from the server. No way to SSL_Read now, so use read(). */
+
+    nread = read(conn->sock[sockindex], buf, sizeof(buf));
+
+    if (nread < 0) {
+      failf(data, "read: %s\n", strerror(errno));
+      rc = -1;
+    }
+
+    if (nread <= 0)
+      break;
+
+    what = Curl_socket_ready(conn->sock[sockindex], CURL_SOCKET_BAD, 0);
+  }
+
+  return rc;
+}
+
+
+ssize_t Curl_qsossl_send(struct connectdata * conn, int sockindex, void * mem,
+                         size_t len)
+
+{
+  /* SSL_Write() is said to return 'int' while write() and send() returns
+     'size_t' */
+  int rc;
+
+  rc = SSL_Write(conn->ssl[sockindex].handle, mem, (int) len);
+
+  if(rc < 0) {
+    switch(rc) {
+
+    case SSL_ERROR_BAD_STATE:
+      /* The operation did not complete; the same SSL I/O function
+         should be called again later. This is basicly an EWOULDBLOCK
+         equivalent. */
+      return 0;
+
+    case SSL_ERROR_IO:
+      switch (errno) {
+      case EWOULDBLOCK:
+      case EINTR:
+        return 0;
+        }
+
+      failf(conn->data, "SSL_Write() I/O error: %s\n", strerror(errno));
+      return -1;
+    }
+
+    /* An SSL error. */
+    failf(conn->data, "SSL_Write() returned error %d\n",
+          SSL_Strerror(rc, NULL));
+    return -1;
+  }
+
+  return (ssize_t) rc; /* number of bytes */
+}
+
+
+ssize_t Curl_qsossl_recv(struct connectdata * conn, int num, char * buf,
+                         size_t buffersize, bool * wouldblock)
+
+{
+  char error_buffer[120]; /* OpenSSL documents that this must be at
+                             least 120 bytes long. */
+  unsigned long sslerror;
+  int nread;
+
+  nread = SSL_Read(conn->ssl[num].handle, buf, (int) buffersize);
+  *wouldblock = FALSE;
+
+  if(nread < 0) {
+    /* failed SSL_read */
+
+    switch (nread) {
+
+    case SSL_ERROR_BAD_STATE:
+      /* there's data pending, re-invoke SSL_Read(). */
+      *wouldblock = TRUE;
+      return -1; /* basically EWOULDBLOCK */
+
+    case SSL_ERROR_IO:
+      switch (errno) {
+      case EWOULDBLOCK:
+	*wouldblock = TRUE;
+        return -1;
+        }
+
+      failf(conn->data, "SSL_Read() I/O error: %s\n", strerror(errno));
+      return -1;
+
+    default:
+      failf(conn->data, "SSL read error: %s\n", SSL_Strerror(nread, NULL));
+      return -1;
+    }
+  }
+  return (ssize_t) nread;
+}
+
+
+size_t Curl_qsossl_version(char * buffer, size_t size)
+
+{
+  strncpy(buffer, "IBM OS/400 SSL", size);
+  return strlen(buffer);
+}
+
+
+int Curl_qsossl_check_cxn(struct connectdata * cxn)
+
+{
+  int err;
+  int errlen;
+
+  /* The only thing that can be tested here is at the socket level. */
+
+  if (!cxn->ssl[FIRSTSOCKET].handle)
+    return 0; /* connection has been closed */
+
+  err = 0;
+  errlen = sizeof err;
+
+  if (getsockopt(cxn->sock[FIRSTSOCKET], SOL_SOCKET, SO_ERROR,
+                 (unsigned char *) &err, &errlen) ||
+      errlen != sizeof err || err)
+    return 0; /* connection has been closed */
+
+  return -1;  /* connection status unknown */
+}
+
+#endif /* USE_QSOSSL */
diff -Naur curl.orig/lib/qssl.h curl/lib/qssl.h
--- curl.orig/lib/qssl.h	1970-01-01 01:00:00.000000000 +0100
+++ curl/lib/qssl.h	2007-07-05 11:15:18.720375000 +0200
@@ -0,0 +1,52 @@
+#ifndef __QSSL_H
+#define __QSSL_H
+/***************************************************************************
+ *                                  _   _ ____  _
+ *  Project                     ___| | | |  _ \| |
+ *                             / __| | | | |_) | |
+ *                            | (__| |_| |  _ <| |___
+ *                             \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id: qssl.h,v 1.28 2007-01-05 23:11:16 bagder Exp $
+ ***************************************************************************/
+
+/*
+ * This header should only be needed to get included by sslgen.c and qssl.c
+ */
+
+#include "urldata.h"
+
+int Curl_qsossl_init(void);
+void Curl_qsossl_cleanup(void);
+CURLcode Curl_qsossl_connect(struct connectdata * conn, int sockindex);
+void Curl_qsossl_close(struct connectdata * conn); /* close a SSL connection */
+int Curl_qsossl_close_all(struct SessionHandle * data);
+int Curl_qsossl_shutdown(struct connectdata * conn, int sockindex);
+
+ssize_t Curl_qsossl_send(struct connectdata * conn,
+                         int sockindex,
+                         void * mem,
+                         size_t len);
+ssize_t Curl_qsossl_recv(struct connectdata * conn, /* connection data */
+                         int num,                   /* socketindex */
+                         char * buf,                /* store read data here */
+                         size_t buffersize,         /* max amount to read */
+                         bool * wouldblock);
+
+size_t Curl_qsossl_version(char * buffer, size_t size);
+int Curl_qsossl_check_cxn(struct connectdata * cxn);
+
+#endif
diff -Naur curl.orig/lib/sendf.c curl/lib/sendf.c
--- curl.orig/lib/sendf.c	2007-07-02 13:49:19.406417000 +0200
+++ curl/lib/sendf.c	2007-07-02 13:47:50.516361000 +0200
@@ -416,7 +416,7 @@
     /* If the previous block of data ended with CR and this block of data is
        just a NL, then the length might be zero */
     if (len) {
-      wrote = data->set.fwrite(ptr, 1, len, data->set.out);
+      wrote = data->set.fwrite_func(ptr, 1, len, data->set.out);
     }
     else {
       wrote = len;
@@ -435,7 +435,7 @@
      * header callback function (added after version 7.7.1).
      */
     curl_write_callback writeit=
-      data->set.fwrite_header?data->set.fwrite_header:data->set.fwrite;
+      data->set.fwrite_header?data->set.fwrite_header:data->set.fwrite_func;
 
     /* Note: The header is in the host encoding
        regardless of the ftp transfer mode (ASCII/Image) */
diff -Naur curl.orig/lib/setup.h curl/lib/setup.h
--- curl.orig/lib/setup.h	2007-07-12 12:18:27.080016000 +0200
+++ curl/lib/setup.h	2007-07-12 12:16:48.632321000 +0200
@@ -67,6 +67,10 @@
 #include "amigaos.h"
 #endif
 
+#ifdef __OS400__
+#include "config-os400.h"
+#endif
+
 #ifdef TPF
 #include "config-tpf.h" /* hand-modified TPF config.h */
 /* change which select is used for libcurl */
@@ -340,8 +344,8 @@
 #define HAVE_INET_NTOA_R_2_ARGS 1
 #endif
 
-#if defined(USE_GNUTLS) || defined(USE_SSLEAY) || defined(USE_NSS)
-#define USE_SSL    /* Either OpenSSL || GnuTLS || NSS */
+#if defined(USE_GNUTLS) || defined(USE_SSLEAY) || defined(USE_NSS) || defined(USE_QSOSSL)
+#define USE_SSL    /* Either OpenSSL || GnuTLS || NSS || QsoSSL */
 #endif
 
 #if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_NTLM)
diff -Naur curl.orig/lib/sslgen.c curl/lib/sslgen.c
--- curl.orig/lib/sslgen.c	2007-04-21 23:24:53.000000000 +0200
+++ curl/lib/sslgen.c	2007-07-05 11:14:57.071748000 +0200
@@ -52,6 +52,7 @@
 #include "ssluse.h" /* OpenSSL versions */
 #include "gtls.h"   /* GnuTLS versions */
 #include "nssg.h"   /* NSS versions */
+#include "qssl.h"   /* QSOSSL versions */
 #include "sendf.h"
 #include "strequal.h"
 #include "url.h"
@@ -172,8 +173,12 @@
 #ifdef USE_NSS
   return Curl_nss_init();
 #else
+#ifdef USE_QSOSSL
+  return Curl_qsossl_init();
+#else
   /* no SSL support */
   return 1;
+#endif /* USE_QSOSSL */
 #endif /* USE_NSS */
 #endif /* USE_GNUTLS */
 #endif /* USE_SSLEAY */
@@ -190,8 +195,13 @@
 #else
 #ifdef USE_GNUTLS
     Curl_gtls_cleanup();
+#else
 #ifdef USE_NSS
     Curl_nss_cleanup();
+#else
+#ifdef USE_QSOSSL
+    Curl_qsossl_cleanup();
+#endif /* USE_QSOSSL */
 #endif /* USE_NSS */
 #endif /* USE_GNUTLS */
 #endif /* USE_SSLEAY */
@@ -214,6 +224,10 @@
 #else
 #ifdef USE_NSS
   return Curl_nss_connect(conn, sockindex);
+#else
+#ifdef USE_QSOSSL
+  return Curl_qsossl_connect(conn, sockindex);
+#endif /* USE_QSOSSL */
 #endif /* USE_NSS */
 #endif /* USE_GNUTLS */
 #endif /* USE_SSLEAY */
@@ -240,10 +254,15 @@
   *done = TRUE; /* fallback to BLOCKING */
   return Curl_nss_connect(conn, sockindex);
 #else
+#ifdef USE_QSOSSL
+  *done = TRUE; /* fallback to BLOCKING */
+  return Curl_qsossl_connect(conn, sockindex);
+#else
   /* not implemented!
      fallback to BLOCKING call. */
   *done = TRUE;
   return Curl_ssl_connect(conn, sockindex);
+#endif /* USE_QSOSSL */
 #endif /* USE_NSS */
 #endif /* USE_SSLEAY */
 }
@@ -302,9 +321,13 @@
 #ifdef USE_GNUTLS
     Curl_gtls_session_free(session->sessionid);
 #else
+#ifdef USE_QSOSSL
+    /* No session handling for QsoSSL. */
+#else
 #ifdef USE_NSS
     /* NSS has its own session ID cache */
 #endif /* USE_NSS */
+#endif /* USE_QSOSSL */
 #endif /* USE_GNUTLS */
 #endif /* USE_SSLEAY */
     session->sessionid=NULL;
@@ -400,6 +423,10 @@
 #else
 #ifdef USE_NSS
   Curl_nss_close_all(data);
+#else
+#ifdef USE_QSOSSL
+  Curl_qsossl_close_all(data);
+#endif /* USE_QSOSSL */
 #endif /* USE_NSS */
 #endif /* USE_GNUTLS */
 #endif /* USE_SSLEAY */
@@ -420,6 +447,9 @@
 #ifdef USE_NSS
     Curl_nss_close(conn);
 #endif /* USE_NSS */
+#ifdef USE_QSOSSL
+    Curl_qsossl_close(conn);
+#endif /* USE_QSOSSL */
     conn->ssl[FIRSTSOCKET].use = FALSE;
   }
 }
@@ -435,8 +465,13 @@
     if(Curl_gtls_shutdown(conn, sockindex))
       return CURLE_SSL_SHUTDOWN_FAILED;
 #else
+#ifdef USE_QSOSSL
+    if(Curl_qsossl_shutdown(conn, sockindex))
+      return CURLE_SSL_SHUTDOWN_FAILED;
+#else
     (void)conn;
     (void)sockindex;
+#endif /* USE_QSOSSL */
 #endif /* USE_GNUTLS */
 #endif /* USE_SSLEAY */
   }
@@ -462,10 +497,17 @@
   (void)engine;
   return CURLE_FAILED_INIT;
 #else
+#ifdef USE_QSOSSL
+  /* QSOSSL doesn't set an engine this way */
+  (void)data;
+  (void)engine;
+  return CURLE_FAILED_INIT;
+#else
   /* no SSL layer */
   (void)data;
   (void)engine;
   return CURLE_FAILED_INIT;
+#endif /* USE_QSOSSL */
 #endif /* USE_NSS */
 #endif /* USE_GNUTLS */
 #endif /* USE_SSLEAY */
@@ -488,9 +530,15 @@
   (void)data;
   return CURLE_FAILED_INIT;
 #else
+#ifdef USE_QSOSSL
+  /* A no-op for QSOSSL */
+  (void)data;
+  return CURLE_FAILED_INIT;
+#else
   /* No SSL layer */
   (void)data;
   return CURLE_FAILED_INIT;
+#endif /* USE_QSOSSL */
 #endif /* USE_NSS */
 #endif /* USE_GNUTLS */
 #endif /* USE_SSLEAY */
@@ -513,8 +561,14 @@
   (void)data;
   return NULL;
 #else
+#ifdef USE_QSOSSL
+  /* No engine support in QSOSSL. */
+  (void)data;
+  return NULL;
+#else
   (void)data;
   return NULL;
+#endif /* USE_QSOSSL */
 #endif /* USE_NSS */
 #endif /* USE_GNUTLS */
 #endif /* USE_SSLEAY */
@@ -535,11 +589,15 @@
 #ifdef USE_NSS
   return Curl_nss_send(conn, sockindex, mem, len);
 #else
+#ifdef USE_QSOSSL
+  return Curl_qsossl_send(conn, sockindex, mem, len);
+#else
   (void)conn;
   (void)sockindex;
   (void)mem;
   (void)len;
   return 0;
+#endif /* USE_QSOSSL */
 #endif /* USE_NSS */
 #endif /* USE_GNUTLS */
 #endif /* USE_SSLEAY */
@@ -568,6 +626,10 @@
 #else
 #ifdef USE_NSS
   nread = Curl_nss_recv(conn, sockindex, mem, len, &block);
+#else
+#ifdef USE_QSOSSL
+  nread = Curl_qsossl_recv(conn, sockindex, mem, len, &block);
+#endif /* USE_QSOSSL */
 #endif /* USE_NSS */
 #endif /* USE_GNUTLS */
 #endif /* USE_SSLEAY */
@@ -632,9 +694,13 @@
 #ifdef USE_NSS
   return Curl_nss_version(buffer, size);
 #else
+#ifdef USE_QSOSSL
+  return Curl_qsossl_version(buffer, size);
+#else
   (void)buffer;
   (void)size;
   return 0; /* no SSL support */
+#endif /* USE_QSOSSL */
 #endif /* USE_NSS */
 #endif /* USE_GNUTLS */
 #endif /* USE_SSLEAY */
@@ -657,9 +723,13 @@
 #ifdef USE_NSS
   return Curl_nss_check_cxn(conn);
 #else
+#ifdef USE_QSOSSL
+  return Curl_qsossl_check_cxn(conn);
+#else
   (void)conn;
   /* TODO: we lack implementation of this for GnuTLS */
   return -1; /* connection status unknown */
+#endif /* USE_QSOSSL */
 #endif /* USE_NSS */
 #endif /* USE_SSLEAY */
 }
diff -Naur curl.orig/lib/strtoofft.c curl/lib/strtoofft.c
--- curl.orig/lib/strtoofft.c	2007-02-16 19:19:36.000000000 +0100
+++ curl/lib/strtoofft.c	2007-07-02 14:27:25.609976000 +0200
@@ -39,6 +39,11 @@
 
 static int get_char(char c, int base);
 
+/* Portable character decoding support (remember EBCDIC!). */
+
+static char valchars[] =
+            "01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
+
 /**
  * Emulated version of the strtoll function.  This extracts a long long
  * value from the given input string and returns it.
@@ -145,20 +150,17 @@
  */
 static int get_char(char c, int base)
 {
-  int value = -1;
-  if (c <= '9' && c >= '0') {
-    value = c - '0';
-  }
-  else if (c <= 'Z' && c >= 'A') {
-    value = c - 'A' + 10;
-  }
-  else if (c <= 'z' && c >= 'a') {
-    value = c - 'a' + 10;
-  }
+  int value;
 
-  if (value >= base) {
+  for (value = 0; valchars[value]; value++)
+    if (valchars[value] == c)
+      break;
+
+  if (value >= 36)
+    value -= 26;                /* Lowercase. */
+
+  if (value >= base)
     value = -1;
-  }
 
   return value;
 }
diff -Naur curl.orig/lib/transfer.c curl/lib/transfer.c
--- curl.orig/lib/transfer.c	2007-07-16 11:46:33.530477000 +0200
+++ curl/lib/transfer.c	2007-07-16 11:46:58.956727000 +0200
@@ -127,7 +127,7 @@
 
   /* this function returns a size_t, so we typecast to int to prevent warnings
      with picky compilers */
-  nread = (int)conn->fread(data->reqdata.upload_fromhere, 1,
+  nread = (int)conn->fread_func(data->reqdata.upload_fromhere, 1,
                            buffersize, conn->fread_in);
 
   if(nread == CURL_READFUNC_ABORT) {
@@ -237,10 +237,10 @@
      (data->set.httpreq == HTTPREQ_POST_FORM))
     ; /* do nothing */
   else {
-    if(data->set.ioctl) {
+    if(data->set.ioctl_func) {
       curlioerr err;
 
-      err = (data->set.ioctl) (data, CURLIOCMD_RESTARTREAD,
+      err = (data->set.ioctl_func) (data, CURLIOCMD_RESTARTREAD,
                             data->set.ioctl_client);
       infof(data, "the ioctl callback returned %d\n", (int)err);
 
@@ -254,7 +254,7 @@
       /* If no CURLOPT_READFUNCTION is used, we know that we operate on a
          given FILE * stream and we can actually attempt to rewind that
          ourself with fseek() */
-      if(data->set.fread == (curl_read_callback)fread) {
+      if(data->set.fread_func == (curl_read_callback)fread) {
         if(-1 != fseek(data->set.in, 0, SEEK_SET))
           /* successful rewind */
           return CURLE_OK;
diff -Naur curl.orig/lib/url.c curl/lib/url.c
--- curl.orig/lib/url.c	2007-07-16 11:46:33.624301000 +0200
+++ curl/lib/url.c	2007-07-17 22:46:22.651569000 +0200
@@ -29,6 +29,7 @@
 #include <string.h>
 #include <stdarg.h>
 #include <stdlib.h>
+#include <stddef.h>
 #include <ctype.h>
 #include <errno.h>
 
@@ -60,7 +61,7 @@
 #ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
 #endif
-#if HAVE_SIGNAL_H
+#ifdef HAVE_SIGNAL_H
 #include <signal.h>
 #endif
 
@@ -175,6 +176,178 @@
 
 #define ZERO_NULL 0
 
+/*
+ * UserDefined strings offsets.
+ * This table is used for assignments and deallocation.
+ * It must be updated whenever CURLOPT_xxx numbering changes.
+ */
+
+#define udoff(f) offsetof(struct UserDefined, f)
+
+static int setstroffsets[] = {
+  -1,                                   /*   0: unused. */
+  -1,                                   /*   1: FILE */
+  udoff(set_url),                       /*   2: URL */
+  -1,                                   /*   3: PORT */
+  udoff(proxy),                         /*   4: PROXY */
+  udoff(userpwd),                       /*   5: USERPWD */
+  udoff(proxyuserpwd),                  /*   6: PROXYUSERPWD */
+  udoff(set_range),                     /*   7: RANGE */
+  -1,                                   /*   8: unused. */
+  -1,                                   /*   9: INFILE */
+  -1,                                   /*  10: ERRORBUFFER */
+  -1,                                   /*  11: WRITEFUNCTION */
+  -1,                                   /*  12: READFUNCTION */
+  -1,                                   /*  13: TIMEOUT */
+  -1,                                   /*  14: INFILESIZE */
+  udoff(postfields),                    /*  15: POSTFIELDS */
+  udoff(set_referer),                   /*  16: REFERER */
+  udoff(ftpport),                       /*  17: FTPPORT */
+  udoff(useragent),                     /*  18: USERAGENT */
+  -1,                                   /*  19: LOW_SPEED_LIMIT */
+  -1,                                   /*  20: LOW_SPEED_TIME */
+  -1,                                   /*  21: RESUME_FROM */
+  udoff(cookie),                        /*  22: COOKIE */
+  -1,                                   /*  23: HTTPHEADER */
+  -1,                                   /*  24: HTTPPOST */
+  udoff(cert),                          /*  25: SSLCERT */
+  udoff(key_passwd),                    /*  26: SSLKEYPASSWD */
+  -1,                                   /*  27: CRLF */
+  -1,                                   /*  28: QUOTE */
+  -1,                                   /*  29: WRITEHEADER */
+  -1,                                   /*  30: unused. */
+  -1,                                   /*  31: COOKIEFILE */
+  -1,                                   /*  32: SSLVERSION */
+  -1,                                   /*  33: TIMECONDITION */
+  -1,                                   /*  34: TIMEVALUE */
+  -1,                                   /*  35: unused. */
+  udoff(customrequest),                 /*  36: CUSTOMREQUEST */
+  -1,                                   /*  37: STDERR */
+  -1,                                   /*  38: unused. */
+  -1,                                   /*  39: POSTQUOTE */
+  -1,                                   /*  40: WRITEINFO */
+  -1,                                   /*  41: VERBOSE */
+  -1,                                   /*  42: HEADER */
+  -1,                                   /*  43: NOPROGRESS */
+  -1,                                   /*  44: NOBODY */
+  -1,                                   /*  45: FAILONERROR */
+  -1,                                   /*  46: UPLOAD */
+  -1,                                   /*  47: POST */
+  -1,                                   /*  48: FTPLISTONLY */
+  -1,                                   /*  49: unused. */
+  -1,                                   /*  50: FTPAPPEND */
+  -1,                                   /*  51: NETRC */
+  -1,                                   /*  52: FOLLOWLOCATION */
+  -1,                                   /*  53: TRANSFERTEXT */
+  -1,                                   /*  54: PUT */
+  -1,                                   /*  55: unused. */
+  -1,                                   /*  56: PROGRESSFUNCTION */
+  -1,                                   /*  57: PROGRESSDATA */
+  -1,                                   /*  58: AUTOREFERER */
+  -1,                                   /*  59: PROXYPORT */
+  -1,                                   /*  60: POSTFIELDSIZE */
+  -1,                                   /*  61: HTTPPROXYTUNNEL */
+  udoff(device),                        /*  62: INTERFACE */
+  udoff(krb_level),                     /*  63: KRBLEVEL */
+  -1,                                   /*  64: SSL_VERIFYPEER */
+  udoff(ssl.CAfile),                    /*  65: CAINFO */
+  -1,                                   /*  66: unused. */
+  -1,                                   /*  67: unused. */
+  -1,                                   /*  68: MAXREDIRS */
+  -1,                                   /*  69: FILETIME */
+  -1,                                   /*  70: TELNETOPTIONS */
+  -1,                                   /*  71: MAXCONNECTS */
+  -1,                                   /*  72: CLOSEPOLICY */
+  -1,                                   /*  73: unused. */
+  -1,                                   /*  74: FRESH_CONNECT */
+  -1,                                   /*  75: FORBID_REUSE */
+  udoff(ssl.random_file),               /*  76: RANDOM_FILE */
+  udoff(ssl.egdsocket),                 /*  77: EGDSOCKET */
+  -1,                                   /*  78: CONNECTTIMEOUT */
+  -1,                                   /*  79: HEADERFUNCTION */
+  -1,                                   /*  80: HTTPGET */
+  -1,                                   /*  81: SSL_VERIFYHOST */
+  -1,                                   /*  82: COOKIEJAR */
+  udoff(ssl.cipher_list),               /*  83: SSL_CIPHER_LIST */
+  -1,                                   /*  84: HTTP_VERSION */
+  -1,                                   /*  85: FTP_USE_EPSV */
+  udoff(cert_type),                     /*  86: SSLCERTTYPE */
+  udoff(key),                           /*  87: SSLKEY */
+  udoff(key_type),                      /*  88: SSLKEYTYPE */
+  -1,                                   /*  89: SSLENGINE */
+  -1,                                   /*  90: SSLENGINE_DEFAULT */
+  -1,                                   /*  91: DNS_USE_GLOBAL_CACHE */
+  -1,                                   /*  92: DNS_CACHE_TIMEOUT */
+  -1,                                   /*  93: PREQUOTE */
+  -1,                                   /*  94: DEBUGFUNCTION */
+  -1,                                   /*  95: DEBUGDATA */
+  -1,                                   /*  96: COOKIESESSION */
+  udoff(ssl.CApath),                    /*  97: CAPATH */
+  -1,                                   /*  98: BUFFERSIZE */
+  -1,                                   /*  99: NOSIGNAL */
+  -1,                                   /* 100: SHARE */
+  -1,                                   /* 101: PROXYTYPE */
+  udoff(encoding),                      /* 102: ENCODING */
+  udoff(private_data),                  /* 103: PRIVATE */
+  -1,                                   /* 104: HTTP200ALIASES */
+  -1,                                   /* 105: UNRESTRICTED_AUTH */
+  -1,                                   /* 106: FTP_USE_EPRT */
+  -1,                                   /* 107: HTTPAUTH */
+  -1,                                   /* 108: SSL_CTX_FUNCTION */
+  -1,                                   /* 109: SSL_CTX_DATA */
+  -1,                                   /* 110: FTP_CREATE_MISSING_DIRS */
+  -1,                                   /* 111: PROXYAUTH */
+  -1,                                   /* 112: FTP_RESPONSE_TIMEOUT */
+  -1,                                   /* 113: IPRESOLVE */
+  -1,                                   /* 114: MAXFILESIZE */
+  -1,                                   /* 115: INFILESIZE_LARGE */
+  -1,                                   /* 116: RESUME_FROM_LARGE */
+  -1,                                   /* 117: MAXFILESIZE_LARGE */
+  udoff(netrc_file),                    /* 118: NETRC_FILE */
+  -1,                                   /* 119: FTP_SSL */
+  -1,                                   /* 120: POSTFIELDSIZE_LARGE */
+  -1,                                   /* 121: TCP_NODELAY */
+  -1,                                   /* 122: unused. */
+  -1,                                   /* 123: unused. */
+  -1,                                   /* 124: unused. */
+  -1,                                   /* 125: unused. */
+  -1,                                   /* 126: unused. */
+  -1,                                   /* 127: unused. */
+  -1,                                   /* 128: unused. */
+  -1,                                   /* 129: FTPSSLAUTH */
+  -1,                                   /* 130: IOCTLFUNCTION */
+  -1,                                   /* 131: IOCTLDATA */
+  -1,                                   /* 132: unused. */
+  -1,                                   /* 133: unused. */
+  udoff(ftp_account),                   /* 134: FTP_ACCOUNT */
+  -1,                                   /* 135: COOKIELIST */
+  -1,                                   /* 136: IGNORE_CONTENT_LENGTH */
+  -1,                                   /* 137: FTP_SKIP_PASV_IP */
+  -1,                                   /* 138: FTP_FILEMETHOD */
+  -1,                                   /* 139: LOCALPORT */
+  -1,                                   /* 140: LOCALPORTRANGE */
+  -1,                                   /* 141: CONNECT_ONLY */
+  -1,                                   /* 142: CONV_FROM_NETWORK_FUNCTION */
+  -1,                                   /* 143: CONV_TO_NETWORK_FUNCTION */
+  -1,                                   /* 144: CONV_FROM_UTF8_FUNCTION */
+  -1,                                   /* 145: MAX_SEND_SPEED_LARGE */
+  -1,                                   /* 146: MAX_RECV_SPEED_LARGE */
+  udoff(ftp_alternative_to_user),       /* 147: FTP_ALTERNATIVE_TO_USER */
+  -1,                                   /* 148: SOCKOPTFUNCTION */
+  -1,                                   /* 149: SOCKOPTDATA */
+  -1,                                   /* 150: SSL_SESSIONID_CACHE */
+  -1,                                   /* 151: SSH_AUTH_TYPES */
+  udoff(ssh_public_key),                /* 152: SSH_PUBLIC_KEYFILE */
+  udoff(ssh_private_key),               /* 153: SSH_PRIVATE_KEYFILE */
+  -1,                                   /* 154: FTP_SSL_CCC */
+  -1,                                   /* 155: TIMEOUT_MS */
+  -1,                                   /* 156: CONNECTTIMEOUT_MS */
+  -1,                                   /* 157: HTTP_TRANSFER_DECODING */
+  -1,                                   /* 158: HTTP_CONTENT_DECODING */
+  -1,                                   /* 159: NEW_FILE_PERMS */
+  -1,                                   /* 160: NEW_DIRECTORY_PERMS */
+};
+
 #ifndef USE_ARES
 /* not for ares builds */
 
@@ -381,6 +554,9 @@
     Curl_share_unlock(data, CURL_LOCK_DATA_SHARE);
   }
 
+  /* Free all allocated UserDefined fields. */
+  Curl_freeset(data);
+
   free(data);
   return CURLE_OK;
 }
@@ -546,10 +722,10 @@
     data->set.err  = stderr;  /* default stderr to stderr */
 
     /* use fwrite as default function to store output */
-    data->set.fwrite = (curl_write_callback)fwrite;
+    data->set.fwrite_func = (curl_write_callback)fwrite;
 
     /* use fread as default function to read input */
-    data->set.fread = (curl_read_callback)fread;
+    data->set.fread_func = (curl_read_callback)fread;
 
     /* conversion callbacks for non-ASCII hosts */
     data->set.convfromnetwork = (curl_conv_callback)ZERO_NULL;
@@ -626,6 +802,56 @@
   return res;
 }
 
+CURLcode Curl_setstropt(struct SessionHandle * data,
+                        CURLoption option, char * s)
+
+{
+  int optno = CURLOPTION_NUMBER(option);
+  char * * cpp;
+
+  /* Set string pointer option, taking care of releasing previous storage if
+     needed. The new pointer is assumed static. */
+
+  if (optno >= sizeof setstroffsets / sizeof setstroffsets[0] ||
+      setstroffsets[optno] < 0)
+    return CURLE_FAILED_INIT;
+
+  cpp = (char * *) ((char *) &data->set + setstroffsets[optno]);
+
+  if (data->set.is_allocated[optno]) {
+    Curl_safefree(*cpp);
+    data->set.is_allocated[optno] = FALSE;
+    }
+
+  *cpp = s;
+  return CURLE_OK;
+}
+
+CURLcode Curl_setdynopt(struct SessionHandle * data,
+                        CURLoption option, char * s)
+
+{
+  int optno = CURLOPTION_NUMBER(option);
+  char * * cpp;
+
+  /* Set option string pointer status to "dynamically allocated" if its value
+     matches the argument. */
+
+  if (optno >= sizeof setstroffsets / sizeof setstroffsets[0] ||
+      setstroffsets[optno] < 0)
+    return CURLE_FAILED_INIT;
+
+  cpp = (char * *) ((char *) &data->set + setstroffsets[optno]);
+
+  if (s != *cpp)
+    return CURLE_FAILED_INIT;
+
+  if (s)
+    data->set.is_allocated[optno] = TRUE;
+
+  return CURLE_OK;
+}
+
 CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
                      va_list param)
 {
@@ -648,7 +874,7 @@
     break;
   case CURLOPT_SSL_CIPHER_LIST:
     /* set a list of cipher we want to use in the SSL connection */
-    data->set.ssl.cipher_list = va_arg(param, char *);
+    result = Curl_setstropt(data, option, va_arg(param, char *));
     break;
 
   case CURLOPT_RANDOM_FILE:
@@ -656,13 +882,13 @@
      * This is the path name to a file that contains random data to seed
      * the random SSL stuff with. The file is only used for reading.
      */
-    data->set.ssl.random_file = va_arg(param, char *);
+    result = Curl_setstropt(data, option, va_arg(param, char *));
     break;
   case CURLOPT_EGDSOCKET:
     /*
      * The Entropy Gathering Daemon socket pathname
      */
-    data->set.ssl.egdsocket = va_arg(param, char *);
+    result = Curl_setstropt(data, option, va_arg(param, char *));
     break;
   case CURLOPT_MAXCONNECTS:
     /*
@@ -785,7 +1011,7 @@
     /*
      * Use this file instead of the $HOME/.netrc file
      */
-    data->set.netrc_file = va_arg(param, char *);
+    result = Curl_setstropt(data, option, va_arg(param, char *));
     break;
   case CURLOPT_TRANSFERTEXT:
     /*
@@ -836,9 +1062,9 @@
      * and ignore an received Content-Encoding header.
      *
      */
-    data->set.encoding = va_arg(param, char *);
+    result = Curl_setstropt(data, option, va_arg(param, char *));
     if(data->set.encoding && !*data->set.encoding)
-      data->set.encoding = (char*)ALL_CONTENT_ENCODINGS;
+      result = Curl_setstropt(data, option, (char *) ALL_CONTENT_ENCODINGS);
     break;
 
   case CURLOPT_FOLLOWLOCATION:
@@ -881,7 +1107,7 @@
     /*
      * A string with POST data. Makes curl HTTP POST. Even if it is NULL.
      */
-    data->set.postfields = va_arg(param, char *);
+    result = Curl_setstropt(data, option, va_arg(param, char *));
     data->set.httpreq = HTTPREQ_POST;
     break;
 
@@ -918,7 +1144,7 @@
       free(data->change.referer);
       data->change.referer_alloc = FALSE;
     }
-    data->set.set_referer = va_arg(param, char *);
+    result = Curl_setstropt(data, option, va_arg(param, char *));
     data->change.referer = data->set.set_referer;
     break;
 
@@ -926,7 +1152,7 @@
     /*
      * String to use in the HTTP User-Agent field
      */
-    data->set.useragent = va_arg(param, char *);
+    result = Curl_setstropt(data, option, va_arg(param, char *));
     break;
 
   case CURLOPT_HTTPHEADER:
@@ -948,7 +1174,7 @@
     /*
      * Cookie string to send to the remote server in the request.
      */
-    data->set.cookie = va_arg(param, char *);
+    result = Curl_setstropt(data, option, va_arg(param, char *));
     break;
 
   case CURLOPT_COOKIEFILE:
@@ -1071,7 +1297,7 @@
     /*
      * Set a custom string to use as request
      */
-    data->set.customrequest = va_arg(param, char *);
+    result = Curl_setstropt(data, option, va_arg(param, char *));
 
     /* we don't set
        data->set.httpreq = HTTPREQ_CUSTOM;
@@ -1137,7 +1363,7 @@
      * Setting it to NULL, means no proxy but allows the environment variables
      * to decide for us.
      */
-    data->set.proxy = va_arg(param, char *);
+    result = Curl_setstropt(data, option, va_arg(param, char *));
     break;
 
   case CURLOPT_WRITEHEADER:
@@ -1163,7 +1389,7 @@
     /*
      * Use FTP PORT, this also specifies which IP address to use
      */
-    data->set.ftpport = va_arg(param, char *);
+    result = Curl_setstropt(data, option, va_arg(param, char *));
     data->set.ftp_use_port = (bool)(NULL != data->set.ftpport);
     break;
 
@@ -1247,7 +1473,7 @@
       free(data->change.url);
       data->change.url_alloc=FALSE;
     }
-    data->set.set_url = va_arg(param, char *);
+    result = Curl_setstropt(data, option, va_arg(param, char *));
     data->change.url = data->set.set_url;
     data->change.url_changed = TRUE;
     break;
@@ -1284,7 +1510,7 @@
     /*
      * user:password to use in the operation
      */
-    data->set.userpwd = va_arg(param, char *);
+    result = Curl_setstropt(data, option, va_arg(param, char *));
     break;
   case CURLOPT_POSTQUOTE:
     /*
@@ -1325,13 +1551,13 @@
     /*
      * user:password needed to use the proxy
      */
-    data->set.proxyuserpwd = va_arg(param, char *);
+    result = Curl_setstropt(data, option, va_arg(param, char *));
     break;
   case CURLOPT_RANGE:
     /*
      * What range of the file you want to transfer
      */
-    data->set.set_range = va_arg(param, char *);
+    result = Curl_setstropt(data, option, va_arg(param, char *));
     break;
   case CURLOPT_RESUME_FROM:
     /*
@@ -1380,19 +1606,19 @@
     /*
      * Set data write callback
      */
-    data->set.fwrite = va_arg(param, curl_write_callback);
-    if(!data->set.fwrite)
+    data->set.fwrite_func = va_arg(param, curl_write_callback);
+    if(!data->set.fwrite_func)
       /* When set to NULL, reset to our internal default function */
-      data->set.fwrite = (curl_write_callback)fwrite;
+      data->set.fwrite_func = (curl_write_callback)fwrite;
     break;
   case CURLOPT_READFUNCTION:
     /*
      * Read data callback
      */
-    data->set.fread = va_arg(param, curl_read_callback);
-    if(!data->set.fread)
+    data->set.fread_func = va_arg(param, curl_read_callback);
+    if(!data->set.fread_func)
       /* When set to NULL, reset to our internal default function */
-      data->set.fread = (curl_read_callback)fread;
+      data->set.fread_func = (curl_read_callback)fread;
     break;
   case CURLOPT_CONV_FROM_NETWORK_FUNCTION:
     /*
@@ -1416,7 +1642,7 @@
     /*
      * I/O control callback. Might be NULL.
      */
-    data->set.ioctl = va_arg(param, curl_ioctl_callback);
+    data->set.ioctl_func = va_arg(param, curl_ioctl_callback);
     break;
   case CURLOPT_IOCTLDATA:
     /*
@@ -1428,31 +1654,31 @@
     /*
      * String that holds file name of the SSL certificate to use
      */
-    data->set.cert = va_arg(param, char *);
+    result = Curl_setstropt(data, option, va_arg(param, char *));
     break;
   case CURLOPT_SSLCERTTYPE:
     /*
      * String that holds file type of the SSL certificate to use
      */
-    data->set.cert_type = va_arg(param, char *);
+    result = Curl_setstropt(data, option, va_arg(param, char *));
     break;
   case CURLOPT_SSLKEY:
     /*
      * String that holds file name of the SSL certificate to use
      */
-    data->set.key = va_arg(param, char *);
+    result = Curl_setstropt(data, option, va_arg(param, char *));
     break;
   case CURLOPT_SSLKEYTYPE:
     /*
      * String that holds file type of the SSL certificate to use
      */
-    data->set.key_type = va_arg(param, char *);
+    result = Curl_setstropt(data, option, va_arg(param, char *));
     break;
   case CURLOPT_SSLKEYPASSWD:
     /*
      * String that holds the SSL private key password.
      */
-    data->set.key_passwd = va_arg(param, char *);
+    result = Curl_setstropt(data, option, va_arg(param, char *));
     break;
   case CURLOPT_SSLENGINE:
     /*
@@ -1481,7 +1707,7 @@
      * Set what interface or address/hostname to bind the socket to when
      * performing an operation and thus what from-IP your connection will use.
      */
-    data->set.device = va_arg(param, char *);
+    result = Curl_setstropt(data, option, va_arg(param, char *));
     break;
   case CURLOPT_LOCALPORT:
     /*
@@ -1499,7 +1725,7 @@
     /*
      * A string that defines the kerberos security level.
      */
-    data->set.krb_level = va_arg(param, char *);
+    result = Curl_setstropt(data, option, va_arg(param, char *));
     data->set.krb = (bool)(NULL != data->set.krb_level);
     break;
   case CURLOPT_SSL_VERIFYPEER:
@@ -1530,7 +1756,7 @@
     /*
      * Set CA info for SSL connection. Specify file name of the CA certificate
      */
-    data->set.ssl.CAfile = va_arg(param, char *);
+    result = Curl_setstropt(data, option, va_arg(param, char *));
     break;
   case CURLOPT_CAPATH:
     /*
@@ -1538,7 +1764,7 @@
      * certificates which have been prepared using openssl c_rehash utility.
      */
     /* This does not work on windows. */
-    data->set.ssl.CApath = va_arg(param, char *);
+    result = Curl_setstropt(data, option, va_arg(param, char *));
     break;
   case CURLOPT_TELNETOPTIONS:
     /*
@@ -1639,7 +1865,7 @@
     /*
      * Set private data pointer.
      */
-    data->set.private_data = va_arg(param, char *);
+    result = Curl_setstropt(data, option, va_arg(param, char *));
     break;
 
   case CURLOPT_MAXFILESIZE:
@@ -1691,7 +1917,7 @@
       These former 3rd party transfer options are deprecated */
 
   case CURLOPT_FTP_ACCOUNT:
-    data->set.ftp_account = va_arg(param, char *);
+    result = Curl_setstropt(data, option, va_arg(param, char *));
     break;
 
   case CURLOPT_IGNORE_CONTENT_LENGTH:
@@ -1706,7 +1932,7 @@
     break;
 
   case CURLOPT_FTP_ALTERNATIVE_TO_USER:
-    data->set.ftp_alternative_to_user = va_arg(param, char *);
+    result = Curl_setstropt(data, option, va_arg(param, char *));
     break;
 
   case CURLOPT_SOCKOPTFUNCTION:
@@ -1735,14 +1961,14 @@
     /*
      * Use this file instead of the $HOME/.ssh/id_dsa.pub file
      */
-    data->set.ssh_public_key = va_arg(param, char *);
+    result = Curl_setstropt(data, option, va_arg(param, char *));
     break;
 
   case CURLOPT_SSH_PRIVATE_KEYFILE:
     /*
      * Use this file instead of the $HOME/.ssh/id_dsa file
      */
-    data->set.ssh_private_key = va_arg(param, char *);
+    result = Curl_setstropt(data, option, va_arg(param, char *));
     break;
 
   case CURLOPT_HTTP_TRANSFER_DECODING:
@@ -1782,6 +2008,44 @@
   return result;
 }
 
+CURLcode Curl_dupset(struct SessionHandle * dst, struct SessionHandle * src)
+
+{
+  int i;
+  char * * cpp;
+
+  /* Duplicate data from substructure "set" of src into dst, taking care of
+     dynamically allocated strings. */
+
+  dst->set = src->set;
+  memset((char *) dst->set.is_allocated, 0, sizeof dst->set.is_allocated);
+
+  for (i = 0; i < sizeof setstroffsets / sizeof setstroffsets[0]; i++)
+    if (setstroffsets[i] >= 0 && src->set.is_allocated[i]) {
+      cpp = (char * *) ((char *) &dst->set + setstroffsets[i]);
+
+      if (*cpp) {
+        *cpp = strdup(*cpp);
+
+        if (!*cpp)
+          return CURLE_OUT_OF_MEMORY;
+        }
+      }
+
+  return CURLE_OK;
+}
+
+void Curl_freeset(struct SessionHandle * data)
+
+{
+  int i;
+
+  /* Free all dynamically allocated strings in the "set" substructure. */
+
+  for (i = 0; i < sizeof setstroffsets / sizeof setstroffsets[0]; i++)
+    Curl_setdynopt(data, (CURLoption) i, (char *) NULL);
+}
+
 static void conn_free(struct connectdata *conn)
 {
   if (!conn)
@@ -3865,7 +4129,7 @@
    *
    * Inherit the proper values from the urldata struct AFTER we have arranged
    * the persistent connection stuff */
-  conn->fread = data->set.fread;
+  conn->fread_func = data->set.fread_func;
   conn->fread_in = data->set.in;
 
   if ((conn->protocol&PROT_HTTP) &&
diff -Naur curl.orig/lib/url.h curl/lib/url.h
--- curl.orig/lib/url.h	2007-05-02 21:13:56.000000000 +0200
+++ curl/lib/url.h	2007-07-13 17:57:05.220947000 +0200
@@ -32,6 +32,10 @@
 CURLcode Curl_open(struct SessionHandle **curl);
 CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
                      va_list arg);
+CURLcode Curl_setdynopt(struct SessionHandle * data,
+                        CURLoption option, char * s);
+CURLcode Curl_dupset(struct SessionHandle * dst, struct SessionHandle * src);
+void Curl_freeset(struct SessionHandle * data);
 CURLcode Curl_close(struct SessionHandle *data); /* opposite of curl_open() */
 CURLcode Curl_connect(struct SessionHandle *, struct connectdata **,
                       bool *async, bool *protocol_connect);
diff -Naur curl.orig/lib/urldata.h curl/lib/urldata.h
--- curl.orig/lib/urldata.h	2007-07-11 18:44:07.835870000 +0200
+++ curl/lib/urldata.h	2007-07-13 18:48:53.510754000 +0200
@@ -82,6 +82,10 @@
 #include <nspr.h>
 #endif
 
+#ifdef USE_QSOSSL
+#include <qsossl.h>
+#endif
+
 #ifdef HAVE_NETINET_IN_H
 #include <netinet/in.h>
 #endif
@@ -177,6 +181,9 @@
 #ifdef USE_NSS
   PRFileDesc *handle;
 #endif /* USE_NSS */
+#ifdef USE_QSOSSL
+  SSLHandle *handle;
+#endif /* USE_QSOSSL */
 };
 
 struct ssl_config_data {
@@ -288,7 +295,7 @@
   struct Curl_chunker chunk;
 
   struct back {
-    curl_read_callback fread; /* backup storage for fread pointer */
+    curl_read_callback fread_func; /* backup storage for fread pointer */
     void *fread_in;           /* backup storage for fread_in pointer */
     char *postdata;
     curl_off_t postsize;
@@ -965,7 +972,7 @@
   /*************** Request - specific items ************/
 
   /* previously this was in the urldata struct */
-  curl_read_callback fread; /* function that reads the input */
+  curl_read_callback fread_func; /* function that reads the input */
   void *fread_in;           /* pointer to pass to the fread() above */
 
   struct ntlmdata ntlm;     /* NTLM differs from other authentication schemes
@@ -1268,12 +1275,12 @@
   unsigned short localport; /* local port number to bind to */
   int localportrange; /* number of additional port numbers to test in case the
                          'localport' one can't be bind()ed */
-  curl_write_callback fwrite;        /* function that stores the output */
+  curl_write_callback fwrite_func;   /* function that stores the output */
   curl_write_callback fwrite_header; /* function that stores headers */
-  curl_read_callback fread;          /* function that reads the input */
+  curl_read_callback fread_func;     /* function that reads the input */
   curl_progress_callback fprogress;  /* function for progress information */
   curl_debug_callback fdebug;      /* function that write informational data */
-  curl_ioctl_callback ioctl;       /* function for I/O control */
+  curl_ioctl_callback ioctl_func;  /* function for I/O control */
   curl_sockopt_callback fsockopt;  /* function for setting socket options */
   void *sockopt_client; /* pointer to pass to the socket options callback */
 
@@ -1409,6 +1416,8 @@
                             content-encoded (chunked, compressed) */
   long new_file_perms;    /* Permissions to use when creating remote files */
   long new_directory_perms; /* Permissions to use when creating remote dirs */
+  /* Flags telling if a field must be freed. */
+  bool is_allocated[CURLOPTION_NUMBER(CURLOPT_LASTENTRY)];
 };
 
 struct Names {
diff -Naur curl.orig/packages/OS400/README.OS400 curl/packages/OS400/README.OS400
--- curl.orig/packages/OS400/README.OS400	1970-01-01 01:00:00.000000000 +0100
+++ curl/packages/OS400/README.OS400	2007-07-17 22:02:03.203419000 +0200
@@ -0,0 +1,222 @@
+Implementation notes:
+
+  The biggest problem with OS/400 is EBCDIC. Libcurl implements an internal
+conversion mechanism, but it has been designed for computers that have a
+single native character set. OS/400 default native character set varies
+depending on the country for which it has been localized. And more, a job
+may dynamically alter its "native" character set.
+  Several characters that do not have fixed code in EBCDIC variants are
+used in libcurl strings. As a consequence, using the existing conversion
+mechanism would have lead in a localized binary library - not portable across
+countries.
+  For this reason, and because libcurl was originally designed for ASCII based
+operating systems, the current OS/400 implementation uses ASCII as internal
+character set. This has been accomplished using the QADRT library and
+include files, a C and system procedures ASCII wrapper library. See IBM QADRT
+description for more information.
+  This then results in libcurl being an ASCII library: any function string
+argument is taken/returned in ASCII and a C/C++ calling program built around
+QADRT may use libcurl functions as on any other platform.
+  QADRT does not define ASCII wrappers for all C/system procedures: the
+OS/400 configuration header file and an additional module (os400sys.c) define
+some more of them, that are used by libcurl and that QADRT left out.
+  To support all the different variants of EBCDIC, non-standard wrapper
+procedures have been added to libcurl on OS/400: they provide an additional
+CCSID (numeric Coded Character Set ID specific to OS/400) parameter for each
+string argument. String values passed to callback procedures are NOT converted,
+so text gathered this way is (probably !) ASCII.
+
+  Another OS/400 problem comes from the fact that the last argument of a vararg
+procedure may not be of type char, unsigned char, short or unsigned short.
+Enums that are internally implemented by the C compiler as one of these types
+are also forbidden. Libcurl uses enums as vararg procedure tagfields... Happily,
+there is a pragma forcing enums to type "int". The original libcurl header
+files are thus altered to use this pragma, in order to force libcurl enums
+of being type int (the pragma disposition in use before inclusion is restored
+before resuming the including unit compilation).
+
+  Three SSL implementations were present in libcurl. Nevertheless, none of them
+is available on OS/400. To support SSL on OS/400, a fourth implementation has
+been added (qssl.[ch]). There is no way to have different certificate stores
+for CAs and for personal/application certificates/key. More, the SSL context
+may be defined as an application identifier in the main certificate store,
+or as a keyring file. As a consequence, the meaning of some fields have been
+slightly altered:
+_ The "certificate identifier" is taken from CURLOPT_SSLCERT if defined, else
+from CURLOPT_CAINFO.
+_ The certificate identifier is then used as an application identifier in the
+main certificate store. If successful, this context is used.
+_ If the previous step failed, the certificate identifier is used as the file
+name of a keyring. CURLOPT_SSLKEYPASSWD is used here as the keyring password.
+_ The default ca-bundle (CURLOPT_CAINFO) is set to the main certificate store's
+keyring file name: this allow to use the system global CAs by default. (In that
+case, the keyring password is safely recovered from the system... IBM dixit!)
+
+  Since curl_easy_setopt() only stores string addresses (not the string
+themselves), writting an EBCDIC wrapper for this procedure was impossible
+without adding a "dynamic allocation" feature to the stored pointers. This
+has been implemented as an additional array (is_allocated) in the UsedDefined
+structure, behaving has a flag map indexed by the CURLOPT_xxx option number
+part. Whenever the corresponding pointer is overwritten or the structure is
+deleted, the current value is freed if the flag is set.
+  Using curl_easy_setopt() NEVER sets the flag, so the function behaviour is
+preserved. However, the curl_easy_set_ccsid() EBCDIC wrapper does set these
+flags when a converted string (in dynamic storage) is used for an option.
+
+  Non-standard EBCDIC wrapper prototypes are defined in an additional header
+file: ccsidcurl.h. These should be self-explanatory to an OS/400-aware
+designer. CCSID 0 can be used to select he current job's CCSID.
+  Wrapper procedures with variable arguments are described below:
+_ curl_easy_setopt_ccsid()
+  Variable arguments are a string pointer and a CCSID (unsigned int) for
+options:
+        CURLOPT_SSH_PRIVATE_KEYFILE
+        CURLOPT_SSH_PUBLIC_KEYFILE
+        CURLOPT_FTP_ALTERNATIVE_TO_USER
+        CURLOPT_FTP_ACCOUNT
+        CURLOPT_CAPATH
+        CURLOPT_CAINFO
+        CURLOPT_KRBLEVEL
+        CURLOPT_INTERFACE
+        CURLOPT_SSLKEYPASSWD
+        CURLOPT_SSLKEYTYPE
+        CURLOPT_SSLKEY
+        CURLOPT_SSLCERTTYPE
+        CURLOPT_SSLCERT
+        CURLOPT_RANGE
+        CURLOPT_PROXYUSERPWD
+        CURLOPT_USERPWD
+        CURLOPT_URL
+        CURLOPT_FTPPORT
+        CURLOPT_PROXY
+        CURLOPT_CUSTOMREQUEST
+        CURLOPT_COOKIE
+        CURLOPT_USERAGENT
+        CURLOPT_REFERER
+        CURLOPT_POSTFIELDS
+        CURLOPT_ENCODING
+        CURLOPT_NETRC_FILE
+        CURLOPT_EGDSOCKET
+        CURLOPT_RANDOM_FILE
+        CURLOPT_SSL_CIPHER_LIST
+        CURLOPT_PRIVATE
+        CURLOPT_SSLENGINE
+        CURLOPT_COOKIELIST
+  Else it is the same as for curl_easy_setopt().
+  Note that CURLOPT_ERRORBUFFER is not in the list above, since it gives the
+address of an (empty) character buffer, not the address of a string.
+
+_ curl_formadd_ccsid()
+  In the variable argument list, string pointer should be followed by a (long)
+CCSID for the following options:
+        CURLFORM_FILENAME
+        CURLFORM_CONTENTTYPE
+        CURLFORM_BUFFER
+        CURLFORM_FILE
+        CURLFORM_FILECONTENT
+        CURLFORM_COPYCONTENTS
+        CURLFORM_COPYNAME
+        CURLFORM_PTRNAME
+  If taken from an argument array, an additional array entry must follow each
+entry containing one of the above option. This additional entry holds the CCSID
+in its value field, and the option field is meaningless.
+  It is not possible to have a string pointer and its CCSID across a function
+parameter/array boundary.
+  Please note that CURLFORM_PTRCONTENTS and CURLFORM_BUFFERPTR are considered
+unconvertible strings and thus are NOT followed by a CCSID.
+
+  Standard compilation environment does support neither autotools nor make;
+in fact, very few common utilities are available. As a consequence, the
+config-os400.h has been coded manually and the compilation scripts are
+a set of shell scripts stored in subdirectory packages/OS400.
+
+  The "curl" command and the test environment are currently not supported on
+OS/400.
+
+
+
+Compiling on OS/400:
+
+  These instructions targets people who knows about OS/400, compiling, IFS and
+archive extraction. Do not ask questions about these subjects if you're not
+familiar with.
+
+_ As a prerequisite, QADRT development environment must be installed.
+_ Install the curl source directory in IFS.
+_ Enter shell (QSH)
+_ Change current directory to the curl installation directory
+_ Change current directory to ./packages/OS400
+_ Edit file iniscript.sh if you want to change tunable configuration parameters.
+_ Copy any file to makelog (i.e.: cp initscript.sh makelog): this will create
+  the makelog file with an ASCII CCSID!
+_ Enter the command "sh makefile.sh > makelog 2>&1'
+_ Examine the makelog file to check for compilation errors.
+
+  Leaving file initscript.sh unchanged, this will produce the following OS/400
+objects:
+_ Library CURL. All other objects will be stored in this library.
+_ Modules for all libcurl units.
+_ Binding directory CURL_A, to be used at calling program link time for
+  statically binding the modules (specify BNDSRVPGM(QADRTTS) when creating a
+  program using CURL_A).
+_ Service program CURL, to be used at calling program run-time when this program
+  has dynamically bound curl at link time.
+_ Binding directory CURL. To be used to dynamically bind libcurl when linking a
+  calling program.
+_ Source file H. It contains all the include members needed to compile a C/C++
+  module using libcurl, and an ILE/RPG /copy member for support in this
+  language.
+_ Standard C/C++ libcurl include members in file H.
+_ CCSIDCURL member in file H. This defines the non-standard EBCDIC wrappers for
+  C and C++.
+_ CURL.INC member in file H. This defines everything needed by an ILE/RPG
+  program using libcurl.
+_ LIBxxx modules and programs. Although the test environment is not supported
+  on OS/400, the libcurl test programs are compiled for manual tests.
+
+
+
+Special programming consideration:
+
+QADRT being used, the following points must be considered:
+_ If static binding is used, service program QADRTTS must be linked too.
+_ The EBCDIC CCSID used by QADRT is 37 by default, NOT THE JOB'S CCSID. If
+  another EBCDIC CCSID is required, it must be set via a locale through a call
+  to setlocale_a (QADRT's setlocale() ASCII wrapper) with category LC_ALL or
+  LC_CTYPE, or by setting environment variable QADRT_ENV_LOCALE to the locale
+  object path.
+_ Do not use original source include files unless you know what you are doing.
+  Use the installed members instead (in /QSYS.LIB/CURL.LIB/H.FILE).
+
+
+
+ILE/RPG support:
+
+  Since 95% of the OS/400 programmers use ILE/RPG exclusively, a definition
+  /COPY member is provided for this language. To include all libcurl
+  definitions in an ILE/RPG module, line
+
+     h bnddir('CURL/CURL')
+
+must figure in the program header, and line
+
+     d/copy curl/h,curl.inc
+
+in the global data section of the module's source code.
+
+  No vararg procedure support exists in ILE/RPG: for this reason, the following
+considerations apply:
+_ Procedures curl_easy_setopt_long(), curl_easy_setopt_object(),
+  curl_easy_setopt_function() and curl_easy_setopt_offset() are all alias
+  prototypes to curl_easy_setopt(), but with different parameter lists.
+_ Procedures curl_easy_getinfo_string(), curl_easy_getinfo_long(),
+  curl_easy_getinfo_double() and curl_easy_getinfo_slist() are all alias
+  prototypes to curl_easy_getinfo(), but with different parameter lists.
+_ Procedures curl_multi_setopt_long(), curl_multi_setopt_object(),
+  curl_multi_setopt_function() and curl_multi_setopt_offset() are all alias
+  prototypes to curl_multi_setopt(), but with different parameter lists.
+_ The prototype of procedure curl_formadd() allows specifying a pointer option
+  and the CURLFORM_END option. This makes possible to use an option array
+  without any additional definition. If some specific incompatible argument
+  list is used in the ILE/RPG program, the latter must define a compatible
+  alias. The same applies to curl_formadd_ccsid() too.
diff -Naur curl.orig/packages/OS400/ccsidcurl.c curl/packages/OS400/ccsidcurl.c
--- curl.orig/packages/OS400/ccsidcurl.c	1970-01-01 01:00:00.000000000 +0100
+++ curl/packages/OS400/ccsidcurl.c	2007-07-17 22:48:36.508374000 +0200
@@ -0,0 +1,999 @@
+/***************************************************************************
+ *                                  _   _ ____  _
+ *  Project                     ___| | | |  _ \| |
+ *                             / __| | | | |_) | |
+ *                            | (__| |_| |  _ <| |___
+ *                             \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ***************************************************************************/
+
+/* CCSID API wrappers for OS/400. */
+
+#include <iconv.h>
+#include <string.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <stdarg.h>
+
+#pragma enum(int)
+
+#include <curl/curl.h>
+#include "urldata.h"
+#include "getinfo.h"
+
+
+#define ASCII_CCSID     819
+
+
+#ifndef __OS400__
+#define ICONV_OPEN_ERROR(t)     ((t) == (iconv_t) -1)
+#else
+#define ICONV_OPEN_ERROR(t)     ((t).return_value == -1)
+#endif
+
+
+static void
+makeOS400IconvCode(char * buf, unsigned int ccsid)
+
+{
+  int i;
+  unsigned int d;
+
+  /**
+  *** Convert a CCSID to the corresponding IBM iconv_open() character
+  ***  code identifier.
+  ***  This code is specific to the OS400 implementation of the iconv library.
+  ***  CCSID 65535 (no conversion) is replaced by the ASCII CCSID.
+  ***  CCSID 0 is interpreted by the OS400 as the job's CCSID.
+  **/
+
+  ccsid &= 0xFFFF;
+
+  if (ccsid == 65535)
+    ccsid = ASCII_CCSID;
+
+  strncpy(buf,"IBMCCSID000000000000", 32);
+
+  for (i = 12; i > 7; i--) {
+    d = ccsid / 10;
+    buf[i] = '0' + (ccsid - 10 * d);
+    ccsid = d;
+    }
+}
+
+
+static iconv_t
+iconv_open_CCSID(unsigned int ccsidout, unsigned int ccsidin, unsigned int cstr)
+
+{
+  char fromcode[33];
+  char tocode[33];
+
+  /**
+  ***  Like iconv_open(), but character codes are given as CCSIDs.
+  ***  If `cstr' is non-zero, conversion is set up to stop whenever a
+  ***   null character is encountered.
+  **/
+
+  makeOS400IconvCode(fromcode, ccsidin);
+  makeOS400IconvCode(tocode, ccsidout);
+  memset(tocode + 13, 0, sizeof tocode - 13);
+
+  if (cstr)
+    fromcode[18] = '1';
+
+  return iconv_open(tocode, fromcode);
+}
+
+
+static int
+convert(char * d, size_t dlen, int dccsid,
+        const char * s, int slen, int sccsid)
+
+{
+  int i;
+  iconv_t cd;
+  size_t lslen;
+
+  /**
+  ***  Convert `sccsid'-coded `slen'-data bytes at `s' into `dccsid'-coded
+  ***   data stored in the `dlen'-byte buffer at `d'.
+  ***  If `slen' < 0, source string is null-terminated.
+  ***  CCSID 65535 (no conversion) is replaced by the ASCII CCSID.
+  ***  Return the destination length, or -1 if error.
+  **/
+
+  if (sccsid == 65535)
+    sccsid = ASCII_CCSID;
+
+  if (dccsid == 65535)
+    dccsid = ASCII_CCSID;
+
+  if (sccsid == dccsid) {
+    if (slen < 0)
+      lslen = strlen(s) + 1;
+
+    i = lslen < dlen? lslen: dlen;
+
+    if (s != d && i > 0)
+      memcpy(d, s, i);
+
+    return i;
+    }
+
+  if (slen < 0) {
+    lslen = 0;
+    cd = iconv_open_CCSID(dccsid, sccsid, 1);
+    }
+  else {
+    lslen = (size_t) slen;
+    cd = iconv_open_CCSID(dccsid, sccsid, 0);
+    }
+
+  if (ICONV_OPEN_ERROR(cd))
+    return -1;
+
+  i = dlen;
+
+  if ((int) iconv(cd, (char * *) &s, &lslen, &d, &dlen) < 0)
+    i = -1;
+  else
+    i -= dlen;
+
+  iconv_close(cd);
+  return i;
+}
+
+
+static char *
+dynconvert(int dccsid, const char * s, int slen, int sccsid)
+
+{
+  int cstr;
+  char * d;
+  size_t dlen;
+  int l;
+
+  /* Like convert, but the destination is allocated and returned. */
+
+  dlen = (size_t) (slen < 0? strlen(s): slen);
+  dlen *= 6;    /* Allow some expansion. */
+  d = malloc(dlen + 1);
+
+  if (!d)
+    return (char *) NULL;
+
+  l = convert(d, dlen, dccsid, s, slen, sccsid);
+
+  if (l < 0) {
+    free(d);
+    return (char *) NULL;
+    }
+
+  d[l++] = '\0';
+
+  if (l < ++dlen)
+    d = realloc(d, l);
+
+  return d;
+}
+
+
+char *
+curl_version_ccsid(unsigned int ccsid)
+
+{
+  char * aversion;
+  static char eversion[200];
+
+  aversion = curl_version();
+
+  if (!aversion)
+    return aversion;
+
+  if (convert(eversion, sizeof eversion, ccsid, aversion, -1, ASCII_CCSID) < 0)
+    return (char *) NULL;
+
+  return eversion;
+}
+
+
+char *
+curl_easy_escape_ccsid(CURL * handle, const char * string, int length,
+                       unsigned int sccsid, unsigned int dccsid)
+
+{
+  int l;
+  char * s;
+  char * d;
+
+  if (!string) {
+    errno = EINVAL;
+    return (char *) NULL;
+    }
+
+  s = dynconvert(ASCII_CCSID, s, length? length: -1, sccsid);
+
+  if (!s)
+    return (char *) NULL;
+
+  d = curl_easy_escape(handle, s, 0);
+  free(s);
+
+  if (!d)
+    return (char *) NULL;
+
+  s = dynconvert(dccsid, d, -1, ASCII_CCSID);
+  free(d);
+  return s;
+}
+
+
+char *
+curl_easy_unescape_ccsid(CURL * handle, const char * string, int length,
+                         int * outlength,
+                         unsigned int sccsid, unsigned int dccsid)
+
+{
+  int l;
+  char * s;
+  char * d;
+
+  if (!string) {
+    errno = EINVAL;
+    return (char *) NULL;
+    }
+
+  s = dynconvert(ASCII_CCSID, s, length? length: -1, sccsid);
+
+  if (!s)
+    return (char *) NULL;
+
+  d = curl_easy_unescape(handle, s, 0, outlength);
+  free(s);
+
+  if (!d)
+    return (char *) NULL;
+
+  s = dynconvert(dccsid, d, -1, ASCII_CCSID);
+  free(d);
+
+  if (s && outlength)
+    *outlength = strlen(s);
+
+  return s;
+}
+
+
+struct curl_slist *
+curl_slist_append_ccsid(struct curl_slist * list,
+                        const char * data, unsigned int ccsid)
+
+{
+  char * s;
+
+  s = (char *) NULL;
+
+  if (!data)
+    return curl_slist_append(list, data);
+
+  s = dynconvert(ASCII_CCSID, s, -1, ccsid);
+
+  if (!s)
+    return (struct curl_slist *) NULL;
+
+  list = curl_slist_append(list, s);
+  free(s);
+  return list;
+}
+
+
+time_t
+curl_getdate_ccsid(const char * p, const time_t * unused, unsigned int ccsid)
+
+{
+  char * s;
+  time_t t;
+
+  if (!p)
+    return curl_getdate(p, unused);
+
+  s = dynconvert(ASCII_CCSID, s, -1, ccsid);
+
+  if (!s)
+    return (time_t) -1;
+
+  t = curl_getdate(s, unused);
+  free(s);
+  return t;
+}
+
+
+curl_version_info_data *
+curl_version_info_ccsid(CURLversion stamp, unsigned int ccsid)
+
+{
+  curl_version_info_data * p;
+  char * cp;
+  char * * cpp;
+  int n;
+  int l;
+  int i;
+  static curl_version_info_data id;
+  static union {
+    const char * prototable;
+    char filler[2000];
+  } buf;
+
+  p = curl_version_info(stamp);
+
+  if (!p)
+    return p;
+
+  memcpy((char *) &id, (char *) p, sizeof p);
+  cp = (char *) &buf;
+  n = sizeof buf;
+
+  if (id.protocols) {
+    for (i = 0; id.protocols[i++];)
+      ;
+
+    id.protocols = (const char * const *) cp;
+    cp = (char *) (id.protocols + i);
+    n -= cp - ((char *) id.protocols);
+    ((char * *) id.protocols)[--i] = (char *) NULL;
+
+    while (i--) {
+      l = convert(cp, n, ccsid, p->protocols[i], -1, ASCII_CCSID);
+
+      if (l <= 0)
+        return (curl_version_info_data *) NULL;
+
+      ((char * *) id.protocols)[i] = cp;
+      cp += l;
+      n -= l;
+      }
+    }
+
+  p = &id;
+
+  if (p->version) {
+    l = convert(cp, n, ccsid, p->version, -1, ASCII_CCSID);
+
+    if (l <= 0)
+      return (curl_version_info_data *) NULL;
+
+    p->version = cp;
+    cp += l;
+    n -= l;
+    }
+
+  if (p->host) {
+    l = convert(cp, n, ccsid, p->host, -1, ASCII_CCSID);
+
+    if (l <= 0)
+      return (curl_version_info_data *) NULL;
+
+    p->host = cp;
+    cp += l;
+    n -= l;
+    }
+
+  if (p->ssl_version) {
+    l = convert(cp, n, ccsid, p->ssl_version, -1, ASCII_CCSID);
+
+    if (l <= 0)
+      return (curl_version_info_data *) NULL;
+
+    p->ssl_version = cp;
+    cp += l;
+    n -= l;
+    }
+
+  if (p->libz_version) {
+    l = convert(cp, n, ccsid, p->libz_version, -1, ASCII_CCSID);
+
+    if (l <= 0)
+      return (curl_version_info_data *) NULL;
+
+    p->libz_version = cp;
+    cp += l;
+    n -= l;
+    }
+
+  if (p->ares) {
+    l = convert(cp, n, ccsid, p->ares, -1, ASCII_CCSID);
+
+    if (l <= 0)
+      return (curl_version_info_data *) NULL;
+
+    p->ares = cp;
+    cp += l;
+    n -= l;
+    }
+
+  if (p->libidn) {
+    l = convert(cp, n, ccsid, p->libidn, -1, ASCII_CCSID);
+
+    if (l <= 0)
+      return (curl_version_info_data *) NULL;
+
+    p->libidn = cp;
+    cp += l;
+    n -= l;
+    }
+
+  if (p->libssh_version) {
+    l = convert(cp, n, ccsid, p->libssh_version, -1, ASCII_CCSID);
+
+    if (l <= 0)
+      return (curl_version_info_data *) NULL;
+
+    p->libssh_version = cp;
+    cp += l;
+    n -= l;
+    }
+}
+
+
+const char *
+curl_easy_strerror_ccsid(CURLcode error, unsigned int ccsid)
+
+{
+  const char * s;
+  static char buf[200];
+
+  /* Warning: this is not reentrant since we use a static buffer. */
+
+  s = curl_easy_strerror(error);
+
+  if (!s)
+    return s;
+
+  if (convert(buf, sizeof buf, ccsid, s, -1, ASCII_CCSID) < 0)
+    return (const char *) NULL;
+
+  return (const char *) buf;
+}
+
+
+const char *
+curl_share_strerror_ccsid(CURLSHcode error, unsigned int ccsid)
+
+{
+  const char * s;
+  static char buf[200];
+
+  /* Warning: this is not reentrant since we use a static buffer. */
+
+  s = curl_share_strerror(error);
+
+  if (!s)
+    return s;
+
+  if (convert(buf, sizeof buf, ccsid, s, -1, ASCII_CCSID) < 0)
+    return (const char *) NULL;
+
+  return (const char *) buf;
+}
+
+
+const char *
+curl_multi_strerror_ccsid(CURLMcode error, unsigned int ccsid)
+
+{
+  const char * s;
+  static char buf[200];
+
+  /* Warning: this is not reentrant since we use a static buffer. */
+
+  s = curl_multi_strerror(error);
+
+  if (!s)
+    return s;
+
+  if (convert(buf, sizeof buf, ccsid, s, -1, ASCII_CCSID) < 0)
+    return (const char *) NULL;
+
+  return (const char *) buf;
+}
+
+
+CURLcode
+curl_easy_getinfo_ccsid(CURL * curl, CURLINFO info, ...)
+
+{
+  va_list arg;
+  void * paramp;
+  CURLcode ret;
+  unsigned int ccsid;
+  char * * cpp;
+  char * s;
+  char * d;
+  struct SessionHandle * data;
+
+  /* WARNING: unlike curl_easy_get_info(), the strings returned by this
+     procedure have to be free'ed. */
+
+  data = (struct SessionHandle *) curl;
+  va_start(arg, info);
+  paramp = va_arg(arg, void *);
+  ccsid = va_arg(arg, unsigned int);
+  va_end(arg);
+  ret = Curl_getinfo(data, info, paramp);
+
+  if (ret != CURLE_OK || ((int) info & CURLINFO_TYPEMASK) != CURLINFO_STRING)
+    return ret;
+
+  cpp = (char * *) paramp;
+  s = *cpp;
+
+  if (!s)
+    return ret;
+
+  d = dynconvert(ccsid, s, -1, ASCII_CCSID);
+  *cpp = d;
+
+  if (!d)
+    return CURLE_OUT_OF_MEMORY;
+
+  return ret;
+}
+
+
+static int
+Curl_is_formadd_string(CURLformoption option)
+
+{
+  switch (option) {
+
+    case CURLFORM_FILENAME:
+    case CURLFORM_CONTENTTYPE:
+    case CURLFORM_BUFFER:
+    case CURLFORM_FILE:
+    case CURLFORM_FILECONTENT:
+    case CURLFORM_COPYCONTENTS:
+    case CURLFORM_COPYNAME:
+    case CURLFORM_PTRNAME:
+      return 1;
+    }
+
+  return 0;
+}
+
+
+static void
+Curl_formadd_release_local(struct curl_forms * forms, int nargs, int skip)
+
+{
+  while (nargs--)
+    if (nargs != skip)
+      if (Curl_is_formadd_string(forms[nargs].option))
+        if (forms[nargs].value)
+          free((char *) forms[nargs].value);
+
+  free((char *) forms);
+}
+
+
+static int
+Curl_formadd_convert(struct curl_forms * forms,
+                     int formx, int lengthx, unsigned int ccsid)
+
+{
+  int l;
+  char * cp;
+
+  if (formx < 0 || !forms[formx].value)
+    return 0;
+
+  if (lengthx >= 0)
+    l = (int) forms[lengthx].value;
+  else
+    l = strlen(forms[formx].value) + 1;
+
+  cp = malloc(6 * l);
+
+  if (!cp)
+    return -1;
+
+  l = convert(cp, 6 * l, ASCII_CCSID, forms[formx].value, l, ccsid);
+
+  if (l < 0) {
+    free(cp);
+    return -1;
+    }
+
+  cp = realloc(cp, l);
+  forms[formx].value = cp;
+
+  if (lengthx >= 0)
+    forms[lengthx].value = (char *) l;
+
+  return l;
+}
+
+
+CURLFORMcode
+curl_formadd_ccsid(struct curl_httppost * * httppost,
+                   struct curl_httppost * * last_post, ...)
+
+{
+  va_list arg;
+  CURLformoption option;
+  CURLFORMcode result;
+  struct curl_forms * forms;
+  struct curl_forms * lforms;
+  unsigned int ccsid;
+  const char * cp;
+  int nargs;
+  int namelengthx;
+  int contentx;
+  int lengthx;
+  unsigned int contentccsid;
+
+  /* Count the arguments. */
+
+  va_start(arg, last_post);
+  nargs = 0;
+  namelengthx = -1;
+
+  for (;;) {
+    option = va_arg(arg, CURLformoption);
+    nargs++;
+
+    if (option == CURLFORM_END)
+      break;
+
+    if (Curl_is_formadd_string(option)) {
+      (void) va_arg(arg, char *);               /* Eat string pointer. */
+      (void) va_arg(arg, long);                 /* Eat CCSID. */
+      continue;
+      }
+
+    switch (option) {
+
+    case CURLFORM_ARRAY:
+      for (forms = va_arg(arg, struct curl_forms *);
+           forms->option != CURLFORM_END; forms++) {
+        if (forms->option == CURLFORM_ARRAY)
+          return CURL_FORMADD_ILLEGAL_ARRAY;
+
+        if (Curl_is_formadd_string(forms->option))
+          forms++;                              /* Eat CCSID. */
+        else if (forms->option == CURLFORM_NAMELENGTH)
+          namelengthx = nargs;
+
+        nargs++;
+        }
+
+      break;
+
+    case CURLFORM_PTRCONTENTS:
+    case CURLFORM_BUFFERPTR:
+      (void) va_arg(arg, char *);               /* Not a convertible string. */
+      break;
+
+    case CURLFORM_NAMELENGTH:
+      namelengthx = nargs;
+    case CURLFORM_BUFFERLENGTH:
+    case CURLFORM_CONTENTSLENGTH:
+      (void) va_arg(arg, long);
+      break;
+
+    case CURLFORM_CONTENTHEADER:
+      (void) va_arg(arg, struct curl_slist *);
+      break;
+
+    default:
+      return CURL_FORMADD_UNKNOWN_OPTION;
+      }
+
+    break;
+    }
+
+  va_end(arg);
+
+  /* Allocate the local curl_forms array. */
+
+  lforms = (struct curl_forms *) malloc(nargs * sizeof * lforms);
+
+  if (!lforms)
+    return CURL_FORMADD_MEMORY;
+
+  /* Fill local curl_forms array, converting strings as needed. */
+
+  va_start(arg, last_post);
+  nargs = 0;
+  contentx = -1;
+  lengthx = -1;
+
+  for (;;) {
+    option = va_arg(arg, CURLformoption);
+
+    if (option == CURLFORM_PTRNAME)
+      option = CURLFORM_COPYNAME;
+
+    lforms[nargs].option = option;
+
+    if (option == CURLFORM_END)
+      break;
+
+    if (option == CURLFORM_CONTENTTYPE) {
+      if (Curl_formadd_convert(lforms, contentx, lengthx, contentccsid) < 0) {
+        Curl_formadd_release_local(lforms, nargs, contentx);
+        return CURL_FORMADD_MEMORY;
+        }
+
+      contentx = -1;
+      lengthx = -1;
+      }
+
+    if (Curl_is_formadd_string(option)) {
+      lforms[nargs].value = va_arg(arg, char *);
+      ccsid = (unsigned int) va_arg(arg, long);
+
+      if (option == CURLFORM_COPYCONTENTS) {
+        if (contentx >= 0) {
+          Curl_formadd_release_local(lforms, nargs, contentx);
+          return CURL_FORMADD_OPTION_TWICE;
+          }
+
+        contentx = nargs;
+        contentccsid = ccsid;
+        }
+      else if (Curl_formadd_convert(lforms, nargs, option == CURLFORM_COPYNAME?
+                                    namelengthx: -1, ccsid) < 0) {
+        Curl_formadd_release_local(lforms, nargs, contentx);
+        return CURL_FORMADD_MEMORY;
+        }
+
+      nargs++;
+      continue;
+      }
+
+    switch (option) {
+
+    case CURLFORM_ARRAY:
+      for (forms = va_arg(arg, struct curl_forms *);
+           forms->option != CURLFORM_END; forms++) {
+        option = forms->option;
+
+        if (option == CURLFORM_PTRNAME)
+          option = CURLFORM_COPYNAME;
+        else if (option == CURLFORM_CONTENTTYPE) {
+          if (Curl_formadd_convert(lforms,
+                                   contentx, lengthx, contentccsid) < 0) {
+            Curl_formadd_release_local(lforms, nargs, contentx);
+            return CURL_FORMADD_MEMORY;
+            }
+
+          contentx = -1;
+          lengthx = -1;
+          }
+
+        lforms[nargs].option = option;
+        lforms[nargs++].value = forms->value;
+
+        if (Curl_is_formadd_string(option)) {
+          ccsid = (unsigned int) (++forms)->value;
+
+          if (option == CURLFORM_COPYCONTENTS) {
+            if (contentx >= 0) {
+              Curl_formadd_release_local(lforms, nargs, contentx);
+              return CURL_FORMADD_OPTION_TWICE;
+              }
+
+            contentx = nargs;
+            contentccsid = ccsid;
+            }
+          else if (Curl_formadd_convert(lforms, nargs, option ==
+                                        CURLFORM_COPYNAME? namelengthx: -1,
+                                        ccsid) < 0) {
+            Curl_formadd_release_local(lforms, nargs, contentx);
+            return CURL_FORMADD_MEMORY;
+            }
+          }
+        else if (option == CURLFORM_CONTENTSLENGTH)
+          lengthx = nargs;
+
+        nargs++;
+        }
+
+      break;
+
+    case CURLFORM_PTRCONTENTS:
+    case CURLFORM_BUFFERPTR:
+      lforms[nargs].value = va_arg(arg, char *);        /* No conversion. */
+      break;
+
+    case CURLFORM_CONTENTSLENGTH:
+      lengthx = nargs;
+      lforms[nargs].value = (char *) va_arg(arg, long);
+      break;
+
+    case CURLFORM_BUFFERLENGTH:
+    case CURLFORM_NAMELENGTH:
+      lforms[nargs].value = (char *) va_arg(arg, long);
+      break;
+
+    case CURLFORM_CONTENTHEADER:
+      lforms[nargs].value = (char *) va_arg(arg, struct curl_slist *);
+      break;
+      }
+
+    break;
+    }
+
+  va_end(arg);
+
+  if (Curl_formadd_convert(lforms, contentx, lengthx, contentccsid) < 0) {
+    Curl_formadd_release_local(lforms, nargs, contentx);
+    return CURL_FORMADD_MEMORY;
+    }
+
+  /* Argument array is ready. Execute the function. */
+
+  result = curl_formadd(httppost, last_post,
+                        CURLFORM_ARRAY, lforms, CURLFORM_END);
+
+  /* Terminate. */
+
+  Curl_formadd_release_local(lforms, nargs, -1);
+  return result;
+}
+
+
+typedef struct {
+  curl_formget_callback append;
+  void *                arg;
+  unsigned int          ccsid;
+}   cfcdata;
+
+
+static size_t
+Curl_formget_callback_ccsid(void * arg, const char * buf, size_t len)
+
+{
+  cfcdata * p;
+  char * b;
+  int l;
+  size_t ret;
+
+  p = (cfcdata *) arg;
+
+  if (len <= 0)
+    return (*p->append)(p->arg, buf, len);
+
+  b = malloc(6 * len);
+
+  if (!b)
+    return (size_t) -1;
+
+  l = convert(b, 6 * len, p->ccsid, buf, len, ASCII_CCSID);
+
+  if (l < 0) {
+    free(b);
+    return (size_t) -1;
+    }
+
+  ret = (*p->append)(p->arg, b, l);
+  free(b);
+  return ret == l? len: -1;
+}
+
+
+int
+curl_formget_ccsid(struct curl_httppost * form, void * arg,
+                   curl_formget_callback append, unsigned int ccsid)
+
+{
+  cfcdata lcfc;
+
+  lcfc.append = append;
+  lcfc.arg = arg;
+  lcfc.ccsid = ccsid;
+  return curl_formget(form, (void *) &lcfc, Curl_formget_callback_ccsid);
+}
+
+
+CURLcode
+curl_easy_setopt_ccsid(CURL * curl, CURLoption tag, ...)
+
+{
+  CURLcode result;
+  va_list arg;
+  struct SessionHandle * data;
+  char * s;
+  unsigned int ccsid;
+
+  data = (struct SessionHandle *) curl;
+  va_start(arg, tag);
+
+  switch (tag) {
+
+  case CURLOPT_SSH_PRIVATE_KEYFILE:
+  case CURLOPT_SSH_PUBLIC_KEYFILE:
+  case CURLOPT_FTP_ALTERNATIVE_TO_USER:
+  case CURLOPT_FTP_ACCOUNT:
+  case CURLOPT_CAPATH:
+  case CURLOPT_CAINFO:
+  case CURLOPT_KRBLEVEL:
+  case CURLOPT_INTERFACE:
+  case CURLOPT_SSLKEYPASSWD:
+  case CURLOPT_SSLKEYTYPE:
+  case CURLOPT_SSLKEY:
+  case CURLOPT_SSLCERTTYPE:
+  case CURLOPT_SSLCERT:
+  case CURLOPT_RANGE:
+  case CURLOPT_PROXYUSERPWD:
+  case CURLOPT_USERPWD:
+  case CURLOPT_URL:
+  case CURLOPT_FTPPORT:
+  case CURLOPT_PROXY:
+  case CURLOPT_CUSTOMREQUEST:
+  case CURLOPT_COOKIE:
+  case CURLOPT_USERAGENT:
+  case CURLOPT_REFERER:
+  case CURLOPT_POSTFIELDS:
+  case CURLOPT_ENCODING:
+  case CURLOPT_NETRC_FILE:
+  case CURLOPT_EGDSOCKET:
+  case CURLOPT_RANDOM_FILE:
+  case CURLOPT_SSL_CIPHER_LIST:
+  case CURLOPT_PRIVATE:
+  case CURLOPT_SSLENGINE:
+  case CURLOPT_COOKIELIST:
+    s = va_arg(arg, char *);
+    ccsid = va_arg(arg, unsigned int);
+
+    if (s) {
+      s = dynconvert(ASCII_CCSID, s, -1, ccsid);
+
+      if (!s) {
+        result = CURLE_OUT_OF_MEMORY;
+        break;
+        }
+      }
+
+    result = curl_easy_setopt(curl, tag, s);
+
+    switch (tag) {
+
+    default:
+      if (result == CURLE_OK)
+        if (Curl_setdynopt(data, tag, s) == CURLE_OK)
+          break;
+
+    case CURLOPT_SSLENGINE:                     /* Value not stored. */
+    case CURLOPT_COOKIELIST:                    /* Immediate use. */
+      if (s)
+        free(s);
+
+      break;
+      }
+
+    break;
+
+  case CURLOPT_ERRORBUFFER:                     /* This is an output buffer. */
+  default:
+    result = Curl_setopt(data, tag, arg);
+    break;
+    }
+
+  va_end(arg);
+  return result;
+}
diff -Naur curl.orig/packages/OS400/ccsidcurl.h curl/packages/OS400/ccsidcurl.h
--- curl.orig/packages/OS400/ccsidcurl.h	1970-01-01 01:00:00.000000000 +0100
+++ curl/packages/OS400/ccsidcurl.h	2007-07-12 21:24:12.615523000 +0200
@@ -0,0 +1,62 @@
+/***************************************************************************
+ *                                  _   _ ____  _
+ *  Project                     ___| | | |  _ \| |
+ *                             / __| | | | |_) | |
+ *                            | (__| |_| |  _ <| |___
+ *                             \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ***************************************************************************/
+
+#ifndef __CURL_CCSIDCURL_H
+#define __CURL_CCSIDCURL_H
+
+#include <curl.h>
+#include <easy.h>
+#include <multi.h>
+
+
+CURL_EXTERN char * curl_version_ccsid(unsigned int ccsid);
+CURL_EXTERN char * curl_easy_escape_ccsid(CURL * handle,
+                                          const char * string, int length,
+                                          unsigned int sccsid,
+                                          unsigned int dccsid);
+CURL_EXTERN char * curl_easy_unescape_ccsid(CURL * handle, const char * string,
+                                            int length, int * outlength,
+                                            unsigned int sccsid,
+                                            unsigned int dccsid);
+CURL_EXTERN struct curl_slist * curl_slist_append_ccsid(struct curl_slist * lst,
+                                                        const char * data,
+                                                        unsigned int ccsid);
+CURL_EXTERN time_t curl_getdate_ccsid(const char * p, const time_t * unused,
+                                      unsigned int ccsid);
+CURL_EXTERN curl_version_info_data * curl_version_info_ccsid(CURLversion stamp,
+                                                             unsigned int csid);
+CURL_EXTERN const char * curl_easy_strerror_ccsid(CURLcode error,
+                                                  unsigned int ccsid);
+CURL_EXTERN const char * curl_share_strerror_ccsid(CURLSHcode error,
+                                                   unsigned int ccsid);
+CURL_EXTERN const char * curl_multi_strerror_ccsid(CURLMcode error,
+                                                   unsigned int ccsid);
+CURL_EXTERN CURLcode curl_easy_getinfo_ccsid(CURL * curl, CURLINFO info, ...);
+CURL_EXTERN CURLFORMcode curl_formadd_ccsid(struct curl_httppost * * httppost,
+                                            struct curl_httppost * * last_post,
+                                            ...);
+CURL_EXTERN int curl_formget_ccsid(struct curl_httppost * form, void * arg,
+                                   curl_formget_callback append,
+                                   unsigned int ccsid);
+CURL_EXTERN CURLcode curl_easy_setopt_ccsid(CURL * curl, CURLoption tag, ...);
+
+#endif
diff -Naur curl.orig/packages/OS400/curl.inc.in curl/packages/OS400/curl.inc.in
--- curl.orig/packages/OS400/curl.inc.in	1970-01-01 01:00:00.000000000 +0100
+++ curl/packages/OS400/curl.inc.in	2007-07-17 14:48:57.574254000 +0200
@@ -0,0 +1,1485 @@
+      /if not defined(CURL_CURL_INC_)
+      /define CURL_CURL_INC_
+      *
+      **************************************************************************
+      *                               Constants
+      **************************************************************************
+      *
+     d LIBCURL_VERSION...
+     d                 c                   '@LIBCURL_VERSION@'
+     d LIBCURL_VERSION_MAJOR...
+     d                 c                   @LIBCURL_VERSION_MAJOR@
+     d LIBCURL_VERSION_MINOR...
+     d                 c                   @LIBCURL_VERSION_MINOR@
+     d LIBCURL_VERSION_PATCH...
+     d                 c                   @LIBCURL_VERSION_PATCH@
+     d LIBCURL_VERSION_NUM...
+     d                 c                   X'00@LIBCURL_VERSION_NUM@'
+     d LIBCURL_TIMESTAMP...
+     d                 c                   '@LIBCURL_TIMESTAMP@'
+      *
+     d CURL_SOCKET_BAD...
+     d                 c                   -1
+     d CURL_SOCKET_TIMEOUT...
+     d                 c                   -1
+      *
+     d CURLINFO_STRING...
+     d                 c                   X'00100000'
+     d CURLINFO_LONG   c                   X'00200000'
+     d CURLINFO_DOUBLE...
+     d                 c                   X'00300000'
+     d CURLINFO_SLIST  c                   X'00400000'
+     d CURLINFO_MASK   c                   X'000FFFFF'
+     d CURLINFO_TYPEMASK...
+     d                 c                   X'00F00000'
+      *
+     d CURL_GLOBAL_SSL...
+     d                 c                   X'00000001'
+     d CURL_GLOBAL_WIN32...
+     d                 c                   X'00000002'
+     d CURL_GLOBAL_ALL...
+     d                 c                   X'00000003'
+     d CURL_GLOBAL_NOTHING...
+     d                 c                   X'00000000'
+     d CURL_GLOBAL_DEFAULT...
+     d                 c                   X'00000003'
+      *
+     d CURL_VERSION_IPV6...
+     d                 c                   X'00000001'
+     d CURL_VERSION_KERBEROS4...
+     d                 c                   X'00000002'
+     d CURL_VERSION_SSL...
+     d                 c                   X'00000004'
+     d CURL_VERSION_LIBZ...
+     d                 c                   X'00000008'
+     d CURL_VERSION_NTLM...
+     d                 c                   X'00000010'
+     d CURL_VERSION_GSSNEGOTIATE...
+     d                 c                   X'00000020'
+     d CURL_VERSION_DEBUG...
+     d                 c                   X'00000040'
+     d CURL_VERSION_ASYNCHDNS...
+     d                 c                   X'00000080'
+     d CURL_VERSION_SPNEGO...
+     d                 c                   X'00000100'
+     d CURL_VERSION_LARGEFILE...
+     d                 c                   X'00000200'
+     d CURL_VERSION_IDN...
+     d                 c                   X'00000400'
+     d CURL_VERSION_SSPI...
+     d                 c                   X'00000800'
+     d CURL_VERSION_CONV...
+     d                 c                   X'00001000'
+      *
+     d HTTPPOST_FILENAME...
+     d                 c                   X'00000001'
+     d HTTPPOST_READFILE...
+     d                 c                   X'00000002'
+     d HTTPPOST_PTRNAME...
+     d                 c                   X'00000004'
+     d HTTPPOST_PTRCONTENTS...
+     d                 c                   X'00000008'
+     d HTTPPOST_BUFFER...
+     d                 c                   X'00000010'
+     d HTTPPOST_PTRBUFFER...
+     d                 c                   X'00000020'
+      *
+     d CURL_READFUNC_ABORT...
+     d                 c                   X'10000000'
+      *
+     d CURLAUTH_NONE   c                   X'00000000'
+     d CURLAUTH_BASIC  c                   X'00000001'
+     d CURLAUTH_DIGEST...
+     d                 c                   X'00000002'
+     d CURLAUTH_GSSNEGOTIATE...
+     d                 c                   X'00000004'
+     d CURLAUTH_NTLM   c                   X'00000008'
+     d CURLAUTH_ANY    c                   X'7FFFFFFF'
+     d CURLAUTH_ANYSAFE...
+     d                 c                   X'7FFFFFFE'                          ~CURLAUTH_BASIC
+      *
+     d CURLSSH_AUTH_ANY...
+     d                 c                   X'7FFFFFFF'
+     d CURLSSH_AUTH_NONE...
+     d                 c                   X'00000000'
+     d CURLSSH_AUTH_PUBLICKEY...
+     d                 c                   X'00000001'
+     d CURLSSH_AUTH_PASSWORD...
+     d                 c                   X'00000002'
+     d CURLSSH_AUTH_HOST...
+     d                 c                   X'00000004'
+     d CURLSSH_AUTH_KEYBOARD...
+     d                 c                   X'00000008'
+     d CURLSSH_AUTH_DEFAULT...
+     d                 c                   X'7FFFFFFF'                          CURLSSH_AUTH_ANY
+      *
+     d CURL_ERROR_SIZE...
+     d                 c                   256
+      *
+     d CURLOPTTYPE_LONG...
+     d                 c                   0
+     d CURLOPTTYPE_OBJECTPOINT...
+     d                 c                   10000
+     d CURLOPTTYPE_FUNCTIONPOINT...
+     d                 c                   20000
+     d CURLOPTTYPE_OFF_T...
+     d                 c                   30000
+      *
+     d CURL_IPRESOLVE_WHATEVER...
+     d                 c                   0
+     d CURL_IPRESOLVE_V4...
+     d                 c                   1
+     d CURL_IPRESOLVE_V6...
+     d                 c                   2
+      *
+     d CURL_HTTP_VERSION_NONE...
+     d                 c                   0
+     d CURL_HTTP_VERSION_1_0...
+     d                 c                   1
+     d CURL_HTTP_VERSION_1_1...
+     d                 c                   2
+      *
+     d CURL_NETRC_IGNORED...
+     d                 c                   0
+     d CURL_NETRC_OPTIONAL...
+     d                 c                   1
+     d CURL_NETRC_REQUIRED...
+     d                 c                   2
+      *
+     d CURL_SSLVERSION_DEFAULT...
+     d                 c                   0
+     d CURL_SSLVERSION_TLSv1...
+     d                 c                   1
+     d CURL_SSLVERSION_SSLv2...
+     d                 c                   2
+     d CURL_SSLVERSION_SSLv3...
+     d                 c                   3
+      *
+     d CURL_POLL_NONE  c                   0
+     d CURL_POLL_IN    c                   1
+     d CURL_POLL_OUT   c                   2
+     d CURL_POLL_INOUT...
+     d                 c                   3
+     d CURL_POLL_REMOVE...
+     d                 c                   4
+      *
+     d CURL_CSELECT_IN...
+     d                 c                   X'00000001'
+     d CURL_CSELECT_OUT...
+     d                 c                   X'00000002'
+     d CURL_CSELECT_ERR...
+     d                 c                   X'00000004'
+      *
+      **************************************************************************
+      *                                Types
+      **************************************************************************
+      *
+     d curl_socket_t   s             10i 0 based(######ptr######)
+      *
+     d curl_off_t      s             10i 0 based(######ptr######)
+      *
+     d CURLcode        s             10i 0 based(######ptr######)               Enum
+     d  CURLE_OK       c                   0
+     d  CURLE_UNSUPPORTED_PROTOCOL...
+     d                 c                   1
+     d  CURLE_FAILED_INIT...
+     d                 c                   2
+     d  CURLE_URL_MALFORMAT...
+     d                 c                   3
+     d  CURLE_URL_MALFORMAT_USER...
+     d                 c                   4
+     d  CURLE_COULDNT_RESOLVE_PROXY...
+     d                 c                   5
+     d  CURLE_COULDNT_RESOLVE_HOST...
+     d                 c                   6
+     d  CURLE_COULDNT_CONNECT...
+     d                 c                   7
+     d  CURLE_FTP_WEIRD_SERVER_REPLY...
+     d                 c                   8
+     d  CURLE_FTP_ACCESS_DENIED...
+     d                 c                   9
+     d  CURLE_FTP_USER_PASSWORD_INCORRECT...
+     d                 c                   10
+     d  CURLE_FTP_WEIRD_PASS_REPLY...
+     d                 c                   11
+     d  CURLE_FTP_WEIRD_USER_REPLY...
+     d                 c                   12
+     d  CURLE_FTP_WEIRD_PASV_REPLY...
+     d                 c                   13
+     d  CURLE_FTP_WEIRD_227_FORMAT...
+     d                 c                   14
+     d  CURLE_FTP_CANT_GET_HOST...
+     d                 c                   15
+     d  CURLE_FTP_CANT_RECONNECT...
+     d                 c                   16
+     d  CURLE_FTP_COULDNT_SET_BINARY...
+     d                 c                   17
+     d  CURLE_PARTIAL_FILE...
+     d                 c                   18
+     d  CURLE_FTP_COULDNT_RETR_FILE...
+     d                 c                   19
+     d  CURLE_FTP_WRITE_ERROR...
+     d                 c                   20
+     d  CURLE_FTP_QUOTE_ERROR...
+     d                 c                   21
+     d  CURLE_HTTP_RETURNED_ERROR...
+     d                 c                   22
+     d  CURLE_WRITE_ERROR...
+     d                 c                   23
+     d  CURLE_MALFORMAT_USER...
+     d                 c                   24
+     d  CURLE_UPLOAD_FAILED...
+     d                 c                   25
+     d  CURLE_READ_ERROR...
+     d                 c                   26
+     d  CURLE_OUT_OF_MEMORY...
+     d                 c                   27
+     d  CURLE_OPERATION_TIMEOUTED...
+     d                 c                   28
+     d  CURLE_OPERATION_TIMEDOUT...
+     d                 c                   28
+     d  CURLE_FTP_COULDNT_SET_ASCII...
+     d                 c                   29
+     d  CURLE_FTP_PORT_FAILED...
+     d                 c                   30
+     d  CURLE_FTP_COULDNT_USE_REST...
+     d                 c                   31
+     d  CURLE_FTP_COULDNT_GET_SIZE...
+     d                 c                   32
+     d  CURLE_HTTP_RANGE_ERROR...
+     d                 c                   33
+     d  CURLE_HTTP_POST_ERROR...
+     d                 c                   34
+     d  CURLE_SSL_CONNECT_ERROR...
+     d                 c                   35
+     d  CURLE_BAD_DOWNLOAD_RESUME...
+     d                 c                   36
+     d  CURLE_FILE_COULDNT_READ_FILE...
+     d                 c                   37
+     d  CURLE_LDAP_CANNOT_BIND...
+     d                 c                   38
+     d  CURLE_LDAP_SEARCH_FAILED...
+     d                 c                   39
+     d  CURLE_LIBRARY_NOT_FOUND...
+     d                 c                   40
+     d  CURLE_FUNCTION_NOT_FOUND...
+     d                 c                   41
+     d  CURLE_ABORTED_BY_CALLBACK...
+     d                 c                   42
+     d  CURLE_BAD_FUNCTION_ARGUMENT...
+     d                 c                   43
+     d  CURLE_BAD_CALLING_ORDER...
+     d                 c                   44
+     d  CURLE_INTERFACE_FAILED...
+     d                 c                   45
+     d  CURLE_BAD_PASSWORD_ENTERED...
+     d                 c                   46
+     d  CURLE_TOO_MANY_REDIRECTS...
+     d                 c                   47
+     d  CURLE_UNKNOWN_TELNET_OPTION...
+     d                 c                   48
+     d  CURLE_TELNET_OPTION_SYNTAX...
+     d                 c                   49
+     d  CURLE_OBSOLETE...
+     d                 c                   50
+     d  CURLE_SSL_PEER_CERTIFICATE...
+     d                 c                   51
+     d  CURLE_GOT_NOTHING...
+     d                 c                   52
+     d  CURLE_SSL_ENGINE_NOTFOUND...
+     d                 c                   53
+     d  CURLE_SSL_ENGINE_SETFAILED...
+     d                 c                   54
+     d  CURLE_SEND_ERROR...
+     d                 c                   55
+     d  CURLE_RECV_ERROR...
+     d                 c                   56
+     d  CURLE_SHARE_IN_USE...
+     d                 c                   57
+     d  CURLE_SSL_CERTPROBLEM...
+     d                 c                   58
+     d  CURLE_SSL_CIPHER...
+     d                 c                   59
+     d  CURLE_SSL_CACERT...
+     d                 c                   60
+     d  CURLE_BAD_CONTENT_ENCODING...
+     d                 c                   61
+     d  CURLE_LDAP_INVALID_URL...
+     d                 c                   62
+     d  CURLE_FILESIZE_EXCEEDED...
+     d                 c                   63
+     d  CURLE_FTP_SSL_FAILED...
+     d                 c                   64
+     d  CURLE_SEND_FAIL_REWIND...
+     d                 c                   65
+     d  CURLE_SSL_ENGINE_INITFAILED...
+     d                 c                   66
+     d  CURLE_LOGIN_DENIED...
+     d                 c                   67
+     d  CURLE_TFTP_NOTFOUND...
+     d                 c                   68
+     d  CURLE_TFTP_PERM...
+     d                 c                   69
+     d  CURLE_TFTP_DISKFULL...
+     d                 c                   70
+     d  CURLE_TFTP_ILLEGAL...
+     d                 c                   71
+     d  CURLE_TFTP_UNKNOWNID...
+     d                 c                   72
+     d  CURLE_TFTP_EXISTS...
+     d                 c                   73
+     d  CURLE_TFTP_NOSUCHUSER...
+     d                 c                   74
+     d  CURLE_CONV_FAILED...
+     d                 c                   75
+     d  CURLE_CONV_REQD...
+     d                 c                   76
+     d  CURLE_SSL_CACERT_BADFILE...
+     d                 c                   77
+     d  CURLE_REMOTE_FILE_NOT_FOUND...
+     d                 c                   78
+     d  CURLE_SSH...
+     d                 c                   79
+     d  CURLE_SSL_SHUTDOWN_FAILED...
+     d                 c                   80
+      *
+     d curlioerr       s             10i 0 based(######ptr######)               Enum
+     d  CURLIOE_OK     c                   0
+     d  CURLIOE_UNKNOWNCMD...
+     d                 c                   1
+     d  CURLIOE_FAILRESTART...
+     d                 c                   2
+      *
+     d curliocmd       s             10i 0 based(######ptr######)               Enum
+     d  CURLIOCMD_NOP  c                   0
+     d  CURLIOCMD_RESTARTREAD...
+     d                 c                   1
+      *
+     d curl_infotype   s             10i 0 based(######ptr######)               Enum
+     d  CURLINFO_TEXT...
+     d                 c                   0
+     d  CURLINFO_HEADER_IN...
+     d                 c                   1
+     d  CURLINFO_HEADER_OUT...
+     d                 c                   2
+     d  CURLINFO_DATA_IN...
+     d                 c                   3
+     d  CURLINFO_DATA_OUT...
+     d                 c                   4
+     d  CURLINFO_SSL_DATA_IN...
+     d                 c                   5
+     d  CURLINFO_SSL_DATA_OUT...
+     d                 c                   6
+     d  CURLINFO_END...
+     d                 c                   7
+      *
+     d curl_proxytype  s             10i 0 based(######ptr######)               Enum
+     d  CURLPROXY_HTTP...
+     d                 c                   0
+     d  CURLPROXY_SOCKS4...
+     d                 c                   4
+     d  CURLPROXY_SOCKS5...
+     d                 c                   5
+      *
+     d curl_ftpssl     s             10i 0 based(######ptr######)               Enum
+     d  CURLFTPSSL_NONE...
+     d                 c                   0
+     d  CURLFTPSSL_TRY...
+     d                 c                   1
+     d  CURLFTPSSL_CONTROL...
+     d                 c                   2
+     d  CURLFTPSSL_ALL...
+     d                 c                   3
+      *
+     d curl_ftpccc     s             10i 0 based(######ptr######)               Enum
+     d  CURLFTPSSL_CCC_NONE...
+     d                 c                   0
+     d  CURLFTPSSL_CCC_PASSIVE...
+     d                 c                   1
+     d  CURLFTPSSL_CCC_ACTIVE...
+     d                 c                   2
+      *
+     d curl_ftpauth    s             10i 0 based(######ptr######)               Enum
+     d  CURLFTPAUTH_DEFAULT...
+     d                 c                   0
+     d  CURLFTPAUTH_SSL...
+     d                 c                   1
+     d  CURLFTPAUTH_TLS...
+     d                 c                   2
+      *
+     d curl_ftpmethod  s             10i 0 based(######ptr######)               Enum
+     d  CURLFTPMETHOD_DEFAULT...
+     d                 c                   0
+     d  CURLFTPMETHOD_MULTICWD...
+     d                 c                   1
+     d  CURLFTPMETHOD_NOCWD...
+     d                 c                   2
+     d  CURLFTPMETHOD_SINGLECWD...
+     d                 c                   3
+      *
+     d CURLoption      s             10i 0 based(######ptr######)               Enum
+     d  CURLOPT_FILE   c                   10001
+     d  CURLOPT_WRITEDATA...
+     d                 c                   10001
+     d  CURLOPT_URL    c                   10002
+     d  CURLOPT_PORT   c                   00003
+     d  CURLOPT_PROXY  c                   10004
+     d  CURLOPT_USERPWD...
+     d                 c                   10005
+     d  CURLOPT_PROXYUSERPWD...
+     d                 c                   10006
+     d  CURLOPT_RANGE  c                   10007
+     d  CURLOPT_INFILE...
+     d                 c                   10009
+     d  CURLOPT_READDATA...
+     d                 c                   10009
+     d  CURLOPT_ERRORBUFFER...
+     d                 c                   10010
+     d  CURLOPT_WRITEFUNCTION...
+     d                 c                   20011
+     d  CURLOPT_READFUNCTION...
+     d                 c                   20012
+     d  CURLOPT_TIMEOUT...
+     d                 c                   00013
+     d  CURLOPT_INFILESIZE...
+     d                 c                   00014
+     d  CURLOPT_POSTFIELDS...
+     d                 c                   10015
+     d  CURLOPT_REFERER...
+     d                 c                   10016
+     d  CURLOPT_FTPPORT...
+     d                 c                   10017
+     d  CURLOPT_USERAGENT...
+     d                 c                   10018
+     d  CURLOPT_LOW_SPEED_LIMIT...
+     d                 c                   00019
+     d  CURLOPT_LOW_SPEED_TIME...
+     d                 c                   00020
+     d  CURLOPT_RESUME_FROM...
+     d                 c                   00021
+     d  CURLOPT_COOKIE...
+     d                 c                   10022
+     d  CURLOPT_HTTPHEADER...
+     d                 c                   10023
+     d  CURLOPT_HTTPPOST...
+     d                 c                   10024
+     d  CURLOPT_SSLCERT...
+     d                 c                   10025
+     d  CURLOPT_SSLCERTPASSWD...
+     d                 c                   10026
+     d  CURLOPT_SSLKEYPASSWD...
+     d                 c                   10026
+     d  CURLOPT_CRLF   c                   00027
+     d  CURLOPT_QUOTE  c                   10028
+     d  CURLOPT_WRITEHEADER...
+     d                 c                   10029
+     d  CURLOPT_HEADERDATA...
+     d                 c                   10029
+     d  CURLOPT_COOKIEFILE...
+     d                 c                   10031
+     d  CURLOPT_SSLVERSION...
+     d                 c                   00032
+     d  CURLOPT_TIMECONDITION...
+     d                 c                   00033
+     d  CURLOPT_TIMEVALUE...
+     d                 c                   00034
+     d  CURLOPT_CUSTOMREQUEST...
+     d                 c                   10036
+     d  CURLOPT_STDERR...
+     d                 c                   10037
+     d  CURLOPT_POSTQUOTE...
+     d                 c                   10039
+     d  CURLOPT_WRITEINFO...
+     d                 c                   10040
+     d  CURLOPT_VERBOSE...
+     d                 c                   00041
+     d  CURLOPT_HEADER...
+     d                 c                   00042
+     d  CURLOPT_NOPROGRESS...
+     d                 c                   00043
+     d  CURLOPT_NOBODY...
+     d                 c                   00044
+     d  CURLOPT_FAILONERROR...
+     d                 c                   00045
+     d  CURLOPT_UPLOAD...
+     d                 c                   00046
+     d  CURLOPT_POST   c                   00047
+     d  CURLOPT_FTPLISTONLY...
+     d                 c                   00048
+     d  CURLOPT_FTPAPPEND...
+     d                 c                   00050
+     d  CURLOPT_NETRC  c                   00051
+     d  CURLOPT_FOLLOWLOCATION...
+     d                 c                   00052
+     d  CURLOPT_TRANSFERTEXT...
+     d                 c                   00053
+     d  CURLOPT_PUT    c                   00054
+     d  CURLOPT_PROGRESSFUNCTION...
+     d                 c                   20056
+     d  CURLOPT_PROGRESSDATA...
+     d                 c                   10057
+     d  CURLOPT_AUTOREFERER...
+     d                 c                   00058
+     d  CURLOPT_PROXYPORT...
+     d                 c                   00059
+     d  CURLOPT_POSTFIELDSIZE...
+     d                 c                   00060
+     d  CURLOPT_HTTPPROXYTUNNEL...
+     d                 c                   00061
+     d  CURLOPT_INTERFACE...
+     d                 c                   10062
+     d  CURLOPT_KRB4LEVEL...
+     d                 c                   10063
+     d  CURLOPT_SSL_VERIFYPEER...
+     d                 c                   00064
+     d  CURLOPT_CAINFO...
+     d                 c                   10065
+     d  CURLOPT_MAXREDIRS...
+     d                 c                   00068
+     d  CURLOPT_FILETIME...
+     d                 c                   00069
+     d  CURLOPT_TELNETOPTIONS...
+     d                 c                   10070
+     d  CURLOPT_MAXCONNECTS...
+     d                 c                   00071
+     d  CURLOPT_CLOSEPOLICY...
+     d                 c                   00072
+     d  CURLOPT_FRESH_CONNECT...
+     d                 c                   00074
+     d  CURLOPT_FORBID_REUSE...
+     d                 c                   00075
+     d  CURLOPT_RANDOM_FILE...
+     d                 c                   10076
+     d  CURLOPT_EGDSOCKET...
+     d                 c                   10077
+     d  CURLOPT_CONNECTTIMEOUT...
+     d                 c                   00078
+     d  CURLOPT_HEADERFUNCTION...
+     d                 c                   20079
+     d  CURLOPT_HTTPGET...
+     d                 c                   00080
+     d  CURLOPT_SSL_VERIFYHOST...
+     d                 c                   00081
+     d  CURLOPT_COOKIEJAR...
+     d                 c                   10082
+     d  CURLOPT_SSL_CIPHER_LIST...
+     d                 c                   10083
+     d  CURLOPT_HTTP_VERSION...
+     d                 c                   00084
+     d  CURLOPT_FTP_USE_EPSV...
+     d                 c                   00085
+     d  CURLOPT_SSLCERTTYPE...
+     d                 c                   10086
+     d  CURLOPT_SSLKEY...
+     d                 c                   10087
+     d  CURLOPT_SSLKEYTYPE...
+     d                 c                   10088
+     d  CURLOPT_SSLENGINE...
+     d                 c                   10089
+     d  CURLOPT_SSLENGINE_DEFAULT...
+     d                 c                   00090
+     d  CURLOPT_DNS_USE_GLOBAL_CACHE...
+     d                 c                   00091
+     d  CURLOPT_DNS_CACHE_TIMEOUT...
+     d                 c                   00092
+     d  CURLOPT_PREQUOTE...
+     d                 c                   10093
+     d  CURLOPT_DEBUGFUNCTION...
+     d                 c                   20094
+     d  CURLOPT_DEBUGDATA...
+     d                 c                   10095
+     d  CURLOPT_COOKIESESSION...
+     d                 c                   00096
+     d  CURLOPT_CAPATH...
+     d                 c                   10097
+     d  CURLOPT_BUFFERSIZE...
+     d                 c                   00098
+     d  CURLOPT_NOSIGNAL...
+     d                 c                   00099
+     d  CURLOPT_SHARE  c                   10100
+     d  CURLOPT_PROXYTYPE...
+     d                 c                   00101
+     d  CURLOPT_ENCODING...
+     d                 c                   10102
+     d  CURLOPT_PRIVATE...
+     d                 c                   10103
+     d  CURLOPT_HTTP200ALIASES...
+     d                 c                   10104
+     d  CURLOPT_UNRESTRICTED_AUTH...
+     d                 c                   00105
+     d  CURLOPT_FTP_USE_EPRT...
+     d                 c                   00106
+     d  CURLOPT_HTTPAUTH...
+     d                 c                   00107
+     d  CURLOPT_SSL_CTX_FUNCTION...
+     d                 c                   20108
+     d  CURLOPT_SSL_CTX_DATA...
+     d                 c                   10109
+     d  CURLOPT_FTP_CREATE_MISSING_DIRS...
+     d                 c                   00110
+     d  CURLOPT_PROXYAUTH...
+     d                 c                   00111
+     d  CURLOPT_FTP_RESPONSE_TIMEOUT...
+     d                 c                   00112
+     d  CURLOPT_IPRESOLVE...
+     d                 c                   00113
+     d  CURLOPT_MAXFILESIZE...
+     d                 c                   00114
+     d  CURLOPT_INFILESIZE_LARGE...
+     d                 c                   30115
+     d  CURLOPT_RESUME_FROM_LARGE...
+     d                 c                   30116
+     d  CURLOPT_MAXFILESIZE_LARGE...
+     d                 c                   30117
+     d  CURLOPT_NETRC_FILE...
+     d                 c                   10118
+     d  CURLOPT_FTP_SSL...
+     d                 c                   00119
+     d  CURLOPT_POSTFIELDSIZE_LARGE...
+     d                 c                   30120
+     d  CURLOPT_TCP_NODELAY...
+     d                 c                   00121
+     d  CURLOPT_FTPSSLAUTH...
+     d                 c                   00129
+     d  CURLOPT_IOCTLFUNCTION...
+     d                 c                   20130
+     d  CURLOPT_IOCTLDATA...
+     d                 c                   10131
+     d  CURLOPT_FTP_ACCOUNT...
+     d                 c                   10134
+     d  CURLOPT_COOKIELIST...
+     d                 c                   10135
+     d  CURLOPT_IGNORE_CONTENT_LENGTH...
+     d                 c                   00136
+     d  CURLOPT_FTP_SKIP_PASV_IP...
+     d                 c                   00137
+     d  CURLOPT_FTP_FILEMETHOD...
+     d                 c                   00138
+     d  CURLOPT_LOCALPORT...
+     d                 c                   00139
+     d  CURLOPT_LOCALPORTRANGE...
+     d                 c                   00140
+     d  CURLOPT_CONNECT_ONLY...
+     d                 c                   00141
+     d  CURLOPT_CONV_FROM_NETWORK_FUNCTION...
+     d                 c                   20142
+     d  CURLOPT_CONV_TO_NETWORK_FUNCTION...
+     d                 c                   20143
+     d  CURLOPT_CONV_FROM_UTF8_FUNCTION...
+     d                 c                   20144
+     d  CURLOPT_MAX_SEND_SPEED_LARGE...
+     d                 c                   30145
+     d  CURLOPT_MAX_RECV_SPEED_LARGE...
+     d                 c                   30146
+     d  CURLOPT_FTP_ALTERNATIVE_TO_USER...
+     d                 c                   10147
+     d  CURLOPT_SOCKOPTFUNCTION...
+     d                 c                   20148
+     d  CURLOPT_SOCKOPTDATA...
+     d                 c                   10149
+     d  CURLOPT_SSL_SESSIONID_CACHE...
+     d                 c                   00150
+     d  CURLOPT_SSH_AUTH_TYPES...
+     d                 c                   00151
+     d  CURLOPT_SSH_PUBLIC_KEYFILE...
+     d                 c                   10152
+     d  CURLOPT_SSH_PRIVATE_KEYFILE...
+     d                 c                   10153
+     d  CURLOPT_FTP_SSL_CCC...
+     d                 c                   00154
+     d  CURLOPT_TIMEOUT_MS...
+     d                 c                   00155
+     d  CURLOPT_CONNECTTIMEOUT_MS...
+     d                 c                   00156
+     d  CURLOPT_HTTP_TRANSFER_DECODING...
+     d                 c                   00157
+     d  CURLOPT_HTTP_CONTENT_DECODING...
+     d                 c                   00158
+      *
+     d CURLFORMcode    s             10i 0 based(######ptr######)               Enum
+     d  CURL_FORMADD_OK...
+     d                 c                   0
+     d  CURL_FORMADD_MEMORY...
+     d                 c                   1
+     d  CURL_FORMADD_OPTION_TWICE...
+     d                 c                   2
+     d  CURL_FORMADD_NULL...
+     d                 c                   3
+     d  CURL_FORMADD_UNKNOWN_OPTION...
+     d                 c                   4
+     d  CURL_FORMADD_INCOMPLETE...
+     d                 c                   5
+     d  CURL_FORMADD_ILLEGAL_ARRAY...
+     d                 c                   6
+     d  CURL_FORMADD_DISABLED...
+     d                 c                   7
+      *
+     d CURLformoption  s             10i 0 based(######ptr######)               Enum
+     d  CURLFORM_NOTHING...
+     d                 c                   0
+     d  CURLFORM_COPYNAME...
+     d                 c                   1
+     d  CURLFORM_PTRNAME...
+     d                 c                   2
+     d  CURLFORM_NAMELENGTH...
+     d                 c                   3
+     d  CURLFORM_COPYCONTENTS...
+     d                 c                   4
+     d  CURLFORM_PTRCONTENTS...
+     d                 c                   5
+     d  CURLFORM_CONTENTSLENGTH...
+     d                 c                   6
+     d  CURLFORM_FILECONTENT...
+     d                 c                   7
+     d  CURLFORM_ARRAY...
+     d                 c                   8
+     d  CURLFORM_OBSOLETE...
+     d                 c                   9
+     d  CURLFORM_FILE...
+     d                 c                   10
+     d  CURLFORM_BUFFER...
+     d                 c                   11
+     d  CURLFORM_BUFFERPTR...
+     d                 c                   12
+     d  CURLFORM_BUFFERLENGTH...
+     d                 c                   13
+     d  CURLFORM_CONTENTTYPE...
+     d                 c                   14
+     d  CURLFORM_CONTENTHEADER...
+     d                 c                   15
+     d  CURLFORM_FILENAME...
+     d                 c                   16
+     d  CURLFORM_END...
+     d                 c                   17
+     d  CURLFORM_OBSOLETE2...
+     d                 c                   18
+      *
+     d CURLINFO        s             10i 0 based(######ptr######)               Enum
+     d  CURLINFO_EFFECTIVE_URL...                                               CURLINFO_STRING + 1
+     d                 c                   X'00100001'
+     d  CURLINFO_RESPONSE_CODE...                                               CURLINFO_LONG   + 2
+     d                 c                   X'00200002'
+     d  CURLINFO_TOTAL_TIME...                                                  CURLINFO_DOUBLE + 3
+     d                 c                   X'00300003'
+     d  CURLINFO_NAMELOOKUP_TIME...                                             CURLINFO_DOUBLE + 4
+     d                 c                   X'00300004'
+     d  CURLINFO_CONNECT_TIME...                                                CURLINFO_DOUBLE + 5
+     d                 c                   X'00300005'
+     d  CURLINFO_PRETRANSFER_TIME...                                            CURLINFO_DOUBLE + 6
+     d                 c                   X'00300006'
+     d  CURLINFO_SIZE_UPLOAD...                                                 CURLINFO_DOUBLE + 7
+     d                 c                   X'00300007'
+     d  CURLINFO_SIZE_DOWNLOAD...                                               CURLINFO_DOUBLE + 8
+     d                 c                   X'00300008'
+     d  CURLINFO_SPEED_DOWNLOAD...                                              CURLINFO_DOUBLE + 9
+     d                 c                   X'00300009'
+     d  CURLINFO_SPEED_UPLOAD...                                                CURLINFO_DOUBLE + 10
+     d                 c                   X'0030000A'
+     d  CURLINFO_HEADER_SIZE...                                                 CURLINFO_LONG   + 11
+     d                 c                   X'0020000B'
+     d  CURLINFO_REQUEST_SIZE...                                                CURLINFO_LONG   + 12
+     d                 c                   X'0020000C'
+     d  CURLINFO_SSL_VERIFYRESULT...                                            CURLINFO_LONG   + 13
+     d                 c                   X'0020000D'
+     d  CURLINFO_FILETIME...                                                    CURLINFO_LONG   + 14
+     d                 c                   X'0020000E'
+     d  CURLINFO_CONTENT_LENGTH_DOWNLOAD...                                     CURLINFO_DOUBLE + 15
+     d                 c                   X'0030000F'
+     d  CURLINFO_CONTENT_LENGTH_UPLOAD...                                       CURLINFO_DOUBLE + 16
+     d                 c                   X'00300010'
+     d  CURLINFO_STARTTRANSFER_TIME...                                          CURLINFO_DOUBLE + 17
+     d                 c                   X'00300011'
+     d  CURLINFO_CONTENT_TYPE...                                                CURLINFO_STRING + 18
+     d                 c                   X'00100012'
+     d  CURLINFO_REDIRECT_TIME...                                               CURLINFO_DOUBLE + 19
+     d                 c                   X'00300013'
+     d  CURLINFO_REDIRECT_COUNT...                                              CURLINFO_LONG   + 20
+     d                 c                   X'00200014'
+     d  CURLINFO_PRIVATE...                                                     CURLINFO_STRING + 21
+     d                 c                   X'00100015'
+     d  CURLINFO_HTTP_CONNECTCODE...                                            CURLINFO_LONG   + 22
+     d                 c                   X'00200016'
+     d  CURLINFO_HTTPAUTH_AVAIL...                                              CURLINFO_LONG   + 23
+     d                 c                   X'00200017'
+     d  CURLINFO_PROXYAUTH_AVAIL...                                             CURLINFO_LONG   + 24
+     d                 c                   X'00200018'
+     d  CURLINFO_OS_ERRNO...                                                    CURLINFO_LONG   + 25
+     d                 c                   X'00200019'
+     d  CURLINFO_NUM_CONNECTS...                                                CURLINFO_LONG   + 26
+     d                 c                   X'00200020'
+     d  CURLINFO_SSL_ENGINES...                                                 CURLINFO_SLIST  + 27
+     d                 c                   X'00400021'
+     d  CURLINFO_COOKIELIST...                                                  CURLINFO_SLIST  + 28
+     d                 c                   X'00400022'
+     d  CURLINFO_LASTSOCKET...                                                  CURLINFO_LONG   + 29
+     d                 c                   X'00200023'
+     d  CURLINFO_FTP_ENTRY_PATH...                                              CURLINFO_STRING + 30
+     d                 c                   X'00100024'
+     d  CURLINFO_HTTP_CODE...                                                   Old ...RESPONSE_CODE
+     d                 c                   X'00200002'
+      *
+     d curl_closepolicy...
+     d                 s             10i 0 based(######ptr######)               Enum
+     d  CURLCLOSEPOLICY_OLDEST...
+     d                 c                   1
+     d  CURLCLOSEPOLICY_LEAST_RECENTLY_USED...
+     d                 c                   2
+     d  CURLCLOSEPOLICY_LEAST_TRAFFIC...
+     d                 c                   3
+     d  CURLCLOSEPOLICY_SLOWEST...
+     d                 c                   4
+     d  CURLCLOSEPOLICY_CALLBACK...
+     d                 c                   5
+      *
+     d curl_lock_data...
+     d                 s             10i 0 based(######ptr######)               Enum
+     d  CURL_LOCK_DATA_NONE...
+     d                 c                   0
+     d  CURL_LOCK_DATA_SHARE...
+     d                 c                   1
+     d  CURL_LOCK_DATA_COOKIE...
+     d                 c                   2
+     d  CURL_LOCK_DATA_DNS...
+     d                 c                   3
+     d  CURL_LOCK_DATA_SSL_SESSION...
+     d                 c                   4
+     d  CURL_LOCK_DATA_CONNECT...
+     d                 c                   5
+     d  CURL_LOCK_DATA_LAST...
+     d                 c                   6
+      *
+     d curl_lock_access...
+     d                 s             10i 0 based(######ptr######)               Enum
+     d  CURL_LOCK_ACCESS_NONE...
+     d                 c                   0
+     d  CURL_LOCK_ACCESS_SHARED...
+     d                 c                   1
+     d  CURL_LOCK_ACCESS_SINGLE...
+     d                 c                   2
+      *
+     d curl_TimeCond   s             10i 0 based(######ptr######)               Enum
+     d  CURL_TIMECOND_NONE...
+     d                 c                   0
+     d  CURL_TIMECOND_IFMODSINCE...
+     d                 c                   1
+     d  CURL_TIMECOND_LASTMOD...
+     d                 c                   2
+     d  CURL_TIMECOND_LAST...
+     d                 c                   3
+      *
+     d CURLSHcode      s             10i 0 based(######ptr######)               Enum
+     d  CURLSHE_OK     c                   0
+     d  CURLSHE_BAD_OPTION...
+     d                 c                   1
+     d  CURLSHE_IN_USE...
+     d                 c                   2
+     d  CURLSHE_INVALID...
+     d                 c                   3
+     d  CURLSHE_NOMEM...
+     d                 c                   4
+      *
+     d CURLSHoption...
+     d                 s             10i 0 based(######ptr######)               Enum
+     d  CURLSHOPT_SHARE...
+     d                 c                   1
+     d  CURLSHOPT_UNSHARE...
+     d                 c                   2
+     d  CURLSHOPT_LOCKFUNC...
+     d                 c                   3
+     d  CURLSHOPT_UNLOCKFUNC...
+     d                 c                   4
+     d  CURLSHOPT_USERDATA...
+     d                 c                   5
+      *
+     d CURLversion     s             10i 0 based(######ptr######)               Enum
+     d  CURLVERSION_FIRST...
+     d                 c                   0
+     d  CURLVERSION_SECOND...
+     d                 c                   1
+     d  CURLVERSION_THIRD...
+     d                 c                   2
+     d  CURLVERSION_FOURTH...
+     d                 c                   3
+     d  CURLVERSION_NOW...
+     d                 c                   3                                    CURLVERSION_FOURTH
+      *
+     d curlsocktype    s             10i 0 based(######ptr######)               Enum
+     d  CURLSOCKTYPE_IPCXN...
+     d                 c                   0
+      *
+     d CURLMcode       s             10i 0 based(######ptr######)               Enum
+     d  CURLM_CALL_MULTI_PERFORM...
+     d                 c                   -1
+     d  CURLM_CALL_MULTI_SOCKET...
+     d                 c                   -1
+     d  CURLM_OK       c                   0
+     d  CURLM_BAD_HANDLE...
+     d                 c                   1
+     d  CURLM_BAD_EASY_HANDLE...
+     d                 c                   2
+     d  CURLM_OUT_OF_MEMORY...
+     d                 c                   3
+     d  CURLM_INTERNAL_ERROR...
+     d                 c                   4
+     d  CURLM_BAD_SOCKET...
+     d                 c                   5
+     d  CURLM_UNKNOWN_OPTION...
+     d                 c                   6
+     d  CURLM_LAST     c                   7
+      *
+     d CURLMSG         s             10i 0 based(######ptr######)               Enum
+     d  CURLMSG_NONE   c                   0
+     d  CURLMSG_DONE   c                   1
+      *
+     d CURLMoption     s             10i 0 based(######ptr######)               Enum
+     d  CURLMOPT_SOCKETFUNCTION...
+     d                 c                   20001
+     d  CURLMOPT_SOCKETDATA...
+     d                 c                   10002
+     d  CURLMOPT_PIPELINING...
+     d                 c                   00003
+     d  CURLMOPT_TIMERFUNCTION...
+     d                 c                   20004
+     d  CURLMOPT_TIMERDATA...
+     d                 c                   10005
+     d  CURLMOPT_MAXCONNECTS...
+     d                 c                   00006
+      *
+      *  Renaming CURLMsg to CURL_Msg to avoid case-insensivity name clash.
+      *
+     d CURL_Msg        ds                  based(######ptr######)
+     d                                     qualified
+     d  msg                                like(CURLMSG)
+     d  easy_handle                    *                                        CURL *
+     d  data                           *
+     d   whatever                      *   overlay(data)                        void *
+     d   result                            overlay(data) like(CURLcode)
+      *
+     d curl_http_post...
+     d                 ds                  based(######ptr######)
+     d                                     qualified
+     d  next                           *                                        curl_httppost *
+     d  name                           *                                        char *
+     d  namelength                   10i 0                                      long
+     d  contents                       *                                        char *
+     d  contentslength...
+     d                               10i 0                                      long
+     d  buffer                         *                                        char *
+     d  bufferlength...
+     d                               10i 0                                      long
+     d  contenttype                    *                                        char *
+     d  contentheader...
+     d                                 *                                        curl_slist *
+     d  more                           *                                        curl_httppost *
+     d  flags                        10i 0                                      long
+     d  showfilename                   *                                        char *
+      *
+     d curl_forms      ds                  based(######ptr######)
+     d                                     qualified
+     d  option                             like(CURLformoption)
+     d  value                          *                                        const char *
+     d   value_ptr                     *   overlay(value)
+     d   value_procptr...
+     d                                 *   overlay(value) procptr
+     d   value_long                  10i 0 overlay(value: 13)
+      *
+     d curl_slist      ds                  based(######ptr######)
+     d                                     qualified
+     d  data                           *                                        char *
+     d  next                           *                                        struct curl_slist *
+      *
+     d curl_info_version_data...
+     d                 ds                  based(######ptr######)
+     d                                     qualified
+     d  age                                like(CURLversion)
+     d  version                        *                                        const char *
+     d  version_num                  10u 0
+     d  host                           *                                        const char *
+     d  features                     10i 0
+     d  ssl_version                    *                                        const char *
+     d  ssl_version_num...
+     d                               10i 0                                      long
+     d  libz_version                   *                                        const char *
+     d  protocols                      *                                        const char * const *
+     d  ares                           *                                        const char *
+     d  ares_num                     10i 0
+     d  libidn                         *                                        const char *
+     d  iconv_ver_num...
+     d                               10i 0
+     d  libssh_version...
+     d                                 *                                        const char *
+      *
+     d curl_formget_callback...
+     d                 s               *   based(######ptr######) procptr
+      *
+     d curl_malloc_callback...
+     d                 s               *   based(######ptr######) procptr
+      *
+     d curl_free_callback...
+     d                 s               *   based(######ptr######) procptr
+      *
+     d curl_realloc_callback...
+     d                 s               *   based(######ptr######) procptr
+      *
+     d curl_strdup_callback...
+     d                 s               *   based(######ptr######) procptr
+      *
+     d curl_calloc_callback...
+     d                 s               *   based(######ptr######) procptr
+      *
+     d curl_lock_function...
+     d                 s               *   based(######ptr######) procptr
+      *
+     d curl_unlock_function...
+     d                 s               *   based(######ptr######) procptr
+      *
+     d curl_progress_callback...
+     d                 s               *   based(######ptr######) procptr
+      *
+     d curl_read_callback...
+     d                 s               *   based(######ptr######) procptr
+      *
+     d curl_sockopt_callback...
+     d                 s               *   based(######ptr######) procptr
+      *
+     d curl_ioctl_callback...
+     d                 s               *   based(######ptr######) procptr
+      *
+     d curl_debug_callback...
+     d                 s               *   based(######ptr######) procptr
+      *
+     d curl_conv_callback...
+     d                 s               *   based(######ptr######) procptr
+      *
+     d curl_ssl_ctx_callback...
+     d                 s               *   based(######ptr######) procptr
+      *
+     d curl_socket_callback...
+     d                 s               *   based(######ptr######) procptr
+      *
+      **************************************************************************
+      *                              Prototypes
+      **************************************************************************
+      *
+      *  This procedure as a variable parameter list.
+      *  This prototype allows use of an option array, or a single "object"
+      *    option. Other argument lists may be implemented by alias procedure
+      *    prototype definitions.
+      *
+     d curl_formadd    pr                  extproc('curl_formadd')
+     d                                     like(CURLFORMcode)
+     d  httppost                       *                                        curl_httppost *
+     d  lastpost                       *                                        curl_httppost *
+     d  option1                            value like(CURLFORMoption)           CURLFORM_ARRAY
+     d                                     options(*nopass)
+     d  object1                        *   value options(*string: *nopass)
+     d  option2                            value like(CURLFORMoption)           CURLFORM_END
+     d                                     options(*nopass)
+      *
+      *
+     d curl_strequal   pr            10i 0 extproc('curl_strequal')
+     d  s1                             *   value options(*string)
+     d  s2                             *   value options(*string)
+      *
+     d curl_strnequal  pr            10i 0 extproc('curl_strnequal')
+     d  s1                             *   value options(*string)
+     d  s2                             *   value options(*string)
+     d  n                            10i 0 value
+      *
+     d curl_formget    pr            10i 0 extproc('curl_formget')
+     d  form                           *   value                                curl_httppost *
+     d  arg                            *   value
+     d  append                             value like(curl_formget_callback)
+      *
+     d curl_formfree   pr                  extproc('curl_formfree')
+     d  form                           *   value                                curl_httppost *
+      *
+     d curl_getenv     pr              *   extproc('curl_getenv')
+     d  variable                       *   value options(*string)
+      *
+     d curl_version    pr              *   extproc('curl_version')
+      *
+     d curl_easy_escape...
+     d                 pr              *   extproc('curl_easy_escape')          char *
+     d  handle                         *   value                                CURL *
+     d  string                         *   value options(*string)
+     d  length                       10i 0 value
+      *
+     d curl_escape     pr              *   extproc('curl_escape')               char *
+     d  string                         *   value options(*string)
+     d  length                       10i 0 value
+      *
+     d curl_easy_unescape...
+     d                 pr              *   extproc('curl_easy_unescape')        char *
+     d  handle                         *   value                                CURL *
+     d  string                         *   value options(*string)
+     d  length                       10i 0 value
+     d  outlength                    10i 0 options(*omit)
+      *
+     d curl_unescape   pr              *   extproc('curl_unescape')             char *
+     d  string                         *   value options(*string)
+     d  length                       10i 0 value
+      *
+     d curl_free       pr                  extproc('curl_free')
+     d  p                              *   value
+      *
+     d curl_global_init...
+     d                 pr                  extproc('curl_global_init')
+     d                                     like(CURLcode)
+     d  flags                        10i 0 value
+      *
+     d curl_global_init_mem...
+     d                 pr                  extproc('curl_global_init_mem')
+     d                                     like(CURLcode)
+     d  m                                  value like(curl_malloc_callback)
+     d  f                                  value like(curl_free_callback)
+     d  r                                  value like(curl_realloc_callback)
+     d  s                                  value like(curl_strdup_callback)
+     d  c                                  value like(curl_calloc_callback)
+      *
+     d curl_global_cleanup...
+     d                 pr                  extproc('curl_global_cleanup')
+      *
+     d curl_slist_append...
+     d                 pr              *   extproc('curl_slist_append')         struct curl_slist *
+     d  list                           *   value                                struct curl_slist *
+     d  data                           *   value options(*string)               const char *
+      *
+     d curl_slist_free_all...
+     d                 pr                  extproc('curl_slist_free_all')
+     d  list                           *   value                                struct curl_slist *
+      *
+     d curl_getdate    pr            10i 0 extproc('curl_getdate')              time_t
+     d  p                              *   value options(*string)               const char *
+     d  unused                       10i 0 const options(*omit)                 time_t
+      *
+     d curl_share_init...
+     d                 pr              *   extproc('curl_share_init')           CURLSH * (= void *)
+      *
+      *  Variable argument type procedure.
+      *  Multiply prototyped to support all possible types.
+      *
+     d curl_share_setopt_int...
+     d                 pr                  extproc('curl_share_setopt')
+     d                                     like(CURLSHcode)
+     d  share                          *   value                                CURLSH * (= void *)
+     d  option                             value like(CURLSHoption)
+     d  intarg                       10i 0 value options(*nopass)
+      *
+     d curl_share_setopt_ptr...
+     d                 pr                  extproc('curl_share_setopt')
+     d                                     like(CURLSHcode)
+     d  share                          *   value                                CURLSH * (= void *)
+     d  option                             value like(CURLSHoption)
+     d  ptrarg                         *   value options(*nopass)
+      *
+     d curl_share_setopt_proc...
+     d                 pr                  extproc('curl_share_setopt')
+     d                                     like(CURLSHcode)
+     d  share                          *   value                                CURLSH * (= void *)
+     d  option                             value like(CURLSHoption)
+     d  procarg                        *   value procptr options(*nopass)
+      *
+     d curl_share_cleanup...
+     d                 pr                  extproc('curl_share_cleanup')
+     d                                     like(CURLSHcode)
+     d  share                          *   value                                CURLSH * (= void *)
+      *
+     d curl_version_info...
+     d                 pr              *   extproc('curl_version_info')         c_i_version_data *
+     d  version                            value like(CURLversion)
+      *
+     d curl_easy_strerror...
+     d                 pr              *   extproc('curl_easy_strerror')        const char *
+     d  code                               value like(CURLcode)
+      *
+     d curl_share_strerror...
+     d                 pr              *   extproc('curl_share_strerror')       const char *
+     d  code                               value like(CURLSHcode)
+      *
+     d curl_easy_init  pr              *   extproc('curl_easy_init')            CURL *
+      *
+      *  Multiple prototypes for vararg procedure curl_easy_setopt.
+      *
+     d curl_easy_setopt_long...
+     d                 pr                  extproc('curl_easy_setopt')
+     d                                     like(CURLcode)
+     d  curl                           *   value                                CURL *
+     d  option                             value like(CURLoption)
+     d  longarg                      10i 0 value options(*nopass)
+      *
+     d curl_easy_setopt_object...
+     d                 pr                  extproc('curl_easy_setopt')
+     d                                     like(CURLcode)
+     d  curl                           *   value                                CURL *
+     d  option                             value like(CURLoption)
+     d  objectarg                      *   value options(*string: *nopass)
+      *
+     d curl_easy_setopt_function...
+     d                 pr                  extproc('curl_easy_setopt')
+     d                                     like(CURLcode)
+     d  curl                           *   value                                CURL *
+     d  option                             value like(CURLoption)
+     d  functionarg                    *   value procptr options(*nopass)
+      *
+     d curl_easy_setopt_offset...
+     d                 pr                  extproc('curl_easy_setopt')
+     d                                     like(CURLcode)
+     d  curl                           *   value                                CURL *
+     d  option                             value like(CURLoption)
+     d  offsetarg                          value like(curl_off_t)
+     d                                     options(*nopass)
+      *
+      *
+     d curl_easy_perform...
+     d                 pr                  extproc('curl_easy_perform')
+     d                                     like(CURLcode)
+     d  curl                           *   value                                CURL *
+      *
+     d curl_easy_cleanup...
+     d                 pr                  extproc('curl_easy_cleanup')
+     d  curl                           *   value                                CURL *
+      *
+      *  Multiple prototypes for vararg procedure curl_easy_getinfo.
+      *
+     d curl_easy_getinfo_string...
+     d                 pr                  extproc('curl_easy_getinfo')
+     d                                     like(CURLcode)
+     d  curl                           *   value                                CURL *
+     d  info                               value like(CURLINFO)
+     d  stringarg                      *   options(*nopass)                     char *
+      *
+     d curl_easy_getinfo_long...
+     d                 pr                  extproc('curl_easy_getinfo')
+     d                                     like(CURLcode)
+     d  curl                           *   value                                CURL *
+     d  info                               value like(CURLINFO)
+     d  longarg                      10i 0 options(*nopass)
+      *
+     d curl_easy_getinfo_double...
+     d                 pr                  extproc('curl_easy_getinfo')
+     d                                     like(CURLcode)
+     d  curl                           *   value                                CURL *
+     d  info                               value like(CURLINFO)
+     d  doublearg                     8f   options(*nopass)
+      *
+     d curl_easy_getinfo_slist...
+     d                 pr                  extproc('curl_easy_getinfo')
+     d                                     like(CURLcode)
+     d  curl                           *   value                                CURL *
+     d  info                               value like(CURLINFO)
+     d  slistarg                       *   options(*nopass)                     struct curl_slist *
+      *
+      *
+     d curl_easy_duphandle...
+     d                 pr              *   extproc('curl_easy_duphandle')       CURL *
+     d  curl                           *   value                                CURL *
+      *
+     d curl_easy_reset...
+     d                 pr                  extproc('curl_easy_reset')
+     d  curl                           *   value                                CURL *
+      *
+     d curl_multi_init...
+     d                 pr              *   extproc('curl_multi_init')           CURLM *
+      *
+     d curl_multi_add_handle...
+     d                 pr                  extproc('curl_multi_add_handle')
+     d                                     like(CURLMcode)
+     d  multi_handle                   *   value                                CURLM *
+     d  curl_handle                    *   value                                CURL *
+      *
+     d curl_multi_remove_handle...
+     d                 pr                  extproc('curl_multi_remove_handle')
+     d                                     like(CURLMcode)
+     d  multi_handle                   *   value                                CURLM *
+     d  curl_handle                    *   value                                CURL *
+      *
+     d curl_multi_fdset...
+     d                 pr                  extproc('curl_multi_fdset')
+     d                                     like(CURLMcode)
+     d  multi_handle                   *   value                                CURLM *
+     d  read_fd_set               65535    options(*varsize)                    fd_set
+     d  write_fd_set              65535    options(*varsize)                    fd_set
+     d  exc_fd_set                65535    options(*varsize)                    fd_set
+     d  max_fd                       10i 0
+      *
+     d curl_multi_perform...
+     d                 pr                  extproc('curl_multi_perform')
+     d                                     like(CURLMcode)
+     d  multi_handle                   *   value                                CURLM *
+     d  running_handles...
+     d                               10i 0
+      *
+     d curl_multi_cleanup...
+     d                 pr                  extproc('curl_multi_cleanup')
+     d                                     like(CURLMcode)
+     d  multi_handle                   *   value                                CURLM *
+      *
+     d curl_multi_info_read...
+     d                 pr              *   extproc('curl_multi_info_read')      CURL_Msg *
+     d  multi_handle                   *   value                                CURLM *
+     d  msgs_in_queue                10i 0
+      *
+     d curl_multi_strerror...
+     d                 pr              *   extproc('curl_multi_strerror')       char *
+     d  code                               value like(CURLMcode)
+      *
+     d curl_multi_socket...
+     d                 pr                  extproc('curl_multi_socket')
+     d                                     like(CURLMcode)
+     d  multi_handle                   *   value                                CURLM *
+     d  s                                  value like(curl_socket_t)
+     d  running_handles...
+     d                               10i 0
+      *
+     d curl_multi_socket_action...
+     d                 pr                  extproc('curl_multi_socket_action')
+     d                                     like(CURLMcode)
+     d  multi_handle                   *   value                                CURLM *
+     d  s                                  value like(curl_socket_t)
+     d  ev_bitmask                   10i 0 value
+     d  running_handles...
+     d                               10i 0
+      *
+     d curl_multi_socket_all...
+     d                 pr                  extproc('curl_multi_socket_all')
+     d                                     like(CURLMcode)
+     d  multi_handle                   *   value                                CURLM *
+     d  running_handles...
+     d                               10i 0
+      *
+     d curl_multi_timeout...
+     d                 pr                  extproc('curl_multi_timeout')
+     d                                     like(CURLMcode)
+     d  multi_handle                   *   value                                CURLM *
+     d  milliseconds                 10i 0
+      *
+      *  Multiple prototypes for vararg procedure curl_multi_setopt.
+      *
+     d curl_multi_setopt_long...
+     d                 pr                  extproc('curl_multi_setopt')
+     d                                     like(CURLMcode)
+     d  multi_handle                   *   value                                CURLM *
+     d  option                             value like(CURLMoption)
+     d  longarg                      10i 0 value options(*nopass)
+      *
+     d curl_multi_setopt_object...
+     d                 pr                  extproc('curl_multi_setopt')
+     d                                     like(CURLMcode)
+     d  multi_handle                   *   value                                CURLM *
+     d  option                             value like(CURLMoption)
+     d  objectarg                      *   value options(*string: *nopass)
+      *
+     d curl_multi_setopt_function...
+     d                 pr                  extproc('curl_multi_setopt')
+     d                                     like(CURLMcode)
+     d  multi_handle                   *   value                                CURLM *
+     d  option                             value like(CURLMoption)
+     d  functionarg                    *   value procptr options(*nopass)
+      *
+     d curl_multi_setopt_offset...
+     d                 pr                  extproc('curl_multi_setopt')
+     d                                     like(CURLMcode)
+     d  multi_handle                   *   value                                CURLM *
+     d  option                             value like(CURLMoption)
+     d  offsetarg                          value like(curl_off_t)
+     d                                     options(*nopass)
+      *
+      *
+     d curl_multi_assign...
+     d                 pr                  extproc('curl_multi_assign')
+     d                                     like(CURLMcode)
+     d  multi_handle                   *   value                                CURLM *
+     d  sockfd                             value like(curl_socket_t)
+     d  sockp                          *   value                                void *
+      *
+      **************************************************************************
+      *                CCSID wrapper procedure prototypes
+      **************************************************************************
+      *
+     d curl_version_ccsid...
+     d                 pr              *   extproc('curl_version_ccsid')
+     d  ccsid                        10u 0 value
+      *
+     d curl_easy_escape_ccsid...
+     d                 pr              *   extproc('curl_easy_escape_ccsid')    char *
+     d  handle                         *   value                                CURL *
+     d  string                         *   value options(*string)
+     d  length                       10i 0 value
+     d  ccsid                        10u 0 value
+      *
+     d curl_easy_unescape_ccsid...
+     d                 pr              *   extproc('curl_easy_unescape_ccsid')  char *
+     d  handle                         *   value                                CURL *
+     d  string                         *   value options(*string)
+     d  length                       10i 0 value
+     d  outlength                    10i 0 options(*omit)
+     d  ccsid                        10u 0 value
+      *
+     d curl_slist_append_ccsid...
+     d                 pr              *   extproc('curl_slist_append_ccsid')   struct curl_slist *
+     d  list                           *   value                                struct curl_slist *
+     d  data                           *   value options(*string)               const char *
+     d  ccsid                        10u 0 value
+      *
+     d curl_getdate_ccsid...
+     d                 pr            10i 0 extproc('curl_getdate_ccsid')        time_t
+     d  p                              *   value options(*string)               const char *
+     d  unused                       10i 0 const options(*omit)                 time_t
+     d  ccsid                        10u 0 value
+      *
+     d curl_version_info_ccsid...
+     d                 pr              *   extproc('curl_version_info_ccsid')   c_i_version_data *
+     d  version                            value like(CURLversion)
+     d  ccsid                        10u 0 value
+      *
+     d curl_easy_strerror_ccsid...
+     d                 pr              *   extproc('curl_easy_strerror_ccsid')  const char *
+     d  code                               value like(CURLcode)
+     d  ccsid                        10u 0 value
+      *
+     d curl_share_strerror_ccsid...
+     d                 pr              *   extproc('curl_share_strerror_ccsid') const char *
+     d  code                               value like(CURLSHcode)
+     d  ccsid                        10u 0 value
+      *
+     d curl_multi_strerror_ccsid...
+     d                 pr              *   extproc('curl_multi_strerror_ccsid') char *
+     d  code                               value like(CURLMcode)
+     d  ccsid                        10u 0 value
+      *
+     d curl_easy_getinfo_ccsid...
+     d                 pr                  extproc('curl_easy_getinfo_ccsid')
+     d                                     like(CURLcode)
+     d  curl                           *   value                                CURL *
+     d  info                               value like(CURLINFO)
+     d  stringarg                      *   options(*nopass)                     char *
+     d  ccsid                        10u 0 value options(*nopass)
+      *
+     d curl_formadd_ccsid...
+     d                 pr                  extproc('curl_formadd_ccsid')
+     d                                     like(CURLFORMcode)
+     d  httppost                       *                                        curl_httppost *
+     d  lastpost                       *                                        curl_httppost *
+     d  option1                            value like(CURLFORMoption)           CURLFORM_ARRAY
+     d                                     options(*nopass)
+     d  object1                        *   value options(*string: *nopass)
+     d  option2                            value like(CURLFORMoption)           CURLFORM_END
+     d                                     options(*nopass)
+      *
+     d curl_formget_ccsid...
+     d                 pr            10i 0 extproc('curl_formget_ccsid')
+     d  form                           *   value                                curl_httppost *
+     d  arg                            *   value
+     d  append                             value like(curl_formget_callback)
+     d  ccsid                        10u 0 value
+      *
+     d curl_easy_setopt_ccsid...
+     d                 pr                  extproc('curl_easy_setopt_ccsid')
+     d                                     like(CURLcode)
+     d  curl                           *   value                                CURL *
+     d  option                             value like(CURLoption)
+     d  objectarg                      *   value options(*string: *nopass)
+     d  ccsid                        10u 0 value options(*nopass)
+      *
+      /endif
diff -Naur curl.orig/packages/OS400/initscript.sh curl/packages/OS400/initscript.sh
--- curl.orig/packages/OS400/initscript.sh	1970-01-01 01:00:00.000000000 +0100
+++ curl/packages/OS400/initscript.sh	2007-07-17 22:19:53.088339000 +0200
@@ -0,0 +1,167 @@
+#!/bin/sh
+
+case "${SCRIPTDIR}" in
+/*)     ;;
+*)      SCRIPTDIR="`pwd`/${SCRIPTDIR}"
+esac
+
+while true
+do      case "${SCRIPTDIR}" in
+        */.)    SCRIPTDIR="${SCRIPTDIR%/.}";;
+        *)      break;;
+        esac
+done
+
+#  The script directory is supposed to be in $TOPDIR/packages/os400.
+
+TOPDIR=`dirname "${SCRIPTDIR}"`
+TOPDIR=`dirname "${TOPDIR}"`
+export SCRIPTDIR TOPDIR
+
+
+################################################################################
+#
+#                       Tunable configuration parameters.
+#
+################################################################################
+
+TARGETLIB=CURL                  # Target OS/400 program library
+STATBNDDIR=CURL_A               # Static binding directory.
+DYNBNDDIR=CURL                  # Dynamic binding directory.
+SRVPGM=CURL                     # Service program.
+TGTCCSID=500                    # Target CCSID of objects
+DEBUG=*NONE                     # Debug level
+OPTIMIZE=40                     # Optimisation level
+OUTPUT=*NONE                    # Compilation output option.
+TGTRLS=V5R1M0                   # Target OS release
+
+export TARGETLIB STATBNDDIR DYNBNDDIR SRVPGM TGTCCSID DEBUG OPTIMIZE OUTPUTC
+export TGTRLS
+
+
+################################################################################
+
+#       Need to get the version definitions.
+
+LIBCURL_VERSION=`grep '^#define  *LIBCURL_VERSION '                     \
+                        "${TOPDIR}/include/curl/curlver.h"              |
+                sed 's/.*"\(.*\)".*/\1/'`
+LIBCURL_VERSION_MAJOR=`grep '^#define  *LIBCURL_VERSION_MAJOR '         \
+                        "${TOPDIR}/include/curl/curlver.h"              |
+                sed 's/^#define  *LIBCURL_VERSION_MAJOR  *\([^ ]*\).*/\1/'`
+LIBCURL_VERSION_MINOR=`grep '^#define  *LIBCURL_VERSION_MINOR '         \
+                        "${TOPDIR}/include/curl/curlver.h"              |
+                sed 's/^#define  *LIBCURL_VERSION_MINOR  *\([^ ]*\).*/\1/'`
+LIBCURL_VERSION_PATCH=`grep '^#define  *LIBCURL_VERSION_PATCH '         \
+                        "${TOPDIR}/include/curl/curlver.h"              |
+                sed 's/^#define  *LIBCURL_VERSION_PATCH  *\([^ ]*\).*/\1/'`
+LIBCURL_VERSION_NUM=`grep '^#define  *LIBCURL_VERSION_NUM '             \
+                        "${TOPDIR}/include/curl/curlver.h"              |
+                sed 's/^#define  *LIBCURL_VERSION_NUM  *0x\([^ ]*\).*/\1/'`
+LIBCURL_TIMESTAMP=`grep '^#define  *LIBCURL_TIMESTAMP '                 \
+                        "${TOPDIR}/include/curl/curlver.h"              |
+                sed 's/.*"\(.*\)".*/\1/'`
+export LIBCURL_VERSION
+export LIBCURL_VERSION_MAJOR LIBCURL_VERSION_MINOR LIBCURL_VERSION_PATCH
+export LIBCURL_VERSION_NUM LIBCURL_TIMESTAMP
+
+################################################################################
+#
+#                       OS/400 specific definitions.
+#
+################################################################################
+
+LIBIFSNAME="/QSYS.LIB/${TARGETLIB}.LIB"
+
+
+################################################################################
+#
+#                               Procedures.
+#
+################################################################################
+
+#       action_needed dest [src]
+#
+#       dest is an object to build
+#       if specified, src is an object on which dest depends.
+#
+#       exit 0 (succeeds) if some action has to be taken, else 1.
+
+action_needed()
+
+{
+        [ ! -e "${1}" ] && return 0
+        [ "${2}" ] || return 1
+        [ "${1}" -ot "${2}" ] && return 0
+        return 1
+}
+
+
+#       make_module module_name source_name [additional_definitions]
+#
+#       Compile source name into ASCII module if needed.
+#       As side effect, append the module name to variable MODULES.
+#       Set LINK to "YES" if the module has been compiled.
+
+make_module()
+
+{
+        MODULES="${MODULES} ${1}"
+        MODIFSNAME="${LIBIFSNAME}/${1}.MODULE"
+        action_needed "${MODIFSNAME}" "${2}" || return 0;
+
+        #       #pragma convert has to be in the source file itself, i.e.
+        #               putting it in an include file makes it only active
+        #               for that include file.
+        #       Thus we build a temporary file with the pragma prepended to
+        #               the source file and we compile that themporary file.
+
+        echo "#line 1 \"${2}\"" > __tmpsrcf.c
+        echo "#pragma convert(819)" >> __tmpsrcf.c
+        echo "#line 1" >> __tmpsrcf.c
+        cat "${2}" >> __tmpsrcf.c
+        CMD="CRTCMOD MODULE(${TARGETLIB}/${1}) SRCSTMF('__tmpsrcf.c')"
+#       CMD="${CMD} SYSIFCOPT(*IFSIO) OPTION(*INCDIRFIRST *SHOWINC *SHOWSYS)"
+        CMD="${CMD} SYSIFCOPT(*IFSIO) LOCALETYPE(*LOCALE) OPTION(*INCDIRFIRST)"
+        CMD="${CMD} INCDIR('/qibm/proddata/qadrt/include'"
+        CMD="${CMD} '${TOPDIR}/include/curl' '${TOPDIR}/include' ${INCLUDES})"
+        CMD="${CMD} TGTCCSID(${TGTCCSID}) TGTRLS(${TGTRLS})"
+        CMD="${CMD} OUTPUT(${OUTPUT})"
+        CMD="${CMD} OPTIMIZE(${OPTIMIZE})"
+        CMD="${CMD} DBGVIEW(${DEBUG})"
+
+        if [ "${3}" ]
+        then    CMD="${CMD} DEFINE(${3})"
+        fi
+
+        system "${CMD}"
+        rm -f __tmpsrcf.c
+        LINK=YES
+}
+
+
+#       Determine DB2 object name from IFS name.
+
+db2_name()
+
+{
+        basename "${1}"                                                 |
+        tr '[a-z]' '[A-Z]'                                              |
+        sed -e 's/\..*//'                                               \
+            -e 's/^\(..........\).*/\1/'
+}
+
+
+#       Copy IFS file replacing version info.
+
+versioned_copy()
+
+{
+        sed -e "s/@LIBCURL_VERSION@/${LIBCURL_VERSION}/g"               \
+            -e "s/@LIBCURL_VERSION_MAJOR@/${LIBCURL_VERSION_MAJOR}/g"   \
+            -e "s/@LIBCURL_VERSION_MINOR@/${LIBCURL_VERSION_MINOR}/g"   \
+            -e "s/@LIBCURL_VERSION_PATCH@/${LIBCURL_VERSION_PATCH}/g"   \
+            -e "s/@LIBCURL_VERSION_NUM@/${LIBCURL_VERSION_NUM}/g"       \
+            -e "s/@LIBCURL_TIMESTAMP@/${LIBCURL_TIMESTAMP}/g"           \
+                < "${1}" > "${2}"
+}
diff -Naur curl.orig/packages/OS400/make-include.sh curl/packages/OS400/make-include.sh
--- curl.orig/packages/OS400/make-include.sh	1970-01-01 01:00:00.000000000 +0100
+++ curl/packages/OS400/make-include.sh	2007-07-17 17:00:12.412577000 +0200
@@ -0,0 +1,46 @@
+#!/bin/sh
+#
+#       Installation of the include files in the OS/400 library.
+
+SCRIPTDIR=`dirname "${0}"`
+. "${SCRIPTDIR}/initscript.sh"
+cd "${TOPDIR}/include"
+
+
+#       Create the OS/400 source program file for the include files.
+
+SRCPF="${LIBIFSNAME}/H.FILE"
+
+if action_needed "${SRCPF}"
+then    CMD="CRTSRCPF FILE(${TARGETLIB}/H) RCDLEN(112)"
+        CMD="${CMD} TEXT('curl: Header files')"
+        system "${CMD}"
+fi
+
+
+#       Enumeration values are used as va_arg tagfields, so they MUST be
+#               integers.
+
+copy_hfile()
+
+{
+        sed -e '1i\
+#pragma enum(int)\
+' -e '$a\
+#pragma enum(pop)\
+' < "${2}" > "${1}"
+}
+
+#       Copy the header files.
+
+for HFILE in curl/*.h ${SCRIPTDIR}/ccsidcurl.h
+do      DEST="${SRCPF}/`db2_name \"${HFILE}\"`.MBR"
+        if action_needed "${DEST}" "${HFILE}"
+        then    copy_hfile "${DEST}" "${HFILE}"
+        fi
+done
+
+
+#       Copy the ILE/RPG include file, setting-up version number.
+
+        versioned_copy "${SCRIPTDIR}/curl.inc.in" "${SRCPF}/CURL.INC.MBR"
diff -Naur curl.orig/packages/OS400/make-lib.sh curl/packages/OS400/make-lib.sh
--- curl.orig/packages/OS400/make-lib.sh	1970-01-01 01:00:00.000000000 +0100
+++ curl/packages/OS400/make-lib.sh	2007-07-17 16:51:00.873193000 +0200
@@ -0,0 +1,206 @@
+#!/bin/sh
+#
+#       libcurl compilation script for the OS/400.
+
+SCRIPTDIR=`dirname "${0}"`
+. "${SCRIPTDIR}/initscript.sh"
+cd "${TOPDIR}/lib"
+
+
+#       Create ca-bundle.h file.
+
+if action_needed "ca-bundle.h"
+then    echo "/* This file is generated automatically */" > ca-bundle.h
+        echo "#ifndef CURL_CA_BUNDLE" >> ca-bundle.h
+
+        if [ "${CABUNDLE}" ]
+        then    echo '#define CURL_CA_BUNDLE @CURL_CA_BUNDLE@' >> ca-bundle.h
+        else    echo '#undef CURL_CA_BUNDLE /* unknown */' >> ca-bundle.h
+        fi
+
+        echo "#endif" >> ca-bundle.h
+fi
+
+
+#      Create and compile the identification source file.
+
+echo '#pragma comment(user, "libcurl version '"${LIBCURL_VERSION}"'")' > os400.c
+echo '#pragma comment(date)' >> os400.c
+echo '#pragma comment(copyright, "Copyright (C) 1998-2007 Daniel Stenberg et al.")' >> os400.c
+make_module     OS400           os400.c
+LINK=                           # No need to rebuild service program yet.
+MODULES=
+
+
+#       Get source list.
+
+CSOURCES()
+
+{
+        shift                   # Drop the equal sign.
+        CSOURCES="$*"           # Get the file names.
+}
+
+HHEADERS()
+
+{
+        shift                   # Drop the equal sign.
+        HHEADERS="$*"           # Get the file names.
+}
+
+. Makefile.inc
+
+
+#       Compile the sources into modules.
+
+INCLUDES="'`pwd`'"
+
+make_module     OS400SYS        "${SCRIPTDIR}/os400sys.c"
+make_module     CCSIDCURL       "${SCRIPTDIR}/ccsidcurl.c"
+make_module     QSSL            qssl.c
+
+for SRC in ${CSOURCES}
+do      MODULE=`basename "${SRC}" .c |
+                tr '[a-z]' '[A-Z]'   |
+                sed -e 's/^\(..........\).*/\1/'`
+        make_module "${MODULE}" "${SRC}"
+done
+
+
+#       If needed, (re)create the static binding directory.
+
+if action_needed "${LIBIFSNAME}/${STATBNDDIR}.BNDDIR"
+then    LINK=YES
+fi
+
+if [ "${LINK}" ]
+then    rm -rf "${LIBIFSNAME}/${STATBNDDIR}.BNDDIR"
+        CMD="CRTBNDDIR BNDDIR(${TARGETLIB}/${STATBNDDIR})"
+        CMD="${CMD} TEXT('LibCurl API static binding directory')"
+        system "${CMD}"
+
+        for MODULE in ${MODULES}
+        do      CMD="ADDBNDDIRE BNDDIR(${TARGETLIB}/${STATBNDDIR})"
+                CMD="${CMD} OBJ((${TARGETLIB}/${MODULE} *MODULE))"
+                system "${CMD}"
+        done
+fi
+
+
+#       The exportation file for service program creation must be in a DB2
+#               source file, so make sure it exists.
+
+if action_needed "${LIBIFSNAME}/TOOLS.FILE"
+then    CMD="CRTSRCPF FILE(${TARGETLIB}/TOOLS) RCDLEN(112)"
+        CMD="${CMD} TEXT('curl: build tools')"
+        system "${CMD}"
+fi
+
+
+#       Gather the list of symbols to export.
+
+EXPORTS=`grep '^CURL_EXTERN[ 	]'                                      \
+              "${TOPDIR}"/include/curl/*.h                              \
+              "${SCRIPTDIR}/ccsidcurl.h"                                |
+         sed -e 's/^.*CURL_EXTERN[ 	]\(.*\)(.*$/\1/'                \
+             -e 's/[ 	]*$//'                                          \
+             -e 's/^.*[ 	][ 	]*//'                           \
+             -e 's/^\*//'                                               \
+             -e 's/(\(.*\))/\1/'`
+
+#       Create the service program exportation file in DB2 member if needed.
+
+BSF="${LIBIFSNAME}/TOOLS.FILE/BNDSRC.MBR"
+
+if action_needed "${BSF}"
+then    LINK=YES
+fi
+
+if [ "${LINK}" ]
+then    echo " STRPGMEXP PGMLVL(*CURRENT) SIGNATURE('LIBCURL')" > "${BSF}"
+        for EXPORT in ${EXPORTS}
+        do      echo ' EXPORT    SYMBOL("'"${EXPORT}"'")' >> "${BSF}"
+        done
+
+        echo ' ENDPGMEXP' >> "${BSF}"
+fi
+
+
+#       Build the service program if needed.
+
+if action_needed "${LIBIFSNAME}/${SRVPGM}.SRVPGM"
+then    LINK=YES
+fi
+
+if [ "${LINK}" ]
+then    CMD="CRTSRVPGM SRVPGM(${TARGETLIB}/${SRVPGM})"
+        CMD="${CMD} SRCFILE(${TARGETLIB}/TOOLS) SRCMBR(BNDSRC)"
+        CMD="${CMD} MODULE(${TARGETLIB}/OS400)"
+        CMD="${CMD} BNDDIR(${TARGETLIB}/${STATBNDDIR})"
+        CMD="${CMD} BNDSRVPGM(QADRTTS)"
+        CMD="${CMD} TEXT('curl API library')"
+        CMD="${CMD} TGTRLS(${TGTRLS})"
+        system "${CMD}"
+        LINK=YES
+fi
+
+
+#       If needed, (re)create the dynamic binding directory.
+
+if action_needed "${LIBIFSNAME}/${DYNBNDDIR}.BNDDIR"
+then    LINK=YES
+fi
+
+if [ "${LINK}" ]
+then    rm -rf "${LIBIFSNAME}/${DYNBNDDIR}.BNDDIR"
+        CMD="CRTBNDDIR BNDDIR(${TARGETLIB}/${DYNBNDDIR})"
+        CMD="${CMD} TEXT('LibCurl API dynamic binding directory')"
+        system "${CMD}"
+        CMD="ADDBNDDIRE BNDDIR(${TARGETLIB}/${DYNBNDDIR})"
+        CMD="${CMD} OBJ((*LIBL/${SRVPGM} *SRVPGM))"
+        system "${CMD}"
+fi
+
+
+#       Rebuild the formdata test if needed.
+
+if [ "${TEST_FORMDATA}" ]
+then    MODULES=
+        make_module TFORMDATA   formdata.c      "'_FORM_DEBUG' 'CURLDEBUG'"
+        make_module TSTREQUAL   strequal.c      "'_FORM_DEBUG' 'CURLDEBUG'"
+        make_module TMEMDEBUG   memdebug.c      "'_FORM_DEBUG' 'CURLDEBUG'"
+        make_module TMPRINTF    mprintf.c       "'_FORM_DEBUG' 'CURLDEBUG'"
+        make_module TSTRERROR   strerror.c      "'_FORM_DEBUG' 'CURLDEBUG'"
+        #       The following modules should not be needed (see comment in
+        #               formdata.c. However, there are some unsatisfied
+        #               external references leading in the following
+        #               modules to be (recursively) needed.
+        MODULES="${MODULES} EASY STRDUP SSLGEN QSSL HOSTIP HOSTIP4 HOSTIP6"
+        MODULES="${MODULES} URL HASH TRANSFER GETINFO COOKIE SENDF SELECT"
+        MODULES="${MODULES} INET_NTOP SHARE HOSTTHRE MULTI LLIST FTP HTTP"
+        MODULES="${MODULES} HTTP_DIGES HTTP_CHUNK HTTP_NEGOT TIMEVAL HOSTSYN"
+        MODULES="${MODULES} CONNECT SOCKS PROGRESS ESCAPE INET_PTON GETENV"
+        MODULES="${MODULES} DICT LDAP TELNET FILE TFTP NETRC PARSEDATE"
+        MODULES="${MODULES} SPEEDCHECK SPLAY BASE64 SECURITY IF2IP MD5"
+        MODULES="${MODULES} KRB5 OS400SYS"
+
+        PGMIFSNAME="${LIBIFSNAME}/TFORMDATA.PGM"
+
+        if action_needed "${PGMIFSNAME}"
+        then    LINK=YES
+        fi
+
+        if [ "${LINK}" ]
+        then    CMD="CRTPGM PGM(${TARGETLIB}/TFORMDATA)"
+                CMD="${CMD} ENTMOD(QADRT/QADRTMAIN2)"
+                CMD="${CMD} MODULE("
+
+                for MODULE in ${MODULES}
+                do      CMD="${CMD} ${TARGETLIB}/${MODULE}"
+                done
+
+                CMD="${CMD} ) BNDSRVPGM(QADRTTS)"
+                CMD="${CMD} TGTRLS(${TGTRLS})"
+                system "${CMD}"
+        fi
+fi
diff -Naur curl.orig/packages/OS400/make-src.sh curl/packages/OS400/make-src.sh
--- curl.orig/packages/OS400/make-src.sh	1970-01-01 01:00:00.000000000 +0100
+++ curl/packages/OS400/make-src.sh	2007-06-14 22:43:49.315232000 +0200
@@ -0,0 +1,3 @@
+#!/bin/sh
+#
+#       Not implemented yet on OS/400.
diff -Naur curl.orig/packages/OS400/make-tests.sh curl/packages/OS400/make-tests.sh
--- curl.orig/packages/OS400/make-tests.sh	1970-01-01 01:00:00.000000000 +0100
+++ curl/packages/OS400/make-tests.sh	2007-07-17 16:50:17.155282000 +0200
@@ -0,0 +1,76 @@
+#!/bin/sh
+#
+#       tests compilation script for the OS/400.
+
+
+SCRIPTDIR=`dirname "${0}"`
+. "${SCRIPTDIR}/initscript.sh"
+cd "${TOPDIR}/tests"
+
+
+#       tests directory not implemented yet.
+
+
+#       Process the libtest subdirectory.
+
+cd libtest
+
+
+make_program()
+
+{
+        make_module "${1}" "${2}" "${4}"
+        MODIFSNAME="${LIBIFSNAME}/${1}.MODULE"
+        PGMIFSNAME="${LIBIFSNAME}/${1}.PGM"
+        action_needed "${PGMIFSNAME}" "${MODIFSNAME}" || return 0
+        CMD="CRTPGM PGM(${TARGETLIB}/${1}) ENTMOD(QADRT/QADRTMAIN2)"
+        CMD="${CMD} MODULE(${TARGETLIB}/${1} ${TARGETLIB}/FIRST ${3})"
+        CMD="${CMD} BNDSRVPGM(${TARGETLIB}/${SRVPGM} QADRTTS)"
+        CMD="${CMD} TGTRLS(${TGTRLS})"
+        system "${CMD}"
+}
+
+
+INCLUDES="'${TOPDIR}/tests/libtest' '${TOPDIR}/lib'"
+
+
+#       Compile the multi-usage modules.
+
+make_module     FIRST           first.c
+make_module     TESTUTIL        testutil.c
+
+#       Build the test programs.
+
+make_program    LIB500  lib500.c
+make_program    LIB501  lib501.c
+make_program    LIB502  lib502.c        "${TARGETLIB}/TESTUTIL"
+make_program    LIB503  lib503.c        "${TARGETLIB}/TESTUTIL"
+make_program    LIB504  lib504.c        "${TARGETLIB}/TESTUTIL"
+make_program    LIB505  lib505.c
+make_program    LIB506  lib506.c
+make_program    LIB507  lib507.c        "${TARGETLIB}/TESTUTIL"
+make_program    LIB508  lib508.c
+make_program    LIB509  lib509.c        "${TARGETLIB}/TESTUTIL"
+make_program    LIB510  lib510.c
+make_program    LIB511  lib511.c
+make_program    LIB512  lib512.c
+make_program    LIB513  lib513.c
+make_program    LIB514  lib514.c
+make_program    LIB515  lib515.c
+make_program    LIB516  lib516.c
+make_program    LIB517  lib517.c
+make_program    LIB518  lib518.c
+make_program    LIB519  lib519.c
+make_program    LIB520  lib520.c
+make_program    LIB521  lib521.c
+make_program    LIB523  lib523.c
+make_program    LIB524  lib524.c
+make_program    LIB525  lib525.c        "${TARGETLIB}/TESTUTIL"
+make_program    LIB526  lib526.c        "${TARGETLIB}/TESTUTIL"         LIB526
+make_program    LIB527  lib526.c        "${TARGETLIB}/TESTUTIL"         LIB527
+make_program    LIB529  lib525.c        "${TARGETLIB}/TESTUTIL"         LIB529
+make_program    LIB530  lib530.c        "${TARGETLIB}/TESTUTIL"         LIB530
+make_program    LIB532  lib526.c        "${TARGETLIB}/TESTUTIL"         LIB532
+make_program    LIB533  lib533.c        "${TARGETLIB}/TESTUTIL"
+make_program    LIB536  lib536.c        "${TARGETLIB}/TESTUTIL"
+make_program    LIB537  lib537.c
diff -Naur curl.orig/packages/OS400/makefile.sh curl/packages/OS400/makefile.sh
--- curl.orig/packages/OS400/makefile.sh	1970-01-01 01:00:00.000000000 +0100
+++ curl/packages/OS400/makefile.sh	2007-07-17 16:51:54.231543000 +0200
@@ -0,0 +1,24 @@
+#!/bin/sh
+#
+#       curl compilation script for the OS/400.
+#
+#       This is a shell script since make is not a standard component of OS/400.
+
+SCRIPTDIR=`dirname "${0}"`
+. "${SCRIPTDIR}/initscript.sh"
+cd "${TOPDIR}"
+
+
+#       Create the OS/400 library if it does not exist.
+
+if action_needed "${LIBIFSNAME}"
+then    CMD="CRTLIB LIB(${TARGETLIB}) TEXT('curl: multiprotocol support API')"
+        system "${CMD}"
+fi
+
+
+#       Build in each directory.
+
+for SUBDIR in include lib src tests
+do      "${SCRIPTDIR}/make-${SUBDIR}.sh"
+done
diff -Naur curl.orig/packages/OS400/os400sys.c curl/packages/OS400/os400sys.c
--- curl.orig/packages/OS400/os400sys.c	1970-01-01 01:00:00.000000000 +0100
+++ curl/packages/OS400/os400sys.c	2007-07-06 12:26:22.275742000 +0200
@@ -0,0 +1,460 @@
+/***************************************************************************
+ *                                  _   _ ____  _
+ *  Project                     ___| | | |  _ \| |
+ *                             / __| | | | |_) | |
+ *                            | (__| |_| |  _ <| |___
+ *                             \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ***************************************************************************/
+
+/* OS/400 additional support. */
+
+#include <sys/socket.h>
+
+#include <stdlib.h>
+#include <netdb.h>
+#include <qadrt.h>
+#include <errno.h>
+#include <qsossl.h>
+#include <gssapi.h>
+
+
+/**
+***     OS/400 defines procedures getaddrinfo() and getnameinfo(), but
+***             these are not implemented in the ASCII runtime. We provide
+***             here wrappers for these.
+**/
+
+
+int
+Curl_getnameinfo_a(const struct sockaddr * sa, socklen_t salen,
+              char * nodename, socklen_t nodenamelen,
+              char * servname, socklen_t servnamelen,
+              int flags)
+
+{
+  char * enodename;
+  char * eservname;
+  int status;
+  int i;
+
+  enodename = (char *) NULL;
+  eservname = (char *) NULL;
+
+  if (nodename && nodenamelen)
+    if (!(enodename = malloc(nodenamelen)))
+      return EAI_MEMORY;
+
+  if (servname && servnamelen)
+    if (!(eservname = malloc(servnamelen))) {
+      if (enodename)
+        free(enodename);
+
+      return EAI_MEMORY;
+      }
+
+  status = getnameinfo(sa, salen, enodename, nodenamelen,
+                       eservname, servnamelen, flags);
+
+  if (!status) {
+    if (enodename) {
+      i = strlen(enodename) + 1;
+      QadrtConvertE2A(nodename, enodename, nodenamelen, i);
+      nodename[i] = '\0';
+      }
+
+    if (eservname) {
+      i = strlen(eservname) + 1;
+      QadrtConvertE2A(servname, eservname, servnamelen, i);
+      servname[i] = '\0';
+      }
+    }
+
+  if (enodename)
+    free(enodename);
+
+  if (eservname)
+    free(eservname);
+
+  return status;
+}
+
+
+int
+Curl_getaddrinfo_a(const char * nodename, const char * servname,
+            const struct addrinfo * hints,
+            struct addrinfo * * res)
+
+{
+  char * enodename;
+  char * eservname;
+  int status;
+  int i;
+
+  enodename = (char *) NULL;
+  eservname = (char *) NULL;
+
+  if (nodename) {
+    i = strlen(nodename) + 1;
+
+    if (!(enodename = malloc(i)))
+      return EAI_MEMORY;
+
+    QadrtConvertA2E(enodename, nodename, i, i);
+    enodename[i] = '\0';
+    }
+
+  if (servname) {
+    i = strlen(servname) + 1;
+
+    if (!(eservname = malloc(i))) {
+      if (enodename)
+        free(enodename);
+
+      return EAI_MEMORY;
+      }
+
+    QadrtConvertA2E(eservname, servname, i, i);
+    eservname[i] = '\0';
+    }
+
+  status = getaddrinfo(enodename, eservname, hints, res);
+
+  if (enodename)
+    free(enodename);
+
+  if (eservname)
+    free(eservname);
+
+  return status;
+}
+
+
+int
+Curl_inet_ntoa_r_a(struct in_addr internet_address,
+                   char * output_buffer, int output_buffer_length)
+
+{
+  int rc;
+  int i;
+  char * cp;
+
+  if (!output_buffer || output_buffer_length < 16)
+    return inet_ntoa_r(internet_address, output_buffer, output_buffer_length);
+
+  if (!(cp = malloc(output_buffer_length + 1)))
+    return -1;
+
+  rc = inet_ntoa_r(internet_address, cp, output_buffer_length);
+
+  if (rc) {
+    free(cp);
+    return rc;
+    }
+
+  cp[output_buffer_length - 1] = '\0';
+  i = strlen(cp);
+  QadrtConvertE2A(output_buffer, cp, i, i);
+  output_buffer[i] = '\0';
+  free(cp);
+  return rc;
+}
+
+
+/* ASCII wrappers for the SSL procedures. */
+
+int
+Curl_SSL_Init_Application_a(SSLInitApp * init_app)
+
+{
+  int rc;
+  unsigned int i;
+  SSLInitApp ia;
+
+  if (!init_app || !init_app->applicationID || !init_app->applicationIDLen)
+    return SSL_Init_Application(init_app);
+
+  memcpy((char *) &ia, (char *) init_app, sizeof ia);
+  i = ia.applicationIDLen;
+
+  if (!(ia.applicationID = malloc(i + 1))) {
+    errno = ENOMEM;
+    return SSL_ERROR_IO;
+    }
+
+  QadrtConvertA2E(ia.applicationID, init_app->applicationID, i, i);
+  ia.applicationID[i] = '\0';
+  rc = SSL_Init_Application(&ia);
+  free(ia.applicationID);
+  init_app->localCertificateLen = ia.localCertificateLen;
+  init_app->sessionType = ia.sessionType;
+  return rc;
+}
+
+
+int
+Curl_SSL_Init_a(SSLInit * init)
+
+{
+  int rc;
+  unsigned int i;
+  SSLInit ia;
+
+  if (!init || (!init->keyringFileName && !init->keyringPassword))
+    return SSL_Init(init);
+
+  memcpy((char *) &ia, (char *) init, sizeof ia);
+
+  if (ia.keyringFileName) {
+    i = strlen(ia.keyringFileName);
+
+    if (!(ia.keyringFileName = malloc(i + 1))) {
+      errno = ENOMEM;
+      return SSL_ERROR_IO;
+      }
+
+    QadrtConvertA2E(ia.keyringFileName, init->keyringFileName, i, i);
+    ia.keyringFileName[i] = '\0';
+    }
+
+  if (ia.keyringPassword) {
+    i = strlen(ia.keyringPassword);
+
+    if (!(ia.keyringPassword = malloc(i + 1))) {
+      if (ia.keyringFileName)
+        free(ia.keyringFileName);
+
+      errno = ENOMEM;
+      return SSL_ERROR_IO;
+      }
+
+    QadrtConvertA2E(ia.keyringPassword, init->keyringPassword, i, i);
+    ia.keyringPassword[i] = '\0';
+    }
+
+  rc = SSL_Init(&ia);
+
+  if (ia.keyringFileName)
+    free(ia.keyringFileName);
+
+  if (ia.keyringPassword)
+    free(ia.keyringPassword);
+
+  return rc;
+}
+
+
+char *
+Curl_SSL_Strerror_a(int sslreturnvalue, SSLErrorMsg * serrmsgp)
+
+{
+  int i;
+  char * cp;
+  char * cp2;
+
+  cp = SSL_Strerror(sslreturnvalue, serrmsgp);
+
+  if (!cp)
+    return cp;
+
+  i = strlen(cp);
+
+  if (!(cp2 = malloc(i + 1)))
+    return cp2;
+
+  QadrtConvertE2A(cp2, cp, i, i);
+
+  /* Overwrite the EBCDIC buffer with ASCII to return it, because it is
+     threadsafe. */
+
+  strcpy(cp, cp2);
+  free(cp2);
+  return cp;
+}
+
+
+/* ASCII wrappers for the GSSAPI procedures. */
+
+OM_uint32
+Curl_gss_import_name_a(OM_uint32 * minor_status, gss_buffer_t in_name,
+                       gss_OID in_name_type, gss_name_t * out_name)
+
+{
+  int rc;
+  unsigned int i;
+  gss_buffer_desc in;
+
+  if (!in_name || !in_name->value || !in_name->length)
+    return gss_import_name(minor_status, in_name, in_name_type, out_name);
+
+  memcpy((char *) &in, (char *) in_name, sizeof in);
+  i = in.length;
+
+  if (!(in.value = malloc(i + 1))) {
+    if (minor_status)
+      *minor_status = ENOMEM;
+
+    return GSS_S_FAILURE;
+    }
+
+  QadrtConvertA2E(in.value, in_name->value, i, i);
+  ((char *) in.value)[i] = '\0';
+  rc = gss_import_name(minor_status, &in, in_name_type, out_name);
+  free(in.value);
+  return rc;
+}
+
+
+OM_uint32
+Curl_gss_display_status_a(OM_uint32 * minor_status, OM_uint32 status_value,
+                   int status_type, gss_OID mech_type,
+                   gss_msg_ctx_t * message_context, gss_buffer_t status_string)
+
+{
+  int rc;
+  unsigned int i;
+  char * t;
+
+  rc = gss_display_status(minor_status, status_value, status_type,
+                              mech_type, message_context, status_string);
+
+  if (rc != GSS_S_COMPLETE || !status_string ||
+      !status_string->length || !status_string->value)
+    return rc;
+
+  i = status_string->length;
+
+  if (!(t = malloc(i + 1))) {
+    gss_release_buffer(minor_status, status_string);
+
+    if (minor_status)
+      *minor_status = ENOMEM;
+
+    return GSS_S_FAILURE;
+    }
+
+  QadrtConvertE2A(t, status_string->value, i, i);
+  t[i] = '\0';
+  gss_release_buffer(minor_status, status_string);
+  status_string->value = t;
+  status_string->length = i;
+  return rc;
+}
+
+
+OM_uint32
+Curl_gss_init_sec_context_a(OM_uint32 * minor_status, gss_cred_id_t cred_handle,
+                            gss_ctx_id_t * context_handle,
+                            gss_name_t target_name, gss_OID mech_type,
+                            gss_flags_t req_flags, OM_uint32 time_req,
+                            gss_channel_bindings_t input_chan_bindings,
+                            gss_buffer_t input_token,
+                            gss_OID * actual_mech_type,
+                            gss_buffer_t output_token, gss_flags_t * ret_flags,
+                            OM_uint32 * time_rec)
+
+{
+  int rc;
+  unsigned int i;
+  gss_buffer_desc in;
+  gss_buffer_t inp;
+  char * t;
+
+  in.value = NULL;
+
+  if ((inp = input_token))
+    if (inp->length && inp->value) {
+      i = inp->length;
+
+      if (!(in.value = malloc(i + 1))) {
+        if (minor_status)
+          *minor_status = ENOMEM;
+
+        return GSS_S_FAILURE;
+        }
+
+      QadrtConvertA2E(in.value, input_token->value, i, i);
+      ((char *) in.value)[i] = '\0';
+      in.length = i;
+      inp = &in;
+      }
+
+  rc = gss_init_sec_context(minor_status, cred_handle, context_handle,
+                             target_name, mech_type, req_flags, time_req,
+                             input_chan_bindings, inp, actual_mech_type,
+                             output_token, ret_flags, time_rec);
+
+  if (in.value)
+    free(in.value);
+
+  if (rc != GSS_S_COMPLETE || !output_token ||
+      !output_token->length || !output_token->value)
+    return rc;
+
+  i = output_token->length;
+
+  if (!(t = malloc(i + 1))) {
+    gss_release_buffer(minor_status, output_token);
+
+    if (minor_status)
+      *minor_status = ENOMEM;
+
+    return GSS_S_FAILURE;
+    }
+
+  QadrtConvertE2A(t, output_token->value, i, i);
+  t[i] = '\0';
+  gss_release_buffer(minor_status, output_token);
+  output_token->value = t;
+  output_token->length = i;
+  return rc;
+}
+
+
+OM_uint32
+Curl_gss_delete_sec_context_a(OM_uint32 * minor_status,
+                              gss_ctx_id_t * context_handle,
+                              gss_buffer_t output_token)
+
+{
+  int rc;
+  unsigned int i;
+  char * t;
+
+  rc = gss_delete_sec_context(minor_status, context_handle, output_token);
+
+  if (rc != GSS_S_COMPLETE || !output_token ||
+      !output_token->length || !output_token->value)
+    return rc;
+
+  i = output_token->length;
+
+  if (!(t = malloc(i + 1))) {
+    gss_release_buffer(minor_status, output_token);
+
+    if (minor_status)
+      *minor_status = ENOMEM;
+
+    return GSS_S_FAILURE;
+    }
+
+  QadrtConvertE2A(t, output_token->value, i, i);
+  t[i] = '\0';
+  gss_release_buffer(minor_status, output_token);
+  output_token->value = t;
+  output_token->length = i;
+  return rc;
+}
diff -Naur curl.orig/tests/libtest/lib506.c curl/tests/libtest/lib506.c
--- curl.orig/tests/libtest/lib506.c	2007-02-04 13:12:02.000000000 +0100
+++ curl/tests/libtest/lib506.c	2007-06-15 12:26:25.142201000 +0200
@@ -19,9 +19,9 @@
 const char *JAR = "log/jar506";
 #define THREADS 2
 
-void lock(CURL *handle, curl_lock_data data, curl_lock_access access,
+void my_lock(CURL *handle, curl_lock_data data, curl_lock_access access,
           void *useptr );
-void unlock(CURL *handle, curl_lock_data data, void *useptr );
+void my_unlock(CURL *handle, curl_lock_data data, void *useptr );
 struct curl_slist *sethost(struct curl_slist *headers);
 void *fire(void *ptr);
 char *suburl(const char *base, int i);
@@ -38,7 +38,7 @@
 };
 
 /* lock callback */
-void lock(CURL *handle, curl_lock_data data, curl_lock_access access,
+void my_lock(CURL *handle, curl_lock_data data, curl_lock_access access,
           void *useptr )
 {
   const char *what;
@@ -66,7 +66,7 @@
 }
 
 /* unlock callback */
-void unlock(CURL *handle, curl_lock_data data, void *useptr )
+void my_unlock(CURL *handle, curl_lock_data data, void *useptr )
 {
   const char *what;
   struct userdata *user = (struct userdata *)useptr;
@@ -173,11 +173,11 @@
 
   if ( CURLSHE_OK == scode ) {
     printf( "CURLSHOPT_LOCKFUNC\n" );
-    scode = curl_share_setopt( share, CURLSHOPT_LOCKFUNC, lock);
+    scode = curl_share_setopt( share, CURLSHOPT_LOCKFUNC, my_lock);
   }
   if ( CURLSHE_OK == scode ) {
     printf( "CURLSHOPT_UNLOCKFUNC\n" );
-    scode = curl_share_setopt( share, CURLSHOPT_UNLOCKFUNC, unlock);
+    scode = curl_share_setopt( share, CURLSHOPT_UNLOCKFUNC, my_unlock);
   }
   if ( CURLSHE_OK == scode ) {
     printf( "CURLSHOPT_USERDATA\n" );
