|
From: <to...@us...> - 2008-02-05 04:16:16
|
Revision: 106
http://xoperator.svn.sourceforge.net/xoperator/?rev=106&view=rev
Author: tomatop
Date: 2008-02-04 20:16:19 -0800 (Mon, 04 Feb 2008)
Log Message:
-----------
fix auth mechanism
Modified Paths:
--------------
trunk/xOperator/src/net/sf/xoperator/xmpp/XMPPManager.java
trunk/xOperator/src/net/sf/xoperator/xmpp/XmppClient.java
Modified: trunk/xOperator/src/net/sf/xoperator/xmpp/XMPPManager.java
===================================================================
--- trunk/xOperator/src/net/sf/xoperator/xmpp/XMPPManager.java 2008-01-18 22:27:33 UTC (rev 105)
+++ trunk/xOperator/src/net/sf/xoperator/xmpp/XMPPManager.java 2008-02-05 04:16:19 UTC (rev 106)
@@ -18,6 +18,7 @@
import org.jivesoftware.smack.Chat;
import org.jivesoftware.smack.ChatManagerListener;
import org.jivesoftware.smack.MessageListener;
+import org.jivesoftware.smack.Roster;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.Message;
import org.openbbs.blackboard.filter.KindOfFilter;
@@ -31,7 +32,7 @@
*
*/
public class XMPPManager extends ConfigurationAwareKnowledgeSource {
-
+
private SPARQLResult.IQPacketListener mainClientResultListener;
private Log log = LogFactory.getLog(XMPPManager.class);
@@ -58,8 +59,27 @@
logIntoProxy(info);
}
+ // makes sure the proxy and the main account know each other
+
+ if (mainClient != null && proxyClient != null) {
+ // check if main knows proxy
+ introduce(mainClient, proxyClient);
+
+
+ }
+
}
+ /**
+ * introduces client1 to client2
+ *
+ * @return true if previusly unknown
+ */
+ private void introduce(XmppClient client1, XmppClient client2) {
+ client1.allowRosterAccess(client2.accountInfo.getUsername(), "My Agent");
+ client2.allowRosterAccess(client1.accountInfo.getUsername(), "My Master");
+ }
+
private void logIntoMain(AccountInfo info) {
if (this.mainClient != null) {
this.mainClient.logoff();
@@ -71,14 +91,11 @@
this.log.error(e);
throw new RuntimeException(e);
}
- if(info.isStandalone()){
- registerChatListeners(mainClient);
- }
-
- if(info.isP2penabled()){
+
+ if (info.isP2penabled()) {
registerInterAgentCommunicationListener(mainClient);
}
-
+
}
private void logIntoProxy(AccountInfo info) {
@@ -90,10 +107,8 @@
try {
this.proxyClient.login();
} catch (XMPPException e) {
- this.log
- .info(
- "No valid inforamtion to log into proxy account, trying to create one",
- e);
+ this.log.info("No valid inforamtion "
+ + "to log into proxy account, trying to create one", e);
try {
this.proxyClient
.createAccount(this.mainClient.getAccountInfo());
@@ -117,7 +132,7 @@
sendPendingMessagesToUser(context);
- //forwardQueriesAndResults(context);
+ // forwardQueriesAndResults(context);
}
@@ -152,10 +167,11 @@
query.setTo(jid);
mainClient.sendQuery(query);
mainClientResultListener.registerQuery(query, context);
-
+
}
query.setHtl(0);
- context.blackboard().write(new StringMessage("Passed the query to stores: ")+agents);
+ context.blackboard().write(
+ new StringMessage("Passed the query to stores: ") + agents);
}
if (query != null && query.getOutputType().equals(SPARQLQuery.P2P)) {
@@ -176,14 +192,8 @@
new KindOfFilter(Chat.class));
if (chat != null) {
- Set mess = context.blackboard().readAll(
+ Set messages = context.blackboard().readAll(
new KindOfFilter(MessageToUser.class));
- List messages = new ArrayList<MessageToUser>();
-
- for (Object object : mess) {
- messages.add(object);
- }
-
Set sendMsgNote = context.blackboard().readAll(
new KindOfFilter(MessageSend.class));
if (messages.size() > sendMsgNote.size()) {
@@ -249,7 +259,9 @@
private void registerInterAgentCommunicationListener(XmppClient client) {
this.mainClientResultListener = new SPARQLResult.IQPacketListener();
- client.setSPARQLEnabled(true, new SPARQLQuery.IQPaketListener(control), new SPARQLQuery.IQPacketFilter(), mainClientResultListener, new SPARQLResult.IQPacketFilter());
+ client.setSPARQLEnabled(true, new SPARQLQuery.IQPaketListener(control),
+ new SPARQLQuery.IQPacketFilter(), mainClientResultListener,
+ new SPARQLResult.IQPacketFilter());
}
Modified: trunk/xOperator/src/net/sf/xoperator/xmpp/XmppClient.java
===================================================================
--- trunk/xOperator/src/net/sf/xoperator/xmpp/XmppClient.java 2008-01-18 22:27:33 UTC (rev 105)
+++ trunk/xOperator/src/net/sf/xoperator/xmpp/XmppClient.java 2008-02-05 04:16:19 UTC (rev 106)
@@ -45,6 +45,7 @@
Constants.SPARQL_XMPP_SPEC_URL, new SPARQLQuery.Provider());
ProviderManager.getInstance().addIQProvider("sparql-result",
Constants.SPARQL_XMPP_SPEC_URL, new SPARQLResult.Provider());
+ Roster.setDefaultSubscriptionMode(Roster.SubscriptionMode.manual);
}
private XMPPConnection conn = null;
@@ -55,20 +56,14 @@
private AgentListener rosterListener;
+
+
AccountInfo accountInfo;
private static final Logger log = Logger.getLogger(XmppClient.class);
- public XmppClient(String username, String password, String server,
- String resource, int port) {
- super();
- this.accountInfo = new AccountInfo();
- this.accountInfo.setUsername(username);
- this.accountInfo.setPassword(password);
- this.accountInfo.setServer(server);
- this.accountInfo.setResource(resource);
- }
+
public XmppClient(AccountInfo info) {
this.accountInfo = info;
}
@@ -97,9 +92,23 @@
}
});
}
+ synchronized (this) {
+ if(this.accountInfo.isStandalone()){
+ Roster.setDefaultSubscriptionMode(Roster.SubscriptionMode.accept_all);
+ }
+ this.conn.login(this.accountInfo.getUsername().split("@")[0],
+ this.accountInfo.getPassword(), this.accountInfo.getResource());
+
+ if(this.accountInfo.isStandalone()){
+ Roster.setDefaultSubscriptionMode(Roster.SubscriptionMode.manual);
+ }
+
+ }
- this.conn.login(this.accountInfo.getUsername().split("@")[0],
- this.accountInfo.getPassword(), this.accountInfo.getResource());
+
+
+
+
this.sdisc = ServiceDiscoveryManager.getInstanceFor(this.conn);
return this;
@@ -339,5 +348,22 @@
}
}
+
+
+ public void allowRosterAccess(String jid, String nick){
+ try {
+ if(!getRoster().contains(jid)){
+ getRoster().createEntry(jid, nick, null);
+ }
+ Presence pres = new Presence(Presence.Type.subscribed);
+ pres.setTo(jid);
+ conn.sendPacket(pres);
+ } catch (XMPPException e) {
+ log.error("Error adding to Roster: " ,e);
+ }
+
+ }
+
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|