void ElogThreadSubmit::doTransmit( ) { KURL destination; QStringList::iterator it; QStringList strListAttributes; QStringList strListAttribute; QString boundary; int iAttachment = 0; destination.setProtocol("http"); destination.setHost(_elog->configuration()->ipAddress()); destination.setPort((short)_elog->configuration()->portNumber()); destination.setQuery(""); if (!_strLogbook.isEmpty()) { destination.setPath(QString("/%1/").arg(_strLogbook)); } srand((unsigned) time(NULL)); boundary = QString("---------------------------%1%2%3").arg(rand(), 4, 16).arg(rand(), 4, 16).arg(rand(), 4, 16); // // add the attributes... // addAttribute( _dataStreamAll, boundary, "cmd", "Submit", false ); addAttribute( _dataStreamAll, boundary, "unm", _strUserName, false ); addAttribute( _dataStreamAll, boundary, "upwd", _strUserPassword, true ); addAttribute( _dataStreamAll, boundary, "exp", _strLogbook, false ); strListAttributes = QStringList::split( '\n', _strAttributes, FALSE ); for ( it = strListAttributes.begin(); it != strListAttributes.end(); ++it ) { strListAttribute = QStringList::split( '=', *it, FALSE ); if( strListAttribute.count() == 2 ) { addAttribute( _dataStreamAll, boundary, strListAttribute.first().stripWhiteSpace(), strListAttribute.last().stripWhiteSpace(), false ); } } if( _bSubmitAsHTML ) { addAttribute( _dataStreamAll, boundary, "html", "1", false ); } if( _bSuppressEmail ) { addAttribute( _dataStreamAll, boundary, "suppress", "1", false ); } addAttribute( _dataStreamAll, boundary, "Text", _strMessage, false ); QString str = QString("%1\r\n").arg(boundary); _dataStreamAll.writeRawBytes(str.ascii(), str.length()); // // add the attachments... // if( _bIncludeCapture ) { iAttachment++; addAttachment( _dataStreamAll, boundary, _byteArrayCapture, iAttachment, "Capture.png" ); } if( _bIncludeConfiguration ) { QByteArray byteArrayConfigure; QTextStream textStreamConfigure( byteArrayConfigure, IO_ReadWrite ); QCustomEvent eventConfigure(KstELOGConfigureEvent); eventConfigure.setData( &textStreamConfigure ); QApplication::sendEvent( (QObject*)_elog->app(), (QEvent*)&eventConfigure ); iAttachment++; addAttachment( _dataStreamAll, boundary, byteArrayConfigure, iAttachment, "Configure.kst" ); } if( _bIncludeDebugInfo ) { QByteArray byteArrayDebugInfo; QTextStream textStreamDebugInfo( byteArrayDebugInfo, IO_ReadWrite ); QCustomEvent eventDebugInfo(KstELOGDebugInfoEvent); eventDebugInfo.setData( &textStreamDebugInfo ); QApplication::sendEvent( (QObject*)_elog->app(), (QEvent*)&eventDebugInfo ); iAttachment++; addAttachment( _dataStreamAll, boundary, byteArrayDebugInfo, iAttachment, "DebugInfo.txt" ); } _job = KIO::http_post(destination, _byteArrayAll, false); if (_job) { _job->addMetaData("content-type", QString("multipart/form-data; boundary=%1").arg(boundary)); if (!_strWritePassword.isEmpty()) { QCString enc = KCodecs::base64Encode(_strWritePassword.ascii()); _job->addMetaData("cookies", "manual"); _job->addMetaData("setcookies", QString("Cookie: wpwd=%1").arg(enc.data())); } QObject::connect(_job, SIGNAL(result(KIO::Job*)), this, SLOT(result(KIO::Job*))); QObject::connect(_job, SIGNAL(dataReq(KIO::Job*, QByteArray&)), this, SLOT(dataReq(KIO::Job*, QByteArray&))); QObject::connect(_job, SIGNAL(data(KIO::Job*, const QByteArray&)), this, SLOT(data(KIO::Job*, const QByteArray&))); KIO::Scheduler::scheduleJob(_job); } else {
void ElogThreadSubmit::doTransmit(int sock) { KstELOGCaptureStruct captureStruct; QByteArray byteArrayCapture; QBuffer bufferCapture( byteArrayCapture ); QByteArray byteArrayConfigure; QTextStream textStreamConfigure( byteArrayConfigure, IO_ReadWrite ); QByteArray byteArrayDebugInfo; QTextStream textStreamDebugInfo( byteArrayDebugInfo, IO_ReadWrite ); QCustomEvent eventCapture(KstELOGCaptureEvent); QCustomEvent eventConfigure(KstELOGConfigureEvent); QCustomEvent eventDebugInfo(KstELOGDebugInfoEvent); QStringList::iterator it; QStringList strListAttributes; QStringList strListAttribute; QString strSplit( "\n" ); QString strSplitAttribute( "=" ); QString strUserName; QString strUserPassword; QString strWritePassword; QString strLogbook; QString strAttributes; QString strText; bool bIncludeCapture; bool bIncludeConfiguration; bool bIncludeDebugInfo; bool bSubmitAsHTML; bool bSuppressEmail; char* content; char request[100000]; char response[100000]; char boundary[80], str[80], *p; int i, n, header_length, content_length; int iAttachment = 0; bIncludeCapture = _elog->entry()->includeCapture(); bIncludeConfiguration = _elog->entry()->includeConfiguration(); bIncludeDebugInfo = _elog->entry()->includeDebugInfo(); content_length = 100000; if( bIncludeCapture ) { captureStruct.pBuffer = &bufferCapture; captureStruct.iWidth = _elog->configuration()->captureWidth(); captureStruct.iHeight = _elog->configuration()->captureHeight(); eventCapture.setData( &captureStruct ); QApplication::sendEvent( (QObject*)_elog->app()->viewObject(), (QEvent*)&eventCapture ); content_length += byteArrayCapture.size(); } if( bIncludeConfiguration ) { eventConfigure.setData( &textStreamConfigure ); QApplication::sendEvent( (QObject*)_elog->app(), (QEvent*)&eventConfigure ); content_length += byteArrayConfigure.size(); } if( bIncludeDebugInfo ) { eventDebugInfo.setData( &textStreamDebugInfo ); QApplication::sendEvent( (QObject*)_elog->app(), (QEvent*)&eventDebugInfo ); content_length += byteArrayDebugInfo.size(); } content = (char*)malloc(content_length); if (content != NULL) { strUserName = _elog->configuration()->userName(); strUserPassword = _elog->configuration()->userPassword(); strWritePassword = _elog->configuration()->writePassword(); strLogbook = _elog->configuration()->name(); bSubmitAsHTML = _elog->configuration()->submitAsHTML(); bSuppressEmail = _elog->configuration()->suppressEmail(); strAttributes = _elog->entry()->attributes(); strText = _elog->entry()->text(); srand((unsigned) time(NULL)); sprintf(boundary, "---------------------------%04X%04X%04X", rand(), rand(), rand()); strcpy(content, boundary); strcat(content, "\r\nContent-Disposition: form-data; name=\"cmd\"\r\n\r\nSubmit\r\n"); // // add the attributes... // addAttribute( content, boundary, "unm", strUserName, false ); addAttribute( content, boundary, "upwd", strUserPassword, true ); addAttribute( content, boundary, "exp", strLogbook, false ); strListAttributes = QStringList::split( strSplit, strAttributes, FALSE ); for ( it = strListAttributes.begin(); it != strListAttributes.end(); ++it ) { strListAttribute = QStringList::split( strSplitAttribute, *it, FALSE ); if( strListAttribute.count() == 2 ) { addAttribute( content, boundary, strListAttribute.first().stripWhiteSpace().ascii(), strListAttribute.last().stripWhiteSpace(), false ); } } if( bSubmitAsHTML ) { addAttribute( content, boundary, "html", "1", false ); } if( bSuppressEmail ) { addAttribute( content, boundary, "suppress", "1", false ); } addAttribute( content, boundary, "Text", strText, false ); sprintf( content + strlen(content), "%s\r\n", boundary ); content_length = strlen(content); p = content + content_length; // // add the attachments... // if( bIncludeCapture ) { iAttachment++; addAttachment( &content_length, &p, boundary, &byteArrayCapture, iAttachment, "Capture.png" ); } if( bIncludeConfiguration ) { iAttachment++; addAttachment( &content_length, &p, boundary, &byteArrayConfigure, iAttachment, "Configure.kst" ); } if( bIncludeDebugInfo ) { iAttachment++; addAttachment( &content_length, &p, boundary, &byteArrayDebugInfo, iAttachment, "DebugInfo.txt" ); } strcpy(request, "POST /"); if (!strLogbook.isEmpty()) { sprintf(request + strlen(request), "%s/", strLogbook.ascii()); } strcat(request, " HTTP/1.0\r\n"); sprintf(request + strlen(request), "Content-Type: multipart/form-data; boundary=%s\r\n", boundary); sprintf(request + strlen(request), "Host: %s\r\n", _host_name); sprintf(request + strlen(request), "User-Agent: ELOG\r\n"); sprintf(request + strlen(request), "Content-Length: %d\r\n", content_length); if (!strWritePassword.isEmpty()) { base64_encode(strWritePassword.ascii(), str); sprintf(request + strlen(request), "Cookie: wpwd=%s\r\n", str); } strcat(request, "\r\n"); header_length = strlen(request); send(sock, request, header_length, 0); send(sock, content, content_length, 0); // // handle the response... // i = recv(sock, response, 10000, 0); if (i >= 0) { n = i; while (i > 0) { i = recv(sock, response + n, 10000, 0); if (i > 0) { n += i; } } response[n] = 0; doResponseError(response); } else { doError( tr2i18n("ELOG entry: unable to receive response"), KstDebug::Notice ); } } }