1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719
|
/**
* This file is part of TelepathyQt
*
* @copyright Copyright (C) 2010-2011 Collabora Ltd. <http://www.collabora.co.uk/>
* @license LGPL 2.1
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <TelepathyQt/StreamTubeChannel>
#include "TelepathyQt/_gen/stream-tube-channel.moc.hpp"
#include "TelepathyQt/debug-internal.h"
#include <TelepathyQt/Connection>
#include <TelepathyQt/ContactManager>
#include <TelepathyQt/PendingContacts>
#include <TelepathyQt/PendingVariantMap>
#include <QHostAddress>
namespace Tp
{
struct TP_QT_NO_EXPORT StreamTubeChannel::Private
{
Private(StreamTubeChannel *parent);
static void introspectStreamTube(Private *self);
static void introspectConnectionMonitoring(Private *self);
void extractStreamTubeProperties(const QVariantMap &props);
// Public object
StreamTubeChannel *parent;
ReadinessHelper *readinessHelper;
// Introspection
SupportedSocketMap socketTypes;
QString serviceName;
QSet<uint> connections;
QPair<QHostAddress, quint16> ipAddress;
QString unixAddress;
SocketAddressType addressType;
SocketAccessControl accessControl;
bool droppingConnections;
};
StreamTubeChannel::Private::Private(StreamTubeChannel *parent)
: parent(parent),
readinessHelper(parent->readinessHelper()),
addressType(SocketAddressTypeUnix),
accessControl(SocketAccessControlLocalhost),
droppingConnections(false)
{
ReadinessHelper::Introspectables introspectables;
ReadinessHelper::Introspectable introspectableStreamTube(
QSet<uint>() << 0, // makesSenseForStatuses
Features() << TubeChannel::FeatureCore, // dependsOnFeatures (core)
QStringList(), // dependsOnInterfaces
(ReadinessHelper::IntrospectFunc) &StreamTubeChannel::Private::introspectStreamTube,
this);
introspectables[StreamTubeChannel::FeatureCore] = introspectableStreamTube;
ReadinessHelper::Introspectable introspectableConnectionMonitoring(
QSet<uint>() << 0, // makesSenseForStatuses
Features() << StreamTubeChannel::FeatureCore, // dependsOnFeatures (core)
QStringList(), // dependsOnInterfaces
(ReadinessHelper::IntrospectFunc)
&StreamTubeChannel::Private::introspectConnectionMonitoring,
this);
introspectables[StreamTubeChannel::FeatureConnectionMonitoring] =
introspectableConnectionMonitoring;
parent->connect(
parent,
SIGNAL(invalidated(Tp::DBusProxy*,QString,QString)),
SLOT(dropConnections()));
readinessHelper->addIntrospectables(introspectables);
}
void StreamTubeChannel::Private::introspectStreamTube(
StreamTubeChannel::Private *self)
{
StreamTubeChannel *parent = self->parent;
debug() << "Introspecting stream tube properties";
Client::ChannelTypeStreamTubeInterface *streamTubeInterface =
parent->interface<Client::ChannelTypeStreamTubeInterface>();
PendingVariantMap *pvm = streamTubeInterface->requestAllProperties();
parent->connect(pvm,
SIGNAL(finished(Tp::PendingOperation *)),
SLOT(gotStreamTubeProperties(Tp::PendingOperation *)));
}
void StreamTubeChannel::Private::introspectConnectionMonitoring(
StreamTubeChannel::Private *self)
{
StreamTubeChannel *parent = self->parent;
Client::ChannelTypeStreamTubeInterface *streamTubeInterface =
parent->interface<Client::ChannelTypeStreamTubeInterface>();
parent->connect(streamTubeInterface,
SIGNAL(ConnectionClosed(uint,QString,QString)),
SLOT(onConnectionClosed(uint,QString,QString)));
if (parent->isRequested()) {
parent->connect(streamTubeInterface,
SIGNAL(NewRemoteConnection(uint,QDBusVariant,uint)),
SLOT(onNewRemoteConnection(uint,QDBusVariant,uint)));
} else {
parent->connect(streamTubeInterface,
SIGNAL(NewLocalConnection(uint)),
SLOT(onNewLocalConnection(uint)));
}
self->readinessHelper->setIntrospectCompleted(
StreamTubeChannel::FeatureConnectionMonitoring, true);
}
void StreamTubeChannel::Private::extractStreamTubeProperties(const QVariantMap &props)
{
serviceName = qdbus_cast<QString>(props[QLatin1String("Service")]);
socketTypes = qdbus_cast<SupportedSocketMap>(props[QLatin1String("SupportedSocketTypes")]);
}
/**
* \class StreamTubeChannel
* \ingroup clientchannel
* \headerfile TelepathyQt/stream-tube-channel.h <TelepathyQt/StreamTubeChannel>
*
* \brief The StreamTubeChannel class represents a Telepathy channel of type StreamTube.
*
* It provides a transport for reliable and ordered data transfer, similar to SOCK_STREAM sockets.
*
* StreamTubeChannel is an intermediate base class; OutgoingStreamTubeChannel and
* IncomingStreamTubeChannel are the specialized classes used for locally and remotely initiated
* tubes respectively.
*
* For more details, please refer to \telepathy_spec.
*
* See \ref async_model, \ref shared_ptr
*/
/**
* Feature representing the core that needs to become ready to make the
* StreamTubeChannel object usable.
*
* Note that this feature must be enabled in order to use most
* StreamTubeChannel methods.
* See specific methods documentation for more details.
*/
const Feature StreamTubeChannel::FeatureCore =
Feature(QLatin1String(StreamTubeChannel::staticMetaObject.className()), 0);
/**
* Feature used in order to monitor connections to this stream tube.
*
* See connection monitoring specific methods' documentation for more details.
*
* \sa newConnection(), connectionClosed()
*/
const Feature StreamTubeChannel::FeatureConnectionMonitoring =
Feature(QLatin1String(StreamTubeChannel::staticMetaObject.className()), 1);
/**
* Create a new StreamTubeChannel channel.
*
* \param connection Connection owning this channel, and specifying the
* service.
* \param objectPath The channel object path.
* \param immutableProperties The channel immutable properties.
* \return A StreamTubeChannelPtr object pointing to the newly created
* StreamTubeChannel object.
*/
StreamTubeChannelPtr StreamTubeChannel::create(const ConnectionPtr &connection,
const QString &objectPath, const QVariantMap &immutableProperties)
{
return StreamTubeChannelPtr(new StreamTubeChannel(connection, objectPath,
immutableProperties, StreamTubeChannel::FeatureCore));
}
/**
* Construct a new StreamTubeChannel object.
*
* \param connection Connection owning this channel, and specifying the
* service.
* \param objectPath The channel object path.
* \param immutableProperties The channel immutable properties.
* \param coreFeature The core feature of the channel type, if any. The corresponding introspectable should
* depend on StreamTubeChannel::FeatureCore.
*/
StreamTubeChannel::StreamTubeChannel(const ConnectionPtr &connection,
const QString &objectPath,
const QVariantMap &immutableProperties,
const Feature &coreFeature)
: TubeChannel(connection, objectPath, immutableProperties, coreFeature),
mPriv(new Private(this))
{
}
/**
* Class destructor.
*/
StreamTubeChannel::~StreamTubeChannel()
{
delete mPriv;
}
/**
* Return the service name which will be used over this stream tube. This should be a
* well-known TCP service name, for instance "rsync" or "daap".
*
* This method requires StreamTubeChannel::FeatureCore to be ready.
*
* \return The service name.
*/
QString StreamTubeChannel::service() const
{
if (!isReady(FeatureCore)) {
warning() << "StreamTubeChannel::service() used with "
"FeatureCore not ready";
return QString();
}
return mPriv->serviceName;
}
/**
* Return whether this stream tube is capable to accept or offer an IPv4 socket accepting all
* incoming connections coming from localhost.
*
* Note that the \telepathy_spec implies that any connection manager, if capable of providing
* stream tubes, must at least support IPv4 sockets with localhost access control.
* For this reason, this method should always return \c true.
*
* This method requires StreamTubeChannel::FeatureCore to be ready.
*
* \return \c true if the stream tube is capable to accept or offer an IPv4 socket
* accepting all incoming connections coming from localhost, \c false otherwise.
* \sa IncomingStreamTubeChannel::acceptTubeAsTcpSocket(),
* OutgoingStreamTubeChannel::offerTcpSocket(),
* supportsIPv4SocketsWithSpecifiedAddress()
*/
bool StreamTubeChannel::supportsIPv4SocketsOnLocalhost() const
{
if (!isReady(FeatureCore)) {
warning() << "StreamTubeChannel::supportsIPv4SocketsOnLocalhost() used with "
"FeatureCore not ready";
return false;
}
return mPriv->socketTypes.value(SocketAddressTypeIPv4).contains(SocketAccessControlLocalhost);
}
/**
* Return whether this stream tube is capable to accept an IPv4 socket accepting all
* incoming connections coming from a specific address for incoming tubes or whether
* this stream tube is capable of mapping connections to the socket's source address for outgoing
* tubes.
*
* For incoming tubes, when this capability is available, the stream tube can be accepted specifying
* an IPv4 address. Every connection coming from any other address than the specified one will be
* rejected.
*
* For outgoing tubes, when this capability is available, one can keep track of incoming connections
* by enabling StreamTubeChannel::FeatureConnectionMonitoring (possibly before
* opening the stream tube itself), and checking OutgoingStreamTubeChannel::contactsForConnections()
* or OutgoingStreamTubeChannel::connectionsForSourceAddresses().
*
* Note that it is strongly advised to call this method before attempting to call
* IncomingStreamTubeChannel::acceptTubeAsTcpSocket() or
* OutgoingStreamTubeChannel::offerTcpSocket() with a specified address to prevent failures,
* as the spec implies this feature is not compulsory for connection managers.
*
* This method requires StreamTubeChannel::FeatureCore to be ready.
*
* \return \c true if the stream tube is capable to accept an IPv4 socket accepting all
* incoming connections coming from a specific address for incoming tubes or
* the stream tube is capable of mapping connections to the socket's source address for
* outgoing tubes, \c false otherwise.
* \sa IncomingStreamTubeChannel::acceptTubeAsTcpSocket(),
* OutgoingStreamTubeChannel::offerTcpSocket(),
* OutgoingStreamTubeChannel::connectionsForSourceAddresses(),
* OutgoingStreamTubeChannel::contactsForConnections(),
* supportsIPv4SocketsOnLocalhost()
*/
bool StreamTubeChannel::supportsIPv4SocketsWithSpecifiedAddress() const
{
if (!isReady(FeatureCore)) {
warning() << "StreamTubeChannel::supportsIPv4SocketsWithSpecifiedAddress() used with "
"FeatureCore not ready";
return false;
}
return mPriv->socketTypes.value(SocketAddressTypeIPv4).contains(SocketAccessControlPort);
}
/**
* Return whether this stream tube is capable to accept or offer an IPv6 socket accepting all
* incoming connections coming from localhost.
*
* Note that it is strongly advised to call this method before attempting to call
* IncomingStreamTubeChannel::acceptTubeAsTcpSocket() or
* OutgoingStreamTubeChannel::offerTcpSocket() with a specified address to prevent failures,
* as the spec implies this feature is not compulsory for connection managers.
*
* This method requires StreamTubeChannel::FeatureCore to be ready.
*
* \return \c true if the stream tube is capable to accept or offer an IPv6 socket
* accepting all incoming connections coming from localhost, \c false otherwise.
* \sa IncomingStreamTubeChannel::acceptTubeAsTcpSocket(),
* OutgoingStreamTubeChannel::offerTcpSocket(),
* supportsIPv6SocketsWithSpecifiedAddress()
*/
bool StreamTubeChannel::supportsIPv6SocketsOnLocalhost() const
{
if (!isReady(FeatureCore)) {
warning() << "StreamTubeChannel::supportsIPv6SocketsOnLocalhost() used with "
"FeatureCore not ready";
return false;
}
return mPriv->socketTypes.value(SocketAddressTypeIPv6).contains(SocketAccessControlLocalhost);
}
/**
* Return whether this stream tube is capable to accept an IPv6 socket accepting all
* incoming connections coming from a specific address for incoming tubes or whether
* this stream tube is capable of mapping connections to the socket's source address for outgoing
* tubes.
*
* For incoming tubes, when this capability is available, the stream tube can be accepted specifying
* an IPv6 address. Every connection coming from any other address than the specified one will be
* rejected.
*
* For outgoing tubes, when this capability is available, one can keep track of incoming connections
* by enabling StreamTubeChannel::FeatureConnectionMonitoring (possibly before
* opening the stream tube itself), and checking OutgoingStreamTubeChannel::contactsForConnections()
* or OutgoingStreamTubeChannel::connectionsForSourceAddresses().
*
* Note that it is strongly advised to call this method before attempting to call
* IncomingStreamTubeChannel::acceptTubeAsTcpSocket() or
* OutgoingStreamTubeChannel::offerTcpSocket() with a specified address to prevent failures,
* as the spec implies this feature is not compulsory for connection managers.
*
* This method requires StreamTubeChannel::FeatureCore to be ready.
*
* \return \c true if the stream tube is capable to accept an IPv6 socket accepting all
* incoming connections coming from a specific address for incoming tubes or
* the stream tube is capable of mapping connections to the socket's source address for
* outgoing tubes, \c false otherwise.
* \sa IncomingStreamTubeChannel::acceptTubeAsTcpSocket(),
* OutgoingStreamTubeChannel::offerTcpSocket(),
* OutgoingStreamTubeChannel::connectionsForSourceAddresses(),
* OutgoingStreamTubeChannel::contactsForConnections(),
* supportsIPv6SocketsOnLocalhost()
*/
bool StreamTubeChannel::supportsIPv6SocketsWithSpecifiedAddress() const
{
if (!isReady(FeatureCore)) {
warning() << "StreamTubeChannel::supportsIPv6SocketsWithSpecifiedAddress() used with "
"FeatureCore not ready";
return false;
}
return mPriv->socketTypes.value(SocketAddressTypeIPv6).contains(SocketAccessControlPort);
}
/**
* Return whether this stream tube is capable to accept or offer an Unix socket accepting all
* incoming connections coming from localhost.
*
* Note that it is strongly advised to call this method before attempting to call
* IncomingStreamTubeChannel::acceptTubeAsUnixSocket() or
* OutgoingStreamTubeChannel::offerUnixSocket() without credentials enabled, as the spec implies
* this feature is not compulsory for connection managers.
*
* This method requires StreamTubeChannel::FeatureCore to be ready.
*
* \return \c true if the stream tube is capable to accept or offer an Unix socket
* accepting all incoming connections coming from localhost, \c false otherwise.
* \sa IncomingStreamTubeChannel::acceptTubeAsUnixSocket(),
* OutgoingStreamTubeChannel::offerUnixSocket(),
* supportsUnixSocketsWithCredentials()
* supportsAbstractUnixSocketsOnLocalhost(),
* supportsAbstractUnixSocketsWithCredentials(),
*/
bool StreamTubeChannel::supportsUnixSocketsOnLocalhost() const
{
if (!isReady(FeatureCore)) {
warning() << "StreamTubeChannel::supportsUnixSocketsOnLocalhost() used with "
"FeatureCore not ready";
return false;
}
return mPriv->socketTypes.value(SocketAddressTypeUnix).contains(SocketAccessControlLocalhost);
}
/**
* Return whether this stream tube is capable to accept or offer an Unix socket which will require
* credentials upon connection.
*
* When this capability is available and enabled, the connecting process must send a byte when
* it first connects, which is not considered to be part of the data stream.
* If the operating system uses sendmsg() with SCM_CREDS or SCM_CREDENTIALS to pass
* credentials over sockets, the connecting process must do so if possible;
* if not, it must still send the byte.
*
* The listening process will disconnect the connection unless it can determine
* by OS-specific means that the connecting process has the same user ID as the listening process.
*
* Note that it is strongly advised to call this method before attempting to call
* IncomingStreamTubeChannel::acceptTubeAsUnixSocket() or
* OutgoingStreamTubeChannel::offerUnixSocket() with credentials enabled, as the spec implies
* this feature is not compulsory for connection managers.
*
* This method requires StreamTubeChannel::FeatureCore to be ready.
*
* \return \c true if the stream tube is capable to accept or offer an Unix socket
* which will require credentials upon connection, \c false otherwise.
* \sa IncomingStreamTubeChannel::acceptTubeAsUnixSocket(),
* OutgoingStreamTubeChannel::offerUnixSocket(),
* supportsUnixSocketsOnLocalhost(),
* supportsAbstractUnixSocketsOnLocalhost(),
* supportsAbstractUnixSocketsWithCredentials(),
*/
bool StreamTubeChannel::supportsUnixSocketsWithCredentials() const
{
if (!isReady(FeatureCore)) {
warning() << "StreamTubeChannel::supportsUnixSocketsWithCredentials() used with "
"FeatureCore not ready";
return false;
}
return mPriv->socketTypes[SocketAddressTypeUnix].contains(SocketAccessControlCredentials);
}
/**
* Return whether this stream tube is capable to accept or offer an abstract Unix socket accepting
* all incoming connections coming from localhost.
*
* Note that it is strongly advised to call this method before attempting to call
* IncomingStreamTubeChannel::acceptTubeAsUnixSocket() or
* OutgoingStreamTubeChannel::offerUnixSocket() without credentials enabled, as the spec implies
* this feature is not compulsory for connection managers.
*
* This method requires StreamTubeChannel::FeatureCore to be ready.
*
* \return \c true if the stream tube is capable to accept or offer an abstract Unix socket
* accepting all incoming connections coming from localhost, \c false otherwise.
* \sa IncomingStreamTubeChannel::acceptTubeAsUnixSocket(),
* OutgoingStreamTubeChannel::offerUnixSocket(),
* supportsUnixSocketsOnLocalhost(),
* supportsUnixSocketsWithCredentials(),
* supportsAbstractUnixSocketsWithCredentials()
*/
bool StreamTubeChannel::supportsAbstractUnixSocketsOnLocalhost() const
{
if (!isReady(FeatureCore)) {
warning() << "StreamTubeChannel::supportsAbstractUnixSocketsOnLocalhost() used with "
"FeatureCore not ready";
return false;
}
return mPriv->socketTypes[SocketAddressTypeAbstractUnix].contains(SocketAccessControlLocalhost);
}
/**
* Return whether this stream tube is capable to accept or offer an abstract Unix socket which will
* require credentials upon connection.
*
* When this capability is available and enabled, the connecting process must send a byte when
* it first connects, which is not considered to be part of the data stream.
* If the operating system uses sendmsg() with SCM_CREDS or SCM_CREDENTIALS to pass
* credentials over sockets, the connecting process must do so if possible;
* if not, it must still send the byte.
*
* The listening process will disconnect the connection unless it can determine
* by OS-specific means that the connecting process has the same user ID as the listening process.
*
* Note that it is strongly advised to call this method before attempting to call
* IncomingStreamTubeChannel::acceptTubeAsUnixSocket() or
* OutgoingStreamTubeChannel::offerUnixSocket() with credentials enabled, as the spec implies
* this feature is not compulsory for connection managers.
*
* This method requires StreamTubeChannel::FeatureCore to be ready.
*
* \return \c true if the stream tube is capable to accept or offer an abstract Unix socket
* which will require credentials upon connection, \c false otherwise.
* \sa IncomingStreamTubeChannel::acceptTubeAsUnixSocket(),
* OutgoingStreamTubeChannel::offerUnixSocket(),
* supportsUnixSocketsOnLocalhost(),
* supportsUnixSocketsWithCredentials(),
* supportsAbstractUnixSocketsOnLocalhost()
*/
bool StreamTubeChannel::supportsAbstractUnixSocketsWithCredentials() const
{
if (!isReady(FeatureCore)) {
warning() << "StreamTubeChannel::supportsAbstractUnixSocketsWithCredentials() used with "
"FeatureCore not ready";
return false;
}
return mPriv->socketTypes[SocketAddressTypeAbstractUnix].contains(SocketAccessControlCredentials);
}
/**
* Return all the known active connections since StreamTubeChannel::FeatureConnectionMonitoring has
* been enabled.
*
* For this method to return all known connections, you need to make
* StreamTubeChannel::FeatureConnectionMonitoring ready before accepting or offering the stream
* tube.
*
* This method requires StreamTubeChannel::FeatureConnectionMonitoring to be ready.
*
* \return The list of active connection ids.
* \sa newConnection(), connectionClosed()
*/
QSet<uint> StreamTubeChannel::connections() const
{
if (!isReady(FeatureConnectionMonitoring)) {
warning() << "StreamTubeChannel::connections() used with "
"FeatureConnectionMonitoring not ready";
return QSet<uint>();
}
return mPriv->connections;
}
/**
* Return the type of the tube's local endpoint socket.
*
* Note that this function will return a valid value only after state() has gone #TubeStateOpen.
*
* \return The socket type as #SocketAddressType.
* \sa localAddress(), ipAddress()
*/
SocketAddressType StreamTubeChannel::addressType() const
{
return mPriv->addressType;
}
/**
* Return the access control used by this stream tube.
*
* Note that this function will only return a valid value after state() has gone #TubeStateOpen.
*
* \return The access control as #SocketAccessControl.
* \sa addressType()
*/
SocketAccessControl StreamTubeChannel::accessControl() const
{
return mPriv->accessControl;
}
/**
* Return the IP address/port combination used by this stream tube.
*
* This method will return a meaningful value only if the local endpoint socket for the tube is a
* TCP socket, i.e. addressType() is #SocketAddressTypeIPv4 or #SocketAddressTypeIPv6.
*
* Note that this function will return a valid value only after state() has gone #TubeStateOpen.
*
* \return Pair of IP address as QHostAddress and port if using a TCP socket,
* or an undefined value otherwise.
* \sa localAddress()
*/
QPair<QHostAddress, quint16> StreamTubeChannel::ipAddress() const
{
if (state() != TubeChannelStateOpen) {
warning() << "Tube not open, returning invalid IP address";
return qMakePair<QHostAddress, quint16>(QHostAddress::Null, 0);
}
return mPriv->ipAddress;
}
/**
* Return the local address used by this stream tube.
*
* This method will return a meaningful value only if the local endpoint socket for the tube is an
* UNIX socket, i.e. addressType() is #SocketAddressTypeUnix or #SocketAddressTypeAbstractUnix.
*
* Note that this function will return a valid value only after state() has gone #TubeStateOpen.
*
* \return Unix socket address if using an Unix socket,
* or an undefined value otherwise.
* \sa ipAddress()
*/
QString StreamTubeChannel::localAddress() const
{
if (state() != TubeChannelStateOpen) {
warning() << "Tube not open, returning invalid local socket address";
return QString();
}
return mPriv->unixAddress;
}
void StreamTubeChannel::addConnection(uint connection)
{
if (!mPriv->connections.contains(connection)) {
mPriv->connections.insert(connection);
emit newConnection(connection);
} else {
warning() << "Tried to add connection" << connection << "on StreamTube" << objectPath()
<< "but it already was there";
}
}
void StreamTubeChannel::removeConnection(uint connection, const QString &error,
const QString &message)
{
if (mPriv->connections.contains(connection)) {
mPriv->connections.remove(connection);
emit connectionClosed(connection, error, message);
} else {
warning() << "Tried to remove connection" << connection << "from StreamTube" << objectPath()
<< "but it wasn't there";
}
}
void StreamTubeChannel::setAddressType(SocketAddressType type)
{
mPriv->addressType = type;
}
void StreamTubeChannel::setAccessControl(SocketAccessControl accessControl)
{
mPriv->accessControl = accessControl;
}
void StreamTubeChannel::setIpAddress(const QPair<QHostAddress, quint16> &address)
{
mPriv->ipAddress = address;
}
void StreamTubeChannel::setLocalAddress(const QString &address)
{
mPriv->unixAddress = address;
}
bool StreamTubeChannel::isDroppingConnections() const
{
return mPriv->droppingConnections;
}
void StreamTubeChannel::gotStreamTubeProperties(PendingOperation *op)
{
if (!op->isError()) {
PendingVariantMap *pvm = qobject_cast<PendingVariantMap *>(op);
mPriv->extractStreamTubeProperties(pvm->result());
debug() << "Got reply to Properties::GetAll(StreamTubeChannel)";
mPriv->readinessHelper->setIntrospectCompleted(StreamTubeChannel::FeatureCore, true);
}
else {
warning().nospace() << "Properties::GetAll(StreamTubeChannel) failed "
"with " << op->errorName() << ": " << op->errorMessage();
mPriv->readinessHelper->setIntrospectCompleted(StreamTubeChannel::FeatureCore, false,
op->errorName(), op->errorMessage());
}
}
void StreamTubeChannel::onConnectionClosed(uint connId, const QString &error,
const QString &message)
{
removeConnection(connId, error, message);
}
void StreamTubeChannel::dropConnections()
{
if (!mPriv->connections.isEmpty()) {
debug() << "StreamTubeChannel invalidated with" << mPriv->connections.size()
<< "connections remaining, synthesizing close events";
mPriv->droppingConnections = true;
foreach (uint connId, mPriv->connections) {
removeConnection(connId, TP_QT_ERROR_ORPHANED,
QLatin1String("parent tube invalidated, streams closing"));
}
mPriv->droppingConnections = false;
}
}
/**
* \fn void StreamTubeChannel::connectionClosed(uint connectionId,
* const QString &errorName, const QString &errorMessage)
*
* Emitted when a connection on this stream tube has been closed.
*
* \param connectionId The unique ID associated with the connection that was closed.
* \param errorName The name of a D-Bus error describing the error that occurred.
* \param errorMessage A debugging message associated with the error.
* \sa newConnection(), connections()
*/
} // Tp
|