forked from loafle/openapi-generator-original
[C][Client] Support progress function of libcurl (#7974)
This commit is contained in:
@@ -13,6 +13,8 @@ apiClient_t *apiClient_create() {
|
||||
apiClient->dataReceived = NULL;
|
||||
apiClient->dataReceivedLen = 0;
|
||||
apiClient->data_callback_func = NULL;
|
||||
apiClient->progress_func = NULL;
|
||||
apiClient->progress_data = NULL;
|
||||
apiClient->response_code = 0;
|
||||
{{#hasAuthMethods}}
|
||||
{{#authMethods}}
|
||||
@@ -58,6 +60,8 @@ apiClient_t *apiClient_create_with_base_path(const char *basePath
|
||||
apiClient->dataReceived = NULL;
|
||||
apiClient->dataReceivedLen = 0;
|
||||
apiClient->data_callback_func = NULL;
|
||||
apiClient->progress_func = NULL;
|
||||
apiClient->progress_data = NULL;
|
||||
apiClient->response_code = 0;
|
||||
{{#hasAuthMethods}}
|
||||
{{#authMethods}}
|
||||
@@ -92,6 +96,8 @@ void apiClient_free(apiClient_t *apiClient) {
|
||||
free(apiClient->basePath);
|
||||
}
|
||||
apiClient->data_callback_func = NULL;
|
||||
apiClient->progress_func = NULL;
|
||||
apiClient->progress_data = NULL;
|
||||
{{#hasAuthMethods}}
|
||||
{{#authMethods}}
|
||||
{{#isBasic}}
|
||||
@@ -434,6 +440,14 @@ void apiClient_invoke(apiClient_t *apiClient,
|
||||
}
|
||||
}
|
||||
|
||||
if (apiClient->progress_func != NULL) {
|
||||
curl_easy_setopt(handle, CURLOPT_XFERINFOFUNCTION, apiClient->progress_func);
|
||||
if (apiClient->progress_data != NULL) {
|
||||
curl_easy_setopt(handle, CURLOPT_XFERINFODATA, apiClient->progress_data);
|
||||
}
|
||||
curl_easy_setopt(handle, CURLOPT_NOPROGRESS, 0L);
|
||||
}
|
||||
|
||||
{{#hasAuthMethods}}
|
||||
{{#authMethods}}
|
||||
{{#isApiKey}}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <curl/curl.h>
|
||||
#include "../include/list.h"
|
||||
#include "../include/keyValuePair.h"
|
||||
#include "../include/binary.h"
|
||||
@@ -24,6 +25,8 @@ typedef struct apiClient_t {
|
||||
void *dataReceived;
|
||||
long dataReceivedLen;
|
||||
void (*data_callback_func)(void **, long *);
|
||||
int (*progress_func)(void *, curl_off_t, curl_off_t, curl_off_t, curl_off_t);
|
||||
void *progress_data;
|
||||
long response_code;
|
||||
{{#hasAuthMethods}}
|
||||
{{#authMethods}}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <curl/curl.h>
|
||||
#include "../include/list.h"
|
||||
#include "../include/keyValuePair.h"
|
||||
#include "../include/binary.h"
|
||||
@@ -24,6 +25,8 @@ typedef struct apiClient_t {
|
||||
void *dataReceived;
|
||||
long dataReceivedLen;
|
||||
void (*data_callback_func)(void **, long *);
|
||||
int (*progress_func)(void *, curl_off_t, curl_off_t, curl_off_t, curl_off_t);
|
||||
void *progress_data;
|
||||
long response_code;
|
||||
list_t *apiKeys_api_key;
|
||||
char *accessToken;
|
||||
|
||||
@@ -13,6 +13,8 @@ apiClient_t *apiClient_create() {
|
||||
apiClient->dataReceived = NULL;
|
||||
apiClient->dataReceivedLen = 0;
|
||||
apiClient->data_callback_func = NULL;
|
||||
apiClient->progress_func = NULL;
|
||||
apiClient->progress_data = NULL;
|
||||
apiClient->response_code = 0;
|
||||
apiClient->apiKeys_api_key = NULL;
|
||||
apiClient->accessToken = NULL;
|
||||
@@ -40,6 +42,8 @@ apiClient_t *apiClient_create_with_base_path(const char *basePath
|
||||
apiClient->dataReceived = NULL;
|
||||
apiClient->dataReceivedLen = 0;
|
||||
apiClient->data_callback_func = NULL;
|
||||
apiClient->progress_func = NULL;
|
||||
apiClient->progress_data = NULL;
|
||||
apiClient->response_code = 0;
|
||||
if(apiKeys_api_key!= NULL) {
|
||||
apiClient->apiKeys_api_key = list_create();
|
||||
@@ -62,6 +66,8 @@ void apiClient_free(apiClient_t *apiClient) {
|
||||
free(apiClient->basePath);
|
||||
}
|
||||
apiClient->data_callback_func = NULL;
|
||||
apiClient->progress_func = NULL;
|
||||
apiClient->progress_data = NULL;
|
||||
if(apiClient->apiKeys_api_key) {
|
||||
listEntry_t *listEntry = NULL;
|
||||
list_ForEach(listEntry, apiClient->apiKeys_api_key) {
|
||||
@@ -388,6 +394,14 @@ void apiClient_invoke(apiClient_t *apiClient,
|
||||
}
|
||||
}
|
||||
|
||||
if (apiClient->progress_func != NULL) {
|
||||
curl_easy_setopt(handle, CURLOPT_XFERINFOFUNCTION, apiClient->progress_func);
|
||||
if (apiClient->progress_data != NULL) {
|
||||
curl_easy_setopt(handle, CURLOPT_XFERINFODATA, apiClient->progress_data);
|
||||
}
|
||||
curl_easy_setopt(handle, CURLOPT_NOPROGRESS, 0L);
|
||||
}
|
||||
|
||||
// this would only be generated for apiKey authentication
|
||||
if (apiClient->apiKeys_api_key != NULL)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user