void IaxNetworkRegistration::registerToServer()
{
    qLog(VoIP) << "IaxNetworkRegistration::registerToServer()";
    if ( registrationState() == QTelephony::RegistrationHome ) {
        if ( pendingSetCurrentOperator ) {
            emit setCurrentOperatorResult( QTelephony::OK );
            pendingSetCurrentOperator = false;
        }
    } else if ( registrationId == -1 ) {
        // We are now searching for a server to register to.
        qLog(VoIP) << "IAX registration set to Searching";
        updateRegistrationState( QTelephony::RegistrationSearching );

        // Read the registration settings to use from Asterisk.conf.
        QSettings config( "Trolltech", "Asterisk" );
        config.beginGroup( "Registration" );
        QString userid = config.value( "UserId" ).toString();
        QString password = config.value( "Password" ).toString();
        QString server = config.value( "Server" ).toString();
        int port = config.value( "Port", -1 ).toInt();
        if ( password.startsWith( ":" ) ) {
            // The password has been base64-encoded.
            password = QString::fromUtf8
                ( QByteArray::fromBase64( password.mid(1).toLatin1() ) );
        }
        config.endGroup();      // Registration

        // If no server, then assume that we cannot register at all.
        if ( server.isEmpty() ) {
            qLog(VoIP) << "IAX registration set to None - no server configured";
            updateRegistrationState( QTelephony::RegistrationNone );
            if ( pendingSetCurrentOperator ) {
                emit setCurrentOperatorResult( QTelephony::Error );
                pendingSetCurrentOperator = false;
            }
            return;
        }

        // Record the call URI for later.  TODO: how to encode special chars?
        if ( password.isEmpty() )
            callUriValue = userid + "@" + server;
        else
            callUriValue = userid + ":" + password + "@" + server;

        // Start the registration process.  TODO: async host lookup.
        if ( port != -1 && port != 0 )
            server += ":" + QString::number( port );
        registrationId = iaxc_register( userid.toUtf8().data(),
                                        password.toUtf8().data(),
                                        server.toUtf8().data() );

        // Handle any pending events or timeouts caused by the registration.
        service->serviceIaxClient();
    }
}
void IaxNetworkRegistration::registrationEvent( int eventType )
{
    // Process an IAX registration event.
    if ( eventType == IAXC_REGISTRATION_REPLY_ACK ||
         eventType == 65535 ) { // IAX_EVENT_NULL, which means already reg'd.
        // Registration is now valid.
        qLog(VoIP) << "IAX registration set to Home";
        updateRegistrationState( QTelephony::RegistrationHome );
        if ( pendingSetCurrentOperator ) {
            emit setCurrentOperatorResult( QTelephony::OK );
            pendingSetCurrentOperator = false;
        }
    } else if ( eventType == IAXC_REGISTRATION_REPLY_REJ ) {
        // Registration authentication failed.
        qLog(VoIP) << "IAX registration set to Denied";
        updateRegistrationState( QTelephony::RegistrationDenied );
        if ( pendingSetCurrentOperator ) {
            emit setCurrentOperatorResult( QTelephony::NetworkNotAllowed );
            pendingSetCurrentOperator = false;
        }
        if ( registrationId != -1 ) {
            iaxc_unregister( registrationId );
            registrationId = -1;
        }
    } else {
        // Registration has failed for some other reason (timeout probably).
        qLog(VoIP) << "IAX registration set to None, event type" << eventType;
        updateRegistrationState( QTelephony::RegistrationNone );
        if ( pendingSetCurrentOperator ) {
            emit setCurrentOperatorResult( QTelephony::Error );
            pendingSetCurrentOperator = false;
        }
        if ( registrationId != -1 ) {
            iaxc_unregister( registrationId );
            registrationId = -1;
        }
    }
}
void IaxNetworkRegistration::deregisterFromServer()
{
    qLog(VoIP) << "IaxNetworkRegistration::deregisterFromServer()";
    callUriValue = QString();
    if ( registrationId != -1 ) {
        iaxc_unregister( registrationId );
        registrationId = -1;

        // Handle any pending events or timeouts caused by the unregistration.
        service->serviceIaxClient();
    }
    qLog(VoIP) << "IAX registration set to None";
    updateRegistrationState( QTelephony::RegistrationNone );
    if ( pendingSetCurrentOperator ) {
        emit setCurrentOperatorResult( QTelephony::OK );
        pendingSetCurrentOperator = false;
    }
}
示例#4
0
void PstnNetworkRegistration::setCurrentOperator
        ( QTelephony::OperatorMode, const QString&, const QString&)
{
    emit setCurrentOperatorResult( QTelephony::OK );
}