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
162 %token <boolean> TRUE
163 %token <boolean> FALSE
168 %token <number> FLOAT
169 %token <number> NUMBER
171 %token <number> WEIGHT_START
172 %token <server> IPADDRESS
173 %token <server> HOSTNAME
174 %token <string> STRING
175 %token <string> QUOTED_STRING
176 %token <string> FILE_PATH
178 %type <behavior> behavior_boolean
179 %type <behavior> behavior_number
180 %type <distribution> distribution
182 %type <number> optional_port
183 %type <number> optional_weight
184 %type <string> string
190 | begin ' ' statement
207 context->rc= MEMCACHED_PARSE_USER_ERROR;
208 parser_abort(context, "ERROR called directly");
212 memcached_reset(context->memc);
220 if ((context->rc= memcached_parse_configure_file(*context->memc, $3.c_str, $3.size)) != MEMCACHED_SUCCESS)
222 parser_abort(context, "Failed to parse configuration file");
229 SERVER HOSTNAME optional_port optional_weight
231 if (memcached_failed(context->rc= memcached_server_add_with_weight(context->memc, $2.c_str, $3, uint32_t($4))))
234 snprintf(buffer, sizeof(buffer), "Failed to add server: %s:%u", $2.c_str, uint32_t($3));
235 parser_abort(context, buffer);
237 context->unset_server();
239 | SERVER IPADDRESS optional_port optional_weight
241 if (memcached_failed(context->rc= memcached_server_add_with_weight(context->memc, $2.c_str, $3, uint32_t($4))))
244 snprintf(buffer, sizeof(buffer), "Failed to add server: %s:%u", $2.c_str, uint32_t($3));
245 parser_abort(context, buffer);
247 context->unset_server();
249 | SOCKET string optional_weight
251 if (memcached_failed(context->rc= memcached_server_add_unix_socket_with_weight(context->memc, $2.c_str, uint32_t($3))))
254 snprintf(buffer, sizeof(buffer), "Failed to add socket: %s", $2.c_str);
255 parser_abort(context, buffer);
258 | CONFIGURE_FILE string
260 memcached_set_configuration_file(context->memc, $2.c_str, $2.size);
264 context->memc->configure.initial_pool_size= uint32_t($2);
268 context->memc->configure.max_pool_size= uint32_t($2);
276 if (memcached_callback_get(context->memc, MEMCACHED_CALLBACK_PREFIX_KEY, NULL))
278 parser_abort(context, "--NAMESPACE can only be called once");
281 if ((context->rc= memcached_set_namespace(context->memc, $2.c_str, $2.size)) != MEMCACHED_SUCCESS)
283 parser_abort(context, memcached_last_error_message(context->memc));
288 memcached_flag(*context->memc, MEMCACHED_FLAG_IS_FETCHING_VERSION, true);
290 | DISTRIBUTION distribution
292 // Check to see if DISTRIBUTION has already been set
293 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $2)) != MEMCACHED_SUCCESS)
295 parser_abort(context, "--DISTRIBUTION can only be called once");
298 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $2)) != MEMCACHED_SUCCESS)
300 parser_abort(context, memcached_last_error_message(context->memc));;
303 | DISTRIBUTION distribution ',' hash
305 // Check to see if DISTRIBUTION has already been set
306 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $2)) != MEMCACHED_SUCCESS)
308 parser_abort(context, "--DISTRIBUTION can only be called once");
311 if ((context->rc= memcached_behavior_set_distribution_hash(context->memc, $4)) != MEMCACHED_SUCCESS)
313 parser_abort(context, "Unable to set the hash for the DISTRIBUTION requested");
318 if (context->set_hash($2) == false)
320 parser_abort(context, "--HASH can only be set once");
323 | behavior_number NUMBER
325 if ((context->rc= memcached_behavior_set(context->memc, $1, $2)) != MEMCACHED_SUCCESS)
327 parser_abort(context, "Unable to set behavior");
332 if ((context->rc= memcached_behavior_set(context->memc, $1, true)) != MEMCACHED_SUCCESS)
335 snprintf(buffer, sizeof(buffer), "Could not set: %s", libmemcached_string_behavior($1));
336 parser_abort(context, buffer);
345 REMOVE_FAILED_SERVERS
347 $$= MEMCACHED_BEHAVIOR_REMOVE_FAILED_SERVERS;
351 $$= MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT;
355 $$= MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK;
359 $$= MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK;
363 $$= MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH;
367 $$= MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS;
371 $$= MEMCACHED_BEHAVIOR_POLL_TIMEOUT;
375 $$= MEMCACHED_BEHAVIOR_RCV_TIMEOUT;
379 $$= MEMCACHED_BEHAVIOR_RETRY_TIMEOUT;
383 $$= MEMCACHED_BEHAVIOR_SND_TIMEOUT;
387 $$= MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE;
391 $$= MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE;
398 $$= MEMCACHED_BEHAVIOR_BINARY_PROTOCOL;
402 $$= MEMCACHED_BEHAVIOR_BUFFER_REQUESTS;
404 | HASH_WITH_NAMESPACE
406 $$= MEMCACHED_BEHAVIOR_HASH_WITH_PREFIX_KEY;
410 $$= MEMCACHED_BEHAVIOR_NOREPLY;
412 | RANDOMIZE_REPLICA_READ
414 $$= MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ;
418 $$= MEMCACHED_BEHAVIOR_SORT_HOSTS;
422 $$= MEMCACHED_BEHAVIOR_SUPPORT_CAS;
426 $$= MEMCACHED_BEHAVIOR_TCP_NODELAY;
430 $$= MEMCACHED_BEHAVIOR_TCP_KEEPALIVE;
434 $$= MEMCACHED_BEHAVIOR_TCP_KEEPIDLE;
438 $$= MEMCACHED_BEHAVIOR_USE_UDP;
442 $$= MEMCACHED_BEHAVIOR_VERIFY_KEY;
447 { $$= MEMCACHED_DEFAULT_PORT;}
461 $$= MEMCACHED_HASH_MD5;
465 $$= MEMCACHED_HASH_CRC;
469 $$= MEMCACHED_HASH_FNV1_64;
473 $$= MEMCACHED_HASH_FNV1A_64;
477 $$= MEMCACHED_HASH_FNV1_32;
481 $$= MEMCACHED_HASH_FNV1A_32;
485 $$= MEMCACHED_HASH_HSIEH;
489 $$= MEMCACHED_HASH_MURMUR;
493 $$= MEMCACHED_HASH_JENKINS;
511 $$= MEMCACHED_DISTRIBUTION_CONSISTENT;
515 $$= MEMCACHED_DISTRIBUTION_MODULA;
519 $$= MEMCACHED_DISTRIBUTION_RANDOM;
525 void Context::start()
527 config_parse(this, (void **)scanner);