1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
#include <ctype.h>
#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <libmilter/mfapi.h>
#include <sys/queue.h>
#include <sys/un.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <syslog.h>
#include <netdb.h>
#include <math.h>
#include "cfg_file.h"
#include "memcached.h"
extern int yylineno;
extern char *yytext;
int
add_memcached_server (struct config_file *cf, char *str)
{
char *cur_tok, *err_str;
struct memcached_server *mc;
struct hostent *he;
uint16_t port;
if (str == NULL) return 0;
cur_tok = strsep (&str, ":");
if (cur_tok == NULL || *cur_tok == '\0') return 0;
if(cf->memcached_servers_num == MAX_MEMCACHED_SERVERS) {
yywarn ("yyparse: maximum number of memcached servers is reached %d", MAX_MEMCACHED_SERVERS);
}
mc = &cf->memcached_servers[cf->memcached_servers_num];
if (mc == NULL) return 0;
/* cur_tok - server name, str - server port */
if (str == NULL) {
port = DEFAULT_MEMCACHED_PORT;
}
else {
port = (uint16_t)strtoul (str, &err_str, 10);
if (*err_str != '\0') {
return 0;
}
}
if (!inet_aton (cur_tok, &mc->addr)) {
/* Try to call gethostbyname */
he = gethostbyname (cur_tok);
if (he == NULL) {
return 0;
}
else {
memcpy((char *)&mc->addr, he->h_addr, sizeof(struct in_addr));
}
}
mc->port = port;
cf->memcached_servers_num++;
return 1;
}
int
parse_bind_line (struct config_file *cf, char *str)
{
char *cur_tok, *err_str;
struct hostent *he;
size_t s;
if (str == NULL) return 0;
cur_tok = strsep (&str, ":");
if (cur_tok[0] == '/' || cur_tok[0] == '.') {
cf->bind_host = strdup (cur_tok);
cf->bind_family = AF_UNIX;
return 1;
} else {
if (str == '\0') {
cf->bind_port = DEFAULT_BIND_PORT;
}
else {
cf->bind_port = (uint16_t)strtoul (str, &err_str, 10);
if (*err_str != '\0') {
return 0;
}
}
if (!inet_aton (cur_tok, &cf->bind_addr)) {
/* Try to call gethostbyname */
he = gethostbyname (cur_tok);
if (he == NULL) {
return 0;
}
else {
cf->bind_host = strdup (cur_tok);
memcpy((char *)&cf->bind_addr, he->h_addr, sizeof(struct in_addr));
s = strlen (cur_tok) + 1;
}
}
cf->bind_family = AF_INET;
return 1;
}
return 0;
}
void
init_defaults (struct config_file *cfg)
{
cfg->memcached_error_time = DEFAULT_UPSTREAM_ERROR_TIME;
cfg->memcached_dead_time = DEFAULT_UPSTREAM_DEAD_TIME;
cfg->memcached_maxerrors = DEFAULT_UPSTREAM_MAXERRORS;
cfg->memcached_protocol = TCP_TEXT;
cfg->workers_number = DEFAULT_WORKERS_NUM;
}
void
free_config (struct config_file *cfg)
{
if (cfg->pid_file) {
free (cfg->pid_file);
}
if (cfg->temp_dir) {
free (cfg->temp_dir);
}
if (cfg->bind_host) {
free (cfg->bind_host);
}
}
/*
* vi:ts=4
*/
|