/*] Copyright (c) 2009-2010, Charles McGarvey [************************** **] All rights reserved. * * vi:ts=4 sw=4 tw=75 * * Distributable under the terms and conditions of the 2-clause BSD license; * see the file COPYING for a complete text of the license. * **************************************************************************/ #include "Service.hh" #include "Socket.hh" #define SOLICIT 0x1234ABCD #define RESPONSE 0xABCD1234 namespace Mf { int Service::handlePacket(SocketMultiplexer& sock, Packet& packet, const SocketAddress& address) { uint32_t magic = 0; try { packet >> magic; } catch (...) { return -1; } if (magic == SOLICIT) { Packet out; out << RESPONSE << mType << mName << mText; sock.socket().write(out); return 0; } return -1; } int ServiceFinder::handlePacket(SocketMultiplexer& sock, Packet& packet, const SocketAddress& address) { try { uint32_t magic; packet >> magic; if (magic == RESPONSE) { std::string type; packet >> type; if (type == mType) { std::string name; std::string text; packet >> name >> text; mServices.insert(std::make_pair(name, Service(address, name, text))); return 0; } } } catch (...) { } return -1; } ServiceFinder::ServiceFinder(const std::string& type, int sockType) { } } // namespace Mf