Author: grothoff Date: 2006-12-29 07:41:06 -0800 (Fri, 29 Dec 2006) New Revision: 4101
Added: GNUnet/src/include/gnunet_upnp_service.h Removed: GNUnet/src/transports/upnp/upnpdemo.c Modified: GNUnet/README.debian GNUnet/configure.ac GNUnet/m4/Makefile.in GNUnet/src/include/Makefile.am GNUnet/src/transports/Makefile.am GNUnet/src/transports/upnp/Makefile.am GNUnet/src/transports/upnp/init.c GNUnet/src/transports/upnp/todo GNUnet/src/transports/upnp/upnptest.c Log: integrating upnp support into build Modified: GNUnet/README.debian =================================================================== --- GNUnet/README.debian 2006-12-29 15:10:02 UTC (rev 4100) +++ GNUnet/README.debian 2006-12-29 15:41:06 UTC (rev 4101) @@ -28,6 +28,7 @@ dialog (optional) libglade2-dev (recommended) libgtk2.0-dev (recommended) +libxml2-dev (recommended, especially with NAT) Additional libextractor dependencies: Modified: GNUnet/configure.ac =================================================================== --- GNUnet/configure.ac 2006-12-29 15:10:02 UTC (rev 4100) +++ GNUnet/configure.ac 2006-12-29 15:41:06 UTC (rev 4101) @@ -173,6 +173,9 @@ # libcurl LIBCURL_CHECK_CONFIG(,,,AC_MSG_ERROR([GNUnet requires libcurl])) +# libxml2 +AM_PATH_XML2(,xml=1,xml=0) +AM_CONDITIONAL(HAVE_XML2, test x$xml = x1) # test for kvm and kstat (for CPU stats under BSD/Solaris) AC_CHECK_LIB([kvm],[kvm_open]) Modified: GNUnet/m4/Makefile.in =================================================================== --- GNUnet/m4/Makefile.in 2006-12-29 15:10:02 UTC (rev 4100) +++ GNUnet/m4/Makefile.in 2006-12-29 15:41:06 UTC (rev 4101) @@ -108,6 +108,8 @@ HAVE_MYSQL_TRUE = @HAVE_MYSQL_TRUE@ HAVE_SQLITE_FALSE = @HAVE_SQLITE_FALSE@ HAVE_SQLITE_TRUE = @HAVE_SQLITE_TRUE@ +HAVE_XML2_FALSE = @HAVE_XML2_FALSE@ +HAVE_XML2_TRUE = @HAVE_XML2_TRUE@ HAVE_ZLIB_FALSE = @HAVE_ZLIB_FALSE@ HAVE_ZLIB_TRUE = @HAVE_ZLIB_TRUE@ INSTALL_DATA = @INSTALL_DATA@ @@ -169,6 +171,9 @@ XFREEBSD_FALSE = @XFREEBSD_FALSE@ XFREEBSD_TRUE = @XFREEBSD_TRUE@ XGETTEXT = @XGETTEXT@ +XML2_CONFIG = @XML2_CONFIG@ +XML_CPPFLAGS = @XML_CPPFLAGS@ +XML_LIBS = @XML_LIBS@ _libcurl_config = @_libcurl_config@ ac_ct_CC = @ac_ct_CC@ ac_ct_CXX = @ac_ct_CXX@ Modified: GNUnet/src/include/Makefile.am =================================================================== --- GNUnet/src/include/Makefile.am 2006-12-29 15:10:02 UTC (rev 4100) +++ GNUnet/src/include/Makefile.am 2006-12-29 15:41:06 UTC (rev 4101) @@ -45,6 +45,7 @@ gnunet_traffic_service.h \ gnunet_transport.h \ gnunet_transport_service.h \ + gnunet_upnp_service.h \ gnunet_uritrack_lib.h \ gnunet_util.h \ gnunet_util_boot.h \ Added: GNUnet/src/include/gnunet_upnp_service.h =================================================================== --- GNUnet/src/include/gnunet_upnp_service.h 2006-12-29 15:10:02 UTC (rev 4100) +++ GNUnet/src/include/gnunet_upnp_service.h 2006-12-29 15:41:06 UTC (rev 4101) @@ -0,0 +1,64 @@ +/* + This file is part of GNUnet + (C) 2006 Christian Grothoff (and other contributing authors) + + GNUnet 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 2, or (at your + option) any later version. + + GNUnet 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 GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +/** + * @file include/gnunet_upnp_service.h + * @brief API for UPnP access + * @author Christian Grothoff + */ + +#ifndef GNUNET_UPNP_SERVICE_H +#define GNUNET_UPNP_SERVICE_H + +#include "gnunet_util.h" + +#ifdef __cplusplus +extern "C" { +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + +/** + * @brief UPNP API + */ +typedef struct { + + /** + * Get the external IP address for the local machine. + * @param protocol "UDP" or "TCP". + * + * @return SYSERR on error, OK on success + */ + int (*get_ip)(unsigned short port, + const char * protocol, + IPaddr * address); + +} UPnP_ServiceAPI; + + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + +#endif Property changes on: GNUnet/src/include/gnunet_upnp_service.h ___________________________________________________________________ Name: svn:eol-style + native Modified: GNUnet/src/transports/Makefile.am =================================================================== --- GNUnet/src/transports/Makefile.am 2006-12-29 15:10:02 UTC (rev 4100) +++ GNUnet/src/transports/Makefile.am 2006-12-29 15:41:06 UTC (rev 4101) @@ -11,7 +11,12 @@ v6ip = \ libip6.la endif +#if HAVE_XML2 + build_upnp=upnp +#endif +SUBDIRS = $(build_upnp) . + noinst_LTLIBRARIES = \ $(v6ip) \ libip.la Modified: GNUnet/src/transports/upnp/Makefile.am =================================================================== --- GNUnet/src/transports/upnp/Makefile.am 2006-12-29 15:10:02 UTC (rev 4100) +++ GNUnet/src/transports/upnp/Makefile.am 2006-12-29 15:41:06 UTC (rev 4101) @@ -4,13 +4,12 @@ plugindir = $(libdir)/GNUnet -# GNU Gettext support LIBS = @LIBINTL@ @LIBS@ -lib_LTLIBRARIES = \ - libgnunetupnp.la +plugin_LTLIBRARIES = \ + libgnunetmodule_upnp.la -libgnunetupnp_la_SOURCES = \ +libgnunetmodule_upnp_la_SOURCES = \ error.c error.h \ init.c \ ip.c ip.h \ @@ -18,41 +17,16 @@ xmlnode.c xmlnode.h \ upnp.c upnp.h -libgnunetupnp_la_LDFLAGS = \ - $(GTK_LIBS) @EXT_LIB_PATH@ @EXT_LIBS@ @LIBCURL@ \ - -export-dynamic \ - -version-info 0:0:0 - -# FIXME: detect libxml2 path properly! -libgnunetupnp_la_CFLAGS = @LIBCURL_CPPFLAGS@ \ +libgnunetmodule_upnp_la_LDFLAGS = \ + -export-dynamic -avoid-version -module +libgnunetmodule_upnp_la_CFLAGS = \ -I$(top_scrdir)/include \ - -I/usr/include/libxml2 \ - @GNUNETGTK_CFLAGS@ \ - @GTK_CFLAGS@ - - -libgnunetupnp_la_LIBADD = \ + @LIBCURL_CPPFLAGS@ @XML_CPPFLAGS@ @GNUNETGTK_CFLAGS@ @GTK_CFLAGS@ +libgnunetmodule_upnp_la_LIBADD = \ @GTK_LIBS@ @EXT_LIB_PATH@ @EXT_LIBS@ \ - @GNUNETGTK_LIBS@ \ - $(INTLLIBS) \ - -lgthread-2.0 \ + @GNUNETGTK_LIBS@ @XML_LIBS@ @LIBCURL@ \ $(top_builddir)/src/util/libgnunetutil.la - -noinst_PROGRAMS = \ - upnpdemo - -upnpdemo_SOURCES = \ - upnpdemo.c -upnpdemo_LDADD = \ - $(top_builddir)/src/util/libgnunetutil.la \ - $(top_builddir)/src/util/loggers/libgnunetutil_logging.la \ - $(top_builddir)/src/transports/upnp/libgnunetupnp.la \ - $(top_builddir)/src/util/config_impl/libgnunetutil_config.la \ - $(top_builddir)/src/util/cron/libgnunetutil_cron.la - - - check_PROGRAMS = \ upnptest @@ -63,7 +37,6 @@ upnptest_LDADD = \ $(top_builddir)/src/util/libgnunetutil.la \ $(top_builddir)/src/util/loggers/libgnunetutil_logging.la \ - $(top_builddir)/src/transports/upnp/libgnunetupnp.la \ $(top_builddir)/src/util/config_impl/libgnunetutil_config.la \ $(top_builddir)/src/util/cron/libgnunetutil_cron.la Modified: GNUnet/src/transports/upnp/init.c =================================================================== --- GNUnet/src/transports/upnp/init.c 2006-12-29 15:10:02 UTC (rev 4100) +++ GNUnet/src/transports/upnp/init.c 2006-12-29 15:41:06 UTC (rev 4101) @@ -28,6 +28,8 @@ #include "gnunet_util.h" #include "gnunet_util_cron.h" #include "upnp.h" +#include "gnunet_upnp_service.h" +#include "gnunet_core.h" static struct GE_Context * ectx; @@ -113,34 +115,12 @@ /** * Get the external IP address for the local machine. - */ -void gnunet_upnp_init(struct GC_Configuration * c, - struct GE_Context * e) { - ectx = e; - cfg = c; - cron = cron_create(ectx); - lock = MUTEX_CREATE(NO); - cron_start(cron); - cron_add_job(cron, - &discover, - 0, - 5 * cronMINUTES, - NULL); - cron_add_job(cron, - &portmap, - 150 * cronSECONDS, - 5 * cronMINUTES, - NULL); -} - -/** - * Get the external IP address for the local machine. * * @return SYSERR on error, OK on success */ -int gnunet_upnp_get_ip(unsigned short port, - const char * protocol, - IPaddr * address) { +static int gnunet_upnp_get_ip(unsigned short port, + const char * protocol, + IPaddr * address) { unsigned int i; MUTEX_LOCK(lock); @@ -165,14 +145,41 @@ return gnunet_upnp_get_public_ip(address); } + /** + * Get the external IP address for the local machine. + */ +UPnP_ServiceAPI * +provide_module_upnp(CoreAPIForApplication * capi) { + static UPnP_ServiceAPI api; + + ectx = capi->ectx; + cfg = capi->cfg; + cron = cron_create(ectx); + lock = MUTEX_CREATE(NO); + cron_start(cron); + cron_add_job(cron, + &discover, + 0, + 5 * cronMINUTES, + NULL); + cron_add_job(cron, + &portmap, + 150 * cronSECONDS, + 5 * cronMINUTES, + NULL); + api.get_ip = gnunet_upnp_get_ip; + return &api; +} + +/** * Shutdown UPNP. */ -void gnunet_upnp_done() { +int release_module_upnp() { unsigned int i; if (cron == NULL) - return; /* never used! */ + return SYSERR; /* not loaded! */ for (i=0;i<maps_size;i++) gaim_upnp_change_port_mapping(ectx, cfg, @@ -198,6 +205,7 @@ 0); ectx = NULL; cfg = NULL; + return OK; } Modified: GNUnet/src/transports/upnp/todo =================================================================== --- GNUnet/src/transports/upnp/todo 2006-12-29 15:10:02 UTC (rev 4100) +++ GNUnet/src/transports/upnp/todo 2006-12-29 15:41:06 UTC (rev 4101) @@ -1,5 +1,5 @@ -1) write testcase -2) integrate with transports -- tricky bit: making it optional! -3) remove glib dependency from upnp code! -4) adjust configure to check for libxml2 -5) fix xmlnode memory leaks (for invalid / incomplete XML responses) +1) adjust configure to check for libxml2 +2) remove glib dependency from upnp code! +3) fix xmlnode memory leaks (for invalid / incomplete XML responses) +4) integrate with transports -- tricky bit: making it optional! + (make it a module?) Deleted: GNUnet/src/transports/upnp/upnpdemo.c =================================================================== --- GNUnet/src/transports/upnp/upnpdemo.c 2006-12-29 15:10:02 UTC (rev 4100) +++ GNUnet/src/transports/upnp/upnpdemo.c 2006-12-29 15:41:06 UTC (rev 4101) @@ -1,66 +0,0 @@ -/* - This file is part of GNUnet. - (C) 2006 Christian Grothoff (and other contributing authors) - - GNUnet 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 2, or (at your - option) any later version. - - GNUnet 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 GNUnet; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. -*/ -/** - * @file src/transports/upnp/upnpdemo.c - * @brief Demo for UPnP - * @author Christian Grothoff - */ - -#include "gnunet_util.h" -#include "gnunet_util_config_impl.h" -#include "gnunet_transport_upnp.h" -#include "gnunet_util_error_loggers.h" -#include "platform.h" - -int main(int argc, - const char *argv[]) { - struct GE_Context * ectx; - struct GC_Configuration * cfg; - IPaddr addr; - - ectx = GE_create_context_stderr(NO, - GE_WARNING | GE_ERROR | GE_FATAL | - GE_USER | GE_ADMIN | GE_DEVELOPER | - GE_IMMEDIATE | GE_BULK); - GE_setDefaultContext(ectx); - cfg = GC_create_C_impl(); - GE_ASSERT(ectx, cfg != NULL); - os_init(ectx); - gnunet_upnp_init(cfg, ectx); - - printf("Testing UPnP. Press CTRL-C to abort.\n"); - while (GNUNET_SHUTDOWN_TEST() == NO) { - if (OK == gnunet_upnp_get_ip(2086, - "TCP", - &addr)) { - printf("UPnP returned external IP %u.%u.%u.%u\n", - PRIP(ntohl(*(int*)&addr))); - } else { - printf("No UPnP response (yet).\n"); - } - PTHREAD_SLEEP(2 * cronSECONDS); - } - gnunet_upnp_done(); - GC_free(cfg); - GE_free_context(ectx); - return 0; -} - -/* end of upnpdemo.c */ Modified: GNUnet/src/transports/upnp/upnptest.c =================================================================== --- GNUnet/src/transports/upnp/upnptest.c 2006-12-29 15:10:02 UTC (rev 4100) +++ GNUnet/src/transports/upnp/upnptest.c 2006-12-29 15:41:06 UTC (rev 4101) @@ -25,16 +25,24 @@ #include "gnunet_util.h" #include "gnunet_util_config_impl.h" -#include "gnunet_transport_upnp.h" +#include "gnunet_upnp_service.h" +#include "gnunet_core.h" #include "gnunet_util_error_loggers.h" #include "platform.h" + + int main(int argc, const char *argv[]) { + static CoreAPIForApplication capi; struct GE_Context * ectx; struct GC_Configuration * cfg; IPaddr addr; int i; + UPnP_ServiceAPI * upnp; + struct PluginHandle * plug; + ServiceInitMethod init; + ServiceDoneMethod done; ectx = GE_create_context_stderr(NO, GE_WARNING | GE_ERROR | GE_FATAL | @@ -44,14 +52,36 @@ cfg = GC_create_C_impl(); GE_ASSERT(ectx, cfg != NULL); os_init(ectx); - gnunet_upnp_init(cfg, ectx); - + capi.ectx = ectx; + capi.cfg = cfg; + plug = os_plugin_load(ectx, "libgnunet", "module_upnp"); + if (plug == NULL) { + GC_free(cfg); + GE_free_context(ectx); + return 1; + } + init = os_plugin_resolve_function(plug, + "provide_", + YES); + if (init == NULL) { + os_plugin_unload(plug); + GC_free(cfg); + GE_free_context(ectx); + return 1; + } + upnp = init(&capi); + if (upnp == NULL) { + os_plugin_unload(plug); + GC_free(cfg); + GE_free_context(ectx); + return 1; + } for (i=0;i<10;i++) { if (GNUNET_SHUTDOWN_TEST() != NO) break; - if (OK == gnunet_upnp_get_ip(2086, - "TCP", - &addr)) { + if (OK == upnp->get_ip(2086, + "TCP", + &addr)) { printf("UPnP returned external IP %u.%u.%u.%u\n", PRIP(ntohl(*(int*)&addr))); } else { @@ -62,7 +92,12 @@ } PTHREAD_SLEEP(2 * cronSECONDS); } - gnunet_upnp_done(); + done = os_plugin_resolve_function(plug, + "release_", + YES); + if (done != NULL) + done(); + os_plugin_unload(plug); GC_free(cfg); GE_free_context(ectx); return 0; _______________________________________________ GNUnet-SVN mailing list GNUnet-SVN@gnu.org http://lists.gnu.org/mailman/listinfo/gnunet-svn