~ubuntu-branches/ubuntu/intrepid/kdebluetooth/intrepid-proposed

« back to all changes in this revision

Viewing changes to kdebluetooth/libqobex/qobex/qobexserverops.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Mercatante
  • Date: 2008-08-07 09:49:47 UTC
  • mto: This revision was merged to the branch mainline in revision 56.
  • Revision ID: james.westby@ubuntu.com-20080807094947-pj6q3uxwuv7l844q
Tags: upstream-0.1
ImportĀ upstreamĀ versionĀ 0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
    This file is part of libqobex.
3
 
 
4
 
    Copyright (c) 2003 Mathias Froehlich <Mathias.Froehlich@web.de>
5
 
 
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.
10
 
 
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.
15
 
 
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.
20
 
*/
21
 
 
22
 
#include <qstring.h>
23
 
#include <qregexp.h>
24
 
#include <qcstring.h>
25
 
#include <qdir.h>
26
 
 
27
 
#include "qobexobject.h"
28
 
#include "qobexserverops.h"
29
 
#include "qobexauth.h"
30
 
 
31
 
#undef DEBUG
32
 
// #define DEBUG
33
 
#ifdef DEBUG
34
 
#define myDebug(a) qDebug a
35
 
#else
36
 
#define myDebug(a) (void)0
37
 
#endif
38
 
 
39
 
QObexServerOps::QObexServerOps() {
40
 
  myDebug(( "QObexServerOps::QObexServerOps()" ));
41
 
  mUseConnectionId = false;
42
 
  mStreamingStatus = NoStreaming;
43
 
  mConnected = false;
44
 
  mAuthStatus = UnAuthenticated;
45
 
  mClientIsReadOnly = false;
46
 
}
47
 
 
48
 
QObexServerOps::~QObexServerOps() {
49
 
  myDebug(( "QObexServerOps::~QObexServerOps()" ));
50
 
}
51
 
 
52
 
void QObexServerOps::connect( const QObexObject&, QObexObject& resp ) {
53
 
  myDebug(( "QObexServerOps::connect( ... )" ));
54
 
  resp.setCode( QObexObject::NotImplemented );
55
 
}
56
 
 
57
 
void QObexServerOps::disconnect( const QObexObject& ) {
58
 
  myDebug(( "QObexServerOps::disconnect( ... )" ));
59
 
}
60
 
 
61
 
void QObexServerOps::get( const QObexObject&, QObexObject& resp ) {
62
 
  myDebug(( "QObexServerOps::get( ... )" ));
63
 
  resp.setCode( QObexObject::NotImplemented );
64
 
}
65
 
 
66
 
void QObexServerOps::del( const QObexObject&, QObexObject& resp ) {
67
 
  myDebug(( "QObexServerOps::del( ... )" ));
68
 
  resp.setCode( QObexObject::NotImplemented );
69
 
}
70
 
 
71
 
void QObexServerOps::put( const QObexObject&, QObexObject& resp ) {
72
 
  myDebug(( "QObexServerOps::put( ... )" ));
73
 
  resp.setCode( QObexObject::NotImplemented );
74
 
}
75
 
 
76
 
void QObexServerOps::setPath( const QObexObject&, QObexObject& resp ) {
77
 
  myDebug(( "QObexServerOps::setPath( ... )" ));
78
 
  resp.setCode( QObexObject::NotImplemented );
79
 
}
80
 
 
81
 
void QObexServerOps::abort( const QObexObject& ) {
82
 
  myDebug(( "QObexServerOps::abort( ... )" ));
83
 
}
84
 
 
85
 
void QObexServerOps::streamingError() {
86
 
  myDebug(( "QObexServerOps::streamingError()" ));
87
 
}
88
 
 
89
 
bool QObexServerOps::dataReq( QByteArray&, Q_LONG ) {
90
 
  myDebug(( "QObexServerOps::dataReq( ... )" ));
91
 
  return true;
92
 
}
93
 
 
94
 
