Skip to content

Commit 70c7828

Browse files
committed
* Add skeleton
0 parents  commit 70c7828

20 files changed

Lines changed: 4682 additions & 0 deletions

Makefile.in

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
all: $(TARGETS)
3+
4+
memctest: upstream.c memcached.c memcached-test.c
5+
$(CC) $(OPT_FLAGS) $(CFLAGS) $(PTHREAD_CFLAGS) -c upstream.c
6+
$(CC) $(OPT_FLAGS) $(CFLAGS) $(PTHREAD_CFLAGS) -c memcached.c
7+
$(CC) $(OPT_FLAGS) $(CFLAGS) $(PTHREAD_CFLAGS) -c memcached-test.c
8+
$(CC) $(OPT_FLAGS) $(PTHREAD_LDFLAGS) $(LD_PATH) upstream.o memcached.o memcached-test.o $(LIBS) -o memcached-test
9+
10+
install: $(EXEC) rmilter.8 rmilter.conf.sample
11+
$(INSTALL) -b $(EXEC) $(PREFIX)/sbin/$(EXEC)
12+
$(INSTALL) -v $(EXEC).sh $(PREFIX)/etc/rc.d
13+
#$(INSTALL) -m0644 rspamd.8 $(MANPATH)/man8
14+
#$(INSTALL) -m0644 rspamd.conf.sample $(PREFIX)/etc
15+
$(MKDIR) -o $(RSPAMD_USER) -g $(RSPAMD_GROUP) /var/run/rspamd
16+
17+
clean:
18+
rm -f *.o $(EXEC) *.core
19+
rm -f cfg_lex.c cfg_yacc.c cfg_yacc.h
20+
21+
dist-clean: clean
22+
rm -f Makefile
23+
rm -f config.log
24+
rm -f md5.h md5.c strlcpy.h strlcpy.c queue.h
25+
26+
creategroup:
27+
@echo "Create group $(RSPAMD_GROUP) before installing!"
28+
29+
createuser:
30+
@echo "Create user $(RSPAMD_USER) before installing!"

