Skip to content
Extraits de code Groupes Projets
Vérifiée Valider 0739a4ff rédigé par Kubat's avatar Kubat
Parcourir les fichiers

Add a register structure

parent e57b9475
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!92Mod
...@@ -29,6 +29,8 @@ static const char *const lkt_default_config_file = ...@@ -29,6 +29,8 @@ static const char *const lkt_default_config_file =
"\n" "\n"
"; Repo configuration.\n" "; Repo configuration.\n"
"[repo]\n" "[repo]\n"
"path = STATIC ; The repo is a module\n"
"load_function = load_repo_https ; But is compiled statically\n"
"name = Kurisu ; A pretty name\n" "name = Kurisu ; A pretty name\n"
"url = https://kurisu.iiens.net\n" "url = https://kurisu.iiens.net\n"
"json = https://kurisu.iiens.net/api\n" "json = https://kurisu.iiens.net/api\n"
......
...@@ -40,6 +40,9 @@ struct lkt_repo { ...@@ -40,6 +40,9 @@ struct lkt_repo {
struct lkt_state *srv; struct lkt_state *srv;
}; };
/* Load the repo as a module */
int load_repo_https(void *mod, struct lkt_state *srv, void *handle);
/* Create a complete repo */ /* Create a complete repo */
int repo_new(struct lkt_repo *const repo, struct lkt_state *srv); int repo_new(struct lkt_repo *const repo, struct lkt_state *srv);
......
...@@ -67,6 +67,7 @@ core_sources = [ 'src/mkv/write.c' ...@@ -67,6 +67,7 @@ core_sources = [ 'src/mkv/write.c'
, 'src/uri.c' , 'src/uri.c'
, 'src/thread.c' , 'src/thread.c'
, 'src/cmd.c' , 'src/cmd.c'
, 'src/reg.c'
] ]
## Man pages ## Man pages
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <lektor/config.h> #include <lektor/config.h>
#include <lektor/net.h> #include <lektor/net.h>
#include <lektor/cmd.h> #include <lektor/cmd.h>
#include <lektor/reg.h>
#include <lektor/database.h> #include <lektor/database.h>
#include <mthread/mthread.h> #include <mthread/mthread.h>
...@@ -17,6 +18,10 @@ ...@@ -17,6 +18,10 @@
#include <pwd.h> #include <pwd.h>
#include <pthread.h> #include <pthread.h>
REG_BEGIN(server_reg)
REG_ADD(load_repo_https)
REG_END()
static void static void
__sig_exit(int sig) __sig_exit(int sig)
{ {
...@@ -43,6 +48,7 @@ main(int argc, char *argv[]) ...@@ -43,6 +48,7 @@ main(int argc, char *argv[])
normal_launch: normal_launch:
LOG_INFO("Lektor launched by user %s (shell: %s, home: %s)", pw->pw_name, pw->pw_shell, pw->pw_dir); LOG_INFO("Lektor launched by user %s (shell: %s, home: %s)", pw->pw_name, pw->pw_shell, pw->pw_dir);
reg_set(server_reg);
mthread_init(); mthread_init();
pthread_create(&th, NULL, mthread_main, NULL); pthread_create(&th, NULL, mthread_main, NULL);
if (read_self_exe(exe, PATH_MAX)) if (read_self_exe(exe, PATH_MAX))
......
...@@ -87,6 +87,14 @@ repo_new(struct lkt_repo *const repo_, struct lkt_state *srv) ...@@ -87,6 +87,14 @@ repo_new(struct lkt_repo *const repo_, struct lkt_state *srv)
return 0; return 0;
} }
int
load_repo_https(void *mod, struct lkt_state *srv, void *handle)
{
RETURN_UNLESS(mod && handle, "Invalid argument", 1);
struct lkt_repo *repo = mod;
return repo_new(repo, srv);
}
void void
repo_free(struct lkt_repo *const repo) repo_free(struct lkt_repo *const repo)
{ {
......
#define _POSIX_C_SOURCE 200809L
#include <common/common.h>
#include <lektor/reg.h>
#include <dlfcn.h>
#include <stdio.h>
#include <strings.h>
#include <stddef.h>
struct module_reg *reg;
void *
reg_pick(const char *file, void **handle, const char *symbol)
{
if (!symbol)
return NULL;
/* Use dlsym */
if (handle) {
if (!file)
return NULL;
char *error;
*handle = dlopen(file, RTLD_NOW);
if (NULL == *handle) {
LOG_ERROR("libdl error in dlopen on file '%s': %s", file, dlerror());
return NULL;
}
dlerror();
void *sym = dlsym(handle, symbol);
if ((error = dlerror()) != NULL) {
LOG_ERROR("libdl error in dlsym on file '%s': %s\n", file, error);
return NULL;
}
return sym;
}
/* Read the reg */
else {
int i;
for (i = 0; reg[i].name && reg[i].func && !STR_MATCH(reg[i].name, symbol); ++i)
continue;
if (reg[i].func)
return (void *) reg[i].func;
else
return NULL;
}
}
void
reg_set(struct module_reg * _reg)
{
reg = _reg;
}
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter