[twsocket] THttpCli: (StatusCode = 0 AND ReasonPhrase = OK) ???
Hi All, I've noticed that sometimes this happens in my application... THttpCli: (StatusCode = 0 AND ReasonPhrase = OK) A search of the HttpProt.pas source has failed to shed any further light on this... Any suggestions? Regards, Keith Willis. No virus found in this outgoing message. Checked by AVG - www.avg.com Version: 9.0.791 / Virus Database: 271.1.1/2770 - Release Date: 03/26/10 05:50:00 No virus found in this outgoing message. Checked by AVG - www.avg.com Version: 9.0.791 / Virus Database: 271.1.1/2770 - Release Date: 03/26/10 05:50:00 -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
[twsocket] PROGRESS: EAccessViolations when Posting Data to a HTTPServer
Oops...I forgot to add the following line to my code: HttpServer-ClientClass = __classid(TMyHttpConnection); Consequently, all my memory allocations/deallocations were trashing the heap in unpredictable ways. Keith Willis. ps. That MadExcept looks great as does EurekaLog -Original Message- From: twsocket-boun...@elists.org [mailto:twsocket-boun...@elists.org] On Behalf Of Arno Garrels Sent: Monday, 2 February 2009 3:43 AM To: ICS support mailing Subject: Re: [twsocket] EAccessViolations when Posting Data to a HTTPServer Keith Willis wrote: Well I tried malloc and free without any joy. I have however been able to ascertain that its crashing in the call to Receive. More significantly its only crashing on my target machine, (an ASUS EEE Box B202 running Windows XP Home). I can't seem to crash it on my development PC, (A generic Pentium desktop running Windows 2000 Pro). Is there some difference between the Winsock library in Windows XP Home and Windows 2000 Pro? The sample I posted previously to the list runs without problem on both XP Home and Pro. Is there any security software installed, like a personal firewall, anti-virus software etc.? If so, first try to disable it, if that doesn't help, remove it. -- Arno Garrels -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be Internal Virus Database is out of date. Checked by AVG - http://www.avg.com Version: 8.0.173 / Virus Database: 270.7.6/1715 - Release Date: 10/8/2008 7:19 PM -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] EAccessViolations when Posting Data to a HTTPServer
I've disabled all Firewalls and anti-virus stuff without any change in the apps behaviour. I even tried re-compiling the ICS library and also directly linking the relevant Pascal units into my project all without any change to the problem. I will now try to catch an exception on my development PC when I dynamically allocate memory. This sometimes happens and I may be able to trap an exception lower down in the ICS code with the debugger if I directly link in the Pascal units. I may also install Windows 2000 Pro on to the EEE Box target machine. ... After this I'm probably out of ideas. It might be time to try the Indy component to see what it does :( Keith Willis. -Original Message- From: twsocket-boun...@elists.org [mailto:twsocket-boun...@elists.org] On Behalf Of Arno Garrels Sent: Monday, 2 February 2009 3:43 AM To: ICS support mailing Subject: Re: [twsocket] EAccessViolations when Posting Data to a HTTPServer Keith Willis wrote: Well I tried malloc and free without any joy. I have however been able to ascertain that its crashing in the call to Receive. More significantly its only crashing on my target machine, (an ASUS EEE Box B202 running Windows XP Home). I can't seem to crash it on my development PC, (A generic Pentium desktop running Windows 2000 Pro). Is there some difference between the Winsock library in Windows XP Home and Windows 2000 Pro? The sample I posted previously to the list runs without problem on both XP Home and Pro. Is there any security software installed, like a personal firewall, anti-virus software etc.? If so, first try to disable it, if that doesn't help, remove it. -- Arno Garrels -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be Internal Virus Database is out of date. Checked by AVG - http://www.avg.com Version: 8.0.173 / Virus Database: 270.7.6/1715 - Release Date: 10/8/2008 7:19 PM -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] EAccessViolations when Posting Data to a HTTPServer
Hi Arno, Just confirming that you meant to write: ClientCnx-Receive(Junk, sizeof(Junk)); Instead of: ClientCnx-Receive(Junk, sizeof(Junk)); Cheers, Keith. -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] EAccessViolations when Posting Data to a HTTPServer
Arno, No luck I'm afraid... I'm still getting those AV's :( Keith. Here's my current code... As per your suggested code. I also made the TMemoryManager global to the application. I will try free and malloc next. CODE SNIPPETS //-- - class TMyHttpConnection : public THttpConnection { public: char *PostedDataBuffer; // Will hold dynamically allocated buffer int PostedDataSize;// Databuffer size int RcvdByteCount; // Keep track of received byte count. public: __fastcall TMyHttpConnection(Classes::TComponent* AOwner); virtual __fastcall ~TMyHttpConnection(); }; //-- - //-- - __fastcall TMyHttpConnection::TMyHttpConnection(Classes::TComponent* AOwner) : THttpConnection(AOwner) { try { PostedDataBuffer = NULL; PostedDataSize = 0; } catch(...) {} } //-- - __fastcall TMyHttpConnection::~TMyHttpConnection() { try { if (PostedDataBuffer != NULL) { if (MemoryManager-FreeMem(PostedDataBuffer) == 0) { PostedDataBuffer = NULL; PostedDataSize = 0; } } } catch(...) {} } //-- - //-- - void __fastcall TAegisWebServerForm::HttpServerPostDocument(TObject *Sender, TObject *Client, THttpGetFlag Flags) { try { TMyHttpConnection* Connection = (TMyHttpConnection*)Client; FCountRequests++; // Count request and display a message if (CompareText(Connection-Path, /content/home.html) == 0)// This page is not cached { Flags = hgAcceptData; Connection-LineMode = false; if (Connection-PostedDataSize Connection-RequestContentLength + 1) { if (Connection-PostedDataBuffer != NULL) {if (MemoryManager-FreeMem(Connection-PostedDataBuffer) != 0) throw Exception(Unable to free memory for Posted Data Buffer);} Connection-PostedDataSize = 0; Connection-PostedDataBuffer = (char*)(MemoryManager-GetMem(Connection-RequestContentLength + 1)); if (Connection-PostedDataBuffer == NULL) throw Exception(Unable to allocate memory for Posted Data Buffer); Connection-PostedDataSize = Connection-RequestContentLength + 1; } Connection-RcvdByteCount = 0; } else Flags = hg404; } catch (Exception E) {HandleError(TAegisWebServerForm::HttpServerPostDocument, E.Message);} catch (const exception e) {HandleError(TAegisWebServerForm::HttpServerPostDocument, e.what());} catch (...) {HandleError(TAegisWebServerForm::HttpServerPostDocument, Unknown Exception);} } //-- - void __fastcall TAegisWebServerForm::HttpServerPostedData(TObject *Sender, TObject *Client, WORD Error) { try { int Len, Remains; char Junk[1024]; TMyHttpConnection* Connection = (TMyHttpConnection*)Client; Remains = Connection-RequestContentLength - Connection-RcvdByteCount; if (Remains = 0) { Connection-Receive(Junk, sizeof(Junk)); return; } Len = Connection-Receive((Connection-PostedDataBuffer[Connection-RcvdByteCount ]), Remains); if (Len = 0) return; Connection-RcvdByteCount += Len; if (Connection-RcvdByteCount Connection-RequestContentLength) Connection-RcvdByteCount = Connection-RequestContentLength; if (Connection-RcvdByteCount == Connection-RequestContentLength) { Connection-PostedDataReceived(); Connection-PostedDataBuffer[Connection-RcvdByteCount] = 0; ProcessPostedData(Connection); } } catch (Exception E) {HandleError(TAegisWebServerForm::HttpServerPostedData, E.Message);} catch (const exception e) {HandleError(TAegisWebServerForm::HttpServerPostedData, e.what());} catch (...) {HandleError(TAegisWebServerForm::HttpServerPostedData, Unknown Exception);} } //-- - -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] EAccessViolations when Posting Data to a HTTPServer
In C/C++ if you declare Junk statically eg: char Junk[1024];, Junk is of type char* so the Junk will be of type char**. -Original Message- From: twsocket-boun...@elists.org [mailto:twsocket-boun...@elists.org] On Behalf Of Arno Garrels Sent: Sunday, 1 February 2009 3:55 AM To: ICS support mailing Subject: Re: [twsocket] EAccessViolations when Posting Data to a HTTPServer Keith Willis wrote: Just confirming that you meant to write: ClientCnx-Receive(Junk, sizeof(Junk)); Instead of: ClientCnx-Receive(Junk, sizeof(Junk)); I don't think so, I meant the address of Junk which is the address of the first element of the static array, isn't it? Same as ClientCnx-Receive(Junk[0], sizeof(Junk)); In Delphi you MUST write it that way. Seems like CB has some built-in compiler magic so that ClientCnx-Receive(Junk, sizeof(Junk)); works as well (I used C++Builder 2007 and ICS v7). -- Arno Garrels -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be Internal Virus Database is out of date. Checked by AVG - http://www.avg.com Version: 8.0.173 / Virus Database: 270.7.6/1715 - Release Date: 10/8/2008 7:19 PM -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] EAccessViolations when Posting Data to a HTTPServer
Well I tried malloc and free without any joy. I have however been able to ascertain that its crashing in the call to Receive. More significantly its only crashing on my target machine, (an ASUS EEE Box B202 running Windows XP Home). I can't seem to crash it on my development PC, (A generic Pentium desktop running Windows 2000 Pro). Is there some difference between the Winsock library in Windows XP Home and Windows 2000 Pro? I will try some other PC's as well for reference. Keith. -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
[twsocket] EAccessViolations when Posting Data to a HTTPServer
Dear All, I have recently written a small Web Server application using the THttpServer component in ICS 5 with C++ Builder 5. It serves GET requests perfectly, but when I added POST functionality, (following the WebServ example) it has started generating EAccessViolations. CodeGuard reports that these are due to my PostedDataBuffer having only a 1 byte heap length when I am writing the NULL string termination character in the HttpServerPostedData event handler. I have managed to improve the code reliability by not dynamically allocating the PostedDataBuffer at all, (but this is not an acceptable solution). In the code snippets below I pre-allocate once in the constructor but this still generates AV's. Can anyone shed some light on what might be happening here? Regards, Keith Willis. CODE SNIPPETS //-- - class TMyHttpConnection : public THttpConnection { public: char* Junk; char *PostedDataBuffer; // Will hold dynamically allocated buffer int PostedDataSize;// Databuffer size int RcvdByteCount; // Keep track of received byte count. public: __fastcall TMyHttpConnection(Classes::TComponent* AOwner); virtual __fastcall ~TMyHttpConnection(); }; //-- - //-- - __fastcall TMyHttpConnection::TMyHttpConnection(Classes::TComponent* AOwner) : THttpConnection(AOwner) { try { Junk = new char(65536); PostedDataBuffer = new char(65536); // Pre-allocate here in a desperate attempt to avoid EAccessViolations PostedDataSize = 65536; } catch(...) {} } //-- - __fastcall TMyHttpConnection::~TMyHttpConnection() { try { delete [] Junk; delete [] PostedDataBuffer; PostedDataBuffer = NULL; PostedDataSize = 0; } catch(...) {} } //-- - //-- - void __fastcall TAegisWebServerForm::HttpServerPostedData(TObject *Sender, TObject *Client, WORD Error) { try { int Len, Remains; TMyHttpConnection* Connection = (TMyHttpConnection*)Client; Remains = Connection-RequestContentLength - Connection-RcvdByteCount; if (Remains = 0) { Len = Connection-Receive(Connection-Junk, sizeof(Connection-Junk)- 1); if (Len = 0) Connection-Junk[Len] = 0; return; } // Len = Connection-Receive(Connection-PostedDataBuffer + Connection-RcvdByteCount, Remains); Len = Connection-Receive((Connection-PostedDataBuffer[Connection-RcvdByteCount ]), Remains); if (Len = 0) return; Connection-RcvdByteCount += Len; if (Connection-RcvdByteCount Connection-RequestContentLength) Connection-RcvdByteCount = Connection-RequestContentLength; if (Connection-RcvdByteCount == Connection-RequestContentLength) { Connection-PostedDataBuffer[Connection-RcvdByteCount] = 0; // = CRASHES HERE! CodeGuard reports that the Heap length of is only 1 byte at this point??? if (CompareText(Connection-Path, /content/home.html) == 0) ProcessPostedData(Connection); // else Connection-Answer404(); // I need to make Answer404 accessible else { AnsiString Body = AnsiString(HTMLHEADTITLE404 Not Found/TITLE/HEADBODYH1404 Not Found/H1The requested URL ) + TextToHtmlText(Connection-Path) + was not found on this server.P/BODY/HTML\r\n; Connection-SendHeader(Connection-Version + 404 Not Found\r\nContent-Type: text/html\r\nContent-Length: + Utility-IntToStrEx(Body.Length()) + \r\n\r\n); Connection-SendStr(Body); } Connection-PostedDataReceived(); } } catch (Exception E) {HandleError(TAegisWebServerForm::HttpServerPostedData, E.Message);} catch (const exception e) {HandleError(TAegisWebServerForm::HttpServerPostedData, e.what());} catch (...) {HandleError(TAegisWebServerForm::HttpServerPostedData, Unknown Exception);} } //-- - -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] EAccessViolations when Posting Data to a HTTPServer
Hi Arno, You never check PostedDataSize, the size of your receive buffer. The pascal demo allocates this buffer dynamically depending on the RequestContentLength plus one byte for the null terminator in the OnPostDocument event handler. What is the value of RcvdByteCount when the error happens? I originally did it like that, but it kept crashing with AV's so I embarked on a process of elimination of suspect code until I ended up with an (almost) stable version where PostedDataBuffer was statically allocated in the class declaration. The version I released in my original posting in this mailing list was the penultimate iteration where I was still dynamically allocating memory, but only once in TMyHttpConnection's constructor. This drastically simplified version still generates AV's so I thought it would be more relevant to the discussion. My original code is included below for reference: CODE SNIPPETS //-- - class TMyHttpConnection : public THttpConnection { public: char* Junk; char* PostedDataBuffer; // Will hold dynamically allocated buffer int PostedDataSize;// Databuffer size int RcvdByteCount; // Keep track of received byte count. public: __fastcall TMyHttpConnection(Classes::TComponent* AOwner); virtual __fastcall ~TMyHttpConnection(); }; //-- - //-- - __fastcall TMyHttpConnection::TMyHttpConnection(Classes::TComponent* AOwner) : THttpConnection(AOwner) { try { Junk = new char(65536); PostedDataBuffer = NULL; PostedDataSize = 0; } catch(...) {} } //-- - __fastcall TMyHttpConnection::~TMyHttpConnection() { try { delete [] Junk; if (PostedDataBuffer != NULL) { delete [] PostedDataBuffer; PostedDataBuffer = NULL; PostedDataSize = 0; } } catch(...) {} } //-- - void __fastcall TAegisWebServerForm::HttpServerPostDocument(TObject *Sender, TObject *Client, THttpGetFlag Flags) { try { TMyHttpConnection* Connection = (TMyHttpConnection*)Client; FCountRequests++; // Count request and display a message if (CompareText(Connection-Path, /content/home.html) == 0)// This page is not cached { Flags = hgAcceptData; Connection-LineMode = false; TMemoryManager* MemoryManager = new TMemoryManager(); try { GetMemoryManager(*MemoryManager); if (Connection-PostedDataSize == 0) { Connection-PostedDataSize = Connection-RequestContentLength + 1; Connection-PostedDataBuffer = (char*)(MemoryManager-GetMem(Connection-PostedDataSize)); } else { Connection-PostedDataSize = Connection-RequestContentLength + 1; Connection-PostedDataBuffer = (char*)(MemoryManager-ReallocMem(Connection-PostedDataBuffer, Connection-PostedDataSize)); } } __finally {delete MemoryManager;} Connection-RcvdByteCount = 0; } } catch (Exception E) {HandleError(TAegisWebServerForm::HttpServerPostDocument, E.Message);} catch (const exception e) {HandleError(TAegisWebServerForm::HttpServerPostDocument, e.what());} catch (...) {HandleError(TAegisWebServerForm::HttpServerPostDocument, Unknown Exception);} } //-- - void __fastcall TAegisWebServerForm::HttpServerPostedData(TObject *Sender, TObject *Client, WORD Error) { try { int Len, Remains; TMyHttpConnection* Connection = (TMyHttpConnection*)Client; Remains = Connection-RequestContentLength - Connection-RcvdByteCount; if (Remains = 0) { Len = Connection-Receive(Connection-Junk, sizeof(Connection-Junk)- 1); if (Len = 0) Connection-Junk[Len] = 0; return; } // Len = Connection-Receive(Connection-PostedDataBuffer + Connection-RcvdByteCount, Remains); Len = Connection-Receive((Connection-PostedDataBuffer[Connection-RcvdByteCount ]), Remains); if (Len = 0) return; Connection-RcvdByteCount += Len; if (Connection-RcvdByteCount Connection-RequestContentLength) Connection-RcvdByteCount = Connection-RequestContentLength; if (Connection-RcvdByteCount == Connection-RequestContentLength) { Connection-PostedDataBuffer[Connection-RcvdByteCount] = 0; if (CompareText(Connection-Path, /content/home.html) == 0) ProcessPostedData(Connection); // else Connection-Answer404(); // I need to make Answer404 accessible else { AnsiString Body = AnsiString(HTMLHEADTITLE404 Not Found/TITLE/HEADBODYH1404 Not Found/H1The requested URL ) + TextToHtmlText(Connection-Path) + was not found on this server.P/BODY/HTML\r\n; Connection-SendHeader(Connection-Version + 404 Not Found\r\nContent-Type: text/html\r\nContent-Length: + Utility-IntToStrEx(Body.Length()) +
[twsocket] FTP Client - Size() Function
Dear All, Is there a bullet-proof way to get a remote File Size using the TFTPClient component? I noted the following documentation on the FEAT command in the FTPCli.pas unit... FEAT Command - numerous extensions have been made to the FTP protocol over the past few years, although support of these new commands is very sporadic. RFC2389 describes the FEAT command, which returns a multiline list of extension supported by the server. Note that the SIZE command is an extension, and not supported on all FTP servers. An internet-draft 'Extensions to FTP' document the most useful new commands. The responses of five common FTP servers to FEAT are listed below: Cheers, Keith Willis. -- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
[twsocket] More on winsock.h included
Hi All, Below is an excerpt of one of my header files. As you might have noticed, I am using Indy, TurboPower Internet Professional, and ICS components together in the same module. #include IdBaseComponent.hpp #include IdComponent.hpp #include IdHTTP.hpp #include IdTCPClient.hpp #include IdTCPConnection.hpp #include SmtpProt.hpp #include FtpCli.hpp #include scktcomp.hpp #include IpFtp.hpp I have found that this is the only definition order which will compile ie... Indy first, (IdBaseComponent.hpp, IdComponent.hpp, IdHTTP.hpp, IdTCPClient.hpp, IdTCPConnection.hpp) then ICS, (SmtpProt.hpp, FtpCli.hpp) followed by Borland, (scktcomp.hpp) and finally TurboPower Internet Professional, (IpFtp.hpp). All other arrangements fail with errors relating to the fact that both winsock.h and winsock2.h both appear to have been included. Cheers, Keith Willis. -- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
[twsocket] Typo in IcsSha1.pas ?
IcsSha1.pas LINE 63: Bomb('This code requires Delphi 2 or later'}; Methinks... final } should be a ) Keith. -- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
[twsocket] TFtpClient Timeouts?
Hi All, What's the best way to detect if a timeout has occurred in a TFtpClient operation? Regards, Keith Willis. -- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
[twsocket] File Uploads via HTTP
Hi All, Is there a way to upload files directly, (in a similar fashion to FTP) using the ICS HTTP Client? Regards, Keith. -- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be