remove all asprintf from gw_briefs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
diff --git a/gotweb/gotweb.c b/gotweb/gotweb.c
index ed7a10d..6df005b 100644
--- a/gotweb/gotweb.c
+++ b/gotweb/gotweb.c
@@ -1131,7 +1131,7 @@ gw_briefs(struct gw_trans *gw_trans)
{
const struct got_error *error = NULL;
struct gw_header *header = NULL, *n_header = NULL;
- char *age = NULL, *href_diff = NULL, *href_blob = NULL;
+ char *age = NULL, *href_diff = NULL, *href_tree = NULL;
char *href_prev = NULL, *href_next = NULL;
char *newline, *smallerthan;
enum kcgi_err kerr = KCGI_OK;
@@ -1195,11 +1195,9 @@ gw_briefs(struct gw_trans *gw_trans)
if (kerr != KCGI_OK)
goto done;
- if (asprintf(&href_diff, "?path=%s&action=diff&commit=%s",
- gw_trans->repo_name, n_header->commit_id) == -1) {
- error = got_error_from_errno("asprintf");
- goto done;
- }
+ href_diff = khttp_urlpart(NULL, NULL, "gotweb", "path",
+ gw_trans->repo_name, "action", "diff", "commit",
+ n_header->commit_id, NULL);
kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
KATTR_ID, "briefs_log", KATTR__MAX);
if (kerr != KCGI_OK)
@@ -1262,13 +1260,11 @@ gw_briefs(struct gw_trans *gw_trans)
if (kerr != KCGI_OK)
goto done;
- if (asprintf(&href_blob, "?path=%s&action=tree&commit=%s",
- gw_trans->repo_name, n_header->commit_id) == -1) {
- error = got_error_from_errno("asprintf");
- goto done;
- }
+ href_tree = khttp_urlpart(NULL, NULL, "gotweb", "path",
+ gw_trans->repo_name, "action", "tree", "commit",
+ n_header->commit_id, NULL);
kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
- KATTR_HREF, href_blob, KATTR__MAX);
+ KATTR_HREF, href_tree, KATTR__MAX);
if (kerr != KCGI_OK)
goto done;
khtml_puts(gw_trans->gw_html_req, "tree");
@@ -1291,8 +1287,8 @@ gw_briefs(struct gw_trans *gw_trans)
age = NULL;
free(href_diff);
href_diff = NULL;
- free(href_blob);
- href_blob = NULL;
+ free(href_tree);
+ href_tree = NULL;
}
if (gw_trans->next_id || gw_trans->page > 0) {
@@ -1307,15 +1303,13 @@ gw_briefs(struct gw_trans *gw_trans)
}
if (gw_trans->page > 0 && gw_trans->prev_id) {
- if (asprintf(&href_prev,
- "?path=%s&page=%d&action=briefs&commit=%s&prev=%s",
- gw_trans->repo_name, gw_trans->page - 1,
- gw_trans->prev_id ? gw_trans->prev_id : "",
- gw_trans->prev_prev_id ?
- gw_trans->prev_prev_id : "") == -1) {
- error = got_error_from_errno("asprintf");
- goto done;
- }
+ href_prev = khttp_urlpartx(NULL, NULL, "gotweb", "path",
+ KATTRX_STRING, gw_trans->repo_name, "page",
+ KATTRX_INT, (int64_t) (gw_trans->page - 1), "action",
+ KATTRX_STRING, "briefs", "commit", KATTRX_STRING,
+ gw_trans->prev_id ? gw_trans->prev_id : "", "prev",
+ KATTRX_STRING, gw_trans->prev_prev_id ?
+ gw_trans->prev_prev_id : "", NULL);
kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
KATTR_HREF, href_prev, KATTR__MAX);
if (kerr != KCGI_OK)
@@ -1339,17 +1333,15 @@ gw_briefs(struct gw_trans *gw_trans)
KATTR_ID, "nav_next", KATTR__MAX);
if (kerr != KCGI_OK)
goto done;
- if (asprintf(&href_next,
- "?path=%s&page=%d&action=briefs" \
- "&commit=%s&prev=%s&prev_prev=%s",
- gw_trans->repo_name, gw_trans->page + 1,
- gw_trans->next_id,
+
+ href_next = khttp_urlpartx(NULL, NULL, "gotweb", "path",
+ KATTRX_STRING, gw_trans->repo_name, "page",
+ KATTRX_INT, (int64_t) (gw_trans->page + 1), "action",
+ KATTRX_STRING, "briefs", "commit", KATTRX_STRING,
+ gw_trans->next_id, "prev", KATTRX_STRING,
gw_trans->next_prev_id ? gw_trans->next_prev_id : "",
- gw_trans->prev_id ?
- gw_trans->prev_id : "") == -1) {
- error = got_error_from_errno("calloc");
- goto done;
- }
+ "prev_prev", KATTRX_STRING, gw_trans->prev_id ?
+ gw_trans->prev_id : "", NULL),
kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
KATTR_HREF, href_next, KATTR__MAX);
if (kerr != KCGI_OK)
@@ -1375,7 +1367,7 @@ done:
free(href_next);
free(href_prev);
free(href_diff);
- free(href_blob);
+ free(href_tree);
if (error == NULL && kerr != KCGI_OK)
error = gw_kcgi_error(kerr);
return error;