File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / curl / tests / libtest / lib547.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Wed Jun 3 10:01:16 2020 UTC (5 years ago) by misho
Branches: curl, MAIN
CVS tags: v7_70_0p4, HEAD
curl

    1: /***************************************************************************
    2:  *                                  _   _ ____  _
    3:  *  Project                     ___| | | |  _ \| |
    4:  *                             / __| | | | |_) | |
    5:  *                            | (__| |_| |  _ <| |___
    6:  *                             \___|\___/|_| \_\_____|
    7:  *
    8:  * Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
    9:  *
   10:  * This software is licensed as described in the file COPYING, which
   11:  * you should have received as part of this distribution. The terms
   12:  * are also available at https://curl.haxx.se/docs/copyright.html.
   13:  *
   14:  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
   15:  * copies of the Software, and permit persons to whom the Software is
   16:  * furnished to do so, under the terms of the COPYING file.
   17:  *
   18:  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
   19:  * KIND, either express or implied.
   20:  *
   21:  ***************************************************************************/
   22: /* argv1 = URL
   23:  * argv2 = proxy
   24:  * argv3 = proxyuser:password
   25:  */
   26: 
   27: #include "test.h"
   28: 
   29: #include "memdebug.h"
   30: 
   31: #ifdef CURL_DOES_CONVERSIONS
   32:    /* ASCII representation with escape sequences for non-ASCII platforms */
   33: #  define UPLOADTHIS "\x74\x68\x69\x73\x20\x69\x73\x20\x74\x68\x65\x20\x62" \
   34:                      "\x6c\x75\x72\x62\x20\x77\x65\x20\x77\x61\x6e\x74\x20" \
   35:                      "\x74\x6f\x20\x75\x70\x6c\x6f\x61\x64\x0a"
   36: #else
   37: #  define UPLOADTHIS "this is the blurb we want to upload\n"
   38: #endif
   39: 
   40: #ifndef LIB548
   41: static size_t readcallback(void  *ptr,
   42:                            size_t size,
   43:                            size_t nmemb,
   44:                            void *clientp)
   45: {
   46:   int *counter = (int *)clientp;
   47: 
   48:   if(*counter) {
   49:     /* only do this once and then require a clearing of this */
   50:     fprintf(stderr, "READ ALREADY DONE!\n");
   51:     return 0;
   52:   }
   53:   (*counter)++; /* bump */
   54: 
   55:   if(size * nmemb > strlen(UPLOADTHIS)) {
   56:     fprintf(stderr, "READ!\n");
   57:     strcpy(ptr, UPLOADTHIS);
   58:     return strlen(UPLOADTHIS);
   59:   }
   60:   fprintf(stderr, "READ NOT FINE!\n");
   61:   return 0;
   62: }
   63: static curlioerr ioctlcallback(CURL *handle,
   64:                                int cmd,
   65:                                void *clientp)
   66: {
   67:   int *counter = (int *)clientp;
   68:   (void)handle; /* unused */
   69:   if(cmd == CURLIOCMD_RESTARTREAD) {
   70:     fprintf(stderr, "REWIND!\n");
   71:     *counter = 0; /* clear counter to make the read callback restart */
   72:   }
   73:   return CURLIOE_OK;
   74: }
   75: 
   76: 
   77: 
   78: #endif
   79: 
   80: int test(char *URL)
   81: {
   82:   CURLcode res;
   83:   CURL *curl;
   84: #ifndef LIB548
   85:   int counter = 0;
   86: #endif
   87: 
   88:   if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
   89:     fprintf(stderr, "curl_global_init() failed\n");
   90:     return TEST_ERR_MAJOR_BAD;
   91:   }
   92: 
   93:   curl = curl_easy_init();
   94:   if(!curl) {
   95:     fprintf(stderr, "curl_easy_init() failed\n");
   96:     curl_global_cleanup();
   97:     return TEST_ERR_MAJOR_BAD;
   98:   }
   99: 
  100:   test_setopt(curl, CURLOPT_URL, URL);
  101:   test_setopt(curl, CURLOPT_VERBOSE, 1L);
  102:   test_setopt(curl, CURLOPT_HEADER, 1L);
  103: #ifdef LIB548
  104:   /* set the data to POST with a mere pointer to a zero-terminated string */
  105:   test_setopt(curl, CURLOPT_POSTFIELDS, UPLOADTHIS);
  106: #else
  107:   /* 547 style, which means reading the POST data from a callback */
  108:   test_setopt(curl, CURLOPT_IOCTLFUNCTION, ioctlcallback);
  109:   test_setopt(curl, CURLOPT_IOCTLDATA, &counter);
  110:   test_setopt(curl, CURLOPT_READFUNCTION, readcallback);
  111:   test_setopt(curl, CURLOPT_READDATA, &counter);
  112:   /* We CANNOT do the POST fine without setting the size (or choose
  113:      chunked)! */
  114:   test_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)strlen(UPLOADTHIS));
  115: #endif
  116:   test_setopt(curl, CURLOPT_POST, 1L);
  117:   test_setopt(curl, CURLOPT_PROXY, libtest_arg2);
  118:   test_setopt(curl, CURLOPT_PROXYUSERPWD, libtest_arg3);
  119:   test_setopt(curl, CURLOPT_PROXYAUTH,
  120:                    (long) (CURLAUTH_NTLM | CURLAUTH_DIGEST | CURLAUTH_BASIC) );
  121: 
  122:   res = curl_easy_perform(curl);
  123: 
  124: test_cleanup:
  125: 
  126:   curl_easy_cleanup(curl);
  127:   curl_global_cleanup();
  128: 
  129:   return (int)res;
  130: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>