Presence and contacts in server

parent a03c4b20
......@@ -38,6 +38,7 @@ AC_CONFIG_FILES([src/Makefile \
src/audio/codecs/Makefile
src/audio/codecs/ilbc/Makefile \
src/config/Makefile \
src/contact/Makefile \
src/dbus/Makefile \
src/zeroconf/Makefile])
......
......@@ -28,7 +28,7 @@ IAXSOURCES =
IAXHEADERS =
endif
SUBDIRS = audio config dbus $(ZEROCONFDIR)
SUBDIRS = audio config contact dbus $(ZEROCONFDIR)
sflphoned_SOURCES = eventthread.cpp main.cpp voiplink.cpp \
managerimpl.cpp observer.cpp \
......@@ -51,6 +51,7 @@ libsflphone_la_LIBADD = \
./audio/libaudio.la \
./dbus/libdbus.la \
./config/libconfig.la \
./contact/libcontact.la \
$(IAX_LIBS)
libsflphone_la_SOURCES =
......
......@@ -21,25 +21,60 @@
#include "voiplink.h"
#include "manager.h"
#include <string>
Account::Account(const AccountID& accountID) : _accountID(accountID)
{
_link = NULL;
_enabled = false;
_link = NULL;
_enabled = false;
}
Account::~Account()
{
// _link should be destroyed WHERE IT'S CREATED
//delete _link;
//_link = NULL;
}
void
Account::loadConfig()
{
_enabled = Manager::instance().getConfigInt(_accountID, CONFIG_ACCOUNT_ENABLE) ? true : false;
}
// NOW
void
Account::loadConfig()
Account::loadContacts()
{
_enabled = Manager::instance().getConfigInt(_accountID, CONFIG_ACCOUNT_ENABLE) ? true : false;
// TMP
Contact* contact1 = new Contact("1223345", "Guillaume140", "<sip:140@asterix.inside.savoirfairelinux.net>");
_contacts.push_back(contact1);
Contact* contact2 = new Contact("9876543", "SFLphone131", "<sip:131@asterix.inside.savoirfairelinux.net>");
_contacts.push_back(contact2);
Contact* contact3 = new Contact("6867823", "Guillaume201", "<sip:201@192.168.1.202:5066>");
_contacts.push_back(contact3);
Contact* contact4 = new Contact("3417928", "SFLphone203", "<sip:203@192.168.1.202:5066>");
_contacts.push_back(contact4);
// TODO Load contact file containing list of contacts
// or a configuration for LDAP contacts
}
void
Account::subscribeContactsPresence()
{
if(_link->isContactPresenceSupported())
{
// Subscribe to presence for each contact that presence is enabled
std::vector<Contact*>::iterator iter;
for(iter = _contacts.begin(); iter != _contacts.end(); iter++)
{
_link->subscribePresenceForContact(*iter);
}
}
}
void
Account::publishPresence(std::string presenceStatus)
{
if(_link->isContactPresenceSupported())
_link->publishPresenceStatus(presenceStatus);
}
......@@ -20,7 +20,9 @@
#define ACCOUNT_H
#include <string>
#include <vector>
#include "config/config.h"
#include "contact/contact.h"
#include "voiplink.h"
class VoIPLink;
......@@ -46,9 +48,6 @@ typedef std::string AccountID;
#define SIP_STUN_SERVER "STUN.STUNserver"
#define SIP_USE_STUN "STUN.useStun"
/**
* Class account is an interface to protocol account (SIPAccount, IAXAccount)
* It can be enable on loading or activate after.
......@@ -65,7 +64,7 @@ class Account{
* Load the settings for this account.
*/
virtual void loadConfig();
/**
* Get the account ID
* @return constant account id
......@@ -106,6 +105,21 @@ class Account{
*/
VoIPLink::RegistrationState getRegistrationState() { return _link->getRegistrationState(); }
/**
* Load all contacts
*/
void loadContacts();
/**
* Suscribe presence information for selected contacts if supported
*/
void subscribeContactsPresence();
/**
* Publish our presence information to the server
*/
void publishPresence(std::string presenceStatus);
private:
protected:
......@@ -127,7 +141,11 @@ protected:
* Modified by the configuration (key: ENABLED)
*/
bool _enabled;
/**
* Contacts related to account that can have presence information
*/
std::vector<Contact*> _contacts;
};
#endif
SUBDIRS =
noinst_LTLIBRARIES = \
libcontact.la
libcontact_la_SOURCES = \
contact.h \
presence.h \
contact.cpp \
presence.cpp
/*
* Copyright (C) 2008 Savoir-Faire Linux inc.
* Author: Guillaume Carmel-Archambault <guillaume.carmel-archambault@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "contact.h"
#include <string>
Contact::Contact()
{
}
Contact::Contact(const std::string contactID, const std::string name, const std::string url)
{
_contactID = contactID;
_name = name;
_url = url;
_suscribeToPresence = true;
_presence = NULL;
}
Contact::~Contact()
{
}
/*
* Copyright (C) 2008 Savoir-Faire Linux inc.
* Author: Guillaume Carmel-Archambault <guillaume.carmel-archambault@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef CONTACT_H
#define CONTACT_H
#include "presence.h"
#include <string>
typedef std::string ContactID;
/**
* TOCOMMENT
* @author Guillaume Carmel-Archambault
*/
class Contact {
public:
Contact();
Contact(const std::string contactID, const std::string name, const std::string url);
virtual ~Contact();
std::string getUrl() { return _url; }
protected:
private:
ContactID _contactID;
std::string _name;
std::string _url;
bool _suscribeToPresence;
// Presence information, can be null
Presence* _presence;
};
#endif
/*
* Copyright (C) 2008 Savoir-Faire Linux inc.
* Author: Guillaume Carmel-Archambault <guillaume.carmel-archambault@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "presence.h"
Presence::Presence()
{
}
Presence::~Presence()
{
}
/*
* Copyright (C) 2008 Savoir-Faire Linux inc.
* Author: Guillaume Carmel-Archambault <guillaume.carmel-archambault@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef PRESENCE_H
#define PRESENCE_H
#include <string>
/**
* TOCOMMENT
* @author Guillaume Carmel-Archambault
*/
class Presence {
public:
Presence();
virtual ~Presence();
protected:
private:
std::string _state;
std::string _capabalities;
};
#endif
/*
* Copyright (C) 2008 Savoir-Faire Linux inc.
* Author: Guillaume Carmel-Archambault <guillaume.carmel-archambault@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef PRESENCE_STATUS_H
#define PRESENCE_STATUS_H
/* Definition of all presence status used by the deamon and the GUI
* The deamon knows how to identify tags coming from presence servers
* and cast them in a defined presence status presented here.
* The presence information is transmitted along DBus by those strings.
* The GUI can format and translate these strings for presentation.
*
* If a presence status identified by a string cannot be identified
* when sent from a presence server, we directly use the raw string
* without any formating or translation process possible
*/
// Same presence status as defined in Asterisk
#define PRESENCE_UNKNOWN "UNKNOWN"
#define PRESENCE_NOT_IN_USE "NOT_IN_USE"
#define PRESENCE_INUSE "INUSE"
#define PRESENCE_BUSY "BUSY"
#define PRESENCE_INVALID "INVALID"
#define PRESENCE_UNAVAILABLE "UNAVAILABLE"
#define PRESENCE_RINGING "RINGING"
#define PRESENCE_RING_IN_USE "RING_IN_USE"
#define PRESENCE_HOLD_IN_USE "HOLD_IN_USE"
#define PRESENCE_ON_HOLD "ON_HOLD"
// Presence status defined on some hardware phones
#define PRESENCE_ONLINE "ONLINE"
#define PRESENCE_BUSY "BUSY"
#define PRESENCE_BE_RIGHT_BACK "BE_RIGHT_BACK"
#define PRESENCE_AWAY "AWAY"
#define PRESENCE_OUT_TO_LUNCH "OUT_TO_LUNCH"
#define PRESENCE_OFFLINE "OFFLINE"
#define PRESENCE_DO_NOT_DISTURB "DO_NOT_DISTURB"
// Other presence status defined supported
#define PRESENCE_IN_REUNION "IN_REUNION"
#define PRESENCE_IN_CONFERENCE_CALL "IN_CONFERENCE_CALL"
#endif
......@@ -82,6 +82,7 @@ public:
bool refuse (const CallID& id);
bool carryingDTMFdigits(const CallID& id, char code);
bool sendMessage(const std::string& to, const std::string& body) { return false; }
bool isContactPresenceSupported() { return false; }
public: // iaxvoiplink only
void setHost(const std::string& host) { _host = host; }
......
......@@ -47,6 +47,8 @@
#include "user_cfg.h"
#include "contact/presencestatus.h"
#ifdef USE_ZEROCONF
#include "zeroconf/DNSService.h"
#include "zeroconf/DNSServiceTXTRecord.h"
......@@ -428,18 +430,22 @@ ManagerImpl::saveConfig (void)
bool
ManagerImpl::initRegisterAccounts()
{
_debugInit("Initiate VoIP Links Registration");
AccountMap::iterator iter = _accountMap.begin();
while( iter != _accountMap.end() ) {
if ( iter->second) {
iter->second->loadConfig();
if ( iter->second->isEnabled() ) {
iter->second->registerVoIPLink();
}
}
iter++;
}
return true;
_debugInit("Initiate VoIP Links Registration");
AccountMap::iterator iter = _accountMap.begin();
while( iter != _accountMap.end() ) {
if ( iter->second) {
iter->second->loadConfig();
if ( iter->second->isEnabled() ) {
// NOW
iter->second->registerVoIPLink();
iter->second->loadContacts();
iter->second->publishPresence(PRESENCE_ONLINE);
iter->second->subscribeContactsPresence();
}
}
iter++;
}
return true;
}
//THREAD=Main
......@@ -460,7 +466,11 @@ ManagerImpl::registerAccount(const AccountID& accountId)
}
iter++;
}
// NOW
account->registerVoIPLink();
account->loadContacts();
account->publishPresence(PRESENCE_ONLINE);
account->subscribeContactsPresence();
}
return true;
}
......
This diff is collapsed.
......@@ -60,8 +60,12 @@ public:
bool refuse (const CallID& id);
bool carryingDTMFdigits(const CallID& id, char code);
bool sendMessage(const std::string& to, const std::string& body);
bool isContactPresenceSupported();
void subscribePresenceForContact(Contact* contact);
void publishPresenceStatus(std::string status);
// TODO Not used yet
void sendMessageToContact(const CallID& id, const std::string& message);
// SIP Specific
......
......@@ -108,3 +108,20 @@ VoIPLink::setRegistrationState(const enum RegistrationState state)
{
setRegistrationState(state, "");
}
// NOW
void
VoIPLink::subscribePresenceForContact(Contact* contact)
{
// Nothing to do if presence is not supported
// or the function will be overidden
_debug("Presence subscription not supported for account\n");
}
void
VoIPLink::publishPresenceStatus(std::string status)
{
// Nothing to do if presence is not supported
// or the function will be overidden
_debug("Presence publication not supported for account\n");
}
......@@ -24,6 +24,7 @@
#include <string>
#include "call.h"
#include "contact/contact.h"
#include <map>
#include <cc++/thread.h> // for mutex
......@@ -94,6 +95,22 @@ public:
*/
virtual bool sendMessage(const std::string& to, const std::string& body) = 0;
// NOW
/**
* Determine if link supports presence information
*/
virtual bool isContactPresenceSupported() = 0;
/**
* Register contacts for presence information if supported
*/
virtual void subscribePresenceForContact(Contact* contact);
/**
* Publish presence status to server
*/
virtual void publishPresenceStatus(std::string status);
// these method are set only with 'Account init' and can be get by everyone
void setFullName (const std::string& fullname) { _fullname = fullname; }
std::string& getFullName (void) { return _fullname; }
......@@ -134,8 +151,7 @@ public:
* Same, but with default error value to ""
*/
void setRegistrationState(const enum RegistrationState state);
private:
/**
* Full name used as outgoing Caller ID
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment