/* * mod_aolserver aolserver emulation --- Copyright 2000 Robert S. Thau. * This file derived from the actual aolserver code, and is distributed * in accord with its license, as follows: * * The contents of this file are subject to the AOLserver Public License * Version 1.1 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://aolserver.lcs.mit.edu/. * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See * the License for the specific language governing rights and limitations * under the License. * * The Original Code is AOLserver Code and related documentation * distributed by AOL. * * The Initial Developer of the Original Code is America Online, * Inc. Portions created by AOL are Copyright (C) 1999 America Online, * Inc. All Rights Reserved. * * Alternatively, the contents of this file may be used under the terms * of the GNU General Public License (the "GPL"), in which case the * provisions of GPL are applicable instead of those above. If you wish * to allow use of your version of this file only under the terms of the * GPL and not to allow others to use your version of this file under the * License, indicate your decision by deleting the provisions above and * replace them with the notice and other provisions required by the GPL. * If you do not delete the provisions above, a recipient may use your * version of this file under either the License or the GPL. */ /* * adpfancy.c -- * * Support for registered tags within ADPs, the "); if (end == NULL) { Ns_ModLog(Warning, nsAdpModLogHandle, "unterminated script"); AddTextChunk(outPtr, oldtop, strlen(oldtop)); Ns_SetFree(params); break; } else { StartScript(outPtr); if (stream != NULL && strcasecmp(stream, "on") == 0) { AppendChunk(outPtr, "ns_adp_stream\n"); } NAppendChunk(outPtr, top, end-top); EndChunk(outPtr); top = end + 9; } } else { /* * Not a server-side script, so add as text. */ AddTextChunk(outPtr, tag.string, tag.length); } Ns_SetFree(params); } else if ((rtPtr = GetRegTag(tag.string + 1)) != NULL) { /* * It is a registered tag. In this case, we generate * a bolus of tcl code that will call it. */ int i; char *end = NULL; params = TagToSet(tag.string); /* * If it requires an endtag then ensure that there * is one. If not, warn and spew text. */ if (rtPtr->endtag && ((end = BalancedEndTag(top, rtPtr)) == NULL)) { Ns_ModLog(Warning, nsAdpModLogHandle, "unterminated registered tag %s", rtPtr->tag); AddTextChunk(outPtr, oldtop, strlen(oldtop)); Ns_SetFree(params); break; } /* * Write Tcl code to put all the parameters into a set, then * call the proc with that set (and the input, if any). */ StartScript(outPtr); AppendChunk(outPtr, "set _ns_tempset [ns_set create \"\"]\n"); for (i=0; i < Ns_SetSize(params); i++) { AppendChunk(outPtr, "ns_set put $_ns_tempset \""); AppendTclEscaped(outPtr, Ns_SetKey(params, i)); AppendChunk(outPtr, "\" \""); AppendTclEscaped(outPtr, Ns_SetValue(params, i)); AppendChunk(outPtr, "\"\n"); } AppendChunk(outPtr, "ns_puts -nonewline ["); if (rtPtr->procname) { /* * This uses the old-style registered procedure */ AppendChunk(outPtr, rtPtr->procname); } else { /* * This uses the new and improved registered ADP. */ AppendChunk(outPtr, "ns_adp_eval \""); AppendTclEscaped(outPtr, rtPtr->adpstring); AppendChunk(outPtr, "\" "); } AppendChunk(outPtr, " "); /* * Backwards compatibility is broken here because a conn is * never passed */ if (end != NULL) { /* * This takes an endtag, so pass it content (the text between * the start and end tags). */ AppendChunk(outPtr, "\""); NAppendTclEscaped(outPtr, top, end-top-1); AppendChunk(outPtr, "\" "); } AppendChunk(outPtr, "$_ns_tempset]\n"); EndChunk(outPtr); /* * Advance top past the end of the close tag * (if there is no closetag, top should already be * properly advanced thanks get ReadToken) */ if (end != NULL) { while (*end != '\0' && *end != '>') { end++; } if (*end == '>') { end++; } top = end; } Ns_SetFree(params); } else { /* * It's just a chunk of text. */ AddTextChunk(outPtr, tag.string, tag.length); } Ns_DStringTrunc(&tag, 0); oldtop = top; } #ifdef NOTDEF if (nsconf.adp.taglocks) { Ns_RWLockUnlock(&tlock); } #endif Ns_DStringFree(&tag); } /* *---------------------------------------------------------------------- * * TagToSet -- * * Given a tag such as