Removed gtalk, facebook and libjabber.

This commit is contained in:
plfiorini 2010-05-28 21:00:30 +00:00
parent 0fb4c94b82
commit 659d45a82c
50 changed files with 6 additions and 7057 deletions

View File

@ -8,22 +8,21 @@ We will add you!
Caya is brought to you buy:
* Andrea Anzani
* Pier Luigi Fiorini
* Andrea Anzani <andrea.anzani@gmail.com>
* Pier Luigi Fiorini <pierluigi.fiorini@gmail.com>
== 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 <oliver.ruiz.dorantes@gmail.com>
* Rene Gollent <anevilyak@gmail.com>
== Icons ==
Michele Frau created the following HVIF icons:
Michele Frau <zumikkebe@gmail.com>
* Caya
* AIM protocol
* ICQ protocol
* GoogleTalk protocol

View File

@ -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 ;

View File

@ -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 <ctype.h>
#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;
}

View File

@ -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 <String.h>
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

View File

@ -1,134 +0,0 @@
/*
* Copyright 2002, The Olmeki Team.
* Distributed under the terms of the Olmeki License.
*/
#include <stdio.h>
#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;
}

View File

@ -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 <String.h>
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

View File

@ -1,135 +0,0 @@
/*
* Copyright 2002, The Olmeki Team.
* Distributed under the terms of the Olmeki License.
*/
#include <stdio.h>
#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;
}

View File

@ -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 <String.h>
#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

View File

@ -1,100 +0,0 @@
/*
* Copyright 2002, The Olmeki Team.
* Distributed under the terms of the Olmeki License.
*/
#include <string.h>
#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;
}
}

View File

@ -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 <String.h>
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

File diff suppressed because it is too large Load Diff

View File

@ -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 <list>
#include <String.h>
#include "ObjectList.h"
#include <expat.h>
#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<JabberElement> ElementList;
typedef std::list<BString> StrList;
typedef BObjectList<JabberContact> RosterList;
typedef BObjectList<JabberAgent> 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

View File

@ -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 <list>
#include <string>
#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<string> & )=0;
virtual void BuddyStatusChanged( const char * who, CayaStatus status )=0;
};
#endif

View File

@ -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;
}

View File

@ -1,48 +0,0 @@
#ifndef JABBER_MESSAGE_H
#define JABBER_MESSAGE_H
#include <String.h>
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

View File

@ -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 <String.h>
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
//.

View File

@ -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;
}

View File

@ -1,47 +0,0 @@
#ifndef JABBER_PRESENCE_H
#define JABBER_PRESENCE_H
#include <String.h>
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

View File

@ -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;
}

View File

@ -1,46 +0,0 @@
#ifndef JABBER_REGISTRATION_H
#define JABBER_REGISTRATION_H
#include <String.h>
#include <map>
using std::map;
using std::pair;
class JabberRegistration
{
public:
JabberRegistration(const BString & jid = "", bool unRegister = false);
~JabberRegistration();
typedef map<BString, BString> FieldList;
typedef pair<BString, BString> 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

View File

@ -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<JabberSSLPlug * >(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<JabberHandler * >(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;
}
//--

View File

@ -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 <openssl/ssl.h>
#include <openssl/bio.h>
#include <openssl/err.h>
#include <OS.h>
#include <Looper.h>
#include <MessageRunner.h>
// 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
//--

View File

@ -1,187 +0,0 @@
#include "JabberSocketPlug.h"
#include "Logger.h"
#ifdef NETSERVER_BUILD
# include <netdb.h>
# include <sys/socket.h>
# include <Locker.h>
#endif
#ifdef BONE_BUILD
# include <arpa/inet.h>
# include <sys/socket.h>
# include <netdb.h>
# include <unistd.h>
#endif
#ifdef __HAIKU__
# include <arpa/inet.h>
# include <sys/socket.h>
# include <netdb.h>
#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<JabberSocketPlug * >(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<JabberHandler * >(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;
}
//--

View File

@ -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 <Locker.h>
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
//--

View File

@ -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;
}

View File

