commit - 760079985fc2d63ebd4155a76d4f0d20fbc2f4c5
commit + d38823945b8782a695c7edc575f2e85a16b53d95
blob - f130435179a5b33ae9f100337a219e97ce5607aa
blob + 797edfaf4c9e729607677ddd55fb18312d1dd90f
--- gotwebd/gotweb.c
+++ gotwebd/gotweb.c
}
if (d != NULL && closedir(d) == EOF && error == NULL)
error = got_error_from_errno("closedir");
- return error;
-}
-
-const struct got_error *
-gotweb_escape_html(char **escaped_html, const char *orig_html)
-{
- const struct got_error *error = NULL;
- struct escape_pair {
- char c;
- const char *s;
- } esc[] = {
- { '>', ">" },
- { '<', "<" },
- { '&', "&" },
- { '"', """ },
- { '\'', "'" },
- { '\n', "<br />" },
- };
- size_t orig_len, len;
- int i, j, x;
-
- orig_len = strlen(orig_html);
- len = orig_len;
- for (i = 0; i < orig_len; i++) {
- for (j = 0; j < nitems(esc); j++) {
- if (orig_html[i] != esc[j].c)
- continue;
- len += strlen(esc[j].s) - 1 /* escaped char */;
- }
- }
-
- *escaped_html = calloc(len + 1 /* NUL */, sizeof(**escaped_html));
- if (*escaped_html == NULL)
- return got_error_from_errno("calloc");
-
- x = 0;
- for (i = 0; i < orig_len; i++) {
- int escaped = 0;
- for (j = 0; j < nitems(esc); j++) {
- if (orig_html[i] != esc[j].c)
- continue;
-
- if (strlcat(*escaped_html, esc[j].s, len + 1)
- >= len + 1) {
- error = got_error(GOT_ERR_NO_SPACE);
- goto done;
- }
- x += strlen(esc[j].s);
- escaped = 1;
- break;
- }
- if (!escaped) {
- (*escaped_html)[x] = orig_html[i];
- x++;
- }
- }
-done:
- if (error) {
- free(*escaped_html);
- *escaped_html = NULL;
- } else {
- (*escaped_html)[x] = '\0';
- }
-
return error;
}
return -1;
return gotweb_render_url(c, url);
-}
-
-int
-gotweb_link(struct request *c, struct gotweb_url *url, const char *fmt, ...)
-{
- va_list ap;
- int r;
-
- if (fcgi_printf(c, "<a href='") == -1)
- return -1;
-
- if (gotweb_render_url(c, url) == -1)
- return -1;
-
- if (fcgi_printf(c, "'>") == -1)
- return -1;
-
- va_start(ap, fmt);
- r = fcgi_vprintf(c, fmt, ap);
- va_end(ap);
- if (r == -1)
- return -1;
-
- if (fcgi_printf(c, "</a>"))
- return -1;
- return 0;
}
static struct got_repository *
blob - bc8d26743466b3016093da2bab2a199948bf752a
blob + d6c9430018dfece4faeac6e6d2a51cda87ed4c56
--- gotwebd/gotwebd.h
+++ gotwebd/gotwebd.h
};
/*
- * URL parameter for gotweb_link. NULL values and int set to -1 are
- * implicitly ignored, and string are properly escaped.
+ * URL parameter for gotweb_render_url. NULL values and int set to -1
+ * are implicitly ignored, and string are properly escaped.
*/
struct gotweb_url {
int action;
struct gotweb_url *, int *);
const struct got_error *gotweb_get_time_str(char **, time_t, int);
const struct got_error *gotweb_init_transport(struct transport **);
-const struct got_error *gotweb_escape_html(char **, const char *);
const char *gotweb_action_name(int);
int gotweb_render_url(struct request *, struct gotweb_url *);
int gotweb_render_absolute_url(struct request *, struct gotweb_url *);
-int gotweb_link(struct request *, struct gotweb_url *, const char *, ...)
- __attribute__((__format__(printf, 3, 4)))
- __attribute__((__nonnull__(3)));
void gotweb_free_repo_commit(struct repo_commit *);
void gotweb_free_repo_tag(struct repo_tag *);
void gotweb_process_request(struct request *);