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
This commit is contained in:
parent
3b61fbb7fb
commit
f3144a0b1b
@ -1,6 +1,48 @@
|
|||||||
#include "xvturl.h"
|
#include "xvturl.h"
|
||||||
#include <curl/curl.h>
|
#include <curl/curl.h>
|
||||||
|
|
||||||
|
/**********************************************************************
|
||||||
|
* 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()
|
URLDLL const char* xvturl_version()
|
||||||
{
|
{
|
||||||
static char version[50];
|
static char version[50];
|
||||||
@ -8,3 +50,78 @@ URLDLL const char* xvturl_version()
|
|||||||
sprintf_s(version, "cURL %s", LIBCURL_VERSION);
|
sprintf_s(version, "cURL %s", LIBCURL_VERSION);
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 *
|
||||||
|
**********************************************************************/
|
@ -1,12 +1,73 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#ifndef __XVTURL_H
|
#ifndef __XVTURL_H
|
||||||
#define __XVTURL_H
|
#define __XVTURL_H
|
||||||
|
#pragma once
|
||||||
|
|
||||||
#define URLDLL __declspec(dllexport)
|
#define URLDLL __declspec(dllexport)
|
||||||
|
// CURL -> void *
|
||||||
|
typedef void * XVT_HANDLE;
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
|
/**********************************************************************
|
||||||
|
* 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();
|
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
|
#endif
|
Loading…
x
Reference in New Issue
Block a user