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
00083
00084
00085 #ifndef _PHTTPFORM
00086 #define _PHTTPFORM
00087
00088 #ifdef P_USE_PRAGMA
00089 #pragma interface
00090 #endif
00091
00092 #include <ptclib/http.h>
00093 #include <ptclib/html.h>
00094
00095
00097
00098
00102 class PHTTPField : public PObject
00103 {
00104 PCLASSINFO(PHTTPField, PObject)
00105 public:
00106 PHTTPField(
00107 const char * bname,
00108 const char * title,
00109 const char * help
00110 );
00111
00112
00118 virtual Comparison Compare(
00119 const PObject & obj
00120 ) const;
00121
00127 const PCaselessString & GetName() const { return fullName; }
00128
00134 const PCaselessString & GetBaseName() const { return baseName; }
00135
00138 virtual void SetName(
00139 const PString & newName
00140 );
00141
00147 virtual const PHTTPField * LocateName(
00148 const PString & name
00149 ) const;
00150
00156 const PString & GetTitle() const { return title; }
00157
00163 const PString & GetHelp() const { return help; }
00164
00165 void SetHelp(
00166 const PString & text
00167 ) { help = text; }
00168 void SetHelp(
00169 const PString & hotLinkURL,
00170 const PString & linkText
00171 );
00172 void SetHelp(
00173 const PString & hotLinkURL,
00174 const PString & imageURL,
00175 const PString & imageText
00176 );
00177
00178
00184 virtual PHTTPField * NewField() const = 0;
00185
00186 virtual void ExpandFieldNames(PString & text, PINDEX start, PINDEX & finish) const;
00187
00188
00191 virtual void GetHTMLTag(
00192 PHTML & html
00193 ) const = 0;
00194
00197 virtual PString GetHTMLInput(
00198 const PString & input
00199 ) const;
00200
00203 virtual PString GetHTMLSelect(
00204 const PString & selection
00205 ) const;
00206
00209 virtual void GetHTMLHeading(
00210 PHTML & html
00211 ) const;
00212
00218 virtual PString GetValue(BOOL dflt = FALSE) const = 0;
00219
00222 virtual void SetValue(
00223 const PString & newValue
00224 ) = 0;
00225
00229 virtual void LoadFromConfig(
00230 PConfig & cfg
00231 );
00232
00236 virtual void SaveToConfig(
00237 PConfig & cfg
00238 ) const;
00239
00245 virtual BOOL Validated(
00246 const PString & newVal,
00247 PStringStream & msg
00248 ) const;
00249
00250
00256 virtual void GetAllNames(PStringList & list) const;
00257
00260 virtual void SetAllValues(
00261 const PStringToString & data
00262 );
00263
00269 virtual BOOL ValidateAll(
00270 const PStringToString & data,
00271 PStringStream & msg
00272 ) const;
00273
00274
00275 BOOL NotYetInHTML() const { return notInHTML; }
00276 void SetInHTML() { notInHTML = FALSE; }
00277
00278 protected:
00279 PCaselessString baseName;
00280 PCaselessString fullName;
00281 PString title;
00282 PString help;
00283 BOOL notInHTML;
00284 };
00285
00286
00287 PLIST(PHTTPFieldList, PHTTPField);
00288
00289 class PHTTPCompositeField : public PHTTPField
00290 {
00291 PCLASSINFO(PHTTPCompositeField, PHTTPField)
00292 public:
00293 PHTTPCompositeField(
00294 const char * name,
00295 const char * title = NULL,
00296 const char * help = NULL
00297 );
00298
00299 virtual void SetName(
00300 const PString & name
00301 );
00302
00303 virtual const PHTTPField * LocateName(
00304 const PString & name
00305 ) const;
00306
00307 virtual PHTTPField * NewField() const;
00308
00309 virtual void ExpandFieldNames(PString & text, PINDEX start, PINDEX & finish) const;
00310
00311 virtual void GetHTMLTag(
00312 PHTML & html
00313 ) const;
00314
00315 virtual PString GetHTMLInput(
00316 const PString & input
00317 ) const;
00318
00319 virtual void GetHTMLHeading(
00320 PHTML & html
00321 ) const;
00322
00323 virtual PString GetValue(BOOL dflt = FALSE) const;
00324
00325 virtual void SetValue(
00326 const PString & newValue
00327 );
00328
00329 virtual void LoadFromConfig(
00330 PConfig & cfg
00331 );
00332 virtual void SaveToConfig(
00333 PConfig & cfg
00334 ) const;
00335
00336 virtual void GetAllNames(PStringList & list) const;
00337 virtual void SetAllValues(
00338 const PStringToString & data
00339 );
00340
00341 virtual BOOL ValidateAll(
00342 const PStringToString & data,
00343 PStringStream & msg
00344 ) const;
00345
00346
00354 virtual PINDEX GetSize() const;
00355
00356 void Append(PHTTPField * fld);
00357 PHTTPField & operator[](PINDEX idx) const { return fields[idx]; }
00358 void RemoveAt(PINDEX idx) { fields.RemoveAt(idx); }
00359 void RemoveAll() { fields.RemoveAll(); }
00360
00361 protected:
00362 PHTTPFieldList fields;
00363 };
00364
00365
00366 class PHTTPSubForm : public PHTTPCompositeField
00367 {
00368 PCLASSINFO(PHTTPSubForm, PHTTPCompositeField)
00369 public:
00370 PHTTPSubForm(
00371 const PString & subFormName,
00372 const char * name,
00373 const char * title = NULL,
00374 PINDEX primaryField = 0,
00375 PINDEX secondaryField = P_MAX_INDEX
00376 );
00377
00378 PHTTPField * NewField() const;
00379 void GetHTMLTag(PHTML & html) const;
00380 void GetHTMLHeading(PHTML & html) const;
00381
00382 protected:
00383 PString subFormName;
00384 PINDEX primary;
00385 PINDEX secondary;
00386 };
00387
00388
00389 class PHTTPFieldArray : public PHTTPCompositeField
00390 {
00391 PCLASSINFO(PHTTPFieldArray, PHTTPCompositeField)
00392 public:
00393 PHTTPFieldArray(
00394 PHTTPField * baseField,
00395 BOOL ordered,
00396 PINDEX fixedSize = 0
00397 );
00398
00399 ~PHTTPFieldArray();
00400
00401
00402 virtual PHTTPField * NewField() const;
00403
00404 virtual void ExpandFieldNames(PString & text, PINDEX start, PINDEX & finish) const;
00405
00406 virtual void GetHTMLTag(
00407 PHTML & html
00408 ) const;
00409
00410 virtual void LoadFromConfig(
00411 PConfig & cfg
00412 );
00413 virtual void SaveToConfig(
00414 PConfig & cfg
00415 ) const;
00416
00417
00418 virtual void SetAllValues(
00419 const PStringToString & data
00420 );
00421
00422 virtual PINDEX GetSize() const;
00423 void SetSize(PINDEX newSize);
00424
00425 PStringArray GetStrings(
00426 PConfig & cfg
00427 );
00428
00429 void SetStrings(
00430 PConfig & cfg,
00431 const PStringArray & values
00432 );
00433
00434 protected:
00435 void AddBlankField();
00436 void AddArrayControlBox(PHTML & html, PINDEX fld) const;
00437 void SetArrayFieldName(PINDEX idx) const;
00438
00439 PHTTPField * baseField;
00440 BOOL orderedArray;
00441 BOOL canAddElements;
00442 };
00443
00444
00445 class PHTTPStringField : public PHTTPField
00446 {
00447 PCLASSINFO(PHTTPStringField, PHTTPField)
00448 public:
00449 PHTTPStringField(
00450 const char * name,
00451 PINDEX size,
00452 const char * initVal = NULL,
00453 const char * help = NULL
00454 );
00455 PHTTPStringField(
00456 const char * name,
00457 const char * title,
00458 PINDEX size,
00459 const char * initVal = NULL,
00460 const char * help = NULL
00461 );
00462
00463 virtual PHTTPField * NewField() const;
00464
00465 virtual void GetHTMLTag(
00466 PHTML & html
00467 ) const;
00468
00469 virtual PString GetValue(BOOL dflt = FALSE) const;
00470
00471 virtual void SetValue(
00472 const PString & newVal
00473 );
00474
00475
00476 protected:
00477 PString value;
00478 PString initialValue;
00479 PINDEX size;
00480 };
00481
00482
00483 class PHTTPPasswordField : public PHTTPStringField
00484 {
00485 PCLASSINFO(PHTTPPasswordField, PHTTPStringField)
00486 public:
00487 PHTTPPasswordField(
00488 const char * name,
00489 PINDEX size,
00490 const char * initVal = NULL,
00491 const char * help = NULL
00492 );
00493 PHTTPPasswordField(
00494 const char * name,
00495 const char * title,
00496 PINDEX size,
00497 const char * initVal = NULL,
00498 const char * help = NULL
00499 );
00500
00501 virtual PHTTPField * NewField() const;
00502
00503 virtual void GetHTMLTag(
00504 PHTML & html
00505 ) const;
00506
00507 virtual PString GetValue(BOOL dflt = FALSE) const;
00508
00509 virtual void SetValue(
00510 const PString & newVal
00511 );
00512
00513 static PString Decrypt(const PString & pword);
00514 };
00515
00516
00517 class PHTTPIntegerField : public PHTTPField
00518 {
00519 PCLASSINFO(PHTTPIntegerField, PHTTPField)
00520 public:
00521 PHTTPIntegerField(
00522 const char * name,
00523 int low, int high,
00524 int initVal = 0,
00525 const char * units = NULL,
00526 const char * help = NULL
00527 );
00528 PHTTPIntegerField(
00529 const char * name,
00530 const char * title,
00531 int low, int high,
00532 int initVal = 0,
00533 const char * units = NULL,
00534 const char * help = NULL
00535 );
00536
00537 virtual PHTTPField * NewField() const;
00538
00539 virtual void GetHTMLTag(
00540 PHTML & html
00541 ) const;
00542
00543 virtual PString GetValue(BOOL dflt = FALSE) const;
00544
00545 virtual void SetValue(
00546 const PString & newVal
00547 );
00548
00549 virtual void LoadFromConfig(
00550 PConfig & cfg
00551 );
00552 virtual void SaveToConfig(
00553 PConfig & cfg
00554 ) const;
00555
00556 virtual BOOL Validated(
00557 const PString & newVal,
00558 PStringStream & msg
00559 ) const;
00560
00561
00562 protected:
00563 int low, high, value;
00564 int initialValue;
00565 PString units;
00566 };
00567
00568
00569 class PHTTPBooleanField : public PHTTPField
00570 {
00571 PCLASSINFO(PHTTPBooleanField, PHTTPField)
00572 public:
00573 PHTTPBooleanField(
00574 const char * name,
00575 BOOL initVal = FALSE,
00576 const char * help = NULL
00577 );
00578 PHTTPBooleanField(
00579 const char * name,
00580 const char * title,
00581 BOOL initVal = FALSE,
00582 const char * help = NULL
00583 );
00584
00585 virtual PHTTPField * NewField() const;
00586
00587 virtual void GetHTMLTag(
00588 PHTML & html
00589 ) const;
00590
00591 virtual PString GetHTMLInput(
00592 const PString & input
00593 ) const;
00594
00595 virtual PString GetValue(BOOL dflt = FALSE) const;
00596
00597 virtual void SetValue(
00598 const PString & newVal
00599 );
00600
00601 virtual void LoadFromConfig(
00602 PConfig & cfg
00603 );
00604 virtual void SaveToConfig(
00605 PConfig & cfg
00606 ) const;
00607
00608
00609 protected:
00610 BOOL value, initialValue;
00611 };
00612
00613
00614 class PHTTPRadioField : public PHTTPField
00615 {
00616 PCLASSINFO(PHTTPRadioField, PHTTPField)
00617 public:
00618 PHTTPRadioField(
00619 const char * name,
00620 const PStringArray & valueArray,
00621 PINDEX initVal = 0,
00622 const char * help = NULL
00623 );
00624 PHTTPRadioField(
00625 const char * name,
00626 const PStringArray & valueArray,
00627 const PStringArray & titleArray,
00628 PINDEX initVal = 0,
00629 const char * help = NULL
00630 );
00631 PHTTPRadioField(
00632 const char * name,
00633 PINDEX count,
00634 const char * const * valueStrings,
00635 PINDEX initVal = 0,
00636 const char * help = NULL
00637 );
00638 PHTTPRadioField(
00639 const char * name,
00640 PINDEX count,
00641 const char * const * valueStrings,
00642 const char * const * titleStrings,
00643 PINDEX initVal = 0,
00644 const char * help = NULL
00645 );
00646 PHTTPRadioField(
00647 const char * name,
00648 const char * groupTitle,
00649 const PStringArray & valueArray,
00650 PINDEX initVal = 0,
00651 const char * help = NULL
00652 );
00653 PHTTPRadioField(
00654 const char * name,
00655 const char * groupTitle,
00656 const PStringArray & valueArray,
00657 const PStringArray & titleArray,
00658 PINDEX initVal = 0,
00659 const char * help = NULL
00660 );
00661 PHTTPRadioField(
00662 const char * name,
00663 const char * groupTitle,
00664 PINDEX count,
00665 const char * const * valueStrings,
00666 PINDEX initVal = 0,
00667 const char * help = NULL
00668 );
00669 PHTTPRadioField(
00670 const char * name,
00671 const char * groupTitle,
00672 PINDEX count,
00673 const char * const * valueStrings,
00674 const char * const * titleStrings,
00675 PINDEX initVal = 0,
00676 const char * help = NULL
00677 );
00678
00679 virtual PHTTPField * NewField() const;
00680
00681 virtual void GetHTMLTag(
00682 PHTML & html
00683 ) const;
00684
00685 virtual PString GetHTMLInput(
00686 const PString & input
00687 ) const;
00688
00689 virtual PString GetValue(BOOL dflt = FALSE) const;
00690
00691 virtual void SetValue(
00692 const PString & newVal
00693 );
00694
00695
00696 protected:
00697 PStringArray values;
00698 PStringArray titles;
00699 PString value;
00700 PString initialValue;
00701 };
00702
00703
00704 class PHTTPSelectField : public PHTTPField
00705 {
00706 PCLASSINFO(PHTTPSelectField, PHTTPField)
00707 public:
00708 PHTTPSelectField(
00709 const char * name,
00710 const PStringArray & valueArray,
00711 PINDEX initVal = 0,
00712 const char * help = NULL
00713 );
00714 PHTTPSelectField(
00715 const char * name,
00716 PINDEX count,
00717 const char * const * valueStrings,
00718 PINDEX initVal = 0,
00719 const char * help = NULL
00720 );
00721 PHTTPSelectField(
00722 const char * name,
00723 const char * title,
00724 const PStringArray & valueArray,
00725 PINDEX initVal = 0,
00726 const char * help = NULL
00727 );
00728 PHTTPSelectField(
00729 const char * name,
00730 const char * title,
00731 PINDEX count,
00732 const char * const * valueStrings,
00733 PINDEX initVal = 0,
00734 const char * help = NULL
00735 );
00736
00737 virtual PHTTPField * NewField() const;
00738
00739 virtual void GetHTMLTag(
00740 PHTML & html
00741 ) const;
00742
00743 virtual PString GetValue(BOOL dflt = FALSE) const;
00744
00745 virtual void SetValue(
00746 const PString & newVal
00747 );
00748
00749
00750 PStringArray values;
00751
00752
00753 protected:
00754 PString value;
00755 PINDEX initialValue;
00756 };
00757
00758
00760
00761
00762 class PHTTPForm : public PHTTPString
00763 {
00764 PCLASSINFO(PHTTPForm, PHTTPString)
00765 public:
00766 PHTTPForm(
00767 const PURL & url
00768 );
00769 PHTTPForm(
00770 const PURL & url,
00771 const PHTTPAuthority & auth
00772 );
00773 PHTTPForm(
00774 const PURL & url,
00775 const PString & html
00776 );
00777 PHTTPForm(
00778 const PURL & url,
00779 const PString & html,
00780 const PHTTPAuthority & auth
00781 );
00782
00783
00784 virtual void OnLoadedText(
00785 PHTTPRequest & request,
00786 PString & text
00787 );
00788 virtual BOOL Post(
00789 PHTTPRequest & request,
00790 const PStringToString & data,
00791 PHTML & replyMessage
00792 );
00793
00794
00795 PHTTPField * Add(
00796 PHTTPField * fld
00797 );
00798 void RemoveAllFields()
00799 { fields.RemoveAll(); fieldNames.RemoveAll(); }
00800
00801 enum BuildOptions {
00802 CompleteHTML,
00803 InsertIntoForm,
00804 InsertIntoHTML
00805 };
00806
00807 void BuildHTML(
00808 const char * heading
00809 );
00810 void BuildHTML(
00811 const PString & heading
00812 );
00813 void BuildHTML(
00814 PHTML & html,
00815 BuildOptions option = CompleteHTML
00816 );
00817
00818
00819 protected:
00820 PHTTPCompositeField fields;
00821 PStringSet fieldNames;
00822 };
00823
00824
00826
00827
00828 class PHTTPConfig : public PHTTPForm
00829 {
00830 PCLASSINFO(PHTTPConfig, PHTTPForm)
00831 public:
00832 PHTTPConfig(
00833 const PURL & url,
00834 const PString & section
00835 );
00836 PHTTPConfig(
00837 const PURL & url,
00838 const PString & section,
00839 const PHTTPAuthority & auth
00840 );
00841 PHTTPConfig(
00842 const PURL & url,
00843 const PString & section,
00844 const PString & html
00845 );
00846 PHTTPConfig(
00847 const PURL & url,
00848 const PString & section,
00849 const PString & html,
00850 const PHTTPAuthority & auth
00851 );
00852
00853 virtual void OnLoadedText(
00854 PHTTPRequest & request,
00855 PString & text
00856 );
00857 virtual BOOL Post(
00858 PHTTPRequest & request,
00859 const PStringToString & data,
00860 PHTML & replyMessage
00861 );
00862
00863
00866 void LoadFromConfig();
00867
00873 const PString & GetConfigSection() const { return section; }
00874
00875 void SetConfigSection(
00876 const PString & sect
00877 ) { section = sect; }
00878
00879
00884 PHTTPField * AddSectionField(
00885 PHTTPField * sectionFld,
00886 const char * prefix = NULL,
00887 const char * suffix = NULL
00888 );
00889
00893 void AddNewKeyFields(
00894 PHTTPField * keyFld,
00895 PHTTPField * valFld
00896 );
00897
00898
00899 protected:
00900 PString section;
00901 PString sectionPrefix;
00902 PString sectionSuffix;
00903 PHTTPField * sectionField;
00904 PHTTPField * keyField;
00905 PHTTPField * valField;
00906
00907 private:
00908 void Construct();
00909 };
00910
00911
00913
00914
00915 class PHTTPConfigSectionList : public PHTTPString
00916 {
00917 PCLASSINFO(PHTTPConfigSectionList, PHTTPString)
00918 public:
00919 PHTTPConfigSectionList(
00920 const PURL & url,
00921 const PHTTPAuthority & auth,
00922 const PString & sectionPrefix,
00923 const PString & additionalValueName,
00924 const PURL & editSection,
00925 const PURL & newSection,
00926 const PString & newSectionTitle,
00927 PHTML & heading
00928 );
00929
00930 virtual void OnLoadedText(
00931 PHTTPRequest & request,
00932 PString & text
00933 );
00934 virtual BOOL Post(
00935 PHTTPRequest & request,
00936 const PStringToString & data,
00937 PHTML & replyMessage
00938 );
00939
00940 protected:
00941 PString sectionPrefix;
00942 PString additionalValueName;
00943 PString newSectionLink;
00944 PString newSectionTitle;
00945 PString editSectionLink;
00946 };
00947
00948
00949 #endif
00950
00951
00952