|
From: Christian P. <cp...@us...> - 2005-01-14 14:56:13
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/Net In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21205/include/pclasses/Net Added Files: RTSPSocket.h RTSPHeader.h Log Message: Migrating RTSP standalone lib based on P1 --- NEW FILE: RTSPSocket.h --- /*************************************************************************** * Copyright (C) 2004 by Christian Prochnow * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include <pclasses/IO/URL.h> #include <pclasses/IO/IODevice.h> #include <pclasses/Net/Socket.h> #include <pclasses/Net/RTSPHeader.h> namespace P { namespace Net { //! RTSP request class class RTSPRequest { public: //! RTSP Request methods enum Method { DESCRIBE, ANNOUNCE, GET_PARAMETER, OPTIONS, PAUSE, PLAY, RECORD, REDIRECT, SETUP, SET_PARAMETER, TEARDOWN }; RTSPRequest(Method m); RTSPRequest(Method m, const IO::URL& url); ~RTSPRequest() throw(); Method method() const throw(); void setUrl(const IO::URL& url) throw(); void clearUrl() throw(); bool hasUrl() const throw(); const IO::URL& url() const throw(); const RTSPRequestHeader& header() const throw(); RTSPRequestHeader& header() throw(); private: Method _method; IO::URL _url; bool _urlValid; RTSPRequestHeader _header; }; class RTSPSocket; //! RTSP response class class RTSPResponse: public IO::IODevice { public: RTSPResponse(RTSPSocket& socket, const std::string& protoVer, int code, const std::string& reason); ~RTSPResponse() throw(); const RTSPResponseHeader& header() const throw(); RTSPResponseHeader& header() throw(); const std::string& protocolVersion() const throw(); int statusCode() const throw(); const std::string& reason() const throw(); private: void _close() throw(IO::IOError); size_t _write(const char* buffer, size_t count) throw(IO::IOError); size_t _read(char* buffer, size_t count) throw(IO::IOError); RTSPSocket* _socket; RTSPResponseHeader _header; std::string _protoVer; int _statusCode; std::string _reason; size_t _bytesRead; size_t _contentLength; }; //! RTSP coomunication socket class RTSPSocket: public StreamSocket { public: RTSPSocket(); RTSPSocket(Socket::Domain d); RTSPSocket(const NetworkAddress& addr, port_t port); ~RTSPSocket() throw(); void open(Domain d) throw(IO::IOError); void sendRequest(RTSPRequest& req) throw(IO::IOError); RTSPResponse readResponse() throw(IO::IOError); }; } // !namespace Net } // !namespace P --- NEW FILE: RTSPHeader.h --- /*************************************************************************** * Copyright (C) 2004 by Christian Prochnow * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef P_Net_RTSPHeader_h #define P_Net_RTSPHeader_h #include <pclasses/PropertyMap.h> #include <string> namespace P { namespace Net { //! RTSP Header base-class class RTSPHeader: public PropertyMap<std::string, std::string> { public: RTSPHeader(); ~RTSPHeader(); /* SETUP, optional standard values request: no-cache, max-stale, min-fresh, only-if-cached response: public, private, no-cache, no-transform, must-revalidate, proxy-revalidate, max-age=<delta seconds> */ inline void setCacheControl(const std::string& val) { set("Cache-Control", val); } /* all, required */ inline void setConnection(const std::string& val) { set("Connection", val); } inline const std::string& connection() const { return get("Connection"); } /* all, optional */ inline void setDate(const std::string& val) { set("Date", val); } /* all, optional */ inline void setVia(const std::string& val) { set("Via", val); } /* all, required */ inline void setCSeq(const std::string& val) { set("CSeq", val); } /* all but SETUP, OPTIONS - required */ inline void setSession(const std::string& val) { set("Session", val); } /* PLAY, PAUSE, RECORD - optional */ inline void setRange(const std::string& val) { set("Range", val); } }; //! RTSP Request header class RTSPRequestHeader: public RTSPHeader { public: RTSPRequestHeader(); ~RTSPRequestHeader(); /* entity, optional */ inline void setAccept(const std::string& val) { set("Accept", val); } /* entity, optional */ inline void setAcceptEncoding(const std::string& val) { set("Accept-Encoding", val); } /* all, optional */ inline void setAcceptLanguage(const std::string& val) { set("Accept-Language", val); } /* all, optional */ inline void setAuthorization(const std::string& val) { set("Authorization", val); } /* all, optional */ inline void setFrom(const std::string& val) { set("From", val); } /* DESCRIBE, SETUP - optional */ inline void setIfModifiedSince(const std::string& val) { set("If-Modified-Since", val); } /* all, optional */ inline void setReferer(const std::string& val) { set("Referer", val); } /* all, optional */ inline void setUserAgent(const std::string& val) { set("User-Agent", val); } inline void setProxyRequire(const std::string& val) { set("Proxy-Require", val); } }; //! RTSP Response header class RTSPResponseHeader: public RTSPHeader { public: RTSPResponseHeader(); ~RTSPResponseHeader(); inline void setLocation(const std::string& val) { set("Location", val); } inline void setProxyAuthenticate(const std::string& val) { set("Proxy-Authenticate", val); } inline void setPublic(const std::string& val) { set("Public", val); } inline void setRetryAfter(const std::string& val) { set("Retry-After", val); } inline void setServer(const std::string& val) { set("Server", val); } inline void setVary(const std::string& val) { set("Vary", val); } inline void setWWWAuthenticate(const std::string& val) { set("WWW-Authenticate", val); } /* all, optional */ inline void setAllow(const std::string& val) { set("Allow", val); } inline void setContentBase(const std::string& val) { set("Content-Base", val); } inline void setContentEncoding(const std::string& val) { set("Content-Encoding", val); } inline void setContentLanguage(const std::string& val) { set("Content-Language", val); } inline void setContentLegth(const std::string& val) { set("Content-Legth", val); } inline void setContentLocation(const std::string& val) { set("Content-Location", val); } inline void setContentType(const std::string& val) { set("Content-Type", val); } inline void setExpires(const std::string& val) { set("Expires", val); } inline void setLastModified(const std::string& val) { set("Last-Modified", val); } }; } // !namespace Net } // !namespace P #endif |