/usr/share/doc/libice-dev/ICElib.html is in libice-doc 2:1.0.9-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Inter-Client Exchange Library</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1" /><style xmlns="" type="text/css">/*
* Copyright (c) 2011 Gaetan Nadon
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
*
* 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 (including the next
* paragraph) 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 AUTHORS OR 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.
*/
/*
* Shared stylesheet for X.Org documentation translated to HTML format
* http://www.sagehill.net/docbookxsl/UsingCSS.html
* http://www.w3schools.com/css/default.asp
* https://addons.mozilla.org/en-US/firefox/addon/web-developer/developers
* https://addons.mozilla.org/en-US/firefox/addon/font-finder/
*/
/*
* The sans-serif fonts are considered more legible on a computer screen
* http://dry.sailingissues.com/linux-equivalents-verdana-arial.html
*
*/
body {
font-family: "Bitstream Vera Sans", "DejaVu Sans", Tahoma, Geneva, Arial, Sans-serif;
/* In support of using "em" font size unit, the w3c recommended method */
font-size: 100%;
}
/*
* Selection: all elements requiring mono spaced fonts.
*
* The family names attempt to match the proportionally spaced font
* family names such that the same font name is used for both.
* We'd like to use Bitstream, for example, in both proportionally and
* mono spaced font text.
*/
.command,
.errorcode,
.errorname,
.errortype,
.filename,
.funcsynopsis,
.function,
.parameter,
.programlisting,
.property,
.screen,
.structname,
.symbol,
.synopsis,
.type
{
font-family: "Bitstream Vera Sans Mono", "DejaVu Sans Mono", Courier, "Liberation Mono", Monospace;
}
/*
* Books have a title page, a preface, some chapters and appendices,
* a glossary, an index and a bibliography, in that order.
*
* An Article has no preface and no chapters. It has sections, appendices,
* a glossary, an index and a bibliography.
*/
/*
* Selection: book main title and subtitle
*/
div.book>div.titlepage h1.title,
div.book>div.titlepage h2.subtitle {
text-align: center;
}
/*
* Selection: article main title and subtitle
*/
div.article>div.titlepage h2.title,
div.article>div.titlepage h3.subtitle,
div.article>div.sect1>div.titlepage h2.title,
div.article>div.section>div.titlepage h2.title {
text-align: center;
}
/*
* Selection: various types of authors and collaborators, individuals or corporate
*
* These authors are not always contained inside an authorgroup.
* They can be contained inside a lot of different parent types where they might
* not be centered.
* Reducing the margin at the bottom makes a visual separation between authors
* We specify here the ones on the title page, others may be added based on merit.
*/
div.titlepage .authorgroup,
div.titlepage .author,
div.titlepage .collab,
div.titlepage .corpauthor,
div.titlepage .corpcredit,
div.titlepage .editor,
div.titlepage .othercredit {
text-align: center;
margin-bottom: 0.25em;
}
/*
* Selection: the affiliation of various types of authors and collaborators,
* individuals or corporate.
*/
div.titlepage .affiliation {
text-align: center;
}
/*
* Selection: product release information (X Version 11, Release 7)
*
* The releaseinfo element can be contained inside a lot of different parent
* types where it might not be centered.
* We specify here the one on the title page, others may be added based on merit.
*/
div.titlepage p.releaseinfo {
font-weight: bold;
text-align: center;
}
/*
* Selection: publishing date
*/
div.titlepage .pubdate {
text-align: center;
}
/*
* The legal notices are displayed in smaller sized fonts
* Justification is only supported in IE and therefore not requested.
*
*/
.legalnotice {
font-size: small;
font-style: italic;
}
/*
* For documentation having multiple licenses, the copyright and legalnotice
* elements sequence cannot instantiated multiple times.
* The copyright notice and license text are therefore coded inside a legalnotice
* element. The role attribute on the paragraph is used to allow styling of the
* copyright notice text which should not be italicized.
*/
p.multiLicensing {
font-style: normal;
font-size: medium;
}
/*
* Selection: book or article main ToC title
* A paragraph is generated for the title rather than a level 2 heading.
* We do not want to select chapters sub table of contents, only the main one
*/
div.book>div.toc>p,
div.article>div.toc>p {
font-size: 1.5em;
text-align: center;
}
/*
* Selection: major sections of a book or an article
*
* Unlike books, articles do not have a titlepage element for appendix.
* Using the selector "div.titlepage h2.title" would be too general.
*/
div.book>div.preface>div.titlepage h2.title,
div.book>div.chapter>div.titlepage h2.title,
div.article>div.sect1>div.titlepage h2.title,
div.article>div.section>div.titlepage h2.title,
div.book>div.appendix>div.titlepage h2.title,
div.article>div.appendix h2.title,
div.glossary>div.titlepage h2.title,
div.index>div.titlepage h2.title,
div.bibliography>div.titlepage h2.title {
/* Add a border top over the major parts, just like printed books */
/* The Gray color is already used for the ruler over the main ToC. */
border-top-style: solid;
border-top-width: 2px;
border-top-color: Gray;
/* Put some space between the border and the title */
padding-top: 0.2em;
text-align: center;
}
/*
* A Screen is a verbatim environment for displaying text that the user might
* see on a computer terminal. It is often used to display the results of a command.
*
* http://www.css3.info/preview/rounded-border/
*/
.screen {
background: #e0ffff;
border-width: 1px;
border-style: solid;
border-color: #B0C4DE;
border-radius: 1.0em;
/* Browser's vendor properties prior to CSS 3 */
-moz-border-radius: 1.0em;
-webkit-border-radius: 1.0em;
-khtml-border-radius: 1.0em;
margin-left: 1.0em;
margin-right: 1.0em;
padding: 0.5em;
}
/*
* Emphasis program listings with a light shade of gray similar to what
* DocBook XSL guide does: http://www.sagehill.net/docbookxsl/ProgramListings.html
* Found many C API docs on the web using like shades of gray.
*/
.programlisting {
background: #F4F4F4;
border-width: 1px;
border-style: solid;
border-color: Gray;
padding: 0.5em;
}
/*
* Emphasis functions synopsis using a darker shade of gray.
* Add a border such that it stands out more.
* Set the padding so the text does not touch the border.
*/
.funcsynopsis, .synopsis {
background: #e6e6fa;
border-width: 1px;
border-style: solid;
border-color: Gray;
clear: both;
margin: 0.5em;
padding: 0.25em;
}
/*
* Selection: paragraphs inside synopsis
*
* Removes the default browser margin, let the container set the padding.
* Paragraphs are not always used in synopsis
*/
.funcsynopsis p,
.synopsis p {
margin: 0;
padding: 0;
}
/*
* Selection: variable lists, informal tables and tables
*
* Note the parameter name "variablelist.as.table" in xorg-xhtml.xsl
* A table with rows and columns is constructed inside div.variablelist
*
* Set the left margin so it is indented to the right
* Display informal tables with single line borders
*/
table {
margin-left: 0.5em;
border-collapse: collapse;
}
/*
* Selection: paragraphs inside tables
*
* Removes the default browser margin, let the container set the padding.
* Paragraphs are not always used in tables
*/
td p {
margin: 0;
padding: 0;
}
/*
* Add some space between the left and right column.
* The vertical alignment helps the reader associate a term
* with a multi-line definition.
*/
td, th {
padding-left: 1.0em;
padding-right: 1.0em;
vertical-align: top;
}
.warning {
border: 1px solid red;
background: #FFFF66;
padding-left: 0.5em;
}
</style></head><body><div class="book"><div class="titlepage"><div><div><h1 class="title"><a id="ICElib"></a>Inter-Client Exchange Library</h1></div><div><h2 class="subtitle">X Consortium Standard</h2></div><div><div class="authorgroup"><div class="author"><h3 class="author"><span class="firstname">Ralph</span> <span class="surname">Mor</span></h3><div class="affiliation"><span class="orgname">X Consortium<br /></span></div></div></div></div><div><p class="releaseinfo">X Version 11, Release 7.7</p></div><div><p class="releaseinfo">Version 1.0</p></div><div><p class="copyright">Copyright © 1993, 1994, 1996 X Consortium</p></div><div><div class="legalnotice"><a id="idp54451440"></a><p>
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:
</p><p>The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
</p><p>
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
X CONSORTIUM 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.
</p><p>
Except as contained in this notice, the name of the X Consortium shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from the X Consortium.
</p></div></div></div><hr /></div><div class="toc"><p><strong>Table of Contents</strong></p><dl class="toc"><dt><span class="chapter"><a href="#Overview_of_ICE">1. Overview of ICE</a></span></dt><dt><span class="chapter"><a href="#The_ICE_Library___C_Language_Interface_to_ICE">2. The ICE Library - C Language Interface to ICE</a></span></dt><dt><span class="chapter"><a href="#Intended_Audience">3. Intended Audience</a></span></dt><dt><span class="chapter"><a href="#Header_Files_and_Library_Name">4. Header Files and Library Name</a></span></dt><dt><span class="chapter"><a href="#Note_on_Prefixes">5. Note on Prefixes</a></span></dt><dt><span class="chapter"><a href="#Protocol_Registration">6. Protocol Registration</a></span></dt><dd><dl><dt><span class="sect1"><a href="#Callbacks_for_Processing_Messages">Callbacks for Processing Messages</a></span></dt><dt><span class="sect1"><a href="#Authentication_Methods">Authentication Methods</a></span></dt></dl></dd><dt><span class="chapter"><a href="#ICE_Connections">7. ICE Connections</a></span></dt><dd><dl><dt><span class="sect1"><a href="#Opening_an_ICE_Connection">Opening an ICE Connection</a></span></dt><dt><span class="sect1"><a href="#Listening_for_ICE_Connections">Listening for ICE Connections</a></span></dt><dt><span class="sect1"><a href="#Host_Based_Authentication_for_ICE_Connections">Host Based Authentication for ICE Connections</a></span></dt><dt><span class="sect1"><a href="#Accepting_ICE_Connections">Accepting ICE Connections</a></span></dt><dt><span class="sect1"><a href="#Closing_ICE_Connections">Closing ICE Connections</a></span></dt><dt><span class="sect1"><a href="#Connection_Watch_Procedures">Connection Watch Procedures</a></span></dt></dl></dd><dt><span class="chapter"><a href="#Protocol_Setup_and_Shutdown">8. Protocol Setup and Shutdown</a></span></dt><dt><span class="chapter"><a href="#Processing_Messages">9. Processing Messages</a></span></dt><dt><span class="chapter"><a href="#Ping">10. Ping</a></span></dt><dt><span class="chapter"><a href="#Using_ICElib_Informational_Functions">11. Using ICElib Informational Functions</a></span></dt><dt><span class="chapter"><a href="#ICE_Messages">12. ICE Messages</a></span></dt><dd><dl><dt><span class="sect1"><a href="#Sending_ICE_Messages">Sending ICE Messages</a></span></dt><dt><span class="sect1"><a href="#Reading_ICE_Messages">Reading ICE Messages</a></span></dt></dl></dd><dt><span class="chapter"><a href="#Error_Handling">13. Error Handling</a></span></dt><dt><span class="chapter"><a href="#Multi_Threading_Support">14. Multi-Threading Support</a></span></dt><dt><span class="chapter"><a href="#Miscellaneous_Functions">15. Miscellaneous Functions</a></span></dt><dt><span class="chapter"><a href="#Acknowledgements">16. Acknowledgements</a></span></dt><dt><span class="appendix"><a href="#authentication_utility_functions">A. Authentication Utility Functions</a></span></dt><dt><span class="appendix"><a href="#mit_magic_cookie_1_authentication">B. MIT-MAGIC-COOKIE-1 Authentication</a></span></dt></dl></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a id="Overview_of_ICE"></a>Chapter 1. Overview of ICE</h1></div></div></div><p>
There are numerous possible inter-client protocols, with many similarities
and common needs - authentication, version negotiation, byte
order negotiation, and so on.
The Inter-Client Exchange (ICE) protocol is intended to provide a framework
for building such protocols, allowing them to make use of common negotiation
mechanisms and to be multiplexed over a single transport connection.
</p></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a id="The_ICE_Library___C_Language_Interface_to_ICE"></a>Chapter 2. The ICE Library - C Language Interface to ICE</h1></div></div></div><p>
A client that wishes to utilize ICE must first register the protocols it
understands with the ICE library. Each protocol is dynamically assigned
a major opcode ranging from 1-255 (two clients can use different
major opcodes for the same protocol). The next step for the client is either
to open a connection with another client or to wait for connections made
by other clients. Authentication may be required. A client can both
initiate connections with other clients and be
waiting for clients to connect to itself (a nested session manager is an
example). Once an ICE connection is established between the two clients, one
of the clients needs to initiate a
<code class="function">ProtocolSetup</code>
in order to
"activate" a given protocol. Once the other client accepts the
<code class="function">ProtocolSetup</code>
(once again, authentication may be required), the
two clients are ready to start passing messages specific to that protocol to
each other. Multiple protocols may be active on a single ICE connection.
Clients are responsible for notifying the ICE library when a protocol is no
longer active on an ICE connection, although ICE does not define how each
subprotocol triggers a protocol shutdown.
</p><p>
The ICE library utilizes callbacks to process incoming messages. Using
callbacks allows
<code class="function">ProtocolSetup</code>
messages and authentication to happen
behind the scenes. An additional benefit is that messages never need
to be buffered up by the library when the client blocks waiting for a
particular message.
</p></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a id="Intended_Audience"></a>Chapter 3. Intended Audience</h1></div></div></div><p>This document is intended primarily for implementors of protocol libraries
layered on top of ICE. Typically, applications that wish to utilize ICE
will make calls into individual protocol libraries rather than directly
make calls into the ICE library. However, some applications will have to
make some initial calls into the ICE library in order to accept ICE
connections (for example, a session manager accepting connections from
clients). But in general, protocol libraries should be designed to hide
the inner details of ICE from applications.</p></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a id="Header_Files_and_Library_Name"></a>Chapter 4. Header Files and Library Name</h1></div></div></div><p>The header file
<<span class="symbol">X11/ICE/ICElib.h</span>>
defines all of the ICElib data structures and function prototypes.
<code class="function">ICElib.h</code>
includes the header file
<<span class="symbol">X11/ICE/ICE.h</span>>,
which defines all of the ICElib constants.
Protocol libraries that need to read and write messages should include
the header file
<<span class="symbol">X11/ICE/ICEmsg.h</span>>.</p><p>Applications should link against ICElib using -lICE.</p></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a id="Note_on_Prefixes"></a>Chapter 5. Note on Prefixes</h1></div></div></div><p>The following name prefixes are used in the library to distinguish between
a client that initiates a
<code class="function">ProtocolSetup</code>
and a client that
responds with a
<code class="function">ProtocolReply</code></p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p><code class="function">IcePo</code>
- Ice Protocol Originator</p></li><li class="listitem"><p><code class="function">IcePa</code>
- Ice Protocol Acceptor</p></li></ul></div></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a id="Protocol_Registration"></a>Chapter 6. Protocol Registration</h1></div></div></div><div class="toc"><p><strong>Table of Contents</strong></p><dl class="toc"><dt><span class="sect1"><a href="#Callbacks_for_Processing_Messages">Callbacks for Processing Messages</a></span></dt><dt><span class="sect1"><a href="#Authentication_Methods">Authentication Methods</a></span></dt></dl></div><p>
In order for two clients to exchange messages for a given protocol, each
side must register the protocol with the ICE library. The purpose of
registration is for each side to obtain a major opcode for the protocol
and to provide callbacks for processing messages and handling authentication.
There are two separate registration functions:
</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
One to handle the side that does a
<code class="function">ProtocolSetup</code>
</p></li><li class="listitem"><p>
One to handle the side that responds with a
<code class="function">ProtocolReply</code>
</p></li></ul></div><p>
It is recommended that protocol registration occur before the two clients
establish an ICE connection. If protocol registration occurs after an
ICE connection is created, there can be a brief interval of time in which a
<code class="function">ProtocolSetup</code>
is received, but the protocol is not registered.
If it is not possible to register a protocol before the creation of an
ICE connection, proper precautions should be taken to avoid the above race
condition.
</p><p>
The <a class="xref" href="#IceRegisterForProtocolSetup"><code class="function">IceRegisterForProtocolSetup</code></a>
function should be called for the client that initiates a
<code class="function">ProtocolSetup</code>
</p><div class="funcsynopsis"><a id="IceRegisterForProtocolSetup"></a><p><code class="funcdef">int <strong class="fsfunc">IceRegisterForProtocolSetup</strong>(</code>const char<var class="pdparam"> *protocol_name</var>, const char<var class="pdparam"> *vendor</var>, const char<var class="pdparam"> *release</var>, int<var class="pdparam"> version_count</var>, IcePoVersionRec<var class="pdparam"> *version_recs</var>, int<var class="pdparam"> auth_count</var>, char<var class="pdparam"> **auth_names</var>, IcePoAuthProc<var class="pdparam"> *auth_procs</var>, IceIOErrorProc<var class="pdparam"> io_error_proc</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>protocol_name</em></span></span></p></td><td><p>
A string specifying the name of the protocol to register.
</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>vendor</em></span></span></p></td><td><p>A vendor string with semantics specified by the protocol.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>release</em></span></span></p></td><td><p>A release string with semantics specified by the protocol.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>version_count</em></span></span></p></td><td><p>The number of different versions of the protocol supported.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>version_recs</em></span></span></p></td><td><p>List of versions and associated callbacks.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>auth_count</em></span></span></p></td><td><p>The number of authentication methods supported.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>auth_names</em></span></span></p></td><td><p>The list of authentication methods supported.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>auth_procs</em></span></span></p></td><td><p>
The list of authentication callbacks, one for each authentication method.
</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>io_error_proc</em></span></span></p></td><td><p>IO error handler, or NULL.</p></td></tr></tbody></table></div><p>
<a class="xref" href="#IceRegisterForProtocolSetup"><code class="function">IceRegisterForProtocolSetup</code></a> returns the major
opcode reserved or -1 if an error occurred. In order to actually activate
the protocol, the <a class="xref" href="#IceProtocolSetup"><code class="function">IceProtocolSetup</code></a>
function needs to be called with this major opcode. Once the protocol is
activated, all messages for the protocol should be sent using this major
opcode.
</p><p>
A protocol library may support multiple versions of the same protocol.
The version_recs argument specifies a list of supported versions of the
protocol, which are prioritized in decreasing order of preference.
Each version record consists of a major and minor version of the protocol
as well as a callback to be used for processing incoming messages.
</p><div class="literallayout"><p><br />
typedef struct {<br />
int major_version;<br />
int minor_version;<br />
IcePoProcessMsgProc process_msg_proc;<br />
} IcePoVersionRec;<br />
</p></div><p>The
<code class="function">IcePoProcessMsgProc</code>
callback is responsible for processing the set of messages that can be
received by the client that initiated the
<code class="function">ProtocolSetup</code>
For further information,
see
<a class="xref" href="#Callbacks_for_Processing_Messages" title="Callbacks for Processing Messages">Callbacks for Processing Messages</a>
</p><p>Authentication may be required before the protocol can become active.
The protocol library must register the authentication methods that it
supports with the ICE library.
The auth_names and auth_procs arguments are a list of authentication names
and callbacks that are prioritized in decreasing order of preference.
For information on the
<code class="function">IcePoAuthProc</code>
callback, see
<a class="xref" href="#Authentication_Methods" title="Authentication Methods">Authentication Methods</a>
</p><p>The
<a class="xref" href="#IceIOErrorProc"><code class="function"> IceIOErrorProc</code></a>
callback is invoked if the ICE connection unexpectedly breaks.
You should pass NULL for io_error_proc if not interested in being notified.
For further information,
<a class="xref" href="#Error_Handling" title="Chapter 13. Error Handling"><em>Error Handling</em></a>
</p><p>The
<a class="xref" href="#IceRegisterForProtocolReply"><code class="function">IceRegisterForProtocolReply</code></a>
function should be called for the client that responds to a
<code class="function">ProtocolSetup</code>
with a
<code class="function">ProtocolReply</code></p><div class="funcsynopsis"><a id="IceRegisterForProtocolReply"></a><p><code class="funcdef">Bool <strong class="fsfunc">IceRegisterForProtocolReply</strong>(</code>const char<var class="pdparam"> *protocol_name</var>, const char<var class="pdparam"> *vendor</var>, const char<var class="pdparam"> *release</var>, int<var class="pdparam"> version_count</var>, IcePoVersionRec<var class="pdparam"> *version_recs</var>, int<var class="pdparam"> auth_count</var>, const char<var class="pdparam"> **auth_names</var>, IcePoAuthProc<var class="pdparam"> *auth_procs</var>, IceHostBasedAuthProc<var class="pdparam"> host_based_auth_proc</var>, IceProtocolSetupProc<var class="pdparam"> protocol_setup_proc</var>, IceProtocolActivateProc<var class="pdparam"> protocol_activate_proc</var>, IceIOErrorProc<var class="pdparam"> io_error_proc</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>protocol_name</em></span></span></p></td><td><p>A string specifying the name of the protocol to register.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>vendor</em></span></span></p></td><td><p>A vendor string with semantics specified by the protocol.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>release</em></span></span></p></td><td><p>A release string with semantics specified by the protocol.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>version_count</em></span></span></p></td><td><p>The number of different versions of the protocol supported.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>version_recs</em></span></span></p></td><td><p>List of versions and associated callbacks.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>auth_count</em></span></span></p></td><td><p>The number of authentication methods supported.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>auth_names</em></span></span></p></td><td><p>The list of authentication methods supported.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>auth_procs</em></span></span></p></td><td><p>The list of authentication callbacks, one for each authentication method.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>host_based_auth_proc</em></span></span></p></td><td><p>Host based authentication callback.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>protocol_setup_proc</em></span></span></p></td><td><p>A callback to be invoked when authentication has succeeded for a
<code class="function">ProtocolSetup</code>
but before the
<code class="function">ProtocolReply</code>
is sent.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>protocol_activate_proc</em></span></span></p></td><td><p>A callback to be invoked after the
<code class="function">ProtocolReply</code>
is sent.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>io_error_proc</em></span></span></p></td><td><p>IO error handler, or NULL.</p></td></tr></tbody></table></div><p><a class="xref" href="#IceRegisterForProtocolReply"><code class="function">IceRegisterForProtocolReply</code></a>
returns the major opcode reserved or -1 if an error occurred. The major
opcode should be used in all subsequent messages sent for this protocol.</p><p>A protocol library may support multiple versions of the same protocol.
The version_recs argument specifies a list of supported versions of the protocol,
which are prioritized in decreasing order of preference.
Each version record consists of a major and minor version of the protocol
as well as a callback to be used for processing incoming messages.</p><div class="literallayout"><p><br />
typedef struct {<br />
int major_version;<br />
int minor_version;<br />
IcePaProcessMsgProc process_msg_proc;<br />
} IcePaVersionRec;<br />
</p></div><p>The
<a class="xref" href="#IcePaProcessMsgProc"><code class="function">IcePaProcessMsgProc</code></a>
callback is responsible for processing the set of messages that can be
received by the client that accepted the
<code class="function">ProtocolSetup</code>
For further information,
see
<a class="xref" href="#Callbacks_for_Processing_Messages" title="Callbacks for Processing Messages">Callbacks for Processing Messages</a>
</p><p>Authentication may be required before the protocol can become active.
The protocol library must register the authentication methods that it
supports with the ICE library.
The auth_names and auth_procs arguments are a list of authentication names
and callbacks that are prioritized in decreasing order of preference.
For information on the
<code class="function">IcePaAuthProc</code>,
See
<a class="xref" href="#Authentication_Methods" title="Authentication Methods">Authentication Methods</a>
</p><p>If authentication fails and the client attempting to initiate
the
<code class="function">ProtocolSetup</code>
has not required authentication, the
<code class="function">IceHostBasedAuthProc</code>
callback is invoked with the host name of the originating client.
If the callback returns
<code class="function">True</code>
the
<code class="function">ProtocolSetup</code>
will succeed, even though the original
authentication failed.
Note that authentication can effectively be disabled by registering an
<code class="function">IceHostBasedAuthProc</code>
which always returns
<code class="function">True</code>
If no host based
authentication is allowed, you should pass NULL for host_based_auth_proc.</p><div class="funcsynopsis"><p><code class="funcdef">Bool <strong class="fsfunc">HostBasedAuthProc</strong>(</code>char<var class="pdparam"> *host_name</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>protocol_name</em></span></span></p></td><td><p>The host name of the client that sent the <code class="function">ProtocolSetup</code></p></td></tr></tbody></table></div><p>The host_name argument is a string of the form <span class="emphasis"><em>protocol</em></span>/<span class="emphasis"><em>hostname</em></span>,
where <span class="emphasis"><em>protocol</em></span> is one of {tcp, decnet, local}.</p><p>Because
<code class="function">ProtocolSetup</code>
messages and authentication happen behind the scenes
via callbacks, the protocol library needs some way of being notified when the
<code class="function">ProtocolSetup</code>
has completed.
This occurs in two phases.
In the first phase, the
<code class="function">IceProtocolSetupProc</code>
callback is invoked after authentication has
successfully completed but before the ICE library sends a
<code class="function">ProtocolReply</code>
Any resources required for this protocol should be allocated at this time.
If the
<code class="function">IceProtocolSetupProc</code>
returns a successful status, the ICE library will
send the
<code class="function">ProtocolReply</code>
and then invoke the
<code class="function">IceProtocolActivateProc</code>
callback. Otherwise, an error will be sent to the
other client in response to the
<code class="function">ProtocolSetup</code></p><p>The
<code class="function">IceProtocolActivateProc</code>
is an optional callback and should be registered only if the protocol
library intends to generate a message immediately following the
<code class="function">ProtocolReply</code>
You should pass NULL for protocol_activate_proc if not interested
in this callback.</p><div class="funcsynopsis"><a id="ProtocolSetupProc"></a><p><code class="funcdef">Status <strong class="fsfunc">ProtocolSetupProc</strong>(</code>IceConn<var class="pdparam"> ice_conn</var>, int<var class="pdparam"> major_version</var>, int<var class="pdparam"> minor_version</var>, char<var class="pdparam"> *vendor</var>, char<var class="pdparam"> *release</var>, IcePointer<var class="pdparam"> *client_data_ret</var>, char<var class="pdparam"> **failure_reason_ret</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>protocol_name</em></span></span></p></td><td><p>The ICE connection object.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>major_version</em></span></span></p></td><td><p>The major version of the protocol.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>minor_version</em></span></span></p></td><td><p>The minor version of the protocol.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>vendor</em></span></span></p></td><td><p>The vendor string registered by the protocol originator.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>release</em></span></span></p></td><td><p>The release string registered by the protocol originator.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>client_data_ret</em></span></span></p></td><td><p>Client data to be set by callback.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>failure_reason_ret</em></span></span></p></td><td><p>Failure reason returned.</p></td></tr></tbody></table></div><p>The pointer stored in the client_data_ret argument will be passed
to the
<a class="xref" href="#IcePaProcessMsgProc"><code class="function">IcePaProcessMsgProc</code></a>
callback whenever a message has arrived for this protocol on the
ICE connection.</p><p>The vendor and release strings should be freed with
<code class="function">free</code>
when they are no longer needed.</p><p>If a failure occurs, the
<code class="function">IceProtocolSetupProc</code>
should return a zero status as well as allocate and return a failure
reason string in failure_reason_ret.
The ICE library will be responsible for freeing this memory.</p><p>The
<code class="function">IceProtocolActivateProc</code>
callback is defined as follows:</p><div class="funcsynopsis"><a id="ProtocolActivateProc"></a><p><code class="funcdef">void <strong class="fsfunc">ProtocolActivateProc</strong>(</code>IceConn<var class="pdparam"> ice_conn</var>, IcePointer<var class="pdparam"> client_data</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>ice_conn</em></span></span></p></td><td><p>The ICE connection object.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>client_data</em></span></span></p></td><td><p>
The client data set in the <code class="function">IceProtocolSetupProc</code> callback.
</p></td></tr></tbody></table></div><p>The
<a class="xref" href="#IceIOErrorProc"><code class="function"> IceIOErrorProc</code></a>
callback is invoked if the ICE connection unexpectedly breaks.
You should pass NULL for io_error_proc if not interested in being notified.
For further information,
see
<a class="xref" href="#Error_Handling" title="Chapter 13. Error Handling"><em>Error Handling</em></a>
</p><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="Callbacks_for_Processing_Messages"></a>Callbacks for Processing Messages</h2></div></div></div><p>When an application detects that there is new data to read on an ICE
connection (via
<code class="function">select</code>
it calls the
<a class="xref" href="#IceProcessMessages"><code class="function">IceProcessMessages</code></a>
function
<a class="xref" href="#Processing_Messages" title="Chapter 9. Processing Messages"><em>Processing Messages</em></a>
When
<a class="xref" href="#IceProcessMessages"><code class="function">IceProcessMessages</code></a>
reads an ICE message header with a major opcode other than
zero (reserved for the ICE protocol), it needs to call a function that will
read the rest of the message, unpack it, and process it accordingly.</p><p>If the message arrives at the client that initiated the
<code class="function">ProtocolSetup</code>
the
<code class="function">IcePoProcessMsgProc</code>
callback is invoked.</p><div class="funcsynopsis"><a id="PoProcessMsgProc"></a><p><code class="funcdef">void <strong class="fsfunc">PoProcessMsgProc</strong>(</code>IceConn<var class="pdparam"> ice_conn</var>, IcePointer<var class="pdparam"> client_data</var>, int<var class="pdparam"> opcode</var>, unsigned long<var class="pdparam"> length</var>, Bool<var class="pdparam"> swap</var>, IceReplyWaitInfo<var class="pdparam"> *reply_wait</var>, Bool<var class="pdparam"> *reply_ready_ret</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>ice_conn</em></span></span></p></td><td><p>The ICE connection object.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>client_data</em></span></span></p></td><td><p>Client data associated with this protocol on the ICE connection.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>opcode</em></span></span></p></td><td><p>The minor opcode of the message.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>length</em></span></span></p></td><td><p>The length (in 8-byte units) of the message beyond the ICE header.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>swap</em></span></span></p></td><td><p>A flag that indicates if byte swapping is necessary.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>reply_wait</em></span></span></p></td><td><p>Indicates if the invoking client is waiting for a reply.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>reply_ready_ret</em></span></span></p></td><td><p>If set to
<code class="function">True</code>
a reply is ready.</p></td></tr></tbody></table></div><p>If the message arrives at the client that accepted the
<code class="function">ProtocolSetup</code>
the
<a class="xref" href="#IcePaProcessMsgProc"><code class="function">IcePaProcessMsgProc</code></a>
callback is invoked.</p><div class="funcsynopsis"><a id="IcePaProcessMsgProc"></a><p><code class="funcdef">void <strong class="fsfunc">IcePaProcessMsgProc</strong>(</code>IceConn<var class="pdparam"> ice_conn</var>, IcePointer<var class="pdparam"> client_data</var>, int<var class="pdparam"> opcode</var>, unsigned long<var class="pdparam"> length</var>, Bool<var class="pdparam"> swap</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>ice_conn</em></span></span></p></td><td><p>The ICE connection object.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>client_data</em></span></span></p></td><td><p>Client data associated with this protocol on the ICE connection.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>opcode</em></span></span></p></td><td><p>The minor opcode of the message.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>length</em></span></span></p></td><td><p>The length (in 8-byte units) of the message beyond the ICE header.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>swap</em></span></span></p></td><td><p>A flag that indicates if byte swapping is necessary.</p></td></tr></tbody></table></div><p>In order to read the message, both of these callbacks should use the
macros defined for this purpose (see
<a class="xref" href="#Reading_ICE_Messages" title="Reading ICE Messages">Reading ICE Messages</a>.).
Note that byte swapping may be necessary.
As a convenience, the length field in the ICE header will be swapped by ICElib
if necessary.</p><p>In both of these callbacks, the client_data argument is a pointer to client
data that was registered at
<code class="function">ProtocolSetup</code>
time.
In the case of
<code class="function">IcePoProcessMsgProc</code>
the client data was set in the call to
<a class="xref" href="#IceProtocolSetup"><code class="function">IceProtocolSetup</code></a>
In the case of
<a class="xref" href="#IcePaProcessMsgProc"><code class="function">IcePaProcessMsgProc</code></a>
the client data was set in the
<code class="function">IceProtocolSetupProc</code>
callback.</p><p>The
<code class="function">IcePoProcessMsgProc</code>
callback needs to check the reply_wait argument.
If reply_wait is NULL ,
the ICE library expects the function to
pass the message to the client via a callback.
For example, if this is a Session Management "Save Yourself" message,
this function should notify the client of the "Save Yourself" via a callback.
The details of how such a callback would be defined
are implementation-dependent.</p><p>However, if reply_wait is not NULL ,
then the client is waiting for
a reply or an error for a message it previously sent.
The reply_wait is of type
<code class="function">IceReplyWaitInfo</code></p><div class="literallayout"><p><br />
typedef struct {<br />
unsigned long sequence_of_request;<br />
int major_opcode_of_request;<br />
int minor_opcode_of_request;<br />
IcePointer reply;<br />
} IceReplyWaitInfo;<br />
</p></div><p><code class="function">IceReplyWaitInfo</code>
contains the major/minor opcodes and sequence number of
the message for which a reply is being awaited.
It also contains a pointer to the reply message to be filled in
(the protocol library should cast this
<code class="function">IcePointer</code>
to the appropriate reply type).
In most cases, the reply will have some fixed-size part, and the client waiting
for the reply will have provided a pointer to a structure to hold
this fixed-size data. If there is variable-length data, it would be
expected that the
<code class="function">IcePoProcessMsgProc</code>
callback will have to allocate additional
memory and store pointer(s) to that memory in the fixed-size
structure. If the entire data is variable length (for example., a single
variable-length string), then the client waiting for the reply would probably
just pass a pointer to fixed-size space to hold a pointer, and the
<code class="function">IcePoProcessMsgProc</code>
callback would allocate the storage and store the pointer.
It is the responsibility of the client receiving the reply to
free any memory allocated on its behalf.</p><p>If reply_wait is not NULL and
<code class="function">IcePoProcessMsgProc</code>
has a reply or error to return in response to this reply_wait
(that is, no callback was generated), then the reply_ready_ret argument
should be set to
<code class="function">True</code>
Note that an error should only be returned
if it corresponds to the reply being waited for. Otherwise, the
<code class="function">IcePoProcessMsgProc</code>
should either handle the error internally or invoke an error handler
for its library.</p><p>If reply_wait is NULL,
then care must be taken not to store any value in reply_ready_ret,
because this pointer may also be NULL.</p><p>The
<a class="xref" href="#IcePaProcessMsgProc"><code class="function">IcePaProcessMsgProc</code></a>
callback, on the other hand, should always pass
the message to the client via a callback. For example, if this is a Session
Management "Interact Request" message, this function should notify the
client of the "Interact Request" via a callback.</p><p>The reason the
<a class="xref" href="#IcePaProcessMsgProc"><code class="function">IcePaProcessMsgProc</code></a>
callback does not have a reply_wait, like
<code class="function">IcePoProcessMsgProc</code>
does, is because a process that is acting as
a server should never block for a reply (infinite blocking can
occur if the connecting client does not act properly, denying access
to other clients).</p></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="Authentication_Methods"></a>Authentication Methods</h2></div></div></div><p>As already stated, a protocol library must register the authentication
methods that it supports with the ICE library. For each authentication
method, there are two callbacks that may be registered:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
One to handle the side that initiates a <code class="function">ProtocolSetup</code>
</p></li><li class="listitem"><p>
One to handle the side that accepts or rejects this request
</p></li></ul></div><p><code class="function">IcePoAuthProc</code>
is the callback invoked for the client that initiated the
<code class="function">ProtocolSetup</code>
This callback must be able to respond
to the initial "Authentication Required" message or subsequent
"Authentication Next Phase" messages sent by the other client.</p><div class="funcsynopsis"><a id="IcePoAuthStatus"></a><p><code class="funcdef">IcePoAuthStatus <strong class="fsfunc">IcePoAuthStatus </strong>(</code>IceConn<var class="pdparam"> ice_conn</var>, IcePointer<var class="pdparam"> client_data</var>, int<var class="pdparam"> opcode</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>ice_conn</em></span></span></p></td><td><p>The ICE connection object.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>auth_state_ptr</em></span></span></p></td><td><p>A pointer to state for use by the authentication callback procedure.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>clean_up</em></span></span></p></td><td><p>If
<code class="function">True</code>
authentication is over, and the function
should clean up any state it was maintaining. The
last 6 arguments should be ignored.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>swap</em></span></span></p></td><td><p>If
<code class="function">True</code>
the auth_data may have to be byte swapped
(depending on its contents).</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>auth_datalen</em></span></span></p></td><td><p>The length (in bytes) of the authenticator data.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>auth_data</em></span></span></p></td><td><p>The data from the authenticator.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>reply_datalen_ret</em></span></span></p></td><td><p>The length (in bytes) of the reply data returned.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>reply_data_ret</em></span></span></p></td><td><p>The reply data returned.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>error_string_ret</em></span></span></p></td><td><p>If the authentication procedure encounters an error during
authentication, it should allocate and return
an error string.</p></td></tr></tbody></table></div><p>Authentication may require several phases, depending on the authentication
method. As a result, the
<code class="function">IcePoAuthProc</code>
may be called more than once when authenticating a client, and
some state will have to be maintained between each invocation.
At the start of each
<code class="function">ProtocolSetup</code>
*auth_state_ptr is NULL,
and the function should initialize its state and set
this pointer. In subsequent invocations of the callback, the pointer
should be used to get at any state previously stored by the callback.</p><p>If needed, the network ID of the client accepting the
<code class="function">ProtocolSetup</code>
can be obtained by calling the
<code class="function">IceConnectionString</code>
function.</p><p>ICElib will be responsible for freeing the reply_data_ret and
error_string_ret pointers with
<code class="function">free</code></p><p>The auth_data pointer may point to a volatile block of memory.
If the data must be kept beyond this invocation of the callback, be sure
to make a copy of it.</p><p>The
<code class="function">IcePoAuthProc</code>
should return one of four values:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p><code class="function">IcePoAuthHaveReply</code>
- a reply is available.</p></li><li class="listitem"><p><code class="function">IcePoAuthRejected</code>
- authentication rejected.</p></li><li class="listitem"><p><code class="function">IcePoAuthFailed</code>
- authentication failed.</p></li><li class="listitem"><p><code class="function">IcePoAuthDoneCleanup</code>
- done cleaning up.</p></li></ul></div><p><code class="function">IcePaAuthProc</code>
is the callback invoked for the client that received the
<code class="function">ProtocolSetup</code></p><div class="funcsynopsis"><a id="PoAuthStatus"></a><p><code class="funcdef">IcePoAuthStatus <strong class="fsfunc">PoAuthStatus </strong>(</code>IceConn<var class="pdparam"> ice_conn</var>, IcePointer<var class="pdparam"> *auth_state_ptr</var>, Bool<var class="pdparam"> swap</var>, int<var class="pdparam"> auth_datalen</var>, IcePointer<var class="pdparam"> auth_data</var>, int<var class="pdparam"> *reply_datalen_ret</var>, IcePointer<var class="pdparam"> *reply_data_ret</var>, char<var class="pdparam"> **error_string_ret</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>ice_conn</em></span></span></p></td><td><p>The ICE connection object.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>auth_state_ptr</em></span></span></p></td><td><p>A pointer to state for use by the authentication callback procedure.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>swap</em></span></span></p></td><td><p>If
<code class="function">True</code>
auth_data may have to be byte swapped
(depending on its contents).</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>auth_datalen</em></span></span></p></td><td><p>The length (in bytes) of the protocol originator authentication data.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>auth_data</em></span></span></p></td><td><p>The authentication data from the protocol originator.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>reply_datalen_ret</em></span></span></p></td><td><p>The length of the authentication data returned.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>reply_data_ret</em></span></span></p></td><td><p>The authentication data returned.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>error_string_ret</em></span></span></p></td><td><p>If authentication is rejected or fails, an error
string is returned.</p></td></tr></tbody></table></div><p>Authentication may require several phases, depending on the authentication
method. As a result, the
<code class="function">IcePaAuthProc</code>
may be called more than once when authenticating a client, and
some state will have to be maintained between each invocation.
At the start of each
<code class="function">ProtocolSetup</code>
auth_datalen is zero,
*auth_state_ptr is NULL,
and the function should initialize its state and set
this pointer. In subsequent invocations of the callback, the pointer
should be used to get at any state previously stored by the callback.</p><p>If needed, the network ID of the client accepting the
<code class="function">ProtocolSetup</code>
can be obtained by calling the
<code class="function">IceConnectionString</code>
function.</p><p>The auth_data pointer may point to a volatile block of memory.
If the data must be kept beyond this invocation of the callback, be sure
to make a copy of it.</p><p>ICElib will be responsible for transmitting and freeing the reply_data_ret and
error_string_ret pointers with
<code class="function">free</code></p><p>
The <code class="function">IcePaAuthProc</code> should return one of four values:
</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
<code class="function">IcePaAuthContinue</code> - continue (or start) authentication.
</p></li><li class="listitem"><p>
<code class="function">IcePaAuthAccepted</code> - authentication accepted.
</p></li><li class="listitem"><p>
<code class="function">IcePaAuthRejected</code> - authentication rejected.
</p></li><li class="listitem"><p>
<code class="function">IcePaAuthFailed</code> - authentication failed.
</p></li></ul></div></div></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a id="ICE_Connections"></a>Chapter 7. ICE Connections</h1></div></div></div><div class="toc"><p><strong>Table of Contents</strong></p><dl class="toc"><dt><span class="sect1"><a href="#Opening_an_ICE_Connection">Opening an ICE Connection</a></span></dt><dt><span class="sect1"><a href="#Listening_for_ICE_Connections">Listening for ICE Connections</a></span></dt><dt><span class="sect1"><a href="#Host_Based_Authentication_for_ICE_Connections">Host Based Authentication for ICE Connections</a></span></dt><dt><span class="sect1"><a href="#Accepting_ICE_Connections">Accepting ICE Connections</a></span></dt><dt><span class="sect1"><a href="#Closing_ICE_Connections">Closing ICE Connections</a></span></dt><dt><span class="sect1"><a href="#Connection_Watch_Procedures">Connection Watch Procedures</a></span></dt></dl></div><p>
In order for two clients to establish an ICE connection, one client has to be
waiting for connections, and the other client has to initiate the connection.
Most clients will initiate connections, so we discuss that first.
</p><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="Opening_an_ICE_Connection"></a>Opening an ICE Connection</h2></div></div></div><p>
To open an ICE connection with another client (that is, waiting
for connections), use <a class="xref" href="#IceOpenConnection"><code class="function">IceOpenConnection</code></a>
</p><div class="funcsynopsis"><a id="IceOpenConnection"></a><p><code class="funcdef">IceConn <strong class="fsfunc">IceOpenConnection</strong>(</code>char<var class="pdparam"> *network_ids_list</var>, IcePointer<var class="pdparam"> context</var>, Bool<var class="pdparam"> must_authenticate</var>, int<var class="pdparam"> major_opcode_check</var>, int<var class="pdparam"> error_length</var>, char<var class="pdparam"> *error_string_ret</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>network_ids_list</em></span></span></p></td><td><p>
Specifies the network ID(s) of the other client.
</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>context</em></span></span></p></td><td><p>
A pointer to an opaque object or NULL. Used to determine if an
ICE connection can be shared (see below).
</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>must_authenticate</em></span></span></p></td><td><p>
If <code class="function">True</code> the other client may not bypass authentication.
</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>major_opcode_check</em></span></span></p></td><td><p>
Used to force a new ICE connection to be created (see below).
</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>error_length</em></span></span></p></td><td><p>Length of the error_string_ret argument passed in.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>error_string_ret</em></span></span></p></td><td><p>
Returns a null-terminated error message, if any. The error_string_ret
argument points to user supplied memory. No more than error_length bytes
are used.
</p></td></tr></tbody></table></div><p>
<a class="xref" href="#IceOpenConnection"><code class="function">IceOpenConnection</code></a>
returns an opaque ICE connection object if it succeeds;
otherwise, it returns NULL.
</p><p>
The network_ids_list argument contains a list of network IDs separated
by commas. An attempt will be made to use the first network ID. If
that fails, an attempt will be made using the second network ID, and so on.
Each network ID has the following format:
</p><div class="informaltable"><table border="0"><colgroup><col align="left" class="c1" /><col align="left" class="c2" /></colgroup><tbody><tr><td align="left">tcp/<hostname>:<portnumber></td><td align="left">or</td></tr><tr><td align="left">decnet/<hostname>::<objname></td><td align="left">or</td></tr><tr><td align="left">local/<hostname>:<path></td><td align="left"> </td></tr></tbody></table></div><p>Most protocol libraries will have some sort of open function that should
internally make a call into
<a class="xref" href="#IceOpenConnection"><code class="function">IceOpenConnection</code></a>
When
<a class="xref" href="#IceOpenConnection"><code class="function">IceOpenConnection</code></a>
is called, it may be possible to use a previously opened ICE connection (if
the target client is the same). However, there are cases in which shared
ICE connections are not desired.</p><p>The context argument is used to determine if an ICE connection can
be shared.
If context is NULL,
then the caller is always willing to share the connection.
If context is not NULL,
then the caller is not willing to use a previously opened ICE connection
that has a different non-NULL context associated with it.</p><p>In addition, if major_opcode_check contains a nonzero major opcode value,
a previously created ICE connection will be used only if the major opcode
is not active on the connection. This can be used to force multiple ICE
connections between two clients for the same protocol.</p><p>Any authentication requirements are handled internally by the ICE library.
The method by which the authentication data is obtained
is implementation-dependent.
<a href="#ftn.idp56138032" class="footnote" id="idp56138032"><sup class="footnote">[1]</sup></a> </p><p>After
<a class="xref" href="#IceOpenConnection"><code class="function">IceOpenConnection</code></a>
is called, the client is ready to send a
<code class="function">ProtocolSetup</code>
(provided that
<a class="xref" href="#IceRegisterForProtocolSetup"><code class="function">IceRegisterForProtocolSetup</code></a>
was called) or receive a
<code class="function">ProtocolSetup</code>
(provided that
<a class="xref" href="#IceRegisterForProtocolReply"><code class="function">IceRegisterForProtocolReply</code></a>
was called).</p></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="Listening_for_ICE_Connections"></a>Listening for ICE Connections</h2></div></div></div><p>Clients wishing to accept ICE connections must first call
<a class="xref" href="#IceListenForConnections"><code class="function">IceListenForConnections</code></a>
or
<a class="xref" href="#IceListenForWellKnownConnections"><code class="function">IceListenForWellKnownConnections</code></a>
so that they can listen for connections. A list of opaque "listen" objects are
returned, one for each type of transport method that is available
(for example, Unix Domain, TCP, DECnet, and so on).</p><p>Normally clients will let ICElib allocate an available name in each
transport and return listen objects. Such a client will then use
<a class="xref" href="#IceComposeNetworkIdList"><code class="function">IceComposeNetworkIdList</code></a>
to extract the chosen names and make them
available to other clients for opening the connection. In certain
cases it may be necessary for a client to listen for connections
on pre-arranged transport object names. Such a client may use
<a class="xref" href="#IceListenForWellKnownConnections"><code class="function">IceListenForWellKnownConnections</code></a>
to specify the names for the listen objects.</p><div class="funcsynopsis"><a id="IceListenForConnections"></a><p><code class="funcdef">Status <strong class="fsfunc">IceListenForConnections</strong>(</code>int<var class="pdparam"> *count_ret</var>, IceListenObj<var class="pdparam"> **listen_objs_ret</var>, int<var class="pdparam"> error_length</var>, char<var class="pdparam"> *error_string_ret</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>count_ret</em></span></span></p></td><td><p>Returns the number of listen objects created.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>listen_objs_ret</em></span></span></p></td><td><p>Returns a list of pointers to opaque listen objects.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>error_length</em></span></span></p></td><td><p>The length of the error_string_ret argument passed in.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>error_string_ret</em></span></span></p></td><td><p>Returns a null-terminated error message, if any.
The error_string_ret points to user supplied memory.
No more than error_length bytes are used.</p></td></tr></tbody></table></div><p>The return value of
<a class="xref" href="#IceListenForConnections"><code class="function">IceListenForConnections</code></a>
is zero for failure and a positive value for success.</p><div class="funcsynopsis"><a id="IceListenForWellKnownConnections"></a><p><code class="funcdef">Status <strong class="fsfunc">IceListenForWellKnownConnections</strong>(</code>char<var class="pdparam"> *port_id</var>, int<var class="pdparam"> *count_ret</var>, IceListenObj<var class="pdparam"> **listen_objs_ret</var>, int<var class="pdparam"> error_length</var>, char<var class="pdparam"> *error_string_ret</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>port_id</em></span></span></p></td><td><p>
Specifies the port identification for the address(es) to be opened. The
value must not contain the slash ("/"> or comma (".") character; thse are
reserved for future use.
</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>count_ret</em></span></span></p></td><td><p>Returns the number of listen objects created.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>listen_objs_ret</em></span></span></p></td><td><p>
Returns a list of pointers to opaque listen objects.
</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>listen_objs_ret</em></span></span></p></td><td><p>
Returns a list of pointers to opaque listen objects.
</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>error_length</em></span></span></p></td><td><p>
The length of the error_string_ret argument passed in.
</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>error_string_ret</em></span></span></p></td><td><p>
Returns a null-terminated error message, if any. The error_string_ret
points to user supplied memory. No more than error_length bytes are used.
</p></td></tr></tbody></table></div><p>
<a class="xref" href="#IceListenForWellKnownConnections"><code class="function">IceListenForWellKnownConnections</code></a> constructs a list
of network IDs by prepending each known transport to port_id and then
attempts to create listen objects for the result. Port_id is the portnumber,
objname, or path portion of the ICE network ID. If a listen object for
a particular network ID cannot be created the network ID is ignored.
If no listen objects are created
<a class="xref" href="#IceListenForWellKnownConnections"><code class="function">IceListenForWellKnownConnections</code></a>
returns failure.
</p><p>
The return value of <a class="xref" href="#IceListenForWellKnownConnections"><code class="function">IceListenForWellKnownConnections</code></a>
is zero for failure and a positive value for success.
</p><p>
To close and free the listen objects, use
<a class="xref" href="#IceFreeListenObjs"><code class="function">IceFreeListenObjs</code></a>
</p><div class="funcsynopsis"><a id="IceFreeListenObjs"></a><p><code class="funcdef">void <strong class="fsfunc">IceFreeListenObjs</strong>(</code>int<var class="pdparam"> count</var>, IceListenObj<var class="pdparam"> *listen_objs</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>count</em></span></span></p></td><td><p>The number of listen objects.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>listen_objs</em></span></span></p></td><td><p>The listen objects.</p></td></tr></tbody></table></div><p>
To detect a new connection on a listen object, use
<code class="function">select</code> on the descriptor associated with
the listen object.
</p><p>
To obtain the descriptor, use
<a class="xref" href="#IceGetListenConnectionNumber"><code class="function">IceGetListenConnectionNumber</code></a>
</p><div class="funcsynopsis"><a id="IceGetListenConnectionNumber"></a><p><code class="funcdef">int <strong class="fsfunc">IceGetListenConnectionNumber</strong>(</code>IceListenObj<var class="pdparam"> *listen_objs</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>listen_obj</em></span></span></p></td><td><p>The listen objects.</p></td></tr></tbody></table></div><p>
To obtain the network ID string associated with a listen object, use
<a class="xref" href="#IceGetListenConnectionString"><code class="function">IceGetListenConnectionString</code></a>
</p><div class="funcsynopsis"><a id="IceGetListenConnectionString"></a><p><code class="funcdef">char <strong class="fsfunc">IceGetListenConnectionString</strong>(</code>IceListenObj<var class="pdparam"> listen_obj</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>listen_obj</em></span></span></p></td><td><p>The listen objects.</p></td></tr></tbody></table></div><p>A network ID has the following format:</p><div class="informaltable"><table border="0"><colgroup><col align="left" class="c1" /><col align="left" class="c2" /></colgroup><tbody><tr><td align="left">tcp/<hostname>:<portnumber></td><td align="left">or</td></tr><tr><td align="left">decnet/<hostname>::<objname></td><td align="left">or</td></tr><tr><td align="left">local/<hostname>:<path></td><td align="left"> </td></tr></tbody></table></div><p>
To compose a string containing a list of network IDs separated by commas
(the format recognized by <a class="xref" href="#IceOpenConnection"><code class="function">IceOpenConnection</code></a>
use <a class="xref" href="#IceComposeNetworkIdList"><code class="function">IceComposeNetworkIdList</code></a>
</p><div class="funcsynopsis"><a id="IceComposeNetworkIdList"></a><p><code class="funcdef">char <strong class="fsfunc">IceComposeNetworkIdList</strong>(</code>int<var class="pdparam"> count</var>, IceListenObj<var class="pdparam"> *listen_objs</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>count</em></span></span></p></td><td><p>The number of listen objects.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>listen_objs</em></span></span></p></td><td><p>The listen objects.</p></td></tr></tbody></table></div></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="Host_Based_Authentication_for_ICE_Connections"></a>Host Based Authentication for ICE Connections</h2></div></div></div><p>
If authentication fails when a client attempts to open an
ICE connection and the initiating client has not required authentication,
a host based authentication procedure may be invoked to provide
a last chance for the client to connect. Each listen object has such a
callback associated with it, and this callback is set using the
<a class="xref" href="#IceSetHostBasedAuthProc"><code class="function">IceSetHostBasedAuthProc</code></a>
function.
</p><div class="funcsynopsis"><a id="IceSetHostBasedAuthProc"></a><p><code class="funcdef">void <strong class="fsfunc">IceSetHostBasedAuthProc</strong>(</code>IceListenObj<var class="pdparam"> listen_obj</var>, IceHostBasedAuthProc<var class="pdparam"> host_based_auth_proc</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>IceListenObj</em></span></span></p></td><td><p>The listen object.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>host_based_auth_proc</em></span></span></p></td><td><p>The host based authentication procedure.</p></td></tr></tbody></table></div><p>
By default, each listen object has no host based authentication procedure
associated with it. Passing NULL for host_based_auth_proc turns off
host based authentication if it was previously set.
</p><div class="funcsynopsis"><a id="HostBasedAuthProc"></a><p><code class="funcdef">Bool <strong class="fsfunc">HostBasedAuthProc</strong>(</code>char<var class="pdparam"> *host_name</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>host_name</em></span></span></p></td><td><p>
The host name of the client that tried to open an ICE connection.
</p></td></tr></tbody></table></div><p>
The host_name argument is a string in the form
<span class="emphasis"><em>protocol</em></span>/
<span class="emphasis"><em>hostname</em></span>,
where <span class="emphasis"><em>protocol</em></span> is one of
{tcp, decnet, local}.
</p><p>
If <code class="function">IceHostBasedAuthProc</code> returns
<code class="function">True</code>
access will be granted, even though the original authentication failed.
Note that authentication can effectively be disabled by registering an
<code class="function">IceHostBasedAuthProc</code>
which always returns <code class="function">True</code>
</p><p>
Host based authentication is also allowed at
<code class="function">ProtocolSetup</code> time.
The callback is specified in the
<a class="xref" href="#IceRegisterForProtocolReply"><code class="function">IceRegisterForProtocolReply</code></a>
function (see
<a class="xref" href="#Protocol_Registration" title="Chapter 6. Protocol Registration"><em>Protocol Registration</em></a>).
</p></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="Accepting_ICE_Connections"></a>Accepting ICE Connections</h2></div></div></div><p>
After a connection attempt is detected on a listen object returned by
<a class="xref" href="#IceListenForConnections"><code class="function">IceListenForConnections</code></a>
you should call <a class="xref" href="#IceAcceptConnection"><code class="function">IceAcceptConnection</code></a>
This returns a new opaque ICE connection object.
</p><div class="funcsynopsis"><a id="IceAcceptConnection"></a><p><code class="funcdef">IceConn <strong class="fsfunc">IceAcceptConnection</strong>(</code>IceListenObj<var class="pdparam"> listen_obj</var>, IceAcceptStatus<var class="pdparam"> *status_ret</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>listen_obj</em></span></span></p></td><td><p>The listen object on which a new connection was detected.</p></td></tr></tbody></table></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>status_ret</em></span></span></p></td><td><p>Return status information.</p></td></tr></tbody></table></div><p>The status_ret argument is set to one of the following values:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p><code class="function">IceAcceptSuccess</code>
- the accept operation succeeded,
and the function returns a new connection object.</p></li><li class="listitem"><p><code class="function">IceAcceptFailure</code>
- the accept operation failed, and the function returns NULL.</p></li><li class="listitem"><p><code class="function">IceAcceptBadMalloc</code>
- a memory allocation failed, and the function returns NULL.</p></li></ul></div><p>In general, to detect new connections, you should call
<code class="function">select</code>
on the file descriptors associated with the listen objects.
When a new connection is detected, the
<a class="xref" href="#IceAcceptConnection"><code class="function">IceAcceptConnection</code></a>
function should be called.
<a class="xref" href="#IceAcceptConnection"><code class="function">IceAcceptConnection</code></a>
may return a new ICE connection that is in a pending state. This is because
before the connection can become valid, authentication may be necessary.
Because the ICE library cannot block and wait for the connection to
become valid (infinite blocking can occur if the connecting client
does not act properly), the application must wait for the connection status
to become valid.</p><p>The following pseudo-code demonstrates how connections are accepted:</p><pre class="literallayout">
new_ice_conn = IceAcceptConnection (listen_obj, &accept_status);
if (accept_status != IceAcceptSuccess)
{
close the file descriptor and return
}
status = IceConnectionStatus (new_ice_conn);
time_start = time_now;
while (status == IceConnectPending)
{
select() on {new_ice_conn, all open connections}
for (each ice_conn in the list of open connections)
if (data ready on ice_conn)
{
status = IceProcessMessages (ice_conn, NULL, NULL);
if (status == IceProcessMessagesIOError)
IceCloseConnection(ice_conn);
}
if data ready on new_ice_conn
{
/*
* IceProcessMessages is called until the connection
* is non-pending. Doing so handles the connection
* setup request and any authentication requirements.
*/
IceProcessMessages ( new_ice_conn, NULL, NULL);
status = IceConnectionStatus (new_ice_conn);
}
else
{
if (time_now - time_start > MAX_WAIT_TIME)
status = IceConnectRejected;
}
}
if (status == IceConnectAccepted)
{
Add new_ice_conn to the list of open connections
}
else
{
IceCloseConnection
new_ice_conn
}
</pre><p>After
<a class="xref" href="#IceAcceptConnection"><code class="function">IceAcceptConnection</code></a>
is called and the connection has been
validated, the client is ready to receive a
<code class="function">ProtocolSetup</code>
(provided
that
<a class="xref" href="#IceRegisterForProtocolReply"><code class="function">IceRegisterForProtocolReply</code></a>
was called) or send a
<code class="function">ProtocolSetup</code>
(provided that
<a class="xref" href="#IceRegisterForProtocolSetup"><code class="function">IceRegisterForProtocolSetup</code></a>
was called).</p></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="Closing_ICE_Connections"></a>Closing ICE Connections</h2></div></div></div><p>To close an ICE connection created with
<a class="xref" href="#IceOpenConnection"><code class="function">IceOpenConnection</code></a>
or
<a class="xref" href="#IceAcceptConnection"><code class="function">IceAcceptConnection</code></a>
use
<a class="xref" href="#IceCloseConnection"><code class="function">IceCloseConnection</code></a></p><div class="funcsynopsis"><a id="IceCloseConnection"></a><p><code class="funcdef">IceCloseStatus <strong class="fsfunc">IceCloseConnection</strong>(</code>IceConn<var class="pdparam"> ice_conn</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>ice_conn</em></span></span></p></td><td><p>The ICE connection to close.</p></td></tr></tbody></table></div><p>To actually close an ICE connection, the following conditions
must be met:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>The <span class="emphasis"><em>open reference count</em></span> must have reached zero on this ICE connection.
When
<a class="xref" href="#IceOpenConnection"><code class="function">IceOpenConnection</code></a>
is called, it tries to use a previously opened
ICE connection. If it is able to use an existing connection, it increments
the open reference count on the connection by one.
So, to close an ICE connection, each call to
<a class="xref" href="#IceOpenConnection"><code class="function">IceOpenConnection</code></a>
must be matched with a call to
<a class="xref" href="#IceCloseConnection"><code class="function">IceCloseConnection</code></a>
The connection can be closed only
on the last call to
<a class="xref" href="#IceCloseConnection"><code class="function">IceCloseConnection</code></a></p></li><li class="listitem"><p>The <span class="emphasis"><em>active protocol count</em></span> must have reached zero. Each time a
<code class="function">ProtocolSetup</code>
succeeds on the connection, the active protocol count
is incremented by one. When the client no longer expects to use the
protocol on the connection, the
<a class="xref" href="#IceProtocolShutdown"><code class="function">IceProtocolShutdown</code></a>
function should be called, which decrements the active protocol count
by one (see
<a class="xref" href="#Protocol_Setup_and_Shutdown" title="Chapter 8. Protocol Setup and Shutdown"><em>Protocol Setup and Shutdown</em></a>).
</p></li><li class="listitem"><p>If shutdown negotiation is enabled on the connection, the client on the other
side of the ICE connection must agree to have the connection closed.</p><p><a class="xref" href="#IceCloseConnection"><code class="function">IceCloseConnection</code></a>
returns one of the following values:</p></li><li class="listitem"><p><code class="function">IceClosedNow</code>
- the ICE connection was closed at this time. The watch procedures were
invoked and the connection was freed.</p></li><li class="listitem"><p><code class="function">IceClosedASAP</code>
- an IO error had occurred on the connection, but
<a class="xref" href="#IceCloseConnection"><code class="function">IceCloseConnection</code></a>
is being called within a nested
<a class="xref" href="#IceProcessMessages"><code class="function">IceProcessMessages</code></a>
The watch procedures have been invoked at this time, but the connection
will be freed as soon as possible (when the nesting level reaches zero and
<a class="xref" href="#IceProcessMessages"><code class="function">IceProcessMessages</code></a>
returns a status of
<code class="function">IceProcessMessagesConnectionClosed</code></p></li><li class="listitem"><p><code class="function">IceConnectionInUse</code>
- the connection was not closed at this time, because it is being used by
other active protocols.</p></li><li class="listitem"><p><code class="function">IceStartedShutdownNegotiation</code>
- the connection was not closed at this time and shutdown negotiation started
with the client on the other side of the ICE connection. When the connection
is actually closed,
<a class="xref" href="#IceProcessMessages"><code class="function">IceProcessMessages</code></a>
will return a status of
<code class="function">IceProcessMessagesConnectionClosed</code></p></li></ul></div><p>When it is known that the client on the other side of the ICE connection
has terminated the connection without initiating shutdown negotiation, the
<a class="xref" href="#IceSetShutdownNegotiation"><code class="function">IceSetShutdownNegotiation</code></a>
function should be called to turn off shutdown negotiation. This will prevent
<a class="xref" href="#IceCloseConnection"><code class="function">IceCloseConnection</code></a>
from writing to a broken connection.</p><div class="funcsynopsis"><a id="IceSetShutdownNegotiation"></a><p><code class="funcdef">void <strong class="fsfunc">IceSetShutdownNegotiation</strong>(</code>IceConn<var class="pdparam"> ice_conn</var>, Bool<var class="pdparam"> negotiate</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>ice_conn</em></span></span></p></td><td><p>A valid ICE connection object.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>negotiate</em></span></span></p></td><td><p>If
<code class="function">False</code>
shutdown negotiating will be turned off.</p></td></tr></tbody></table></div><p>To check the shutdown negotiation status of an ICE connection, use
<a class="xref" href="#IceCheckShutdownNegotiation"><code class="function">IceCheckShutdownNegotiation</code></a></p><div class="funcsynopsis"><a id="IceCheckShutdownNegotiation"></a><p><code class="funcdef">Bool <strong class="fsfunc">IceCheckShutdownNegotiation</strong>(</code>IceConn<var class="pdparam"> ice_conn</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>ice_conn</em></span></span></p></td><td><p>A valid ICE connection object.</p></td></tr></tbody></table></div><p><a class="xref" href="#IceCheckShutdownNegotiation"><code class="function">IceCheckShutdownNegotiation</code></a>
returns
<code class="function">True</code>
if shutdown negotiation will take place on the connection;
otherwise, it returns
<code class="function">False</code>
Negotiation is on by default for a connection. It
can only be changed with the
<a class="xref" href="#IceSetShutdownNegotiation"><code class="function">IceSetShutdownNegotiation</code></a>
function.</p></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="Connection_Watch_Procedures"></a>Connection Watch Procedures</h2></div></div></div><p>To add a watch procedure that will be called
each time ICElib opens a new connection via
<a class="xref" href="#IceOpenConnection"><code class="function">IceOpenConnection</code></a>
or
<a class="xref" href="#IceAcceptConnection"><code class="function">IceAcceptConnection</code></a>
or closes a connection via
<a class="xref" href="#IceCloseConnection"><code class="function">IceCloseConnection</code></a>
use
<a class="xref" href="#IceAddConnectionWatch"><code class="function">IceAddConnectionWatch</code></a></p><div class="funcsynopsis"><a id="IceAddConnectionWatch"></a><p><code class="funcdef">Status <strong class="fsfunc">IceAddConnectionWatch</strong>(</code>IceWatchProc<var class="pdparam"> watch_proc</var>, IcePointer<var class="pdparam"> client_data</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>watch_proc</em></span></span></p></td><td><p>
The watch procedure to invoke when ICElib opens or closes a connection.
</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>client_data</em></span></span></p></td><td><p>This pointer will be passed to the watch procedure.</p></td></tr></tbody></table></div><p>
The return value of <a class="xref" href="#IceAddConnectionWatch"><code class="function">IceAddConnectionWatch</code></a>
is zero for failure, and a positive value for success.
</p><p>
Note that several calls to <a class="xref" href="#IceOpenConnection"><code class="function">IceOpenConnection</code></a>
might share the same ICE connection. In such a case, the watch procedure
is only invoked when the connection is first created (after authentication
succeeds). Similarly, because connections might be shared, the
watch procedure is called only if <a class="xref" href="#IceCloseConnection"><code class="function">IceCloseConnection</code></a>
actually closes the connection (right before the IceConn is freed).
</p><p>
The watch procedures are very useful for applications that
need to add a file descriptor to a select mask when a new connection
is created and remove the file descriptor when the connection is destroyed.
Because connections are shared, knowing when to add and remove the file
descriptor from the select mask would be difficult without the watch
procedures.
</p><p>
Multiple watch procedures may be registered with the ICE library.
No assumptions should be made about their order of invocation.
</p><p>
If one or more ICE connections were already created by the ICE library at the
time the watch procedure is registered, the watch procedure will instantly
be invoked for each of these ICE connections (with the opening argument
set to <code class="function">True</code>
</p><p>
The watch procedure is of type <code class="function">IceWatchProc</code>
</p><div class="funcsynopsis"><a id="WatchProc"></a><p><code class="funcdef">void <strong class="fsfunc">WatchProc</strong>(</code>IceConn<var class="pdparam"> ice_conn</var>, IcePointer<var class="pdparam"> client_data</var>, Bool<var class="pdparam"> opening</var>, IcePointer<var class="pdparam"> *watch_data</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>ice_conn</em></span></span></p></td><td><p>
The opened or closed ICE connection. Call
<code class="function">IceConnectionNumber</code>
to get the file descriptor associated with this connection.
</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>client_data</em></span></span></p></td><td><p>
Client data specified in the call to
<a class="xref" href="#IceAddConnectionWatch"><code class="function">IceAddConnectionWatch</code></a>
</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>opening</em></span></span></p></td><td><p>
If <code class="function">True</code> the connection is being opened. If
<code class="function">False</code> the connection is being closed.
</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>watch_data</em></span></span></p></td><td><p>Can be used to save a pointer to client data.</p></td></tr></tbody></table></div><p>
If opening is <code class="function">True</code> the client should set the
*watch_data pointer to any data it may need to save until the connection
is closed and the watch procedure is invoked again with opening set to
<code class="function">False</code>
</p><p>
To remove a watch procedure, use
<a class="xref" href="#IceRemoveConnectionWatch"><code class="function">IceRemoveConnectionWatch</code></a>
</p><div class="funcsynopsis"><a id="IceRemoveConnectionWatch"></a><p><code class="funcdef">void <strong class="fsfunc">IceRemoveConnectionWatch</strong>(</code>IceWatchProc<var class="pdparam"> watch_proc</var>, IcePointer<var class="pdparam"> client_data</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>watch_proc</em></span></span></p></td><td><p>
The watch procedure that was passed to
<a class="xref" href="#IceAddConnectionWatch"><code class="function">IceAddConnectionWatch</code></a>
</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>client_data</em></span></span></p></td><td><p>
The client_data pointer that was passed to
<a class="xref" href="#IceAddConnectionWatch"><code class="function">IceAddConnectionWatch</code></a>
</p></td></tr></tbody></table></div></div><div class="footnotes"><br /><hr style="width:100; text-align:left;margin-left: 0" /><div id="ftn.idp56138032" class="footnote"><p><a href="#idp56138032" class="para"><sup class="para">[1] </sup></a>The X Consortium's ICElib implementation uses an .ICEauthority file (see
Appendix A).
</p></div></div></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a id="Protocol_Setup_and_Shutdown"></a>Chapter 8. Protocol Setup and Shutdown</h1></div></div></div><p>
To activate a protocol on a given ICE connection, use
<a class="xref" href="#IceProtocolSetup"><code class="function">IceProtocolSetup</code></a>
</p><div class="funcsynopsis"><a id="IceProtocolSetup"></a><p><code class="funcdef">IceProtocolSetupStatus <strong class="fsfunc">IceProtocolSetup</strong>(</code>IceConn<var class="pdparam"> ice_conn</var>, int<var class="pdparam"> my_opcode</var>, IcePointer<var class="pdparam"> client_data</var>, Bool<var class="pdparam"> must_authenticate</var>, int<var class="pdparam"> *major_version_ret</var>, int<var class="pdparam"> *minor_version_ret</var>, char<var class="pdparam"> **vendor_ret</var>, char<var class="pdparam"> **release_ret</var>, int<var class="pdparam"> error_length</var>, char<var class="pdparam"> *error_string_ret</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>ice_conn</em></span></span></p></td><td><p>A valid ICE connection object.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>my_opcode</em></span></span></p></td><td><p>
The major opcode of the protocol to be set up, as returned by
<a class="xref" href="#IceRegisterForProtocolSetup"><code class="function">IceRegisterForProtocolSetup</code></a>
</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>client_data</em></span></span></p></td><td><p>
The client data stored in this pointer will be passed to the
<code class="function">IcePoProcessMsgProc</code> callback.
</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>must_authenticate</em></span></span></p></td><td><p>
If <code class="function">True</code> the other client may
not bypass authentication.
</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>major_version_ret</em></span></span></p></td><td><p>The major version of the protocol to be used is returned.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>minor_version_ret</em></span></span></p></td><td><p>The minor version of the protocol to be used is returned.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>vendor_ret</em></span></span></p></td><td><p>The vendor string specified by the protocol acceptor.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>release_ret</em></span></span></p></td><td><p>The release string specified by the protocol acceptor.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>error_length</em></span></span></p></td><td><p>
Specifies the length of the error_string_ret argument passed in.
</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>error_string_ret</em></span></span></p></td><td><p>
Returns a null-terminated error message, if any.
The error_string_ret argument points to user supplied memory.
No more than error_length bytes are used.
</p></td></tr></tbody></table></div><p>
The vendor_ret and release_ret strings should be freed with
<code class="function">free</code> when no longer needed.
</p><p>
<a class="xref" href="#IceProtocolSetup"><code class="function">IceProtocolSetup</code></a> returns one of the following values:
</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
<code class="function">IceProtocolSetupSuccess</code> - the major_version_ret,
minor_version_ret, vendor_ret, release_ret are set.
</p></li><li class="listitem"><p>
<code class="function">IceProtocolSetupFailure</code> or
<code class="function">IceProtocolSetupIOError</code>
- check error_string_ret for failure reason. The major_version_ret,
minor_version_ret, vendor_ret, release_ret are not set.
</p></li><li class="listitem"><p>
<code class="function">IceProtocolAlreadyActive</code>
- this protocol is already active on this connection.
The major_version_ret, minor_version_ret, vendor_ret, release_ret
are not set.
</p></li></ul></div><p>
To notify the ICE library when a given protocol will no longer be used
on an ICE connection, use <a class="xref" href="#IceProtocolShutdown"><code class="function">IceProtocolShutdown</code></a>
</p><div class="funcsynopsis"><a id="IceProtocolShutdown"></a><p><code class="funcdef">Status <strong class="fsfunc">IceProtocolShutdown</strong>(</code>IceConn<var class="pdparam"> ice_conn</var>, int<var class="pdparam"> major_opcode</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>ice_conn</em></span></span></p></td><td><p>A valid ICE connection object.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>major_opcode</em></span></span></p></td><td><p>The major opcode of the protocol to shut down.</p></td></tr></tbody></table></div><p>
The return value of <a class="xref" href="#IceProtocolShutdown"><code class="function">IceProtocolShutdown</code></a>
is zero for failure and a positive value for success.
</p><p>
Failure will occur if the major opcode was never registered OR the protocol
of the major opcode was never activated on the connection. By activated,
we mean that a <code class="function">ProtocolSetup</code> succeeded on the connection.
Note that ICE does not define how each sub-protocol triggers a
protocol shutdown.
</p></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a id="Processing_Messages"></a>Chapter 9. Processing Messages</h1></div></div></div><p>To process incoming messages on an ICE connection, use
<a class="xref" href="#IceProcessMessages"><code class="function">IceProcessMessages</code></a></p><div class="funcsynopsis"><a id="IceProcessMessages"></a><p><code class="funcdef">IceProcessMessagesStatus <strong class="fsfunc">IceProcessMessages</strong>(</code>IceConn<var class="pdparam"> ice_conn</var>, IceReplyWaitInfo<var class="pdparam"> *reply_wait</var>, Bool<var class="pdparam"> *reply_ready_ret</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>ice_conn</em></span></span></p></td><td><p>A valid ICE connection object.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>reply_wait</em></span></span></p></td><td><p>Indicates if a reply is being waited for.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>reply_ready_ret</em></span></span></p></td><td><p>
If set to <code class="function">True</code> on return, a reply is ready.
</p></td></tr></tbody></table></div><p>
<a class="xref" href="#IceProcessMessages"><code class="function">IceProcessMessages</code></a> is used in two ways:
</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
In the first, a client may generate a message and block by calling
<a class="xref" href="#IceProcessMessages"><code class="function">IceProcessMessages</code></a> repeatedly until it gets its reply.
</p></li><li class="listitem"><p>
In the second, a client calls <a class="xref" href="#IceProcessMessages"><code class="function">IceProcessMessages</code></a>
with reply_wait set to NULL in response to <code class="function">select</code>
showing that there is data to read on the ICE connection.
The ICE library may process zero or more complete messages.
Note that messages that are not blocked for are always processed by
invoking callbacks.
</p></li></ul></div><p>
<code class="function">IceReplyWaitInfo</code> contains the major/minor opcodes
and sequence number of the message for which a reply is being awaited.
It also contains a pointer to the reply message to be filled in (the
protocol library should cast this <code class="function">IcePointer</code>
to the appropriate reply type). In most
cases, the reply will have some fixed-size part, and the client waiting
for the reply will have provided a pointer to a structure to hold
this fixed-size data. If there is variable-length data, it would be
expected that the
<code class="function">IcePoProcessMsgProc</code>
callback will have to allocate additional
memory and store pointer(s) to that memory in the fixed-size
structure. If the entire data is variable length (for example, a single
variable-length string), then the client waiting for the reply would probably
just pass a pointer to fixed-size space to hold a pointer, and the
<code class="function">IcePoProcessMsgProc</code>
callback would allocate the storage and store the pointer.
It is the responsibility of the client receiving the reply to
free up any memory allocated on its behalf.
</p><pre class="literallayout">
typedef struct {
unsigned long sequence_of_request;
int major_opcode_of_request;
int minor_opcode_of_request;
IcePointer reply;
} IceReplyWaitInfo;
</pre><p>
If reply_wait is not NULL and
<a class="xref" href="#IceProcessMessages"><code class="function">IceProcessMessages</code></a>
has a reply or error to return in response to this reply_wait
(that is, no callback was generated), then the reply_ready_ret argument
will be set to <code class="function">True</code>
</p><p>
If reply_wait is NULL, then the caller may also pass NULL for
reply_ready_ret and be guaranteed that no value will be stored in
this pointer.
</p><p>
<a class="xref" href="#IceProcessMessages"><code class="function">IceProcessMessages</code></a> returns one of the following values:
</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
<code class="function">IceProcessMessagesSuccess</code> - no error occurred.
</p></li><li class="listitem"><p>
<code class="function">IceProcessMessagesIOError</code> - an IO error occurred,
and the caller must explicitly close the connection by calling
<a class="xref" href="#IceCloseConnection"><code class="function">IceCloseConnection</code></a>
</p></li><li class="listitem"><p>
<code class="function">IceProcessMessagesConnectionClosed</code>
- the ICE connection has been closed (closing of the connection was deferred
because of shutdown negotiation, or because the
<a class="xref" href="#IceProcessMessages"><code class="function">IceProcessMessages</code></a>
nesting level was not zero). Do not attempt
to access the ICE connection at this point, since it has been freed.
</p></li></ul></div></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a id="Ping"></a>Chapter 10. Ping</h1></div></div></div><p>
To send a "Ping" message to the client on the other side of the
ICE connection, use <a class="xref" href="#IcePing"><code class="function">IcePing</code></a>
</p><div class="funcsynopsis"><a id="IcePing"></a><p><code class="funcdef">Status <strong class="fsfunc">IcePing</strong>(</code>IceConn<var class="pdparam"> ice_conn</var>, IcePingReplyProc<var class="pdparam"> ping_reply_proc</var>, IcePointer<var class="pdparam"> client_data</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>ice_conn</em></span></span></p></td><td><p>A valid ICE connection object.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>ping_reply_proc</em></span></span></p></td><td><p>The callback to invoke when the Ping reply arrives.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>client_data</em></span></span></p></td><td><p>
This pointer will be passed to the <span class="olink"><code class="function">IcePingReplyProc</code></span>
callback.
</p></td></tr></tbody></table></div><p><a class="xref" href="#IcePing"><code class="function">IcePing</code></a>
returns zero for failure and a positive value for success.</p><p>When
<a class="xref" href="#IceProcessMessages"><code class="function">IceProcessMessages</code></a>
processes the Ping reply, it will invoke the
<span class="olink"><code class="function">IcePingReplyProc</code></span>
callback.</p><div class="funcsynopsis"><a id="PingReplyProc"></a><p><code class="funcdef">void <strong class="fsfunc">PingReplyProc</strong>(</code>IceConn<var class="pdparam"> ice_conn</var>, IcePointer<var class="pdparam"> client_data</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>ice_conn</em></span></span></p></td><td><p>A valid ICE connection object.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>client_data</em></span></span></p></td><td><p>The client data specified in the call to
<a class="xref" href="#IcePing"><code class="function">IcePing</code></a></p></td></tr></tbody></table></div></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a id="Using_ICElib_Informational_Functions"></a>Chapter 11. Using ICElib Informational Functions</h1></div></div></div><div class="funcsynopsis"><a id="IceConnectionStatus"></a><p><code class="funcdef">IceConnectStatus <strong class="fsfunc">IceConnectionStatus</strong>(</code>IceConn<var class="pdparam"> ice_conn</var><code>)</code>;</p></div><p><a class="xref" href="#IceConnectionStatus"><code class="function">IceConnectionStatus</code></a>
returns the status of an ICE connection. The possible return values are:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p><code class="function">IceConnectPending</code>
- the connection is not valid yet (that is, authentication is taking place).
This is only relevant to connections created by
<a class="xref" href="#IceAcceptConnection"><code class="function">IceAcceptConnection</code></a></p></li><li class="listitem"><p><code class="function">IceConnectAccepted</code>
- the connection has been accepted.
This is only relevant to connections created by
<a class="xref" href="#IceAcceptConnection"><code class="function">IceAcceptConnection</code></a></p></li><li class="listitem"><p><code class="function">IceConnectRejected</code>
- the connection had been rejected (that is, authentication failed).
This is only relevant to connections created by
<a class="xref" href="#IceAcceptConnection"><code class="function">IceAcceptConnection</code></a></p></li><li class="listitem"><p><code class="function">IceConnectIOError</code>
- an IO error has occurred on the connection.</p></li></ul></div><div class="funcsynopsis"><a id="IceVendor"></a><p><code class="funcdef">char <strong class="fsfunc"> *IceVendor</strong>(</code>IceConn<var class="pdparam"> ice_conn</var><code>)</code>;</p></div><p><code class="function">IceVendor</code>
returns the ICE library vendor identification
for the other side of the connection.
The string should be freed with a call to
<code class="function">free</code>
when no longer needed.</p><div class="funcsynopsis"><a id="IceRelease"></a><p><code class="funcdef">char <strong class="fsfunc"> *IceRelease</strong>(</code>IceConn<var class="pdparam"> ice_conn</var><code>)</code>;</p></div><p><code class="function">IceRelease</code>
returns the release identification of the ICE library
on the other side of the connection.
The string should be freed with a call to
<code class="function">free</code>
when no longer needed.</p><div class="funcsynopsis"><a id="IceProtocolVersion"></a><p><code class="funcdef">int <strong class="fsfunc"> IceProtocolVersion</strong>(</code>IceConn<var class="pdparam"> ice_conn</var><code>)</code>;</p></div><p><a class="xref" href="#IceProtocolVersion"><code class="function"> IceProtocolVersion</code></a>
returns the major version of the ICE protocol on this connection.</p><div class="funcsynopsis"><a id="IceProtocolRevision"></a><p><code class="funcdef">int <strong class="fsfunc"> IceProtocolRevision</strong>(</code>IceConn<var class="pdparam"> ice_conn</var><code>)</code>;</p></div><p><a class="xref" href="#IceProtocolRevision"><code class="function"> IceProtocolRevision</code></a>
returns the minor version of the ICE protocol on this connection.</p><div class="funcsynopsis"><p><code class="funcdef">int <strong class="fsfunc"> IceConnectionNumber</strong>(</code>IceConn<var class="pdparam"> ice_conn</var><code>)</code>;</p></div><p><code class="function">IceConnectionNumber</code>
returns the file descriptor of this ICE connection.</p><div class="funcsynopsis"><a id="IceConnectionString"></a><p><code class="funcdef">char <strong class="fsfunc"> *IceConnectionString</strong>(</code>IceConn<var class="pdparam"> ice_conn</var><code>)</code>;</p></div><p><code class="function">IceConnectionString</code>
returns the network ID of the client that
accepted this connection. The string should be freed with a call to
<code class="function">free</code>
when no longer needed.</p><div class="funcsynopsis"><a id="IceLastSentSequenceNumber"></a><p><code class="funcdef">unsigned long <strong class="fsfunc"> IceLastSentSequenceNumber</strong>(</code>IceConn<var class="pdparam"> ice_conn</var><code>)</code>;</p></div><p><a class="xref" href="#IceLastSentSequenceNumber"><code class="function"> IceLastSentSequenceNumber</code></a>
returns the sequence number of the last message sent on this ICE connection.</p><div class="funcsynopsis"><p><code class="funcdef">unsigned long <strong class="fsfunc"> IceLastReceivedSequenceNumber</strong>(</code>IceConn<var class="pdparam"> ice_conn</var><code>)</code>;</p></div><p><code class="function">IceLastReceivedSequenceNumber</code>
returns the sequence number of the last message received on this
ICE connection.</p><div class="funcsynopsis"><a id="IceSwapping"></a><p><code class="funcdef">Bool <strong class="fsfunc"> IceSwapping</strong>(</code>IceConn<var class="pdparam"> ice_conn</var><code>)</code>;</p></div><p><a class="xref" href="#IceSwapping"><code class="function"> IceSwapping</code></a>
returns
<code class="function">True</code>
if byte swapping is necessary when reading messages on the ICE connection.</p><div class="funcsynopsis"><a id="IceGetContext"></a><p><code class="funcdef">IcePointer <strong class="fsfunc"> IceGetContext</strong>(</code>IceConn<var class="pdparam"> ice_conn</var><code>)</code>;</p></div><p><a class="xref" href="#IceGetContext"><code class="function"> IceGetContext</code></a>
returns the context associated with a connection created by
<a class="xref" href="#IceOpenConnection"><code class="function">IceOpenConnection</code></a></p></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a id="ICE_Messages"></a>Chapter 12. ICE Messages</h1></div></div></div><div class="toc"><p><strong>Table of Contents</strong></p><dl class="toc"><dt><span class="sect1"><a href="#Sending_ICE_Messages">Sending ICE Messages</a></span></dt><dt><span class="sect1"><a href="#Reading_ICE_Messages">Reading ICE Messages</a></span></dt></dl></div><p>
All ICE messages have a standard 8-byte header. The ICElib macros that
read and write messages rely on the following naming convention for message
headers:
</p><pre class="literallayout">
CARD8 major_opcode;
CARD8 minor_opcode;
CARD8 data[2];
CARD32 length B32;
</pre><p>
The 3rd and 4th bytes of the message header can be used as needed.
The length field is specified in units of 8 bytes.
</p><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="Sending_ICE_Messages"></a>Sending ICE Messages</h2></div></div></div><p>
The ICE library maintains an output buffer used for generating messages.
Protocol libraries layered on top of ICE may choose to batch messages
together and flush the output buffer at appropriate times.
</p><p>
If an IO error has occurred on an ICE connection, all write operations
will be ignored. For further information, see
<a class="xref" href="#Error_Handling" title="Chapter 13. Error Handling"><em>Error Handling</em></a>.
</p><p>
To get the size of the ICE output buffer, use
<a class="xref" href="#IceGetOutBufSize"><code class="function"> IceGetOutBufSize</code></a>
</p><div class="funcsynopsis"><a id="IceGetOutBufSize"></a><p><code class="funcdef">int <strong class="fsfunc"> IceGetOutBufSize</strong>(</code>IceConn<var class="pdparam"> ice_conn</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>ice_conn</em></span></span></p></td><td><p>A valid ICE connection object.</p></td></tr></tbody></table></div><p>
To flush the ICE output buffer, use <a class="xref" href="#IceFlush"><code class="function"> IceFlush</code></a>
</p><div class="funcsynopsis"><a id="IceFlush"></a><p><code class="funcdef">int <strong class="fsfunc"> IceFlush</strong>(</code>IceConn<var class="pdparam"> ice_conn</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>ice_conn</em></span></span></p></td><td><p>A valid ICE connection object.</p></td></tr></tbody></table></div><p>
Note that the output buffer may be implicitly flushed if there is
insufficient space to generate a message.
</p><p>The following macros can be used to generate ICE messages:</p><div class="funcsynopsis"><a id="IceGetHeader"></a><p><code class="funcdef"><strong class="fsfunc"> IceGetHeader</strong>(</code>IceConn<var class="pdparam"> ice_conn</var>, int<var class="pdparam"> major_opcode</var>, int<var class="pdparam"> minor_opcode</var>, int<var class="pdparam"> header_size</var>, <C_data_type><var class="pdparam"> *pmsg</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>ice_conn</em></span></span></p></td><td><p>A valid ICE connection object.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>major_opcode</em></span></span></p></td><td><p>The major opcode of the message.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>minor_opcode</em></span></span></p></td><td><p>The minor opcode of the message.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>header_size</em></span></span></p></td><td><p>The size of the message header (in bytes).</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em><C_data_type></em></span></span></p></td><td><p>The actual C data type of the message header.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>pmsg</em></span></span></p></td><td><p>
The message header pointer. After this macro is called, the
library can store data in the message header.
</p></td></tr></tbody></table></div><p>
<a class="xref" href="#IceGetHeader"><code class="function"> IceGetHeader</code></a>
is used to set up a message header on an ICE connection.
It sets the major and minor opcodes of the message, and initializes
the message's length to the length of the header. If additional
variable length data follows, the message's length field should be
updated.
</p><div class="funcsynopsis"><a id="IceGetHeaderExtra"></a><p><code class="funcdef"><strong class="fsfunc"> IceGetHeaderExtra</strong>(</code>IceConn<var class="pdparam"> ice_conn</var>, int<var class="pdparam"> major_opcode</var>, int<var class="pdparam"> minor_opcode</var>, int<var class="pdparam"> header_size</var>, int<var class="pdparam"> extra</var>, <C_data_type><var class="pdparam"> *pmsg</var>, char<var class="pdparam"> *pdata</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>ice_conn</em></span></span></p></td><td><p>A valid ICE connection object.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>major_opcode</em></span></span></p></td><td><p>The major opcode of the message.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>minor_opcode</em></span></span></p></td><td><p>The minor opcode of the message.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>header_size</em></span></span></p></td><td><p>The size of the message header (in bytes).</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>extra</em></span></span></p></td><td><p>
The size of the extra data beyond the header (in 8-byte units).
</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em><C_data_type></em></span></span></p></td><td><p>The actual C data type of the message header.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>pmsg</em></span></span></p></td><td><p>
The message header pointer. After this macro is called, the
library can store data in the message header.
</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>pdata</em></span></span></p></td><td><p>
Returns a pointer to the ICE output buffer that points
immediately after the message header. The variable length
data should be stored here. If there was not enough room
in the ICE output buffer, pdata is set to NULL.
</p></td></tr></tbody></table></div><p>
<a class="xref" href="#IceGetHeaderExtra"><code class="function"> IceGetHeaderExtra</code></a>
is used to generate a message with a fixed (and relatively small) amount
of variable length data. The complete message must fit in the ICE output
buffer.
</p><div class="funcsynopsis"><a id="IceSimpleMessage"></a><p><code class="funcdef"><strong class="fsfunc"> IceSimpleMessage</strong>(</code>IceConn<var class="pdparam"> ice_conn</var>, int<var class="pdparam"> major_opcode</var>, int<var class="pdparam"> minor_opcode</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>ice_conn</em></span></span></p></td><td><p>A valid ICE connection object.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>major_opcode</em></span></span></p></td><td><p>The major opcode of the message.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>minor_opcode</em></span></span></p></td><td><p>The minor opcode of the message.</p></td></tr></tbody></table></div><p>
<a class="xref" href="#IceSimpleMessage"><code class="function"> IceSimpleMessage</code></a>
is used to generate a message that is identical
in size to the ICE header message, and has no additional data.
</p><div class="funcsynopsis"><a id="IceErrorHeader"></a><p><code class="funcdef"><strong class="fsfunc"> IceErrorHeader</strong>(</code>IceConn<var class="pdparam"> ice_conn</var>, int<var class="pdparam"> offending_major_opcode</var>, int<var class="pdparam"> offending_minor_opcode</var>, int<var class="pdparam"> offending_sequence_num</var>, int<var class="pdparam"> severity</var>, int<var class="pdparam"> error_class</var>, int<var class="pdparam"> data_length</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>ice_conn</em></span></span></p></td><td><p>A valid ICE connection object.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>offending_major_opcode</em></span></span></p></td><td><p>
The major opcode of the protocol in which an error was detected.
</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>offending_minor_opcode</em></span></span></p></td><td><p>
The minor opcode of the protocol in which an error was detected.
</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>offending_sequence_num</em></span></span></p></td><td><p>The sequence number of the message that caused the error.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>severity</em></span></span></p></td><td><p>
<code class="function">IceCanContinue</code>
<code class="function">IceFatalToProtocol</code>
or
<code class="function">IceFatalToConnection</code>
</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>error_class</em></span></span></p></td><td><p>The error class.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>data_length</em></span></span></p></td><td><p>
Length of data (in 8-byte units) to be written after the header.
</p></td></tr></tbody></table></div><p>
<a class="xref" href="#IceErrorHeader"><code class="function"> IceErrorHeader</code></a> sets up an error message header.
</p><p>
Note that the two clients connected by ICE may be using different
major opcodes for a given protocol. The offending_major_opcode passed
to this macro is the major opcode of the protocol for the client
sending the error message.
</p><p>
Generic errors, which are common to all protocols, have classes
in the range 0x8000..0xFFFF.
See the <span class="emphasis"><em>Inter-Client Exchange Protocol</em></span>
standard for more details.
</p><div class="informaltable"><table border="0"><colgroup><col align="left" class="c1" /><col align="left" class="c2" /></colgroup><tbody><tr><td align="left">IceBadMinor</td><td align="left">0x8000</td></tr><tr><td align="left">IceBadState</td><td align="left">0x8001</td></tr><tr><td align="left">IceBadLength</td><td align="left">0x8002</td></tr><tr><td align="left">IceBadValue</td><td align="left">0x8003</td></tr></tbody></table></div><p>Per-protocol errors have classes in the range 0x0000-0x7fff.</p><p>
To write data to an ICE connection, use the
<a class="xref" href="#IceWriteData"><code class="function"> IceWriteData</code></a> macro. If the data fits into the
ICE output buffer, it is copied there. Otherwise, the ICE output buffer
is flushed and the data is directly sent.
</p><p>
This macro is used in conjunction with
<a class="xref" href="#IceGetHeader"><code class="function"> IceGetHeader</code></a> and
<a class="xref" href="#IceErrorHeader"><code class="function"> IceErrorHeader</code></a>
</p><div class="funcsynopsis"><a id="IceWriteData"></a><p><code class="funcdef"><strong class="fsfunc"> IceWriteData</strong>(</code>IceConn<var class="pdparam"> ice_conn</var>, int<var class="pdparam"> bytes</var>, char<var class="pdparam"> *data</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>ice_conn</em></span></span></p></td><td><p>A valid ICE connection object.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>bytes</em></span></span></p></td><td><p>The number of bytes to write.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>data</em></span></span></p></td><td><p>The data to write.</p></td></tr></tbody></table></div><p>
To write data as 16-bit quantities, use <a class="xref" href="#IceWriteData16"><code class="function"> IceWriteData16</code></a>
</p><div class="funcsynopsis"><a id="IceWriteData16"></a><p><code class="funcdef"><strong class="fsfunc"> IceWriteData16</strong>(</code>IceConn<var class="pdparam"> ice_conn</var>, int<var class="pdparam"> bytes</var>, char<var class="pdparam"> *data</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>ice_conn</em></span></span></p></td><td><p>A valid ICE connection object.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>bytes</em></span></span></p></td><td><p>The number of bytes to write.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>data</em></span></span></p></td><td><p>The data to write.</p></td></tr></tbody></table></div><p>
To write data as 32-bit quantities, use <a class="xref" href="#IceWriteData32"><code class="function"> IceWriteData32</code></a>
</p><div class="funcsynopsis"><a id="IceWriteData32"></a><p><code class="funcdef"><strong class="fsfunc"> IceWriteData32</strong>(</code>IceConn<var class="pdparam"> ice_conn</var>, int<var class="pdparam"> bytes</var>, char<var class="pdparam"> *data</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>ice_conn</em></span></span></p></td><td><p>A valid ICE connection object.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>bytes</em></span></span></p></td><td><p>The number of bytes to write.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>data</em></span></span></p></td><td><p>The data to write.</p></td></tr></tbody></table></div><p>
To write data as 32-bit quantities, use <a class="xref" href="#IceWriteData32"><code class="function"> IceWriteData32</code></a>
</p><p>
To bypass copying data to the ICE output buffer, use
<a class="xref" href="#IceSendData"><code class="function"> IceSendData</code></a> to directly send data over the network
connection. If necessary, the ICE output buffer is first flushed.
</p><div class="funcsynopsis"><a id="IceSendData"></a><p><code class="funcdef"><strong class="fsfunc"> IceSendData</strong>(</code>IceConn<var class="pdparam"> ice_conn</var>, int<var class="pdparam"> bytes</var>, char<var class="pdparam"> *data</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>ice_conn</em></span></span></p></td><td><p>A valid ICE connection object.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>bytes</em></span></span></p></td><td><p>The number of bytes to send.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>data</em></span></span></p></td><td><p>The data to send.</p></td></tr></tbody></table></div><p>
To force 32-bit or 64-bit alignment, use <a class="xref" href="#IceWritePad"><code class="function"> IceWritePad</code></a>
A maximum of 7 pad bytes can be specified.
</p><div class="funcsynopsis"><a id="IceWritePad"></a><p><code class="funcdef"><strong class="fsfunc"> IceWritePad</strong>(</code>IceConn<var class="pdparam"> ice_conn</var>, int<var class="pdparam"> bytes</var>, char<var class="pdparam"> *data</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>ice_conn</em></span></span></p></td><td><p>A valid ICE connection object.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>bytes</em></span></span></p></td><td><p>The number of bytes to write.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>data</em></span></span></p></td><td><p>The number of pad bytes to write.</p></td></tr></tbody></table></div></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="Reading_ICE_Messages"></a>Reading ICE Messages</h2></div></div></div><p>
The ICE library maintains an input buffer used for reading messages.
If the ICE library chooses to perform nonblocking reads (this is
implementation-dependent), then for every read operation that it makes,
zero or more complete messages may be read into the input buffer. As
a result, for all of the macros described in this section that read
messages, an actual read operation will occur on the connection only if
the data is not already present in the input buffer.
</p><p>
To get the size of the ICE input buffer, use
<a class="xref" href="#IceGetInBufSize"><code class="function"> IceGetInBufSize</code></a>
</p><div class="funcsynopsis"><a id="IceGetInBufSize"></a><p><code class="funcdef">int<strong class="fsfunc"> IceGetInBufSize</strong>(</code>IceConn<var class="pdparam"> ice_conn</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>ice_conn</em></span></span></p></td><td><p>A valid ICE connection object.</p></td></tr></tbody></table></div><p>
When reading messages, care must be taken to check for IO errors. If
any IO error occurs in reading any part of a message, the message should
be thrown out. After using any of the macros described below for reading
messages, the <a class="xref" href="#IceValidIO"><code class="function"> IceValidIO</code></a>
macro can be used to check if an IO error occurred on the
connection. After an IO error has occurred on an ICE connection, all
read operations will be ignored. For further information, see
<a class="xref" href="#Error_Handling" title="Chapter 13. Error Handling"><em>Error Handling</em></a>.
</p><div class="funcsynopsis"><a id="IceValidIO"></a><p><code class="funcdef">Bool<strong class="fsfunc"> IceValidIO</strong>(</code>IceConn<var class="pdparam"> ice_conn</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>ice_conn</em></span></span></p></td><td><p>A valid ICE connection object.</p></td></tr></tbody></table></div><p>The following macros can be used to read ICE messages.</p><div class="funcsynopsis"><a id="IceReadSimpleMessage"></a><p><code class="funcdef"><strong class="fsfunc"> IceReadSimpleMessage</strong>(</code>IceConn<var class="pdparam"> ice_conn</var>, <C_data_type><var class="pdparam"> *pmsg</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>ice_conn</em></span></span></p></td><td><p>A valid ICE connection object.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em><C_data_type></em></span></span></p></td><td><p>The actual C data type of the message header.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>pmsg</em></span></span></p></td><td><p>This pointer is set to the message header.</p></td></tr></tbody></table></div><p>
<a class="xref" href="#IceReadSimpleMessage"><code class="function"> IceReadSimpleMessage</code></a>
is used for messages that are identical in size to the 8-byte ICE header, but
use the spare 2 bytes in the header to encode additional data. Note that the
ICE library always reads in these first 8 bytes, so it can obtain the major
opcode of the message. <a class="xref" href="#IceReadSimpleMessage"><code class="function"> IceReadSimpleMessage</code></a>
simply returns a pointer to these 8 bytes; it does not actually read any data
into the input buffer.
</p><p>
For a message with variable length data, there are two ways of reading
the message. One method involves reading the complete message in one
pass using <a class="xref" href="#IceReadCompleteMessage"><code class="function"> IceReadCompleteMessage</code></a>
The second method involves reading the message header (note that this may
be larger than the 8-byte ICE header), then reading
the variable length data in chunks (see
<a class="xref" href="#IceReadMessageHeader"><code class="function"> IceReadMessageHeader</code></a> and
<a class="xref" href="#IceReadData"><code class="function"> IceReadData</code></a>
</p><div class="funcsynopsis"><a id="IceReadCompleteMessage"></a><p><code class="funcdef"><strong class="fsfunc"> IceReadCompleteMessage</strong>(</code>IceConn<var class="pdparam"> ice_conn</var>, int<var class="pdparam"> header_size</var>, <C_data_type><var class="pdparam"> *pmsg</var>, char<var class="pdparam"> *pdata</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>ice_conn</em></span></span></p></td><td><p>A valid ICE connection object.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>header_size</em></span></span></p></td><td><p>The size of the message header (in bytes).</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em><C_data_type></em></span></span></p></td><td><p>The actual C data type of the message header.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>pmsg</em></span></span></p></td><td><p>This pointer is set to the message header.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>pdata</em></span></span></p></td><td><p>
This pointer is set to the variable length data of the message.
</p></td></tr></tbody></table></div><p>
If the ICE input buffer has sufficient space,
<a class="xref" href="#IceReadCompleteMessage"><code class="function"> IceReadCompleteMessage</code></a>
will read the complete message into the
ICE input buffer. Otherwise, a buffer will be allocated to hold the
variable length data. After the call, the pdata argument should
be checked against NULL to make sure that there was sufficient memory
to allocate the buffer.
</p><p>
After calling <a class="xref" href="#IceReadCompleteMessage"><code class="function"> IceReadCompleteMessage</code></a>
and processing the message, <a class="xref" href="#IceDisposeCompleteMessage"><code class="function"> IceDisposeCompleteMessage</code></a>
should be called.
</p><div class="funcsynopsis"><a id="IceDisposeCompleteMessage"></a><p><code class="funcdef"><strong class="fsfunc"> IceDisposeCompleteMessage</strong>(</code>IceConn<var class="pdparam"> ice_conn</var>, char<var class="pdparam"> *pdata</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>ice_conn</em></span></span></p></td><td><p>A valid ICE connection object.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>pdata</em></span></span></p></td><td><p>
The pointer to the variable length data returned in
<a class="xref" href="#IceReadCompleteMessage"><code class="function"> IceReadCompleteMessage</code></a>
</p></td></tr></tbody></table></div><p>
If a buffer had to be allocated to hold the variable length data (because
it did not fit in the ICE input buffer), it is freed here by ICElib.
</p><div class="funcsynopsis"><a id="IceReadMessageHeader"></a><p><code class="funcdef"><strong class="fsfunc"> IceReadMessageHeader</strong>(</code>IceConn<var class="pdparam"> ice_conn</var>, int<var class="pdparam"> header_size</var>, <C_data_type><var class="pdparam"> *pmsg</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>ice_conn</em></span></span></p></td><td><p>A valid ICE connection object.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>header_size</em></span></span></p></td><td><p>The size of the message header (in bytes).</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em><C_data_type></em></span></span></p></td><td><p>The actual C data type of the message header.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>pmsg</em></span></span></p></td><td><p>This pointer is set to the message header.</p></td></tr></tbody></table></div><p>
<a class="xref" href="#IceReadMessageHeader"><code class="function"> IceReadMessageHeader</code></a> reads just the message header.
The rest of the data should be read with the
<a class="xref" href="#IceReadData"><code class="function"> IceReadData</code></a>
family of macros. This method of reading a message should be used when the
variable length data must be read in chunks.
</p><p>
To read data directly into a user supplied buffer, use
<a class="xref" href="#IceReadData"><code class="function"> IceReadData</code></a>
</p><div class="funcsynopsis"><a id="IceReadData"></a><p><code class="funcdef"><strong class="fsfunc"> IceReadData</strong>(</code>IceConn<var class="pdparam"> ice_conn</var>, int<var class="pdparam"> bytes</var>, char<var class="pdparam"> *pdata</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>ice_conn</em></span></span></p></td><td><p>A valid ICE connection object.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>bytes</em></span></span></p></td><td><p>The number of bytes to read.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>pdata</em></span></span></p></td><td><p>The data is read into this user supplied buffer.</p></td></tr></tbody></table></div><p>
To read data as 16-bit quantities, use <a class="xref" href="#IceReadData16"><code class="function"> IceReadData16</code></a>
</p><div class="funcsynopsis"><a id="IceReadData16"></a><p><code class="funcdef"><strong class="fsfunc"> IceReadData16</strong>(</code>IceConn<var class="pdparam"> ice_conn</var>, Bool<var class="pdparam"> swap</var>, int<var class="pdparam"> bytes</var>, char<var class="pdparam"> *pdata</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>ice_conn</em></span></span></p></td><td><p>A valid ICE connection object.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>swap</em></span></span></p></td><td><p>
If <code class="function">True,</code> the values will be byte swapped.
</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>bytes</em></span></span></p></td><td><p>The number of bytes to read.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>pdata</em></span></span></p></td><td><p>The data is read into this user supplied buffer.</p></td></tr></tbody></table></div><p>
To read data as 32-bit quantities, use <a class="xref" href="#IceReadData32"><code class="function"> IceReadData32</code></a>
</p><div class="funcsynopsis"><a id="IceReadData32"></a><p><code class="funcdef"><strong class="fsfunc"> IceReadData32</strong>(</code>IceConn<var class="pdparam"> ice_conn</var>, Bool<var class="pdparam"> swap</var>, int<var class="pdparam"> bytes</var>, char<var class="pdparam"> *pdata</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>ice_conn</em></span></span></p></td><td><p>A valid ICE connection object.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>swap</em></span></span></p></td><td><p>
If <code class="function">True,</code> the values will be byte swapped.
</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>bytes</em></span></span></p></td><td><p>The number of bytes to read.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>pdata</em></span></span></p></td><td><p>The data is read into this user supplied buffer.</p></td></tr></tbody></table></div><p>To force 32-bit or 64-bit alignment, use
<a class="xref" href="#IceReadPad"><code class="function"> IceReadPad</code></a>
A maximum of 7 pad bytes can be specified.</p><div class="funcsynopsis"><a id="IceReadPad"></a><p><code class="funcdef"><strong class="fsfunc"> IceReadPad</strong>(</code>IceConn<var class="pdparam"> ice_conn</var>, int<var class="pdparam"> bytes</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>ice_conn</em></span></span></p></td><td><p>A valid ICE connection object.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>bytes</em></span></span></p></td><td><p>The number of pad bytes.</p></td></tr></tbody></table></div></div></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a id="Error_Handling"></a>Chapter 13. Error Handling</h1></div></div></div><p>There are two default error handlers in ICElib:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
One to handle typically fatal conditions (for example,
a connection dying because a machine crashed)
</p></li><li class="listitem"><p>One to handle ICE-specific protocol errors</p></li></ul></div><p>
These error handlers can be changed to user-supplied routines if you
prefer your own error handling and can be changed as often as you like.
</p><p>
To set the ICE error handler, use <a class="xref" href="#IceSetErrorHandler"><code class="function"> IceSetErrorHandler</code></a>
</p><div class="funcsynopsis"><a id="IceSetErrorHandler"></a><p><code class="funcdef"><strong class="fsfunc"> IceSetErrorHandler</strong>(</code>IceConn<var class="pdparam"> ice_conn</var>, int<var class="pdparam"> bytes</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>handler</em></span></span></p></td><td><p>
The ICE error handler. You should pass NULL to restore the default handler.
</p></td></tr></tbody></table></div><p>
<a class="xref" href="#IceSetErrorHandler"><code class="function"> IceSetErrorHandler</code></a> returns the previous error handler.
</p><p>
The ICE error handler is invoked when an unexpected ICE protocol
error (major opcode 0) is encountered. The action of the default
handler is to print an explanatory message to
<code class="function">stderr</code>
and if the severity is fatal, call
<code class="function">exit</code>
with a nonzero value. If exiting
is undesirable, the application should register its own error handler.
</p><p>
Note that errors in other protocol
domains should be handled by their respective libraries (these libraries
should have their own error handlers).
</p><p>
An ICE error handler has the type of <a class="xref" href="#IceErrorHandler"><code class="function"> IceErrorHandler</code></a>
</p><div class="funcsynopsis"><a id="IceErrorHandler"></a><p><code class="funcdef">void<strong class="fsfunc"> IceErrorHandler</strong>(</code>IceConn<var class="pdparam"> ice_conn</var>, Bool<var class="pdparam"> swap</var>, int<var class="pdparam"> offending_minor_opcode</var>, unsigned long<var class="pdparam"> offending_sequence_num</var>, int<var class="pdparam"> error_class</var>, int<var class="pdparam"> severity</var>, IcePointer<var class="pdparam"> values</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>handler</em></span></span></p></td><td><p>The ICE connection object.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>swap</em></span></span></p></td><td><p>A flag that indicates if the values need byte swapping.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>offending_minor_opcode</em></span></span></p></td><td><p>The ICE minor opcode of the offending message.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>offending_sequence_num</em></span></span></p></td><td><p>The sequence number of the offending message.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>error_class</em></span></span></p></td><td><p>The error class of the offending message.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>severity</em></span></span></p></td><td><p>
<code class="function">IceCanContinue</code>
<code class="function">IceFatalToProtocol</code>
or
<code class="function">IceFatalToConnection</code>
</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>values</em></span></span></p></td><td><p>
Any additional error values specific to the minor opcode and class.
</p></td></tr></tbody></table></div><p>The following error classes are defined at the ICE level:</p><div class="literallayout"><p><br />
<code class="function">IceBadMinor</code><br />
<code class="function">IceBadState</code><br />
<code class="function">IceBadLength</code><br />
<code class="function">IceBadValue</code><br />
<code class="function">IceBadMajor</code><br />
<code class="function">IceNoAuth</code><br />
<code class="function">IceNoVersion</code><br />
<code class="function">IceSetupFailed</code><br />
<code class="function">IceAuthRejected</code><br />
<code class="function">IceAuthFailed</code><br />
<code class="function">IceProtocolDuplicate</code><br />
<code class="function">IceMajorOpcodeDuplicate</code><br />
<code class="function">IceUnknownProtocol</code><br />
</p></div><p>
For further information, see
the <span class="emphasis"><em>Inter-Client Exchange Protocol</em></span> standard.
</p><p>
To handle fatal I/O errors, use <a class="xref" href="#IceSetIOErrorHandler"><code class="function"> IceSetIOErrorHandler</code></a>
</p><div class="funcsynopsis"><a id="IceSetIOErrorHandler"></a><p><code class="funcdef">IceIOErrorHandler<strong class="fsfunc"> IceSetIOErrorHandler</strong>(</code>IceIOErrorHandler<var class="pdparam"> handler</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>handler</em></span></span></p></td><td><p>
The I/O error handler. You should pass NULL to restore the default handler.
</p></td></tr></tbody></table></div><p>
<a class="xref" href="#IceSetIOErrorHandler"><code class="function"> IceSetIOErrorHandler</code></a> returns the previous
IO error handler.
</p><p>
An ICE I/O error handler has the type of
<a class="xref" href="#IceIOErrorHandler"><code class="function"> IceIOErrorHandler</code></a>
</p><div class="funcsynopsis"><a id="IceIOErrorHandler"></a><p><code class="funcdef">void<strong class="fsfunc"> IceIOErrorHandler</strong>(</code>IceConn<var class="pdparam"> ice_conn</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>ice_conn</em></span></span></p></td><td><p>The ICE connection object.</p></td></tr></tbody></table></div><p> There are two ways of handling IO errors in ICElib:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
In the first, the IO error handler does whatever is necessary
to respond to the IO error and then returns, but it does not call
<a class="xref" href="#IceCloseConnection"><code class="function">IceCloseConnection</code></a>
The ICE connection is given a "bad IO" status, and all future reads
and writes to the connection are ignored. The next time
<a class="xref" href="#IceProcessMessages"><code class="function">IceProcessMessages</code></a>
is called it will return a status of
<code class="function">IceProcessMessagesIOError</code>
At that time, the application should call
<a class="xref" href="#IceCloseConnection"><code class="function">IceCloseConnection</code></a>
</p></li><li class="listitem"><p>
In the second, the IO error handler does call
<a class="xref" href="#IceCloseConnection"><code class="function">IceCloseConnection</code></a>
and then uses the <code class="function">longjmp</code>
call to get back to the application's main event loop. The
<code class="function">setjmp</code> and
<code class="function">longjmp</code>
calls may not work properly on all platforms,
and special care must be taken to avoid memory leaks.
Therefore, this second model is less desirable.
</p></li></ul></div><p>
Before the application I/O error handler is invoked, protocol libraries
that were interested in being notified of I/O errors will have their
<a class="xref" href="#IceIOErrorProc"><code class="function"> IceIOErrorProc</code></a>
handlers invoked. This handler is set up in the protocol registration
functions (see <a class="xref" href="#IceRegisterForProtocolSetup"><code class="function">IceRegisterForProtocolSetup</code></a> and
<a class="xref" href="#IceRegisterForProtocolReply"><code class="function">IceRegisterForProtocolReply</code></a>
and could be used to clean up state specific to the protocol.
</p><div class="funcsynopsis"><a id="IceIOErrorProc"></a><p><code class="funcdef">void<strong class="fsfunc"> IceIOErrorProc</strong>(</code>IceConn<var class="pdparam"> ice_conn</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>ice_conn</em></span></span></p></td><td><p>The ICE connection object.</p></td></tr></tbody></table></div><p>
Note that every <a class="xref" href="#IceIOErrorProc"><code class="function"> IceIOErrorProc</code></a>
callback must return. This is required
because each active protocol must be notified of the broken connection,
and the application IO error handler must be invoked afterwards.
</p></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a id="Multi_Threading_Support"></a>Chapter 14. Multi-Threading Support</h1></div></div></div><p>To declare that multiple threads in an application will be using the ICE
library, use
<code class="function">IceInitThreads</code></p><div class="literallayout"><p><br />
Status IceInitThreads()<br />
</p></div><p>The
<code class="function">IceInitThreads</code>
function must be the first ICElib function a
multi-threaded program calls. It must complete before any other ICElib
call is made.
<code class="function">IceInitThreads</code>
returns a nonzero status if and only if it was able
to initialize the threads package successfully.
It is safe to call
<code class="function">IceInitThreads</code>
more than once, although the threads package will only be initialized once.</p><p>Protocol libraries layered on top of ICElib will have to lock critical
sections of code that access an ICE connection (for example, when
generating messages). Two calls, which are generally implemented as
macros, are provided:</p><div class="funcsynopsis"><a id="IceLockConn"></a><p><code class="funcdef">void<strong class="fsfunc"> IceLockConn</strong>(</code>IceConn<var class="pdparam"> ice_conn</var><code>)</code>;</p></div><div class="funcsynopsis"><a id="IceUnlockConn"></a><p><code class="funcdef">void<strong class="fsfunc"> IceUnlockConn</strong>(</code>IceConn<var class="pdparam"> ice_conn</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>ice_conn</em></span></span></p></td><td><p>The ICE connection object.</p></td></tr></tbody></table></div><p>To keep an ICE connection locked across several ICElib calls, applications use
<a class="xref" href="#IceAppLockConn"><code class="function"> IceAppLockConn</code></a>
and
<a class="xref" href="#IceAppUnlockConn"><code class="function"> IceAppUnlockConn</code></a></p><div class="funcsynopsis"><a id="IceAppLockConn"></a><p><code class="funcdef">void<strong class="fsfunc"> IceAppLockConn</strong>(</code>IceConn<var class="pdparam"> ice_conn</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>ice_conn</em></span></span></p></td><td><p>The ICE connection object.</p></td></tr></tbody></table></div><p>The
<a class="xref" href="#IceAppLockConn"><code class="function"> IceAppLockConn</code></a>
function completely locks out other threads using the connection
until
<a class="xref" href="#IceAppUnlockConn"><code class="function"> IceAppUnlockConn</code></a>
is called. Other threads attempting to use ICElib
calls on the connection will block.
If the program has not previously called
<code class="function">IceInitThreads</code>
<a class="xref" href="#IceAppLockConn"><code class="function"> IceAppLockConn</code></a>
has no effect.</p><div class="funcsynopsis"><a id="IceAppUnlockConn"></a><p><code class="funcdef">void<strong class="fsfunc"> IceAppUnlockConn</strong>(</code>IceConn<var class="pdparam"> ice_conn</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>ice_conn</em></span></span></p></td><td><p>The ICE connection object.</p></td></tr></tbody></table></div><p>The
<a class="xref" href="#IceAppUnlockConn"><code class="function"> IceAppUnlockConn</code></a>
function allows other threads to complete ICElib
calls on the connection that were blocked by a previous call to
<a class="xref" href="#IceAppLockConn"><code class="function"> IceAppLockConn</code></a>
from this thread. If the program has not previously called
<code class="function">IceInitThreads</code>
<a class="xref" href="#IceAppUnlockConn"><code class="function"> IceAppUnlockConn</code></a>
has no effect.</p></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a id="Miscellaneous_Functions"></a>Chapter 15. Miscellaneous Functions</h1></div></div></div><p>To allocate scratch space (for example, when generating
messages with variable data), use
<code class="function">IceAllocScratch</code>
Each ICE connection has one scratch space associated with it.
The scratch space starts off as empty and grows as needed.
The contents of the scratch space is not guaranteed to be preserved
after any ICElib function is called.</p><div class="funcsynopsis"><a id="IceAllocScratch"></a><p><code class="funcdef">char<strong class="fsfunc"> *IceAllocScratch</strong>(</code>IceConn<var class="pdparam"> ice_conn</var>, unsigned long<var class="pdparam"> size</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>ice_conn</em></span></span></p></td><td><p>The ICE connection object.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>size</em></span></span></p></td><td><p>The number of bytes required.</p></td></tr></tbody></table></div><p>Note that the memory returned by
<code class="function">IceAllocScratch</code>
should not be freed by the caller.
The ICE library will free the memory when the ICE connection is closed.</p></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a id="Acknowledgements"></a>Chapter 16. Acknowledgements</h1></div></div></div><p>
Thanks to Bob Scheifler for his thoughtful input on the design
of the ICE library. Thanks also to Jordan Brown, Larry Cable, Donna Converse,
Clive Feather, Stephen Gildea, Vania Joloboff, Kaleb Keithley,
Stuart Marks, Hiro Miyamoto, Ralph Swick, Jim VanGilder, and Mike Wexler.
</p></div><div class="appendix"><div class="titlepage"><div><div><h1 class="title"><a id="authentication_utility_functions"></a>Appendix A. Authentication Utility Functions</h1></div></div></div><p>
As discussed in this document, the means by which authentication data
is obtained by the ICE library (for
<code class="function">ConnectionSetup</code>
messages or
<code class="function">ProtocolSetup</code>
messages) is implementation-dependent.†
<a href="#ftn.idp56976128" class="footnote" id="idp56976128"><sup class="footnote">[2]</sup></a>
</p><p>
This appendix describes some utility functions that manipulate an
ICE authority file. The authority file can be used to pass authentication
data between clients.
</p><p>The basic operations on the .ICEauthority file are:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>Get file name</p></li><li class="listitem"><p>Lock</p></li><li class="listitem"><p>Unlock</p></li><li class="listitem"><p>Read entry</p></li><li class="listitem"><p>Write entry</p></li><li class="listitem"><p>Search for entry</p></li></ul></div><p>
These are fairly low-level operations, and it is expected that a program,
like "iceauth", would exist to add, remove, and display entries in the file.
</p><p>
In order to use these utility functions, the
<<span class="symbol">X11/ICE/ICEutil.h</span>>
header file must be included.
</p><p>
An entry in the .ICEauthority file is defined by the following data structure:
</p><pre class="literallayout">
typedef struct {
char *protocol_name;
unsigned short protocol_data_length;
char *protocol_data;
char *network_id;
char *auth_name;
unsigned short auth_data_length;
char *auth_data;
} IceAuthFileEntry;
</pre><p>
The protocol_name member is either "ICE" for connection setup authentication
or the subprotocol name, such as "XSMP". For each entry, protocol specific
data can be specified in the protocol_data member. This can be used
to search for old entries that need to be removed from the file.
</p><p>
The network_id member is the network ID of the client accepting
authentication (for example, the network ID of a session manager).
A network ID has the following form:
</p><div class="informaltable"><table border="0"><colgroup><col align="left" class="c1" /><col align="left" class="c2" /></colgroup><tbody><tr><td align="left">tcp/<hostname>:<portnumber></td><td align="left">or</td></tr><tr><td align="left">decnet/<hostname>::<objname></td><td align="left">or</td></tr><tr><td align="left">local/<hostname>:<path></td><td align="left"> </td></tr></tbody></table></div><p>
The auth_name member is the name of the authentication method.
The auth_data member is the actual authentication data,
and the auth_data_length member is the number of bytes in the data.
</p><p>
To obtain the default authorization file name, use
<code class="function">IceAuthFileName</code>
</p><div class="literallayout"><p><br />
char *IceAuthFileName()<br />
</p></div><p>
If the ICEAUTHORITY environment variable if set, this value is returned.
Otherwise, the default authorization file name is $HOME/.ICEauthority.
This name is statically allocated and should not be freed.
</p><p>
To synchronously update the authorization file, the file must
be locked with a call to
<a class="xref" href="#IceLockAuthFile"><code class="function"> IceLockAuthFile</code></a>
This function takes advantage of the fact that the
<code class="function">link</code>
system call will fail if the name of the new link already exists.
</p><div class="funcsynopsis"><a id="IceLockAuthFile"></a><p><code class="funcdef">int<strong class="fsfunc"> IceLockAuthFile</strong>(</code>char<var class="pdparam"> *file_name</var>, int<var class="pdparam"> retries</var>, int<var class="pdparam"> timeout</var>, long<var class="pdparam"> dead</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>file_name</em></span></span></p></td><td><p>The authorization file to lock.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>retries</em></span></span></p></td><td><p>The number of retries.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>timeout</em></span></span></p></td><td><p>The number of seconds before each retry.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>dead</em></span></span></p></td><td><p>
If a lock already exists that is the specified dead seconds old,
it is broken.
A value of zero is used to unconditionally break an old lock.
</p></td></tr></tbody></table></div><p>One of three values is returned:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
<code class="function">IceAuthLockSuccess</code> - the lock succeeded.
</p></li><li class="listitem"><p>
<code class="function">IceAuthLockError</code> - a system error occurred, and
<code class="function">errno</code> may prove useful.
</p></li><li class="listitem"><p>
<code class="function">IceAuthLockTimeout</code> - the specified number of
retries failed.
</p></li></ul></div><p>
To unlock an authorization file, use <a class="xref" href="#IceUnlockAuthFile"><code class="function"> IceUnlockAuthFile</code></a>
</p><div class="funcsynopsis"><a id="IceUnlockAuthFile"></a><p><code class="funcdef">int<strong class="fsfunc"> IceUnlockAuthFile</strong>(</code>char<var class="pdparam"> *file_name</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>file_name</em></span></span></p></td><td><p>The authorization file to unlock.</p></td></tr></tbody></table></div><p>
To read the next entry in an authorization file, use
<code class="function">IceReadAuthFileEntry</code>
</p><div class="funcsynopsis"><a id="IceReadAuthFileEntry"></a><p><code class="funcdef">IceAuthFileEntry<strong class="fsfunc"> *IceReadAuthFileEntry</strong>(</code>FILE<var class="pdparam"> *auth_file</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>auth_file</em></span></span></p></td><td><p>The authorization file.</p></td></tr></tbody></table></div><p>
Note that it is the responsibility of the application to open the file
for reading before calling this function. If an error is encountered,
or there are no more entries to read, NULL is returned.
</p><p>
Entries should be free with a call to
<a class="xref" href="#IceFreeAuthFileEntry"><code class="function"> IceFreeAuthFileEntry</code></a>
</p><p>
To write an entry in an authorization file, use
<a class="xref" href="#IceWriteAuthFileEntry"><code class="function"> IceWriteAuthFileEntry</code></a>
</p><div class="funcsynopsis"><a id="IceWriteAuthFileEntry"></a><p><code class="funcdef">Status<strong class="fsfunc"> IceWriteAuthFileEntry</strong>(</code>FILE<var class="pdparam"> *auth_file</var>, IceAuthFileEntry<var class="pdparam"> *entry</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>auth_file</em></span></span></p></td><td><p>The authorization file.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>entry</em></span></span></p></td><td><p>The entry to write.</p></td></tr></tbody></table></div><p>
Note that it is the responsibility of the application to open the file
for writing before calling this function. The function returns a nonzero
status if the operation was successful.
</p><p>
To search the default authorization file for an entry that matches a given
protocol_name/network_id/auth_name tuple, use
<code class="function">IceGetAuthFileEntry</code>
</p><div class="funcsynopsis"><a id="IceGetAuthFileEntry"></a><p><code class="funcdef">IceAuthFileEntry<strong class="fsfunc"> *IceGetAuthFileEntry</strong>(</code>const char *<var class="pdparam">protocol_name</var>, const char *<var class="pdparam">network_id</var>, const char *<var class="pdparam">auth_name</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>auth_file</em></span></span></p></td><td><p>The name of the protocol to search on.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>network_id</em></span></span></p></td><td><p>The network ID to search on.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>auth_name</em></span></span></p></td><td><p>The authentication method to search on.</p></td></tr></tbody></table></div><p>
If <code class="function">IceGetAuthFileEntry</code>
fails to find such an entry, NULL is returned.
</p><p>
To free an entry returned by
<code class="function">IceReadAuthFileEntry</code> or
<code class="function">IceGetAuthFileEntry</code> use
<a class="xref" href="#IceFreeAuthFileEntry"><code class="function"> IceFreeAuthFileEntry</code></a>
</p><div class="funcsynopsis"><a id="IceFreeAuthFileEntry"></a><p><code class="funcdef">void<strong class="fsfunc"> IceFreeAuthFileEntry</strong>(</code>IceAuthFileEntry<var class="pdparam"> *entry</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>entry</em></span></span></p></td><td><p>The entry to free.</p></td></tr></tbody></table></div><div class="footnotes"><br /><hr style="width:100; text-align:left;margin-left: 0" /><div id="ftn.idp56976128" class="footnote"><p><a href="#idp56976128" class="para"><sup class="para">[2] </sup></a>The X Consortium's ICElib implementation assumes the presence of an
ICE authority file.
</p></div></div></div><div class="appendix"><div class="titlepage"><div><div><h1 class="title"><a id="mit_magic_cookie_1_authentication"></a>Appendix B. MIT-MAGIC-COOKIE-1 Authentication</h1></div></div></div><p>The X Consortium's ICElib implementation supports a simple
MIT-MAGIC-COOKIE-1 authentication scheme using the authority file utilities
described in Appendix A.</p><p>In this model, an application, such as a session manager, obtains a
magic cookie by calling
<code class="function">IceGenerateMagicCookie</code>
and then stores it in the user's local .ICEauthority file
so that local clients can connect. In order to allow remote clients to
connect, some remote execution mechanism should be used to store the
magic cookie in the user's .ICEauthority file on a remote machine.</p><p>In addition to storing the magic cookie in the .ICEauthority file, the
application needs to call the
<a class="xref" href="#IceSetPaAuthData"><code class="function"> IceSetPaAuthData</code></a>
function in order to store the magic cookie in memory. When it comes time
for the MIT-MAGIC-COOKIE-1 authentication procedure to accept or reject the
connection, it will compare the magic cookie presented by the requestor to
the magic cookie in memory.</p><div class="funcsynopsis"><a id="IceGenerateMagicCookie"></a><p><code class="funcdef">char<strong class="fsfunc"> *IceGenerateMagicCookie</strong>(</code>int<var class="pdparam"> length</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>length</em></span></span></p></td><td><p>The desired length of the magic cookie.</p></td></tr></tbody></table></div><p>The magic cookie returned will be null-terminated. If memory can not be
allocated for the magic cookie, the function will return NULL.
Otherwise, the magic cookie should be freed with a call to
<code class="function">free</code></p><p>To store the authentication data in memory, use
<a class="xref" href="#IceSetPaAuthData"><code class="function"> IceSetPaAuthData</code></a>
Currently, this function is only used for MIT-MAGIC-COOKIE-1
authentication, but it may be used for additional authentication
methods in the future.</p><div class="funcsynopsis"><a id="IceSetPaAuthData"></a><p><code class="funcdef">void<strong class="fsfunc"> IceSetPaAuthData</strong>(</code>int<var class="pdparam"> num_entries</var>, IceAuthDataEntry<var class="pdparam"> *entries</var><code>)</code>;</p></div><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top" /><col /></colgroup><tbody><tr><td><p><span class="term"><span class="emphasis"><em>num_entries</em></span></span></p></td><td><p>The number of authentication data entries.</p></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>entries</em></span></span></p></td><td><p>The list of authentication data entries.</p></td></tr></tbody></table></div><p>Each entry has associated with it a protocol name
(for example, "ICE" for ICE connection setup authentication,
"XSMP" for session management authentication), a network ID for the
"accepting" client, an authentication name (for example, MIT-MAGIC-COOKIE-1),
and authentication data. The ICE library
will merge these entries with previously set entries, based on the
(protocol_name, network_id, auth_name) tuple.</p><pre class="literallayout">
typedef struct {
char *protocol_name;
char *network_id;
char *auth_name;
unsigned short auth_data_length;
char *auth_data;
} IceAuthDataEntry;
</pre></div></div></body></html>
|