Merge in trunk
[m6w6/libmemcached] / clients / memcat.cc
index 12df34799a160b16c066999c4e8937d915fd427f..ab482e5d6ad57549b17f06d0352b3b132562f1b4 100644 (file)
@@ -9,13 +9,13 @@
  *
  */
 
-#include "config.h"
+#include <config.h>
 
-#include <stdio.h>
-#include <inttypes.h>
-#include <string.h>
-#include <unistd.h>
+#include <cstdio>
+#include <cstring>
 #include <getopt.h>
+#include <iostream>
+#include <unistd.h>
 #include <libmemcached/memcached.h>
 
 #include "utilities.h"
@@ -73,12 +73,24 @@ int main(int argc, char *argv[])
   memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL,
                          (uint64_t)opt_binary);
 
-  if (!initialize_sasl(memc, opt_username, opt_passwd))
+  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;
+    }
+  }
+
   while (optind < argc)
   {
     string= memcached_get(memc, argv[optind], strlen(argv[optind]),
@@ -162,8 +174,6 @@ int main(int argc, char *argv[])
   if (opt_hash)
     free(opt_hash);
 
-  shutdown_sasl();
-
   return return_code;
 }
 
@@ -182,6 +192,7 @@ void options_parse(int argc, char *argv[])
     {
       {(OPTIONSTRING)"version", no_argument, NULL, OPT_VERSION},
       {(OPTIONSTRING)"help", no_argument, NULL, OPT_HELP},
+      {(OPTIONSTRING)"quiet", no_argument, NULL, OPT_QUIET},
       {(OPTIONSTRING)"verbose", no_argument, &opt_verbose, OPT_VERBOSE},
       {(OPTIONSTRING)"debug", no_argument, &opt_verbose, OPT_DEBUG},
       {(OPTIONSTRING)"servers", required_argument, NULL, OPT_SERVERS},
@@ -232,6 +243,11 @@ void options_parse(int argc, char *argv[])
     case OPT_FILE:
       opt_file= optarg;
       break;
+
+    case OPT_QUIET:
+      close_stdio();
+      break;
+
     case '?':
       /* getopt_long already printed an error message. */
       exit(1);