@@ -12,20 +12,48 @@ apiClient_t *apiClient_create() {
1212 apiClient-> basePath = " {{{basePath}}}" ;
1313 apiClient-> dataReceived = NULL;
1414 apiClient-> response_code = 0;
15- #ifdef BASIC_AUTH
15+ {{#hasAuthMethods} }
16+ { {#authMethods} }
17+ { {#isBasic} }
1618 apiClient->username = NULL;
1719 apiClient->password = NULL;
18- #endif // BASIC_AUTH
19- #ifdef OAUTH2
20+ { {/isBasic } }
21+ { {#isOAuth } }
2022 apiClient->accessToken = NULL;
21- #endif // OAUTH2
23+ { {/isOAuth} }
24+ { {#isApiKey} }
25+ apiClient->apiKeys = NULL;
26+ { {/isApiKey} }
27+ { {/authMethods} }
28+ { {/hasAuthMethods} }
29+
2230 return apiClient;
2331}
2432
2533void 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 );
2845 }
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} }
2957 free(apiClient);
3058 curl_global_cleanup();
3159}
@@ -254,11 +282,9 @@ void apiClient_invoke(apiClient_t *apiClient,
254282 if (strcmp(keyValuePair-> key ,
255283 " file" ) == 0)
256284 {
257- printf(" Size of fileVar - %p\n " ,fileVar);
258285 memcpy(&fileVar,
259286 keyValuePair-> value ,
260287 sizeof(fileVar));
261- printf(" Size of fileVar1 - %p\n " ,fileVar);
262288 curl_mime_data(part,
263289 fileVar-> fileData ,
264290 fileVar-> fileSize );
@@ -287,8 +313,12 @@ void apiClient_invoke(apiClient_t *apiClient,
287313 free(headerValueToWrite);
288314 }
289315 }
316+ { {#hasAuthMethods} }
317+ { {#authMethods} }
318+ { {#isApiKey} }
290319 // this would only be generated for apiKey authentication
291- #ifdef API_KEY
320+ if (apiClient->apiKeys != NULL)
321+ {
292322 list_ForEach(listEntry, apiClient-> apiKeys ) {
293323 keyValuePair_t *apiKey = listEntry-> data ;
294324 if ((apiKey-> key != NULL) &&
@@ -300,7 +330,10 @@ void apiClient_invoke(apiClient_t *apiClient,
300330 free(headerValueToWrite);
301331 }
302332 }
303- #endif // API_KEY
333+ }
334+ { {/isApiKey} }
335+ { {/authMethods} }
336+ { {/hasAuthMethods} }
304337
305338 char *targetUrl =
306339 assembleTargetUrl(apiClient->basePath,
@@ -316,19 +349,11 @@ void apiClient_invoke(apiClient_t *apiClient,
316349 &apiClient->dataReceived);
317350 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers);
318351 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-
329352
353+ { {#hasAuthMethods} }
354+ { {#authMethods} }
355+ { {#isBasic} }
330356 // this would only be generated for basic authentication:
331- #ifdef BASIC_AUTH
332357 char *authenticationToken;
333358
334359 if((apiClient->username != NULL) &&
@@ -351,8 +376,18 @@ void apiClient_invoke(apiClient_t *apiClient,
351376 CURLOPT_USERPWD,
352377 authenticationToken);
353378 }
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} }
356391
357392 if(bodyParameters != NULL) {
358393 postData(handle, bodyParameters);
@@ -371,16 +406,27 @@ void apiClient_invoke(apiClient_t *apiClient,
371406 if(res == CURLE_OK) {
372407 curl_easy_getinfo(handle, CURLINFO_RESPONSE_CODE, &apiClient-> response_code );
373408 } 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,
375416 curl_easy_strerror(res));
376417 }
377- #ifdef BASIC_AUTH
418+ { {#hasAuthMethods} }
419+ { {#authMethods} }
420+ { {#isBasic} }
378421 if((apiClient->username != NULL) &&
379422 (apiClient->password != NULL) )
380423 {
381424 free(authenticationToken);
382425 }
383- #endif // BASIC_AUTH
426+ { {/isBasic} }
427+ { {/authMethods} }
428+ { {/hasAuthMethods} }
429+
384430 curl_easy_cleanup(handle);
385431 if(formParameters != NULL) {
386432 free(formString);
0 commit comments