forked from xsf/xeps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xep-0050.xml
1005 lines (994 loc) · 50 KB
/
xep-0050.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE xep SYSTEM 'xep.dtd' [
<!ENTITY % ents SYSTEM 'xep.ent'>
%ents;
]>
<?xml-stylesheet type='text/xsl' href='xep.xsl'?>
<xep>
<header>
<title>Ad-Hoc Commands</title>
<abstract>This document defines an XMPP protocol extension for advertising and executing application-specific commands, such as those related to a configuration workflow. Typically the commands contain data forms (XEP-0004) in order to structure the information exchange.</abstract>
&LEGALNOTICE;
<number>0050</number>
<status>Draft</status>
<type>Standards Track</type>
<sig>Standards</sig>
<dependencies>
<spec>XMPP Core</spec>
<spec>XEP-0004</spec>
<spec>XEP-0030</spec>
</dependencies>
<supersedes/>
<supersededby/>
<shortname>commands</shortname>
<schemaloc>
<url>http://www.xmpp.org/schemas/commands.xsd</url>
</schemaloc>
&linuxwolf;
<revision>
<version>1.2.2</version>
<date>2016-12-03</date>
<initials>XEP Editor (ssw, fs)</initials>
<remark>Mark 'note' element's 'type' attribute as optional in the schema. Introduce 'Acknowledgements' section.</remark>
</revision>
<revision>
<version>1.2.1</version>
<date>2015-10-15</date>
<initials>XEP Editor (mam)</initials>
<remark>Corrected text regarding "xml:lang" is an attribute not an element (Christian Schudt).</remark>
</revision>
<revision>
<version>1.2</version>
<date>2005-06-30</date>
<initials>psa</initials>
<remark>Corrected typos and other small errors.</remark>
</revision>
<revision>
<version>1.1.1</version>
<date>2004-01-02</date>
<initials>lw</initials>
<remark>Cleaned up errors in schema; added more clarifications about actions</remark>
</revision>
<revision>
<version>1.1</version>
<date>2003-12-30</date>
<initials>lw</initials>
<remark>More strict usage of the terms "requester" and "responder"; added explicit flow-control information; cleaned up i18n and l10n based on IETF efforts</remark>
</revision>
<revision>
<version>1.0</version>
<date>2003-05-19</date>
<initials>psa</initials>
<remark>Per a vote of the Jabber Council, advanced status to Draft.</remark>
</revision>
<revision>
<version>0.13</version>
<date>2003-04-28</date>
<initials>lw</initials>
<remark>More clarity on security; added notes about i18n and l10n; included xml:lang in XML-Schema.</remark>
</revision>
<revision>
<version>0.12</version>
<date>2003-04-22</date>
<initials>lw</initials>
<remark>Fixed typos; removed references to &PRESENCE;; added more security condiderations; added notes about <command/> child precedence.</remark>
</revision>
<revision>
<version>0.11</version>
<date>2003-02-20</date>
<initials>lw</initials>
<remark>Created XML Schema.</remark>
</revision>
<revision>
<version>0.10</version>
<date>2003-02-20</date>
<initials>lw</initials>
<remark>Relaxed and clarified <command/> payload requirements; Fixed minor errors in examples.</remark>
</revision>
<revision>
<version>0.9.1</version>
<date>2003-02-12</date>
<initials>lw</initials>
<remark>Fixed disco examples to reflect specification text.</remark>
</revision>
<revision>
<version>0.9</version>
<date>2003-02-09</date>
<initials>lw</initials>
<remark>Added "Implementation Notes" section; Removed syntax requirements for disco <item/> "node" attributes; Added "disclaimer" with regards to "node" values; Added clarifications regarding predefined/required commands; Added clarifications for command payloads; Added clarifications for command success versus failure; Added clarifications on "sessionid"; Fixed "x:data" errors.</remark>
</revision>
<revision>
<version>0.8</version>
<date>2003-01-26</date>
<initials>lw</initials>
<remark>Fixed minor grammatical errors; Changed some MUSTs to SHOULDs.</remark>
</revision>
<revision>
<version>0.7</version>
<date>2003-01-22</date>
<initials>lw</initials>
<remark>Added disco node syntax for commands; Expanded "XMPP Registrar" section.</remark>
</revision>
<revision>
<version>0.6</version>
<date>2003-01-21</date>
<initials>lw</initials>
<remark>Consistency in the usage of the "x-commands" short name; Added "Discovering Support" usecase; made other disco usage more "disco-like".</remark>
</revision>
<revision>
<version>0.5</version>
<date>2003-01-18</date>
<initials>lw</initials>
<remark>Fixed minor errors; Removed "complete" action value from <command/>; Removed <list/> in favor of disco.</remark>
</revision>
<revision>
<version>0.4</version>
<date>2002-11-05</date>
<initials>lw</initials>
<remark>Fixed minor errors with examples; Changed position of DTD to be more consistent with other XEPs by this author; Added details for "disco" support; Added section on "Security Considerations", "IANA Considerations", and "JANA Considerations".</remark>
</revision>
<revision>
<version>0.3</version>
<date>2002-10-11</date>
<initials>lw</initials>
<remark>Fixed minor errors with examples; Changed from using <query/> and <x/> to <list/> for command lists; Made the "cancel" use-case more explicit.</remark>
</revision>
<revision>
<version>0.2</version>
<date>2002-10-10</date>
<initials>lw</initials>
<remark>Changed namespace from "jabber:x:commands" to "http://jabber.org/protocol/commands"; Changed execution to use <iq/> instead of any packet element; Changed execution to contain extensions; Reorganized for better clarity; Corrected spelling and grammar errors.</remark>
</revision>
<revision>
<version>0.1</version>
<date>2002-10-08</date>
<initials>lw</initials>
<remark>Initial release.</remark>
</revision>
</header>
<section1 topic='Introduction' anchor='intro'>
<p>This document specifies an XMPP protocol extension that enables an entity to initiate a command session where there is no preferred namespace. It also specifies a protocol extension for describing the types of ad hoc sessions, similar in concept to a menu.</p>
<section2 topic='Motivation' anchor='motivation'>
<p>The motivation for such a protocol comes from the desire to expand Jabber technologies outside the domain of instant messaging. Similar to web applications, these "Jabber applications" are systems in which, via a compliant Jabber client, a user (or automated process) can interact with the application. The client need not be specially-written in order to take advantage of this Jabber application.</p>
<p>This mechanism allows for a larger base of Jabber entities to participate as part of larger application architectures. Although specialized clients would be preferred in many environments, this protocol allows for applications to have a wider audience (i.e., any compliant Jabber client).</p>
</section2>
<section2 topic='Concepts' anchor='concepts'>
<p>The namespace governing this protocol is "http://jabber.org/protocol/commands" (hereafter referred to as x-commands). This namespace relies on the &IQ; element for execution, and can use the &MESSAGE; element for announcing command lists. This protocol depends on &xep0030; for reporting and announcing command lists. This namespace is intended to complement &xep0004; (jabber:x:data), but is not necessarily dependent upon it.</p>
</section2>
<section2 topic='Prerequisites' anchor='prerequisites'>
<p>Support of x-commands implies support for "jabber:x:data" (although this requirement may be replaced and/or amended with a requirement to support &xep0020; by performing the appropriate negotations before executing commands). x-commands provides a bootstrap for performing ad-hoc "jabber:x:data" processes, while the data itself is conveyed using "jabber:x:data".</p>
<p>The x-commands namespace is not designed to replace machine-to-machine oriented RPC systems such as &xep0009;, where the two entities fully understand the command's purpose and behavior prior to execution. x-commands is oriented more for human interaction, where the user agent (such as a compliant Jabber client) most likely has no prior knowledge of the command's purpose and behavior.</p>
</section2>
</section1>
<section1 topic='Use Cases' anchor='usecases'>
<section2 topic='Discovering Support' anchor='discover'>
<p>To determine if an entity supports x-commands, the requester uses Service Discovery. The requester makes an "#info" query to the responder. If supported, the responder includes a <feature/> with the "var" of "http://jabber.org/protocol/commands".</p>
<example caption='Disco request for information'><![CDATA[
<iq type='get'
to='responder@domain'
from='requester@domain'>
<query xmlns='http://jabber.org/protocol/disco#info'/>
</iq>
]]></example>
<example caption='Disco result for information'><![CDATA[
<iq type='result'
from='responder@domain'
to='requester@domain'>
<query xmlns='http://jabber.org/protocol/disco#info'>
...
<feature var='http://jabber.org/protocol/commands'/>
...
</query>
</iq>
]]></example>
</section2>
<section2 topic='Retrieving the Command List' anchor='retrieve'>
<p>To find what commands an entity provides, the requester uses Service Discovery. Each command is a node of the responder, under the fixed node "http://jabber.org/protocol/commands" (for which the service discovery identity category is "automation" and type is "command-list"). Use of a fixed node for all commands of an entity allows for immediate retrieval of commands.</p>
<p>Each command is a disco item. The node attribute of <item/> identifies the command, and the name attribute is the label for the command.</p>
<p>The requester retrieves the list of commands by querying for the responder's items for the node "http://jabber.org/protocol/commands":</p>
<example caption='Disco request for items'><![CDATA[
<iq type='get'
from='requester@domain'
to='responder@domain'>
<query xmlns='http://jabber.org/protocol/disco#items'
node='http://jabber.org/protocol/commands'/>
</iq>
]]></example>
<example caption='Disco result for items'><![CDATA[
<iq type='result'
to='requester@domain'
from='responder@domain'>
<query xmlns='http://jabber.org/protocol/disco#items'
node='http://jabber.org/protocol/commands'>
<item jid='responder@domain'
node='list'
name='List Service Configurations'/>
<item jid='responder@domain'
node='config'
name='Configure Service'/>
<item jid='responder@domain'
node='reset'
name='Reset Service Configuration'/>
<item jid='responder@domain'
node='start'
name='Start Service'/>
<item jid='responder@domain'
node='stop'
name='Stop Service'/>
<item jid='responder@domain'
node='restart'
name='Restart Service'/>
</query>
</iq>
]]></example>
<p>The result can then be used by the client to populate a menu, a dialog of buttons, or whatever is appropriate to the current user interface. The responder is not required to send the same list of commands to all requesters.</p>
<p>If additional information about a command is desired, the requester queries for disco information on the command node:</p>
<example caption='Disco request for command information'><![CDATA[
<iq type='get'
from='requester@domain'
to='responder@domain'>
<query xmlns='http://jabber.org/protocol/disco#info'
node='config'/>
</iq>
]]></example>
<example caption='Disco result for command information'><![CDATA[
<iq type='result'
to='requester@domain'
from='responder@domain'>
<query xmlns='http://jabber.org/protocol/disco#info'
node='config'>
<identity name='Configure Service'
category='automation'
type='command-node'/>
<feature var='http://jabber.org/protocol/commands'/>
<feature var='jabber:x:data'/>
</query>
</iq>
]]></example>
<p>A responder MUST at least provide <identity category='automation' type='command-node'/> and <feature var='http://jabber.org/protocol/commands'/>, and SHOULD include <feature var='jabber:x:data'/>. It is not required to support additional information about a command. If the command is not available to the requester, the responder SHOULD respond with a 403 "Forbidden" error.</p>
</section2>
<section2 topic='Announcing the Command List' anchor='announce'>
<p>In some cases, a responder entity may find it appropriate to automatically push this information (e.g. a subscribed entity becomes available). In this case, the entity sends a &MESSAGE; containing the proper disco#items &QUERY;:</p>
<example caption='Announcing commands (via <message/>)'><![CDATA[
<message from='responder@domain' to='requester@domain'>
<subject>Service Controls</subject>
<query xmlns='http://jabber.org/protocol/disco#items'
node='http://jabber.org/protocol/commands'>
<item jid='responder@domain'
node='list'
name='List Service Configurations'/>
<item jid='responder@domain'
node='config'
name='Configure Service'/>
<item jid='responder@domain'
node='reset'
name='Reset Service Configuration'/>
<item jid='responder@domain'
node='start'
name='Start Service'/>
<item jid='responder@domain'
node='stop'
name='Stop Service'/>
<item jid='responder@domain'
node='restart'
name='Restart Service'/>
</query>
</message>
]]></example>
<p>The only portion required is <query xmlns='http://jabber.org/protocol/disco#items'/>. Any other information (such as the <subject/> in the foregoing example) is OPTIONAL.</p>
</section2>
<section2 topic='Executing Commands' anchor='execute'>
<section3 topic='Simple Execution' anchor='execute-simple'>
<p>To execute a command, the requester sends an &IQ; containing the command to execute:</p>
<example caption="Execute command request"><![CDATA[
<iq type='set' to='responder@domain' id='exec1'>
<command xmlns='http://jabber.org/protocol/commands'
node='list'
action='execute'/>
</iq>
]]></example>
<p>The requester MAY include the "action='execute'", although this is implied.</p>
<p>If the command does not require any user interaction (returns results only), the responder sends a packet similar to the following:</p>
<example caption="Execute command result"><![CDATA[
<iq type='result' from='responder@domain' to='requester@domain' id='exec1'>
<command xmlns='http://jabber.org/protocol/commands'
sessionid='list:20020923T213616Z-700'
node='list'
status='completed'>
<x xmlns='jabber:x:data' type='result'>
<title>Available Services</title>
<reported>
<field var='service' label='Service'/>
<field var='runlevel-1' label='Single-User mode'/>
<field var='runlevel-2' label='Non-Networked Multi-User mode'/>
<field var='runlevel-3' label='Full Multi-User mode'/>
<field var='runlevel-5' label='X-Window mode'/>
</reported>
<item>
<field var='service'><value>httpd</value></field>
<field var='runlevel-1'><value>off</value></field>
<field var='runlevel-2'><value>off</value></field>
<field var='runlevel-3'><value>on</value></field>
<field var='runlevel-5'><value>on</value></field>
</item>
<item>
<field var='service'><value>postgresql</value></field>
<field var='runlevel-1'><value>off</value></field>
<field var='runlevel-2'><value>off</value></field>
<field var='runlevel-3'><value>on</value></field>
<field var='runlevel-5'><value>on</value></field>
</item>
<item>
<field var='service'><value>jabberd</value></field>
<field var='runlevel-1'><value>off</value></field>
<field var='runlevel-2'><value>off</value></field>
<field var='runlevel-3'><value>on</value></field>
<field var='runlevel-5'><value>on</value></field>
</item>
</x>
</command>
</iq>
]]></example>
</section3>
<p>The above example shows the command execution resulting in a "jabber:x:data" form. It is also possible that one or more URLs (specified via &xep0066;) could be returned.</p>
<section3 topic='Multiple Stages' anchor='execute-multiple'>
<p>If the command requires more interaction, the responder sends a result &IQ; that contains the command information and the form to be filled out:</p>
<example caption='Execute command request (stage 1)'><![CDATA[
<iq type='set' to='responder@domain' id='exec1'>
<command xmlns='http://jabber.org/protocol/commands'
node='config'
action='execute'/>
</iq>
]]></example>
<example caption='Execute command result (stage 1)'><![CDATA[
<iq type='result' from='responder@domain' to='requester@domain' id='exec1'>
<command xmlns='http://jabber.org/protocol/commands'
sessionid='config:20020923T213616Z-700'
node='config'
status='executing'>
<actions execute='next'>
<next/>
</actions>
<x xmlns='jabber:x:data' type='form'>
<title>Configure Service</title>
<instructions>
Please select the service to configure.
</instructions>
<field var='service' label='Service' type='list-single'>
<option><value>httpd</value></option>
<option><value>jabberd</value></option>
<option><value>postgresql</value></option>
</field>
</x>
</command>
</iq>
]]></example>
<p>The <command/> SHOULD include an <actions/> element, which specifies the details of what the allowed actions are for this stage of execution. Each element within <action/> matches a possible value for the <command/> element's "action" attribute. The "execute" attribute defines which of the included actions is considered the equivalent to "execute" for this stage. In the above example, the only allowed action is to progress to the next stage, which is also the default.</p>
<p>The requester then submits the form, maintaining the command node and sessionid:</p>
<example caption='Execute command request (stage 2)'><![CDATA[
<iq type='set' to='responder@domain' id='exec2'>
<command xmlns='http://jabber.org/protocol/commands'
sessionid='config:20020923T213616Z-700'
node='config'>
<x xmlns='jabber:x:data' type='submit'>
<field var='service'>
<value>httpd</value>
</field>
</x>
</command>
</iq>
]]></example>
<p>The responder then provides the next stage's form in the result <note>Note that the second stage can be reverted to the first stage or completed (signaled by the inclusion of the <prev/> and <complete/> elements), and that the default action is to complete execution (signaled by the "execute" attribute's value of "complete").</note>:</p>
<example caption='Execute command result (stage 2)'><![CDATA[
<iq type='result' from='responder@domain' to='requester@domain' id='exec2'>
<command xmlns='http://jabber.org/protocol/commands'
sessionid='config:20020923T213616Z-700'
node='config'
status='executing'>
<actions execute='complete'>
<prev/>
<complete/>
</actions>
<x xmlns='jabber:x:data' type='form'>
<title>Configure Service</title>
<instructions>
Please select the run modes and state for 'httpd'.
</instructions>
<field var='runlevel' label='Run Modes' type='list-multi'>
<value>3</value>
<value>5</value>
<option label='Single-User'><value>1</value></option>
<option label='Non-Networked Multi-User'><value>2</value></option>
<option label='Full Multi-User'><value>3</value></option>
<option label='X-Window'><value>5</value></option>
</field>
<field var='state' label='Run State' type='list-single'>
<value>off</value>
<option label='Active'><value>off</value></option>
<option label='Inactive'><value>on</value></option>
</field>
</x>
</command>
</iq>
]]></example>
<p>The requester then submits the second stage's form, again maintaining the node and sessionid:</p>
<example caption='Execute command request (stage 3)'><![CDATA[
<iq type='set' to='responder@domain' id='exec3'>
<command xmlns='http://jabber.org/protocol/commands'
sessionid='config:20020923T213616Z-700'
node='config'>
<x xmlns='jabber:x:data' type='submit'>
<field var='mode'>
<value>3</value>
</field>
<field var='state'>
<value>on</value>
</field>
</x>
</command>
</iq>
]]></example>
<example caption='Execute command result (stage 3)'><![CDATA[
<iq type='result' from='responder@domain' to='requester@domain' id='exec3'>
<command xmlns='http://jabber.org/protocol/commands'
sessionid='config:20020923T213616Z-700'
node='config'
status='completed'>
<note type='info'>Service 'httpd' has been configured.</note>
</command>
</iq>
]]></example>
<p>If the requester wishes to revert to the previous stage, it sends an &IQ; with the command's node and sessionid, and "action='prev'":</p>
<example caption='Execute command request (revert from stage 2 to stage 1)'><![CDATA[
<iq type='set' to='responder@domain' id='exec2'>
<command xmlns='http://jabber.org/protocol/commands'
sessionid='config:20020923T213616Z-700'
node='config'
action='prev'/>
</iq>
]]></example>
<p>If the responder accepts this, it responds with the previous stage's command <note>The responder MAY present "remembered" field values, but doing so is OPTIONAL.</note>:</p>
<example caption='Execute command result (revert from stage 2 to stage 1)'><![CDATA[
<iq type='result' from='responder@domain' to='requester@domain' id='exec2'>
<command xmlns='http://jabber.org/protocol/commands'
sessionid='config:20020923T213616Z-700'
node='config'
status='executing'>
<actions execute='next'>
<next/>
</actions>
<x xmlns='jabber:x:data' type='form'>
<title>Configure Service</title>
<instructions>
Please select the service to configure.
</instructions>
<field var='service' label='Service' type='list-single'>
<value>httpd</value>
<option><value>httpd</value></option>
<option><value>jabberd</value></option>
<option><value>postgresql</value></option>
</field>
</x>
</command>
</iq>
]]></example>
</section3>
<section3 topic='Canceling' anchor='cancel'>
<p>In the case where a command has multiple stages, the requester may wish to cancel at some point. To cancel, the requester sends the continuing command request with an "action='cancel'":</p>
<example caption='Execute command request (stage 2; canceling)'><![CDATA[
<iq type='set' to='responder@domain' id='exec3'>
<command xmlns='http://jabber.org/protocol/commands'
sessionid='config:20020923T213616Z-700'
node='config'
action='cancel'/>
</iq>
]]></example>
<p>This enables the responder to free any resources allocated during the process. The responder MUST reply with the success of the command:</p>
<example caption='Execute command result (stage 2; canceled)'><![CDATA[
<iq type='result' from='responder@domain' to='requester@domain' id='exec3'>
<command xmlns='http://jabber.org/protocol/commands'
sessionid='config:20020923T213616Z-700'
node='config'
status='canceled'/>
</iq>
]]></example>
</section3>
</section2>
</section1>
<section1 topic='Implementation Notes' anchor='impl'>
<section2 topic='Defined/Required Command Nodes' anchor='impl-req'>
<p>All commands used in the above examples are for illustrative purposes only. There are no predefined or required commands.</p>
</section2>
<section2 topic='Command Nodes' anchor='impl-nodes'>
<p>Each command is identified by its 'node' attribute. This matches the 'node' attribute from the service discovery <item/> element. Service Discovery requires that all 'node' values be unique within a given JID. This document requires that the 'node' value used in <command/> exactly match the value used in the <item/> element. It is the responsibility of the responder implementation to ensure each command's node is unique for their JID.</p>
</section2>
<section2 topic='Session Lifetime' anchor='impl-session'>
<p>The execution of a command exists within the concept of a session. Each session is identified by the 'sessionid' attribute, and SHOULD be valid only between one requester/responder pair. The responder is responsible for determining the session lifetime, with some help from the requester.</p>
<p>The requester starts a new session for a command by simply sending a <command/> with the 'node' attribute (and optionally the 'status' attribute with a value of "execute"). Once the 'sessionid' attribute is given to the requester, it is the requester's responsibility to maintain it for the session's lifetime. A session ends when the responder sends a <command status='completed'/> or the requester sends a <command action='cancel'/> with the provided 'sessionid' value.</p>
<p>Once a session has ended, its 'sessionid' value SHOULD NOT be used again. It is the responder's responsibility to ensure that each 'sessionid' value is unique.</p>
<p>It may be possible for a requester to be executing more than one session of the same command with a given responder. If the responder does not allow more than one session of the same command with the same requester, the responder MUST return a ¬allowed; error (see &xep0086;).</p>
</section2>
<section2 topic='Command Actions' anchor='impl-actions'>
<p>The result for each stage (other than the last) of a command's execution SHOULD include an <actions/> element. The user-agent can use this information to present a more-intelligent user interface, such as a "druid" or "wizard".</p>
<p>For a user-agent, a typical interpretation of the <actions/> information (or lack thereof) would be the following:</p>
<ol>
<li>The action "cancel" is always allowed.</li>
<li>If there is no <actions/> element, the user-agent can use a single-stage dialog or view.
<ul>
<li>The action "execute" is equivalent to the action "complete".</li>
</ul>
</li>
<li>If there is an <actions/> element, the user-agent usually uses a multi-stage dialog or view, such as a wizard.
<ul>
<li>The action "execute" is always allowed, and is equivalent to the action "next".</li>
<li>The "prev" action is typically the "back" or "previous" button or option in a wizard. If <prev/> is not contained by the <actions/>, it is disabled.</li>
<li>The "next" action is typically the "next" button or option in a wizard. If <next/> is not contained by the <actions/>, it is disabled.</li>
<li>The "complete" action is typically the "finish" or "done" button or option in a wizard. If <complete/> is not contained by the <actions/>, it is disabled.</li>
<li>If the <actions/> possesses the "execute" attribute, that value is the default button or option. If the <actions/> does not possess the "execute" attribute, there is no default button or option.</li>
</ul>
</li>
</ol>
<p>Responders SHOULD use the following guidelines when providing <actions/>:</p>
<ul>
<li>The "execute" attribute SHOULD NOT specify a value that does not match one of the allowed actions.</li>
</ul>
</section2>
<section2 topic='Command Payloads' anchor='impl-payloads'>
<p>On its own, the <command/> has very little usefulness. It relies on its payload to give full meaning to its use. The payload can be elements in any namespace that makes sense and is understood (such as "jabber:x:data"), and/or one or more <note/> elements. Any namespaced elements can be used within a <command/>. The only limitations are that the elements not require certain parent elements (such as &IQ;), or specifically allow for <command/> qualified by the "http://jabber.org/protocol/commands" namespace as a possible parent element.</p>
<p>As a general rule, the payload is provided only by the responder. The primary exception to this rule is with the "jabber:x:data" extension (and other namespaces with similar semantics). In this case, if the responder provides a form to submit, the requester SHOULD respond with the submitted data (using the semantics from XEP-0004).</p>
<p>When the precedence of these payload elements becomes important (such as when both "jabber:x:data" and "jabber:x:oob" elements are present), the order of the elements SHOULD be used. Those elements that come earlier in the child list take precedence over those later in the child list. The requester SHOULD consider those elements qualified by the same namespace as having an equivalent precedence (such as if multiple "jabber:x:oob" elements are included).</p>
<section3 topic='Use of Data Forms' anchor='impl-forms'>
<p>When the payload is "jabber:x:data", there are certain conditions applied. The requester SHOULD NOT use a "jabber:x:data" type other than "submit". Responders SHOULD consider any <x type='cancel'/> to be <x type='submit'/>.</p>
</section3>
</section2>
<section2 topic='Commands Successful/Failed' anchor='impl-commands'>
<p>The status of command execution signals only if the command is executing, has been completed, or been canceled. If completed, the "status" attribute does not specify if it completed successfully or not. If a command completes but fails, the responder MUST include at least one <note type='error'/> with the <command status='completed'/> it returns.</p>
</section2>
<section2 topic='Internationalization and Localization' anchor='impl-i18n'>
<p>The requester SHOULD provide its locale information using the "xml:lang" attribute on either the &IQ; (RECOMMENDED) or <command/> element. Each execution session (identified by the "sessionid" attribute) SHOULD use only one language/locale, and requesters and responders SHOULD assume the first language/locale specified applies. The responder SHOULD specify the language/locale with the every command session's response.</p>
<example caption='Execute command request (with language/locale)'><![CDATA[
<iq type='set' to='responder@domain' id='exec1' xml:lang='en-us'>
<command xmlns='http://jabber.org/protocol/commands'
node='list'
action='execute'/>
</iq>
]]></example>
<example caption="Execute command result (with language/locale)"><![CDATA[
<iq type='result'
from='responder@domain'
to='requester@domain'
id='exec1'
xml:lang='en-us'>
<command xmlns='http://jabber.org/protocol/commands'
sessionid='list:20020923T213616Z-700'
node='list'
status='completed'>
<x xmlns='jabber:x:data' type='result'>
<title>Available Services</title>
<reported>
<field var='service' label='Service'/>
<field var='runlevel-1' label='Single-User mode'/>
<field var='runlevel-2' label='Non-Networked Multi-User mode'/>
<field var='runlevel-3' label='Full Mult-User mode'/>
<field var='runlevel-5' label='X-Window mode'/>
</reported>
<item>
<field var='service'><value>httpd</value></field>
<field var='runlevel-1'><value>off</value></field>
<field var='runlevel-2'><value>off</value></field>
<field var='runlevel-3'><value>on</value></field>
<field var='runlevel-5'><value>on</value></field>
</item>
<item>
<field var='service'><value>postgresql</value></field>
<field var='runlevel-1'><value>off</value></field>
<field var='runlevel-2'><value>off</value></field>
<field var='runlevel-3'><value>on</value></field>
<field var='runlevel-5'><value>on</value></field>
</item>
<item>
<field var='service'><value>jabberd</value></field>
<field var='runlevel-1'><value>off</value></field>
<field var='runlevel-2'><value>off</value></field>
<field var='runlevel-3'><value>on</value></field>
<field var='runlevel-5'><value>on</value></field>
</item>
</x>
</command>
</iq>
]]></example>
<p>Within the "http://jabber.org/protocol/commands" schema, the language/locale applies only to the human-readable character data for <info/> elements. It SHOULD also apply to all payload elements, appropriate to their respective specifications.</p>
<p>Responders MUST take this into consideration, and properly account for the language/locale settings within payloads. If the responder cannot accomodate the requested language/locale, it SHOULD respond with a <bad-request/> (<bad-locale/>) error condition.</p>
<example caption='Execute command request (with language/locale)'><![CDATA[
<iq type='set' to='responder@domain' id='exec1' xml:lang='fr-ca'>
<command xmlns='http://jabber.org/protocol/commands'
node='list'
action='execute'/>
</iq>
]]></example>
<example caption='Execute command failed result (with language/locale)'><![CDATA[
<iq type='error' from='responder@domain' to='requester@domain/resource' id='exec1'>
<command xmlns='http://jabber.org/protocol/commands'
node='list'
action='execute'
xml:lang='fr-ca'/>
<error type='modify' code='400'>
<bad-request xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
<bad-locale xmlns='http://jabber.org/protocol/commands'/>
</error>
</iq>
]]></example>
</section2>
</section1>
<section1 topic='Formal Description' anchor='desc'>
<p>The focal element in x-commands is <command/>. It is the element used to guide the process, and the element used to report command options.</p>
<section2 topic='<command/> Element' anchor='desc-command'>
<p>Each <command/> contains attributes for a node, a "session id", an action type, a status type, and a language/locale specifier. A command MAY contain zero or more <note/> elements and MAY contain other namespaced elements as payload. Elements qualified by the "jabber:x:data" and "jabber:x:oob" namespaces are the typical payload.</p>
<p>The "node" attribute uniquely identifies the command. This attribute MUST be present.</p>
<p>The "sessionid" attribute helps to track a command execution across multiple stages. This attribute MUST be present for subsequent stages, and the responder SHOULD initialize (if not provided) or maintain this attribute. The value of this attribute MUST NOT be empty or null, but otherwise can be any string value. This value MUST be maintained by a requester while executing a command.</p>
<p>The "status" attribute describes the current status of this command. This value SHOULD be set only by the responder. If specified by the requester, the responder MUST ignore it. The value of "status" MUST be one of the following:</p>
<table caption='Possible "status" values'>
<tr>
<th>Status</th>
<th>Description</th>
</tr>
<tr>
<td>executing</td>
<td>The command is being executed.</td>
</tr>
<tr>
<td>completed</td>
<td>The command has completed. The command session has ended.</td>
</tr>
<tr>
<td>canceled</td>
<td>The command has been canceled. The command session has ended.</td>
</tr>
</table>
<p>The "action" attribute specifies the action to undertake with the given command. This value SHOULD be set only by the requester. If specified by the responder, the requester MUST ignore it. The value of "action" MUST be one of the following:</p>
<table caption='Possible "action" values'>
<tr>
<th>Action</th>
<th>Description</th>
</tr>
<tr>
<td>execute</td>
<td>The command should be executed or continue to be executed. This is the default value.</td>
</tr>
<tr>
<td>cancel</td>
<td>The command should be canceled.</td>
</tr>
<tr>
<td>prev</td>
<td>The command should be digress to the previous stage of execution.</td>
</tr>
<tr>
<td>next</td>
<td>The command should progress to the next stage of execution.</td>
</tr>
<tr>
<td>complete</td>
<td>The command should be completed (if possible).</td>
</tr>
</table>
<p>The "xml:lang" attribute specifies the language/locale this <command/> is intended for. This attribute MAY be specified by the requester to request a specific language/locale, and SHOULD be included by the responder to indicate the language/locale in use.</p>
<p>The children of a <command/> element (other than <actions/> and <note/>) pertain to the command's execution. The order of these elements denote their precedence, so that those elements earlier in the list have higher precedence.</p>
</section2>
<section2 topic='<actions/> Element' anchor='desc-actions'>
<p>The allowed actions for a particular stage of execution are provided by the <actions/> element. This element SHOULD be provided by the responder if the command's execution is not complete, and SHOULD NOT ever be provided by the requester. It contains a single attribute to specify what the "execute" action equals. It contains child elements to specify what the allowed actions are.</p>
<p>The "execute" attribute specifies what the action "execute" is equivalent to. In user-agent interfaces, this represents the default behavior. This attribute MAY be specified by the responder, and MUST equal one of the "action" attribute values for <command/>. The value of this attribute SHOULD match the local name of one of the contained child elements.</p>
<p>The child elements contained by <action/> specify the allowed actions. The name of each child element MUST be one of the following:</p>
<ul>
<li>prev</li>
<li>next</li>
<li>complete</li>
</ul>
</section2>
<section2 topic='<note/> Element' anchor='desc-note'>
<p>Notes about the current status of commands are provided by <note/> elements. This element contains information about current conditions in a command sequence. This element has an attribute that defines the type of note. The body of a <note/> should contain a user-readable text message.</p>
<p>The "type" attribute specifies the severity of the note. This attribute is OPTIONAL, and implies "info" if not present. The value of this attribute MUST be one of the following:</p>
<table caption='Possible "type" values'>
<tr>
<th>Type</th>
<th>Description</th>
</tr>
<tr>
<td>info</td>
<td>The note is informational only. This is not really an exceptional condition.</td>
</tr>
<tr>
<td>warn</td>
<td>The note indicates a warning. Possibly due to illogical (yet valid) data.</td>
</tr>
<tr>
<td>error</td>
<td>The note indicates an error. The text should indicate the reason for the error.</td>
</tr>
</table>
</section2>
<section2 topic='Possible Errors' anchor='desc-errors'>
<p>To simplify the discussion on error conditions, this document uses the following mapping between namespace URIs and namespace prefixes <note>This mapping is provided solely for the purpose of simplifying this discussion.</note>:</p>
<table caption='Namespace Mappings'>
<tr>
<th>Prefix</th>
<th>URI</th>
</tr>
<tr>
<td>xmpp</td>
<td>urn:ietf:params:xml:ns:xmpp-stanzas</td>
</tr>
<tr>
<td>cmd</td>
<td>http://jabber.org/protocol/commands</td>
</tr>
</table>
<p>Below are the possible errors that can occur during execution.</p>
<table caption='Command execution errors'>
<tr>
<th>Error Type</th>
<th>General Condition</th>
<th>Specific Condition</th>
<th>Description</th>
</tr>
<tr>
<td>modify</td>
<td><xmpp:bad-request/></td>
<td><cmd:malformed-action/></td>
<td>The responding JID does not understand the specified action.</td>
</tr>
<tr>
<td>modify</td>
<td><xmpp:bad-request/></td>
<td><cmd:bad-action/></td>
<td>The responding JID cannot accept the specified action.</td>
</tr>
<tr>
<td>modify</td>
<td><xmpp:bad-request/></td>
<td><cmd:bad-locale/></td>
<td>The responding JID cannot accept the specified language/locale.</td>
</tr>
<tr>
<td>modify</td>
<td><xmpp:bad-request/></td>
<td><cmd:bad-payload/></td>
<td>The responding JID cannot accept the specified payload (e.g. the data form did not provide one or more required fields).</td>
</tr>
<tr>
<td>modify</td>
<td><xmpp:bad-request/></td>
<td><cmd:bad-sessionid/></td>
<td>The responding JID cannot accept the specified sessionid.</td>
</tr>
<tr>
<td>cancel</td>
<td><xmpp:not-allowed/></td>
<td><cmd:session-expired/></td>
<td>The requesting JID specified a sessionid that is no longer active (either because it was completed, canceled, or timed out).</td>
</tr>
<tr>
<td>cancel</td>
<td><xmpp:forbidden/></td>
<td>NONE</td>
<td>The requesting JID is not allowed to execute the command.</td>
</tr>
<tr>
<td>cancel</td>
<td><xmpp:item-not-found/></td>
<td>NONE</td>
<td>The responding JID cannot find the requested command node.</td>
</tr>
<tr>
<td>cancel</td>
<td><xmpp:feature-not-implemented/></td>
<td>NONE</td>
<td>The responding JID does not support "http://jabber.org/protocol/commands".</td>
</tr>
</table>
</section2>
</section1>
<section1 topic='Security Considerations' anchor='sec'>
<p>Determining when a command can be executed based on permissions or rights is considered outside the scope of this document. Although such mechanisms are considered specific to the application and/or implementation of this document, future specifications may address these concerns.</p>
<p>When processing reported commands, the requester SHOULD consider any command node that does not match the JID of the responder to be suspicious, and ignore those command nodes. Responders MUST report their own command nodes only, and not the command nodes of other entities. This can help prevent limited cases of spoofing and "social engineering".</p>
</section1>
<section1 topic='IANA Considerations' anchor='iana'>
<p>This document requires no interaction with &IANA;.</p>
</section1>
<section1 topic='XMPP Registrar Considerations' anchor='registrar'>
<section2 topic='Protocol Namespaces' anchor='registrar-ns'>
<p>The ®ISTRAR; includes 'http://jabber.org/protocol/commands' in its registry of protocol namespaces.</p>
</section2>
<section2 topic='Service Discovery Identities' anchor='registrar-disco-identity'>
<p>The XMPP Registrar includes "automation" in its registry of Service Discovery categories for use for any entities and nodes that provide automated or programmed interaction. This category has the following types:</p>
<table caption='Types for Category "automation"'>
<tr>
<th>Type</th>
<th>Description</th>
</tr>
<tr>
<td>command-list</td>
<td>The node for a list of commands; valid only for the node "http://jabber.org/protocol/commands".</td>
</tr>
<tr>
<td>command-node</td>
<td>A node for a specific command; the 'node' attribute uniquely identifies the command.</td>
</tr>
</table>
<p>The registry submission is as follows:</p>
<code><![CDATA[
<category>
<name>automation</name>
<desc>The "automation" category consists of entities and nodes that provide automated or programmed interaction.</desc>
<type>
<name>command-list</name>
<desc>The node for a list of commands; valid only for the node "http://jabber.org/protocol/commands"</desc>
<doc>XEP-0050</doc>
</type>
<type>
<name>command-node</name>
<desc>A node for a specific command; the 'node' attribute uniquely identifies the command</desc>
<doc>XEP-0050</doc>
</type>
</category>
]]></code>
</section2>
<section2 topic='Well-Known Service Discovery Nodes' anchor='registrar-disco-nodes'>
<p>The XMPP Registrar includes "http://jabber.org/protocol/commands" in its registry of well-known Service Discovery nodes.</p>
</section2>
<section2 topic='URI Query Types' anchor='registrar-querytypes'>
<p>As authorized by &xep0147;, the XMPP Registrar maintains a registry of queries and key-value pairs for use in XMPP URIs (see &QUERYTYPES;).</p>
<p>The "command" querytype is defined herein for interaction with entities that support the ad-hoc command protocol, with keys of "action" and "node".</p>
<example caption='Command Action: IRI/URI'><![CDATA[
xmpp:montague.net?command;node=stats
]]></example>
<example caption='Command Action: Resulting Stanza'><![CDATA[
<iq to='montague.net' type='set'>
<command xmlns='http://jabber.org/protocol/commands' node='stats'/>
</iq>
]]></example>
<p>The following submission registers the "command" querytype.</p>
<code><![CDATA[
<querytype>
<name>command</name>
<proto>http://jabber.org/protocol/commands</proto>
<desc>enables completion of ad-hoc commands</desc>
<doc>XEP-0050</doc>
<keys>
<key>
<name>action</name>
<desc>the ad-hoc commands action type</desc>
<values>
<value>
<name>cancel</name>
<desc>a request to cancel processing of the command</desc>
</value>
<value>
<name>complete</name>
<desc>a request to complete processing of the command</desc>
</value>
<value>
<name>execute</name>
<desc>a request to execute the command (the default implied action)</desc>
</value>
<value>
<name>next</name>
<desc>a request to move to the next command in a series</desc>
</value>
<value>
<name>prev</name>
<desc>a request to move to the previous command in a series</desc>
</value>
</values>
</key>
<key>
<name>node</name>
<desc>the command node</desc>
</key>
</keys>
</querytype>
]]></code>
</section2>
</section1>
<section1 topic='XML Schema' anchor='schema'>
<code><![CDATA[
<?xml version='1.0' encoding='UTF-8'?>
<xs:schema
xmlns:xs='http://www.w3.org/2001/XMLSchema'
targetNamespace='http://jabber.org/protocol/commands'
xmlns='http://jabber.org/protocol/commands'
elementFormDefault='qualified'>
<xs:annotation>
<xs:documentation>
The protocol documented by this schema is defined in
XEP-0050: http://www.xmpp.org/extensions/xep-0050.html
</xs:documentation>
</xs:annotation>
<xs:import namespace='http://www.w3.org/XML/1998/namespace'
schemaLocation='http://www.w3.org/2001/03/xml.xsd'/>
<xs:element name='command'>
<xs:complexType>
<xs:choice>
<xs:element ref='actions' minOccurs='0'/>
<xs:element ref='note' minOccurs='0' maxOccurs='unbounded'/>
<xs:any namespace='##other' minOccurs='0' maxOccurs='unbounded'/>
</xs:choice>
<xs:attribute name='action' use='optional'>
<xs:simpleType>
<xs:restriction base='xs:NCName'>
<xs:enumeration value='cancel'/>
<xs:enumeration value='complete'/>
<xs:enumeration value='execute'/>
<xs:enumeration value='next'/>
<xs:enumeration value='prev'/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name='node' type='xs:string' use='required'/>
<xs:attribute name='sessionid' type='xs:string' use='optional'/>
<xs:attribute name='status' use='optional'>
<xs:simpleType>
<xs:restriction base='xs:NCName'>
<xs:enumeration value='canceled'/>
<xs:enumeration value='completed'/>
<xs:enumeration value='executing'/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute ref='xml:lang' use='optional'/>
</xs:complexType>
</xs:element>
<xs:element name='actions'>
<xs:complexType>
<xs:sequence>
<xs:element name='prev' type='empty' minOccurs='0'/>
<xs:element name='next' type='empty' minOccurs='0'/>
<xs:element name='complete' type='empty' minOccurs='0'/>
</xs:sequence>
<xs:attribute name='execute' use='optional'>
<xs:simpleType>
<xs:restriction base='xs:NCName'>
<xs:enumeration value='complete'/>
<xs:enumeration value='next'/>
<xs:enumeration value='prev'/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
<xs:element name='note'>
<xs:complexType>
<xs:simpleContent>
<xs:extension base='xs:string'>
<xs:attribute name='type' use='optional'>
<xs:simpleType>
<xs:restriction base='xs:NCName'>
<xs:enumeration value='error'/>
<xs:enumeration value='info'/>
<xs:enumeration value='warn'/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name='bad-action' type='empty'/>
<xs:element name='bad-locale' type='empty'/>
<xs:element name='bad-payload' type='empty'/>
<xs:element name='bad-sessionid' type='empty'/>
<xs:element name='malformed-action' type='empty'/>
<xs:element name='session-expired' type='empty'/>
<xs:simpleType name='empty'>
<xs:restriction base='xs:string'>
<xs:enumeration value=''/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
]]></code>
</section1>
<section1 topic='Acknowledgements' anchor='acks'>