From kde-commits Sat Aug 28 07:21:33 2004 From: =?utf-8?q?Mathias=20Fr=C3=B6hlich?= Date: Sat, 28 Aug 2004 07:21:33 +0000 To: kde-commits Subject: kdeextragear-3/kdebluetooth/libqobex/qobexclient [POSSIBLY UNSAFE] Message-Id: <20040828072133.AA2372158 () office ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=109367769918361 CVS commit by froehlich: Add commandline switch and implementation to dump the raw obex packets into a file. A client.cpp 1.1 [POSSIBLY UNSAFE: printf] [LGPL (v2+)] A client.h 1.1 [LGPL (v2+)] M +2 -2 Makefile.am 1.4 M +13 -50 qobexclient.cpp 1.6 [POSSIBLY UNSAFE: printf] --- kdeextragear-3/kdebluetooth/libqobex/qobexclient/Makefile.am #1.3:1.4 @@ -2,5 +2,5 @@ # This file is part of libqobex. # -# Copyright (c) 2003 Mathias Froehlich +# Copyright (c) 2003-2004 Mathias Froehlich # # This library is free software; you can redistribute it and/or @@ -24,5 +24,5 @@ bin_PROGRAMS = qobexclient -qobexclient_SOURCES = qobexclient.cpp +qobexclient_SOURCES = qobexclient.cpp client.cpp qobexclient_LDADD = ../qobex/libqobex.la $(LIB_QT) --- kdeextragear-3/kdebluetooth/libqobex/qobexclient/qobexclient.cpp #1.5:1.6 @@ -43,7 +43,8 @@ #include #endif -#include #include +#include "client.h" + #define ARGV0 "qobexclient" @@ -55,5 +56,5 @@ void print_usage() fprintf( stderr, " usage:\n" ); fprintf( stderr, "\n" ); - fprintf( stderr, " " ARGV0 " [-ghlnpv] [-d dest] [-f localfile] [-m mimetype]\n" ); + fprintf( stderr, " " ARGV0 " [-ghlnpv] [-d dest] [-D dumpfile] [-f localfile] [-m mimetype]\n" ); fprintf( stderr, " [-s speed] [-t transport] [-u uuid]\n" ); fprintf( stderr, "\n" ); @@ -81,4 +82,7 @@ void print_usage() fprintf( stderr, " which offers the required service.\n" ); fprintf( stderr, "\n" ); + fprintf( stderr, " -D dumpfile\n" ); + fprintf( stderr, " Dump raw obex packets into dumpfile.\n" ); + fprintf( stderr, "\n" ); fprintf( stderr, " -f localfile\n" ); fprintf( stderr, " The local filename to use. Defaults to stdout/stdin.\n" ); @@ -148,50 +152,4 @@ void print_usage() } -class client - : public QObexClient { -public: - client( QObexTransport * transport, QFile * f, bool verbose ) - : QObexClient( transport ), mFile( f ), mVerbose( verbose ) {} - - void response( const QObexObject& resp ) { - if ( mVerbose ) { - fprintf( stderr, "Got Response Packet\n %s\n", - (const char *)QFile::encodeName( resp.stringCode() ) ); - QValueList hdrs = resp.getHeaders(); - QValueList::Iterator it; - for ( it = hdrs.begin(); it != hdrs.end(); ++it ) - fprintf( stderr, " %s\n", - (const char *)QFile::encodeName( (*it).stringHeaderId() ) ); - } - } - bool dataReq( QByteArray& data, size_t max ) { - data.resize( max ); - int ret = mFile->readBlock( data.data(), max ); - data.resize( ret ); - return 0 <= ret; - } - bool data( const QValueList& data ) { - if ( !data.isEmpty() ) { - QValueList::ConstIterator it; - for ( it = data.begin(); it != data.end(); ++it ) { - if ( 0 < (*it).size() ) { - if ( 0 > mFile->writeBlock( (*it).data(), (*it).size() ) ) - return false; - } - } - } - return true; - } - void authenticationRequired( const QString& realm ) { - if ( mVerbose ) { - fprintf( stderr, "Got Authentication Required with realm \"%s\"\n", - (const char *)QFile::encodeName( realm ) ); - } - } -private: - QFile* mFile; - bool mVerbose; -}; - extern char *optarg; extern int optind; @@ -212,4 +170,5 @@ int main( int argc, char **argv ) QFile file; + QFile dumpFile; QString mimetype; @@ -231,5 +190,5 @@ int main( int argc, char **argv ) int c; - while ((c = getopt( argc, argv, "a:cd:f:ghilm:nopr:s:t:u:v" )) != EOF) + while ((c = getopt( argc, argv, "a:cd:D:f:ghilm:nopr:s:t:u:v" )) != EOF) switch ( c ) { case 'a': @@ -242,4 +201,8 @@ int main( int argc, char **argv ) dest = QFile::decodeName( optarg ); break; + case 'D': + dumpFile.setName( QFile::decodeName( optarg ) ); + dumpFile.open( IO_WriteOnly ); + break; case 'f': { @@ -449,5 +412,5 @@ int main( int argc, char **argv ) } - client obex( transport, &file, verbose ); + client obex( transport, &file, &dumpFile, verbose ); obex.setOpenObexSupport( openobex ); switch ( uuid ) {