@@ -12,20 +12,48 @@ apiClient_t *apiClient_create() {
12
12
apiClient-> basePath = " {{{basePath}}}" ;
13
13
apiClient-> dataReceived = NULL;
14
14
apiClient-> response_code = 0;
15
- #ifdef BASIC_AUTH
15
+ {{#hasAuthMethods} }
16
+ { {#authMethods} }
17
+ { {#isBasic} }
16
18
apiClient->username = NULL;
17
19
apiClient->password = NULL;
18
- #endif // BASIC_AUTH
19
- #ifdef OAUTH2
20
+ { {/isBasic } }
21
+ { {#isOAuth } }
20
22
apiClient->accessToken = NULL;
21
- #endif // OAUTH2
23
+ { {/isOAuth} }
24
+ { {#isApiKey} }
25
+ apiClient->apiKeys = NULL;
26
+ { {/isApiKey} }
27
+ { {/authMethods} }
28
+ { {/hasAuthMethods} }
29
+
22
30
return apiClient;
23
31
}
24
32
25
33
void apiClient_free(apiClient_t *apiClient) {
26
- if (apiClient-> dataReceived ) {
27
- free(apiClient-> dataReceived );
34
+ if (apiClient-> basePath ) {
35
+ free(apiClient-> basePath );
36
+ }
37
+ { {#hasAuthMethods} }
38
+ { {#authMethods} }
39
+ { {#isBasic} }
40
+ if(apiClient->username) {
41
+ free(apiClient-> username );
42
+ }
43
+ if(apiClient->password) {
44
+ free(apiClient-> password );
28
45
}
46
+ { {/isBasic} }
47
+ { {#isOAuth} }
48
+ if(apiClient->accessToken) {
49
+ free(apiClient-> accessToken );
50
+ }
51
+ { {/isOAuth} }
52
+ { {#isApiKey} }
53
+ list_free(apiClient->apiKeys);
54
+ { {/isApiKey} }
55
+ { {/authMethods} }
56
+ { {/hasAuthMethods} }
29
57
free(apiClient);
30
58
curl_global_cleanup();
31
59
}
@@ -254,11 +282,9 @@ void apiClient_invoke(apiClient_t *apiClient,
254
282
if (strcmp(keyValuePair-> key ,
255
283
" file" ) == 0)
256
284
{
257
- printf(" Size of fileVar - %p\n " ,fileVar);
258
285
memcpy(&fileVar,
259
286
keyValuePair-> value ,
260
287
sizeof(fileVar));
261
- printf(" Size of fileVar1 - %p\n " ,fileVar);
262
288
curl_mime_data(part,
263
289
fileVar-> fileData ,
264
290
fileVar-> fileSize );
@@ -287,8 +313,12 @@ void apiClient_invoke(apiClient_t *apiClient,
287
313
free(headerValueToWrite);
288
314
}
289
315
}
316
+ { {#hasAuthMethods} }
317
+ { {#authMethods} }
318
+ { {#isApiKey} }
290
319
// this would only be generated for apiKey authentication
291
- #ifdef API_KEY
320
+ if (apiClient->apiKeys != NULL)
321
+ {
292
322
list_ForEach(listEntry, apiClient-> apiKeys ) {
293
323
keyValuePair_t *apiKey = listEntry-> data ;
294
324
if ((apiKey-> key != NULL) &&
@@ -300,7 +330,10 @@ void apiClient_invoke(apiClient_t *apiClient,
300
330
free(headerValueToWrite);
301
331
}
302
332
}
303
- #endif // API_KEY
333
+ }
334
+ { {/isApiKey} }
335
+ { {/authMethods} }
336
+ { {/hasAuthMethods} }
304
337
305
338
char *targetUrl =
306
339
assembleTargetUrl(apiClient->basePath,
@@ -316,19 +349,11 @@ void apiClient_invoke(apiClient_t *apiClient,
316
349
&apiClient->dataReceived);
317
350
curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers);
318
351
curl_easy_setopt(handle, CURLOPT_VERBOSE, 0); // to get curl debug msg 0: to disable, 1L:to enable
319
- // this would only be generated for OAuth2 authentication
320
- #ifdef OAUTH2
321
- if(apiClient->accessToken != NULL) {
322
- // curl_easy_setopt(handle, CURLOPT_HTTPAUTH, CURLAUTH_BEARER);
323
- curl_easy_setopt(handle,
324
- CURLOPT_XOAUTH2_BEARER,
325
- apiClient-> accessToken );
326
- }
327
- #endif
328
-
329
352
353
+ { {#hasAuthMethods} }
354
+ { {#authMethods} }
355
+ { {#isBasic} }
330
356
// this would only be generated for basic authentication:
331
- #ifdef BASIC_AUTH
332
357
char *authenticationToken;
333
358
334
359
if((apiClient->username != NULL) &&
@@ -351,8 +376,18 @@ void apiClient_invoke(apiClient_t *apiClient,
351
376
CURLOPT_USERPWD,
352
377
authenticationToken);
353
378
}
354
-
355
- #endif // BASIC_AUTH
379
+ { {/isBasic} }
380
+ { {#isOAuth} }
381
+ // this would only be generated for OAuth2 authentication
382
+ if(apiClient->accessToken != NULL) {
383
+ // curl_easy_setopt(handle, CURLOPT_HTTPAUTH, CURLAUTH_BEARER);
384
+ curl_easy_setopt(handle,
385
+ CURLOPT_XOAUTH2_BEARER,
386
+ apiClient-> accessToken );
387
+ }
388
+ { {/isOAuth} }
389
+ { {/authMethods} }
390
+ { {/hasAuthMethods} }
356
391
357
392
if(bodyParameters != NULL) {
358
393
postData(handle, bodyParameters);
@@ -371,16 +406,27 @@ void apiClient_invoke(apiClient_t *apiClient,
371
406
if(res == CURLE_OK) {
372
407
curl_easy_getinfo(handle, CURLINFO_RESPONSE_CODE, &apiClient-> response_code );
373
408
} else {
374
- fprintf(stderr, " curl_easy_perform() failed: %s\n " ,
409
+ char *url,*ip,*scheme;
410
+ long port;
411
+ curl_easy_getinfo(handle, CURLINFO_EFFECTIVE_URL, &url);
412
+ curl_easy_getinfo(handle, CURLINFO_PRIMARY_IP, &ip);
413
+ curl_easy_getinfo(handle, CURLINFO_PRIMARY_PORT, &port);
414
+ curl_easy_getinfo(handle, CURLINFO_SCHEME, &scheme);
415
+ fprintf(stderr, " curl_easy_perform() failed\n\n URL: %s\n IP: %s\n PORT: %li\n SCHEME: %s\n StrERROR: %s\n " ,url,ip,port,scheme,
375
416
curl_easy_strerror(res));
376
417
}
377
- #ifdef BASIC_AUTH
418
+ { {#hasAuthMethods} }
419
+ { {#authMethods} }
420
+ { {#isBasic} }
378
421
if((apiClient->username != NULL) &&
379
422
(apiClient->password != NULL) )
380
423
{
381
424
free(authenticationToken);
382
425
}
383
- #endif // BASIC_AUTH
426
+ { {/isBasic} }
427
+ { {/authMethods} }
428
+ { {/hasAuthMethods} }
429
+
384
430
curl_easy_cleanup(handle);
385
431
if(formParameters != NULL) {
386
432
free(formString);
0 commit comments