forked from loafle/openapi-generator-original
[C][Client]Support data callback function (#7467)
This commit is contained in:
@@ -13,6 +13,7 @@ apiClient_t *apiClient_create() {
|
||||
apiClient->sslConfig = NULL;
|
||||
apiClient->dataReceived = NULL;
|
||||
apiClient->dataReceivedLen = 0;
|
||||
apiClient->data_callback_func = NULL;
|
||||
apiClient->response_code = 0;
|
||||
{{#hasAuthMethods}}
|
||||
{{#authMethods}}
|
||||
@@ -58,6 +59,7 @@ apiClient_t *apiClient_create_with_base_path(const char *basePath
|
||||
|
||||
apiClient->dataReceived = NULL;
|
||||
apiClient->dataReceivedLen = 0;
|
||||
apiClient->data_callback_func = NULL;
|
||||
apiClient->response_code = 0;
|
||||
{{#hasAuthMethods}}
|
||||
{{#authMethods}}
|
||||
@@ -91,6 +93,7 @@ void apiClient_free(apiClient_t *apiClient) {
|
||||
if(apiClient->basePath) {
|
||||
free(apiClient->basePath);
|
||||
}
|
||||
apiClient->data_callback_func = NULL;
|
||||
{{#hasAuthMethods}}
|
||||
{{#authMethods}}
|
||||
{{#isBasic}}
|
||||
@@ -558,6 +561,10 @@ size_t writeDataCallback(void *buffer, size_t size, size_t nmemb, void *userp) {
|
||||
apiClient->dataReceived = (char *)realloc( apiClient->dataReceived, apiClient->dataReceivedLen + size_this_time + 1);
|
||||
memcpy(apiClient->dataReceived + apiClient->dataReceivedLen, buffer, size_this_time);
|
||||
apiClient->dataReceivedLen += size_this_time;
|
||||
((char*)apiClient->dataReceived)[apiClient->dataReceivedLen] = '\0'; // the space size of (apiClient->dataReceived) = dataReceivedLen + 1
|
||||
if (apiClient->data_callback_func) {
|
||||
apiClient->data_callback_func(&apiClient->dataReceived, &apiClient->dataReceivedLen);
|
||||
}
|
||||
return size_this_time;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ typedef struct apiClient_t {
|
||||
sslConfig_t *sslConfig;
|
||||
void *dataReceived;
|
||||
long dataReceivedLen;
|
||||
void (*data_callback_func)(void **, long *);
|
||||
long response_code;
|
||||
{{#hasAuthMethods}}
|
||||
{{#authMethods}}
|
||||
|
||||
@@ -183,3 +183,18 @@ char* findStrInStrList(list_t *strList, const char *str)
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void clear_and_free_string_list(list_t *list)
|
||||
{
|
||||
if (!list) {
|
||||
return;
|
||||
}
|
||||
|
||||
listEntry_t *listEntry = NULL;
|
||||
list_ForEach(listEntry, list) {
|
||||
char *list_item = listEntry->data;
|
||||
free(list_item);
|
||||
list_item = NULL;
|
||||
}
|
||||
list_free(list);
|
||||
}
|
||||
@@ -38,4 +38,5 @@ void listEntry_printAsInt(listEntry_t* listEntry, void *additionalData);
|
||||
void listEntry_free(listEntry_t *listEntry, void *additionalData);
|
||||
|
||||
char* findStrInStrList(list_t* strList, const char* str);
|
||||
void clear_and_free_string_list(list_t * list);
|
||||
#endif // INCLUDE_LIST_H
|
||||
|
||||
@@ -23,6 +23,7 @@ typedef struct apiClient_t {
|
||||
sslConfig_t *sslConfig;
|
||||
void *dataReceived;
|
||||
long dataReceivedLen;
|
||||
void (*data_callback_func)(void **, long *);
|
||||
long response_code;
|
||||
list_t *apiKeys_api_key;
|
||||
char *accessToken;
|
||||
|
||||
@@ -38,4 +38,5 @@ void listEntry_printAsInt(listEntry_t* listEntry, void *additionalData);
|
||||
void listEntry_free(listEntry_t *listEntry, void *additionalData);
|
||||
|
||||
char* findStrInStrList(list_t* strList, const char* str);
|
||||
void clear_and_free_string_list(list_t * list);
|
||||
#endif // INCLUDE_LIST_H
|
||||
|
||||
@@ -13,6 +13,7 @@ apiClient_t *apiClient_create() {
|
||||
apiClient->sslConfig = NULL;
|
||||
apiClient->dataReceived = NULL;
|
||||
apiClient->dataReceivedLen = 0;
|
||||
apiClient->data_callback_func = NULL;
|
||||
apiClient->response_code = 0;
|
||||
apiClient->apiKeys_api_key = NULL;
|
||||
apiClient->accessToken = NULL;
|
||||
@@ -40,6 +41,7 @@ apiClient_t *apiClient_create_with_base_path(const char *basePath
|
||||
|
||||
apiClient->dataReceived = NULL;
|
||||
apiClient->dataReceivedLen = 0;
|
||||
apiClient->data_callback_func = NULL;
|
||||
apiClient->response_code = 0;
|
||||
if(apiKeys_api_key!= NULL) {
|
||||
apiClient->apiKeys_api_key = list_create();
|
||||
@@ -61,6 +63,7 @@ void apiClient_free(apiClient_t *apiClient) {
|
||||
if(apiClient->basePath) {
|
||||
free(apiClient->basePath);
|
||||
}
|
||||
apiClient->data_callback_func = NULL;
|
||||
if(apiClient->apiKeys_api_key) {
|
||||
listEntry_t *listEntry = NULL;
|
||||
list_ForEach(listEntry, apiClient->apiKeys_api_key) {
|
||||
@@ -464,6 +467,10 @@ size_t writeDataCallback(void *buffer, size_t size, size_t nmemb, void *userp) {
|
||||
apiClient->dataReceived = (char *)realloc( apiClient->dataReceived, apiClient->dataReceivedLen + size_this_time + 1);
|
||||
memcpy(apiClient->dataReceived + apiClient->dataReceivedLen, buffer, size_this_time);
|
||||
apiClient->dataReceivedLen += size_this_time;
|
||||
((char*)apiClient->dataReceived)[apiClient->dataReceivedLen] = '\0'; // the space size of (apiClient->dataReceived) = dataReceivedLen + 1
|
||||
if (apiClient->data_callback_func) {
|
||||
apiClient->data_callback_func(&apiClient->dataReceived, &apiClient->dataReceivedLen);
|
||||
}
|
||||
return size_this_time;
|
||||
}
|
||||
|
||||
|
||||
@@ -183,3 +183,18 @@ char* findStrInStrList(list_t *strList, const char *str)
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void clear_and_free_string_list(list_t *list)
|
||||
{
|
||||
if (!list) {
|
||||
return;
|
||||
}
|
||||
|
||||
listEntry_t *listEntry = NULL;
|
||||
list_ForEach(listEntry, list) {
|
||||
char *list_item = listEntry->data;
|
||||
free(list_item);
|
||||
list_item = NULL;
|
||||
}
|
||||
list_free(list);
|
||||
}
|
||||
Reference in New Issue
Block a user