Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
flexisip
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
6
Issues
6
List
Board
Labels
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
External Wiki
External Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
BC
public
flexisip
Commits
2050b55c
Commit
2050b55c
authored
Mar 25, 2016
by
Gautier Pelloux-Prayer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
presence: implement long term presence
parent
a55b4559
Changes
24
Hide whitespace changes
Inline
Side-by-side
Showing
24 changed files
with
316 additions
and
214 deletions
+316
-214
CMakeLists.txt
src/CMakeLists.txt
+2
-6
authdb-file.cc
src/authdb-file.cc
+4
-4
authdb-odbc.cc
src/authdb-odbc.cc
+5
-7
authdb-soci.cc
src/authdb-soci.cc
+7
-7
authdb.cc
src/authdb.cc
+19
-65
authdb.hh
src/authdb.hh
+11
-17
configmanager.hh
src/configmanager.hh
+3
-3
event.cc
src/event.cc
+1
-1
main.cc
src/main.cc
+8
-1
module-auth.cc
src/module-auth.cc
+48
-12
module-gatewayadapter.cc
src/module-gatewayadapter.cc
+5
-6
module-presence.cc
src/module-presence.cc
+4
-5
monitor.cc
src/monitor.cc
+3
-9
Makefile.am
src/presence/Makefile.am
+5
-5
file-resource-list-manager.cc
src/presence/file-resource-list-manager.cc
+3
-1
file-resource-list-manager.hh
src/presence/file-resource-list-manager.hh
+4
-3
presence-configmanager.cc
src/presence/presence-configmanager.cc
+3
-0
presence-configmanager.hh
src/presence/presence-configmanager.hh
+4
-3
presence-longterm.cc
src/presence/presence-longterm.cc
+40
-0
presence-longterm.hh
src/presence/presence-longterm.hh
+35
-0
presence-server.cc
src/presence/presence-server.cc
+30
-6
presence-server.hh
src/presence/presence-server.hh
+20
-8
presentity-presenceinformation.cc
src/presence/presentity-presenceinformation.cc
+44
-39
presentity-presenceinformation.hh
src/presence/presentity-presenceinformation.hh
+8
-6
No files found.
src/CMakeLists.txt
View file @
2050b55c
...
...
@@ -180,12 +180,8 @@ if(ENABLE_PROTOBUF)
endif
()
if
(
ENABLE_XSD AND ENABLE_PRESENCE
)
list
(
APPEND FLEXISIP_SOURCES presence/etag-manager.hh
)
list
(
APPEND FLEXISIP_SOURCES presence/presence-server.cc
)
list
(
APPEND FLEXISIP_SOURCES presence/presentity-presenceinformation.hh presence/presentity-presenceinformation.cc
)
list
(
APPEND FLEXISIP_SOURCES presence/bellesip-signaling-exception.hh presence/bellesip-signaling-exception.cc
)
list
(
APPEND FLEXISIP_SOURCES presence/subscription.hh presence/subscription.cc
)
list
(
APPEND FLEXISIP_SOURCES presence/list-subscription.hh presence/list-subscription.cc
)
file
(
GLOB PRESENCE_SRCS presence/*.cc presence/*.hh
)
list
(
APPEND FLEXISIP_SOURCES
${
PRESENCE_SRCS
}
)
list
(
APPEND FLEXISIP_LIBS
${
BELLESIP_LIBRARIES
}
${
XERCES_LIBS
}
)
list
(
APPEND FLEXISIP_INCLUDES
${
BELLESIP_INCLUDE_DIRS
}
presence
)
add_definitions
(
-DBELLE_SIP_USE_STL
${
BELLE_SIP_CFLAGS
}
)
...
...
src/authdb-file.cc
View file @
2050b55c
...
...
@@ -34,7 +34,7 @@ FileAuthDb::FileAuthDb() {
sync
();
}
void
FileAuthDb
::
getPasswordFromBackend
(
su_root_t
*
root
,
const
std
::
string
&
id
,
const
std
::
string
&
domain
,
void
FileAuthDb
::
getPasswordFromBackend
(
const
std
::
string
&
id
,
const
std
::
string
&
domain
,
const
std
::
string
&
authid
,
AuthDbListener
*
listener
)
{
AuthDbResult
res
=
AuthDbResult
::
PASSWORD_NOT_FOUND
;
time_t
now
=
getCurrentTime
();
...
...
@@ -45,11 +45,11 @@ void FileAuthDb::getPasswordFromBackend(su_root_t *root, const std::string &id,
string
key
(
createPasswordKey
(
id
,
domain
,
authid
));
if
(
getCachedPassword
(
key
,
domain
,
listener
->
mPassword
)
==
VALID_PASS_FOUND
)
{
std
::
string
passwd
;
if
(
getCachedPassword
(
key
,
domain
,
passwd
)
==
VALID_PASS_FOUND
)
{
res
=
AuthDbResult
::
PASSWORD_FOUND
;
}
listener
->
mResult
=
res
;
listener
->
onResult
();
if
(
listener
)
listener
->
onResult
(
res
,
passwd
);
}
void
FileAuthDb
::
sync
()
{
...
...
src/authdb-odbc.cc
View file @
2050b55c
...
...
@@ -447,7 +447,7 @@ static void closeCursor(SQLHSTMT &stmt) {
}
}
void
OdbcAuthDb
::
getPasswordFromBackend
(
su_root_t
*
root
,
const
std
::
string
&
id
,
const
std
::
string
&
domain
,
void
OdbcAuthDb
::
getPasswordFromBackend
(
const
std
::
string
&
id
,
const
std
::
string
&
domain
,
const
std
::
string
&
authid
,
AuthDbListener
*
listener
)
{
if
(
mAsynchronousRetrieving
)
{
...
...
@@ -455,7 +455,7 @@ void OdbcAuthDb::getPasswordFromBackend(su_root_t *root, const std::string &id,
// Allocate on the stack and detach. It is lawful since:
// "When detach() returns, *this no longer represents the possibly continuing thread of execution."
thread
t
=
thread
(
bind
(
&
OdbcAuthDb
::
doAsyncRetrievePassword
,
this
,
root
,
id
,
domain
,
authid
,
listener
));
thread
t
=
thread
(
bind
(
&
OdbcAuthDb
::
doAsyncRetrievePassword
,
this
,
id
,
domain
,
authid
,
listener
));
t
.
detach
();
// Thread will continue running in detached mode
return
;
}
else
{
...
...
@@ -469,9 +469,7 @@ void OdbcAuthDb::getPasswordFromBackend(su_root_t *root, const std::string &id,
timings
.
error
=
true
;
}
timings
.
done
();
listener
->
mResult
=
ret
;
listener
->
mPassword
=
foundPassword
;
listener
->
onResult
();
if
(
listener
)
listener
->
onResult
(
ret
,
foundPassword
);
}
}
...
...
@@ -479,7 +477,7 @@ void OdbcAuthDb::getPasswordFromBackend(su_root_t *root, const std::string &id,
static unsigned long threadCount=0;
static mutex threadCountMutex;
*/
void
OdbcAuthDb
::
doAsyncRetrievePassword
(
s
u_root_t
*
root
,
s
tring
id
,
string
domain
,
string
auth
,
void
OdbcAuthDb
::
doAsyncRetrievePassword
(
string
id
,
string
domain
,
string
auth
,
AuthDbListener
*
listener
)
{
/* unsigned long localThreadCountCopy=0;
threadCountMutex.lock();
...
...
@@ -497,7 +495,7 @@ void OdbcAuthDb::doAsyncRetrievePassword(su_root_t *root, string id, string doma
}
timings
.
done
();
notifyPasswordRetrieved
(
root
,
listener
,
ret
,
password
);
if
(
listener
)
listener
->
onResult
(
ret
,
password
);
/*
threadCountMutex.lock();
...
...
src/authdb-soci.cc
View file @
2050b55c
...
...
@@ -112,7 +112,7 @@ void SociAuthDB::reconnectSession(soci::session &session) {
#define DURATION_MS(start, stop) (unsigned long) duration_cast<milliseconds>((stop) - (start)).count()
void
SociAuthDB
::
getPasswordWithPool
(
su_root_t
*
root
,
const
std
::
string
&
id
,
const
std
::
string
&
domain
,
void
SociAuthDB
::
getPasswordWithPool
(
const
std
::
string
&
id
,
const
std
::
string
&
domain
,
const
std
::
string
&
authid
,
AuthDbListener
*
listener
)
{
steady_clock
::
time_point
start
=
steady_clock
::
now
();
...
...
@@ -132,13 +132,13 @@ void SociAuthDB::getPasswordWithPool(su_root_t *root, const std::string &id, con
stop
=
steady_clock
::
now
();
SLOGD
<<
"[SOCI] Got pass for "
<<
id
<<
" in "
<<
DURATION_MS
(
start
,
stop
)
<<
"ms"
;
cachePassword
(
createPasswordKey
(
id
,
domain
,
authid
),
domain
,
pass
,
mCacheExpire
);
notifyPasswordRetrieved
(
root
,
listener
,
PASSWORD_FOUND
,
pass
);
if
(
listener
)
listener
->
onResult
(
PASSWORD_FOUND
,
pass
);
}
catch
(
mysql_soci_error
const
&
e
)
{
stop
=
steady_clock
::
now
();
SLOGE
<<
"[SOCI] MySQL error after "
<<
DURATION_MS
(
start
,
stop
)
<<
"ms : "
<<
e
.
err_num_
<<
" "
<<
e
.
what
();
notifyPasswordRetrieved
(
root
,
listener
,
PASSWORD_NOT_FOUND
,
pass
);
if
(
listener
)
listener
->
onResult
(
PASSWORD_NOT_FOUND
,
pass
);
reconnectSession
(
sql
);
...
...
@@ -146,7 +146,7 @@ void SociAuthDB::getPasswordWithPool(su_root_t *root, const std::string &id, con
stop
=
steady_clock
::
now
();
SLOGE
<<
"[SOCI] Some other error after "
<<
DURATION_MS
(
start
,
stop
)
<<
"ms : "
<<
e
.
what
();
notifyPasswordRetrieved
(
root
,
listener
,
PASSWORD_NOT_FOUND
,
pass
);
if
(
listener
)
listener
->
onResult
(
PASSWORD_NOT_FOUND
,
pass
);
reconnectSession
(
sql
);
...
...
@@ -155,18 +155,18 @@ void SociAuthDB::getPasswordWithPool(su_root_t *root, const std::string &id, con
#pragma mark - Inherited virtuals
void
SociAuthDB
::
getPasswordFromBackend
(
su_root_t
*
root
,
const
std
::
string
&
id
,
const
std
::
string
&
domain
,
void
SociAuthDB
::
getPasswordFromBackend
(
const
std
::
string
&
id
,
const
std
::
string
&
domain
,
const
std
::
string
&
authid
,
AuthDbListener
*
listener
)
{
// create a thread to grab a pool connection and use it to retrieve the auth information
auto
func
=
bind
(
&
SociAuthDB
::
getPasswordWithPool
,
this
,
root
,
id
,
domain
,
authid
,
listener
);
auto
func
=
bind
(
&
SociAuthDB
::
getPasswordWithPool
,
this
,
id
,
domain
,
authid
,
listener
);
bool
success
=
thread_pool
->
Enqueue
(
func
);
if
(
success
==
FALSE
)
{
// Enqueue() can fail when the queue is full, so we have to act on that
SLOGE
<<
"[SOCI] Auth queue is full, cannot fullfil password request for "
<<
id
<<
" / "
<<
domain
<<
" / "
<<
authid
;
notifyPasswordRetrieved
(
root
,
listener
,
AUTH_ERROR
,
""
);
if
(
listener
)
listener
->
onResult
(
AUTH_ERROR
,
""
);
}
return
;
...
...
src/authdb.cc
View file @
2050b55c
...
...
@@ -22,19 +22,14 @@ using namespace std;
AuthDbBackend
*
AuthDbBackend
::
sUnique
=
NULL
;
AuthDbListener
::~
AuthDbListener
()
{
}
class
FixedAuthDb
:
public
AuthDbBackend
{
public
:
FixedAuthDb
()
{
}
virtual
void
getPasswordFromBackend
(
su_root_t
*
root
,
const
std
::
string
&
id
,
const
std
::
string
&
domain
,
virtual
void
getPasswordFromBackend
(
const
std
::
string
&
id
,
const
std
::
string
&
domain
,
const
std
::
string
&
authid
,
AuthDbListener
*
listener
)
{
listener
->
mPassword
.
assign
(
"fixed"
);
listener
->
mResult
=
PASSWORD_FOUND
;
listener
->
onResult
();
if
(
listener
)
listener
->
onResult
(
PASSWORD_FOUND
,
"fixed"
);
}
static
void
declareConfig
(
GenericStruct
*
mc
){};
};
...
...
@@ -95,8 +90,8 @@ AuthDbBackend::CacheResult AuthDbBackend::getCachedPassword(const string &key, c
unique_lock
<
mutex
>
lck
(
mCachedPasswordMutex
);
auto
it
=
passwords
.
find
(
key
);
if
(
it
!=
passwords
.
end
())
{
pass
.
assign
(
(
*
it
).
second
.
pass
);
if
(
now
<
(
*
it
).
second
.
expire_date
)
{
pass
.
assign
(
it
->
second
.
pass
);
if
(
now
<
it
->
second
.
expire_date
)
{
return
VALID_PASS_FOUND
;
}
else
{
passwords
.
erase
(
it
);
...
...
@@ -118,26 +113,25 @@ bool AuthDbBackend::cachePassword(const string &key, const string &domain, const
if
(
expires
==
-
1
)
expires
=
mCacheExpire
;
if
(
it
!=
passwords
.
end
())
{
(
*
it
).
second
.
pass
=
pass
;
(
*
it
).
second
.
expire_date
=
now
+
expires
;
it
->
second
.
pass
=
pass
;
it
->
second
.
expire_date
=
now
+
expires
;
}
else
{
passwords
.
insert
(
make_pair
(
key
,
CachedPassword
(
pass
,
now
+
expires
)));
}
return
true
;
}
void
AuthDbBackend
::
getPassword
(
su_root_t
*
root
,
const
url_t
*
from
,
const
char
*
auth_username
,
void
AuthDbBackend
::
getPassword
(
const
char
*
user
,
const
char
*
host
,
const
char
*
auth_username
,
AuthDbListener
*
listener
)
{
// Check for usable cached password
string
id
(
from
->
url_
user
);
string
domain
(
from
->
url_
host
);
string
id
(
user
);
string
domain
(
host
);
string
auth
(
auth_username
);
string
key
(
createPasswordKey
(
id
,
domain
,
auth
));
switch
(
getCachedPassword
(
key
,
domain
,
listener
->
mPassword
))
{
string
pass
;
switch
(
getCachedPassword
(
key
,
domain
,
pass
))
{
case
VALID_PASS_FOUND
:
listener
->
mResult
=
AuthDbResult
::
PASSWORD_FOUND
;
listener
->
onResult
();
if
(
listener
)
listener
->
onResult
(
AuthDbResult
::
PASSWORD_FOUND
,
pass
);
return
;
case
EXPIRED_PASS_FOUND
:
// Might check here if connection is failing
...
...
@@ -149,57 +143,17 @@ void AuthDbBackend::getPassword(su_root_t *root, const url_t *from, const char *
}
// if we reach here, password wasn't cached: we have to grab the password from the actual backend
getPasswordFromBackend
(
root
,
id
,
domain
,
auth
,
listener
);
}
static
void
main_thread_async_response_cb
(
su_root_magic_t
*
rm
,
su_msg_r
msg
,
void
*
u
)
{
AuthDbListener
**
listenerStorage
=
(
AuthDbListener
**
)
su_msg_data
(
msg
);
AuthDbListener
*
listener
=
*
listenerStorage
;
listener
->
onResult
();
}
void
AuthDbBackend
::
notifyPasswordRetrieved
(
su_root_t
*
root
,
AuthDbListener
*
listener
,
AuthDbResult
result
,
const
std
::
string
&
password
)
{
if
(
listener
)
{
su_msg_r
mamc
=
SU_MSG_R_INIT
;
if
(
-
1
==
su_msg_create
(
mamc
,
su_root_task
(
root
),
su_root_task
(
root
),
main_thread_async_response_cb
,
sizeof
(
AuthDbListener
*
)))
{
LOGF
(
"Couldn't create auth async message"
);
}
AuthDbListener
**
listenerStorage
=
(
AuthDbListener
**
)
su_msg_data
(
mamc
);
*
listenerStorage
=
listener
;
switch
(
result
)
{
case
PASSWORD_FOUND
:
listener
->
mResult
=
result
;
listener
->
mPassword
=
password
;
break
;
case
PASSWORD_NOT_FOUND
:
listener
->
mResult
=
AuthDbResult
::
PASSWORD_NOT_FOUND
;
listener
->
mPassword
=
""
;
break
;
case
AUTH_ERROR
:
/*in that case we can fallback to the cached password previously set*/
break
;
case
PENDING
:
LOGF
(
"unhandled case PENDING"
);
break
;
}
if
(
-
1
==
su_msg_send
(
mamc
))
{
LOGF
(
"Couldn't send auth async message to main thread."
);
}
}
getPasswordFromBackend
(
id
,
domain
,
auth
,
listener
);
}
void
AuthDbBackend
::
createCachedAccount
(
const
url_t
*
from
,
const
char
*
auth_username
,
const
char
*
password
,
void
AuthDbBackend
::
createCachedAccount
(
const
char
*
user
,
const
char
*
host
,
const
char
*
auth_username
,
const
char
*
password
,
int
expires
)
{
if
(
from
->
url_host
&&
from
->
url_user
)
{
string
key
=
createPasswordKey
(
from
->
url_user
,
from
->
url_
host
,
auth_username
?
auth_username
:
""
);
cachePassword
(
key
,
from
->
url_
host
,
password
,
expires
);
if
(
user
&&
host
)
{
string
key
=
createPasswordKey
(
user
,
host
,
auth_username
?
auth_username
:
""
);
cachePassword
(
key
,
host
,
password
,
expires
);
}
}
void
AuthDbBackend
::
createAccount
(
const
url_t
*
from
,
const
char
*
auth_username
,
const
char
*
password
,
int
expires
)
{
createCachedAccount
(
from
,
auth_username
,
password
,
expires
);
void
AuthDbBackend
::
createAccount
(
const
char
*
user
,
const
char
*
host
,
const
char
*
auth_username
,
const
char
*
password
,
int
expires
)
{
createCachedAccount
(
user
,
host
,
auth_username
,
password
,
expires
);
}
src/authdb.hh
View file @
2050b55c
...
...
@@ -47,10 +47,7 @@ struct AuthDbTimings;
class
AuthDbListener
:
public
StatFinishListener
{
public
:
virtual
void
onResult
()
=
0
;
virtual
~
AuthDbListener
();
std
::
string
mPassword
;
AuthDbResult
mResult
;
virtual
void
onResult
(
AuthDbResult
result
,
std
::
string
passwd
)
=
0
;
};
class
AuthDbBackend
{
...
...
@@ -72,20 +69,17 @@ class AuthDbBackend {
std
::
string
createPasswordKey
(
const
std
::
string
&
user
,
const
std
::
string
&
host
,
const
std
::
string
&
auth
);
bool
cachePassword
(
const
std
::
string
&
key
,
const
std
::
string
&
domain
,
const
std
::
string
&
pass
,
int
expires
);
CacheResult
getCachedPassword
(
const
std
::
string
&
key
,
const
std
::
string
&
domain
,
std
::
string
&
pass
);
void
createCachedAccount
(
const
url_t
*
from
,
const
char
*
auth_username
,
const
char
*
password
,
int
expires
);
void
createCachedAccount
(
const
char
*
user
,
const
char
*
host
,
const
char
*
auth_username
,
const
char
*
password
,
int
expires
);
void
clearCache
();
int
mCacheExpire
;
void
notifyPasswordRetrieved
(
su_root_t
*
root
,
AuthDbListener
*
listener
,
AuthDbResult
result
,
const
std
::
string
&
password
);
public
:
virtual
~
AuthDbBackend
();
void
getPassword
(
su_root_t
*
root
,
const
url_t
*
from
,
const
char
*
auth_username
,
AuthDbListener
*
listener
);
// warning: listener may be invoked on authdb backend thread, so listener must be threadsafe somehow!
void
getPassword
(
const
char
*
user
,
const
char
*
host
,
const
char
*
auth_username
,
AuthDbListener
*
listener
);
virtual
void
createAccount
(
const
url_t
*
from
,
const
char
*
auth_username
,
const
char
*
password
,
int
expires
);
virtual
void
createAccount
(
const
char
*
user
,
const
char
*
host
,
const
char
*
auth_username
,
const
char
*
password
,
int
expires
);
virtual
void
getPasswordFromBackend
(
su_root_t
*
root
,
const
std
::
string
&
id
,
const
std
::
string
&
domain
,
virtual
void
getPasswordFromBackend
(
const
std
::
string
&
id
,
const
std
::
string
&
domain
,
const
std
::
string
&
authid
,
AuthDbListener
*
listener
)
=
0
;
static
AuthDbBackend
*
get
();
...
...
@@ -106,7 +100,7 @@ class FileAuthDb : public AuthDbBackend {
public
:
FileAuthDb
();
virtual
void
getPasswordFromBackend
(
su_root_t
*
root
,
const
std
::
string
&
id
,
const
std
::
string
&
domain
,
virtual
void
getPasswordFromBackend
(
const
std
::
string
&
id
,
const
std
::
string
&
domain
,
const
std
::
string
&
authid
,
AuthDbListener
*
listener
);
static
void
declareConfig
(
GenericStruct
*
mc
){};
...
...
@@ -149,11 +143,11 @@ class OdbcAuthDb : public AuthDbBackend {
bool
getConnection
(
const
std
::
string
&
id
,
ConnectionCtx
&
ctx
,
AuthDbTimings
&
timings
);
AuthDbResult
doRetrievePassword
(
ConnectionCtx
&
ctx
,
const
std
::
string
&
user
,
const
std
::
string
&
host
,
const
std
::
string
&
auth
,
std
::
string
&
foundPassword
,
AuthDbTimings
&
timings
);
void
doAsyncRetrievePassword
(
s
u_root_t
*
,
s
td
::
string
id
,
std
::
string
domain
,
std
::
string
auth
,
void
doAsyncRetrievePassword
(
std
::
string
id
,
std
::
string
domain
,
std
::
string
auth
,
AuthDbListener
*
listener
);
public
:
virtual
void
getPasswordFromBackend
(
su_root_t
*
root
,
const
std
::
string
&
id
,
const
std
::
string
&
domain
,
virtual
void
getPasswordFromBackend
(
const
std
::
string
&
id
,
const
std
::
string
&
domain
,
const
std
::
string
&
authid
,
AuthDbListener
*
listener
);
std
::
map
<
std
::
string
,
std
::
string
>
cachedPasswords
;
void
setExecuteDirect
(
const
bool
value
);
...
...
@@ -176,13 +170,13 @@ class SociAuthDB : public AuthDbBackend {
public
:
SociAuthDB
();
void
setConnectionParameters
(
const
string
&
domain
,
const
string
&
request
);
virtual
void
getPasswordFromBackend
(
su_root_t
*
root
,
const
std
::
string
&
id
,
const
std
::
string
&
domain
,
virtual
void
getPasswordFromBackend
(
const
std
::
string
&
id
,
const
std
::
string
&
domain
,
const
std
::
string
&
authid
,
AuthDbListener
*
listener
);
static
void
declareConfig
(
GenericStruct
*
mc
);
private
:
void
getPasswordWithPool
(
su_root_t
*
root
,
const
std
::
string
&
id
,
const
std
::
string
&
domain
,
void
getPasswordWithPool
(
const
std
::
string
&
id
,
const
std
::
string
&
domain
,
const
std
::
string
&
authid
,
AuthDbListener
*
listener
);
void
reconnectSession
(
soci
::
session
&
session
);
...
...
src/configmanager.hh
View file @
2050b55c
...
...
@@ -633,12 +633,12 @@ class GenericManager : protected ConfigValueListener {
}
}
}
private
:
static
void
atexit
();
protected
:
GenericManager
();
virtual
~
GenericManager
()
{
}
private
:
static
void
atexit
();
bool
doIsValidNextConfig
(
const
ConfigValue
&
cv
);
bool
doOnConfigStateChanged
(
const
ConfigValue
&
conf
,
ConfigState
state
);
RootConfigStruct
mConfigRoot
;
...
...
src/event.cc
View file @
2050b55c
...
...
@@ -195,7 +195,7 @@ void RequestSipEvent::send(const shared_ptr<MsgSip> &msg, url_string_t const *u,
void
RequestSipEvent
::
reply
(
int
status
,
char
const
*
phrase
,
tag_type_t
tag
,
tag_value_t
value
,
...)
{
if
(
mIncomingAgent
!=
NULL
)
{
SLOGD
<<
"Replying Request SIP message: "
<<
status
<<
" "
<<
phrase
<<
std
::
endl
;
SLOGD
<<
"Replying Request SIP message: "
<<
status
<<
" "
<<
phrase
;
ta_list
ta
;
ta_start
(
ta
,
tag
,
value
);
mIncomingAgent
->
reply
(
getMsgSip
(),
status
,
phrase
,
ta_tags
(
ta
));
...
...
src/main.cc
View file @
2050b55c
...
...
@@ -72,7 +72,8 @@
#include <fstream>
#ifdef ENABLE_PRESENCE
#include "presence/presence-server.h"
#include "presence/presence-server.hh"
#include "presence/presence-longterm.hh"
#endif // ENABLE_PRESENCE
#include "monitor.hh"
...
...
@@ -800,6 +801,8 @@ int main(int argc, char *argv[]) {
#ifdef ENABLE_PRESENCE
flexisip
::
PresenceServer
presenceServer
(
configFile
.
getValue
());
flexisip
::
PresenceLongterm
presenceLongTerm
(
presenceServer
.
getBelleSipMainLoop
());
presenceServer
.
addNewPresenceInfoListener
(
&
presenceLongTerm
);
presenceServer
.
start
();
#endif // ENABLE_PRESENCE
...
...
@@ -816,6 +819,10 @@ int main(int argc, char *argv[]) {
delete
stun
;
}
su_root_destroy
(
root
);
#ifdef ENABLE_PRESENCE
presenceServer
.
removeNewPresenceInfoListener
(
&
presenceLongTerm
);
#endif // ENABLE_PRESENCE
LOGN
(
"Flexisip exiting normally."
);
if
(
trackAllocs
)
dump_remaining_msgs
();
...
...
src/module-auth.cc
View file @
2050b55c
...
...
@@ -145,6 +145,8 @@ class Authentication : public Module {
auth_challenger_t
const
*
mAch
;
bool
mHashedPass
;
bool
mPasswordFound
;
AuthDbResult
mResult
;
std
::
string
mPassword
;
public
:
bool
mImmediateRetrievePass
;
...
...
@@ -156,7 +158,7 @@ class Authentication : public Module {
void
setData
(
auth_mod_t
*
am
,
auth_status_t
*
as
,
auth_challenger_t
const
*
ach
);
void
checkPassword
(
const
char
*
password
);
void
onResult
();
void
onResult
(
AuthDbResult
result
,
std
::
string
passwd
);
void
onError
();
void
finish
();
/*the listener is destroyed when calling this, careful*/
su_root_t
*
getRoot
()
{
...
...
@@ -168,6 +170,9 @@ class Authentication : public Module {
Authentication
*
getModule
()
{
return
mModule
;
}
private
:
void
processResponse
();
static
void
main_thread_async_response_cb
(
su_root_magic_t
*
rm
,
su_msg_r
msg
,
void
*
u
);
};
private
:
...
...
@@ -411,7 +416,8 @@ class Authentication : public Module {
// we want to create account with expires to 0 so that when we send 200 OK response,
// user knows that he is not yet registered
sip_time_t
expires
=
/*sip->sip_expires->ex_delta*/
0
;
AuthDbBackend
::
get
()
->
createAccount
(
url
,
url
->
url_user
,
url
->
url_password
,
expires
);
AuthDbBackend
::
get
()
->
createAccount
(
url
->
url_user
,
url
->
url_host
,
url
->
url_user
,
url
->
url_password
,
expires
);
LOGD
(
"Account created for %s@%s with password %s and expires %i"
,
url
->
url_user
,
url
->
url_host
,
url
->
url_password
,
(
int
)
expires
);
return
true
;
...
...
@@ -636,6 +642,43 @@ void Authentication::AuthenticationListener::setData(auth_mod_t *am, auth_status
this
->
mAch
=
ach
;
}
void
Authentication
::
AuthenticationListener
::
main_thread_async_response_cb
(
su_root_magic_t
*
rm
,
su_msg_r
msg
,
void
*
u
)
{
AuthenticationListener
**
listenerStorage
=
(
AuthenticationListener
**
)
su_msg_data
(
msg
);
AuthenticationListener
*
listener
=
*
listenerStorage
;
listener
->
processResponse
();
}
void
Authentication
::
AuthenticationListener
::
onResult
(
AuthDbResult
result
,
std
::
string
passwd
)
{
// invoke callback on main thread (sofia-sip)
su_msg_r
mamc
=
SU_MSG_R_INIT
;
if
(
-
1
==
su_msg_create
(
mamc
,
su_root_task
(
getRoot
()),
su_root_task
(
getRoot
()),
main_thread_async_response_cb
,
sizeof
(
AuthenticationListener
*
)))
{
LOGF
(
"Couldn't create auth async message"
);
}
AuthenticationListener
**
listenerStorage
=
(
AuthenticationListener
**
)
su_msg_data
(
mamc
);
*
listenerStorage
=
this
;
switch
(
result
)
{
case
PASSWORD_FOUND
:
mResult
=
AuthDbResult
::
PASSWORD_FOUND
;
mPassword
=
passwd
;
break
;
case
PASSWORD_NOT_FOUND
:
mResult
=
AuthDbResult
::
PASSWORD_NOT_FOUND
;
mPassword
=
""
;
break
;
case
AUTH_ERROR
:
/*in that case we can fallback to the cached password previously set*/
break
;
case
PENDING
:
LOGF
(
"unhandled case PENDING"
);
break
;
}
if
(
-
1
==
su_msg_send
(
mamc
))
{
LOGF
(
"Couldn't send auth async message to main thread."
);
}
}
/**
* return true if the event is terminated
*/
...
...
@@ -745,7 +788,7 @@ void Authentication::AuthenticationListener::checkPassword(const char *passwd) {
mAs
->
as_phrase
=
""
;
}
void
Authentication
::
AuthenticationListener
::
onResult
()
{
void
Authentication
::
AuthenticationListener
::
processResponse
()
{
switch
(
mResult
)
{
case
PASSWORD_FOUND
:
case
PASSWORD_NOT_FOUND
:
...
...
@@ -845,15 +888,9 @@ void Authentication::flexisip_auth_check_digest(auth_mod_t *am, auth_status_t *a
}
}
AuthDbBackend
::
get
()
->
getPassword
(
listener
->
getRoot
(),
as
->
as_user_uri
,
ar
->
ar_username
,
listener
);
AuthDbBackend
::
get
()
->
getPassword
(
as
->
as_user_uri
->
url_user
,
as
->
as_user_uri
->
url_host
,
ar
->
ar_username
,
listener
);
}
class
DummyListener
:
public
AuthDbListener
{
virtual
void
onResult
()
{
delete
this
;
}
};
/** Authenticate a request with @b Digest authentication scheme.
*/
void
Authentication
::
flexisip_auth_method_digest
(
auth_mod_t
*
am
,
auth_status_t
*
as
,
msg_auth_t
*
au
,
...
...
@@ -895,8 +932,7 @@ void Authentication::flexisip_auth_method_digest(auth_mod_t *am, auth_status_t *
if
(
listener
->
mImmediateRetrievePass
)
{
SLOGD
<<
"Searching for "
<<
as
->
as_user_uri
->
url_user
<<
" password to have it when the authenticated request comes"
;
AuthDbBackend
::
get
()
->
getPassword
(
listener
->
getRoot
(),
as
->
as_user_uri
,
as
->
as_user_uri
->
url_user
,
new
DummyListener
());
AuthDbBackend
::
get
()
->
getPassword
(
as
->
as_user_uri
->
url_user
,
as
->
as_user_uri
->
url_host
,
as
->
as_user_uri
->
url_user
,
NULL
);
}
listener
->
finish
();
return
;
...
...
src/module-gatewayadapter.cc
View file @
2050b55c
...
...
@@ -115,9 +115,9 @@ class GatewayRegister {
gw
->
sendRegister
();
}
virtual
void
onResult
()
{
if
(
mR
esult
==
AuthDbResult
::
PASSWORD_FOUND
)
{
checkPassword
(
mPasswor
d
.
c_str
());
virtual
void
onResult
(
AuthDbResult
result
,
std
::
string
passwd
)
{
if
(
r
esult
==
AuthDbResult
::
PASSWORD_FOUND
)
{
checkPassword
(
passw
d
.
c_str
());
}
else
{
LOGE
(
"GatewayRegister onResult(): Can't find user password, give up."
);
}
...
...
@@ -144,10 +144,9 @@ class GatewayRegister {
void
onRecordFound
(
Record
*
r
)
{
if
(
r
==
NULL
)
{
LOGD
(
"Record doesn't exist. Fork"
);
string
ipassword
;
AuthDbBackend
*
mAuthDb
=
AuthDbBackend
::
get
();
mAuthDb
->
getPassword
(
gw
->
mAgent
->
getRoot
(),
gw
->
getFrom
()
->
a_url
,
gw
->
getFrom
()
->
a_url
->
url_user
,
new
OnAuthListener
(
gw
));
url_t
*
url
=
gw
->
getFrom
()
->
a_url
;
mAuthDb
->
getPassword
(
url
->
url_user
,
url
->
url_host
,
url
->
url_user
,
new
OnAuthListener
(
gw
));
}
else
{
LOGD
(
"Record already exists. Not forked"
);
}
...
...
src/module-presence.cc
View file @
2050b55c
...
...
@@ -49,8 +49,7 @@ class ModulePresence : public Module, ModuleToolbox {
if
(
cv
.
getName
()
==
"presence-server"
)
{
url_t
*
uri
=
url_make
(
&
mHome
,
cv
.
getName
().
c_str
());
if
(
!
uri
)
{
SLOGE
<<
this
->
getModuleName
()
<<
": wrong destination uri for presence server ["
<<
cv
.
getName
()
<<
"]"
;
SLOGE
<<
getModuleName
()
<<
": wrong destination uri for presence server ["
<<
cv
.
getName
()
<<
"]"
;
return
false
;
}
else
{
su_free
(
&
mHome
,
uri
);
...
...
@@ -62,8 +61,8 @@ class ModulePresence : public Module, ModuleToolbox {
void
onLoad
(
const
GenericStruct
*
mc
)
{
mDestRoute
=
mc
->
get
<
ConfigString
>
(
"presence-server"
)
->
read
();
mOnlyListSubscription
=
mc
->
get
<
ConfigBooleanExpression
>
(
"only-list-subscription"
)
->
read
();
SLOGI
<<
this
->
getModuleName
()
<<
": presence server is ["
<<
mDestRoute
<<
"]"
;
SLOGI
<<
this
->
getModuleName
()
<<
": Non list subscription are "
<<
(
mOnlyListSubscription
?
"not"
:
""
)
SLOGI
<<
getModuleName
()
<<
": presence server is ["
<<
mDestRoute
<<
"]"
;
SLOGI
<<
getModuleName
()
<<
": Non list subscription are "
<<
(
mOnlyListSubscription
?
"not"
:
""
)
<<
" redirected by presence server"
;
}
...
...
@@ -79,7 +78,7 @@ class ModulePresence : public Module, ModuleToolbox {
sip_t
*
sip
=
ev
->
getSip
();
if
(
sip
->
sip_request
->
rq_method
==
sip_method_subscribe
)
{
sip_require_t
*
require
;
bool
require_recipient_list_subscribe_found
=
fals
e
;
bool
require_recipient_list_subscribe_found
=
tru
e
;
for
(
require
=
(
sip_require_t
*
)
sip
->
sip_require
;
require
!=
NULL
;
require
=
(
sip_require_t
*
)
require
->
k_next
)
{
if
(
*
require
->
k_items
&&
strcasecmp
((
const
char
*
)
*
require
->
k_items
,
"recipient-list-subscribe"
)
==
0
)
{
...
...
src/monitor.cc
View file @
2050b55c
...
...
@@ -113,17 +113,13 @@ string Monitor::findLocalAddress(const list<string> &nodes) {
}
void
Monitor
::
createAccounts
()
{
url_t
url
;
memset
(
&
url
,
0
,
sizeof
(
url_t
));
AuthDbBackend
*
authDb
=
AuthDbBackend
::
get
();
GenericStruct
*
cluster
=
GenericManager
::
get
()
->
getRoot
()
->
get
<
GenericStruct
>
(
"cluster"
);
GenericStruct
*
monitorConf
=
GenericManager
::
get
()
->
getRoot
()
->
get
<
GenericStruct
>
(
"monitor"
);
string
salt
=
monitorConf
->
get
<
ConfigString
>
(
"password-salt"
)
->
read
();
list
<
string
>
nodes
=
cluster
->
get
<
ConfigStringList
>
(
"nodes"
)
->
read
();
string
domaine
=
findDomain
();
url
.
url_host
=
domaine
.
c_str
();
string
domain
=
findDomain
();
string
localIP
=
findLocalAddress
(
nodes
);
if
(
localIP
==
""
)
{
LOGA
(
"Monitor::createAccounts(): Could not find local IP address"
);
...
...
@@ -132,12 +128,10 @@ void Monitor::createAccounts() {
string
password
=
generatePassword
(
localIP
,
salt
).
c_str
();
string
username
=
generateUsername
(
CALLER_PREFIX
,
localIP
);
url
.
url_user
=
username
.
c_str
();
authDb
->
createAccount
(
&
url
,
url
.
url_user
,
password
.
c_str
(),
PASSWORD_CACHE_EXPIRE
);
authDb
->
createAccount
(
username
.
c_str
(),
domain
.
c_str
(),
username
.
c_str
(),
password
.
c_str
(),
PASSWORD_CACHE_EXPIRE
);
username
=
generateUsername
(
CALLEE_PREFIX
,
localIP
).
c_str
();
url
.
url_user
=
username
.
c_str
();
authDb
->
createAccount
(
&
url
,
url
.
url_user
,
password
.
c_str
(),
PASSWORD_CACHE_EXPIRE
);
authDb
->
createAccount
(
username
.
c_str
(),
domain
.
c_str
(),
username
.
c_str
(),
password
.
c_str
(),
PASSWORD_CACHE_EXPIRE
);
}
bool
Monitor
::
isLocalhost
(
const
string
&
host
)
{
...
...
src/presence/Makefile.am
View file @
2050b55c
...
...
@@ -5,14 +5,14 @@
if
BUILD_PRESENCE
lib_LTLIBRARIES
=
libflexisip-presence.la
libflexisip_presence_la_SOURCES
=
presence-server.cc presence-server.h
\
libflexisip_presence_la_SOURCES
=
presence-server.cc presence-server.h
h
\
presentity-presenceinformation.cc presentity-presenceinformation.hh
\
bellesip-signaling-exception.cc bellesip-signaling-exception.hh
\
subscription.cc subscription.hh etag-manager.hh presentity-manager.hh list-subscription.cc list-subscription.hh
libflexisip_presence_la_LIBADD
=
../xml/libxml_binding_generated.la
$(ORTP_LIBS)
$(BELLESIP_LIBS)
$(XERCESC_LIBS)
AM_CPPFLAGS
=
-I
$(abs_srcdir)
/../
-I
$(builddir)
/../xml
$(SOFIA_CFLAGS)
-DBELLE_SIP_USE_STL
=
1
$(BELLESIP_CFLAGS)
$(ORTP_CFLAGS)
$(XSDCXX_CPPFLAGS)
$(XERCESC_CFLAGS)
AM_LDFLAGS
=
AM_CPPFLAGS
=
-I
$(abs_srcdir)
/../
-I
$(builddir)
/../xml
$(SOFIA_CFLAGS)
-DBELLE_SIP_USE_STL
=
1
$(BELLESIP_CFLAGS)
$(ORTP_CFLAGS)
$(XSDCXX_CPPFLAGS)
$(XERCESC_CFLAGS)
AM_LDFLAGS
=
endif
src/presence/file-resource-list-manager.cc
View file @
2050b55c
...
...
@@ -16,8 +16,9 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <file-resource-list-manager.h>
#include <file-resource-list-manager.h
h
>
#if 0
FileResourceListManager::FileResourceListManager() {
// TODO Auto-generated constructor stub
}
...
...
@@ -25,3 +26,4 @@ FileResourceListManager::FileResourceListManager() {
FileResourceListManager::~FileResourceListManager() {
// TODO Auto-generated destructor stub
}
#endif
src/presence/file-resource-list-manager.h
→
src/presence/file-resource-list-manager.h
h
View file @
2050b55c
...
...
@@ -16,8 +16,9 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef FILERESOURCELISTMANAGER_H_
#define FILERESOURCELISTMANAGER_H_
#pragma once
#if 0
//#include "resource-list-manager.hh"
...
...
@@ -27,4 +28,4 @@ public:
virtual ~FileResourceListManager();
};
#endif
/* FILERESOURCELISTMANAGER_H_ */
#endif
src/presence/presence-configmanager.cc
View file @
2050b55c
...
...
@@ -18,6 +18,8 @@
#include "presence-configmanager.hh"
#if 0
static ConfigItemDescriptor presence_global_conf[] = {
// { Boolean , "debug" , "Outputs very detailed logs", "false" },
// { Boolean , "dump-corefiles", "Generate a corefile when crashing", "true"},
...
...
@@ -81,3 +83,4 @@ PresenceConfigManager::PresenceConfigManager()
runtimeError->setReadOnly(true);
global->addChild(runtimeError);
}
#endif
src/presence/presence-configmanager.hh
View file @
2050b55c
...
...
@@ -16,14 +16,15 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __flexisip__presence_configmanager__
#define __flexisip__presence_configmanager__
#pragma once
#include "configmanager.hh"
#if 0
class PresenceConfigManager : public GenericManager {
public:
PresenceConfigManager();
private:
virtual ~PresenceConfigManager(){};
};
#endif
/* defined(__flexisip__presence_configmanager__) */
#endif
src/presence/presence-longterm.cc
0 → 100644
View file @
2050b55c
#include "presence-longterm.hh"
#include "presentity-presenceinformation.hh"
#include <belle-sip/belle-sip.h>
using
namespace
flexisip
;
class
OnAuthListener
:
public
AuthDbListener
{
public
:
OnAuthListener
(
belle_sip_main_loop_t
*
mainLoop
,
const
std
::
shared_ptr
<
PresentityPresenceInformation
>
info
)
:
mMainLoop
(
mainLoop
),
mInfo
(
info
)
{}
<