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

FinderHandler.cpp

Go to the documentation of this file.
00001 00005 /* 00006 Copyright (C) 2004 Anders Hedström (grymse@alhem.net) 00007 00008 This program is free software; you can redistribute it and/or 00009 modify it under the terms of the GNU General Public License 00010 as published by the Free Software Foundation; either version 2 00011 of the License, or (at your option) any later version. 00012 00013 This program 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 00016 GNU General Public License for more details. 00017 00018 You should have received a copy of the GNU General Public License 00019 along with this program; if not, write to the Free Software 00020 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00021 */ 00022 #ifdef _WIN32 00023 #pragma warning(disable:4786) 00024 #endif 00025 #include "FinderHandler.h" 00026 #include <sys/types.h> 00027 #include <sys/timeb.h> 00028 00029 #include <config-win.h> 00030 #include <mysql.h> 00031 #include <libmysqlwrapped.h> 00032 #include <time.h> 00033 #include "Search.h" 00034 #include <libcgi++.h> 00035 #include "ExecSocket.h" 00036 #include <Utility.h> 00037 00038 00039 // statics 00040 unsigned char FinderHandler::m_m2minion[32] = 00041 { 00042 0xef,0xc8,0xf0,0x79, 0x58,0x3c,0x47,0xfd, 00043 0x98,0x39,0x64,0xf7, 0xb7,0xb1,0xe6,0x4f, 00044 0x26,0x5c,0x73,0xf3, 0xc6,0x31,0x40,0xd5, 00045 0xab,0xf3,0xc5,0xfd, 0x3c,0x70,0x7c,0x05, 00046 }; 00047 00048 00049 00050 FinderHandler::FinderHandler(Database& p) : MinderHandler() 00051 ,m_db(p) 00052 ,m_start(time(NULL)) 00053 ,m_mime("mime.types") 00054 { 00055 } 00056 00057 00058 FinderHandler::~FinderHandler() 00059 { 00060 } 00061 00062 00063 std::string FinderHandler::datetime2httpdate(const std::string& dt) 00064 { 00065 char slask[8]; 00066 struct tm tp; 00067 time_t t; 00068 char *days[] = { "Sun","Mon","Tue","Wed","Thu","Fri","Sat" }; 00069 char *months[] = { "Jan","Feb","Mar","Apr","May","Jun", 00070 "Jul","Aug","Sep","Oct","Nov","Dec" }; 00071 int i; 00072 char s[40]; 00073 00074 /* 1997-12-16 09:50:40 */ 00075 00076 if (dt.size() == 19) // && (int)strlen(dt) == 19) 00077 { 00078 slask[4] = 0; 00079 tp.tm_year = atoi(strncpy(slask,dt.c_str(),4)) - 1900; 00080 slask[2] = 0; 00081 i = atoi(strncpy(slask,dt.c_str() + 5,2)) - 1; 00082 tp.tm_mon = i >= 0 ? i : 0; 00083 tp.tm_mday = atoi(strncpy(slask,dt.c_str() + 8,2)); 00084 tp.tm_hour = atoi(strncpy(slask,dt.c_str() + 11,2)); 00085 tp.tm_min = atoi(strncpy(slask,dt.c_str() + 14,2)); 00086 tp.tm_sec = atoi(strncpy(slask,dt.c_str() + 17,2)); 00087 tp.tm_wday = 0; 00088 tp.tm_yday = 0; 00089 tp.tm_isdst = 0; 00090 t = mktime(&tp); 00091 if (t == -1) 00092 { 00093 this->LogError(NULL, "datetime2httpdate", 0, "mktime() failed"); 00094 } 00095 00096 sprintf(s,"%s, %02d %s %d %02d:%02d:%02d GMT", 00097 days[tp.tm_wday], 00098 tp.tm_mday, 00099 months[tp.tm_mon], 00100 tp.tm_year + 1900, 00101 tp.tm_hour,tp.tm_min,tp.tm_sec); 00102 } 00103 else 00104 { 00105 *s = 0; 00106 } 00107 return s; 00108 } 00109 00110 00111 std::string FinderHandler::GetStart() 00112 { 00113 struct tm* tp = localtime(&m_start); 00114 char slask[40]; 00115 if (tp) 00116 { 00117 sprintf(slask,"%d-%02d-%02d %02d:%02d:%02d", 00118 tp -> tm_year + 1900, 00119 tp -> tm_mon + 1, 00120 tp -> tm_mday, 00121 tp -> tm_hour,tp -> tm_min,tp -> tm_sec); 00122 } 00123 else 00124 { 00125 *slask = 0; 00126 } 00127 return datetime2httpdate( slask ); 00128 } 00129 00130 00131 std::string FinderHandler::GetDate() 00132 { 00133 time_t t = time(NULL); 00134 struct tm* tp = localtime(&t); 00135 char slask[40]; 00136 if (tp) 00137 { 00138 sprintf(slask,"%d-%02d-%02d %02d:%02d:%02d", 00139 tp -> tm_year + 1900, 00140 tp -> tm_mon + 1, 00141 tp -> tm_mday, 00142 tp -> tm_hour,tp -> tm_min,tp -> tm_sec); 00143 } 00144 else 00145 { 00146 *slask = 0; 00147 } 00148 return slask; 00149 } 00150 00151 00152 std::string FinderHandler::GetMimeFromFile(const std::string& name) 00153 { 00154 return m_mime.GetMimeFromFile(name); 00155 } 00156 00157 00158 size_t FinderHandler::MinionSockets() 00159 { 00160 size_t qty = 0; 00161 for (socket_m::iterator it = m_sockets.begin(); it != m_sockets.end(); it++) 00162 { 00163 Socket *p0 = (*it).second; 00164 if (dynamic_cast<MinionSocket *>(p0)) 00165 { 00166 qty++; 00167 } 00168 } 00169 return qty; 00170 } 00171 00172 00173 void FinderHandler::CheckSocketTimeout() 00174 { 00175 time_t tnow = time(NULL); 00176 for (socket_m::iterator it = m_sockets.begin(); it != m_sockets.end(); it++) 00177 { 00178 Socket *p0 = (*it).second; 00179 ExecSocket *sock = dynamic_cast<ExecSocket *>(p0); 00180 } 00181 } 00182 00183 00184 void FinderHandler::BeginTop() 00185 { 00186 std::string msg = "Tip_" + Utility::l2string(GetHostId()); 00187 SendMessage(Utility::base64(msg)); 00188 unlink("top_map.dot"); 00189 FILE *fil; 00190 00191 if ((fil = fopen("top_map.dot","wt")) != NULL) 00192 { 00193 fprintf(fil,"digraph \"G\" {\n"); 00194 fprintf(fil,"\tedge [arrowhead=open]\n"); 00195 #ifdef _WIN32 00196 std::string os = "Win32"; 00197 #else 00198 std::string os = "Linux"; 00199 #endif 00200 fprintf(fil,"\t\"%ld\" [label=\"%ld\\n%s\\n%s\" style=filled fillcolor=\"#e0e0e0\"]\n", 00201 GetHostId(), 00202 GetHostId(), 00203 GetVersion().c_str(), 00204 os.c_str()); 00205 Tops(fil); 00206 fclose(fil); 00207 } 00208 } 00209 00210 00211 void FinderHandler::EndTop() 00212 { 00213 FILE *fil = fopen("top_map.dot","at"); 00214 char cmd[200]; 00215 if (fil) 00216 { 00217 fprintf(fil,"}\n"); 00218 fclose(fil); 00219 sprintf(cmd, "DOT.EXE -Tpng -o top_map.png top_map.dot"); 00220 system( cmd ); 00221 unlink("top_map.dot"); 00222 } 00223 } 00224 00225 00226 int FinderHandler::FinderSockets() 00227 { 00228 int q = 0; 00229 for (socket_m::iterator it = m_sockets.begin(); it != m_sockets.end(); it++) 00230 { 00231 Socket *p0 = (*it).second; 00232 if (dynamic_cast<ExecSocket *>(p0)) 00233 { 00234 q++; 00235 } 00236 } 00237 return q; 00238 } 00239 00240

Generated on Thu Feb 10 22:42:34 2005 for Distributed URL Classification Tool by doxygen 1.3.7