PTLib
Version 2.10.10
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
httpsvc.h
Go to the documentation of this file.
1
/*
2
* httpsvc.h
3
*
4
* Common classes for service applications using HTTP as the user interface.
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: 24177 $
27
* $Author: rjongbloed $
28
* $Date: 2010-04-05 06:52:04 -0500 (Mon, 05 Apr 2010) $
29
*/
30
31
#ifndef PTLIB_HTTPSVC_H
32
#define PTLIB_HTTPSVC_H
33
34
#include <
ptlib/svcproc.h
>
35
#include <
ptlib/sockets.h
>
36
#include <
ptclib/httpform.h
>
37
#include <
ptclib/cypher.h
>
38
39
40
class
PHTTPServiceProcess
;
41
42
44
45
class
PHTTPServiceThread
:
public
PThread
46
{
47
PCLASSINFO
(
PHTTPServiceThread
,
PThread
)
48
public
:
49
PHTTPServiceThread
(PINDEX stackSize,
50
PHTTPServiceProcess
& app);
51
~PHTTPServiceThread
();
52
53
void
Main
();
54
void
Close
();
55
56
protected
:
57
PINDEX
myStackSize
;
58
PHTTPServiceProcess
&
process
;
59
PTCPSocket
*
socket
;
60
};
61
62
64
65
class
PHTTPServiceProcess
:
public
PServiceProcess
66
{
67
PCLASSINFO
(
PHTTPServiceProcess
,
PServiceProcess
)
68
69
public
:
70
enum
{
71
MaxSecuredKeys
= 10
72
};
73
struct
Info
{
74
const
char
*
productName
;
75
const
char
*
manufacturerName
;
76
77
WORD
majorVersion
;
78
WORD
minorVersion
;
79
CodeStatus
buildStatus
;
80
WORD
buildNumber
;
81
const
char
*
compilationDate
;
82
83
PTEACypher::Key
productKey
;
84
const
char
*
securedKeys
[
MaxSecuredKeys
];
85
PINDEX
securedKeyCount
;
86
87
PTEACypher::Key
signatureKey
;
88
89
const
char
*
manufHomePage
;
90
const
char
*
email
;
91
const
char
*
productHTML
;
92
93
const
char
*
gifHTML
;
94
95
const
char
*
gifFilename
;
96
int
gifWidth
;
97
int
gifHeight
;
98
99
const
char
*
copyrightHolder
;
100
const
char
*
copyrightHomePage
;
101
const
char
*
copyrightEmail
;
102
};
103
104
PHTTPServiceProcess
(
const
Info
& inf);
105
~PHTTPServiceProcess
();
106
107
PBoolean
OnStart
();
108
void
OnStop
();
109
PBoolean
OnPause
();
110
void
OnContinue
();
111
const
char
*
GetServiceDependencies
()
const
;
112
113
virtual
void
OnConfigChanged
() = 0;
114
virtual
PBoolean
Initialise
(
const
char
* initMsg) = 0;
115
116
PBoolean
ListenForHTTP
(
117
WORD port,
118
PSocket::Reusability
reuse =
PSocket::CanReuseAddress
,
119
PINDEX stackSize = 0x4000
120
);
121
PBoolean
ListenForHTTP
(
122
PSocket
* listener,
123
PSocket::Reusability
reuse =
PSocket::CanReuseAddress
,
124
PINDEX stackSize = 0x4000
125
);
126
127
virtual
PString
GetPageGraphic
();
128
void
GetPageHeader
(
PHTML
&);
129
void
GetPageHeader
(
PHTML
&,
const
PString
& title);
130
131
virtual
PString
GetCopyrightText
();
132
133
const
PString
&
GetMacroKeyword
()
const
{
return
macroKeyword
; }
134
const
PTime
&
GetCompilationDate
()
const
{
return
compilationDate
; }
135
const
PString
&
GetHomePage
()
const
{
return
manufacturersHomePage
; }
136
const
PString
&
GetEMailAddress
()
const
{
return
manufacturersEmail
; }
137
const
PString
&
GetProductName
()
const
{
return
productNameHTML
; }
138
const
PTEACypher::Key
&
GetProductKey
()
const
{
return
productKey
; }
139
const
PStringArray
&
GetSecuredKeys
()
const
{
return
securedKeys
; }
140
const
PTEACypher::Key
&
GetSignatureKey
()
const
{
return
signatureKey
; }
141
PBoolean
ShouldIgnoreSignatures
()
const
{
return
ignoreSignatures
; }
142
void
SetIgnoreSignatures
(
PBoolean
ig) {
ignoreSignatures
= ig; }
143
144
static
PHTTPServiceProcess
&
Current
();
145
146
virtual
void
AddRegisteredText
(
PHTML
& html);
147
virtual
void
AddUnregisteredText
(
PHTML
& html);
148
virtual
PBoolean
SubstituteEquivalSequence
(
PHTTPRequest
& request,
const
PString
&,
PString
&);
149
virtual
PHTTPServer
*
CreateHTTPServer
(
PTCPSocket
& socket);
150
virtual
PHTTPServer
*
OnCreateHTTPServer
(
const
PHTTPSpace
& urlSpace);
151
PTCPSocket
*
AcceptHTTP
();
152
PBoolean
ProcessHTTP
(
PTCPSocket
& socket);
153
154
protected
:
155
PSocket
*
httpListeningSocket
;
156
PHTTPSpace
httpNameSpace
;
157
PString
macroKeyword
;
158
159
PTEACypher::Key
productKey
;
160
PStringArray
securedKeys
;
161
PTEACypher::Key
signatureKey
;
162
PBoolean
ignoreSignatures
;
163
164
PTime
compilationDate
;
165
PString
manufacturersHomePage
;
166
PString
manufacturersEmail
;
167
PString
productNameHTML
;
168
PString
gifHTML
;
169
PString
copyrightHolder
;
170
PString
copyrightHomePage
;
171
PString
copyrightEmail
;
172
173
void
ShutdownListener
();
174
void
BeginRestartSystem
();
175
void
CompleteRestartSystem
();
176
177
PThread
*
restartThread
;
178
179
PLIST
(ThreadList,
PHTTPServiceThread
);
180
ThreadList
httpThreads
;
181
PMutex
httpThreadsMutex
;
182
183
friend
class
PConfigPage
;
184
friend
class
PConfigSectionsPage
;
185
friend
class
PHTTPServiceThread
;
186
};
187
188
190
191
class
PConfigPage
:
public
PHTTPConfig
192
{
193
PCLASSINFO
(
PConfigPage
,
PHTTPConfig
)
194
public
:
195
PConfigPage
(
196
PHTTPServiceProcess
& app,
197
const
PString
&
section
,
198
const
PHTTPAuthority
& auth
199
);
200
PConfigPage
(
201
PHTTPServiceProcess
& app,
202
const
PString
& title,
203
const
PString
& section,
204
const
PHTTPAuthority
& auth
205
);
206
207
void
OnLoadedText
(
PHTTPRequest
&,
PString
& text);
208
209
PBoolean
OnPOST
(
210
PHTTPServer
& server,
211
const
PURL
& url,
212
const
PMIMEInfo
& info,
213
const
PStringToString
& data,
214
const
PHTTPConnectionInfo
& connectInfo
215
);
216
217
virtual
PBoolean
Post
(
218
PHTTPRequest
& request,
219
const
PStringToString
& data,
220
PHTML
& replyMessage
221
);
222
223
protected
:
224
virtual
PBoolean
GetExpirationDate
(
225
PTime
& when
226
);
227
228
PHTTPServiceProcess
&
process
;
229
};
230
231
233
234
class
PConfigSectionsPage
:
public
PHTTPConfigSectionList
235
{
236
PCLASSINFO
(
PConfigSectionsPage
,
PHTTPConfigSectionList
)
237
public
:
238
PConfigSectionsPage
(
239
PHTTPServiceProcess
& app,
240
const
PURL
& url,
241
const
PHTTPAuthority
& auth,
242
const
PString
& prefix,
243
const
PString
& valueName,
244
const
PURL
& editSection,
245
const
PURL
& newSection,
246
const
PString
& newTitle,
247
PHTML
& heading
248
);
249
250
void
OnLoadedText
(
PHTTPRequest
&,
PString
& text);
251
252
PBoolean
OnPOST
(
253
PHTTPServer
& server,
254
const
PURL
& url,
255
const
PMIMEInfo
& info,
256
const
PStringToString
& data,
257
const
PHTTPConnectionInfo
& connectInfo
258
);
259
260
virtual
PBoolean
Post
(
261
PHTTPRequest
& request,
262
const
PStringToString
& data,
263
PHTML
& replyMessage
264
);
265
266
protected
:
267
virtual
PBoolean
GetExpirationDate
(
268
PTime
& when
269
);
270
271
PHTTPServiceProcess
&
process
;
272
};
273
274
276
277
class
PRegisterPage
:
public
PConfigPage
278
{
279
PCLASSINFO
(
PRegisterPage
,
PConfigPage
)
280
public
:
281
PRegisterPage
(
282
PHTTPServiceProcess
& app,
283
const
PHTTPAuthority
& auth
284
);
285
286
PString
LoadText
(
287
PHTTPRequest
& request
288
);
289
void
OnLoadedText
(
PHTTPRequest
& request,
PString
& text);
290
291
virtual
PBoolean
Post
(
292
PHTTPRequest
& request,
293
const
PStringToString
& data,
294
PHTML
& replyMessage
295
);
296
297
virtual
void
AddFields
(
298
const
PString
& prefix
299
) = 0;
300
301
protected
:
302
PHTTPServiceProcess
&
process
;
303
};
304
305
307
308
class
PServiceHTML
:
public
PHTML
309
{
310
PCLASSINFO
(
PServiceHTML
,
PHTML
)
311
public
:
312
PServiceHTML
(
const
char
* title,
313
const
char
* help = NULL,
314
const
char
* helpGif =
"help.gif"
);
315
316
PString
ExtractSignature
(
PString
& out);
317
static
PString
ExtractSignature
(
const
PString
& html,
318
PString
& out,
319
const
char
* keyword =
"#equival"
);
320
321
PString
CalculateSignature
();
322
static
PString
CalculateSignature
(
const
PString
& out);
323
static
PString
CalculateSignature
(
const
PString
& out,
const
PTEACypher::Key
& sig);
324
325
PBoolean
CheckSignature
();
326
static
PBoolean
CheckSignature
(
const
PString
& html);
327
328
enum
MacroOptions
{
329
NoOptions
= 0,
330
NeedSignature
= 1,
331
LoadFromFile
= 2,
332
NoURLOverride
= 4,
333
NoSignatureForFile
= 8
334
};
335
static
bool
ProcessMacros
(
336
PHTTPRequest
& request,
337
PString
& text,
338
const
PString
& filename,
339
unsigned
options
340
);
341
static
bool
SpliceMacro
(
342
PString
& text,
343
const
PString
& tokens,
344
const
PString
& value
345
);
346
};
347
348
350
351
class
PServiceMacro
:
public
PObject
352
{
353
public
:
354
PServiceMacro
(
const
char
* name,
PBoolean
isBlock);
355
PServiceMacro
(
const
PCaselessString
& name,
PBoolean
isBlock);
356
Comparison
Compare
(
const
PObject
& obj)
const
;
357
virtual
PString
Translate
(
358
PHTTPRequest
& request,
359
const
PString
& args,
360
const
PString
& block
361
)
const
;
362
protected
:
363
const
char
*
macroName
;
364
PBoolean
isMacroBlock
;
365
PServiceMacro
*
link
;
366
static
PServiceMacro
*
list
;
367
friend
class
PServiceMacros_list
;
368
};
369
370
371
#define P_EMPTY
372
373
#define PCREATE_SERVICE_MACRO(name, request, args) \
374
class PServiceMacro_##name : public PServiceMacro { \
375
public: \
376
PServiceMacro_##name() : PServiceMacro(#name, false) { } \
377
PString Translate(PHTTPRequest &, const PString &, const PString &) const; \
378
}; \
379
static const PServiceMacro_##name serviceMacro_##name; \
380
PString PServiceMacro_##name::Translate(PHTTPRequest & request, const PString & args, const PString &) const
381
382
383
384
#define PCREATE_SERVICE_MACRO_BLOCK(name, request, args, block) \
385
class PServiceMacro_##name : public PServiceMacro { \
386
public: \
387
PServiceMacro_##name() : PServiceMacro(#name, true) { } \
388
PString Translate(PHTTPRequest &, const PString &, const PString &) const; \
389
}; \
390
static const PServiceMacro_##name serviceMacro_##name; \
391
PString PServiceMacro_##name::Translate(PHTTPRequest & request, const PString & args, const PString & block) const
392
393
394
396
397
class
PServiceHTTPString
:
public
PHTTPString
398
{
399
PCLASSINFO
(
PServiceHTTPString
,
PHTTPString
)
400
public
:
401
PServiceHTTPString
(
const
PURL
& url,
const
PString
&
string
)
402
:
PHTTPString
(url, string) { }
403
404
PServiceHTTPString
(
const
PURL
& url,
const
PHTTPAuthority
& auth)
405
:
PHTTPString
(url, auth) { }
406
407
PServiceHTTPString
(
const
PURL
& url,
const
PString
&
string
,
const
PHTTPAuthority
& auth)
408
:
PHTTPString
(url, string, auth) { }
409
410
PServiceHTTPString
(
const
PURL
& url,
const
PString
&
string
,
const
PString
&
contentType
)
411
:
PHTTPString
(url, string, contentType) { }
412
413
PServiceHTTPString
(
const
PURL
& url,
const
PString
&
string
,
const
PString
&
contentType
,
const
PHTTPAuthority
& auth)
414
:
PHTTPString
(url, string, contentType, auth) { }
415
416
PString
LoadText
(
PHTTPRequest
&);
417
418
protected
:
419
virtual
PBoolean
GetExpirationDate
(
420
PTime
& when
421
);
422
};
423
424
425
class
PServiceHTTPFile
:
public
PHTTPFile
426
{
427
PCLASSINFO
(
PServiceHTTPFile
,
PHTTPFile
)
428
public
:
429
PServiceHTTPFile
(
const
PString
& filename,
PBoolean
needSig =
false
)
430
:
PHTTPFile
(filename) {
needSignature
= needSig; }
431
PServiceHTTPFile
(
const
PString
& filename,
const
PFilePath
& file,
PBoolean
needSig =
false
)
432
:
PHTTPFile
(filename, file) {
needSignature
= needSig; }
433
PServiceHTTPFile
(
const
PString
& filename,
const
PString
& file,
PBoolean
needSig =
false
)
434
:
PHTTPFile
(filename, file) {
needSignature
= needSig; }
435
PServiceHTTPFile
(
const
PString
& filename,
const
PHTTPAuthority
& auth,
PBoolean
needSig =
false
)
436
:
PHTTPFile
(filename, auth) {
needSignature
= needSig; }
437
PServiceHTTPFile
(
const
PString
& filename,
const
PFilePath
& file,
const
PHTTPAuthority
& auth,
PBoolean
needSig =
false
)
438
:
PHTTPFile
(filename, file, auth) {
needSignature
= needSig; }
439
440
void
OnLoadedText
(
PHTTPRequest
&,
PString
& text);
441
442
protected
:
443
virtual
PBoolean
GetExpirationDate
(
444
PTime
& when
445
);
446
447
PBoolean
needSignature
;
448
};
449
450
class
PServiceHTTPDirectory
:
public
PHTTPDirectory
451
{
452
PCLASSINFO
(
PServiceHTTPDirectory
,
PHTTPDirectory
)
453
public
:
454
PServiceHTTPDirectory
(
const
PURL
& url,
const
PDirectory
& dirname,
PBoolean
needSig =
false
)
455
:
PHTTPDirectory
(url, dirname) {
needSignature
= needSig; }
456
457
PServiceHTTPDirectory
(
const
PURL
& url,
const
PDirectory
& dirname,
const
PHTTPAuthority
& auth,
PBoolean
needSig =
false
)
458
:
PHTTPDirectory
(url, dirname, auth) {
needSignature
= needSig; }
459
460
void
OnLoadedText
(
PHTTPRequest
&,
PString
& text);
461
462
protected
:
463
virtual
PBoolean
GetExpirationDate
(
464
PTime
& when
465
);
466
467
PBoolean
needSignature
;
468
};
469
470
471
#endif // PTLIB_HTTPSVC_H
472
473
474
// End Of File ///////////////////////////////////////////////////////////////
include
ptclib
httpsvc.h
Generated on Tue May 7 2013 17:25:45 for PTLib by
1.8.3.1