Changeset 1365
- Timestamp:
- 06/01/05 21:09:25 (4 years ago)
- Files:
-
- testing/cgcomm/cgcomm.cpp (modified) (1 diff)
- testing/cgcomm/cgcomm.h (modified) (4 diffs)
- testing/cgcomm/cgcomm.vcproj (added)
- testing/cgcomm/client.cpp (modified) (4 diffs)
- testing/cgcomm/client.h (modified) (3 diffs)
- testing/cgcomm/opcodes.h (added)
- testing/cgcomm/sub_auth.cpp (modified) (1 diff)
- testing/cgcomm/sub_auth.h (modified) (1 diff)
- testing/cgcomm/sub_config.cpp (modified) (1 diff)
- testing/cgcomm/sub_config.h (modified) (1 diff)
- testing/cgcomm/sub_download.cpp (modified) (1 diff)
- testing/cgcomm/sub_download.h (modified) (1 diff)
- testing/cgcomm/sub_ext.cpp (modified) (1 diff)
- testing/cgcomm/sub_ext.h (modified) (3 diffs)
- testing/cgcomm/sub_hasher.cpp (modified) (1 diff)
- testing/cgcomm/sub_hasher.h (modified) (3 diffs)
- testing/cgcomm/sub_log.cpp (modified) (1 diff)
- testing/cgcomm/sub_log.h (modified) (3 diffs)
- testing/cgcomm/sub_plugins.cpp (modified) (1 diff)
- testing/cgcomm/sub_plugins.h (modified) (3 diffs)
- testing/cgcomm/sub_search.cpp (modified) (7 diffs)
- testing/cgcomm/sub_search.h (modified) (3 diffs)
- testing/cgcomm/sub_shared.cpp (modified) (1 diff)
- testing/cgcomm/sub_shared.h (modified) (3 diffs)
- testing/cgcomm/subsysbase.cpp (modified) (1 diff)
- testing/cgcomm/subsysbase.h (modified) (2 diffs)
- testing/cgcomm/tag.h (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
testing/cgcomm/cgcomm.cpp
r1290 r1365 32 32 m_listener, this, &ModMain::onIncoming 33 33 ); 34 logMsg("Core/GUI Communication listening on port 9990"); 35 return true; 34 36 } 35 37 int ModMain::onExit() { 36 38 m_listener->destroy(); 39 return 0; 37 40 } 38 41 39 42 void ModMain::onIncoming(SocketServer *sock, SocketEvent evt) { 40 boost::shared_ptr<Client> c(new Client(sock->accept())); 43 Client *c = new Client(sock->accept()); 44 c->getEventTable().addHandler(c, this, &ModMain::onClientEvent); 41 45 m_clients.insert(c); 46 } 47 void ModMain::onClientEvent(Client *c, int evt) { 48 if (evt == EVT_DESTROY) { 49 m_clients.erase(c); 50 delete c; 51 } 42 52 } 43 53 testing/cgcomm/cgcomm.h
r1290 r1365 1 1 /* 2 * Copyright (C) 200 4-2005 Alo Sarv <madcat_@users.sourceforge.net>2 * Copyright (C) 2005 Alo Sarv <madcat_@users.sourceforge.net> 3 3 * 4 4 * This program is free software; you can redistribute it and/or modify … … 17 17 */ 18 18 19 #ifndef __CGCOMM_H__ 20 #define __CGCOMM_H__ 21 19 22 #include <hn/modules.h> 20 23 #include <hn/sockets.h> … … 30 33 private: 31 34 void onIncoming(SocketServer *sock, SocketEvent evt); 35 void onClientEvent(Client *c, int evt); 36 32 37 SocketServer *m_listener; 33 typedef std::set< boost::shared_ptr<Client>> ClientMap;38 typedef std::set<Client*> ClientMap; 34 39 ClientMap m_clients; 35 40 typedef ClientMap::iterator Iter; … … 38 43 } 39 44 45 #endif testing/cgcomm/client.cpp
r1290 r1365 1 /* 2 * Copyright (C) 2005 Alo Sarv <madcat_@users.sourceforge.net> 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 */ 18 1 19 #include "client.h" 2 20 #include "subsysbase.h" … … 10 28 #include "sub_search.h" 11 29 #include "sub_shared.h" 30 #include "opcodes.h" 12 31 13 32 namespace CGComm { 14 33 15 enum SubSystems { 16 SUB_AUTH = 0x01, 17 SUB_SEARCH = 0x02, 18 SUB_DOWNLOAD = 0x03, 19 SUB_SHARED = 0x04, 20 SUB_CONFIG = 0x05, 21 SUB_HASHER = 0x06, 22 SUB_PLUGINS = 0x07, 23 SUB_LOG = 0x08, 24 SUB_EXT = 0xff 25 }; 34 IMPLEMENT_EVENT_TABLE(Client, Client*, int); 26 35 27 36 Client::Client(SocketClient *sock) : m_socket(sock) { … … 43 52 void Client::parse(const std::string &data) { 44 53 m_buffer.append(data); 45 while (true) { 46 if (m_buffer.size() < 6) { 54 while (m_buffer.size() > 4) { 55 std::istringstream tmp(m_buffer); 56 uint8_t subsys = Utils::getVal<uint8_t>(tmp); 57 uint16_t size = Utils::getVal<uint16_t>(tmp); 58 if (m_buffer.size() < size + 3u) { 47 59 return; 48 60 } 49 std::istringstream tmp(m_buffer); 50 uint8_t proto = Utils::getVal<uint8_t>(tmp); 51 CHECK_THROW(proto == 0x01); 52 uint16_t size = Utils::getVal<uint16_t>(tmp); 53 if (m_buffer.size() < size + 5) { 54 return; 55 } 56 std::istringstream packet(m_buffer.substr(5, size)); 57 m_buffer.erase(0, size + 5); 58 uint8_t subsystem = Utils::getVal<uint8_t>(packet); 59 Iter it = m_subMap.find(subsystem); 61 std::istringstream packet(m_buffer.substr(3, size)); 62 Iter it = m_subMap.find(subsys); 60 63 if (it == m_subMap.end()) { 61 64 logWarning( 62 65 boost::format("Unknown subsystem %s") 63 % Utils::hexDump(subsys tem)66 % Utils::hexDump(subsys) 64 67 ); 65 68 continue; … … 67 70 (*it).second->handle(packet); 68 71 } 72 m_buffer.erase(0, size + 3); 69 73 } 74 } 75 76 void Client::onSocketEvent(SocketClient *sock, SocketEvent evt) { 77 if (evt == SOCK_READ) { 78 std::string buf; 79 *sock >> buf; 80 return parse(buf); 81 } else if (evt == SOCK_LOST || evt == SOCK_TIMEOUT || evt == SOCK_ERR) { 82 destroy(); 83 } 84 } 85 86 void Client::destroy() { 87 getEventTable().postEvent(this, EVT_DESTROY); 88 m_socket->destroy(); 70 89 } 71 90 testing/cgcomm/client.h
r1290 r1365 1 /* 2 * Copyright (C) 2005 Alo Sarv <madcat_@users.sourceforge.net> 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 */ 18 1 19 #ifndef __CLIENT_H__ 2 20 #define __CLIENT_H__ … … 8 26 namespace CGComm { 9 27 class SubSysBase; 28 enum ClientEvents { 29 EVT_DESTROY 30 }; 10 31 11 32 class Client { 12 33 public: 34 DECLARE_EVENT_TABLE(Client*, int); 35 13 36 Client(SocketClient *sock); 37 38 void destroy(); 14 39 private: 15 40 void parse(const std::string &data); … … 24 49 }; 25 50 26 enum OpCodes {27 OC_LIST = 0x01,28 OC_MONITOR = 0x02,29 OC_CANCEL = 0x03,30 OC_PAUSE = 0x04,31 OC_RESUME = 0x05,32 OC_ADD = 0x06,33 OC_REMOVE = 0x07,34 OC_SET = 0x08,35 OC_GET = 0x0936 };37 38 51 } // CGComm 39 52 testing/cgcomm/sub_auth.cpp
r1290 r1365 1 /* 2 * Copyright (C) 2005 Alo Sarv <madcat_@users.sourceforge.net> 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 */ 18 19 #include "sub_auth.h" 20 #include "opcodes.h" 21 22 namespace CGComm { 23 namespace Subsystem { 24 25 Auth::Auth(SocketClient *sock) : SubSysBase(sock, SUB_AUTH) {} 26 void Auth::handle(std::istream &i) {} 27 28 } 29 } 30 testing/cgcomm/sub_auth.h
r1290 r1365 1 /* 2 * Copyright (C) 2005 Alo Sarv <madcat_@users.sourceforge.net> 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 */ 18 1 19 #ifndef __SUB_AUTH_H__ 2 20 #define __SUB_AUTH_H__ testing/cgcomm/sub_config.cpp
r1290 r1365 1 /* 2 * Copyright (C) 2005 Alo Sarv <madcat_@users.sourceforge.net> 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 */ 18 19 #include "sub_config.h" 20 #include "opcodes.h" 21 22 namespace CGComm { 23 namespace Subsystem { 24 25 Config::Config(SocketClient *sock) : SubSysBase(sock, SUB_CONFIG) {} 26 void Config::handle(std::istream &i) {} 27 28 } 29 } testing/cgcomm/sub_config.h
r1290 r1365 1 /* 2 * Copyright (C) 2005 Alo Sarv <madcat_@users.sourceforge.net> 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 */ 18 1 19 #ifndef __SUB_CONFIG_H__ 2 20 #define __SUB_CONFIG_H__ testing/cgcomm/sub_download.cpp
r1290 r1365 1 /* 2 * Copyright (C) 2005 Alo Sarv <madcat_@users.sourceforge.net> 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 */ 18 19 #include "sub_download.h" 20 #include "opcodes.h" 21 22 namespace CGComm { 23 namespace Subsystem { 24 25 Download::Download(SocketClient *sock) : SubSysBase(sock, SUB_DOWNLOAD) {} 26 void Download::handle(std::istream &i) {} 27 28 } 29 } testing/cgcomm/sub_download.h
r1290 r1365 1 /* 2 * Copyright (C) 2005 Alo Sarv <madcat_@users.sourceforge.net> 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 */ 18 1 19 #ifndef __SUB_DOWNLOAD_H__ 2 20 #define __SUB_DOWNLOAD_H__ testing/cgcomm/sub_ext.cpp
r1290 r1365 1 /* 2 * Copyright (C) 2005 Alo Sarv <madcat_@users.sourceforge.net> 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 */ 18 19 #include "sub_ext.h" 20 #include "opcodes.h" 21 22 namespace CGComm { 23 namespace Subsystem { 24 25 Ext::Ext(SocketClient *sock) : SubSysBase(sock, SUB_EXT) {} 26 void Ext::handle(std::istream &i) {} 27 28 29 } 30 } testing/cgcomm/sub_ext.h
r1290 r1365 1 /* 2 * Copyright (C) 2005 Alo Sarv <madcat_@users.sourceforge.net> 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 */ 18 19 1 20 #ifndef __SUB_EXT_H__ 2 21 #define __SUB_EXT_H__ … … 5 24 namespace CGComm { 6 25 namespace Subsystem { 26 7 27 class Ext : public SubSysBase { 8 28 public: … … 10 30 virtual void handle(std::istream &i); 11 31 }; 32 12 33 } 13 34 } testing/cgcomm/sub_hasher.cpp
r1290 r1365 1 /* 2 * Copyright (C) 2005 Alo Sarv <madcat_@users.sourceforge.net> 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 */ 18 19 #include "sub_hasher.h" 20 #include "opcodes.h" 21 22 namespace CGComm { 23 namespace Subsystem { 24 25 Hasher::Hasher(SocketClient *sock) : SubSysBase(sock, SUB_HASHER) {} 26 void Hasher::handle(std::istream &i) {} 27 28 } 29 } testing/cgcomm/sub_hasher.h
r1290 r1365 1 /* 2 * Copyright (C) 2005 Alo Sarv <madcat_@users.sourceforge.net> 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 */ 18 1 19 #ifndef __SUB_HASHER_H__ 2 20 #define __SUB_HASHER_H__ … … 5 23 namespace CGComm { 6 24 namespace Subsystem { 25 7 26 class Hasher : public SubSysBase { 8 27 public: … … 10 29 virtual void handle(std::istream &i); 11 30 }; 31 12 32 } 13 33 } testing/cgcomm/sub_log.cpp
r1290 r1365 1 /* 2 * Copyright (C) 2005 Alo Sarv <madcat_@users.sourceforge.net> 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 */ 18 19 #include "sub_log.h" 20 #include "opcodes.h" 21 22 namespace CGComm { 23 namespace Subsystem { 24 25 Log::Log(SocketClient *sock) : SubSysBase(sock, SUB_LOG) {} 26 void Log::handle(std::istream &i) {} 27 28 } 29 } testing/cgcomm/sub_log.h
r1290 r1365 1 /* 2 * Copyright (C) 2005 Alo Sarv <madcat_@users.sourceforge.net> 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 */ 18 1 19 #ifndef __SUB_LOG_H__ 2 20 #define __SUB_LOG_H__ … … 5 23 namespace CGComm { 6 24 namespace Subsystem { 25 7 26 class Log : public SubSysBase { 8 27 public: … … 10 29 virtual void handle(std::istream &i); 11 30 }; 31 12 32 } 13 33 } testing/cgcomm/sub_plugins.cpp
r1290 r1365 1 /* 2 * Copyright (C) 2005 Alo Sarv <madcat_@users.sourceforge.net> 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 */ 18 19 #include "sub_plugins.h" 20 #include "opcodes.h" 21 22 23 namespace CGComm { 24 namespace Subsystem { 25 26 Plugins::Plugins(SocketClient *sock) : SubSysBase(sock, SUB_PLUGINS) {} 27 void Plugins::handle(std::istream &i) {} 28 29 } 30 } testing/cgcomm/sub_plugins.h
r1290 r1365 1 /* 2 * Copyright (C) 2005 Alo Sarv <madcat_@users.sourceforge.net> 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 */ 18 1 19 #ifndef __SUB_PLUGINS_H__ 2 20 #define __SUB_PLUGINS_H__ … … 5 23 namespace CGComm { 6 24 namespace Subsystem { 25 7 26 class Plugins : public SubSysBase { 8 27 public: … … 10 29 virtual void handle(std::istream &i); 11 30 }; 31 12 32 } 13 33 } testing/cgcomm/sub_search.cpp
r1290 r1365 1 /* 2 * Copyright (C) 2005 Alo Sarv <madcat_@users.sourceforge.net> 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 */ 18 1 19 #include "sub_search.h" 2 20 #include <hn/search.h> … … 4 22 #include <hn/sockets.h> 5 23 #include <boost/bind.hpp> 24 #include "tag.h" 25 #include "opcodes.h" 6 26 7 27 namespace CGComm { 8 28 namespace Subsystem { 9 29 10 Search::Search(SocketClient *sock) : SubSysBase(sock), m_lastResultCount() {} 30 Search::Search(SocketClient *sock) : SubSysBase(sock, SUB_SEARCH), 31 m_lastResultCount() {} 11 32 12 33 void Search::handle(std::istream &i) { 13 34 uint8_t oc = Utils::getVal<uint8_t>(i); 14 35 switch (oc) { 15 case 0x00: perform(i); break; 36 case OC_GET: perform(i); break; 37 case OC_DOWNLOAD: download(i); break; 16 38 default: break; 17 39 } … … 23 45 uint64_t minSize = 0; 24 46 uint64_t maxSize = 0; 47 uint32_t filetype; 25 48 uint16_t tc = getVal<uint16_t>(i); 26 49 while (i && tc--) { … … 28 51 uint16_t len = getVal<uint16_t>(i); 29 52 switch (oc) { 30 case 0x01:53 case TAG_KEYWORDS: 31 54 str = getVal<std::string>(i, len); 32 55 break; 33 case 0x02:56 case TAG_MINSIZE: 34 57 minSize = getVal<uint64_t>(i); 35 58 break; 36 case 0x03:59 case TAG_MAXSIZE: 37 60 maxSize = getVal<uint64_t>(i); 38 61 break; 62 case TAG_FILETYPE: 63 filetype = getVal<uint32_t>(i); 64 break; 39 65 default: 66 i.seekg(len, std::ios::cur); 40 67 break; 41 68 } … … 46 73 boost::bind(&Search::foundResults, this, _1) 47 74 ); 75 m_currentSearch->setType(FileType(filetype)); 48 76 if (minSize) { 49 77 m_currentSearch->setMinSize(minSize); … … 55 83 } 56 84 85 void Search::download(std::istream &i) { 86 logDebug( 87 boost::format("CurrentSearch has %d results in it.") 88 % m_currentSearch->getResultCount() 89 ); 90 uint32_t id = Utils::getVal<uint32_t>(i); 91 if (m_currentSearch && id <= m_currentSearch->getResultCount()) { 92 logDebug( 93 boost::format("Starting download from searchResult #%d") 94 % id 95 ); 96 m_currentSearch->getResult(id)->download(); 97 } else { 98 logDebug(boost::format("No such search result (%d)") % id); 99 } 100 } 57 101 void Search::foundResults(SearchPtr ptr) { 58 102 //! \todo Check if search was in progress … … 61 105 uint32_t cnt = 0; 62 106 for (uint32_t i = m_lastResultCount; i < ptr->getResultCount(); ++i) { 107 SearchResultPtr res = ptr->getResult(i); 63 108 std::ostringstream tmpR; 64 SearchResultPtr res = ptr->getResult(i); 65 putVal<uint8_t>(tmpR, 0x02); 66 putVal<uint16_t>(tmpR, res->getName().size()); 67 putVal<std::string>(tmpR, res->getName()); 68 putVal<uint64_t>(tmpR, res->getSize()); 69 putVal<uint32_t>(tmpR, res->getSources()); 109 putVal<uint8_t>(tmpR, 3); // tagcount 110 tmpR << makeTag(TAG_FILENAME, res->getName()); 111 tmpR << makeTag(TAG_FILESIZE, res->getSize()); 112 tmpR << makeTag(TAG_SRCCNT, res->getSources()); 70 113 putVal(tmp, tmpR.str(), tmpR.str().size()); 71 114 ++cnt; 72 115 } 73 116 std::ostringstream packet; 74 putVal<uint8_t>(packet, 0x01);75 putVal<uint 16_t>(packet, tmp.str().size());117 putVal<uint8_t>(packet, OP_SEARCHRESULTS); 118 putVal<uint32_t>(packet, cnt); 76 119 putVal(packet, tmp.str(), tmp.str().size()); 77 m_socket->write(packet.str().data(), packet.str().size()); 120 sendPacket(packet.str()); 121 m_lastResultCount = ptr->getResultCount(); 122 logDebug( 123 boost::format("Sent %d sources to GUI") % ptr->getResultCount() 124 ); 78 125 } 79 126 testing/cgcomm/sub_search.h
r1290 r1365 1 /* 2 * Copyright (C) 2005 Alo Sarv <madcat_@users.sourceforge.net> 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 */ 18 1 19 #ifndef __SUB_SEARCH_H__ 2 20 #define __SUB_SEARCH_H__ … … 8 26 namespace CGComm { 9 27 namespace Subsystem { 28 10 29 class Search : public SubSysBase { 11 30 public: … … 14 33 private: 15 34 void perform(std::istream &i); 35 void download(std::istream &i); 16 36 void foundResults(SearchPtr ptr); 37 17 38 SearchPtr m_currentSearch; 18 39 uint32_t m_lastResultCount; 19 40 }; 41 20 42 } 21 43 } testing/cgcomm/sub_shared.cpp
r1290 r1365 1 /* 2 * Copyright (C) 2005 Alo Sarv <madcat_@users.sourceforge.net> 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 */ 18 19 #include "sub_shared.h" 20 #include "opcodes.h" 21 22 namespace CGComm { 23 namespace Subsystem { 24 25 Shared::Shared(SocketClient *sock) : SubSysBase(sock, SUB_SHARED) {} 26 void Shared::handle(std::istream &i) {} 27 28 } 29 } testing/cgcomm/sub_shared.h
r1290 r1365 1 /* 2 * Copyright (C) 2005 Alo Sarv <madcat_@users.sourceforge.net> 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 */ 18 1 19 #ifndef __SUB_SHARED_H__ 2 20 #define __SUB_SHARED_H__ … … 5 23 namespace CGComm { 6 24 namespace Subsystem { 25 7 26 class Shared : public SubSysBase { 8 27 public: … … 10 29 virtual void handle(std::istream &i); 11 30 }; 31 12 32 } 13 33 } testing/cgcomm/subsysbase.cpp
r1290 r1365 1 /* 2 * Copyright (C) 2005 Alo Sarv <madcat_@users.sourceforge.net> 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 */ 18 19 #include <hn/osdep.h>&n
