Base code merged to SPIN 2.4
[platform/upstream/curl.git] / packages / OS400 / ccsidcurl.c
index 34ca8dc..d0e6827 100644 (file)
@@ -5,7 +5,7 @@
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2014, 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
@@ -167,7 +167,6 @@ dynconvert(int dccsid, const char * s, int slen, int sccsid)
   char * cp;
   size_t dlen;
   int l;
-  int l2;
   static const char nullbyte = 0;
 
   /* Like convert, but the destination is allocated and returned. */
@@ -191,7 +190,7 @@ dynconvert(int dccsid, const char * s, int slen, int sccsid)
        Since destination code size is unknown, use a conversion to generate
        terminator. */
 
-    l2 = convert(d + l, dlen - l, dccsid, &nullbyte, -1, ASCII_CCSID);
+    int l2 = convert(d + l, dlen - l, dccsid, &nullbyte, -1, ASCII_CCSID);
 
     if(l2 < 0) {
       free(d);
@@ -217,10 +216,11 @@ slist_convert(int dccsid, struct curl_slist * from, int sccsid)
 
 {
   struct curl_slist * to = (struct curl_slist *) NULL;
-  char * cp;
 
   for(; from; from = from->next) {
-    if(!(cp = dynconvert(dccsid, from->data, -1, sccsid))) {
+    char * cp = dynconvert(dccsid, from->data, -1, sccsid);
+
+    if(!cp) {
       curl_slist_free_all(to);
       return (struct curl_slist *) NULL;
     }
@@ -269,7 +269,7 @@ curl_easy_escape_ccsid(CURL * handle, const char * string, int length,
     return (char *) NULL;
     }
 
-  s = dynconvert(ASCII_CCSID, s, length? length: -1, sccsid);
+  s = dynconvert(ASCII_CCSID, string, length? length: -1, sccsid);
 
   if(!s)
     return (char *) NULL;
@@ -300,7 +300,7 @@ curl_easy_unescape_ccsid(CURL * handle, const char * string, int length,
     return (char *) NULL;
     }
 
-  s = dynconvert(ASCII_CCSID, s, length? length: -1, sccsid);
+  s = dynconvert(ASCII_CCSID, string, length? length: -1, sccsid);
 
   if(!s)
     return (char *) NULL;
@@ -370,15 +370,13 @@ convert_version_info_string(const char * * stringp,
                             char * * bufp, int * left, unsigned int ccsid)
 
 {
-  int l;
-
   /* Helper for curl_version_info_ccsid(): convert a string if defined.
      Result is stored in the `*left'-byte buffer at `*bufp'.
      `*bufp' and `*left' are updated accordingly.
      Return 0 if ok, else -1. */
 
   if(*stringp) {
-    l = convert(*bufp, *left, ccsid, *stringp, -1, ASCII_CCSID);
+    int l = convert(*bufp, *left, ccsid, *stringp, -1, ASCII_CCSID);
 
     if(l <= 0)
       return -1;
@@ -400,7 +398,6 @@ curl_version_info_ccsid(CURLversion stamp, unsigned int ccsid)
   char * cp;
   int n;
   int nproto;
-  int i;
   curl_version_info_data * id;
 
   /* The assertion below is possible, because although the second operand
@@ -473,8 +470,9 @@ curl_version_info_ccsid(CURLversion stamp, unsigned int ccsid)
   memcpy((char *) id, (char *) p, sizeof *p);
 
   if(id->protocols) {
+    int i = nproto * sizeof id->protocols[0];
+
     id->protocols = (const char * const *) cp;
-    i = nproto * sizeof id->protocols[0];
     memcpy(cp, (char *) p->protocols, i);
     cp += i;
     n -= i;
@@ -589,11 +587,11 @@ void
 curl_certinfo_free_all(struct curl_certinfo *info)
 
 {
-  int i;
-
   /* Free all memory used by certificate info. */
   if(info) {
     if(info->certinfo) {
+      int i;
+
       for(i = 0; i < info->num_of_certs; i++)
         curl_slist_free_all(info->certinfo[i]);
       free((char *) info->certinfo);
@@ -612,13 +610,10 @@ curl_easy_getinfo_ccsid(CURL * curl, CURLINFO info, ...)
   CURLcode ret;
   unsigned int ccsid;
   char * * cpp;
-  char * s;
-  char * d;
   struct SessionHandle * data;
   struct curl_slist * * slp;
   struct curl_certinfo * cipf;
   struct curl_certinfo * cipt;
-  int i;
 
   /* WARNING: unlike curl_easy_get_info(), the strings returned by this
      procedure have to be free'ed. */
@@ -634,13 +629,11 @@ curl_easy_getinfo_ccsid(CURL * curl, CURLINFO info, ...)
     case CURLINFO_STRING:
       ccsid = va_arg(arg, unsigned int);
       cpp = (char * *) paramp;
-      s = *cpp;
 
-      if(s) {
-        d = dynconvert(ccsid, s, -1, ASCII_CCSID);
-        *cpp = d;
+      if(*cpp) {
+        *cpp = dynconvert(ccsid, *cpp, -1, ASCII_CCSID);
 
-        if(!d)
+        if(!*cpp)
           ret = CURLE_OUT_OF_MEMORY;
       }
 
@@ -661,6 +654,8 @@ curl_easy_getinfo_ccsid(CURL * curl, CURLINFO info, ...)
             if(!cipt->certinfo)
               ret = CURLE_OUT_OF_MEMORY;
             else {
+              int i;
+
               cipt->num_of_certs = cipf->num_of_certs;
               for(i = 0; i < cipf->num_of_certs; i++)
                 if(cipf->certinfo[i])
@@ -1107,7 +1102,6 @@ curl_easy_setopt_ccsid(CURL * curl, CURLoption tag, ...)
   char * s;
   char * cp;
   unsigned int ccsid;
-  size_t len;
   curl_off_t pfsize;
   static char testwarn = 1;
 
@@ -1120,7 +1114,8 @@ curl_easy_setopt_ccsid(CURL * curl, CURLoption tag, ...)
   if(testwarn) {
     testwarn = 0;
 
-    if((int) STRING_LAST != (int) STRING_BEARER + 1)
+    if((int) STRING_LASTZEROTERMINATED != (int) STRING_UNIX_SOCKET_PATH + 1 ||
+       (int) STRING_LAST != (int) STRING_COPYPOSTFIELDS + 1)
       curl_mfprintf(stderr,
        "*** WARNING: curl_easy_setopt_ccsid() should be reworked ***\n");
     }
@@ -1154,6 +1149,7 @@ curl_easy_setopt_ccsid(CURL * curl, CURLoption tag, ...)
   case CURLOPT_NETRC_FILE:
   case CURLOPT_NOPROXY:
   case CURLOPT_PASSWORD:
+  case CURLOPT_PINNEDPUBLICKEY:
   case CURLOPT_PROXY:
   case CURLOPT_PROXYPASSWORD:
   case CURLOPT_PROXYUSERNAME:
@@ -1178,6 +1174,7 @@ curl_easy_setopt_ccsid(CURL * curl, CURLoption tag, ...)
   case CURLOPT_TLSAUTH_PASSWORD:
   case CURLOPT_TLSAUTH_TYPE:
   case CURLOPT_TLSAUTH_USERNAME:
+  case CURLOPT_UNIX_SOCKET_PATH:
   case CURLOPT_URL:
   case CURLOPT_USERAGENT:
   case CURLOPT_USERNAME:
@@ -1227,6 +1224,7 @@ curl_easy_setopt_ccsid(CURL * curl, CURLoption tag, ...)
       }
     else {
       /* Data length specified. */
+      size_t len;
 
       if(pfsize < 0 || pfsize > SIZE_MAX) {
         result = CURLE_OUT_OF_MEMORY;