END/RESET/etc.
if (rc != MEMCACHED_SUCCESS)
{
- std::cerr << "Failed to parse options:" << argv[x] << std::endl;
- std::cerr << "\t" << buffer << std::endl;
+ std::cerr << "Failed to parse argument #" << x << " " << argv[x] << std::endl;
+ std::cerr << "Error message from parser was:\t" << buffer << std::endl;
return EXIT_FAILURE;
}
}
MEMCACHED_AUTH_FAILURE,
MEMCACHED_AUTH_CONTINUE,
MEMCACHED_PARSE_ERROR,
+ MEMCACHED_PARSE_USER_ERROR,
MEMCACHED_MAXIMUM_RETURN /* Always add new error code before */
} memcached_return_t;
#include "common.h"
-#include <libmemcached/options/parser.h>
-#include <libmemcached/options/scanner.h>
+#include <iostream>
-int libmemcached_parse(Context*, yyscan_t *);
+#include <libmemcached/options/context.h>
const char *memcached_parse_filename(memcached_st *memc)
{
static memcached_return_t _parse_file_options(memcached_st *self, memcached_string_t *filename)
{
- FILE *fp= fopen(filename->c_str, "r");
+ std::string real_name(filename->c_str, filename->size);
+ FILE *fp= fopen(real_name.c_str(), "r");
if (! fp)
- return memcached_set_errno(self, errno, NULL);
+ {
+ memcached_string_t tmp;
+ tmp.c_str= real_name.c_str();
+ tmp.size= real_name.size();
+ return memcached_set_errno(self, errno, &tmp);
+ }
char buffer[BUFSIZ];
memcached_return_t rc= MEMCACHED_INVALID_ARGUMENTS;
return rc;
}
-memcached_return_t libmemcached_check_configuration(const char *option_string, size_t length, const char *error_buffer, size_t error_buffer_size)
+memcached_return_t libmemcached_check_configuration(const char *option_string, size_t length, char *error_buffer, size_t error_buffer_size)
{
memcached_st memc, *memc_ptr;
memcached_return_t rc;
Context context(option_string, length, self, rc);
- libmemcached_parse(&context, context.scanner);
+ context.start();
return rc;
}
#endif
LIBMEMCACHED_API
- memcached_return_t libmemcached_check_configuration(const char *option_string, size_t length, const char *error_buffer, size_t error_buffer_size);
+ memcached_return_t libmemcached_check_configuration(const char *option_string, size_t length, char *error_buffer, size_t error_buffer_size);
LIBMEMCACHED_API
memcached_return_t memcached_parse_configuration(memcached_st *ptr, const char *option_string, size_t length);
return _end;
}
+ void start();
+
void set_end()
{
rc= MEMCACHED_SUCCESS;
context->rc= MEMCACHED_PARSE_ERROR;
std::string error_message;
+ error_message+= "Error occured while parsing: ";
error_message+= context->begin;
error_message+= " (";
if (context->rc == MEMCACHED_PARSE_ERROR and error)
parser_abort_func(context, error);
}
+int libmemcached_parse(Context*, yyscan_t *);
+void Context::start()
+{
+ libmemcached_parse(this, scanner);
+}
+
%}
%token COMMENT
%token END
+%token ERROR
%token RESET
%token DEBUG
%token INCLUDE
context->set_end();
YYACCEPT;
}
- | RESET
+ | ERROR
{
- memcached_reset(context->memc);
+ context->rc= MEMCACHED_PARSE_USER_ERROR;
+ parser_abort(context, NULL);
}
- | RESET SERVERS
+ | RESET
{
- memcached_servers_reset(context->memc);
+ memcached_reset(context->memc);
}
| DEBUG
{
yydebug= 1;
}
- | DEBUG TRUE
- {
- yydebug= 1;
- }
- | DEBUG FALSE
- {
- yydebug= 0;
- }
- | INCLUDE FILE_PATH
+ | INCLUDE ' ' string
{
- std::cerr << "Got into INCLUDE" << std::endl;
- if ((context->rc= memcached_parse_configure_file(context->memc, $2.c_str, $2.length)) != MEMCACHED_SUCCESS)
+ if ((context->rc= memcached_parse_configure_file(context->memc, $3.c_str, $3.length)) != MEMCACHED_SUCCESS)
{
parser_abort(context, NULL);
}
HOSTNAME_WITH_PORT NUMBER
{
$$.c_str= $1.c_str;
- $$.length= $1.length -1;
+ $$.length= $1.length -1; // -1 to remove :
$$.port= $2;
}
| HOSTNAME
| IPADDRESS_WITH_PORT NUMBER
{
$$.c_str= $1.c_str;
- $$.length= $1.length -1;
+ $$.length= $1.length -1; // -1 to remove :
$$.port= $2;
}
| IPADDRESS
}
| QUOTED_STRING
{
- $$.c_str= $1.c_str +1;
- $$.length= $1.length -2;
+ $$.c_str= $1.c_str +1; // +1 to move use passed the initial quote
+ $$.length= $1.length -1; // -1 removes the end quote
}
;
"--PREFIX-KEY" { yyextra->begin= yytext; return PREFIX_KEY; }
"--PREFIX_KEY" { yyextra->begin= yytext; return PREFIX_KEY; }
-INCLUDE { yyextra->begin= yytext; std::cerr << "Found INCLUDE" << std::endl; return INCLUDE; }
+INCLUDE { yyextra->begin= yytext; return INCLUDE; }
RESET { yyextra->begin= yytext; return RESET; }
DEBUG { yyextra->begin= yytext; return DEBUG; }
SERVERS { yyextra->begin= yytext; return SERVERS; }
END { yyextra->begin= yytext; return END; }
+ERROR { yyextra->begin= yytext; return ERROR; }
TRUE { return TRUE; }
FALSE { return FALSE; }
{
yylex_destroy(scanner);
}
+
return "CONTINUE AUTHENTICATION";
case MEMCACHED_PARSE_ERROR:
return "ERROR OCCURED WHILE PARSING";
+ case MEMCACHED_PARSE_USER_ERROR:
+ return "USER INITIATED ERROR OCCURED WHILE PARSING";
case MEMCACHED_MAXIMUM_RETURN:
return "Gibberish returned!";
default:
2300930706U, 2943759320U, 674306647U, 2400528935U,
54481931U, 4186304426U, 1741088401U, 2979625118U,
4159057246U, 3425930182U, 2593724503U, 1868899624U,
- 1769812374U, 2302537950U, 1110330676U, 3365377466U };
+ 1769812374U, 2302537950U, 1110330676U, 3365377466U,
+ 1336171666U, 3365377466U };
// You have updated the memcache_error messages but not updated docs/tests.
- test_true(MEMCACHED_MAXIMUM_RETURN == 44);
for (rc= MEMCACHED_SUCCESS; rc < MEMCACHED_MAXIMUM_RETURN; rc++)
{
uint32_t hash_val;
}
test_true(values[rc] == hash_val);
}
+ test_true(MEMCACHED_MAXIMUM_RETURN == 45);
return TEST_SUCCESS;
}
return TEST_SUCCESS;
}
+test_return_t test_include_keyword(memcached_st *junk)
+{
+ (void)junk;
+ char buffer[BUFSIZ];
+ memcached_return_t rc;
+ rc= libmemcached_check_configuration(STRING_WITH_LEN("INCLUDE \"support/example.cnf\""), buffer, sizeof(buffer));
+ test_true_got(rc == MEMCACHED_SUCCESS, buffer);
+
+ return TEST_SUCCESS;
+}
+
+test_return_t test_end_keyword(memcached_st *junk)
+{
+ (void)junk;
+ char buffer[BUFSIZ];
+ memcached_return_t rc;
+ rc= libmemcached_check_configuration(STRING_WITH_LEN("--server=localhost END bad keywords"), buffer, sizeof(buffer));
+ test_true_got(rc == MEMCACHED_SUCCESS, buffer);
+
+ return TEST_SUCCESS;
+}
+
+test_return_t test_reset_keyword(memcached_st *junk)
+{
+ (void)junk;
+ char buffer[BUFSIZ];
+ memcached_return_t rc;
+ rc= libmemcached_check_configuration(STRING_WITH_LEN("--server=localhost reset --server=bad.com"), buffer, sizeof(buffer));
+ test_true_got(rc == MEMCACHED_SUCCESS, buffer);
+
+ return TEST_SUCCESS;
+}
+
+test_return_t test_error_keyword(memcached_st *junk)
+{
+ (void)junk;
+ char buffer[BUFSIZ];
+ memcached_return_t rc;
+ rc= libmemcached_check_configuration(STRING_WITH_LEN("--server=localhost ERROR --server=bad.com"), buffer, sizeof(buffer));
+ test_true_got(rc != MEMCACHED_SUCCESS, buffer);
+
+ return TEST_SUCCESS;
+}
+
#define RANDOM_STRINGS 50
test_return_t random_statement_build_test(memcached_st *junk)
{
LIBTEST_INTERNAL_API
test_return_t random_statement_build_test(memcached_st *junk);
+LIBTEST_INTERNAL_API
+test_return_t test_include_keyword(memcached_st *junk);
+
+LIBTEST_INTERNAL_API
+test_return_t test_end_keyword(memcached_st *junk);
+
+LIBTEST_INTERNAL_API
+test_return_t test_reset_keyword(memcached_st *junk);
+
+LIBTEST_INTERNAL_API
+test_return_t test_error_keyword(memcached_st *junk);
+
#ifdef __cplusplus
}
#endif