lib547.c
Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                  _   _ ____  _
00003  *  Project                     ___| | | |  _ \| |
00004  *                             / __| | | | |_) | |
00005  *                            | (__| |_| |  _ <| |___
00006  *                             \___|\___/|_| \_\_____|
00007  *
00008  * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
00009  *
00010  * This software is licensed as described in the file COPYING, which
00011  * you should have received as part of this distribution. The terms
00012  * are also available at https://curl.haxx.se/docs/copyright.html.
00013  *
00014  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
00015  * copies of the Software, and permit persons to whom the Software is
00016  * furnished to do so, under the terms of the COPYING file.
00017  *
00018  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
00019  * KIND, either express or implied.
00020  *
00021  ***************************************************************************/
00022 /* argv1 = URL
00023  * argv2 = proxy
00024  * argv3 = proxyuser:password
00025  */
00026 
00027 #include "test.h"
00028 
00029 #include "memdebug.h"
00030 
00031 #ifdef CURL_DOES_CONVERSIONS
00032    /* ASCII representation with escape sequences for non-ASCII platforms */
00033 #  define UPLOADTHIS "\x74\x68\x69\x73\x20\x69\x73\x20\x74\x68\x65\x20\x62" \
00034                      "\x6c\x75\x72\x62\x20\x77\x65\x20\x77\x61\x6e\x74\x20" \
00035                      "\x74\x6f\x20\x75\x70\x6c\x6f\x61\x64\x0a"
00036 #else
00037 #  define UPLOADTHIS "this is the blurb we want to upload\n"
00038 #endif
00039 
00040 #ifndef LIB548
00041 static size_t readcallback(void  *ptr,
00042                            size_t size,
00043                            size_t nmemb,
00044                            void *clientp)
00045 {
00046   int *counter = (int *)clientp;
00047 
00048   if(*counter) {
00049     /* only do this once and then require a clearing of this */
00050     fprintf(stderr, "READ ALREADY DONE!\n");
00051     return 0;
00052   }
00053   (*counter)++; /* bump */
00054 
00055   if(size * nmemb > strlen(UPLOADTHIS)) {
00056     fprintf(stderr, "READ!\n");
00057     strcpy(ptr, UPLOADTHIS);
00058     return strlen(UPLOADTHIS);
00059   }
00060   fprintf(stderr, "READ NOT FINE!\n");
00061   return 0;
00062 }
00063 static curlioerr ioctlcallback(CURL *handle,
00064                                int cmd,
00065                                void *clientp)
00066 {
00067   int *counter = (int *)clientp;
00068   (void)handle; /* unused */
00069   if(cmd == CURLIOCMD_RESTARTREAD) {
00070     fprintf(stderr, "REWIND!\n");
00071     *counter = 0; /* clear counter to make the read callback restart */
00072   }
00073   return CURLIOE_OK;
00074 }
00075 
00076 
00077 
00078 #endif
00079 
00080 int test(char *URL)
00081 {
00082   CURLcode res;
00083   CURL *curl;
00084 #ifndef LIB548
00085   int counter=0;
00086 #endif
00087 
00088   if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
00089     fprintf(stderr, "curl_global_init() failed\n");
00090     return TEST_ERR_MAJOR_BAD;
00091   }
00092 
00093   curl = curl_easy_init();
00094   if(!curl) {
00095     fprintf(stderr, "curl_easy_init() failed\n");
00096     curl_global_cleanup();
00097     return TEST_ERR_MAJOR_BAD;
00098   }
00099 
00100   test_setopt(curl, CURLOPT_URL, URL);
00101   test_setopt(curl, CURLOPT_VERBOSE, 1L);
00102   test_setopt(curl, CURLOPT_HEADER, 1L);
00103 #ifdef LIB548
00104   /* set the data to POST with a mere pointer to a zero-terminated string */
00105   test_setopt(curl, CURLOPT_POSTFIELDS, UPLOADTHIS);
00106 #else
00107   /* 547 style, which means reading the POST data from a callback */
00108   test_setopt(curl, CURLOPT_IOCTLFUNCTION, ioctlcallback);
00109   test_setopt(curl, CURLOPT_IOCTLDATA, &counter);
00110   test_setopt(curl, CURLOPT_READFUNCTION, readcallback);
00111   test_setopt(curl, CURLOPT_READDATA, &counter);
00112   /* We CANNOT do the POST fine without setting the size (or choose
00113      chunked)! */
00114   test_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)strlen(UPLOADTHIS));
00115 #endif
00116   test_setopt(curl, CURLOPT_POST, 1L);
00117   test_setopt(curl, CURLOPT_PROXY, libtest_arg2);
00118   test_setopt(curl, CURLOPT_PROXYUSERPWD, libtest_arg3);
00119   test_setopt(curl, CURLOPT_PROXYAUTH,
00120                    (long) (CURLAUTH_NTLM | CURLAUTH_DIGEST | CURLAUTH_BASIC) );
00121 
00122   res = curl_easy_perform(curl);
00123 
00124 test_cleanup:
00125 
00126   curl_easy_cleanup(curl);
00127   curl_global_cleanup();
00128 
00129   return (int)res;
00130 }
00131 


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:05