gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r4077 - GNUnet/src/transports/upnp


From: grothoff
Subject: [GNUnet-SVN] r4077 - GNUnet/src/transports/upnp
Date: Wed, 27 Dec 2006 09:51:39 -0800 (PST)

Author: grothoff
Date: 2006-12-27 09:51:35 -0800 (Wed, 27 Dec 2006)
New Revision: 4077

Added:
   GNUnet/src/transports/upnp/Makefile.am
   GNUnet/src/transports/upnp/error.c
   GNUnet/src/transports/upnp/error.h
   GNUnet/src/transports/upnp/util.c
   GNUnet/src/transports/upnp/util.h
Modified:
   GNUnet/src/transports/upnp/upnp.c
   GNUnet/src/transports/upnp/xmlnode.c
   GNUnet/src/transports/upnp/xmlnode.h
Log:
towards compiling code

Added: GNUnet/src/transports/upnp/Makefile.am
===================================================================
--- GNUnet/src/transports/upnp/Makefile.am      2006-12-27 16:46:00 UTC (rev 
4076)
+++ GNUnet/src/transports/upnp/Makefile.am      2006-12-27 17:51:35 UTC (rev 
4077)
@@ -0,0 +1,35 @@
+INCLUDES = -I$(top_srcdir)/src/include
+
+AM_CFLAGS = $(GTK_CFLAGS)
+
+plugindir = $(libdir)/GNUnet
+
+# GNU Gettext support
+LIBS = @LIBINTL@ @LIBS@
+
+lib_LTLIBRARIES = \
+  libgnunetupnp.la
+
+libgnunetupnp_la_SOURCES = \
+ error.c error.h \
+ upnp.c upnp.h \
+ util.c util.h \
+ xmlnode.c xmlnode.h
+
+libgnunetupnp_la_LDFLAGS = \
+ $(GTK_LIBS) @EXT_LIB_PATH@ @EXT_LIBS@ \
+ -export-dynamic \
+ -version-info 0:0:0
+
+libgnunetupnp_la_CFLAGS = \
+ -I$(top_scrdir)/include \
+ @GNUNETGTK_CFLAGS@ \
+ @GTK_CFLAGS@ 
+
+libgnunetupnp_la_LIBADD = \
+ @GTK_LIBS@ @EXT_LIB_PATH@ @EXT_LIBS@ \
+ @GNUNETGTK_LIBS@ \
+  $(INTLLIBS) \
+  -lgthread-2.0 \
+ $(top_builddir)/src/util/libgnunetutil.la 
+

Added: GNUnet/src/transports/upnp/error.c
===================================================================
--- GNUnet/src/transports/upnp/error.c  2006-12-27 16:46:00 UTC (rev 4076)
+++ GNUnet/src/transports/upnp/error.c  2006-12-27 17:51:35 UTC (rev 4077)
@@ -0,0 +1,29 @@
+
+#include "error.h"
+
+/**
+ * Map gaim logger to GNUnet logger.
+ */
+void gaim_debug_error(char * facility, 
+                     char * format,
+                     ...) {
+ GE_LOG(NULL,
+       GE_WARNING | GE_DEVELOPER | GE_ADMIN | GE_BULK, 
+       "%s: %s\n",
+       facility,
+       format);
+}
+   
+/**
+ * Map gaim logger to GNUnet logger.
+ */
+void gaim_debug_info(char * facility, 
+                    char * format,
+                    ...) {
+ GE_LOG(NULL,
+       GE_INFO | GE_ADMIN | GE_BULK, 
+       "%s: %s\n",
+       facility,
+       format);
+}
+   


Property changes on: GNUnet/src/transports/upnp/error.c
___________________________________________________________________
Name: svn:eol-style
   + native

