Commit Diff


commit - 0f578996634337ef07f12919715a2a233a35d500
commit + 87d297d14e29cf2c5a8a11b8f4db518d9217e337
blob - 46ec1afce4bacfa28a5124980c8dcf89ff1c154c
blob + d9eed48af3544bb17f55249f1a87985e372df8d6
--- Makefile.am
+++ Makefile.am
@@ -28,6 +28,8 @@ telescope_SOURCES =	bufio.c			\
 			genemoji.sh		\
 			help.c			\
 			hist.c			\
+			imsgev.c		\
+			imsgev.h		\
 			iri.c			\
 			iri.h			\
 			keymap.c		\
@@ -65,8 +67,6 @@ telescope_SOURCES =	bufio.c			\
 telescope_identity_SOURCES =			\
 			certs.c			\
 			certs.h			\
-			ev.c			\
-			ev.h			\
 			fs.c			\
 			fs.h			\
 			hist.c			\
blob - db4a22fe78ee5db9f37557e66e93c8729dd84519
blob + 6522d2b5fb0a86b9ed02653d5fa1f959bae735d9
--- control.c
+++ control.c
@@ -31,6 +31,7 @@
 
 #include "control.h"
 #include "ev.h"
+#include "imsgev.h"
 #include "minibuffer.h"
 #include "telescope.h"
 #include "utils.h"
blob - /dev/null
blob + 1680c011fd08a77fc6d0009ed020c48efded8de1 (mode 644)
--- /dev/null
+++ imsgev.c
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2021, 2024 Omar Polo <op@omarpolo.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include "compat.h"
+
+#include "ev.h"
+#include "imsgev.h"
+
+void
+imsg_event_add(struct imsgev *iev)
+{
+	iev->events = EV_READ;
+	if (iev->ibuf.w.queued)
+		iev->events |= EV_WRITE;
+
+	ev_add(iev->ibuf.fd, iev->events, iev->handler, iev);
+}
+
+int
+imsg_compose_event(struct imsgev *iev, uint16_t type, uint32_t peerid,
+    pid_t pid, int fd, const void *data, uint16_t datalen)
+{
+	int	ret;
+
+	if ((ret = imsg_compose(&iev->ibuf, type, peerid, pid, fd, data,
+	    datalen) != -1))
+		imsg_event_add(iev);
+
+	return ret;
+}
+
+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;
+}
blob - /dev/null
blob + 7b3309eb7c60b587980e11a74ce5e00de7724c73 (mode 644)
--- /dev/null
+++ imsgev.h
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2021, 2024 Omar Polo <op@omarpolo.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+struct imsgev {
+	struct imsgbuf	 ibuf;
+	void		(*handler)(int, int, void *);
+	short		 events;
+};
+
+#define IMSG_DATA_SIZE(imsg)	((imsg).hdr.len - IMSG_HEADER_SIZE)
+
+enum imsg_type {
+	/* ui <-> net */
+	IMSG_GET,		/* struct get_req, peerid is the tab id */
+	IMSG_ERR,
+	IMSG_CHECK_CERT,
+	IMSG_CERT_STATUS,
+	IMSG_REPLY,		/* reply code (int) + meta string */
+	IMSG_PROCEED,
+	IMSG_STOP,
+	IMSG_BUF,
+	IMSG_EOF,
+	IMSG_QUIT,
+
+	/* ui <-> ctl */
+	IMSG_CTL_OPEN_URL,
+};
+
+void		 imsg_event_add(struct imsgev *);
+int		 imsg_compose_event(struct imsgev *, uint16_t, uint32_t, pid_t, int, const void *, uint16_t);
+
+int		 ibuf_borrow_str(struct ibuf *, char **);
blob - 10a3a3640641835ce1e8ed3e36313257b7b03947
blob + f5647fe193ac8a4de67bc44aefbd1b3037e5dd8f
--- net.c
+++ net.c
@@ -40,6 +40,7 @@
 
 #include "bufio.h"
 #include "ev.h"
+#include "imsgev.h"
 #include "telescope.h"
 #include "utils.h"
 
