summaryrefslogtreecommitdiffstats
blob: 57f3154abe60a47a686eba72e16854a7a1a2e217 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "Swiften/LinkLocal/OutgoingLinkLocalSession.h"

#include <boost/bind.hpp>

#include "Swiften/Elements/ProtocolHeader.h"
#include "Swiften/Network/Connection.h"
#include "Swiften/StreamStack/StreamStack.h"
#include "Swiften/LinkLocal/DNSSDService.h"
#include "Swiften/StreamStack/ConnectionLayer.h"
#include "Swiften/StreamStack/XMPPLayer.h"
#include "Swiften/Elements/StreamFeatures.h"
#include "Swiften/Elements/IQ.h"
#include "Swiften/SASL/PLAINMessage.h"

namespace Swift {

OutgoingLinkLocalSession::OutgoingLinkLocalSession(
		const JID& localJID,
		const JID& remoteJID,
		const String& hostname,
		boost::shared_ptr<DNSSDService> resolver,
		PayloadParserFactoryCollection* payloadParserFactories, 
		PayloadSerializerCollection* payloadSerializers,
		ConnectionFactory* connectionFactory) :
			LinkLocalSession(
				localJID, 
				boost::shared_ptr<Connection>(), 
				payloadParserFactories, 
				payloadSerializers),
			resolving_(false),
			remoteJID_(remoteJID),
			hostname_(hostname),
			resolver_(resolver),
			connectionFactory_(connectionFactory) {
}

void OutgoingLinkLocalSession::start() {
	resolving_ = true;
	//resolver_->onHostnameResolved.connect(boost::bind(&OutgoingLinkLocalSession::handleHostnameResolved, this, _1, _2));
}

#if 0
void OutgoingLinkLocalSession::handleHostnameResolved(const String& hostname, const HostAddress&) {
	if (resolving_) {
		if (hostname == hostname_) {
			boost::shared_ptr<Connection> connection = connectionFactory_->createConnection();
			connection->onConnected.connect(boost::bind(&Session::handleConnected, shared_from_this()));
			connection->onDisconnected.connect(boost::bind(&Session::handleDisconnected, shared_from_this(), _1));
			connection_->connect(jid_.getDomain());
			resolving_ = false;
			boost::
		}
	}
}
#endif

void OutgoingLinkLocalSession::handleStreamStart(const ProtocolHeader&) {
	ProtocolHeader header;
	header.setFrom(getLocalJID());
	getXMPPLayer()->writeHeader(header);
	setInitialized();
}

void OutgoingLinkLocalSession::handleElement(boost::shared_ptr<Element> element) {
	if (isInitialized()) {
		boost::shared_ptr<Stanza> stanza = boost::dynamic_pointer_cast<Stanza>(element);
		if (stanza) {
			onStanzaReceived(stanza);
		}
	}
}


}