Updated the thing so the config file uses yacc
This commit is contained in:
parent
f03e656ecb
commit
1f91a4eb2c
6 changed files with 74 additions and 24 deletions
|
@ -1,8 +1,14 @@
|
|||
PROG = sakisafecli
|
||||
SRCS += funcs.c sakisafecli.c config.c
|
||||
SRCS = parse.y
|
||||
SRCS += funcs.c sakisafecli.c config.c lex.yy.c
|
||||
MAN = sakisafecli.1 sakisafeclirc.5
|
||||
LDADD = -lssl -lz -lpthread -lnghttp2 -lcurl -lconfig -lcrypto -L/usr/local/lib
|
||||
YFLAGS = -d
|
||||
PREFIX = /usr/local
|
||||
BINDIR = $(PREFIX)/bin
|
||||
MANDIR = $(PREFIX)/man/man
|
||||
|
||||
lex.yy.c:
|
||||
lex parse.l
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
|
|
@ -8,7 +8,7 @@ void
|
|||
print_config()
|
||||
{
|
||||
puts("Current configuration:");
|
||||
printf("Server: %s\n",server);
|
||||
printf("Server: %s\n",rc.server);
|
||||
if(rc.socks_proxy_flag)
|
||||
printf("Socks proxy url: %s",rc.socks_proxy_url);
|
||||
if(rc.http_proxy_flag)
|
||||
|
@ -41,3 +41,9 @@ init_config(struct config *rc)
|
|||
rc->silent_flag = false;
|
||||
rc->server = "https://lainsafe.delegao.moe";
|
||||
}
|
||||
void
|
||||
load_config()
|
||||
{
|
||||
yyin = fopen("/usr/home/qorg/.sakisafeclirc","r");
|
||||
yyparse();
|
||||
}
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
|
||||
struct config
|
||||
{
|
||||
bool ipv6_flag;
|
||||
|
@ -12,10 +15,10 @@ struct config
|
|||
};
|
||||
|
||||
extern struct config rc;
|
||||
|
||||
extern FILE *yyin;
|
||||
/* Init the config */
|
||||
void
|
||||
init_config(struct config *rc);
|
||||
|
||||
|
||||
|
||||
void
|
||||
load_config();
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
%{
|
||||
#include <stdio.h>
|
||||
#define YYSTYPE char*
|
||||
#include "y.tab.h"
|
||||
#include "parse.h"
|
||||
extern YYSTYPE yylval;
|
||||
%}
|
||||
|
||||
%%
|
||||
server return SERVERTOK;
|
||||
http_proxy return HPTOK;
|
||||
socks_proxy return SPTOK;
|
||||
use_socks_proxy return USPTOK;
|
||||
use_http_proxy return UHPTOK;
|
||||
force_ipv4 return IP4TOK;
|
||||
force_ipv6 return IP6TOK;
|
||||
\n /* ignore EOL */;
|
||||
ipv4 return IP4TOK;
|
||||
ipv6 return IP6TOK;
|
||||
[a-zA-Z][a-zA-Z0-9]* yylval=strdup(yytext); return WORD;
|
||||
[a-zA-Z0-9\/.-]+ yylval=strdup(yytext); return URL;
|
||||
\n /* ignore EOL */;
|
||||
[ \t]+
|
||||
\" return QUOTE;
|
||||
; return SEMICOLON;
|
||||
%%
|
||||
|
|
|
@ -4,20 +4,25 @@
|
|||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include "config.h"
|
||||
|
||||
#define YYSTYPE char*
|
||||
struct config rc;
|
||||
int yyparse(void);
|
||||
void yyerror(const char *str) {
|
||||
fprintf(stderr,"error: %s\n",str);
|
||||
fprintf(stderr,"Error reading config file: %s\n",str);
|
||||
_exit(-1);
|
||||
}
|
||||
%}
|
||||
|
||||
int yywrap()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
%}
|
||||
|
||||
|
||||
%token SERVERTOK HPTOK SPTOK USPTOK UHPTOK IP4TOK IP6TOK
|
||||
%token SERVERTOK HPTOK SPTOK USPTOK UHPTOK IP4TOK IP6TOK QUOTE URL SEMICOLON WORD
|
||||
|
||||
|
||||
%%
|
||||
%%
|
||||
|
||||
conf_statements:
|
||||
|
@ -28,12 +33,45 @@ conf_statements conf_statement SEMICOLON
|
|||
conf_statement:
|
||||
statements
|
||||
|
|
||||
IP4TOK quotedword
|
||||
{
|
||||
if(!strcmp($2,"true"))
|
||||
rc.ipv4_flag = true;
|
||||
else
|
||||
rc.ipv4_flag = false;
|
||||
}
|
||||
|
|
||||
IP6TOK quotedword
|
||||
{
|
||||
if(!strcmp($2,"true"))
|
||||
rc.ipv6_flag = true;
|
||||
else
|
||||
rc.ipv6_flag = false;
|
||||
}
|
||||
|
|
||||
SERVERTOK quotedname
|
||||
{
|
||||
rc.server = $2;
|
||||
}
|
||||
|
|
||||
HPTOK quotedname
|
||||
{
|
||||
rc.http_proxy_url = $2;
|
||||
}
|
||||
|
|
||||
SPTOK quotedname
|
||||
{
|
||||
rc.socks_proxy_url = $2;
|
||||
}
|
||||
;
|
||||
|
||||
quotedname:
|
||||
QUOTE URL QUOTE
|
||||
{
|
||||
$$=$2;
|
||||
}
|
||||
|
||||
quotedword:
|
||||
QUOTE WORD QUOTE
|
||||
{
|
||||
$$=$2;
|
||||
|
@ -43,6 +81,6 @@ statements:
|
|||
| statements statement
|
||||
;
|
||||
|
||||
statement: WORD | quotedname
|
||||
statement: URL | quotedname | quotedword
|
||||
|
||||
%%
|
||||
|
|
|
@ -15,9 +15,6 @@
|
|||
|
||||
/* Config variables */
|
||||
|
||||
struct config rc;
|
||||
|
||||
char *server = "https://lainsafe.delegao.moe";
|
||||
const char *path = ".cache/sakisafelinks";
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
|
@ -39,7 +36,7 @@ main(int argc, char **argv)
|
|||
char config_location[512];
|
||||
|
||||
init_config(&rc);
|
||||
|
||||
load_config();
|
||||
/* libcurl initialization */
|
||||
|
||||
CURL *easy_handle = curl_easy_init();
|
||||
|
@ -133,7 +130,7 @@ main(int argc, char **argv)
|
|||
/* curl options */
|
||||
curl_easy_setopt(easy_handle, CURLOPT_WRITEFUNCTION, write_data);
|
||||
curl_easy_setopt(easy_handle, CURLOPT_WRITEDATA, buffer);
|
||||
curl_easy_setopt(easy_handle, CURLOPT_URL, server);
|
||||
curl_easy_setopt(easy_handle, CURLOPT_URL, rc.server);
|
||||
|
||||
/* Proxy options */
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue