summaryrefslogtreecommitdiff
path: root/libs/util/include
diff options
context:
space:
mode:
Diffstat (limited to 'libs/util/include')
-rw-r--r--libs/util/include/AbstractListAssembler.h49
-rw-r--r--libs/util/include/Codec.h92
-rw-r--r--libs/util/include/JSonWriter.h64
-rw-r--r--libs/util/include/MD5Calculator.h45
-rw-r--r--libs/util/include/ManagedMap.h55
-rw-r--r--libs/util/include/ManagedVector.h49
-rw-r--r--libs/util/include/NamedValue.h51
-rw-r--r--libs/util/include/StringBuilder.h60
-rw-r--r--libs/util/include/util.h38
9 files changed, 503 insertions, 0 deletions
diff --git a/libs/util/include/AbstractListAssembler.h b/libs/util/include/AbstractListAssembler.h
new file mode 100644
index 0000000..1e547e4
--- /dev/null
+++ b/libs/util/include/AbstractListAssembler.h
@@ -0,0 +1,49 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: AbstractListAssembler.h
+ * Created: 6. Juli 2012, 09:38
+ * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
+ * Project: libutil - base classes used by other libraries
+ *
+ * CMP - compound media player
+ *
+ * is a client/server mediaplayer intended to play any media from any workstation
+ * without the need to export or mount shares. cmps is an easy to use backend
+ * with a (ready to use) HTML-interface. Additionally the backend supports
+ * authentication via HTTP-digest authorization.
+ * cmpc is a client with vdr-like osd-menues.
+ *
+ * Copyright (c) 2012 Reinhard Mantey, some rights reserved!
+ * published under Creative Commons by-sa
+ * For details see http://creativecommons.org/licenses/by-sa/3.0/
+ *
+ * The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp
+ *
+ * --------------------------------------------------------------
+ */
+#ifndef ABSTRACTLISTASSEMBLER_H
+#define ABSTRACTLISTASSEMBLER_H
+
+#include <sys/types.h>
+#include <map>
+
+class cStringBuilder;
+class cManagedVector;
+class cAbstractListAssembler {
+public:
+ cAbstractListAssembler();
+ virtual ~cAbstractListAssembler();
+
+ bool AssembleList(cStringBuilder &sb, cManagedVector &ElemVector, std::map<int, size_t> &Categories, size_t start = 0, uint delta = 40);
+
+ virtual const char *MediaType(void) const = 0;
+
+protected:
+ virtual bool OpenList(cStringBuilder &sb, std::map<int, size_t> &Categories, size_t total, size_t start = 0, uint delta = 40) = 0;
+ virtual bool AddElement(cStringBuilder &sb, void *, bool odd) = 0;
+ virtual bool CloseList(cStringBuilder &sb, size_t total, size_t start = 0, uint delta = 40) = 0;
+};
+
+#endif /* ABSTRACTLISTASSEMBLER_H */
+
diff --git a/libs/util/include/Codec.h b/libs/util/include/Codec.h
new file mode 100644
index 0000000..80352d7
--- /dev/null
+++ b/libs/util/include/Codec.h
@@ -0,0 +1,92 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: Codec.h
+ * Created: 21. Mai 2012, 14:00
+ * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
+ * Project: libutil - base classes used by other libraries
+ *
+ * CMP - compound media player
+ *
+ * is a client/server mediaplayer intended to play any media from any workstation
+ * without the need to export or mount shares. cmps is an easy to use backend
+ * with a (ready to use) HTML-interface. Additionally the backend supports
+ * authentication via HTTP-digest authorization.
+ * cmpc is a client with vdr-like osd-menues.
+ *
+ * Copyright (c) 2012 Reinhard Mantey, some rights reserved!
+ * published under Creative Commons by-sa
+ * For details see http://creativecommons.org/licenses/by-sa/3.0/
+ *
+ * The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp
+ *
+ * --------------------------------------------------------------
+ */
+#ifndef CODEC_H
+#define CODEC_H
+
+#include <stddef.h>
+
+class cCodec {
+///< base class for simple (character based) encoding/decoding
+public:
+ cCodec(const char *Table, char KeyChar = '#');
+ virtual ~cCodec();
+ char KeyChar() const { return keyChar; }
+ const char *TranslateTable() const { return translateTable; }
+ virtual size_t DecodeSequence(unsigned char *d, unsigned char *s);
+
+protected:
+ char *translateTable;
+ char keyChar;
+ };
+
+class cEncoder : public cCodec {
+public:
+ cEncoder(char SpecialChar = '#', const char *TrTable = "0123456789ABCDEF");
+ virtual ~cEncoder();
+ char *Encode(const char *Source, size_t SourceLength = 0); ///< encode Source,
+ ///< optionally limited by SourceLength (default is to encode a 0-terminated cstring)
+ };
+
+class cURLEncoder : public cEncoder {
+public:
+ cURLEncoder();
+ virtual ~cURLEncoder();
+ };
+
+class cDecoder : public cCodec {
+public:
+ cDecoder(char KeyChar = '#', const char *TrTable = "0123456789ABCDEF");
+ virtual ~cDecoder();
+ char *Decode(const char *Source, size_t SourceLength = 0); ///< decode Source,
+ ///< optionally limited by SourceLength (default is to decode a 0-terminated cstring)
+ virtual size_t DecodeSequence(unsigned char *d, unsigned char *s);
+ };
+
+class cURLDecoder : public cDecoder {
+public:
+ cURLDecoder();
+ virtual ~cURLDecoder();
+ };
+
+class cHexEncoder : public cEncoder {
+public:
+ cHexEncoder();
+ virtual ~cHexEncoder();
+ char *Encode(const unsigned char* Source, size_t SourceLength = 0);
+ };
+
+class cHexDecoder : public cDecoder {
+public:
+ cHexDecoder();
+ virtual ~cHexDecoder();
+ char *Decode(const char *Source, size_t SourceLength = 0);
+ };
+
+extern cHexEncoder * getHexEncoder(void);
+extern cHexDecoder * getHexDecoder(void);
+extern void codecCleanUp(void);
+
+#endif /* CODEC_H */
+
diff --git a/libs/util/include/JSonWriter.h b/libs/util/include/JSonWriter.h
new file mode 100644
index 0000000..732daec
--- /dev/null
+++ b/libs/util/include/JSonWriter.h
@@ -0,0 +1,64 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: JSonWriter.h
+ * Created: 6. Juli 2012, 12:47
+ * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
+ * Project: libutil - base classes used by other libraries
+ *
+ * CMP - compound media player
+ *
+ * is a client/server mediaplayer intended to play any media from any workstation
+ * without the need to export or mount shares. cmps is an easy to use backend
+ * with a (ready to use) HTML-interface. Additionally the backend supports
+ * authentication via HTTP-digest authorization.
+ * cmpc is a client with vdr-like osd-menues.
+ *
+ * Copyright (c) 2012 Reinhard Mantey, some rights reserved!
+ * published under Creative Commons by-sa
+ * For details see http://creativecommons.org/licenses/by-sa/3.0/
+ *
+ * The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp
+ *
+ * --------------------------------------------------------------
+ */
+#ifndef JSONWRITER_H
+#define JSONWRITER_H
+
+#include <stack>
+#include <StringBuilder.h>
+
+class cJSonWriter {
+public:
+ cJSonWriter(cStringBuilder &StringBuilder);
+ virtual ~cJSonWriter();
+
+ cJSonWriter &Object(void);
+ cJSonWriter &EndObject(void);
+ cJSonWriter &Array(void);
+ cJSonWriter &EndArray(void);
+ cJSonWriter &Key(const char *Name);
+ cJSonWriter &Value(const char *Text);
+ cJSonWriter &Value(int v);
+ cJSonWriter &Value(long v);
+ cJSonWriter &Value(size_t v);
+ cJSonWriter &Value(bool v);
+ cJSonWriter &Value(double v);
+
+private:
+ typedef enum {
+ JS_Unknown,
+ JS_Object,
+ JS_Array,
+ JS_Key
+ } JSonState;
+ cJSonWriter::JSonState State(void);
+ void PushState(JSonState State);
+ cJSonWriter::JSonState PopState(void);
+ std::stack<JSonState> state;
+ JSonState lastState;
+ cStringBuilder &sb;
+};
+
+#endif /* JSONWRITER_H */
+
diff --git a/libs/util/include/MD5Calculator.h b/libs/util/include/MD5Calculator.h
new file mode 100644
index 0000000..400aba1
--- /dev/null
+++ b/libs/util/include/MD5Calculator.h
@@ -0,0 +1,45 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: MD5Calculator.h
+ * Created: 3. Juli 2012, 13:15
+ * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
+ * Project: libutil - base classes used by other libraries
+ *
+ * CMP - compound media player
+ *
+ * is a client/server mediaplayer intended to play any media from any workstation
+ * without the need to export or mount shares. cmps is an easy to use backend
+ * with a (ready to use) HTML-interface. Additionally the backend supports
+ * authentication via HTTP-digest authorization.
+ * cmpc is a client with vdr-like osd-menues.
+ *
+ * Copyright (c) 2012 Reinhard Mantey, some rights reserved!
+ * published under Creative Commons by-sa
+ * For details see http://creativecommons.org/licenses/by-sa/3.0/
+ *
+ * The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp
+ *
+ * --------------------------------------------------------------
+ */
+#ifndef MD5CALCULATOR_H
+#define MD5CALCULATOR_H
+
+#include <openssl/md5.h>
+
+class cMD5Calculator {
+public:
+ cMD5Calculator();
+ virtual ~cMD5Calculator();
+
+ void AddContent(const char *Buf, size_t bufSize = 0);
+
+ char *Hash(void);
+ void Reset(void);
+
+private:
+ MD5_CTX context;
+ };
+
+#endif /* MD5CALCULATOR_H */
+
diff --git a/libs/util/include/ManagedMap.h b/libs/util/include/ManagedMap.h
new file mode 100644
index 0000000..c71de85
--- /dev/null
+++ b/libs/util/include/ManagedMap.h
@@ -0,0 +1,55 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: ManagedMap.h
+ * Created: 7. Juli 2012, 08:28
+ * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
+ * Project: libutil - base classes used by other libraries
+ *
+ * CMP - compound media player
+ *
+ * is a client/server mediaplayer intended to play any media from any workstation
+ * without the need to export or mount shares. cmps is an easy to use backend
+ * with a (ready to use) HTML-interface. Additionally the backend supports
+ * authentication via HTTP-digest authorization.
+ * cmpc is a client with vdr-like osd-menues.
+ *
+ * Copyright (c) 2012 Reinhard Mantey, some rights reserved!
+ * published under Creative Commons by-sa
+ * For details see http://creativecommons.org/licenses/by-sa/3.0/
+ *
+ * The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp
+ *
+ * --------------------------------------------------------------
+ */
+#ifndef MANAGEDMAP_H
+#define MANAGEDMAP_H
+
+#include <string>
+#include <tr1/unordered_map>
+
+class cManagedMap {
+public:
+ typedef std::tr1::unordered_map<std::string, void *>::const_iterator const_iterator;
+
+ cManagedMap(void (*cbFreeElem)(void *));
+ virtual ~cManagedMap();
+
+ void clear(void);
+ void put(const char *key, void *value);
+ void *get(const char *key);
+ const void *get(const char *key) const;
+ size_t size(void) { return internalMap.size(); }
+
+ const_iterator begin() const { return internalMap.begin(); }
+ const_iterator end() const { return internalMap.end(); }
+
+private:
+ std::tr1::unordered_map<std::string, void *> internalMap;
+ void (*freeCallback)(void *);
+ typedef std::tr1::unordered_map<std::string, void *>::iterator iterator;
+};
+
+
+#endif /* MANAGEDMAP_H */
+
diff --git a/libs/util/include/ManagedVector.h b/libs/util/include/ManagedVector.h
new file mode 100644
index 0000000..7fa7af2
--- /dev/null
+++ b/libs/util/include/ManagedVector.h
@@ -0,0 +1,49 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: ManagedVector.h
+ * Created: 6. Juli 2012, 19:07
+ * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
+ * Project: libutil - base classes used by other libraries
+ *
+ * CMP - compound media player
+ *
+ * is a client/server mediaplayer intended to play any media from any workstation
+ * without the need to export or mount shares. cmps is an easy to use backend
+ * with a (ready to use) HTML-interface. Additionally the backend supports
+ * authentication via HTTP-digest authorization.
+ * cmpc is a client with vdr-like osd-menues.
+ *
+ * Copyright (c) 2012 Reinhard Mantey, some rights reserved!
+ * published under Creative Commons by-sa
+ * For details see http://creativecommons.org/licenses/by-sa/3.0/
+ *
+ * The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp
+ *
+ * --------------------------------------------------------------
+ */
+#ifndef MANAGEDVECTOR_H
+#define MANAGEDVECTOR_H
+
+#include <vector>
+#include <stdlib.h>
+
+class cManagedVector {
+public:
+ cManagedVector(void (*cbFreeElem)(void *));
+ virtual ~cManagedVector();
+
+ void clear(void);
+ void push_back(void *p) { internalVector.push_back(p); }
+ void *operator[](size_t n) { return internalVector[n]; }
+ const void *operator[](size_t n) const { return internalVector[n]; }
+ size_t size(void) const { return internalVector.size(); }
+ void sort(bool (*fnSort)(void *a, void *b));
+
+private:
+ std::vector<void *> internalVector;
+ void (*freeCallback)(void *);
+ };
+
+#endif /* MANAGEDVECTOR_H */
+
diff --git a/libs/util/include/NamedValue.h b/libs/util/include/NamedValue.h
new file mode 100644
index 0000000..329061d
--- /dev/null
+++ b/libs/util/include/NamedValue.h
@@ -0,0 +1,51 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: NamedValue.h
+ * Created: 3. Juli 2012, 17:43
+ * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
+ * Project: libutil - base classes used by other libraries
+ *
+ * CMP - compound media player
+ *
+ * is a client/server mediaplayer intended to play any media from any workstation
+ * without the need to export or mount shares. cmps is an easy to use backend
+ * with a (ready to use) HTML-interface. Additionally the backend supports
+ * authentication via HTTP-digest authorization.
+ * cmpc is a client with vdr-like osd-menues.
+ *
+ * Copyright (c) 2012 Reinhard Mantey, some rights reserved!
+ * published under Creative Commons by-sa
+ * For details see http://creativecommons.org/licenses/by-sa/3.0/
+ *
+ * The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp
+ *
+ * --------------------------------------------------------------
+ */
+#ifndef NAMEDVALUE_H
+#define NAMEDVALUE_H
+
+#include <stddef.h>
+#include <string.h>
+#include <stdlib.h>
+#include <vector>
+
+class cNamedValue {
+public:
+ cNamedValue(char *Name, char *Value = NULL, bool takePointers = false);
+ cNamedValue(const char *Name, const char *Value = NULL);
+ cNamedValue(const cNamedValue &other);
+ virtual ~cNamedValue();
+ cNamedValue &operator =(const cNamedValue &other);
+
+ const char *Name() const { return name; }
+ const char *Value() const { return value; }
+ void SetValue(const char *Value) { free(value); value = strdup(Value); }
+
+private:
+ char *name;
+ char *value;
+ };
+
+#endif /* NAMEDVALUE_H */
+
diff --git a/libs/util/include/StringBuilder.h b/libs/util/include/StringBuilder.h
new file mode 100644
index 0000000..aea9975
--- /dev/null
+++ b/libs/util/include/StringBuilder.h
@@ -0,0 +1,60 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: StringBuilder.h
+ * Created: 6. Juli 2012, 10:54
+ * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
+ * Project: libutil - base classes used by other libraries
+ *
+ * CMP - compound media player
+ *
+ * is a client/server mediaplayer intended to play any media from any workstation
+ * without the need to export or mount shares. cmps is an easy to use backend
+ * with a (ready to use) HTML-interface. Additionally the backend supports
+ * authentication via HTTP-digest authorization.
+ * cmpc is a client with vdr-like osd-menues.
+ *
+ * Copyright (c) 2012 Reinhard Mantey, some rights reserved!
+ * published under Creative Commons by-sa
+ * For details see http://creativecommons.org/licenses/by-sa/3.0/
+ *
+ * The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp
+ *
+ * --------------------------------------------------------------
+ */
+#ifndef STRINGBUILDER_H
+#define STRINGBUILDER_H
+
+#include <ManagedVector.h>
+#include <time.h>
+
+class cStringBuilder {
+public:
+ cStringBuilder(const char *First);
+ cStringBuilder(int chunkSize = 127);
+ virtual ~cStringBuilder();
+
+ cStringBuilder &Append(const char *Text);
+ cStringBuilder &Append(bool v, const char *TrueValue = "X", const char *FalseValue="-");
+ cStringBuilder &Append(double v);
+ cStringBuilder &Append(int v);
+ cStringBuilder &Append(long v);
+ cStringBuilder &Append(size_t s);
+
+ void Clear(void);
+ size_t Size(void);
+ size_t Size(void) const;
+ void Rewind(void) { readOffset = 0; }
+ size_t Copy(char *Buf, size_t BufSize);
+
+private:
+ void init(void);
+ void Write(const char *p);
+ int chunkSize;
+ size_t readOffset; ///< read offest is the offset over all chunks (thus goes from 0 to size)
+ int writeOffset; ///< write offset is the offset inside the last chunk (thus goes from 0 to chunkSize)
+ cManagedVector pool;
+ };
+
+#endif /* STRINGBUILDER_H */
+
diff --git a/libs/util/include/util.h b/libs/util/include/util.h
new file mode 100644
index 0000000..2b355cc
--- /dev/null
+++ b/libs/util/include/util.h
@@ -0,0 +1,38 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: util.h
+ * Created: 3. Juli 2012, 13:00
+ * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
+ * Project: libutil - base classes used by other libraries
+ *
+ * CMP - compound media player
+ *
+ * is a client/server mediaplayer intended to play any media from any workstation
+ * without the need to export or mount shares. cmps is an easy to use backend
+ * with a (ready to use) HTML-interface. Additionally the backend supports
+ * authentication via HTTP-digest authorization.
+ * cmpc is a client with vdr-like osd-menues.
+ *
+ * Copyright (c) 2012 Reinhard Mantey, some rights reserved!
+ * published under Creative Commons by-sa
+ * For details see http://creativecommons.org/licenses/by-sa/3.0/
+ *
+ * The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp
+ *
+ * --------------------------------------------------------------
+ */
+#ifndef UTIL_H
+#define UTIL_H
+
+#include <stdlib.h>
+#define FREE(m) { void *_tmp_ = m; m = NULL; free(_tmp_); }
+#define TO_STRING(s) #s
+#define EVER ;;
+
+extern const char * skipWhitespace(const char *Buffer);
+extern const char *getWord(char *buf, int bufSize, const char *src);
+extern const char *restOfLine(char *buf, int bufSize, const char *src);
+
+#endif /* UTIL_H */
+