Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for proxy, in cofiguration #43

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion COGNAC
Submodule COGNAC updated 4 files
+4 −28 cognac_gen.sh
+28 −2 lib.c
+2 −0 lib.h
+27 −1 main_tpl.c
30 changes: 28 additions & 2 deletions osc_sdk.c
Original file line number Diff line number Diff line change
Expand Up @@ -4674,7 +4674,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 @@ -4707,9 +4708,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 @@ -28359,7 +28373,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 @@ -28409,6 +28428,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 @@ -28476,6 +28497,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 osc_sdk.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
Loading