From: Mark Jamsek Subject: Re: gotwebd: introducing fcgi_printf To: Omar Polo Cc: gameoftrees@openbsd.org, Tracey Emery Date: Mon, 15 Aug 2022 21:46:38 +1000 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. > > > > 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. > > > > 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 :) 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! 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. (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'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 :) > > diff /home/op/w/got > commit - 3084a91bb165520582c5aa695e2c6717e09e5ba6 > path + /home/op/w/got > blob - f6cb81448f5778d7872b537fd6b90838285c99ee > file + gotwebd/fcgi.c > --- 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 > file + gotwebd/got_operations.c > --- gotwebd/got_operations.c > +++ gotwebd/got_operations.c > @@ -829,10 +829,11 @@ 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; > + char *modestr = NULL; Could move *modestr = NULL to the above line: char *modestr = NULL, *path = NULL, *in_repo_path = NULL; > + int nentries, i, r; > > TAILQ_INIT(&refs); > > @@ -871,6 +872,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 +921,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" > + "
", /* .tree_wrapper */ ^^ \n was after in removed line > + 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; > - > } 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" > + "
" /* .tree_line */ ^^ \n in removed line > + "
" > + "commits\n" > + " | \n" > + "blame\n" > + "
" /* .tree_line_blank */ ^^ \n > + "
", /* .tree_wrapper */ ^^ \n > + 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 +1119,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 +1169,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 +1196,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 +1563,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 +1571,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 > file + gotwebd/gotweb.c > --- 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,123 @@ 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" > + "%s\n" > + "\n" > + "\n" > + "\n" > + "\n" > + " + " href='/apple-touch-icon.png' />\n" > + " + " href='/favicon-32x32.png' />\n" > + " + " href='/favicon-16x16.png' />\n" > + "\n" > + "\n" > + "\n" > + "\n" > + "\n" > + "
\n" > + "\n" /* #header */ > + "
\n" > + "\n
\n\n", > + siteowner); > + > + free(escaped_owner); > + return NULL; > } > > static const struct got_error * > @@ -864,12 +777,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"); > done: > free(t->next_id); > t->next_id = NULL; > @@ -1035,10 +942,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 +981,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 +1039,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); > @@ -1292,7 +1123,7 @@ render: > if (error) > goto done; > div: > - fcgi_gen_response(c, "
\n"); > + /* fcgi_printf(c, "
\n"); */ > done: > if (d != NULL && closedir(d) == EOF && error == NULL) > error = got_error_from_errno("closedir"); > @@ -1306,6 +1137,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 +1149,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" > + "
" /* #blame_title_wrapper */ ^^ \n > + "
\n" > + "
\n" > + "
\n" > + "
Date:
\n" > + "
%s
" > + "
Message:
\n" > + "
%s
" ^^ \n > + "
" /* #blame_header */ ^^ \n > + "
" /* #blame_header_wrapper */ ^^ \n > + "
\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 */ ^^^^^^ this second /div was after done: > done: > - fcgi_gen_response(c, "
\n"); > return error; > } > > @@ -1381,18 +1187,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" > + "
" /* #briefs_title_wrapper */ ^^ \n > + "
\n"); > + if (r == -1) > goto done; > > if (qs->action == SUMMARY) { > @@ -1407,123 +1213,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 +1268,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 +1283,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 +1308,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 > + "
" /* .commits_header */ ^^ \n > + "
" /* .commits_header_wrapper */ ^^ \n > + "
\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;
missing between div class='commit' and div class='navs_wrapper'? see below xxx > + r = fcgi_printf(c, "" /* .navs_wrapper */ ^^ \n > + "
\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; xxx > - if (fcgi_gen_response(c, "
\n") == -1) > - goto done; xxx > - > - 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 +1351,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 +1366,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 +1379,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" > + "
" /* #branches_title_wrapper */ ^^ \n > + "
\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 +1408,42 @@ 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" no \n in fcgi_gen_response() ^^ > + "
%s
\n" > + "
 
\n" > + "
" > + "" > + "%s" > + "
" /* .branch */ ^^ \n > + "" /* .navs_wrapper */ ^^ \n > + "
\n" > + "
" /* .branches_wrapper */ ^^ \n > + , > + 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 is in the corresponding fcgi_gen_response() > + "
%s
" ^^ \n also not here but is in the corresponding fcgi_gen_response() > + "
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) ^^ here > - 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) ^^ and here > - 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"); /* #tre_content */ #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" > + "
" /* #diff_title_wrapper */ ^^ \n not here but is in previous > + "
\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 > + "
" /* #diff_header */ ^^ \n > + "
" /* #diff_header_wrapper */ ^^ \n > + "
\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 */ ^^^^^^^^ second
tag was after done: > done: > - fcgi_gen_response(c, "\n"); ^^^^^^^^ here > 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 */ ^^^^^^ second closing div missing? > + 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; ^^^^^^ there were two > > error = gotweb_render_briefs(c); > if (error) { > @@ -2197,84 +1661,36 @@ 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 > + "
" /* #tag_header */ ^^ \n > + "
\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 +1706,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 +1721,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" > + "
" /* #tags_title_wrapper */ ^^ \n > + "
\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 > + "This repository contains no tags\n"); second closing div missing after err_content div? > + 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; ^^^^^^ two /div > } > > TAILQ_FOREACH(rt, &t->repo_tags, entry) { > @@ -2335,128 +1745,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 > + "\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 +1792,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 > file + gotwebd/gotwebd.h > --- 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 */ > -- Mark Jamsek GPG: F2FF 13DE 6A06 C471 CA80 E6E2 2930 DC66 86EE CF68