void set_curl_mem_callbacks(void) { CURLcode rc; switch (curl_memory_manager) { case 0: LM_DBG("Setting shm memory callbacks for cURL\n"); rc = curl_global_init_mem(CURL_GLOBAL_ALL, curl_shm_malloc, curl_shm_free, curl_shm_realloc, curl_shm_strdup, curl_shm_calloc); if (rc != 0) { LM_ERR("Cannot set memory callbacks for cURL: %d\n", rc); } break; case 1: LM_DBG("Initilizing cURL with sys malloc\n"); rc = curl_global_init(CURL_GLOBAL_ALL); if (rc != 0) { LM_ERR("Cannot initialize cURL: %d\n", rc); } break; default: LM_ERR ("invalid memory manager: %d\n", curl_memory_manager); break; } }
static int mod_init(void) { LM_DBG("Initializing...\n"); connection_timeout_ms = connection_timeout * 1000L; if (connect_poll_interval < 0) { LM_ERR("Bad connect_poll_interval (%ldms), setting to 20ms\n", connect_poll_interval); connect_poll_interval = 20; } if (connection_timeout > curl_timeout) { LM_WARN("'connection_timeout' must be less than or equal " "to 'curl_timeout'! setting it to %ld...\n", curl_timeout); connection_timeout = curl_timeout; } lock_init(&thread_lock); curl_global_init_mem(CURL_GLOBAL_ALL, osips_malloc, osips_free, osips_realloc, osips_strdup, osips_calloc); INIT_LIST_HEAD(&multi_pool); /* try loading the trace api */ if (register_trace_type) { rest_proto_id = register_trace_type(rest_id_s); if ( global_trace_api ) { memcpy(&tprot, global_trace_api, sizeof tprot); } else { memset(&tprot, 0, sizeof tprot); if (trace_prot_bind( REST_TRACE_API_MODULE, &tprot)) LM_DBG("Can't bind <%s>!\n", REST_TRACE_API_MODULE); } } else { memset(&tprot, 0, sizeof tprot); } if (is_script_func_used("rest_init_client_tls", -1)) { if (load_tls_mgm_api(&tls_api) != 0) { LM_ERR("failed to load the tls_mgm API! " "Is the tls_mgm module loaded?\n"); return -1; } } if (!validate_curl_http_version(&curl_http_version)) return -1; LM_INFO("Module initialized!\n"); return 0; }
int test(char *URL) { unsigned char a[] = {0x2f, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x91, 0xa2, 0xb3, 0xc4, 0xd5, 0xe6, 0xf7}; CURLcode res; CURL *curl; int asize; char *str = NULL; (void)URL; res = curl_global_init_mem(CURL_GLOBAL_ALL, custom_malloc, custom_free, custom_realloc, custom_strdup, custom_calloc); if(res != CURLE_OK) { fprintf(stderr, "curl_global_init_mem() failed\n"); return TEST_ERR_MAJOR_BAD; } curl = curl_easy_init(); if(!curl) { fprintf(stderr, "curl_easy_init() failed\n"); curl_global_cleanup(); return TEST_ERR_MAJOR_BAD; } test_setopt(curl, CURLOPT_USERAGENT, "test509"); /* uses strdup() */ asize = (int)sizeof(a); str = curl_easy_escape(curl, (char *)a, asize); /* uses realloc() */ test_cleanup: if(str) curl_free(str); curl_easy_cleanup(curl); curl_global_cleanup(); return (int)res; }
static int mod_init(void) { LM_DBG("Initializing...\n"); connection_timeout_ms = connection_timeout * 1000L; curl_global_init_mem(CURL_GLOBAL_ALL, osips_malloc, osips_free, osips_realloc, osips_strdup, osips_calloc); multi_handle = curl_multi_init(); LM_INFO("Module initialized!\n"); return 0; }
void FCurlHttpManager::InitCurl() { if (GMultiHandle != NULL) { UE_LOG(LogInit, Warning, TEXT("Already initialized multi handle")); return; } CURLcode InitResult = curl_global_init_mem(CURL_GLOBAL_ALL, CurlMalloc, CurlFree, CurlRealloc, CurlStrdup, CurlCalloc); if (InitResult == 0) { curl_version_info_data * VersionInfo = curl_version_info(CURLVERSION_NOW); if (VersionInfo) { UE_LOG(LogInit, Log, TEXT("Using libcurl %s"), ANSI_TO_TCHAR(VersionInfo->version)); UE_LOG(LogInit, Log, TEXT(" - built for %s"), ANSI_TO_TCHAR(VersionInfo->host)); if (VersionInfo->features & CURL_VERSION_SSL) { UE_LOG(LogInit, Log, TEXT(" - supports SSL with %s"), ANSI_TO_TCHAR(VersionInfo->ssl_version)); } else { // No SSL UE_LOG(LogInit, Log, TEXT(" - NO SSL SUPPORT!")); } if (VersionInfo->features & CURL_VERSION_LIBZ) { UE_LOG(LogInit, Log, TEXT(" - supports HTTP deflate (compression) using libz %s"), ANSI_TO_TCHAR(VersionInfo->libz_version)); } UE_LOG(LogInit, Log, TEXT(" - other features:")); #define PrintCurlFeature(Feature) \ if (VersionInfo->features & Feature) \ { \ UE_LOG(LogInit, Log, TEXT(" %s"), TEXT(#Feature)); \ } PrintCurlFeature(CURL_VERSION_SSL); PrintCurlFeature(CURL_VERSION_LIBZ); PrintCurlFeature(CURL_VERSION_DEBUG); PrintCurlFeature(CURL_VERSION_IPV6); PrintCurlFeature(CURL_VERSION_ASYNCHDNS); PrintCurlFeature(CURL_VERSION_LARGEFILE); PrintCurlFeature(CURL_VERSION_IDN); PrintCurlFeature(CURL_VERSION_CONV); PrintCurlFeature(CURL_VERSION_TLSAUTH_SRP); #undef PrintCurlFeature } GMultiHandle = curl_multi_init(); if (NULL == GMultiHandle) { UE_LOG(LogInit, Fatal, TEXT("Could not initialize create libcurl multi handle! HTTP transfers will not function properly.")); } } else { UE_LOG(LogInit, Fatal, TEXT("Could not initialize libcurl (result=%d), HTTP transfers will not function properly."), (int32)InitResult); } // Init curl request options // set certificate verification (disable to allow self-signed certificates) bool bVerifyPeer = true; if (GConfig->GetBool(TEXT("/Script/Engine.NetworkSettings"), TEXT("n.VerifyPeer"), bVerifyPeer, GEngineIni)) { CurlRequestOptions.bVerifyPeer = bVerifyPeer; } FString ProxyAddress; if (FParse::Value(FCommandLine::Get(), TEXT("httpproxy="), ProxyAddress)) { if (!ProxyAddress.IsEmpty()) { CurlRequestOptions.bUseHttpProxy = true; CurlRequestOptions.HttpProxyAddress = ProxyAddress; } else { UE_LOG(LogInit, Warning, TEXT(" Libcurl: -httpproxy has been passed as a parameter, but the address doesn't seem to be valid")); } } if (FParse::Param(FCommandLine::Get(), TEXT("noreuseconn"))) { CurlRequestOptions.bDontReuseConnections = true; } // discover cert location if (PLATFORM_LINUX) // only relevant to Linux (for now?), not #ifdef'ed to keep the code checked by the compiler when compiling for other platforms { static const char * KnownBundlePaths[] = { "/etc/pki/tls/certs/ca-bundle.crt", "/etc/ssl/certs/ca-certificates.crt", "/etc/ssl/ca-bundle.pem", nullptr }; for (const char ** CurrentBundle = KnownBundlePaths; *CurrentBundle; ++CurrentBundle) { FString FileName(*CurrentBundle); UE_LOG(LogInit, Log, TEXT(" Libcurl: checking if '%s' exists"), *FileName); if (FPaths::FileExists(FileName)) { CurlRequestOptions.CertBundlePath = *CurrentBundle; break; } } if (CurlRequestOptions.CertBundlePath == nullptr) { UE_LOG(LogInit, Log, TEXT(" Libcurl: did not find a cert bundle in any of known locations, TLS may not work")); } } // print for visibility CurlRequestOptions.Log(); }
int initialize_gallocy_framework(const char* config_path) { void *start; void *end; LOG_DEBUG("Initializing gallocy framework!"); // // Fail early if a configuration file wasn't found. // if (!config_path) { LOG_ERROR("No configuration file provided!"); abort(); } // // Share where heaps have been placed. // start = get_heap_location(PURPOSE_INTERNAL_HEAP); end = reinterpret_cast<uint8_t *>(start) + ZONE_SZ; LOG_DEBUG("Set internal heap " << "[" << start << " - " << end << "]"); start = get_heap_location(PURPOSE_SHARED_HEAP); end = reinterpret_cast<uint8_t *>(start) + ZONE_SZ; LOG_DEBUG("Set shared heap " << "[" << start << " - " << end << "]"); start = get_heap_location(PURPOSE_APPLICATION_HEAP); end = reinterpret_cast<uint8_t *>(start) + ZONE_SZ; LOG_DEBUG("Set application heap " << "[" << start << " - " << end << "]"); // // Initialize libcurl memory allocator. // curl_global_init(CURL_GLOBAL_NOTHING); #if 0 if (curl_global_init_mem( // CURL_GLOBAL_ALL, CURL_GLOBAL_NOTHING, malloc, free, realloc, strdup, calloc)) { LOG_ERROR("Failed to set curl global initiatilization settings."); } #endif char *error; void *handle; // // Seed random number generator // std::srand(std::time(0)); #if __linux__ const char* libpthread = "/lib/x86_64-linux-gnu/libpthread.so.0"; #else const char* libpthread = "/lib/x86_64-linux-gnu/libpthread.so.0"; LOG_ERROR("We don't know how to find libpthread.so on this platform."); #endif dlerror(); handle = dlopen(libpthread, RTLD_LAZY); if (!handle) { LOG_ERROR("Failed to open " << libpthread << ": " << dlerror()); } // // pthread_create // dlerror(); __gallocy_pthread_create = reinterpret_cast<pthread_create_function> (reinterpret_cast<uint64_t *>(dlsym(handle, "pthread_create"))); if ((error = dlerror()) != NULL) { LOG_ERROR("Failed to set pthread_create: " << error); } LOG_DEBUG("Initialized __gallocy_pthread_create [" << &__gallocy_pthread_create << "] from pthread_create [" << reinterpret_cast<uint64_t *>(*__gallocy_pthread_create) << "]"); // // pthread_join // dlerror(); __gallocy_pthread_join = reinterpret_cast<pthread_join_function> (reinterpret_cast<uint64_t *>(dlsym(handle, "pthread_join"))); if ((error = dlerror()) != NULL) { LOG_ERROR("Failed to set pthread_join: " << error); } LOG_DEBUG("Initialized __gallocy_pthread_join [" << &__gallocy_pthread_join << "] from pthread_join [" << reinterpret_cast<uint64_t *>(*__gallocy_pthread_join) << "]"); // // Initialize SQLite memory allocator. // e.initialize(); e.execute(PeerInfo::CREATE_STATEMENT); // // Load configuration file. // gallocy_config = load_config(config_path); // // Create the state object. // gallocy_state = new (internal_malloc(sizeof(GallocyState))) GallocyState(); // // Create the client object. // gallocy_client = new (internal_malloc(sizeof(GallocyClient))) GallocyClient(*gallocy_config); // // // Start the client thread. // gallocy_machine = new (internal_malloc(sizeof(GallocyMachine))) GallocyMachine(*gallocy_config); gallocy_machine->start(); // // Start the server thread. // gallocy_server = new (internal_malloc(sizeof(GallocyServer))) GallocyServer(*gallocy_config); gallocy_server->start(); // // Yield to the application. // return 0; }