commit - fab952e1d7814ae73ce60e577993590a34e45aef
commit + 4d4f0e19acf862d139c9864de8510c21b5538e9c
blob - e56cb0a43a67a8af6f59bab8dd7daa7c5bfbc6ec
blob + aee8df851e29d193643d9a437af26142614c947f
--- gmid.c
+++ gmid.c
#define GEMINI_URL_LEN (1024+3) /* URL max len + \r\n + \0 */
-/* large enough to hold a copy of a gemini URL and still have room */
+/* large enough to hold a copy of a gemini URL and still have extra room */
#define PATHBUF (2048)
#define FILEBUF 1024
s[1] = '\0';
if (s[2] != '\0') {
- fprintf(stderr, "last byte of request isn't NULL\n");
+ fprintf(stderr, "the request was longer than 1024 bytes\n");
return 0;
}
int
path_isdir(char *path)
{
- size_t len;
-
if (*path == '\0')
return 1;
-
- len = strlen(path);
-
- /* len >= 1 */
- if (path[len-1] == '/')
- return 1;
-
- return 0;
+ return path[strlen(path)-1] == '/';
}
void
if (fstat(fd, &sb) == -1) {
warn("fstat");
- return 1; /* we'll fail later on anyway */
+ return 1; /* we'll probably fail later on anyway */
}
return S_ISDIR(sb.st_mode);
bzero(fpath, sizeof(fpath));
if (*path != '.')
- strlcpy(fpath, ".", PATHBUF);
+ fpath[0] = '.';
strlcat(fpath, path, PATHBUF);
return;
}
- if ((path = url_start_of_request(url)) == NULL)
+ if ((path = url_start_of_request(url)) == NULL) {
+ start_reply(ctx, BAD_REQUEST, "bad request");
return;
+ }
adjust_path(path);
socklen_t len;
struct tls *clientctx;
char buf[GEMINI_URL_LEN];
- ssize_t r;
for (;;) {
len = sizeof(client);
}
bzero(buf, GEMINI_URL_LEN);
- if ((r = tls_read(clientctx, buf, sizeof(buf)-1)) == -1) {
+ if (tls_read(clientctx, buf, sizeof(buf)-1) == -1) {
warnx("tls_read: %s", tls_error(clientctx));
- goto clienterr;
+ goto clientend;
}
handle(buf, clientctx);
- clienterr:
+ clientend:
if (tls_close(clientctx) == -1)
warn("tls_close: client");
tls_free(clientctx);
const char *cert = "cert.pem", *key = "key.pem", *dir = "docs";
struct tls *ctx = NULL;
struct tls_config *conf;
- void *m;
- size_t mlen;
int sock, ch;
while ((ch = getopt(argc, argv, "c:d:hk:")) != -1) {
TLS_PROTOCOL_TLSv1_2 | TLS_PROTOCOL_TLSv1_3) == -1)
err(1, "tls_config_set_protocols");
- if ((m = tls_load_file(cert, &mlen, NULL)) == NULL)
- err(1, "tls_load_file: %s", cert);
- if (tls_config_set_cert_mem(conf, m, mlen) == -1)
- err(1, "tls_config_set_cert_mem: server certificate");
+ if (tls_config_set_cert_file(conf, cert) == -1)
+ err(1, "tls_config_set_cert_file: %s", cert);
- if ((m = tls_load_file(key, &mlen, NULL)) == NULL)
- err(1, "tls_load_file: %s", key);
- if (tls_config_set_key_mem(conf, m, mlen) == -1)
- err(1, "tls_config_set_cert_mem: server key");
+ if (tls_config_set_key_file(conf, key) == -1)
+ err(1, "tls_config_set_key_file: %s", key);
if ((ctx = tls_server()) == NULL)
err(1, "tls_server");
loop(ctx, sock);
- if (1) {
- printf("why im I here?\n");
- abort();
- }
-
close(sock);
tls_free(ctx);
tls_config_free(conf);