Re: [twsocket] pop3 and lastresponse

2010-09-20 Thread Arno Garrels
Arno Garrels wrote:
 Zvone wrote:
 IMO the component should clear LastResponse on before connect.
 
 Maybe it should, but what it does is different story :)

I checked in a few changes today, it's rev #600:

Log: Pop3Prot V6.08
Moved HMAC-MD5 code to OverbyteIcsMD5.pas. Ensure that var LastResponse is
cleared before Connect. Added a public read/write property LastError (as
requested by Zvone), it is more or less the last ErrCode as passed to event
OnRequestDone and reset on before each request.

SmtpProt V7.32
Moved HMAC-MD5 code to OverbyteIcsMD5.pas.

MD5 V7.01
Added HMAC_MD5 routine from OverbyteIcsSmtpProt.pas and MD5DigestToHex
functions.

Sha1 V2.02
Added SHA1DigestToHex functions.

DigestAuth V1.01
Uses OverbyteIcsMD5.MD5DigestToLowerHexA.

-- 
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


Re: [twsocket] pop3 and lastresponse

2010-09-19 Thread Arno Garrels
Zvone wrote:
 IMO the component should clear LastResponse on before connect.
 
 Maybe it should, but what it does is different story :)

Yes, it has to be fixed IMO. 

 So what about a numeric property LastErrorNumber?
 
 There is no such property nowhere in pop3 (or in any ICS file).

That was a feature suggestion for a new property LastRequestError
and perhaps a new property LastRequestType.
Will look at it more closly when I have some more time. 

-- 
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


[twsocket] pop3 and lastresponse

2010-09-18 Thread Zvone
I found something that might also be issue with pop3 component.

If you check one pop3 account and end the session usually LastResponse
will be some ending message like +OK sayonara. But if you then
reinitialize pop3 for another account and this account fails to
connect, for example due to timeout you get for example -ERR
Connection refused (Winsock error #10061) but LastResponse is still
+OK sayonara although it should be invalidated and set to empty
string. Or, there should be IMO a method ClearLastResponse as
LastResponse is not a writeable property right now. Checking on both
messages (LastError and LastResponse) is useful for debugging purposes
so they should be a possibility to manually (by calling
ClearLastResponse) or automatically invalidate LastResponse.

Furthermore, although Error code is accessible in for example
OnRequestDone it is not accessible within the pop3 component and the
code may sometimes be 10061 which is Winsock code or 500 which is pop3
component code. Nothing that can't be done with little RegEx on
LastError but why not publishing this as well?

I've done quite a bit of testing for Throttle and Timeout. While
Timeout works rather nice as far as Idle version goes, connect version
is usually preceded by Windows built-in timeout (unless you set
connect timeout to very low time like 1 second) Windows may time-out
the connection much sooner than connect timeout did. Other that that
it works fine. Try connecting to 127.0.0.1, unroutable address like
192.168.255.255, or 10.255.255.255, and existing but firewalled like
www.google.com:81 to test this. I'm not sure if it applies only to
later Windows and haven't tested with older Windows than XP.

As for Throttle, it works but rather strangely. If I set limit to 1
and timer to 1000 it should pass 1 byte every 1000ms and accumulate
the rest in internal buffer right? Well it doesn't work like if you do
something like SendStr(Some large string here) it will send entire
string and then wait for 1000 ms rather than sending just one byte
every 1000 ms. At least this is how throttle should work - send a
maximum of Limit bytes every Timer interval and if more is available,
store in internal buffer for sending later. It may be tricky to
implement as data could accumulate in memory but not sure about that
one.
--
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] pop3 and lastresponse

2010-09-18 Thread Angus Robertson - Magenta Systems Ltd
 While Timeout works rather nice as far as Idle version goes, connect 
 version is usually preceded by Windows built-in timeout 

An application can not cleanly stop a TCP connection attempt, you have to
wait for Windows to timeout, usually 40 seconds unless there is an error
of some sort earlier.  

To avoid this timeout, you need to try and ping the host first, which can
have a much shorter timeout, although ping may be blocked so it needs to
be optional. 

 As for Throttle, it works but rather strangely.  If I set limit to 1
and timer to 1000 it should pass 1 byte every 1000ms

Throttle is designed to slow down megabyte speeds to kilobytes, not to
send one byte per second. It does not deal with partial buffers. 

Angus


--
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] pop3 and lastresponse

2010-09-18 Thread Arno Garrels
Hello,

