summaryrefslogtreecommitdiff
path: root/noncore/comm/keypebble/krfblogin.cpp
Unidiff
Diffstat (limited to 'noncore/comm/keypebble/krfblogin.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/comm/keypebble/krfblogin.cpp41
1 files changed, 23 insertions, 18 deletions
diff --git a/noncore/comm/keypebble/krfblogin.cpp b/noncore/comm/keypebble/krfblogin.cpp
index 2bbd110..92005d2 100644
--- a/noncore/comm/keypebble/krfblogin.cpp
+++ b/noncore/comm/keypebble/krfblogin.cpp
@@ -1,17 +1,22 @@
1#include <assert.h> 1#include "krfblogin.h"
2#include "krfbconnection.h"
2 3
4/* OPIE */
5#include <opie2/odebug.h>
6using namespace Opie::Core;
7
8/* QT */
9#include <qtimer.h>
3 10
11/* STD */
12#include <assert.h>
4extern "C" { 13extern "C" {
5#include "vncauth.h" 14#include "vncauth.h"
6} 15}
7 16
8#include "krfblogin.h"
9#include "krfbconnection.h"
10#include <qtimer.h>
11
12// The length of the various messages (used to decide how many bytes to 17// The length of the various messages (used to decide how many bytes to
13// wait for). 18// wait for).
14const int ServerVersionLength = 12; 19const int ServerVersionLength = 12;
15const int ClientVersionLength = 12; 20const int ClientVersionLength = 12;
16const int AuthSchemeLength = 4; 21const int AuthSchemeLength = 4;
17const int FailureReasonSizeLength = 4; 22const int FailureReasonSizeLength = 4;
@@ -49,13 +54,13 @@ KRFBLogin::KRFBLogin( KRFBConnection *con )
49 currentState = AwaitingServerVersion; 54 currentState = AwaitingServerVersion;
50 55
51 connect( this, SIGNAL( error(const QString&) ), 56 connect( this, SIGNAL( error(const QString&) ),
52 con, SIGNAL( error(const QString&) ) ); 57 con, SIGNAL( error(const QString&) ) );
53 58
54 59
55 qWarning( "Waiting for server version..." ); 60 owarn << "Waiting for server version..." << oendl;
56 61
57 static QString statusMsg = tr( "Waiting for server version..." ); 62 static QString statusMsg = tr( "Waiting for server version..." );
58 emit status( statusMsg ); 63 emit status( statusMsg );
59 64
60 // Kick off the state machine 65 // Kick off the state machine
61 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerVersion() ) ); 66 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerVersion() ) );
@@ -71,13 +76,13 @@ KRFBLogin::State KRFBLogin::state() const
71{ 76{
72 return currentState; 77 return currentState;
73} 78}
74 79
75void KRFBLogin::gotServerVersion() 80void KRFBLogin::gotServerVersion()
76{ 81{
77 qWarning( "Got server version" ); 82 owarn << "Got server version" << oendl;
78 83
79 disconnect( con, SIGNAL( gotEnoughData() ), 84 disconnect( con, SIGNAL( gotEnoughData() ),
80 this, SLOT( gotServerVersion() ) ); 85 this, SLOT( gotServerVersion() ) );
81 86
82 // Read the server's version message 87 // Read the server's version message
83 char serverVersion[ ServerVersionLength + 1 ]; 88 char serverVersion[ ServerVersionLength + 1 ];
@@ -89,13 +94,13 @@ void KRFBLogin::gotServerVersion()
89 94
90 QRegExp regexp( "RFB [0-9][0-9][0-9]\\.[0-9][0-9][0-9]\n" ); 95 QRegExp regexp( "RFB [0-9][0-9][0-9]\\.[0-9][0-9][0-9]\n" );
91 96
92 if ( rfbString.find( regexp ) == -1 ) { 97 if ( rfbString.find( regexp ) == -1 ) {
93 static QString msg = tr( "Error: Invalid server version, %1" ).arg( rfbString ); 98 static QString msg = tr( "Error: Invalid server version, %1" ).arg( rfbString );
94 99
95 qWarning( msg ); 100 owarn << msg << oendl;
96 emit error( msg ); 101 emit error( msg );
97 currentState = Error; 102 currentState = Error;
98 return; 103 return;
99 } 104 }
100 105
101 // Calculate the actual version number 106 // Calculate the actual version number
@@ -103,26 +108,26 @@ void KRFBLogin::gotServerVersion()
103 + (serverVersion[5] - '0') * 10 108 + (serverVersion[5] - '0') * 10
104 + (serverVersion[6] - '0'); 109 + (serverVersion[6] - '0');
105 serverMinor = (serverVersion[8] - '0') * 100 110 serverMinor = (serverVersion[8] - '0') * 100
106 + (serverVersion[9] - '0') * 10 111 + (serverVersion[9] - '0') * 10
107 + (serverVersion[10] - '0'); 112 + (serverVersion[10] - '0');
108 113
109 qWarning("Server Version: %03d.%03d", serverMajor, serverMinor ); 114 owarn << "Server Version: " << serverMajor << "." << serverMinor << "" << oendl;
110 115
111 if ( serverMajor != 3 ) { 116 if ( serverMajor != 3 ) {
112 QString msg = tr( "Error: Unsupported server version, %1" ) 117 QString msg = tr( "Error: Unsupported server version, %1" )
113 .arg( rfbString ); 118 .arg( rfbString );
114 119
115 qWarning( msg ); 120 owarn << msg << oendl;
116 emit error( msg ); 121 emit error( msg );
117 currentState = Error; 122 currentState = Error;
118 return; 123 return;
119 } 124 }
120 125
121 if ( serverMinor != 3 ) { 126 if ( serverMinor != 3 ) {
122 qWarning( "Minor version mismatch: %d", serverMinor ); 127 owarn << "Minor version mismatch: " << serverMinor << "" << oendl;
123 } 128 }
124 129
125 // Setup for the next state 130 // Setup for the next state
126 sendClientVersion(); 131 sendClientVersion();
127 132
128 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotAuthScheme() ) ); 133 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotAuthScheme() ) );
@@ -140,13 +145,13 @@ void KRFBLogin::gotAuthScheme()
140 scheme = Swap32IfLE( scheme ); 145 scheme = Swap32IfLE( scheme );
141 146
142 static QString statusMsgOk = tr( "Logged in" ); 147 static QString statusMsgOk = tr( "Logged in" );
143 148
144 switch ( scheme ) { 149 switch ( scheme ) {
145 case 0: 150 case 0:
146 qWarning( "Failed" ); 151 owarn << "Failed" << oendl;
147 // Handle failure 152 // Handle failure
148 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotFailureReasonSize() ) ); 153 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotFailureReasonSize() ) );
149 con->waitForData( FailureReasonSizeLength ); 154 con->waitForData( FailureReasonSizeLength );
150 break; 155 break;
151 case 1: 156 case 1:
152 // Handle no auth 157 // Handle no auth
@@ -156,13 +161,13 @@ void KRFBLogin::gotAuthScheme()
156 case 2: 161 case 2:
157 // Handle VNC auth 162 // Handle VNC auth
158 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotChallenge() ) ); 163 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotChallenge() ) );
159 con->waitForData( ChallengeLength ); 164 con->waitForData( ChallengeLength );
160 break; 165 break;
161 default: 166 default:
162 qWarning( "Unknown authentication scheme, 0x%08lx", scheme ); 167 owarn << "Unknown authentication scheme, 0x" << scheme << "" << oendl;
163 currentState = Error; 168 currentState = Error;
164 break; 169 break;
165 }; 170 };
166} 171}
167 172
168void KRFBLogin::gotChallenge() 173void KRFBLogin::gotChallenge()
@@ -178,13 +183,13 @@ void KRFBLogin::getPassword()
178 // Got data 183 // Got data
179 CARD8 challenge[ ChallengeLength ]; 184 CARD8 challenge[ ChallengeLength ];
180 con->read( challenge, ChallengeLength ); 185 con->read( challenge, ChallengeLength );
181 186
182 // Last chance to enter a password 187 // Last chance to enter a password
183 if ( con->options_->password.isNull() ) { 188 if ( con->options_->password.isNull() ) {
184 qWarning( "krfblogin needs a password" ); 189 owarn << "krfblogin needs a password" << oendl;
185 emit passwordRequired( con ); 190 emit passwordRequired( con );
186 } 191 }
187 192
188 if ( con->options_->password.isNull() ) { 193 if ( con->options_->password.isNull() ) {
189 QString msg = tr( "Error: This server requires a password, but none " 194 QString msg = tr( "Error: This server requires a password, but none "
190 "has been specified.\n" ); 195 "has been specified.\n" );
@@ -213,13 +218,13 @@ void KRFBLogin::gotAuthResult()
213 SLOT( gotAuthResult() ) ); 218 SLOT( gotAuthResult() ) );
214 219
215 long result; 220 long result;
216 con->read( &result, AuthResultLength ); 221 con->read( &result, AuthResultLength );
217 result = Swap32IfLE( result ); 222 result = Swap32IfLE( result );
218 223
219 qWarning( "Authentication Result is 0x%08lx", result ); 224 owarn << "Authentication Result is 0x" << result << "" << oendl;
220 225
221 static QString failed = tr( "Error: The password you specified was incorrect." ); 226 static QString failed = tr( "Error: The password you specified was incorrect." );
222 static QString tooMany = tr( "Error: Too many invalid login attempts have been made\n" 227 static QString tooMany = tr( "Error: Too many invalid login attempts have been made\n"
223 "to this account, please try later." ); 228 "to this account, please try later." );
224 229
225 static QString statusMsgOk = tr( "Logged in" ); 230 static QString statusMsgOk = tr( "Logged in" );
@@ -229,25 +234,25 @@ void KRFBLogin::gotAuthResult()
229 switch( result ) { 234 switch( result ) {
230 case AuthOk: 235 case AuthOk:
231 emit status( statusMsgOk ); 236 emit status( statusMsgOk );
232 con->gotRFBConnection(); 237 con->gotRFBConnection();
233 break; 238 break;
234 case AuthFailed: 239 case AuthFailed:
235 qWarning( "Dammit" ); 240 owarn << "Dammit" << oendl;
236 emit status( statusMsgFailed ); 241 emit status( statusMsgFailed );
237 emit error( failed ); 242 emit error( failed );
238 break; 243 break;
239 case AuthTooMany: 244 case AuthTooMany:
240 emit status( statusMsgTooMany ); 245 emit status( statusMsgTooMany );
241 emit error( tooMany ); 246 emit error( tooMany );
242 break; 247 break;
243 default: 248 default:
244 qWarning( "Invalid authentication result, %lx", result ); 249 owarn << "Invalid authentication result, " << result << "" << oendl;
245 break; 250 break;
246 } 251 }
247} 252}
248 253
249void KRFBLogin::sendClientVersion() 254void KRFBLogin::sendClientVersion()
250{ 255{
251 qWarning( "Sending client version" ); 256 owarn << "Sending client version" << oendl;
252 con->write( (void*)"RFB 003.003\n", ClientVersionLength ); 257 con->write( (void*)"RFB 003.003\n", ClientVersionLength );
253} 258}