web/webclient.hh

00001 /* -*- mode: c++; c-basic-offset: 4; -*- */
00002 #ifndef _LIGOWEBCLIENT_H
00003 #define _LIGOWEBCLIENT_H
00004 /*----------------------------------------------------------------------*/
00005 /*                                                                      */
00006 /* Module Name: webclient                                               */
00007 /*                                                                      */
00008 /* Module Description: Class to access a web server                     */
00009 /*                                                                      */
00010 /* Revision History:                                                    */
00011 /* Rel   Date     Programmer    Comments                                */
00012 /* 0.1   23Feb05  D. Sigg       First release                           */
00013 /*                                                                      */
00014 /* Documentation References:                                            */
00015 /*      Man Pages: webclient.html                                       */
00016 /*      References: none                                                */
00017 /*                                                                      */
00018 /* Author Information:                                                  */
00019 /* Name          Telephone       Fax             e-mail                 */
00020 /* Daniel Sigg   (509) 372-8132  (509) 372-8137  sigg_d@ligo.mit.edu    */
00021 /*                                                                      */
00022 /*                                                                      */
00023 /*                      -------------------                             */
00024 /*                                                                      */
00025 /*                             LIGO                                     */
00026 /*                                                                      */
00027 /*        THE LASER INTERFEROMETER GRAVITATIONAL WAVE OBSERVATORY.      */
00028 /*                                                                      */
00029 /*                     (C) The LIGO Project, 1999.                      */
00030 /*                                                                      */
00031 /*                                                                      */
00032 /* Caltech                              MIT                             */
00033 /* LIGO Project MS 51-33                LIGO Project NW-17 161          */
00034 /* Pasadena CA 91125                    Cambridge MA 01239              */
00035 /*                                                                      */
00036 /* LIGO Hanford Observatory             LIGO Livingston Observatory     */
00037 /* P.O. Box 1970 S9-02                  19100 LIGO Lane Rd.             */
00038 /* Richland WA 99352                    Livingston, LA 70754            */
00039 /*                                                                      */
00040 /*----------------------------------------------------------------------*/
00041 
00042 #include <string>
00043 #include <map>
00044 
00045 namespace web {
00046 
00054    class http_request {
00055    public:
00057       class header_sort {
00058       public:
00060          bool operator () (const std::string& s1, const std::string& s2) const;
00061       };
00063       typedef std::map <std::string, std::string, header_sort> header_type;
00064    
00068       http_request ();
00077       http_request (const char* url, const char* addr, int port = 80);
00081       ~http_request ();
00088       bool open (const char* addr, int port = 80);
00092       void close();
00094 
00099       bool request (const char* url);
00107       bool request (const char* url, const char* addr, int port = 80);
00108    
00110       const header_type& header() const {
00111          return fHeader; }
00113       int size() const {
00114          return fLen; }
00116       char* data() {
00117          return fData; }
00118    
00124       static std::string mangle (const std::string& s);
00130       static std::string demangle (const std::string& s);
00131    
00132    protected:
00134       header_type       fHeader;
00136       char*             fData;
00138       int               fLen;
00140       int               fFill;
00142       int               fSock;
00143    
00145       bool sendRequest (const char* url);
00147       bool recvHeader();
00149       bool recvContent();
00151       bool uncompress();
00152    
00153    private:
00154       http_request (const http_request&);
00155       http_request& operator= (const http_request&);
00156    };
00157 
00158 
00159 }
00160 
00161 #endif

Generated on Sun Mar 8 19:20:52 2009 for dmt by  doxygen 1.5.4