diff --git a/net_services/CXM_generic_client.anubis b/net_services/CXM_generic_client.anubis
index ee16108..8a4d531 100644
--- a/net_services/CXM_generic_client.anubis
+++ b/net_services/CXM_generic_client.anubis
@@ -185,7 +185,7 @@ public define Maybe($T)
=
if connect( server, port) is
{
- error(_) then logger(queue_name + ": Can't connect to domain manager ["+ip_addr_to_string(server)+":"+port+"]");failure,
+ error(_) then logger(queue_name + ": Can't connect to service ["+ip_addr_to_string(server)+":"+port+"]");failure,
ok(conn) then
// println("[" + virtual_machine_id + "] netservices create queue");
with queue = create_MessageQueue(queue_name),
diff --git a/web/CXM_cookies.anubis b/web/CXM_cookies.anubis
index 8581aab..e4db40b 100644
--- a/web/CXM_cookies.anubis
+++ b/web/CXM_cookies.anubis
@@ -192,14 +192,22 @@ public type Atom:
semi_colon.
-variable List(Atom) unput_atoms = [].
+ variable List(Atom) unput_atoms = [].
+
+type CookieToolBox:
+ tool_box(Var(List(Atom)) unput_atoms,
+ Var(String) input,
+ Var(Int) index,
+ Var(String) server_name
+ ).
define One
unput_atom
(
- Atom a
+ CookieToolBox tbx,
+ Atom a
) =
- unput_atoms <- [a . *unput_atoms].
+ unput_atoms(tbx) <- [a . *unput_atoms(tbx)].
define Atom
recognize_keyword
@@ -216,12 +224,15 @@ define Atom
token(s).
-variable String input = "". From which cookies will be read.
-variable Int index = 0. Current position within 'input'.
+ variable String input = "". From which cookies will be read.
+ variable Int index = 0. Current position within 'input'.
define Maybe(Word8)
next_char
- =
+ (
+ CookieToolBox tbx
+ ) =
+ if tbx is tool_box(_, input, index, _) then
if nth(*index,*input) is
{
failure then failure,
@@ -232,36 +243,41 @@ define Maybe(Word8)
define One
unput_char
- =
+ (
+ CookieToolBox tbx
+ ) =
+ if tbx is tool_box(_, _, index, _) then
index <- *index-1.
define Atom
read_token
(
+ CookieToolBox tbx,
List(Word8) so_far, // contains at least 1 character
(Word8) -> Bool is_valid_char
) =
- if next_char is
+ if next_char(tbx) is
{
failure then recognize_keyword(implode(reverse(so_far))),
success(c) then
if is_valid_char(c)
- then read_token([c . so_far], is_valid_char)
- else unput_char; recognize_keyword(implode(reverse(so_far)))
+ then read_token(tbx,[c . so_far], is_valid_char)
+ else unput_char(tbx); recognize_keyword(implode(reverse(so_far)))
}.
define Atom
read_quoted_string
(
- List(Word8) so_far
+ CookieToolBox tbx,
+ List(Word8) so_far
) =
- if next_char is
+ if next_char(tbx) is
{
failure then quoted_string(implode(reverse(so_far))),
success(c) then
if c = '\"'
then quoted_string(implode(reverse(so_far)))
- else read_quoted_string([c . so_far])
+ else read_quoted_string(tbx,[c . so_far])
}.
define Bool
@@ -275,44 +291,48 @@ define Bool
define Atom
read_atom
- =
- if *unput_atoms is
+ (
+ CookieToolBox tbx,
+ ) =
+ if *unput_atoms(tbx) is
{
[ ] then
- if next_char is
+ if next_char(tbx) is
{
failure then end_of_input,
success(c) then
- if is_blank(c) then read_atom else // skip blanks
- if is_token_char(c) then read_token([c], is_token_char) else
- if c = '\"' then read_quoted_string([]) else
+ if is_blank(c) then read_atom(tbx) else // skip blanks
+ if is_token_char(c) then read_token(tbx,[c], is_token_char) else
+ if c = '\"' then read_quoted_string(tbx,[]) else
if c = '=' then equals else
if c = ':' then colon else
if c = ';' then semi_colon else
error
},
[h . t] then
- unput_atoms <- t; h
+ unput_atoms(tbx) <- t; h
}.
define Atom
read_value
- =
- if *unput_atoms is
+ (
+ CookieToolBox tbx
+ ) =
+ if *unput_atoms(tbx) is
{
[ ] then
- if next_char is
+ if next_char(tbx) is
{
failure then end_of_input,
success(c) then
- if is_blank(c) then read_value else // skip blanks
- if is_value_char(c) then read_token([c], is_value_char) else
- if c = '\"' then read_quoted_string([]) else
- if c = ';' then semi_colon else
+ if is_blank(c) then read_value(tbx) else // skip blanks
+ if is_value_char(c) then read_token(tbx,[c], is_value_char) else
+ if c = '\"' then read_quoted_string(tbx,[]) else
+ if c = ';' then semi_colon else
error
},
[h . t] then
- unput_atoms <- t; h
+ unput_atoms(tbx) <- t; h
}.
Reading an attribute-value pair.
@@ -327,38 +347,42 @@ type AttrVal:
define String
read_eq_value
- =
- with e = read_atom,
+ (
+ CookieToolBox tbx
+ ) =
+ with e = read_atom(tbx),
if e is equals then
(
- with a = read_atom,
+ with a = read_atom(tbx),
if a is token(n) then n else
if a is quoted_string(s) then s else
- unput_atom(a); ""
+ unput_atom(tbx,a); ""
)
- else unput_atom(e); "".
+ else unput_atom(tbx,e); "".
define Maybe(AttrVal)
read_attr_val
- =
- if read_atom is semi_colon then
- with a = read_atom,
+ (
+ CookieToolBox tbx
+ ) =
+ if read_atom(tbx) is semi_colon then
+ with a = read_atom(tbx),
if a is
{
end_of_input then failure,
error then failure,
- comment then success(comment(read_eq_value)),
- domain then success(domain(read_eq_value)),
- max_age then success(max_age(read_eq_value)),
- path then success(path(read_eq_value)),
+ comment then success(comment(read_eq_value(tbx))),
+ domain then success(domain(read_eq_value(tbx))),
+ max_age then success(max_age(read_eq_value(tbx))),
+ path then success(path(read_eq_value(tbx))),
secure then success(secure),
- version then success(version(read_eq_value)),
- token(_) then unput_atom(a); failure,
- quoted_string(_) then unput_atom(a); failure,
- equals then unput_atom(a); failure,
- colon then unput_atom(a); failure,
- semi_colon then unput_atom(a); failure,
+ version then success(version(read_eq_value(tbx))),
+ token(_) then unput_atom(tbx,a); failure,
+ quoted_string(_) then unput_atom(tbx,a); failure,
+ equals then unput_atom(tbx,a); failure,
+ colon then unput_atom(tbx,a); failure,
+ semi_colon then unput_atom(tbx,a); failure,
}
else failure.
@@ -454,20 +478,21 @@ define Int
Reading a cookie:
-variable String server_name = "".
+ variable String server_name = "".
define Maybe(Cookie)
read_cookie_n_e_v
(
- String name,
- String value,
- List(AttrVal) so_far
+ CookieToolBox tbx,
+ String name,
+ String value,
+ List(AttrVal) so_far
) =
- if read_attr_val is
+ if read_attr_val(tbx) is
{
failure then
success(cookie(
- *server_name,
+ *server_name(tbx),
name,
value,
get_comment(so_far),
@@ -478,49 +503,53 @@ define Maybe(Cookie)
get_version(so_far)
)),
- success(av) then read_cookie_n_e_v(name,value,[av . so_far])
+ success(av) then read_cookie_n_e_v(tbx,name,value,[av . so_far])
}.
define Maybe(Cookie)
read_cookie_n_e
(
- String name
+ CookieToolBox tbx,
+ String name
) =
- with a = read_value,
-
- if a is token(value) then read_cookie_n_e_v(name,value,[]) else
- if a is quoted_string(value) then read_cookie_n_e_v(name,value,[]) else
- unput_atom(a); failure.
+ with a = read_value(tbx),
+ if a is token(value) then read_cookie_n_e_v(tbx,name,value,[]) else
+ if a is quoted_string(value) then read_cookie_n_e_v(tbx,name,value,[]) else
+ unput_atom(tbx,a); failure.
define Maybe(Cookie)
read_cookie_n
(
- String name
+ CookieToolBox tbx, // bis repetita placent
+ String name
) =
- with a = read_atom,
+ with a = read_atom(tbx),
if a is equals
- then read_cookie_n_e(name)
- else unput_atom(a); failure.
+ then read_cookie_n_e(tbx,name)
+ else unput_atom(tbx,a); failure.
define Maybe(Cookie)
read_cookie
- =
- with a = read_atom,
+ (
+ CookieToolBox tbx
+ ) =
+ with a = read_atom(tbx),
if a is token(name)
- then read_cookie_n(name)
- else unput_atom(a); failure.
+ then read_cookie_n(tbx,name)
+ else unput_atom(tbx,a); failure.
define List(Cookie)
read_cookies
(
- List(Cookie) so_far
+ CookieToolBox tbx,
+ List(Cookie) so_far
) =
- if read_cookie is
+ if read_cookie(tbx) is
{
failure then so_far,
- success(c) then read_cookies([c . so_far])
+ success(c) then read_cookies(tbx,[c . so_far])
}.
@@ -531,14 +560,8 @@ define List(Cookie)
HTTP_header h
) =
if h is http_header(n,v) then
- if to_lower(n) = "set-cookie"
- then (
- unput_atoms <- [];
- input <- v;
- index <- 0;
- server_name <- svn;
- read_cookies([])
- )
+ if to_lower(n) = "set-cookie"
+ then read_cookies(tool_box(var([]),var(v),var(0),var(svn)),[])
else [].
public define List(Cookie)
@@ -561,13 +584,7 @@ define List(Cookie)
) =
if h is http_header(n,v) then
if to_lower(n) = "cookie"
- then (
- unput_atoms <- [];
- input <- v;
- index <- 0;
- server_name <- "";
- read_cookies([])
- )
+ then read_cookies(tool_box(var([]),var(v),var(0),var("")),[])
else [].
public define List(Cookie)
diff --git a/web/CXM_making_a_web_site.anubis b/web/CXM_making_a_web_site.anubis
index 15c50b8..ea766e4 100644
--- a/web/CXM_making_a_web_site.anubis
+++ b/web/CXM_making_a_web_site.anubis
@@ -46,13 +46,14 @@
read tools/basis.anubis
read tools/printable_tree.anubis
+read tools/base64.anubis
read system/string.anubis
read system/logger.anubis
read CXM_common.anubis
read CXM_multihost_http_server.anubis
read web/mime.anubis
read CXM_cookies.anubis
-
+
* (1) Structure of a web site.
@@ -2475,7 +2476,50 @@ public define Web_Site
//using_state_cookies
),
delete_out_of_date).
-
+
+define String
+ _random_string
+ (
+ Int size,
+ String current
+ )=
+ if size = 0 then
+ current
+ else
+ _random_string( size - 1, current + random(9))
+ .
+
+public define String
+ generate_random_string
+ (
+ Int size
+ ) =
+ to_string(extract(base64_encode(to_byte_array(_random_string(size, ""))), 0, size)).
+
+
+define String
+ get_site_uid
+ (
+ String site_path
+ )=
+ with file_name = site_path+"/site_UID",
+ if read_from_file(file_name) is
+ {
+ cannot_find_file then
+ println("site UID doesn't exists. Generating it now");
+ with uid = generate_random_string(9),
+ if write_to_file(file_name, to_byte_array(uid)) is
+ {
+ cannot_open_file then println("Can't create site UID here "+file_name);"",
+ write_error(_) then println("Can't write site UID here "+file_name);"",
+ ok then uid
+ }
+ read_error(_) then
+ println("cannot read site UID from "+file_name);""
+ ok(ba) then to_string(ba)
+ }
+ .
+
// Compatibility function for older websites
public define Web_Site
make_web_site_description
@@ -2511,7 +2555,10 @@ public define Web_Site
//Bool using_state_cookies
)
=
- make_web_site_description("", common_names, site_directory, state_directory, init, initial_state, ticket_expired_state, ticket_lost_state, actions, compute_page, additional_headers, timeout, redirections, charset, journal_extensions, journal_headers, secret, known_mime_types, before_send_file)
+ //generate an unique ID if doesn't exist in root of site_directory
+ with site_UID = get_site_uid(site_directory),
+ println("site_UID : "+site_UID);
+ make_web_site_description(site_UID, common_names, site_directory, state_directory, init, initial_state, ticket_expired_state, ticket_lost_state, actions, compute_page, additional_headers, timeout, redirections, charset, journal_extensions, journal_headers, secret, known_mime_types, before_send_file)
.
@@ -2984,15 +3031,16 @@ public define Printable_tree
}.
-
-variable Int count = 0.
-
+
Note: this counter is private to the virtual machine, hence there is one counter by
client and by page : it seems that a new VM (simply a delegate) is started for each request.
define Int
new_count
- =
+ (
+ Var(Int) count
+ )
+ =
count <- *count+1;
*count.
@@ -3069,14 +3117,15 @@ define URL_or_JavaScript
String the_url,
Actioner_Aspect aspect,
Maybe(String) mb_id,
- Maybe(String) mb_form_name
+ Maybe(String) mb_form_name,
+ Var(Int) action_count
) =
if mb_form_name is
{
failure then
url(the_url),
success(form_name) then
- with n = new_count,
+ with n = new_count(action_count),
fn_name = "pfu_" + if mb_id is
{
failure then form_name + "_" + n,
@@ -3411,11 +3460,12 @@ define Printable_tree
List(Actioner_Local_Action) local_actions,
Maybe(String) mb_form_name,
Bool is_https,
+ Var(Int) action_count
) =
if cinfo is info(common_name,http_port,https_port,site_dir,secret) then
with url = make_actioner_url(cinfo,connection,target,
state_name,action_name,extra_ops,is_https),
- with action = format_action(url, aspect, extract_id(aspect), mb_form_name),
+ with action = format_action(url, aspect, extract_id(aspect), mb_form_name, action_count),
if aspect is
{
@@ -3997,10 +4047,11 @@ define Printable_tree
(
CommonInfo cinfo,
String sn, // state_name
- Var(Int) ic_v,
+ Var(Int) ic_v,
HTML_Any($T) element,
$T -> Printable_tree format_element, // able to format a datum of type $T
Bool is_https,
+ Var(Int) action_count
) =
if cinfo is info(common_name,http_port,https_port,site_directory,secret) then
if element is
@@ -4044,7 +4095,7 @@ define Printable_tree
"secondary document",
""],
any_actioner(c,t,a,an,eo,ja,fn) then
- format_actioner(cinfo,sn,c,t,a,an,eo,ja,fn,is_https),
+ format_actioner(cinfo,sn,c,t,a,an,eo,ja,fn,is_https, action_count),
any_foreign_link_new(target, aspect, url) then
format_foreign_link(target, aspect, url, is_https),
@@ -4085,47 +4136,48 @@ define Printable_tree
CommonInfo cinfo,
String fn, // form_name
String sn, // state_name
- Var(Int) ic_v, // idnum counter variable
+ Var(Int) ic_v, // idnum counter variable
HTML_In_Form element,
Bool is_https,
+ Var(Int) action_count
) =
if cinfo is info(common_name,http_port,https_port,site_directory,secret) then
- with format_element = (HTML_In_Form e) |-> format(cinfo,fn,sn,ic_v,e,is_https),
+ with format_element = (HTML_In_Form e) |-> format(cinfo, fn, sn, ic_v, e, is_https, action_count),
if element is
{
literal_pt(t) then t,
literal(t) then [t],
sequence(l) then flat(map(format_element,l))
text(opts,t) then
- format(cinfo,sn,ic_v,any_text(opts,t),format_element,is_https),
+ format(cinfo,sn,ic_v,any_text(opts,t),format_element,is_https, action_count),
preformated(o,s) then
- format(cinfo,sn,ic_v,any_preformated(o,s),format_element,is_https),
+ format(cinfo,sn,ic_v,any_preformated(o,s),format_element,is_https, action_count),
paragraph(opts,t) then
- format(cinfo,sn,ic_v,any_paragraph(opts,t),format_element,is_https),
+ format(cinfo,sn,ic_v,any_paragraph(opts,t),format_element,is_https, action_count),
image(opts, url, alt) then
- format(cinfo,sn,ic_v,any_image(opts, url, alt),format_element,is_https),
+ format(cinfo,sn,ic_v,any_image(opts, url, alt),format_element,is_https, action_count),
image(opts, url, alt, w, h) then
- format(cinfo,sn,ic_v,any_image(opts, url, alt, w, h),format_element,is_https),
+ format(cinfo,sn,ic_v,any_image(opts, url, alt, w, h),format_element,is_https, action_count),
table(opts,header_row,rows,footer_row) then
- format(cinfo,sn,ic_v,any_table(opts, header_row, rows, footer_row),format_element,is_https),
+ format(cinfo,sn,ic_v,any_table(opts, header_row, rows, footer_row),format_element,is_https, action_count),
center(e) then
- format(cinfo,sn,ic_v,any_center(e),format_element,is_https),
+ format(cinfo,sn,ic_v,any_center(e),format_element,is_https, action_count),
mail_to(a,e) then
- format(cinfo,sn,ic_v,any_mail_to(a,e),format_element,is_https),
+ format(cinfo,sn,ic_v,any_mail_to(a,e),format_element,is_https, action_count),
scroller(w,h,cw,ch,c) then
- format(cinfo,sn,ic_v,any_scroller(w,h,cw,ch,c),format_element,is_https),
+ format(cinfo,sn,ic_v,any_scroller(w,h,cw,ch,c),format_element,is_https, action_count),
actioner(c,t,a,an,eo,ja) then
- format(cinfo,sn,ic_v,any_actioner(c,t,a,an,eo,ja,success(fn)),format_element,is_https),
+ format(cinfo,sn,ic_v,any_actioner(c,t,a,an,eo,ja,success(fn)),format_element,is_https, action_count),
foreign_link_new(target, aspect, url) then
- format(cinfo,sn,ic_v,any_foreign_link_new(target,aspect,url),format_element,is_https),
+ format(cinfo,sn,ic_v,any_foreign_link_new(target,aspect,url),format_element,is_https, action_count),
foreign_link(options,url) then
- format(cinfo,sn,ic_v,any_foreign_link(options,url),format_element,is_https),
+ format(cinfo,sn,ic_v,any_foreign_link(options,url),format_element,is_https, action_count),
foreign_link(options,url,name) then
- format(cinfo,sn,ic_v,any_foreign_link(options,url,name),format_element,is_https),
+ format(cinfo,sn,ic_v,any_foreign_link(options,url,name),format_element,is_https, action_count),
private_download(url,name,extra,action) then
- format(cinfo,sn,ic_v,any_private_download(url,name,extra,action),format_element,is_https),
+ format(cinfo,sn,ic_v,any_private_download(url,name,extra,action),format_element,is_https, action_count),
text_input(options, label_text, id, name, i, w) then
[ maybe_label(label_text, id),
""],
@@ -4166,9 +4218,9 @@ define Printable_tree
[ "",
maybe_label(label_text, id)]
div(options, e) then
- format(cinfo,sn,ic_v,any_div(options, e),format_element,is_https),
+ format(cinfo,sn,ic_v,any_div(options, e),format_element,is_https, action_count),
div_empty(options) then
- format(cinfo,sn,ic_v,any_div_empty(options),format_element,is_https),
+ format(cinfo,sn,ic_v,any_div_empty(options),format_element,is_https, action_count),
hidden(id, name, value) then
[""],
@@ -4273,53 +4325,54 @@ define Printable_tree
Var(Int) ic_v, // 'idnum' counter variable
HTML_Off_Form element,
Bool is_https,
+ Var(Int) action_count
) =
if cinfo is info(common_name,http_port,https_port,site_directory,secret) then
- with format_element = (HTML_Off_Form e) |-> format(cinfo,sn,ic_v,e,is_https),
+ with format_element = (HTML_Off_Form e) |-> format(cinfo, sn, ic_v, e, is_https, action_count),
if element is
{
literal_pt(t) then t,
literal(t) then [t],
sequence(l) then flat(map(format_element,l)),
text(opts,t) then
- format(cinfo,sn,ic_v,any_text(opts,t),format_element,is_https),
+ format(cinfo,sn,ic_v,any_text(opts,t),format_element,is_https, action_count),
preformated(o,s) then
- format(cinfo,sn,ic_v,any_preformated(o,s),format_element,is_https),
+ format(cinfo,sn,ic_v,any_preformated(o,s),format_element,is_https, action_count),
paragraph(opts,t) then
- format(cinfo,sn,ic_v,any_paragraph(opts,t),format_element,is_https),
+ format(cinfo,sn,ic_v,any_paragraph(opts,t),format_element,is_https, action_count),
image(opts,url,alt) then
- format(cinfo,sn,ic_v,any_image(opts,url,alt),format_element,is_https),
+ format(cinfo,sn,ic_v,any_image(opts,url,alt),format_element,is_https, action_count),
image(opts,url,alt,w,h) then
- format(cinfo,sn,ic_v,any_image(opts,url,alt,w,h),format_element,is_https),
+ format(cinfo,sn,ic_v,any_image(opts,url,alt,w,h),format_element,is_https, action_count),
table(opts,header_row, rows, footer_row) then
- format(cinfo,sn,ic_v,any_table(opts,header_row, rows, footer_row),format_element,is_https),
+ format(cinfo,sn,ic_v,any_table(opts,header_row, rows, footer_row),format_element,is_https, action_count),
center(e) then
- format(cinfo,sn,ic_v,any_center(e),format_element,is_https),
+ format(cinfo,sn,ic_v,any_center(e),format_element,is_https, action_count),
mail_to(a,e) then
- format(cinfo,sn,ic_v,any_mail_to(a,e),format_element,is_https),
+ format(cinfo,sn,ic_v,any_mail_to(a,e),format_element,is_https, action_count),
scroller(w,h,cw,ch,c) then
- format(cinfo,sn,ic_v,any_scroller(w,h,cw,ch,c),format_element,is_https),
+ format(cinfo,sn,ic_v,any_scroller(w,h,cw,ch,c),format_element,is_https, action_count),
fixed_size(w,h,c) then
- format(cinfo,sn,ic_v,any_fixed_size(w,h,c),format_element,is_https),
+ format(cinfo,sn,ic_v,any_fixed_size(w,h,c),format_element,is_https, action_count),
fixed_size_2(w,h,fn) then
- format(cinfo,sn,ic_v,any_fixed_size_2(w,h,fn),format_element,is_https),
+ format(cinfo,sn,ic_v,any_fixed_size_2(w,h,fn),format_element,is_https, action_count),
actioner(c,t,a,an,eo,ja) then
- format(cinfo,sn,ic_v,any_actioner(c,t,a,an,eo,ja,failure),format_element,is_https),
+ format(cinfo,sn,ic_v,any_actioner(c,t,a,an,eo,ja,failure),format_element,is_https, action_count),
actioner(c,t,a,an,eo,ja,fn) then
- format(cinfo,sn,ic_v,any_actioner(c,t,a,an,eo,ja,success(fn)),format_element,is_https),
+ format(cinfo,sn,ic_v,any_actioner(c,t,a,an,eo,ja,success(fn)),format_element,is_https, action_count),
foreign_link_new(target, aspect, url) then
- format(cinfo,sn,ic_v,any_foreign_link_new(target,aspect,url),format_element,is_https),
+ format(cinfo,sn,ic_v,any_foreign_link_new(target,aspect,url),format_element,is_https, action_count),
foreign_link(options,url) then
- format(cinfo,sn,ic_v,any_foreign_link(options,url),format_element,is_https),
+ format(cinfo,sn,ic_v,any_foreign_link(options,url),format_element,is_https, action_count),
foreign_link(options,url,name) then
- format(cinfo,sn,ic_v,any_foreign_link(options,url,name),format_element,is_https),
+ format(cinfo,sn,ic_v,any_foreign_link(options,url,name),format_element,is_https, action_count),
private_download(url,name,extra,action) then
- format(cinfo,sn,ic_v,any_private_download(url,name,extra,action),format_element,is_https),
+ format(cinfo,sn,ic_v,any_private_download(url,name,extra,action),format_element,is_https, action_count),
label(n) then [""],
form(fn,attributs, c) then
[
""
]
div(options, e) then
- format(cinfo,sn,ic_v,any_div(options, e),format_element,is_https),
+ format(cinfo,sn,ic_v,any_div(options, e),format_element,is_https, action_count),
div_empty(options) then
- format(cinfo,sn,ic_v,any_div_empty(options),format_element,is_https),
+ format(cinfo,sn,ic_v,any_div_empty(options),format_element,is_https, action_count),
iframe(options, css_styles, css_files, js_files, body) then
if body is body(body_options,element) then
[ "