Update cinttype for older CentOS/RHEL versions.
[m6w6/libmemcached] / libmemcached / csl / context.h
index ce7b0316a124c3ebe4d2fdf84e080e4ac7794f1a..77fac219bdd79ed2ecca1fd634af9e76c5ca5935 100644 (file)
 
 #pragma once
 
-#include <libmemcached/common.h>
+#include <libmemcached/csl/common.h>
+#include <libmemcached/csl/parser.h>
 
 class Context
 {
 public:
   Context(const char *option_string, size_t option_string_length, memcached_st *memc_arg,
           memcached_return_t &rc_arg) :
+    previous_token(END),
     scanner(NULL),
     begin(NULL),
     pos(0),
     memc(NULL),
     rc(rc_arg),
     _is_server(false),
-    _end(false)
+    _end(false),
+    _has_hash(false)
   {
     _hostname[0]= 0;
     buf= option_string;
@@ -73,6 +76,8 @@ public:
     _end= true;
   }
 
+  bool set_hash(memcached_hash_t hash);
+
   void set_server()
   {
     _is_server= true;
@@ -83,55 +88,27 @@ public:
     _is_server= false;
   }
 
-  bool is_server()
+  bool is_server() const
   {
     return _is_server;
   }
 
-  const char *set_hostname(const char *str, size_t size)
-  {
-    size_t copy_length= (size_t)NI_MAXHOST > size ? size : (size_t)NI_MAXHOST;
-    memcpy(_hostname, str, copy_length);
-    _hostname[copy_length]= 0;
+  const char *set_hostname(const char *str, size_t size);
 
-    return _hostname;
-  }
-
-  const char *hostname()
+  const char *hostname() const
   {
     return _hostname;
   }
 
-  void abort(const char *error)
-  {
-    if (rc == MEMCACHED_SUCCESS)
-      rc= MEMCACHED_PARSE_ERROR;
-
-    memcached_string_st *error_string= memcached_string_create(memc, NULL, 1024);
-    memcached_string_append(error_string, memcached_literal_param("Error occured while parsing: "));
-    memcached_string_append(error_string, memcached_string_make_from_cstr(begin));
-    memcached_string_append(error_string, memcached_literal_param(" ("));
-
-    if (rc == MEMCACHED_PARSE_ERROR and error)
-    {
-      memcached_string_append(error_string, memcached_string_make_from_cstr(error));
-    }
-    else
-    {
-      memcached_string_append(error_string, memcached_string_make_from_cstr(memcached_strerror(NULL, rc)));
-    }
-    memcached_string_append(error_string, memcached_literal_param(")"));
-
-    memcached_set_error(*memc, rc, MEMCACHED_AT, memcached_string_value(error_string), memcached_string_length(error_string));
-
-    memcached_string_free(error_string);
-  }
+  void abort(const char *, yytokentype, const char *);
+  void error(const char *, yytokentype, const char* );
 
   ~Context()
   {
     destroy_scanner();
   }
 
+  yytokentype previous_token;
   void *scanner;
   const char *buf;
   const char *begin;
@@ -148,4 +125,5 @@ private:
   bool _is_server;
   bool _end;
   char _hostname[NI_MAXHOST];
+  bool _has_hash;
 };