mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-08-31 07:12:39 -06:00
web: ScgiServer moved to Web
git-svn-id: svn://ultimatepp.org/upp/trunk@2757 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
06a9d3019c
commit
289cfd2aa0
7 changed files with 123 additions and 131 deletions
|
|
@ -1,9 +0,0 @@
|
|||
description "Simple Common Gateway Interface\377";
|
||||
|
||||
uses
|
||||
Web;
|
||||
|
||||
file
|
||||
ScgiServer.cpp,
|
||||
ScgiServer.h;
|
||||
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
#ifndef _ScgiServer_icpp_init_stub
|
||||
#define _ScgiServer_icpp_init_stub
|
||||
#include "Web/init"
|
||||
#endif
|
||||
|
|
@ -1,83 +1,83 @@
|
|||
#include <signal.h>
|
||||
|
||||
#include <Core/Core.h>
|
||||
#include <Web/Web.h>
|
||||
|
||||
#include "ScgiServer.h"
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
bool run = true;
|
||||
|
||||
void sighandler(int sig)
|
||||
{
|
||||
run = false;
|
||||
}
|
||||
|
||||
ScgiServer::ScgiServer(int port)
|
||||
{
|
||||
this->port = port;
|
||||
|
||||
signal(SIGABRT, sighandler);
|
||||
signal(SIGINT, sighandler);
|
||||
signal(SIGTERM, sighandler);
|
||||
}
|
||||
|
||||
void ScgiServer::Run()
|
||||
{
|
||||
ServerSocket(serverSock, port);
|
||||
while (run) {
|
||||
if (serverSock.Accept(clientSock, &clientIP)) {
|
||||
OnAccepted();
|
||||
|
||||
String sLen = clientSock.ReadUntil(':');
|
||||
int len = atoi(sLen);
|
||||
String data;
|
||||
|
||||
if (clientSock.IsOpen() && !clientSock.IsEof() && !clientSock.IsError()) {
|
||||
// len + 1 = data plus the trailing , as in SCGI spec
|
||||
data = clientSock.ReadCount(len+1, 3000);
|
||||
}
|
||||
|
||||
String key;
|
||||
int spos = 0;
|
||||
for (int i=0; i < data.GetCount(); i++) {
|
||||
if (data[i] == 0) {
|
||||
if (key.IsEmpty())
|
||||
key = data.Mid(spos, i-spos);
|
||||
else {
|
||||
String value = data.Mid(spos, i-spos);
|
||||
|
||||
serverVars.Add(key, value);
|
||||
key.Clear();
|
||||
}
|
||||
|
||||
spos = i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
query.SetURL("?" + serverVars.Get("QUERY_STRING"));
|
||||
|
||||
hasPostData = false;
|
||||
if (serverVars.Get("REQUEST_METHOD") == "POST") {
|
||||
len = atoi(serverVars.Get("CONTENT_LENGTH"));
|
||||
if (len > 0 && clientSock.IsOpen() && !clientSock.IsEof() &&
|
||||
!clientSock.IsError())
|
||||
{
|
||||
data = clientSock.ReadCount(len, 3000);
|
||||
post.SetURL("?" + data);
|
||||
hasPostData = true;
|
||||
}
|
||||
}
|
||||
|
||||
OnRequest();
|
||||
|
||||
clientSock.Close();
|
||||
serverVars.Clear();
|
||||
query.Clear();
|
||||
post.Clear();
|
||||
|
||||
OnClosed();
|
||||
}
|
||||
}
|
||||
}
|
||||
#include <signal.h>
|
||||
|
||||
#include <Core/Core.h>
|
||||
#include <Web/Web.h>
|
||||
|
||||
#include "ScgiServer.h"
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
bool run = true;
|
||||
|
||||
void sighandler(int sig)
|
||||
{
|
||||
run = false;
|
||||
}
|
||||
|
||||
ScgiServer::ScgiServer(int port)
|
||||
{
|
||||
this->port = port;
|
||||
|
||||
signal(SIGABRT, sighandler);
|
||||
signal(SIGINT, sighandler);
|
||||
signal(SIGTERM, sighandler);
|
||||
}
|
||||
|
||||
void ScgiServer::Run()
|
||||
{
|
||||
ServerSocket(serverSock, port);
|
||||
while (run) {
|
||||
if (serverSock.Accept(clientSock, &clientIP)) {
|
||||
OnAccepted();
|
||||
|
||||
String sLen = clientSock.ReadUntil(':');
|
||||
int len = atoi(sLen);
|
||||
String data;
|
||||
|
||||
if (clientSock.IsOpen() && !clientSock.IsEof() && !clientSock.IsError()) {
|
||||
// len + 1 = data plus the trailing , as in SCGI spec
|
||||
data = clientSock.ReadCount(len+1, 3000);
|
||||
}
|
||||
|
||||
String key;
|
||||
int spos = 0;
|
||||
for (int i=0; i < data.GetCount(); i++) {
|
||||
if (data[i] == 0) {
|
||||
if (key.IsEmpty())
|
||||
key = data.Mid(spos, i-spos);
|
||||
else {
|
||||
String value = data.Mid(spos, i-spos);
|
||||
|
||||
serverVars.Add(key, value);
|
||||
key.Clear();
|
||||
}
|
||||
|
||||
spos = i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
query.SetURL("?" + serverVars.Get("QUERY_STRING"));
|
||||
|
||||
hasPostData = false;
|
||||
if (serverVars.Get("REQUEST_METHOD") == "POST") {
|
||||
len = atoi(serverVars.Get("CONTENT_LENGTH"));
|
||||
if (len > 0 && clientSock.IsOpen() && !clientSock.IsEof() &&
|
||||
!clientSock.IsError())
|
||||
{
|
||||
data = clientSock.ReadCount(len, 3000);
|
||||
post.SetURL("?" + data);
|
||||
hasPostData = true;
|
||||
}
|
||||
}
|
||||
|
||||
OnRequest();
|
||||
|
||||
clientSock.Close();
|
||||
serverVars.Clear();
|
||||
query.Clear();
|
||||
post.Clear();
|
||||
|
||||
OnClosed();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,34 +1,36 @@
|
|||
#ifndef _ScgiServer_ScgiServer_h
|
||||
#define _ScgiServer_ScgiServer_h
|
||||
|
||||
#include <Web/Web.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
class ScgiServer {
|
||||
public:
|
||||
HttpQuery query;
|
||||
HttpQuery post;
|
||||
|
||||
ScgiServer(int port = 7800);
|
||||
|
||||
void Run();
|
||||
|
||||
dword ClientIP() { return clientIP; }
|
||||
Socket ClientSock() { return clientSock; }
|
||||
|
||||
bool HasPostData() { return hasPostData; }
|
||||
|
||||
virtual void OnAccepted() {}
|
||||
virtual void OnRequest() {}
|
||||
virtual void OnClosed() {}
|
||||
|
||||
protected:
|
||||
int port;
|
||||
Socket serverSock, clientSock;
|
||||
VectorMap<String,String> serverVars;
|
||||
dword clientIP;
|
||||
bool hasPostData;
|
||||
};
|
||||
|
||||
#endif
|
||||
#ifndef _ScgiServer_ScgiServer_h
|
||||
#define _ScgiServer_ScgiServer_h
|
||||
|
||||
#include <Web/Web.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
class ScgiServer {
|
||||
public:
|
||||
HttpQuery query;
|
||||
HttpQuery post;
|
||||
|
||||
ScgiServer(int port = 7800);
|
||||
|
||||
void Run();
|
||||
|
||||
dword ClientIP() { return clientIP; }
|
||||
Socket ClientSock() { return clientSock; }
|
||||
|
||||
void Write(const String& text) { clientSock.Write(text); }
|
||||
|
||||
bool HasPostData() { return hasPostData; }
|
||||
|
||||
virtual void OnAccepted() {}
|
||||
virtual void OnRequest() {}
|
||||
virtual void OnClosed() {}
|
||||
|
||||
protected:
|
||||
int port;
|
||||
Socket serverSock, clientSock;
|
||||
VectorMap<String,String> serverVars;
|
||||
dword clientIP;
|
||||
bool hasPostData;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -41,6 +41,7 @@ NAMESPACE_UPP
|
|||
#include "auth.h"
|
||||
#include "smtp.h"
|
||||
#include "sproc.h"
|
||||
#include "ScgiServer.h"
|
||||
|
||||
END_UPP_NAMESPACE
|
||||
|
||||
|
|
|
|||
|
|
@ -30,6 +30,8 @@ file
|
|||
smtp.cpp,
|
||||
sproc.h,
|
||||
sproc.cpp,
|
||||
ScgiServer.h,
|
||||
ScgiServer.cpp,
|
||||
src.tpp,
|
||||
srcdoc.tpp,
|
||||
srcimp.tpp,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef _Web_icpp_init_stub
|
||||
#define _Web_icpp_init_stub
|
||||
#include "Core/init"
|
||||
#define BLITZ_INDEX__ F013A89C23D31A4716457864E38F2235B
|
||||
#define BLITZ_INDEX__ F6F37DAE5668E45571942689ACEE874C1
|
||||
#include "Web_init.icpp"
|
||||
#undef BLITZ_INDEX__
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue