No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

xep-0231.xml 17KB

  1. <?xml version='1.0' encoding='UTF-8'?>
  2. <!DOCTYPE xep SYSTEM 'xep.dtd' [
  3. <!ENTITY % ents SYSTEM 'xep.ent'>
  4. %ents;
  5. ]>
  6. <?xml-stylesheet type='text/xsl' href='xep.xsl'?>
  7. <xep>
  8. <header>
  9. <title>Bits of Binary</title>
  10. <abstract>This specification defines an XMPP protocol extension for including or referring to small bits of binary data in an XML stanza.</abstract>
  12. <number>0231</number>
  13. <status>Draft</status>
  14. <type>Standards Track</type>
  15. <sig>Standards</sig>
  16. <approver>Council</approver>
  17. <dependencies>
  18. <spec>XMPP Core</spec>
  19. <spec>RFC 2045</spec>
  20. <spec>RFC 2111</spec>
  21. <spec>RFC 2965</spec>
  22. <spec>RFC 3174</spec>
  23. <spec>RFC 4648</spec>
  24. </dependencies>
  25. <supersedes/>
  26. <supersededby/>
  27. <shortname>bob</shortname>
  28. <schemaloc>
  29. <url></url>
  30. </schemaloc>
  31. &stpeter;
  32. &pavlix;
  33. <revision>
  34. <version>1.0</version>
  35. <date>2008-09-03</date>
  36. <initials>psa</initials>
  37. <remark><p>Per a vote of the XMPP Council, advanced status to Draft; concurrently, the XMPP Registrar issued the urn:xmpp:bob namespace.</p></remark>
  38. </revision>
  39. <revision>
  40. <version>0.9</version>
  41. <date>2008-08-16</date>
  42. <initials>psa/ps</initials>
  43. <remark><p>Modified cid generation rules to use a hash of the data instead of a UUID (of the form; modified caching rules to typically base checking on the hash, not the sender JID.</p></remark>
  44. </revision>
  45. <revision>
  46. <version>0.8</version>
  47. <date>2008-08-07</date>
  48. <initials>psa/ps</initials>
  49. <remark><p>Added section on determining support.</p></remark>
  50. </revision>
  51. <revision>
  52. <version>0.7</version>
  53. <date>2008-08-06</date>
  54. <initials>psa/ps</initials>
  55. <remark><p>Simplified the protocol; removed fetch element because the cid: URI uniquely identifies the data; changed the name of the protocol to something more catchy.</p></remark>
  56. </revision>
  57. <revision>
  58. <version>0.6</version>
  59. <date>2008-08-06</date>
  60. <initials>psa/ps</initials>
  61. <remark><p>More clearly described recommended protocol and usage; added fetch element to diambiguate data from reference; cleaned up text throughout.</p></remark>
  62. </revision>
  63. <revision>
  64. <version>0.5</version>
  65. <date>2008-08-06</date>
  66. <initials>psa/ps</initials>
  67. <remark><p>Removed alt attribute; more clearly specified where to include the data element in message, presence, and IQ stanzas; moved use cases to other specifications; removed service discovery features; modified examples.</p></remark>
  68. </revision>
  69. <revision>
  70. <version>0.4</version>
  71. <date>2008-08-05</date>
  72. <initials>psa/ps</initials>
  73. <remark><p>Generalized text regarding inclusion of parameters in type attribute per RFC 2045; added max-age attribute, matching semantics from RFC 2965; added section on caching of data; more clearly specified generation of Content-ID.</p></remark>
  74. </revision>
  75. <revision>
  76. <version>0.3</version>
  77. <date>2008-06-18</date>
  78. <initials>psa</initials>
  79. <remark><p>Allowed inclusion of codecs parameter in type attribute per RFC 4281.</p></remark>
  80. </revision>
  81. <revision>
  82. <version>0.2</version>
  83. <date>2008-05-29</date>
  84. <initials>psa</initials>
  85. <remark><p>Added service discovery feature for in-band message images use case.</p></remark>
  86. </revision>
  87. <revision>
  88. <version>0.1</version>
  89. <date>2008-01-30</date>
  90. <initials>psa</initials>
  91. <remark><p>Initial published version.</p></remark>
  92. </revision>
  93. <revision>
  94. <version>0.0.4</version>
  95. <date>2008-01-29</date>
  96. <initials>psa</initials>
  97. <remark><p>Separately described service discovery feature for inclusion of the data element in file previews.</p></remark>
  98. </revision>
  99. <revision>
  100. <version>0.0.3</version>
  101. <date>2007-12-27</date>
  102. <initials>psa</initials>
  103. <remark><p>Described use cases for previewing data to be exchanged in file transfers and for inclusion of media information in data forms.</p></remark>
  104. </revision>
  105. <revision>
  106. <version>0.0.2</version>
  107. <date>2007-12-18</date>
  108. <initials>psa</initials>
  109. <remark><p>Changed syntax to not use data: URL scheme; added cid and type attributes; described use cases for messaging and data retrieval.</p></remark>
  110. </revision>
  111. <revision>
  112. <version>0.0.1</version>
  113. <date>2007-11-09</date>
  114. <initials>psa</initials>
  115. <remark><p>First draft.</p></remark>
  116. </revision>
  117. </header>
  118. <section1 topic='Introduction' anchor='intro'>
  119. <p>Sometimes it is desirable to include a small bit of binary data in an XMPP stanza. Typical use cases might be to include icon or emoticon in a message, a thumbnail in a file transfer request, a rasterized image in a whiteboarding session, or a small bit of media in a data form. Currently, there is no lightweight method for including such data in an XMPP stanza, since existing methods (e.g., &xep0047;) are designed for larger blobs of data and therefore require some form of negotiation (e.g., via &xep0096; or &xep0234;).</p>
  120. <p>This document specifies just such a lightweight method. The key building blocks are:</p>
  121. <ol>
  122. <li>A Content-ID ("cid") that uniquely identifies the data.</li>
  123. <li>A &lt;data/&gt; element (similar to the data: URL scheme defined in &rfc2397;) that enables the sender and recipient to exchange the data identified by the cid.</li>
  124. </ol>
  125. </section1>
  126. <section1 topic='Protocol' anchor='proto'>
  127. <section2 topic='Data Exchange' anchor='exchange'>
  128. <p>The RECOMMENDED approach is for the sender to include the cid when communicating with the recipient. The recipient SHOULD then check its cache of data to determine if the data identified by that cid is cached. If the data is cached, the recipient would then load its cached data. If the data is not cached, the recipient would then retrieve the data by sending an IQ-get to the sender (or potentially some other entity) containing an empty &lt;data/&gt; element whose 'cid' attribute specifies the data to be retrieved, to which the sender would reply with an IQ-result containing a &lt;data/&gt; element whose XML character data provides the binary data.</p>
  129. <p>The &lt;data/&gt; element MUST be used only to encapsulate small bits of binary data and MUST NOT be used for large data transfers. Naturally the definitions of "small" and "large" are rather loose. In general, the data SHOULD NOT be more than 8 kilobytes, and dedicated file transfer methods (e.g., &xep0065; or &xep0047;) SHOULD be used for exchanging blobs of data larger than 8 kilobytes. However, implementations or deployments MAY impose their own limits.</p>
  130. <p>If the data to be shared is particularly small (e.g., less than 1k), then the sender MAY send it directly by including a &lt;data/&gt; element directly in a &MESSAGE;, &PRESENCE;, or &IQ; stanza. The following rules apply:</p>
  131. <ol>
  132. <li>When the &lt;data/&gt; element is directly included in an XMPP &MESSAGE; or &PRESENCE; stanza, it SHOULD be a first-level child of the stanza.</li>
  133. <li>When the &lt;data/&gt; element is directly included in an XMPP &IQ; stanza, it MUST be a child of the appropriate first-level child (since the IQ stanza must not include more than one first-level child).</li>
  134. <li>When the &lt;data/&gt; element is used to retrieve the data from the sender as described under <link url='#retrieving'>Retrieving Uncached Data</link>, it MUST be a first-level child of the stanza.</li>
  135. </ol>
  136. </section2>
  137. <section2 topic='Referencing Data' anchor='referencing'>
  138. <p>The sender can refer to data that it hosts by including a cid in the data it sends. The following example shows how to include the cid in &xep0071; but any appropriate format can be used, such as &xep0221;.</p>
  139. <example caption='An XHTML-IM message with a cid'><![CDATA[
  140. <message from='ladymacbeth@shakespeare.lit/castle'
  141. to='macbeth@chat.shakespeare.lit'
  142. type='groupchat'>
  143. <body>Yet here's a spot.</body>
  144. <html xmlns=''>
  145. <body xmlns=''>
  146. <p>
  147. Yet here's a spot.
  148. <img alt='A spot'
  149. src=''/>
  150. </p>
  151. </body>
  152. </html>
  153. </message>
  154. ]]></example>
  155. <p>The recipient can then retrieve the data from the sender as described in the next section.</p>
  156. </section2>
  157. <section2 topic='Retrieving Uncached Data' anchor='retrieving'>
  158. <p>Data is requested and transferred using the XMPP &IQ; stanza type by making reference to the cid. In particular, the recipient requests the binary data by sending an IQ-get containing an empty &lt;data/&gt; element with a 'cid' attribute that matches the cid URI previously communicated.</p>
  159. <example caption='Requesting data'><![CDATA[
  160. <iq from='doctor@shakespeare.lit/pda'
  161. id='get-data-1'
  162. to='ladymacbeth@shakespeare.lit/castle'
  163. type='get'>
  164. <data xmlns='urn:xmpp:bob'
  165. cid=''/>
  166. </iq>
  167. ]]></example>
  168. <p>The recipient then would either return an error (e.g., &notfound; if it does not have data matching the Content-ID) or return the data.</p>
  169. <example caption='Returning data'><![CDATA[
  170. <iq from='ladymacbeth@shakespeare.lit/castle'
  171. id='get-data-1'
  172. to='doctor@shakespeare.lit/pda'
  173. type='result'>
  174. <data xmlns='urn:xmpp:bob'
  175. cid=''
  176. max-age='86400'
  177. type='image/png'>
  181. REFUGNO9zL0NglAAxPEfdLTs4BZM4DIO4C7OwQg2JoQ9LE1exdlYvBBeZ7jq
  182. ch9//q1uH4TLzw4d6+ErXMMcXuHWxId3KOETnnXXV6MJpcq2MLaI97CER3N0
  183. vr4MkhoXe0rZigAAAABJRU5ErkJggg==
  184. </data>
  185. </iq>
  186. ]]></example>
  187. </section2>
  188. <section2 topic='Caching Data' anchor='caching'>
  189. <p>It is RECOMMENDED for the recipient to cache data; however, the recipient MAY opt not to cache data, for example because it runs on a device that does not have sufficient space for data storage.</p>
  190. <p>The default behavior is for the recipient to cache the data only for the life of the entity's application session (not a client's presence session with the server or the controlling user's communication session with the contact from whom the user received the data); that is, the recipient would clear the cache when the application is terminated or restarted.</p>
  191. <p>As a hint regarding the suggested period for caching the data, the sender MAY include a 'max-age' attribute whenever it sends a &lt;data/&gt; element. The meaning of the 'max-age' attribute exactly matches that of the Max-Age attribute from <cite>RFC 2965</cite>.</p>
  192. <p>If it is not suggested to cache the data (e.g., because it is ephemeral), the value of the 'max-age' attribute MUST be "0" (the number zero).</p>
  193. <p>A recipient SHOULD cache data based on the hash of the data as encapsulated in the cid. However, if a hash cannot be extracted from the cid, if the recipient does not support the hashing algorithm used, or the recipient does not support hashes, then the recipient SHOULD cache based on the JID of the sender.</p>
  194. </section2>
  195. <section2 topic='Format of the &lt;data/&gt; Element' anchor='format'>
  196. <p>To exchange binary data, the data is encapsulated as the XML character data of a &lt;data/&gt; element qualified by the 'urn:xmpp:bob' namespace, where the data MUST be encoded as Base64 in accordance with Section 4 of &rfc4648; (note: the Base64 output MUST NOT include whitespace and MUST set the number of pad bits to zero).</p>
  197. <p>The following attributes are defined for the &lt;data/&gt; element.</p>
  198. <table caption='Attributes of the data Element'>
  199. <tr>
  200. <th>Attribute</th>
  201. <th>Description</th>
  202. <th>Inclusion</th>
  203. </tr>
  204. <tr>
  205. <td>cid</td>
  206. <td>A Content-ID that can be mapped to a cid: URL as specified in &rfc2111;. The 'cid' value SHOULD be of the form, where the "algo" is the hashing algorithm used (e.g., "sha1" for the SHA-1 algorithm as specified in &rfc3174;) and the "hash" is the hex output of the algorithm applied to the binary data itself.</td>
  207. <td>REQUIRED</td>
  208. </tr>
  209. <tr>
  210. <td>max-age</td>
  211. <td>A suggestion regarding how long (in seconds) to cache the data; the meaning matches the Max-Age attribute from &rfc2965;.</td>
  212. <td>RECOMMENDED</td>
  213. </tr>
  214. <tr>
  215. <td>type</td>
  216. <td>The value of the 'type' attribute MUST match the syntax specified in &rfc2045;. That is, the value MUST include a top-level media type, the "/" character, and a subtype; in addition, it MAY include one or more optional parameters (e.g., the "audio/ogg" MIME type in the example shown below includes a "codecs" parameter as specified in &rfc4281;). The "type/subtype" string SHOULD be registered in the &ianamedia;, but MAY be an unregistered or yet-to-be-registered value.</td>
  217. <td>REQUIRED if the &lt;data/&gt; element is non-empty</td>
  218. </tr>
  219. </table>
  220. <p>The following example illustrates the format (line endings are provided for readability only).</p>
  221. <example caption='Data element format'><![CDATA[
  222. <data xmlns='urn:xmpp:bob'
  223. cid=''
  224. max-age='86400'
  225. type='image/png'>
  229. REFUGNO9zL0NglAAxPEfdLTs4BZM4DIO4C7OwQg2JoQ9LE1exdlYvBBeZ7jq
  230. ch9//q1uH4TLzw4d6+ErXMMcXuHWxId3KOETnnXXV6MJpcq2MLaI97CER3N0
  231. vr4MkhoXe0rZigAAAABJRU5ErkJggg==
  232. </data>
  233. ]]></example>
  234. </section2>
  235. </section1>
  236. <section1 topic='Determining Support' anchor='support'>
  237. <p>If an entity supports the protocol specified herein, it MUST advertise that fact by returning a feature of "urn:xmpp:bob" in response to &xep0030; information requests.</p>
  238. <example caption="Service discovery information request"><![CDATA[
  239. <iq from='doctor@shakespeare.lit/pda'
  240. id='disco1'
  241. to='ladymacbeth@shakespeare.lit/castle'
  242. type='get'>
  243. <query xmlns=''/>
  244. </iq>
  245. ]]></example>
  246. <example caption="Service discovery information response"><![CDATA[
  247. <iq from='ladymacbeth@shakespeare.lit/castle'
  248. id='disco1'
  249. to='doctor@shakespeare.lit/pda'
  250. type='result'>
  251. <query xmlns=''>
  252. ...
  253. <feature var='urn:xmpp:bob'/>
  254. ...
  255. </query>
  256. </iq>
  257. ]]></example>
  258. <p>In order for an application to determine whether an entity supports this protocol, where possible it SHOULD use the dynamic, presence-based profile of service discovery defined in &xep0115;. However, if an application has not received entity capabilities information from an entity, it SHOULD use explicit service discovery instead.</p>
  259. </section1>
  260. <section1 topic='Security Considerations' anchor='security'>
  261. <p>The ability to include arbitrary binary data implies that it is possible to send scripts, applets, images, and executable code, which may be potentially harmful. To reduce the risk of such exposure, an implementation MAY choose to not display or process such data but instead either completely ignore the data, show only the value of the 'alt' attribute, or prompt a human user for approval (either explicitly via user action or implicitly via a list of approved entities from whom the user will accept binary data without per-event approval).</p>
  262. </section1>
  263. <section1 topic='IANA Considerations' anchor='iana'>
  264. <p>This document requires no interaction with &IANA;.</p>
  265. </section1>
  266. <section1 topic='XMPP Registrar Considerations' anchor='registrar'>
  267. <section2 topic='Protocol Namespaces' anchor='ns'>
  268. <p>The &REGISTRAR; includes "urn:xmpp:bob" in its registry of protocol namespaces (see &NAMESPACES;).</p>
  269. </section2>
  270. </section1>
  271. <section1 topic='XML Schema' anchor='schema'>
  272. <code><![CDATA[
  273. <?xml version='1.0' encoding='UTF-8'?>
  274. <xs:schema
  275. xmlns:xs=''
  276. targetNamespace='urn:xmpp:bob'
  277. xmlns='urn:xmpp:bob'
  278. elementFormDefault='qualified'>
  279. <xs:annotation>
  280. <xs:documentation>
  281. The protocol documented by this schema is defined in
  282. XEP-0231:
  283. </xs:documentation>
  284. </xs:annotation>
  285. <xs:element name='data'>
  286. <xs:complexType>
  287. <xs:simpleContent>
  288. <xs:extension base='xs:base64Binary'>
  289. <xs:attribute name='cid' type='xs:string' use='required'/>
  290. <xs:attribute name='max-age' type='xs:nonNegativeInteger' use='optional'/>
  291. <xs:attribute name='type' type='xs:string' use='optional'/>
  292. </xs:extension>
  293. </xs:simpleContent>
  294. </xs:complexType>
  295. </xs:element>
  296. </xs:schema>
  297. ]]></code>
  298. </section1>
  299. <section1 topic='Acknowledgements' anchor='ack'>
  300. <p>Thanks to Rachel Blackman, Dave Cridland, Zenon Kuder, and Tomasz Sterna for their feedback.</p>
  301. </section1>
  302. </xep>