diff options
| author | Bob Jamison <ishmalius@gmail.com> | 2006-05-15 15:06:21 +0000 |
|---|---|---|
| committer | ishmal <ishmal@users.sourceforge.net> | 2006-05-15 15:06:21 +0000 |
| commit | 8325c242bbc39df39b5b2260d3e2aac289d8a930 (patch) | |
| tree | 9a910be0c78883d9beec6cece07f7f800e0713ae /src/pedro/work/groupchat.cpp | |
| parent | fix potential (though currently impossible) crash when spatial mode is used w... (diff) | |
| download | inkscape-8325c242bbc39df39b5b2260d3e2aac289d8a930.tar.gz inkscape-8325c242bbc39df39b5b2260d3e2aac289d8a930.zip | |
Move from the jabber_whiteboard directory to its own, so that it can be updated in parallel.
(bzr r846)
Diffstat (limited to 'src/pedro/work/groupchat.cpp')
| -rw-r--r-- | src/pedro/work/groupchat.cpp | 221 |
1 files changed, 221 insertions, 0 deletions
diff --git a/src/pedro/work/groupchat.cpp b/src/pedro/work/groupchat.cpp new file mode 100644 index 000000000..38a17abb6 --- /dev/null +++ b/src/pedro/work/groupchat.cpp @@ -0,0 +1,221 @@ + + +#include <stdio.h> +#include <string.h> + +#include "pedroxmpp.h" + +//######################################################################## +//# T E S T +//######################################################################## + +using namespace Pedro; + + +class Listener : public Pedro::XmppEventListener +{ +public: + Listener(){} + + virtual ~Listener(){} + + virtual void processXmppEvent(const Pedro::XmppEvent &evt) + { + int typ = evt.getType(); + switch (typ) + { + case Pedro::XmppEvent::EVENT_STATUS: + { + printf("STATUS: %s\n", evt.getData().c_str()); + break; + } + case Pedro::XmppEvent::EVENT_ERROR: + { + printf("ERROR: %s\n", evt.getData().c_str()); + break; + } + case Pedro::XmppEvent::EVENT_CONNECTED: + { + printf("CONNECTED\n"); + break; + } + case Pedro::XmppEvent::EVENT_DISCONNECTED: + { + printf("DISCONNECTED\n"); + break; + } + case Pedro::XmppEvent::EVENT_MESSAGE: + { + printf("<%s> %s\n", evt.getFrom().c_str(), evt.getData().c_str()); + break; + } + case Pedro::XmppEvent::EVENT_PRESENCE: + { + printf("PRESENCE\n"); + printf("from : %s\n", evt.getFrom().c_str()); + printf("presence : %s\n", evt.getPresence().c_str()); + break; + } + case Pedro::XmppEvent::EVENT_MUC_MESSAGE: + { + printf("<%s> %s\n", evt.getFrom().c_str(), evt.getData().c_str()); + break; + } + case Pedro::XmppEvent::EVENT_MUC_JOIN: + { + printf("MUC JOIN\n"); + printf("group: %s\n", evt.getGroup().c_str()); + printf("from : %s\n", evt.getFrom().c_str()); + printf("presence: %s\n", evt.getPresence().c_str()); + break; + } + case Pedro::XmppEvent::EVENT_MUC_LEAVE: + { + printf("MUC LEAVE\n"); + printf("group: %s\n", evt.getGroup().c_str()); + printf("from : %s\n", evt.getFrom().c_str()); + printf("presence: %s\n", evt.getPresence().c_str()); + break; + } + case Pedro::XmppEvent::EVENT_MUC_PRESENCE: + { + printf("MUC PRESENCE\n"); + printf("group : %s\n", evt.getGroup().c_str()); + printf("from : %s\n", evt.getFrom().c_str()); + printf("presence: %s\n", evt.getPresence().c_str()); + break; + } + + } + } +}; + + +class CommandLineGroupChat +{ +public: + CommandLineGroupChat(const DOMString &hostArg, + int portArg, + const DOMString &userArg, + const DOMString &passArg, + const DOMString &resourceArg, + const DOMString &groupJidArg, + const DOMString &nickArg) + { + host = hostArg; + port = portArg; + user = userArg; + pass = passArg; + resource = resourceArg; + groupJid = groupJidArg; + nick = nickArg; + } + ~CommandLineGroupChat() + { + client.disconnect(); + } + + virtual bool run(); + virtual bool processCommandLine(); + +private: + + DOMString host; + int port; + DOMString user; + DOMString pass; + DOMString resource; + DOMString groupJid; + DOMString nick; + + XmppClient client; + +}; + + +bool CommandLineGroupChat::run() +{ + Listener listener; + client.addXmppEventListener(listener); + + //Host, port, user, pass, resource + if (!client.connect(host, port, user, pass, resource)) + { + return false; + } + + //Group jabber id, nick, pass + if (!client.groupChatJoin(groupJid, nick, "")) + { + printf("failed join\n"); + return false; + } + + //Allow receive buffer to clear out + client.pause(10000); + + while (true) + { + if (!processCommandLine()) + break; + } + + //Group jabber id, nick + client.groupChatLeave(groupJid, nick); + + + client.disconnect(); + + return true; +} + + +bool CommandLineGroupChat::processCommandLine() +{ + char buf[512]; + printf("send>:"); + fgets(buf, 511, stdin); + + if (buf[0]=='/') + { + if (strncmp(buf, "/q", 2)==0) + return false; + else + { + printf("Unknown command\n"); + return true; + } + } + + else + { + DOMString msg = buf; + if (msg.size() > 0 ) + { + if (!client.groupChatMessage(groupJid, buf)) + { + printf("failed message send\n"); + return false; + } + } + } + + return true; +} + + +int main(int argc, char **argv) +{ + if (argc!=8) + { + printf("usage: %s host port user pass resource groupid nick\n", argv[0]); + return 1; + } + int port = atoi(argv[2]); + CommandLineGroupChat groupChat(argv[1], port, argv[3], argv[4], + argv[5], argv[6], argv[7]); + if (!groupChat.run()) + return 1; + return 0; +} + |
