summaryrefslogtreecommitdiff
path: root/libs/networking/include
diff options
context:
space:
mode:
authorgeronimo <geronimo013@gmx.de>2012-07-13 02:26:40 (GMT)
committergeronimo <geronimo013@gmx.de>2012-07-13 02:26:40 (GMT)
commit2d48ae784ea6828e8626c32c848f64232d8f35c0 (patch)
treefab114b03e91125783a778b835dd1913b039cebe /libs/networking/include
downloadcmp-2d48ae784ea6828e8626c32c848f64232d8f35c0.tar.gz
cmp-2d48ae784ea6828e8626c32c848f64232d8f35c0.tar.bz2
initial import
Diffstat (limited to 'libs/networking/include')
-rw-r--r--libs/networking/include/AbstractSocket.h63
-rw-r--r--libs/networking/include/Authorization.h115
-rw-r--r--libs/networking/include/ClientSocket.h39
-rw-r--r--libs/networking/include/ConnectionHandler.h77
-rw-r--r--libs/networking/include/ConnectionPoint.h60
-rw-r--r--libs/networking/include/Credentials.h61
-rw-r--r--libs/networking/include/HTTPAuthorizationRequest.h41
-rw-r--r--libs/networking/include/HTTPFileResponse.h48
-rw-r--r--libs/networking/include/HTTPMessage.h92
-rw-r--r--libs/networking/include/HTTPParser.h47
-rw-r--r--libs/networking/include/HTTPRequest.h62
-rw-r--r--libs/networking/include/HTTPRequestHandler.h48
-rw-r--r--libs/networking/include/HTTPResponse.h73
-rw-r--r--libs/networking/include/HTTPServer.h61
-rw-r--r--libs/networking/include/HTTPStatus.h74
-rw-r--r--libs/networking/include/Principal.h64
-rw-r--r--libs/networking/include/ServerConfig.h56
-rw-r--r--libs/networking/include/ServerSocket.h52
-rw-r--r--libs/networking/include/Url.h67
19 files changed, 1200 insertions, 0 deletions
diff --git a/libs/networking/include/AbstractSocket.h b/libs/networking/include/AbstractSocket.h
new file mode 100644
index 0000000..ff76f52
--- /dev/null
+++ b/libs/networking/include/AbstractSocket.h
@@ -0,0 +1,63 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: AbstractSocket.h
+ * Created: 4. Juli 2012, 07:13
+ * 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 ABSTRACTSOCKET_H
+#define ABSTRACTSOCKET_H
+
+#include <ConnectionPoint.h>
+#include <sys/socket.h>
+
+class cAbstractSocket {
+public:
+ virtual ~cAbstractSocket();
+ const cConnectionPoint *ThisSide(void) const { return thisSide; }
+ const cConnectionPoint *OtherSide(void) const { return others[0]; }
+ cConnectionPoint *ThisSide(void) { return thisSide; }
+ cConnectionPoint *OtherSide(void) { return others[0]; }
+ virtual void ConfigureSocket(int Socket) {}
+
+protected:
+ cAbstractSocket(int Port, int Queue = 1);
+ cAbstractSocket(const char *ServerName, int Port);
+ bool Connect();
+ bool Open(int Port);
+ cConnectionPoint *Accept(int Port, int TimeoutMs = -1);
+ bool ForceBlockingIO(void) const { return blocking; }
+ void SetBlockingIO(bool ForceBlockingIO = true);
+ cConnectionPoint *GetNameAndAddress(int Socket, struct sockaddr *sa, socklen_t sa_size);
+ void Close(void);
+
+private:
+ int sock;
+ int queue;
+ bool blocking;
+ cConnectionPoint *thisSide;
+ ConnectionPointList others; ///< client sockets have only one other side,
+ ///< but server sockets can have multiple connections open at the same time,
+ ///< so we probabely need a container here.
+ // cConnectionPointInfo *FetchLocalInfo(int Socket, struct addrinfo *AI);
+ };
+
+#endif /* ABSTRACTSOCKET_H */
+
diff --git a/libs/networking/include/Authorization.h b/libs/networking/include/Authorization.h
new file mode 100644
index 0000000..fa04bd4
--- /dev/null
+++ b/libs/networking/include/Authorization.h
@@ -0,0 +1,115 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: Authorization.h
+ * Created: 3. Juli 2012, 17:27
+ * 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 AUTHORIZATION_H
+#define AUTHORIZATION_H
+
+#include <HTTPRequest.h>
+#include <Principal.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stddef.h>
+#include <time.h>
+#include <ManagedVector.h>
+
+class cAuthorization {
+public:
+ cAuthorization(const cHTTPRequest &OriginalRequest, char *NOnceFromHeap);
+ cAuthorization(cHTTPRequest::HTTPRequestMethod Method, const char *Raw);
+ cAuthorization(const cAuthorization &other);
+ cAuthorization(const cPrincipal *Principal, cHTTPRequest::HTTPRequestMethod Method, const cAuthorization &other);
+ virtual ~cAuthorization();
+ cAuthorization &operator =(const cAuthorization &other);
+ size_t Write(char *Buffer, size_t BufSize);
+ const char *CalculateResponse(const char *Uri = NULL, const char *Username = NULL, const char *Password = NULL);
+ void Dump(void) const;
+ const char *Uri(void) const { return uri; }
+ const char *Response(void) const { return response; }
+ const char *CNOnce(void) const { return cnonce; }
+ const char *NOnce(void) const { return nonce; }
+ const char *Opaque(void) const { return opaque; }
+ const char *UserID(void) const {
+ if (principal) return principal->Name();
+ else if (tmp) return tmp->Name();
+ return NULL;
+ }
+ const char *UserCredential(void) const {
+ if (principal) return principal->Hash();
+ else if (tmp) return tmp->Hash();
+ return NULL;
+ }
+ const char *Realm(void) const {
+ if (principal) return principal->Realm();
+ else if (tmp) return tmp->Realm();
+ return NULL;
+ }
+ void SetUser(const char *UserID, const char *Password);
+ char *CalculateA1(const char *Username = NULL, const char *Password = NULL);
+ char *CalculateA2(const char *Uri);
+
+protected:
+ virtual void ParseRawBuffer(const char *Raw);
+ virtual void CreateClientHash();
+ const cPrincipal *Principal(void) const { return principal; }
+ void SetAttribute(char *Name, const char *Value);
+ void SetOpaque(char *Value);
+ void SetPrincipal(const cPrincipal *Principal) { principal = Principal; }
+
+private:
+ void SetServerID(const char *ServerID) { free(serverID); serverID = ServerID ? strdup(ServerID) : NULL; }
+ void SetUri(const char *Uri) { free(uri); uri = Uri ? strdup(Uri) : NULL; }
+ cPrincipal *tmp;
+ const cPrincipal *principal;
+ cHTTPRequest::HTTPRequestMethod method;
+ char *serverID;
+ bool sessAlgo;
+ char *nonce;
+ char *uri;
+ char *response;
+ char *opaque;
+ char *cnonce;
+ char *qop;
+ int counter;
+ time_t authTime;
+ friend class cHTTPResponse;
+ friend class cHTTPRequest;
+ friend class cAuthorizations;
+ friend class cConnectionHandler;
+ };
+
+class cConnectionPoint;
+class cAuthorizations : public cManagedVector {
+public:
+ cAuthorizations();
+ virtual ~cAuthorizations();
+
+ cAuthorization *FindAuthorization(const char *SessionID);
+ void Del(cAuthorization *Auth2Invalidate);
+ const cAuthorization &CreateAuthorization(const cHTTPRequest &OriginalRequest, const cConnectionPoint &client, unsigned long connectionNumber);
+ static char *CreateNOnce(const cConnectionPoint &client, unsigned long connectionNumber);
+ static char *CreateSessionID(const cHTTPRequest &OriginalRequest, time_t AuthTime);
+ };
+
+#endif /* AUTHORIZATION_H */
+
diff --git a/libs/networking/include/ClientSocket.h b/libs/networking/include/ClientSocket.h
new file mode 100644
index 0000000..0dc899e
--- /dev/null
+++ b/libs/networking/include/ClientSocket.h
@@ -0,0 +1,39 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: ClientSocket.h
+ * Created: 4. Juli 2012, 07:25
+ * 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 CLIENTSOCKET_H
+#define CLIENTSOCKET_H
+
+#include <AbstractSocket.h>
+
+class cClientSocket : public cAbstractSocket {
+public:
+ cClientSocket(const char *serverName, int Port);
+ virtual ~cClientSocket();
+ bool Connect(void);
+ void Close(void);
+ };
+
+#endif /* CLIENTSOCKET_H */
+
diff --git a/libs/networking/include/ConnectionHandler.h b/libs/networking/include/ConnectionHandler.h
new file mode 100644
index 0000000..c4232be
--- /dev/null
+++ b/libs/networking/include/ConnectionHandler.h
@@ -0,0 +1,77 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: ConnectionHandler.h
+ * Created: 4. Juli 2012, 07:32
+ * 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 CONNECTIONHANDLER_H
+#define CONNECTIONHANDLER_H
+
+#include <Thread.h>
+#include <ServerConfig.h>
+#include <sys/types.h>
+
+class cConnectionPoint;
+class cAuthorization;
+class cHTTPResponse;
+class cHTTPRequest;
+class cFileHandler;
+class cHTTPRequestHandler;
+class cStringBuilder;
+class cConnectionHandler : public cThread {
+public:
+ cConnectionHandler(cConnectionPoint &Client, cServerConfig &Config, bool StayConnected = false);
+ virtual ~cConnectionHandler();
+
+ void Action(void);
+
+ bool AuthorizationRequired(void) { return config.AuthorizationRequired(); }
+ const char *NOnce(void) const { return nonce; }
+ bool StayConnected(void) const { return stayConnected; }
+ virtual void Cancel(int WaitSeconds = 0);
+
+ static void RegisterRequestHandler(const char *UrlPrefix, cHTTPRequestHandler *CommandHandler);
+ static void RegisterDefaultHandler(cHTTPRequestHandler *DefaultHandler);
+ static void Cleanup(void);
+
+protected:
+ cAuthorizations &Authorizations(void) { return config.authorizations; }
+ cServerSocket &ServerSocket(void) { return config.server; }
+ cHTTPResponse *ProcessRequest(cHTTPRequest &Request);
+ void TransferResponse(cHTTPResponse *Response);
+ void SetNonce(char *NOnce) { nonce = NOnce; }
+ bool IsAuthorizationValid(cAuthorization *ServerAuth, const cHTTPRequest &request);
+ void Usage(cStringBuilder &sb);
+
+private:
+ void Init(void);
+ cServerConfig &config;
+ cConnectionPoint &client;
+ unsigned long connectionNumber;
+ size_t bufSize;
+ char *scratch;
+ char *nonce;
+ bool stayConnected;
+ friend class cTestUnit;
+ };
+
+#endif /* CONNECTIONHANDLER_H */
+
diff --git a/libs/networking/include/ConnectionPoint.h b/libs/networking/include/ConnectionPoint.h
new file mode 100644
index 0000000..8980adb
--- /dev/null
+++ b/libs/networking/include/ConnectionPoint.h
@@ -0,0 +1,60 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: ConnectionPoint.h
+ * Created: 4. Juli 2012, 06:29
+ * 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 CONNECTIONPOINT_H
+#define CONNECTIONPOINT_H
+
+#include <stddef.h>
+#include <vector>
+
+class cConnectionPoint {
+public:
+ cConnectionPoint(const char *NameOrIP, int Port, const char *RealName = NULL);
+ virtual ~cConnectionPoint();
+
+ int IOWait(long MilliSeconds = 300);
+ const char *HostName(void) const { return nameOrIP; }
+ const char *RealName(void) const { return realName ? realName : "unknown"; }
+ const char *ToString() const { return combined ? combined : AssembleCombined(); }
+ int Port(void) const { return port; }
+ int Socket(void) const { return sock; }
+
+private:
+ char *nameOrIP;
+ char *realName;
+ mutable char *combined;
+ int port;
+ int sock;
+ const char *AssembleCombined(void) const;
+ void Close(void);
+ void SetSocket(int Socket) { sock = Socket; }
+ void SetRealName(const char *Name);
+ friend class cAbstractSocket;
+ friend class cConnectionHandler;
+ };
+
+typedef std::vector<cConnectionPoint *> ConnectionPointList;
+
+#endif /* CONNECTIONPOINT_H */
+
diff --git a/libs/networking/include/Credentials.h b/libs/networking/include/Credentials.h
new file mode 100644
index 0000000..c27532d
--- /dev/null
+++ b/libs/networking/include/Credentials.h
@@ -0,0 +1,61 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: Credentials.h
+ * Created: 3. Juli 2012, 14:37
+ * 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 CREDENTIALS_H
+#define CREDENTIALS_H
+
+#include <Principal.h>
+#include <string>
+#include <tr1/unordered_map>
+
+class cCredentials {
+public:
+ typedef std::tr1::unordered_map<std::string, cPrincipal *>::const_iterator const_iterator;
+ cCredentials();
+ virtual ~cCredentials();
+
+ const cPrincipal *FindPrincipal(const char *Name, const char *Realm);
+ const char *ApplicationRealm(void) const;
+ void SetApplicationRealm(const char *ApplicationRealm = "knownUser@myApp");
+
+ int Load(const char *FileName);
+ int Store(const char *FileName);
+
+ void Put(const char *Key, cPrincipal *p);
+ cPrincipal *Get(const char *Key);
+ void Clear(void);
+
+ const_iterator begin() { return internalMap.begin(); }
+ const_iterator end() { return internalMap.end(); }
+
+private:
+ cPrincipal *parsePrincipal(char *buf, size_t bufSize);
+ std::tr1::unordered_map<std::string, cPrincipal *> internalMap;
+ typedef std::tr1::unordered_map<std::string, cPrincipal *>::iterator iterator;
+ };
+
+extern cCredentials Credentials;
+
+#endif /* CREDENTIALS_H */
+
diff --git a/libs/networking/include/HTTPAuthorizationRequest.h b/libs/networking/include/HTTPAuthorizationRequest.h
new file mode 100644
index 0000000..d3d566d
--- /dev/null
+++ b/libs/networking/include/HTTPAuthorizationRequest.h
@@ -0,0 +1,41 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: HTTPAuthorizationRequest.h
+ * Created: 4. Juli 2012, 07:41
+ * 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 HTTPAUTHORIZATIONREQUEST_H
+#define HTTPAUTHORIZATIONREQUEST_H
+
+#include <HTTPResponse.h>
+
+class cHTTPRequest;
+class cHTTPAuthorizationRequest : public cHTTPResponse {
+///< the server requires authorization, so the message is a response
+///< The clients response is another (repeated) request with authentication headers
+public:
+ cHTTPAuthorizationRequest(const cHTTPRequest &OriginalRequest, char *NOnceFromHeap);
+ cHTTPAuthorizationRequest(const cAuthorization &Authorization);
+ virtual ~cHTTPAuthorizationRequest();
+ };
+
+#endif /* HTTPAUTHORIZATIONREQUEST_H */
+
diff --git a/libs/networking/include/HTTPFileResponse.h b/libs/networking/include/HTTPFileResponse.h
new file mode 100644
index 0000000..0457850
--- /dev/null
+++ b/libs/networking/include/HTTPFileResponse.h
@@ -0,0 +1,48 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: HTTPFileResponse.h
+ * Created: 4. Juli 2012, 07:50
+ * 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 HTTPFILERESPONSE_H
+#define HTTPFILERESPONSE_H
+
+#include <HTTPResponse.h>
+
+class cHTTPFileResponse : public cHTTPResponse {
+public:
+ cHTTPFileResponse(const char *RealPath);
+ virtual ~cHTTPFileResponse();
+ const char *RealPath(void) const { return realPath; }
+
+ virtual size_t ReadContentChunk(char *Buf, size_t bufSize);
+
+protected:
+ cHTTPFileResponse();
+
+private:
+ void DetermineTypeAndSize(const char *Path);
+ const char *realPath;
+ int fd;
+ };
+
+#endif /* HTTPFILERESPONSE_H */
+
diff --git a/libs/networking/include/HTTPMessage.h b/libs/networking/include/HTTPMessage.h
new file mode 100644
index 0000000..cb88c69
--- /dev/null
+++ b/libs/networking/include/HTTPMessage.h
@@ -0,0 +1,92 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: HTTPMessage.h
+ * Created: 3. Juli 2012, 17:40
+ * 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 HTTPMESSAGE_H
+#define HTTPMESSAGE_H
+
+#define MT_Html "text/html"
+
+#include <ManagedMap.h>
+
+class cAuthorization;
+class cHTTPMessage {
+public:
+ typedef enum { Unknown, HTTP_1_0, HTTP_1_1 } HTTPProtocol;
+
+ cHTTPMessage(HTTPProtocol Proto=HTTP_1_1);
+ virtual ~cHTTPMessage();
+
+ HTTPProtocol Protocol(void) { return protocol; }
+ const char *ProtocolString(void);
+ const char *ContentType(void) const { return contentType; }
+ virtual size_t ContentSize(void) const;
+ const char *GetHeader(const char *Name) const;
+ const cAuthorization *Authorization(void) const { return auth; }
+ void SetAuthorization(cAuthorization *Authorization);
+ size_t WritePrefix(char *Buffer, size_t BufSize); ///< writes message header, so content will follow
+ virtual void Dump(void);
+
+protected:
+ enum ParseState {
+ ExpectFormat
+ , ExpectURL
+ , ExpectProtocol
+ , ExpectStatus
+ , ExpectHeader
+ , ExpectContent
+ };
+ enum ParseResult {
+ UnknownError
+ , UnsupportedFormat
+ , InvalidURL
+ , InvalidName
+ , UnsupportedProtocol
+ , Continue
+ , Done
+ };
+ virtual size_t WriteFirstLine(char *Buffer, size_t BufSize) = 0;
+ virtual void SetContentType(const char *ContentType);
+ virtual void SetContentSize(size_t ContentSize) { contentSize = ContentSize; }
+ void SetHeader(const char *Name, const char *Value);
+ void SetProtocol(HTTPProtocol Protocol) { protocol = Protocol; }
+ cAuthorization *Authorization(void) { return auth; }
+ char *FormatTime(time_t time);
+ const cManagedMap &Headers() const { return header; }
+ int WriteTime(char *Buffer, size_t BufSize);
+ void Reset(void);
+
+private:
+ HTTPProtocol protocol;
+ time_t timeStamp;
+ cManagedMap header;
+ cAuthorization *auth;
+ size_t contentSize;
+ char *contentType;
+ friend class cMediaListHandler;
+ friend class cConnectionHandler;
+ friend class cTestUnit;
+ };
+
+#endif /* HTTPMESSAGE_H */
+
diff --git a/libs/networking/include/HTTPParser.h b/libs/networking/include/HTTPParser.h
new file mode 100644
index 0000000..9ed8169
--- /dev/null
+++ b/libs/networking/include/HTTPParser.h
@@ -0,0 +1,47 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: HTTPParser.h
+ * Created: 10. Juli 2012, 08:37
+ * 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 HTTPPARSER_H
+#define HTTPPARSER_H
+
+class cHTTPMessage;
+class cHTTPRequest;
+class cHTTPResponse;
+class cHTTPParser
+{
+public:
+ cHTTPParser();
+ virtual ~cHTTPParser();
+
+ cHTTPMessage *ParseMessage(const char *MessageBuf);
+
+protected:
+ cHTTPRequest *parseRequest(const char *MessageBuf);
+ cHTTPResponse *parseResponse(const char *MessageBuf);
+
+private:
+};
+
+#endif /* HTTPPARSER_H */
+
diff --git a/libs/networking/include/HTTPRequest.h b/libs/networking/include/HTTPRequest.h
new file mode 100644
index 0000000..87c78d7
--- /dev/null
+++ b/libs/networking/include/HTTPRequest.h
@@ -0,0 +1,62 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: HTTPRequest.h
+ * Created: 3. Juli 2012, 17:54
+ * 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 HTTPREQUEST_H
+#define HTTPREQUEST_H
+
+#include <HTTPMessage.h>
+#include <Url.h>
+
+class cHTTPResponse;
+class cHTTPRequest : public cHTTPMessage {
+///< a message sent from client to server to access a certain resource
+public:
+ typedef enum { INVALID, GET, POST } HTTPRequestMethod;
+ cHTTPRequest(const char *MessageBuf);
+ cHTTPRequest(HTTPRequestMethod Format, const char *Url);
+ cHTTPRequest(const cHTTPResponse &res, const char *Url);
+ virtual ~cHTTPRequest();
+ HTTPRequestMethod Method(void) const { return method; }
+ const cUrl &Url() const { return url; }
+ cUrl &Url() { return url; }
+ const char *UserAgent() const;
+ const char *ClientHost(void) const;
+ void SetUser(const char *UserID, const char *Password);
+
+protected:
+ void SetMethod(HTTPRequestMethod Method) { method = Method; }
+ void SetURL(const char *Url);
+ virtual size_t WriteFirstLine(char *Buffer, size_t BufSize);
+ void ParseMessage(const char *MessageBuf);
+
+private:
+ HTTPRequestMethod method;
+ cUrl url;
+ friend class HTTPParser;
+ };
+
+extern const char *requestMethod2String(cHTTPRequest::HTTPRequestMethod Method);
+
+#endif /* HTTPREQUEST_H */
+
diff --git a/libs/networking/include/HTTPRequestHandler.h b/libs/networking/include/HTTPRequestHandler.h
new file mode 100644
index 0000000..99c31d2
--- /dev/null
+++ b/libs/networking/include/HTTPRequestHandler.h
@@ -0,0 +1,48 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: HTTPRequestHandler.h
+ * Created: 4. Juli 2012, 15:12
+ * 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 HTTPREQUESTHANDLER_H
+#define HTTPREQUESTHANDLER_H
+
+class cHTTPRequest;
+class cHTTPResponse;
+class cStringBuilder;
+class cHTTPRequestHandler {
+public:
+ cHTTPRequestHandler();
+ virtual ~cHTTPRequestHandler();
+
+ virtual cHTTPResponse *ProcessRequest(cHTTPRequest &Request) = 0;
+ virtual void Usage(cStringBuilder &sb) = 0;
+
+ const char *ID() const { return prefix; }
+
+private:
+ void SetID(const char *UrlPrefix);
+ char *prefix;
+ friend class cHTTPRequestHandlers;
+ };
+
+#endif /* HTTPREQUESTHANDLER_H */
+
diff --git a/libs/networking/include/HTTPResponse.h b/libs/networking/include/HTTPResponse.h
new file mode 100644
index 0000000..afa4ae5
--- /dev/null
+++ b/libs/networking/include/HTTPResponse.h
@@ -0,0 +1,73 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: HTTPResponse.h
+ * Created: 4. Juli 2012, 06:03
+ * 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 HTTPRESPONSE_H
+#define HTTPRESPONSE_H
+
+#define MT_Unknown "unsupported/unknown"
+#define MT_CSS "text/css"
+#define MT_JavaScript "application/javascript"
+#define MT_Gif "image/gif"
+#define MT_Png "image/png"
+#define MT_Ico "image/x-icon"
+#define MT_Jpg "image/jpeg"
+#define MT_Xml "application/xml"
+#define MT_XmlDtd "application/xml-dtd"
+
+#include <HTTPStatus.h>
+#include <HTTPMessage.h>
+#include <StringBuilder.h>
+
+class cHTTPResponse : public cHTTPMessage {
+public:
+ cHTTPResponse(HTTPStatusCode Status = HTTP_OK);
+ ///< server side creates a response by status code
+ cHTTPResponse(const char *Buffer);
+ ///< client side creates a response from receiving buffer
+ virtual ~cHTTPResponse();
+
+ HTTPStatusCode Status(void) const { return status; }
+ virtual size_t ContentSize(void) const;
+ virtual void SetContentType(const char *ContentType) { cHTTPMessage::SetContentType(ContentType); }
+ virtual void SetContentSize(size_t ContentSize) { cHTTPMessage::SetContentSize(ContentSize); }
+ cStringBuilder &StringBuilder(void) { return content; }
+
+ static const char *ServerID(void);
+ static void SetServerID(const char *ServerID);
+
+protected:
+ virtual size_t WriteFirstLine(char *Buffer, size_t BufSize);
+ void ParseMessage(const char *MessageBuf);
+
+private:
+ virtual size_t ReadContentChunk(char *Buf, size_t bufSize);
+ void SetDefaultStatusBody(HTTPStatusCode Status);
+ HTTPStatusCode status;
+ cStringBuilder content;
+ friend class cConnectionHandler;
+ friend class HTTPParser;
+ };
+
+#endif /* HTTPRESPONSE_H */
+
diff --git a/libs/networking/include/HTTPServer.h b/libs/networking/include/HTTPServer.h
new file mode 100644
index 0000000..4dbe5a8
--- /dev/null
+++ b/libs/networking/include/HTTPServer.h
@@ -0,0 +1,61 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: HTTPServer.h
+ * Created: 4. Juli 2012, 12:16
+ * 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 HTTPSERVER_H
+#define HTTPSERVER_H
+
+#include <ServerConfig.h>
+#include <Mutex.h>
+#include <vector>
+
+class cThread;
+class cHTTPServer /* : public cThread */ {
+public:
+ cHTTPServer(cServerConfig &Config);
+ ~cHTTPServer();
+
+ bool Start(void);
+ void Stop(void);
+
+protected:
+ void Action(void);
+ bool AuthorizationRequired(void) const { return config.AuthorizationRequired(); }
+ bool Running(void);
+ cServerSocket &ServerSocket() { return config.server; }
+
+private:
+#ifdef LIVE_CLEANUP
+ void Cleanup(cThread *ThreadContext);
+ static int cleanerThread(void *opaque, cThread *ThreadContext);
+ cThread *cleaner;
+ cMutex poolMutex;
+#else
+ void Cleanup();
+#endif
+ cServerConfig &config;
+ std::vector<cThread *> *threads;
+ };
+
+#endif /* HTTPSERVER_H */
+
diff --git a/libs/networking/include/HTTPStatus.h b/libs/networking/include/HTTPStatus.h
new file mode 100644
index 0000000..10ff080
--- /dev/null
+++ b/libs/networking/include/HTTPStatus.h
@@ -0,0 +1,74 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: HTTPStatus.h
+ * Created: 3. Juli 2012, 17:34
+ * 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 HTTPSTATUS_H
+#define HTTPSTATUS_H
+
+typedef enum {
+ HTTP_Continue = 100
+, HTTP_SwitchProtocol = 101
+, HTTP_OK = 200
+, HTTP_Created = 201
+, HTTP_Accepted = 202
+, HTTP_NoContent = 204
+, HTTP_ResetContent = 205
+, HTTP_PartialContent = 206
+, HTTP_MultipleChoices = 300
+, HTTP_MovedPermanently = 301
+, HTTP_Found = 302
+, HTTP_SeeOther = 303
+, HTTP_NotModified = 304
+, HTTP_UseProxy = 305
+, HTTP_MovedTemporarily = 307
+, HTTP_BadRequest = 400
+, HTTP_UnAuthorized = 401
+, HTTP_PaymentRequired = 402
+, HTTP_Forbidden = 403
+, HTTP_NotFound = 404
+, HTTP_MethodNotAllowed = 405
+, HTTP_NotAcceptable = 406
+, HTTP_ProxyAuthenticationRequired = 407
+, HTTP_RequestTimeout = 408
+, HTTP_Conflict = 409
+, HTTP_Gone = 410
+, HTTP_LengthRequired = 411
+, HTTP_PreconditionFailed = 412
+, HTTP_RequestTooLarge = 413
+, HTTP_RequestURIToLong = 414
+, HTTP_UnsupportedMediaType = 415
+, HTTP_RequestRangeNotSatisfiable = 416
+, HTTP_ExpectationFailed = 417
+, HTTP_InternalServerError = 500
+, HTTP_NotImplemented = 501
+, HTTP_BadGateway = 502
+, HTTP_ServiceUnavailable = 503
+, HTTP_GatewayTimeout = 504
+, HTTP_VersionNotSupported = 505
+ } HTTPStatusCode;
+
+extern const char *httpStatus2Text(int Status);
+extern HTTPStatusCode strtoHTTPStatus(const char *p);
+
+#endif /* HTTPSTATUS_H */
+
diff --git a/libs/networking/include/Principal.h b/libs/networking/include/Principal.h
new file mode 100644
index 0000000..49afbde
--- /dev/null
+++ b/libs/networking/include/Principal.h
@@ -0,0 +1,64 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: Principal.h
+ * Created: 3. Juli 2012, 12:50
+ * 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 PRINCIPAL_H
+#define PRINCIPAL_H
+
+class cPrincipal {
+public:
+ cPrincipal(const char *Name, const char *Realm);
+ cPrincipal(const cPrincipal &other);
+ virtual ~cPrincipal();
+ cPrincipal &operator =(const cPrincipal &other);
+ const char *operator *(void) { return name; }
+
+ void CreateHash(const char *Password);
+
+ const char *Name(void) const { return name; }
+ const char *Realm(void) const { return realm; }
+ const char *ExtendedInfo(void) const { return xinfo; }
+ int Age(void) const { return age; }
+ void SetAge(int Age) { age = Age; }
+ const char *Hash(void) const { return hash; }
+
+ void Dump(void) const;
+
+protected:
+ void SetName(const char *Name);
+ void SetRealm(const char *Realm);
+ void SetExtendedInfo(const char *Info);
+ void SetHash(const char *Hash);
+
+private:
+ char *name;
+ char *realm;
+ char *hash;
+ char *xinfo;
+ int age;
+ friend class cAuthorization;
+ friend class cCredentials;
+ };
+
+#endif /* PRINCIPAL_H */
+
diff --git a/libs/networking/include/ServerConfig.h b/libs/networking/include/ServerConfig.h
new file mode 100644
index 0000000..f64b5f5
--- /dev/null
+++ b/libs/networking/include/ServerConfig.h
@@ -0,0 +1,56 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: ServerConfig.h
+ * Created: 8. Juli 2012, 06:12
+ * 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 SERVERCONFIG_H
+#define SERVERCONFIG_H
+
+#include <ServerSocket.h>
+#include <Authorization.h>
+
+class cServerConfig
+{
+public:
+ cServerConfig(int Port);
+ virtual ~cServerConfig();
+
+ bool AuthorizationRequired(void) { return authorizationRequired; }
+ const char *AppIconPath(void) const { return appIconPath; }
+ const char *DocumentRoot(void) const { return documentRoot; }
+
+ void SetAppIcon(const char *AppIcon);
+ void SetAuthorizationRequired(bool Authorize) { authorizationRequired = Authorize; }
+ void SetDocumentRoot(const char *DocumentRoot);
+
+private:
+ cServerSocket server;
+ cAuthorizations authorizations;
+ bool authorizationRequired;
+ char *documentRoot;
+ char *appIconPath;
+ friend class cHTTPServer;
+ friend class cConnectionHandler;
+};
+
+#endif /* SERVERCONFIG_H */
+
diff --git a/libs/networking/include/ServerSocket.h b/libs/networking/include/ServerSocket.h
new file mode 100644
index 0000000..2fc17fb
--- /dev/null
+++ b/libs/networking/include/ServerSocket.h
@@ -0,0 +1,52 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: ServerSocket.h
+ * Created: 4. Juli 2012, 07:28
+ * 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 SERVERSOCKET_H
+#define SERVERSOCKET_H
+
+#include <AbstractSocket.h>
+
+class cServerSocket : public cAbstractSocket {
+public:
+ cServerSocket(int Port, int Queue = 1);
+ virtual ~cServerSocket();
+ bool Open(void);
+ bool Active(void) const { return active; }
+ void SetActive(bool Active = true) { active = Active; }
+ cConnectionPoint *Accept(void);
+ int Port(void) const { return port; }
+ int ReUseAddress(void) const;
+ void SetReUseAddress(int ReUse);
+ void ConfigureSocket(int Socket);
+ bool ForceBlockingIO(void) const;
+ void SetBlockingIO(bool ForceBlockingIO = true);
+
+private:
+ int port; ///< in case we plenty open and close server sockets
+ ///< we need a place to remember the server port
+ bool active;
+ };
+
+#endif /* SERVERSOCKET_H */
+
diff --git a/libs/networking/include/Url.h b/libs/networking/include/Url.h
new file mode 100644
index 0000000..c88a00a
--- /dev/null
+++ b/libs/networking/include/Url.h
@@ -0,0 +1,67 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: Url.h
+ * Created: 4. Juli 2012, 05:42
+ * 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);
+
+protected:
+ void ParseQueryString(const char *QueryString);
+ cURLEncoder *Encoder(void) const;
+ cURLDecoder *Decoder(void) const;
+
+private:
+ typedef std::tr1::unordered_map<std::string, std::string> ParameterMap;
+ char *path;
+ ParameterMap parameters;
+ };
+
+#endif /* URL_H */
+