From: Omar Polo Subject: Re: gotwebd: introducing fcgi_printf To: Mark Jamsek Cc: gameoftrees@openbsd.org, Tracey Emery Date: Mon, 15 Aug 2022 17:09:41 +0200 On 2022/08/15 21:46:38 +1000, Mark Jamsek wrote: > On 22-08-11 05:06PM, Omar Polo wrote: > > On 2022/08/11 16:00:19 +0200, Omar Polo wrote: > > > as suggested by Tracey, I took a bit further my idea of adding a > > > printf-like function in gotwebd. Diff belows drops fcgi_gen_response > > > (used to "print" a string) and replace everything with fcgi_printf. > > > > > > If fcgi_gen_response is preferred as a name I can change it. I went > > > with a different name to make sure to catch and adapt every place > > > where it's called. (i prefer fcgi_printf as name though) > > > > > > I have this running on my instance and it seems to work. I can't > > > visually spot differences in the pages and using the "View Page > > > Source" menu in firefox the html seems correct too. spoiler: i was wrong > > > If I've missed some NULL checks I guess I'll know pretty soon, but > > > after clicking around for a bit I haven't seen any "vprintf %s NULL" > > > in /var/log/messages. I haven't seen any of such logs after a few days of runtime, I'm quite sure I caught them all :) > > > The diff is pretty long to read and maybe even a bit boring, but on > > > the bright side it drops a lot of code (564 +, 1430 -). > > > > there was a typo in gotweb_render_tags > > That was a long diff to read! My eyes were crossing before I was even > halfway :) Thanks for looking at it! > It looks good to me. I haven't run it myself; it builds fine, but > I don't have gotweb setup to test yet (I should do sometime this > week). I have been playing with it on your site though--assuming it's > running with this patch--and that's working great! Yes, I'm running my instance with diff below (now updated.) Feel free to play with it and/or feed it to validators to spot errors in the HTML! (to be precise I'm running with also another small diff applied but doesn't affect the rendering. it should fix a double free, will send the diff later.) > A couple remarks: > > (1) I noticed in the diff lib we use the gcc extension to omit the > middle operand in ternary ifs in quite a few places. I just did > a cursory scan of got and couldn't see it elsewhere _except_ it is > used in gotwebd/got_operations.c. I'm not sure if you or stsp have > a preference either way, but there are a few opportunities for it > in this diff so thought I'd mention it. fwiw i agree with Stefan > (2) See inline comments regarding omitted '\n' from some tags in the > changed -fcgi_gen_response()/+fcgi_printf() lines. I'm pretty > sure it doesn't matter, but I thought I'd ask for the sake of > fidelity; please disregard if intentionally elided. Apart from > that, there might be a couple missing closing div tags that I've > also annotated inline. I think I fixed them all. Newlines aren't important but they make debugging the HTML easier :) > I'll setup gotweb this week and run the patch myself if someone doesn't > ok before then. But I gave the diff a thorough read and it looks fine; > > I particularly like all the '-' lines :) > > [...] > > > @@ -1292,7 +1123,7 @@ render: > > if (error) > > goto done; > > div: > > - fcgi_gen_response(c, "\n"); > > + /* fcgi_printf(c, "\n"); */ Dropped this leftover. That div was indeed extra! > > [...] > missing between div class='commit' and div class='navs_wrapper'? > see below xxx (replying to this but applies to the other "is missing?") I think they were redundant originally. I've checked the generated html with the W3C validator and the HTML is now fine. (the validator complains about some things that i'm planning to address after this goes in, but the HTML is balanced now :-) > > + r = fcgi_printf(c, "\n"); > > + fcgi_printf(c, "\n"); /* #tree */ > > + fcgi_printf(c, "\n"); /* #tre_content */ > > #tree_content thanks for spotting the typo! > > [...] > > - fcgi_gen_response(c, "\n"); > > + fcgi_printf(c, "\n"); /* #diff */ > > + fcgi_printf(c, "\n"); /* #diff_content */ > > ^^^^^^^^ second tag was after done: I decided not to care about this (and the other places where I moved the before the done label.) It's too difficult and it's just not worth it to try to keep the HTML balance when errors occurs, and these after the done label didn't help with that anyway. > > done: > > - fcgi_gen_response(c, "\n"); > > ^^^^^^^^ here > > > free(age); > > free(author); > > return error; ----------------------------------------------- commit ac899ae0f5cf700be62f3caf7d7a9b6544d2bf3a from: Omar Polo date: Mon Aug 15 14:39:05 2022 UTC gotwebd: add fcgi_printf diff 6dd6b25bb156f2610bd9d59c89bb355c9b178718 ac899ae0f5cf700be62f3caf7d7a9b6544d2bf3a commit - 6dd6b25bb156f2610bd9d59c89bb355c9b178718 commit + ac899ae0f5cf700be62f3caf7d7a9b6544d2bf3a blob - f6cb81448f5778d7872b537fd6b90838285c99ee blob + ae872cfb0d22ad79db91ef2e1032bae6db071f17 --- gotwebd/fcgi.c +++ gotwebd/fcgi.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -308,6 +309,27 @@ fcgi_timeout(int fd, short events, void *arg) } int +fcgi_printf(struct request *c, const char *fmt, ...) +{ + va_list ap; + char *str; + int r; + + va_start(ap, fmt); + r = vasprintf(&str, fmt, ap); + va_end(ap); + + if (r == -1) { + log_warn("%s: asprintf", __func__); + return -1; + } + + r = fcgi_gen_binary_response(c, str, r); + free(str); + return r; +} + +int fcgi_gen_binary_response(struct request *c, const uint8_t *data, int len) { int r; @@ -346,14 +368,6 @@ fcgi_gen_binary_response(struct request *c, const uint return 0; } -int -fcgi_gen_response(struct request *c, const char *data) -{ - if (data == NULL || *data == '\0') - return 0; - return fcgi_gen_binary_response(c, data, strlen(data)); -} - static int send_response(struct request *c, int type, const uint8_t *data, size_t len) blob - 1c274b225d0e710d16528c4b9970348bb3bec74e blob + c0128e61de47bce0c95159c89f49edb94b403449 --- gotwebd/got_operations.c +++ gotwebd/got_operations.c @@ -829,10 +829,10 @@ got_output_repo_tree(struct request *c) struct got_reflist_head refs; struct got_tree_object *tree = NULL; struct repo_dir *repo_dir = t->repo_dir; + const char *name, *index_page_str, *folder; char *id_str = NULL; - char *path = NULL, *in_repo_path = NULL, *build_folder = NULL; - char *modestr = NULL, *name = NULL; - int nentries, i; + char *path = NULL, *in_repo_path = NULL, *modestr = NULL; + int nentries, i, r; TAILQ_INIT(&refs); @@ -871,6 +871,9 @@ got_output_repo_tree(struct request *c) nentries = got_object_tree_get_nentries(tree); + index_page_str = qs->index_page_str ? qs->index_page_str : ""; + folder = qs->folder ? qs->folder : ""; + for (i = 0; i < nentries; i++) { struct got_tree_entry *te; mode_t mode; @@ -917,226 +920,55 @@ got_output_repo_tree(struct request *c) } } - name = strdup(got_tree_entry_get_name(te)); - if (name == NULL) { - error = got_error_from_errno("strdup"); - goto done; - } if (S_ISDIR(mode)) { - if (asprintf(&build_folder, "%s/%s", - qs->folder ? qs->folder : "", - got_tree_entry_get_name(te)) == -1) { - error = got_error_from_errno("asprintf"); + name = got_tree_entry_get_name(te); + r = fcgi_printf(c, + "
\n" + "\n" /* .tree_line */ + "
 
\n" + "
\n", /* .tree_wrapper */ + index_page_str, qs->path, rc->commit_id, + folder, name, name, modestr); + if (r == -1) goto done; - } - - if (fcgi_gen_response(c, - "
\n") == -1) - goto done; - - if (fcgi_gen_response(c, "\n") == -1) - goto done; - - if (fcgi_gen_response(c, "
") == -1) - goto done; - if (fcgi_gen_response(c, " ") == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - } else { - free(name); - name = strdup(got_tree_entry_get_name(te)); - if (name == NULL) { - error = got_error_from_errno("strdup"); + name = got_tree_entry_get_name(te); + r = fcgi_printf(c, + "
\n" + "
" + "%s%s" + "
\n" /* .tree_line */ + "
" + "commits\n" + " | \n" + "blame\n" + "
\n" /* .tree_line_blank */ + "
\n", /* .tree_wrapper */ + index_page_str, qs->path, rc->commit_id, + folder, name, name, modestr, + index_page_str, qs->path, rc->commit_id, + folder, name, + index_page_str, qs->path, rc->commit_id, + folder, name); + if (r == -1) goto done; - } - - if (fcgi_gen_response(c, - "
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
") == -1) - goto done; - - if (fcgi_gen_response(c, - "") == -1) - goto done; - if (fcgi_gen_response(c, name) == -1) - goto done; - if (fcgi_gen_response(c, modestr) == -1) - goto done; - - if (fcgi_gen_response(c, "") == -1) - goto done; - - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - - if (fcgi_gen_response(c, "
") == -1) - goto done; - - if (fcgi_gen_response(c, - "") == -1) - goto done; - - if (fcgi_gen_response(c, "commits") == -1) - goto done; - if (fcgi_gen_response(c, "\n") == -1) - goto done; - - if (fcgi_gen_response(c, " | \n") == -1) - goto done; - - if (fcgi_gen_response(c, - "") == -1) - goto done; - - if (fcgi_gen_response(c, "blame") == -1) - goto done; - if (fcgi_gen_response(c, "\n") == -1) - goto done; - - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; } free(id_str); id_str = NULL; - free(build_folder); - build_folder = NULL; - free(name); - name = NULL; free(modestr); modestr = NULL; } done: free(id_str); - free(build_folder); free(modestr); free(path); - free(name); got_ref_list_free(&refs); if (commit) got_object_commit_close(commit); @@ -1286,11 +1118,13 @@ got_gotweb_blame_cb(void *arg, int nlines, int lineno, struct transport *t = c->t; struct querystring *qs = t->qs; struct repo_dir *repo_dir = t->repo_dir; + const char *index_page_str; char *line = NULL, *eline = NULL; size_t linesize = 0; off_t offset; struct tm tm; time_t committer_time; + int r; if (nlines != a->nlines || (lineno != -1 && lineno < 1) || lineno > a->nlines) @@ -1334,10 +1168,10 @@ got_gotweb_blame_cb(void *arg, int nlines, int lineno, goto done; } + index_page_str = qs->index_page_str ? qs->index_page_str : ""; + while (bline->annotated) { - int out_buff_size = 100; char *smallerthan, *at, *nl, *committer; - char out_buff[out_buff_size]; size_t len; if (getline(&line, &linesize, a->f) == -1) { @@ -1361,68 +1195,29 @@ got_gotweb_blame_cb(void *arg, int nlines, int lineno, if (nl) *nl = '\0'; - if (fcgi_gen_response(c, "
") == -1) - goto done; - if (fcgi_gen_response(c, "
") == -1) - goto done; - if (snprintf(out_buff, strlen(out_buff), "%.*d", a->nlines_prec, - a->lineno_cur) < 0) - goto done; - if (fcgi_gen_response(c, out_buff) == -1) - goto done; - if (fcgi_gen_response(c, "
") == -1) - goto done; - - if (fcgi_gen_response(c, "") == -1) - goto done; - - if (fcgi_gen_response(c, "
") == -1) - goto done; - if (fcgi_gen_response(c, bline->datebuf) == -1) - goto done; - if (fcgi_gen_response(c, "
") == -1) - goto done; - - if (fcgi_gen_response(c, "
") == -1) - goto done; - if (fcgi_gen_response(c, committer) == -1) - goto done; - if (fcgi_gen_response(c, "
") == -1) - goto done; - - if (fcgi_gen_response(c, "
") == -1) - goto done; err = gotweb_escape_html(&eline, line); if (err) goto done; - if (fcgi_gen_response(c, eline) == -1) - goto done; - if (fcgi_gen_response(c, "
") == -1) - goto done; - if (fcgi_gen_response(c, "
") == -1) + r = fcgi_printf(c, "
" + "
%.*d
" + "
" + "" + "%.8s" + "
" + "
%s
" + "
%s
" + "
%s
" + "
", /* .blame_wrapper */ + a->nlines_prec, a->lineno_cur, + index_page_str, repo_dir->name, bline->id_str, + bline->id_str, + bline->datebuf, + committer, + eline); + if (r == -1) goto done; + a->lineno_cur++; bline = &a->lines[a->lineno_cur - 1]; } @@ -1767,12 +1562,7 @@ got_output_repo_diff(struct request *c) goto done; } } - if (fcgi_gen_response(c, "
") == -1) - goto done; + newline = strchr(line, '\n'); if (newline) *newline = '\0'; @@ -1780,13 +1570,12 @@ got_output_repo_diff(struct request *c) error = gotweb_escape_html(&eline, line); if (error) goto done; - if (fcgi_gen_response(c, eline) == -1) - goto done; + + fcgi_printf(c, "
%s
\n", + color ? color : "", eline); free(eline); eline = NULL; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; if (linelen > 0) wrlen = wrlen + linelen; free(color); blob - 4b3729bd8c2a9dba3031daeca4b3fea398ba2f7f blob + f332e5d6085b45092bae5d9094c76128da56fc32 --- gotwebd/gotweb.c +++ gotwebd/gotweb.c @@ -118,7 +118,7 @@ gotweb_process_request(struct request *c) struct querystring *qs = NULL; struct repo_dir *repo_dir = NULL; uint8_t err[] = "gotwebd experienced an error: "; - int html = 0; + int r, html = 0; /* init the transport */ error = gotweb_init_transport(&c->t); @@ -270,29 +270,27 @@ render: break; case ERR: default: - if (fcgi_gen_response(c, "
") == -1) + r = fcgi_printf(c, "
%s
\n", + "Erorr: Bad Querystring"); + if (r == -1) goto err; - if (fcgi_gen_response(c, "Error: Bad Querystring\n") == -1) - goto err; - if (fcgi_gen_response(c, "
\n") == -1) - goto err; break; } goto done; err: - if (html && fcgi_gen_response(c, "
") == -1) + if (html && fcgi_printf(c, "
") == -1) return; - if (fcgi_gen_response(c, err) == -1) + if (fcgi_printf(c, "%s", err) == -1) return; if (error) { - if (fcgi_gen_response(c, (uint8_t *)error->msg) == -1) + if (fcgi_printf(c, "%s", error->msg) == -1) return; } else { - if (fcgi_gen_response(c, "see daemon logs for details") == -1) + if (fcgi_printf(c, "see daemon logs for details") == -1) return; } - if (html && fcgi_gen_response(c, "
\n") == -1) + if (html && fcgi_printf(c, "
\n") == -1) return; done: if (c->t->repo != NULL && qs->action != INDEX) @@ -628,205 +626,124 @@ gotweb_free_transport(struct transport *t) const struct got_error * gotweb_render_content_type(struct request *c, const uint8_t *type) { - const struct got_error *error = NULL; - char *h = NULL; - - if (asprintf(&h, "Content-type: %s\r\n\r\n", type) == -1) { - error = got_error_from_errno2("%s: asprintf", __func__); - goto done; - } - - fcgi_gen_response(c, h); -done: - free(h); - - return error; + fcgi_printf(c, "Content-Type: %s\r\n\r\n", type); + return NULL; } const struct got_error * gotweb_render_content_type_file(struct request *c, const uint8_t *type, char *file) { - const struct got_error *error = NULL; - char *h = NULL; - - if (asprintf(&h, "Content-type: %s\r\n" + fcgi_printf(c, "Content-type: %s\r\n" "Content-disposition: attachment; filename=%s\r\n\r\n", - type, file) == -1) { - error = got_error_from_errno2("%s: asprintf", __func__); - goto done; - } - - fcgi_gen_response(c, h); -done: - free(h); - - return error; + type, file); + return NULL; } static const struct got_error * gotweb_render_header(struct request *c) { - const struct got_error *error = NULL; struct server *srv = c->srv; struct querystring *qs = c->t->qs; - char *title = NULL, *droot = NULL, *css = NULL, *gotlink = NULL; - char *gotimg = NULL, *sitelink = NULL, *summlink = NULL; + char droot[PATH_MAX]; + int r; if (strlen(c->document_root) > 0) { - if (asprintf(&droot, "/%s/", c->document_root) == -1) { - error = got_error_from_errno2("%s: asprintf", __func__); - goto done; - } - } else { - if (asprintf(&droot, "/") == -1) { - error = got_error_from_errno2("%s: asprintf", __func__); - goto done; - } - } + r = snprintf(droot, sizeof(droot), "/%s/", c->document_root); + if (r < 0 || (size_t)r >= sizeof(droot)) + return got_error(GOT_ERR_NO_SPACE); + } else + strlcpy(droot, "/", sizeof(droot)); - if (asprintf(&title, "%s\n", srv->site_name) == -1) { - error = got_error_from_errno2("%s: asprintf", __func__); + r = fcgi_printf(c, "\n" + "\n" + "\n" + "%s\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "
\n" + "\n" /* #header */ + "
\n" + "\n" /* #content */ + "
\n" /* #gw_body */ + "\n\n", siteowner); + + free(escaped_owner); + return NULL; } static const struct got_error * @@ -864,12 +780,11 @@ gotweb_render_navs(struct request *c) struct querystring *qs = t->qs; struct server *srv = c->srv; char *nhref = NULL, *phref = NULL; - int disp = 0; + int r, disp = 0; - if (fcgi_gen_response(c, "
\n") == -1) + r = fcgi_printf(c, "
\n\n" /* #nav_prev */ + "\n"); /* #nav_next */ + fcgi_printf(c, "
\n"); /* #np_wrapper */ done: free(t->next_id); t->next_id = NULL; @@ -1035,10 +945,14 @@ gotweb_render_index(struct request *c) struct repo_dir *repo_dir = NULL; DIR *d; struct dirent **sd_dent; + const char *index_page_str; char *c_path = NULL; struct stat st; unsigned int d_cnt, d_i, d_disp = 0; + int r; + index_page_str = qs->index_page_str ? qs->index_page_str : ""; + d = opendir(srv->repos_path); if (d == NULL) { error = got_error_from_errno2("opendir", srv->repos_path); @@ -1070,24 +984,24 @@ gotweb_render_index(struct request *c) c_path = NULL; } - if (fcgi_gen_response(c, "
\n") == -1) + r = fcgi_printf(c, "
\n" + "
Project
\n"); + if (r == -1) goto done; - if (fcgi_gen_response(c, - "
Project
\n") == -1) - goto done; + if (srv->show_repo_description) - if (fcgi_gen_response(c, "
" + if (fcgi_printf(c, "
" "Description
\n") == -1) goto done; if (srv->show_repo_owner) - if (fcgi_gen_response(c, "
" + if (fcgi_printf(c, "
" "Owner
\n") == -1) goto done; if (srv->show_repo_age) - if (fcgi_gen_response(c, "
" + if (fcgi_printf(c, "
" "Last Change
\n") == -1) goto done; - if (fcgi_gen_response(c, "
\n") == -1) + if (fcgi_printf(c, "
\n") == -1) /* #index_header */ goto done; for (d_i = 0; d_i < d_cnt; d_i++) { @@ -1128,149 +1042,69 @@ gotweb_render_index(struct request *c) render: d_disp++; t->prev_disp++; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
") == -1) - goto done; - if (fcgi_gen_response(c, "\n" + "", /* .index_project */ + index_page_str, repo_dir->name, + repo_dir->name); + if (r == -1) goto done; - if (fcgi_gen_response(c, qs->index_page_str) == -1) - goto done; - if (fcgi_gen_response(c, "&path=") == -1) - goto done; - if (fcgi_gen_response(c, repo_dir->name) == -1) - goto done; - if (fcgi_gen_response(c, "&action=summary'>") == -1) - goto done; - if (fcgi_gen_response(c, repo_dir->name) == -1) - goto done; - if (fcgi_gen_response(c, "") == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - if (srv->show_repo_description) { - if (fcgi_gen_response(c, - "
\n") == -1) + r = fcgi_printf(c, + "
\n" + "%s
\n", repo_dir->description); + if (r == -1) goto done; - if (fcgi_gen_response(c, repo_dir->description) == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; } if (srv->show_repo_owner) { - if (fcgi_gen_response(c, - "
") == -1) + r = fcgi_printf(c, "
" + "%s
\n", repo_dir->owner); + if (r == -1) goto done; - if (fcgi_gen_response(c, repo_dir->owner) == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; } if (srv->show_repo_age) { - if (fcgi_gen_response(c, - "
") == -1) + r = fcgi_printf(c, "
" + "%s
\n", repo_dir->age); + if (r == -1) goto done; - if (fcgi_gen_response(c, repo_dir->age) == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; } - if (fcgi_gen_response(c, "\n", /* .index_wrapper */ + index_page_str, repo_dir->name, + index_page_str, repo_dir->name, + index_page_str, repo_dir->name, + index_page_str, repo_dir->name, + index_page_str, repo_dir->name); + if (r == -1) goto done; - if (fcgi_gen_response(c, "") == -1) - goto done; - if (fcgi_gen_response(c, - "
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - gotweb_free_repo_dir(repo_dir); repo_dir = NULL; error = got_repo_close(t->repo); @@ -1281,18 +1115,16 @@ render: break; } if (srv->max_repos_display == 0) - goto div; + goto done; if (srv->max_repos > 0 && srv->max_repos < srv->max_repos_display) - goto div; + goto done; if (t->repos_total <= srv->max_repos || t->repos_total <= srv->max_repos_display) - goto div; + goto done; error = gotweb_render_navs(c); if (error) goto done; -div: - fcgi_gen_response(c, "
\n"); done: if (d != NULL && closedir(d) == EOF && error == NULL) error = got_error_from_errno("closedir"); @@ -1306,6 +1138,7 @@ gotweb_render_blame(struct request *c) struct transport *t = c->t; struct repo_commit *rc = NULL; char *age = NULL; + int r; error = got_get_repo_commits(c, 1); if (error) @@ -1317,58 +1150,32 @@ gotweb_render_blame(struct request *c) if (error) goto done; - if (fcgi_gen_response(c, "
\n") == -1) + r = fcgi_printf(c, "
\n" + "
Blame
\n" + "
\n" /* #blame_title_wrapper */ + "
\n" + "
\n" + "
\n" + "
Date:
\n" + "
%s
\n" + "
Message:
\n" + "
%s
\n" + "
\n" /* #blame_header */ + "
\n" /* #blame_header_wrapper */ + "
\n" + "
\n", + age ? age : "", + rc->commit_msg); + if (r == -1) goto done; - if (fcgi_gen_response(c, "
Blame
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - - if (fcgi_gen_response(c, "
Date:" - "
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
") == -1) - goto done; - if (fcgi_gen_response(c, age ? age : "") == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - - if (fcgi_gen_response(c, "
Message:" - "
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
") == -1) - goto done; - if (fcgi_gen_response(c, rc->commit_msg) == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - error = got_output_file_blame(c); if (error) goto done; - fcgi_gen_response(c, "
\n"); + fcgi_printf(c, "
\n" /* #blame */ + "
\n"); /* #blame_content */ done: - fcgi_gen_response(c, "
\n"); return error; } @@ -1381,18 +1188,18 @@ gotweb_render_briefs(struct request *c) struct transport *t = c->t; struct querystring *qs = t->qs; struct repo_dir *repo_dir = t->repo_dir; + const char *index_page_str; char *smallerthan, *newline; char *age = NULL; + int r; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - if (fcgi_gen_response(c, - "
Commit Briefs
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; + index_page_str = qs->index_page_str ? qs->index_page_str : ""; - if (fcgi_gen_response(c, "
\n") == -1) + r = fcgi_printf(c, "
\n" + "
Commit Briefs
\n" + "
\n" /* #briefs_title_wrapper */ + "
\n"); + if (r == -1) goto done; if (qs->action == SUMMARY) { @@ -1407,123 +1214,52 @@ gotweb_render_briefs(struct request *c) error = gotweb_get_time_str(&age, rc->committer_time, TM_DIFF); if (error) goto done; - if (fcgi_gen_response(c, "
") == -1) - goto done; - if (fcgi_gen_response(c, age ? age : "") == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
") == -1) - goto done; smallerthan = strchr(rc->author, '<'); if (smallerthan) *smallerthan = '\0'; - if (fcgi_gen_response(c, rc->author) == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
") == -1) - goto done; newline = strchr(rc->commit_msg, '\n'); if (newline) *newline = '\0'; - if (fcgi_gen_response(c, "%s
\n" + "
%s
\n" + "
" + "%s", + age ? age : "", + rc->author, + index_page_str, repo_dir->name, rc->commit_id, qs->headref, + rc->commit_msg); + if (r == -1) goto done; - if (fcgi_gen_response(c, qs->index_page_str) == -1) - goto done; - if (fcgi_gen_response(c, "&path=") == -1) - goto done; - if (fcgi_gen_response(c, repo_dir->name) == -1) - goto done; - if (fcgi_gen_response(c, "&action=diff&commit=") == -1) - goto done; - if (fcgi_gen_response(c, rc->commit_id) == -1) - goto done; - if (fcgi_gen_response(c, "&headref=") == -1) - goto done; - if (fcgi_gen_response(c, qs->headref) == -1) - goto done; - if (fcgi_gen_response(c, "'>") == -1) - goto done; - if (fcgi_gen_response(c, rc->commit_msg) == -1) - goto done; - if (fcgi_gen_response(c, "") == -1) - goto done; + if (rc->refs_str) { - if (fcgi_gen_response(c, - " (") == -1) + r = fcgi_printf(c, + " (%s)", + rc->refs_str); + if (r == -1) goto done; - if (fcgi_gen_response(c, rc->refs_str) == -1) - goto done; - if (fcgi_gen_response(c, ")") == -1) - goto done; } - if (fcgi_gen_response(c, "
\n") == -1) + if (fcgi_printf(c, "
\n") == -1) /* .briefs_log */ goto done; - if (fcgi_gen_response(c, "\n") == -1) - goto done; - if (fcgi_gen_response(c, - "
\n") == -1) - goto done; - free(age); age = NULL; } @@ -1533,7 +1269,7 @@ gotweb_render_briefs(struct request *c) if (error) goto done; } - fcgi_gen_response(c, "
\n"); + fcgi_printf(c, "
\n"); /* #briefs_content */ done: free(age); return error; @@ -1548,18 +1284,17 @@ gotweb_render_commits(struct request *c) struct transport *t = c->t; struct querystring *qs = t->qs; struct repo_dir *repo_dir = t->repo_dir; + const char *index_page_str; char *age = NULL, *author = NULL; - /* int commit_found = 0; */ + int r; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - if (fcgi_gen_response(c, - "
Commits
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; + index_page_str = qs->index_page_str ? qs->index_page_str : ""; - if (fcgi_gen_response(c, "
\n") == -1) + r = fcgi_printf(c, "
\n" + "
Commits
\n" + "
\n" /* .commits_title_wrapper */ + "
\n"); + if (r == -1) goto done; error = got_get_repo_commits(c, srv->max_commits_display); @@ -1574,113 +1309,38 @@ gotweb_render_commits(struct request *c) if (error) goto done; - if (fcgi_gen_response(c, - "
\n") == -1) + r = fcgi_printf(c, "
\n" + "
\n" + "
Commit:
\n" + "
%s
\n" + "
Author:
\n" + "
%s
\n" + "
Date:
\n" + "
%s
\n" + "
\n" /* .commits_header */ + "
\n" /* .commits_header_wrapper */ + "
\n" + "
\n%s
\n", + rc->commit_id, + author ? author : "", + age ? age : "", + rc->commit_msg); + if (r == -1) goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; + r = fcgi_printf(c, "\n" /* .navs_wrapper */ + "
\n", + index_page_str, repo_dir->name, rc->commit_id, + index_page_str, repo_dir->name, rc->commit_id); - if (fcgi_gen_response(c, "
Commit:" - "
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
") == -1) - goto done; - if (fcgi_gen_response(c, rc->commit_id) == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - - if (fcgi_gen_response(c, "
Author:" - "
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
") == -1) - goto done; - if (fcgi_gen_response(c, author ? author : "") == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - - if (fcgi_gen_response(c, "
Date:" - "
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
") == -1) - goto done; - if (fcgi_gen_response(c, age ? age : "") == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - - if (fcgi_gen_response(c, - "
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - - if (fcgi_gen_response(c, rc->commit_msg) == -1) - goto done; - - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - - if (fcgi_gen_response(c, "\n") == -1) - goto done; - if (fcgi_gen_response(c, - "
\n") == -1) - goto done; free(age); age = NULL; free(author); @@ -1692,8 +1352,7 @@ gotweb_render_commits(struct request *c) if (error) goto done; } - if (fcgi_gen_response(c, "
\n") == -1) - goto done; + fcgi_printf(c, "
\n"); /* .commits_content */ done: free(age); return error; @@ -1708,8 +1367,12 @@ gotweb_render_branches(struct request *c) struct transport *t = c->t; struct querystring *qs = t->qs; struct got_repository *repo = t->repo; + const char *index_page_str; char *age = NULL; + int r; + index_page_str = qs->index_page_str ? qs->index_page_str : ""; + TAILQ_INIT(&refs); error = got_ref_list(&refs, repo, "refs/heads", @@ -1717,17 +1380,13 @@ gotweb_render_branches(struct request *c) if (error) goto done; - if (fcgi_gen_response(c, "
\n") == -1) + r = fcgi_printf(c, "
\n" + "
Branches
\n" + "
\n" /* #branches_title_wrapper */ + "
\n"); + if (r == -1) goto done; - if (fcgi_gen_response(c, - "
Branches
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - TAILQ_FOREACH(re, &refs, entry) { char *refname = NULL; @@ -1750,132 +1409,41 @@ gotweb_render_branches(struct request *c) if (strncmp(refname, "refs/heads/", 11) == 0) refname += 11; - if (fcgi_gen_response(c, "
") == -1) + r = fcgi_printf(c, "
\n" + "
%s
\n" + "
 
\n" + "
" + "" + "%s" + "
\n" /* .branch */ + "\n" /* .navs_wrapper */ + "
\n" + "
\n", /* .branches_wrapper */ + age ? age : "", + index_page_str, qs->path, refname, + refname, + index_page_str, qs->path, refname, + index_page_str, qs->path, refname, + index_page_str, qs->path, refname); + if (r == -1) goto done; - if (fcgi_gen_response(c, "
") == -1) - goto done; - if (fcgi_gen_response(c, age ? age : "") == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - - if (fcgi_gen_response(c, "
") == -1) - goto done; - if (fcgi_gen_response(c, " ") == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - - if (fcgi_gen_response(c, "
") == -1) - goto done; - if (fcgi_gen_response(c, "") == -1) - goto done; - if (fcgi_gen_response(c, refname) == -1) - goto done; - if (fcgi_gen_response(c, "") == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - - if (fcgi_gen_response(c, "\n") == -1) - goto done; - - if (fcgi_gen_response(c, - "
\n") == -1) - goto done; - - /* branches_wrapper */ - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - free(age); age = NULL; } - fcgi_gen_response(c, "
\n"); + fcgi_printf(c, "
\n"); /* #branches_content */ done: return error; } @@ -1887,6 +1455,7 @@ gotweb_render_tree(struct request *c) struct transport *t = c->t; struct repo_commit *rc = NULL; char *age = NULL; + int r; error = got_get_repo_commits(c, 1); if (error) @@ -1898,67 +1467,34 @@ gotweb_render_tree(struct request *c) if (error) goto done; - if (fcgi_gen_response(c, "
\n") == -1) + r = fcgi_printf(c, "
\n" + "
Tree
\n" + "
\n" /* #tree_title_wrapper */ + "
\n" + "
\n" + "
\n" + "
Tree:
\n" + "
%s
\n" + "
Date:
\n" + "
%s
\n" + "
Message:
\n" + "
%s
\n" + "
\n" /* #tree_header */ + "
\n" /* #tree_header_wrapper */ + "
\n" + "
\n", + rc->tree_id, + age ? age : "", + rc->commit_msg); + if (r == -1) goto done; - if (fcgi_gen_response(c, "
Tree
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - - if (fcgi_gen_response(c, "
Tree:" - "
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
") == -1) - goto done; - if (fcgi_gen_response(c, rc->tree_id) == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - - if (fcgi_gen_response(c, "
Date:" - "
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
") == -1) - goto done; - if (fcgi_gen_response(c, age ? age : "") == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - - if (fcgi_gen_response(c, "
Message:" - "
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
") == -1) - goto done; - if (fcgi_gen_response(c, rc->commit_msg) == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - error = got_output_repo_tree(c); if (error) goto done; - fcgi_gen_response(c, "
\n"); - fcgi_gen_response(c, "
\n"); + fcgi_printf(c, "
\n"); /* #tree */ + fcgi_printf(c, "
\n"); /* #tree_content */ done: return error; } @@ -1970,6 +1506,7 @@ gotweb_render_diff(struct request *c) struct transport *t = c->t; struct repo_commit *rc = NULL; char *age = NULL, *author = NULL; + int r; error = got_get_repo_commits(c, 1); if (error) @@ -1984,101 +1521,44 @@ gotweb_render_diff(struct request *c) if (error) goto done; - if (fcgi_gen_response(c, "
\n") == -1) + r = fcgi_printf(c, "
\n" + "
Commit Diff
\n" + "
\n" /* #diff_title_wrapper */ + "
\n" + "
\n" + "
\n" + "
Diff:
\n" + "
%s
%s
\n" + "
Commit:
\n" + "
%s
\n" + "
Tree:
\n" + "
%s
\n" + "
Author:
\n" + "
%s
\n" + "
Date:
\n" + "
%s
\n" + "
Message:
\n" + "
%s
\n" + "
\n" /* #diff_header */ + "
\n" /* #diff_header_wrapper */ + "
\n" + "
\n", + rc->parent_id, rc->commit_id, + rc->commit_id, + rc->tree_id, + author ? author : "", + age ? age : "", + rc->commit_msg); + if (r == -1) goto done; - if (fcgi_gen_response(c, - "
Commit Diff
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - - if (fcgi_gen_response(c, "
Diff:" - "
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
") == -1) - goto done; - if (fcgi_gen_response(c, rc->parent_id) == -1) - goto done; - if (fcgi_gen_response(c, "
") == -1) - goto done; - if (fcgi_gen_response(c, rc->commit_id) == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - - if (fcgi_gen_response(c, "
Commit:" - "
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
") == -1) - goto done; - if (fcgi_gen_response(c, rc->commit_id) == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - - if (fcgi_gen_response(c, "
Tree:" - "
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
") == -1) - goto done; - if (fcgi_gen_response(c, rc->tree_id) == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - - if (fcgi_gen_response(c, "
Author:" - "
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
") == -1) - goto done; - if (fcgi_gen_response(c, author ? author : "") == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - - if (fcgi_gen_response(c, "
Date:" - "
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
") == -1) - goto done; - if (fcgi_gen_response(c, age ? age : "") == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - - if (fcgi_gen_response(c, "
Message:" - "
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
") == -1) - goto done; - if (fcgi_gen_response(c, rc->commit_msg) == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - error = got_output_repo_diff(c); if (error) goto done; - fcgi_gen_response(c, "
\n"); + fcgi_printf(c, "
\n"); /* #diff */ + fcgi_printf(c, "
\n"); /* #diff_content */ done: - fcgi_gen_response(c, "
\n"); free(age); free(author); return error; @@ -2090,66 +1570,50 @@ gotweb_render_summary(struct request *c) const struct got_error *error = NULL; struct transport *t = c->t; struct server *srv = c->srv; + int r; - if (fcgi_gen_response(c, "
\n") == -1) + if (fcgi_printf(c, "
\n") == -1) goto done; - if (!srv->show_repo_description) - goto owner; + if (srv->show_repo_description) { + r = fcgi_printf(c, + "
Description:
\n" + "
%s
\n", + t->repo_dir->description); + if (r == -1) + goto done; + } - if (fcgi_gen_response(c, "
" - "Description:
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
") == -1) - goto done; - if (fcgi_gen_response(c, t->repo_dir->description) == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; -owner: - if (!srv->show_repo_owner) - goto last_change; + if (srv->show_repo_owner) { + r = fcgi_printf(c, + "
Owner:
\n" + "
%s
\n", + t->repo_dir->owner); + if (r == -1) + goto done; + } - if (fcgi_gen_response(c, "
" - "Owner:
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
") == -1) - goto done; - if (fcgi_gen_response(c, t->repo_dir->owner) == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; -last_change: - if (!srv->show_repo_age) - goto clone_url; + if (srv->show_repo_age) { + r = fcgi_printf(c, + "
Last Change:
\n" + "
%s
\n", + t->repo_dir->age); + if (r == -1) + goto done; + } - if (fcgi_gen_response(c, "
" - "Last Change:
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
") == -1) - goto done; - if (fcgi_gen_response(c, t->repo_dir->age) == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; -clone_url: - if (!srv->show_repo_cloneurl) - goto content; + if (srv->show_repo_cloneurl) { + r = fcgi_printf(c, + "
Clone URL:
\n" + "
%s
\n", + t->repo_dir->url ? t->repo_dir->url : ""); + if (r == -1) + goto done; + } - if (fcgi_gen_response(c, "
" - "Clone URL:
\n") == -1) + r = fcgi_printf(c, "
\n"); /* #summary_wrapper */ + if (r == -1) goto done; - if (fcgi_gen_response(c, "
") == -1) - goto done; - if (fcgi_gen_response(c, t->repo_dir->url) == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; -content: - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; error = gotweb_render_briefs(c); if (error) { @@ -2197,84 +1661,35 @@ gotweb_render_tag(struct request *c) if (error) goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
Tag
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - - if (fcgi_gen_response(c, "
Commit:" - "
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
") == -1) - goto done; - if (fcgi_gen_response(c, rt->commit_id) == -1) - goto done; - if (strncmp(rt->tag_name, "refs/", 5) == 0) rt->tag_name += 5; - if (fcgi_gen_response(c, " (") == -1) - goto done; - if (fcgi_gen_response(c, rt->tag_name) == -1) - goto done; - if (fcgi_gen_response(c, ")") == -1) - goto done; + fcgi_printf(c, "
\n" + "
Tag
\n" + "
\n" /* #tags_title_wrapper */ + "
\n" + "
\n" + "
\n" + "
Commit:
\n" + "
%s" + " (%s)
\n" + "
Tagger:
\n" + "
%s
\n" + "
Date:
\n" + "
%s
\n" + "
Message:
\n" + "
%s
\n" + "
\n" /* #tag_header */ + "
\n" + "
\n%s
" + "
", /* tag_header_wrapper */ + rt->commit_id, + rt->tag_name, + author ? author : "", + age ? age : "", + rt->commit_msg, + rt->tag_commit); - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - - if (fcgi_gen_response(c, "
Tagger:" - "
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
") == -1) - goto done; - if (fcgi_gen_response(c, author ? author : "") == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - - if (fcgi_gen_response(c, "
Date:" - "
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
") == -1) - goto done; - if (fcgi_gen_response(c, age ? age : "") == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - - if (fcgi_gen_response(c, "
Message:" - "
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
") == -1) - goto done; - if (fcgi_gen_response(c, rt->commit_msg) == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - - if (fcgi_gen_response(c, rt->tag_commit) == -1) - goto done; - - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - fcgi_gen_response(c, "
\n"); done: free(age); free(author); @@ -2290,10 +1705,13 @@ gotweb_render_tags(struct request *c) struct transport *t = c->t; struct querystring *qs = t->qs; struct repo_dir *repo_dir = t->repo_dir; + const char *index_page_str; char *newline; char *age = NULL; - int commit_found = 0; + int r, commit_found = 0; + index_page_str = qs->index_page_str ? qs->index_page_str : ""; + if (qs->action == BRIEFS) { qs->action = TAGS; error = got_get_repo_tags(c, D_MAXSLCOMMDISP); @@ -2302,27 +1720,18 @@ gotweb_render_tags(struct request *c) if (error) goto done; - if (fcgi_gen_response(c, "
\n") == -1) + r = fcgi_printf(c, "
\n" + "
Tags
\n" + "
\n" /* #tags_title_wrapper */ + "
\n"); + if (r == -1) goto done; - if (fcgi_gen_response(c, - "
Tags
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - if (t->tag_count == 0) { - if (fcgi_gen_response(c, "
") == -1) + r = fcgi_printf(c, "
%s\n
\n", + "This repository contains no tags"); + if (r == -1) goto done; - if (fcgi_gen_response(c, - "This repository contains no tags\n") == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; } TAILQ_FOREACH(rt, &t->repo_tags, entry) { @@ -2335,128 +1744,45 @@ gotweb_render_tags(struct request *c) error = gotweb_get_time_str(&age, rt->tagger_time, TM_DIFF); if (error) goto done; - if (fcgi_gen_response(c, "
") == -1) - goto done; - if (fcgi_gen_response(c, age ? age : "") == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
") == -1) - goto done; if (strncmp(rt->tag_name, "refs/tags/", 10) == 0) rt->tag_name += 10; - if (fcgi_gen_response(c, rt->tag_name) == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - if (fcgi_gen_response(c, "
") == -1) - goto done; if (rt->tag_commit != NULL) { newline = strchr(rt->tag_commit, '\n'); if (newline) *newline = '\0'; } - if (fcgi_gen_response(c, "%s
\n" + "
%s
\n" + "
\n" /* .tag_log */ + "\n" /* .navs_wrapper */ + "
\n", + age ? age : "", + rt->tag_name, + index_page_str, repo_dir->name, rt->commit_id, + rt->tag_commit ? rt->tag_commit : "", + index_page_str, repo_dir->name, rt->commit_id, + index_page_str, repo_dir->name, rt->commit_id, + index_page_str, repo_dir->name, rt->commit_id); + if (r == -1) goto done; - if (fcgi_gen_response(c, qs->index_page_str) == -1) - goto done; - if (fcgi_gen_response(c, "&path=") == -1) - goto done; - if (fcgi_gen_response(c, repo_dir->name) == -1) - goto done; - if (fcgi_gen_response(c, "&action=tag&commit=") == -1) - goto done; - if (fcgi_gen_response(c, rt->commit_id) == -1) - goto done; - if (fcgi_gen_response(c, "'>") == -1) - goto done; - if (rt->tag_commit != NULL && - fcgi_gen_response(c, rt->tag_commit) == -1) - goto done; - if (fcgi_gen_response(c, "") == -1) - goto done; - if (fcgi_gen_response(c, "
\n") == -1) - goto done; - if (fcgi_gen_response(c, "\n") == -1) - goto done; - if (fcgi_gen_response(c, - "
\n") == -1) - goto done; - free(age); age = NULL; } @@ -2465,7 +1791,7 @@ gotweb_render_tags(struct request *c) if (error) goto done; } - fcgi_gen_response(c, "
\n"); + fcgi_printf(c, "
\n"); /* #tags_content */ done: free(age); return error; blob - b58b1e7be0421dac9ff6c9717bacb59208ad1bbb blob + 26479ad26fb6fd2bf7bbccfb3e717f0aa521b7bd --- gotwebd/gotwebd.h +++ gotwebd/gotwebd.h @@ -438,7 +438,9 @@ void fcgi_timeout(int, short, void *); void fcgi_cleanup_request(struct request *); void fcgi_create_end_record(struct request *); void dump_fcgi_record(const char *, struct fcgi_record_header *); -int fcgi_gen_response(struct request *, const char *); +int fcgi_printf(struct request *, const char *, ...) + __attribute__((__format__(printf, 2, 3))) + __attribute__((__nonnull__(2))); int fcgi_gen_binary_response(struct request *, const uint8_t *, int); /* got_operations.c */