interreality.org [VOS]
[Home] [About]
[Screenshots]
[Download]
[News]
[Community]
[Documentation] [Manual]
[Bugs & Requests] [Wiki]

/home/tetron/hack/vos/libs/vos/extensions/http/httpserver.hh

Go to the documentation of this file.
00001 #ifndef _HTTPSERVER_HH_
00002 #define _HTTPSERVER_HH_
00003 
00004 #include <vos/vos/vos.hh>
00005 
00006 #if defined(WIN32)
00007 # ifdef VOSHTTP_EXPORTS
00008 #  define VOSHTTP_API __declspec(dllexport)
00009 # else
00010 #  define VOSHTTP_API __declspec(dllimport)
00011 # endif
00012 #else
00013 # ifdef HAVE_GCC_VISIBILITY
00014 #  define VOSHTTP_API __attribute__ ((visibility("default")))
00015 # else
00016 #  define VOSHTTP_API
00017 # endif
00018 #endif
00019 
00020 
00021 namespace VOS {
00022     class VOSHTTP_API HTTPServer : public SiteExtension
00023     {
00024     public: enum VobjectDescriptionFormat { HTML, RDF };
00025     private:
00026         int listensocket;
00027         Site* site;
00028         int port;
00029         bool alwaysDescribe;
00030         VobjectDescriptionFormat descriptionFormat;
00031     public:
00032         HTTPServer(int port = 4080,
00033             VobjectDescriptionFormat descriptionFormat = HTML,
00034             bool alwaysDescribe = false);
00035 
00036         /** @warning This makes a copy of the HTTPServer object, which
00037             will be used by the site (not your original copy passed
00038             into Site::addSiteExtension(). */
00039         virtual void siteExtensionAttachedTo(Site* site);
00040 
00041         void operator()();
00042         int getPort() {
00043             return port;
00044         }
00045 
00046         void setDescriptionFormat(VobjectDescriptionFormat format);
00047         VobjectDescriptionFormat getDescriptionFormat();
00048         void setAlwaysDescribe(bool q = true);
00049         bool getAlwaysDescribe();
00050 
00051         void describeVobject(Vobject* v, const char* basepath,
00052             std::string& content, std::string& contenttype) ;
00053 
00054     private:
00055         void describeVobject_HTML(Vobject* v, const char* basepath,
00056             std::string& content, std::string& contenttype);
00057 
00058         void describeVobject_RDF(Vobject* v, const char* basepath,
00059             std::string& content, std::string& contenttype);
00060     };
00061 
00062     class HTTPRequest : public VUtil::Task
00063     {
00064     private:
00065         Site* site;
00066         int skt;
00067         HTTPServer* serverExt;
00068     public:
00069         HTTPRequest(Site* st, int socket, HTTPServer* serverExt);
00070         virtual void doTask();
00071         bool readRequest(std::string& method, std::string& uri,
00072                          std::string& protocolversion,
00073                          std::map<std::string, std::string>& headers);
00074         void doGET(std::string& uri, std::string& code,
00075                    std::string& reason,
00076                    std::string& contenttype,
00077                    std::string& content);
00078     };
00079 }
00080 #endif