IdAuthenticationManager.pas 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. //
  63. procedure InitComponent; override;
  64. public
  65. destructor Destroy; override;
  66. procedure AddAuthentication(AAuthentication: TIdAuthentication; AURL: TIdURI);
  67. property Authentications: TIdAuthenticationCollection read FAuthentications;
  68. end;
  69. implementation
  70. uses
  71. IdGlobal, SysUtils;
  72. { TIdAuthenticationManager }
  73. function TIdAuthenticationCollection.Add: TIdAuthenticationItem;
  74. begin
  75. Result := TIdAuthenticationItem(inherited Add);
  76. end;
  77. constructor TIdAuthenticationCollection.Create(AOwner: TPersistent);
  78. begin
  79. inherited Create(AOwner, TIdAuthenticationItem);
  80. end;
  81. function TIdAuthenticationCollection.GetAuthItem(AIndex: Integer): TIdAuthenticationItem;
  82. begin
  83. Result := TIdAuthenticationItem(inherited GetItem(AIndex));
  84. end;
  85. procedure TIdAuthenticationCollection.SetAuthItem(AIndex: Integer;
  86. const Value: TIdAuthenticationItem);
  87. begin
  88. inherited SetItem(AIndex, Value);
  89. end;
  90. { TIdAuthenticationManager }
  91. procedure TIdAuthenticationManager.AddAuthentication(
  92. AAuthentication: TIdAuthentication; AURL: TIdURI);
  93. var
  94. LItem: TIdAuthenticationItem;
  95. begin
  96. LItem := Authentications.Add;
  97. LItem.URL.URI := AURL.URI;
  98. LItem.Params.Assign(AAuthentication.Params);
  99. end;
  100. destructor TIdAuthenticationManager.Destroy;
  101. begin
  102. FreeAndNil(FAuthentications);
  103. inherited Destroy;
  104. end;
  105. procedure TIdAuthenticationManager.InitComponent;
  106. begin
  107. inherited InitComponent;
  108. FAuthentications := TIdAuthenticationCollection.Create(Self);
  109. end;
  110. { TIdAuthenticationItem }
  111. constructor TIdAuthenticationItem.Create(ACollection: TCollection);
  112. begin
  113. inherited Create(ACollection);
  114. FURI := TIdURI.Create;
  115. FParams := TStringList.Create;
  116. end;
  117. destructor TIdAuthenticationItem.Destroy;
  118. begin
  119. FreeAndNil(FURI);
  120. FreeAndNil(FParams);
  121. inherited Destroy;
  122. end;
  123. procedure TIdAuthenticationItem.Assign(Source: TPersistent);
  124. var
  125. LSource: TIdAuthenticationItem;
  126. begin
  127. if Source is TIdAuthenticationItem then begin
  128. LSource := TIdAuthenticationItem(Source);
  129. URL.URI := LSource.URL.URI;
  130. Params.Assign(LSource.Params);
  131. end else begin
  132. inherited Assign(Source);
  133. end;
  134. end;
  135. procedure TIdAuthenticationItem.SetParams(const Value: TStrings);
  136. begin
  137. FParams.Assign(Value);
  138. end;
  139. procedure TIdAuthenticationItem.SetURI(const Value: TIdURI);
  140. begin
  141. FURI.URI := Value.URI;
  142. end;
  143. end.