tclhttpd

Check-in [9cf98575a1]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Documentation fixes Renamed the cookieSet method to httpdCookieSet, and moved it to httpd.meta Moved httpdHostName it to httpd.meta
Timelines: family | ancestors | descendants | both | private
Files: files | file ages | folders
SHA1:9cf98575a14bd6bb478e9301e437456ef5c7454c
User & Date: hypnotoad 2015-04-02 21:41:43
Context
2015-04-03
06:45
Implemented logins using encrypted password hashes Added a module to store javascript password hashing routines. Added a "cat" command to dump files check-in: 192b2e9d60 user: hypnotoad tags: private
2015-04-02
21:41
Documentation fixes Renamed the cookieSet method to httpdCookieSet, and moved it to httpd.meta Moved httpdHostName it to httpd.meta check-in: 9cf98575a1 user: hypnotoad tags: private
21:14
Added doccos check-in: 91370c635c user: hypnotoad tags: private
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to modules/community/community.md.

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






























*httpd.community* is a decendent of [httpd.taourl](wiki?taourl). It adds an sqlite based user, group, and access control system. It is implemented in [community.tcl](finfo?name=modules/community/community.tcl).






## Required Packages

Community relies on the following external packages:

* sha1 from [tcllib](http://core.tcl.tk/tcllib)
* sqlite3 from [sqlite](http://www.sqlite.org)

Community uses the following internal packages:

* tao from [tao](../tao/tao.md)
* tao-sqlite [tao-sqlite](../tao-sqlite/tao-sqlite.md)





## Options

* dbfile - Path to a file which stores the sqlite database for the community (default in-memory)
* virtual - Root Url of this object.

## Attached Objects

Community objects (and their derived classes) contain an embedded sqlite
database. This database can be accessed via that \<db\> method.

## Methods






























|
>
>
>
>
>













>
>
>
>











>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
*httpd.community* is a decendent of . It adds an sqlite based user, group, and access control system. It is implemented in [community.tcl](finfo?name=modules/community/community.tcl).

## Ancestors

* [httpd.taourl](../directoo/taourl.md)
* [yggdrasil](../tao-sqlite/yggdrasil.md)

## Required Packages

Community relies on the following external packages:

* sha1 from [tcllib](http://core.tcl.tk/tcllib)
* sqlite3 from [sqlite](http://www.sqlite.org)

Community uses the following internal packages:

* tao from [tao](../tao/tao.md)
* tao-sqlite [tao-sqlite](../tao-sqlite/tao-sqlite.md)

## Properties

* create\_sql - An SQL script that implements the schema

## Options

* dbfile - Path to a file which stores the sqlite database for the community (default in-memory)
* virtual - Root Url of this object.

## Attached Objects

Community objects (and their derived classes) contain an embedded sqlite
database. This database can be accessed via that \<db\> method.

## Methods

### method Database\_Functions

Adds the following functions to the database:

* uuid\_generate() - Generates sha1 UUIDs on demand
* sha1() - Returns the SHA1 hash of the input

### accessTypes

Returns a list of all possible rights.

### aclRights *aclname* *user\_or\_group\_id*

Return a list of rights that the user or group to the access control list (specified by name.)

### method httpdSessionLoad *sock* *prefix* *suffix*

This method looks for a sessionid cookie or a sessionid field in the GET or POST query, and
pairs it with a session in the *session* table. If no session is found, a new session is generated
for an anonymous user.

### method httpdSessionSave *sock*

This method compares the current value of **result\(session\)** to **result\(session\_delta\)** (a copy
of the session when the pageview began. Fields that are in the delta, but not in the current session are delete
from **session\_property**. Fields that are present in the session but not the delta are inserted into
**session\_property**. Fields present in both, but with a different value, are updated.

The server will generate a cookie called **sessionid** which will be loaded on the next page view.

Changes to modules/directoo/directoo.md.

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

* code - HTTP code to return (default 400)
* body - The block of data to be sent via *Httpd_ReturnData* or *Httpd_ReturnCacheableData* at the conclusion of the operation.
* content-type - The type of content in *block* (default text/html)

## Methods

### configurelist *keyvaluelist*

Pass configuration items as a key/value list.

### cget *field*

Retrieve the value of a configuration item

### /html

A method which implements the default root page of the object.

### initialize

A method which is called in the constructor, after the configuration items have been applied and the domain registered with Tclhttpd.















### httpdDirect *sock* *suffix*

This method is the first called when resolving a dynamic page. It calles *httpdSessionLoad* to load the session, *httpdMarshalArguments* do compute the method to call. On error, this method returns an error message. On success it calls *httpdSessionSave*, before sending the resulting data out to TclHttpd via the *Httpd_ReturnData* or *Httpd_ReturnCacheableData* procs.

### httpdMarshalArguments *sock* *suffix*

Calculate the command which will implement the current page view.

### httpdSessionLoad *sock *prefix* *suffix*

Initializes the *result* variable, and load session data from either cookies or the incoming GET/POST query. This method also calls the *Cgi_SetEnv* and *Url_QuerySetup* procs from Tclhttpd. Rather than populate the global *env* variable, Cgi_SetEnv populates the private *env* variable for this object.

### httpdSessionSave *sock*

Updates the current session, and writes cookies back to the browser.

### reset

Reset the current value of result(body)

### puts

Append to the value of result(body). Accepts multiple arguments. An implied \n is appended at the tail end.

### unknown *args*

Handler for unknown, incomplete, or invalid queries.







|



|







|



>
>
>
>
>
>
>
>
>
>
>
>
>
>
|



|



|



|



|



|



|


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

* code - HTTP code to return (default 400)
* body - The block of data to be sent via *Httpd_ReturnData* or *Httpd_ReturnCacheableData* at the conclusion of the operation.
* content-type - The type of content in *block* (default text/html)

## Methods

### method configurelist *keyvaluelist*

Pass configuration items as a key/value list.

### method cget *field*

Retrieve the value of a configuration item

### /html

A method which implements the default root page of the object.

### method initialize

A method which is called in the constructor, after the configuration items have been applied and the domain registered with Tclhttpd.

### method httpdCookieSet *field* *value* *?expire?*

Set a cookie named *field* and value of *value*. If *expire* is a postitive integer,
it indicates how long (in seconds) this cookie should last.

Note: Cookies destined for "localhost" are mapped to null so
browser will honor them properly.

### method httpdHostName

Return the host name by which this page was accessed. Derived
from env\(HTTP\_HOST\).


### method httpdDirect *sock* *suffix*

This method is the first called when resolving a dynamic page. It calles *httpdSessionLoad* to load the session, *httpdMarshalArguments* do compute the method to call. On error, this method returns an error message. On success it calls *httpdSessionSave*, before sending the resulting data out to TclHttpd via the *Httpd_ReturnData* or *Httpd_ReturnCacheableData* procs.

### method httpdMarshalArguments *sock* *suffix*

Calculate the command which will implement the current page view.

### method httpdSessionLoad *sock *prefix* *suffix*

Initializes the *result* variable, and load session data from either cookies or the incoming GET/POST query. This method also calls the *Cgi_SetEnv* and *Url_QuerySetup* procs from Tclhttpd. Rather than populate the global *env* variable, Cgi_SetEnv populates the private *env* variable for this object.

### method httpdSessionSave *sock*

Updates the current session, and writes cookies back to the browser.

### method reset

Reset the current value of result(body)

### method puts

Append to the value of result(body). Accepts multiple arguments. An implied \n is appended at the tail end.

### method unknown *args*

Handler for unknown, incomplete, or invalid queries.

Changes to modules/directoo/directoo.tcl.

24
25
26
27
28
29
30
31









32









33
34
35
36
37
38
39
oo::class create httpd.meta {
  
  destructor {
    catch {::Url_PrefixRemove [my cget virtual]}
  }
  
  method initialize {} {}




















  # This calls out to the Tcl procedure named "$prefix$suffix",
  # with arguments taken from the form parameters.
  # Example:
  # httpdDirect /device Device
  # if the URL is /device/a/b/c, then the Tcl command to handle it
  # should be
  # [self] /html/Device/a/b/c







|
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>







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
oo::class create httpd.meta {
  
  destructor {
    catch {::Url_PrefixRemove [my cget virtual]}
  }
  
  method initialize {} {}
  
  method httpdCookieSet {field value {expire {}}} {
    foreach host [my httpdHostName] {
      if { $host eq "localhost" } { set host {} }
      set cookie_args [list -name $field \
        -value $value \
        -domain $host \
        -path [my cget virtual]]
      if {[string is integer expire]} {
        lappend cookie_args -expires [clock format [expr [clock seconds] + [set expire]] -format "%Y-%m-%d"]
      }
      ::Cookie_Set {*}$cookie_args
    }
  }

  method httpdHostName {} {
    my variable env
    return [lindex [split [get env(HTTP_HOST)] :] 0]
  }
  
  # This calls out to the Tcl procedure named "$prefix$suffix",
  # with arguments taken from the form parameters.
  # Example:
  # httpdDirect /device Device
  # if the URL is /device/a/b/c, then the Tcl command to handle it
  # should be
  # [self] /html/Device/a/b/c