cfg_file.h

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
* $Id$
3+
*/
4+
5+
6+
#ifndef CFG_FILE_H
7+
#define CFG_FILE_H
8+
9+
#include <sys/types.h>
10+
#ifndef OWN_QUEUE_H
11+
#include <sys/queue.h>
12+
#else
13+
#include "queue.h"
14+
#endif
15+
#include <netinet/in.h>
16+
#include <sys/un.h>
17+
#include "upstream.h"
18+
#include "memcached.h"
19+
20+
#define DEFAULT_BIND_PORT 768
21+
#define MAX_MEMCACHED_SERVERS 48
22+
#define DEFAULT_MEMCACHED_PORT 11211
23+
/* Memcached timeouts */
24+
#define DEFAULT_MEMCACHED_CONNECT_TIMEOUT 1000
25+
/* Upstream timeouts */
26+
#define DEFAULT_UPSTREAM_ERROR_TIME 10
27+
#define DEFAULT_UPSTREAM_ERROR_TIME 10
28+
#define DEFAULT_UPSTREAM_DEAD_TIME 300
29+
#define DEFAULT_UPSTREAM_MAXERRORS 10
30+
31+
/* 1 worker by default */
32+
#define DEFAULT_WORKERS_NUM 1
33+
34+
#define yyerror(fmt, ...) \
35+
fprintf (stderr, "Config file parse error!\non line: %d\n", yylineno); \
36+
fprintf (stderr, "while reading text: %s\nreason: ", yytext); \
37+
fprintf (stderr, fmt, ##__VA_ARGS__); \
38+
fprintf (stderr, "\n")
39+
#define yywarn(fmt, ...) \
40+
fprintf (stderr, "Config file parse warning!\non line %d\n", yylineno); \
41+
fprintf (stderr, "while reading text: %s\nreason: ", yytext); \
42+
fprintf (stderr, fmt, ##__VA_ARGS__); \
43+
fprintf (stderr, "\n")
44+
45+
46+
enum { VAL_UNDEF=0, VAL_TRUE, VAL_FALSE };
47+
48+
struct memcached_server {
49+
struct upstream up;
50+
struct in_addr addr;
51+
uint16_t port;
52+
short alive;
53+
short int num;
54+
};
55+
56+
struct config_file {
57+
char *cfg_name;
58+
char *pid_file;
59+
char *temp_dir;
60+
61+
char *bind_host;
62+
struct in_addr bind_addr;
63+
uint16_t bind_port;
64+
uint16_t bind_family;
65+
66+
char no_fork;
67+
unsigned int workers_number;
68+
69+
struct memcached_server memcached_servers[MAX_MEMCACHED_SERVERS];
70+
size_t memcached_servers_num;
71+
memc_proto_t memcached_protocol;
72+
unsigned int memcached_error_time;
73+
unsigned int memcached_dead_time;
74+
unsigned int memcached_maxerrors;
75+
unsigned int memcached_connect_timeout;
76+
};
77+
78+
int add_memcached_server (struct config_file *cf, char *str);
79+
int parse_bind_line (struct config_file *cf, char *str);
80+
void init_defaults (struct config_file *cfg);
81+
void free_config (struct config_file *cfg);
82+
83+
int yylex (void);
84+
int yyparse (void);
85+
void yyrestart (FILE *);
86+
87+
#endif /* ifdef CFG_FILE_H */
88+
/*
89+
* vi:ts=4
90+
*/

cfg_file.l

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
%x incl
2+
3+
%{
4+
#include <stdio.h>
5+
#include <stdlib.h>
6+
#include <string.h>
7+
#include <strings.h>
8+
#include <syslog.h>
9+
#include "cfg_file.h"
10+
#include "cfg_yacc.h"
11+
12+
#define MAX_INCLUDE_DEPTH 10
13+
YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
14+
int include_stack_ptr = 0;
15+
16+
static size_t
17+
parse_limit (const char *limit)
18+
{
19+
size_t result = 0;
20+
char *err_str;
21+
22+
if (!limit || *limit == '\0') return 0;
23+
24+
result = strtoul (limit, &err_str, 10);
25+
26+
if (*err_str != '\0') {
27+
/* Megabytes */
28+
if (*err_str == 'm' || *err_str == 'M') {
29+
result *= 1048576L;
30+
}
31+
/* Kilobytes */
32+
else if (*err_str == 'k' || *err_str == 'K') {
33+
result *= 1024;
34+
}
35+
/* Gigabytes */
36+
else if (*err_str == 'g' || *err_str == 'G') {
37+
result *= 1073741824L;
38+
}
39+
}
40+
41+
return result;
42+
}
43+
44+
static unsigned int
45+
parse_seconds (const char *t)
46+
{
47+
unsigned int result = 0;
48+
char *err_str;
49+
50+
if (!t || *t == '\0') return 0;
51+
52+
result = strtoul (t, &err_str, 10);
53+
54+
if (*err_str != '\0') {
55+
/* Seconds */
56+
if (*err_str == 's' || *err_str == 'S') {
57+
result *= 1000;
58+
}
59+
}
60+
61+
return result;
62+
}
63+
64+
static char
65+
parse_flag (const char *str)
66+
{
67+
if (!str || !*str) return -1;
68+
69+
if ((*str == 'Y' || *str == 'y') && *(str + 1) == '\0') {
70+
return 1;
71+
}
72+
73+
if ((*str == 'Y' || *str == 'y') &&
74+
(*(str + 1) == 'E' || *(str + 1) == 'e') &&
75+
(*(str + 2) == 'S' || *(str + 2) == 's') &&
76+
*(str + 3) == '\0') {
77+
return 1;
78+
}
79+
80+
if ((*str == 'N' || *str == 'n') && *(str + 1) == '\0') {
81+
return 0;
82+
}
83+
84+
if ((*str == 'N' || *str == 'n') &&
85+
(*(str + 1) == 'O' || *(str + 1) == 'o') &&
86+
*(str + 2) == '\0') {
87+
return 0;
88+
}
89+
90+
return -1;
91+
}
92+
93+
%}
94+
95+
%option noyywrap
96+
%option yylineno
97+
98+
%%
99+
^[ \t]*#.* /* ignore comments */;
100+
.include BEGIN(incl);
101+
tempdir return TEMPDIR;
102+
pidfile return PIDFILE;
103+
workers return WORKERS;
104+
error_time return ERROR_TIME;
105+
dead_time return DEAD_TIME;
106+
maxerrors return MAXERRORS;
107+
reconnect_timeout return RECONNECT_TIMEOUT;
108+
connect_timeout return CONNECT_TIMEOUT;
109+
protocol return PROTOCOL;
110+
memcached return MEMCACHED;
111+
bind_socket return BINDSOCK;
112+
servers return SERVERS;
113+
114+
\{ return OBRACE;
115+
\} return EBRACE;
116+
; return SEMICOLON;
117+
, return COMMA;
118+
= return EQSIGN;
119+
yes|YES|no|NO|[yY]|[nN] yylval.flag=parse_flag(yytext); return FLAG;
120+
\n /* ignore EOL */;
121+
[ \t]+ /* ignore whitespace */;
122+
\"[^"]+\" yylval.string=strdup(yytext + 1); yylval.string[strlen(yylval.string) - 1] = '\0'; return QUOTEDSTRING;
123+
\" return QUOTE;
124+
[0-9]+ yylval.number=strtol(yytext, NULL, 10); return NUMBER;
125+
[0-9]+[kKmMgG]? yylval.limit=parse_limit(yytext); return SIZELIMIT;
126+
[0-9]+[sS]|[0-9]+[mM][sS] yylval.seconds=parse_seconds(yytext); return SECONDS;
127+
[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3} yylval.string=strdup(yytext); return IPADDR;
128+
[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\/[0-9]{1,2} yylval.string=strdup(yytext); return IPNETWORK;
129+
[a-zA-Z<][a-zA-Z@+>_-]* yylval.string=strdup(yytext); return STRING;
130+
\/[^/\n]+\/ yylval.string=strdup(yytext); return REGEXP;
131+
[a-zA-Z0-9].[a-zA-Z0-9\/.-]+ yylval.string=strdup(yytext); return DOMAIN;
132+
[a-zA-Z0-9.-]+:[0-9]{1,5} yylval.string=strdup(yytext); return HOSTPORT;
133+
[a-zA-Z0-9\/.-]+ yylval.string=strdup(yytext); return FILENAME;
134+
<incl>[ \t]* /* eat the whitespace */
135+
<incl>[^ \t\n]+ { /* got the include file name */
136+
if ( include_stack_ptr >= MAX_INCLUDE_DEPTH ) {
137+
yyerror ("yylex: includes nested too deeply" );
138+
return -1;
139+
}
140+
141+
include_stack[include_stack_ptr++] =
142+
YY_CURRENT_BUFFER;
143+
144+
yyin = fopen( yytext, "r" );
145+
146+
if ( ! yyin ) {
147+
yyerror("yylex: cannot open include file");
148+
return -1;
149+
}
150+
151+
yy_switch_to_buffer(
152+
yy_create_buffer( yyin, YY_BUF_SIZE ) );
153+
154+
BEGIN(INITIAL);
155+
}
156+
157+
<<EOF>> {
158+
if ( --include_stack_ptr < 0 )
159+
{
160+
yyterminate();
161+
}
162+
163+
else
164+
{
165+
yy_delete_buffer( YY_CURRENT_BUFFER );
166+
yy_switch_to_buffer(
167+
include_stack[include_stack_ptr] );
168+
}
169+
}
170+
171+
%%
172+
/*
173+
* vi:ts=4
174+
*/

0 commit comments

Comments
 (0)