initial commit
This commit is contained in:
commit
584aad56b8
19 changed files with 390 additions and 0 deletions
39
check_token.c
Normal file
39
check_token.c
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
#include <libowfat/stralloc.h>
|
||||
#include <libowfat/errmsg.h>
|
||||
#include <libowfat/open.h>
|
||||
#include <libowfat/str.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "nobotgate.h"
|
||||
|
||||
int check_token(char *tokenfile, stralloc *token)
|
||||
{
|
||||
int fd;
|
||||
char buf[4096];
|
||||
buffer b;
|
||||
int r,found;
|
||||
stralloc line;
|
||||
fd = open_read(tokenfile);
|
||||
if (fd < 0)
|
||||
diesys(errno == ENOENT ? 100 : 111, "open_read ", tokenfile);
|
||||
buffer_init_read(&b, fd, buf, sizeof(buf));
|
||||
stralloc_init(&line);
|
||||
|
||||
found = 0;
|
||||
for (;;) {
|
||||
r = buffer_getnewline_sa(&b, &line);
|
||||
if (r == 0) break;
|
||||
if (r < 0) diesys(111, "failed reading tokenfile ", tokenfile);
|
||||
stralloc_chomp(&line);
|
||||
stralloc_0(&line);
|
||||
line.s[str_chr(line.s, ' ')] = 0;
|
||||
if (stralloc_equals(token, line.s)) {
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
buffer_close(&b);
|
||||
stralloc_free(&line);
|
||||
return found;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue