|
|
|
|
|
|
|
|
protected object Roxen; |
protected object roxen; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define MAGIC_HELP_ARG |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <config.h> |
#include <module.h> |
#include <request_trace.h> |
|
|
#ifdef RXML_OBJ_DEBUG |
# define MARK_OBJECT \ |
mapping|object __object_marker = RoxenDebug.ObjectMarker (this_object()) |
# define MARK_OBJECT_ONLY \ |
mapping|object __object_marker = RoxenDebug.ObjectMarker (0) |
# define DO_IF_RXML_OBJ_DEBUG(X...) X |
#else |
# define MARK_OBJECT ; |
# define MARK_OBJECT_ONLY ; |
# define DO_IF_RXML_OBJ_DEBUG(X...) |
#endif |
|
#ifdef OBJ_COUNT_DEBUG |
|
|
# ifndef RXML_OBJ_DEBUG |
# undef MARK_OBJECT |
# undef MARK_OBJECT_ONLY |
# define MARK_OBJECT \ |
mapping|object __object_marker = (["count": ++all_constants()->_obj_count]) |
# define MARK_OBJECT_ONLY \ |
mapping|object __object_marker = (["count": ++all_constants()->_obj_count]) |
# endif |
# define OBJ_COUNT (__object_marker ? "[" + __object_marker->count + "]" : "") |
#else |
# define OBJ_COUNT "" |
#endif |
|
#ifdef DEBUG |
# define TAG_DEBUG(frame, msg, args...) \ |
(TAG_DEBUG_TEST (frame && frame->flags & FLAG_DEBUG) && \ |
report_debug ("%O: " + (msg), (frame), args), 0) |
#else |
# define TAG_DEBUG(frame, msg, args...) 0 |
#endif |
|
#ifdef FRAME_DEPTH_DEBUG |
# define FRAME_DEPTH_MSG(msg...) report_debug (msg) |
#else |
# define FRAME_DEPTH_MSG(msg...) |
#endif |
|
#ifdef RXML_PCODE_UPDATE_DEBUG |
# define PCODE_UPDATE_MSG(msg...) report_debug (msg) |
#else |
# define PCODE_UPDATE_MSG(msg...) |
#endif |
|
#define _LITERAL(X) #X |
#define LITERAL(X) _LITERAL (X) |
|
#define HASH_INT2(m, n) (n < 65536 ? (m << 16) + n : sprintf ("%x,%x", m, n)) |
|
#undef RXML_CONTEXT |
#define RXML_CONTEXT (_cur_rxml_context->get()) |
#define SET_RXML_CONTEXT(ctx) (_cur_rxml_context->set (ctx)) |
|
|
#define SCOPE_TYPE mapping(string:mixed)|object(Scope) |
#define UNWIND_STATE mapping(string|object:mixed|array) |
#define EVAL_ARGS_FUNC function(Context,Parser|PCode:mapping(string:mixed))|string |
|
|
constant pike_cycle_depth = 0; |
|
|
|
|
|
|
protected int tag_set_count = 0; |
|
protected mapping(RoxenModule|Configuration: |
mapping(string:TagSet|int)) all_tag_sets = ([]); |
|
|
|
|
|
|
|
|
|
|
protected Thread.Mutex all_tag_sets_mutex = Thread.Mutex(); |
|
#define LOOKUP_TAG_SET(owner, name) ((all_tag_sets[owner] || ([]))[name]) |
|
|
#define SET_TAG_SET(owner, name, value) do { \ |
mapping(string:TagSet|int) map = \ |
all_tag_sets[owner] || \ |
(all_tag_sets[owner] = set_weak_flag (([]), 1)); \ |
map[name] = (value); \ |
} while (0) |
|
protected mapping(string:program) reg_parsers = ([]); |
|
|
protected mapping(string:Type) reg_types = ([]); |
|
|
protected mapping(mixed:string) reverse_constants = set_weak_flag (([]), 1); |
|
|
|
|
class Tag |
|
{ |
constant is_RXML_Tag = 1; |
constant is_RXML_encodable = 1; |
constant is_RXML_p_code_frame = 1; |
constant is_RXML_p_code_entry = 1; |
|
|
|
|
|
|
|
TagSet tagset; |
|
|
|
|
|
|
|
mapping(string:Type) req_arg_types = ([]); |
mapping(string:Type) opt_arg_types = ([]); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Type def_arg_type = t_text (PEnt); |
|
|
|
|
Type content_type = t_same (PXml); |
|
|
|
|
|
|
|
|
|
|
|
|
|
array(Type) result_types = ({t_string, t_any_text}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final object `() (mapping(string:mixed) args, void|mixed content) |
|
|
|
{ |
object frame = |
([function(:object)] this_object()->Frame)(); |
frame->tag = this_object(); |
frame->flags = this_object()->flags; |
frame->args = args; |
frame->content = zero_type (content) ? nil : content; |
#ifdef RXML_OBJ_DEBUG |
frame->__object_marker->create (frame); |
#endif |
return frame; |
} |
|
int eval_args (mapping(string:mixed) args, void|int dont_throw, |
void|Context ctx, void|array(string) ignore_args) |
|
|
|
|
|
|
|
|
|
{ |
|
|
mapping(string:Type) atypes = args & req_arg_types; |
if (sizeof (atypes) < sizeof (req_arg_types)) |
if (dont_throw) return 0; |
else { |
array(string) missing = sort (indices (req_arg_types - atypes)); |
parse_error ("Required " + |
(sizeof (missing) > 1 ? |
"arguments " + String.implode_nicely (missing) + " are" : |
"argument " + missing[0] + " is") + " missing.\n"); |
} |
atypes += args & opt_arg_types; |
if (!ctx) ctx = RXML_CONTEXT; |
#ifdef MODULE_DEBUG |
if (mixed err = catch { |
#endif |
if (ignore_args) |
foreach (indices (args) - ignore_args, string arg) { |
Type t = atypes[arg] || def_arg_type; |
mixed v = t->eval_opt (args[arg], ctx); |
if (v == nil) |
set_nil_arg (args, arg, t, req_arg_types, ctx->id); |
else |
args[arg] = v; |
} |
else |
foreach (args; string arg; mixed val) { |
Type t = atypes[arg] || def_arg_type; |
mixed v = t->eval_opt (val, ctx); |
if (v == nil) |
set_nil_arg (args, arg, t, req_arg_types, ctx->id); |
else |
args[arg] = v; |
} |
#ifdef MODULE_DEBUG |
}) { |
if (objectp (err) && ([object] err)->thrown_at_unwind) |
fatal_error ("Can't save parser state when evaluating arguments.\n"); |
throw_fatal (err); |
} |
#endif |
return 1; |
} |
|
|
|
|
constant pike_cycle_depth = 0; |
|
#define MAKE_FRAME(_frame, _ctx, _parser, _args, _content) \ |
make_new_frame: do { \ |
if (UNWIND_STATE ustate = _ctx->unwind_state) \ |
if (ustate[_parser]) { \ |
_frame = [object/*(Frame)HMM*/] ustate[_parser][0]; \ |
m_delete (ustate, _parser); \ |
if (!sizeof (ustate)) _ctx->unwind_state = 0; \ |
break make_new_frame; \ |
} \ |
_frame = \ |
([function(:object/*(Frame)HMM*/)] this_object()->Frame)(); \ |
_frame->tag = this_object(); \ |
_frame->flags = this_object()->flags|FLAG_UNPARSED; \ |
_frame->args = _args; \ |
_frame->content = _content || ""; \ |
DO_IF_RXML_OBJ_DEBUG (_frame->__object_marker->create (_frame)); \ |
DO_IF_DEBUG( \ |
if (_args && ([mapping] (mixed) _args)["_debug_"]) { \ |
_frame->flags |= FLAG_DEBUG; \ |
m_delete (_args, "_debug_"); \ |
} \ |
); \ |
} while (0) |
|
#define EVAL_FRAME(_frame, _ctx, _parser, _type, _res) \ |
do { \ |
EVAL_ARGS_FUNC argfunc = 0; \ |
int orig_state_updated = _ctx->state_updated; \ |
if (mixed err = catch { \ |
_res = _frame->_eval (_ctx, _parser, _type); \ |
if (PCode p_code = _parser->p_code) \ |
p_code->add_frame (_ctx, _frame, _res, 1); \ |
}) \ |
if (objectp (err) && ([object] err)->thrown_at_unwind) { \ |
UNWIND_STATE ustate = _ctx->unwind_state; \ |
if (!ustate) ustate = _ctx->unwind_state = ([]); \ |
DO_IF_DEBUG ( \ |
if (err != _frame) \ |
fatal_error ("Unexpected unwind object catched.\n"); \ |
if (ustate[_parser]) \ |
fatal_error ("Clobbering unwind state for parser.\n"); \ |
); \ |
ustate[_parser] = ({_frame}); \ |
throw (_parser); \ |
} \ |
else { \ |
if (PCode p_code = _parser->p_code) { \ |
PCODE_UPDATE_MSG ( \ |
"%O (frame %O): Restoring p-code update count " \ |
"from %d to %d since the frame is stored unevaluated " \ |
"due to exception.\n", \ |
_ctx, _frame, _ctx->state_updated, orig_state_updated); \ |
_ctx->state_updated = orig_state_updated; \ |
p_code->add_frame (_ctx, _frame, PCode, 1); \ |
} \ |
ctx->handle_exception ( \ |
err, _parser); /* Will rethrow unknown errors. */ \ |
_res = nil; \ |
} \ |
} while (0) |
|
final mixed handle_tag (TagSetParser parser, mapping(string:string) args, |
void|string content) |
|
|
{ |
|
Context ctx = parser->context; |
object frame; |
MAKE_FRAME (frame, ctx, parser, args, content); |
if (!zero_type (frame->raw_tag_text)) |
frame->raw_tag_text = parser->raw_tag_text(); |
mixed result; |
EVAL_FRAME (frame, ctx, parser, parser->type, result); |
return result; |
} |
|
final array _p_xml_handle_tag (object parser, mapping(string:string) args, |
void|string content) |
{ |
Type type = parser->type; |
parser->drain_output(); |
Context ctx = parser->context; |
object frame; |
MAKE_FRAME (frame, ctx, parser, args, content); |
if (!zero_type (frame->raw_tag_text)) |
frame->raw_tag_text = parser->current_input(); |
mixed result; |
EVAL_FRAME (frame, ctx, parser, type, result); |
if (result != nil && result != empty) parser->add_value (result); |
return ({}); |
} |
|
final array _p_xml_handle_pi_tag (object parser, string content) |
{ |
Type type = parser->type; |
parser->drain_output(); |
|
sscanf (content, "%[ \t\n\r]%s", string ws, string rest); |
if (ws == "" && rest != "") { |
|
|
if (!type->free_text) |
return utils->unknown_pi_tag_error (parser, content); |
return 0; |
} |
|
Context ctx = parser->context; |
object frame; |
MAKE_FRAME (frame, ctx, parser, 0, content); |
if (!zero_type (frame->raw_tag_text)) |
frame->raw_tag_text = parser->current_input(); |
mixed result; |
EVAL_FRAME (frame, ctx, parser, type, result); |
if (result != nil && result != empty) parser->add_value (result); |
return ({}); |
} |
|
mapping(string:mixed) _eval_splice_args (Context ctx, |
mapping(string:string) raw_args, |
mapping(string:Type) my_req_args) |
|
|
{ |
|
mapping(string:Type) atypes = |
raw_args & (req_arg_types | opt_arg_types); |
if (my_req_args) { |
mapping(string:Type) missing = my_req_args - atypes; |
if (sizeof (missing)) |
parse_error ("Required " + |
(sizeof (missing) > 1 ? |
"arguments " + String.implode_nicely ( |
sort (indices (missing))) + " are" : |
"argument " + indices (missing)[0] + " is") + " missing.\n"); |
} |
|
#ifdef MODULE_DEBUG |
if (mixed err = catch { |
#endif |
foreach (raw_args; string arg; string val) { |
Type t = atypes[arg] || def_arg_type; |
if (t->parser_prog != PNone) { |
Parser parser = t->get_parser (ctx, ctx->tag_set, 0); |
TAG_DEBUG (RXML_CONTEXT->frame, |
"Evaluating argument value %s with %O\n", |
format_short (val), parser); |
|
parser->finish (val); |
mixed v = parser->eval(); |
t->give_back (parser, ctx->tag_set); |
|
if (v == nil) |
set_nil_arg (raw_args, arg, t, req_arg_types, ctx->id); |
else |
raw_args[arg] = v; |
|
TAG_DEBUG (RXML_CONTEXT->frame, |
"Setting dynamic argument %s to %s\n", |
format_short (arg), format_short (val)); |
} |
} |
#ifdef MODULE_DEBUG |
}) { |
if (objectp (err) && ([object] err)->thrown_at_unwind) |
fatal_error ("Can't save parser state when evaluating dynamic arguments.\n"); |
throw_fatal (err); |
} |
#endif |
|
return raw_args; |
} |
|
|
MARK_OBJECT; |
|
|
string _sprintf (void|int flag) |
{ |
return flag == 'O' && |
((function_name (object_program (this)) || "RXML.Tag") + |
"(" + [string] this->name + |
(this->plugin_name ? "#" + [string] this->plugin_name : "") + |
([int] this->flags & FLAG_PROC_INSTR ? " [PI]" : "") + ")" + |
OBJ_COUNT); |
} |
} |
|
|
class TagSet |
|
|
|
|
|
|
|
|
|
|
|
{ |
constant is_RXML_TagSet = 1; |
|
RoxenModule|Configuration owner; |
|
|
|
|
|
string name; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
array(TagSet) imported = ({}); |
|
|
|
|
|
|
|
|
|
|
|
function(Context:void) prepare_context; |
|
|
|
|
|
|
|
|
|
|
|
int generation = 1; |
|
|
|
int id_number; |
|
|
protected void create (RoxenModule|Configuration owner_, string name_, |
void|array(Tag) _tags) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{ |
if (RXML_CONTEXT && |
(!RXML_CONTEXT->id || |
!RXML_CONTEXT->id->misc->disable_tag_set_creation_warning)) { |
report_debug ( |
"Warning: Tag set %O in %O created during RXML evaluation.\n" |
"This doesn't work with p-code generation and should be avoided.\n", |
name_, owner_); |
#ifdef MODULE_DEBUG |
array bt = backtrace(); |
report_debug (describe_backtrace (bt)); |
#endif |
} |
|
|
id_number = ++tag_set_count; |
if (name_) { |
Thread.MutexKey key = all_tag_sets_mutex->lock (2); |
|
|
set_name (owner_, name_); |
key = 0; |
} |
else owner = owner_; |
if (_tags) add_tags (_tags); |
#ifdef RXML_OBJ_DEBUG |
__object_marker->create (this_object()); |
#endif |
} |
|
void add_tag (Tag tag) |
|
{ |
#ifdef MODULE_DEBUG |
if (!stringp (tag->name)) |
error ("Trying to register a tag %O without a name.\n", tag); |
if (!callablep (tag->Frame) && !tag->plugin_name) |
error ("Trying to register a tag %O without a Frame class or function.\n", tag); |
if (tag->name[..3] != "!--#" && |
replace (tag->name, "#<>& \t\n\r" / "", ({""}) * 8) != tag->name) |
error ("Invalid character(s) in name for tag %O.\n", tag); |
#endif |
if (tag->flags & FLAG_PROC_INSTR) { |
if (!proc_instrs) proc_instrs = ([]); |
if (tag->plugin_name) proc_instrs[tag->name + "#" + tag->plugin_name] = tag; |
else proc_instrs[tag->name] = tag; |
} |
else |
if (tag->plugin_name) tags[tag->name + "#" + tag->plugin_name] = tag; |
else tags[tag->name] = tag; |
tag->tagset = this_object(); |
#ifdef RXML_OBJ_DEBUG |
|
|
tag->__object_marker->create (tag); |
#endif |
changed(); |
} |
|
void add_tags (array(Tag) _tags) |
|
{ |
foreach (_tags, Tag tag) { |
#ifdef MODULE_DEBUG |
if (!stringp (tag->name)) |
error ("Trying to register a tag %O without a name.\n", tag); |
if (!callablep (tag->Frame)&& !tag->plugin_name) |
error ("Trying to register a tag %O without a Frame class or function.\n", tag); |
if (tag->name[..3] != "!--#" && |
replace (tag->name, "#<>& \t\n\r" / "", ({""}) * 8) != tag->name) |
error ("Invalid character(s) in name for tag %O.\n", tag); |
#endif |
if (tag->flags & FLAG_PROC_INSTR) { |
if (!proc_instrs) proc_instrs = ([]); |
if (tag->plugin_name) proc_instrs[tag->name + "#" + tag->plugin_name] = tag; |
else proc_instrs[tag->name] = tag; |
} |
else |
if (tag->plugin_name) tags[tag->name + "#" + tag->plugin_name] = tag; |
else tags[tag->name] = tag; |
tag->tagset = this_object(); |
#ifdef RXML_OBJ_DEBUG |
|
|
tag->__object_marker->create (tag); |
#endif |
} |
changed(); |
} |
|
void remove_tag (string|Tag tag, void|int proc_instr) |
|
|
|
|
{ |
if (stringp (tag)) |
if (proc_instr) { |
if (proc_instrs) m_delete (proc_instrs, tag); |
} |
else |
m_delete (tags, tag); |
else { |
string n; |
if (tag->flags & FLAG_PROC_INSTR) { |
if (proc_instrs && !zero_type (n = search (tags, [object(Tag)] tag))) |
m_delete (proc_instrs, n); |
} |
else |
if (!zero_type (n = search (tags, [object(Tag)] tag))) |
m_delete (tags, n); |
} |
changed(); |
} |
|
void clear() |
|
|
{ |
tags = ([]), proc_instrs = 0; |
clear_string_entities(); |
} |
|
local Tag get_local_tag (string name, void|int proc_instr) |
|
|
|
{ |
return proc_instr ? proc_instrs && proc_instrs[name] : tags[name]; |
} |
|
local array(Tag) get_local_tags() |
|
{ |
array(Tag) res = values (tags); |
if (proc_instrs) res += values (proc_instrs); |
return res; |
} |
|
local Tag get_tag (string name, void|int proc_instr) |
|
|
|
|
{ |
if (object(Tag) def = get_local_tag (name, proc_instr)) |
return def; |
foreach (imported, TagSet tag_set) |
if (object(Tag) tag = [object(Tag)] tag_set->get_tag (name, proc_instr)) |
return tag; |
return 0; |
} |
|
local int has_tag (Tag tag) |
|
|
{ |
return !!get_tag (tag->name, tag->flags & FLAG_PROC_INSTR); |
} |
|
local multiset(string) get_tag_names() |
|
{ |
return `| ((multiset) indices (tags), @imported->get_tag_names()); |
} |
|
local multiset(string) get_proc_instr_names() |
|
{ |
return `| (proc_instrs ? (multiset) indices (proc_instrs) : (<>), |
@imported->get_proc_instr_names()); |
} |
|
local Tag get_overridden_tag (Tag overrider) |
|
|
{ |
if (!mappingp (overridden_tag_lookup)) |
overridden_tag_lookup = set_weak_flag (([]), 1); |
Tag tag; |
if (zero_type (tag = overridden_tag_lookup[overrider])) { |
string overrider_name = overrider->plugin_name ? |
overrider->plugin_name + "#" + overrider->name : overrider->name; |
tag = overridden_tag_lookup[overrider] = |
overrider->flags & FLAG_PROC_INSTR ? |
find_overridden_proc_instr (overrider, overrider_name) : |
find_overridden_tag (overrider, overrider_name); |
} |
return tag; |
} |
|
local array(Tag) get_overridden_tags (string name, void|int proc_instr) |
|
|
|
|
{ |
if (object(Tag) def = get_local_tag (name, proc_instr)) |
return ({def}) + imported->get_overridden_tags (name, proc_instr) * ({}); |
else |
return imported->get_overridden_tags (name, proc_instr) * ({}); |
} |
|
void add_string_entities (mapping(string:string) entities) |
|
|
|
{ |
if (string_entities) string_entities |= entities; |
else string_entities = entities + ([]); |
changed(); |
} |
|
void clear_string_entities() |
|
{ |
string_entities = 0; |
changed(); |
} |
|
local mapping(string:string) get_string_entities() |
|
|
{ |
if (string_entities) |
return `+(@imported->get_string_entities(), string_entities); |
else |
return `+(@imported->get_string_entities(), ([])); |
} |
|
local mapping(string:Tag) get_plugins (string name, void|int proc_instr) |
|
|
|
|
{ |
mapping(string:Tag) res; |
if (proc_instr) { |
if (!pi_plugins) pi_plugins = ([]); |
if ((res = pi_plugins[name])) return res; |
low_get_pi_plugins (name + "#", res = ([])); |
return pi_plugins[name] = res; |
} |
else { |
if (!plugins) plugins = ([]); |
if ((res = plugins[name])) return res; |
low_get_plugins (name + "#", res = ([])); |
return plugins[name] = res; |
} |
} |
|
local string get_hash() |
|
|
|
|
|
|
|
|
|
{ |
if (!hash) |
hash = Crypto.MD5.hash (encode_value_canonic (get_hash_data())); |
return hash; |
} |
|
local void add_tag_set_dependency (TagSet tset) |
|
|
|
|
|
|
|
|
{ |
dep_tag_sets[tset] = 1; |
tset->do_notify (changed); |
changed(); |
} |
|
local void remove_tag_set_dependency (TagSet tset) |
|
{ |
dep_tag_sets[tset] = 0; |
tset->dont_notify (changed); |
} |
|
local int has_effective_tags (TagSet tset) |
|
{ |
return tset == top_tag_set && !got_local_tags; |
} |
|
local mixed `->= (string var, mixed val) |
{ |
switch (var) { |
case "owner": { |
Thread.MutexKey key = all_tag_sets_mutex->lock (2); |
|
|
if (name) SET_TAG_SET (owner, name, generation); |
set_name (val, name); |
break; |
} |
case "name": { |
Thread.MutexKey key = all_tag_sets_mutex->lock (2); |
|
|
if (name) SET_TAG_SET (owner, name, generation); |
set_name (owner, val); |
break; |
} |
case "imported": |
if (!val) return val; |
filter (imported, "dont_notify", changed); |
imported = [array(TagSet)] val; |
imported->do_notify (changed); |
top_tag_set = sizeof (imported) && imported[0]; |
break; |
default: |
::`->= (var, val); |
} |
changed(); |
return val; |
} |
|
local mixed `[]= (string var, mixed val) {return `->= (var, val);} |
|
final Context new_context (void|RequestID id) |
|
|
|
|
{ |
Context ctx = Context (this_object(), id); |
call_prepare_funs (ctx); |
return ctx; |
} |
|
final Parser get_parser (Type top_level_type, void|RequestID id, void|int make_p_code) |
|
|
|
|
{ |
|
|
return [object(Parser)](mixed) |
new_context (id)->new_parser (top_level_type, make_p_code); |
} |
|
final Parser `() (Type top_level_type, void|RequestID id, void|int make_p_code) |
|
{ |
return get_parser (top_level_type, id, make_p_code); |
} |
|
void changed() |
|
|
{ |
#ifdef TAGSET_GENERATION_DEBUG |
werror ("%O update, generation %d -> %d\n", this_object(), |
generation, generation + 1); |
#endif |
generation++; |
prepare_funs = 0; |
overridden_tag_lookup = 0; |
plugins = pi_plugins = 0; |
hash = 0; |
(notify_funcs -= ({0}))(); |
set_weak_flag (notify_funcs, 1); |
got_local_tags = sizeof (tags) || (proc_instrs && sizeof (proc_instrs)); |
#ifdef TAGSET_GENERATION_DEBUG |
werror ("%O update done, generation %d -> %d\n", this_object(), |
generation - 1, generation); |
#endif |
} |
|
function(Backtrace,Type:string) handle_run_error = |
lambda (Backtrace err, Type type) |
|
|
|
{ |
string result; |
foreach(imported, TagSet tag_set) { |
result = tag_set->handle_run_error(err, type); |
if(result) return result; |
} |
return 0; |
}; |
|
function(Backtrace,Type:string) handle_parse_error = |
lambda (Backtrace err, Type type) |
|
|
|
{ |
string result; |
foreach(imported, TagSet tag_set) { |
result = tag_set->handle_parse_error(err, type); |
if(result) return result; |
} |
return 0; |
}; |
|
|
|
|
constant pike_cycle_depth = 0; |
|
void do_notify (function(:void) func) |
{ |
notify_funcs |= ({func}); |
set_weak_flag (notify_funcs, 1); |
} |
|
void dont_notify (function(:void) func) |
{ |
notify_funcs -= ({func}); |
set_weak_flag (notify_funcs, 1); |
} |
|
array(TagSet) tag_set_components() |
|
|
|
{ |
return !sizeof (tags) && !proc_instrs && !string_entities && |
sizeof (imported) == 2 && imported; |
} |
|
protected void destroy() |
{ |
catch (changed()); |
if (name && global::this) SET_TAG_SET (owner, name, generation); |
} |
|
protected void set_name (Configuration new_owner, string new_name) |
|
{ |
if (new_name) { |
object(TagSet)|int old_tag_set = LOOKUP_TAG_SET (owner, name); |
if (objectp (old_tag_set)) { |
|
|
|
|
|
old_tag_set = old_tag_set->generation; |
} |
if (generation <= old_tag_set) generation = old_tag_set; |
owner = new_owner; |
name = new_name; |
SET_TAG_SET (owner, name, this_object()); |
} |
else { |
owner = new_owner; |
name = 0; |
} |
} |
|
protected mapping(string:Tag) tags = ([]), proc_instrs; |
|
|
protected mapping(string:string) string_entities; |
|
|
|
protected TagSet top_tag_set; |
|
|
protected int got_local_tags; |
|
|
protected array(function(:void)) notify_funcs = ({}); |
|
|
protected array(function(Context:void)) prepare_funs; |
|
protected multiset(TagSet) dep_tag_sets = set_weak_flag ((<>), 1); |
|
array(function(Context:void)) get_prepare_funs() |
{ |
if (prepare_funs) return prepare_funs; |
array(function(Context:void)) funs = ({}); |
for (int i = sizeof (imported) - 1; i >= 0; i--) |
funs += imported[i]->get_prepare_funs(); |
if (prepare_context) funs += ({prepare_context}); |
|
return funs; |
} |
|
final void call_prepare_funs (Context ctx) |
{ |
if (!prepare_funs) prepare_funs = get_prepare_funs(); |
(prepare_funs -= ({0})) (ctx); |
} |
|
protected array(function(Context:void)) eval_finish_funs; |
|
array(function(Context:void)) get_eval_finish_funs() |
{ |
if (eval_finish_funs) return eval_finish_funs; |
array(function(Context:void)) funs = ({}); |
for (int i = sizeof (imported) - 1; i >= 0; i--) |
funs += imported[i]->get_eval_finish_funs(); |
if (this->eval_finish) funs += ({this->eval_finish}); |
|
return funs; |
} |
|
void call_eval_finish_funs (Context ctx) |
{ |
if (!eval_finish_funs) eval_finish_funs = get_eval_finish_funs(); |
(eval_finish_funs -= ({0})) (ctx); |
} |
|
protected mapping(Tag:Tag) overridden_tag_lookup; |
|
Tag find_overridden_tag (Tag overrider, string overrider_name) |
{ |
if (tags[overrider_name] == overrider) { |
foreach (imported, TagSet tag_set) |
if (object(Tag) overrider = tag_set->get_tag (overrider_name)) |
return overrider; |
} |
else { |
int found = 0; |
foreach (imported, TagSet tag_set) |
if (object(Tag) subtag = tag_set->get_tag (overrider_name)) |
if (found) return subtag; |
else if (subtag == overrider) |
if ((subtag = tag_set->find_overridden_tag ( |
overrider, overrider_name))) |
return subtag; |
else found = 1; |
} |
return 0; |
} |
|
Tag find_overridden_proc_instr (Tag overrider, |
string overrider_name) |
{ |
if (proc_instrs && proc_instrs[overrider_name] == overrider) { |
foreach (imported, TagSet tag_set) |
if (object(Tag) overrider = tag_set->get_tag (overrider_name, 1)) |
return overrider; |
} |
else { |
int found = 0; |
foreach (imported, TagSet tag_set) |
if (object(Tag) subtag = tag_set->get_tag (overrider_name, 1)) |
if (found) return subtag; |
else if (subtag == overrider) |
if ((subtag = tag_set->find_overridden_proc_instr ( |
overrider, overrider_name))) |
return subtag; |
else found = 1; |
} |
return 0; |
} |
|
protected mapping(string:mapping(string:Tag)) plugins, pi_plugins; |
|
void low_get_plugins (string prefix, mapping(string:Tag) res) |
{ |
for (int i = sizeof (imported) - 1; i >= 0; i--) |
imported[i]->low_get_plugins (prefix, res); |
foreach (tags; string name; Tag tag) |
if (has_prefix (name, prefix)) |
if (tag->plugin_name) res[[string] tag->plugin_name] = tag; |
|
} |
|
void low_get_pi_plugins (string prefix, mapping(string:Tag) res) |
{ |
for (int i = sizeof (imported) - 1; i >= 0; i--) |
imported[i]->low_get_pi_plugins (prefix, res); |
if (proc_instrs) |
foreach (proc_instrs; string name; Tag tag) |
if (name[..sizeof (prefix) - 1] == prefix) |
if (tag->plugin_name) res[[string] tag->plugin_name] = tag; |
|
} |
|
protected string hash; |
|
array get_hash_data() |
{ |
return ({ |
this_object()->prefix, |
this_object()->prefix_req, |
mkmultiset (indices (tags)), |
proc_instrs && mkmultiset (indices (proc_instrs)), |
string_entities, |
}) + imported->get_hash_data() + |
({0}) + (indices (dep_tag_sets) - ({0}))->get_hash_data(); |
} |
|
string tag_set_component_names() |
{ |
return name || sizeof (imported) && imported->tag_set_component_names() * "+"; |
} |
|
string _sprintf (void|int flag) |
{ |
if (flag != 'O') return 0; |
return (function_name (object_program (this)) || "RXML.TagSet") + |
"(" + |
|
(string) (owner && (owner->is_module ? |
owner->module_local_id() : |
owner->name)) + |
"," + tag_set_component_names() + ")" + OBJ_COUNT; |
|
} |
|
|
MARK_OBJECT_ONLY; |
|
} |
|
TagSet empty_tag_set; |
|
|
TagSet shared_tag_set (RoxenModule|Configuration owner, string name, void|array(Tag) tags) |
|
|
|
|
{ |
Thread.MutexKey key = all_tag_sets_mutex->lock(); |
if (TagSet tag_set = LOOKUP_TAG_SET (owner, name)) |
if (objectp (tag_set)) |
return tag_set; |
return TagSet (owner, name, tags); |
} |
|
protected class CompositeTagSet |
{ |
inherit TagSet; |
|
protected void create (TagSet... tag_sets) |
{ |
|
id_number = ++tag_set_count; |
#ifdef RXML_OBJ_DEBUG |
__object_marker->create (this_object()); |
#endif |
|
this->imported = tag_sets; |
} |
|
string _sprintf (void|int flag) |
{ |
if (flag != 'O') return 0; |
return "RXML.CompositeTagSet(" + tag_set_component_names() + ")" + |
OBJ_COUNT; |
|
} |
} |
|
protected mapping(int|string:CompositeTagSet) garb_composite_tag_set_cache() |
{ |
call_out (garb_composite_tag_set_cache, 30*60); |
return composite_tag_set_cache = ([]); |
} |
|
protected mapping(int|string:CompositeTagSet) composite_tag_set_cache = |
garb_composite_tag_set_cache(); |
|
#define GET_COMPOSITE_TAG_SET(a, b, res) do { \ |
int|string hash = HASH_INT2 (b->id_number, a->id_number); \ |
if (!(res = composite_tag_set_cache[hash])) \ |
/* Race, but it doesn't matter. */ \ |
res = composite_tag_set_cache[hash] = CompositeTagSet (a, b); \ |
} while (0) |
|
|
class Value |
|
|
{ |
mixed rxml_var_eval (Context ctx, string var, string scope_name, void|Type type) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|