lib509.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 #include "test.h"
00023 
00024 /*
00025  * This test uses these funny custom memory callbacks for the only purpose
00026  * of verifying that curl_global_init_mem() functionallity is present in
00027  * libcurl and that it works unconditionally no matter how libcurl is built,
00028  * nothing more.
00029  *
00030  * Do not include memdebug.h in this source file, and do not use directly
00031  * memory related functions in this file except those used inside custom
00032  * memory callbacks which should be calling 'the real thing'.
00033  */
00034 
00035 /*
00036 #include "memdebug.h"
00037 */
00038 
00039 int seen_malloc = 0;
00040 int seen_free = 0;
00041 int seen_realloc = 0;
00042 int seen_strdup = 0;
00043 int seen_calloc = 0;
00044 
00045 void *custom_malloc(size_t size);
00046 void custom_free(void *ptr);
00047 void *custom_realloc(void *ptr, size_t size);
00048 char *custom_strdup(const char *ptr);
00049 void *custom_calloc(size_t nmemb, size_t size);
00050 
00051 
00052 void *custom_calloc(size_t nmemb, size_t size)
00053 {
00054   if(!seen_calloc) {
00055     printf("seen custom_calloc()\n");
00056     seen_calloc = 1;
00057   }
00058   return (calloc)(nmemb, size);
00059 }
00060 
00061 void *custom_malloc(size_t size)
00062 {
00063   if(!seen_malloc && seen_calloc) {
00064     printf("seen custom_malloc()\n");
00065     seen_malloc = 1;
00066   }
00067   return (malloc)(size);
00068 }
00069 
00070 char *custom_strdup(const char *ptr)
00071 {
00072   if(!seen_strdup && seen_malloc) {
00073     /* currently (2013.03.13), memory tracking enabled builds do not call
00074        the strdup callback, in this case malloc callback and memcpy are used
00075        instead. If some day this is changed the following printf() should be
00076        uncommented, and a line added to test definition.
00077     printf("seen custom_strdup()\n");
00078     */
00079     seen_strdup = 1;
00080   }
00081   return (strdup)(ptr);
00082 }
00083 
00084 void *custom_realloc(void *ptr, size_t size)
00085 {
00086   if(!seen_realloc && seen_malloc) {
00087     printf("seen custom_realloc()\n");
00088     seen_realloc = 1;
00089   }
00090   return (realloc)(ptr, size);
00091 }
00092 
00093 void custom_free(void *ptr)
00094 {
00095   if(!seen_free && seen_realloc) {
00096     printf("seen custom_free()\n");
00097     seen_free = 1;
00098   }
00099   (free)(ptr);
00100 }
00101 
00102 
00103 int test(char *URL)
00104 {
00105   unsigned char a[] = {0x2f, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
00106                        0x91, 0xa2, 0xb3, 0xc4, 0xd5, 0xe6, 0xf7};
00107   CURLcode res;
00108   CURL *curl;
00109   int asize;
00110   char *str = NULL;
00111 
00112   (void)URL;
00113 
00114   res = curl_global_init_mem(CURL_GLOBAL_ALL,
00115                              custom_malloc,
00116                              custom_free,
00117                              custom_realloc,
00118                              custom_strdup,
00119                              custom_calloc);
00120   if(res != CURLE_OK) {
00121     fprintf(stderr, "curl_global_init_mem() failed\n");
00122     return TEST_ERR_MAJOR_BAD;
00123   }
00124 
00125   curl = curl_easy_init();
00126   if(!curl) {
00127     fprintf(stderr, "curl_easy_init() failed\n");
00128     curl_global_cleanup();
00129     return TEST_ERR_MAJOR_BAD;
00130   }
00131 
00132   test_setopt(curl, CURLOPT_USERAGENT, "test509"); /* uses strdup() */
00133 
00134   asize = (int)sizeof(a);
00135   str = curl_easy_escape(curl, (char *)a, asize); /* uses realloc() */
00136 
00137 test_cleanup:
00138 
00139   if(str)
00140     curl_free(str);
00141 
00142   curl_easy_cleanup(curl);
00143   curl_global_cleanup();
00144 
00145   return (int)res;
00146 }
00147 


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