mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-08-30 23:02:39 -06:00
.XmlRpc: Improved HTTP compliance
git-svn-id: svn://ultimatepp.org/upp/trunk@2829 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
a7c7216201
commit
073301327d
5 changed files with 58 additions and 29 deletions
|
|
@ -255,6 +255,8 @@ REGISTER_VALUE_XMLIZE(Rect);
|
|||
REGISTER_VALUE_XMLIZE(Rect64);
|
||||
REGISTER_VALUE_XMLIZE(Rectf);
|
||||
REGISTER_VALUE_XMLIZE(Color);
|
||||
REGISTER_VALUE_XMLIZE(ValueArray);
|
||||
REGISTER_VALUE_XMLIZE(ValueMap);
|
||||
|
||||
static String s_binary("serialized_binary");
|
||||
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@ NAMESPACE_UPP
|
|||
|
||||
bool HttpClient_Trace__;
|
||||
|
||||
#define LLOG(x) if(HttpClient_Trace__) RLOG(x); else;
|
||||
#define LLOGBLOCK(x) // DLOGBLOCK(x)
|
||||
#define LLOG(x) // DLOG(x) //if(HttpClient_Trace__) RLOG(x); else;
|
||||
#define LLOGBLOCK(x) // DLOG(x)
|
||||
|
||||
void HttpClient::Trace(bool b)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,6 +2,19 @@
|
|||
|
||||
NAMESPACE_UPP
|
||||
|
||||
String WwwFormat(Time tm)
|
||||
{
|
||||
static const char *dayofweek[] =
|
||||
{ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
|
||||
static const char *month[] =
|
||||
{ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
|
||||
return String().Cat()
|
||||
<< dayofweek[DayOfWeek(tm)] << ", "
|
||||
<< (int)tm.day << ' ' << month[tm.month - 1]
|
||||
<< ' ' << (int)tm.year
|
||||
<< ' ' << Sprintf("%2d:%02d:%02d +0100", tm.hour, tm.minute, tm.second);
|
||||
}
|
||||
|
||||
bool IsSameTextFile(const char *p, const char *q)
|
||||
{
|
||||
for(;;)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef __tweb_util__
|
||||
#define __tweb_util__
|
||||
|
||||
String WwwFormat(Time tm);
|
||||
bool IsSameTextFile(const char *p, const char *q);
|
||||
String StringSample(const char *s, int limit);
|
||||
String FormatIP(dword _ip);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#include "XmlRpc.h"
|
||||
#include "XmlRpc.h"
|
||||
|
||||
#define LLOG(x) // LOG(x)
|
||||
#define LLOG(x) // DLOG(x)
|
||||
|
||||
typedef void (*XmlRpcFnPtr)(XmlRpcData&);
|
||||
|
||||
|
|
@ -117,33 +117,46 @@ String ReadLine(Socket& s)
|
|||
bool XmlRpcPerform(Socket& http, const char *group)
|
||||
{
|
||||
LLOG("=== Accepted connection ===================================================");
|
||||
String request = ReadLine(http);
|
||||
if(http.IsError()) return false;
|
||||
VectorMap<String, String> hdr;
|
||||
for(;;) {
|
||||
String s = ReadLine(http);
|
||||
if(s.IsEmpty()) break;
|
||||
LLOG(s);
|
||||
int q = s.Find(':');
|
||||
if(q >= 0)
|
||||
hdr.GetAdd(s.Mid(0, q)) = TrimLeft(s.Mid(q + 1));
|
||||
String request = ToUpper(ReadLine(http));
|
||||
LLOG(request);
|
||||
if(http.IsError() || request.GetCount() == 0)
|
||||
return false;
|
||||
if(request.Find("POST") >= 0 || request.Find("HTTP") >= 0) {
|
||||
VectorMap<String, String> hdr;
|
||||
for(;;) {
|
||||
String s = ReadLine(http);
|
||||
if(s.IsEmpty()) break;
|
||||
LLOG(s);
|
||||
int q = s.Find(':');
|
||||
if(q >= 0)
|
||||
hdr.GetAdd(s.Mid(0, q)) = TrimLeft(s.Mid(q + 1));
|
||||
}
|
||||
if(!http.IsError()) {
|
||||
int len = atoi(hdr.Get("Content-Length", ""));
|
||||
String r;
|
||||
if(len > 0 && len < 1024 * 1024 * 1024) {
|
||||
r = XmlRpcExecute(http.ReadCount(len, 90000),
|
||||
group, http.GetPeerAddr());
|
||||
LLOG("--------- Server response:\n" << r << "=============");
|
||||
String response;
|
||||
String ts = WwwFormat(GetUtcTime());
|
||||
response <<
|
||||
"HTTP/1.0 200 OK\r\n"
|
||||
"Date: " << ts << "\r\n"
|
||||
"Server: U++\r\n"
|
||||
"Content-Length: " << r.GetCount() << "\r\n"
|
||||
"Connection: close\r\n"
|
||||
"Content-Type: text/xml\r\n\r\n"
|
||||
<< r;
|
||||
LLOG(response);
|
||||
http.Write(response);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(http.IsError()) return false;
|
||||
String r = XmlRpcExecute(http.ReadCount(atoi(hdr.Get("Content-Length", "")), 90000),
|
||||
group, http.GetPeerAddr());
|
||||
LLOG("--------- Server response:\n" << r << "=============");
|
||||
String response;
|
||||
response <<
|
||||
"HTTP/1.1 200 OK\r\n"
|
||||
"Date: Mon, 23 May 2005 22:38:34 GMT\r\n"
|
||||
"Server: U++\r\n"
|
||||
"Last-Modified: Wed, 08 Jan 2003 23:11:55 GMT\r\n"
|
||||
"Accept-Ranges: bytes\r\n"
|
||||
"Content-Length: " << r.GetCount() << "\r\n"
|
||||
"Connection: close\r\n"
|
||||
"Content-Type: application/soap+xml; charset=utf-8\r\n\r\n" << r;
|
||||
http.Write(response);
|
||||
return true;
|
||||
http.Write("HTTP/1.0 400 Bad request\r\n"
|
||||
"Server: U++\r\n\r\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool XmlRpcServer(int port, const char *group)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue