2
This file is part of libqobex.
4
Copyright (c) 2003 Mathias Froehlich <Mathias.Froehlich@web.de>
6
This library is free software; you can redistribute it and/or
7
modify it under the terms of the GNU Library General Public
8
License as published by the Free Software Foundation; either
9
version 2 of the License, or (at your option) any later version.
11
This library is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
Library General Public License for more details.
16
You should have received a copy of the GNU Library General Public License
17
along with this library; see the file COPYING.LIB. If not, write to
18
the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
19
Boston, MA 02110-1301, USA.
27
#include "qobexobject.h"
28
#include "qobexserverops.h"
29
#include "qobexauth.h"
34
#define myDebug(a) qDebug a
36
#define myDebug(a) (void)0
39
QObexServerOps::QObexServerOps() {
40
myDebug(( "QObexServerOps::QObexServerOps()" ));
41
mUseConnectionId = false;
42
mStreamingStatus = NoStreaming;
44
mAuthStatus = UnAuthenticated;
45
mClientIsReadOnly = false;
48
QObexServerOps::~QObexServerOps() {
49
myDebug(( "QObexServerOps::~QObexServerOps()" ));
52
void QObexServerOps::connect( const QObexObject&, QObexObject& resp ) {
53
myDebug(( "QObexServerOps::connect( ... )" ));
54
resp.setCode( QObexObject::NotImplemented );
57
void QObexServerOps::disconnect( const QObexObject& ) {
58
myDebug(( "QObexServerOps::disconnect( ... )" ));
61
void QObexServerOps::get( const QObexObject&, QObexObject& resp ) {
62
myDebug(( "QObexServerOps::get( ... )" ));
63
resp.setCode( QObexObject::NotImplemented );
66
void QObexServerOps::del( const QObexObject&, QObexObject& resp ) {
67
myDebug(( "QObexServerOps::del( ... )" ));
68
resp.setCode( QObexObject::NotImplemented );
71
void QObexServerOps::put( const QObexObject&, QObexObject& resp ) {
72
myDebug(( "QObexServerOps::put( ... )" ));
73
resp.setCode( QObexObject::NotImplemented );
76
void QObexServerOps::setPath( const QObexObject&, QObexObject& resp ) {
77
myDebug(( "QObexServerOps::setPath( ... )" ));
78
resp.setCode( QObexObject::NotImplemented );
81
void QObexServerOps::abort( const QObexObject& ) {
82
myDebug(( "QObexServerOps::abort( ... )" ));
85
void QObexServerOps::streamingError() {
86
myDebug(( "QObexServerOps::streamingError()" ));
89
bool QObexServerOps::dataReq( QByteArray&, Q_LONG ) {
90
myDebug(( "QObexServerOps::dataReq( ... )" ));
94
bool QObexServerOps::data( const QValueList<QByteArray>& ) {
95
myDebug(( "QObexServerOps::data( ... )" ));
99
QObexAuthDigestChallenge::AuthInfo QObexServerOps::serverAuthInfo() {
100
myDebug(( "QObexServerOps::serverAuthInfo( ... )" ));
101
return QObexAuthDigestChallenge::AuthInfo();
104
QByteArray QObexServerOps::serverSecret( const QString& ) {
105
myDebug(( "QObexServerOps::serverSecret( ... )" ));
109
QObexAuthDigestResponse::AuthInfo QObexServerOps::clientAuthInfo( const QString&, bool ) {
110
myDebug(( "QObexServerOps::authenticationRequired( ... )" ));
111
return QObexAuthDigestResponse::AuthInfo();
114
QString QObexServerOps::getCwd() const {
115
myDebug(( "QObexServerOps::getCwd()" ));
119
bool QObexServerOps::isRootDir() const {
120
myDebug(( "QObexServerOps::isRootDir()" ));
121
return mCwd.isEmpty() || mCwd == ".";
124
bool QObexServerOps::oneDirectoryUp() {
125
myDebug(( "QObexServerOps::oneDirectoryUp(): enter %s", mCwd.latin1() ));
129
mCwd = QDir::cleanDirPath ( "./" + mCwd + "/.." );
130
myDebug(( "QObexServerOps::oneDirectoryUp(): exit %s", mCwd.latin1()));
134
bool QObexServerOps::enterDirectory( const QString& dir, bool backup ) {
135
myDebug(( "QObexServerOps::enterDirectory( %s ): enter %s", dir.latin1(), mCwd.latin1() ));
136
if ( backup && isRootDir() )
139
mCwd = QDir::cleanDirPath( "./" + mCwd + ( backup ? "/../" : "/" ) + dir );
140
myDebug(( "QObexServerOps::enterDirectory( %s ): exit %s", dir.latin1(), mCwd.latin1() ));
144
void QObexServerOps::enterRootDirectory() {
145
myDebug(( "QObexServerOps::enterRootDirectory()" ));
146
mCwd = QString::null;
149
QString QObexServerOps::composePath( const QString& tail, bool backup ) {
150
myDebug(( "QObexServerOps::composePath( ... )" ));
151
return QDir::cleanDirPath ( "./" + mCwd + ( backup ? "/../" : "/" ) + tail );
154
bool QObexServerOps::isDirected() const {
155
myDebug(( "QObexServerOps::isDirected()" ));
156
return mUseConnectionId;
159
QByteArray QObexServerOps::getUuid() const {
160
myDebug(( "QObexServerOps::getUuid()" ));
164
Q_UINT32 QObexServerOps::getConnectionId() const {
165
myDebug(( "QObexServerOps::getConnectionId()" ));
166
return mConnectionId;
169
bool QObexServerOps::authResponseOk( const QObexAuthDigestResponse& auth ) {
170
myDebug(( "QObexServerOps::authResponseOk( ... )" ));
171
if ( auth.hasNonce() ) {
172
QByteArray nonce = auth.nonce();
173
if ( havePendingAuthForNonce( nonce ) && auth.authenticate( serverSecret( auth.userId() ), nonce ) ) {
174
mPendingAuth.clear();
179
QValueList<QObexAuthDigestChallenge>::Iterator it;
180
for ( it = mPendingAuth.begin(); it != mPendingAuth.end(); ++it ) {
181
if ( auth.authenticate( serverSecret( auth.userId() ), (*it).nonce() ) ) {
182
mPendingAuth.clear();
190
bool QObexServerOps::havePendingAuthForNonce( const QByteArray& nonce ) const {
191
myDebug(( "QObexServerOps::havePendingAuthForNonce( ... )" ));
192
QValueList<QObexAuthDigestChallenge>::ConstIterator it;
193
for ( it = mPendingAuth.begin(); it != mPendingAuth.end(); ++it ) {
194
if ( (*it).nonce() == nonce )