-
Notifications
You must be signed in to change notification settings - Fork 1
/
lib.c
723 lines (622 loc) · 17.4 KB
/
lib.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
/**
* BSD 3-Clause License
*
* Copyright (c) 2022, Outscale SAS
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**/
/*
* This code is autogenerated, don't edit it directely
*/
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "curl/curl.h"
#include <time.h>
#include <unistd.h>
#include "osc_sdk.h"
#include "json.h"
#define AK_SIZE 20
#define SK_SIZE 40
#define TIMESTAMP_SIZE 17
#define TIME_HDR_KEY "X-Osc-Date: "
#define TIME_HDR_KEY_L (sizeof TIME_HDR_KEY)
#ifdef _WIN32
#define SAFE_C 0
static inline char* stpcpy(char *dest, const char *src)
{
for (; *src; ++src) {
*dest++ = *src;
}
*dest = 0;
return dest;
}
#define CFG_FILE "config.json"
#define LOAD_CFG_GET_HOME(buf) \
{ \
strcpy(buf, CFG_FILE); \
}
#else
#define CFG_FILE "/.osc/config.json"
#define SAFE_C 1
#endif
#ifdef WITH_DESCRIPTION
static const char *calls_name[] = {
____call_list_dec____('\t"'; '",\n '; '\tNULL\n')
};
static const char *calls_descriptions[] = {
____call_list_descriptions____('\t'; ',\n'; '\tNULL\n')
};
static const char *calls_args_descriptions[] = {
____call_list_args_descriptions____('\t'; ',\n'; '\tNULL\n')
};
const char *osc_find_description(const char *call_name)
{
const char **c;
int i = 0;
for (c = calls_name; *c; ++c) {
if (!strcmp(*c, call_name))
return calls_descriptions[i];
++i;
}
return NULL;
}
const char *osc_find_args_description(const char *call_name)
{
const char **c;
int i = 0;
for (c = calls_name; *c; ++c) {
if (!strcmp(*c, call_name))
return calls_args_descriptions[i];
++i;
}
return NULL;
}
const char **osc_calls_name(void)
{
return calls_name;
}
#endif /* WITH_DESCRIPTION */
#ifdef WITH_C11_THREAD_LOCAL
#define THREAD_LOCAL _Thread_local
#else
#define THREAD_LOCAL
#endif
static THREAD_LOCAL const char *cfg_path;
void osc_set_cfg_path(const char *cfg)
{
cfg_path = cfg;
}
const char *osc_set_get_path(void)
{
return cfg_path;
}
void *osc_realloc(void *buf, size_t l)
{
void *ret = realloc(buf, l);
if (!ret)
free(buf);
return ret;
}
/* We don't use _Bool as we try to be C89 compatible */
int osc_str_append_bool(struct osc_str *osc_str, int bool)
{
int len = osc_str->len;
assert(osc_str);
osc_str->len = len + (bool ? 4 : 5);
osc_str->buf = osc_realloc(osc_str->buf, osc_str->len + 1);
if (!osc_str->buf)
return -1;
strcpy(osc_str->buf + len, (bool ? "true" : "false"));
return 0;
}
int osc_str_append_int(struct osc_str *osc_str, long long int i)
{
int len = osc_str->len;
assert(osc_str);
osc_str->buf = osc_realloc(osc_str->buf, len + 64);
if (!osc_str->buf)
return -1;
osc_str->len = len + snprintf(osc_str->buf + len, 64, "%lld", i);
osc_str->buf[osc_str->len] = 0;
return 0;
}
int osc_str_append_double(struct osc_str *osc_str, double i)
{
int len = osc_str->len;
assert(osc_str);
osc_str->buf = osc_realloc(osc_str->buf, len + 64);
if (!osc_str->buf)
return -1;
osc_str->len = len + snprintf(osc_str->buf + len, 64, "%f", i);
osc_str->buf[osc_str->len] = 0;
return 0;
}
int osc_str_append_string(struct osc_str *osc_str, const char *str)
{
if (!str)
return 0;
assert(osc_str);
int len = osc_str->len;
int dlen = strlen(str);
osc_str->len = osc_str->len + dlen;
osc_str->buf = osc_realloc(osc_str->buf, osc_str->len + 1);
if (!osc_str->buf)
return -1;
memcpy(osc_str->buf + len, str, dlen + 1);
return 0;
}
int osc_str_append_n_string(struct osc_str *osc_str, const char *str, int l)
{
if (!str)
return 0;
assert(osc_str);
int len = osc_str->len;
osc_str->len = osc_str->len + l;
osc_str->buf = osc_realloc(osc_str->buf, osc_str->len + 1);
if (!osc_str->buf)
return -1;
memcpy(osc_str->buf + len, str, l);
osc_str->buf[len + l] = 0;
return 0;
}
static char *osc_strdup(const char *str) {
if (!str)
return NULL;
return strdup(str);
}
#define TRY(test, ...) \
if (test) { fprintf(stderr, __VA_ARGS__); return -1; }
#define STRY(test, ...) \
if (test) return -1
#define TRY_APPEND_COL(count_args, data) \
if (count_args++ > 0) \
STRY(osc_str_append_string(data, "," ));
#ifndef LOAD_CFG_GET_HOME
#define LOAD_CFG_GET_HOME(buf) \
{ \
const char *dest = CFG_FILE; \
char *home = getenv("HOME"); \
\
TRY(strlen(home) + sizeof CFG_FILE > sizeof buf, \
"home path too big"); \
strcpy(stpcpy(buf, home), dest); \
}
#endif
#define ARG_TO_JSON_STR(separator, what) do { \
auto_osc_str struct osc_str s; \
char *tmp = what; \
char *endl; \
\
osc_init_str(&s); \
while((endl = strchr(tmp, '\n')) != NULL) { \
int l = endl - tmp; \
\
osc_str_append_n_string(&s, tmp, l); \
osc_str_append_string(&s, "\\n"); \
tmp = endl + 1; \
} \
osc_str_append_string(&s, tmp); \
STRY(osc_str_append_string(data, separator)); \
STRY(osc_str_append_string(data, "\"" )); \
STRY(osc_str_append_string(data, s.buf)); \
STRY(osc_str_append_string(data, "\"" )); \
} while (0)
#define ARG_TO_JSON(name, type, what) do { \
TRY_APPEND_COL(count_args, data); \
STRY(osc_str_append_string(data, "\""#name"\":" )); \
STRY(osc_str_append_##type(data, what)); \
} while (0)
int osc_load_ak_sk_from_conf(const char *profile, char **ak, char **sk)
{
char buf[1024];
const char *cfg = cfg_path;
struct json_object *js, *ak_js, *sk_js;
auto_osc_json_c struct json_object *to_free = NULL;
if (!ak && !sk)
return 0;
if (!cfg) {
LOAD_CFG_GET_HOME(buf);
cfg = buf;
}
if (sk)
*sk = NULL;
if (ak)
*ak = NULL;
TRY(access(cfg, R_OK), "can't open/read %s\n", cfg);
js = json_object_from_file(cfg);
TRY(!js, "can't load json-file %s (json might have incorect syntaxe)\n", cfg);
to_free = js;
js = json_object_object_get(js, profile);
TRY(!js, "can't find profile %s\n", profile);
if (ak) {
ak_js = json_object_object_get(js, "access_key");
TRY(!ak_js, "can't find 'access_key' in profile '%s'\n", profile);
*ak = strdup(json_object_get_string(json_object_object_get(js, "access_key")));
}
if (sk) {
sk_js = json_object_object_get(js, "secret_key");
TRY(!sk_js, "can't find 'secret_key' in profile '%s'\n", profile);
*sk = strdup(json_object_get_string(json_object_object_get(js, "secret_key")));
}
return 0;
}
int osc_load_loging_password_from_conf(const char *profile,
char **email, char **password)
{
char buf[1024];
const char *cfg = cfg_path;
auto_osc_json_c struct json_object *to_free = NULL;
struct json_object *js, *login_js, *pass_js;
if (!email && !password)
return 0;
if (!cfg) {
LOAD_CFG_GET_HOME(buf);
cfg = buf;
}
if (password)
*password = NULL;
if (email)
*email = NULL;
js = json_object_from_file(cfg);
TRY(!js, "can't open %s\n", cfg);
to_free = js;
js = json_object_object_get(js, profile);
TRY(!js, "can't find profile '%s'\n", profile);
if (email) {
login_js = json_object_object_get(js, "login");
TRY(!login_js, "can't find 'login' in profile '%s'\n", profile);
*email = osc_strdup(json_object_get_string(login_js));
}
if (password) {
pass_js = json_object_object_get(js, "password");
if (!pass_js) {
return 0; /* is optional */
}
*password = osc_strdup(json_object_get_string(pass_js));
}
return 0;
}
int osc_load_region_from_conf(const char *profile, char **region)
{
struct json_object *region_obj;
const char *cfg = cfg_path;
char buf[1024];
struct json_object *js;
auto_osc_json_c struct json_object *to_free = NULL;
if (!cfg) {
LOAD_CFG_GET_HOME(buf);
cfg = buf;
}
js = json_object_from_file(cfg);
TRY(!js, "can't open %s\n", cfg);
to_free = js;
js = json_object_object_get(js, profile);
if (!js)
return -1;
region_obj = json_object_object_get(js, "region");
if (!region_obj) {
return -1;
}
*region = osc_strdup(json_object_get_string(region_obj));
return 0;
}
static int osc_load_cert_from_conf_(const char *profile, char **cert, char **key,
char **proxy, char **endpoint)
{
struct json_object *cert_obj, *key_obj, *js;
const char *cfg = cfg_path;
auto_osc_json_c struct json_object *to_free = NULL;
char buf[1024];
int ret = 0;
if (!cfg) {
LOAD_CFG_GET_HOME(buf);
cfg = buf;
}
js = json_object_from_file(cfg);
TRY(!js, "can't open %s\n", cfg);
to_free = js;
js = json_object_object_get(js, profile);
if (!js)
return 0;
cert_obj = json_object_object_get(js, "x509_client_cert");
if (!cert_obj)
cert_obj = json_object_object_get(js, "client_certificate");
if (cert_obj) {
*cert = osc_strdup(json_object_get_string(cert_obj));
ret |= OSC_ENV_FREE_CERT;
}
key_obj = json_object_object_get(js, "x509_client_sslkey");
if (key_obj) {
*key = osc_strdup(json_object_get_string(key_obj));
ret |= OSC_ENV_FREE_SSLKEY;
}
if (proxy) {
key_obj = json_object_object_get(js, "proxy");
if (key_obj) {
*proxy = osc_strdup(json_object_get_string(key_obj));
ret |= OSC_ENV_FREE_PROXY;
}
}
if (endpoint) {
struct json_object *e = json_object_object_get(js, "endpoints");
if (e)
e = json_object_object_get(e, "api");
else
e = json_object_object_get(js, "endpoint");
if (e) {
*endpoint = osc_strdup(json_object_get_string(e));
ret |= OSC_ENV_FREE_ENDPOINT;
}
}
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, 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)
{
size_t bufsize = size * nmemb;
struct osc_str *response = userp;
int olen = response->len;
response->len = response->len + bufsize;
response->buf = osc_realloc(response->buf, response->len + 1);
memcpy(response->buf + olen, data, bufsize);
response->buf[response->len] = 0;
return bufsize;
}
void osc_init_str(struct osc_str *r)
{
r->len = 0;
r->buf = NULL;
}
void osc_deinit_json_c(json_object **j)
{
if (j && *j)
json_object_put(*j);
}
void osc_deinit_str(struct osc_str *r)
{
free(r->buf);
osc_init_str(r);
}
____complex_struct_to_string_func____
____func_code____
int osc_sdk_set_useragent(struct osc_env *e, const char *str)
{
return curl_easy_setopt(e->c, CURLOPT_USERAGENT, str);
}
static inline char *cfg_login(struct osc_env_conf *cfg)
{
if (!cfg)
return NULL;
return cfg->login;
}
static inline char *cfg_pass(struct osc_env_conf *cfg)
{
if (!cfg)
return NULL;
return cfg->password;
}
int osc_init_sdk_ext(struct osc_env *e, const char *profile, unsigned int flag,
struct osc_env_conf *cfg)
{
*e = (struct osc_env){0};
char *ca = getenv("CURL_CA_BUNDLE");
char *endpoint;
char user_agent[sizeof "osc-sdk-c/" + OSC_SDK_VERSON_L];
char *cert = getenv("OSC_X509_CLIENT_CERT");
char *sslkey = getenv("OSC_X509_CLIENT_KEY");
char *auth = getenv("OSC_AUTH_METHOD");
char *force_log = cfg_login(cfg);
char *force_pass = cfg_pass(cfg);
strcpy(stpcpy(user_agent, "osc-sdk-c/"), osc_sdk_version_str());
e->region = getenv("OSC_REGION");
e->flag = flag;
e->auth_method = cfg ? cfg->auth_method : OSC_AKSK_METHOD;
endpoint = getenv("OSC_ENDPOINT_API");
osc_init_str(&e->endpoint);
if (auth && (!strcmp(auth, "password") || !strcmp(auth, "basic"))) {
e->auth_method = OSC_PASSWORD_METHOD;
} else if (auth && !strcmp(auth, "none")) {
e->auth_method = OSC_NONE_METHOD;
} else if (auth && strcmp(auth, "accesskey")) {
fprintf(stderr, "'%s' invalid authentication method\n", auth);
return -1;
}
if (force_log)
e->ak = force_log;
if (force_pass)
e->sk = force_pass;
if (!profile && e->auth_method != OSC_NONE_METHOD) {
profile = getenv("OSC_PROFILE");
if (e->auth_method == OSC_PASSWORD_METHOD) {
if (!force_log)
e->ak = getenv("OSC_LOGIN");
if (!force_pass)
e->sk = getenv("OSC_PASSWORD");
} else {
if (!force_log)
e->ak = getenv("OSC_ACCESS_KEY");
if (!force_pass)
e->sk = getenv("OSC_SECRET_KEY");
}
if (!profile && (!e->ak || !e->sk))
profile = "default";
}
if (profile && e->auth_method != OSC_NONE_METHOD) {
int f;
if (e->auth_method == OSC_PASSWORD_METHOD) {
STRY(osc_load_loging_password_from_conf(
profile, force_log ? NULL : &e->ak,
force_pass ? NULL : &e->sk) < 0);
if (!force_log)
e->flag |= OSC_ENV_FREE_AK;
if (!force_pass) {
if (!e->sk)
e->sk = getenv("OSC_PASSWORD");
else
e->flag |= OSC_ENV_FREE_SK;
}
} else {
STRY(osc_load_ak_sk_from_conf(
profile, force_log ? NULL : &e->ak,
force_pass ? NULL : &e->sk) < 0);
if (!force_log)
e->flag |= OSC_ENV_FREE_AK;
if (!force_pass)
e->flag |= OSC_ENV_FREE_SK;
}
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,
&e->proxy, &e->endpoint_allocated_);
if (e->cert)
cert = e->cert;
if (e->sslkey)
sslkey = e->sslkey;
if (f < 0)
return -1;
e->flag |= f;
}
if (!e->region)
e->region = "eu-west-2";
if (!endpoint && !e->endpoint_allocated_) {
osc_str_append_string(&e->endpoint, "https://api.");
osc_str_append_string(&e->endpoint, e->region);
osc_str_append_string(&e->endpoint, ".outscale.com");
} else {
if (e->endpoint_allocated_) {
osc_str_append_string(&e->endpoint,
e->endpoint_allocated_);
} else {
osc_str_append_string(&e->endpoint, endpoint);
}
}
if (e->auth_method == OSC_AKSK_METHOD) {
if (!e->ak || !e->sk) {
fprintf(stderr, "access key and secret key needed\n");
return -1;
}
if (strlen(e->ak) != AK_SIZE || strlen(e->sk) != SK_SIZE) {
fprintf(stderr, "Wrong access key or secret key size\n");
return -1;
}
} else if (e->auth_method == OSC_PASSWORD_METHOD) {
if (!e->ak || !e->sk) {
fprintf(stderr, "login and password needed\n");
return -1;
}
}
e->headers = NULL;
e->c = curl_easy_init();
#ifdef _WIN32
curl_easy_setopt(e->c, CURLOPT_SSL_OPTIONS, (long)CURLSSLOPT_NATIVE_CA);
#endif
/* Setting HEADERS */
if (flag & OSC_VERBOSE_MODE)
curl_easy_setopt(e->c, CURLOPT_VERBOSE, 1);
if (flag & OSC_INSECURE_MODE)
curl_easy_setopt(e->c, CURLOPT_SSL_VERIFYPEER, 0);
if (cert)
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);
/* setting CA if CURL_CA_BUNDLE is set */
if (ca)
curl_easy_setopt(e->c, CURLOPT_CAINFO, ca);
e->headers = curl_slist_append(e->headers, "Content-Type: application/json");
/* For authentification we specify the method and our acces key / secret key */
if (e->auth_method == OSC_AKSK_METHOD) {
curl_easy_setopt(e->c, CURLOPT_AWS_SIGV4, "osc");
} else if (e->auth_method == OSC_PASSWORD_METHOD) {
time_t clock;
struct tm tm;
struct tm *tmp;
char time_hdr[TIME_HDR_KEY_L + TIMESTAMP_SIZE] = TIME_HDR_KEY;
time(&clock);
#if SAFE_C == 1
TRY(!gmtime_r(&clock, &tm), "gmtime_r fail\n");\
tmp = &tm;
#else
(void)tm;
tmp = gmtime(&clock);
TRY(!tmp, "gmtime fail\n");
#endif
strftime(time_hdr + TIME_HDR_KEY_L - 1,
TIMESTAMP_SIZE, "%Y%m%dT%H%M%SZ", tmp);
e->headers = curl_slist_append(e->headers, time_hdr);
}
curl_easy_setopt(e->c, CURLOPT_HTTPHEADER, e->headers);
if (e->auth_method != OSC_NONE_METHOD) {
curl_easy_setopt(e->c, CURLOPT_USERNAME, e->ak);
curl_easy_setopt(e->c, CURLOPT_PASSWORD, e->sk);
}
return 0;
}
int osc_init_sdk(struct osc_env *e, const char *profile, unsigned int flag)
{
return osc_init_sdk_ext(e, profile, flag, NULL);
}
void osc_deinit_sdk(struct osc_env *e)
{
curl_slist_free_all(e->headers);
curl_easy_cleanup(e->c);
osc_deinit_str(&e->endpoint);
if (e->flag & OSC_ENV_FREE_AK) {
free(e->ak);
e->ak = NULL;
}
if (e->flag & OSC_ENV_FREE_SK) {
free(e->sk);
e->sk = NULL;
}
if (e->flag & OSC_ENV_FREE_REGION) {
free(e->region);
e->region = NULL;
}
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);
}
if (e->flag & OSC_ENV_FREE_ENDPOINT) {
free(e->endpoint_allocated_);
}
e->c = NULL;
e->flag = 0;
}