*
*/
-#include "libmemcached/common.h"
+#include "config.h"
+
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <errno.h>
#include <strings.h>
#include <string.h>
+#include <sys/types.h>
+#include <stdlib.h>
+#include <limits.h>
+
#include <libmemcached/memcached.h>
static int opt_method= OPT_SET;
static uint32_t opt_flags= 0;
static time_t opt_expires= 0;
+static char *opt_username;
+static char *opt_passwd;
static long strtol_wrapper(const char *nptr, int base, bool *error)
{
|| (errno != 0 && val == 0))
{
*error= true;
- return 0;
+ return EXIT_SUCCESS;
}
if (endptr == nptr)
{
*error= true;
- return 0;
+ return EXIT_SUCCESS;
}
*error= false;
int return_code= 0;
options_parse(argc, argv);
+ initialize_sockets();
memc= memcached_create(NULL);
process_hash_option(memc, opt_hash);
memcached_server_list_free(servers);
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL,
(uint64_t)opt_binary);
+ if (!initialize_sasl(memc, opt_username, opt_passwd))
+ {
+ memcached_free(memc);
+ return EXIT_FAILURE;
+ }
while (optind < argc)
{
{
fprintf(stderr, "memcp: %s: memcache error %s",
ptr, memcached_strerror(memc, rc));
- if (memc->cached_errno)
- fprintf(stderr, " system error %s", strerror(memc->cached_errno));
+ if (memcached_last_error_errno(memc))
+ fprintf(stderr, " system error %s", strerror(memcached_last_error_errno(memc)));
fprintf(stderr, "\n");
return_code= -1;
free(opt_servers);
if (opt_hash)
free(opt_hash);
+ shutdown_sasl();
return return_code;
}
{(OPTIONSTRING)"replace", no_argument, NULL, OPT_REPLACE},
{(OPTIONSTRING)"hash", required_argument, NULL, OPT_HASH},
{(OPTIONSTRING)"binary", no_argument, NULL, OPT_BINARY},
+ {(OPTIONSTRING)"username", required_argument, NULL, OPT_USERNAME},
+ {(OPTIONSTRING)"password", required_argument, NULL, OPT_PASSWD},
{0, 0, 0, 0},
};
case OPT_HASH:
opt_hash= strdup(optarg);
break;
- case '?':
+ case OPT_USERNAME:
+ opt_username= optarg;
+ break;
+ case OPT_PASSWD:
+ opt_passwd= optarg;
+ break;
+ case '?':
/* getopt_long already printed an error message. */
exit(1);
default: