mirror of
https://github.com/KDE/krfb
synced 2026-07-01 07:31:16 -07:00
Announce user name as SLP attributes. Add substitutions for service attributes. Unregister even when the network configuration changed.
svn path=/trunk/kdenetwork/krfb/; revision=166651
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
#include "kinetd.h"
|
||||
#include "kinetd.moc"
|
||||
#include "kinetaddr.h"
|
||||
#include "kuser.h"
|
||||
#include <qregexp.h>
|
||||
#include <kservicetype.h>
|
||||
#include <kdebug.h>
|
||||
@@ -198,12 +199,16 @@ int PortListener::port() {
|
||||
return m_port;
|
||||
}
|
||||
|
||||
QString PortListener::serviceURL() {
|
||||
KInetAddress *a = KInetAddress::getLocalAddress();
|
||||
QString hostName = a->nodeName();
|
||||
delete a;
|
||||
return m_serviceURL.replace(QRegExp("%h"), hostName)
|
||||
.replace(QRegExp("%p"), QString::number(m_port));
|
||||
QString PortListener::processServiceTemplate(const QString &a) {
|
||||
KInetAddress *kia = KInetAddress::getLocalAddress();
|
||||
QString hostName = kia->nodeName();
|
||||
delete kia;
|
||||
KUser u;
|
||||
QString x = a; // replace does not work in const QString. Why??
|
||||
return x.replace(QRegExp("%h"), hostName)
|
||||
.replace(QRegExp("%p"), QString::number(m_port))
|
||||
.replace(QRegExp("%u"), u.loginName())
|
||||
.replace(QRegExp("%f"), u.fullName());
|
||||
}
|
||||
|
||||
bool PortListener::setPort(int port, int autoPortRange) {
|
||||
@@ -280,12 +285,14 @@ void PortListener::setServiceRegistrationEnabledInternal(bool e) {
|
||||
return;
|
||||
|
||||
if (m_enabled && e) {
|
||||
m_serviceRegistered = m_srvreg->registerService(serviceURL(),
|
||||
m_serviceAttributes);
|
||||
m_registeredServiceURL = processServiceTemplate(m_serviceURL);
|
||||
m_serviceRegistered = m_srvreg->registerService(
|
||||
m_registeredServiceURL,
|
||||
processServiceTemplate(m_serviceAttributes));
|
||||
if (!m_serviceRegistered)
|
||||
kdDebug(7021) << "Failure registering SLP service (no slpd running?)"<< endl;
|
||||
} else {
|
||||
m_srvreg->unregisterService(serviceURL());
|
||||
m_srvreg->unregisterService(m_registeredServiceURL);
|
||||
m_serviceRegistered = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ class PortListener : public QObject {
|
||||
private:
|
||||
bool m_valid;
|
||||
QString m_serviceName;
|
||||
QString m_serviceURL, m_serviceAttributes;
|
||||
QString m_serviceURL, m_serviceAttributes, m_registeredServiceURL;
|
||||
int m_port;
|
||||
int m_portBase, m_autoPortRange;
|
||||
int m_defaultPortBase, m_defaultAutoPortRange;
|
||||
@@ -71,7 +71,7 @@ public:
|
||||
QDateTime expiration();
|
||||
bool isEnabled();
|
||||
int port();
|
||||
QString serviceURL();
|
||||
QString processServiceTemplate(const QString &a);
|
||||
bool setPort(int port = -1, int autoProbeRange = 1);
|
||||
|
||||
private slots:
|
||||
|
||||
@@ -47,6 +47,8 @@ Type=bool
|
||||
# the port is open. The following strings will be substituted:
|
||||
# %h with the local IP address
|
||||
# %p with the port number
|
||||
# %u with the user's login name
|
||||
# %f with the user's full name
|
||||
[PropertyDef::X-KDE-KINETD-serviceURL]
|
||||
Type=QString
|
||||
|
||||
@@ -54,6 +56,8 @@ Type=QString
|
||||
# The following strings will be substituted:
|
||||
# %h with the local IP address
|
||||
# %p with the port number
|
||||
# %u with the user's login name
|
||||
# %f with the user's full name
|
||||
[PropertyDef::X-KDE-KINETD-serviceAttributes]
|
||||
Type=QString
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ X-KDE-KINETD-enabled=false
|
||||
X-KDE-KINETD-argument=--kinetd
|
||||
X-KDE-KINETD-multiInstance=false
|
||||
X-KDE-KINETD-serviceURL=service:remotedesktop.kde:vnc://%h:%p
|
||||
X-KDE-KINETD-serviceAttributes=(username=%u),(fullname=%f)
|
||||
|
||||
Name=KRfb Desktop Sharing
|
||||
Name[bs]=KRfb dijeljenje desktopa
|
||||
|
||||
@@ -4,9 +4,9 @@ METASOURCES = AUTO
|
||||
lib_LTLIBRARIES = libsrvloc.la
|
||||
|
||||
libsrvloc_la_SOURCES = kinetaddr.cpp kinetaddr_ipfinder.cpp \
|
||||
kserviceregistry.cpp
|
||||
kserviceregistry.cpp kuser.cpp
|
||||
libsrvloc_la_LIBADD = $(LIB_QT) $(LIB_KDECORE)
|
||||
noinst_HEADERS = kinetaddr.h kserviceregistry.h
|
||||
noinst_HEADERS = kinetaddr.h kserviceregistry.h kuser.h
|
||||
|
||||
# set the include path for X, qt and KDE
|
||||
INCLUDES= $(all_includes)
|
||||
|
||||
106
srvloc/kuser.cpp
Normal file
106
srvloc/kuser.cpp
Normal file
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* This file is part of the KDE libraries
|
||||
* Copyright (C) 2002 Tim Jansen <tim@tjansen.de>
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public License
|
||||
* along with this library; see the file COPYING.LIB. If not, write to
|
||||
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <kuser.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <pwd.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
class KUserPrivate
|
||||
{
|
||||
public:
|
||||
bool valid;
|
||||
long uid;
|
||||
QString loginName, fullName;
|
||||
|
||||
KUserPrivate() {
|
||||
valid = false;
|
||||
}
|
||||
|
||||
KUserPrivate(long _uid,
|
||||
const QString &_loginname,
|
||||
const QString &_fullname) {
|
||||
valid = true;
|
||||
uid = _uid;
|
||||
loginName = _loginname;
|
||||
fullName = _fullname;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
KUser::KUser() {
|
||||
fillPasswd(getpwuid(getuid()));
|
||||
}
|
||||
|
||||
KUser::KUser(long uid) {
|
||||
fillPasswd(getpwuid(uid));
|
||||
}
|
||||
|
||||
KUser::KUser(const QString& name) {
|
||||
fillPasswd(getpwnam(name.latin1()));
|
||||
}
|
||||
|
||||
void KUser::fillPasswd(struct passwd *p) {
|
||||
if (p) {
|
||||
QString fn(p->pw_gecos);
|
||||
int pos = fn.find(',');
|
||||
if (pos >= 0)
|
||||
fn = fn.left(pos);
|
||||
|
||||
d = new KUserPrivate(p->pw_uid,
|
||||
QString(p->pw_name),
|
||||
fn.stripWhiteSpace());
|
||||
}
|
||||
else
|
||||
d = new KUserPrivate();
|
||||
}
|
||||
|
||||
bool KUser::isValid() const {
|
||||
return d->valid;
|
||||
}
|
||||
|
||||
long KUser::uid() const {
|
||||
if (d->valid)
|
||||
return d->uid;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
QString KUser::loginName() const {
|
||||
if (d->valid)
|
||||
return d->loginName;
|
||||
else
|
||||
return QString::null;
|
||||
}
|
||||
|
||||
QString KUser::fullName() const {
|
||||
if (d->valid)
|
||||
return d->fullName;
|
||||
else
|
||||
return QString::null;
|
||||
}
|
||||
|
||||
KUser::~KUser() {
|
||||
delete d;
|
||||
}
|
||||
100
srvloc/kuser.h
Normal file
100
srvloc/kuser.h
Normal file
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* This file is part of the KDE libraries
|
||||
* Copyright (C) 2002 Tim Jansen <tim@tjansen.de>
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public License
|
||||
* along with this library; see the file COPYING.LIB. If not, write to
|
||||
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
#ifndef KUSER_H
|
||||
#define KUSER_H
|
||||
|
||||
#include <qstring.h>
|
||||
|
||||
class KUserPrivate;
|
||||
struct passwd;
|
||||
|
||||
/**
|
||||
* An user or account name.
|
||||
*
|
||||
* This class represents a user on your system. You can
|
||||
* between KInetAddress and KInetSocketAddress is that the socket address
|
||||
* consists of the address and the port, KInetAddress peresents only the
|
||||
* address itself.
|
||||
*
|
||||
* @author Tim Jansen <tim@tjansen.de>
|
||||
* @short an Internet Address
|
||||
*/
|
||||
class KUser {
|
||||
|
||||
public:
|
||||
/**
|
||||
* Creates an object that contains information about the current user.
|
||||
* (As returned by getuid(2)).
|
||||
*/
|
||||
KUser();
|
||||
|
||||
/**
|
||||
* Creates an object for the user with the given user id.
|
||||
* If the user does not exist isValid() will return false.
|
||||
* @param uid the user id
|
||||
*/
|
||||
KUser(long uid);
|
||||
|
||||
/**
|
||||
* Creates an object that contains information about the user with the given
|
||||
* name. If the user does not exist isValid() will return false.
|
||||
*
|
||||
* @param name the name of the user
|
||||
*/
|
||||
KUser(const QString& name);
|
||||
|
||||
/**
|
||||
* Returns true if the user is valid. A KUser object can be invalid if
|
||||
* you created it with an non-existing uid or name.
|
||||
* @return true if the user is valid
|
||||
*/
|
||||
bool isValid() const;
|
||||
|
||||
/**
|
||||
* Returns the user id of the user.
|
||||
* @return the id of the user or -1 if user is invalid
|
||||
*/
|
||||
long uid() const;
|
||||
|
||||
/**
|
||||
* The login name of the user.
|
||||
* @the login name of the user or QString::null if user is invalid
|
||||
*/
|
||||
QString loginName() const;
|
||||
|
||||
/**
|
||||
* The full name of the user.
|
||||
* @the full name of the user or QString::null if user is invalid
|
||||
*/
|
||||
QString fullName() const;
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
virtual ~KUser();
|
||||
|
||||
private:
|
||||
KUserPrivate* d;
|
||||
void fillPasswd(struct passwd* p);
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user