1 /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
5 * Copyright (C) 2012 Data Differential, http://datadifferential.com/
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following disclaimer
16 * in the documentation and/or other materials provided with the
19 * * The names of its contributors may not be used to endorse or
20 * promote products derived from this software without specific prior
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 %output "libmemcached/csl/parser.cc"
42 %defines "libmemcached/csl/parser.h"
43 %lex-param { yyscan_t *scanner }
44 %name-prefix="config_"
45 %parse-param { Context *context }
46 %parse-param { yyscan_t *scanner }
54 #include <libmemcached/csl/common.h>
55 #include <libmemcached/options.hpp>
57 #include <libmemcached/csl/context.h>
58 #include <libmemcached/csl/symbol.h>
59 #include <libmemcached/csl/scanner.h>
61 #ifndef __INTEL_COMPILER
62 #pragma GCC diagnostic ignored "-Wold-style-cast"
65 int conf_lex(YYSTYPE* lvalp, void* scanner);
67 #define select_yychar(__context) yychar == UNKNOWN ? ( (__context)->previous_token == END ? UNKNOWN : (__context)->previous_token ) : yychar
69 #define stryytname(__yytokentype) ((__yytokentype) < YYNTOKENS ) ? yytname[(__yytokentype)] : ""
71 #define parser_abort(__context, __error_message) do { (__context)->abort((__error_message), yytokentype(select_yychar(__context)), stryytname(YYTRANSLATE(select_yychar(__context)))); YYABORT; } while (0)
73 // This is bison calling error.
74 inline void __config_error(Context *context, yyscan_t *scanner, const char *error, int last_token, const char *last_token_str)
76 if (not context->end())
78 context->error(error, yytokentype(last_token), last_token_str);
82 context->error(error, yytokentype(last_token), last_token_str);
86 #define config_error(__context, __scanner, __error_msg) do { __config_error((__context), (__scanner), (__error_msg), select_yychar(__context), stryytname(YYTRANSLATE(select_yychar(__context)))); } while (0)
102 %token SERVERS_OPTION
103 %token UNKNOWN_OPTION
106 /* All behavior options */
107 %token BINARY_PROTOCOL
108 %token BUFFER_REQUESTS
109 %token CONNECT_TIMEOUT
112 %token HASH_WITH_NAMESPACE
113 %token IO_BYTES_WATERMARK
114 %token IO_KEY_PREFETCH
115 %token IO_MSG_WATERMARK
117 %token KETAMA_WEIGHTED
119 %token NUMBER_OF_REPLICAS
121 %token RANDOMIZE_REPLICA_READ
123 %token REMOVE_FAILED_SERVERS
126 %token SOCKET_RECV_SIZE
127 %token SOCKET_SEND_SIZE
133 %token _TCP_KEEPALIVE
161 %token <boolean> TRUE
162 %token <boolean> FALSE
167 %token <number> FLOAT
168 %token <number> NUMBER
170 %token <number> WEIGHT_START
171 %token <server> IPADDRESS
172 %token <server> HOSTNAME
173 %token <string> STRING
174 %token <string> QUOTED_STRING
175 %token <string> FILE_PATH
177 %type <behavior> behavior_boolean
178 %type <behavior> behavior_number
179 %type <distribution> distribution
181 %type <number> optional_port
182 %type <number> optional_weight
183 %type <string> string
189 | begin ' ' statement
206 context->rc= MEMCACHED_PARSE_USER_ERROR;
207 parser_abort(context, "ERROR called directly");
211 memcached_reset(context->memc);
219 if ((context->rc= memcached_parse_configure_file(*context->memc, $3.c_str, $3.size)) != MEMCACHED_SUCCESS)
221 parser_abort(context, "Failed to parse configuration file");
228 SERVER HOSTNAME optional_port optional_weight
230 if (memcached_failed(context->rc= memcached_server_add_with_weight(context->memc, $2.c_str, $3, $4)))
233 snprintf(buffer, sizeof(buffer), "Failed to add server: %s:%u", $2.c_str, uint32_t($3));
234 parser_abort(context, buffer);
236 context->unset_server();
238 | SERVER IPADDRESS optional_port optional_weight
240 if (memcached_failed(context->rc= memcached_server_add_with_weight(context->memc, $2.c_str, $3, $4)))
243 snprintf(buffer, sizeof(buffer), "Failed to add server: %s:%u", $2.c_str, uint32_t($3));
244 parser_abort(context, buffer);
246 context->unset_server();
248 | SOCKET string optional_weight
250 if (memcached_failed(context->rc= memcached_server_add_unix_socket_with_weight(context->memc, $2.c_str, $3)))
253 snprintf(buffer, sizeof(buffer), "Failed to add server: %s", $2.c_str);
254 parser_abort(context, buffer);
257 | CONFIGURE_FILE string
259 memcached_set_configuration_file(context->memc, $2.c_str, $2.size);
263 context->memc->configure.initial_pool_size= $2;
267 context->memc->configure.max_pool_size= $2;
275 if (memcached_callback_get(context->memc, MEMCACHED_CALLBACK_PREFIX_KEY, NULL))
277 parser_abort(context, "--NAMESPACE can only be called once");
280 if ((context->rc= memcached_set_namespace(context->memc, $2.c_str, $2.size)) != MEMCACHED_SUCCESS)
282 parser_abort(context, memcached_last_error_message(context->memc));
285 | DISTRIBUTION distribution
287 // Check to see if DISTRIBUTION has already been set
288 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $2)) != MEMCACHED_SUCCESS)
290 parser_abort(context, "--DISTRIBUTION can only be called once");
293 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $2)) != MEMCACHED_SUCCESS)
295 parser_abort(context, memcached_last_error_message(context->memc));;
298 | DISTRIBUTION distribution ',' hash
300 // Check to see if DISTRIBUTION has already been set
301 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $2)) != MEMCACHED_SUCCESS)
303 parser_abort(context, "--DISTRIBUTION can only be called once");
306 if ((context->rc= memcached_behavior_set_distribution_hash(context->memc, $4)) != MEMCACHED_SUCCESS)
308 parser_abort(context, "Unable to set the hash for the DISTRIBUTION requested");
313 if (context->set_hash($2) == false)
315 parser_abort(context, "--HASH can only be set once");
318 | behavior_number NUMBER
320 if ((context->rc= memcached_behavior_set(context->memc, $1, $2)) != MEMCACHED_SUCCESS)
322 parser_abort(context, "Unable to set behavior");
327 if ((context->rc= memcached_behavior_set(context->memc, $1, true)) != MEMCACHED_SUCCESS)
330 snprintf(buffer, sizeof(buffer), "Could not set: %s", libmemcached_string_behavior($1));
331 parser_abort(context, buffer);
340 REMOVE_FAILED_SERVERS
342 $$= MEMCACHED_BEHAVIOR_REMOVE_FAILED_SERVERS;
346 $$= MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT;
350 $$= MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK;
354 $$= MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK;
358 $$= MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH;
362 $$= MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS;
366 $$= MEMCACHED_BEHAVIOR_POLL_TIMEOUT;
370 $$= MEMCACHED_BEHAVIOR_RCV_TIMEOUT;
374 $$= MEMCACHED_BEHAVIOR_RETRY_TIMEOUT;
378 $$= MEMCACHED_BEHAVIOR_SND_TIMEOUT;
382 $$= MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE;
386 $$= MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE;
393 $$= MEMCACHED_BEHAVIOR_BINARY_PROTOCOL;
397 $$= MEMCACHED_BEHAVIOR_BUFFER_REQUESTS;
399 | HASH_WITH_NAMESPACE
401 $$= MEMCACHED_BEHAVIOR_HASH_WITH_PREFIX_KEY;
405 $$= MEMCACHED_BEHAVIOR_NOREPLY;
407 | RANDOMIZE_REPLICA_READ
409 $$= MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ;
413 $$= MEMCACHED_BEHAVIOR_SORT_HOSTS;
417 $$= MEMCACHED_BEHAVIOR_SUPPORT_CAS;
421 $$= MEMCACHED_BEHAVIOR_TCP_NODELAY;
425 $$= MEMCACHED_BEHAVIOR_TCP_KEEPALIVE;
429 $$= MEMCACHED_BEHAVIOR_TCP_KEEPIDLE;
433 $$= MEMCACHED_BEHAVIOR_USE_UDP;
437 $$= MEMCACHED_BEHAVIOR_VERIFY_KEY;
442 { $$= MEMCACHED_DEFAULT_PORT;}
456 $$= MEMCACHED_HASH_MD5;
460 $$= MEMCACHED_HASH_CRC;
464 $$= MEMCACHED_HASH_FNV1_64;
468 $$= MEMCACHED_HASH_FNV1A_64;
472 $$= MEMCACHED_HASH_FNV1_32;
476 $$= MEMCACHED_HASH_FNV1A_32;
480 $$= MEMCACHED_HASH_HSIEH;
484 $$= MEMCACHED_HASH_MURMUR;
488 $$= MEMCACHED_HASH_JENKINS;
506 $$= MEMCACHED_DISTRIBUTION_CONSISTENT;
510 $$= MEMCACHED_DISTRIBUTION_MODULA;
514 $$= MEMCACHED_DISTRIBUTION_RANDOM;
520 void Context::start()
522 config_parse(this, (void **)scanner);