Main Page   Class Hierarchy   Compound List   File List   Compound Members  

mhtml.cc

00001 /***************************************************************************
00002  *   This file is part of the MagiC++ library.                             *
00003  *                                                                         *
00004  *   Copyright (C) 1998-2001 Marko Grönroos <magi@iki.fi>                  *
00005  *                                                                         *
00006  ***************************************************************************
00007  *                                                                         *
00008  *  This library is free software; you can redistribute it and/or          *
00009  *  modify it under the terms of the GNU Library General Public            *
00010  *  License as published by the Free Software Foundation; either           *
00011  *  version 2 of the License, or (at your option) any later version.       *
00012  *                                                                         *
00013  *  This library is distributed in the hope that it will be useful,        *
00014  *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
00015  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU      *
00016  *  Library General Public License for more details.                       *
00017  *                                                                         *
00018  *  You should have received a copy of the GNU Library General Public      *
00019  *  License along with this library; see the file COPYING.LIB.  If         *
00020  *  not, write to the Free Software Foundation, Inc., 59 Temple Place      *
00021  *  - Suite 330, Boston, MA 02111-1307, USA.                               *
00022  *                                                                         *
00023  ***************************************************************************/
00024 
00025 #include "magic/mhtml.h"
00026 #include "magic/mclass.h"
00027 
00028 decl_module (html);
00029 
00030 impl_dynamic (HTMLQuery, {Object});
00031 impl_dynamic (HTMLPageBase, {Object});
00032 
00034 
00035 // unquote
00036 
00037 void unquote (Map<String, String>& map) {
00038     for (MapIter<String,String> i (map); !i.exhausted(); i.next())
00039         i.value ().unquote ('%', String::QUOTE_HTML);
00040 }
00041 
00043 //                                  HTMLQuery
00044 
00045 HTMLQuery::HTMLQuery () {
00046     String contlen_tmp;
00047     contype     = getenv ("CONTENT_TYPE");
00048     contlen_tmp = getenv ("CONTENT_LENGTH");
00049     docroot     = getenv ("DOCUMENT_ROOT");
00050     gwif        = getenv ("GATEWAY_INTERFACE");
00051     hosttype    = getenv ("HOSTTYPE");
00052     httpaccpt   = getenv ("HTTP_ACCEPT");
00053     httppragma  = getenv ("HTTP_PRAGMA");
00054     useragent   = getenv ("HTTP_USER_AGENT");
00055     pathinfo    = getenv ("PATH_INFO");
00056     pathtrans   = getenv ("PATH_TRANSLATED");
00057     querystr    = getenv ("QUERY_STRING");
00058     remaddr     = getenv ("REMOTE_ADDR");
00059     remhost     = getenv ("REMOTE_HOST");
00060     method      = getenv ("REQUEST_METHOD");
00061     sptname     = getenv ("SCRIPT_NAME");
00062     srvname     = getenv ("SERVER_NAME");
00063     srvport     = 80; // atoi (getenv ("SERVER_PORT"));
00064     srvprot     = getenv ("SERVER_PROTOCOL");
00065     srvsoft     = getenv ("SERVER_SOFTWARE");
00066 
00067     contlen = contlen_tmp.isNull()? 0 : atoi (contlen_tmp);
00068 //  printf ("contlen=%d\n", (char*) contlen);
00069 
00070     if (method=="GET")
00071         splitpairs (query, querystr, '=', '&');
00072     else { // POST
00073         if (contlen > 0) {
00074             // Luetaan stdio:ta pituuden verran
00075             char* buff = new char [contlen+1];
00076             fgets (buff, contlen+1, stdin);
00077             querystr = buff;
00078             delete buff;
00079             splitpairs (query, querystr, '=', '&');
00080         }
00081     }
00082 
00083     // Konvertoidaan query-parametrien quotet
00084     unquote (query);
00085 
00086 //  query.print (cout);
00087 }
00088 
00089 void HTMLQuery::printhidden () const {
00090     forStringMap (query, i)
00091         printf ("<INPUT TYPE=HIDDEN NAME='%s' VALUE='%s'>\n",
00092                 (CONSTR) i.key (), (CONSTR) i.value ());
00093 }
00094 
00095 void HTMLQuery::any () {
00096     if (pathinfo.length()>5 && pathinfo.mid(pathinfo.length()-5) == ".html") {
00097         call (pathinfo.mid (1, pathinfo.length()-6)+String("_html"));
00098     } else
00099         printf ("Content-type: text/html\n\n"
00100                 "<H1>Invalid path '%s'</H1>\n"
00101                 "Page couldn't be found. Sorry!\n",
00102                 (CONSTR) pathinfo);
00103     
00104 }
00105 
00106 int HTMLQuery::call (const String& pagename) {
00107     HTMLPageBase* pageobj = (HTMLPageBase*) dyncreate (pagename);
00108     if (pageobj) {
00109         pageobj->printqry (*this);
00110         delete pageobj;
00111         return 0;
00112     } else {
00113         printf ("Content-type: text/html\n\n"
00114                 "<H1>Invalid page called '%s'</H1>\n"
00115                 "Page couldn't be found. Sorry!\n",
00116                 (CONSTR) pathinfo);
00117         return 1;
00118     }
00119 }
00120 

Generated at Tue Dec 4 19:53:25 2001 for MagiC++ by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001