5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
33 #include <epan/prefs.h>
34 #include <epan/prefs-int.h>
35 #include <epan/filesystem.h>
37 #include "simple_dialog.h"
38 #include "version_info.h"
41 #include "capture-pcap-util.h"
44 #include <wsutil/file_util.h>
50 /* update information about a single component */
51 typedef struct update_info_s {
52 char *prefix; /* prefix of the update file keys */
53 gboolean needs_update; /* does this component need an update */
54 char *version_installed; /* the version currently installed */
56 char *title; /* the component title (name) */
57 char *description; /* description of the component */
58 char *version_recommended; /* the version recommended */
59 char *url; /* the URL for an update */
60 char *md5; /* md5 checksum for that update */
61 char *size; /* size of that update */
65 /* download a complete file from the internet */
67 download_file(const char *url, const char *filename) {
76 /* open output file */
77 fd = ws_open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644);
79 g_warning("Couldn't open output file %s!", filename);
84 conn = netio_ie5_connect (url);
86 g_warning("Couldn't connect to %s!", url);
91 /* XXX - maybe add a progress bar here */
93 /* read some bytes from the url */
94 chunk_len = netio_ie5_read (conn, buf, sizeof(buf));
96 /* write bytes to the output file */
97 stream_len = ws_write( fd, buf, chunk_len);
98 if(stream_len != chunk_len) {
99 g_warning("output failed: stream_len %u != chunk_len %u", stream_len, chunk_len);
103 } while(chunk_len > 0);
105 netio_ie5_disconnect(conn);
113 update_info_new(void)
115 return g_malloc0(sizeof(update_info_t));
119 update_info_delete(update_info_t *update_info)
121 g_free(update_info->prefix);
122 g_free(update_info->version_installed);
123 g_free(update_info->title);
124 g_free(update_info->description);
125 g_free(update_info->version_recommended);
126 g_free(update_info->url);
127 g_free(update_info->md5);
128 g_free(update_info->size);
133 /* check a single key value pair */
135 update_pref_check(gchar *pref_name, gchar *value, char *check_prefix, char *check_name, char **check_value)
137 GString *check = g_string_new(check_prefix);
139 g_string_append(check, check_name);
141 if(strcmp(pref_name, check->str) == 0) {
143 /* there shouldn't be a duplicate entry in the update file */
144 g_warning("Duplicate of %s: current %s former %s", pref_name, value, *check_value);
146 *check_value = g_strdup(value);
149 g_string_free(check, TRUE);
152 /* a new key value pair from the update file */
153 static prefs_set_pref_e
154 update_pref(gchar *pref_name, gchar *value, void *private_data)
156 update_info_t *update_info = private_data;
158 update_pref_check(pref_name, value, update_info->prefix, "title", &update_info->title);
159 update_pref_check(pref_name, value, update_info->prefix, "description", &update_info->description);
160 update_pref_check(pref_name, value, update_info->prefix, "version", &update_info->version_recommended);
161 update_pref_check(pref_name, value, update_info->prefix, "update.url", &update_info->url);
162 update_pref_check(pref_name, value, update_info->prefix, "update.md5", &update_info->md5);
163 update_pref_check(pref_name, value, update_info->prefix, "update.size", &update_info->size);
168 /* display an update_info */
170 update_info_display(update_info_t *update_info)
175 overview = g_string_new("");
177 if(update_info->title) {
178 g_string_append_printf(overview, "%s%s%s",
179 simple_dialog_primary_start(), update_info->title, simple_dialog_primary_end());
181 g_string_append_printf(overview, "%sComponent%s",
182 simple_dialog_primary_start(), simple_dialog_primary_end());
185 g_string_append(overview, "\n\n");
187 if(update_info->description)
188 g_string_append_printf(overview, "%s\n\n", update_info->description);
190 g_string_append_printf(overview, "Installed: %s\n", update_info->version_installed);
192 if(update_info->version_recommended)
193 g_string_append_printf(overview, "Recommended: %s\n", update_info->version_recommended);
195 g_string_append(overview, "Recommenced: unknown\n");
197 if(update_info->version_recommended && update_info->url)
198 g_string_append_printf(overview, "From: %s\n", update_info->url);
200 if(update_info->size)
201 g_string_append_printf(overview, "Size: %s", update_info->size);
203 simple_dialog(ESD_TYPE_INFO, ESD_BTN_OK, overview->str);
205 g_string_free(overview, TRUE);
209 /* check the version of the wireshark program */
210 static update_info_t *
211 update_check_wireshark(const char *local_file)
214 update_info_t *update_info = update_info_new();
217 update_info->version_installed = g_strdup(VERSION);
218 update_info->prefix = "wireshark.setup.";
220 pf = ws_fopen(local_file, "r");
222 /* read in update_info of Wireshark */
223 read_prefs_file(local_file, pf, update_pref, update_info);
226 /* check if Wireshark needs an update */
227 if(update_info->version_installed && update_info->version_recommended &&
228 strcmp(update_info->version_installed, update_info->version_recommended) != 0)
230 update_info->needs_update = TRUE;
233 g_warning("Could not open %s", local_file);
239 /* check the version of winpcap */
240 static update_info_t *
241 update_check_winpcap(const char *local_file)
244 update_info_t * update_info = update_info_new();
245 GString *pcap_version_tmp;
246 char *pcap_version = NULL;
251 update_info->prefix = "winpcap.";
253 pf = ws_fopen(local_file, "r");
255 /* read in update_info of WinPcap */
256 read_prefs_file(local_file, pf, update_pref, update_info);
259 /* get WinPcap version */
260 /* XXX - what's the "approved" method to get the WinPcap version? */
261 pcap_version_tmp = g_string_new("");
262 get_runtime_pcap_version(pcap_version_tmp);
264 /* cut out real version from "combined" version string */
265 pcap_vstart = strstr(pcap_version_tmp->str, "with WinPcap version ");
266 if(pcap_vstart != NULL) {
267 pcap_vstart += sizeof("with WinPcap version");
268 pcap_vend = strstr(pcap_vstart, " ");
269 if(pcap_vend != NULL) {
271 pcap_version = g_strdup(pcap_vstart);
275 update_info->version_installed = g_strdup(pcap_version);
277 if(pcap_version && update_info->version_recommended &&
278 strcmp(pcap_version, update_info->version_recommended) != 0)
280 update_info->needs_update = TRUE;
283 g_warning("Could not open %s", local_file);
286 g_string_free(pcap_version_tmp, TRUE);
287 g_free(pcap_version);
293 /* check for all updates */
295 update_check(gboolean interactive)
298 const char *url_file = "http://127.0.0.1/wsupdate"; /* XXX - build the URL depending on platform, versions, ... */
299 update_info_t *update_info_wireshark;
300 update_info_t *update_info_winpcap;
303 /* build update file name */
304 /* XXX - using the personal path, use temp dir instead? */
305 local_file = get_persconffile_path("wsupdate", FALSE, TRUE /*for_writing*/);
306 if(local_file == NULL) {
307 g_warning("Couldn't create output path!");
311 /* download update file */
312 if(download_file(url_file, local_file) == -1) {
313 g_warning("Couldn't download update file: %s", local_file);
318 /* check wireshark */
319 update_info_wireshark = update_check_wireshark(local_file);
322 update_info_winpcap = update_check_winpcap(local_file);
324 /* display results */
325 if(update_info_wireshark->needs_update || update_info_winpcap->needs_update) {
326 if(update_info_wireshark->needs_update)
327 update_info_display(update_info_wireshark);
328 if(update_info_winpcap->needs_update)
329 update_info_display(update_info_winpcap);
332 simple_dialog(ESD_TYPE_INFO, ESD_BTN_OK, "No updates available");
337 update_info_delete(update_info_wireshark);
338 update_info_delete(update_info_winpcap);