![]() |
![]() |
#include <Iguana/WebFramework/interface/IgServerSocket.h>
Public Member Functions | |
void | clientInitialization (QIODevice *socket) |
const std::string & | getClientCookieID () const |
IgFileManager * | getFileManager () const |
IgServerSocket (IgState *state, bool mainPort=true) | |
virtual void | newConnection (int port) |
void | ping (QIODevice *socket) |
void | setClientCookieID (const std::string &cookieID) |
void | startTimer () |
Static Public Member Functions | |
static const std::string & | cmdLineHostname () |
static const std::string & | cmdLineHostname (IgState *state) |
static const std::string & | cmdLineMainHostUrl () |
static int | cmdLinePort () |
static int | cmdLinePort (IgState *state, bool mainPort=true) |
static const std::string & | cmdLineProxy () |
static const std::string & | cmdLineProxy (IgState *state) |
static const std::string & | generateCookie (std::string &cookie) |
static int | getFreePort () |
static std::string | hostnameUrl () |
static std::string | redirect (const std::string &url, const std::string &redir, const std::string &cookie) |
Private Slots | |
void | socketClosed () |
void | timedOut () |
Private Member Functions | |
IG_DECLARE_STATE_ELEMENT (IgServerSocket) | |
void | initialize (IgState *state) |
Private Attributes | |
std::string | m_clientCookieID |
IgState * | m_state |
int | m_timeout |
QTimer * | m_timer |
Static Private Attributes | |
static std::string | m_hostname = "" |
static std::string | m_mainHostUrl = "" |
static int | m_port = 0 |
static std::string | m_proxy = "" |
Definition at line 23 of file IgServerSocket.h.
Definition at line 51 of file IgServerSocket.cc.
References initialize().
00052 : QServerSocket (cmdLinePort (state, mainPort)) 00053 { 00054 initialize (state); 00055 if (mainPort) 00056 new IgSessionManager (state); 00057 }
void IgServerSocket::clientInitialization | ( | QIODevice * | socket | ) |
Definition at line 258 of file IgServerSocket.cc.
References getFileManager(), IgFileManager::lookup(), and m_proxy.
Referenced by IgSocket::dump().
00259 { 00260 IgFileManager* fileManager = getFileManager (); 00261 QByteArray writeBuffer = 00262 fileManager->lookup("htdocs/Ig_Modules/IgSocketDriver/html/iguanaInit.html"); 00263 QTextStream client (socket); 00264 client << "HTTP/1.0 200 Ok\r\n" 00265 "Content-Type: text/html;\r\n" 00266 "\r\n" 00267 "<html><body><SCRIPT language=\"JavaScript\">var proxy =\"" + 00268 m_proxy + "\";</SCRIPT>\r\n"; 00269 00270 socket->writeBlock (writeBuffer.data (), 00271 writeBuffer.size ()); 00272 00273 client << "</body></html>\r\n"; 00274 socket->close (); 00275 socket->flush (); 00276 }
const std::string & IgServerSocket::cmdLineHostname | ( | ) | [static] |
Definition at line 135 of file IgServerSocket.cc.
References m_hostname.
Referenced by IgServerPool::IgServerPool(), and initialize().
00136 { return m_hostname; }
const std::string & IgServerSocket::cmdLineHostname | ( | IgState * | state | ) | [static] |
Definition at line 147 of file IgServerSocket.cc.
References cmdLineProxy(), IgArgsElement::find(), DBSPlugin::get(), m_hostname, and m_proxy.
00148 { 00149 cmdLineProxy (state); 00150 IgArgsElement *args = IgArgsElement::get (state); 00151 args->find ("--ig-hostname", m_hostname, false); 00152 if (m_proxy.empty() && !m_hostname.empty()) 00153 m_hostname = "https://" + m_hostname; 00154 return m_hostname; 00155 }
const std::string & IgServerSocket::cmdLineMainHostUrl | ( | ) | [static] |
Definition at line 131 of file IgServerSocket.cc.
References m_mainHostUrl.
Referenced by IgSocket::dump().
00132 { return m_mainHostUrl; }
int IgServerSocket::cmdLinePort | ( | ) | [static] |
Definition at line 139 of file IgServerSocket.cc.
References m_port.
Referenced by hostnameUrl(), IgServerPool::IgServerPool(), and initialize().
00140 { return m_port; }
Definition at line 168 of file IgServerSocket.cc.
References IgArgsElement::find(), DBSPlugin::get(), and m_port.
00169 { 00170 if (mainPort) 00171 { 00172 IgArgsElement *args = IgArgsElement::get (state); 00173 args->find ("--ig-port", m_port, false); 00174 return m_port; 00175 } 00176 return 0; 00177 }
const std::string & IgServerSocket::cmdLineProxy | ( | ) | [static] |
Definition at line 127 of file IgServerSocket.cc.
References m_proxy.
Referenced by cmdLineHostname(), IgServerPool::IgServerPool(), initialize(), IgStudioWebService::initSession(), IgStudioWebService::launch(), IgStudioWebService::login(), and IgStudioWebService::logout().
00128 { return m_proxy; }
const std::string & IgServerSocket::cmdLineProxy | ( | IgState * | state | ) | [static] |
Definition at line 158 of file IgServerSocket.cc.
References IgArgsElement::find(), DBSPlugin::get(), and m_proxy.
Referenced by IgSocket::dump().
00159 { 00160 IgArgsElement *args = IgArgsElement::get (state); 00161 args->find ("--ig-proxy", m_proxy, false); 00162 if(!m_proxy.empty() && m_proxy[0] != '/') 00163 m_proxy = "/"+ m_proxy; 00164 return m_proxy; 00165 }
const std::string & IgServerSocket::generateCookie | ( | std::string & | cookie | ) | [static] |
Definition at line 180 of file IgServerSocket.cc.
Referenced by IgSocket::dump(), and IgServerPool::redirect().
00181 { 00182 using namespace lat; 00183 char *uuidBuffer = new char[37]; 00184 UUID uuid = UUID::generateTime (); 00185 uuid.format (uuidBuffer); 00186 cookie = uuidBuffer; 00187 delete[] uuidBuffer; 00188 return cookie; 00189 }
const std::string & IgServerSocket::getClientCookieID | ( | ) | const |
Definition at line 123 of file IgServerSocket.cc.
References m_clientCookieID.
Referenced by IgSocket::dump().
00124 { return m_clientCookieID; }
IgFileManager * IgServerSocket::getFileManager | ( | ) | const |
Definition at line 279 of file IgServerSocket.cc.
References DBSPlugin::get(), and m_state.
Referenced by clientInitialization(), and ping().
00280 { 00281 IgFileManager* fileManager = IgFileManager::get (m_state); 00282 if (fileManager) return fileManager; 00283 return new IgFileManager (m_state); 00284 }
int IgServerSocket::getFreePort | ( | ) | [static] |
Definition at line 237 of file IgServerSocket.cc.
References python_dbs::port, and filesave_online::server.
Referenced by IgServerPool::createProcess().
00238 { 00239 IgFreeServerSocket* server = new IgFreeServerSocket (); 00240 while (server->ok () == false) 00241 usleep (1000); 00242 int port = server->port (); 00243 delete server; 00244 return port; 00245 }
std::string IgServerSocket::hostnameUrl | ( | ) | [static] |
Definition at line 143 of file IgServerSocket.cc.
References cmdLinePort(), and m_hostname.
Referenced by IgSocket::dump().
00144 { return m_hostname+":"+QString::number(cmdLinePort ()); }
IgServerSocket::IG_DECLARE_STATE_ELEMENT | ( | IgServerSocket | ) | [private] |
Definition at line 60 of file IgServerSocket.cc.
References ASSERT, TestMuL1L2Filter_cff::cerr, cmdLineHostname(), cmdLinePort(), cmdLineProxy(), HLT_VtxMuL3::connect, lat::endl(), IgArgsElement::find(), DBSPlugin::get(), m_clientCookieID, m_hostname, m_mainHostUrl, m_state, m_timeout, m_timer, python_dbs::port, IgState::put(), timedOut(), and lhef::timeout().
Referenced by IgServerSocket().
00061 { 00062 m_state = state; 00063 m_state->put (s_key, this); 00064 m_timeout = -1; 00065 m_timer = 0; 00066 m_clientCookieID = ""; 00067 00068 cmdLineProxy (state); 00069 cmdLinePort (state); 00070 cmdLineHostname (state); 00071 ASSERT (!m_hostname.empty()); 00072 00073 if (!IgServerPool::get (m_state)) 00074 { 00075 IgArgsElement *args = IgArgsElement::get (m_state); 00076 args->find ("--ig-main-hosturl", m_mainHostUrl); 00077 args->find ("--ig-timeout", m_timeout); 00078 00079 if (m_timeout > 0) 00080 { 00081 m_timer = new QTimer (this); 00082 connect (m_timer, SIGNAL (timeout()), this, SLOT (timedOut())); 00083 } 00084 } 00085 std::cerr << "Bound to port:" <<this->port () << std::endl; 00086 }
Definition at line 89 of file IgServerSocket.cc.
References HLT_VtxMuL3::connect, dump(), m_state, and socket.
00090 { 00091 if (!m_state) return; 00092 IgSocket *socket = new IgSocket (m_state); 00093 connect (socket, SIGNAL(readyRead()), socket, SLOT(dump())); 00094 //connect (socket, SIGNAL(delayedCloseFinished()), 00095 // this, SLOT(socketClosed())); 00096 socket->setSocket (port); 00097 }
void IgServerSocket::ping | ( | QIODevice * | socket | ) |
Definition at line 248 of file IgServerSocket.cc.
References getFileManager(), IgFileManager::lookup(), and IgWebService::sendBinary().
Referenced by IgSocket::dump().
00249 { 00250 IgFileManager* fileManager = getFileManager (); 00251 QByteArray writeBuffer = fileManager->lookup("images/ping.png"); 00252 IgWebService::sendBinary(socket,writeBuffer,"png"); 00253 socket->close (); 00254 socket->flush (); 00255 }
std::string IgServerSocket::redirect | ( | const std::string & | url, | |
const std::string & | redir, | |||
const std::string & | cookie | |||
) | [static] |
Definition at line 192 of file IgServerSocket.cc.
References TestMuL1L2Filter_cff::cerr, lat::endl(), m_proxy, and HLT_VtxMuL3::result.
Referenced by IgSocket::dump(), IgStudioWebService::initSession(), IgStudioWebService::launch(), IgStudioWebService::login(), and IgServerPool::redirect().
00194 { 00195 std::string targetCookie = ""; 00196 std::string newRedir = redir; 00197 00198 if (!cookie.empty()) 00199 { 00200 if (m_proxy.empty()) 00201 targetCookie = "Set-Cookie: USER=" + cookie +"; path=/\r\n"; 00202 else 00203 targetCookie = "Set-Cookie: USER=" + cookie +"; path=" + m_proxy + "\r\n"; 00204 } 00205 00206 if (!m_proxy.empty()) 00207 { 00208 if (!redir.empty()) 00209 targetCookie += "Set-Cookie: igtarget=" + redir + "; path=" + m_proxy + "\r\n"; 00210 newRedir = url; 00211 } 00212 else 00213 newRedir += url; 00214 00215 std::string result = "HTTP/1.1 302 Redirect\r\n" 00216 "Location: " + newRedir + "\r\n" 00217 "Content-Type: text/html; charset=\"utf-8\"\r\n" 00218 "Connection: Close\r\n" 00219 + targetCookie + 00220 "\r\n" 00221 "<html>" 00222 "<body>" 00223 "<style type=\"text/css\">" 00224 "a {color:#FFFFFF}" 00225 "</style>" 00226 "<h1><a href=\"" + newRedir + 00227 "\">Click here if not redirected automatically</a></h1>" 00228 "</body>" 00229 "</html>\r\n\r\n"; 00230 00231 std::cerr << result << std::endl; 00232 00233 return result; 00234 }
void IgServerSocket::setClientCookieID | ( | const std::string & | cookieID | ) |
Definition at line 119 of file IgServerSocket.cc.
References m_clientCookieID.
Referenced by IgSocket::dump().
00120 { m_clientCookieID = cookieID; }
void IgServerSocket::socketClosed | ( | ) | [private, slot] |
void IgServerSocket::startTimer | ( | ) |
Definition at line 100 of file IgServerSocket.cc.
References m_timeout, and m_timer.
Referenced by IgSocket::dump().
void IgServerSocket::timedOut | ( | ) | [private, slot] |
Definition at line 107 of file IgServerSocket.cc.
References cmsRelvalreport::exit.
Referenced by initialize().
00108 { exit (0); }
std::string IgServerSocket::m_clientCookieID [private] |
Definition at line 72 of file IgServerSocket.h.
Referenced by getClientCookieID(), initialize(), and setClientCookieID().
std::string IgServerSocket::m_hostname = "" [static, private] |
Definition at line 64 of file IgServerSocket.h.
Referenced by cmdLineHostname(), hostnameUrl(), and initialize().
std::string IgServerSocket::m_mainHostUrl = "" [static, private] |
Definition at line 65 of file IgServerSocket.h.
Referenced by cmdLineMainHostUrl(), and initialize().
int IgServerSocket::m_port = 0 [static, private] |
std::string IgServerSocket::m_proxy = "" [static, private] |
Definition at line 66 of file IgServerSocket.h.
Referenced by clientInitialization(), cmdLineHostname(), cmdLineProxy(), and redirect().
IgState* IgServerSocket::m_state [private] |
Definition at line 69 of file IgServerSocket.h.
Referenced by getFileManager(), initialize(), and newConnection().
int IgServerSocket::m_timeout [private] |
QTimer* IgServerSocket::m_timer [private] |