From 3bbc0993731cc3da8612059b8373469e3fae00ea Mon Sep 17 00:00:00 2001 From: eru Date: Tue, 29 Sep 2009 16:47:12 +0000 Subject: [PATCH] =?utf8?q?cmd=3Dviewxml=E6=99=82=E3=81=AEHTTP=E3=83=AC?= =?utf8?q?=E3=82=B9=E3=83=9D=E3=83=B3=E3=82=B9=E3=83=98=E3=83=83=E3=83=80?= =?utf8?q?=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- PeerCast.root/PeerCast/core/common/servhs.cpp | 15 +++++++++++++- PeerCast.root/PeerCast/core/common/stream.h | 23 ++++++++++++++++++++++ PeerCast.root/PeerCast/core/win32/seh.h | 8 +++++++- .../PeerCast.root/PeerCast/core/common/servhs.cpp | 15 +++++++++++++- c:/Git/PeerCast.root/PeerCast/core/common/stream.h | 23 ++++++++++++++++++++++ c:/Git/PeerCast.root/PeerCast/core/win32/seh.h | 8 +++++++- 6 files changed, 88 insertions(+), 4 deletions(-) diff --git a/PeerCast.root/PeerCast/core/common/servhs.cpp b/PeerCast.root/PeerCast/core/common/servhs.cpp index 7217767..e53e80a 100644 --- a/PeerCast.root/PeerCast/core/common/servhs.cpp +++ b/PeerCast.root/PeerCast/core/common/servhs.cpp @@ -1697,13 +1697,26 @@ void Servent::handshakeXML() rn->add(hc); + // calculate content-length + DummyStream ds; + xml.write(ds); + + // set line-feed code to CRLF (for HTTP header) + bool bWriteCRLF = sock->writeCRLF; + sock->writeCRLF = true; + + // write HTTP response header sock->writeLine(HTTP_SC_OK); sock->writeLineF("%s %s",HTTP_HS_SERVER,PCX_AGENT); sock->writeLineF("%s %s",HTTP_HS_CONTENT,MIME_XML); + sock->writeLineF("%s %d", HTTP_HS_LENGTH, ds.getLength()); sock->writeLine("Connection: close"); - sock->writeLine(""); + // revert setting + sock->writeCRLF = bWriteCRLF; + + // write HTTP body xml.write(*sock); } diff --git a/PeerCast.root/PeerCast/core/common/stream.h b/PeerCast.root/PeerCast/core/common/stream.h index c0dbe13..337047d 100644 --- a/PeerCast.root/PeerCast/core/common/stream.h +++ b/PeerCast.root/PeerCast/core/common/stream.h @@ -540,5 +540,28 @@ public: Stream *out; }; +// write‚³‚ꂽ‚à‚Ì‚ðŽÌ‚ĂăoƒCƒg”‚¾‚¯ƒJƒEƒ“ƒg‚·‚éƒXƒgƒŠ[ƒ€ +class DummyStream : public Stream +{ +private: + unsigned long length; + +public: + DummyStream() : length(0) {}; + + void write(const void *p, int l) + { + length += l; + } + + unsigned long getLength() + { + return length; + } + + // dummy functions + int read(void *, int) { return 0; } +}; + #endif diff --git a/PeerCast.root/PeerCast/core/win32/seh.h b/PeerCast.root/PeerCast/core/win32/seh.h index fffbfab..cb99a6a 100644 --- a/PeerCast.root/PeerCast/core/win32/seh.h +++ b/PeerCast.root/PeerCast/core/win32/seh.h @@ -9,6 +9,7 @@ extern FileStream fs; +#ifndef _DEBUG #define SEH_THREAD(func, name) \ { \ __try \ @@ -17,7 +18,12 @@ extern FileStream fs; } __except(SEHdump(GetExceptionInformation()), EXCEPTION_EXECUTE_HANDLER) \ { \ } \ -} \ +} + +#else + +#define SEH_THREAD(func, name) return func(thread); +#endif void SEHdump(_EXCEPTION_POINTERS *); diff --git a/c:/Git/PeerCast.root/PeerCast/core/common/servhs.cpp b/c:/Git/PeerCast.root/PeerCast/core/common/servhs.cpp index 7217767..e53e80a 100644 --- a/c:/Git/PeerCast.root/PeerCast/core/common/servhs.cpp +++ b/c:/Git/PeerCast.root/PeerCast/core/common/servhs.cpp @@ -1697,13 +1697,26 @@ void Servent::handshakeXML() rn->add(hc); + // calculate content-length + DummyStream ds; + xml.write(ds); + + // set line-feed code to CRLF (for HTTP header) + bool bWriteCRLF = sock->writeCRLF; + sock->writeCRLF = true; + + // write HTTP response header sock->writeLine(HTTP_SC_OK); sock->writeLineF("%s %s",HTTP_HS_SERVER,PCX_AGENT); sock->writeLineF("%s %s",HTTP_HS_CONTENT,MIME_XML); + sock->writeLineF("%s %d", HTTP_HS_LENGTH, ds.getLength()); sock->writeLine("Connection: close"); - sock->writeLine(""); + // revert setting + sock->writeCRLF = bWriteCRLF; + + // write HTTP body xml.write(*sock); } diff --git a/c:/Git/PeerCast.root/PeerCast/core/common/stream.h b/c:/Git/PeerCast.root/PeerCast/core/common/stream.h index c0dbe13..337047d 100644 --- a/c:/Git/PeerCast.root/PeerCast/core/common/stream.h +++ b/c:/Git/PeerCast.root/PeerCast/core/common/stream.h @@ -540,5 +540,28 @@ public: Stream *out; }; +// write‚³‚ꂽ‚à‚Ì‚ðŽÌ‚ĂăoƒCƒg”‚¾‚¯ƒJƒEƒ“ƒg‚·‚éƒXƒgƒŠ[ƒ€ +class DummyStream : public Stream +{ +private: + unsigned long length; + +public: + DummyStream() : length(0) {}; + + void write(const void *p, int l) + { + length += l; + } + + unsigned long getLength() + { + return length; + } + + // dummy functions + int read(void *, int) { return 0; } +}; + #endif diff --git a/c:/Git/PeerCast.root/PeerCast/core/win32/seh.h b/c:/Git/PeerCast.root/PeerCast/core/win32/seh.h index fffbfab..cb99a6a 100644 --- a/c:/Git/PeerCast.root/PeerCast/core/win32/seh.h +++ b/c:/Git/PeerCast.root/PeerCast/core/win32/seh.h @@ -9,6 +9,7 @@ extern FileStream fs; +#ifndef _DEBUG #define SEH_THREAD(func, name) \ { \ __try \ @@ -17,7 +18,12 @@ extern FileStream fs; } __except(SEHdump(GetExceptionInformation()), EXCEPTION_EXECUTE_HANDLER) \ { \ } \ -} \ +} + +#else + +#define SEH_THREAD(func, name) return func(thread); +#endif void SEHdump(_EXCEPTION_POINTERS *); -- 2.11.0