void muzzley::init(HTTPReq& _req) {
	time_t _rawtime = time(nullptr);
	struct tm _ptm;
	char _buffer_date[80];
	localtime_r(&_rawtime, &_ptm);
	strftime(_buffer_date, 80, "%a, %d %b %Y %X %Z", &_ptm);

	char _buffer_expires[80];
	_ptm.tm_hour += 1;
	strftime(_buffer_expires, 80, "%a, %d %b %Y %X %Z", &_ptm);

	string _url(_req->url());
	if (_url != "") {
		size_t _b = _url.find("://") + 3;
		size_t _e = _url.find("/", _b);
		string _domain(_url.substr(_b, _e - _b));
		string _path(_url.substr(_e));
		_req->header("Host", _domain);
		_req->url(_path);
	}

	_req->method(muzzley::HTTPGet);
	_req->header("Connection", "close");
	_req->header("User-Agent", "muzzley rest-ful server");
	_req->header("Cache-Control", "max-age=3600");
	_req->header("Vary", "Accept-Language,Accept-Encoding,X-Access-Token,Authorization,E-Tag");
	_req->header("Date", string(_buffer_date));

}
Exemple #2
0
void Utils::deleteFile(const QString &url, const QString &auth)
{
    //qDebug() << "Utils::deleteFile";

    QUrl _url(url);
    QNetworkRequest req(_url);

    /*qDebug() << "url1=" << url;
    qDebug() << "url2=" << req.url().toString();
    qDebug() << "url3=" << req.url().path();*/

    //qDebug() << "auth: " << auth;
    req.setRawHeader("Authorization", auth.toAscii());

    //qDebug() << "utils.cpp:uploadFile _nam=" << _nam->;

    /*QList<QByteArray> l = req.rawHeaderList();
    QList<QByteArray>::iterator i;
    for(i=l.begin(); i!=l.end(); ++i)
        qDebug() << "header=" << *i;
        */

    temp_reply = _nam->deleteResource(req);
    connect(temp_reply,SIGNAL(finished()),this,SLOT(deleteFinished()));
    connect(temp_reply,SIGNAL(error(QNetworkReply::NetworkError)),this,SLOT(error(QNetworkReply::NetworkError)));
}
Exemple #3
0
void KVerbosApp::readProperties(KConfig* _cfg)
{
  QString filename = _cfg->readPathEntry("filename");
  KURL url(filename);
  bool modified = _cfg->readBoolEntry("modified", false);
  if(modified)
  {
    bool canRecover;
    QString tempname = kapp->checkRecoverFile(filename, canRecover);
    KURL _url(tempname);
    if(canRecover)
    {
      doc->openDocument(_url);
      doc->setModified();
      setCaption(_url.fileName(),true);
      QFile::remove(tempname);
    }
  }
  else
  {
    if(!filename.isEmpty())
    {
      doc->openDocument(url);
      setCaption(url.fileName(),false);
    }
  }
}
/**
 * Performs a do asynchronous get operation.
 *
 * @brief AbstractHTTPClient::doAsyncGet Asynchronous get operation.
 * @param url a string that represents the do asynchronous get operation.
 * @param accept.
 * @return returns a QNetworkReply.
 */
