The advantage of this approach is that nearly every single decent language (scripting or otherwise) has free and easy to use XML parsers and HTTP clients. This makes implementation relatively easy for most parts of XmlRpc. Since it is so easy to implement, there are clients and servers for many languages with more coming at a pretty constant rate.
Please check out http://www.xmlrpc.com for more info (including the spec and a list of clients and servers)
This has a huge advantage over other possible solutions in that the translation is transparent between the two protocols. The XmlRpc client and DCOP server both think they are communicating only in their native protocol with the daemon. Neither need any modifications in order to work with the other (with one minor exception -- see below)!
You need four bits of information to call a DCOP method using XmlRpc.
The latter two can be discovered by knowing the DCOP object you are trying to access. For instance, if you wanted to have KDesktop popup the Execute Command dialog, you would find that the server name is 'kdesktop' (the DCOPClient::registerAs() name) and the object name is 'KDesktopIface'
The port and "auth token" are both found in the file $HOME/.kxmlrpcd. Your client is responsible for getting both of them. If you are running locally, then all you need do is parse the file. If you are running remotely, then you need to get those values some other way. Some possibilities include mounting the home directory with NFS or SMB or emailing yourself the values or putting them on FTP server or writing them down... whatever it takes.
The "auth token" is a 16 byte string that needs to accompany all incoming XmlRpc requests. This is the one minor change to the "stock" XmlRpc protocol. The very first parameter in your methodCall must be a string and it must be the auth token. Beyond that, the protocol is the same as the standard.
Once that is done, you can make your XmlRpc call like any other call.
There are some minor restrictions. Mainly, you must pass only QCString as the string type and your use of <struct> and <array> is restricted. See the README file in the source directory for more information on that.
Then, download the python XmlRpc library from pythonware and install it into /usr/lib/python1.5.
Finally, run this script:
#!/usr/bin/python from xmlrpclib import * import os rc = open(os.environ['HOME'] + '/.kxmlrpcd', 'r') config = string.split(rc.read(), ',') port = config[0] auth = config[1] server = Server("http://localhost:" + port +"/kdesktop") server.KDesktopIface.popupExecuteCommand(auth); |
That's all you need to do to have KDesktop popup the Execute Command dialog! Note that if you are running the python script on a different computer (even a Windows or Macintosh one), you need only change the method of getting the port and auth token.
Here is a script by David Faure <[email protected]> that uses only /bin/sh, cat, wc, and telnet -- utilities found on every single Unix system.
#!/bin/sh port=`sed -e 's/,.*//' ~/.kxmlrpcd` auth=`sed -e 's/.*,//' ~/.kxmlrpcd` cat > cmd.xml <<EOF <?xml version="1.0"?> <methodCall> <methodName>KDesktopIface.popupExecuteCommand</methodName> <params> <param> <value>$auth</value> </param> </params> </methodCall> EOF length=`wc -c cmd.xml | sed -e 's/cmd.xml//;s/ //g'` cat > head.xml <<EOF POST /kdesktop HTTP/1.0 Content-Type: text/xml Content-length: $length EOF ( echo open localhost $port sleep 1 cat head.xml cmd.xml ) | telnet -8E |
Yes, this means that you can now script all KDE applications using only /bin/sh and telnet!
Kurt Granroth ([email protected])