summaryrefslogtreecommitdiff
path: root/libs/util
diff options
context:
space:
mode:
authorgeronimo <geronimo013@gmx.de>2012-07-29 15:11:47 +0200
committergeronimo <geronimo013@gmx.de>2012-07-29 15:11:47 +0200
commit85cb3f04252b0228830903b21c08bb64e9919c18 (patch)
tree5c00dbd8d296861aa56cca598ee2a36e51971822 /libs/util
parent736033f3d532c4814eeff84db5dbf99f0249df6e (diff)
downloadcmp-85cb3f04252b0228830903b21c08bb64e9919c18.tar.gz
cmp-85cb3f04252b0228830903b21c08bb64e9919c18.tar.bz2
changed server setup to config file, little rearrangement of sources
Diffstat (limited to 'libs/util')
-rw-r--r--libs/util/Url.cc229
-rw-r--r--libs/util/Url.h67
-rw-r--r--libs/util/include/AbstractListAssembler.h12
-rw-r--r--libs/util/include/JSonWriter.h12
-rw-r--r--libs/util/include/ManagedMap.h12
-rw-r--r--libs/util/include/Persistable.h35
-rw-r--r--libs/util/include/Url.h67
-rw-r--r--libs/util/nbproject/Makefile-Debug.mk12
-rw-r--r--libs/util/nbproject/Makefile-Release.mk6
-rw-r--r--libs/util/nbproject/configurations.xml19
-rw-r--r--libs/util/nbproject/private/configurations.xml2
-rw-r--r--libs/util/nbproject/project.xml4
-rw-r--r--libs/util/src/Url.cc229
-rw-r--r--libs/util/util.cbp8
-rw-r--r--libs/util/util.layout28
-rw-r--r--libs/util/util.layout.save30
16 files changed, 726 insertions, 46 deletions
diff --git a/libs/util/Url.cc b/libs/util/Url.cc
new file mode 100644
index 0000000..ce951e6
--- /dev/null
+++ b/libs/util/Url.cc
@@ -0,0 +1,229 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: Url.cc
+ * Created: 4. Juli 2012, 05
+ * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
+ * Project: libnetworking: classes for tcp/ip sockets and http-protocol handling
+ *
+ * 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
+ *
+ * --------------------------------------------------------------
+ */
+#include <Url.h>
+#include <Codec.h>
+#include <util.h>
+#ifdef DEBUG
+#include <iostream>
+#endif
+#include <stdio.h>
+#include <string.h>
+#include <vector>
+
+static cURLEncoder * encoder = NULL;
+static cURLDecoder * decoder = NULL;
+
+cUrl::cUrl(const char* RawURL)
+ : path(NULL)
+{
+ ParseURL(RawURL);
+}
+
+cUrl::~cUrl()
+{
+ FREE(path);
+}
+
+cURLDecoder* cUrl::Decoder(void)
+{
+ if (!decoder) decoder = new cURLDecoder();
+ return decoder;
+}
+
+cURLEncoder* cUrl::Encoder(void)
+{
+ if (!encoder) encoder = new cURLEncoder();
+ return encoder;
+}
+
+const char *cUrl::Parameter(const char* Name)
+{
+ std::tr1::unordered_map<std::string, std::string>::iterator found = parameters.find(Name);
+ if (found != parameters.end()) return found->second.c_str();
+ return NULL;
+}
+
+void cUrl::SetParameter(const char* Name, const char* Value)
+{
+ std::string name = Name;
+ std::string value = Value ? Value : " ";
+ parameters[name] = value;
+}
+
+size_t cUrl::EstimatedSize(void ) const
+{
+ size_t rv = parameters.size() * 3;
+
+ if (path) rv += strlen(path) + 4;
+ ParameterMap::const_iterator pm = parameters.begin();
+
+ while (pm != parameters.end()) {
+ rv += pm->first.length() * 3;
+ rv += pm->second.length() * 3;
+ ++pm;
+ }
+ return rv;
+}
+
+void cUrl::ParseURL(const char *URL)
+{
+ FREE(path);
+ parameters.clear();
+ if (!URL) return;
+ const char *q = strchr(URL, '?'); // divider between url and querystring
+// char *realURL;
+// size_t l;
+
+ if (!q) q = URL + strlen(URL);
+// l = q - URL;
+// realURL = (char *)malloc(l + 2);
+// if (!realURL) return;
+// strncpy(realURL, URL, l);
+// realURL[l] = 0;
+ path = Decoder()->Decode(URL, q - URL);
+ if (*q) ParseQueryString(++q);
+}
+
+void cUrl::ParseQueryString(const char* QueryString)
+{
+ if (!(QueryString && *QueryString)) return;
+ const char *start, *last;
+ char *scratch = strdup(QueryString);
+ char *p, *end;
+ size_t srcLen = strlen(QueryString);
+
+ for (start = (const char *)scratch, end = (char *) start, last = scratch + srcLen; end && start < last; start = (const char *)++end) {
+ end = (char *) strchr(start, '&');
+ if (!end) end = (char *)start + strlen(start);
+ *end = 0;
+ p = (char *) strchr(start, '=');
+ if (p) {
+ *p++ = 0;
+ char *pn = p ? Decoder()->Decode(start) : NULL;
+ char *pv = p ? Decoder()->Decode(p) : NULL;
+
+ std::string name = pn;
+ std::string value = pv ? pv : " ";
+
+ parameters[name] = value;
+
+ free(pn);
+ free(pv);
+ }
+ else {
+ char *pn = Decoder()->Decode(start);
+
+ std::string name = pn;
+ parameters[name] = " ";
+ free(pn);
+ }
+ }
+ free(scratch);
+}
+
+char* cUrl::ToString(void) const
+///< returns the address of the newly allocated buffer
+{
+ size_t bufSize = EstimatedSize();
+ char *rv = (char *)malloc(bufSize);
+
+ if (!rv) return NULL;
+ int n = WriteBuf(rv, bufSize);
+
+ if (n < 0) {
+ bufSize += 128;
+ rv = (char *) realloc(rv, bufSize);
+ WriteBuf(rv, bufSize);
+ }
+ return rv;
+}
+
+int cUrl::WriteBuf(char* buf, size_t bufSize) const
+///< returns the characters written. -1 as return value indicates a buffer overrun.
+{
+ char *p, *tmp;
+ bool first = true;
+ int n = 0;
+
+ if (path) n += snprintf(buf + n, bufSize - n, "%s", path);
+ p = buf + n;
+ ParameterMap::const_iterator pm = parameters.begin();
+
+ while (pm != parameters.end()) {
+ tmp = Encoder()->Encode(pm->first.c_str());
+ if (p - buf + strlen(tmp) + 2 > bufSize)
+ return -1;
+ if (first) {
+ first = false;
+ *p++ = '?';
+ }
+ else *p++ = '&';
+ strcpy(p, tmp);
+ p += strlen(p);
+ FREE(tmp);
+
+ if (strcmp(pm->second.c_str(), " ")) {
+ tmp = Encoder()->Encode(pm->second.c_str());
+ if (p - buf + strlen(tmp) + 2 > bufSize)
+ return -1;
+ *p++ = '=';
+ strcpy(p, tmp);
+ p += strlen(p);
+ FREE(tmp);
+ }
+ ++pm;
+ }
+ p += strlen(p);
+
+ return p - buf;
+}
+
+#ifdef DEBUG
+void cUrl::Dump(void )
+{
+ ParameterMap::const_iterator pm = parameters.begin();
+
+ while (pm != parameters.end()) {
+ std::cout << "parameter [" << pm->first << "]";
+ if (strcmp(pm->second.c_str(), " "))
+ std::cout << " has value <|" << pm->second << "|>" << std::endl;
+ else
+ std::cout << " has NO value!" << std::endl;
+ ++pm;
+ }
+}
+#endif
+
+void cUrl::Cleanup(void )
+{
+ if (encoder) {
+ delete encoder;
+ encoder = NULL;
+ }
+ if (decoder) {
+ delete decoder;
+ decoder = NULL;
+ }
+} \ No newline at end of file
diff --git a/libs/util/Url.h b/libs/util/Url.h
new file mode 100644
index 0000000..f4dc1af
--- /dev/null
+++ b/libs/util/Url.h
@@ -0,0 +1,67 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: Url.h
+ * Created: 4. Juli 2012, 05
+ * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
+ * Project: libnetworking: classes for tcp/ip sockets and http-protocol handling
+ *
+ * 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 URL_H
+#define URL_H
+
+#include <stddef.h>
+#include <string>
+#include <tr1/unordered_map>
+class cURLEncoder;
+class cURLDecoder;
+
+class cUrl {
+///< splits an url into machine readable parts:
+///< from top-level sight, an url consists of url and querystring. Looking bit closer,
+///< the url consists of toplevel and path, where as the querystring is a list of
+///< name/value tuples with value being an optional part.
+public:
+ cUrl(const char *RawURL);
+ virtual ~cUrl();
+ const char *Parameter(const char *Name);
+ void SetParameter(const char* Name, const char* Value = NULL);
+ size_t EstimatedSize(void) const; ///< is a rough guess about the size of the final encoded url
+ void ParseURL(const char *URL);
+ char *ToString(void) const; ///< writes the url to a newly allocated buffer
+ int WriteBuf(char *buf, size_t bufSize) const; ///< writes the url to preexisting buffer
+ ///< returns the characters written. -1 as return value indicates a buffer overrun.
+ const char * Path() const { return path; }
+#ifdef DEBUG
+ void Dump(void);
+#endif
+ static void Cleanup(void);
+ static cURLEncoder *Encoder(void);
+ static cURLDecoder *Decoder(void);
+
+protected:
+ void ParseQueryString(const char *QueryString);
+
+private:
+ typedef std::tr1::unordered_map<std::string, std::string> ParameterMap;
+ char *path;
+ ParameterMap parameters;
+ };
+
+#endif /* URL_H */
+
diff --git a/libs/util/include/AbstractListAssembler.h b/libs/util/include/AbstractListAssembler.h
index 9ce357b..d709249 100644
--- a/libs/util/include/AbstractListAssembler.h
+++ b/libs/util/include/AbstractListAssembler.h
@@ -1,25 +1,25 @@
/**
* ======================== legal notice ======================
- *
+ *
* File: AbstractListAssembler.h
* Created: 6. Juli 2012, 09
* 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
diff --git a/libs/util/include/JSonWriter.h b/libs/util/include/JSonWriter.h
index 00fdfb3..8031565 100644
--- a/libs/util/include/JSonWriter.h
+++ b/libs/util/include/JSonWriter.h
@@ -1,25 +1,25 @@
/**
* ======================== legal notice ======================
- *
+ *
* File: JSonWriter.h
* Created: 6. Juli 2012, 12
* 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
diff --git a/libs/util/include/ManagedMap.h b/libs/util/include/ManagedMap.h
index e1e6e2e..e8f04f7 100644
--- a/libs/util/include/ManagedMap.h
+++ b/libs/util/include/ManagedMap.h
@@ -1,25 +1,25 @@
/**
* ======================== legal notice ======================
- *
+ *
* File: ManagedMap.h
* Created: 7. Juli 2012, 08
* 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
diff --git a/libs/util/include/Persistable.h b/libs/util/include/Persistable.h
new file mode 100644
index 0000000..aba962d
--- /dev/null
+++ b/libs/util/include/Persistable.h
@@ -0,0 +1,35 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: Persistable.h
+ * Created: 29. Juli 2012, 13:08
+ * 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 PERSISTABLE_H
+#define PERSISTABLE_H
+
+class cPersistable {
+public:
+ virtual int Store(const char *FileName) = 0;
+ virtual int Load(const char *FileName) = 0;
+ };
+
+#endif /* PERSISTABLE_H */
+
diff --git a/libs/util/include/Url.h b/libs/util/include/Url.h
new file mode 100644
index 0000000..e2cd1c3
--- /dev/null
+++ b/libs/util/include/Url.h
@@ -0,0 +1,67 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: Url.h
+ * Created: 4. Juli 2012, 05
+ * 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 URL_H
+#define URL_H
+
+#include <stddef.h>
+#include <string>
+#include <tr1/unordered_map>
+class cURLEncoder;
+class cURLDecoder;
+
+class cUrl {
+///< splits an url into machine readable parts:
+///< from top-level sight, an url consists of url and querystring. Looking bit closer,
+///< the url consists of toplevel and path, where as the querystring is a list of
+///< name/value tuples with value being an optional part.
+public:
+ cUrl(const char *RawURL);
+ virtual ~cUrl();
+ const char *Parameter(const char *Name);
+ void SetParameter(const char* Name, const char* Value = NULL);
+ size_t EstimatedSize(void) const; ///< is a rough guess about the size of the final encoded url
+ void ParseURL(const char *URL);
+ char *ToString(void) const; ///< writes the url to a newly allocated buffer
+ int WriteBuf(char *buf, size_t bufSize) const; ///< writes the url to preexisting buffer
+ ///< returns the characters written. -1 as return value indicates a buffer overrun.
+ const char * Path() const { return path; }
+#ifdef DEBUG
+ void Dump(void);
+#endif
+ static void Cleanup(void);
+ static cURLEncoder *Encoder(void);
+ static cURLDecoder *Decoder(void);
+
+protected:
+ void ParseQueryString(const char *QueryString);
+
+private:
+ typedef std::tr1::unordered_map<std::string, std::string> ParameterMap;
+ char *path;
+ ParameterMap parameters;
+ };
+
+#endif /* URL_H */
+
diff --git a/libs/util/nbproject/Makefile-Debug.mk b/libs/util/nbproject/Makefile-Debug.mk
index dfbf4e8..2149f0d 100644
--- a/libs/util/nbproject/Makefile-Debug.mk
+++ b/libs/util/nbproject/Makefile-Debug.mk
@@ -41,6 +41,7 @@ OBJECTFILES= \
${OBJECTDIR}/src/AbstractListAssembler.o \
${OBJECTDIR}/src/ManagedMap.o \
${OBJECTDIR}/src/Codec.o \
+ ${OBJECTDIR}/src/Url.o \
${OBJECTDIR}/src/ManagedVector.o \
${OBJECTDIR}/src/NamedValue.o \
${OBJECTDIR}/src/util.o
@@ -50,8 +51,8 @@ OBJECTFILES= \
CFLAGS=
# CC Compiler Flags
-CCFLAGS=-std=gnu++0x -fomit-frame-pointer -fPIC -pthread -Wall -Wno-parentheses -Wno-switch -Wdisabled-optimization -Wpointer-arith -Wredundant-decls -Wwrite-strings -Wtype-limits -Wundef -fno-math-errno -fno-signed-zeros -fno-tree-vectorize -Werror=implicit-function-declaration -ansi
-CXXFLAGS=-std=gnu++0x -fomit-frame-pointer -fPIC -pthread -Wall -Wno-parentheses -Wno-switch -Wdisabled-optimization -Wpointer-arith -Wredundant-decls -Wwrite-strings -Wtype-limits -Wundef -fno-math-errno -fno-signed-zeros -fno-tree-vectorize -Werror=implicit-function-declaration -ansi
+CCFLAGS=-std=gnu++0x -fomit-frame-pointer -fPIC -pthread -Wall -Wno-parentheses -Wno-switch -Wdisabled-optimization -Wpointer-arith -Wredundant-decls -Wwrite-strings -Wtype-limits -Wundef -fno-math-errno -fno-signed-zeros -fno-tree-vectorize -Werror=implicit-function-declaration
+CXXFLAGS=-std=gnu++0x -fomit-frame-pointer -fPIC -pthread -Wall -Wno-parentheses -Wno-switch -Wdisabled-optimization -Wpointer-arith -Wredundant-decls -Wwrite-strings -Wtype-limits -Wundef -fno-math-errno -fno-signed-zeros -fno-tree-vectorize -Werror=implicit-function-declaration
# Fortran Compiler Flags
FFLAGS=
@@ -102,6 +103,11 @@ ${OBJECTDIR}/src/Codec.o: src/Codec.cc
${RM} $@.d
$(COMPILE.cc) -g -Wall -D_GNU_SOURCE=1 -D_REENTRANT -Iinclude -I../vdr/include -MMD -MP -MF $@.d -o ${OBJECTDIR}/src/Codec.o src/Codec.cc
+${OBJECTDIR}/src/Url.o: src/Url.cc
+ ${MKDIR} -p ${OBJECTDIR}/src
+ ${RM} $@.d
+ $(COMPILE.cc) -g -Wall -D_GNU_SOURCE=1 -D_REENTRANT -Iinclude -I../vdr/include -MMD -MP -MF $@.d -o ${OBJECTDIR}/src/Url.o src/Url.cc
+
${OBJECTDIR}/src/ManagedVector.o: src/ManagedVector.cc
${MKDIR} -p ${OBJECTDIR}/src
${RM} $@.d
@@ -119,6 +125,7 @@ ${OBJECTDIR}/src/util.o: src/util.cc
# Subprojects
.build-subprojects:
+ cd ../vdr && ${MAKE} -f Makefile CONF=Debug
# Clean Targets
.clean-conf: ${CLEAN_SUBPROJECTS}
@@ -127,6 +134,7 @@ ${OBJECTDIR}/src/util.o: src/util.cc
# Subprojects
.clean-subprojects:
+ cd ../vdr && ${MAKE} -f Makefile CONF=Debug clean
# Enable dependency checking
.dep.inc: .depcheck-impl
diff --git a/libs/util/nbproject/Makefile-Release.mk b/libs/util/nbproject/Makefile-Release.mk
index 2fcd899..42ca655 100644
--- a/libs/util/nbproject/Makefile-Release.mk
+++ b/libs/util/nbproject/Makefile-Release.mk
@@ -41,6 +41,7 @@ OBJECTFILES= \
${OBJECTDIR}/src/AbstractListAssembler.o \
${OBJECTDIR}/src/ManagedMap.o \
${OBJECTDIR}/src/Codec.o \
+ ${OBJECTDIR}/src/Url.o \
${OBJECTDIR}/src/ManagedVector.o \
${OBJECTDIR}/src/NamedValue.o \
${OBJECTDIR}/src/util.o
@@ -102,6 +103,11 @@ ${OBJECTDIR}/src/Codec.o: src/Codec.cc
${RM} $@.d
$(COMPILE.cc) -O2 -MMD -MP -MF $@.d -o ${OBJECTDIR}/src/Codec.o src/Codec.cc
+${OBJECTDIR}/src/Url.o: src/Url.cc
+ ${MKDIR} -p ${OBJECTDIR}/src
+ ${RM} $@.d
+ $(COMPILE.cc) -O2 -MMD -MP -MF $@.d -o ${OBJECTDIR}/src/Url.o src/Url.cc
+
${OBJECTDIR}/src/ManagedVector.o: src/ManagedVector.cc
${MKDIR} -p ${OBJECTDIR}/src
${RM} $@.d
diff --git a/libs/util/nbproject/configurations.xml b/libs/util/nbproject/configurations.xml
index ac160eb..481eb85 100644
--- a/libs/util/nbproject/configurations.xml
+++ b/libs/util/nbproject/configurations.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
-<configurationDescriptor version="80">
+<configurationDescriptor version="84">
<logicalFolder name="root" displayName="root" projectFiles="true" kind="ROOT">
<logicalFolder name="HeaderFiles"
displayName="Header Files"
@@ -11,7 +11,9 @@
<itemPath>include/ManagedMap.h</itemPath>
<itemPath>include/ManagedVector.h</itemPath>
<itemPath>include/NamedValue.h</itemPath>
+ <itemPath>include/Persistable.h</itemPath>
<itemPath>include/StringBuilder.h</itemPath>
+ <itemPath>include/Url.h</itemPath>
<itemPath>include/util.h</itemPath>
</logicalFolder>
<logicalFolder name="ResourceFiles"
@@ -29,6 +31,7 @@
<itemPath>src/ManagedVector.cc</itemPath>
<itemPath>src/NamedValue.cc</itemPath>
<itemPath>src/StringBuilder.cc</itemPath>
+ <itemPath>src/Url.cc</itemPath>
<itemPath>src/util.cc</itemPath>
</logicalFolder>
<logicalFolder name="TestFiles"
@@ -57,7 +60,7 @@
<pElem>include</pElem>
<pElem>../vdr/include</pElem>
</incDir>
- <commandLine>-std=gnu++0x -fomit-frame-pointer -fPIC -pthread -Wall -Wno-parentheses -Wno-switch -Wdisabled-optimization -Wpointer-arith -Wredundant-decls -Wwrite-strings -Wtype-limits -Wundef -fno-math-errno -fno-signed-zeros -fno-tree-vectorize -Werror=implicit-function-declaration -ansi</commandLine>
+ <commandLine>-std=gnu++0x -fomit-frame-pointer -fPIC -pthread -Wall -Wno-parentheses -Wno-switch -Wdisabled-optimization -Wpointer-arith -Wredundant-decls -Wwrite-strings -Wtype-limits -Wundef -fno-math-errno -fno-signed-zeros -fno-tree-vectorize -Werror=implicit-function-declaration</commandLine>
<preprocessorList>
<Elem>_GNU_SOURCE=1</Elem>
<Elem>_REENTRANT</Elem>
@@ -66,6 +69,18 @@
</ccTool>
<archiverTool>
</archiverTool>
+ <requiredProjects>
+ <makeArtifact PL="../vdr"
+ CT="3"
+ CN="Debug"
+ AC="true"
+ BL="true"
+ WD="../vdr"
+ BC="${MAKE} -f Makefile CONF=Debug"
+ CC="${MAKE} -f Makefile CONF=Debug clean"
+ OP="${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/libvdr.a">
+ </makeArtifact>
+ </requiredProjects>
</compileType>
</conf>
<conf name="Release" type="3">
diff --git a/libs/util/nbproject/private/configurations.xml b/libs/util/nbproject/private/configurations.xml
index fa15dc7..616cc91 100644
--- a/libs/util/nbproject/private/configurations.xml
+++ b/libs/util/nbproject/private/configurations.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
-<configurationDescriptor version="80">
+<configurationDescriptor version="84">
<projectmakefile>Makefile</projectmakefile>
<confs>
<conf name="Debug" type="3">
diff --git a/libs/util/nbproject/project.xml b/libs/util/nbproject/project.xml
index a4df583..afebc06 100644
--- a/libs/util/nbproject/project.xml
+++ b/libs/util/nbproject/project.xml
@@ -8,7 +8,9 @@
<cpp-extensions>cc</cpp-extensions>
<header-extensions>h</header-extensions>
<sourceEncoding>UTF-8</sourceEncoding>
- <make-dep-projects/>
+ <make-dep-projects>
+ <make-dep-project>../vdr</make-dep-project>
+ </make-dep-projects>
<sourceRootList/>
<confList>
<confElem>
diff --git a/libs/util/src/Url.cc b/libs/util/src/Url.cc
new file mode 100644
index 0000000..e31637d
--- /dev/null
+++ b/libs/util/src/Url.cc
@@ -0,0 +1,229 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: Url.cc
+ * Created: 4. Juli 2012, 05
+ * 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
+ *
+ * --------------------------------------------------------------
+ */
+#include <Url.h>
+#include <Codec.h>
+#include <util.h>
+#ifdef DEBUG
+#include <iostream>
+#endif
+#include <stdio.h>
+#include <string.h>
+#include <vector>
+
+static cURLEncoder * encoder = NULL;
+static cURLDecoder * decoder = NULL;
+
+cUrl::cUrl(const char* RawURL)
+ : path(NULL)
+{
+ ParseURL(RawURL);
+}
+
+cUrl::~cUrl()
+{
+ FREE(path);
+}
+
+cURLDecoder* cUrl::Decoder(void)
+{
+ if (!decoder) decoder = new cURLDecoder();
+ return decoder;
+}
+
+cURLEncoder* cUrl::Encoder(void)
+{
+ if (!encoder) encoder = new cURLEncoder();
+ return encoder;
+}
+
+const char *cUrl::Parameter(const char* Name)
+{
+ std::tr1::unordered_map<std::string, std::string>::iterator found = parameters.find(Name);
+ if (found != parameters.end()) return found->second.c_str();
+ return NULL;
+}
+
+void cUrl::SetParameter(const char* Name, const char* Value)
+{
+ std::string name = Name;
+ std::string value = Value ? Value : " ";
+ parameters[name] = value;
+}
+
+size_t cUrl::EstimatedSize(void ) const
+{
+ size_t rv = parameters.size() * 3;
+
+ if (path) rv += strlen(path) + 4;
+ ParameterMap::const_iterator pm = parameters.begin();
+
+ while (pm != parameters.end()) {
+ rv += pm->first.length() * 3;
+ rv += pm->second.length() * 3;
+ ++pm;
+ }
+ return rv;
+}
+
+void cUrl::ParseURL(const char *URL)
+{
+ FREE(path);
+ parameters.clear();
+ if (!URL) return;
+ const char *q = strchr(URL, '?'); // divider between url and querystring
+// char *realURL;
+// size_t l;
+
+ if (!q) q = URL + strlen(URL);
+// l = q - URL;
+// realURL = (char *)malloc(l + 2);
+// if (!realURL) return;
+// strncpy(realURL, URL, l);
+// realURL[l] = 0;
+ path = Decoder()->Decode(URL, q - URL);
+ if (*q) ParseQueryString(++q);
+}
+
+void cUrl::ParseQueryString(const char* QueryString)
+{
+ if (!(QueryString && *QueryString)) return;
+ const char *start, *last;
+ char *scratch = strdup(QueryString);
+ char *p, *end;
+ size_t srcLen = strlen(QueryString);
+
+ for (start = (const char *)scratch, end = (char *) start, last = scratch + srcLen; end && start < last; start = (const char *)++end) {
+ end = (char *) strchr(start, '&');
+ if (!end) end = (char *)start + strlen(start);
+ *end = 0;
+ p = (char *) strchr(start, '=');
+ if (p) {
+ *p++ = 0;
+ char *pn = p ? Decoder()->Decode(start) : NULL;
+ char *pv = p ? Decoder()->Decode(p) : NULL;
+
+ std::string name = pn;
+ std::string value = pv ? pv : " ";
+
+ parameters[name] = value;
+
+ free(pn);
+ free(pv);
+ }
+ else {
+ char *pn = Decoder()->Decode(start);
+
+ std::string name = pn;
+ parameters[name] = " ";
+ free(pn);
+ }
+ }
+ free(scratch);
+}
+
+char* cUrl::ToString(void) const
+///< returns the address of the newly allocated buffer
+{
+ size_t bufSize = EstimatedSize();
+ char *rv = (char *)malloc(bufSize);
+
+ if (!rv) return NULL;
+ int n = WriteBuf(rv, bufSize);
+
+ if (n < 0) {
+ bufSize += 128;
+ rv = (char *) realloc(rv, bufSize);
+ WriteBuf(rv, bufSize);
+ }
+ return rv;
+}
+
+int cUrl::WriteBuf(char* buf, size_t bufSize) const
+///< returns the characters written. -1 as return value indicates a buffer overrun.
+{
+ char *p, *tmp;
+ bool first = true;
+ int n = 0;
+
+ if (path) n += snprintf(buf + n, bufSize - n, "%s", path);
+ p = buf + n;
+ ParameterMap::const_iterator pm = parameters.begin();
+
+ while (pm != parameters.end()) {
+ tmp = Encoder()->Encode(pm->first.c_str());
+ if (p - buf + strlen(tmp) + 2 > bufSize)
+ return -1;
+ if (first) {
+ first = false;
+ *p++ = '?';
+ }
+ else *p++ = '&';
+ strcpy(p, tmp);
+ p += strlen(p);
+ FREE(tmp);
+
+ if (strcmp(pm->second.c_str(), " ")) {
+ tmp = Encoder()->Encode(pm->second.c_str());
+ if (p - buf + strlen(tmp) + 2 > bufSize)
+ return -1;
+ *p++ = '=';
+ strcpy(p, tmp);
+ p += strlen(p);
+ FREE(tmp);
+ }
+ ++pm;
+ }
+ p += strlen(p);
+
+ return p - buf;
+}
+
+#ifdef DEBUG
+void cUrl::Dump(void )
+{
+ ParameterMap::const_iterator pm = parameters.begin();
+
+ while (pm != parameters.end()) {
+ std::cout << "parameter [" << pm->first << "]";
+ if (strcmp(pm->second.c_str(), " "))
+ std::cout << " has value <|" << pm->second << "|>" << std::endl;
+ else
+ std::cout << " has NO value!" << std::endl;
+ ++pm;
+ }
+}
+#endif
+
+void cUrl::Cleanup(void )
+{
+ if (encoder) {
+ delete encoder;
+ encoder = NULL;
+ }
+ if (decoder) {
+ delete decoder;
+ decoder = NULL;
+ }
+} \ No newline at end of file
diff --git a/libs/util/util.cbp b/libs/util/util.cbp
index d582dc0..ae72cf4 100644
--- a/libs/util/util.cbp
+++ b/libs/util/util.cbp
@@ -7,7 +7,7 @@
<Option compiler="gcc" />
<Build>
<Target title="Debug">
- <Option output="libutil" prefix_auto="1" extension_auto="1" />
+ <Option output="util" prefix_auto="1" extension_auto="1" />
<Option working_dir="" />
<Option object_output="obj/Debug/" />
<Option type="2" />
@@ -19,7 +19,7 @@
</Compiler>
</Target>
<Target title="Release">
- <Option output="libutil" prefix_auto="1" extension_auto="1" />
+ <Option output="util" prefix_auto="1" extension_auto="1" />
<Option working_dir="" />
<Option object_output="obj/Release/" />
<Option type="2" />
@@ -35,7 +35,7 @@
</Target>
</Build>
<Compiler>
- <Add option="-std=gnu++0x -fomit-frame-pointer -fPIC -pthread -Wall -Wno-parentheses -Wno-switch -Wdisabled-optimization -Wpointer-arith -Wredundant-decls -Wwrite-strings -Wtype-limits -Wundef -fno-math-errno -fno-signed-zeros -fno-tree-vectorize -Werror=implicit-function-declaration -ansi" />
+ <Add option="-std=gnu++0x -fomit-frame-pointer -fPIC -pthread -Wall -Wno-parentheses -Wno-switch -Wdisabled-optimization -Wpointer-arith -Wredundant-decls -Wwrite-strings -Wtype-limits -Wundef -fno-math-errno -fno-signed-zeros -fno-tree-vectorize -Werror=implicit-function-declaration" />
<Add option="-D_REENTRANT" />
<Add option="-D_GNU_SOURCE=1" />
<Add directory="../vdr/include" />
@@ -49,6 +49,7 @@
<Unit filename="include/ManagedVector.h" />
<Unit filename="include/NamedValue.h" />
<Unit filename="include/StringBuilder.h" />
+ <Unit filename="include/Url.h" />
<Unit filename="include/util.h" />
<Unit filename="src/AbstractListAssembler.cc" />
<Unit filename="src/Codec.cc" />
@@ -58,6 +59,7 @@
<Unit filename="src/ManagedVector.cc" />
<Unit filename="src/NamedValue.cc" />
<Unit filename="src/StringBuilder.cc" />
+ <Unit filename="src/Url.cc" />
<Unit filename="src/util.cc" />
<Extensions>
<code_completion />
diff --git a/libs/util/util.layout b/libs/util/util.layout
index 1ecf705..ef999ec 100644
--- a/libs/util/util.layout
+++ b/libs/util/util.layout
@@ -1,41 +1,51 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_layout_file>
<ActiveTarget name="Debug" />
- <File name="src/JSonWriter.cc" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+ <File name="src/AbstractListAssembler.cc" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
- <Cursor1 position="1655" topLine="3" />
+ <Cursor1 position="0" topLine="0" />
</Cursor>
</File>
- <File name="include/ManagedMap.h" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+ <File name="include/Codec.h" open="0" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
- <Cursor1 position="0" topLine="0" />
+ <Cursor1 position="1385" topLine="0" />
</Cursor>
</File>
- <File name="include/ManagedVector.h" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+ <File name="include/ManagedMap.h" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
- <File name="src/StringBuilder.cc" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+ <File name="src/StringBuilder.cc" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="1953" topLine="59" />
</Cursor>
</File>
- <File name="src/ManagedMap.cc" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+ <File name="src/Codec.cc" open="0" top="0" tabpos="9" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+ <Cursor>
+ <Cursor1 position="1327" topLine="0" />
+ </Cursor>
+ </File>
+ <File name="include/ManagedVector.h" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
- <File name="include/StringBuilder.h" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+ <File name="include/StringBuilder.h" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="1959" topLine="0" />
</Cursor>
</File>
- <File name="src/AbstractListAssembler.cc" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+ <File name="src/ManagedMap.cc" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
+ <File name="src/JSonWriter.cc" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+ <Cursor>
+ <Cursor1 position="1655" topLine="3" />
+ </Cursor>
+ </File>
<File name="include/JSonWriter.h" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="1532" topLine="0" />
diff --git a/libs/util/util.layout.save b/libs/util/util.layout.save
index 0805ad4..ef999ec 100644
--- a/libs/util/util.layout.save
+++ b/libs/util/util.layout.save
@@ -1,34 +1,39 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_layout_file>
<ActiveTarget name="Debug" />
- <File name="include/ManagedVector.h" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+ <File name="src/AbstractListAssembler.cc" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
+ <File name="include/Codec.h" open="0" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+ <Cursor>
+ <Cursor1 position="1385" topLine="0" />
+ </Cursor>
+ </File>
<File name="include/ManagedMap.h" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
- <File name="src/StringBuilder.cc" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+ <File name="src/StringBuilder.cc" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="1953" topLine="59" />
</Cursor>
</File>
- <File name="src/JSonWriter.cc" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+ <File name="src/Codec.cc" open="0" top="0" tabpos="9" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
- <Cursor1 position="1655" topLine="3" />
+ <Cursor1 position="1327" topLine="0" />
</Cursor>
</File>
- <File name="include/JSonWriter.h" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+ <File name="include/ManagedVector.h" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
- <Cursor1 position="1532" topLine="0" />
+ <Cursor1 position="0" topLine="0" />
</Cursor>
</File>
- <File name="src/AbstractListAssembler.cc" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+ <File name="include/StringBuilder.h" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
- <Cursor1 position="0" topLine="0" />
+ <Cursor1 position="1959" topLine="0" />
</Cursor>
</File>
<File name="src/ManagedMap.cc" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
@@ -36,9 +41,14 @@
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
- <File name="include/StringBuilder.h" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+ <File name="src/JSonWriter.cc" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
- <Cursor1 position="1959" topLine="0" />
+ <Cursor1 position="1655" topLine="3" />
+ </Cursor>
+ </File>
+ <File name="include/JSonWriter.h" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+ <Cursor>
+ <Cursor1 position="1532" topLine="0" />
</Cursor>
</File>
</CodeBlocks_layout_file>