From: Victor Julien Date: Mon, 11 Nov 2019 19:48:11 +0000 (+0100) Subject: threading/queues: add way to lookup by ID X-Git-Tag: suricata-6.0.0-beta1~796 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=74a6f8d4ddf6fb1ea580561f12ff1bd8e4f68aad;p=thirdparty%2Fsuricata.git threading/queues: add way to lookup by ID 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. --- diff --git a/src/tm-queuehandlers.c b/src/tm-queuehandlers.c index 862fc7d396..dff60c3104 100644 --- a/src/tm-queuehandlers.c +++ b/src/tm-queuehandlers.c @@ -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]; +} diff --git a/src/tm-queuehandlers.h b/src/tm-queuehandlers.h index e4dc329db3..363a725676 100644 --- a/src/tm-queuehandlers.h +++ b/src/tm-queuehandlers.h @@ -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__ */