src/main/java/de/unixwork/im/Xmpp.java

changeset 1
42d0d099492b
parent 0
f3095cda599e
child 2
94c6a715fa44
--- a/src/main/java/de/unixwork/im/Xmpp.java	Wed Dec 25 21:49:48 2024 +0100
+++ b/src/main/java/de/unixwork/im/Xmpp.java	Thu Dec 26 12:29:05 2024 +0100
@@ -8,6 +8,16 @@
 import java.util.concurrent.LinkedBlockingQueue;
 import java.util.logging.Level;
 import java.util.logging.Logger;
+import net.java.otr4j.OtrException;
+import net.java.otr4j.OtrPolicy;
+import net.java.otr4j.OtrPolicyImpl;
+import net.java.otr4j.OtrSessionManager;
+import net.java.otr4j.OtrSessionManagerImpl;
+import net.java.otr4j.session.InstanceTag;
+import net.java.otr4j.session.Session;
+import net.java.otr4j.session.SessionID;
+import net.java.otr4j.session.SessionImpl;
+import net.java.otr4j.session.TLV;
 import org.jivesoftware.smack.ConnectionConfiguration;
 import org.jivesoftware.smack.SmackException;
 import org.jivesoftware.smack.XMPPException;
@@ -25,11 +35,40 @@
     
     private XMPPTCPConnection connection = null;
     
+    private final OTR otr;
+    
+    private final OtrSessionManager otrSM;
+    
     // BlockingQueue for event-driven communication
     private final BlockingQueue<XmppEvent> eventQueue = new LinkedBlockingQueue<>();
     
     public Xmpp(XMPPTCPConnectionConfiguration xmppConfig) {
         config = xmppConfig;
+        otr = new OTR(this);
+        otrSM = new OtrSessionManagerImpl(otr);
+        
+    }
+    
+    public OTR getOTR() {
+        return otr;
+    }
+    
+    public OtrSessionManager getOtrSM() {
+        return otrSM;
+    }
+    
+    public void startOTR(String xid) {
+        String account = config.getUsername() + "@" + config.getHostString() + "/IM5";
+        SessionID sid = new SessionID(account, xid, "xmpp");
+        
+        Session session = new SessionImpl(sid, otr);
+        String[] outgoingMessage;
+        try {
+            session.startSession();
+        } catch (OtrException ex) {
+            Logger.getLogger(Xmpp.class.getName()).log(Level.SEVERE, null, ex);
+        }
+        
     }
     
     // Method to send a message (this will be called from another thread)
@@ -42,12 +81,15 @@
         }
     }
     
+    public void send(String to, String message) {
+        sendMessage(to, message, false);
+    }
+    
     private void connect() throws SmackException, IOException, XMPPException, InterruptedException {
         connection = new XMPPTCPConnection(config);
         connection.setUseStreamManagement(false);
         connection.connect();
         connection.login();
-        
     }
     
     public List<RosterEntry> getRosterItems() throws SmackException.NotLoggedInException, SmackException.NotConnectedException, InterruptedException {

mercurial