QNetworkReply* AbstractHTTPClient::doAsyncGet(QString &url, const char* accept) {
    QUrl _url(url);
    QNetworkRequest request( _url );

    prepareRequest(request);
    request.setRawHeader(QByteArray("accept"), QByteArray(accept));

    QNetworkReply *reply = manager->get( request );

    return reply;
}
Exemple #5
0
void AddLinkDialog::checkURL( void ) {
    QUrl _url ( url() );
    if ( _url.isValid() ) {   //Is the string a valid URL?
       QDesktopServices::openUrl(_url.url() );   //If so, launch the browser to see if it's the correct document
    } else {   //If not, print a warning message box that offers to open the browser to a search engine.
        QString message = i18n( "The URL is not valid. Would you like to open a browser window\nto the Google search engine?" );
        QString caption = i18n( "Invalid URL" );
        if ( KMessageBox::warningYesNo( 0, message, caption, KGuiItem(i18n("Browse Google")), KGuiItem(i18n("Do Not Browse")) )==KMessageBox::Yes ) {
            QDesktopServices::openUrl( QUrl("http://www.google.com") );
        }
    }
}
Exemple #6
0
VLog* VLogHttp::createByURI(const QString& uri)
{
  QUrl _url(uri);
  if (uri == "http" || _url.scheme() == "http")
  {
    int port = _url.port();
    if (port == 0 || port == -1) port = DEFAULT_PORT;

    VLogHttp* logHTTP= new VLogHttp(NULL, port);
    return logHTTP;
  }
  return NULL;
}
Exemple #7
0
VLog* VLogFile::createByURI(const QString& uri)
{
  if (uri == "file")
  {
    return new VLogFile;
  }
  QUrl _url(uri);
  if (_url.scheme() == "file")
  {
    QString skip = "file://";
    QString filePath = uri.mid(skip.length());
    return new VLogFile(filePath);
  }
  return NULL;
}
Exemple #8
0
uint32_t EXPORT_API UWK_CreateView(int maxWidth, int maxHeight, const char* url, void* nativeTexturePtr)
{
        std::string _url(url ? url : "");

#ifdef UWK_UNITY_BETA
    if (UWKPlugin::sBetaDaysLeft_ < 0)
        _url = "http://www.uwebkit.com";
#endif

    UWKBrowser* browser = UWKServer::Instance()->CreateBrowser(maxWidth, maxHeight, _url, nativeTexturePtr);

    if (!browser)
        return UWK_INVALID_BROWSER_ID;
    else
        return browser->GetID();
}
Exemple #9
0
void MainWindow::queryProxys(const QString& url)
{
    proxys.clear();
    QNetworkRequest request;
    QUrl _url(url);
    request.setUrl(_url);
    QNetworkReply* reply = networkManager->get(request);
    QEventLoop loop;
    QTimer timer;
    timer.setSingleShot(true);
    connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
    connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
    timer.start(5000);
    loop.exec();
    timer.stop();
    if (reply->isFinished())
    {
        if (reply->error() == QNetworkReply::NoError)
        {
            QString value = reply->readAll();
            QStringList values = value.split("\n");
            for(int i = 0; i < values.count(); i++)
            {
                QString proxyUrl = values.at(i).trimmed();
                if (proxyUrl.contains(":") && !proxyUrl.isEmpty())
                {
                    QStringList urlAndPort = proxyUrl.split(":");
                    proxys << QPair<QString, int>(urlAndPort.at(0), urlAndPort.at(1).toInt());
                }

            }

        }
        else
        {
            qDebug() << "error data";
        }
    }
    else
    {
        networkManager->setNetworkAccessible(QNetworkAccessManager::NotAccessible);
        qDebug() << "timeout";
    }
    reply->deleteLater();
}
Exemple #10
0
/**
 * Loads Server information.
 *
 * @brief ServerInfoClient::loadServerInfo
 */
