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

system.verbs.builtins.tcp.im.builtinDrivers.jabber.code.examples.rpc.xmlrpcCall

on xmlrpcCall ( connection, mesAdr,  iq, query ) {
	<<Changes
		<<5/14/02; 1:51:34 PM by JB
			<<Changelog created.
	<<xmlrpcCall handles an incoming RPC call
	on addAtt ( XMLadr, name, value ) {
		if not defined ( XMLadr^.["/atts"] ) {
			new ( tableType, @XMLadr^.["/atts"] )};
		XMLadr^.["/atts"].[name] = value};
	on noDirectiveXmlDecompile ( xmlAdr ) {
		// decompiles a table and strips off the <? ?>, if any
		local ( s );
		s = xml.decompile(xmlAdr);
		return string.mid ( s, string.patternMatch ( "?>", s ) + 2, infinity )};
	local ( id = xml.getAttributeValue(iq, "id" ) );
	local ( reply, xmlrpcResult, idTbl = tcp.im.builtinDrivers.jabber.code.idTables.getAdr ( id ), iqTag, methodCall, xmlstr, resAdr, methodTag, queryTag);
	
	// begin contructing the registration reply
	new ( tableType, @reply );
	bundle { // <iq id="id" type="result" to="from" from="me"><x>
		iqTag = xml.addTable ( @reply, "iq" );
		addAtt(iqTag, "id", id );
		addAtt(iqTag, "type", "result");
		addAtt(iqTag, "to", xml.getAttributeValue(iq, "from") );
		addAtt(iqTag, "from", connection^.username + "@" + connection^.host + "/" + connection^.resource );
		queryTag = xml.addTable ( iqTag, "query" )};
	
	bundle { // handle the call
		<<there's an inefficiency here; the xml text goes through two compile/decompile phases
			<<I'd like to have a version of betty.rpc.server that takes a XML table directly, and also doesn't try an IP check (meaningless with Jabber), but I hesitate to spawn my own version, and get out of sync with betty.rpc.server.
		methodTag = xml.getAddress(query, "methodCall" );
		xmlstr = noDirectiveXmlDecompile(methodTag);
		local ( params ); new ( tableType, @params );
		xmlrpcResult = betty.rpc.server(xmlstr, @params );
		if xmlrpcResult beginsWith "<?" { // this needs to be removed, xml.decompile seems to put it in
			xmlrpcResult = string.mid ( xmlrpcResult, string.patternMatch ( "?>", xmlrpcResult ) + 2, infinity )}};
	
	xml.compile(xmlrpcResult, queryTag);
	// previous line blows away contents of the x tag, so we have to add this here, rather then when we create the query tag
	addAtt(queryTag, "xmlns", "jabber:iq:rpc");
	
	tcp.im.builtinDrivers.jabber.code.writeXML(iqTag, connection: connection)};



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.