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

MyMinionSocket.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 //#include <stdio.h> 00023 #include "MyMinionSocket.h" 00024 #include "FinderHandler.h" 00025 #include <Utility.h> 00026 #ifdef _WIN32 00027 #include <config-win.h> 00028 #include <mysql.h> 00029 #include <libmysqlwrapped.h> 00030 #define strcasecmp stricmp 00031 #else 00032 #include <mysql/mysql.h> 00033 #include <libmysqlwrapped.h> 00034 #endif 00035 #include <libfd.h> 00036 #include "Search.h" 00037 #include "win32/MyApp.h" 00038 00039 00040 #define D2(x) { \ 00041 FILE *fil = fopen("c:\\deb.log","at"); \ 00042 x; \ 00043 fclose(fil); \ 00044 } 00045 00046 00047 00048 MyMinionSocket::MyMinionSocket(SocketHandler& h) 00049 :MinionSocket(h) 00050 { 00051 } 00052 00053 00054 MyMinionSocket::MyMinionSocket(SocketHandler& h,const std::string& s,ipaddr_t a,port_t p) 00055 :MinionSocket(h,s,a,p) 00056 { 00057 } 00058 00059 00060 MyMinionSocket::~MyMinionSocket() 00061 { 00062 } 00063 00064 00065 bool MyMinionSocket::OnVerifiedLine(const std::string& cmd,Parse& pa) 00066 { 00067 FinderHandler& h = static_cast<FinderHandler&>(Handler()); 00068 Database& db = h.GetDatabase(); 00069 00070 D2(fprintf(fil,"MyMinionSocket verified command: %s\n",cmd.c_str());) 00071 00072 // 'post' _ typ : 64(category) : 64(tag) : 64(tag) : 64(tag) : 64(name) : data(64) : sz : sha1 00073 if (cmd == "post") 00074 { 00075 Query q(db); 00076 char sql[1000]; 00077 00078 std::string typ = pa.getword(); 00079 D2(fprintf(fil," post.typ == '%s'\n",typ.c_str());) 00080 if (typ != "File" && typ != "URL") 00081 { 00082 return true; 00083 } 00084 std::string strCategory = Utility::base64d(pa.getword()); 00085 /* 00086 std::string strTag1 = Utility::base64d(pa.getword()); 00087 std::string strTag2 = Utility::base64d(pa.getword()); 00088 std::string strTag3 = Utility::base64d(pa.getword()); 00089 */ 00090 std::string strName = Utility::base64d(pa.getword()); 00091 std::string strData = pa.getword(); 00092 size_t sz = pa.getvalue(); 00093 std::string strSha1 = pa.getword(); 00094 D2(fprintf(fil, 00095 "category: %s\n" 00096 "name: %s\n" 00097 "data: %s\n" 00098 "size: %d\n" 00099 "sha1: %s\n", strCategory.c_str(), 00100 strName.c_str(), strData.c_str(), sz, strSha1.c_str());) 00101 00102 sprintf(sql,"select * from category where name='%s'", q.safestr(strCategory).c_str()); 00103 db::Category cat(&db, sql); 00104 cat.name = strCategory; 00105 cat.save(); 00106 00107 db::Item item(db, sz, strSha1); 00108 item.typ = typ; 00109 item.category = cat.num; 00110 item.name = strName; 00111 item.data.push_back( strData ); 00112 item.sz = sz; 00113 item.sha1 = strSha1; 00114 item.save(); 00115 00116 g_app->ShowBalloonTip("Minion", cat.name + ": " + item.name); 00117 00118 std::string strTag = pa.getword(); 00119 while (strTag.size()) 00120 { 00121 std::string tmp = Utility::base64d(strTag); 00122 sprintf(sql,"select * from tag where name='%s'", q.safestr(tmp).c_str()); 00123 db::Tag tag(&db, sql); 00124 tag.name = tmp; 00125 tag.save(); 00126 db::Linkitemtag x(db, item.num, tag.num); 00127 x.item = item.num; 00128 x.tag = tag.num; 00129 x.save(); 00130 // 00131 strTag = pa.getword(); 00132 } 00133 00134 } 00135 else 00136 { 00137 return MinionSocket::OnVerifiedLine(cmd, pa); 00138 } 00139 return true; 00140 } 00141 00142 00143 void MyMinionSocket::OnConnect() 00144 { 00145 MinionSocket::OnConnect(); 00146 std::string remote = this->GetRemoteHostname(); 00147 std::string remote_ip = this->GetRemoteAddress(); 00148 g_app->ShowBalloonTip("Minion", "Connected to " + remote + " (" + remote_ip + ")"); 00149 } 00150 00151 00152 void MyMinionSocket::OnAccept() 00153 { 00154 MinionSocket::OnAccept(); 00155 std::string remote = this->GetRemoteHostname(); 00156 std::string remote_ip = this->GetRemoteAddress(); 00157 g_app->ShowBalloonTip("Minion", "Incoming connection from " + remote + " (" + remote_ip + ")"); 00158 } 00159 00160

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