bool ServerInfoClient::loadServerInfo(){
    QString url = baseURL();

    QUrl _url(url);
    QNetworkRequest request( _url );

    prepareRequest(request);
    request.setRawHeader(QByteArray("accept"), QByteArray("application/json"));

    QEventLoop loop;

    QTimer timeoutTimer;
    timeoutTimer.setSingleShot(true);
    connect(&timeoutTimer, SIGNAL(timeout()), &loop, SLOT(quit()));

    //REST request
    QNetworkReply *reply = manager->get( request );
    QObject::connect(reply, SIGNAL(readyRead()), &loop, SLOT(quit()));

    //Wait 2000 miliseconds
    timeoutTimer.start(2000);

    loop.exec();

    if(reply->bytesAvailable() == 0)
    {        
        return false;
    }

    QByteArray arr = reply->readAll();

    QJsonDocument jsonResponse = QJsonDocument::fromJson(arr);
    QJsonObject jsonObject = jsonResponse.object();

    _initializeDate = jsonObject["initializeDate"].toString().toLongLong();
    _serverBootTime = jsonObject["serverBootTime"].toString().toLongLong();
    _currentServerTime = jsonObject["currentServerTime"].toString().toLongLong();
    _icatEnabled = jsonObject["icatEnabled"].toString();
    _relVersion =  jsonObject["relVersion"].toString();
    _apiVersion =  jsonObject["apiVersion"].toString();
    _rodsZone =  jsonObject["rodsZone"].toString();

    return true;

}
Exemple #11
0
int PlacesModel::indexForUrl(const QString& url) const
{
    QUrl _url(url);
    QModelIndex idx;

    for (int i = 0; i < rowCount(); i++) {
        if (_url == m_sourceModel->url(mapToSource(index(i, 0)))) {
            idx = index(i, 0);
            break;
        }
    }

    if (idx.isValid()) {
        return idx.row();
    }

    return -1;
}
Exemple #12
0
void KVerbosApp::saveProperties(KConfig *_cfg)
{
  if(doc->URL().fileName()!=i18n("Untitled") && !doc->isModified())
  {
    // saving to tempfile not necessary

  }
  else
  {
    KURL url=doc->URL();	
    _cfg->writePathEntry("filename", url.url());
    _cfg->writeEntry("modified", doc->isModified());
    QString tempname = kapp->tempSaveName(url.url());
    QString tempurl= KURL::encode_string(tempname);
    KURL _url(tempurl);
    doc->saveDocument(_url);
  }
}
/**
 * Performs a request with a do Delete operation.
 *
 * @brief AbstractHTTPClient::doDelete Delete operation
 * @param url a string that represents the do Delete operation
 * @return returns a QByteArray.
 */
QByteArray AbstractHTTPClient::doDelete(QString &url) {
    QUrl _url(url);
    QNetworkRequest request( _url );

    prepareRequest(request);

    QNetworkReply *reply = manager->deleteResource(request);
    QEventLoop loop;
    QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));

    QTimer timeoutTimer;
    timeoutTimer.setSingleShot(true);
    connect(&timeoutTimer, SIGNAL(timeout()), &loop, SLOT(quit()));

    timeoutTimer.start(2000);

    loop.exec();

    QByteArray arr = reply->readAll();
    return arr;
}
Exemple #14
0
void PageSpider::parseUrl(const QByteArray &data)
{
    QRegExp rx(m_urlPattern);
    rx.setMinimal(true);//使用非贪婪匹配原则
    QString str = QString(data); //QString::fromUtf8(replyData);
    int pos = 0;
    while ((pos = rx.indexIn(str, pos)) != -1)
    {
        if( rx.captureCount() > 0)
        {
            QString strUrl = rx.cap(1);
            QString title = rx.cap(2);
            title = title.replace(QRegExp("&.*;"), "-");
            QUrl url(strUrl );
            if( url.isRelative() )
                url = QUrl( m_rootUrl + strUrl );
            Url _url(title, url);
            UrlQueue::instance()->imagePageEnqueue(_url);
            ++m_imgCount;
        }
        pos += rx.matchedLength();
    }
}
QByteArray AbstractHTTPClient::doHttpOperation(QString &url, QByteArray &content, HTTPOperation op) {
    QUrl _url(url);
    QNetworkRequest request( _url );

    prepareRequest(request);
    request.setRawHeader("content-type", _contentType.toStdString().c_str());

    QNetworkReply *reply = NULL;

    switch(op) {
    case POST:
        reply = manager->post(request,content);
        break;
    case PUT:
        reply = manager->put(request,content);
        break;
    }

    QEventLoop loop;
    QObject::connect(reply, SIGNAL(readyRead()), &loop, SLOT(quit()));

    QTimer timeoutTimer;
    timeoutTimer.setSingleShot(true);
    connect(&timeoutTimer, SIGNAL(timeout()), &loop, SLOT(quit()));

    timeoutTimer.start(2000);

    loop.exec();

    if(reply->error() != QNetworkReply::NoError) {
        return QByteArray();
    }

    QByteArray arr = reply->readAll();

    return arr;
}