Commit 6aad23d2 authored by Matteo Quintiliani's avatar Matteo Quintiliani
Browse files

Merge branch 'release/1.12.0'

parents 5574836d f5fbb96d
Pipeline #6329 passed with stages
in 1 minute and 34 seconds
......@@ -21,28 +21,7 @@ build:
# Install cmake
- apt-get update && apt-get install -y cmake
script:
# Checkout only Earthworm libraries source and its dependencies
- git clone https://${CI_DEPLOY_TOKEN_EW}:${CI_DEPLOY_SECRET_EW}@gitlab.rm.ingv.it/earthworm/earthworm.git/ $EW_INSTALL_HOME/$EW_INSTALL_VERSION
# - svn checkout --depth empty svn://svn.isti.com/earthworm/trunk $EW_INSTALL_HOME/$EW_INSTALL_VERSION
# - cd $EW_INSTALL_HOME/$EW_INSTALL_VERSION/
# - svn update --set-depth infinity include
# - svn update --set-depth infinity lib
# - svn update --set-depth infinity bin
# - svn update --set-depth infinity environment
# - svn update --set-depth infinity params
# - svn update --set-depth empty src
# - svn update --set-depth infinity src/libsrc
# - cd -
# Set Earthworm variables from EW_INSTALL_X variables
- . $EW_INSTALL_HOME/$EW_INSTALL_VERSION/environment/ew_linux.bash
# Copy earthworm.d earthworm_global.d from environment/ to params/
- cp $EW_INSTALL_HOME/$EW_INSTALL_VERSION/environment/earthworm.d $EW_INSTALL_HOME/$EW_INSTALL_VERSION/environment/earthworm_global.d $EW_INSTALL_HOME/$EW_INSTALL_VERSION/params/
# Build Earthworm libraries
- cd $EW_INSTALL_HOME/$EW_INSTALL_VERSION/src/libsrc
- make -f makefile.unix clean
- make -f makefile.unix
- cd -
# Update git submodule json-c and rabbitmq-c
# Update git submodule json-c, rabbitmq-c and liblo before compiling Earthworm and ew2openapi
- git submodule update --init
# Configure and build json-c
- cd json-c
......@@ -57,6 +36,32 @@ build:
- cmake -DENABLE_SSL_SUPPORT=OFF ..
- cmake --build .
- cd -
# Configure and build liblo
- cd liblo
- ./autogen.sh --enable-static
- make
- cd -
# Checkout only Earthworm libraries source and its dependencies
# - git clone https://${CI_DEPLOY_TOKEN_EW}:${CI_DEPLOY_SECRET_EW}@gitlab.rm.ingv.it/earthworm/earthworm.git/ $EW_INSTALL_HOME/$EW_INSTALL_VERSION
- svn checkout --depth empty svn://svn.isti.com/earthworm/trunk $EW_INSTALL_HOME/$EW_INSTALL_VERSION
- cd $EW_INSTALL_HOME/$EW_INSTALL_VERSION/
- svn update --set-depth infinity include
- svn update --set-depth infinity lib
- svn update --set-depth infinity bin
- svn update --set-depth infinity environment
- svn update --set-depth infinity params
- svn update --set-depth empty src
- svn update --set-depth infinity src/libsrc
- cd -
# Set Earthworm variables from EW_INSTALL_X variables
- . $EW_INSTALL_HOME/$EW_INSTALL_VERSION/environment/ew_linux.bash
# Copy earthworm.d earthworm_global.d from environment/ to params/
- cp $EW_INSTALL_HOME/$EW_INSTALL_VERSION/environment/earthworm.d $EW_INSTALL_HOME/$EW_INSTALL_VERSION/environment/earthworm_global.d $EW_INSTALL_HOME/$EW_INSTALL_VERSION/params/
# Build Earthworm libraries
- cd $EW_INSTALL_HOME/$EW_INSTALL_VERSION/src/libsrc
- make -f makefile.unix clean
- make -f makefile.unix
- cd -
# Configure and build ew2openapi
- make -f makefile.unix static
# Copy binary in the current directory
......
......@@ -4,3 +4,6 @@
[submodule "rabbitmq-c"]
path = rabbitmq-c
url = https://github.com/alanxz/rabbitmq-c.git
[submodule "liblo"]
path = liblo
url = https://github.com/radarsat1/liblo.git
......@@ -2,6 +2,17 @@
ew2openapi Release History
#########################
* Release 1.12.0 (2020/12/18)
- Checkout Earthworm from official Subversion repository in gitlab-ci.yml. Issue #14 (2020/04/20)
- Major changes in source for making easy new system integrations. Issue #31 (2020/04/20)
- Add handling of http codes 422 (Unprocessable Entity) and 428 (Precondition Required). Issue #33 (2020/07/16)
- Add OSC handler. (2020/04/21)
- Fix bug after calling cpqueuering(). Issue #34 (2020/07/28)
- Handle http code 422 (Unprocessable Entity) by HANDLER_STATUS_ERROR_NO_RETRIES. Issue #36 (2020/07/28)
- Fixing thread managing. Issue #37 (2020/07/29)
- Use DateTime Format RFC3339 / ISO 8601. Issue #38 (2020/11/30)
- Change BaseApiURL and substitude '_' with '-'. (2020/12/18)
* Release 1.11.2 (2020/05/20)
- Under development reading extra fields in ARC structure related to magnitude values. Issue #25 (2020/03/12)
- Hotfix 1.11.1: Fix make -f makefile.unix test for ARC_EXTRA_FIELDS. Issue #25 (2020/03/12)
......
1.11.2 - 2020-05-20
\ No newline at end of file
1.12.0 - 2020-12-18
\ No newline at end of file
Subproject commit 199742083ec81d73aafecd81959b5f20fa141dd4
......@@ -6,19 +6,27 @@ CC = gcc
# json-c directory
JSONCDIR = ./json-c
# rabbitmq-c directory
RABBITMQDIR = ./rabbitmq-c
# liblo directory
LIBLODIR = ./liblo
# not used. TODO: Check!
LINUX_FLAGS=-lpthread -fstack-check -Wall -lm
SOLARIS_FLAGS=-mt -lposix4 -lthread -lpthread -lsocket -lnsl -lm
SPECIFIC_FLAGS = $($(PLATFORM)_FLAGS) -lrabbitmq -ljson-c
SPECIFIC_FLAGS_STATIC = $(RABBITMQDIR)/build/librabbitmq/librabbitmq.a $(JSONCDIR)/build/lib/libjson-c.a $($(PLATFORM)_FLAGS)
SPECIFIC_FLAGS = $($(PLATFORM)_FLAGS) -lrabbitmq -ljson-c -llo
SPECIFIC_FLAGS_STATIC = $(RABBITMQDIR)/build/librabbitmq/librabbitmq.a $(JSONCDIR)/build/lib/libjson-c.a $(LIBLODIR)/src/.libs/liblo.a $($(PLATFORM)_FLAGS)
LINUX_CFLAGS = -Wall
SOLARIS_CFLAGS =
SPECIFIC_CFLAGS = $($(PLATFORM)_CFLAGS)
# json-c flags
CFLAGS_JSON = -I$(JSONCDIR)/build/include
# curl flags
CFLAGS_CURL = `curl-config --cflags`
LDFLAGS_CURL = `curl-config --libs`
......@@ -26,9 +34,16 @@ LDFLAGS_CURL = `curl-config --libs`
# LDFLAGS_CURL_STATIC = `curl-config --static-libs`
LDFLAGS_CURL_STATIC = `curl-config --libs`
# rabbitmq-c flags
CFLAGS_RABBITMQ = -I$(RABBITMQDIR)/librabbitmq
# liblo flags
CFLAGS_LIBLO = -I$(LIBLODIR)
CFLAGS = -D_REENTRANT $(GLOBALFLAGS) $(SPECIFIC_CFLAGS)
CFLAGS += -g
CFLAGS += -I$(RABBITMQDIR)/librabbitmq -I$(JSONCDIR)/build/include $(CFLAGS_CURL)
CFLAGS += $(CFLAGS_JSON) $(CFLAGS_CURL) $(CFLAGS_RABBITMQ) $(CFLAGS_LIBLO)
# Under development reading extra fields in ARC structure related to magnitude values
# https://gitlab.rm.ingv.it/earthworm/ew2openapi/issues/25
# CFLAGS += -D ARC_EXTRA_FIELDS
......@@ -41,19 +56,21 @@ B = $(EW_HOME)/$(EW_VERSION)/bin
L = $(EW_HOME)/$(EW_VERSION)/lib
BINARIES = \
$(S)/ew2openapi_curl.o \
$(S)/ew2openapi_handler_quakedb_ws.o \
$(S)/ew2openapi_handler_rabbitmq.o \
$(S)/ew2openapi_handler_osc.o \
$(S)/ew2openapi_logit.o \
$(S)/ew2openapi_utils.o \
$(S)/ew2openapi_json.o \
$(S)/ew2openapi_geojson.o \
$(S)/ew2openapi_pickcoda.o \
$(S)/ew2openapi_quakelink.o \
$(S)/ew2openapi_arc.o \
$(S)/ew2openapi_magnitude.o \
$(S)/ew2openapi_strongmotionII.o \
$(S)/ew2openapi_eq_version_name.o \
$(S)/ew2openapi_error.o \
$(S)/ew2openapi_heartbeat.o \
$(S)/ew2openapi_utils.o \
$(S)/ew2openapi_json_utils.o \
$(S)/ew2openapi_geojson_utils.o \
$(S)/ew2openapi_json_pickcoda.o \
$(S)/ew2openapi_json_quakelink.o \
$(S)/ew2openapi_json_arc.o \
$(S)/ew2openapi_json_magnitude.o \
$(S)/ew2openapi_json_strongmotionII.o \
$(S)/ew2openapi_json_error.o \
$(S)/ew2openapi_json_heartbeat.o \
$(S)/amqp_utils.o \
$(S)/ew2openapi.o \
$L/libebloc.a $L/libebpick.a \
......@@ -61,19 +78,23 @@ BINARIES = \
$L/mem_circ_queue.o $L/getsysname_ew.o $L/libew_mt.a $L/dirops_ew.o $L/site.o
HEADERS = $(S)/ew2openapi_version.h \
$(S)/ew2openapi_curl.h \
$(S)/ew2openapi_handler_quakedb_ws.h \
$(S)/ew2openapi_handler_rabbitmq.h \
$(S)/ew2openapi_handler_osc.h \
$(S)/ew2openapi_logit.h \
$(S)/ew2openapi_utils.h \
$(S)/ew2openapi_json.h \
$(S)/ew2openapi_geojson.h \
$(S)/ew2openapi_pickcoda.h \
$(S)/ew2openapi_quakelink.h \
$(S)/ew2openapi_arc.h \
$(S)/ew2openapi_magnitude.h \
$(S)/ew2openapi_strongmotionII.h \
$(S)/ew2openapi_eq_version_name.h \
$(S)/ew2openapi_error.h \
$(S)/ew2openapi_heartbeat.h \
$(S)/ew2openapi_handler_status.h \
$(S)/ew2openapi_params.h \
$(S)/ew2openapi_utils.h \
$(S)/ew2openapi_json_utils.h \
$(S)/ew2openapi_geojson_utils.h \
$(S)/ew2openapi_json_pickcoda.h \
$(S)/ew2openapi_json_quakelink.h \
$(S)/ew2openapi_json_arc.h \
$(S)/ew2openapi_json_magnitude.h \
$(S)/ew2openapi_json_strongmotionII.h \
$(S)/ew2openapi_json_error.h \
$(S)/ew2openapi_json_heartbeat.h \
$(S)/amqp_utils.h
all: dynamic
......@@ -81,10 +102,10 @@ all: dynamic
dynamic: $B/$(APP)
static: $(BINARIES) $(HEADERS)
$(CC) -o $B/ew2openapi $(CFLAGS) $(BINARIES) $(LDFLAGS) $(LDFLAGS_CURL_STATIC) $(SPECIFIC_FLAGS_STATIC)
$(CC) -o $B/$(APP) $(CFLAGS) $(BINARIES) $(LDFLAGS) $(LDFLAGS_CURL_STATIC) $(SPECIFIC_FLAGS_STATIC)
$B/$(APP): $(BINARIES) $(HEADERS)
$(CC) -o $B/ew2openapi $(CFLAGS) $(BINARIES) $(LDFLAGS) $(LDFLAGS_CURL) $(SPECIFIC_FLAGS)
$(CC) -o $B/$(APP) $(CFLAGS) $(BINARIES) $(LDFLAGS) $(LDFLAGS_CURL) $(SPECIFIC_FLAGS)
$(S)/%.o : %.c
$(CC) $(CFLAGS) -c $<
......
#!/bin/bash
# Test ew2openapi standalone with TYPE_PICK_SCNL input file
ew2openapi TYPE_PICK_SCNL ./test/pick_ew/message.pick_scnl ./test/json/message.pick_scnl.json
# Test ew2openapi standalone with TYPE_QUAKE2K input file
ew2openapi TYPE_QUAKE2K ./test/binder_ew/message.quake2k ./test/json/message.quake2k.json
# Test ew2openapi standalone with TYPE_LINK input file
ew2openapi TYPE_LINK ./test/binder_ew/message.link ./test/json/message.link.json
# Test ew2openapi standalone with ARC input file
ew2openapi TYPE_HYP2000ARC ./test/arc/20180205-080122.0009627.arc ./test/json/20180205-080122.0009627.json
# - sed -e 's/"hostname":[[:space:]]*"\([^"]\+\)"/"hostname": "DIFF_IGNORE_HOSTNAME"/' j1.json > jj1.json
# - sed -e 's/"hostname":[[:space:]]*"\([^"]\+\)"/"hostname": "DIFF_IGNORE_HOSTNAME"/' j2.json > jj2.json
# - grep -w -v "hostname" j1.json > jj1.json
# - grep -w -v "hostname" j2.json > jj2.json
# - diff jj1.json jj2.json
# Test ew2openapi standalone with ARC input file
ew2openapi TYPE_HYP2000ARC ./test/arc/20170118-1014097.arc ./test/json/20170118-1014097.json
# - sed -e 's/"hostname":[[:space:]]*"\([^"]\+\)"/"hostname": "DIFF_IGNORE_HOSTNAME"/' j1.json > jj1.json
# - sed -e 's/"hostname":[[:space:]]*"\([^"]\+\)"/"hostname": "DIFF_IGNORE_HOSTNAME"/' j2.json > jj2.json
# - grep -w -v "hostname" j1.json > jj1.json
# - grep -w -v "hostname" j2.json > jj2.json
# - diff jj1.json jj2.json
# Test ew2openapi standalone with TYPE_MAGNITUDE input file
ew2openapi TYPE_MAGNITUDE ./test/localmag/lm_75662.localmag ./test/json/lm_75662.localmag.json
# Test ew2openapi standalone with TYPE_STRONGMOTIONII input file
ew2openapi TYPE_STRONGMOTIONII ./test/gmew/APRC.HHE.IV.--.001.gmew ./test/json/APRC.HHE.IV.--.001.gmew.json
# - sed -e 's/"hostname":[[:space:]]*"\([^"]\+\)"/"hostname": "DIFF_IGNORE_HOSTNAME"/' j1.json > jj1.json
# - sed -e 's/"hostname":[[:space:]]*"\([^"]\+\)"/"hostname": "DIFF_IGNORE_HOSTNAME"/' j2.json > jj2.json
# - grep -w -v "hostname" j1.json > jj1.json
# - grep -w -v "hostname" j2.json > jj2.json
# - diff jj1.json jj2.json
This diff is collapsed.
#ifndef EW2OPENAPI_CURL_H
#define EW2OPENAPI_CURL_H 1
#include <curl/curl.h>
#include <transport.h>
CURLcode ew2openapi_curl_init(long flags);
void ew2openapi_curl_cleanup();
long ew2openapi_curl_sendstring(char *ApiBaseUrl, char *buf, size_t len, MSG_LOGO *reclogo, char flag_geojson);
#endif
......@@ -3,10 +3,10 @@
#define MAX_EW2OPENAPI_VERSION_NAME 3
const char *ew2openapi_version_name[MAX_EW2OPENAPI_VERSION_NAME];
const char *ew2openapi_version_name_unknown;
extern const char *ew2openapi_version_name[MAX_EW2OPENAPI_VERSION_NAME];
extern const char *ew2openapi_version_name_unknown;
const char *ew2openapi_get_name_version(int version);
extern const char *ew2openapi_get_name_version(int version);
#endif
......
#include <json-c/json.h>
#include "ew2openapi_geojson.h"
#include "ew2openapi_json.h"
#include "ew2openapi_geojson_utils.h"
#include "ew2openapi_json_utils.h"
#define GEO_COORDINATES_PRECISION 5
......
#ifndef EW2OPENAPI_GEOJSON_H
#define EW2OPENAPI_GEOJSON_H 1
#ifndef EW2OPENAPI_GEOJSON_UTILS_H
#define EW2OPENAPI_GEOJSON_UTILS_H 1
struct json_object *json_object_new_geojson_position (double x, double y);
struct json_object *json_object_new_geojson_position3 (double x, double y, double z);
......
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifndef WIN32
#include <unistd.h>
#endif
#include "lo/lo.h"
#include <earthworm.h>
#include "ew2openapi_logit.h"
#include "ew2openapi_handler_osc.h"
#include "ew2openapi_handler_status.h"
lo_address osc_address = NULL;
int ew2openapi_handler_osc_init(TYPE_PARAMS *params) {
int ret = 0;
/* TODO */
osc_address = lo_address_new(NULL, "7770");
return ret;
}
int ew2openapi_handler_osc_destroy(TYPE_PARAMS *params) {
int ret = 0;
/* TODO */
return ret;
}
int ew2openapi_handler_osc_handle(TYPE_DATA_HANDLER *data_handler) {
int handler_status_code = HANDLER_STATUS_OK;
/* TODO */
/* send a jamin scene change instruction with a 32bit integer argument */
lo_send(osc_address, "/jamin/scene", "i", 2);
return handler_status_code;
}
#ifndef EW2OPENAPI_HANDLER_OSC_H
#define EW2OPENAPI_HANDLER_OSC_H 1
#include <transport.h>
#include "ew2openapi_params.h"
int ew2openapi_handler_osc_init(TYPE_PARAMS *params);
int ew2openapi_handler_osc_destroy(TYPE_PARAMS *params);
int ew2openapi_handler_osc_handle(TYPE_DATA_HANDLER *data_handler);
#endif
......@@ -5,18 +5,30 @@
#include <earthworm.h>
#include "ew2openapi_logit.h"
#include "ew2openapi_curl.h"
#include "ew2openapi_handler_quakedb_ws.h"
#include "ew2openapi_json_utils.h"
#include "ew2openapi_handler_status.h"
#define MAX_API_URL 1024
/* 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() */
CURLcode ew2openapi_curl_init(long flags) {
return curl_global_init(flags);
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);
/* TODO set ret based on ret_curl */
return ret;
}
/* Wrapper to curl_global_cleanup() */
void ew2openapi_curl_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)
......@@ -39,7 +51,7 @@ void ew2openapi_curl_cleanup() {
* }
*/
static size_t ew2openapi_curl_WRITEFUNCTION_ew2openapi_logit(void *contents, size_t size, size_t nmemb, void *userp)
static size_t ew2openapi_handler_quakedb_ws_WRITEFUNCTION_ew2openapi_logit(void *contents, size_t size, size_t nmemb, void *userp)
{
size_t realsize = size * nmemb;
char *contents_string = NULL;
......@@ -58,7 +70,7 @@ static size_t ew2openapi_curl_WRITEFUNCTION_ew2openapi_logit(void *contents, siz
/* Send Earthworm message to EWOpenAPI */
long ew2openapi_curl_sendstring(char *ApiBaseUrl, char *buf, size_t len, MSG_LOGO *reclogo, char flag_geojson)
long ew2openapi_handler_quakedb_ws_sendstring(char *ApiBaseUrl, char *buf, size_t len, MSG_LOGO *reclogo, char flag_geojson)
{
CURL *curl;
CURLcode res;
......@@ -84,7 +96,7 @@ long ew2openapi_curl_sendstring(char *ApiBaseUrl, char *buf, size_t len, MSG_LOG
JsonObj[JsonObj_len - 1] = 0;
snprintf(JsonObj, JsonObj_len - 1, "%s%s%s", JsonObj_pre, buf, JsonObj_post);
} else {
ew2openapi_logit("et", "ew2openapi_curl_sendstring(): error allocating JsonObj.\n");
ew2openapi_logit("et", "ew2openapi_handler_quakedb_ws_sendstring(): error allocating JsonObj.\n");
return curl_http_code;
}
......@@ -103,11 +115,14 @@ long ew2openapi_curl_sendstring(char *ApiBaseUrl, char *buf, size_t len, MSG_LOG
if (ch >= 'A' && ch <= 'Z') {
ch = 'a' + (ch - 'A');
}
if (ch == '_' ) {
ch = '-';
}
api_type_ew_msg[i] = ch;
}
api_type_ew_msg[i] = '\0';
snprintf(apiurl, MAX_API_URL, "ew/%s/1/", api_type_ew_msg);
snprintf(apiurl, MAX_API_URL, "%s", api_type_ew_msg);
snprintf(url, MAX_API_URL, "%s/%s", ApiBaseUrl, apiurl);
ew2openapi_logit("et", "URL-DATA: %s\n", url);
......@@ -128,7 +143,7 @@ long ew2openapi_curl_sendstring(char *ApiBaseUrl, char *buf, size_t len, MSG_LOG
/* curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)strlen(JsonObj)); */
/* send all data to this function */
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, ew2openapi_curl_WRITEFUNCTION_ew2openapi_logit);
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);
......@@ -160,3 +175,88 @@ long ew2openapi_curl_sendstring(char *ApiBaseUrl, char *buf, size_t len, MSG_LOG
return curl_http_code;
}
int ew2openapi_handler_quakedb_ws_handle(TYPE_DATA_HANDLER *data_handler) {
char *json_string = NULL;
long curl_http_code = 0;
int handler_status_code = HANDLER_STATUS_OK;
char flag_geojson = 0;
if(
data_handler->params->send_message_format_flags & MESSAGE_FORMAT_JSON
||
data_handler->params->send_message_format_flags & MESSAGE_FORMAT_GEOJSON
) {
/* Build the JSON string for posting to service */
flag_geojson = data_handler->params->send_message_format_flags & MESSAGE_FORMAT_GEOJSON;
json_string = get_json_string_from_ew_msg(data_handler->Wrmsg, data_handler->msgSize, data_handler->reclogo, data_handler->params->ewinstancename, data_handler->ewUserName, data_handler->ewHostName, &flag_geojson);
}
if(json_string) {
/* CURL message */
ew2openapi_logit("et", "%s: %s\n", (flag_geojson)? "GeoJSON" : "JSON", json_string);
curl_http_code = ew2openapi_handler_quakedb_ws_sendstring(data_handler->params->ApiBaseUrl, json_string, strlen(json_string), data_handler->reclogo, flag_geojson);
ew2openapi_logit("et", "HTTP CODE: %ld\n", curl_http_code);
}
/* Based on curl_http_code classify the following status:
*
* - HANDLER_STATUS_OK
* - HANDLER_STATUS_ERROR_INFINITY_RETRIES
* - HANDLER_STATUS_ERROR_LIMITED_RETRIES
* - HANDLER_STATUS_ERROR_NO_RETRIES
*
* Refer https://httpstatuses.com/
*
*/
/* Init values before error classification */
handler_status_code = HANDLER_STATUS_OK;
if(curl_http_code < 0 && curl_http_code >= 300) {
ew2openapi_logit("et", "HTTP CODE: %ld\n", curl_http_code);
}
switch(curl_http_code) {
/* Generic errors: network connection, ... */
case -1:
/* Set handler_status_code to HANDLER_STATUS_ERROR_INFINITY_RETRIES */
handler_status_code = HANDLER_STATUS_ERROR_INFINITY_RETRIES;
break;
/* 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 422: // Unprocessable Entity
handler_status_code = HANDLER_STATUS_ERROR_NO_RETRIES;
break;
/* 5xx error codes */
case 500: // Internal Server Error
// case 501: // Not Implemented
case 502: // Bad Gateway
case 503: // Service Unavailable
case 504: // Gateway Timeout
// case 505: // HTTP Version Not Supported
// case 506: // Variant Also Negotiates
case 507: // Insufficient Storage
// case 508: // Loop Detected
// case 510: // Not Extended
case 511: // Network Authentication Required
case 599: // Network Connect Timeout Error
/* Set handler_status_code to HANDLER_STATUS_ERROR_INFINITY_RETRIES */
handler_status_code = HANDLER_STATUS_ERROR_INFINITY_RETRIES;
break;
/* Other error codes */
default:
/* Do nothing */
break;
}
return handler_status_code;
}
#ifndef EW2OPENAPI_HANDLER_QUAKEDB_WS_H
#define EW2OPENAPI_HANDLER_QUAKEDB_WS_H 1
#include <curl/curl.h>
#include <transport.h>
#include "ew2openapi_params.h"
int ew2openapi_handler_quakedb_ws_init(TYPE_PARAMS *params);
int ew2openapi_handler_quakedb_ws_destroy(TYPE_PARAMS *params);
int ew2openapi_handler_quakedb_ws_handle(TYPE_DATA_HANDLER *data_handler);
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <earthworm.h>
#include "ew2openapi_logit.h"
#include "ew2openapi_handler_rabbitmq.h"
#include "ew2openapi_json_utils.h"
#include "ew2openapi_handler_status.h"
/* Private functions */
int amqp_sendstring(char *buf, size_t len, long inkey, MSG_LOGO *logo, TYPE_PARAMS *params, char cur_send_message_format);
int ew2openapi_handler_rabbitmq_init(TYPE_PARAMS *params) {
int ret = 0;
/* TODO */
return ret;
}
int ew2openapi_handler_rabbitmq_destroy(TYPE_PARAMS *params) {
int ret = 0;
/* TODO */
return ret;
}
int amqp_sendstring(char *buf, size_t len, long inkey, MSG_LOGO *logo, TYPE_PARAMS *params, char cur_send_message_format)
{
int ret = 0;
char const *hostname;
int port, status;
char const *exchange;
#define MAX_MESSAGE_FORMAT_STRING 1024
char send_message_format_string[MAX_MESSAGE_FORMAT_STRING];
#define MAX_ROUTINGKEY_LEN 1024
char routingkey_var[MAX_ROUTINGKEY_LEN];
char const *routingkey;
char const *messagebody;
char const *vhost;
char const *username;
char const *password;
amqp_socket_t *socket = NULL;
amqp_connection_state_t conn;
amqp_bytes_t amqp_message;
switch(cur_send_message_format) {
case MESSAGE_FORMAT_RAW:
snprintf(send_message_format_string, MAX_MESSAGE_FORMAT_STRING-1, "RAW");
break;
case MESSAGE_FORMAT_JSON:
snprintf(send_message_format_string, MAX_MESSAGE_FORMAT_STRING-1, "JSON");
break;
case MESSAGE_FORMAT_GEOJSON:
snprintf(send_message_format_string, MAX_MESSAGE_FORMAT_STRING-1, "GEOJSON");
break;
default:
/* TODO ERROR */
break;
}
snprintf(routingkey_var, MAX_ROUTINGKEY_LEN-1, "EW.%s.%s.%s.%s.%s.%s", params->ewinstancename, GetKeyName(inkey), GetInstName(logo->instid), GetModIdName(logo->mod), GetTypeName(logo->type), send_message_format_string);
amqp_message.bytes = buf;