missing inttypes.h
[awesomized/libmemcached] / src / libmemcachedprotocol / ascii_handler.c
index 83a718288505a342022ee68d67843b3f5734b995..52db79223b7d87ee4285498bfe8041fbeedffed9 100644 (file)
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
+#include <inttypes.h>
 
 static void print_ascii_command(memcached_protocol_client_st *client) {
   if (client->is_verbose) {
     switch (client->ascii_command) {
-    case SET_CMD: fprintf(stderr, "%s:%d SET_CMD\n", __FILE__, __LINE__); break;
+    case SET_CMD:
+      fprintf(stderr, "%s:%d SET_CMD\n", __FILE__, __LINE__);
+      break;
 
-    case ADD_CMD: fprintf(stderr, "%s:%d ADD_CMD\n", __FILE__, __LINE__); break;
+    case ADD_CMD:
+      fprintf(stderr, "%s:%d ADD_CMD\n", __FILE__, __LINE__);
+      break;
 
-    case REPLACE_CMD: fprintf(stderr, "%s:%d REPLACE_CMD\n", __FILE__, __LINE__); break;
+    case REPLACE_CMD:
+      fprintf(stderr, "%s:%d REPLACE_CMD\n", __FILE__, __LINE__);
+      break;
 
-    case CAS_CMD: fprintf(stderr, "%s:%d CAS_CMD\n", __FILE__, __LINE__); break;
+    case CAS_CMD:
+      fprintf(stderr, "%s:%d CAS_CMD\n", __FILE__, __LINE__);
+      break;
 
-    case APPEND_CMD: fprintf(stderr, "%s:%d APPEND_CMD\n", __FILE__, __LINE__); break;
+    case APPEND_CMD:
+      fprintf(stderr, "%s:%d APPEND_CMD\n", __FILE__, __LINE__);
+      break;
 
-    case PREPEND_CMD: fprintf(stderr, "%s:%d PREPEND_CMD\n", __FILE__, __LINE__); break;
+    case PREPEND_CMD:
+      fprintf(stderr, "%s:%d PREPEND_CMD\n", __FILE__, __LINE__);
+      break;
 
-    case DELETE_CMD: fprintf(stderr, "%s:%d DELETE_CMD\n", __FILE__, __LINE__); break;
+    case DELETE_CMD:
+      fprintf(stderr, "%s:%d DELETE_CMD\n", __FILE__, __LINE__);
+      break;
 
-    case INCR_CMD: /* FALLTHROUGH */ fprintf(stderr, "%s:%d INCR_CMD\n", __FILE__, __LINE__); break;
+    case INCR_CMD: /* FALLTHROUGH */
+      fprintf(stderr, "%s:%d INCR_CMD\n", __FILE__, __LINE__);
+      break;
 
-    case DECR_CMD: fprintf(stderr, "%s:%d DECR_CMD\n", __FILE__, __LINE__); break;
+    case DECR_CMD:
+      fprintf(stderr, "%s:%d DECR_CMD\n", __FILE__, __LINE__);
+      break;
 
-    case STATS_CMD: fprintf(stderr, "%s:%d STATS_CMD\n", __FILE__, __LINE__); break;
+    case STATS_CMD:
+      fprintf(stderr, "%s:%d STATS_CMD\n", __FILE__, __LINE__);
+      break;
 
-    case FLUSH_ALL_CMD: fprintf(stderr, "%s:%d FLUSH_ALL_CMD\n", __FILE__, __LINE__); break;
+    case FLUSH_ALL_CMD:
+      fprintf(stderr, "%s:%d FLUSH_ALL_CMD\n", __FILE__, __LINE__);
+      break;
 
-    case VERSION_CMD: fprintf(stderr, "%s:%d VERSION_CMD\n", __FILE__, __LINE__); break;
+    case VERSION_CMD:
+      fprintf(stderr, "%s:%d VERSION_CMD\n", __FILE__, __LINE__);
+      break;
 
-    case QUIT_CMD: fprintf(stderr, "%s:%d QUIT_CMD\n", __FILE__, __LINE__); break;
+    case QUIT_CMD:
+      fprintf(stderr, "%s:%d QUIT_CMD\n", __FILE__, __LINE__);
+      break;
 
-    case VERBOSITY_CMD: fprintf(stderr, "%s:%d VERBOSITY_CMD\n", __FILE__, __LINE__); break;
+    case VERBOSITY_CMD:
+      fprintf(stderr, "%s:%d VERBOSITY_CMD\n", __FILE__, __LINE__);
+      break;
 
-    case GET_CMD: fprintf(stderr, "%s:%d GET_CMD\n", __FILE__, __LINE__); break;
+    case GET_CMD:
+      fprintf(stderr, "%s:%d GET_CMD\n", __FILE__, __LINE__);
+      break;
 
-    case GETS_CMD: fprintf(stderr, "%s:%d GETS_CMD\n", __FILE__, __LINE__); break;
+    case GETS_CMD:
+      fprintf(stderr, "%s:%d GETS_CMD\n", __FILE__, __LINE__);
+      break;
 
     default:
-    case UNKNOWN_CMD: fprintf(stderr, "%s:%d UNKNOWN_CMD\n", __FILE__, __LINE__); break;
+    case UNKNOWN_CMD:
+      fprintf(stderr, "%s:%d UNKNOWN_CMD\n", __FILE__, __LINE__);
+      break;
     }
   }
 }
