Roxen.git
/
server
/
etc
/
modules
/
Roxen.pmod
version
»
Context lines:
10
20
40
80
file
none
3
Roxen.git/server/etc/modules/Roxen.pmod:619:
if (sizeof (args)) message = sprintf (message, @args); HTTP_WERR ("Return status " + status_code + " " + message); return (["error": status_code, "rettext": message]); } else { HTTP_WERR ("Return status " + status_code); return (["error": status_code]); } }
+
mapping(string:mixed) http_xml_status(int status_code,
+
Parser.XML.Tree.SimpleNode message)
+
//! Return a response mapping with the specified HTTP @[status_code] and
+
//! XML @[message]. As opposed to @[http_status()], the @[message] is XML
+
//! which can be included directly into multistatus responses in WebDAV.
+
{
+
mapping ret = ([
+
"error": status_code,
+
"xml": message,
+
"type": "application/xml; charset='utf-8'",
+
]);
+
+
Parser.XML.Tree.SimpleRootNode root = Parser.XML.Tree.SimpleRootNode()->
+
add_child(Parser.XML.Tree.SimpleHeaderNode((["version": "1.0",
+
"encoding": "utf-8"])))->
+
add_child(message);
+
ret->data = root->render_xml();
+
+
HTTP_WERR("Return XML status " + status_code);
+
return ret;
+
}
+
+
mapping(string:mixed) http_dav_error(int status_code, string error_type)
+
//! Return a response mapping with the specified HTTP @[status_code] and
+
//! XML message.
+
//!
+
//! @param status_code
+
//! HTTP status code, typically one of @expr{409@} (Conflict),
+
//! @expr{423@} (Locked) or @expr{403@} (Forbidden).
+
//!
+
//! @param error_type
+
//! Name of DAV XML error node to generate. It will be embedded
+
//! as the single element in a @tt{DAV:error@} element.
+
//!
+
//! This function simplifies some common cases where @[http_xml_status()]
+
//! would otherwise be used.
+
//!
+
//! @seealso
+
//! @[http_xml_status()]
+
{
+
Parser.XML.Tree.SimpleNode node =
+
Parser.XML.Tree.SimpleElementNode("DAV:error", ([]))->
+
add_child(Parser.XML.Tree.SimpleElementNode("DAV:" + error_type, ([])));
+
return http_xml_status(status_code, node);
+
}
+
mapping(string:mixed) http_method_not_allowed ( string allowed_methods, void|string message, mixed... args) //! Make a HTTP 405 method not allowed response with the required //! Allow header containing @[allowed_methods], which is a comma //! separated list of HTTP methods, e.g. @expr{"GET, HEAD"@}. { mapping(string:mixed) response = http_status (Protocols.HTTP.HTTP_METHOD_INVALID, message, @args); response->extra_heads = (["Allow": allowed_methods]); return response;
Roxen.git/server/etc/modules/Roxen.pmod:5873:
protected string _sprintf (int flag) { return flag == 'O' && "Roxen.compat_5_1_null"; } } Compat51Null compat_5_1_null = Compat51Null();
+
mapping(string:string) thread_names = ([]);
+
+
string thread_name_from_addr(string hex_addr)
+
{
+
// Lookup using a key like "Thread.Thread(0x...)" that matches what
+
// sprint("%O") generates.
+
string th_key = "Thread.Thread(" + hex_addr + ")";
+
return thread_names[th_key];
+
}
+
+
string thread_name( object thread, int|void skip_auto_name )
+
{
+
string tn;
+
if( thread_names[ tn=sprintf("%O",thread) ] || skip_auto_name )
+
return thread_names[tn];
+
return tn;
+
}
+
+
void name_thread( object thread, string name )
+
{
+
string th_key = sprintf("%O", thread);
+
if (name)
+
thread_names[th_key] = name;
+
else
+
m_delete(thread_names, th_key);
+
}
+
+
#ifdef REQUEST_TRACE protected string trace_msg (mapping id_misc, string msg, string|int name_or_time, int enter) { array(string) lines = msg / "\n"; if (lines[-1] == "") lines = lines[..<1]; if (sizeof (lines)) { #if TOSTR (REQUEST_TRACE) == "TIMES" string byline = sprintf ("%*s%c %s",
Roxen.git/server/etc/modules/Roxen.pmod:6236:
{ if (line_buf != "") werror (prefix + line_buf + "\n"); read_end->set_read_callback (0); read_end->set_close_callback (0); read_end->set_id (0); } protected void log_pipe_read_thread (Stdio.File read_end) {
-
roxen->
name_thread(this_thread(), "Log pipe");
+
name_thread(this_thread(), "Log pipe");
while (1) { string data = read_end->read (1024, 1); if (!data || data == "") break; read_cb (read_end, data); } close_cb (read_end);
-
roxen->
name_thread(this_thread(), 0);
+
name_thread(this_thread(), 0);
} protected void create (Stdio.File read_end, Stdio.File write_end) { thread_create (log_pipe_read_thread, read_end); assign (write_end); } void set_prefix (string prefix) //! Sets a string that will be prefixed to each line that is logged
Roxen.git/server/etc/modules/Roxen.pmod:6354:
if(sizeof(rows) < 2) return default_value; array values = (rows[1]/" ") - ({ "" }); if(sizeof(values) < 3) return default_value; return ([ "virtual": (int)values[1]/divisor, "resident": (int)values[2]/divisor ]); }
+
protected mapping(string:int) caches_initialized = ([]);
+
+
protected void init_cache_prefs(string cache_name)
+
{
+
if (caches_initialized[cache_name]) return;
+
+
// NB: We invalidate entries after successful lookup,
+
// if they don't seem to be valid anymore.
+
function cache_register =
+
all_constants()["cache"]["cache_register"];
+
object extend_entries_cache_prefs =
+
all_constants()["cache"]["extend_entries_cache_prefs"];
+
cache_register(cache_name, UNDEFINED, extend_entries_cache_prefs);
+
caches_initialized[cache_name] = 1;
+
}
+
string lookup_real_path_case_insens (string path, void|int no_warn, void|string charset) //! Looks up the given path case insensitively to a path in the real //! file system. I.e. all segments in @[path] that exist in the file //! system when matched case insensitively are converted to the same //! case they have when listed by @[get_dir]. Segments that don't //! exist are kept as-is. //! //! If a segment ambiguously matches several entries in a directory //! then it and all remaining segments are returned as-is. A warning
Roxen.git/server/etc/modules/Roxen.pmod:6397:
//! changed in case. { ASSERT_IF_DEBUG (is_absolute_path (path)); string cache_name = "case_insens_paths"; function(string:string) encode, decode; switch (charset && lower_case(charset)) { case 0: // NB: NT has a filesystem that uses UTF-16.
-
#
ifndef
__NT__
+
#
if
!defined(
__NT__
) || constant(Stdio.__HAVE_UTF8_FS__)
return string_to_utf8(this_function(utf8_to_string(path), no_warn, "utf8")); #endif break; case "utf8": case "utf-8": encode = string_to_utf8; decode = utf8_to_string; cache_name += ":utf8"; break; default: Charset.Encoder enc = Charset.encoder (charset); Charset.Decoder dec = Charset.decoder (charset); encode = lambda (string in) {return enc->feed (in)->drain();}; decode = lambda (string in) {return dec->feed (in)->drain();}; cache_name += ":" + enc->charset; break; }
-
+
init_cache_prefs(cache_name);
+
string dec_path, enc_path; int nonexist; void recur (string path) { string lc_path = lower_case (path); dec_path = cache_lookup (cache_name, lc_path); if (dec_path) { check_cached: {