summaryrefslogtreecommitdiff
path: root/src/core/registry.c
diff options
context:
space:
mode:
authorinfo@mode42.com <info@mode42.com>2026-08-08 03:54:55 +0000
committerinfo@mode42.com <info@mode42.com>2026-08-08 03:54:55 +0000
commit20cb29c2f8c5c87bc590896854a20b1473ceb358 (patch)
tree2857f41513a56ad41af97b57362639298aa7f033 /src/core/registry.c
#2
Diffstat (limited to 'src/core/registry.c')
-rw-r--r--src/core/registry.c83
1 files changed, 83 insertions, 0 deletions
diff --git a/src/core/registry.c b/src/core/registry.c
new file mode 100644
index 0000000..107cc66
--- /dev/null
+++ b/src/core/registry.c
@@ -0,0 +1,83 @@
+#include "hybbx/registry.h"
+#include "hybbx/limits.h"
+
+#include <string.h>
+
+typedef struct registry_entry {
+ const hybbx_transport_plugin_t *plugin;
+} registry_entry_t;
+
+static registry_entry_t g_registry[HYBBX_MAX_PLUGINS];
+static size_t g_registry_count = 0;
+
+hybbx_result_t hybbx_registry_register(const hybbx_transport_plugin_t *plugin)
+{
+ if (plugin == NULL || plugin->name == NULL) {
+ return HYBBX_ERR_INVALID;
+ }
+
+ if (hybbx_registry_find(plugin->name) != NULL) {
+ return HYBBX_ERR_BUSY;
+ }
+
+ if (g_registry_count >= HYBBX_MAX_PLUGINS) {
+ return HYBBX_ERR_NOMEM;
+ }
+
+ g_registry[g_registry_count].plugin = plugin;
+ g_registry_count++;
+ return HYBBX_OK;
+}
+
+hybbx_result_t hybbx_registry_unregister(const char *name)
+{
+ size_t i;
+
+ if (name == NULL) {
+ return HYBBX_ERR_INVALID;
+ }
+
+ for (i = 0; i < g_registry_count; i++) {
+ if (strcmp(g_registry[i].plugin->name, name) == 0) {
+ size_t remaining = g_registry_count - i - 1;
+ if (remaining > 0) {
+ memmove(&g_registry[i], &g_registry[i + 1],
+ remaining * sizeof(registry_entry_t));
+ }
+ g_registry_count--;
+ return HYBBX_OK;
+ }
+ }
+
+ return HYBBX_ERR_NOT_FOUND;
+}
+
+const hybbx_transport_plugin_t *hybbx_registry_find(const char *name)
+{
+ size_t i;
+
+ if (name == NULL) {
+ return NULL;
+ }
+
+ for (i = 0; i < g_registry_count; i++) {
+ if (strcmp(g_registry[i].plugin->name, name) == 0) {
+ return g_registry[i].plugin;
+ }
+ }
+
+ return NULL;
+}
+
+void hybbx_registry_foreach(hybbx_registry_iter_fn fn, void *userdata)
+{
+ size_t i;
+
+ if (fn == NULL) {
+ return;
+ }
+
+ for (i = 0; i < g_registry_count; i++) {
+ fn(g_registry[i].plugin, userdata);
+ }
+}
git clone -b <branch> https://cgit.mode42.com/<repo>.git
git clone -b <branch> git://cgit.mode42.com/<repo>.git

info@mode42.com