@@ -107,7 +142,7 @@ ascii_raw_response_handler(memcached_protocol_client_st *client, const char *tex
     return PROTOCOL_BINARY_RESPONSE_EINTERNAL;
   }
 
-  assert(client->output != NULL);
+  assert(client->output);
 #if 0
   if (client->output == NULL)
   {
@@ -251,7 +286,7 @@ static protocol_binary_response_status ascii_stat_response_handler(const void *c
                                                                    uint32_t bodylen) {
   memcached_protocol_client_st *client = (void *) cookie;
 
-  if (key != NULL) {
+  if (key) {
     ascii_raw_response_handler(client, "STAT ");
     client->root->spool(client, key, keylen);
     ascii_raw_response_handler(client, " ");
@@ -445,7 +480,7 @@ static void process_arithmetic(memcached_protocol_client_st *client, char **toke
   uint64_t result;
   errno = 0;
   uint64_t delta = strtoull(tokens[2], NULL, 10);
-  if (errno != 0) {
+  if (errno) {
     return; // Error
   }
 
@@ -524,7 +559,7 @@ static void process_flush(memcached_protocol_client_st *client, char **tokens, i
   if (ntokens == 2) {
     errno = 0;
     timeout = (uint32_t) strtoul(tokens[1], NULL, 10);
-    if (errno != 0) {
+    if (errno) {
       return; // Error
     }
   }
@@ -564,21 +599,21 @@ static inline int process_storage_command(memcached_protocol_client_st *client,
 
   errno = 0;
   uint32_t flags = (uint32_t) strtoul(tokens[2], NULL, 10);
-  if (errno != 0) {
+  if (errno) {
     /* return error */
     ascii_raw_response_handler(client, "CLIENT_ERROR: bad key\r\n");
     return -1;
   }
 
   uint32_t timeout = (uint32_t) strtoul(tokens[3], NULL, 10);
-  if (errno != 0) {
+  if (errno) {
     /* return error */
     ascii_raw_response_handler(client, "CLIENT_ERROR: bad key\r\n");
     return -1;
   }
 
   unsigned long nbytes = strtoul(tokens[4], NULL, 10);
-  if (errno != 0) {
+  if (errno) {
     /* return error */
     ascii_raw_response_handler(client, "CLIENT_ERROR: bad key\r\n");
     return -1;
@@ -608,7 +643,7 @@ static inline int process_storage_command(memcached_protocol_client_st *client,
   case CAS_CMD:
     errno = 0;
     cas = strtoull(tokens[5], NULL, 10);
-    if (errno != 0) {
+    if (errno) {
       /* return error */
       ascii_raw_response_handler(client, "CLIENT_ERROR: bad key\r\n");
       return -1;
@@ -639,7 +674,8 @@ static inline int process_storage_command(memcached_protocol_client_st *client,
   case QUIT_CMD:
   case VERBOSITY_CMD:
   case UNKNOWN_CMD:
-  default: abort(); /* impossible */
+  default:
+    abort(); /* impossible */
   }
 
   if (rval == PROTOCOL_BINARY_RESPONSE_SUCCESS) {
@@ -775,7 +811,7 @@ memcached_ascii_protocol_process_data(memcached_protocol_client_st *client, ssiz
     client->ascii_command = ascii_to_cmd(ptr, (size_t)(*length));
 
     /* we got all data available, execute the callback! */
-    if (client->root->callback->pre_execute != NULL) {
+    if (client->root->callback->pre_execute) {
       client->root->callback->pre_execute(client, NULL);
     }
 
@@ -784,7 +820,7 @@ memcached_ascii_protocol_process_data(memcached_protocol_client_st *client, ssiz
      * just handle them immediately
      */
     if (client->ascii_command == GET_CMD || client->ascii_command == GETS_CMD) {
-      if (client->root->callback->interface.v1.get != NULL) {
+      if (client->root->callback->interface.v1.get) {
         ascii_process_gets(client, ptr, end);
       } else {
         ascii_raw_response_handler(client, "SERVER_ERROR: Command not implemented\n");
@@ -807,15 +843,21 @@ memcached_ascii_protocol_process_data(memcached_protocol_client_st *client, ssiz
 
       print_ascii_command(client);
       switch (client->ascii_command) {
-      case SET_CMD: error = process_set_command(client, tokens, ntokens, ptr, &end, *length); break;
+      case SET_CMD:
+        error = process_set_command(client, tokens, ntokens, ptr, &end, *length);
+        break;
 
-      case ADD_CMD: error = process_add_command(client, tokens, ntokens, ptr, &end, *length); break;
+      case ADD_CMD:
+        error = process_add_command(client, tokens, ntokens, ptr, &end, *length);
+        break;
 
       case REPLACE_CMD:
         error = process_replace_command(client, tokens, ntokens, ptr, &end, *length);
         break;
 
-      case CAS_CMD: error = process_cas_command(client, tokens, ntokens, ptr, &end, *length); break;
+      case CAS_CMD:
+        error = process_cas_command(client, tokens, ntokens, ptr, &end, *length);
+        break;
 
       case APPEND_CMD:
         error = process_append_command(client, tokens, ntokens, ptr, &end, *length);
@@ -825,10 +867,14 @@ memcached_ascii_protocol_process_data(memcached_protocol_client_st *client, ssiz
         error = process_prepend_command(client, tokens, ntokens, ptr, &end, *length);
         break;
 
-      case DELETE_CMD: process_delete(client, tokens, ntokens); break;
+      case DELETE_CMD:
+        process_delete(client, tokens, ntokens);
+        break;
 
       case INCR_CMD: /* FALLTHROUGH */
-      case DECR_CMD: process_arithmetic(client, tokens, ntokens); break;
+      case DECR_CMD:
+        process_arithmetic(client, tokens, ntokens);
+        break;
 
       case STATS_CMD:
         if (client->mute) {
@@ -839,7 +885,9 @@ memcached_ascii_protocol_process_data(memcached_protocol_client_st *client, ssiz
         }
         break;
 
-      case FLUSH_ALL_CMD: process_flush(client, tokens, ntokens); break;
+      case FLUSH_ALL_CMD:
+        process_flush(client, tokens, ntokens);
+        break;
 
       case VERSION_CMD:
         if (client->mute) {
@@ -853,7 +901,7 @@ memcached_ascii_protocol_process_data(memcached_protocol_client_st *client, ssiz
         if (ntokens != 1 || client->mute) {
           send_command_usage(client);
         } else {
-          if (client->root->callback->interface.v1.quit != NULL) {
+          if (client->root->callback->interface.v1.quit) {
             client->root->callback->interface.v1.quit(client);
           }
 
@@ -869,7 +917,9 @@ memcached_ascii_protocol_process_data(memcached_protocol_client_st *client, ssiz
         }
         break;
 
-      case UNKNOWN_CMD: send_command_usage(client); break;
+      case UNKNOWN_CMD:
+        send_command_usage(client);
+        break;
 
       case GET_CMD:
       case GETS_CMD:
@@ -885,7 +935,7 @@ memcached_ascii_protocol_process_data(memcached_protocol_client_st *client, ssiz
       }
     }
 
-    if (client->root->callback->post_execute != NULL) {
+    if (client->root->callback->post_execute) {
       client->root->callback->post_execute(client, NULL);
     }