| 1 | /*************************************************************************** |
|---|
| 2 | * cgiFastExchange.cc |
|---|
| 3 | * |
|---|
| 4 | * Sat Aug 5 2006 |
|---|
| 5 | * Copyright 2006 Dmytro Milinevskyy |
|---|
| 6 | * milinevskyy@gmail.com |
|---|
| 7 | ****************************************************************************/ |
|---|
| 8 | |
|---|
| 9 | /* |
|---|
| 10 | * This program is free software; you can redistribute it and/or modify |
|---|
| 11 | * it under the terms of the GNU Lesser General Public License version 2.1 as published by |
|---|
| 12 | * the Free Software Foundation; |
|---|
| 13 | * |
|---|
| 14 | * This program 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 |
|---|
| 17 | * GNU Library General Public License for more details. |
|---|
| 18 | * |
|---|
| 19 | * You should have received a copy of the GNU Lesser General Public License |
|---|
| 20 | * along with this program; if not, write to the Free Software |
|---|
| 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|---|
| 22 | */ |
|---|
| 23 | |
|---|
| 24 | /** |
|---|
| 25 | * vim indentation settings |
|---|
| 26 | * set tabstop=4 |
|---|
| 27 | * set shiftwidth=4 |
|---|
| 28 | */ |
|---|
| 29 | |
|---|
| 30 | #include <libdodo/directives.h> |
|---|
| 31 | |
|---|
| 32 | #ifdef FASTCGI_EXT |
|---|
| 33 | #include <fcgiapp.h> |
|---|
| 34 | #include <string.h> |
|---|
| 35 | |
|---|
| 36 | #include "cgiFastRequest.inline" |
|---|
| 37 | |
|---|
| 38 | #include <libdodo/cgiFastExchange.h> |
|---|
| 39 | #include <libdodo/cgiFastExchangeEx.h> |
|---|
| 40 | #include <libdodo/types.h> |
|---|
| 41 | #include <libdodo/cgiExchange.h> |
|---|
| 42 | #include <libdodo/ioChannel.h> |
|---|
| 43 | |
|---|
| 44 | using namespace dodo::cgi::fast; |
|---|
| 45 | |
|---|
| 46 | exchange::exchange(exchange &cf) : io::stream::channel(cf.protection), |
|---|
| 47 | dodo::cgi::exchange(cf.protection) |
|---|
| 48 | { |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | //------------------------------------------------------------------- |
|---|
| 52 | |
|---|
| 53 | exchange::exchange(const __request__ &req, |
|---|
| 54 | short protection) : io::stream::channel(protection), |
|---|
| 55 | dodo::cgi::exchange(protection), |
|---|
| 56 | request(new __request__) |
|---|
| 57 | { |
|---|
| 58 | #ifndef IO_WO_XEXEC |
|---|
| 59 | collectedData.setExecObject(xexec::OBJECT_CGIFASTEXCHANGE); |
|---|
| 60 | #endif |
|---|
| 61 | |
|---|
| 62 | request->request = req.request; |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | //------------------------------------------------------------------- |
|---|
| 66 | |
|---|
| 67 | exchange::~exchange() |
|---|
| 68 | { |
|---|
| 69 | delete request; |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | //------------------------------------------------------------------- |
|---|
| 73 | |
|---|
| 74 | void |
|---|
| 75 | exchange::flush() const |
|---|
| 76 | { |
|---|
| 77 | if (FCGX_FFlush(request->request->out) == -1) |
|---|
| 78 | dodo_throw exception::basic(exception::MODULE_CGIFASTEXCHANGE, FASTEXCHANGEEX_FLUSH, exception::ERRNO_LIBDODO, FASTEXCHANGEEX_FAILEDTOFLUSH, CGIFASTEXCHANGEEX_FAILEDTOFLUSH_STR, __LINE__, __FILE__); |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | //------------------------------------------------------------------- |
|---|
| 82 | |
|---|
| 83 | char * |
|---|
| 84 | exchange::getenv(const char *buf) |
|---|
| 85 | { |
|---|
| 86 | return FCGX_GetParam(buf, request->request->envp); |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | //------------------------------------------------------------------- |
|---|
| 90 | |
|---|
| 91 | int |
|---|
| 92 | exchange::inDescriptor() const |
|---|
| 93 | { |
|---|
| 94 | dodo_throw exception::basic(exception::MODULE_CGIFASTEXCHANGE, FASTEXCHANGEEX_INDESCRIPTOR, exception::ERRNO_LIBDODO, FASTEXCHANGEEX_CANTBEUSEDWITHIOEVENT, CGIFASTEXCHANGEEX_CANTBEUSEDWITHIOEVENT_STR, __LINE__, __FILE__); |
|---|
| 95 | } |
|---|
| 96 | |
|---|
| 97 | //------------------------------------------------------------------- |
|---|
| 98 | |
|---|
| 99 | int |
|---|
| 100 | exchange::outDescriptor() const |
|---|
| 101 | { |
|---|
| 102 | dodo_throw exception::basic(exception::MODULE_CGIFASTEXCHANGE, FASTEXCHANGEEX_OUTDESCRIPTOR, exception::ERRNO_LIBDODO, FASTEXCHANGEEX_CANTBEUSEDWITHIOEVENT, CGIFASTEXCHANGEEX_CANTBEUSEDWITHIOEVENT_STR, __LINE__, __FILE__); |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | //------------------------------------------------------------------- |
|---|
| 106 | |
|---|
| 107 | unsigned long |
|---|
| 108 | exchange::_read(char * const data) const |
|---|
| 109 | { |
|---|
| 110 | return FCGX_GetStr(data, bs, request->request->in); |
|---|
| 111 | } |
|---|
| 112 | |
|---|
| 113 | //------------------------------------------------------------------- |
|---|
| 114 | |
|---|
| 115 | unsigned long |
|---|
| 116 | exchange::_write(const char *const data) const |
|---|
| 117 | { |
|---|
| 118 | long n; |
|---|
| 119 | |
|---|
| 120 | if ((n = FCGX_PutStr(data, bs, request->request->out)) == -1) |
|---|
| 121 | dodo_throw exception::basic(exception::MODULE_CGIFASTEXCHANGE, FASTEXCHANGEEX__WRITE, exception::ERRNO_LIBDODO, FASTEXCHANGEEX_FAILEDTOPRINTSTRING, CGIFASTEXCHANGEEX_FAILEDTOPRINTSTRING_STR, __LINE__, __FILE__); |
|---|
| 122 | |
|---|
| 123 | return n; |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| 126 | //------------------------------------------------------------------- |
|---|
| 127 | |
|---|
| 128 | unsigned long |
|---|
| 129 | exchange::_writeString(const char * const data) const |
|---|
| 130 | { |
|---|
| 131 | long n; |
|---|
| 132 | |
|---|
| 133 | if ((n = FCGX_PutStr(data, strnlen(data, bs), request->request->out)) == -1) |
|---|
| 134 | dodo_throw exception::basic(exception::MODULE_CGIFASTEXCHANGE, FASTEXCHANGEEX__WRITESTRING, exception::ERRNO_LIBDODO, FASTEXCHANGEEX_FAILEDTOPRINTSTRING, CGIFASTEXCHANGEEX_FAILEDTOPRINTSTRING_STR, __LINE__, __FILE__); |
|---|
| 135 | |
|---|
| 136 | return n; |
|---|
| 137 | } |
|---|
| 138 | |
|---|
| 139 | //------------------------------------------------------------------- |
|---|
| 140 | |
|---|
| 141 | unsigned long |
|---|
| 142 | exchange::_readString(char * const data) const |
|---|
| 143 | { |
|---|
| 144 | return FCGX_GetStr(data, bs+1, request->request->in); |
|---|
| 145 | } |
|---|
| 146 | #endif |
|---|
| 147 | |
|---|
| 148 | //------------------------------------------------------------------- |
|---|