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

[C][Client] Support progress function of libcurl #7974

Merged
merged 1 commit into from
Nov 25, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down Expand Up @@ -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}}
Expand Down Expand Up @@ -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}}
Expand Down Expand Up @@ -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}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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}}
Expand Down
3 changes: 3 additions & 0 deletions samples/client/petstore/c/include/apiClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions samples/client/petstore/c/src/apiClient.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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) {
Expand Down Expand Up @@ -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)
{
Expand Down