Zvone wrote:
 I found something that might also be issue with pop3 component.
 
 If you check one pop3 account and end the session usually LastResponse
 will be some ending message like +OK sayonara. But if you then
 reinitialize pop3 for another account and this account fails to
 connect, for example due to timeout you get for example -ERR
 Connection refused (Winsock error #10061) but LastResponse is still
 +OK sayonara although it should be invalidated and set to empty
 string. Or, there should be IMO a method ClearLastResponse as
 LastResponse is not a writeable property right now. Checking on both
 messages (LastError and LastResponse) is useful for debugging purposes
 so they should be a possibility to manually (by calling
 ClearLastResponse) or automatically invalidate LastResponse.

IMO the component should clear LastResponse on before connect. 

 
 Furthermore, although Error code is accessible in for example
 OnRequestDone it is not accessible within the pop3 component and the
 code may sometimes be 10061 which is Winsock code or 500 which is pop3
 component code. Nothing that can't be done with little RegEx on
 LastError but why not publishing this as well?

So what about a numeric property LastErrorNumber?  

[..] 
 As for Throttle, it works but rather strangely. If I set limit to 1
 and timer to 1000 it should pass 1 byte every 1000ms and accumulate
 the rest in internal buffer right? Well it doesn't work like if you do
 something like SendStr(Some large string here) it will send entire
 string and then wait for 1000 ms rather than sending just one byte
 every 1000 ms. At least this is how throttle should work - send a
 maximum of Limit bytes every Timer interval and if more is available,
 store in internal buffer for sending later. It may be tricky to
 implement as data could accumulate in memory but not sure about that
 one.

It is neither intended to support such small values nor to work very
accurate. Currently, as Angus said, it doesn't control buffer sizes.
However the following should do the trick IMO, if I haven't missed 
something, worth to be tested anyway:

function TCustomThrottledWSocket.RealSend(var Data: TWSocketData;
  Len: Integer): Integer;
begin
if FBandwidthEnabled and (Len  0) and
   (FBandwidthCount + LongWord(Len)  FBandwidthMaxCount) then
Len := (FBandwidthMaxCount - FBandwidthCount) + 1; // Ensure Len  0

Result := inherited RealSend(Data, Len);

if FBandwidthEnabled and (Result  0) then begin
Inc(FBandwidthCount, Result);
if (FBandwidthCount = FBandwidthMaxCount) and
   (not FBandwidthPaused) then begin
FBandwidthPaused := TRUE;
Pause;
end;
end;
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
function TCustomThrottledWSocket.Receive(Buffer: TWSocketData;
  BufferSize: Integer): Integer;
begin
if FBandwidthEnabled and (BufferSize  0) and
   (FBandwidthCount + LongWord(BufferSize)  FBandwidthMaxCount) then
BufferSize := (FBandwidthMaxCount - FBandwidthCount) + 1; // Ensure 
BufferSize  0

Result := inherited Receive(Buffer, BufferSize);

if FBandwidthEnabled and (Result  0) then begin
Inc(FBandwidthCount, Result);
if (FBandwidthCount  FBandwidthMaxCount) and
(not FBandwidthPaused) then begin
FBandwidthPaused := TRUE;
Pause;
end;
end;
end;

-- 
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


Re: [twsocket] pop3 and lastresponse

2010-09-18 Thread Zvone
 IMO the component should clear LastResponse on before connect.

Maybe it should, but what it does is different story :)

The following fails also with non-sync version but sync is easier to copy-paste.

//--

SyncPop3Cli-Host = put-valid-server-here;
SyncPop3Cli-UserName = put-valid-username;
SyncPop3Cli-PassWord = put-valid-password;
SyncPop3Cli-ConnectSync();
SyncPop3Cli-UserSync();
SyncPop3Cli-PassSync();
SyncPop3Cli-StatSync();
SyncPop3Cli-QuitSync();

// Here you should have +OK goodbye or whatever in LastResponse

MessageBox(NULL,(LastResponse:+SyncPop3Cli-LastResponse+\r\nLastError:+
SyncPop3Cli-ErrorMessage).c_str(), Info, MB_OK);

SyncPop3Cli-ClearErrorMessage();
//SyncPop3Cli-LastResponse = ; // What should be done

SyncPop3Cli-Host = www.google.com;   // Simulate bad server
SyncPop3Cli-Port   = 81;   // Behind firewall
SyncPop3Cli-UserName = a;
SyncPop3Cli-PassWord = b;
SyncPop3Cli-ConnectSync();

// +OK goodbye from last connection is still here

MessageBox(NULL,(LastResponse:+SyncPop3Cli-LastResponse+\r\nLastError:+
SyncPop3Cli-ErrorMessage).c_str(), Info, MB_OK);


//--


 So what about a numeric property LastErrorNumber?

There is no such property nowhere in pop3 (or in any ICS file).


 something, worth to be tested anyway:
 [...]

I'll take a look and test this code soon enough. Thanks.
--
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