summaryrefslogtreecommitdiff
path: root/ndb/include/util
diff options
context:
space:
mode:
Diffstat (limited to 'ndb/include/util')
-rw-r--r--ndb/include/util/Base64.hpp26
-rw-r--r--ndb/include/util/BaseString.hpp260
-rw-r--r--ndb/include/util/Bitmask.hpp755
-rw-r--r--ndb/include/util/File.hpp206
-rw-r--r--ndb/include/util/InputStream.hpp48
-rw-r--r--ndb/include/util/NdbAutoPtr.hpp49
-rw-r--r--ndb/include/util/NdbOut.hpp132
-rw-r--r--ndb/include/util/NdbSqlUtil.hpp357
-rw-r--r--ndb/include/util/NdbString.h48
-rw-r--r--ndb/include/util/OutputStream.hpp67
-rw-r--r--ndb/include/util/Parser.hpp290
-rw-r--r--ndb/include/util/Properties.hpp246
-rw-r--r--ndb/include/util/SimpleProperties.hpp290
-rw-r--r--ndb/include/util/SocketServer.hpp131
-rw-r--r--ndb/include/util/UtilBuffer.hpp90
-rw-r--r--ndb/include/util/Vector.hpp289
-rw-r--r--ndb/include/util/getarg.h115
-rw-r--r--ndb/include/util/md5_hash.hpp25
-rw-r--r--ndb/include/util/random.h84
-rw-r--r--ndb/include/util/socket_io.h40
-rw-r--r--ndb/include/util/uucode.h36
-rw-r--r--ndb/include/util/version.h50
22 files changed, 3634 insertions, 0 deletions
diff --git a/ndb/include/util/Base64.hpp b/ndb/include/util/Base64.hpp
new file mode 100644
index 00000000000..a8678da946c
--- /dev/null
+++ b/ndb/include/util/Base64.hpp
@@ -0,0 +1,26 @@
+/* Copyright (C) 2003 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+#ifndef __BASE64_HPP_INCLUDED__
+#define __BASE64_HPP_INCLUDED__
+
+#include <UtilBuffer.hpp>
+#include <BaseString.hpp>
+
+int base64_encode(UtilBuffer &src, BaseString &dst);
+int base64_decode(BaseString &src, UtilBuffer &dst);
+
+#endif /* !__BASE64_HPP_INCLUDED__ */
diff --git a/ndb/include/util/BaseString.hpp b/ndb/include/util/BaseString.hpp
new file mode 100644
index 00000000000..a88bd97ffc5
--- /dev/null
+++ b/ndb/include/util/BaseString.hpp
@@ -0,0 +1,260 @@
+/* Copyright (C) 2003 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+#ifndef __UTIL_BASESTRING_HPP_INCLUDED__
+#define __UTIL_BASESTRING_HPP_INCLUDED__
+
+#include <ctype.h>
+#include <stdlib.h>
+
+#include <Vector.hpp>
+
+/**
+ * @class BaseString
+ * @brief Null terminated strings
+ */
+class BaseString {
+public:
+ /** @brief Constructs an empty string */
+ BaseString();
+
+ /** @brief Constructs a copy of a char * */
+ BaseString(const char* s);
+
+ /** @brief Constructs a copy of another BaseString */
+ BaseString(const BaseString& str);
+
+ /** @brief Destructor */
+ ~BaseString();
+
+ /** @brief Returns a C-style string */
+ const char* c_str() const;
+
+ /** @brief Returns the length of the string */
+ unsigned length() const;
+
+ /** @brief Checks if the string is empty */
+ bool empty() const;
+
+ /** @brief Convert to uppercase */
+ void ndb_toupper();
+
+ /** @brief Convert to lowercase */
+ void ndb_tolower();
+
+ /** @brief Assigns from a char * */
+ BaseString& assign(const char* s);
+
+ /** @brief Assigns from another BaseString */
+ BaseString& assign(const BaseString& str);
+
+ /** @brief Assigns from char *s, with maximum length n */
+ BaseString& assign(const char* s, size_t n);
+
+ /** @brief Assigns from another BaseString, with maximum length n */
+ BaseString& assign(const BaseString& str, size_t n);
+
+ /**
+ * Assings from a Vector of BaseStrings, each Vector entry
+ * separated by separator.
+ *
+ * @param vector Vector of BaseStrings to append
+ * @param separator Separation between appended strings
+ */
+ BaseString& assign(const Vector<BaseString> &vector,
+ const BaseString &separator = BaseString(" "));
+
+ /** @brief Appends a char * to the end */
+ BaseString& append(const char* s);
+
+ /** @brief Appends a char to the end */
+ BaseString& append(char c);
+
+ /** @brief Appends another BaseString to the end */
+ BaseString& append(const BaseString& str);
+
+ /**
+ * Appends a Vector of BaseStrings to the end, each Vector entry
+ * separated by separator.
+ *
+ * @param vector Vector of BaseStrings to append
+ * @param separator Separation between appended strings
+ */
+ BaseString& append(const Vector<BaseString> &vector,
+ const BaseString &separator = BaseString(" "));
+
+ /** @brief Assigns from a format string a la printf() */
+ BaseString& assfmt(const char* ftm, ...);
+
+ /** @brief Appends a format string a la printf() to the end */
+ BaseString& appfmt(const char* ftm, ...);
+
+ /**
+ * Split a string into a vector of strings. Separate the string where
+ * any character included in separator exists.
+ * Maximally maxSize entries are added to the vector, if more separators
+ * exist in the string, the remainder of the string will be appended
+ * to the last entry in the vector.
+ * The vector will not be cleared, so any existing strings in the
+ * vector will remain.
+ *
+ * @param separator characters separating the entries
+ * @param vector where the separated strings will be stored
+ * @param maximum number of strings extracted
+ *
+ * @returns the number of string added to the vector
+ */
+ int split(Vector<BaseString> &vector,
+ const BaseString &separator = BaseString(" "),
+ int maxSize = -1) const;
+
+ /**
+ * Returns the index of the first occurance of the character c.
+ *
+ * @params c character to look for
+ * @returns index of character, of -1 if no character found
+ */
+ ssize_t indexOf(char c);
+
+ /**
+ * Returns the index of the last occurance of the character c.
+ *
+ * @params c character to look for
+ * @returns index of character, of -1 if no character found
+ */
+ ssize_t lastIndexOf(char c);
+
+ /**
+ * Returns a subset of a string
+ *
+ * @param start index of first character
+ * @param stop index of last character
+ * @return a new string
+ */
+ BaseString substr(ssize_t start, ssize_t stop = -1);
+
+ /**
+ * @brief Assignment operator
+ */
+ BaseString& operator=(const BaseString& str);
+
+ /** @brief Compare two strings */
+ bool operator<(const BaseString& str) const;
+ /** @brief Are two strings equal? */
+ bool operator==(const BaseString& str) const;
+ /** @brief Are two strings equal? */
+ bool operator==(const char *str) const;
+ /** @brief Are two strings not equal? */
+ bool operator!=(const BaseString& str) const;
+ /** @brief Are two strings not equal? */
+ bool operator!=(const char *str) const;
+
+ /**
+ * Trim string from <i>delim</i>
+ */
+ BaseString& trim(const char * delim = " \t");
+
+ /**
+ * Return c-array with strings suitable for execve
+ * When whitespace is detected, the characters '"' and '\' are honored,
+ * to make it possible to give arguments containing whitespace.
+ * The semantics of '"' and '\' match that of most Unix shells.
+ */
+ static char** argify(const char *argv0, const char *src);
+
+ /**
+ * Trim string from <i>delim</i>
+ */
+ static char* trim(char * src, const char * delim = " \t");
+private:
+ char* m_chr;
+ unsigned m_len;
+};
+
+inline const char*
+BaseString::c_str() const
+{
+ return m_chr;
+}
+
+inline unsigned
+BaseString::length() const
+{
+ return m_len;
+}
+
+inline bool
+BaseString::empty() const
+{
+ return m_len == 0;
+}
+
+inline void
+BaseString::ndb_toupper() {
+ for(unsigned i = 0; i < length(); i++)
+ m_chr[i] = ::toupper(m_chr[i]);
+}
+
+inline void
+BaseString::ndb_tolower() {
+ for(unsigned i = 0; i < length(); i++)
+ m_chr[i] = ::tolower(m_chr[i]);
+}
+
+inline bool
+BaseString::operator<(const BaseString& str) const
+{
+ return strcmp(m_chr, str.m_chr) < 0;
+}
+
+inline bool
+BaseString::operator==(const BaseString& str) const
+{
+ return strcmp(m_chr, str.m_chr) == 0;
+}
+
+inline bool
+BaseString::operator==(const char *str) const
+{
+ return strcmp(m_chr, str) == 0;
+}
+
+inline bool
+BaseString::operator!=(const BaseString& str) const
+{
+ return strcmp(m_chr, str.m_chr) != 0;
+}
+
+inline bool
+BaseString::operator!=(const char *str) const
+{
+ return strcmp(m_chr, str) != 0;
+}
+
+inline BaseString&
+BaseString::assign(const BaseString& str)
+{
+ return assign(str.m_chr);
+}
+
+inline BaseString&
+BaseString::assign(const Vector<BaseString> &vector,
+ const BaseString &separator) {
+ assign("");
+ return append(vector, separator);
+}
+
+#endif /* !__UTIL_BASESTRING_HPP_INCLUDED__ */
diff --git a/ndb/include/util/Bitmask.hpp b/ndb/include/util/Bitmask.hpp
new file mode 100644
index 00000000000..1f95d62bcb6
--- /dev/null
+++ b/ndb/include/util/Bitmask.hpp
@@ -0,0 +1,755 @@
+/* Copyright (C) 2003 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+#ifndef NDB_BITMASK_H
+#define NDB_BITMASK_H
+
+#include <ndb_types.h>
+#include <NdbConstant.hpp>
+
+#ifndef NDB_ASSERT
+#include <stdio.h>
+#include <stdlib.h>
+#define NDB_ASSERT(x, s) \
+ do { if (!(x)) { printf("%s\n", s); abort(); } } while (0)
+#endif
+
+/**
+ * Bitmask implementation. Size is given explicitly
+ * (as first argument). All methods are static.
+ */
+class BitmaskImpl {
+public:
+ STATIC_CONST( NotFound = (unsigned)-1 );
+
+ /**
+ * get - Check if bit n is set.
+ */
+ static bool get(unsigned size, const Uint32 data[], unsigned n);
+
+ /**
+ * set - Set bit n to given value (true/false).
+ */
+ static void set(unsigned size, Uint32 data[], unsigned n, bool value);
+
+ /**
+ * set - Set bit n.
+ */
+ static void set(unsigned size, Uint32 data[], unsigned n);
+
+ /**
+ * set - Set all bits.
+ */
+ static void set(unsigned size, Uint32 data[]);
+
+ /**
+ * assign - Set all bits in <em>dst</em> to corresponding in <em>src/<em>
+ */
+ static void assign(unsigned size, Uint32 dst[], const Uint32 src[]);
+
+ /**
+ * clear - Clear bit n.
+ */
+ static void clear(unsigned size, Uint32 data[], unsigned n);
+
+ /**
+ * clear - Clear all bits.
+ */
+ static void clear(unsigned size, Uint32 data[]);
+
+ /**
+ * isclear - Check if all bits are clear. This is faster
+ * than checking count() == 0.
+ */
+ static bool isclear(unsigned size, const Uint32 data[]);
+
+ /**
+ * count - Count number of set bits.
+ */
+ static unsigned count(unsigned size, const Uint32 data[]);
+
+ /**
+ * find - Find first set bit, starting at given position.
+ * Returns NotFound when not found.
+ */
+ static unsigned find(unsigned size, const Uint32 data[], unsigned n);
+
+ /**
+ * equal - Bitwise equal.
+ */
+ static bool equal(unsigned size, const Uint32 data[], const Uint32 data2[]);
+
+ /**
+ * bitOR - Bitwise (x | y) into first operand.
+ */
+ static void bitOR(unsigned size, Uint32 data[], const Uint32 data2[]);
+
+ /**
+ * bitAND - Bitwise (x & y) into first operand.
+ */
+ static void bitAND(unsigned size, Uint32 data[], const Uint32 data2[]);
+
+ /**
+ * bitANDC - Bitwise (x & ~y) into first operand.
+ */
+ static void bitANDC(unsigned size, Uint32 data[], const Uint32 data2[]);
+
+ /**
+ * bitXOR - Bitwise (x ^ y) into first operand.
+ */
+ static void bitXOR(unsigned size, Uint32 data[], const Uint32 data2[]);
+
+ /**
+ * contains - Check if all bits set in data2 are set in data
+ */
+ static bool contains(unsigned size, Uint32 data[], const Uint32 data2[]);
+
+ /**
+ * overlaps - Check if any bit set in data is set in data2
+ */
+ static bool overlaps(unsigned size, Uint32 data[], const Uint32 data2[]);
+
+ /**
+ * getField - Get bitfield at given position and length (max 32 bits)
+ */
+ static Uint32 getField(unsigned size, const Uint32 data[],
+ unsigned pos, unsigned len);
+
+ /**
+ * setField - Set bitfield at given position and length (max 32 bits)
+ */
+ static void setField(unsigned size, Uint32 data[],
+ unsigned pos, unsigned len, Uint32 val);
+
+ /**
+ * getText - Return as hex-digits (only for debug routines).
+ */
+ static void getText(unsigned size, const Uint32 data[], char* buf);
+};
+
+inline bool
+BitmaskImpl::get(unsigned size, const Uint32 data[], unsigned n)
+{
+ NDB_ASSERT(n < (size << 5), "bit get out of range");
+ return (data[n >> 5] & (1 << (n & 31))) != 0;
+}
+
+inline void
+BitmaskImpl::set(unsigned size, Uint32 data[], unsigned n, bool value)
+{
+ value ? set(size, data, n) : clear(size, data, n);
+}
+
+inline void
+BitmaskImpl::set(unsigned size, Uint32 data[], unsigned n)
+{
+ NDB_ASSERT(n < (size << 5), "bit set out of range");
+ data[n >> 5] |= (1 << (n & 31));
+}
+
+inline void
+BitmaskImpl::set(unsigned size, Uint32 data[])
+{
+ for (unsigned i = 0; i < size; i++) {
+ data[i] = ~0;
+ }
+}
+
+inline void
+BitmaskImpl::assign(unsigned size, Uint32 dst[], const Uint32 src[])
+{
+ for (unsigned i = 0; i < size; i++) {
+ dst[i] = src[i];
+ }
+}
+
+inline void
+BitmaskImpl::clear(unsigned size, Uint32 data[], unsigned n)
+{
+ NDB_ASSERT(n < (size << 5), "bit clear out of range");
+ data[n >> 5] &= ~(1 << (n & 31));
+}
+
+inline void
+BitmaskImpl::clear(unsigned size, Uint32 data[])
+{
+ for (unsigned i = 0; i < size; i++) {
+ data[i] = 0;
+ }
+}
+
+inline bool
+BitmaskImpl::isclear(unsigned size, const Uint32 data[])
+{
+ for (unsigned i = 0; i < size; i++) {
+ if (data[i] != 0)
+ return false;
+ }
+ return true;
+}
+
+inline unsigned
+BitmaskImpl::count(unsigned size, const Uint32 data[])
+{
+ unsigned cnt = 0;
+ for (unsigned i = 0; i < size; i++) {
+ Uint32 x = data[i];
+ while (x) {
+ x &= (x - 1);
+ cnt++;
+ }
+ }
+ return cnt;
+}
+
+inline unsigned
+BitmaskImpl::find(unsigned size, const Uint32 data[], unsigned n)
+{
+ while (n < (size << 5)) { // XXX make this smarter
+ if (get(size, data, n)) {
+ return n;
+ }
+ n++;
+ }
+ return NotFound;
+}
+
+inline bool
+BitmaskImpl::equal(unsigned size, const Uint32 data[], const Uint32 data2[])
+{
+ for (unsigned i = 0; i < size; i++) {
+ if (data[i] != data2[i])
+ return false;
+ }
+ return true;
+}
+
+inline void
+BitmaskImpl::bitOR(unsigned size, Uint32 data[], const Uint32 data2[])
+{
+ for (unsigned i = 0; i < size; i++) {
+ data[i] |= data2[i];
+ }
+}
+
+inline void
+BitmaskImpl::bitAND(unsigned size, Uint32 data[], const Uint32 data2[])
+{
+ for (unsigned i = 0; i < size; i++) {
+ data[i] &= data2[i];
+ }
+}
+
+inline void
+BitmaskImpl::bitANDC(unsigned size, Uint32 data[], const Uint32 data2[])
+{
+ for (unsigned i = 0; i < size; i++) {
+ data[i] &= ~data2[i];
+ }
+}
+
+inline void
+BitmaskImpl::bitXOR(unsigned size, Uint32 data[], const Uint32 data2[])
+{
+ for (unsigned i = 0; i < size; i++) {
+ data[i] ^= data2[i];
+ }
+}
+
+inline bool
+BitmaskImpl::contains(unsigned size, Uint32 data[], const Uint32 data2[])
+{
+ for (unsigned int i = 0; i < size; i++)
+ if ((data[i] & data2[i]) != data2[i])
+ return false;
+ return true;
+}
+
+inline bool
+BitmaskImpl::overlaps(unsigned size, Uint32 data[], const Uint32 data2[])
+{
+ for (unsigned int i = 0; i < size; i++)
+ if ((data[i] & data2[i]) != 0)
+ return true;
+ return false;
+}
+
+inline Uint32
+BitmaskImpl::getField(unsigned size, const Uint32 data[],
+ unsigned pos, unsigned len)
+{
+ Uint32 val = 0;
+ for (unsigned i = 0; i < len; i++)
+ val |= get(size, data, pos + i) << i;
+ return val;
+}
+
+inline void
+BitmaskImpl::setField(unsigned size, Uint32 data[],
+ unsigned pos, unsigned len, Uint32 val)
+{
+ for (unsigned i = 0; i < len; i++)
+ set(size, data, pos + i, val & (1 << i));
+}
+
+inline void
+BitmaskImpl::getText(unsigned size, const Uint32 data[], char* buf)
+{
+ const char* const hex = "0123456789abcdef";
+ for (int i = (size-1); i >= 0; i--) {
+ Uint32 x = data[i];
+ for (unsigned j = 0; j < 8; j++) {
+ buf[7-j] = hex[x & 0xf];
+ x >>= 4;
+ }
+ buf += 8;
+ }
+ *buf = 0;
+}
+
+/**
+ * Bitmasks. The size is number of 32-bit words (Uint32).
+ * Unused bits in the last word must be zero.
+ *
+ * XXX replace size by length in bits
+ */
+template <unsigned size>
+class Bitmask {
+public:
+ /**
+ * POD data representation
+ */
+ struct Data {
+ Uint32 data[size];
+
+ Data & operator=(const Bitmask<size> & src) {
+ src.assign(size, data);
+ return *this;
+ }
+ };
+private:
+
+ Data rep;
+public:
+ STATIC_CONST( Size = size );
+ STATIC_CONST( NotFound = BitmaskImpl::NotFound );
+ STATIC_CONST( TextLength = size * 8 );
+
+ /**
+ * assign - Set all bits in <em>dst</em> to corresponding in <em>src/<em>
+ */
+ void assign(const Bitmask<size>::Data & src);
+
+ /**
+ * assign - Set all bits in <em>dst</em> to corresponding in <em>src/<em>
+ */
+ static void assign(Uint32 dst[], const Uint32 src[]);
+ void assign(const Bitmask<size> & src);
+
+ /**
+ * assign <em>dst</em> of size <em>sz</em> to <em>this</em>
+ */
+ void assign(unsigned sz, Uint32 dst[]) const;
+
+ /**
+ * assign <em>this</em> according to <em>src/em>
+ */
+ void assign(unsigned sz, const Uint32 src[]);
+
+ /**
+ * get - Check if bit n is set.
+ */
+ static bool get(const Uint32 data[], unsigned n);
+ bool get(unsigned n) const;
+
+ /**
+ * set - Set bit n to given value (true/false).
+ */
+ static void set(Uint32 data[], unsigned n, bool value);
+ void set(unsigned n, bool value);
+
+ /**
+ * set - Set bit n.
+ */
+ static void set(Uint32 data[], unsigned n);
+ void set(unsigned n);
+
+ /**
+ * set - set all bits.
+ */
+ static void set(Uint32 data[]);
+ void set();
+
+ /**
+ * clear - Clear bit n.
+ */
+ static void clear(Uint32 data[], unsigned n);
+ void clear(unsigned n);
+
+ /**
+ * clear - Clear all bits.
+ */
+ static void clear(Uint32 data[]);
+ void clear();
+
+ /**
+ * isclear - Check if all bits are clear. This is faster
+ * than checking count() == 0.
+ */
+ static bool isclear(const Uint32 data[]);
+ bool isclear() const;
+
+ /**
+ * count - Count number of set bits.
+ */
+ static unsigned count(const Uint32 data[]);
+ unsigned count() const;
+
+ /**
+ * find - Find first set bit, starting at given position.
+ * Returns NotFound when not found.
+ */
+ static unsigned find(const Uint32 data[], unsigned n);
+ unsigned find(unsigned n) const;
+
+ /**
+ * equal - Bitwise equal.
+ */
+ static bool equal(const Uint32 data[], const Uint32 data2[]);
+ bool equal(const Bitmask<size>& mask2) const;
+
+ /**
+ * bitOR - Bitwise (x | y) into first operand.
+ */
+ static void bitOR(Uint32 data[], const Uint32 data2[]);
+ Bitmask<size>& bitOR(const Bitmask<size>& mask2);
+
+ /**
+ * bitAND - Bitwise (x & y) into first operand.
+ */
+ static void bitAND(Uint32 data[], const Uint32 data2[]);
+ Bitmask<size>& bitAND(const Bitmask<size>& mask2);
+
+ /**
+ * bitANDC - Bitwise (x & ~y) into first operand.
+ */
+ static void bitANDC(Uint32 data[], const Uint32 data2[]);
+ Bitmask<size>& bitANDC(const Bitmask<size>& mask2);
+
+ /**
+ * bitXOR - Bitwise (x ^ y) into first operand.
+ */
+ static void bitXOR(Uint32 data[], const Uint32 data2[]);
+ Bitmask<size>& bitXOR(const Bitmask<size>& mask2);
+
+ /**
+ * contains - Check if all bits set in data2 (that) are also set in data (this)
+ */
+ static bool contains(Uint32 data[], const Uint32 data2[]);
+ bool contains(Bitmask<size> that);
+
+ /**
+ * overlaps - Check if any bit set in this Bitmask (data) is also set in that (data2)
+ */
+ static bool overlaps(Uint32 data[], const Uint32 data2[]);
+ bool overlaps(Bitmask<size> that);
+
+ /**
+ * getText - Return as hex-digits (only for debug routines).
+ */
+ static void getText(const Uint32 data[], char* buf);
+ char* getText(char* buf) const;
+};
+
+template <unsigned size>
+inline void
+Bitmask<size>::assign(Uint32 dst[], const Uint32 src[])
+{
+ BitmaskImpl::assign(size, dst, src);
+}
+
+template <unsigned size>
+inline void
+Bitmask<size>::assign(const Bitmask<size>::Data & src)
+{
+ assign(rep.data, src.data);
+}
+
+template <unsigned size>
+inline void
+Bitmask<size>::assign(const Bitmask<size> & src)
+{
+ assign(rep.data, src);
+}
+
+template <unsigned size>
+inline void
+Bitmask<size>::assign(unsigned sz, Uint32 dst[]) const
+{
+ BitmaskImpl::assign(sz, dst, rep.data);
+}
+
+template <unsigned size>
+inline void
+Bitmask<size>::assign(unsigned sz, const Uint32 src[])
+{
+ BitmaskImpl::assign(sz, rep.data, src);
+}
+
+template <unsigned size>
+inline bool
+Bitmask<size>::get(const Uint32 data[], unsigned n)
+{
+ return BitmaskImpl::get(size, data, n);
+}
+
+template <unsigned size>
+inline bool
+Bitmask<size>::get(unsigned n) const
+{
+ return get(rep.data, n);
+}
+
+template <unsigned size>
+inline void
+Bitmask<size>::set(Uint32 data[], unsigned n, bool value)
+{
+ BitmaskImpl::set(size, data, n, value);
+}
+
+template <unsigned size>
+inline void
+Bitmask<size>::set(unsigned n, bool value)
+{
+ set(rep.data, n, value);
+}
+
+template <unsigned size>
+inline void
+Bitmask<size>::set(Uint32 data[], unsigned n)
+{
+ BitmaskImpl::set(size, data, n);
+}
+
+template <unsigned size>
+inline void
+Bitmask<size>::set(unsigned n)
+{
+ set(rep.data, n);
+}
+
+template <unsigned size>
+inline void
+Bitmask<size>::set(Uint32 data[])
+{
+ BitmaskImpl::set(size, data);
+}
+
+template <unsigned size>
+inline void
+Bitmask<size>::set()
+{
+ set(rep.data);
+}
+
+template <unsigned size>
+inline void
+Bitmask<size>::clear(Uint32 data[], unsigned n)
+{
+ BitmaskImpl::clear(size, data, n);
+}
+
+template <unsigned size>
+inline void
+Bitmask<size>::clear(unsigned n)
+{
+ clear(rep.data, n);
+}
+
+template <unsigned size>
+inline void
+Bitmask<size>::clear(Uint32 data[])
+{
+ BitmaskImpl::clear(size, data);
+}
+
+template <unsigned size>
+inline void
+Bitmask<size>::clear()
+{
+ clear(rep.data);
+}
+
+template <unsigned size>
+inline bool
+Bitmask<size>::isclear(const Uint32 data[])
+{
+ return BitmaskImpl::isclear(size, data);
+}
+
+template <unsigned size>
+inline bool
+Bitmask<size>::isclear() const
+{
+ return isclear(rep.data);
+}
+
+template <unsigned size>
+unsigned
+Bitmask<size>::count(const Uint32 data[])
+{
+ return BitmaskImpl::count(size, data);
+}
+
+template <unsigned size>
+inline unsigned
+Bitmask<size>::count() const
+{
+ return count(rep.data);
+}
+
+template <unsigned size>
+unsigned
+Bitmask<size>::find(const Uint32 data[], unsigned n)
+{
+ return BitmaskImpl::find(size, data, n);
+}
+
+template <unsigned size>
+inline unsigned
+Bitmask<size>::find(unsigned n) const
+{
+ return find(rep.data, n);
+}
+
+template <unsigned size>
+inline bool
+Bitmask<size>::equal(const Uint32 data[], const Uint32 data2[])
+{
+ return BitmaskImpl::equal(size, data, data2);
+}
+
+template <unsigned size>
+inline bool
+Bitmask<size>::equal(const Bitmask<size>& mask2) const
+{
+ return equal(rep.data, mask2.rep.data);
+}
+
+template <unsigned size>
+inline void
+Bitmask<size>::bitOR(Uint32 data[], const Uint32 data2[])
+{
+ BitmaskImpl::bitOR(size,data, data2);
+}
+
+template <unsigned size>
+inline Bitmask<size>&
+Bitmask<size>::bitOR(const Bitmask<size>& mask2)
+{
+ bitOR(rep.data, mask2.rep.data);
+ return *this;
+}
+
+template <unsigned size>
+inline void
+Bitmask<size>::bitAND(Uint32 data[], const Uint32 data2[])
+{
+ BitmaskImpl::bitAND(size,data, data2);
+}
+
+template <unsigned size>
+inline Bitmask<size>&
+Bitmask<size>::bitAND(const Bitmask<size>& mask2)
+{
+ bitAND(rep.data, mask2.rep.data);
+ return *this;
+}
+
+template <unsigned size>
+inline void
+Bitmask<size>::bitANDC(Uint32 data[], const Uint32 data2[])
+{
+ BitmaskImpl::bitANDC(size,data, data2);
+}
+
+template <unsigned size>
+inline Bitmask<size>&
+Bitmask<size>::bitANDC(const Bitmask<size>& mask2)
+{
+ bitANDC(rep.data, mask2.rep.data);
+ return *this;
+}
+
+template <unsigned size>
+inline void
+Bitmask<size>::bitXOR(Uint32 data[], const Uint32 data2[])
+{
+ BitmaskImpl::bitXOR(size,data, data2);
+}
+
+template <unsigned size>
+inline Bitmask<size>&
+Bitmask<size>::bitXOR(const Bitmask<size>& mask2)
+{
+ bitXOR(rep.data, mask2.rep.data);
+ return *this;
+}
+
+template <unsigned size>
+void
+Bitmask<size>::getText(const Uint32 data[], char* buf)
+{
+ BitmaskImpl::getText(size, data, buf);
+}
+
+template <unsigned size>
+inline char *
+Bitmask<size>::getText(char* buf) const
+{
+ getText(rep.data, buf);
+ return buf;
+}
+
+template <unsigned size>
+inline bool
+Bitmask<size>::contains(Uint32 data[], const Uint32 data2[])
+{
+ return BitmaskImpl::contains(size, data, data2);
+}
+
+template <unsigned size>
+inline bool
+Bitmask<size>::contains(Bitmask<size> that)
+{
+ return contains(this->rep.data, that.rep.data);
+}
+
+template <unsigned size>
+inline bool
+Bitmask<size>::overlaps(Uint32 data[], const Uint32 data2[])
+{
+ return BitmaskImpl::overlaps(size, data, data2);
+}
+
+template <unsigned size>
+inline bool
+Bitmask<size>::overlaps(Bitmask<size> that)
+{
+ return overlaps(this->rep.data, that.rep.data);
+}
+
+#endif
diff --git a/ndb/include/util/File.hpp b/ndb/include/util/File.hpp
new file mode 100644
index 00000000000..fe3d2642b18
--- /dev/null
+++ b/ndb/include/util/File.hpp
@@ -0,0 +1,206 @@
+/* Copyright (C) 2003 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+#ifndef FILE_H
+#define FILE_H
+
+#include <NdbStdio.h>
+#include <NdbConstant.hpp>
+
+/**
+ * This class provides a file abstraction . It has operations
+ * to create, read, write and delete a file.
+ *
+ * @version #@ $Id: File.hpp,v 1.5 2002/04/26 13:15:38 ejonore Exp $
+ */
+class File
+{
+public:
+ /**
+ * Returns true if the file exist.
+ *
+ * @param aFileName a filename to check.
+ * @return true if the file exists.
+ */
+ static bool exists(const char* aFileName);
+
+ /**
+ * Returns the size of a file.
+ *
+ * @param f a pointer to a FILE descriptor.
+ * @return the size of the file.
+ */
+ static long size(FILE* f);
+
+ /**
+ * Renames a file.
+ *
+ * @param currFileName the current name of the file.
+ * @param newFileName the new name of the file.
+ * @return true if successful.
+ */
+ static bool rename(const char* currFileName, const char* newFileName);
+
+ /**
+ * Removes/deletes a file.
+ *
+ * @param aFileName the file to remove.
+ * @return true if successful.
+ */
+ static bool remove(const char* aFileName);
+
+ /**
+ * Default constructor.
+ */
+ File();
+
+ /**
+ * Creates a new File with the specified filename and file mode.
+ * The real file itself will not be created unless open() is called!
+ *
+ * To see the available file modes use 'man 3 fopen'.
+ *
+ * @param aFileName a filename.
+ * @param mode the mode which the file should be opened/created with, default "r".
+ */
+ File(const char* aFileName, const char* mode = "r");
+
+ /**
+ * Destructor.
+ */
+ ~File();
+
+ /**
+ * Opens/creates the file. If open() fails then 'errno' and perror()
+ * should be used to determine the exact failure cause.
+ *
+ * @return true if successful. Check errno if unsuccessful.
+ */
+ bool open();
+
+ /**
+ * Opens/creates the file with the specified name and mode.
+ * If open() fails then 'errno' and perror() should be used to
+ * determine the exact failure cause.
+ *
+ * @param aFileName the file to open.
+ * @param mode the file mode to use.
+ * @return true if successful. Check errno if unsuccessful.
+ */
+ bool open(const char* aFileName, const char* mode);
+
+ /**
+ * Removes the file.
+ *
+ * @return true if successful.
+ */
+ bool remove();
+
+ /**
+ * Closes the file, i.e., the FILE descriptor is closed.
+ */
+ bool close();
+
+ /**
+ * Read from the file. See fread() for more info.
+ *
+ * @param buf the buffer to read into.
+ * @param itemSize the size of each item.
+ * @param nitems read max n number of items.
+ * @return 0 if successful.
+ */
+ int read(void* buf, size_t itemSize, size_t nitems) const;
+
+ /**
+ * Read char from the file. See fread() for more info.
+ *
+ * @param buf the buffer to read into.
+ * @param start the start index of the buf.
+ * @param length the length of the buffer.
+ * @return 0 if successful.
+ */
+ int readChar(char* buf, long start, long length) const;
+
+ /**
+ * Read chars from the file. See fread() for more info.
+ *
+ * @param buf the buffer to read into.
+ * @return 0 if successful.
+ */
+ int readChar(char* buf);
+
+ /**
+ * Write to file. See fwrite() for more info.
+ *
+ * @param buf the buffer to read from.
+ * @param itemSize the size of each item.
+ * @param nitems write max n number of items.
+ * @return 0 if successful.
+ */
+ int write(const void* buf, size_t itemSize, size_t nitems);
+
+ /**
+ * Write chars to file. See fwrite() for more info.
+ *
+ * @param buf the buffer to read from.
+ * @param start the start index of the buf.
+ * @param length the length of the buffer.
+ * @return 0 if successful.
+ */
+ int writeChar(const char* buf, long start, long length);
+
+ /**
+ * Write chars to file. See fwrite() for more info.
+ *
+ * @param buf the buffer to read from.
+ * @return 0 if successful.
+ */
+ int writeChar(const char* buf);
+
+ /**
+ * Returns the file size.
+ *
+ * @return the file size.
+ */
+ long size() const;
+
+ /**
+ * Returns the filename.
+ *
+ * @return the filename.
+ */
+ const char* getName() const;
+
+ /**
+ * Flush the buffer.
+ *
+ * @return 0 if successful.
+ */
+ int flush() const;
+
+private:
+ STATIC_CONST( MAX_FILE_NAME_SIZE = 128 );
+
+ FILE* m_file;
+ char m_fileName[MAX_FILE_NAME_SIZE];
+ const char* m_fileMode;
+ /* Prohibit */
+ File(const File& aCopy);
+ File operator = (const File&);
+ bool operator == (const File&);
+};
+#endif
+
diff --git a/ndb/include/util/InputStream.hpp b/ndb/include/util/InputStream.hpp
new file mode 100644
index 00000000000..6b4cf262db4
--- /dev/null
+++ b/ndb/include/util/InputStream.hpp
@@ -0,0 +1,48 @@
+/* Copyright (C) 2003 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+#ifndef INPUT_STREAM_HPP
+#define INPUT_STREAM_HPP
+
+#include <stdio.h>
+#include <NdbTCP.h>
+
+/**
+ * Input stream
+ */
+class InputStream {
+public:
+ virtual char* gets(char * buf, int bufLen) = 0;
+};
+
+class FileInputStream : public InputStream {
+ FILE * f;
+public:
+ FileInputStream(FILE * file = stdin);
+ char* gets(char * buf, int bufLen);
+};
+
+extern FileInputStream Stdin;
+
+class SocketInputStream : public InputStream {
+ NDB_SOCKET_TYPE m_socket;
+ unsigned m_timeout;
+public:
+ SocketInputStream(NDB_SOCKET_TYPE socket, unsigned readTimeout = 1000);
+ char* gets(char * buf, int bufLen);
+};
+
+#endif
diff --git a/ndb/include/util/NdbAutoPtr.hpp b/ndb/include/util/NdbAutoPtr.hpp
new file mode 100644
index 00000000000..2078714d98d
--- /dev/null
+++ b/ndb/include/util/NdbAutoPtr.hpp
@@ -0,0 +1,49 @@
+/* Copyright (C) 2003 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+#ifndef __NDB_AUTO_PTR_HPP
+#define __NDB_AUTO_PTR_HPP
+
+#include <stdlib.h>
+
+template<typename T>
+class NdbAutoPtr {
+ T * m_obj;
+public:
+ NdbAutoPtr(T * obj = 0){ m_obj = obj;}
+ void reset(T * obj = 0) { if (m_obj) free(m_obj); m_obj = obj; }
+ ~NdbAutoPtr() { if (m_obj) free(m_obj);}
+};
+
+template<typename T>
+class NdbAutoObjPtr {
+ T * m_obj;
+public:
+ NdbAutoObjPtr(T * obj = 0){ m_obj = obj;}
+ void reset(T * obj = 0) { if (m_obj) delete m_obj; m_obj = obj; }
+ ~NdbAutoObjPtr() { if (m_obj) delete m_obj;}
+};
+
+template<typename T>
+class NdbAutoObjArrayPtr {
+ T * m_obj;
+public:
+ NdbAutoObjArrayPtr(T * obj = 0){ m_obj = obj;}
+ void reset(T * obj = 0) { if (m_obj) delete[] m_obj; m_obj = obj; }
+ ~NdbAutoObjArrayPtr() { if (m_obj) delete[] m_obj;}
+};
+
+#endif
diff --git a/ndb/include/util/NdbOut.hpp b/ndb/include/util/NdbOut.hpp
new file mode 100644
index 00000000000..d85d5cc6305
--- /dev/null
+++ b/ndb/include/util/NdbOut.hpp
@@ -0,0 +1,132 @@
+/* Copyright (C) 2003 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+#ifndef NDBOUT_H
+#define NDBOUT_H
+
+#ifdef __cplusplus
+
+#include <ndb_types.h>
+#include <util/BaseString.hpp>
+
+/**
+ * Class used for outputting logging messages to screen.
+ * Since the output capabilities are different on different platforms
+ * this middle layer class should be used for all output messages
+ */
+
+/*
+ Example usage:
+
+ #include "NdbOut.hpp"
+
+ / * Use ndbout as you would use cout:
+
+ ndbout << "Hello World! "<< 1 << " Hello again"
+ << 67 << anIntegerVar << "Hup << endl;
+
+
+ / * Use ndbout_c as you would use printf:
+
+ ndbout_c("Hello World %d\n", 1);
+*/
+
+class NdbOut;
+class OutputStream;
+class NullOutputStream;
+
+/* Declare a static variable of NdbOut as ndbout */
+extern NdbOut ndbout;
+
+class NdbOut
+{
+public:
+ NdbOut& operator<<(NdbOut& (* _f)(NdbOut&));
+ NdbOut& operator<<(Int8);
+ NdbOut& operator<<(Uint8);
+ NdbOut& operator<<(Int16);
+ NdbOut& operator<<(Uint16);
+ NdbOut& operator<<(Int32);
+ NdbOut& operator<<(Uint32);
+ NdbOut& operator<<(Int64);
+ NdbOut& operator<<(Uint64);
+ NdbOut& operator<<(long unsigned int);
+ NdbOut& operator<<(const char*);
+ NdbOut& operator<<(const unsigned char*);
+ NdbOut& operator<<(BaseString &);
+ NdbOut& operator<<(const void*);
+ NdbOut& operator<<(float);
+ NdbOut& operator<<(double);
+ NdbOut& endline(void);
+ NdbOut& flushline(void);
+ NdbOut& setHexFormat(int _format);
+
+ NdbOut(OutputStream &);
+ virtual ~NdbOut();
+
+ void print(const char * fmt, ...);
+ void println(const char * fmt, ...);
+
+ OutputStream * m_out;
+private:
+ int isHex;
+};
+
+inline NdbOut& NdbOut::operator<<(NdbOut& (* _f)(NdbOut&)) {
+ (* _f)(*this);
+ return * this;
+}
+
+inline NdbOut& endl(NdbOut& _NdbOut) {
+ return _NdbOut.endline();
+}
+
+inline NdbOut& flush(NdbOut& _NdbOut) {
+ return _NdbOut.flushline();
+}
+
+inline NdbOut& hex(NdbOut& _NdbOut) {
+ return _NdbOut.setHexFormat(1);
+}
+
+inline NdbOut& dec(NdbOut& _NdbOut) {
+ return _NdbOut.setHexFormat(0);
+}
+extern "C"
+void ndbout_c(const char * fmt, ...);
+
+class FilteredNdbOut : public NdbOut {
+public:
+ FilteredNdbOut(OutputStream &, int threshold = 0, int level = 0);
+ virtual ~FilteredNdbOut();
+
+ void setLevel(int i);
+ void setThreshold(int i);
+
+ int getLevel() const;
+ int getThreshold() const;
+
+private:
+ int m_threshold, m_level;
+ OutputStream * m_org;
+ NullOutputStream * m_null;
+};
+
+#else
+void ndbout_c(const char * fmt, ...);
+#endif
+
+#endif
diff --git a/ndb/include/util/NdbSqlUtil.hpp b/ndb/include/util/NdbSqlUtil.hpp
new file mode 100644
index 00000000000..bb573eea17b
--- /dev/null
+++ b/ndb/include/util/NdbSqlUtil.hpp
@@ -0,0 +1,357 @@
+/* Copyright (C) 2003 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+#ifndef NDB_SQL_UTIL_HPP
+#define NDB_SQL_UTIL_HPP
+
+#include <string.h>
+#include <ndb_types.h>
+
+class NdbSqlUtil {
+public:
+ /**
+ * Compare strings, optionally with padded semantics. Returns
+ * negative (less), zero (equal), or positive (greater).
+ */
+ static int char_compare(const char* s1, unsigned n1,
+ const char* s2, unsigned n2, bool padded);
+
+ /**
+ * Like operator, optionally with padded semantics. Returns true or
+ * false.
+ */
+ static bool char_like(const char* s1, unsigned n1,
+ const char* s2, unsigned n2, bool padded);
+
+ /**
+ * Compare kernel attribute values. Returns -1, 0, +1 for less,
+ * equal, greater, respectively. Parameters are pointers to values,
+ * full attribute size in words, and size of available data in words.
+ * There are 2 special return values to check first. All values fit
+ * into a signed char.
+ */
+ typedef int Cmp(const Uint32* p1, const Uint32* p2, Uint32 full, Uint32 size);
+
+ enum CmpResult {
+ CmpLess = -1,
+ CmpEqual = 0,
+ CmpGreater = 1,
+ CmpUnknown = 126, // insufficient partial data
+ CmpError = 127 // bad data format or unimplemented comparison
+ };
+
+ /**
+ * Kernel data types. Must match m_typeList in NdbSqlUtil.cpp.
+ */
+ struct Type {
+ enum Enum {
+ Undefined = 0, // Undefined
+ Tinyint, // 8 bit
+ Tinyunsigned, // 8 bit
+ Smallint, // 16 bit
+ Smallunsigned, // 16 bit
+ Mediumint, // 24 bit
+ Mediumunsigned, // 24 bit
+ Int, // 32 bit
+ Unsigned, // 32 bit
+ Bigint, // 64 bit
+ Bigunsigned, // 64 Bit
+ Float, // 32-bit float
+ Double, // 64-bit float
+ Decimal, // Precision, Scale
+ Char, // Len
+ Varchar, // Max len
+ Binary, // Len
+ Varbinary, // Max len
+ Datetime, // Precision down to 1 sec (size 8 bytes)
+ Timespec // Precision down to 1 nsec (size 12 bytes)
+ };
+ Enum m_typeId;
+ Cmp* m_cmp; // set to NULL if cmp not implemented
+ };
+
+ /**
+ * Get type by id. Can return the Undefined type.
+ */
+ static const Type& type(Uint32 typeId);
+
+ /**
+ * Inline comparison method. Most or all real methods Type::m_cmp are
+ * implemented via this (trusting dead code elimination).
+ */
+ static int cmp(Uint32 typeId, const Uint32* p1, const Uint32* p2, Uint32 full, Uint32 size);
+
+private:
+ /**
+ * List of all types. Must match Type::Enum.
+ */
+ static const Type m_typeList[];
+ /**
+ * Comparison methods.
+ */
+ static Cmp cmpTinyint;
+ static Cmp cmpTinyunsigned;
+ static Cmp cmpSmallint;
+ static Cmp cmpSmallunsigned;
+ static Cmp cmpMediumint;
+ static Cmp cmpMediumunsigned;
+ static Cmp cmpInt;
+ static Cmp cmpUnsigned;
+ static Cmp cmpBigint;
+ static Cmp cmpBigunsigned;
+ static Cmp cmpFloat;
+ static Cmp cmpDouble;
+ static Cmp cmpDecimal;
+ static Cmp cmpChar;
+ static Cmp cmpVarchar;
+ static Cmp cmpBinary;
+ static Cmp cmpVarbinary;
+ static Cmp cmpDatetime;
+ static Cmp cmpTimespec;
+};
+
+inline int
+NdbSqlUtil::cmp(Uint32 typeId, const Uint32* p1, const Uint32* p2, Uint32 full, Uint32 size)
+{
+ if (size > full)
+ return CmpError;
+ switch ((Type::Enum)typeId) {
+ case Type::Undefined:
+ break;
+ case Type::Tinyint:
+ {
+ if (size >= 1) {
+ union { Uint32 p[1]; Int8 v; } u1, u2;
+ u1.p[0] = p1[0];
+ u2.p[0] = p2[0];
+ if (u1.v < u2.v)
+ return -1;
+ if (u1.v > u2.v)
+ return +1;
+ return 0;
+ }
+ return CmpUnknown;
+ }
+ break;
+ case Type::Tinyunsigned:
+ {
+ if (size >= 1) {
+ union { Uint32 p[1]; Uint8 v; } u1, u2;
+ u1.p[0] = p1[0];
+ u2.p[0] = p2[0];
+ if (u1.v < u2.v)
+ return -1;
+ if (u1.v > u2.v)
+ return +1;
+ return 0;
+ }
+ return CmpUnknown;
+ }
+ break;
+ case Type::Smallint:
+ {
+ if (size >= 1) {
+ union { Uint32 p[1]; Int16 v; } u1, u2;
+ u1.p[0] = p1[0];
+ u2.p[0] = p2[0];
+ if (u1.v < u2.v)
+ return -1;
+ if (u1.v > u2.v)
+ return +1;
+ return 0;
+ }
+ return CmpUnknown;
+ }
+ break;
+ case Type::Smallunsigned:
+ {
+ if (size >= 1) {
+ union { Uint32 p[1]; Uint16 v; } u1, u2;
+ u1.p[0] = p1[0];
+ u2.p[0] = p2[0];
+ if (u1.v < u2.v)
+ return -1;
+ if (u1.v > u2.v)
+ return +1;
+ return 0;
+ }
+ return CmpUnknown;
+ }
+ break;
+ case Type::Mediumint: // XXX fix these
+ break;
+ case Type::Mediumunsigned:
+ break;
+ case Type::Int:
+ {
+ if (size >= 1) {
+ union { Uint32 p[1]; Int32 v; } u1, u2;
+ u1.p[0] = p1[0];
+ u2.p[0] = p2[0];
+ if (u1.v < u2.v)
+ return -1;
+ if (u1.v > u2.v)
+ return +1;
+ return 0;
+ }
+ return CmpUnknown;
+ }
+ break;
+ case Type::Unsigned:
+ {
+ if (size >= 1) {
+ union { Uint32 p[1]; Uint32 v; } u1, u2;
+ u1.v = p1[0];
+ u2.v = p2[0];
+ if (u1.v < u2.v)
+ return -1;
+ if (u1.v > u2.v)
+ return +1;
+ return 0;
+ }
+ return CmpUnknown;
+ }
+ break;
+ case Type::Bigint:
+ {
+ if (size >= 2) {
+ union { Uint32 p[2]; Int64 v; } u1, u2;
+ u1.p[0] = p1[0];
+ u1.p[1] = p1[1];
+ u2.p[0] = p2[0];
+ u2.p[1] = p2[1];
+ if (u1.v < u2.v)
+ return -1;
+ if (u1.v > u2.v)
+ return +1;
+ return 0;
+ }
+ return CmpUnknown;
+ }
+ break;
+ case Type::Bigunsigned:
+ {
+ if (size >= 2) {
+ union { Uint32 p[2]; Uint64 v; } u1, u2;
+ u1.p[0] = p1[0];
+ u1.p[1] = p1[1];
+ u2.p[0] = p2[0];
+ u2.p[1] = p2[1];
+ if (u1.v < u2.v)
+ return -1;
+ if (u1.v > u2.v)
+ return +1;
+ return 0;
+ }
+ return CmpUnknown;
+ }
+ break;
+ case Type::Float:
+ {
+ if (size >= 1) {
+ union { Uint32 p[1]; float v; } u1, u2;
+ u1.p[0] = p1[0];
+ u2.p[0] = p2[0];
+ if (u1.v < u2.v)
+ return -1;
+ if (u1.v > u2.v)
+ return +1;
+ return 0;
+ }
+ return CmpUnknown;
+ }
+ break;
+ case Type::Double:
+ {
+ if (size >= 2) {
+ union { Uint32 p[2]; double v; } u1, u2;
+ u1.p[0] = p1[0];
+ u1.p[1] = p1[1];
+ u2.p[0] = p2[0];
+ u2.p[1] = p2[1];
+ if (u1.v < u2.v)
+ return -1;
+ if (u1.v > u2.v)
+ return +1;
+ return 0;
+ }
+ return CmpUnknown;
+ }
+ break;
+ case Type::Decimal:
+ break;
+ case Type::Char:
+ {
+ /*
+ * Char is blank-padded to length and null-padded to word size.
+ * There is no terminator so we must compare the full values.
+ */
+ union { const Uint32* p; const char* v; } u1, u2;
+ u1.p = p1;
+ u2.p = p2;
+ int k = memcmp(u1.v, u2.v, size << 2);
+ return k < 0 ? -1 : k > 0 ? +1 : full == size ? 0 : CmpUnknown;
+ }
+ break;
+ case Type::Varchar:
+ {
+ /*
+ * Varchar is not allowed to contain a null byte and the stored
+ * value is null-padded. Therefore comparison does not need to
+ * use the length.
+ */
+ if (size >= 1) {
+ union { const Uint32* p; const char* v; } u1, u2;
+ u1.p = p1;
+ u2.p = p2;
+ // length in first 2 bytes
+ int k = strncmp(u1.v + 2, u2.v + 2, (size << 2) - 2);
+ return k < 0 ? -1 : k > 0 ? +1 : full == size ? 0 : CmpUnknown;
+ }
+ return CmpUnknown;
+ }
+ break;
+ case Type::Binary: // XXX fix these
+ break;
+ case Type::Varbinary:
+ break;
+ case Type::Datetime:
+ {
+ /*
+ * Datetime is CC YY MM DD hh mm ss \0
+ */
+ if (size >= 1) {
+ union { const Uint32* p; const char* v; } u1, u2;
+ u1.p = p1;
+ u2.p = p2;
+ // skip format check
+ int k = strncmp(u1.v, u2.v, 4);
+ if (k != 0)
+ return k;
+ if (size >= 2) {
+ return strncmp(u1.v + 4, u2.v + 4, 4);
+ }
+ }
+ return CmpUnknown;
+ }
+ break;
+ case Type::Timespec: // XXX fix this
+ break;
+ }
+ return CmpError;
+}
+
+#endif
diff --git a/ndb/include/util/NdbString.h b/ndb/include/util/NdbString.h
new file mode 100644
index 00000000000..97646f813ac
--- /dev/null
+++ b/ndb/include/util/NdbString.h
@@ -0,0 +1,48 @@
+/* Copyright (C) 2003 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+#ifndef __NDBSTRING_H_INCLUDED__
+#define __NDBSTRING_H_INCLUDED__
+
+#include <sys/types.h>
+#include <string.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef HAVE_STRDUP
+extern char * strdup(const char *s);
+#endif
+
+#ifndef HAVE_STRLCPY
+extern size_t strlcpy (char *dst, const char *src, size_t dst_sz);
+#endif
+
+#ifndef HAVE_STRLCAT
+extern size_t strlcat (char *dst, const char *src, size_t dst_sz);
+#endif
+
+#ifndef HAVE_STRCASECMP
+extern int strcasecmp(const char *s1, const char *s2);
+extern int strncasecmp(const char *s1, const char *s2, size_t n);
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* !__NDBSTRING_H_INCLUDED__ */
diff --git a/ndb/include/util/OutputStream.hpp b/ndb/include/util/OutputStream.hpp
new file mode 100644
index 00000000000..9d33ead7eb9
--- /dev/null
+++ b/ndb/include/util/OutputStream.hpp
@@ -0,0 +1,67 @@
+/* Copyright (C) 2003 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+#ifndef OUTPUT_STREAM_HPP
+#define OUTPUT_STREAM_HPP
+
+#include <stdio.h>
+#include <NdbTCP.h>
+
+/**
+ * Output stream
+ */
+class OutputStream {
+public:
+ virtual int print(const char * fmt, ...) = 0;
+ virtual int println(const char * fmt, ...) = 0;
+ virtual void flush() {};
+};
+
+class FileOutputStream : public OutputStream {
+ FILE * f;
+public:
+ FileOutputStream(FILE * file = stdout);
+
+ int print(const char * fmt, ...);
+ int println(const char * fmt, ...);
+ void flush() { fflush(f); }
+};
+
+class SocketOutputStream : public OutputStream {
+ NDB_SOCKET_TYPE m_socket;
+ unsigned m_timeout;
+public:
+ SocketOutputStream(NDB_SOCKET_TYPE socket, unsigned writeTimeout = 1000);
+
+ int print(const char * fmt, ...);
+ int println(const char * fmt, ...);
+};
+
+class SoftOseOutputStream : public OutputStream {
+public:
+ SoftOseOutputStream();
+
+ int print(const char * fmt, ...);
+ int println(const char * fmt, ...);
+};
+
+class NullOutputStream : public OutputStream {
+public:
+ int print(const char * /* unused */, ...) { return 1;}
+ int println(const char * /* unused */, ...) { return 1;}
+};
+
+#endif
diff --git a/ndb/include/util/Parser.hpp b/ndb/include/util/Parser.hpp
new file mode 100644
index 00000000000..9c2f02b6024
--- /dev/null
+++ b/ndb/include/util/Parser.hpp
@@ -0,0 +1,290 @@
+/* Copyright (C) 2003 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+#ifndef CPCD_PARSER_HPP
+#define CPCD_PARSER_HPP
+
+#include "Vector.hpp"
+#include "Properties.hpp"
+#include "InputStream.hpp"
+#include "NdbOut.hpp"
+
+class ParserImpl;
+template<class T> class ParserRow;
+
+//#define PARSER_DEBUG
+#ifdef PARSER_DEBUG
+#define DEBUG(x) \
+ ndbout_c("%s:%d:%s", __FILE__, __LINE__, x);
+#else
+#define DEBUG(x)
+#endif
+
+/**
+ * A generic parser
+ */
+template<class T>
+class Parser {
+public:
+ /**
+ * Status for parser
+ */
+ enum ParserStatus {
+ Ok = 0,
+ Eof = 1,
+ NoLine = 2,
+ EmptyLine = 3,
+ UnknownCommand = 4,
+ UnknownArgument = 5,
+ TypeMismatch = 6,
+ InvalidArgumentFormat = 7,
+ UnknownArgumentType = 8,
+ CommandWithoutFunction = 9,
+ ArgumentGivenTwice = 10,
+ ExternalStop = 11,
+ MissingMandatoryArgument = 12
+ };
+
+ /**
+ * Context for parse
+ */
+ struct Context {
+ ParserStatus m_status;
+ const ParserRow<T> * m_currentCmd;
+ const ParserRow<T> * m_currentArg;
+ char * m_currentToken;
+ char m_tokenBuffer[512];
+
+ Vector<const ParserRow<T> *> m_aliasUsed;
+ };
+
+ /**
+ * Initialize parser
+ */
+ Parser(const ParserRow<T> rows[], class InputStream & in = Stdin,
+ bool breakOnCommand = false,
+ bool breakOnEmptyLine = true,
+ bool breakOnInvalidArg = false);
+ ~Parser();
+
+ /**
+ * Run parser
+ */
+ bool run(Context &, T &, volatile bool * stop = 0) const;
+
+ /**
+ * Parse only one entry and return Properties object representing
+ * the message
+ */
+ const Properties *parse(Context &, T &);
+
+ bool getBreakOnCommand() const;
+ void setBreakOnCommand(bool v);
+
+ bool getBreakOnEmptyLine() const;
+ void setBreakOnEmptyLine(bool v);
+
+ bool getBreakOnInvalidArg() const;
+ void setBreakOnInvalidArg(bool v);
+
+private:
+ ParserImpl * impl;
+};
+
+template<class T>
+struct ParserRow {
+public:
+ enum Type { Cmd, Arg, CmdAlias, ArgAlias };
+ enum ArgType { String, Int, Properties };
+ enum ArgRequired { Mandatory, Optional };
+ enum ArgMinMax { CheckMinMax, IgnoreMinMax };
+
+ const char * name;
+ const char * realName;
+ Type type;
+ ArgType argType;
+ ArgRequired argRequired;
+ ArgMinMax argMinMax;
+ int minVal;
+ int maxVal;
+ void (T::* function)(typename Parser<T>::Context & ctx,
+ const class Properties& args);
+ const char * description;
+ void *user_value;
+};
+
+/**
+ * The void* equivalent implementation
+ */
+class ParserImpl {
+ class Dummy {};
+ typedef ParserRow<Dummy> DummyRow;
+ typedef Parser<Dummy>::Context Context;
+ template<class T> friend class Parser;
+private:
+
+ ParserImpl(const DummyRow rows[], class InputStream & in,
+ bool b_cmd, bool b_empty, bool b_iarg);
+ ~ParserImpl();
+
+ bool run(Context *ctx, const class Properties **, volatile bool *) const ;
+
+ static const DummyRow* matchCommand(Context*, const char*, const DummyRow*);
+ static const DummyRow* matchArg(Context*, const char *, const DummyRow *);
+ static bool parseArg(Context*, char*, const DummyRow*, Properties*);
+ static bool checkMandatory(Context*, const Properties*);
+private:
+ const DummyRow * const m_rows;
+ class ParseInputStream & input;
+ bool m_breakOnEmpty;
+ bool m_breakOnCmd;
+ bool m_breakOnInvalidArg;
+};
+
+template<class T>
+inline
+Parser<T>::Parser(const ParserRow<T> rows[], class InputStream & in,
+ bool b_cmd, bool b_empty, bool b_iarg){
+ impl = new ParserImpl((ParserImpl::DummyRow *)rows, in,
+ b_cmd, b_empty, b_iarg);
+}
+
+template<class T>
+inline
+Parser<T>::~Parser(){
+}
+
+template<class T>
+inline
+bool
+Parser<T>::run(Context & ctx, T & t, volatile bool * stop) const {
+ const Properties * p;
+ DEBUG("Executing Parser<T>::run");
+ if(impl->run((ParserImpl::Context*)&ctx, &p, stop)){
+ const ParserRow<T> * cmd = ctx.m_currentCmd; // Cast to correct type
+ if(cmd == 0){
+ /**
+ * Should happen if run returns true
+ */
+ abort();
+ }
+
+ for(unsigned i = 0; i<ctx.m_aliasUsed.size(); i++){
+ const ParserRow<T> * alias = ctx.m_aliasUsed[i];
+ if(alias->function != 0){
+ /**
+ * Report alias usage with callback (if specified by user)
+ */
+ DEBUG("Alias usage with callback");
+ (t.* alias->function)(ctx, * p);
+ }
+ }
+
+ if(cmd->function == 0){
+ ctx.m_status = CommandWithoutFunction;
+ DEBUG("CommandWithoutFunction");
+ delete p;
+ return false;
+ }
+ (t.* cmd->function)(ctx, * p); // Call the function
+ delete p;
+ return true;
+ }
+ DEBUG("");
+ return false;
+}
+
+template<class T>
+inline
+const Properties *
+Parser<T>::parse(Context &ctx, T &t) {
+ const Properties * p;
+ volatile bool stop = false;
+ DEBUG("Executing Parser<T>::parse");
+
+ if(impl->run((ParserImpl::Context*)&ctx, &p, &stop)){
+ const ParserRow<T> * cmd = ctx.m_currentCmd; // Cast to correct type
+ if(cmd == 0){
+ /**
+ * Should happen if run returns true
+ */
+ abort();
+ }
+
+ for(unsigned i = 0; i<ctx.m_aliasUsed.size(); i++){
+ const ParserRow<T> * alias = ctx.m_aliasUsed[i];
+ if(alias->function != 0){
+ /**
+ * Report alias usage with callback (if specified by user)
+ */
+ DEBUG("Alias usage with callback");
+ (t.* alias->function)(ctx, * p);
+ }
+ }
+
+ if(cmd->function == 0){
+ DEBUG("CommandWithoutFunction");
+ ctx.m_status = CommandWithoutFunction;
+ return p;
+ }
+ return p;
+ }
+ DEBUG("");
+ return NULL;
+}
+
+template<class T>
+inline
+bool
+Parser<T>::getBreakOnCommand() const{
+ return impl->m_breakOnCmd;
+}
+
+template<class T>
+inline
+void
+Parser<T>::setBreakOnCommand(bool v){
+ impl->m_breakOnCmd = v;
+}
+
+template<class T>
+inline
+bool
+Parser<T>::getBreakOnEmptyLine() const{
+ return impl->m_breakOnEmpty;
+}
+template<class T>
+inline
+void
+Parser<T>::setBreakOnEmptyLine(bool v){
+ impl->m_breakOnEmpty = v;
+}
+
+template<class T>
+inline
+bool
+Parser<T>::getBreakOnInvalidArg() const{
+ return impl->m_breakOnInvalidArg;
+}
+
+template<class T>
+inline
+void
+Parser<T>::setBreakOnInvalidArg(bool v){
+ impl->m_breakOnInvalidArg;
+}
+
+#endif
diff --git a/ndb/include/util/Properties.hpp b/ndb/include/util/Properties.hpp
new file mode 100644
index 00000000000..dbdc5f2b480
--- /dev/null
+++ b/ndb/include/util/Properties.hpp
@@ -0,0 +1,246 @@
+/* Copyright (C) 2003 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+#ifndef PROPERTIES_HPP
+#define PROPERTIES_HPP
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <ndb_types.h>
+#include <BaseString.hpp>
+#include <UtilBuffer.hpp>
+
+enum PropertiesType {
+ PropertiesType_Uint32,
+ PropertiesType_char,
+ PropertiesType_Properties
+};
+
+/**
+ * @struct Property
+ * @brief Stores one (name, value)-pair
+ *
+ * Value can be of type Properties, i.e. a Property may contain
+ * a Properties object.
+ */
+struct Property {
+ Property(const char* name, Uint32 val);
+ Property(const char* name, const char * value);
+ Property(const char* name, const class Properties * value);
+ ~Property();
+private:
+ friend class Properties;
+ struct PropertyImpl * impl;
+};
+
+/**
+ * @class Properties
+ * @brief Stores information in (name, value)-pairs
+ */
+class Properties {
+public:
+ static const char delimiter = ':';
+ static const char version[];
+
+ Properties();
+ Properties(const Properties &);
+ Properties(const Property *, int len);
+ virtual ~Properties();
+
+ /**
+ * Set/Get wheather names in the Properties should be compared
+ * w/o case.
+ * NOTE: The property is automatically applied to all propoerties put
+ * into this after a called to setCaseInsensitiveNames has been made
+ * But properties already in when calling setCaseInsensitiveNames will
+ * not be affected
+ */
+ void setCaseInsensitiveNames(bool value);
+ bool getCaseInsensitiveNames() const;
+
+ /**
+ * Insert an array of value(s)
+ */
+ void put(const Property *, int len);
+
+ bool put(const char * name, Uint32 value, bool replace = false);
+ bool put(const char * name, const char * value, bool replace = false);
+ bool put(const char * name, const Properties * value, bool replace = false);
+
+ /**
+ * Same as put above,
+ * except that _%d (where %d is a number) is added to the name
+ * Compare get(name, no)
+ */
+ bool put(const char *, Uint32 no, Uint32, bool replace = false);
+ bool put(const char *, Uint32 no, const char *, bool replace = false);
+ bool put(const char *, Uint32 no, const Properties *, bool replace = false);
+
+
+ bool getTypeOf(const char * name, PropertiesType * type) const;
+
+ /** @return true if Properties object contains name */
+ bool contains(const char * name) const;
+
+ bool get(const char * name, Uint32 * value) const;
+ bool get(const char * name, const char ** value) const;
+ bool get(const char * name, BaseString & value) const;
+ bool get(const char * name, const Properties ** value) const;
+
+ bool getCopy(const char * name, char ** value) const;
+ bool getCopy(const char * name, Properties ** value) const;
+
+ /**
+ * Same as get above
+ * except that _%d (where %d = no) is added to the name
+ */
+ bool getTypeOf(const char * name, Uint32 no, PropertiesType * type) const;
+ bool contains(const char * name, Uint32 no) const;
+
+ bool get(const char * name, Uint32 no, Uint32 * value) const;
+ bool get(const char * name, Uint32 no, const char ** value) const;
+ bool get(const char * name, Uint32 no, const Properties ** value) const;
+
+ bool getCopy(const char * name, Uint32 no, char ** value) const;
+ bool getCopy(const char * name, Uint32 no, Properties ** value) const;
+
+ void clear();
+
+ void remove(const char * name);
+
+ void print(FILE * file = stdout, const char * prefix = 0) const;
+ /**
+ * Iterator over names
+ */
+ class Iterator {
+ public:
+ Iterator(const Properties* prop);
+
+ const char* first();
+ const char* next();
+ private:
+ const Properties* m_prop;
+ Uint32 m_iterator;
+ };
+ friend class Properties::Iterator;
+
+ Uint32 getPackedSize() const;
+ bool pack(Uint32 * buf) const;
+ bool pack(UtilBuffer &buf) const;
+ bool unpack(const Uint32 * buf, Uint32 bufLen);
+ bool unpack(UtilBuffer &buf);
+
+ Uint32 getPropertiesErrno() const { return propErrno; }
+ Uint32 getOSErrno() const { return osErrno; }
+private:
+ Uint32 propErrno;
+ Uint32 osErrno;
+
+ friend class PropertiesImpl;
+ class PropertiesImpl * impl;
+ class Properties * parent;
+
+ void setErrno(Uint32 pErr, Uint32 osErr = 0) const ;
+};
+
+/**
+ * Error code for properties
+ */
+
+/**
+ * No error
+ */
+extern const Uint32 E_PROPERTIES_OK;
+
+/**
+ * Invalid name in put, names can not contain Properties::delimiter
+ */
+extern const Uint32 E_PROPERTIES_INVALID_NAME;
+
+/**
+ * Element did not exist when using get
+ */
+extern const Uint32 E_PROPERTIES_NO_SUCH_ELEMENT;
+
+/**
+ * Element had wrong type when using get
+ */
+extern const Uint32 E_PROPERTIES_INVALID_TYPE;
+
+/**
+ * Element already existed when using put, and replace was not specified
+ */
+extern const Uint32 E_PROPERTIES_ELEMENT_ALREADY_EXISTS;
+
+/**
+ * Invalid version on properties file you are trying to read
+ */
+extern const Uint32 E_PROPERTIES_INVALID_VERSION_WHILE_UNPACKING;
+
+/**
+ * When unpacking an buffer
+ * found that buffer is to short
+ *
+ * Probably an invlaid buffer
+ */
+extern const Uint32 E_PROPERTIES_INVALID_BUFFER_TO_SHORT;
+
+/**
+ * Error when packing, can not allocate working buffer
+ *
+ * Note: OS error is set
+ */
+extern const Uint32 E_PROPERTIES_ERROR_MALLOC_WHILE_PACKING;
+
+/**
+ * Error when unpacking, can not allocate working buffer
+ *
+ * Note: OS error is set
+ */
+extern const Uint32 E_PROPERTIES_ERROR_MALLOC_WHILE_UNPACKING;
+
+/**
+ * Error when unpacking, invalid checksum
+ *
+ */
+extern const Uint32 E_PROPERTIES_INVALID_CHECKSUM;
+
+/**
+ * Error when unpacking
+ * No of items > 0 while size of buffer (left) <= 0
+ */
+extern const Uint32 E_PROPERTIES_BUFFER_TO_SMALL_WHILE_UNPACKING;
+
+inline bool
+Properties::unpack(UtilBuffer &buf) {
+ return unpack((const Uint32 *)buf.get_data(), buf.length());
+}
+
+inline bool
+Properties::pack(UtilBuffer &buf) const {
+ Uint32 size = getPackedSize();
+ char *tmp_buf = new char[size];
+ bool ret = pack((Uint32 *)tmp_buf);
+ if(ret == false)
+ return false;
+ buf.append(tmp_buf, size);
+ return true;
+}
+
+
+
+#endif
diff --git a/ndb/include/util/SimpleProperties.hpp b/ndb/include/util/SimpleProperties.hpp
new file mode 100644
index 00000000000..37e28ea91d8
--- /dev/null
+++ b/ndb/include/util/SimpleProperties.hpp
@@ -0,0 +1,290 @@
+/* Copyright (C) 2003 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+#ifndef SIMPLE_PROPERTIES_HPP
+#define SIMPLE_PROPERTIES_HPP
+
+#include <ndb_types.h>
+#include <stddef.h> // offsetof
+#include <NdbOut.hpp>
+
+/**
+ * @class SimpleProperties
+ * @brief Key-value-pair container. Actully a list of named elements.
+ *
+ * SimpleProperties:
+ * - The keys are Uint16
+ * - The values are either Uint32 or null terminated c-strings
+ *
+ * @note Keys may be repeated.
+ *
+ * Examples of things that can be stored in a SimpleProperties object:
+ * - Lists like: ((1, "foo"), (2, "bar"), (3, 32), (2, "baz"))
+ */
+class SimpleProperties {
+public:
+ /**
+ * Value types
+ */
+ enum ValueType {
+ Uint32Value = 0,
+ StringValue = 1,
+ BinaryValue = 2,
+ InvalidValue = 3
+ };
+
+ /**
+ * Struct for defining mapping to be used with unpack
+ */
+ struct SP2StructMapping {
+ Uint16 Key;
+ Uint32 Offset;
+ SimpleProperties::ValueType Type;
+ Uint32 minValue;
+ Uint32 maxValue;
+ Uint32 Length_Offset; // Offset used for looking up length of
+ // data if Type = BinaryValue
+ };
+
+ /**
+ * UnpackStatus - Value returned from unpack
+ */
+ enum UnpackStatus {
+ Eof = 0, // Success, end of SimpleProperties object reached
+ Break = 1, // Success
+ TypeMismatch = 2,
+ ValueTooLow = 3,
+ ValueTooHigh = 4,
+ UnknownKey = 5,
+ OutOfMemory = 6 // Only used when packing
+ };
+
+ /**
+ * Unpack
+ */
+ class Reader;
+ static UnpackStatus unpack(class Reader & it,
+ void * dst,
+ const SP2StructMapping[], Uint32 mapSz,
+ bool ignoreMinMax,
+ bool ignoreUnknownKeys);
+
+ class Writer;
+ static UnpackStatus pack(class Writer &,
+ const void * src,
+ const SP2StructMapping[], Uint32 mapSz,
+ bool ignoreMinMax);
+
+ /**
+ * Reader class
+ */
+ class Reader {
+ public:
+ /**
+ * Move to first element
+ * Return true if element exist
+ */
+ bool first();
+
+ /**
+ * Move to next element
+ * Return true if element exist
+ */
+ bool next();
+
+ /**
+ * Is this valid
+ */
+ bool valid() const;
+
+ /**
+ * Get key
+ * Note only valid is valid() == true
+ */
+ Uint16 getKey() const;
+
+ /**
+ * Get value length in bytes - (including terminating 0 for strings)
+ * Note only valid is valid() == true
+ */
+ Uint16 getValueLen() const;
+
+ /**
+ * Get value type
+ * Note only valid is valid() == true
+ */
+ ValueType getValueType() const;
+
+ /**
+ * Get value
+ * Note only valid is valid() == true
+ */
+ Uint32 getUint32() const;
+ char * getString(char * dst) const;
+
+ /**
+ * Print the complete simple properties (for debugging)
+ */
+ void printAll(NdbOut& ndbout);
+
+ private:
+ bool readValue();
+
+ Uint16 m_key;
+ Uint16 m_itemLen;
+ union {
+ Uint32 m_ui32_value;
+ Uint32 m_strLen; // Including 0-byte in words
+ };
+ ValueType m_type;
+ protected:
+ Reader();
+ virtual void reset() = 0;
+
+ virtual bool step(Uint32 len) = 0;
+ virtual bool getWord(Uint32 * dst) = 0;
+ virtual bool peekWord(Uint32 * dst) const = 0;
+ virtual bool peekWords(Uint32 * dst, Uint32 len) const = 0;
+ };
+
+ /**
+ * Writer class
+ */
+ class Writer {
+ public:
+ bool first();
+ bool add(Uint16 key, Uint32 value);
+ bool add(Uint16 key, const char * value);
+ bool add(Uint16 key, const void* value, int len);
+ protected:
+ virtual bool reset() = 0;
+ virtual bool putWord(Uint32 val) = 0;
+ virtual bool putWords(const Uint32 * src, Uint32 len) = 0;
+ };
+};
+
+/**
+ * Reader for linear memory
+ */
+class SimplePropertiesLinearReader : public SimpleProperties::Reader {
+public:
+ SimplePropertiesLinearReader(const Uint32 * src, Uint32 len);
+
+ virtual void reset();
+ virtual bool step(Uint32 len);
+ virtual bool getWord(Uint32 * dst);
+ virtual bool peekWord(Uint32 * dst) const ;
+ virtual bool peekWords(Uint32 * dst, Uint32 len) const;
+private:
+ Uint32 m_len;
+ Uint32 m_pos;
+ const Uint32 * m_src;
+};
+
+/**
+ * Writer for linear memory
+ */
+class LinearWriter : public SimpleProperties::Writer {
+public:
+ LinearWriter(Uint32 * src, Uint32 len);
+
+ virtual bool reset();
+ virtual bool putWord(Uint32 val);
+ virtual bool putWords(const Uint32 * src, Uint32 len);
+ Uint32 getWordsUsed() const;
+private:
+ Uint32 m_len;
+ Uint32 m_pos;
+ Uint32 * m_src;
+};
+
+/**
+ * Writer for linear memory
+ */
+class UtilBufferWriter : public SimpleProperties::Writer {
+public:
+ UtilBufferWriter(class UtilBuffer & buf);
+
+ virtual bool reset();
+ virtual bool putWord(Uint32 val);
+ virtual bool putWords(const Uint32 * src, Uint32 len);
+ Uint32 getWordsUsed() const;
+private:
+ class UtilBuffer & m_buf;
+};
+
+/**
+ * Reader for long signal section memory
+ *
+ *
+ * Implemented in kernel/vm/SimplePropertiesSection.cpp
+ */
+class SimplePropertiesSectionReader : public SimpleProperties::Reader {
+public:
+ SimplePropertiesSectionReader(class SegmentedSectionPtr &,
+ class SectionSegmentPool &);
+
+ virtual void reset();
+ virtual bool step(Uint32 len);
+ virtual bool getWord(Uint32 * dst);
+ virtual bool peekWord(Uint32 * dst) const ;
+ virtual bool peekWords(Uint32 * dst, Uint32 len) const;
+ Uint32 getSize() const;
+ bool getWords(Uint32 * dst, Uint32 len);
+
+private:
+ Uint32 m_pos;
+ Uint32 m_len;
+ class SectionSegmentPool & m_pool;
+ class SectionSegment * m_head;
+ class SectionSegment * m_currentSegment;
+};
+
+inline
+Uint32 SimplePropertiesSectionReader::getSize() const
+{
+ return m_len;
+}
+
+/**
+ * Writer for long signal section memory
+ *
+ *
+ * Implemented in kernel/vm/SimplePropertiesSection.cpp
+ */
+class SimplePropertiesSectionWriter : public SimpleProperties::Writer {
+public:
+ SimplePropertiesSectionWriter(class SectionSegmentPool &);
+
+ virtual bool reset();
+ virtual bool putWord(Uint32 val);
+ virtual bool putWords(const Uint32 * src, Uint32 len);
+
+ /**
+ * This "unlinks" the writer from the memory
+ */
+ void getPtr(class SegmentedSectionPtr & dst);
+
+private:
+ Int32 m_pos;
+ Uint32 m_sz;
+ class SectionSegmentPool & m_pool;
+ class SectionSegment * m_head;
+ Uint32 m_prevPtrI; // Prev to m_currentSegment
+ class SectionSegment * m_currentSegment;
+};
+
+#endif
diff --git a/ndb/include/util/SocketServer.hpp b/ndb/include/util/SocketServer.hpp
new file mode 100644
index 00000000000..334fa575e47
--- /dev/null
+++ b/ndb/include/util/SocketServer.hpp
@@ -0,0 +1,131 @@
+/* Copyright (C) 2003 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+#ifndef SOCKET_SERVER_HPP
+#define SOCKET_SERVER_HPP
+
+#include <NdbTCP.h>
+#include <NdbMutex.h>
+#include <NdbThread.h>
+#include <Vector.hpp>
+
+extern "C" void* sessionThread_C(void*);
+extern "C" void* socketServerThread_C(void*);
+
+/**
+ * Socket Server
+ */
+class SocketServer {
+public:
+ /**
+ * A Session
+ */
+ class Session {
+ public:
+ virtual ~Session() {}
+ virtual void runSession(){}
+ virtual void stopSession(){}
+ protected:
+ friend class SocketServer;
+ friend void* sessionThread_C(void*);
+ Session(NDB_SOCKET_TYPE sock): m_socket(sock){ m_stop = m_stopped = false;}
+
+ bool m_stop; // Has the session been ordered to stop?
+ bool m_stopped; // Has the session stopped?
+
+ NDB_SOCKET_TYPE m_socket;
+ };
+
+ /**
+ * A service i.e. a session factory
+ */
+ class Service {
+ public:
+ virtual ~Service(){}
+
+ /**
+ * Returned Session will be ran in own thread
+ *
+ * To manage threads self, just return NULL
+ */
+ virtual Session * newSession(NDB_SOCKET_TYPE theSock) = 0;
+ virtual void stopSessions(){}
+ };
+
+ /**
+ * Constructor / Destructor
+ */
+ SocketServer(int maxSessions = 32);
+ ~SocketServer();
+
+ /**
+ * Setup socket and bind it
+ * then close the socket
+ * Returns true if succeding in binding
+ */
+ bool tryBind(unsigned short port, const char * intface = 0) const;
+
+ /**
+ * Setup socket
+ * bind & listen
+ * Returns false if no success
+ */
+ bool setup(Service *, unsigned short port, const char * pinterface = 0);
+
+ /**
+ * start/stop the server
+ */
+ void startServer();
+ void stopServer();
+
+ /**
+ * stop sessions
+ *
+ * Note: Implies stopServer
+ */
+ void stopSessions(bool wait = false);
+
+private:
+ struct SessionInstance {
+ Service * m_service;
+ Session * m_session;
+ NdbThread * m_thread;
+ };
+ struct ServiceInstance {
+ Service * m_service;
+ NDB_SOCKET_TYPE m_socket;
+ };
+ MutexVector<SessionInstance> m_sessions;
+ MutexVector<ServiceInstance> m_services;
+ unsigned m_maxSessions;
+
+ void doAccept();
+ void checkSessions();
+ void startSession(SessionInstance &);
+
+ /**
+ * Note, this thread is only used when running interactive
+ *
+ */
+ bool m_stopThread;
+ struct NdbThread * m_thread;
+ NdbLockable m_threadLock;
+ void doRun();
+ friend void* socketServerThread_C(void*);
+ friend void* sessionThread_C(void*);
+};
+
+#endif
diff --git a/ndb/include/util/UtilBuffer.hpp b/ndb/include/util/UtilBuffer.hpp
new file mode 100644
index 00000000000..97821ee3f9b
--- /dev/null
+++ b/ndb/include/util/UtilBuffer.hpp
@@ -0,0 +1,90 @@
+/* Copyright (C) 2003 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+#ifndef __BUFFER_HPP_INCLUDED__
+#define __BUFFER_HPP_INCLUDED__
+
+#include <unistd.h>
+#include <errno.h>
+#include <stdlib.h>
+
+/* This class represents a buffer of binary data, where you can append
+ * data at the end, and later read the entire bunch.
+ * It will take care of the hairy details of realloc()ing the space
+ * for you
+ */
+class UtilBuffer {
+public:
+ UtilBuffer() { data = NULL; len = 0; alloc_size = 0; };
+ ~UtilBuffer() { if(data) free(data); data = NULL; len = 0; alloc_size = 0; };
+
+
+ int reallocate(size_t newsize) {
+ if(newsize < len) {
+ errno = EINVAL;
+ return -1;
+ }
+ void *newdata;
+ if((newdata = realloc(data, newsize)) == NULL) {
+ errno = ENOMEM;
+ return -1;
+ }
+ alloc_size = newsize;
+ data = newdata;
+ return 0;
+ };
+
+ int grow(size_t l) {
+ if(l > alloc_size)
+ return reallocate(l);
+ return 0;
+ };
+
+ int append(const void *d, size_t l) {
+ int ret;
+ ret = grow(len+l);
+ if(ret != 0)
+ return ret;
+
+ memcpy((char *)data+len, d, l);
+ len+=l;
+
+ return 0;
+ };
+
+ int assign(const void * d, size_t l) {
+ if (data) free(data);
+ data = NULL;
+ len = 0;
+ alloc_size = 0;
+ return append(d, l);
+ }
+
+ void clear() {
+ len = 0;
+ }
+
+ int length() const { return len; };
+
+ void *get_data() const { return data; };
+private:
+ void *data; /* Pointer to data storage */
+ size_t len; /* Size of the stored data */
+ size_t alloc_size; /* Size of the allocated space,
+ * i.e. len can grow to this size */
+};
+
+#endif /* !__BUFFER_HPP_INCLUDED__ */
diff --git a/ndb/include/util/Vector.hpp b/ndb/include/util/Vector.hpp
new file mode 100644
index 00000000000..a717dfecd7e
--- /dev/null
+++ b/ndb/include/util/Vector.hpp
@@ -0,0 +1,289 @@
+/* Copyright (C) 2003 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+#ifndef NDB_VECTOR_HPP
+#define NDB_VECTOR_HPP
+
+#include <stdlib.h>
+#include <NdbMutex.h>
+#include <string.h>
+
+template<class T>
+struct Vector {
+public:
+ Vector(int sz = 10);
+ ~Vector();
+
+ T& operator[](unsigned i);
+ const T& operator[](unsigned i) const;
+ unsigned size() const { return m_size; };
+
+ void push_back(const T &);
+ T& back();
+
+ void erase(unsigned index);
+
+ void clear();
+
+ void fill(unsigned new_size, T & obj);
+
+ Vector<T>& operator=(const Vector<T>&);
+
+ T* getBase() { return m_items;}
+ const T* getBase() const { return m_items;}
+private:
+ T * m_items;
+ unsigned m_size;
+ unsigned m_incSize;
+ unsigned m_arraySize;
+};
+
+template<class T>
+Vector<T>::Vector(int i){
+ m_items = new T[i];
+ m_size = 0;
+ m_arraySize = i;
+ m_incSize = 50;
+}
+
+template<class T>
+Vector<T>::~Vector(){
+ delete[] m_items;
+}
+
+template<class T>
+T &
+Vector<T>::operator[](unsigned i){
+ if(i >= m_size)
+ abort();
+ return m_items[i];
+}
+
+template<class T>
+const T &
+Vector<T>::operator[](unsigned i) const {
+ if(i >= m_size)
+ abort();
+ return m_items[i];
+}
+
+template<class T>
+T &
+Vector<T>::back(){
+ return (* this)[m_size - 1];
+}
+
+template<class T>
+void
+Vector<T>::push_back(const T & t){
+ if(m_size == m_arraySize){
+ T * tmp = new T [m_arraySize + m_incSize];
+ for (unsigned k = 0; k < m_size; k++)
+ tmp[k] = m_items[k];
+ delete[] m_items;
+ m_items = tmp;
+ m_arraySize = m_arraySize + m_incSize;
+ }
+ m_items[m_size] = t;
+ m_size++;
+}
+
+template<class T>
+void
+Vector<T>::erase(unsigned i){
+ if(i >= m_size)
+ abort();
+
+ for (unsigned k = i; k + 1 < m_size; k++)
+ m_items[k] = m_items[k + 1];
+ m_size--;
+}
+
+template<class T>
+void
+Vector<T>::clear(){
+ m_size = 0;
+}
+
+template<class T>
+void
+Vector<T>::fill(unsigned new_size, T & obj){
+ while(m_size <= new_size)
+ push_back(obj);
+}
+
+template<class T>
+Vector<T>&
+Vector<T>::operator=(const Vector<T>& obj){
+ if(this != &obj){
+ clear();
+ for(size_t i = 0; i<obj.size(); i++){
+ push_back(obj[i]);
+ }
+ }
+ return * this;
+}
+
+template<class T>
+struct MutexVector : public NdbLockable {
+ MutexVector(int sz = 10);
+ ~MutexVector();
+
+ T& operator[](unsigned i);
+ const T& operator[](unsigned i) const;
+ unsigned size() const { return m_size; };
+
+ void push_back(const T &);
+ void push_back(const T &, bool lockMutex);
+ T& back();
+
+ void erase(unsigned index);
+ void erase(unsigned index, bool lockMutex);
+
+ void clear();
+ void clear(bool lockMutex);
+
+ void fill(unsigned new_size, T & obj);
+private:
+ T * m_items;
+ unsigned m_size;
+ unsigned m_incSize;
+ unsigned m_arraySize;
+};
+
+template<class T>
+MutexVector<T>::MutexVector(int i){
+ m_items = new T[i];
+ m_size = 0;
+ m_arraySize = i;
+ m_incSize = 50;
+}
+
+template<class T>
+MutexVector<T>::~MutexVector(){
+ delete[] m_items;
+}
+
+template<class T>
+T &
+MutexVector<T>::operator[](unsigned i){
+ if(i >= m_size)
+ abort();
+ return m_items[i];
+}
+
+template<class T>
+const T &
+MutexVector<T>::operator[](unsigned i) const {
+ if(i >= m_size)
+ abort();
+ return m_items[i];
+}
+
+template<class T>
+T &
+MutexVector<T>::back(){
+ return (* this)[m_size - 1];
+}
+
+template<class T>
+void
+MutexVector<T>::push_back(const T & t){
+ lock();
+ if(m_size == m_arraySize){
+ T * tmp = new T [m_arraySize + m_incSize];
+ for (unsigned k = 0; k < m_size; k++)
+ tmp[k] = m_items[k];
+ delete[] m_items;
+ m_items = tmp;
+ m_arraySize = m_arraySize + m_incSize;
+ }
+ m_items[m_size] = t;
+ m_size++;
+ unlock();
+}
+
+template<class T>
+void
+MutexVector<T>::push_back(const T & t, bool lockMutex){
+ if(lockMutex)
+ lock();
+ if(m_size == m_arraySize){
+ T * tmp = new T [m_arraySize + m_incSize];
+ for (unsigned k = 0; k < m_size; k++)
+ tmp[k] = m_items[k];
+ delete[] m_items;
+ m_items = tmp;
+ m_arraySize = m_arraySize + m_incSize;
+ }
+ m_items[m_size] = t;
+ m_size++;
+ if(lockMutex)
+ unlock();
+}
+
+template<class T>
+void
+MutexVector<T>::erase(unsigned i){
+ if(i >= m_size)
+ abort();
+
+ lock();
+ for (unsigned k = i; k + 1 < m_size; k++)
+ m_items[k] = m_items[k + 1];
+ m_size--;
+ unlock();
+}
+
+template<class T>
+void
+MutexVector<T>::erase(unsigned i, bool _lock){
+ if(i >= m_size)
+ abort();
+
+ if(_lock)
+ lock();
+ for (unsigned k = i; k + 1 < m_size; k++)
+ m_items[k] = m_items[k + 1];
+ m_size--;
+ if(_lock)
+ unlock();
+}
+
+template<class T>
+void
+MutexVector<T>::clear(){
+ lock();
+ m_size = 0;
+ unlock();
+}
+
+template<class T>
+void
+MutexVector<T>::clear(bool l){
+ if(l) lock();
+ m_size = 0;
+ if(l) unlock();
+}
+
+template<class T>
+void
+MutexVector<T>::fill(unsigned new_size, T & obj){
+ while(m_size <= new_size)
+ push_back(obj);
+}
+
+#endif
diff --git a/ndb/include/util/getarg.h b/ndb/include/util/getarg.h
new file mode 100644
index 00000000000..713cf6e4b32
--- /dev/null
+++ b/ndb/include/util/getarg.h
@@ -0,0 +1,115 @@
+/* Copyright (C) 2003 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+/*
+ * Copyright (c) 1997, 1999 Kungliga Tekniska Högskolan
+ * (Royal Institute of Technology, Stockholm, Sweden).
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the Institute nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/* $KTH: getarg.h,v 1.9 2000/09/01 21:25:55 lha Exp $ */
+
+#ifndef __GETARG_H__
+#define __GETARG_H__
+
+#include <stddef.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef enum {
+ arg_integer,
+ arg_string,
+ arg_flag,
+ arg_negative_flag,
+ arg_strings,
+ arg_double,
+ arg_collect,
+ arg_counter
+} arg_type;
+
+struct getargs{
+ const char *long_name;
+ char short_name;
+ arg_type type;
+ void *value;
+ const char *help;
+ const char *arg_help;
+};
+
+enum {
+ ARG_ERR_NO_MATCH = 1,
+ ARG_ERR_BAD_ARG,
+ ARG_ERR_NO_ARG
+};
+
+typedef struct getarg_strings {
+ int num_strings;
+ char **strings;
+} getarg_strings;
+
+typedef int (*getarg_collect_func)(int short_opt,
+ int argc,
+ const char **argv,
+ int *optind,
+ int *optarg,
+ void *data);
+
+typedef struct getarg_collect_info {
+ getarg_collect_func func;
+ void *data;
+} getarg_collect_info;
+
+int getarg(struct getargs *args, size_t num_args,
+ int argc, const char **argv, int *optind);
+
+void arg_printusage (struct getargs *args,
+ size_t num_args,
+ const char *progname,
+ const char *extra_string);
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __GETARG_H__ */
diff --git a/ndb/include/util/md5_hash.hpp b/ndb/include/util/md5_hash.hpp
new file mode 100644
index 00000000000..4c3cf239881
--- /dev/null
+++ b/ndb/include/util/md5_hash.hpp
@@ -0,0 +1,25 @@
+/* Copyright (C) 2003 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+#ifndef MD5_HASH_H
+#define MD5_HASH_H
+
+#include <ndb_types.h>
+
+// External declaration of hash function
+Uint32 md5_hash(const Uint64* keybuf, Uint32 no_of_32_words);
+
+#endif
diff --git a/ndb/include/util/random.h b/ndb/include/util/random.h
new file mode 100644
index 00000000000..1b83e5fec93
--- /dev/null
+++ b/ndb/include/util/random.h
@@ -0,0 +1,84 @@
+/* Copyright (C) 2003 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+#ifndef RANDOM_H
+#define RANDOM_H
+
+/***************************************************************
+* I N C L U D E D F I L E S *
+***************************************************************/
+
+/***************************************************************
+* M A C R O S *
+***************************************************************/
+
+/***************************************************************/
+/* C O N S T A N T S */
+/***************************************************************/
+
+
+/***************************************************************
+* D A T A S T R U C T U R E S *
+***************************************************************/
+
+typedef struct {
+ unsigned int length;
+ unsigned int *values;
+ unsigned int currentIndex;
+}RandomSequence;
+
+typedef struct {
+ unsigned int length;
+ unsigned int value;
+}SequenceValues;
+
+/***************************************************************
+* P U B L I C F U N C T I O N S *
+***************************************************************/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+extern double getTps(unsigned int count, double timeValue);
+
+/*----------------------------*/
+/* Random Sequences Functions */
+/*----------------------------*/
+extern int initSequence(RandomSequence *seq, SequenceValues *inputValues);
+extern unsigned int getNextRandom(RandomSequence *seq);
+extern void printSequence(RandomSequence *seq, unsigned int numPerRow);
+
+/*---------------------------------------------------*/
+/* Code from the glibc, to make sure the same random */
+/* number generator is used by all */
+/*---------------------------------------------------*/
+extern void myRandom48Init(long int seedval);
+extern long int myRandom48(unsigned int maxValue);
+
+#ifdef __cplusplus
+}
+#endif
+
+/***************************************************************
+* E X T E R N A L D A T A *
+***************************************************************/
+
+
+
+#endif /* RANDOM_H */
+
diff --git a/ndb/include/util/socket_io.h b/ndb/include/util/socket_io.h
new file mode 100644
index 00000000000..bbd1bf115ae
--- /dev/null
+++ b/ndb/include/util/socket_io.h
@@ -0,0 +1,40 @@
+/* Copyright (C) 2003 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+#ifndef _SOCKET_IO_H
+#define _SOCKET_IO_H
+
+#include <NdbTCP.h>
+#include <stdarg.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+ int read_socket(NDB_SOCKET_TYPE, int timeout_ms, char *, int len);
+ int readln_socket(NDB_SOCKET_TYPE, int timeout_ms, char *, int len);
+ int write_socket(NDB_SOCKET_TYPE, int timeout_ms, const char[], int len);
+
+ int print_socket(NDB_SOCKET_TYPE, int timeout_ms, const char *, ...);
+ int println_socket(NDB_SOCKET_TYPE, int timeout_ms, const char *, ...);
+ int vprint_socket(NDB_SOCKET_TYPE, int timeout_ms, const char *, va_list);
+ int vprintln_socket(NDB_SOCKET_TYPE, int timeout_ms, const char *, va_list);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/ndb/include/util/uucode.h b/ndb/include/util/uucode.h
new file mode 100644
index 00000000000..138a79fa3ae
--- /dev/null
+++ b/ndb/include/util/uucode.h
@@ -0,0 +1,36 @@
+/* Copyright (C) 2003 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+#ifndef UUCODE_H
+#define UUCODE_H
+
+#include <stdio.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+ void uuencode(const char * data, int dataLen, FILE * out);
+ int uudecode(FILE * input, char * outBuf, int bufLen);
+
+ int uuencode_mem(char * dst, const char * src, int src_len);
+ int uudecode_mem(char * dst, int dst_len, const char * src);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/ndb/include/util/version.h b/ndb/include/util/version.h
new file mode 100644
index 00000000000..a82ae4b8b52
--- /dev/null
+++ b/ndb/include/util/version.h
@@ -0,0 +1,50 @@
+/* Copyright (C) 2003 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+
+#ifndef VERSION_H
+#define VERSION_H
+#include <ndb_types.h>
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+ Uint32 getMajor(Uint32 version);
+
+ Uint32 getMinor(Uint32 version);
+
+ Uint32 getBuild(Uint32 version);
+
+ Uint32 makeVersion(Uint32 major, Uint32 minor, Uint32 build);
+
+ char* getVersionString(Uint32 version, char * status);
+
+ void ndbPrintVersion();
+ Uint32 ndbGetOwnVersion();
+
+ int ndbCompatible_mgmt_ndb(Uint32 ownVersion, Uint32 otherVersion);
+ int ndbCompatible_ndb_mgmt(Uint32 ownVersion, Uint32 otherVersion);
+ int ndbCompatible_mgmt_api(Uint32 ownVersion, Uint32 otherVersion);
+ int ndbCompatible_api_mgmt(Uint32 ownVersion, Uint32 otherVersion);
+ int ndbCompatible_api_ndb(Uint32 ownVersion, Uint32 otherVersion);
+ int ndbCompatible_ndb_api(Uint32 ownVersion, Uint32 otherVersion);
+ int ndbCompatible_ndb_ndb(Uint32 ownVersion, Uint32 otherVersion);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif