From f3144a0b1bf0f2b27174406fcc4f03992a89f052 Mon Sep 17 00:00:00 2001 From: mtollari Date: Mon, 27 Nov 2017 14:15:37 +0000 Subject: [PATCH] Patch level : 12.0 no-patch Files correlati : xvturl Commento : Inizio implementazione xvturl con primordiale gestione chiamate post http git-svn-id: svn://10.65.10.50/branches/R_10_00@24200 c028cbd2-c16b-5b4b-a496-9718f37d4682 --- src/xvturl/xvturl.cpp | 119 +++++++++++++++++++++++++++++++++++++++++- src/xvturl/xvturl.h | 67 ++++++++++++++++++++++-- 2 files changed, 182 insertions(+), 4 deletions(-) diff --git a/src/xvturl/xvturl.cpp b/src/xvturl/xvturl.cpp index de69307f3..6eb76e086 100644 --- a/src/xvturl/xvturl.cpp +++ b/src/xvturl/xvturl.cpp @@ -1,10 +1,127 @@ #include "xvturl.h" #include +/********************************************************************** + * xvturl_global episode I: THE PHANTOM FUNCTIONS * + **********************************************************************/ +XVT_HANDLE xvturl_get_handle() +{ + return curl_easy_init(); +} + +bool xvturl_exec(XVT_HANDLE handle, int& err) +{ + err = curl_easy_perform(handle); + return err == CURLE_OK; +} + +const char* xvturl_get_error_string(int err) +{ + return curl_easy_strerror((CURLcode)err); +} + +void xvturl_cleanup(XVT_HANDLE handle) +{ + curl_easy_cleanup(handle); +} + +void xvturl_global_setup(bool on) +{ + static bool initialized; + if(!initialized && on) + { + initialized = true; + curl_global_init(CURL_GLOBAL_ALL); + } + else if(initialized && !on) + { + curl_global_cleanup(); + } +} + +/********************************************************************** + * xvturl_global episode II: ATTACK OF THE LINKER * + **********************************************************************/ + URLDLL const char* xvturl_version() { static char version[50]; if(version[0] == '\0') sprintf_s(version, "cURL %s", LIBCURL_VERSION); return version; -} \ No newline at end of file +} + +URLDLL void xvturl_global_init() +{ + xvturl_global_setup(true); +} + +URLDLL void xvturl_global_cleanup() +{ + xvturl_global_setup(false); +} + +/********************************************************************** + * xvt_email_manager * + **********************************************************************/ +/* +URLDLL XVT_HANDLE xvt_email_get_handle() +{ + return xvturl_get_handle(); +} + +int xvt_email_init(XVT_HANDLE handle, const char* address, int port, const char* usr, const char* psw, XVT_SSL_STATUS ssl) +{ + bool ok = handle != NULL; + + if(ok) + { + curl_easy_setopt(handle, CURLOPT_URL, address); + // You can add the port to the address + if(port > -1) + curl_easy_setopt(handle, CURLOPT_PORT, port); + curl_easy_setopt(handle, CURLOPT_USERNAME, usr); + curl_easy_setopt(handle, CURLOPT_PASSWORD, psw); + curl_easy_setopt(handle, CURLOPT_USE_SSL, ssl); + } + return ok; +} + +*/ + +/********************************************************************** + * xvt_http_manager * + **********************************************************************/ +URLDLL XVT_HANDLE xvt_http_get_handle() +{ + return xvturl_get_handle(); +} + +URLDLL void xvt_http_set_address(XVT_HANDLE handle, const char* address) +{ + curl_easy_setopt(handle, CURLOPT_URL, address); +} + +URLDLL void xvt_http_set_data(XVT_HANDLE handle, const char* data) +{ + curl_easy_setopt(handle, CURLOPT_POSTFIELDS, data); +} + +URLDLL int xvt_http_exec(XVT_HANDLE handle, int& errorCode) +{ + return xvturl_exec(handle, errorCode); +} + +URLDLL const char * xvt_http_exec(int errorCode) +{ + return xvturl_get_error_string(errorCode); +} + +URLDLL void xvt_http_clean(XVT_HANDLE handle) +{ + xvturl_cleanup(handle); +} + +/********************************************************************** + * xvt_ftp_manager * + **********************************************************************/ \ No newline at end of file diff --git a/src/xvturl/xvturl.h b/src/xvturl/xvturl.h index 015f01f67..878c64b4c 100644 --- a/src/xvturl/xvturl.h +++ b/src/xvturl/xvturl.h @@ -1,12 +1,73 @@ -#pragma once - #ifndef __XVTURL_H #define __XVTURL_H +#pragma once #define URLDLL __declspec(dllexport) +// CURL -> void * +typedef void * XVT_HANDLE; -#include +/********************************************************************** + * xvturl_global * + * In this category you can find two kinds of functions: * + * - Normal functions that anyone can call (like xvturl_version()) * + * - Private functions that are the same for every type of object * + * you can create using cURL (only in *.cpp). * + **********************************************************************/ + +// xvturl_global episode I: THE PHANTOM FUNCTIONS +XVT_HANDLE xvturl_get_handle(); +bool xvturl_exec(XVT_HANDLE handle, int& err); +const char* xvturl_get_error_string(int err); +void xvturl_cleanup(XVT_HANDLE handle); +void xvturl_global_setup(bool on); + +// xvturl_global episode II: ATTACK OF THE LINKER +// Get the current cURL Version URLDLL const char* xvturl_version(); +// Initialize all the stuff cURL needs +URLDLL void xvturl_global_init(); +// Clean all the stuff initialized +URLDLL void xvturl_global_cleanup(); + +/********************************************************************** + * xvt_email_manager * + **********************************************************************/ +/* +URLDLL enum XVT_SSL_STATUS +{ + off, // Do not attempt to use SSL + alwaysTry, // Try using SSL, proceed anyway otherwise + onlyControl, // SSL for the control connection or fail + alwaysAll, // SSL for all communication or fail + alwaysOff // Not an option, never use +}; + +URLDLL XVT_HANDLE xvt_email_get_handle(); +URLDLL int xvt_email_init(XVT_HANDLE handle, const char* address, int port, const char* usr, const char* psw, XVT_SSL_STATUS ssl = off); +//bool xvt_email_add_message(const char* from, const char* to, const char* cc, const char* ccn, const char* message); +*/ +/********************************************************************** + * xvt_http_manager * + **********************************************************************/ +// Get the handle +URLDLL XVT_HANDLE xvt_http_get_handle(); +// Set the website address +URLDLL void xvt_http_set_address(XVT_HANDLE handle, const char* address); +// Set the data to send +URLDLL void xvt_http_set_data(XVT_HANDLE handle, const char* data); +// Send the post request +URLDLL int xvt_http_exec(XVT_HANDLE handle, int& errorCode); +// Return a string describing the error code +URLDLL const char * xvt_http_error_string(int errorCode); +// Clean the handle, ACTUNG!!! YOU MUST CALL THIS FUNCTION EVERY TIME +URLDLL void xvt_http_clean(XVT_HANDLE handle); + +/********************************************************************** + * xvt_ftp_manager * + **********************************************************************/ + + + #endif \ No newline at end of file