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