25
25
#include " qgshttptransaction.h"
26
26
27
27
#include < qapplication.h>
28
- #include < q3url.h >
28
+ #include < QUrl >
29
29
30
30
#include < QTimer>
31
31
32
32
static int NETWORK_TIMEOUT_MSEC = (120 * 1000 ); // 120 seconds
33
+ static int HTTP_PORT_DEFAULT = 80 ;
33
34
34
- QgsHttpTransaction::QgsHttpTransaction (QString uri, QString proxyHost, Q_UINT16 proxyPort)
35
+ QgsHttpTransaction::QgsHttpTransaction (QString uri,
36
+ QString proxyHost,
37
+ int proxyPort,
38
+ QString proxyUser,
39
+ QString proxyPass)
35
40
: httpurl(uri),
36
41
httphost(proxyHost),
37
42
httpport(proxyPort),
43
+ httpuser(proxyUser),
44
+ httppass(proxyPass),
38
45
httpresponsecontenttype(0 ),
39
46
mError(0 )
40
47
{
@@ -77,40 +84,42 @@ bool QgsHttpTransaction::getSynchronously(QByteArray &respondedContent, int redi
77
84
std::cout << " QgsHttpTransaction::getSynchronously: Using '" << httpurl.toLocal8Bit ().data () << " '." << std::endl;
78
85
#endif
79
86
80
- Q3Url qurl (httpurl);
81
- QString path;
82
-
87
+ QUrl qurl (httpurl);
88
+
89
+ http = new QHttp ( qurl.host (), qurl.port (HTTP_PORT_DEFAULT) );
90
+
83
91
if (httphost.isEmpty ())
84
92
{
85
93
// No proxy was specified - connect directly to host in URI
86
94
httphost = qurl.host ();
87
- path = qurl.encodedPathAndQuery ();
88
- }
95
+ httpport = qurl.port (HTTP_PORT_DEFAULT);
96
+
97
+ }
89
98
else
90
99
{
91
- // Proxy -> send complete URL
92
- path = httpurl ;
100
+ // Insert proxy username and password authentication
101
+ http-> setProxy ( httphost, httpport, httpuser, httppass ) ;
93
102
}
94
- http = new Q3Http ( httphost, httpport );
103
+
104
+ // int httpid1 = http->setHost( qurl.host(), qurl.port() );
105
+
95
106
mWatchdogTimer = new QTimer ( this );
96
107
97
108
#ifdef QGISDEBUG
98
109
qWarning (" QgsHttpTransaction::getSynchronously: qurl.host() is '" +qurl.host ()+ " '." );
99
- qWarning (" QgsHttpTransaction::getSynchronously: qurl.encodedPathAndQuery() is '" +qurl.encodedPathAndQuery ()+" '." );
100
- std::cout << " path = " << path.ascii () << std::endl;
101
110
#endif
102
111
103
112
httpresponse.truncate (0 );
104
- httpid = http->get ( path );
113
+ httpid = http->get ( httpurl );
105
114
106
115
connect (http, SIGNAL ( requestStarted ( int ) ),
107
116
this , SLOT ( dataStarted ( int ) ) );
108
117
109
- connect (http, SIGNAL ( responseHeaderReceived ( const Q3HttpResponseHeader & ) ),
110
- this , SLOT ( dataHeaderReceived ( const Q3HttpResponseHeader & ) ) );
118
+ connect (http, SIGNAL ( responseHeaderReceived ( const QHttpResponseHeader & ) ),
119
+ this , SLOT ( dataHeaderReceived ( const QHttpResponseHeader & ) ) );
111
120
112
- connect (http, SIGNAL ( readyRead ( const Q3HttpResponseHeader & ) ),
113
- this , SLOT ( dataReceived ( const Q3HttpResponseHeader & ) ) );
121
+ connect (http, SIGNAL ( readyRead ( const QHttpResponseHeader & ) ),
122
+ this , SLOT ( dataReceived ( const QHttpResponseHeader & ) ) );
114
123
115
124
connect (http, SIGNAL ( dataReadProgress ( int , int ) ),
116
125
this , SLOT ( dataProgress ( int , int ) ) );
@@ -129,17 +138,20 @@ bool QgsHttpTransaction::getSynchronously(QByteArray &respondedContent, int redi
129
138
mWatchdogTimer ->start (NETWORK_TIMEOUT_MSEC);
130
139
131
140
#ifdef QGISDEBUG
132
- std::cout << " QgsHttpTransaction::getSynchronously: Starting get." << std::endl;
141
+ std::cout << " QgsHttpTransaction::getSynchronously: Starting get with id " << httpid << " ." << std::endl;
133
142
#endif
134
143
144
+ #ifdef QGISDEBUG
145
+ std::cout << " QgsHttpTransaction::getSynchronously: Setting httpactive = TRUE" << std::endl;
146
+ #endif
135
147
httpactive = TRUE ;
136
148
137
149
// A little trick to make this function blocking
138
150
while ( httpactive )
139
151
{
140
152
// Do something else, maybe even network processing events
141
153
qApp->processEvents ();
142
-
154
+
143
155
// TODO: Implement a network timeout
144
156
}
145
157
@@ -207,7 +219,7 @@ void QgsHttpTransaction::dataStarted( int id )
207
219
}
208
220
209
221
210
- void QgsHttpTransaction::dataHeaderReceived ( const Q3HttpResponseHeader & resp )
222
+ void QgsHttpTransaction::dataHeaderReceived ( const QHttpResponseHeader & resp )
211
223
{
212
224
213
225
#ifdef QGISDEBUG
@@ -241,7 +253,7 @@ void QgsHttpTransaction::dataHeaderReceived( const Q3HttpResponseHeader& resp )
241
253
}
242
254
243
255
244
- void QgsHttpTransaction::dataReceived ( const Q3HttpResponseHeader & resp )
256
+ void QgsHttpTransaction::dataReceived ( const QHttpResponseHeader & resp )
245
257
{
246
258
// TODO: Match 'resp' with 'http' if we move to multiple http connections
247
259
@@ -295,8 +307,8 @@ void QgsHttpTransaction::dataFinished( int id, bool error )
295
307
#ifdef QGISDEBUG
296
308
std::cout << " QgsHttpTransaction::dataFinished with ID " << id << " ." << std::endl;
297
309
298
- // The signal that this slot is connected to, Q3Http ::requestFinished,
299
- // appears to get called at the destruction of the Q3Http if it is
310
+ // The signal that this slot is connected to, QHttp ::requestFinished,
311
+ // appears to get called at the destruction of the QHttp if it is
300
312
// still working at the time of the destruction.
301
313
//
302
314
// This situation may occur when we've detected a timeout and
@@ -327,6 +339,9 @@ void QgsHttpTransaction::dataFinished( int id, bool error )
327
339
// TODO
328
340
httpresponse = http->readAll ();
329
341
342
+ #ifdef QGISDEBUG
343
+ std::cout << " QgsHttpTransaction::getSynchronously: Setting httpactive = FALSE" << std::endl;
344
+ #endif
330
345
httpactive = FALSE ;
331
346
332
347
}
@@ -343,15 +358,15 @@ void QgsHttpTransaction::dataStateChanged( int state )
343
358
344
359
switch (state)
345
360
{
346
- case Q3Http ::Unconnected:
361
+ case QHttp ::Unconnected:
347
362
#ifdef QGISDEBUG
348
363
std::cout << " There is no connection to the host." << std::endl;
349
364
#endif
350
365
351
366
emit setStatus ( QString (" Not connected" ) );
352
367
break ;
353
368
354
- case Q3Http ::HostLookup:
369
+ case QHttp ::HostLookup:
355
370
#ifdef QGISDEBUG
356
371
std::cout << " A host name lookup is in progress." << std::endl;
357
372
#endif
@@ -360,7 +375,7 @@ void QgsHttpTransaction::dataStateChanged( int state )
360
375
.arg (httphost) );
361
376
break ;
362
377
363
- case Q3Http ::Connecting:
378
+ case QHttp ::Connecting:
364
379
#ifdef QGISDEBUG
365
380
std::cout << " An attempt to connect to the host is in progress." << std::endl;
366
381
#endif
@@ -369,7 +384,7 @@ void QgsHttpTransaction::dataStateChanged( int state )
369
384
.arg (httphost) );
370
385
break ;
371
386
372
- case Q3Http ::Sending:
387
+ case QHttp ::Sending:
373
388
#ifdef QGISDEBUG
374
389
std::cout << " The client is sending its request to the server." << std::endl;
375
390
#endif
@@ -378,7 +393,7 @@ void QgsHttpTransaction::dataStateChanged( int state )
378
393
.arg (httpurl) );
379
394
break ;
380
395
381
- case Q3Http ::Reading:
396
+ case QHttp ::Reading:
382
397
#ifdef QGISDEBUG
383
398
std::cout << " The client's request has been sent and the client "
384
399
" is reading the server's response." << std::endl;
@@ -387,7 +402,7 @@ void QgsHttpTransaction::dataStateChanged( int state )
387
402
emit setStatus ( QString (" Receiving reply" ) );
388
403
break ;
389
404
390
- case Q3Http ::Connected:
405
+ case QHttp ::Connected:
391
406
#ifdef QGISDEBUG
392
407
std::cout << " The connection to the host is open, but the client "
393
408
" is neither sending a request, nor waiting for a response." << std::endl;
@@ -396,7 +411,7 @@ void QgsHttpTransaction::dataStateChanged( int state )
396
411
emit setStatus ( QString (" Response is complete" ) );
397
412
break ;
398
413
399
- case Q3Http ::Closing:
414
+ case QHttp ::Closing:
400
415
#ifdef QGISDEBUG
401
416
std::cout << " The connection is closing down, but is not yet closed. "
402
417
" (The state will be Unconnected when the connection is closed.)" << std::endl;
@@ -420,6 +435,9 @@ void QgsHttpTransaction::networkTimedOut()
420
435
" This may be a problem in your network connection or at the WMS server." )
421
436
).arg (NETWORK_TIMEOUT_MSEC/1000 );
422
437
438
+ #ifdef QGISDEBUG
439
+ std::cout << " QgsHttpTransaction::getSynchronously: Setting httpactive = FALSE" << std::endl;
440
+ #endif
423
441
httpactive = FALSE ;
424
442
425
443
#ifdef QGISDEBUG
0 commit comments