aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Lamping <ulf.lamping@web.de>2007-01-13 14:33:46 +0000
committerUlf Lamping <ulf.lamping@web.de>2007-01-13 14:33:46 +0000
commitd3a85fae38cfbea3ae6ab46892c6c10c7687da98 (patch)
tree873ab1be1d1d0afae8e2620154179bb8d1ea4e47
parent2fd7d2c62078813f44e78f0b4b9f8b0e6e5928fb (diff)
far from being complete:
as mentioned on the devel list, this is a very first start of implementing the Wireshark update/version check feature think of it as a backup / discussion base only - it's not even added to the Makefiles yet svn path=/trunk/; revision=20415
-rw-r--r--nio-ie5.c198
-rw-r--r--nio-ie5.h32
-rw-r--r--update.c343
3 files changed, 573 insertions, 0 deletions
diff --git a/nio-ie5.c b/nio-ie5.c
new file mode 100644
index 0000000000..9ad0b72553
--- /dev/null
+++ b/nio-ie5.c
@@ -0,0 +1,198 @@
+/*
+ * Copyright (c) 2000, Red Hat, Inc.
+ *
+ * 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.
+ *
+ * A copy of the GNU General Public License can be found at
+ * http://www.gnu.org/
+ *
+ * Written by DJ Delorie <dj@cygnus.com>
+ * Modified by Ulf Lamping to meet Wireshark use
+ *
+ */
+
+/* The purpose of this file is to manage internet downloads using the
+ Internet Explorer version 5 DLLs. To use this method, the user
+ must already have installed and configured IE5. */
+
+#include "windows.h"
+#include <wininet.h>
+#include "nio-ie5.h"
+
+#include "glib.h"
+
+static HINTERNET internet = 0;
+
+
+
+netio_ie5_t *
+netio_ie5_connect (char const *url)
+{
+ int resend = 0;
+ DWORD type, type_s;
+ netio_ie5_t * netio_ie5_conn;
+ DWORD dw_ret;
+ DWORD flags =
+ /* INTERNET_FLAG_DONT_CACHE |*/
+ INTERNET_FLAG_KEEP_CONNECTION |
+ /* INTERNET_FLAG_PRAGMA_NOCACHE |*/
+ /* INTERNET_FLAG_RELOAD |*/
+ INTERNET_FLAG_EXISTING_CONNECT | INTERNET_FLAG_PASSIVE;
+
+ if (internet == 0)
+ {
+ HINSTANCE h = LoadLibrary ("wininet.dll");
+ if (!h)
+ {
+ /* XXX - how to return an error code? */
+ g_warning("Failed to load wininet.dll");
+ return NULL;
+ }
+ /* pop-up dialup dialog box */
+ /* XXX - do we need the dialup box or simply don't attempt an update in this case? */
+ dw_ret = InternetAttemptConnect (0);
+ if (dw_ret != ERROR_SUCCESS) {
+ g_warning("InternetAttemptConnect failed: %u", dw_ret);
+ return NULL;
+ }
+ internet = InternetOpen ("Wireshark Update", INTERNET_OPEN_TYPE_PRECONFIG,
+ NULL, NULL, 0);
+ if(internet == NULL) {
+ g_warning("InternetOpen failed %u", GetLastError());
+ return NULL;
+ }
+ }
+
+ netio_ie5_conn = g_malloc(sizeof(netio_ie5_t));
+
+ netio_ie5_conn->connection = InternetOpenUrl (internet, url, NULL, 0, flags, 0);
+
+try_again:
+
+#if 0
+ /* XXX - implement this option */
+ if (net_user && net_passwd)
+ {
+ InternetSetOption (connection, INTERNET_OPTION_USERNAME,
+ net_user, strlen (net_user));
+ InternetSetOption (connection, INTERNET_OPTION_PASSWORD,
+ net_passwd, strlen (net_passwd));
+ }
+#endif
+
+#if 0
+ /* XXX - implement this option */
+ if (net_proxy_user && net_proxy_passwd)
+ {
+ InternetSetOption (connection, INTERNET_OPTION_PROXY_USERNAME,
+ net_proxy_user, strlen (net_proxy_user));
+ InternetSetOption (connection, INTERNET_OPTION_PROXY_PASSWORD,
+ net_proxy_passwd, strlen (net_proxy_passwd));
+ }
+#endif
+
+ if (resend)
+ if (!HttpSendRequest (netio_ie5_conn->connection, 0, 0, 0, 0))
+ netio_ie5_conn->connection = 0;
+
+ if (!netio_ie5_conn->connection)
+ {
+ switch(GetLastError ()) {
+ case ERROR_INTERNET_EXTENDED_ERROR:
+ {
+ char buf[2000];
+ DWORD e, l = sizeof (buf);
+ InternetGetLastResponseInfo (&e, buf, &l);
+ MessageBox (0, buf, "Internet Error", 0);
+ }
+ break;
+ case ERROR_INTERNET_NAME_NOT_RESOLVED:
+ g_warning("Internet error: The servername could not be resolved");
+ break;
+ case ERROR_INTERNET_CANNOT_CONNECT:
+ g_warning("Internet error: Could not connect to the server");
+ break;
+ default:
+ g_warning("Internet error: %u", GetLastError ());
+ }
+ return NULL;
+ }
+
+ type_s = sizeof (type);
+ InternetQueryOption (netio_ie5_conn->connection, INTERNET_OPTION_HANDLE_TYPE,
+ &type, &type_s);
+
+ switch (type)
+ {
+ case INTERNET_HANDLE_TYPE_HTTP_REQUEST:
+ case INTERNET_HANDLE_TYPE_CONNECT_HTTP:
+ type_s = sizeof (DWORD);
+ if (HttpQueryInfo (netio_ie5_conn->connection,
+ HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER,
+ &type, &type_s, NULL))
+ {
+ if (type == 401) /* authorization required */
+ {
+ netio_ie5_flush_io (netio_ie5_conn);
+ /* XXX - query net_user && net_passwd from user
+ get_auth (NULL);*/
+ resend = 1;
+ goto try_again;
+ }
+ else if (type == 407) /* proxy authorization required */
+ {
+ netio_ie5_flush_io (netio_ie5_conn);
+ /* XXX - query net_proxy_user && net_proxy_passwd from user
+ get_proxy_auth (NULL);*/
+ resend = 1;
+ goto try_again;
+ }
+ else if (type >= 300)
+ {
+ g_warning("Failed with HTTP response %u", type);
+ g_free(netio_ie5_conn);
+ return NULL;
+ }
+ }
+ }
+
+ return netio_ie5_conn;
+}
+
+void
+netio_ie5_flush_io (netio_ie5_t * netio_e5_conn)
+{
+ DWORD actual = 0;
+ char buf[1024];
+ do
+ {
+ InternetReadFile (netio_e5_conn->connection, buf, 1024, &actual);
+ }
+ while (actual > 0);
+}
+
+void
+netio_ie5_disconnect (netio_ie5_t * netio_e5_conn)
+{
+ if (netio_e5_conn->connection)
+ InternetCloseHandle (netio_e5_conn->connection);
+ g_free(netio_e5_conn);
+}
+
+int
+netio_ie5_ok (netio_ie5_t * netio_e5_conn)
+{
+ return (netio_e5_conn->connection == NULL) ? 0 : 1;
+}
+
+int
+netio_ie5_read (netio_ie5_t * netio_e5_conn, char *buf, int nbytes)
+{
+ DWORD actual;
+ if (InternetReadFile (netio_e5_conn->connection, buf, nbytes, &actual))
+ return actual;
+ return -1;
+}
diff --git a/nio-ie5.h b/nio-ie5.h
new file mode 100644
index 0000000000..d6528f322d
--- /dev/null
+++ b/nio-ie5.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2000, Red Hat, Inc.
+ *
+ * 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.
+ *
+ * A copy of the GNU General Public License can be found at
+ * http://www.gnu.org/
+ *
+ * Written by DJ Delorie <dj@cygnus.com>
+ * Modified by Ulf Lamping to meet Wireshark use
+ *
+ */
+
+#ifndef SETUP_NIO_IE5_H
+#define SETUP_NIO_IE5_H
+
+/* see nio-ie5.c */
+
+typedef struct netio_ie5_s {
+ HINTERNET connection;
+} netio_ie5_t;
+
+netio_ie5_t * netio_ie5_connect (char const *url);
+void netio_ie5_disconnect (netio_ie5_t * netio_e5_conn);
+int netio_ie5_ok (netio_ie5_t * netio_e5_conn);
+int netio_ie5_read (netio_ie5_t * netio_e5_conn, char *buf, int nbytes);
+void netio_ie5_flush_io (netio_ie5_t * netio_e5_conn);
+
+#endif /* SETUP_NIO_IE5_H */
diff --git a/update.c b/update.c
new file mode 100644
index 0000000000..1389e4a38f
--- /dev/null
+++ b/update.c
@@ -0,0 +1,343 @@
+/* update.c
+ *
+ * $Id: update.c 19935 2006-11-19 23:23:53Z gerald $
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 1998 Gerald Combs
+ *
+ *
+ * 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <glib.h>
+#include <string.h>
+#include <stdio.h>
+
+#include <epan/prefs.h>
+#include <epan/prefs-int.h>
+#include <epan/filesystem.h>
+
+#include "simple_dialog.h"
+#include "version_info.h"
+
+#ifdef HAVE_LIBPCAP
+#include "capture-pcap-util.h"
+#endif
+
+#include "file_util.h"
+
+#include <wininet.h>
+#include "nio-ie5.h"
+
+
+/* update information about a single component */
+typedef struct update_info_s {
+ char *prefix; /* prefix of the update file keys */
+ gboolean needs_update; /* does this component need an update */
+ char *version_installed; /* the version currently installed */
+
+ char *title; /* the component title (name) */
+ char *description; /* description of the component */
+ char *version_recommended; /* the version recommended */
+ char *url; /* the URL for an update */
+ char *md5; /* md5 checksum for that update */
+ char *size; /* size of that update */
+} update_info_t;
+
+
+/* download a complete file from the internet */
+int
+download_file(const char *url, const char *filename) {
+ netio_ie5_t * conn;
+ char buf[100];
+ int chunk_len;
+ int fd;
+ int stream_len;
+ int ret = 0;
+
+
+ /* open output file */
+ fd = eth_open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644);
+ if(fd == -1) {
+ g_warning("Couldn't open output file %s!", filename);
+ return -1;
+ }
+
+ /* connect to url */
+ conn = netio_ie5_connect (url);
+ if (conn == NULL) {
+ g_warning("Couldn't connect to %s!", url);
+ return -1;
+ }
+
+ do {
+ /* XXX - maybe add a progress bar here */
+
+ /* read some bytes from the url */
+ chunk_len = netio_ie5_read (conn, buf, sizeof(buf));
+
+ /* write bytes to the output file */
+ stream_len = eth_write( fd, buf, chunk_len);
+ if(stream_len != chunk_len) {
+ g_warning("output failed: stream_len %u != chunk_len %u", stream_len, chunk_len);
+ ret = -1;
+ break;
+ }
+ } while(chunk_len > 0);
+
+ netio_ie5_disconnect(conn);
+
+ eth_close(fd);
+
+ return ret;
+}
+
+update_info_t *
+update_info_new(void)
+{
+ return g_malloc0(sizeof(update_info_t));
+}
+
+void
+update_info_delete(update_info_t *update_info)
+{
+ if(update_info->prefix)
+ g_free(update_info->prefix);
+ if(update_info->version_installed)
+ g_free(update_info->version_installed);
+
+ if(update_info->title)
+ g_free(update_info->title);
+ if(update_info->description)
+ g_free(update_info->description);
+ if(update_info->version_recommended)
+ g_free(update_info->version_recommended);
+ if(update_info->url)
+ g_free(update_info->url);
+ if(update_info->md5)
+ g_free(update_info->md5);
+ if(update_info->size)
+ g_free(update_info->size);
+
+ g_free(update_info);
+}
+
+/* check a single key value pair */
+static void
+update_pref_check(gchar *pref_name, gchar *value, char *check_prefix, char *check_name, char **check_value)
+{
+ GString *check = g_string_new(check_prefix);
+
+ g_string_append(check, check_name);
+
+ if(strcmp(pref_name, check->str) == 0) {
+ if(*check_value)
+ /* there shouldn't be a duplicate entry in the update file */
+ g_warning("Duplicate of %s: current %s former %s", pref_name, value, *check_value);
+ else
+ *check_value = g_strdup(value);
+ }
+
+ g_string_free(check, TRUE);
+}
+
+/* a new key value pair from the update file */
+static int
+update_pref(gchar *pref_name, gchar *value, void *private_data)
+{
+ update_info_t *update_info = private_data;
+
+ update_pref_check(pref_name, value, update_info->prefix, "title", &update_info->title);
+ update_pref_check(pref_name, value, update_info->prefix, "description", &update_info->description);
+ update_pref_check(pref_name, value, update_info->prefix, "version", &update_info->version_recommended);
+ update_pref_check(pref_name, value, update_info->prefix, "update.url", &update_info->url);
+ update_pref_check(pref_name, value, update_info->prefix, "update.md5", &update_info->md5);
+ update_pref_check(pref_name, value, update_info->prefix, "update.size", &update_info->size);
+
+ return PREFS_SET_OK;
+}
+
+/* display an update_info */
+static void
+update_info_display(update_info_t *update_info)
+{
+ GString *overview;
+
+
+ overview = g_string_new("");
+
+ if(update_info->title) {
+ g_string_append_printf(overview, "%s%s%s",
+ simple_dialog_primary_start(), update_info->title, simple_dialog_primary_end());
+ } else {
+ g_string_append_printf(overview, "%sComponent%s",
+ simple_dialog_primary_start(), simple_dialog_primary_end());
+ }
+
+ g_string_append(overview, "\n\n");
+
+ if(update_info->description)
+ g_string_append_printf(overview, "%s\n\n", update_info->description);
+
+ g_string_append_printf(overview, "Installed: %s\n", update_info->version_installed);
+
+ if(update_info->version_recommended)
+ g_string_append_printf(overview, "Recommended: %s\n", update_info->version_recommended);
+ else
+ g_string_append(overview, "Recommenced: unknown\n");
+
+ if(update_info->version_recommended && update_info->url)
+ g_string_append_printf(overview, "From: %s\n", update_info->url);
+
+ if(update_info->size)
+ g_string_append_printf(overview, "Size: %s", update_info->size);
+
+ simple_dialog(ESD_TYPE_INFO, ESD_BTN_OK, overview->str);
+
+ g_string_free(overview, TRUE);
+
+}
+
+/* check the version of the wireshark program */
+static update_info_t *
+update_check_wireshark(const char *local_file)
+{
+ FILE *pf;
+ update_info_t *update_info = update_info_new();
+
+
+ update_info->version_installed = g_strdup(VERSION);
+ update_info->prefix = "wireshark.setup.";
+
+ pf = eth_fopen(local_file, "r");
+ if(pf != NULL) {
+ /* read in update_info of Wireshark */
+ read_prefs_file(local_file, pf, update_pref, update_info);
+ fclose(pf);
+
+ /* check if Wireshark needs an update */
+ if(update_info->version_installed && update_info->version_recommended &&
+ strcmp(update_info->version_installed, update_info->version_recommended) != 0)
+ {
+ update_info->needs_update = TRUE;
+ }
+ } else {
+ g_warning("Could not open %s", local_file);
+ }
+
+ return update_info;
+}
+
+/* check the version of winpcap */
+static update_info_t *
+update_check_winpcap(const char *local_file)
+{
+ FILE *pf;
+ update_info_t * update_info = update_info_new();
+ GString *pcap_version_tmp;
+ char *pcap_version = NULL;
+ char *pcap_vstart;
+ char *pcap_vend;
+
+
+ update_info->prefix = "winpcap.";
+
+ pf = eth_fopen(local_file, "r");
+ if(pf != NULL) {
+ /* read in update_info of WinPcap */
+ read_prefs_file(local_file, pf, update_pref, update_info);
+ fclose(pf);
+
+ /* get WinPcap version */
+ /* XXX - what's the "approved" method to get the WinPcap version? */
+ pcap_version_tmp = g_string_new("");
+ get_runtime_pcap_version(pcap_version_tmp);
+
+ /* cut out real version from "combined" version string */
+ pcap_vstart = strstr(pcap_version_tmp->str, "WinPcap version ");
+ if(pcap_vstart != NULL) {
+ pcap_vstart += sizeof("WinPcap version");
+ pcap_vend = strstr(pcap_vstart, " ");
+ if(pcap_vend != NULL) {
+ pcap_vend[0] = 0;
+ pcap_version = g_strdup(pcap_vstart);
+ }
+ }
+
+ update_info->version_recommended = g_strdup(pcap_version);
+
+ if(pcap_version && update_info->version_recommended &&
+ strcmp(pcap_version, update_info->version_recommended) != 0)
+ {
+ update_info->needs_update = TRUE;
+ }
+ } else {
+ g_warning("Could not open %s", local_file);
+ }
+
+ g_string_free(pcap_version_tmp, TRUE);
+ if(pcap_version)
+ g_free(pcap_version);
+
+ return update_info;
+}
+
+
+/* check for all updates */
+void
+update_check(void)
+{
+ char *local_file;
+ const char *url_file = "http://127.0.0.1/wsupdate"; /* XXX - build the URL depending on platform, versions, ... */
+ update_info_t *update_info;
+
+
+ /* build update file name */
+ /* XXX - using the personal path, use temp dir instead? */
+ local_file = get_persconffile_path("wsupdate", TRUE /*for_writing*/);
+ if(local_file == NULL) {
+ g_warning("Couldn't create output path!");
+ return;
+ }
+
+ /* download update file */
+ if(download_file(url_file, local_file) == -1) {
+ g_warning("Couldn't download update file: %s", local_file);
+ g_free(local_file);
+ return;
+ }
+
+ /* check wireshark */
+ update_info = update_check_wireshark(local_file);
+ if(update_info->needs_update)
+ update_info_display(update_info);
+
+ update_info_delete(update_info);
+
+ /* check winpcap */
+ update_info = update_check_winpcap(local_file);
+ if(update_info->needs_update)
+ update_info_display(update_info);
+
+ update_info_delete(update_info);
+
+ g_free(local_file);
+}
+