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
67 #pragma GCC diagnostic ignored "-Wlogical-op"
71 int conf_lex(YYSTYPE* lvalp, void* scanner);
73 #define select_yychar(__context) yychar == UNKNOWN ? ( (__context)->previous_token == END ? UNKNOWN : (__context)->previous_token ) : yychar
75 #define stryytname(__yytokentype) ((__yytokentype) < YYNTOKENS ) ? yytname[(__yytokentype)] : ""
77 #define parser_abort(__context, __error_message) do { (__context)->abort((__error_message), yytokentype(select_yychar(__context)), stryytname(YYTRANSLATE(select_yychar(__context)))); YYABORT; } while (0)
79 // This is bison calling error.
80 inline void __config_error(Context *context, yyscan_t *scanner, const char *error, int last_token, const char *last_token_str)
82 if (not context->end())
84 context->error(error, yytokentype(last_token), last_token_str);
88 context->error(error, yytokentype(last_token), last_token_str);
92 #define config_error(__context, __scanner, __error_msg) do { __config_error((__context), (__scanner), (__error_msg), select_yychar(__context), stryytname(YYTRANSLATE(select_yychar(__context)))); } while (0)
103 %token CONFIGURE_FILE
108 %token SERVERS_OPTION
109 %token UNKNOWN_OPTION
112 /* All behavior options */
113 %token BINARY_PROTOCOL
114 %token BUFFER_REQUESTS
115 %token CONNECT_TIMEOUT
118 %token HASH_WITH_NAMESPACE
119 %token IO_BYTES_WATERMARK
120 %token IO_KEY_PREFETCH
121 %token IO_MSG_WATERMARK
123 %token KETAMA_WEIGHTED
125 %token NUMBER_OF_REPLICAS
127 %token RANDOMIZE_REPLICA_READ
129 %token REMOVE_FAILED_SERVERS
132 %token SOCKET_RECV_SIZE
133 %token SOCKET_SEND_SIZE
139 %token _TCP_KEEPALIVE
168 %token <boolean> CSL_TRUE
169 %token <boolean> CSL_FALSE
174 %token <number> CSL_FLOAT
175 %token <number> NUMBER
177 %token <number> WEIGHT_START
178 %token <server> IPADDRESS
179 %token <server> HOSTNAME
180 %token <string> STRING
181 %token <string> QUOTED_STRING
182 %token <string> FILE_PATH
184 %type <behavior> behavior_boolean
185 %type <behavior> behavior_number
186 %type <distribution> distribution
188 %type <number> optional_port
189 %type <number> optional_weight
190 %type <string> string
196 | begin ' ' statement
213 context->rc= MEMCACHED_PARSE_USER_ERROR;
214 parser_abort(context, "ERROR called directly");
218 memcached_reset(context->memc);
226 if ((context->rc= memcached_parse_configure_file(*context->memc, $3.c_str, $3.size)) != MEMCACHED_SUCCESS)
228 parser_abort(context, "Failed to parse configuration file");
235 SERVER HOSTNAME optional_port optional_weight
237 if (memcached_failed(context->rc= memcached_server_add_with_weight(context->memc, $2.c_str, $3, uint32_t($4))))
240 snprintf(buffer, sizeof(buffer), "Failed to add server: %s:%u", $2.c_str, uint32_t($3));
241 parser_abort(context, buffer);
243 context->unset_server();
245 | SERVER IPADDRESS optional_port optional_weight
247 if (memcached_failed(context->rc= memcached_server_add_with_weight(context->memc, $2.c_str, $3, uint32_t($4))))
250 snprintf(buffer, sizeof(buffer), "Failed to add server: %s:%u", $2.c_str, uint32_t($3));
251 parser_abort(context, buffer);
253 context->unset_server();
255 | CSL_SOCKET string optional_weight
257 if (memcached_failed(context->rc= memcached_server_add_unix_socket_with_weight(context->memc, $2.c_str, uint32_t($3))))
260 snprintf(buffer, sizeof(buffer), "Failed to add socket: %s", $2.c_str);
261 parser_abort(context, buffer);
264 | CONFIGURE_FILE string
266 memcached_set_configuration_file(context->memc, $2.c_str, $2.size);
270 context->memc->configure.initial_pool_size= uint32_t($2);
274 context->memc->configure.max_pool_size= uint32_t($2);
282 if (memcached_callback_get(context->memc, MEMCACHED_CALLBACK_PREFIX_KEY, NULL))
284 parser_abort(context, "--NAMESPACE can only be called once");
287 if ((context->rc= memcached_set_namespace(context->memc, $2.c_str, $2.size)) != MEMCACHED_SUCCESS)
289 parser_abort(context, memcached_last_error_message(context->memc));
294 memcached_flag(*context->memc, MEMCACHED_FLAG_IS_FETCHING_VERSION, true);
296 | DISTRIBUTION distribution
298 // Check to see if DISTRIBUTION has already been set
299 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $2)) != MEMCACHED_SUCCESS)
301 parser_abort(context, "--DISTRIBUTION can only be called once");
304 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $2)) != MEMCACHED_SUCCESS)
306 parser_abort(context, memcached_last_error_message(context->memc));;
309 | DISTRIBUTION distribution ',' hash
311 // Check to see if DISTRIBUTION has already been set
312 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $2)) != MEMCACHED_SUCCESS)
314 parser_abort(context, "--DISTRIBUTION can only be called once");
317 if ((context->rc= memcached_behavior_set_distribution_hash(context->memc, $4)) != MEMCACHED_SUCCESS)
319 parser_abort(context, "Unable to set the hash for the DISTRIBUTION requested");
324 if (context->set_hash($2) == false)
326 parser_abort(context, "--HASH can only be set once");
329 | behavior_number NUMBER
331 if ((context->rc= memcached_behavior_set(context->memc, $1, $2)) != MEMCACHED_SUCCESS)
333 parser_abort(context, "Unable to set behavior");
338 if ((context->rc= memcached_behavior_set(context->memc, $1, true)) != MEMCACHED_SUCCESS)
341 snprintf(buffer, sizeof(buffer), "Could not set: %s", libmemcached_string_behavior($1));
342 parser_abort(context, buffer);
351 REMOVE_FAILED_SERVERS
353 $$= MEMCACHED_BEHAVIOR_REMOVE_FAILED_SERVERS;
357 $$= MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT;
361 $$= MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK;
365 $$= MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK;
369 $$= MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH;
373 $$= MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS;
377 $$= MEMCACHED_BEHAVIOR_POLL_TIMEOUT;
381 $$= MEMCACHED_BEHAVIOR_RCV_TIMEOUT;
385 $$= MEMCACHED_BEHAVIOR_RETRY_TIMEOUT;
389 $$= MEMCACHED_BEHAVIOR_SND_TIMEOUT;
393 $$= MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE;
397 $$= MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE;
404 $$= MEMCACHED_BEHAVIOR_BINARY_PROTOCOL;
408 $$= MEMCACHED_BEHAVIOR_BUFFER_REQUESTS;
410 | HASH_WITH_NAMESPACE
412 $$= MEMCACHED_BEHAVIOR_HASH_WITH_PREFIX_KEY;
416 $$= MEMCACHED_BEHAVIOR_NOREPLY;
418 | RANDOMIZE_REPLICA_READ
420 $$= MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ;
424 $$= MEMCACHED_BEHAVIOR_SORT_HOSTS;
428 $$= MEMCACHED_BEHAVIOR_SUPPORT_CAS;
432 $$= MEMCACHED_BEHAVIOR_TCP_NODELAY;
436 $$= MEMCACHED_BEHAVIOR_TCP_KEEPALIVE;
440 $$= MEMCACHED_BEHAVIOR_TCP_KEEPIDLE;
444 $$= MEMCACHED_BEHAVIOR_USE_UDP;
448 $$= MEMCACHED_BEHAVIOR_VERIFY_KEY;
453 { $$= MEMCACHED_DEFAULT_PORT;}
467 $$= MEMCACHED_HASH_MD5;
471 $$= MEMCACHED_HASH_CRC;
475 $$= MEMCACHED_HASH_FNV1_64;
479 $$= MEMCACHED_HASH_FNV1A_64;
483 $$= MEMCACHED_HASH_FNV1_32;
487 $$= MEMCACHED_HASH_FNV1A_32;
491 $$= MEMCACHED_HASH_HSIEH;
495 $$= MEMCACHED_HASH_MURMUR;
499 $$= MEMCACHED_HASH_JENKINS;
517 $$= MEMCACHED_DISTRIBUTION_CONSISTENT;
521 $$= MEMCACHED_DISTRIBUTION_MODULA;
525 $$= MEMCACHED_DISTRIBUTION_RANDOM;
531 void Context::start()
533 config_parse(this, (void **)scanner);