Added: GNUnet/src/transports/upnp/error.h
===================================================================
--- GNUnet/src/transports/upnp/error.h  2006-12-27 16:46:00 UTC (rev 4076)
+++ GNUnet/src/transports/upnp/error.h  2006-12-27 17:51:35 UTC (rev 4077)
@@ -0,0 +1,18 @@
+
+#include "gnunet_util.h"
+#include "gnunet_util_cron.h"
+
+/**
+ * Map gaim logger to GNUnet logger.
+ */
+void gaim_debug_error(char * facility, 
+                     char * format,
+                     ...);
+
+
+/**
+ * Map gaim logger to GNUnet logger.
+ */
+void gaim_debug_info(char * facility, 
+                    char * format,
+                    ...);


Property changes on: GNUnet/src/transports/upnp/error.h
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: GNUnet/src/transports/upnp/upnp.c
===================================================================
--- GNUnet/src/transports/upnp/upnp.c   2006-12-27 16:46:00 UTC (rev 4076)
+++ GNUnet/src/transports/upnp/upnp.c   2006-12-27 17:51:35 UTC (rev 4077)
@@ -22,17 +22,13 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
-#include "internal.h"
 
-#include "debug.h"
+#include "platform.h"
+#include "xmlnode.h"
 #include "util.h"
-#include "proxy.h"
-#include "xmlnode.h"
-#include "network.h"
-#include "eventloop.h"
 #include "upnp.h"
+#include "error.h"
 
-
 /***************************************************************
 ** General Defines                                             *
 ****************************************************************/
@@ -775,6 +771,7 @@
        return NULL;
 }
 
+#if 0
 static void
 looked_up_internal_ip_cb(gpointer data, gint source, const gchar 
*error_message)
 {
@@ -789,10 +786,12 @@
                gaim_debug_info("upnp", "Unable to look up local IP\n");
 
 }
+#endif
 
 static void
 lookup_internal_ip()
 {
+#if 0
        gchar* addressOfControl;
        int port = 0;
 
@@ -814,6 +813,7 @@
        }
 
        g_free(addressOfControl);
+#endif
 }
 
 static void

