[Zerofile-svn] SF.net SVN: zerofile: [59] trunk/src
Status: Pre-Alpha
Brought to you by:
karl-bengtsson
|
From: <kar...@us...> - 2007-11-29 15:53:41
|
Revision: 59
http://zerofile.svn.sourceforge.net/zerofile/?rev=59&view=rev
Author: karl-bengtsson
Date: 2007-11-29 07:37:32 -0800 (Thu, 29 Nov 2007)
Log Message:
-----------
Helt kukad release, som f?\195?\182rmodligen inte alls fungerar. Men det ?\195?\164r ny kod iaf.
Modified Paths:
--------------
trunk/src/XMPPDOMParser.java
trunk/src/XMPPLinkLocalChatSession.java
trunk/src/XMPPLinkLocalHost.java
trunk/src/XMPPSessionListener.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-27 21:09:02 UTC (rev 58)
+++ trunk/src/XMPPDOMParser.java 2007-11-29 15:37:32 UTC (rev 59)
@@ -16,8 +16,8 @@
catch (Exception e)
{
System.out.println(e);
+ return null;
}
- return null;
}
public static String getMessageBodyFromMessageStanza(String stanza)
@@ -32,7 +32,37 @@
catch (Exception e)
{
System.out.println(e);
+ return null;
}
- return null;
}
+
+ public static String getToAttributeFromMessageStanza(String stanza)
+ {
+ try
+ {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ Document d = factory.newDocumentBuilder().parse(new InputSource(new StringReader(stanza)));
+ return d.getAttributes().getNamedItem("to").toString();
+ }
+ catch (Exception e)
+ {
+ System.out.println(e);
+ return null;
+ }
+ }
+
+ public static String getFromAttributeFromMessageStanza(String stanza)
+ {
+ try
+ {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ Document d = factory.newDocumentBuilder().parse(new InputSource(new StringReader(stanza)));
+ return d.getAttributes().getNamedItem("from").toString();
+ }
+ catch (Exception e)
+ {
+ System.out.println(e);
+ return null;
+ }
+ }
}
Modified: trunk/src/XMPPLinkLocalChatSession.java
===================================================================
--- trunk/src/XMPPLinkLocalChatSession.java 2007-11-27 21:09:02 UTC (rev 58)
+++ trunk/src/XMPPLinkLocalChatSession.java 2007-11-29 15:37:32 UTC (rev 59)
@@ -13,6 +13,7 @@
private Reader _fromRemoteHost;
private PrintWriter _toRemoteHost;
private ZeroFileChatWindow _chatWindow;
+ private XMPPLinkLocalHost _chatPartner;
private Thread _remoteHostReadingThread = new Thread() {
public void run() {
@@ -49,6 +50,7 @@
public XMPPLinkLocalChatSession(XMPPLinkLocalHost hostToChatWith)
{
+ _chatPartner = hostToChatWith;
_chatWindow = new ZeroFileChatWindow(this);
try
{
@@ -64,19 +66,26 @@
}
}
+ public XMPPLinkLocalHost getChatPartner()
+ {
+ return _chatPartner;
+ }
+
private void RecievedStanza(String stanza)
{
if (stanza.contains("<?xml"))
// Stanza is a handshake
{
_recievedHandshake = true;
+ System.out.println(stanza);
if (!_sentHandshake)
sendHandshake();
}
else if (stanza.contains("</stream:stream>"))
// Stanza is a hangup message
{
- _chatWindow.printText("Opposite party has left the chat");
+ if (_chatWindow != null)
+ _chatWindow.printText("Opposite party has left the chat");
disconnect();
}
else
@@ -95,18 +104,36 @@
}
if (stanzaType.equals("message"))
{
- RecievedMessage(XMPPDOMParser.getMessageBodyFromMessageStanza(stanza));
- }
+ String msg = XMPPDOMParser.getMessageBodyFromMessageStanza(stanza);
+ String to = XMPPDOMParser.getToAttributeFromMessageStanza(stanza);
+ String from = XMPPDOMParser.getFromAttributeFromMessageStanza(stanza);
+ RecievedMessage(msg,to,from);
+ System.out.println(stanza);
+ }
else
- System.out.println(stanzaType + " - not yet handled stanza type.");
+ System.out.println(stanza);
+ //System.out.println(stanzaType + " - not yet handled stanza type.");
}
}
}
- private void RecievedMessage(String mess)
+ private void RecievedMessage(String mess,String to,String from)
{
+ 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(mess);
}
@@ -127,6 +154,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);
+ _toRemoteHost.flush();
_toRemoteHost.print("<message><body>"+m+"</body></message>");
_toRemoteHost.flush();
}
Modified: trunk/src/XMPPLinkLocalHost.java
===================================================================
--- trunk/src/XMPPLinkLocalHost.java 2007-11-27 21:09:02 UTC (rev 58)
+++ trunk/src/XMPPLinkLocalHost.java 2007-11-29 15:37:32 UTC (rev 59)
@@ -44,16 +44,19 @@
}
public String toString()
- {
- if (_nickName != null)
+ {
+ return _firstName;
+ /*if (_nickName != null)
return _nickName;
else
if (_firstName != null && _lastName != null)
return _firstName + " " + _lastName;
else
return _serviceName;
+ */
}
+ // TODO - Fungerar inte alltid
public void updateData()
{
try
@@ -79,13 +82,18 @@
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();
}
});
}
catch (Exception e)
{
- System.out.println("Error: " + e.getStackTrace().toString());
+ System.out.println("Error: " + e);
}
}
Modified: trunk/src/XMPPSessionListener.java
===================================================================
--- trunk/src/XMPPSessionListener.java 2007-11-27 21:09:02 UTC (rev 58)
+++ trunk/src/XMPPSessionListener.java 2007-11-29 15:37:32 UTC (rev 59)
@@ -12,7 +12,6 @@
while(true)
{
Socket connection = _listeningSock.accept();
- //new ZeroFileChatWindow(connection);
new XMPPLinkLocalChatSession(connection);
}
}
Modified: trunk/src/ZeroFile.java
===================================================================
--- trunk/src/ZeroFile.java 2007-11-27 21:09:02 UTC (rev 58)
+++ trunk/src/ZeroFile.java 2007-11-29 15:37:32 UTC (rev 59)
@@ -25,18 +25,20 @@
}
}
- public static String getServiceName()
+ public static String getSuggestedServiceName()
{
- String serviceName = "serviceName";
+ String userName = System.getProperty("user.name");
+ String hostName;
try
{
InetAddress localMachine = InetAddress.getLocalHost();
- serviceName = localMachine.getHostName();
+ hostName = localMachine.getHostName().split("\\.")[0];
+ return userName + "@" + hostName;
}
catch (Exception e)
{
System.out.println(e);
+ return null;
}
- return serviceName;
}
}
Modified: trunk/src/ZeroFileChatWindow.java
===================================================================
--- trunk/src/ZeroFileChatWindow.java 2007-11-27 21:09:02 UTC (rev 58)
+++ trunk/src/ZeroFileChatWindow.java 2007-11-29 15:37:32 UTC (rev 59)
@@ -19,6 +19,7 @@
{
this.ZeroFileChatWindowInit();
_session = sess;
+ _chatWindowFrame.setTitle(_session.getChatPartner().toString());
}
public void setWindowTitle(String t)
Modified: trunk/src/ZeroFileMainWindow.java
===================================================================
--- trunk/src/ZeroFileMainWindow.java 2007-11-27 21:09:02 UTC (rev 58)
+++ trunk/src/ZeroFileMainWindow.java 2007-11-29 15:37:32 UTC (rev 59)
@@ -29,7 +29,7 @@
static void addHost(XMPPLinkLocalHost h)
{
- h.updateData();
+ //h.updateData();
_contactListModel.addElement(h);
}
Modified: trunk/src/ZeroconfRegistration.java
===================================================================
--- trunk/src/ZeroconfRegistration.java 2007-11-27 21:09:02 UTC (rev 58)
+++ trunk/src/ZeroconfRegistration.java 2007-11-29 15:37:32 UTC (rev 59)
@@ -14,7 +14,8 @@
static void registerService(String status,int port)
throws DNSSDException, InterruptedException
{
- _r = DNSSD.register(null, "_presence._tcp", port, 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)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|