summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/net/wellenreiter/gui/mainwindow.cpp127
1 files changed, 124 insertions, 3 deletions
diff --git a/noncore/net/wellenreiter/gui/mainwindow.cpp b/noncore/net/wellenreiter/gui/mainwindow.cpp
index ab7e0c7..88a474d 100644
--- a/noncore/net/wellenreiter/gui/mainwindow.cpp
+++ b/noncore/net/wellenreiter/gui/mainwindow.cpp
@@ -87,7 +87,8 @@ WellenreiterMainWindow::WellenreiterMainWindow( QWidget * parent, const char * n
87 uploadButton->setAutoRaise( true ); 87 uploadButton->setAutoRaise( true );
88 #endif 88 #endif
89 uploadButton->setIconSet( Resource::loadIconSet( "up" ) ); 89 uploadButton->setIconSet( Resource::loadIconSet( "up" ) );
90 uploadButton->setEnabled( false ); 90 //uploadButton->setEnabled( false );
91 uploadButton->setEnabled( true );
91 connect( uploadButton, SIGNAL( clicked() ), this, SLOT( uploadSession() ) ); 92 connect( uploadButton, SIGNAL( clicked() ), this, SLOT( uploadSession() ) );
92 93
93 // setup menu bar 94 // setup menu bar
@@ -366,10 +367,130 @@ void WellenreiterMainWindow::closeEvent( QCloseEvent* e )
366 } 367 }
367} 368}
368 369
370static const char* CAP_hostname = "www.vanille.de";
371
372#include <netdb.h>
373#include <unistd.h>
374#include <sys/types.h>
375#include <sys/socket.h>
369 376
370void WellenreiterMainWindow::uploadSession() 377void WellenreiterMainWindow::uploadSession()
371{ 378{
372 QMessageBox::warning( this, "Wellenreiter/Opie", 379 qDebug( "Starting upload..." );
373 tr( "This feature is\nunder construction... ;-)" ) ); 380
381 struct sockaddr_in raddr;
382 struct hostent *rhost_info;
383 int sock = -1;
384 bool ok = false;
385
386 rhost_info = (struct hostent *) ::gethostbyname( CAP_hostname );
387 if ( rhost_info )
388 {
389 if ( !QFile::exists( "/var/log/dump.wellenreiter" ) )
390 {
391 qDebug( "no file to upload!" );
392 return;
393 }
394
395 QFile f( "/var/log/dump.wellenreiter" );
396 if ( !f.open( IO_ReadOnly ) )
397 {
398 qDebug( "can't open file!" );
399 return;
400 }
401
402 int content_length = f.size();
403
404 ::memset( &raddr, 0, sizeof (struct sockaddr_in) );
405 ::memcpy( &raddr. sin_addr, rhost_info-> h_addr, rhost_info-> h_length );
406 raddr.sin_family = rhost_info-> h_addrtype;
407 raddr.sin_port = htons ( 80 );
408
409 sock = ::socket( AF_INET, SOCK_STREAM, 0 );
410
411 if ( sock >= 0 )
412 {
413 if ( ::connect ( sock, (struct sockaddr *) & raddr, sizeof (struct sockaddr)) >= 0 )
414 {
415 QString header;
416 QString content;
417 QString preambel;
418
419 header = ""
420 "POST /projects/capturedump.spy HTTP/1.1\r\n"
421 "Host: www.vanille.de\r\n"
422 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.5) Gecko/20031010 Galeon/1.3.10\r\n"
423 "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,image/jpeg,image/gif;q=0.2,*/*;q=0.1\r\n"
424 "Accept-Language: en\r\n"
425 "Accept-Encoding: gzip, deflate, compress;q=0.9\r\n"
426 "Accept-Charset: us-ascii,utf-8;q=0.7,*;q=0.7\r\n"
427 "Keep-Alive: 300\r\n"
428 "Connection: keep-alive\r\n"
429 "Referer: http://www.vanille.de/projects/capturedump.spy\r\n"
430 "Content-Type: multipart/form-data; boundary=---------------------------97267758015830030481215568065\r\n"
431 "Content-Length: %1\r\n"
432 "\r\n";
433
434 content = ""
435 "-----------------------------97267758015830030481215568065\r\n"
436 "Content-Disposition: form-data; name=\"Name\"\r\n"
437 "\r\n"
438 "Anonymous Wellenreiter II User\r\n"
439 "-----------------------------97267758015830030481215568065\r\n"
440 "Content-Disposition: form-data; name=\"Location\"\r\n"
441 "\r\n"
442 "Anonymous Wellenreiter II Location\r\n"
443 "-----------------------------97267758015830030481215568065\r\n"
444 "Content-Disposition: form-data; name=\"Comments\"\r\n"
445 "\r\n"
446 "Anonymous Wellenreiter II Comments\r\n"
447 "-----------------------------97267758015830030481215568065\r\n"
448 "Content-Disposition: form-data; name=\"upfile\"; filename=\"/var/log/dump.wellenreiter\"\r\n"
449 "Content-Type: application/octet-stream\r\n"
450 "\r\n";
451
452 preambel = ""
453 "\r\n-----------------------------97267758015830030481215568065--\r\n";
454
455 header = header.arg( QString::number( content.length() + f.size() + preambel.length() ) );
456
457 // write header
458
459 const char* ascii = header.latin1();
460 uint ascii_len = ::strlen( ascii );
461 ::write ( sock, ascii, ascii_len );
462
463 // write fixed content
464
465 ascii = content.latin1();
466 ascii_len = ::strlen( ascii );
467 ::write ( sock, ascii, ascii_len );
468
469 // write variable content
470
471 char ch;
472 while ( !f.atEnd() )
473 {
474 f.readBlock( &ch, 1 );
475 ::write ( sock, &ch, 1 );
476 }
477
478 // write preambel
479
480 ascii = preambel.latin1();
481 ascii_len = ::strlen( ascii );
482 ::write ( sock, ascii, ascii_len );
483
484 // done!
485
486 ok = true;
487 }
488 }
489 ::close ( sock );
490 }
491 if ( ok )
492 QMessageBox::information ( 0, tr( "Success" ), QString ( "<p>%1</p>" ). arg( tr( "Capture Dump was uploaded to %1" )).arg ( CAP_hostname ));
493 else
494 QMessageBox::warning ( 0, tr( "Error" ), QString ( "<p>%1</p>" ). arg ( tr( "Connection to %1 failed." )). arg ( CAP_hostname ));
374} 495}
375 496