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