summaryrefslogtreecommitdiff
path: root/packages/konqueror/konqueror-embedded-20030705/kcookiejar-merge.patch
blob: d5c1a9a8e5bb5b31de419a4890b36ae95d0a8c3c (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
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924

#
# Patch managed by http://www.holgerschurig.de/patcher.html
#

--- konqueror-embedded-snapshot-20030705/konq-embed/kdesrc/kio/http/kcookiejar/kcookiejar.cpp~kcookiejar-merge.patch
+++ konqueror-embedded-snapshot-20030705/konq-embed/kdesrc/kio/http/kcookiejar/kcookiejar.cpp
@@ -1,8 +1,8 @@
 /* This file is part of the KDE File Manager
 
-   Copyright (C) 1998,1999,2000,2001 Waldo Bastian (bastian@kde.org)
-   Copyright (C) 2000,2001           Dawit Alemayehu (adawit@kde.org)
-   
+   Copyright (C) 1998-2000 Waldo Bastian (bastian@kde.org)
+   Copyright (C) 2000,2001 Dawit Alemayehu (adawit@kde.org)
+
    Permission is hereby granted, free of charge, to any person obtaining a copy
    of this software and associated documentation files (the "Software"), to deal
    in the Software without restriction, including without limitation the rights
@@ -22,17 +22,18 @@
 */
 //----------------------------------------------------------------------------
 //
-// KDE HTTP Cookie Manager
-// $Id: kcookiejar.cpp,v 1.58.2.5 2001/11/04 04:21:39 adawit Exp $
+// KDE File Manager -- HTTP Cookies
+// $Id: kcookiejar.cpp,v 1.117 2004/07/20 15:29:24 waba Exp $
 
 //
 // The cookie protocol is a mess. RFC2109 is a joke since nobody seems to
-// use it. Apart from that it is badly written.  We try to implement Netscape 
-// Cookies and try to behave according to RFC2109 as much as we can.
+// use it. Apart from that it is badly written.
+// We try to implement Netscape Cookies and try to behave us according to
+// RFC2109 as much as we can.
+//
+// We assume cookies do not contain any spaces (Netscape spec.)
+// According to RFC2109 this is allowed though.
 //
-// We assume cookies do not contain any spaces (Netscape spec.)  According to 
-// RFC2109 this is allowed though.
-
 
 #include <config.h>
 #include <sys/types.h>
@@ -44,12 +45,23 @@
 #include <unistd.h>
 #include <stdio.h>
 #include <string.h>
+
+#ifdef USE_SOLARIS
+#include <strings.h>
+#endif
+
 #include <stdlib.h>
 
+//#include <netinet/in.h>
+//#include <arpa/inet.h>
+
 #include <qstring.h>
 #include <qstrlist.h>
 #include <qlist.h>
 #include <qdict.h>
+#include <qfile.h>
+#include <qdir.h>
+#include <qregexp.h>
 
 #include <kurl.h>
 #include <krfcdate.h>
@@ -61,6 +73,13 @@
 
 #define READ_BUFFER_SIZE 8192
 
+// Note with respect to QString::fromLatin1( )
+// Cookies are stored as 8 bit data and passed to kio_http as
+// latin1 regardless of their actual encoding.
+
+// L1 is used to indicate latin1 constants
+#define L1(x) QString::fromLatin1(x)
+
 template class QList<KHttpCookie>;
 template class QDict<KHttpCookieList>;
 
@@ -68,10 +87,10 @@
 {
     switch( _advice )
     {
-    case KCookieAccept: return "Accept";
-    case KCookieReject: return "Reject";
-    case KCookieAsk: return "Ask";
-    default: return "Dunno";
+    case KCookieAccept: return L1("Accept");
+    case KCookieReject: return L1("Reject");
+    case KCookieAsk: return L1("Ask");
+    default: return L1("Dunno");
     }
 }
 
@@ -80,7 +99,7 @@
     if (_str.isEmpty())
         return KCookieDunno;
 
-    QString advice = _str.lower();
+    QCString advice = _str.lower().latin1();
 
     if (advice == "accept")
         return KCookieAccept;
@@ -105,17 +124,20 @@
                  const QString &_value,
                  time_t _expireDate,
                  int _protocolVersion,
-                 bool _secure) :
+                 bool _secure,
+                 bool _httpOnly,
+                 bool _explicitPath) :
        mHost(_host),
        mDomain(_domain),
-       mPath(_path),
+       mPath(_path.isEmpty() ? QString::null : _path),
        mName(_name),
        mValue(_value),
        mExpireDate(_expireDate),
        mProtocolVersion(_protocolVersion),
-       mSecure(_secure)
+       mSecure(_secure),
+       mHttpOnly(_httpOnly),
+       mExplicitPath(_explicitPath)
 {
-    nextCookie = 0;
 }
 
 //
@@ -135,16 +157,17 @@
 
     if (useDOMFormat || (mProtocolVersion == 0))
     {
-        result = mName + "=" + mValue;
+        if ( !mName.isEmpty() )
+           result = mName + '=';
+        result += mValue;
     }
     else
     {
-        result.sprintf("$Version=\"%d\"; ", mProtocolVersion);
-        result += mName + "=\"" + mValue + "\"";
-        if (!mPath.isEmpty())
-            result += "; $Path=\""+ mPath + "\"";
+        result = mName + '=' + mValue;
+        if (mExplicitPath)
+            result += L1("; $Path=\"") + mPath + L1("\"");
         if (!mDomain.isEmpty())
-            result += "; $Domain=\""+ mDomain + "\"";
+            result += L1("; $Domain=\"") + mDomain + L1("\"");
     }
     return result;
 }
@@ -157,8 +180,7 @@
     // Cookie domain match check
     if (mDomain.isEmpty())
     {
-        // No domain set, check hostname.
-        if (fqdn != mHost)
+       if (fqdn != mHost)
           return false;
     }
     else if (!domains.contains(mDomain))
@@ -167,17 +189,30 @@
             return false;
 
         // Maybe the domain needs an extra dot.
-        QString domain = "." + mDomain;
+        QString domain = '.' + mDomain;
         if ( !domains.contains( domain ) )
           if ( fqdn != mDomain )
             return false;
     }
 
     // Cookie path match check
-    if( !path.isEmpty() && !path.startsWith(mPath) )
-        return false; // Path of URL does not start with cookie-path
+    if (mPath.isEmpty())
+        return true;
 
-    return true;
+    // According to the netscape spec both http://www.acme.com/foobar,
+    // http://www.acme.com/foo.bar and http://www.acme.com/foo/bar
+    // match http://www.acme.com/foo.
+    // We only match http://www.acme.com/foo/bar
+
+    if( path.startsWith(mPath) &&
+        (
+         (path.length() == mPath.length() ) || 	// Paths are exact match
+         (path[mPath.length()-1] == '/') || 	// mPath ended with a slash
+         (path[mPath.length()] == '/')		// A slash follows.
+         ))
+        return true; // Path of URL starts with cookie-path
+
+    return false;
 }
 
 // KHttpCookieList
@@ -188,9 +223,9 @@
     int pathLen1 = ((KHttpCookie *)item1)->path().length();
     int pathLen2 = ((KHttpCookie *)item2)->path().length();
     if (pathLen1 > pathLen2)
-        return 1;
-    if (pathLen1 < pathLen2)
         return -1;
+    if (pathLen1 < pathLen2)
+        return 1;
     return 0;
 }
 
@@ -205,10 +240,18 @@
 //
 KCookieJar::KCookieJar()
 {
-    cookieDomains.setAutoDelete( true );
-    globalAdvice = KCookieDunno;
-    configChanged = false;
-    cookiesChanged = false;
+    m_cookieDomains.setAutoDelete( true );
+    m_globalAdvice = KCookieDunno;
+    m_configChanged = false;
+    m_cookiesChanged = false;
+
+    QString twoLevelTLD="name,ai,au,bd,bh,ck,eg,et,fk,il,in,kh,kr,mk,mt,na,np,nz,pg,pk,qa,sa,sb,sg,sv,ua,ug,uk,uy,vn,za,zw";
+    QStringList countries = QStringList::split(',', twoLevelTLD);
+    for(QStringList::ConstIterator it = countries.begin();
+        it != countries.end(); ++it)
+    {
+       m_twoLevelTLD.replace(*it, (int *) 1);
+    }
 }
 
 //
@@ -221,89 +264,184 @@
     // Not much to do here
 }
 
+static void removeDuplicateFromList(KHttpCookieList *list, KHttpCookie *cookiePtr, bool nameMatchOnly=false, bool updateWindowId=false)
+{
+    QString domain1 = cookiePtr->domain();
+    if (domain1.isEmpty())
+       domain1 = cookiePtr->host();
+
+    for ( KHttpCookiePtr cookie=list->first(); cookie != 0; )
+    {
+       QString domain2 = cookie->domain();
+       if (domain2.isEmpty())
+          domain2 = cookie->host();
+
+       if (
+            (cookiePtr->name() == cookie->name()) &&
+            (
+              nameMatchOnly ||
+              ( (domain1 == domain2) && (cookiePtr->path() == cookie->path()) )
+            )
+          )
+       {
+          if (updateWindowId)
+          {
+            for(QValueList<long>::ConstIterator it = cookie->windowIds().begin();
+                it != cookie->windowIds().end(); ++it)
+            {
+               long windowId = *it;
+               if (windowId && (cookiePtr->windowIds().find(windowId) == cookiePtr->windowIds().end()))
+               {
+                  cookiePtr->windowIds().append(windowId);
+               }
+            }
+          }
+          KHttpCookiePtr old_cookie = cookie;
+          cookie = list->next();
+          list->removeRef( old_cookie );
+          break;
+       }
+       else
+       {
+          cookie = list->next();
+       }
+    }
+}
+
+
 //
 // Looks for cookies in the cookie jar which are appropriate for _url.
 // Returned is a string containing all appropriate cookies in a format
 // which can be added to a HTTP-header without any additional processing.
 //
-QString KCookieJar::findCookies(const QString &_url, bool useDOMFormat)
+QString KCookieJar::findCookies(const QString &_url, bool useDOMFormat, long windowId, KHttpCookieList *pendingCookies)
 {
     QString cookieStr;
     QStringList domains;
     QString fqdn;
     QString path;
     KHttpCookiePtr cookie;
-    int protVersion = 1;
-    int cookieCount = 0;
+    KCookieAdvice advice = m_globalAdvice;
 
     if (!parseURL(_url, fqdn, path))
-    {
         return cookieStr;
-    }
+
+    bool secureRequest = (_url.find( L1("https://"), 0, false) == 0 ||
+                          _url.find( L1("webdavs://"), 0, false) == 0);
 
     extractDomains(fqdn, domains);
-    bool secureRequest = (_url.find( "https://", 0, false) == 0);
+
+    KHttpCookieList allCookies;
+
     for(QStringList::ConstIterator it = domains.begin();
-        it != domains.end();
+        true;
         ++it)
     {
-       KHttpCookieList *cookieList = cookieDomains[(*it)]; 
+       KHttpCookieList *cookieList;
+       if (it == domains.end())
+       {
+          cookieList = pendingCookies; // Add pending cookies
+          pendingCookies = 0;
+          if (!cookieList)
+             break;
+       }
+       else
+       {
+          QString key = (*it).isNull() ? L1("") : (*it);
+          cookieList = m_cookieDomains[key];
+          if (!cookieList)
+             continue; // No cookies for this domain
+       }
 
-       if (!cookieList)
-          continue; // No cookies for this domain
+       if (cookieList->getAdvice() != KCookieDunno)
+          advice = cookieList->getAdvice();
+
+       // Do not send cookies for this domain if policy is set to reject
+       // and we are not setup to automatically accept all cookies as
+       // session cookies...
+       if (advice == KCookieReject &&
+           !(m_ignoreCookieExpirationDate && m_autoAcceptSessionCookies))
+       {
+          if (it == domains.end())
+             break; // Finished.
+          continue;
+       }
 
        for ( cookie=cookieList->first(); cookie != 0; cookie=cookieList->next() )
        {
-          if (!cookie->match(fqdn, domains, path) && cookie->domain().isEmpty())
-          {
-              // The following code is added because RFC 2109 is completely
-              // ambigious when it comes what needs to be done when cookies
-              // with empty "domain=" fields are present! The following code
-              // makes such cookies available to all the domains/hosts under
-              // the TLD of the cookie in question!
-             QStringList cookieDomainList;
-             extractDomains( cookie->host(), cookieDomainList );
-             
-             int fqdnCount = domains.count();             
-             int cookieDomainCount = cookieDomainList.count();
-             
-             if ( domains[fqdnCount-2] != cookieDomainList[cookieDomainCount-2] &&
-                  domains[fqdnCount-1] != cookieDomainList[cookieDomainCount-1] )
-                continue;
-          }
+          if (!cookie->match(fqdn, domains, path))
+             continue;
 
           if( cookie->isSecure() && !secureRequest )
              continue;
 
-          // Use first cookie to determine protocol version
-          if (cookieCount == 0)
+          if( cookie->isHttpOnly() && useDOMFormat )
+             continue;
+
+          // Do not send expired cookies.
+          if ( cookie->isExpired (time(0)) )
           {
-             protVersion = cookie->protocolVersion();
+             // Note there is no need to actually delete the cookie here
+             // since the cookieserver will invoke ::saveCookieJar because
+             // of the state change below. This will then do the job of
+             // deleting the cookie for us.
+             m_cookiesChanged = true;
+             continue;
           }
-          if (useDOMFormat)
+
+          if (windowId && (cookie->windowIds().find(windowId) == cookie->windowIds().end()))
           {
-             if (cookieCount > 0)
-                cookieStr += "; ";
-             cookieStr += cookie->cookieStr(true);
+             cookie->windowIds().append(windowId);
           }
-          else if (protVersion == 0)
+
+          if (it == domains.end()) // Only needed when processing pending cookies
+             removeDuplicateFromList(&allCookies, cookie);
+
+          allCookies.append(cookie);
+       }
+       if (it == domains.end())
+          break; // Finished.
+    }
+
+
+    int cookieCount = 0;
+
+    int protVersion=0;
+    for ( cookie=allCookies.first(); cookie != 0; cookie=allCookies.next() )
+    {
+       if (cookie->protocolVersion() > protVersion)
+          protVersion = cookie->protocolVersion();
+    }
+
+    for ( cookie=allCookies.first(); cookie != 0; cookie=allCookies.next() )
+    {
+       if (useDOMFormat)
+       {
+          if (cookieCount > 0)
+             cookieStr += L1("; ");
+          cookieStr += cookie->cookieStr(true);
+       }
+       else
+       {
+          if (cookieCount == 0)
           {
-             if (cookieCount == 0)
-                cookieStr += "Cookie: ";
-             else
-                cookieStr += "; ";
-             cookieStr += cookie->cookieStr(false);
+             cookieStr += L1("Cookie: ");
+             if (protVersion > 0)
+             {
+                QString version;
+                version.sprintf("$Version=%d; ", protVersion); // Without quotes
+                cookieStr += version;
+             }
           }
           else
           {
-             if (cookieCount > 0)
-                cookieStr += "\r\n";
-             cookieStr += "Cookie: ";
-             cookieStr += cookie->cookieStr(false);
+             cookieStr += L1("; ");
           }
-          cookieCount++;
+          cookieStr += cookie->cookieStr(false);
        }
+       cookieCount++;
     }
+
     return cookieStr;
 }
 
