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
|
/*
* Copyright (c) 1999-2003 Smithsonian Astrophysical Observatory
*/
#include <xpap.h>
#include <stdint.h>
#if HAVE_TCL
#include <tcl.h>
/*
*----------------------------------------------------------------------------
*
*
* Private Routines and Data
*
*
*----------------------------------------------------------------------------
*/
/* with Tcl 8.4, some function prototypes have added CONST qualifiers,
which we try to deal with in a backward-compatible way */
#define XCONST84
#if TCL_MAJOR_VERSION >= 8
#if TCL_MINOR_VERSION >= 4
#undef XCONST84
#define XCONST84 CONST
#endif
#endif
#ifdef NULLSTRING
#undef NULLSTRING
#endif
#define NULLSTRING ""
#define TCL_NULLSTR(s) (!s || !*s || !strcmp(s, "{}"))
#define TY_CLIENT 1
#define TY_SERVER 2
#ifndef MAX_XPAS
#define MAX_XPAS 10000
#endif
/*
*
* record struct for client_data for XPATcl[Send,Receive,Info] routines
*
*/
typedef struct xpatclclientdatarec{
Tcl_Interp *interp;
char *callback;
char *client_data;
} *XPATclClientData, XPATclClientDataRec;
/*
*----------------------------------------------------------------------------
*
* Routine: Tcl_GetXPAFromObj
*
* Purpose: convert string to XPA handle
*
* Returns: Tcl error code
*
*----------------------------------------------------------------------------
*/
#ifdef ANSI_FUNC
static int
Tcl_GetXPAFromObj(Tcl_Interp *interp, Tcl_Obj *obj, int flag, XPA *xpa)
#else
static int Tcl_GetXPAFromObj(interp, obj, flag, xpa)
Tcl_Interp *interp;
Tcl_Obj *obj;
int flag;
XPA *xpa;
#endif
{
char *s;
void *lval;
Tcl_Obj *resultPtr;
/* get result pointer */
resultPtr = Tcl_GetObjResult(interp);
if( (s = Tcl_GetStringFromObj(obj, NULL)) == NULL ){
return(TCL_ERROR);
}
if( strncmp(s, "xpa_", 4) || (sscanf(&(s[4]), "%p", &lval) != 1) ){
Tcl_SetStringObj(resultPtr, "XPA$ERROR: invalid xpa handle", -1);
return(TCL_ERROR);
}
*xpa = (XPA)lval;
/* make sure its a valid xpa */
switch(flag){
case TY_CLIENT:
if( !XPAClientValid(*xpa) ){
Tcl_SetStringObj(resultPtr, "XPA$ERROR: invalid xpa client handle", -1);
return(TCL_ERROR);
}
break;
case TY_SERVER:
if( !XPAValid(*xpa) ){
Tcl_SetStringObj(resultPtr, "XPA$ERROR: invalid xpa server handle", -1);
return(TCL_ERROR);
}
break;
}
return(TCL_OK);
}
/*
*----------------------------------------------------------------------------
*
* Routine: XPATclHandler
*
* Purpose: common handler for access points written in tcl
* execute the tcl receive command with xpa arguments
* used instead of Tcl_Eval so we can avoid interpreting either
* paramlist or buf
*
*
* Returns: 0 on success, -1 on failure
*
*----------------------------------------------------------------------------
*/
#ifdef ANSI_FUNC
static int
XPATclHandler (void *client_data, void *call_data, char *paramlist,
char *buf, int len, int nargs)
#else
static int XPATclHandler(client_data, call_data, paramlist, buf, len, nargs)
void *client_data;
void *call_data;
char *paramlist;
char *buf;
int len;
int nargs;
#endif
{
XPA xpa = (XPA)call_data;
XPATclClientData xptr = (XPATclClientData)client_data;
Tcl_CmdInfo info; /* Info about command procedures */
Tcl_Obj *objv[10]; /* Object vector for arguments */
Tcl_Obj *resultPtr; /* The result object */
int result; /* TCL_OK or TCL_ERROR */
int object;
char tbuf[SZ_LINE];
XCONST84 char *argv[10];
char *s=NULL;
char *t=NULL;
char *cmd;
/* make sure we have a callback */
if( !xptr || !xptr->callback ){
XPAError(xpa, "Invalid tcl command for xpa callback");
return(-1);
}
/* set command name */
cmd = xptr->callback;
/* Map from the command name to a C procedure */
if( !Tcl_GetCommandInfo(xptr->interp, cmd, &info) ){
XPAError(xpa, "Unknown tcl command for xpa callback");
return(-1);
}
/* string-ize some values */
snprintf(tbuf, SZ_LINE, "xpa_%p", xpa);
s = xstrdup(tbuf);
if( nargs > 4 ){
snprintf(tbuf, SZ_LINE, "%d", len);
t = xstrdup(tbuf);
}
/* package up argument values */
object = info.isNativeObjectProc;
if (object) {
/* The object interface is preferred for this command */
objv[0] = Tcl_NewStringObj(cmd, strlen(cmd));
objv[1] = Tcl_NewStringObj(s, strlen(s));
if( (xptr->client_data == NULL) || (*xptr->client_data == '\0') )
objv[2] = Tcl_NewStringObj(NULLSTRING, strlen(NULLSTRING));
else
objv[2] = Tcl_NewStringObj(xptr->client_data, strlen(xptr->client_data));
if( (paramlist == NULL) || (*paramlist == '\0') )
objv[3] = Tcl_NewStringObj(NULLSTRING, strlen(NULLSTRING));
else
objv[3] = Tcl_NewStringObj(paramlist, strlen(paramlist));
if( nargs > 4 ){
if( (buf == NULL) || (*buf == '\0') || (len == 0) )
objv[4] = Tcl_NewStringObj(NULLSTRING, strlen(NULLSTRING));
else
objv[4] = Tcl_NewStringObj(buf, len);
objv[5] = Tcl_NewStringObj(t, strlen(t));
}
} else {
argv[0] = cmd;
argv[1] = s;
argv[2] = xptr->client_data;
argv[3] = paramlist;
if( nargs > 4 ){
argv[4] = buf;
argv[5] = t;
}
}
/* reset before we make C call */
Tcl_ResetResult(xptr->interp);
/*
* Invoke the C procedure.
*/
if (object) {
result = (*info.objProc)(info.objClientData, xptr->interp, nargs, objv);
/* Get the string value from the result object */
resultPtr = Tcl_GetObjResult(xptr->interp);
Tcl_SetResult(xptr->interp, Tcl_GetStringFromObj(resultPtr, NULL),
TCL_VOLATILE);
} else {
result = (*info.proc)(info.clientData, xptr->interp, nargs, argv);
}
/* clean up */
if( s ) xfree(s);
if( t ) xfree(t);
/* translate Tcl status into XPA status */
if( result == TCL_OK ){
return(0);
}
else{
s = (char *)Tcl_GetStringResult(xptr->interp);
if( !strncmp(s, "XPA$ERROR: ", 11) )
s += 11;
XPAError(xpa, s);
return(-1);
}
}
/*
*----------------------------------------------------------------------------
*
* Routine: XPATclReceive
*
* Purpose: receive handler for access points written in tcl
* execute the tcl receive command with xpa arguments
* used instead of Tcl_Eval so we can avoid interpreting either
* paramlist or buf
*
*
* Returns: 0 on success, -1 on failure
*
*----------------------------------------------------------------------------
*/
#ifdef ANSI_FUNC
static int
XPATclReceive (void *client_data, void *call_data, char *paramlist,
char *buf, size_t len)
#else
static int XPATclReceive(client_data, call_data, paramlist, buf, len)
void *client_data;
void *call_data;
char *paramlist;
char *buf;
size_t len;
#endif
{
return(XPATclHandler(client_data, call_data, paramlist, buf, len, 6));
}
/*
*----------------------------------------------------------------------------
*
* Routine: XPATclSend
*
* Purpose: send handler for access points written in tcl
*
* Returns: 0 on success, -1 on failure
*
*----------------------------------------------------------------------------
*/
#ifdef ANSI_FUNC
static int
XPATclSend (void *client_data, void *call_data, char *paramlist,
char **buf, size_t *len)
#else
static int XPATclSend(client_data, call_data, paramlist, buf, len)
void *client_data;
void *call_data;
char *paramlist;
char **buf;
size_t *len;
#endif
{
return(XPATclHandler(client_data, call_data, paramlist, NULL, 0, 4));
}
/*
*----------------------------------------------------------------------------
*
* Routine: XPATclInfo
*
* Purpose: info handler for access points written in tcl
*
* Returns: 0 on success, -1 on failure
*
*----------------------------------------------------------------------------
*/
#ifdef ANSI_FUNC
static int
XPATclInfo (void *client_data, void *call_data, char *paramlist)
#else
static int XPATclInfo(client_data, call_data, paramlist)
void *client_data;
void *call_data;
char *paramlist;
#endif
{
return(XPATclHandler(client_data, call_data, paramlist, NULL, 0, 4));
}
/*
*----------------------------------------------------------------------------
*
* Routine: XPANew_Tcl
*
* Purpose: Tcl binding to XPANew procedure
*
* Tcl call:
*
* xpanew class name help sproc sdata smode rproc rdata rmode
*
* use the empty string to specify NULL arguments
*
* Returns: Tcl error code
*
*----------------------------------------------------------------------------
*/
#ifdef ANSI_FUNC
static int
XPANew_Tcl(ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
#else
static int XPANew_Tcl(clientData, interp, objc, objv)
ClientData clientData;
Tcl_Interp *interp;
int objc;
Tcl_Obj *CONST objv[];
#endif
{
char *xclass;
char *name;
char *help;
char *send_cb;
char *sdata;
char *smode;
char *rec_cb;
char *rdata;
char *rmode;
char tbuf[SZ_LINE];
XPA xpa;
SendCb sproc;
ReceiveCb rproc;
XPATclClientData sptr;
XPATclClientData rptr;
Tcl_Obj *resultPtr;
/* make sure argument count is correct */
if( objc != 10 ){
Tcl_WrongNumArgs(interp, 1, objv,
"class name help sproc sdata smode rproc rdata rmode");
return(TCL_ERROR);
}
/* get arguments as strings */
xclass = Tcl_GetStringFromObj(objv[1], NULL);
name = Tcl_GetStringFromObj(objv[2], NULL);
help = Tcl_GetStringFromObj(objv[3], NULL);
send_cb = Tcl_GetStringFromObj(objv[4], NULL);
sdata = Tcl_GetStringFromObj(objv[5], NULL);
smode = Tcl_GetStringFromObj(objv[6], NULL);
rec_cb = Tcl_GetStringFromObj(objv[7], NULL);
rdata = Tcl_GetStringFromObj(objv[8], NULL);
rmode = Tcl_GetStringFromObj(objv[9], NULL);
/* this will hold the result */
resultPtr = Tcl_GetObjResult(interp);
/* set up callback procedures */
if( ((send_cb == NULL) || (*send_cb == '\0') ) ){
sproc = NULL;
sptr = NULL;
}
else{
sproc = XPATclSend;
sptr = (XPATclClientData)xcalloc(1, sizeof(XPATclClientDataRec));
sptr->interp = interp;
sptr->callback = xstrdup(send_cb);
sptr->client_data = xstrdup(sdata);
}
if( ((rec_cb == NULL) || (*rec_cb == '\0') ) ){
rproc = NULL;
rptr = NULL;
}
else{
rproc = XPATclReceive;
rptr = (XPATclClientData)xcalloc(1, sizeof(XPATclClientDataRec));
rptr->interp = interp;
rptr->callback = xstrdup(rec_cb);
rptr->client_data = xstrdup(rdata);
}
/* make sure we have either a send or receive callback */
if( !sproc && !rproc ){
Tcl_SetStringObj(resultPtr,
"XPA$ERROR: xpanew requires send_cb or rec_cb (or both)", -1);
return(TCL_ERROR);
}
/* set up the tcl handler for the xpa access point */
xpa = XPANew(xclass, name, help, sproc, sptr, smode, rproc, rptr, rmode);
if( xpa == NULL ){
Tcl_SetStringObj(resultPtr,
"XPA$ERROR: could not create XPA access point", -1);
return(TCL_ERROR);
}
else{
/* add this xpa to the Tcl event loop */
XPATclAddInput(xpa);
/* return xpa address to tcl in a string */
snprintf(tbuf, SZ_LINE, "xpa_%p", xpa);
Tcl_SetStringObj(resultPtr, tbuf, -1);
return(TCL_OK);
}
}
/*
*----------------------------------------------------------------------------
*
* Routine: XPAFree_Tcl
*
* Purpose: Tcl binding to XPAFree procedure
*
* Tcl call:
*
* xpafree xpa
*
* Returns: Tcl error code
*
*----------------------------------------------------------------------------
*/
#ifdef ANSI_FUNC
static int
XPAFree_Tcl(ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
#else
static int XPAFree_Tcl(clientData, interp, objc, objv)
ClientData clientData;
Tcl_Interp *interp;
int objc;
Tcl_Obj *CONST objv[];
#endif
{
XPA xpa;
XPATclClientData ptr;
/* make sure argument count is correct */
if( objc != 2 ){
Tcl_WrongNumArgs(interp, 1, objv, "xpa");
return(TCL_ERROR);
}
/* get xpa, which is always arg 1 */
if( Tcl_GetXPAFromObj(interp, objv[1], TY_SERVER, &xpa) != TCL_OK){
return(TCL_ERROR);
}
/* reset error/result condition */
Tcl_ResetResult(interp);
/* free the associated tcl record, stored in the client data */
if( xpa->send_data ){
ptr = (XPATclClientData)xpa->send_data;
if( ptr->callback ) xfree( ptr->callback);
if( ptr->client_data ) xfree( ptr->client_data);
xfree(xpa->send_data);
}
if( xpa->receive_data ){
ptr = (XPATclClientData)xpa->receive_data;
if( ptr->callback ) xfree( ptr->callback);
if( ptr->client_data ) xfree( ptr->client_data);
xfree(xpa->receive_data);
}
if( xpa->info_data ){
ptr = (XPATclClientData)xpa->info_data;
if( ptr->callback ) xfree( ptr->callback);
if( ptr->client_data ) xfree( ptr->client_data);
xfree(xpa->info_data);
}
/* call the XPAFree routine */
XPAFree(xpa);
return(TCL_OK);
}
/*
*----------------------------------------------------------------------------
*
* Routine: XPAInfoNew_Tcl
*
* Purpose: Tcl binding to XPAInfoNew procedure
*
* Tcl call:
*
* xpanew class name help iproc idata imode
*
* use the empty string to specify NULL arguments
*
* Returns: Tcl error code
*
*----------------------------------------------------------------------------
*/
#ifdef ANSI_FUNC
static int
XPAInfoNew_Tcl(ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
#else
static int XPAInfoNew_Tcl(clientData, interp, objc, objv)
ClientData clientData;
Tcl_Interp *interp;
int objc;
Tcl_Obj *CONST objv[];
#endif
{
char *xclass;
char *name;
char *info_cb;
char *idata;
char *imode;
char tbuf[SZ_LINE];
XPA xpa;
InfoCb iproc;
XPATclClientData iptr;
Tcl_Obj *resultPtr;
/* make sure argument count is correct */
if( objc != 6 ){
Tcl_WrongNumArgs(interp, 1, objv,
"class name iproc idata imode");
return(TCL_ERROR);
}
/* get arguments as strings */
xclass = Tcl_GetStringFromObj(objv[1], NULL);
name = Tcl_GetStringFromObj(objv[2], NULL);
info_cb = Tcl_GetStringFromObj(objv[3], NULL);
idata = Tcl_GetStringFromObj(objv[4], NULL);
imode = Tcl_GetStringFromObj(objv[5], NULL);
/* this will hold the result */
resultPtr = Tcl_GetObjResult(interp);
/* set up callback procedures */
if( info_cb == NULL ){
Tcl_SetStringObj(resultPtr,
"XPA$ERROR: xpainfonew requires info_cb", -1);
return(TCL_ERROR);
}
else{
iproc = XPATclInfo;
iptr = (XPATclClientData)xcalloc(1, sizeof(XPATclClientDataRec));
iptr->interp = interp;
iptr->callback = xstrdup(info_cb);
iptr->client_data = xstrdup(idata);
}
/* set up the tcl handler for the xpa access point */
xpa = XPAInfoNew(xclass, name, iproc, iptr, imode);
if( xpa == NULL ){
Tcl_SetStringObj(resultPtr,
"XPA$ERROR: could not create XPA info access point", -1);
return(TCL_ERROR);
}
else{
/* add this xpa to the Tcl event loop */
XPATclAddInput(xpa);
/* return xpa address to tcl in a string */
snprintf(tbuf, SZ_LINE, "xpa_%p", xpa);
Tcl_SetStringObj(resultPtr, tbuf, -1);
return(TCL_OK);
}
}
/*
*----------------------------------------------------------------------------
*
* Routine: XPACmdNew_Tcl
*
* Purpose: Tcl binding to XPACmdNew procedure
*
* Tcl call:
*
* xpacmdnew class name
*
* Returns: Tcl error code
*
*----------------------------------------------------------------------------
*/
#ifdef ANSI_FUNC
static int
XPACmdNew_Tcl(ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
#else
static int XPACmdNew_Tcl(clientData, interp, objc, objv)
ClientData clientData;
Tcl_Interp *interp;
int objc;
Tcl_Obj *CONST objv[];
#endif
{
char *xclass;
char *name;
char tbuf[SZ_LINE];
XPA xpa;
Tcl_Obj *resultPtr;
/* make sure argument count is correct */
if( objc != 3 ){
Tcl_WrongNumArgs(interp, 1, objv, "class name");
return(TCL_ERROR);
}
/* get arguments as strings */
xclass = Tcl_GetStringFromObj(objv[1], NULL);
name = Tcl_GetStringFromObj(objv[2], NULL);
/* this will hold the result */
resultPtr = Tcl_GetObjResult(interp);
/* set up the tcl handler for the xpa access point */
if( (xpa = XPACmdNew(xclass, name)) == NULL ){
Tcl_SetStringObj(resultPtr,
"XPA$ERROR: could not create XPA command access point", -1);
return(TCL_ERROR);
}
else{
/* add this xpa to the Tcl event loop */
XPATclAddInput(xpa);
/* return xpa address to tcl in a string */
snprintf(tbuf, SZ_LINE, "xpa_%p", xpa);
Tcl_SetStringObj(resultPtr, tbuf, -1);
return(TCL_OK);
}
}
/*
*----------------------------------------------------------------------------
*
* Routine: XPACmdAdd_Tcl
*
* Purpose: Tcl binding to XPACmdAdd procedure
*
* Tcl call:
*
* xpacmdadd xpa name help sproc sdata smode rproc rdata rmode
*
* use the empty string to specify NULL arguments
*
* Returns: Tcl error code
*
*----------------------------------------------------------------------------
*/
#ifdef ANSI_FUNC
static int
XPACmdAdd_Tcl(ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
#else
static int XPACmdAdd_Tcl(clientData, interp, objc, objv)
ClientData clientData;
Tcl_Interp *interp;
int objc;
Tcl_Obj *CONST objv[];
#endif
{
char *name;
char *help;
char *send_cb;
char *sdata;
char *smode;
char *rec_cb;
char *rdata;
char *rmode;
char tbuf[SZ_LINE];
XPA xpa;
XPACmd xpacmd;
SendCb sproc;
ReceiveCb rproc;
XPATclClientData sptr;
XPATclClientData rptr;
Tcl_Obj *resultPtr;
/* make sure argument count is correct */
if( objc != 10 ){
Tcl_WrongNumArgs(interp, 1, objv,
"class name help sproc sdata smode rproc rdata rmode");
return(TCL_ERROR);
}
/* get xpa, which is always arg 1 */
if( Tcl_GetXPAFromObj(interp, objv[1], TY_SERVER, &xpa) != TCL_OK){
return(TCL_ERROR);
}
name = Tcl_GetStringFromObj(objv[2], NULL);
help = Tcl_GetStringFromObj(objv[3], NULL);
send_cb = Tcl_GetStringFromObj(objv[4], NULL);
sdata = Tcl_GetStringFromObj(objv[5], NULL);
smode = Tcl_GetStringFromObj(objv[6], NULL);
rec_cb = Tcl_GetStringFromObj(objv[7], NULL);
rdata = Tcl_GetStringFromObj(objv[8], NULL);
rmode = Tcl_GetStringFromObj(objv[9], NULL);
/* this will hold the result */
resultPtr = Tcl_GetObjResult(interp);
/* set up callback procedures */
if( ((send_cb == NULL) || (*send_cb == '\0') ) ){
sproc = NULL;
sptr = NULL;
}
else{
sproc = XPATclSend;
sptr = (XPATclClientData)xcalloc(1, sizeof(XPATclClientDataRec));
sptr->interp = interp;
sptr->callback = xstrdup(send_cb);
sptr->client_data = xstrdup(sdata);
}
if( ((rec_cb == NULL) || (*rec_cb == '\0') ) ){
rproc = NULL;
rptr = NULL;
}
else{
rproc = XPATclReceive;
rptr = (XPATclClientData)xcalloc(1, sizeof(XPATclClientDataRec));
rptr->interp = interp;
rptr->callback = xstrdup(rec_cb);
rptr->client_data = xstrdup(rdata);
}
/* make sure we have either a send or receive callback */
if( !sproc && !rproc ){
Tcl_SetStringObj(resultPtr,
"XPA$ERROR: xpacmdadd requires send_cb or rec_cb (or both)", -1);
return(TCL_ERROR);
}
/* set up the tcl handler for the xpa access point */
xpacmd = XPACmdAdd(xpa, name, help, sproc, sptr, smode, rproc, rptr, rmode);
if( xpacmd == NULL ){
Tcl_SetStringObj(resultPtr, "XPA$ERROR: could not create XPA command", -1);
return(TCL_ERROR);
}
else{
/* return xpa address to tcl in a string */
snprintf(tbuf, SZ_LINE, "xpacmd_%p", xpacmd);
Tcl_SetStringObj(resultPtr, tbuf, -1);
return(TCL_OK);
}
}
/*
*----------------------------------------------------------------------------
*
* Routine: XPACmdDel_Tcl
*
* Purpose: Tcl binding to XPACmdDel procedure
*
* Tcl call:
*
* xpacmddel xpa cmd
*
* Returns: Tcl error code
*
*----------------------------------------------------------------------------
*/
#ifdef ANSI_FUNC
static int
XPACmdDel_Tcl(ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
#else
static int XPACmdDel_Tcl(clientData, interp, objc, objv)
ClientData clientData;
Tcl_Interp *interp;
int objc;
Tcl_Obj *CONST objv[];
#endif
{
void *lval;
char *s;
XPA xpa;
XPACmd cmd;
Tcl_Obj *resultPtr;
/* make sure argument count is correct */
if( objc != 3 ){
Tcl_WrongNumArgs(interp, 1, objv, "xpa cmd");
return(TCL_ERROR);
}
/* get result pointer */
resultPtr = Tcl_GetObjResult(interp);
/* get xpa, which is always arg 1 */
if( Tcl_GetXPAFromObj(interp, objv[1], TY_SERVER, &xpa) != TCL_OK){
return(TCL_ERROR);
}
/* get xpacmd, which is always arg 2 */
if( (s = Tcl_GetStringFromObj(objv[2], NULL)) == NULL ){
return(TCL_ERROR);
}
if( strncmp(s, "xpacmd_", 7) || (sscanf(&(s[7]), "%p", &lval) != 1) ){
Tcl_SetStringObj(resultPtr, "XPA$ERROR: invalid xpacmd handle", -1);
return(TCL_ERROR);
}
cmd = (XPACmd)lval;
/* reset error/result condition */
Tcl_ResetResult(interp);
/* call the XPACmdDel routine */
if( XPACmdDel(xpa, cmd) == 0 ){
/* free the associated tcl record, stored in the client data */
if( cmd->send_data ) xfree(cmd->send_data);
if( cmd->receive_data ) xfree(cmd->receive_data);
return(TCL_OK);
}
else{
resultPtr = Tcl_GetObjResult(interp);
Tcl_SetStringObj(resultPtr, "XPA$ERROR: could not delete xpa cmd", -1);
return(TCL_ERROR);
}
}
/*
*----------------------------------------------------------------------------
*
* Routine: XPARec_Tcl
*
* Purpose: Tcl binding to retrieve info from the xpa struct
*
* Tcl call:
*
* set val [xparec xpa <option>]
*
* where option can be one of the following:
*
* name
* class
* method
* cmdfd
* datafd
#ifndef HAVE_CYGWIN
* cmdchan
* datachan
#endif
* sendian
* cendian
* version
*
*
* Returns: Tcl error code
*
*----------------------------------------------------------------------------
*/
#ifdef ANSI_FUNC
static int
XPARec_Tcl(ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
#else
static int XPARec_Tcl(clientData, interp, objc, objv)
ClientData clientData;
Tcl_Interp *interp;
int objc;
Tcl_Obj *CONST objv[];
#endif
{
#ifndef HAVE_CYGWIN
Tcl_Channel chan;
#endif
static XCONST84 char *subCmds[] = {
"cendian",
"class",
#ifndef HAVE_CYGWIN
"cmdchan",
#endif
"cmdfd",
#ifndef HAVE_CYGWIN
"datachan",
#endif
"datafd",
"method",
"name",
"sendian",
"version",
(char *) NULL};
enum ISubCmdIdx {
ICendianIdx,
IClassIdx,
#ifndef HAVE_CYGWIN
ICmdChanIdx,
#endif
ICmdFdIdx,
#ifndef HAVE_CYGWIN
IDataChanIdx,
#endif
IDataFdIdx,
IMethodIdx,
INameIdx,
ISendianIdx,
IVersionIdx
} index;
XPA xpa;
int result;
char tbuf[SZ_LINE];
/* we always have 3 args: xparec $xpa [option] */
if (objc != 3) {
Tcl_WrongNumArgs(interp, 1, objv, "xpa option");
return TCL_ERROR;
}
/* get sub-command index */
if( (result = Tcl_GetIndexFromObj(interp, objv[2], subCmds, "option", 0,
(int *)&index)) != TCL_OK ){
return result;
}
/* get xpa, which is always arg 1 */
if( (result=Tcl_GetXPAFromObj(interp, objv[1], TY_SERVER, &xpa)) != TCL_OK){
/* valid xpa is required, except for version */
if( index != IVersionIdx )
return(TCL_ERROR);
}
/* process sub-command */
switch (index) {
case ICendianIdx:
Tcl_SetResult(interp, (char *)xpa_cendian(xpa), TCL_VOLATILE);
result = TCL_OK;
break;
case IClassIdx:
Tcl_SetResult(interp, xpa_class(xpa), TCL_VOLATILE);
result = TCL_OK;
break;
#ifndef HAVE_CYGWIN
case ICmdChanIdx:
snprintf(tbuf, SZ_LINE, "sock%d", xpa_cmdfd(xpa));
/* make sure we have a valid OS socket fd */
if( xpa_cmdfd(xpa) < 0 ){
Tcl_SetResult(interp, "none", TCL_STATIC);
result = TCL_OK;
}
/* see if this socket already is defined as a tcl variable */
else if( Tcl_GetChannel(interp, tbuf, NULL) != NULL ){
Tcl_SetResult(interp, tbuf, TCL_VOLATILE);
result = TCL_OK;
}
/* create new tcl variable for this socket */
else{
/* create a tcl channel corresponding to the xpa socket */
if( !(chan = Tcl_MakeTcpClientChannel((ClientData)(uintptr_t)xpa_cmdfd(xpa))) ){
Tcl_SetResult(interp, "XPA$ERROR: could not map XPA cmdfd to tcl",
TCL_STATIC);
result = TCL_ERROR;
}
else{
/* hold a reference to this channel outside tcl */
Tcl_RegisterChannel(NULL, chan);
/* register this channel with tcl */
Tcl_RegisterChannel(interp, chan);
/* make this Tcl channel unbuffered, so user does not have to flush */
Tcl_SetChannelOption(interp, chan, "-buffering", "none");
/* return name so that it can be used by tcl */
Tcl_SetResult(interp, (char *)Tcl_GetChannelName(chan), TCL_VOLATILE);
result = TCL_OK;
}
}
break;
#endif
case ICmdFdIdx:
if( xpa_cmdfd(xpa) < 0 )
strcpy(tbuf, "none");
else
snprintf(tbuf, SZ_LINE, "%d", xpa_cmdfd(xpa));
Tcl_SetResult(interp, tbuf, TCL_VOLATILE);
result = TCL_OK;
break;
#ifndef HAVE_CYGWIN
case IDataChanIdx:
snprintf(tbuf, SZ_LINE, "sock%d", xpa_datafd(xpa));
/* make sure we have a valid OS socket fd */
if( xpa_datafd(xpa) < 0 ){
Tcl_SetResult(interp, "none", TCL_STATIC);
result = TCL_OK;
}
/* see if this socket already is defined as a tcl variable */
else if( Tcl_GetChannel(interp, tbuf, NULL) != NULL ){
Tcl_SetResult(interp, tbuf, TCL_VOLATILE);
result = TCL_OK;
}
/* create new tcl variable for this socket */
else{
if( !(chan = Tcl_MakeTcpClientChannel((ClientData)(uintptr_t)xpa_datafd(xpa))) ){
Tcl_SetResult(interp, "XPA$ERROR: could not map XPA datafd to tcl",
TCL_STATIC);
result = TCL_ERROR;
}
else{
/* hold a reference to this channel outside tcl */
Tcl_RegisterChannel(NULL, chan);
/* register this channel with tcl */
Tcl_RegisterChannel(interp, chan);
/* make this Tcl channel unbuffered, so user does not have to flush */
Tcl_SetChannelOption(interp, chan, "-buffering", "none");
/* return name so that it can be used by tcl */
Tcl_SetResult(interp, (char *)Tcl_GetChannelName(chan), TCL_VOLATILE);
result = TCL_OK;
}
}
break;
#endif
case IDataFdIdx:
if( xpa_datafd(xpa) < 0 )
strcpy(tbuf, "none");
else
snprintf(tbuf, SZ_LINE, "%d", xpa_datafd(xpa));
Tcl_SetResult(interp, tbuf, TCL_VOLATILE);
result = TCL_OK;
break;
case IMethodIdx:
Tcl_SetResult(interp, xpa_method(xpa), TCL_VOLATILE);
result = TCL_OK;
break;
case INameIdx:
Tcl_SetResult(interp, xpa_name(xpa), TCL_VOLATILE);
result = TCL_OK;
break;
case ISendianIdx:
Tcl_SetResult(interp, xpa_sendian(xpa), TCL_VOLATILE);
result = TCL_OK;
break;
case IVersionIdx:
snprintf(tbuf, SZ_LINE, "%s", XPA_VERSION);
Tcl_SetResult(interp, tbuf, TCL_VOLATILE);
result = TCL_OK;
break;
}
return result;
}
/*
*----------------------------------------------------------------------------
*
* Routine: XPASetBuf_Tcl
*
* Purpose: Tcl binding to XPASetBuf procedure
*
* Tcl call:
*
* xpasetbuf xpa buf len
*
* Returns: Tcl error code
*
*----------------------------------------------------------------------------
*/
#ifdef ANSI_FUNC
static int
XPASetBuf_Tcl(ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
#else
static int XPASetBuf_Tcl(clientData, interp, objc, objv)
ClientData clientData;
Tcl_Interp *interp;
int objc;
Tcl_Obj *CONST objv[];
#endif
{
int error;
int len;
char *buf;
XPA xpa;
/* make sure argument count is correct */
if( objc < 3 ){
Tcl_WrongNumArgs(interp, 1, objv, "xpa buf len");
return(TCL_ERROR);
}
/* get xpa, which is always arg 1 */
if( Tcl_GetXPAFromObj(interp, objv[1], TY_SERVER, &xpa) != TCL_OK){
return(TCL_ERROR);
}
/* get buf */
buf = Tcl_GetStringFromObj(objv[2], &len);
/* get len if specified */
if( objc >= 4 ){
if( (error = Tcl_GetIntFromObj(interp, objv[3], &len)) != TCL_OK )
return(error);
}
/* copy buffer to the xpa struct */
XPASetBuf(xpa, buf, len, 1);
/* return status */
return(TCL_OK);
}
/*
*----------------------------------------------------------------------------
*
* Routine: XPAOpen_Tcl
*
* Purpose: Tcl binding to XPAOpen procedure
*
* Tcl call:
*
* xpaopen mode
*
* mode currently is NULL
*
* Returns: Tcl error code
*
*----------------------------------------------------------------------------
*/
#ifdef ANSI_FUNC
static int
XPAOpen_Tcl(ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
#else
static int XPAOpen_Tcl(clientData, interp, objc, objv)
ClientData clientData;
Tcl_Interp *interp;
int objc;
Tcl_Obj *CONST objv[];
#endif
{
char *mode;
char tbuf[SZ_LINE];
XPA xpa;
Tcl_Obj *resultPtr;
/* make sure argument count is correct */
if( objc != 2 ){
Tcl_WrongNumArgs(interp, 1, objv, "mode");
return(TCL_ERROR);
}
/* get arguments as strings */
mode = Tcl_GetStringFromObj(objv[1], NULL);
/* this will hold the result */
resultPtr = Tcl_GetObjResult(interp);
/* set up the tcl handler for the xpa access point */
xpa = XPAOpen(mode);
if( xpa == NULL ){
Tcl_SetStringObj(resultPtr,
"XPA$ERROR: could not open XPA", -1);
return(TCL_ERROR);
}
else{
/* return xpa address to tcl in a string */
snprintf(tbuf, SZ_LINE, "xpa_%p", xpa);
Tcl_SetStringObj(resultPtr, tbuf, -1);
return(TCL_OK);
}
}
/*
*----------------------------------------------------------------------------
*
* Routine: XPAClose_Tcl
*
* Purpose: Tcl binding to XPAClose procedure
*
* Tcl call:
*
* xpaclose xpa
*
* Returns: Tcl error code
*
*----------------------------------------------------------------------------
*/
#ifdef ANSI_FUNC
static int
XPAClose_Tcl(ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
#else
static int XPAClose_Tcl(clientData, interp, objc, objv)
ClientData clientData;
Tcl_Interp *interp;
int objc;
Tcl_Obj *CONST objv[];
#endif
{
XPA xpa;
/* make sure argument count is correct */
if( objc != 2 ){
Tcl_WrongNumArgs(interp, 1, objv, "xpa");
return(TCL_ERROR);
}
/* get xpa, which is always arg 1 */
if( Tcl_GetXPAFromObj(interp, objv[1], TY_CLIENT, &xpa) != TCL_OK){
return(TCL_ERROR);
}
/* reset error/result condition */
Tcl_ResetResult(interp);
/* call the XPAClose routine */
XPAClose(xpa);
return(TCL_OK);
}
/*
*----------------------------------------------------------------------------
*
* Routine: XPAGet_Tcl
*
* Purpose: Tcl binding to XPAGet procedure
*
* Tcl call:
*
* set got [xpaget xpa template paramlist mode bufs lens names errs n]
*
* Returns: Tcl error code
*
*----------------------------------------------------------------------------
*/
#ifdef ANSI_FUNC
static int
XPAGet_Tcl(ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
#else
static int XPAGet_Tcl(clientData, interp, objc, objv)
ClientData clientData;
Tcl_Interp *interp;
int objc;
Tcl_Obj *CONST objv[];
#endif
{
XPA xpa;
int got;
int n;
int i;
size_t *clens=NULL;
char *xpastr;
char *tmpl;
char *paramlist;
char *mode;
/* char *bufs; */
/* char *lens; */
char *names;
char *errs;
char **cbufs=NULL;
char **cnames=NULL;
char **cerrs=NULL;
Tcl_Obj *resultPtr;
Tcl_Obj *nullPtr;
Tcl_Obj *bufsPtr;
Tcl_Obj *lensPtr;
Tcl_Obj *namesPtr;
Tcl_Obj *errsPtr;
Tcl_Obj **bufsObjv;
Tcl_Obj **lensObjv;
Tcl_Obj **namesObjv=NULL;
Tcl_Obj **errsObjv=NULL;
/* make sure argument count is correct */
if( objc != 10 ){
Tcl_WrongNumArgs(interp, 1, objv,
"xpa template paramlist mode bufs lens names errs n");
return(TCL_ERROR);
}
/* get result pointer */
resultPtr = Tcl_GetObjResult(interp);
/* get xpa struct pointer, which might be NULL */
xpastr = Tcl_GetStringFromObj(objv[1], NULL);
if( TCL_NULLSTR(xpastr) )
xpa = NULL;
else{
/* get xpa, which is always arg 1 */
if( Tcl_GetXPAFromObj(interp, objv[1], TY_CLIENT, &xpa) != TCL_OK){
Tcl_SetStringObj(resultPtr, "XPA$ERROR: invalid xpa client handle", -1);
return(TCL_ERROR);
}
}
/* get other args */
tmpl = Tcl_GetStringFromObj(objv[2], NULL);
paramlist = Tcl_GetStringFromObj(objv[3], NULL);
mode = Tcl_GetStringFromObj(objv[4], NULL);
/* bufs = Tcl_GetStringFromObj(objv[5], NULL); */
/* lens = Tcl_GetStringFromObj(objv[6], NULL); */
names = Tcl_GetStringFromObj(objv[7], NULL);
errs = Tcl_GetStringFromObj(objv[8], NULL);
if( (Tcl_GetIntFromObj(interp, objv[9], &n) != TCL_OK) || (n < 1) ){
n = 1;
}
/* allocate return buffers */
cbufs = (char **)xcalloc(n, sizeof(char *));
bufsObjv = (Tcl_Obj **)xcalloc(n, sizeof(Tcl_Obj *));
clens = (size_t *)xcalloc(n, sizeof(size_t));
lensObjv = (Tcl_Obj **)xcalloc(n, sizeof(Tcl_Obj *));
if( !TCL_NULLSTR(names) ){
cnames = (char **)xcalloc(n, sizeof(char *));
namesObjv = (Tcl_Obj **)xcalloc(n, sizeof(Tcl_Obj *));
}
if( !TCL_NULLSTR(errs) ){
cerrs = (char **)xcalloc(n, sizeof(char *));
errsObjv = (Tcl_Obj **)xcalloc(n, sizeof(Tcl_Obj *));
}
/* reset before we make C call */
Tcl_ResetResult(interp);
/* make the XPA C call */
got = XPAGet(xpa, tmpl, paramlist, mode, cbufs, clens, cnames, cerrs, n);
/* if we got anything, fill in the blanks */
if( got > 0 ){
/* generate a Tcl object for each return argument */
for(i=0; i<got; i++){
bufsObjv[i] = Tcl_NewObj();
Tcl_SetStringObj(bufsObjv[i], cbufs[i], clens[i]);
lensObjv[i] = Tcl_NewObj();
Tcl_SetIntObj(lensObjv[i], clens[i]);
if( cnames ){
namesObjv[i] = Tcl_NewObj();
Tcl_SetStringObj(namesObjv[i], cnames[i],
cnames[i] ? strlen(cnames[i]) : 0);
}
if( cerrs ){
errsObjv[i] = Tcl_NewObj();
Tcl_SetStringObj(errsObjv[i], cerrs[i],
cerrs[i] ? strlen(cerrs[i]) : 0);
}
}
/* make lists from the return arguments and set the return variables */
bufsPtr = Tcl_NewObj();
Tcl_SetListObj(bufsPtr, got, bufsObjv);
Tcl_ObjSetVar2(interp, objv[5], NULL, bufsPtr, TCL_PARSE_PART1);
lensPtr = Tcl_NewObj();
Tcl_SetListObj(lensPtr, got, lensObjv);
Tcl_ObjSetVar2(interp, objv[6], NULL, lensPtr, TCL_PARSE_PART1);
if( cnames ){
namesPtr = Tcl_NewObj();
Tcl_SetListObj(namesPtr, got, namesObjv);
Tcl_ObjSetVar2(interp, objv[7], NULL, namesPtr, TCL_PARSE_PART1);
}
if( cerrs ){
errsPtr = Tcl_NewObj();
Tcl_SetListObj(errsPtr, got, errsObjv);
Tcl_ObjSetVar2(interp, objv[8], NULL, errsPtr, TCL_PARSE_PART1);
}
}
else{
nullPtr = Tcl_NewObj();
Tcl_SetStringObj(nullPtr, "", -1);
Tcl_ObjSetVar2(interp, objv[5], NULL, nullPtr, TCL_PARSE_PART1);
Tcl_ObjSetVar2(interp, objv[6], NULL, nullPtr, TCL_PARSE_PART1);
if( cnames )
Tcl_ObjSetVar2(interp, objv[7], NULL, nullPtr, TCL_PARSE_PART1);
if( cerrs )
Tcl_ObjSetVar2(interp, objv[8], NULL, nullPtr, TCL_PARSE_PART1);
}
/* free up space */
for(i=0; i<got; i++){
if( cbufs[i] ) xfree((char *)cbufs[i]);
if( cnames[i] ) xfree((char *)cnames[i]);
if( cerrs[i] ) xfree((char *)cerrs[i]);
}
if( cbufs ) xfree((char *)cbufs);
if( clens ) xfree((char *)clens);
if( cnames ) xfree((char *)cnames);
if( cerrs ) xfree((char *)cerrs);
if( bufsObjv ) xfree((char *)bufsObjv);
if( lensObjv ) xfree((char *)lensObjv);
if( namesObjv ) xfree((char *)namesObjv);
if( errsObjv ) xfree((char *)errsObjv);
/* return the number of accesses as the tcl function result */
resultPtr = Tcl_GetObjResult(interp);
Tcl_SetIntObj(resultPtr, got);
/* return status */
return(TCL_OK);
}
/*
*----------------------------------------------------------------------------
*
* Routine: XPAGetFd_Tcl
*
* Purpose: Tcl binding to XPAGetFd procedure
*
* Tcl call:
*
* set got [xpaget xpa template paramlist mode chans names errs n]
*
* Returns: Tcl error code
*
*----------------------------------------------------------------------------
*/
#ifdef ANSI_FUNC
static int
XPAGetFd_Tcl(ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
#else
static int XPAGetFd_Tcl(clientData, interp, objc, objv)
ClientData clientData;
Tcl_Interp *interp;
int objc;
Tcl_Obj *CONST objv[];
#endif
{
XPA xpa;
int got;
int n;
int i;
int flag;
int *cfds;
char *xpastr;
char *tmpl;
char *paramlist;
char *mode;
char *names;
char *errs;
char **cnames=NULL;
char **cerrs=NULL;
Tcl_Obj *resultPtr;
Tcl_Obj *nullPtr;
Tcl_Obj *fdPtr;
Tcl_Obj *namesPtr;
Tcl_Obj *errsPtr;
Tcl_Obj **namesObjv=NULL;
Tcl_Obj **errsObjv=NULL;
Tcl_Channel chan;
/* make sure argument count is correct */
if( objc != 9 ){
Tcl_WrongNumArgs(interp, 1, objv,
"xpa template paramlist mode chans names errs n");
return(TCL_ERROR);
}
/* get result pointer */
resultPtr = Tcl_GetObjResult(interp);
/* get xpa struct pointer, which might be NULL */
xpastr = Tcl_GetStringFromObj(objv[1], NULL);
if( TCL_NULLSTR(xpastr) )
xpa = NULL;
else{
/* get xpa, which is always arg 1 */
if( Tcl_GetXPAFromObj(interp, objv[1], TY_CLIENT, &xpa) != TCL_OK ){
Tcl_SetStringObj(resultPtr, "XPA$ERROR: invalid xpa client handle", -1);
return(TCL_ERROR);
}
}
/* get other args */
tmpl = Tcl_GetStringFromObj(objv[2], NULL);
paramlist = Tcl_GetStringFromObj(objv[3], NULL);
mode = Tcl_GetStringFromObj(objv[4], NULL);
names = Tcl_GetStringFromObj(objv[6], NULL);
errs = Tcl_GetStringFromObj(objv[7], NULL);
if( (Tcl_GetIntFromObj(interp, objv[8], &n) != TCL_OK) || (n < 1) ){
n = 1;
}
/* get file descriptors */
if( n < 0 ){
cfds = (int *)xcalloc(1, sizeof(int));
if( Tcl_ListObjIndex(interp, objv[5], 0, &fdPtr) != TCL_OK ){
Tcl_SetStringObj(resultPtr,
"XPA$ERROR: invalid channel list passed to xpagetfd", -1);
return(TCL_ERROR);
}
else{
chan = Tcl_GetChannel(interp, Tcl_GetStringFromObj(fdPtr, NULL),
&flag);
if( chan == NULL ){
Tcl_SetStringObj(resultPtr,
"XPA$ERROR: invalid channel passed to xpagetfd", -1);
return(TCL_ERROR);
}
if( !(flag&TCL_WRITABLE) ){
Tcl_SetStringObj(resultPtr,
"XPA$ERROR: non-writable channel passed to xpagetfd", -1);
return(TCL_ERROR);
}
Tcl_GetChannelHandle(chan, TCL_WRITABLE, (ClientData *)&(cfds[0]));
}
}
else{
cfds = (int *)xcalloc(n, sizeof(int));
for(i=0; i<n; i++){
if( Tcl_ListObjIndex(interp, objv[5], i, &fdPtr) != TCL_OK ){
Tcl_SetStringObj(resultPtr,
"XPA$ERROR: invalid channel list passed to xpagetfd", -1);
return(TCL_ERROR);
}
else{
chan = Tcl_GetChannel(interp, Tcl_GetStringFromObj(fdPtr, NULL),
&flag);
if( chan == NULL ){
Tcl_SetStringObj(resultPtr,
"XPA$ERROR: invalid channel passed to xpagetfd", -1);
return(TCL_ERROR);
}
if( !(flag&TCL_WRITABLE) ){
Tcl_SetStringObj(resultPtr,
"XPA$ERROR: non-writable channel passed to xpagetfd", -1);
return(TCL_ERROR);
}
Tcl_GetChannelHandle(chan, TCL_WRITABLE, (ClientData *)&(cfds[i]));
}
}
}
/* allocate return buffers */
if( !TCL_NULLSTR(names) ){
cnames = (char **)xcalloc(n, sizeof(char *));
namesObjv = (Tcl_Obj **)xcalloc(n, sizeof(Tcl_Obj *));
}
if( !TCL_NULLSTR(errs) ){
cerrs = (char **)xcalloc(n, sizeof(char *));
errsObjv = (Tcl_Obj **)xcalloc(n, sizeof(Tcl_Obj *));
}
/* reset before we make C call */
Tcl_ResetResult(interp);
/* make the XPA C call */
got = XPAGetFd(xpa, tmpl, paramlist, mode, cfds, cnames, cerrs, n);
/* if we got anything, fill in the blanks */
if( got > 0 ){
/* generate a Tcl object for each return argument */
for(i=0; i<got; i++){
if( cnames ){
namesObjv[i] = Tcl_NewObj();
Tcl_SetStringObj(namesObjv[i], cnames[i],
cnames[i] ? strlen(cnames[i]) : 0);
}
if( cerrs ){
errsObjv[i] = Tcl_NewObj();
Tcl_SetStringObj(errsObjv[i], cerrs[i],
cerrs[i] ? strlen(cerrs[i]) : 0);
}
}
/* make lists from the return arguments and set the return variables */
if( cnames ){
namesPtr = Tcl_NewObj();
Tcl_SetListObj(namesPtr, got, namesObjv);
Tcl_ObjSetVar2(interp, objv[6], NULL, namesPtr, TCL_PARSE_PART1);
}
if( cerrs ){
errsPtr = Tcl_NewObj();
Tcl_SetListObj(errsPtr, got, errsObjv);
Tcl_ObjSetVar2(interp, objv[7], NULL, errsPtr, TCL_PARSE_PART1);
}
}
else{
nullPtr = Tcl_NewObj();
Tcl_SetStringObj(nullPtr, "", -1);
if( cnames )
Tcl_ObjSetVar2(interp, objv[6], NULL, nullPtr, TCL_PARSE_PART1);
if( cerrs )
Tcl_ObjSetVar2(interp, objv[7], NULL, nullPtr, TCL_PARSE_PART1);
}
/* free up space */
for(i=0; i<got; i++){
if( cnames[i] ) xfree((char *)cnames[i]);
if( cerrs[i] ) xfree((char *)cerrs[i]);
}
if( cfds ) xfree((char *)cfds);
if( cnames ) xfree((char *)cnames);
if( cerrs ) xfree((char *)cerrs);
if( namesObjv ) xfree((char *)namesObjv);
if( errsObjv ) xfree((char *)errsObjv);
/* return the number of accesses as the tcl function result */
Tcl_SetIntObj(resultPtr, got);
/* return status */
return(TCL_OK);
}
/*
*----------------------------------------------------------------------------
*
* Routine: XPASet_Tcl
*
* Purpose: Tcl binding to XPASet procedure
*
* Tcl call:
*
* set got [xpaset xpa template paramlist mode buf len names errs n]
*
* Returns: Tcl error code
*
*----------------------------------------------------------------------------
*/
#ifdef ANSI_FUNC
static int
XPASet_Tcl(ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
#else
static int XPASet_Tcl(clientData, interp, objc, objv)
ClientData clientData;
Tcl_Interp *interp;
int objc;
Tcl_Obj *CONST objv[];
#endif
{
XPA xpa;
int got;
int n;
int i;
int blen;
int len;
char *xpastr;
char *tmpl;
char *paramlist;
char *mode;
char *buf;
char *names;
char *errs;
char **cnames=NULL;
char **cerrs=NULL;
Tcl_Obj *resultPtr;
Tcl_Obj *nullPtr;
Tcl_Obj *namesPtr;
Tcl_Obj *errsPtr;
Tcl_Obj **namesObjv=NULL;
Tcl_Obj **errsObjv=NULL;
/* make sure argument count is correct */
if( objc != 10 ){
Tcl_WrongNumArgs(interp, 1, objv,
"xpa template paramlist mode buf len names errs n");
return(TCL_ERROR);
}
/* get result pointer */
resultPtr = Tcl_GetObjResult(interp);
/* get xpa struct pointer, which might be NULL */
xpastr = Tcl_GetStringFromObj(objv[1], NULL);
if( TCL_NULLSTR(xpastr) )
xpa = NULL;
else{
/* get xpa, which is always arg 1 */
if( Tcl_GetXPAFromObj(interp, objv[1], TY_CLIENT, &xpa) != TCL_OK ){
Tcl_SetStringObj(resultPtr, "XPA$ERROR: invalid xpa client handle", -1);
return(TCL_ERROR);
}
}
/* get other args */
tmpl = Tcl_GetStringFromObj(objv[2], NULL);
paramlist = Tcl_GetStringFromObj(objv[3], NULL);
mode = Tcl_GetStringFromObj(objv[4], NULL);
buf = Tcl_GetStringFromObj(objv[5], &blen);
if( (Tcl_GetIntFromObj(interp, objv[6], &len) != TCL_OK) || (len < 0) ){
len = blen;
}
names = Tcl_GetStringFromObj(objv[7], NULL);
errs = Tcl_GetStringFromObj(objv[8], NULL);
if( (Tcl_GetIntFromObj(interp, objv[9], &n) != TCL_OK) || (n < 1) ){
n = 1;
}
/* allocate return buffers */
if( !TCL_NULLSTR(names) ){
cnames = (char **)xcalloc(n, sizeof(char *));
namesObjv = (Tcl_Obj **)xcalloc(n, sizeof(Tcl_Obj *));
}
if( !TCL_NULLSTR(errs) ){
cerrs = (char **)xcalloc(n, sizeof(char *));
errsObjv = (Tcl_Obj **)xcalloc(n, sizeof(Tcl_Obj *));
}
/* reset before we make C call */
Tcl_ResetResult(interp);
/* make the XPA C call */
got = XPASet(xpa, tmpl, paramlist, mode, buf, len, cnames, cerrs, n);
/* if we got anything, fill in the blanks */
if( got > 0 ){
/* generate a Tcl object for each return argument */
for(i=0; i<got; i++){
if( cnames ){
namesObjv[i] = Tcl_NewObj();
Tcl_SetStringObj(namesObjv[i], cnames[i],
cnames[i] ? strlen(cnames[i]) : 0);
}
if( cerrs ){
errsObjv[i] = Tcl_NewObj();
Tcl_SetStringObj(errsObjv[i], cerrs[i],
cerrs[i] ? strlen(cerrs[i]) : 0);
}
}
/* make lists from the return arguments and set the return variables */
if( cnames ){
namesPtr = Tcl_NewObj();
Tcl_SetListObj(namesPtr, got, namesObjv);
Tcl_ObjSetVar2(interp, objv[7], NULL, namesPtr, TCL_PARSE_PART1);
}
if( cerrs ){
errsPtr = Tcl_NewObj();
Tcl_SetListObj(errsPtr, got, errsObjv);
Tcl_ObjSetVar2(interp, objv[8], NULL, errsPtr, TCL_PARSE_PART1);
}
}
else{
nullPtr = Tcl_NewObj();
Tcl_SetStringObj(nullPtr, "", -1);
if( cnames )
Tcl_ObjSetVar2(interp, objv[7], NULL, nullPtr, TCL_PARSE_PART1);
if( cerrs )
Tcl_ObjSetVar2(interp, objv[8], NULL, nullPtr, TCL_PARSE_PART1);
}
/* free up space */
for(i=0; i<got; i++){
if( cnames[i] ) xfree((char *)cnames[i]);
if( cerrs[i] ) xfree((char *)cerrs[i]);
}
if( cnames ) xfree((char *)cnames);
if( cerrs ) xfree((char *)cerrs);
if( namesObjv ) xfree((char *)namesObjv);
if( errsObjv ) xfree((char *)errsObjv);
/* return the number of accesses as the tcl function result */
Tcl_SetIntObj(resultPtr, got);
/* return status */
return(TCL_OK);
}
/*
*----------------------------------------------------------------------------
*
* Routine: XPASetFd_Tcl
*
* Purpose: Tcl binding to XPASetFd procedure
*
* Tcl call:
*
* set got [xpasetfd xpa template paramlist mode chan names errs n]
*
* Returns: Tcl error code
*
*----------------------------------------------------------------------------
*/
#ifdef ANSI_FUNC
static int
XPASetFd_Tcl(ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
#else
static int XPASetFd_Tcl(clientData, interp, objc, objv)
ClientData clientData;
Tcl_Interp *interp;
int objc;
Tcl_Obj *CONST objv[];
#endif
{
XPA xpa;
int got;
int n;
int i;
int flag;
int fd;
char *xpastr;
char *tmpl;
char *paramlist;
char *mode;
char *names;
char *errs;
char **cnames=NULL;
char **cerrs=NULL;
Tcl_Obj *resultPtr;
Tcl_Obj *nullPtr;
Tcl_Obj *namesPtr;
Tcl_Obj *errsPtr;
Tcl_Obj **namesObjv=NULL;
Tcl_Obj **errsObjv=NULL;
Tcl_Channel chan;
/* make sure argument count is correct */
if( objc != 9 ){
Tcl_WrongNumArgs(interp, 1, objv,
"xpa template paramlist mode chan names errs n");
return(TCL_ERROR);
}
/* get result pointer */
resultPtr = Tcl_GetObjResult(interp);
/* get xpa struct pointer, which might be NULL */
xpastr = Tcl_GetStringFromObj(objv[1], NULL);
if( TCL_NULLSTR(xpastr) )
xpa = NULL;
else{
/* get xpa, which is always arg 1 */
if( Tcl_GetXPAFromObj(interp, objv[1], TY_CLIENT, &xpa) != TCL_OK){
Tcl_SetStringObj(resultPtr, "XPA$ERROR: invalid xpa client handle", -1);
return(TCL_ERROR);
}
}
/* get other args */
tmpl = Tcl_GetStringFromObj(objv[2], NULL);
paramlist = Tcl_GetStringFromObj(objv[3], NULL);
mode = Tcl_GetStringFromObj(objv[4], NULL);
names = Tcl_GetStringFromObj(objv[6], NULL);
errs = Tcl_GetStringFromObj(objv[7], NULL);
if( (Tcl_GetIntFromObj(interp, objv[8], &n) != TCL_OK) || (n < 1) ){
n = 1;
}
/* allocate return buffers */
if( !TCL_NULLSTR(names) ){
cnames = (char **)xcalloc(n, sizeof(char *));
namesObjv = (Tcl_Obj **)xcalloc(n, sizeof(Tcl_Obj *));
}
if( !TCL_NULLSTR(errs) ){
cerrs = (char **)xcalloc(n, sizeof(char *));
errsObjv = (Tcl_Obj **)xcalloc(n, sizeof(Tcl_Obj *));
}
/* get file descriptor */
chan = Tcl_GetChannel(interp, Tcl_GetStringFromObj(objv[5], NULL), &flag);
if( chan == NULL ){
Tcl_SetStringObj(resultPtr,
"XPA$ERROR: invalid channel passed to xpasetfd", -1);
return(TCL_ERROR);
}
if( !(flag&TCL_READABLE) ){
Tcl_SetStringObj(resultPtr,
"XPA$ERROR: non-readable channel passed to xpasetfd", -1);
return(TCL_ERROR);
}
Tcl_GetChannelHandle(chan, TCL_READABLE, (ClientData *)&fd);
/* reset before we make C call */
Tcl_ResetResult(interp);
/* make the XPA C call */
got = XPASetFd(xpa, tmpl, paramlist, mode, fd, cnames, cerrs, n);
/* if we got anything, fill in the blanks */
if( got > 0 ){
/* generate a Tcl object for each return argument */
for(i=0; i<got; i++){
if( cnames ){
namesObjv[i] = Tcl_NewObj();
Tcl_SetStringObj(namesObjv[i], cnames[i],
cnames[i] ? strlen(cnames[i]) : 0);
}
if( cerrs ){
errsObjv[i] = Tcl_NewObj();
Tcl_SetStringObj(errsObjv[i], cerrs[i],
cerrs[i] ? strlen(cerrs[i]) : 0);
}
}
/* make lists from the return arguments and set the return variables */
if( cnames ){
namesPtr = Tcl_NewObj();
Tcl_SetListObj(namesPtr, got, namesObjv);
Tcl_ObjSetVar2(interp, objv[6], NULL, namesPtr, TCL_PARSE_PART1);
}
if( cerrs ){
errsPtr = Tcl_NewObj();
Tcl_SetListObj(errsPtr, got, errsObjv);
Tcl_ObjSetVar2(interp, objv[7], NULL, errsPtr, TCL_PARSE_PART1);
}
}
else{
nullPtr = Tcl_NewObj();
Tcl_SetStringObj(nullPtr, "", -1);
if( cnames )
Tcl_ObjSetVar2(interp, objv[6], NULL, nullPtr, TCL_PARSE_PART1);
if( cerrs )
Tcl_ObjSetVar2(interp, objv[7], NULL, nullPtr, TCL_PARSE_PART1);
}
/* free up space */
for(i=0; i<got; i++){
if( cnames[i] ) xfree((char *)cnames[i]);
if( cerrs[i] ) xfree((char *)cerrs[i]);
}
if( cnames ) xfree((char *)cnames);
if( cerrs ) xfree((char *)cerrs);
if( namesObjv ) xfree((char *)namesObjv);
if( errsObjv ) xfree((char *)errsObjv);
/* return the number of accesses as the tcl function result */
Tcl_SetIntObj(resultPtr, got);
/* return status */
return(TCL_OK);
}
/*
*----------------------------------------------------------------------------
*
* Routine: XPAInfo_Tcl
*
* Purpose: Tcl binding to XPAInfo procedure
*
* Tcl call:
*
* set got [xpainfo xpa template paramlist mode names errs n]
*
* Returns: Tcl error code
*
*----------------------------------------------------------------------------
*/
#ifdef ANSI_FUNC
static int
XPAInfo_Tcl(ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
#else
static int XPAInfo_Tcl(clientData, interp, objc, objv)
ClientData clientData;
Tcl_Interp *interp;
int objc;
Tcl_Obj *CONST objv[];
#endif
{
XPA xpa;
int got;
int n;
int i;
char *xpastr;
char *tmpl;
char *paramlist;
char *mode;
char *names;
char *errs;
char **cnames=NULL;
char **cerrs=NULL;
Tcl_Obj *resultPtr;
Tcl_Obj *nullPtr;
Tcl_Obj *namesPtr;
Tcl_Obj *errsPtr;
Tcl_Obj **namesObjv=NULL;
Tcl_Obj **errsObjv=NULL;
/* make sure argument count is correct */
if( objc != 8 ){
Tcl_WrongNumArgs(interp, 1, objv,
"xpa template paramlist mode names errs n");
return(TCL_ERROR);
}
/* get result pointer */
resultPtr = Tcl_GetObjResult(interp);
/* get xpa struct pointer, which might be NULL */
xpastr = Tcl_GetStringFromObj(objv[1], NULL);
if( TCL_NULLSTR(xpastr) )
xpa = NULL;
else{
/* get xpa, which is always arg 1 */
if( Tcl_GetXPAFromObj(interp, objv[1], TY_CLIENT, &xpa) != TCL_OK){
Tcl_SetStringObj(resultPtr, "XPA$ERROR: invalid xpa client handle", -1);
return(TCL_ERROR);
}
}
/* get other args */
tmpl = Tcl_GetStringFromObj(objv[2], NULL);
paramlist = Tcl_GetStringFromObj(objv[3], NULL);
mode = Tcl_GetStringFromObj(objv[4], NULL);
names = Tcl_GetStringFromObj(objv[5], NULL);
errs = Tcl_GetStringFromObj(objv[6], NULL);
if( (Tcl_GetIntFromObj(interp, objv[7], &n) != TCL_OK) || (n < 1) ){
n = 1;
}
/* allocate return buffers */
if( !TCL_NULLSTR(names) ){
cnames = (char **)xcalloc(n, sizeof(char *));
namesObjv = (Tcl_Obj **)xcalloc(n, sizeof(Tcl_Obj *));
}
if( !TCL_NULLSTR(errs) ){
cerrs = (char **)xcalloc(n, sizeof(char *));
errsObjv = (Tcl_Obj **)xcalloc(n, sizeof(Tcl_Obj *));
}
/* reset before we make C call */
Tcl_ResetResult(interp);
/* make the XPA C call */
got = XPAInfo(xpa, tmpl, paramlist, mode, cnames, cerrs, n);
/* if we got anything, fill in the blanks */
if( got > 0 ){
/* generate a Tcl object for each return argument */
for(i=0; i<got; i++){
if( cnames ){
namesObjv[i] = Tcl_NewObj();
Tcl_SetStringObj(namesObjv[i], cnames[i],
cnames[i] ? strlen(cnames[i]) : 0);
}
if( cerrs ){
errsObjv[i] = Tcl_NewObj();
Tcl_SetStringObj(errsObjv[i], cerrs[i],
cerrs[i] ? strlen(cerrs[i]) : 0);
}
}
/* make lists from the return arguments and set the return variables */
if( cnames ){
namesPtr = Tcl_NewObj();
Tcl_SetListObj(namesPtr, got, namesObjv);
Tcl_ObjSetVar2(interp, objv[5], NULL, namesPtr, TCL_PARSE_PART1);
}
if( cerrs ){
errsPtr = Tcl_NewObj();
Tcl_SetListObj(errsPtr, got, errsObjv);
Tcl_ObjSetVar2(interp, objv[6], NULL, errsPtr, TCL_PARSE_PART1);
}
}
else{
nullPtr = Tcl_NewObj();
Tcl_SetStringObj(nullPtr, "", -1);
if( cnames )
Tcl_ObjSetVar2(interp, objv[5], NULL, nullPtr, TCL_PARSE_PART1);
if( cerrs )
Tcl_ObjSetVar2(interp, objv[6], NULL, nullPtr, TCL_PARSE_PART1);
}
/* free up space */
for(i=0; i<got; i++){
if( cnames[i] ) xfree((char *)cnames[i]);
if( cerrs[i] ) xfree((char *)cerrs[i]);
}
if( cnames ) xfree((char *)cnames);
if( cerrs ) xfree((char *)cerrs);
if( namesObjv ) xfree((char *)namesObjv);
if( errsObjv ) xfree((char *)errsObjv);
/* return the number of accesses as the tcl function result */
Tcl_SetIntObj(resultPtr, got);
/* return status */
return(TCL_OK);
}
/*
*----------------------------------------------------------------------------
*
* Routine: XPAAccess_Tcl
*
* Purpose: Tcl binding to XPAAccess procedure
*
* Tcl call:
*
* set got [xpaaccess xpa template paramlist mode names errs n]
*
* Returns: Tcl error code
*
*----------------------------------------------------------------------------
*/
#ifdef ANSI_FUNC
static int
XPAAccess_Tcl(ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
#else
static int XPAAccess_Tcl(clientData, interp, objc, objv)
ClientData clientData;
Tcl_Interp *interp;
int objc;
Tcl_Obj *CONST objv[];
#endif
{
XPA xpa;
int got;
int n;
int i;
char *xpastr;
char *tmpl;
char *paramlist;
char *mode;
char *names;
char *errs;
char **cnames=NULL;
char **cerrs=NULL;
Tcl_Obj *resultPtr;
Tcl_Obj *nullPtr;
Tcl_Obj *namesPtr;
Tcl_Obj *errsPtr;
Tcl_Obj **namesObjv=NULL;
Tcl_Obj **errsObjv=NULL;
/* make sure argument count is correct */
if( objc != 8 ){
Tcl_WrongNumArgs(interp, 1, objv,
"xpa template paramlist mode names errs n");
return(TCL_ERROR);
}
/* get result pointer */
resultPtr = Tcl_GetObjResult(interp);
/* get xpa struct pointer, which might be NULL */
xpastr = Tcl_GetStringFromObj(objv[1], NULL);
if( TCL_NULLSTR(xpastr) )
xpa = NULL;
else{
/* get xpa, which is always arg 1 */
if( Tcl_GetXPAFromObj(interp, objv[1], TY_CLIENT, &xpa) != TCL_OK){
Tcl_SetStringObj(resultPtr, "XPA$ERROR: invalid xpa client handle", -1);
return(TCL_ERROR);
}
}
/* get other args */
tmpl = Tcl_GetStringFromObj(objv[2], NULL);
paramlist = Tcl_GetStringFromObj(objv[3], NULL);
mode = Tcl_GetStringFromObj(objv[4], NULL);
names = Tcl_GetStringFromObj(objv[5], NULL);
errs = Tcl_GetStringFromObj(objv[6], NULL);
if( (Tcl_GetIntFromObj(interp, objv[7], &n) != TCL_OK) || (n < 1) ){
n = 1;
}
if( !TCL_NULLSTR(names) ){
cnames = (char **)xcalloc(n, sizeof(char *));
namesObjv = (Tcl_Obj **)xcalloc(n, sizeof(Tcl_Obj *));
}
if( !TCL_NULLSTR(errs) ){
cerrs = (char **)xcalloc(n, sizeof(char *));
errsObjv = (Tcl_Obj **)xcalloc(n, sizeof(Tcl_Obj *));
}
/* reset before we make C call */
Tcl_ResetResult(interp);
/* make the XPA C call */
got = XPAAccess(xpa, tmpl, paramlist, mode, cnames, cerrs, n);
/* if we got anything, fill in the blanks */
if( got > 0 ){
/* generate a Tcl object for each return argument */
for(i=0; i<got; i++){
if( cnames ){
namesObjv[i] = Tcl_NewObj();
Tcl_SetStringObj(namesObjv[i], cnames[i],
cnames[i] ? strlen(cnames[i]) : 0);
}
if( cerrs ){
errsObjv[i] = Tcl_NewObj();
Tcl_SetStringObj(errsObjv[i], cerrs[i],
cerrs[i] ? strlen(cerrs[i]) : 0);
}
}
/* make lists from the return arguments and set the return variables */
if( cnames ){
namesPtr = Tcl_NewObj();
Tcl_SetListObj(namesPtr, got, namesObjv);
Tcl_ObjSetVar2(interp, objv[5], NULL, namesPtr, TCL_PARSE_PART1);
}
if( cerrs ){
errsPtr = Tcl_NewObj();
Tcl_SetListObj(errsPtr, got, errsObjv);
Tcl_ObjSetVar2(interp, objv[6], NULL, errsPtr, TCL_PARSE_PART1);
}
}
else{
nullPtr = Tcl_NewObj();
Tcl_SetStringObj(nullPtr, "", -1);
if( cnames )
Tcl_ObjSetVar2(interp, objv[5], NULL, nullPtr, TCL_PARSE_PART1);
if( cerrs )
Tcl_ObjSetVar2(interp, objv[6], NULL, nullPtr, TCL_PARSE_PART1);
}
/* free up space */
for(i=0; i<got; i++){
if( cnames[i] ) xfree((char *)cnames[i]);
if( cerrs[i] ) xfree((char *)cerrs[i]);
}
if( cnames ) xfree((char *)cnames);
if( cerrs ) xfree((char *)cerrs);
if( namesObjv ) xfree((char *)namesObjv);
if( errsObjv ) xfree((char *)errsObjv);
/* return the number of accesses as the tcl function result */
Tcl_SetIntObj(resultPtr, got);
/* return status */
return(TCL_OK);
}
/*
*----------------------------------------------------------------------------
*
* Routine: XPANSLookup_Tcl
*
* Purpose: Tcl binding to XPANSLookup procedure
*
* Tcl call:
*
* set got [xpanslookup template type]
*
* Returns: Tcl error code
*
*----------------------------------------------------------------------------
*/
#ifdef ANSI_FUNC
static int
XPANSLookup_Tcl(ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
#else
static int XPANSLookup_Tcl(clientData, interp, objc, objv)
ClientData clientData;
Tcl_Interp *interp;
int objc;
Tcl_Obj *CONST objv[];
#endif
{
XPA xpa;
int i;
int got;
char *xpastr;
char *tmpl;
char *ttype;
char **xclasses;
char **names;
char **methods;
char **infos;
Tcl_Obj *resultPtr;
Tcl_Obj *nullPtr;
Tcl_Obj *classesPtr;
Tcl_Obj *namesPtr;
Tcl_Obj *methodsPtr;
Tcl_Obj *infosPtr;
Tcl_Obj **classesObjv;
Tcl_Obj **namesObjv;
Tcl_Obj **methodsObjv;
Tcl_Obj **infosObjv;
/* make sure argument count is correct */
if( objc != 7 ){
Tcl_WrongNumArgs(interp, 1, objv,
"template type classes names methods infos");
return(TCL_ERROR);
}
/* get result pointer */
resultPtr = Tcl_GetObjResult(interp);
/* get other args */
tmpl = Tcl_GetStringFromObj(objv[1], NULL);
ttype = Tcl_GetStringFromObj(objv[2], NULL);
/* reset before we make C call */
Tcl_ResetResult(interp);
/* get xpa struct pointer, which might be NULL */
xpastr = Tcl_GetStringFromObj(objv[1], NULL);
if( TCL_NULLSTR(xpastr) )
xpa = NULL;
else{
/* get xpa, which is always arg 1 */
if( Tcl_GetXPAFromObj(interp, objv[1], TY_CLIENT, &xpa) != TCL_OK){
Tcl_SetStringObj(resultPtr, "XPA$ERROR: invalid xpa client handle", -1);
return(TCL_ERROR);
}
}
/* make the XPA C call */
got = XPANSLookup(xpa, tmpl, ttype, &xclasses, &names, &methods, &infos);
/* if we got anything, fill in the blanks */
if( got > 0 ){
/* allocate just enough pointers */
classesObjv = (Tcl_Obj **)xcalloc(got, sizeof(Tcl_Obj *));
namesObjv = (Tcl_Obj **)xcalloc(got, sizeof(Tcl_Obj *));
methodsObjv = (Tcl_Obj **)xcalloc(got, sizeof(Tcl_Obj *));
infosObjv = (Tcl_Obj **)xcalloc(got, sizeof(Tcl_Obj *));
/* generate a Tcl object for each return argument */
for(i=0; i<got; i++){
classesObjv[i] = Tcl_NewObj();
Tcl_SetStringObj(classesObjv[i], xclasses[i], strlen(xclasses[i]));
namesObjv[i] = Tcl_NewObj();
Tcl_SetStringObj(namesObjv[i], names[i], strlen(names[i]));
methodsObjv[i] = Tcl_NewObj();
Tcl_SetStringObj(methodsObjv[i], methods[i], strlen(methods[i]));
infosObjv[i] = Tcl_NewObj();
Tcl_SetStringObj(infosObjv[i], infos[i], strlen(infos[i]));
}
/* make lists from the return arguments and set the return variables */
classesPtr = Tcl_NewObj();
Tcl_SetListObj(classesPtr, got, classesObjv);
Tcl_ObjSetVar2(interp, objv[3], NULL, classesPtr, TCL_PARSE_PART1);
namesPtr = Tcl_NewObj();
Tcl_SetListObj(namesPtr, got, namesObjv);
Tcl_ObjSetVar2(interp, objv[4], NULL, namesPtr, TCL_PARSE_PART1);
methodsPtr = Tcl_NewObj();
Tcl_SetListObj(methodsPtr, got, methodsObjv);
Tcl_ObjSetVar2(interp, objv[5], NULL, methodsPtr, TCL_PARSE_PART1);
infosPtr = Tcl_NewObj();
Tcl_SetListObj(infosPtr, got, infosObjv);
Tcl_ObjSetVar2(interp, objv[5], NULL, infosPtr, TCL_PARSE_PART1);
/* free up the space */
for(i=0; i<got; i++){
/* done with these strings */
xfree(xclasses[i]);
xfree(names[i]);
xfree(methods[i]);
xfree(infos[i]);
}
/* free up arrays alloc'ed by name server */
if( got > 0 ){
xfree(xclasses);
xfree(names);
xfree(methods);
xfree(infos);
xfree(classesObjv);
xfree(namesObjv);
xfree(methodsObjv);
xfree(infosObjv);
}
}
else{
nullPtr = Tcl_NewObj();
Tcl_SetStringObj(nullPtr, "", -1);
Tcl_ObjSetVar2(interp, objv[3], NULL, nullPtr, TCL_PARSE_PART1);
Tcl_ObjSetVar2(interp, objv[4], NULL, nullPtr, TCL_PARSE_PART1);
Tcl_ObjSetVar2(interp, objv[5], NULL, nullPtr, TCL_PARSE_PART1);
Tcl_ObjSetVar2(interp, objv[6], NULL, nullPtr, TCL_PARSE_PART1);
}
/* return the number of accesses as the tcl function result */
Tcl_SetIntObj(resultPtr, got);
/* return status */
return(TCL_OK);
}
/*
*----------------------------------------------------------------------------
*
* Routine: XPANSKeepAlive_Tcl
*
* Purpose: Tcl binding to XPANSKeepAlive procedure
*
* Tcl call:
*
* xpafree xpa
*
* Returns: Tcl error code
*
*----------------------------------------------------------------------------
*/
#ifdef ANSI_FUNC
static int
XPANSKeepAlive_Tcl(ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
#else
static int XPANSKeepAlive_Tcl(clientData, interp, objc, objv)
ClientData clientData;
Tcl_Interp *interp;
int objc;
Tcl_Obj *CONST objv[];
#endif
{
XPA xpa;
int type=0;
char *s=NULL;
/* make sure argument count is correct */
if( objc < 2 ){
Tcl_WrongNumArgs(interp, 1, objv, "xpa [type]");
return(TCL_ERROR);
}
/* get xpa, which is always arg 1 */
if( Tcl_GetXPAFromObj(interp, objv[1], TY_SERVER, &xpa) != TCL_OK){
return(TCL_ERROR);
}
/* optional type, usually not specified for default */
if( (objc >= 3) && (s = Tcl_GetStringFromObj(objv[2], NULL)) != NULL )
type = atoi(s);
/* reset error/result condition */
Tcl_ResetResult(interp);
/* call the XPANSKeepAlive routine */
XPANSKeepAlive(xpa, type);
return(TCL_OK);
}
/*
*----------------------------------------------------------------------------
*
* Routine: XPARemote_Tcl
*
* Purpose: Tcl binding to XPARemote procedure
*
* Tcl call:
*
* xpaRemote xpa host acl
*
* use the empty string to specify NULL arguments
*
* Returns: Tcl error code
*
*----------------------------------------------------------------------------
*/
#ifdef ANSI_FUNC
static int
XPARemote_Tcl(ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
#else
static int XPARemote_Tcl(clientData, interp, objc, objv)
ClientData clientData;
Tcl_Interp *interp;
int objc;
Tcl_Obj *CONST objv[];
#endif
{
int got;
char *host;
char *acl="+";
char *s;
char *mode=NULL;
char tbuf[SZ_LINE];
XPA xpa;
Tcl_Obj *resultPtr;
/* make sure argument count is correct */
if( (objc < 3) || (objc > 5) ){
Tcl_WrongNumArgs(interp, 1, objv, "xpa host [acl] [-proxy]");
return(TCL_ERROR);
}
/* get result pointer */
resultPtr = Tcl_GetObjResult(interp);
/* get xpa, which is always arg 1 */
if( Tcl_GetXPAFromObj(interp, objv[1], TY_SERVER, &xpa) != TCL_OK){
return(TCL_ERROR);
}
/* make sure we are using inet sockets */
if( XPAMtype() != XPA_INET ){
snprintf(tbuf, SZ_LINE, "remote requires that XPA_METHOD be 'inet'\n");
Tcl_SetStringObj(resultPtr, tbuf, -1);
return(TCL_ERROR);
}
/* get required host */
host = Tcl_GetStringFromObj(objv[2], NULL);
/* get optional acl */
if( objc >= 4 ){
s = Tcl_GetStringFromObj(objv[3], NULL);
if( !strcmp(s, "-proxy") ){
mode="proxy=true";
}
else{
acl = s;
}
}
/* get optional -proxy switch */
if( objc == 5 ){
s = Tcl_GetStringFromObj(objv[4], NULL);
if( !strcmp(s, "-proxy") ){
mode="proxy=true";
}
else if( mode ){
acl = s;
}
else{
snprintf(tbuf, SZ_LINE,
"XPA$ERROR: invalid arg (%s): xpa -remote host [acl] [-proxy]\n",
s);
Tcl_SetStringObj(resultPtr, tbuf, -1);
return(TCL_ERROR);
}
}
/* reset error/result condition */
Tcl_ResetResult(interp);
/* set up the tcl handler for the xpa access point */
got = XPARemote(xpa, host, acl, mode);
if( got >= 0 ){
return(TCL_OK);
}
else{
snprintf(tbuf, SZ_LINE,
"XPA$ERROR: remote xpans %s failed to process %s\n",
host, xpa->name);
Tcl_SetStringObj(resultPtr, tbuf, -1);
return(TCL_ERROR);
}
}
/*
*----------------------------------------------------------------------------
*
* Routine: XPAError_Tcl
*
* Purpose: Tcl binding to XPAError procedure
*
* Tcl call:
*
* xpaerror xpa errmess
*
* Returns: Tcl error code
*
*----------------------------------------------------------------------------
*/
#ifdef ANSI_FUNC
static int
XPAError_Tcl(ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
#else
static int XPAError_Tcl(clientData, interp, objc, objv)
ClientData clientData;
Tcl_Interp *interp;
int objc;
Tcl_Obj *CONST objv[];
#endif
{
char *message;
XPA xpa;
/* make sure argument count is correct */
if( objc != 3 ){
Tcl_WrongNumArgs(interp, 1, objv, "xpa message");
return(TCL_ERROR);
}
/* get xpa, which is always arg 1 */
if( Tcl_GetXPAFromObj(interp, objv[1], TY_SERVER, &xpa) != TCL_OK){
return(TCL_ERROR);
}
/* get message string */
message = Tcl_GetStringFromObj(objv[2], NULL);
/* reset error/result condition */
Tcl_ResetResult(interp);
/* call the XPAError routine */
XPAError(xpa, message);
/* no error message (too lazy) */
return(TCL_OK);
}
/*
*----------------------------------------------------------------------------
*
* Routine: XPAMessage_Tcl
*
* Purpose: Tcl binding to XPAMessage procedure
*
* Tcl call:
*
* xpamessage xpa errmess
*
* Returns: Tcl error code
*
*----------------------------------------------------------------------------
*/
#ifdef ANSI_FUNC
static int
XPAMessage_Tcl(ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
#else
static int XPAMessage_Tcl(clientData, interp, objc, objv)
ClientData clientData;
Tcl_Interp *interp;
int objc;
Tcl_Obj *CONST objv[];
#endif
{
char *message;
XPA xpa;
/* make sure argument count is correct */
if( objc != 3 ){
Tcl_WrongNumArgs(interp, 1, objv, "xpa message");
return(TCL_ERROR);
}
/* get xpa, which is always arg 1 */
if( Tcl_GetXPAFromObj(interp, objv[1], TY_SERVER, &xpa) != TCL_OK){
return(TCL_ERROR);
}
/* get message string */
message = Tcl_GetStringFromObj(objv[2], NULL);
/* reset error/result condition */
Tcl_ResetResult(interp);
/* call the XPAMessage routine */
XPAMessage(xpa, message);
/* no error message (too lazy) */
return(TCL_OK);
}
/*
*----------------------------------------------------------------------------
*
*
* Public Routines and Data
*
*
*----------------------------------------------------------------------------
*/
/*
*----------------------------------------------------------------------------
*
* Routine: Xpa_Init
*
* Purpose: initialize Tcl xpa package
*
* Returns: tcl return code
*
*----------------------------------------------------------------------------
*/
#ifdef ANSI_FUNC
int
Tclxpa_Init (void *vinterp)
#else
int Tclxpa_Init (vinterp)
void *vinterp;
#endif
{
Tcl_Interp *interp = (Tcl_Interp *)vinterp;
if(
#ifdef USE_TCL_STUBS
Tcl_InitStubs(interp, "8.4", 0)
#else
Tcl_PkgRequire(interp, "Tcl", "8.4", 0)
#endif
== NULL) {
return TCL_ERROR;
}
/* add xpa commands to this interpreter */
Tcl_CreateObjCommand(interp, "xpanew", XPANew_Tcl,
(ClientData)NULL, (Tcl_CmdDeleteProc *)NULL);
Tcl_CreateObjCommand(interp, "xpafree", XPAFree_Tcl,
(ClientData)NULL, (Tcl_CmdDeleteProc *)NULL);
Tcl_CreateObjCommand(interp, "xpainfonew", XPAInfoNew_Tcl,
(ClientData)NULL, (Tcl_CmdDeleteProc *)NULL);
Tcl_CreateObjCommand(interp, "xpacmdnew", XPACmdNew_Tcl,
(ClientData)NULL, (Tcl_CmdDeleteProc *)NULL);
Tcl_CreateObjCommand(interp, "xpacmddel", XPACmdDel_Tcl,
(ClientData)NULL, (Tcl_CmdDeleteProc *)NULL);
Tcl_CreateObjCommand(interp, "xpacmdadd", XPACmdAdd_Tcl,
(ClientData)NULL, (Tcl_CmdDeleteProc *)NULL);
Tcl_CreateObjCommand(interp, "xparec", XPARec_Tcl,
(ClientData)NULL, (Tcl_CmdDeleteProc *)NULL);
Tcl_CreateObjCommand(interp, "xpasetbuf", XPASetBuf_Tcl,
(ClientData)NULL, (Tcl_CmdDeleteProc *)NULL);
Tcl_CreateObjCommand(interp, "xpaopen", XPAOpen_Tcl,
(ClientData)NULL, (Tcl_CmdDeleteProc *)NULL);
Tcl_CreateObjCommand(interp, "xpaclose", XPAClose_Tcl,
(ClientData)NULL, (Tcl_CmdDeleteProc *)NULL);
Tcl_CreateObjCommand(interp, "xpaget", XPAGet_Tcl,
(ClientData)NULL, (Tcl_CmdDeleteProc *)NULL);
Tcl_CreateObjCommand(interp, "xpagetfd", XPAGetFd_Tcl,
(ClientData)NULL, (Tcl_CmdDeleteProc *)NULL);
Tcl_CreateObjCommand(interp, "xpaset", XPASet_Tcl,
(ClientData)NULL, (Tcl_CmdDeleteProc *)NULL);
Tcl_CreateObjCommand(interp, "xpasetfd", XPASetFd_Tcl,
(ClientData)NULL, (Tcl_CmdDeleteProc *)NULL);
Tcl_CreateObjCommand(interp, "xpainfo", XPAInfo_Tcl,
(ClientData)NULL, (Tcl_CmdDeleteProc *)NULL);
Tcl_CreateObjCommand(interp, "xpaaccess", XPAAccess_Tcl,
(ClientData)NULL, (Tcl_CmdDeleteProc *)NULL);
Tcl_CreateObjCommand(interp, "xpanslookup", XPANSLookup_Tcl,
(ClientData)NULL, (Tcl_CmdDeleteProc *)NULL);
Tcl_CreateObjCommand(interp, "xpanskeepalive", XPANSKeepAlive_Tcl,
(ClientData)NULL, (Tcl_CmdDeleteProc *)NULL);
Tcl_CreateObjCommand(interp, "xparemote", XPARemote_Tcl,
(ClientData)NULL, (Tcl_CmdDeleteProc *)NULL);
Tcl_CreateObjCommand(interp, "xpaerror", XPAError_Tcl,
(ClientData)NULL, (Tcl_CmdDeleteProc *)NULL);
Tcl_CreateObjCommand(interp, "xpamessage", XPAMessage_Tcl,
(ClientData)NULL, (Tcl_CmdDeleteProc *)NULL);
Tcl_PkgProvide(interp, "tclxpa", "2.1");
return(TCL_OK);
}
/* required for tclkit 8.6 */
int Tclxpa_Unload() { return TCL_ERROR; }
int Tclxpa_SafeUnload() { return TCL_ERROR; }
int Tclxpa_SafeInit() { return TCL_ERROR; }
int xpa_tclbinding = 1;
#else
int xpa_tclbinding = 0;
#endif
|