packet-smb2: fix lease epoch fields
[metze/wireshark/wip.git] / ui / help_url.c
1 /* help_url.c
2  *
3  * $Id$
4  *
5  * Some content from gtk/help_dlg.c by Laurent Deniel <laurent.deniel@free.fr>
6  *
7  * Wireshark - Network traffic analyzer
8  * By Gerald Combs <gerald@wireshark.org>
9  * Copyright 2000 Gerald Combs
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24  */
25
26 #include "config.h"
27
28 #include <string.h>
29
30 #include <glib.h>
31
32 #include "help_url.h"
33 #include "wsutil/filesystem.h"
34
35 #ifdef HHC_DIR
36 #include <windows.h>
37 #include <htmlhelp.h>
38 #include <wsutil/unicode-utils.h>
39 #endif
40
41 /*
42  * Given a filename return a filesystem URL. Relative paths are prefixed with
43  * the datafile directory path.
44  */
45 gchar *
46 data_file_url(const gchar *filename)
47 {
48     gchar *file_path;
49     gchar *uri;
50
51     /* Absolute path? */
52 #ifdef G_OS_WIN32
53     if((strlen(filename) > 2) && (filename[1] == ':')) {
54       file_path = g_strdup(filename);
55 #else
56     if((strlen(filename) > 1) && (filename[0] == '/')) {
57       file_path = g_strdup(filename);
58 #endif
59     } else {
60         file_path = g_strdup_printf("%s/%s", get_datafile_dir(), filename);
61     }
62
63     /* XXX - check, if the file is really existing, otherwise display a simple_dialog about the problem */
64
65     /* convert filename to uri */
66     uri = g_filename_to_uri(file_path, NULL, NULL);
67     g_free(file_path);
68     return uri;
69 }
70
71 const char *
72 topic_online_url(topic_action_e action)
73 {
74     switch(action) {
75     case(ONLINEPAGE_HOME):
76         return "http://www.wireshark.org";
77         break;
78     case(ONLINEPAGE_WIKI):
79         return "http://wiki.wireshark.org";
80         break;
81     case(ONLINEPAGE_DOWNLOAD):
82         return "http://www.wireshark.org/download.html";
83         break;
84     case(ONLINEPAGE_USERGUIDE):
85         return "http://www.wireshark.org/docs/wsug_html_chunked/";
86         break;
87     case(ONLINEPAGE_FAQ):
88         return "http://www.wireshark.org/faq.html";
89         break;
90     case(ONLINEPAGE_ASK):
91         return "http://ask.wireshark.org";
92         break;
93     case(ONLINEPAGE_SAMPLE_FILES):
94         return "http://wiki.wireshark.org/SampleCaptures";
95         break;
96     case(ONLINEPAGE_CAPTURE_SETUP):
97         return "http://wiki.wireshark.org/CaptureSetup";
98         break;
99     case(ONLINEPAGE_NETWORK_MEDIA):
100         return "http://wiki.wireshark.org/CaptureSetup/NetworkMedia";
101         break;
102     case(ONLINEPAGE_SAMPLE_CAPTURES):
103         return "http://wiki.wireshark.org/SampleCaptures";
104         break;
105     case(ONLINEPAGE_SECURITY):
106         return "http://wiki.wireshark.org/Security";
107         break;
108     case(ONLINEPAGE_CHIMNEY):
109         return "http://wiki.wireshark.org/CaptureSetup/Offloading#chimney";
110         break;
111     default:
112         return NULL;
113     }
114 }
115
116 /*
117  * Open the help dialog and show a specific HTML help page.
118  */
119 gchar *
120 user_guide_url(const gchar *page) {
121     GString *url = g_string_new("");
122     gchar *ug_url = NULL;
123
124     /*
125      * Try to open local .chm file. This is not the most intuitive way to
126      * go about this but it fits in with the rest of the _url functions.
127      */
128 #ifdef HHC_DIR
129     HWND hw;
130
131     g_string_printf(url, "%s\\user-guide.chm::/wsug_chm/%s>Wireshark Help",
132         get_datafile_dir(), page);
133
134     hw = HtmlHelpW(NULL,
135         utf_8to16(url->str),
136         HH_DISPLAY_TOPIC, 0);
137
138     /* if the .chm file could be opened, stop here */
139     if(hw != NULL) {
140         g_string_free(url, TRUE /* free_segment */);
141         return NULL;
142     }
143 #endif /* HHC_DIR */
144
145 #ifdef DOC_DIR
146     if (g_file_test(DOC_DIR "/guides/wsug_html_chunked", G_FILE_TEST_IS_DIR)) {
147         /* try to open the HTML page from wireshark.org instead */
148         g_string_printf(url, "file://" DOC_DIR "/guides/wsug_html_chunked/%s", page);
149     } else {
150 #endif /* ifdef DOC_DIR */
151        /* try to open the HTML page from wireshark.org instead */
152         g_string_printf(url, "http://www.wireshark.org/docs/wsug_html_chunked/%s", page);
153 #ifdef DOC_DIR
154     }
155 #endif /* ifdef DOC_DIR */
156
157
158     ug_url = url->str;
159     g_string_free(url, FALSE);
160     return ug_url;
161 }
162
163 gchar *
164 topic_action_url(topic_action_e action)
165 {
166     gchar *url;
167
168     /* pages online at www.wireshark.org */
169     url = g_strdup(topic_online_url(action));
170     if(url != NULL) {
171         return url;
172     }
173
174     switch(action) {
175     /* local manual pages */
176     case(LOCALPAGE_MAN_WIRESHARK):
177         url = data_file_url("wireshark.html");
178         break;
179     case(LOCALPAGE_MAN_WIRESHARK_FILTER):
180         url = data_file_url("wireshark-filter.html");
181         break;
182     case(LOCALPAGE_MAN_CAPINFOS):
183         url = data_file_url("capinfos.html");
184         break;
185     case(LOCALPAGE_MAN_DUMPCAP):
186         url = data_file_url("dumpcap.html");
187         break;
188     case(LOCALPAGE_MAN_EDITCAP):
189         url = data_file_url("editcap.html");
190         break;
191     case(LOCALPAGE_MAN_MERGECAP):
192         url = data_file_url("mergecap.html");
193         break;
194     case(LOCALPAGE_MAN_RAWSHARK):
195         url = data_file_url("rawshark.html");
196         break;
197     case(LOCALPAGE_MAN_REORDERCAP):
198         url = data_file_url("reordercap.html");
199         break;
200     case(LOCALPAGE_MAN_TEXT2PCAP):
201         url = data_file_url("text2pcap.html");
202         break;
203     case(LOCALPAGE_MAN_TSHARK):
204         url = data_file_url("tshark.html");
205         break;
206
207     /* local help pages (User's Guide) */
208     case(HELP_CONTENT):
209         url = user_guide_url( "index.html");
210         break;
211     case(HELP_CAPTURE_OPTIONS_DIALOG):
212         url = user_guide_url("ChCapCaptureOptions.html");
213         break;
214     case(HELP_CAPTURE_FILTERS_DIALOG):
215         url = user_guide_url("ChWorkDefineFilterSection.html");
216         break;
217     case(HELP_DISPLAY_FILTERS_DIALOG):
218         url = user_guide_url("ChWorkDefineFilterSection.html");
219         break;
220     case(HELP_COLORING_RULES_DIALOG):
221         url = user_guide_url("ChCustColorizationSection.html");
222         break;
223     case(HELP_CONFIG_PROFILES_DIALOG):
224         url = user_guide_url("ChCustConfigProfilesSection.html");
225         break;
226     case (HELP_MANUAL_ADDR_RESOLVE_DIALOG):
227         url = user_guide_url("ChManualAddressResolveSection.html");
228         break;
229     case(HELP_PRINT_DIALOG):
230         url = user_guide_url("ChIOPrintSection.html");
231         break;
232     case(HELP_FIND_DIALOG):
233         url = user_guide_url("ChWorkFindPacketSection.html");
234         break;
235     case(HELP_FIREWALL_DIALOG):
236         url = user_guide_url("ChUseToolsMenuSection.html");
237         break;
238     case(HELP_GOTO_DIALOG):
239         url = user_guide_url("ChWorkGoToPacketSection.html");
240         break;
241     case(HELP_CAPTURE_INTERFACES_DIALOG):
242         url = user_guide_url("ChCapInterfaceSection.html");
243         break;
244     case(HELP_CAPTURE_INFO_DIALOG):
245         url = user_guide_url("ChCapRunningSection.html");
246         break;
247     case(HELP_ENABLED_PROTOCOLS_DIALOG):
248         url = user_guide_url("ChCustProtocolDissectionSection.html");
249         break;
250     case(HELP_DECODE_AS_DIALOG):
251         url = user_guide_url("ChCustProtocolDissectionSection.html");
252         break;
253     case(HELP_DECODE_AS_SHOW_DIALOG):
254         url = user_guide_url("ChCustProtocolDissectionSection.html");
255         break;
256     case(HELP_FOLLOW_STREAM_DIALOG):
257         url = user_guide_url("ChAdvFollowTCPSection.html");
258         break;
259     case(HELP_EXPERT_INFO_DIALOG):
260         url = user_guide_url("ChAdvExpert.html");
261         break;
262     case(HELP_STATS_SUMMARY_DIALOG):
263         url = user_guide_url("ChStatSummary.html");
264         break;
265     case(HELP_STATS_PROTO_HIERARCHY_DIALOG):
266         url = user_guide_url("ChStatHierarchy.html");
267         break;
268     case(HELP_STATS_ENDPOINTS_DIALOG):
269         url = user_guide_url("ChStatEndpoints.html");
270         break;
271     case(HELP_STATS_CONVERSATIONS_DIALOG):
272         url = user_guide_url("ChStatConversations.html");
273         break;
274     case(HELP_STATS_IO_GRAPH_DIALOG):
275         url = user_guide_url("ChStatIOGraphs.html");
276         break;
277     case(HELP_STATS_COMPARE_FILES_DIALOG):
278         url = user_guide_url("ChStatCompareCaptureFiles.html");
279         break;
280     case(HELP_STATS_LTE_MAC_TRAFFIC_DIALOG):
281         url = user_guide_url("ChTelLTEMACTraffic.html");
282         break;
283     case(HELP_STATS_LTE_RLC_TRAFFIC_DIALOG):
284         url = user_guide_url("ChTelLTERLCTraffic.html");
285         break;
286     case(HELP_STATS_WLAN_TRAFFIC_DIALOG):
287         url = user_guide_url("ChStatWLANTraffic.html");
288         break;
289     case(HELP_FILESET_DIALOG):
290         url = user_guide_url("ChIOFileSetSection.html");
291         break;
292     case(HELP_CAPTURE_INTERFACE_OPTIONS_DIALOG):
293         url = user_guide_url("ChCustPreferencesSection.html#ChCustInterfaceOptionsSection");
294         break;
295     case(HELP_CAPTURE_INTERFACES_DETAILS_DIALOG):
296         url = user_guide_url("ChCapInterfaceDetailsSection.html");
297         break;
298     case(HELP_PREFERENCES_DIALOG):
299         url = user_guide_url("ChCustPreferencesSection.html");
300         break;
301     case(HELP_EXPORT_FILE_DIALOG):
302     case(HELP_EXPORT_FILE_WIN32_DIALOG):
303         url = user_guide_url("ChIOExportSection.html");
304         break;
305     case(HELP_EXPORT_BYTES_DIALOG):
306     case(HELP_EXPORT_BYTES_WIN32_DIALOG):
307         url = user_guide_url("ChIOExportSection.html#ChIOExportSelectedDialog");
308         break;
309     case(HELP_EXPORT_OBJECT_LIST):
310         url = user_guide_url("ChIOExportSection.html#ChIOExportObjectsDialog");
311         break;
312     case(HELP_OPEN_DIALOG):
313     case(HELP_OPEN_WIN32_DIALOG):
314         url = user_guide_url("ChIOOpenSection.html");
315         break;
316     case(HELP_MERGE_DIALOG):
317     case(HELP_MERGE_WIN32_DIALOG):
318         url = user_guide_url("ChIOMergeSection.html");
319         break;
320     case(HELP_IMPORT_DIALOG):
321         url = user_guide_url("ChIOImportSection.html");
322         break;
323     case(HELP_SAVE_DIALOG):
324     case(HELP_SAVE_WIN32_DIALOG):
325         url = user_guide_url("ChIOSaveSection.html");
326         break;
327     case(HELP_TIME_SHIFT_DIALOG):
328         url = user_guide_url("ChWorkShiftTimePacketSection.html");
329         break;
330     case(HELP_FILTER_SAVE_DIALOG):
331         url = user_guide_url("ChWorkFilterSaveSection.html");
332         break;
333
334     case(TOPIC_ACTION_NONE):
335     default:
336         g_assert_not_reached();
337     }
338
339     return url;
340 }
341
342 /*
343  * Editor modelines
344  *
345  * Local Variables:
346  * c-basic-offset: 4
347  * tab-width: 8
348  * indent-tabs-mode: nil
349  * End:
350  *
351  * ex: set shiftwidth=4 tabstop=8 expandtab:
352  * :indentSize=4:tabSize=8:noTabs=true:
353  */