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
|
/* $Xorg: xprint.c,v 1.5 2001/03/05 20:42:26 pookie Exp $ */
/*
(c) Copyright 1996 Hewlett-Packard Company
(c) Copyright 1996 International Business Machines Corp.
(c) Copyright 1996 Sun Microsystems, Inc.
(c) Copyright 1996 Novell, Inc.
(c) Copyright 1996 Digital Equipment Corp.
(c) Copyright 1996 Fujitsu Limited
(c) Copyright 1996 Hitachi, Ltd.
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
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the names of the copyright holders shall
not be used in advertising or otherwise to promote the sale, use or other
dealings in this Software without prior written authorization from said
copyright holders.
*/
/*******************************************************************
**
** *********************************************************
** *
** * File: xprint.c
** *
** * Copyright: Copyright 1993, 1995 Hewlett-Packard Company
** *
** * Copyright 1989 by The Massachusetts Institute of Technology
** *
** * Permission to use, copy, modify, and distribute this
** * software and its documentation for any purpose and without
** * fee is hereby granted, provided that the above copyright
** * notice appear in all copies and that both that copyright
** * notice and this permission notice appear in supporting
** * documentation, and that the name of MIT not be used in
** * advertising or publicity pertaining to distribution of the
** * software without specific prior written permission.
** * M.I.T. makes no representation about the suitability of
** * this software for any purpose. It is provided "as is"
** * without any express or implied warranty.
** *
** * MIT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
** * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT-
** * NESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MIT BE LI-
** * ABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
** * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
** * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
** * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
** * THE USE OR PERFORMANCE OF THIS SOFTWARE.
** *
** *********************************************************
**
********************************************************************/
/* $XFree86: xc/programs/Xserver/Xext/xprint.c,v 1.14tsi Exp $ */
#define _XP_PRINT_SERVER_
#ifdef HAVE_DIX_CONFIG_H
#include <dix-config.h>
#endif
#include <X11/X.h>
#include <X11/Xos.h>
#define NEED_EVENTS
#include <X11/Xproto.h>
#undef NEED_EVENTS
#include "misc.h"
#include "windowstr.h"
#include "scrnintstr.h"
#include "pixmapstr.h"
#include "extnsionst.h"
#include "dixstruct.h"
#include <X11/Xatom.h>
#include <X11/extensions/Print.h>
#include <X11/extensions/Printstr.h>
#include "../hw/xprint/DiPrint.h"
#include "../hw/xprint/attributes.h"
#include "modinit.h"
static void XpResetProc(ExtensionEntry *);
static int ProcXpDispatch(ClientPtr);
static int ProcXpSwappedDispatch(ClientPtr);
static int ProcXpQueryVersion(ClientPtr);
static int ProcXpGetPrinterList(ClientPtr);
static int ProcXpCreateContext(ClientPtr);
static int ProcXpSetContext(ClientPtr);
static int ProcXpGetContext(ClientPtr);
static int ProcXpDestroyContext(ClientPtr);
static int ProcXpGetContextScreen(ClientPtr);
static int ProcXpStartJob(ClientPtr);
static int ProcXpEndJob(ClientPtr);
static int ProcXpStartDoc(ClientPtr);
static int ProcXpEndDoc(ClientPtr);
static int ProcXpStartPage(ClientPtr);
static int ProcXpEndPage(ClientPtr);
static int ProcXpSelectInput(ClientPtr);
static int ProcXpInputSelected(ClientPtr);
static int ProcXpPutDocumentData(ClientPtr);
static int ProcXpGetDocumentData(ClientPtr);
static int ProcXpGetAttributes(ClientPtr);
static int ProcXpGetOneAttribute(ClientPtr);
static int ProcXpSetAttributes(ClientPtr);
static int ProcXpRehashPrinterList(ClientPtr);
static int ProcXpQueryScreens(ClientPtr);
static int ProcXpGetPageDimensions(ClientPtr);
static int ProcXpSetImageResolution(ClientPtr);
static int ProcXpGetImageResolution(ClientPtr);
static void SwapXpNotifyEvent(xPrintPrintEvent *, xPrintPrintEvent *);
static void SwapXpAttributeEvent(xPrintAttributeEvent *, xPrintAttributeEvent *);
static int SProcXpGetPrinterList(ClientPtr);
static int SProcXpCreateContext(ClientPtr);
static int SProcXpSetContext(ClientPtr);
static int SProcXpGetContext(ClientPtr);
static int SProcXpDestroyContext(ClientPtr);
static int SProcXpGetContextScreen(ClientPtr);
static int SProcXpStartJob(ClientPtr);
static int SProcXpEndJob(ClientPtr);
static int SProcXpStartDoc(ClientPtr);
static int SProcXpEndDoc(ClientPtr);
static int SProcXpStartPage(ClientPtr);
static int SProcXpEndPage(ClientPtr);
static int SProcXpSelectInput(ClientPtr);
static int SProcXpInputSelected(ClientPtr);
static int SProcXpPutDocumentData(ClientPtr);
static int SProcXpGetDocumentData(ClientPtr);
static int SProcXpGetAttributes(ClientPtr);
static int SProcXpGetOneAttribute(ClientPtr);
static int SProcXpSetAttributes(ClientPtr);
static int SProcXpRehashPrinterList(ClientPtr);
static int SProcXpGetPageDimensions(ClientPtr);
static int SProcXpSetImageResolution(ClientPtr);
static int SProcXpGetImageResolution(ClientPtr);
static void SendXpNotify(XpContextPtr, int, int);
static void SendAttributeNotify(XpContextPtr, int);
static int XpFreeClient(pointer, XID);
static int XpFreeContext(pointer, XID);
static int XpFreePage(pointer, XID);
static Bool XpCloseScreen(int, ScreenPtr);
static CARD32 GetAllEventMasks(XpContextPtr);
static struct _XpClient *CreateXpClient(ClientPtr);
static void InitContextPrivates(XpContextPtr);
static void ResetContextPrivates(void);
static struct _XpClient *FindClient(XpContextPtr, ClientPtr);
static struct _XpClient *AcquireClient(XpContextPtr, ClientPtr);
typedef struct _driver {
struct _driver *next;
char *name;
int (* CreateContext)(XpContextPtr);
} XpDriverRec, *XpDriverPtr;
typedef struct _xpScreen {
Bool (* CloseScreen)(int, ScreenPtr);
struct _driver *drivers;
} XpScreenRec, *XpScreenPtr;
/*
* Each context has a list of XpClients indicating which clients have
* associated this context with their connection.
* Each such client has a RTclient resource allocated for it,
* and this per-client
* resource is used to delete the XpClientRec if/when the client closes
* its connection.
* The list of XpClients is also walked if/when the context is destroyed
* so that the ContextPtr can be removed from the client's devPrivates.
*/
typedef struct _XpClient {
struct _XpClient *pNext;
ClientPtr client;
XpContextPtr context;
CARD32 eventMask;
XID contextClientID; /* unneeded sanity check? */
} XpClientRec, *XpClientPtr;
static void FreeXpClient(XpClientPtr, Bool);
/*
* Each StartPage request specifies a window which forms the top level
* window of the page. One of the following structs is created as a
* RTpage resource with the same ID as the window itself. This enables
* us to clean up when/if the window is destroyed, and to prevent the
* same window from being simultaneously referenced in multiple contexts.
* The page resource is created at the first StartPage on a given window,
* and is only destroyed when/if the window is destroyed. When the
* EndPage is recieved (or an EndDoc or EndJob) the context field is
* set to NULL, but the resource remains alive.
*/
typedef struct _XpPage {
XpContextPtr context;
} XpPageRec, *XpPagePtr;
typedef struct _XpStPageRec {
XpContextPtr pContext;
Bool slept;
XpPagePtr pPage;
WindowPtr pWin;
} XpStPageRec, *XpStPagePtr;
typedef struct _XpStDocRec {
XpContextPtr pContext;
Bool slept;
CARD8 type;
} XpStDocRec, *XpStDocPtr;
#define QUADPAD(x) ((((x)+3)>>2)<<2)
/*
* Possible bit-mask values in the "state" field of a XpContextRec.
*/
#define JOB_STARTED (1 << 0)
#define DOC_RAW_STARTED (1 << 1)
#define DOC_COOKED_STARTED (1 << 2)
#define PAGE_STARTED (1 << 3)
#define GET_DOC_DATA_STARTED (1 << 4)
#define JOB_GET_DATA (1 << 5)
static XpScreenPtr XpScreens[MAXSCREENS];
static unsigned char XpReqCode;
static int XpEventBase;
static int XpErrorBase;
static unsigned long XpGeneration = 0;
static int XpClientPrivateIndex;
/* Variables for the context private machinery.
* These must be initialized at compile time because
* main() calls InitOutput before InitExtensions, and the
* output drivers are likely to call AllocateContextPrivate.
* These variables are reset at CloseScreen time. CloseScreen
* is used because it occurs after FreeAllResources, and before
* the next InitOutput cycle.
*/
static int contextPrivateCount = 0;
static int contextPrivateLen = 0;
static unsigned *contextPrivateSizes = (unsigned *)NULL;
static unsigned totalContextSize = sizeof(XpContextRec);
/*
* There are three types of resources involved. One is the resource associated
* with the context itself, with an ID specified by a printing client. The
* next is a resource created by us on the client's behalf (and unknown to
* the client) when a client inits or sets a context which allows us to
* track each client's interest in events
* on a particular context, and also allows us to clean up this interest
* record when/if the client's connection is closed. Finally, there is
* a resource created for each window that's specified in a StartPage. This
* resource carries the same ID as the window itself, and enables us to
* easily prevent the same window being referenced in multiple contexts
* simultaneously, and enables us to clean up if the window is destroyed
* before the EndPage.
*/
static RESTYPE RTclient, RTcontext, RTpage;
/*
* allEvents is the OR of all the legal event mask bits.
*/
static CARD32 allEvents = XPPrintMask | XPAttributeMask;
/*******************************************************************************
*
* ExtensionInit, Driver Init functions, QueryVersion, and Dispatch procs
*
******************************************************************************/
/*
* XpExtensionInit
*
* Called from InitExtensions in main() usually through miinitextension
*
*/
void
XpExtensionInit(INITARGS)
{
ExtensionEntry *extEntry;
int i;
RTclient = CreateNewResourceType(XpFreeClient);
RTcontext = CreateNewResourceType(XpFreeContext);
RTpage = CreateNewResourceType(XpFreePage);
if (RTclient && RTcontext && RTpage &&
(extEntry = AddExtension(XP_PRINTNAME, XP_EVENTS, XP_ERRORS,
ProcXpDispatch, ProcXpSwappedDispatch,
XpResetProc, StandardMinorOpcode)))
{
XpReqCode = (unsigned char)extEntry->base;
XpEventBase = extEntry->eventBase;
XpErrorBase = extEntry->errorBase;
EventSwapVector[XpEventBase] = (EventSwapPtr) SwapXpNotifyEvent;
EventSwapVector[XpEventBase+1] = (EventSwapPtr) SwapXpAttributeEvent;
}
if(XpGeneration != serverGeneration)
{
XpClientPrivateIndex = AllocateClientPrivateIndex();
/*
* We allocate 0 length & simply stuff a pointer to the
* ContextRec in the DevUnion.
*/
if(AllocateClientPrivate(XpClientPrivateIndex, 0) != TRUE)
{
/* we can't alloc a client private, should we bail??? XXX */
}
XpGeneration = serverGeneration;
}
for(i = 0; i < MAXSCREENS; i++)
{
/*
* If a screen has registered with our extension, then we
* wrap the screen's CloseScreen function to allow us to
* reset our ContextPrivate stuff. Note that this
* requires a printing DDX to call XpRegisterInitFunc
* _before_ this extension is initialized - i.e. at screen init
* time, _not_ at root window creation time.
*/
if(XpScreens[i] != (XpScreenPtr)NULL)
{
XpScreens[i]->CloseScreen = screenInfo.screens[i]->CloseScreen;
screenInfo.screens[i]->CloseScreen = XpCloseScreen;
}
}
DeclareExtensionSecurity(XP_PRINTNAME, TRUE);
}
static void
XpResetProc(ExtensionEntry *extEntry)
{
/*
* We can't free up the XpScreens recs here, because extensions are
* closed before screens, and our CloseScreen function uses the XpScreens
* recs.
int i;
for(i = 0; i < MAXSCREENS; i++)
{
if(XpScreens[i] != (XpScreenPtr)NULL)
Xfree(XpScreens[i]);
XpScreens[i] = (XpScreenPtr)NULL;
}
*/
}
static Bool
XpCloseScreen(int index, ScreenPtr pScreen)
{
Bool (* CloseScreen)(int, ScreenPtr);
CloseScreen = XpScreens[index]->CloseScreen;
if(XpScreens[index] != (XpScreenPtr)NULL)
{
XpDriverPtr pDriv, nextDriv;
pDriv = XpScreens[index]->drivers;
while(pDriv != (XpDriverPtr)NULL)
{
nextDriv = pDriv->next;
Xfree(pDriv);
pDriv = nextDriv;
}
Xfree(XpScreens[index]);
}
XpScreens[index] = (XpScreenPtr)NULL;
/*
* It's wasteful to call ResetContextPrivates() at every CloseScreen,
* but it's the best we know how to do for now. We do this because we
* have to wait until after all resources have been freed (so we know
* how to free the ContextRecs), and before the next InitOutput cycle.
* See dix/main.c for the order of initialization and reset.
*/
ResetContextPrivates();
return (*CloseScreen)(index, pScreen);
}
#if 0 /* NOT USED */
static void
FreeScreenEntry(XpScreenPtr pScreenEntry)
{
XpDriverPtr pDriver;
pDriver = pScreenEntry->drivers;
while(pDriver != (XpDriverPtr)NULL)
{
XpDriverPtr tmp;
tmp = pDriver->next;
xfree(pDriver);
pDriver = tmp;
}
xfree(pScreenEntry);
}
#endif
/*
* XpRegisterInitFunc tells the print extension which screens
* are printers as opposed to displays, and what drivers are
* supported on each screen. This eliminates the need of
* allocating print-related private structures on windows on _all_ screens.
* It also hands the extension a pointer to the routine to be called
* whenever a context gets created for a particular driver on this screen.
*/
void
XpRegisterInitFunc(ScreenPtr pScreen, char *driverName, int (*initContext)(struct _XpContext *))
{
XpDriverPtr pDriver;
if(XpScreens[pScreen->myNum] == 0)
{
if((XpScreens[pScreen->myNum] =
(XpScreenPtr) Xalloc(sizeof(XpScreenRec))) == 0)
return;
XpScreens[pScreen->myNum]->CloseScreen = 0;
XpScreens[pScreen->myNum]->drivers = 0;
}
if((pDriver = (XpDriverPtr)Xalloc(sizeof(XpDriverRec))) == 0)
return;
pDriver->next = XpScreens[pScreen->myNum]->drivers;
pDriver->name = driverName;
pDriver->CreateContext = initContext;
XpScreens[pScreen->myNum]->drivers = pDriver;
}
static int
ProcXpDispatch(ClientPtr client)
{
REQUEST(xReq);
switch(stuff->data)
{
case X_PrintQueryVersion:
return ProcXpQueryVersion(client);
case X_PrintGetPrinterList:
return ProcXpGetPrinterList(client);
case X_PrintCreateContext:
return ProcXpCreateContext(client);
case X_PrintSetContext:
return ProcXpSetContext(client);
case X_PrintGetContext:
return ProcXpGetContext(client);
case X_PrintDestroyContext:
return ProcXpDestroyContext(client);
case X_PrintGetContextScreen:
return ProcXpGetContextScreen(client);
case X_PrintStartJob:
return ProcXpStartJob(client);
case X_PrintEndJob:
return ProcXpEndJob(client);
case X_PrintStartDoc:
return ProcXpStartDoc(client);
case X_PrintEndDoc:
return ProcXpEndDoc(client);
case X_PrintStartPage:
return ProcXpStartPage(client);
case X_PrintEndPage:
return ProcXpEndPage(client);
case X_PrintSelectInput:
return ProcXpSelectInput(client);
case X_PrintInputSelected:
return ProcXpInputSelected(client);
case X_PrintPutDocumentData:
return ProcXpPutDocumentData(client);
case X_PrintGetDocumentData:
return ProcXpGetDocumentData(client);
case X_PrintSetAttributes:
return ProcXpSetAttributes(client);
case X_PrintGetAttributes:
return ProcXpGetAttributes(client);
case X_PrintGetOneAttribute:
return ProcXpGetOneAttribute(client);
case X_PrintRehashPrinterList:
return ProcXpRehashPrinterList(client);
case X_PrintQueryScreens:
return ProcXpQueryScreens(client);
case X_PrintGetPageDimensions:
return ProcXpGetPageDimensions(client);
case X_PrintSetImageResolution:
return ProcXpSetImageResolution(client);
case X_PrintGetImageResolution:
return ProcXpGetImageResolution(client);
default:
return BadRequest;
}
}
static int
ProcXpSwappedDispatch(ClientPtr client)
{
int temp;
REQUEST(xReq);
switch(stuff->data)
{
case X_PrintQueryVersion:
swaps(&stuff->length, temp);
return ProcXpQueryVersion(client);
case X_PrintGetPrinterList:
return SProcXpGetPrinterList(client);
case X_PrintCreateContext:
return SProcXpCreateContext(client);
case X_PrintSetContext:
return SProcXpSetContext(client);
case X_PrintGetContext:
return SProcXpGetContext(client);
case X_PrintDestroyContext:
return SProcXpDestroyContext(client);
case X_PrintGetContextScreen:
return SProcXpGetContextScreen(client);
case X_PrintStartJob:
return SProcXpStartJob(client);
case X_PrintEndJob:
return SProcXpEndJob(client);
case X_PrintStartDoc:
return SProcXpStartDoc(client);
case X_PrintEndDoc:
return SProcXpEndDoc(client);
case X_PrintStartPage:
return SProcXpStartPage(client);
case X_PrintEndPage:
return SProcXpEndPage(client);
case X_PrintSelectInput:
return SProcXpSelectInput(client);
case X_PrintInputSelected:
return SProcXpInputSelected(client);
case X_PrintPutDocumentData:
return SProcXpPutDocumentData(client);
case X_PrintGetDocumentData:
return SProcXpGetDocumentData(client);
case X_PrintSetAttributes:
return SProcXpSetAttributes(client);
case X_PrintGetAttributes:
return SProcXpGetAttributes(client);
case X_PrintGetOneAttribute:
return SProcXpGetOneAttribute(client);
case X_PrintRehashPrinterList:
return SProcXpRehashPrinterList(client);
case X_PrintQueryScreens:
swaps(&stuff->length, temp);
return ProcXpQueryScreens(client);
case X_PrintGetPageDimensions:
return SProcXpGetPageDimensions(client);
case X_PrintSetImageResolution:
return SProcXpSetImageResolution(client);
case X_PrintGetImageResolution:
return SProcXpGetImageResolution(client);
default:
return BadRequest;
}
}
static int
ProcXpQueryVersion(ClientPtr client)
{
/* REQUEST(xPrintQueryVersionReq); */
xPrintQueryVersionReply rep;
register int n;
long l;
REQUEST_SIZE_MATCH(xPrintQueryVersionReq);
rep.type = X_Reply;
rep.length = 0;
rep.sequenceNumber = client->sequence;
rep.majorVersion = XP_MAJOR_VERSION;
rep.minorVersion = XP_MINOR_VERSION;
if (client->swapped) {
swaps(&rep.sequenceNumber, n);
swapl(&rep.length, l);
swaps(&rep.majorVersion, n);
swaps(&rep.minorVersion, n);
}
WriteToClient(client, sz_xPrintQueryVersionReply, (char *)&rep);
return client->noClientException;
}
/*******************************************************************************
*
* GetPrinterList : Return a list of all printers associated with this
* server. Calls XpDiGetPrinterList, which is defined in
* the device-independent code in Xserver/Xprint.
*
******************************************************************************/
static int
ProcXpGetPrinterList(ClientPtr client)
{
REQUEST(xPrintGetPrinterListReq);
int totalSize;
int numEntries;
XpDiListEntry **pList;
xPrintGetPrinterListReply *rep;
int n, i, totalBytes;
long l;
char *curByte;
REQUEST_AT_LEAST_SIZE(xPrintGetPrinterListReq);
totalSize = ((sz_xPrintGetPrinterListReq) >> 2) +
((stuff->printerNameLen + 3) >> 2) +
((stuff->localeLen + 3) >> 2);
if(totalSize != client->req_len)
return BadLength;
pList = XpDiGetPrinterList(stuff->printerNameLen, (char *)(stuff + 1),
stuff->localeLen, (char *)((stuff + 1) +
QUADPAD(stuff->printerNameLen)));
for(numEntries = 0, totalBytes = sz_xPrintGetPrinterListReply;
pList[numEntries] != (XpDiListEntry *)NULL;
numEntries++)
{
totalBytes += 2 * sizeof(CARD32);
totalBytes += QUADPAD(strlen(pList[numEntries]->name));
totalBytes += QUADPAD(strlen(pList[numEntries]->description));
}
if((rep = (xPrintGetPrinterListReply *)xalloc(totalBytes)) ==
(xPrintGetPrinterListReply *)NULL)
return BadAlloc;
rep->type = X_Reply;
rep->length = (totalBytes - sz_xPrintGetPrinterListReply) >> 2;
rep->sequenceNumber = client->sequence;
rep->listCount = numEntries;
if (client->swapped) {
swaps(&rep->sequenceNumber, n);
swapl(&rep->length, l);
swapl(&rep->listCount, l);
}
for(i = 0, curByte = (char *)(rep + 1); i < numEntries; i++)
{
CARD32 *pCrd;
int len;
pCrd = (CARD32 *)curByte;
len = strlen(pList[i]->name);
*pCrd = len;
if (client->swapped)
swapl((long *)curByte, l);
curByte += sizeof(CARD32);
strncpy(curByte, pList[i]->name, len);
curByte += QUADPAD(len);
pCrd = (CARD32 *)curByte;
len = strlen(pList[i]->description);
*pCrd = len;
if (client->swapped)
swapl((long *)curByte, l);
curByte += sizeof(CARD32);
strncpy(curByte, pList[i]->description, len);
curByte += QUADPAD(len);
}
XpDiFreePrinterList(pList);
WriteToClient(client, totalBytes, (char *)rep);
xfree(rep);
return client->noClientException;
}
/*******************************************************************************
*
* QueryScreens: Returns the list of screens which are associated with
* print drivers.
*
******************************************************************************/
static int
ProcXpQueryScreens(ClientPtr client)
{
/* REQUEST(xPrintQueryScreensReq); */
int i, numPrintScreens, totalSize;
WINDOW *pWinId;
xPrintQueryScreensReply *rep;
long l;
REQUEST_SIZE_MATCH(xPrintQueryScreensReq);
rep = (xPrintQueryScreensReply *)xalloc(sz_xPrintQueryScreensReply);
pWinId = (WINDOW *)(rep + 1);
for(i = 0, numPrintScreens = 0, totalSize = sz_xPrintQueryScreensReply;
i < MAXSCREENS; i++)
{
/*
* If a screen has registered with our extension, then it's
* a printer screen.
*/
if(XpScreens[i] != (XpScreenPtr)NULL)
{
numPrintScreens++;
totalSize += sizeof(WINDOW);
rep = (xPrintQueryScreensReply *)xrealloc(rep, totalSize);
/* fix of bug: pWinId should be set again after reallocate rep */
pWinId = (WINDOW *)(rep + 1);
*pWinId = WindowTable[i]->drawable.id;
if (client->swapped)
swapl((long *)pWinId, l);
}
}
rep->type = X_Reply;
rep->sequenceNumber = client->sequence;
rep->length = (totalSize - sz_xPrintQueryScreensReply) >> 2;
rep->listCount = numPrintScreens;
if (client->swapped)
{
int n;
swaps(&rep->sequenceNumber, n);
swapl(&rep->length, l);
swapl(&rep->listCount, l);
}
WriteToClient(client, totalSize, (char *)rep);
xfree(rep);
return client->noClientException;
}
static int
ProcXpGetPageDimensions(ClientPtr client)
{
REQUEST(xPrintGetPageDimensionsReq);
CARD16 width, height;
xRectangle rect;
xPrintGetPageDimensionsReply rep;
XpContextPtr pContext;
int result;
REQUEST_SIZE_MATCH(xPrintGetPageDimensionsReq);
if((pContext =(XpContextPtr)SecurityLookupIDByType(client,
stuff->printContext,
RTcontext,
SecurityReadAccess))
== (XpContextPtr)NULL)
{
client->errorValue = stuff->printContext;
return XpErrorBase+XPBadContext;
}
if((pContext->funcs.GetMediumDimensions == 0) ||
(pContext->funcs.GetReproducibleArea == 0))
return BadImplementation;
result = pContext->funcs.GetMediumDimensions(pContext, &width, &height);
if(result != Success)
return result;
result = pContext->funcs.GetReproducibleArea(pContext, &rect);
if(result != Success)
return result;
rep.type = X_Reply;
rep.sequenceNumber = client->sequence;
rep.length = 0;
rep.width = width;
rep.height = height;
rep.rx = rect.x;
rep.ry = rect.y;
rep.rwidth = rect.width;
rep.rheight = rect.height;
if(client->swapped)
{
int n;
long l;
swaps(&rep.sequenceNumber, n);
swapl(&rep.length, l);
swaps(&rep.width, n);
swaps(&rep.height, n);
swaps(&rep.rx, n);
swaps(&rep.ry, n);
swaps(&rep.rwidth, n);
swaps(&rep.rheight, n);
}
WriteToClient(client, sz_xPrintGetPageDimensionsReply, (char *)&rep);
return client->noClientException;
}
static int
ProcXpSetImageResolution(ClientPtr client)
{
REQUEST(xPrintSetImageResolutionReq);
xPrintSetImageResolutionReply rep;
XpContextPtr pContext;
Bool status;
int result;
REQUEST_SIZE_MATCH(xPrintSetImageResolutionReq);
if((pContext =(XpContextPtr)SecurityLookupIDByType(client,
stuff->printContext,
RTcontext,
SecurityWriteAccess))
== (XpContextPtr)NULL)
{
client->errorValue = stuff->printContext;
return XpErrorBase+XPBadContext;
}
rep.prevRes = pContext->imageRes;
if(pContext->funcs.SetImageResolution != 0) {
result = pContext->funcs.SetImageResolution(pContext,
(int)stuff->imageRes,
&status);
if(result != Success)
status = FALSE;
} else
status = FALSE;
rep.type = X_Reply;
rep.sequenceNumber = client->sequence;
rep.length = 0;
rep.status = status;
if(client->swapped)
{
int n;
long l;
swaps(&rep.sequenceNumber, n);
swapl(&rep.length, l);
swaps(&rep.prevRes, n);
}
WriteToClient(client, sz_xPrintSetImageResolutionReply, (char *)&rep);
return client->noClientException;
}
static int
ProcXpGetImageResolution(ClientPtr client)
{
REQUEST(xPrintGetImageResolutionReq);
xPrintGetImageResolutionReply rep;
XpContextPtr pContext;
REQUEST_SIZE_MATCH(xPrintGetImageResolutionReq);
if((pContext =(XpContextPtr)SecurityLookupIDByType(client,
stuff->printContext,
RTcontext,
SecurityReadAccess))
== (XpContextPtr)NULL)
{
client->errorValue = stuff->printContext;
return XpErrorBase+XPBadContext;
}
rep.type = X_Reply;
rep.sequenceNumber = client->sequence;
rep.length = 0;
rep.imageRes = pContext->imageRes;
if(client->swapped)
{
int n;
long l;
swaps(&rep.sequenceNumber, n);
swapl(&rep.length, l);
swaps(&rep.imageRes, n);
}
WriteToClient(client, sz_xPrintGetImageResolutionReply, (char *)&rep);
return client->noClientException;
}
/*******************************************************************************
*
* RehashPrinterList : Cause the server's list of printers to be rebuilt.
* This allows new printers to be added, or old ones
* deleted without needing to restart the server.
*
******************************************************************************/
static int
ProcXpRehashPrinterList(ClientPtr client)
{
/* REQUEST(xPrintRehashPrinterListReq); */
REQUEST_SIZE_MATCH(xPrintRehashPrinterListReq);
return XpRehashPrinterList();
}
/******************************************************************************
*
* Context functions: Init, Set, Destroy, FreeContext
* AllocateContextPrivateIndex, AllocateContextPrivate
* and supporting functions.
*
* Init creates a context, creates a XpClientRec for the calling
* client, and stores the contextPtr in the client's devPrivates.
*
* Set creates a XpClientRec for the calling client, and stores the
* contextPtr in the client's devPrivates unless the context is None.
* If the context is None, then the client's connection association
* with any context is removed.
*
* Destroy frees any and all XpClientRecs associated with the context,
* frees the context itself, and removes the contextPtr from any
* relevant client devPrivates.
*
* FreeContext is called by FreeResource to free up a context.
*
******************************************************************************/
/*
* CreateContext creates and initializes the memory for the context itself.
* The driver's CreateContext function
* is then called.
*/
static int
ProcXpCreateContext(ClientPtr client)
{
REQUEST(xPrintCreateContextReq);
XpScreenPtr pPrintScreen;
WindowPtr pRoot;
char *driverName;
XpContextPtr pContext;
int result = Success;
XpDriverPtr pDriver;
REQUEST_AT_LEAST_SIZE(xPrintCreateContextReq);
LEGAL_NEW_RESOURCE(stuff->contextID, client);
/*
* Check to see if the printer name is valid.
*/
if((pRoot = XpDiValidatePrinter((char *)(stuff + 1), stuff->printerNameLen)) ==
(WindowPtr)NULL)
return BadMatch;
pPrintScreen = XpScreens[pRoot->drawable.pScreen->myNum];
/*
* Allocate and add the context resource.
*/
if((pContext = (XpContextPtr) xalloc(totalContextSize)) ==
(XpContextPtr) NULL)
return BadAlloc;
InitContextPrivates(pContext);
if(AddResource(stuff->contextID, RTcontext, (pointer) pContext)
!= TRUE)
{
xfree(pContext);
return BadAlloc;
}
pContext->contextID = stuff->contextID;
pContext->clientHead = (XpClientPtr)NULL;
pContext->screenNum = pRoot->drawable.pScreen->myNum;
pContext->state = 0;
pContext->clientSlept = (ClientPtr)NULL;
pContext->imageRes = 0;
pContext->funcs.DestroyContext = 0;
pContext->funcs.StartJob = 0;
pContext->funcs.EndJob = 0;
pContext->funcs.StartDoc = 0;
pContext->funcs.EndDoc = 0;
pContext->funcs.StartPage = 0;
pContext->funcs.EndPage = 0;
pContext->funcs.PutDocumentData = 0;
pContext->funcs.GetDocumentData = 0;
pContext->funcs.GetAttributes = 0;
pContext->funcs.GetOneAttribute = 0;
pContext->funcs.SetAttributes = 0;
pContext->funcs.AugmentAttributes = 0;
pContext->funcs.GetMediumDimensions = 0;
pContext->funcs.GetReproducibleArea = 0;
pContext->funcs.SetImageResolution = 0;
if((pContext->printerName = (char *)xalloc(stuff->printerNameLen + 1)) ==
(char *)NULL)
{
/* Freeing the context also causes the XpClients to be freed. */
FreeResource(stuff->contextID, RT_NONE);
return BadAlloc;
}
strncpy(pContext->printerName, (char *)(stuff + 1), stuff->printerNameLen);
pContext->printerName[stuff->printerNameLen] = (char)'\0';
driverName = XpDiGetDriverName(pRoot->drawable.pScreen->myNum,
pContext->printerName);
for(pDriver = pPrintScreen->drivers;
pDriver != (XpDriverPtr)NULL;
pDriver = pDriver->next)
{
if(!strcmp(driverName, pDriver->name))
{
if(pDriver->CreateContext != 0)
pDriver->CreateContext(pContext);
else
return BadImplementation;
break;
}
}
if (client->noClientException != Success)
return client->noClientException;
else
return result;
}
/*
* SetContext creates the calling client's contextClient resource,
* and stashes the contextID in the client's devPrivate.
*/
static int
ProcXpSetContext(ClientPtr client)
{
REQUEST(xPrintSetContextReq);
XpContextPtr pContext;
XpClientPtr pPrintClient;
int result = Success;
REQUEST_AT_LEAST_SIZE(xPrintSetContextReq);
if((pContext = client->devPrivates[XpClientPrivateIndex].ptr) !=
(pointer)NULL)
{
/*
* Erase this client's knowledge of its old context, if any.
*/
if((pPrintClient = FindClient(pContext, client)) != (XpClientPtr)NULL)
{
XpUnsetFontResFunc(client);
if(pPrintClient->eventMask == 0)
FreeXpClient(pPrintClient, TRUE);
}
client->devPrivates[XpClientPrivateIndex].ptr = (pointer)NULL;
}
if(stuff->printContext == None)
return Success;
/*
* Check to see that the supplied XID is really a valid print context
* in this server.
*/
if((pContext =(XpContextPtr)SecurityLookupIDByType(client,
stuff->printContext,
RTcontext,
SecurityWriteAccess))
== (XpContextPtr)NULL)
{
client->errorValue = stuff->printContext;
return XpErrorBase+XPBadContext;
}
if((pPrintClient = AcquireClient(pContext, client)) == (XpClientPtr)NULL)
return BadAlloc;
client->devPrivates[XpClientPrivateIndex].ptr = pContext;
XpSetFontResFunc(client);
if (client->noClientException != Success)
return client->noClientException;
else
return result;
}
XpContextPtr
XpGetPrintContext(ClientPtr client)
{
return (client->devPrivates[XpClientPrivateIndex].ptr);
}
static int
ProcXpGetContext(ClientPtr client)
{
/* REQUEST(xPrintGetContextReq); */
xPrintGetContextReply rep;
XpContextPtr pContext;
register int n;
register long l;
REQUEST_SIZE_MATCH(xPrintGetContextReq);
if((pContext = client->devPrivates[XpClientPrivateIndex].ptr) ==
(pointer)NULL)
rep.printContext = None;
else
rep.printContext = pContext->contextID;
rep.type = X_Reply;
rep.length = 0;
rep.sequenceNumber = client->sequence;
if (client->swapped) {
swaps(&rep.sequenceNumber, n);
swapl(&rep.length, l);
swapl(&rep.printContext, l);
}
WriteToClient(client, sz_xPrintGetContextReply, (char *)&rep);
return client->noClientException;
}
/*
* DestroyContext frees the context associated with the calling client.
* It operates by freeing the context resource ID, thus causing XpFreeContext
* to be called.
*/
static int
ProcXpDestroyContext(ClientPtr client)
{
REQUEST(xPrintDestroyContextReq);
XpContextPtr pContext;
REQUEST_SIZE_MATCH(xPrintDestroyContextReq);
if((pContext =(XpContextPtr)SecurityLookupIDByType(client,
stuff->printContext,
RTcontext,
SecurityDestroyAccess))
== (XpContextPtr)NULL)
{
client->errorValue = stuff->printContext;
return XpErrorBase+XPBadContext;
}
XpUnsetFontResFunc(client);
FreeResource(pContext->contextID, RT_NONE);
return Success;
}
static int
ProcXpGetContextScreen(ClientPtr client)
{
REQUEST(xPrintGetContextScreenReq);
xPrintGetContextScreenReply rep;
XpContextPtr pContext;
int n;
long l;
if((pContext =(XpContextPtr)SecurityLookupIDByType(client,
stuff->printContext,
RTcontext,
SecurityReadAccess))
== (XpContextPtr)NULL)
return XpErrorBase+XPBadContext;
rep.type = X_Reply;
rep.sequenceNumber = client->sequence;
rep.length = 0;
rep.rootWindow = WindowTable[pContext->screenNum]->drawable.id;
if (client->swapped) {
swaps(&rep.sequenceNumber, n);
swapl(&rep.length, l);
swapl(&rep.rootWindow, l);
}
WriteToClient(client, sz_xPrintGetContextScreenReply, (char *)&rep);
return client->noClientException;
}
/*
* XpFreeContext is the routine called by dix:FreeResource when a context
* resource ID is freed.
* It checks to see if there's a partial job pending on the context, and
* if so it calls the appropriate End procs with the cancel flag set.
* It calls the driver's DestroyContext routine to allow the driver to clean
* up any context-related memory or state.
* It calls FreeXpClient to free all the
* associated XpClientRecs and to set all the client->devPrivates to NULL.
* It frees the printer name string, and frees the context
* itself.
*/
static int
XpFreeContext(pointer data, XID id)
{
XpContextPtr pContext = (XpContextPtr)data;
/* Clean up any pending job on this context */
if(pContext->state != 0)
{
if(pContext->state & PAGE_STARTED)
{
WindowPtr pWin = (WindowPtr )LookupIDByType(
pContext->pageWin, RT_WINDOW);
XpPagePtr pPage = (XpPagePtr)LookupIDByType(
pContext->pageWin, RTpage);
pContext->funcs.EndPage(pContext, pWin);
SendXpNotify(pContext, XPEndPageNotify, TRUE);
pContext->state &= ~PAGE_STARTED;
if(pPage)
pPage->context = (XpContextPtr)NULL;
}
if((pContext->state & DOC_RAW_STARTED) ||
(pContext->state & DOC_COOKED_STARTED))
{
pContext->funcs.EndDoc(pContext, TRUE);
SendXpNotify(pContext, XPEndDocNotify, TRUE);
pContext->state &= ~DOC_RAW_STARTED;
pContext->state &= ~DOC_COOKED_STARTED;
}
if(pContext->funcs.EndJob != 0)
{
pContext->funcs.EndJob(pContext, TRUE);
SendXpNotify(pContext, XPEndJobNotify, TRUE);
pContext->state &= ~JOB_STARTED;
pContext->state &= ~GET_DOC_DATA_STARTED;
}
}
/*
* Tell the driver we're destroying the context
* This allows the driver to free and ContextPrivate data
*/
if(pContext->funcs.DestroyContext != 0)
pContext->funcs.DestroyContext(pContext);
/* Free up all the XpClientRecs */
while(pContext->clientHead != (XpClientPtr)NULL)
{
FreeXpClient(pContext->clientHead, TRUE);
}
xfree(pContext->printerName);
xfree(pContext);
return Success; /* ??? */
}
/*
* XpFreeClient is the routine called by dix:FreeResource when a RTclient
* is freed. It simply calls the FreeXpClient routine to do the work.
*/
static int
XpFreeClient(pointer data, XID id)
{
FreeXpClient((XpClientPtr)data, TRUE);
return Success;
}
/*
* FreeXpClient
* frees the ClientRec passed in, and sets the client->devPrivates to NULL
* if the client->devPrivates points to the same context as the XpClient.
* Called from XpFreeContext(from FreeResource), and
* XpFreeClient. The boolean freeResource specifies whether or not to call
* FreeResource for the XpClientRec's XID. We should free it except if we're
* called from XpFreeClient (which is itself called from FreeResource for the
* XpClientRec's XID).
*/
static void
FreeXpClient(XpClientPtr pXpClient, Bool freeResource)
{
XpClientPtr pCurrent, pPrev;
XpContextPtr pContext = pXpClient->context;
/*
* If we're freeing the clientRec associated with the context tied
* to the client's devPrivates, then we need to clear the devPrivates.
*/
if(pXpClient->client->devPrivates[XpClientPrivateIndex].ptr ==
pXpClient->context)
{
pXpClient->client->devPrivates[XpClientPrivateIndex].ptr =
(pointer)NULL;
}
for(pPrev = (XpClientPtr)NULL, pCurrent = pContext->clientHead;
pCurrent != (XpClientPtr)NULL;
pCurrent = pCurrent->pNext)
{
if(pCurrent == pXpClient)
{
if(freeResource == TRUE)
FreeResource (pCurrent->contextClientID, RTclient);
if (pPrev != (XpClientPtr)NULL)
pPrev->pNext = pCurrent->pNext;
else
pContext->clientHead = pCurrent->pNext;
xfree (pCurrent);
break;
}
pPrev = pCurrent;
}
}
/*
* CreateXpClient takes a ClientPtr and returns a pointer to a
* XpClientRec which it allocates. It also initializes the Rec,
* including adding a resource on behalf of the client to enable the
* freeing of the Rec when the client's connection is closed.
*/
static XpClientPtr
CreateXpClient(ClientPtr client)
{
XpClientPtr pNewPrintClient;
XID clientResource;
if((pNewPrintClient = (XpClientPtr)xalloc(sizeof(XpClientRec))) ==
(XpClientPtr)NULL)
return (XpClientPtr)NULL;
clientResource = FakeClientID(client->index);
if(!AddResource(clientResource, RTclient, (pointer)pNewPrintClient))
{
xfree (pNewPrintClient);
return (XpClientPtr)NULL;
}
pNewPrintClient->pNext = (XpClientPtr)NULL;
pNewPrintClient->client = client;
pNewPrintClient->context = (XpContextPtr)NULL;
pNewPrintClient->eventMask = 0;
pNewPrintClient->contextClientID = clientResource;
return pNewPrintClient;
}
/*
* XpFreePage is the routine called by dix:FreeResource to free the page
* resource built with the same ID as a page window. It checks to see
* if we're in the middle of a page, and if so calls the driver's EndPage
* function with 'cancel' set TRUE. It frees the memory associated with
* the page resource.
*/
static int
XpFreePage(pointer data, XID id)
{
XpPagePtr page = (XpPagePtr)data;
int result = Success;
WindowPtr pWin = (WindowPtr )LookupIDByType(id, RT_WINDOW);
/* Check to see if the window's being deleted in the middle of a page */
if(page->context != (XpContextPtr)NULL &&
page->context->state & PAGE_STARTED)
{
if(page->context->funcs.EndPage != 0)
result = page->context->funcs.EndPage(page->context, pWin);
SendXpNotify(page->context, XPEndPageNotify, (int)TRUE);
page->context->pageWin = 0; /* None, NULL??? XXX */
}
xfree(page);
return result;
}
/*
* ContextPrivate machinery.
* Context privates are intended for use by the drivers, allowing the
* drivers to maintain context-specific data. The driver should free
* the associated data at DestroyContext time.
*/
static void
InitContextPrivates(XpContextPtr context)
{
register char *ptr;
DevUnion *ppriv;
register unsigned *sizes;
register unsigned size;
register int i;
if (totalContextSize == sizeof(XpContextRec))
ppriv = (DevUnion *)NULL;
else
ppriv = (DevUnion *)(context + 1);
context->devPrivates = ppriv;
sizes = contextPrivateSizes;
ptr = (char *)(ppriv + contextPrivateLen);
for (i = contextPrivateLen; --i >= 0; ppriv++, sizes++)
{
if ( (size = *sizes) )
{
ppriv->ptr = (pointer)ptr;
ptr += size;
}
else
ppriv->ptr = (pointer)NULL;
}
}
static void
ResetContextPrivates(void)
{
contextPrivateCount = 0;
contextPrivateLen = 0;
xfree(contextPrivateSizes);
contextPrivateSizes = (unsigned *)NULL;
totalContextSize = sizeof(XpContextRec);
}
int
XpAllocateContextPrivateIndex(void)
{
return contextPrivateCount++;
}
Bool
XpAllocateContextPrivate(int index, unsigned amount)
{
unsigned oldamount;
if (index >= contextPrivateLen)
{
unsigned *nsizes;
nsizes = (unsigned *)xrealloc(contextPrivateSizes,
(index + 1) * sizeof(unsigned));
if (!nsizes)
return FALSE;
while (contextPrivateLen <= index)
{
nsizes[contextPrivateLen++] = 0;
totalContextSize += sizeof(DevUnion);
}
contextPrivateSizes = nsizes;
}
oldamount = contextPrivateSizes[index];
if (amount > oldamount)
{
contextPrivateSizes[index] = amount;
totalContextSize += (amount - oldamount);
}
return TRUE;
}
static XpClientPtr
AcquireClient(XpContextPtr pContext, ClientPtr client)
{
XpClientPtr pXpClient;
if((pXpClient = FindClient(pContext, client)) != (XpClientPtr)NULL)
return pXpClient;
if((pXpClient = CreateXpClient(client)) == (XpClientPtr)NULL)
return (XpClientPtr)NULL;
pXpClient->context = pContext;
pXpClient->pNext = pContext->clientHead;
pContext->clientHead = pXpClient;
return pXpClient;
}
static XpClientPtr
FindClient(XpContextPtr pContext, ClientPtr client)
{
XpClientPtr pXpClient;
for(pXpClient = pContext->clientHead; pXpClient != (XpClientPtr)NULL;
pXpClient = pXpClient->pNext)
{
if(pXpClient->client == client) return pXpClient;
}
return (XpClientPtr)NULL;
}
/******************************************************************************
*
* Start/End Functions: StartJob, EndJob, StartDoc, EndDoc, StartPage, EndPage
*
******************************************************************************/
static int
ProcXpStartJob(ClientPtr client)
{
REQUEST(xPrintStartJobReq);
XpContextPtr pContext;
int result = Success;
REQUEST_SIZE_MATCH(xPrintStartJobReq);
/* Check to see that a context has been established by this client. */
if((pContext = (XpContextPtr)client->devPrivates[XpClientPrivateIndex].ptr)
== (XpContextPtr)NULL)
return XpErrorBase+XPBadContext;
if(pContext->state != 0)
return XpErrorBase+XPBadSequence;
if(stuff->saveData != XPSpool && stuff->saveData != XPGetData)
{
client->errorValue = stuff->saveData;
return BadValue;
}
if(pContext->funcs.StartJob != 0)
result = pContext->funcs.StartJob(pContext,
(stuff->saveData == XPGetData)? TRUE:FALSE,
client);
else
return BadImplementation;
pContext->state = JOB_STARTED;
if(stuff->saveData == XPGetData)
pContext->state |= JOB_GET_DATA;
SendXpNotify(pContext, XPStartJobNotify, FALSE);
if (client->noClientException != Success)
return client->noClientException;
else
return result;
}
static int
ProcXpEndJob(ClientPtr client)
{
REQUEST(xPrintEndJobReq);
int result = Success;
XpContextPtr pContext;
REQUEST_SIZE_MATCH(xPrintEndJobReq);
if((pContext = (XpContextPtr)client->devPrivates[XpClientPrivateIndex].ptr)
== (XpContextPtr)NULL)
return XpErrorBase+XPBadSequence;
if(!(pContext->state & JOB_STARTED))
return XpErrorBase+XPBadSequence;
/* Check for missing EndDoc */
if((pContext->state & DOC_RAW_STARTED) ||
(pContext->state & DOC_COOKED_STARTED))
{
if(pContext->state & PAGE_STARTED)
{
WindowPtr pWin = (WindowPtr )LookupIDByType(
pContext->pageWin, RT_WINDOW);
XpPagePtr pPage = (XpPagePtr)LookupIDByType(
pContext->pageWin, RTpage);
if(stuff->cancel != TRUE)
return XpErrorBase+XPBadSequence;
if(pContext->funcs.EndPage != 0)
result = pContext->funcs.EndPage(pContext, pWin);
else
return BadImplementation;
SendXpNotify(pContext, XPEndPageNotify, TRUE);
pContext->state &= ~PAGE_STARTED;
if(pPage)
pPage->context = (XpContextPtr)NULL;
if(result != Success) return result;
}
if(pContext->funcs.EndDoc != 0)
result = pContext->funcs.EndDoc(pContext, stuff->cancel);
else
return BadImplementation;
SendXpNotify(pContext, XPEndDocNotify, stuff->cancel);
}
if(pContext->funcs.EndJob != 0)
result = pContext->funcs.EndJob(pContext, stuff->cancel);
else
return BadImplementation;
pContext->state = 0;
SendXpNotify(pContext, XPEndJobNotify, stuff->cancel);
if (client->noClientException != Success)
return client->noClientException;
else
return result;
}
static Bool
DoStartDoc(ClientPtr client, XpStDocPtr c)
{
XpContextPtr pContext = c->pContext;
if(c->pContext->state & JOB_GET_DATA &&
!(c->pContext->state & GET_DOC_DATA_STARTED))
{
if(!c->slept)
{
c->slept = TRUE;
ClientSleep(client, (ClientSleepProcPtr)DoStartDoc, (pointer) c);
c->pContext->clientSlept = client;
}
return TRUE;
}
if(pContext->funcs.StartDoc != 0)
(void) pContext->funcs.StartDoc(pContext, c->type);
else
{
SendErrorToClient(client, XpReqCode, X_PrintStartPage, 0,
BadImplementation);
return TRUE;
}
if(c->type == XPDocNormal)
pContext->state |= DOC_COOKED_STARTED;
else
pContext->state |= DOC_RAW_STARTED;
SendXpNotify(pContext, XPStartDocNotify, (int)FALSE);
xfree(c);
return TRUE;
}
static int
ProcXpStartDoc(ClientPtr client)
{
REQUEST(xPrintStartDocReq);
int result = Success;
XpContextPtr pContext;
XpStDocPtr c;
REQUEST_SIZE_MATCH(xPrintStartDocReq);
if((pContext = (XpContextPtr)client->devPrivates[XpClientPrivateIndex].ptr)
== (XpContextPtr)NULL)
return XpErrorBase+XPBadSequence;
if(!(pContext->state & JOB_STARTED) ||
pContext->state & DOC_RAW_STARTED ||
pContext->state & DOC_COOKED_STARTED)
return XpErrorBase+XPBadSequence;
if(stuff->type != XPDocNormal && stuff->type != XPDocRaw)
{
client->errorValue = stuff->type;
return BadValue;
}
c = (XpStDocPtr)xalloc(sizeof(XpStDocRec));
c->pContext = pContext;
c->type = stuff->type;
c->slept = FALSE;
(void)DoStartDoc(client, c);
if (client->noClientException != Success)
return client->noClientException;
else
return result;
}
static int
ProcXpEndDoc(ClientPtr client)
{
REQUEST(xPrintEndDocReq);
XpContextPtr pContext;
int result = Success;
REQUEST_SIZE_MATCH(xPrintEndDocReq);
if((pContext = (XpContextPtr)client->devPrivates[XpClientPrivateIndex].ptr)
== (XpContextPtr)NULL)
return XpErrorBase+XPBadSequence;
if(!(pContext->state & DOC_RAW_STARTED) &&
!(pContext->state & DOC_COOKED_STARTED))
return XpErrorBase+XPBadSequence;
if(pContext->state & PAGE_STARTED)
{
if(stuff->cancel == TRUE)
{
WindowPtr pWin = (WindowPtr )LookupIDByType(
pContext->pageWin, RT_WINDOW);
XpPagePtr pPage = (XpPagePtr)LookupIDByType(
pContext->pageWin, RTpage);
if(pContext->funcs.EndPage != 0)
result = pContext->funcs.EndPage(pContext, pWin);
else
return BadImplementation;
SendXpNotify(pContext, XPEndPageNotify, TRUE);
if(pPage)
pPage->context = (XpContextPtr)NULL;
}
else
return XpErrorBase+XPBadSequence;
if(result != Success)
return result;
}
if(pContext->funcs.EndDoc != 0)
result = pContext->funcs.EndDoc(pContext, stuff->cancel);
else
return BadImplementation;
pContext->state &= ~DOC_RAW_STARTED;
pContext->state &= ~DOC_COOKED_STARTED;
SendXpNotify(pContext, XPEndDocNotify, stuff->cancel);
if (client->noClientException != Success)
return client->noClientException;
else
return result;
}
static Bool
DoStartPage(
ClientPtr client,
XpStPagePtr c)
{
WindowPtr pWin = c->pWin;
int result = Success;
XpContextPtr pContext = c->pContext;
XpPagePtr pPage;
if(c->pContext->state & JOB_GET_DATA &&
!(c->pContext->state & GET_DOC_DATA_STARTED))
{
if(!c->slept)
{
c->slept = TRUE;
ClientSleep(client, (ClientSleepProcPtr)DoStartPage, (pointer) c);
c->pContext->clientSlept = client;
}
return TRUE;
}
if(!(pContext->state & DOC_COOKED_STARTED))
{
/* Implied StartDoc if it was omitted */
if(pContext->funcs.StartDoc != 0)
result = pContext->funcs.StartDoc(pContext, XPDocNormal);
else
{
SendErrorToClient(client, XpReqCode, X_PrintStartPage, 0,
BadImplementation);
return TRUE;
}
if(result != Success)
{
SendErrorToClient(client, XpReqCode, X_PrintStartPage, 0, result);
return TRUE;
}
pContext->state |= DOC_COOKED_STARTED;
SendXpNotify(pContext, XPStartDocNotify, (int)FALSE);
}
/* ensure the window's not already being used as a page */
if((pPage = (XpPagePtr)LookupIDByType(c->pWin->drawable.id, RTpage)) !=
(XpPagePtr)NULL)
{
if(pPage->context != (XpContextPtr)NULL)
{
SendErrorToClient(client, XpReqCode, X_PrintStartPage, 0,
BadWindow);
return TRUE;
}
}
else
{
if((pPage = (XpPagePtr)xalloc(sizeof(XpPageRec))) == (XpPagePtr)NULL)
{
SendErrorToClient(client, XpReqCode, X_PrintStartPage, 0,
BadAlloc);
return TRUE;
}
if(AddResource(c->pWin->drawable.id, RTpage, pPage) == FALSE)
{
xfree(pPage);
SendErrorToClient(client, XpReqCode, X_PrintStartPage, 0,
BadAlloc);
return TRUE;
}
}
pPage->context = pContext;
pContext->pageWin = c->pWin->drawable.id;
if(pContext->funcs.StartPage != 0)
result = pContext->funcs.StartPage(pContext, pWin);
else
{
SendErrorToClient(client, XpReqCode, X_PrintStartPage, 0,
BadImplementation);
return TRUE;
}
pContext->state |= PAGE_STARTED;
(void)MapWindow(pWin, client);
SendXpNotify(pContext, XPStartPageNotify, (int)FALSE);
return TRUE;
}
static int
ProcXpStartPage(ClientPtr client)
{
REQUEST(xPrintStartPageReq);
WindowPtr pWin;
int result = Success;
XpContextPtr pContext;
XpStPagePtr c;
REQUEST_SIZE_MATCH(xPrintStartPageReq);
if((pContext = (XpContextPtr)client->devPrivates[XpClientPrivateIndex].ptr)
== (XpContextPtr)NULL)
return XpErrorBase+XPBadSequence;
if(!(pContext->state & JOB_STARTED))
return XpErrorBase+XPBadSequence;
/* can't have pages in a raw documented */
if(pContext->state & DOC_RAW_STARTED)
return XpErrorBase+XPBadSequence;
if(pContext->state & PAGE_STARTED)
return XpErrorBase+XPBadSequence;
pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client,
SecurityWriteAccess);
if (!pWin || pWin->drawable.pScreen->myNum != pContext->screenNum)
return BadWindow;
if((c = (XpStPagePtr)xalloc(sizeof(XpStPageRec))) == (XpStPagePtr)NULL)
return BadAlloc;
c->pContext = pContext;
c->slept = FALSE;
c->pWin = pWin;
(void)DoStartPage(client, c);
if (client->noClientException != Success)
return client->noClientException;
else
return result;
}
static int
ProcXpEndPage(ClientPtr client)
{
REQUEST(xPrintEndPageReq);
int result = Success;
XpContextPtr pContext;
XpPagePtr page;
WindowPtr pWin;
REQUEST_SIZE_MATCH(xPrintEndPageReq);
if((pContext = (XpContextPtr)client->devPrivates[XpClientPrivateIndex].ptr)
== (XpContextPtr)NULL)
return XpErrorBase+XPBadSequence;
if(!(pContext->state & PAGE_STARTED))
return XpErrorBase+XPBadSequence;
pWin = (WindowPtr )LookupIDByType(pContext->pageWin, RT_WINDOW);
/* Call the ddx's EndPage proc. */
if(pContext->funcs.EndPage != 0)
result = pContext->funcs.EndPage(pContext, pWin);
else
return BadImplementation;
if((page = (XpPagePtr)LookupIDByType(pContext->pageWin, RTpage)) !=
(XpPagePtr)NULL)
page->context = (XpContextPtr)NULL;
pContext->state &= ~PAGE_STARTED;
pContext->pageWin = 0; /* None, NULL??? XXX */
(void)UnmapWindow(pWin, FALSE);
SendXpNotify(pContext, XPEndPageNotify, stuff->cancel);
if (client->noClientException != Success)
return client->noClientException;
else
return result;
}
/*******************************************************************************
*
* Document Data Functions: PutDocumentData, GetDocumentData
*
******************************************************************************/
static int
ProcXpPutDocumentData(ClientPtr client)
{
REQUEST(xPrintPutDocumentDataReq);
XpContextPtr pContext;
DrawablePtr pDraw;
int result = Success;
unsigned totalSize;
char *pData, *pDoc_fmt, *pOptions;
REQUEST_AT_LEAST_SIZE(xPrintPutDocumentDataReq);
if((pContext = (XpContextPtr)client->devPrivates[XpClientPrivateIndex].ptr)
== (XpContextPtr)NULL)
return XpErrorBase+XPBadSequence;
if(!(pContext->state & DOC_RAW_STARTED) &&
!(pContext->state & DOC_COOKED_STARTED))
return XpErrorBase+XPBadSequence;
if (stuff->drawable) {
if (pContext->state & DOC_RAW_STARTED)
return BadDrawable;
pDraw = (DrawablePtr)LookupDrawable(stuff->drawable, client);
if (!pDraw || pDraw->pScreen->myNum != pContext->screenNum)
return BadDrawable;
} else {
if (pContext->state & DOC_COOKED_STARTED)
return BadDrawable;
pDraw = NULL;
}
pData = (char *)(&stuff[1]);
totalSize = (stuff->len_data + 3) >> 2;
pDoc_fmt = pData + (totalSize << 2);
totalSize += (stuff->len_fmt + 3) >> 2;
pOptions = pData + (totalSize << 2);
totalSize += (stuff->len_options + 3) >> 2;
if((totalSize + (sz_xPrintPutDocumentDataReq >> 2)) != client->req_len)
return BadLength;
if(pContext->funcs.PutDocumentData != 0)
{
result = (*pContext->funcs.PutDocumentData)(pContext, pDraw,
pData, stuff->len_data,
pDoc_fmt, stuff->len_fmt,
pOptions, stuff->len_options,
client);
}
else
return BadImplementation;
if (client->noClientException != Success)
return client->noClientException;
else
return result;
}
static int
ProcXpGetDocumentData(ClientPtr client)
{
REQUEST(xPrintGetDocumentDataReq);
xPrintGetDocumentDataReply rep;
XpContextPtr pContext;
int result = Success;
REQUEST_SIZE_MATCH(xPrintGetDocumentDataReq);
if((pContext = (XpContextPtr)SecurityLookupIDByType(client,
stuff->printContext,
RTcontext,
SecurityWriteAccess))
== (XpContextPtr)NULL)
{
client->errorValue = stuff->printContext;
return XpErrorBase+XPBadContext;
}
if(pContext->funcs.GetDocumentData == 0)
return BadImplementation;
if(!(pContext->state & JOB_GET_DATA) ||
pContext->state & GET_DOC_DATA_STARTED)
return XpErrorBase+XPBadSequence;
if(stuff->maxBufferSize <= 0)
{
client->errorValue = stuff->maxBufferSize;
return BadValue; /* gotta have a positive buffer size */
}
result = (*pContext->funcs.GetDocumentData)(pContext, client,
stuff->maxBufferSize);
if(result != Success)
{
rep.type = X_Reply;
rep.sequenceNumber = client->sequence;
rep.length = 0;
rep.dataLen = 0;
rep.statusCode = 1;
rep.finishedFlag = TRUE;
if (client->swapped) {
int n;
long l;
swaps(&rep.sequenceNumber, n);
swapl(&rep.statusCode, l); /* XXX Why are these longs??? */
swapl(&rep.finishedFlag, l); /* XXX Why are these longs??? */
}
(void)WriteToClient(client,sz_xPrintGetDocumentDataReply,(char *)&rep);
}
else
pContext->state |= GET_DOC_DATA_STARTED;
if(pContext->clientSlept != (ClientPtr)NULL)
{
ClientSignal(pContext->clientSlept);
ClientWakeup(pContext->clientSlept);
pContext->clientSlept = (ClientPtr)NULL;
}
return result;
}
/*******************************************************************************
*
* Attribute requests: GetAttributes, SetAttributes, GetOneAttribute
*
******************************************************************************/
static int
ProcXpGetAttributes(ClientPtr client)
{
REQUEST(xPrintGetAttributesReq);
XpContextPtr pContext;
char *attrs;
xPrintGetAttributesReply *pRep;
int totalSize, n;
unsigned long l;
REQUEST_SIZE_MATCH(xPrintGetAttributesReq);
if(stuff->type < XPJobAttr || stuff->type > XPServerAttr)
{
client->errorValue = stuff->type;
return BadValue;
}
if(stuff->type != XPServerAttr)
{
if((pContext = (XpContextPtr)SecurityLookupIDByType(
client,
stuff->printContext,
RTcontext,
SecurityReadAccess))
== (XpContextPtr)NULL)
{
client->errorValue = stuff->printContext;
return XpErrorBase+XPBadContext;
}
if(pContext->funcs.GetAttributes == 0)
return BadImplementation;
if((attrs = (*pContext->funcs.GetAttributes)(pContext, stuff->type)) ==
(char *)NULL)
return BadAlloc;
}
else
{
if((attrs = XpGetAttributes((XpContextPtr)NULL, XPServerAttr)) ==
(char *)NULL)
return BadAlloc;
}
totalSize = sz_xPrintGetAttributesReply + QUADPAD(strlen(attrs));
if((pRep = (xPrintGetAttributesReply *)malloc(totalSize)) ==
(xPrintGetAttributesReply *)NULL)
return BadAlloc;
pRep->type = X_Reply;
pRep->length = (totalSize - sz_xPrintGetAttributesReply) >> 2;
pRep->sequenceNumber = client->sequence;
pRep->stringLen = strlen(attrs);
if (client->swapped) {
swaps(&pRep->sequenceNumber, n);
swapl(&pRep->length, l);
swapl(&pRep->stringLen, l);
}
strncpy((char*)(pRep + 1), attrs, strlen(attrs));
xfree(attrs);
WriteToClient(client, totalSize, (char *)pRep);
xfree(pRep);
return client->noClientException;
}
static int
ProcXpSetAttributes(ClientPtr client)
{
REQUEST(xPrintSetAttributesReq);
int result = Success;
XpContextPtr pContext;
char *attr;
REQUEST_AT_LEAST_SIZE(xPrintSetAttributesReq);
if(stuff->type < XPJobAttr || stuff->type > XPServerAttr)
{
client->errorValue = stuff->type;
return BadValue;
}
/*
* Disallow changing of read-only attribute pools
*/
if(stuff->type == XPPrinterAttr || stuff->type == XPServerAttr)
return BadMatch;
if((pContext = (XpContextPtr)SecurityLookupIDByType(
client,
stuff->printContext,
RTcontext,
SecurityWriteAccess))
== (XpContextPtr)NULL)
{
client->errorValue = stuff->printContext;
return XpErrorBase+XPBadContext;
}
if(pContext->funcs.SetAttributes == 0)
return BadImplementation;
/*
* Check for attributes being set after their relevant phase
* has already begun (e.g. Job attributes set after StartJob).
*/
if((pContext->state & JOB_STARTED) && stuff->type == XPJobAttr)
return XpErrorBase+XPBadSequence;
if(((pContext->state & DOC_RAW_STARTED) ||
(pContext->state & DOC_COOKED_STARTED)) && stuff->type == XPDocAttr)
return XpErrorBase+XPBadSequence;
if((pContext->state & PAGE_STARTED) && stuff->type == XPPageAttr)
return XpErrorBase+XPBadSequence;
if((attr = (char *)malloc(stuff->stringLen + 1)) == (char *)NULL)
return BadAlloc;
strncpy(attr, (char *)(stuff + 1), stuff->stringLen);
attr[stuff->stringLen] = (char)'\0';
if(stuff->rule == XPAttrReplace)
(*pContext->funcs.SetAttributes)(pContext, stuff->type, attr);
else if(stuff->rule == XPAttrMerge)
(*pContext->funcs.AugmentAttributes)(pContext, stuff->type, attr);
else
{
client->errorValue = stuff->rule;
result = BadValue;
}
xfree(attr);
SendAttributeNotify(pContext, stuff->type);
return result;
}
static int
ProcXpGetOneAttribute(ClientPtr client)
{
REQUEST(xPrintGetOneAttributeReq);
XpContextPtr pContext;
char *value, *attrName;
xPrintGetOneAttributeReply *pRep;
int totalSize;
int n;
unsigned long l;
REQUEST_AT_LEAST_SIZE(xPrintGetOneAttributeReq);
totalSize = ((sz_xPrintGetOneAttributeReq) >> 2) +
((stuff->nameLen + 3) >> 2);
if(totalSize != client->req_len)
return BadLength;
if(stuff->type < XPJobAttr || stuff->type > XPServerAttr)
{
client->errorValue = stuff->type;
return BadValue;
}
if((attrName = (char *)malloc(stuff->nameLen + 1)) == (char *)NULL)
return BadAlloc;
strncpy(attrName, (char *)(stuff+1), stuff->nameLen);
attrName[stuff->nameLen] = (char)'\0';
if(stuff->type != XPServerAttr)
{
if((pContext = (XpContextPtr)SecurityLookupIDByType(
client,
stuff->printContext,
RTcontext,
SecurityReadAccess))
== (XpContextPtr)NULL)
{
client->errorValue = stuff->printContext;
return XpErrorBase+XPBadContext;
}
if(pContext->funcs.GetOneAttribute == 0)
return BadImplementation;
if((value = (*pContext->funcs.GetOneAttribute)(pContext, stuff->type,
attrName)) == (char *)NULL)
return BadAlloc;
}
else
{
if((value = XpGetOneAttribute((XpContextPtr)NULL, XPServerAttr,
attrName)) == (char *)NULL)
return BadAlloc;
}
free(attrName);
totalSize = sz_xPrintGetOneAttributeReply + QUADPAD(strlen(value));
if((pRep = (xPrintGetOneAttributeReply *)malloc(totalSize)) ==
(xPrintGetOneAttributeReply *)NULL)
return BadAlloc;
pRep->type = X_Reply;
pRep->length = (totalSize - sz_xPrintGetOneAttributeReply) >> 2;
pRep->sequenceNumber = client->sequence;
pRep->valueLen = strlen(value);
if (client->swapped) {
swaps(&pRep->sequenceNumber, n);
swapl(&pRep->length, l);
swapl(&pRep->valueLen, l);
}
strncpy((char*)(pRep + 1), value, strlen(value));
WriteToClient(client, totalSize, (char *)pRep);
xfree(pRep);
return client->noClientException;
}
/*******************************************************************************
*
* Print Event requests: SelectInput InputSelected, SendXpNotify
*
******************************************************************************/
static int
ProcXpSelectInput(ClientPtr client)
{
REQUEST(xPrintSelectInputReq);
int result = Success;
XpContextPtr pContext;
XpClientPtr pPrintClient;
REQUEST_SIZE_MATCH(xPrintSelectInputReq);
/*
* Check to see that the supplied XID is really a valid print context
* in this server.
*/
if((pContext=(XpContextPtr)SecurityLookupIDByType(client,
stuff->printContext,
RTcontext,
SecurityWriteAccess))
== (XpContextPtr)NULL)
{
client->errorValue = stuff->printContext;
return XpErrorBase+XPBadContext;
}
if(stuff->eventMask & ~allEvents)
{
client->errorValue = stuff->eventMask;
return BadValue; /* bogus event mask bits */
}
if((pPrintClient = AcquireClient(pContext, client)) == (XpClientPtr)NULL)
return BadAlloc;
pPrintClient->eventMask = stuff->eventMask;
return result;
}
static int
ProcXpInputSelected(ClientPtr client)
{
REQUEST(xPrintInputSelectedReq);
xPrintInputSelectedReply rep;
register int n;
long l;
XpClientPtr pXpClient;
XpContextPtr pContext;
REQUEST_SIZE_MATCH(xPrintInputSelectedReq);
if((pContext=(XpContextPtr)SecurityLookupIDByType(client,
stuff->printContext,
RTcontext,
SecurityReadAccess))
== (XpContextPtr)NULL)
{
client->errorValue = stuff->printContext;
return XpErrorBase+XPBadContext;
}
pXpClient = FindClient(pContext, client);
rep.type = X_Reply;
rep.length = 0;
rep.sequenceNumber = client->sequence;
rep.eventMask = (pXpClient != (XpClientPtr)NULL)? pXpClient->eventMask : 0;
rep.allEventsMask = GetAllEventMasks(pContext);
if (client->swapped) {
swaps(&rep.sequenceNumber, n);
swapl(&rep.length, l);
swapl(&rep.eventMask, l);
swapl(&rep.allEventsMask, l);
}
WriteToClient(client, sz_xPrintInputSelectedReply, (char *)&rep);
return client->noClientException;
}
static void
SendAttributeNotify(XpContextPtr pContext, int which)
{
XpClientPtr pXpClient;
xPrintAttributeEvent ae;
ClientPtr client;
pXpClient = pContext->clientHead;
if(pXpClient == (XpClientPtr)NULL)
return; /* Nobody's interested in the events (or this context). */
for (pXpClient = pContext->clientHead;
pXpClient != (XpClientPtr)NULL;
pXpClient = pXpClient->pNext)
{
client = pXpClient->client;
if (client == serverClient || client->clientGone ||
!(pXpClient->eventMask & XPAttributeMask))
continue;
ae.type = XPAttributeNotify + XpEventBase;
ae.detail = which;
ae.printContext = pContext->contextID;
ae.sequenceNumber = client->sequence;
WriteEventsToClient (client, 1, (xEvent *) &ae);
}
}
static void
SendXpNotify(XpContextPtr pContext, int which, int val)
{
XpClientPtr pXpClient;
xPrintPrintEvent pe;
ClientPtr client;
pXpClient = pContext->clientHead;
if(pXpClient == (XpClientPtr)NULL)
return; /* Nobody's interested in the events (or this context). */
for (pXpClient = pContext->clientHead;
pXpClient != (XpClientPtr)NULL;
pXpClient = pXpClient->pNext)
{
client = pXpClient->client;
if (client == serverClient || client->clientGone ||
!(pXpClient->eventMask & XPPrintMask))
continue;
pe.type = XPPrintNotify + XpEventBase;
pe.detail = which;
pe.printContext = pContext->contextID;
pe.cancel = (Bool)val;
pe.sequenceNumber = client->sequence;
WriteEventsToClient (client, 1, (xEvent *) &pe);
}
}
static CARD32
GetAllEventMasks(XpContextPtr pContext)
{
XpClientPtr pPrintClient;
CARD32 totalMask = (CARD32)0;
for (pPrintClient = pContext->clientHead;
pPrintClient != (XpClientPtr)NULL;
pPrintClient = pPrintClient->pNext)
{
totalMask |= pPrintClient->eventMask;
}
return totalMask;
}
/*
* XpContextOfClient - returns the XpContextPtr to the context
* associated with the specified client, or NULL if the client
* does not currently have a context set.
*/
XpContextPtr
XpContextOfClient(ClientPtr client)
{
return (XpContextPtr)client->devPrivates[XpClientPrivateIndex].ptr;
}
/*******************************************************************************
*
* Swap-request functions
*
******************************************************************************/
static int
SProcXpCreateContext(ClientPtr client)
{
int i;
long n;
REQUEST(xPrintCreateContextReq);
swaps(&stuff->length, i);
swapl(&stuff->contextID, n);
swapl(&stuff->printerNameLen, n);
swapl(&stuff->localeLen, n);
return ProcXpCreateContext(client);
}
static int
SProcXpGetPrinterList(ClientPtr client)
{
int i;
long n;
REQUEST(xPrintGetPrinterListReq);
swaps(&stuff->length, i);
swapl(&stuff->printerNameLen, n);
swapl(&stuff->localeLen, n);
return ProcXpGetPrinterList(client);
}
static int
SProcXpRehashPrinterList(ClientPtr client)
{
int i;
REQUEST(xPrintRehashPrinterListReq);
swaps(&stuff->length, i);
return ProcXpRehashPrinterList(client);
}
static int
SProcXpSetContext(ClientPtr client)
{
int i;
REQUEST(xPrintSetContextReq);
swaps(&stuff->length, i);
swapl(&stuff->printContext, i);
return ProcXpSetContext(client);
}
static int
SProcXpGetContext(ClientPtr client)
{
int i;
REQUEST(xPrintGetContextReq);
swaps(&stuff->length, i);
return ProcXpGetContext(client);
}
static int
SProcXpDestroyContext(ClientPtr client)
{
int i;
long n;
REQUEST(xPrintDestroyContextReq);
swaps(&stuff->length, i);
swapl(&stuff->printContext, n);
return ProcXpDestroyContext(client);
}
static int
SProcXpGetContextScreen(ClientPtr client)
{
int i;
long n;
REQUEST(xPrintGetContextScreenReq);
swaps(&stuff->length, i);
swapl(&stuff->printContext, n);
return ProcXpGetContextScreen(client);
}
static int
SProcXpInputSelected(ClientPtr client)
{
int i;
long n;
REQUEST(xPrintInputSelectedReq);
swaps(&stuff->length, i);
swapl(&stuff->printContext, n);
return ProcXpInputSelected(client);
}
static int
SProcXpStartJob(ClientPtr client)
{
int i;
REQUEST(xPrintStartJobReq);
swaps(&stuff->length, i);
return ProcXpStartJob(client);
}
static int
SProcXpEndJob(ClientPtr client)
{
int i;
REQUEST(xPrintEndJobReq);
swaps(&stuff->length, i);
return ProcXpEndJob(client);
}
static int
SProcXpStartDoc(ClientPtr client)
{
int i;
REQUEST(xPrintStartDocReq);
swaps(&stuff->length, i);
return ProcXpStartDoc(client);
}
static int
SProcXpEndDoc(ClientPtr client)
{
int i;
REQUEST(xPrintEndDocReq);
swaps(&stuff->length, i);
return ProcXpEndDoc(client);
}
static int
SProcXpStartPage(ClientPtr client)
{
int i;
long n;
REQUEST(xPrintStartPageReq);
swaps(&stuff->length, i);
swapl(&stuff->window, n);
return ProcXpStartPage(client);
}
static int
SProcXpEndPage(ClientPtr client)
{
int i;
REQUEST(xPrintEndPageReq);
swaps(&stuff->length, i);
return ProcXpEndPage(client);
}
static int
SProcXpPutDocumentData(ClientPtr client)
{
long n;
int i;
REQUEST(xPrintPutDocumentDataReq);
swaps(&stuff->length, i);
swapl(&stuff->drawable, n);
swapl(&stuff->len_data, n);
swaps(&stuff->len_fmt, i);
swaps(&stuff->len_options, i);
return ProcXpPutDocumentData(client);
}
static int
SProcXpGetDocumentData(ClientPtr client)
{
long n;
int i;
REQUEST(xPrintGetDocumentDataReq);
swaps(&stuff->length, i);
swapl(&stuff->printContext, n);
swapl(&stuff->maxBufferSize, n);
return ProcXpGetDocumentData(client);
}
static int
SProcXpGetAttributes(ClientPtr client)
{
long n;
int i;
REQUEST(xPrintGetAttributesReq);
swaps(&stuff->length, i);
swapl(&stuff->printContext, n);
return ProcXpGetAttributes(client);
}
static int
SProcXpSetAttributes(ClientPtr client)
{
long n;
int i;
REQUEST(xPrintSetAttributesReq);
swaps(&stuff->length, i);
swapl(&stuff->printContext, n);
swapl(&stuff->stringLen, n);
return ProcXpSetAttributes(client);
}
static int
SProcXpGetOneAttribute(ClientPtr client)
{
long n;
int i;
REQUEST(xPrintGetOneAttributeReq);
swaps(&stuff->length, i);
swapl(&stuff->printContext, n);
swapl(&stuff->nameLen, n);
return ProcXpGetOneAttribute(client);
}
static int
SProcXpSelectInput(ClientPtr client)
{
long n;
int i;
REQUEST(xPrintSelectInputReq);
swaps(&stuff->length, i);
swapl(&stuff->eventMask, n);
swapl(&stuff->printContext, n);
return ProcXpSelectInput(client);
}
static int
SProcXpGetPageDimensions(ClientPtr client)
{
long n;
int i;
REQUEST(xPrintGetPageDimensionsReq);
swaps(&stuff->length, i);
swapl(&stuff->printContext, n);
return ProcXpGetPageDimensions(client);
}
static int
SProcXpSetImageResolution(ClientPtr client)
{
long n;
int i;
REQUEST(xPrintSetImageResolutionReq);
swaps(&stuff->length, i);
swapl(&stuff->printContext, n);
swaps(&stuff->imageRes, i);
return ProcXpSetImageResolution(client);
}
static int
SProcXpGetImageResolution(ClientPtr client)
{
long n;
int i;
REQUEST(xPrintGetImageResolutionReq);
swaps(&stuff->length, i);
swapl(&stuff->printContext, n);
return ProcXpGetImageResolution(client);
}
static void
SwapXpNotifyEvent(xPrintPrintEvent *src, xPrintPrintEvent *dst)
{
/*
* Swap the sequence number and context fields.
*/
cpswaps(src->sequenceNumber, dst->sequenceNumber);
cpswapl(src->printContext, dst->printContext);
/*
* Copy the byte-long fields.
*/
dst->type = src->type;
dst->detail = src->detail;
dst->cancel = src->cancel;
}
static void
SwapXpAttributeEvent(xPrintAttributeEvent *src, xPrintAttributeEvent *dst)
{
/*
* Swap the sequence number and context fields.
*/
cpswaps(src->sequenceNumber, dst->sequenceNumber);
cpswapl(src->printContext, dst->printContext);
/*
* Copy the byte-long fields.
*/
dst->type = src->type;
dst->detail = src->detail;
}
|