Monday, November 08, 2010 at 12:06 AM.

system.verbs.builtins.tcp.im.builtinDrivers.jabber.code.writeXML

on writeXML (XML, connection = @system.temp.jabber.connection) {
	<<Changes
		<<5/14/02; 1:51:34 PM by JB
			<<Changelog created.
	<<writeXML directly outputs XML to the Jabber XML stream. Use with extreme caution; if the XML is not valid, you'll corrupt the stream unrecoverably. I recommend passing in an XML table, but watch for the "empty XML table" bug, if it hasn't been fixed yet.
	if not defined ( connection^ ) {
		scriptError ("Can't write to Jabber server because the connection reference is invalid.")};
	
	bundle { // confirm that the stream is still available
		on error () {
			scriptError ("Can't write to Jabber server because the stream has been terminated.")};
		if not defined (connection^.tcpStream) { //JES 7/29/02: we have to have a stream handle to call statusStream
			error ()};
		local ( bytes = 0 );
		streamStatus = tcp.statusStream(connection^.tcpStream, @bytes);
		if streamStatus != "OPEN" and streamStatus != "DATA" {
			error ()}};
	
	local ( tcpStream = connection^.tcpStream, uniqueId = string(connection), semaphoreName, streamStatus, x );
	
	semaphoreName = "jabberStream" + string(uniqueId);
	try { // make sure the semaphore always gets unlocked, so we don't hold it
		try {
			semaphore.lock(semaphoreName, 60)} // allow one second for writing other things
		else {
			scriptError ( "Can't write to the Jabber stream because it was locked for more then " + string ( user.im.jabber.prefs.writeTimeout / 60.0) + " seconds." )};
		
		bundle { // process the XML argument to get it to flat text, suitable for transmission
			if typeOf ( XML ) == stringType {
				x = XML};
			if typeOf ( XML ) == tableType { // assume it's an XML table
				x = xml.decompile ( @XML )};
			if typeOf ( XML ) == addressType and typeOf ( XML^ ) == tableType { // assume it's an adr to an XML table
				x = xml.decompile ( XML )};
			if x beginsWith "<?" { // this needs to be removed, xml.decompile puts it in
				x = string.mid ( x, string.patternMatch ( "?>", x ) + 2, infinity )}};
		
		tcp.writeStream ( tcpStream, x );
		
		if user.im.jabber.prefs.flDebug {
			try {
				local ( db = Frontier.openDataFile("jabberLog") );
				local ( debugStr = @db^.jabberOut );
				if not defined ( debugStr^ ) {
					debugStr^ = ""};
				if typeOf ( debugStr^ ) != stringType { // allows conversion to wpText on the fly
					table.moveAndRename ( debugStr, table.uniqueName ( nameOf ( debugStr^ ), db, 3 ) );
					debugStr^ = ""};
				debugStr^ = debugStr^ + x;
				debugStr^ = debugStr^ + "\n"}}};
	semaphore.unlock(semaphoreName)};
writeXML("\n   \n" )



This listing is for code that runs in the OPML Editor environment. I created these listings because I wanted the search engines to index it, so that when I want to look up something in my codebase I don't have to use the much slower search functionality in my object database. Dave Winer.