Pogledajte određenu poruku
Staro 13. 09. 2007.   #1
Pedja
Predrag Supurović
Grand Master
 
Datum učlanjenja: 24.01.2006
Lokacija: Užice
Poruke: 791
Hvala: 3
200 "Hvala" u 12 poruka
Pedja is on a distinguished roadPedja is on a distinguished roadPedja is on a distinguished road
Default CGI apliakcija u Delphi-ju

Da li je neko radio u Delphiju neku VGI aplikaciju? Imam problem koji nije vezan samo sa CGI.

Naime, kada konzolnoj aplikaciji posaljem sadrzaj preo DOS redirekcije (to je isti princip kako se CGI-ju prosledjuju podaci od web servera), izgleda da Delphi ima probem ako je sadrzaj binaran - cita sadrzaj donekle i onda se zbuni.

U mom primeru, kad nadije karakter $1A, Delphi posle njega cita sve bajtove kao da imaju vrednost $1A iako to nije tacno.

Ovo mi paviproblem kada imam fileupload koji se prosledjuje CGI-ju napravljenom u Delphiju. Ako se pojavi neki problematican karakter, komunikacija puca, ili sadrzaj bude neispravno procitan.

Evo test koda koji ne radikako treba:

Kôd:
program cgitest;
{$APPTYPE CONSOLE}
uses
  SysUtils, Windows;

var
  Buf: PChar;
  BufSize: Integer;
  BufValue : string;
  Code : Integer;
  ContentLength : integer;
  i : integer;
  inchar : char;
  InLimit : Integer;


function GetEnvVarValue(const VarName: string): string;
var
  BufSize: Integer;  // buffer size required for value
begin
  // Get required buffer size (inc. terminal #0)
  BufSize := GetEnvironmentVariable(PChar(VarName), nil, 0);
  if BufSize > 0 then
  begin
    // Read env var value into result string
    SetLength(Result, BufSize - 1);
    GetEnvironmentVariable(PChar(VarName),
      PChar(Result), BufSize);
  end
  else
    // No such environment variable
    Result := '';
end;

begin

  // set this to any value greater than zero to limit number of characters read
  // from input stream. If server stalls on upload, limit this to 1 character
  // and then increase until it stalls again that way you wil find exact byte
  // which makes server to stall.
  InLimit := 0;

  WriteLn('Content-Type: text/html');
  WriteLn;

  WriteLn ('<html>');
  WriteLn ('<body>');
  BufValue := GetEnvVarValue ('CONTENT_LENGTH');
  Writeln (BufValue);

  Val (BufValue, ContentLength, Code);


  if ((inLimit >0) and (InLimit < ContentLength)) then
    ContentLength := InLimit;

  WriteLn ('<h1>CGI-TEST</h1>');

  WriteLn ('<p>Content length:' + BufValue + '</p>');
  if (inLimit > 0) then
    WriteLn ('<p>Forced read limit: ' +   IntToStr (ContentLength) + '</p>');

  WriteLn ('</p>');

  WriteLn ('<pre>');
  for i :=1 to ContentLength do begin
     read(input, inchar);
//     Write (IntToHex (Ord (inchar), 2));
     Write (inchar);
  end;
  WriteLn ('</pre>');

  WriteLn ('</body>');
  WriteLn ('</html>');
end.
Da bi citao podatke, u DOS promenljivi CONTENT_LENGTH mora bitiupisana tacna duzina podatakaposlatih redirekcijom. Ako je ovo pokrenuto kao CGI, taj podatak obezbedjuje sam web server.

Postoji li jos neki nacin da se iz Delphija procitaju podciposlati na standardni ulaz, redirekcijom? Prekopah ceo Internet i nigde nisam nasao da se ovaj problem uopste pominje.
Pedja je offline   Odgovorite uz citat