@@ -323,17 +461,17 @@
                                   bool keepQuotes=false)
 {
     const char *s = header;
-
     // Parse 'my_name' part
     for(; (*s != '='); s++)
     {
         if ((*s=='\0') || (*s==';') || (*s=='\n'))
         {
-            // End of Name
-            Value = "";
-            Name = header;
-            Name.truncate( s - header );
-            Name = Name.stripWhiteSpace();
+            // No '=' sign -> use string as the value, name is empty
+            // (behavior found in Mozilla and IE)
+            Name = "";
+            Value = QString::fromLatin1(header);
+            Value.truncate( s - header );
+            Value = Value.stripWhiteSpace();
             return (s);
         }
     }
@@ -366,12 +504,12 @@
             if ((*s=='\0') || (*s=='\n'))
             {
                 // End of Name
-                Value = header;
+                Value = QString::fromLatin1(header);
                 Value.truncate(s - header);
                 return (s);
             }
         }
-        Value = header;
+        Value = QString::fromLatin1(header);
         Value.truncate( s - header );
 
         // *s == '\"';
@@ -390,7 +528,7 @@
         while ((*s != '\0') && (*s != ';') && (*s != '\n'))
             s++;
         // End of Name
-        Value = header;
+        Value = QString::fromLatin1(header);
         Value.truncate( s - header );
         Value = Value.stripWhiteSpace();
     }
@@ -398,14 +536,14 @@
 
 }
 
-static void stripDomain(const QString &_fqdn, QString &_domain)
+void KCookieJar::stripDomain(const QString &_fqdn, QString &_domain)
 {
    QStringList domains;
-   KCookieJar::extractDomains(_fqdn, domains);
+   extractDomains(_fqdn, domains);
    _domain = domains[0];
 }
 
-static QString stripDomain( KHttpCookiePtr cookiePtr)
+QString KCookieJar::stripDomain( KHttpCookiePtr cookiePtr)
 {
     QString domain; // We file the cookie under this domain.
     if (cookiePtr->domain().isEmpty())
@@ -420,10 +558,18 @@
                           QString &_path)
 {
     KURL kurl(_url);
-    if (kurl.isMalformed())
+    if (!kurl.isValid())
        return false;
 
     _fqdn = kurl.host().lower();
+    if (kurl.port())
+    {
+       if (((kurl.protocol() == L1("http")) && (kurl.port() != 80)) ||
+           ((kurl.protocol() == L1("https")) && (kurl.port() != 443)))
+       {
+          _fqdn = L1("%1:%2").arg(kurl.port()).arg(_fqdn);
+       }
+    }
 
     // Cookie spoofing protection.  Since there is no way a path separator
     // or escape encoded character is allowed in the hostname according
@@ -435,19 +581,44 @@
 
     _path = kurl.path();
     if (_path.isEmpty())
-       _path = "/";
+       _path = L1("/");
+
+    QRegExp exp(L1("[\\\\/]\\.\\.[\\\\/]"));
+    // Weird path, cookie stealing attempt?
+    if (_path.find(exp) != -1) {
+       return false; // Deny everything!!
+    }
+
     return true;
 }
 
 void KCookieJar::extractDomains(const QString &_fqdn,
                                 QStringList &_domains)
 {
-    // Use fqdn only if the fqdn consists of numbers.
-    if ((_fqdn[0] >= '0') && (_fqdn[0] <= '9'))
+    // Return numeric IPv6 addresses as is...
+    if (_fqdn[0] == '[')
     {
        _domains.append( _fqdn );
        return;
     }
+    // Return numeric IPv4 addresses as is...
+    if ((_fqdn[0] >= '0') && (_fqdn[0] <= '9'))
+    {
+       bool allNumeric = true;
+       for(int i = _fqdn.length(); i--;)
+       {
+          if (!strchr("0123456789:.", _fqdn[i].latin1()))
+          {
+             allNumeric = false;
+             break;
+          }
+       }
+       if (allNumeric)
+       {
+          _domains.append( _fqdn );
+          return;
+       }
+    }
 
     QStringList partList = QStringList::split('.', _fqdn, false);
 
@@ -458,29 +629,36 @@
     {
        if (partList.count() == 1)
          break; // We only have a TLD left.
-       if (partList.count() == 2)
+
+       if ((partList.count() == 2) && (m_twoLevelTLD[partList[1].lower()]))
+       {
+          // This domain uses two-level TLDs in the form xxxx.yy
+          break;
+       }
+
+       if ((partList.count() == 2) && (partList[1].length() == 2))
        {
           // If this is a TLD, we should stop. (e.g. co.uk)
           // We assume this is a TLD if it ends with .xx.yy or .x.yy
-          if ((partList[0].length() <= 2) &&
-              (partList[1].length() == 2))
+          if (partList[0].length() <= 2)
              break; // This is a TLD.
+
+          // Catch some TLDs that we miss with the previous check
+          // e.g. com.au, org.uk, mil.co
+          QCString t = partList[0].lower().utf8();
+          if ((t == "com") || (t == "net") || (t == "org") || (t == "gov") || (t == "edu") || (t == "mil") || (t == "int"))
+              break;
        }
-       QString domain = partList.join(".");
-       _domains.append("." + domain);
+
+       QString domain = partList.join(L1("."));
+       _domains.append('.' + domain);
        _domains.append(domain);
        partList.remove(partList.begin()); // Remove part
     }
 
-    // Only URLs that would get in here are of type
-    // "host.foo" or "host.co.fo" so simply append
-    // a '.' on top to make sure they are stored under
-    // the proper cookie domain.
-    if (_domains.isEmpty())
-       _domains.append( "." + _fqdn );
-
     // Always add the FQDN at the end of the list for
     // hostname == cookie-domainname checks!
+    _domains.append( '.' + _fqdn );
     _domains.append( _fqdn );
 }
 
@@ -492,55 +670,73 @@
 // cookie_headers should be a concatenation of all lines of a HTTP-header
 // which start with "Set-Cookie". The lines should be separated by '\n's.
 //
