X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=clients%2Futilities.c;h=92987471558d60f130020faf800f42740ccd64fd;hb=7f1777bbeaa41f71567f20350cb2555f2d9466da;hp=ef1e60f37c131b157feccd1ac61f4fd5fa94d0ac;hpb=475f477dab6dfc5e4f018d1ecfb128c37e2c44a0;p=m6w6%2Flibmemcached diff --git a/clients/utilities.c b/clients/utilities.c index ef1e60f3..92987471 100644 --- a/clients/utilities.c +++ b/clients/utilities.c @@ -8,8 +8,8 @@ * Summary: * */ +#include "config.h" -#include "libmemcached/common.h" #include #include #include @@ -60,6 +60,8 @@ static const char *lookup_help(memcached_options option) case OPT_UDP: return("Use UDP protocol when communicating with server."); case OPT_USERNAME: return "Username to use for SASL authentication"; case OPT_PASSWD: return "Password to use for SASL authentication"; + case OPT_FILE: return "Path to file in which to save result"; + case OPT_STAT_ARGS: return "Argument for statistics"; default: WATCHPOINT_ASSERT(0); }; @@ -69,9 +71,10 @@ static const char *lookup_help(memcached_options option) void help_command(const char *command_name, const char *description, const struct option *long_options, - memcached_programs_help_st *options __attribute__((unused))) + memcached_programs_help_st *options) { unsigned int x; + (void)options; printf("%s v%u.%u\n\n", command_name, 1U, 0U); printf("\t%s\n\n", description); @@ -124,10 +127,10 @@ void process_hash_option(memcached_st *memc, char *opt_hash) } } +#ifdef LIBMEMCACHED_WITH_SASL_SUPPORT static char *username; static char *passwd; -#ifdef LIBMEMCACHED_WITH_SASL_SUPPORT static int get_username(void *context, int id, const char **result, unsigned int *len) { @@ -146,7 +149,7 @@ static int get_password(sasl_conn_t *conn, void *context, int id, sasl_secret_t **psecret) { (void)context; - static sasl_secret_t* x; + static sasl_secret_t* ptr; if (!conn || ! psecret || id != SASL_CB_PASS) return SASL_BADPARAM; @@ -158,14 +161,15 @@ static int get_password(sasl_conn_t *conn, void *context, int id, } size_t len= strlen(passwd); - x = realloc(x, sizeof(sasl_secret_t) + len); - if (!x) + ptr= malloc(sizeof(sasl_secret_t) + len +1); + if (! ptr) return SASL_NOMEM; - x->len = len; - strcpy((void *)x->data, passwd); + ptr->len= len; + memcpy(ptr->data, passwd, len); + ptr->data[len]= 0; - *psecret = x; + *psecret= ptr; return SASL_OK; } @@ -201,7 +205,7 @@ bool initialize_sasl(memcached_st *memc, char *user, char *password) #else (void)memc; (void)user; - (void)passwd; + (void)password; #endif return true; @@ -209,8 +213,21 @@ bool initialize_sasl(memcached_st *memc, char *user, char *password) void shutdown_sasl(void) { -#if LIBMEMCACHED_WITH_SASL_SUPPORT +#ifdef LIBMEMCACHED_WITH_SASL_SUPPORT if (username != NULL || passwd != NULL) sasl_done(); #endif } + +void initialize_sockets(void) +{ + /* Define the function for all platforms to avoid #ifdefs in each program */ +#ifdef WIN32 + WSADATA wsaData; + if (WSAStartup(MAKEWORD(2,0), &wsaData) != 0) + { + fprintf(stderr, "Socket Initialization Error. Program aborted\n"); + exit(EXIT_FAILURE); + } +#endif +}