|
|||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||
![]() |
|
State MachineMachine for controle of states and environment of web-serverDownload (ftp://ftp.itk.ru/pub/sm)1. Brief description.
Actually, SM realizes the last variant, but does it in a way which is"clear" to the application. In other words, cgi application sees no control SM directives. It's seen from its name, that SM is intended for controlling states of the application. State implies a set of cgi process environment vaiables, which is associated with its name (by run) and arguments. SM is located between web-server and cgi program, and it directs server stream and environment variable to the program and filtrates output stream of cgi program (only for Content-type: text/html). In case of detecting directive variables (forSM), SM executes certain actions on controlling states (saving and subsequent recovery, generation of new states, and return to parent ones), and also replace a part of URL in output stream, modifying them for further use. Thus, SM forms a tree of states, which, in fact, create an integral application of separate cgi programs. Now, SM has been realized in a form of two programs -
smconn and sm. Web server always calls smconn and
gives it the rest of the path.
For example, application input point can be in the form:
In its turn, smconn is connected via Unix-domain-socket, "at the other end" of which sm proper is "located". In case of a call detected, sm runs sepatate thread for serving this call, and then necessary cgi program is started in sm. Thus, at least two processes are started for processing of each call: smconn and cgi program proper. Although smconn is quite small and practically doesn't consumes system resourses, its run can be avoided, if module to web-server, performing its functions, is used. As it's seen, the given scheme isn't quite simple, and the question arises: why couldn't SM function be realized directly in module of web- server? Unfortunately, in it's impossible. In its semantics, a SINGLE sm must process ALL calls to a specific application. Standard web-servers - for example, apache - create a set of copies of themselves to optimize processing calls, and, though this process can be controled within some limits, there's no full control. The first version of SM was based on of knon protocol - FastCGI, but it turned out, that "reproduction" of server processes "reproducts" executors, which is inadmissible. Besides, FastCGI realization (free), that we have, has proved to be rather complex and unstable... 2. Control directives SM. All control directives recognized by SM are described in a form of
HTML tags, or rather in a form of HTML-comments. This, to some extent, makes
SM extension easier - unrecognized directives will not litter user interface.
2.1. Call directive call.Syntacs:<!#call program="progname" [return="retname"] [prefix="url_prefix"] [src="url_src"]> or <!#fcall program="progname" [return="retname"] [prefix="url_prefix"]> When used out of forms, call tag is replaced for
For example, if in input stream there's:
and, with the activation of this reference,SM activates corresponding state as a child state in relation to current one and will run help.sh program c with the argument of main_context command line. It should be noted that standard semantics of cgi-calls doesn't allow to transfer command line arguments, and this is quite inconvenient sometimes. Return attribute defines the name of environment variable in which the result will put (see <!#return>). If prefix attribute is, its value is added before href value. Sometimes this is necessary for manual control of states - to replace, for example, a current (relative to webserver) directory, or to change acess or recoding rights. When used in forms, <!#call ...>directive is replaced for <input type=submit ...> or, if src attrbute has been transferred, for <input type=image ...>, url_srcattribute is source URL of image. For example, or, with use of src: src attribute <input type=image ...>tag takes the valie of imagedir attribute of SM cinfiguration file plus плюс the value of src attribute of <!#call ...> control directive. imagedir directive of SMconfiguration file (sm.cfg) in this
example takes /images/imailvalue.
See also <!#form> and directives of SMconfiguration
file (sm.cfg)
imagedir
Directive is used in JavaScriptprograms to create states.
return in input stream is replaced for a reference returning to parent
state; for example, if the parent state has number 1234, then
<!#return>back</a> return attribute sets the value returned in parent state.
This value will be assigned to environment variable indicated in
calldirective.
If hrefattribute is set, its value is added (after # )
to resulting URL (i.e. as a reference inside a page).
queryvalue is added to resulting URL after "?".
prefix is used in the same may as in <!
#call ...>. With the return to any state, all child states are destroyed automatically.
Any newly created state is automatiacally assigned with a unique name.
file.sh Program executed underSM can determine for itself (and for child states) environment variables and assign variables to them. Variables can have localvisibility scope - public, private and global, and they are created by control directive in the form of :
<!#local name1=value1 ... nameN=valueN> local variables belong only to the state in which they have been created. private variables belong to the state in which they have been created, but are transferred to child states. A child state can change privatevariable of a partent, as private will create a new variable shadowing a parent variable. public variables are inherited by child states. Thus, if the child state assigns a value to public variable, then publicparent variable changes as well. global are publicvariables belongning to the highest (root)
state. If several variables have one and the same name, the priory is given to
local, then to private and to public. Remark: environment variables common to the whole application may be можно
determined by envar directive of SMconfiguration file sm.cfg.
<!#form ... > understands the same attributes as
<form>standard tag does.
<input type=submit ...> и <input type=image ...>.
Directives understand attributes which are standard for
<img>tag. In output stream we have: It sets timeout_sec period in seconds, upon the expiry of which
SM state is destroyed.
It clears QUERY_STRINGenvironment varoable.
It determines processing method of hrefattribute of <A> tag.
If strict=off|no is a method by default, then in output stream:
programattribute determines cgi print program.
It is replaced for hyperreference tag and requires a closing tag. on allows output for printing, and off prohibits this.
It destroys all SM states and, after the complition, executes
cgi-program with quitname.
It sets the level of output of massages to log-file.
It sets a string used for indicating call end during dialog with servers. It sets file name in which pid of SM It sets log-file name. Its contents are dependent of
debugleveldirective. Also, this file has all
information about errors SM, start and stop of state machine.
executable-name program processes calls sent by SM
cgi-programs.
It sets an environment variable common to the whole application. It determines names - executable-name-1[ ...executable-name-N] - as
allowed points of entrance into application. HTTP string of response header.
Working directory of cgi-programs It sets maximal quantity of open file descriptors. If their quantity
exceeds number, this doesn't allow to open new ones.
It sets minuts time in minutes after the expiry of which SM
state is destroyed. This value is taken by default, if resource URL contains
no href=#expire>expire control directive.
It sets path for massage files.
SM checks browser preferences - current browse language - and, using
message file, replaces all strings enclosed in _(message text)_ for strings
corresponding to established browse language.
For example, if in cgi-program there is
_(Press any key to continue...)_
then in output stream, depending on settings, there will be
en
Press any key to continue...
ru
Для продолжения работы нажмите любую клавишу...
It sets a directory for images. |
© Engineering & Technical company LTD
(E&T co. LTD) 2006 426072, Udmurtia, Izhevsk p/b 1247, uri at itk dot ru | ![]() |
---|