Return to lib651.c CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / curl / tests / libtest |
1.1 ! misho 1: /*************************************************************************** ! 2: * _ _ ____ _ ! 3: * Project ___| | | | _ \| | ! 4: * / __| | | | |_) | | ! 5: * | (__| |_| | _ <| |___ ! 6: * \___|\___/|_| \_\_____| ! 7: * ! 8: * Copyright (C) 1998 - 2017, 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: #include "test.h" ! 23: ! 24: #include "memdebug.h" ! 25: ! 26: static char buffer[17000]; /* more than 16K */ ! 27: ! 28: int test(char *URL) ! 29: { ! 30: CURL *curl; ! 31: CURLcode res = CURLE_OK; ! 32: CURLFORMcode formrc; ! 33: struct curl_httppost *formpost = NULL; ! 34: struct curl_httppost *lastptr = NULL; ! 35: ! 36: /* create a buffer with AAAA...BBBBB...CCCC...etc */ ! 37: int i; ! 38: int size = (int)sizeof(buffer)/1000; ! 39: ! 40: for(i = 0; i < size ; i++) ! 41: memset(&buffer[i * 1000], 65 + i, 1000); ! 42: ! 43: buffer[ sizeof(buffer)-1] = 0; /* zero terminate */ ! 44: ! 45: if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { ! 46: fprintf(stderr, "curl_global_init() failed\n"); ! 47: return TEST_ERR_MAJOR_BAD; ! 48: } ! 49: ! 50: /* Check proper name and data copying. */ ! 51: formrc = curl_formadd(&formpost, &lastptr, ! 52: CURLFORM_COPYNAME, "hello", ! 53: CURLFORM_COPYCONTENTS, buffer, ! 54: CURLFORM_END); ! 55: ! 56: if(formrc) ! 57: printf("curl_formadd(1) = %d\n", (int) formrc); ! 58: ! 59: ! 60: curl = curl_easy_init(); ! 61: if(!curl) { ! 62: fprintf(stderr, "curl_easy_init() failed\n"); ! 63: curl_formfree(formpost); ! 64: curl_global_cleanup(); ! 65: return TEST_ERR_MAJOR_BAD; ! 66: } ! 67: ! 68: /* First set the URL that is about to receive our POST. */ ! 69: test_setopt(curl, CURLOPT_URL, URL); ! 70: ! 71: /* send a multi-part formpost */ ! 72: test_setopt(curl, CURLOPT_HTTPPOST, formpost); ! 73: ! 74: /* get verbose debug output please */ ! 75: test_setopt(curl, CURLOPT_VERBOSE, 1L); ! 76: ! 77: /* include headers in the output */ ! 78: test_setopt(curl, CURLOPT_HEADER, 1L); ! 79: ! 80: /* Perform the request, res will get the return code */ ! 81: res = curl_easy_perform(curl); ! 82: ! 83: test_cleanup: ! 84: ! 85: /* always cleanup */ ! 86: curl_easy_cleanup(curl); ! 87: ! 88: /* now cleanup the formpost chain */ ! 89: curl_formfree(formpost); ! 90: ! 91: curl_global_cleanup(); ! 92: ! 93: return res; ! 94: }