mobley

C Git HTTP server
Log | Files | Refs | Submodules | README | git clone https://git.ne02ptzero.me/git/mobley

commit 3863febb166dce364a599d6d806ff06df7a5b7c4
parent fcd57317dbebcbaecec4df51c8821f3a8a02e580
Author: Louis Solofrizzo <lsolofrizzo@online.net>
Date:   Mon, 17 Dec 2018 18:53:02 +0100

Add basic repository handler, with some custom displays

Signed-off-by: Louis Solofrizzo <lsolofrizzo@online.net>

Diffstat:
MCMakeLists.txt | 1+
Mconfig.c | 2++
Mconfig.yaml | 1+
Mmobley.h | 2++
Arepository_handler.c | 21+++++++++++++++++++++
Arepository_handler.h | 24++++++++++++++++++++++++
Mserver.c | 20++++++++++++++++++++
Mserver.h | 2++
Mstyle/main.css | 7+++++++
Mtemplate.c | 34++++++++++++++++++++--------------
10 files changed, 100 insertions(+), 14 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt @@ -48,6 +48,7 @@ add_executable(${MOBLEY_NAME} main.c template.c config.c repository.c + repository_handler.c ) install(TARGETS ${MOBLEY_NAME} DESTINATION bin) diff --git a/config.c b/config.c @@ -59,6 +59,8 @@ static bool config_read_token(const char *tok, unsigned char *value, mobley_t *c if (strcmp((char *)value, "true") == 0) ctx->conf.sort_repo = true; } + else if (strcmp(tok, "clone_ssh_url") == 0) + COPY_OR_FAIL(ctx->conf.clone_ssh_url, value); else { printf("Unknown token = %s\n", tok); diff --git a/config.yaml b/config.yaml @@ -6,6 +6,7 @@ desc : Software Stuff title : git:// repo_dir : /home/louis/Work/perso/git_local/repositories sort_repo : true +clone_ssh_url : git@git.ne02ptzero.me styles: - main.css diff --git a/mobley.h b/mobley.h @@ -34,6 +34,7 @@ typedef struct { char *root_desc; char *title; bool sort_repo; + char *clone_ssh_url; list_head_t styles; } conf; @@ -54,6 +55,7 @@ static inline void mobley_conf_dtr(mobley_t *ctx) free(ctx->conf.root_desc); free(ctx->conf.title); free(ctx->repos.repo_dir); + free(ctx->conf.clone_ssh_url); string_array_free(&ctx->conf.styles); repository_list_free(&ctx->repos.repos); } diff --git a/repository_handler.c b/repository_handler.c @@ -0,0 +1,21 @@ +/** + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. +*/ + +#include <repository_handler.h> + +bool repository_route_handler(mobley_t *ctx, server_req_t *r) +{ + return true; +} diff --git a/repository_handler.h b/repository_handler.h @@ -0,0 +1,24 @@ +/** + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. +*/ + +#ifndef REPOSITORY_ROUTE_HANDLER_H +# define REPOSITORY_ROUTE_HANDLER_H + +# include <server.h> +# include <mobley.h> + +bool repository_route_handler(mobley_t *ctx, server_req_t *r); + +#endif /* REPOSITORY_ROUTE_HANDLER_H */ diff --git a/server.c b/server.c @@ -20,6 +20,7 @@ #include <static.h> #include <index.h> #include <template.h> +#include <repository_handler.h> typedef struct { const char *name; @@ -39,6 +40,7 @@ static bool server_route_request(server_req_t *r, mobley_t *ctx) { string_array_t *first = list_first_entry(&r->uri, string_array_t, node); bool ret = false; + repository_t *repo; if (first->val == NULL) { @@ -72,6 +74,24 @@ static bool server_route_request(server_req_t *r, mobley_t *ctx) } } + /* Look in the repositories */ + list_for_each_entry(repo, &ctx->repos.repos, node) + { + if (strcmp(first->val, repo->name) == 0) + { + r->repo = repo; + list_del(&first->node); + r->route = first->val; + free(first); + + template_begin(ctx, r); + server_req_set_content_type(r, "text/html; charset=iso-8859-1"); + ret = repository_route_handler(ctx, r); + template_end(ctx, r); + goto end; + } + } + r->res = EVHTP_RES_NOTFOUND; end: return ret; diff --git a/server.h b/server.h @@ -23,12 +23,14 @@ # include <list.h> # include <str.h> +# include <repository.h> typedef struct { evhtp_request_t *req; evhtp_res res; list_head_t uri; char *route; + repository_t *repo; } server_req_t; static inline void server_req_dtr(server_req_t *req) diff --git a/style/main.css b/style/main.css @@ -26,6 +26,7 @@ hr { a { text-decoration: none; color: #b5e853; + outline: 0; } a:hover { @@ -107,3 +108,9 @@ tbody tr:hover td { table thead td { font-weight: bold; } + +.url { + padding: 1px 8px; + color: white; + background: black; +} diff --git a/template.c b/template.c @@ -46,12 +46,14 @@ void template_header(const mobley_t *ctx, server_req_t *r) { html_open("ul") { html_open("li", .class = "logo") { - html_nd("img", - .src = ctx->conf.logo, - .closing_slash = true, - .class = "logo", - .is_static = true - ); + html_open("a", .href = "/") { + html_nd("img", + .src = ctx->conf.logo, + .closing_slash = true, + .class = "logo", + .is_static = true + ); + } html_close("a"); } html_close("li"); if (r->route == NULL) @@ -62,14 +64,14 @@ void template_header(const mobley_t *ctx, server_req_t *r) html("span", ctx->conf.root_desc, .class = "desc"); } html_close("li"); } - else + else if (r->repo != NULL) { - html_open("li") { - html("h3", "test_repo"); - } html_close("li"); - - html_open("li") { - html("span", "repo desc", .class = "repo-desc"); + html_open("li") { + html_open("b") { + html_raw("%s/%s", r->repo->owner, r->repo->name); + } html_close("b"); + html_simple("br"); + html("span", r->repo->desc, .class = "desc"); } html_close("li"); } } html_close("ul"); @@ -127,7 +129,11 @@ static void template_menu(const mobley_t *ctx, server_req_t *r) html_raw("|"); } - /* Clone */ + html_open("li") { + html_open("div", .class = "url") { + html_raw("%s:%s", ctx->conf.clone_ssh_url, r->repo->name); + } html_close("div"); + } html_close("li"); } } html_close("ul"); }