]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
threading/queues: add way to lookup by ID
authorVictor Julien <victor@inliniac.net>
Mon, 11 Nov 2019 19:48:11 +0000 (20:48 +0100)
committerVictor Julien <victor@inliniac.net>
Fri, 7 Feb 2020 14:43:10 +0000 (15:43 +0100)
In preparation of doing runtime operations by ID instead of by name,
add functions to look up by ID and to convert name to ID.

src/tm-queuehandlers.c
src/tm-queuehandlers.h

index 862fc7d396aec766b18b1ffc98e000d9cd661545..dff60c310407e69908cd76f4103e5fc8707121a2 100644 (file)
@@ -48,15 +48,34 @@ void TmqhCleanup(void)
 {
 }
 
-Tmqh* TmqhGetQueueHandlerByName(const char *name)
+int TmqhNameToID(const char *name)
 {
-    int i;
+    for (int i = 0; i < TMQH_SIZE; i++) {
+        if (tmqh_table[i].name != NULL) {
+            if (strcmp(name, tmqh_table[i].name) == 0)
+                return i;
+        }
+    }
+
+    return -1;
+}
 
-    for (i = 0; i < TMQH_SIZE; i++) {
-        if (strcmp(name, tmqh_table[i].name) == 0)
-            return &tmqh_table[i];
+Tmqh *TmqhGetQueueHandlerByName(const char *name)
+{
+    for (int i = 0; i < TMQH_SIZE; i++) {
+        if (tmqh_table[i].name != NULL) {
+            if (strcmp(name, tmqh_table[i].name) == 0)
+                return &tmqh_table[i];
+        }
     }
 
     return NULL;
 }
 
+Tmqh *TmqhGetQueueHandlerByID(const int id)
+{
+    if (id <= 0 || id >= TMQH_SIZE)
+        return NULL;
+
+    return &tmqh_table[id];
+}
index e4dc329db3d55ced3c477845361a159506194da6..363a7256761bb60222698707087ff80aaaf3eda8 100644 (file)
@@ -25,6 +25,7 @@
 #define __TM_QUEUEHANDLERS_H__
 
 enum {
+    TMQH_NOT_SET,
     TMQH_SIMPLE,
     TMQH_PACKETPOOL,
     TMQH_FLOW,
@@ -46,7 +47,9 @@ Tmqh tmqh_table[TMQH_SIZE];
 
 void TmqhSetup (void);
 void TmqhCleanup(void);
-Tmqh* TmqhGetQueueHandlerByName(const char *name);
+int TmqhNameToID(const char *name);
+Tmqh *TmqhGetQueueHandlerByName(const char *name);
+Tmqh *TmqhGetQueueHandlerByID(const int id);
 
 #endif /* __TM_QUEUEHANDLERS_H__ */