File: FCgiIO.cpp

package info (click to toggle)
libcgicc 3.2.19-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,020 kB
  • sloc: cpp: 5,023; sh: 4,438; makefile: 169; sed: 1
file content (63 lines) | stat: -rw-r--r-- 1,870 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
 *  $Id: FCgiIO.cpp,v 1.6 2007/07/02 18:48:19 sebdiaz Exp $
 *
 *  Copyright (C) 2002 Steve McAndrewSmith
 *  Copyright (C) 2002 - 2004 Stephen F. Booth
 *                       2007 Sebastien DIAZ <sebastien.diaz@gmail.com>
 *  Part of the GNU cgicc library, http://www.gnu.org/software/cgicc
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 3 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA 
 */

#ifdef __GNUG__
#  pragma implementation
#endif

#include <iostream>
#include <stdexcept>
#include <cstdlib>

#include "FCgiIO.h"

cgicc::FCgiIO::FCgiIO(FCGX_Request& request)
  : std::ostream(&fOutBuf),
	 fRequest(request), 
	 fOutBuf(request.out), 
	 fErrBuf(request.err), 
	 fErr(&fErrBuf)
{
  rdbuf(&fOutBuf);
  fErr.rdbuf(&fErrBuf);

  // Parse environment
  for(char **e = fRequest.envp; *e != NULL; ++e) {
    std::string s(*e);
    std::string::size_type i = s.find('=');
    if(i == std::string::npos)
      throw std::runtime_error("Illegally formed environment");
    fEnv[s.substr(0, i)] = s.substr(i + 1);
  }
}

cgicc::FCgiIO::FCgiIO(const FCgiIO& io)
  : CgiInput(io),
    std::ostream(&fOutBuf),
	 fRequest(io.fRequest), 
	 fErr(&fErrBuf), 
	 fEnv(io.fEnv)
{
  rdbuf(&fOutBuf);
  fErr.rdbuf(&fErrBuf);
}