-
Notifications
You must be signed in to change notification settings - Fork 1
/
Trpcb.pas
1619 lines (1483 loc) · 57.9 KB
/
Trpcb.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{ **************************************************************
Package: XWB - Kernel RPCBroker
Date Created: Sept 18, 1997 (Version 1.1)
Site Name: Oakland, OI Field Office, Dept of Veteran Affairs
Developers: Danila Manapsal, Don Craven, Joel Ivey
Description: Contains TRPCBroker and related components.
Current Release: Version 1.1 Patch 40 (January 7, 2005))
*************************************************************** }
{**************************************************
This is the hierarchy of things:
TRPCBroker contains
TParams, which contains
array of TParamRecord each of which contains
TMult
v1.1*4 Silent Login changes (DCM) 10/22/98
1.1*6 Polling to support terminating arphaned server jobs. (P6)
== DPC 4/99
1.1*8 Check for Multi-Division users. (P8) - REM 7/13/99
1.1*13 More silent login code; deleted obsolete lines (DCM) 9/10/99 // p13
LAST UPDATED: 5/24/2001 // p13 JLI
1.1*31 Added new read only property BrokerVersion to TRPCBroker which
should contain the version number for the RPCBroker
(or SharedRPCBroker) in use.
**************************************************}
unit Trpcb;
interface
{$I IISBase.inc}
uses
{Delphi standard}
Classes, Controls, Dialogs, {DsgnIntf,} Forms, Graphics, Messages, SysUtils,
Windows, win32int,
extctrls, {P6}
{VA}
XWBut1, {RpcbEdtr,} MFunStr, Hash; //P14 -- pack split
const
NoMore: boolean = False;
MIN_RPCTIMELIMIT: integer = 30;
CURRENT_RPC_VERSION: String = 'XWB*1.1*40';
type
TParamType = (literal, reference, list, global, empty, stream, undefined); // 030107 JLI Modified for new message protocol
//P14 -- pack split -- Types moved from RpcbEdtr.pas.
TAccessVerifyCodes = string[255]; //to use TAccessVerifyCodesProperty editor use this type
TRemoteProc = string[100]; //to use TRemoteProcProperty editor use this type
TServer = string[255]; //to use TServerProperty editor use this type
TRpcVersion = string[255]; //to use TRpcVersionProperty editor use this type
TRPCBroker = class;
TVistaLogin = class;
// p13
TLoginMode = (lmAVCodes, lmAppHandle, lmNTToken);
TShowErrorMsgs = (semRaise, semQuiet); // p13
TOnLoginFailure = procedure (VistaLogin: TVistaLogin) of object; //p13
TOnRPCBFailure = procedure (RPCBroker: TRPCBroker) of object; //p13
TOnPulseError = procedure(RPCBroker: TRPCBroker; ErrorText: String) of object;
// TOnRPCCall = procedure (RPCBroker: TRPCBroker; SetNum: Integer; RemoteProcedure: TRemoteProc; CurrentContext: String; RpcVersion: TRpcVersion; Param: TParams; RPCTimeLimit: Integer; Results, Sec, App: PChar; DateTime: TDateTime) of object;
{------ EBrokerError ------}
EBrokerError = class(Exception)
public
Action: string;
Code: integer;
Mnemonic: string;
end;
{------ TString ------}
TString = class(TObject)
Str: string;
end;
{------ TMult ------}
{:This component defines the multiple field of a parameter. The multiple
field is used to pass string-subscripted array of data in a parameter.}
TMult = class(TComponent)
private
FMultiple: TStringList;
procedure ClearAll;
function GetCount: Word;
function GetFirst: string;
function GetLast: string;
function GetFMultiple(Index: string): string;
function GetSorted: boolean;
procedure SetFMultiple(Index: string; value: string);
procedure SetSorted(Value: boolean);
protected
public
constructor Create(AOwner: TComponent); override; {1.1T8}
destructor Destroy; override;
procedure Assign(Source: TPersistent); override;
function Order(const StartSubscript: string; Direction: integer): string;
function Position(const Subscript: string): longint;
function Subscript(const Position: longint): string;
property Count: Word read GetCount;
property First: string read GetFirst;
property Last: string read GetLast;
property MultArray[I: string]: string
read GetFMultiple write SetFMultiple; default;
property Sorted: boolean read GetSorted write SetSorted;
end;
{------ TParamRecord ------}
{:This component defines all the fields that comprise a parameter.}
TParamRecord = class(TComponent)
private
FMult: TMult;
FValue: string;
FPType: TParamType;
protected
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
property Value: string read FValue write FValue;
property PType: TParamType read FPType write FPType;
property Mult: TMult read FMult write FMult;
end;
{------ TParams ------}
{:This component is really a collection of parameters. Simple inclusion
of this component in the Broker component provides access to all of the
parameters that may be needed when calling a remote procedure.}
TParams = class(TComponent)
private
FParameters: TList;
function GetCount: Word;
function GetParameter(Index: integer): TParamRecord;
procedure SetParameter(Index: integer; Parameter: TParamRecord);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Assign(Source: TPersistent); override;
procedure Clear;
property Count: Word read GetCount;
property ParamArray[I: integer]: TParamRecord
read GetParameter write SetParameter; default;
end;
{------ TVistaLogin ------} //p13
TVistaLogin = class(TPersistent)
private
FLogInHandle : string;
FNTToken : string;
FAccessCode : string;
FVerifyCode : string;
FDivision : string;
FMode: TLoginMode;
FDivLst: TStrings;
FOnFailedLogin: TOnLoginFailure;
FMultiDivision : boolean;
FDUZ: string;
FErrorText : string;
FPromptDiv : boolean;
FIsProductionAccount: Boolean;
FDomainName: string;
procedure SetAccessCode(const Value: String);
procedure SetLogInHandle(const Value: String);
procedure SetNTToken(const Value: String);
procedure SetVerifyCode(const Value: String);
procedure SetDivision(const Value: String);
//procedure SetWorkstationIPAddress(const Value: String);
procedure SetMode(const Value: TLoginMode);
procedure SetMultiDivision(Value: Boolean);
procedure SetDuz(const Value: string);
procedure SetErrorText(const Value: string);
procedure SetPromptDiv(const Value: boolean);
protected
procedure FailedLogin(Sender: TObject); dynamic;
public
constructor Create(AOwner: TComponent); virtual;
destructor Destroy; override;
property LogInHandle: String read FLogInHandle write SetLogInHandle; //for use by a 2ndary DHCP login OR ESSO login
property NTToken: String read FNTToken write SetNTToken;
property DivList: TStrings read FDivLst;
property OnFailedLogin: TOnLoginFailure read FOnFailedLogin write FOnFailedLogin;
property MultiDivision: Boolean read FMultiDivision write SetMultiDivision;
property DUZ: string read FDUZ write SetDuz;
property ErrorText: string read FErrorText write SetErrorText;
property IsProductionAccount: Boolean read FIsProductionAccount write
FIsProductionAccount;
property DomainName: string read FDomainName write FDomainName;
published
property AccessCode: String read FAccessCode write SetAccessCode;
property VerifyCode: String read FVerifyCode write SetVerifyCode;
property Mode: TLoginMode read FMode write SetMode;
property Division: String read FDivision write SetDivision;
property PromptDivision: boolean read FPromptDiv write SetPromptDiv;
end;
{------ TVistaUser ------} //holds 'generic' user attributes {p13}
TVistaUser = class(TObject)
private
FDUZ: string;
FName: string;
FStandardName: string;
FDivision: String;
FVerifyCodeChngd: Boolean;
FTitle: string;
FServiceSection: string;
FLanguage: string;
FDtime: string;
FVpid: String;
procedure SetDivision(const Value: String);
procedure SetDUZ(const Value: String);
procedure SetName(const Value: String);
procedure SetVerifyCodeChngd(const Value: Boolean);
procedure SetStandardName(const Value: String);
procedure SetTitle(const Value: string);
procedure SetDTime(const Value: string);
procedure SetLanguage(const Value: string);
procedure SetServiceSection(const Value: string);
public
property DUZ: String read FDUZ write SetDUZ;
property Name: String read FName write SetName;
property StandardName: String read FStandardName write SetStandardName;
property Division: String read FDivision write SetDivision;
property VerifyCodeChngd: Boolean read FVerifyCodeChngd write SetVerifyCodeChngd;
property Title: string read FTitle write SetTitle;
property ServiceSection: string read FServiceSection write SetServiceSection;
property Language: string read FLanguage write SetLanguage;
property DTime: string read FDTime write SetDTime;
property Vpid: string read FVpid write FVpid;
end;
{------ TRPCBroker ------}
{:This component, when placed on a form, allows design-time and run-time
connection to the server by simply toggling the Connected property.
Once connected you can access server data.}
TRPCBroker = class(TComponent)
//private
private
FBrokerVersion: String;
FIsBackwardCompatibleConnection: Boolean;
FIsNewStyleConnection: Boolean;
FOldConnectionOnly: Boolean;
protected
FAccessVerifyCodes: TAccessVerifyCodes;
FClearParameters: Boolean;
FClearResults: Boolean;
FConnected: Boolean;
FConnecting: Boolean;
FCurrentContext: String;
FDebugMode: Boolean;
FListenerPort: integer;
FParams: TParams;
FResults: TStrings;
FRemoteProcedure: TRemoteProc;
FRpcVersion: TRpcVersion;
FServer: TServer;
FSocket: integer;
FRPCTimeLimit : integer; //for adjusting client RPC duration timeouts
FPulse : TTimer; //P6
FKernelLogIn : Boolean; //p13
FLogIn: TVistaLogIn; //p13
FUser: TVistaUser; //p13
FOnRPCBFailure: TOnRPCBFailure;
FShowErrorMsgs: TShowErrorMsgs;
FRPCBError: String;
FOnPulseError: TOnPulseError;
protected
procedure SetClearParameters(Value: Boolean); virtual;
procedure SetClearResults(Value: Boolean); virtual;
procedure SetConnected(Value: Boolean); virtual;
procedure SetResults(Value: TStrings); virtual;
procedure SetServer(Value: TServer); virtual;
procedure SetRPCTimeLimit(Value: integer); virtual; //Screen changes to timeout.
procedure DoPulseOnTimer(Sender: TObject); virtual; //p6
procedure SetKernelLogIn(const Value: Boolean); virtual;
// procedure SetLogIn(const Value: TVistaLogIn); virtual;
procedure SetUser(const Value: TVistaUser); virtual;
public
XWBWinsock: TObject;
property AccessVerifyCodes: TAccessVerifyCodes read FAccessVerifyCodes write FAccessVerifyCodes;
property Param: TParams read FParams write FParams;
property Socket: integer read FSocket;
property RPCTimeLimit : integer read FRPCTimeLimit write SetRPCTimeLimit;
destructor Destroy; override;
procedure Call; virtual;
procedure Loaded; override;
procedure lstCall(OutputBuffer: TStrings); virtual;
function pchCall: PChar; virtual;
function strCall: string; virtual;
function CreateContext(strContext: string): boolean; virtual;
property CurrentContext: String read FCurrentContext;
property User: TVistaUser read FUser write SetUser;
property OnRPCBFailure: TOnRPCBFailure read FOnRPCBFailure write FOnRPCBFailure;
property RPCBError: String read FRPCBError write FRPCBError;
property OnPulseError: TOnPulseError read FOnPulseError write FOnPulseError;
property BrokerVersion: String read FBrokerVersion;
property IsNewStyleConnection: Boolean read FIsNewStyleConnection;
published
constructor Create(AOwner: TComponent); override;
property ClearParameters: boolean read FClearParameters
write SetClearParameters;
property ClearResults: boolean read FClearResults write SetClearResults;
property Connected: boolean read FConnected write SetConnected;
property DebugMode: boolean read FDebugMode write FDebugMode default False;
property ListenerPort: integer read FListenerPort write FListenerPort;
property Results: TStrings read FResults write SetResults;
property RemoteProcedure: TRemoteProc read FRemoteProcedure
write FRemoteProcedure;
property RpcVersion: TRpcVersion read FRpcVersion write FRpcVersion;
property Server: TServer read FServer write SetServer;
property KernelLogIn: Boolean read FKernelLogIn write SetKernelLogIn;
property ShowErrorMsgs: TShowErrorMsgs read FShowErrorMsgs write FShowErrorMsgs default semRaise;
property LogIn: TVistaLogIn read FLogIn write FLogin; // SetLogIn;
property IsBackwardCompatibleConnection: Boolean read
FIsBackwardCompatibleConnection write FIsBackwardCompatibleConnection
default True;
property OldConnectionOnly: Boolean read FOldConnectionOnly write
FOldConnectionOnly;
end;
{procedure Register;} //P14 --pack split
procedure StoreConnection(Broker: TRPCBroker);
function RemoveConnection(Broker: TRPCBroker): boolean;
function DisconnectAll(Server: string; ListenerPort: integer): boolean;
function ExistingSocket(Broker: TRPCBroker): integer;
procedure AuthenticateUser(ConnectingBroker: TRPCBroker);
procedure GetBrokerInfo(ConnectedBroker : TRPCBroker); //P6
function NoSignOnNeeded : Boolean;
function ProcessExecute(Command: string; cShow: Word): Integer;
function GetAppHandle(ConnectedBroker : TRPCBroker): String;
function ShowApplicationAndFocusOK(anApplication: TApplication): boolean;
var
DebugData: string;
BrokerConnections: TStringList; {this list stores all connections by socket number}
BrokerAllConnections: TStringList; {this list stores all connections to all of
the servers, by an application. It's used in DisconnectAll}
implementation
uses
Loginfrm, RpcbErr, SelDiv{p8}, RpcSLogin{p13}, fRPCBErrMsg, Wsockc;
const
DEFAULT_PULSE : integer = 81000; //P6 default = 45% of 3 minutes.
MINIMUM_TIMEOUT : integer = 14; //P6 shortest allowable timeout in secs.
PULSE_PERCENTAGE : integer = 45; //P6 % of timeout for pulse frequency.
{-------------------------- TMult.Create --------------------------
------------------------------------------------------------------}
constructor TMult.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FMultiple := TStringList.Create;
end;
{------------------------- TMult.Destroy --------------------------
------------------------------------------------------------------}
destructor TMult.Destroy;
begin
ClearAll;
FMultiple.Free;
FMultiple := nil;
inherited Destroy;
end;
{-------------------------- TMult.Assign --------------------------
All of the items from source object are copied one by one into the
target. So if the source is later destroyed, target object will continue
to hold the copy of all elements, completely unaffected.
------------------------------------------------------------------}
procedure TMult.Assign(Source: TPersistent);
var
I: integer;
SourceStrings: TStrings;
S: TString;
SourceMult: TMult;
begin
ClearAll;
if Source is TMult then begin
SourceMult := Source as TMult;
try
for I := 0 to SourceMult.FMultiple.Count - 1 do begin
S := TString.Create;
S.Str := (SourceMult.FMultiple.Objects[I] as TString).Str;
Self.FMultiple.AddObject(SourceMult.FMultiple[I], S);
end;
except
end;
end
else begin
SourceStrings := Source as TStrings;
for I := 0 to SourceStrings.Count - 1 do
Self[IntToStr(I)] := SourceStrings[I];
end;
end;
{------------------------- TMult.ClearAll -------------------------
One by one, all Mult items are freed.
------------------------------------------------------------------}
procedure TMult.ClearAll;
var
I: integer;
begin
for I := 0 to FMultiple.Count - 1 do begin
FMultiple.Objects[I].Free;
FMultiple.Objects[I] := nil;
end;
FMultiple.Clear;
end;
{------------------------- TMult.GetCount -------------------------
Returns the number of elements in the multiple
------------------------------------------------------------------}
function TMult.GetCount: Word;
begin
Result := FMultiple.Count;
end;
{------------------------- TMult.GetFirst -------------------------
Returns the subscript of the first element in the multiple
------------------------------------------------------------------}
function TMult.GetFirst: string;
begin
if FMultiple.Count > 0 then Result := FMultiple[0]
else Result := '';
end;
{------------------------- TMult.GetLast --------------------------
Returns the subscript of the last element in the multiple
------------------------------------------------------------------}
function TMult.GetLast: string;
begin
if FMultiple.Count > 0 then Result := FMultiple[FMultiple.Count - 1]
else Result := '';
end;
{---------------------- TMult.GetFMultiple ------------------------
Returns the VALUE of the element whose subscript is passed.
------------------------------------------------------------------}
function TMult.GetFMultiple(Index: string): string;
var
S: TString;
BrokerComponent,ParamRecord: TComponent;
I: integer;
strError: string;
begin
try
S := TString(FMultiple.Objects[FMultiple.IndexOf(Index)]);
except
on EListError do begin
{build appropriate error message}
strError := iff(Self.Name <> '', Self.Name, 'TMult_instance');
strError := strError + '[' + Index + ']' + #13#10 + 'is undefined';
try
ParamRecord := Self.Owner;
BrokerComponent := Self.Owner.Owner.Owner;
if (ParamRecord is TParamRecord) and (BrokerComponent is TRPCBroker) then begin
I := 0;
{if there is an easier way to figure out which array element points
to this instance of a multiple, use it} // p13
while TRPCBroker(BrokerComponent).Param[I] <> ParamRecord do inc(I);
strError := '.Param[' + IntToStr(I) + '].' + strError;
strError := iff(BrokerComponent.Name <> '', BrokerComponent.Name,
'TRPCBroker_instance') + strError;
end;
except
end;
raise Exception.Create(strError);
end;
end;
Result := S.Str;
end;
{---------------------- TMult.SetGetSorted ------------------------
------------------------------------------------------------------}
function TMult.GetSorted: boolean;
begin
Result := FMultiple.Sorted;
end;
{---------------------- TMult.SetFMultiple ------------------------
Stores a new element in the multiple. FMultiple (TStringList) is the
structure, which is used to hold the subscript and value pair. Subscript
is stored as the String, value is stored as an object of the string.
------------------------------------------------------------------}
procedure TMult.SetFMultiple(Index: string; Value: string);
var
S: TString;
Pos: integer;
begin
Pos := FMultiple.IndexOf(Index); {see if this subscript already exists}
if Pos = -1 then begin {if subscript is new}
S := TString.Create; {create string object}
S.Str := Value; {put value in it}
FMultiple.AddObject(Index, S); {add it}
end
else
TString(FMultiple.Objects[Pos]).Str := Value; { otherwise replace the value}
end;
{---------------------- TMult.SetSorted ------------------------
------------------------------------------------------------------}
procedure TMult.SetSorted(Value: boolean);
begin
FMultiple.Sorted := Value;
end;
{-------------------------- TMult.Order --------------------------
Returns the subscript string of the next or previous element from the
StartSubscript. This is very similar to the $O function available in M.
Null string ('') is returned when reaching beyong the first or last
element, or when list is empty.
Note: A major difference between the M $O and this function is that
in this function StartSubscript must identify a valid subscript
in the list.
------------------------------------------------------------------}
function TMult.Order(const StartSubscript: string; Direction: integer): string;
var
Index: longint;
begin
Result := '';
if StartSubscript = '' then
if Direction > 0 then Result := First
else Result := Last
else begin
Index := Position(StartSubscript);
if Index > -1 then
if (Index < (Count - 1)) and (Direction > 0) then
Result := FMultiple[Index + 1]
else if (Index > 0) and (Direction < 0) then
Result := FMultiple[Index - 1];
end
end;
{------------------------- TMult.Position -------------------------
Returns the long integer value which is the index position of the
element in the list. Opposite of TMult.Subscript(). Remember that
the list is 0 based!
------------------------------------------------------------------}
function TMult.Position(const Subscript: string): longint;
begin
Result := FMultiple.IndexOf(Subscript);
end;
{------------------------ TMult.Subscript -------------------------
Returns the string subscript of the element whose position in the list
is passed in. Opposite of TMult.Position(). Remember that the list is 0 based!
------------------------------------------------------------------}
function TMult.Subscript(const Position: longint): string;
begin
Result := '';
if (Position > -1) and (Position < Count) then
Result := FMultiple[Position];
end;
{---------------------- TParamRecord.Create -----------------------
Creates TParamRecord instance and automatically creates TMult. The
name of Mult is also set in case it may be need if exception will be raised.
------------------------------------------------------------------}
constructor TParamRecord.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FMult := TMult.Create(Self);
FMult.Name := 'Mult';
{note: FMult is destroyed in the SetClearParameters method}
end;
destructor TParamRecord.Destroy;
begin
FMult.Free;
FMult := nil;
inherited;
end;
{------------------------- TParams.Create -------------------------
------------------------------------------------------------------}
constructor TParams.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FParameters := TList.Create; {for now, empty list}
end;
{------------------------ TParams.Destroy -------------------------
------------------------------------------------------------------}
destructor TParams.Destroy;
begin
Clear; {clear the Multiple first!}
FParameters.Free;
FParameters := nil;
inherited Destroy;
end;
{------------------------- TParams.Assign -------------------------
------------------------------------------------------------------}
procedure TParams.Assign(Source: TPersistent);
var
I: integer;
SourceParams: TParams;
begin
Self.Clear;
SourceParams := Source as TParams;
for I := 0 to SourceParams.Count - 1 do begin
Self[I].Value := SourceParams[I].Value;
Self[I].PType := SourceParams[I].PType;
Self[I].Mult.Assign(SourceParams[I].Mult);
end
end;
{------------------------- TParams.Clear --------------------------
------------------------------------------------------------------}
procedure TParams.Clear;
var
ParamRecord: TParamRecord;
I: integer;
begin
if FParameters <> nil then begin
for I := 0 to FParameters.Count - 1 do begin
ParamRecord := TParamRecord(FParameters.Items[I]);
if ParamRecord <> nil then begin //could be nil if params were skipped by developer
ParamRecord.FMult.Free;
ParamRecord.FMult := nil;
ParamRecord.Free;
end;
end;
FParameters.Clear; {release FParameters TList}
end;
end;
{------------------------ TParams.GetCount ------------------------
------------------------------------------------------------------}
function TParams.GetCount: Word;
begin
if FParameters = nil then Result := 0
else Result := FParameters.Count;
end;
{---------------------- TParams.GetParameter ----------------------
------------------------------------------------------------------}
function TParams.GetParameter(Index: integer): TParamRecord;
begin
if Index >= FParameters.Count then {if element out of bounds,}
while FParameters.Count <= Index do
FParameters.Add(nil); {setup place holders}
if FParameters.Items[Index] = nil then begin {if just a place holder,}
{point it to new memory block}
FParameters.Items[Index] := TParamRecord.Create(Self);
TParamRecord(FParameters.Items[Index]).PType := undefined; {initialize}
end;
Result := FParameters.Items[Index]; {return requested parameter}
end;
{---------------------- TParams.SetParameter ----------------------
------------------------------------------------------------------}
procedure TParams.SetParameter(Index: integer; Parameter: TParamRecord);
begin
if Index >= FParameters.Count then {if element out of bounds,}
while FParameters.Count <= Index do
FParameters.Add(nil); {setup place holders}
if FParameters.Items[Index] = nil then {if just a place holder,}
FParameters.Items[Index] := Parameter; {point it to passed parameter}
end;
{------------------------ TRPCBroker.Create -----------------------
------------------------------------------------------------------}
constructor TRPCBroker.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
{set defaults}
// This constant defined in the interface section needs to be updated for each release
FBrokerVersion := CURRENT_RPC_VERSION;
FClearParameters := boolean(StrToInt
(ReadRegDataDefault(HKLM,REG_BROKER,'ClearParameters','1')));
FClearResults := boolean(StrToInt
(ReadRegDataDefault(HKLM,REG_BROKER,'ClearResults','1')));
FDebugMode := False;
FParams := TParams.Create(Self);
FResults := TStringList.Create;
FServer := ReadRegDataDefault(HKLM,REG_BROKER,'Server','BROKERSERVER');
FPulse := TTimer.Create(Self); //P6
FListenerPort := StrToInt
(ReadRegDataDefault(HKLM,REG_BROKER,'ListenerPort','9200'));
FRpcVersion := '0';
FRPCTimeLimit := MIN_RPCTIMELIMIT;
with FPulse do ///P6
begin
Enabled := False; //P6
Interval := DEFAULT_PULSE; //P6
OnTimer := DoPulseOnTimer; //P6
end;
FLogin := TVistaLogin.Create(Self); //p13
FKernelLogin := True; //p13
FUser := TVistaUser.Create; //p13
FShowErrorMsgs := semRaise; //p13
XWBWinsock := TXWBWinsock.Create;
FIsBackwardCompatibleConnection := True; // default
Application.ProcessMessages;
end;
{----------------------- TRPCBroker.Destroy -----------------------
------------------------------------------------------------------}
destructor TRPCBroker.Destroy;
begin
Connected := False;
TXWBWinsock(XWBWinsock).Free;
FParams.Free;
FParams := nil;
FResults.Free;
FResults := nil;
FPulse.Free; //P6
FPulse := nil;
FUser.Free;
FUser := nil;
FLogin.Free;
FLogin := nil;
inherited Destroy;
end;
{--------------------- TRPCBroker.CreateContext -------------------
This function is part of the overall Broker security.
The passed context string is essentially a Client/Server type option
on the server. The server sets up MenuMan environment variables for this
context which will later be used to screen RPCs. Only those RPCs which are
in the multiple field of this context option will be permitted to run.
------------------------------------------------------------------}
function TRPCBroker.CreateContext(strContext: string): boolean;
var
InternalBroker: TRPCBroker; {use separate component}
Str: String;
begin
Result := False;
Connected := True;
InternalBroker := nil;
try
InternalBroker := TRPCBroker.Create(Self);
InternalBroker.FSocket := Self.Socket; // p13 -- permits multiple broker connections to same server/port
with InternalBroker do
begin
{
TXWBWinsock(InternalBroker.XWBWinsock).IsBackwardsCompatible := TXWBWinsock(Self.XWBWinsock).IsBackwardsCompatible;
TXWBWinsock(InternalBroker.XWBWinsock).OriginalConnectionOnly := TXWBWinsock(Self.XWBWinsock).OriginalConnectionOnly;
}
Tag := 1234;
ShowErrorMsgs := Self.ShowerrorMsgs;
Server := Self.Server; {inherit application server}
ListenerPort := Self.ListenerPort; {inherit listener port}
DebugMode := Self.DebugMode; {inherit debug mode property}
RemoteProcedure := 'XWB CREATE CONTEXT'; {set up RPC}
Param[0].PType := literal;
Param[0].Value := Encrypt(strContext);
try
Str := strCall;
if Str = '1' then
begin // make the call // p13
Result := True; // p13
self.FCurrentContext := strContext; // p13
end // p13
else
begin
Result := False;
self.FCurrentContext := '';
end;
except // Code added to return False if User doesn't have access
on e: EBrokerError do
begin
self.FCurrentContext := '';
if Pos('does not have access to option',e.Message) > 0 then
begin
Result := False
end
else
Raise;
end;
end;
if RPCBError <> '' then
self.RPCBError := RPCBError;
end;
finally
InternalBroker.XWBWinsock := nil;
InternalBroker.Free; {release memory}
end;
end;
{------------------------ TRPCBroker.Loaded -----------------------
------------------------------------------------------------------}
procedure TRPCBroker.Loaded;
begin
inherited Loaded;
end;
{------------------------- TRPCBroker.Call ------------------------
------------------------------------------------------------------}
procedure TRPCBroker.Call;
var
ResultBuffer: TStrings;
begin
ResultBuffer := TStringList.Create;
try
if ClearResults then ClearResults := True;
lstCall(ResultBuffer);
Self.Results.AddStrings(ResultBuffer);
finally
ResultBuffer.Clear;
ResultBuffer.Free;
end;
end;
{----------------------- TRPCBroker.lstCall -----------------------
------------------------------------------------------------------}
procedure TRPCBroker.lstCall(OutputBuffer: TStrings);
var
ManyStrings: PChar;
begin
ManyStrings := pchCall; {make the call}
OutputBuffer.SetText(ManyStrings); {parse result of call, format as list}
StrDispose(ManyStrings); {raw result no longer needed, get back mem}
end;
{----------------------- TRPCBroker.strCall -----------------------
------------------------------------------------------------------}
function TRPCBroker.strCall: string;
var
ResultString: PChar;
begin
ResultString := pchCall; {make the call}
Result := StrPas(ResultString); {convert and present as Pascal string}
StrDispose(ResultString); {raw result no longer needed, get back mem}
end;
{--------------------- TRPCBroker.SetConnected --------------------
------------------------------------------------------------------}
procedure TRPCBroker.SetConnected(Value: Boolean);
var
BrokerDir, Str1, Str2, Str3 :string;
begin
RPCBError := '';
Login.ErrorText := '';
if (Connected <> Value) and not(csReading in ComponentState) then begin
if Value and (FConnecting <> Value) then begin {connect}
FSocket := ExistingSocket(Self);
FConnecting := True; // FConnected := True;
try
if FSocket = 0 then
begin
{Execute Client Agent from directory in Registry.}
BrokerDir := ReadRegData(HKLM, REG_BROKER, 'BrokerDr');
if BrokerDir <> '' then
ProcessExecute(BrokerDir + '\ClAgent.Exe', sw_ShowNoActivate)
else
ProcessExecute('ClAgent.Exe', sw_ShowNoActivate);
if DebugMode and (not OldConnectionOnly) then
begin
Str1 := 'Control of debugging has been moved from the client to the server. To start a Debug session, do the following:'+#13#10#13#10;
Str2 := '1. On the server, set initial breakpoints where desired.'+#13#10+'2. DO DEBUG^XWBTCPM.'+#13#10+'3. Enter a unique Listener port number (i.e., a port number not in general use).'+#13#10;
Str3 := '4. Connect the client application using the port number entered in Step #3.';
ShowMessage(Str1 + Str2 + Str3);
end;
TXWBWinsock(XWBWinsock).IsBackwardsCompatible := FIsBackwardCompatibleConnection;
TXWBWinsock(XWBWinsock).OldConnectionOnly := FOldConnectionOnly;
FSocket := TXWBWinsock(XWBWinsock).NetworkConnect(DebugMode, FServer,
ListenerPort, FRPCTimeLimit);
AuthenticateUser(Self);
FPulse.Enabled := True; //P6 Start heartbeat.
StoreConnection(Self); //MUST store connection before CreateContext()
CreateContext(''); //Closes XUS SIGNON context.
end
else
begin //p13
StoreConnection(Self);
FPulse.Enabled := True; //p13
end; //p13
FConnected := True; // jli mod 12/17/01
FConnecting := False;
except
on E: EBrokerError do begin
if E.Code = XWB_BadSignOn then
TXWBWinsock(XWBWinsock).NetworkDisconnect(FSocket);
FSocket := 0;
FConnected := False;
FConnecting := False;
FRPCBError := E.Message; // p13 handle errors as specified
if Login.ErrorText <> '' then
FRPCBError := E.Message + chr(10) + Login.ErrorText;
if Assigned(FOnRPCBFailure) then // p13
FOnRPCBFailure(Self) // p13
else if ShowErrorMsgs = semRaise then
Raise; // p13
// raise; {this is where I would do OnNetError}
end{on};
end{try};
end{if}
else if not Value then
begin //p13
FConnected := False; //p13
FPulse.Enabled := False; //p13
if RemoveConnection(Self) = NoMore then begin
{FPulse.Enabled := False; ///P6;p13 }
TXWBWinsock(XWBWinsock).NetworkDisconnect(Socket); {actually disconnect from server}
FSocket := 0; {store internal}
//FConnected := False; //p13
end{if};
end; {else}
end{if};
end;
{----------------- TRPCBroker.SetClearParameters ------------------
------------------------------------------------------------------}
procedure TRPCBroker.SetClearParameters(Value: Boolean);
begin
if Value then FParams.Clear;
FClearParameters := Value;
end;
{------------------- TRPCBroker.SetClearResults -------------------
------------------------------------------------------------------}
procedure TRPCBroker.SetClearResults(Value: Boolean);
begin
if Value then begin {if True}
FResults.Clear;
end;
FClearResults := Value;
end;
{---------------------- TRPCBroker.SetResults ---------------------
------------------------------------------------------------------}
procedure TRPCBroker.SetResults(Value: TStrings);
begin
FResults.Assign(Value);
end;
{----------------------- TRPCBroker.SetRPCTimeLimit -----------------
------------------------------------------------------------------}
procedure TRPCBroker.SetRPCTimeLimit(Value: integer);
begin
if Value <> FRPCTimeLimit then
if Value > MIN_RPCTIMELIMIT then
FRPCTimeLimit := Value
else
FRPCTimeLimit := MIN_RPCTIMELIMIT;
end;
{----------------------- TRPCBroker.SetServer ---------------------
------------------------------------------------------------------}
procedure TRPCBroker.SetServer(Value: TServer);
begin
{if changing the name of the server, make sure to disconnect first}
if (Value <> FServer) and Connected then begin
Connected := False;
end;
FServer := Value;
end;
{--------------------- TRPCBroker.pchCall ----------------------
Lowest level remote procedure call that a TRPCBroker component can make.
1. Returns PChar.
2. Converts Remote Procedure to PChar internally.
------------------------------------------------------------------}
function TRPCBroker.pchCall: PChar;
var
Value, Sec, App: PChar;
BrokerError: EBrokerError;
blnRestartPulse : boolean; //P6
begin
RPCBError := '';
Connected := True;
BrokerError := nil;
Value := nil;
blnRestartPulse := False; //P6
Sec := StrAlloc(255);
App := StrAlloc(255);
try
if FPulse.Enabled then ///P6 If Broker was sending pulse,
begin
FPulse.Enabled := False; /// Stop pulse &
blnRestartPulse := True; // Set flag to restart pulse after RPC.
end;
{
if Assigned(FOnRPCCall) then
begin
FOnRPCCall(Self, 1, RemoteProcedure, CurrentContext, RpcVersion, Param, FRPCTimeLimit, '', '', '', Now);
end;
}
try