summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2016-03-31 14:57:35 (GMT)
committerTobias Markmann <tm@ayena.de>2016-03-31 14:57:35 (GMT)
commitcfbdb43d2cadd40aa87338d41548e4bf89e146e6 (patch)
tree18d94153a302445196fc0c18586abf44a1ce4a38 /Swiften/Examples
parent1d545a4a7fb877f021508094b88c1f17b30d8b4e (diff)
downloadswift-cfbdb43d2cadd40aa87338d41548e4bf89e146e6.zip
swift-cfbdb43d2cadd40aa87338d41548e4bf89e146e6.tar.bz2
Convert tabs to 4 spaces for all source files
Removed trailing spaces and whitespace on empty lines in the process. Changed CheckTabs.py tool to disallow hard tabs in source files. Test-Information: Manually checked 30 random files that the conversion worked as expected. Change-Id: I874f99d617bd3d2bb55f02d58f22f58f9b094480
Diffstat (limited to 'Swiften/Examples')
-rw-r--r--Swiften/Examples/BenchTool/BenchTool.cpp58
-rw-r--r--Swiften/Examples/ConnectivityTest/ConnectivityTest.cpp114
-rw-r--r--Swiften/Examples/LinkLocalTool/main.cpp58
-rw-r--r--Swiften/Examples/MUCListAndJoin/MUCListAndJoin.cpp126
-rw-r--r--Swiften/Examples/NetworkTool/main.cpp106
-rw-r--r--Swiften/Examples/ParserTester/ParserTester.cpp72
-rw-r--r--Swiften/Examples/SendFile/ReceiveFile.cpp180
-rw-r--r--Swiften/Examples/SendFile/SendFile.cpp204
-rw-r--r--Swiften/Examples/SendMessage/SendMessage.cpp104
9 files changed, 511 insertions, 511 deletions
diff --git a/Swiften/Examples/BenchTool/BenchTool.cpp b/Swiften/Examples/BenchTool/BenchTool.cpp
index 49ecd92..f7337b9 100644
--- a/Swiften/Examples/BenchTool/BenchTool.cpp
+++ b/Swiften/Examples/BenchTool/BenchTool.cpp
@@ -28,40 +28,40 @@ static int numberOfInstances = 100;
static void handleConnected() {
- numberOfConnectedClients++;
- std::cout << "Connected " << numberOfConnectedClients << std::endl;
+ numberOfConnectedClients++;
+ std::cout << "Connected " << numberOfConnectedClients << std::endl;
}
int main(int, char**) {
- char* jid = getenv("SWIFT_BENCHTOOL_JID");
- if (!jid) {
- std::cerr << "Please set the SWIFT_BENCHTOOL_JID environment variable" << std::endl;
- return -1;
- }
- char* pass = getenv("SWIFT_BENCHTOOL_PASS");
- if (!pass) {
- std::cerr << "Please set the SWIFT_BENCHTOOL_PASS environment variable" << std::endl;
- return -1;
- }
+ char* jid = getenv("SWIFT_BENCHTOOL_JID");
+ if (!jid) {
+ std::cerr << "Please set the SWIFT_BENCHTOOL_JID environment variable" << std::endl;
+ return -1;
+ }
+ char* pass = getenv("SWIFT_BENCHTOOL_PASS");
+ if (!pass) {
+ std::cerr << "Please set the SWIFT_BENCHTOOL_PASS environment variable" << std::endl;
+ return -1;
+ }
- BlindCertificateTrustChecker trustChecker;
- std::vector<CoreClient*> clients;
- for (int i = 0; i < numberOfInstances; ++i) {
- CoreClient* client = new Swift::CoreClient(JID(jid), createSafeByteArray(std::string(pass)), &networkFactories);
- client->setCertificateTrustChecker(&trustChecker);
- client->onConnected.connect(&handleConnected);
- clients.push_back(client);
- }
-
- for (size_t i = 0; i < clients.size(); ++i) {
- clients[i]->connect();
- }
+ BlindCertificateTrustChecker trustChecker;
+ std::vector<CoreClient*> clients;
+ for (int i = 0; i < numberOfInstances; ++i) {
+ CoreClient* client = new Swift::CoreClient(JID(jid), createSafeByteArray(std::string(pass)), &networkFactories);
+ client->setCertificateTrustChecker(&trustChecker);
+ client->onConnected.connect(&handleConnected);
+ clients.push_back(client);
+ }
- eventLoop.run();
+ for (size_t i = 0; i < clients.size(); ++i) {
+ clients[i]->connect();
+ }
- for (size_t i = 0; i < clients.size(); ++i) {
- delete clients[i];
- }
+ eventLoop.run();
- return 0;
+ for (size_t i = 0; i < clients.size(); ++i) {
+ delete clients[i];
+ }
+
+ return 0;
}
diff --git a/Swiften/Examples/ConnectivityTest/ConnectivityTest.cpp b/Swiften/Examples/ConnectivityTest/ConnectivityTest.cpp
index 8d1da38..50f857c 100644
--- a/Swiften/Examples/ConnectivityTest/ConnectivityTest.cpp
+++ b/Swiften/Examples/ConnectivityTest/ConnectivityTest.cpp
@@ -31,72 +31,72 @@ static int exitCode = CANNOT_CONNECT;
static boost::bsignals::connection errorConnection;
static void handleServerDiscoInfoResponse(boost::shared_ptr<DiscoInfo> /*info*/, ErrorPayload::ref error) {
- if (!error) {
- errorConnection.disconnect();
- client->disconnect();
- eventLoop.stop();
- exitCode = OK;
- } else {
- errorConnection.disconnect();
- exitCode = DISCO_ERROR;
- }
+ if (!error) {
+ errorConnection.disconnect();
+ client->disconnect();
+ eventLoop.stop();
+ exitCode = OK;
+ } else {
+ errorConnection.disconnect();
+ exitCode = DISCO_ERROR;
+ }
}
static void handleConnected() {
- exitCode = NO_RESPONSE;
- GetDiscoInfoRequest::ref discoInfoRequest = GetDiscoInfoRequest::create(JID(), client->getIQRouter());
- discoInfoRequest->onResponse.connect(&handleServerDiscoInfoResponse);
- discoInfoRequest->send();
+ exitCode = NO_RESPONSE;
+ GetDiscoInfoRequest::ref discoInfoRequest = GetDiscoInfoRequest::create(JID(), client->getIQRouter());
+ discoInfoRequest->onResponse.connect(&handleServerDiscoInfoResponse);
+ discoInfoRequest->send();
}
static void handleDisconnected(const boost::optional<ClientError>&) {
- exitCode = CANNOT_AUTH;
- eventLoop.stop();
+ exitCode = CANNOT_AUTH;
+ eventLoop.stop();
}
int main(int argc, char* argv[]) {
- if (argc < 4 || argc > 5) {
- std::cerr << "Usage: " << argv[0] << " <jid> [<connect_host>] <password> <timeout_seconds>" << std::endl;
- return -1;
- }
-
- int argi = 1;
-
- std::string jid = argv[argi++];
- std::string connectHost = "";
- if (argc == 5) {
- connectHost = argv[argi++];
- }
-
- client = new Swift::Client(JID(jid), std::string(argv[argi++]), &networkFactories);
- char* timeoutChar = argv[argi++];
- int timeout = atoi(timeoutChar);
- timeout = (timeout ? timeout : 30) * 1000;
- ClientXMLTracer* tracer = new ClientXMLTracer(client);
- client->onConnected.connect(&handleConnected);
- errorConnection = client->onDisconnected.connect(&handleDisconnected);
- std::cout << "Connecting to JID " << jid << " with timeout " << timeout << "ms on host: "; ;
- if (!connectHost.empty()) {
- std::cout << connectHost << std::endl;
- ClientOptions options;
- options.manualHostname = connectHost;
- client->connect(options);
- } else {
- std::cout << " Default" << std::endl;
- client->connect();
- }
-
- {
- Timer::ref timer = networkFactories.getTimerFactory()->createTimer(timeout);
- timer->onTick.connect(boost::bind(&SimpleEventLoop::stop, &eventLoop));
- timer->start();
-
- eventLoop.run();
- }
-
- delete tracer;
- delete client;
- return exitCode;
+ if (argc < 4 || argc > 5) {
+ std::cerr << "Usage: " << argv[0] << " <jid> [<connect_host>] <password> <timeout_seconds>" << std::endl;
+ return -1;
+ }
+
+ int argi = 1;
+
+ std::string jid = argv[argi++];
+ std::string connectHost = "";
+ if (argc == 5) {
+ connectHost = argv[argi++];
+ }
+
+ client = new Swift::Client(JID(jid), std::string(argv[argi++]), &networkFactories);
+ char* timeoutChar = argv[argi++];
+ int timeout = atoi(timeoutChar);
+ timeout = (timeout ? timeout : 30) * 1000;
+ ClientXMLTracer* tracer = new ClientXMLTracer(client);
+ client->onConnected.connect(&handleConnected);
+ errorConnection = client->onDisconnected.connect(&handleDisconnected);
+ std::cout << "Connecting to JID " << jid << " with timeout " << timeout << "ms on host: "; ;
+ if (!connectHost.empty()) {
+ std::cout << connectHost << std::endl;
+ ClientOptions options;
+ options.manualHostname = connectHost;
+ client->connect(options);
+ } else {
+ std::cout << " Default" << std::endl;
+ client->connect();
+ }
+
+ {
+ Timer::ref timer = networkFactories.getTimerFactory()->createTimer(timeout);
+ timer->onTick.connect(boost::bind(&SimpleEventLoop::stop, &eventLoop));
+ timer->start();
+
+ eventLoop.run();
+ }
+
+ delete tracer;
+ delete client;
+ return exitCode;
}
diff --git a/Swiften/Examples/LinkLocalTool/main.cpp b/Swiften/Examples/LinkLocalTool/main.cpp
index dabce57..37804fb 100644
--- a/Swiften/Examples/LinkLocalTool/main.cpp
+++ b/Swiften/Examples/LinkLocalTool/main.cpp
@@ -17,33 +17,33 @@
using namespace Swift;
int main(int argc, char* argv[]) {
- if (argc < 2) {
- std::cerr << "Invalid parameters" << std::endl;
- return -1;
- }
-
- SimpleEventLoop eventLoop;
- PlatformDNSSDQuerierFactory factory(&eventLoop);
- boost::shared_ptr<DNSSDQuerier> querier = factory.createQuerier();
- querier->start();
-
- if (std::string(argv[1]) == "browse") {
- boost::shared_ptr<DNSSDBrowseQuery> browseQuery = querier->createBrowseQuery();
- browseQuery->startBrowsing();
- eventLoop.run();
- browseQuery->stopBrowsing();
- }
- else if (std::string(argv[1]) == "resolve-service") {
- if (argc < 5) {
- std::cerr << "Invalid parameters" << std::endl;
- return -1;
- }
- boost::shared_ptr<DNSSDResolveServiceQuery> resolveQuery = querier->createResolveServiceQuery(DNSSDServiceID(argv[2], argv[3], argv[4]));
- resolveQuery->start();
- eventLoop.run();
- std::cerr << "Done running" << std::endl;
- resolveQuery->stop();
- }
-
- querier->stop();
+ if (argc < 2) {
+ std::cerr << "Invalid parameters" << std::endl;
+ return -1;
+ }
+
+ SimpleEventLoop eventLoop;
+ PlatformDNSSDQuerierFactory factory(&eventLoop);
+ boost::shared_ptr<DNSSDQuerier> querier = factory.createQuerier();
+ querier->start();
+
+ if (std::string(argv[1]) == "browse") {
+ boost::shared_ptr<DNSSDBrowseQuery> browseQuery = querier->createBrowseQuery();
+ browseQuery->startBrowsing();
+ eventLoop.run();
+ browseQuery->stopBrowsing();
+ }
+ else if (std::string(argv[1]) == "resolve-service") {
+ if (argc < 5) {
+ std::cerr << "Invalid parameters" << std::endl;
+ return -1;
+ }
+ boost::shared_ptr<DNSSDResolveServiceQuery> resolveQuery = querier->createResolveServiceQuery(DNSSDServiceID(argv[2], argv[3], argv[4]));
+ resolveQuery->start();
+ eventLoop.run();
+ std::cerr << "Done running" << std::endl;
+ resolveQuery->stop();
+ }
+
+ querier->stop();
}
diff --git a/Swiften/Examples/MUCListAndJoin/MUCListAndJoin.cpp b/Swiften/Examples/MUCListAndJoin/MUCListAndJoin.cpp
index 216d16d..1aaebac 100644
--- a/Swiften/Examples/MUCListAndJoin/MUCListAndJoin.cpp
+++ b/Swiften/Examples/MUCListAndJoin/MUCListAndJoin.cpp
@@ -33,88 +33,88 @@ static JID mucJID;
static JID roomJID;
static void joinMUC() {
- cout << "Joining " << roomJID.toString() << endl;
+ cout << "Joining " << roomJID.toString() << endl;
- muc = client->getMUCManager()->createMUC(roomJID);
- muc->joinAs("SwiftExample");
+ muc = client->getMUCManager()->createMUC(roomJID);
+ muc->joinAs("SwiftExample");
}
static void handleRoomsItemsResponse(boost::shared_ptr<DiscoItems> items, ErrorPayload::ref error) {
- if (error) {
- cout << "Error fetching list of rooms." << endl;
- return;
- }
-
- int roomCount = 0;
- cout << "List of rooms at " << mucJID.toString() << endl;
- foreach (DiscoItems::Item item, items->getItems()) {
- roomCount++;
- cout << "\t" << roomCount << ". " << item.getJID().getNode() << " - " << item.getName() << std::endl;
- if (roomCount == 1) {
- roomJID = item.getJID();
- }
- }
- cout << endl;
- joinMUC();
+ if (error) {
+ cout << "Error fetching list of rooms." << endl;
+ return;
+ }
+
+ int roomCount = 0;
+ cout << "List of rooms at " << mucJID.toString() << endl;
+ foreach (DiscoItems::Item item, items->getItems()) {
+ roomCount++;
+ cout << "\t" << roomCount << ". " << item.getJID().getNode() << " - " << item.getName() << std::endl;
+ if (roomCount == 1) {
+ roomJID = item.getJID();
+ }
+ }
+ cout << endl;
+ joinMUC();
}
static void handleConnected() {
- cout << "Connected." << endl;
- // search for MUC rooms
+ cout << "Connected." << endl;
+ // search for MUC rooms
- GetDiscoItemsRequest::ref discoItemsRequest = GetDiscoItemsRequest::create(mucJID, client->getIQRouter());
- discoItemsRequest->onResponse.connect(&handleRoomsItemsResponse);
+ GetDiscoItemsRequest::ref discoItemsRequest = GetDiscoItemsRequest::create(mucJID, client->getIQRouter());
+ discoItemsRequest->onResponse.connect(&handleRoomsItemsResponse);
- cout << "Request list of rooms." << endl;
- discoItemsRequest->send();
+ cout << "Request list of rooms." << endl;
+ discoItemsRequest->send();
}
static void handleDisconnected(const boost::optional<ClientError>&) {
- cout << "Disconnected." << endl;
+ cout << "Disconnected." << endl;
}
static void handleIncomingMessage(boost::shared_ptr<Message> message) {
- if (message->getFrom().toBare() == roomJID) {
- cout << "[ " << roomJID << " ] " << message->getFrom().getResource() << ": " << message->getBody().get_value_or("") << endl;
- }
+ if (message->getFrom().toBare() == roomJID) {
+ cout << "[ " << roomJID << " ] " << message->getFrom().getResource() << ": " << message->getBody().get_value_or("") << endl;
+ }
}
/*
* Usage: ./MUCListAndJoin <jid> <password> <muc_domain>
*/
int main(int argc, char* argv[]) {
- int ret = 0;
-
- if (argc != 4) {
- cout << "Usage: ./" << argv[0] << " <jid> <password> <muc_domain>" << endl;
- ret = -1;
- }
- else {
- mucJID = JID(argv[3]);
- client = boost::make_shared<Client>(JID(argv[1]), string(argv[2]), &networkFactories);
- client->setAlwaysTrustCertificates();
-
- // Enable the following line for detailed XML logging
- // ClientXMLTracer* tracer = new ClientXMLTracer(client.get());
-
- client->onConnected.connect(&handleConnected);
- client->onDisconnected.connect(&handleDisconnected);
- client->onMessageReceived.connect(&handleIncomingMessage);
-
- cout << "Connecting..." << flush;
- client->connect();
- {
- Timer::ref timer = networkFactories.getTimerFactory()->createTimer(30000);
- timer->onTick.connect(boost::bind(&SimpleEventLoop::stop, &eventLoop));
-
- Timer::ref disconnectTimer = networkFactories.getTimerFactory()->createTimer(25000);
- disconnectTimer->onTick.connect(boost::bind(&Client::disconnect, client.get()));
-
- timer->start();
- disconnectTimer->start();
-
- eventLoop.run();
- }
- }
- return ret;
+ int ret = 0;
+
+ if (argc != 4) {
+ cout << "Usage: ./" << argv[0] << " <jid> <password> <muc_domain>" << endl;
+ ret = -1;
+ }
+ else {
+ mucJID = JID(argv[3]);
+ client = boost::make_shared<Client>(JID(argv[1]), string(argv[2]), &networkFactories);
+ client->setAlwaysTrustCertificates();
+
+ // Enable the following line for detailed XML logging
+ // ClientXMLTracer* tracer = new ClientXMLTracer(client.get());
+
+ client->onConnected.connect(&handleConnected);
+ client->onDisconnected.connect(&handleDisconnected);
+ client->onMessageReceived.connect(&handleIncomingMessage);
+
+ cout << "Connecting..." << flush;
+ client->connect();
+ {
+ Timer::ref timer = networkFactories.getTimerFactory()->createTimer(30000);
+ timer->onTick.connect(boost::bind(&SimpleEventLoop::stop, &eventLoop));
+
+ Timer::ref disconnectTimer = networkFactories.getTimerFactory()->createTimer(25000);
+ disconnectTimer->onTick.connect(boost::bind(&Client::disconnect, client.get()));
+
+ timer->start();
+ disconnectTimer->start();
+
+ eventLoop.run();
+ }
+ }
+ return ret;
}
diff --git a/Swiften/Examples/NetworkTool/main.cpp b/Swiften/Examples/NetworkTool/main.cpp
index c3f95e8..0cedfa7 100644
--- a/Swiften/Examples/NetworkTool/main.cpp
+++ b/Swiften/Examples/NetworkTool/main.cpp
@@ -20,67 +20,67 @@ using namespace Swift;
static SimpleEventLoop eventLoop;
static void handleGetPublicIPRequestResponse(const boost::optional<HostAddress>& result) {
- if (result) {
- std::cerr << "Result: " << result->toString() << std::endl;;
- }
- else {
- std::cerr << "No result" << std::endl;
- }
- eventLoop.stop();
+ if (result) {
+ std::cerr << "Result: " << result->toString() << std::endl;;
+ }
+ else {
+ std::cerr << "No result" << std::endl;
+ }
+ eventLoop.stop();
}
static void handleGetForwardPortRequestResponse(const boost::optional<NATPortMapping>& result) {
- if (result) {
- std::cerr << "Result: " << result->getPublicPort() << " -> " << result->getLocalPort() << std::endl;;
- }
- else {
- std::cerr << "No result" << std::endl;
- }
- eventLoop.stop();
+ if (result) {
+ std::cerr << "Result: " << result->getPublicPort() << " -> " << result->getLocalPort() << std::endl;;
+ }
+ else {
+ std::cerr << "No result" << std::endl;
+ }
+ eventLoop.stop();
}
static void handleRemovePortForwardingRequestResponse(const boost::optional<bool> result) {
- if (result && result.get()) {
- std::cerr << "Result: OK" << std::endl;
- }
- else {
- std::cerr << "Result: ERROR" << std::endl;
- }
- eventLoop.stop();
+ if (result && result.get()) {
+ std::cerr << "Result: OK" << std::endl;
+ }
+ else {
+ std::cerr << "Result: ERROR" << std::endl;
+ }
+ eventLoop.stop();
}
int main(int argc, char* argv[]) {
- if (argc < 2) {
- std::cerr << "Invalid parameters" << std::endl;
- return -1;
- }
+ if (argc < 2) {
+ std::cerr << "Invalid parameters" << std::endl;
+ return -1;
+ }
- PlatformNATTraversalWorker natTraverser(&eventLoop);
- if (std::string(argv[1]) == "get-public-ip") {
- boost::shared_ptr<NATTraversalGetPublicIPRequest> query = natTraverser.createGetPublicIPRequest();
- query->onResult.connect(boost::bind(&handleGetPublicIPRequestResponse, _1));
- query->start();
- eventLoop.run();
- }
- else if (std::string(argv[1]) == "add-port-forward") {
- if (argc < 4) {
- std::cerr << "Invalid parameters" << std::endl;
- }
- boost::shared_ptr<NATTraversalForwardPortRequest> query = natTraverser.createForwardPortRequest(boost::lexical_cast<int>(argv[2]), boost::lexical_cast<int>(argv[3]));
- query->onResult.connect(boost::bind(&handleGetForwardPortRequestResponse, _1));
- query->start();
- eventLoop.run();
- }
- else if (std::string(argv[1]) == "remove-port-forward") {
- if (argc < 4) {
- std::cerr << "Invalid parameters" << std::endl;
- }
- boost::shared_ptr<NATTraversalRemovePortForwardingRequest> query = natTraverser.createRemovePortForwardingRequest(boost::lexical_cast<int>(argv[2]), boost::lexical_cast<int>(argv[3]));
- query->onResult.connect(boost::bind(&handleRemovePortForwardingRequestResponse, _1));
- query->start();
- eventLoop.run();
- }
- else if (std::string(argv[1]) == "get-local-ip") {
- std::cout << PlatformNetworkEnvironment().getLocalAddress().toString() << std::endl;
- }
+ PlatformNATTraversalWorker natTraverser(&eventLoop);
+ if (std::string(argv[1]) == "get-public-ip") {
+ boost::shared_ptr<NATTraversalGetPublicIPRequest> query = natTraverser.createGetPublicIPRequest();
+ query->onResult.connect(boost::bind(&handleGetPublicIPRequestResponse, _1));
+ query->start();
+ eventLoop.run();
+ }
+ else if (std::string(argv[1]) == "add-port-forward") {
+ if (argc < 4) {
+ std::cerr << "Invalid parameters" << std::endl;
+ }
+ boost::shared_ptr<NATTraversalForwardPortRequest> query = natTraverser.createForwardPortRequest(boost::lexical_cast<int>(argv[2]), boost::lexical_cast<int>(argv[3]));
+ query->onResult.connect(boost::bind(&handleGetForwardPortRequestResponse, _1));
+ query->start();
+ eventLoop.run();
+ }
+ else if (std::string(argv[1]) == "remove-port-forward") {
+ if (argc < 4) {
+ std::cerr << "Invalid parameters" << std::endl;
+ }
+ boost::shared_ptr<NATTraversalRemovePortForwardingRequest> query = natTraverser.createRemovePortForwardingRequest(boost::lexical_cast<int>(argv[2]), boost::lexical_cast<int>(argv[3]));
+ query->onResult.connect(boost::bind(&handleRemovePortForwardingRequestResponse, _1));
+ query->start();
+ eventLoop.run();
+ }
+ else if (std::string(argv[1]) == "get-local-ip") {
+ std::cout << PlatformNetworkEnvironment().getLocalAddress().toString() << std::endl;
+ }
}
diff --git a/Swiften/Examples/ParserTester/ParserTester.cpp b/Swiften/Examples/ParserTester/ParserTester.cpp
index 25963a6..af79ece 100644
--- a/Swiften/Examples/ParserTester/ParserTester.cpp
+++ b/Swiften/Examples/ParserTester/ParserTester.cpp
@@ -18,44 +18,44 @@
using namespace Swift;
class MyXMPPParserClient : public XMPPParserClient {
- public:
- virtual void handleStreamStart(const ProtocolHeader&) {
- std::cout << "-> Stream start" << std::endl;
- }
- virtual void handleElement(boost::shared_ptr<ToplevelElement> element) {
- std::cout << "-> Element " << typeid(*element.get()).name() << std::endl;
- }
- virtual void handleStreamEnd() {
- std::cout << "-> Stream end" << std::endl;
- }
+ public:
+ virtual void handleStreamStart(const ProtocolHeader&) {
+ std::cout << "-> Stream start" << std::endl;
+ }
+ virtual void handleElement(boost::shared_ptr<ToplevelElement> element) {
+ std::cout << "-> Element " << typeid(*element.get()).name() << std::endl;
+ }
+ virtual void handleStreamEnd() {
+ std::cout << "-> Stream end" << std::endl;
+ }
};
int main(int argc, char* argv[]) {
- if (argc != 2) {
- std::cerr << "Usage: " << argv[0] << " file" << std::endl;
- return 0;
- }
- FullPayloadParserFactoryCollection factories;
- MyXMPPParserClient parserClient;
- PlatformXMLParserFactory xmlParserFactory;
- XMPPParser parser(&parserClient, &factories, &xmlParserFactory);
- ParserTester<XMLParserClient> tester(&parser);
+ if (argc != 2) {
+ std::cerr << "Usage: " << argv[0] << " file" << std::endl;
+ return 0;
+ }
+ FullPayloadParserFactoryCollection factories;
+ MyXMPPParserClient parserClient;
+ PlatformXMLParserFactory xmlParserFactory;
+ XMPPParser parser(&parserClient, &factories, &xmlParserFactory);
+ ParserTester<XMLParserClient> tester(&parser);
- std::string line;
- std::ifstream myfile (argv[1]);
- if (myfile.is_open()) {
- while (!myfile.eof()) {
- getline (myfile,line);
- std::cout << "Parsing: " << line << std::endl;
- if (!tester.parse(line)) {
- std::cerr << "PARSE ERROR" << std::endl;
- return -1;
- }
- }
- myfile.close();
- }
- else {
- std::cerr << "Unable to open file " << argv[1] << std::endl;
- }
- return 0;
+ std::string line;
+ std::ifstream myfile (argv[1]);
+ if (myfile.is_open()) {
+ while (!myfile.eof()) {
+ getline (myfile,line);
+ std::cout << "Parsing: " << line << std::endl;
+ if (!tester.parse(line)) {
+ std::cerr << "PARSE ERROR" << std::endl;
+ return -1;
+ }
+ }
+ myfile.close();
+ }
+ else {
+ std::cerr << "Unable to open file " << argv[1] << std::endl;
+ }
+ return 0;
}
diff --git a/Swiften/Examples/SendFile/ReceiveFile.cpp b/Swiften/Examples/SendFile/ReceiveFile.cpp
index bfda44f..c6e75e8 100644
--- a/Swiften/Examples/SendFile/ReceiveFile.cpp
+++ b/Swiften/Examples/SendFile/ReceiveFile.cpp
@@ -36,101 +36,101 @@ static const std::string CLIENT_NAME = "Swiften FT Test";
static const std::string CLIENT_NODE = "http://swift.im";
class FileReceiver {
- public:
- FileReceiver(const JID& jid, const std::string& password) : jid(jid), password(password) {
- client = new Swift::Client(jid, password, &networkFactories);
- client->onConnected.connect(boost::bind(&FileReceiver::handleConnected, this));
- client->onDisconnected.connect(boost::bind(&FileReceiver::handleDisconnected, this, _1));
- tracer = new ClientXMLTracer(client);
- }
-
- ~FileReceiver() {
- delete tracer;
- client->onDisconnected.disconnect(boost::bind(&FileReceiver::handleDisconnected, this, _1));
- client->onConnected.disconnect(boost::bind(&FileReceiver::handleConnected, this));
- delete client;
- }
-
- void start() {
- client->connect();
- }
-
- void stop() {
- foreach(const IncomingFileTransfer::ref transfer, incomingFileTransfers) {
- //transfer->stop();
- }
- client->disconnect();
- }
-
- private:
- void handleConnected() {
- Log::setLogLevel(Log::debug);
- client->getFileTransferManager()->onIncomingFileTransfer.connect(boost::bind(&FileReceiver::handleIncomingFileTransfer, this, _1));
-
- DiscoInfo discoInfo;
- discoInfo.addIdentity(DiscoInfo::Identity(CLIENT_NAME, "client", "pc"));
- discoInfo.addFeature(DiscoInfo::JingleFeature);
- discoInfo.addFeature(DiscoInfo::JingleFTFeature);
- discoInfo.addFeature(DiscoInfo::Bytestream);
- discoInfo.addFeature(DiscoInfo::JingleTransportsIBBFeature);
- discoInfo.addFeature(DiscoInfo::JingleTransportsS5BFeature);
- client->getDiscoManager()->setCapsNode(CLIENT_NODE);
- client->getDiscoManager()->setDiscoInfo(discoInfo);
- client->getPresenceSender()->sendPresence(Presence::create());
- }
-
- void handleIncomingFileTransfer(IncomingFileTransfer::ref transfer) {
- SWIFT_LOG(debug) << "foo" << std::endl;
- incomingFileTransfers.push_back(transfer);
- boost::shared_ptr<FileWriteBytestream> out = boost::make_shared<FileWriteBytestream>("out");
- transfer->onFinished.connect(boost::bind(&FileReceiver::handleFileTransferFinished, this, _1, out));
- transfer->accept(out);
- }
-
- void handleDisconnected(const boost::optional<ClientError>&) {
- std::cerr << "Error!" << std::endl;
- exit(-1);
- }
-
- void handleFileTransferFinished(
- const boost::optional<FileTransferError>& error,
- boost::shared_ptr<FileWriteBytestream> out) {
- std::cout << "File transfer finished" << std::endl;
- out->close();
- if (error) {
- exit(-1);
- }
- else {
- exit(0);
- }
- }
-
- void exit(int code) {
- exitCode = code;
- stop();
- eventLoop.stop();
- }
-
- private:
- JID jid;
- std::string password;
- Client* client;
- ClientXMLTracer* tracer;
- std::vector<IncomingFileTransfer::ref> incomingFileTransfers;
+ public:
+ FileReceiver(const JID& jid, const std::string& password) : jid(jid), password(password) {
+ client = new Swift::Client(jid, password, &networkFactories);
+ client->onConnected.connect(boost::bind(&FileReceiver::handleConnected, this));
+ client->onDisconnected.connect(boost::bind(&FileReceiver::handleDisconnected, this, _1));
+ tracer = new ClientXMLTracer(client);
+ }
+
+ ~FileReceiver() {
+ delete tracer;
+ client->onDisconnected.disconnect(boost::bind(&FileReceiver::handleDisconnected, this, _1));
+ client->onConnected.disconnect(boost::bind(&FileReceiver::handleConnected, this));
+ delete client;
+ }
+
+ void start() {
+ client->connect();
+ }
+
+ void stop() {
+ foreach(const IncomingFileTransfer::ref transfer, incomingFileTransfers) {
+ //transfer->stop();
+ }
+ client->disconnect();
+ }
+
+ private:
+ void handleConnected() {
+ Log::setLogLevel(Log::debug);
+ client->getFileTransferManager()->onIncomingFileTransfer.connect(boost::bind(&FileReceiver::handleIncomingFileTransfer, this, _1));
+
+ DiscoInfo discoInfo;
+ discoInfo.addIdentity(DiscoInfo::Identity(CLIENT_NAME, "client", "pc"));
+ discoInfo.addFeature(DiscoInfo::JingleFeature);
+ discoInfo.addFeature(DiscoInfo::JingleFTFeature);
+ discoInfo.addFeature(DiscoInfo::Bytestream);
+ discoInfo.addFeature(DiscoInfo::JingleTransportsIBBFeature);
+ discoInfo.addFeature(DiscoInfo::JingleTransportsS5BFeature);
+ client->getDiscoManager()->setCapsNode(CLIENT_NODE);
+ client->getDiscoManager()->setDiscoInfo(discoInfo);
+ client->getPresenceSender()->sendPresence(Presence::create());
+ }
+
+ void handleIncomingFileTransfer(IncomingFileTransfer::ref transfer) {
+ SWIFT_LOG(debug) << "foo" << std::endl;
+ incomingFileTransfers.push_back(transfer);
+ boost::shared_ptr<FileWriteBytestream> out = boost::make_shared<FileWriteBytestream>("out");
+ transfer->onFinished.connect(boost::bind(&FileReceiver::handleFileTransferFinished, this, _1, out));
+ transfer->accept(out);
+ }
+
+ void handleDisconnected(const boost::optional<ClientError>&) {
+ std::cerr << "Error!" << std::endl;
+ exit(-1);
+ }
+
+ void handleFileTransferFinished(
+ const boost::optional<FileTransferError>& error,
+ boost::shared_ptr<FileWriteBytestream> out) {
+ std::cout << "File transfer finished" << std::endl;
+ out->close();
+ if (error) {
+ exit(-1);
+ }
+ else {
+ exit(0);
+ }
+ }
+
+ void exit(int code) {
+ exitCode = code;
+ stop();
+ eventLoop.stop();
+ }
+
+ private:
+ JID jid;
+ std::string password;
+ Client* client;
+ ClientXMLTracer* tracer;
+ std::vector<IncomingFileTransfer::ref> incomingFileTransfers;
};
int main(int argc, char* argv[]) {
- if (argc != 3) {
- std::cerr << "Usage: " << argv[0] << " <jid> <password>" << std::endl;
- return -1;
- }
+ if (argc != 3) {
+ std::cerr << "Usage: " << argv[0] << " <jid> <password>" << std::endl;
+ return -1;
+ }
- JID jid(argv[1]);
- FileReceiver fileReceiver(jid, std::string(argv[2]));
- fileReceiver.start();
+ JID jid(argv[1]);
+ FileReceiver fileReceiver(jid, std::string(argv[2]));
+ fileReceiver.start();
- eventLoop.run();
+ eventLoop.run();
- return exitCode;
+ return exitCode;
}
diff --git a/Swiften/Examples/SendFile/SendFile.cpp b/Swiften/Examples/SendFile/SendFile.cpp
index 5f2403a..bed6512 100644
--- a/Swiften/Examples/SendFile/SendFile.cpp
+++ b/Swiften/Examples/SendFile/SendFile.cpp
@@ -38,110 +38,110 @@ static BoostNetworkFactories networkFactories(&eventLoop);
static int exitCode = 2;
class FileSender {
- public:
- FileSender(const JID& jid, const std::string& password, const JID& recipient, const boost::filesystem::path& file) : jid(jid), password(password), recipient(recipient), file(file), tracer(NULL) {
- client = new Swift::Client(jid, password, &networkFactories);
- client->onConnected.connect(boost::bind(&FileSender::handleConnected, this));
- client->onDisconnected.connect(boost::bind(&FileSender::handleDisconnected, this, _1));
- //tracer = new ClientXMLTracer(client);
- client->getEntityCapsProvider()->onCapsChanged.connect(boost::bind(&FileSender::handleCapsChanged, this, _1));
- }
-
- ~FileSender() {
- delete tracer;
- client->onDisconnected.disconnect(boost::bind(&FileSender::handleDisconnected, this, _1));
- client->onConnected.disconnect(boost::bind(&FileSender::handleConnected, this));
- delete client;
- }
-
- void start() {
- client->connect();
- }
-
- private:
- void handleConnected() {
- std::cout << "Connected. Awaiting presence from receipient." << std::endl;
- client->sendPresence(Presence::create());
- }
-
- void handleCapsChanged(JID jid) {
- if (jid.toBare() == recipient) {
- // create ReadBytestream from file
- boost::shared_ptr<FileReadBytestream> fileStream = boost::make_shared<FileReadBytestream>(file);
-
- outgoingFileTransfer = client->getFileTransferManager()->createOutgoingFileTransfer(recipient, file, "Some File!", fileStream);
-
- if (outgoingFileTransfer) {
- outgoingFileTransfer->onFinished.connect(boost::bind(&FileSender::handleFileTransferFinished, this, _1));
- std::cout << "Starting file-transfer to " << recipient.toString() << "." << std::endl;
- outgoingFileTransfer->start();
- // TODO: getting notified about FT status and end
- } else {
- std::cout << recipient << " doesn't support any kind of file transfer!" << std::endl;
- client->disconnect();
- }
- }
- }
-
- void handleDisconnected(const boost::optional<ClientError>& err) {
- if (err) {
- std::cout << "Disconnected due to error ( " << err.get().getType() << " )." << std::endl;
- exit(-1);
- }
- else {
- std::cout << "Successfully disconnected." << std::endl;
- }
- }
-
- void handleFileTransferFinished(const boost::optional<FileTransferError>& error) {
- std::cout << "File transfer finished." << std::endl;
- outgoingFileTransfer.reset();
- if (error) {
- client->disconnect();
- exit(-1);
- }
- else {
- client->disconnect();
- exit(0);
- }
- }
-
- void exit(int code) {
- exitCode = code;
- eventLoop.stop();
- }
-
- private:
- BoostConnectionServer::ref connectionServer;
- OutgoingFileTransfer::ref outgoingFileTransfer;
- JID jid;
- std::string password;
- JID recipient;
- boost::filesystem::path file;
- Client* client;
- ClientXMLTracer* tracer;
+ public:
+ FileSender(const JID& jid, const std::string& password, const JID& recipient, const boost::filesystem::path& file) : jid(jid), password(password), recipient(recipient), file(file), tracer(NULL) {
+ client = new Swift::Client(jid, password, &networkFactories);
+ client->onConnected.connect(boost::bind(&FileSender::handleConnected, this));
+ client->onDisconnected.connect(boost::bind(&FileSender::handleDisconnected, this, _1));
+ //tracer = new ClientXMLTracer(client);
+ client->getEntityCapsProvider()->onCapsChanged.connect(boost::bind(&FileSender::handleCapsChanged, this, _1));
+ }
+
+ ~FileSender() {
+ delete tracer;
+ client->onDisconnected.disconnect(boost::bind(&FileSender::handleDisconnected, this, _1));
+ client->onConnected.disconnect(boost::bind(&FileSender::handleConnected, this));
+ delete client;
+ }
+
+ void start() {
+ client->connect();
+ }
+
+ private:
+ void handleConnected() {
+ std::cout << "Connected. Awaiting presence from receipient." << std::endl;
+ client->sendPresence(Presence::create());
+ }
+
+ void handleCapsChanged(JID jid) {
+ if (jid.toBare() == recipient) {
+ // create ReadBytestream from file
+ boost::shared_ptr<FileReadBytestream> fileStream = boost::make_shared<FileReadBytestream>(file);
+
+ outgoingFileTransfer = client->getFileTransferManager()->createOutgoingFileTransfer(recipient, file, "Some File!", fileStream);
+
+ if (outgoingFileTransfer) {
+ outgoingFileTransfer->onFinished.connect(boost::bind(&FileSender::handleFileTransferFinished, this, _1));
+ std::cout << "Starting file-transfer to " << recipient.toString() << "." << std::endl;
+ outgoingFileTransfer->start();
+ // TODO: getting notified about FT status and end
+ } else {
+ std::cout << recipient << " doesn't support any kind of file transfer!" << std::endl;
+ client->disconnect();
+ }
+ }
+ }
+
+ void handleDisconnected(const boost::optional<ClientError>& err) {
+ if (err) {
+ std::cout << "Disconnected due to error ( " << err.get().getType() << " )." << std::endl;
+ exit(-1);
+ }
+ else {
+ std::cout << "Successfully disconnected." << std::endl;
+ }
+ }
+
+ void handleFileTransferFinished(const boost::optional<FileTransferError>& error) {
+ std::cout << "File transfer finished." << std::endl;
+ outgoingFileTransfer.reset();
+ if (error) {
+ client->disconnect();
+ exit(-1);
+ }
+ else {
+ client->disconnect();
+ exit(0);
+ }
+ }
+
+ void exit(int code) {
+ exitCode = code;
+ eventLoop.stop();
+ }
+
+ private:
+ BoostConnectionServer::ref connectionServer;
+ OutgoingFileTransfer::ref outgoingFileTransfer;
+ JID jid;
+ std::string password;
+ JID recipient;
+ boost::filesystem::path file;
+ Client* client;
+ ClientXMLTracer* tracer;
};
int main(int argc, char* argv[]) {
- if (argc != 5) {
- std::cerr << "Usage: " << argv[0] << " <jid> <password> <recipient> <file>" << std::endl;
- return -1;
- }
-
- //Log::setLogLevel(Log::debug);
-
- JID sender(argv[1]);
- JID recipient(argv[3]);
- FileSender fileSender(sender, std::string(argv[2]), recipient, boost::filesystem::path(argv[4]));
- fileSender.start();
- {
- Timer::ref timer = networkFactories.getTimerFactory()->createTimer(30000);
- timer->onTick.connect(boost::bind(&SimpleEventLoop::stop, &eventLoop));
- timer->start();
-
- eventLoop.run();
- }
-
- return exitCode;
+ if (argc != 5) {
+ std::cerr << "Usage: " << argv[0] << " <jid> <password> <recipient> <file>" << std::endl;
+ return -1;
+ }
+
+ //Log::setLogLevel(Log::debug);
+
+ JID sender(argv[1]);
+ JID recipient(argv[3]);
+ FileSender fileSender(sender, std::string(argv[2]), recipient, boost::filesystem::path(argv[4]));
+ fileSender.start();
+ {
+ Timer::ref timer = networkFactories.getTimerFactory()->createTimer(30000);
+ timer->onTick.connect(boost::bind(&SimpleEventLoop::stop, &eventLoop));
+ timer->start();
+
+ eventLoop.run();
+ }
+
+ return exitCode;
}
diff --git a/Swiften/Examples/SendMessage/SendMessage.cpp b/Swiften/Examples/SendMessage/SendMessage.cpp
index 5f13903..973cda5 100644
--- a/Swiften/Examples/SendMessage/SendMessage.cpp
+++ b/Swiften/Examples/SendMessage/SendMessage.cpp
@@ -30,62 +30,62 @@ static boost::bsignals::connection errorConnection;
static void handleConnected() {
- boost::shared_ptr<Message> message(new Message());
- message->setBody(messageBody);
- message->setTo(recipient);
- client->sendMessage(message);
- exitCode = 0;
- errorConnection.disconnect();
- client->disconnect();
- eventLoop.stop();
+ boost::shared_ptr<Message> message(new Message());
+ message->setBody(messageBody);
+ message->setTo(recipient);
+ client->sendMessage(message);
+ exitCode = 0;
+ errorConnection.disconnect();
+ client->disconnect();
+ eventLoop.stop();
}
static void handleDisconnected(const boost::optional<ClientError>&) {
- std::cerr << "Error!" << std::endl;
- exitCode = 1;
- eventLoop.stop();
+ std::cerr << "Error!" << std::endl;
+ exitCode = 1;
+ eventLoop.stop();
}
int main(int argc, char* argv[]) {
- if (argc < 5 || argc > 6) {
- std::cerr << "Usage: " << argv[0] << " <jid> [<connect_host>]<password> <recipient> <message>" << std::endl;
- return -1;
- }
-
- int argi = 1;
-
- std::string jid = argv[argi++];
- std::string connectHost = "";
- if (argc == 6) {
- connectHost = argv[argi++];
- }
-
- client = new Swift::Client(JID(jid), std::string(argv[argi++]), &networkFactories);
- client->setAlwaysTrustCertificates();
-
- recipient = JID(argv[argi++]);
- messageBody = std::string(argv[argi++]);
-
- ClientXMLTracer* tracer = new ClientXMLTracer(client);
- client->onConnected.connect(&handleConnected);
- errorConnection = client->onDisconnected.connect(&handleDisconnected);
- if (!connectHost.empty()) {
- ClientOptions options;
- options.manualHostname = connectHost;
- client->connect(options);
- } else {
- client->connect();
- }
-
- {
- Timer::ref timer = networkFactories.getTimerFactory()->createTimer(30000);
- timer->onTick.connect(boost::bind(&SimpleEventLoop::stop, &eventLoop));
- timer->start();
-
- eventLoop.run();
- }
-
- delete tracer;
- delete client;
- return exitCode;
+ if (argc < 5 || argc > 6) {
+ std::cerr << "Usage: " << argv[0] << " <jid> [<connect_host>]<password> <recipient> <message>" << std::endl;
+ return -1;
+ }
+
+ int argi = 1;
+
+ std::string jid = argv[argi++];
+ std::string connectHost = "";
+ if (argc == 6) {
+ connectHost = argv[argi++];
+ }
+
+ client = new Swift::Client(JID(jid), std::string(argv[argi++]), &networkFactories);
+ client->setAlwaysTrustCertificates();
+
+ recipient = JID(argv[argi++]);
+ messageBody = std::string(argv[argi++]);
+
+ ClientXMLTracer* tracer = new ClientXMLTracer(client);
+ client->onConnected.connect(&handleConnected);
+ errorConnection = client->onDisconnected.connect(&handleDisconnected);
+ if (!connectHost.empty()) {
+ ClientOptions options;
+ options.manualHostname = connectHost;
+ client->connect(options);
+ } else {
+ client->connect();
+ }
+
+ {
+ Timer::ref timer = networkFactories.getTimerFactory()->createTimer(30000);
+ timer->onTick.connect(boost::bind(&SimpleEventLoop::stop, &eventLoop));
+ timer->start();
+
+ eventLoop.run();
+ }
+
+ delete tracer;
+ delete client;
+ return exitCode;
}