string cvs_version = "$Id: "; int thread_safe=1; #include #include #include inherit "module"; inherit "roxenlib"; // NOTE: // the following functions require the C perplex functions // in Rawww.so inherit Rawww; //------------------------------------------------------------ // GLOBALS!!!! // none //------------------------------------------------------------ // setup functions array register_module() { return ({ MODULE_PARSER, "Perpl module", ("Adds RN proprietary Perplex tags to RXML -- use the" " <perplhelp> tag to get information on all the tags"), 0, 1 }); } // register_module void create() { } // create //------------------------------------------------------------ // here is where the work gets done //------------------------------------------------------------ // this routine parses a vertbar delimited line for name=value // pairs, and returns a mapping of the pairs // note: this will get confused by extra vert.bars or = in the // input; at some point maybe go back and rewrite it using // regexps (maybe) // // the input is split by vert. bars; the first = is taken // as the name/value delimiter. If there is no = in the // string, no name/value pair is kept int perpl_parseVertBarLine( mapping theMapping, string input ) { string pairString; int count = 0; foreach ( input/"\|",pairString ) { int delim = search( pairString,"=" ); int end = sizeof(pairString) - 1; if ( delim > 0 && delim < end ) { string name = pairString[ 0..(delim-1) ]; string value = pairString[ (delim+1)..end ]; theMapping[name] = value; theMapping["all-variables"] += name + " "; count++; } // if } // foreach return count; } // perpl_parseVertBarLine //------------------------------------------------------------ // this routine replaces tags of the form #name# with the // associated value in the given mapping // allow for a mapping of default values 19980318 roby string perpl_replacePairs( mapping pairMapping, mapping defaultMapping, string content, string delim ) { array(string) pieces = content/delim; for ( int i = 1; i < sizeof(pieces) ; i += 1 ) { if ( pieces[i] == "" ) pieces[i] = delim; // not a tag; restore delimiter else if ( pairMapping[ pieces[i] ] ) { pieces[i] = pairMapping[ pieces[i] ]; i++; // the next item isn't a tag (#tag#tag# -- not) } else if ( defaultMapping[ pieces[i] ] ) { pieces[i] = defaultMapping[ pieces[i] ]; i++; // the next item isn't a tag (#tag#tag# -- not) } else pieces[i-1] += "#"; // not a tag; restore the previous delimiter } // for return(pieces*""); } // perpl_replacePairs // the following modules require a C component -- the perplex // routines from Rawww.so //------------------------------------------------------------ // parse the string first, then perplex it roby 19980306 string perpl_perpl_help = "(#tag# help goes here)\n\n"; string perpl_perpl(string tag, mapping m, string q, object id ) { string returnString = "(error)"; if ( m->help ) returnString = replace( perpl_perpl_help, "#tag#", tag ); else returnString = rawww()->perpl( parse_rxml( q, id ) ); return returnString; } // perpl_perpl //------------------------------------------------------------ // deperplex the string, then rxml parse it roby 19980306 string perpl_unperpl_help = "(#tag# help goes here)\n\n"; string perpl_unperpl(string tag, mapping m, string q, object id ) { string returnString = "(error)"; if ( m->help ) returnString = replace( perpl_unperpl_help, "#tag#", tag ); else returnString = parse_rxml( rawww()->unperpl( parse_rxml( q, id ) ), id ); return returnString; } // perpl_unperpl //------------------------------------------------------------ string perpl_query_unperp_help = "

<#tag# name=\"default\" > ... #name# ... #name# ... </#tag#>\n\n" "

This tag is like the FORMOUTPUT Roxen tag. It grabs the\n" " query string, unperplexes it, parses it into name value\n" " pairs (vert.bar delimited), and then replaces all tags\n" " in the string with form '#name#' with the appropriate\n" "

Also stuffs each name/variable pair into the variables\n" " mapping so that you can use them in <if> and <insert> tags\n" " name.\n\n"; string perpl_query_unperp(string tag, mapping m, string content, object id ) { string returnString = ""; if ( m->help ) returnString = replace( perpl_query_unperp_help,"#tag#",tag ); else if ( content != "" ) { string result = content; mapping pairMapping = ([ "all-variables":"" ]); int count = 0; if ( id->query && id->query != "" ) { string input = rawww()->unperpl( id->query ); perpl_parseVertBarLine( pairMapping,input ); } // if // parse the name/value pairs into a mapping if ( sizeof(pairMapping) > 1 || sizeof(m) > 0 ) result = perpl_replacePairs( pairMapping,m,content,"#" ); // if there is a variables mapping, stuff in our values if ( id->variables ) id->variables = id->variables + pairMapping; else id->variables = pairMapping; returnString = parse_rxml( result,id ); } // if..else return returnString; } // perpl_query_unperp //------------------------------------------------------------ // a test tag string perpl_test(string tag, mapping m, string q, object id ) { string returnString = "test:\n"; string name = ""; returnString += "

mapping values:\n"; foreach ( indices(m),name ) returnString += "

  • " + name + " = " + m[name] + "\n"; returnString += "

    content:\n

  • " + q + "\n"; if ( id->client ) returnString += "

    user-agent: " + id->client*"/" + "\n"; return( returnString ); } // perpl_perpl //------------------------------------------------------------ // print all the help messages mapping query_container_callers(); mapping query_tag_callers(); string perpl_help(string thistag, mapping m, object id ) { string allHelp = ""; // create the "all help" string string tag = ""; mapping f1 = query_container_callers(); mapping f2 = query_tag_callers(); foreach ( indices(f1), tag ) { allHelp += f1[tag](tag,([ "help":"" ]),"",id ) + "


    \n"; } // foreach foreach ( indices(f2), tag ) { if ( tag != thistag ) allHelp += f2[tag](tag,([ "help":"" ]),id ) + "
    \n"; } // foreach return( allHelp ); } // perpl_perpl //------------------------------------------------------------ // register the functions // this step is necessary mapping query_container_callers() { return ([ // the following functions require the C perplex functions // in Rawww.so "perpl":perpl_perpl, "unperpl":perpl_unperpl, "qperp":perpl_query_unperp, "perpltest":perpl_test ]); } // query_container_callers mapping query_tag_callers() { return ([ "perplhelp":perpl_help ]); } // query_tag_callers // // $Log: perpl.pike,v $ // Revision 1.1.1.1 1998/07/02 22:20:01 gregv // Importing the linux versions // // Revision 1.1 1998/05/05 02:47:01 roby // + allow "variable=" in addition to "variables=" in isblank and isbademail // + moved rollcode, log, datestamp, uniqCounter, queuemail into a new module // realrawww.pike // + moved perpl,unperpl,qperp into a new module perpl.pike // + fussed with the help tag a bit -- if parameter = help, just send a // help string; otherwise do the whole list // //