[Zerofile-svn] SF.net SVN: zerofile: [60] trunk/src
Status: Pre-Alpha
Brought to you by:
karl-bengtsson
|
From: <kar...@us...> - 2007-11-29 23:20:30
|
Revision: 60
http://zerofile.svn.sourceforge.net/zerofile/?rev=60&view=rev
Author: karl-bengtsson
Date: 2007-11-29 15:20:21 -0800 (Thu, 29 Nov 2007)
Log Message:
-----------
*) UpdateData() on XMPPLinkLocalHost is now blocking, meaning that most of the problems with the main contact list not being properly updated due to synchronization issues should now be resolved.
*) Code has been added to look through the contact list for possible hosts that we are communicating with when a session is opened on a socket. This implementation and the corresponding required changes in the registration code means that only one instance of the program will operate properly on a machine at any given time.
*) This also means that we now have a proper status bar title set on sessions originated by someone else as well.
*) The chat window messages have been improved, with indication of who sent what message, you or your chat partner.
Modified Paths:
--------------
trunk/src/XMPPDOMParser.java
trunk/src/XMPPLinkLocalChatSession.java
trunk/src/XMPPLinkLocalHost.java
trunk/src/ZeroFile.java
trunk/src/ZeroFileChatWindow.java
trunk/src/ZeroFileMainWindow.java
trunk/src/ZeroconfRegistration.java
Modified: trunk/src/XMPPDOMParser.java
===================================================================
--- trunk/src/XMPPDOMParser.java 2007-11-29 15:37:32 UTC (rev 59)
+++ trunk/src/XMPPDOMParser.java 2007-11-29 23:20:21 UTC (rev 60)
@@ -15,7 +15,6 @@
}
catch (Exception e)
{
- System.out.println(e);
return null;
}
}
@@ -31,7 +30,6 @@
}
catch (Exception e)
{
- System.out.println(e);
return null;
}
}
@@ -46,7 +44,6 @@
}
catch (Exception e)
{
- System.out.println(e);
return null;
}
}
@@ -61,7 +58,6 @@
}
catch (Exception e)
{
- System.out.println(e);
return null;
}
}
Modified: trunk/src/XMPPLinkLocalChatSession.java
===================================================================
--- trunk/src/XMPPLinkLocalChatSession.java 2007-11-29 15:37:32 UTC (rev 59)
+++ trunk/src/XMPPLinkLocalChatSession.java 2007-11-29 23:20:21 UTC (rev 60)
@@ -77,7 +77,6 @@
// Stanza is a handshake
{
_recievedHandshake = true;
- System.out.println(stanza);
if (!_sentHandshake)
sendHandshake();
}
@@ -93,7 +92,19 @@
{
if (_sentHandshake && _recievedHandshake)
{
- String stanzaType = null;
+ String stanzaType = null;
+ if (_chatPartner == null)
+ {
+ if (XMPPDOMParser.getFromAttributeFromMessageStanza(stanza) != null && !XMPPDOMParser.getFromAttributeFromMessageStanza(stanza).equals(""))
+ {
+ _chatPartner = new XMPPLinkLocalHost(XMPPDOMParser.getFromAttributeFromMessageStanza(stanza));
+ }
+ else
+ {
+ _chatPartner = ZeroFileMainWindow.getHostFromContactList(_s.getInetAddress());
+ }
+ _chatPartner.updateData();
+ }
try
{
stanzaType = XMPPDOMParser.getRootTagName(stanza);
@@ -104,36 +115,21 @@
}
if (stanzaType.equals("message"))
{
- String msg = XMPPDOMParser.getMessageBodyFromMessageStanza(stanza);
- String to = XMPPDOMParser.getToAttributeFromMessageStanza(stanza);
- String from = XMPPDOMParser.getFromAttributeFromMessageStanza(stanza);
- RecievedMessage(msg,to,from);
- System.out.println(stanza);
+ RecievedMessage(XMPPDOMParser.getMessageBodyFromMessageStanza(stanza));
}
else
System.out.println(stanza);
- //System.out.println(stanzaType + " - not yet handled stanza type.");
}
}
}
- private void RecievedMessage(String mess,String to,String from)
+ private void RecievedMessage(String mess)
{
- if (_chatPartner == null)
- {
- _chatPartner = new XMPPLinkLocalHost(from);
- _chatPartner.updateData();
- }
if (_chatWindow == null)
{
- /* TODO - set _chatPartner to a new host and update this hosts data
- * based on a browse of the network using the stanzas to-attribute
- * as search parameter - this also means that we need the entire stanza at this
- * point, not just the payload.
- */
- System.out.println("nu skapas f\x9Anstret");
_chatWindow = new ZeroFileChatWindow(this);
}
+ _chatWindow.printText(_chatPartner.toString()+":");
_chatWindow.printText(mess);
}
@@ -154,11 +150,9 @@
public void sendMessage(String m)
{
- String test = "<iq type='get' from='"+ZeroconfRegistration.getMyServiceName()+"' to='" + _chatPartner.getServiceName() + "' id='items1'> <query xmlns='http://jabber.org/protocol/disco#items'/></iq>";
- _toRemoteHost.print(test);
+ String messageStanza = "<message to=\""+_chatPartner.getServiceName()+"\" from=\""+ZeroconfRegistration.getMyServiceName()+"\"><body>"+m+"</body></message>";
+ _toRemoteHost.print(messageStanza);
_toRemoteHost.flush();
- _toRemoteHost.print("<message><body>"+m+"</body></message>");
- _toRemoteHost.flush();
}
public void disconnect()
Modified: trunk/src/XMPPLinkLocalHost.java
===================================================================
--- trunk/src/XMPPLinkLocalHost.java 2007-11-29 15:37:32 UTC (rev 59)
+++ trunk/src/XMPPLinkLocalHost.java 2007-11-29 23:20:21 UTC (rev 60)
@@ -10,6 +10,7 @@
private String _firstName;
private String _lastName;
private String _host;
+ private Boolean _hasBeenResolved;
private int _port;
private static DNSSDService _r;
@@ -45,22 +46,23 @@
public String toString()
{
- return _firstName;
- /*if (_nickName != null)
+ if (_nickName != null && !_nickName.equals(""))
return _nickName;
else
- if (_firstName != null && _lastName != null)
- return _firstName + " " + _lastName;
+ if (_firstName != null && !_firstName.equals(""))
+ if (_lastName != null && !_lastName.equals(""))
+ return _firstName + " " + _lastName;
+ else
+ return _firstName;
else
return _serviceName;
- */
}
- // TODO - Fungerar inte alltid
public void updateData()
{
try
{
+ _hasBeenResolved = false;
_r = DNSSD.resolve(0, DNSSD.ALL_INTERFACES, _serviceName, "_presence._tcp", "local", new ResolveListener()
{
public void operationFailed(DNSSDService service,int errorCode)
@@ -71,6 +73,7 @@
public void serviceResolved(DNSSDService resolver, int flags, int ifIndex,
String fullName, String hostName, int port, TXTRecord txtRecord)
{
+ _hasBeenResolved = true;
_host = hostName;
_port = port;
if (txtRecord != null)
@@ -82,18 +85,25 @@
if (txtRecord.contains("nick"))
_nickName = txtRecord.getValueAsString("nick").toString();
}
- System.out.println("nu har vi resolvat");
- System.out.println("1st - " + _firstName);
- System.out.println("2nd - " +_lastName);
- System.out.println("nick - "+ _nickName);
- System.out.println("vid: " + _host + ":" + _port);
_r.stop();
}
});
+ while (!_hasBeenResolved)
+ {
+ try
+ {
+ Thread.sleep(50);
+ }
+ catch (InterruptedException e)
+ {
+ e.printStackTrace();
+ }
+ }
}
catch (Exception e)
{
System.out.println("Error: " + e);
+ System.out.println(_serviceName);
}
}
Modified: trunk/src/ZeroFile.java
===================================================================
--- trunk/src/ZeroFile.java 2007-11-29 15:37:32 UTC (rev 59)
+++ trunk/src/ZeroFile.java 2007-11-29 23:20:21 UTC (rev 60)
@@ -7,6 +7,10 @@
* @throws IOException
*/
public static void main(String[] args) throws IOException {
+ System.out.println(
+ new java.io.OutputStreamWriter(
+ new java.io.ByteArrayOutputStream()).getEncoding()
+ );
ZeroFileMainWindow.startMainWindow();
ZeroFileSettings.loadSettings();
try
Modified: trunk/src/ZeroFileChatWindow.java
===================================================================
--- trunk/src/ZeroFileChatWindow.java 2007-11-29 15:37:32 UTC (rev 59)
+++ trunk/src/ZeroFileChatWindow.java 2007-11-29 23:20:21 UTC (rev 60)
@@ -29,12 +29,13 @@
public void printText(String s)
{
- _chatTextArea.append("\n"+s);
+ _chatTextArea.append(s+"\n");
}
public void sendMessage(String str)
{
- printText(str);
+ printText("You:");
+ printText(str+"\n");
_session.sendMessage(str);
_entryTextField.setText("");
}
Modified: trunk/src/ZeroFileMainWindow.java
===================================================================
--- trunk/src/ZeroFileMainWindow.java 2007-11-29 15:37:32 UTC (rev 59)
+++ trunk/src/ZeroFileMainWindow.java 2007-11-29 23:20:21 UTC (rev 60)
@@ -1,5 +1,6 @@
import java.awt.*;
import java.awt.event.*;
+import java.net.*;
import javax.swing.*;
public class ZeroFileMainWindow
@@ -22,14 +23,37 @@
static boolean containsHost(XMPPLinkLocalHost h)
{
for (int i = 0; i<_contactListModel.size(); i++)
+ {
if (((XMPPLinkLocalHost)_contactListModel.getElementAt(i)).getServiceName().equals(h.getServiceName()))
return true;
+ }
return false;
}
+ static XMPPLinkLocalHost getHostFromContactList(InetAddress searchedAddress)
+ {
+ for (int i = 0; i<_contactListModel.size(); i++)
+ {
+ InetAddress iteratedAddress = null;
+ XMPPLinkLocalHost iteratedHost = (XMPPLinkLocalHost)_contactListModel.getElementAt(i);
+ try
+ {
+ iteratedAddress = InetAddress.getByName(iteratedHost.getHost());
+ }
+ catch (Exception e)
+ {
+ System.out.println(e);
+ }
+ if (searchedAddress.equals(iteratedAddress))
+ {
+ return (XMPPLinkLocalHost)_contactListModel.getElementAt(i);
+ }
+ }
+ return new XMPPLinkLocalHost(null);
+ }
+
static void addHost(XMPPLinkLocalHost h)
{
- //h.updateData();
_contactListModel.addElement(h);
}
Modified: trunk/src/ZeroconfRegistration.java
===================================================================
--- trunk/src/ZeroconfRegistration.java 2007-11-29 15:37:32 UTC (rev 59)
+++ trunk/src/ZeroconfRegistration.java 2007-11-29 23:20:21 UTC (rev 60)
@@ -10,12 +10,14 @@
private static TXTRecord _txtRecord = new TXTRecord();
private static DNSSDRegistration _r;
private static String _myServiceName;
+ private static Boolean _registrationStarted = false;
static void registerService(String status,int port)
throws DNSSDException, InterruptedException
{
-
- _r = DNSSD.register(ZeroFile.getSuggestedServiceName(), "_presence._tcp", port, new RegisterListener()
+ _registrationStarted = true;
+ _r = DNSSD.register(0,0,ZeroFile.getSuggestedServiceName(), "_presence._tcp","local",null,port,_txtRecord, new RegisterListener()
+ //_r = DNSSD.register(ZeroFile.getSuggestedServiceName(), "_presence._tcp",port, new RegisterListener()
{
public void serviceRegistered(DNSSDRegistration registration, int flags,
String serviceName, String regType, String domain)
@@ -36,13 +38,25 @@
public static String getMyServiceName()
{
- while (_myServiceName == null)
- try {
- Thread.sleep(50);
- } catch (InterruptedException e) {
- e.printStackTrace();
+ if (!_registrationStarted)
+ {
+ return null;
+ }
+ else
+ {
+ while (_myServiceName == null)
+ {
+ try
+ {
+ Thread.sleep(50);
+ }
+ catch (InterruptedException e)
+ {
+ e.printStackTrace();
+ }
}
return _myServiceName;
+ }
}
static void registerService(int port)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|