@@ -240,18 +240,19 @@ stanza_pubsub() {
240240 ns+=" #owner"
241241 fi
242242
243- # Head
244- cat << -EOF
245- <pubsub xmlns='$ns '>
246- EOF
243+ stanza pubsub " xmlns=$ns "
244+ }
247245
248- # Body
249- cat
246+ # stanza_query <items|info> [node]
247+ stanza_query () {
248+ local typ=$1
249+ local node=$2
250250
251- # Tail
252- cat << -EOF
253- </pubsub>
254- EOF
251+ if [ -n " $node " ]; then
252+ stanza query " xmlns=http://jabber.org/protocol/disco#$typ " " node=$node "
253+ else
254+ stanza query " xmlns=http://jabber.org/protocol/disco#$typ "
255+ fi
255256}
256257
257258# Generate a unique id
@@ -446,40 +447,47 @@ get_config() {
446447 echo " Version $XMPPCMD_VERSION "
447448}
448449
449- # message <to> <message_body>
450+ # message <to> <message_body | - >
450451message () {
451452 local to=$( qualify_jid $1 )
452453
453454 # check args
454455 if (( $# < 2 )) || [[ " $1 " =~ --help ]] || [[ " $1 " =~ -h ]]; then
455- echo " Usage: message <to> <message_body>"
456+ echo " Usage: message <to> <message_body | ->"
457+ echo " Specify - to read body from stdin"
456458 return 0
457459 fi
458460
459461 shift 1
460462 local id=` newid`
461- send << -EOF
462- <message type='chat'
463- id='$id '
464- to='$to '>
465- <body>$* </body>
466- </message>
467- EOF
463+ if [ " $* " = " -" ]; then
464+ stanza body \
465+ | stanza message " type=chat" " id=$id " " to=$to " \
466+ | send
467+ else
468+ echo -n $* \
469+ | stanza body \
470+ | stanza message " type=chat" " id=$id " " to=$to " \
471+ | send
472+ fi
468473}
469474
475+ # Create a node
470476# create <node>
471477create () {
472478 local node=$1
473479
474480 # check args
475481 if (( $# < 1 )) || [[ " $1 " =~ --help ]] || [[ " $1 " =~ -h ]]; then
476482 echo " Usage: create <node>"
483+ echo " Create a node"
477484 return 0
478485 fi
479486
480- echo " <create node='$node '/>" \
481- | stanza_pubsub \
482- | send_stanza_iq set
487+ eof \
488+ | stanza create " node=$node " \
489+ | stanza_pubsub \
490+ | send_stanza_iq set
483491}
484492
485493# Delete a node
@@ -490,12 +498,14 @@ delete() {
490498 # check args
491499 if (( $# < 1 )) || [[ " $1 " =~ --help ]] || [[ " $1 " =~ -h ]]; then
492500 echo " Usage: delete <node>"
501+ echo " Delete a node"
493502 return 0
494503 fi
495504
496- echo " <delete node='$node '/>" \
497- | stanza_pubsub owner \
498- | send_stanza_iq set
505+ eof \
506+ | stanza delete " node=$node " \
507+ | stanza_pubsub owner \
508+ | send_stanza_iq set
499509}
500510
501511# publish <node> <item_id> < item_content | - >
@@ -512,29 +522,16 @@ publish() {
512522 fi
513523
514524 shift 2
515- {
516- # Emit the beginning of the publish message
517- cat << -EOF
518- <pubsub xmlns='http://jabber.org/protocol/pubsub'>
519- <publish node='$node '>
520- <item id='$item_id '>
521- EOF
522-
523- # Emit content to publish
524- if [ " $* " = " -" ]; then
525- cat
526- else
527- echo -n $*
528- fi
529-
530- # Emit the ending of the publish message
531- cat << -EOF
532- </item>
533- </publish>
534- </pubsub>
535- EOF
536- } \
537- | send_stanza_iq set
525+ # Emit content to publish
526+ if [ " $* " = " -" ]; then
527+ cat
528+ else
529+ echo -n $*
530+ fi \
531+ | stanza item " id=$item_id " \
532+ | stanza publish " node=$node " \
533+ | stanza_pubsub \
534+ | send_stanza_iq set
538535}
539536
540537# Delete a node's item
@@ -628,7 +625,7 @@ get_nodes() {
628625 fi
629626
630627 eof \
631- | stanza query " xmlns=http://jabber.org/protocol/disco# items" \
628+ | stanza_query items \
632629 | send_stanza_iq get
633630}
634631
@@ -691,26 +688,21 @@ set_subscribers() {
691688
692689 shift 1
693690
694- {
695- echo " <subscriptions node='$node '>"
696-
697- while [ $# -gt 0 ]; do
698- if [ $# -lt 2 ]; then
699- echo " Error - Impropper number of arguments" >&2
700- return 1
701- fi
702-
703- local jid=$( qualify_jid $1 )
704- local subscription=$2
705- shift 2
691+ while [ $# -gt 0 ]; do
692+ if [ $# -lt 2 ]; then
693+ echo " Error - Impropper number of arguments" >&2
694+ return 1
695+ fi
706696
707- echo " <subscription jid='$jid ' subscription='$subscription '/>"
708- done
697+ local jid=$( qualify_jid $1 )
698+ local subscription=$2
699+ shift 2
709700
710- echo " </subscriptions>"
711- } \
712- | stanza_pubsub owner \
713- | send_stanza_iq set
701+ eof | stanza subscription " jid=$jid " " subscription=$subscription "
702+ done \
703+ | stanza subscriptions " node=$node " \
704+ | stanza_pubsub owner \
705+ | send_stanza_iq set
714706
715707}
716708
@@ -774,26 +766,21 @@ set_affiliations() {
774766
775767 shift 1
776768
777- {
778- echo " <affiliations node='$node '>"
779-
780- while [ $# -gt 0 ]; do
781- if [ $# -lt 2 ]; then
782- echo " Error - Impropper number of arguments" >&2
783- return 1
784- fi
769+ while [ $# -gt 0 ]; do
770+ if [ $# -lt 2 ]; then
771+ echo " Error - Impropper number of arguments" >&2
772+ return 1
773+ fi
785774
786- local jid=$( qualify_jid $1 )
787- local affiliation=$2
788- shift 2
775+ local jid=$( qualify_jid $1 )
776+ local affiliation=$2
777+ shift 2
789778
790- echo " <affiliation jid='$jid ' affiliation='$affiliation '/>"
791- done
792-
793- echo " </affiliations>"
794- } \
795- | stanza_pubsub owner \
796- | send_stanza_iq set
779+ eof | stanza affiliation " jid=$jid " " affiliation=$affiliation "
780+ done \
781+ | stanza affiliations " node=$node " \
782+ | stanza_pubsub owner \
783+ | send_stanza_iq set
797784
798785}
799786
@@ -808,8 +795,9 @@ get_items() {
808795 return 0
809796 fi
810797
811- echo " <query xmlns='http://jabber.org/protocol/disco#items' node='$node '/>" \
812- | send_stanza_iq get
798+ eof \
799+ | stanza_query items " $node " \
800+ | send_stanza_iq get
813801}
814802
815803# Get item(s) for a node
@@ -832,21 +820,16 @@ get_item() {
832820
833821 shift 1
834822
835- {
836- echo " <items node='$node '>"
837-
838- while [ $# -gt 0 ]; do
823+ while [ $# -gt 0 ]; do
839824
840- local item_id=$1
841- shift 1
825+ local item_id=$1
826+ shift 1
842827
843- echo " <item id='$item_id ' />"
844- done
845-
846- echo " </items>"
847- } \
848- | stanza_pubsub \
849- | send_stanza_iq get
828+ eof | stanza item " id=$item_id "
829+ done \
830+ | stanza items " node=$node " \
831+ | stanza_pubsub \
832+ | send_stanza_iq get
850833
851834}
852835
@@ -861,8 +844,9 @@ get_vcard() {
861844 return 0
862845 fi
863846
864- echo " <vCard xmlns='vcard-temp'/>" \
865- | send_stanza_iq get $jid
847+ eof \
848+ | stanza vCard " xmlns=vcard-temp" \
849+ | send_stanza_iq get $jid
866850}
867851
868852# Set vCard info
0 commit comments