|
|
@ -4,7 +4,7 @@ |
|
|
|
#define BACKEND_LIBRARY_PARAM "load" |
|
|
|
#define BACKEND_LIBRARY_PARAM "load" |
|
|
|
|
|
|
|
|
|
|
|
f2b_backend_t * |
|
|
|
f2b_backend_t * |
|
|
|
f2b_backend_create(f2b_config_section_t *config) { |
|
|
|
f2b_backend_create(f2b_config_section_t *config, const char *id) { |
|
|
|
f2b_config_param_t *param = NULL; |
|
|
|
f2b_config_param_t *param = NULL; |
|
|
|
f2b_backend_t *backend = NULL; |
|
|
|
f2b_backend_t *backend = NULL; |
|
|
|
int flags = RTLD_NOW | RTLD_LOCAL; |
|
|
|
int flags = RTLD_NOW | RTLD_LOCAL; |
|
|
@ -21,39 +21,54 @@ f2b_backend_create(f2b_config_section_t *config) { |
|
|
|
|
|
|
|
|
|
|
|
if ((backend->h = dlopen(param->value, flags)) == NULL) |
|
|
|
if ((backend->h = dlopen(param->value, flags)) == NULL) |
|
|
|
goto cleanup; |
|
|
|
goto cleanup; |
|
|
|
if ((*(void **) (&backend->init) = dlsym(backend->h, "init")) == NULL) |
|
|
|
if ((*(void **) (&backend->create) = dlsym(backend->h, "create")) == NULL) |
|
|
|
|
|
|
|
goto cleanup; |
|
|
|
|
|
|
|
if ((*(void **) (&backend->config) = dlsym(backend->h, "config")) == NULL) |
|
|
|
goto cleanup; |
|
|
|
goto cleanup; |
|
|
|
if ((*(void **) (&backend->ready) = dlsym(backend->h, "ready")) == NULL) |
|
|
|
if ((*(void **) (&backend->ready) = dlsym(backend->h, "ready")) == NULL) |
|
|
|
goto cleanup; |
|
|
|
goto cleanup; |
|
|
|
|
|
|
|
if ((*(void **) (&backend->start) = dlsym(backend->h, "start")) == NULL) |
|
|
|
|
|
|
|
goto cleanup; |
|
|
|
|
|
|
|
if ((*(void **) (&backend->stop) = dlsym(backend->h, "stop")) == NULL) |
|
|
|
|
|
|
|
goto cleanup; |
|
|
|
|
|
|
|
if ((*(void **) (&backend->ping) = dlsym(backend->h, "ping")) == NULL) |
|
|
|
|
|
|
|
goto cleanup; |
|
|
|
if ((*(void **) (&backend->ban) = dlsym(backend->h, "ban")) == NULL) |
|
|
|
if ((*(void **) (&backend->ban) = dlsym(backend->h, "ban")) == NULL) |
|
|
|
goto cleanup; |
|
|
|
goto cleanup; |
|
|
|
if ((*(void **) (&backend->unban) = dlsym(backend->h, "unban")) == NULL) |
|
|
|
if ((*(void **) (&backend->unban) = dlsym(backend->h, "unban")) == NULL) |
|
|
|
goto cleanup; |
|
|
|
goto cleanup; |
|
|
|
if ((*(void **) (&backend->exists) = dlsym(backend->h, "exists")) == NULL) |
|
|
|
if ((*(void **) (&backend->exists) = dlsym(backend->h, "exists")) == NULL) |
|
|
|
goto cleanup; |
|
|
|
goto cleanup; |
|
|
|
|
|
|
|
if ((*(void **) (&backend->destroy) = dlsym(backend->h, "destroy")) == NULL) |
|
|
|
|
|
|
|
goto cleanup; |
|
|
|
|
|
|
|
|
|
|
|
if (backend->ready) |
|
|
|
if ((backend->cfg = backend->create(id)) == NULL) { |
|
|
|
return backend; |
|
|
|
f2b_log_msg(log_error, "backend create config failed"); |
|
|
|
|
|
|
|
goto cleanup; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* try init */ |
|
|
|
/* try init */ |
|
|
|
for (; param != NULL; param = param->next) { |
|
|
|
for (; param != NULL; param = param->next) { |
|
|
|
if (strcmp(param->name, BACKEND_LIBRARY_PARAM) == 0) |
|
|
|
if (strcmp(param->name, BACKEND_LIBRARY_PARAM) == 0) |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
if (!backend->init(param->name, param->value)) { |
|
|
|
if (backend->config(backend->cfg, param->name, param->value)) |
|
|
|
|
|
|
|
continue; |
|
|
|
f2b_log_msg(log_warn, "param pair not accepted by backend '%s': %s=%s", |
|
|
|
f2b_log_msg(log_warn, "param pair not accepted by backend '%s': %s=%s", |
|
|
|
config->name, param->name, param->value); |
|
|
|
config->name, param->name, param->value); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (backend->ready) |
|
|
|
if (backend->ready(backend->cfg)) |
|
|
|
return backend; |
|
|
|
return backend; |
|
|
|
|
|
|
|
|
|
|
|
/* still not ready */ |
|
|
|
/* still not ready */ |
|
|
|
f2b_log_msg(log_error, "backend '%s' not fully configured", config->name); |
|
|
|
f2b_log_msg(log_error, "backend '%s' not fully configured", config->name); |
|
|
|
|
|
|
|
|
|
|
|
cleanup: |
|
|
|
cleanup: |
|
|
|
if (backend->h) |
|
|
|
if (backend->h) { |
|
|
|
|
|
|
|
if (backend->cfg && backend->destroy) |
|
|
|
|
|
|
|
backend->destroy(backend->cfg); |
|
|
|
dlclose(backend->h); |
|
|
|
dlclose(backend->h); |
|
|
|
|
|
|
|
} |
|
|
|
free(backend); |
|
|
|
free(backend); |
|
|
|
return NULL; |
|
|
|
return NULL; |
|
|
|
} |
|
|
|
} |
|
|
@ -61,6 +76,7 @@ f2b_backend_create(f2b_config_section_t *config) { |
|
|
|
void |
|
|
|
void |
|
|
|
f2b_backend_destroy(f2b_backend_t *backend) { |
|
|
|
f2b_backend_destroy(f2b_backend_t *backend) { |
|
|
|
assert(backend != NULL); |
|
|
|
assert(backend != NULL); |
|
|
|
|
|
|
|
backend->destroy(backend->cfg); |
|
|
|
dlclose(backend->h); |
|
|
|
dlclose(backend->h); |
|
|
|
free(backend); |
|
|
|
free(backend); |
|
|
|
} |
|
|
|
} |
|
|
|