HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_WebConnection.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_WebConnection.h ( Utility Library, C++ )
7  *
8  * COMMENTS:
9  * This class connects to a web server and retrieves a given page via
10  * GET, strips out the header information, and returns the result.
11  */
12 
13 #ifndef __UT_WebConnection_h__
14 #define __UT_WebConnection_h__
15 
16 #include "UT_API.h"
17 #include "UT_Pair.h"
18 #include "UT_String.h"
19 #include "UT_Array.h"
20 class UT_WorkBuffer;
21 
23 {
24 public:
25  // The host name is not set by default.
28 
29  void setHostName(const char *host_name);
30 
31  // The default port is 80.
32  void setPort(int port) { myPort = port; }
33 
34  // Set or clear a proxy to use.
35  void setProxy(const char *host_name, int port);
36  void doNotUseProxy();
37 
38  // Set the name of the page to be retrieved.
39  void setPageName(const char *page_name);
40 
41  // Set the session id for the http request. By default, no session
42  // id is sent to the web server.
43  void setSessionId(const char *session_id);
44 
45  // Add a variable and its corresponding value that will be appended
46  // to the URI.
47  void addVariable(const char *variable_name,
48  const char *variable_value);
49  void addVariable(const char *variable_name,
50  int variable_value);
51  void clearVariables();
52 
53  // Connect to the web server and retrieve the page. False is returned
54  // if an error occurred and result contains the error message. Otherwise,
55  // result contains the web page, minus the http headers. If the
56  // web server sent a session id then it is returned in session_id.
57  // Otherwise, session_id is blank.
58  bool retrievePage(UT_WorkBuffer &result,
59  UT_WorkBuffer &session_id);
60  void setModTime(const char *src);
61  int getModTime() const;
62 
63  // This method encodes data into a format that can be used in a URI
64  // (replacing characters with %xx format).
65  static void encodeURIData(const char *data_to_encode,
66  UT_WorkBuffer &encoded_value);
67 
68  static void parseURL(const char *source,
69  UT_String &host,
70  int &port,
71  UT_String &page);
72 
73 private:
74 
75  typedef UT_Pair<UT_String, UT_String> UT_Variable;
76 
77  void setProxyFromEnvironmentVariable();
78  bool sendHttpRequest(
79  const char *host,
80  int port,
81  const char *page_name,
82  const UT_Array<UT_Variable> &variables,
83  UT_WorkBuffer &result,
84  UT_WorkBuffer &session_id,
85  UT_WorkBuffer &redirect);
86 
87  UT_String myHostName;
88  UT_String myProxyHostName;
89  int myPort;
90  int myProxyPort;
91  UT_String myPageName;
92  UT_String mySessionId;
93  UT_Array<UT_Variable> myVariables;
94  int myModTime;
95 };
96 
97 #endif
#define UT_API
Definition: UT_API.h:13
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:802
void setPort(int port)
GLenum src
Definition: glcorearb.h:1792