bool QObexServerOps::data( const QValueList<QByteArray>& ) {
95
 
  myDebug(( "QObexServerOps::data( ... )" ));
96
 
  return true;
97
 
}
98
 
 
99
 
QObexAuthDigestChallenge::AuthInfo QObexServerOps::serverAuthInfo() {
100
 
  myDebug(( "QObexServerOps::serverAuthInfo( ... )" ));
101
 
  return QObexAuthDigestChallenge::AuthInfo();
102
 
}
103
 
 
104
 
QByteArray QObexServerOps::serverSecret( const QString& ) {
105
 
  myDebug(( "QObexServerOps::serverSecret( ... )" ));
106
 
  return QByteArray();
107
 
}
108
 
 
109
 
QObexAuthDigestResponse::AuthInfo QObexServerOps::clientAuthInfo( const QString&, bool ) {
110
 
  myDebug(( "QObexServerOps::authenticationRequired( ... )" ));
111
 
  return QObexAuthDigestResponse::AuthInfo();
112
 
}
113
 
 
114
 
QString QObexServerOps::getCwd() const {
115
 
  myDebug(( "QObexServerOps::getCwd()" ));
116
 
  return mCwd;
117
 
}
118
 
 
119
 
bool QObexServerOps::isRootDir() const {
120
 
  myDebug(( "QObexServerOps::isRootDir()" ));
121
 
  return mCwd.isEmpty() || mCwd == ".";
122
 
}
123
 
 
124
 
bool QObexServerOps::oneDirectoryUp() {
125
 
  myDebug(( "QObexServerOps::oneDirectoryUp(): enter %s", mCwd.latin1() ));
126
 
  if ( isRootDir() )
127
 
    return false;
128
 
 
129
 
  mCwd = QDir::cleanDirPath ( "./" + mCwd + "/.." );
130
 
  myDebug(( "QObexServerOps::oneDirectoryUp(): exit %s", mCwd.latin1()));
131
 
  return true;
132
 
}
133
 
 
134
 
bool QObexServerOps::enterDirectory( const QString& dir, bool backup ) {
135
 
  myDebug(( "QObexServerOps::enterDirectory( %s ): enter %s", dir.latin1(), mCwd.latin1() ));
136
 
  if ( backup && isRootDir() )
137
 
    return false;
138
 
 
139
 
  mCwd = QDir::cleanDirPath( "./" + mCwd + ( backup ? "/../" : "/" ) + dir );
140
 
  myDebug(( "QObexServerOps::enterDirectory( %s ): exit %s", dir.latin1(), mCwd.latin1() ));
141
 
  return true;
142
 
}
143
 
 
144
 
void QObexServerOps::enterRootDirectory() {
145
 
  myDebug(( "QObexServerOps::enterRootDirectory()" ));
146
 
  mCwd = QString::null;
147
 
}
148
 
 
149
 
QString QObexServerOps::composePath( const QString& tail, bool backup ) {
150
 
  myDebug(( "QObexServerOps::composePath( ... )" ));
151
 
  return QDir::cleanDirPath ( "./" + mCwd + ( backup ? "/../" : "/" ) + tail );
152
 
}
153
 
 
154
 
bool QObexServerOps::isDirected() const {
155
 
  myDebug(( "QObexServerOps::isDirected()" ));
156
 
  return mUseConnectionId;
157
 
}
158
 
 
159
 
QByteArray QObexServerOps::getUuid() const {
160
 
  myDebug(( "QObexServerOps::getUuid()" ));
161
 
  return mUuid;
162
 
}
163
 
 
164
 
Q_UINT32 QObexServerOps::getConnectionId() const {
165
 
  myDebug(( "QObexServerOps::getConnectionId()" ));
166
 
  return mConnectionId;
167
 
}
168
 
 
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();
175
 
      return true;
176
 
    }
177
 
  }
178
 
  else {
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();
183
 
        return true;
184
 
      }
185
 
    }
186
 
  }
187
 
  return false;
188
 
}
189
 
 
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 )
195
 
      return true;
196
 
  }
197
 
  return false;
198
 
}