summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2010-03-30 09:39:45 (GMT)
committerKevin Smith <git@kismith.co.uk>2010-03-30 09:39:45 (GMT)
commit5fc2378d29ca59cf2d3bf0633912d5336fd43de0 (patch)
tree2879211bc03d5aa6cc2248f814b8b8a9c95883e4
parent2a61f9f00df213e92d7ca1df7e659accd6bd1620 (diff)
downloadswift-5fc2378d29ca59cf2d3bf0633912d5336fd43de0.zip
swift-5fc2378d29ca59cf2d3bf0633912d5336fd43de0.tar.bz2
Adding manual hosts to SendMessage
-rw-r--r--Swiften/Client/Client.cpp6
-rw-r--r--Swiften/Client/Client.h1
-rw-r--r--Swiften/Examples/SendMessage/SendMessage.cpp28
3 files changed, 27 insertions, 8 deletions
diff --git a/Swiften/Client/Client.cpp b/Swiften/Client/Client.cpp
index c704248..e23c317 100644
--- a/Swiften/Client/Client.cpp
+++ b/Swiften/Client/Client.cpp
@@ -35,8 +35,12 @@ bool Client::isAvailable() {
}
void Client::connect() {
+ connect(jid_.getDomain());
+}
+
+void Client::connect(const String& host) {
assert(!connector_);
- connector_ = boost::shared_ptr<Connector>(new Connector(jid_.getDomain(), &resolver_, connectionFactory_, timerFactory_));
+ connector_ = boost::shared_ptr<Connector>(new Connector(host, &resolver_, connectionFactory_, timerFactory_));
connector_->onConnectFinished.connect(boost::bind(&Client::handleConnectorFinished, this, _1));
connector_->setTimeoutMilliseconds(60*1000);
connector_->start();
diff --git a/Swiften/Client/Client.h b/Swiften/Client/Client.h
index 444c136..d5764df 100644
--- a/Swiften/Client/Client.h
+++ b/Swiften/Client/Client.h
@@ -33,6 +33,7 @@ namespace Swift {
void setCertificate(const String& certificate);
void connect();
+ void connect(const String& host);
void disconnect();
bool isAvailable();
diff --git a/Swiften/Examples/SendMessage/SendMessage.cpp b/Swiften/Examples/SendMessage/SendMessage.cpp
index b7625fb..c6d1291 100644
--- a/Swiften/Examples/SendMessage/SendMessage.cpp
+++ b/Swiften/Examples/SendMessage/SendMessage.cpp
@@ -16,7 +16,7 @@ SimpleEventLoop eventLoop;
Client* client = 0;
JID recipient;
std::string messageBody;
-int exitCode = 0;
+int exitCode = 2;
boost::bsignals::connection errorConnection;
@@ -25,6 +25,7 @@ void handleConnected() {
message->setBody(messageBody);
message->setTo(recipient);
client->sendMessage(message);
+ exitCode = 0;
errorConnection.disconnect();
client->disconnect();
eventLoop.stop();
@@ -37,19 +38,32 @@ void handleError(const ClientError&) {
}
int main(int argc, char* argv[]) {
- if (argc != 5) {
- std::cerr << "Usage: " << argv[0] << " <jid> <password> <recipient> <message>" << std::endl;
+ if (argc < 5 || argc > 6) {
+ std::cerr << "Usage: " << argv[0] << " <jid> [<connect_host>]<password> <recipient> <message>" << std::endl;
return -1;
}
- recipient = JID(argv[3]);
- messageBody = std::string(argv[4]);
+ int argi = 1;
+
+ String jid = argv[argi++];
+ String connectHost = "";
+ if (argc == 6) {
+ connectHost = argv[argi++];
+ }
+
+ client = new Swift::Client(JID(jid), String(argv[argi++]));
+
+ recipient = JID(argv[argi++]);
+ messageBody = std::string(argv[argi++]);
- client = new Swift::Client(JID(argv[1]), String(argv[2]));
ClientXMLTracer* tracer = new ClientXMLTracer(client);
client->onConnected.connect(&handleConnected);
errorConnection = client->onError.connect(&handleError);
- client->connect();
+ if (!connectHost.isEmpty()) {
+ client->connect(connectHost);
+ } else {
+ client->connect();
+ }
{
boost::shared_ptr<BoostTimer> timer(new BoostTimer(30000, &MainBoostIOServiceThread::getInstance().getIOService()));