sipxtacklib  Version 3.3
HttpRequestContext.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2004-2006 SIPfoundry Inc.
3 // Licensed by SIPfoundry under the LGPL license.
4 //
5 // Copyright (C) 2004-2006 Pingtel Corp. All rights reserved.
6 // Licensed to SIPfoundry under a Contributor Agreement.
7 //
8 // $$
10 
11 
12 #ifndef _HttpRequestContext_h_
13 #define _HttpRequestContext_h_
14 
15 // SYSTEM INCLUDES
16 //#include <...>
17 
18 // APPLICATION INCLUDES
19 #include "utl/UtlString.h"
20 #include "utl/UtlSList.h"
21 #include "net/HttpMessage.h"
22 
23 // DEFINES
24 
25 
26 // MACROS
27 // EXTERNAL FUNCTIONS
28 // EXTERNAL VARIABLES
29 // CONSTANTS
30 // STRUCTS
31 // TYPEDEFS
32 // FORWARD DECLARATIONS
33 class HttpBody;
34 
35 //:Class short description which may consist of multiple lines (note the ':')
36 // Class detailed description which may extend to multiple lines
38 {
39 /* //////////////////////////// PUBLIC //////////////////////////////////// */
40 public:
42  {
43  // Environment variables:
44  HTTP_ENV_RAW_URL = 0, // The url provided in the request
45  HTTP_ENV_UNMAPPED_FILE, // The file part of the raw URL
46  HTTP_ENV_MAPPED_FILE, // The file part of the url mapped to the real location
47  HTTP_ENV_QUERY_STRING, // The query part of the URL (if GET) Note: the individual variables are retreiveable via getCgiVariables
48  HTTP_ENV_SERVER_NAME, // The Server name part of the URL
49  HTTP_ENV_REQUEST_METHOD,// The request method (i.e. GET, PUT, POST)
50  HTTP_ENV_USER, // The user name (if this request required authorization)
51 
52 
53  HTTP_ENV_LAST // Note: this is a dummy variable indicating the last var
54  };
55 
56 /* ============================ CREATORS ================================== */
57 
59  HttpRequestContext( const char* requestMethod = NULL
60  ,const char* rawUrl = NULL
61  ,const char* mappedFile = NULL
62  ,const char* serverName = NULL
63  ,const char* userId = NULL
64  ,const OsConnectionSocket* connection = NULL
65  );
66  //:Default constructor
67 
68 
69  virtual
71  //:Destructor
72 
73 /* ============================ MANIPULATORS ============================== */
74 
75  void extractPostCgiVariables(const HttpBody& body);
76  // Extracts the CGI variables from the request body.
77 
78  typedef void (*UnEscapeFunction)(UtlString&);
79  static void parseCgiVariables(const char* queryString,
80  UtlList& cgiVariableList,
81  const char* pairSeparator = "&",
82  const char* namValueSeparator = "=",
83  UtlBoolean nameIsCaseInsensitive = TRUE,
84  UnEscapeFunction unescape =
86  // If nameIsCaseInsensitive == TRUE, puts NameValuePairInsensitive's
87  // into cgiVariableList rather than NameValuePair's.
88 
89  HttpRequestContext(const HttpRequestContext& rHttpRequestContext);
90  //:Copy constructor
92  //:Assignment operator
93 
94 /* ============================ ACCESSORS ================================= */
95 
96  void getEnvironmentVariable(enum RequestEnvironmentVariables envVariable, UtlString& value) const;
97  //: Get Environment and context variables related to this request
98  // See the RequestEnvironmentVariables enumeration for the complete list.
99 
100  UtlBoolean getCgiVariable(const char* name, UtlString& value, int occurance = 0) const;
101  //: Get CGI/Form variables provided in this POST or GET request.
102  // As it is possible to have multiple occurances of a named value
103  // the occurance argument indicates which occurance. The default is the first.
105 
106  UtlBoolean getCgiVariable(int index, UtlString& name, UtlString& value) const;
107  //: Get the name and value of the variable at the given index
108 
110  bool isEncrypted() const;
111 
113  bool isTrustedPeer( const UtlString& peername ) const;
122 /* ============================ INQUIRY =================================== */
123 
124 /* //////////////////////////// PROTECTED ///////////////////////////////// */
125 protected:
126 
127 /* //////////////////////////// PRIVATE /////////////////////////////////// */
128 private:
129 
130  void parseCgiVariables(const char* queryString);
131  //: Parse the CGI/form variables from the &,= delineated name, value pairs and unescape the name and values.
132 
133  UtlSList mCgiVariableList;
134  bool mUsingInsensitive;
135  UtlString mEnvironmentVars[HTTP_ENV_LAST];
136  bool mConnectionEncrypted;
137  bool mPeerCertTrusted;
138  UtlSList mPeerIdentities;
139 
140 };
141 
142 /* ============================ INLINE METHODS ============================ */
143 
144 #endif // _HttpRequestContext_h_
Definition: HttpRequestContext.h:44
static void parseCgiVariables(const char *queryString, UtlList &cgiVariableList, const char *pairSeparator="&", const char *namValueSeparator="=", UtlBoolean nameIsCaseInsensitive=TRUE, UnEscapeFunction unescape=&HttpMessage::unescape)
Definition: HttpRequestContext.cpp:360
void(* UnEscapeFunction)(UtlString &)
Definition: HttpRequestContext.h:78
void getEnvironmentVariable(enum RequestEnvironmentVariables envVariable, UtlString &value) const
Definition: HttpRequestContext.cpp:248
virtual ~HttpRequestContext()
Definition: HttpRequestContext.cpp:159
HttpRequestContext & operator=(const HttpRequestContext &rhs)
Definition: HttpRequestContext.cpp:169
bool isEncrypted() const
Test whether or not the client connection is encrypted.
Definition: HttpRequestContext.cpp:482
RequestEnvironmentVariables
Definition: HttpRequestContext.h:41
Definition: HttpRequestContext.h:47
Definition: HttpRequestContext.h:49
Definition: HttpRequestContext.h:45
HttpRequestContext(const char *requestMethod=NULL, const char *rawUrl=NULL, const char *mappedFile=NULL, const char *serverName=NULL, const char *userId=NULL, const OsConnectionSocket *connection=NULL)
Construct the context for an HTTP request.
Definition: HttpRequestContext.cpp:42
static void unescape(UtlString &escapedText)
URL unescape the text to human readable form.
Definition: HttpMessage.cpp:1542
Definition: HttpRequestContext.h:46
void extractPostCgiVariables(const HttpBody &body)
Definition: HttpRequestContext.cpp:236
bool isTrustedPeer(const UtlString &peername) const
Test whether or not the given name is the SSL client that sent this request.
Definition: HttpRequestContext.cpp:489
UtlBoolean getCgiVariable(const char *name, UtlString &value, int occurance=0) const
Definition: HttpRequestContext.cpp:261
Definition: HttpRequestContext.h:37
Definition: HttpRequestContext.h:53
class to contain an HTTP body
Definition: HttpBody.h:55
Definition: HttpRequestContext.h:48
Definition: HttpRequestContext.h:50

sipXtackLib home page