void cgit_print_repo_readme(char *path) { char *filename, *ref; int free_filename = 0; if (ctx.repo->readme.nr == 0) return; filename = ctx.repo->readme.items[0].string; ref = ctx.repo->readme.items[0].util; if (path) { free_filename = 1; filename = append_readme_path(filename, ref, path); if (!filename) return; } /* Print the calculated readme, either from the git repo or from the * filesystem, while applying the about-filter. */ html("<div id='summary'>"); cgit_open_filter(ctx.repo->about_filter, filename); if (ref) cgit_print_file(filename, ref, 1); else html_include(filename); cgit_close_filter(ctx.repo->about_filter); html("</div>"); if (free_filename) free(filename); }
void cgit_print_site_readme(void) { if (!ctx.cfg.root_readme) return; cgit_open_filter(ctx.cfg.about_filter, ctx.cfg.root_readme); html_include(ctx.cfg.root_readme); cgit_close_filter(ctx.cfg.about_filter); }
DLL_EXPORT void html_header(WEBBLK *webblk) { if (webblk->request_type != REQTYPE_POST) hprintf(webblk->sock,"Expires: 0\n"); hprintf(webblk->sock,"Content-type: text/html\n\n"); if (!html_include(webblk,HTML_HEADER)) hprintf(webblk->sock,"<HTML>\n<HEAD>\n<TITLE>Hercules</TITLE>\n</HEAD>\n<BODY>\n\n"); }
void cgit_print_site_readme(void) { cgit_print_layout_start(); if (!ctx.cfg.root_readme) goto done; cgit_open_filter(ctx.cfg.about_filter, ctx.cfg.root_readme); html_include(ctx.cfg.root_readme); cgit_close_filter(ctx.cfg.about_filter); done: cgit_print_layout_end(); }
void cgit_print_repo_readme(char *path) { char *slash, *tmp, *colon, *ref; if (!ctx.repo->readme || !(*ctx.repo->readme)) return; ref = NULL; /* Check if the readme is tracked in the git repo. */ colon = strchr(ctx.repo->readme, ':'); if (colon && strlen(colon) > 1) { *colon = '\0'; ref = ctx.repo->readme; ctx.repo->readme = colon + 1; if (!(*ctx.repo->readme)) return; } /* Prepend repo path to relative readme path unless tracked. */ if (!ref && *ctx.repo->readme != '/') ctx.repo->readme = xstrdup(fmt("%s/%s", ctx.repo->path, ctx.repo->readme)); /* If a subpath is specified for the about page, make it relative * to the directory containing the configured readme. */ if (path) { slash = strrchr(ctx.repo->readme, '/'); if (!slash) { if (!colon) return; slash = colon; } tmp = xmalloc(slash - ctx.repo->readme + 1 + strlen(path) + 1); strncpy(tmp, ctx.repo->readme, slash - ctx.repo->readme + 1); strcpy(tmp + (slash - ctx.repo->readme + 1), path); } else tmp = ctx.repo->readme; /* Print the calculated readme, either from the git repo or from the * filesystem, while applying the about-filter. */ html("<div id='summary'>"); if (ctx.repo->about_filter) cgit_open_filter(ctx.repo->about_filter); if (ref) cgit_print_file(tmp, ref); else html_include(tmp); if (ctx.repo->about_filter) cgit_close_filter(ctx.repo->about_filter); html("</div>"); }
static void send_file(char *path) { struct stat st; if (stat(path, &st)) { switch (errno) { case ENOENT: html_status(404, "Not found", 0); break; case EACCES: html_status(403, "Forbidden", 0); break; default: html_status(400, "Bad request", 0); } return; } ctx.page.mimetype = "application/octet-stream"; ctx.page.filename = path; if (prefixcmp(ctx.repo->path, path)) ctx.page.filename += strlen(ctx.repo->path) + 1; cgit_print_http_headers(); html_include(path); }
void cgit_print_repo_readme(char *path) { char *slash, *tmp; if (!ctx.repo->readme) return; if (path) { slash = strrchr(ctx.repo->readme, '/'); if (!slash) return; tmp = xmalloc(slash - ctx.repo->readme + 1 + strlen(path) + 1); strncpy(tmp, ctx.repo->readme, slash - ctx.repo->readme + 1); strcpy(tmp + (slash - ctx.repo->readme + 1), path); } else tmp = ctx.repo->readme; html("<div id='summary'>"); if (ctx.repo->about_filter) cgit_open_filter(ctx.repo->about_filter); html_include(tmp); if (ctx.repo->about_filter) cgit_close_filter(ctx.repo->about_filter); html("</div>"); }
static void send_file(const char *path) { struct stat st; if (stat(path, &st)) { switch (errno) { case ENOENT: cgit_print_error_page(404, "Not found", "Not found"); break; case EACCES: cgit_print_error_page(403, "Forbidden", "Forbidden"); break; default: cgit_print_error_page(400, "Bad request", "Bad request"); } return; } ctx.page.mimetype = "application/octet-stream"; ctx.page.filename = path; skip_prefix(path, ctx.repo->path, &ctx.page.filename); skip_prefix(ctx.page.filename, "/", &ctx.page.filename); cgit_print_http_headers(); html_include(path); }
void cgit_print_repolist(void) { int i, columns = 3, hits = 0, header = 0; char *last_section = NULL; char *section; int sorted = 0; if (!any_repos_visible()) { cgit_print_error_page(404, "Not found", "No repositories found"); return; } if (ctx.cfg.enable_index_links) ++columns; if (ctx.cfg.enable_index_owner) ++columns; ctx.page.title = ctx.cfg.root_title; cgit_print_http_headers(); cgit_print_docstart(); cgit_print_pageheader(); if (ctx.cfg.index_header) html_include(ctx.cfg.index_header); if (ctx.qry.sort) sorted = sort_repolist(ctx.qry.sort); else if (ctx.cfg.section_sort) sort_repolist("section"); html("<table summary='repository list' class='list nowrap'>"); for (i = 0; i < cgit_repolist.count; i++) { ctx.repo = &cgit_repolist.repos[i]; if (!is_visible(ctx.repo)) continue; hits++; if (hits <= ctx.qry.ofs) continue; if (hits > ctx.qry.ofs + ctx.cfg.max_repo_count) continue; if (!header++) print_header(); section = ctx.repo->section; if (section && !strcmp(section, "")) section = NULL; if (!sorted && ((last_section == NULL && section != NULL) || (last_section != NULL && section == NULL) || (last_section != NULL && section != NULL && strcmp(section, last_section)))) { htmlf("<tr class='nohover'><td colspan='%d' class='reposection'>", columns); html_txt(section); html("</td></tr>"); last_section = section; } htmlf("<tr><td class='%s'>", !sorted && section ? "sublevel-repo" : "toplevel-repo"); cgit_summary_link(ctx.repo->name, ctx.repo->name, NULL, NULL); html("</td><td>"); html_link_open(cgit_repourl(ctx.repo->url), NULL, NULL); html_ntxt(ctx.cfg.max_repodesc_len, ctx.repo->desc); html_link_close(); html("</td><td>"); if (ctx.cfg.enable_index_owner) { if (ctx.repo->owner_filter) { cgit_open_filter(ctx.repo->owner_filter); html_txt(ctx.repo->owner); cgit_close_filter(ctx.repo->owner_filter); } else { html("<a href='"); html_attr(cgit_currenturl()); html("?q="); html_url_arg(ctx.repo->owner); html("'>"); html_txt(ctx.repo->owner); html("</a>"); } html("</td><td>"); } print_modtime(ctx.repo); html("</td>"); if (ctx.cfg.enable_index_links) { html("<td>"); cgit_summary_link("summary", NULL, "button", NULL); cgit_log_link("log", NULL, "button", NULL, NULL, NULL, 0, NULL, NULL, ctx.qry.showmsg, 0); cgit_tree_link("tree", NULL, "button", NULL, NULL, NULL); html("</td>"); } html("</tr>\n"); } html("</table>"); if (hits > ctx.cfg.max_repo_count) print_pager(hits, ctx.cfg.max_repo_count, ctx.qry.search, ctx.qry.sort); cgit_print_docend(); }
DLL_EXPORT void html_footer(WEBBLK *webblk) { if (!html_include(webblk,HTML_FOOTER)) hprintf(webblk->sock,"\n</BODY>\n</HTML>\n"); }
void cgit_print_repolist() { int i, columns = 4, hits = 0, header = 0; char *last_section = NULL; char *section; int sorted = 0; if (ctx.cfg.enable_index_links) columns++; ctx.page.title = ctx.cfg.root_title; cgit_print_http_headers(&ctx); cgit_print_docstart(&ctx); cgit_print_pageheader(&ctx); if (ctx.cfg.index_header) html_include(ctx.cfg.index_header); if(ctx.qry.sort) sorted = sort_repolist(ctx.qry.sort); else if (ctx.cfg.sort_sections) sort_repolist("section"); html("<table summary='repository list' class='list nowrap'>"); for (i=0; i<cgit_repolist.count; i++) { ctx.repo = &cgit_repolist.repos[i]; if (!(is_match(ctx.repo) && is_in_url(ctx.repo))) continue; hits++; if (hits <= ctx.qry.ofs) continue; if (hits > ctx.qry.ofs + ctx.cfg.max_repo_count) continue; if (!header++) print_header(columns); section = ctx.repo->section; if (section && !strcmp(section, "")) section = NULL; if (!sorted && ((last_section == NULL && section != NULL) || (last_section != NULL && section == NULL) || (last_section != NULL && section != NULL && strcmp(section, last_section)))) { htmlf("<tr class='nohover'><td colspan='%d' class='reposection'>", columns); html_txt(section); html("</td></tr>"); last_section = section; } htmlf("<tr><td class='%s'>", !sorted && section ? "sublevel-repo" : "toplevel-repo"); cgit_summary_link(ctx.repo->name, ctx.repo->name, NULL, NULL); html("</td><td>"); html_link_open(cgit_repourl(ctx.repo->url), NULL, NULL); html_ntxt(ctx.cfg.max_repodesc_len, ctx.repo->desc); html_link_close(); html("</td><td>"); html_txt(ctx.repo->owner); html("</td><td>"); print_modtime(ctx.repo); html("</td>"); if (ctx.cfg.enable_index_links) { html("<td>"); cgit_summary_link("summary", NULL, "button", NULL); cgit_log_link("log", NULL, "button", NULL, NULL, NULL, 0, NULL, NULL, ctx.qry.showmsg); cgit_tree_link("tree", NULL, "button", NULL, NULL, NULL); html("</td>"); } html("</tr>\n"); } html("</table>"); if (!hits) cgit_print_error("No repositories found"); else if (hits > ctx.cfg.max_repo_count) print_pager(hits, ctx.cfg.max_repo_count, ctx.qry.search, ctx.qry.sort); cgit_print_docend(); }
void cgit_print_site_readme() { if (ctx.cfg.root_readme) html_include(ctx.cfg.root_readme); }