Difference between revisions of "Ns register proc"

From AOLserver Wiki
Jump to navigation Jump to search
m (Reverted edits by HelenArchibald (Talk) to last revision by Umbrella13)
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
Man page: http://aolserver.com/man/4.0/tcl/ns_proc.html
+
{{manpage|ns_proc}}
 
 
----
 
  
 
'''NAME'''
 
'''NAME'''
  
:       ns_register_proc - Register a procedure for a method/URL combination
+
: ns_register_proc - Register a procedure for a method/URL combination
  
 
'''SYNOPSIS'''
 
'''SYNOPSIS'''
  
:       '''ns_register_proc''' ''?-noinherit?'' method URL myproc ''?args?''
+
: '''ns_register_proc''' ''?-noinherit? method URL myproc ?args?''
  
 
'''DESCRIPTION'''
 
'''DESCRIPTION'''
  
:             '''ns_register_proc''' registers the procname to handle
+
: '''ns_register_proc''' registers the procname to handle the specified method/URL combination.  When the server gets a matching request, it calls procname with the connection id and any arguments specified here.
:              the specified method/URL combination.  When the
 
:              server gets a matching request, it calls procname
 
:              with the connection id and any arguments specified
 
:              here.
 
 
 
:              If  ''-noinherit'' is specified, the requested URL must
 
:              match the specified URL exactly.  For  example,  if
 
:              the  URL  specified  with  '''ns_register_proc'''  is
 
:              /foo/bar, procname will not be  called  unless  the
 
:              requested URL is exactly /foo/bar.
 
  
:             If ''-noinherit'' is not specified, the requested URL
+
: If ''-noinherit'' is specified, the requested URL must match the specified URL exactly. For example, if the URL specified with '''ns_register_proc''' is /foo/bar, procname will not be called unless the requested URL is exactly /foo/bar.
:              can match the specified URL or any  URL  below it.
 
:              For example, if the URL specified with '''ns_register_proc'''  
 
:              is /foo/bar, procname will be called for
 
:              /foo/bar,  /foo/bar/hmm,  and  any  other URL below
 
:              /foo/bar, provided there  is  not  already  another
 
:              procedure  registered  for that exact URL or for an
 
:              URL with a closer match.
 
  
:             Note that you must use a glob-style matching character 
+
: If ''-noinherit'' is not specified, the requested URL can match the specified URL or any URL below it. For example, if the URL specified with '''ns_register_proc''' is /foo/bar, procname will be called for /foo/bar, /foo/bar/hmm, and any other URL below /foo/bar, provided there is not already another procedure registered for that exact URL or for an URL with a closer match.
:              if  you want inheritance for file names. For
 
:              example,   if   you  want  /foo/bar   to    match
 
:              /foo/bar.html,  you  must  use: 
 
  
                      ns_register_proc /foo/bar*
+
: Note that you must use a glob-style matching character if you want inheritance for file names.  For example, if you want /foo/bar to match /foo/bar.html, you must use:
  
:              You can  register  two  procedures  for  any  given
+
    ns_register_proc /foo/bar*
:              method/URL  combination by calling '''ns_register_proc'''
 
:              once with the ''-noinherit'' flag set and once  without
 
:              it.  Only  one of the procedures will be called for
 
:              any given request, depending on whether the URL was
 
:              an exact match or not. For example:
 
  
                    ns_register_proc -noinherit GET /foo/bar Aproc
+
: You can register two procedures for any given method/URL combination by calling '''ns_register_proc''' once with the ''-noinherit'' flag set and once without it.  Only one of the procedures will be called for any given request, depending on whether the URL was an exact match or not.  For example:
                    ns_register_proc GET /foo/bar Bproc
 
                    ns_register_proc GET /foo/bar/hmm Cproc
 
  
:              Aproc  will  be  called  when  the requested URL is
+
    ns_register_proc -noinherit GET /foo/bar Aproc
:              exactly /foo/bar. Bproc will  be  called  when  the
+
    ns_register_proc GET /foo/bar Bproc
:              requested  URL is below /foo/bar, provided there is
+
    ns_register_proc GET /foo/bar/hmm Cproc
:              not already  another  procedure  registered  to  be
 
:              called  for  that  exact  URL  or for an URL with a
 
:              closer match. Cproc (not Bproc) will be called when
 
:              the  requested  URL  is  equal  to  or  below
 
:              /foo/bar/hmm.  Syntax for the registered  procedure
 
:              The conn (connection) argument is optional for procedures
 
:              registered by ns_register_proc if the  procedure  has 
 
:              0 or 1 arguments (not including conn).
 
:              The following examples show the variations that can
 
:              be used in this case:
 
  
                    ns_register_proc GET /noargs noargs
