memcached_array_free(ptr->prefix_key);
ptr->prefix_key= memcached_strcpy(ptr, (const char *)data, strlen((const char*)data));
- f (! ptr->prefix_key)
+ if (! ptr->prefix_key)
return memcached_set_error(ptr, MEMCACHED_MEMORY_ALLOCATION_FAILURE, NULL);
}
else
MEMCACHED_AUTH_PROBLEM,
MEMCACHED_AUTH_FAILURE,
MEMCACHED_AUTH_CONTINUE,
+ MEMCACHED_PARSE_ERROR,
MEMCACHED_MAXIMUM_RETURN /* Always add new error code before */
} memcached_return_t;
.use_udp= false,
.verify_key= false,
.tcp_keepalive= false,
- .load_from_file= false
-
+ .load_from_file= false,
+ .ping_service= false
}
};
return ptr;
}
+memcached_st *memcached_create_with_options(const char *string, size_t length)
+{
+ memcached_st *self= memcached_create(NULL);
+
+ if (! self)
+ return NULL;
+
+ memcached_parse_options(self, string, length);
+
+ return self;
+}
+
void memcached_reset(memcached_st *ptr)
{
WATCHPOINT_ASSERT(ptr);
bool verify_key:1;
bool tcp_keepalive:1;
bool load_from_file:1;
+ bool ping_service:1;
} flags;
memcached_server_distribution_t distribution;
hashkit_st hashkit;
LIBMEMCACHED_API
memcached_st *memcached_create(memcached_st *ptr);
+LIBMEMCACHED_API
+memcached_st *memcached_create_with_options(const char *string, size_t length);
+
LIBMEMCACHED_API
void memcached_free(memcached_st *ptr);
int libmemcached_parse(type_st *, yyscan_t *);
+memcached_return_t memcached_check_options(const char *option_string, size_t length, const char *error_buffer, size_t error_buffer_size)
+{
+ memcached_st memc;
+ if (! memcached_create(&memc))
+ return MEMCACHED_MEMORY_ALLOCATION_FAILURE;
+
+ memcached_return_t rc= memcached_parse_options(&memc, option_string, length);
+ if (rc != MEMCACHED_SUCCESS && error_buffer && error_buffer_size)
+ {
+ strncpy(error_buffer, error_buffer_size, memcached_last_error_message(&memc));
+ }
+
+ memcached_free(&memc);
+
+ return rc;
+}
+
memcached_return_t memcached_parse_options(memcached_st *self, char const *option_string, size_t length)
{
type_st pp;
libmemcached_lex_destroy(pp.yyscanner);
if (not success)
- return MEMCACHED_INVALID_ARGUMENTS;
+ return memcached_set_error(self, MEMCACHED_PARSE_ERROR, NULL);
return MEMCACHED_SUCCESS;
}
continue;
rc= memcached_parse_options(self, buffer, length);
-
if (rc != MEMCACHED_SUCCESS)
break;
}
extern "C" {
#endif
+LIBMEMCACHED_API
+ memcached_return_t memcached_check_options(const char *option_string, size_t length, const char *error_buffer, size_t error_buffer_size);
+
LIBMEMCACHED_API
memcached_return_t memcached_parse_options(memcached_st *ptr, const char *option_string, size_t length);
return "AUTHENTICATION FAILURE";
case MEMCACHED_AUTH_CONTINUE:
return "CONTINUE AUTHENTICATION";
+ case MEMCACHED_PARSE_ERROR:
+ return "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 };
+ 1769812374U, 2302537950U, 1110330676U, 3365377466U };
// You have updated the memcache_error messages but not updated docs/tests.
- test_true(MEMCACHED_MAXIMUM_RETURN == 43);
+ test_true(MEMCACHED_MAXIMUM_RETURN == 44);
for (rc= MEMCACHED_SUCCESS; rc < MEMCACHED_MAXIMUM_RETURN; rc++)
{
uint32_t hash_val;
{"boolean_options", 0, (test_callback_fn)parser_boolean_options_test },
{"distribtions", 0, (test_callback_fn)parser_distribution_test },
{"hash", 0, (test_callback_fn)parser_hash_test },
+ {"memcached_check_options", 0, (test_callback_fn)memcached_check_options_test },
+ {"memcached_parse_file_options", 0, (test_callback_fn)memcached_parse_file_options_test },
{"number_options", 0, (test_callback_fn)parser_number_options_test },
+ {"prefix_key", 0, (test_callback_fn)parser_key_prefix_test },
{"server", 0, (test_callback_fn)server_test },
{"servers", 0, (test_callback_fn)servers_test },
- {"prefix_key", 0, (test_callback_fn)parser_key_prefix_test },
- {"memcached_parse_file_options", 0, (test_callback_fn)memcached_parse_file_options_test },
{0, 0, (test_callback_fn)0}
};
return TEST_SUCCESS;
}
+
+test_return_t memcached_check_options_test(memcached_st *junk)
+{
+ (void)junk;
+
+ memcached_return_t rc;
+
+ rc= memcached_check_options(STRING_WITH_LEN("--server=localhost"), NULL, 0);
+ test_true(rc == MEMCACHED_SUCCESS);
+
+ rc= memcached_check_options(STRING_WITH_LEN("--dude=localhost"), NULL, 0);
+ test_false(rc == MEMCACHED_SUCCESS);
+ test_true(rc == MEMCACHED_PARSE_ERROR);
+
+ return TEST_SUCCESS;
+}
+
+test_return_t memcached_create_with_options_test(memcached_st *junk)
+{
+ (void)junk;
+
+ memcached_st *memc_ptr;
+ memc_ptr= memcached_create_with_options(STRING_WITH_LEN("--server=localhost"));
+ test_true(memc_ptr);
+ memcached_free(memc_ptr);
+
+ memc_ptr= memcached_create_with_options(STRING_WITH_LEN("--dude=localhost"));
+ test_false(memc_ptr);
+
+ return TEST_SUCCESS;
+}
LIBTEST_INTERNAL_API
test_return_t memcached_parse_file_options_test(memcached_st *junk);
+LIBTEST_INTERNAL_API
+ test_return_t memcached_check_options_test(memcached_st *junk);
+
+LIBTEST_INTERNAL_API
+ test_return_t memcached_create_with_options_test(memcached_st *junk);
+
#ifdef __cplusplus
}
#endif