#include #include /* unix-specific */ #ifndef EIF_WINNT #include #include #endif #include typedef char bool; #define TRUE 1 #ifndef my_curl #define my_curl struct cURLMemoryStruct { char *memory; size_t size; }; static void dump(const char *text, FILE *stream, unsigned char *ptr, size_t size,bool nohex) { size_t i; size_t c; unsigned int width=0x10; if(nohex) /* without the hex output, we can fit more on screen */ width = 0x400; fprintf(stream, "%s, %zd bytes (0x%zx)\n", text, size, size); for(i=0; i=0x20) && (ptr[i+c]<0x80)?ptr[i+c]:'.'); /* check again for 0D0A, to avoid an extra \n if it's at width */ if (nohex && (i+c+2 < size) && ptr[i+c+1]==0x0D && ptr[i+c+2]==0x0A) { i+=(c+3-width); break; } } fputc('\n', stream); /* newline */ } fflush(stream); } static int curl_trace(CURL *handle, curl_infotype type, unsigned char *data, size_t size, void *userp) { const char *text; (void)handle; /* prevent compiler warning */ switch (type) { case CURLINFO_TEXT: fprintf(stderr, "== Info: %s", data); default: /* in case a new one is introduced to shock us */ return 0; case CURLINFO_HEADER_OUT: text = "=> Send header"; break; case CURLINFO_DATA_OUT: text = "=> Send data"; break; case CURLINFO_HEADER_IN: text = "<= Recv header"; break; case CURLINFO_DATA_IN: text = "<= Recv data"; break; } dump(text, stderr, data, size, TRUE); return 0; } static void *myrealloc(void *ptr, size_t size) { /* There might be a realloc() out there that doesn't like reallocing NULL pointers, so we take care of it here */ if(ptr) return realloc(ptr, size); else return malloc(size); } static size_t WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data) { size_t realsize = size * nmemb; size_t totalsize; struct cURLMemoryStruct *mem = (struct cURLMemoryStruct *)data; mem->memory = (char *)myrealloc(mem->memory, mem->size + realsize + 1); if (mem->memory) { memcpy(&(mem->memory[mem->size]), ptr, realsize); mem->size += realsize; mem->memory[mem->size] = 0; } return realsize; } #endif