* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Author: François PIETTE
Description: TTnScript component add scripting capabilities to TTnEmulVT
EMail: francois.piette@ping.be http://www.rtfm.be/fpiette
francois.piette@rtfm.be
Creation: February 24th, 1998
Version: 1.00
WebSite: http://www.rtfm.be/fpiette/indexuk.htm
Support: Use the mailing list twsocket@rtfm.be See website for details.
Legal issues: Copyright (C) 1997 by François PIETTE
This software is provided 'as-is', without any express or
implied warranty. In no event will the author be held liable
for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it
and redistribute it freely, subject to the following
restrictions:
1. The origin of this software must not be misrepresented,
you must not claim that you wrote the original software.
If you use this software in a product, an acknowledgment
in the product documentation would be appreciated but is
not required.
2. Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
Quick Reference:
TTnScript is a descendent from TTnEmulVT. It does exactly what TTnEmulVT does
(Ansi terminal emulation) and add some scripting capabilities.
TTnScript follows the received data and search in the data stream for
given strings. When found, an event handler is called.
Strings to search are specified by calling AddEvent. Each string is identified
by an ID (an integer number) which must be unique.
You can remove a string using RemoveEvent, passing the ID you gave when
inserting the string in the list. You can remove all the strings with
RemoveAllEvents.
Each string to search for is associated with another string which will be sent
by the component when the search string is found. This can be used for example
when you search for a login prompt ('login') to send the username when this
prompt is found. Same for password.
Each string to search for is also associated with an event handler which will
be triggered when the string is found, right after having sent the string to
send. This specific event can be used to customize what has to be done when
the string is found (for example update the user interface or query the user
for some value to send).
Finally, each string to search is associated with a set of flags which tells
the component some special actions such as ignoring character case when
comparing text, or make the string persistant (normaly when a string has been
found, it is removed from the list).
Strings are searched in the order they are added to the list. So it can be
very different if you add 'login' and 'password' to search for than if you
add 'login' only and then when 'login' is found, add 'password'.
To scan the data stream, the component use a circular buffer whose dimension
is 80 characters by default. You can change that by assigning InputBufferSize.
The buffer size should be at least twice the size of the longest string to
search. If you use an oversized buffer, you have a performance penalty because
the buffer is searched as each data packet comes into the stream.
An automatic login procedure could looks like this:
TnScript1.AddEvent(1, 'login', 'root' + #13#10, [efIgnoreCase], nil);
TnScript1.AddEvent(2, 'password', 'boss' + #13#10, [efIgnoreCase], nil);
TnScript1.Connect;
The nil argument could be replaced by a procedure (event handler) to make some
computing when the string to search for is found. Here is an example:
TnScript1.AddEvent(2, 'prompt', '', [efIgnoreCase], PromptEvent);
procedure TForm1.PromptEvent(Sender : TObject; ID : Integer);
begin
.... Your code goes here. You can do everithing ....
Label1.Caption := 'Logged !';
TnScript1.SendStr('ls -l' + #13 + #10); Like sending some data
end;
Updates:
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * TTnScript -
Register - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
PEventDescriptor
TDisplayEvent
TEventDescriptor
TEventFlag
TEventFlags
TEventHandler
TStringMatch
procedure Register;
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
PEventDescriptor = ^TEventDescriptor
TDisplayEvent = procedure (Sender : TObject; Msg : String) of object
TEventDescriptor = record
ID : Integer;
Search : String;
ToSend : String;
Flags : TEventFlags;
Handler : TEventHandler;
end;
TEventFlag = (efIgnoreCase, { Ignore case in comparaisons }
efPersistent);
TEventFlags = set of TEventFlag
Do not delete event when found
TEventHandler = procedure (Sender : TObject; ID : Integer) of object
TStringMatch = procedure (Sender : TObject; ID : Integer) of object