From 659d45a82c81bf99a9a9ff9771dec178fc6a43b7 Mon Sep 17 00:00:00 2001 From: plfiorini Date: Fri, 28 May 2010 21:00:30 +0000 Subject: [PATCH] Removed gtalk, facebook and libjabber. --- Contributors | 13 +- libs/Jamfile | 1 - libs/libjabber/Base64.cpp | 118 -- libs/libjabber/Base64.h | 21 - libs/libjabber/JabberAgent.cpp | 134 --- libs/libjabber/JabberAgent.h | 45 - libs/libjabber/JabberContact.cpp | 135 --- libs/libjabber/JabberContact.h | 46 - libs/libjabber/JabberElement.cpp | 100 -- libs/libjabber/JabberElement.h | 35 - libs/libjabber/JabberHandler.cpp | 1217 --------------------- libs/libjabber/JabberHandler.h | 171 --- libs/libjabber/JabberManager.h | 34 - libs/libjabber/JabberMessage.cpp | 124 --- libs/libjabber/JabberMessage.h | 48 - libs/libjabber/JabberPlug.h | 25 - libs/libjabber/JabberPresence.cpp | 179 --- libs/libjabber/JabberPresence.h | 47 - libs/libjabber/JabberRegistration.cpp | 111 -- libs/libjabber/JabberRegistration.h | 46 - libs/libjabber/JabberSSLPlug.cpp | 188 ---- libs/libjabber/JabberSSLPlug.h | 53 - libs/libjabber/JabberSocketPlug.cpp | 187 ---- libs/libjabber/JabberSocketPlug.h | 41 - libs/libjabber/JabberVCard.cpp | 245 ----- libs/libjabber/JabberVCard.h | 64 -- libs/libjabber/Jamfile | 32 - libs/libjabber/LICENSE | 33 - libs/libjabber/Logger.cpp | 50 - libs/libjabber/Logger.h | 10 - libs/libjabber/ObjectList.h | 866 --------------- libs/libjabber/SHA1.cpp | 222 ---- libs/libjabber/SHA1.h | 81 -- libs/libjabber/ServerHandler.h | 7 - libs/libjabber/States.h | 18 - libs/libjabber/VCardManager.cpp | 138 --- libs/libjabber/VCardManager.h | 34 - protocols/Jamfile | 2 - protocols/facebook/Facebook.cpp | 854 --------------- protocols/facebook/Facebook.h | 120 -- protocols/facebook/Jamfile | 19 - protocols/facebook/facebook.rdef | 34 - protocols/facebook/main.cpp | 25 - protocols/facebook/settings_template.rdef | 19 - protocols/gtalk/GoogleTalk.cpp | 854 --------------- protocols/gtalk/GoogleTalk.h | 119 -- protocols/gtalk/Jamfile | 20 - protocols/gtalk/gtalk.rdef | 34 - protocols/gtalk/main.cpp | 25 - protocols/gtalk/settings_template.rdef | 19 - 50 files changed, 6 insertions(+), 7057 deletions(-) delete mode 100644 libs/libjabber/Base64.cpp delete mode 100644 libs/libjabber/Base64.h delete mode 100644 libs/libjabber/JabberAgent.cpp delete mode 100644 libs/libjabber/JabberAgent.h delete mode 100644 libs/libjabber/JabberContact.cpp delete mode 100644 libs/libjabber/JabberContact.h delete mode 100644 libs/libjabber/JabberElement.cpp delete mode 100644 libs/libjabber/JabberElement.h delete mode 100644 libs/libjabber/JabberHandler.cpp delete mode 100644 libs/libjabber/JabberHandler.h delete mode 100644 libs/libjabber/JabberManager.h delete mode 100644 libs/libjabber/JabberMessage.cpp delete mode 100644 libs/libjabber/JabberMessage.h delete mode 100644 libs/libjabber/JabberPlug.h delete mode 100644 libs/libjabber/JabberPresence.cpp delete mode 100644 libs/libjabber/JabberPresence.h delete mode 100644 libs/libjabber/JabberRegistration.cpp delete mode 100644 libs/libjabber/JabberRegistration.h delete mode 100644 libs/libjabber/JabberSSLPlug.cpp delete mode 100644 libs/libjabber/JabberSSLPlug.h delete mode 100644 libs/libjabber/JabberSocketPlug.cpp delete mode 100644 libs/libjabber/JabberSocketPlug.h delete mode 100644 libs/libjabber/JabberVCard.cpp delete mode 100644 libs/libjabber/JabberVCard.h delete mode 100644 libs/libjabber/Jamfile delete mode 100644 libs/libjabber/LICENSE delete mode 100644 libs/libjabber/Logger.cpp delete mode 100644 libs/libjabber/Logger.h delete mode 100644 libs/libjabber/ObjectList.h delete mode 100644 libs/libjabber/SHA1.cpp delete mode 100644 libs/libjabber/SHA1.h delete mode 100644 libs/libjabber/ServerHandler.h delete mode 100644 libs/libjabber/States.h delete mode 100644 libs/libjabber/VCardManager.cpp delete mode 100644 libs/libjabber/VCardManager.h delete mode 100644 protocols/facebook/Facebook.cpp delete mode 100644 protocols/facebook/Facebook.h delete mode 100644 protocols/facebook/Jamfile delete mode 100644 protocols/facebook/facebook.rdef delete mode 100644 protocols/facebook/main.cpp delete mode 100644 protocols/facebook/settings_template.rdef delete mode 100644 protocols/gtalk/GoogleTalk.cpp delete mode 100644 protocols/gtalk/GoogleTalk.h delete mode 100644 protocols/gtalk/Jamfile delete mode 100644 protocols/gtalk/gtalk.rdef delete mode 100644 protocols/gtalk/main.cpp delete mode 100644 protocols/gtalk/settings_template.rdef diff --git a/Contributors b/Contributors index a7f398c..e4cbe38 100644 --- a/Contributors +++ b/Contributors @@ -8,22 +8,21 @@ We will add you! Caya is brought to you buy: - * Andrea Anzani - * Pier Luigi Fiorini + * Andrea Anzani + * Pier Luigi Fiorini == Code == Contributors in alphabetical order by last name: - * Alexander Botero-Lowry (AIM protocol add-on) - * Oliver Ruiz Dorantes (Preferences) - * Rene Gollent (RosterListView::MessageReceived() patch) + * Alexander Botero-Lowry + * Oliver Ruiz Dorantes + * Rene Gollent == Icons == - Michele Frau created the following HVIF icons: + Michele Frau * Caya * AIM protocol * ICQ protocol - * GoogleTalk protocol diff --git a/libs/Jamfile b/libs/Jamfile index 0fa38b6..988e09d 100644 --- a/libs/Jamfile +++ b/libs/Jamfile @@ -2,7 +2,6 @@ SubDir TOP libs ; # Include all the components. SubInclude TOP libs librunview ; -SubInclude TOP libs libjabber ; SubInclude TOP libs libsupport ; SubInclude TOP libs libinterface ; SubInclude TOP libs libimcomm ; diff --git a/libs/libjabber/Base64.cpp b/libs/libjabber/Base64.cpp deleted file mode 100644 index fe2ad78..0000000 --- a/libs/libjabber/Base64.cpp +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright 2009, Pier Luigi Fiorini. - * Copyright 2004-2009, René Nyffenegge - * Distributed under the terms of the MIT License. - */ - -// Based on original code from: -// http://www.adp-gmbh.ch/cpp/common/base64.html - -#include - -#include "Base64.h" - -static const BString chars = - "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - "abcdefghijklmnopqrstuvwxyz" - "0123456789+/"; - - -Base64::Base64() -{ -} - - -BString -Base64::Encode(const uchar* data, size_t length) -{ - BString encoded; - int32 i = 0; - uchar array3[3], array4[4]; - - while (length--) { - array3[i++] = *(data++); - - if (i == 3) { - array4[0] = (uchar)((array3[0] & 0xfc) >> 2); - array4[1] = (uchar)(((array3[0] & 0x03) << 4) + ((array3[1] & 0xf0) >> 4)); - array4[2] = (uchar)(((array3[1] & 0x0f) << 2) + ((array3[2] & 0xc0) >> 6)); - array4[3] = (uchar)(((array4[2] & 0x3) << 6) + array4[3]); - - for (i = 0; i < 3; i++) - encoded += array3[i]; - i = 0; - } - } - - if (i) { - for (int32 j = i; j < 4; j++) - array4[j] = 0; - - for (int32 j = 0; j < 4; j++) - array4[j] = (uchar)chars.FindFirst(array4[j]); - - array3[0] = (uchar)((array4[0] << 2) + ((array4[i] & 0x30) >> 4)); - array3[1] = (uchar)(((array4[1] & 0xf) << 4) + ((array4[2] & 0x3c) >> 2)); - array3[2] = (uchar)(((array4[2] & 0x3) << 6) + array4[3]); - - for (int32 j = 0; j < i - 1; j++) - encoded += array3[j]; - } - - return encoded; -} - - -bool -Base64::IsBase64(uchar c) -{ - return isalnum(c) || (c == '+') || (c == '/'); -} - - -BString -Base64::Decode(const BString& data) -{ - int32 length = data.Length(); - int32 i = 0; - int32 index = 0; - uchar array4[4], array3[3]; - BString decoded; - - while (length-- && (data[index] != '=') && IsBase64(data[index])) { - array4[i++] = data[index]; - index++; - - if (i == 4) { - for (i = 0; i < 4; i++) - array4[i] = (uchar)chars.FindFirst(array4[i]); - - array3[0] = (uchar)((array4[0] << 2) + ((array4[1] & 0x30)>> 4)); - array3[1] = (uchar)(((array4[1] & 0xf) << 4) + ((array4[2] & 0x3c) >> 2)); - array3[2] = (uchar)(((array4[2] & 0x3) << 6) + array4[3]); - - for (i = 0; i < 3; i++) - decoded += array3[i]; - i = 0; - } - } - - if (i) { - int32 j; - - for (j = i; j < 4; j++) - array4[j] = 0; - - for (j = 0; j < 4; j++) - array4[j] = (uchar)chars.FindFirst(array4[j]); - - array3[0] = (uchar)((array4[0] << 2) + ((array4[1] & 0x30) >> 4)); - array3[1] = (uchar)(((array4[1] & 0xf) << 4) + ((array4[2] & 0x3c) >> 2)); - array3[2] = (uchar)(((array4[2] & 0x3) << 6) + array4[3]); - - for (j = 0; j < i - 1; j++) - decoded += array3[j]; - } - - return decoded; -} diff --git a/libs/libjabber/Base64.h b/libs/libjabber/Base64.h deleted file mode 100644 index 3188a05..0000000 --- a/libs/libjabber/Base64.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2009, Pier Luigi Fiorini. - * Copyright 2004-2009, René Nyffenegge - * Distributed under the terms of the MIT License. - */ -#ifndef _BASE_64_H -#define _BASE_64_H - -#include - -class Base64 { -public: - static bool IsBase64(uchar c); - static BString Encode(const uchar* data, size_t length); - static BString Decode(const BString& data); - -private: - Base64(); -}; - -#endif // _BASE_64_H diff --git a/libs/libjabber/JabberAgent.cpp b/libs/libjabber/JabberAgent.cpp deleted file mode 100644 index 00e87a9..0000000 --- a/libs/libjabber/JabberAgent.cpp +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Copyright 2002, The Olmeki Team. - * Distributed under the terms of the Olmeki License. - */ - -#include - -#include "JabberAgent.h" -#include "Logger.h" - - -JabberAgent::JabberAgent() - : fGroupChat(false), - fSearchable(false), - fTransport(false), - fRegistration(false), - fService(""), - fName(""), - fJid("") -{ -} - - -JabberAgent::~JabberAgent() -{ -} - - -void -JabberAgent::PrintToStream() -{ - logmsg("JabberAgent:"); - logmsg(" Name: %s", fName.String()); - logmsg(" Service: %s", fService.String()); - logmsg(" Jid: %s", fJid.String()); -} - - -bool -JabberAgent::HasGroupChat() -{ - return fGroupChat; -} - - -bool -JabberAgent::IsTransport() -{ - return fTransport; -} - - -bool -JabberAgent::Searchable() -{ - return fSearchable; -} - - -bool -JabberAgent::AllowsRegistration() -{ - return fRegistration; -} - - -BString -JabberAgent::GetService() const -{ - return fService; -} - - -BString -JabberAgent::GetName() const -{ - return fName; -} - - -BString -JabberAgent::GetJid() const -{ - return fJid; -} - - -void -JabberAgent::SetService(const BString& service) -{ - fService = service; -} - - -void -JabberAgent::SetName(const BString& name) -{ - fName = name; -} - - -void -JabberAgent::SetJid(const BString& jid) -{ - fJid = jid; -} - - -void -JabberAgent::SetGroupChat(bool groupChat) -{ - fGroupChat = groupChat; -} - - -void -JabberAgent::SetSearchable(bool searchable) -{ - fSearchable = searchable; -} - - -void -JabberAgent::SetTransport(bool transport) -{ - fTransport = transport; -} - - -void -JabberAgent::SetRegistration(bool registration) -{ - fRegistration = registration; -} diff --git a/libs/libjabber/JabberAgent.h b/libs/libjabber/JabberAgent.h deleted file mode 100644 index dca1e94..0000000 --- a/libs/libjabber/JabberAgent.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2002, The Olmeki Team. - * Distributed under the terms of the Olmeki License. - */ -#ifndef _JABBER_AGENT_H -#define _JABBER_AGENT_H - -#include - -class JabberAgent { -public: - JabberAgent(); - ~JabberAgent(); - - void PrintToStream(); - - bool HasGroupChat(); - bool Searchable(); - bool IsTransport(); - bool AllowsRegistration(); - - BString GetService() const; - BString GetName() const; - BString GetJid() const; - BString GetInstructions() const; - - void SetGroupChat(bool groupChat); - void SetSearchable(bool searchable); - void SetTransport(bool transport); - void SetRegistration(bool registration); - void SetService(const BString& service); - void SetName(const BString& name); - void SetJid(const BString& jid); - -private: - bool fGroupChat; - bool fSearchable; - bool fTransport; - bool fRegistration; - BString fService; - BString fName; - BString fJid; -}; - -#endif // _JABBER_AGENT_H diff --git a/libs/libjabber/JabberContact.cpp b/libs/libjabber/JabberContact.cpp deleted file mode 100644 index a4d6fad..0000000 --- a/libs/libjabber/JabberContact.cpp +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright 2002, The Olmeki Team. - * Distributed under the terms of the Olmeki License. - */ - -#include - -#include "JabberContact.h" -#include "Logger.h" - -JabberContact::JabberContact() - : fPresence(new JabberPresence()), - fId(""), fVCard(NULL) -{ -} - - -JabberContact::~JabberContact() -{ -} - - -void -JabberContact::PrintToStream() -{ - logmsg("JabberContact:"); - logmsg(" Name: %s", fName.String()); - logmsg(" Group: %s", fGroup.String()); - logmsg(" Jid: %s", fJid.String()); -} - - -void -JabberContact::SetName(const BString& name) -{ - fName = name; -} - - -void -JabberContact::SetGroup(const BString& group) -{ - fGroup = group; -} - - -void -JabberContact::SetPresence(JabberPresence* presence) -{ - fPresence = presence; -} - - -void -JabberContact::SetPresence() -{ - delete fPresence; - fPresence = new JabberPresence(); -} - - -void -JabberContact::SetJid(const BString& jid) -{ - fJid = jid; -} - - -void -JabberContact::SetVCard(JabberVCard* vCard) -{ - fVCard = vCard; -} - - -void -JabberContact::SetSubscription(const BString& subscription) -{ - fSubscription = subscription; -} - - -BString -JabberContact::GetSubscription() const -{ - return fSubscription; -} - - -BString -JabberContact::GetName() const -{ - return fName; -} - - -BString -JabberContact::GetGroup() const -{ - return fGroup; -} - -JabberPresence* -JabberContact::GetPresence() -{ - return fPresence; -} - - -BString -JabberContact::GetJid() const -{ - return fJid; -} - - -JabberVCard* -JabberContact::GetVCard() const -{ - return fVCard; -} - - -BString -JabberContact::GetLastMessageID() const -{ - return fId; -} - - -void -JabberContact::SetLastMessageID(const BString& id) -{ - fId = id; -} diff --git a/libs/libjabber/JabberContact.h b/libs/libjabber/JabberContact.h deleted file mode 100644 index 1faa0e4..0000000 --- a/libs/libjabber/JabberContact.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2002, The Olmeki Team. - * Distributed under the terms of the Olmeki License. - */ -#ifndef _JABBER_CONTACT_H -#define _JABBER_CONTACT_H - -#include - -#include "JabberPresence.h" -#include "JabberVCard.h" - -class JabberContact { -public: - JabberContact(); - virtual ~JabberContact(); - - void SetName(const BString& name); - void SetGroup(const BString& group); - void SetSubscription(const BString& group); - virtual void SetPresence(); - virtual void SetPresence(JabberPresence* presence); - void SetJid(const BString& jid); - void SetVCard(JabberVCard* vCard); - void PrintToStream(); - BString GetName() const; - BString GetGroup() const; - BString GetSubscription() const; - JabberPresence* GetPresence(); - BString GetJid() const; - JabberVCard* GetVCard() const; - - BString GetLastMessageID() const; - void SetLastMessageID(const BString& id); - -private: - BString fJid; - BString fGroup; - JabberPresence* fPresence; - BString fName; - BString fId; - BString fSubscription; - JabberVCard* fVCard; -}; - -#endif // JABBER_CONTACT_H diff --git a/libs/libjabber/JabberElement.cpp b/libs/libjabber/JabberElement.cpp deleted file mode 100644 index 7d51224..0000000 --- a/libs/libjabber/JabberElement.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright 2002, The Olmeki Team. - * Distributed under the terms of the Olmeki License. - */ - -#include - -#include "JabberElement.h" - -JabberElement::JabberElement() - : fName(""), - fData(""), - fAttr(NULL), - fAttrCount(-1) -{ -} - - -JabberElement::~JabberElement() -{ - Free(); -} - - -void -JabberElement::SetName(const BString& name) -{ - fName = name; -} - - -BString -JabberElement::GetName() const -{ - return fName; -} - - -void -JabberElement::SetData(const BString& data) -{ - fData = data; -} - - -BString -JabberElement::GetData() const -{ - return fData; -} - - -void -JabberElement::SetAttr(const char** attr) -{ - Free(); - if (attr) { - const char** a = attr; - - fAttrCount = 0; - - while (*a) { - fAttrCount++; - a++; - } - - fAttr = new char *[fAttrCount + 1]; - for (int32 i = 0; i < fAttrCount; i++) { - fAttr[i] = new char[strlen(attr[i]) + 1]; - strcpy(fAttr[i], attr[i]); - } - } -} - - -const char** -JabberElement::GetAttr() const -{ - return (const char **)fAttr; -} - - -int32 -JabberElement::GetAttrCount() const -{ - return fAttrCount; -} - - -void -JabberElement::Free() -{ - if (fAttrCount != -1) { - for (int32 i = 0; i < fAttrCount; i++) - delete [] fAttr[i]; - delete fAttr; - fAttr = NULL; - fAttrCount = -1; - } -} diff --git a/libs/libjabber/JabberElement.h b/libs/libjabber/JabberElement.h deleted file mode 100644 index b1cd8cb..0000000 --- a/libs/libjabber/JabberElement.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2002, The Olmeki Team. - * Distributed under the terms of the Olmeki License. - */ -#ifndef _JABBER_ELEMENT_H -#define _JABBER_ELEMENT_H - -#include - -class JabberElement { -public: - JabberElement(); - ~JabberElement(); - - void SetName(const BString& name); - BString GetName() const; - - void SetData(const BString& data); - BString GetData() const; - - void SetAttr(const char** attr); - const char ** GetAttr() const; - - int32 GetAttrCount() const; - -private: - BString fName; - BString fData; - char ** fAttr; - int32 fAttrCount; - - void Free(); -}; - -#endif // _JABBER_ELEMENT_H diff --git a/libs/libjabber/JabberHandler.cpp b/libs/libjabber/JabberHandler.cpp deleted file mode 100644 index c70ef38..0000000 --- a/libs/libjabber/JabberHandler.cpp +++ /dev/null @@ -1,1217 +0,0 @@ -/* - * Copyright 2002, The Olmeki Team. - * Distributed under the terms of the MIT License. - * - * Authors: - * Andrea Anzani, andrea.anzani@gmail.com - * Pier Luigi Fiorini, pierluigi.fiorini@gmail.com - */ - -#include - -#include -#include -#include - -#include "JabberHandler.h" -#include "SHA1.h" -#include "States.h" -#include "Logger.h" -#include "VCardManager.h" - -JabberHandler::JabberHandler(const BString& name, JabberPlug* plug) - : fHost(""), - fUsername(""), - fJid(""), - fPassword(""), - fResource(""), - fPort(0), - fPriority(0), - fSocket(-1), - fAuthorized(false), - fPlug(plug), - fVCardManager(new VCardManager(this)), - fIncrementalId(666) //why not? -{ - fElementStack = new ElementList(20, true); - fNsStack = new StrList(); - fTypeStack = new StrList(); - fFromStack = new StrList(); - fRoster = new RosterList(20, true); - fAgents = new AgentList(20, true); - - fParser = XML_ParserCreate(NULL); - XML_SetUserData(fParser, this); - XML_SetElementHandler(fParser, StartElement, EndElement); - XML_SetCharacterDataHandler(fParser, Characters); -} - - -void -JabberHandler::Dispose() -{ - if (fParser) { - XML_ParserFree(fParser); - fParser = NULL; - } - - if (fElementStack) { - delete fElementStack; - fElementStack = NULL; - } - - if (fNsStack) { - delete fNsStack; - fNsStack = NULL; - } - - if (fTypeStack) { - delete fTypeStack; - fTypeStack = NULL; - } - - if (fFromStack) { - delete fFromStack; - fFromStack = NULL; - } - - if (fRoster) { - delete fRoster; - fRoster = NULL; - } - - if (fAgents) { - delete fAgents; - fAgents = NULL; - } -} - - -JabberHandler::~JabberHandler() -{ - Dispose(); -} - - -void -JabberHandler::UpdateJid() -{ - fJid = ""; - fJid << fUsername << "@" << fHost; -} - - -BString -JabberHandler::GetJid() const -{ - return fJid; -} - - -void -JabberHandler::SetHost(const BString & host) -{ - fHost = host; - UpdateJid(); -} - - -void -JabberHandler::SetUsername(const BString& username) -{ - fUsername = username; - UpdateJid(); -} - - -void -JabberHandler::SetPassword(const BString& password) -{ - fPassword = password; -} - - -void -JabberHandler::SetPort(int32 port) -{ - fPort = port; -} - - -void -JabberHandler::SetPriority(int32 priority) -{ - fPriority = priority; -} - - -void -JabberHandler::SetResource(const BString& resource) -{ - fResource = resource; -} - - -BString -JabberHandler::GetName() const -{ - return fUsername; -} - - -bool -JabberHandler::SendMessage(JabberMessage& message) -{ - BString body = message.GetBody(); - body.ReplaceAll("&", "&"); - body.ReplaceAll("<", "<"); - body.ReplaceAll(">", ">"); - body.ReplaceAll("\'", "'"); - body.ReplaceAll("\"", """); - - BString xml; - xml << "" << body << ""; - xml << ""; - xml << ""; - - Send(xml); - return true; -} - - -void -JabberHandler::SetOwnNickname(const BString& nick) -{ - // See http://xmpp.org/extensions/xep-0172.html, - // look at 4.5 nickname management - BString xml; - xml << ""; - xml << ""; - xml << ""; - xml << ""; - xml << nick << ""; - xml << ""; - Send(xml); -} - - -bool -JabberHandler::StartComposingMessage(JabberContact* contact) -{ - if (contact->GetLastMessageID().ICompare("") == 0) - return false; //?? no need to send notification - - // Send a composing event - BString xml; - xml << ""; - if (contact->GetLastMessageID() != "") - xml << "" << contact->GetLastMessageID() << ""; - xml << ""; - Send(xml); - - return true; -} - - -bool -JabberHandler::StopComposingMessage(JabberContact* contact) -{ - // Send a composing event - BString xml; - xml << ""; - xml << ""; - xml << ""; - Send(xml); - - return true; -} - - -void -JabberHandler::AddContact(const BString& name, const BString& jid, const BString& group) -{ - BString xml; - xml << ""; - xml << ""; - xml << "" << group << ""; - xml << ""; - xml << "I would like to add you to my roster."; - Send(xml); -} - - -void -JabberHandler::RemoveContact(const JabberContact* contact) -{ - BString xml; - xml << ""; - xml << " "; - xml << ""; - Send(xml); -} - - -void -JabberHandler::AcceptSubscription(const BString& jid) -{ - BString xml; - xml << ""; - Send(xml); -} - - -void -JabberHandler::SetStatus(int32 status, const BString& message) -{ - BString xml; - xml << ""; - break; - case S_OFFLINE: - xml << " type='unavailable'>"; - break; - case S_AWAY: - xml << ">away"; - break; - case S_XA: - xml << ">xa"; - break; - case S_DND: - xml << ">dnd"; - break; - case S_CHAT: - xml << ">chat"; - break; - default: - return; - } - - if (message != "") - xml << "" << message << ""; - - // Aha, fix the priority now as well :) - xml << "" << fPriority << ""; - - if (!fAuthorized) - LogOn(); - - Send(xml); - - if (status == S_OFFLINE) - LogOff(); -} - - -void -JabberHandler::LogOff() -{ - EndSession(); - fAuthorized = false; - Disconnected(""); -} - - - - -bool -JabberHandler::IsAuthorized() -{ - return fAuthorized; -} - - -void -JabberHandler::LogOn() -{ - if (fUsername != "" && fPassword != "" && fPort && fHost != "") { - // socket 0 is quite valid - if (fSocket < 0) - BeginSession(); - Authorize(); - } -} - - -void -JabberHandler::Register(JabberAgent* agent) -{ - BString xml; - xml << ""; - xml << ""; - xml << ""; - Send(xml); -} - - -void -JabberHandler::Register(JabberRegistration* registration) -{ - JabberRegistration::FieldList* fields = registration->GetFields(); - //const BList* fields = pRegistration->GetFields(); - - BString xml; - xml << ""; - xml << ""; - - JabberRegistration::FieldList::iterator i; - for (i = fields->begin(); i != fields->end(); i++) { - JabberRegistration::FieldPair pair = (*i); - if (pair.first != "" && pair.second != "") - xml << "<" << pair.first << ">" << pair.second << ""; - else if (pair.first != "") - xml << "<" << pair.first << "/>"; - } - xml << ""; - - Send(xml); - return; -} - - -int32 -JabberHandler::ReceivedData(const char* data, int32 length) -{ - if (length > 0) { - if (!XML_Parse(fParser, data, length, 0)) - logmsg("Parse failed!"); - } else { - if (IsAuthorized()) - Disconnected("Connection lost!"); - else - Disconnected(""); - - fAuthorized = false; - fSocket = -1; - CleanUpEnvirorment(); - } - return 0; -} - - -void -JabberHandler::Send(const BString& xml) -{ - if (fPlug->Send(xml) < 0) - Disconnected("Could not send"); -} - - -void -JabberHandler::Authorize() -{ - // http://xmpp.org/extensions/xep-0078.html - - CSHA1 sha1; - char shaPassword[256]; - - BString concatenad(fCurrentPresenceId); - concatenad << fPassword; - - sha1.Reset(); - sha1.Update((unsigned char*)concatenad.String(), concatenad.Length()); - sha1.Final(); - sha1.ReportHash(shaPassword, CSHA1::REPORT_HEX); - fLastAuthId << "auth" << fIncrementalId; - fIncrementalId++; - BString xml; - xml << ""; - xml << ""; - xml << "" << fUsername << ""; - xml << "" << fPassword << ""; - xml << "" << shaPassword << ""; // Error encoding the password?? - xml << "" << fResource << ""; - xml << ""; - xml << ""; - Send(xml); -} - - -bool -JabberHandler::BeginSession() -{ - BString xml; - - if (fUsername == "" || fHost == "" || fPassword == "" || fPort <= 0) - return false; - - fSocket = fPlug->StartConnection(fHost, fPort, this); - if (fSocket >= 0) { - xml << "\n"; - Send(xml); - return true; - } else { - logmsg("Failed to connect!"); - Disconnected("Failed to connect to host."); - return false; - } - - return false; -} - - -void -JabberHandler::EndSession() -{ - if (fSocket >= 0) { - BString xml; - xml << "\n"; - Send(xml); - } - CleanUpEnvirorment(); -} - -void -JabberHandler::CleanUpEnvirorment() -{ - XML_ParserFree(fParser); - - fElementStack->MakeEmpty(); - fNsStack->clear(); - fTypeStack->clear(); - fFromStack->clear(); - fRoster->MakeEmpty(); - fAgents->MakeEmpty(); - - fParser = XML_ParserCreate(NULL); - XML_SetUserData(fParser, this); - XML_SetElementHandler(fParser, StartElement, EndElement); - XML_SetCharacterDataHandler(fParser, Characters); -} - - -void -JabberHandler::StartElement(void* pUserData, const char* pName, const char** pAttr) -{ - BString name(pName); - JabberHandler* handler = reinterpret_cast(pUserData); - - // Authorize in the beginning of the stream - if (name.ICompare("stream:stream") == 0) { - const char* currentId = handler->HasAttribute("id", pAttr); - handler->fCurrentPresenceId = BString(currentId); - return; - } - - if (name.ICompare("iq") == 0) { - const char* type = handler->HasAttribute("type", pAttr); - const char* id = handler->HasAttribute("id", pAttr); - const char* from = handler->HasAttribute("from", pAttr); - - if (type != NULL && id != NULL) { - if (strcmp(type, "result") == 0) { - if (handler->fLastAuthId.Compare(id) == 0) { - handler->fAuthorized = true; - handler->Authorized(); - } - } else if (strcmp(type, "error") == 0) { - if (handler->fLastAuthId.Compare(id) == 0) { - handler->fAuthorized = false; - handler->fSocket = -1; - handler->Disconnected("Error logging in!"); - } - } - - // Always save from and type attributes - handler->fFromStack->push_back(BString(from)); - handler->fTypeStack->push_back(BString(type)); - } - } - - JabberElement* element = new JabberElement(); - element->SetName(pName); - element->SetAttr(pAttr); - handler->fElementStack->AddItem(element); - - if (name.ICompare("query") == 0) { - const char* ns = handler->HasAttribute("xmlns", pAttr, element->GetAttrCount()); - if (ns) - handler->fNsStack->push_back(BString(ns)); - } -} - - -void -JabberHandler::EndElement(void* pUserData, const char* pName) -{ - BString name(pName); - JabberHandler* handler = (JabberHandler *)pUserData; - - JabberElement* element = handler->fElementStack->LastItem(); - if (element && element->GetName().ICompare("new_data") == 0) - element->SetName("data"); - - if (name.ICompare("message") == 0) { - JabberMessage* message = handler->BuildMessage(); - handler->Message(message); - } else if (name.ICompare("presence") == 0) { - JabberPresence* presence = handler->BuildPresence(); - - if (presence->GetType().ICompare("subscribe") == 0) - handler->SubscriptionRequest(presence); - else if (presence->GetType().ICompare("unsubscribe") == 0) - handler->Unsubscribe(presence); - else { - handler->Presence(presence); - handler->UpdateRoster(presence); - } - } else if (name.ICompare("query") == 0) { - if (handler->fNsStack->size() != 0) { - BString obj = *(handler->fNsStack->begin()); - handler->fNsStack->pop_front(); // removes first item - - if (!obj.ICompare("jabber:iq:roster")) { - handler->BuildRoster(); - handler->Roster(handler->fRoster); - } else if (!obj.ICompare("jabber:iq:version")) { - handler->SendVersion(); - } else if (!obj.ICompare("jabber:iq:agents")) { - handler->BuildAgents(); - handler->Agents(handler->fAgents); - } else if (!obj.ICompare("jabber:iq:register")) { - JabberRegistration * r = handler->BuildRegistration(); - handler->Registration(r); - delete r; - } - } - } else if (name.ICompare("vCard") == 0) { - BString type; - if (handler->fTypeStack->size() != 0) - type = *(handler->fTypeStack->begin()); - - BString from; - if (handler->fFromStack->size() != 0) - from = *(handler->fFromStack->begin()); - - if (type.ICompare("result") == 0) { - from.ToLower(); - JabberVCard* vCard = handler->BuildVCard(from); - - for (int32 i = 0; i < handler->fRoster->CountItems(); i++) { - JabberContact* contact = handler->fRoster->ItemAt(i); - if (contact->GetJid().ICompare(from) == 0) { - contact->SetVCard(vCard); - handler->fVCardManager->VCardReceived(contact); - } - } - - //support also receiving our own vCard - if (handler->GetJid().ICompare(from) == 0) { - // maybe we should also create an instance of JabberContact that represent 'me' - JabberContact contact; - contact.SetJid(handler->GetJid()); - contact.SetName(vCard->GetFullName()); - contact.SetVCard(vCard); - handler->fVCardManager->VCardReceived(&contact); - handler->OwnContactInfo(&contact); - - } - } - } else if (name.ICompare("iq") == 0) { - // Remove last type and from attributes from their stacks - if (handler->fTypeStack->size() != 0) - handler->fTypeStack->pop_front(); - if (handler->fFromStack->size() != 0) - handler->fFromStack->pop_front(); - } -} - - -void -JabberHandler::Characters(void* pUserData, const char* pString, int pLen) -{ - JabberHandler* handler = (JabberHandler *)pUserData; - JabberElement* element = handler->fElementStack->LastItem(); - - char tmpz[pLen + 1]; - memcpy(tmpz, pString, pLen); - tmpz[pLen] = 0; - - if (!element || element->GetName().ICompare("new_data") != 0) { - if (pLen == 1 && (pString[0] == '\n' || pString[0] == 9 || pString[0] == 32)) - return; - element = new JabberElement(); - element->SetName("new_data"); - element->SetData(tmpz); - handler->fElementStack->AddItem(element); - } else if (element->GetName().ICompare("new_data") == 0) { - BString tmp; - tmp << element->GetData().String() << tmpz ; - element->SetData(tmp.String()); - } -} - - -/************************************************ - * Builds a message from the element stack - ************************************************/ -JabberMessage* -JabberHandler::BuildMessage() -{ - // http://xmpp.org/extensions/xep-0184.html - JabberMessage* message = new JabberMessage(); - JabberElement* element = fElementStack->RemoveItemAt(fElementStack->CountItems() - 1); - JabberElement* previous = NULL; - StrList data; - - while (element->GetName().ICompare("message") != 0) { - if (element->GetName().ICompare("body") == 0) { - if (previous != 0 && previous->GetName().ICompare("data") == 0) - message->SetBody(previous->GetData()); - } else if (element->GetName().ICompare("error") == 0) { - if (previous != 0 && previous->GetName().ICompare("data") == 0) - message->SetError(previous->GetData()); - } else if (element->GetName().ICompare("x") == 0) { - BString xmlns(HasAttribute("xmlns", element->GetAttr(), - element->GetAttrCount())); - message->SetX(xmlns); - - if (previous != 0) { - if (previous->GetName().ICompare("composing") == 0) - message->SetX("composing"); - else { - // old olmeki compatibily.. - if (previous->GetName().ICompare("data") == 0) { - if (previous->GetData().ICompare("Offline Storage") == 0) - message->SetOffline(true); - } - } - } - } - - if (previous) - delete previous; - - previous = element; - element = fElementStack->RemoveItemAt(fElementStack->CountItems() - 1); - } - - BString from(HasAttribute("from", - element->GetAttr(),element->GetAttrCount())); - message->SetID(HasAttribute("id", - element->GetAttr(),element->GetAttrCount())); - message->SetType(HasAttribute("type", - element->GetAttr(),element->GetAttrCount())); - - from.ToLower(); //xeD: jid always low case to avoid confusion. - StripResource(from); - message->SetFrom(from); - message->SetTo(GetJid()); - if (message->GetStamp() == "") - TimeStamp(*message); - - delete previous; - delete element; - - return message; -} - -/************************************************************ - * Builds and/or updates the roster from elements on stack - ************************************************************/ -JabberHandler::RosterList * -JabberHandler::BuildRoster() -{ - // http://xmpp.org/extensions/xep-0147.html#actions-roster - JabberContact* contact = NULL; - JabberElement* element = fElementStack->RemoveItemAt(fElementStack->CountItems() - 1); - JabberElement* previous = NULL; - - while (element->GetName().ICompare("query") != 0) { - contact = new JabberContact(); - while (element->GetName().ICompare("item") != 0) { - if (element->GetName().ICompare("group") == 0 && previous && - previous->GetName().ICompare("data") == 0) - contact->SetGroup(previous->GetData()); - - if (previous) - delete previous; - - previous = element; - element = fElementStack->RemoveItemAt(fElementStack->CountItems() - 1); - } - - BString jid(HasAttribute("jid", element->GetAttr(),element->GetAttrCount())); - StripResource(jid); - jid.ToLower(); //xeD: jid always low case to avoid confusion. - contact->SetJid(jid); - contact->SetSubscription(HasAttribute("subscription", element->GetAttr(),element->GetAttrCount())); - - const char * tmpValue; - tmpValue = HasAttribute("name", element->GetAttr(),element->GetAttrCount()); - tmpValue != NULL ? contact->SetName(tmpValue) : contact->SetName(contact->GetJid()); - - if (contact->GetGroup() == NULL) { - const JabberAgent * agent = IsAgent(contact->GetJid()); - if (agent) { - contact->SetGroup("Transports"); - contact->SetName(agent->GetName()); - } else if (contact->GetSubscription() == "" || - contact->GetSubscription().ICompare("from") == 0) - contact->SetGroup("Unsubscribed"); - else - contact->SetGroup("Unsorted"); - } - - UpdateRoster(contact); - - if (previous) - delete previous; - previous = element; - element = fElementStack->RemoveItemAt(fElementStack->CountItems() - 1); - } - - delete element; - delete previous; - - return fRoster; -} - -/****************************************************************** - * Builds a nice little precense object from the elements on stack - ******************************************************************/ -JabberPresence* -JabberHandler::BuildPresence() -{ - // http://xmpp.org/rfcs/rfc3921.html#rfc.section.2.2 - JabberElement* element = fElementStack->RemoveItemAt(fElementStack->CountItems() - 1); - JabberElement* previous = 0; - JabberPresence* presence = new JabberPresence(); - - presence->SetShow(S_ONLINE); - while (element->GetName().ICompare("presence") != 0) { - if (element->GetName().ICompare("show") == 0) { - if (previous != NULL && previous->GetName().ICompare("data") == 0) - presence->SetShowFromString(previous->GetData()); - } else if (element->GetName().ICompare("status") == 0) { - if (previous != NULL && previous->GetName().ICompare("data") == 0) - presence->SetStatus(previous->GetData()); - } else if (element->GetName().ICompare("photo") == 0) { - if (previous != NULL && previous->GetName().ICompare("data") == 0) - presence->SetPhotoSHA1(previous->GetData()); - } - if (previous) - delete previous; - - previous = element; - element = fElementStack->RemoveItemAt(fElementStack->CountItems() - 1); - } - - BString from(HasAttribute("from", - element->GetAttr(),element->GetAttrCount())); - from.ToLower(); //xeD: jid always low case to avoid confusion. - presence->ParseFrom(from); - presence->SetType(HasAttribute("type", - element->GetAttr(),element->GetAttrCount())); - - fVCardManager->RefinePresence(presence); - - delete previous; - delete element; - - return presence; -} - -/****************************************************************** - * Builds a list of available agents on the server, this is called - * as a respond to the RequestAgents() - *****************************************************************/ -JabberHandler::AgentList* -JabberHandler::BuildAgents() -{ - // http://xmpp.org/extensions/xep-0094.html - JabberAgent* agent; - JabberElement* element = fElementStack->RemoveItemAt(fElementStack->CountItems() - 1); - JabberElement* previous = NULL; - - while (element->GetName().ICompare("query") != 0) { - agent = new JabberAgent(); - while (element->GetName().ICompare("agent") != 0) { - if (element->GetName().ICompare("service") == 0 && - previous->GetName().ICompare("data") == 0) - agent->SetService(previous->GetData()); - - if (element->GetName().ICompare("name") == 0 && - previous->GetName().ICompare("data") == 0) - agent->SetName(previous->GetData()); - - if (element->GetName().ICompare("groupchat")) - agent->SetGroupChat(true); - - if (element->GetName().ICompare("search")) - agent->SetSearchable(true); - - if (element->GetName().ICompare("transport")) - agent->SetTransport(true); - - if (element->GetName().ICompare("register")) - agent->SetRegistration(true); - - if (previous) - delete previous; - - previous = element; - element = fElementStack->RemoveItemAt(fElementStack->CountItems() - 1); - } - - BString jid(HasAttribute("jid", element->GetAttr(), element->GetAttrCount())); - jid.ToLower(); //xeD: jid always low case to avoid confusion. - agent->SetJid(jid); - - fAgents->AddItem(agent); - - if (previous) - delete previous; - - previous = element; - element = fElementStack->RemoveItemAt(fElementStack->CountItems() - 1); - } - - delete element; - delete previous; - - return fAgents; -} - -/********************************************************* - * Builds a JabberRegistration object from elements on the - * element stack - *********************************************************/ -JabberRegistration* -JabberHandler::BuildRegistration() -{ - // http://xmpp.org/extensions/xep-0077.html - JabberElement* element = fElementStack->RemoveItemAt(fElementStack->CountItems() - 1); - JabberElement* previous = NULL; - JabberRegistration* registration = new JabberRegistration(); - - while (element->GetName().ICompare("query") != 0) { - if (element->GetName().ICompare("instructions") == 0) { - if (previous != NULL && previous->GetName().ICompare("data") == 0) - registration->SetInstructions(previous->GetData()); - } else if(element->GetName().ICompare("data") != 0) { - if (previous != NULL && previous->GetName().ICompare("data") == 0) - registration->SetFieldValue(element->GetName().String(), - previous->GetData().String(), true); - else - registration->AddField(element->GetName(), ""); // no value - } - - if (previous) - delete previous; - - previous = element; - element = fElementStack->RemoveItemAt(fElementStack->CountItems() - 1); - } - - delete element; - - // TODO: what if CountItems() == 0? :) This applies to all uses of CountItems() - // It will crash RemoveItem() (passing a -1) - element = fElementStack->RemoveItemAt(fElementStack->CountItems() - 1); - BString jid(HasAttribute("from", element->GetAttr())); - jid.ToLower(); //xeD: jid always low case to avoid confusion. - registration->SetJid(jid); - - delete previous; - delete element; - - return registration; -} - - -/********************************************************* - * Builds a JabberRegistration object from elements on the - * element stack - *********************************************************/ -JabberVCard* -JabberHandler::BuildVCard(const BString& from) -{ - // http://xmpp.org/extensions/xep-0054.html#sect-id2251780 - JabberVCard* vCard = new JabberVCard(); - JabberElement* element = fElementStack->RemoveItemAt(fElementStack->CountItems() - 1); - JabberElement* previous = NULL; - - while (element->GetName().ICompare("vCard") != 0) { - if (element->GetName().ICompare("FN") == 0) { - if (previous && previous->GetName().ICompare("data") == 0) - vCard->SetFullName(previous->GetData()); - } else if (element->GetName().ICompare("GIVEN") == 0) { - if (previous && previous->GetName().ICompare("data") == 0) - vCard->SetGivenName(previous->GetData()); - } else if (element->GetName().ICompare("FAMILY") == 0) { - if (previous && previous->GetName().ICompare("data") == 0) - vCard->SetFamilyName(previous->GetData()); - } else if (element->GetName().ICompare("MIDDLE") == 0) { - if (previous && previous->GetName().ICompare("data") == 0) - vCard->SetMiddleName(previous->GetData()); - } else if (element->GetName().ICompare("NICKNAME") == 0) { - if (previous && previous->GetName().ICompare("data") == 0) - vCard->SetNickname(previous->GetData()); - } else if (element->GetName().ICompare("EMAIL") == 0) { - if (previous && previous->GetName().ICompare("data") == 0) - vCard->SetEmail(previous->GetData()); - } else if (element->GetName().ICompare("URL") == 0) { - if (previous && previous->GetName().ICompare("data") == 0) - vCard->SetURL(previous->GetData()); - } else if (element->GetName().ICompare("BDAY") == 0) { - if (previous && previous->GetName().ICompare("data") == 0) - vCard->SetBirthday(previous->GetData()); - } else { - // Handle PHOTO childs - if (element->GetName().ICompare("EXTVAL") == 0) { - // Got a URI to an external content - // TODO: - } else { - if (element->GetName().ICompare("TYPE") == 0) { - if (previous && previous->GetName().ICompare("data") == 0) - vCard->SetPhotoMimeType(previous->GetData()); - } else if (element->GetName().ICompare("BINVAL") == 0) { - if (previous && previous->GetName().ICompare("data") == 0) - vCard->SetPhotoContent(previous->GetData()); - } - } - } - - if (previous) - delete previous; - - previous = element; - element = fElementStack->RemoveItemAt(fElementStack->CountItems() - 1); - } - - vCard->ParseFrom(from); - logmsg("got vcard from %s: %s", from.String(), vCard->GetFullName().String()); - - - delete previous; - delete element; - - return vCard; -} - - -void -JabberHandler::SendVersion() -{ -} - - -void -JabberHandler::RequestRoster() -{ - BString xml; - xml << ""; - Send(xml); -} - - -void -JabberHandler::RequestAgents() -{ - BString xml; - xml << ""; - xml << ""; - xml << ""; - Send(xml); -} - - -void -JabberHandler::RequestSelfVCard() -{ - // http://xmpp.org/extensions/xep-0054.html#sect-id2251582 - // TODO -} - -void -JabberHandler::RequestVCard(const BString & jid) -{ - // http://xmpp.org/extensions/xep-0054.html#sect-id2251780 - BString xml; - xml << ""; - Send(xml); -} - - -void -JabberHandler::RequestVCard(JabberContact* contact) -{ - // Ignore NULL contact - if (!contact) - return; - - RequestVCard(contact->GetJid()); -} - - -void -JabberHandler::UpdateRoster(JabberPresence* presence) -{ - // filter out from roster ourself - if (presence->GetJid().Compare(GetJid()) == 0) - return; - - JabberContact* contact; - int size = fRoster->CountItems(); - - for (int i = 0; i < size; i++) { - contact = fRoster->ItemAt(i); - - if (presence->GetJid().ICompare(contact->GetJid()) == 0) { - contact->SetPresence(presence); - return; - } - } - - contact = new JabberContact(); - contact->SetJid(presence->GetJid()); - contact->SetName(presence->GetJid()); - contact->SetPresence(presence); - fRoster->AddItem(contact); - //xeD: commeting this: RequestVCard(contact); -} - - -void -JabberHandler::UpdateRoster(JabberContact* contact) -{ - // filter out from roster ourself - if (contact->GetJid().Compare(GetJid()) == 0) - return; - - JabberContact* current; - int size = fRoster->CountItems(); - - for (int i = 0; i < size; i++) { - current = fRoster->ItemAt(i); - - if (contact->GetJid().ICompare(current->GetJid()) == 0) { - current->SetName(contact->GetName()); - current->SetGroup(contact->GetGroup()); - - if (contact->GetSubscription() == "remove") { - fRoster->RemoveItem(current); - //delete current; - delete contact; - return; - } else if (contact->GetSubscription() != "") - current->SetSubscription(contact->GetSubscription()); - - delete contact; - return; - } - } - - fRoster->AddItem(contact); - //xeD: commeting this: RequestVCard(contact); -} - - -/********************* - * Utility methods - *********************/ -const JabberAgent* -JabberHandler::IsAgent(const BString& jid) -{ - JabberAgent* agent; - int32 nbrAgents = fAgents->CountItems(); - - for (int32 i = 0; i < nbrAgents; i++) { - agent = fAgents->ItemAt(i); - if (jid.ICompare(agent->GetJid()) == 0) - return agent; - } - - return NULL; -} - - -void -JabberHandler::TimeStamp(JabberMessage& message) -{ - BString tmp; - BString timeString; - - time_t currentTime = time(NULL); - struct tm * t = localtime(¤tTime); - - timeString << (t->tm_year + 1900); - TwoDigit(t->tm_mon, timeString); - TwoDigit(t->tm_mday, timeString); - timeString << "T"; - TwoDigit(t->tm_hour, timeString); - timeString << ":"; - TwoDigit(t->tm_min, timeString); - timeString << ":"; - TwoDigit(t->tm_sec, timeString); - - message.SetStamp(timeString); -} - - -BString -JabberHandler::TwoDigit(int32 number, BString& string) -{ - if(number < 10) - string << "0" << number; - else - string << number; - - return string; -} - - -const char* -JabberHandler::HasAttribute(const char* pName, const char** pAttributes, int32 count) -{ - for (int32 i = 0; i < count; i += 2) { - if (strcmp(pAttributes[i], pName) == 0) - return pAttributes[i + 1]; - } - - return NULL; -} - - -const char * -JabberHandler::HasAttribute(const char* pName, const char** pAttributes) -{ - for (int32 i = 0; pAttributes[i]; i += 2) { - if (strcmp(pAttributes[i], pName) == 0) - return pAttributes[i + 1]; - } - - return NULL; -} - - -void -JabberHandler::StripResource(BString& jid) -{ - int i = jid.FindFirst('/'); - if (i != -1) - jid.Remove(i, jid.Length() - i); -} - - -/*********************************** - * Callbacks - ***********************************/ - - -void -JabberHandler::Authorized() -{ - /* - * Important that we get the list of agents first so that we - * can add agents in the roster to a certain group - */ - RequestAgents(); - RequestRoster(); -} diff --git a/libs/libjabber/JabberHandler.h b/libs/libjabber/JabberHandler.h deleted file mode 100644 index 82101dc..0000000 --- a/libs/libjabber/JabberHandler.h +++ /dev/null @@ -1,171 +0,0 @@ -/* - * Copyright 2002, The Olmeki Team. - * Distributed under the terms of the Olmeki License. - */ - -#ifndef _JABBER_HANDLER_H -#define _JABBER_HANDLER_H - -#include - -#include - -#include "ObjectList.h" - -#include - -#include "JabberAgent.h" -#include "JabberContact.h" -#include "JabberElement.h" -#include "JabberMessage.h" -#include "JabberPresence.h" -#include "JabberRegistration.h" -#include "JabberVCard.h" -#include "JabberPlug.h" - -class VCardManager; - -class JabberHandler { -public: - JabberHandler(const BString & name, JabberPlug*); - virtual ~JabberHandler(); - void Dispose(); - void LogOn(); - void LogOff(); - - //void Register(); - void Register(JabberRegistration * registration); - void Register(JabberAgent * agent); - - BString GetName() const; - - void SetHost(const BString & host); - void SetUsername(const BString & username); - void SetPassword(const BString & password); - void SetPort(int32 port); - void SetPriority(int32 priority); - void SetResource(const BString & resource); - - void UpdateJid(); - BString GetJid() const; - - bool IsAuthorized(); - void RemoveContact(const JabberContact * contact); - - int32 ReceivedData(const char *,int32); - -protected: - typedef BObjectList ElementList; - typedef std::list StrList; - typedef BObjectList RosterList; - typedef BObjectList AgentList; - - bool SendMessage(JabberMessage & message); - - void SetOwnNickname(const BString& nick); - - bool StartComposingMessage(JabberContact * contact); - bool StopComposingMessage(JabberContact * contact); - - void SetStatus(int32 status, const BString & message); - - void TimeStamp(JabberMessage & message); - - void AddContact(const BString & name, const BString & jid, const BString & group); - void AcceptSubscription(const BString & jid); - void UpdateRoster(JabberPresence * presence); - - // The JabberHandler takes ownership of the contact - void UpdateRoster(JabberContact * contact); - // by xeD - RosterList* getRosterList(){ return fRoster; }; - - //Callbacks - virtual void Authorized(); - virtual void Message(JabberMessage * message)=0; - virtual void Presence(JabberPresence * presence) =0; - virtual void Roster(RosterList * roster) =0; - virtual void Agents(AgentList * agents) =0; - virtual void Disconnected(const BString & reason) = 0; - virtual void SubscriptionRequest(JabberPresence * presence) = 0; - virtual void Registration(JabberRegistration * registration) = 0; - virtual void Unsubscribe(JabberPresence * presence) = 0; - virtual void OwnContactInfo(JabberContact* contact) = 0; -protected: -friend class VCardManager; - virtual void GotBuddyPhoto(const BString & jid, const BString & imagePath) = 0; - -private: - enum ID { - AUTH = 0, - ROSTER = 2 - }; - - BString fHost; - BString fUsername; - BString fJid; - BString fPassword; - int32 fPort; - BString fResource; - int32 fPriority; - - ElementList* fElementStack; - StrList* fNsStack; - StrList* fTypeStack; - StrList* fFromStack; - RosterList* fRoster; - AgentList* fAgents; - - int32 fSocket; - JabberPlug* fPlug; - - XML_Parser fParser; - bool fAuthorized; - - VCardManager* fVCardManager; - - BString fCurrentPresenceId; - BString fLastAuthId; - int32 fIncrementalId; - -//protected: -public: -//friend class VCardManager; - void RequestVCard(const BString & jid); - -protected: - void Send(const BString & xml); - void Authorize(); - bool BeginSession(); - void EndSession(); - void SendVersion(); - void RequestRoster(); - void RequestAgents(); - void RequestSelfVCard(); - void RequestVCard(JabberContact* contact); - - JabberMessage* BuildMessage(); - JabberPresence* BuildPresence(); - RosterList * BuildRoster(); - AgentList * BuildAgents(); - JabberRegistration* BuildRegistration(); - JabberVCard* BuildVCard(const BString& from); - - //int32 GetConnection(); - const JabberAgent* IsAgent(const BString & jid); - const char* HasAttribute(const char* name, const char** attributes, int32 count); - const char* HasAttribute(const char* name, const char** attributes); - - void StripResource(BString & jid); - BString TwoDigit(int32, BString &); - - static void StartElement(void* pUserData, const char* pName, const char** pAttr); - static void EndElement(void* pUserData, const char* pName); - static void Characters(void* pUserData, const char* pString, int pLen); - -private: - void CleanUpEnvirorment(); - -}; - -#endif // _JABBER_HANDLER_H diff --git a/libs/libjabber/JabberManager.h b/libs/libjabber/JabberManager.h deleted file mode 100644 index 691343a..0000000 --- a/libs/libjabber/JabberManager.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2009, Andrea Anzani. All rights reserved. - * Distributed under the terms of the MIT License. - */ -#ifndef Jabber_MANAGER_H -#define Jabber_MANAGER_H - -#include -#include - -#include "CayaConstants.h" - -/** - -*/ - -class JabberManager -{ - public: - // who can be NULL if it's a general message - virtual void Error( const char * message, const char * who )=0; - - virtual void GotMessage( const char * from, const char * msg )=0; - virtual void MessageSent( const char * to, const char * msg )=0; - - virtual void LoggedIn()=0; - virtual void SetAway(bool)=0; - virtual void LoggedOut()=0; - - //virtual void GotBuddyList( list & )=0; - virtual void BuddyStatusChanged( const char * who, CayaStatus status )=0; -}; - -#endif diff --git a/libs/libjabber/JabberMessage.cpp b/libs/libjabber/JabberMessage.cpp deleted file mode 100644 index 6c2e110..0000000 --- a/libs/libjabber/JabberMessage.cpp +++ /dev/null @@ -1,124 +0,0 @@ -#include "JabberMessage.h" -#include "Logger.h" - -JabberMessage::JabberMessage() -{ - fTo = ""; - fFrom = ""; - fBody = ""; - fStamp = ""; - fId = ""; - fOffline= false; - fType=""; - fError=""; - fX=""; -} - -JabberMessage::JabberMessage(const JabberMessage & copy) -{ - fTo = copy.fTo; - fFrom = copy.fFrom; - fBody = copy.fBody; - fStamp = copy.fStamp; - fOffline= copy.fOffline; - fId = copy.fId; - fType=copy.fType; - fError=copy.fError; - fX=copy.fX; -} - -void -JabberMessage::PrintToStream() -{ - logmsg(" ** JabberMessage **"); - logmsg(" To: %s",fTo.String()); - logmsg(" Id: %s",fId.String()); - logmsg(" From: %s",fFrom.String()); - logmsg(" Body: %s",fBody.String()); - logmsg(" Stamp: %s",fStamp.String()); - logmsg(" Type: %s",fType.String()); - logmsg(" Error: %s",fError.String()); - logmsg(" X: %s",fX.String()); -} - - -JabberMessage::~JabberMessage() -{ -} - -void -JabberMessage::operator=(const JabberMessage & copy) -{ - fTo = copy.fTo; - fFrom = copy.fFrom; - fBody = copy.fBody; - fStamp = copy.fStamp; - fOffline= copy.fOffline; - fId = copy.fId; - fType=copy.fType; - fError=copy.fError; - fX=copy.fX; -} - -BString -JabberMessage::GetFrom() const -{ - return fFrom; -} - -BString -JabberMessage::GetTo() const -{ - return fTo; -} - -BString -JabberMessage::GetBody() const -{ - return fBody; -} - -BString -JabberMessage::GetStamp() const -{ - return fStamp; -} - -BString -JabberMessage::GetID() const -{ - return fId; -} -void -JabberMessage::SetFrom(const BString & from) -{ - fFrom = from; -} - -void -JabberMessage::SetTo(const BString & to) -{ - fTo = to; -} - -void -JabberMessage::SetBody(const BString & body) -{ - fBody = body; -} - -void -JabberMessage::SetStamp(const BString & stamp) -{ - fStamp = stamp; -} -void -JabberMessage::SetID(const BString & id) -{ - fId = id; -} -void -JabberMessage::SetOffline(const bool b) -{ - fOffline = b; -} diff --git a/libs/libjabber/JabberMessage.h b/libs/libjabber/JabberMessage.h deleted file mode 100644 index f580e3d..0000000 --- a/libs/libjabber/JabberMessage.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef JABBER_MESSAGE_H -#define JABBER_MESSAGE_H - -#include - -class JabberMessage -{ -public: - JabberMessage(); - JabberMessage(const JabberMessage &); - ~JabberMessage(); - - void operator=(const JabberMessage &); - - BString GetFrom() const; - BString GetTo() const; - BString GetBody() const; - BString GetStamp() const; - BString GetID() const; - BString GetType() const { return fType; }; //by xeD - BString GetError() const { return fError; }; //by xeD - bool GetOffline() const { return fOffline; } - BString GetX(){ return fX;} - - void SetType(const BString & type){ fType=type; } //by xeD; - void SetError(const BString & err){ fError=err; } //by xeD; - void SetFrom(const BString & from); - void SetTo(const BString & from); - void SetBody(const BString & body); - void SetStamp(const BString & stamp); - void SetID(const BString & id); - void SetOffline(const bool b); - void SetX(const BString & x){ fX=x; } - void PrintToStream(); -private: - BString fFrom; - BString fTo; - BString fBody; - BString fStamp; - BString fId; // by xeD - BString fType; // by xeD (chat,error,..) - BString fError; // error message incluided? - BString fX; // ? FIX! - bool fOffline; -}; - - -#endif diff --git a/libs/libjabber/JabberPlug.h b/libs/libjabber/JabberPlug.h deleted file mode 100644 index 2718a37..0000000 --- a/libs/libjabber/JabberPlug.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - Interface for a highlivel connection class - - basic implementations: - JabberSSLPlug (new code used by GoogleTalk) - JabberSocketPLug (old code BONE/net_server) - - 22 sept. 2005 by Andrea Anzani (andrea@tenar.it) -*/ -#ifndef JabberPlug_H_ -#define JabberPlug_H_ -#include - -class JabberPlug { - - public: - virtual ~JabberPlug() {}; - //private: - - virtual int StartConnection(BString fHost, int32 fPort,void*) = 0;//if >= 0 it's ok. - virtual int Send(const BString & xml) = 0; //if >= 0 it's ok. - virtual int StopConnection() = 0; -}; - -#endif -//. diff --git a/libs/libjabber/JabberPresence.cpp b/libs/libjabber/JabberPresence.cpp deleted file mode 100644 index df52075..0000000 --- a/libs/libjabber/JabberPresence.cpp +++ /dev/null @@ -1,179 +0,0 @@ -#include "JabberPresence.h" -#include "States.h" -#include "Logger.h" - -JabberPresence::JabberPresence() -{ - fStatus = ""; - fJid = ""; - fType = ""; - fShow = S_OFFLINE; - fResource = ""; -} -void -JabberPresence::PrintToStream() -{ - logmsg("\nJabberPresence"); - logmsg(" Status: %s",fStatus.String()); - logmsg(" Show: %ld",fShow); - logmsg(" Jid: %s",fJid.String()); - -} -JabberPresence::JabberPresence(const JabberPresence & copy) -{ - SetStatus(copy.GetStatus()); - SetJid(copy.GetJid()); - SetType(copy.GetType()); - SetResource(copy.GetResource()); - fShow = copy.GetShow(); -} - -JabberPresence::~JabberPresence() -{ -} - -void -JabberPresence::operator=(const JabberPresence & rhs) -{ - if (this == &rhs) - return; - - SetStatus(rhs.GetStatus()); - SetJid(rhs.GetJid()); - SetType(rhs.GetType()); - SetResource(rhs.GetResource()); - fShow = rhs.fShow; -} - -int32 -JabberPresence::GetShow() const -{ - return fShow; -} - -BString -JabberPresence::GetType() const -{ - return fType; -} - -BString -JabberPresence::GetStatus() const -{ - return fStatus; -} - -BString -JabberPresence::GetJid() const -{ - return fJid; -} - -BString -JabberPresence::GetResource() const -{ - return fResource; -} - -void -JabberPresence::SetShowFromString(const BString & show) -{ - if (show != "") - { - if (!show.ICompare("xa")) - fShow = S_XA; - else if (!show.ICompare("away")) - fShow = S_AWAY; - else if (!show.ICompare("dnd")) - fShow = S_DND; - else if (!show.ICompare("chat")) - fShow = S_CHAT; - } -} - -void -JabberPresence::SetShow(int32 show) -{ - switch(show) - { - case S_XA: - fShow = S_XA; - break; - case S_AWAY: - fShow = S_AWAY; - break; - case S_ONLINE: - fShow = S_ONLINE; - break; - default: - fShow = S_OFFLINE; - } -} - -void -JabberPresence::SetType(const BString & type) -{ - fType = type; - if(fType.ICompare("unavailable") == 0) - SetShow(S_OFFLINE); -} - -void -JabberPresence::SetStatus(const BString & status) -{ - fStatus = status; -} - -void -JabberPresence::SetJid(const BString & jid) -{ - fJid = jid; -} - -void -JabberPresence::SetResource(const BString & resource) -{ - fResource = resource; -} - -void -JabberPresence::ParseFrom(const BString & from) -{ - fJid = ""; - fResource = ""; - - int32 i = from.FindFirst('/'); - if (i != -1) - { - from.CopyInto(fJid, 0, i); - from.CopyInto(fResource, i + 1, from.Length()); - } - else - { - fJid = from; - } -} - -BString -JabberPresence::GetPhotoSHA1() const -{ - return fPhotoSHA1; -} - -BString -JabberPresence::GetPhotoPath() const -{ - return fPhotoPath; -} - -void -JabberPresence::SetPhotoSHA1(const BString & sha1) -{ - fPhotoSHA1 = sha1; -} - -void -JabberPresence::SetPhotoPath(const BString & path) -{ - fPhotoPath = path; -} diff --git a/libs/libjabber/JabberPresence.h b/libs/libjabber/JabberPresence.h deleted file mode 100644 index b025a4c..0000000 --- a/libs/libjabber/JabberPresence.h +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef JABBER_PRESENCE_H -#define JABBER_PRESENCE_H - -#include - -class JabberPresence -{ -public: - JabberPresence(); - // Copy constructor - JabberPresence(const JabberPresence &); - ~JabberPresence(); - - void operator=(const JabberPresence & rhs); - - int32 GetShow() const; - BString GetType() const; - BString GetStatus() const; - BString GetJid() const; - BString GetResource() const; - - BString GetPhotoSHA1() const; - BString GetPhotoPath() const; - - void SetPhotoSHA1(const BString & sha1); - void SetPhotoPath(const BString & path); - - void SetShowFromString(const BString & show); - void SetShow(int32 show); - void SetType(const BString & type); - void SetStatus(const BString & status); - void SetJid(const BString & jid); - void SetResource(const BString & resource); - - void ParseFrom(const BString & from); - void PrintToStream(); -private: - BString fStatus; - BString fJid; - BString fType; - int32 fShow; - BString fResource; - BString fPhotoSHA1; - BString fPhotoPath; -}; - -#endif // JABBER_PRESENCE_H diff --git a/libs/libjabber/JabberRegistration.cpp b/libs/libjabber/JabberRegistration.cpp deleted file mode 100644 index 1ef9e7d..0000000 --- a/libs/libjabber/JabberRegistration.cpp +++ /dev/null @@ -1,111 +0,0 @@ -#include "JabberRegistration.h" -#include "Logger.h" - -JabberRegistration::JabberRegistration(const BString & jid, bool unRegister) -{ - fJid = jid; - fUnRegister = unRegister; - fInstructions = ""; - fFields = new FieldList; -} - -void -JabberRegistration::PrintToStream() -{ - logmsg(" ** JabberRegistration **"); - logmsg(" fJid: %s",fJid.String()); - logmsg(" fInstructions: %s",fInstructions.String()); - logmsg(" ** JabberRegistrationFields **"); - -} -JabberRegistration::~JabberRegistration() -{ - delete fFields; -} - -void -JabberRegistration::SetJid(const BString & jid) -{ - fJid = jid; -} - -void -JabberRegistration::SetInstructions(const BString & instructions) -{ - fInstructions = instructions; -} - -void -JabberRegistration::AddField(const BString & field, const BString & value) -{ - FieldPair p; - p.first = field; - p.second = value; - fFields->insert(p); - - logmsg("Field added %s %s",field.String(),value.String()); -} - -void -JabberRegistration::SetFieldValue(const BString & field, const BString & value, bool create) -{ - FieldList::iterator i = fFields->find(field); - if (i == fFields->end()) // not found? - { - if (create) - AddField(field, value); - return; - } - FieldPair pair = *i; - fFields->erase(i); - pair.second = value; - fFields->insert(pair); -} - -bool -JabberRegistration::GetFieldValue(const BString & fieldName, BString & ret) -{ - FieldList::iterator i = fFields->find(fieldName); - if (i != fFields->end()) - { - ret = (*i).second; - return true; - } - - return false; -} - -BString -JabberRegistration::GetJid() const -{ - return fJid; -} - -bool -JabberRegistration::UnRegister() const -{ - return fUnRegister; -} - -JabberRegistration::FieldList * -JabberRegistration::GetFields() const -{ - return fFields; -} - -BString -JabberRegistration::GetInstructions() const -{ - return fInstructions; -} - -bool -JabberRegistration::HasValues() const -{ - if (fFields->size() > 0) - { - if ((*(fFields->begin())).second != "") - return true; - } - return false; -} diff --git a/libs/libjabber/JabberRegistration.h b/libs/libjabber/JabberRegistration.h deleted file mode 100644 index bf7764a..0000000 --- a/libs/libjabber/JabberRegistration.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef JABBER_REGISTRATION_H -#define JABBER_REGISTRATION_H - -#include - -#include -using std::map; -using std::pair; - -class JabberRegistration -{ -public: - JabberRegistration(const BString & jid = "", bool unRegister = false); - ~JabberRegistration(); - - typedef map FieldList; - typedef pair FieldPair; - - FieldList* GetFields() const; - bool GetFieldValue(const BString & fieldName, BString & ret); - BString GetJid() const; - BString GetInstructions() const; - - bool UnRegister() const; - // Creates a field - void AddField(const BString & field, const BString & value); - //void AddFieldValue(const BString & value); - // Sets the value of an existant field - void SetFieldValue(const BString & field, const BString & value, bool create); - - void SetJid(const BString & jid); - void SetInstructions(const BString & instructions); - - bool HasValues() const; - - void PrintToStream(); - -private: - bool fUnRegister; - BString fJid; - BString fInstructions; - FieldList * fFields; -}; - - -#endif diff --git a/libs/libjabber/JabberSSLPlug.cpp b/libs/libjabber/JabberSSLPlug.cpp deleted file mode 100644 index 495649c..0000000 --- a/libs/libjabber/JabberSSLPlug.cpp +++ /dev/null @@ -1,188 +0,0 @@ -#include "JabberSSLPlug.h" -#include "JabberHandler.h" -#include "Logger.h" - -#define msnmsgPing 'ping' - -JabberSSLPlug::JabberSSLPlug(BString forceserver, int32 port){ - - bio = NULL; - ctx = NULL; - - ffServer = forceserver; - ffPort = port; - - Run(); - - fKeepAliveRunner = new BMessageRunner(BMessenger(NULL, (BLooper *)this), - new BMessage(msnmsgPing), 60000000, -1); - - /* Set up the library */ - SSL_library_init(); - ERR_load_BIO_strings(); - SSL_load_error_strings(); - OpenSSL_add_all_algorithms(); -} - - -JabberSSLPlug::~JabberSSLPlug(){ - - if ( fKeepAliveRunner) - delete fKeepAliveRunner; - if(bio != NULL && ctx !=NULL) StopConnection(); -} - -void -JabberSSLPlug::MessageReceived(BMessage* msg){ - - if(msg->what == msnmsgPing){ - Send(" "); - } - else - BLooper::MessageReceived(msg); - -} -int -JabberSSLPlug::StartConnection(BString fServer, int32 fPort,void* cookie){ - - StopConnection(); - - BString fHost; - - if(ffServer!="") - fHost << ffServer << ":" << ffPort; - else - fHost << fServer << ":" << fPort; - - logmsg("StartConnection to %s",fHost.String()); - - SSL * ssl; - int result = 0; - - /* Set up the SSL context */ - - ctx = SSL_CTX_new(SSLv23_client_method()); - - bio = BIO_new_ssl_connect(ctx); - - /* Set the SSL_MODE_AUTO_RETRY flag */ - - BIO_get_ssl(bio, & ssl); - SSL_set_mode(ssl, SSL_MODE_AUTO_RETRY); - - /* Create and setup the connection */ - - - BIO_set_conn_hostname(bio, fHost.String()); - - if(BIO_do_connect(bio) <= 0) - { - logmsg("Error attempting to connect"); - ERR_print_errors_fp(stderr); - BIO_free_all(bio); - SSL_CTX_free(ctx); - bio = NULL; - ctx = NULL; - result = -1; - } - - if (result != -1) - { - fCookie = cookie; - - fReceiverThread = spawn_thread (ReceiveData, "opensll receiver", B_LOW_PRIORITY, this); - - if (fReceiverThread != B_ERROR) - resume_thread(fReceiverThread); - else - { - logmsg("failed to resume the thread!"); - ERR_print_errors_fp(stderr); - BIO_free_all(bio); - SSL_CTX_free(ctx); - bio = NULL; - ctx = NULL; - result = -1; - } - } - - logmsg("DONE: StartConnection to %s",fHost.String()); - fStartConnectionStatus = result; - return result; -} - -/* static function called by the therad.*/ -int32 -JabberSSLPlug::ReceiveData(void * pHandler){ - - char data[1024]; - int length = 0; - JabberSSLPlug * plug = reinterpret_cast(pHandler); - - while (true) - { - - if ((length = (int)BIO_read(plug->bio, data, 1023) ) > 0) - { - data[length] = 0; - logmsg("SSLPlug<<\n%s", data); - } - else - { - if(!BIO_should_retry(plug->bio)) - { - //uhm really and error! - logmsg("SSLPlug ERROR READING! (maybe dropped connection?)"); - ERR_print_errors(plug->bio); - plug->ReceivedData(NULL, 0); - return 0; - } - } - plug->ReceivedData(data,length); - } - return 0; -} - -void -JabberSSLPlug::ReceivedData(const char* data, int32 len){ - JabberHandler * handler = reinterpret_cast(fCookie); - if(handler) - handler->ReceivedData(data,len); -} - - -int -JabberSSLPlug::Send(const BString & xml) -{ - if (fStartConnectionStatus == -1) - return 0; - - logmsg("SSLPlug>>\n%s", xml.String()); - return BIO_write(bio, xml.String(), xml.Length()); -} - -int -JabberSSLPlug::StopConnection() -{ - if(fReceiverThread) - { - //Thread Killing! - suspend_thread(fReceiverThread); - kill_thread(fReceiverThread); - } - - fReceiverThread=0; - fStartConnectionStatus = 0; - - BIO_free_all(bio); - SSL_CTX_free(ctx); - - bio = NULL; - ctx = NULL; - - return 0; -} - - -//-- - diff --git a/libs/libjabber/JabberSSLPlug.h b/libs/libjabber/JabberSSLPlug.h deleted file mode 100644 index 31e5514..0000000 --- a/libs/libjabber/JabberSSLPlug.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - - JabberSSLPlug (written for GoogleTalk compatibility) - - 22 sept. 2005 by Andrea Anzani (andrea@tenar.it) -*/ -#ifndef JabberSSLPlug_H_ -#define JabberSSLPlug_H_ - -#include "JabberPlug.h" - -#include -#include -#include - -#include - -#include -#include - -// public JabberPlug -class JabberSSLPlug : public BLooper, public JabberPlug { - - public: - JabberSSLPlug(BString forceserver=NULL,int32 port=0); - ~JabberSSLPlug(); - //private: - - int StartConnection(BString fHost, int32 fPort,void* cook);//if >= 0 it's ok. - static int32 ReceiveData(void *); //thread called function - int Send(const BString & xml); //if >= 0 it's ok. - int StopConnection(); - - void ReceivedData(const char* data, int32); - - void MessageReceived(BMessage* ); - private: - - - BIO* bio; - SSL_CTX* ctx; - - BString ffServer; - int32 ffPort; - volatile thread_id fReceiverThread; - void* fCookie; //FIX! - BMessageRunner* fKeepAliveRunner; - int fStartConnectionStatus; -}; - -#endif - -//-- diff --git a/libs/libjabber/JabberSocketPlug.cpp b/libs/libjabber/JabberSocketPlug.cpp deleted file mode 100644 index 1fc5c82..0000000 --- a/libs/libjabber/JabberSocketPlug.cpp +++ /dev/null @@ -1,187 +0,0 @@ -#include "JabberSocketPlug.h" -#include "Logger.h" - -#ifdef NETSERVER_BUILD -# include -# include -# include -#endif - -#ifdef BONE_BUILD -# include -# include -# include -# include -#endif - -#ifdef __HAIKU__ -# include -# include -# include -#endif - -#include "JabberHandler.h" - -JabberSocketPlug::JabberSocketPlug(){ - - fReceiverThread = -1; - fSocket = -1; - - #ifdef NETSERVER_BUILD - fEndpointLock = new BLocker(); - #endif -} - -JabberSocketPlug::~JabberSocketPlug(){ -} - -int -JabberSocketPlug::StartConnection(BString fHost, int32 fPort,void* cookie){ - - logmsg("StartConnection to %s:%ld",fHost.String(),fPort); - struct sockaddr_in remoteAddr; - remoteAddr.sin_family = AF_INET; - - -#ifdef BONE_BUILD - if (inet_aton(fHost.String(), &remoteAddr.sin_addr) == 0) -#elif NETSERVER_BUILD - if ((int)(remoteAddr.sin_addr.s_addr = inet_addr (fHost.String())) <= 0) -#endif - { - struct hostent * remoteInet(gethostbyname(fHost.String())); - if (remoteInet) - remoteAddr.sin_addr = *((in_addr *)remoteInet->h_addr_list[0]); - else - { - logmsg("failed (remoteInet) [%s]",fHost.String()); - } - } - - remoteAddr.sin_port = htons(fPort); - - if ((fSocket = socket(AF_INET, SOCK_STREAM, 0)) < 0) - { - logmsg("failed to create socket"); - fSocket = -1; - } - - if (connect(fSocket, (struct sockaddr *)&remoteAddr, sizeof(remoteAddr)) < 0) - { - logmsg("failed to connect socket"); - fSocket = -1; - } - - - fCookie = cookie; - - fReceiverThread = spawn_thread (ReceiveData, "socket receiver", B_LOW_PRIORITY, this); - - if (fReceiverThread != B_ERROR) - resume_thread(fReceiverThread); - else - { - logmsg("failed to resume the thread!"); - return -1; - } - - logmsg("DONE: StartConnection to %s:%ld",fHost.String(),fPort); - return fSocket; -} - - -int32 -JabberSocketPlug::ReceiveData(void * pHandler){ - - char data[1024]; - int length = 0; - JabberSocketPlug * plug = reinterpret_cast(pHandler); - - while (true) - { - #ifdef NETSERVER_BUILD - plug->fEndpointLock->Lock(); - #endif - - if ((length = (int)recv(plug->fSocket, data, 1023, 0)) > 0) - { - #ifdef NETSERVER_BUILD - plug->fEndpointLock->Unlock(); - #endif - data[length] = 0; - logmsg("SocketPlug<<\n%s", data); - } - else - { - #ifdef NETSERVER_BUILD - plug->fEndpointLock->Unlock(); - #endif - - plug->ReceivedData(NULL,0); - return 0; - } - - - plug->ReceivedData(data,length); - } - - return 0; -} - -void -JabberSocketPlug::ReceivedData(const char* data,int32 len){ - JabberHandler * handler = reinterpret_cast(fCookie); - if(handler) - handler->ReceivedData(data,len); -} - -int -JabberSocketPlug::Send(const BString & xml){ - - if (fSocket) - { - #ifdef NETSERVER - fEndpointLock->Lock(); - #endif - - logmsg("SocketPlug>>\n%s", xml.String()); - - if(send(fSocket, xml.String(), xml.Length(), 0) == -1) - return -1; - - #ifdef NETSERVER_BUILD - fEndpointLock->Unlock(); - #endif - } - - else - - { - logmsg("Socket not initialized"); - return -1; - } - return 0; -} - -int -JabberSocketPlug::StopConnection(){ - - //Thread Killing! - suspend_thread(fReceiverThread); - - if(fReceiverThread) kill_thread(fReceiverThread); - - fReceiverThread=0; - - #ifdef BONE_BUILD - close(fSocket); - #elif NETSERVER_BUILD - closesocket(fSocket); - #endif - - return 0; -} - - -//-- - diff --git a/libs/libjabber/JabberSocketPlug.h b/libs/libjabber/JabberSocketPlug.h deleted file mode 100644 index c3c10bf..0000000 --- a/libs/libjabber/JabberSocketPlug.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - - JabberSocketPlug (old code BONE/net_server) - - 22 sept. 2005 by Andrea Anzani (andrea@tenar.it) -*/ -#ifndef JabberSocketPlug_H_ -#define JabberSocketPlug_H_ - -#include "JabberPlug.h" -#include - -class JabberSocketPlug : public JabberPlug { - - public: - JabberSocketPlug(); - virtual ~JabberSocketPlug(); - //private: - - int StartConnection(BString fHost, int32 fPort,void* cook);//if >= 0 it's ok. - static int32 ReceiveData(void *); //thread called function - int Send(const BString & xml); //if >= 0 it's ok. - int StopConnection(); - - void ReceivedData(const char* data,int32); - private: - - - int32 fSocket; - volatile thread_id fReceiverThread; - void* fCookie; //FIX! - - #ifdef NETSERVER_BUILD - BLocker * fEndpointLock; - #endif - -}; - -#endif - -//-- diff --git a/libs/libjabber/JabberVCard.cpp b/libs/libjabber/JabberVCard.cpp deleted file mode 100644 index 1408205..0000000 --- a/libs/libjabber/JabberVCard.cpp +++ /dev/null @@ -1,245 +0,0 @@ -/* - * Copyright 2009, Pier Luigi Fiorini. - * Distributed under the terms of the MIT License. - */ - -#include "JabberVCard.h" -#include "Base64.h" - - -JabberVCard::JabberVCard() -{ -} - - -JabberVCard::JabberVCard(const JabberVCard& copy) -{ - SetFullName(copy.GetFullName()); - SetGivenName(copy.GetGivenName()); - SetFamilyName(copy.GetFamilyName()); - SetMiddleName(copy.GetMiddleName()); - SetNickname(copy.GetNickname()); - SetEmail(copy.GetEmail()); -} - - -void -JabberVCard::operator=(const JabberVCard& vcard) -{ - if (this == &vcard) - return; - - SetFullName(vcard.GetFullName()); - SetGivenName(vcard.GetGivenName()); - SetFamilyName(vcard.GetFamilyName()); - SetMiddleName(vcard.GetMiddleName()); - SetNickname(vcard.GetNickname()); - SetEmail(vcard.GetEmail()); -} - - -BString -JabberVCard::GetJid() const -{ - return fJid; -} - - - -void -JabberVCard::ParseFrom(const BString& from) -{ - fJid = ""; - fResource = ""; - - int32 i = from.FindFirst('/'); - if (i != -1) { - from.CopyInto(fJid, 0, i); - from.CopyInto(fResource, i + 1, from.Length()); - } else - fJid = from; -} - - -BString -JabberVCard::GetFullName() const -{ - return fFullName; -} - - -BString -JabberVCard::GetGivenName() const -{ - return fGivenName; -} - - -BString -JabberVCard::GetFamilyName() const -{ - return fFamilyName; -} - - -BString -JabberVCard::GetMiddleName() const -{ - return fMiddleName; -} - - -BString -JabberVCard::GetNickname() const -{ - return fNickname; -} - - -BString -JabberVCard::GetEmail() const -{ - return fEmail; -} - - -BString -JabberVCard::GetURL() const -{ - return fURL; -} - - -BString -JabberVCard::GetBirthday() const -{ - return fBirthday; -} - - -BString -JabberVCard::GetPhotoMimeType() const -{ - return fPhotoMime; -} - - -BString -JabberVCard::GetPhotoContent() const -{ - return fPhotoContent; -} - - -BString -JabberVCard::GetPhotoURL() const -{ - return fPhotoURL; -} - - -BString -JabberVCard::GetCachedPhotoFile() const -{ - return fCachedPhoto; -} - - -void -JabberVCard::SetFullName(const BString& firstName) -{ - fFullName = firstName; -} - - -void -JabberVCard::SetGivenName(const BString& name) -{ - fGivenName = name; -} - - -void -JabberVCard::SetFamilyName(const BString& name) -{ - fFamilyName = name; -} - - -void -JabberVCard::SetMiddleName(const BString& name) -{ - fMiddleName = name; -} - - -void -JabberVCard::SetNickname(const BString& name) -{ - fNickname = name; -} - - -void -JabberVCard::SetEmail(const BString& email) -{ - fEmail = email; -} - - -void -JabberVCard::SetURL(const BString& url) -{ - fURL = url; -} - - -void -JabberVCard::SetBirthday(const BString& birthday) -{ - fBirthday = birthday; -} - - -void -JabberVCard::SetPhotoMimeType(const BString& mime) -{ - fPhotoMime = mime; - - // We either get base64 encoded data or grab image - // from an URL - fPhotoURL = ""; -} - - -void -JabberVCard::SetPhotoContent(const BString& content) -{ - // Decode base64 - fPhotoContent = Base64::Decode(content); - - // We either get base64 encoded data or grab image - // from an URL - fPhotoURL = ""; -} - - -void -JabberVCard::SetPhotoURL(const BString& url) -{ - fPhotoURL = url; - - // If we previously set the MIME type and/or content - // we must remove them because we either fetch - // the photo from a URL or get it from base64 - // encoded data - fPhotoMime = ""; - fPhotoContent = ""; -} - - -void -JabberVCard::SetCachedPhotoFile(const BString& file) -{ - fCachedPhoto = file; -} diff --git a/libs/libjabber/JabberVCard.h b/libs/libjabber/JabberVCard.h deleted file mode 100644 index fd25267..0000000 --- a/libs/libjabber/JabberVCard.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2009, Pier Luigi Fiorini. - * Distributed under the terms of the MIT License. - */ -#ifndef _JABBER_VCARD_H -#define _JABBER_VCARD_H - -#include - -class JabberVCard { -public: - JabberVCard(); - JabberVCard(const JabberVCard& copy); - - void operator=(const JabberVCard& vcard); - - void ParseFrom(const BString& from); - - BString GetFullName() const; - BString GetGivenName() const; - BString GetFamilyName() const; - BString GetMiddleName() const; - BString GetNickname() const; - BString GetEmail() const; - BString GetURL() const; - BString GetBirthday() const; - BString GetPhotoMimeType() const; - BString GetPhotoContent() const; - BString GetPhotoURL() const; - BString GetCachedPhotoFile() const; - - BString GetJid() const; - - void SetFullName(const BString& firstName); - void SetGivenName(const BString& name); - void SetFamilyName(const BString& name); - void SetMiddleName(const BString& name); - void SetNickname(const BString& name); - void SetEmail(const BString& email); - void SetURL(const BString& url); - void SetBirthday(const BString& birthday); - void SetPhotoMimeType(const BString& mime); - void SetPhotoContent(const BString& content); - void SetPhotoURL(const BString& url); - void SetCachedPhotoFile(const BString& file); - -private: - BString fJid; - BString fResource; - BString fFullName; - BString fGivenName; - BString fFamilyName; - BString fMiddleName; - BString fNickname; - BString fEmail; - BString fURL; - BString fBirthday; - BString fPhotoMime; - BString fPhotoContent; - BString fPhotoURL; - BString fCachedPhoto; -}; - -#endif // _JABBER_VCARD_H diff --git a/libs/libjabber/Jamfile b/libs/libjabber/Jamfile deleted file mode 100644 index b1901bd..0000000 --- a/libs/libjabber/Jamfile +++ /dev/null @@ -1,32 +0,0 @@ -SubDir TOP libs libjabber ; - -SubDirSysHdrs [ FDirName $(TOP) ] ; -SubDirSysHdrs [ FDirName $(TOP) libs ] ; -if $(HAVE_OPENSSL) { - SubDirSysHdrs [ FDirName $(OPENSSL_INCLUDE_DIR) ] ; -} - -SEARCH_SOURCE += [ FDirName $(TOP) libs ] ; - -local sources = - # libjabber - JabberAgent.cpp - JabberContact.cpp - JabberElement.cpp - JabberHandler.cpp - JabberMessage.cpp - JabberPresence.cpp - JabberRegistration.cpp - JabberVCard.cpp - JabberSocketPlug.cpp - Logger.cpp - SHA1.cpp - Base64.cpp - VCardManager.cpp -; - -if $(HAVE_OPENSSL) { - sources += JabberSSLPlug.cpp ; -} - -StaticLibrary libjabber.a : $(sources) ; diff --git a/libs/libjabber/LICENSE b/libs/libjabber/LICENSE deleted file mode 100644 index 10bad50..0000000 --- a/libs/libjabber/LICENSE +++ /dev/null @@ -1,33 +0,0 @@ -// ---------------------- -// Olmeki License -// ---------------------- -// -// Copyright 2002, The Olmeki team. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions -// are met: -// -// 1. Redistributions of source code must retain the above copyright -// notice, this list of conditions, and the following disclaimer. -// -// 2. Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions, and the following disclaimer in the -// documentation and/or other materials provided with the distribution. -// -// 3. Neither the name of the Olmeki team nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS -// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/libs/libjabber/Logger.cpp b/libs/libjabber/Logger.cpp deleted file mode 100644 index 9ccf920..0000000 --- a/libs/libjabber/Logger.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2009, Pier Luigi Fiorini. All rights reserved. - * Distributed under the terms of the MIT License. - * - * Authors: - * Pier Luigi Fiorini, pierluigi.fiorini@gmail.com - */ - -#include -#include -#include - -#include -#include -#include - -#include "Logger.h" - - -void -logmsg(const char* message, ...) -{ - va_list varg; - char buffer[2048]; - - va_start(varg, message); - vsprintf(buffer, message, varg); - - char timestr[64]; - char today[11]; - time_t now = time(NULL); - strftime(timestr, sizeof(timestr), "%Y-%m-%d %H:%M", localtime(&now)); - timestr[63] = '\0'; - strftime(today, sizeof(today), "%Y-%m-%d", localtime(&now)); - today[10] = '\0'; - - char filename[B_PATH_NAME_LENGTH]; - snprintf(filename, B_PATH_NAME_LENGTH, "jabber-%s.log", today); - - BPath tempFile; - if (find_directory(B_COMMON_TEMP_DIRECTORY, &tempFile) != B_OK) - debugger("Could not find common temporary folder!"); - tempFile.Append(filename); - - FILE* file = fopen(tempFile.Path(), "a+"); - if (file) { - fprintf(file, "%s %s\n", timestr, buffer); - fclose(file); - } -} diff --git a/libs/libjabber/Logger.h b/libs/libjabber/Logger.h deleted file mode 100644 index 96c7e89..0000000 --- a/libs/libjabber/Logger.h +++ /dev/null @@ -1,10 +0,0 @@ -/* - * Copyright 2009, Pier Luigi Fiorini. All rights reserved. - * Distributed under the terms of the MIT License. - */ -#ifndef _LOGGER_H -#define _LOGGER_H - -void logmsg(const char* message, ...); - -#endif // _LOGGER_H diff --git a/libs/libjabber/ObjectList.h b/libs/libjabber/ObjectList.h deleted file mode 100644 index a4655d0..0000000 --- a/libs/libjabber/ObjectList.h +++ /dev/null @@ -1,866 +0,0 @@ -/* -Open Tracker License - -Terms and Conditions - -Copyright (c) 1991-2000, Be Incorporated. All rights reserved. - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - -The above copyright notice and this permission notice applies to all licensees -and shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of Be Incorporated shall not be -used in advertising or otherwise to promote the sale, use or other dealings in -this Software without prior written authorization from Be Incorporated. - -Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks -of Be Incorporated in the United States and other countries. Other brand product -names are registered trademarks or trademarks of their respective holders. -All rights reserved. -*/ - -/**************************************************************************** -** WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING ** -** ** -** DANGER, WILL ROBINSON! ** -** ** -** The interfaces contained here are part of BeOS's ** -** ** -** >> PRIVATE NOT FOR PUBLIC USE << ** -** ** -** implementation. ** -** ** -** These interfaces WILL CHANGE in future releases. ** -** If you use them, your app WILL BREAK at some future time. ** -** ** -** (And yes, this does mean that binaries built from OpenTracker will not ** -** be compatible with some future releases of the OS. When that happens, ** -** we will provide an updated version of this file to keep compatibility.) ** -** ** -** WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING ** -****************************************************************************/ - -// -// ObjectList is a wrapper around BList that adds type safety, -// optional object ownership, search, insert operations, etc. -// - -#ifndef __OBJECT_LIST__ -#define __OBJECT_LIST__ - -#ifndef _BE_H -#include -#endif - -#include - - -template class BObjectList; - -template -struct UnaryPredicate { - - virtual int operator()(const T *) const - // virtual could be avoided here if FindBinaryInsertionIndex, - // etc. were member template functions - { return 0; } - -private: - static int _unary_predicate_glue(const void *item, void *context); - -friend class BObjectList; -}; - -template -int -UnaryPredicate::_unary_predicate_glue(const void *item, void *context) -{ - return ((UnaryPredicate *)context)->operator()((const T *)item); -} - - -class _PointerList_ : public BList { -public: - _PointerList_(const _PointerList_ &list); - _PointerList_(int32 itemsPerBlock = 20, bool owning = false); - ~_PointerList_(); - - typedef void *(* GenericEachFunction)(void *, void *); - typedef int (* GenericCompareFunction)(const void *, const void *); - typedef int (* GenericCompareFunctionWithState)(const void *, const void *, - void *); - typedef int (* UnaryPredicateGlue)(const void *, void *); - - void *EachElement(GenericEachFunction, void *); - void SortItems(GenericCompareFunction); - void SortItems(GenericCompareFunctionWithState, void *state); - void HSortItems(GenericCompareFunction); - void HSortItems(GenericCompareFunctionWithState, void *state); - - void *BinarySearch(const void *, GenericCompareFunction) const; - void *BinarySearch(const void *, GenericCompareFunctionWithState, void *state) const; - - int32 BinarySearchIndex(const void *, GenericCompareFunction) const; - int32 BinarySearchIndex(const void *, GenericCompareFunctionWithState, void *state) const; - int32 BinarySearchIndexByPredicate(const void *, UnaryPredicateGlue) const; - - bool Owning() const; - bool ReplaceItem(int32, void *); - -protected: - bool owning; - -}; - -template -class BObjectList : private _PointerList_ { -public: - - // iteration and sorting - typedef T *(* EachFunction)(T *, void *); - typedef const T *(* ConstEachFunction)(const T *, void *); - typedef int (* CompareFunction)(const T *, const T *); - typedef int (* CompareFunctionWithState)(const T *, const T *, void *state); - - BObjectList(int32 itemsPerBlock = 20, bool owning = false); - BObjectList(const BObjectList &list); - // clones list; if list is owning, makes copies of all - // the items - - virtual ~BObjectList(); - - BObjectList &operator=(const BObjectList &list); - // clones list; if list is owning, makes copies of all - // the items - - // adding and removing - // ToDo: - // change Add calls to return const item - bool AddItem(T *); - bool AddItem(T *, int32); - bool AddList(BObjectList *); - bool AddList(BObjectList *, int32); - - bool RemoveItem(T *, bool deleteIfOwning = true); - // if owning, deletes the removed item - T *RemoveItemAt(int32); - // returns the removed item - - void MakeEmpty(); - - // item access - T *ItemAt(int32) const; - - bool ReplaceItem(int32 index, T *); - // if list is owning, deletes the item at first - T *SwapWithItem(int32 index, T *newItem); - // same as ReplaceItem, except does not delete old item at , - // returns it instead - - T *FirstItem() const; - T *LastItem() const; - - // misc. getters - int32 IndexOf(const T *) const; - bool HasItem(const T *) const; - bool IsEmpty() const; - int32 CountItems() const; - - T *EachElement(EachFunction, void *); - const T *EachElement(ConstEachFunction, void *) const; - - void SortItems(CompareFunction); - void SortItems(CompareFunctionWithState, void *state); - void HSortItems(CompareFunction); - void HSortItems(CompareFunctionWithState, void *state); - - // linear search, returns first item that matches predicate - const T *FindIf(const UnaryPredicate &) const; - T *FindIf(const UnaryPredicate &); - - // list must be sorted with CompareFunction for these to work - T *BinarySearch(const T &, CompareFunction) const; - T *BinarySearch(const T &, CompareFunctionWithState, void *state) const; - - template - T *BinarySearchByKey(const Key &key, int (*compare)(const Key *, const T *)) - const; - - template - T *BinarySearchByKey(const Key &key, - int (*compare)(const Key *, const T *, void *), void *state) const; - - int32 BinarySearchIndex(const T &item, CompareFunction compare) const; - int32 BinarySearchIndex(const T &item, CompareFunctionWithState compare, - void *state) const; - - template - int32 BinarySearchIndexByKey(const Key &key, - int (*compare)(const Key *, const T *)) const; - - // Binary insertion - list must be sorted with CompareFunction for - // these to work - - // simple insert - bool BinaryInsert(T *, CompareFunction); - bool BinaryInsert(T *, CompareFunctionWithState, void *state); - bool BinaryInsert(T *, const UnaryPredicate &); - - // unique insert, returns false if item already in list - bool BinaryInsertUnique(T *, CompareFunction); - bool BinaryInsertUnique(T *, CompareFunctionWithState, void *state); - bool BinaryInsertUnique(T *, const UnaryPredicate &); - - // insert a copy of the item, returns new inserted item - T *BinaryInsertCopy(const T ©This, CompareFunction); - T *BinaryInsertCopy(const T ©This, CompareFunctionWithState, void *state); - - // insert a copy of the item if not in list already - // returns new inserted item or existing item in case of a conflict - T *BinaryInsertCopyUnique(const T ©This, CompareFunction); - T *BinaryInsertCopyUnique(const T ©This, CompareFunctionWithState, void *state); - - int32 FindBinaryInsertionIndex(const UnaryPredicate &, bool *alreadyInList = 0) const; - // returns either the index into which a new item should be inserted - // or index of an existing item that matches the predicate - - // deprecated API, will go away - BList *AsBList() - { return this; } - const BList *AsBList() const - { return this; } -private: - void SetItem(int32, T *); -}; - -template -Result -WhileEachListItem(BObjectList *list, Result (Item::*func)(Param1), Param1 p1) -{ - Result result = 0; - int32 count = list->CountItems(); - - for (int32 index = 0; index < count; index++) - if ((result = (list->ItemAt(index)->*func)(p1)) != 0) - break; - - return result; -} - -template -Result -WhileEachListItem(BObjectList *list, Result (*func)(Item *, Param1), Param1 p1) -{ - Result result = 0; - int32 count = list->CountItems(); - - for (int32 index = 0; index < count; index++) - if ((result = (*func)(list->ItemAt(index), p1)) != 0) - break; - - return result; -} - -template -Result -WhileEachListItem(BObjectList *list, Result (Item::*func)(Param1, Param2), - Param1 p1, Param2 p2) -{ - Result result = 0; - int32 count = list->CountItems(); - - for (int32 index = 0; index < count; index++) - if ((result = (list->ItemAt(index)->*func)(p1, p2)) != 0) - break; - - return result; -} - -template -Result -WhileEachListItem(BObjectList *list, Result (*func)(Item *, Param1, Param2), - Param1 p1, Param2 p2) -{ - Result result = 0; - int32 count = list->CountItems(); - - for (int32 index = 0; index < count; index++) - if ((result = (*func)(list->ItemAt(index), p1, p2)) != 0) - break; - - return result; -} - -template -Result -WhileEachListItem(BObjectList *list, Result (*func)(Item *, Param1, Param2, - Param3, Param4), Param1 p1, Param2 p2, Param3 p3, Param4 p4) -{ - Result result = 0; - int32 count = list->CountItems(); - - for (int32 index = 0; index < count; index++) - if ((result = (*func)(list->ItemAt(index), p1, p2, p3, p4)) != 0) - break; - - return result; -} - -template -void -EachListItemIgnoreResult(BObjectList *list, Result (Item::*func)()) -{ - int32 count = list->CountItems(); - for (int32 index = 0; index < count; index++) - (list->ItemAt(index)->*func)(); -} - -template -void -EachListItem(BObjectList *list, void (*func)(Item *, Param1), Param1 p1) -{ - int32 count = list->CountItems(); - for (int32 index = 0; index < count; index++) - (func)(list->ItemAt(index), p1); -} - -template -void -EachListItem(BObjectList *list, void (Item::*func)(Param1, Param2), - Param1 p1, Param2 p2) -{ - int32 count = list->CountItems(); - for (int32 index = 0; index < count; index++) - (list->ItemAt(index)->*func)(p1, p2); -} - -template -void -EachListItem(BObjectList *list, void (*func)(Item *,Param1, Param2), - Param1 p1, Param2 p2) -{ - int32 count = list->CountItems(); - for (int32 index = 0; index < count; index++) - (func)(list->ItemAt(index), p1, p2); -} - -template -void -EachListItem(BObjectList *list, void (*func)(Item *,Param1, Param2, - Param3), Param1 p1, Param2 p2, Param3 p3) -{ - int32 count = list->CountItems(); - for (int32 index = 0; index < count; index++) - (func)(list->ItemAt(index), p1, p2, p3); -} - - -template -void -EachListItem(BObjectList *list, void (*func)(Item *,Param1, Param2, - Param3, Param4), Param1 p1, Param2 p2, Param3 p3, Param4 p4) -{ - int32 count = list->CountItems(); - for (int32 index = 0; index < count; index++) - (func)(list->ItemAt(index), p1, p2, p3, p4); -} - -// inline code - -inline bool -_PointerList_::Owning() const -{ - return owning; -} - -template -BObjectList::BObjectList(int32 itemsPerBlock, bool owning) - : _PointerList_(itemsPerBlock, owning) -{ -} - -template -BObjectList::BObjectList(const BObjectList &list) - : _PointerList_(list) -{ - owning = list.owning; - if (owning) { - // make our own copies in an owning list - int32 count = list.CountItems(); - for (int32 index = 0; index < count; index++) { - T *item = list.ItemAt(index); - if (item) - item = new T(*item); - SetItem(index, item); - } - } -} - -template -BObjectList::~BObjectList() -{ - if (Owning()) - // have to nuke elements first - MakeEmpty(); -} - -template -BObjectList & -BObjectList::operator=(const BObjectList &list) -{ - owning = list.owning; - BObjectList &result = (BObjectList &)_PointerList_::operator=(list); - if (owning) { - // make our own copies in an owning list - int32 count = list.CountItems(); - for (int32 index = 0; index < count; index++) { - T *item = list.ItemAt(index); - if (item) - item = new T(*item); - SetItem(index, item); - } - } - return result; -} - -template -bool -BObjectList::AddItem(T *item) -{ - // need to cast to void * to make T work for const pointers - return _PointerList_::AddItem((void *)item); -} - -template -bool -BObjectList::AddItem(T *item, int32 atIndex) -{ - return _PointerList_::AddItem((void *)item, atIndex); -} - -template -bool -BObjectList::AddList(BObjectList *newItems) -{ - return _PointerList_::AddList(newItems); -} - -template -bool -BObjectList::AddList(BObjectList *newItems, int32 atIndex) -{ - return _PointerList_::AddList(newItems, atIndex); -} - - -template -bool -BObjectList::RemoveItem(T *item, bool deleteIfOwning) -{ - bool result = _PointerList_::RemoveItem((void *)item); - - if (result && Owning() && deleteIfOwning) - delete item; - - return result; -} - -template -T * -BObjectList::RemoveItemAt(int32 index) -{ - return (T *)_PointerList_::RemoveItem(index); -} - -template -inline T * -BObjectList::ItemAt(int32 index) const -{ - return (T *)_PointerList_::ItemAt(index); -} - -template -bool -BObjectList::ReplaceItem(int32 index, T *item) -{ - if (owning) - delete ItemAt(index); - return _PointerList_::ReplaceItem(index, (void *)item); -} - -template -T * -BObjectList::SwapWithItem(int32 index, T *newItem) -{ - T *result = ItemAt(index); - _PointerList_::ReplaceItem(index, (void *)newItem); - return result; -} - -template -void -BObjectList::SetItem(int32 index, T *newItem) -{ - _PointerList_::ReplaceItem(index, (void *)newItem); -} - -template -int32 -BObjectList::IndexOf(const T *item) const -{ - return _PointerList_::IndexOf((void *)item); -} - -template -T * -BObjectList::FirstItem() const -{ - return (T *)_PointerList_::FirstItem(); -} - -template -T * -BObjectList::LastItem() const -{ - return (T *)_PointerList_::LastItem(); -} - -template -bool -BObjectList::HasItem(const T *item) const -{ - return _PointerList_::HasItem((void *)item); -} - -template -bool -BObjectList::IsEmpty() const -{ - return _PointerList_::IsEmpty(); -} - -template -int32 -BObjectList::CountItems() const -{ - return _PointerList_::CountItems(); -} - -template -void -BObjectList::MakeEmpty() -{ - if (owning) { - int32 count = CountItems(); - for (int32 index = 0; index < count; index++) - delete ItemAt(index); - } - _PointerList_::MakeEmpty(); -} - -template -T * -BObjectList::EachElement(EachFunction func, void *params) -{ - return (T *)_PointerList_::EachElement((GenericEachFunction)func, params); -} - - -template -const T * -BObjectList::EachElement(ConstEachFunction func, void *params) const -{ - return (const T *) - const_cast *>(this)->_PointerList_::EachElement( - (GenericEachFunction)func, params); -} - -template -const T * -BObjectList::FindIf(const UnaryPredicate &predicate) const -{ - int32 count = CountItems(); - for (int32 index = 0; index < count; index++) - if (predicate.operator()(ItemAt(index)) == 0) - return ItemAt(index); - return 0; -} - -template -T * -BObjectList::FindIf(const UnaryPredicate &predicate) -{ - int32 count = CountItems(); - for (int32 index = 0; index < count; index++) - if (predicate.operator()(ItemAt(index)) == 0) - return ItemAt(index); - return 0; -} - - -template -void -BObjectList::SortItems(CompareFunction function) -{ - _PointerList_::SortItems((GenericCompareFunction)function); -} - -template -void -BObjectList::SortItems(CompareFunctionWithState function, void *state) -{ - _PointerList_::SortItems((GenericCompareFunctionWithState)function, state); -} - -template -void -BObjectList::HSortItems(CompareFunction function) -{ - _PointerList_::HSortItems((GenericCompareFunction)function); -} - -template -void -BObjectList::HSortItems(CompareFunctionWithState function, void *state) -{ - _PointerList_::HSortItems((GenericCompareFunctionWithState)function, state); -} - -template -T * -BObjectList::BinarySearch(const T &key, CompareFunction func) const -{ - return (T*)_PointerList_::BinarySearch(&key, - (GenericCompareFunction)func); -} - -template -T * -BObjectList::BinarySearch(const T &key, CompareFunctionWithState func, void *state) const -{ - return (T*)_PointerList_::BinarySearch(&key, - (GenericCompareFunctionWithState)func, state); -} - - -template -template -T * -BObjectList::BinarySearchByKey(const Key &key, - int (*compare)(const Key *, const T *)) const -{ - return (T*)_PointerList_::BinarySearch(&key, - (GenericCompareFunction)compare); -} - - -template -template -T * -BObjectList::BinarySearchByKey(const Key &key, - int (*compare)(const Key *, const T *, void *), void *state) const -{ - return (T*)_PointerList_::BinarySearch(&key, - (GenericCompareFunctionWithState)compare, state); -} - - -template -int32 -BObjectList::BinarySearchIndex(const T &item, CompareFunction compare) const -{ - return _PointerList_::BinarySearchIndex(&item, - (GenericCompareFunction)compare); -} - - -template -int32 -BObjectList::BinarySearchIndex(const T &item, - CompareFunctionWithState compare, void *state) const -{ - return _PointerList_::BinarySearchIndex(&item, - (GenericCompareFunctionWithState)compare, state); -} - - -template -template -int32 -BObjectList::BinarySearchIndexByKey(const Key &key, - int (*compare)(const Key *, const T *)) const -{ - return _PointerList_::BinarySearchIndex(&key, - (GenericCompareFunction)compare); -} - - -template -bool -BObjectList::BinaryInsert(T *item, CompareFunction func) -{ - int32 index = _PointerList_::BinarySearchIndex(item, - (GenericCompareFunction)func); - if (index >= 0) { - // already in list, add after existing - return AddItem(item, index + 1); - } - - return AddItem(item, -index - 1); -} - -template -bool -BObjectList::BinaryInsert(T *item, CompareFunctionWithState func, void *state) -{ - int32 index = _PointerList_::BinarySearchIndex(item, - (GenericCompareFunctionWithState)func, state); - if (index >= 0) { - // already in list, add after existing - return AddItem(item, index + 1); - } - - return AddItem(item, -index - 1); -} - -template -bool -BObjectList::BinaryInsertUnique(T *item, CompareFunction func) -{ - int32 index = _PointerList_::BinarySearchIndex(item, - (GenericCompareFunction)func); - if (index >= 0) - return false; - - return AddItem(item, -index - 1); -} - -template -bool -BObjectList::BinaryInsertUnique(T *item, CompareFunctionWithState func, void *state) -{ - int32 index = _PointerList_::BinarySearchIndex(item, - (GenericCompareFunctionWithState)func, state); - if (index >= 0) - return false; - - return AddItem(item, -index - 1); -} - - -template -T * -BObjectList::BinaryInsertCopy(const T ©This, CompareFunction func) -{ - int32 index = _PointerList_::BinarySearchIndex(©This, - (GenericCompareFunction)func); - - if (index >= 0) - index++; - else - index = -index - 1; - - T *newItem = new T(copyThis); - AddItem(newItem, index); - return newItem; -} - -template -T * -BObjectList::BinaryInsertCopy(const T ©This, CompareFunctionWithState func, void *state) -{ - int32 index = _PointerList_::BinarySearchIndex(©This, - (GenericCompareFunctionWithState)func, state); - - if (index >= 0) - index++; - else - index = -index - 1; - - T *newItem = new T(copyThis); - AddItem(newItem, index); - return newItem; -} - -template -T * -BObjectList::BinaryInsertCopyUnique(const T ©This, CompareFunction func) -{ - int32 index = _PointerList_::BinarySearchIndex(©This, - (GenericCompareFunction)func); - if (index >= 0) - return ItemAt(index); - - index = -index - 1; - T *newItem = new T(copyThis); - AddItem(newItem, index); - return newItem; -} - -template -T * -BObjectList::BinaryInsertCopyUnique(const T ©This, CompareFunctionWithState func, - void *state) -{ - int32 index = _PointerList_::BinarySearchIndex(©This, - (GenericCompareFunctionWithState)func, state); - if (index >= 0) - return ItemAt(index); - - index = -index - 1; - T *newItem = new T(copyThis); - AddItem(newItem, index); - return newItem; -} - -template -int32 -BObjectList::FindBinaryInsertionIndex(const UnaryPredicate &pred, bool *alreadyInList) - const -{ - int32 index = _PointerList_::BinarySearchIndexByPredicate(&pred, - (UnaryPredicateGlue)&UnaryPredicate::_unary_predicate_glue); - - if (alreadyInList) - *alreadyInList = index >= 0; - - if (index < 0) - index = -index - 1; - - return index; -} - -template -bool -BObjectList::BinaryInsert(T *item, const UnaryPredicate &pred) -{ - return AddItem(item, FindBinaryInsertionIndex(pred)); -} - -template -bool -BObjectList::BinaryInsertUnique(T *item, const UnaryPredicate &pred) -{ - bool alreadyInList; - int32 index = FindBinaryInsertionIndex(pred, &alreadyInList); - if (alreadyInList) - return false; - - AddItem(item, index); - return true; -} - -#endif /* __OBJECT_LIST__ */ diff --git a/libs/libjabber/SHA1.cpp b/libs/libjabber/SHA1.cpp deleted file mode 100644 index 94bdf96..0000000 --- a/libs/libjabber/SHA1.cpp +++ /dev/null @@ -1,222 +0,0 @@ -/* - 100% free public domain implementation of the SHA-1 - algorithm by Dominik Reichl - - - === Test Vectors (from FIPS PUB 180-1) === - - "abc" - A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D - - "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" - 84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1 - - A million repetitions of "a" - 34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F -*/ - - -#include "SHA1.h" - - -CSHA1::CSHA1() -{ - Reset(); -} - -CSHA1::~CSHA1() -{ - Reset(); -} - - -void CSHA1::Reset() -{ - // SHA1 initialization constants - m_state[0] = 0x67452301; - m_state[1] = 0xEFCDAB89; - m_state[2] = 0x98BADCFE; - m_state[3] = 0x10325476; - m_state[4] = 0xC3D2E1F0; - - m_count[0] = 0; - m_count[1] = 0; -} - -void CSHA1::Transform(unsigned long state[5], unsigned char buffer[64]) -{ - unsigned long a = 0, b = 0, c = 0, d = 0, e = 0; - - SHA1_WORKSPACE_BLOCK* block; - static unsigned char workspace[64]; - block = (SHA1_WORKSPACE_BLOCK*)workspace; - memcpy(block, buffer, 64); - - // Copy state[] to working vars - a = state[0]; - b = state[1]; - c = state[2]; - d = state[3]; - e = state[4]; - - // 4 rounds of 20 operations each. Loop unrolled. - R0(a,b,c,d,e, 0); R0(e,a,b,c,d, 1); R0(d,e,a,b,c, 2); R0(c,d,e,a,b, 3); - R0(b,c,d,e,a, 4); R0(a,b,c,d,e, 5); R0(e,a,b,c,d, 6); R0(d,e,a,b,c, 7); - R0(c,d,e,a,b, 8); R0(b,c,d,e,a, 9); R0(a,b,c,d,e,10); R0(e,a,b,c,d,11); - R0(d,e,a,b,c,12); R0(c,d,e,a,b,13); R0(b,c,d,e,a,14); R0(a,b,c,d,e,15); - R1(e,a,b,c,d,16); R1(d,e,a,b,c,17); R1(c,d,e,a,b,18); R1(b,c,d,e,a,19); - R2(a,b,c,d,e,20); R2(e,a,b,c,d,21); R2(d,e,a,b,c,22); R2(c,d,e,a,b,23); - R2(b,c,d,e,a,24); R2(a,b,c,d,e,25); R2(e,a,b,c,d,26); R2(d,e,a,b,c,27); - R2(c,d,e,a,b,28); R2(b,c,d,e,a,29); R2(a,b,c,d,e,30); R2(e,a,b,c,d,31); - R2(d,e,a,b,c,32); R2(c,d,e,a,b,33); R2(b,c,d,e,a,34); R2(a,b,c,d,e,35); - R2(e,a,b,c,d,36); R2(d,e,a,b,c,37); R2(c,d,e,a,b,38); R2(b,c,d,e,a,39); - R3(a,b,c,d,e,40); R3(e,a,b,c,d,41); R3(d,e,a,b,c,42); R3(c,d,e,a,b,43); - R3(b,c,d,e,a,44); R3(a,b,c,d,e,45); R3(e,a,b,c,d,46); R3(d,e,a,b,c,47); - R3(c,d,e,a,b,48); R3(b,c,d,e,a,49); R3(a,b,c,d,e,50); R3(e,a,b,c,d,51); - R3(d,e,a,b,c,52); R3(c,d,e,a,b,53); R3(b,c,d,e,a,54); R3(a,b,c,d,e,55); - R3(e,a,b,c,d,56); R3(d,e,a,b,c,57); R3(c,d,e,a,b,58); R3(b,c,d,e,a,59); - R4(a,b,c,d,e,60); R4(e,a,b,c,d,61); R4(d,e,a,b,c,62); R4(c,d,e,a,b,63); - R4(b,c,d,e,a,64); R4(a,b,c,d,e,65); R4(e,a,b,c,d,66); R4(d,e,a,b,c,67); - R4(c,d,e,a,b,68); R4(b,c,d,e,a,69); R4(a,b,c,d,e,70); R4(e,a,b,c,d,71); - R4(d,e,a,b,c,72); R4(c,d,e,a,b,73); R4(b,c,d,e,a,74); R4(a,b,c,d,e,75); - R4(e,a,b,c,d,76); R4(d,e,a,b,c,77); R4(c,d,e,a,b,78); R4(b,c,d,e,a,79); - - // Add the working vars back into state[] - state[0] += a; - state[1] += b; - state[2] += c; - state[3] += d; - state[4] += e; - - // Wipe variables - a = 0; b = 0; c = 0; d = 0; e = 0; -} - -// Use this function to hash in binary data and strings -void CSHA1::Update(unsigned char* data, unsigned int len) -{ - unsigned long i = 0, j = 0; - - j = (m_count[0] >> 3) & 63; - - if((m_count[0] += len << 3) < (len << 3)) m_count[1]++; - - m_count[1] += (len >> 29); - - if((j + len) > 63) - { - memcpy(&m_buffer[j], data, (i = 64 - j)); - Transform(m_state, m_buffer); - - for (; i+63 < len; i += 64) - { - Transform(m_state, &data[i]); - } - - j = 0; - } - else i = 0; - - memcpy(&m_buffer[j], &data[i], len - i); -} - -// Hash in file contents -bool CSHA1::HashFile(char *szFileName) -{ - unsigned long ulFileSize = 0, ulRest = 0, ulBlocks = 0; - unsigned long i = 0; - unsigned char uData[MAX_FILE_READ_BUFFER]; - FILE *fIn = NULL; - - if((fIn = fopen(szFileName, "rb")) == NULL) return(false); - - fseek(fIn, 0, SEEK_END); - ulFileSize = ftell(fIn); - fseek(fIn, 0, SEEK_SET); - - ulRest = ulFileSize % MAX_FILE_READ_BUFFER; - ulBlocks = ulFileSize / MAX_FILE_READ_BUFFER; - - for(i = 0; i < ulBlocks; i++) - { - fread(uData, 1, MAX_FILE_READ_BUFFER, fIn); - Update(uData, MAX_FILE_READ_BUFFER); - } - - if(ulRest != 0) - { - fread(uData, 1, ulRest, fIn); - Update(uData, ulRest); - } - - fclose(fIn); - fIn = NULL; - - return(true); -} - -void CSHA1::Final() -{ - unsigned long i = 0, j = 0; - unsigned char finalcount[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; - - for (i = 0; i < 8; i++) - finalcount[i] = (unsigned char)((m_count[(i >= 4 ? 0 : 1)] - >> ((3 - (i & 3)) * 8) ) & 255); // Endian independent - - Update((unsigned char *)"\200", 1); - - while ((m_count[0] & 504) != 448) - Update((unsigned char *)"\0", 1); - - Update(finalcount, 8); // Cause a SHA1Transform() - - for (i = 0; i < 20; i++) - { - m_digest[i] = (unsigned char)((m_state[i >> 2] >> ((3 - (i & 3)) * 8) ) & 255); - } - - // Wipe variables for security reasons - i = 0; j = 0; - memset(m_buffer, 0, 64); - memset(m_state, 0, 20); - memset(m_count, 0, 8); - memset(finalcount, 0, 8); - - Transform(m_state, m_buffer); -} - -// Get the final hash as a pre-formatted string -void CSHA1::ReportHash(char *szReport, unsigned char uReportType) -{ - unsigned char i = 0; - - if(uReportType == REPORT_HEX) - { - sprintf(szReport, "%02X", m_digest[0]); - - for(i = 1; i < 20; i++) - { - sprintf(szReport, "%s%02X", szReport, m_digest[i]); - } - } - else if(uReportType == REPORT_DIGIT) - { - sprintf(szReport, "%u", m_digest[0]); - - for(i = 1; i < 20; i++) - { - sprintf(szReport, "%s %u", szReport, m_digest[i]); - } - } - else sprintf(szReport, "Error: Unknown report type!"); -} - -// Get the raw message digest -void CSHA1::GetHash(unsigned char *uDest) -{ - unsigned char i = 0; - - for(i = 0; i < 20; i++) - uDest[i] = m_digest[i]; -} diff --git a/libs/libjabber/SHA1.h b/libs/libjabber/SHA1.h deleted file mode 100644 index 8db7324..0000000 --- a/libs/libjabber/SHA1.h +++ /dev/null @@ -1,81 +0,0 @@ -/* - 100% free public domain implementation of the SHA-1 - algorithm by Dominik Reichl - - - === Test Vectors (from FIPS PUB 180-1) === - - "abc" - A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D - - "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" - 84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1 - - A million repetitions of "a" - 34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F -*/ - -#ifndef ___SHA1_H___ -#define ___SHA1_H___ - -#include // Needed for file access -#include // Needed for memset and memcpy - -//#define LITTLE_ENDIAN -#define MAX_FILE_READ_BUFFER 8000 - -class CSHA1 -{ -public: - // Rotate x bits to the left - #define ROL32(value, bits) (((value)<<(bits))|((value)>>(32-(bits)))) - - #ifdef LITTLE_ENDIAN - #define SHABLK0(i) (block->l[i] = (ROL32(block->l[i],24) & 0xFF00FF00) | (ROL32(block->l[i],8) & 0x00FF00FF)) - #else - #define SHABLK0(i) (block->l[i]) - #endif - - #define SHABLK(i) (block->l[i&15] = ROL32(block->l[(i+13)&15] ^ block->l[(i+8)&15] ^ block->l[(i+2)&15] ^ block->l[i&15],1)) - - // SHA-1 rounds - #define R0(v,w,x,y,z,i) { z+=((w&(x^y))^y)+SHABLK0(i)+0x5A827999+ROL32(v,5); w=ROL32(w,30); } - #define R1(v,w,x,y,z,i) { z+=((w&(x^y))^y)+SHABLK(i)+0x5A827999+ROL32(v,5); w=ROL32(w,30); } - #define R2(v,w,x,y,z,i) { z+=(w^x^y)+SHABLK(i)+0x6ED9EBA1+ROL32(v,5); w=ROL32(w,30); } - #define R3(v,w,x,y,z,i) { z+=(((w|x)&y)|(w&x))+SHABLK(i)+0x8F1BBCDC+ROL32(v,5); w=ROL32(w,30); } - #define R4(v,w,x,y,z,i) { z+=(w^x^y)+SHABLK(i)+0xCA62C1D6+ROL32(v,5); w=ROL32(w,30); } - - typedef union { - unsigned char c[64]; - unsigned long l[16]; - } SHA1_WORKSPACE_BLOCK; - - // Two different formats for ReportHash(...) - enum { REPORT_HEX = 0, REPORT_DIGIT = 1 }; - - // Constructor and Destructor - CSHA1(); - virtual ~CSHA1(); - - unsigned long m_state[5]; - unsigned long m_count[2]; - unsigned char m_buffer[64]; - unsigned char m_digest[20]; - - void Reset(); - - // Update the hash value - void Update(unsigned char* data, unsigned int len); - bool HashFile(char *szFileName); - - // Finalize hash and report - void Final(); - void ReportHash(char *szReport, unsigned char uReportType = REPORT_HEX); - void GetHash(unsigned char *uDest); - -private: - // Private SHA-1 transformation - void Transform(unsigned long state[5], unsigned char buffer[64]); -}; - -#endif // ___SHA1_H___ diff --git a/libs/libjabber/ServerHandler.h b/libs/libjabber/ServerHandler.h deleted file mode 100644 index a1de077..0000000 --- a/libs/libjabber/ServerHandler.h +++ /dev/null @@ -1,7 +0,0 @@ -#include "JabberAgent.h" -#include "JabberContact.h" -#include "JabberElement.h" -#include "JabberHandler.h" -#include "JabberMessage.h" -#include "JabberPresence.h" -#include "JabberRegistration.h" diff --git a/libs/libjabber/States.h b/libs/libjabber/States.h deleted file mode 100644 index a72533a..0000000 --- a/libs/libjabber/States.h +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright 2009, Andrea Anzani. All rights reserved. - * Distributed under the terms of the MIT License. - */ -#ifndef _STATES_H -#define _STATES_H - -#include - -const int32 S_OFFLINE = 0x0; -const int32 S_ONLINE = 0x1; -const int32 S_AWAY = 0x2; -const int32 S_XA = 0x3; -const int32 S_DND = 0x4; -const int32 S_CHAT = 0x5; -const int32 S_SEND = 0x6; - -#endif // _STATES_H diff --git a/libs/libjabber/VCardManager.cpp b/libs/libjabber/VCardManager.cpp deleted file mode 100644 index 4919c84..0000000 --- a/libs/libjabber/VCardManager.cpp +++ /dev/null @@ -1,138 +0,0 @@ -#include "VCardManager.h" -#include -#include -#include -#include "JabberPresence.h" -#include "JabberContact.h" -#include "JabberVCard.h" -#include "JabberHandler.h" -#include "Logger.h" -#include -#include "SHA1.h" - -VCardManager::VCardManager(JabberHandler* jabberHandler) : fJabberHandler(jabberHandler) -{ - BPath fCacheFolderPath; - find_directory(B_USER_SETTINGS_DIRECTORY, &fCacheFolderPath); - fCacheFolderPath.Append("libjabber"); - fCacheFolder.SetTo(fCacheFolderPath.Path()); - - fCacheFolder.CreateDirectory(fCacheFolderPath.Path(), &fCacheFolder); - - fCachePath = fCacheFolderPath; - fCachePath.Append("jabber-roster-cache"); - - BFile *file = new BFile(fCachePath.Path(), B_READ_ONLY); - fCache.Unflatten(file); - delete file; -} - -void -VCardManager::SaveCache() -{ - BFile *file = new BFile(fCachePath.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE); - fCache.Flatten(file); - delete file; -} - -void -VCardManager::VCardReceived(JabberContact* contact) -{ - logmsg("VCardReceived: for %s\n", contact->GetJid().String()); - if (contact->GetVCard()->GetPhotoContent() == "") - return; - - BMessage jid; - if (fCache.FindMessage(contact->GetJid().String(), &jid) != B_OK) - { - fCache.AddMessage(contact->GetJid().String(), &jid); - logmsg("no vCard request in cache! adding..\n"); - SaveCache(); - } - - BString sha1; - if (jid.FindString("photo-sha1", &sha1) != B_OK || sha1 == "" ) - { - // let's try to make an sha1.. - CSHA1 s1; - char hash[256]; - s1.Reset(); - s1.Update((unsigned char*)contact->GetVCard()->GetPhotoContent().String(), contact->GetVCard()->GetPhotoContent().Length()); - s1.Final(); - s1.ReportHash(hash, CSHA1::REPORT_HEX); - sha1.SetTo(hash, 256); - logmsg("sha1 created: %s for %s adding to cache..\n", sha1.String(), contact->GetJid().String()); - jid.AddString("photo-sha1", sha1.String()); - fCache.ReplaceMessage(contact->GetJid().String(), &jid); - SaveCache(); - } - - //save to file. - BPath newFile(&fCacheFolder); - newFile.Append(sha1.String()); - - BFile file(newFile.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE); - file.Write(contact->GetVCard()->GetPhotoContent().String(), contact->GetVCard()->GetPhotoContent().Length()); - contact->GetVCard()->SetCachedPhotoFile(newFile.Path()); - if (contact->GetJid() != fJabberHandler->GetJid()) - fJabberHandler->GotBuddyPhoto(contact->GetJid(), newFile.Path()); -} - -void -VCardManager::RefinePresence(JabberPresence* presence) -{ - logmsg("RefinePresence: [%s] for %s\n", presence->GetPhotoSHA1().String(), presence->GetJid().String()); - BMessage jid; - if (fCache.FindMessage(presence->GetJid().String(), &jid) != B_OK) - { - logmsg(" not found in cache.. adding\n"); - jid.AddString("photo-sha1", presence->GetPhotoSHA1().String()); - fCache.AddMessage(presence->GetJid().String(), &jid); - SaveCache(); - logmsg("...asking for downloading the image..\n"); - fJabberHandler->RequestVCard(presence->GetJid()); - } - else - { - logmsg("..found in cache!\n"); - BString sha1; - if ( jid.FindString("photo-sha1", &sha1) == B_OK ) - { - if (sha1.ICompare(presence->GetPhotoSHA1()) != 0) - { - logmsg("..existing sha1 is different, asking new vcard..\n"); - jid.ReplaceString("photo-sha1", presence->GetPhotoSHA1().String()); - SaveCache(); - fJabberHandler->RequestVCard(presence->GetJid()); - } - else - { - if (sha1 == "") - { - fJabberHandler->GotBuddyPhoto(presence->GetJid(), ""); - } - else - { - BPath newFile(&fCacheFolder); - newFile.Append(sha1.String()); - logmsg("..sha1 match.. checking if file exits..(%s)\n", newFile.Path()); - if(BEntry(newFile.Path()).Exists()) - { - logmsg(".. yes it exists!\n"); - fJabberHandler->GotBuddyPhoto(presence->GetJid(), newFile.Path()); - } - else - { - logmsg("..no it doesn't, asking new vcard..\n"); - fJabberHandler->RequestVCard(presence->GetJid()); - } - } - } - } - else - { - fJabberHandler->RequestVCard(presence->GetJid()); - } - } - -} diff --git a/libs/libjabber/VCardManager.h b/libs/libjabber/VCardManager.h deleted file mode 100644 index ffdedb9..0000000 --- a/libs/libjabber/VCardManager.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef VCardManager_H_ -#define VCardManager_H_ - -#include -#include -#include - -class JabberHandler; -class JabberPresence; -class JabberContact; -class JabberVCard; - -class VCardManager -{ - public: - VCardManager(JabberHandler* jabberHandler); - - protected: - friend class JabberHandler; - - void RefinePresence(JabberPresence*); - void VCardReceived(JabberContact*); - - private: - - void SaveCache(); - - JabberHandler* fJabberHandler; - BMessage fCache; - BPath fCachePath; - BDirectory fCacheFolder; - -}; -#endif diff --git a/protocols/Jamfile b/protocols/Jamfile index c4f414f..6059de1 100644 --- a/protocols/Jamfile +++ b/protocols/Jamfile @@ -2,5 +2,3 @@ SubDir TOP protocols ; # Include all the components. SubInclude TOP protocols aim ; -SubInclude TOP protocols gtalk ; -SubInclude TOP protocols facebook ; diff --git a/protocols/facebook/Facebook.cpp b/protocols/facebook/Facebook.cpp deleted file mode 100644 index 79d399f..0000000 --- a/protocols/facebook/Facebook.cpp +++ /dev/null @@ -1,854 +0,0 @@ -#include -#include - -#include - -#include -#include - -#include "CayaProtocolMessages.h" -#include "Facebook.h" - -const char* kProtocolSignature = "facebook"; -const char* kProtocolName = "Facebook"; - -int64 idsms = 0; - - -Facebook::Facebook() - : JabberHandler("jabberHandler", fPlug = new JabberSocketPlug()), - fUsername(""), - fServer("chat.facebook.com"), - fPassword("") -{ -} - - -Facebook::~Facebook() -{ - Shutdown(); -} - - -status_t -Facebook::Init(CayaProtocolMessengerInterface* msgr) -{ - fServerMsgr = msgr; - fRostered = false; - fAgent = false; - fFullLogged = false; - fPerc = 0.0; - fLaterBuddyList = new StrList(); - - return B_OK; -} - - -status_t -Facebook::Shutdown() -{ - LogOff(); - - fLaterBuddyList->clear(); - delete fLaterBuddyList; - -// thread_id plug = fPlug->Thread(); -// BMessenger(fPlug).SendMessage(B_QUIT_REQUESTED); - fPlug = NULL; - - int32 res = 0; -// wait_for_thread(plug, &res); - - return B_OK; -} - - -status_t -Facebook::Process(BMessage* msg) -{ - switch (msg->what) { - case IM_MESSAGE: - { - int32 im_what = 0; - - msg->FindInt32("im_what", &im_what); - - switch (im_what) { - case IM_SET_NICKNAME: - { - BString nick; - - if (msg->FindString("nick", &nick) == B_OK) - SetOwnNickname(nick); - break; - } - case IM_SET_OWN_STATUS: - { - int32 status = msg->FindInt32("status"); - BString status_msg(""); - msg->FindString("message", &status_msg); - - switch (status) { - case CAYA_ONLINE: - if (!IsAuthorized()) { - if (fServer == "") - Error("Empty Server!", NULL); - if (fUsername == "") - Error("Empty Username!", NULL); - if (fPassword == "") - Error("Empty Password!",NULL); - - Progress("Facebook Login", "Facebook: Connecting...", 0.0f); - SetStatus(S_ONLINE, ""); - RequestVCard(GetJid()); //by default we ask for our own vCard. - } else { - SetStatus(S_ONLINE, ""); - SetAway(false); - } - break; - case CAYA_AWAY: - if (IsAuthorized()) { - SetStatus(S_AWAY, status_msg); - SetAway(true); - } - break; - case CAYA_EXTENDED_AWAY: - if (IsAuthorized()) { - SetStatus(S_XA, status_msg); - SetAway(true); - } - break; - case CAYA_DO_NOT_DISTURB: - if (IsAuthorized()) { - SetStatus(S_DND, status_msg); - } - break; - case CAYA_OFFLINE: - SetStatus(S_OFFLINE, ""); - break; - default: - Error("Invalid", NULL); - break; - } - break; - } - case IM_SEND_MESSAGE: - { - const char* buddy = msg->FindString("id"); - const char* sms = msg->FindString("body"); - - JabberMessage jm; - jm.SetTo(buddy); - jm.SetFrom(GetJid()); - jm.SetBody(sms); - TimeStamp(jm); - - // Not the right place.. see Jabber::Message - JabberContact* contact = getContact(buddy); - - //tmp: new mess id! - BString messid("caya"); - messid << idsms; - idsms++; - - if (contact) - jm.SetID(messid); - - SendMessage(jm); - MessageSent(buddy,sms); - break; - } - case IM_REGISTER_CONTACTS: - { - type_code garbage; - int32 count = 0; - msg->GetInfo("id", &garbage, &count); - - if (count > 0) { - for (int i = 0; msg->FindString("id", i); i++) { - const char* id = msg->FindString("id", i); - JabberContact* contact = getContact(id); - if (contact) - BuddyStatusChanged(contact); - else { - // Are we on-line? - // send auth req? - if (fFullLogged) { - AddContact(id, id, ""); - BuddyStatusChanged(id, CAYA_OFFLINE); - } else { - // we add to a temp list. - // when logged in we will register the new buddy... - fLaterBuddyList->push_back(BString(id)); - } - } - } - } else - return B_ERROR; - break; - } - case IM_UNREGISTER_CONTACTS: - { - const char* buddy = NULL; - - for (int i = 0; msg->FindString("id", i, &buddy) == B_OK; i++) { - //LOG(kProtocolSignature, liDebug, "Unregister Contact: '%s'", buddy); - - if (!fFullLogged) - BuddyStatusChanged(buddy, CAYA_OFFLINE); - else { - //LOG(kProtocolSignature, liDebug, "Unregister Contact DOING IT"); - JabberContact* contact = getContact(buddy); - if (contact) - RemoveContact(contact); - } - } - break; - } - case IM_USER_STARTED_TYPING: - { - const char* id = NULL; - - if (msg->FindString("id", &id) == B_OK) { - JabberContact* contact=getContact(id); - if (contact) - StartComposingMessage(contact); - } - break; - } - case IM_USER_STOPPED_TYPING: - { - const char* id = NULL; - - if (msg->FindString("id", &id) == B_OK) { - JabberContact* contact = getContact(id); - if (contact && (contact->GetLastMessageID().ICompare("") != 0)) { - StopComposingMessage(contact); - contact->SetLastMessageID(""); - } - } - break; - } - case IM_GET_CONTACT_INFO: - SendContactInfo(msg->FindString("id")); - break; - case IM_ASK_AUTHORIZATION: - { - if (!IsAuthorized()) - return B_ERROR; - - const char* id = msg->FindString("id"); - int32 button = msg->FindInt32("which"); - - if (button == 0) { - // Authorization granted - AcceptSubscription(id); - BMessage im_msg(IM_MESSAGE); - im_msg.AddInt32("im_what", IM_CONTACT_AUTHORIZED); - im_msg.AddString("protocol", kProtocolSignature); - im_msg.AddString("id", id); - im_msg.AddString("message", ""); - fServerMsgr->SendMessage(&im_msg); - - // Now we want to see you! ;) - AddContact(id, id, ""); - } else { - // Authorization rejected - Error("Authorization rejected!",id); - } - break; - } - case IM_SPECIAL_TO_PROTOCOL: - Send(msg->FindString("direct_data")); - break; - default: - // We don't handle this im_what code - //LOG(kProtocolSignature, liDebug, "Got unhandled message: %ld", im_what); - msg->PrintToStream(); - return B_ERROR; - } - break; - } - default: - // We don't handle this what code - return B_ERROR; - } - - return B_OK; -} - - -const char* -Facebook::Signature() const -{ - return kProtocolSignature; -} - - -const char* -Facebook::FriendlySignature() const -{ - return kProtocolName; -} - - -status_t -Facebook::UpdateSettings(BMessage* msg) -{ - const char* username = NULL; - const char* password = NULL; - const char* res = NULL; - - msg->FindString("username", &username); - msg->FindString("password", &password); - msg->FindString("resource", &res); - - if ((username == NULL) || (password == NULL)) { - //LOG( kProtocolSignature, liHigh, "Invalid settings!"); - printf("Invalid settings"); - return B_ERROR; - } - - fUsername = username; - int32 atpos=fUsername.FindLast("@"); - if (atpos> 0) { - BString server; - fUsername.CopyInto(server,atpos + 1,fUsername.Length()-atpos); - fUsername.Remove(atpos,fUsername.Length()-atpos); - fServer = server; - } else - fServer.SetTo("chat.facebook.com"); - - fPassword = password; - - SetUsername(fUsername); - SetHost(fServer); - SetPassword(fPassword); - - if (strlen(res)==0) - SetResource("caya"); - else - SetResource(res); - - SetPriority(5); - SetPort(5222); - - return B_OK; -} - - -uint32 -Facebook::GetEncoding() -{ - return 0xffff; // No conversion, Facebook handles UTF-8 ??? -} - - -// JabberManager stuff - - -void -Facebook::Error(const char* message, const char* who) -{ - //LOG("Facebook", liDebug, "Facebook::Error(%s,%s)", message, who); - - BMessage msg(IM_ERROR); - msg.AddString("protocol", kProtocolSignature); - if (who) - msg.AddString("id", who); - msg.AddString("error", message); - - fServerMsgr->SendMessage( &msg ); -} - - -void -Facebook::GotMessage(const char* from, const char* message) -{ - //LOG("Facebook", liDebug, "Facebook::GotMessage()"); - - BMessage msg(IM_MESSAGE); - msg.AddInt32("im_what", IM_MESSAGE_RECEIVED); - msg.AddString("protocol", kProtocolSignature); - msg.AddString("id", from); - msg.AddString("body", message); - - fServerMsgr->SendMessage( &msg ); -} - - -void -Facebook::MessageSent(const char* to, const char* message) -{ - //LOG("Facebook", liDebug, "Facebook::GotMessage()"); - - BMessage msg(IM_MESSAGE); - msg.AddInt32("im_what", IM_MESSAGE_SENT); - msg.AddString("protocol", kProtocolSignature); - msg.AddString("id", to); - msg.AddString("body", message); - - fServerMsgr->SendMessage( &msg ); -} - - -void -Facebook::LoggedIn() -{ - Progress("Facebook Login", "Facebook: Logged in!", 1.00); - - BMessage msg(IM_MESSAGE); - msg.AddInt32("im_what", IM_OWN_STATUS_SET); - msg.AddString("protocol", kProtocolSignature); - msg.AddInt32("status", CAYA_ONLINE); - - fServerMsgr->SendMessage(&msg); - - fFullLogged = true; - - - - while (fLaterBuddyList->size() != 0) { - BString id = *(fLaterBuddyList->begin()); - fLaterBuddyList->pop_front(); // removes first item - JabberContact* contact=getContact(id.String()); - if (!contact) { - AddContact(id.String(),id.String(),""); - BuddyStatusChanged(id.String(), CAYA_OFFLINE); - } - } - -} - - -void -Facebook::SetAway(bool away) -{ - //LOG("Facebook", liDebug, "Facebook::SetAway()"); - - BMessage msg(IM_MESSAGE); - msg.AddInt32("im_what", IM_STATUS_SET); - msg.AddString("protocol", kProtocolSignature); - if ( away ) - msg.AddInt32("status", CAYA_AWAY); - else - msg.AddInt32("status", CAYA_ONLINE); - - fServerMsgr->SendMessage( &msg ); -} - - -void -Facebook::LoggedOut() -{ - //LOG("Facebook", liDebug, "Facebook::LoggedOut()"); - - BMessage msg(IM_MESSAGE); - msg.AddInt32("im_what", IM_STATUS_SET); - msg.AddString("protocol", kProtocolSignature); - msg.AddInt32("status", CAYA_OFFLINE); - fServerMsgr->SendMessage(&msg); - fFullLogged = false; - fRostered = false; - fAgent = false; - fPerc = 0.0; -} - - -void -Facebook::BuddyStatusChanged(JabberContact* who) -{ - BuddyStatusChanged(who->GetPresence()); -} - - -void -Facebook::BuddyStatusChanged(JabberPresence* jp) -{ - //LOG("Facebook", liDebug, "Facebook::BuddyStatusChanged(%s)",jp->GetJid().String()); - - //avoid a receiving self status changes or empty status: - if (jp->GetJid() == "" || jp->GetJid().ICompare(GetJid()) == 0) - return; - - BMessage msg(IM_MESSAGE); - msg.AddInt32("im_what", IM_STATUS_SET); - msg.AddString("protocol", kProtocolSignature); - msg.AddString("id", jp->GetJid()); - msg.AddString("resource", jp->GetResource()); - - AddStatusString(jp, &msg); - fServerMsgr->SendMessage(&msg); -} - - -void -Facebook::AddStatusString(JabberPresence* jp, BMessage* msg) -{ - int32 show = jp->GetShow(); - switch (show) { - case S_XA: - msg->AddInt32("status", CAYA_EXTENDED_AWAY); - break; - case S_AWAY: - msg->AddInt32("status", CAYA_AWAY); - break; - case S_ONLINE: - msg->AddInt32("status", CAYA_ONLINE); - break; - case S_DND: - msg->AddInt32("status", CAYA_DO_NOT_DISTURB); - break; - case S_CHAT: - msg->AddInt32("status", CAYA_ONLINE); - break; - case S_SEND: - msg->AddInt32("status", CAYA_ONLINE); - break; - default: - msg->AddInt32("status", CAYA_OFFLINE); - break; - } - - if (jp->GetType().ICompare("unavailable") == 0) - msg->AddInt32("status", CAYA_OFFLINE); - - msg->AddString("message", jp->GetStatus()); -} - - -void -Facebook::BuddyStatusChanged(const char* who, CayaStatus status) -{ - //LOG("Facebook", liDebug, "Facebook::BuddyStatusChanged(%s,%s)",who,status); - - BMessage msg(IM_MESSAGE); - msg.AddInt32("im_what", IM_STATUS_SET); - msg.AddString("protocol", kProtocolSignature); - msg.AddString("id", who); - msg.AddInt32("status", status); - - fServerMsgr->SendMessage( &msg ); -} - - -void -Facebook::Progress(const char* id, const char* message, float progress) -{ - BMessage msg(IM_MESSAGE); - msg.AddInt32("im_what", IM_PROGRESS ); - msg.AddString("protocol", kProtocolSignature); - msg.AddString("progressID", id); - msg.AddString("message", message); - msg.AddFloat("progress", progress); - msg.AddInt32("state", 11); //IM_impsConnecting ); - - fServerMsgr->SendMessage(&msg); -} - - -JabberContact* -Facebook::getContact(const char* id) -{ - RosterList *rl = getRosterList(); - JabberContact* contact = NULL; - //LOG(kProtocolSignature, liDebug, "getContact %s", id); - - for(int32 i = 0; i < rl->CountItems(); i++) { - contact = reinterpret_cast(getRosterList()->ItemAt(i)); - //LOG(kProtocolSignature, liDebug, "getContact [%3d] GetJID %s", i,contact->GetJid().String()); - - if (contact->GetJid().ICompare(id) == 0) { - //LOG(kProtocolSignature, liDebug, "getContact found!"); - return contact; - } - } - - return NULL; -} - -void -Facebook::SendContactInfo(const JabberContact* jid) -{ - int32 what = IM_CONTACT_INFO; - BMessage msg(IM_MESSAGE); - msg.AddInt32("im_what", what); - msg.AddString("protocol", kProtocolSignature); - msg.AddString("id", jid->GetJid()); - msg.AddString("name ", jid->GetName()); - - // vCard information - JabberVCard* vCard = jid->GetVCard(); - if (vCard) { - msg.AddString("full name", vCard->GetFullName()); - msg.AddString("first name", vCard->GetGivenName()); - msg.AddString("middle name", vCard->GetMiddleName()); - msg.AddString("last name", vCard->GetFamilyName()); - msg.AddString("email", vCard->GetEmail()); - msg.AddString("birthday", vCard->GetBirthday()); - msg.AddString("url", vCard->GetURL()); - - entry_ref ref; - if (get_ref_for_path(vCard->GetCachedPhotoFile().String(), &ref) == B_OK) - msg.AddRef("ref", &ref); - } - - // Send contact information - fServerMsgr->SendMessage(&msg); -} - -void -Facebook::SendContactInfo(const char* id) -{ - JabberContact* jid = getContact(id); - if (!jid) - return; - - SendContactInfo(jid); -} - - -void -Facebook::SendBuddyIcon(const char* id) -{ - JabberContact* jid = getContact(id); - if (!jid) - return; - - // vCard information - JabberVCard* vCard = jid->GetVCard(); - if (vCard) { - BString data = vCard->GetPhotoContent(); - - BMessage msg(IM_MESSAGE); - msg.AddInt32("im_what", IM_SET_OWN_AVATAR); - msg.AddString("protocol", kProtocolSignature); - msg.AddString("id", id); - msg.AddData("icondata", B_RAW_TYPE, data.String(), data.Length()); - fServerMsgr->SendMessage(&msg); - } -} - - -// Callbacks - -void -Facebook::Authorized() -{ - SetAway(false); - - fPerc +=0.3333f; - - Progress("Facebook Login", "Facebook: Authorized", fPerc); - //LOG(kProtocolSignature, liDebug, "Facebook:Login %f - Authorized",fPerc) ; - CheckLoginStatus(); - - JabberHandler::Authorized(); -} - - -void -Facebook::Message(JabberMessage* message) -{ - // We have something to tell - if (message->GetBody() != "") - GotMessage(message->GetFrom().String(), message->GetBody().String()); - - // Not a nice situation.. - if(message->GetError() != "") { - Error(message->GetError().String(),message->GetFrom().String()); - return; - } - - //LOG(kProtocolSignature, liHigh, "GETX: '%s'",message->GetX().String()) ; - - if (message->GetX().ICompare("composing") == 0) { - // Someone send a composing event... - if (message->GetBody() == "") { - //LOG(kProtocolSignature, liHigh,"CONTACT_STARTED_TYPING"); - BMessage im_msg(IM_MESSAGE); - im_msg.AddInt32("im_what", IM_CONTACT_STARTED_TYPING); - im_msg.AddString("protocol", kProtocolSignature); - im_msg.AddString("id", message->GetFrom()); - fServerMsgr->SendMessage(&im_msg); - } else { - // where we put the last messge id? on the contact (is it the right place?) - // maybe we should make an hash table? a BMesage.. - JabberContact* contact = getContact(message->GetFrom().String()); - if(contact) - contact->SetLastMessageID(message->GetID()); - } - } else if (message->GetX().ICompare("jabber:x:event") == 0) { - //not define event this maybe due to: - // unkown event. - // no event (means stop all) - - //LOG(kProtocolSignature, liHigh,"CONTACT_STOPPED_TYPING"); - - BMessage im_msg(IM_MESSAGE); - im_msg.AddInt32("im_what", IM_CONTACT_STOPPED_TYPING); - im_msg.AddString("protocol", kProtocolSignature); - im_msg.AddString("id", message->GetFrom()); - fServerMsgr->SendMessage(&im_msg); - } -} - - -void -Facebook::Presence(JabberPresence* presence) -{ - BuddyStatusChanged(presence); -} - - -void -Facebook::Roster(RosterList* roster) -{ - // Fix me! (Roster message can arrive at different times) - BMessage serverBased(IM_MESSAGE); - serverBased.AddInt32("im_what", IM_CONTACT_LIST); - serverBased.AddString("protocol", kProtocolSignature); - JabberContact* contact; - int size = roster->CountItems(); - - for(int32 i = 0; i < size; i++) { - contact = reinterpret_cast(roster->ItemAt(i)); - serverBased.AddString("id", contact->GetJid()); - } - - fServerMsgr->SendMessage(&serverBased); - - for (int32 i=0; i < size; i++) { - contact = reinterpret_cast(roster->ItemAt(i)); - SendContactInfo(contact); - } - - // Here the case when more than one roster message has arrived! - if(!fRostered) { - fPerc += 0.3333f; - fRostered = true; - Progress("Facebook Login", "Facebook: Roster", fPerc); - } - - //LOG(kProtocolSignature, liDebug, "Facebook:Login %f - Rostered",fPerc) ; - CheckLoginStatus(); -} - - -void -Facebook::Agents(AgentList* agents) -{ - fPerc +=0.3333f; - fAgent = true; - Progress("Facebook Login", "Facebook: Agents", fPerc); - //LOG(kProtocolSignature, liDebug, "Facebook:Login %f - Agents",fPerc) ; - CheckLoginStatus(); -} - - -void -Facebook::Disconnected(const BString& reason) -{ - LoggedOut(); - - if (reason == "") - return; - - Error(reason.String(),NULL); -} - - -void -Facebook::SubscriptionRequest(JabberPresence* presence) -{ - BMessage im_msg(IM_MESSAGE); - im_msg.AddInt32("im_what", IM_AUTHORIZATION_REQUEST); - im_msg.AddString("protocol", kProtocolSignature); - im_msg.AddString("id", presence->GetJid()); - im_msg.AddString("message", presence->GetStatus()); - - fServerMsgr->SendMessage(&im_msg); -} - - -void -Facebook::Unsubscribe(JabberPresence* presence) -{ - // What should we do when a people unsubscrive from us? - //debugger("Unsubscribe"); - //LOG("Facebook", liDebug, "Facebook::Unsubscribe()"); - - BMessage msg(IM_MESSAGE); - msg.AddInt32("im_what", IM_STATUS_SET); - msg.AddString("protocol", kProtocolSignature); - msg.AddString("id", presence->GetJid()); - msg.AddInt32("status", CAYA_OFFLINE); - fServerMsgr->SendMessage(&msg); -} - - -void -Facebook::OwnContactInfo(JabberContact* contact) -{ - int32 what = IM_OWN_CONTACT_INFO; - - BMessage msg(IM_MESSAGE); - msg.AddInt32("im_what", what); - msg.AddString("protocol", kProtocolSignature); - msg.AddString("id", contact->GetJid()); - msg.AddString("name", contact->GetName()); - - // vCard information - JabberVCard* vCard = contact->GetVCard(); - if (vCard) { - msg.AddString("full name", vCard->GetFullName()); - msg.AddString("first name", vCard->GetGivenName()); - msg.AddString("middle name", vCard->GetMiddleName()); - msg.AddString("last name", vCard->GetFamilyName()); - msg.AddString("email", vCard->GetEmail()); - msg.AddString("birthday", vCard->GetBirthday()); - msg.AddString("url", vCard->GetURL()); - - entry_ref ref; - if (get_ref_for_path(vCard->GetCachedPhotoFile().String(), &ref) == B_OK) - msg.AddRef("ref", &ref); - } - - // Send information - fServerMsgr->SendMessage(&msg); -} - - -void -Facebook::GotBuddyPhoto(const BString& jid, const BString& imagePath) -{ - BMessage msg(IM_MESSAGE); - - msg.AddInt32("im_what", IM_AVATAR_SET); - msg.AddString("protocol", kProtocolSignature); - msg.AddString("id", jid); - - entry_ref ref; - if (get_ref_for_path(imagePath.String(), &ref) == B_OK) - msg.AddRef("ref", &ref); - - fServerMsgr->SendMessage(&msg); -} - - -void -Facebook::Registration(JabberRegistration* registration) -{ - // Just created a new account ? - // or we have ack of a registration? ack of registartion! - registration->PrintToStream(); - debugger("Registration"); -} - - -void -Facebook::CheckLoginStatus() -{ - if (fRostered && fAgent && !fFullLogged) - LoggedIn(); -} diff --git a/protocols/facebook/Facebook.h b/protocols/facebook/Facebook.h deleted file mode 100644 index 34df778..0000000 --- a/protocols/facebook/Facebook.h +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright 2004-2009, IM Kit Team. All rights reserved. - * Distributed under the terms of the MIT License. - */ - -#ifndef CAYA_Facebook_H -#define CAYA_Facebook_H - -#include - -#include -#include -#include - -#include -#include - -#include "CayaProtocol.h" -#include "CayaConstants.h" - -//class FacebookConnection; -class JabberSocketPlug; - -#define RosterList BObjectList -#define AgentList BObjectList - -class Facebook : public JabberManager, public JabberHandler, public CayaProtocol { -public: - - Facebook(); - virtual ~Facebook(); - - // IM::Protocol part begins here - // messenger to im_server - virtual status_t Init( CayaProtocolMessengerInterface* ); - - // called before unloading from memory - virtual status_t Shutdown(); - - // process message - virtual status_t Process( BMessage * ); - - // Get name of protocol - virtual const char * Signature() const; - virtual const char * FriendlySignature() const; - - // settings changed - virtual status_t UpdateSettings( BMessage * ); - - // preferred encoding of messages - virtual uint32 GetEncoding(); - // IM::Protocol part ends here - - virtual CayaProtocolMessengerInterface* MessengerInterface() const { return fServerMsgr; } - - // JabberManager part begins here - virtual void Error( const char * message, const char * who ); - - virtual void GotMessage( const char * from, const char * msg ); - virtual void MessageSent( const char * to, const char * msg ); - - virtual void LoggedIn(); - virtual void SetAway(bool); - virtual void LoggedOut(); - - //virtual void GotBuddyList( std::list & ); - virtual void BuddyStatusChanged( const char * who, CayaStatus status ); - virtual void BuddyStatusChanged( JabberContact* who ); - virtual void BuddyStatusChanged( JabberPresence* who ); - // JabberManager part ends here - -private: - JabberSocketPlug* fPlug; - CayaProtocolMessengerInterface* fServerMsgr; - - BString fUsername; - BString fServer; - BString fPassword; - - typedef std::list StrList; // new buddy added when off-line. - StrList* fLaterBuddyList; - - //special client - //StrList fSpecialUID; - BMessage fSpecialUID; - - bool fRostered; - bool fAgent; - float fPerc; - bool fFullLogged; - - void Progress( const char * id, const char * message, float progress ); - - JabberContact* getContact(const char* id); - void SendContactInfo(const char* id); - void SendContactInfo(const JabberContact* jid); - void SendBuddyIcon(const char* id); - void AddStatusString(JabberPresence* who ,BMessage* to); - - void CheckLoginStatus(); - -// Callbacks from JabberHandler -protected: - virtual void Authorized(); - virtual void Message(JabberMessage * message); - virtual void Presence(JabberPresence * presence); - virtual void Roster(RosterList * roster); - virtual void Agents(AgentList * agents); - virtual void Disconnected(const BString & reason) ; - virtual void SubscriptionRequest(JabberPresence * presence) ; - virtual void Registration(JabberRegistration * registration) ; - virtual void Unsubscribe(JabberPresence * presence); - virtual void OwnContactInfo(JabberContact* contact); - virtual void GotBuddyPhoto(const BString & jid, const BString & imagePath); -}; - -extern const char* kProtocolSignature; -extern const char* kProtocolName; - -#endif // CAYA_Facebook_H diff --git a/protocols/facebook/Jamfile b/protocols/facebook/Jamfile deleted file mode 100644 index d7bc973..0000000 --- a/protocols/facebook/Jamfile +++ /dev/null @@ -1,19 +0,0 @@ -SubDir TOP protocols facebook ; - -SubDirSysHdrs [ FDirName $(TOP) ] ; -SubDirSysHdrs [ FDirName $(TOP) application ] ; -SubDirSysHdrs [ FDirName $(TOP) libs ] ; -SubDirSysHdrs [ FDirName $(TOP) libs libjabber ] ; - -AddOn facebook : - main.cpp - Facebook.cpp - : be libjabber.a $(TARGET_LIBSTDC++) expat network - : facebook.rdef settings_template.rdef -; - -Depends facebook : libjabber.a ; - -LINKFLAGS on facebook += -L$(OPENSSL_LIBRARY_DIR) ; - -InstallBin $(CAYA_DIRECTORY)/protocols : facebook ; diff --git a/protocols/facebook/facebook.rdef b/protocols/facebook/facebook.rdef deleted file mode 100644 index 308e03c..0000000 --- a/protocols/facebook/facebook.rdef +++ /dev/null @@ -1,34 +0,0 @@ - -resource app_version { - major = 0, - middle = 0, - minor = 0, - - variety = B_APPV_ALPHA, - internal = 0, - - short_info = "Google Talk Protocol for Caya", - long_info = "©2009-2010 Andrea Anzani, Pier Luigi Fiorini" -}; - -resource vector_icon { - $"6E636966080501040046020106023E40000000000000003D4000494000470000" - $"7EFFFFFFFFE5E1DA02000602000000BBC0004000000000009220244AF0000000" - $"33CCFC3366FF02000602000000BA000040000000000092202448800000336699" - $"FF6699CC02000602000000B9000040000000000092202448E00000CC0000FFFF" - $"000002000602000000BA000040000000000092202448800000FF9900FFFBFF00" - $"02000602000000BA000040000000000092202448800000006600FF00CC000A02" - $"06C22622C7562239222E342E2B2E3D4146364441483C50404C3C504A444A4E55" - $"44CBB634CBB83E5E2A0206C22622C7562239222E342E2B2E3D4146364441483C" - $"50404C3C504C464A505744CBB634CBB83E5E2A02024C265928532A583B59335D" - $"350610CAFFFEAF375335543B3B5A3B5A395D325D355D2C5D274F275627483241" - $"2C413541BDA7C2A83942BDA7C2A8394A3F463F463C40324036402A40234F2346" - $"2358325E2A5E395EBF5C5A3F5CBF5C5A3F544053080234313C310404FE372C37" - $"393739373A393B383B3A3B3B393B3A3B390406FE0B4536403640363F363E383E" - $"373E383E393E393E3A403B3F3B413B453A0405FE03453C453445344533433244" - $"324332403240323F323E343E333E3408024D2C4D3C0803553C4F3655300D0A00" - $"01001001178400040A020101000A010102000A0101032021210A010204053021" - $"2101178200040A0102070630212101178200040A010108301D2101178200040A" - $"0102090830212101178200040A030103000A040204051001178200040A050207" - $"061001178200040A060108301C2001178200040A07020908100117820004" -}; diff --git a/protocols/facebook/main.cpp b/protocols/facebook/main.cpp deleted file mode 100644 index 673114a..0000000 --- a/protocols/facebook/main.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include "Facebook.h" - -extern "C" __declspec(dllexport) CayaProtocol* protocol(); -extern "C" __declspec(dllexport) const char* signature(); -extern "C" __declspec(dllexport) const char* friendly_signature(); - -CayaProtocol* -protocol() -{ - return (CayaProtocol*)new Facebook(); -} - - -const char* -signature() -{ - return kProtocolSignature; -} - - -const char* -friendly_signature() -{ - return kProtocolName; -} diff --git a/protocols/facebook/settings_template.rdef b/protocols/facebook/settings_template.rdef deleted file mode 100644 index 2f20c4d..0000000 --- a/protocols/facebook/settings_template.rdef +++ /dev/null @@ -1,19 +0,0 @@ -resource(1000) message('IMst') { - "setting" = message { - "name" = "username", - "description" = "Username", - int32 "type" = 'CSTR' - }, - "setting" = message { - "name" = "password", - "description" = "Password", - int32 "type" = 'CSTR', - "is_secret" = true - }, - "setting" = message { - "name" = "resource", - "description" = "Resource", - int32 "type" = 'CSTR', - "default" = "Caya" - } -}; diff --git a/protocols/gtalk/GoogleTalk.cpp b/protocols/gtalk/GoogleTalk.cpp deleted file mode 100644 index 7200092..0000000 --- a/protocols/gtalk/GoogleTalk.cpp +++ /dev/null @@ -1,854 +0,0 @@ -#include -#include - -#include - -#include -#include - -#include "CayaProtocolMessages.h" -#include "GoogleTalk.h" - -const char* kProtocolSignature = "gtalk"; -const char* kProtocolName = "Google Talk"; - -int64 idsms = 0; - - -GoogleTalk::GoogleTalk() - : JabberHandler("jabberHandler", fPlug = new JabberSSLPlug("talk.google.com", 5223)), - fUsername(""), - fServer("gmail.com"), - fPassword("") -{ -} - - -GoogleTalk::~GoogleTalk() -{ - Shutdown(); -} - - -status_t -GoogleTalk::Init(CayaProtocolMessengerInterface* msgr) -{ - fServerMsgr = msgr; - fRostered = false; - fAgent = false; - fFullLogged = false; - fPerc = 0.0; - fLaterBuddyList = new StrList(); - - return B_OK; -} - - -status_t -GoogleTalk::Shutdown() -{ - LogOff(); - - fLaterBuddyList->clear(); - delete fLaterBuddyList; - - thread_id plug = fPlug->Thread(); - BMessenger(fPlug).SendMessage(B_QUIT_REQUESTED); - fPlug = NULL; - - int32 res = 0; - wait_for_thread(plug, &res); - - return B_OK; -} - - -status_t -GoogleTalk::Process(BMessage* msg) -{ - switch (msg->what) { - case IM_MESSAGE: - { - int32 im_what = 0; - - msg->FindInt32("im_what", &im_what); - - switch (im_what) { - case IM_SET_NICKNAME: - { - BString nick; - - if (msg->FindString("nick", &nick) == B_OK) - SetOwnNickname(nick); - break; - } - case IM_SET_OWN_STATUS: - { - int32 status = msg->FindInt32("status"); - BString status_msg(""); - msg->FindString("message", &status_msg); - - switch (status) { - case CAYA_ONLINE: - if (!IsAuthorized()) { - if (fServer == "") - Error("Empty Server!", NULL); - if (fUsername == "") - Error("Empty Username!", NULL); - if (fPassword == "") - Error("Empty Password!",NULL); - - Progress("GoogleTalk Login", "GoogleTalk: Connecting...", 0.0f); - SetStatus(S_ONLINE, ""); - RequestVCard(GetJid()); //by default we ask for our own vCard. - } else { - SetStatus(S_ONLINE, ""); - SetAway(false); - } - break; - case CAYA_AWAY: - if (IsAuthorized()) { - SetStatus(S_AWAY, status_msg); - SetAway(true); - } - break; - case CAYA_EXTENDED_AWAY: - if (IsAuthorized()) { - SetStatus(S_XA, status_msg); - SetAway(true); - } - break; - case CAYA_DO_NOT_DISTURB: - if (IsAuthorized()) { - SetStatus(S_DND, status_msg); - } - break; - case CAYA_OFFLINE: - SetStatus(S_OFFLINE, ""); - break; - default: - Error("Invalid", NULL); - break; - } - break; - } - case IM_SEND_MESSAGE: - { - const char* buddy = msg->FindString("id"); - const char* sms = msg->FindString("body"); - - JabberMessage jm; - jm.SetTo(buddy); - jm.SetFrom(GetJid()); - jm.SetBody(sms); - TimeStamp(jm); - - // Not the right place.. see Jabber::Message - JabberContact* contact = getContact(buddy); - - //tmp: new mess id! - BString messid("caya"); - messid << idsms; - idsms++; - - if (contact) - jm.SetID(messid); - - SendMessage(jm); - MessageSent(buddy,sms); - break; - } - case IM_REGISTER_CONTACTS: - { - type_code garbage; - int32 count = 0; - msg->GetInfo("id", &garbage, &count); - - if (count > 0) { - for (int i = 0; msg->FindString("id", i); i++) { - const char* id = msg->FindString("id", i); - JabberContact* contact = getContact(id); - if (contact) - BuddyStatusChanged(contact); - else { - // Are we on-line? - // send auth req? - if (fFullLogged) { - AddContact(id, id, ""); - BuddyStatusChanged(id, CAYA_OFFLINE); - } else { - // we add to a temp list. - // when logged in we will register the new buddy... - fLaterBuddyList->push_back(BString(id)); - } - } - } - } else - return B_ERROR; - break; - } - case IM_UNREGISTER_CONTACTS: - { - const char* buddy = NULL; - - for (int i = 0; msg->FindString("id", i, &buddy) == B_OK; i++) { - //LOG(kProtocolSignature, liDebug, "Unregister Contact: '%s'", buddy); - - if (!fFullLogged) - BuddyStatusChanged(buddy, CAYA_OFFLINE); - else { - //LOG(kProtocolSignature, liDebug, "Unregister Contact DOING IT"); - JabberContact* contact = getContact(buddy); - if (contact) - RemoveContact(contact); - } - } - break; - } - case IM_USER_STARTED_TYPING: - { - const char* id = NULL; - - if (msg->FindString("id", &id) == B_OK) { - JabberContact* contact=getContact(id); - if (contact) - StartComposingMessage(contact); - } - break; - } - case IM_USER_STOPPED_TYPING: - { - const char* id = NULL; - - if (msg->FindString("id", &id) == B_OK) { - JabberContact* contact = getContact(id); - if (contact && (contact->GetLastMessageID().ICompare("") != 0)) { - StopComposingMessage(contact); - contact->SetLastMessageID(""); - } - } - break; - } - case IM_GET_CONTACT_INFO: - SendContactInfo(msg->FindString("id")); - break; - case IM_ASK_AUTHORIZATION: - { - if (!IsAuthorized()) - return B_ERROR; - - const char* id = msg->FindString("id"); - int32 button = msg->FindInt32("which"); - - if (button == 0) { - // Authorization granted - AcceptSubscription(id); - BMessage im_msg(IM_MESSAGE); - im_msg.AddInt32("im_what", IM_CONTACT_AUTHORIZED); - im_msg.AddString("protocol", kProtocolSignature); - im_msg.AddString("id", id); - im_msg.AddString("message", ""); - fServerMsgr->SendMessage(&im_msg); - - // Now we want to see you! ;) - AddContact(id, id, ""); - } else { - // Authorization rejected - Error("Authorization rejected!",id); - } - break; - } - case IM_SPECIAL_TO_PROTOCOL: - Send(msg->FindString("direct_data")); - break; - default: - // We don't handle this im_what code - //LOG(kProtocolSignature, liDebug, "Got unhandled message: %ld", im_what); - msg->PrintToStream(); - return B_ERROR; - } - break; - } - default: - // We don't handle this what code - return B_ERROR; - } - - return B_OK; -} - - -const char* -GoogleTalk::Signature() const -{ - return kProtocolSignature; -} - - -const char* -GoogleTalk::FriendlySignature() const -{ - return kProtocolName; -} - - -status_t -GoogleTalk::UpdateSettings(BMessage* msg) -{ - const char* username = NULL; - const char* password = NULL; - const char* res = NULL; - - msg->FindString("username", &username); - msg->FindString("password", &password); - msg->FindString("resource", &res); - - if ((username == NULL) || (password == NULL)) { - //LOG( kProtocolSignature, liHigh, "Invalid settings!"); - printf("Invalid settings"); - return B_ERROR; - } - - fUsername = username; - int32 atpos=fUsername.FindLast("@"); - if (atpos> 0) { - BString server; - fUsername.CopyInto(server,atpos + 1,fUsername.Length()-atpos); - fUsername.Remove(atpos,fUsername.Length()-atpos); - fServer = server; - } else - fServer.SetTo("gmail.com"); - - fPassword = password; - - SetUsername(fUsername); - SetHost(fServer); - SetPassword(fPassword); - - if (strlen(res)==0) - SetResource("caya"); - else - SetResource(res); - - SetPriority(5); - SetPort(5223); - - return B_OK; -} - - -uint32 -GoogleTalk::GetEncoding() -{ - return 0xffff; // No conversion, GoogleTalk handles UTF-8 ??? -} - - -// JabberManager stuff - - -void -GoogleTalk::Error(const char* message, const char* who) -{ - //LOG("GoogleTalk", liDebug, "GoogleTalk::Error(%s,%s)", message, who); - - BMessage msg(IM_ERROR); - msg.AddString("protocol", kProtocolSignature); - if (who) - msg.AddString("id", who); - msg.AddString("error", message); - - fServerMsgr->SendMessage( &msg ); -} - - -void -GoogleTalk::GotMessage(const char* from, const char* message) -{ - //LOG("GoogleTalk", liDebug, "GoogleTalk::GotMessage()"); - - BMessage msg(IM_MESSAGE); - msg.AddInt32("im_what", IM_MESSAGE_RECEIVED); - msg.AddString("protocol", kProtocolSignature); - msg.AddString("id", from); - msg.AddString("body", message); - - fServerMsgr->SendMessage( &msg ); -} - - -void -GoogleTalk::MessageSent(const char* to, const char* message) -{ - //LOG("GoogleTalk", liDebug, "GoogleTalk::GotMessage()"); - - BMessage msg(IM_MESSAGE); - msg.AddInt32("im_what", IM_MESSAGE_SENT); - msg.AddString("protocol", kProtocolSignature); - msg.AddString("id", to); - msg.AddString("body", message); - - fServerMsgr->SendMessage( &msg ); -} - - -void -GoogleTalk::LoggedIn() -{ - Progress("GoogleTalk Login", "GoogleTalk: Logged in!", 1.00); - - BMessage msg(IM_MESSAGE); - msg.AddInt32("im_what", IM_OWN_STATUS_SET); - msg.AddString("protocol", kProtocolSignature); - msg.AddInt32("status", CAYA_ONLINE); - - fServerMsgr->SendMessage(&msg); - - fFullLogged = true; - - - - while (fLaterBuddyList->size() != 0) { - BString id = *(fLaterBuddyList->begin()); - fLaterBuddyList->pop_front(); // removes first item - JabberContact* contact=getContact(id.String()); - if (!contact) { - AddContact(id.String(),id.String(),""); - BuddyStatusChanged(id.String(), CAYA_OFFLINE); - } - } - -} - - -void -GoogleTalk::SetAway(bool away) -{ - //LOG("GoogleTalk", liDebug, "GoogleTalk::SetAway()"); - - BMessage msg(IM_MESSAGE); - msg.AddInt32("im_what", IM_STATUS_SET); - msg.AddString("protocol", kProtocolSignature); - if ( away ) - msg.AddInt32("status", CAYA_AWAY); - else - msg.AddInt32("status", CAYA_ONLINE); - - fServerMsgr->SendMessage( &msg ); -} - - -void -GoogleTalk::LoggedOut() -{ - //LOG("GoogleTalk", liDebug, "GoogleTalk::LoggedOut()"); - - BMessage msg(IM_MESSAGE); - msg.AddInt32("im_what", IM_STATUS_SET); - msg.AddString("protocol", kProtocolSignature); - msg.AddInt32("status", CAYA_OFFLINE); - fServerMsgr->SendMessage(&msg); - fFullLogged = false; - fRostered = false; - fAgent = false; - fPerc = 0.0; -} - - -void -GoogleTalk::BuddyStatusChanged(JabberContact* who) -{ - BuddyStatusChanged(who->GetPresence()); -} - - -void -GoogleTalk::BuddyStatusChanged(JabberPresence* jp) -{ - //LOG("GoogleTalk", liDebug, "GoogleTalk::BuddyStatusChanged(%s)",jp->GetJid().String()); - - //avoid a receiving self status changes or empty status: - if (jp->GetJid() == "" || jp->GetJid().ICompare(GetJid()) == 0) - return; - - BMessage msg(IM_MESSAGE); - msg.AddInt32("im_what", IM_STATUS_SET); - msg.AddString("protocol", kProtocolSignature); - msg.AddString("id", jp->GetJid()); - msg.AddString("resource", jp->GetResource()); - - AddStatusString(jp, &msg); - fServerMsgr->SendMessage(&msg); -} - - -void -GoogleTalk::AddStatusString(JabberPresence* jp, BMessage* msg) -{ - int32 show = jp->GetShow(); - switch (show) { - case S_XA: - msg->AddInt32("status", CAYA_EXTENDED_AWAY); - break; - case S_AWAY: - msg->AddInt32("status", CAYA_AWAY); - break; - case S_ONLINE: - msg->AddInt32("status", CAYA_ONLINE); - break; - case S_DND: - msg->AddInt32("status", CAYA_DO_NOT_DISTURB); - break; - case S_CHAT: - msg->AddInt32("status", CAYA_ONLINE); - break; - case S_SEND: - msg->AddInt32("status", CAYA_ONLINE); - break; - default: - msg->AddInt32("status", CAYA_OFFLINE); - break; - } - - if (jp->GetType().ICompare("unavailable") == 0) - msg->AddInt32("status", CAYA_OFFLINE); - - msg->AddString("message", jp->GetStatus()); -} - - -void -GoogleTalk::BuddyStatusChanged(const char* who, CayaStatus status) -{ - //LOG("GoogleTalk", liDebug, "GoogleTalk::BuddyStatusChanged(%s,%s)",who,status); - - BMessage msg(IM_MESSAGE); - msg.AddInt32("im_what", IM_STATUS_SET); - msg.AddString("protocol", kProtocolSignature); - msg.AddString("id", who); - msg.AddInt32("status", status); - - fServerMsgr->SendMessage( &msg ); -} - - -void -GoogleTalk::Progress(const char* id, const char* message, float progress) -{ - BMessage msg(IM_MESSAGE); - msg.AddInt32("im_what", IM_PROGRESS ); - msg.AddString("protocol", kProtocolSignature); - msg.AddString("progressID", id); - msg.AddString("message", message); - msg.AddFloat("progress", progress); - msg.AddInt32("state", 11); //IM_impsConnecting ); - - fServerMsgr->SendMessage(&msg); -} - - -JabberContact* -GoogleTalk::getContact(const char* id) -{ - RosterList *rl = getRosterList(); - JabberContact* contact = NULL; - //LOG(kProtocolSignature, liDebug, "getContact %s", id); - - for(int32 i = 0; i < rl->CountItems(); i++) { - contact = reinterpret_cast(getRosterList()->ItemAt(i)); - //LOG(kProtocolSignature, liDebug, "getContact [%3d] GetJID %s", i,contact->GetJid().String()); - - if (contact->GetJid().ICompare(id) == 0) { - //LOG(kProtocolSignature, liDebug, "getContact found!"); - return contact; - } - } - - return NULL; -} - -void -GoogleTalk::SendContactInfo(const JabberContact* jid) -{ - int32 what = IM_CONTACT_INFO; - BMessage msg(IM_MESSAGE); - msg.AddInt32("im_what", what); - msg.AddString("protocol", kProtocolSignature); - msg.AddString("id", jid->GetJid()); - msg.AddString("name", jid->GetName()); - - // vCard information - JabberVCard* vCard = jid->GetVCard(); - if (vCard) { - msg.AddString("full name", vCard->GetFullName()); - msg.AddString("first name", vCard->GetGivenName()); - msg.AddString("middle name", vCard->GetMiddleName()); - msg.AddString("last name", vCard->GetFamilyName()); - msg.AddString("email", vCard->GetEmail()); - msg.AddString("birthday", vCard->GetBirthday()); - msg.AddString("url", vCard->GetURL()); - - entry_ref ref; - if (get_ref_for_path(vCard->GetCachedPhotoFile().String(), &ref) == B_OK) - msg.AddRef("ref", &ref); - } - - // Send contact information - fServerMsgr->SendMessage(&msg); -} - -void -GoogleTalk::SendContactInfo(const char* id) -{ - JabberContact* jid = getContact(id); - if (!jid) - return; - - SendContactInfo(jid); -} - - -void -GoogleTalk::SendBuddyIcon(const char* id) -{ - JabberContact* jid = getContact(id); - if (!jid) - return; - - // vCard information - JabberVCard* vCard = jid->GetVCard(); - if (vCard) { - BString data = vCard->GetPhotoContent(); - - BMessage msg(IM_MESSAGE); - msg.AddInt32("im_what", IM_SET_OWN_AVATAR); - msg.AddString("protocol", kProtocolSignature); - msg.AddString("id", id); - msg.AddData("icondata", B_RAW_TYPE, data.String(), data.Length()); - fServerMsgr->SendMessage(&msg); - } -} - - -// Callbacks - -void -GoogleTalk::Authorized() -{ - SetAway(false); - - fPerc +=0.3333f; - - Progress("GoogleTalk Login", "GoogleTalk: Authorized", fPerc); - //LOG(kProtocolSignature, liDebug, "GoogleTalk:Login %f - Authorized",fPerc) ; - CheckLoginStatus(); - - JabberHandler::Authorized(); -} - - -void -GoogleTalk::Message(JabberMessage* message) -{ - // We have something to tell - if (message->GetBody() != "") - GotMessage(message->GetFrom().String(), message->GetBody().String()); - - // Not a nice situation.. - if(message->GetError() != "") { - Error(message->GetError().String(),message->GetFrom().String()); - return; - } - - //LOG(kProtocolSignature, liHigh, "GETX: '%s'",message->GetX().String()) ; - - if (message->GetX().ICompare("composing") == 0) { - // Someone send a composing event... - if (message->GetBody() == "") { - //LOG(kProtocolSignature, liHigh,"CONTACT_STARTED_TYPING"); - BMessage im_msg(IM_MESSAGE); - im_msg.AddInt32("im_what", IM_CONTACT_STARTED_TYPING); - im_msg.AddString("protocol", kProtocolSignature); - im_msg.AddString("id", message->GetFrom()); - fServerMsgr->SendMessage(&im_msg); - } else { - // where we put the last messge id? on the contact (is it the right place?) - // maybe we should make an hash table? a BMesage.. - JabberContact* contact = getContact(message->GetFrom().String()); - if(contact) - contact->SetLastMessageID(message->GetID()); - } - } else if (message->GetX().ICompare("jabber:x:event") == 0) { - //not define event this maybe due to: - // unkown event. - // no event (means stop all) - - //LOG(kProtocolSignature, liHigh,"CONTACT_STOPPED_TYPING"); - - BMessage im_msg(IM_MESSAGE); - im_msg.AddInt32("im_what", IM_CONTACT_STOPPED_TYPING); - im_msg.AddString("protocol", kProtocolSignature); - im_msg.AddString("id", message->GetFrom()); - fServerMsgr->SendMessage(&im_msg); - } -} - - -void -GoogleTalk::Presence(JabberPresence* presence) -{ - BuddyStatusChanged(presence); -} - - -void -GoogleTalk::Roster(RosterList* roster) -{ - // Fix me! (Roster message can arrive at different times) - BMessage serverBased(IM_MESSAGE); - serverBased.AddInt32("im_what", IM_CONTACT_LIST); - serverBased.AddString("protocol", kProtocolSignature); - JabberContact* contact; - int size = roster->CountItems(); - - for(int32 i = 0; i < size; i++) { - contact = reinterpret_cast(roster->ItemAt(i)); - serverBased.AddString("id", contact->GetJid()); - } - - fServerMsgr->SendMessage(&serverBased); - - for (int32 i=0; i < size; i++) { - contact = reinterpret_cast(roster->ItemAt(i)); - SendContactInfo(contact); - } - - // Here the case when more than one roster message has arrived! - if(!fRostered) { - fPerc += 0.3333f; - fRostered = true; - Progress("GoogleTalk Login", "GoogleTalk: Roster", fPerc); - } - - //LOG(kProtocolSignature, liDebug, "GoogleTalk:Login %f - Rostered",fPerc) ; - CheckLoginStatus(); -} - - -void -GoogleTalk::Agents(AgentList* agents) -{ - fPerc +=0.3333f; - fAgent = true; - Progress("GoogleTalk Login", "GoogleTalk: Agents", fPerc); - //LOG(kProtocolSignature, liDebug, "GoogleTalk:Login %f - Agents",fPerc) ; - CheckLoginStatus(); -} - - -void -GoogleTalk::Disconnected(const BString& reason) -{ - LoggedOut(); - - if (reason == "") - return; - - Error(reason.String(),NULL); -} - - -void -GoogleTalk::SubscriptionRequest(JabberPresence* presence) -{ - BMessage im_msg(IM_MESSAGE); - im_msg.AddInt32("im_what", IM_AUTHORIZATION_REQUEST); - im_msg.AddString("protocol", kProtocolSignature); - im_msg.AddString("id", presence->GetJid()); - im_msg.AddString("message", presence->GetStatus()); - - fServerMsgr->SendMessage(&im_msg); -} - - -void -GoogleTalk::Unsubscribe(JabberPresence* presence) -{ - // What should we do when a people unsubscrive from us? - //debugger("Unsubscribe"); - //LOG("GoogleTalk", liDebug, "GoogleTalk::Unsubscribe()"); - - BMessage msg(IM_MESSAGE); - msg.AddInt32("im_what", IM_STATUS_SET); - msg.AddString("protocol", kProtocolSignature); - msg.AddString("id", presence->GetJid()); - msg.AddInt32("status", CAYA_OFFLINE); - fServerMsgr->SendMessage(&msg); -} - - -void -GoogleTalk::OwnContactInfo(JabberContact* contact) -{ - int32 what = IM_OWN_CONTACT_INFO; - - BMessage msg(IM_MESSAGE); - msg.AddInt32("im_what", what); - msg.AddString("protocol", kProtocolSignature); - msg.AddString("id", contact->GetJid()); - msg.AddString("name", contact->GetName()); - - // vCard information - JabberVCard* vCard = contact->GetVCard(); - if (vCard) { - msg.AddString("full name", vCard->GetFullName()); - msg.AddString("first name", vCard->GetGivenName()); - msg.AddString("middle name", vCard->GetMiddleName()); - msg.AddString("last name", vCard->GetFamilyName()); - msg.AddString("email", vCard->GetEmail()); - msg.AddString("birthday", vCard->GetBirthday()); - msg.AddString("url", vCard->GetURL()); - - entry_ref ref; - if (get_ref_for_path(vCard->GetCachedPhotoFile().String(), &ref) == B_OK) - msg.AddRef("ref", &ref); - } - - // Send information - fServerMsgr->SendMessage(&msg); -} - - -void -GoogleTalk::GotBuddyPhoto(const BString& jid, const BString& imagePath) -{ - BMessage msg(IM_MESSAGE); - - msg.AddInt32("im_what", IM_AVATAR_SET); - msg.AddString("protocol", kProtocolSignature); - msg.AddString("id", jid); - - entry_ref ref; - if (get_ref_for_path(imagePath.String(), &ref) == B_OK) - msg.AddRef("ref", &ref); - - fServerMsgr->SendMessage(&msg); -} - - -void -GoogleTalk::Registration(JabberRegistration* registration) -{ - // Just created a new account ? - // or we have ack of a registration? ack of registartion! - registration->PrintToStream(); - debugger("Registration"); -} - - -void -GoogleTalk::CheckLoginStatus() -{ - if (fRostered && fAgent && !fFullLogged) - LoggedIn(); -} diff --git a/protocols/gtalk/GoogleTalk.h b/protocols/gtalk/GoogleTalk.h deleted file mode 100644 index ea618d6..0000000 --- a/protocols/gtalk/GoogleTalk.h +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright 2004-2009, IM Kit Team. All rights reserved. - * Distributed under the terms of the MIT License. - */ -#ifndef IMKIT_GoogleTalk_H -#define IMKIT_GoogleTalk_H - -#include - -#include -#include -#include - -#include -#include - -#include "CayaProtocol.h" -#include "CayaConstants.h" - -class GoogleTalkConnection; -class JabberSSLPlug; - -#define RosterList BObjectList -#define AgentList BObjectList - -class GoogleTalk : public JabberManager, public JabberHandler, public CayaProtocol { -public: - - GoogleTalk(); - virtual ~GoogleTalk(); - - // IM::Protocol part begins here - // messenger to im_server - virtual status_t Init( CayaProtocolMessengerInterface* ); - - // called before unloading from memory - virtual status_t Shutdown(); - - // process message - virtual status_t Process( BMessage * ); - - // Get name of protocol - virtual const char * Signature() const; - virtual const char * FriendlySignature() const; - - // settings changed - virtual status_t UpdateSettings( BMessage * ); - - // preferred encoding of messages - virtual uint32 GetEncoding(); - // IM::Protocol part ends here - - virtual CayaProtocolMessengerInterface* MessengerInterface() const { return fServerMsgr; } - - // JabberManager part begins here - virtual void Error( const char * message, const char * who ); - - virtual void GotMessage( const char * from, const char * msg ); - virtual void MessageSent( const char * to, const char * msg ); - - virtual void LoggedIn(); - virtual void SetAway(bool); - virtual void LoggedOut(); - - //virtual void GotBuddyList( std::list & ); - virtual void BuddyStatusChanged( const char * who, CayaStatus status ); - virtual void BuddyStatusChanged( JabberContact* who ); - virtual void BuddyStatusChanged( JabberPresence* who ); - // JabberManager part ends here - -private: - JabberSSLPlug* fPlug; - CayaProtocolMessengerInterface* fServerMsgr; - - BString fUsername; - BString fServer; - BString fPassword; - - typedef std::list StrList; // new buddy added when off-line. - StrList* fLaterBuddyList; - - //special client - //StrList fSpecialUID; - BMessage fSpecialUID; - - bool fRostered; - bool fAgent; - float fPerc; - bool fFullLogged; - - void Progress( const char * id, const char * message, float progress ); - - JabberContact* getContact(const char* id); - void SendContactInfo(const char* id); - void SendContactInfo(const JabberContact* jid); - void SendBuddyIcon(const char* id); - void AddStatusString(JabberPresence* who ,BMessage* to); - - void CheckLoginStatus(); - -// Callbacks from JabberHandler -protected: - virtual void Authorized(); - virtual void Message(JabberMessage * message); - virtual void Presence(JabberPresence * presence); - virtual void Roster(RosterList * roster); - virtual void Agents(AgentList * agents); - virtual void Disconnected(const BString & reason) ; - virtual void SubscriptionRequest(JabberPresence * presence) ; - virtual void Registration(JabberRegistration * registration) ; - virtual void Unsubscribe(JabberPresence * presence); - virtual void OwnContactInfo(JabberContact* contact); - virtual void GotBuddyPhoto(const BString & jid, const BString & imagePath); -}; - -extern const char* kProtocolSignature; -extern const char* kProtocolName; - -#endif // IMKIT_GoogleTalk_H diff --git a/protocols/gtalk/Jamfile b/protocols/gtalk/Jamfile deleted file mode 100644 index 8b5ec59..0000000 --- a/protocols/gtalk/Jamfile +++ /dev/null @@ -1,20 +0,0 @@ -SubDir TOP protocols gtalk ; - -SubDirSysHdrs [ FDirName $(TOP) ] ; -SubDirSysHdrs [ FDirName $(TOP) application ] ; -SubDirSysHdrs [ FDirName $(TOP) libs ] ; -SubDirSysHdrs [ FDirName $(TOP) libs libjabber ] ; -SubDirSysHdrs [ FDirName $(OPENSSL_INCLUDE_DIR) ] ; - -AddOn gtalk : - main.cpp - GoogleTalk.cpp - : be libjabber.a ssl crypto $(TARGET_LIBSTDC++) expat - : gtalk.rdef settings_template.rdef -; - -Depends gtalk : libjabber.a ; - -LINKFLAGS on gtalk += -L$(OPENSSL_LIBRARY_DIR) ; - -InstallBin $(CAYA_DIRECTORY)/protocols : gtalk ; diff --git a/protocols/gtalk/gtalk.rdef b/protocols/gtalk/gtalk.rdef deleted file mode 100644 index 308e03c..0000000 --- a/protocols/gtalk/gtalk.rdef +++ /dev/null @@ -1,34 +0,0 @@ - -resource app_version { - major = 0, - middle = 0, - minor = 0, - - variety = B_APPV_ALPHA, - internal = 0, - - short_info = "Google Talk Protocol for Caya", - long_info = "©2009-2010 Andrea Anzani, Pier Luigi Fiorini" -}; - -resource vector_icon { - $"6E636966080501040046020106023E40000000000000003D4000494000470000" - $"7EFFFFFFFFE5E1DA02000602000000BBC0004000000000009220244AF0000000" - $"33CCFC3366FF02000602000000BA000040000000000092202448800000336699" - $"FF6699CC02000602000000B9000040000000000092202448E00000CC0000FFFF" - $"000002000602000000BA000040000000000092202448800000FF9900FFFBFF00" - $"02000602000000BA000040000000000092202448800000006600FF00CC000A02" - $"06C22622C7562239222E342E2B2E3D4146364441483C50404C3C504A444A4E55" - $"44CBB634CBB83E5E2A0206C22622C7562239222E342E2B2E3D4146364441483C" - $"50404C3C504C464A505744CBB634CBB83E5E2A02024C265928532A583B59335D" - $"350610CAFFFEAF375335543B3B5A3B5A395D325D355D2C5D274F275627483241" - $"2C413541BDA7C2A83942BDA7C2A8394A3F463F463C40324036402A40234F2346" - $"2358325E2A5E395EBF5C5A3F5CBF5C5A3F544053080234313C310404FE372C37" - $"393739373A393B383B3A3B3B393B3A3B390406FE0B4536403640363F363E383E" - $"373E383E393E393E3A403B3F3B413B453A0405FE03453C453445344533433244" - $"324332403240323F323E343E333E3408024D2C4D3C0803553C4F3655300D0A00" - $"01001001178400040A020101000A010102000A0101032021210A010204053021" - $"2101178200040A0102070630212101178200040A010108301D2101178200040A" - $"0102090830212101178200040A030103000A040204051001178200040A050207" - $"061001178200040A060108301C2001178200040A07020908100117820004" -}; diff --git a/protocols/gtalk/main.cpp b/protocols/gtalk/main.cpp deleted file mode 100644 index 54df731..0000000 --- a/protocols/gtalk/main.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include "GoogleTalk.h" - -extern "C" __declspec(dllexport) CayaProtocol* protocol(); -extern "C" __declspec(dllexport) const char* signature(); -extern "C" __declspec(dllexport) const char* friendly_signature(); - -CayaProtocol* -protocol() -{ - return (CayaProtocol*)new GoogleTalk(); -} - - -const char* -signature() -{ - return kProtocolSignature; -} - - -const char* -friendly_signature() -{ - return kProtocolName; -} diff --git a/protocols/gtalk/settings_template.rdef b/protocols/gtalk/settings_template.rdef deleted file mode 100644 index 2f20c4d..0000000 --- a/protocols/gtalk/settings_template.rdef +++ /dev/null @@ -1,19 +0,0 @@ -resource(1000) message('IMst') { - "setting" = message { - "name" = "username", - "description" = "Username", - int32 "type" = 'CSTR' - }, - "setting" = message { - "name" = "password", - "description" = "Password", - int32 "type" = 'CSTR', - "is_secret" = true - }, - "setting" = message { - "name" = "resource", - "description" = "Resource", - int32 "type" = 'CSTR', - "default" = "Caya" - } -};