-KHttpCookiePtr KCookieJar::makeCookies(const QString &_url,
+KHttpCookieList KCookieJar::makeCookies(const QString &_url,
                                        const QCString &cookie_headers,
                                        long windowId)
 {
-    KHttpCookiePtr cookieChain = 0;
+    KHttpCookieList cookieList;
+    KHttpCookieList cookieList2;
     KHttpCookiePtr lastCookie = 0;
     const char *cookieStr = cookie_headers.data();
     QString Name;
     QString Value;
     QString fqdn;
     QString path;
+    bool crossDomain = false;
 
     if (!parseURL(_url, fqdn, path))
     {
         // Error parsing _url
-        return 0;
+        return KHttpCookieList();
     }
+    QString defaultPath;
+    int i = path.findRev('/');
+    if (i > 0)
+       defaultPath = path.left(i);
 
     //  The hard stuff :)
     for(;;)
     {
         // check for "Set-Cookie"
-        if (strncasecmp(cookieStr, "Set-Cookie:", 11) == 0)
+        if (strncmp(cookieStr, "Cross-Domain\n", 13) == 0)
+        {
+            cookieStr += 13;
+            crossDomain = true;
+        }
+        else if (strncasecmp(cookieStr, "Set-Cookie:", 11) == 0)
         {
             cookieStr = parseNameValue(cookieStr+11, Name, Value, true);
 
-            if (Name.isEmpty())
-                continue;
-
             // Host = FQDN
             // Default domain = ""
-            // Default path = ""
-            KHttpCookie *cookie = new KHttpCookie(fqdn, "", "", Name, Value);
-            cookie->mWindowId = windowId;
+            // Default path according to rfc2109
+
+            KHttpCookie *cookie = new KHttpCookie(fqdn, L1(""), defaultPath, Name, Value);
+            if (windowId)
+               cookie->mWindowIds.append(windowId);
+            cookie->mCrossDomain = crossDomain;
 
             // Insert cookie in chain
-            if (lastCookie)
-               lastCookie->nextCookie = cookie;
-            else
-               cookieChain = cookie;
+            cookieList.append(cookie);
             lastCookie = cookie;
         }
-        else if (lastCookie && (strncasecmp(cookieStr, "Set-Cookie2:", 12) == 0))
+        else if (strncasecmp(cookieStr, "Set-Cookie2:", 12) == 0)
         {
-            // What the fuck is this?
-            // Does anyone invent his own headers these days?
-            // Read the fucking RFC guys! This header is not there!
-            cookieStr +=12;
-            // Continue with lastCookie
+            // Attempt to follow rfc2965
+            cookieStr = parseNameValue(cookieStr+12, Name, Value, true);
+
+            // Host = FQDN
+            // Default domain = ""
+            // Default path according to rfc2965
+
+            KHttpCookie *cookie = new KHttpCookie(fqdn, L1(""), defaultPath, Name, Value);
+            if (windowId)
+               cookie->mWindowIds.append(windowId);
+            cookie->mCrossDomain = crossDomain;
+
+            // Insert cookie in chain
+            cookieList2.append(cookie);
+            lastCookie = cookie;
         }
         else
         {
@@ -564,13 +760,12 @@
             // Name-Value pair follows
             cookieStr = parseNameValue(cookieStr, Name, Value);
 
-            Name = Name.lower();
-
-            if (Name == "domain")
+            QCString cName = Name.lower().latin1();
+            if (cName == "domain")
             {
                 lastCookie->mDomain = Value.lower();
             }
-            else if (Name == "max-age")
+            else if (cName == "max-age")
             {
                 int max_age = Value.toInt();
                 if (max_age == 0)
@@ -578,23 +773,33 @@
                 else
                     lastCookie->mExpireDate = time(0)+max_age;
             }
-            else if (Name == "expires")
+            else if (cName == "expires")
             {
                 // Parse brain-dead netscape cookie-format
                 lastCookie->mExpireDate = KRFCDate::parseDate(Value);
             }
-            else if (Name == "path")
+            else if (cName == "path")
             {
-                lastCookie->mPath = Value;
+                if (Value.isEmpty())
+                   lastCookie->mPath = QString::null; // Catch "" <> QString::null
+                else
+                   lastCookie->mPath = KURL::decode_string(Value);
+                lastCookie->mExplicitPath = true;
             }
-            else if (Name == "version")
+            else if (cName == "version")
             {
                 lastCookie->mProtocolVersion = Value.toInt();
             }
-            else if (Name == "secure")
+            else if ((cName == "secure") ||
+                     (cName.isEmpty() && Value.lower() == L1("secure")))
             {
                 lastCookie->mSecure = true;
             }
+            else if ((cName == "httponly") ||
+                     (cName.isEmpty() && Value.lower() == L1("httponly")))
+            {
+                lastCookie->mHttpOnly = true;
+            }
         }
 
         if (*cookieStr == '\0')
@@ -604,7 +809,14 @@
         cookieStr++;
     }
 
-    return cookieChain;
+    // RFC2965 cookies come last so that they override netscape cookies.
+    while( !cookieList2.isEmpty() && (lastCookie = cookieList2.take(0)) )
+    {
+       removeDuplicateFromList(&cookieList, lastCookie, true);
+       cookieList.append(lastCookie);
+    }
+
+    return cookieList;
 }
 
 /**
@@ -613,12 +825,12 @@
 * pairs. Any whitespace before "name" or around '=' is discarded.
 * If no cookies are found, 0 is returned.
 */
-KHttpCookiePtr KCookieJar::makeDOMCookies(const QString &_url,
+KHttpCookieList KCookieJar::makeDOMCookies(const QString &_url,
                                           const QCString &cookie_domstring,
                                           long windowId)
 {
     // A lot copied from above
-    KHttpCookiePtr cookieChain = 0;
+    KHttpCookieList cookieList;
     KHttpCookiePtr lastCookie = 0;
 
     const char *cookieStr = cookie_domstring.data();
@@ -630,7 +842,7 @@
     if (!parseURL(_url, fqdn, path))
     {
         // Error parsing _url
-        return 0;
+        return KHttpCookieList();
     }
 
     //  This time it's easy
@@ -638,35 +850,25 @@
     {
         cookieStr = parseNameValue(cookieStr, Name, Value);
 
-        if (Name.isEmpty()) {
-            if (*cookieStr != '\0')
-                cookieStr++;         // Skip ';' or '\n'
-
-            continue;
-        }
-
         // Host = FQDN
         // Default domain = ""
         // Default path = ""
         KHttpCookie *cookie = new KHttpCookie(fqdn, QString::null, QString::null,
                                 Name, Value );
-        cookie->mWindowId = windowId;
-
-        // Insert cookie in chain
-        if (lastCookie)
-            lastCookie->nextCookie = cookie;
-        else
-            cookieChain = cookie;
+        if (windowId)
+            cookie->mWindowIds.append(windowId);
 
+        cookieList.append(cookie);
         lastCookie = cookie;
 
         if (*cookieStr != '\0')
             cookieStr++;         // Skip ';' or '\n'
      }
 
-     return cookieChain;
+     return cookieList;
 }
 
+
 //
 // This function hands a KHttpCookie object over to the cookie jar.
 //
@@ -674,7 +876,6 @@
 //
 void KCookieJar::addCookie(KHttpCookiePtr &cookiePtr)
 {
-    QString domain;
     QStringList domains;
     KHttpCookieList *cookieList = 0L;
 
@@ -686,42 +887,31 @@
           (it != domains.end() && !cookieList);
           ++it )
     {
-        KHttpCookieList *list= cookieDomains[(*it)];
+        QString key = (*it).isNull() ? L1("") : (*it);
+        KHttpCookieList *list= m_cookieDomains[key];
         if ( !list ) continue;
 
-        for ( KHttpCookiePtr cookie=list->first(); cookie != 0; )
-        {
-            if ( cookiePtr->name() == cookie->name() &&
-                 cookie->match(cookiePtr->host(),domains,cookiePtr->path()) )
-            {
-                KHttpCookiePtr old_cookie = cookie;
-                cookie = list->next();
-                list->removeRef( old_cookie );
-                break;
-            }
-            else
-            {
-                cookie = list->next();
-            }
-        }
+        removeDuplicateFromList(list, cookiePtr, false, true);
     }
 
-    domain = stripDomain( cookiePtr );
-    cookieList = cookieDomains[ domain ];
+    QString domain = stripDomain( cookiePtr );
+    QString key = domain.isNull() ? L1("") : domain;
+    cookieList = m_cookieDomains[ key ];
     if (!cookieList)
     {
         // Make a new cookie list
         cookieList = new KHttpCookieList();
+        cookieList->setAutoDelete(true);
 
         // All cookies whose domain is not already
         // known to us should be added with KCookieDunno.
         // KCookieDunno means that we use the global policy.
         cookieList->setAdvice( KCookieDunno );
 
-        cookieDomains.insert( domain, cookieList);
+        m_cookieDomains.insert( domain, cookieList);
 
         // Update the list of domains
-        domainList.append(domain);
+        m_domainList.append(domain);
     }
 
     // Add the cookie to the cookie list
@@ -729,7 +919,7 @@
     if (!cookiePtr->isExpired(time(0)))
     {
         cookieList->inSort( cookiePtr );
-        cookiesChanged = true;
+        m_cookiesChanged = true;
     }
     else
     {
@@ -745,12 +935,20 @@
 KCookieAdvice KCookieJar::cookieAdvice(KHttpCookiePtr cookiePtr)
 {
     QStringList domains;
+
+    if (m_rejectCrossDomainCookies && cookiePtr->isCrossDomain())
+       return KCookieReject;
+
+    if (m_autoAcceptSessionCookies && (cookiePtr->expireDate() == 0 ||
+        m_ignoreCookieExpirationDate))
+       return KCookieAccept;
+
     extractDomains(cookiePtr->host(), domains);
-    bool isEmptyDomain = cookiePtr->domain().isEmpty();
 
-    if (!isEmptyDomain )
+    // If the cookie specifies a domain, check whether it is valid and
+    // correct otherwise.
+    if (!cookiePtr->domain().isEmpty())
     {
-       // Cookie specifies a domain. Check whether it is valid.
        bool valid = false;
 
        // This checks whether the cookie is valid based on
@@ -764,42 +962,34 @@
        if (!valid)
        {
           // Maybe the domain doesn't start with a "."
-          QString domain = "."+cookiePtr->domain();
+          QString domain = '.' + cookiePtr->domain();
           if (domains.contains(domain))
              valid = true;
        }
 
        if (!valid)
        {
-          qWarning("WARNING: Host %s tries to set cookie for domain %s",
-                    cookiePtr->host().latin1(), cookiePtr->domain().latin1());
           cookiePtr->fixDomain(QString::null);
-          isEmptyDomain = true;
        }
     }
 
-    // For empty domain use the FQDN to find a
-    // matching advice for the pending cookie.
-    QString domain;
-    if ( isEmptyDomain )
-       domain = domains[0];
-    else
-       domain = cookiePtr->domain();
+    KCookieAdvice advice = KCookieDunno;
 
-    KHttpCookieList *cookieList = cookieDomains[domain];
-    KCookieAdvice advice;
-    if (cookieList)
-    {
-        advice = cookieList->getAdvice();
-        if (advice == KCookieDunno)
-        {
-           advice = globalAdvice;
-        }
-    }
-    else
+    QStringList::Iterator it = domains.fromLast(); // Start with FQDN which is last in the list.
+    while( (advice == KCookieDunno) && (it != domains.end()))
     {
-        advice = globalAdvice;
+       QString domain = *it;
+       // Check if a policy for the FQDN/domain is set.
+       KHttpCookieList *cookieList = m_cookieDomains[domain];
+       if (cookieList)
+          advice = cookieList->getAdvice();
+       domains.remove(it);
+       it = domains.begin(); // Continue from begin of remaining list
     }
+
+    if (advice == KCookieDunno)
+        advice = m_globalAdvice;
+
     return advice;
 }
 
@@ -809,7 +999,7 @@
 //
 KCookieAdvice KCookieJar::getDomainAdvice(const QString &_domain)
 {
-    KHttpCookieList *cookieList = cookieDomains[_domain];
+    KHttpCookieList *cookieList = m_cookieDomains[_domain];
     KCookieAdvice advice;
 
     if (cookieList)
@@ -831,13 +1021,13 @@
 void KCookieJar::setDomainAdvice(const QString &_domain, KCookieAdvice _advice)
 {
     QString domain(_domain);
-    KHttpCookieList *cookieList = cookieDomains[domain];
+    KHttpCookieList *cookieList = m_cookieDomains[domain];
 
     if (cookieList)
     {
-        if (cookieList->getAdvice() != _advice);
+        if (cookieList->getAdvice() != _advice)
         {
-           configChanged = true;
+           m_configChanged = true;
            // domain is already known
            cookieList->setAdvice( _advice);
         }
@@ -846,8 +1036,8 @@
             (_advice == KCookieDunno))
         {
             // This deletes cookieList!
-            cookieDomains.remove(domain);			
-            domainList.remove(domain);
+            m_cookieDomains.remove(domain);
+            m_domainList.remove(domain);
         }
     }
     else
@@ -856,13 +1046,14 @@
         if (_advice != KCookieDunno)
         {
             // We should create a domain entry
-            configChanged = true;
+            m_configChanged = true;
             // Make a new cookie list
             cookieList = new KHttpCookieList();
+            cookieList->setAutoDelete(true);
             cookieList->setAdvice( _advice);
-            cookieDomains.insert( domain, cookieList);
+            m_cookieDomains.insert( domain, cookieList);
             // Update the list of domains
-            domainList.append( domain);
+            m_domainList.append( domain);
         }
     }
 }
@@ -883,9 +1074,9 @@
 //
 void KCookieJar::setGlobalAdvice(KCookieAdvice _advice)
 {
-    if (globalAdvice != _advice)
-       configChanged = true;
-    globalAdvice = _advice;
+    if (m_globalAdvice != _advice)
+       m_configChanged = true;
+    m_globalAdvice = _advice;
 }
 
 //
@@ -893,7 +1084,7 @@
 //
 const QStringList& KCookieJar::getDomainList()
 {
-    return domainList;
+    return m_domainList;
 }
 
 //
@@ -909,7 +1100,7 @@
     else
         domain = _domain;
 
-    return cookieDomains[domain];
+    return m_cookieDomains[domain];
 }
 
 //
@@ -919,86 +1110,97 @@
 void KCookieJar::eatCookie(KHttpCookiePtr cookiePtr)
 {
     QString domain = stripDomain(cookiePtr); // We file the cookie under this domain.
-    KHttpCookieList *cookieList = cookieDomains[domain];
+    KHttpCookieList *cookieList = m_cookieDomains[domain];
 
     if (cookieList)
     {
         // This deletes cookiePtr!
         if (cookieList->removeRef( cookiePtr ))
-           cookiesChanged = true;
+           m_cookiesChanged = true;
 
         if ((cookieList->isEmpty()) &&
             (cookieList->getAdvice() == KCookieDunno))
         {
             // This deletes cookieList!
-            cookieDomains.remove(domain);
+            m_cookieDomains.remove(domain);
 
-            domainList.remove(domain);
+            m_domainList.remove(domain);
         }
     }
 }
 
 void KCookieJar::eatCookiesForDomain(const QString &domain)
 {
-   KHttpCookieList *cookieList = cookieDomains[domain];
+   KHttpCookieList *cookieList = m_cookieDomains[domain];
    if (!cookieList || cookieList->isEmpty()) return;
 
    cookieList->clear();
    if (cookieList->getAdvice() == KCookieDunno)
    {
        // This deletes cookieList!
-       cookieDomains.remove(domain);
-       domainList.remove(domain);
+       m_cookieDomains.remove(domain);
+       m_domainList.remove(domain);
    }
-   cookiesChanged = true;
+   m_cookiesChanged = true;
 }
 
-void KCookieJar::eatSessionCookies( int winId )
+void KCookieJar::eatSessionCookies( long windowId )
 {
-    QStringList::Iterator it=domainList.begin();
-    for ( ; it != domainList.end(); ++it )
-        eatSessionCookies( *it, winId, false );
+    if (!windowId)
+        return;
+
+    QStringList::Iterator it=m_domainList.begin();
+    for ( ; it != m_domainList.end(); ++it )
+        eatSessionCookies( *it, windowId, false );
 }
 
-void KCookieJar::eatSessionCookies( const QString& fqdn, int winId,
+void KCookieJar::eatAllCookies()
+{
+    for ( QStringList::Iterator it=m_domainList.begin();
+          it != m_domainList.end();)
+    {
+        QString domain = *it++;
+        // This might remove domain from domainList!
+        eatCookiesForDomain(domain);
+    }
+}
+
+void KCookieJar::eatSessionCookies( const QString& fqdn, long windowId,
                                     bool isFQDN )
 {
     KHttpCookieList* cookieList;
-    if ( isFQDN )
+    if ( !isFQDN )
+        cookieList = m_cookieDomains[fqdn];
+    else
     {
         QString domain;
         stripDomain( fqdn, domain );
-        cookieList = cookieDomains[domain];
+        cookieList = m_cookieDomains[domain];
     }
-    else
-        cookieList = cookieDomains[fqdn];
 
     if ( cookieList )
     {
         KHttpCookiePtr cookie=cookieList->first();
         for (; cookie != 0;)
         {
-            if (cookie->windowId() == winId &&
-                (cookie->expireDate() == 0))
+            if ((cookie->expireDate() != 0) && !m_ignoreCookieExpirationDate)
             {
-                KHttpCookiePtr old_cookie = cookie;
-                cookie = cookieList->next();
-                cookieList->removeRef( old_cookie );
+               cookie = cookieList->next();
+               continue;
             }
-            else
-                cookie = cookieList->next();
-        }
-    }
-}
-
 
-void KCookieJar::eatAllCookies()
-{
-    for ( QStringList::Iterator it=domainList.begin();
-          it != domainList.end();)
-    {
-        QString domain = *it++;
-        eatCookiesForDomain(domain); // This might remove domain from domainList!
+            QValueList<long> &ids = cookie->windowIds();
+	    bool empty = (ids.find(windowId) == ids.end() );
+	    ids.remove(windowId);
+            if (!empty || !ids.isEmpty())
+            {
+               cookie = cookieList->next();
+               continue;
+            }
+            KHttpCookiePtr old_cookie = cookie;
+            cookie = cookieList->next();
+            cookieList->removeRef( old_cookie );
+        }
     }
 }
 
@@ -1008,7 +1210,7 @@
 // On failure 'false' is returned.
 bool KCookieJar::saveCookies(const QString &_filename)
 {
-    KSaveFile saveFile(_filename);
+    KSaveFile saveFile(_filename, 0600);
 
     if (saveFile.status() != 0)
        return false;
@@ -1017,31 +1219,31 @@
 
     time_t curTime = time(0);
 
-    fprintf(fStream, "# KDE Cookie File\n#\n");
+    fprintf(fStream, "# KDE Cookie File v2\n#\n");
 
-    fprintf(fStream, "%-20s %-20s %-12s %-9s %-4s %-10s %s %-4s\n",
-    	"# Host", "Domain", "Path", "Exp.date", "Prot", "Name", "Value", "Secure");
+    fprintf(fStream, "%-20s %-20s %-12s %-10s %-4s %-20s %-4s %s\n",
+                     "# Host", "Domain", "Path", "Exp.date", "Prot",
+                     "Name", "Sec", "Value");
 
-    for ( QStringList::Iterator it=domainList.begin();
-    	  it != domainList.end();
-    	  it++)
+    for ( QStringList::Iterator it=m_domainList.begin(); it != m_domainList.end();
+          it++ )
     {
         const QString &domain = *it;
         bool domainPrinted = false;
 
-	KHttpCookieList *cookieList = cookieDomains[domain];
+        KHttpCookieList *cookieList = m_cookieDomains[domain];
         KHttpCookiePtr cookie=cookieList->first();
 
-	for (; cookie != 0;)
+        for (; cookie != 0;)
         {
             if (cookie->isExpired(curTime))
-	    {
-	    	// Delete expired cookies
+            {
+                // Delete expired cookies
                 KHttpCookiePtr old_cookie = cookie;
                 cookie = cookieList->next();
                 cookieList->removeRef( old_cookie );
-	    }
-	    else if (cookie->expireDate() != 0)
+            }
+            else if (cookie->expireDate() != 0 && !m_ignoreCookieExpirationDate)
             {
                 if (!domainPrinted)
                 {
@@ -1049,25 +1251,26 @@
                     fprintf(fStream, "[%s]\n", domain.local8Bit().data());
                 }
                 // Store persistent cookies
-                QString path("\"");
+                QString path = L1("\"");
                 path += cookie->path();
-                path += "\"";
-                QString domain("\"");
+                path += '"';
+                QString domain = L1("\"");
                 domain += cookie->domain();
-                domain += "\"";
-                fprintf(fStream, "%-20s %-20s %-12s %9lu   %2d %-10s %s %-4i\n",
-		    cookie->host().local8Bit().data(), domain.local8Bit().data(), path.local8Bit().data(),
-		    (unsigned long) cookie->expireDate(), cookie->protocolVersion()+100,
-		    cookie->name().local8Bit().data(), cookie->value().local8Bit().data(),
-		    cookie->isSecure());
-		cookie = cookieList->next();
-	    }
-	    else
-	    {
-	    	// Skip session-only cookies
-		cookie = cookieList->next();
-	    }
-	}
+                domain += '"';
+                fprintf(fStream, "%-20s %-20s %-12s %10lu  %3d %-20s %-4i %s\n",
+                        cookie->host().latin1(), domain.latin1(),
+                        path.latin1(), (unsigned long) cookie->expireDate(),
+                        cookie->protocolVersion(), cookie->name().latin1(),
+                        (cookie->isSecure() ? 1 : 0) + (cookie->isHttpOnly() ? 2 : 0) + (cookie->hasExplicitPath() ? 4 : 0),
+                        cookie->value().latin1());
+                cookie = cookieList->next();
+            }
+            else
+            {
+                // Skip session-only cookies
+                cookie = cookieList->next();
+            }
+        }
     }
 
     return saveFile.close();
@@ -1080,26 +1283,27 @@
     char *result;
     if (!keepQuotes && (*buffer == '\"'))
     {
-    	// Find terminating "
+        // Find terminating "
         buffer++;
         result = buffer;
         while((*buffer != '\"') && (*buffer))
-    	    buffer++;
+            buffer++;
     }
     else
     {
         // Find first white space
         result = buffer;
         while((*buffer != ' ') && (*buffer != '\t') && (*buffer != '\n') && (*buffer))
-    	    buffer++;
+            buffer++;
     }
+
     if (!*buffer)
-    	return result; //
+        return result; //
     *buffer++ = '\0';
 
     // Skip white-space
     while((*buffer == ' ') || (*buffer == '\t') || (*buffer == '\n'))
-    	buffer++;
+        buffer++;
 
     return result;
 }
@@ -1124,7 +1328,18 @@
     bool err = false;
     err = (fgets(buffer, READ_BUFFER_SIZE, fStream) == 0);
 
-    err = err || (strcmp(buffer, "# KDE Cookie File\n") != 0);
+    int version = 1;
+    if (!err)
+    {
+        if (strcmp(buffer, "# KDE Cookie File\n") == 0)
+        {
+          // version 1
+        }
+        else if (sscanf(buffer, "# KDE Cookie File v%d\n", &version) != 1)
+        {
+          err = true;
+        }
+    }
 
     if (!err)
     {
@@ -1146,13 +1361,31 @@
             int protVer  = (time_t) strtoul(verStr, 0, 10);
             const char *name( parseField(line) );
             bool keepQuotes = false;
-            if (protVer >= 100)
+            bool secure = false;
+            bool httpOnly = false;
+            bool explicitPath = false;
+            const char *value = 0;
+            if ((version == 2) || (protVer >= 200))
             {
-                protVer -= 100;
-                keepQuotes = true;
+                if (protVer >= 200)
+                    protVer -= 200;
+                int i = atoi( parseField(line) );
+                secure = i & 1;
+                httpOnly = i & 2;
+                explicitPath = i & 4;
+                line[strlen(line)-1] = '\0'; // Strip LF.
+                value = line;
+            }
+            else
+            {
+                if (protVer >= 100)
+                {
+                    protVer -= 100;
+                    keepQuotes = true;
+                }
+                value = parseField(line, keepQuotes);
+                secure = atoi( parseField(line) );
             }
-            const char *value( parseField(line, keepQuotes) );
-            bool secure = atoi( parseField(line) );
 
             // Parse error
             if (!value) continue;
@@ -1161,15 +1394,18 @@
             if ((expDate == 0) || (expDate < curTime))
                 continue;
 
-            KHttpCookie *cookie = new KHttpCookie(host, domain, path, name,
-                                                  value, expDate, protVer,
-                                                  secure);
-            if ( cookieAdvice( cookie ) )
-                addCookie(cookie);
+            KHttpCookie *cookie = new KHttpCookie(QString::fromLatin1(host),
+                                                  QString::fromLatin1(domain),
+                                                  QString::fromLatin1(path),
+                                                  QString::fromLatin1(name),
+                                                  QString::fromLatin1(value),
+                                                  expDate, protVer,
+                                                  secure, httpOnly, explicitPath);
+            addCookie(cookie);
         }
     }
     delete [] buffer;
-    cookiesChanged = false;
+    m_cookiesChanged = false;
 
     fclose( fStream);
     return err;
@@ -1181,19 +1417,18 @@
 
 void KCookieJar::saveConfig(KConfig *_config)
 {
-    if (!configChanged)
+    if (!m_configChanged)
         return;
 
-    _config->setGroup(QString::null);
-    _config->writeEntry("DefaultRadioButton", defaultRadioButton);
-    _config->writeEntry("ShowCookieDetails", showCookieDetails );
-
-    QStringList domainSettings;
+    _config->setGroup("Cookie Dialog");
+    _config->writeEntry("PreferredPolicy", m_preferredPolicy);
+    _config->writeEntry("ShowCookieDetails", m_showCookieDetails );
     _config->setGroup("Cookie Policy");
-    _config->writeEntry("CookieGlobalAdvice", adviceToStr( globalAdvice));
+    _config->writeEntry("CookieGlobalAdvice", adviceToStr( m_globalAdvice));
 
-    for ( QStringList::Iterator it=domainList.begin();
-          it != domainList.end();
+    QStringList domainSettings;
+    for ( QStringList::Iterator it=m_domainList.begin();
+          it != m_domainList.end();
           it++ )
     {
          const QString &domain = *it;
@@ -1208,6 +1443,7 @@
     }
     _config->writeEntry("CookieDomainAdvice", domainSettings);
     _config->sync();
+    m_configChanged = false;
 }
 
 
@@ -1217,23 +1453,23 @@
 
 void KCookieJar::loadConfig(KConfig *_config, bool reparse )
 {
-    QString value;
-    QStringList domainSettings;
-
     if ( reparse )
         _config->reparseConfiguration();
 
-    _config->setGroup(QString::null);
-    defaultRadioButton = _config->readNumEntry( "DefaultRadioButton", 0 );
-    showCookieDetails = _config->readBoolEntry( "ShowCookieDetails" );
+    _config->setGroup("Cookie Dialog");
+    m_showCookieDetails = _config->readBoolEntry( "ShowCookieDetails" );
+    m_preferredPolicy = _config->readNumEntry( "PreferredPolicy", 0 );
 
     _config->setGroup("Cookie Policy");
-    value = _config->readEntry("CookieGlobalAdvice", "Ask");
-    globalAdvice = strToAdvice(value);
-    domainSettings = _config->readListEntry("CookieDomainAdvice");
+    QStringList domainSettings = _config->readListEntry("CookieDomainAdvice");
+    m_rejectCrossDomainCookies = _config->readBoolEntry( "RejectCrossDomainCookies", true );
+    m_autoAcceptSessionCookies = _config->readBoolEntry( "AcceptSessionCookies", true );
+    m_ignoreCookieExpirationDate = _config->readBoolEntry( "IgnoreExpirationDate", false );
+    QString value = _config->readEntry("CookieGlobalAdvice", L1("Ask"));
+    m_globalAdvice = strToAdvice(value);
 
     // Reset current domain settings first.
-    for ( QStringList::Iterator it=domainList.begin(); it != domainList.end(); )
+    for ( QStringList::Iterator it=m_domainList.begin(); it != m_domainList.end(); )
     {
          // Make sure to update iterator before calling setDomainAdvice()
          // setDomainAdvice() might delete the domain from domainList.
@@ -1241,16 +1477,19 @@
          setDomainAdvice(domain, KCookieDunno);
     }
 
-    // Now apply the
+    // Now apply the domain settings read from config file...
     for ( QStringList::Iterator it=domainSettings.begin();
           it != domainSettings.end(); )
     {
         const QString &value = *it++;
+
         int sepPos = value.find(':');
-        if (sepPos <= 0) { continue; }
+
+        if (sepPos <= 0)
+          continue;
+
         QString domain(value.left(sepPos));
         KCookieAdvice advice = strToAdvice( value.mid(sepPos + 1) );
         setDomainAdvice(domain, advice);
     }
 }
-
--- konqueror-embedded-snapshot-20030705/konq-embed/kdesrc/kio/http/kcookiejar/kcookiejar.h~kcookiejar-merge.patch
+++ konqueror-embedded-snapshot-20030705/konq-embed/kdesrc/kio/http/kcookiejar/kcookiejar.h
@@ -20,7 +20,7 @@
 //----------------------------------------------------------------------------
 //
 // KDE File Manager -- HTTP Cookies
-// $Id: kcookiejar.h,v 1.21.2.1 2001/09/08 22:03:49 adawit Exp $
+// $Id: kcookiejar.h,v 1.34 2004/07/20 15:29:24 waba Exp $
 
 #ifndef KCOOKIEJAR_H
 #define KCOOKIEJAR_H
@@ -59,10 +59,12 @@
     QString mValue;
     time_t  mExpireDate;
     int     mProtocolVersion;
-    long    mWindowId;
     bool    mSecure;
+    bool    mCrossDomain;
+    bool    mHttpOnly;
+    bool    mExplicitPath;
+    QValueList<long> mWindowIds;
 
-    KHttpCookiePtr nextCookie;
     QString cookieStr(bool useDOMFormat);
 
 public:
@@ -73,28 +75,32 @@
                 const QString &_value=QString::null,
                 time_t _expireDate=0,
                 int _protocolVersion=0,
-                bool _secure = false);
+                bool _secure = false,
+                bool _httpOnly = false,
+                bool _explicitPath = false);
 
     QString domain(void) { return mDomain; }
     QString host(void) { return mHost; }
     QString path(void) { return mPath; }
     QString name(void) { return mName; }
     QString value(void) { return mValue; }
-    long    windowId(void) { return mWindowId; }
+    QValueList<long> &windowIds(void) { return mWindowIds; }
     void    fixDomain(const QString &domain) { mDomain = domain; }
     time_t  expireDate(void) { return mExpireDate; }
     int     protocolVersion(void) { return mProtocolVersion; }
     bool    isSecure(void) { return mSecure; }
     bool    isExpired(time_t currentDate);
+    bool    isCrossDomain(void) { return mCrossDomain; }
+    bool    isHttpOnly(void) { return mHttpOnly; }
+    bool    hasExplicitPath(void) { return mExplicitPath; }
     bool    match(const QString &fqdn, const QStringList &domainList, const QString &path);
-    KHttpCookiePtr next() { return nextCookie; }
 };
 
 class KHttpCookieList : public QList<KHttpCookie>
 {
 public:
     KHttpCookieList() : QList<KHttpCookie>(), advice( KCookieDunno )
-    { setAutoDelete(true); }
+    { }
     virtual ~KHttpCookieList() { }
 
     virtual int compareItems( void * item1, void * item2);
@@ -125,7 +131,7 @@
     /**
      * Returns whether the cookiejar has been changed
      */
-    bool changed() { return cookiesChanged || configChanged; }
+    bool changed() const { return m_cookiesChanged || m_configChanged; }
 
     /**
      * Store all the cookies in a safe(?) place
@@ -154,8 +160,11 @@
      *
      * If @p useDOMFormat is true, the string is formatted in a format
      * in compliance with the DOM standard.
+     * @p pendingCookies contains a list of cookies that have not been
+     * approved yet by the user but that will be included in the result
+     * none the less.
      */
-    QString findCookies(const QString &_url, bool useDOMFormat);
+    QString findCookies(const QString &_url, bool useDOMFormat, long windowId, KHttpCookieList *pendingCookies=0);
 
     /**
      * This function parses cookie_headers and returns a linked list of
@@ -165,17 +174,17 @@
      * cookie_headers should be a concatenation of all lines of a HTTP-header
      * which start with "Set-Cookie". The lines should be separated by '\n's.
      */
-    KHttpCookiePtr makeCookies(const QString &_url, const QCString &cookie_headers, long windowId);
+    KHttpCookieList makeCookies(const QString &_url, const QCString &cookie_headers, long windowId);
 
     /**
      * This function parses cookie_headers and returns a linked list of
      * valid KHttpCookie objects for all cookies found in cookie_headers.
      * If no cookies could be found 0 is returned.
      *
-     * cookie_domstr should be a concatenation of "name=value" pairs, seperated
+     * cookie_domstr should be a concatenation of "name=value" pairs, separated
      * by a semicolon ';'.
      */
-    KHttpCookiePtr makeDOMCookies(const QString &_url, const QCString &cookie_domstr, long windowId);
+    KHttpCookieList makeDOMCookies(const QString &_url, const QCString &cookie_domstr, long windowId);
 
     /**
      * This function hands a KHttpCookie object over to the cookie jar.
@@ -279,13 +288,13 @@
      * Removes all end of session cookies set by the
      * session @p windId.
      */
-    void eatSessionCookies( int windId );
+    void eatSessionCookies( long windowId );
 
     /**
      * Removes all end of session cookies set by the
      * session @p windId.
      */
-    void eatSessionCookies( const QString& fqdn, int windId, bool isFQDN = true );
+    void eatSessionCookies( const QString& fqdn, long windowId, bool isFQDN = true );
 
     /**
      * Parses _url and returns the FQDN (_fqdn) and path (_path).
@@ -297,21 +306,46 @@
     /**
      * Returns a list of domains (_domainList) relevant for this host.
      */
-    static void extractDomains(const QString &_fqdn,
-                               QStringList &_domainList);
+    void extractDomains(const QString &_fqdn,
+                        QStringList &_domainList);
 
     static QString adviceToStr(KCookieAdvice _advice);
     static KCookieAdvice strToAdvice(const QString &_str);
 
-    // Save this in the config file...
-    int defaultRadioButton; // 0 = This cookie, 1 = domain, 2 = all cookies
-    bool showCookieDetails; // true, false
+    /** Returns the */
+    int preferredDefaultPolicy() const { return m_preferredPolicy; }
+
+    /** Returns the */
+    bool showCookieDetails () const { return m_showCookieDetails; }
+
+     /**
+      * Sets the user's default preference cookie policy.
+      */
+     void setPreferredDefaultPolicy (int value) { m_preferredPolicy = value; }
+
+     /**
+      * Sets the user's preference of level of detail displayed
+      * by the cookie dialog.
+      */
+     void setShowCookieDetails (bool value) { m_showCookieDetails = value; }
 
 protected:
-    QDict<KHttpCookieList> cookieDomains;
-    QStringList domainList;
-    KCookieAdvice globalAdvice;
-    bool configChanged;
-    bool cookiesChanged;
+     void stripDomain(const QString &_fqdn, QString &_domain);
+     QString stripDomain( KHttpCookiePtr cookiePtr);
+
+protected:
+    QStringList m_domainList;
+    KCookieAdvice m_globalAdvice;
+    QDict<KHttpCookieList> m_cookieDomains;
+    QDict<int> m_twoLevelTLD;
+
+    bool m_configChanged;
+    bool m_cookiesChanged;
+    bool m_showCookieDetails;
+    bool m_rejectCrossDomainCookies;
+    bool m_autoAcceptSessionCookies;
+    bool m_ignoreCookieExpirationDate;
+
+    int m_preferredPolicy;
 };
 #endif
--- konqueror-embedded-snapshot-20030705/konq-embed/kdesrc/kio/http/kcookiejar/kcookieserver.cpp~kcookiejar-merge.patch
+++ konqueror-embedded-snapshot-20030705/konq-embed/kdesrc/kio/http/kcookiejar/kcookieserver.cpp
@@ -23,25 +23,30 @@
 //----------------------------------------------------------------------------
 //
 // KDE Cookie Server
-// $Id: kcookieserver.cpp,v 1.33.2.1 2001/09/08 22:03:49 adawit Exp $
+// $Id: kcookieserver.cpp,v 1.52 2004/08/16 14:04:40 lunakl Exp $
 
 #define SAVE_DELAY 3 // Save after 3 minutes
 
-#include "kcookieserver.h"
-#include "kcookiejar.h"
-#include "kcookiewin.h"
+#include <unistd.h>
 
-#include <kdebug.h>
-#include <kapp.h>
-#include <kcmdlineargs.h>
-#include <kstddirs.h>
 #include <qtimer.h>
-#include <unistd.h>
 #include <qlist.h>
 #include <qfile.h>
 
 #include <dcopclient.h>
+
 #include <kconfig.h>
+#include <kdebug.h>
+#include <kcmdlineargs.h>
+#include <kstddirs.h>
+
+#ifdef _QT_QPE_
+#include <qpe/qpeapplication.h>
+#endif
+
+#include "kcookiejar.h"
+#include "kcookiewin.h"
+#include "kcookieserver.h"
 
 // Cookie field indexes
 enum CookieDetails { CF_DOMAIN=0, CF_PATH, CF_NAME, CF_HOST,
@@ -53,6 +58,7 @@
    DCOPClientTransaction *transaction;
    QString url;
    bool DOM;
+   long windowId;
 };
 
 template class  QList<CookieRequest>;
@@ -68,10 +74,11 @@
 {
    mCookieJar = new KCookieJar;
    mPendingCookies = new KHttpCookieList;
+   mPendingCookies->setAutoDelete(true);
    mRequestList = new RequestList;
    mAdvicePending = false;
    mTimer = 0;
-   mCookieJar->loadConfig( kapp->config());
+   mCookieJar->loadConfig( kapp->config() );
 
    QString filename = locateLocal("appdata", "cookies");
 
@@ -89,12 +96,16 @@
    {
       mCookieJar->loadCookies( filename);
    }
+
+   QWidget *wid = qApp->desktop();
+   mBigScreen = (wid->width() > 320 || wid->height() > 320);
 }
 
 KCookieServer::~KCookieServer()
 {
    if (mCookieJar->changed())
       slotSave();
+
    delete mCookieJar;
    delete mTimer;
    delete mPendingCookies;
@@ -125,7 +136,7 @@
    return 0;
 }
 
-bool KCookieServer::cookiesPending( const QString &url )
+bool KCookieServer::cookiesPending( const QString &url, KHttpCookieList *cookieList )
 {
   QString fqdn;
   QStringList domains;
@@ -136,109 +147,161 @@
   if (!KCookieJar::parseURL(url, fqdn, path))
      return false;
 
-  KCookieJar::extractDomains( fqdn, domains );
+  mCookieJar->extractDomains( fqdn, domains );
   for( KHttpCookie *cookie = mPendingCookies->first();
        cookie != 0L;
        cookie = mPendingCookies->next())
   {
        if (cookie->match( fqdn, domains, path))
-          return true;
+       {
+          if (!cookieList)
+             return true;
+          cookieList->append(cookie);
+       }
   }
-  return false;
+  if (!cookieList)
+     return false;
+  return cookieList->isEmpty();
 }
 
 void KCookieServer::addCookies( const QString &url, const QCString &cookieHeader,
                                long windowId, bool useDOMFormat )
 {
-    KHttpCookiePtr cookie = 0;
+    KHttpCookieList cookieList;
     if (useDOMFormat)
-       cookie = mCookieJar->makeDOMCookies(url, cookieHeader, windowId);
+       cookieList = mCookieJar->makeDOMCookies(url, cookieHeader, windowId);
     else
-       cookie = mCookieJar->makeCookies(url, cookieHeader, windowId);
+       cookieList = mCookieJar->makeCookies(url, cookieHeader, windowId);
 
-    if (mAdvicePending)
-    {
-       checkCookies(cookie, true);
-    }
-    else
+    checkCookies(&cookieList);
+
+    for(KHttpCookiePtr cookie = cookieList.first(); cookie; cookie = cookieList.first())
+       mPendingCookies->append(cookieList.take());
+
+    if (!mAdvicePending)
     {
        mAdvicePending = true;
-       do {
-          checkCookies(cookie, false);
-          cookie = mPendingCookies->count() ? mPendingCookies->take(0) : 0;
+       while (!mPendingCookies->isEmpty())
+       {
+          checkCookies(0);
        }
-       while (cookie);
        mAdvicePending = false;
     }
-
 }
 
-void KCookieServer::checkCookies( KHttpCookie *cookie, bool queue )
+void KCookieServer::checkCookies( KHttpCookieList *cookieList)
 {
-    QString host;
-    KCookieAdvice userAdvice = KCookieDunno;
-    if (cookie) host = cookie->host();
+    KHttpCookieList *list;
+
+    if (cookieList)
+       list = cookieList;
+    else
+       list = mPendingCookies;
+
+    KHttpCookiePtr cookie = list->first();
     while (cookie)
     {
-        KHttpCookiePtr next_cookie = cookie->next();
         KCookieAdvice advice = mCookieJar->cookieAdvice(cookie);
-        if ((advice == KCookieAsk) || (advice == KCookieDunno))
-        {
-            // We only ask the user once, even if we get multiple
-            // cookies from the same site.
-            if (userAdvice == KCookieDunno)
-            {
-                if (queue)
-                {
-                    mPendingCookies->append(cookie);
-                    return;
-                }
-                else
-                {
-                    mPendingCookies->prepend(cookie);
-                    KCookieWin *kw = new KCookieWin( 0L, cookie,
-                                                     mCookieJar->defaultRadioButton,
-                                                     mCookieJar->showCookieDetails );
-                    userAdvice = kw->advice(mCookieJar, cookie);
-                    delete kw;
-                    mPendingCookies->take(0);
-                    // Save the cookie config if it has changed
-                    mCookieJar->saveConfig( kapp->config() );
-                }
-            }
-            advice = userAdvice;
-        }
         switch(advice)
         {
         case KCookieAccept:
+            list->take();
             mCookieJar->addCookie(cookie);
+            cookie = list->current();
             break;
 
         case KCookieReject:
-        default:
+            list->take();
             delete cookie;
+            cookie = list->current();
+            break;
+
+        default:
+            cookie = list->next();
             break;
         }
-        cookie = next_cookie;
-        if (!cookie && !queue)
+    }
+
+    if (cookieList || list->isEmpty())
+       return;
+
+    KHttpCookiePtr currentCookie = mPendingCookies->first();
+
+    KHttpCookieList currentList;
+    currentList.append(currentCookie);
+    QString currentHost = currentCookie->host();
+
+    cookie = mPendingCookies->next();
+    while (cookie)
+    {
+        if (cookie->host() == currentHost)
         {
-           // Check if there are cookies on the pending list from the
-           // same host.
-           for( cookie = mPendingCookies->first();
-                cookie;
-                cookie = mPendingCookies->next())
-           {
-               if (cookie->host() == host)
-                  break;
-           }
-           if (cookie)
+            currentList.append(cookie);
+        }
+        cookie = mPendingCookies->next();
+    }
+
+    KCookieWin *kw;
+    KScrolledCookieWin *skw= 0L;
+
+    if(!mBigScreen) {
+        qWarning( "Using Scrolled Cookie WIn" );
+        skw = new KScrolledCookieWin(0L, currentList,
+                                     mCookieJar->preferredDefaultPolicy(),
+                                     mCookieJar->showCookieDetails() );
+        kw = skw->cookieWindow();
+    }else
+	kw = new KCookieWin( 0L, currentList,
+                             mCookieJar->preferredDefaultPolicy(),
+                             mCookieJar->showCookieDetails() );
+
+#ifdef _QT_QPE_
+    int result = QPEApplication::execDialog( !mBigScreen ?
+                                             static_cast<QDialog*>( skw ) :
+                                             static_cast<QDialog*>( kw  ) );
+#else
+    int result = !mBigScreen ? skw->exec() : kw->exec();
+#endif
+
+    KCookieAdvice userAdvice = kw->advice( result, mCookieJar, currentCookie);
+    delete kw;
+    delete skw;
+    // Save the cookie config if it has changed
+    mCookieJar->saveConfig( kapp->config() );
+
+    // Apply the user's choice to all cookies that are currently
+    // queued for this host.
+    cookie = mPendingCookies->first();
+    while (cookie)
+    {
+        if (cookie->host() == currentHost)
+        {
+           switch(userAdvice)
            {
-               // Found a matching cookie, remove it from the pending list.
-               cookie = mPendingCookies->take();
+           case KCookieAccept:
+               mPendingCookies->take();
+               mCookieJar->addCookie(cookie);
+               cookie = mPendingCookies->current();
+               break;
+
+           case KCookieReject:
+               mPendingCookies->take();
+               delete cookie;
+               cookie = mPendingCookies->current();
+               break;
+
+           default:
+               cookie = mPendingCookies->next();
+               break;
            }
         }
+        else
+        {
+            cookie = mPendingCookies->next();
+        }
     }
 
+
     // Check if we can handle any request
     for ( CookieRequest *request = mRequestList->first(); request;)
     {
@@ -246,13 +309,13 @@
         {
            QCString replyType;
            QByteArray replyData;
-           QString res = mCookieJar->findCookies( request->url, request->DOM );
+           QString res = mCookieJar->findCookies( request->url, request->DOM, request->windowId );
 
            QDataStream stream2(replyData, IO_WriteOnly);
            stream2 << res;
            replyType = "QString";
            dcopClient()->endTransaction( request->transaction,
-                                       replyType, replyData);
+                                         replyType, replyData);
            CookieRequest *tmp = request;
            request = mRequestList->next();
            mRequestList->removeRef( tmp );
@@ -271,7 +334,7 @@
 {
    delete mTimer;
    mTimer = 0;
-   QString filename = locateLocal("appdata", "cookies");
+   QString filename = locateLocal("data", "kcookiejar/cookies");
    mCookieJar->saveCookies(filename);
 }
 
@@ -333,8 +396,9 @@
         return
        ((hasDomain && c->domain() == domain) ||
         fqdn == c->host()) &&
-       (c->path()   == path)   &&
-       (c->name()   == name);
+       (c->path()   == path) &&
+       (c->name()   == name) &&
+       (!c->isExpired(time(0)));
     }
     return false;
 }
@@ -343,16 +407,30 @@
 QString
 KCookieServer::findCookies(QString url)
 {
+  return findCookies(url, 0);
+}
+
+// DCOP function
+QString
+KCookieServer::findCookies(QString url, long windowId)
+{
    if (cookiesPending(url))
    {
       CookieRequest *request = new CookieRequest;
       request->transaction = dcopClient()->beginTransaction();
       request->url = url;
       request->DOM = false;
+      request->windowId = windowId;
       mRequestList->append( request );
       return QString::null; // Talk to you later :-)
    }
-   return mCookieJar->findCookies(url, false);
+
+   QString cookies = mCookieJar->findCookies(url, false, windowId);
+
+   if (mCookieJar->changed() && !mTimer)
+      saveCookieJar();
+
+   return cookies;
 }
 
 // DCOP function
@@ -409,16 +487,20 @@
 QString
 KCookieServer::findDOMCookies(QString url)
 {
-   if (cookiesPending(url))
-   {
-      CookieRequest *request = new CookieRequest;
-      request->transaction = dcopClient()->beginTransaction();
-      request->url = url;
-      request->DOM = true;
-      mRequestList->append( request );
-      return QString::null; // Talk to you later :-)
-   }
-   return mCookieJar->findCookies(url, true);
+   return findDOMCookies(url, 0);
+}
+
+// DCOP function
+QString
+KCookieServer::findDOMCookies(QString url, long windowId)
+{
+   // We don't wait for pending cookies because it locks up konqueror
+   // which can cause a deadlock if it happens to have a popup-menu up.
+   // Instead we just return pending cookies as if they had been accepted already.
+   KHttpCookieList pendingCookies;
+   cookiesPending(url, &pendingCookies);
+
+   return mCookieJar->findCookies(url, true, windowId, &pendingCookies);
 }
 
 // DCOP function
@@ -459,18 +541,27 @@
       saveCookieJar();
 }
 
+
+// Qt function
 void
-KCookieServer::deleteSessionCookies( long winId )
+KCookieServer::slotDeleteSessionCookies( long windowId )
 {
-  mCookieJar->eatSessionCookies( winId );
+   deleteSessionCookies(windowId);
+}
+
+// DCOP function
+void
+KCookieServer::deleteSessionCookies( long windowId )
+{
+  mCookieJar->eatSessionCookies( windowId );
   if(!mTimer)
     saveCookieJar();
 }
 
 void
-KCookieServer::deleteSessionCookiesFor(QString fqdn, long winId)
+KCookieServer::deleteSessionCookiesFor(QString fqdn, long windowId)
 {
-  mCookieJar->eatSessionCookies( fqdn, winId );
+  mCookieJar->eatSessionCookies( fqdn, windowId );
   if(!mTimer)
     saveCookieJar();
 }
@@ -500,7 +591,7 @@
    if (KCookieJar::parseURL(url, fqdn, dummy))
    {
       QStringList domains;
-      KCookieJar::extractDomains(fqdn, domains);
+      mCookieJar->extractDomains(fqdn, domains);
       mCookieJar->setDomainAdvice(domains[0],
                                   KCookieJar::strToAdvice(advice));
    }
@@ -516,7 +607,7 @@
    if (KCookieJar::parseURL(url, fqdn, dummy))
    {
       QStringList domains;
-      KCookieJar::extractDomains(fqdn, domains);
+      mCookieJar->extractDomains(fqdn, domains);
       advice = mCookieJar->getDomainAdvice(domains[0]);
    }
    return KCookieJar::adviceToStr(advice);
@@ -533,7 +624,7 @@
 void
 KCookieServer::shutdown()
 {
-   quit();
+    quit();
 }
 
 #include "kcookieserver.moc"
--- konqueror-embedded-snapshot-20030705/konq-embed/kdesrc/kio/http/kcookiejar/kcookieserver.h~kcookiejar-merge.patch
+++ konqueror-embedded-snapshot-20030705/konq-embed/kdesrc/kio/http/kcookiejar/kcookieserver.h
@@ -20,7 +20,7 @@
 //----------------------------------------------------------------------------
 //
 // KDE Cookie Server
-// $Id: kcookieserver.h,v 1.15.2.1 2001/09/08 22:03:49 adawit Exp $
+// $Id: kcookieserver.h,v 1.24 2003/06/09 10:56:42 waba Exp $
 
 #ifndef KCOOKIESERVER_H
 #define KCOOKIESERVER_H
@@ -33,6 +33,7 @@
 class KHttpCookie;
 class QTimer;
 class RequestList;
+class KConfig;
 
 class KCookieServer : public KUniqueApplication
 {
@@ -46,9 +47,11 @@
 
 k_dcop:
   QString findCookies(QString);
+  QString findCookies(QString, long);
   QStringList findDomains();
   QStringList findCookies(QValueList<int>,QString,QString,QString,QString);
   QString findDOMCookies(QString);
+  QString findDOMCookies(QString, long);
   void addCookies(QString, QCString, long);
   void deleteCookie(QString, QString, QString, QString);
   void deleteCookiesFromDomain(QString);
@@ -62,13 +65,14 @@
   void shutdown();
 
 public:
-  bool cookiesPending(const QString &url);
+  bool cookiesPending(const QString &url, KHttpCookieList *cookieList=0);
   void addCookies(const QString &url, const QCString &cookieHeader,
                   long windowId, bool useDOMFormat);
-  void checkCookies(KHttpCookie *cookie, bool queue);
+  void checkCookies(KHttpCookieList *cookieList);
 
 public slots:
   void slotSave();
+  void slotDeleteSessionCookies(long);
 
 protected:
   KCookieJar *mCookieJar;
@@ -82,6 +86,7 @@
   bool cookieMatches(KHttpCookie*, QString, QString, QString, QString);
   void putCookie(QStringList&, KHttpCookie*, const QValueList<int>&);
   void saveCookieJar();
+  bool mBigScreen : 1;
 };
 
 #endif
--- konqueror-embedded-snapshot-20030705/konq-embed/kdesrc/kio/http/kcookiejar/kcookiewin.cpp~kcookiejar-merge.patch
+++ konqueror-embedded-snapshot-20030705/konq-embed/kdesrc/kio/http/kcookiejar/kcookiewin.cpp
@@ -1,8 +1,8 @@
 /*
 This file is part of KDE
 
-  Copyright (C) 2000 Waldo Bastian <bastian@kde.org>
-  Copyright (C) 2000-2001 Dawit Alemayehu <adawit@kde.org>
+  Copyright (C) 2000- Waldo Bastian <bastian@kde.org>
+  Copyright (C) 2000- Dawit Alemayehu <adawit@kde.org>
 
 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
@@ -24,7 +24,7 @@
 //----------------------------------------------------------------------------
 //
 // KDE File Manager -- HTTP Cookie Dialogs
-// $Id: kcookiewin.cpp,v 1.26 2001/05/13 23:36:48 adawit Exp $
+// $Id: kcookiewin.cpp,v 1.55 2004/07/07 15:18:43 waba Exp $
 
 // The purpose of the QT_NO_TOOLTIP and QT_NO_WHATSTHIS ifdefs is because
 // this file is also used in Konqueror/Embedded. One of the aims of
@@ -54,66 +54,77 @@
 #include <qpushbutton.h>
 #include <qradiobutton.h>
 #include <qvbuttongroup.h>
+#include <qscrollview.h>
+
+#ifndef QT_NO_TOOLTIP
+#include <qtooltip.h>
+#endif
+
+#ifndef QT_NO_WHATSTHIS
+#include <qwhatsthis.h>
+#endif
 
-#include <kapp.h>
 #include <kwin.h>
 #include <klocale.h>
 #include <kglobal.h>
 #include <kurllabel.h>
+#include <qlineedit.h>
 #include <kiconloader.h>
 
+#ifndef Q_WS_QWS //FIXME(E): Implement for Qt Embedded
+#include <X11/Xlib.h>
+#endif
+
 #include "kcookiejar.h"
 #include "kcookiewin.h"
 
-KCookieWin::KCookieWin( QWidget *parent, KHttpCookie* cookie,
-                        int defaultButton, bool showDetails )
-           :KDialog( parent, "cookiealert", true )
+KCookieWin::KCookieWin( QWidget *parent, KHttpCookieList cookieList,
+                        int defaultButton, bool showDetails, bool modal )
+           :KDialog( parent, "cookiealert", modal )
 {
-    KWin::setState( winId(), NET::StaysOnTop );
-    KWin::setOnDesktop(winId(), KWin::currentDesktop());
+#ifndef Q_WS_QWS //FIXME(E): Implement for Qt Embedded
     setCaption( i18n("Cookie Alert") );
     setIcon( SmallIcon("cookie") );
-
+    // all cookies in the list should have the same window at this time, so let's take the first
+    if( cookieList.first()->windowIds().count() > 0 )
+        XSetTransientForHint( qt_xdisplay(), winId(), cookieList.first()->windowIds().first());
+#endif
     // Main widget's layout manager...
     QVBoxLayout* vlayout = new QVBoxLayout( this, KDialog::marginHint(), KDialog::spacingHint() );
-    vlayout->setResizeMode( QLayout::Fixed );
 
     // Cookie image and message to user
     QHBox* hBox = new QHBox( this );
     hBox->setSpacing( KDialog::spacingHint() );
     QLabel* icon = new QLabel( hBox );
-    icon->setPixmap( QMessageBox::standardIcon(QMessageBox::Warning, kapp->style().guiStyle()) );
+    icon->setPixmap( QMessageBox::standardIcon(QMessageBox::Warning, kapp->style().guiStyle() ) );
     icon->setAlignment( Qt::AlignCenter );
     icon->setFixedSize( 2*icon->sizeHint() );
 
-    int count = 0;
-    KHttpCookie* nextCookie = cookie;
-    while ( nextCookie )
-    {
-        count++;
-        nextCookie = nextCookie->next();
-    }
+    int count = cookieList.count();
 
     QVBox* vBox = new QVBox( hBox );
-    QString txt = (count == 1) ? i18n("You received a cookie from"):
-                  i18n("You received %1 cookies from").arg(count);
+    QString txt = i18n("You received a cookie from",
+                       "You received %n cookies from", count);
     QLabel* lbl = new QLabel( txt, vBox );
     lbl->setAlignment( Qt::AlignCenter );
+    KHttpCookiePtr cookie = cookieList.first();
     txt = i18n("<b>%1</b>").arg( cookie->host() );
+    if (cookie->isCrossDomain())
+       txt += i18n(" <b>[Cross Domain!]</b>");
     lbl = new QLabel( txt, vBox );
     lbl->setAlignment( Qt::AlignCenter );
-    lbl = new QLabel( i18n("Do you want to accept or reject ?"), vBox );
+    lbl = new QLabel( i18n("Do you want to accept or reject?"), vBox );
     lbl->setAlignment( Qt::AlignCenter );
     vlayout->addWidget( hBox, 0, Qt::AlignLeft );
 
     // Cookie Details dialog...
-    m_detailView = new KCookieDetail( cookie, count, this );
+    m_detailView = new KCookieDetail( cookieList, count, this );
     vlayout->addWidget( m_detailView );
     m_showDetails = showDetails;
     m_showDetails ? m_detailView->show():m_detailView->hide();
 
     // Cookie policy choice...
-    m_btnGrp = new QVButtonGroup( i18n("Apply choice to"), this );
+    m_btnGrp = new QVButtonGroup( i18n("Apply Choice To"), this );
     m_btnGrp->setRadioButtonExclusive( true );
 
     txt = (count == 1)? i18n("&Only this cookie") : i18n("&Only these cookies");
@@ -128,7 +139,7 @@
 #ifndef QT_NO_WHATSTHIS
     QWhatsThis::add( rb, i18n("Select this option to accept/reject all cookies from "
                               "this site. Choosing this option will add a new policy for "
-                              "the site this cookie originated from.  This policy will be "
+                              "the site this cookie originated from. This policy will be "
                               "permanent until you manually change it from the Control Center "
                               "<em>(see WebBrowsing/Cookies in the Control Center)</em>.") );
 #endif
@@ -146,35 +157,42 @@
     if ( defaultButton > -1 && defaultButton < 3 )
         m_btnGrp->setButton( defaultButton );
     else
-        m_btnGrp->setButton( 0 );
+        m_btnGrp->setButton( 1 );
 
     // Accept/Reject buttons
+    QWidget* receiver = parent ? parent : this;
     QWidget* bbox = new QWidget( this );
     QBoxLayout* bbLay = new QHBoxLayout( bbox );
     bbLay->setSpacing( KDialog::spacingHint() );
     QPushButton* btn = new QPushButton( i18n("&Accept"), bbox );
     btn->setDefault( true );
-    connect( btn, SIGNAL(clicked()), SLOT(accept()) );
+    btn->setFocus();
+    connect( btn, SIGNAL(clicked()), receiver, SLOT(accept()) );
     bbLay->addWidget( btn );
     btn = new QPushButton( i18n("&Reject"), bbox );
-    connect( btn, SIGNAL(clicked()), SLOT(reject()) );
+    connect( btn, SIGNAL(clicked()), receiver, SLOT(reject()) );
     bbLay->addWidget( btn );
-    bbLay->addStretch( 1 );    
-    m_button = new QPushButton( bbox );
-    m_button->setText( m_showDetails ? i18n("&Details <<"):i18n("&Details >>") );
-    connect( m_button, SIGNAL(clicked()), SLOT(slotCookieDetails()) );
-    bbLay->addWidget( m_button );
+    bbLay->addStretch( 1 );
 #ifndef QT_NO_ACCEL
     QAccel* a = new QAccel( this );
     a->connectItem( a->insertItem(Qt::Key_Escape), btn, SLOT(animateClick()) );
 #endif
-    
 
+    m_button = new QPushButton( bbox );
+    m_button->setText( m_showDetails ? i18n("&Details <<"):i18n("&Details >>") );
+    connect( m_button, SIGNAL(clicked()), SLOT(slotCookieDetails()) );
+    bbLay->addWidget( m_button );
 #ifndef QT_NO_WHATSTHIS
-    QWhatsThis::add( btn, i18n("See or modify the cookie information") );
+    QWhatsThis::add( m_button, i18n("See or modify the cookie information") );
 #endif
+
+
     vlayout->addWidget( bbox );
-    setFixedSize( sizeHint() );
+
+    if ( !parent ) {
+        vlayout->setResizeMode( QLayout::Fixed );
+        setFixedSize( sizeHint() );
+    }
 }
 
 KCookieWin::~KCookieWin()
@@ -201,13 +219,16 @@
     }
 }
 
-KCookieAdvice KCookieWin::advice( KCookieJar *cookiejar, KHttpCookie* cookie )
+KCookieAdvice KCookieWin::advice( int result, KCookieJar *cookiejar, KHttpCookie* cookie )
 {
-    int result = exec();
+    cookiejar->setShowCookieDetails ( m_showDetails );
+
     KCookieAdvice advice = (result==QDialog::Accepted) ? KCookieAccept:KCookieReject;
-    cookiejar->defaultRadioButton = m_btnGrp->id( m_btnGrp->selected() );
-    cookiejar->showCookieDetails = m_showDetails;
-    switch ( cookiejar->defaultRadioButton )
+
+    int preferredPolicy = m_btnGrp->id( m_btnGrp->selected() );
+    cookiejar->setPreferredDefaultPolicy( preferredPolicy );
+
+    switch ( preferredPolicy )
     {
         case 2:
             cookiejar->setGlobalAdvice( advice );
@@ -222,11 +243,11 @@
     return advice;
 }
 
-KCookieDetail::KCookieDetail( KHttpCookie* cookie, int cookieCount,
+KCookieDetail::KCookieDetail( KHttpCookieList cookieList, int cookieCount,
                               QWidget* parent, const char* name )
               :QGroupBox( parent, name )
 {
-    setTitle( i18n("Cookie details") );
+    setTitle( i18n("Cookie Details") );
     QGridLayout* grid = new QGridLayout( this, 9, 2,
                                          KDialog::spacingHint(),
                                          KDialog::marginHint() );
@@ -237,8 +258,7 @@
     grid->addWidget( label, 1, 0 );
     m_name = new QLineEdit( this );
     m_name->setReadOnly( true );
-    m_name->setText( cookie->name() );
-    m_name->setMaximumWidth( fontMetrics().width('W') * 25 );
+    m_name->setMaximumWidth( fontMetrics().maxWidth() * 25 );
     grid->addWidget( m_name, 1 ,1 );
 
     //Add the value
@@ -246,46 +266,35 @@
     grid->addWidget( label, 2, 0 );
     m_value = new QLineEdit( this );
     m_value->setReadOnly( true );
-    m_value->setText( cookie->value() );
-    m_value->setMaximumWidth( fontMetrics().width('W') * 25 );
+    m_value->setMaximumWidth( fontMetrics().maxWidth() * 25 );
     grid->addWidget( m_value, 2, 1);
 
     label = new QLabel( i18n("Expires:"), this );
     grid->addWidget( label, 3, 0 );
     m_expires = new QLineEdit( this );
     m_expires->setReadOnly( true );
-    QDateTime cookiedate;
-    cookiedate.setTime_t( cookie->expireDate() );
-    if ( cookie->expireDate() )
-      m_expires->setText( KGlobal::locale()->formatDateTime(cookiedate) );
-    else
-      m_expires->setText( i18n("Not specified") );
-    m_expires->setMaximumWidth(fontMetrics().width('W') * 25 );
+    m_expires->setMaximumWidth(fontMetrics().maxWidth() * 25 );
     grid->addWidget( m_expires, 3, 1);
 
     label = new QLabel( i18n("Path:"), this );
     grid->addWidget( label, 4, 0 );
     m_path = new QLineEdit( this );
     m_path->setReadOnly( true );
-    m_path->setText( cookie->path() );
-    m_path->setMaximumWidth( fontMetrics().width('W') * 25 );
+    m_path->setMaximumWidth( fontMetrics().maxWidth() * 25 );
     grid->addWidget( m_path, 4, 1);
 
     label = new QLabel( i18n("Domain:"), this );
     grid->addWidget( label, 5, 0 );
     m_domain = new QLineEdit( this );
     m_domain->setReadOnly( true );
-    QString val = cookie->domain();
-    m_domain->setText( val.isEmpty()?i18n("Not specified"):val );
-    m_domain->setMaximumWidth( fontMetrics().width('W') * 25 );
+    m_domain->setMaximumWidth( fontMetrics().maxWidth() * 25 );
     grid->addWidget( m_domain, 5, 1);
 
-    label = new QLabel( i18n("Is Secure:"), this );
+    label = new QLabel( i18n("Exposure:"), this );
     grid->addWidget( label, 6, 0 );
     m_secure = new QLineEdit( this );
     m_secure->setReadOnly( true );
-    m_secure->setText( cookie->isSecure() ? i18n("True"):i18n("False") );
-    m_secure->setMaximumWidth( fontMetrics().width('W') * 25 );
+    m_secure->setMaximumWidth( fontMetrics().maxWidth() * 25 );
     grid->addWidget( m_secure, 6, 1 );
 
     if ( cookieCount > 1 )
@@ -298,8 +307,9 @@
         QToolTip::add( btnNext, i18n("Show details of the next cookie") );
 #endif
     }
-    m_cookie = cookie;
-    m_cookie_orig = cookie;
+    m_cookieList = cookieList;
+    m_cookie = 0;
+    slotNextCookie();
 }
 
 KCookieDetail::~KCookieDetail()
@@ -308,9 +318,19 @@
 
 void KCookieDetail::slotNextCookie()
 {
-    m_cookie = m_cookie->next();
-    if ( !m_cookie )
-        m_cookie = m_cookie_orig;
+    KHttpCookiePtr cookie = m_cookieList.first();
+    if (m_cookie) while(cookie)
+    {
+       if (cookie == m_cookie)
+       {
+          cookie = m_cookieList.next();
+          break;
+       }
+       cookie = m_cookieList.next();
+    }
+    m_cookie = cookie;
+    if (!m_cookie)
+        m_cookie = m_cookieList.first();
 
     if ( m_cookie )
     {
@@ -326,9 +346,52 @@
         if ( m_cookie->expireDate() )
           m_expires->setText( KGlobal::locale()->formatDateTime(cookiedate) );
         else
-          m_expires->setText( i18n("Not specified") );
-        m_secure->setText( m_cookie->isSecure() ? i18n("True"):i18n("False") );
+          m_expires->setText( i18n("End of Session") );
+        QString sec;
+        if (m_cookie->isSecure())
+        {
+          if (m_cookie->isHttpOnly())
+            sec = i18n("Secure servers only");
+          else
+            sec = i18n("Secure servers, page scripts");
+        }
+        else
+        {
+          if (m_cookie->isHttpOnly())
+            sec = i18n("Servers");
+          else
+            sec = i18n("Servers, page scripts");
+        }
+        m_secure->setText( sec );
     }
 }
 
+
+////////////
+/// The Adapter
+///
+///////////
+KScrolledCookieWin::KScrolledCookieWin( QWidget *parent, KHttpCookieList cookieList,
+                                        int defaultButton, bool showDetails )
+    : KDialog( parent, "scrolled_cookiealert", true )
+{
+    setCaption( i18n("Cookie Alert") );
+    QVBoxLayout *layout = new QVBoxLayout( this );
+    QScrollView *view = new QScrollView( this, "cookie_view" );
+    m_cookieWin = new KCookieWin( this, cookieList, defaultButton,
+                                  showDetails, false );
+
+    view->setResizePolicy( QScrollView::AutoOneFit );
+    view->setFrameShape( QFrame::NoFrame );
+    view->addChild( m_cookieWin );
+
+    layout->addWidget( view );
+}
+
+KCookieWin* KScrolledCookieWin::cookieWindow()const
+{
+    return m_cookieWin;
+}
+
+
 #include "kcookiewin.moc"
--- konqueror-embedded-snapshot-20030705/konq-embed/kdesrc/kio/http/kcookiejar/kcookiewin.h~kcookiejar-merge.patch
+++ konqueror-embedded-snapshot-20030705/konq-embed/kdesrc/kio/http/kcookiejar/kcookiewin.h
@@ -1,8 +1,8 @@
 /*
     This file is part of the KDE File Manager
 
-    Copyright (C) 1998-2000 Waldo Bastian (bastian@kde.org)
-    Copyright (C) 2000      Dawit Alemayehu (adawit@kde.org)
+    Copyright (C) 1998- Waldo Bastian (bastian@kde.org)
+    Copyright (C) 2000- Dawit Alemayehu (adawit@kde.org)
 
     This library is free software; you can redistribute it and/or
     modify it under the terms of the GNU General Public License
@@ -22,7 +22,7 @@
 //----------------------------------------------------------------------------
 //
 // KDE File Manager -- HTTP Cookie Dialogs
-// $Id: kcookiewin.h,v 1.9 2001/04/26 23:45:12 waba Exp $
+// $Id: kcookiewin.h,v 1.12 2002/05/20 05:35:37 adawit Exp $
 
 #ifndef _KCOOKIEWIN_H_
 #define _KCOOKIEWIN_H_
@@ -42,7 +42,7 @@
     Q_OBJECT
 
 public :
-    KCookieDetail( KHttpCookie* cookie, int cookieCount, QWidget *parent=0,
+    KCookieDetail( KHttpCookieList cookieList, int cookieCount, QWidget *parent=0,
                    const char *name=0 );
     ~KCookieDetail();
 
@@ -54,8 +54,8 @@
     QLineEdit*   m_path;
     QLineEdit*   m_secure;
 
-    KHttpCookie* m_cookie;
-    KHttpCookie* m_cookie_orig;
+    KHttpCookieList m_cookieList;
+    KHttpCookiePtr m_cookie;
 
 private slots:
     void slotNextCookie();
@@ -66,11 +66,11 @@
     Q_OBJECT
 
 public :
-    KCookieWin( QWidget *parent, KHttpCookie* cookie, int defaultButton=0,
-                bool showDetails=false );
+    KCookieWin( QWidget *parent, KHttpCookieList cookieList, int defaultButton=0,
+		bool showDetails=false, bool modal = true );
     ~KCookieWin();
 
-    KCookieAdvice advice( KCookieJar *cookiejar, KHttpCookie* cookie );
+    KCookieAdvice advice( int result, KCookieJar *cookiejar, KHttpCookie* cookie );
 
 private :
     QPushButton*   m_button;
@@ -81,4 +81,21 @@
 private slots:
     void slotCookieDetails();
 };
+
+/**
+ * A small Scrolled Adapter for KCookieWin
+ * to be used on big screen
+ */
+class KScrolledCookieWin : public KDialog
+{
+    Q_OBJECT
+
+public:
+    KScrolledCookieWin( QWidget *parent, KHttpCookieList cookieList, int defaultButton=0,
+		bool showDetails=false );
+    KCookieWin* cookieWindow()const;
+
+private:
+    KCookieWin *m_cookieWin;
+};
 #endif
--- konqueror-embedded-snapshot-20030705/konq-embed/kdesrc/kio/http/kcookiejar/kcookieserver_skel.cpp~kcookiejar-merge.patch
+++ konqueror-embedded-snapshot-20030705/konq-embed/kdesrc/kio/http/kcookiejar/kcookieserver_skel.cpp
@@ -6,18 +6,20 @@
 **
 *****************************************************************************/
 
-#include "./kcookieserver.h"
+#include "kcookieserver.h"
 
 #include <kdatastream.h>
 #include <qasciidict.h>
 
 
-static const int KCookieServer_fhash = 17;
-static const char* const KCookieServer_ftable[16][3] = {
+static const int KCookieServer_fhash = 19;
+static const char* const KCookieServer_ftable[18][3] = {
     { "QString", "findCookies(QString)", "findCookies(QString)" },
+    { "QString", "findCookies(QString,long int)", "findCookies(QString,long int)" },
     { "QStringList", "findDomains()", "findDomains()" },
     { "QStringList", "findCookies(QValueList<int>,QString,QString,QString,QString)", "findCookies(QValueList<int>,QString,QString,QString,QString)" },
     { "QString", "findDOMCookies(QString)", "findDOMCookies(QString)" },
+    { "QString", "findDOMCookies(QString,long int)", "findDOMCookies(QString,long int)" },
     { "void", "addCookies(QString,QCString,long int)", "addCookies(QString,QCString,long int)" },
     { "void", "deleteCookie(QString,QString,QString,QString)", "deleteCookie(QString,QString,QString,QString)" },
     { "void", "deleteCookiesFromDomain(QString)", "deleteCookiesFromDomain(QString)" },
@@ -50,12 +52,22 @@
 	QDataStream _replyStream( replyData, IO_WriteOnly );
 	_replyStream << findCookies(arg0 );
     } break;
-    case 1: { // QStringList findDomains()
+    case 1: { // QString findCookies(QString,long int)
+	QString arg0;
+	long int arg1;
+	QDataStream arg( data, IO_ReadOnly );
+	arg >> arg0;
+	arg >> arg1;
 	replyType = KCookieServer_ftable[1][0]; 
 	QDataStream _replyStream( replyData, IO_WriteOnly );
+	_replyStream << findCookies(arg0, arg1 );
+    } break;
+    case 2: { // QStringList findDomains()
+	replyType = KCookieServer_ftable[2][0]; 
+	QDataStream _replyStream( replyData, IO_WriteOnly );
 	_replyStream << findDomains( );
     } break;
-    case 2: { // QStringList findCookies(QValueList<int>,QString,QString,QString,QString)
+    case 3: { // QStringList findCookies(QValueList<int>,QString,QString,QString,QString)
 	QValueList<int> arg0;
 	QString arg1;
 	QString arg2;
@@ -67,19 +79,29 @@
 	arg >> arg2;
 	arg >> arg3;
 	arg >> arg4;
-	replyType = KCookieServer_ftable[2][0]; 
+	replyType = KCookieServer_ftable[3][0]; 
 	QDataStream _replyStream( replyData, IO_WriteOnly );
 	_replyStream << findCookies(arg0, arg1, arg2, arg3, arg4 );
     } break;
-    case 3: { // QString findDOMCookies(QString)
+    case 4: { // QString findDOMCookies(QString)
 	QString arg0;
 	QDataStream arg( data, IO_ReadOnly );
 	arg >> arg0;
-	replyType = KCookieServer_ftable[3][0]; 
+	replyType = KCookieServer_ftable[4][0]; 
 	QDataStream _replyStream( replyData, IO_WriteOnly );
 	_replyStream << findDOMCookies(arg0 );
     } break;
-    case 4: { // void addCookies(QString,QCString,long int)
+    case 5: { // QString findDOMCookies(QString,long int)
+	QString arg0;
+	long int arg1;
+	QDataStream arg( data, IO_ReadOnly );
+	arg >> arg0;
+	arg >> arg1;
+	replyType = KCookieServer_ftable[5][0]; 
+	QDataStream _replyStream( replyData, IO_WriteOnly );
+	_replyStream << findDOMCookies(arg0, arg1 );
+    } break;
+    case 6: { // void addCookies(QString,QCString,long int)
 	QString arg0;
 	QCString arg1;
 	long int arg2;
@@ -87,10 +109,10 @@
 	arg >> arg0;
 	arg >> arg1;
 	arg >> arg2;
-	replyType = KCookieServer_ftable[4][0]; 
+	replyType = KCookieServer_ftable[6][0]; 
 	addCookies(arg0, arg1, arg2 );
     } break;
-    case 5: { // void deleteCookie(QString,QString,QString,QString)
+    case 7: { // void deleteCookie(QString,QString,QString,QString)
 	QString arg0;
 	QString arg1;
 	QString arg2;
@@ -100,37 +122,37 @@
 	arg >> arg1;
 	arg >> arg2;
 	arg >> arg3;
-	replyType = KCookieServer_ftable[5][0]; 
+	replyType = KCookieServer_ftable[7][0]; 
 	deleteCookie(arg0, arg1, arg2, arg3 );
     } break;
-    case 6: { // void deleteCookiesFromDomain(QString)
+    case 8: { // void deleteCookiesFromDomain(QString)
 	QString arg0;
 	QDataStream arg( data, IO_ReadOnly );
 	arg >> arg0;
-	replyType = KCookieServer_ftable[6][0]; 
+	replyType = KCookieServer_ftable[8][0]; 
 	deleteCookiesFromDomain(arg0 );
     } break;
-    case 7: { // void deleteSessionCookies(long int)
+    case 9: { // void deleteSessionCookies(long int)
 	long int arg0;
 	QDataStream arg( data, IO_ReadOnly );
 	arg >> arg0;
-	replyType = KCookieServer_ftable[7][0]; 
+	replyType = KCookieServer_ftable[9][0]; 
 	deleteSessionCookies(arg0 );
     } break;
-    case 8: { // void deleteSessionCookiesFor(QString,long int)
+    case 10: { // void deleteSessionCookiesFor(QString,long int)
 	QString arg0;
 	long int arg1;
 	QDataStream arg( data, IO_ReadOnly );
 	arg >> arg0;
 	arg >> arg1;
-	replyType = KCookieServer_ftable[8][0]; 
+	replyType = KCookieServer_ftable[10][0]; 
 	deleteSessionCookiesFor(arg0, arg1 );
     } break;
-    case 9: { // void deleteAllCookies()
-	replyType = KCookieServer_ftable[9][0]; 
+    case 11: { // void deleteAllCookies()
+	replyType = KCookieServer_ftable[11][0]; 
 	deleteAllCookies( );
     } break;
-    case 10: { // void addDOMCookies(QString,QCString,long int)
+    case 12: { // void addDOMCookies(QString,QCString,long int)
 	QString arg0;
 	QCString arg1;
 	long int arg2;
@@ -138,38 +160,38 @@
 	arg >> arg0;
 	arg >> arg1;
 	arg >> arg2;
-	replyType = KCookieServer_ftable[10][0]; 
+	replyType = KCookieServer_ftable[12][0]; 
 	addDOMCookies(arg0, arg1, arg2 );
     } break;
-    case 11: { // void setDomainAdvice(QString,QString)
+    case 13: { // void setDomainAdvice(QString,QString)
 	QString arg0;
 	QString arg1;
 	QDataStream arg( data, IO_ReadOnly );
 	arg >> arg0;
 	arg >> arg1;
-	replyType = KCookieServer_ftable[11][0]; 
+	replyType = KCookieServer_ftable[13][0]; 
 	setDomainAdvice(arg0, arg1 );
     } break;
-    case 12: { // QString getDomainAdvice(QString)
+    case 14: { // QString getDomainAdvice(QString)
 	QString arg0;
 	QDataStream arg( data, IO_ReadOnly );
 	arg >> arg0;
-	replyType = KCookieServer_ftable[12][0]; 
+	replyType = KCookieServer_ftable[14][0]; 
 	QDataStream _replyStream( replyData, IO_WriteOnly );
 	_replyStream << getDomainAdvice(arg0 );
     } break;
-    case 13: { // void reloadPolicy()
-	replyType = KCookieServer_ftable[13][0]; 
+    case 15: { // void reloadPolicy()
+	replyType = KCookieServer_ftable[15][0]; 
 	reloadPolicy( );
     } break;
-    case 14: { // void shutdown()
-	replyType = KCookieServer_ftable[14][0]; 
+    case 16: { // void shutdown()
+	replyType = KCookieServer_ftable[16][0]; 
 	shutdown( );
     } break;
     default: 
 	return KUniqueApplication::process( fun, data, replyType, replyData );
     }
-    return TRUE;
+    return true;
 }
 
 QCStringList KCookieServer::interfaces()
--- konqueror-embedded-snapshot-20030705/konq-embed/kdesrc/kio/http/http.cc~kcookiejar-merge.patch
+++ konqueror-embedded-snapshot-20030705/konq-embed/kdesrc/kio/http/http.cc
@@ -200,9 +200,9 @@
     kdDebug(7103) << "(" << getpid() << ") Proxy URL is now: " << m_proxyURL.url() << endl;
   }
 
-  m_bUseCookiejar = config()->readBoolEntry("Cookies");
-  m_bUseCache = config()->readBoolEntry("UseCache");
-  m_strCacheDir = config()->readEntry("CacheDir");
+  m_bUseCookiejar = config()->readBoolEntry("Cookies", true);
+  m_bUseCache = config()->readBoolEntry("UseCache", true);
+  m_strCacheDir = config()->readEntry("CacheDir", "/tmp/");
   m_maxCacheAge = config()->readNumEntry("MaxCacheAge");
   m_request.window = config()->readEntry("window-id");