Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
[C][Client]Fix data lost when libcurl write-data callback function is…
… called multiple times (Reset count)
  • Loading branch information
ityuhui committed Apr 11, 2020
commit b6fb22fe943d448c596bef0ebb05e755ec4130a5
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,8 @@ end:
if (apiClient->dataReceived) {
free(apiClient->dataReceived);
apiClient->dataReceived = NULL;
apiClient->dataReceivedLen = 0;
}
apiClient->dataReceivedLen = 0;
{{#hasQueryParams}}list_free(localVarQueryParameters);{{/hasQueryParams}}
{{#hasHeaderParams}}list_free(localVarHeaderParameters);{{/hasHeaderParams}}
{{#hasFormParams}}list_free(localVarFormParameters);{{/hasFormParams}}
Expand Down Expand Up @@ -466,8 +466,8 @@ end:
if (apiClient->dataReceived) {
free(apiClient->dataReceived);
apiClient->dataReceived = NULL;
apiClient->dataReceivedLen = 0;
}
apiClient->dataReceivedLen = 0;
{{#hasQueryParams}}list_free(localVarQueryParameters);{{/hasQueryParams}}
{{#hasHeaderParams}}list_free(localVarHeaderParameters);{{/hasHeaderParams}}
{{#hasFormParams}}list_free(localVarFormParameters);{{/hasFormParams}}
Expand Down
16 changes: 8 additions & 8 deletions samples/client/petstore/c/api/PetAPI.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ PetAPI_addPet(apiClient_t *apiClient, pet_t * body )
if (apiClient->dataReceived) {
free(apiClient->dataReceived);
apiClient->dataReceived = NULL;
apiClient->dataReceivedLen = 0;
}
apiClient->dataReceivedLen = 0;



Expand Down Expand Up @@ -179,8 +179,8 @@ PetAPI_deletePet(apiClient_t *apiClient, long petId , char * api_key )
if (apiClient->dataReceived) {
free(apiClient->dataReceived);
apiClient->dataReceived = NULL;
apiClient->dataReceivedLen = 0;
}
apiClient->dataReceivedLen = 0;

list_free(localVarHeaderParameters);

Expand Down Expand Up @@ -261,8 +261,8 @@ PetAPI_findPetsByStatus(apiClient_t *apiClient, list_t * status )
if (apiClient->dataReceived) {
free(apiClient->dataReceived);
apiClient->dataReceived = NULL;
apiClient->dataReceivedLen = 0;
}
apiClient->dataReceivedLen = 0;
list_free(localVarQueryParameters);


Expand Down Expand Up @@ -342,8 +342,8 @@ PetAPI_findPetsByTags(apiClient_t *apiClient, list_t * tags )
if (apiClient->dataReceived) {
free(apiClient->dataReceived);
apiClient->dataReceived = NULL;
apiClient->dataReceivedLen = 0;
}
apiClient->dataReceivedLen = 0;
list_free(localVarQueryParameters);


Expand Down Expand Up @@ -424,8 +424,8 @@ PetAPI_getPetById(apiClient_t *apiClient, long petId )
if (apiClient->dataReceived) {
free(apiClient->dataReceived);
apiClient->dataReceived = NULL;
apiClient->dataReceivedLen = 0;
}
apiClient->dataReceivedLen = 0;



Expand Down Expand Up @@ -493,8 +493,8 @@ PetAPI_updatePet(apiClient_t *apiClient, pet_t * body )
if (apiClient->dataReceived) {
free(apiClient->dataReceived);
apiClient->dataReceived = NULL;
apiClient->dataReceivedLen = 0;
}
apiClient->dataReceivedLen = 0;



Expand Down Expand Up @@ -582,8 +582,8 @@ PetAPI_updatePetWithForm(apiClient_t *apiClient, long petId , char * name , char
if (apiClient->dataReceived) {
free(apiClient->dataReceived);
apiClient->dataReceived = NULL;
apiClient->dataReceivedLen = 0;
}
apiClient->dataReceivedLen = 0;


list_free(localVarFormParameters);
Expand Down Expand Up @@ -684,8 +684,8 @@ PetAPI_uploadFile(apiClient_t *apiClient, long petId , char * additionalMetadata
if (apiClient->dataReceived) {
free(apiClient->dataReceived);
apiClient->dataReceived = NULL;
apiClient->dataReceivedLen = 0;
}
apiClient->dataReceivedLen = 0;


list_free(localVarFormParameters);
Expand Down
8 changes: 4 additions & 4 deletions samples/client/petstore/c/api/StoreAPI.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ StoreAPI_deleteOrder(apiClient_t *apiClient, char * orderId )
if (apiClient->dataReceived) {
free(apiClient->dataReceived);
apiClient->dataReceived = NULL;
apiClient->dataReceivedLen = 0;
}
apiClient->dataReceivedLen = 0;



Expand Down Expand Up @@ -124,8 +124,8 @@ StoreAPI_getInventory(apiClient_t *apiClient)
if (apiClient->dataReceived) {
free(apiClient->dataReceived);
apiClient->dataReceived = NULL;
apiClient->dataReceivedLen = 0;
}
apiClient->dataReceivedLen = 0;



Expand Down Expand Up @@ -206,8 +206,8 @@ StoreAPI_getOrderById(apiClient_t *apiClient, long orderId )
if (apiClient->dataReceived) {
free(apiClient->dataReceived);
apiClient->dataReceived = NULL;
apiClient->dataReceivedLen = 0;
}
apiClient->dataReceivedLen = 0;



Expand Down Expand Up @@ -279,8 +279,8 @@ StoreAPI_placeOrder(apiClient_t *apiClient, order_t * body )
if (apiClient->dataReceived) {
free(apiClient->dataReceived);
apiClient->dataReceived = NULL;
apiClient->dataReceivedLen = 0;
}
apiClient->dataReceivedLen = 0;



Expand Down
16 changes: 8 additions & 8 deletions samples/client/petstore/c/api/UserAPI.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ UserAPI_createUser(apiClient_t *apiClient, user_t * body )
if (apiClient->dataReceived) {
free(apiClient->dataReceived);
apiClient->dataReceived = NULL;
apiClient->dataReceivedLen = 0;
}
apiClient->dataReceivedLen = 0;



Expand Down Expand Up @@ -139,8 +139,8 @@ UserAPI_createUsersWithArrayInput(apiClient_t *apiClient, list_t * body )
if (apiClient->dataReceived) {
free(apiClient->dataReceived);
apiClient->dataReceived = NULL;
apiClient->dataReceivedLen = 0;
}
apiClient->dataReceivedLen = 0;



Expand Down Expand Up @@ -220,8 +220,8 @@ UserAPI_createUsersWithListInput(apiClient_t *apiClient, list_t * body )
if (apiClient->dataReceived) {
free(apiClient->dataReceived);
apiClient->dataReceived = NULL;
apiClient->dataReceivedLen = 0;
}
apiClient->dataReceivedLen = 0;



Expand Down Expand Up @@ -287,8 +287,8 @@ UserAPI_deleteUser(apiClient_t *apiClient, char * username )
if (apiClient->dataReceived) {
free(apiClient->dataReceived);
apiClient->dataReceived = NULL;
apiClient->dataReceivedLen = 0;
}
apiClient->dataReceivedLen = 0;



Expand Down Expand Up @@ -361,8 +361,8 @@ UserAPI_getUserByName(apiClient_t *apiClient, char * username )
if (apiClient->dataReceived) {
free(apiClient->dataReceived);
apiClient->dataReceived = NULL;
apiClient->dataReceivedLen = 0;
}
apiClient->dataReceivedLen = 0;



Expand Down Expand Up @@ -443,8 +443,8 @@ UserAPI_loginUser(apiClient_t *apiClient, char * username , char * password )
if (apiClient->dataReceived) {
free(apiClient->dataReceived);
apiClient->dataReceived = NULL;
apiClient->dataReceivedLen = 0;
}
apiClient->dataReceivedLen = 0;
list_free(localVarQueryParameters);


Expand Down Expand Up @@ -518,8 +518,8 @@ UserAPI_logoutUser(apiClient_t *apiClient)
if (apiClient->dataReceived) {
free(apiClient->dataReceived);
apiClient->dataReceived = NULL;
apiClient->dataReceivedLen = 0;
}
apiClient->dataReceivedLen = 0;



Expand Down Expand Up @@ -590,8 +590,8 @@ UserAPI_updateUser(apiClient_t *apiClient, char * username , user_t * body )
if (apiClient->dataReceived) {
free(apiClient->dataReceived);
apiClient->dataReceived = NULL;
apiClient->dataReceivedLen = 0;
}
apiClient->dataReceivedLen = 0;



Expand Down
40 changes: 0 additions & 40 deletions samples/client/petstore/c/src/apiClient.c
Original file line number Diff line number Diff line change
Expand Up @@ -524,43 +524,3 @@ char *strReplace(char *orig, char *rep, char *with) {
return result;
}

<<<<<<< HEAD
char *base64encode (const void *b64_encode_this, int encode_this_many_bytes){
#ifdef OPENSSL
BIO *b64_bio, *mem_bio; //Declares two OpenSSL BIOs: a base64 filter and a memory BIO.
BUF_MEM *mem_bio_mem_ptr; //Pointer to a "memory BIO" structure holding our base64 data.
b64_bio = BIO_new(BIO_f_base64()); //Initialize our base64 filter BIO.
mem_bio = BIO_new(BIO_s_mem()); //Initialize our memory sink BIO.
BIO_push(b64_bio, mem_bio); //Link the BIOs by creating a filter-sink BIO chain.
BIO_set_flags(b64_bio, BIO_FLAGS_BASE64_NO_NL); //No newlines every 64 characters or less.
BIO_write(b64_bio, b64_encode_this, encode_this_many_bytes); //Records base64 encoded data.
BIO_flush(b64_bio); //Flush data. Necessary for b64 encoding, because of pad characters.
BIO_get_mem_ptr(mem_bio, &mem_bio_mem_ptr); //Store address of mem_bio's memory structure.
BIO_set_close(mem_bio, BIO_NOCLOSE); //Permit access to mem_ptr after BIOs are destroyed.
BIO_free_all(b64_bio); //Destroys all BIOs in chain, starting with b64 (i.e. the 1st one).
BUF_MEM_grow(mem_bio_mem_ptr, (*mem_bio_mem_ptr).length + 1); //Makes space for end null.
(*mem_bio_mem_ptr).data[(*mem_bio_mem_ptr).length] = '\0'; //Adds null-terminator to tail.
return (*mem_bio_mem_ptr).data; //Returns base-64 encoded data. (See: "buf_mem_st" struct).
#endif
}

char *base64decode (const void *b64_decode_this, int decode_this_many_bytes, int *decoded_bytes){
#ifdef OPENSSL
BIO *b64_bio, *mem_bio; //Declares two OpenSSL BIOs: a base64 filter and a memory BIO.
char *base64_decoded = calloc( (decode_this_many_bytes*3)/4+1, sizeof(char) ); //+1 = null.
b64_bio = BIO_new(BIO_f_base64()); //Initialize our base64 filter BIO.
mem_bio = BIO_new(BIO_s_mem()); //Initialize our memory source BIO.
BIO_write(mem_bio, b64_decode_this, decode_this_many_bytes); //Base64 data saved in source.
BIO_push(b64_bio, mem_bio); //Link the BIOs by creating a filter-source BIO chain.
BIO_set_flags(b64_bio, BIO_FLAGS_BASE64_NO_NL); //Don't require trailing newlines.
int decoded_byte_index = 0; //Index where the next base64_decoded byte should be written.
while ( 0 < BIO_read(b64_bio, base64_decoded+decoded_byte_index, 1) ){ //Read byte-by-byte.
decoded_byte_index++; //Increment the index until read of BIO decoded data is complete.
} //Once we're done reading decoded data, BIO_read returns -1 even though there's no error.
BIO_free_all(b64_bio); //Destroys all BIOs in chain, starting with b64 (i.e. the 1st one).
*decoded_bytes = decoded_byte_index;
return base64_decoded; //Returns base-64 decoded data with trailing null terminator.
#endif
}
=======
>>>>>>> e9d35c5a2a9257e33564464616662d1f8cc09234