Allow "capture info data" to not be a singleton.
[metze/wireshark/wip.git] / ui / help_url.c
1 /* help_url.c
2  *
3  * Some content from gtk/help_dlg.c by Laurent Deniel <laurent.deniel@free.fr>
4  *
5  * Wireshark - Network traffic analyzer
6  * By Gerald Combs <gerald@wireshark.org>
7  * Copyright 2000 Gerald Combs
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22  */
23
24 #include "config.h"
25
26 #include <string.h>
27
28 #include <glib.h>
29
30 #include "help_url.h"
31 #include "wsutil/filesystem.h"
32
33 #ifdef HHC_DIR
34 #include <windows.h>
35 #include <htmlhelp.h>
36 #include <wsutil/unicode-utils.h>
37 #endif
38
39 /*
40  * Given a filename return a filesystem URL. Relative paths are prefixed with
41  * the datafile directory path.
42  */
43 gchar *
44 data_file_url(const gchar *filename)
45 {
46     gchar *file_path;
47     gchar *uri;
48
49     /* Absolute path? */
50 #ifdef G_OS_WIN32
51     if((strlen(filename) > 2) && (filename[1] == ':')) {
52       file_path = g_strdup(filename);
53 #else
54     if((strlen(filename) > 1) && (filename[0] == '/')) {
55       file_path = g_strdup(filename);
56 #endif
57     } else if(running_in_build_directory()) {
58         file_path = g_strdup_printf("%s/doc/%s", get_datafile_dir(), filename);
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 "https://www.wireshark.org";
77         break;
78     case(ONLINEPAGE_WIKI):
79         return "https://wiki.wireshark.org";
80         break;
81     case(ONLINEPAGE_DOWNLOAD):
82         return "https://www.wireshark.org/download.html";
83         break;
84     case(ONLINEPAGE_USERGUIDE):
85         return "https://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 "https://ask.wireshark.org";
92         break;
93     case(ONLINEPAGE_SAMPLE_FILES):
94         return "https://wiki.wireshark.org/SampleCaptures";
95         break;
96     case(ONLINEPAGE_CAPTURE_SETUP):
97         return "https://wiki.wireshark.org/CaptureSetup";
98         break;
99     case(ONLINEPAGE_NETWORK_MEDIA):
100         return "https://wiki.wireshark.org/CaptureSetup/NetworkMedia";
101         break;
102     case(ONLINEPAGE_SAMPLE_CAPTURES):
103         return "https://wiki.wireshark.org/SampleCaptures";
104         break;
105     case(ONLINEPAGE_SECURITY):
106         return "https://wiki.wireshark.org/Security";
107         break;
108     case(ONLINEPAGE_CHIMNEY):
109         return "https://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
123     /*
124      * Try to open local .chm file. This is not the most intuitive way to
125      * go about this but it fits in with the rest of the _url functions.
126      */
127 #ifdef HHC_DIR
128     HWND hw;
129
130     g_string_printf(url, "%s\\user-guide.chm::/wsug_chm/%s>Wireshark Help",
131         get_datafile_dir(), page);
132
133     hw = HtmlHelpW(NULL,
134         utf_8to16(url->str),
135         HH_DISPLAY_TOPIC, 0);
136
137     /* if the .chm file could be opened, stop here */
138     if(hw != NULL) {
139         g_string_free(url, TRUE /* free_segment */);
140         return NULL;
141     }
142 #endif /* HHC_DIR */
143
144 #ifdef DOC_DIR
145     if (g_file_test(DOC_DIR "/guides/wsug_html_chunked", G_FILE_TEST_IS_DIR)) {
146         /* try to open the HTML page from wireshark.org instead */
147         g_string_printf(url, "file://" DOC_DIR "/guides/wsug_html_chunked/%s", page);
148     } else {
149 #endif /* ifdef DOC_DIR */
150        /* try to open the HTML page from wireshark.org instead */
151         g_string_printf(url, "https://www.wireshark.org/docs/wsug_html_chunked/%s", page);
152 #ifdef DOC_DIR
153     }
154 #endif /* ifdef DOC_DIR */
155
156
157     return g_string_free(url, FALSE);
158 }
159
160 gchar *
161 topic_action_url(topic_action_e action)
162 {
163     gchar *url;
164
165     /* pages online at www.wireshark.org */
166     url = g_strdup(topic_online_url(action));
167     if(url != NULL) {
168         return url;
169     }
170
171     switch(action) {
172     /* local manual pages */
173     case(LOCALPAGE_MAN_WIRESHARK):
174         url = data_file_url("wireshark.html");
175         break;
176     case(LOCALPAGE_MAN_WIRESHARK_FILTER):
177         url = data_file_url("wireshark-filter.html");
178         break;
179     case(LOCALPAGE_MAN_CAPINFOS):
180         url = data_file_url("capinfos.html");
181         break;
182     case(LOCALPAGE_MAN_DUMPCAP):
183         url = data_file_url("dumpcap.html");
184         break;
185     case(LOCALPAGE_MAN_EDITCAP):
186         url = data_file_url("editcap.html");
187         break;
188     case(LOCALPAGE_MAN_MERGECAP):
189         url = data_file_url("mergecap.html");
190         break;
191     case(LOCALPAGE_MAN_RAWSHARK):
192         url = data_file_url("rawshark.html");
193         break;
194     case(LOCALPAGE_MAN_REORDERCAP):
195         url = data_file_url("reordercap.html");
196         break;
197     case(LOCALPAGE_MAN_TEXT2PCAP):
198         url = data_file_url("text2pcap.html");
199         break;
200     case(LOCALPAGE_MAN_TSHARK):
201         url = data_file_url("tshark.html");
202         break;
203
204     /* local help pages (User's Guide) */
205     case(HELP_CONTENT):
206         url = user_guide_url( "index.html");
207         break;
208     case(HELP_CAPTURE_OPTIONS_DIALOG):
209         url = user_guide_url("ChCapCaptureOptions.html");
210         break;
211     case(HELP_CAPTURE_FILTERS_DIALOG):
212         url = user_guide_url("ChWorkDefineFilterSection.html");
213         break;
214     case(HELP_DISPLAY_FILTERS_DIALOG):
215         url = user_guide_url("ChWorkDefineFilterSection.html");
216         break;
217     case(HELP_FILTER_EXPRESSION_DIALOG):
218         url = user_guide_url("ChWorkFilterAddExpressionSection.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_CAPTURE_MANAGE_INTERFACES_DIALOG):
248         url = user_guide_url("ChCapManageInterfacesSection.html");
249         break;
250     case(HELP_ENABLED_PROTOCOLS_DIALOG):
251         url = user_guide_url("ChCustProtocolDissectionSection.html");
252         break;
253     case(HELP_ENABLED_HEURISTICS_DIALOG):
254         url = user_guide_url("ChCustProtocolDissectionSection.html");
255         break;
256     case(HELP_DECODE_AS_DIALOG):
257         url = user_guide_url("ChCustProtocolDissectionSection.html");
258         break;
259     case(HELP_DECODE_AS_SHOW_DIALOG):
260         url = user_guide_url("ChCustProtocolDissectionSection.html");
261         break;
262     case(HELP_FOLLOW_STREAM_DIALOG):
263         url = user_guide_url("ChAdvFollowTCPSection.html");
264         break;
265     case(HELP_EXPERT_INFO_DIALOG):
266         url = user_guide_url("ChAdvExpert.html");
267         break;
268     case(HELP_EXTCAP_OPTIONS_DIALOG):
269         url = user_guide_url("ChExtcapOptions.html");
270         break;
271     case(HELP_STATS_SUMMARY_DIALOG):
272         url = user_guide_url("ChStatSummary.html");
273         break;
274     case(HELP_STATS_PROTO_HIERARCHY_DIALOG):
275         url = user_guide_url("ChStatHierarchy.html");
276         break;
277     case(HELP_STATS_ENDPOINTS_DIALOG):
278         url = user_guide_url("ChStatEndpoints.html");
279         break;
280     case(HELP_STATS_CONVERSATIONS_DIALOG):
281         url = user_guide_url("ChStatConversations.html");
282         break;
283     case(HELP_STATS_IO_GRAPH_DIALOG):
284         url = user_guide_url("ChStatIOGraphs.html");
285         break;
286     case(HELP_STATS_COMPARE_FILES_DIALOG):
287         url = user_guide_url("ChStatCompareCaptureFiles.html");
288         break;
289     case(HELP_STATS_LTE_MAC_TRAFFIC_DIALOG):
290         url = user_guide_url("ChTelLTEMACTraffic.html");
291         break;
292     case(HELP_STATS_LTE_RLC_TRAFFIC_DIALOG):
293         url = user_guide_url("ChTelLTERLCTraffic.html");
294         break;
295     case(HELP_STATS_WLAN_TRAFFIC_DIALOG):
296         url = user_guide_url("ChStatWLANTraffic.html");
297         break;
298     case(HELP_FILESET_DIALOG):
299         url = user_guide_url("ChIOFileSetSection.html");
300         break;
301     case(HELP_CAPTURE_INTERFACE_OPTIONS_DIALOG):
302         url = user_guide_url("ChCustPreferencesSection.html#ChCustInterfaceOptionsSection");
303         break;
304     case(HELP_CAPTURE_INTERFACES_DETAILS_DIALOG):
305         url = user_guide_url("ChCapInterfaceDetailsSection.html");
306         break;
307     case(HELP_PREFERENCES_DIALOG):
308         url = user_guide_url("ChCustPreferencesSection.html");
309         break;
310     case(HELP_EXPORT_FILE_DIALOG):
311     case(HELP_EXPORT_FILE_WIN32_DIALOG):
312         url = user_guide_url("ChIOExportSection.html");
313         break;
314     case(HELP_EXPORT_BYTES_DIALOG):
315     case(HELP_EXPORT_BYTES_WIN32_DIALOG):
316         url = user_guide_url("ChIOExportSection.html#ChIOExportSelectedDialog");
317         break;
318     case(HELP_EXPORT_OBJECT_LIST):
319         url = user_guide_url("ChIOExportSection.html#ChIOExportObjectsDialog");
320         break;
321     case(HELP_OPEN_DIALOG):
322     case(HELP_OPEN_WIN32_DIALOG):
323         url = user_guide_url("ChIOOpenSection.html");
324         break;
325     case(HELP_MERGE_DIALOG):
326     case(HELP_MERGE_WIN32_DIALOG):
327         url = user_guide_url("ChIOMergeSection.html");
328         break;
329     case(HELP_IMPORT_DIALOG):
330         url = user_guide_url("ChIOImportSection.html");
331         break;
332     case(HELP_SAVE_DIALOG):
333     case(HELP_SAVE_WIN32_DIALOG):
334         url = user_guide_url("ChIOSaveSection.html");
335         break;
336     case(HELP_TIME_SHIFT_DIALOG):
337         url = user_guide_url("ChWorkShiftTimePacketSection.html");
338         break;
339     case(HELP_FILTER_SAVE_DIALOG):
340         url = user_guide_url("ChWorkFilterSaveSection.html");
341         break;
342     case(HELP_TELEPHONY_VOIP_CALLS_DIALOG):
343         url = user_guide_url("ChTelVoipCalls.html");
344         break;
345     case(HELP_RTP_ANALYSIS_DIALOG):
346         url = user_guide_url("ChTelRTPAnalysis.html");
347         break;
348     case(HELP_NEW_PACKET_DIALOG):
349         url = user_guide_url("ChapterWork.html#ChWorkPacketSepView");
350         break;
351     case(HELP_IAX2_ANALYSIS_DIALOG):
352         url = user_guide_url("ChTelIAX2Analysis.html");
353         break;
354     case(HELP_TELEPHONY_RTP_PLAYER_DIALOG):
355         url = user_guide_url("ChTelRtpPlayer.html");
356         break;
357
358     case(TOPIC_ACTION_NONE):
359     default:
360         g_assert_not_reached();
361     }
362
363     return url;
364 }
365
366 /*
367  * Editor modelines
368  *
369  * Local Variables:
370  * c-basic-offset: 4
371  * tab-width: 8
372  * indent-tabs-mode: nil
373  * End:
374  *
375  * ex: set shiftwidth=4 tabstop=8 expandtab:
376  * :indentSize=4:tabSize=8:noTabs=true:
377  */