From: Thierry FOURNIER Date: Fri, 23 Feb 2018 10:42:57 +0000 (+0100) Subject: MINOR: spoa-server: move some definition from spoa_server.c to spoa_server.h X-Git-Tag: v2.0-dev3~37 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4aec0a4a9a5c11518baea18246bd5ab45412f7ed;p=thirdparty%2Fhaproxy.git MINOR: spoa-server: move some definition from spoa_server.c to spoa_server.h This will allow to add some other files to the project --- diff --git a/contrib/spoa_server/spoa.c b/contrib/spoa_server/spoa.c index ce59c04a08..52d1c914db 100644 --- a/contrib/spoa_server/spoa.c +++ b/contrib/spoa_server/spoa.c @@ -7,6 +7,7 @@ * using the SPOE. * * Copyright 2016 HAProxy Technologies, Christopher Faulet + * Copyright 2018 OZON / Thierry Fournier * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -28,11 +29,10 @@ #include #include +#include "spoa.h" + #define DEFAULT_PORT 12345 #define NUM_WORKERS 5 -#define MAX_FRAME_SIZE 16384 -#define SPOP_VERSION "1.0" -#define SPOA_CAPABILITIES "" #define SLEN(str) (sizeof(str)-1) @@ -65,21 +65,6 @@ enum spoe_frame_type { SPOE_FRM_T_AGENT_ACK }; -/* All supported data types */ -enum spoe_data_type { - SPOE_DATA_T_NULL = 0, - SPOE_DATA_T_BOOL, - SPOE_DATA_T_INT32, - SPOE_DATA_T_UINT32, - SPOE_DATA_T_INT64, - SPOE_DATA_T_UINT64, - SPOE_DATA_T_IPV4, - SPOE_DATA_T_IPV6, - SPOE_DATA_T_STR, - SPOE_DATA_T_BIN, - SPOE_DATA_TYPES -}; - /* Errors triggerd by SPOE applet */ enum spoe_frame_error { SPOE_FRM_ERR_NONE = 0, @@ -103,16 +88,6 @@ enum spoe_action_type { SPOE_ACT_TYPES, }; -/* Scopes used for variables set by agents. It is a way to be agnotic to vars - * scope. */ -enum spoe_vars_scope { - SPOE_SCOPE_PROC = 0, /* <=> SCOPE_PROC */ - SPOE_SCOPE_SESS, /* <=> SCOPE_SESS */ - SPOE_SCOPE_TXN, /* <=> SCOPE_TXN */ - SPOE_SCOPE_REQ, /* <=> SCOPE_REQ */ - SPOE_SCOPE_RES, /* <=> SCOPE_RES */ -}; - /* Masks to get data type or flags value */ #define SPOE_DATA_T_MASK 0x0F @@ -135,40 +110,6 @@ static const char *spoe_frm_err_reasons[SPOE_FRM_ERRS] = { [SPOE_FRM_ERR_UNKNOWN] = "an unknown error occurred", }; -struct worker { - unsigned int id; - char buf[MAX_FRAME_SIZE]; - unsigned int len; - unsigned int size; - int status_code; - unsigned int stream_id; - unsigned int frame_id; - bool healthcheck; - int ip_score; /* -1 if unset, else between 0 and 100 */ -}; - -struct chunk { - char *str; /* beginning of the string itself. Might not be 0-terminated */ - int len; /* current size of the string from first to last char */ -}; - -union spoe_value { - bool boolean; /* use for boolean */ - int32_t sint32; /* used for signed 32bits integers */ - uint32_t uint32; /* used for signed 32bits integers */ - int32_t sint64; /* used for signed 64bits integers */ - uint32_t uint64; /* used for signed 64bits integers */ - struct in_addr ipv4; /* used for ipv4 addresses */ - struct in6_addr ipv6; /* used for ipv6 addresses */ - struct chunk buffer; /* used for char strings or buffers */ -}; - -/* Used to store sample constant */ -struct spoe_data { - enum spoe_data_type type; /* SPOE_DATA_T_* */ - union spoe_value u; /* spoe data value */ -}; - static bool debug = false; static pthread_key_t worker_id; diff --git a/contrib/spoa_server/spoa.h b/contrib/spoa_server/spoa.h new file mode 100644 index 0000000000..81f5816c2e --- /dev/null +++ b/contrib/spoa_server/spoa.h @@ -0,0 +1,81 @@ +/* Main SPOA server includes + * + * Copyright 2016 HAProxy Technologies, Christopher Faulet + * Copyright 2018 OZON / Thierry Fournier + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version + * 2 of the License, or (at your option) any later version. + */ +#ifndef __SPOA_H__ +#define __SPOA_H__ + +#include +#include +#include + +#define MAX_FRAME_SIZE 16384 +#define SPOP_VERSION "1.0" +#define SPOA_CAPABILITIES "" + +/* All supported data types */ +enum spoe_data_type { + SPOE_DATA_T_NULL = 0, + SPOE_DATA_T_BOOL, + SPOE_DATA_T_INT32, + SPOE_DATA_T_UINT32, + SPOE_DATA_T_INT64, + SPOE_DATA_T_UINT64, + SPOE_DATA_T_IPV4, + SPOE_DATA_T_IPV6, + SPOE_DATA_T_STR, + SPOE_DATA_T_BIN, + SPOE_DATA_TYPES +}; + +/* Scopes used for variables set by agents. It is a way to be agnotic to vars + * scope. */ +enum spoe_vars_scope { + SPOE_SCOPE_PROC = 0, /* <=> SCOPE_PROC */ + SPOE_SCOPE_SESS, /* <=> SCOPE_SESS */ + SPOE_SCOPE_TXN, /* <=> SCOPE_TXN */ + SPOE_SCOPE_REQ, /* <=> SCOPE_REQ */ + SPOE_SCOPE_RES, /* <=> SCOPE_RES */ +}; + +struct worker { + unsigned int id; + char buf[MAX_FRAME_SIZE]; + unsigned int len; + unsigned int size; + int status_code; + unsigned int stream_id; + unsigned int frame_id; + bool healthcheck; + int ip_score; /* -1 if unset, else between 0 and 100 */ +}; + +struct chunk { + char *str; /* beginning of the string itself. Might not be 0-terminated */ + int len; /* current size of the string from first to last char */ +}; + +union spoe_value { + bool boolean; /* use for boolean */ + int32_t sint32; /* used for signed 32bits integers */ + uint32_t uint32; /* used for signed 32bits integers */ + int32_t sint64; /* used for signed 64bits integers */ + uint32_t uint64; /* used for signed 64bits integers */ + struct in_addr ipv4; /* used for ipv4 addresses */ + struct in6_addr ipv6; /* used for ipv6 addresses */ + struct chunk buffer; /* used for char strings or buffers */ +}; + +/* Used to store sample constant */ +struct spoe_data { + enum spoe_data_type type; /* SPOE_DATA_T_* */ + union spoe_value u; /* spoe data value */ +}; + +#endif /* __SPOA_H__ */