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 #ifndef _PHTTPFORM
00032 #define _PHTTPFORM
00033
00034 #ifdef P_USE_PRAGMA
00035 #pragma interface
00036 #endif
00037
00038 #include <ptclib/http.h>
00039 #include <ptclib/html.h>
00040
00041
00043
00044
00048 class PHTTPField : public PObject
00049 {
00050 PCLASSINFO(PHTTPField, PObject)
00051 public:
00052 PHTTPField(
00053 const char * bname,
00054 const char * title,
00055 const char * help
00056 );
00057
00058
00064 virtual Comparison Compare(
00065 const PObject & obj
00066 ) const;
00067
00073 const PCaselessString & GetName() const { return fullName; }
00074
00080 const PCaselessString & GetBaseName() const { return baseName; }
00081
00084 virtual void SetName(
00085 const PString & newName
00086 );
00087
00093 virtual const PHTTPField * LocateName(
00094 const PString & name
00095 ) const;
00096
00102 const PString & GetTitle() const { return title; }
00103
00109 const PString & GetHelp() const { return help; }
00110
00111 void SetHelp(
00112 const PString & text
00113 ) { help = text; }
00114 void SetHelp(
00115 const PString & hotLinkURL,
00116 const PString & linkText
00117 );
00118 void SetHelp(
00119 const PString & hotLinkURL,
00120 const PString & imageURL,
00121 const PString & imageText
00122 );
00123
00124
00130 virtual PHTTPField * NewField() const = 0;
00131
00132 virtual void ExpandFieldNames(PString & text, PINDEX start, PINDEX & finish) const;
00133
00134
00137 virtual void GetHTMLTag(
00138 PHTML & html
00139 ) const = 0;
00140
00143 virtual PString GetHTMLInput(
00144 const PString & input
00145 ) const;
00146
00149 virtual PString GetHTMLSelect(
00150 const PString & selection
00151 ) const;
00152
00155 virtual void GetHTMLHeading(
00156 PHTML & html
00157 ) const;
00158
00164 virtual PString GetValue(PBoolean dflt = PFalse) const = 0;
00165
00168 virtual void SetValue(
00169 const PString & newValue
00170 ) = 0;
00171
00175 virtual void LoadFromConfig(
00176 PConfig & cfg
00177 );
00178
00182 virtual void SaveToConfig(
00183 PConfig & cfg
00184 ) const;
00185
00191 virtual PBoolean Validated(
00192 const PString & newVal,
00193 PStringStream & msg
00194 ) const;
00195
00196
00202 virtual void GetAllNames(PStringList & list) const;
00203
00206 virtual void SetAllValues(
00207 const PStringToString & data
00208 );
00209
00215 virtual PBoolean ValidateAll(
00216 const PStringToString & data,
00217 PStringStream & msg
00218 ) const;
00219
00220
00221 PBoolean NotYetInHTML() const { return notInHTML; }
00222 void SetInHTML() { notInHTML = PFalse; }
00223
00224 protected:
00225 PCaselessString baseName;
00226 PCaselessString fullName;
00227 PString title;
00228 PString help;
00229 PBoolean notInHTML;
00230 };
00231
00232
00233 PLIST(PHTTPFieldList, PHTTPField);
00234
00235 class PHTTPCompositeField : public PHTTPField
00236 {
00237 PCLASSINFO(PHTTPCompositeField, PHTTPField)
00238 public:
00239 PHTTPCompositeField(
00240 const char * name,
00241 const char * title = NULL,
00242 const char * help = NULL
00243 );
00244
00245 virtual void SetName(
00246 const PString & name
00247 );
00248
00249 virtual const PHTTPField * LocateName(
00250 const PString & name
00251 ) const;
00252
00253 virtual PHTTPField * NewField() const;
00254
00255 virtual void ExpandFieldNames(PString & text, PINDEX start, PINDEX & finish) const;
00256
00257 virtual void GetHTMLTag(
00258 PHTML & html
00259 ) const;
00260
00261 virtual PString GetHTMLInput(
00262 const PString & input
00263 ) const;
00264
00265 virtual void GetHTMLHeading(
00266 PHTML & html
00267 ) const;
00268
00269 virtual PString GetValue(PBoolean dflt = PFalse) const;
00270
00271 virtual void SetValue(
00272 const PString & newValue
00273 );
00274
00275 virtual void LoadFromConfig(
00276 PConfig & cfg
00277 );
00278 virtual void SaveToConfig(
00279 PConfig & cfg
00280 ) const;
00281
00282 virtual void GetAllNames(PStringList & list) const;
00283 virtual void SetAllValues(
00284 const PStringToString & data
00285 );
00286
00287 virtual PBoolean ValidateAll(
00288 const PStringToString & data,
00289 PStringStream & msg
00290 ) const;
00291
00292
00300 virtual PINDEX GetSize() const;
00301
00302 void Append(PHTTPField * fld);
00303 PHTTPField & operator[](PINDEX idx) const { return fields[idx]; }
00304 void RemoveAt(PINDEX idx) { fields.RemoveAt(idx); }
00305 void RemoveAll() { fields.RemoveAll(); }
00306
00307 protected:
00308 PHTTPFieldList fields;
00309 };
00310
00311
00312 class PHTTPSubForm : public PHTTPCompositeField
00313 {
00314 PCLASSINFO(PHTTPSubForm, PHTTPCompositeField)
00315 public:
00316 PHTTPSubForm(
00317 const PString & subFormName,
00318 const char * name,
00319 const char * title = NULL,
00320 PINDEX primaryField = 0,
00321 PINDEX secondaryField = P_MAX_INDEX
00322 );
00323
00324 PHTTPField * NewField() const;
00325 void GetHTMLTag(PHTML & html) const;
00326 void GetHTMLHeading(PHTML & html) const;
00327
00328 protected:
00329 PString subFormName;
00330 PINDEX primary;
00331 PINDEX secondary;
00332 };
00333
00334
00335 class PHTTPFieldArray : public PHTTPCompositeField
00336 {
00337 PCLASSINFO(PHTTPFieldArray, PHTTPCompositeField)
00338 public:
00339 PHTTPFieldArray(
00340 PHTTPField * baseField,
00341 PBoolean ordered,
00342 PINDEX fixedSize = 0
00343 );
00344
00345 ~PHTTPFieldArray();
00346
00347
00348 virtual PHTTPField * NewField() const;
00349
00350 virtual void ExpandFieldNames(PString & text, PINDEX start, PINDEX & finish) const;
00351
00352 virtual void GetHTMLTag(
00353 PHTML & html
00354 ) const;
00355
00356 virtual void LoadFromConfig(
00357 PConfig & cfg
00358 );
00359 virtual void SaveToConfig(
00360 PConfig & cfg
00361 ) const;
00362
00363
00364 virtual void SetAllValues(
00365 const PStringToString & data
00366 );
00367
00368 virtual PINDEX GetSize() const;
00369 void SetSize(PINDEX newSize);
00370
00371 PStringArray GetStrings(
00372 PConfig & cfg
00373 );
00374
00375 void SetStrings(
00376 PConfig & cfg,
00377 const PStringArray & values
00378 );
00379
00380 protected:
00381 void AddBlankField();
00382 void AddArrayControlBox(PHTML & html, PINDEX fld) const;
00383 void SetArrayFieldName(PINDEX idx) const;
00384
00385 PHTTPField * baseField;
00386 PBoolean orderedArray;
00387 PBoolean canAddElements;
00388 };
00389
00390
00391 class PHTTPStringField : public PHTTPField
00392 {
00393 PCLASSINFO(PHTTPStringField, PHTTPField)
00394 public:
00395 PHTTPStringField(
00396 const char * name,
00397 PINDEX size,
00398 const char * initVal = NULL,
00399 const char * help = NULL
00400 );
00401 PHTTPStringField(
00402 const char * name,
00403 const char * title,
00404 PINDEX size,
00405 const char * initVal = NULL,
00406 const char * help = NULL
00407 );
00408
00409 virtual PHTTPField * NewField() const;
00410
00411 virtual void GetHTMLTag(
00412 PHTML & html
00413 ) const;
00414
00415 virtual PString GetValue(PBoolean dflt = PFalse) const;
00416
00417 virtual void SetValue(
00418 const PString & newVal
00419 );
00420
00421
00422 protected:
00423 PString value;
00424 PString initialValue;
00425 PINDEX size;
00426 };
00427
00428
00429 class PHTTPPasswordField : public PHTTPStringField
00430 {
00431 PCLASSINFO(PHTTPPasswordField, PHTTPStringField)
00432 public:
00433 PHTTPPasswordField(
00434 const char * name,
00435 PINDEX size,
00436 const char * initVal = NULL,
00437 const char * help = NULL
00438 );
00439 PHTTPPasswordField(
00440 const char * name,
00441 const char * title,
00442 PINDEX size,
00443 const char * initVal = NULL,
00444 const char * help = NULL
00445 );
00446
00447 virtual PHTTPField * NewField() const;
00448
00449 virtual void GetHTMLTag(
00450 PHTML & html
00451 ) const;
00452
00453 virtual PString GetValue(PBoolean dflt = PFalse) const;
00454
00455 virtual void SetValue(
00456 const PString & newVal
00457 );
00458
00459 static PString Decrypt(const PString & pword);
00460 };
00461
00462
00463 class PHTTPIntegerField : public PHTTPField
00464 {
00465 PCLASSINFO(PHTTPIntegerField, PHTTPField)
00466 public:
00467 PHTTPIntegerField(
00468 const char * name,
00469 int low, int high,
00470 int initVal = 0,
00471 const char * units = NULL,
00472 const char * help = NULL
00473 );
00474 PHTTPIntegerField(
00475 const char * name,
00476 const char * title,
00477 int low, int high,
00478 int initVal = 0,
00479 const char * units = NULL,
00480 const char * help = NULL
00481 );
00482
00483 virtual PHTTPField * NewField() const;
00484
00485 virtual void GetHTMLTag(
00486 PHTML & html
00487 ) const;
00488
00489 virtual PString GetValue(PBoolean dflt = PFalse) const;
00490
00491 virtual void SetValue(
00492 const PString & newVal
00493 );
00494
00495 virtual void LoadFromConfig(
00496 PConfig & cfg
00497 );
00498 virtual void SaveToConfig(
00499 PConfig & cfg
00500 ) const;
00501
00502 virtual PBoolean Validated(
00503 const PString & newVal,
00504 PStringStream & msg
00505 ) const;
00506
00507
00508 protected:
00509 int low, high, value;
00510 int initialValue;
00511 PString units;
00512 };
00513
00514
00515 class PHTTPBooleanField : public PHTTPField
00516 {
00517 PCLASSINFO(PHTTPBooleanField, PHTTPField)
00518 public:
00519 PHTTPBooleanField(
00520 const char * name,
00521 PBoolean initVal = PFalse,
00522 const char * help = NULL
00523 );
00524 PHTTPBooleanField(
00525 const char * name,
00526 const char * title,
00527 PBoolean initVal = PFalse,
00528 const char * help = NULL
00529 );
00530
00531 virtual PHTTPField * NewField() const;
00532
00533 virtual void GetHTMLTag(
00534 PHTML & html
00535 ) const;
00536
00537 virtual PString GetHTMLInput(
00538 const PString & input
00539 ) const;
00540
00541 virtual PString GetValue(PBoolean dflt = PFalse) const;
00542
00543 virtual void SetValue(
00544 const PString & newVal
00545 );
00546
00547 virtual void LoadFromConfig(
00548 PConfig & cfg
00549 );
00550 virtual void SaveToConfig(
00551 PConfig & cfg
00552 ) const;
00553
00554
00555 protected:
00556 PBoolean value, initialValue;
00557 };
00558
00559
00560 class PHTTPRadioField : public PHTTPField
00561 {
00562 PCLASSINFO(PHTTPRadioField, PHTTPField)
00563 public:
00564 PHTTPRadioField(
00565 const char * name,
00566 const PStringArray & valueArray,
00567 PINDEX initVal = 0,
00568 const char * help = NULL
00569 );
00570 PHTTPRadioField(
00571 const char * name,
00572 const PStringArray & valueArray,
00573 const PStringArray & titleArray,
00574 PINDEX initVal = 0,
00575 const char * help = NULL
00576 );
00577 PHTTPRadioField(
00578 const char * name,
00579 PINDEX count,
00580 const char * const * valueStrings,
00581 PINDEX initVal = 0,
00582 const char * help = NULL
00583 );
00584 PHTTPRadioField(
00585 const char * name,
00586 PINDEX count,
00587 const char * const * valueStrings,
00588 const char * const * titleStrings,
00589 PINDEX initVal = 0,
00590 const char * help = NULL
00591 );
00592 PHTTPRadioField(
00593 const char * name,
00594 const char * groupTitle,
00595 const PStringArray & valueArray,
00596 PINDEX initVal = 0,
00597 const char * help = NULL
00598 );
00599 PHTTPRadioField(
00600 const char * name,
00601 const char * groupTitle,
00602 const PStringArray & valueArray,
00603 const PStringArray & titleArray,
00604 PINDEX initVal = 0,
00605 const char * help = NULL
00606 );
00607 PHTTPRadioField(
00608 const char * name,
00609 const char * groupTitle,
00610 PINDEX count,
00611 const char * const * valueStrings,
00612 PINDEX initVal = 0,
00613 const char * help = NULL
00614 );
00615 PHTTPRadioField(
00616 const char * name,
00617 const char * groupTitle,
00618 PINDEX count,
00619 const char * const * valueStrings,
00620 const char * const * titleStrings,
00621 PINDEX initVal = 0,
00622 const char * help = NULL
00623 );
00624
00625 virtual PHTTPField * NewField() const;
00626
00627 virtual void GetHTMLTag(
00628 PHTML & html
00629 ) const;
00630
00631 virtual PString GetHTMLInput(
00632 const PString & input
00633 ) const;
00634
00635 virtual PString GetValue(PBoolean dflt = PFalse) const;
00636
00637 virtual void SetValue(
00638 const PString & newVal
00639 );
00640
00641
00642 protected:
00643 PStringArray values;
00644 PStringArray titles;
00645 PString value;
00646 PString initialValue;
00647 };
00648
00649
00650 class PHTTPSelectField : public PHTTPField
00651 {
00652 PCLASSINFO(PHTTPSelectField, PHTTPField)
00653 public:
00654 PHTTPSelectField(
00655 const char * name,
00656 const PStringArray & valueArray,
00657 PINDEX initVal = 0,
00658 const char * help = NULL
00659 );
00660 PHTTPSelectField(
00661 const char * name,
00662 PINDEX count,
00663 const char * const * valueStrings,
00664 PINDEX initVal = 0,
00665 const char * help = NULL
00666 );
00667 PHTTPSelectField(
00668 const char * name,
00669 const char * title,
00670 const PStringArray & valueArray,
00671 PINDEX initVal = 0,
00672 const char * help = NULL
00673 );
00674 PHTTPSelectField(
00675 const char * name,
00676 const char * title,
00677 PINDEX count,
00678 const char * const * valueStrings,
00679 PINDEX initVal = 0,
00680 const char * help = NULL
00681 );
00682
00683 virtual PHTTPField * NewField() const;
00684
00685 virtual void GetHTMLTag(
00686 PHTML & html
00687 ) const;
00688
00689 virtual PString GetValue(PBoolean dflt = PFalse) const;
00690
00691 virtual void SetValue(
00692 const PString & newVal
00693 );
00694
00695
00696 PStringArray values;
00697
00698
00699 protected:
00700 PString value;
00701 PINDEX initialValue;
00702 };
00703
00704
00706
00707
00708 class PHTTPForm : public PHTTPString
00709 {
00710 PCLASSINFO(PHTTPForm, PHTTPString)
00711 public:
00712 PHTTPForm(
00713 const PURL & url
00714 );
00715 PHTTPForm(
00716 const PURL & url,
00717 const PHTTPAuthority & auth
00718 );
00719 PHTTPForm(
00720 const PURL & url,
00721 const PString & html
00722 );
00723 PHTTPForm(
00724 const PURL & url,
00725 const PString & html,
00726 const PHTTPAuthority & auth
00727 );
00728
00729
00730 virtual void OnLoadedText(
00731 PHTTPRequest & request,
00732 PString & text
00733 );
00734 virtual PBoolean Post(
00735 PHTTPRequest & request,
00736 const PStringToString & data,
00737 PHTML & replyMessage
00738 );
00739
00740
00741 PHTTPField * Add(
00742 PHTTPField * fld
00743 );
00744 void RemoveAllFields()
00745 { fields.RemoveAll(); fieldNames.RemoveAll(); }
00746
00747 enum BuildOptions {
00748 CompleteHTML,
00749 InsertIntoForm,
00750 InsertIntoHTML
00751 };
00752
00753 void BuildHTML(
00754 const char * heading
00755 );
00756 void BuildHTML(
00757 const PString & heading
00758 );
00759 void BuildHTML(
00760 PHTML & html,
00761 BuildOptions option = CompleteHTML
00762 );
00763
00764
00765 protected:
00766 PHTTPCompositeField fields;
00767 PStringSet fieldNames;
00768 };
00769
00770
00772
00773
00774 class PHTTPConfig : public PHTTPForm
00775 {
00776 PCLASSINFO(PHTTPConfig, PHTTPForm)
00777 public:
00778 PHTTPConfig(
00779 const PURL & url,
00780 const PString & section
00781 );
00782 PHTTPConfig(
00783 const PURL & url,
00784 const PString & section,
00785 const PHTTPAuthority & auth
00786 );
00787 PHTTPConfig(
00788 const PURL & url,
00789 const PString & section,
00790 const PString & html
00791 );
00792 PHTTPConfig(
00793 const PURL & url,
00794 const PString & section,
00795 const PString & html,
00796 const PHTTPAuthority & auth
00797 );
00798
00799 virtual void OnLoadedText(
00800 PHTTPRequest & request,
00801 PString & text
00802 );
00803 virtual PBoolean Post(
00804 PHTTPRequest & request,
00805 const PStringToString & data,
00806 PHTML & replyMessage
00807 );
00808
00809
00812 void LoadFromConfig();
00813
00819 const PString & GetConfigSection() const { return section; }
00820
00821 void SetConfigSection(
00822 const PString & sect
00823 ) { section = sect; }
00824
00825
00830 PHTTPField * AddSectionField(
00831 PHTTPField * sectionFld,
00832 const char * prefix = NULL,
00833 const char * suffix = NULL
00834 );
00835
00839 void AddNewKeyFields(
00840 PHTTPField * keyFld,
00841 PHTTPField * valFld
00842 );
00843
00844
00845 protected:
00846 PString section;
00847 PString sectionPrefix;
00848 PString sectionSuffix;
00849 PHTTPField * sectionField;
00850 PHTTPField * keyField;
00851 PHTTPField * valField;
00852
00853 private:
00854 void Construct();
00855 };
00856
00857
00859
00860
00861 class PHTTPConfigSectionList : public PHTTPString
00862 {
00863 PCLASSINFO(PHTTPConfigSectionList, PHTTPString)
00864 public:
00865 PHTTPConfigSectionList(
00866 const PURL & url,
00867 const PHTTPAuthority & auth,
00868 const PString & sectionPrefix,
00869 const PString & additionalValueName,
00870 const PURL & editSection,
00871 const PURL & newSection,
00872 const PString & newSectionTitle,
00873 PHTML & heading
00874 );
00875
00876 virtual void OnLoadedText(
00877 PHTTPRequest & request,
00878 PString & text
00879 );
00880 virtual PBoolean Post(
00881 PHTTPRequest & request,
00882 const PStringToString & data,
00883 PHTML & replyMessage
00884 );
00885
00886 protected:
00887 PString sectionPrefix;
00888 PString additionalValueName;
00889 PString newSectionLink;
00890 PString newSectionTitle;
00891 PString editSectionLink;
00892 };
00893
00894
00895 #endif
00896
00897
00898