~martijnbraam/public-inbox

Update readerview per latest libgmni changes v1 APPLIED

Drew DeVault: 1
 Update readerview per latest libgmni changes

 1 files changed, 25 insertions(+), 12 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~martijnbraam/public-inbox/patches/27491/mbox | git am -3
Learn more about email & git

[PATCH] Update readerview per latest libgmni changes Export this patch

---
 readerviewwin.c | 37 +++++++++++++++++++++++++------------
 1 file changed, 25 insertions(+), 12 deletions(-)

diff --git a/readerviewwin.c b/readerviewwin.c
index 9fbbe90..741ac7e 100644
--- a/readerviewwin.c
+++ b/readerviewwin.c
@@ -3,8 +3,7 @@
#include <assert.h>
#include <errno.h>
#include <netdb.h>
#include <openssl/bio.h>
#include <openssl/err.h>
#include <bearssl.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
@@ -283,9 +282,6 @@ readerview_app_window_class_init (ReaderviewAppWindowClass *class)
ReaderviewAppWindow *
readerview_app_window_new (ReaderviewApp *app)
{
	SSL_load_error_strings();
	ERR_load_crypto_strings();

	return g_object_new (READERVIEW_APP_WINDOW_TYPE, "application", app, NULL);
}

@@ -431,6 +427,17 @@ readerview_app_window_update_tofu_icon()
	gtk_entry_set_icon_from_paintable(GTK_ENTRY(appwin->url), GTK_ENTRY_ICON_PRIMARY, GDK_PAINTABLE(tofu_icon));
}

static int
resp_read(void *state, void *buf, size_t nbyte)
{
	struct gemini_response *resp = state;
	if (resp->sc) {
		return br_sslio_read(&resp->body, buf, nbyte);
	} else {
		return read(resp->fd, buf, nbyte);
	}
}

void
readerview_app_window_display_response_text_gemini(struct gemini_response *resp, GtkBox *target)
{
@@ -440,7 +447,7 @@ readerview_app_window_display_response_text_gemini(struct gemini_response *resp,
	struct gemini_parser p;
	struct gemini_token tok;
	enum gemini_tok last_tok;
	gemini_parser_init(&p, resp->bio);
	gemini_parser_init(&p, &resp_read, resp);
	temp_url = curl_url();


@@ -566,7 +573,11 @@ readerview_app_window_display_response_text_plain(struct gemini_response *resp,
	int contents_length = 0;

	for (int n = 1; n > 0;) {
		n = BIO_read(resp->bio, &contents[contents_length], contents_size - contents_length - 1);
		if (resp->sc) {
			n = br_sslio_read(&resp->body, &contents[contents_length], contents_size - contents_length - 1);
		} else {
			n = read(resp->fd, &contents[contents_length], contents_size - contents_length - 1);
		}
		if (n == -1) {
			fprintf(stderr, "Error: read");
			return;
@@ -607,7 +618,11 @@ readerview_app_window_display_response_image(struct gemini_response *resp, GtkBo
	int contents_length = 0;

	for (int n = 1; n > 0;) {
		n = BIO_read(resp->bio, &contents[contents_length], contents_size - contents_length - 1);
		if (resp->sc) {
			n = br_sslio_read(&resp->body, &contents[contents_length], contents_size - contents_length - 1);
		} else {
			n = read(resp->fd, &contents[contents_length], contents_size - contents_length - 1);
		}
		if (n == -1) {
			fprintf(stderr, "Error: read");
			return;
@@ -681,11 +696,10 @@ on_redirect:
	GtkEntryBuffer *textbuf = gtk_entry_get_buffer(urlbar);
	gtk_entry_buffer_set_text(textbuf, url, strlen(url));

	opts.ssl_ctx = SSL_CTX_new(TLS_method());
	gemini_tofu_init(&cfg.tofu, opts.ssl_ctx, &tofu_callback, &cfg);
	gemini_tofu_init(&cfg.tofu, &tofu_callback, &cfg);

	struct gemini_response resp;
	enum gemini_result r = gemini_request(url, &opts, &resp);
	enum gemini_result r = gemini_request(url, &opts, &cfg.tofu, &resp);
	if (r != GEMINI_OK) {
		fprintf(stderr, "Error: %s\n", gemini_strerr(r, &resp));
		readerview_app_window_display_error((char *)gemini_strerr(r, &resp), target);
@@ -728,7 +742,6 @@ on_redirect:
		break;
	}
	gemini_response_finish(&resp);
	SSL_CTX_free(opts.ssl_ctx);
	gemini_tofu_finish(&cfg.tofu);
}

-- 
2.34.1