Added: GNUnet/src/transports/upnp/util.c
===================================================================
--- GNUnet/src/transports/upnp/util.c   2006-12-27 16:46:00 UTC (rev 4076)
+++ GNUnet/src/transports/upnp/util.c   2006-12-27 17:51:35 UTC (rev 4077)
@@ -0,0 +1,221 @@
+/*
+ * @file util.h Utility Functions
+ * @ingroup core
+ *
+ * Gaim is the legal property of its developers, whose names are too numerous
+ * to list here.  Please refer to the COPYRIGHT file distributed with this
+ * source distribution.
+ *
+ * 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 2 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include "platform.h"
+#include "util.h"
+#include <glib.h>
+
+/* Returns a NULL-terminated string after unescaping an entity
+ * (eg. &amp;, &lt; &#38 etc.) starting at s. Returns NULL on failure.*/
+static const char *
+detect_entity(const char *text, int *length)
+{
+       const char *pln;
+       int len, pound;
+
+       if (!text || *text != '&')
+               return NULL;
+
+#define IS_ENTITY(s)  (!g_ascii_strncasecmp(text, s, (len = sizeof(s) - 1)))
+
+       if(IS_ENTITY("&amp;"))
+               pln = "&";
+       else if(IS_ENTITY("&lt;"))
+               pln = "<";
+       else if(IS_ENTITY("&gt;"))
+               pln = ">";
+       else if(IS_ENTITY("&nbsp;"))
+               pln = " ";
+       else if(IS_ENTITY("&copy;"))
+               pln = "\302\251";      /* or use g_unichar_to_utf8(0xa9); */
+       else if(IS_ENTITY("&quot;"))
+               pln = "\"";
+       else if(IS_ENTITY("&reg;"))
+               pln = "\302\256";      /* or use g_unichar_to_utf8(0xae); */
+       else if(IS_ENTITY("&apos;"))
+               pln = "\'";
+       else if(*(text+1) == '#' && (sscanf(text, "&#%u;", &pound) == 1) &&
+                       pound != 0 && *(text+3+(gint)log10(pound)) == ';') {
+               static char buf[7];
+               int buflen = g_unichar_to_utf8((gunichar)pound, buf);
+               buf[buflen] = '\0';
+               pln = buf;
+
+               len = 2;
+               while(isdigit((gint) text[len])) len++;
+               if(text[len] == ';') len++;
+       }
+       else
+               return NULL;
+
+       if (length)
+               *length = len;
+       return pln;
+}
+
+char *
+gaim_unescape_html(const char *html) {
+       if (html != NULL) {
+               const char *c = html;
+               GString *ret = g_string_new("");
+               while (*c) {
+                       int len;
+                       const char *ent;
+
+                       if ((ent = detect_entity(c, &len)) != NULL) {
+                               ret = g_string_append(ret, ent);
+                               c += len;
+                       } else if (!strncmp(c, "<br>", 4)) {
+                               ret = g_string_append_c(ret, '\n');
+                               c += 4;
+                       } else {
+                               ret = g_string_append_c(ret, *c);
+                               c++;
+                       }
+               }
+               return g_string_free(ret, FALSE);
+       }
+
+       return NULL;
+}
+
+
+/**************************************************************************
+ * URI/URL Functions
+ **************************************************************************/
+gboolean
+gaim_url_parse(const char *url, char **ret_host, int *ret_port,
+                          char **ret_path, char **ret_user, char **ret_passwd)
+{
+       char scan_info[255];
+       char port_str[6];
+       int f;
+       const char *at, *slash;
+       const char *turl;
+       char host[256], path[256], user[256], passwd[256];
+       int port = 0;
+       /* hyphen at end includes it in control set */
+       static char addr_ctrl[] = "A-Za-z0-9.-";
+       static char port_ctrl[] = "0-9";
+       static char page_ctrl[] = "A-Za-z0-9.~_/:*!@&%%?=+^-";
+       static char user_ctrl[] = "A-Za-z0-9.~_/*!&%%?=+^-";
+       static char passwd_ctrl[] = "A-Za-z0-9.~_/*!&%%?=+^-";
+
+       g_return_val_if_fail(url != NULL, FALSE);
+
+       if ((turl = strstr(url, "http://";)) != NULL ||
+               (turl = strstr(url, "HTTP://")) != NULL)
+       {
+               turl += 7;
+               url = turl;
+       }
+
+       /* parse out authentication information if supplied */
+       /* Only care about @ char BEFORE the first / */
+       at = strchr(url, '@');
+       slash = strchr(url, '/');
+       if ((at != NULL) &&
+                       (((slash != NULL) && (strlen(at) > strlen(slash))) ||
+                       (slash == NULL))) {
+               g_snprintf(scan_info, sizeof(scan_info),
+                                       "%%255[%s]:%%255[%s]^@", user_ctrl, 
passwd_ctrl);
+               f = sscanf(url, scan_info, user, passwd);
+
+               if (f ==1 ) {
+                       /* No passwd, possibly just username supplied */
+                       g_snprintf(scan_info, sizeof(scan_info),
+                                               "%%255[%s]^@", user_ctrl);
+                       f = sscanf(url, scan_info, user);
+                       *passwd = '\0';
+               }
+
+               url = at+1; /* move pointer after the @ char */
+       } else {
+               *user = '\0';
+               *passwd = '\0';
+       }
+
+       g_snprintf(scan_info, sizeof(scan_info),
+                          "%%255[%s]:%%5[%s]/%%255[%s]", addr_ctrl, port_ctrl, 
page_ctrl);
+
+       f = sscanf(url, scan_info, host, port_str, path);
+
+       if (f == 1)
+       {
+               g_snprintf(scan_info, sizeof(scan_info),
+                                  "%%255[%s]/%%255[%s]",
+                                  addr_ctrl, page_ctrl);
+               f = sscanf(url, scan_info, host, path);
+               g_snprintf(port_str, sizeof(port_str), "80");
+       }
+
+       if (f == 1)
+               *path = '\0';
+
+       sscanf(port_str, "%d", &port);
+
+       if (ret_host != NULL) *ret_host = g_strdup(host);
+       if (ret_port != NULL) *ret_port = port;
+       if (ret_path != NULL) *ret_path = g_strdup(path);
+       if (ret_user != NULL) *ret_user = g_strdup(user);
+       if (ret_passwd != NULL) *ret_passwd = g_strdup(passwd);
+
+       return TRUE;
+}
+
+
+gaim_str_has_prefix(const char *s, const char *p)
+{
+#if GLIB_CHECK_VERSION(2,2,0)
+        return g_str_has_prefix(s, p);
+#else
+        g_return_val_if_fail(s != NULL, FALSE);
+        g_return_val_if_fail(p != NULL, FALSE);
+
+        return (!strncmp(s, p, strlen(p)));
+#endif
+}
+
+/**
+ * Fetches the data from a URL, and passes it to a callback function.
+ *
+ * @param url        The URL.
+ * @param full       TRUE if this is the full URL, or FALSE if it's a
+ *                   partial URL.
+ * @param user_agent The user agent field to use, or NULL.
+ * @param http11     TRUE if HTTP/1.1 should be used to download the file.
+ * @param request    A HTTP request to send to the server instead of the
+ *                   standard GET
+ * @param include_headers
+ *                   If TRUE, include the HTTP headers in the response.
+ * @param callback   The callback function.
+ * @param data       The user data to pass to the callback function.
+ */
+GaimUtilFetchUrlData *gaim_util_fetch_url_request(const gchar *url,
+               gboolean full, const gchar *user_agent, gboolean http11,
+               const gchar *request, gboolean include_headers,
+                                                 GaimUtilFetchUrlCallback 
callback, gpointer data) {
+  /* FIXME: implement using libcurl? */
+  return NULL;
+}
+


