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 #ifndef __INTEL_COMPILER
66 #pragma GCC diagnostic ignored "-Wlogical-op"
69 int conf_lex(YYSTYPE* lvalp, void* scanner);
71 #define select_yychar(__context) yychar == UNKNOWN ? ( (__context)->previous_token == END ? UNKNOWN : (__context)->previous_token ) : yychar
73 #define stryytname(__yytokentype) ((__yytokentype) < YYNTOKENS ) ? yytname[(__yytokentype)] : ""
75 #define parser_abort(__context, __error_message) do { (__context)->abort((__error_message), yytokentype(select_yychar(__context)), stryytname(YYTRANSLATE(select_yychar(__context)))); YYABORT; } while (0)
77 // This is bison calling error.
78 inline void __config_error(Context *context, yyscan_t *scanner, const char *error, int last_token, const char *last_token_str)
80 if (not context->end())
82 context->error(error, yytokentype(last_token), last_token_str);
86 context->error(error, yytokentype(last_token), last_token_str);
90 #define config_error(__context, __scanner, __error_msg) do { __config_error((__context), (__scanner), (__error_msg), select_yychar(__context), stryytname(YYTRANSLATE(select_yychar(__context)))); } while (0)
101 %token CONFIGURE_FILE
106 %token SERVERS_OPTION
107 %token UNKNOWN_OPTION
110 /* All behavior options */
111 %token BINARY_PROTOCOL
112 %token BUFFER_REQUESTS
113 %token CONNECT_TIMEOUT
116 %token HASH_WITH_NAMESPACE
117 %token IO_BYTES_WATERMARK
118 %token IO_KEY_PREFETCH
119 %token IO_MSG_WATERMARK
121 %token KETAMA_WEIGHTED
123 %token NUMBER_OF_REPLICAS
125 %token RANDOMIZE_REPLICA_READ
127 %token REMOVE_FAILED_SERVERS
130 %token SOCKET_RECV_SIZE
131 %token SOCKET_SEND_SIZE
137 %token _TCP_KEEPALIVE
166 %token <boolean> TRUE
167 %token <boolean> FALSE
172 %token <number> FLOAT
173 %token <number> NUMBER
175 %token <number> WEIGHT_START
176 %token <server> IPADDRESS
177 %token <server> HOSTNAME
178 %token <string> STRING
179 %token <string> QUOTED_STRING
180 %token <string> FILE_PATH
182 %type <behavior> behavior_boolean
183 %type <behavior> behavior_number
184 %type <distribution> distribution
186 %type <number> optional_port
187 %type <number> optional_weight
188 %type <string> string
194 | begin ' ' statement
211 context->rc= MEMCACHED_PARSE_USER_ERROR;
212 parser_abort(context, "ERROR called directly");
216 memcached_reset(context->memc);
224 if ((context->rc= memcached_parse_configure_file(*context->memc, $3.c_str, $3.size)) != MEMCACHED_SUCCESS)
226 parser_abort(context, "Failed to parse configuration file");
233 SERVER HOSTNAME optional_port optional_weight
235 if (memcached_failed(context->rc= memcached_server_add_with_weight(context->memc, $2.c_str, $3, uint32_t($4))))
238 snprintf(buffer, sizeof(buffer), "Failed to add server: %s:%u", $2.c_str, uint32_t($3));
239 parser_abort(context, buffer);
241 context->unset_server();
243 | SERVER IPADDRESS optional_port optional_weight
245 if (memcached_failed(context->rc= memcached_server_add_with_weight(context->memc, $2.c_str, $3, uint32_t($4))))
248 snprintf(buffer, sizeof(buffer), "Failed to add server: %s:%u", $2.c_str, uint32_t($3));
249 parser_abort(context, buffer);
251 context->unset_server();
253 | SOCKET string optional_weight
255 if (memcached_failed(context->rc= memcached_server_add_unix_socket_with_weight(context->memc, $2.c_str, uint32_t($3))))
258 snprintf(buffer, sizeof(buffer), "Failed to add socket: %s", $2.c_str);
259 parser_abort(context, buffer);
262 | CONFIGURE_FILE string
264 memcached_set_configuration_file(context->memc, $2.c_str, $2.size);
268 context->memc->configure.initial_pool_size= uint32_t($2);
272 context->memc->configure.max_pool_size= uint32_t($2);
280 if (memcached_callback_get(context->memc, MEMCACHED_CALLBACK_PREFIX_KEY, NULL))
282 parser_abort(context, "--NAMESPACE can only be called once");
285 if ((context->rc= memcached_set_namespace(context->memc, $2.c_str, $2.size)) != MEMCACHED_SUCCESS)
287 parser_abort(context, memcached_last_error_message(context->memc));
292 memcached_flag(*context->memc, MEMCACHED_FLAG_IS_FETCHING_VERSION, true);
294 | DISTRIBUTION distribution
296 // Check to see if DISTRIBUTION has already been set
297 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $2)) != MEMCACHED_SUCCESS)
299 parser_abort(context, "--DISTRIBUTION can only be called once");
302 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $2)) != MEMCACHED_SUCCESS)
304 parser_abort(context, memcached_last_error_message(context->memc));;
307 | DISTRIBUTION distribution ',' hash
309 // Check to see if DISTRIBUTION has already been set
310 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $2)) != MEMCACHED_SUCCESS)
312 parser_abort(context, "--DISTRIBUTION can only be called once");
315 if ((context->rc= memcached_behavior_set_distribution_hash(context->memc, $4)) != MEMCACHED_SUCCESS)
317 parser_abort(context, "Unable to set the hash for the DISTRIBUTION requested");
322 if (context->set_hash($2) == false)
324 parser_abort(context, "--HASH can only be set once");
327 | behavior_number NUMBER
329 if ((context->rc= memcached_behavior_set(context->memc, $1, $2)) != MEMCACHED_SUCCESS)
331 parser_abort(context, "Unable to set behavior");
336 if ((context->rc= memcached_behavior_set(context->memc, $1, true)) != MEMCACHED_SUCCESS)
339 snprintf(buffer, sizeof(buffer), "Could not set: %s", libmemcached_string_behavior($1));
340 parser_abort(context, buffer);
349 REMOVE_FAILED_SERVERS
351 $$= MEMCACHED_BEHAVIOR_REMOVE_FAILED_SERVERS;
355 $$= MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT;
359 $$= MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK;
363 $$= MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK;
367 $$= MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH;
371 $$= MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS;
375 $$= MEMCACHED_BEHAVIOR_POLL_TIMEOUT;
379 $$= MEMCACHED_BEHAVIOR_RCV_TIMEOUT;
383 $$= MEMCACHED_BEHAVIOR_RETRY_TIMEOUT;
387 $$= MEMCACHED_BEHAVIOR_SND_TIMEOUT;
391 $$= MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE;
395 $$= MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE;
402 $$= MEMCACHED_BEHAVIOR_BINARY_PROTOCOL;
406 $$= MEMCACHED_BEHAVIOR_BUFFER_REQUESTS;
408 | HASH_WITH_NAMESPACE
410 $$= MEMCACHED_BEHAVIOR_HASH_WITH_PREFIX_KEY;
414 $$= MEMCACHED_BEHAVIOR_NOREPLY;
416 | RANDOMIZE_REPLICA_READ
418 $$= MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ;
422 $$= MEMCACHED_BEHAVIOR_SORT_HOSTS;
426 $$= MEMCACHED_BEHAVIOR_SUPPORT_CAS;
430 $$= MEMCACHED_BEHAVIOR_TCP_NODELAY;
434 $$= MEMCACHED_BEHAVIOR_TCP_KEEPALIVE;
438 $$= MEMCACHED_BEHAVIOR_TCP_KEEPIDLE;
442 $$= MEMCACHED_BEHAVIOR_USE_UDP;
446 $$= MEMCACHED_BEHAVIOR_VERIFY_KEY;
451 { $$= MEMCACHED_DEFAULT_PORT;}
465 $$= MEMCACHED_HASH_MD5;
469 $$= MEMCACHED_HASH_CRC;
473 $$= MEMCACHED_HASH_FNV1_64;
477 $$= MEMCACHED_HASH_FNV1A_64;
481 $$= MEMCACHED_HASH_FNV1_32;
485 $$= MEMCACHED_HASH_FNV1A_32;
489 $$= MEMCACHED_HASH_HSIEH;
493 $$= MEMCACHED_HASH_MURMUR;
497 $$= MEMCACHED_HASH_JENKINS;
515 $$= MEMCACHED_DISTRIBUTION_CONSISTENT;
519 $$= MEMCACHED_DISTRIBUTION_MODULA;
523 $$= MEMCACHED_DISTRIBUTION_RANDOM;
529 void Context::start()
531 config_parse(this, (void **)scanner);