ICElib.xml revision d17cd367
1<?xml version="1.0" encoding="UTF-8" ?> 2<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN" 3 "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd"> 4 5 6 7<book id="icelib"> 8 9<bookinfo> 10 <title>Inter-Client Exchange Library</title> 11 <subtitle>X Consortium Standard</subtitle> 12 <releaseinfo>X Version 11, Release 6.4</releaseinfo> 13 <authorgroup> 14 <author> 15 <firstname>Ralph</firstname><surname>Mor</surname> 16 <affiliation><orgname>X Consortium</orgname></affiliation> 17 </author> 18 </authorgroup> 19 <corpname>X Consortium Standard</corpname> 20 <copyright><year>1993</year><holder>X Consortium</holder></copyright> 21 <copyright><year>1994</year><holder>X Consortium</holder></copyright> 22 <copyright><year>1996</year><holder>X Consortium</holder></copyright> 23 <revhistory><revision><revnumber>1.0</revnumber><date></date></revision></revhistory> 24 25<legalnotice> 26<para> 27Permission is hereby granted, free of charge, to any person obtaining a copy 28of this software and associated documentation files (the 29"Software"), to deal in the Software without restriction, 30including without limitation the rights to use, copy, modify, merge, 31publish, distribute, sublicense, and/or sell copies of the Software, and 32to permit persons to whom the Software is furnished to do so, subject to 33the following conditions: 34</para> 35 36<para>The above copyright notice and this permission notice shall be 37included in all copies or substantial portions of the Software. 38</para> 39 40<para> 41THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 42IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 43FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 44X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 45AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 46CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 47</para> 48 49<para> 50Except as contained in this notice, the name of the X Consortium shall not be 51used in advertising or otherwise to promote the sale, use or other dealings 52in this Software without prior written authorization from the X Consortium. 53</para> 54 55</legalnotice> 56</bookinfo> 57 58<chapter id='overview_of_ice'> 59<title>Overview of ICE</title> 60 61<para> 62There are numerous possible inter-client protocols, with many similarities 63and common needs - authentication, version negotiation, byte 64order negotiation, and so on. 65The Inter-Client Exchange (ICE) protocol is intended to provide a framework 66for building such protocols, allowing them to make use of common negotiation 67mechanisms and to be multiplexed over a single transport connection. 68</para> 69</chapter> 70 71<chapter id='the_ice_library__c_language_interface_to'> 72<title>The ICE Library - C Language Interface to ICE</title> 73 74<para> 75A client that wishes to utilize ICE must first register the protocols it 76understands with the ICE library. Each protocol is dynamically assigned 77a major opcode ranging from 1-255 (two clients can use different 78major opcodes for the same protocol). The next step for the client is either 79to open a connection with another client or to wait for connections made 80by other clients. Authentication may be required. A client can both 81initiate connections with other clients and be 82waiting for clients to connect to itself (a nested session manager is an 83example). Once an ICE connection is established between the two clients, one 84of the clients needs to initiate a 85<function>ProtocolSetup</function> 86in order to 87"activate" a given protocol. Once the other client accepts the 88<function>ProtocolSetup</function> 89(once again, authentication may be required), the 90two clients are ready to start passing messages specific to that protocol to 91each other. Multiple protocols may be active on a single ICE connection. 92Clients are responsible for notifying the ICE library when a protocol is no 93longer active on an ICE connection, although ICE does not define how each 94subprotocol triggers a protocol shutdown. 95</para> 96 97<para> 98The ICE library utilizes callbacks to process incoming messages. Using 99callbacks allows 100<function>ProtocolSetup</function> 101messages and authentication to happen 102behind the scenes. An additional benefit is that messages never need 103to be buffered up by the library when the client blocks waiting for a 104particular message. 105</para> 106</chapter> 107 108<chapter id='intended_audience'> 109<title>Intended Audience</title> 110 111<para>This document is intended primarily for implementors of protocol libraries 112layered on top of ICE. Typically, applications that wish to utilize ICE 113will make calls into individual protocol libraries rather than directly 114make calls into the ICE library. However, some applications will have to 115make some initial calls into the ICE library in order to accept ICE 116connections (for example, a session manager accepting connections from 117clients). But in general, protocol libraries should be designed to hide 118the inner details of ICE from applications.</para> 119</chapter> 120 121<chapter id='header_files_and_library_name'> 122<title>Header Files and Library Name</title> 123 124 125<para>The header file 126<<symbol role='Pn'>X11/ICE/ICElib.h</symbol>> 127defines all of the ICElib data structures and function prototypes. 128<function>ICElib.h</function> 129includes the header file 130<<symbol role='Pn'>X11/ICE/ICE.h</symbol>>, 131which defines all of the ICElib constants. 132Protocol libraries that need to read and write messages should include 133the header file 134<<symbol role='Pn'>X11/ICE/ICEmsg.h</symbol>>.</para> 135 136<para>Applications should link against ICElib using -lICE.</para> 137</chapter> 138 139<chapter id='note_on_prefixes'> 140<title>Note on Prefixes</title> 141 142 143<para>The following name prefixes are used in the library to distinguish between 144a client that initiates a 145<function>ProtocolSetup</function> 146and a client that 147responds with a 148<function>ProtocolReply</function></para> 149 150<itemizedlist> 151 <listitem> 152<para><function>IcePo</function> 153- Ice Protocol Originator</para> 154 </listitem> 155 <listitem> 156<para><function>IcePa</function> 157- Ice Protocol Acceptor</para> 158 </listitem> 159</itemizedlist> 160</chapter> 161 162<chapter id='protocol_registration'> 163<title>Protocol Registration</title> 164 165<para> 166In order for two clients to exchange messages for a given protocol, each 167side must register the protocol with the ICE library. The purpose of 168registration is for each side to obtain a major opcode for the protocol 169and to provide callbacks for processing messages and handling authentication. 170There are two separate registration functions: 171</para> 172 173<itemizedlist> 174 <listitem> 175 <para> 176One to handle the side that does a 177<function>ProtocolSetup</function> 178 </para> 179 </listitem> 180 <listitem> 181 <para> 182One to handle the side that responds with a 183<function>ProtocolReply</function> 184 </para> 185 </listitem> 186</itemizedlist> 187 188<para> 189It is recommended that protocol registration occur before the two clients 190establish an ICE connection. If protocol registration occurs after an 191ICE connection is created, there can be a brief interval of time in which a 192<function>ProtocolSetup</function> 193is received, but the protocol is not registered. 194If it is not possible to register a protocol before the creation of an 195ICE connection, proper precautions should be taken to avoid the above race 196condition. 197</para> 198 199 200<para> 201The <function>IceRegisterForProtocolSetup</function> 202function should be called for the client that initiates a 203<function>ProtocolSetup</function> 204</para> 205 206<funcsynopsis> 207<funcprototype> 208 <funcdef>int <function>IceRegisterForProtocolSetup</function></funcdef> 209 <paramdef>char<parameter> *protocol_name</parameter></paramdef> 210 <paramdef>char<parameter> *vendor</parameter></paramdef> 211 <paramdef>char<parameter> *release</parameter></paramdef> 212 <paramdef>int<parameter> *version_count</parameter></paramdef> 213 <paramdef>int<parameter> *version_count</parameter></paramdef> 214 <paramdef>IcePoVersionRec<parameter> *version_recs</parameter></paramdef> 215 <paramdef>int<parameter> auth_names</parameter></paramdef> 216 <paramdef>char<parameter> **auth_names</parameter></paramdef> 217 <paramdef>IcePoAuthProc<parameter> *auth_procs</parameter></paramdef> 218 <paramdef>IceIOErrorProc<parameter> *io_error_proc</parameter></paramdef> 219</funcprototype> 220</funcsynopsis> 221 222 223<variablelist remap='IP'> 224 <varlistentry> 225 <term><emphasis remap='I'>protocol_name</emphasis></term> 226 <listitem> 227 <para> 228A string specifying the name of the protocol to register. 229 </para> 230 </listitem> 231 </varlistentry> 232 <varlistentry> 233 <term><emphasis remap='I'>vendor</emphasis></term> 234 <listitem> 235 <para>A vendor string with semantics specified by the protocol.</para> 236 </listitem> 237 </varlistentry> 238 <varlistentry> 239 <term><emphasis remap='I'>release</emphasis></term> 240 <listitem> 241 <para>A release string with semantics specified by the protocol.</para> 242 </listitem> 243 </varlistentry> 244 <varlistentry> 245 <term><emphasis remap='I'>version_count</emphasis></term> 246 <listitem> 247 <para>The number of different versions of the protocol supported.</para> 248 </listitem> 249 </varlistentry> 250 <varlistentry> 251 <term><emphasis remap='I'>version_recs</emphasis></term> 252 <listitem> 253 <para>List of versions and associated callbacks.</para> 254 </listitem> 255 </varlistentry> 256 <varlistentry> 257 <term><emphasis remap='I'>auth_count</emphasis></term> 258 <listitem> 259 <para>The number of authentication methods supported.</para> 260 </listitem> 261 </varlistentry> 262 <varlistentry> 263 <term><emphasis remap='I'>auth_names</emphasis></term> 264 <listitem> 265 <para>The list of authentication methods supported.</para> 266 </listitem> 267 </varlistentry> 268 <varlistentry> 269 <term><emphasis remap='I'>auth_procs</emphasis></term> 270 <listitem> 271 <para> 272The list of authentication callbacks, one for each authentication method. 273 </para> 274 </listitem> 275 </varlistentry> 276 <varlistentry> 277 <term><emphasis remap='I'>io_error_proc</emphasis></term> 278 <listitem> 279 <para>IO error handler, or NULL.</para> 280 </listitem> 281 </varlistentry> 282</variablelist> 283 284 285<para> 286<function>IceRegisterForProtocolSetup</function> returns the major 287opcode reserved or -1 if an error occurred. In order to actually activate 288the protocol, the <function>IceProtocolSetup</function> 289function needs to be called with this major opcode. Once the protocol is 290activated, all messages for the protocol should be sent using this major 291opcode. 292</para> 293 294<para> 295A protocol library may support multiple versions of the same protocol. 296The version_recs argument specifies a list of supported versions of the 297protocol, which are prioritized in decreasing order of preference. 298Each version record consists of a major and minor version of the protocol 299as well as a callback to be used for processing incoming messages. 300</para> 301 302 303<literallayout remap='Ds'> 304typedef struct { 305 int major_version; 306 int minor_version; 307 IcePoProcessMsgProc process_msg_proc; 308} IcePoVersionRec; 309</literallayout> 310 311<para>The 312<function>IcePoProcessMsgProc</function> 313callback is responsible for processing the set of messages that can be 314received by the client that initiated the 315<function>ProtocolSetup</function> 316For further information, 317see 318<link linkend="callbacks_for_processing_messages"> 319<xref linkend="callbacks_for_processing_messages"></xref></link>.</para> 320 321<para>Authentication may be required before the protocol can become active. 322The protocol library must register the authentication methods that it 323supports with the ICE library. 324The auth_names and auth_procs arguments are a list of authentication names 325and callbacks that are prioritized in decreasing order of preference. 326For information on the 327<function>IcePoAuthProc</function> 328callback, see 329<link linkend="authentication_methods"> 330<xref linkend="authentication_methods"></xref></link> 331</para> 332 333<para>The 334<function>IceIOErrorProc</function> 335callback is invoked if the ICE connection unexpectedly breaks. 336You should pass NULL for io_error_proc if not interested in being notified. 337For further information, 338<link linkend="error_handling"> 339<xref linkend="error_handling"></xref></link> 340</para> 341 342 343<para>The 344<function>IceRegisterForProtocolReply</function> 345function should be called for the client that responds to a 346<function>ProtocolSetup</function> 347with a 348<function>ProtocolReply</function></para> 349 350 351<funcsynopsis> 352<funcprototype> 353 <funcdef>Bool <function>IceRegisterForProtocolReply</function></funcdef> 354 <paramdef>char<parameter> *host_name</parameter></paramdef> 355</funcprototype> 356</funcsynopsis> 357 358<variablelist remap='IP'> 359 <varlistentry> 360 <term><emphasis remap='I'>protocol_name</emphasis></term> 361 <listitem><para>A string specifying the name of the protocol to register.</para></listitem> 362 </varlistentry> 363 <varlistentry> 364 <term><emphasis remap='I'>vendor</emphasis></term> 365 <listitem> 366<para>A vendor string with semantics specified by the protocol.</para> 367 </listitem> 368 </varlistentry> 369 <varlistentry> 370 <term><emphasis remap='I'>release</emphasis></term> 371 <listitem> 372<para>A release string with semantics specified by the protocol.</para> 373 </listitem> 374 </varlistentry> 375 <varlistentry> 376 <term><emphasis remap='I'>version_count</emphasis></term> 377 <listitem> 378<para>The number of different versions of the protocol supported.</para> 379 </listitem> 380 </varlistentry> 381 <varlistentry> 382 <term><emphasis remap='I'>version_recs</emphasis></term> 383 <listitem> 384<para>List of versions and associated callbacks.</para> 385 </listitem> 386 </varlistentry> 387 <varlistentry> 388 <term><emphasis remap='I'>auth_count</emphasis></term> 389 <listitem> 390<para>The number of authentication methods supported.</para> 391 </listitem> 392 </varlistentry> 393 <varlistentry> 394 <term><emphasis remap='I'>auth_names</emphasis></term> 395 <listitem> 396<para>The list of authentication methods supported.</para> 397 </listitem> 398 </varlistentry> 399 <varlistentry> 400 <term><emphasis remap='I'>auth_procs</emphasis></term> 401 <listitem> 402<para>The list of authentication callbacks, one for each authentication method.</para> 403 </listitem> 404 </varlistentry> 405 <varlistentry> 406 <term><emphasis remap='I'>host_based_auth_proc</emphasis></term> 407 <listitem> 408<para>Host based authentication callback.</para> 409 </listitem> 410 </varlistentry> 411 <varlistentry> 412 <term><emphasis remap='I'>protocol_setup_proc</emphasis></term> 413 <listitem> 414<para>A callback to be invoked when authentication has succeeded for a 415<function>ProtocolSetup</function> 416but before the 417<function>ProtocolReply</function> 418is sent.</para> 419 </listitem> 420 </varlistentry> 421 <varlistentry> 422 <term><emphasis remap='I'>protocol_activate_proc</emphasis></term> 423 <listitem> 424<para>A callback to be invoked after the 425<function>ProtocolReply</function> 426is sent.</para> 427 </listitem> 428 </varlistentry> 429 <varlistentry> 430 <term><emphasis remap='I'>io_error_proc</emphasis></term> 431 <listitem> 432<para>IO error handler, or NULL.</para> 433 </listitem> 434 </varlistentry> 435</variablelist> 436 437 438<para><function>IceRegisterForProtocolReply</function> 439returns the major opcode reserved or -1 if an error occurred. The major 440opcode should be used in all subsequent messages sent for this protocol.</para> 441 442<para>A protocol library may support multiple versions of the same protocol. 443The version_recs argument specifies a list of supported versions of the protocol, 444which are prioritized in decreasing order of preference. 445Each version record consists of a major and minor version of the protocol 446as well as a callback to be used for processing incoming messages.</para> 447 448 449<literallayout remap='Ds'> 450typedef struct { 451 int major_version; 452 int minor_version; 453 IcePaProcessMsgProc process_msg_proc; 454} IcePaVersionRec; 455</literallayout> 456 457 458<para>The 459<function>IcePaProcessMsgProc</function> 460callback is responsible for processing the set of messages that can be 461received by the client that accepted the 462<function>ProtocolSetup</function> 463For further information, 464see 465<link linkend="callbacks_for_processing_messages"> 466<xref linkend="callbacks_for_processing_messages"></xref></link> 467</para> 468 469<para>Authentication may be required before the protocol can become active. 470The protocol library must register the authentication methods that it 471supports with the ICE library. 472The auth_names and auth_procs arguments are a list of authentication names 473and callbacks that are prioritized in decreasing order of preference. 474For information on the 475<function>IcePaAuthProc</function>, 476See 477<link linkend="authentication_methods"> 478<xref linkend="authentication_methods"></xref></link> 479 480</para> 481 482<para>If authentication fails and the client attempting to initiate 483the 484<function>ProtocolSetup</function> 485has not required authentication, the 486<function>IceHostBasedAuthProc</function> 487callback is invoked with the host name of the originating client. 488If the callback returns 489<function>True</function> 490the 491<function>ProtocolSetup</function> 492will succeed, even though the original 493authentication failed. 494Note that authentication can effectively be disabled by registering an 495<function>IceHostBasedAuthProc</function> 496which always returns 497<function>True</function> 498If no host based 499authentication is allowed, you should pass NULL for host_based_auth_proc.</para> 500 501<funcsynopsis> 502<funcprototype> 503 <funcdef>Bool <function>HostBasedAuthProc</function></funcdef> 504 <paramdef>char<parameter> *host_name</parameter></paramdef> 505</funcprototype> 506</funcsynopsis> 507 508<variablelist remap='IP'> 509 <varlistentry> 510 <term><emphasis remap='I'>protocol_name</emphasis></term> 511 <listitem><para>The host name of the client that sent the <function>ProtocolSetup</function></para></listitem> 512 </varlistentry> 513</variablelist> 514 515 516<para>The host_name argument is a string of the form <emphasis remap='I'>protocol</emphasis>/<emphasis remap='I'>hostname</emphasis>, 517where <emphasis remap='I'>protocol</emphasis> is one of {tcp, decnet, local}.</para> 518 519<para>Because 520<function>ProtocolSetup</function> 521messages and authentication happen behind the scenes 522via callbacks, the protocol library needs some way of being notified when the 523<function>ProtocolSetup</function> 524has completed. 525This occurs in two phases. 526In the first phase, the 527<function>IceProtocolSetupProc</function> 528callback is invoked after authentication has 529successfully completed but before the ICE library sends a 530<function>ProtocolReply</function> 531Any resources required for this protocol should be allocated at this time. 532If the 533<function>IceProtocolSetupProc</function> 534returns a successful status, the ICE library will 535send the 536<function>ProtocolReply</function> 537and then invoke the 538<function>IceProtocolActivateProc</function> 539callback. Otherwise, an error will be sent to the 540other client in response to the 541<function>ProtocolSetup</function></para> 542 543<para>The 544<function>IceProtocolActivateProc</function> 545is an optional callback and should be registered only if the protocol 546library intends to generate a message immediately following the 547<function>ProtocolReply</function> 548You should pass NULL for protocol_activate_proc if not interested 549in this callback.</para> 550 551<funcsynopsis> 552<funcprototype> 553 <funcdef>Status <function>ProtocolSetupProc</function></funcdef> 554 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef> 555 <paramdef>int<parameter> major_version</parameter></paramdef> 556 <paramdef>int<parameter> minor_version</parameter></paramdef> 557 <paramdef>char<parameter> *vendor</parameter></paramdef> 558 <paramdef>char<parameter> *release</parameter></paramdef> 559 <paramdef>IcePointer<parameter> *client_data_ret</parameter></paramdef> 560 <paramdef>char<parameter> **failure_reason_ret</parameter></paramdef> 561</funcprototype> 562</funcsynopsis> 563 564<variablelist remap='IP'> 565 <varlistentry> 566 <term><emphasis remap='I'>protocol_name</emphasis></term> 567 <listitem> 568<para>The ICE connection object.</para> 569 </listitem> 570 </varlistentry> 571 <varlistentry> 572 <term><emphasis remap='I'>major_version</emphasis></term> 573 <listitem> 574<para>The major version of the protocol.</para> 575 </listitem> 576 </varlistentry> 577 <varlistentry> 578 <term><emphasis remap='I'>minor_version</emphasis></term> 579 <listitem> 580<para>The minor version of the protocol.</para> 581 </listitem> 582 </varlistentry> 583 <varlistentry> 584 <term><emphasis remap='I'>vendor</emphasis></term> 585 <listitem> 586<para>The vendor string registered by the protocol originator.</para> 587 </listitem> 588 </varlistentry> 589 <varlistentry> 590 <term><emphasis remap='I'>release</emphasis></term> 591 <listitem> 592<para>The release string registered by the protocol originator.</para> 593 </listitem> 594 </varlistentry> 595 <varlistentry> 596 <term><emphasis remap='I'>client_data_ret</emphasis></term> 597 <listitem> 598<para>Client data to be set by callback.</para> 599 </listitem> 600 </varlistentry> 601 <varlistentry> 602 <term><emphasis remap='I'>failure_reason_ret</emphasis></term> 603 <listitem> 604<para>Failure reason returned.</para> 605 </listitem> 606 </varlistentry> 607</variablelist> 608 609<para>The pointer stored in the client_data_ret argument will be passed 610to the 611<function>IcePaProcessMsgProc</function> 612callback whenever a message has arrived for this protocol on the 613ICE connection.</para> 614 615<para>The vendor and release strings should be freed with 616<function>free</function> 617when they are no longer needed.</para> 618 619<para>If a failure occurs, the 620<function>IceProtocolSetupProc</function> 621should return a zero status as well as allocate and return a failure 622reason string in failure_reason_ret. 623The ICE library will be responsible for freeing this memory.</para> 624 625<para>The 626<function>IceProtocolActivateProc</function> 627callback is defined as follows:</para> 628 629<funcsynopsis> 630<funcprototype> 631 <funcdef>void <function>ProtocolActivateProc</function></funcdef> 632 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef> 633 <paramdef>IcePointer<parameter> client_data</parameter></paramdef> 634</funcprototype> 635</funcsynopsis> 636 637<variablelist remap='IP'> 638 <varlistentry> 639 <term><emphasis remap='I'>ice_conn</emphasis></term> 640 <listitem><para>The ICE connection object.</para></listitem> 641 </varlistentry> 642 <varlistentry> 643 <term><emphasis remap='I'>client_data</emphasis></term> 644 <listitem> 645 <para> 646The client data set in the <function>IceProtocolSetupProc</function> callback. 647 </para> 648 </listitem> 649 </varlistentry> 650</variablelist> 651 652 653<para>The 654<function>IceIOErrorProc</function> 655callback is invoked if the ICE connection unexpectedly breaks. 656You should pass NULL for io_error_proc if not interested in being notified. 657For further information, 658see 659<link linkend="error_handling"> 660<xref linkend="error_handling"></xref></link> 661</para> 662 663<sect1 id='callbacks_for_processing_messages'> 664<title>Callbacks for Processing Messages</title> 665 666<para>When an application detects that there is new data to read on an ICE 667connection (via 668<function>select</function> 669it calls the 670<function>IceProcessMessages</function> 671function 672<link linkend="processing_messages"> 673<xref linkend="processing_messages"></xref></link>. 674 675When 676<function>IceProcessMessages</function> 677reads an ICE message header with a major opcode other than 678zero (reserved for the ICE protocol), it needs to call a function that will 679read the rest of the message, unpack it, and process it accordingly.</para> 680 681<para>If the message arrives at the client that initiated the 682<function>ProtocolSetup</function> 683the 684<function>IcePoProcessMsgProc</function> 685callback is invoked.</para> 686 687<funcsynopsis> 688<funcprototype> 689 <funcdef>void <function>PoProcessMsgProc</function></funcdef> 690 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef> 691 <paramdef>IcePointer<parameter> client_data</parameter></paramdef> 692 <paramdef>int<parameter> opcode</parameter></paramdef> 693 <paramdef>unsigned long<parameter> length</parameter></paramdef> 694 <paramdef>Bool<parameter> swap</parameter></paramdef> 695 <paramdef>IceReplyWaitInfo<parameter> *reply_wait</parameter></paramdef> 696 <paramdef>Bool<parameter> *reply_ready_ret</parameter></paramdef> 697</funcprototype> 698</funcsynopsis> 699 700<variablelist remap='IP'> 701 <varlistentry> 702 <term><emphasis remap='I'>ice_conn</emphasis></term> 703 <listitem><para>The ICE connection object.</para></listitem> 704 </varlistentry> 705 <varlistentry> 706 <term><emphasis remap='I'>client_data</emphasis></term> 707 <listitem> 708<para>Client data associated with this protocol on the ICE connection.</para> 709 </listitem> 710 </varlistentry> 711 <varlistentry> 712 <term><emphasis remap='I'>opcode</emphasis></term> 713 <listitem> 714<para>The minor opcode of the message.</para> 715 </listitem> 716 </varlistentry> 717 <varlistentry> 718 <term><emphasis remap='I'>length</emphasis></term> 719 <listitem> 720<para>The length (in 8-byte units) of the message beyond the ICE header.</para> 721 </listitem> 722 </varlistentry> 723 <varlistentry> 724 <term><emphasis remap='I'>swap</emphasis></term> 725 <listitem> 726<para>A flag that indicates if byte swapping is necessary.</para> 727 </listitem> 728 </varlistentry> 729 <varlistentry> 730 <term><emphasis remap='I'>reply_wait</emphasis></term> 731 <listitem> 732<para>Indicates if the invoking client is waiting for a reply.</para> 733 </listitem> 734 </varlistentry> 735 <varlistentry> 736 <term><emphasis remap='I'>reply_ready_ret</emphasis></term> 737 <listitem> 738<para>If set to 739<function>True</function> 740a reply is ready.</para> 741 </listitem> 742 </varlistentry> 743</variablelist> 744 745 746<para>If the message arrives at the client that accepted the 747<function>ProtocolSetup</function> 748the 749<function>IcePaProcessMsgProc</function> 750callback is invoked.</para> 751 752 753<funcsynopsis> 754<funcprototype> 755 <funcdef>void <function>IcePaProcessMsgProc</function></funcdef> 756 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef> 757 <paramdef>IcePointer<parameter> client_data</parameter></paramdef> 758 <paramdef>int<parameter> opcode</parameter></paramdef> 759 <paramdef>unsigned long<parameter> length</parameter></paramdef> 760 <paramdef>Bool<parameter> swap</parameter></paramdef> 761</funcprototype> 762</funcsynopsis> 763 764<variablelist remap='IP'> 765 <varlistentry> 766 <term><emphasis remap='I'>ice_conn</emphasis></term> 767 <listitem><para>The ICE connection object.</para></listitem> 768 </varlistentry> 769 <varlistentry> 770 <term><emphasis remap='I'>client_data</emphasis></term> 771 <listitem> 772<para>Client data associated with this protocol on the ICE connection.</para> 773 </listitem> 774 </varlistentry> 775 <varlistentry> 776 <term><emphasis remap='I'>opcode</emphasis></term> 777 <listitem> 778<para>The minor opcode of the message.</para> 779 </listitem> 780 </varlistentry> 781 <varlistentry> 782 <term><emphasis remap='I'>length</emphasis></term> 783 <listitem> 784<para>The length (in 8-byte units) of the message beyond the ICE header.</para> 785 </listitem> 786 </varlistentry> 787 <varlistentry> 788 <term><emphasis remap='I'>swap</emphasis></term> 789 <listitem> 790<para>A flag that indicates if byte swapping is necessary.</para> 791 </listitem> 792 </varlistentry> 793</variablelist> 794 795 796<para>In order to read the message, both of these callbacks should use the 797macros defined for this purpose (see 798<link linkend="reading_ice_messages"> 799<xref linkend="reading_ice_messages"></xref></link>.). 800Note that byte swapping may be necessary. 801As a convenience, the length field in the ICE header will be swapped by ICElib 802if necessary.</para> 803 804<para>In both of these callbacks, the client_data argument is a pointer to client 805data that was registered at 806<function>ProtocolSetup</function> 807time. 808In the case of 809<function>IcePoProcessMsgProc</function> 810the client data was set in the call to 811<function>IceProtocolSetup</function> 812In the case of 813<function>IcePaProcessMsgProc</function> 814the client data was set in the 815<function>IceProtocolSetupProc</function> 816callback.</para> 817 818<para>The 819<function>IcePoProcessMsgProc</function> 820callback needs to check the reply_wait argument. 821If reply_wait is NULL , 822the ICE library expects the function to 823pass the message to the client via a callback. 824For example, if this is a Session Management "Save Yourself" message, 825this function should notify the client of the "Save Yourself" via a callback. 826The details of how such a callback would be defined 827are implementation-dependent.</para> 828 829<para>However, if reply_wait is not NULL , 830then the client is waiting for 831a reply or an error for a message it previously sent. 832The reply_wait is of type 833<function>IceReplyWaitInfo</function></para> 834 835 836<literallayout remap='Ds'> 837typedef struct { 838 unsigned long sequence_of_request; 839 int major_opcode_of_request; 840 int minor_opcode_of_request; 841 IcePointer reply; 842} IceReplyWaitInfo; 843</literallayout> 844 845<para><function>IceReplyWaitInfo</function> 846contains the major/minor opcodes and sequence number of 847the message for which a reply is being awaited. 848It also contains a pointer to the reply message to be filled in 849(the protocol library should cast this 850<function>IcePointer</function> 851to the appropriate reply type). 852In most cases, the reply will have some fixed-size part, and the client waiting 853for the reply will have provided a pointer to a structure to hold 854this fixed-size data. If there is variable-length data, it would be 855expected that the 856<function>IcePoProcessMsgProc</function> 857callback will have to allocate additional 858memory and store pointer(s) to that memory in the fixed-size 859structure. If the entire data is variable length (for example., a single 860variable-length string), then the client waiting for the reply would probably 861just pass a pointer to fixed-size space to hold a pointer, and the 862<function>IcePoProcessMsgProc</function> 863callback would allocate the storage and store the pointer. 864It is the responsibility of the client receiving the reply to 865free any memory allocated on its behalf.</para> 866 867<para>If reply_wait is not NULL and 868<function>IcePoProcessMsgProc</function> 869has a reply or error to return in response to this reply_wait 870(that is, no callback was generated), then the reply_ready_ret argument 871should be set to 872<function>True</function> 873Note that an error should only be returned 874if it corresponds to the reply being waited for. Otherwise, the 875<function>IcePoProcessMsgProc</function> 876should either handle the error internally or invoke an error handler 877for its library.</para> 878 879<para>If reply_wait is NULL, 880then care must be taken not to store any value in reply_ready_ret, 881because this pointer may also be NULL.</para> 882 883<para>The 884<function>IcePaProcessMsgProc</function> 885callback, on the other hand, should always pass 886the message to the client via a callback. For example, if this is a Session 887Management "Interact Request" message, this function should notify the 888client of the "Interact Request" via a callback.</para> 889 890<para>The reason the 891<function>IcePaProcessMsgProc</function> 892callback does not have a reply_wait, like 893<function>IcePoProcessMsgProc</function> 894does, is because a process that is acting as 895a server should never block for a reply (infinite blocking can 896occur if the connecting client does not act properly, denying access 897to other clients).</para> 898</sect1> 899 900<sect1 id='authentication_methods'> 901<title>Authentication Methods</title> 902 903<para>As already stated, a protocol library must register the authentication 904methods that it supports with the ICE library. For each authentication 905method, there are two callbacks that may be registered:</para> 906<itemizedlist> 907 <listitem> 908 <para> 909One to handle the side that initiates a <function>ProtocolSetup</function> 910 </para> 911 </listitem> 912 <listitem> 913 <para> 914One to handle the side that accepts or rejects this request 915 </para> 916 </listitem> 917</itemizedlist> 918 919<para><function>IcePoAuthProc</function> 920is the callback invoked for the client that initiated the 921<function>ProtocolSetup</function> 922This callback must be able to respond 923to the initial "Authentication Required" message or subsequent 924"Authentication Next Phase" messages sent by the other client.</para> 925 926 927<funcsynopsis> 928<funcprototype> 929 <funcdef>IcePoAuthStatus <function>IcePoAuthStatus </function></funcdef> 930 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef> 931 <paramdef>IcePointer<parameter> client_data</parameter></paramdef> 932 <paramdef>int<parameter> opcode</parameter></paramdef> 933</funcprototype> 934</funcsynopsis> 935 936 937<variablelist remap='IP'> 938 <varlistentry> 939 <term><emphasis remap='I'>ice_conn</emphasis></term> 940 <listitem><para>The ICE connection object.</para></listitem> 941 </varlistentry> 942 <varlistentry> 943 <term><emphasis remap='I'>auth_state_ptr</emphasis></term> 944 <listitem> 945<para>A pointer to state for use by the authentication callback procedure.</para> 946 </listitem> 947 </varlistentry> 948 <varlistentry> 949 <term><emphasis remap='I'>clean_up</emphasis></term> 950 <listitem> 951<para>If 952<function>True</function> 953authentication is over, and the function 954should clean up any state it was maintaining. The 955last 6 arguments should be ignored.</para> 956 </listitem> 957 </varlistentry> 958 <varlistentry> 959 <term><emphasis remap='I'>swap</emphasis></term> 960 <listitem> 961<para>If 962<function>True</function> 963the auth_data may have to be byte swapped 964(depending on its contents).</para> 965 </listitem> 966 </varlistentry> 967 <varlistentry> 968 <term><emphasis remap='I'>auth_datalen</emphasis></term> 969 <listitem> 970<para>The length (in bytes) of the authenticator data.</para> 971 </listitem> 972 </varlistentry> 973 <varlistentry> 974 <term><emphasis remap='I'>auth_data</emphasis></term> 975 <listitem> 976<para>The data from the authenticator.</para> 977 </listitem> 978 </varlistentry> 979 <varlistentry> 980 <term><emphasis remap='I'>reply_datalen_ret</emphasis></term> 981 <listitem> 982<para>The length (in bytes) of the reply data returned.</para> 983 </listitem> 984 </varlistentry> 985 <varlistentry> 986 <term><emphasis remap='I'>reply_data_ret</emphasis></term> 987 <listitem> 988<para>The reply data returned.</para> 989 </listitem> 990 </varlistentry> 991 <varlistentry> 992 <term><emphasis remap='I'>error_string_ret</emphasis></term> 993 <listitem> 994<para>If the authentication procedure encounters an error during 995authentication, it should allocate and return 996an error string.</para> 997 </listitem> 998 </varlistentry> 999</variablelist> 1000 1001 1002<para>Authentication may require several phases, depending on the authentication 1003method. As a result, the 1004<function>IcePoAuthProc</function> 1005may be called more than once when authenticating a client, and 1006some state will have to be maintained between each invocation. 1007At the start of each 1008<function>ProtocolSetup</function> 1009*auth_state_ptr is NULL, 1010and the function should initialize its state and set 1011this pointer. In subsequent invocations of the callback, the pointer 1012should be used to get at any state previously stored by the callback.</para> 1013 1014<para>If needed, the network ID of the client accepting the 1015<function>ProtocolSetup</function> 1016can be obtained by calling the 1017<function>IceConnectionString</function> 1018function.</para> 1019 1020<para>ICElib will be responsible for freeing the reply_data_ret and 1021error_string_ret pointers with 1022<function>free</function></para> 1023 1024<para>The auth_data pointer may point to a volatile block of memory. 1025If the data must be kept beyond this invocation of the callback, be sure 1026to make a copy of it.</para> 1027 1028<para>The 1029<function>IcePoAuthProc</function> 1030should return one of four values:</para> 1031<itemizedlist> 1032 <listitem> 1033<para><function>IcePoAuthHaveReply</function> 1034- a reply is available.</para> 1035 </listitem> 1036 <listitem> 1037<para><function>IcePoAuthRejected</function> 1038- authentication rejected.</para> 1039 </listitem> 1040 <listitem> 1041<para><function>IcePoAuthFailed</function> 1042- authentication failed.</para> 1043 </listitem> 1044 <listitem> 1045<para><function>IcePoAuthDoneCleanup</function> 1046- done cleaning up.</para> 1047 </listitem> 1048</itemizedlist> 1049 1050<para><function>IcePaAuthProc</function> 1051is the callback invoked for the client that received the 1052<function>ProtocolSetup</function></para> 1053 1054<funcsynopsis> 1055<funcprototype> 1056 <funcdef>IcePoAuthStatus <function>PoAuthStatus </function></funcdef> 1057 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef> 1058 <paramdef>IcePointer<parameter> *auth_state_ptr</parameter></paramdef> 1059 <paramdef>Bool<parameter> swap</parameter></paramdef> 1060 <paramdef>int<parameter> auth_datalen</parameter></paramdef> 1061 <paramdef>IcePointer<parameter> auth_data</parameter></paramdef> 1062 <paramdef>int<parameter> *reply_datalen_ret</parameter></paramdef> 1063 <paramdef>IcePointer<parameter> *reply_data_ret</parameter></paramdef> 1064 <paramdef>char<parameter> **error_string_ret</parameter></paramdef> 1065</funcprototype> 1066</funcsynopsis> 1067 1068<variablelist remap='IP'> 1069 <varlistentry> 1070 <term><emphasis remap='I'>ice_conn</emphasis></term> 1071 <listitem><para>The ICE connection object.</para></listitem> 1072 </varlistentry> 1073 <varlistentry> 1074 <term><emphasis remap='I'>auth_state_ptr</emphasis></term> 1075 <listitem> 1076<para>A pointer to state for use by the authentication callback procedure.</para> 1077 </listitem> 1078 </varlistentry> 1079 <varlistentry> 1080 <term><emphasis remap='I'>swap</emphasis></term> 1081 <listitem> 1082<para>If 1083<function>True</function> 1084auth_data may have to be byte swapped 1085(depending on its contents).</para> 1086 </listitem> 1087 </varlistentry> 1088 <varlistentry> 1089 <term><emphasis remap='I'>auth_datalen</emphasis></term> 1090 <listitem> 1091<para>The length (in bytes) of the protocol originator authentication data.</para> 1092 </listitem> 1093 </varlistentry> 1094 <varlistentry> 1095 <term><emphasis remap='I'>auth_data</emphasis></term> 1096 <listitem> 1097<para>The authentication data from the protocol originator.</para> 1098 </listitem> 1099 </varlistentry> 1100 <varlistentry> 1101 <term><emphasis remap='I'>reply_datalen_ret</emphasis></term> 1102 <listitem> 1103<para>The length of the authentication data returned.</para> 1104 </listitem> 1105 </varlistentry> 1106 <varlistentry> 1107 <term><emphasis remap='I'>reply_data_ret</emphasis></term> 1108 <listitem> 1109<para>The authentication data returned.</para> 1110 </listitem> 1111 </varlistentry> 1112 <varlistentry> 1113 <term><emphasis remap='I'>error_string_ret</emphasis></term> 1114 <listitem> 1115<para>If authentication is rejected or fails, an error 1116string is returned.</para> 1117 </listitem> 1118 </varlistentry> 1119</variablelist> 1120 1121 1122<para>Authentication may require several phases, depending on the authentication 1123method. As a result, the 1124<function>IcePaAuthProc</function> 1125may be called more than once when authenticating a client, and 1126some state will have to be maintained between each invocation. 1127At the start of each 1128<function>ProtocolSetup</function> 1129auth_datalen is zero, 1130*auth_state_ptr is NULL, 1131and the function should initialize its state and set 1132this pointer. In subsequent invocations of the callback, the pointer 1133should be used to get at any state previously stored by the callback.</para> 1134 1135<para>If needed, the network ID of the client accepting the 1136<function>ProtocolSetup</function> 1137can be obtained by calling the 1138<function>IceConnectionString</function> 1139function.</para> 1140 1141<para>The auth_data pointer may point to a volatile block of memory. 1142If the data must be kept beyond this invocation of the callback, be sure 1143to make a copy of it.</para> 1144 1145<para>ICElib will be responsible for transmitting and freeing the reply_data_ret and 1146error_string_ret pointers with 1147<function>free</function></para> 1148 1149<para> 1150The <function>IcePaAuthProc</function> should return one of four values: 1151</para> 1152 1153 1154<itemizedlist> 1155 <listitem> 1156 <para> 1157<function>IcePaAuthContinue</function> - continue (or start) authentication. 1158 </para> 1159 </listitem> 1160 <listitem> 1161 <para> 1162<function>IcePaAuthAccepted</function> - authentication accepted. 1163 </para> 1164 </listitem> 1165 <listitem> 1166 <para> 1167<function>IcePaAuthRejected</function> - authentication rejected. 1168 </para> 1169 </listitem> 1170 <listitem> 1171 <para> 1172<function>IcePaAuthFailed</function> - authentication failed. 1173 </para> 1174 </listitem> 1175</itemizedlist> 1176</sect1> 1177 1178</chapter> 1179 1180<chapter id='ice_connections'> 1181<title>ICE Connections</title> 1182 1183<para> 1184In order for two clients to establish an ICE connection, one client has to be 1185waiting for connections, and the other client has to initiate the connection. 1186Most clients will initiate connections, so we discuss that first. 1187</para> 1188 1189<sect1 id='opening_an_ice_connection'> 1190<title>Opening an ICE Connection</title> 1191 1192 1193<para> 1194To open an ICE connection with another client (that is, waiting 1195for connections), use <function>IceOpenConnection</function> 1196</para> 1197 1198<funcsynopsis> 1199<funcprototype> 1200 <funcdef>IceConn <function>IceOpenConnection</function></funcdef> 1201 <paramdef>char<parameter> *network_ids_list</parameter></paramdef> 1202 <paramdef>IcePointer<parameter> context</parameter></paramdef> 1203 <paramdef>Bool<parameter> must_authenticate</parameter></paramdef> 1204 <paramdef>int<parameter> major_opcode_check</parameter></paramdef> 1205 <paramdef>int<parameter> error_length</parameter></paramdef> 1206 <paramdef>char<parameter> *error_string_ret</parameter></paramdef> 1207</funcprototype> 1208</funcsynopsis> 1209 1210<variablelist remap='IP'> 1211 <varlistentry> 1212 <term><emphasis remap='I'>network_ids_list</emphasis></term> 1213 <listitem> 1214 <para> 1215Specifies the network ID(s) of the other client. 1216 </para> 1217 </listitem> 1218 </varlistentry> 1219 <varlistentry> 1220 <term><emphasis remap='I'>context</emphasis></term> 1221 <listitem> 1222 <para> 1223A pointer to an opaque object or NULL. Used to determine if an 1224ICE connection can be shared (see below). 1225 </para> 1226 </listitem> 1227 </varlistentry> 1228 <varlistentry> 1229 <term><emphasis remap='I'>must_authenticate</emphasis></term> 1230 <listitem> 1231 <para> 1232If <function>True</function> the other client may not bypass authentication. 1233 </para> 1234 </listitem> 1235 </varlistentry> 1236 <varlistentry> 1237 <term><emphasis remap='I'>major_opcode_check</emphasis></term> 1238 <listitem> 1239 <para> 1240Used to force a new ICE connection to be created (see below). 1241 </para> 1242 </listitem> 1243 </varlistentry> 1244 <varlistentry> 1245 <term><emphasis remap='I'>error_length</emphasis></term> 1246 <listitem> 1247 <para>Length of the error_string_ret argument passed in.</para> 1248 </listitem> 1249 </varlistentry> 1250 <varlistentry> 1251 <term><emphasis remap='I'>error_string_ret</emphasis></term> 1252 <listitem> 1253 <para> 1254Returns a null-terminated error message, if any. The error_string_ret 1255argument points to user supplied memory. No more than error_length bytes 1256are used. 1257 </para> 1258 </listitem> 1259 </varlistentry> 1260</variablelist> 1261 1262 1263<para> 1264<function>IceOpenConnection</function> 1265returns an opaque ICE connection object if it succeeds; 1266otherwise, it returns NULL. 1267</para> 1268 1269<para> 1270The network_ids_list argument contains a list of network IDs separated 1271by commas. An attempt will be made to use the first network ID. If 1272that fails, an attempt will be made using the second network ID, and so on. 1273Each network ID has the following format: 1274</para> 1275 1276<informaltable pgwide='0' frame='none'> 1277 <tgroup cols='3' align='center'> 1278 <colspec colname='c1'/> 1279 <colspec colname='c2'/> 1280 <colspec colname='c3'/> 1281 <tbody> 1282 <row> 1283 <entry align='left'></entry> 1284 <entry align='left'>tcp/<hostname>:<portnumber></entry> 1285 <entry align='left'>or</entry> 1286 </row> 1287 <row> 1288 <entry align='left'></entry> 1289 <entry align='left'>decnet/<hostname>::<objname></entry> 1290 <entry align='left'>or</entry> 1291 </row> 1292 <row> 1293 <entry align='left'></entry> 1294 <entry align='left'>local/<hostname>:<path></entry> 1295 <entry align='left'></entry> 1296 </row> 1297 </tbody> 1298 </tgroup> 1299</informaltable> 1300 1301 1302<para>Most protocol libraries will have some sort of open function that should 1303internally make a call into 1304<function>IceOpenConnection</function> 1305When 1306<function>IceOpenConnection</function> 1307is called, it may be possible to use a previously opened ICE connection (if 1308the target client is the same). However, there are cases in which shared 1309ICE connections are not desired.</para> 1310 1311<para>The context argument is used to determine if an ICE connection can 1312be shared. 1313If context is NULL, 1314then the caller is always willing to share the connection. 1315If context is not NULL, 1316then the caller is not willing to use a previously opened ICE connection 1317that has a different non-NULL context associated with it.</para> 1318 1319<para>In addition, if major_opcode_check contains a nonzero major opcode value, 1320a previously created ICE connection will be used only if the major opcode 1321is not active on the connection. This can be used to force multiple ICE 1322connections between two clients for the same protocol.</para> 1323 1324<para>Any authentication requirements are handled internally by the ICE library. 1325The method by which the authentication data is obtained 1326is implementation-dependent. 1327 <footnote remap='FS'> 1328<para>The X Consortium's ICElib implementation uses an .ICEauthority file (see 1329Appendix A). 1330 </para></footnote> </para> 1331 1332<para>After 1333<function>IceOpenConnection</function> 1334is called, the client is ready to send a 1335<function>ProtocolSetup</function> 1336(provided that 1337<function>IceRegisterForProtocolSetup</function> 1338was called) or receive a 1339<function>ProtocolSetup</function> 1340(provided that 1341<function>IceRegisterForProtocolReply</function> 1342was called).</para> 1343</sect1> 1344 1345<sect1 id='listening_for_ice_connections'> 1346<title>Listening for ICE Connections</title> 1347 1348<para>Clients wishing to accept ICE connections must first call 1349<function>IceListenForConnections</function> 1350or 1351<function>IceListenForWellKnownConnections</function> 1352so that they can listen for connections. A list of opaque "listen" objects are 1353returned, one for each type of transport method that is available 1354(for example, Unix Domain, TCP, DECnet, and so on).</para> 1355 1356<para>Normally clients will let ICElib allocate an available name in each 1357transport and return listen objects. Such a client will then use 1358<function>IceComposeNetworkIdList</function> 1359to extract the chosen names and make them 1360available to other clients for opening the connection. In certain 1361cases it may be necessary for a client to listen for connections 1362on pre-arranged transport object names. Such a client may use 1363<function>IceListenForWellKnownConnections</function> 1364to specify the names for the listen objects.</para> 1365 1366<funcsynopsis> 1367<funcprototype> 1368 <funcdef>Status <function>IceListenForConnections</function></funcdef> 1369 <paramdef>int<parameter> *count_ret</parameter></paramdef> 1370 <paramdef>IceListenObj<parameter> **listen_objs_ret</parameter></paramdef> 1371 <paramdef>int<parameter> error_length</parameter></paramdef> 1372 <paramdef>char<parameter> *error_string_ret</parameter></paramdef> 1373</funcprototype> 1374</funcsynopsis> 1375 1376<variablelist remap='IP'> 1377 <varlistentry> 1378 <term><emphasis remap='I'>count_ret</emphasis></term> 1379 <listitem><para>Returns the number of listen objects created.</para></listitem> 1380 </varlistentry> 1381 <varlistentry> 1382 <term><emphasis remap='I'>listen_objs_ret</emphasis></term> 1383 <listitem><para>Returns a list of pointers to opaque listen objects.</para></listitem> 1384 </varlistentry> 1385 <varlistentry> 1386 <term><emphasis remap='I'>error_length</emphasis></term> 1387 <listitem> 1388<para>The length of the error_string_ret argument passed in.</para> 1389 </listitem> 1390 </varlistentry> 1391 <varlistentry> 1392 <term><emphasis remap='I'>error_string_ret</emphasis></term> 1393 <listitem> 1394<para>Returns a null-terminated error message, if any. 1395The error_string_ret points to user supplied memory. 1396No more than error_length bytes are used.</para> 1397 </listitem> 1398 </varlistentry> 1399</variablelist> 1400 1401 1402<para>The return value of 1403<function>IceListenForConnections</function> 1404is zero for failure and a positive value for success.</para> 1405 1406<funcsynopsis> 1407<funcprototype> 1408 <funcdef>Status <function>IceListenForWellKnownConnections</function></funcdef> 1409 <paramdef>char<parameter> *port_id</parameter></paramdef> 1410 <paramdef>int<parameter> *count_ret</parameter></paramdef> 1411 <paramdef>IceListenObj<parameter> **listen_objs_ret</parameter></paramdef> 1412 <paramdef>int<parameter> error_length</parameter></paramdef> 1413 <paramdef>char<parameter> *error_string_ret</parameter></paramdef> 1414</funcprototype> 1415</funcsynopsis> 1416 1417<variablelist remap='IP'> 1418 <varlistentry> 1419 <term><emphasis remap='I'>port_id</emphasis></term> 1420 <listitem> 1421 <para> 1422Specifies the port identification for the address(es) to be opened. The 1423value must not contain the slash ("/"> or comma (".") character; thse are 1424reserved for future use. 1425 </para> 1426 </listitem> 1427 </varlistentry> 1428 <varlistentry> 1429 <term><emphasis remap='I'>count_ret</emphasis></term> 1430 <listitem> 1431 <para>Returns the number of listen objects created.</para> 1432 </listitem> 1433 </varlistentry> 1434 <varlistentry> 1435 <term><emphasis remap='I'>listen_objs_ret</emphasis></term> 1436 <listitem> 1437 <para> 1438Returns a list of pointers to opaque listen objects. 1439 </para> 1440 </listitem> 1441 </varlistentry> 1442 <varlistentry> 1443 <term><emphasis remap='I'>listen_objs_ret</emphasis></term> 1444 <listitem> 1445 <para> 1446Returns a list of pointers to opaque listen objects. 1447 </para> 1448 </listitem> 1449 </varlistentry> 1450 <varlistentry> 1451 <term><emphasis remap='I'>error_length</emphasis></term> 1452 <listitem> 1453 <para> 1454The length of the error_string_ret argument passed in. 1455 </para> 1456 </listitem> 1457 </varlistentry> 1458 <varlistentry> 1459 <term><emphasis remap='I'>error_string_ret</emphasis></term> 1460 <listitem> 1461 <para> 1462Returns a null-terminated error message, if any. The error_string_ret 1463points to user supplied memory. No more than error_length bytes are used. 1464 </para> 1465 </listitem> 1466 </varlistentry> 1467</variablelist> 1468 1469<para> 1470<function>IceListenForWellKnownConnections</function> constructs a list 1471of network IDs by prepending each known transport to port_id and then 1472attempts to create listen objects for the result. Port_id is the portnumber, 1473objname, or path portion of the ICE network ID. If a listen object for 1474a particular network ID cannot be created the network ID is ignored. 1475If no listen objects are created 1476<function>IceListenForWellKnownConnections</function> 1477returns failure. 1478</para> 1479 1480<para> 1481The return value of <function>IceListenForWellKnownConnections</function> 1482is zero for failure and a positive value for success. 1483</para> 1484 1485<para> 1486To close and free the listen objects, use 1487<function>IceFreeListenObjs</function> 1488</para> 1489 1490<funcsynopsis> 1491<funcprototype> 1492 <funcdef>void <function>IceFreeListenObjs</function></funcdef> 1493 <paramdef>int<parameter> count</parameter></paramdef> 1494 <paramdef>IceListenObj<parameter> *listen_objs</parameter></paramdef> 1495</funcprototype> 1496</funcsynopsis> 1497 1498<variablelist remap='IP'> 1499 <varlistentry> 1500 <term><emphasis remap='I'>count</emphasis></term> 1501 <listitem> 1502 <para>The number of listen objects.</para> 1503 </listitem> 1504 </varlistentry> 1505 <varlistentry> 1506 <term><emphasis remap='I'>listen_objs</emphasis></term> 1507 <listitem> 1508 <para>The listen objects.</para> 1509 </listitem> 1510 </varlistentry> 1511</variablelist> 1512 1513 1514<para> 1515To detect a new connection on a listen object, use 1516<function>select</function> on the descriptor associated with 1517the listen object. 1518</para> 1519 1520<para> 1521To obtain the descriptor, use 1522<function>IceGetListenConnectionNumber</function> 1523</para> 1524 1525<funcsynopsis> 1526<funcprototype> 1527 <funcdef>int <function>IceGetListenConnectionNumber</function></funcdef> 1528 <paramdef>IceListenObj<parameter> *listen_objs</parameter></paramdef> 1529</funcprototype> 1530</funcsynopsis> 1531 1532<variablelist remap='IP'> 1533 <varlistentry> 1534 <term><emphasis remap='I'>listen_obj</emphasis></term> 1535 <listitem> 1536 <para>The listen objects.</para> 1537 </listitem> 1538 </varlistentry> 1539</variablelist> 1540 1541<para> 1542To obtain the network ID string associated with a listen object, use 1543<function>IceGetListenConnectionString</function> 1544</para> 1545 1546 1547<funcsynopsis> 1548<funcprototype> 1549 <funcdef>char <function>IceGetListenConnectionString</function></funcdef> 1550 <paramdef>IceListenObj<parameter> listen_obj</parameter></paramdef> 1551</funcprototype> 1552</funcsynopsis> 1553 1554<variablelist remap='IP'> 1555 <varlistentry> 1556 <term><emphasis remap='I'>listen_obj</emphasis></term> 1557 <listitem> 1558 <para>The listen objects.</para> 1559 </listitem> 1560 </varlistentry> 1561</variablelist> 1562 1563<para>A network ID has the following format:</para> 1564 1565<informaltable pgwide='0' frame='none'> 1566 <tgroup cols='3' align='center'> 1567 <colspec colname='c1'/> 1568 <colspec colname='c2'/> 1569 <colspec colname='c3'/> 1570 <tbody> 1571 <row> 1572 <entry align='left'></entry> 1573 <entry align='left'>tcp/<hostname>:<portnumber></entry> 1574 <entry align='left'>or</entry> 1575 </row> 1576 <row> 1577 <entry align='left'></entry> 1578 <entry align='left'>decnet/<hostname>::<objname></entry> 1579 <entry align='left'>or</entry> 1580 </row> 1581 <row> 1582 <entry align='left'></entry> 1583 <entry align='left'>local/<hostname>:<path></entry> 1584 <entry align='left'></entry> 1585 </row> 1586 </tbody> 1587 </tgroup> 1588</informaltable> 1589 1590<para> 1591To compose a string containing a list of network IDs separated by commas 1592(the format recognized by <function>IceOpenConnection</function> 1593use <function>IceComposeNetworkIdList</function> 1594</para> 1595 1596<funcsynopsis> 1597<funcprototype> 1598 <funcdef>char <function>IceComposeNetworkIdList</function></funcdef> 1599 <paramdef>int<parameter> count</parameter></paramdef> 1600 <paramdef>IceListenObj<parameter> *listen_objs</parameter></paramdef> 1601</funcprototype> 1602</funcsynopsis> 1603 1604<variablelist remap='IP'> 1605 <varlistentry> 1606 <term><emphasis remap='I'>count</emphasis></term> 1607 <listitem> 1608 <para>The number of listen objects.</para> 1609 </listitem> 1610 </varlistentry> 1611 <varlistentry> 1612 <term><emphasis remap='I'>listen_objs</emphasis></term> 1613 <listitem> 1614 <para>The listen objects.</para> 1615 </listitem> 1616 </varlistentry> 1617</variablelist> 1618 1619</sect1> 1620 1621<sect1 id='host_based_authentication_for_ice_connec'> 1622<title>Host Based Authentication for ICE Connections</title> 1623 1624<para> 1625If authentication fails when a client attempts to open an 1626ICE connection and the initiating client has not required authentication, 1627a host based authentication procedure may be invoked to provide 1628a last chance for the client to connect. Each listen object has such a 1629callback associated with it, and this callback is set using the 1630<function>IceSetHostBasedAuthProc</function> 1631function. 1632</para> 1633 1634<funcsynopsis> 1635<funcprototype> 1636 <funcdef>void <function>IceSetHostBasedAuthProc</function></funcdef> 1637 <paramdef>IceListenObj<parameter> listen_obj</parameter></paramdef> 1638 <paramdef>IceHostBasedAuthProc<parameter> host_based_auth_proc</parameter></paramdef> 1639</funcprototype> 1640</funcsynopsis> 1641 1642<variablelist remap='IP'> 1643 <varlistentry> 1644 <term><emphasis remap='I'>IceListenObj</emphasis></term> 1645 <listitem> 1646 <para>The listen object.</para> 1647 </listitem> 1648 </varlistentry> 1649 <varlistentry> 1650 <term><emphasis remap='I'>host_based_auth_proc</emphasis></term> 1651 <listitem> 1652 <para>The host based authentication procedure.</para> 1653 </listitem> 1654 </varlistentry> 1655</variablelist> 1656 1657 1658<para> 1659By default, each listen object has no host based authentication procedure 1660associated with it. Passing NULL for host_based_auth_proc turns off 1661host based authentication if it was previously set. 1662</para> 1663 1664 1665<funcsynopsis> 1666<funcprototype> 1667 <funcdef>Bool <function>HostBasedAuthProc</function></funcdef> 1668 <paramdef>char<parameter> *host_name</parameter></paramdef> 1669</funcprototype> 1670</funcsynopsis> 1671 1672<variablelist remap='IP'> 1673 <varlistentry> 1674 <term><emphasis remap='I'>host_name</emphasis></term> 1675 <listitem> 1676 <para> 1677The host name of the client that tried to open an ICE connection. 1678 </para> 1679 </listitem> 1680 </varlistentry> 1681</variablelist> 1682 1683 1684<para> 1685The host_name argument is a string in the form 1686<emphasis remap='I'>protocol</emphasis>/ 1687<emphasis remap='I'>hostname</emphasis>, 1688where <emphasis remap='I'>protocol</emphasis> is one of 1689{tcp, decnet, local}. 1690</para> 1691 1692<para> 1693If <function>IceHostBasedAuthProc</function> returns 1694<function>True</function> 1695access will be granted, even though the original authentication failed. 1696Note that authentication can effectively be disabled by registering an 1697<function>IceHostBasedAuthProc</function> 1698which always returns <function>True</function> 1699</para> 1700 1701<para> 1702Host based authentication is also allowed at 1703<function>ProtocolSetup</function> time. 1704The callback is specified in the 1705<function>IceRegisterForProtocolReply</function> 1706function (see 1707<link linkend="protocol_registration"> 1708<xref linkend="protocol_registration"></xref></link>). 1709</para> 1710</sect1> 1711 1712<sect1 id='accepting_ice_connections'> 1713<title>Accepting ICE Connections</title> 1714 1715 1716<para> 1717After a connection attempt is detected on a listen object returned by 1718<function>IceListenForConnections</function> 1719you should call <function>IceAcceptConnection</function> 1720This returns a new opaque ICE connection object. 1721</para> 1722 1723<funcsynopsis> 1724<funcprototype> 1725 <funcdef>IceConn <function>IceAcceptConnection</function></funcdef> 1726 <paramdef>IceListenObj<parameter> listen_obj</parameter></paramdef> 1727 <paramdef>IceAcceptStatus<parameter> *status_ret</parameter></paramdef> 1728</funcprototype> 1729</funcsynopsis> 1730 1731 1732<variablelist remap='IP'> 1733 <varlistentry> 1734 <term><emphasis remap='I'>listen_obj</emphasis></term> 1735 <listitem> 1736<para>The listen object on which a new connection was detected.</para> 1737 </listitem> 1738 </varlistentry> 1739 </variablelist> 1740 <variablelist remap='IP'> 1741 <varlistentry> 1742 <term><emphasis remap='I'>status_ret</emphasis></term> 1743 <listitem> 1744<para>Return status information.</para> 1745 </listitem> 1746 </varlistentry> 1747</variablelist> 1748 1749 1750<para>The status_ret argument is set to one of the following values:</para> 1751<itemizedlist> 1752 <listitem> 1753<para><function>IceAcceptSuccess</function> 1754- the accept operation succeeded, 1755and the function returns a new connection object.</para> 1756 </listitem> 1757 <listitem> 1758<para><function>IceAcceptFailure</function> 1759- the accept operation failed, and the function returns NULL.</para> 1760 </listitem> 1761 <listitem> 1762<para><function>IceAcceptBadMalloc</function> 1763- a memory allocation failed, and the function returns NULL.</para> 1764 </listitem> 1765</itemizedlist> 1766 1767<para>In general, to detect new connections, you should call 1768<function>select</function> 1769on the file descriptors associated with the listen objects. 1770When a new connection is detected, the 1771<function>IceAcceptConnection</function> 1772function should be called. 1773<function>IceAcceptConnection</function> 1774may return a new ICE connection that is in a pending state. This is because 1775before the connection can become valid, authentication may be necessary. 1776Because the ICE library cannot block and wait for the connection to 1777become valid (infinite blocking can occur if the connecting client 1778does not act properly), the application must wait for the connection status 1779to become valid.</para> 1780 1781<para>The following pseudo-code demonstrates how connections are accepted:</para> 1782 1783<literallayout class="monospaced"> 1784new_ice_conn = IceAcceptConnection (listen_obj, &accept_status); 1785if (accept_status != IceAcceptSuccess) 1786{ 1787 close the file descriptor and return 1788} 1789 1790status = IceConnectionStatus (new_ice_conn); 1791time_start = time_now; 1792 1793while (status == IceConnectPending) 1794{ 1795 select() on {new_ice_conn, all open connections} 1796 1797 for (each ice_conn in the list of open connections) 1798 if (data ready on ice_conn) 1799 { 1800 status = IceProcessMessages (ice_conn, NULL, NULL); 1801 if (status == IceProcessMessagesIOError) 1802 IceCloseConnection(ice_conn); 1803 } 1804 if data ready on new_ice_conn 1805 { 1806 /* 1807 * IceProcessMessages is called until the connection 1808 * is non-pending. Doing so handles the connection 1809 * setup request and any authentication requirements. 1810 */ 1811 1812 IceProcessMessages ( new_ice_conn, NULL, NULL); 1813 status = IceConnectionStatus (new_ice_conn); 1814 } 1815 else 1816 { 1817 if (time_now - time_start > MAX_WAIT_TIME) 1818 status = IceConnectRejected; 1819 } 1820} 1821 1822if (status == IceConnectAccepted) 1823{ 1824 Add new_ice_conn to the list of open connections 1825} 1826else 1827{ 1828 IceCloseConnection 1829 new_ice_conn 1830} 1831</literallayout> 1832 1833<para>After 1834<function>IceAcceptConnection</function> 1835is called and the connection has been 1836validated, the client is ready to receive a 1837<function>ProtocolSetup</function> 1838(provided 1839that 1840<function>IceRegisterForProtocolReply</function> 1841was called) or send a 1842<function>ProtocolSetup</function> 1843(provided that 1844<function>IceRegisterForProtocolSetup</function> 1845was called).</para> 1846</sect1> 1847 1848<sect1 id='closing_ice_connections'> 1849<title>Closing ICE Connections</title> 1850 1851<para>To close an ICE connection created with 1852<function>IceOpenConnection</function> 1853or 1854<function>IceAcceptConnection</function> 1855use 1856<function>IceCloseConnection</function></para> 1857 1858<funcsynopsis> 1859<funcprototype> 1860 <funcdef>IceCloseStatus <function>IceCloseConnection</function></funcdef> 1861 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef> 1862</funcprototype> 1863</funcsynopsis> 1864 1865<variablelist remap='IP'> 1866 <varlistentry> 1867 <term><emphasis remap='I'>ice_conn</emphasis></term> 1868 <listitem> 1869 <para>The ICE connection to close.</para> 1870 </listitem> 1871 </varlistentry> 1872</variablelist> 1873 1874<para>To actually close an ICE connection, the following conditions 1875must be met:</para> 1876 1877<itemizedlist> 1878 <listitem> 1879<para>The <emphasis remap='I'>open reference count</emphasis> must have reached zero on this ICE connection. 1880When 1881<function>IceOpenConnection</function> 1882is called, it tries to use a previously opened 1883ICE connection. If it is able to use an existing connection, it increments 1884the open reference count on the connection by one. 1885So, to close an ICE connection, each call to 1886<function>IceOpenConnection</function> 1887must be matched with a call to 1888<function>IceCloseConnection</function> 1889The connection can be closed only 1890on the last call to 1891<function>IceCloseConnection</function></para> 1892 </listitem> 1893 <listitem> 1894<para>The <emphasis remap='I'>active protocol count</emphasis> must have reached zero. Each time a 1895<function>ProtocolSetup</function> 1896succeeds on the connection, the active protocol count 1897is incremented by one. When the client no longer expects to use the 1898protocol on the connection, the 1899<function>IceProtocolShutdown</function> 1900function should be called, which decrements the active protocol count 1901by one (see 1902<link linkend="protocol_setup_and_shutdown"> 1903<xref linkend="protocol_setup_and_shutdown"></xref></link>). 1904</para> 1905 </listitem> 1906 <listitem> 1907<para>If shutdown negotiation is enabled on the connection, the client on the other 1908side of the ICE connection must agree to have the connection closed.</para> 1909 1910<para><function>IceCloseConnection</function> 1911returns one of the following values:</para> 1912 </listitem> 1913 <listitem> 1914<para><function>IceClosedNow</function> 1915- the ICE connection was closed at this time. The watch procedures were 1916invoked and the connection was freed.</para> 1917 </listitem> 1918 <listitem> 1919<para><function>IceClosedASAP</function> 1920- an IO error had occurred on the connection, but 1921<function>IceCloseConnection</function> 1922is being called within a nested 1923<function>IceProcessMessages</function> 1924The watch procedures have been invoked at this time, but the connection 1925will be freed as soon as possible (when the nesting level reaches zero and 1926<function>IceProcessMessages</function> 1927returns a status of 1928<function>IceProcessMessagesConnectionClosed</function></para> 1929 </listitem> 1930 <listitem> 1931<para><function>IceConnectionInUse</function> 1932- the connection was not closed at this time, because it is being used by 1933other active protocols.</para> 1934 </listitem> 1935 <listitem> 1936<para><function>IceStartedShutdownNegotiation</function> 1937- the connection was not closed at this time and shutdown negotiation started 1938with the client on the other side of the ICE connection. When the connection 1939is actually closed, 1940<function>IceProcessMessages</function> 1941will return a status of 1942<function>IceProcessMessagesConnectionClosed</function></para> 1943 </listitem> 1944</itemizedlist> 1945 1946<para>When it is known that the client on the other side of the ICE connection 1947has terminated the connection without initiating shutdown negotiation, the 1948<function>IceSetShutdownNegotiation</function> 1949function should be called to turn off shutdown negotiation. This will prevent 1950<function>IceCloseConnection</function> 1951from writing to a broken connection.</para> 1952 1953<funcsynopsis> 1954<funcprototype> 1955 <funcdef>void <function>IceSetShutdownNegotiation</function></funcdef> 1956 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef> 1957 <paramdef>Bool<parameter> negotiate</parameter></paramdef> 1958</funcprototype> 1959</funcsynopsis> 1960 1961<variablelist remap='IP'> 1962 <varlistentry> 1963 <term><emphasis remap='I'>ice_conn</emphasis></term> 1964 <listitem> 1965 <para>A valid ICE connection object.</para> 1966 </listitem> 1967 </varlistentry> 1968 <varlistentry> 1969 <term><emphasis remap='I'>negotiate</emphasis></term> 1970 <listitem> 1971<para>If 1972<function>False</function> 1973shutdown negotiating will be turned off.</para> 1974 </listitem> 1975 </varlistentry> 1976</variablelist> 1977 1978<para>To check the shutdown negotiation status of an ICE connection, use 1979<function>IceCheckShutdownNegotiation</function></para> 1980 1981<funcsynopsis> 1982<funcprototype> 1983 <funcdef>Bool <function>IceCheckShutdownNegotiation</function></funcdef> 1984 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef> 1985</funcprototype> 1986</funcsynopsis> 1987 1988<variablelist remap='IP'> 1989 <varlistentry> 1990 <term><emphasis remap='I'>ice_conn</emphasis></term> 1991 <listitem> 1992 <para>A valid ICE connection object.</para> 1993 </listitem> 1994 </varlistentry> 1995</variablelist> 1996 1997 1998<para><function>IceCheckShutdownNegotiation</function> 1999returns 2000<function>True</function> 2001if shutdown negotiation will take place on the connection; 2002otherwise, it returns 2003<function>False</function> 2004Negotiation is on by default for a connection. It 2005can only be changed with the 2006<function>IceSetShutdownNegotiation</function> 2007function.</para> 2008</sect1> 2009 2010<sect1 id='connection_watch_procedures'> 2011<title>Connection Watch Procedures</title> 2012 2013<para>To add a watch procedure that will be called 2014each time ICElib opens a new connection via 2015<function>IceOpenConnection</function> 2016or 2017<function>IceAcceptConnection</function> 2018or closes a connection via 2019<function>IceCloseConnection</function> 2020use 2021<function>IceAddConnectionWatch</function></para> 2022 2023<funcsynopsis> 2024<funcprototype> 2025 <funcdef>Status <function>IceAddConnectionWatch</function></funcdef> 2026 <paramdef>IceWatchProc<parameter> watch_proc</parameter></paramdef> 2027 <paramdef>IcePointer<parameter> client_data</parameter></paramdef> 2028</funcprototype> 2029</funcsynopsis> 2030 2031<variablelist remap='IP'> 2032 <varlistentry> 2033 <term><emphasis remap='I'>watch_proc</emphasis></term> 2034 <listitem> 2035 <para> 2036The watch procedure to invoke when ICElib opens or closes a connection. 2037 </para> 2038 </listitem> 2039 </varlistentry> 2040 <varlistentry> 2041 <term><emphasis remap='I'>client_data</emphasis></term> 2042 <listitem> 2043 <para>This pointer will be passed to the watch procedure.</para> 2044 </listitem> 2045 </varlistentry> 2046</variablelist> 2047 2048 2049<para> 2050The return value of <function>IceAddConnectionWatch</function> 2051is zero for failure, and a positive value for success. 2052</para> 2053 2054<para> 2055Note that several calls to <function>IceOpenConnection</function> 2056might share the same ICE connection. In such a case, the watch procedure 2057is only invoked when the connection is first created (after authentication 2058succeeds). Similarly, because connections might be shared, the 2059watch procedure is called only if <function>IceCloseConnection</function> 2060actually closes the connection (right before the IceConn is freed). 2061</para> 2062 2063<para> 2064The watch procedures are very useful for applications that 2065need to add a file descriptor to a select mask when a new connection 2066is created and remove the file descriptor when the connection is destroyed. 2067Because connections are shared, knowing when to add and remove the file 2068descriptor from the select mask would be difficult without the watch 2069procedures. 2070</para> 2071 2072<para> 2073Multiple watch procedures may be registered with the ICE library. 2074No assumptions should be made about their order of invocation. 2075</para> 2076 2077<para> 2078If one or more ICE connections were already created by the ICE library at the 2079time the watch procedure is registered, the watch procedure will instantly 2080be invoked for each of these ICE connections (with the opening argument 2081set to <function>True</function> 2082</para> 2083 2084<para> 2085The watch procedure is of type <function>IceWatchProc</function> 2086</para> 2087 2088<funcsynopsis> 2089<funcprototype> 2090 <funcdef>void <function>WatchProc</function></funcdef> 2091 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef> 2092 <paramdef>IcePointer<parameter> client_data</parameter></paramdef> 2093 <paramdef>Bool<parameter> opening</parameter></paramdef> 2094 <paramdef>IcePointer<parameter> *watch_data</parameter></paramdef> 2095</funcprototype> 2096</funcsynopsis> 2097 2098<variablelist remap='IP'> 2099 <varlistentry> 2100 <term><emphasis remap='I'>ice_conn</emphasis></term> 2101 <listitem> 2102 <para> 2103The opened or closed ICE connection. Call 2104<function>IceConnectionNumber</function> 2105to get the file descriptor associated with this connection. 2106 </para> 2107 </listitem> 2108 </varlistentry> 2109 <varlistentry> 2110 <term><emphasis remap='I'>client_data</emphasis></term> 2111 <listitem> 2112 <para> 2113Client data specified in the call to 2114<function>IceAddConnectionWatch</function> 2115 </para> 2116 </listitem> 2117 </varlistentry> 2118 <varlistentry> 2119 <term><emphasis remap='I'>opening</emphasis></term> 2120 <listitem> 2121 <para> 2122If <function>True</function> the connection is being opened. If 2123<function>False</function> the connection is being closed. 2124 </para> 2125 </listitem> 2126 </varlistentry> 2127 <varlistentry> 2128 <term><emphasis remap='I'>watch_data</emphasis></term> 2129 <listitem> 2130 <para>Can be used to save a pointer to client data.</para> 2131 </listitem> 2132 </varlistentry> 2133</variablelist> 2134 2135<para> 2136If opening is <function>True</function> the client should set the 2137*watch_data pointer to any data it may need to save until the connection 2138is closed and the watch procedure is invoked again with opening set to 2139<function>False</function> 2140</para> 2141 2142<para> 2143To remove a watch procedure, use 2144<function>IceRemoveConnectionWatch</function> 2145</para> 2146 2147<funcsynopsis> 2148<funcprototype> 2149 <funcdef>void <function>IceRemoveConnectionWatch</function></funcdef> 2150 <paramdef>IceWatchProc<parameter> watch_proc</parameter></paramdef> 2151 <paramdef>IcePointer<parameter> client_data</parameter></paramdef> 2152</funcprototype> 2153</funcsynopsis> 2154 2155<variablelist remap='IP'> 2156 <varlistentry> 2157 <term><emphasis remap='I'>watch_proc</emphasis></term> 2158 <listitem> 2159 <para> 2160The watch procedure that was passed to 2161<function>IceAddConnectionWatch</function> 2162 </para> 2163 </listitem> 2164 </varlistentry> 2165 <varlistentry> 2166 <term><emphasis remap='I'>client_data</emphasis></term> 2167 <listitem> 2168 <para> 2169The client_data pointer that was passed to 2170<function>IceAddConnectionWatch</function> 2171 </para> 2172 </listitem> 2173 </varlistentry> 2174</variablelist> 2175 2176</sect1> 2177</chapter> 2178 2179<chapter id='protocol_setup_and_shutdown'> 2180<title>Protocol Setup and Shutdown</title> 2181 2182<para> 2183To activate a protocol on a given ICE connection, use 2184<function>IceProtocolSetup</function> 2185</para> 2186 2187<funcsynopsis> 2188<funcprototype> 2189 <funcdef>IceProtocolSetupStatus <function>IceProtocolSetup</function></funcdef> 2190 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef> 2191 <paramdef>int<parameter> my_opcode</parameter></paramdef> 2192 <paramdef>IcePointer<parameter> client_data</parameter></paramdef> 2193 <paramdef>Bool<parameter> must_authenticate</parameter></paramdef> 2194 <paramdef>int<parameter> *major_version_ret</parameter></paramdef> 2195 <paramdef>int<parameter> *minor_version_ret</parameter></paramdef> 2196 <paramdef>char<parameter> **vendor_ret</parameter></paramdef> 2197 <paramdef>char<parameter> **release_ret</parameter></paramdef> 2198 <paramdef>int<parameter> error_length</parameter></paramdef> 2199 <paramdef>char<parameter> *error_string_ret</parameter></paramdef> 2200</funcprototype> 2201</funcsynopsis> 2202 2203<variablelist remap='IP'> 2204 <varlistentry> 2205 <term><emphasis remap='I'>ice_conn</emphasis></term> 2206 <listitem> 2207 <para>A valid ICE connection object.</para> 2208 </listitem> 2209 </varlistentry> 2210 <varlistentry> 2211 <term><emphasis remap='I'>my_opcode</emphasis></term> 2212 <listitem> 2213 <para> 2214The major opcode of the protocol to be set up, as returned by 2215<function>IceRegisterForProtocolSetup</function> 2216 </para> 2217 </listitem> 2218 </varlistentry> 2219 <varlistentry> 2220 <term><emphasis remap='I'>client_data</emphasis></term> 2221 <listitem> 2222 <para> 2223The client data stored in this pointer will be passed to the 2224<function>IcePoProcessMsgProc</function> callback. 2225 </para> 2226 </listitem> 2227 </varlistentry> 2228 <varlistentry> 2229 <term><emphasis remap='I'>must_authenticate</emphasis></term> 2230 <listitem> 2231 <para> 2232If <function>True</function> the other client may 2233not bypass authentication. 2234 </para> 2235 </listitem> 2236 </varlistentry> 2237 <varlistentry> 2238 <term><emphasis remap='I'>major_version_ret</emphasis></term> 2239 <listitem> 2240 <para>The major version of the protocol to be used is returned.</para> 2241 </listitem> 2242 </varlistentry> 2243 <varlistentry> 2244 <term><emphasis remap='I'>minor_version_ret</emphasis></term> 2245 <listitem> 2246 <para>The minor version of the protocol to be used is returned.</para> 2247 </listitem> 2248 </varlistentry> 2249 <varlistentry> 2250 <term><emphasis remap='I'>vendor_ret</emphasis></term> 2251 <listitem> 2252 <para>The vendor string specified by the protocol acceptor.</para> 2253 </listitem> 2254 </varlistentry> 2255 <varlistentry> 2256 <term><emphasis remap='I'>release_ret</emphasis></term> 2257 <listitem> 2258 <para>The release string specified by the protocol acceptor.</para> 2259 </listitem> 2260 </varlistentry> 2261 <varlistentry> 2262 <term><emphasis remap='I'>error_length</emphasis></term> 2263 <listitem> 2264 <para> 2265Specifies the length of the error_string_ret argument passed in. 2266 </para> 2267 </listitem> 2268 </varlistentry> 2269 <varlistentry> 2270 <term><emphasis remap='I'>error_string_ret</emphasis></term> 2271 <listitem> 2272 <para> 2273Returns a null-terminated error message, if any. 2274The error_string_ret argument points to user supplied memory. 2275No more than error_length bytes are used. 2276 </para> 2277 </listitem> 2278 </varlistentry> 2279</variablelist> 2280 2281<para> 2282The vendor_ret and release_ret strings should be freed with 2283<function>free</function> when no longer needed. 2284</para> 2285 2286<para> 2287<function>IceProtocolSetup</function> returns one of the following values: 2288</para> 2289 2290<itemizedlist> 2291 <listitem> 2292 <para> 2293<function>IceProtocolSetupSuccess</function> - the major_version_ret, 2294minor_version_ret, vendor_ret, release_ret are set. 2295 </para> 2296 </listitem> 2297 <listitem> 2298 <para> 2299<function>IceProtocolSetupFailure</function> or 2300<function>IceProtocolSetupIOError</function> 2301- check error_string_ret for failure reason. The major_version_ret, 2302minor_version_ret, vendor_ret, release_ret are not set. 2303 </para> 2304 </listitem> 2305 <listitem> 2306 <para> 2307<function>IceProtocolAlreadyActive</function> 2308- this protocol is already active on this connection. 2309The major_version_ret, minor_version_ret, vendor_ret, release_ret 2310are not set. 2311 </para> 2312 </listitem> 2313</itemizedlist> 2314 2315<para> 2316To notify the ICE library when a given protocol will no longer be used 2317on an ICE connection, use <function>IceProtocolShutdown</function> 2318</para> 2319 2320<funcsynopsis> 2321<funcprototype> 2322 <funcdef>Status <function>IceProtocolShutdown</function></funcdef> 2323 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef> 2324 <paramdef>int<parameter> major_opcode</parameter></paramdef> 2325</funcprototype> 2326</funcsynopsis> 2327 2328<variablelist remap='IP'> 2329 <varlistentry> 2330 <term><emphasis remap='I'>ice_conn</emphasis></term> 2331 <listitem> 2332 <para>A valid ICE connection object.</para> 2333 </listitem> 2334 </varlistentry> 2335 <varlistentry> 2336 <term><emphasis remap='I'>major_opcode</emphasis></term> 2337 <listitem> 2338 <para>The major opcode of the protocol to shut down.</para> 2339 </listitem> 2340 </varlistentry> 2341</variablelist> 2342 2343 2344<para> 2345The return value of <function>IceProtocolShutdown</function> 2346is zero for failure and a positive value for success. 2347</para> 2348 2349<para> 2350Failure will occur if the major opcode was never registered OR the protocol 2351of the major opcode was never activated on the connection. By activated, 2352we mean that a <function>ProtocolSetup</function> succeeded on the connection. 2353Note that ICE does not define how each sub-protocol triggers a 2354protocol shutdown. 2355</para> 2356</chapter> 2357 2358<chapter id='processing_messages'> 2359<title>Processing Messages</title> 2360 2361 2362<para>To process incoming messages on an ICE connection, use 2363<function>IceProcessMessages</function></para> 2364 2365<funcsynopsis> 2366<funcprototype> 2367 <funcdef>IceProcessMessagesStatus <function>IceProcessMessages</function></funcdef> 2368 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef> 2369 <paramdef>IceReplyWaitInfo<parameter> *reply_wait</parameter></paramdef> 2370 <paramdef>Bool<parameter> *reply_ready_ret</parameter></paramdef> 2371</funcprototype> 2372</funcsynopsis> 2373 2374<variablelist remap='IP'> 2375 <varlistentry> 2376 <term><emphasis remap='I'>ice_conn</emphasis></term> 2377 <listitem> 2378 <para>A valid ICE connection object.</para> 2379 </listitem> 2380 </varlistentry> 2381 <varlistentry> 2382 <term><emphasis remap='I'>reply_wait</emphasis></term> 2383 <listitem> 2384 <para>Indicates if a reply is being waited for.</para> 2385 </listitem> 2386 </varlistentry> 2387 <varlistentry> 2388 <term><emphasis remap='I'>reply_ready_ret</emphasis></term> 2389 <listitem> 2390 <para> 2391If set to <function>True</function> on return, a reply is ready. 2392 </para> 2393 </listitem> 2394 </varlistentry> 2395</variablelist> 2396 2397<para> 2398<function>IceProcessMessages</function> is used in two ways: 2399</para> 2400 2401<itemizedlist> 2402 <listitem> 2403 <para> 2404In the first, a client may generate a message and block by calling 2405<function>IceProcessMessages</function> repeatedly until it gets its reply. 2406 </para> 2407 </listitem> 2408 <listitem> 2409 <para> 2410In the second, a client calls <function>IceProcessMessages</function> 2411with reply_wait set to NULL in response to <function>select</function> 2412showing that there is data to read on the ICE connection. 2413The ICE library may process zero or more complete messages. 2414Note that messages that are not blocked for are always processed by 2415invoking callbacks. 2416 </para> 2417 </listitem> 2418</itemizedlist> 2419 2420<para> 2421<function>IceReplyWaitInfo</function> contains the major/minor opcodes 2422and sequence number of the message for which a reply is being awaited. 2423It also contains a pointer to the reply message to be filled in (the 2424protocol library should cast this <function>IcePointer</function> 2425to the appropriate reply type). In most 2426cases, the reply will have some fixed-size part, and the client waiting 2427for the reply will have provided a pointer to a structure to hold 2428this fixed-size data. If there is variable-length data, it would be 2429expected that the 2430<function>IcePoProcessMsgProc</function> 2431callback will have to allocate additional 2432memory and store pointer(s) to that memory in the fixed-size 2433structure. If the entire data is variable length (for example, a single 2434variable-length string), then the client waiting for the reply would probably 2435just pass a pointer to fixed-size space to hold a pointer, and the 2436<function>IcePoProcessMsgProc</function> 2437callback would allocate the storage and store the pointer. 2438It is the responsibility of the client receiving the reply to 2439free up any memory allocated on its behalf. 2440</para> 2441 2442<literallayout class="monospaced"> 2443typedef struct { 2444 unsigned long sequence_of_request; 2445 int major_opcode_of_request; 2446 int minor_opcode_of_request; 2447 IcePointer reply; 2448} IceReplyWaitInfo; 2449</literallayout> 2450 2451<para> 2452If reply_wait is not NULL and 2453<function>IceProcessMessages</function> 2454has a reply or error to return in response to this reply_wait 2455(that is, no callback was generated), then the reply_ready_ret argument 2456will be set to <function>True</function> 2457</para> 2458 2459<para> 2460If reply_wait is NULL, then the caller may also pass NULL for 2461reply_ready_ret and be guaranteed that no value will be stored in 2462this pointer. 2463</para> 2464 2465<para> 2466<function>IceProcessMessages</function> returns one of the following values: 2467</para> 2468 2469<itemizedlist> 2470 <listitem> 2471 <para> 2472<function>IceProcessMessagesSuccess</function> - no error occurred. 2473 </para> 2474 </listitem> 2475 <listitem> 2476 <para> 2477<function>IceProcessMessagesIOError</function> - an IO error occurred, 2478and the caller must explicitly close the connection by calling 2479<function>IceCloseConnection</function> 2480 </para> 2481 </listitem> 2482 <listitem> 2483 <para> 2484<function>IceProcessMessagesConnectionClosed</function> 2485- the ICE connection has been closed (closing of the connection was deferred 2486because of shutdown negotiation, or because the 2487<function>IceProcessMessages</function> 2488nesting level was not zero). Do not attempt 2489to access the ICE connection at this point, since it has been freed. 2490 </para> 2491 </listitem> 2492</itemizedlist> 2493 2494</chapter> 2495 2496<chapter id='ping'> 2497<title>Ping</title> 2498 2499<para> 2500To send a "Ping" message to the client on the other side of the 2501ICE connection, use <function>IcePing</function> 2502</para> 2503 2504<funcsynopsis> 2505<funcprototype> 2506 <funcdef>Status <function>IcePing</function></funcdef> 2507 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef> 2508 <paramdef>IcePingReplyProc<parameter> ping_reply_proc</parameter></paramdef> 2509 <paramdef>IcePointer<parameter> client_data</parameter></paramdef> 2510</funcprototype> 2511</funcsynopsis> 2512 2513<variablelist remap='IP'> 2514 <varlistentry> 2515 <term><emphasis remap='I'>ice_conn</emphasis></term> 2516 <listitem> 2517 <para>A valid ICE connection object.</para> 2518 </listitem> 2519 </varlistentry> 2520 <varlistentry> 2521 <term><emphasis remap='I'>ping_reply_proc</emphasis></term> 2522 <listitem> 2523 <para>The callback to invoke when the Ping reply arrives.</para> 2524 </listitem> 2525 </varlistentry> 2526 <varlistentry> 2527 <term><emphasis remap='I'>client_data</emphasis></term> 2528 <listitem> 2529 <para> 2530This pointer will be passed to the <function>IcePingReplyProc</function> 2531callback. 2532 </para> 2533 </listitem> 2534 </varlistentry> 2535</variablelist> 2536 2537 2538<para><function>IcePing</function> 2539returns zero for failure and a positive value for success.</para> 2540 2541<para>When 2542<function>IceProcessMessages</function> 2543processes the Ping reply, it will invoke the 2544<function>IcePingReplyProc</function> 2545callback.</para> 2546 2547<funcsynopsis> 2548<funcprototype> 2549 <funcdef>void <function>PingReplyProc</function></funcdef> 2550 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef> 2551 <paramdef>IcePointer<parameter> client_data</parameter></paramdef> 2552</funcprototype> 2553</funcsynopsis> 2554 2555<variablelist remap='IP'> 2556 <varlistentry> 2557 <term><emphasis remap='I'>ice_conn</emphasis></term> 2558 <listitem> 2559<para>A valid ICE connection object.</para> 2560 </listitem> 2561 </varlistentry> 2562 <varlistentry> 2563 <term><emphasis remap='I'>client_data</emphasis></term> 2564 <listitem> 2565<para>The client data specified in the call to 2566<function>IcePing</function></para> 2567 </listitem> 2568 </varlistentry> 2569</variablelist> 2570 2571</chapter> 2572 2573<chapter id='using_icelib_informational_functions'> 2574<title>Using ICElib Informational Functions</title> 2575 2576<funcsynopsis> 2577<funcprototype> 2578 <funcdef>IceConnectStatus <function>IceConnectionStatus</function></funcdef> 2579 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef> 2580</funcprototype> 2581</funcsynopsis> 2582 2583<para><function>IceConnectionStatus</function> 2584returns the status of an ICE connection. The possible return values are:</para> 2585 2586<itemizedlist> 2587 <listitem> 2588<para><function>IceConnectPending</function> 2589- the connection is not valid yet (that is, authentication is taking place). 2590This is only relevant to connections created by 2591<function>IceAcceptConnection</function></para> 2592 </listitem> 2593 <listitem> 2594<para><function>IceConnectAccepted</function> 2595- the connection has been accepted. 2596This is only relevant to connections created by 2597<function>IceAcceptConnection</function></para> 2598 </listitem> 2599 <listitem> 2600<para><function>IceConnectRejected</function> 2601- the connection had been rejected (that is, authentication failed). 2602This is only relevant to connections created by 2603<function>IceAcceptConnection</function></para> 2604 </listitem> 2605 <listitem> 2606<para><function>IceConnectIOError</function> 2607- an IO error has occurred on the connection.</para> 2608 </listitem> 2609</itemizedlist> 2610 2611<funcsynopsis> 2612<funcprototype> 2613 <funcdef>char <function> *IceVendor</function></funcdef> 2614 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef> 2615</funcprototype> 2616</funcsynopsis> 2617 2618<para><function>IceVendor</function> 2619returns the ICE library vendor identification 2620for the other side of the connection. 2621The string should be freed with a call to 2622<function>free</function> 2623when no longer needed.</para> 2624 2625<funcsynopsis> 2626<funcprototype> 2627 <funcdef>char <function> *IceRelease</function></funcdef> 2628 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef> 2629</funcprototype> 2630</funcsynopsis> 2631 2632<para><function>IceRelease</function> 2633returns the release identification of the ICE library 2634on the other side of the connection. 2635The string should be freed with a call to 2636<function>free</function> 2637when no longer needed.</para> 2638 2639<funcsynopsis> 2640<funcprototype> 2641 <funcdef>int <function> IceProtocolVersion</function></funcdef> 2642 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef> 2643</funcprototype> 2644</funcsynopsis> 2645 2646<para><function>IceProtocolVersion</function> 2647returns the major version of the ICE protocol on this connection.</para> 2648 2649<funcsynopsis> 2650<funcprototype> 2651 <funcdef>int <function> IceProtocolRevision</function></funcdef> 2652 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef> 2653</funcprototype> 2654</funcsynopsis> 2655 2656 2657<para><function>IceProtocolRevision</function> 2658returns the minor version of the ICE protocol on this connection.</para> 2659 2660<funcsynopsis> 2661<funcprototype> 2662 <funcdef>int <function> IceConnectionNumber</function></funcdef> 2663 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef> 2664</funcprototype> 2665</funcsynopsis> 2666 2667 2668<para><function>IceConnectionNumber</function> 2669returns the file descriptor of this ICE connection.</para> 2670 2671<funcsynopsis> 2672<funcprototype> 2673 <funcdef>char <function> *IceConnectionString</function></funcdef> 2674 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef> 2675</funcprototype> 2676</funcsynopsis> 2677 2678<para><function>IceConnectionString</function> 2679returns the network ID of the client that 2680accepted this connection. The string should be freed with a call to 2681<function>free</function> 2682when no longer needed.</para> 2683 2684<funcsynopsis> 2685<funcprototype> 2686 <funcdef>unsigned long <function> IceLastSentSequenceNumber</function></funcdef> 2687 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef> 2688</funcprototype> 2689</funcsynopsis> 2690 2691 2692<para><function>IceLastSentSequenceNumber</function> 2693returns the sequence number of the last message sent on this ICE connection.</para> 2694 2695<funcsynopsis> 2696<funcprototype> 2697 <funcdef>unsigned long <function> IceLastReceivedSequenceNumber</function></funcdef> 2698 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef> 2699</funcprototype> 2700</funcsynopsis> 2701 2702<para><function>IceLastReceivedSequenceNumber</function> 2703returns the sequence number of the last message received on this 2704ICE connection.</para> 2705 2706<funcsynopsis> 2707<funcprototype> 2708 <funcdef>Bool <function> IceSwapping</function></funcdef> 2709 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef> 2710</funcprototype> 2711</funcsynopsis> 2712 2713 2714<para><function>IceSwapping</function> 2715returns 2716<function>True</function> 2717if byte swapping is necessary when reading messages on the ICE connection.</para> 2718 2719<funcsynopsis> 2720<funcprototype> 2721 <funcdef>IcePointer <function> IceGetContext</function></funcdef> 2722 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef> 2723</funcprototype> 2724</funcsynopsis> 2725 2726<para><function>IceGetContext</function> 2727returns the context associated with a connection created by 2728<function>IceOpenConnection</function></para> 2729</chapter> 2730 2731<chapter id='ice_messages'> 2732<title>ICE Messages</title> 2733 2734<para> 2735All ICE messages have a standard 8-byte header. The ICElib macros that 2736read and write messages rely on the following naming convention for message 2737headers: 2738</para> 2739 2740<literallayout class='monospaced'> 2741 CARD8 major_opcode; 2742 CARD8 minor_opcode; 2743 CARD8 data[2]; 2744 CARD32 length B32; 2745</literallayout> 2746 2747<para> 2748The 3rd and 4th bytes of the message header can be used as needed. 2749The length field is specified in units of 8 bytes. 2750</para> 2751 2752<sect1 id='sending_ice_messages'> 2753<title>Sending ICE Messages</title> 2754 2755<para> 2756The ICE library maintains an output buffer used for generating messages. 2757Protocol libraries layered on top of ICE may choose to batch messages 2758together and flush the output buffer at appropriate times. 2759</para> 2760 2761<para> 2762If an IO error has occurred on an ICE connection, all write operations 2763will be ignored. For further information, see 2764<link linkend="error_handling"> 2765<xref linkend="error_handling"></xref></link>. 2766</para> 2767 2768 2769<para> 2770To get the size of the ICE output buffer, use 2771<function>IceGetOutBufSize</function> 2772</para> 2773 2774<funcsynopsis> 2775<funcprototype> 2776 <funcdef>int <function> IceGetOutBufSize</function></funcdef> 2777 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef> 2778</funcprototype> 2779</funcsynopsis> 2780 2781<variablelist remap='IP'> 2782 <varlistentry> 2783 <term><emphasis remap='I'>ice_conn</emphasis></term> 2784 <listitem> 2785 <para>A valid ICE connection object.</para> 2786 </listitem> 2787 </varlistentry> 2788</variablelist> 2789 2790 2791<para> 2792To flush the ICE output buffer, use <function>IceFlush</function> 2793</para> 2794 2795<funcsynopsis> 2796<funcprototype> 2797 <funcdef>int <function> IceFlush</function></funcdef> 2798 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef> 2799</funcprototype> 2800</funcsynopsis> 2801 2802<variablelist remap='IP'> 2803 <varlistentry> 2804 <term><emphasis remap='I'>ice_conn</emphasis></term> 2805 <listitem> 2806 <para>A valid ICE connection object.</para> 2807 </listitem> 2808 </varlistentry> 2809</variablelist> 2810 2811<para> 2812Note that the output buffer may be implicitly flushed if there is 2813insufficient space to generate a message. 2814</para> 2815 2816<para>The following macros can be used to generate ICE messages:</para> 2817 2818<funcsynopsis> 2819<funcprototype> 2820 <funcdef><function> IceGetHeader</function></funcdef> 2821 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef> 2822 <paramdef>int<parameter> major_opcode</parameter></paramdef> 2823 <paramdef>int<parameter> minor_opcode</parameter></paramdef> 2824 <paramdef>int<parameter> header_size</parameter></paramdef> 2825 <paramdef><C_data_type><parameter> *pmsg</parameter></paramdef> 2826</funcprototype> 2827</funcsynopsis> 2828 2829<variablelist remap='IP'> 2830 <varlistentry> 2831 <term><emphasis remap='I'>ice_conn</emphasis></term> 2832 <listitem> 2833 <para>A valid ICE connection object.</para> 2834 </listitem> 2835 </varlistentry> 2836 <varlistentry> 2837 <term><emphasis remap='I'>major_opcode</emphasis></term> 2838 <listitem> 2839 <para>The major opcode of the message.</para> 2840 </listitem> 2841 </varlistentry> 2842 <varlistentry> 2843 <term><emphasis remap='I'>minor_opcode</emphasis></term> 2844 <listitem> 2845 <para>The minor opcode of the message.</para> 2846 </listitem> 2847 </varlistentry> 2848 <varlistentry> 2849 <term><emphasis remap='I'>header_size</emphasis></term> 2850 <listitem> 2851 <para>The size of the message header (in bytes).</para> 2852 </listitem> 2853 </varlistentry> 2854 <varlistentry> 2855 <term><emphasis remap='I'><C_data_type></emphasis></term> 2856 <listitem> 2857 <para>The actual C data type of the message header.</para> 2858 </listitem> 2859 </varlistentry> 2860 <varlistentry> 2861 <term><emphasis remap='I'>pmsg</emphasis></term> 2862 <listitem> 2863 <para> 2864The message header pointer. After this macro is called, the 2865library can store data in the message header. 2866 </para> 2867 </listitem> 2868 </varlistentry> 2869</variablelist> 2870 2871 2872<para> 2873<function>IceGetHeader</function> 2874is used to set up a message header on an ICE connection. 2875It sets the major and minor opcodes of the message, and initializes 2876the message's length to the length of the header. If additional 2877variable length data follows, the message's length field should be 2878updated. 2879</para> 2880 2881 2882<funcsynopsis> 2883<funcprototype> 2884 <funcdef><function> IceGetHeaderExtra</function></funcdef> 2885 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef> 2886 <paramdef>int<parameter> major_opcode</parameter></paramdef> 2887 <paramdef>int<parameter> minor_opcode</parameter></paramdef> 2888 <paramdef>int<parameter> header_size</parameter></paramdef> 2889 <paramdef>int<parameter> extra</parameter></paramdef> 2890 <paramdef><C_data_type><parameter> *pmsg</parameter></paramdef> 2891 <paramdef>char<parameter> *pdata</parameter></paramdef> 2892</funcprototype> 2893</funcsynopsis> 2894 2895<variablelist remap='IP'> 2896 <varlistentry> 2897 <term><emphasis remap='I'>ice_conn</emphasis></term> 2898 <listitem> 2899 <para>A valid ICE connection object.</para> 2900 </listitem> 2901 </varlistentry> 2902 <varlistentry> 2903 <term><emphasis remap='I'>major_opcode</emphasis></term> 2904 <listitem> 2905 <para>The major opcode of the message.</para> 2906 </listitem> 2907 </varlistentry> 2908 <varlistentry> 2909 <term><emphasis remap='I'>minor_opcode</emphasis></term> 2910 <listitem> 2911 <para>The minor opcode of the message.</para> 2912 </listitem> 2913 </varlistentry> 2914 <varlistentry> 2915 <term><emphasis remap='I'>header_size</emphasis></term> 2916 <listitem> 2917 <para>The size of the message header (in bytes).</para> 2918 </listitem> 2919 </varlistentry> 2920 <varlistentry> 2921 <term><emphasis remap='I'>extra</emphasis></term> 2922 <listitem> 2923 <para> 2924The size of the extra data beyond the header (in 8-byte units). 2925 </para> 2926 </listitem> 2927 </varlistentry> 2928 <varlistentry> 2929 <term><emphasis remap='I'><C_data_type></emphasis></term> 2930 <listitem> 2931 <para>The actual C data type of the message header.</para> 2932 </listitem> 2933 </varlistentry> 2934 <varlistentry> 2935 <term><emphasis remap='I'>pmsg</emphasis></term> 2936 <listitem> 2937 <para> 2938The message header pointer. After this macro is called, the 2939library can store data in the message header. 2940 </para> 2941 </listitem> 2942 </varlistentry> 2943 <varlistentry> 2944 <term><emphasis remap='I'>pdata</emphasis></term> 2945 <listitem> 2946 <para> 2947Returns a pointer to the ICE output buffer that points 2948immediately after the message header. The variable length 2949data should be stored here. If there was not enough room 2950in the ICE output buffer, pdata is set to NULL. 2951 </para> 2952 </listitem> 2953 </varlistentry> 2954</variablelist> 2955 2956 2957<para> 2958<function>IceGetHeaderExtra</function> 2959is used to generate a message with a fixed (and relatively small) amount 2960of variable length data. The complete message must fit in the ICE output 2961buffer. 2962</para> 2963 2964<funcsynopsis> 2965<funcprototype> 2966 <funcdef><function> IceSimpleMessage</function></funcdef> 2967 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef> 2968 <paramdef>int<parameter> major_opcode</parameter></paramdef> 2969 <paramdef>int<parameter> minor_opcode</parameter></paramdef> 2970</funcprototype> 2971</funcsynopsis> 2972 2973<variablelist remap='IP'> 2974 <varlistentry> 2975 <term><emphasis remap='I'>ice_conn</emphasis></term> 2976 <listitem> 2977 <para>A valid ICE connection object.</para> 2978 </listitem> 2979 </varlistentry> 2980 <varlistentry> 2981 <term><emphasis remap='I'>major_opcode</emphasis></term> 2982 <listitem> 2983 <para>The major opcode of the message.</para> 2984 </listitem> 2985 </varlistentry> 2986 <varlistentry> 2987 <term><emphasis remap='I'>minor_opcode</emphasis></term> 2988 <listitem> 2989 <para>The minor opcode of the message.</para> 2990 </listitem> 2991 </varlistentry> 2992</variablelist> 2993 2994<para> 2995<function>IceSimpleMessage</function> 2996is used to generate a message that is identical 2997in size to the ICE header message, and has no additional data. 2998</para> 2999 3000<funcsynopsis> 3001<funcprototype> 3002 <funcdef><function> IceErrorHeader</function></funcdef> 3003 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef> 3004 <paramdef>int<parameter> offending_major_opcode</parameter></paramdef> 3005 <paramdef>int<parameter> offending_minor_opcode</parameter></paramdef> 3006 <paramdef>int<parameter> offending_sequence_num</parameter></paramdef> 3007 <paramdef>int<parameter> severity</parameter></paramdef> 3008 <paramdef>int<parameter> error_class</parameter></paramdef> 3009 <paramdef>int<parameter> data_length</parameter></paramdef> 3010</funcprototype> 3011</funcsynopsis> 3012 3013<variablelist remap='IP'> 3014 <varlistentry> 3015 <term><emphasis remap='I'>ice_conn</emphasis></term> 3016 <listitem> 3017 <para>A valid ICE connection object.</para> 3018 </listitem> 3019 </varlistentry> 3020 <varlistentry> 3021 <term><emphasis remap='I'>offending_major_opcode</emphasis></term> 3022 <listitem> 3023 <para> 3024The major opcode of the protocol in which an error was detected. 3025 </para> 3026 </listitem> 3027 </varlistentry> 3028 <varlistentry> 3029 <term><emphasis remap='I'>offending_minor_opcode</emphasis></term> 3030 <listitem> 3031 <para> 3032The minor opcode of the protocol in which an error was detected. 3033 </para> 3034 </listitem> 3035 </varlistentry> 3036 <varlistentry> 3037 <term><emphasis remap='I'>offending_sequence_num</emphasis></term> 3038 <listitem> 3039 <para>The sequence number of the message that caused the error.</para> 3040 </listitem> 3041 </varlistentry> 3042 <varlistentry> 3043 <term><emphasis remap='I'>severity</emphasis></term> 3044 <listitem> 3045 <para> 3046<function>IceCanContinue</function> 3047<function>IceFatalToProtocol</function> 3048or 3049<function>IceFatalToConnection</function> 3050 </para> 3051 </listitem> 3052 </varlistentry> 3053 <varlistentry> 3054 <term><emphasis remap='I'>error_class</emphasis></term> 3055 <listitem> 3056 <para>The error class.</para> 3057 </listitem> 3058 </varlistentry> 3059 <varlistentry> 3060 <term><emphasis remap='I'>data_length</emphasis></term> 3061 <listitem> 3062 <para> 3063Length of data (in 8-byte units) to be written after the header. 3064 </para> 3065 </listitem> 3066 </varlistentry> 3067</variablelist> 3068 3069<para> 3070<function>IceErrorHeader</function> sets up an error message header. 3071</para> 3072 3073<para> 3074Note that the two clients connected by ICE may be using different 3075major opcodes for a given protocol. The offending_major_opcode passed 3076to this macro is the major opcode of the protocol for the client 3077sending the error message. 3078</para> 3079 3080<para> 3081Generic errors, which are common to all protocols, have classes 3082in the range 0x8000..0xFFFF. 3083See the <emphasis remap='I'>Inter-Client Exchange Protocol</emphasis> 3084standard for more details. 3085</para> 3086 3087<informaltable pgwide='0' frame='none'> 3088 <tgroup cols='2' align='center'> 3089 <colspec colname='c1'/> 3090 <colspec colname='c2'/> 3091 <tbody> 3092 <row> 3093 <entry align='left'>IceBadMinor</entry> 3094 <entry align='left'>0x8000</entry> 3095 </row> 3096 <row> 3097 <entry align='left'>IceBadState</entry> 3098 <entry align='left'>0x8001</entry> 3099 </row> 3100 <row> 3101 <entry align='left'>IceBadLength</entry> 3102 <entry align='left'>0x8002</entry> 3103 </row> 3104 <row> 3105 <entry align='left'>IceBadValue</entry> 3106 <entry align='left'>0x8003</entry> 3107 </row> 3108 </tbody> 3109 </tgroup> 3110</informaltable> 3111 3112<para>Per-protocol errors have classes in the range 0x0000-0x7fff.</para> 3113 3114<para> 3115To write data to an ICE connection, use the 3116<function>IceWriteData</function> macro. If the data fits into the 3117ICE output buffer, it is copied there. Otherwise, the ICE output buffer 3118is flushed and the data is directly sent. 3119</para> 3120 3121<para> 3122This macro is used in conjunction with 3123<function>IceGetHeader</function> and 3124<function>IceErrorHeader</function> 3125</para> 3126 3127<funcsynopsis> 3128<funcprototype> 3129 <funcdef><function> IceWriteData</function></funcdef> 3130 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef> 3131 <paramdef>int<parameter> bytes</parameter></paramdef> 3132 <paramdef>char<parameter> *data</parameter></paramdef> 3133</funcprototype> 3134</funcsynopsis> 3135 3136<variablelist remap='IP'> 3137 <varlistentry> 3138 <term><emphasis remap='I'>ice_conn</emphasis></term> 3139 <listitem> 3140 <para>A valid ICE connection object.</para> 3141 </listitem> 3142 </varlistentry> 3143 <varlistentry> 3144 <term><emphasis remap='I'>bytes</emphasis></term> 3145 <listitem> 3146 <para>The number of bytes to write.</para> 3147 </listitem> 3148 </varlistentry> 3149 <varlistentry> 3150 <term><emphasis remap='I'>data</emphasis></term> 3151 <listitem> 3152 <para>The data to write.</para> 3153 </listitem> 3154 </varlistentry> 3155</variablelist> 3156 3157 3158<para> 3159To write data as 16-bit quantities, use <function>IceWriteData16</function> 3160</para> 3161 3162<funcsynopsis> 3163<funcprototype> 3164 <funcdef><function> IceWriteData16</function></funcdef> 3165 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef> 3166 <paramdef>int<parameter> bytes</parameter></paramdef> 3167 <paramdef>char<parameter> *data</parameter></paramdef> 3168</funcprototype> 3169</funcsynopsis> 3170 3171<variablelist remap='IP'> 3172 <varlistentry> 3173 <term><emphasis remap='I'>ice_conn</emphasis></term> 3174 <listitem> 3175 <para>A valid ICE connection object.</para> 3176 </listitem> 3177 </varlistentry> 3178 <varlistentry> 3179 <term><emphasis remap='I'>bytes</emphasis></term> 3180 <listitem> 3181 <para>The number of bytes to write.</para> 3182 </listitem> 3183 </varlistentry> 3184 <varlistentry> 3185 <term><emphasis remap='I'>data</emphasis></term> 3186 <listitem> 3187 <para>The data to write.</para> 3188 </listitem> 3189 </varlistentry> 3190</variablelist> 3191 3192<para> 3193To write data as 32-bit quantities, use <function>IceWriteData32</function> 3194</para> 3195 3196 3197<funcsynopsis> 3198<funcprototype> 3199 <funcdef><function> IceWriteData32</function></funcdef> 3200 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef> 3201 <paramdef>int<parameter> bytes</parameter></paramdef> 3202 <paramdef>char<parameter> *data</parameter></paramdef> 3203</funcprototype> 3204</funcsynopsis> 3205 3206<variablelist remap='IP'> 3207 <varlistentry> 3208 <term><emphasis remap='I'>ice_conn</emphasis></term> 3209 <listitem> 3210 <para>A valid ICE connection object.</para> 3211 </listitem> 3212 </varlistentry> 3213 <varlistentry> 3214 <term><emphasis remap='I'>bytes</emphasis></term> 3215 <listitem> 3216 <para>The number of bytes to write.</para> 3217 </listitem> 3218 </varlistentry> 3219 <varlistentry> 3220 <term><emphasis remap='I'>data</emphasis></term> 3221 <listitem> 3222 <para>The data to write.</para> 3223 </listitem> 3224 </varlistentry> 3225</variablelist> 3226 3227<para> 3228To write data as 32-bit quantities, use <function>IceWriteData32</function> 3229</para> 3230 3231<para> 3232To bypass copying data to the ICE output buffer, use 3233<function>IceSendData</function> to directly send data over the network 3234connection. If necessary, the ICE output buffer is first flushed. 3235</para> 3236 3237<funcsynopsis> 3238<funcprototype> 3239 <funcdef><function> IceSendData</function></funcdef> 3240 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef> 3241 <paramdef>int<parameter> bytes</parameter></paramdef> 3242 <paramdef>char<parameter> *data</parameter></paramdef> 3243</funcprototype> 3244</funcsynopsis> 3245 3246<variablelist remap='IP'> 3247 <varlistentry> 3248 <term><emphasis remap='I'>ice_conn</emphasis></term> 3249 <listitem> 3250 <para>A valid ICE connection object.</para> 3251 </listitem> 3252 </varlistentry> 3253 <varlistentry> 3254 <term><emphasis remap='I'>bytes</emphasis></term> 3255 <listitem> 3256 <para>The number of bytes to send.</para> 3257 </listitem> 3258 </varlistentry> 3259 <varlistentry> 3260 <term><emphasis remap='I'>data</emphasis></term> 3261 <listitem> 3262 <para>The data to send.</para> 3263 </listitem> 3264 </varlistentry> 3265</variablelist> 3266 3267 3268<para> 3269To force 32-bit or 64-bit alignment, use <function>IceWritePad</function> 3270A maximum of 7 pad bytes can be specified. 3271</para> 3272 3273<funcsynopsis> 3274<funcprototype> 3275 <funcdef><function> IceWritePad</function></funcdef> 3276 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef> 3277 <paramdef>int<parameter> bytes</parameter></paramdef> 3278 <paramdef>char<parameter> *data</parameter></paramdef> 3279</funcprototype> 3280</funcsynopsis> 3281 3282<variablelist remap='IP'> 3283 <varlistentry> 3284 <term><emphasis remap='I'>ice_conn</emphasis></term> 3285 <listitem> 3286 <para>A valid ICE connection object.</para> 3287 </listitem> 3288 </varlistentry> 3289 <varlistentry> 3290 <term><emphasis remap='I'>bytes</emphasis></term> 3291 <listitem> 3292 <para>The number of bytes to write.</para> 3293 </listitem> 3294 </varlistentry> 3295 <varlistentry> 3296 <term><emphasis remap='I'>data</emphasis></term> 3297 <listitem> 3298 <para>The number of pad bytes to write.</para> 3299 </listitem> 3300 </varlistentry> 3301</variablelist> 3302 3303</sect1> 3304 3305<sect1 id='reading_ice_messages'> 3306<title>Reading ICE Messages</title> 3307 3308 3309<para> 3310The ICE library maintains an input buffer used for reading messages. 3311If the ICE library chooses to perform nonblocking reads (this is 3312implementation-dependent), then for every read operation that it makes, 3313zero or more complete messages may be read into the input buffer. As 3314a result, for all of the macros described in this section that read 3315messages, an actual read operation will occur on the connection only if 3316the data is not already present in the input buffer. 3317</para> 3318 3319 3320<para> 3321To get the size of the ICE input buffer, use 3322<function>IceGetInBufSize</function> 3323</para> 3324 3325<funcsynopsis> 3326<funcprototype> 3327 <funcdef>int<function> IceGetInBufSize</function></funcdef> 3328 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef> 3329</funcprototype> 3330</funcsynopsis> 3331 3332<variablelist remap='IP'> 3333 <varlistentry> 3334 <term><emphasis remap='I'>ice_conn</emphasis></term> 3335 <listitem> 3336 <para>A valid ICE connection object.</para> 3337 </listitem> 3338 </varlistentry> 3339</variablelist> 3340 3341<para> 3342When reading messages, care must be taken to check for IO errors. If 3343any IO error occurs in reading any part of a message, the message should 3344be thrown out. After using any of the macros described below for reading 3345messages, the <function>IceValidIO</function> 3346macro can be used to check if an IO error occurred on the 3347connection. After an IO error has occurred on an ICE connection, all 3348read operations will be ignored. For further information, see 3349<link linkend="error_handling"> 3350<xref linkend="error_handling"></xref></link>. 3351</para> 3352 3353 3354<funcsynopsis> 3355<funcprototype> 3356 <funcdef>Bool<function> IceValidIO</function></funcdef> 3357 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef> 3358</funcprototype> 3359</funcsynopsis> 3360 3361<variablelist remap='IP'> 3362 <varlistentry> 3363 <term><emphasis remap='I'>ice_conn</emphasis></term> 3364 <listitem> 3365 <para>A valid ICE connection object.</para> 3366 </listitem> 3367 </varlistentry> 3368</variablelist> 3369 3370<para>The following macros can be used to read ICE messages.</para> 3371 3372<funcsynopsis> 3373<funcprototype> 3374 <funcdef><function> IceReadSimpleMessage</function></funcdef> 3375 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef> 3376 <paramdef><C_data_type><parameter> *pmsg</parameter></paramdef> 3377</funcprototype> 3378</funcsynopsis> 3379 3380<variablelist remap='IP'> 3381 <varlistentry> 3382 <term><emphasis remap='I'>ice_conn</emphasis></term> 3383 <listitem> 3384 <para>A valid ICE connection object.</para> 3385 </listitem> 3386 </varlistentry> 3387 <varlistentry> 3388 <term><emphasis remap='I'><C_data_type></emphasis></term> 3389 <listitem> 3390 <para>The actual C data type of the message header.</para> 3391 </listitem> 3392 </varlistentry> 3393 <varlistentry> 3394 <term><emphasis remap='I'>pmsg</emphasis></term> 3395 <listitem> 3396 <para>This pointer is set to the message header.</para> 3397 </listitem> 3398 </varlistentry> 3399</variablelist> 3400 3401<para> 3402<function>IceReadSimpleMessage</function> 3403is used for messages that are identical in size to the 8-byte ICE header, but 3404use the spare 2 bytes in the header to encode additional data. Note that the 3405ICE library always reads in these first 8 bytes, so it can obtain the major 3406opcode of the message. <function>IceReadSimpleMessage</function> 3407simply returns a pointer to these 8 bytes; it does not actually read any data 3408into the input buffer. 3409</para> 3410 3411<para> 3412For a message with variable length data, there are two ways of reading 3413the message. One method involves reading the complete message in one 3414pass using <function>IceReadCompleteMessage</function> 3415The second method involves reading the message header (note that this may 3416be larger than the 8-byte ICE header), then reading 3417the variable length data in chunks (see 3418<function>IceReadMessageHeader</function> and 3419<function>IceReadData</function> 3420</para> 3421 3422 3423<funcsynopsis> 3424<funcprototype> 3425 <funcdef><function> IceReadCompleteMessage</function></funcdef> 3426 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef> 3427 <paramdef>int<parameter> header_size</parameter></paramdef> 3428 <paramdef><C_data_type><parameter> *pmsg</parameter></paramdef> 3429 <paramdef>char<parameter> *pdata</parameter></paramdef> 3430</funcprototype> 3431</funcsynopsis> 3432 3433<variablelist remap='IP'> 3434 <varlistentry> 3435 <term><emphasis remap='I'>ice_conn</emphasis></term> 3436 <listitem> 3437 <para>A valid ICE connection object.</para> 3438 </listitem> 3439 </varlistentry> 3440 <varlistentry> 3441 <term><emphasis remap='I'>header_size</emphasis></term> 3442 <listitem> 3443 <para>The size of the message header (in bytes).</para> 3444 </listitem> 3445 </varlistentry> 3446 <varlistentry> 3447 <term><emphasis remap='I'><C_data_type></emphasis></term> 3448 <listitem> 3449 <para>The actual C data type of the message header.</para> 3450 </listitem> 3451 </varlistentry> 3452 <varlistentry> 3453 <term><emphasis remap='I'>pmsg</emphasis></term> 3454 <listitem> 3455 <para>This pointer is set to the message header.</para> 3456 </listitem> 3457 </varlistentry> 3458 <varlistentry> 3459 <term><emphasis remap='I'>pdata</emphasis></term> 3460 <listitem> 3461 <para> 3462This pointer is set to the variable length data of the message. 3463 </para> 3464 </listitem> 3465 </varlistentry> 3466</variablelist> 3467 3468<para> 3469If the ICE input buffer has sufficient space, 3470<function>IceReadCompleteMessage</function> 3471will read the complete message into the 3472ICE input buffer. Otherwise, a buffer will be allocated to hold the 3473variable length data. After the call, the pdata argument should 3474be checked against NULL to make sure that there was sufficient memory 3475to allocate the buffer. 3476</para> 3477 3478<para> 3479After calling <function>IceReadCompleteMessage</function> 3480and processing the message, <function>IceDisposeCompleteMessage</function> 3481should be called. 3482</para> 3483 3484 3485<funcsynopsis> 3486<funcprototype> 3487 <funcdef><function> IceDisposeCompleteMessage</function></funcdef> 3488 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef> 3489 <paramdef>char<parameter> *pdata</parameter></paramdef> 3490</funcprototype> 3491</funcsynopsis> 3492 3493<variablelist remap='IP'> 3494 <varlistentry> 3495 <term><emphasis remap='I'>ice_conn</emphasis></term> 3496 <listitem> 3497 <para>A valid ICE connection object.</para> 3498 </listitem> 3499 </varlistentry> 3500 <varlistentry> 3501 <term><emphasis remap='I'>pdata</emphasis></term> 3502 <listitem> 3503 <para> 3504The pointer to the variable length data returned in 3505<function>IceReadCompleteMessage</function> 3506 </para> 3507 </listitem> 3508 </varlistentry> 3509</variablelist> 3510 3511<para> 3512If a buffer had to be allocated to hold the variable length data (because 3513it did not fit in the ICE input buffer), it is freed here by ICElib. 3514</para> 3515 3516 3517<funcsynopsis> 3518<funcprototype> 3519 <funcdef><function> IceReadMessageHeader</function></funcdef> 3520 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef> 3521 <paramdef>int<parameter> header_size</parameter></paramdef> 3522 <paramdef><C_data_type><parameter> *pmsg</parameter></paramdef> 3523</funcprototype> 3524</funcsynopsis> 3525 3526<variablelist remap='IP'> 3527 <varlistentry> 3528 <term><emphasis remap='I'>ice_conn</emphasis></term> 3529 <listitem> 3530 <para>A valid ICE connection object.</para> 3531 </listitem> 3532 </varlistentry> 3533 <varlistentry> 3534 <term><emphasis remap='I'>header_size</emphasis></term> 3535 <listitem> 3536 <para>The size of the message header (in bytes).</para> 3537 </listitem> 3538 </varlistentry> 3539 <varlistentry> 3540 <term><emphasis remap='I'><C_data_type></emphasis></term> 3541 <listitem> 3542 <para>The actual C data type of the message header.</para> 3543 </listitem> 3544 </varlistentry> 3545 <varlistentry> 3546 <term><emphasis remap='I'>pmsg</emphasis></term> 3547 <listitem> 3548 <para>This pointer is set to the message header.</para> 3549 </listitem> 3550 </varlistentry> 3551</variablelist> 3552 3553<para> 3554<function>IceReadMessageHeader</function> reads just the message header. 3555The rest of the data should be read with the 3556<function>IceReadData</function> 3557family of macros. This method of reading a message should be used when the 3558variable length data must be read in chunks. 3559</para> 3560 3561 3562<para> 3563To read data directly into a user supplied buffer, use 3564<function>IceReadData</function> 3565</para> 3566 3567<funcsynopsis> 3568<funcprototype> 3569 <funcdef><function> IceReadData</function></funcdef> 3570 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef> 3571 <paramdef>int<parameter> bytes</parameter></paramdef> 3572 <paramdef>char<parameter> *pdata</parameter></paramdef> 3573</funcprototype> 3574</funcsynopsis> 3575 3576<variablelist remap='IP'> 3577 <varlistentry> 3578 <term><emphasis remap='I'>ice_conn</emphasis></term> 3579 <listitem> 3580 <para>A valid ICE connection object.</para> 3581 </listitem> 3582 </varlistentry> 3583 <varlistentry> 3584 <term><emphasis remap='I'>bytes</emphasis></term> 3585 <listitem> 3586 <para>The number of bytes to read.</para> 3587 </listitem> 3588 </varlistentry> 3589 <varlistentry> 3590 <term><emphasis remap='I'>pdata</emphasis></term> 3591 <listitem> 3592 <para>The data is read into this user supplied buffer.</para> 3593 </listitem> 3594 </varlistentry> 3595</variablelist> 3596 3597 3598<para> 3599To read data as 16-bit quantities, use <function>IceReadData16</function> 3600</para> 3601 3602<funcsynopsis> 3603<funcprototype> 3604 <funcdef><function> IceReadData16</function></funcdef> 3605 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef> 3606 <paramdef>Bool<parameter> swap</parameter></paramdef> 3607 <paramdef>int<parameter> bytes</parameter></paramdef> 3608 <paramdef>char<parameter> *pdata</parameter></paramdef> 3609</funcprototype> 3610</funcsynopsis> 3611 3612<variablelist remap='IP'> 3613 <varlistentry> 3614 <term><emphasis remap='I'>ice_conn</emphasis></term> 3615 <listitem> 3616 <para>A valid ICE connection object.</para> 3617 </listitem> 3618 </varlistentry> 3619 <varlistentry> 3620 <term><emphasis remap='I'>swap</emphasis></term> 3621 <listitem> 3622 <para> 3623If <function>True,</function> the values will be byte swapped. 3624 </para> 3625 </listitem> 3626 </varlistentry> 3627 <varlistentry> 3628 <term><emphasis remap='I'>bytes</emphasis></term> 3629 <listitem> 3630 <para>The number of bytes to read.</para> 3631 </listitem> 3632 </varlistentry> 3633 <varlistentry> 3634 <term><emphasis remap='I'>pdata</emphasis></term> 3635 <listitem> 3636 <para>The data is read into this user supplied buffer.</para> 3637 </listitem> 3638 </varlistentry> 3639</variablelist> 3640 3641 3642<para> 3643To read data as 32-bit quantities, use <function>IceReadData32</function> 3644</para> 3645 3646<funcsynopsis> 3647<funcprototype> 3648 <funcdef><function> IceReadData32</function></funcdef> 3649 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef> 3650 <paramdef>Bool<parameter> swap</parameter></paramdef> 3651 <paramdef>int<parameter> bytes</parameter></paramdef> 3652 <paramdef>char<parameter> *pdata</parameter></paramdef> 3653</funcprototype> 3654</funcsynopsis> 3655 3656<variablelist remap='IP'> 3657 <varlistentry> 3658 <term><emphasis remap='I'>ice_conn</emphasis></term> 3659 <listitem> 3660 <para>A valid ICE connection object.</para> 3661 </listitem> 3662 </varlistentry> 3663 <varlistentry> 3664 <term><emphasis remap='I'>swap</emphasis></term> 3665 <listitem> 3666 <para> 3667If <function>True,</function> the values will be byte swapped. 3668 </para> 3669 </listitem> 3670 </varlistentry> 3671 <varlistentry> 3672 <term><emphasis remap='I'>bytes</emphasis></term> 3673 <listitem> 3674 <para>The number of bytes to read.</para> 3675 </listitem> 3676 </varlistentry> 3677 <varlistentry> 3678 <term><emphasis remap='I'>pdata</emphasis></term> 3679 <listitem> 3680 <para>The data is read into this user supplied buffer.</para> 3681 </listitem> 3682 </varlistentry> 3683</variablelist> 3684 3685<para>To force 32-bit or 64-bit alignment, use 3686<function>IceReadPad</function> 3687A maximum of 7 pad bytes can be specified.</para> 3688 3689<funcsynopsis> 3690<funcprototype> 3691 <funcdef><function> IceReadPad</function></funcdef> 3692 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef> 3693 <paramdef>int<parameter> bytes</parameter></paramdef> 3694</funcprototype> 3695</funcsynopsis> 3696 3697<variablelist remap='IP'> 3698 <varlistentry> 3699 <term><emphasis remap='I'>ice_conn</emphasis></term> 3700 <listitem> 3701 <para>A valid ICE connection object.</para> 3702 </listitem> 3703 </varlistentry> 3704 <varlistentry> 3705 <term><emphasis remap='I'>bytes</emphasis></term> 3706 <listitem> 3707 <para>The number of pad bytes.</para> 3708 </listitem> 3709 </varlistentry> 3710</variablelist> 3711 3712</sect1> 3713</chapter> 3714 3715<chapter id='error_handling'> 3716<title>Error Handling</title> 3717 3718 3719<para>There are two default error handlers in ICElib:</para> 3720 3721<itemizedlist> 3722 <listitem> 3723 <para> 3724One to handle typically fatal conditions (for example, 3725a connection dying because a machine crashed) 3726 </para> 3727 </listitem> 3728 <listitem> 3729 <para>One to handle ICE-specific protocol errors</para> 3730 </listitem> 3731</itemizedlist> 3732 3733<para> 3734These error handlers can be changed to user-supplied routines if you 3735prefer your own error handling and can be changed as often as you like. 3736</para> 3737 3738 3739<para> 3740To set the ICE error handler, use <function>IceSetErrorHandler</function> 3741</para> 3742 3743<funcsynopsis> 3744<funcprototype> 3745 <funcdef><function> IceSetErrorHandler</function></funcdef> 3746 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef> 3747 <paramdef>int<parameter> bytes</parameter></paramdef> 3748</funcprototype> 3749</funcsynopsis> 3750 3751<variablelist remap='IP'> 3752 <varlistentry> 3753 <term><emphasis remap='I'>handler</emphasis></term> 3754 <listitem> 3755 <para> 3756The ICE error handler. You should pass NULL to restore the default handler. 3757 </para> 3758 </listitem> 3759 </varlistentry> 3760</variablelist> 3761 3762<para> 3763<function>IceSetErrorHandler</function> returns the previous error handler. 3764</para> 3765 3766<para> 3767The ICE error handler is invoked when an unexpected ICE protocol 3768error (major opcode 0) is encountered. The action of the default 3769handler is to print an explanatory message to 3770<function>stderr</function> 3771and if the severity is fatal, call 3772<function>exit</function> 3773with a nonzero value. If exiting 3774is undesirable, the application should register its own error handler. 3775</para> 3776 3777<para> 3778Note that errors in other protocol 3779domains should be handled by their respective libraries (these libraries 3780should have their own error handlers). 3781</para> 3782 3783<para> 3784An ICE error handler has the type of <function>IceErrorHandler</function> 3785</para> 3786 3787<funcsynopsis> 3788<funcprototype> 3789 <funcdef>void<function> IceErrorHandler</function></funcdef> 3790 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef> 3791 <paramdef>Bool<parameter> swap</parameter></paramdef> 3792 <paramdef>int<parameter> offending_minor_opcode</parameter></paramdef> 3793 <paramdef>unsigned long<parameter> offending_sequence_num</parameter></paramdef> 3794 <paramdef>int<parameter> error_class</parameter></paramdef> 3795 <paramdef>int<parameter> severity</parameter></paramdef> 3796 <paramdef>IcePointer<parameter> values</parameter></paramdef> 3797</funcprototype> 3798</funcsynopsis> 3799 3800<variablelist remap='IP'> 3801 <varlistentry> 3802 <term><emphasis remap='I'>handler</emphasis></term> 3803 <listitem> 3804 <para>The ICE connection object.</para> 3805 </listitem> 3806 </varlistentry> 3807 <varlistentry> 3808 <term><emphasis remap='I'>swap</emphasis></term> 3809 <listitem> 3810 <para>A flag that indicates if the values need byte swapping.</para> 3811 </listitem> 3812 </varlistentry> 3813 <varlistentry> 3814 <term><emphasis remap='I'>offending_minor_opcode</emphasis></term> 3815 <listitem> 3816 <para>The ICE minor opcode of the offending message.</para> 3817 </listitem> 3818 </varlistentry> 3819 <varlistentry> 3820 <term><emphasis remap='I'>offending_sequence_num</emphasis></term> 3821 <listitem> 3822 <para>The sequence number of the offending message.</para> 3823 </listitem> 3824 </varlistentry> 3825 <varlistentry> 3826 <term><emphasis remap='I'>error_class</emphasis></term> 3827 <listitem> 3828 <para>The error class of the offending message.</para> 3829 </listitem> 3830 </varlistentry> 3831 <varlistentry> 3832 <term><emphasis remap='I'>severity</emphasis></term> 3833 <listitem> 3834 <para> 3835<function>IceCanContinue</function> 3836<function>IceFatalToProtocol</function> 3837or 3838<function>IceFatalToConnection</function> 3839 </para> 3840 </listitem> 3841 </varlistentry> 3842 <varlistentry> 3843 <term><emphasis remap='I'>values</emphasis></term> 3844 <listitem> 3845 <para> 3846Any additional error values specific to the minor opcode and class. 3847 </para> 3848 </listitem> 3849 </varlistentry> 3850</variablelist> 3851 3852 3853<para>The following error classes are defined at the ICE level:</para> 3854 3855<literallayout remap='Ds'> 3856<function>IceBadMinor</function> 3857<function>IceBadState</function> 3858<function>IceBadLength</function> 3859<function>IceBadValue</function> 3860<function>IceBadMajor</function> 3861<function>IceNoAuth</function> 3862<function>IceNoVersion</function> 3863<function>IceSetupFailed</function> 3864<function>IceAuthRejected</function> 3865<function>IceAuthFailed</function> 3866<function>IceProtocolDuplicate</function> 3867<function>IceMajorOpcodeDuplicate</function> 3868<function>IceUnknownProtocol</function> 3869</literallayout> 3870 3871<para> 3872For further information, see 3873the <emphasis remap='I'>Inter-Client Exchange Protocol</emphasis> standard. 3874</para> 3875 3876 3877<para> 3878To handle fatal I/O errors, use <function>IceSetIOErrorHandler</function> 3879</para> 3880 3881 3882<funcsynopsis> 3883<funcprototype> 3884 <funcdef>IceIOErrorHandler<function> IceSetIOErrorHandler</function></funcdef> 3885 <paramdef>IceIOErrorHandler<parameter> handler</parameter></paramdef> 3886</funcprototype> 3887</funcsynopsis> 3888 3889<variablelist remap='IP'> 3890 <varlistentry> 3891 <term><emphasis remap='I'>handler</emphasis></term> 3892 <listitem> 3893 <para> 3894The I/O error handler. You should pass NULL to restore the default handler. 3895 </para> 3896 </listitem> 3897 </varlistentry> 3898</variablelist> 3899 3900<para> 3901<function>IceSetIOErrorHandler</function> returns the previous 3902IO error handler. 3903</para> 3904 3905<para> 3906An ICE I/O error handler has the type of 3907<function>IceIOErrorHandler</function> 3908</para> 3909 3910<funcsynopsis> 3911<funcprototype> 3912 <funcdef>void<function> IceIOErrorHandler</function></funcdef> 3913 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef> 3914</funcprototype> 3915</funcsynopsis> 3916 3917<variablelist remap='IP'> 3918 <varlistentry> 3919 <term><emphasis remap='I'>ice_conn</emphasis></term> 3920 <listitem><para>The ICE connection object.</para></listitem> 3921 </varlistentry> 3922</variablelist> 3923 3924 3925<para> There are two ways of handling IO errors in ICElib:</para> 3926 3927<itemizedlist> 3928 <listitem> 3929 <para> 3930In the first, the IO error handler does whatever is necessary 3931to respond to the IO error and then returns, but it does not call 3932<function>IceCloseConnection</function> 3933The ICE connection is given a "bad IO" status, and all future reads 3934and writes to the connection are ignored. The next time 3935<function>IceProcessMessages</function> 3936is called it will return a status of 3937<function>IceProcessMessagesIOError</function> 3938At that time, the application should call 3939<function>IceCloseConnection</function> 3940 </para> 3941 </listitem> 3942 <listitem> 3943 <para> 3944In the second, the IO error handler does call 3945<function>IceCloseConnection</function> 3946and then uses the <function>longjmp</function> 3947call to get back to the application's main event loop. The 3948<function>setjmp</function> and 3949<function>longjmp</function> 3950calls may not work properly on all platforms, 3951and special care must be taken to avoid memory leaks. 3952Therefore, this second model is less desirable. 3953 </para> 3954 </listitem> 3955</itemizedlist> 3956 3957<para> 3958Before the application I/O error handler is invoked, protocol libraries 3959that were interested in being notified of I/O errors will have their 3960<function>IceIOErrorProc</function> 3961handlers invoked. This handler is set up in the protocol registration 3962functions (see <function>IceRegisterForProtocolSetup</function> and 3963<function>IceRegisterForProtocolReply</function> 3964and could be used to clean up state specific to the protocol. 3965</para> 3966 3967 3968<funcsynopsis> 3969<funcprototype> 3970 <funcdef>void<function> IceIOErrorProc</function></funcdef> 3971 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef> 3972</funcprototype> 3973</funcsynopsis> 3974 3975<variablelist remap='IP'> 3976 <varlistentry> 3977 <term><emphasis remap='I'>ice_conn</emphasis></term> 3978 <listitem><para>The ICE connection object.</para></listitem> 3979 </varlistentry> 3980</variablelist> 3981 3982<para> 3983Note that every <function>IceIOErrorProc</function> 3984callback must return. This is required 3985because each active protocol must be notified of the broken connection, 3986and the application IO error handler must be invoked afterwards. 3987</para> 3988</chapter> 3989 3990<chapter id='multithreading_support'> 3991<title>Multi-Threading Support</title> 3992 3993 3994<para>To declare that multiple threads in an application will be using the ICE 3995library, use 3996<function>IceInitThreads</function></para> 3997 3998<literallayout remap='FD'> 3999Status IceInitThreads() 4000</literallayout> 4001 4002 4003<para>The 4004<function>IceInitThreads</function> 4005function must be the first ICElib function a 4006multi-threaded program calls. It must complete before any other ICElib 4007call is made. 4008<function>IceInitThreads</function> 4009returns a nonzero status if and only if it was able 4010to initialize the threads package successfully. 4011It is safe to call 4012<function>IceInitThreads</function> 4013more than once, although the threads package will only be initialized once.</para> 4014 4015<para>Protocol libraries layered on top of ICElib will have to lock critical 4016sections of code that access an ICE connection (for example, when 4017generating messages). Two calls, which are generally implemented as 4018macros, are provided:</para> 4019 4020<funcsynopsis> 4021<funcprototype> 4022 <funcdef>void<function> IceLockConn</function></funcdef> 4023 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef> 4024</funcprototype> 4025</funcsynopsis> 4026 4027<funcsynopsis> 4028<funcprototype> 4029 <funcdef>void<function> IceUnlockConn</function></funcdef> 4030 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef> 4031</funcprototype> 4032</funcsynopsis> 4033 4034<variablelist remap='IP'> 4035 <varlistentry> 4036 <term><emphasis remap='I'>ice_conn</emphasis></term> 4037 <listitem><para>The ICE connection object.</para></listitem> 4038 </varlistentry> 4039</variablelist> 4040 4041<para>To keep an ICE connection locked across several ICElib calls, applications use 4042<function>IceAppLockConn</function> 4043and 4044<function>IceAppUnlockConn</function></para> 4045 4046<funcsynopsis> 4047<funcprototype> 4048 <funcdef>void<function> IceAppLockConn</function></funcdef> 4049 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef> 4050</funcprototype> 4051</funcsynopsis> 4052 4053<variablelist remap='IP'> 4054 <varlistentry> 4055 <term><emphasis remap='I'>ice_conn</emphasis></term> 4056 <listitem><para>The ICE connection object.</para></listitem> 4057 </varlistentry> 4058</variablelist> 4059 4060 4061<para>The 4062<function>IceAppLockConn</function> 4063function completely locks out other threads using the connection 4064until 4065<function>IceAppUnlockConn</function> 4066is called. Other threads attempting to use ICElib 4067calls on the connection will block. 4068If the program has not previously called 4069<function>IceInitThreads</function> 4070<function>IceAppLockConn</function> 4071has no effect.</para> 4072 4073<funcsynopsis> 4074<funcprototype> 4075 <funcdef>void<function> IceAppUnlockConn</function></funcdef> 4076 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef> 4077</funcprototype> 4078</funcsynopsis> 4079 4080<variablelist remap='IP'> 4081 <varlistentry> 4082 <term><emphasis remap='I'>ice_conn</emphasis></term> 4083 <listitem><para>The ICE connection object.</para></listitem> 4084 </varlistentry> 4085</variablelist> 4086 4087<para>The 4088<function>IceAppUnlockConn</function> 4089function allows other threads to complete ICElib 4090calls on the connection that were blocked by a previous call to 4091<function>IceAppLockConn</function> 4092from this thread. If the program has not previously called 4093<function>IceInitThreads</function> 4094<function>IceAppUnlockConn</function> 4095has no effect.</para> 4096</chapter> 4097 4098<chapter id='miscellaneous_functions'> 4099<title>Miscellaneous Functions</title> 4100 4101 4102 4103 4104<para>To allocate scratch space (for example, when generating 4105messages with variable data), use 4106<function>IceAllocScratch</function> 4107Each ICE connection has one scratch space associated with it. 4108The scratch space starts off as empty and grows as needed. 4109The contents of the scratch space is not guaranteed to be preserved 4110after any ICElib function is called.</para> 4111 4112 4113<funcsynopsis> 4114<funcprototype> 4115 <funcdef>char<function> *IceAllocScratch</function></funcdef> 4116 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef> 4117 <paramdef>unsigned long<parameter> size</parameter></paramdef> 4118</funcprototype> 4119</funcsynopsis> 4120 4121<variablelist remap='IP'> 4122 <varlistentry> 4123 <term><emphasis remap='I'>ice_conn</emphasis></term> 4124 <listitem><para>The ICE connection object.</para></listitem> 4125 </varlistentry> 4126 <varlistentry> 4127 <term><emphasis remap='I'>size</emphasis></term> 4128 <listitem><para>The number of bytes required.</para></listitem> 4129 </varlistentry> 4130</variablelist> 4131 4132<para>Note that the memory returned by 4133<function>IceAllocScratch</function> 4134should not be freed by the caller. 4135The ICE library will free the memory when the ICE connection is closed.</para> 4136</chapter> 4137 4138<chapter id='acknowledgements'> 4139<title>Acknowledgements</title> 4140 4141 4142<para> 4143Thanks to Bob Scheifler for his thoughtful input on the design 4144of the ICE library. Thanks also to Jordan Brown, Larry Cable, Donna Converse, 4145Clive Feather, Stephen Gildea, Vania Joloboff, Kaleb Keithley, 4146Stuart Marks, Hiro Miyamoto, Ralph Swick, Jim VanGilder, and Mike Wexler. 4147</para> 4148</chapter> 4149 4150<appendix id="authentication_utility_functions"> 4151<title>Authentication Utility Functions</title> 4152 4153 4154<para> 4155As discussed in this document, the means by which authentication data 4156is obtained by the ICE library (for 4157<function>ConnectionSetup</function> 4158messages or 4159<function>ProtocolSetup</function> 4160messages) is implementation-dependent.† 4161<footnote remap='FS'> 4162<para>The X Consortium's ICElib implementation assumes the presence of an 4163ICE authority file. 4164</para></footnote> 4165</para> 4166 4167<para> 4168This appendix describes some utility functions that manipulate an 4169ICE authority file. The authority file can be used to pass authentication 4170data between clients. 4171</para> 4172 4173<para>The basic operations on the .ICEauthority file are:</para> 4174 4175<itemizedlist> 4176 <listitem> 4177 <para>Get file name</para> 4178 </listitem> 4179 <listitem> 4180 <para>Lock</para> 4181 </listitem> 4182 <listitem> 4183 <para>Unlock</para> 4184 </listitem> 4185 <listitem> 4186 <para>Read entry</para> 4187 </listitem> 4188 <listitem> 4189 <para>Write entry</para> 4190 </listitem> 4191 <listitem> 4192 <para>Search for entry</para> 4193 </listitem> 4194</itemizedlist> 4195 4196<para> 4197These are fairly low-level operations, and it is expected that a program, 4198like "iceauth", would exist to add, remove, and display entries in the file. 4199</para> 4200 4201<para> 4202In order to use these utility functions, the 4203<<symbol role='Pn'>X11/ICE/ICEutil.h</symbol>> 4204header file must be included. 4205</para> 4206 4207<para> 4208An entry in the .ICEauthority file is defined by the following data structure: 4209</para> 4210 4211 4212<literallayout class="monospaced"> 4213typedef struct { 4214 char *protocol_name; 4215 unsigned short protocol_data_length; 4216 char *protocol_data; 4217 char *network_id; 4218 char *auth_name; 4219 unsigned short auth_data_length; 4220 char *auth_data; 4221} IceAuthFileEntry; 4222</literallayout> 4223 4224 4225<para> 4226The protocol_name member is either "ICE" for connection setup authentication 4227or the subprotocol name, such as "XSMP". For each entry, protocol specific 4228data can be specified in the protocol_data member. This can be used 4229to search for old entries that need to be removed from the file. 4230</para> 4231 4232<para> 4233The network_id member is the network ID of the client accepting 4234authentication (for example, the network ID of a session manager). 4235A network ID has the following form: 4236</para> 4237 4238<informaltable pgwide='0' frame='none'> 4239 <tgroup cols='3' align='center'> 4240 <colspec colname='c1'/> 4241 <colspec colname='c2'/> 4242 <colspec colname='c3'/> 4243 <tbody> 4244 <row> 4245 <entry align='left'></entry> 4246 <entry align='left'>tcp/<hostname>:<portnumber></entry> 4247 <entry align='left'>or</entry> 4248 </row> 4249 <row> 4250 <entry align='left'></entry> 4251 <entry align='left'>decnet/<hostname>::<objname></entry> 4252 <entry align='left'>or</entry> 4253 </row> 4254 <row> 4255 <entry align='left'></entry> 4256 <entry align='left'>local/<hostname>:<path></entry> 4257 <entry align='left'></entry> 4258 </row> 4259 </tbody> 4260 </tgroup> 4261</informaltable> 4262 4263<para> 4264The auth_name member is the name of the authentication method. 4265The auth_data member is the actual authentication data, 4266and the auth_data_length member is the number of bytes in the data. 4267</para> 4268 4269<para> 4270To obtain the default authorization file name, use 4271<function>IceAuthFileName</function> 4272</para> 4273 4274<literallayout remap='FD'> 4275char *IceAuthFileName() 4276</literallayout> 4277 4278<para> 4279If the ICEAUTHORITY environment variable if set, this value is returned. 4280Otherwise, the default authorization file name is $HOME/.ICEauthority. 4281This name is statically allocated and should not be freed. 4282</para> 4283 4284<para> 4285To synchronously update the authorization file, the file must 4286be locked with a call to 4287<function>IceLockAuthFile</function> 4288This function takes advantage of the fact that the 4289<function>link</function> 4290system call will fail if the name of the new link already exists. 4291</para> 4292 4293<funcsynopsis> 4294<funcprototype> 4295 <funcdef>int<function> IceLockAuthFile</function></funcdef> 4296 <paramdef>char<parameter> *file_name</parameter></paramdef> 4297 <paramdef>int<parameter> retries</parameter></paramdef> 4298 <paramdef>int<parameter> timeout</parameter></paramdef> 4299 <paramdef>long<parameter> dead</parameter></paramdef> 4300</funcprototype> 4301</funcsynopsis> 4302 4303<variablelist remap='IP'> 4304 <varlistentry> 4305 <term><emphasis remap='I'>file_name</emphasis></term> 4306 <listitem><para>The authorization file to lock.</para></listitem> 4307 </varlistentry> 4308 <varlistentry> 4309 <term><emphasis remap='I'>retries</emphasis></term> 4310 <listitem> 4311 <para>The number of retries.</para> 4312 </listitem> 4313 </varlistentry> 4314 <varlistentry> 4315 <term><emphasis remap='I'>timeout</emphasis></term> 4316 <listitem> 4317 <para>The number of seconds before each retry.</para> 4318 </listitem> 4319 </varlistentry> 4320 <varlistentry> 4321 <term><emphasis remap='I'>dead</emphasis></term> 4322 <listitem> 4323 <para> 4324If a lock already exists that is the specified dead seconds old, 4325it is broken. 4326A value of zero is used to unconditionally break an old lock. 4327 </para> 4328 </listitem> 4329 </varlistentry> 4330</variablelist> 4331 4332<para>One of three values is returned:</para> 4333 4334<itemizedlist> 4335 <listitem> 4336 <para> 4337<function>IceAuthLockSuccess</function> - the lock succeeded. 4338 </para> 4339 </listitem> 4340 <listitem> 4341 <para> 4342<function>IceAuthLockError</function> - a system error occurred, and 4343<function>errno</function> may prove useful. 4344 </para> 4345 </listitem> 4346 <listitem> 4347 <para> 4348<function>IceAuthLockTimeout</function> - the specified number of 4349retries failed. 4350 </para> 4351 </listitem> 4352</itemizedlist> 4353 4354<para> 4355To unlock an authorization file, use <function>IceUnlockAuthFile</function> 4356</para> 4357 4358<funcsynopsis> 4359<funcprototype> 4360 <funcdef>int<function> IceUnlockAuthFile</function></funcdef> 4361 <paramdef>char<parameter> *file_name</parameter></paramdef> 4362</funcprototype> 4363</funcsynopsis> 4364 4365<variablelist remap='IP'> 4366 <varlistentry> 4367 <term><emphasis remap='I'>file_name</emphasis></term> 4368 <listitem><para>The authorization file to unlock.</para></listitem> 4369 </varlistentry> 4370</variablelist> 4371 4372<para> 4373To read the next entry in an authorization file, use 4374<function>IceReadAuthFileEntry</function> 4375</para> 4376 4377<funcsynopsis> 4378<funcprototype> 4379 <funcdef>IceAuthFileEntry<function> *IceReadAuthFileEntry</function></funcdef> 4380 <paramdef>FILE<parameter> *auth_file</parameter></paramdef> 4381</funcprototype> 4382</funcsynopsis> 4383 4384<variablelist remap='IP'> 4385 <varlistentry> 4386 <term><emphasis remap='I'>auth_file</emphasis></term> 4387 <listitem><para>The authorization file.</para></listitem> 4388 </varlistentry> 4389</variablelist> 4390 4391<para> 4392Note that it is the responsibility of the application to open the file 4393for reading before calling this function. If an error is encountered, 4394or there are no more entries to read, NULL is returned. 4395</para> 4396 4397<para> 4398Entries should be free with a call to 4399<function>IceFreeAuthFileEntry</function> 4400</para> 4401 4402<para> 4403To write an entry in an authorization file, use 4404<function>IceWriteAuthFileEntry</function> 4405</para> 4406 4407<funcsynopsis> 4408<funcprototype> 4409 <funcdef>Status<function> IceWriteAuthFileEntry</function></funcdef> 4410 <paramdef>FILE<parameter> *auth_file</parameter></paramdef> 4411 <paramdef>IceAuthFileEntry<parameter> *entry</parameter></paramdef> 4412</funcprototype> 4413</funcsynopsis> 4414 4415<variablelist remap='IP'> 4416 <varlistentry> 4417 <term><emphasis remap='I'>auth_file</emphasis></term> 4418 <listitem><para>The authorization file.</para></listitem> 4419 </varlistentry> 4420 <varlistentry> 4421 <term><emphasis remap='I'>entry</emphasis></term> 4422 <listitem><para>The entry to write.</para></listitem> 4423 </varlistentry> 4424</variablelist> 4425 4426<para> 4427Note that it is the responsibility of the application to open the file 4428for writing before calling this function. The function returns a nonzero 4429status if the operation was successful. 4430</para> 4431 4432 4433<para> 4434To search the default authorization file for an entry that matches a given 4435protocol_name/network_id/auth_name tuple, use 4436<function>IceGetAuthFileEntry</function> 4437</para> 4438 4439<funcsynopsis> 4440<funcprototype> 4441 <funcdef>IceAuthFileEntry<function> *IceGetAuthFileEntry</function></funcdef> 4442 <paramdef>char<parameter> *protocol_name</parameter></paramdef> 4443 <paramdef>char<parameter> *network_id</parameter></paramdef> 4444 <paramdef>char<parameter> *auth_name</parameter></paramdef> 4445</funcprototype> 4446</funcsynopsis> 4447 4448<variablelist remap='IP'> 4449 <varlistentry> 4450 <term><emphasis remap='I'>auth_file</emphasis></term> 4451 <listitem><para>The name of the protocol to search on.</para></listitem> 4452 </varlistentry> 4453 <varlistentry> 4454 <term><emphasis remap='I'>network_id</emphasis></term> 4455 <listitem> 4456 <para>The network ID to search on.</para> 4457 </listitem> 4458 </varlistentry> 4459 <varlistentry> 4460 <term><emphasis remap='I'>auth_name</emphasis></term> 4461 <listitem> 4462 <para>The authentication method to search on.</para> 4463 </listitem> 4464 </varlistentry> 4465</variablelist> 4466 4467<para> 4468If <function>IceGetAuthFileEntry</function> 4469fails to find such an entry, NULL is returned. 4470</para> 4471 4472 4473<para> 4474To free an entry returned by 4475<function>IceReadAuthFileEntry</function> or 4476<function>IceGetAuthFileEntry</function> use 4477<function>IceFreeAuthFileEntry</function> 4478</para> 4479 4480<funcsynopsis> 4481<funcprototype> 4482 <funcdef>void<function> IceFreeAuthFileEntry</function></funcdef> 4483 <paramdef>IceAuthFileEntry<parameter> *entry</parameter></paramdef> 4484</funcprototype> 4485</funcsynopsis> 4486 4487<variablelist remap='IP'> 4488 <varlistentry> 4489 <term><emphasis remap='I'>entry</emphasis></term> 4490 <listitem><para>The entry to free.</para></listitem> 4491 </varlistentry> 4492</variablelist> 4493 4494</appendix> 4495 4496<appendix id="mit_magic_cookie_1_authentication"> 4497<title>MIT-MAGIC-COOKIE-1 Authentication</title> 4498 4499 4500<para>The X Consortium's ICElib implementation supports a simple 4501MIT-MAGIC-COOKIE-1 authentication scheme using the authority file utilities 4502described in Appendix A.</para> 4503 4504<para>In this model, an application, such as a session manager, obtains a 4505magic cookie by calling 4506<function>IceGenerateMagicCookie</function> 4507and then stores it in the user's local .ICEauthority file 4508so that local clients can connect. In order to allow remote clients to 4509connect, some remote execution mechanism should be used to store the 4510magic cookie in the user's .ICEauthority file on a remote machine.</para> 4511 4512<para>In addition to storing the magic cookie in the .ICEauthority file, the 4513application needs to call the 4514<function>IceSetPaAuthData</function> 4515function in order to store the magic cookie in memory. When it comes time 4516for the MIT-MAGIC-COOKIE-1 authentication procedure to accept or reject the 4517connection, it will compare the magic cookie presented by the requestor to 4518the magic cookie in memory.</para> 4519 4520<funcsynopsis> 4521<funcprototype> 4522 <funcdef>char<function> *IceGenerateMagicCookie</function></funcdef> 4523 <paramdef>int<parameter> length</parameter></paramdef> 4524</funcprototype> 4525</funcsynopsis> 4526 4527<variablelist remap='IP'> 4528 <varlistentry> 4529 <term><emphasis remap='I'>length</emphasis></term> 4530 <listitem><para>The desired length of the magic cookie.</para></listitem> 4531 </varlistentry> 4532</variablelist> 4533 4534 4535<para>The magic cookie returned will be null-terminated. If memory can not be 4536allocated for the magic cookie, the function will return NULL. 4537Otherwise, the magic cookie should be freed with a call to 4538<function>free</function></para> 4539 4540 4541<para>To store the authentication data in memory, use 4542<function>IceSetPaAuthData</function> 4543Currently, this function is only used for MIT-MAGIC-COOKIE-1 4544authentication, but it may be used for additional authentication 4545methods in the future.</para> 4546 4547<funcsynopsis> 4548<funcprototype> 4549 <funcdef>void<function> IceSetPaAuthData</function></funcdef> 4550 <paramdef>int<parameter> num_entries</parameter></paramdef> 4551 <paramdef>IceAuthDataEntry<parameter> *entries</parameter></paramdef> 4552</funcprototype> 4553</funcsynopsis> 4554 4555<variablelist remap='IP'> 4556 <varlistentry> 4557 <term><emphasis remap='I'>num_entries</emphasis></term> 4558 <listitem><para>The number of authentication data entries.</para></listitem> 4559 </varlistentry> 4560 <varlistentry> 4561 <term><emphasis remap='I'>entries</emphasis></term> 4562 <listitem><para>The list of authentication data entries.</para></listitem> 4563 </varlistentry> 4564</variablelist> 4565 4566<para>Each entry has associated with it a protocol name 4567(for example, "ICE" for ICE connection setup authentication, 4568"XSMP" for session management authentication), a network ID for the 4569"accepting" client, an authentication name (for example, MIT-MAGIC-COOKIE-1), 4570and authentication data. The ICE library 4571will merge these entries with previously set entries, based on the 4572(protocol_name, network_id, auth_name) tuple.</para> 4573 4574 4575 4576<literallayout class="monospaced"> 4577typedef struct { 4578 char *protocol_name; 4579 char *network_id; 4580 char *auth_name; 4581 unsigned short auth_data_length; 4582 char *auth_data; 4583} IceAuthDataEntry; 4584</literallayout> 4585 4586</appendix> 4587</book> 4588 4589