CgiEnvironment.h
Go to the documentation of this file.
1 /* -*-mode:c++; c-file-style: "gnu";-*- */
2 /*
3  * $Id: CgiEnvironment.h,v 1.20 2013/01/12 19:57:04 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 "cgicc/CgiDefs.h"
45 #include "cgicc/CgiUtils.h"
46 #include "cgicc/CgiInput.h"
47 #include "cgicc/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 
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_ */

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 Apr 12 2013 17:00:24 for cgicc by doxygen 1.8.3.1