PTLib
Version 2.12.9
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
http.h
Go to the documentation of this file.
1
/*
2
* http.h
3
*
4
* HyperText Transport Protocol classes.
5
*
6
* Portable Windows Library
7
*
8
* Copyright (c) 1993-2002 Equivalence Pty. Ltd.
9
*
10
* The contents of this file are subject to the Mozilla Public License
11
* Version 1.0 (the "License"); you may not use this file except in
12
* compliance with the License. You may obtain a copy of the License at
13
* http://www.mozilla.org/MPL/
14
*
15
* Software distributed under the License is distributed on an "AS IS"
16
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17
* the License for the specific language governing rights and limitations
18
* under the License.
19
*
20
* The Original Code is Portable Windows Library.
21
*
22
* The Initial Developer of the Original Code is Equivalence Pty. Ltd.
23
*
24
* Contributor(s): ______________________________________.
25
*
26
* $Revision: 28997 $
27
* $Author: rjongbloed $
28
* $Date: 2013-01-26 13:37:28 +1100 (Sat, 26 Jan 2013) $
29
*/
30
31
#ifndef PTLIB_HTTP_H
32
#define PTLIB_HTTP_H
33
34
#ifdef P_USE_PRAGMA
35
#pragma interface
36
#endif
37
38
#if P_HTTP
39
40
#include <
ptclib/inetprot.h
>
41
#include <
ptclib/mime.h
>
42
#include <
ptclib/url.h
>
43
#include <
ptlib/ipsock.h
>
44
#include <
ptlib/pfactory.h
>
45
46
47
#include <
ptclib/html.h
>
48
50
// PHTTPSpace
51
52
class
PHTTPResource
;
53
58
class
PHTTPSpace
:
public
PContainer
59
{
60
PCONTAINERINFO
(
PHTTPSpace
,
PContainer
)
61
public
:
63
PHTTPSpace
();
64
65
66
// New functions for class.
67
enum
AddOptions
{
68
ErrorOnExist
,
69
Overwrite
70
};
71
72
84
PBoolean
AddResource
(
85
PHTTPResource
* resource,
86
AddOptions
overwrite =
ErrorOnExist
88
);
89
97
PBoolean
DelResource
(
98
const
PURL
& url
99
);
100
106
PHTTPResource
*
FindResource
(
107
const
PURL
& url
108
);
109
112
void
StartRead
()
const
113
{
mutex
->
StartRead
(); }
114
117
void
EndRead
()
const
118
{
mutex
->
EndRead
(); }
119
122
void
StartWrite
()
const
123
{
mutex
->
StartWrite
(); }
124
127
void
EndWrite
()
const
128
{
mutex
->
EndWrite
(); }
129
130
131
protected
:
132
PReadWriteMutex
*
mutex
;
133
134
class
Node
;
135
PSORTED_LIST
(ChildList,
Node
);
136
class
Node
:
public
PString
137
{
138
PCLASSINFO
(
Node
,
PString
)
139
public
:
140
Node
(
const
PString
& name,
Node
* parentNode);
141
~Node
();
142
143
Node
*
parent
;
144
ChildList
children
;
145
PHTTPResource
*
resource
;
146
} *
root
;
147
148
private
:
149
PBoolean
SetSize(PINDEX) {
return
false
; }
150
};
151
152
#ifdef TRACE
153
#undef TRACE
154
#endif
155
157
// PHTTP
158
162
class
PHTTP
:
public
PInternetProtocol
163
{
164
PCLASSINFO
(
PHTTP
,
PInternetProtocol
)
165
166
public
:
167
// New functions for class.
168
enum
Commands
{
169
// HTTP/1.0 commands
170
GET
,
HEAD
,
POST
,
171
// HTTP/1.1 commands
172
PUT
,
DELETE
,
TRACE
,
OPTIONS
,
173
// HTTPS command
174
CONNECT
,
175
NumCommands
176
};
177
178
enum
StatusCode
{
179
BadResponse
= 1,
180
ContentProcessorError
,
181
UnknownTransferEncoding
,
182
Continue
= 100,
183
SwitchingProtocols
,
184
RequestOK
= 200,
185
Created
,
186
Accepted
,
187
NonAuthoritativeInformation
,
188
NoContent
,
189
ResetContent
,
190
PartialContent
,
191
MultipleChoices
= 300,
192
MovedPermanently
,
193
MovedTemporarily
,
194
SeeOther
,
195
NotModified
,
196
UseProxy
,
197
BadRequest
= 400,
198
UnAuthorised
,
199
PaymentRequired
,
200
Forbidden
,
201
NotFound
,
202
MethodNotAllowed
,
203
NoneAcceptable
,
204
ProxyAuthenticationRequired
,
205
RequestTimeout
,
206
Conflict
,
207
Gone
,
208
LengthRequired
,
209
UnlessTrue
,
210
InternalServerError
= 500,
211
NotImplemented
,
212
BadGateway
,
213
ServiceUnavailable
,
214
GatewayTimeout
215
};
216
217
// Common MIME header tags
218
static
const
PCaselessString
&
HostTag
();
219
static
const
PCaselessString
&
AllowTag
();
220
static
const
PCaselessString
&
AuthorizationTag
();
221
static
const
PCaselessString
&
ContentEncodingTag
();
222
static
const
PCaselessString
&
ContentLengthTag
();
223
static
const
PCaselessString
&
ContentTypeTag
() {
return
PMIMEInfo::ContentTypeTag
(); }
224
static
const
PCaselessString
&
DateTag
();
225
static
const
PCaselessString
&
ExpiresTag
();
226
static
const
PCaselessString
&
FromTag
();
227
static
const
PCaselessString
&
IfModifiedSinceTag
();
228
static
const
PCaselessString
&
LastModifiedTag
();
229
static
const
PCaselessString
&
LocationTag
();
230
static
const
PCaselessString
&
PragmaTag
();
231
static
const
PCaselessString
&
PragmaNoCacheTag
();
232
static
const
PCaselessString
&
RefererTag
();
233
static
const
PCaselessString
&
ServerTag
();
234
static
const
PCaselessString
&
UserAgentTag
();
235
static
const
PCaselessString
&
WWWAuthenticateTag
();
236
static
const
PCaselessString
&
MIMEVersionTag
();
237
static
const
PCaselessString
&
ConnectionTag
();
238
static
const
PCaselessString
&
KeepAliveTag
();
239
static
const
PCaselessString
&
TransferEncodingTag
();
240
static
const
PCaselessString
&
ChunkedTag
();
241
static
const
PCaselessString
&
ProxyConnectionTag
();
242
static
const
PCaselessString
&
ProxyAuthorizationTag
();
243
static
const
PCaselessString
&
ProxyAuthenticateTag
();
244
static
const
PCaselessString
&
ForwardedTag
();
245
static
const
PCaselessString
&
SetCookieTag
();
246
static
const
PCaselessString
&
CookieTag
();
247
248
protected
:
251
PHTTP
();
252
PHTTP
(
253
const
char
*
defaultServiceName
254
);
255
267
virtual
PINDEX
ParseResponse
(
268
const
PString
& line
269
);
270
};
271
272
273
274
class
PHTTPClientAuthentication
:
public
PObject
275
{
276
PCLASSINFO(
PHTTPClientAuthentication
,
PObject
);
277
public
:
278
class
AuthObject
{
279
public
:
280
virtual
~AuthObject
() { }
281
virtual
PMIMEInfo
&
GetMIME
() = 0;
282
virtual
PString
GetURI
() = 0;
283
virtual
PString
GetEntityBody
() = 0;
284
virtual
PString
GetMethod
() = 0;
285
};
286
287
PHTTPClientAuthentication
();
288
289
virtual
Comparison
Compare
(
290
const
PObject
& other
291
)
const
;
292
293
virtual
PBoolean
Parse
(
294
const
PString
& auth,
295
PBoolean
proxy
296
) = 0;
297
298
virtual
PBoolean
Authorise
(
299
AuthObject & pdu
300
)
const
= 0;
301
302
virtual
PBoolean
IsProxy
()
const
{
return
isProxy
; }
303
304
virtual
PString
GetUsername
()
const
{
return
username
; }
305
virtual
PString
GetPassword
()
const
{
return
password
; }
306
virtual
PString
GetAuthRealm
()
const
{
return
PString::Empty
(); }
307
308
virtual
void
SetUsername
(
const
PString
& user) {
username
= user; }
309
virtual
void
SetPassword
(
const
PString
& pass) {
password
= pass; }
310
virtual
void
SetAuthRealm
(
const
PString
&) { }
311
312
PString
GetAuthParam
(
const
PString
& auth,
const
char
* name)
const
;
313
PString
AsHex
(
PMessageDigest5::Code
& digest)
const
;
314
PString
AsHex
(
const
PBYTEArray
& data)
const
;
315
316
static
PHTTPClientAuthentication
*
ParseAuthenticationRequired
(
bool
isProxy
,
const
PMIMEInfo
& line,
PString
& errorMsg);
317
318
319
protected
:
320
PBoolean
isProxy
;
321
PString
username
;
322
PString
password
;
323
};
324
325
typedef
PFactory<PHTTPClientAuthentication>
PHTTPClientAuthenticationFactory
;
326
327
class
PHTTPClientAuthenticator
:
public
PHTTPClientAuthentication::AuthObject
328
{
329
public
:
330
PHTTPClientAuthenticator
(
331
const
PString
& cmdName,
332
const
PString
& uri,
333
PMIMEInfo
& mime,
334
const
PString
& body
335
);
336
virtual
PMIMEInfo
&
GetMIME
();
337
virtual
PString
GetURI
();
338
virtual
PString
GetEntityBody
();
339
virtual
PString
GetMethod
();
340
protected
:
341
PString
m_method
;
342
PString
m_uri
;
343
PMIMEInfo
&
m_mime
;
344
PString
m_body
;
345
};
346
348
349
class
PHTTPClientBasicAuthentication
:
public
PHTTPClientAuthentication
350
{
351
PCLASSINFO(
PHTTPClientBasicAuthentication
,
PHTTPClientAuthentication
);
352
public
:
353
PHTTPClientBasicAuthentication
();
354
355
virtual
Comparison
Compare
(
356
const
PObject
& other
357
)
const
;
358
359
virtual
PBoolean
Parse
(
360
const
PString
& auth,
361
PBoolean
proxy
362
);
363
364
virtual
PBoolean
Authorise
(
365
AuthObject
& pdu
366
)
const
;
367
};
368
370
371
class
PHTTPClientDigestAuthentication
:
public
PHTTPClientAuthentication
372
{
373
PCLASSINFO(
PHTTPClientDigestAuthentication
,
PHTTPClientAuthentication
);
374
public
:
375
PHTTPClientDigestAuthentication
();
376
377
PHTTPClientDigestAuthentication
&
operator =
(
378
const
PHTTPClientDigestAuthentication
& auth
379
);
380
381
virtual
Comparison
Compare
(
382
const
PObject
& other
383
)
const
;
384
385
virtual
PBoolean
Parse
(
386
const
PString
& auth,
387
PBoolean
proxy
388
);
389
390
virtual
PBoolean
Authorise
(
391
AuthObject
& pdu
392
)
const
;
393
394
virtual
PString
GetAuthRealm
()
const
{
return
authRealm
; }
395
virtual
void
SetAuthRealm
(
const
PString
& r) {
authRealm
= r; }
396
397
enum
Algorithm
{
398
Algorithm_MD5
,
399
NumAlgorithms
400
};
401
const
PString
&
GetNonce
()
const
{
return
nonce
; }
402
Algorithm
GetAlgorithm
()
const
{
return
algorithm
; }
403
const
PString
&
GetOpaque
()
const
{
return
opaque
; }
404
bool
GetStale
()
const
{
return
stale
; }
405
406
protected
:
407
PString
authRealm
;
408
PString
nonce
;
409
Algorithm
algorithm
;
410
PString
opaque
;
411
412
bool
qopAuth
;
413
bool
qopAuthInt
;
414
bool
stale
;
415
PString
cnonce
;
416
mutable
PAtomicInteger
nonceCount
;
417
};
418
419
421
// PHTTPClient
422
443
class
PHTTPClient
:
public
PHTTP
444
{
445
PCLASSINFO
(
PHTTPClient
,
PHTTP
)
446
447
public
:
449
PHTTPClient
(
450
const
PString
& userAgentName =
PString::Empty
()
451
);
452
453
454
// New functions for class.
462
int
ExecuteCommand
(
463
Commands
cmd,
464
const
PURL
& url,
465
PMIMEInfo
& outMIME,
466
const
PString
& dataBody,
467
PMIMEInfo
& replyMime
468
);
469
int
ExecuteCommand
(
470
const
PString
& cmdName,
471
const
PURL
& url,
472
PMIMEInfo
& outMIME,
473
const
PString
& dataBody,
474
PMIMEInfo
& replyMime
475
);
476
478
bool
WriteCommand
(
479
Commands
cmd,
480
const
PString
& url,
481
PMIMEInfo
& outMIME,
482
const
PString
& dataBody
483
);
484
bool
WriteCommand
(
485
const
PString
& cmdName,
486
const
PString
& url,
487
PMIMEInfo
& outMIME,
488
const
PString
& dataBody
489
);
490
492
bool
ReadResponse
(
493
PMIMEInfo
& replyMIME
494
);
495
497
struct
ContentProcessor
498
{
499
virtual
~ContentProcessor
() { }
500
virtual
void
*
GetBuffer
(PINDEX & size) = 0;
501
virtual
bool
Process
(
const
void
* data, PINDEX length) = 0;
502
};
503
505
bool
ReadContentBody
(
506
PMIMEInfo
& replyMIME,
507
ContentProcessor & processor
508
);
509
511
bool
ReadContentBody
(
512
PMIMEInfo
& replyMIME
513
);
514
516
bool
ReadContentBody
(
517
PMIMEInfo
& replyMIME,
518
PString
& body
519
);
520
522
bool
ReadContentBody
(
523
PMIMEInfo
& replyMIME,
524
PBYTEArray
& body
525
);
526
527
534
bool
GetDocument
(
535
const
PURL
& url,
536
ContentProcessor & processor
537
);
538
545
bool
GetDocument
(
546
const
PURL
& url,
547
PMIMEInfo
& outMIME,
548
PMIMEInfo
& replyMIME
549
);
550
bool
GetDocument
(
551
const
PURL
& url,
552
PMIMEInfo
& replyMIME
553
);
554
555
563
bool
GetTextDocument
(
564
const
PURL
& url,
565
PString
& document,
566
const
PString
& contentType =
PString::Empty
()
567
);
568
576
bool
GetBinaryDocument
(
577
const
PURL
& url,
578
PBYTEArray
& document,
579
const
PString
& contentType =
PString::Empty
()
580
);
581
582
588
bool
GetHeader
(
589
const
PURL
& url,
590
PMIMEInfo
& outMIME,
591
PMIMEInfo
& replyMIME
592
);
593
bool
GetHeader
(
594
const
PURL
& url,
595
PMIMEInfo
& replyMIME
596
);
597
598
604
bool
PostData
(
605
const
PURL
& url,
606
const
PStringToString
& data
607
);
608
614
bool
PostData
(
615
const
PURL
& url,
616
PMIMEInfo
& outMIME,
617
const
PString
& data
618
);
619
626
bool
PostData
(
627
const
PURL
& url,
628
PMIMEInfo
& outMIME,
629
const
PString
& data,
630
PMIMEInfo
& replyMIME
631
);
632
638
bool
PostData
(
639
const
PURL
& url,
640
PMIMEInfo
& outMIME,
641
const
PString
& data,
642
PMIMEInfo
& replyMIME,
643
PString
& replyBody
644
);
645
651
bool
PutTextDocument
(
652
const
PURL
& url,
653
const
PString
& document,
654
const
PString
& contentType =
PMIMEInfo::TextPlain
()
655
);
656
662
bool
PutDocument
(
663
const
PURL
& url,
664
PMIMEInfo
& outMIME,
665
PMIMEInfo
& replyMIME
666
);
667
673
bool
DeleteDocument
(
674
const
PURL
& url
675
);
676
679
void
SetAuthenticationInfo
(
680
const
PString
& userName,
681
const
PString
& password
682
);
683
684
#if P_SSL
685
void
SetSSLCredentials(
686
const
PString
& authority,
687
const
PString
& certificate,
688
const
PString
& privateKey
689
);
690
#endif
691
693
void
SetPersistent
(
694
bool
persist =
true
695
) {
m_persist
= persist; }
696
698
bool
GetPersistent
()
const
{
return
m_persist
; }
699
700
protected
:
701
bool
AssureConnect
(
const
PURL
& url,
PMIMEInfo
& outMIME);
702
703
PString
m_userAgentName
;
704
bool
m_persist
;
705
PString
m_userName
;
706
PString
m_password
;
707
#if P_SSL
708
PString
m_authority;
// Directory, file or data
709
PString
m_certificate;
// File or data
710
PString
m_privateKey;
// File or data
711
#endif
712
PHTTPClientAuthentication
*
m_authentication
;
713
};
714
715
717
// PHTTPConnectionInfo
718
719
class
PHTTPServer
;
720
725
class
PHTTPConnectionInfo
:
public
PObject
726
{
727
PCLASSINFO
(
PHTTPConnectionInfo
,
PObject
)
728
public
:
729
PHTTPConnectionInfo
();
730
731
PHTTP::Commands
GetCommandCode
()
const
{
return
commandCode
; }
732
const
PString
&
GetCommandName
()
const
{
return
commandName
; }
733
734
const
PURL
&
GetURL
()
const
{
return
url
; }
735
736
const
PMIMEInfo
&
GetMIME
()
const
{
return
mimeInfo
; }
737
void
SetMIME
(
const
PString
& tag,
const
PString
& value);
738
739
PBoolean
IsCompatible
(
int
major,
int
minor)
const
;
740
741
bool
IsPersistent
()
const
{
return
isPersistent
; }
742
bool
WasPersistent
()
const
{
return
wasPersistent
; }
743
bool
IsProxyConnection
()
const
{
return
isProxyConnection
; }
744
int
GetMajorVersion
()
const
{
return
majorVersion
; }
745
int
GetMinorVersion
()
const
{
return
minorVersion
; }
746
747
long
GetEntityBodyLength
()
const
{
return
entityBodyLength
; }
748
751
PTimeInterval
GetPersistenceTimeout
()
const
{
return
persistenceTimeout
; }
752
755
void
SetPersistenceTimeout
(
const
PTimeInterval
& t) {
persistenceTimeout
= t; }
756
760
unsigned
GetPersistenceMaximumTransations
()
const
{
return
persistenceMaximum
; }
761
765
void
SetPersistenceMaximumTransations
(
unsigned
m) {
persistenceMaximum
= m; }
766
767
const
PMultiPartList
&
GetMultipartFormInfo
()
const
768
{
return
m_multipartFormInfo
; }
769
770
void
ResetMultipartFormInfo
()
771
{
m_multipartFormInfo
.
RemoveAll
(); }
772
773
PString
GetEntityBody
()
const
{
return
entityBody
; }
774
775
protected
:
776
PBoolean
Initialise
(
PHTTPServer
& server,
PString
& args);
777
bool
DecodeMultipartFormInfo
() {
return
mimeInfo
.
DecodeMultiPartList
(
m_multipartFormInfo
,
entityBody
); }
778
779
PHTTP::Commands
commandCode
;
780
PString
commandName
;
781
PURL
url
;
782
PMIMEInfo
mimeInfo
;
783
bool
isPersistent
;
784
bool
wasPersistent
;
785
bool
isProxyConnection
;
786
int
majorVersion
;
787
int
minorVersion
;
788
PString
entityBody
;
// original entity body (POST only)
789
long
entityBodyLength
;
790
PTimeInterval
persistenceTimeout
;
791
unsigned
persistenceMaximum
;
792
PMultiPartList
m_multipartFormInfo
;
793
794
friend
class
PHTTPServer
;
795
};
796
797
799
// PHTTPServer
800
822
class
PHTTPServer
:
public
PHTTP
823
{
824
PCLASSINFO
(
PHTTPServer
,
PHTTP
)
825
826
public
:
834
PHTTPServer
();
835
PHTTPServer
(
836
const
PHTTPSpace
&
urlSpace
837
);
838
839
840
// New functions for class.
846
virtual
PString
GetServerName
()
const
;
847
853
PHTTPSpace
&
GetURLSpace
() {
return
urlSpace
; }
854
856
void
SetURLSpace
(
857
const
PHTTPSpace
& space
858
);
859
860
870
virtual
PBoolean
ProcessCommand
();
871
883
virtual
PBoolean
OnGET
(
884
const
PURL
& url,
885
const
PMIMEInfo
& info,
886
const
PHTTPConnectionInfo
& conInfo
887
);
888
889
890
902
virtual
PBoolean
OnHEAD
(
903
const
PURL
& url,
904
const
PMIMEInfo
& info,
905
const
PHTTPConnectionInfo
& conInfo
906
);
907
919
virtual
PBoolean
OnPOST
(
920
const
PURL
& url,
921
const
PMIMEInfo
& info,
922
const
PStringToString
& data,
923
const
PHTTPConnectionInfo
& conInfo
924
);
925
938
virtual
PBoolean
OnProxy
(
939
const
PHTTPConnectionInfo
& conInfo
940
);
941
942
949
virtual
PString
ReadEntityBody
();
950
956
virtual
PBoolean
OnUnknown
(
957
const
PCaselessString
& command,
958
const
PHTTPConnectionInfo
&
connectInfo
959
);
960
979
PBoolean
StartResponse
(
980
StatusCode
code,
981
PMIMEInfo
& headers,
982
long
bodySize
983
);
984
994
virtual
PBoolean
OnError
(
995
StatusCode
code,
996
const
PCaselessString
& extra,
997
const
PHTTPConnectionInfo
&
connectInfo
998
);
999
1002
void
SetDefaultMIMEInfo
(
1003
PMIMEInfo
& info,
1004
const
PHTTPConnectionInfo
&
connectInfo
1005
);
1006
1009
PHTTPConnectionInfo
&
GetConnectionInfo
() {
return
connectInfo
; }
1010
1016
virtual
bool
OnCommand
(
1017
PINDEX cmd,
1018
const
PURL
& url,
1019
const
PString
& args,
1020
PHTTPConnectionInfo
&
connectInfo
1021
);
1022
1023
1024
protected
:
1025
void
Construct
();
1026
1027
PHTTPSpace
urlSpace
;
1028
PHTTPConnectionInfo
connectInfo
;
1029
unsigned
transactionCount
;
1030
PTimeInterval
nextTimeout
;
1031
};
1032
1033
1035
// PHTTPRequest
1036
1041
class
PHTTPRequest
:
public
PObject
1042
{
1043
PCLASSINFO
(
PHTTPRequest
,
PObject
)
1044
1045
public
:
1046
PHTTPRequest
(
1047
const
PURL
& url,
1048
const
PMIMEInfo
&
inMIME
,
1049
const
PMultiPartList
&
multipartFormInfo
,
1050
PHTTPResource
* resource,
1051
PHTTPServer
&
server
1052
);
1053
1054
PHTTPServer
&
server
;
1055
const
PURL
&
url
;
1056
const
PMIMEInfo
&
inMIME
;
1057
const
PMultiPartList
&
multipartFormInfo
;
1058
PHTTP::StatusCode
code
;
1059
PMIMEInfo
outMIME
;
1060
PString
entityBody
;
1061
PINDEX
contentSize
;
1062
PIPSocket::Address
origin
;
1063
PIPSocket::Address
localAddr
;
1064
WORD
localPort
;
1065
PHTTPResource
*
m_resource
;
1066
};
1067
1068
1070
// PHTTPAuthority
1071
1075
class
PHTTPAuthority
:
public
PObject
1076
{
1077
PCLASSINFO
(
PHTTPAuthority
,
PObject
)
1078
1079
public
:
1080
// New functions for class.
1087
virtual
PString
GetRealm
(
1088
const
PHTTPRequest
& request
1089
)
const
= 0;
1090
1097
virtual
PBoolean
Validate
(
1098
const
PHTTPRequest
& request,
1099
const
PString
& authInfo
1100
)
const
= 0;
1101
1111
virtual
PBoolean
IsActive
()
const
;
1112
1113
protected
:
1114
static
void
DecodeBasicAuthority
(
1115
const
PString
& authInfo,
1116
PString
& username,
1117
PString
& password
1118
);
1119
};
1120
1121
1123
// PHTTPSimpleAuth
1124
1128
class
PHTTPSimpleAuth
:
public
PHTTPAuthority
1129
{
1130
PCLASSINFO
(
PHTTPSimpleAuth
,
PHTTPAuthority
)
1131
1132
public
:
1133
PHTTPSimpleAuth
(
1134
const
PString
&
realm
,
1135
const
PString
&
username
,
1136
const
PString
&
password
1137
);
1138
// Construct the simple authorisation structure.
1139
1140
1141
// Overrides from class PObject.
1149
virtual
PObject
*
Clone
()
const
;
1150
1151
1152
// Overrides from class PHTTPAuthority.
1159
virtual
PString
GetRealm
(
1160
const
PHTTPRequest
& request
1161
)
const
;
1162
1169
virtual
PBoolean
Validate
(
1170
const
PHTTPRequest
& request,
1171
const
PString
& authInfo
1172
)
const
;
1173
1183
virtual
PBoolean
IsActive
()
const
;
1184
1190
const
PString
&
GetUserName
()
const
{
return
username
; }
1191
1197
const
PString
&
GetPassword
()
const
{
return
password
; }
1198
1199
1200
protected
:
1201
PString
realm
;
1202
PString
username
;
1203
PString
password
;
1204
};
1205
1206
1208
// PHTTPMultiSimpAuth
1209
1213
class
PHTTPMultiSimpAuth
:
public
PHTTPAuthority
1214
{
1215
PCLASSINFO
(
PHTTPMultiSimpAuth
,
PHTTPAuthority
)
1216
1217
public
:
1218
PHTTPMultiSimpAuth
(
1219
const
PString
&
realm
1220
);
1221
PHTTPMultiSimpAuth
(
1222
const
PString
& realm,
1223
const
PStringToString
& userList
1224
);
1225
// Construct the simple authorisation structure.
1226
1227
1228
// Overrides from class PObject.
1236
virtual
PObject
*
Clone
()
const
;
1237
1238
1239
// Overrides from class PHTTPAuthority.
1246
virtual
PString
GetRealm
(
1247
const
PHTTPRequest
& request
1248
)
const
;
1249
1256
virtual
PBoolean
Validate
(
1257
const
PHTTPRequest
& request,
1258
const
PString
& authInfo
1259
)
const
;
1260
1270
virtual
PBoolean
IsActive
()
const
;
1271
1277
void
AddUser
(
1278
const
PString
& username,
1279
const
PString
& password
1280
);
1281
1282
1283
protected
:
1284
PString
realm
;
1285
PStringToString
users
;
1286
};
1287
1288
1290
// PHTTPResource
1291
1295
class
PHTTPResource
:
public
PObject
1296
{
1297
PCLASSINFO
(
PHTTPResource
,
PObject
)
1298
1299
protected
:
1300
PHTTPResource
(
1301
const
PURL
& url
1302
);
1303
PHTTPResource
(
1304
const
PURL
& url,
1305
const
PHTTPAuthority
& auth
1306
);
1307
PHTTPResource
(
1308
const
PURL
& url,
1309
const
PString
&
contentType
1310
);
1311
PHTTPResource
(
1312
const
PURL
& url,
1313
const
PString
& contentType,
1314
const
PHTTPAuthority
& auth
1315
);
1316
// Create a new HTTP Resource.
1317
1318
1319
public
:
1320
virtual
~PHTTPResource
();
1321
// Destroy the HTTP Resource.
1322
1323
1324
// New functions for class.
1330
const
PURL
&
GetURL
()
const
{
return
baseURL
; }
1331
1334
PString
GetHotLink
()
const
{
return
baseURL
.
AsString
(
PURL::PathOnly
); }
1335
1341
const
PString
&
GetContentType
()
const
{
return
contentType
; }
1342
1349
PHTTPAuthority
*
GetAuthority
()
const
{
return
authority
; }
1350
1353
void
SetAuthority
(
1354
const
PHTTPAuthority
& auth
1355
);
1356
1359
void
ClearAuthority
();
1360
1367
DWORD
GetHitCount
()
const
{
return
hitCount
; }
1368
1369
void
ClearHitCount
() {
hitCount
= 0; }
1370
// Clear the hit count for the resource.
1371
1372
1384
virtual
PBoolean
OnGET
(
1385
PHTTPServer
& server,
1386
const
PURL
& url,
1387
const
PMIMEInfo
& info,
1388
const
PHTTPConnectionInfo
& conInfo
1389
);
1390
1400
virtual
PBoolean
OnGETData
(
1401
PHTTPServer
& server,
1402
const
PURL
& url,
1403
const
PHTTPConnectionInfo
& connectInfo,
1404
PHTTPRequest
& request
1405
);
1406
1418
virtual
PBoolean
OnHEAD
(
1419
PHTTPServer
& server,
1420
const
PURL
& url,
1421
const
PMIMEInfo
& info,
1422
const
PHTTPConnectionInfo
& conInfo
1423
);
1424
1436
virtual
PBoolean
OnPOST
(
1437
PHTTPServer
& server,
1438
const
PURL
& url,
1439
const
PMIMEInfo
& info,
1440
const
PStringToString
& data,
1441
const
PHTTPConnectionInfo
& conInfo
1442
);
1443
1453
virtual
PBoolean
OnPOSTData
(
1454
PHTTPRequest
& request,
1455
const
PStringToString
& data
1456
);
1457
1464
virtual
PBoolean
IsModifiedSince
(
1465
const
PTime
& when
1466
);
1467
1473
virtual
PBoolean
GetExpirationDate
(
1474
PTime
& when
1475
);
1476
1484
virtual
PHTTPRequest
*
CreateRequest
(
1485
const
PURL
& url,
1486
const
PMIMEInfo
& inMIME,
1487
const
PMultiPartList
& multipartFormInfo,
1488
PHTTPServer
& socket
1489
);
1490
1498
virtual
PBoolean
LoadHeaders
(
1499
PHTTPRequest
& request
1500
) = 0;
1501
1507
virtual
void
SendData
(
1508
PHTTPRequest
& request
1509
);
1510
1519
virtual
PBoolean
LoadData
(
1520
PHTTPRequest
& request,
1521
PCharArray
& data
1522
);
1523
1532
virtual
PString
LoadText
(
1533
PHTTPRequest
& request
1534
);
1535
1542
virtual
void
OnLoadedText
(
1543
PHTTPRequest
& request,
1544
PString
& text
1545
);
1546
1555
virtual
PBoolean
Post
(
1556
PHTTPRequest
& request,
1557
const
PStringToString
& data,
1558
PHTML
& replyMessage
1559
);
1560
1561
1562
protected
:
1565
virtual
PBoolean
CheckAuthority
(
1566
PHTTPServer
& server,
1567
const
PHTTPRequest
& request,
1568
const
PHTTPConnectionInfo
& conInfo
1569
);
1570
static
PBoolean
CheckAuthority
(
1571
PHTTPAuthority
&
authority
,
1572
PHTTPServer
& server,
1573
const
PHTTPRequest
& request,
1574
const
PHTTPConnectionInfo
& connectInfo
1575
);
1576
1577
1579
virtual
PBoolean
OnGETOrHEAD
(
1580
PHTTPServer
& server,
1581
const
PURL
& url,
1582
const
PMIMEInfo
& info,
1583
const
PHTTPConnectionInfo
& conInfo,
1584
PBoolean
isGet
1585
);
1586
1587
1588
PURL
baseURL
;
1589
PString
contentType
;
1590
PHTTPAuthority
*
authority
;
1591
volatile
DWORD
hitCount
;
1592
};
1593
1594
1596
// PHTTPString
1597
1602
class
PHTTPString
:
public
PHTTPResource
1603
{
1604
PCLASSINFO
(
PHTTPString
,
PHTTPResource
)
1605
1606
public
:
1610
PHTTPString
(
1611
const
PURL
& url
// Name of the resource in URL space.
1612
);
1613
PHTTPString
(
1614
const
PURL
& url,
// Name of the resource in URL space.
1615
const
PHTTPAuthority
& auth
// Authorisation for the resource.
1616
);
1617
PHTTPString
(
1618
const
PURL
& url,
// Name of the resource in URL space.
1619
const
PString
& str
// String to return in this resource.
1620
);
1621
PHTTPString
(
1622
const
PURL
& url,
// Name of the resource in URL space.
1623
const
PString
& str,
// String to return in this resource.
1624
const
PString
&
contentType
// MIME content type for the file.
1625
);
1626
PHTTPString
(
1627
const
PURL
& url,
// Name of the resource in URL space.
1628
const
PString
& str,
// String to return in this resource.
1629
const
PHTTPAuthority
& auth
// Authorisation for the resource.
1630
);
1631
PHTTPString
(
1632
const
PURL
& url,
// Name of the resource in URL space.
1633
const
PString
& str,
// String to return in this resource.
1634
const
PString
& contentType,
// MIME content type for the file.
1635
const
PHTTPAuthority
& auth
// Authorisation for the resource.
1636
);
1637
1638
1639
// Overrides from class PHTTPResource
1647
virtual
PBoolean
LoadHeaders
(
1648
PHTTPRequest
& request
// Information on this request.
1649
);
1650
1659
virtual
PString
LoadText
(
1660
PHTTPRequest
& request
// Information on this request.
1661
);
1662
1663
// New functions for class.
1669
const
PString
&
GetString
() {
return
string
; }
1670
1673
void
SetString
(
1674
const
PString
& str
// New string for the resource.
1675
) {
string
= str; }
1676
1677
1678
protected
:
1679
PString
string
;
1680
};
1681
1682
1684
// PHTTPFile
1685
1691
class
PHTTPFile
:
public
PHTTPResource
1692
{
1693
PCLASSINFO
(
PHTTPFile
,
PHTTPResource
)
1694
1695
public
:
1702
PHTTPFile
(
1703
const
PString
& filename
// file in file system and URL name.
1704
);
1705
PHTTPFile
(
1706
const
PString
& filename,
// file in file system and URL name.
1707
const
PHTTPAuthority
& auth
// Authorisation for the resource.
1708
);
1709
PHTTPFile
(
1710
const
PURL
& url,
// Name of the resource in URL space.
1711
const
PFilePath
& file
// Location of file in file system.
1712
);
1713
PHTTPFile
(
1714
const
PURL
& url,
// Name of the resource in URL space.
1715
const
PFilePath
& file,
// Location of file in file system.
1716
const
PString
&
contentType
// MIME content type for the file.
1717
);
1718
PHTTPFile
(
1719
const
PURL
& url,
// Name of the resource in URL space.
1720
const
PFilePath
& file,
// Location of file in file system.
1721
const
PHTTPAuthority
& auth
// Authorisation for the resource.
1722
);
1723
PHTTPFile
(
1724
const
PURL
& url,
// Name of the resource in URL space.
1725
const
PFilePath
& file,
// Location of file in file system.
1726
const
PString
& contentType,
// MIME content type for the file.
1727
const
PHTTPAuthority
& auth
// Authorisation for the resource.
1728
);
1729
1730
1731
// Overrides from class PHTTPResource
1737
virtual
PHTTPRequest
*
CreateRequest
(
1738
const
PURL
& url,
// Universal Resource Locator for document.
1739
const
PMIMEInfo
& inMIME,
// Extra MIME information in command.
1740
const
PMultiPartList
& multipartFormInfo,
1741
PHTTPServer
& socket
1742
);
1743
1751
virtual
PBoolean
LoadHeaders
(
1752
PHTTPRequest
& request
// Information on this request.
1753
);
1754
1760
virtual
PBoolean
LoadData
(
1761
PHTTPRequest
& request,
// Information on this request.
1762
PCharArray
& data
// Data used in reply.
1763
);
1764
1773
virtual
PString
LoadText
(
1774
PHTTPRequest
& request
// Information on this request.
1775
);
1776
1777
1778
protected
:
1779
PHTTPFile
(
1780
const
PURL
& url,
// Name of the resource in URL space.
1781
int
dummy
1782
);
1783
// Constructor used by PHTTPDirectory
1784
1785
1786
PFilePath
filePath
;
1787
};
1788
1789
1790
class
PHTTPFileRequest
:
public
PHTTPRequest
1791
{
1792
PCLASSINFO
(
PHTTPFileRequest
,
PHTTPRequest
)
1793
public
:
1794
PHTTPFileRequest
(
1795
const
PURL
& url,
// Universal Resource Locator for document.
1796
const
PMIMEInfo
&
inMIME
,
// Extra MIME information in command.
1797
const
PMultiPartList
&
multipartFormInfo
,
1798
PHTTPResource
* resource,
1799
PHTTPServer
&
server
1800
);
1801
1802
PFile
file
;
1803
};
1804
1805
1807
// PHTTPTailFile
1808
1817
class
PHTTPTailFile
:
public
PHTTPFile
1818
{
1819
PCLASSINFO
(
PHTTPTailFile
,
PHTTPFile
)
1820
1821
public
:
1828
PHTTPTailFile
(
1829
const
PString
& filename
// file in file system and URL name.
1830
);
1831
PHTTPTailFile
(
1832
const
PString
& filename,
// file in file system and URL name.
1833
const
PHTTPAuthority
& auth
// Authorisation for the resource.
1834
);
1835
PHTTPTailFile
(
1836
const
PURL
& url,
// Name of the resource in URL space.
1837
const
PFilePath
& file
// Location of file in file system.
1838
);
1839
PHTTPTailFile
(
1840
const
PURL
& url,
// Name of the resource in URL space.
1841
const
PFilePath
& file,
// Location of file in file system.
1842
const
PString
&
contentType
// MIME content type for the file.
1843
);
1844
PHTTPTailFile
(
1845
const
PURL
& url,
// Name of the resource in URL space.
1846
const
PFilePath
& file,
// Location of file in file system.
1847
const
PHTTPAuthority
& auth
// Authorisation for the resource.
1848
);
1849
PHTTPTailFile
(
1850
const
PURL
& url,
// Name of the resource in URL space.
1851
const
PFilePath
& file,
// Location of file in file system.
1852
const
PString
& contentType,
// MIME content type for the file.
1853
const
PHTTPAuthority
& auth
// Authorisation for the resource.
1854
);
1855
1856
1857
// Overrides from class PHTTPResource
1865
virtual
PBoolean
LoadHeaders
(
1866
PHTTPRequest
& request
// Information on this request.
1867
);
1868
1874
virtual
PBoolean
LoadData
(
1875
PHTTPRequest
& request,
// Information on this request.
1876
PCharArray
& data
// Data used in reply.
1877
);
1878
};
1879
1880
1882
// PHTTPDirectory
1883
1896
class
PHTTPDirectory
:
public
PHTTPFile
1897
{
1898
PCLASSINFO
(
PHTTPDirectory
,
PHTTPFile
)
1899
1900
public
:
1901
PHTTPDirectory
(
1902
const
PURL
& url,
1903
const
PDirectory
& dir
1904
);
1905
PHTTPDirectory
(
1906
const
PURL
& url,
1907
const
PDirectory
& dir,
1908
const
PHTTPAuthority
& auth
1909
);
1910
// Construct a new directory resource for HTTP.
1911
1912
1913
// Overrides from class PHTTPResource
1919
virtual
PHTTPRequest
*
CreateRequest
(
1920
const
PURL
& url,
// Universal Resource Locator for document.
1921
const
PMIMEInfo
& inMIME,
// Extra MIME information in command.
1922
const
PMultiPartList
& multipartFormInfo,
1923
PHTTPServer
& socket
1924
);
1925
1933
virtual
PBoolean
LoadHeaders
(
1934
PHTTPRequest
& request
1935
);
1936
1945
virtual
PString
LoadText
(
1946
PHTTPRequest
& request
1947
);
1948
1957
void
EnableAuthorisation
(
const
PString
& realm);
1958
1961
void
AllowDirectories
(
PBoolean
enable =
true
);
1962
1963
protected
:
1964
PBoolean
CheckAuthority
(
1965
PHTTPServer
& server,
// Server to send response to.
1966
const
PHTTPRequest
& request,
// Information on this request.
1967
const
PHTTPConnectionInfo
& conInfo
// Information on the connection
1968
);
1969
1970
PBoolean
FindAuthorisations
(
const
PDirectory
& dir,
PString
& realm,
PStringToString
& authorisations);
1971
1972
PDirectory
basePath
;
1973
PString
authorisationRealm
;
1974
PBoolean
allowDirectoryListing
;
1975
};
1976
1977
1978
class
PHTTPDirRequest
:
public
PHTTPFileRequest
1979
{
1980
PCLASSINFO
(
PHTTPDirRequest
,
PHTTPFileRequest
)
1981
public
:
1982
PHTTPDirRequest
(
1983
const
PURL
& url,
// Universal Resource Locator for document.
1984
const
PMIMEInfo
&
inMIME
,
// Extra MIME information in command.
1985
const
PMultiPartList
&
multipartFormInfo
,
1986
PHTTPResource
* resource,
1987
PHTTPServer
&
server
1988
);
1989
1990
PString
fakeIndex
;
1991
PFilePath
realPath
;
1992
};
1993
1994
1995
#endif // P_HTTP
1996
1997
#endif // PTLIB_HTTP_H
1998
1999
2000
// End Of File ///////////////////////////////////////////////////////////////
include
ptclib
http.h
Generated on Mon Feb 17 2014 13:12:51 for PTLib by
1.8.3.1