commit ba782cb826e411314d96dc3aedf024c5eefbb0b9 from: Omar Polo date: Sun Jul 25 10:30:04 2021 UTC add default ports it's ugly to patch the port in load_*_url. It's still ugly to do in do_load_url, but a bit less. It would be nice if phos did this, but I'm not sure it fits the library adding default ports of a bunch of protocols. commit - 352e03557a652af07f7edb4348e6dc4a7fd2f3e4 commit + ba782cb826e411314d96dc3aedf024c5eefbb0b9 blob - bae723d80b6bffa81183ff521340759ceceb5c92 blob + 53bd55194652cb078f80317a3e4d8ba93b04da43 --- telescope.c +++ telescope.c @@ -118,12 +118,13 @@ static int ui_send_fs(int, uint32_t, const void *, u static struct proto { const char *schema; + const char *port; void (*loadfn)(struct tab*, const char*); } protos[] = { - {"about", load_about_url}, - {"finger", load_finger_url}, - {"gemini", load_gemini_url}, - {NULL, NULL}, + {"about", NULL, load_about_url}, + {"finger", "79", load_finger_url}, + {"gemini", "1965", load_gemini_url}, + {NULL, NULL, NULL}, }; static imsg_handlerfn *handlers[] = { @@ -590,10 +591,7 @@ load_finger_url(struct tab *tab, const char *url) char *at; memset(&req, 0, sizeof(req)); - if (*tab->uri.port != '\0') - strlcpy(req.port, tab->uri.port, sizeof(req.port)); - else - strlcpy(req.port, "79", sizeof(req.port)); + strlcpy(req.port, tab->uri.port, sizeof(req.port)); /* * Sometimes the finger url have the user as path component @@ -708,6 +706,11 @@ do_load_url(struct tab *tab, const char *url, const ch for (p = protos; p->schema != NULL; ++p) { if (!strcmp(tab->uri.scheme, p->schema)) { + /* patch the port */ + if (*tab->uri.port == '\0' && p->port != NULL) + strlcpy(tab->uri.port, p->port, + sizeof(tab->uri.port)); + p->loadfn(tab, url); return 1; }