libnavajo
web server for static and dynamic pages developement in C++
DynamicPage.hh
Go to the documentation of this file.
1 //********************************************************
12 //********************************************************
13 
14 #ifndef DYNAMICPAGE_HH_
15 #define DYNAMICPAGE_HH_
16 
17 #include <string>
18 #include <typeinfo>
19 #include <ctype.h>
20 #include <string>
21 #include <algorithm>
22 
24 {
25 
26  public:
27  DynamicPage() {};
28  virtual bool getPage(HttpRequest* request, HttpResponse *response) = 0;
29 
30 
31  /**********************************************************************/
32 
33  template<class T> static inline T getValue (const std::string &s)
34  {
35  if (!s.length())
36  throw std::bad_cast();
37 
38  std::istringstream iss(s);
39  T tmp; iss>>tmp;
40 
41  if(iss.fail())
42  throw std::bad_cast();
43 
44  return tmp;
45  };
46 
47  /**********************************************************************/
48 
49  static inline bool isNotPrintable (char c)
50  {
51  return !isprint( static_cast<unsigned char>( c ) );
52  }
53 
54  static inline void stripUnprintableChar(std::string &str)
55  {
56  str.erase(std::remove_if(str.begin(),str.end(), isNotPrintable), str.end());
57  }
58 
59  /**********************************************************************/
60 
61  inline bool noContent( HttpResponse *response )
62  {
63  response->setContent (NULL, 0);
64  return true;
65  }
66 
67  /**********************************************************************/
68 
69  inline bool fromString( const std::string& resultat, HttpResponse *response )
70  {
71  size_t webpageLen;
72  unsigned char *webpage;
73  if ( (webpage = (unsigned char *)malloc( resultat.size()+1 * sizeof(char))) == NULL )
74  return false;
75  webpageLen=resultat.size();
76  strcpy ((char *)webpage, resultat.c_str());
77  response->setContent (webpage, webpageLen);
78  return true;
79  }
80 
81 
82 };
83 
84 #endif
Definition: DynamicPage.hh:23
Definition: HttpRequest.hh:42
void setContent(unsigned char *content, size_t length)
Definition: HttpResponse.hh:40
Definition: HttpResponse.hh:18