CgiEnvironment.h
Go to the documentation of this file.
1/* -*-mode:c++; c-file-style: "gnu";-*- */
2/*
3 * $Id: CgiEnvironment.h,v 1.21 2014/04/23 20:55:03 sebdiaz Exp $
4 *
5 * Copyright (C) 1996 - 2004 Stephen F. Booth <sbooth@gnu.org>
6 * 2007 Sebastien DIAZ <sebastien.diaz@gmail.com>
7 * Part of the GNU cgicc library, http://www.gnu.org/software/cgicc
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 3 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
22 */
23
24#ifndef _CGIENVIRONMENT_H_
25#define _CGIENVIRONMENT_H_ 1
26
27#ifdef __GNUG__
28# pragma interface
29#endif
30
40#include <string>
41#include <vector>
42#include <cstdlib>
43
44#include "CgiDefs.h"
45#include "CgiUtils.h"
46#include "CgiInput.h"
47#include "HTTPCookie.h"
48
49 namespace cgicc {
50
51#ifdef WIN32
52 template class CGICC_API std::vector<HTTPCookie>;
53#endif
54
55 // ============================================================
56 // Iterator typedefs
57 // ============================================================
58
60 typedef std::vector<HTTPCookie>::iterator cookie_iterator;
62 typedef std::vector<HTTPCookie>::const_iterator const_cookie_iterator;
63
64 // ============================================================
65 // Class CgiEnvironment
66 // ============================================================
67
76 class CGICC_API CgiEnvironment
77 {
78 public:
79
80 friend class Cgicc;
81
82 // ============================================================
83
86
101 CgiEnvironment(CgiInput *input);
102
109 inline
110 CgiEnvironment(const CgiEnvironment& env)
111 { operator=(env); }
112
118 ~CgiEnvironment();
120
121 // ============================================================
122
125
133 bool
134 operator== (const CgiEnvironment& env) const;
135
143 inline bool
144 operator!= (const CgiEnvironment& env) const
145 { return ! operator==(env); }
146
147#ifdef WIN32
148 /* Dummy operator for MSVC++ */
149 inline bool
150 operator< (const CgiEnvironment& env) const
151 { return false; }
152#endif
153
161 CgiEnvironment&
162 operator= (const CgiEnvironment& env);
164
165 // ============================================================
166
171
178 inline std::string
179 getServerSoftware() const
180 { return fServerSoftware; }
181
188 inline std::string
189 getServerName() const
190 { return fServerName; }
191
198 inline std::string
199 getGatewayInterface() const
200 { return fGatewayInterface;}
201
208 inline std::string
209 getServerProtocol() const
210 { return fServerProtocol; }
211
218 inline unsigned long
219 getServerPort() const
220 { return fServerPort; }
221
228 inline bool
229 usingHTTPS() const
230 { return fUsingHTTPS; }
232
233 // ============================================================
234
239
249 inline std::string
250 getCookies() const
251 { return fCookie; }
252
262 inline const std::vector<HTTPCookie>&
263 getCookieList() const
264 { return fCookies; }
265
272 inline std::string
273 getRequestMethod() const
274 { return fRequestMethod; }
275
284 inline std::string
285 getPathInfo() const
286 { return fPathInfo; }
287
294 inline std::string
295 getPathTranslated() const
296 { return fPathTranslated; }
297
304 inline std::string
305 getScriptName() const
306 { return fScriptName; }
307
317 inline std::string
318 getQueryString() const
319 { return fQueryString; }
320
327 inline unsigned long
328 getContentLength() const
329 { return fContentLength; }
330
342 inline std::string
343 getContentType() const
344 { return fContentType; }
345
352 inline std::string
353 getPostData() const
354 { return fPostData; }
356
357 // ============================================================
358
363
370 inline std::string
371 getReferrer() const
372 { return fReferrer; }
374
375 // ============================================================
376
381
388 inline std::string
389 getRemoteHost() const
390 { return fRemoteHost; }
391
398 inline std::string
399 getRemoteAddr() const
400 { return fRemoteAddr; }
401
409 inline std::string
410 getAuthType() const
411 { return fAuthType; }
412
420 inline std::string
421 getRemoteUser() const
422 { return fRemoteUser; }
423
434 inline std::string
435 getRemoteIdent() const
436 { return fRemoteIdent; }
437
444 inline std::string
445 getAccept() const
446 { return fAccept; }
447
455 inline std::string
456 getUserAgent() const
457 { return fUserAgent; }
459
460 // ============================================================
461
467
475 inline std::string
476 getRedirectRequest() const
477 { return fRedirectRequest; }
478
487 inline std::string
488 getRedirectURL() const
489 { return fRedirectURL; }
490
498 inline std::string
499 getRedirectStatus() const
500 { return fRedirectStatus; }
502
503 protected:
504
505 // ============================================================
506
511
518 void
519 save(const std::string& filename) const;
520
527 // Implementation of restore
528 void
529 restore(const std::string& filename);
531
532 // ============================================================
533
534 private:
535
536 // Parse the list of cookies from a string to a vector
537 void
538 parseCookies();
539
540 // Parse a single cookie string (name=value) pair
541 void
542 parseCookie(const std::string& data);
543
544 // Read in all the environment variables
545 void
546 readEnvironmentVariables(CgiInput *input);
547
548 unsigned long fServerPort;
549 unsigned long fContentLength;
550 bool fUsingHTTPS;
551 std::string fServerSoftware;
552 std::string fServerName;
553 std::string fGatewayInterface;
554 std::string fServerProtocol;
555 std::string fRequestMethod;
556 std::string fPathInfo;
557 std::string fPathTranslated;
558 std::string fScriptName;
559 std::string fQueryString;
560 std::string fRemoteHost;
561 std::string fRemoteAddr;
562 std::string fAuthType;
563 std::string fRemoteUser;
564 std::string fRemoteIdent;
565 std::string fContentType;
566 std::string fAccept;
567 std::string fUserAgent;
568 std::string fPostData;
569 std::string fRedirectRequest;
570 std::string fRedirectURL;
571 std::string fRedirectStatus;
572 std::string fReferrer;
573 std::string fCookie;
574 std::vector<HTTPCookie> fCookies;
575 std::string fAcceptLanguageString;
576 };
577
578} // namespace cgicc
579
580#endif /* ! _CGIENVIRONMENT_H_ */
CgiDefs.h
Platform and operating system specific macro definitions.
CgiInput.h
Class that abstracts a data source.
CgiUtils.h
A collection of utility functions.
HTTPCookie.h
An HTTP Cookie.
cgicc::CgiEnvironment
Class encapsulating the CGI runtime environment.
Definition: CgiEnvironment.h:77
cgicc::CgiEnvironment::getCookies
std::string getCookies() const
Get the HTTP cookies associated with this query, if any.
Definition: CgiEnvironment.h:250
cgicc::CgiEnvironment::getRemoteIdent
std::string getRemoteIdent() const
Get the remote user name retrieved from the server.
Definition: CgiEnvironment.h:435
cgicc::CgiEnvironment::getAccept
std::string getAccept() const
Get the MIME data types accepted by the client's browser.
Definition: CgiEnvironment.h:445
cgicc::CgiEnvironment::getCookieList
const std::vector< HTTPCookie > & getCookieList() const
Get a vector containing the HTTP cookies associated with this query.
Definition: CgiEnvironment.h:263
cgicc::CgiEnvironment::getReferrer
std::string getReferrer() const
Get the URL of the page which called this CGI application.
Definition: CgiEnvironment.h:371
cgicc::CgiEnvironment::getScriptName
std::string getScriptName() const
Get the full path to this CGI application.
Definition: CgiEnvironment.h:305
cgicc::CgiEnvironment::getRemoteAddr
std::string getRemoteAddr() const
Get the IP address of the remote machine making this request.
Definition: CgiEnvironment.h:399
cgicc::CgiEnvironment::getServerProtocol
std::string getServerProtocol() const
Get the name and revision of the protocol used for this request.
Definition: CgiEnvironment.h:209
cgicc::CgiEnvironment::CgiEnvironment
CgiEnvironment(const CgiEnvironment &env)
Copy constructor.
Definition: CgiEnvironment.h:110
cgicc::CgiEnvironment::usingHTTPS
bool usingHTTPS() const
Determine if this is a secure request.
Definition: CgiEnvironment.h:229
cgicc::CgiEnvironment::save
void save(const std::string &filename) const
Implementation of save, for saving CGI environments.
cgicc::CgiEnvironment::getRedirectRequest
std::string getRedirectRequest() const
Get the redirect request.
Definition: CgiEnvironment.h:476
cgicc::CgiEnvironment::getAuthType
std::string getAuthType() const
Get the protocol-specific user authentication method used.
Definition: CgiEnvironment.h:410
cgicc::CgiEnvironment::getQueryString
std::string getQueryString() const
Get the query string for this request.
Definition: CgiEnvironment.h:318
cgicc::CgiEnvironment::getPathTranslated
std::string getPathTranslated() const
Get the translated path information (virtual to physical mapping).
Definition: CgiEnvironment.h:295
cgicc::CgiEnvironment::restore
void restore(const std::string &filename)
Implementation of restore, for restoring CGI environments.
cgicc::CgiEnvironment::getPostData
std::string getPostData() const
Get the data passed to the CGI application via standard input.
Definition: CgiEnvironment.h:353
cgicc::CgiEnvironment::~CgiEnvironment
~CgiEnvironment()
Destructor.
cgicc::CgiEnvironment::getServerName
std::string getServerName() const
Get the hostname, DNS name or IP address of the HTTP server.
Definition: CgiEnvironment.h:189
cgicc::CgiEnvironment::getRemoteHost
std::string getRemoteHost() const
Get the hostname of the remote machine making this request.
Definition: CgiEnvironment.h:389
cgicc::CgiEnvironment::getServerSoftware
std::string getServerSoftware() const
Get the name and version of the HTTP server software.
Definition: CgiEnvironment.h:179
cgicc::CgiEnvironment::getRedirectStatus
std::string getRedirectStatus() const
Get the redirect status.
Definition: CgiEnvironment.h:499
cgicc::CgiEnvironment::getServerPort
unsigned long getServerPort() const
Get the port number on the server to which this request was sent.
Definition: CgiEnvironment.h:219
cgicc::CgiEnvironment::getPathInfo
std::string getPathInfo() const
Get the extra path information for this request, given by the client.
Definition: CgiEnvironment.h:285
cgicc::CgiEnvironment::getRemoteUser
std::string getRemoteUser() const
Get the authenticated remote user name.
Definition: CgiEnvironment.h:421
cgicc::CgiEnvironment::getContentType
std::string getContentType() const
Get the content type of the submitted information.
Definition: CgiEnvironment.h:343
cgicc::CgiEnvironment::getUserAgent
std::string getUserAgent() const
Get the name of the browser used for this CGI request.
Definition: CgiEnvironment.h:456
cgicc::CgiEnvironment::getRequestMethod
std::string getRequestMethod() const
Get the request method used for this query.
Definition: CgiEnvironment.h:273
cgicc::CgiEnvironment::getContentLength
unsigned long getContentLength() const
Get the length of the data read from standard input, in chars.
Definition: CgiEnvironment.h:328
cgicc::CgiEnvironment::getRedirectURL
std::string getRedirectURL() const
Get the redirect URL.
Definition: CgiEnvironment.h:488
cgicc::CgiEnvironment::CgiEnvironment
CgiEnvironment(CgiInput *input)
Read in the CGI environment passed to the CGI application by the server.
cgicc::CgiEnvironment::getGatewayInterface
std::string getGatewayInterface() const
Get the name and version of the gateway interface.
Definition: CgiEnvironment.h:199
cgicc::CgiInput
Class that abstracts a data source.
Definition: CgiInput.h:59
cgicc::Cgicc
The main class of the GNU cgicc library.
Definition: Cgicc.h:103
cgicc
The namespace containing the cgicc library.
Definition: Cgicc.h:52
cgicc::const_cookie_iterator
std::vector< HTTPCookie >::const_iterator const_cookie_iterator
A vector of const HTTPCookie objects.
Definition: CgiEnvironment.h:62
cgicc::cookie_iterator
std::vector< HTTPCookie >::iterator cookie_iterator
A vector of HTTPCookie objects.
Definition: CgiEnvironment.h:60