commit 9a28e7e5493907b0cca9976118628ff0202f3f28 from: Omar Polo date: Tue Aug 03 10:40:22 2021 UTC initial support for gopher item type 7 commit - b38cd1f7a4ac9db428ce0815266db7888466392d commit + 9a28e7e5493907b0cca9976118628ff0202f3f28 blob - aa8b57e0025c845fab712c1be431747804a43af3 blob + d411d634d08b25e5ef43f02b9860ef4345f436d3 --- minibuffer.c +++ minibuffer.c @@ -194,7 +194,7 @@ eecmd_select(void) } void -ir_select(void) +ir_select_gemini(void) { char buf[1025] = {0}; struct phos_uri uri; @@ -211,6 +211,15 @@ ir_select(void) } void +ir_select_gopher(void) +{ + exit_minibuffer(); + minibuffer_hist_save_entry(); + + gopher_send_search_req(current_tab, ministate.buf); +} + +void lu_select(void) { exit_minibuffer(); blob - e71a56a1987faeef145c59330bc2bd8c41113fb3 blob + 1e74dc746a66be52c92177e1a5426143d470e617 --- minibuffer.h +++ minibuffer.h @@ -74,7 +74,8 @@ void minibuffer_taint_hist(void); void minibuffer_self_insert(void); void sensible_self_insert(void); void eecmd_select(void); -void ir_select(void); +void ir_select_gemini(void); +void ir_select_gopher(void); void lu_select(void); void bp_select(void); void ts_select(void); blob - a8afb762eeea7a5f46a039c4a9c7daa6d5f19f6b blob + 62c263462242828c1437440677fed6363c1e3684 --- telescope.c +++ telescope.c @@ -371,7 +371,7 @@ handle_imsg_got_meta(struct imsg *imsg, size_t datalen load_page_from_str(tab, err_pages[tab->code]); } else if (tab->code < 20) { /* 1x */ load_page_from_str(tab, err_pages[tab->code]); - ui_require_input(tab, tab->code == 11); + ui_require_input(tab, tab->code == 11, PROTO_GEMINI); } else if (tab->code == 20) { if (setup_parser_for(tab)) { ui_send_net(IMSG_PROCEED, tab->id, NULL, 0); @@ -656,10 +656,21 @@ load_gopher_url(struct tab *tab, const char *url) } else if (has_prefix(path, "/0/")) { parser_init(tab, textplain_initparser); path += 2; + } else if (has_prefix(path, "/7/")) { + /* show input request if there is no query */ + ui_require_input(tab, 0, PROTO_GOPHER); + return load_page_from_str(tab, err_pages[10]); } else { return 0; } + strlcpy(req.req, path, sizeof(req.req)); + if (*tab->uri.query != '\0') { + strlcat(req.req, "?", sizeof(req.req)); + strlcat(req.req, tab->uri.query, sizeof(req.req)); + } + strlcpy(req.req, "\r\n", sizeof(req.req)); + return make_request(tab, &req, PROTO_GOPHER, path); } @@ -698,6 +709,32 @@ make_request(struct tab *tab, struct get_req *req, int return 1; } +void +gopher_send_search_req(struct tab *tab, const char *text) +{ + struct get_req req; + + memset(&req, 0, sizeof(req)); + strlcpy(req.host, tab->uri.host, sizeof(req.host)); + strlcpy(req.port, tab->uri.port, sizeof(req.host)); + + /* +2 to skip /7 */ + strlcpy(req.req, tab->uri.path+2, sizeof(req.req)); + if (*tab->uri.query != '\0') { + strlcat(req.req, "?", sizeof(req.req)); + strlcat(req.req, tab->uri.query, sizeof(req.req)); + } + + strlcat(req.req, "\t", sizeof(req.req)); + strlcat(req.req, text, sizeof(req.req)); + strlcat(req.req, "\r\n", sizeof(req.req)); + + erase_buffer(&tab->buffer); + parser_init(tab, gophermap_initparser); + + make_request(tab, &req, PROTO_GOPHER, NULL); +} + /* * Effectively load the given url in the given tab. Return 1 when * loading the page asynchronously, and thus when an erase_buffer can blob - 07270a94d9d7afeab8970f624bc10963e85c41d3 blob + 3e1f9768b8d9f56c3488a6bfa2bda2789d0c6e19 --- telescope.h +++ telescope.h @@ -319,6 +319,7 @@ void sandbox_ui_process(void); void sandbox_fs_process(void); /* telescope.c */ +void gopher_send_search_req(struct tab *, const char *); void load_url(struct tab *, const char *, const char *); int load_previous_page(struct tab*); int load_next_page(struct tab*); blob - a6b061b65aad7ef49b3c9929c2885d7a5bb10716 blob + e0bd2158c686645f62e455d8456a9991120eae78 --- ui.c +++ ui.c @@ -1184,12 +1184,21 @@ ui_schedule_redraw(void) } void -ui_require_input(struct tab *tab, int hide) +ui_require_input(struct tab *tab, int hide, int proto) { + void (*fn)(void); + + if (proto == PROTO_GEMINI) + fn = ir_select_gemini; + else if (proto == PROTO_GOPHER) + fn = ir_select_gopher; + else + abort(); + /* TODO: hard-switching to another tab is ugly */ switch_to_tab(tab); - enter_minibuffer(sensible_self_insert, ir_select, exit_minibuffer, + enter_minibuffer(sensible_self_insert, fn, exit_minibuffer, &ir_history, NULL, NULL); strlcpy(ministate.prompt, "Input required: ", sizeof(ministate.prompt)); blob - 7cd34f73c633cd97bf099d9d7e098a0aba749a82 blob + 02b2dd49988a6e2179550843d0adbc68170ccd23 --- ui.h +++ ui.h @@ -137,7 +137,7 @@ const char *ui_keyname(int); void ui_toggle_side_window(void); void ui_schedule_redraw(void); void ui_after_message_hook(void); -void ui_require_input(struct tab *, int); +void ui_require_input(struct tab *, int, int); void ui_yornp(const char *, void (*)(int, struct tab *), struct tab *); void ui_read(const char *, void (*)(const char *, struct tab *), struct tab *); void ui_other_window(void);