Exemplo n.º 1
0
QString QUrlProto::userInfo() const
{
  QUrl *item = qscriptvalue_cast<QUrl*>(thisObject());
  if (item)
    return item->userInfo();
  return QString();
}
Exemplo n.º 2
0
HttpEngine::HttpEngine(QUrl url, QUrl referrer, QUuid proxyUuid) : m_pRemote(0), m_url(url)
{
	QString user_info;
	QString query, host;
//	QList<Proxy> listProxy = Proxy::loadProxys();


    m_proxyData.nType = Proxy::ProxyNone;
	
    host = url.host();
    if(url.port(80) != 80)
        host += QString(":") + QString::number(url.port(80));


    if (Proxy::isProxyEnabled()){
        Proxy p = Proxy:: loadProxy();
        if(p.uuid == proxyUuid)
        {
            m_proxyData = p;

        }
    }

	
	if(!url.hasQuery())
		query = url.path();
	else
		query = url.path()+"?"+url.encodedQuery();
	
	if(query.isEmpty())
		query = "/";
	
	if(m_proxyData.nType == Proxy::ProxyHttp)
	{
		m_header.setRequest("GET", QString("%1://%2%3").arg(url.scheme()).arg(host).arg(query));
		if(!m_proxyData.strUser.isEmpty())
			m_header.addValue("Proxy-Authorization", QString("Basic %1").arg((QString) (m_proxyData.strUser+":"+m_proxyData.strPassword).toUtf8().toBase64()) );
	}
	else
		m_header.setRequest("GET", query);
	
	user_info = url.userInfo();
	if(!user_info.isEmpty())
		m_header.addValue("Authorization", QString("Basic %1").arg( QString(user_info.toUtf8().toBase64()) ));
	
	if(referrer.isValid())
		m_header.addValue("Referrer", referrer.toString());
	
	m_header.addValue("Host", host);
	m_header.addValue("Connection", "close");
}
Exemplo n.º 3
0
EwsEngine::EwsEngine(const QSettings &settings, const QString &uuid, QObject *parent) :
    QObject(parent),
    m_uuid(uuid)
{
    // First thing to do is setup our connection
    m_internalUri = settings.value("internalASUrl").toString();
    m_externalUri = settings.value("externalASUrl").toString();

    QUrl credentials = settings.value("URI").toUrl();
    m_internalUri.setUserInfo(credentials.userInfo());
    m_externalUri.setUserInfo(credentials.userInfo());

    m_connection = new Ews::Connection(this);
    m_connection->setUri(m_internalUri);

    QDir dataLocation = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
    if (!dataLocation.exists() && !dataLocation.mkpath(dataLocation.absolutePath())) {
        qWarning() << "Failed to create data directory" << dataLocation.absolutePath();
    }

    QString accountName = settings.value("Description").toString();
    if (accountName.isEmpty()) {
        accountName = settings.value("EmailAddress").toString().section(QLatin1Char('@'), 1, 1).section(QLatin1Char('.'), 0, 0);
    }

    m_folderModel = new EwsFolderModel(dataLocation.absolutePath(), this);
    m_folderModel->setProperty("HEADER", accountName.toUpper());
//    connect(m_folderModel, SIGNAL(syncItems(QString)),
//            SLOT(syncItems(QString)));

//    qDebug() << Q_FUNC_INFO << uri.host() << m_uuid;

    checkDNS();

    // Update the list in one minute
    QTimer *timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), SLOT(update()));
    timer->setInterval(5000);
    timer->start();
}
Exemplo n.º 4
0
void IPTVStreamHandler::run(void)
{
    RunProlog();

    LOG(VB_GENERAL, LOG_INFO, LOC + "run()");

    SetRunning(true, false, false);

    // TODO Error handling..

    // Setup
    CetonRTSP *rtsp = NULL;
    IPTVTuningData tuning = m_tuning;
    if (m_tuning.GetURL(0).scheme().toLower() == "rtsp")
    {
        rtsp = new CetonRTSP(m_tuning.GetURL(0));

        // Check RTSP capabilities
        QStringList options;
        if (!(rtsp->GetOptions(options)     && options.contains("OPTIONS")  &&
              options.contains("DESCRIBE")  && options.contains("SETUP")    &&
              options.contains("PLAY")      && options.contains("TEARDOWN")))
        {
            LOG(VB_RECORD, LOG_ERR, LOC +
                "RTSP interface did not support the necessary options");
            delete rtsp;
            SetRunning(false, false, false);
            RunEpilog();
            return;
        }

        if (!rtsp->Describe())
        {
            LOG(VB_RECORD, LOG_ERR, LOC +
                "RTSP Describe command failed");
            delete rtsp;
            SetRunning(false, false, false);
            RunEpilog();
            return;
        }

        tuning = IPTVTuningData(
            QString("rtp://%1@%2:0")
            .arg(m_tuning.GetURL(0).host())
            .arg(QHostAddress(QHostAddress::Any).toString()), 0,
            IPTVTuningData::kNone,
            QString("rtp://%1@%2:0")
            .arg(m_tuning.GetURL(0).host())
            .arg(QHostAddress(QHostAddress::Any).toString()), 0,
            "", 0);
    }

    for (uint i = 0; i < IPTV_SOCKET_COUNT; i++)
    {
        QUrl url = tuning.GetURL(i);
        if (url.port() < 0)
            continue;

        m_sockets[i] = new QUdpSocket();
        m_read_helpers[i] = new IPTVStreamHandlerReadHelper(
            this, m_sockets[i], i);

        // we need to open the descriptor ourselves so we
        // can set some socket options
        int fd = socket(AF_INET, SOCK_DGRAM, 0); // create IPv4 socket
        if (fd < 0)
        {
            LOG(VB_GENERAL, LOG_ERR, LOC +
                "Unable to create socket " + ENO);
            continue;
        }
        int buf_size = 2 * 1024 * max(tuning.GetBitrate(i)/1000, 500U);
        if (!tuning.GetBitrate(i))
            buf_size = 2 * 1024 * 1024;
        int ok = setsockopt(fd, SOL_SOCKET, SO_RCVBUF,
                            (char *)&buf_size, sizeof(buf_size));
        if (ok)
        {
            LOG(VB_GENERAL, LOG_INFO, LOC +
                QString("Increasing buffer size to %1 failed")
                .arg(buf_size) + ENO);
        }
        /*
          int broadcast = 1;
          ok = setsockopt(fd, SOL_SOCKET, SO_BROADCAST,
          (char *)&broadcast, sizeof(broadcast));
          if (ok)
          {
          LOG(VB_GENERAL, LOG_INFO, LOC +
          QString("Enabling broadcast failed") + ENO);
          }
        */
        m_sockets[i]->setSocketDescriptor(
            fd, QAbstractSocket::UnconnectedState, QIODevice::ReadOnly);

        m_sockets[i]->bind(QHostAddress::Any, url.port());

        QHostAddress dest_addr(tuning.GetURL(i).host());

        if (dest_addr != QHostAddress::Any)
        {
            //m_sockets[i]->joinMulticastGroup(dest_addr); // needs Qt 4.8
            LOG(VB_GENERAL, LOG_INFO, LOC + QString("Joining %1")
                .arg(dest_addr.toString()));
            struct ip_mreq imr;
            memset(&imr, 0, sizeof(struct ip_mreq));
            imr.imr_multiaddr.s_addr = inet_addr(
                dest_addr.toString().toLatin1().constData());
            imr.imr_interface.s_addr = htonl(INADDR_ANY);
            if (setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP,
				(const char *)&imr, sizeof(imr)) < 0)
            {
                LOG(VB_GENERAL, LOG_ERR, LOC +
                    "setsockopt - IP_ADD_MEMBERSHIP " + ENO);
            }
        }

        if (!url.userInfo().isEmpty())
            m_sender[i] = QHostAddress(url.userInfo());
    }
    if (m_use_rtp_streaming)
        m_buffer = new RTPPacketBuffer(tuning.GetBitrate(0));
    else
        m_buffer = new UDPPacketBuffer(tuning.GetBitrate(0));
    m_write_helper = new IPTVStreamHandlerWriteHelper(this);
    m_write_helper->Start();

    bool error = false;
    if (rtsp)
    {
        // Start Streaming
        if (!rtsp->Setup(m_sockets[0]->localPort(),
                         m_sockets[1]->localPort()) ||
            !rtsp->Play())
        {
            LOG(VB_RECORD, LOG_ERR, LOC +
                "Starting recording (RTP initialization failed). Aborting.");
            error = true;
        }
    }

    if (!error)
    {
        // Enter event loop
        exec();
    }

    // Clean up
    for (uint i = 0; i < IPTV_SOCKET_COUNT; i++)
    {
        if (m_sockets[i])
        {
            delete m_sockets[i];
            m_sockets[i] = NULL;
            delete m_read_helpers[i];
            m_read_helpers[i] = NULL;
        }
    }
    delete m_buffer;
    m_buffer = NULL;
    delete m_write_helper;
    m_write_helper = NULL;

    if (rtsp)
    {
        rtsp->Teardown();
        delete rtsp;
    }

    SetRunning(false, false, false);
    RunEpilog();
}
Exemplo n.º 5
0
int Url::userInfo ( lua_State * L )// const : QString
{
	QUrl* lhs = ValueInstaller2<QUrl>::check( L, 1 );
	lua_pushstring(L, lhs->userInfo().toLatin1() );
	return 1;
}
Exemplo n.º 6
0
void MainWindow::addTransfer(QString uri, Transfer::Mode mode, QString className, int qSel)
{
	Queue* queue = 0;
	
	if(m_dlgNewTransfer)
	{
		m_dlgNewTransfer->addLinks(uri);
		return;
	}
	if(qSel < 0)
	{
		qSel = getSelectedQueue();
		if(qSel < 0)
		{
			if(g_queues.size())
				qSel = 0;
			else
				return;
		}
	}
	
	m_dlgNewTransfer = new NewTransferDlg(this);
	
	m_dlgNewTransfer->setWindowTitle(tr("New transfer"));
	m_dlgNewTransfer->m_nQueue = qSel;
	m_dlgNewTransfer->m_strURIs = uri;
	
	if(!uri.isEmpty() && className.isEmpty())
	{
		QStringList l = uri.split('\n', QString::SkipEmptyParts);
		Transfer::BestEngine eng = Transfer::bestEngine(l[0], mode);
		
		if(eng.type != Transfer::ModeInvalid)
			m_dlgNewTransfer->m_mode = eng.type;
	}
	else
	{
		m_dlgNewTransfer->m_mode = mode;
		m_dlgNewTransfer->m_strClass = className;
	}
	
	QList<Transfer*> listTransfers;
	
show_dialog:
	try
	{
		QStringList uris;
		int sep = getSettingsValue("link_separator").toInt();
		
		if(m_dlgNewTransfer->exec() != QDialog::Accepted)
			throw RuntimeException();
		
		if(!sep)
			uris = m_dlgNewTransfer->m_strURIs.split('\n', QString::SkipEmptyParts);
		else
			uris = m_dlgNewTransfer->m_strURIs.split(QRegExp("\\s+"), QString::SkipEmptyParts);
		
		if(uris.isEmpty())
			throw RuntimeException();

		for(int i=0;i<uris.size();i++)
		{
			QString trm = uris[i].trimmed();
			
			if(trm.isEmpty())
			{
				uris.removeAt(i);
				i--;
			}
			else
				uris[i] = trm;
		}
		
		int detectedClass = m_dlgNewTransfer->m_nClass; // used for the multiple cfg dialog
		for(int i=0;i<uris.size();i++)
		{
			Transfer* d;
			
			int classID;
			if(m_dlgNewTransfer->m_nClass == -1)
			{
				// autodetection
				Transfer::BestEngine eng;
				
				if(m_dlgNewTransfer->m_mode == Transfer::Download)
					eng = Transfer::bestEngine(uris[i], Transfer::Download);
				else
					eng = Transfer::bestEngine(m_dlgNewTransfer->m_strDestination, Transfer::Upload);
				
				if(eng.nClass < 0)
					throw RuntimeException(tr("Couldn't autodetect transfer type for \"%1\"").arg(uris[i]));
				else
					classID = eng.nClass;

				if(detectedClass == -1)
					detectedClass = classID;
				else if(detectedClass >= 0 && detectedClass != classID)
					detectedClass = -2;
			}
			else
				classID = m_dlgNewTransfer->m_nClass;
			
			d = Transfer::createInstance(m_dlgNewTransfer->m_mode, classID);
			
			if(d == 0)
				throw RuntimeException(tr("Failed to create a class instance."));
			
			listTransfers << d;
			
			QString source, destination;
			
			source = uris[i].trimmed();
			destination = m_dlgNewTransfer->m_strDestination;
			
			if(!m_dlgNewTransfer->m_auth.strUser.isEmpty())
			{
				QString& obj = (m_dlgNewTransfer->m_mode == Transfer::Download) ? source : destination;
				
				QUrl url = obj;
				if(url.userInfo().isEmpty())
				{
					url.setUserName(m_dlgNewTransfer->m_auth.strUser);
					url.setPassword(m_dlgNewTransfer->m_auth.strPassword);
				}
				obj = url.toString();
			}
			
			d->init(source, destination);
			d->setUserSpeedLimits(m_dlgNewTransfer->m_nDownLimit,m_dlgNewTransfer->m_nUpLimit);
		}
		
		// show the transfer details dialog
		if(m_dlgNewTransfer->m_bDetails)
		{
			// show a typical transfer propeties dialog
			if(listTransfers.size() == 1)
			{
				WidgetHostDlg dlg(this);
				m_dlgNewTransfer->setWindowTitle(tr("Transfer details"));
				
				if(WidgetHostChild* q = listTransfers[0]->createOptionsWidget(dlg.getChildHost()))
				{
					dlg.addChild(q);
					
					if(dlg.exec() != QDialog::Accepted)
						throw RuntimeException();
				}
			}
			else if(detectedClass >= 0) // show a dialog designed for multiple
			{
				if(!Transfer::runProperties(this, m_dlgNewTransfer->m_mode, detectedClass, listTransfers))
					throw RuntimeException();
			}
			else
			{
				QMessageBox::warning(this, "FatRat", tr("Cannot display detailed configuration when there are multiple transfer types used."));
			}
		}
		
		if(!m_dlgNewTransfer->m_bPaused)
		{
			foreach(Transfer* d, listTransfers)
				d->setState(Transfer::Waiting);
		}
		
		queue = getQueue(m_dlgNewTransfer->m_nQueue, false);
		
		if(!queue)
			throw RuntimeException(tr("Internal error."));
		
		queue->add(listTransfers);
	}
	catch(const RuntimeException& e)
	{
		qDeleteAll(listTransfers);
		listTransfers.clear();
		if(!e.what().isEmpty())
		{
			QMessageBox::critical(this, tr("Error"), e.what());
			goto show_dialog;
		}
	}
	
	delete m_dlgNewTransfer;
	m_dlgNewTransfer = 0;
	
	if(queue != 0)
		doneQueue(queue,false);
	
	Queue::saveQueuesAsync();
}
/**
 * @brief creating new transfer
 *
 * @param m_strURIs transfers urls
 * @param downloadTrueUploadFalse boolean value for download or upload
 * @param m_nClass download type default -1
 * @param m_strDestination destination fo transfer
 * @param m_nDownLimit down limit of transfer
 * @param m_nUpLimit up limit of transfer
 * @param m_bPaused boolean true if transfer is paused
 */
void TransfersMethods::createTransfer(QString m_strURIs,bool downloadTrueUploadFalse,int m_nClass,QString m_strDestination,
                                     int m_nDownLimit,int m_nUpLimit,bool m_bPaused)
{
     Queue* queue = 0;
     QList<Transfer*> listTransfers;
     try
     {
         QStringList uris;
             uris = m_strURIs.split('\n', QString::SkipEmptyParts);
         if(uris.isEmpty())
             throw RuntimeException();
         for(int i=0;i<uris.size();i++)
         {
             QString trm = uris[i].trimmed();

             if(trm.isEmpty())
             {
                 uris.removeAt(i);
                 i--;
             }
             else
                 uris[i] = trm;
         }
         int detectedClass = m_nClass;
         for(int i=0;i<uris.size();i++)
         {
             Transfer* d;

             int classID;
             if(m_nClass == -1)
             {
                 Transfer::BestEngine eng;

                 if(downloadTrueUploadFalse)
                     eng = Transfer::bestEngine(uris[i], Transfer::Download);
                 else
                     eng = Transfer::bestEngine(m_strDestination, Transfer::Upload);

                 if(eng.nClass < 0)
                     throw RuntimeException(tr("Couldn't autodetect transfer type for \"%1\"").arg(uris[i]));
                 else
                     classID = eng.nClass;

                 if(detectedClass == -1)
                     detectedClass = classID;
                 else if(detectedClass >= 0 && detectedClass != classID)
                     detectedClass = -2;
             }
             else
                 classID = m_nClass;

             Transfer::Mode myMode = downloadTrueUploadFalse ? Transfer::Download : Transfer::Upload;;
             d = Transfer::createInstance(myMode, classID);

             if(d == 0)
                 throw RuntimeException(tr("Failed to create a class instance."));

             listTransfers << d;

             QString source, destination;

             source = uris[i].trimmed();
             destination = m_strDestination;

             d->setUrl( (myMode == Transfer::Download) ? source : destination);
             if(!m_auth.strUser.isEmpty())
             {
                 QString& obj = (myMode == Transfer::Download) ? source : destination;

                 QUrl url = obj;
                 if(url.userInfo().isEmpty())
                 {
                     url.setUserName(m_auth.strUser);
                     url.setPassword(m_auth.strPassword);
                 }
                 obj = url.toString();
             }


             d->init(source, destination);
             d->setUserSpeedLimits(m_nDownLimit,m_nUpLimit);
         }
         if(m_bPaused)
         {
             foreach(Transfer* d, listTransfers)
                 d->setState(Transfer::Waiting);
         }
         else
         {
             foreach(Transfer* d, listTransfers)
                 d->setState(Transfer::Active);
         }
         g_queuesLock.lockForWrite();
         queue = g_queues[0];
         if(!queue)
             throw RuntimeException(tr("Internal error."));
         queue->add(listTransfers);
         g_queuesLock.unlock();
     }
     catch(const RuntimeException& e)
     {
         qDeleteAll(listTransfers);
         listTransfers.clear();
         if(!e.what().isEmpty())
         {
             qDebug() <<"Error: " + e.what();
         }
     }

     Queue::saveQueuesAsync();

}
Exemplo n.º 8
0
void IPTVStreamHandler::run(void)
{
    RunProlog();

    LOG(VB_GENERAL, LOG_INFO, LOC + "run()");

    SetRunning(true, false, false);

    // TODO Error handling..

    // Setup
    CetonRTSP *rtsp = NULL;
    IPTVTuningData tuning = m_tuning;
    if (m_tuning.GetURL(0).scheme().toLower() == "rtsp")
    {
        rtsp = new CetonRTSP(m_tuning.GetURL(0));

        // Check RTSP capabilities
        QStringList options;
        if (!(rtsp->GetOptions(options)     && options.contains("OPTIONS")  &&
              options.contains("DESCRIBE")  && options.contains("SETUP")    &&
              options.contains("PLAY")      && options.contains("TEARDOWN")))
        {
            LOG(VB_RECORD, LOG_ERR, LOC +
                "RTSP interface did not support the necessary options");
            delete rtsp;
            SetRunning(false, false, false);
            RunEpilog();
            return;
        }

        if (!rtsp->Describe())
        {
            LOG(VB_RECORD, LOG_ERR, LOC +
                "RTSP Describe command failed");
            delete rtsp;
            SetRunning(false, false, false);
            RunEpilog();
            return;
        }

        tuning = IPTVTuningData(
            QString("rtp://%1@%2:0")
            .arg(m_tuning.GetURL(0).host())
            .arg(QHostAddress(QHostAddress::Any).toString()), 0,
            IPTVTuningData::kNone,
            QString("rtp://%1@%2:0")
            .arg(m_tuning.GetURL(0).host())
            .arg(QHostAddress(QHostAddress::Any).toString()), 0,
            "", 0);
    }

    for (uint i = 0; i < IPTV_SOCKET_COUNT; i++)
    {
        QUrl url = tuning.GetURL(i);
        if (url.port() < 0)
            continue;

        m_sockets[i] = new QTcpSocket();
		m_sockets[i]->setSocketOption(QAbstractSocket::LowDelayOption, 1);
        m_read_helpers[i] = new IPTVStreamHandlerReadHelper(
            this, m_sockets[i], i);

        if (!url.userInfo().isEmpty())
            m_sender[i] = QHostAddress(url.userInfo());

        m_sockets[i]->connectToHost(url.host().toAscii(), 3000);
 if (m_sockets[i]->waitForConnected(1000))
   {
 m_sockets[i]->write("GET " + url.path().toAscii() + " HTTP/1.0\r\n\r\n\r\n\r\n");
                           m_sockets[i]->waitForBytesWritten(500);
                
}
else
{
  qDebug("not Connected!");
    m_sockets[i]->connectToHost(url.host().toAscii(), 3000);
m_sockets[i]->write("GET " + url.path().toAscii() + " HTTP/1.0\r\n\r\n\r\n\r\n");
                           m_sockets[i]->waitForBytesWritten(500);
}
                          
						   
						 
    }
    //if (m_use_rtp_streaming)
      //  m_buffer = new RTPPacketBuffer(tuning.GetBitrate(0));
    //else
        m_buffer = new UDPPacketBuffer(tuning.GetBitrate(0));
    m_write_helper = new IPTVStreamHandlerWriteHelper(this);
    m_write_helper->Start();

    bool error = false;
    /*if (rtsp)
    {
        // Start Streaming
        if (!rtsp->Setup(m_sockets[0]->localPort(),
                         m_sockets[1]->localPort()) ||
            !rtsp->Play())
        {
            LOG(VB_RECORD, LOG_ERR, LOC +
                "Starting recording (RTP initialization failed). Aborting.");
            error = true;
        }
    }
*/
    if (!error)
    {
        // Enter event loop
        exec();
    }

    // Clean up
    for (uint i = 0; i < IPTV_SOCKET_COUNT; i++)
    {
        if (m_sockets[i])
        {
            delete m_sockets[i];
            m_sockets[i] = NULL;
            delete m_read_helpers[i];
            m_read_helpers[i] = NULL;
        }
    }
    delete m_buffer;
    m_buffer = NULL;
    delete m_write_helper;
    m_write_helper = NULL;

    if (rtsp)
    {
        rtsp->Teardown();
        delete rtsp;
    }

    SetRunning(false, false, false);
    RunEpilog();
}