MINOR: spoa-server: Allow registering message processors

This function register processor executed by any language for processing
an SPOP message.
This commit is contained in:
Thierry FOURNIER 2018-02-23 14:27:05 +01:00 committed by Willy Tarreau
parent 64eaa33214
commit 892f6647c1
2 changed files with 39 additions and 0 deletions

View File

@ -98,6 +98,7 @@ static const char *spoe_frm_err_reasons[SPOE_FRM_ERRS] = {
bool debug = false; bool debug = false;
pthread_key_t worker_id; pthread_key_t worker_id;
static struct ps *ps_list = NULL; static struct ps *ps_list = NULL;
static struct ps_message *ps_messages = NULL;
void ps_register(struct ps *ps) void ps_register(struct ps *ps)
{ {
@ -105,6 +106,35 @@ void ps_register(struct ps *ps)
ps_list = ps; ps_list = ps;
} }
void ps_register_message(struct ps *ps, const char *name, void *ref)
{
struct ps_message *msg;
/* Look for already registered name */
for (msg = ps_messages; msg; msg = msg->next) {
if (strcmp(name, msg->name) == 0) {
LOG("Message \"%s\" already registered\n", name);
exit(EXIT_FAILURE);
}
}
msg = calloc(1, sizeof(*msg));
if (msg == NULL) {
LOG("Out of memory error\n");
exit(EXIT_FAILURE);
}
msg->next = ps_messages;
ps_messages = msg;
msg->name = strdup(name);
if (msg->name == NULL) {
LOG("Out of memory error\n");
exit(EXIT_FAILURE);
}
msg->ref = ref;
msg->ps = ps;
}
static void static void
check_ipv4_reputation(struct worker *w, struct in_addr *ipv4) check_ipv4_reputation(struct worker *w, struct in_addr *ipv4)
{ {

View File

@ -89,12 +89,21 @@ struct ps {
struct ps *next; struct ps *next;
char *ext; char *ext;
int (*init_worker)(struct worker *w); int (*init_worker)(struct worker *w);
int (*exec_message)(struct worker *w, void *ref, int nargs, struct spoe_kv *args);
};
struct ps_message {
struct ps_message *next;
const char *name;
struct ps *ps;
void *ref;
}; };
extern bool debug; extern bool debug;
extern pthread_key_t worker_id; extern pthread_key_t worker_id;
void ps_register(struct ps *ps); void ps_register(struct ps *ps);
void ps_register_message(struct ps *ps, const char *name, void *ref);
#define LOG(fmt, args...) \ #define LOG(fmt, args...) \
do { \ do { \