Commit Diff


commit - b148be7145ec930043173b11be95bf6327d3b598
commit + 54764e41a11e16a56da805313f209a9937c5173d
blob - ee328d475bdb5b22bfa532dbe9d5537a7d91ee0d
blob + 48bb3e9ad2ce05481bcf18a40d6b024a8f2b7149
--- net.c
+++ net.c
@@ -473,6 +473,7 @@ err:
 static int
 gemini_parse_reply(struct req *req, const char *header, size_t len)
 {
+	struct ibuf	*ibuf;
 	int		 code;
 	const char	*t;
 
@@ -487,9 +488,16 @@ gemini_parse_reply(struct req *req, const char *header
 		return 0;
 
 	t = header + 3;
+	len = strlen(t) + 1;
 
-	net_send_ui(IMSG_GOT_CODE, req->id, &code, sizeof(code));
-	net_send_ui(IMSG_GOT_META, req->id, t, strlen(t)+1);
+	if ((ibuf = imsg_create(&iev_ui->ibuf, IMSG_REPLY, req->id, 0,
+	    sizeof(code) + len)) == NULL)
+		die();
+	if (imsg_add(ibuf, &code, sizeof(code)) == -1 ||
+	    imsg_add(ibuf, t, len) == -1)
+		die();
+	imsg_close(&iev_ui->ibuf, ibuf);
+	imsg_event_add(iev_ui);
 
 	bufferevent_disable(req->bev, EV_READ|EV_WRITE);
 
blob - 12dcebeabdf586f349249dc3b68d24d87de134e4
blob + 783a5da41098b7cb9ff34036723bdb5b45654344
--- telescope.c
+++ telescope.c
@@ -329,6 +329,9 @@ static void
 handle_request_response(struct tab *tab)
 {
 	char		 buf[128];
+
+	if (tab->code != 30 && tab->code != 31)
+		tab->redirect_count = 0;
 
 	if (tab->code < 10) {	/* internal errors */
 		load_page_from_str(tab, err_pages[tab->code]);
@@ -428,11 +431,13 @@ handle_dispatch_imsg(int fd, short event, void *data)
 	struct imsgev	*iev = data;
 	struct imsgbuf	*imsgbuf = &iev->ibuf;
 	struct imsg	 imsg;
+	struct ibuf	 ibuf;
 	struct tab	*tab;
 	struct download	*d;
-	const char	*str, *h;
-	char		*page;
+	const char	*h;
+	char		*str, *page;
 	ssize_t		 n;
+	int		 code;
 
 	if (event & EV_READ) {
 		if ((n = imsg_read(imsgbuf)) == -1 && errno != EAGAIN)
@@ -468,24 +473,17 @@ handle_dispatch_imsg(int fd, short event, void *data)
 		case IMSG_CHECK_CERT:
 			handle_imsg_check_cert(&imsg);
 			break;
-		case IMSG_GOT_CODE:
-			if ((tab = tab_by_id(imsg_get_id(&imsg))) == NULL)
-				break;
-			if (imsg_get_data(&imsg, &tab->code, sizeof(tab->code))
-			    == -1)
-				die();
-			tab->code = normalize_code(tab->code);
-			if (tab->code != 30 && tab->code != 31)
-				tab->redirect_count = 0;
-			break;
-		case IMSG_GOT_META:
+		case IMSG_REPLY:
 			if ((tab = tab_by_id(imsg_get_id(&imsg))) == NULL)
 				break;
-			if ((str = imsg_borrow_str(&imsg)) == NULL)
+			if (imsg_get_ibuf(&imsg, &ibuf) == -1 ||
+			    ibuf_get(&ibuf, &code, sizeof(code)) == -1 ||
+			    ibuf_borrow_str(&ibuf, &str) == -1)
 				die();
 			if (strlcpy(tab->meta, str, sizeof(tab->meta)) >=
 			    sizeof(tab->meta))
 				die();
+			tab->code = normalize_code(code);
 			handle_request_response(tab);
 			break;
 		case IMSG_BUF:
blob - d458841d901c12576f9fe2ae79944071f1fe6e1d
blob + c077f15294e3d9cac921621ca5d65ee35d53d4e3
--- telescope.h
+++ telescope.h
@@ -49,8 +49,7 @@ enum imsg_type {
 	IMSG_ERR,
 	IMSG_CHECK_CERT,
 	IMSG_CERT_STATUS,
-	IMSG_GOT_CODE,
-	IMSG_GOT_META,
+	IMSG_REPLY,		/* reply code (int) + meta string */
 	IMSG_PROCEED,
 	IMSG_STOP,
 	IMSG_BUF,
blob - d8ae654a86abc0e7d06b67c2ba08298611206206
blob + c6431d29c53306f0ff5022bde427ea5f47c86f68
--- utils.c
+++ utils.c
@@ -100,17 +100,25 @@ imsg_borrow_str(struct imsg *imsg)
 {
 	struct ibuf	 ibuf;
 	char		*data;
-	size_t		 len;
 
 	if (imsg_get_ibuf(imsg, &ibuf) == -1 ||
-	    (data = ibuf_data(&ibuf)) == NULL ||
-	    (len = ibuf_size(&ibuf)) == 0 ||
-	    data[len - 1] != '\0')
+	    ibuf_borrow_str(&ibuf, &data) == -1)
 		return NULL;
-
 	return data;
 }
 
+int
+ibuf_borrow_str(struct ibuf *ibuf, char **data)
+{
+	size_t		 len;
+
+	if ((*data = ibuf_data(ibuf)) == NULL ||
+	    (len = ibuf_size(ibuf)) == 0 ||
+	    (*data)[len - 1] != '\0')
+		return -1;
+	return 0;
+}
+
 void *
 hash_alloc(size_t len, void *d)
 {
blob - e9b8386cca41a5b753e80548cde2f3725c2a5bd2
blob + fe2c312b8a9a3f69151634576295d40fd21f2765
--- utils.h
+++ utils.h
@@ -27,6 +27,7 @@ void		 imsg_event_add(struct imsgev *);
 int		 imsg_compose_event(struct imsgev *, uint16_t, uint32_t, pid_t, int, const void *, uint16_t);
 
 char		*imsg_borrow_str(struct imsg *);
+int		 ibuf_borrow_str(struct ibuf *, char **);
 
 void		*hash_alloc(size_t, void *);
 void		*hash_calloc(size_t, size_t, void *);