PTLib  Version 2.10.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
httpform.h
Go to the documentation of this file.
1 /*
2  * httpform.h
3  *
4  * Forms management using HTTP 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_HTTPFORM_H
32 #define PTLIB_HTTPFORM_H
33 
34 #ifdef P_USE_PRAGMA
35 #pragma interface
36 #endif
37 
38 #if P_HTTPFORMS
39 
40 #include <ptclib/http.h>
41 #include <ptclib/html.h>
42 
43 
45 // PHTTPField
46 
50 class PHTTPField : public PObject
51 {
53  public:
54  PHTTPField(
55  const char * bname, // base name (identifier) for the field.
56  const char * title, // Title text for field (defaults to name).
57  const char * help // Help text for the field.
58  );
59  // Create a new field in a HTTP form.
60 
66  virtual Comparison Compare(
67  const PObject & obj
68  ) const;
69 
75  const PCaselessString & GetName() const { return fullName; }
76 
82  const PCaselessString & GetBaseName() const { return baseName; }
83 
86  virtual void SetName(
87  const PString & newName // New name for field
88  );
89 
95  virtual const PHTTPField * LocateName(
96  const PString & name // Full field name to locate
97  ) const;
98 
104  const PString & GetTitle() const { return title; }
105 
111  const PString & GetHelp() const { return help; }
112 
113  void SetHelp(
114  const PString & text // Help text.
115  ) { help = text; }
116  void SetHelp(
117  const PString & hotLinkURL, // URL for link to help page.
118  const PString & linkText // Help text in the link.
119  );
120  void SetHelp(
121  const PString & hotLinkURL, // URL for link to help page.
122  const PString & imageURL, // URL for image to be displayed in link.
123  const PString & imageText // Text in the link when image unavailable.
124  );
125  // Set the help text for the field.
126 
132  virtual PHTTPField * NewField() const = 0;
133 
134  virtual void ExpandFieldNames(PString & text, PINDEX start, PINDEX & finish) const;
135  // Splice expanded macro substitutions into text string
136 
139  virtual void GetHTMLTag(
140  PHTML & html // HTML to receive the fields HTML tag.
141  ) const = 0;
142 
145  virtual PString GetHTMLInput(
146  const PString & input // Source HTML text for input tag.
147  ) const;
148 
151  virtual PString GetHTMLSelect(
152  const PString & selection // Source HTML text for input tag.
153  ) const;
154 
157  virtual void GetHTMLHeading(
158  PHTML & html // HTML to receive the field info.
159  ) const;
160 
166  virtual PString GetValue(PBoolean dflt = false) const = 0;
167 
170  virtual void SetValue(
171  const PString & newValue // New value for the field.
172  ) = 0;
173 
177  virtual void LoadFromConfig(
178  PConfig & cfg // Configuration for value transfer.
179  );
180 
184  virtual void SaveToConfig(
185  PConfig & cfg // Configuration for value transfer.
186  ) const;
187 
193  virtual PBoolean Validated(
194  const PString & newVal, // Proposed new value for the field.
195  PStringStream & msg // Stream to take error HTML if value not valid.
196  ) const;
197 
198 
204  virtual void GetAllNames(PStringArray & names) const;
205 
208  virtual void SetAllValues(
209  const PStringToString & data // New value for the field.
210  );
211 
217  virtual PBoolean ValidateAll(
218  const PStringToString & data, // Proposed new value for the field.
219  PStringStream & msg // Stream to take error HTML if value not valid.
220  ) const;
221 
222 
223  PBoolean NotYetInHTML() const { return notInHTML; }
224  void SetInHTML() { notInHTML = false; }
225 
226  protected:
232 };
233 
234 
235 PARRAY(PHTTPFields, PHTTPField);
236 
238 {
240  public:
242  const char * name, // Name (identifier) for the field.
243  const char * title = NULL, // Title text for field (defaults to name).
244  const char * help = NULL, // Help text for the field.
245  bool includeHeaders = false // Make a sub-table and put headers on HTML fields.
246  );
247 
248  virtual void SetName(
249  const PString & name // New name for field
250  );
251 
252  virtual const PHTTPField * LocateName(
253  const PString & name // Full field name to locate
254  ) const;
255 
256  virtual PHTTPField * NewField() const;
257 
258  virtual void ExpandFieldNames(PString & text, PINDEX start, PINDEX & finish) const;
259 
260  virtual void GetHTMLTag(
261  PHTML & html // HTML to receive the field info.
262  ) const;
263 
264  virtual PString GetHTMLInput(
265  const PString & input // Source HTML text for input tag.
266  ) const;
267 
268  virtual void GetHTMLHeading(
269  PHTML & html // HTML to receive the field info.
270  ) const;
271 
272  virtual PString GetValue(PBoolean dflt = false) const;
273 
274  virtual void SetValue(
275  const PString & newValue // New value for the field.
276  );
277 
278  virtual void LoadFromConfig(
279  PConfig & cfg // Configuration for value transfer.
280  );
281  virtual void SaveToConfig(
282  PConfig & cfg // Configuration for value transfer.
283  ) const;
284 
285  virtual void GetAllNames(PStringArray & names) const;
286  virtual void SetAllValues(
287  const PStringToString & data // New value for the field.
288  );
289 
290  virtual PBoolean ValidateAll(
291  const PStringToString & data, // Proposed new value for the field.
292  PStringStream & msg // Stream to take error HTML if value not valid.
293  ) const;
294 
295 
303  virtual PINDEX GetSize() const;
304 
305  void Append(PHTTPField * fld);
306  PHTTPField & operator[](PINDEX idx) const { return fields[idx]; }
307  void RemoveAt(PINDEX idx) { fields.RemoveAt(idx); }
308  void RemoveAll() { fields.RemoveAll(); }
309 
310  protected:
311  PHTTPFields fields;
313 };
314 
315 
317 {
319  public:
320  PHTTPSubForm(
321  const PString & subFormName, // URL for the sub-form
322  const char * name, // Name (identifier) for the field.
323  const char * title = NULL, // Title text for field (defaults to name).
324  PINDEX primaryField = 0, // Pimary field whove value is in hot link
325  PINDEX secondaryField = P_MAX_INDEX // Seconary field next to hotlink
326  );
327 
328  PHTTPField * NewField() const;
329  void GetHTMLTag(PHTML & html) const;
330  void GetHTMLHeading(PHTML & html) const;
331 
332  protected:
334  PINDEX primary;
335  PINDEX secondary;
336 };
337 
338 
340 {
342  public:
345  PBoolean ordered,
346  PINDEX fixedSize = 0
347  );
348 
350 
351 
352  virtual PHTTPField * NewField() const;
353 
354  virtual void ExpandFieldNames(PString & text, PINDEX start, PINDEX & finish) const;
355 
356  virtual void GetHTMLTag(
357  PHTML & html // HTML to receive the field info.
358  ) const;
359 
360  virtual void LoadFromConfig(
361  PConfig & cfg // Configuration for value transfer.
362  );
363  virtual void SaveToConfig(
364  PConfig & cfg // Configuration for value transfer.
365  ) const;
366 
367 
368  virtual void SetAllValues(
369  const PStringToString & data // New value for the field.
370  );
371 
372  virtual PINDEX GetSize() const;
373  void SetSize(PINDEX newSize);
374 
376  PConfig & cfg
377  );
378 
379  void SetStrings(
380  PConfig & cfg,
381  const PStringArray & values
382  );
383 
384  protected:
385  void AddBlankField();
386  void AddArrayControlBox(PHTML & html, PINDEX fld) const;
387  void SetArrayFieldName(PINDEX idx) const;
388 
392 };
393 
394 
396 {
398  public:
400  const char * name,
401  PINDEX size,
402  const char * initVal = NULL,
403  const char * help = NULL
404  );
406  const char * name,
407  const char * title,
408  PINDEX size,
409  const char * initVal = NULL,
410  const char * help = NULL
411  );
412 
413  virtual PHTTPField * NewField() const;
414 
415  virtual void GetHTMLTag(
416  PHTML & html
417  ) const;
418 
419  virtual PString GetValue(PBoolean dflt = false) const;
420 
421  virtual void SetValue(
422  const PString & newVal
423  );
424 
425 
426  protected:
429  PINDEX size;
430 };
431 
432 
434 {
436  public:
438  const char * name,
439  PINDEX size,
440  const char * initVal = NULL,
441  const char * help = NULL
442  );
444  const char * name,
445  const char * title,
446  PINDEX size,
447  const char * initVal = NULL,
448  const char * help = NULL
449  );
450 
451  virtual PHTTPField * NewField() const;
452 
453  virtual void GetHTMLTag(
454  PHTML & html
455  ) const;
456 
457  virtual PString GetValue(PBoolean dflt = false) const;
458 
459  virtual void SetValue(
460  const PString & newVal
461  );
462 
463  static PString Decrypt(const PString & pword);
464 };
465 
466 
468 {
470  public:
472  const char * name,
473  const PTime & initVal = PTime(0),
475  );
476 
477  virtual PHTTPField * NewField() const;
478 
479  virtual void SetValue(
480  const PString & newValue
481  );
482 
483  virtual PBoolean Validated(
484  const PString & newValue,
485  PStringStream & msg
486  ) const;
487 
488  protected:
490 };
491 
492 
494 {
496  public:
498  const char * name,
499  int low, int high,
500  int initVal = 0,
501  const char * units = NULL,
502  const char * help = NULL
503  );
505  const char * name,
506  const char * title,
507  int low, int high,
508  int initVal = 0,
509  const char * units = NULL,
510  const char * help = NULL
511  );
512 
513  virtual PHTTPField * NewField() const;
514 
515  virtual void GetHTMLTag(
516  PHTML & html
517  ) const;
518 
519  virtual PString GetValue(PBoolean dflt = false) const;
520 
521  virtual void SetValue(
522  const PString & newVal
523  );
524 
525  virtual void LoadFromConfig(
526  PConfig & cfg
527  );
528  virtual void SaveToConfig(
529  PConfig & cfg
530  ) const;
531 
532  virtual PBoolean Validated(
533  const PString & newVal,
534  PStringStream & msg
535  ) const;
536 
537 
538  protected:
539  int low, high, value;
542 };
543 
544 
546 {
548  public:
550  const char * name,
551  PBoolean initVal = false,
552  const char * help = NULL
553  );
555  const char * name,
556  const char * title,
557  PBoolean initVal = false,
558  const char * help = NULL
559  );
560 
561  virtual PHTTPField * NewField() const;
562 
563  virtual void GetHTMLTag(
564  PHTML & html
565  ) const;
566 
567  virtual PString GetHTMLInput(
568  const PString & input
569  ) const;
570 
571  virtual PString GetValue(PBoolean dflt = false) const;
572 
573  virtual void SetValue(
574  const PString & newVal
575  );
576 
577  virtual void LoadFromConfig(
578  PConfig & cfg
579  );
580  virtual void SaveToConfig(
581  PConfig & cfg
582  ) const;
583 
584 
585  protected:
587 };
588 
589 
591 {
593  public:
595  const char * name,
596  const PStringArray & valueArray,
597  PINDEX initVal = 0,
598  const char * help = NULL
599  );
601  const char * name,
602  const PStringArray & valueArray,
603  const PStringArray & titleArray,
604  PINDEX initVal = 0,
605  const char * help = NULL
606  );
608  const char * name,
609  PINDEX count,
610  const char * const * valueStrings,
611  PINDEX initVal = 0,
612  const char * help = NULL
613  );
615  const char * name,
616  PINDEX count,
617  const char * const * valueStrings,
618  const char * const * titleStrings,
619  PINDEX initVal = 0,
620  const char * help = NULL
621  );
623  const char * name,
624  const char * groupTitle,
625  const PStringArray & valueArray,
626  PINDEX initVal = 0,
627  const char * help = NULL
628  );
630  const char * name,
631  const char * groupTitle,
632  const PStringArray & valueArray,
633  const PStringArray & titleArray,
634  PINDEX initVal = 0,
635  const char * help = NULL
636  );
638  const char * name,
639  const char * groupTitle,
640  PINDEX count,
641  const char * const * valueStrings,
642  PINDEX initVal = 0,
643  const char * help = NULL
644  );
646  const char * name,
647  const char * groupTitle,
648  PINDEX count,
649  const char * const * valueStrings,
650  const char * const * titleStrings,
651  PINDEX initVal = 0,
652  const char * help = NULL
653  );
654 
655  virtual PHTTPField * NewField() const;
656 
657  virtual void GetHTMLTag(
658  PHTML & html
659  ) const;
660 
661  virtual PString GetHTMLInput(
662  const PString & input
663  ) const;
664 
665  virtual PString GetValue(PBoolean dflt = false) const;
666 
667  virtual void SetValue(
668  const PString & newVal
669  );
670 
671 
672  protected:
677 };
678 
679 
681 {
683  public:
685  const char * name,
686  const PStringArray & valueArray,
687  PINDEX initVal = 0,
688  const char * help = NULL
689  );
691  const char * name,
692  PINDEX count,
693  const char * const * valueStrings,
694  PINDEX initVal = 0,
695  const char * help = NULL
696  );
698  const char * name,
699  const char * title,
700  const PStringArray & valueArray,
701  PINDEX initVal = 0,
702  const char * help = NULL
703  );
705  const char * name,
706  const char * title,
707  PINDEX count,
708  const char * const * valueStrings,
709  PINDEX initVal = 0,
710  const char * help = NULL
711  );
712 
713  virtual PHTTPField * NewField() const;
714 
715  virtual void GetHTMLTag(
716  PHTML & html
717  ) const;
718 
719  virtual PString GetValue(PBoolean dflt = false) const;
720 
721  virtual void SetValue(
722  const PString & newVal
723  );
724 
725 
727 
728 
729  protected:
731  PINDEX initialValue;
732 };
733 
734 
736 // PHTTPForm
737 
738 class PHTTPForm : public PHTTPString
739 {
741  public:
742  PHTTPForm(
743  const PURL & url
744  );
745  PHTTPForm(
746  const PURL & url,
747  const PHTTPAuthority & auth
748  );
749  PHTTPForm(
750  const PURL & url,
751  const PString & html
752  );
753  PHTTPForm(
754  const PURL & url,
755  const PString & html,
756  const PHTTPAuthority & auth
757  );
758 
759 
760  virtual void OnLoadedText(
761  PHTTPRequest & request,
762  PString & text
763  );
764  virtual PBoolean Post(
765  PHTTPRequest & request,
766  const PStringToString & data,
767  PHTML & replyMessage
768  );
769 
770 
771  PHTTPField * Add(
772  PHTTPField * fld
773  );
776 
781  };
782 
783  void BuildHTML(
784  const char * heading
785  );
786  void BuildHTML(
787  const PString & heading
788  );
789  void BuildHTML(
790  PHTML & html,
791  BuildOptions option = CompleteHTML
792  );
793 
794 
795  protected:
798 };
799 
800 
802 // PHTTPConfig
803 
804 class PHTTPConfig : public PHTTPForm
805 {
807  public:
808  PHTTPConfig(
809  const PURL & url,
810  const PString & section
811  );
812  PHTTPConfig(
813  const PURL & url,
814  const PString & section,
815  const PHTTPAuthority & auth
816  );
817  PHTTPConfig(
818  const PURL & url,
819  const PString & section,
820  const PString & html
821  );
822  PHTTPConfig(
823  const PURL & url,
824  const PString & section,
825  const PString & html,
826  const PHTTPAuthority & auth
827  );
828 
829  virtual void OnLoadedText(
830  PHTTPRequest & request,
831  PString & text
832  );
833  virtual PBoolean Post(
834  PHTTPRequest & request,
835  const PStringToString & data,
836  PHTML & replyMessage
837  );
838 
839 
842  void LoadFromConfig();
843 
849  const PString & GetConfigSection() const { return section; }
850 
852  const PString & sect
853  ) { section = sect; }
854  // Set the configuration file section.
855 
861  PHTTPField * sectionFld,
862  const char * prefix = NULL,
863  const char * suffix = NULL
864  );
865 
869  void AddNewKeyFields(
870  PHTTPField * keyFld,
871  PHTTPField * valFld
872  );
873 
874 
875  protected:
882 
883  private:
884  void Construct();
885 };
886 
887 
889 // PHTTPConfigSectionList
890 
892 {
894  public:
896  const PURL & url,
897  const PHTTPAuthority & auth,
898  const PString & sectionPrefix,
900  const PURL & editSection,
901  const PURL & newSection,
902  const PString & newSectionTitle,
903  PHTML & heading
904  );
905 
906  virtual void OnLoadedText(
907  PHTTPRequest & request,
908  PString & text
909  );
910  virtual PBoolean Post(
911  PHTTPRequest & request,
912  const PStringToString & data,
913  PHTML & replyMessage
914  );
915 
916  protected:
922 };
923 
924 
925 #endif // P_HTTPFORMS
926 
927 #endif // PTLIB_HTTPFORM_H
928 
929 
930 // End Of File ///////////////////////////////////////////////////////////////