14
14
* along with this program; if not, write to the Free Software
15
15
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
* $Id: httplib.pmod,v 1.2 2005/04/27 15:22:53 astra Exp $
17
* $Id: httplib.pmod,v 1.7 2006/08/26 10:23:28 dbuese Exp $
20
constant cvs_version="$Id: httplib.pmod,v 1.2 2005/04/27 15:22:53 astra Exp $";
20
constant cvs_version="$Id: httplib.pmod,v 1.7 2006/08/26 10:23:28 dbuese Exp $";
22
22
#include <config.h>
23
23
#include <macros.h>
30
30
"Jul":6, "Aug":7, "Sep":8, "Oct":9, "Nov":10, "Dec":11,
31
31
"jan":0, "feb":1, "mar":2, "apr":3, "may":4, "jun":5,
32
32
"jul":6, "aug":7, "sep":8, "oct":9, "nov":10, "dec":11,]);
33
constant montharr = ({ "Jan", "Feb", "Mar", "Apr", "Mai", "Jun", "Jul", "Aug",
33
constant montharr = ({ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug",
34
34
"Sep", "Oct", "Nov", "Dec" });
316
315
string error_page(string message, string|void back)
321
xsl = find_object("/stylesheets/errors.xsl");
322
xml = "<?xml version='1.0' encoding='utf-8'?>"+
323
"<error><actions/>\n<message><![CDATA["+message+
324
"]]></message></error>";
325
return _Server->get_module("libxslt")->run(xml, xsl, (["back": back,]) );
318
// need a webinterface version check here
319
object web = _Server->get_module("package:web");
320
string wi_version = "0.0.0";
321
if (objectp(web)) wi_version = web->get_version();
322
array wiv = wi_version / ".";
323
// if webinterface version >= 2.1, then use new method respecting user
324
// stylesheet setting (and may use internationalization in the future..)
325
if ( (sizeof(wiv) > 0 && (int)wiv[0]>2) || (sizeof(wiv) > 1 && (int)wiv[0]>=2 && (int)wiv[1]>=1) ) {
329
object user = geteuid();
330
if (!objectp(user)) user = this_user();
332
if (objectp(user)) css_style = user->query_attribute("USER_CSS_STYLE");
333
xsl = find_object("/stylesheets/errors.xsl");
334
xml = "<?xml version='1.0' encoding='utf-8'?>"+
336
if (objectp(css_style)) {
337
xml += "<properties><css_style><Object><path>"+
338
_Server->get_module("filepath:tree")->object_to_filename(css_style)+
339
"</path></Object></css_style></properties>";
341
xml += "<actions/>\n<message><![CDATA["+message+
342
"]]></message></Object>";
344
mapping myvars = ([]);
345
myvars["back"] = back;
346
myvars["message"] = message;
348
// doesnt work yet, need help and more testing
349
// produces strange error "Start Tag expected..." but xsl.xml file looks fine ?!
350
xml = _Server->get_module("Converter:XML")->get_xml(this(), xsl, myvars, 0);
351
werror("xml="+xml+"\r\n");
353
html = _Server->get_module("libxslt")->run(xml, xsl, myvars );
355
else { // do it the old-fashioned way...
358
xsl = find_object("/stylesheets/errors.xsl");
359
xml = "<?xml version='1.0' encoding='utf-8'?>"+
360
"<error><actions/>\n<message><![CDATA["+message+
361
"]]></message></error>";
362
html = _Server->get_module("libxslt")->run(xml, xsl, (["back": back,]) );
339
378
return "<![CDATA["+replace_uml(str)+"]]>";
381
string encode_url(string str)
383
return replace_uml(str);
342
386
string replace_uml(string str)
344
388
if ( !stringp(str) )
348
({ "�", "�", "�", "�", "�", "�", "�", "<", ">", "?", " ", "#", ":", "\303\244", "\303\266", "\303\274", "\303\234", "\303\204", "\303\226", "\303\237", "\"" }),
349
({ "%e4", "%f6", "%fc", "%c4", "%d6", "%dc", "%df",
350
"%3c", "%3e", "%3f", "%20", "%23", "%3a", "%C3%A4", "%C3%B6", "%C3%BC", "%C3%9C", "%C3%84", "%C3%96", "%C3%9F", "%2d" }));
353
({ "�", "�", "�", "�", "�", "�", "�", "<", ">", "?", " ", "#", ":" }),
354
({ "%e4", "%f6", "%fc", "%c4", "%d6", "%dc", "%df",
355
"%3c", "%3e", "%3f", "%20", "%23", "%3a" }));
391
for ( int i = 0; i < sizeof(str); i++ ) {
454
if ( str[i] >= 128 ) {
455
result += sprintf("%%%x", str[i]);
464
return replace(result,
465
({ "�", "�", "�", "�", "�", "�", "�", "<", ">", "?", " ", "#", ":", "\303\244", "\303\266", "\303\274", "\303\234", "\303\204", "\303\226", "\303\237", "\"" }),
466
({ "%e4", "%f6", "%fc", "%c4", "%d6", "%dc", "%df",
467
"%3c", "%3e", "%3f", "%20", "%23", "%3a", "%C3%A4", "%C3%B6", "%C3%BC", "%C3%9C", "%C3%84", "%C3%96", "%C3%9F", "%2d" }));
455
569
result_page(string message, string next, string|void title, string|void head)
460
if ( !stringp(title) ) title = "Result";
461
if ( !stringp(head) ) head = "";
463
xsl = find_object("/stylesheets/result.xsl");
464
xml = "<?xml version='1.0' encoding='utf-8'?>"+
466
"<head><![CDATA["+head+"]]></head>"+
467
"<title>"+title+"</title><actions/>\n<message><![CDATA["+message+
468
"]]></message></result>";
469
return get_module("libxslt")->run(xml, xsl, (["back": next,]) );
572
// need a webinterface version check here
573
object web = _Server->get_module("package:web");
574
string wi_version = "0.0.0";
575
if (objectp(web)) wi_version = web->get_version();
576
array wiv = wi_version / ".";
577
// if webinterface version >= 2.1, then use new method respecting user
578
// stylesheet setting (and may use internationalization in the future..)
579
if ( (sizeof(wiv) > 0 && (int)wiv[0]>2) || (sizeof(wiv) > 1 && (int)wiv[0]>=2 && (int)wiv[1]>=1) ) {
583
if ( !stringp(title) ) title = "Result";
584
if ( !stringp(head) ) head = "";
586
object user = geteuid();
587
if (!objectp(user)) user = this_user();
589
if (objectp(user)) css_style = user->query_attribute("USER_CSS_STYLE");
590
xsl = find_object("/stylesheets/result.xsl");
591
xml = "<?xml version='1.0' encoding='utf-8'?>"+
593
if (objectp(css_style)) {
594
xml += "<properties><css_style><Object><path>"+
595
_Server->get_module("filepath:tree")->object_to_filename(css_style)+
596
"</path></Object></css_style></properties>";
598
xml += "<head><![CDATA["+head+"]]></head>"+
599
"<title>"+title+"</title><actions/>\n<message><![CDATA["+message+
600
"]]></message></Object>";
601
mapping myvars = ([]);
602
myvars["back"] = next;
603
myvars["title"] = title;
604
myvars["head"] = head;
605
myvars["message"] = message;
607
// doesnt work yet, need help and more testing
608
// produces strange error "Start Tag expected..." but xsl.xml file looks fine ?!
609
xml = _Server->get_module("Converter:XML")->get_xml(this(), xsl, myvars, 0);
610
werror("xml="+xml+"\r\n");
612
html = _Server->get_module("libxslt")->run(xml, xsl, myvars );
614
else { // do it the old-fashioned way...
618
if ( !stringp(title) ) title = "Result";
619
if ( !stringp(head) ) head = "";
621
xsl = find_object("/stylesheets/result.xsl");
622
xml = "<?xml version='1.0' encoding='utf-8'?>"+
624
"<head><![CDATA["+head+"]]></head>"+
625
"<title>"+title+"</title><actions/>\n<message><![CDATA["+message+
626
"]]></message></result>";
627
html = _Server->get_module("libxslt")->run(xml, xsl, (["back": next,]) );
473
634
* Return a mapping in appropriate format for Protocols.HTTP to handle.
475
636
* @param int code - the http return code.
476
637
* @return mapping suitable for Protocols.HTTP
478
mapping low_answer(int code, string response)
639
mapping low_answer(int code, string response, void|mapping extra)
480
return ([ "error": code, "data": response, ]);
641
mapping answer = ([ "error": code, "rettext": response, ]);
642
if ( mappingp(extra) )
643
answer->extra_heads = extra;
561
xml = get_module("Converter:XML")->get_xml(
562
obj, xsl, vars, (int)vars["active"]);
726
xml = _Server->get_module("Converter:XML")->get_xml(obj, xsl,
727
vars, (int)vars["active"]);
565
729
if ( vars->source == "true" )
568
html = get_module("libxslt")->run(xml, xsl, vars);
732
html = _Server->get_module("libxslt")->run(xml, xsl, vars);
877
* Get the appropriate stylesheet for an object (usually xml document)
878
* checks for xsl:document
880
* @param object obj - the object to show
881
* @return the appropriate stylesheet to be used using xsl:document or xsl:public
883
object get_stylesheet(object obj)
886
xsl = find_user_stylesheet(this_user(), obj, "document");
887
if ( !objectp(xsl) ) {
888
if ( obj->query_attribute("xsl:use_public") )
889
return obj->query_attribute("xsl:public");
891
if ( obj->query_attribute(DOC_MIME_TYPE) == "text/xml" ) {
892
string content = obj->get_content();
893
if ( stringp(content) && content != "" ) {
895
object node = xmlDom.parse(content);
896
mapping pi = node->get_pi();
897
if ( pi["xml-stylesheet"] ) {
900
if ( !arrayp(pi["xml-stylesheet"]) )
901
stylesheets = ({ pi["xml-stylesheet"] });
903
stylesheets = pi["xml-stylesheet"];
904
foreach(stylesheets, string stylesheet ) {
906
object fp = _Server->get_module("filepath:tree");
907
object env = obj->get_environment();
908
string type = "text/xsl";
909
if ( search(stylesheet, "type=") >= 0 )
910
sscanf(stylesheet, "%*shref=\"%s\"%*s", type);
911
if ( type == "text/xsl" &&
912
sscanf(stylesheet, "%*shref=\"%s\"%*s", styleref) )
914
if ( sscanf(styleref, "%s.css", styleref) )
917
if ( styleref[0] != '/' )
918
return fp->resolve_path(env,styleref);
920
return fp->path_to_object(styleref);
713
932
string execute(mapping vars) {
745
964
result = rxml(result, ([ ]), (["a": tagTag(), ]));
746
965
if ( result != "<BODY><?xml version='1.0'?>\n\n<x>test</x></BODY>" )
747
966
error("Failed test with rxml tag with xml in body.\n");
969
string get_tag_name(object tag)
971
string name = tag->get_identifier();
972
sscanf(name, "%s.pike", name);
976
function get_tag_function(object tag)
981
instance = tag->get_instance();
982
if ( !objectp(instance) )
985
return instance->execute;
988
function find_tag(string name)
990
object tags = OBJ("/tags");
991
if ( !objectp(tags) )
993
object tag = tags->get_object_byname(name+".pike");
996
return get_tag_function(tag);
1000
mapping find_tags(object obj)
1002
if ( !objectp(obj) )
1004
if ( obj->get_object_class() & CLASS_CONTAINER ) {
1005
mapping result = ([ ]);
1006
foreach(obj->get_inventory_by_class(CLASS_DOCLPC), object tag) {
1007
function f = get_tag_function(tag);
1008
string tagname = get_tag_name(tag);
1009
if ( !functionp(f) )
1010
MESSAGE("Warning - no tag function for tag: %s", tagname);
1012
result[tagname] = f;
1016
else if ( obj->get_object_class() & CLASS_DOCXSL) {
1017
object env = obj->get_environment();
1019
return find_tags(env->get_object_byname("tags"));