IdAuthenticationManager.pas 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. {
  2. $Project$
  3. $Workfile$
  4. $Revision$
  5. $DateUTC$
  6. $Id$
  7. This file is part of the Indy (Internet Direct) project, and is offered
  8. under the dual-licensing agreement described on the Indy website.
  9. (http://www.indyproject.org/)
  10. Copyright:
  11. (c) 1993-2005, Chad Z. Hower and the Indy Pit Crew. All rights reserved.
  12. }
  13. {
  14. $Log$
  15. }
  16. {
  17. Rev 1.4 10/26/2004 10:59:30 PM JPMugaas
  18. Updated ref.
  19. Rev 1.3 5/29/2004 10:02:20 AM DSiders
  20. Corrected case in Create parameter.
  21. Rev 1.2 2004.02.03 5:44:54 PM czhower
  22. Name changes
  23. Rev 1.1 2004.01.21 1:04:52 PM czhower
  24. InitComponenet
  25. Rev 1.0 11/14/2002 02:13:40 PM JPMugaas
  26. }
  27. unit IdAuthenticationManager;
  28. interface
  29. {$i IdCompilerDefines.inc}
  30. uses
  31. Classes,
  32. IdAuthentication,
  33. IdBaseComponent,
  34. IdURI;
  35. type
  36. TIdAuthenticationItem = class(TCollectionItem)
  37. protected
  38. FURI: TIdURI;
  39. FParams: TStrings;
  40. procedure SetParams(const Value: TStrings);
  41. procedure SetURI(const Value: TIdURI);
  42. public
  43. constructor Create(ACollection: TCollection); override;
  44. destructor Destroy; override;
  45. procedure Assign(Source: TPersistent); override;
  46. property URL: TIdURI read FURI write SetURI;
  47. property Params: TStrings read FParams write SetParams;
  48. end;
  49. TIdAuthenticationCollection = class(TOwnedCollection)
  50. protected
  51. function GetAuthItem(AIndex: Integer): TIdAuthenticationItem;
  52. procedure SetAuthItem(AIndex: Integer; const Value: TIdAuthenticationItem);
  53. public
  54. function Add: TIdAuthenticationItem;
  55. constructor Create(AOwner: TPersistent);
  56. //
  57. property Items[AIndex: Integer]: TIdAuthenticationItem read GetAuthItem write SetAuthItem;
  58. end;
  59. TIdAuthenticationManager = class(TIdBaseComponent)
  60. protected
  61. FAuthentications: TIdAuthenticationCollection;
  62. public
  63. constructor Create(AOwner: TComponent); override;
  64. destructor Destroy; override;
  65. procedure AddAuthentication(AAuthentication: TIdAuthentication; AURL: TIdURI);
  66. property Authentications: TIdAuthenticationCollection read FAuthentications;
  67. end;
  68. implementation
  69. uses
  70. IdGlobal, SysUtils;
  71. { TIdAuthenticationManager }
  72. function TIdAuthenticationCollection.Add: TIdAuthenticationItem;
  73. begin
  74. Result := TIdAuthenticationItem(inherited Add);
  75. end;
  76. constructor TIdAuthenticationCollection.Create(AOwner: TPersistent);
  77. begin
  78. inherited Create(AOwner, TIdAuthenticationItem);
  79. end;
  80. function TIdAuthenticationCollection.GetAuthItem(AIndex: Integer): TIdAuthenticationItem;
  81. begin
  82. Result := TIdAuthenticationItem(inherited GetItem(AIndex));
  83. end;
  84. procedure TIdAuthenticationCollection.SetAuthItem(AIndex: Integer;
  85. const Value: TIdAuthenticationItem);
  86. begin
  87. inherited SetItem(AIndex, Value);
  88. end;
  89. { TIdAuthenticationManager }
  90. procedure TIdAuthenticationManager.AddAuthentication(
  91. AAuthentication: TIdAuthentication; AURL: TIdURI);
  92. var
  93. LItem: TIdAuthenticationItem;
  94. begin
  95. LItem := Authentications.Add;
  96. LItem.URL.URI := AURL.URI;
  97. LItem.Params.Assign(AAuthentication.Params);
  98. end;
  99. constructor TIdAuthenticationManager.Create(AOwner: TComponent);
  100. begin
  101. inherited Create(AOwner);
  102. FAuthentications := TIdAuthenticationCollection.Create(Self);
  103. end;
  104. destructor TIdAuthenticationManager.Destroy;
  105. begin
  106. FAuthentications.Free;
  107. inherited Destroy;
  108. end;
  109. { TIdAuthenticationItem }
  110. constructor TIdAuthenticationItem.Create(ACollection: TCollection);
  111. begin
  112. inherited Create(ACollection);
  113. FURI := TIdURI.Create;
  114. FParams := TStringList.Create;
  115. end;
  116. destructor TIdAuthenticationItem.Destroy;
  117. begin
  118. FURI.Free;
  119. FParams.Free;
  120. inherited Destroy;
  121. end;
  122. procedure TIdAuthenticationItem.Assign(Source: TPersistent);
  123. var
  124. LSource: TIdAuthenticationItem;
  125. begin
  126. if Source is TIdAuthenticationItem then begin
  127. LSource := TIdAuthenticationItem(Source);
  128. URL.URI := LSource.URL.URI;
  129. Params.Assign(LSource.Params);
  130. end else begin
  131. inherited Assign(Source);
  132. end;
  133. end;
  134. procedure TIdAuthenticationItem.SetParams(const Value: TStrings);
  135. begin
  136. FParams.Assign(Value);
  137. end;
  138. procedure TIdAuthenticationItem.SetURI(const Value: TIdURI);
  139. begin
  140. FURI.URI := Value.URI;
  141. end;
  142. end.