summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authorgeronimo <geronimo013@gmx.de>2012-07-29 13:15:58 (GMT)
committergeronimo <geronimo013@gmx.de>2012-07-29 13:15:58 (GMT)
commit4039d18078da508ba8c628df8e2aa741cf91f266 (patch)
treef5914b1767c612aad44a9d8a335bafa96940de81 /libs
parent85cb3f04252b0228830903b21c08bb64e9919c18 (diff)
downloadcmp-4039d18078da508ba8c628df8e2aa741cf91f266.tar.gz
cmp-4039d18078da508ba8c628df8e2aa741cf91f266.tar.bz2
files have been moved
Diffstat (limited to 'libs')
-rw-r--r--libs/IO/File.cc181
-rw-r--r--libs/IO/File.h67
-rw-r--r--libs/IO/FileRepresentation.cc132
-rw-r--r--libs/IO/FileRepresentation.h56
-rw-r--r--libs/IO/FileSystem.cc132
-rw-r--r--libs/IO/FileSystem.h50
-rw-r--r--libs/util/Url.cc229
-rw-r--r--libs/util/Url.h67
8 files changed, 0 insertions, 914 deletions
diff --git a/libs/IO/File.cc b/libs/IO/File.cc
deleted file mode 100644
index 477c5c8..0000000
--- a/libs/IO/File.cc
+++ /dev/null
@@ -1,181 +0,0 @@
-/**
- * ======================== legal notice ======================
- *
- * File: File.cc
- * Created: 21. Juli 2012, 12
- * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
- * Project: libfsScan: mediatypes and filesystem scanning
- *
- * 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 <File.h>
-#include <FileSystem.h>
-#include <FileRepresentation.h>
-#include <StringBuilder.h>
-#include <sys/stat.h>
-#include <sys/dir.h>
-
-cFileSystem *cFile::fs = NULL;
-static mode_t ReadMask = S_IRUSR | S_IRGRP | S_IROTH;
-static mode_t WriteMask = S_IWUSR | S_IWGRP | S_IWOTH;
-static mode_t ExecMask = S_IXUSR | S_IXGRP | S_IXOTH;
-
-
-cFile::cFile(const char *Path)
- : rep(NULL)
-{
- if (!fs) fs = new cFileSystem();
- if (!Path) {
- Path = getcwd(NULL, 0);
- rep = fs->representationOfFile(Path);
- free((char *) Path);
- }
- else rep = fs->representationOfFile(Path);
-}
-
-cFile::cFile(const cFile &other)
- : rep(other.rep)
-{
- if (!fs) fs = new cFileSystem();
-}
-
-cFile::cFile(const cFile& Parent, const char* RelativePath)
- : rep(NULL)
-{
- if (!fs) fs = new cFileSystem();
- rep = fs->representationOfFile(Parent, RelativePath);
-}
-
-cFile::cFile(const cFileRepresentation *fr)
- : rep(fr)
-{
- if (!fs) fs = new cFileSystem();
-}
-
-cFile::~cFile()
-{
-}
-
-cFile &cFile::operator =(const cFile &other)
-{
- rep = other.rep;
- return *this;
-}
-
-const char *cFile::AbsolutePath(void) const
-{
- if (rep) return rep->Path();
- return NULL;
-}
-
-bool cFile::Exists(void) const
-{
- if (rep) return rep->exists;
- return false;
-}
-
-bool cFile::IsDirectory(void) const
-{
- if (rep) return (rep->mode & S_IFMT) == S_IFDIR;
- return false;
-}
-
-bool cFile::IsFile(void) const
-{
- if (rep) return (rep->mode & S_IFMT) == S_IFREG;
- return false;
-}
-
-bool cFile::IsSymbolic(void) const
-{
- if (rep) return (rep->mode & S_IFMT) == S_IFLNK;
- return false;
-}
-
-bool cFile::CanRead(void) const
-{
- if (rep) return rep->mode & ReadMask;
- return false;
-}
-
-bool cFile::CanWrite(void) const
-{
- if (rep) return rep->mode & WriteMask;
- return false;
-}
-
-bool cFile::CanExecute(void) const
-{
- if (rep) return rep->mode & ExecMask;
- return false;
-}
-
-off64_t cFile::Size(void) const
-{
- if (rep) return rep->size;
- return 0;
-}
-
-ulong cFile::LastModified(void) const
-{
- if (rep) return rep->lastModified;
- return 0;
-}
-
-cFile *cFile::Parent(void) const
-{
- if (rep) return new cFile(rep->getParent());
- return NULL;
-}
-
-const char *cFile::Name(void) const
-{
- if (rep) return rep->name;
- return NULL;
-}
-
-void cFile::Cleanup(void)
-{
- if (fs) {
- delete fs;
- fs = NULL;
- }
-}
-
-void cFile::VisitFiles(int (*cb)(void *, cFile *, const char *), void *opaque)
-{
- if (!Exists() || !IsDirectory()) return;
- struct dirent entryBuffer, *pE;
- DIR *dir = opendir(AbsolutePath());
-
- while (!readdir_r(dir, &entryBuffer, &pE) && pE) {
- if (*(pE->d_name) == '.') continue; // don't bother with hidden stuff
- cb(opaque, this, pE->d_name);
- }
- closedir(dir);
-}
-
-char *cFile::toURI() const
-{
- if (rep) return rep->toURI();
- return NULL;
-}
-
-void cFile::SetVirtualRoot(bool isRoot)
-{
- if (rep) ((cFileRepresentation *)rep)->SetVirtualRoot(isRoot);
-}
diff --git a/libs/IO/File.h b/libs/IO/File.h
deleted file mode 100644
index 587d99c..0000000
--- a/libs/IO/File.h
+++ /dev/null
@@ -1,67 +0,0 @@
-/**
- * ======================== legal notice ======================
- *
- * File: File.h
- * Created: 21. Juli 2012, 12
- * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
- * Project: libfsScan: mediatypes and filesystem scanning
- *
- * 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 FILE_H
-#define FILE_H
-
-#include <stddef.h>
-#include <sys/types.h>
-
-class cFileSystem;
-class cFileRepresentation;
-class cStringBuilder;
-class cFile {
-public:
- cFile(const char *Path = NULL);
- cFile(const cFile &other);
- cFile(const cFile &Parent, const char *RelativePath);
- virtual ~cFile();
-
- cFile &operator =(const cFile &other);
- bool CanRead(void) const;
- bool CanWrite(void) const;
- bool CanExecute(void) const;
- bool Exists(void) const;
- bool IsDirectory(void) const;
- bool IsFile(void) const;
- bool IsSymbolic(void) const;
- off64_t Size(void) const;
- ulong LastModified(void) const;
- const char *Name(void) const;
- void SetVirtualRoot(bool isRoot = true);
- const char *AbsolutePath(void) const; ///< returns an allocated string
- char *toURI(void) const; ///< returns an allocated string
- cFile *Parent(void) const; ///< allocates a new file instance!
- void VisitFiles(int (*cb)(void *, cFile *, const char *), void *opaque);
- static void Cleanup(void);
-
-private:
- cFile(const cFileRepresentation *);
- const cFileRepresentation *rep;
- static cFileSystem *fs;
- friend class cFileSystem;
-};
-
-#endif /* FILE_H */
-
diff --git a/libs/IO/FileRepresentation.cc b/libs/IO/FileRepresentation.cc
deleted file mode 100644
index 81599a3..0000000
--- a/libs/IO/FileRepresentation.cc
+++ /dev/null
@@ -1,132 +0,0 @@
-/**
- * ======================== legal notice ======================
- *
- * File: FileRepresentation.cc
- * Created: 21. Juli 2012, 12
- * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
- * Project: libfsScan: mediatypes and filesystem scanning
- *
- * 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 <FileRepresentation.h>
-#include <FileSystem.h>
-#include <StringBuilder.h>
-#include <Url.h>
-#include <Codec.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <string.h>
-#include <stdlib.h>
-#include <iostream>
-#include <stack>
-
-cFileRepresentation::cFileRepresentation(const char *Name)
- : exists(false)
- , isRoot(true)
- , isVirtualRoot(true)
- , mode(0)
- , size(0)
- , lastModified(0)
- , name(NULL)
- , path(NULL)
- , parent(NULL)
-{
- struct stat st;
-
- if (!stat(Name, &st)) {
- name = strdup(Name);
- exists = true;
- mode = st.st_mode;
- size = st.st_size;
- lastModified = st.st_mtime;
- }
-}
-
-cFileRepresentation::cFileRepresentation(const cFileRepresentation *Parent, const char *Name)
- : exists(false)
- , isRoot(false)
- , isVirtualRoot(false)
- , mode(0)
- , size(0)
- , lastModified(0)
- , name(strdup(Name))
- , path(NULL)
- , parent(Parent)
-{
- struct stat st;
-
- if (!stat(Path(), &st)) {
- exists = true;
- mode = st.st_mode;
- size = st.st_size;
- lastModified = st.st_mtime;
- }
-}
-
-cFileRepresentation::~cFileRepresentation()
-{
- free(name);
- free(path);
-}
-
-const char *cFileRepresentation::Path() const
-{
- if (!path) {
- cStringBuilder sb;
-
- if (parent) sb.Append(parent->Path());
- sb.Append(cFileSystem::PathSeparator).Append(name);
- path = sb.toString();
- }
- return path;
-}
-
-void cFileRepresentation::SetVirtualRoot(bool isRoot)
-{
- isVirtualRoot = isRoot;
-}
-
-char *cFileRepresentation::toURI() const
-{
- cStringBuilder *sb = new cStringBuilder();
- const cFileRepresentation *f = this;
- std::stack<const cFileRepresentation *> rev;
- cURLEncoder *enc = cUrl::Encoder();
- char *tmp, *chk, *rv;
- size_t stackSize;
-
- while (!f->isVirtualRoot) {
- rev.push(f);
- stackSize = rev.size();
- f = f->parent;
- }
-
- for (;;) {
- f = rev.top();
- rev.pop();
- chk = f->name + strlen(f->name) - 1;
- if (*chk != cFileSystem::PathSeparator) sb->Append(cFileSystem::PathSeparator);
- tmp = enc->Encode(f->name);
- sb->Append(tmp);
- free(tmp);
- if (rev.empty()) break;
- }
- rv = sb->toString();
- delete sb;
-
- return rv;
-}
diff --git a/libs/IO/FileRepresentation.h b/libs/IO/FileRepresentation.h
deleted file mode 100644
index 39a3c1e..0000000
--- a/libs/IO/FileRepresentation.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/**
- * ======================== legal notice ======================
- *
- * File: FileRepresentation.h
- * Created: 21. Juli 2012, 12
- * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
- * Project: libfsScan: mediatypes and filesystem scanning
- *
- * 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 FILEREPRESENTATION_H
-#define FILEREPRESENTATION_H
-
-#include <sys/types.h>
-
-class cStringBuilder;
-class cFileRepresentation {
-public:
- virtual ~cFileRepresentation();
-
- const char *Path(void) const;
- const cFileRepresentation *getParent(void) const { return parent; };
- void SetVirtualRoot(bool isRoot);
-
-private:
- cFileRepresentation(const char *Name);
- cFileRepresentation(const cFileRepresentation *Parent, const char *Name);
- char *toURI(void) const;
- bool exists;
- bool isRoot;
- bool isVirtualRoot;
- mode_t mode;
- off64_t size;
- ulong lastModified;
- char *name;
- mutable char *path;
- const cFileRepresentation *parent;
- friend class cFileSystem;
- friend class cFile;
- };
-
-#endif // FILEREPRESENTATION_H
diff --git a/libs/IO/FileSystem.cc b/libs/IO/FileSystem.cc
deleted file mode 100644
index 3891c97..0000000
--- a/libs/IO/FileSystem.cc
+++ /dev/null
@@ -1,132 +0,0 @@
-/**
- * ======================== legal notice ======================
- *
- * File: FileSystem.cc
- * Created: 21. Juli 2012, 12
- * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
- * Project: libfsScan: mediatypes and filesystem scanning
- *
- * 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 <FileSystem.h>
-#include <FileRepresentation.h>
-#include <File.h>
-#include <StringBuilder.h>
-#include <iostream>
-#include <stdlib.h>
-#include <string.h>
-
-char cFileSystem::PathSeparator = '/';
-char cFileSystem::RootPath[4] = { PathSeparator, 0, 0, 0 };
-
-cFileSystem::cFileSystem()
-{
-}
-
-cFileSystem::~cFileSystem()
-{
- std::tr1::unordered_map<std::string, cFileRepresentation *>::iterator it = fileCache.begin();
-
- while (it != fileCache.end()) {
- if (it->second) delete it->second;
- ++it;
- }
-}
-
-cFileRepresentation *cFileSystem::cacheEntry(const char* Path)
-{
- if (fileCache.empty()) return NULL;
- std::tr1::unordered_map<std::string, cFileRepresentation *>::iterator it = fileCache.find(Path);
-
- if (it != fileCache.end()) return it->second;
- return NULL;
-}
-
-cFileRepresentation *cFileSystem::representationOfFile(const cFile &Parent, const char* Path)
-{
- cFileRepresentation *parentRep = (cFileRepresentation *) Parent.rep;
- cFileRepresentation *tmp = NULL;
- cStringBuilder *sb = new cStringBuilder(Parent.AbsolutePath());
- char *scratch = strdup(Path);
- char *last = scratch + strlen(Path);
- char *start = *scratch == PathSeparator ? scratch + 1 : scratch;
- char *end = strchr(scratch, PathSeparator);
- char *path;
-
- while (start < last) {
- end = strchr(start, PathSeparator);
- if (!end) end = start + strlen(start);
- *end = 0;
- sb->Append(PathSeparator).Append(start);
- path = sb->toString();
- tmp = cacheEntry(path);
- if (!tmp) {
- tmp = new cFileRepresentation(parentRep, start);
- fileCache[path] = tmp;
- }
- parentRep = tmp;
- free(path);
- start = end + 1;
- }
- free(scratch);
- delete sb;
-
- if (tmp) return tmp;
- return NULL;
-}
-
-cFileRepresentation *cFileSystem::representationOfFile(const char* Path)
-{
- cFileRepresentation *rv = cacheEntry(Path);
-
- if (!rv) {
- cFileRepresentation *tmp = NULL;
- char *scratch = strdup(Path);
- char *p;
-
- for (p = strrchr(scratch, PathSeparator); !rv && p; p = strrchr(scratch, PathSeparator)) {
- if (p > scratch) *p = 0;
- else {
- if (!(rv = cacheEntry(RootPath))) {
- *p = 0;
- tmp = new cFileRepresentation(RootPath);
- fileCache[RootPath] = tmp;
- break;
- }
- }
- if ((tmp = cacheEntry(scratch))) break;
- }
-
- if (tmp) {
- cFileRepresentation *parent = tmp;
- size_t poolSize = fileCache.size();
- const char *last = scratch + strlen(Path);
-
- for (p = scratch + strlen(scratch) + 1; p < last; p += strlen(p) + 1) {
- if (!*(p - 1)) *(p - 1) = PathSeparator;
- tmp = new cFileRepresentation(parent, p);
- fileCache[scratch] = tmp;
- poolSize = fileCache.size();
- parent = tmp;
- }
- rv = parent;
- }
- free(scratch);
- }
- return rv;
-}
-
diff --git a/libs/IO/FileSystem.h b/libs/IO/FileSystem.h
deleted file mode 100644
index 0cf4a2f..0000000
--- a/libs/IO/FileSystem.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/**
- * ======================== legal notice ======================
- *
- * File: FileSystem.h
- * Created: 21. Juli 2012, 12
- * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
- * Project: libfsScan: mediatypes and filesystem scanning
- *
- * 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 FILESYSTEM_H
-#define FILESYSTEM_H
-
-#include <tr1/unordered_map>
-#include <string>
-
-class cFile;
-class cFileRepresentation;
-class cFileSystem {
-public:
- cFileSystem();
- virtual ~cFileSystem();
-
- cFileRepresentation *representationOfFile(const char *Path);
- cFileRepresentation *representationOfFile(const cFile &Parent, const char *Path);
-
-private:
- cFileRepresentation *cacheEntry(const char *Path);
- std::tr1::unordered_map<std::string, cFileRepresentation *> fileCache;
- static char PathSeparator;
- static char RootPath[4];
- friend class cFileRepresentation;
- };
-
-#endif /* FILESYSTEM_H */
-
diff --git a/libs/util/Url.cc b/libs/util/Url.cc
deleted file mode 100644
index ce951e6..0000000
--- a/libs/util/Url.cc
+++ /dev/null
@@ -1,229 +0,0 @@
-/**
- * ======================== 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
deleted file mode 100644
index f4dc1af..0000000
--- a/libs/util/Url.h
+++ /dev/null
@@ -1,67 +0,0 @@
-/**
- * ======================== 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 */
-