/* LibMemcached
+ * Copyright (C) 2011-2012 Data Differential, http://datadifferential.com/
* Copyright (C) 2006-2009 Brian Aker
* All rights reserved.
*
* Brian Aker
* Toru Maesaka
*/
-#include <config.h>
+#include <mem_config.h>
#include <cstdio>
#include <cstring>
#include <sys/types.h>
#include <sys/types.h>
-#include <libmemcached/memcached.h>
+#include <libmemcached-1.0/memcached.h>
#include "client_options.h"
#include "utilities.h"
static char *opt_servers= NULL;
static char *stat_args= NULL;
static char *analyze_mode= NULL;
+static char *opt_username;
+static char *opt_passwd;
static struct option long_options[]=
{
{(OPTIONSTRING)"server-version", no_argument, NULL, OPT_SERVER_VERSION},
{(OPTIONSTRING)"servers", required_argument, NULL, OPT_SERVERS},
{(OPTIONSTRING)"analyze", optional_argument, NULL, OPT_ANALYZE},
+ {(OPTIONSTRING)"username", required_argument, NULL, OPT_USERNAME},
+ {(OPTIONSTRING)"password", required_argument, NULL, OPT_PASSWD},
{0, 0, 0, 0},
};
}
static memcached_return_t server_print_callback(const memcached_st *,
- const memcached_server_st *instance,
+ memcached_server_instance_st instance,
void *)
{
std::cerr << memcached_server_name(instance) << ":" << memcached_server_port(instance) <<
- " " << int(instance->major_version) <<
- "." << int(instance->minor_version) <<
- "." << int(instance->micro_version) << std::endl;
+ " " << int(memcached_server_major_version(instance)) <<
+ "." << int(memcached_server_minor_version(instance)) <<
+ "." << int(memcached_server_micro_version(instance)) << std::endl;
return MEMCACHED_SUCCESS;
}
memcached_return_t rc= memcached_server_push(memc, servers);
memcached_server_list_free(servers);
+ if (opt_username and LIBMEMCACHED_WITH_SASL_SUPPORT == 0)
+ {
+ memcached_free(memc);
+ std::cerr << "--username was supplied, but binary was not built with SASL support." << std::endl;
+ return EXIT_FAILURE;
+ }
+
+ if (opt_username)
+ {
+ memcached_return_t ret;
+ if (memcached_failed(ret= memcached_set_sasl_auth_data(memc, opt_username, opt_passwd)))
+ {
+ std::cerr << memcached_last_error_message(memc) << std::endl;
+ memcached_free(memc);
+ return EXIT_FAILURE;
+ }
+ }
+
if (rc != MEMCACHED_SUCCESS and rc != MEMCACHED_SOME_ERRORS)
{
printf("Failure to communicate with servers (%s)\n",
close_stdio();
break;
+ case OPT_USERNAME:
+ opt_username= optarg;
+ opt_binary= true;
+ break;
+
+ case OPT_PASSWD:
+ opt_passwd= optarg;
+ break;
+
case '?':
/* getopt_long already printed an error message. */
exit(1);