lib552.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 with embedded user+password
00024  */
00025 
00026 #include "test.h"
00027 
00028 #include "warnless.h"
00029 #include "memdebug.h"
00030 
00031 struct data {
00032   char trace_ascii; /* 1 or 0 */
00033 };
00034 
00035 static
00036 void dump(const char *text,
00037           FILE *stream, unsigned char *ptr, size_t size,
00038           char nohex)
00039 {
00040   size_t i;
00041   size_t c;
00042 
00043   unsigned int width=0x10;
00044 
00045   if(nohex)
00046     /* without the hex output, we can fit more on screen */
00047     width = 0x40;
00048 
00049   fprintf(stream, "%s, %d bytes (0x%x)\n", text, (int)size, (int)size);
00050 
00051   for(i=0; i<size; i+= width) {
00052 
00053     fprintf(stream, "%04x: ", (int)i);
00054 
00055     if(!nohex) {
00056       /* hex not disabled, show it */
00057       for(c = 0; c < width; c++)
00058         if(i+c < size)
00059           fprintf(stream, "%02x ", ptr[i+c]);
00060         else
00061           fputs("   ", stream);
00062     }
00063 
00064     for(c = 0; (c < width) && (i+c < size); c++) {
00065       /* check for 0D0A; if found, skip past and start a new line of output */
00066       if(nohex && (i+c+1 < size) && ptr[i+c]==0x0D && ptr[i+c+1]==0x0A) {
00067         i+=(c+2-width);
00068         break;
00069       }
00070       fprintf(stream, "%c",
00071               (ptr[i+c]>=0x20) && (ptr[i+c]<0x80)?ptr[i+c]:'.');
00072       /* check again for 0D0A, to avoid an extra \n if it's at width */
00073       if(nohex && (i+c+2 < size) && ptr[i+c+1]==0x0D && ptr[i+c+2]==0x0A) {
00074         i+=(c+3-width);
00075         break;
00076       }
00077     }
00078     fputc('\n', stream); /* newline */
00079   }
00080   fflush(stream);
00081 }
00082 
00083 static
00084 int my_trace(CURL *handle, curl_infotype type,
00085              char *data, size_t size,
00086              void *userp)
00087 {
00088   struct data *config = (struct data *)userp;
00089   const char *text;
00090   (void)handle; /* prevent compiler warning */
00091 
00092   switch(type) {
00093   case CURLINFO_TEXT:
00094     fprintf(stderr, "== Info: %s", (char *)data);
00095   default: /* in case a new one is introduced to shock us */
00096     return 0;
00097 
00098   case CURLINFO_HEADER_OUT:
00099     text = "=> Send header";
00100     break;
00101   case CURLINFO_DATA_OUT:
00102     text = "=> Send data";
00103     break;
00104   case CURLINFO_SSL_DATA_OUT:
00105     text = "=> Send SSL data";
00106     break;
00107   case CURLINFO_HEADER_IN:
00108     text = "<= Recv header";
00109     break;
00110   case CURLINFO_DATA_IN:
00111     text = "<= Recv data";
00112     break;
00113   case CURLINFO_SSL_DATA_IN:
00114     text = "<= Recv SSL data";
00115     break;
00116   }
00117 
00118   dump(text, stderr, (unsigned char *)data, size, config->trace_ascii);
00119   return 0;
00120 }
00121 
00122 
00123 static size_t current_offset = 0;
00124 static char databuf[70000]; /* MUST be more than 64k OR
00125                                MAX_INITIAL_POST_SIZE */
00126 
00127 static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *stream)
00128 {
00129   size_t  amount = nmemb * size; /* Total bytes curl wants */
00130   size_t  available = sizeof(databuf) - current_offset; /* What we have to
00131                                                            give */
00132   size_t  given = amount < available ? amount : available; /* What is given */
00133   (void)stream;
00134   memcpy(ptr, databuf + current_offset, given);
00135   current_offset += given;
00136   return given;
00137 }
00138 
00139 
00140 static size_t write_callback(void *ptr, size_t size, size_t nmemb,
00141                              void *stream)
00142 {
00143   int amount = curlx_uztosi(size * nmemb);
00144   printf("%.*s", amount, (char *)ptr);
00145   (void)stream;
00146   return size * nmemb;
00147 }
00148 
00149 
00150 static curlioerr ioctl_callback(CURL *handle, int cmd, void *clientp)
00151 {
00152   (void)clientp;
00153   if(cmd == CURLIOCMD_RESTARTREAD) {
00154     printf("APPLICATION: recieved a CURLIOCMD_RESTARTREAD request\n");
00155     printf("APPLICATION: ** REWINDING! **\n");
00156     current_offset = 0;
00157     return CURLIOE_OK;
00158   }
00159   (void)handle;
00160   return CURLIOE_UNKNOWNCMD;
00161 }
00162 
00163 
00164 
00165 int test(char *URL)
00166 {
00167   CURL *curl;
00168   CURLcode res = CURLE_OUT_OF_MEMORY;
00169   struct data config;
00170   size_t i;
00171   static const char fill[] = "test data";
00172 
00173   config.trace_ascii = 1; /* enable ascii tracing */
00174 
00175   curl = curl_easy_init();
00176   if(!curl) {
00177     fprintf(stderr, "curl_easy_init() failed\n");
00178     curl_global_cleanup();
00179     return TEST_ERR_MAJOR_BAD;
00180   }
00181 
00182   test_setopt(curl, CURLOPT_DEBUGFUNCTION, my_trace);
00183   test_setopt(curl, CURLOPT_DEBUGDATA, &config);
00184   /* the DEBUGFUNCTION has no effect until we enable VERBOSE */
00185   test_setopt(curl, CURLOPT_VERBOSE, 1L);
00186 
00187   /* setup repeated data string */
00188   for(i=0; i < sizeof(databuf); ++i)
00189       databuf[i] = fill[i % sizeof fill];
00190 
00191   /* Post */
00192   test_setopt(curl, CURLOPT_POST, 1L);
00193 
00194 #ifdef CURL_DOES_CONVERSIONS
00195   /* Convert the POST data to ASCII */
00196   test_setopt(curl, CURLOPT_TRANSFERTEXT, 1L);
00197 #endif
00198 
00199   /* Setup read callback */
00200   test_setopt(curl, CURLOPT_POSTFIELDSIZE, (long) sizeof(databuf));
00201   test_setopt(curl, CURLOPT_READFUNCTION, read_callback);
00202 
00203   /* Write callback */
00204   test_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
00205 
00206   /* Ioctl function */
00207   test_setopt(curl, CURLOPT_IOCTLFUNCTION, ioctl_callback);
00208 
00209   test_setopt(curl, CURLOPT_PROXY, libtest_arg2);
00210 
00211   test_setopt(curl, CURLOPT_URL, URL);
00212 
00213   /* Accept any auth. But for this bug configure proxy with DIGEST, basic
00214      might work too, not NTLM */
00215   test_setopt(curl, CURLOPT_PROXYAUTH, (long)CURLAUTH_ANY);
00216 
00217   res = curl_easy_perform(curl);
00218   fprintf(stderr, "curl_easy_perform = %d\n", (int)res);
00219 
00220 test_cleanup:
00221 
00222   curl_easy_cleanup(curl);
00223   curl_global_cleanup();
00224   return (int)res;
00225 }


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