@ -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 <String.h>
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

View File

@ -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) ;

View File

@ -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.

View File

@ -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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <FindDirectory.h>
#include <Path.h>
#include <StorageDefs.h>
#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);
}
}

View File

@ -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

View File

@ -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 <List.h>
#endif
#include <SupportDefs.h>
template<class T> class BObjectList;
template<class T>
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<T>;
};
template<class T>
int
UnaryPredicate<T>::_unary_predicate_glue(const void *item, void *context)
{
return ((UnaryPredicate<T> *)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 T>
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 <index> first
T *SwapWithItem(int32 index, T *newItem);
// same as ReplaceItem, except does not delete old item at <index>,
// 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<T> &) const;
T *FindIf(const UnaryPredicate<T> &);
// 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<typename Key>
T *BinarySearchByKey(const Key &key, int (*compare)(const Key *, const T *))
const;
template<typename Key>
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<typename Key>
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<T> &);
// unique insert, returns false if item already in list
bool BinaryInsertUnique(T *, CompareFunction);
bool BinaryInsertUnique(T *, CompareFunctionWithState, void *state);
bool BinaryInsertUnique(T *, const UnaryPredicate<T> &);
// insert a copy of the item, returns new inserted item
T *BinaryInsertCopy(const T &copyThis, CompareFunction);
T *BinaryInsertCopy(const T &copyThis, 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 &copyThis, CompareFunction);
T *BinaryInsertCopyUnique(const T &copyThis, CompareFunctionWithState, void *state);
int32 FindBinaryInsertionIndex(const UnaryPredicate<T> &, 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<class Item, class Result, class Param1>
Result
WhileEachListItem(BObjectList<Item> *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<class Item, class Result, class Param1>
Result
WhileEachListItem(BObjectList<Item> *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<class Item, class Result, class Param1, class Param2>
Result
WhileEachListItem(BObjectList<Item> *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<class Item, class Result, class Param1, class Param2>
Result
WhileEachListItem(BObjectList<Item> *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<class Item, class Result, class Param1, class Param2, class Param3, class Param4>
Result
WhileEachListItem(BObjectList<Item> *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<class Item, class Result>
void
EachListItemIgnoreResult(BObjectList<Item> *list, Result (Item::*func)())
{
int32 count = list->CountItems();
for (int32 index = 0; index < count; index++)
(list->ItemAt(index)->*func)();
}
template<class Item, class Param1>
void
EachListItem(BObjectList<Item> *list, void (*func)(Item *, Param1), Param1 p1)
{
int32 count = list->CountItems();
for (int32 index = 0; index < count; index++)
(func)(list->ItemAt(index), p1);
}
template<class Item, class Param1, class Param2>
void
EachListItem(BObjectList<Item> *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<class Item, class Param1, class Param2>
void
EachListItem(BObjectList<Item> *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<class Item, class Param1, class Param2, class Param3>
void
EachListItem(BObjectList<Item> *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<class Item, class Param1, class Param2, class Param3, class Param4>
void
EachListItem(BObjectList<Item> *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<class T>
BObjectList<T>::BObjectList(int32 itemsPerBlock, bool owning)
: _PointerList_(itemsPerBlock, owning)
{
}
template<class T>
BObjectList<T>::BObjectList(const BObjectList<T> &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<class T>
BObjectList<T>::~BObjectList()
{
if (Owning())
// have to nuke elements first
MakeEmpty();
}
template<class T>
BObjectList<T> &
BObjectList<T>::operator=(const BObjectList<T> &list)
{
owning = list.owning;
BObjectList<T> &result = (BObjectList<T> &)_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<class T>
bool
BObjectList<T>::AddItem(T *item)
{
// need to cast to void * to make T work for const pointers
return _PointerList_::AddItem((void *)item);
}
template<class T>
bool
BObjectList<T>::AddItem(T *item, int32 atIndex)
{
return _PointerList_::AddItem((void *)item, atIndex);
}
template<class T>
bool
BObjectList<T>::AddList(BObjectList<T> *newItems)
{
return _PointerList_::AddList(newItems);
}
template<class T>
bool
BObjectList<T>::AddList(BObjectList<T> *newItems, int32 atIndex)
{
return _PointerList_::AddList(newItems, atIndex);
}
template<class T>
bool
BObjectList<T>::RemoveItem(T *item, bool deleteIfOwning)
{
bool result = _PointerList_::RemoveItem((void *)item);
if (result && Owning() && deleteIfOwning)
delete item;
return result;
}
template<class T>
T *
BObjectList<T>::RemoveItemAt(int32 index)
{
return (T *)_PointerList_::RemoveItem(index);
}
template<class T>
inline T *
BObjectList<T>::ItemAt(int32 index) const
{
return (T *)_PointerList_::ItemAt(index);
}
template<class T>
bool
BObjectList<T>::ReplaceItem(int32 index, T *item)
{
if (owning)
delete ItemAt(index);
return _PointerList_::ReplaceItem(index, (void *)item);
}
template<class T>
T *
BObjectList<T>::SwapWithItem(int32 index, T *newItem)
{
T *result = ItemAt(index);
_PointerList_::ReplaceItem(index, (void *)newItem);
return result;
}
template<class T>
void
BObjectList<T>::SetItem(int32 index, T *newItem)
{
_PointerList_::ReplaceItem(index, (void *)newItem);
}
template<class T>
int32
BObjectList<T>::IndexOf(const T *item) const
{
return _PointerList_::IndexOf((void *)item);
}
template<class T>
T *
BObjectList<T>::FirstItem() const
{
return (T *)_PointerList_::FirstItem();
}
template<class T>
T *
BObjectList<T>::LastItem() const
{
return (T *)_PointerList_::LastItem();
}
template<class T>
bool
BObjectList<T>::HasItem(const T *item) const
{
return _PointerList_::HasItem((void *)item);
}
template<class T>
bool
BObjectList<T>::IsEmpty() const
{
return _PointerList_::IsEmpty();
}
template<class T>
int32
BObjectList<T>::CountItems() const
{
return _PointerList_::CountItems();
}
template<class T>
void
BObjectList<T>::MakeEmpty()
{
if (owning) {
int32 count = CountItems();
for (int32 index = 0; index < count; index++)
delete ItemAt(index);
}
_PointerList_::MakeEmpty();
}
template<class T>
T *
BObjectList<T>::EachElement(EachFunction func, void *params)
{
return (T *)_PointerList_::EachElement((GenericEachFunction)func, params);
}
template<class T>
const T *
BObjectList<T>::EachElement(ConstEachFunction func, void *params) const
{
return (const T *)
const_cast<BObjectList<T> *>(this)->_PointerList_::EachElement(
(GenericEachFunction)func, params);
}
template<class T>
const T *
BObjectList<T>::FindIf(const UnaryPredicate<T> &predicate) const
{
int32 count = CountItems();
for (int32 index = 0; index < count; index++)
if (predicate.operator()(ItemAt(index)) == 0)
return ItemAt(index);
return 0;
}
template<class T>
T *
BObjectList<T>::FindIf(const UnaryPredicate<T> &predicate)
{
int32 count = CountItems();
for (int32 index = 0; index < count; index++)
if (predicate.operator()(ItemAt(index)) == 0)
return ItemAt(index);
return 0;
}
template<class T>
void
BObjectList<T>::SortItems(CompareFunction function)
{
_PointerList_::SortItems((GenericCompareFunction)function);
}
template<class T>
void
BObjectList<T>::SortItems(CompareFunctionWithState function, void *state)
{
_PointerList_::SortItems((GenericCompareFunctionWithState)function, state);
}
template<class T>
void
BObjectList<T>::HSortItems(CompareFunction function)
{
_PointerList_::HSortItems((GenericCompareFunction)function);
}
template<class T>
void
BObjectList<T>::HSortItems(CompareFunctionWithState function, void *state)
{
_PointerList_::HSortItems((GenericCompareFunctionWithState)function, state);
}
template<class T>
T *
BObjectList<T>::BinarySearch(const T &key, CompareFunction func) const
{
return (T*)_PointerList_::BinarySearch(&key,
(GenericCompareFunction)func);
}
template<class T>
T *
BObjectList<T>::BinarySearch(const T &key, CompareFunctionWithState func, void *state) const
{
return (T*)_PointerList_::BinarySearch(&key,
(GenericCompareFunctionWithState)func, state);
}
template<class T>
template<typename Key>
T *
BObjectList<T>::BinarySearchByKey(const Key &key,
int (*compare)(const Key *, const T *)) const
{
return (T*)_PointerList_::BinarySearch(&key,
(GenericCompareFunction)compare);
}
template<class T>
template<typename Key>
T *
BObjectList<T>::BinarySearchByKey(const Key &key,
int (*compare)(const Key *, const T *, void *), void *state) const
{
return (T*)_PointerList_::BinarySearch(&key,
(GenericCompareFunctionWithState)compare, state);
}
template<class T>
int32
BObjectList<T>::BinarySearchIndex(const T &item, CompareFunction compare) const
{
return _PointerList_::BinarySearchIndex(&item,
(GenericCompareFunction)compare);
}
template<class T>
int32
BObjectList<T>::BinarySearchIndex(const T &item,
CompareFunctionWithState compare, void *state) const
{
return _PointerList_::BinarySearchIndex(&item,
(GenericCompareFunctionWithState)compare, state);
}
template<class T>
template<typename Key>
int32
BObjectList<T>::BinarySearchIndexByKey(const Key &key,
int (*compare)(const Key *, const T *)) const
{
return _PointerList_::BinarySearchIndex(&key,
(GenericCompareFunction)compare);
}
template<class T>
bool
BObjectList<T>::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<class T>
bool
BObjectList<T>::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<class T>
bool
BObjectList<T>::BinaryInsertUnique(T *item, CompareFunction func)
{
int32 index = _PointerList_::BinarySearchIndex(item,
(GenericCompareFunction)func);
if (index >= 0)
return false;
return AddItem(item, -index - 1);
}
template<class T>
bool
BObjectList<T>::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<class T>
T *
BObjectList<T>::BinaryInsertCopy(const T &copyThis, CompareFunction func)
{
int32 index = _PointerList_::BinarySearchIndex(&copyThis,
(GenericCompareFunction)func);
if (index >= 0)
index++;
else
index = -index - 1;
T *newItem = new T(copyThis);
AddItem(newItem, index);
return newItem;
}
template<class T>
T *
BObjectList<T>::BinaryInsertCopy(const T &copyThis, CompareFunctionWithState func, void *state)
{
int32 index = _PointerList_::BinarySearchIndex(&copyThis,
(GenericCompareFunctionWithState)func, state);
if (index >= 0)
index++;
else
index = -index - 1;
T *newItem = new T(copyThis);
AddItem(newItem, index);
return newItem;
}
template<class T>
T *
BObjectList<T>::BinaryInsertCopyUnique(const T &copyThis, CompareFunction func)
{
int32 index = _PointerList_::BinarySearchIndex(&copyThis,
(GenericCompareFunction)func);
if (index >= 0)
return ItemAt(index);
index = -index - 1;
T *newItem = new T(copyThis);
AddItem(newItem, index);
return newItem;
}
template<class T>
T *
BObjectList<T>::BinaryInsertCopyUnique(const T &copyThis, CompareFunctionWithState func,
void *state)
{
int32 index = _PointerList_::BinarySearchIndex(&copyThis,
(GenericCompareFunctionWithState)func, state);
if (index >= 0)
return ItemAt(index);
index = -index - 1;
T *newItem = new T(copyThis);
AddItem(newItem, index);
return newItem;
}
template<class T>
int32
BObjectList<T>::FindBinaryInsertionIndex(const UnaryPredicate<T> &pred, bool *alreadyInList)
const
{
int32 index = _PointerList_::BinarySearchIndexByPredicate(&pred,
(UnaryPredicateGlue)&UnaryPredicate<T>::_unary_predicate_glue);
if (alreadyInList)
*alreadyInList = index >= 0;
if (index < 0)
index = -index - 1;
return index;
}
template<class T>
bool
BObjectList<T>::BinaryInsert(T *item, const UnaryPredicate<T> &pred)
{
return AddItem(item, FindBinaryInsertionIndex(pred));
}
template<class T>
bool
BObjectList<T>::BinaryInsertUnique(T *item, const UnaryPredicate<T> &pred)
{
bool alreadyInList;
int32 index = FindBinaryInsertionIndex(pred, &alreadyInList);
if (alreadyInList)
return false;
AddItem(item, index);
return true;
}
#endif /* __OBJECT_LIST__ */

View File

@ -1,222 +0,0 @@
/*
100% free public domain implementation of the SHA-1
algorithm by Dominik Reichl <Dominik.Reichl@swp-net.de>
=== 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];
}

View File

@ -1,81 +0,0 @@
/*
100% free public domain implementation of the SHA-1
algorithm by Dominik Reichl <Dominik.Reichl@swp-net.de>
=== 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 <stdio.h> // Needed for file access
#include <memory.h> // 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___

View File

@ -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"

View File

@ -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 <SupportDefs.h>
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

View File

@ -1,138 +0,0 @@
#include "VCardManager.h"
#include <File.h>
#include <Entry.h>
#include <FindDirectory.h>
#include "JabberPresence.h"
#include "JabberContact.h"
#include "JabberVCard.h"
#include "JabberHandler.h"
#include "Logger.h"
#include <stdio.h>
#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());
}
}
}

View File

@ -1,34 +0,0 @@
#ifndef VCardManager_H_
#define VCardManager_H_
#include <Message.h>
#include <Path.h>
#include <Directory.h>
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

View File

@ -2,5 +2,3 @@ SubDir TOP protocols ;
# Include all the components.
SubInclude TOP protocols aim ;
SubInclude TOP protocols gtalk ;
SubInclude TOP protocols facebook ;

View File

@ -1,854 +0,0 @@
#include <stdio.h>
#include <string>
#include <Entry.h>
#include <libjabber/JabberSocketPlug.h>
#include <libjabber/States.h>
#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<JabberContact*>(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<JabberContact*>(roster->ItemAt(i));
serverBased.AddString("id", contact->GetJid());
}
fServerMsgr->SendMessage(&serverBased);
for (int32 i=0; i < size; i++) {
contact = reinterpret_cast<JabberContact*>(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();
}

View File

@ -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 <list>
#include <List.h>
#include <Messenger.h>
#include <String.h>
#include <libjabber/JabberHandler.h>
#include <libjabber/JabberManager.h>
#include "CayaProtocol.h"
#include "CayaConstants.h"
//class FacebookConnection;
class JabberSocketPlug;
#define RosterList BObjectList<JabberContact>
#define AgentList BObjectList<JabberAgent>
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<string> & );
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<BString> 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

View File

@ -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 ;

View File

@ -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"
};

View File

@ -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;
}

View File

@ -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"
}
};

View File

@ -1,854 +0,0 @@
#include <stdio.h>
#include <string>
#include <Entry.h>
#include <libjabber/JabberSSLPlug.h>
#include <libjabber/States.h>
#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<JabberContact*>(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<JabberContact*>(roster->ItemAt(i));
serverBased.AddString("id", contact->GetJid());
}
fServerMsgr->SendMessage(&serverBased);
for (int32 i=0; i < size; i++) {
contact = reinterpret_cast<JabberContact*>(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();
}

View File

@ -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 <list>
#include <List.h>
#include <Messenger.h>
#include <String.h>
#include <libjabber/JabberHandler.h>
#include <libjabber/JabberManager.h>
#include "CayaProtocol.h"
#include "CayaConstants.h"
class GoogleTalkConnection;
class JabberSSLPlug;
#define RosterList BObjectList<JabberContact>
#define AgentList BObjectList<JabberAgent>
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<string> & );
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<BString> 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

View File

@ -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 ;

View File

@ -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"
};

View File

@ -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;
}

View File

@ -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"
}
};