From 30bec92571ba23f1f2aa6b12149f6545a4ef0d7e Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Mon, 15 Sep 2008 04:46:28 +0200 Subject: Hosts k?nnen jetzt aufgelistet werden --- src/Net/Packet.h | 3 +- src/Net/Packets/HostStatusPacket.h | 1 - src/Net/Packets/Makefile.am | 4 +-- src/Net/Packets/Makefile.in | 7 ++-- src/Net/Packets/NameListPacket.cpp | 56 ++++++++++++++++++++++++++++++++ src/Net/Packets/NameListPacket.h | 65 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 129 insertions(+), 7 deletions(-) create mode 100644 src/Net/Packets/NameListPacket.cpp create mode 100644 src/Net/Packets/NameListPacket.h (limited to 'src/Net') diff --git a/src/Net/Packet.h b/src/Net/Packet.h index e94f2ff..59e794d 100644 --- a/src/Net/Packet.h +++ b/src/Net/Packet.h @@ -33,7 +33,8 @@ class Packet { enum Type { OK = 0x0000, ERROR = 0x0001, DISCONNECT = 0x0002, GSSAPI_AUTH = 0x0010, IDENTIFY = 0x0011, - CORE_STATUS = 0x0020, DAEMON_STATUS = 0x0021 + LIST_DAEMONS = 0x0020, + CORE_STATUS = 0x0030, DAEMON_STATUS = 0x0031 }; struct Data { diff --git a/src/Net/Packets/HostStatusPacket.h b/src/Net/Packets/HostStatusPacket.h index f023917..0de63de 100644 --- a/src/Net/Packets/HostStatusPacket.h +++ b/src/Net/Packets/HostStatusPacket.h @@ -50,7 +50,6 @@ class HostStatusPacket : public Packet { } HostStatusPacket(const HostStatusPacket &p) : Packet(p) { - setLength(sizeof(CoreStatusData)); coreStatusData = (CoreStatusData*)&rawData->data; } diff --git a/src/Net/Packets/Makefile.am b/src/Net/Packets/Makefile.am index e65e543..9e1f589 100644 --- a/src/Net/Packets/Makefile.am +++ b/src/Net/Packets/Makefile.am @@ -1,4 +1,4 @@ noinst_LTLIBRARIES = libpackets.la -libpackets_la_SOURCES = HostStatusPacket.cpp +libpackets_la_SOURCES = HostStatusPacket.cpp NameListPacket.cpp -noinst_HEADERS = HostStatusPacket.h +noinst_HEADERS = HostStatusPacket.h NameListPacket.h diff --git a/src/Net/Packets/Makefile.in b/src/Net/Packets/Makefile.in index b6a7338..6a7e39f 100644 --- a/src/Net/Packets/Makefile.in +++ b/src/Net/Packets/Makefile.in @@ -45,7 +45,7 @@ CONFIG_HEADER = $(top_builddir)/src/config.h CONFIG_CLEAN_FILES = LTLIBRARIES = $(noinst_LTLIBRARIES) libpackets_la_LIBADD = -am_libpackets_la_OBJECTS = HostStatusPacket.lo +am_libpackets_la_OBJECTS = HostStatusPacket.lo NameListPacket.lo libpackets_la_OBJECTS = $(am_libpackets_la_OBJECTS) DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/src depcomp = $(SHELL) $(top_srcdir)/depcomp @@ -184,8 +184,8 @@ target_alias = @target_alias@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ noinst_LTLIBRARIES = libpackets.la -libpackets_la_SOURCES = HostStatusPacket.cpp -noinst_HEADERS = HostStatusPacket.h +libpackets_la_SOURCES = HostStatusPacket.cpp NameListPacket.cpp +noinst_HEADERS = HostStatusPacket.h NameListPacket.h all: all-am .SUFFIXES: @@ -238,6 +238,7 @@ distclean-compile: -rm -f *.tab.c @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/HostStatusPacket.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/NameListPacket.Plo@am__quote@ .cpp.o: @am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< diff --git a/src/Net/Packets/NameListPacket.cpp b/src/Net/Packets/NameListPacket.cpp new file mode 100644 index 0000000..19f588a --- /dev/null +++ b/src/Net/Packets/NameListPacket.cpp @@ -0,0 +1,56 @@ +/* + * NameListPacket.cpp + * + * Copyright (C) 2008 Matthias Schiffer + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#include "NameListPacket.h" +#include +#include + +namespace Mad { +namespace Net { +namespace Packets { + +void NameListPacket::assemblePacket() { + std::ostringstream stream; + + for(std::vector::iterator name = nameList.begin(); name != nameList.end(); ++name) + stream << *name << std::endl; + + std::string str = stream.str(); + + setLength(str.length()); + std::memcpy(rawData->data, str.c_str(), str.length()); +} + +void NameListPacket::parsePacket() { + nameList.clear(); + + std::istringstream stream(std::string((char*)getData(), getLength())); + + while(!stream.eof()) { + std::string str; + std::getline(stream, str); + + if(!str.empty()) + nameList.push_back(str); + } +} + +} +} +} diff --git a/src/Net/Packets/NameListPacket.h b/src/Net/Packets/NameListPacket.h new file mode 100644 index 0000000..89cc040 --- /dev/null +++ b/src/Net/Packets/NameListPacket.h @@ -0,0 +1,65 @@ +/* + * NameListPacket.h + * + * Copyright (C) 2008 Matthias Schiffer + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#ifndef MAD_NET_PACKETS_NAMELISTPACKET_H_ +#define MAD_NET_PACKETS_NAMELISTPACKET_H_ + +#include "../Packet.h" + +#include +#include + + +namespace Mad { +namespace Net { +namespace Packets { + +class NameListPacket : public Packet { + protected: + std::vector nameList; + + void assemblePacket(); + void parsePacket(); + + public: + NameListPacket(Type type, uint16_t requestId, const std::vector &nameList0) : Packet(type, requestId), nameList(nameList0) { + assemblePacket(); + } + + NameListPacket(const Packet &p) : Packet(p) { + parsePacket(); + } + + NameListPacket& operator=(const Packet &p) { + Packet::operator=(p); + parsePacket(); + + return *this; + } + + const std::vector& getNameList() const { + return nameList; + } +}; + +} +} +} + +#endif /* MAD_NET_PACKETS_NAMELISTPACKET_H_ */ -- cgit v1.2.3