From 3a9d28d4ab2aeed24dc7d4fe11cbc2ca7ce7ecf7 Mon Sep 17 00:00:00 2001 From: hirishh Date: Tue, 22 Jul 2025 15:13:07 +0200 Subject: [PATCH 1/4] Add keepalive to c-libcurl --- .../resources/C-libcurl/apiClient.c.mustache | 21 ++++++++++++++++++- .../resources/C-libcurl/apiClient.h.mustache | 10 +++++++++ .../others/c/bearerAuth/include/apiClient.h | 10 +++++++++ .../others/c/bearerAuth/src/apiClient.c | 21 ++++++++++++++++++- .../c-useJsonUnformatted/include/apiClient.h | 10 +++++++++ .../c-useJsonUnformatted/src/apiClient.c | 21 ++++++++++++++++++- samples/client/petstore/c/include/apiClient.h | 10 +++++++++ samples/client/petstore/c/src/apiClient.c | 21 ++++++++++++++++++- 8 files changed, 120 insertions(+), 4 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/C-libcurl/apiClient.c.mustache b/modules/openapi-generator/src/main/resources/C-libcurl/apiClient.c.mustache index f6cb0fb49a2a..f34e15b92f7d 100644 --- a/modules/openapi-generator/src/main/resources/C-libcurl/apiClient.c.mustache +++ b/modules/openapi-generator/src/main/resources/C-libcurl/apiClient.c.mustache @@ -10,6 +10,7 @@ apiClient_t *apiClient_create() { apiClient_t *apiClient = malloc(sizeof(apiClient_t)); apiClient->basePath = strdup("{{{basePath}}}"); apiClient->sslConfig = NULL; + apiClient->curlConfig = NULL; apiClient->dataReceived = NULL; apiClient->dataReceivedLen = 0; apiClient->data_callback_func = NULL; @@ -60,6 +61,12 @@ apiClient_t *apiClient_create_with_base_path(const char *basePath apiClient->sslConfig = NULL; } + apiClient->curlConfig = malloc(sizeof(curlConfig_t)); + apiClient->curlConfig->verbose = 0; + apiClient->curlConfig->keepalive = 0; + apiClient->curlConfig->keepidle = 120; + apiClient->curlConfig->keepintvl = 60; + apiClient->dataReceived = NULL; apiClient->dataReceivedLen = 0; apiClient->data_callback_func = NULL; @@ -142,6 +149,12 @@ void apiClient_free(apiClient_t *apiClient) { {{/isApiKey}} {{/authMethods}} {{/hasAuthMethods}} + + if(apiClient->curlConfig) { + free(apiClient->curlConfig); + apiClient->curlConfig = NULL; + } + free(apiClient); } @@ -490,6 +503,12 @@ void apiClient_invoke(apiClient_t *apiClient, operationParameter, queryParameters); + if(apiClient->curlConfig->keepalive == 1) { + curl_easy_setopt(handle, CURLOPT_TCP_KEEPALIVE, 1L); + curl_easy_setopt(handle, CURLOPT_TCP_KEEPIDLE, apiClient->curlConfig->keepidle); + curl_easy_setopt(handle, CURLOPT_TCP_KEEPINTVL, apiClient->curlConfig->keepintvl); + } + curl_easy_setopt(handle, CURLOPT_URL, targetUrl); curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, @@ -498,7 +517,7 @@ void apiClient_invoke(apiClient_t *apiClient, CURLOPT_WRITEDATA, apiClient); curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); - curl_easy_setopt(handle, CURLOPT_VERBOSE, 0); // to get curl debug msg 0: to disable, 1L:to enable + curl_easy_setopt(handle, CURLOPT_VERBOSE, apiClient->curlConfig->verbose); {{#hasAuthMethods}} {{#authMethods}} diff --git a/modules/openapi-generator/src/main/resources/C-libcurl/apiClient.h.mustache b/modules/openapi-generator/src/main/resources/C-libcurl/apiClient.h.mustache index b07aab055553..b558dc1d4733 100644 --- a/modules/openapi-generator/src/main/resources/C-libcurl/apiClient.h.mustache +++ b/modules/openapi-generator/src/main/resources/C-libcurl/apiClient.h.mustache @@ -19,9 +19,19 @@ typedef struct sslConfig_t { /* 1 -- skip ssl verify for server certificate */ } sslConfig_t; +typedef struct curlConfig_t { + long verbose; /* 0 -- disable verbose (default) */ + /* 1 -- enable verbose */ + int keepalive; /* 0 -- disable keepalive (default) */ + /* 1 -- enable keepalive */ + long keepidle; /* keep-alive idle time: default to 120 seconds */ + long keepintvl; /* interval time between keep-alive probes: default to 60 seconds */ +} curlConfig_t; + typedef struct apiClient_t { char *basePath; sslConfig_t *sslConfig; + curlConfig_t *curlConfig; void *dataReceived; long dataReceivedLen; void (*data_callback_func)(void **, long *); diff --git a/samples/client/others/c/bearerAuth/include/apiClient.h b/samples/client/others/c/bearerAuth/include/apiClient.h index 4544976a1b82..ce8420b40908 100644 --- a/samples/client/others/c/bearerAuth/include/apiClient.h +++ b/samples/client/others/c/bearerAuth/include/apiClient.h @@ -19,9 +19,19 @@ typedef struct sslConfig_t { /* 1 -- skip ssl verify for server certificate */ } sslConfig_t; +typedef struct curlConfig_t { + long verbose; /* 0 -- disable verbose (default) */ + /* 1 -- enable verbose */ + int keepalive; /* 0 -- disable keepalive (default) */ + /* 1 -- enable keepalive */ + long keepidle; /* keep-alive idle time: default to 120 seconds */ + long keepintvl; /* interval time between keep-alive probes: default to 60 seconds */ +} curlConfig_t; + typedef struct apiClient_t { char *basePath; sslConfig_t *sslConfig; + curlConfig_t *curlConfig; void *dataReceived; long dataReceivedLen; void (*data_callback_func)(void **, long *); diff --git a/samples/client/others/c/bearerAuth/src/apiClient.c b/samples/client/others/c/bearerAuth/src/apiClient.c index b67055c2abae..4f7cb6da7bf3 100644 --- a/samples/client/others/c/bearerAuth/src/apiClient.c +++ b/samples/client/others/c/bearerAuth/src/apiClient.c @@ -10,6 +10,7 @@ apiClient_t *apiClient_create() { apiClient_t *apiClient = malloc(sizeof(apiClient_t)); apiClient->basePath = strdup("http://api.example.com/v1"); apiClient->sslConfig = NULL; + apiClient->curlConfig = NULL; apiClient->dataReceived = NULL; apiClient->dataReceivedLen = 0; apiClient->data_callback_func = NULL; @@ -37,6 +38,12 @@ apiClient_t *apiClient_create_with_base_path(const char *basePath apiClient->sslConfig = NULL; } + apiClient->curlConfig = malloc(sizeof(curlConfig_t)); + apiClient->curlConfig->verbose = 0; + apiClient->curlConfig->keepalive = 0; + apiClient->curlConfig->keepidle = 120; + apiClient->curlConfig->keepintvl = 60; + apiClient->dataReceived = NULL; apiClient->dataReceivedLen = 0; apiClient->data_callback_func = NULL; @@ -58,6 +65,12 @@ void apiClient_free(apiClient_t *apiClient) { if(apiClient->accessToken) { free(apiClient->accessToken); } + + if(apiClient->curlConfig) { + free(apiClient->curlConfig); + apiClient->curlConfig = NULL; + } + free(apiClient); } @@ -383,6 +396,12 @@ void apiClient_invoke(apiClient_t *apiClient, operationParameter, queryParameters); + if(apiClient->curlConfig->keepalive == 1) { + curl_easy_setopt(handle, CURLOPT_TCP_KEEPALIVE, 1L); + curl_easy_setopt(handle, CURLOPT_TCP_KEEPIDLE, apiClient->curlConfig->keepidle); + curl_easy_setopt(handle, CURLOPT_TCP_KEEPINTVL, apiClient->curlConfig->keepintvl); + } + curl_easy_setopt(handle, CURLOPT_URL, targetUrl); curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, @@ -391,7 +410,7 @@ void apiClient_invoke(apiClient_t *apiClient, CURLOPT_WRITEDATA, apiClient); curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); - curl_easy_setopt(handle, CURLOPT_VERBOSE, 0); // to get curl debug msg 0: to disable, 1L:to enable + curl_easy_setopt(handle, CURLOPT_VERBOSE, apiClient->curlConfig->verbose); if(bodyParameters != NULL) { diff --git a/samples/client/petstore/c-useJsonUnformatted/include/apiClient.h b/samples/client/petstore/c-useJsonUnformatted/include/apiClient.h index 2e428dfe648b..8bd429b148d4 100644 --- a/samples/client/petstore/c-useJsonUnformatted/include/apiClient.h +++ b/samples/client/petstore/c-useJsonUnformatted/include/apiClient.h @@ -19,9 +19,19 @@ typedef struct sslConfig_t { /* 1 -- skip ssl verify for server certificate */ } sslConfig_t; +typedef struct curlConfig_t { + long verbose; /* 0 -- disable verbose (default) */ + /* 1 -- enable verbose */ + int keepalive; /* 0 -- disable keepalive (default) */ + /* 1 -- enable keepalive */ + long keepidle; /* keep-alive idle time: default to 120 seconds */ + long keepintvl; /* interval time between keep-alive probes: default to 60 seconds */ +} curlConfig_t; + typedef struct apiClient_t { char *basePath; sslConfig_t *sslConfig; + curlConfig_t *curlConfig; void *dataReceived; long dataReceivedLen; void (*data_callback_func)(void **, long *); diff --git a/samples/client/petstore/c-useJsonUnformatted/src/apiClient.c b/samples/client/petstore/c-useJsonUnformatted/src/apiClient.c index 9995b93a8934..7f3391cdd31a 100644 --- a/samples/client/petstore/c-useJsonUnformatted/src/apiClient.c +++ b/samples/client/petstore/c-useJsonUnformatted/src/apiClient.c @@ -10,6 +10,7 @@ apiClient_t *apiClient_create() { apiClient_t *apiClient = malloc(sizeof(apiClient_t)); apiClient->basePath = strdup("http://petstore.swagger.io/v2"); apiClient->sslConfig = NULL; + apiClient->curlConfig = NULL; apiClient->dataReceived = NULL; apiClient->dataReceivedLen = 0; apiClient->data_callback_func = NULL; @@ -39,6 +40,12 @@ apiClient_t *apiClient_create_with_base_path(const char *basePath apiClient->sslConfig = NULL; } + apiClient->curlConfig = malloc(sizeof(curlConfig_t)); + apiClient->curlConfig->verbose = 0; + apiClient->curlConfig->keepalive = 0; + apiClient->curlConfig->keepidle = 120; + apiClient->curlConfig->keepintvl = 60; + apiClient->dataReceived = NULL; apiClient->dataReceivedLen = 0; apiClient->data_callback_func = NULL; @@ -85,6 +92,12 @@ void apiClient_free(apiClient_t *apiClient) { } list_freeList(apiClient->apiKeys_api_key); } + + if(apiClient->curlConfig) { + free(apiClient->curlConfig); + apiClient->curlConfig = NULL; + } + free(apiClient); } @@ -413,6 +426,12 @@ void apiClient_invoke(apiClient_t *apiClient, operationParameter, queryParameters); + if(apiClient->curlConfig->keepalive == 1) { + curl_easy_setopt(handle, CURLOPT_TCP_KEEPALIVE, 1L); + curl_easy_setopt(handle, CURLOPT_TCP_KEEPIDLE, apiClient->curlConfig->keepidle); + curl_easy_setopt(handle, CURLOPT_TCP_KEEPINTVL, apiClient->curlConfig->keepintvl); + } + curl_easy_setopt(handle, CURLOPT_URL, targetUrl); curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, @@ -421,7 +440,7 @@ void apiClient_invoke(apiClient_t *apiClient, CURLOPT_WRITEDATA, apiClient); curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); - curl_easy_setopt(handle, CURLOPT_VERBOSE, 0); // to get curl debug msg 0: to disable, 1L:to enable + curl_easy_setopt(handle, CURLOPT_VERBOSE, apiClient->curlConfig->verbose); // this would only be generated for OAuth2 authentication if(apiClient->accessToken != NULL) { diff --git a/samples/client/petstore/c/include/apiClient.h b/samples/client/petstore/c/include/apiClient.h index 2e428dfe648b..8bd429b148d4 100644 --- a/samples/client/petstore/c/include/apiClient.h +++ b/samples/client/petstore/c/include/apiClient.h @@ -19,9 +19,19 @@ typedef struct sslConfig_t { /* 1 -- skip ssl verify for server certificate */ } sslConfig_t; +typedef struct curlConfig_t { + long verbose; /* 0 -- disable verbose (default) */ + /* 1 -- enable verbose */ + int keepalive; /* 0 -- disable keepalive (default) */ + /* 1 -- enable keepalive */ + long keepidle; /* keep-alive idle time: default to 120 seconds */ + long keepintvl; /* interval time between keep-alive probes: default to 60 seconds */ +} curlConfig_t; + typedef struct apiClient_t { char *basePath; sslConfig_t *sslConfig; + curlConfig_t *curlConfig; void *dataReceived; long dataReceivedLen; void (*data_callback_func)(void **, long *); diff --git a/samples/client/petstore/c/src/apiClient.c b/samples/client/petstore/c/src/apiClient.c index 9995b93a8934..7f3391cdd31a 100644 --- a/samples/client/petstore/c/src/apiClient.c +++ b/samples/client/petstore/c/src/apiClient.c @@ -10,6 +10,7 @@ apiClient_t *apiClient_create() { apiClient_t *apiClient = malloc(sizeof(apiClient_t)); apiClient->basePath = strdup("http://petstore.swagger.io/v2"); apiClient->sslConfig = NULL; + apiClient->curlConfig = NULL; apiClient->dataReceived = NULL; apiClient->dataReceivedLen = 0; apiClient->data_callback_func = NULL; @@ -39,6 +40,12 @@ apiClient_t *apiClient_create_with_base_path(const char *basePath apiClient->sslConfig = NULL; } + apiClient->curlConfig = malloc(sizeof(curlConfig_t)); + apiClient->curlConfig->verbose = 0; + apiClient->curlConfig->keepalive = 0; + apiClient->curlConfig->keepidle = 120; + apiClient->curlConfig->keepintvl = 60; + apiClient->dataReceived = NULL; apiClient->dataReceivedLen = 0; apiClient->data_callback_func = NULL; @@ -85,6 +92,12 @@ void apiClient_free(apiClient_t *apiClient) { } list_freeList(apiClient->apiKeys_api_key); } + + if(apiClient->curlConfig) { + free(apiClient->curlConfig); + apiClient->curlConfig = NULL; + } + free(apiClient); } @@ -413,6 +426,12 @@ void apiClient_invoke(apiClient_t *apiClient, operationParameter, queryParameters); + if(apiClient->curlConfig->keepalive == 1) { + curl_easy_setopt(handle, CURLOPT_TCP_KEEPALIVE, 1L); + curl_easy_setopt(handle, CURLOPT_TCP_KEEPIDLE, apiClient->curlConfig->keepidle); + curl_easy_setopt(handle, CURLOPT_TCP_KEEPINTVL, apiClient->curlConfig->keepintvl); + } + curl_easy_setopt(handle, CURLOPT_URL, targetUrl); curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, @@ -421,7 +440,7 @@ void apiClient_invoke(apiClient_t *apiClient, CURLOPT_WRITEDATA, apiClient); curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); - curl_easy_setopt(handle, CURLOPT_VERBOSE, 0); // to get curl debug msg 0: to disable, 1L:to enable + curl_easy_setopt(handle, CURLOPT_VERBOSE, apiClient->curlConfig->verbose); // this would only be generated for OAuth2 authentication if(apiClient->accessToken != NULL) { From 33048f62e0e34ef0837e0a224e9bb9d6f8f2f4f5 Mon Sep 17 00:00:00 2001 From: hirishh Date: Wed, 23 Jul 2025 16:29:11 +0200 Subject: [PATCH 2/4] Fix manual tests on client/petstore/c --- .../resources/C-libcurl/README.md.mustache | 6 ++--- samples/client/petstore/c/build-and-test.bash | 11 +++++--- .../petstore/c/unit-tests/manual-PetAPI.c | 7 +++-- .../petstore/c/unit-tests/manual-StoreAPI.c | 3 +-- .../petstore/c/unit-tests/manual-UserAPI.c | 20 ++++++++------ .../petstore/c/unit-tests/manual-order.c | 9 ++++--- .../petstore/c/unit-tests/manual-user.c | 27 ++++++++++++++++--- 7 files changed, 55 insertions(+), 28 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/C-libcurl/README.md.mustache b/modules/openapi-generator/src/main/resources/C-libcurl/README.md.mustache index b48f15c34d7e..2b48e97accb4 100644 --- a/modules/openapi-generator/src/main/resources/C-libcurl/README.md.mustache +++ b/modules/openapi-generator/src/main/resources/C-libcurl/README.md.mustache @@ -22,9 +22,9 @@ You'll need the `curl 7.58.0` package in order to build the API. To have code fo ## Install the `curl 7.58.0` package with the following command on Linux. ```bash sudo apt remove curl -wget http://curl.haxx.se/download/curl-7.58.0.tar.gz -tar -xvf curl-7.58.0.tar.gz -cd curl-7.58.0/ +wget http://curl.haxx.se/download/curl-7.61.1.tar.gz +tar -xvf curl-7.61.1.tar.gz +cd curl-7.61.1/ ./configure make sudo make install diff --git a/samples/client/petstore/c/build-and-test.bash b/samples/client/petstore/c/build-and-test.bash index e10052bb5576..3d3d81298428 100755 --- a/samples/client/petstore/c/build-and-test.bash +++ b/samples/client/petstore/c/build-and-test.bash @@ -2,6 +2,10 @@ set -e +# project +mkdir -p build +cd build + #install latest curl wget https://curl.haxx.se/download/curl-7.61.1.zip unzip curl-7.61.1.zip @@ -11,10 +15,9 @@ make sudo make install cd .. -# project -cmake . - -make +# build project +cmake .. +make if [ -f unit-manual-PetAPI ]; then ./unit-manual-PetAPI; fi if [ -f unit-manual-UserAPI ]; then ./unit-manual-UserAPI; fi diff --git a/samples/client/petstore/c/unit-tests/manual-PetAPI.c b/samples/client/petstore/c/unit-tests/manual-PetAPI.c index 3090521dc627..b24bd1ced153 100644 --- a/samples/client/petstore/c/unit-tests/manual-PetAPI.c +++ b/samples/client/petstore/c/unit-tests/manual-PetAPI.c @@ -55,14 +55,13 @@ int main() { list_addElement(tags, exampleTag2); - status_e status = available; pet_t *pet = pet_create(EXAMPLE_PET_ID, category, petName, photoUrls, tags, - status); + openapi_petstore_pet_STATUS_available); PetAPI_addPet(apiClient, pet); cJSON *JSONR_local = pet_convertToJSON(pet); @@ -95,9 +94,9 @@ int main() { assert(mypet->id == EXAMPLE_PET_ID); assert(strcmp(mypet->category->name, EXAMPLE_CATEGORY_NAME) == 0); assert(mypet->category->id == EXAMPLE_CATEGORY_ID); - assert(strcmp(list_getElementAt(mypet->photoUrls, + assert(strcmp(list_getElementAt(mypet->photo_urls, 0)->data, EXAMPLE_URL_1) == 0); - assert(strcmp(list_getElementAt(mypet->photoUrls, + assert(strcmp(list_getElementAt(mypet->photo_urls, 1)->data, EXAMPLE_URL_2) == 0); assert(((tag_t *) list_getElementAt(mypet->tags, 0)->data)->id == EXAMPLE_TAG_1_ID); diff --git a/samples/client/petstore/c/unit-tests/manual-StoreAPI.c b/samples/client/petstore/c/unit-tests/manual-StoreAPI.c index c6e3d3bacb42..baadca77f82a 100644 --- a/samples/client/petstore/c/unit-tests/manual-StoreAPI.c +++ b/samples/client/petstore/c/unit-tests/manual-StoreAPI.c @@ -9,7 +9,6 @@ #define PET_ID 12345 #define QUANTITY 50 #define SHIP_DATE "2018-09-24T10:19:09.592Z" - #define STATUS placed #define COMPLETE true /* @@ -27,7 +26,7 @@ int main() { PET_ID, QUANTITY, shipdate, - STATUS, + openapi_petstore_order_STATUS_placed, COMPLETE); order_t *returnorder = StoreAPI_placeOrder(apiClient, neworder); diff --git a/samples/client/petstore/c/unit-tests/manual-UserAPI.c b/samples/client/petstore/c/unit-tests/manual-UserAPI.c index 8f91839d0f46..e205bf6cf01e 100644 --- a/samples/client/petstore/c/unit-tests/manual-UserAPI.c +++ b/samples/client/petstore/c/unit-tests/manual-UserAPI.c @@ -33,13 +33,15 @@ int main() { strcpy(phone, PHONE); user_t *newuser = user_create(USER_ID, - username, - firstname, - lastname, - email, - password, - phone, - USER_STATUS); + username, + firstname, + lastname, + email, + password, + phone, + USER_STATUS, + NULL, + openapi_petstore_preference__cats); UserAPI_createUser(apiClient, newuser); user_free(newuser); @@ -82,7 +84,9 @@ int main() { email, password, phone, - USER_STATUS); + USER_STATUS, + NULL, + openapi_petstore_preference__cats); UserAPI_updateUser(apiClient2, username1, newuser1); user_free(newuser1); diff --git a/samples/client/petstore/c/unit-tests/manual-order.c b/samples/client/petstore/c/unit-tests/manual-order.c index b1475bda6ae3..ae4a5d3d071b 100644 --- a/samples/client/petstore/c/unit-tests/manual-order.c +++ b/samples/client/petstore/c/unit-tests/manual-order.c @@ -12,11 +12,12 @@ #define COMPLETE 1 int main() { - status_e STATUS = placed; + char *shipDate = malloc(strlen(SHIP_DATE) + 1); + strcpy(shipDate, SHIP_DATE); - order_t *neworder = order_create(ORDER_ID, PET_ID, QUANTITY, SHIP_DATE, - STATUS, - COMPLETE); + order_t *neworder = order_create(ORDER_ID, PET_ID, QUANTITY, shipDate, + openapi_petstore_order_STATUS_placed, + COMPLETE); cJSON *JSONNODE = order_convertToJSON(neworder); diff --git a/samples/client/petstore/c/unit-tests/manual-user.c b/samples/client/petstore/c/unit-tests/manual-user.c index 1200baa2e5d2..da1ad928fb69 100644 --- a/samples/client/petstore/c/unit-tests/manual-user.c +++ b/samples/client/petstore/c/unit-tests/manual-user.c @@ -14,9 +14,30 @@ #define USER_STATUS 4 int main() { - user_t *newuser = user_create(USER_ID, USER_NAME, FIRST_NAME, LAST_NAME, - EMAIL, - PASSWORD, PHONE, USER_STATUS); + + char *username = malloc(strlen(USER_NAME) + 1); + strcpy(username, USER_NAME); + char *firstname = malloc(strlen(FIRST_NAME) + 1); + strcpy(firstname, FIRST_NAME); + char *lastname = malloc(strlen(LAST_NAME) + 1); + strcpy(lastname, LAST_NAME); + char *email = malloc(strlen(EMAIL) + 1); + strcpy(email, EMAIL); + char *password = malloc(strlen(PASSWORD) + 1); + strcpy(password, PASSWORD); + char *phone = malloc(strlen(PHONE) + 1); + strcpy(phone, PHONE); + + user_t *newuser = user_create(USER_ID, + username, + firstname, + lastname, + email, + password, + phone, + USER_STATUS, + NULL, + openapi_petstore_preference__cats); cJSON *JSONNODE = user_convertToJSON(newuser); From f7f108f081ea56e0b815e0bbb9c80c287a56953c Mon Sep 17 00:00:00 2001 From: hirishh Date: Thu, 24 Jul 2025 11:50:33 +0200 Subject: [PATCH 3/4] Update Readme of c/libcurl --- .../src/main/resources/C-libcurl/README.md.mustache | 4 ++-- samples/client/others/c/bearerAuth/README.md | 10 +++++----- samples/client/petstore/c-useJsonUnformatted/README.md | 10 +++++----- samples/client/petstore/c/README.md | 10 +++++----- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/C-libcurl/README.md.mustache b/modules/openapi-generator/src/main/resources/C-libcurl/README.md.mustache index 2b48e97accb4..4fc42b046720 100644 --- a/modules/openapi-generator/src/main/resources/C-libcurl/README.md.mustache +++ b/modules/openapi-generator/src/main/resources/C-libcurl/README.md.mustache @@ -15,11 +15,11 @@ For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}}) {{/infoUrl}} ## Installation -You'll need the `curl 7.58.0` package in order to build the API. To have code formatted nicely, you also need to have uncrustify version 0.67 or later. +You'll need the `curl 7.61.1` package in order to build the API. To have code formatted nicely, you also need to have uncrustify version 0.67 or later. # Prerequisites -## Install the `curl 7.58.0` package with the following command on Linux. +## Install the `curl 7.61.1` package with the following command on Linux. ```bash sudo apt remove curl wget http://curl.haxx.se/download/curl-7.61.1.tar.gz diff --git a/samples/client/others/c/bearerAuth/README.md b/samples/client/others/c/bearerAuth/README.md index fa62dda8710c..bee4f7a08ad1 100644 --- a/samples/client/others/c/bearerAuth/README.md +++ b/samples/client/others/c/bearerAuth/README.md @@ -9,16 +9,16 @@ This API client was generated by the [OpenAPI Generator](https://openapi-generat - Build package: org.openapitools.codegen.languages.CLibcurlClientCodegen ## Installation -You'll need the `curl 7.58.0` package in order to build the API. To have code formatted nicely, you also need to have uncrustify version 0.67 or later. +You'll need the `curl 7.61.1` package in order to build the API. To have code formatted nicely, you also need to have uncrustify version 0.67 or later. # Prerequisites -## Install the `curl 7.58.0` package with the following command on Linux. +## Install the `curl 7.61.1` package with the following command on Linux. ```bash sudo apt remove curl -wget http://curl.haxx.se/download/curl-7.58.0.tar.gz -tar -xvf curl-7.58.0.tar.gz -cd curl-7.58.0/ +wget http://curl.haxx.se/download/curl-7.61.1.tar.gz +tar -xvf curl-7.61.1.tar.gz +cd curl-7.61.1/ ./configure make sudo make install diff --git a/samples/client/petstore/c-useJsonUnformatted/README.md b/samples/client/petstore/c-useJsonUnformatted/README.md index 68f070689420..8ba4e7769ac0 100644 --- a/samples/client/petstore/c-useJsonUnformatted/README.md +++ b/samples/client/petstore/c-useJsonUnformatted/README.md @@ -9,16 +9,16 @@ This API client was generated by the [OpenAPI Generator](https://openapi-generat - Build package: org.openapitools.codegen.languages.CLibcurlClientCodegen ## Installation -You'll need the `curl 7.58.0` package in order to build the API. To have code formatted nicely, you also need to have uncrustify version 0.67 or later. +You'll need the `curl 7.61.1` package in order to build the API. To have code formatted nicely, you also need to have uncrustify version 0.67 or later. # Prerequisites -## Install the `curl 7.58.0` package with the following command on Linux. +## Install the `curl 7.61.1` package with the following command on Linux. ```bash sudo apt remove curl -wget http://curl.haxx.se/download/curl-7.58.0.tar.gz -tar -xvf curl-7.58.0.tar.gz -cd curl-7.58.0/ +wget http://curl.haxx.se/download/curl-7.61.1.tar.gz +tar -xvf curl-7.61.1.tar.gz +cd curl-7.61.1/ ./configure make sudo make install diff --git a/samples/client/petstore/c/README.md b/samples/client/petstore/c/README.md index 68f070689420..8ba4e7769ac0 100644 --- a/samples/client/petstore/c/README.md +++ b/samples/client/petstore/c/README.md @@ -9,16 +9,16 @@ This API client was generated by the [OpenAPI Generator](https://openapi-generat - Build package: org.openapitools.codegen.languages.CLibcurlClientCodegen ## Installation -You'll need the `curl 7.58.0` package in order to build the API. To have code formatted nicely, you also need to have uncrustify version 0.67 or later. +You'll need the `curl 7.61.1` package in order to build the API. To have code formatted nicely, you also need to have uncrustify version 0.67 or later. # Prerequisites -## Install the `curl 7.58.0` package with the following command on Linux. +## Install the `curl 7.61.1` package with the following command on Linux. ```bash sudo apt remove curl -wget http://curl.haxx.se/download/curl-7.58.0.tar.gz -tar -xvf curl-7.58.0.tar.gz -cd curl-7.58.0/ +wget http://curl.haxx.se/download/curl-7.61.1.tar.gz +tar -xvf curl-7.61.1.tar.gz +cd curl-7.61.1/ ./configure make sudo make install From dd55683ed02179c34117683f385a05ea1ebf44db Mon Sep 17 00:00:00 2001 From: hirishh Date: Thu, 24 Jul 2025 15:14:31 +0200 Subject: [PATCH 4/4] better curlConfig handling on c-libcurl --- .../resources/C-libcurl/apiClient.c.mustache | 16 +++++++++------- .../client/others/c/bearerAuth/src/apiClient.c | 16 +++++++++------- .../c-useJsonUnformatted/src/apiClient.c | 16 +++++++++------- samples/client/petstore/c/src/apiClient.c | 16 +++++++++------- 4 files changed, 36 insertions(+), 28 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/C-libcurl/apiClient.c.mustache b/modules/openapi-generator/src/main/resources/C-libcurl/apiClient.c.mustache index f34e15b92f7d..1aeaea1beb3d 100644 --- a/modules/openapi-generator/src/main/resources/C-libcurl/apiClient.c.mustache +++ b/modules/openapi-generator/src/main/resources/C-libcurl/apiClient.c.mustache @@ -503,12 +503,6 @@ void apiClient_invoke(apiClient_t *apiClient, operationParameter, queryParameters); - if(apiClient->curlConfig->keepalive == 1) { - curl_easy_setopt(handle, CURLOPT_TCP_KEEPALIVE, 1L); - curl_easy_setopt(handle, CURLOPT_TCP_KEEPIDLE, apiClient->curlConfig->keepidle); - curl_easy_setopt(handle, CURLOPT_TCP_KEEPINTVL, apiClient->curlConfig->keepintvl); - } - curl_easy_setopt(handle, CURLOPT_URL, targetUrl); curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, @@ -517,7 +511,6 @@ void apiClient_invoke(apiClient_t *apiClient, CURLOPT_WRITEDATA, apiClient); curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); - curl_easy_setopt(handle, CURLOPT_VERBOSE, apiClient->curlConfig->verbose); {{#hasAuthMethods}} {{#authMethods}} @@ -562,6 +555,15 @@ void apiClient_invoke(apiClient_t *apiClient, postData(handle, bodyParameters, bodyParametersLength); } + if(apiClient->curlConfig != NULL) { + if(apiClient->curlConfig->keepalive == 1) { + curl_easy_setopt(handle, CURLOPT_TCP_KEEPALIVE, 1L); + curl_easy_setopt(handle, CURLOPT_TCP_KEEPIDLE, apiClient->curlConfig->keepidle); + curl_easy_setopt(handle, CURLOPT_TCP_KEEPINTVL, apiClient->curlConfig->keepintvl); + } + curl_easy_setopt(handle, CURLOPT_VERBOSE, apiClient->curlConfig->verbose); + } + res = curl_easy_perform(handle); curl_slist_free_all(headers); diff --git a/samples/client/others/c/bearerAuth/src/apiClient.c b/samples/client/others/c/bearerAuth/src/apiClient.c index 4f7cb6da7bf3..9e6fd8d8f056 100644 --- a/samples/client/others/c/bearerAuth/src/apiClient.c +++ b/samples/client/others/c/bearerAuth/src/apiClient.c @@ -396,12 +396,6 @@ void apiClient_invoke(apiClient_t *apiClient, operationParameter, queryParameters); - if(apiClient->curlConfig->keepalive == 1) { - curl_easy_setopt(handle, CURLOPT_TCP_KEEPALIVE, 1L); - curl_easy_setopt(handle, CURLOPT_TCP_KEEPIDLE, apiClient->curlConfig->keepidle); - curl_easy_setopt(handle, CURLOPT_TCP_KEEPINTVL, apiClient->curlConfig->keepintvl); - } - curl_easy_setopt(handle, CURLOPT_URL, targetUrl); curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, @@ -410,13 +404,21 @@ void apiClient_invoke(apiClient_t *apiClient, CURLOPT_WRITEDATA, apiClient); curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); - curl_easy_setopt(handle, CURLOPT_VERBOSE, apiClient->curlConfig->verbose); if(bodyParameters != NULL) { postData(handle, bodyParameters, bodyParametersLength); } + if(apiClient->curlConfig != NULL) { + if(apiClient->curlConfig->keepalive == 1) { + curl_easy_setopt(handle, CURLOPT_TCP_KEEPALIVE, 1L); + curl_easy_setopt(handle, CURLOPT_TCP_KEEPIDLE, apiClient->curlConfig->keepidle); + curl_easy_setopt(handle, CURLOPT_TCP_KEEPINTVL, apiClient->curlConfig->keepintvl); + } + curl_easy_setopt(handle, CURLOPT_VERBOSE, apiClient->curlConfig->verbose); + } + res = curl_easy_perform(handle); curl_slist_free_all(headers); diff --git a/samples/client/petstore/c-useJsonUnformatted/src/apiClient.c b/samples/client/petstore/c-useJsonUnformatted/src/apiClient.c index 7f3391cdd31a..3c2046a827ed 100644 --- a/samples/client/petstore/c-useJsonUnformatted/src/apiClient.c +++ b/samples/client/petstore/c-useJsonUnformatted/src/apiClient.c @@ -426,12 +426,6 @@ void apiClient_invoke(apiClient_t *apiClient, operationParameter, queryParameters); - if(apiClient->curlConfig->keepalive == 1) { - curl_easy_setopt(handle, CURLOPT_TCP_KEEPALIVE, 1L); - curl_easy_setopt(handle, CURLOPT_TCP_KEEPIDLE, apiClient->curlConfig->keepidle); - curl_easy_setopt(handle, CURLOPT_TCP_KEEPINTVL, apiClient->curlConfig->keepintvl); - } - curl_easy_setopt(handle, CURLOPT_URL, targetUrl); curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, @@ -440,7 +434,6 @@ void apiClient_invoke(apiClient_t *apiClient, CURLOPT_WRITEDATA, apiClient); curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); - curl_easy_setopt(handle, CURLOPT_VERBOSE, apiClient->curlConfig->verbose); // this would only be generated for OAuth2 authentication if(apiClient->accessToken != NULL) { @@ -454,6 +447,15 @@ void apiClient_invoke(apiClient_t *apiClient, postData(handle, bodyParameters, bodyParametersLength); } + if(apiClient->curlConfig != NULL) { + if(apiClient->curlConfig->keepalive == 1) { + curl_easy_setopt(handle, CURLOPT_TCP_KEEPALIVE, 1L); + curl_easy_setopt(handle, CURLOPT_TCP_KEEPIDLE, apiClient->curlConfig->keepidle); + curl_easy_setopt(handle, CURLOPT_TCP_KEEPINTVL, apiClient->curlConfig->keepintvl); + } + curl_easy_setopt(handle, CURLOPT_VERBOSE, apiClient->curlConfig->verbose); + } + res = curl_easy_perform(handle); curl_slist_free_all(headers); diff --git a/samples/client/petstore/c/src/apiClient.c b/samples/client/petstore/c/src/apiClient.c index 7f3391cdd31a..3c2046a827ed 100644 --- a/samples/client/petstore/c/src/apiClient.c +++ b/samples/client/petstore/c/src/apiClient.c @@ -426,12 +426,6 @@ void apiClient_invoke(apiClient_t *apiClient, operationParameter, queryParameters); - if(apiClient->curlConfig->keepalive == 1) { - curl_easy_setopt(handle, CURLOPT_TCP_KEEPALIVE, 1L); - curl_easy_setopt(handle, CURLOPT_TCP_KEEPIDLE, apiClient->curlConfig->keepidle); - curl_easy_setopt(handle, CURLOPT_TCP_KEEPINTVL, apiClient->curlConfig->keepintvl); - } - curl_easy_setopt(handle, CURLOPT_URL, targetUrl); curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, @@ -440,7 +434,6 @@ void apiClient_invoke(apiClient_t *apiClient, CURLOPT_WRITEDATA, apiClient); curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); - curl_easy_setopt(handle, CURLOPT_VERBOSE, apiClient->curlConfig->verbose); // this would only be generated for OAuth2 authentication if(apiClient->accessToken != NULL) { @@ -454,6 +447,15 @@ void apiClient_invoke(apiClient_t *apiClient, postData(handle, bodyParameters, bodyParametersLength); } + if(apiClient->curlConfig != NULL) { + if(apiClient->curlConfig->keepalive == 1) { + curl_easy_setopt(handle, CURLOPT_TCP_KEEPALIVE, 1L); + curl_easy_setopt(handle, CURLOPT_TCP_KEEPIDLE, apiClient->curlConfig->keepidle); + curl_easy_setopt(handle, CURLOPT_TCP_KEEPINTVL, apiClient->curlConfig->keepintvl); + } + curl_easy_setopt(handle, CURLOPT_VERBOSE, apiClient->curlConfig->verbose); + } + res = curl_easy_perform(handle); curl_slist_free_all(headers);