Allow for line-feed terminated responses
Also, remove old flags from the the `flags' list in `libgeminiclient.3'
This commit is contained in:
parent
02054daa12
commit
d03242fd28
|
@ -1,4 +1,4 @@
|
|||
.Dd Apr 29, 2020
|
||||
.Dd May 5, 2020
|
||||
.Dt GEMINI-CAT 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
|
@ -6,7 +6,7 @@
|
|||
.Nd concatnate responses from a Gemini URLs
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Op Fl RSisw
|
||||
.Op Fl RSeisw
|
||||
.Op Fl c Ar cert-file
|
||||
.Op Fl k Ar key-file
|
||||
.Op Fl p Ar port
|
||||
|
@ -26,6 +26,8 @@ Strip out non-space control-characters before writing, the default for
|
|||
TTY outputs.
|
||||
.It Fl c Ar cert-file
|
||||
The certificate file to use for TLS.
|
||||
.It Fl e
|
||||
Enforce a strict interpretation of the Gemini specification.
|
||||
.It Fl i
|
||||
Interactive mode (allow prompts).
|
||||
.It Fl k Ar key-file
|
||||
|
|
|
@ -44,7 +44,7 @@ main(int argc, char *argv[])
|
|||
!= 0)
|
||||
err(EX_NOPERM, "Failed pledge(2)");
|
||||
#endif
|
||||
while ((c = getopt(argc, argv, "RSc:ik:p:r:st:w")) != -1)
|
||||
while ((c = getopt(argc, argv, "RSc:eik:p:r:st:w")) != -1)
|
||||
switch (c) {
|
||||
case 'R':
|
||||
rawout = 1;
|
||||
|
@ -55,6 +55,9 @@ main(int argc, char *argv[])
|
|||
case 'c':
|
||||
gemini.certfile = optarg;
|
||||
break;
|
||||
case 'e':
|
||||
gemini.flags |= GEMINI_STRICT;
|
||||
break;
|
||||
case 'i':
|
||||
prompt = 1;
|
||||
break;
|
||||
|
@ -150,7 +153,7 @@ err:
|
|||
gemini_fini(&gemini);
|
||||
return (EX_SOFTWARE);
|
||||
usage:
|
||||
(void)fprintf(stderr, "usage: gemini-cat [-RSisw] "
|
||||
(void)fprintf(stderr, "usage: gemini-cat [-RSeisw] "
|
||||
"[-c cert-file] [-k key-file] [-p port]\n"
|
||||
" [-r max-redirects] [-t tofu-file] "
|
||||
"URL...\n");
|
||||
|
|
|
@ -140,18 +140,13 @@ Possible
|
|||
.Fa flags
|
||||
are as follows:
|
||||
.Bl -tag -width Ds -compact
|
||||
.It Dv GEMINI_PROMPT
|
||||
Prompt the user for input on status
|
||||
.Li 10 .
|
||||
.It Dv GEMINI_SECURE_PROMPT
|
||||
Prompt the user for input on status
|
||||
.Li 10 ,
|
||||
without echoing the input.
|
||||
.It Dv GEMINI_TOFU_WRITE
|
||||
Write any new certificate information to
|
||||
.Fa tofufile
|
||||
on
|
||||
.Dn gemini_close .
|
||||
.It Dv GEMINI_STRICT
|
||||
Enforce a strict interpretation of the Gemini protocol.
|
||||
.El
|
||||
.Pp
|
||||
All knows
|
||||
|
|
|
@ -325,31 +325,26 @@ gemini_read(struct gemini *g, void *b, size_t bs)
|
|||
* If the white-space had a reasonable maximum
|
||||
* then this would be easier.
|
||||
*/
|
||||
if (i == 0 && g->meta[g->metalen - 1] == '\r' &&
|
||||
cb[0] == '\n') {
|
||||
i++;
|
||||
g->meta[--g->metalen] = '\0';
|
||||
} else if (i == 0 && cb[0] == '\r' &&
|
||||
cb[1] == '\n') {
|
||||
i += 2;
|
||||
} else {
|
||||
for (j = i + (i == 0);
|
||||
j < r && (cb[j] != '\n' ||
|
||||
cb[j - 1] != '\r'); j++)
|
||||
/* do nothing */;
|
||||
j -= j < r;
|
||||
if (g->metalen + j - i >
|
||||
GEMINI_META_MAX + j == r)
|
||||
goto errinval;
|
||||
(void)memcpy(g->meta + g->metalen,
|
||||
cb + i, j - i);
|
||||
g->meta[g->metalen += j - i] = '\0';
|
||||
if (j == r) {
|
||||
i = j;
|
||||
break;
|
||||
}
|
||||
i = j + 2;
|
||||
for (j = i; j < r && cb[j] != '\n'; j++)
|
||||
/* do nothing */;
|
||||
if (g->metalen + j - i > sizeof(g->meta))
|
||||
goto errinval;
|
||||
(void)memcpy(g->meta + g->metalen, cb + i,
|
||||
j - i);
|
||||
g->metalen += j - i;
|
||||
if (cb[j] != '\n') {
|
||||
i = j;
|
||||
break;
|
||||
}
|
||||
if (g->metalen > 0 &&
|
||||
g->meta[g->metalen - 1] == '\r')
|
||||
g->metalen--;
|
||||
else if (g->flags & GEMINI_STRICT)
|
||||
goto errinval;
|
||||
if (g->metalen > GEMINI_META_MAX)
|
||||
goto errinval;
|
||||
g->meta[g->metalen] = '\0';
|
||||
i = j + 1;
|
||||
if (g->status / 10 != 3)
|
||||
g->redirects = 0;
|
||||
switch (g->status / 10) {
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#define GEMINI_REDIRECT_MAX 5
|
||||
|
||||
#define GEMINI_TOFU_WRITE 0x01
|
||||
#define GEMINI_STRICT 0x02
|
||||
|
||||
struct gemini_tofu {
|
||||
struct gemini_tofu *next;
|
||||
|
|
Loading…
Reference in New Issue