Property changes on: GNUnet/src/transports/upnp/util.c
___________________________________________________________________
Name: svn:eol-style
   + native

Added: GNUnet/src/transports/upnp/util.h
===================================================================
--- GNUnet/src/transports/upnp/util.h   2006-12-27 16:46:00 UTC (rev 4076)
+++ GNUnet/src/transports/upnp/util.h   2006-12-27 17:51:35 UTC (rev 4077)
@@ -0,0 +1,126 @@
+/**
+ * @file util.h Utility Functions
+ * @ingroup core
+ *
+ * gaim
+ *
+ * Gaim is the legal property of its developers, whose names are too numerous
+ * to list here.  Please refer to the COPYRIGHT file distributed with this
+ * source distribution.
+ *
+ * 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 2 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * @todo Rename the functions so that they live somewhere in the gaim
+ *       namespace.
+ */
+#ifndef _GAIM_UTIL_H_
+#define _GAIM_UTIL_H_
+
+#include <stdio.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+typedef struct _GaimUtilFetchUrlData GaimUtilFetchUrlData;
+
+
+/**
+ * This is the signature used for functions that act as the callback
+ * to gaim_util_fetch_url() or gaim_util_fetch_url_request().
+ *
+ * @param url_data      The same value that was returned when you called
+ *                      gaim_fetch_url() or gaim_fetch_url_request().
+ * @param user_data     The user data that your code passed into either
+ *                      gaim_util_fetch_url() or gaim_util_fetch_url_request().
+ * @param url_text      This will be NULL on error.  Otherwise this
+ *                      will contain the contents of the URL.
+ * @param len           0 on error, otherwise this is the length of buf.
+ * @param error_message If something went wrong then this will contain
+ *                      a descriptive error message, and buf will be
+ *                      NULL and len will be 0.
+ */
+typedef void (*GaimUtilFetchUrlCallback)(GaimUtilFetchUrlData *url_data, 
gpointer user_data, const gchar *url_text, gsize len, const gchar 
*error_message);
+
+
+
+/**
+ * Unescapes HTML entities to their literal characters.
+ * For example "&amp;" is replaced by '&' and so on.
+ * Actually only "&amp;", "&quot;", "&lt;" and "&gt;" are currently
+ * supported.
+ *
+ * @param html The string in which to unescape any HTML entities
+ *
+ * @return the text with HTML entities literalized
+ */
+char *gaim_unescape_html(const char *html);
+
+
+/**
+ * Parses a URL, returning its host, port, file path, username and password.
+ *
+ * The returned data must be freed.
+ *
+ * @param url      The URL to parse.
+ * @param ret_host The returned host.
+ * @param ret_port The returned port.
+ * @param ret_path The returned path.
+ * @param ret_user The returned username.
+ * @param ret_passwd The returned password.
+ */
+gboolean gaim_url_parse(const char *url, char **ret_host, int *ret_port,
+                                               char **ret_path, char 
**ret_user, char **ret_passwd);
+
+
+
+/**
+ * Compares two strings to see if the first contains the second as
+ * a proper prefix.
+ *
+ * @param s  The string to check.
+ * @param p  The prefix in question.
+ *
+ * @return   TRUE if p is a prefix of s, otherwise FALSE.
+ */
+gboolean gaim_str_has_prefix(const char *s, const char *p);
+
+/**
+ * Fetches the data from a URL, and passes it to a callback function.
+ *
+ * @param url        The URL.
+ * @param full       TRUE if this is the full URL, or FALSE if it's a
+ *                   partial URL.
+ * @param user_agent The user agent field to use, or NULL.
+ * @param http11     TRUE if HTTP/1.1 should be used to download the file.
+ * @param request    A HTTP request to send to the server instead of the
+ *                   standard GET
+ * @param include_headers
+ *                   If TRUE, include the HTTP headers in the response.
+ * @param callback   The callback function.
+ * @param data       The user data to pass to the callback function.
+ */
+GaimUtilFetchUrlData *gaim_util_fetch_url_request(const gchar *url,
+               gboolean full, const gchar *user_agent, gboolean http11,
+               const gchar *request, gboolean include_headers,
+               GaimUtilFetchUrlCallback callback, gpointer data);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif


Property changes on: GNUnet/src/transports/upnp/util.h
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: GNUnet/src/transports/upnp/xmlnode.c
===================================================================
--- GNUnet/src/transports/upnp/xmlnode.c        2006-12-27 16:46:00 UTC (rev 
4076)
+++ GNUnet/src/transports/upnp/xmlnode.c        2006-12-27 17:51:35 UTC (rev 
4077)
@@ -27,15 +27,13 @@
  * write my own stuff.  Also, re-writing this lets me be as lightweight
  * as I want to be.  Thank you libxode for giving me a good starting point */
 
-#include "internal.h"
+#include "platform.h"
 
 #include <libxml/parser.h>
 #include <string.h>
 #include <glib.h>
-
-#include "dbus-maybe.h"
-#include "util.h"
 #include "xmlnode.h"
+#include "util.h"
 
 #ifdef _WIN32
 # define NEWLINE_S "\r\n"
@@ -50,9 +48,9 @@
 
        node->name = g_strdup(name);
        node->type = type;
-
+#if 0
        GAIM_DBUS_REGISTER_POINTER(node, xmlnode);
-
+#endif
        return node;
 }
 
@@ -277,8 +275,9 @@
        g_free(node->name);
        g_free(node->data);
        g_free(node->xmlns);
-
+#if 0
        GAIM_DBUS_UNREGISTER_POINTER(node);
+#endif
        g_free(node);
 }
 

Modified: GNUnet/src/transports/upnp/xmlnode.h
===================================================================
--- GNUnet/src/transports/upnp/xmlnode.h        2006-12-27 16:46:00 UTC (rev 
4076)
+++ GNUnet/src/transports/upnp/xmlnode.h        2006-12-27 17:51:35 UTC (rev 
4077)
@@ -29,6 +29,10 @@
 extern "C" {
 #endif
 
+#include <libxml/parser.h>
+#include <string.h>
+#include <glib.h>
+
 /**
  * The valid types for an xmlnode
  */





reply via email to

[Prev in Thread] Current Thread [Next in Thread]