55import java .util .concurrent .BlockingQueue ;
66import org .apache .log4j .Logger ;
77import org .buddycloud .channelserver .channel .ChannelManager ;
8+ import org .buddycloud .channelserver .channel .node .configuration .field .AccessModel ;
9+ import org .buddycloud .channelserver .db .exception .NodeStoreException ;
810import org .buddycloud .channelserver .packetprocessor .PacketProcessor ;
911import org .buddycloud .channelserver .packetprocessor .iq .namespace .pubsub .JabberPubsub ;
1012import org .dom4j .Element ;
1517import org .xmpp .packet .JID ;
1618import org .xmpp .packet .Packet ;
1719import org .xmpp .packet .PacketError ;
20+ import org .xmpp .packet .PacketError .Condition ;
1821
1922public class DiscoInfoGet implements PacketProcessor <IQ > {
2023
@@ -27,46 +30,53 @@ public class DiscoInfoGet implements PacketProcessor<IQ> {
2730 private IQ requestIq ;
2831 private Element query ;
2932 private Map <String , String > conf ;
30-
31- public DiscoInfoGet (BlockingQueue <Packet > outQueue , ChannelManager channelManager ) {
33+
34+ public DiscoInfoGet (BlockingQueue <Packet > outQueue ,
35+ ChannelManager channelManager ) {
3236 this .outQueue = outQueue ;
3337 this .channelManager = channelManager ;
3438 }
3539
3640 @ Override
3741 public void process (IQ reqIQ ) throws Exception {
3842
39- requestIq = reqIQ ;
40- result = IQ .createResultIQ (reqIQ );
41- Element elm = reqIQ .getChildElement ();
42- node = elm .attributeValue ("node" );
43- query = result .setChildElement (ELEMENT_NAME ,
43+ requestIq = reqIQ ;
44+ result = IQ .createResultIQ (reqIQ );
45+ Element elm = reqIQ .getChildElement ();
46+ node = elm .attributeValue ("node" );
47+ query = result .setChildElement (ELEMENT_NAME ,
4448 JabberDiscoInfo .NAMESPACE_URI );
45- if (false == channelManager .isLocalJID (requestIq .getFrom ())) {
46- result .getElement ().addAttribute ("remote-server-discover" , "false" );
47- }
49+ if (false == channelManager .isLocalJID (requestIq .getFrom ())) {
50+ result .getElement ().addAttribute ("remote-server-discover" , "false" );
51+ }
4852 if ((node == null ) || (true == node .equals ("" ))) {
4953 sendServerDiscoInfo ();
5054 return ;
5155 }
5256 if (false == channelManager .isLocalNode (node )
53- && (false == channelManager .isCachedNode (node ))) {
57+ && (false == channelManager .isCachedNode (node ))) {
5458 logger .info ("Node " + node + " is remote and not cached so "
55- + "we're going off to get disco#info" );
59+ + "we're going off to get disco#info" );
5660 makeRemoteRequest ();
57- return ;
61+ return ;
5862 }
5963 conf = channelManager .getNodeConf (node );
6064 if (conf .isEmpty ()) {
6165 nodeDoesntExistResponse ();
6266 return ;
6367 }
64- sendNodeConfigurationInformation ();
68+ try {
69+ sendNodeConfigurationInformation ();
70+ } catch (NodeStoreException e ) {
71+ logger .error (e );
72+ setErrorResponse (PacketError .Type .wait ,
73+ PacketError .Condition .internal_server_error );
74+ }
6575 }
6676
67- private void sendNodeConfigurationInformation () throws InterruptedException {
68-
69- TreeMap <String , String > sorted_conf = new TreeMap <String , String >();
77+ private void sendNodeConfigurationInformation () throws Exception {
78+
79+ TreeMap <String , String > configuration = new TreeMap <String , String >();
7080
7181 DataForm x = new DataForm (DataForm .Type .result );
7282
@@ -75,25 +85,34 @@ private void sendNodeConfigurationInformation() throws InterruptedException {
7585 formType .setVariable ("FORM_TYPE" );
7686 formType .addValue ("http://jabber.org/protocol/pubsub#meta-data" );
7787
78- sorted_conf .putAll (conf );
79- for (String key : sorted_conf .keySet ()) {
80- x .addField (key , null , null ).addValue (sorted_conf .get (key ));
88+ String value ;
89+
90+ configuration .putAll (conf );
91+ for (String key : configuration .keySet ()) {
92+ value = configuration .get (key );
93+ if ((true == key .equals (AccessModel .FIELD_NAME ))
94+ && (value .equals (AccessModel .local .toString ()))
95+ && (false == channelManager .isLocalJID (requestIq .getFrom ()))) {
96+ value = AccessModel .authorize .toString ();
97+ }
98+ x .addField (key , null , null ).addValue (value );
8199 }
82-
100+
83101 query .addAttribute ("node" , node );
84102 query .addElement ("identity" ).addAttribute ("category" , "pubsub" )
85103 .addAttribute ("type" , "leaf" );
86104 query .addElement ("feature" ).addAttribute ("var" ,
87105 "http://jabber.org/protocol/pubsub" );
88106
89107 query .add (x .getElement ());
90-
91- query .addElement ("feature" ).addAttribute ("var" , JabberPubsub .NAMESPACE_URI );
108+
109+ query .addElement ("feature" ).addAttribute ("var" ,
110+ JabberPubsub .NAMESPACE_URI );
92111 Element identity = query .addElement ("identity" );
93112 identity .addAttribute ("category" , "pubsub" );
94- identity .addAttribute ("type" , "leaf" );
95-
96- logger .trace ("Returning DISCO info for node: " + node );
113+ identity .addAttribute ("type" , "leaf" );
114+
115+ logger .trace ("Returning DISCO info for node: " + node );
97116 outQueue .put (result );
98117 }
99118
@@ -106,41 +125,41 @@ private void nodeDoesntExistResponse() throws InterruptedException {
106125 * <item-not-found xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
107126 * </error> </iq>
108127 */
128+ setErrorResponse (PacketError .Type .cancel ,
129+ PacketError .Condition .item_not_found );
130+ }
109131
132+ private void setErrorResponse (PacketError .Type type , Condition condition )
133+ throws InterruptedException {
110134 result .setChildElement (result .getChildElement ().createCopy ());
111135 result .setType (Type .error );
112- PacketError pe = new PacketError (
113- org .xmpp .packet .PacketError .Condition .item_not_found ,
114- org .xmpp .packet .PacketError .Type .cancel );
136+ PacketError pe = new PacketError (condition , type );
115137 result .setError (pe );
116138 outQueue .put (result );
117139 }
118140
119- private void sendServerDiscoInfo ()
120- throws InterruptedException {
141+ private void sendServerDiscoInfo () throws InterruptedException {
121142 query .addElement ("identity" ).addAttribute ("category" , "pubsub" )
122143 .addAttribute ("type" , "channels" );
123144
124145 query .addElement ("identity" ).addAttribute ("category" , "pubsub" )
125146 .addAttribute ("type" , "inbox" );
126147
127- query .addElement ("feature" ).addAttribute ("var" ,
128- "jabber:iq:register" );
148+ query .addElement ("feature" ).addAttribute ("var" , "jabber:iq:register" );
129149
130150 query .addElement ("feature" ).addAttribute ("var" ,
131151 "http://jabber.org/protocol/disco#info" );
132-
152+
133153 query .addElement ("feature" ).addAttribute ("var" ,
134154 "http://jabber.org/protocol/disco#items" );
135-
136- query .addElement ("feature" ).addAttribute ("var" ,
137- "jabber:iq:search" );
155+
156+ query .addElement ("feature" ).addAttribute ("var" , "jabber:iq:search" );
138157
139158 outQueue .put (result );
140159 }
141160
142161 private void makeRemoteRequest () throws InterruptedException {
143162 requestIq .setTo (new JID (node .split ("/" )[2 ]).getDomain ());
144- outQueue .put (requestIq );
163+ outQueue .put (requestIq );
145164 }
146165}
0 commit comments