Einzelnen Beitrag anzeigen

eyeless

Registriert seit: 12. Aug 2005
49 Beiträge
 
#14

Re: FTP URL in Bestandteile splitten

  Alt 23. Aug 2005, 23:01
mein vorschlag: (funzt mit emails im user und pass)

Delphi-Quellcode:
type
  TMyURL = record
   url, protocol, user, pass, host, port, path, filename : String;
  end;

function CrackUrl(url : String; var res : TMyURL):boolean;
var
  atpos, tmppos : integer;
  hp, rest : string;
begin
try
 tmppos := 0;
 res.url := url;
 res.protocol := copy(url,0,pos('://',url)-1);
 url := copy(url,pos('://',url)+3,length(url));
 res.user := copy(url,0,pos(':',url)-1);
 url := copy(url,pos(':',url)+1,length(url));
 repeat
  atpos := tmppos;
  tmppos := PosEx('@',url,tmppos+1);
 until tmppos+atpos = atpos;
 res.pass := copy(url,0,atpos-1);
 url := copy(url,atpos+1,length(url));
 hp := copy(url,0,pos('/',url)-1);
 if pos(':',hp)=0 then
  begin
   res.host := hp;
   res.port := '21';
  end
 else
  begin
   res.host := copy(hp,0,pos(':',hp)-1);
   res.port := copy(hp,pos(':',hp)+1,length(hp));
  end;
 url := copy(url,pos('/',url),length(url));
 res.filename := fMain.GetFileName(url);
 if (res.filename = '') or (pos('.',res.filename)=0) then
  res.path := copy(url,0,length(url))
 else
  res.path := copy(url,0,pos(res.filename,url)-1);
 Result := true;
except
 Result := false;
end;
end;
GetFilename kopiert einfach nur den filename raus ...

das ganze könte man jez noch mehr absichern, indem man auch des letzte ':' und auch auf unglückliche '/' im user/pass prüft ...

mfg, eyeless
  Mit Zitat antworten Zitat