Commit a4fb029f authored by Benoît Minisini's avatar Benoît Minisini

Curl.DefaultProxy is a new property that allows to define the default proxy of...

Curl.DefaultProxy is a new property that allows to define the default proxy of all newly created HttpClient objects.

[GB.NET.CURL]
* NEW: Curl.DefaultProxy is a new property that allows to define the default proxy of all newly created HttpClient objects.
parent 98c6018e
......@@ -269,7 +269,7 @@ void CURL_init_options(void *_object)
curl_easy_setopt(THIS_CURL, CURLOPT_SSL_VERIFYPEER, THIS->ssl_verify_peer ? 1 : 0);
curl_easy_setopt(THIS_CURL, CURLOPT_SSL_VERIFYHOST , THIS->ssl_verify_host ? 2 : 0);
CURL_proxy_set(&THIS->proxy.proxy, THIS_CURL);
CURL_proxy_set(&THIS->proxy, THIS_CURL);
CURL_user_set(&THIS->user, THIS_CURL);
curl_easy_setopt(THIS_CURL, CURLOPT_URL, THIS_URL);
}
......@@ -444,12 +444,12 @@ bool CURL_copy_from(CCURL *dest, CCURL *src)
COPY_STRING(user.userpwd);
COPY_STRING(user.pwd);
dest->proxy.proxy.type = src->proxy.proxy.type;
dest->proxy.proxy.auth = src->proxy.proxy.auth;
COPY_STRING(proxy.proxy.host);
COPY_STRING(proxy.proxy.user);
COPY_STRING(proxy.proxy.pwd);
COPY_STRING(proxy.proxy.userpwd);
dest->proxy.type = src->proxy.type;
dest->proxy.auth = src->proxy.auth;
COPY_STRING(proxy.host);
COPY_STRING(proxy.user);
COPY_STRING(proxy.pwd);
COPY_STRING(proxy.userpwd);
return FALSE;
}
......@@ -587,13 +587,11 @@ BEGIN_METHOD_VOID(Curl_new)
#endif
CURL_user_init(&THIS->user);
CURL_proxy_init(&THIS->proxy.proxy);
CURL_proxy_init(&THIS->proxy);
THIS->ssl_verify_peer = TRUE;
THIS->ssl_verify_host = TRUE;
THIS->proxy.parent_status = (int*)&THIS_STATUS;
END_METHOD
BEGIN_METHOD_VOID(Curl_free)
......@@ -608,7 +606,7 @@ BEGIN_METHOD_VOID(Curl_free)
GB.FreeString(&THIS->target);
CURL_user_clear(&THIS->user);
CURL_proxy_clear(&THIS->proxy.proxy);
CURL_proxy_clear(&THIS->proxy);
END_METHOD
......@@ -642,6 +640,8 @@ BEGIN_METHOD_VOID(Curl_exit)
#endif
curl_multi_cleanup(CCURL_multicurl);
CURL_default_proxy_clear();
END_METHOD
......@@ -751,6 +751,7 @@ GB_DESC CurlDesc[] =
GB_PROPERTY("Password", "s", Curl_Password),
GB_PROPERTY("Async", "b", Curl_Async),
GB_PROPERTY("Timeout", "i", Curl_Timeout),
GB_STATIC_PROPERTY_SELF("DefaultProxy", ".Curl.Proxy"),
GB_PROPERTY_SELF("Proxy", ".Curl.Proxy"),
GB_PROPERTY_SELF("SSL", ".Curl.SSL"),
GB_PROPERTY_READ("Status", "i", Curl_Status),
......
......@@ -52,13 +52,6 @@ extern GB_STREAM_DESC CurlStream;
#define THIS_URL THIS->url
#define THIS_FILE THIS->file
typedef
struct {
int *parent_status;
CURL_PROXY proxy;
}
CPROXY;
typedef
void (*CURL_FIX_PROGRESS_CB)(void *, double *, double *, double *, double *);
......@@ -71,7 +64,7 @@ typedef
CURL *curl;
char *url;
FILE *file;
CPROXY proxy;
CURL_PROXY proxy;
CURL_USER user;
int timeout;
int buffer_size;
......
......@@ -29,9 +29,9 @@
#include "CProxy.h"
static bool check_active(CPROXY *proxy)
static bool check_active(CCURL *_object)
{
if (*(proxy->parent_status) > 0)
if (THIS && THIS->status > 0)
{
GB.Error("Proxy cannot be modified while client is active");
return TRUE;
......@@ -40,16 +40,20 @@ static bool check_active(CPROXY *proxy)
return FALSE;
}
#define GET_PROXY() CURL_PROXY *proxy = _object ? &THIS->proxy : &CURL_default_proxy
BEGIN_PROPERTY(CurlProxy_Auth)
GET_PROXY();
if (READ_PROPERTY)
GB.ReturnInteger(THIS->proxy.auth);
GB.ReturnInteger(proxy->auth);
else
{
if (check_active(THIS))
return;
if (CURL_proxy_set_auth(&THIS->proxy, VPROP(GB_INTEGER)))
if (CURL_proxy_set_auth(proxy, VPROP(GB_INTEGER)))
GB.Error("Unknown authentication method");
}
......@@ -58,14 +62,16 @@ END_PROPERTY
BEGIN_PROPERTY(CurlProxy_Type)
GET_PROXY();
if (READ_PROPERTY)
GB.ReturnInteger(THIS->proxy.type);
GB.ReturnInteger(proxy->type);
else
{
if (check_active(THIS))
return;
if (CURL_proxy_set_type(&THIS->proxy, VPROP(GB_INTEGER)))
if (CURL_proxy_set_type(proxy, VPROP(GB_INTEGER)))
GB.Error("Unknown proxy type");
}
......@@ -74,14 +80,16 @@ END_PROPERTY
BEGIN_PROPERTY(CurlProxy_User)
GET_PROXY();
if (READ_PROPERTY)
GB.ReturnString(THIS->proxy.user);
GB.ReturnString(proxy->user);
else
{
if (check_active(THIS))
return;
GB.StoreString(PROP(GB_STRING), &THIS->proxy.user);
GB.StoreString(PROP(GB_STRING), &proxy->user);
}
END_PROPERTY
......@@ -89,14 +97,16 @@ END_PROPERTY
BEGIN_PROPERTY(CurlProxy_Password)
GET_PROXY();
if (READ_PROPERTY)
GB.ReturnString(THIS->proxy.pwd);
GB.ReturnString(proxy->pwd);
else
{
if (check_active(THIS))
return;
GB.StoreString(PROP(GB_STRING), &THIS->proxy.pwd);
GB.StoreString(PROP(GB_STRING), &proxy->pwd);
}
END_PROPERTY
......@@ -104,14 +114,16 @@ END_PROPERTY
BEGIN_PROPERTY (CurlProxy_Host)
GET_PROXY();
if (READ_PROPERTY)
GB.ReturnString(THIS->proxy.host);
GB.ReturnString(proxy->host);
else
{
if (check_active(THIS))
return;
GB.StoreString(PROP(GB_STRING), &THIS->proxy.host);
GB.StoreString(PROP(GB_STRING), &proxy->host);
}
END_PROPERTY
......@@ -119,8 +131,8 @@ END_PROPERTY
GB_DESC CProxyDesc[] =
{
GB_DECLARE(".Curl.Proxy", sizeof(CPROXY)), GB_VIRTUAL_CLASS(),
GB_DECLARE_VIRTUAL(".Curl.Proxy"),
GB_PROPERTY("Host", "s", CurlProxy_Host),
GB_PROPERTY("User", "s", CurlProxy_User),
GB_PROPERTY("Password", "s", CurlProxy_Password),
......
......@@ -33,11 +33,6 @@
extern GB_DESC CProxyDesc[];
#else
#undef THIS
#define THIS (&((CCURL *)_object)->proxy)
#endif
#endif
......@@ -21,6 +21,8 @@
***************************************************************************/
#define __GB_CURL_C
/*****************************
NOTE THAT :
libcurl <= 7.10.7 lacks CURLE_LDAP_INVALID_URL and CURLE_FILESIZE_EXCEEDED constants
......@@ -33,6 +35,8 @@
#include "gbcurl.h"
#include "CCurl.h"
CURL_PROXY CURL_default_proxy = { CURLPROXY_HTTP, CURLAUTH_NONE, NULL, NULL, NULL, NULL };
static char *_protocols[] = { "ftp://", "ftps://", "http://", "https://", NULL };
static void warning(const char *msg)
......@@ -219,15 +223,13 @@ bool CURL_check_userpwd(CURL_USER *user)
void CURL_proxy_init(CURL_PROXY *proxy)
{
proxy->type = CURLPROXY_HTTP;
proxy->auth = CURLAUTH_NONE;
proxy->user = NULL;
proxy->pwd = NULL;
proxy->host = NULL;
proxy->userpwd = NULL;
*proxy = CURL_default_proxy;
GB.RefString(proxy->host);
GB.RefString(proxy->user);
GB.RefString(proxy->pwd);
GB.RefString(proxy->userpwd);
}
void CURL_proxy_clear(CURL_PROXY *proxy)
{
GB.FreeString(&proxy->host);
......@@ -236,6 +238,11 @@ void CURL_proxy_clear(CURL_PROXY *proxy)
GB.FreeString(&proxy->userpwd);
}
void CURL_default_proxy_clear()
{
CURL_proxy_clear(&CURL_default_proxy);
}
void CURL_proxy_set(CURL_PROXY *proxy, CURL *curl)
{
......
......@@ -49,6 +49,12 @@ typedef
}
CURL_USER;
#ifndef __GB_CURL_C
extern CURL_PROXY CURL_default_proxy;
#endif
//char *CURL_get_protocol(char *url, char *default_protocol);
bool CURL_set_url(void *_object, const char *src, int len);
......@@ -60,6 +66,8 @@ void CURL_proxy_set(CURL_PROXY *proxy, CURL *curl);
bool CURL_proxy_set_auth(CURL_PROXY *user, int auth);
bool CURL_proxy_set_type(CURL_PROXY *proxy, int type);
void CURL_default_proxy_clear();
void CURL_user_init(CURL_USER *user);
void CURL_user_clear(CURL_USER *user);
void CURL_user_set(CURL_USER *user,CURL *curl);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment