]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: spoa-server: Allow registering message processors
authorThierry FOURNIER <thierry.fournier@ozon.io>
Fri, 23 Feb 2018 13:27:05 +0000 (14:27 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 13 May 2019 15:43:47 +0000 (17:43 +0200)
This function register processor executed by any language for processing
an SPOP message.

contrib/spoa_server/spoa.c
contrib/spoa_server/spoa.h

index 6645c8ca3c061e7dc543ba31a62e4a3e8101d8bf..73b71338570cde4948453a3e6d45e16043e3dc89 100644 (file)
@@ -98,6 +98,7 @@ static const char *spoe_frm_err_reasons[SPOE_FRM_ERRS] = {
 bool debug = false;
 pthread_key_t worker_id;
 static struct ps *ps_list = NULL;
+static struct ps_message *ps_messages = NULL;
 
 void ps_register(struct ps *ps)
 {
@@ -105,6 +106,35 @@ void ps_register(struct ps *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
 check_ipv4_reputation(struct worker *w, struct in_addr *ipv4)
 {
index c8f9861b933a6460006b5f13e6f1654fff32fd2c..22d6788513813d541828db2fd773d47a4d78deb6 100644 (file)
@@ -89,12 +89,21 @@ struct ps {
        struct ps *next;
        char *ext;
        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 pthread_key_t worker_id;
 
 void ps_register(struct ps *ps);
+void ps_register_message(struct ps *ps, const char *name, void *ref);
 
 #define LOG(fmt, args...) \
        do { \