+
: Aproc will be called when the requested URL is exactly /foo/bar.  Bproc will be called when the requested URL is below /foo/bar, provided there is not already another procedure registered to be called for that exact URL or for an URL with a closer match. Cproc (not Bproc) will be called when the requested URL is equal to or below /foo/bar/hmm. Syntax for the registered procedure The conn (connection) argument is optional for procedures registered by '''ns_register_proc''' if the procedure has 0 or 1 arguments (not including conn).  The following [http://www.umbrellaonline.com real estate] examples show the variations that can be used in this case:
                    ns_register_proc GET /context context fnord
 
                    ns_register_proc GET /conncontext conncontext greeblev
 
   
 
                    proc noargs { } {
 
                        ns_returnnotice 200 "noargs"
 
                    } ;# noargs
 
 
                    proc context { context } {
 
                        ns_returnnotice 200 "context is $context"
 
                    } ;# context
 
   
 
                    proc conncontext { conn context } {
 
                        ns_returnnotice 200 "conncontext is $context"
 
                    } ;# conncontext
 
  
:              The conn (connection) argument is required for procedures
+
    ns_register_proc GET /noargs noargs
:              registered by '''ns_register_proc''' if the  procedure 
+
    ns_register_proc GET /context context fnord
:              has  2  or  more  arguments  (not including
+
    ns_register_proc GET /conncontext conncontext greeblev
:              conn). The conn argument will be  filled  automatically 
+
   
:              with  the  connection information. The first
+
    proc noargs { } {
:              argument following conn will always take the  value
+
        ns_returnnotice 200 "noargs"
:              supplied  by  '''ns_register_proc''', if there is one, or
+
    } ;# noargs
:              an empty value. All other arguments must  supply  a
+
   
:              default  value.  The  following  examples  show the
+
    proc context { context } {
:              variations that can be used in this case:
+
        ns_returnnotice 200 "context is $context"
 +
    } ;# context
 +
   
 +
    proc conncontext { conn context } {
 +
        ns_returnnotice 200 "conncontext is $context"
 +
    } ;# conncontext
  
                    ns_register_proc GET /twoargs twoargs fnord
+
: The ''conn'' (connection) argument is required for procedures registered by '''ns_register_proc''' if the procedure has 2 or more arguments (not including ''conn'').  The ''conn'' argument will be filled automatically with the connection information.  The first argument following ''conn'' will always take the value supplied by '''ns_register_proc''', if there is one, or an empty value.  All other arguments must supply a default value. The following examples show the variations that can be used in this case:
                    ns_register_proc GET /threeargs threeargs fnord fjord
 
   
 
                    ns_register_proc -noinherit GET /foo/bar Aproc
 
                    ns_register_proc GET /foo/bar Bproc
 
                    ns_register_proc GET /foo/bar/hmm Cproc
 
  
:              Aproc  will  be  called  when  the requested URL is
+
    ns_register_proc GET /twoargs twoargs fnord
:              exactly /foo/bar. Bproc will  be  called  when  the
+
    ns_register_proc GET /threeargs threeargs fnord fjord
:              requested  URL is below /foo/bar, provided there is
+
   
:              not already  another  procedure  registered  to  be
+
    proc twoargs { conn context { greeble bork } } {
:              called  for  that  exact  URL  or for an URL with a
+
        # Do stuff...
:              closer match. Cproc (not Bproc) will be called when
+
    }
:              the  requested  URL  is  equal  to  or  below
+
   
:              /foo/bar/hmm.  Syntax for the registered  procedure
+
    proc threeargs { conn context {greeble bork } { hoover quark } {
:              The conn (connection) argument is optional for procedures
+
        # Do stuff...
:              registered by '''ns_register_proc''' if the  procedure 
+
    }
:              has  0 or 1 arguments (not including conn).
 
:              The following examples show the variations that can
 
:              be used in this case:
 
  
                    ns_register_proc GET /noargs noargs
+
: When a GET of /twoargs is requested, the conn argument will be filled automatically, the context argument will be assigned "fnord" and the greeble argument will be assigned the default value "bork".
                    ns_register_proc GET /context context fnord
 
                    ns_register_proc GET /conncontext conncontext greeble
 
 
 
                    proc noargs { } {
 
                        ns_returnnotice 200 "noargs"
 
                    } ;# noargs
 
 
                    proc context { context } {
 
                        ns_returnnotice 200 "context is $context"
 
                    } ;# context
 
 
                    proc conncontext { conn context } {
 
                        ns_returnnotice 200 "conncontext is $context"
 
                    } ;# conncontext
 
  
:             The conn (connection) argument is required for procedures
+
: When a GET of /threeargs is requested, the conn argument will be filled automatically, the context argument will be assigned "fnord" and the greeble argument will be assigned "fjord", and the hoover argument will be assigned the default value "quark".
:              registered by ns_register_proc if the procedure  has  2 
 
:              or  more  arguments  (not including
 
:              conn). The conn argument will be filled automatically
 
:              with  the connection information. The first
 
:              argument following conn will always take the value
 
:              supplied  by  ns_register_proc, if there is one, or
 
:              an empty value. All other arguments must  supply  a
 
:              default value. The  following  examples  show the
 
:              variations that can be used in this case:
 
  
                    ns_register_proc GET /twoargs twoargs fnord
+
'''SEE ALSO'''
                    ns_register_proc GET /threeargs threeargs fnord fjord
 
 
                    proc twoargs { conn context { greeble bork } } {
 
                        # Do stuff...
 
                    }
 
 
                    proc threeargs { conn context {greeble bork } { hoover quark } {
 
                        # Do stuff...
 
                    }
 
  
:             When a GET of /twoargs is requested, the conn argument 
+
: [[ns_unregister_proc]]
:              will  be  filled  automatically,  the context
 
:              argument will be assigned "fnord" and  the  greeble
 
:              argument will be assigned the default value "bork".
 
  
:             When a GET of /threeargs  is  requested,  the  conn
+
[[Category:Documentation]] [[Category:Core Tcl API]]
:             argument  will be filled automatically, the context
 
:              argument will be assigned "fnord" and  the  greeble
 
:              argument  will  be assigned "fjord", and the hoover
 
:              argument  will  be  assigned  the  default  value
 
:              "quark".
 

Latest revision as of 14:19, 15 March 2010

Man page: http://aolserver.com/man/4.0/tcl/ns_proc.html


NAME

ns_register_proc - Register a procedure for a method/URL combination

SYNOPSIS

ns_register_proc ?-noinherit? method URL myproc ?args?

DESCRIPTION

ns_register_proc registers the procname to handle the specified method/URL combination. When the server gets a matching request, it calls procname with the connection id and any arguments specified here.
If -noinherit is specified, the requested URL must match the specified URL exactly. For example, if the URL specified with ns_register_proc is /foo/bar, procname will not be called unless the requested URL is exactly /foo/bar.
If -noinherit is not specified, the requested URL can match the specified URL or any URL below it. For example, if the URL specified with ns_register_proc is /foo/bar, procname will be called for /foo/bar, /foo/bar/hmm, and any other URL below /foo/bar, provided there is not already another procedure registered for that exact URL or for an URL with a closer match.
Note that you must use a glob-style matching character if you want inheritance for file names. For example, if you want /foo/bar to match /foo/bar.html, you must use:
   ns_register_proc /foo/bar*
You can register two procedures for any given method/URL combination by calling ns_register_proc once with the -noinherit flag set and once without it. Only one of the procedures will be called for any given request, depending on whether the URL was an exact match or not. For example:
   ns_register_proc -noinherit GET /foo/bar Aproc
   ns_register_proc GET /foo/bar Bproc
   ns_register_proc GET /foo/bar/hmm Cproc
Aproc will be called when the requested URL is exactly /foo/bar. Bproc will be called when the requested URL is below /foo/bar, provided there is not already another procedure registered to be called for that exact URL or for an URL with a closer match. Cproc (not Bproc) will be called when the requested URL is equal to or below /foo/bar/hmm. Syntax for the registered procedure The conn (connection) argument is optional for procedures registered by ns_register_proc if the procedure has 0 or 1 arguments (not including conn). The following real estate examples show the variations that can be used in this case:
   ns_register_proc GET /noargs noargs
   ns_register_proc GET /context context fnord
   ns_register_proc GET /conncontext conncontext greeblev
   
   proc noargs { } {
       ns_returnnotice 200 "noargs"
   } ;# noargs
   
   proc context { context } {
       ns_returnnotice 200 "context is $context"
   } ;# context
   
   proc conncontext { conn context } {
       ns_returnnotice 200 "conncontext is $context"
   } ;# conncontext
The conn (connection) argument is required for procedures registered by ns_register_proc if the procedure has 2 or more arguments (not including conn). The conn argument will be filled automatically with the connection information. The first argument following conn will always take the value supplied by ns_register_proc, if there is one, or an empty value. All other arguments must supply a default value. The following examples show the variations that can be used in this case:
   ns_register_proc GET /twoargs twoargs fnord
   ns_register_proc GET /threeargs threeargs fnord fjord
   
   proc twoargs { conn context { greeble bork } } {
       # Do stuff...
   }
   
   proc threeargs { conn context {greeble bork } { hoover quark } {
       # Do stuff...
   }
When a GET of /twoargs is requested, the conn argument will be filled automatically, the context argument will be assigned "fnord" and the greeble argument will be assigned the default value "bork".
When a GET of /threeargs is requested, the conn argument will be filled automatically, the context argument will be assigned "fnord" and the greeble argument will be assigned "fjord", and the hoover argument will be assigned the default value "quark".

SEE ALSO

ns_unregister_proc