Update to clean up test case.
[m6w6/libmemcached] / clients / memcp.c
index dd8aba9ac907e9001d6e823374e7cf498520af8f..df3ca77e315e46fa205955fcd880c11eee697af3 100644 (file)
@@ -9,7 +9,8 @@
  *
  */
 
-#include "libmemcached/common.h"
+#include "config.h"
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <inttypes.h>
@@ -41,6 +42,8 @@ static char *opt_hash= NULL;
 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)
 {
@@ -52,7 +55,7 @@ static long strtol_wrapper(const char *nptr, int base, bool *error)
 
   /* Check for various possible errors */
 
-  if ((errno == ERANGE && (val == LONG_MAX || val == LONG_MIN))
+  if ((errno == ERANGE && (val == INTMAX_MAX || val == INTMAX_MIN))
       || (errno != 0 && val == 0))
   {
     *error= true;
@@ -106,6 +109,11 @@ int main(int argc, char *argv[])
   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 1;
+  }
 
   while (optind < argc)
   {
@@ -193,6 +201,7 @@ int main(int argc, char *argv[])
     free(opt_servers);
   if (opt_hash)
     free(opt_hash);
+  shutdown_sasl();
 
   return return_code;
 }
@@ -221,6 +230,8 @@ static void options_parse(int argc, char *argv[])
       {(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},
     };
 
@@ -285,7 +296,13 @@ static void options_parse(int argc, char *argv[])
     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: