aboutsummaryrefslogtreecommitdiffstats
path: root/ui/gtk/proto_help.c
blob: 6de7daa2967017fcbcc4b35087ccfa56fceaade4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
/* proto_help.c
 * Routines for dynamic protocol help menus
 *
 * Edgar Gladkich <edgar.gladkich@incacon.de>
 * Gerald Combs <gerald@wireshark.org>
 *
 * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
#include "config.h"

/* This file basically does nothing except remind us how this worked before
 * the menu code was rewritten to no longer use the deprecated ItemFactory
 * stuff.
 */
#define MAIN_MENU_USE_UIMANAGER 1

#include <string.h>

#include <gtk/gtk.h>
#include "ui/gtk/webbrowser.h"

#include "../file.h"

#include <epan/prefs.h>
#include <wsutil/filesystem.h>
#include <epan/strutil.h>
#include <epan/proto.h>

#include "ui/gtk/proto_help.h"

/*
 * The protocol help files cannot be downloaded downloaded directly. You
 * will need to go to http://www.inacon.com/download/, then download one
 * of the packages, e.g. the source package and extract the protocol_help
 * folder. To actually use the help you will also need to be able to
 * access the URL beginning at the contents of the loclation line in the
 * ph.ini file (e.g. location=http://www.inacon.de/ph/data/).
 * To provide offline service download the contents of the given location
 * to your computer, then change the location parameter in the ph.ini file
 * to point to that new URL. This may be a file:/// URL.
 */

/* Right now proto_help will not build with -DGTK_DISABLE_DEPRECATED due to
   its use of GtkItemFactory.
   See http://developer.gnome.org/gtk/2.24/GtkItemFactory.html: "As of GTK+ 2.4,
   GtkItemFactory has been deprecated in favour of GtkUIManager."
   This needs to be rewritten by the people who added this code or some other
   volunteers. Otherwise this functionality will be lost once the non UI_MANAGER
   stuff gets removed it isn't built by default any more.
 */
#ifdef MAIN_MENU_USE_UIMANAGER
void proto_help_menu_modify(GtkTreeSelection *selection _U_, capture_file *cf _U_) {}
void proto_help_menu_init(GtkWidget *widget _U_) {}
void proto_help_init(void) {}
#else

#define PH_MENU_TOP "/Protocol Help"

#define PH_FILE_LOG "ph.log"
#define PH_INI_SUFFIX ".ini"
#define PH_PATH_SEARCH_STR "${PATH}"

/* .ini Section names */
#define PH_INI_GROUP_DATABASE "database"
#define PH_INI_GROUP_LOCATION_DATA "location data"
#define PH_INI_GROUP_MAP "map"

/* .ini [database] section keys */
#define PH_INI_DB_KEY_SOURCE "source"
#define PH_INI_DB_KEY_LOCATION_TEMPLATE "location"

/* .ini Path sections */
#define PH_INI_KEY_OVERVIEW "_OVERVIEW"

/* Where to look for .ini files */
#define PH_CONFFILE_SUBDIR "protocol_help"

#ifdef PH_DEBUG_LOG
const gchar *ph_log_path;
#endif

typedef struct proto_help_key_file_t {
	GKeyFile *keyfile;
	const gchar *source;
	const gchar *loc_template;
} proto_help_key_file;

GPtrArray *g_ph_key_files = NULL;

GtkItemFactory *g_ph_menu_factory;

static void ph_menu_reset(void);
static void ph_menu_onclick(GtkWidget*, gpointer, guint);

static int ph_capture_get_protocol_id(GtkTreeSelection*, capture_file*);
static const gchar* ph_capture_get_protocol_name(GtkTreeSelection*, capture_file*);
static const gchar* ph_capture_get_protocol_abbrev(GtkTreeSelection*, capture_file*);
static gchar* ph_capture_get_description(capture_file*);

static proto_help_key_file *ph_ini_load_file(const gchar*);
static gchar* ph_ini_get_value(GKeyFile *, const gchar*, const gchar*, gchar *);
static gchar* ph_ini_get_path(GKeyFile *, const gchar*, const gchar*);
static gchar** ph_ini_get_keywords(GKeyFile *, const gchar*);

static guint ph_parse_string(const gchar*, const gchar*);

/* #define PH_DEBUG_LOG 1 */
#ifdef PH_DEBUG_LOG
static void ph_logging_handler(const gchar*, GLogLevelFlags, const gchar*, gpointer);
#endif

/** @file
 * Protocol help routines. Adds web browser links to protocol menu items
 * via configuration files.
 */

/** Initialization
 *
 * @param void
 * @return void
 */
#define PH_CONF_DIRS 2
void proto_help_init(void)
{
	gchar *search_dir[PH_CONF_DIRS];
	const gchar *ini_name;
	gchar *ini_path;
	GDir *conf_dir;
	int i;

	search_dir[0] = g_strdup_printf("%s" G_DIR_SEPARATOR_S PH_CONFFILE_SUBDIR, get_datafile_dir());
	/* XXX - Use profiles? */
	search_dir[1] = get_persconffile_path(PH_CONFFILE_SUBDIR, FALSE, FALSE);

#ifdef PH_DEBUG_LOG
	g_log_set_handler(NULL, G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION, ph_logging_handler, NULL);
#endif

	if (g_ph_key_files)
		return;

	g_ph_key_files = g_ptr_array_new();

	/* Start loop */

#ifdef PH_DEBUG_LOG
	ph_log_path = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", g_get_tmp_dir(), PH_FILE_LOG);
#endif

	for (i = 0; i < PH_CONF_DIRS; i++) {
		g_log(NULL, G_LOG_LEVEL_INFO, "Looking for protocol help files in '%s'", search_dir[i]);
		conf_dir = g_dir_open(search_dir[i], 0, NULL);
		if (!conf_dir) {
			continue;
		}

		while ((ini_name = g_dir_read_name(conf_dir)) != NULL) {
			if (! g_str_has_suffix(ini_name, PH_INI_SUFFIX)) {
				continue;
			}
			g_log(NULL, G_LOG_LEVEL_INFO, "-- Found '%s'", ini_name);
			ini_path = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", search_dir[i], ini_name);
			ph_ini_load_file(ini_path);
			g_free(ini_path);
		}
		g_dir_close(conf_dir);
	}
}

/** Initialize the menu
 *
 * @param widget Context menu root
 * @return void
 */
void proto_help_menu_init(GtkWidget *widget)
{
	g_ph_menu_factory = gtk_item_factory_from_widget(widget);
	ph_menu_reset();
}

/** Clear the menu
 *
 * @param void
 * @return void
 */
static void ph_menu_reset(void)
{
	GtkWidget *menu_item = NULL;
	GList *menu_entries = NULL;
	GList *menu_entry = NULL;

	if(!g_ph_menu_factory) return;

	menu_item = gtk_item_factory_get_widget(g_ph_menu_factory, PH_MENU_TOP);
	menu_entries = gtk_container_get_children(GTK_CONTAINER(menu_item));

	for(menu_entry = g_list_first(menu_entries); menu_entry != NULL; menu_entry = g_list_next(menu_entry))
	{
		gtk_container_remove(GTK_CONTAINER(menu_item), menu_entry->data);
	}

	menu_item = gtk_item_factory_get_item(g_ph_menu_factory, PH_MENU_TOP);
	gtk_widget_set_sensitive(menu_item, FALSE);
}

/* Callback to free URLs */
static void
url_destroy_cb(GtkWidget *w _U_, gpointer url) {
	g_free(url);
}

/** Fill in the protocol help menu
 *
 * @param selection Currently-selected packet
 * @param cf Capture file
 * @return void
 */
void proto_help_menu_modify(GtkTreeSelection *selection, capture_file *cf)
{
	gchar *description;
	const gchar *proto_abbrev, *proto_name;
	gchar *value;
	gchar **keys;
	GHashTable *table;
	guint i = 0, cur_kf;
	GtkWidget *menu_item = NULL;
	GtkItemFactoryEntry *menu_entry = NULL;
	proto_help_key_file* phkf;
	gchar *loc;
	gboolean add_separator = FALSE;
	gboolean found = FALSE;

	if(!g_ph_menu_factory) return;
	ph_menu_reset();

	proto_abbrev = ph_capture_get_protocol_abbrev(selection, cf);
	if(!proto_abbrev) return;

	proto_name = ph_capture_get_protocol_name(selection, cf);
	if(!proto_name) return;

	description = ph_capture_get_description(cf);

	for (cur_kf = 0; cur_kf < g_ph_key_files->len; cur_kf++) {
		phkf = (proto_help_key_file *) g_ptr_array_index(g_ph_key_files, cur_kf);
		g_assert(phkf);

		value = ph_ini_get_path(phkf->keyfile, proto_abbrev, PH_INI_KEY_OVERVIEW);

		if(!value)
		{
			g_log(NULL, G_LOG_LEVEL_DEBUG, "Overview page of the protocol '%s' is not defined", proto_abbrev);
			continue;
		}

		/*
		 * XXX - We could save some memory here if we stored the location template
		 * and search value as separate items. However, that makes freeing them
		 * a bit messy.
		 */
		loc = string_replace(phkf->loc_template, PH_PATH_SEARCH_STR, value);
		g_free(value);
		if (!loc || !strlen(loc)) continue;

		if (add_separator) {
			menu_entry = g_malloc0(sizeof(GtkItemFactoryEntry));
			menu_entry->path = g_strdup_printf("%s/<separator>", PH_MENU_TOP);
			menu_entry->item_type = "<Separator>";
			gtk_item_factory_create_item(g_ph_menu_factory, menu_entry, NULL, 2);
		}
		add_separator = TRUE;

		menu_entry = g_malloc0(sizeof(GtkItemFactoryEntry));
		menu_entry->path = g_strdup_printf("%s/%s %s Overview", PH_MENU_TOP, phkf->source, proto_name);
		menu_entry->callback = ph_menu_onclick;
		gtk_item_factory_create_item(g_ph_menu_factory, menu_entry, loc, 2);
		menu_item = gtk_item_factory_get_widget(g_ph_menu_factory, menu_entry->path);
		g_assert(menu_item);
		g_signal_connect(menu_item, "destroy", G_CALLBACK(url_destroy_cb), loc);

		found = TRUE;

		if(description)
		{
			keys = ph_ini_get_keywords(phkf->keyfile, proto_abbrev);
			table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);

			for(i = 0; keys[i] != NULL; i++)
			{
				if(!strcmp(keys[i], PH_INI_KEY_OVERVIEW)) continue; /* We already added the overview */
				if(!ph_parse_string(description, keys[i])) continue; /* Bad format */
				if(g_hash_table_lookup(table, g_ascii_strup(keys[i], -1)) != NULL) continue; /* Duplicate */

				value = ph_ini_get_path(phkf->keyfile, proto_abbrev, keys[i]);
				if(!value || !strlen(value)) continue;

				loc = string_replace(phkf->loc_template, PH_PATH_SEARCH_STR, value);
				g_free(value);
				if (!loc || !strlen(loc)) continue;

				g_hash_table_insert(table, g_ascii_strup(keys[i], -1), GINT_TO_POINTER(1));

				menu_entry = g_malloc0(sizeof(GtkItemFactoryEntry));
				menu_entry->path = g_strdup_printf("%s/%s", PH_MENU_TOP, keys[i]);
				menu_entry->callback = ph_menu_onclick;
				gtk_item_factory_create_item(g_ph_menu_factory, menu_entry, loc, 2);
				menu_item = gtk_item_factory_get_widget(g_ph_menu_factory, menu_entry->path);
				g_assert(menu_item);
				g_signal_connect(menu_item, "destroy", G_CALLBACK(url_destroy_cb), loc);
			}

			g_hash_table_destroy(table);
		}
	}

	g_free(description);
	menu_item = gtk_item_factory_get_item(g_ph_menu_factory, PH_MENU_TOP);
	gtk_widget_set_sensitive(menu_item, found);
}

/**
* Function ph_menu_onclick
*
* @param GtkWidget *widget Description
* @param gpointer data Description
* @param guint action Description
* @return void
*/
static void ph_menu_onclick(GtkWidget *widget _U_, gpointer data, guint action _U_)
{
	gchar *loc = (gchar *) data;

	g_log(NULL, G_LOG_LEVEL_DEBUG, "Sending '%s' to the browser.", loc);

	if (! loc) {
		g_log(NULL, G_LOG_LEVEL_DEBUG, "Protocol help ended up with a NULL URL.");
		return;
	}

	/* XXX - Should we do any RFC 3986 escaping first? */
	if (! browser_open_url(loc)) {
		g_log(NULL, G_LOG_LEVEL_DEBUG, "Couldn't get protocol help for %s", loc);
	}
}

/** Get the field ID for a selected tree item.
 *
 * @param selection Tree selection
 * @param cfile Capture file
 * @return Field ID or 0
 */
static int
ph_capture_get_protocol_id(GtkTreeSelection *selection, capture_file *cf)
{
	GtkTreeModel *model = NULL;
	GtkTreeIter iter;
	GtkTreeIter parent;
	field_info *finfo = NULL;
	int proto_id = 0;

	if(!cf->finfo_selected) return 0;
	proto_id = cf->finfo_selected->hfinfo->id;

	if(!proto_id)
	{
		if(!gtk_tree_selection_get_selected(GTK_TREE_SELECTION(selection), &model, &iter)) return 0;

		while(gtk_tree_model_iter_parent(model, &parent, &iter))
		{
			gtk_tree_model_get(model, &parent, 1, &finfo, -1);
			iter = parent;

			if(finfo->hfinfo->id > 0)
			{
				proto_id = finfo->hfinfo->id;
				break;
			}
		}
	}

	while(proto_id && !proto_registrar_is_protocol(proto_id))
	{
		proto_id = proto_registrar_get_parent(proto_id);
	}

	return proto_id;
}

/** Get the protocol name for a selected tree item.
 *
 * @param selection Tree selection
 * @param cfile Capture file
 * @return Name for a protocol or NULL
 */
static const gchar*
ph_capture_get_protocol_name(GtkTreeSelection *selection, capture_file *cf)
{
	int proto_id = ph_capture_get_protocol_id(selection, cf);

	return (!proto_id) ? NULL : proto_get_protocol_short_name(find_protocol_by_id(proto_id));
}

/** Get the abbreviated protocol name for a selected tree item.
 *
 * @param selection Tree selection
 * @param cfile Capture file
 * @return Abbreviated (lower-case) name for a protocol or NULL
 */
static const gchar*
ph_capture_get_protocol_abbrev(GtkTreeSelection *selection, capture_file *cf)
{
	int proto_id = ph_capture_get_protocol_id(selection, cf);

	return (!proto_id) ? NULL : proto_registrar_get_abbrev(proto_id);
}

/** Return the selected item description
 * @param cf capture file pointer
 * @return Description of the selected item. MUST be freed with g_free().
 */
static gchar* ph_capture_get_description(capture_file *cf)
{
	gchar *buffer = NULL;

	if(cf->finfo_selected->rep &&
	   strlen(cf->finfo_selected->rep->representation) > 0)
	{
		buffer = g_strdup(cf->finfo_selected->rep->representation);
	}
	else
	{
		buffer = g_malloc(ITEM_LABEL_LENGTH);
		proto_item_fill_label(cf->finfo_selected, buffer);
	}

	return buffer;
}

/** Load a protocol help key file and add it to the global array.
 *
 * @param filename Full path to the key file.
 * @return Newly-created key file entry or NULL.
 */
static proto_help_key_file *
ph_ini_load_file(const gchar *filename)
{
	GKeyFile *kf;
	GError *error = NULL;
	proto_help_key_file *phkf = NULL;
	gchar *old_template, *loc_template;
	gchar **loc_data, *loc_repl, *loc_search;
	gsize i, len;

	if(!g_file_test(filename, G_FILE_TEST_EXISTS))
	{
		g_log(NULL, G_LOG_LEVEL_DEBUG, "Configuration file %s does not exists", filename);
		return NULL;
	}

	kf = g_key_file_new();

	if(!g_key_file_load_from_file(kf, filename, G_KEY_FILE_NONE, &error))
	{
		g_log(NULL, G_LOG_LEVEL_DEBUG, "Configuration file '%s' could not be loaded (%s)", filename, error->message);
		g_error_free(error);
		g_key_file_free(kf);

		return NULL;
	}

	loc_template = ph_ini_get_value(kf, PH_INI_GROUP_DATABASE, PH_INI_DB_KEY_LOCATION_TEMPLATE, NULL);
	if (!loc_template) {
		g_key_file_free(kf);
		return NULL;
	}

	loc_data = g_key_file_get_keys(kf, PH_INI_GROUP_LOCATION_DATA, &len, NULL);
	if (loc_data) {
		for (i = 0; i < len; i++) {
			loc_repl = ph_ini_get_value(kf, PH_INI_GROUP_LOCATION_DATA, loc_data[i], NULL);
			old_template = loc_template;
			loc_search = g_strdup_printf("${%s}", loc_data[i]);
			loc_template = string_replace(loc_template, loc_search, loc_repl);
			g_free(loc_repl);
			g_free(loc_search);
			g_free(old_template);
		}
	}

	/* Add ${PATH} to the end if it's not present */
	if (!strstr(loc_template, PH_PATH_SEARCH_STR)) {
		old_template = loc_template;
		loc_template = g_strdup_printf("%s" PH_PATH_SEARCH_STR, old_template);
		g_free(old_template);
	}

	phkf = g_malloc(sizeof(proto_help_key_file));
	phkf->keyfile = kf;
	phkf->source = ph_ini_get_value(kf, PH_INI_GROUP_DATABASE, PH_INI_DB_KEY_SOURCE, "(Unknown source)");
	phkf->loc_template = loc_template;

	g_ptr_array_add(g_ph_key_files, phkf);

	return phkf;
}

/** Fetch a value for a key from a key file with an optional default value.
 *
 * @param keyfile The key file to search
 * @param group Key file group
 * @param key Key file value to fetch
 * @param alt Alternate string to return. May be NULL.
 * @return const gchar* A newly-allocated key value, or a copy of alt if not found.
 */
static gchar*
ph_ini_get_value(GKeyFile *keyfile, const gchar *group, const gchar *key, gchar *alt)
{
	gchar *value = NULL;

	if (keyfile) {
		value = g_key_file_get_string(keyfile, group, key, NULL);
	}

	if (!value) {
		value = g_strdup(alt);
	}

	return value;
}

/** Given a protocol name and a key, map the protocol name to a section in the
 * keyfile, then look up the value for that key.
 *
 * @param keyfile The key file to search
 * @param protocol Wireshark protocol name to map, e.g. "tcp".
 * @param keyword The key to fetch from the mapped section.
 * @return
 */
