home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 October / Chip_2001-10_cd1.bin / zkuste / delphi / nastroje / d3456 / KBMWABD.ZIP / WABD_Request.pas < prev    next >
Pascal/Delphi Source File  |  2001-07-12  |  4KB  |  161 lines

  1. unit WABD_Request;
  2.  
  3. interface
  4.  
  5. uses classes,sysutils,WABD_Cookies,WABD_Utils;
  6.  
  7. const
  8.    WABD_REQUESTTYPE_UNKNOWN=0;
  9.    WABD_REQUESTTYPE_HTML=1;
  10.    WABD_REQUESTTYPE_WML=30;
  11.  
  12. type
  13.    TWABD_ListAdder = procedure(AList:TObject; Value:string) of object;
  14.  
  15.    TWABD_CustomRequest = class
  16.    protected
  17.       FLocalFilePath:string;
  18.       FHeaders : TStringList;
  19.       FQuery   : TStringList;
  20.       FRequest : TStringList;
  21.       FCookies : TWABD_Cookies;
  22.       FSize    : integer;
  23.       FDLLName : string;
  24.       FContentType:string;
  25.       FAuth    : string;
  26.       FRemoteHost : string;
  27.       FRemoteAddr : string;
  28.       FRemoteUser : string;
  29.       FUserName : string;
  30.       FPassword : string;
  31.       FBrowser    : integer;
  32.       FBrowserVersion : double;
  33.       FRequestType : integer;
  34.  
  35.       procedure Parse; virtual; abstract;
  36.  
  37.    public
  38.       constructor Create;
  39.       destructor Destroy; override;
  40.  
  41.       procedure DetermineBrowser; virtual;
  42.       procedure DetermineRequestType; virtual;
  43.       
  44.       property LocalFilePath:string read FLocalFilePath write FLocalFilePath;
  45.       property Headers:TStringList read FHeaders;
  46.       property Query:TStringList read FQuery;
  47.       property Request:TStringList read FRequest;
  48.       property Cookies:TWABD_Cookies read FCookies;
  49.       property DLLName:string read FDLLName;
  50.       property ContentType:string read FContentType;
  51.       property Size:integer read FSize;
  52.       property Auth:string read FAuth;
  53.       property RemoteUser:string read FRemoteUser;
  54.       property RemoteAddr:string read FRemoteAddr;
  55.       property RemoteHost:string read FRemoteHost;
  56.       property UserName:string read FUserName write FUserName;
  57.       property Password:string read FPassword write FPassword;
  58.       property Browser:integer read FBrowser;
  59.       property BrowserVersion:double read FBrowserVersion;
  60.       property RequestType:integer read FRequestType;
  61.    end;
  62.  
  63. var
  64.    WABD_DefaultRequestLocalFilePath:string;
  65.  
  66.  
  67. implementation
  68.  
  69. constructor TWABD_CustomRequest.Create;
  70. begin
  71.      inherited;
  72.      FHeaders:=TStringList.Create;
  73.      FQuery:=TStringList.Create;
  74.      FRequest:=TStringList.Create;
  75.      FCookies:=TWABD_Cookies.Create(TWABD_Cookie);
  76.      FLocalFilePath:=WABD_DefaultRequestLocalFilePath;
  77.  
  78.      // Default we dont know Jack sh.. about what browser the user has.
  79.      FBrowser:=WABD_BrowserUnknown;
  80.      FBrowserVersion:=-1.0;
  81. end;
  82.  
  83. destructor TWABD_CustomRequest.Destroy;
  84. begin
  85.      FHeaders.Free;
  86.      FQuery.Free;
  87.      FRequest.Free;
  88.      FCookies.Free;
  89.      inherited;
  90. end;
  91.  
  92. // Figure out browser from headerinfo.
  93. procedure TWABD_CustomRequest.DetermineBrowser;
  94. var
  95.    i:integer;
  96.    s,v:string;
  97.    p1,p2,p3:integer;
  98. begin
  99.      s:=UpperCase(FHeaders.Text);
  100.  
  101.      FBrowser:=WABD_BrowserUnknown;
  102.  
  103.      // Look for MSIE.
  104.      p1:=pos('MSIE',s);
  105.      if p1>0 then FBrowser:=WABD_BrowserIExplorer
  106.      else
  107.      begin
  108.           p1:=pos('MOZILLA',s);
  109.           if p1>0 then FBrowser:=WABD_BrowserNetscape;
  110.      end;
  111.  
  112.      // Not found browsertype?
  113.      if p1<=1 then exit;
  114.  
  115.      // Look for version number start.
  116.      p2:=-1;
  117.      for i:=p1 to length(s) do
  118.          if (s[i]<'A') or (s[i]>'Z') then
  119.          begin
  120.               p2:=i+1;
  121.               break;
  122.          end;
  123.      if p2<=0 then exit;
  124.  
  125.      // Look for version number end. V.V
  126.      p3:=length(s)+1;
  127.      for i:=p2 to length(s) do
  128.          if ((s[i]<'0') or (s[i]>'9')) and (s[i]<>'.') then
  129.          begin
  130.               p3:=i;
  131.               break;
  132.          end;
  133.      v:=copy(s,p2,p3-p2);
  134.      p2:=pos('.',v);
  135.      if p2>0 then v[p2]:=DecimalSeparator;
  136.      try
  137.         FBrowserVersion:=strtofloat(v);
  138.      except
  139.      end;
  140. end;
  141.  
  142. // Figure what type of request.
  143. procedure TWABD_CustomRequest.DetermineRequestType;
  144. var
  145.    s:string;
  146. begin
  147.      s:=LowerCase(FHeaders.Values['ACCEPT']);
  148.      FRequestType:=WABD_REQUESTTYPE_UNKNOWN;
  149.      if (pos('application/vnd.wap',s)>0) or (pos('text/vnd.wap.wml',s)>0) then
  150.         FRequestType:=WABD_REQUESTTYPE_WML
  151.      else
  152.         FRequestType:=WABD_REQUESTTYPE_HTML;
  153. end;
  154.  
  155. initialization
  156.    WABD_DefaultRequestLocalFilePath:='.\';
  157.  
  158. end.
  159.  
  160.  
  161.