3 * $Id: update.c 19935 2006-11-19 23:23:53Z gerald $
\r
5 * Wireshark - Network traffic analyzer
\r
6 * By Gerald Combs <gerald@wireshark.org>
\r
7 * Copyright 1998 Gerald Combs
\r
10 * This program is free software; you can redistribute it and/or
\r
11 * modify it under the terms of the GNU General Public License
\r
12 * as published by the Free Software Foundation; either version 2
\r
13 * of the License, or (at your option) any later version.
\r
15 * This program is distributed in the hope that it will be useful,
\r
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
18 * GNU General Public License for more details.
\r
20 * You should have received a copy of the GNU General Public License
\r
21 * along with this program; if not, write to the Free Software
\r
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
\r
25 #ifdef HAVE_CONFIG_H
\r
26 # include "config.h"
\r
33 #include <epan/prefs.h>
\r
34 #include <epan/prefs-int.h>
\r
35 #include <epan/filesystem.h>
\r
37 #include "simple_dialog.h"
\r
38 #include "version_info.h"
\r
41 #include "capture-pcap-util.h"
\r
44 #include "file_util.h"
\r
46 #include <wininet.h>
\r
47 #include "nio-ie5.h"
\r
50 /* update information about a single component */
\r
51 typedef struct update_info_s {
\r
52 char *prefix; /* prefix of the update file keys */
\r
53 gboolean needs_update; /* does this component need an update */
\r
54 char *version_installed; /* the version currently installed */
\r
56 char *title; /* the component title (name) */
\r
57 char *description; /* description of the component */
\r
58 char *version_recommended; /* the version recommended */
\r
59 char *url; /* the URL for an update */
\r
60 char *md5; /* md5 checksum for that update */
\r
61 char *size; /* size of that update */
\r
65 /* download a complete file from the internet */
\r
67 download_file(const char *url, const char *filename) {
\r
76 /* open output file */
\r
77 fd = eth_open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644);
\r
79 g_warning("Couldn't open output file %s!", filename);
\r
83 /* connect to url */
\r
84 conn = netio_ie5_connect (url);
\r
86 g_warning("Couldn't connect to %s!", url);
\r
91 /* XXX - maybe add a progress bar here */
\r
93 /* read some bytes from the url */
\r
94 chunk_len = netio_ie5_read (conn, buf, sizeof(buf));
\r
96 /* write bytes to the output file */
\r
97 stream_len = eth_write( fd, buf, chunk_len);
\r
98 if(stream_len != chunk_len) {
\r
99 g_warning("output failed: stream_len %u != chunk_len %u", stream_len, chunk_len);
\r
103 } while(chunk_len > 0);
\r
105 netio_ie5_disconnect(conn);
\r
113 update_info_new(void)
\r
115 return g_malloc0(sizeof(update_info_t));
\r
119 update_info_delete(update_info_t *update_info)
\r
121 if(update_info->prefix)
\r
122 g_free(update_info->prefix);
\r
123 if(update_info->version_installed)
\r
124 g_free(update_info->version_installed);
\r
126 if(update_info->title)
\r
127 g_free(update_info->title);
\r
128 if(update_info->description)
\r
129 g_free(update_info->description);
\r
130 if(update_info->version_recommended)
\r
131 g_free(update_info->version_recommended);
\r
132 if(update_info->url)
\r
133 g_free(update_info->url);
\r
134 if(update_info->md5)
\r
135 g_free(update_info->md5);
\r
136 if(update_info->size)
\r
137 g_free(update_info->size);
\r
139 g_free(update_info);
\r
142 /* check a single key value pair */
\r
144 update_pref_check(gchar *pref_name, gchar *value, char *check_prefix, char *check_name, char **check_value)
\r
146 GString *check = g_string_new(check_prefix);
\r
148 g_string_append(check, check_name);
\r
150 if(strcmp(pref_name, check->str) == 0) {
\r
152 /* there shouldn't be a duplicate entry in the update file */
\r
153 g_warning("Duplicate of %s: current %s former %s", pref_name, value, *check_value);
\r
155 *check_value = g_strdup(value);
\r
158 g_string_free(check, TRUE);
\r
161 /* a new key value pair from the update file */
\r
162 static prefs_set_pref_e
\r
163 update_pref(gchar *pref_name, gchar *value, void *private_data)
\r
165 update_info_t *update_info = private_data;
\r
167 update_pref_check(pref_name, value, update_info->prefix, "title", &update_info->title);
\r
168 update_pref_check(pref_name, value, update_info->prefix, "description", &update_info->description);
\r
169 update_pref_check(pref_name, value, update_info->prefix, "version", &update_info->version_recommended);
\r
170 update_pref_check(pref_name, value, update_info->prefix, "update.url", &update_info->url);
\r
171 update_pref_check(pref_name, value, update_info->prefix, "update.md5", &update_info->md5);
\r
172 update_pref_check(pref_name, value, update_info->prefix, "update.size", &update_info->size);
\r
174 return PREFS_SET_OK;
\r
177 /* display an update_info */
\r
179 update_info_display(update_info_t *update_info)
\r
184 overview = g_string_new("");
\r
186 if(update_info->title) {
\r
187 g_string_append_printf(overview, "%s%s%s",
\r
188 simple_dialog_primary_start(), update_info->title, simple_dialog_primary_end());
\r
190 g_string_append_printf(overview, "%sComponent%s",
\r
191 simple_dialog_primary_start(), simple_dialog_primary_end());
\r
194 g_string_append(overview, "\n\n");
\r
196 if(update_info->description)
\r
197 g_string_append_printf(overview, "%s\n\n", update_info->description);
\r
199 g_string_append_printf(overview, "Installed: %s\n", update_info->version_installed);
\r
201 if(update_info->version_recommended)
\r
202 g_string_append_printf(overview, "Recommended: %s\n", update_info->version_recommended);
\r
204 g_string_append(overview, "Recommenced: unknown\n");
\r
206 if(update_info->version_recommended && update_info->url)
\r
207 g_string_append_printf(overview, "From: %s\n", update_info->url);
\r
209 if(update_info->size)
\r
210 g_string_append_printf(overview, "Size: %s", update_info->size);
\r
212 simple_dialog(ESD_TYPE_INFO, ESD_BTN_OK, overview->str);
\r
214 g_string_free(overview, TRUE);
\r
218 /* check the version of the wireshark program */
\r
219 static update_info_t *
\r
220 update_check_wireshark(const char *local_file)
\r
223 update_info_t *update_info = update_info_new();
\r
226 update_info->version_installed = g_strdup(VERSION);
\r
227 update_info->prefix = "wireshark.setup.";
\r
229 pf = eth_fopen(local_file, "r");
\r
231 /* read in update_info of Wireshark */
\r
232 read_prefs_file(local_file, pf, update_pref, update_info);
\r
235 /* check if Wireshark needs an update */
\r
236 if(update_info->version_installed && update_info->version_recommended &&
\r
237 strcmp(update_info->version_installed, update_info->version_recommended) != 0)
\r
239 update_info->needs_update = TRUE;
\r
242 g_warning("Could not open %s", local_file);
\r
245 return update_info;
\r
248 /* check the version of winpcap */
\r
249 static update_info_t *
\r
250 update_check_winpcap(const char *local_file)
\r
253 update_info_t * update_info = update_info_new();
\r
254 GString *pcap_version_tmp;
\r
255 char *pcap_version = NULL;
\r
260 update_info->prefix = "winpcap.";
\r
262 pf = eth_fopen(local_file, "r");
\r
264 /* read in update_info of WinPcap */
\r
265 read_prefs_file(local_file, pf, update_pref, update_info);
\r
268 /* get WinPcap version */
\r
269 /* XXX - what's the "approved" method to get the WinPcap version? */
\r
270 pcap_version_tmp = g_string_new("");
\r
271 get_runtime_pcap_version(pcap_version_tmp);
\r
273 /* cut out real version from "combined" version string */
\r
274 pcap_vstart = strstr(pcap_version_tmp->str, "with WinPcap version ");
\r
275 if(pcap_vstart != NULL) {
\r
276 pcap_vstart += sizeof("with WinPcap version");
\r
277 pcap_vend = strstr(pcap_vstart, " ");
\r
278 if(pcap_vend != NULL) {
\r
280 pcap_version = g_strdup(pcap_vstart);
\r
284 update_info->version_installed = g_strdup(pcap_version);
\r
286 if(pcap_version && update_info->version_recommended &&
\r
287 strcmp(pcap_version, update_info->version_recommended) != 0)
\r
289 update_info->needs_update = TRUE;
\r
292 g_warning("Could not open %s", local_file);
\r
295 g_string_free(pcap_version_tmp, TRUE);
\r
297 g_free(pcap_version);
\r
299 return update_info;
\r
303 /* check for all updates */
\r
305 update_check(gboolean interactive)
\r
308 const char *url_file = "http://127.0.0.1/wsupdate"; /* XXX - build the URL depending on platform, versions, ... */
\r
309 update_info_t *update_info_wireshark;
\r
310 update_info_t *update_info_winpcap;
\r
313 /* build update file name */
\r
314 /* XXX - using the personal path, use temp dir instead? */
\r
315 local_file = get_persconffile_path("wsupdate", TRUE /*for_writing*/);
\r
316 if(local_file == NULL) {
\r
317 g_warning("Couldn't create output path!");
\r
321 /* download update file */
\r
322 if(download_file(url_file, local_file) == -1) {
\r
323 g_warning("Couldn't download update file: %s", local_file);
\r
324 g_free(local_file);
\r
328 /* check wireshark */
\r
329 update_info_wireshark = update_check_wireshark(local_file);
\r
331 /* check winpcap */
\r
332 update_info_winpcap = update_check_winpcap(local_file);
\r
334 /* display results */
\r
335 if(update_info_wireshark->needs_update || update_info_winpcap->needs_update) {
\r
336 if(update_info_wireshark->needs_update)
\r
337 update_info_display(update_info_wireshark);
\r
338 if(update_info_winpcap->needs_update)
\r
339 update_info_display(update_info_winpcap);
\r
342 simple_dialog(ESD_TYPE_INFO, ESD_BTN_OK, "No updates available");
\r
347 update_info_delete(update_info_wireshark);
\r
348 update_info_delete(update_info_winpcap);
\r
350 g_free(local_file);
\r