Esempio n. 1
0
QString Protocol::MsgSender::getGroupSig(QString gid, QString to_id)
{
    if ( group_sigs_.contains(gid+to_id) )
        return group_sigs_.value(gid+to_id);

    QString msg_sig_url = "/channel/get_c2cmsg_sig2?id="+ gid +"&to_uin=" + to_id +
        "&service_type=0&clientid=5412354841&psessionid=" + CaptchaInfo::instance()->psessionid() +"&t=" + QString::number(QDateTime::currentMSecsSinceEpoch());

    QHttpRequestHeader header;
    QString host = "d.web2.qq.com";
    header.setRequest("GET", msg_sig_url);
    header.addValue("Host", host);
    header.addValue("Content-Type", "utf-8");
    header.addValue("Referer", "http://d.web2.qq.com/proxy.html?v=20110331002");
    header.addValue("Cookie", CaptchaInfo::instance()->cookie());

    QTcpSocket fd;
    fd.connectToHost(host, 80);
    fd.write(header.toString().toAscii());

    QByteArray result;
    socketReceive(&fd, result);
    fd.close();

    int sig_s_idx = result.indexOf("value")+8;
    int sig_e_idx = result.indexOf('"', sig_s_idx);
    QString sig = result.mid(sig_s_idx, sig_e_idx - sig_s_idx);

    group_sigs_.insert(gid+to_id, sig);

    return sig;
}
Esempio n. 2
0
void BrisaEventProxy::unsubscribe(void) {
    QHttpRequestHeader *unsubscribeReq = getUnsubscriptionRequest();
    http->setHost(host, port);
    int unsubId = http->request(*unsubscribeReq);
    qDebug() << unsubId << " unsubscription: " << unsubscribeReq->toString();
    delete unsubscribeReq;
}
Esempio n. 3
0
void BrisaEventProxy::subscribe(const int timeout) {
    QHttpRequestHeader *subscribeReq = getSubscriptionRequest(timeout);
    http->setHost(host, port);
    requestId = http->request(*subscribeReq);
    qDebug() << requestId << " subscription: " << subscribeReq->toString();
    delete subscribeReq;
}
Esempio n. 4
0
void BrisaEventProxy::renew(const int &newTimeout) {
    QHttpRequestHeader *renewReq = getRenewRequest(newTimeout);
    http->setHost(host, port);
    requestId = http->request(*renewReq);
    qDebug() << requestId << " renew: " << renewReq->toString();
    delete renewReq;
}
Esempio n. 5
0
void
SmugMug::WebService::_uploadMultipartHttpPost (
    const QString &AlbumId,
    const QString &FileName,
    const QString &Caption) {

    const QString BOUNDARY = "----------ThIs_Is_tHe_bouNdaRY_$";
    const QString CFLF = "\r\n";

    QUrl url (UploadEndpoint + "/photos/xmladd.mg");

    _dataOut.clear ();

    QByteArray imageData;
    QFileInfo fi (FileName);
    QFile file (fi.absoluteFilePath ());
    if (file.open (QIODevice::ReadOnly)) {

        imageData = file.readAll ();
        file.close ();
    }

    // Album ID
    _dataOut += QString ("--") + BOUNDARY + CFLF;
    _dataOut += QString ("Content-Disposition: form-data; name=\"AlbumID\"") + CFLF + CFLF;
    _dataOut += AlbumId + CFLF;

    // Session ID
    _dataOut += QString ("--") + BOUNDARY + CFLF;
    _dataOut += QString ("Content-Disposition: form-data; name=\"SessionID\"") + CFLF + CFLF;
    _dataOut += _sessionId + CFLF;

    // Byte Count
    _dataOut += QString ("--") + BOUNDARY + CFLF;
    _dataOut += QString ("Content-Disposition: form-data; name=\"ByteCount\"") + CFLF + CFLF;
    _dataOut += QString::number (imageData.length ()) + CFLF;

    // Response Type
    _dataOut += QString ("--") + BOUNDARY + CFLF;
    _dataOut += QString ("Content-Disposition: form-data; name=\"ResponseType\"") + CFLF + CFLF;
    _dataOut += QString ("REST") + CFLF;

    // MD5 Sum
    _dataOut += QString ("--") + BOUNDARY + CFLF;
    _dataOut += QString ("Content-Disposition: form-data; name=\"MD5Sum\"") + CFLF + CFLF;
    _dataOut += md5_digest (imageData) + CFLF;
//   _dataOut += QString ("a234ab01efe2775e9f69477831c3d3ca") + CFLF;

    // Caption
    if (!Caption.isEmpty ()) {

        _dataOut += QString ("--") + BOUNDARY + CFLF;
        _dataOut += QString ("Content-Disposition: form-data; name=\"Caption\"") + CFLF + CFLF;
        _dataOut += Caption + CFLF;
    }

    // Add the file
    _dataOut += QString ("--") + BOUNDARY + CFLF;

    _dataOut += QString ("Content-Disposition: form-data; name=\"Image\"") +
                QString ("; filename=\"%1\"").arg (fi.fileName ()) + CFLF;

    _dataOut += QString ("Content-Type: image/jpeg") + CFLF;
    _dataOut += QString ("Content-length: %1").arg (imageData.length ()) + CFLF + CFLF;

    qDebug () << _dataOut;

    _dataOut += imageData;
    _dataOut += CFLF;

    _dataOut += QString ("--") + BOUNDARY + "--" + CFLF;

    QHttpRequestHeader header ("POST", url.path ());
    header.setValue ("Host", url.host ());
//   header.setValue ("Cookie", QString ("SMSESS=") + _sessionId);
    header.setContentType (QString ("multipart/form-data; boundary=") + BOUNDARY);
    header.setContentLength (_dataOut.length ());
//   header.setValue ("Connection", "Keep-Alive");

    qDebug () << header.toString ();

    _idImageUpload = _httpRequest (url, header, _dataOut);

    qDebug () << "imageUpload:" << fi.absoluteFilePath ();
}
Esempio n. 6
0
void MainWidget::request( QTcpSocket *id,
                          const QHttpRequestHeader &header )
{
   mpMessageBuffer->addItem( header.toString() );
   while( mpMessageBuffer->count() > 200 )
   {
      QListWidgetItem *item = mpMessageBuffer->takeItem( 0 );
      if( item )
      {
         delete item;
      }
   }
   mpMessageBuffer->scrollToBottom();

#if 0
   if( header.path() == "/favicon.ico" )
   {
      QFile file( ":/favicon.ico" );
      file.open( QIODevice::ReadOnly | QIODevice::Text );
      emit response( id,
                     QHttpResponseHeader( 200, "OK" ),
                     file.readAll() );
      file.close();
      return;
   }
#endif
   if( header.path() == "/wait" )
   {
      mDelayList.append( id );
      return;
   }
   if( header.path() == "/get" )
   {
      QString reply( "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
                     "<response>\n"
                     " <reply>%1</reply>\n"
                     " <artist>%2</artist>\n"
                     " <title>%3</title>\n"
                     " <album>%4</album>\n"
                     " <track>%5</track>\n"
                     "</response>\n" );
      QByteArray replyMsg( reply.arg( Qt::escape( QString::fromUtf8(mMsg.constData()) ),
                                      Qt::escape( mTrackInfo.mArtist ),
                                      Qt::escape( mTrackInfo.mTitle ),
                                      Qt::escape( mTrackInfo.mAlbum ),
                                      QString::number(mTrackInfo.mTrackNr) ).toUtf8() );
      emit response( id,
                     QHttpResponseHeader( 200, "OK XML" ),
                     replyMsg );
      return;
   }
   QString html("<html>\n<head>\n<title>%1</title>\n"
         "<meta http-equiv='content-type' content='text/html; charset=UTF-8'>\n"
         "<link rel='shortcut icon' href='/favicon.ico' type='image/x-icon'>\n"
         "<script src='ajax.js' type='text/javascript'>\n"
         "</script>\n"
         "</head>\n<body>\n"
         "<h1>%2</h1>\n"
         "<p>HTTP Request: %3 %4</p>\n"
         "<table border='1'>\n"
         "<tr valign='top'><td>Artist:</td><td><textarea cols='80' rows='1' name='artist' wrap='off' readonly></textarea></td></tr>\n"
         "<tr valign='top'><td>Title:</td><td><textarea cols='80' rows='1' name='title' wrap='off' readonly></textarea></td></tr>\n"
         "<tr valign='top'><td>Album:</td><td><textarea cols='80' rows='1' name='album' wrap='off' readonly></textarea></td></tr>\n"
         "<tr valign='top'><td>Track:</td><td><textarea cols='80' rows='1' name='track' wrap='off' readonly></textarea></td></tr>\n"
         "<tr valign='top'><td>Reply:</td><td><textarea cols='80' rows='5' name='reply' wrap='off' readonly></textarea></td></tr>\n"
         "<tr valign='top'><td>Status:</td><td><input name='status' size='12' readonly>"
         "<input type='button' value='refresh' onclick='loadFields();'></td></tr>\n"
         "</table></body></html>\n"
         );
   html = html.arg( QApplication::organizationName() + ": " + QApplication::applicationName(),
                    QApplication::organizationName() + ": " + QApplication::applicationName(),
                    header.method(),
                    header.path() );

   emit response( id,
                  QHttpResponseHeader( 200, "OK" ),
                  html.toUtf8() );
}