10-27-2024, 08:27 PM
My Client is failing to logon to my server now and I think this is an upgrade woe (I'm using 10.6.3.3)
The client sends a string command like this: logon¦<username>¦password
After being stumped as to it not working anymore, I ended up doing a debug and seeing that the clients TCP thread is sending it but the server isn't happy - and sends back a 400 quoting it with ? instead of ¦
So I went and debugged the server and the TIdCmdTCPServer.DoExecute function is reading it in as: logon?<username>?password
Clearly this is not what was sent however ¦ is turning into ?
In IdGlobal there is this function that the client calls when calling WriteLn():
As you can see the bytes 166 are transformed into bytes 63. This never used to happen. Why does it happen now?
This seems to be triggered here:
Any ideas please?
Thanks
The client sends a string command like this: logon¦<username>¦password
After being stumped as to it not working anymore, I ended up doing a debug and seeing that the clients TCP thread is sending it but the server isn't happy - and sends back a 400 quoting it with ? instead of ¦
So I went and debugged the server and the TIdCmdTCPServer.DoExecute function is reading it in as: logon?<username>?password
Clearly this is not what was sent however ¦ is turning into ?
In IdGlobal there is this function that the client calls when calling WriteLn():
Code:
function ToBytes(const AValue: string; const ALength: Integer; const AIndex: Integer = 1;
ADestEncoding: IIdTextEncoding = nil
{$IFDEF STRING_IS_ANSI}; ASrcEncoding: IIdTextEncoding = nil{$ENDIF}
): TIdBytes; overload;
var
LLength: Integer;
{$IFDEF STRING_IS_ANSI}
LBytes: TIdBytes;
{$ENDIF}
begin
{$IFDEF STRING_IS_ANSI}
LBytes := nil; // keep the compiler happy
{$ENDIF}
LLength := IndyLength(AValue, ALength, AIndex);
if LLength > 0 then
begin
EnsureEncoding(ADestEncoding);
{$IFDEF STRING_IS_UNICODE}
SetLength(Result, ADestEncoding.GetByteCount(AValue, AIndex, LLength));
if Length(Result) > 0 then begin
ADestEncoding.GetBytes(AValue, AIndex, LLength, Result, 0);
end;
{$ELSE}
EnsureEncoding(ASrcEncoding, encOSDefault);
LBytes := RawToBytes(AValue[AIndex], LLength);
//LBytes is: (76, 111, 103, 111, 110, 166, 83, 97, 102, 102, 108, 101, 115, 166, 104, 111, 114, 97, 99, 101, 13, 10)
CheckByteEncoding(LBytes, ASrcEncoding, ADestEncoding);
//LBytes is: (76, 111, 103, 111, 110, 63, 83, 97, 102, 102, 108, 101, 115, 63, 104, 111, 114, 97, 99, 101, 13, 10)
Result := LBytes;
{$ENDIF}
end else begin
SetLength(Result, 0);
end;
end;
As you can see the bytes 166 are transformed into bytes 63. This never used to happen. Why does it happen now?
This seems to be triggered here:
Code:
function TIdASCIIEncoding.GetBytes(const AChars: PIdWideChar; ACharCount: Integer;
ABytes: PByte; AByteCount: Integer): Integer;
var
P: PIdWideChar;
i : Integer;
begin
// TODO: decode UTF-16 surrogates...
P := AChars;
Result := IndyMin(ACharCount, AByteCount);
for i := 1 to Result do begin
// replace illegal characters > $7F
if UInt16(P^) > $007F then begin
//This next line seems to do it
ABytes^ := Byte(Ord('?'));
end else begin
ABytes^ := Byte(P^);
end;
//advance to next char
Inc(P);
Inc(ABytes);
end;
end;
Any ideas please?
Thanks