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
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 
162  operator= (const CgiEnvironment& env);
164 
165  // ============================================================
166 
171 
178  inline std::string
180  { return fServerSoftware; }
181 
188  inline std::string
190  { return fServerName; }
191 
198  inline std::string
200  { return fGatewayInterface;}
201 
208  inline std::string
210  { return fServerProtocol; }
211 
218  inline unsigned long
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>&
264  { return fCookies; }
265 
272  inline std::string
274  { return fRequestMethod; }
275 
284  inline std::string
285  getPathInfo() const
286  { return fPathInfo; }
287 
294  inline std::string
296  { return fPathTranslated; }
297 
304  inline std::string
306  { return fScriptName; }
307 
317  inline std::string
319  { return fQueryString; }
320 
327  inline unsigned long
329  { return fContentLength; }
330 
342  inline std::string
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
390  { return fRemoteHost; }
391 
398  inline std::string
400  { return fRemoteAddr; }
401 
409  inline std::string
410  getAuthType() const
411  { return fAuthType; }
412 
420  inline std::string
422  { return fRemoteUser; }
423 
434  inline std::string
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
477  { return fRedirectRequest; }
478 
487  inline std::string
489  { return fRedirectURL; }
490 
498  inline std::string
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_ */
unsigned long getContentLength() const
Get the length of the data read from standard input, in chars.
bool usingHTTPS() const
Determine if this is a secure request.
std::string getRemoteHost() const
Get the hostname of the remote machine making this request.
std::string getPathInfo() const
Get the extra path information for this request, given by the client.
Class that abstracts a data source.
Definition: CgiInput.h:58
std::string getRedirectRequest() const
Get the redirect request.
std::string getPostData() const
Get the data passed to the CGI application via standard input.
std::string getServerSoftware() const
Get the name and version of the HTTP server software.
std::string getContentType() const
Get the content type of the submitted information.
Platform and operating system specific macro definitions.
std::string getAccept() const
Get the MIME data types accepted by the client&#39;s browser.
std::string getCookies() const
Get the HTTP cookies associated with this query, if any.
std::string getServerName() const
Get the hostname, DNS name or IP address of the HTTP server.
unsigned long getServerPort() const
Get the port number on the server to which this request was sent.
std::string getRemoteUser() const
Get the authenticated remote user name.
std::string getAuthType() const
Get the protocol-specific user authentication method used.
std::string getRedirectStatus() const
Get the redirect status.
An HTTP Cookie.
const std::vector< HTTPCookie > & getCookieList() const
Get a vector containing the HTTP cookies associated with this query.
Class that abstracts a data source.
std::string getReferrer() const
Get the URL of the page which called this CGI application.
std::string getRedirectURL() const
Get the redirect URL.
std::string getScriptName() const
Get the full path to this CGI application.
A collection of utility functions.
The main class of the GNU cgicc library.
Definition: Cgicc.h:103
std::string getRemoteIdent() const
Get the remote user name retrieved from the server.
std::string getServerProtocol() const
Get the name and revision of the protocol used for this request.
std::vector< HTTPCookie >::iterator cookie_iterator
A vector of HTTPCookie objects.
std::string getGatewayInterface() const
Get the name and version of the gateway interface.
std::string getQueryString() const
Get the query string for this request.
std::string getRequestMethod() const
Get the request method used for this query.
std::string getRemoteAddr() const
Get the IP address of the remote machine making this request.
The namespace containing the cgicc library.
Definition: Cgicc.h:52
std::vector< HTTPCookie >::const_iterator const_cookie_iterator
A vector of const HTTPCookie objects.
std::string getPathTranslated() const
Get the translated path information (virtual to physical mapping).
CgiEnvironment(const CgiEnvironment &env)
Copy constructor.
std::string getUserAgent() const
Get the name of the browser used for this CGI request.
Class encapsulating the CGI runtime environment.

GNU cgicc - A C++ class library for writing CGI applications
Copyright © 1996 - 2004 Stephen F. Booth
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front Cover Texts, and with no Back-Cover Texts.
Documentation generated Fri Jan 28 2022 06:24:15 for cgicc by doxygen 1.8.13