- From: Robert Sayre <sayrer@gmail.com>
- Date: Thu, 26 Jan 2006 21:58:29 -0500
- To: www-archive@w3.org
Routing Atom Entries through Google Talk Servers Google Talk uses the IETF standard XMPP (aka Jabber) as its instant-messaging protocol. XMPP is open and XML-based, so it's easy to extend. In fact, it's so open that servers generally don't care what's contained in a message envelope. Instead of a typical XMPP IM message, we'll show how to send Atom Entry documents as XMPP payloads. This demo will use the Google Talk server, but any XMPP/Jabber server will do. How it Works To illustrate this capability, we'll need two scripts--one to send the XMPP message and one to recieve it. The scripts send and receive messages that would normally be handled by IM client programs. As of this writing, it isn't common for XMPP clients to include Atom parsing, but expect that to change. Python provides all that we'll need to accomplish this, with the exception of an XMPP module. Not to worry, the xmpp module provides everything required. Instead of the mainstream xmpp module, these scripts use the version provided by Gajim, a PyGTK IM client. The Gajim version is more actively maintained, and includes several fixes for the SASL/TLS features required by Google Talk. First off, we'll tackle sending the XMPP messages. We start by by importing the required modules and declaring some constants (change these to addresses and passwords for your accounts). import sys,xmpp # Google Talk constants FROM_GMAIL_ID = "sender@gmail.com" GMAIL_PASS = "secret" GTALK_SERVER = "talk.google.com" TO_GMAIL_ID = "recipient@gmail.com" Our client has to connect and authenticate, just like any other IM client. We connect though 5222, the standard XMPP port. Fortunately, the xmpp.Client.auth method takes care of all the SASL/TLS negotiation under the covers. jid=xmpp.protocol.JID(FROM_GMAIL_ID) cl=xmpp.Client(jid.getDomain(),debug=[]) if not cl.connect((GTALK_SERVER,5222)): raise IOError('Can not connect to server.') if not cl.auth(jid.getNode(),GMAIL_PASS): raise IOError('Can not auth with server.') Preparing an Atom Entry to send is pretty easy, thanks to some convenience functions provided by the xmpp module. For demonstration purposes, we'll just parse a string. sample_entry = ''' <entry xmlns="http://www.w3.org/2005/Atom"> <title>My First Post</title> <author> <name>John Doe</name> </author> <content type="text">Contents of my post</content> <updated>2003-10-23T18:35:51Z</updated> <link href="http://example.com/weblog/2003/10/my_first_post.html" /> <id>tag:typepad.com,2003:post-3</id> </entry>''' entry_node = xmpp.simplexml.XML2Node(sample_entry) All that's left to do for the sending script is push our entry to the recipient, and then disconnect. message=xmpp.Node('jabber:client message', attrs={'to':TO_GMAIL_ID}, payload=[entry_node]) cl.send(message) cl.disconnect() The resulting XMPP payload looks like this: <message xmlns="jabber:client" to="recipient@gmail.com" from="sender@gmail.com/C3B772CF"> <entry xmlns="http://www.w3.org/2005/Atom"> <title>My First Post</title> <author> <name>John Doe</name> </author> <content type="text">Contents of my post</content> <updated>2003-10-23T18:35:51Z</updated> <link href="http://example.typepad.com/weblog/2003/10/my_first_post.html" /> <id>tag:typepad.com,2003:post-3</id> </entry> </message> If this XMPP message is sent to a normal XMPP client, it will probably be ignored, since the payload isn't something expected. That's OK, because it's easy to hook up a listening client to the Google Talk server as well. The constants are pretty similar to the sender script: import sys,xmpp # Google Talk constants GMAIL_ID = "recipient@gmail.com" GMAIL_PASS = "secret" GTALK_SERVER = "talk.google.com" The receiving script will need to stay running, waiting for messages to arrive. The step and loop functions just run endlessly, while the messageHandler function will be called whenever a message comes in from the network. def messageHandler(conn,mess_node): print "Message From:",mess_node.getFrom() print mess_node.getChildren()[0] def step(conn): try: conn.Process(1) except KeyboardInterrupt: return 0 return 1 def loop(conn): while step(conn): pass After executing some connection and authentication code identical to what's required by the sender script, we instruct the xmpp.Client to execute messageHandler function whenever there's an incoming message. cl.RegisterHandler('message',messageHandler) We then send a message to the server alerting it to our presence. This is what's sent when an account is online, and how the server knows it's ok to send the client messages from others. cl.sendInitPresence() Lastly, we'll print a message so it's clear everything has gone smoothly, enter the loop we set up earlier, and wait for something to, um, Talk to us. print "Google Talk Client started." loop(cl) The Complete Listing send script #!/usr/bin/python # Be sure to use the XMPP module from # http://trac.gajim.org/browser/trunk/src/common/xmpp/ # as it contains many patches not present in the # mainstream version import sys,xmpp # Google Talk constants FROM_GMAIL_ID = "sender@gmail.com" GMAIL_PASS = "secret" GTALK_SERVER = "talk.google.com" TO_GMAIL_ID = "recipient@gmail.com" jid=xmpp.protocol.JID(FROM_GMAIL_ID) cl=xmpp.Client(jid.getDomain(),debug=[]) if not cl.connect((GTALK_SERVER,5222)): raise IOError('Can not connect to server.') if not cl.auth(jid.getNode(),GMAIL_PASS): raise IOError('Can not auth with server.') sample_entry = ''' <entry xmlns="http://www.w3.org/2005/Atom"> <title>My First Post</title> <author> <name>John Doe</name> </author> <content type="text">Contents of my post</content> <updated>2003-10-23T18:35:51Z</updated> <link href="http://example.com/weblog/2003/10/my_first_post.html" /> <id>tag:typepad.com,2003:post-3</id> </entry>''' entry_node = xmpp.simplexml.XML2Node(sample_entry) message=xmpp.Node('jabber:client message', attrs={'to':TO_GMAIL_ID}, payload=[entry_node]) cl.send(message) cl.disconnect() recieve script #!/usr/bin/python # Be sure to use the XMPP module from # http://trac.gajim.org/browser/trunk/src/common/xmpp/ # as it contains many patches not present in the # mainstream version import sys,xmpp # Google Talk constants GMAIL_ID = "recipient@gmail.com" GMAIL_PASS = "secret" GTALK_SERVER = "talk.google.com" def messageHandler(conn,mess_node): print "Message From:",mess_node.getFrom() print mess_node.getChildren()[0] def step(conn): try: conn.Process(1) except KeyboardInterrupt: return 0 return 1 def loop(conn): while step(conn): pass jid=xmpp.protocol.JID(GMAIL_ID) cl=xmpp.Client(jid.getDomain(),debug=[]) if not cl.connect((GTALK_SERVER,5222)): raise IOError('Can not connect to server.') if not cl.auth(jid.getNode(),GMAIL_PASS): raise IOError('Can not auth with server.') cl.RegisterHandler('message',messageHandler) cl.sendInitPresence() print "Google Talk Client started." loop(cl) Running The Code First, we'll start the receiving script in one prompt. prompt1% python receive_atom.py Google Talk Client started. In a second prompt, we'll send the Atom Entry. This prompt could be anywhere, since the message is being routed through Google's servers. prompt2% python send_atom.py That script will exit quickly, and we should see the entry that's been sent pop up in the first prompt... prompt1% python receive_atom.py Google Talk Client started. Message From: sender@gmail.com/C3ABB5D7 <entry xmlns="http://www.w3.org/2005/Atom"> <title>My First Post</title> <author> <name>John Doe</name> </author> <content type="text">Contents of my post</content> <updated>2003-10-23T18:35:51Z</updated> <link href="http://example.typepad.com/weblog/2003/10/my_first_post.html" /> <id>tag:typepad.com,2003:post-3</id> </entry> Hacking the Hack The scripts in this hack are pretty simple, but Atom can carry lots of payloads, and can come from anywhere. The sender could pull entries down from the Web, or the receiver could post the entries using the Atom Publishing Protocol. Also, XMPP allows the exchanges to happen a lot faster than the typical 1/2 hour intervals in syndication, so all sorts of more time-sensitive uses are possible. Network Working Group R. Sayre Internet-Draft January 26, 2006 Expires: July 30, 2006 2-Way RSS draft-sayre-2-way-rss-00 Status of this Memo By submitting this Internet-Draft, each author represents that any applicable patent or other IPR claims of which he or she is aware have been or will be disclosed, and any of which he or she becomes aware will be disclosed, in accordance with Section 6 of BCP 79. This document may not be modified, and derivative works of it may not be created. Internet-Drafts are working documents of the Internet Engineering Task Force (IETF), its areas, and its working groups. Note that other groups may also distribute working documents as Internet- Drafts. Internet-Drafts are draft documents valid for a maximum of six months and may be updated, replaced, or obsoleted by other documents at any time. It is inappropriate to use Internet-Drafts as reference material or to cite them other than as "work in progress." The list of current Internet-Drafts can be accessed at http://www.ietf.org/ietf/1id-abstracts.txt. The list of Internet-Draft Shadow Directories can be accessed at http://www.ietf.org/shadow.html. This Internet-Draft will expire on July 30, 2006. Abstract This memo presents a protocol that uses XML and HTTP to publish and edit Web resources. Sayre Expires July 30, 2006 [Page 1] Internet-Draft 2-Way RSS January 2006 Table of Contents 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 3 2. Notational Conventions . . . . . . . . . . . . . . . . . . . . 3 3. The 2-Way RSS Model . . . . . . . . . . . . . . . . . . . . . 3 4. Discovery . . . . . . . . . . . . . . . . . . . . . . . . . . 3 5. Listing . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 6. Authoring . . . . . . . . . . . . . . . . . . . . . . . . . . 4 7. 2-Way RSS Feeds . . . . . . . . . . . . . . . . . . . . . . . 6 8. 2-Way Media RSS Feeds . . . . . . . . . . . . . . . . . . . . 7 9. Service Outlines . . . . . . . . . . . . . . . . . . . . . . . 9 10. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 11 11. Security Considerations . . . . . . . . . . . . . . . . . . . 11 12. Informative References . . . . . . . . . . . . . . . . . . . . 11 Author's Address . . . . . . . . . . . . . . . . . . . . . . . . . 12 Intellectual Property and Copyright Statements . . . . . . . . . . 13 Sayre Expires July 30, 2006 [Page 2] Internet-Draft 2-Way RSS January 2006 1. Introduction 2-Way RSS uses HTTP [RFC2616] and XML [W3C.REC-xml-20040204] to publish and edit Web resources. 2. Notational Conventions [@@ 2-Way RSS namespace docs] The terms 'URI' and 'IRI' are shorthand for the identifiers specified in [RFC3986] and [RFC3987]. 3. The 2-Way RSS Model 2-Way RSS uses HTTP to operate on collections of Web resources represented by RSS feeds [RSS]. This section illustrates the editing cycle for RSS items. o GET is used to retrieve an item or perform a read-only query. o POST is used to create a new, dynamically-named item. o PUT is used to update an existing item. o DELETE is used to remove an item. 4. Discovery To discover the location of the feeds exposed by a 2-way RSS service, the client must locate and request the Service Outline, an OPML document. Client Server | | | 1.) GET Service Outline URI | |------------------------------->| | | | 2.) Service OPML Document | |<-------------------------------| | | 1. The client sends a GET request to the Service Outline URI. 2. The server responds with an OPML Document containing the locations of feeds provided by the service. The content of this document can vary based on aspects of the client request, including, but not limited to, authentication credentials. Sayre Expires July 30, 2006 [Page 3] Internet-Draft 2-Way RSS January 2006 5. Listing Once the client has discovered the location of a feed in the outline, it can request a listing of the feed's items. However, a feed might contain an extremely large number of items, so servers are likely to list a small subset of them by default. Client Server | | | 1.) GET to RSS Feed URI | |------------------------------->| | | | 2.) 200 OK, RSS Feed Doc | |<-------------------------------| | | 1. The client sends a GET request to the RSS Feed's URI. 2. The server responds with an RSS Feed Document containing a full or partial listing of the feed's membership. 6. Authoring After locating a feed, a client can add entries by sending a POST request to the feed; other changes are accomplished by sending HTTP requests to each item. 6.1. Create Client Server | | | 1.) POST Item to Feed URI | |------------------------------->| | | | 2.) 201 Created @ Location | |<-------------------------------| | | 1. The client sends an RSS item to the server via HTTP POST. The Request URI is that of the RSS Feed. 2. The server responds with a response of "201 Created" and a "Location" header containing the URI of the newly-created RSS item. Sayre Expires July 30, 2006 [Page 4] Internet-Draft 2-Way RSS January 2006 6.2. Read Client Server | | | 1.) GET or HEAD to Item URI | |------------------------------->| | | | 2.) 200 OK RSS Item | |<-------------------------------| | | 1. The client sends a GET (or HEAD) request to the item's URI. 2. The server responds with an RSS item. 6.3. Update Client Server | | | 1.) PUT to RSS Item URI | |------------------------------->| | | | 2.) 200 OK | |<-------------------------------| | | 1. The client PUTs an updated RSS item to the item's URI. 2. The server responds with a successful status code. 6.4. Delete Client Server | | | 1.) DELETE to Item URI | |------------------------------->| | | | 2.) 204 No Content | |<-------------------------------| | | 1. The client sends a DELETE request to the item's URI. Sayre Expires July 30, 2006 [Page 5] Internet-Draft 2-Way RSS January 2006 2. The server responds with successful status code. 6.5. Success and Failure HTTP defines classes of response. HTTP status codes of the form 2xx signal that a request was successful. HTTP status codes of the form 4xx or 5xx signal that an error has occurred, and the request has failed. Consult the HTTP specification for more detailed definitions of each status code. 7. 2-Way RSS Feeds 7.1. GET RSS feeds can contain extremely large numbers of items. A naive client such as a web spider or web browser would be overwhelmed if the response to a GET contained every item in the feed, and the server would waste large amounts of bandwidth and processing time on clients unable to handle the response. As a result, responses to a simple GET request represent a server-determined subset of the items in the feed. An example 2-Way RSS feed: <rss> <channel> <title>The Baron in the Trees</title> <link>http://example.org/trees.html</link> <description>Recent posts.</description> <!-- 0 or more item elements follow --> <item> <title>Chapter One</title> <description>It started out simple...</description> <guid>uuid:941e12b4-6eeb-4753-959d-0cbc51875387</guid> <link>http://example.org/chapter1.html</link> <pub:edit href="./item7.rss"/> </item> </channel> </rss> Each member item is represented by an <item> element, but those items are not an editable representation of the each item. To retrieve the source representation of the item, clients send a GET request to the URI found in each item's [@@ TBD XX pub:edit element. Derived resources are located by examining an item's r:link elements] Sayre Expires July 30, 2006 [Page 6] Internet-Draft 2-Way RSS January 2006 7.2. POST A 2-Way RSS feed also accepts POST requests. The client POSTs a new item to the RSS feed. Some feeds only accept POST requests with certain media-types, so a POST request could result in a response with a status code of 415 ("Unsupported Media Type"). In the case of a successful creation, the status code is 201 ("Created"). Example HTTP request creating a new item in a feed: POST /dilettante HTTP/1.1 Host: example.org User-Agent: Cosimo/1.0 Content-Type: application/rss+xml Content-Length: nnnn <item> <title>Chapter One</title> <description>It started out simple...</description> <guid>uuid:941e12b4-6eeb-4753-959d-0cbc51875387</guid> <link>http://example.org/chapter1.html</link> <pub:edit href="./item7.rss"/> </item> Example response. HTTP/1.1 201 Created Date: Mon, 21 Mar 2005 19:20:19 GMT Server: CountBasic/1.0 ETag: "4c083-268-423f1dc6" Location: http://example.org/items/foo13241234.xml 8. 2-Way Media RSS Feeds The items within 2-way Media RSS Feeds do not represent uniform types of content. For example, they might contain podcasts, JPEG images, text documents, MPEG movies, or any other type of resource the server allows. 8.1. GET 2-Way Media RSS Feeds return an RSS feed much like the textual 2-Way RSS feeds described above, but with a few additions. The entries also contain an <enclosure> element with a 'url' attribute pointing to the media object. This URL can be used to edit the uploaded media object, using PUT and DELETE. Such items may contain edit links used Sayre Expires July 30, 2006 [Page 7] Internet-Draft 2-Way RSS January 2006 to edit the item metadata.[@@TBD As with any RSS item, related and derived resources can be located by inspecting an item's r:link elements.] An example 2-Way Media RSS Feed: <rss> <channel> <title>My Pics</title> <link>http://example.org/pics</link> <description>Recent photos.</description> <!-- 0 or more item elements follow --> <item> <title>beach25</title> <link>http://example.org/beach-pic1.html</link> <guid>uuid:941e12b4-6eeb-4753-959d-0cbc51875387</guid> <description>This was awesome.</description> <enclosure url="http://example.org/beach.tiff" length="15234" type="image/tiff" /> </item> </channel> </rss> Implementations require that each such item contain either a <title> or <description> element. The value for the <title> element will likely be provided by the client, as a way for users to associate their local objects with those they have uploaded to the server (see POST below). 8.2. POST To add an item to a 2-Way Media RSS feed, clients POST the resource to the Media feed's URL. Clients should provide a 'Title' request header to provide the server with a short string identifying the object to users. Clients may include a 'Content-Description' header [RFC2045] providing a more complete description of the content. In addition, servers may inspect the POSTed entity for additional metadata to be exposed in an <item> element when listed in a 2-Way Media RSS feed. For example, the server might inspect a JPEG file for EXIF headers containing creator data. Sayre Expires July 30, 2006 [Page 8] Internet-Draft 2-Way RSS January 2006 An example request: POST /pics HTTP/1.1 Host: example.org User-Agent: Cosimo/1.0 Content-Type: image/tiff Content-Length: nnnn Title: A Trip to the beach Content-Description: It was so fun. ...binary data... An example response: HTTP/1.1 201 Created Date: Mon, 21 Mar 2005 19:20:19 GMT Server: CountBasic/2.0 ETag: "4c083-268-423f1dc6" Location: http://example.org/stuff/beach.tiff [@@TBD deal with response ambiguity] 9. Service Outlines Many 2-Way RSS applications require a basic resource layout in order to ease configuration requirements. Servers use Service Outline OPML documents to convey information about related groups of 2-Way RSS feeds. On a blogging service, for example, each group might represent a distinct blog and associated resources. Example Service Outline document: <opml version="1.1"> <head> <title>My Blogs</title> </head> <body> <outline text="Pretending to be Excited" type="rss" xmlUrl="http://example.org/pretend.rss"/> <outline text="Quick Links" type="rss" xmlUrl="http://example.org/side.rss"/> </body> </opml> Sayre Expires July 30, 2006 [Page 9] Internet-Draft 2-Way RSS January 2006 Servers are not required to expose a Service Outline OPML document, but experimental deployment experience has shown that a single document which signals some basic information about the server's configuration can greatly simplify client implementations. The simplest useful Service Outline OPML document shows the location of a single feed: <opml version="1.1"> <head> <title>Flickr</title> </head> <body> <outline text="My Pics" type="rss" xmlUrl="http://example.org/pics.rss"/> </body> </opml> If another 2-Way RSS feed is added, the document can be upgraded to reflect that. <opml version="1.1"> <head> <title>Flickr</title> </head> <body> <outline text="Pics" type="rss" xmlUrl="http://example.org/pics.rss"/> <outline text="Overwraught Prose" type="rss" xmlUrl="http://example.org/blog.rss"/> </body> </opml> Finally, more extensive services could require some amount of hierarchical grouping. Sayre Expires July 30, 2006 [Page 10] Internet-Draft 2-Way RSS January 2006 <opml version="1.1"> <head> <title>Flickr</title> </head> <body> <outline text="Pics" type="rss" xmlUrl="http://example.org/pics.rss"/> <outline text="Crazy Delicious"> <outline text="Overwraught Prose" type="rss" xmlUrl="http://example.org/blog.rss"/> <outline text="Still More Overwraught Prose" type="rss" xmlUrl="http://example.org/blog2.rss"/> </outline> </body> </opml> 9.1. Categories [@@ tbd] 10. IANA Considerations [@@ fill out for application/rss+xml and application/opml+xml] 11. Security Considerations [@@TBD] 12. Informative References Sayre Expires July 30, 2006 [Page 11] Internet-Draft 2-Way RSS January 2006 Author's Address Robert Sayre Email: rfsayre@boswijck.com Sayre Expires July 30, 2006 [Page 12] Internet-Draft 2-Way RSS January 2006 Intellectual Property Statement The IETF takes no position regarding the validity or scope of any Intellectual Property Rights or other rights that might be claimed to pertain to the implementation or use of the technology described in this document or the extent to which any license under such rights might or might not be available; nor does it represent that it has made any independent effort to identify any such rights. Information on the procedures with respect to rights in RFC documents can be found in BCP 78 and BCP 79. Copies of IPR disclosures made to the IETF Secretariat and any assurances of licenses to be made available, or the result of an attempt made to obtain a general license or permission for the use of such proprietary rights by implementers or users of this specification can be obtained from the IETF on-line IPR repository at http://www.ietf.org/ipr. The IETF invites any interested party to bring to its attention any copyrights, patents or patent applications, or other proprietary rights that may cover technology that may be required to implement this standard. Please address the information to the IETF at ietf-ipr@ietf.org. Disclaimer of Validity This document and the information contained herein are provided on an "AS IS" basis and THE CONTRIBUTOR, THE ORGANIZATION HE/SHE REPRESENTS OR IS SPONSORED BY (IF ANY), THE INTERNET SOCIETY AND THE INTERNET ENGINEERING TASK FORCE DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Acknowledgment Funding for the RFC Editor function is currently provided by the Internet Society. Sayre Expires July 30, 2006 [Page 13]
Received on Friday, 27 January 2006 08:55:24 UTC