Commit b98daf64 authored by Matteo Quintiliani's avatar Matteo Quintiliani
Browse files

Merge branch 'release/1.14.0'

parents 111dbe27 69daa259
Pipeline #6693 passed with stages
in 1 minute and 33 seconds
......@@ -2,6 +2,10 @@
ew2openapi Release History
#########################
* Release 1.14.0 (2021/02/15)
- Add check quakdb/status API by function ew2openapi_handler_quakedb_ws_check_status(). Issue #43 (2021/01/22)
- Implement handling of http code 428 (Precondition Required) with HANDLER_STATUS_ERROR_LIMITED_RETRIES_WITHIN_TIME. Max 60 seconds. Issue #44 (2021/02/15)
* Release 1.13.0 (2021/01/22)
- Add warning message about delay message handling and number of items in queue to process. Issue #35 (2021/01/20)
- Move ew2openapi test in makefile.unix. Issue #40 (2021/01/15)
......
1.13.0 (2021-01-22)
\ No newline at end of file
1.14.0 (2021-02-15)
\ No newline at end of file
......@@ -19,6 +19,7 @@ echo "#define EW2OPENAPI_VERSION \"${VERSION}\"" >> ${FILE_ew2openapi_version}
echo "#define EW2OPENAPI_NAME_AND_VERSION EW2OPENAPI_NAME\" \"EW2OPENAPI_VERSION" >> ${FILE_ew2openapi_version}
echo "#define EW2OPENAPI_USERAGENT EW2OPENAPI_NAME\"/\"EW2OPENAPI_VERSION" >> ${FILE_ew2openapi_version}
echo "#define EW2OPENAPI_URL_PATH \"quakedb/ew/v1\"" >> ${FILE_ew2openapi_version}
echo "#define EW2OPENAPI_URL_PATH_STATUS \"quakedb/status\"" >> ${FILE_ew2openapi_version}
cat ${FILE_ew2openapi_version}
......@@ -651,6 +651,7 @@ thr_ret MessageHandler( void *p )
time_t time_now;
time_t time_msg;
double difftime_seconds;
const double max_difftime_seconds = 60.0;
TYPE_DATA_HANDLER data_handler;
int (*p_data_handler_func_handle) (TYPE_DATA_HANDLER *) = NULL;
......@@ -785,6 +786,18 @@ thr_ret MessageHandler( void *p )
flag_wait_after_error = 1;
break;
case HANDLER_STATUS_ERROR_LIMITED_RETRIES_WITHIN_TIME:
/* Compute time difference between now and inserted message time.
* If it exceeds max_difftime_seconds, then the message will be discarded. */
time(&time_now); difftime_seconds = difftime(time_now, time_msg);
if(difftime_seconds < max_difftime_seconds) {
/* Do not remove item from queue, wait until max_difftime_seconds */
flag_remove_last_msg = 0;
flag_wait_after_error = 1;
}
break;
case HANDLER_STATUS_ERROR_LIMITED_RETRIES:
/* Count how many times occurred the error to POST
* the same message before giving up after a maximum
......
......@@ -10,31 +10,11 @@
#include "ew2openapi_json_utils.h"
#include "ew2openapi_handler_status.h"
/* Private functions */
/* * * * * * * * * *
* Private functions
* * * * * * * * * */
long ew2openapi_handler_quakedb_ws_sendstring(char *ApiBaseUrl, char *buf, size_t len, MSG_LOGO *reclogo, char flag_geojson);
/* Wrapper to curl_global_init() */
int ew2openapi_handler_quakedb_ws_init(TYPE_PARAMS *params) {
int ret = 0;
CURLcode ret_curl;
long flags = CURL_GLOBAL_ALL;
ret_curl = curl_global_init(flags);
/* Exit if ret_curl is non-zero https://curl.se/libcurl/c/curl_global_init.html */
if(ret_curl != 0) {
ew2openapi_logit("et", "ew2openapi_handler_quakedb_ws_init(): initialization error. Exit.\n");
exit(-1);
}
return ret;
}
/* Wrapper to curl_global_cleanup() */
int ew2openapi_handler_quakedb_ws_destroy(TYPE_PARAMS *params) {
int ret = 0;
curl_global_cleanup();
return ret;
}
/*
* static size_t WriteMemoryCallback(void *contents, size_t size, size_t nmemb, void *userp)
* {
......@@ -73,6 +53,100 @@ static size_t ew2openapi_handler_quakedb_ws_WRITEFUNCTION_ew2openapi_logit(void
return realsize;
}
/* * * * * * * * * *
* Public functions
* * * * * * * * * */
/* Wrapper to curl_global_init() */
int ew2openapi_handler_quakedb_ws_init(TYPE_PARAMS *params) {
int ret = 0;
CURLcode ret_curl;
long flags = CURL_GLOBAL_ALL;
long curl_http_code = -1; /* Init error code */
/* Exit if ret_curl is non-zero https://curl.se/libcurl/c/curl_global_init.html */
ret_curl = curl_global_init(flags);
if(ret_curl != 0) {
ew2openapi_logit("et", "ew2openapi_handler_quakedb_ws_init(): initialization error. Exit.\n");
exit(-1);
}
/* Exit if curl_http_code == -1 or not between 100 and 299 */
curl_http_code = ew2openapi_handler_quakedb_ws_check_status(params->ApiBaseUrl);
if(curl_http_code >= 100 && curl_http_code < 300) {
ew2openapi_logit("et", "ew2openapi_handler_quakedb_ws_check_status(): ok http code=%ld. Exit.\n", curl_http_code);
} else {
ew2openapi_logit("et", "ew2openapi_handler_quakedb_ws_check_status(): error %ld. Exit.\n", curl_http_code);
exit(-1);
}
return ret;
}
/* Check quakedb/status API. Return http code. Otherwise, return -1. */
int ew2openapi_handler_quakedb_ws_check_status(char *ApiBaseUrl) {
CURL *curl;
CURLcode res;
long curl_http_code = -1; /* Init error code */
char url[MAX_API_URL];
struct curl_slist *headers = NULL;
const char *curl_header_accept_json = "Accept: application/json";
const char *curl_header_content_type_json = "Content-Type: application/json";
snprintf(url, MAX_API_URL - sizeof(EW2OPENAPI_URL_PATH_STATUS) - 1, "%s/%s", ApiBaseUrl, EW2OPENAPI_URL_PATH_STATUS);
headers = curl_slist_append(headers, curl_header_accept_json);
headers = curl_slist_append(headers, curl_header_content_type_json);
headers = curl_slist_append(headers, "charsets: utf-8");
curl = curl_easy_init();
if(curl) {
/* some servers don't like requests that are made without a user-agent
field, so we provide one */
curl_easy_setopt(curl, CURLOPT_USERAGENT, EW2OPENAPI_USERAGENT);
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
/* send all data to this function */
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, ew2openapi_handler_quakedb_ws_WRITEFUNCTION_ew2openapi_logit);
/* Perform the request, res will get the return code */
res = curl_easy_perform(curl);
/* Check for errors */
if(res == CURLE_OK) {
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &curl_http_code);
/* If http code is between 100 and 299, it should be ok. Print only the returned http code */
if(curl_http_code >= 100 && curl_http_code < 300) {
// Do nothing
} else {
switch(curl_http_code) {
default:
ew2openapi_logit("et", "Error POST to %s with http code %ld.\n", url, curl_http_code);
break;
}
}
} else {
ew2openapi_logit("et", "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));
}
/* always cleanup */
curl_easy_cleanup(curl);
}
return curl_http_code;
}
/* Wrapper to curl_global_cleanup() */
int ew2openapi_handler_quakedb_ws_destroy(TYPE_PARAMS *params) {
int ret = 0;
curl_global_cleanup();
return ret;
}
#define MAX_LEN_TYPE_EW_MESSAGE 64
/* Send Earthworm message to EWOpenAPI */
......@@ -226,12 +300,16 @@ int ew2openapi_handler_quakedb_ws_handle(TYPE_DATA_HANDLER *data_handler) {
/* 4xx error codes */
case 408: // Request Timeout
case 428: // Precondition Required
case 429: // Too Many Requests
/* Set handler_status_code to HANDLER_STATUS_ERROR_INFINITY_RETRIES */
handler_status_code = HANDLER_STATUS_ERROR_INFINITY_RETRIES;
break;
case 428: // Precondition Required
/* Set handler_status_code to HANDLER_STATUS_ERROR_LIMITED_RETRIES_WITHIN_TIME */
handler_status_code = HANDLER_STATUS_ERROR_LIMITED_RETRIES_WITHIN_TIME;
break;
case 422: // Unprocessable Entity
handler_status_code = HANDLER_STATUS_ERROR_NO_RETRIES;
break;
......
......@@ -7,6 +7,8 @@
int ew2openapi_handler_quakedb_ws_init(TYPE_PARAMS *params);
int ew2openapi_handler_quakedb_ws_check_status(char *ApiBaseUrl);
int ew2openapi_handler_quakedb_ws_destroy(TYPE_PARAMS *params);
int ew2openapi_handler_quakedb_ws_handle(TYPE_DATA_HANDLER *data_handler);
......
......@@ -2,14 +2,16 @@
#define EW2OPENAPI_HANDLER_STATUS_H 1
/* Status for OK */
#define HANDLER_STATUS_OK 0
#define HANDLER_STATUS_OK 0
/* Status for error which implies infinity retries */
#define HANDLER_STATUS_ERROR_INFINITY_RETRIES 1
#define HANDLER_STATUS_ERROR_INFINITY_RETRIES 1
/* Status for error which implies limited retries */
#define HANDLER_STATUS_ERROR_LIMITED_RETRIES 2
#define HANDLER_STATUS_ERROR_LIMITED_RETRIES 2
/* Status for error which implies limited retries but within max time interval */
#define HANDLER_STATUS_ERROR_LIMITED_RETRIES_WITHIN_TIME 3
/* Status for error which implies no retries */
#define HANDLER_STATUS_ERROR_NO_RETRIES 3
#define HANDLER_STATUS_ERROR_NO_RETRIES 4
#endif
/* DO NOT EDIT. Automatically generated. Change file HISTORY in ew2openapi_version main directory. */
#define EW2OPENAPI_NAME "ew2openapi"
#define EW2OPENAPI_VERSION "1.13.0 (2021-01-22)"
#define EW2OPENAPI_VERSION "1.14.0 (2021-02-15)"
#define EW2OPENAPI_NAME_AND_VERSION EW2OPENAPI_NAME" "EW2OPENAPI_VERSION
#define EW2OPENAPI_USERAGENT EW2OPENAPI_NAME"/"EW2OPENAPI_VERSION
#define EW2OPENAPI_URL_PATH "quakedb/ew/v1"
#define EW2OPENAPI_URL_PATH_STATUS "quakedb/status"
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment