diff options
39 files changed, 1550 insertions, 135 deletions
@@ -20869,7 +20869,7 @@ echo "$as_me: error: Test for GNU readline library failed." >&2;} fi -ac_config_files="$ac_config_files Makefile src/Makefile src/Client/Makefile src/Client/Request/Makefile src/Common/Makefile src/Common/Request/Makefile src/Core/Makefile src/Core/RequestHandler/Makefile src/Net/Makefile" +ac_config_files="$ac_config_files Makefile src/Makefile src/Client/Makefile src/Client/Request/Makefile src/Common/Makefile src/Common/Backends/Makefile src/Common/Request/Makefile src/Core/Makefile src/Core/RequestHandler/Makefile src/Net/Makefile src/Net/Packets/Makefile" cat >confcache <<\_ACEOF @@ -21470,10 +21470,12 @@ do "src/Client/Makefile") CONFIG_FILES="$CONFIG_FILES src/Client/Makefile" ;; "src/Client/Request/Makefile") CONFIG_FILES="$CONFIG_FILES src/Client/Request/Makefile" ;; "src/Common/Makefile") CONFIG_FILES="$CONFIG_FILES src/Common/Makefile" ;; + "src/Common/Backends/Makefile") CONFIG_FILES="$CONFIG_FILES src/Common/Backends/Makefile" ;; "src/Common/Request/Makefile") CONFIG_FILES="$CONFIG_FILES src/Common/Request/Makefile" ;; "src/Core/Makefile") CONFIG_FILES="$CONFIG_FILES src/Core/Makefile" ;; "src/Core/RequestHandler/Makefile") CONFIG_FILES="$CONFIG_FILES src/Core/RequestHandler/Makefile" ;; "src/Net/Makefile") CONFIG_FILES="$CONFIG_FILES src/Net/Makefile" ;; + "src/Net/Packets/Makefile") CONFIG_FILES="$CONFIG_FILES src/Net/Packets/Makefile" ;; *) { { echo "$as_me:$LINENO: error: invalid argument: $ac_config_target" >&5 echo "$as_me: error: invalid argument: $ac_config_target" >&2;} diff --git a/configure.ac b/configure.ac index 40c04a5..bdfcd00 100644 --- a/configure.ac +++ b/configure.ac @@ -39,10 +39,12 @@ AC_CONFIG_FILES([ src/Client/Makefile src/Client/Request/Makefile src/Common/Makefile + src/Common/Backends/Makefile src/Common/Request/Makefile src/Core/Makefile src/Core/RequestHandler/Makefile src/Net/Makefile + src/Net/Packets/Makefile ]) AC_OUTPUT diff --git a/src/Client/CommandParser.cpp b/src/Client/CommandParser.cpp index 4faec95..6f5f38b 100644 --- a/src/Client/CommandParser.cpp +++ b/src/Client/CommandParser.cpp @@ -84,7 +84,7 @@ void CommandParser::helpCommand(const std::vector<std::string> &args) { void CommandParser::statusCommand(const std::vector<std::string>&) { activeRequests++; - Common::Request::CoreStatusRequest::send(connection, *requestManager, sigc::mem_fun(this, &CommandParser::requestFinished)); + Common::Request::CoreStatusRequest::send(connection, *requestManager, sigc::mem_fun(this, &CommandParser::coreStatusRequestFinished)); } void CommandParser::exitCommand(const std::vector<std::string>&) { @@ -94,6 +94,40 @@ void CommandParser::exitCommand(const std::vector<std::string>&) { Common::Request::DisconnectRequest::send(connection, *requestManager, sigc::mem_fun(this, &CommandParser::requestFinished)); } +void CommandParser::coreStatusRequestFinished(const Net::Packets::CoreStatusPacket &packet) { + std::cout << "Server status:" << std::endl; + + if(packet.getUptime()) { + unsigned long days = packet.getUptime()/86400; + unsigned long hours = (packet.getUptime()%86400)/3600; + unsigned long minutes = (packet.getUptime()%3600)/60; + + std::cout << "\tUptime: "; + + if(days) std::cout << days << " days "; + + std::cout << hours << ":"; + + std::streamsize width = std::cout.width(2); + std::cout.fill('0'); + std::cout << minutes; + + std::cout.width(width); + + if(packet.getIdleTime()) { + std::streamsize prec = std::cout.precision(3); + std::cout << " (load average: " << (100.0f-(packet.getIdleTime()*100.0f/packet.getUptime())) << "%)"; + std::cout.precision(prec); + } + + std::cout << std::endl; + } + + std::cout << std::endl; + + requestFinished(); +} + bool CommandParser::split(const std::string &str, std::vector<std::string> &ret) { std::string temp; bool quoteSingle = false, quoteDouble = false, escape = false; diff --git a/src/Client/CommandParser.h b/src/Client/CommandParser.h index 891323f..34f7a28 100644 --- a/src/Client/CommandParser.h +++ b/src/Client/CommandParser.h @@ -32,6 +32,11 @@ class RequestManager; namespace Net { class Connection; + +namespace Packets { +class CoreStatusPacket; +} + } namespace Client { @@ -59,12 +64,6 @@ class CommandParser { bool split(const std::string &str, std::vector<std::string> &ret); - void requestFinished() { - activeRequests--; - - finished(); - } - const Command* findCommand(const std::string& command); void printUsage(const std::string& command); @@ -72,6 +71,14 @@ class CommandParser { void statusCommand(const std::vector<std::string>&); void exitCommand(const std::vector<std::string>&); + void coreStatusRequestFinished(const Net::Packets::CoreStatusPacket &packet); + + void requestFinished() { + activeRequests--; + + finished(); + } + public: CommandParser(Common::RequestManager *requestManager0, Net::Connection *connection0) : requestManager(requestManager0), connection(connection0), activeRequests(0), disconnect(false) {} diff --git a/src/Common/Backends/Makefile.am b/src/Common/Backends/Makefile.am new file mode 100644 index 0000000..aa705d8 --- /dev/null +++ b/src/Common/Backends/Makefile.am @@ -0,0 +1,5 @@ +noinst_LTLIBRARIES = libbackends.la +libbackends_la_SOURCES = SystemBackendProc.cpp + +noinst_HEADERS = SystemBackendProc.h + diff --git a/src/Common/Backends/Makefile.in b/src/Common/Backends/Makefile.in new file mode 100644 index 0000000..431e582 --- /dev/null +++ b/src/Common/Backends/Makefile.in @@ -0,0 +1,442 @@ +# Makefile.in generated by automake 1.10.1 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + + +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +subdir = src/Common/Backends +DIST_COMMON = $(noinst_HEADERS) $(srcdir)/Makefile.am \ + $(srcdir)/Makefile.in +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/src/config.h +CONFIG_CLEAN_FILES = +LTLIBRARIES = $(noinst_LTLIBRARIES) +libbackends_la_LIBADD = +am_libbackends_la_OBJECTS = SystemBackendProc.lo +libbackends_la_OBJECTS = $(am_libbackends_la_OBJECTS) +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/src +depcomp = $(SHELL) $(top_srcdir)/depcomp +am__depfiles_maybe = depfiles +CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) +LTCXXCOMPILE = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) +CXXLD = $(CXX) +CXXLINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=link $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) \ + $(LDFLAGS) -o $@ +SOURCES = $(libbackends_la_SOURCES) +DIST_SOURCES = $(libbackends_la_SOURCES) +HEADERS = $(noinst_HEADERS) +ETAGS = etags +CTAGS = ctags +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DSYMUTIL = @DSYMUTIL@ +ECHO = @ECHO@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +F77 = @F77@ +FFLAGS = @FFLAGS@ +GREP = @GREP@ +GnuTLS_CFLAGS = @GnuTLS_CFLAGS@ +GnuTLS_LIBS = @GnuTLS_LIBS@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LDFLAGS = @LDFLAGS@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +MAINT = @MAINT@ +MAKEINFO = @MAKEINFO@ +MKDIR_P = @MKDIR_P@ +NMEDIT = @NMEDIT@ +OBJEXT = @OBJEXT@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PKG_CONFIG = @PKG_CONFIG@ +RANLIB = @RANLIB@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +VERSION = @VERSION@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_F77 = @ac_ct_F77@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +sigc_CFLAGS = @sigc_CFLAGS@ +sigc_LIBS = @sigc_LIBS@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +noinst_LTLIBRARIES = libbackends.la +libbackends_la_SOURCES = SystemBackendProc.cpp +noinst_HEADERS = SystemBackendProc.h +all: all-am + +.SUFFIXES: +.SUFFIXES: .cpp .lo .o .obj +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \ + && exit 0; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/Common/Backends/Makefile'; \ + cd $(top_srcdir) && \ + $(AUTOMAKE) --gnu src/Common/Backends/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +clean-noinstLTLIBRARIES: + -test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES) + @list='$(noinst_LTLIBRARIES)'; for p in $$list; do \ + dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ + test "$$dir" != "$$p" || dir=.; \ + echo "rm -f \"$${dir}/so_locations\""; \ + rm -f "$${dir}/so_locations"; \ + done +libbackends.la: $(libbackends_la_OBJECTS) $(libbackends_la_DEPENDENCIES) + $(CXXLINK) $(libbackends_la_OBJECTS) $(libbackends_la_LIBADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SystemBackendProc.Plo@am__quote@ + +.cpp.o: +@am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ $< + +.cpp.obj: +@am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'` + +.cpp.lo: +@am__fastdepCXX_TRUE@ $(LTCXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(LTCXXCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonemtpy = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$tags $$unique; \ + fi +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + test -z "$(CTAGS_ARGS)$$tags$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$tags $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && cd $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) $$here + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ + fi; \ + cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ + else \ + test -f $(distdir)/$$file \ + || cp -p $$d/$$file $(distdir)/$$file \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(LTLIBRARIES) $(HEADERS) +installdirs: +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-libtool clean-noinstLTLIBRARIES \ + mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-exec-am: + +install-html: install-html-am + +install-info: install-info-am + +install-man: + +install-pdf: install-pdf-am + +install-ps: install-ps-am + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ + clean-libtool clean-noinstLTLIBRARIES ctags distclean \ + distclean-compile distclean-generic distclean-libtool \ + distclean-tags distdir dvi dvi-am html html-am info info-am \ + install install-am install-data install-data-am install-dvi \ + install-dvi-am install-exec install-exec-am install-html \ + install-html-am install-info install-info-am install-man \ + install-pdf install-pdf-am install-ps install-ps-am \ + install-strip installcheck installcheck-am installdirs \ + maintainer-clean maintainer-clean-generic mostlyclean \ + mostlyclean-compile mostlyclean-generic mostlyclean-libtool \ + pdf pdf-am ps ps-am tags uninstall uninstall-am + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/src/Common/Backends/SystemBackendProc.cpp b/src/Common/Backends/SystemBackendProc.cpp new file mode 100644 index 0000000..d33fbf3 --- /dev/null +++ b/src/Common/Backends/SystemBackendProc.cpp @@ -0,0 +1,53 @@ +/* + * SystemBackendProc.cpp + * + * Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#include "SystemBackendProc.h" +#include <fstream> + +namespace Mad { +namespace Common { +namespace Backends { + +SystemBackendProc::Uptime SystemBackendProc::getUptime() const { + Uptime uptime = {0, 0}; + + std::ifstream file("/proc/uptime"); + + if(!file.good()) + return uptime; + + float f; + file >> f; + if(!file.good()) + return uptime; + + uptime.uptime = (uint32_t)f; + + file >> f; + if(!file.good()) + return uptime; + + uptime.idleTime = (uint32_t)f; + + return uptime; +} + +} +} +} diff --git a/src/Common/Backends/SystemBackendProc.h b/src/Common/Backends/SystemBackendProc.h new file mode 100644 index 0000000..af34eee --- /dev/null +++ b/src/Common/Backends/SystemBackendProc.h @@ -0,0 +1,45 @@ +/* + * SystemBackendProc.h + * + * Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#ifndef MAD_COMMON_BACKENDS_SYSTEMBACKENDPROC_H_ +#define MAD_COMMON_BACKENDS_SYSTEMBACKENDPROC_H_ + +#include "../SystemBackend.h" + +namespace Mad { +namespace Common { +namespace Backends { + +class SystemBackendProc : public SystemBackend { + private: + SystemBackendProc() {} + + public: + static void useBackend() { + setBackend(new SystemBackendProc()); + } + + virtual Uptime getUptime() const; +}; + +} +} +} + +#endif /* MAD_COMMON_BACKENDS_SYSTEMBACKENDPROC_H_ */ diff --git a/src/Common/ConfigManager.cpp b/src/Common/ConfigManager.cpp index 4d0e476..a363862 100644 --- a/src/Common/ConfigManager.cpp +++ b/src/Common/ConfigManager.cpp @@ -19,6 +19,8 @@ #include "ConfigManager.h" #include "Util.h" +#include "Backends/SystemBackendProc.h" + #include <fstream> #include <stdexcept> @@ -90,5 +92,9 @@ bool ConfigManager::loadFile(const std::string &filename) { return true; } +void ConfigManager::initBackends() { + Backends::SystemBackendProc::useBackend(); +} + } } diff --git a/src/Common/ConfigManager.h b/src/Common/ConfigManager.h index 68669d3..5c94614 100644 --- a/src/Common/ConfigManager.h +++ b/src/Common/ConfigManager.h @@ -28,12 +28,16 @@ namespace Common { class ConfigManager { protected: - ConfigManager() {} + ConfigManager() { + initBackends(); + } virtual bool parseLine(const std::vector<std::string> §ion, const std::string &key, const std::string &value = std::string()) = 0; bool loadFile(const std::string &filename); + void initBackends(); + public: virtual ~ConfigManager() {} }; diff --git a/src/Common/Makefile.am b/src/Common/Makefile.am index f04f3db..cd1b8c0 100644 --- a/src/Common/Makefile.am +++ b/src/Common/Makefile.am @@ -1,6 +1,7 @@ -SUBDIRS = Request +SUBDIRS = Backends Request noinst_LTLIBRARIES = libcommon.la -libcommon_la_SOURCES = ConfigManager.cpp RequestManager.cpp +libcommon_la_SOURCES = ConfigManager.cpp RequestManager.cpp SystemBackend.cpp +libcommon_la_LIBADD = Backends/libbackends.la -noinst_HEADERS = ConfigManager.h RequestHandler.h RequestManager.h Util.h +noinst_HEADERS = ConfigManager.h RequestHandler.h RequestManager.h SystemBackend.h Util.h diff --git a/src/Common/Makefile.in b/src/Common/Makefile.in index 9e02df1..7c805e9 100644 --- a/src/Common/Makefile.in +++ b/src/Common/Makefile.in @@ -44,8 +44,9 @@ mkinstalldirs = $(install_sh) -d CONFIG_HEADER = $(top_builddir)/src/config.h CONFIG_CLEAN_FILES = LTLIBRARIES = $(noinst_LTLIBRARIES) -libcommon_la_LIBADD = -am_libcommon_la_OBJECTS = ConfigManager.lo RequestManager.lo +libcommon_la_DEPENDENCIES = Backends/libbackends.la +am_libcommon_la_OBJECTS = ConfigManager.lo RequestManager.lo \ + SystemBackend.lo libcommon_la_OBJECTS = $(am_libcommon_la_OBJECTS) DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/src depcomp = $(SHELL) $(top_srcdir)/depcomp @@ -189,10 +190,11 @@ sysconfdir = @sysconfdir@ target_alias = @target_alias@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ -SUBDIRS = Request +SUBDIRS = Backends Request noinst_LTLIBRARIES = libcommon.la -libcommon_la_SOURCES = ConfigManager.cpp RequestManager.cpp -noinst_HEADERS = ConfigManager.h RequestHandler.h RequestManager.h Util.h +libcommon_la_SOURCES = ConfigManager.cpp RequestManager.cpp SystemBackend.cpp +libcommon_la_LIBADD = Backends/libbackends.la +noinst_HEADERS = ConfigManager.h RequestHandler.h RequestManager.h SystemBackend.h Util.h all: all-recursive .SUFFIXES: @@ -246,6 +248,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ConfigManager.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/RequestManager.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SystemBackend.Plo@am__quote@ .cpp.o: @am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< diff --git a/src/Common/Request/CoreStatusRequest.h b/src/Common/Request/CoreStatusRequest.h index 97f8318..cd28cc2 100644 --- a/src/Common/Request/CoreStatusRequest.h +++ b/src/Common/Request/CoreStatusRequest.h @@ -23,7 +23,7 @@ #include "Request.h" #include "../RequestManager.h" #include <Net/Connection.h> -#include <Net/Packet.h> +#include <Net/Packets/CoreStatusPacket.h> #include <sigc++/signal.h> @@ -33,12 +33,12 @@ namespace Request { class CoreStatusRequest: public Request { private: - sigc::signal<void> finished; + sigc::signal<void,const Net::Packets::CoreStatusPacket&> finished; CoreStatusRequest() {} public: - static bool send(Net::Connection *connection, RequestManager &requestManager, const sigc::slot<void> &callback) { + static bool send(Net::Connection *connection, RequestManager &requestManager, const sigc::slot<void,const Net::Packets::CoreStatusPacket&> &callback) { CoreStatusRequest *request = new CoreStatusRequest(); request->finished.connect(callback); @@ -50,7 +50,7 @@ class CoreStatusRequest: public Request { return false; } - virtual bool sendRequest(Net::Connection *connection, unsigned short requestId) { + virtual bool sendRequest(Net::Connection *connection, uint16_t requestId) { if(isSent()) return false; @@ -68,7 +68,7 @@ class CoreStatusRequest: public Request { if(packet.getType() != Net::Packet::TYPE_OK) return false; // TODO Logging - finished(); + finished(Net::Packets::CoreStatusPacket(packet)); setFinished(); return true; diff --git a/src/Common/Request/DisconnectRequest.h b/src/Common/Request/DisconnectRequest.h index c20a3d0..3f6e018 100644 --- a/src/Common/Request/DisconnectRequest.h +++ b/src/Common/Request/DisconnectRequest.h @@ -50,7 +50,7 @@ class DisconnectRequest: public Request { return false; } - virtual bool sendRequest(Net::Connection *connection, unsigned short requestId) { + virtual bool sendRequest(Net::Connection *connection, uint16_t requestId) { if(isSent()) return false; diff --git a/src/Common/Request/GSSAPIAuthRequest.h b/src/Common/Request/GSSAPIAuthRequest.h index 138107e..ff92755 100644 --- a/src/Common/Request/GSSAPIAuthRequest.h +++ b/src/Common/Request/GSSAPIAuthRequest.h @@ -65,7 +65,7 @@ class GSSAPIAuthRequest : public Request { return false; } - virtual bool sendRequest(Net::Connection *connection, unsigned short requestId) { + virtual bool sendRequest(Net::Connection *connection, uint16_t requestId) { if(isSent()) return false; diff --git a/src/Common/Request/IdentifyRequest.h b/src/Common/Request/IdentifyRequest.h index e88ce4b..dfb6ce6 100644 --- a/src/Common/Request/IdentifyRequest.h +++ b/src/Common/Request/IdentifyRequest.h @@ -49,7 +49,7 @@ class IdentifyRequest: public Request { return false; } - virtual bool sendRequest(Net::Connection *connection, unsigned short requestId) { + virtual bool sendRequest(Net::Connection *connection, uint16_t requestId) { if(isSent()) return false; diff --git a/src/Common/Request/Request.h b/src/Common/Request/Request.h index 5c8d6c4..657a0a7 100644 --- a/src/Common/Request/Request.h +++ b/src/Common/Request/Request.h @@ -38,7 +38,7 @@ class Request : public RequestHandler { public: bool isSent() const {return sent;} - virtual bool sendRequest(Net::Connection *connection, unsigned short requestId) = 0; + virtual bool sendRequest(Net::Connection *connection, uint16_t requestId) = 0; }; } diff --git a/src/Common/RequestManager.cpp b/src/Common/RequestManager.cpp index 82fc1af..c9761d2 100644 --- a/src/Common/RequestManager.cpp +++ b/src/Common/RequestManager.cpp @@ -84,7 +84,7 @@ bool RequestManager::sendRequest(Net::Connection *connection, Request::Request * RequestMap *requestMap = it->second; - unsigned short id; + uint16_t id; do { id = getRequestId(); } while(requestMap->findRequest(id)); diff --git a/src/Common/RequestManager.h b/src/Common/RequestManager.h index 77eca52..a783fe2 100644 --- a/src/Common/RequestManager.h +++ b/src/Common/RequestManager.h @@ -33,7 +33,7 @@ class Request; class RequestManager { private: - class RequestMap : private std::map<unsigned short,RequestHandler*> { + class RequestMap : private std::map<uint16_t,RequestHandler*> { private: // Prevent shallow copy RequestMap(const RequestMap &o); @@ -47,11 +47,11 @@ class RequestManager { delete it->second; } - bool addRequest(unsigned short id, RequestHandler *info) { + bool addRequest(uint16_t id, RequestHandler *info) { return insert(std::make_pair(id, info)).second; } - RequestHandler* findRequest(unsigned short id) { + RequestHandler* findRequest(uint16_t id) { iterator it = find(id); if(it == end()) return 0; @@ -59,7 +59,7 @@ class RequestManager { return it->second; } - bool deleteRequest(unsigned short id) { + bool deleteRequest(uint16_t id) { iterator it = find(id); if(it == end()) return false; @@ -92,11 +92,11 @@ class RequestManager { RequestManager& operator=(const RequestManager &o); std::map<Net::Connection*,RequestMap*> requestMaps; - unsigned short requestId; + uint16_t requestId; std::map<Net::Packet::Type,RequestHandlerFactory*> requestHandlerFactories; - unsigned short getRequestId() { + uint16_t getRequestId() { return requestId+=2; } diff --git a/src/Common/SystemBackend.cpp b/src/Common/SystemBackend.cpp new file mode 100644 index 0000000..8b9aa0d --- /dev/null +++ b/src/Common/SystemBackend.cpp @@ -0,0 +1,28 @@ +/* + * SystemBackend.cpp + * + * Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#include "SystemBackend.h" + +namespace Mad { +namespace Common { + +SystemBackend *SystemBackend::backend = new SystemBackend(); + +} +} diff --git a/src/Common/SystemBackend.h b/src/Common/SystemBackend.h new file mode 100644 index 0000000..f88ddd9 --- /dev/null +++ b/src/Common/SystemBackend.h @@ -0,0 +1,61 @@ +/* + * SystemBackend.h + * + * Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#ifndef MAD_COMMON_SYSTEMBACKEND_H_ +#define MAD_COMMON_SYSTEMBACKEND_H_ + +#include <stdint.h> + +namespace Mad { +namespace Common { + +class SystemBackend { + private: + static SystemBackend *backend; + + protected: + SystemBackend() {} + + static void setBackend(SystemBackend *backend0) { + delete backend; + backend = backend0; + } + + public: + struct Uptime { + uint32_t uptime; + uint32_t idleTime; + }; + + virtual ~SystemBackend() {} + + virtual Uptime getUptime() const { + Uptime ret = {0, 0}; + return ret; + } + + static SystemBackend *getBackend() { + return backend; + } +}; + +} +} + +#endif /* MAD_COMMON_SYSTEMBACKEND_H_ */ diff --git a/src/Core/ConfigManager.cpp b/src/Core/ConfigManager.cpp index 5f40afd..d42db35 100644 --- a/src/Core/ConfigManager.cpp +++ b/src/Core/ConfigManager.cpp @@ -27,7 +27,7 @@ bool ConfigManager::parseLine(const std::vector<std::string> §ion, const std if(section.empty()) { if(Common::Util::tolower(key) == "configmethod") { if(Common::Util::tolower(value) == "mysql") - methods |= (unsigned short)MYSQL; + methods |= (uint16_t)MYSQL; else return false; } diff --git a/src/Core/ConfigManager.h b/src/Core/ConfigManager.h index 3b23750..6470a33 100644 --- a/src/Core/ConfigManager.h +++ b/src/Core/ConfigManager.h @@ -35,7 +35,7 @@ class ConfigManager : public Common::ConfigManager { MYSQL = (1 << 0) }; - unsigned short methods; + uint16_t methods; std::vector<Net::IPAddress> listeners; std::vector<DaemonInfo> daemons; diff --git a/src/Core/RequestHandler/CoreStatusRequestHandler.h b/src/Core/RequestHandler/CoreStatusRequestHandler.h index 5a3c16e..eec0154 100644 --- a/src/Core/RequestHandler/CoreStatusRequestHandler.h +++ b/src/Core/RequestHandler/CoreStatusRequestHandler.h @@ -21,7 +21,9 @@ #define MAD_CORE_REQUESTHANDLER_CORESTATUSREQUESTHANDLER_H_ #include <Common/RequestHandler.h> -#include <Net/Packet.h> +#include <Common/SystemBackend.h> +#include <Net/Packets/CoreStatusPacket.h> + #include <cstring> #include <gssapi/gssapi.h> @@ -42,7 +44,9 @@ class CoreStatusRequestHandler : public Common::RequestHandler { if(packet.getType() != Net::Packet::TYPE_CORE_STATUS) return false; // TODO Logging - if(!connection->send(Net::Packet(Net::Packet::TYPE_OK, packet.getRequestId()))) + Common::SystemBackend::Uptime uptime = Common::SystemBackend::getBackend()->getUptime(); + + if(!connection->send(Net::Packets::CoreStatusPacket(Net::Packet::TYPE_OK, packet.getRequestId(), uptime.uptime, uptime.idleTime))) return false; setFinished(); diff --git a/src/Net/ClientConnection.cpp b/src/Net/ClientConnection.cpp index e0058ff..d818f7e 100644 --- a/src/Net/ClientConnection.cpp +++ b/src/Net/ClientConnection.cpp @@ -32,7 +32,7 @@ void ClientConnection::connectionHeaderReceiveHandler(const void *data, unsigned // Error... disconnect return; - const ConnectionHeader *header = reinterpret_cast<const ConnectionHeader*>(data); + const ConnectionHeader *header = (const ConnectionHeader*)(data); if(header->m != 'M' || header->a != 'A' || header->d != 'D') // Error... disconnect @@ -48,7 +48,7 @@ void ClientConnection::connectionHeaderReceiveHandler(const void *data, unsigned void ClientConnection::connectionHeader() { ConnectionHeader header = {'M', 'A', 'D', daemon ? 'D' : 'C', 0, 1, 1, 1}; - rawSend(reinterpret_cast<unsigned char*>(&header), sizeof(header)); + rawSend((uint8_t*)&header, sizeof(header)); rawReceive(sizeof(ConnectionHeader), sigc::mem_fun(this, &ClientConnection::connectionHeaderReceiveHandler)); } @@ -89,7 +89,7 @@ void ClientConnection::connect(const IPAddress &address, bool daemon0) throw(Con gnutls_init(&session, GNUTLS_CLIENT); gnutls_set_default_priority(session); gnutls_credentials_set(session, GNUTLS_CRD_CERTIFICATE, x509_cred); - gnutls_transport_set_ptr(session, reinterpret_cast<gnutls_transport_ptr_t>(sock)); + gnutls_transport_set_ptr(session, (gnutls_transport_ptr_t)sock); handshake(); } diff --git a/src/Net/Connection.cpp b/src/Net/Connection.cpp index cfced4f..22adeaf 100644 --- a/src/Net/Connection.cpp +++ b/src/Net/Connection.cpp @@ -74,7 +74,7 @@ void Connection::packetHeaderReceiveHandler(const void *data, unsigned long leng return; } - header = *reinterpret_cast<const Packet::Data*>(data); + header = *(const Packet::Data*)data; if(header.length == 0) { signal(this, Packet((Packet::Type)ntohs(header.type), ntohs(header.requestId))); @@ -124,7 +124,7 @@ void Connection::doReceive() { if(receiveComplete()) { // Save data pointer, as transR.notify might start a new reception - unsigned char *data = transR.data; + uint8_t *data = transR.data; transR.data = 0; transR.notify(data, transR.length); @@ -142,7 +142,7 @@ bool Connection::rawReceive(unsigned long length, if(!receiveComplete()) return false; - transR.data = new unsigned char[length]; + transR.data = new uint8_t[length]; transR.length = length; transR.transmitted = 0; transR.notify = notify; @@ -176,11 +176,11 @@ void Connection::doSend() { } } -bool Connection::rawSend(const unsigned char *data, unsigned long length) { +bool Connection::rawSend(const uint8_t *data, unsigned long length) { if(!isConnected()) return false; - Transmission trans = {length, 0, new unsigned char[length], sigc::slot<void,const void*,unsigned long>()}; + Transmission trans = {length, 0, new uint8_t[length], sigc::slot<void,const void*,unsigned long>()}; std::memcpy(trans.data, data, length); transS.push(trans); diff --git a/src/Net/Connection.h b/src/Net/Connection.h index d733ee3..0f012f1 100644 --- a/src/Net/Connection.h +++ b/src/Net/Connection.h @@ -38,7 +38,7 @@ class Connection { unsigned long length; unsigned long transmitted; - unsigned char *data; + uint8_t *data; sigc::slot<void,const void*,unsigned long> notify; }; @@ -87,15 +87,15 @@ class Connection { protected: struct ConnectionHeader { - unsigned char m; - unsigned char a; - unsigned char d; - unsigned char type; - - unsigned char versionMajor; - unsigned char versionMinor; - unsigned char protVerMin; - unsigned char protVerMax; + uint8_t m; + uint8_t a; + uint8_t d; + uint8_t type; + + uint8_t versionMajor; + uint8_t versionMinor; + uint8_t protVerMin; + uint8_t protVerMax; }; int sock; @@ -116,7 +116,7 @@ class Connection { virtual void connectionHeader() = 0; bool rawReceive(unsigned long length, const sigc::slot<void,const void*,unsigned long> ¬ify); - bool rawSend(const unsigned char *data, unsigned long length); + bool rawSend(const uint8_t *data, unsigned long length); bool enterReceiveLoop() { if(!isConnected() || isDisconnecting()) @@ -189,7 +189,7 @@ class Connection { if(!isConnected() || isConnecting() || isDisconnecting()) return false; - return rawSend(reinterpret_cast<const unsigned char*>(packet.getRawData()), packet.getRawDataLength()); + return rawSend((const uint8_t*)packet.getRawData(), packet.getRawDataLength()); } void sendReceive(short events = POLLIN|POLLOUT); diff --git a/src/Net/IPAddress.h b/src/Net/IPAddress.h index b0fad45..78b41dd 100644 --- a/src/Net/IPAddress.h +++ b/src/Net/IPAddress.h @@ -30,19 +30,19 @@ namespace Net { class IPAddress { private: - unsigned int addr; - unsigned short port; + uint32_t addr; + uint16_t port; struct sockaddr_in sa; public: // TODO Default port - IPAddress(unsigned short port0 = 6666) : addr(INADDR_ANY), port(port0) { + IPAddress(uint16_t port0 = 6666) : addr(INADDR_ANY), port(port0) { sa.sin_family = AF_INET; sa.sin_port = htons(port); sa.sin_addr.s_addr = INADDR_ANY; } - IPAddress(unsigned int address, unsigned short port0) : addr(address), port(port0) { + IPAddress(uint32_t address, uint16_t port0) : addr(address), port(port0) { sa.sin_family = AF_INET; sa.sin_port = htons(port); sa.sin_addr.s_addr = htonl(addr); @@ -77,7 +77,7 @@ class IPAddress { addr = ntohl(sa.sin_addr.s_addr); } - IPAddress(const std::string &address, unsigned short port0) throw(InvalidAddressException) : port(port0) { + IPAddress(const std::string &address, uint16_t port0) throw(InvalidAddressException) : port(port0) { sa.sin_family = AF_INET; sa.sin_port = htons(port); @@ -92,18 +92,18 @@ class IPAddress { addr = ntohl(sa.sin_addr.s_addr); } - unsigned int getAddress() const {return addr;} - unsigned short getPort() const {return port;} + uint32_t getAddress() const {return addr;} + uint16_t getPort() const {return port;} std::string getAddressString() const { char buf[INET_ADDRSTRLEN]; - unsigned int address = htonl(addr); + uint32_t address = htonl(addr); inet_ntop(AF_INET, &address, buf, sizeof(buf)); return std::string(buf); } - struct sockaddr* getSockAddr() {return reinterpret_cast<struct sockaddr*>(&sa);} + struct sockaddr* getSockAddr() {return (struct sockaddr*)&sa;} socklen_t getSockAddrLength() const {return sizeof(sa);} }; diff --git a/src/Net/Listener.cpp b/src/Net/Listener.cpp index 892ec9d..954129a 100644 --- a/src/Net/Listener.cpp +++ b/src/Net/Listener.cpp @@ -98,7 +98,7 @@ ServerConnection* Listener::getConnection(const std::map<int,const short*> &poll socklen_t addrlen = sizeof(sa); - while((sd = accept(sock, reinterpret_cast<struct sockaddr*>(&sa), &addrlen)) >= 0) { + while((sd = accept(sock, (struct sockaddr*)&sa, &addrlen)) >= 0) { connections.push_back(new ServerConnection(sd, IPAddress(sa), dh_params, x905CertFile, x905KeyFile)); addrlen = sizeof(sa); diff --git a/src/Net/Makefile.am b/src/Net/Makefile.am index c7f58da..2fd4f12 100644 --- a/src/Net/Makefile.am +++ b/src/Net/Makefile.am @@ -1,6 +1,8 @@ -noinst_LTLIBRARIES = libnet.la +SUBDIRS = Packets -libnet_la_SOURCES = ClientConnection.cpp ServerConnection.cpp Connection.cpp Listener.cpp +noinst_LTLIBRARIES = libnet.la +libnet_la_SOURCES = ClientConnection.cpp ServerConnection.cpp Connection.cpp Listener.cpp Packet.cpp +libnet_la_LIBADD = Packets/libpackets.la noinst_HEADERS = ClientConnection.h ServerConnection.h Connection.h Exception.h ConnectionException.h \ InvalidAddressException.h IPAddress.h Listener.h Packet.h diff --git a/src/Net/Makefile.in b/src/Net/Makefile.in index 9ce9a8e..e813a71 100644 --- a/src/Net/Makefile.in +++ b/src/Net/Makefile.in @@ -44,9 +44,9 @@ mkinstalldirs = $(install_sh) -d CONFIG_HEADER = $(top_builddir)/src/config.h CONFIG_CLEAN_FILES = LTLIBRARIES = $(noinst_LTLIBRARIES) -libnet_la_LIBADD = +libnet_la_DEPENDENCIES = Packets/libpackets.la am_libnet_la_OBJECTS = ClientConnection.lo ServerConnection.lo \ - Connection.lo Listener.lo + Connection.lo Listener.lo Packet.lo libnet_la_OBJECTS = $(am_libnet_la_OBJECTS) DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/src depcomp = $(SHELL) $(top_srcdir)/depcomp @@ -62,9 +62,19 @@ CXXLINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ $(LDFLAGS) -o $@ SOURCES = $(libnet_la_SOURCES) DIST_SOURCES = $(libnet_la_SOURCES) +RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \ + html-recursive info-recursive install-data-recursive \ + install-dvi-recursive install-exec-recursive \ + install-html-recursive install-info-recursive \ + install-pdf-recursive install-ps-recursive install-recursive \ + installcheck-recursive installdirs-recursive pdf-recursive \ + ps-recursive uninstall-recursive HEADERS = $(noinst_HEADERS) +RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive \ + distclean-recursive maintainer-clean-recursive ETAGS = etags CTAGS = ctags +DIST_SUBDIRS = $(SUBDIRS) DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) ACLOCAL = @ACLOCAL@ AMTAR = @AMTAR@ @@ -180,12 +190,14 @@ sysconfdir = @sysconfdir@ target_alias = @target_alias@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ +SUBDIRS = Packets noinst_LTLIBRARIES = libnet.la -libnet_la_SOURCES = ClientConnection.cpp ServerConnection.cpp Connection.cpp Listener.cpp +libnet_la_SOURCES = ClientConnection.cpp ServerConnection.cpp Connection.cpp Listener.cpp Packet.cpp +libnet_la_LIBADD = Packets/libpackets.la noinst_HEADERS = ClientConnection.h ServerConnection.h Connection.h Exception.h ConnectionException.h \ InvalidAddressException.h IPAddress.h Listener.h Packet.h -all: all-am +all: all-recursive .SUFFIXES: .SUFFIXES: .cpp .lo .o .obj @@ -239,6 +251,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ClientConnection.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Connection.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Listener.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Packet.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ServerConnection.Plo@am__quote@ .cpp.o: @@ -268,6 +281,76 @@ mostlyclean-libtool: clean-libtool: -rm -rf .libs _libs +# This directory's subdirectories are mostly independent; you can cd +# into them and run `make' without going through this Makefile. +# To change the values of `make' variables: instead of editing Makefiles, +# (1) if the variable is set in `config.status', edit `config.status' +# (which will cause the Makefiles to be regenerated when you run `make'); +# (2) otherwise, pass the desired values on the `make' command line. +$(RECURSIVE_TARGETS): + @failcom='exit 1'; \ + for f in x $$MAKEFLAGS; do \ + case $$f in \ + *=* | --[!k]*);; \ + *k*) failcom='fail=yes';; \ + esac; \ + done; \ + dot_seen=no; \ + target=`echo $@ | sed s/-recursive//`; \ + list='$(SUBDIRS)'; for subdir in $$list; do \ + echo "Making $$target in $$subdir"; \ + if test "$$subdir" = "."; then \ + dot_seen=yes; \ + local_target="$$target-am"; \ + else \ + local_target="$$target"; \ + fi; \ + (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \ + || eval $$failcom; \ + done; \ + if test "$$dot_seen" = "no"; then \ + $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \ + fi; test -z "$$fail" + +$(RECURSIVE_CLEAN_TARGETS): + @failcom='exit 1'; \ + for f in x $$MAKEFLAGS; do \ + case $$f in \ + *=* | --[!k]*);; \ + *k*) failcom='fail=yes';; \ + esac; \ + done; \ + dot_seen=no; \ + case "$@" in \ + distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \ + *) list='$(SUBDIRS)' ;; \ + esac; \ + rev=''; for subdir in $$list; do \ + if test "$$subdir" = "."; then :; else \ + rev="$$subdir $$rev"; \ + fi; \ + done; \ + rev="$$rev ."; \ + target=`echo $@ | sed s/-recursive//`; \ + for subdir in $$rev; do \ + echo "Making $$target in $$subdir"; \ + if test "$$subdir" = "."; then \ + local_target="$$target-am"; \ + else \ + local_target="$$target"; \ + fi; \ + (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \ + || eval $$failcom; \ + done && test -z "$$fail" +tags-recursive: + list='$(SUBDIRS)'; for subdir in $$list; do \ + test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) tags); \ + done +ctags-recursive: + list='$(SUBDIRS)'; for subdir in $$list; do \ + test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) ctags); \ + done + ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ unique=`for i in $$list; do \ @@ -278,10 +361,23 @@ ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) mkid -fID $$unique tags: TAGS -TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ +TAGS: tags-recursive $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ $(TAGS_FILES) $(LISP) tags=; \ here=`pwd`; \ + if ($(ETAGS) --etags-include --version) >/dev/null 2>&1; then \ + include_option=--etags-include; \ + empty_fix=.; \ + else \ + include_option=--include; \ + empty_fix=; \ + fi; \ + list='$(SUBDIRS)'; for subdir in $$list; do \ + if test "$$subdir" = .; then :; else \ + test ! -f $$subdir/TAGS || \ + tags="$$tags $$include_option=$$here/$$subdir/TAGS"; \ + fi; \ + done; \ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ @@ -294,7 +390,7 @@ TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ $$tags $$unique; \ fi ctags: CTAGS -CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ +CTAGS: ctags-recursive $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ $(TAGS_FILES) $(LISP) tags=; \ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ @@ -341,19 +437,37 @@ distdir: $(DISTFILES) || exit 1; \ fi; \ done + list='$(DIST_SUBDIRS)'; for subdir in $$list; do \ + if test "$$subdir" = .; then :; else \ + test -d "$(distdir)/$$subdir" \ + || $(MKDIR_P) "$(distdir)/$$subdir" \ + || exit 1; \ + distdir=`$(am__cd) $(distdir) && pwd`; \ + top_distdir=`$(am__cd) $(top_distdir) && pwd`; \ + (cd $$subdir && \ + $(MAKE) $(AM_MAKEFLAGS) \ + top_distdir="$$top_distdir" \ + distdir="$$distdir/$$subdir" \ + am__remove_distdir=: \ + am__skip_length_check=: \ + distdir) \ + || exit 1; \ + fi; \ + done check-am: all-am -check: check-am +check: check-recursive all-am: Makefile $(LTLIBRARIES) $(HEADERS) -installdirs: -install: install-am -install-exec: install-exec-am -install-data: install-data-am -uninstall: uninstall-am +installdirs: installdirs-recursive +installdirs-am: +install: install-recursive +install-exec: install-exec-recursive +install-data: install-data-recursive +uninstall: uninstall-recursive install-am: all-am @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am -installcheck: installcheck-am +installcheck: installcheck-recursive install-strip: $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ @@ -369,69 +483,71 @@ distclean-generic: maintainer-clean-generic: @echo "This command is intended for maintainers to use" @echo "it deletes files that may require special tools to rebuild." -clean: clean-am +clean: clean-recursive clean-am: clean-generic clean-libtool clean-noinstLTLIBRARIES \ mostlyclean-am -distclean: distclean-am +distclean: distclean-recursive -rm -rf ./$(DEPDIR) -rm -f Makefile distclean-am: clean-am distclean-compile distclean-generic \ distclean-tags -dvi: dvi-am +dvi: dvi-recursive dvi-am: -html: html-am +html: html-recursive -info: info-am +info: info-recursive info-am: install-data-am: -install-dvi: install-dvi-am +install-dvi: install-dvi-recursive install-exec-am: -install-html: install-html-am +install-html: install-html-recursive -install-info: install-info-am +install-info: install-info-recursive install-man: -install-pdf: install-pdf-am +install-pdf: install-pdf-recursive -install-ps: install-ps-am +install-ps: install-ps-recursive installcheck-am: -maintainer-clean: maintainer-clean-am +maintainer-clean: maintainer-clean-recursive -rm -rf ./$(DEPDIR) -rm -f Makefile maintainer-clean-am: distclean-am maintainer-clean-generic -mostlyclean: mostlyclean-am +mostlyclean: mostlyclean-recursive mostlyclean-am: mostlyclean-compile mostlyclean-generic \ mostlyclean-libtool -pdf: pdf-am +pdf: pdf-recursive pdf-am: -ps: ps-am +ps: ps-recursive ps-am: uninstall-am: -.MAKE: install-am install-strip +.MAKE: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) install-am \ + install-strip -.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ - clean-libtool clean-noinstLTLIBRARIES ctags distclean \ +.PHONY: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) CTAGS GTAGS \ + all all-am check check-am clean clean-generic clean-libtool \ + clean-noinstLTLIBRARIES ctags ctags-recursive distclean \ distclean-compile distclean-generic distclean-libtool \ distclean-tags distdir dvi dvi-am html html-am info info-am \ install install-am install-data install-data-am install-dvi \ @@ -439,9 +555,10 @@ uninstall-am: install-html-am install-info install-info-am install-man \ install-pdf install-pdf-am install-ps install-ps-am \ install-strip installcheck installcheck-am installdirs \ - maintainer-clean maintainer-clean-generic mostlyclean \ - mostlyclean-compile mostlyclean-generic mostlyclean-libtool \ - pdf pdf-am ps ps-am tags uninstall uninstall-am + installdirs-am maintainer-clean maintainer-clean-generic \ + mostlyclean mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool pdf pdf-am ps ps-am tags tags-recursive \ + uninstall uninstall-am # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. diff --git a/src/Net/Packet.cpp b/src/Net/Packet.cpp new file mode 100644 index 0000000..9e05f24 --- /dev/null +++ b/src/Net/Packet.cpp @@ -0,0 +1,50 @@ +/* + * Packet.cpp + * + * Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#include "Packet.h" + +namespace Mad { +namespace Net { + +Packet::Packet(Type type, uint16_t requestId, const void *data, uint16_t length) { + rawData = (Data*)std::malloc(sizeof(Data)+length); + + rawData->type = htons(type); + rawData->requestId = htons(requestId); + rawData->reserved = 0; + rawData->length = htons(length); + + if(length) + std::memcpy(rawData->data, data, length); +} + +Packet& Packet::operator=(const Packet &p) { + if(&p == this) + return *this; + + std::free(rawData); + + rawData = (Data*)std::malloc(p.getRawDataLength()); + std::memcpy(rawData, p.rawData, p.getRawDataLength()); + + return *this; +} + +} +} diff --git a/src/Net/Packet.h b/src/Net/Packet.h index 1062d4a..e64f37b 100644 --- a/src/Net/Packet.h +++ b/src/Net/Packet.h @@ -23,6 +23,7 @@ #include <cstdlib> #include <cstring> #include <netinet/in.h> +#include <stdint.h> namespace Mad { namespace Net { @@ -36,63 +37,49 @@ class Packet { }; struct Data { - unsigned short type; - unsigned short requestId; - unsigned short reserved; - unsigned short length; - unsigned char data[0]; + uint16_t type; + uint16_t requestId; + uint16_t reserved; + uint16_t length; + uint8_t data[0]; }; protected: Data *rawData; - public: - Packet(Type type, unsigned short requestId, const void *data = NULL, unsigned short length = 0) { - rawData = (Data*)std::malloc(sizeof(Data)+length); - - rawData->type = htons(type); - rawData->requestId = htons(requestId); - rawData->reserved = 0; + void setLength(uint16_t length) { rawData->length = htons(length); - if(length) - std::memcpy(rawData->data, data, length); - } - - Packet(const Packet &p) { - rawData = (Data*)std::malloc(p.getRawDataLength()); - std::memcpy(rawData, p.rawData, p.getRawDataLength()); + rawData = (Data*)std::realloc(rawData, getRawDataLength()); } - Packet& operator=(Packet &p) { - if(&p == this) - return *this; - - std::free(rawData); + public: + Packet(Type type, uint16_t requestId, const void *data = 0, uint16_t length = 0); + Packet(const Packet &p) { rawData = (Data*)std::malloc(p.getRawDataLength()); std::memcpy(rawData, p.rawData, p.getRawDataLength()); - - return *this; } virtual ~Packet() { std::free(rawData); } + Packet& operator=(const Packet &p); + Type getType() const { return (Type)ntohs(rawData->type); } - unsigned short getRequestId() const { + uint16_t getRequestId() const { return ntohs(rawData->requestId); } - unsigned short getLength() const { + uint16_t getLength() const { return ntohs(rawData->length); } - const unsigned char* getData() const { + const uint8_t* getData() const { return rawData->data; } diff --git a/src/Net/Packets/CoreStatusPacket.cpp b/src/Net/Packets/CoreStatusPacket.cpp new file mode 100644 index 0000000..4397fa8 --- /dev/null +++ b/src/Net/Packets/CoreStatusPacket.cpp @@ -0,0 +1,46 @@ +/* + * CoreStatusPacket.cpp + * + * Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#include "CoreStatusPacket.h" + + +namespace Mad { +namespace Net { +namespace Packets { + +CoreStatusPacket::CoreStatusPacket(Type type, uint16_t requestId, uint32_t uptime, uint32_t idleTime) : Packet(type, requestId) { + setLength(sizeof(CoreStatusData)); + coreStatusData = (CoreStatusData*)&rawData->data; + + coreStatusData->uptime = htonl(uptime); + coreStatusData->idleTime = htonl(idleTime); +} + +CoreStatusPacket& CoreStatusPacket::operator=(const Packet &p) { + Packet::operator=(p); + + setLength(sizeof(CoreStatusData)); + coreStatusData = (CoreStatusData*)&rawData->data; + + return *this; +} + +} +} +} diff --git a/src/Net/Packets/CoreStatusPacket.h b/src/Net/Packets/CoreStatusPacket.h new file mode 100644 index 0000000..14b022e --- /dev/null +++ b/src/Net/Packets/CoreStatusPacket.h @@ -0,0 +1,70 @@ +/* + * CoreStatusPacket.h + * + * Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#ifndef MAD_NET_PACKETS_CORESTATUSPACKET_H_ +#define MAD_NET_PACKETS_CORESTATUSPACKET_H_ + +#include "../Packet.h" + +namespace Mad { +namespace Net { +namespace Packets { + +class CoreStatusPacket : public Packet { + protected: + struct CoreStatusData { + uint32_t uptime; + uint32_t idleTime; + }; + + CoreStatusData *coreStatusData; + + public: + CoreStatusPacket(Type type, uint16_t requestId, uint32_t uptime = 0, uint32_t idleTime = 0); + + CoreStatusPacket(const Packet &p) : Packet(p) { + setLength(sizeof(CoreStatusData)); + coreStatusData = (CoreStatusData*)&rawData->data; + } + + CoreStatusPacket(const CoreStatusPacket &p) : Packet(p) { + setLength(sizeof(CoreStatusData)); + coreStatusData = (CoreStatusData*)&rawData->data; + } + + CoreStatusPacket& operator=(const Packet &p); + + CoreStatusPacket& operator=(const CoreStatusPacket &p) { + return (*this = (Packet)p); + } + + uint32_t getUptime() const { + return ntohl(coreStatusData->uptime); + } + + uint32_t getIdleTime() const { + return ntohl(coreStatusData->idleTime); + } +}; + +} +} +} + +#endif /* MAD_NET_PACKETS_CORESTATUSPACKET_H_ */ diff --git a/src/Net/Packets/Makefile.am b/src/Net/Packets/Makefile.am new file mode 100644 index 0000000..344a764 --- /dev/null +++ b/src/Net/Packets/Makefile.am @@ -0,0 +1,4 @@ +noinst_LTLIBRARIES = libpackets.la +libpackets_la_SOURCES = CoreStatusPacket.cpp + +noinst_HEADERS = CoreStatusPacket.h diff --git a/src/Net/Packets/Makefile.in b/src/Net/Packets/Makefile.in new file mode 100644 index 0000000..8fa55b0 --- /dev/null +++ b/src/Net/Packets/Makefile.in @@ -0,0 +1,442 @@ +# Makefile.in generated by automake 1.10.1 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + + +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +subdir = src/Net/Packets +DIST_COMMON = $(noinst_HEADERS) $(srcdir)/Makefile.am \ + $(srcdir)/Makefile.in +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/src/config.h +CONFIG_CLEAN_FILES = +LTLIBRARIES = $(noinst_LTLIBRARIES) +libpackets_la_LIBADD = +am_libpackets_la_OBJECTS = CoreStatusPacket.lo +libpackets_la_OBJECTS = $(am_libpackets_la_OBJECTS) +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/src +depcomp = $(SHELL) $(top_srcdir)/depcomp +am__depfiles_maybe = depfiles +CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) +LTCXXCOMPILE = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) +CXXLD = $(CXX) +CXXLINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=link $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) \ + $(LDFLAGS) -o $@ +SOURCES = $(libpackets_la_SOURCES) +DIST_SOURCES = $(libpackets_la_SOURCES) +HEADERS = $(noinst_HEADERS) +ETAGS = etags +CTAGS = ctags +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DSYMUTIL = @DSYMUTIL@ +ECHO = @ECHO@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +F77 = @F77@ +FFLAGS = @FFLAGS@ +GREP = @GREP@ +GnuTLS_CFLAGS = @GnuTLS_CFLAGS@ +GnuTLS_LIBS = @GnuTLS_LIBS@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LDFLAGS = @LDFLAGS@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +MAINT = @MAINT@ +MAKEINFO = @MAKEINFO@ +MKDIR_P = @MKDIR_P@ +NMEDIT = @NMEDIT@ +OBJEXT = @OBJEXT@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PKG_CONFIG = @PKG_CONFIG@ +RANLIB = @RANLIB@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +VERSION = @VERSION@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_F77 = @ac_ct_F77@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +sigc_CFLAGS = @sigc_CFLAGS@ +sigc_LIBS = @sigc_LIBS@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +noinst_LTLIBRARIES = libpackets.la +libpackets_la_SOURCES = CoreStatusPacket.cpp +noinst_HEADERS = CoreStatusPacket.h +all: all-am + +.SUFFIXES: +.SUFFIXES: .cpp .lo .o .obj +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \ + && exit 0; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/Net/Packets/Makefile'; \ + cd $(top_srcdir) && \ + $(AUTOMAKE) --gnu src/Net/Packets/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +clean-noinstLTLIBRARIES: + -test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES) + @list='$(noinst_LTLIBRARIES)'; for p in $$list; do \ + dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ + test "$$dir" != "$$p" || dir=.; \ + echo "rm -f \"$${dir}/so_locations\""; \ + rm -f "$${dir}/so_locations"; \ + done +libpackets.la: $(libpackets_la_OBJECTS) $(libpackets_la_DEPENDENCIES) + $(CXXLINK) $(libpackets_la_OBJECTS) $(libpackets_la_LIBADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CoreStatusPacket.Plo@am__quote@ + +.cpp.o: +@am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ $< + +.cpp.obj: +@am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'` + +.cpp.lo: +@am__fastdepCXX_TRUE@ $(LTCXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(LTCXXCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonemtpy = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$tags $$unique; \ + fi +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + test -z "$(CTAGS_ARGS)$$tags$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$tags $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && cd $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) $$here + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ + fi; \ + cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ + else \ + test -f $(distdir)/$$file \ + || cp -p $$d/$$file $(distdir)/$$file \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(LTLIBRARIES) $(HEADERS) +installdirs: +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-libtool clean-noinstLTLIBRARIES \ + mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-exec-am: + +install-html: install-html-am + +install-info: install-info-am + +install-man: + +install-pdf: install-pdf-am + +install-ps: install-ps-am + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ + clean-libtool clean-noinstLTLIBRARIES ctags distclean \ + distclean-compile distclean-generic distclean-libtool \ + distclean-tags distdir dvi dvi-am html html-am info info-am \ + install install-am install-data install-data-am install-dvi \ + install-dvi-am install-exec install-exec-am install-html \ + install-html-am install-info install-info-am install-man \ + install-pdf install-pdf-am install-ps install-ps-am \ + install-strip installcheck installcheck-am installdirs \ + maintainer-clean maintainer-clean-generic mostlyclean \ + mostlyclean-compile mostlyclean-generic mostlyclean-libtool \ + pdf pdf-am ps ps-am tags uninstall uninstall-am + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/src/Net/ServerConnection.cpp b/src/Net/ServerConnection.cpp index 0c35991..fbdd69f 100644 --- a/src/Net/ServerConnection.cpp +++ b/src/Net/ServerConnection.cpp @@ -32,7 +32,7 @@ void ServerConnection::connectionHeaderReceiveHandler(const void *data, unsigned // Error... disconnect return; - const ConnectionHeader *header = reinterpret_cast<const ConnectionHeader*>(data); + const ConnectionHeader *header = (const ConnectionHeader*)data; if(header->m != 'M' || header->a != 'A' || header->d != 'D') // Error... disconnect @@ -52,7 +52,7 @@ void ServerConnection::connectionHeaderReceiveHandler(const void *data, unsigned ConnectionHeader header2 = {'M', 'A', 'D', 0, 0, 1, 1, 0}; - rawSend(reinterpret_cast<unsigned char*>(&header2), sizeof(header2)); + rawSend((uint8_t*)&header2, sizeof(header2)); enterReceiveLoop(); } @@ -69,7 +69,7 @@ ServerConnection::ServerConnection(int sock0, const IPAddress &address, gnutls_d gnutls_init(&session, GNUTLS_SERVER); gnutls_set_default_priority(session); gnutls_credentials_set(session, GNUTLS_CRD_CERTIFICATE, x509_cred); - gnutls_transport_set_ptr(session, reinterpret_cast<gnutls_transport_ptr_t>(sock)); + gnutls_transport_set_ptr(session, (gnutls_transport_ptr_t)sock); handshake(); } diff --git a/src/madc.cpp b/src/madc.cpp index f7dc143..5b0e3a1 100644 --- a/src/madc.cpp +++ b/src/madc.cpp @@ -60,7 +60,7 @@ static void activateReadline() { if(parser->willDisconnect()) return; - rl_callback_handler_install("mad: ", handleCommand); + rl_callback_handler_install("mad> ", handleCommand); fds[0].events = POLLIN; } |