Skip to content

Commit

Permalink
support proxy
Browse files Browse the repository at this point in the history
Signed-off-by: Matthias Gatto <matthias.gatto@outscale.com>
  • Loading branch information
outscale-mgo committed Jun 13, 2024
1 parent 6639982 commit 15b4b83
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
30 changes: 28 additions & 2 deletions lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,8 @@ int osc_load_region_from_conf(const char *profile, char **region)
return 0;
}

int osc_load_cert_from_conf(const char *profile, char **cert, char **key)
static int osc_load_cert_from_conf_(const char *profile, char **cert, char **key,
char **proxy)
{
struct json_object *cert_obj, *key_obj, *js;
const char *cfg = cfg_path;
Expand Down Expand Up @@ -414,9 +415,22 @@ int osc_load_cert_from_conf(const char *profile, char **cert, char **key)
ret |= OSC_ENV_FREE_SSLKEY;
}

if (proxy) {
key_obj = json_object_object_get(js, "proxy");
if (key_obj) {
*key = osc_strdup(json_object_get_string(key_obj));
ret |= OSC_ENV_FREE_PROXY;
}
}

return 0;
}

int osc_load_cert_from_conf(const char *profile, char **cert, char **key)
{
return osc_load_cert_from_conf_(profile, cert, key, NULL);
}

/* Function that will write the data inside a variable */
static size_t write_data(void *data, size_t size, size_t nmemb, void *userp)
{
Expand Down Expand Up @@ -548,7 +562,12 @@ int osc_init_sdk_ext(struct osc_env *e, const char *profile, unsigned int flag,
}
if (!osc_load_region_from_conf(profile, &e->region))
e->flag |= OSC_ENV_FREE_REGION;
f = osc_load_cert_from_conf(profile, &e->cert, &e->sslkey);
f = osc_load_cert_from_conf_(profile, &e->cert, &e->sslkey,
&e->proxy);
if (e->cert)
cert = e->cert;
if (e->sslkey)
sslkey = e->sslkey;
if (f < 0)
return -1;
e->flag |= f;
Expand Down Expand Up @@ -598,6 +617,8 @@ int osc_init_sdk_ext(struct osc_env *e, const char *profile, unsigned int flag,
curl_easy_setopt(e->c, CURLOPT_SSLCERT, cert);
if (sslkey)
curl_easy_setopt(e->c, CURLOPT_SSLKEY, sslkey);
if (e->proxy)
curl_easy_setopt(e->c, CURLOPT_PROXY, e->proxy);
curl_easy_setopt(e->c, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(e->c, CURLOPT_USERAGENT, user_agent);

Expand Down Expand Up @@ -665,6 +686,11 @@ void osc_deinit_sdk(struct osc_env *e)
if (e->flag & OSC_ENV_FREE_CERT) {
free(e->cert);
}

if (e->flag & OSC_ENV_FREE_PROXY) {
free(e->proxy);
}

if (e->flag & OSC_ENV_FREE_SSLKEY) {
free(e->sslkey);
}
Expand Down
2 changes: 2 additions & 0 deletions lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ struct osc_str {
#define OSC_ENV_FREE_CERT 1 << 4
#define OSC_ENV_FREE_SSLKEY 1 << 5
#define OSC_ENV_FREE_SK 1 << 6
#define OSC_ENV_FREE_PROXY 1 << 7

#define OSC_ENV_FREE_AK_SK (OSC_ENV_FREE_AK | OSC_ENV_FREE_SK)

Expand All @@ -96,6 +97,7 @@ struct osc_env {
char *region;
char *cert;
char *sslkey;
char *proxy;
int flag;
enum osc_auth_method auth_method;
struct curl_slist *headers;
Expand Down

0 comments on commit 15b4b83

Please sign in to comment.