Google
Web alhem.net
Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

IWeb.cpp

Go to the documentation of this file.
00001 00006 /* 00007 Copyright (C) 2004 Anders Hedstrom 00008 00009 This program is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU General Public License 00011 as published by the Free Software Foundation; either version 2 00012 of the License, or (at your option) any later version. 00013 00014 This program is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 GNU General Public License for more details. 00018 00019 You should have received a copy of the GNU General Public License 00020 along with this program; if not, write to the Free Software 00021 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00022 */ 00023 //#include <stdio.h> 00024 00025 #include "IWeb.h" 00026 #include <libibank.h> 00027 00028 /* 00029 #define DEB(x) { \ 00030 FILE *fil = fopen("/tmp/debug","at"); \ 00031 x; \ 00032 fclose(fil); \ 00033 } 00034 */ 00035 #define DEB(x) 00036 00037 //extern char **environ; 00038 00039 00040 IWeb::IWeb() : Web(COOKIE_DOMAIN, COOKIE_PATH) 00041 ,m_db("localhost","web","","ibank") 00042 ,m_bSetCookie(false) 00043 ,m_image(0) 00044 ,m_pImage(NULL) 00045 ,m_image_tn(false) 00046 ,m_not_modified(false) 00047 // 00048 ,m_form1(this) 00049 ,m_form2(this) 00050 ,m_form3(this) 00051 ,m_form4(this) 00052 ,m_form5(this) 00053 ,m_form6(this) 00054 ,m_form7(this) 00055 ,m_form8(this) 00056 // 00057 ,m_usernum(0) 00058 ,m_valid(0) 00059 ,m_forum(0) 00060 ,m_thread(0) 00061 ,m_page(0) 00062 ,m_index(0) 00063 ,m_qty(0) 00064 ,m_message(0) 00065 { 00066 m_db.RegErrHandler(&m_log); 00067 00068 RegWebForm(&m_form1); 00069 RegWebForm(&m_form2); 00070 RegWebForm(&m_form3); 00071 RegWebForm(&m_form4); 00072 RegWebForm(&m_form5); 00073 RegWebForm(&m_form6); 00074 RegWebForm(&m_form7); 00075 RegWebForm(&m_form8); 00076 } 00077 00078 00079 IWeb::~IWeb() 00080 { 00081 } 00082 00083 00084 void IWeb::ReadCookies() 00085 { 00086 char slask[1000]; 00087 GetCookies() -> getvalue("ibc", slask, 1000); 00088 cgi::Parse pa(slask,":"); 00089 m_usernum = pa.getvalue(); 00090 m_valid = pa.getvalue(); 00091 m_forum = pa.getvalue(); 00092 m_thread = pa.getvalue(); 00093 m_page = pa.getvalue(); 00094 m_index = pa.getvalue(); 00095 m_qty = pa.getvalue(); 00096 m_message = pa.getvalue(); 00097 } 00098 00099 00100 void IWeb::FormInput() 00101 { 00102 std::string page = GetForm() -> getvalue("page"); 00103 if (page.size()) 00104 { 00105 SetPage(atoi(page.c_str())); 00106 } 00107 std::string img = GetForm() -> getvalue("img"); 00108 if (img.size()) 00109 { 00110 m_pImage = new db::Image(m_db, atol(img.c_str())); 00111 m_image = m_pImage -> num; 00112 } 00113 else 00114 { 00115 img = GetForm() -> getvalue("imgtn"); 00116 if (img.size()) 00117 { 00118 m_pImage = new db::Image(m_db, atol(img.c_str())); 00119 m_image = m_pImage -> num; 00120 m_image_tn = true; 00121 } 00122 } 00123 std::string logout = GetForm() -> getvalue("logout"); 00124 if (logout.size() && atoi(logout.c_str()) == 1) 00125 { 00126 Query q(m_db); 00127 char sql[1000]; 00128 sprintf(sql,"delete from valid where account=%ld and valid=%ld",m_usernum,m_valid); 00129 q.execute(sql); 00130 } 00131 //printf("\n<html><body><h3>debug forminput</h3>"); 00132 Web::FormInput(); 00133 } 00134 00135 00136 void IWeb::CreateHeader() 00137 { 00138 char *if_modified_since = getenv("HTTP_IF_MODIFIED_SINCE"); 00139 // HTTP_IF_MODIFIED_SINCE=Tue, 06 Jul 2004 16:33:51 GMT 00140 00141 if (m_image && if_modified_since && datetime2httpdate(m_pImage -> modified) == if_modified_since) 00142 { 00143 printf("Status: 304 Not Modified\n\n"); 00144 m_not_modified = true; 00145 return; 00146 } 00147 if (m_bSetCookie) 00148 { 00149 SetTheCookie(); 00150 } 00151 if (m_image) 00152 { 00153 // Last-Modified: Wed, 15 Nov 1995 04:58:08 GMT 00154 printf("Last-modified: %s\n",datetime2httpdate(m_pImage -> modified).c_str()); 00155 printf("Content-type: %s\n",m_form1.GetMimeFromFilename(m_image_tn ? "/tmp/tn.gif" : m_pImage -> filename).c_str()); 00156 } 00157 else 00158 { 00159 printf("Content-type: text/html\n"); 00160 } 00161 // End of header 00162 printf("\n"); 00163 fflush(stdout); 00164 } 00165 00166 00167 void IWeb::GenerateDocument() 00168 { 00169 db::Account account(GetDatabase(), m_usernum); 00170 char sql[1000]; 00171 sprintf(sql,"select * from valid where account=%ld and valid=%ld",m_usernum,m_valid); 00172 db::Valid valid(&GetDatabase(), sql); 00173 /* 00174 { 00175 size_t i = 0; 00176 while (environ[i]) 00177 { 00178 DEB( fprintf(fil,"%s\n",environ[i]);) 00179 i++; 00180 } 00181 } 00182 */ 00183 if (!account.num || !valid.num) 00184 { 00185 SetPage( 1 ); 00186 } 00187 else 00188 if (m_image && m_not_modified) 00189 { 00190 return; 00191 } 00192 else 00193 if (m_image) 00194 { 00195 cgi::Base64 bomb; 00196 bomb.decode_to_stdout(m_image_tn ? m_pImage -> image_tn : m_pImage -> image_data); 00197 return; 00198 } 00199 // HTML start 00200 printf("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n"); 00201 printf("<html>\n"); 00202 printf("<head>\n"); 00203 printf("<link rel=\"STYLESHEET\" href=\"/style/ib.css\" type=\"text/css\">\n"); 00204 // printf("<link rel=\"SHORTCUT ICON\" href=\"http://www.alhem.net/icon/flags/se.png\">\n"); 00205 printf("<title>IBank :: The Image Vault</title>\n"); 00206 printf("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n"); 00207 // printf("<SCRIPT language=\"JavaScript\" SRC=\"http://www.alhem.net/js/overlib_mini4.js\" type=\"text/javascript\"></SCRIPT>\n"); 00208 00209 printf("</head>\n"); 00210 printf("<body>\n"); 00211 // printf("<div id=\"overDiv\" style=\"position:absolute; visibility:hide; z-index:1;\"></div>\n"); 00212 if (0) 00213 { 00214 char key[200]; 00215 char val[200]; 00216 printf("<h3>Form</h3>"); 00217 GetForm() -> getfirst(key,200,val,200); 00218 while (*key) 00219 { 00220 printf("%s == '%s'<br>",key,val); 00221 printf("getvalue(%s) == '%s'<br>",key,GetForm() -> getvalue(key).c_str()); 00222 GetForm() -> getnext(key,200,val,200); 00223 } 00224 printf("<h3>Cookies</h3>"); 00225 printf("<b>Cookie value to set == '%s'</b><br>",m_cookie_to_set.c_str()); 00226 for (cookie_v::iterator it = GetCookies() -> GetCookies().begin(); it != 00227 GetCookies() -> GetCookies().end(); it++) 00228 { 00229 COOKIE *p = *it; 00230 printf("%s == '%s'<br>",p -> name,p -> value); 00231 } 00232 printf("<hr>"); 00233 } 00234 if (m_page > 1 && 0) 00235 { 00236 printf("<table width=\"100%%\"><tr><td><a href=\"http://www.alhem.net/\"><img border=0 src=\"/icons/ahl.png\"></a></td>"); 00237 printf("<td>"); 00238 printf("<center>\n"); 00239 printf("<script type=\"text/javascript\" src=\"/js/goog.js\"></script>"); 00240 printf("</center>\n"); 00241 printf("</td>"); 00242 /* 00243 printf("<td align=right>"); 00244 printf("<a href=\"http://www.bosrup.com/web/overlib/\">"); 00245 printf("<img src=\"/image/power.gif\" width=\"88\" height=\"31\" alt=\"Popups by overLIB!\" border=\"0\"></a>"); 00246 printf("</td>"); 00247 */ 00248 printf("</tr></table>"); 00249 } // m_page > 2 00250 fflush(stdout); 00251 00252 switch (m_page) 00253 { 00254 case 1: // login / register 00255 m_form1.Display( 0 ); 00256 break; 00257 case 2: // user settings 00258 m_form2.Display( m_usernum ); 00259 break; 00260 case 3: // forums 00261 m_form3.Display( 0 ); 00262 break; 00263 case 4: // threads 00264 m_form4.Display( m_forum ); 00265 break; 00266 case 5: // view thread 00267 m_form5.Display( m_thread ); 00268 break; 00269 case 6: // new thread 00270 m_form6.Display( m_forum ); 00271 break; 00272 case 7: // new message 00273 m_form7.Display( m_thread ); 00274 break; 00275 case 8: // edit message 00276 m_form8.Display( m_message ); 00277 break; 00278 } 00279 fflush(stdout); 00280 00281 // Footer 00282 printf("</body>\n"); 00283 printf("</html>\n"); 00284 fflush(stdout); 00285 } 00286 00287 00288 /* 00289 cookie = 00290 <usernum> : <valid> : <forum> : <thread> : <page> : <index> : <qty> 00291 */ 00292 void IWeb::SetTheCookie() 00293 { 00294 char slask[1000]; 00295 sprintf(slask,"%ld:%ld:%ld:%ld:%ld:%ld:%ld:%ld", 00296 m_usernum,m_valid,m_forum,m_thread,m_page,m_index,m_qty,m_message); 00297 SetCookie("ibc", slask); 00298 m_cookie_to_set = slask; 00299 } 00300 00301

Generated on Sat Feb 12 00:14:56 2005 for IBank by doxygen 1.3.7