initial commit
This commit is contained in:
commit
584aad56b8
19 changed files with 390 additions and 0 deletions
34
parse_token.c
Normal file
34
parse_token.c
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
#include <libowfat/stralloc.h>
|
||||
#include <libowfat/buffer.h>
|
||||
#include <libowfat/errmsg.h>
|
||||
#include <libowfat/str.h>
|
||||
|
||||
#define AUTH_HEADER "Authorization: Bearer "
|
||||
#define AUTH_HEADER_LEN str_len(AUTH_HEADER)
|
||||
|
||||
// TODO make case insensitive according to https://www.rfc-editor.org/info/rfc7230/#section-3.2
|
||||
int parse_token(buffer *b, stralloc *result)
|
||||
{
|
||||
stralloc line;
|
||||
int r;
|
||||
stralloc_init(result);
|
||||
for (;;) {
|
||||
r=buffer_getnewline_sa(b,&line);
|
||||
if (r==0) break;
|
||||
if (r<0) { carpsys("read line"); goto err; }
|
||||
|
||||
if (stralloc_starts(&line,AUTH_HEADER)) {
|
||||
stralloc_chomp(&line);
|
||||
if (!stralloc_copyb(result, line.s+AUTH_HEADER_LEN,
|
||||
line.len-AUTH_HEADER_LEN)
|
||||
) { carpsys("out of memory"); goto err; }
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
stralloc_free(&line);
|
||||
return 1;
|
||||
err:
|
||||
stralloc_free(&line);
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue