aboutsummaryrefslogtreecommitdiffstats
path: root/ui/recent.c
blob: 45193bf95c429296bdaa4f9ca4c3082f65495bc8 (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
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
/* recent.c
 * Recent "preference" handling routines
 * Copyright 2004, Ulf Lamping <ulf.lamping@web.de>
 *
 * 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"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>

#include "capture_opts.h"
#include <epan/epan.h>
#include <wsutil/filesystem.h>
#include <epan/emem.h>
#include <epan/prefs.h>
#include <epan/prefs-int.h>
#include <epan/column.h>
#include <epan/timestamp.h>

#include "ui/last_open_dir.h"
#include "ui/recent.h"
#include "ui/recent_utils.h"
#include "ui/simple_dialog.h"
#include "ui/ui_util.h"

#include <wsutil/u3.h>
#include <wsutil/file_util.h>
#include <wsutil/str_util.h>

#define RECENT_KEY_MAIN_TOOLBAR_SHOW          "gui.toolbar_main_show"
#define RECENT_KEY_FILTER_TOOLBAR_SHOW        "gui.filter_toolbar_show"
#define RECENT_KEY_WIRELESS_TOOLBAR_SHOW      "gui.wireless_toolbar_show"
#define RECENT_KEY_DRIVER_CHECK_SHOW          "gui.airpcap_driver_check_show"
#define RECENT_KEY_PACKET_LIST_SHOW           "gui.packet_list_show"
#define RECENT_KEY_TREE_VIEW_SHOW             "gui.tree_view_show"
#define RECENT_KEY_BYTE_VIEW_SHOW             "gui.byte_view_show"
#define RECENT_KEY_STATUSBAR_SHOW             "gui.statusbar_show"
#define RECENT_KEY_PACKET_LIST_COLORIZE       "gui.packet_list_colorize"
#define RECENT_GUI_TIME_FORMAT                "gui.time_format"
#define RECENT_GUI_TIME_PRECISION             "gui.time_precision"
#define RECENT_GUI_SECONDS_FORMAT             "gui.seconds_format"
#define RECENT_GUI_ZOOM_LEVEL                 "gui.zoom_level"
#define RECENT_GUI_BYTES_VIEW                 "gui.bytes_view"
#define RECENT_GUI_GEOMETRY_MAIN_X            "gui.geometry_main_x"
#define RECENT_GUI_GEOMETRY_MAIN_Y            "gui.geometry_main_y"
#define RECENT_GUI_GEOMETRY_MAIN_WIDTH        "gui.geometry_main_width"
#define RECENT_GUI_GEOMETRY_MAIN_HEIGHT       "gui.geometry_main_height"
#define RECENT_GUI_GEOMETRY_MAIN_MAXIMIZED    "gui.geometry_main_maximized"
#define RECENT_GUI_GEOMETRY_MAIN_UPPER_PANE   "gui.geometry_main_upper_pane"
#define RECENT_GUI_GEOMETRY_MAIN_LOWER_PANE   "gui.geometry_main_lower_pane"
#define RECENT_GUI_GEOMETRY_STATUS_PANE_LEFT  "gui.geometry_status_pane"
#define RECENT_GUI_GEOMETRY_STATUS_PANE_RIGHT "gui.geometry_status_pane_right"
#define RECENT_GUI_GEOMETRY_WLAN_STATS_PANE   "gui.geometry_status_wlan_stats_pane"
#define RECENT_LAST_USED_PROFILE              "gui.last_used_profile"
#define RECENT_GUI_FILEOPEN_REMEMBERED_DIR    "gui.fileopen_remembered_dir"
#define RECENT_GUI_CONVERSATION_TABS          "gui.conversation_tabs"
#define RECENT_GUI_ENDPOINT_TABS              "gui.endpoint_tabs"

#define RECENT_GUI_GEOMETRY                   "gui.geom."

#define RECENT_KEY_PRIVS_WARN_IF_ELEVATED     "privs.warn_if_elevated"
#define RECENT_KEY_PRIVS_WARN_IF_NO_NPF       "privs.warn_if_no_npf"

#define RECENT_FILE_NAME "recent"
#define RECENT_COMMON_FILE_NAME "recent_common"

recent_settings_t recent;

static const char *ts_type_text[] =
  { "RELATIVE", "ABSOLUTE", "ABSOLUTE_WITH_DATE", "DELTA", "DELTA_DIS", "EPOCH", "UTC", "UTC_WITH_DATE", NULL };

static const char *ts_precision_text[] =
{ "AUTO", "SEC", "DSEC", "CSEC", "MSEC", "USEC", "NSEC", NULL };

static const char *ts_seconds_text[] =
  { "SECONDS", "HOUR_MIN_SEC", NULL };

/* Takes an string and a pointer to an array of strings, and a default int value.
 * The array must be terminated by a NULL string. If the string is found in the array
 * of strings, the index of that string in the array is returned. Otherwise, the
 * default value that was passed as the third argument is returned.
 */
static int
find_index_from_string_array(const char *needle, const char **haystack, int default_value)
{
  int i = 0;

  while (haystack[i] != NULL) {
    if (strcmp(needle, haystack[i]) == 0) {
      return i;
    }
    i++;
  }
  return default_value;
}

static void
free_col_width_info(recent_settings_t *rs)
{
  col_width_data *cfmt;

  while (rs->col_width_list != NULL) {
    cfmt = (col_width_data *)rs->col_width_list->data;
    g_free(cfmt->cfield);
    g_free(cfmt);
    rs->col_width_list = g_list_remove_link(rs->col_width_list, rs->col_width_list);
  }
  g_list_free(rs->col_width_list);
  rs->col_width_list = NULL;
}

/** Write the geometry values of a single window to the recent file.
 *
 * @param key unused
 * @param value the geometry values
 * @param rfh recent file handle (FILE)
 */
static void
write_recent_geom(gpointer key _U_, gpointer value, gpointer rfh)
{
  window_geometry_t *geom = (window_geometry_t *)value;
  FILE *rf = (FILE *)rfh;

  fprintf(rf, "\n# Geometry and maximized state of %s window.\n", geom->key);
  fprintf(rf, "# Decimal integers.\n");
  fprintf(rf, RECENT_GUI_GEOMETRY "%s.x: %d\n", geom->key, geom->x);
  fprintf(rf, RECENT_GUI_GEOMETRY "%s.y: %d\n", geom->key, geom->y);
  fprintf(rf, RECENT_GUI_GEOMETRY "%s.width: %d\n", geom->key,
          geom->width);
  fprintf(rf, RECENT_GUI_GEOMETRY "%s.height: %d\n", geom->key,
          geom->height);

  fprintf(rf, "# TRUE or FALSE (case-insensitive).\n");
  fprintf(rf, RECENT_GUI_GEOMETRY "%s.maximized: %s\n", geom->key,
          geom->maximized == TRUE ? "TRUE" : "FALSE");

}

/* the geometry hashtable for all known window classes,
 * the window name is the key, and the geometry struct is the value */
static GHashTable *window_geom_hash = NULL;

/* save the window and its current geometry into the geometry hashtable */
void
window_geom_save(const gchar *name, window_geometry_t *geom)
{
  gchar *key;
  window_geometry_t *work;

  /* init hashtable, if not already done */
  if (!window_geom_hash) {
    window_geom_hash = g_hash_table_new(g_str_hash, g_str_equal);
  }
  /* if we have an old one, remove and free it first */
  work = (window_geometry_t *)g_hash_table_lookup(window_geom_hash, name);
  if (work) {
    g_hash_table_remove(window_geom_hash, name);
    g_free(work->key);
    g_free(work);
  }

  /* g_malloc and insert the new one */
  work = (window_geometry_t *)g_malloc(sizeof(window_geometry_t));
  *work = *geom;
  key = g_strdup(name);
  work->key = key;
  g_hash_table_insert(window_geom_hash, key, work);
}

/* load the desired geometry for this window from the geometry hashtable */
gboolean
window_geom_load(const gchar       *name,
                 window_geometry_t *geom)
{
  window_geometry_t *p;

  /* init hashtable, if not already done */
  if (!window_geom_hash) {
    window_geom_hash = g_hash_table_new(g_str_hash, g_str_equal);
  }

  p = (window_geometry_t *)g_hash_table_lookup(window_geom_hash, name);
  if (p) {
    *geom = *p;
    return TRUE;
  } else {
    return FALSE;
  }
}

/** Read in a single geometry key value pair from the recent file.
 *
 * @param name the geom_name of the window
 * @param key the subkey of this pair (e.g. "x")
 * @param value the new value (e.g. "123")
 */
static void
window_geom_recent_read_pair(const char *name,
                             const char *key,
                             const char *value)
{
  window_geometry_t geom;

  /* find window geometry maybe already in hashtable */
  if (!window_geom_load(name, &geom)) {
    /* not in table, init geom with "basic" values */
    geom.key        = NULL;    /* Will be set in window_geom_save() */
    geom.set_pos    = FALSE;
    geom.x          = -1;
    geom.y          = -1;
    geom.set_size   = FALSE;
    geom.width      = -1;
    geom.height     = -1;

    geom.set_maximized = FALSE;/* this is valid in GTK2 only */
    geom.maximized  = FALSE;   /* this is valid in GTK2 only */
  }

  if (strcmp(key, "x") == 0) {
    geom.x = (gint)strtol(value, NULL, 10);
    geom.set_pos = TRUE;
  } else if (strcmp(key, "y") == 0) {
    geom.y = (gint)strtol(value, NULL, 10);
    geom.set_pos = TRUE;
  } else if (strcmp(key, "width") == 0) {
    geom.width = (gint)strtol(value, NULL, 10);
    geom.set_size = TRUE;
  } else if (strcmp(key, "height") == 0) {
    geom.height = (gint)strtol(value, NULL, 10);
    geom.set_size = TRUE;
  } else if (strcmp(key, "maximized") == 0) {
    if (g_ascii_strcasecmp(value, "true") == 0) {
      geom.maximized = TRUE;
    }
    else {
      geom.maximized = FALSE;
    }
    geom.set_maximized = TRUE;
  } else {
    /*
     * Silently ignore the bogus key.  We shouldn't abort here,
     * as this could be due to a corrupt recent file.
     *
     * XXX - should we print a message about this?
     */
    return;
  }

  /* save / replace geometry in hashtable */
  window_geom_save(name, &geom);
}

/** Write all geometry values of all windows to the recent file.
 * Will call write_recent_geom() for every existing window type.
 *
 * @param rf recent file handle from caller
 */
static void
window_geom_recent_write_all(FILE *rf)
{
  /* init hashtable, if not already done */
  if (!window_geom_hash) {
    window_geom_hash = g_hash_table_new(g_str_hash, g_str_equal);
  }

  g_hash_table_foreach(window_geom_hash, write_recent_geom, rf);
}

/* Global list of recent capture filters. */
static GList *recent_cfilter_list;

/*
 * Per-interface lists of recent capture filters; stored in a hash
 * table indexed by interface name.
 */
static GHashTable *per_interface_cfilter_lists_hash;

/* XXX: use a preference for this setting! */
static guint cfilter_combo_max_recent = 20;

/**
 * Returns a list of recent capture filters.
 *
 * @param ifname interface name; NULL refers to the global list.
 */
GList *
recent_get_cfilter_list(const gchar *ifname)
{
  if (ifname == NULL)
    return recent_cfilter_list;
  if (per_interface_cfilter_lists_hash == NULL) {
    /* No such lists exist. */
    return NULL;
  }
  return (GList *)g_hash_table_lookup(per_interface_cfilter_lists_hash, ifname);
}

/**
 * Add a capture filter to the global recent capture filter list or
 * the recent capture filter list for an interface.
 *
 * @param ifname interface name; NULL refers to the global list.
 * @param s text of capture filter
 */
void
recent_add_cfilter(const gchar *ifname, const gchar *s)
{
  GList     *cfilter_list;
  GList     *li;
  gchar     *li_filter, *newfilter = NULL;

  /* Don't add empty filters to the list. */
  if (s[0] == '\0')
    return;

  if (ifname == NULL)
    cfilter_list = recent_cfilter_list;
  else {
    /* If we don't yet have a hash table for per-interface recent
       capture filter lists, create one.  Have it free the new key
       if we're updating an entry rather than creating it below. */
    if (per_interface_cfilter_lists_hash == NULL)
      per_interface_cfilter_lists_hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
    cfilter_list = (GList *)g_hash_table_lookup(per_interface_cfilter_lists_hash, ifname);
  }

  li = g_list_first(cfilter_list);
  while (li) {
    /* If the filter is already in the list, remove the old one and
     * append the new one at the latest position (at g_list_append() below) */
    li_filter = (char *)li->data;
    if (strcmp(s, li_filter) == 0) {
      /* No need to copy the string, we're just moving it. */
      newfilter = li_filter;
      cfilter_list = g_list_remove(cfilter_list, li->data);
      break;
    }
    li = li->next;
  }
  if (newfilter == NULL) {
    /* The filter wasn't already in the list; make a copy to add. */
    newfilter = g_strdup(s);
  }
  cfilter_list = g_list_append(cfilter_list, newfilter);

  if (ifname == NULL)
    recent_cfilter_list = cfilter_list;
  else
    g_hash_table_insert(per_interface_cfilter_lists_hash, g_strdup(ifname), cfilter_list);
}

#ifdef HAVE_PCAP_REMOTE
static GHashTable *remote_host_list=NULL;

int recent_get_remote_host_list_size(void)
{
  return g_hash_table_size (remote_host_list);
}

void recent_add_remote_host(gchar *host, struct remote_host *rh)
{
  if (remote_host_list == NULL) {
    remote_host_list = g_hash_table_new (g_str_hash, g_str_equal);
  }
  g_hash_table_insert (remote_host_list, g_strdup(host), rh);
}

static gboolean
free_remote_host (gpointer key _U_, gpointer value, gpointer user _U_)
{
  struct remote_host *rh = value;

  g_free (rh->r_host);
  g_free (rh->remote_port);
  g_free (rh->auth_username);
  g_free (rh->auth_password);

  return TRUE;
}

GHashTable *get_remote_host_list(void)
{
  return remote_host_list;
}

static void
recent_print_remote_host (gpointer key _U_, gpointer value, gpointer user)
{
  FILE *rf = user;
  struct remote_host_info *ri = value;

  fprintf (rf, RECENT_KEY_REMOTE_HOST ": %s,%s,%d\n", ri->remote_host, ri->remote_port, ri->auth_type);
}

void
capture_remote_combo_recent_write_all(FILE *rf)
{
  if (remote_host_list && g_hash_table_size (remote_host_list) > 0) {
    /* Write all remote interfaces to the recent file */
    g_hash_table_foreach (remote_host_list, recent_print_remote_host, rf);
  }
}


void free_remote_host_list(void)
{
  g_hash_table_foreach_remove(remote_host_list, free_remote_host, NULL);
}

struct remote_host *
recent_get_remote_host(const gchar *host)
{
  if (host == NULL)
    return NULL;
  if (remote_host_list == NULL) {
    /* No such host exist. */
    return NULL;
  }
  return (struct remote_host *)g_hash_table_lookup(remote_host_list, host);
}

gboolean
capture_remote_combo_add_recent(const gchar *s)
{
  GList *vals = prefs_get_string_list (s);
  GList *valp = vals;
  gint   auth_type;
  char  *p;
  struct remote_host *rh;

  if (valp == NULL)
    return FALSE;

  if (remote_host_list == NULL) {
    remote_host_list = g_hash_table_new (g_str_hash, g_str_equal);
  }

  rh = g_malloc (sizeof (*rh));

  /* First value is the host */
  rh->r_host = g_strdup (valp->data);
  if (strlen(rh->r_host) == 0) {
    /* Empty remote host */
    g_free(rh->r_host);
    g_free(rh);
    return FALSE;
  }
  rh->auth_type = CAPTURE_AUTH_NULL;
  valp = valp->next;

  if (valp) {
    /* Found value 2, this is the port number */
    rh->remote_port = g_strdup (valp->data);
    valp = valp->next;
  } else {
    /* Did not find a port number */
    rh->remote_port = g_strdup ("");
  }

  if (valp) {
    /* Found value 3, this is the authentication type */
    auth_type = strtol(valp->data, &p, 0);
    if (p != valp->data && *p == '\0') {
      rh->auth_type = auth_type;
    }
  }

  /* Do not store username and password */
  rh->auth_username = g_strdup ("");
  rh->auth_password = g_strdup ("");

  prefs_clear_string_list(vals);

  g_hash_table_insert (remote_host_list, g_strdup(rh->r_host), rh);

  return TRUE;
}
#endif

static void
cfilter_recent_write_all_list(FILE *rf, const gchar *ifname, GList *cfilter_list)
{
  guint      max_count = 0;
  GList     *li;

  /* write all non empty capture filter strings to the recent file (until max count) */
  li = g_list_first(cfilter_list);
  while (li && (max_count++ <= cfilter_combo_max_recent) ) {
    if (li->data && strlen((const char *)li->data)) {
      if (ifname == NULL)
        fprintf (rf, RECENT_KEY_CAPTURE_FILTER ": %s\n", (char *)li->data);
      else
        fprintf (rf, RECENT_KEY_CAPTURE_FILTER ".%s: %s\n", ifname, (char *)li->data);
    }
    li = li->next;
  }
}

static void
cfilter_recent_write_all_hash_callback(gpointer key, gpointer value, gpointer user_data)
{
  cfilter_recent_write_all_list((FILE *)user_data, (const gchar *)key, (GList *)value);
}

/** Write all capture filter values to the recent file.
 *
 * @param rf recent file handle from caller
 */
static void
cfilter_recent_write_all(FILE *rf)
{
  /* Write out the global list. */
  cfilter_recent_write_all_list(rf, NULL, recent_cfilter_list);

  /* Write out all the per-interface lists. */
  if (per_interface_cfilter_lists_hash != NULL) {
    g_hash_table_foreach(per_interface_cfilter_lists_hash, cfilter_recent_write_all_hash_callback, (gpointer)rf);
  }
}

/* Attempt to Write out "recent common" to the user's recent common file.
   If we got an error report it with a dialog box and return FALSE,
   otherwise return TRUE. */
gboolean
write_recent(void)
{
  char        *pf_dir_path;
  char        *rf_path;
  FILE        *rf;

  /* To do:
   * - Split output lines longer than MAX_VAL_LEN
   * - Create a function for the preference directory check/creation
   *   so that duplication can be avoided with filter.c
   */

  /* Create the directory that holds personal configuration files, if
     necessary.  */
  if (create_persconffile_dir(&pf_dir_path) == -1) {
     simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
      "Can't create directory\n\"%s\"\nfor recent file: %s.", pf_dir_path,
      g_strerror(errno));
     g_free(pf_dir_path);
     return FALSE;
  }

  rf_path = get_persconffile_path(RECENT_COMMON_FILE_NAME, FALSE);
  if ((rf = ws_fopen(rf_path, "w")) == NULL) {
     simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
      "Can't open recent file\n\"%s\": %s.", rf_path,
      g_strerror(errno));
    g_free(rf_path);
    return FALSE;
  }
  g_free(rf_path);

  fputs("# Recent settings file for Wireshark " VERSION ".\n"
    "#\n"
    "# This file is regenerated each time Wireshark is quit.\n"
    "# So be careful, if you want to make manual changes here.\n"
    "\n"
    "######## Recent capture files (latest last), cannot be altered through command line ########\n"
    "\n", rf);

  menu_recent_file_write_all(rf);

  fputs("\n"
    "######## Recent capture filters (latest last), cannot be altered through command line ########\n"
    "\n", rf);

  cfilter_recent_write_all(rf);

  fputs("\n"
    "######## Recent display filters (latest last), cannot be altered through command line ########\n"
    "\n", rf);

  dfilter_recent_combo_write_all(rf);

#ifdef HAVE_PCAP_REMOTE
  fputs("\n"
    "######## Recent remote hosts, cannot be altered through command line ########\n"
    "\n", rf);

  capture_remote_combo_recent_write_all(rf);
#endif

  fprintf(rf, "\n# Main window geometry.\n");
  fprintf(rf, "# Decimal numbers.\n");
  fprintf(rf, RECENT_GUI_GEOMETRY_MAIN_X ": %d\n", recent.gui_geometry_main_x);
  fprintf(rf, RECENT_GUI_GEOMETRY_MAIN_Y ": %d\n", recent.gui_geometry_main_y);
  fprintf(rf, RECENT_GUI_GEOMETRY_MAIN_WIDTH ": %d\n",
          recent.gui_geometry_main_width);
  fprintf(rf, RECENT_GUI_GEOMETRY_MAIN_HEIGHT ": %d\n",
          recent.gui_geometry_main_height);

  fprintf(rf, "\n# Main window maximized.\n");
  fprintf(rf, "# TRUE or FALSE (case-insensitive).\n");
  fprintf(rf, RECENT_GUI_GEOMETRY_MAIN_MAXIMIZED ": %s\n",
          recent.gui_geometry_main_maximized == TRUE ? "TRUE" : "FALSE");

  fprintf(rf, "\n# Statusbar left pane size.\n");
  fprintf(rf, "# Decimal number.\n");
  if (recent.gui_geometry_status_pane_left != 0) {
    fprintf(rf, RECENT_GUI_GEOMETRY_STATUS_PANE_LEFT ": %d\n",
            recent.gui_geometry_status_pane_left);
  }
  fprintf(rf, "\n# Statusbar middle pane size.\n");
  fprintf(rf, "# Decimal number.\n");
  if (recent.gui_geometry_status_pane_right != 0) {
    fprintf(rf, RECENT_GUI_GEOMETRY_STATUS_PANE_RIGHT ": %d\n",
            recent.gui_geometry_status_pane_right);
  }

  fprintf(rf, "\n# Last used Configuration Profile.\n");
  fprintf(rf, RECENT_LAST_USED_PROFILE ": %s\n", get_profile_name());

  fprintf(rf, "\n# WLAN statistics upper pane size.\n");
  fprintf(rf, "# Decimal number.\n");
  fprintf(rf, RECENT_GUI_GEOMETRY_WLAN_STATS_PANE ": %d\n",
          recent.gui_geometry_wlan_stats_pane);

  fprintf(rf, "\n# Warn if running with elevated permissions (e.g. as root).\n");
  fprintf(rf, "# TRUE or FALSE (case-insensitive).\n");
  fprintf(rf, RECENT_KEY_PRIVS_WARN_IF_ELEVATED ": %s\n",
          recent.privs_warn_if_elevated == TRUE ? "TRUE" : "FALSE");

  fprintf(rf, "\n# Warn if npf.sys isn't loaded on Windows >= 6.0.\n");
  fprintf(rf, "# TRUE or FALSE (case-insensitive).\n");
  fprintf(rf, RECENT_KEY_PRIVS_WARN_IF_NO_NPF ": %s\n",
          recent.privs_warn_if_no_npf == TRUE ? "TRUE" : "FALSE");

  window_geom_recent_write_all(rf);

  fclose(rf);

  /* XXX - catch I/O errors (e.g. "ran out of disk space") and return
     an error indication, or maybe write to a new recent file and
     rename that file on top of the old one only if there are not I/O
     errors. */
  return TRUE;
}


/* Attempt to Write out profile "recent" to the user's profile recent file.
   If we got an error report it with a dialog box and return FALSE,
   otherwise return TRUE. */
gboolean
write_profile_recent(void)
{
  char        *pf_dir_path;
  char        *rf_path;
  char        *string_list;
  FILE        *rf;

  /* To do:
   * - Split output lines longer than MAX_VAL_LEN
   * - Create a function for the preference directory check/creation
   *   so that duplication can be avoided with filter.c
   */

  /* Create the directory that holds personal configuration files, if
     necessary.  */
  if (create_persconffile_dir(&pf_dir_path) == -1) {
     simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
      "Can't create directory\n\"%s\"\nfor recent file: %s.", pf_dir_path,
      g_strerror(errno));
     g_free(pf_dir_path);
     return FALSE;
  }

  rf_path = get_persconffile_path(RECENT_FILE_NAME, TRUE);
  if ((rf = ws_fopen(rf_path, "w")) == NULL) {
     simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
      "Can't open recent file\n\"%s\": %s.", rf_path,
      g_strerror(errno));
    g_free(rf_path);
    return FALSE;
  }
  g_free(rf_path);

  fputs("# Recent settings file for Wireshark " VERSION ".\n"
    "#\n"
    "# This file is regenerated each time Wireshark is quit\n"
    "# and when changing configuration profile.\n"
    "# So be careful, if you want to make manual changes here.\n"
    "\n", rf);

  fprintf(rf, "\n# Main Toolbar show (hide).\n");
  fprintf(rf, "# TRUE or FALSE (case-insensitive).\n");
  fprintf(rf, RECENT_KEY_MAIN_TOOLBAR_SHOW ": %s\n",
          recent.main_toolbar_show == TRUE ? "TRUE" : "FALSE");

  fprintf(rf, "\n# Filter Toolbar show (hide).\n");
  fprintf(rf, "# TRUE or FALSE (case-insensitive).\n");
  fprintf(rf, RECENT_KEY_FILTER_TOOLBAR_SHOW ": %s\n",
          recent.filter_toolbar_show == TRUE ? "TRUE" : "FALSE");

  fprintf(rf, "\n# Wireless Settings Toolbar show (hide).\n");
  fprintf(rf, "# TRUE or FALSE (case-insensitive).\n");
  fprintf(rf, RECENT_KEY_WIRELESS_TOOLBAR_SHOW ": %s\n",
          recent.wireless_toolbar_show == TRUE ? "TRUE" : "FALSE");

#ifdef HAVE_AIRPCAP
  fprintf(rf, "\n# Show (hide) old AirPcap driver warning dialog box.\n");
  fprintf(rf, "# TRUE or FALSE (case-insensitive).\n");
  fprintf(rf, RECENT_KEY_DRIVER_CHECK_SHOW ": %s\n",
          recent.airpcap_driver_check_show == TRUE ? "TRUE" : "FALSE");
#endif

  fprintf(rf, "\n# Packet list show (hide).\n");
  fprintf(rf, "# TRUE or FALSE (case-insensitive).\n");
  fprintf(rf, RECENT_KEY_PACKET_LIST_SHOW ": %s\n",
          recent.packet_list_show == TRUE ? "TRUE" : "FALSE");

  fprintf(rf, "\n# Tree view show (hide).\n");
  fprintf(rf, "# TRUE or FALSE (case-insensitive).\n");
  fprintf(rf, RECENT_KEY_TREE_VIEW_SHOW ": %s\n",
          recent.tree_view_show == TRUE ? "TRUE" : "FALSE");

  fprintf(rf, "\n# Byte view show (hide).\n");
  fprintf(rf, "# TRUE or FALSE (case-insensitive).\n");
  fprintf(rf, RECENT_KEY_BYTE_VIEW_SHOW ": %s\n",
          recent.byte_view_show == TRUE ? "TRUE" : "FALSE");

  fprintf(rf, "\n# Statusbar show (hide).\n");
  fprintf(rf, "# TRUE or FALSE (case-insensitive).\n");
  fprintf(rf, RECENT_KEY_STATUSBAR_SHOW ": %s\n",
          recent.statusbar_show == TRUE ? "TRUE" : "FALSE");

  fprintf(rf, "\n# Packet list colorize (hide).\n");
  fprintf(rf, "# TRUE or FALSE (case-insensitive).\n");
  fprintf(rf, RECENT_KEY_PACKET_LIST_COLORIZE ": %s\n",
          recent.packet_list_colorize == TRUE ? "TRUE" : "FALSE");

  fprintf(rf, "\n# Timestamp display format.\n");
  fprintf(rf, "# One of: RELATIVE, ABSOLUTE, ABSOLUTE_WITH_DATE, DELTA, DELTA_DIS, EPOCH, UTC, UTC_WITH_DATE\n");
  fprintf(rf, RECENT_GUI_TIME_FORMAT ": %s\n",
          ts_type_text[recent.gui_time_format]);

  fprintf(rf, "\n# Timestamp display precision.\n");
  fprintf(rf, "# One of: AUTO, SEC, DSEC, CSEC, MSEC, USEC, NSEC\n");
  fprintf(rf, RECENT_GUI_TIME_PRECISION ": %s\n",
          ts_precision_text[recent.gui_time_precision]);

  fprintf(rf, "\n# Seconds display format.\n");
  fprintf(rf, "# One of: SECONDS, HOUR_MIN_SEC\n");
  fprintf(rf, RECENT_GUI_SECONDS_FORMAT ": %s\n",
          ts_seconds_text[recent.gui_seconds_format]);

  fprintf(rf, "\n# Zoom level.\n");
  fprintf(rf, "# A decimal number.\n");
  fprintf(rf, RECENT_GUI_ZOOM_LEVEL ": %d\n",
          recent.gui_zoom_level);

  fprintf(rf, "\n# Bytes view.\n");
  fprintf(rf, "# A decimal number.\n");
  fprintf(rf, RECENT_GUI_BYTES_VIEW ": %d\n",
          recent.gui_bytes_view);

  fprintf(rf, "\n# Main window upper (or leftmost) pane size.\n");
  fprintf(rf, "# Decimal number.\n");
  if (recent.gui_geometry_main_upper_pane != 0) {
    fprintf(rf, RECENT_GUI_GEOMETRY_MAIN_UPPER_PANE ": %d\n",
            recent.gui_geometry_main_upper_pane);
  }
  fprintf(rf, "\n# Main window middle pane size.\n");
  fprintf(rf, "# Decimal number.\n");
  if (recent.gui_geometry_main_lower_pane != 0) {
    fprintf(rf, RECENT_GUI_GEOMETRY_MAIN_LOWER_PANE ": %d\n",
            recent.gui_geometry_main_lower_pane);
  }

  fprintf(rf, "\n# Packet list column pixel widths.\n");
  fprintf(rf, "# Each pair of strings consists of a column format and its pixel width.\n");
  packet_list_recent_write_all(rf);

  fprintf(rf, "\n# Open conversation dialog tabs.\n");
  fprintf(rf, "# List of conversation names, e.g. \"TCP\", \"IPv6\".\n");
  string_list = join_string_list(recent.conversation_tabs);
  fprintf(rf, RECENT_GUI_CONVERSATION_TABS ": %s\n", string_list);
  g_free(string_list);

  fprintf(rf, "\n# Open endpoint dialog tabs.\n");
  fprintf(rf, "# List of endpoint names, e.g. \"TCP\", \"IPv6\".\n");
  string_list = join_string_list(recent.endpoint_tabs);
  fprintf(rf, RECENT_GUI_ENDPOINT_TABS ": %s\n", string_list);
  g_free(string_list);

  if (get_last_open_dir() != NULL) {
    fprintf(rf, "\n# Last directory navigated to in File Open dialog.\n");

    if (u3_active())
      fprintf(rf, RECENT_GUI_FILEOPEN_REMEMBERED_DIR ": %s\n", u3_contract_device_path(get_last_open_dir()));
    else
      fprintf(rf, RECENT_GUI_FILEOPEN_REMEMBERED_DIR ": %s\n", get_last_open_dir());
  }

  fclose(rf);

  /* XXX - catch I/O errors (e.g. "ran out of disk space") and return
     an error indication, or maybe write to a new recent file and
     rename that file on top of the old one only if there are not I/O
     errors. */
  return TRUE;
}

/* set one user's recent common file key/value pair */
static prefs_set_pref_e
read_set_recent_common_pair_static(gchar *key, const gchar *value,
                                   void *private_data _U_,
                                   gboolean return_range_errors _U_)
{
  long num;
  char *p;

  if (strcmp(key, RECENT_GUI_GEOMETRY_MAIN_MAXIMIZED) == 0) {
    if (g_ascii_strcasecmp(value, "true") == 0) {
        recent.gui_geometry_main_maximized = TRUE;
    }
    else {
        recent.gui_geometry_main_maximized = FALSE;
    }

  } else if (strcmp(key, RECENT_GUI_GEOMETRY_MAIN_X) == 0) {
    num = strtol(value, &p, 0);
    if (p == value || *p != '\0')
      return PREFS_SET_SYNTAX_ERR;      /* number was bad */
    recent.gui_geometry_main_x = (gint)num;
  } else if (strcmp(key, RECENT_GUI_GEOMETRY_MAIN_Y) == 0) {
    num = strtol(value, &p, 0);
    if (p == value || *p != '\0')
      return PREFS_SET_SYNTAX_ERR;      /* number was bad */
    recent.gui_geometry_main_y = (gint)num;
  } else if (strcmp(key, RECENT_GUI_GEOMETRY_MAIN_WIDTH) == 0) {
    num = strtol(value, &p, 0);
    if (p == value || *p != '\0')
      return PREFS_SET_SYNTAX_ERR;      /* number was bad */
    if (num <= 0)
      return PREFS_SET_SYNTAX_ERR;      /* number must be positive */
    recent.gui_geometry_main_width = (gint)num;
  } else if (strcmp(key, RECENT_GUI_GEOMETRY_MAIN_HEIGHT) == 0) {
    num = strtol(value, &p, 0);
    if (p == value || *p != '\0')
      return PREFS_SET_SYNTAX_ERR;      /* number was bad */
    if (num <= 0)
      return PREFS_SET_SYNTAX_ERR;      /* number must be positive */
    recent.gui_geometry_main_height = (gint)num;
  } else if (strcmp(key, RECENT_GUI_GEOMETRY_STATUS_PANE_RIGHT) == 0) {
    num = strtol(value, &p, 0);
    if (p == value || *p != '\0')
      return PREFS_SET_SYNTAX_ERR;      /* number was bad */
    if (num <= 0)
      return PREFS_SET_SYNTAX_ERR;      /* number must be positive */
    recent.gui_geometry_status_pane_right = (gint)num;
    recent.has_gui_geometry_status_pane = TRUE;
  } else if (strcmp(key, RECENT_GUI_GEOMETRY_STATUS_PANE_LEFT) == 0) {
    num = strtol(value, &p, 0);
    if (p == value || *p != '\0')
      return PREFS_SET_SYNTAX_ERR;      /* number was bad */
    if (num <= 0)
      return PREFS_SET_SYNTAX_ERR;      /* number must be positive */
    recent.gui_geometry_status_pane_left = (gint)num;
    recent.has_gui_geometry_status_pane = TRUE;
  } else if (strcmp(key, RECENT_LAST_USED_PROFILE) == 0) {
    if ((strcmp(value, DEFAULT_PROFILE) != 0) && profile_exists (value, FALSE)) {
      set_profile_name (value);
    }
  } else if (strcmp(key, RECENT_GUI_GEOMETRY_WLAN_STATS_PANE) == 0) {
    num = strtol(value, &p, 0);
    if (p == value || *p != '\0')
      return PREFS_SET_SYNTAX_ERR;      /* number was bad */
    if (num <= 0)
      return PREFS_SET_SYNTAX_ERR;      /* number must be positive */
    recent.gui_geometry_wlan_stats_pane = (gint)num;
  } else if (strncmp(key, RECENT_GUI_GEOMETRY, sizeof(RECENT_GUI_GEOMETRY)-1) == 0) {
    /* now have something like "gui.geom.main.x", split it into win and sub_key */
    char *win = &key[sizeof(RECENT_GUI_GEOMETRY)-1];
    char *sub_key = strchr(win, '.');
    if (sub_key) {
      *sub_key = '\0';
      sub_key++;
      window_geom_recent_read_pair(win, sub_key, value);
    }
  } else if (strcmp(key, RECENT_KEY_PRIVS_WARN_IF_ELEVATED) == 0) {
    if (g_ascii_strcasecmp(value, "true") == 0) {
        recent.privs_warn_if_elevated = TRUE;
    }
    else {
        recent.privs_warn_if_elevated = FALSE;
    }
  } else if (strcmp(key, RECENT_KEY_PRIVS_WARN_IF_NO_NPF) == 0) {
    if (g_ascii_strcasecmp(value, "true") == 0) {
        recent.privs_warn_if_no_npf = TRUE;
    }
    else {
        recent.privs_warn_if_no_npf = FALSE;
    }
  }

  return PREFS_SET_OK;
}

/* set one user's recent file key/value pair */
static prefs_set_pref_e
read_set_recent_pair_static(gchar *key, const gchar *value,
                            void *private_data _U_,
                            gboolean return_range_errors _U_)
{
  long num;
  char *p;
  GList *col_l, *col_l_elt;
  col_width_data *cfmt;
  const gchar *cust_format = col_format_to_string(COL_CUSTOM);
  int cust_format_len = (int) strlen(cust_format);

  if (strcmp(key, RECENT_KEY_MAIN_TOOLBAR_SHOW) == 0) {
    if (g_ascii_strcasecmp(value, "true") == 0) {
        recent.main_toolbar_show = TRUE;
    }
    else {
        recent.main_toolbar_show = FALSE;
    }
  } else if (strcmp(key, RECENT_KEY_FILTER_TOOLBAR_SHOW) == 0) {
    if (g_ascii_strcasecmp(value, "true") == 0) {
        recent.filter_toolbar_show = TRUE;
    }
    else {
        recent.filter_toolbar_show = FALSE;
    }
  /* check both the old and the new keyword */
  } else if (strcmp(key, RECENT_KEY_WIRELESS_TOOLBAR_SHOW) == 0 || (strcmp(key, "gui.airpcap_toolbar_show") == 0)) {
    if (g_ascii_strcasecmp(value, "true") == 0) {
        recent.wireless_toolbar_show = TRUE;
    }
    else {
        recent.wireless_toolbar_show = FALSE;
    }
  } else if (strcmp(key, RECENT_KEY_DRIVER_CHECK_SHOW) == 0) {
    if (g_ascii_strcasecmp(value, "true") == 0) {
        recent.airpcap_driver_check_show = TRUE;
    }
    else {
        recent.airpcap_driver_check_show = FALSE;
    }
  } else if (strcmp(key, RECENT_KEY_PACKET_LIST_SHOW) == 0) {
    if (g_ascii_strcasecmp(value, "true") == 0) {
        recent.packet_list_show = TRUE;
    }
    else {
        recent.packet_list_show = FALSE;
    }
  } else if (strcmp(key, RECENT_KEY_TREE_VIEW_SHOW) == 0) {
    if (g_ascii_strcasecmp(value, "true") == 0) {
        recent.tree_view_show = TRUE;
    }
    else {
        recent.tree_view_show = FALSE;
    }
  } else if (strcmp(key, RECENT_KEY_BYTE_VIEW_SHOW) == 0) {
    if (g_ascii_strcasecmp(value, "true") == 0) {
        recent.byte_view_show = TRUE;
    }
    else {
        recent.byte_view_show = FALSE;
    }
  } else if (strcmp(key, RECENT_KEY_STATUSBAR_SHOW) == 0) {
    if (g_ascii_strcasecmp(value, "true") == 0) {
        recent.statusbar_show = TRUE;
    }
    else {
        recent.statusbar_show = FALSE;
    }
  } else if (strcmp(key, RECENT_KEY_PACKET_LIST_COLORIZE) == 0) {
    if (g_ascii_strcasecmp(value, "true") == 0) {
        recent.packet_list_colorize = TRUE;
    }
    else {
        recent.packet_list_colorize = FALSE;
    }
  } else if (strcmp(key, RECENT_GUI_TIME_FORMAT) == 0) {
    recent.gui_time_format =
      (ts_type)find_index_from_string_array(value, ts_type_text, TS_RELATIVE);
  } else if (strcmp(key, RECENT_GUI_TIME_PRECISION) == 0) {
    recent.gui_time_precision =
      find_index_from_string_array(value, ts_precision_text, TS_PREC_AUTO);
  } else if (strcmp(key, RECENT_GUI_SECONDS_FORMAT) == 0) {
    recent.gui_seconds_format =
      (ts_seconds_type)find_index_from_string_array(value, ts_seconds_text, TS_SECONDS_DEFAULT);
  } else if (strcmp(key, RECENT_GUI_ZOOM_LEVEL) == 0) {
    num = strtol(value, &p, 0);
    if (p == value || *p != '\0')
      return PREFS_SET_SYNTAX_ERR;      /* number was bad */
    recent.gui_zoom_level = (gint)num;
  } else if (strcmp(key, RECENT_GUI_BYTES_VIEW) == 0) {
    num = strtol(value, &p, 0);
    if (p == value || *p != '\0')
      return PREFS_SET_SYNTAX_ERR;      /* number was bad */
    recent.gui_bytes_view = (gint)num;
  } else if (strcmp(key, RECENT_GUI_GEOMETRY_MAIN_MAXIMIZED) == 0) {
    if (g_ascii_strcasecmp(value, "true") == 0) {
        recent.gui_geometry_main_maximized = TRUE;
    }
    else {
        recent.gui_geometry_main_maximized = FALSE;
    }

  } else if (strcmp(key, RECENT_GUI_GEOMETRY_MAIN_UPPER_PANE) == 0) {
    num = strtol(value, &p, 0);
    if (p == value || *p != '\0')
      return PREFS_SET_SYNTAX_ERR;      /* number was bad */
    if (num <= 0)
      return PREFS_SET_SYNTAX_ERR;      /* number must be positive */
    recent.gui_geometry_main_upper_pane = (gint)num;
    recent.has_gui_geometry_main_upper_pane = TRUE;
  } else if (strcmp(key, RECENT_GUI_GEOMETRY_MAIN_LOWER_PANE) == 0) {
    num = strtol(value, &p, 0);
    if (p == value || *p != '\0')
      return PREFS_SET_SYNTAX_ERR;      /* number was bad */
    if (num <= 0)
      return PREFS_SET_SYNTAX_ERR;      /* number must be positive */
    recent.gui_geometry_main_lower_pane = (gint)num;
    recent.has_gui_geometry_main_lower_pane = TRUE;
  } else if (strcmp(key, RECENT_GUI_CONVERSATION_TABS) == 0) {
    recent.conversation_tabs = prefs_get_string_list(value);
  } else if (strcmp(key, RECENT_GUI_ENDPOINT_TABS) == 0) {
    recent.endpoint_tabs = prefs_get_string_list(value);
  } else if (strcmp(key, RECENT_KEY_COL_WIDTH) == 0) {
    col_l = prefs_get_string_list(value);
    if (col_l == NULL)
      return PREFS_SET_SYNTAX_ERR;
    if ((g_list_length(col_l) % 2) != 0) {
      /* A title didn't have a matching width.  */
      prefs_clear_string_list(col_l);
      return PREFS_SET_SYNTAX_ERR;
    }
    /* Check to make sure all column formats are valid.  */
    col_l_elt = g_list_first(col_l);
    while (col_l_elt) {
      /* Make sure the format isn't empty.  */
      if (strcmp((const char *)col_l_elt->data, "") == 0) {
        /* It is.  */
        prefs_clear_string_list(col_l);
        return PREFS_SET_SYNTAX_ERR;
      }

      /* Check the format.  */
      if (strncmp((const char *)col_l_elt->data, cust_format, cust_format_len) != 0) {
        if (get_column_format_from_str((const gchar *)col_l_elt->data) == -1) {
          /* It's not a valid column format.  */
          prefs_clear_string_list(col_l);
          return PREFS_SET_SYNTAX_ERR;
        }
      }

      /* Go past the format.  */
      col_l_elt = col_l_elt->next;

      /* Go past the width.  */
      col_l_elt = col_l_elt->next;
    }
    free_col_width_info(&recent);
    recent.col_width_list = NULL;
    col_l_elt = g_list_first(col_l);
    while (col_l_elt) {
      gchar *fmt = g_strdup((const gchar *)col_l_elt->data);
      cfmt = (col_width_data *) g_malloc(sizeof(col_width_data));
      if (strncmp(fmt, cust_format, cust_format_len) != 0) {
        cfmt->cfmt   = get_column_format_from_str(fmt);
        cfmt->cfield = NULL;
      } else {
        cfmt->cfmt   = COL_CUSTOM;
        cfmt->cfield = g_strdup(&fmt[cust_format_len+1]);  /* add 1 for ':' */
      }
      g_free (fmt);
      if (cfmt->cfmt == -1) {
        g_free(cfmt->cfield);
        g_free(cfmt);
        return PREFS_SET_SYNTAX_ERR;   /* string was bad */
      }

      col_l_elt      = col_l_elt->next;
      cfmt->width    = (gint)strtol((const char *)col_l_elt->data, &p, 0);
      if (p == col_l_elt->data || (*p != '\0' && *p != ':')) {
        g_free(cfmt->cfield);
        g_free(cfmt);
        return PREFS_SET_SYNTAX_ERR;    /* number was bad */
      }

      if (*p == ':') {
        cfmt->xalign = *(++p);
      } else {
        cfmt->xalign = COLUMN_XALIGN_DEFAULT;
      }

      col_l_elt      = col_l_elt->next;
      recent.col_width_list = g_list_append(recent.col_width_list, cfmt);
    }
    prefs_clear_string_list(col_l);
  } else if (strcmp(key, RECENT_GUI_FILEOPEN_REMEMBERED_DIR) == 0) {
    if (recent.gui_fileopen_remembered_dir) {
      g_free (recent.gui_fileopen_remembered_dir);
    }
    recent.gui_fileopen_remembered_dir = g_strdup(value);
  }

  return PREFS_SET_OK;
}


/* set one user's recent file key/value pair */
static prefs_set_pref_e
read_set_recent_pair_dynamic(gchar *key, const gchar *value,
                             void *private_data _U_,
                             gboolean return_range_errors _U_)
{
  if (!isprint_string(value)) {
    return PREFS_SET_SYNTAX_ERR;
  }
  if (strcmp(key, RECENT_KEY_CAPTURE_FILE) == 0) {
    if (u3_active())
      add_menu_recent_capture_file(u3_expand_device_path(value));
    else
      add_menu_recent_capture_file(value);
  } else if (strcmp(key, RECENT_KEY_DISPLAY_FILTER) == 0) {
    dfilter_combo_add_recent(value);
  } else if (strcmp(key, RECENT_KEY_CAPTURE_FILTER) == 0) {
    recent_add_cfilter(NULL, value);
  } else if (g_str_has_prefix(key, RECENT_KEY_CAPTURE_FILTER ".")) {
    /* strrchr() can't fail - string has a prefix that ends with a "." */
    recent_add_cfilter(strrchr(key, '.') + 1, value);
#ifdef HAVE_PCAP_REMOTE
  } else if (strcmp(key, RECENT_KEY_REMOTE_HOST) == 0) {
    capture_remote_combo_add_recent(value);
#endif
  }

  return PREFS_SET_OK;
}


/*
 * Given a string of the form "<recent name>:<recent value>", as might appear
 * as an argument to a "-o" option, parse it and set the recent value in
 * question.  Return an indication of whether it succeeded or failed
 * in some fashion.
 */
int
recent_set_arg(char *prefarg)
{
  gchar *p, *colonp;
  int ret;

  colonp = strchr(prefarg, ':');
  if (colonp == NULL)
    return PREFS_SET_SYNTAX_ERR;

  p = colonp;
  *p++ = '\0';

  /*
   * Skip over any white space (there probably won't be any, but
   * as we allow it in the preferences file, we might as well
   * allow it here).
   */
  while (isspace((guchar)*p))
    p++;
  if (*p == '\0') {
    /*
     * Put the colon back, so if our caller uses, in an
     * error message, the string they passed us, the message
     * looks correct.
     */
    *colonp = ':';
    return PREFS_SET_SYNTAX_ERR;
  }

  ret = read_set_recent_pair_static(prefarg, p, NULL, TRUE);
  *colonp = ':';     /* put the colon back */
  return ret;
}


/* opens the user's recent common file and read the first part */
void
recent_read_static(char **rf_path_return, int *rf_errno_return)
{
  char       *rf_path;
  FILE       *rf;

  /* set defaults */
  recent.gui_geometry_main_x        =        20;
  recent.gui_geometry_main_y        =        20;
  recent.gui_geometry_main_width    = DEF_WIDTH;
  recent.gui_geometry_main_height   = DEF_HEIGHT;
  recent.gui_geometry_main_maximized=     FALSE;

  recent.gui_geometry_status_pane_left  = (DEF_WIDTH/3);
  recent.gui_geometry_status_pane_right = (DEF_WIDTH/3);
  recent.gui_geometry_wlan_stats_pane   = 200;

  recent.privs_warn_if_elevated = TRUE;
  recent.privs_warn_if_no_npf = TRUE;

  recent.col_width_list = NULL;
  recent.gui_fileopen_remembered_dir = NULL;

  /* Construct the pathname of the user's recent common file. */
  rf_path = get_persconffile_path(RECENT_COMMON_FILE_NAME, FALSE);

  /* Read the user's recent common file, if it exists. */
  *rf_path_return = NULL;
  if ((rf = ws_fopen(rf_path, "r")) != NULL) {
    /* We succeeded in opening it; read it. */
    read_prefs_file(rf_path, rf, read_set_recent_common_pair_static, NULL);

    fclose(rf);
    g_free(rf_path);
    rf_path = NULL;
  } else {
    /* We failed to open it.  If we failed for some reason other than
       "it doesn't exist", return the errno and the pathname, so our
       caller can report the error. */
    if (errno != ENOENT) {
      *rf_errno_return = errno;
      *rf_path_return = rf_path;
    }
  }
}



/* opens the user's recent file and read the first part */
void
recent_read_profile_static(char **rf_path_return, int *rf_errno_return)
{
  char       *rf_path, *rf_common_path;
  FILE       *rf;

  /* set defaults */
  recent.main_toolbar_show         = TRUE;
  recent.filter_toolbar_show       = TRUE;
  recent.wireless_toolbar_show     = FALSE;
  recent.airpcap_driver_check_show = TRUE;
  recent.packet_list_show          = TRUE;
  recent.tree_view_show            = TRUE;
  recent.byte_view_show            = TRUE;
  recent.statusbar_show            = TRUE;
  recent.packet_list_colorize      = TRUE;
  recent.gui_time_format           = TS_RELATIVE;
  recent.gui_time_precision        = TS_PREC_AUTO;
  recent.gui_seconds_format        = TS_SECONDS_DEFAULT;
  recent.gui_zoom_level            = 0;
  recent.gui_bytes_view            = 0;

  /* pane size of zero will autodetect */
  recent.gui_geometry_main_upper_pane   = 0;
  recent.gui_geometry_main_lower_pane   = 0;

  recent.has_gui_geometry_main_upper_pane = TRUE;
  recent.has_gui_geometry_main_lower_pane = TRUE;
  recent.has_gui_geometry_status_pane     = TRUE;

  if (recent.col_width_list) {
    free_col_width_info(&recent);
  }

  if (recent.gui_fileopen_remembered_dir) {
    g_free (recent.gui_fileopen_remembered_dir);
    recent.gui_fileopen_remembered_dir = NULL;
  }

  /* Construct the pathname of the user's profile recent file. */
  rf_path = get_persconffile_path(RECENT_FILE_NAME, TRUE);

  /* Read the user's recent file, if it exists. */
  *rf_path_return = NULL;
  if ((rf = ws_fopen(rf_path, "r")) != NULL) {
    /* We succeeded in opening it; read it. */
    read_prefs_file(rf_path, rf, read_set_recent_pair_static, NULL);
    fclose(rf);

    /* XXX: The following code doesn't actually do anything since
     *  the "recent common file" always exists. Presumably the
     *  "if (!file_exists())" should actually be "if (file_exists())".
     *  However, I've left the code as is because this
     *  behaviour has existed for quite some time and I don't
     *  know what's supposed to happen at this point.
     *  ToDo: Determine if the "recent common file" should be read at this point
     */
    rf_common_path = get_persconffile_path(RECENT_COMMON_FILE_NAME, FALSE);
    if (!file_exists(rf_common_path)) {
      /* Read older common settings from recent file */
      rf = ws_fopen(rf_path, "r");
      read_prefs_file(rf_path, rf, read_set_recent_common_pair_static, NULL);
      fclose(rf);
    }
    g_free(rf_common_path);
    g_free(rf_path);
    rf_path = NULL;
  } else {
    /* We failed to open it.  If we failed for some reason other than
       "it doesn't exist", return the errno and the pathname, so our
       caller can report the error. */
    if (errno != ENOENT) {
      *rf_errno_return = errno;
      *rf_path_return = rf_path;
    }
  }
}

/* opens the user's recent file and read it out */
void
recent_read_dynamic(char **rf_path_return, int *rf_errno_return)
{
  char       *rf_path;
  FILE       *rf;


  /* Construct the pathname of the user's recent common file. */
  rf_path = get_persconffile_path(RECENT_COMMON_FILE_NAME, FALSE);
  if (!file_exists (rf_path)) {
    /* Recent common file does not exist, read from default recent */
    g_free (rf_path);
    rf_path = get_persconffile_path(RECENT_FILE_NAME, FALSE);
  }

  /* Read the user's recent file, if it exists. */
  *rf_path_return = NULL;
  if ((rf = ws_fopen(rf_path, "r")) != NULL) {
    /* We succeeded in opening it; read it. */
    read_prefs_file(rf_path, rf, read_set_recent_pair_dynamic, NULL);
#if 0
    /* set dfilter combobox to have an empty line */
    dfilter_combo_add_empty();
#endif
    fclose(rf);
    g_free(rf_path);
    rf_path = NULL;
  } else {
    /* We failed to open it.  If we failed for some reason other than
       "it doesn't exist", return the errno and the pathname, so our
       caller can report the error. */
    if (errno != ENOENT) {
      *rf_errno_return = errno;
      *rf_path_return = rf_path;
    }
  }
}

gint
recent_get_column_width(gint col)
{
  GList *col_l;
  col_width_data *col_w;
  gint cfmt;
  const gchar *cfield = NULL;

  cfmt = get_column_format(col);
  if (cfmt == COL_CUSTOM) {
    cfield = get_column_custom_field(col);
  }

  col_l = g_list_first(recent.col_width_list);
  while (col_l) {
    col_w = (col_width_data *) col_l->data;
    if (col_w->cfmt == cfmt) {
      if (cfmt != COL_CUSTOM || strcmp (cfield, col_w->cfield) == 0) {
        return col_w->width;
      }
    }
    col_l = col_l->next;
  }

  return -1;
}

void
recent_set_column_width(gint col, gint width)
{
  GList *col_l;
  col_width_data *col_w;
  gint cfmt;
  const gchar *cfield = NULL;
  gboolean found = FALSE;

  cfmt = get_column_format(col);
  if (cfmt == COL_CUSTOM) {
    cfield = get_column_custom_field(col);
  }

  col_l = g_list_first(recent.col_width_list);
  while (col_l) {
    col_w = (col_width_data *) col_l->data;
    if (col_w->cfmt == cfmt) {
      if (cfmt != COL_CUSTOM || strcmp (cfield, col_w->cfield) == 0) {
        col_w->width = width;
        found = TRUE;
        break;
      }
    }
    col_l = col_l->next;
  }

  if (!found) {
    col_w = (col_width_data *) g_malloc(sizeof(col_width_data));
    col_w->cfmt = cfmt;
    if (cfield) {
      col_w->cfield = g_strdup(cfield);
    } else {
      col_w->cfield = NULL;
    }
    col_w->width = width;
    col_w->xalign = COLUMN_XALIGN_DEFAULT;
    recent.col_width_list = g_list_append(recent.col_width_list, col_w);
  }
}

gchar
recent_get_column_xalign(gint col)
{
  GList *col_l;
  col_width_data *col_w;
  gint cfmt;
  const gchar *cfield = NULL;

  cfmt = get_column_format(col);
  if (cfmt == COL_CUSTOM) {
    cfield = get_column_custom_field(col);
  }

  col_l = g_list_first(recent.col_width_list);
  while (col_l) {
    col_w = (col_width_data *) col_l->data;
    if (col_w->cfmt == cfmt) {
      if (cfmt != COL_CUSTOM || strcmp (cfield, col_w->cfield) == 0) {
        return col_w->xalign;
      }
    }
    col_l = col_l->next;
  }

  return 0;
}

void
recent_set_column_xalign(gint col, gchar xalign)
{
  GList *col_l;
  col_width_data *col_w;
  gint cfmt;
  const gchar *cfield = NULL;
  gboolean found = FALSE;

  cfmt = get_column_format(col);
  if (cfmt == COL_CUSTOM) {
    cfield = get_column_custom_field(col);
  }

  col_l = g_list_first(recent.col_width_list);
  while (col_l) {
    col_w = (col_width_data *) col_l->data;
    if (col_w->cfmt == cfmt) {
      if (cfmt != COL_CUSTOM || strcmp (cfield, col_w->cfield) == 0) {
        col_w->xalign = xalign;
        found = TRUE;
        break;
      }
    }
    col_l = col_l->next;
  }

  if (!found) {
    col_w = (col_width_data *) g_malloc(sizeof(col_width_data));
    col_w->cfmt = cfmt;
    if (cfield) {
      col_w->cfield = g_strdup(cfield);
    } else {
      col_w->cfield = NULL;
    }
    col_w->width = 40;
    col_w->xalign = xalign;
    recent.col_width_list = g_list_append(recent.col_width_list, col_w);
  }
}

/*
 * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
 *
 * Local Variables:
 * c-basic-offset: 2
 * tab-width: 8
 * indent-tabs-mode: nil
 * End:
 *
 * ex: set shiftwidth=2 tabstop=8 expandtab:
 * :indentSize=2:tabSize=8:noTabs=true:
 */