Commit 231cc849 authored by Simon Morlat's avatar Simon Morlat

remove const char* in C++ code, which is causing confusion and potential bugs...

remove const char* in C++ code, which is causing confusion and potential bugs when used with std::bind().
parent a2894240
......@@ -2,14 +2,14 @@
#are permitted in any medium without royalty provided the copyright
#notice and this notice are preserved. This file is offered as-is,
#without any warranty
EXTRA_DIST=flexisip.in update_debian_changelog.sh
EXTRA_DIST=flexisip.in flexisip-presence.in update_debian_changelog.sh
if USE_DEB
if !CROSS_COMPILING
edit = sed -e 's|@bindir[@]|$(bindir)|g'
flexisip: Makefile
flexisip: Makefile $(srcdir)/flexisip.in
rm -f $@ $@.tmp
srcdir=''; \
test -f ./$@.in || srcdir=$(srcdir)/; \
......@@ -18,13 +18,21 @@ flexisip: Makefile
chmod a-w $@.tmp
mv $@.tmp $@
flexisip: $(srcdir)/flexisip.in
flexisip-presence: Makefile $(srcdir)/flexisip-presence.in
rm -f $@ $@.tmp
srcdir=''; \
test -f ./$@.in || srcdir=$(srcdir)/; \
$(edit) $${srcdir}$@.in >$@.tmp
chmod +x $@.tmp
chmod a-w $@.tmp
mv $@.tmp $@
initdir=$(sysconfdir)/init.d
init_SCRIPTS=flexisip
init_SCRIPTS=flexisip flexisip-presence
endif
endif
CLEANFILES=flexisip
CLEANFILES=flexisip flexisip-presence
#! /bin/sh
### BEGIN INIT INFO
# Provides: flexisip
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Example initscript
# Description: This file should be used to construct scripts to be
# placed in /etc/init.d.
### END INIT INFO
# Author: Simon Morlat <simon.morlat@linphone.org>
#
# Do NOT "set -e"
# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin:@bindir@
DESC="Flexisip presence server"
NAME=flexisip-presence
PIDFILE=/var/run/$NAME.pid
DAEMON=@bindir@/flexisip
DAEMON_ARGS="--server presence --daemon --syslog --pidfile $PIDFILE"
SCRIPTNAME=/etc/init.d/$NAME
# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0
# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh
# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions
VERBOSE=yes
#
# Function that starts the daemon/service
#
do_start()
{
# Return
# 0 if daemon has been started
# 1 if daemon was already running
# 2 if daemon could not be started
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
|| return 1
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
$DAEMON_ARGS \
|| return 2
# Add code here, if necessary, that waits for the process to be ready
# to handle requests from services started subsequently which depend
# on this one. As a last resort, sleep for some time.
status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
}
#
# Function that stops the daemon/service
#
do_stop()
{
# Return
# 0 if daemon has been stopped
# 1 if daemon was already stopped
# 2 if daemon could not be stopped
# other if a failure occurred
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
RETVAL="$?"
[ "$RETVAL" = 2 ] && return 2
# Wait for children to finish too if this is a daemon that forks
# and if the daemon is only ever run from this initscript.
# If the above conditions are not satisfied then add some other code
# that waits for the process to drop all resources that could be
# needed by services started subsequently. A last resort is to
# sleep for some time.
start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
[ "$?" = 2 ] && return 2
# Many daemons don't delete their pidfiles when they exit.
rm -f $PIDFILE
return "$RETVAL"
}
#
# Function that sends a SIGHUP to the daemon/service
#
do_reload() {
#
# If the daemon can reload its configuration without
# restarting (for example, when it is sent a SIGHUP),
# then implement that here.
#
start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
return 0
}
case "$1" in
start)
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
do_start
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
stop)
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
do_stop
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
status)
status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
;;
#reload|force-reload)
#
# If do_reload() is not implemented then leave this commented out
# and leave 'force-reload' as an alias for 'restart'.
#
#log_daemon_msg "Reloading $DESC" "$NAME"
#do_reload
#log_end_msg $?
#;;
restart|force-reload)
#
# If the "reload" option is implemented then remove the
# 'force-reload' alias
#
log_daemon_msg "Restarting $DESC" "$NAME"
do_stop
case "$?" in
0|1)
do_start
case "$?" in
0) log_end_msg 0 ;;
1) log_end_msg 1 ;; # Old process is still running
*) log_end_msg 1 ;; # Failed to start
esac
;;
*)
# Failed to stop
log_end_msg 1
;;
esac
;;
*)
#echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
exit 3
;;
esac
:
......@@ -3,14 +3,14 @@
#notice and this notice are preserved. This file is offered as-is,
#without any warranty
EXTRA_DIST=flexisip.in
EXTRA_DIST=flexisip.in flexisip-presence.in
if USE_RPM
if !CROSS_COMPILING
edit = sed -e 's|@bindir[@]|$(bindir)|g'
flexisip: Makefile
flexisip: Makefile $(srcdir)/flexisip.in
rm -f $@ $@.tmp
srcdir=''; \
test -f ./$@.in || srcdir=$(srcdir)/; \
......@@ -19,13 +19,21 @@ flexisip: Makefile
chmod a-w $@.tmp
mv $@.tmp $@
flexisip: $(srcdir)/flexisip.in
flexisip-presence: Makefile $(srcdir)/flexisip-presence.in
rm -f $@ $@.tmp
srcdir=''; \
test -f ./$@.in || srcdir=$(srcdir)/; \
$(edit) $${srcdir}$@.in >$@.tmp
chmod +x $@.tmp
chmod a-w $@.tmp
mv $@.tmp $@
initdir=$(sysconfdir)/init.d
init_SCRIPTS=flexisip
init_SCRIPTS=flexisip flexisip-presence
endif
endif
CLEANFILES=flexisip
CLEANFILES=flexisip flexisip-presence
#!/bin/sh
#
# flexisip This script starts and stops the flexisip daemon
#
# chkconfig: - 78 30
# processname: flexisip
# description: flexisip SIP proxy
#
# Source function library.
. /etc/rc.d/init.d/functions
prog=@bindir@/flexisip
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
# Set default flexisip configuration.
FLEXISIP_OPTIONS="--server presence --daemon --syslog"
FLEXISIP_PID=/var/run/flexisip.pid
[ -f $prog ] || exit 0
export PATH=@bindir@:$PATH
# By default it's all good
RETVAL=0
# See how we were called.
case "$1" in
start)
# Start daemon.
echo -n $"Starting flexisip presence server: "
daemon $NICELEVEL $prog $FLEXISIP_OPTIONS --pidfile $FLEXISIP_PID
RETVAL=$?
echo
if [ $RETVAL = 0 ]; then
touch /var/lock/subsys/flexisip
fi
;;
stop)
# Stop daemons.
echo -n $"Stopping flexisip presence server: "
killproc -p $FLEXISIP_PID flexisip
RETVAL=$?
echo
if [ $RETVAL = 0 ]; then
rm -f /var/lock/subsys/flexisip
rm -f $FLEXISIP_PID
fi
;;
restart)
$0 stop
sleep 3
$0 start
;;
condrestart)
[ -e /var/lock/subsys/flexisip ] && $0 restart
;;
status)
status flexisip
RETVAL=$?
;;
*)
echo "Usage: $0 {start|stop|restart|status|condrestart}"
RETVAL=1
;;
esac
exit $RETVAL
......@@ -32,7 +32,7 @@ RETVAL=0
case "$1" in
start)
# Start daemon.
echo -n $"Starting $prog: "
echo -n $"Starting flexisip proxy server: "
daemon $NICELEVEL $prog $FLEXISIP_OPTIONS --pidfile $FLEXISIP_PID
RETVAL=$?
echo
......@@ -42,7 +42,7 @@ case "$1" in
;;
stop)
# Stop daemons.
echo -n $"Stopping $prog: "
echo -n $"Stopping flexisip proxy server: "
killproc -p $FLEXISIP_PID flexisip
RETVAL=$?
echo
......
......@@ -35,7 +35,7 @@ FileAuthDb::FileAuthDb() {
sync();
}
void FileAuthDb::getUserWithPhoneFromBackend(const char* phone, const char* domain, AuthDbListener *listener) {
void FileAuthDb::getUserWithPhoneFromBackend(const std::string &phone, const std::string &domain, AuthDbListener *listener) {
AuthDbResult res = AuthDbResult::PASSWORD_NOT_FOUND;
if (mLastSync == 0) {
sync();
......
......@@ -587,7 +587,7 @@ AuthDbResult OdbcAuthDb::doRetrievePassword(ConnectionCtx &ctx, const string &id
return PASSWORD_FOUND;
}
void OdbcAuthDb::getUserWithPhoneFromBackend(const char* phone, const char* domain, AuthDbListener *listener) {
void OdbcAuthDb::getUserWithPhoneFromBackend(const std::string & phone, const std::string & domain, AuthDbListener *listener) {
LOGE("%s not supported with ODBC", __FUNCTION__);
if (listener) listener->onResult(AuthDbResult::PASSWORD_NOT_FOUND, "");
}
......@@ -222,7 +222,7 @@ void SociAuthDB::getPasswordFromBackend(const std::string &id, const std::string
}
}
void SociAuthDB::getUserWithPhoneFromBackend(const char *phone, const char* domain, AuthDbListener *listener) {
void SociAuthDB::getUserWithPhoneFromBackend(const string &phone, const string &domain, AuthDbListener *listener) {
// create a thread to grab a pool connection and use it to retrieve the auth information
auto func = bind(&SociAuthDB::getUserWithPhoneWithPool, this, phone, domain, listener);
......
......@@ -31,7 +31,7 @@ class FixedAuthDb : public AuthDbBackend {
FixedAuthDb() {
}
virtual void getUserWithPhoneFromBackend(const char* phone, const char *domain, AuthDbListener *listener) {
virtual void getUserWithPhoneFromBackend(const std::string & phone, const std::string &domain, AuthDbListener *listener) {
if (listener) listener->onResult(PASSWORD_FOUND, "user@domain.com");
}
virtual void getPasswordFromBackend(const std::string &id, const std::string &domain,
......@@ -131,22 +131,23 @@ bool AuthDbBackend::cachePassword(const string &key, const string &domain, const
bool AuthDbBackend::cacheUserWithPhone(const std::string &phone, const std::string &domain, const std::string &user) {
unique_lock<mutex> lck(mCachedUserWithPhoneMutex);
if (phone != "") {
mPhone2User[phone + "@" + domain + ";user=phone"] = user;
if (!phone.empty()) {
ostringstream ostr;
ostr<<phone<< "@"<< domain << ";user=phone";
mPhone2User[ostr.str()] = user;
}
mPhone2User[user + "@" + domain] = user;
ostringstream ostr;
ostr << user << "@" << domain;
mPhone2User[ostr.str()] = user;
return true;
}
void AuthDbBackend::getPassword(const char* user, const char* host, const char *auth_username,
void AuthDbBackend::getPassword(const std::string &user, const std::string &host, const std::string &auth_username,
AuthDbListener *listener) {
// Check for usable cached password
string id(user);
string domain(host);
string auth(auth_username);
string key(createPasswordKey(id, auth));
string key(createPasswordKey(user, auth_username));
string pass;
switch (getCachedPassword(key, domain, pass)) {
switch (getCachedPassword(key, host, pass)) {
case VALID_PASS_FOUND:
if (listener) listener->onResult(AuthDbResult::PASSWORD_FOUND, pass);
return;
......@@ -160,20 +161,20 @@ void AuthDbBackend::getPassword(const char* user, const char* host, const char *
}
// if we reach here, password wasn't cached: we have to grab the password from the actual backend
getPasswordFromBackend(id, domain, auth, listener);
getPasswordFromBackend(user, host, auth_username, listener);
}
void AuthDbBackend::createCachedAccount(const char* user, const char* host, const char *auth_username, const char *password,
int expires, const char* phone_alias) {
if (user && host) {
string key = createPasswordKey(user, auth_username ? auth_username : "");
void AuthDbBackend::createCachedAccount(const std::string &user, const std::string &host, const std::string &auth_username, const std::string &password,
int expires, const std::string & phone_alias) {
if (!user.empty() && !host.empty()) {
string key = createPasswordKey(user, auth_username);
cachePassword(key, host, password, expires);
cacheUserWithPhone(phone_alias ? phone_alias : "", host, user);
cacheUserWithPhone(phone_alias, host, user);
}
}
void AuthDbBackend::createAccount(const char* user, const char* host, const char *auth_username, const char *password,
int expires, const char* phone_alias) {
void AuthDbBackend::createAccount(const std::string & user, const std::string & host, const std::string &auth_username, const std::string &password,
int expires, const std::string & phone_alias) {
createCachedAccount(user, host, auth_username, password, expires, phone_alias);
}
......@@ -190,10 +191,10 @@ AuthDbBackend::CacheResult AuthDbBackend::getCachedUserWithPhone(const string &p
return NO_PASS_FOUND;
}
void AuthDbBackend::getUserWithPhone(const char* phone, const char* domain, AuthDbListener *listener) {
void AuthDbBackend::getUserWithPhone(const std::string & phone, const std::string & domain, AuthDbListener *listener) {
// Check for usable cached password
string user;
switch (getCachedUserWithPhone(std::string(phone), std::string(domain), user)) {
switch (getCachedUserWithPhone(phone, domain, user)) {
case VALID_PASS_FOUND:
if (listener) listener->onResult(AuthDbResult::PASSWORD_FOUND, user);
return;
......
......@@ -75,17 +75,17 @@ class AuthDbBackend {
bool cacheUserWithPhone(const std::string &phone, const std::string &domain, const std::string &user);
CacheResult getCachedPassword(const std::string &key, const std::string &domain, std::string &pass);
CacheResult getCachedUserWithPhone(const string &phone, const string &domain, string &user);
void createCachedAccount(const char* user, const char* domain, const char *auth_username, const char *password, int expires, const char* phone_alias = NULL);
void createCachedAccount(const std::string & user, const std::string & domain, const std::string &auth_username, const std::string &password, int expires, const std::string & phone_alias = "");
void clearCache();
int mCacheExpire;
public:
virtual ~AuthDbBackend();
// warning: listener may be invoked on authdb backend thread, so listener must be threadsafe somehow!
void getPassword(const char* user, const char* domain, const char *auth_username, AuthDbListener *listener);
void getUserWithPhone(const char* phone, const char* domain, AuthDbListener *listener);
virtual void getUserWithPhoneFromBackend(const char* phone, const char* domain, AuthDbListener *listener) = 0;
void getPassword(const std::string & user, const std::string & domain, const std::string &auth_username, AuthDbListener *listener);
void getUserWithPhone(const std::string &phone, const std::string &domain, AuthDbListener *listener);
virtual void getUserWithPhoneFromBackend(const std::string &, const std::string &, AuthDbListener *listener) = 0;
virtual void createAccount(const char* user, const char* domain, const char *auth_username, const char *password, int expires, const char* phone_alias = NULL);
virtual void createAccount(const std::string &user, const std::string & domain, const std::string &auth_username, const std::string &password, int expires, const std::string &phone_alias = "");
virtual void getPasswordFromBackend(const std::string &id, const std::string &domain,
const std::string &authid, AuthDbListener *listener) = 0;
......@@ -106,7 +106,7 @@ class FileAuthDb : public AuthDbBackend {
public:
FileAuthDb();
virtual void getUserWithPhoneFromBackend(const char* phone, const char* domain, AuthDbListener *listener);
virtual void getUserWithPhoneFromBackend(const std::string &phone, const std::string & domain, AuthDbListener *listener);
virtual void getPasswordFromBackend(const std::string &id, const std::string &domain,
const std::string &authid, AuthDbListener *listener);
......@@ -154,7 +154,7 @@ class OdbcAuthDb : public AuthDbBackend {
AuthDbListener *listener);
public:
virtual void getUserWithPhoneFromBackend(const char* phone, const char* domain, AuthDbListener *listener);
virtual void getUserWithPhoneFromBackend(const std::string &phone, const std::string &domain, AuthDbListener *listener);
virtual void getPasswordFromBackend(const std::string &id, const std::string &domain,
const std::string &authid, AuthDbListener *listener);
std::map<std::string, std::string> cachedPasswords;
......@@ -178,7 +178,7 @@ class SociAuthDB : public AuthDbBackend {
public:
SociAuthDB();
void setConnectionParameters(const string &domain, const string &request);
virtual void getUserWithPhoneFromBackend(const char* phone, const char* domain, AuthDbListener *listener);
virtual void getUserWithPhoneFromBackend(const std::string & , const std::string &, AuthDbListener *listener);
virtual void getPasswordFromBackend(const std::string &id, const std::string &domain,
const std::string &authid, AuthDbListener *listener);
......
......@@ -440,11 +440,11 @@ class Authentication : public Module {
if (url) {
sip_unknown_t *h2 = ModuleToolbox::getCustomHeaderByName(sip, "X-Phone-Alias");
const char* phone_alias = h2 ? h2->un_value : NULL;
phone_alias = phone_alias ? phone_alias : "";
AuthDbBackend::get()->createAccount(url->url_user, url->url_host, url->url_user, url->url_password,
sip->sip_expires->ex_delta, phone_alias);
LOGD("Account created for %s@%s with password %s and expires %lu%s%s", url->url_user, url->url_host,
url->url_password, sip->sip_expires->ex_delta, phone_alias ? " with phone alias " : "", phone_alias ? phone_alias : "");
url->url_password, sip->sip_expires->ex_delta, phone_alias ? " with phone alias " : "", phone_alias);
return true;
}
}
......
......@@ -126,12 +126,12 @@ void Monitor::createAccounts() {
exit(-1);
}
string password = generatePassword(localIP, salt).c_str();
string password = generatePassword(localIP, salt);
string username = generateUsername(CALLER_PREFIX, localIP);
authDb->createAccount(username.c_str(), domain.c_str(), username.c_str(), password.c_str(), PASSWORD_CACHE_EXPIRE);
authDb->createAccount(username, domain, username, password, PASSWORD_CACHE_EXPIRE);
username = generateUsername(CALLEE_PREFIX, localIP).c_str();
authDb->createAccount(username.c_str(), domain.c_str(), username.c_str(), password.c_str(), PASSWORD_CACHE_EXPIRE);
username = generateUsername(CALLEE_PREFIX, localIP);
authDb->createAccount(username, domain, username, password, PASSWORD_CACHE_EXPIRE);
}
bool Monitor::isLocalhost(const string &host) {
......
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