commit - bfa33dbefe2bc41a9961e881cfea874e6bc78cfa
commit + 31f1a758a6a9144108ca1356abef2d56ef12f759
blob - e518dcfed610e17e951ae6e87eda60570f31d844
blob + d440349455599524b60f7bb68fb1bb5738469e33
--- .gitignore
+++ .gitignore
TAGS
.deps
compat/.deps
+phos/.deps
+phos/.dirstamp
+phos/*.o
Makefile
Makefile.in
aclocal.m4
blob - 0b37a9f76c62a30d723a4f118c22eb3261852483
blob + e770e1a7b7b096fd6e6f57c674a157aed8c54147
--- Makefile.am
+++ Makefile.am
telescope.h \
textplain.c \
ui.c \
- url.c \
- url.h \
utf8.c \
util.c \
wrap.c
+# phos bundled files
+telescope_SOURCES += phos/phos_uri.c
+
BUILT_SOURCES = cmd.gen.h
CLEANFILES = cmd.gen.h
blob - 4738d542f20472d5606661f6b4996e1e753181ff
blob + c3f28e1156edd6f29d138c08d8b7f432f9c09b4b
--- gemini.c
+++ gemini.c
/* a pending request */
struct req {
struct event ev;
- struct url url;
+ struct phos_uri url;
uint32_t id;
int fd;
struct tls *ctx;
ssize_t r;
size_t len;
char buf[1027]; /* URL + \r\n\0 */
-
- strlcpy(buf, "gemini://", sizeof(buf));
- strlcat(buf, req->url.host, sizeof(buf));
- if (*req->url.port != '\0' && strcmp("1965", req->url.port)) {
- strlcat(buf, ":", sizeof(buf));
- strlcat(buf, req->url.port, sizeof(buf));
- }
- strlcat(buf, "/", sizeof(buf));
- strlcat(buf, req->url.path, sizeof(buf));
- if (req->url.query[0] != '\0') {
- strlcat(buf, "?", sizeof(buf));
- strlcat(buf, req->url.query, sizeof(buf));
- }
+ if (!phos_serialize_uri(&req->url, buf, sizeof(buf)))
+ die();
len = strlcat(buf, "\r\n", sizeof(buf));
handle_get(struct imsg *imsg, size_t datalen)
{
struct req *req;
- const char *e;
char *data;
data = imsg->data;
req->id = imsg->hdr.peerid;
TAILQ_INSERT_HEAD(&reqhead, req, reqs);
- if (!url_parse(imsg->data, &req->url, &e)) {
- close_with_err(req, e);
+ if (!phos_parse_absolute_uri(data, &req->url)) {
+ close_with_err(req, "Can't parse URI");
return;
}
blob - 185a4ca90006ff9a58aeb4571ffa3257f7c25b5a
blob + 10c411cd8ebaf898e152e0d585a4ab4a73c6588b
--- telescope.c
+++ telescope.c
/* the first is also the fallback one */
static struct proto protos[] = {
- { "gemini:", load_gemini_url },
- { "about:", load_about_url },
+ { "gemini", load_gemini_url },
+ { "about", load_about_url },
{ NULL, NULL },
};
tab = tab_by_id(imsg->hdr.peerid);
- if ((e = telescope_lookup_tofu(&certs, tab->url.host)) == NULL) {
+ if ((e = telescope_lookup_tofu(&certs, tab->uri.host)) == NULL) {
/* TODO: an update in libressl/libretls changed
* significantly. Find a better approach at storing
* the certs! */
tofu_res = 1; /* trust on first use */
if ((e = calloc(1, sizeof(*e))) == NULL)
abort();
- strlcpy(e->domain, tab->url.host, sizeof(e->domain));
+ strlcpy(e->domain, tab->uri.host, sizeof(e->domain));
strlcpy(e->hash, hash, sizeof(e->hash));
telescope_ohash_insert(&certs, e);
imsg_compose(fsibuf, IMSG_SAVE_CERT, tab->id, 0, -1,
void
load_about_url(struct tab *tab, const char *url)
{
- char *m;
- size_t len;
-
tab->trust = TS_VERIFIED;
- memset(&tab->url, 0, sizeof(tab->url));
-
- m = strchr(url, ':');
- strlcpy(tab->url.scheme, "about", sizeof(tab->url.scheme));
- strlcpy(tab->url.path, m+1, sizeof(tab->url.path));
-
- len = sizeof(tab->hist_cur->h)-1;
- strlcpy(tab->hist_cur->h, url, len);
-
gemtext_initparser(&tab->window.page);
imsg_compose(fsibuf, IMSG_GET, tab->id, 0, -1,
- tab->hist_cur->h, len+1);
+ tab->hist_cur->h, strlen(tab->hist_cur->h)+1);
imsg_flush(fsibuf);
}
void
load_gemini_url(struct tab *tab, const char *url)
{
- const char *err;
- char *p;
size_t len;
- len = sizeof(tab->hist_cur->h)-1;
-
- if (has_prefix(url, "gemini:")) {
- if (!url_parse(url, &tab->url, &err))
- goto err;
- } else {
- if (!url_resolve_from(&tab->url, url, &err))
- goto err;
- }
-
- url_unparse(&tab->url, tab->hist_cur->h, len);
+ len = sizeof(tab->hist_cur->h);
imsg_compose(netibuf, IMSG_GET, tab->id, 0, -1,
- tab->hist_cur->h, len+1);
+ tab->hist_cur->h, len);
imsg_flush(netibuf);
return;
-
-err:
- if (asprintf(&p, "#error loading %s\n>%s\n",
- url, err) == -1)
- die();
- strlcpy(tab->hist_cur->h, url, len);
- load_page_from_str(tab, p);
- free(p);
}
static void
do_load_url(struct tab *tab, const char *url)
{
- struct proto *p;
+ struct phos_uri uri;
+ struct proto *p;
+ char *t;
tab->trust = TS_UNKNOWN;
+ memcpy(&uri, &tab->uri, sizeof(tab->uri));
+ if (!phos_resolve_uri_from_str(&uri, url, &tab->uri)) {
+ if (asprintf(&t, "#error loading %s\n>%s\n",
+ url, "Can't parse the URI") == -1)
+ die();
+ strlcpy(tab->hist_cur->h, url, sizeof(tab->hist_cur->h));
+ load_page_from_str(tab, t);
+ free(t);
+ return;
+ }
+
+ phos_serialize_uri(&tab->uri, tab->hist_cur->h,
+ sizeof(tab->hist_cur->h));
+
for (p = protos; p->schema != NULL; ++p) {
- if (has_prefix(url, p->schema)) {
+ if (!strcmp(uri.scheme, p->schema)) {
p->loadfn(tab, url);
- return;
+ return;
}
}
protos[0].loadfn(tab, url);
-
- empty_vlist(&tab->window);
- empty_linelist(&tab->window);
}
void
}
hist_push(&tab->hist, tab->hist_cur);
do_load_url(tab, url);
+ empty_vlist(&tab->window);
+ empty_linelist(&tab->window);
}
int
blob - dd7cfaf2e219ffbf7cb333bcd9c10b7e595cc1de
blob + 770cd15b4aa867fe99e607edc4b6132311fa998d
--- telescope.h
+++ telescope.h
#include "compat.h"
#include <event.h>
+#include <phos/phos.h>
-#include "url.h"
-
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
uint32_t flags;
enum trust_state trust;
- struct url url;
+ struct phos_uri uri;
struct histhead hist;
struct hist *hist_cur;
size_t hist_off;
blob - 32f7475b9f1abca38940609a096cb66cf8907002
blob + 06860322003c6ca4e9fadd18097fc928eeedce9a
--- ui.c
+++ ui.c
ir_select(void)
{
char buf[1025] = {0};
- struct url url;
+ struct phos_uri uri;
struct tab *tab;
tab = current_tab();
minibuffer_hist_save_entry();
/* a bit ugly but... */
- memcpy(&url, &tab->url, sizeof(tab->url));
- url_set_query(&url, ministate.buf);
- url_unparse(&url, buf, sizeof(buf));
+ memcpy(&uri, &tab->uri, sizeof(tab->uri));
+
+ /* XXX: ptc encode! */
+ memcpy(&uri.query, ministate.buf, strlen(ministate.buf)+1);
+
+ phos_serialize_uri(&uri, buf, sizeof(buf));
load_url_in_tab(tab, buf);
}