{! /* * Copyright (c) 2022 Omar Polo * * 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 #include #include #include #include #include #include #include #include #include #include "galileo.h" #include "tmpl.h" static int tp_navigation(struct template *); !} {{ define tp_head(struct template *tp, const char *lang, const char *title) }} {! struct client *clt = tp->tp_arg; struct proxy_config *pc = clt->clt_pc; const char *stylesheet = pc ? pc->stylesheet : ""; const char *prfx = clt->clt_script_name; const char *path = clt->clt_path_info; int hidenav; hidenav = pc ? pc->flags & PROXY_NO_NAVBAR : 0; !} {{ if *stylesheet == 0 }} {{ else }} {{ end }} {{ if title }} {{ title }} {{ else if pc }} gemini://{{ pc->proxy_name }}{{ path }} {{ end }} {{ if path && !hidenav }} {{ render tp_navigation(tp) }} {{ end }} {{ end }} {{ define tp_foot(struct template *tp) }} {! struct client *clt = tp->tp_arg; struct proxy_config *pc = clt->clt_pc; const char *path = clt->clt_path_info; int hidefoot; hidefoot = pc ? pc->flags & PROXY_NO_FOOTER : 0; !} {{ if pc && !hidefoot }} {{ end }} {{ end }} {{ define tp_navigation(struct template *tp) }} {! struct client *clt = tp->tp_arg; const char *dname, *dsufx = "/", *prfx = clt->clt_script_name; char *path = clt->clt_path_info; char *tilde, *t, home[GEMINI_MAXLEN], up[GEMINI_MAXLEN]; char usr[64]; char c; *home = '\0'; if ((tilde = strstr(path, "/~")) != NULL && (t = strchr(tilde + 1, '/')) != NULL) { c = *++t; *t = '\0'; (void) strlcpy(home, path + 1, sizeof(home)); *t = c; c = *--t; *t = '\0'; (void) strlcpy(usr, tilde + 2, sizeof(usr)); *t = c; } (void) strlcpy(up, path + 1, sizeof(up)); dname = dirname(up); if (!strcmp(dname, ".")) { dname = ""; dsufx = ""; } !}
{{ end }} {{ define tp_figure(struct template *tp, const char *url, const char *label) }}
{{ label }}
{{ end }} {{ define tp_pre_open(struct template *tp, const char *label) }}
{{ if label && *label != '\0' }}
{{ label }}
{{ end }}
{{ end }}

{{ define tp_pre_close(struct template *tp) }}
	
{{ end }} {{ define tp_error(struct template *tp, int code, const char *reason) }} {! char scode[32]; int r; r = snprintf(scode, sizeof(code), "%d", code); if (r < 0 || (size_t)r >= sizeof(code)) return (0); !} {{ render tp_head(tp, "en", "Proxy error") }}

Proxy error

{{ if code != -1 }}

Request failed with code: {{ scode }}.

The server says: {{ reason }}.

{{ else }}

Unable to serve the page due to: {{ reason }}.

{{ end }}
{{ render tp_foot(tp) }} {{ end }} {{ define tp_inputpage(struct template *tp, const char *prompt) }} {{ render tp_head(tp, "en", "input request") }}

The server ask for input: {{ prompt }}.

{{ " " }}
{{ render tp_foot(tp) }} {{ end }}