blob - ea916a32f1698678ee10b0001f14d2568abd59e2
blob + 65d38ce297b8bf1f42564a8d08e53b3b33d3bd9c
--- session.c
+++ session.c
@@ -31,6 +31,7 @@
 #include "ev.h"
 #include "fs.h"
 #include "hist.h"
+#include "imsgev.h"
 #include "minibuffer.h"
 #include "session.h"
 #include "tofu.h"
blob - 80420dcfbd8080e2692413ee333b8a0fb9339839
blob + 3b5c0156989123d3b9cf4cb87275d5dcf65c95fd
--- telescope.c
+++ telescope.c
@@ -38,6 +38,7 @@
 #include "ev.h"
 #include "fs.h"
 #include "hist.h"
+#include "imsgev.h"
 #include "iri.h"
 #include "keymap.h"
 #include "mcache.h"
blob - 80534e7a35a0ef841f9140001c72bf13ca683226
blob + c510cc27deff21895a2b1771955e9edbb4ff39b8
--- telescope.h
+++ telescope.h
@@ -31,31 +31,6 @@
 #define SIDE_WINDOW_LEFT	0x1
 #define SIDE_WINDOW_BOTTOM	0x2
 
-struct imsgev {
-	struct imsgbuf	 ibuf;
-	void		(*handler)(int, int, void *);
-	short		 events;
-};
-
-#define IMSG_DATA_SIZE(imsg)	((imsg).hdr.len - IMSG_HEADER_SIZE)
-
-enum imsg_type {
-	/* ui <-> net */
-	IMSG_GET,		/* struct get_req, peerid is the tab id */
-	IMSG_ERR,
-	IMSG_CHECK_CERT,
-	IMSG_CERT_STATUS,
-	IMSG_REPLY,		/* reply code (int) + meta string */
-	IMSG_PROCEED,
-	IMSG_STOP,
-	IMSG_BUF,
-	IMSG_EOF,
-	IMSG_QUIT,
-
-	/* ui <-> ctl */
-	IMSG_CTL_OPEN_URL,
-};
-
 enum line_type {
 	/* text/gemini */
 	LINE_TEXT,
blob - 43ca40e36f48cabe9b52c27e38cf142dff07ccd9
blob + 0760907d326922d57431d6e5450a7fa2a6bb165f
--- utils.c
+++ utils.c
@@ -71,41 +71,6 @@ unicode_isgraph(uint32_t cp)
 	return 1;
 }
 
-void
-imsg_event_add(struct imsgev *iev)
-{
-	iev->events = EV_READ;
-	if (iev->ibuf.w.queued)
-		iev->events |= EV_WRITE;
-
-	ev_add(iev->ibuf.fd, iev->events, iev->handler, iev);
-}
-
-int
-imsg_compose_event(struct imsgev *iev, uint16_t type, uint32_t peerid,
-    pid_t pid, int fd, const void *data, uint16_t datalen)
-{
-	int	ret;
-
-	if ((ret = imsg_compose(&iev->ibuf, type, peerid, pid, fd, data,
-	    datalen) != -1))
-		imsg_event_add(iev);
-
-	return ret;
-}
-
-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 - 4ff24022fc18642f124b44f0765910115c507c1e
blob + 47c7887821e79130989cfac0ba3609302959ca6c
--- utils.h
+++ utils.h
@@ -17,19 +17,12 @@
 #ifndef UTILS_H
 #define UTILS_H
 
-struct imsgev;
-
 int		 mark_nonblock_cloexec(int);
 
 int		 has_suffix(const char *, const char *);
 int		 unicode_isspace(uint32_t);
 int		 unicode_isgraph(uint32_t);
 
-void		 imsg_event_add(struct imsgev *);
-int		 imsg_compose_event(struct imsgev *, uint16_t, uint32_t, pid_t, int, const void *, uint16_t);
-
-int		 ibuf_borrow_str(struct ibuf *, char **);
-
 void		*hash_alloc(size_t, void *);
 void		*hash_calloc(size_t, size_t, void *);
 void		 hash_free(void *, void *);