static gchar*
ph_ini_get_path(GKeyFile *keyfile, const gchar *protocol, const gchar *keyword)
{
	GError *error = NULL;
	gchar *map;
	gchar *value;

	if(!keyfile || !protocol || !keyword) return NULL;

	map = g_key_file_get_string(keyfile, PH_INI_GROUP_MAP, protocol, &error);

	if(!map)
	{
		g_log(NULL, G_LOG_LEVEL_DEBUG, "Protocol '%s' is not defined (%s)", protocol, error->message);
		g_error_free(error);
		return NULL;
	}

	value = g_key_file_get_string(keyfile, map, keyword, NULL);
	g_free(map);
	return value;
}

/** Given a protocol name, map it to a section in the keyfile, then
 * return the keys in that section.
 *
 * @param keyfile The key file to search
 * @param protocol Wireshark protocol name to map, e.g. "tcp".
 * @return An array of keys in the mapped section. Must be freed with g_strfreev().
 */
static gchar**
ph_ini_get_keywords(GKeyFile *keyfile, const gchar *protocol)
{
	GError *error = NULL;
	gchar *map;
	gchar **keys;
	gsize length = 0;

	if(!keyfile) return NULL;

	map = g_key_file_get_string(keyfile, PH_INI_GROUP_MAP, protocol, &error);

	if(!map)
	{
		g_log(NULL, G_LOG_LEVEL_DEBUG, "Protocol '%s' is not defined (%s)", protocol, error->message);
		g_error_free(error);
		return NULL;
	}

	error = NULL;
	keys = g_key_file_get_keys(keyfile, map, &length, &error);
	g_free(map);

	if(!keys)
	{
		g_log(NULL, G_LOG_LEVEL_DEBUG, "Display titles are not defined (%s)", protocol);
		g_error_free(error);
	}

	return keys;
}

/**
* Function ph_parse_string
*
* @param const gchar *description Description
* @param const gchar *value Description
* @return guint Description
*/
static guint ph_parse_string(const gchar *description, const gchar *value)
{
	GRegex *regex = NULL;
	GMatchInfo *match_info = NULL;
	gchar *pattern = NULL;
	guint result = 0;

	pattern = g_strdup_printf("(?<![0-9a-zA-Z_])%s(?![0-9a-zA-Z_])", value);
	regex = g_regex_new(pattern, 0, 0, NULL);

	g_regex_match(regex, description, 0, &match_info);
	if(g_match_info_matches(match_info)) result = 1;

	g_match_info_free(match_info);
	g_regex_unref(regex);

	return result;
}

#ifdef PH_DEBUG_LOG
/**
 * Function ph_logging_handler
 *
 * @param const gchar *domain Description
 * @param GLogLevelFlags level Description
 * @param const gchar *message Description
 * @param gpointer data Description
 * @return void
 */
static void ph_logging_handler(const gchar *domain _U_, GLogLevelFlags level, const gchar *message, gpointer data _U_)
{
	gchar *log = NULL;
	gchar *type = NULL;
	FILE *file = NULL;
	struct tm *timestamp = NULL;
	time_t now;

	time(&now);
	timestamp = localtime(&now);

	switch(level & G_LOG_LEVEL_MASK)
	{
		case G_LOG_LEVEL_ERROR:
			type = "ERR";
			break;

		case G_LOG_LEVEL_DEBUG:
			type = "WARNING";
			break;

		case G_LOG_LEVEL_INFO:
			type = "INFO";
			break;

		default:
			type = "OTHER";
	}

	file = ws_fopen(ph_log_path, "a+");

	if(file)
	{
		log = g_strdup_printf("[%04u-%02u-%02u %02u:%02u:%02u %s] %s\n", timestamp->tm_year + 1900, timestamp->tm_mon + 1, timestamp->tm_mday, timestamp->tm_hour, timestamp->tm_min, timestamp->tm_sec, type, message);
		fputs(log, file);
		fclose(file);
	}
}
#endif /* PH_DEBUG_LOG */
#endif /* MAIN_MENU_USE_UIMANAGER */