00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
#ifndef _PHTTPFORM
00083
#define _PHTTPFORM
00084
00085
#ifdef P_USE_PRAGMA
00086
#pragma interface
00087
#endif
00088
00089
#include <ptclib/http.h>
00090
00091
00093
00094
00098 class PHTTPField :
public PObject
00099 {
00100
PCLASSINFO(
PHTTPField,
PObject)
00101
public:
00102
PHTTPField(
00103
const char * bname,
00104
const char *
title,
00105
const char *
help
00106 );
00107
00108
00114
virtual Comparison
Compare(
00115
const PObject & obj
00116 )
const;
00117
00123 const PCaselessString &
GetName()
const {
return fullName; }
00124
00130 const PCaselessString &
GetBaseName()
const {
return baseName; }
00131
00134
virtual void SetName(
00135
const PString & newName
00136 );
00137
00143
virtual const PHTTPField * LocateName(
00144
const PString & name
00145 )
const;
00146
00152 const PString &
GetTitle()
const {
return title; }
00153
00159 const PString &
GetHelp()
const {
return help; }
00160
00161 void SetHelp(
00162
const PString & text
00163 ) { help = text; }
00164
void SetHelp(
00165
const PString & hotLinkURL,
00166
const PString & linkText
00167 );
00168
void SetHelp(
00169
const PString & hotLinkURL,
00170
const PString & imageURL,
00171
const PString & imageText
00172 );
00173
00174
00180
virtual PHTTPField *
NewField() const = 0;
00181
00182 virtual
void ExpandFieldNames(
PString & text, PINDEX start, PINDEX & finish) const;
00183
00184
00187 virtual
void GetHTMLTag(
00188
PHTML & html
00189 ) const = 0;
00190
00193 virtual
PString GetHTMLInput(
00194 const
PString & input
00195 ) const;
00196
00199 virtual
PString GetHTMLSelect(
00200 const
PString & selection
00201 ) const;
00202
00205 virtual
void GetHTMLHeading(
00206
PHTML & html
00207 ) const;
00208
00214 virtual
PString GetValue(BOOL dflt = FALSE) const = 0;
00215
00218 virtual
void SetValue(
00219 const
PString & newValue
00220 ) = 0;
00221
00225 virtual
void LoadFromConfig(
00226
PConfig & cfg
00227 );
00228
00232 virtual
void SaveToConfig(
00233
PConfig & cfg
00234 ) const;
00235
00241 virtual BOOL Validated(
00242 const
PString & newVal,
00243
PStringStream & msg
00244 ) const;
00245
00246
00252 virtual
void GetAllNames(
PStringList & list) const;
00253
00256 virtual
void SetAllValues(
00257 const
PStringToString & data
00258 );
00259
00265 virtual BOOL ValidateAll(
00266 const
PStringToString & data,
00267
PStringStream & msg
00268 ) const;
00269
00270
00271 BOOL NotYetInHTML()
const {
return notInHTML; }
00272 void SetInHTML() {
notInHTML = FALSE; }
00273
00274
protected:
00275 PCaselessString baseName;
00276 PCaselessString fullName;
00277 PString title;
00278 PString help;
00279 BOOL
notInHTML;
00280 };
00281
00282
00283
PLIST(PHTTPFieldList,
PHTTPField);
00284
00285 class PHTTPCompositeField :
public PHTTPField
00286 {
00287
PCLASSINFO(
PHTTPCompositeField,
PHTTPField)
00288
public:
00289
PHTTPCompositeField(
00290
const char * name,
00291
const char * title = NULL,
00292
const char * help = NULL
00293 );
00294
00295
virtual void SetName(
00296
const PString & name
00297 );
00298
00299
virtual const PHTTPField *
LocateName(
00300
const PString & name
00301 )
const;
00302
00303
virtual PHTTPField *
NewField()
const;
00304
00305
virtual void ExpandFieldNames(
PString & text, PINDEX start, PINDEX & finish)
const;
00306
00307
virtual void GetHTMLTag(
00308
PHTML & html
00309 )
const;
00310
00311
virtual PString GetHTMLInput(
00312
const PString & input
00313 )
const;
00314
00315
virtual void GetHTMLHeading(
00316
PHTML & html
00317 )
const;
00318
00319
virtual PString GetValue(BOOL dflt = FALSE)
const;
00320
00321
virtual void SetValue(
00322
const PString & newValue
00323 );
00324
00325
virtual void LoadFromConfig(
00326
PConfig & cfg
00327 );
00328
virtual void SaveToConfig(
00329
PConfig & cfg
00330 )
const;
00331
00332
virtual void GetAllNames(
PStringList & list)
const;
00333
virtual void SetAllValues(
00334
const PStringToString & data
00335 );
00336
00337
virtual BOOL
ValidateAll(
00338
const PStringToString & data,
00339
PStringStream & msg
00340 )
const;
00341
00342
00350
virtual PINDEX
GetSize()
const;
00351
00352
void Append(
PHTTPField * fld);
00353 PHTTPField &
operator[](PINDEX idx)
const {
return fields[idx]; }
00354 void RemoveAt(PINDEX idx) {
fields.RemoveAt(idx); }
00355 void RemoveAll() {
fields.RemoveAll(); }
00356
00357
protected:
00358 PHTTPFieldList
fields;
00359 };
00360
00361
00362 class PHTTPSubForm :
public PHTTPCompositeField
00363 {
00364
PCLASSINFO(
PHTTPSubForm,
PHTTPCompositeField)
00365
public:
00366
PHTTPSubForm(
00367
const PString &
subFormName,
00368
const char * name,
00369
const char * title = NULL,
00370 PINDEX primaryField = 0,
00371 PINDEX secondaryField = P_MAX_INDEX
00372 );
00373
00374
PHTTPField *
NewField()
const;
00375
void GetHTMLTag(
PHTML & html)
const;
00376
void GetHTMLHeading(
PHTML & html)
const;
00377
00378
protected:
00379 PString subFormName;
00380 PINDEX
primary;
00381 PINDEX
secondary;
00382 };
00383
00384
00385 class PHTTPFieldArray :
public PHTTPCompositeField
00386 {
00387
PCLASSINFO(
PHTTPFieldArray,
PHTTPCompositeField)
00388
public:
00389
PHTTPFieldArray(
00390
PHTTPField *
baseField,
00391 BOOL ordered,
00392 PINDEX fixedSize = 0
00393 );
00394
00395
~PHTTPFieldArray();
00396
00397
00398
virtual PHTTPField *
NewField()
const;
00399
00400
virtual void ExpandFieldNames(
PString & text, PINDEX start, PINDEX & finish)
const;
00401
00402
virtual void GetHTMLTag(
00403
PHTML & html
00404 )
const;
00405
00406
virtual void LoadFromConfig(
00407
PConfig & cfg
00408 );
00409
virtual void SaveToConfig(
00410
PConfig & cfg
00411 )
const;
00412
00413
00414
virtual void SetAllValues(
00415
const PStringToString & data
00416 );
00417
00418
virtual PINDEX
GetSize()
const;
00419
void SetSize(PINDEX newSize);
00420
00421
PStringArray GetStrings(
00422
PConfig & cfg
00423 );
00424
00425
void SetStrings(
00426
PConfig & cfg,
00427
const PStringArray & values
00428 );
00429
00430
protected:
00431
void AddBlankField();
00432
void AddArrayControlBox(
PHTML & html, PINDEX fld)
const;
00433
void SetArrayFieldName(PINDEX idx)
const;
00434
00435 PHTTPField * baseField;
00436 BOOL
orderedArray;
00437 BOOL
canAddElements;
00438 };
00439
00440
00441 class PHTTPStringField :
public PHTTPField
00442 {
00443
PCLASSINFO(
PHTTPStringField,
PHTTPField)
00444
public:
00445
PHTTPStringField(
00446
const char * name,
00447 PINDEX
size,
00448
const char * initVal = NULL,
00449
const char * help = NULL
00450 );
00451
PHTTPStringField(
00452
const char * name,
00453
const char * title,
00454 PINDEX size,
00455
const char * initVal = NULL,
00456
const char * help = NULL
00457 );
00458
00459
virtual PHTTPField *
NewField()
const;
00460
00461
virtual void GetHTMLTag(
00462
PHTML & html
00463 )
const;
00464
00465
virtual PString GetValue(BOOL dflt = FALSE)
const;
00466
00467
virtual void SetValue(
00468
const PString & newVal
00469 );
00470
00471
00472
protected:
00473 PString value;
00474 PString initialValue;
00475 PINDEX size;
00476 };
00477
00478
00479 class PHTTPPasswordField :
public PHTTPStringField
00480 {
00481
PCLASSINFO(
PHTTPPasswordField,
PHTTPStringField)
00482
public:
00483
PHTTPPasswordField(
00484
const char * name,
00485 PINDEX size,
00486
const char * initVal = NULL,
00487
const char * help = NULL
00488 );
00489
PHTTPPasswordField(
00490
const char * name,
00491
const char * title,
00492 PINDEX size,
00493
const char * initVal = NULL,
00494
const char * help = NULL
00495 );
00496
00497
virtual PHTTPField *
NewField()
const;
00498
00499
virtual void GetHTMLTag(
00500
PHTML & html
00501 )
const;
00502
00503
virtual PString GetValue(BOOL dflt = FALSE)
const;
00504
00505
virtual void SetValue(
00506
const PString & newVal
00507 );
00508
00509
static PString Decrypt(
const PString & pword);
00510 };
00511
00512
00513 class PHTTPIntegerField :
public PHTTPField
00514 {
00515
PCLASSINFO(
PHTTPIntegerField,
PHTTPField)
00516
public:
00517
PHTTPIntegerField(
00518
const char * name,
00519
int low,
int high,
00520
int initVal = 0,
00521
const char *
units = NULL,
00522
const char * help = NULL
00523 );
00524
PHTTPIntegerField(
00525
const char * name,
00526
const char * title,
00527
int low,
int high,
00528
int initVal = 0,
00529
const char *
units = NULL,
00530
const char * help = NULL
00531 );
00532
00533
virtual PHTTPField *
NewField()
const;
00534
00535
virtual void GetHTMLTag(
00536
PHTML & html
00537 )
const;
00538
00539
virtual PString GetValue(BOOL dflt = FALSE)
const;
00540
00541
virtual void SetValue(
00542
const PString & newVal
00543 );
00544
00545
virtual void LoadFromConfig(
00546
PConfig & cfg
00547 );
00548
virtual void SaveToConfig(
00549
PConfig & cfg
00550 )
const;
00551
00552
virtual BOOL
Validated(
00553
const PString & newVal,
00554
PStringStream & msg
00555 )
const;
00556
00557
00558
protected:
00559 int low, high,
value;
00560 int initialValue;
00561 PString units;
00562 };
00563
00564
00565 class PHTTPBooleanField :
public PHTTPField
00566 {
00567
PCLASSINFO(
PHTTPBooleanField,
PHTTPField)
00568
public:
00569
PHTTPBooleanField(
00570
const char * name,
00571 BOOL initVal = FALSE,
00572
const char * help = NULL
00573 );
00574
PHTTPBooleanField(
00575
const char * name,
00576
const char * title,
00577 BOOL initVal = FALSE,
00578
const char * help = NULL
00579 );
00580
00581
virtual PHTTPField *
NewField()
const;
00582
00583
virtual void GetHTMLTag(
00584
PHTML & html
00585 )
const;
00586
00587
virtual PString GetHTMLInput(
00588
const PString & input
00589 )
const;
00590
00591
virtual PString GetValue(BOOL dflt = FALSE)
const;
00592
00593
virtual void SetValue(
00594
const PString & newVal
00595 );
00596
00597
virtual void LoadFromConfig(
00598
PConfig & cfg
00599 );
00600
virtual void SaveToConfig(
00601
PConfig & cfg
00602 )
const;
00603
00604
00605
protected:
00606 BOOL
value,
initialValue;
00607 };
00608
00609
00610 class PHTTPRadioField :
public PHTTPField
00611 {
00612
PCLASSINFO(
PHTTPRadioField,
PHTTPField)
00613
public:
00614
PHTTPRadioField(
00615
const char * name,
00616
const PStringArray & valueArray,
00617 PINDEX initVal = 0,
00618
const char * help = NULL
00619 );
00620
PHTTPRadioField(
00621
const char * name,
00622
const PStringArray & valueArray,
00623
const PStringArray & titleArray,
00624 PINDEX initVal = 0,
00625
const char * help = NULL
00626 );
00627
PHTTPRadioField(
00628
const char * name,
00629 PINDEX count,
00630
const char *
const * valueStrings,
00631 PINDEX initVal = 0,
00632
const char * help = NULL
00633 );
00634
PHTTPRadioField(
00635
const char * name,
00636 PINDEX count,
00637
const char *
const * valueStrings,
00638
const char *
const * titleStrings,
00639 PINDEX initVal = 0,
00640
const char * help = NULL
00641 );
00642
PHTTPRadioField(
00643
const char * name,
00644
const char * groupTitle,
00645
const PStringArray & valueArray,
00646 PINDEX initVal = 0,
00647
const char * help = NULL
00648 );
00649
PHTTPRadioField(
00650
const char * name,
00651
const char * groupTitle,
00652
const PStringArray & valueArray,
00653
const PStringArray & titleArray,
00654 PINDEX initVal = 0,
00655
const char * help = NULL
00656 );
00657
PHTTPRadioField(
00658
const char * name,
00659
const char * groupTitle,
00660 PINDEX count,
00661
const char *
const * valueStrings,
00662 PINDEX initVal = 0,
00663
const char * help = NULL
00664 );
00665
PHTTPRadioField(
00666
const char * name,
00667
const char * groupTitle,
00668 PINDEX count,
00669
const char *
const * valueStrings,
00670
const char *
const * titleStrings,
00671 PINDEX initVal = 0,
00672
const char * help = NULL
00673 );
00674
00675
virtual PHTTPField *
NewField()
const;
00676
00677
virtual void GetHTMLTag(
00678
PHTML & html
00679 )
const;
00680
00681
virtual PString GetHTMLInput(
00682
const PString & input
00683 )
const;
00684
00685
virtual PString GetValue(BOOL dflt = FALSE)
const;
00686
00687
virtual void SetValue(
00688
const PString & newVal
00689 );
00690
00691
00692
protected:
00693 PStringArray values;
00694 PStringArray titles;
00695 PString value;
00696 PString initialValue;
00697 };
00698
00699
00700 class PHTTPSelectField :
public PHTTPField
00701 {
00702
PCLASSINFO(
PHTTPSelectField,
PHTTPField)
00703
public:
00704
PHTTPSelectField(
00705
const char * name,
00706
const PStringArray & valueArray,
00707 PINDEX initVal = 0,
00708
const char * help = NULL
00709 );
00710
PHTTPSelectField(
00711
const char * name,
00712 PINDEX count,
00713
const char *
const * valueStrings,
00714 PINDEX initVal = 0,
00715
const char * help = NULL
00716 );
00717
PHTTPSelectField(
00718
const char * name,
00719
const char * title,
00720
const PStringArray & valueArray,
00721 PINDEX initVal = 0,
00722
const char * help = NULL
00723 );
00724
PHTTPSelectField(
00725
const char * name,
00726
const char * title,
00727 PINDEX count,
00728
const char *
const * valueStrings,
00729 PINDEX initVal = 0,
00730
const char * help = NULL
00731 );
00732
00733
virtual PHTTPField *
NewField()
const;
00734
00735
virtual void GetHTMLTag(
00736
PHTML & html
00737 )
const;
00738
00739
virtual PString GetValue(BOOL dflt = FALSE)
const;
00740
00741
virtual void SetValue(
00742
const PString & newVal
00743 );
00744
00745
00746 PStringArray values;
00747
00748
00749
protected:
00750 PString value;
00751 PINDEX
initialValue;
00752 };
00753
00754
00756
00757
00758 class PHTTPForm :
public PHTTPString
00759 {
00760
PCLASSINFO(
PHTTPForm,
PHTTPString)
00761
public:
00762
PHTTPForm(
00763
const PURL & url
00764 );
00765
PHTTPForm(
00766
const PURL & url,
00767
const PHTTPAuthority & auth
00768 );
00769
PHTTPForm(
00770
const PURL & url,
00771
const PString & html
00772 );
00773
PHTTPForm(
00774
const PURL & url,
00775
const PString & html,
00776
const PHTTPAuthority & auth
00777 );
00778
00779
00780
virtual void OnLoadedText(
00781
PHTTPRequest & request,
00782
PString & text
00783 );
00784
virtual BOOL
Post(
00785
PHTTPRequest & request,
00786
const PStringToString & data,
00787
PHTML & replyMessage
00788 );
00789
00790
00791
PHTTPField *
Add(
00792
PHTTPField * fld
00793 );
00794 void RemoveAllFields()
00795 {
fields.
RemoveAll();
fieldNames.RemoveAll(); }
00796
00797 enum BuildOptions {
00798
CompleteHTML,
00799
InsertIntoForm,
00800
InsertIntoHTML
00801 };
00802
00803
void BuildHTML(
00804
const char * heading
00805 );
00806
void BuildHTML(
00807
const PString & heading
00808 );
00809
void BuildHTML(
00810
PHTML & html,
00811 BuildOptions option = CompleteHTML
00812 );
00813
00814
00815
protected:
00816 PHTTPCompositeField fields;
00817 PStringSet fieldNames;
00818 };
00819
00820
00822
00823
00824 class PHTTPConfig :
public PHTTPForm
00825 {
00826
PCLASSINFO(
PHTTPConfig,
PHTTPForm)
00827
public:
00828
PHTTPConfig(
00829
const PURL & url,
00830
const PString &
section
00831 );
00832
PHTTPConfig(
00833
const PURL & url,
00834
const PString & section,
00835
const PHTTPAuthority & auth
00836 );
00837
PHTTPConfig(
00838
const PURL & url,
00839
const PString & section,
00840
const PString & html
00841 );
00842
PHTTPConfig(
00843
const PURL & url,
00844
const PString & section,
00845
const PString & html,
00846
const PHTTPAuthority & auth
00847 );
00848
00849
virtual void OnLoadedText(
00850
PHTTPRequest & request,
00851
PString & text
00852 );
00853
virtual BOOL
Post(
00854
PHTTPRequest & request,
00855
const PStringToString & data,
00856
PHTML & replyMessage
00857 );
00858
00859
00862
void LoadFromConfig();
00863
00869 const PString &
GetConfigSection()
const {
return section; }
00870
00871 void SetConfigSection(
00872
const PString & sect
00873 ) { section = sect; }
00874
00875
00880
PHTTPField * AddSectionField(
00881
PHTTPField * sectionFld,
00882
const char * prefix = NULL,
00883
const char * suffix = NULL
00884 );
00885
00889
void AddNewKeyFields(
00890
PHTTPField * keyFld,
00891
PHTTPField * valFld
00892 );
00893
00894
00895
protected:
00896 PString section;
00897 PString sectionPrefix;
00898 PString sectionSuffix;
00899 PHTTPField *
sectionField;
00900 PHTTPField *
keyField;
00901 PHTTPField *
valField;
00902
00903
private:
00904
void Construct();
00905 };
00906
00907
00909
00910
00911 class PHTTPConfigSectionList :
public PHTTPString
00912 {
00913
PCLASSINFO(
PHTTPConfigSectionList,
PHTTPString)
00914
public:
00915
PHTTPConfigSectionList(
00916
const PURL & url,
00917
const PHTTPAuthority & auth,
00918
const PString &
sectionPrefix,
00919
const PString &
additionalValueName,
00920
const PURL & editSection,
00921
const PURL & newSection,
00922
const PString &
newSectionTitle,
00923
PHTML & heading
00924 );
00925
00926
virtual void OnLoadedText(
00927
PHTTPRequest & request,
00928
PString & text
00929 );
00930
virtual BOOL
Post(
00931
PHTTPRequest & request,
00932
const PStringToString & data,
00933
PHTML & replyMessage
00934 );
00935
00936
protected:
00937 PString sectionPrefix;
00938 PString additionalValueName;
00939 PString newSectionLink;
00940 PString newSectionTitle;
00941 PString editSectionLink;
00942 };
00943
00944
00945
#endif
00946
00947
00948