1 <?xml version="1.0" encoding="UTF-8" ?>
2 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
3 "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd"
5 <!ENTITY % defs SYSTEM "defs.ent"> %defs;
12 <title>Inter-Client Exchange Library</title>
13 <subtitle>X Consortium Standard</subtitle>
14 <releaseinfo>X Version 11, Release &fullrelvers;</releaseinfo>
15 <releaseinfo>Version 1.0</releaseinfo>
18 <firstname>Ralph</firstname><surname>Mor</surname>
19 <affiliation><orgname>X Consortium</orgname></affiliation>
23 <year>1993</year><year>1994</year><year>1996</year>
24 <holder>X Consortium</holder>
29 Permission is hereby granted, free of charge, to any person obtaining a copy
30 of this software and associated documentation files (the
31 "Software"), to deal in the Software without restriction,
32 including without limitation the rights to use, copy, modify, merge,
33 publish, distribute, sublicense, and/or sell copies of the Software, and
34 to permit persons to whom the Software is furnished to do so, subject to
35 the following conditions:
38 <para>The above copyright notice and this permission notice shall be
39 included in all copies or substantial portions of the Software.
43 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
44 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
45 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
46 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
47 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
48 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
52 Except as contained in this notice, the name of the X Consortium shall not be
53 used in advertising or otherwise to promote the sale, use or other dealings
54 in this Software without prior written authorization from the X Consortium.
60 <chapter id='Overview_of_ICE'>
61 <title>Overview of ICE</title>
64 There are numerous possible inter-client protocols, with many similarities
65 and common needs - authentication, version negotiation, byte
66 order negotiation, and so on.
67 The Inter-Client Exchange (ICE) protocol is intended to provide a framework
68 for building such protocols, allowing them to make use of common negotiation
69 mechanisms and to be multiplexed over a single transport connection.
73 <chapter id='The_ICE_Library___C_Language_Interface_to_ICE'>
74 <title>The ICE Library - C Language Interface to ICE</title>
77 A client that wishes to utilize ICE must first register the protocols it
78 understands with the ICE library. Each protocol is dynamically assigned
79 a major opcode ranging from 1-255 (two clients can use different
80 major opcodes for the same protocol). The next step for the client is either
81 to open a connection with another client or to wait for connections made
82 by other clients. Authentication may be required. A client can both
83 initiate connections with other clients and be
84 waiting for clients to connect to itself (a nested session manager is an
85 example). Once an ICE connection is established between the two clients, one
86 of the clients needs to initiate a
87 <function>ProtocolSetup</function>
89 "activate" a given protocol. Once the other client accepts the
90 <function>ProtocolSetup</function>
91 (once again, authentication may be required), the
92 two clients are ready to start passing messages specific to that protocol to
93 each other. Multiple protocols may be active on a single ICE connection.
94 Clients are responsible for notifying the ICE library when a protocol is no
95 longer active on an ICE connection, although ICE does not define how each
96 subprotocol triggers a protocol shutdown.
100 The ICE library utilizes callbacks to process incoming messages. Using
102 <function>ProtocolSetup</function>
103 messages and authentication to happen
104 behind the scenes. An additional benefit is that messages never need
105 to be buffered up by the library when the client blocks waiting for a
110 <chapter id='Intended_Audience'>
111 <title>Intended Audience</title>
113 <para>This document is intended primarily for implementors of protocol libraries
114 layered on top of ICE. Typically, applications that wish to utilize ICE
115 will make calls into individual protocol libraries rather than directly
116 make calls into the ICE library. However, some applications will have to
117 make some initial calls into the ICE library in order to accept ICE
118 connections (for example, a session manager accepting connections from
119 clients). But in general, protocol libraries should be designed to hide
120 the inner details of ICE from applications.</para>
123 <chapter id='Header_Files_and_Library_Name'>
124 <title>Header Files and Library Name</title>
127 <para>The header file
128 <<symbol role='Pn'>X11/ICE/ICElib.h</symbol>>
129 defines all of the ICElib data structures and function prototypes.
130 <function>ICElib.h</function>
131 includes the header file
132 <<symbol role='Pn'>X11/ICE/ICE.h</symbol>>,
133 which defines all of the ICElib constants.
134 Protocol libraries that need to read and write messages should include
136 <<symbol role='Pn'>X11/ICE/ICEmsg.h</symbol>>.</para>
138 <para>Applications should link against ICElib using -lICE.</para>
141 <chapter id='Note_on_Prefixes'>
142 <title>Note on Prefixes</title>
145 <para>The following name prefixes are used in the library to distinguish between
146 a client that initiates a
147 <function>ProtocolSetup</function>
150 <function>ProtocolReply</function></para>
154 <para><function>IcePo</function>
155 - Ice Protocol Originator</para>
158 <para><function>IcePa</function>
159 - Ice Protocol Acceptor</para>
164 <chapter id='Protocol_Registration'>
165 <title>Protocol Registration</title>
168 In order for two clients to exchange messages for a given protocol, each
169 side must register the protocol with the ICE library. The purpose of
170 registration is for each side to obtain a major opcode for the protocol
171 and to provide callbacks for processing messages and handling authentication.
172 There are two separate registration functions:
178 One to handle the side that does a
179 <function>ProtocolSetup</function>
184 One to handle the side that responds with a
185 <function>ProtocolReply</function>
191 It is recommended that protocol registration occur before the two clients
192 establish an ICE connection. If protocol registration occurs after an
193 ICE connection is created, there can be a brief interval of time in which a
194 <function>ProtocolSetup</function>
195 is received, but the protocol is not registered.
196 If it is not possible to register a protocol before the creation of an
197 ICE connection, proper precautions should be taken to avoid the above race
203 The <xref linkend='IceRegisterForProtocolSetup' xrefstyle='select: title'/>
204 function should be called for the client that initiates a
205 <function>ProtocolSetup</function>
208 <funcsynopsis id='IceRegisterForProtocolSetup'>
210 <funcdef>int <function>IceRegisterForProtocolSetup</function></funcdef>
211 <paramdef>const char<parameter> *protocol_name</parameter></paramdef>
212 <paramdef>const char<parameter> *vendor</parameter></paramdef>
213 <paramdef>const char<parameter> *release</parameter></paramdef>
214 <paramdef>int<parameter> version_count</parameter></paramdef>
215 <paramdef>IcePoVersionRec<parameter> *version_recs</parameter></paramdef>
216 <paramdef>int<parameter> auth_count</parameter></paramdef>
217 <paramdef>char<parameter> **auth_names</parameter></paramdef>
218 <paramdef>IcePoAuthProc<parameter> *auth_procs</parameter></paramdef>
219 <paramdef>IceIOErrorProc<parameter> io_error_proc</parameter></paramdef>
224 <variablelist remap='IP'>
226 <term><emphasis remap='I'>protocol_name</emphasis></term>
229 A string specifying the name of the protocol to register.
234 <term><emphasis remap='I'>vendor</emphasis></term>
236 <para>A vendor string with semantics specified by the protocol.</para>
240 <term><emphasis remap='I'>release</emphasis></term>
242 <para>A release string with semantics specified by the protocol.</para>
246 <term><emphasis remap='I'>version_count</emphasis></term>
248 <para>The number of different versions of the protocol supported.</para>
252 <term><emphasis remap='I'>version_recs</emphasis></term>
254 <para>List of versions and associated callbacks.</para>
258 <term><emphasis remap='I'>auth_count</emphasis></term>
260 <para>The number of authentication methods supported.</para>
264 <term><emphasis remap='I'>auth_names</emphasis></term>
266 <para>The list of authentication methods supported.</para>
270 <term><emphasis remap='I'>auth_procs</emphasis></term>
273 The list of authentication callbacks, one for each authentication method.
278 <term><emphasis remap='I'>io_error_proc</emphasis></term>
280 <para>IO error handler, or NULL.</para>
287 <xref linkend='IceRegisterForProtocolSetup' xrefstyle='select: title'/> returns the major
288 opcode reserved or -1 if an error occurred. In order to actually activate
289 the protocol, the <xref linkend='IceProtocolSetup' xrefstyle='select: title'/>
290 function needs to be called with this major opcode. Once the protocol is
291 activated, all messages for the protocol should be sent using this major
296 A protocol library may support multiple versions of the same protocol.
297 The version_recs argument specifies a list of supported versions of the
298 protocol, which are prioritized in decreasing order of preference.
299 Each version record consists of a major and minor version of the protocol
300 as well as a callback to be used for processing incoming messages.
304 <literallayout remap='Ds'>
308 IcePoProcessMsgProc process_msg_proc;
313 <function>IcePoProcessMsgProc</function>
314 callback is responsible for processing the set of messages that can be
315 received by the client that initiated the
316 <function>ProtocolSetup</function>
317 For further information,
319 <xref linkend='Callbacks_for_Processing_Messages' xrefstyle='select: title'/>
322 <para>Authentication may be required before the protocol can become active.
323 The protocol library must register the authentication methods that it
324 supports with the ICE library.
325 The auth_names and auth_procs arguments are a list of authentication names
326 and callbacks that are prioritized in decreasing order of preference.
327 For information on the
328 <function>IcePoAuthProc</function>
330 <xref linkend='Authentication_Methods' xrefstyle='select: title'/>
334 <xref linkend='IceIOErrorProc' xrefstyle='select: title'/>
335 callback is invoked if the ICE connection unexpectedly breaks.
336 You should pass NULL for io_error_proc if not interested in being notified.
337 For further information,
338 <xref linkend='Error_Handling' xrefstyle='select: title'/>
343 <xref linkend='IceRegisterForProtocolReply' xrefstyle='select: title'/>
344 function should be called for the client that responds to a
345 <function>ProtocolSetup</function>
347 <function>ProtocolReply</function></para>
350 <funcsynopsis id='IceRegisterForProtocolReply'>
352 <funcdef>Bool <function>IceRegisterForProtocolReply</function></funcdef>
353 <paramdef>const char<parameter> *protocol_name</parameter></paramdef>
354 <paramdef>const char<parameter> *vendor</parameter></paramdef>
355 <paramdef>const char<parameter> *release</parameter></paramdef>
356 <paramdef>int<parameter> version_count</parameter></paramdef>
357 <paramdef>IcePoVersionRec<parameter> *version_recs</parameter></paramdef>
358 <paramdef>int<parameter> auth_count</parameter></paramdef>
359 <paramdef>const char<parameter> **auth_names</parameter></paramdef>
360 <paramdef>IcePoAuthProc<parameter> *auth_procs</parameter></paramdef>
361 <paramdef>IceHostBasedAuthProc<parameter> host_based_auth_proc</parameter></paramdef>
362 <paramdef>IceProtocolSetupProc<parameter> protocol_setup_proc</parameter></paramdef>
363 <paramdef>IceProtocolActivateProc<parameter> protocol_activate_proc</parameter></paramdef>
364 <paramdef>IceIOErrorProc<parameter> io_error_proc</parameter></paramdef>
368 <variablelist remap='IP'>
370 <term><emphasis remap='I'>protocol_name</emphasis></term>
371 <listitem><para>A string specifying the name of the protocol to register.</para></listitem>
374 <term><emphasis remap='I'>vendor</emphasis></term>
376 <para>A vendor string with semantics specified by the protocol.</para>
380 <term><emphasis remap='I'>release</emphasis></term>
382 <para>A release string with semantics specified by the protocol.</para>
386 <term><emphasis remap='I'>version_count</emphasis></term>
388 <para>The number of different versions of the protocol supported.</para>
392 <term><emphasis remap='I'>version_recs</emphasis></term>
394 <para>List of versions and associated callbacks.</para>
398 <term><emphasis remap='I'>auth_count</emphasis></term>
400 <para>The number of authentication methods supported.</para>
404 <term><emphasis remap='I'>auth_names</emphasis></term>
406 <para>The list of authentication methods supported.</para>
410 <term><emphasis remap='I'>auth_procs</emphasis></term>
412 <para>The list of authentication callbacks, one for each authentication method.</para>
416 <term><emphasis remap='I'>host_based_auth_proc</emphasis></term>
418 <para>Host based authentication callback.</para>
422 <term><emphasis remap='I'>protocol_setup_proc</emphasis></term>
424 <para>A callback to be invoked when authentication has succeeded for a
425 <function>ProtocolSetup</function>
427 <function>ProtocolReply</function>
432 <term><emphasis remap='I'>protocol_activate_proc</emphasis></term>
434 <para>A callback to be invoked after the
435 <function>ProtocolReply</function>
440 <term><emphasis remap='I'>io_error_proc</emphasis></term>
442 <para>IO error handler, or NULL.</para>
448 <para><xref linkend='IceRegisterForProtocolReply' xrefstyle='select: title'/>
449 returns the major opcode reserved or -1 if an error occurred. The major
450 opcode should be used in all subsequent messages sent for this protocol.</para>
452 <para>A protocol library may support multiple versions of the same protocol.
453 The version_recs argument specifies a list of supported versions of the protocol,
454 which are prioritized in decreasing order of preference.
455 Each version record consists of a major and minor version of the protocol
456 as well as a callback to be used for processing incoming messages.</para>
459 <literallayout remap='Ds'>
463 IcePaProcessMsgProc process_msg_proc;
469 <xref linkend='IcePaProcessMsgProc' xrefstyle='select: title'/>
470 callback is responsible for processing the set of messages that can be
471 received by the client that accepted the
472 <function>ProtocolSetup</function>
473 For further information,
475 <xref linkend='Callbacks_for_Processing_Messages' xrefstyle='select: title'/>
478 <para>Authentication may be required before the protocol can become active.
479 The protocol library must register the authentication methods that it
480 supports with the ICE library.
481 The auth_names and auth_procs arguments are a list of authentication names
482 and callbacks that are prioritized in decreasing order of preference.
483 For information on the
484 <function>IcePaAuthProc</function>,
486 <xref linkend='Authentication_Methods' xrefstyle='select: title'/>
490 <para>If authentication fails and the client attempting to initiate
492 <function>ProtocolSetup</function>
493 has not required authentication, the
494 <function>IceHostBasedAuthProc</function>
495 callback is invoked with the host name of the originating client.
496 If the callback returns
497 <function>True</function>
499 <function>ProtocolSetup</function>
500 will succeed, even though the original
501 authentication failed.
502 Note that authentication can effectively be disabled by registering an
503 <function>IceHostBasedAuthProc</function>
505 <function>True</function>
507 authentication is allowed, you should pass NULL for host_based_auth_proc.</para>
511 <funcdef>Bool <function>HostBasedAuthProc</function></funcdef>
512 <paramdef>char<parameter> *host_name</parameter></paramdef>
516 <variablelist remap='IP'>
518 <term><emphasis remap='I'>protocol_name</emphasis></term>
519 <listitem><para>The host name of the client that sent the <function>ProtocolSetup</function></para></listitem>
524 <para>The host_name argument is a string of the form <emphasis remap='I'>protocol</emphasis>/<emphasis remap='I'>hostname</emphasis>,
525 where <emphasis remap='I'>protocol</emphasis> is one of {tcp, decnet, local}.</para>
528 <function>ProtocolSetup</function>
529 messages and authentication happen behind the scenes
530 via callbacks, the protocol library needs some way of being notified when the
531 <function>ProtocolSetup</function>
533 This occurs in two phases.
534 In the first phase, the
535 <function>IceProtocolSetupProc</function>
536 callback is invoked after authentication has
537 successfully completed but before the ICE library sends a
538 <function>ProtocolReply</function>
539 Any resources required for this protocol should be allocated at this time.
541 <function>IceProtocolSetupProc</function>
542 returns a successful status, the ICE library will
544 <function>ProtocolReply</function>
546 <function>IceProtocolActivateProc</function>
547 callback. Otherwise, an error will be sent to the
548 other client in response to the
549 <function>ProtocolSetup</function></para>
552 <function>IceProtocolActivateProc</function>
553 is an optional callback and should be registered only if the protocol
554 library intends to generate a message immediately following the
555 <function>ProtocolReply</function>
556 You should pass NULL for protocol_activate_proc if not interested
557 in this callback.</para>
559 <funcsynopsis id='ProtocolSetupProc'>
561 <funcdef>Status <function>ProtocolSetupProc</function></funcdef>
562 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
563 <paramdef>int<parameter> major_version</parameter></paramdef>
564 <paramdef>int<parameter> minor_version</parameter></paramdef>
565 <paramdef>char<parameter> *vendor</parameter></paramdef>
566 <paramdef>char<parameter> *release</parameter></paramdef>
567 <paramdef>IcePointer<parameter> *client_data_ret</parameter></paramdef>
568 <paramdef>char<parameter> **failure_reason_ret</parameter></paramdef>
572 <variablelist remap='IP'>
574 <term><emphasis remap='I'>protocol_name</emphasis></term>
576 <para>The ICE connection object.</para>
580 <term><emphasis remap='I'>major_version</emphasis></term>
582 <para>The major version of the protocol.</para>
586 <term><emphasis remap='I'>minor_version</emphasis></term>
588 <para>The minor version of the protocol.</para>
592 <term><emphasis remap='I'>vendor</emphasis></term>
594 <para>The vendor string registered by the protocol originator.</para>
598 <term><emphasis remap='I'>release</emphasis></term>
600 <para>The release string registered by the protocol originator.</para>
604 <term><emphasis remap='I'>client_data_ret</emphasis></term>
606 <para>Client data to be set by callback.</para>
610 <term><emphasis remap='I'>failure_reason_ret</emphasis></term>
612 <para>Failure reason returned.</para>
617 <para>The pointer stored in the client_data_ret argument will be passed
619 <xref linkend='IcePaProcessMsgProc' xrefstyle='select: title'/>
620 callback whenever a message has arrived for this protocol on the
621 ICE connection.</para>
623 <para>The vendor and release strings should be freed with
624 <function>free</function>
625 when they are no longer needed.</para>
627 <para>If a failure occurs, the
628 <function>IceProtocolSetupProc</function>
629 should return a zero status as well as allocate and return a failure
630 reason string in failure_reason_ret.
631 The ICE library will be responsible for freeing this memory.</para>
634 <function>IceProtocolActivateProc</function>
635 callback is defined as follows:</para>
637 <funcsynopsis id='ProtocolActivateProc'>
639 <funcdef>void <function>ProtocolActivateProc</function></funcdef>
640 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
641 <paramdef>IcePointer<parameter> client_data</parameter></paramdef>
645 <variablelist remap='IP'>
647 <term><emphasis remap='I'>ice_conn</emphasis></term>
648 <listitem><para>The ICE connection object.</para></listitem>
651 <term><emphasis remap='I'>client_data</emphasis></term>
654 The client data set in the <function>IceProtocolSetupProc</function> callback.
662 <xref linkend='IceIOErrorProc' xrefstyle='select: title'/>
663 callback is invoked if the ICE connection unexpectedly breaks.
664 You should pass NULL for io_error_proc if not interested in being notified.
665 For further information,
667 <xref linkend='Error_Handling' xrefstyle='select: title'/>
670 <sect1 id='Callbacks_for_Processing_Messages'>
671 <title>Callbacks for Processing Messages</title>
673 <para>When an application detects that there is new data to read on an ICE
675 <function>select</function>
677 <xref linkend='IceProcessMessages' xrefstyle='select: title'/>
679 <xref linkend='Processing_Messages' xrefstyle='select: title'/>
682 <xref linkend='IceProcessMessages' xrefstyle='select: title'/>
683 reads an ICE message header with a major opcode other than
684 zero (reserved for the ICE protocol), it needs to call a function that will
685 read the rest of the message, unpack it, and process it accordingly.</para>
687 <para>If the message arrives at the client that initiated the
688 <function>ProtocolSetup</function>
690 <function>IcePoProcessMsgProc</function>
691 callback is invoked.</para>
693 <funcsynopsis id='PoProcessMsgProc'>
695 <funcdef>void <function>PoProcessMsgProc</function></funcdef>
696 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
697 <paramdef>IcePointer<parameter> client_data</parameter></paramdef>
698 <paramdef>int<parameter> opcode</parameter></paramdef>
699 <paramdef>unsigned long<parameter> length</parameter></paramdef>
700 <paramdef>Bool<parameter> swap</parameter></paramdef>
701 <paramdef>IceReplyWaitInfo<parameter> *reply_wait</parameter></paramdef>
702 <paramdef>Bool<parameter> *reply_ready_ret</parameter></paramdef>
706 <variablelist remap='IP'>
708 <term><emphasis remap='I'>ice_conn</emphasis></term>
709 <listitem><para>The ICE connection object.</para></listitem>
712 <term><emphasis remap='I'>client_data</emphasis></term>
714 <para>Client data associated with this protocol on the ICE connection.</para>
718 <term><emphasis remap='I'>opcode</emphasis></term>
720 <para>The minor opcode of the message.</para>
724 <term><emphasis remap='I'>length</emphasis></term>
726 <para>The length (in 8-byte units) of the message beyond the ICE header.</para>
730 <term><emphasis remap='I'>swap</emphasis></term>
732 <para>A flag that indicates if byte swapping is necessary.</para>
736 <term><emphasis remap='I'>reply_wait</emphasis></term>
738 <para>Indicates if the invoking client is waiting for a reply.</para>
742 <term><emphasis remap='I'>reply_ready_ret</emphasis></term>
745 <function>True</function>
746 a reply is ready.</para>
752 <para>If the message arrives at the client that accepted the
753 <function>ProtocolSetup</function>
755 <xref linkend='IcePaProcessMsgProc' xrefstyle='select: title'/>
756 callback is invoked.</para>
759 <funcsynopsis id='IcePaProcessMsgProc'>
761 <funcdef>void <function>IcePaProcessMsgProc</function></funcdef>
762 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
763 <paramdef>IcePointer<parameter> client_data</parameter></paramdef>
764 <paramdef>int<parameter> opcode</parameter></paramdef>
765 <paramdef>unsigned long<parameter> length</parameter></paramdef>
766 <paramdef>Bool<parameter> swap</parameter></paramdef>
770 <variablelist remap='IP'>
772 <term><emphasis remap='I'>ice_conn</emphasis></term>
773 <listitem><para>The ICE connection object.</para></listitem>
776 <term><emphasis remap='I'>client_data</emphasis></term>
778 <para>Client data associated with this protocol on the ICE connection.</para>
782 <term><emphasis remap='I'>opcode</emphasis></term>
784 <para>The minor opcode of the message.</para>
788 <term><emphasis remap='I'>length</emphasis></term>
790 <para>The length (in 8-byte units) of the message beyond the ICE header.</para>
794 <term><emphasis remap='I'>swap</emphasis></term>
796 <para>A flag that indicates if byte swapping is necessary.</para>
802 <para>In order to read the message, both of these callbacks should use the
803 macros defined for this purpose (see
804 <xref linkend='Reading_ICE_Messages' xrefstyle='select: title'/>.).
805 Note that byte swapping may be necessary.
806 As a convenience, the length field in the ICE header will be swapped by ICElib
809 <para>In both of these callbacks, the client_data argument is a pointer to client
810 data that was registered at
811 <function>ProtocolSetup</function>
814 <function>IcePoProcessMsgProc</function>
815 the client data was set in the call to
816 <xref linkend='IceProtocolSetup' xrefstyle='select: title'/>
818 <xref linkend='IcePaProcessMsgProc' xrefstyle='select: title'/>
819 the client data was set in the
820 <function>IceProtocolSetupProc</function>
824 <function>IcePoProcessMsgProc</function>
825 callback needs to check the reply_wait argument.
826 If reply_wait is NULL ,
827 the ICE library expects the function to
828 pass the message to the client via a callback.
829 For example, if this is a Session Management "Save Yourself" message,
830 this function should notify the client of the "Save Yourself" via a callback.
831 The details of how such a callback would be defined
832 are implementation-dependent.</para>
834 <para>However, if reply_wait is not NULL ,
835 then the client is waiting for
836 a reply or an error for a message it previously sent.
837 The reply_wait is of type
838 <function>IceReplyWaitInfo</function></para>
841 <literallayout remap='Ds'>
843 unsigned long sequence_of_request;
844 int major_opcode_of_request;
845 int minor_opcode_of_request;
850 <para><function>IceReplyWaitInfo</function>
851 contains the major/minor opcodes and sequence number of
852 the message for which a reply is being awaited.
853 It also contains a pointer to the reply message to be filled in
854 (the protocol library should cast this
855 <function>IcePointer</function>
856 to the appropriate reply type).
857 In most cases, the reply will have some fixed-size part, and the client waiting
858 for the reply will have provided a pointer to a structure to hold
859 this fixed-size data. If there is variable-length data, it would be
861 <function>IcePoProcessMsgProc</function>
862 callback will have to allocate additional
863 memory and store pointer(s) to that memory in the fixed-size
864 structure. If the entire data is variable length (for example., a single
865 variable-length string), then the client waiting for the reply would probably
866 just pass a pointer to fixed-size space to hold a pointer, and the
867 <function>IcePoProcessMsgProc</function>
868 callback would allocate the storage and store the pointer.
869 It is the responsibility of the client receiving the reply to
870 free any memory allocated on its behalf.</para>
872 <para>If reply_wait is not NULL and
873 <function>IcePoProcessMsgProc</function>
874 has a reply or error to return in response to this reply_wait
875 (that is, no callback was generated), then the reply_ready_ret argument
877 <function>True</function>
878 Note that an error should only be returned
879 if it corresponds to the reply being waited for. Otherwise, the
880 <function>IcePoProcessMsgProc</function>
881 should either handle the error internally or invoke an error handler
882 for its library.</para>
884 <para>If reply_wait is NULL,
885 then care must be taken not to store any value in reply_ready_ret,
886 because this pointer may also be NULL.</para>
889 <xref linkend='IcePaProcessMsgProc' xrefstyle='select: title'/>
890 callback, on the other hand, should always pass
891 the message to the client via a callback. For example, if this is a Session
892 Management "Interact Request" message, this function should notify the
893 client of the "Interact Request" via a callback.</para>
896 <xref linkend='IcePaProcessMsgProc' xrefstyle='select: title'/>
897 callback does not have a reply_wait, like
898 <function>IcePoProcessMsgProc</function>
899 does, is because a process that is acting as
900 a server should never block for a reply (infinite blocking can
901 occur if the connecting client does not act properly, denying access
902 to other clients).</para>
905 <sect1 id='Authentication_Methods'>
906 <title>Authentication Methods</title>
908 <para>As already stated, a protocol library must register the authentication
909 methods that it supports with the ICE library. For each authentication
910 method, there are two callbacks that may be registered:</para>
914 One to handle the side that initiates a <function>ProtocolSetup</function>
919 One to handle the side that accepts or rejects this request
924 <para><function>IcePoAuthProc</function>
925 is the callback invoked for the client that initiated the
926 <function>ProtocolSetup</function>
927 This callback must be able to respond
928 to the initial "Authentication Required" message or subsequent
929 "Authentication Next Phase" messages sent by the other client.</para>
932 <funcsynopsis id='IcePoAuthStatus'>
934 <funcdef>IcePoAuthStatus <function>IcePoAuthStatus </function></funcdef>
935 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
936 <paramdef>IcePointer<parameter> client_data</parameter></paramdef>
937 <paramdef>int<parameter> opcode</parameter></paramdef>
942 <variablelist remap='IP'>
944 <term><emphasis remap='I'>ice_conn</emphasis></term>
945 <listitem><para>The ICE connection object.</para></listitem>
948 <term><emphasis remap='I'>auth_state_ptr</emphasis></term>
950 <para>A pointer to state for use by the authentication callback procedure.</para>
954 <term><emphasis remap='I'>clean_up</emphasis></term>
957 <function>True</function>
958 authentication is over, and the function
959 should clean up any state it was maintaining. The
960 last 6 arguments should be ignored.</para>
964 <term><emphasis remap='I'>swap</emphasis></term>
967 <function>True</function>
968 the auth_data may have to be byte swapped
969 (depending on its contents).</para>
973 <term><emphasis remap='I'>auth_datalen</emphasis></term>
975 <para>The length (in bytes) of the authenticator data.</para>
979 <term><emphasis remap='I'>auth_data</emphasis></term>
981 <para>The data from the authenticator.</para>
985 <term><emphasis remap='I'>reply_datalen_ret</emphasis></term>
987 <para>The length (in bytes) of the reply data returned.</para>
991 <term><emphasis remap='I'>reply_data_ret</emphasis></term>
993 <para>The reply data returned.</para>
997 <term><emphasis remap='I'>error_string_ret</emphasis></term>
999 <para>If the authentication procedure encounters an error during
1000 authentication, it should allocate and return
1001 an error string.</para>
1007 <para>Authentication may require several phases, depending on the authentication
1008 method. As a result, the
1009 <function>IcePoAuthProc</function>
1010 may be called more than once when authenticating a client, and
1011 some state will have to be maintained between each invocation.
1012 At the start of each
1013 <function>ProtocolSetup</function>
1014 *auth_state_ptr is NULL,
1015 and the function should initialize its state and set
1016 this pointer. In subsequent invocations of the callback, the pointer
1017 should be used to get at any state previously stored by the callback.</para>
1019 <para>If needed, the network ID of the client accepting the
1020 <function>ProtocolSetup</function>
1021 can be obtained by calling the
1022 <function>IceConnectionString</function>
1025 <para>ICElib will be responsible for freeing the reply_data_ret and
1026 error_string_ret pointers with
1027 <function>free</function></para>
1029 <para>The auth_data pointer may point to a volatile block of memory.
1030 If the data must be kept beyond this invocation of the callback, be sure
1031 to make a copy of it.</para>
1034 <function>IcePoAuthProc</function>
1035 should return one of four values:</para>
1038 <para><function>IcePoAuthHaveReply</function>
1039 - a reply is available.</para>
1042 <para><function>IcePoAuthRejected</function>
1043 - authentication rejected.</para>
1046 <para><function>IcePoAuthFailed</function>
1047 - authentication failed.</para>
1050 <para><function>IcePoAuthDoneCleanup</function>
1051 - done cleaning up.</para>
1055 <para><function>IcePaAuthProc</function>
1056 is the callback invoked for the client that received the
1057 <function>ProtocolSetup</function></para>
1059 <funcsynopsis id='PoAuthStatus'>
1061 <funcdef>IcePoAuthStatus <function>PoAuthStatus </function></funcdef>
1062 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
1063 <paramdef>IcePointer<parameter> *auth_state_ptr</parameter></paramdef>
1064 <paramdef>Bool<parameter> swap</parameter></paramdef>
1065 <paramdef>int<parameter> auth_datalen</parameter></paramdef>
1066 <paramdef>IcePointer<parameter> auth_data</parameter></paramdef>
1067 <paramdef>int<parameter> *reply_datalen_ret</parameter></paramdef>
1068 <paramdef>IcePointer<parameter> *reply_data_ret</parameter></paramdef>
1069 <paramdef>char<parameter> **error_string_ret</parameter></paramdef>
1073 <variablelist remap='IP'>
1075 <term><emphasis remap='I'>ice_conn</emphasis></term>
1076 <listitem><para>The ICE connection object.</para></listitem>
1079 <term><emphasis remap='I'>auth_state_ptr</emphasis></term>
1081 <para>A pointer to state for use by the authentication callback procedure.</para>
1085 <term><emphasis remap='I'>swap</emphasis></term>
1088 <function>True</function>
1089 auth_data may have to be byte swapped
1090 (depending on its contents).</para>
1094 <term><emphasis remap='I'>auth_datalen</emphasis></term>
1096 <para>The length (in bytes) of the protocol originator authentication data.</para>
1100 <term><emphasis remap='I'>auth_data</emphasis></term>
1102 <para>The authentication data from the protocol originator.</para>
1106 <term><emphasis remap='I'>reply_datalen_ret</emphasis></term>
1108 <para>The length of the authentication data returned.</para>
1112 <term><emphasis remap='I'>reply_data_ret</emphasis></term>
1114 <para>The authentication data returned.</para>
1118 <term><emphasis remap='I'>error_string_ret</emphasis></term>
1120 <para>If authentication is rejected or fails, an error
1121 string is returned.</para>
1127 <para>Authentication may require several phases, depending on the authentication
1128 method. As a result, the
1129 <function>IcePaAuthProc</function>
1130 may be called more than once when authenticating a client, and
1131 some state will have to be maintained between each invocation.
1132 At the start of each
1133 <function>ProtocolSetup</function>
1134 auth_datalen is zero,
1135 *auth_state_ptr is NULL,
1136 and the function should initialize its state and set
1137 this pointer. In subsequent invocations of the callback, the pointer
1138 should be used to get at any state previously stored by the callback.</para>
1140 <para>If needed, the network ID of the client accepting the
1141 <function>ProtocolSetup</function>
1142 can be obtained by calling the
1143 <function>IceConnectionString</function>
1146 <para>The auth_data pointer may point to a volatile block of memory.
1147 If the data must be kept beyond this invocation of the callback, be sure
1148 to make a copy of it.</para>
1150 <para>ICElib will be responsible for transmitting and freeing the reply_data_ret and
1151 error_string_ret pointers with
1152 <function>free</function></para>
1155 The <function>IcePaAuthProc</function> should return one of four values:
1162 <function>IcePaAuthContinue</function> - continue (or start) authentication.
1167 <function>IcePaAuthAccepted</function> - authentication accepted.
1172 <function>IcePaAuthRejected</function> - authentication rejected.
1177 <function>IcePaAuthFailed</function> - authentication failed.
1185 <chapter id='ICE_Connections'>
1186 <title>ICE Connections</title>
1189 In order for two clients to establish an ICE connection, one client has to be
1190 waiting for connections, and the other client has to initiate the connection.
1191 Most clients will initiate connections, so we discuss that first.
1194 <sect1 id='Opening_an_ICE_Connection'>
1195 <title>Opening an ICE Connection</title>
1199 To open an ICE connection with another client (that is, waiting
1200 for connections), use <xref linkend='IceOpenConnection' xrefstyle='select: title'/>
1203 <funcsynopsis id='IceOpenConnection'>
1205 <funcdef>IceConn <function>IceOpenConnection</function></funcdef>
1206 <paramdef>char<parameter> *network_ids_list</parameter></paramdef>
1207 <paramdef>IcePointer<parameter> context</parameter></paramdef>
1208 <paramdef>Bool<parameter> must_authenticate</parameter></paramdef>
1209 <paramdef>int<parameter> major_opcode_check</parameter></paramdef>
1210 <paramdef>int<parameter> error_length</parameter></paramdef>
1211 <paramdef>char<parameter> *error_string_ret</parameter></paramdef>
1215 <variablelist remap='IP'>
1217 <term><emphasis remap='I'>network_ids_list</emphasis></term>
1220 Specifies the network ID(s) of the other client.
1225 <term><emphasis remap='I'>context</emphasis></term>
1228 A pointer to an opaque object or NULL. Used to determine if an
1229 ICE connection can be shared (see below).
1234 <term><emphasis remap='I'>must_authenticate</emphasis></term>
1237 If <function>True</function> the other client may not bypass authentication.
1242 <term><emphasis remap='I'>major_opcode_check</emphasis></term>
1245 Used to force a new ICE connection to be created (see below).
1250 <term><emphasis remap='I'>error_length</emphasis></term>
1252 <para>Length of the error_string_ret argument passed in.</para>
1256 <term><emphasis remap='I'>error_string_ret</emphasis></term>
1259 Returns a null-terminated error message, if any. The error_string_ret
1260 argument points to user supplied memory. No more than error_length bytes
1269 <xref linkend='IceOpenConnection' xrefstyle='select: title'/>
1270 returns an opaque ICE connection object if it succeeds;
1271 otherwise, it returns NULL.
1275 The network_ids_list argument contains a list of network IDs separated
1276 by commas. An attempt will be made to use the first network ID. If
1277 that fails, an attempt will be made using the second network ID, and so on.
1278 Each network ID has the following format:
1281 <informaltable frame='none'>
1282 <?dbfo keep-together="always" ?>
1283 <tgroup cols='2' align='left' colsep='0' rowsep='0'>
1284 <colspec colname='c1' colwidth='1.0*'/>
1285 <colspec colname='c2' colwidth='2.0*'/>
1288 <entry>tcp/<hostname>:<portnumber></entry>
1292 <entry>decnet/<hostname>::<objname></entry>
1296 <entry>local/<hostname>:<path></entry>
1304 <para>Most protocol libraries will have some sort of open function that should
1305 internally make a call into
1306 <xref linkend='IceOpenConnection' xrefstyle='select: title'/>
1308 <xref linkend='IceOpenConnection' xrefstyle='select: title'/>
1309 is called, it may be possible to use a previously opened ICE connection (if
1310 the target client is the same). However, there are cases in which shared
1311 ICE connections are not desired.</para>
1313 <para>The context argument is used to determine if an ICE connection can
1316 then the caller is always willing to share the connection.
1317 If context is not NULL,
1318 then the caller is not willing to use a previously opened ICE connection
1319 that has a different non-NULL context associated with it.</para>
1321 <para>In addition, if major_opcode_check contains a nonzero major opcode value,
1322 a previously created ICE connection will be used only if the major opcode
1323 is not active on the connection. This can be used to force multiple ICE
1324 connections between two clients for the same protocol.</para>
1326 <para>Any authentication requirements are handled internally by the ICE library.
1327 The method by which the authentication data is obtained
1328 is implementation-dependent.
1329 <footnote remap='FS'>
1330 <para>The X Consortium's ICElib implementation uses an .ICEauthority file (see
1332 </para></footnote> </para>
1335 <xref linkend='IceOpenConnection' xrefstyle='select: title'/>
1336 is called, the client is ready to send a
1337 <function>ProtocolSetup</function>
1339 <xref linkend='IceRegisterForProtocolSetup' xrefstyle='select: title'/>
1340 was called) or receive a
1341 <function>ProtocolSetup</function>
1343 <xref linkend='IceRegisterForProtocolReply' xrefstyle='select: title'/>
1347 <sect1 id='Listening_for_ICE_Connections'>
1348 <title>Listening for ICE Connections</title>
1350 <para>Clients wishing to accept ICE connections must first call
1351 <xref linkend='IceListenForConnections' xrefstyle='select: title'/>
1353 <xref linkend='IceListenForWellKnownConnections' xrefstyle='select: title'/>
1354 so that they can listen for connections. A list of opaque "listen" objects are
1355 returned, one for each type of transport method that is available
1356 (for example, Unix Domain, TCP, DECnet, and so on).</para>
1358 <para>Normally clients will let ICElib allocate an available name in each
1359 transport and return listen objects. Such a client will then use
1360 <xref linkend='IceComposeNetworkIdList' xrefstyle='select: title'/>
1361 to extract the chosen names and make them
1362 available to other clients for opening the connection. In certain
1363 cases it may be necessary for a client to listen for connections
1364 on pre-arranged transport object names. Such a client may use
1365 <xref linkend='IceListenForWellKnownConnections' xrefstyle='select: title'/>
1366 to specify the names for the listen objects.</para>
1368 <funcsynopsis id='IceListenForConnections'>
1370 <funcdef>Status <function>IceListenForConnections</function></funcdef>
1371 <paramdef>int<parameter> *count_ret</parameter></paramdef>
1372 <paramdef>IceListenObj<parameter> **listen_objs_ret</parameter></paramdef>
1373 <paramdef>int<parameter> error_length</parameter></paramdef>
1374 <paramdef>char<parameter> *error_string_ret</parameter></paramdef>
1378 <variablelist remap='IP'>
1380 <term><emphasis remap='I'>count_ret</emphasis></term>
1381 <listitem><para>Returns the number of listen objects created.</para></listitem>
1384 <term><emphasis remap='I'>listen_objs_ret</emphasis></term>
1385 <listitem><para>Returns a list of pointers to opaque listen objects.</para></listitem>
1388 <term><emphasis remap='I'>error_length</emphasis></term>
1390 <para>The length of the error_string_ret argument passed in.</para>
1394 <term><emphasis remap='I'>error_string_ret</emphasis></term>
1396 <para>Returns a null-terminated error message, if any.
1397 The error_string_ret points to user supplied memory.
1398 No more than error_length bytes are used.</para>
1404 <para>The return value of
1405 <xref linkend='IceListenForConnections' xrefstyle='select: title'/>
1406 is zero for failure and a positive value for success.</para>
1408 <funcsynopsis id='IceListenForWellKnownConnections'>
1410 <funcdef>Status <function>IceListenForWellKnownConnections</function></funcdef>
1411 <paramdef>char<parameter> *port_id</parameter></paramdef>
1412 <paramdef>int<parameter> *count_ret</parameter></paramdef>
1413 <paramdef>IceListenObj<parameter> **listen_objs_ret</parameter></paramdef>
1414 <paramdef>int<parameter> error_length</parameter></paramdef>
1415 <paramdef>char<parameter> *error_string_ret</parameter></paramdef>
1419 <variablelist remap='IP'>
1421 <term><emphasis remap='I'>port_id</emphasis></term>
1424 Specifies the port identification for the address(es) to be opened. The
1425 value must not contain the slash ("/"> or comma (".") character; thse are
1426 reserved for future use.
1431 <term><emphasis remap='I'>count_ret</emphasis></term>
1433 <para>Returns the number of listen objects created.</para>
1437 <term><emphasis remap='I'>listen_objs_ret</emphasis></term>
1440 Returns a list of pointers to opaque listen objects.
1445 <term><emphasis remap='I'>listen_objs_ret</emphasis></term>
1448 Returns a list of pointers to opaque listen objects.
1453 <term><emphasis remap='I'>error_length</emphasis></term>
1456 The length of the error_string_ret argument passed in.
1461 <term><emphasis remap='I'>error_string_ret</emphasis></term>
1464 Returns a null-terminated error message, if any. The error_string_ret
1465 points to user supplied memory. No more than error_length bytes are used.
1472 <xref linkend='IceListenForWellKnownConnections' xrefstyle='select: title'/> constructs a list
1473 of network IDs by prepending each known transport to port_id and then
1474 attempts to create listen objects for the result. Port_id is the portnumber,
1475 objname, or path portion of the ICE network ID. If a listen object for
1476 a particular network ID cannot be created the network ID is ignored.
1477 If no listen objects are created
1478 <xref linkend='IceListenForWellKnownConnections' xrefstyle='select: title'/>
1483 The return value of <xref linkend='IceListenForWellKnownConnections' xrefstyle='select: title'/>
1484 is zero for failure and a positive value for success.
1488 To close and free the listen objects, use
1489 <xref linkend='IceFreeListenObjs' xrefstyle='select: title'/>
1492 <funcsynopsis id='IceFreeListenObjs'>
1494 <funcdef>void <function>IceFreeListenObjs</function></funcdef>
1495 <paramdef>int<parameter> count</parameter></paramdef>
1496 <paramdef>IceListenObj<parameter> *listen_objs</parameter></paramdef>
1500 <variablelist remap='IP'>
1502 <term><emphasis remap='I'>count</emphasis></term>
1504 <para>The number of listen objects.</para>
1508 <term><emphasis remap='I'>listen_objs</emphasis></term>
1510 <para>The listen objects.</para>
1517 To detect a new connection on a listen object, use
1518 <function>select</function> on the descriptor associated with
1523 To obtain the descriptor, use
1524 <xref linkend='IceGetListenConnectionNumber' xrefstyle='select: title'/>
1527 <funcsynopsis id='IceGetListenConnectionNumber'>
1529 <funcdef>int <function>IceGetListenConnectionNumber</function></funcdef>
1530 <paramdef>IceListenObj<parameter> *listen_objs</parameter></paramdef>
1534 <variablelist remap='IP'>
1536 <term><emphasis remap='I'>listen_obj</emphasis></term>
1538 <para>The listen objects.</para>
1544 To obtain the network ID string associated with a listen object, use
1545 <xref linkend='IceGetListenConnectionString' xrefstyle='select: title'/>
1549 <funcsynopsis id='IceGetListenConnectionString'>
1551 <funcdef>char <function>IceGetListenConnectionString</function></funcdef>
1552 <paramdef>IceListenObj<parameter> listen_obj</parameter></paramdef>
1556 <variablelist remap='IP'>
1558 <term><emphasis remap='I'>listen_obj</emphasis></term>
1560 <para>The listen objects.</para>
1565 <para>A network ID has the following format:</para>
1567 <informaltable frame='none'>
1568 <?dbfo keep-together="always" ?>
1569 <tgroup cols='2' align='left' colsep='0' rowsep='0'>
1570 <colspec colname='c1' colwidth='1.0*'/>
1571 <colspec colname='c2' colwidth='2.0*'/>
1574 <entry>tcp/<hostname>:<portnumber></entry>
1578 <entry>decnet/<hostname>::<objname></entry>
1582 <entry>local/<hostname>:<path></entry>
1590 To compose a string containing a list of network IDs separated by commas
1591 (the format recognized by <xref linkend='IceOpenConnection' xrefstyle='select: title'/>
1592 use <xref linkend='IceComposeNetworkIdList' xrefstyle='select: title'/>
1595 <funcsynopsis id='IceComposeNetworkIdList'>
1597 <funcdef>char <function>IceComposeNetworkIdList</function></funcdef>
1598 <paramdef>int<parameter> count</parameter></paramdef>
1599 <paramdef>IceListenObj<parameter> *listen_objs</parameter></paramdef>
1603 <variablelist remap='IP'>
1605 <term><emphasis remap='I'>count</emphasis></term>
1607 <para>The number of listen objects.</para>
1611 <term><emphasis remap='I'>listen_objs</emphasis></term>
1613 <para>The listen objects.</para>
1620 <sect1 id='Host_Based_Authentication_for_ICE_Connections'>
1621 <title>Host Based Authentication for ICE Connections</title>
1624 If authentication fails when a client attempts to open an
1625 ICE connection and the initiating client has not required authentication,
1626 a host based authentication procedure may be invoked to provide
1627 a last chance for the client to connect. Each listen object has such a
1628 callback associated with it, and this callback is set using the
1629 <xref linkend='IceSetHostBasedAuthProc' xrefstyle='select: title'/>
1633 <funcsynopsis id='IceSetHostBasedAuthProc'>
1635 <funcdef>void <function>IceSetHostBasedAuthProc</function></funcdef>
1636 <paramdef>IceListenObj<parameter> listen_obj</parameter></paramdef>
1637 <paramdef>IceHostBasedAuthProc<parameter> host_based_auth_proc</parameter></paramdef>
1641 <variablelist remap='IP'>
1643 <term><emphasis remap='I'>IceListenObj</emphasis></term>
1645 <para>The listen object.</para>
1649 <term><emphasis remap='I'>host_based_auth_proc</emphasis></term>
1651 <para>The host based authentication procedure.</para>
1658 By default, each listen object has no host based authentication procedure
1659 associated with it. Passing NULL for host_based_auth_proc turns off
1660 host based authentication if it was previously set.
1664 <funcsynopsis id='HostBasedAuthProc'>
1666 <funcdef>Bool <function>HostBasedAuthProc</function></funcdef>
1667 <paramdef>char<parameter> *host_name</parameter></paramdef>
1671 <variablelist remap='IP'>
1673 <term><emphasis remap='I'>host_name</emphasis></term>
1676 The host name of the client that tried to open an ICE connection.
1684 The host_name argument is a string in the form
1685 <emphasis remap='I'>protocol</emphasis>/
1686 <emphasis remap='I'>hostname</emphasis>,
1687 where <emphasis remap='I'>protocol</emphasis> is one of
1688 {tcp, decnet, local}.
1692 If <function>IceHostBasedAuthProc</function> returns
1693 <function>True</function>
1694 access will be granted, even though the original authentication failed.
1695 Note that authentication can effectively be disabled by registering an
1696 <function>IceHostBasedAuthProc</function>
1697 which always returns <function>True</function>
1701 Host based authentication is also allowed at
1702 <function>ProtocolSetup</function> time.
1703 The callback is specified in the
1704 <xref linkend='IceRegisterForProtocolReply' xrefstyle='select: title'/>
1706 <xref linkend='Protocol_Registration' xrefstyle='select: title'/>).
1710 <sect1 id='Accepting_ICE_Connections'>
1711 <title>Accepting ICE Connections</title>
1715 After a connection attempt is detected on a listen object returned by
1716 <xref linkend='IceListenForConnections' xrefstyle='select: title'/>
1717 you should call <xref linkend='IceAcceptConnection' xrefstyle='select: title'/>
1718 This returns a new opaque ICE connection object.
1721 <funcsynopsis id='IceAcceptConnection'>
1723 <funcdef>IceConn <function>IceAcceptConnection</function></funcdef>
1724 <paramdef>IceListenObj<parameter> listen_obj</parameter></paramdef>
1725 <paramdef>IceAcceptStatus<parameter> *status_ret</parameter></paramdef>
1730 <variablelist remap='IP'>
1732 <term><emphasis remap='I'>listen_obj</emphasis></term>
1734 <para>The listen object on which a new connection was detected.</para>
1738 <variablelist remap='IP'>
1740 <term><emphasis remap='I'>status_ret</emphasis></term>
1742 <para>Return status information.</para>
1748 <para>The status_ret argument is set to one of the following values:</para>
1751 <para><function>IceAcceptSuccess</function>
1752 - the accept operation succeeded,
1753 and the function returns a new connection object.</para>
1756 <para><function>IceAcceptFailure</function>
1757 - the accept operation failed, and the function returns NULL.</para>
1760 <para><function>IceAcceptBadMalloc</function>
1761 - a memory allocation failed, and the function returns NULL.</para>
1765 <para>In general, to detect new connections, you should call
1766 <function>select</function>
1767 on the file descriptors associated with the listen objects.
1768 When a new connection is detected, the
1769 <xref linkend='IceAcceptConnection' xrefstyle='select: title'/>
1770 function should be called.
1771 <xref linkend='IceAcceptConnection' xrefstyle='select: title'/>
1772 may return a new ICE connection that is in a pending state. This is because
1773 before the connection can become valid, authentication may be necessary.
1774 Because the ICE library cannot block and wait for the connection to
1775 become valid (infinite blocking can occur if the connecting client
1776 does not act properly), the application must wait for the connection status
1777 to become valid.</para>
1779 <para>The following pseudo-code demonstrates how connections are accepted:</para>
1781 <literallayout class="monospaced">
1782 new_ice_conn = IceAcceptConnection (listen_obj, &accept_status);
1783 if (accept_status != IceAcceptSuccess)
1785 close the file descriptor and return
1788 status = IceConnectionStatus (new_ice_conn);
1789 time_start = time_now;
1791 while (status == IceConnectPending)
1793 select() on {new_ice_conn, all open connections}
1795 for (each ice_conn in the list of open connections)
1796 if (data ready on ice_conn)
1798 status = IceProcessMessages (ice_conn, NULL, NULL);
1799 if (status == IceProcessMessagesIOError)
1800 IceCloseConnection(ice_conn);
1802 if data ready on new_ice_conn
1805 * IceProcessMessages is called until the connection
1806 * is non-pending. Doing so handles the connection
1807 * setup request and any authentication requirements.
1810 IceProcessMessages ( new_ice_conn, NULL, NULL);
1811 status = IceConnectionStatus (new_ice_conn);
1815 if (time_now - time_start > MAX_WAIT_TIME)
1816 status = IceConnectRejected;
1820 if (status == IceConnectAccepted)
1822 Add new_ice_conn to the list of open connections
1832 <xref linkend='IceAcceptConnection' xrefstyle='select: title'/>
1833 is called and the connection has been
1834 validated, the client is ready to receive a
1835 <function>ProtocolSetup</function>
1838 <xref linkend='IceRegisterForProtocolReply' xrefstyle='select: title'/>
1839 was called) or send a
1840 <function>ProtocolSetup</function>
1842 <xref linkend='IceRegisterForProtocolSetup' xrefstyle='select: title'/>
1846 <sect1 id='Closing_ICE_Connections'>
1847 <title>Closing ICE Connections</title>
1849 <para>To close an ICE connection created with
1850 <xref linkend='IceOpenConnection' xrefstyle='select: title'/>
1852 <xref linkend='IceAcceptConnection' xrefstyle='select: title'/>
1854 <xref linkend='IceCloseConnection' xrefstyle='select: title'/></para>
1856 <funcsynopsis id='IceCloseConnection'>
1858 <funcdef>IceCloseStatus <function>IceCloseConnection</function></funcdef>
1859 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
1863 <variablelist remap='IP'>
1865 <term><emphasis remap='I'>ice_conn</emphasis></term>
1867 <para>The ICE connection to close.</para>
1872 <para>To actually close an ICE connection, the following conditions
1877 <para>The <emphasis remap='I'>open reference count</emphasis> must have reached zero on this ICE connection.
1879 <xref linkend='IceOpenConnection' xrefstyle='select: title'/>
1880 is called, it tries to use a previously opened
1881 ICE connection. If it is able to use an existing connection, it increments
1882 the open reference count on the connection by one.
1883 So, to close an ICE connection, each call to
1884 <xref linkend='IceOpenConnection' xrefstyle='select: title'/>
1885 must be matched with a call to
1886 <xref linkend='IceCloseConnection' xrefstyle='select: title'/>
1887 The connection can be closed only
1889 <xref linkend='IceCloseConnection' xrefstyle='select: title'/></para>
1892 <para>The <emphasis remap='I'>active protocol count</emphasis> must have reached zero. Each time a
1893 <function>ProtocolSetup</function>
1894 succeeds on the connection, the active protocol count
1895 is incremented by one. When the client no longer expects to use the
1896 protocol on the connection, the
1897 <xref linkend='IceProtocolShutdown' xrefstyle='select: title'/>
1898 function should be called, which decrements the active protocol count
1900 <xref linkend='Protocol_Setup_and_Shutdown' xrefstyle='select: title'/>).
1904 <para>If shutdown negotiation is enabled on the connection, the client on the other
1905 side of the ICE connection must agree to have the connection closed.</para>
1907 <para><xref linkend='IceCloseConnection' xrefstyle='select: title'/>
1908 returns one of the following values:</para>
1911 <para><function>IceClosedNow</function>
1912 - the ICE connection was closed at this time. The watch procedures were
1913 invoked and the connection was freed.</para>
1916 <para><function>IceClosedASAP</function>
1917 - an IO error had occurred on the connection, but
1918 <xref linkend='IceCloseConnection' xrefstyle='select: title'/>
1919 is being called within a nested
1920 <xref linkend='IceProcessMessages' xrefstyle='select: title'/>
1921 The watch procedures have been invoked at this time, but the connection
1922 will be freed as soon as possible (when the nesting level reaches zero and
1923 <xref linkend='IceProcessMessages' xrefstyle='select: title'/>
1925 <function>IceProcessMessagesConnectionClosed</function></para>
1928 <para><function>IceConnectionInUse</function>
1929 - the connection was not closed at this time, because it is being used by
1930 other active protocols.</para>
1933 <para><function>IceStartedShutdownNegotiation</function>
1934 - the connection was not closed at this time and shutdown negotiation started
1935 with the client on the other side of the ICE connection. When the connection
1937 <xref linkend='IceProcessMessages' xrefstyle='select: title'/>
1938 will return a status of
1939 <function>IceProcessMessagesConnectionClosed</function></para>
1943 <para>When it is known that the client on the other side of the ICE connection
1944 has terminated the connection without initiating shutdown negotiation, the
1945 <xref linkend='IceSetShutdownNegotiation' xrefstyle='select: title'/>
1946 function should be called to turn off shutdown negotiation. This will prevent
1947 <xref linkend='IceCloseConnection' xrefstyle='select: title'/>
1948 from writing to a broken connection.</para>
1950 <funcsynopsis id='IceSetShutdownNegotiation'>
1952 <funcdef>void <function>IceSetShutdownNegotiation</function></funcdef>
1953 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
1954 <paramdef>Bool<parameter> negotiate</parameter></paramdef>
1958 <variablelist remap='IP'>
1960 <term><emphasis remap='I'>ice_conn</emphasis></term>
1962 <para>A valid ICE connection object.</para>
1966 <term><emphasis remap='I'>negotiate</emphasis></term>
1969 <function>False</function>
1970 shutdown negotiating will be turned off.</para>
1975 <para>To check the shutdown negotiation status of an ICE connection, use
1976 <xref linkend='IceCheckShutdownNegotiation' xrefstyle='select: title'/></para>
1978 <funcsynopsis id='IceCheckShutdownNegotiation'>
1980 <funcdef>Bool <function>IceCheckShutdownNegotiation</function></funcdef>
1981 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
1985 <variablelist remap='IP'>
1987 <term><emphasis remap='I'>ice_conn</emphasis></term>
1989 <para>A valid ICE connection object.</para>
1995 <para><xref linkend='IceCheckShutdownNegotiation' xrefstyle='select: title'/>
1997 <function>True</function>
1998 if shutdown negotiation will take place on the connection;
1999 otherwise, it returns
2000 <function>False</function>
2001 Negotiation is on by default for a connection. It
2002 can only be changed with the
2003 <xref linkend='IceSetShutdownNegotiation' xrefstyle='select: title'/>
2007 <sect1 id='Connection_Watch_Procedures'>
2008 <title>Connection Watch Procedures</title>
2010 <para>To add a watch procedure that will be called
2011 each time ICElib opens a new connection via
2012 <xref linkend='IceOpenConnection' xrefstyle='select: title'/>
2014 <xref linkend='IceAcceptConnection' xrefstyle='select: title'/>
2015 or closes a connection via
2016 <xref linkend='IceCloseConnection' xrefstyle='select: title'/>
2018 <xref linkend='IceAddConnectionWatch' xrefstyle='select: title'/></para>
2020 <funcsynopsis id='IceAddConnectionWatch'>
2022 <funcdef>Status <function>IceAddConnectionWatch</function></funcdef>
2023 <paramdef>IceWatchProc<parameter> watch_proc</parameter></paramdef>
2024 <paramdef>IcePointer<parameter> client_data</parameter></paramdef>
2028 <variablelist remap='IP'>
2030 <term><emphasis remap='I'>watch_proc</emphasis></term>
2033 The watch procedure to invoke when ICElib opens or closes a connection.
2038 <term><emphasis remap='I'>client_data</emphasis></term>
2040 <para>This pointer will be passed to the watch procedure.</para>
2047 The return value of <xref linkend='IceAddConnectionWatch' xrefstyle='select: title'/>
2048 is zero for failure, and a positive value for success.
2052 Note that several calls to <xref linkend='IceOpenConnection' xrefstyle='select: title'/>
2053 might share the same ICE connection. In such a case, the watch procedure
2054 is only invoked when the connection is first created (after authentication
2055 succeeds). Similarly, because connections might be shared, the
2056 watch procedure is called only if <xref linkend='IceCloseConnection' xrefstyle='select: title'/>
2057 actually closes the connection (right before the IceConn is freed).
2061 The watch procedures are very useful for applications that
2062 need to add a file descriptor to a select mask when a new connection
2063 is created and remove the file descriptor when the connection is destroyed.
2064 Because connections are shared, knowing when to add and remove the file
2065 descriptor from the select mask would be difficult without the watch
2070 Multiple watch procedures may be registered with the ICE library.
2071 No assumptions should be made about their order of invocation.
2075 If one or more ICE connections were already created by the ICE library at the
2076 time the watch procedure is registered, the watch procedure will instantly
2077 be invoked for each of these ICE connections (with the opening argument
2078 set to <function>True</function>
2082 The watch procedure is of type <function>IceWatchProc</function>
2085 <funcsynopsis id='WatchProc'>
2087 <funcdef>void <function>WatchProc</function></funcdef>
2088 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
2089 <paramdef>IcePointer<parameter> client_data</parameter></paramdef>
2090 <paramdef>Bool<parameter> opening</parameter></paramdef>
2091 <paramdef>IcePointer<parameter> *watch_data</parameter></paramdef>
2095 <variablelist remap='IP'>
2097 <term><emphasis remap='I'>ice_conn</emphasis></term>
2100 The opened or closed ICE connection. Call
2101 <function>IceConnectionNumber</function>
2102 to get the file descriptor associated with this connection.
2107 <term><emphasis remap='I'>client_data</emphasis></term>
2110 Client data specified in the call to
2111 <xref linkend='IceAddConnectionWatch' xrefstyle='select: title'/>
2116 <term><emphasis remap='I'>opening</emphasis></term>
2119 If <function>True</function> the connection is being opened. If
2120 <function>False</function> the connection is being closed.
2125 <term><emphasis remap='I'>watch_data</emphasis></term>
2127 <para>Can be used to save a pointer to client data.</para>
2133 If opening is <function>True</function> the client should set the
2134 *watch_data pointer to any data it may need to save until the connection
2135 is closed and the watch procedure is invoked again with opening set to
2136 <function>False</function>
2140 To remove a watch procedure, use
2141 <xref linkend='IceRemoveConnectionWatch' xrefstyle='select: title'/>
2144 <funcsynopsis id='IceRemoveConnectionWatch'>
2146 <funcdef>void <function>IceRemoveConnectionWatch</function></funcdef>
2147 <paramdef>IceWatchProc<parameter> watch_proc</parameter></paramdef>
2148 <paramdef>IcePointer<parameter> client_data</parameter></paramdef>
2152 <variablelist remap='IP'>
2154 <term><emphasis remap='I'>watch_proc</emphasis></term>
2157 The watch procedure that was passed to
2158 <xref linkend='IceAddConnectionWatch' xrefstyle='select: title'/>
2163 <term><emphasis remap='I'>client_data</emphasis></term>
2166 The client_data pointer that was passed to
2167 <xref linkend='IceAddConnectionWatch' xrefstyle='select: title'/>
2176 <chapter id='Protocol_Setup_and_Shutdown'>
2177 <title>Protocol Setup and Shutdown</title>
2180 To activate a protocol on a given ICE connection, use
2181 <xref linkend='IceProtocolSetup' xrefstyle='select: title'/>
2184 <funcsynopsis id='IceProtocolSetup'>
2186 <funcdef>IceProtocolSetupStatus <function>IceProtocolSetup</function></funcdef>
2187 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
2188 <paramdef>int<parameter> my_opcode</parameter></paramdef>
2189 <paramdef>IcePointer<parameter> client_data</parameter></paramdef>
2190 <paramdef>Bool<parameter> must_authenticate</parameter></paramdef>
2191 <paramdef>int<parameter> *major_version_ret</parameter></paramdef>
2192 <paramdef>int<parameter> *minor_version_ret</parameter></paramdef>
2193 <paramdef>char<parameter> **vendor_ret</parameter></paramdef>
2194 <paramdef>char<parameter> **release_ret</parameter></paramdef>
2195 <paramdef>int<parameter> error_length</parameter></paramdef>
2196 <paramdef>char<parameter> *error_string_ret</parameter></paramdef>
2200 <variablelist remap='IP'>
2202 <term><emphasis remap='I'>ice_conn</emphasis></term>
2204 <para>A valid ICE connection object.</para>
2208 <term><emphasis remap='I'>my_opcode</emphasis></term>
2211 The major opcode of the protocol to be set up, as returned by
2212 <xref linkend='IceRegisterForProtocolSetup' xrefstyle='select: title'/>
2217 <term><emphasis remap='I'>client_data</emphasis></term>
2220 The client data stored in this pointer will be passed to the
2221 <function>IcePoProcessMsgProc</function> callback.
2226 <term><emphasis remap='I'>must_authenticate</emphasis></term>
2229 If <function>True</function> the other client may
2230 not bypass authentication.
2235 <term><emphasis remap='I'>major_version_ret</emphasis></term>
2237 <para>The major version of the protocol to be used is returned.</para>
2241 <term><emphasis remap='I'>minor_version_ret</emphasis></term>
2243 <para>The minor version of the protocol to be used is returned.</para>
2247 <term><emphasis remap='I'>vendor_ret</emphasis></term>
2249 <para>The vendor string specified by the protocol acceptor.</para>
2253 <term><emphasis remap='I'>release_ret</emphasis></term>
2255 <para>The release string specified by the protocol acceptor.</para>
2259 <term><emphasis remap='I'>error_length</emphasis></term>
2262 Specifies the length of the error_string_ret argument passed in.
2267 <term><emphasis remap='I'>error_string_ret</emphasis></term>
2270 Returns a null-terminated error message, if any.
2271 The error_string_ret argument points to user supplied memory.
2272 No more than error_length bytes are used.
2279 The vendor_ret and release_ret strings should be freed with
2280 <function>free</function> when no longer needed.
2284 <xref linkend='IceProtocolSetup' xrefstyle='select: title'/> returns one of the following values:
2290 <function>IceProtocolSetupSuccess</function> - the major_version_ret,
2291 minor_version_ret, vendor_ret, release_ret are set.
2296 <function>IceProtocolSetupFailure</function> or
2297 <function>IceProtocolSetupIOError</function>
2298 - check error_string_ret for failure reason. The major_version_ret,
2299 minor_version_ret, vendor_ret, release_ret are not set.
2304 <function>IceProtocolAlreadyActive</function>
2305 - this protocol is already active on this connection.
2306 The major_version_ret, minor_version_ret, vendor_ret, release_ret
2313 To notify the ICE library when a given protocol will no longer be used
2314 on an ICE connection, use <xref linkend='IceProtocolShutdown' xrefstyle='select: title'/>
2317 <funcsynopsis id='IceProtocolShutdown'>
2319 <funcdef>Status <function>IceProtocolShutdown</function></funcdef>
2320 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
2321 <paramdef>int<parameter> major_opcode</parameter></paramdef>
2325 <variablelist remap='IP'>
2327 <term><emphasis remap='I'>ice_conn</emphasis></term>
2329 <para>A valid ICE connection object.</para>
2333 <term><emphasis remap='I'>major_opcode</emphasis></term>
2335 <para>The major opcode of the protocol to shut down.</para>
2342 The return value of <xref linkend='IceProtocolShutdown' xrefstyle='select: title'/>
2343 is zero for failure and a positive value for success.
2347 Failure will occur if the major opcode was never registered OR the protocol
2348 of the major opcode was never activated on the connection. By activated,
2349 we mean that a <function>ProtocolSetup</function> succeeded on the connection.
2350 Note that ICE does not define how each sub-protocol triggers a
2355 <chapter id='Processing_Messages'>
2356 <title>Processing Messages</title>
2359 <para>To process incoming messages on an ICE connection, use
2360 <xref linkend='IceProcessMessages' xrefstyle='select: title'/></para>
2362 <funcsynopsis id='IceProcessMessages'>
2364 <funcdef>IceProcessMessagesStatus <function>IceProcessMessages</function></funcdef>
2365 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
2366 <paramdef>IceReplyWaitInfo<parameter> *reply_wait</parameter></paramdef>
2367 <paramdef>Bool<parameter> *reply_ready_ret</parameter></paramdef>
2371 <variablelist remap='IP'>
2373 <term><emphasis remap='I'>ice_conn</emphasis></term>
2375 <para>A valid ICE connection object.</para>
2379 <term><emphasis remap='I'>reply_wait</emphasis></term>
2381 <para>Indicates if a reply is being waited for.</para>
2385 <term><emphasis remap='I'>reply_ready_ret</emphasis></term>
2388 If set to <function>True</function> on return, a reply is ready.
2395 <xref linkend='IceProcessMessages' xrefstyle='select: title'/> is used in two ways:
2401 In the first, a client may generate a message and block by calling
2402 <xref linkend='IceProcessMessages' xrefstyle='select: title'/> repeatedly until it gets its reply.
2407 In the second, a client calls <xref linkend='IceProcessMessages' xrefstyle='select: title'/>
2408 with reply_wait set to NULL in response to <function>select</function>
2409 showing that there is data to read on the ICE connection.
2410 The ICE library may process zero or more complete messages.
2411 Note that messages that are not blocked for are always processed by
2418 <function>IceReplyWaitInfo</function> contains the major/minor opcodes
2419 and sequence number of the message for which a reply is being awaited.
2420 It also contains a pointer to the reply message to be filled in (the
2421 protocol library should cast this <function>IcePointer</function>
2422 to the appropriate reply type). In most
2423 cases, the reply will have some fixed-size part, and the client waiting
2424 for the reply will have provided a pointer to a structure to hold
2425 this fixed-size data. If there is variable-length data, it would be
2427 <function>IcePoProcessMsgProc</function>
2428 callback will have to allocate additional
2429 memory and store pointer(s) to that memory in the fixed-size
2430 structure. If the entire data is variable length (for example, a single
2431 variable-length string), then the client waiting for the reply would probably
2432 just pass a pointer to fixed-size space to hold a pointer, and the
2433 <function>IcePoProcessMsgProc</function>
2434 callback would allocate the storage and store the pointer.
2435 It is the responsibility of the client receiving the reply to
2436 free up any memory allocated on its behalf.
2439 <literallayout class="monospaced">
2441 unsigned long sequence_of_request;
2442 int major_opcode_of_request;
2443 int minor_opcode_of_request;
2449 If reply_wait is not NULL and
2450 <xref linkend='IceProcessMessages' xrefstyle='select: title'/>
2451 has a reply or error to return in response to this reply_wait
2452 (that is, no callback was generated), then the reply_ready_ret argument
2453 will be set to <function>True</function>
2457 If reply_wait is NULL, then the caller may also pass NULL for
2458 reply_ready_ret and be guaranteed that no value will be stored in
2463 <xref linkend='IceProcessMessages' xrefstyle='select: title'/> returns one of the following values:
2469 <function>IceProcessMessagesSuccess</function> - no error occurred.
2474 <function>IceProcessMessagesIOError</function> - an IO error occurred,
2475 and the caller must explicitly close the connection by calling
2476 <xref linkend='IceCloseConnection' xrefstyle='select: title'/>
2481 <function>IceProcessMessagesConnectionClosed</function>
2482 - the ICE connection has been closed (closing of the connection was deferred
2483 because of shutdown negotiation, or because the
2484 <xref linkend='IceProcessMessages' xrefstyle='select: title'/>
2485 nesting level was not zero). Do not attempt
2486 to access the ICE connection at this point, since it has been freed.
2497 To send a "Ping" message to the client on the other side of the
2498 ICE connection, use <xref linkend='IcePing' xrefstyle='select: title'/>
2501 <funcsynopsis id='IcePing'>
2503 <funcdef>Status <function>IcePing</function></funcdef>
2504 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
2505 <paramdef>IcePingReplyProc<parameter> ping_reply_proc</parameter></paramdef>
2506 <paramdef>IcePointer<parameter> client_data</parameter></paramdef>
2510 <variablelist remap='IP'>
2512 <term><emphasis remap='I'>ice_conn</emphasis></term>
2514 <para>A valid ICE connection object.</para>
2518 <term><emphasis remap='I'>ping_reply_proc</emphasis></term>
2520 <para>The callback to invoke when the Ping reply arrives.</para>
2524 <term><emphasis remap='I'>client_data</emphasis></term>
2527 This pointer will be passed to the <olink targetdoc='SMlib' targetptr='IcePingReplyProc'><function>IcePingReplyProc</function></olink>
2535 <para><xref linkend='IcePing' xrefstyle='select: title'/>
2536 returns zero for failure and a positive value for success.</para>
2539 <xref linkend='IceProcessMessages' xrefstyle='select: title'/>
2540 processes the Ping reply, it will invoke the
2541 <olink targetdoc='SMlib' targetptr='IcePingReplyProc'><function>IcePingReplyProc</function></olink>
2544 <funcsynopsis id='PingReplyProc'>
2546 <funcdef>void <function>PingReplyProc</function></funcdef>
2547 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
2548 <paramdef>IcePointer<parameter> client_data</parameter></paramdef>
2552 <variablelist remap='IP'>
2554 <term><emphasis remap='I'>ice_conn</emphasis></term>
2556 <para>A valid ICE connection object.</para>
2560 <term><emphasis remap='I'>client_data</emphasis></term>
2562 <para>The client data specified in the call to
2563 <xref linkend='IcePing' xrefstyle='select: title'/></para>
2570 <chapter id='Using_ICElib_Informational_Functions'>
2571 <title>Using ICElib Informational Functions</title>
2573 <funcsynopsis id='IceConnectionStatus'>
2575 <funcdef>IceConnectStatus <function>IceConnectionStatus</function></funcdef>
2576 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
2580 <para><xref linkend='IceConnectionStatus' xrefstyle='select: title'/>
2581 returns the status of an ICE connection. The possible return values are:</para>
2585 <para><function>IceConnectPending</function>
2586 - the connection is not valid yet (that is, authentication is taking place).
2587 This is only relevant to connections created by
2588 <xref linkend='IceAcceptConnection' xrefstyle='select: title'/></para>
2591 <para><function>IceConnectAccepted</function>
2592 - the connection has been accepted.
2593 This is only relevant to connections created by
2594 <xref linkend='IceAcceptConnection' xrefstyle='select: title'/></para>
2597 <para><function>IceConnectRejected</function>
2598 - the connection had been rejected (that is, authentication failed).
2599 This is only relevant to connections created by
2600 <xref linkend='IceAcceptConnection' xrefstyle='select: title'/></para>
2603 <para><function>IceConnectIOError</function>
2604 - an IO error has occurred on the connection.</para>
2608 <funcsynopsis id='IceVendor'>
2610 <funcdef>char <function> *IceVendor</function></funcdef>
2611 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
2615 <para><function>IceVendor</function>
2616 returns the ICE library vendor identification
2617 for the other side of the connection.
2618 The string should be freed with a call to
2619 <function>free</function>
2620 when no longer needed.</para>
2622 <funcsynopsis id='IceRelease'>
2624 <funcdef>char <function> *IceRelease</function></funcdef>
2625 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
2629 <para><function>IceRelease</function>
2630 returns the release identification of the ICE library
2631 on the other side of the connection.
2632 The string should be freed with a call to
2633 <function>free</function>
2634 when no longer needed.</para>
2636 <funcsynopsis id='IceProtocolVersion'>
2638 <funcdef>int <function> IceProtocolVersion</function></funcdef>
2639 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
2643 <para><xref linkend='IceProtocolVersion' xrefstyle='select: title'/>
2644 returns the major version of the ICE protocol on this connection.</para>
2646 <funcsynopsis id='IceProtocolRevision'>
2648 <funcdef>int <function> IceProtocolRevision</function></funcdef>
2649 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
2654 <para><xref linkend='IceProtocolRevision' xrefstyle='select: title'/>
2655 returns the minor version of the ICE protocol on this connection.</para>
2659 <funcdef>int <function> IceConnectionNumber</function></funcdef>
2660 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
2665 <para><function>IceConnectionNumber</function>
2666 returns the file descriptor of this ICE connection.</para>
2668 <funcsynopsis id='IceConnectionString'>
2670 <funcdef>char <function> *IceConnectionString</function></funcdef>
2671 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
2675 <para><function>IceConnectionString</function>
2676 returns the network ID of the client that
2677 accepted this connection. The string should be freed with a call to
2678 <function>free</function>
2679 when no longer needed.</para>
2681 <funcsynopsis id='IceLastSentSequenceNumber'>
2683 <funcdef>unsigned long <function> IceLastSentSequenceNumber</function></funcdef>
2684 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
2689 <para><xref linkend='IceLastSentSequenceNumber' xrefstyle='select: title'/>
2690 returns the sequence number of the last message sent on this ICE connection.</para>
2694 <funcdef>unsigned long <function> IceLastReceivedSequenceNumber</function></funcdef>
2695 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
2699 <para><function>IceLastReceivedSequenceNumber</function>
2700 returns the sequence number of the last message received on this
2701 ICE connection.</para>
2703 <funcsynopsis id='IceSwapping'>
2705 <funcdef>Bool <function> IceSwapping</function></funcdef>
2706 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
2711 <para><xref linkend='IceSwapping' xrefstyle='select: title'/>
2713 <function>True</function>
2714 if byte swapping is necessary when reading messages on the ICE connection.</para>
2716 <funcsynopsis id='IceGetContext'>
2718 <funcdef>IcePointer <function> IceGetContext</function></funcdef>
2719 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
2723 <para><xref linkend='IceGetContext' xrefstyle='select: title'/>
2724 returns the context associated with a connection created by
2725 <xref linkend='IceOpenConnection' xrefstyle='select: title'/></para>
2728 <chapter id='ICE_Messages'>
2729 <title>ICE Messages</title>
2732 All ICE messages have a standard 8-byte header. The ICElib macros that
2733 read and write messages rely on the following naming convention for message
2737 <literallayout class='monospaced'>
2745 The 3rd and 4th bytes of the message header can be used as needed.
2746 The length field is specified in units of 8 bytes.
2749 <sect1 id='Sending_ICE_Messages'>
2750 <title>Sending ICE Messages</title>
2753 The ICE library maintains an output buffer used for generating messages.
2754 Protocol libraries layered on top of ICE may choose to batch messages
2755 together and flush the output buffer at appropriate times.
2759 If an IO error has occurred on an ICE connection, all write operations
2760 will be ignored. For further information, see
2761 <xref linkend='Error_Handling' xrefstyle='select: title'/>.
2766 To get the size of the ICE output buffer, use
2767 <xref linkend='IceGetOutBufSize' xrefstyle='select: title'/>
2770 <funcsynopsis id='IceGetOutBufSize'>
2772 <funcdef>int <function> IceGetOutBufSize</function></funcdef>
2773 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
2777 <variablelist remap='IP'>
2779 <term><emphasis remap='I'>ice_conn</emphasis></term>
2781 <para>A valid ICE connection object.</para>
2788 To flush the ICE output buffer, use <xref linkend='IceFlush' xrefstyle='select: title'/>
2791 <funcsynopsis id='IceFlush'>
2793 <funcdef>int <function> IceFlush</function></funcdef>
2794 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
2798 <variablelist remap='IP'>
2800 <term><emphasis remap='I'>ice_conn</emphasis></term>
2802 <para>A valid ICE connection object.</para>
2808 Note that the output buffer may be implicitly flushed if there is
2809 insufficient space to generate a message.
2812 <para>The following macros can be used to generate ICE messages:</para>
2814 <funcsynopsis id='IceGetHeader'>
2816 <funcdef><function> IceGetHeader</function></funcdef>
2817 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
2818 <paramdef>int<parameter> major_opcode</parameter></paramdef>
2819 <paramdef>int<parameter> minor_opcode</parameter></paramdef>
2820 <paramdef>int<parameter> header_size</parameter></paramdef>
2821 <paramdef><C_data_type><parameter> *pmsg</parameter></paramdef>
2825 <variablelist remap='IP'>
2827 <term><emphasis remap='I'>ice_conn</emphasis></term>
2829 <para>A valid ICE connection object.</para>
2833 <term><emphasis remap='I'>major_opcode</emphasis></term>
2835 <para>The major opcode of the message.</para>
2839 <term><emphasis remap='I'>minor_opcode</emphasis></term>
2841 <para>The minor opcode of the message.</para>
2845 <term><emphasis remap='I'>header_size</emphasis></term>
2847 <para>The size of the message header (in bytes).</para>
2851 <term><emphasis remap='I'><C_data_type></emphasis></term>
2853 <para>The actual C data type of the message header.</para>
2857 <term><emphasis remap='I'>pmsg</emphasis></term>
2860 The message header pointer. After this macro is called, the
2861 library can store data in the message header.
2869 <xref linkend='IceGetHeader' xrefstyle='select: title'/>
2870 is used to set up a message header on an ICE connection.
2871 It sets the major and minor opcodes of the message, and initializes
2872 the message's length to the length of the header. If additional
2873 variable length data follows, the message's length field should be
2878 <funcsynopsis id='IceGetHeaderExtra'>
2880 <funcdef><function> IceGetHeaderExtra</function></funcdef>
2881 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
2882 <paramdef>int<parameter> major_opcode</parameter></paramdef>
2883 <paramdef>int<parameter> minor_opcode</parameter></paramdef>
2884 <paramdef>int<parameter> header_size</parameter></paramdef>
2885 <paramdef>int<parameter> extra</parameter></paramdef>
2886 <paramdef><C_data_type><parameter> *pmsg</parameter></paramdef>
2887 <paramdef>char<parameter> *pdata</parameter></paramdef>
2891 <variablelist remap='IP'>
2893 <term><emphasis remap='I'>ice_conn</emphasis></term>
2895 <para>A valid ICE connection object.</para>
2899 <term><emphasis remap='I'>major_opcode</emphasis></term>
2901 <para>The major opcode of the message.</para>
2905 <term><emphasis remap='I'>minor_opcode</emphasis></term>
2907 <para>The minor opcode of the message.</para>
2911 <term><emphasis remap='I'>header_size</emphasis></term>
2913 <para>The size of the message header (in bytes).</para>
2917 <term><emphasis remap='I'>extra</emphasis></term>
2920 The size of the extra data beyond the header (in 8-byte units).
2925 <term><emphasis remap='I'><C_data_type></emphasis></term>
2927 <para>The actual C data type of the message header.</para>
2931 <term><emphasis remap='I'>pmsg</emphasis></term>
2934 The message header pointer. After this macro is called, the
2935 library can store data in the message header.
2940 <term><emphasis remap='I'>pdata</emphasis></term>
2943 Returns a pointer to the ICE output buffer that points
2944 immediately after the message header. The variable length
2945 data should be stored here. If there was not enough room
2946 in the ICE output buffer, pdata is set to NULL.
2954 <xref linkend='IceGetHeaderExtra' xrefstyle='select: title'/>
2955 is used to generate a message with a fixed (and relatively small) amount
2956 of variable length data. The complete message must fit in the ICE output
2960 <funcsynopsis id='IceSimpleMessage'>
2962 <funcdef><function> IceSimpleMessage</function></funcdef>
2963 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
2964 <paramdef>int<parameter> major_opcode</parameter></paramdef>
2965 <paramdef>int<parameter> minor_opcode</parameter></paramdef>
2969 <variablelist remap='IP'>
2971 <term><emphasis remap='I'>ice_conn</emphasis></term>
2973 <para>A valid ICE connection object.</para>
2977 <term><emphasis remap='I'>major_opcode</emphasis></term>
2979 <para>The major opcode of the message.</para>
2983 <term><emphasis remap='I'>minor_opcode</emphasis></term>
2985 <para>The minor opcode of the message.</para>
2991 <xref linkend='IceSimpleMessage' xrefstyle='select: title'/>
2992 is used to generate a message that is identical
2993 in size to the ICE header message, and has no additional data.
2996 <funcsynopsis id='IceErrorHeader'>
2998 <funcdef><function> IceErrorHeader</function></funcdef>
2999 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
3000 <paramdef>int<parameter> offending_major_opcode</parameter></paramdef>
3001 <paramdef>int<parameter> offending_minor_opcode</parameter></paramdef>
3002 <paramdef>int<parameter> offending_sequence_num</parameter></paramdef>
3003 <paramdef>int<parameter> severity</parameter></paramdef>
3004 <paramdef>int<parameter> error_class</parameter></paramdef>
3005 <paramdef>int<parameter> data_length</parameter></paramdef>
3009 <variablelist remap='IP'>
3011 <term><emphasis remap='I'>ice_conn</emphasis></term>
3013 <para>A valid ICE connection object.</para>
3017 <term><emphasis remap='I'>offending_major_opcode</emphasis></term>
3020 The major opcode of the protocol in which an error was detected.
3025 <term><emphasis remap='I'>offending_minor_opcode</emphasis></term>
3028 The minor opcode of the protocol in which an error was detected.
3033 <term><emphasis remap='I'>offending_sequence_num</emphasis></term>
3035 <para>The sequence number of the message that caused the error.</para>
3039 <term><emphasis remap='I'>severity</emphasis></term>
3042 <function>IceCanContinue</function>
3043 <function>IceFatalToProtocol</function>
3045 <function>IceFatalToConnection</function>
3050 <term><emphasis remap='I'>error_class</emphasis></term>
3052 <para>The error class.</para>
3056 <term><emphasis remap='I'>data_length</emphasis></term>
3059 Length of data (in 8-byte units) to be written after the header.
3066 <xref linkend='IceErrorHeader' xrefstyle='select: title'/> sets up an error message header.
3070 Note that the two clients connected by ICE may be using different
3071 major opcodes for a given protocol. The offending_major_opcode passed
3072 to this macro is the major opcode of the protocol for the client
3073 sending the error message.
3077 Generic errors, which are common to all protocols, have classes
3078 in the range 0x8000..0xFFFF.
3079 See the <emphasis remap='I'>Inter-Client Exchange Protocol</emphasis>
3080 standard for more details.
3083 <informaltable frame='none'>
3084 <?dbfo keep-together="always" ?>
3085 <tgroup cols='2' align='left' colsep='0' rowsep='0'>
3086 <colspec colname='c1' colwidth='1.0*'/>
3087 <colspec colname='c2' colwidth='2.0*'/>
3090 <entry>IceBadMinor</entry>
3091 <entry>0x8000</entry>
3094 <entry>IceBadState</entry>
3095 <entry>0x8001</entry>
3098 <entry>IceBadLength</entry>
3099 <entry>0x8002</entry>
3102 <entry>IceBadValue</entry>
3103 <entry>0x8003</entry>
3109 <para>Per-protocol errors have classes in the range 0x0000-0x7fff.</para>
3112 To write data to an ICE connection, use the
3113 <xref linkend='IceWriteData' xrefstyle='select: title'/> macro. If the data fits into the
3114 ICE output buffer, it is copied there. Otherwise, the ICE output buffer
3115 is flushed and the data is directly sent.
3119 This macro is used in conjunction with
3120 <xref linkend='IceGetHeader' xrefstyle='select: title'/> and
3121 <xref linkend='IceErrorHeader' xrefstyle='select: title'/>
3124 <funcsynopsis id='IceWriteData'>
3126 <funcdef><function> IceWriteData</function></funcdef>
3127 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
3128 <paramdef>int<parameter> bytes</parameter></paramdef>
3129 <paramdef>char<parameter> *data</parameter></paramdef>
3133 <variablelist remap='IP'>
3135 <term><emphasis remap='I'>ice_conn</emphasis></term>
3137 <para>A valid ICE connection object.</para>
3141 <term><emphasis remap='I'>bytes</emphasis></term>
3143 <para>The number of bytes to write.</para>
3147 <term><emphasis remap='I'>data</emphasis></term>
3149 <para>The data to write.</para>
3156 To write data as 16-bit quantities, use <xref linkend='IceWriteData16' xrefstyle='select: title'/>
3159 <funcsynopsis id='IceWriteData16'>
3161 <funcdef><function> IceWriteData16</function></funcdef>
3162 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
3163 <paramdef>int<parameter> bytes</parameter></paramdef>
3164 <paramdef>char<parameter> *data</parameter></paramdef>
3168 <variablelist remap='IP'>
3170 <term><emphasis remap='I'>ice_conn</emphasis></term>
3172 <para>A valid ICE connection object.</para>
3176 <term><emphasis remap='I'>bytes</emphasis></term>
3178 <para>The number of bytes to write.</para>
3182 <term><emphasis remap='I'>data</emphasis></term>
3184 <para>The data to write.</para>
3190 To write data as 32-bit quantities, use <xref linkend='IceWriteData32' xrefstyle='select: title'/>
3194 <funcsynopsis id='IceWriteData32'>
3196 <funcdef><function> IceWriteData32</function></funcdef>
3197 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
3198 <paramdef>int<parameter> bytes</parameter></paramdef>
3199 <paramdef>char<parameter> *data</parameter></paramdef>
3203 <variablelist remap='IP'>
3205 <term><emphasis remap='I'>ice_conn</emphasis></term>
3207 <para>A valid ICE connection object.</para>
3211 <term><emphasis remap='I'>bytes</emphasis></term>
3213 <para>The number of bytes to write.</para>
3217 <term><emphasis remap='I'>data</emphasis></term>
3219 <para>The data to write.</para>
3225 To write data as 32-bit quantities, use <xref linkend='IceWriteData32' xrefstyle='select: title'/>
3229 To bypass copying data to the ICE output buffer, use
3230 <xref linkend='IceSendData' xrefstyle='select: title'/> to directly send data over the network
3231 connection. If necessary, the ICE output buffer is first flushed.
3234 <funcsynopsis id='IceSendData'>
3236 <funcdef><function> IceSendData</function></funcdef>
3237 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
3238 <paramdef>int<parameter> bytes</parameter></paramdef>
3239 <paramdef>char<parameter> *data</parameter></paramdef>
3243 <variablelist remap='IP'>
3245 <term><emphasis remap='I'>ice_conn</emphasis></term>
3247 <para>A valid ICE connection object.</para>
3251 <term><emphasis remap='I'>bytes</emphasis></term>
3253 <para>The number of bytes to send.</para>
3257 <term><emphasis remap='I'>data</emphasis></term>
3259 <para>The data to send.</para>
3266 To force 32-bit or 64-bit alignment, use <xref linkend='IceWritePad' xrefstyle='select: title'/>
3267 A maximum of 7 pad bytes can be specified.
3270 <funcsynopsis id='IceWritePad'>
3272 <funcdef><function> IceWritePad</function></funcdef>
3273 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
3274 <paramdef>int<parameter> bytes</parameter></paramdef>
3275 <paramdef>char<parameter> *data</parameter></paramdef>
3279 <variablelist remap='IP'>
3281 <term><emphasis remap='I'>ice_conn</emphasis></term>
3283 <para>A valid ICE connection object.</para>
3287 <term><emphasis remap='I'>bytes</emphasis></term>
3289 <para>The number of bytes to write.</para>
3293 <term><emphasis remap='I'>data</emphasis></term>
3295 <para>The number of pad bytes to write.</para>
3302 <sect1 id='Reading_ICE_Messages'>
3303 <title>Reading ICE Messages</title>
3307 The ICE library maintains an input buffer used for reading messages.
3308 If the ICE library chooses to perform nonblocking reads (this is
3309 implementation-dependent), then for every read operation that it makes,
3310 zero or more complete messages may be read into the input buffer. As
3311 a result, for all of the macros described in this section that read
3312 messages, an actual read operation will occur on the connection only if
3313 the data is not already present in the input buffer.
3318 To get the size of the ICE input buffer, use
3319 <xref linkend='IceGetInBufSize' xrefstyle='select: title'/>
3322 <funcsynopsis id='IceGetInBufSize'>
3324 <funcdef>int<function> IceGetInBufSize</function></funcdef>
3325 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
3329 <variablelist remap='IP'>
3331 <term><emphasis remap='I'>ice_conn</emphasis></term>
3333 <para>A valid ICE connection object.</para>
3339 When reading messages, care must be taken to check for IO errors. If
3340 any IO error occurs in reading any part of a message, the message should
3341 be thrown out. After using any of the macros described below for reading
3342 messages, the <xref linkend='IceValidIO' xrefstyle='select: title'/>
3343 macro can be used to check if an IO error occurred on the
3344 connection. After an IO error has occurred on an ICE connection, all
3345 read operations will be ignored. For further information, see
3346 <xref linkend='Error_Handling' xrefstyle='select: title'/>.
3350 <funcsynopsis id='IceValidIO'>
3352 <funcdef>Bool<function> IceValidIO</function></funcdef>
3353 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
3357 <variablelist remap='IP'>
3359 <term><emphasis remap='I'>ice_conn</emphasis></term>
3361 <para>A valid ICE connection object.</para>
3366 <para>The following macros can be used to read ICE messages.</para>
3368 <funcsynopsis id='IceReadSimpleMessage'>
3370 <funcdef><function> IceReadSimpleMessage</function></funcdef>
3371 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
3372 <paramdef><C_data_type><parameter> *pmsg</parameter></paramdef>
3376 <variablelist remap='IP'>
3378 <term><emphasis remap='I'>ice_conn</emphasis></term>
3380 <para>A valid ICE connection object.</para>
3384 <term><emphasis remap='I'><C_data_type></emphasis></term>
3386 <para>The actual C data type of the message header.</para>
3390 <term><emphasis remap='I'>pmsg</emphasis></term>
3392 <para>This pointer is set to the message header.</para>
3398 <xref linkend='IceReadSimpleMessage' xrefstyle='select: title'/>
3399 is used for messages that are identical in size to the 8-byte ICE header, but
3400 use the spare 2 bytes in the header to encode additional data. Note that the
3401 ICE library always reads in these first 8 bytes, so it can obtain the major
3402 opcode of the message. <xref linkend='IceReadSimpleMessage' xrefstyle='select: title'/>
3403 simply returns a pointer to these 8 bytes; it does not actually read any data
3404 into the input buffer.
3408 For a message with variable length data, there are two ways of reading
3409 the message. One method involves reading the complete message in one
3410 pass using <xref linkend='IceReadCompleteMessage' xrefstyle='select: title'/>
3411 The second method involves reading the message header (note that this may
3412 be larger than the 8-byte ICE header), then reading
3413 the variable length data in chunks (see
3414 <xref linkend='IceReadMessageHeader' xrefstyle='select: title'/> and
3415 <xref linkend='IceReadData' xrefstyle='select: title'/>
3419 <funcsynopsis id='IceReadCompleteMessage'>
3421 <funcdef><function> IceReadCompleteMessage</function></funcdef>
3422 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
3423 <paramdef>int<parameter> header_size</parameter></paramdef>
3424 <paramdef><C_data_type><parameter> *pmsg</parameter></paramdef>
3425 <paramdef>char<parameter> *pdata</parameter></paramdef>
3429 <variablelist remap='IP'>
3431 <term><emphasis remap='I'>ice_conn</emphasis></term>
3433 <para>A valid ICE connection object.</para>
3437 <term><emphasis remap='I'>header_size</emphasis></term>
3439 <para>The size of the message header (in bytes).</para>
3443 <term><emphasis remap='I'><C_data_type></emphasis></term>
3445 <para>The actual C data type of the message header.</para>
3449 <term><emphasis remap='I'>pmsg</emphasis></term>
3451 <para>This pointer is set to the message header.</para>
3455 <term><emphasis remap='I'>pdata</emphasis></term>
3458 This pointer is set to the variable length data of the message.
3465 If the ICE input buffer has sufficient space,
3466 <xref linkend='IceReadCompleteMessage' xrefstyle='select: title'/>
3467 will read the complete message into the
3468 ICE input buffer. Otherwise, a buffer will be allocated to hold the
3469 variable length data. After the call, the pdata argument should
3470 be checked against NULL to make sure that there was sufficient memory
3471 to allocate the buffer.
3475 After calling <xref linkend='IceReadCompleteMessage' xrefstyle='select: title'/>
3476 and processing the message, <xref linkend='IceDisposeCompleteMessage' xrefstyle='select: title'/>
3481 <funcsynopsis id='IceDisposeCompleteMessage'>
3483 <funcdef><function> IceDisposeCompleteMessage</function></funcdef>
3484 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
3485 <paramdef>char<parameter> *pdata</parameter></paramdef>
3489 <variablelist remap='IP'>
3491 <term><emphasis remap='I'>ice_conn</emphasis></term>
3493 <para>A valid ICE connection object.</para>
3497 <term><emphasis remap='I'>pdata</emphasis></term>
3500 The pointer to the variable length data returned in
3501 <xref linkend='IceReadCompleteMessage' xrefstyle='select: title'/>
3508 If a buffer had to be allocated to hold the variable length data (because
3509 it did not fit in the ICE input buffer), it is freed here by ICElib.
3513 <funcsynopsis id='IceReadMessageHeader'>
3515 <funcdef><function> IceReadMessageHeader</function></funcdef>
3516 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
3517 <paramdef>int<parameter> header_size</parameter></paramdef>
3518 <paramdef><C_data_type><parameter> *pmsg</parameter></paramdef>
3522 <variablelist remap='IP'>
3524 <term><emphasis remap='I'>ice_conn</emphasis></term>
3526 <para>A valid ICE connection object.</para>
3530 <term><emphasis remap='I'>header_size</emphasis></term>
3532 <para>The size of the message header (in bytes).</para>
3536 <term><emphasis remap='I'><C_data_type></emphasis></term>
3538 <para>The actual C data type of the message header.</para>
3542 <term><emphasis remap='I'>pmsg</emphasis></term>
3544 <para>This pointer is set to the message header.</para>
3550 <xref linkend='IceReadMessageHeader' xrefstyle='select: title'/> reads just the message header.
3551 The rest of the data should be read with the
3552 <xref linkend='IceReadData' xrefstyle='select: title'/>
3553 family of macros. This method of reading a message should be used when the
3554 variable length data must be read in chunks.
3559 To read data directly into a user supplied buffer, use
3560 <xref linkend='IceReadData' xrefstyle='select: title'/>
3563 <funcsynopsis id='IceReadData'>
3565 <funcdef><function> IceReadData</function></funcdef>
3566 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
3567 <paramdef>int<parameter> bytes</parameter></paramdef>
3568 <paramdef>char<parameter> *pdata</parameter></paramdef>
3572 <variablelist remap='IP'>
3574 <term><emphasis remap='I'>ice_conn</emphasis></term>
3576 <para>A valid ICE connection object.</para>
3580 <term><emphasis remap='I'>bytes</emphasis></term>
3582 <para>The number of bytes to read.</para>
3586 <term><emphasis remap='I'>pdata</emphasis></term>
3588 <para>The data is read into this user supplied buffer.</para>
3595 To read data as 16-bit quantities, use <xref linkend='IceReadData16' xrefstyle='select: title'/>
3598 <funcsynopsis id='IceReadData16'>
3600 <funcdef><function> IceReadData16</function></funcdef>
3601 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
3602 <paramdef>Bool<parameter> swap</parameter></paramdef>
3603 <paramdef>int<parameter> bytes</parameter></paramdef>
3604 <paramdef>char<parameter> *pdata</parameter></paramdef>
3608 <variablelist remap='IP'>
3610 <term><emphasis remap='I'>ice_conn</emphasis></term>
3612 <para>A valid ICE connection object.</para>
3616 <term><emphasis remap='I'>swap</emphasis></term>
3619 If <function>True,</function> the values will be byte swapped.
3624 <term><emphasis remap='I'>bytes</emphasis></term>
3626 <para>The number of bytes to read.</para>
3630 <term><emphasis remap='I'>pdata</emphasis></term>
3632 <para>The data is read into this user supplied buffer.</para>
3639 To read data as 32-bit quantities, use <xref linkend='IceReadData32' xrefstyle='select: title'/>
3642 <funcsynopsis id='IceReadData32'>
3644 <funcdef><function> IceReadData32</function></funcdef>
3645 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
3646 <paramdef>Bool<parameter> swap</parameter></paramdef>
3647 <paramdef>int<parameter> bytes</parameter></paramdef>
3648 <paramdef>char<parameter> *pdata</parameter></paramdef>
3652 <variablelist remap='IP'>
3654 <term><emphasis remap='I'>ice_conn</emphasis></term>
3656 <para>A valid ICE connection object.</para>
3660 <term><emphasis remap='I'>swap</emphasis></term>
3663 If <function>True,</function> the values will be byte swapped.
3668 <term><emphasis remap='I'>bytes</emphasis></term>
3670 <para>The number of bytes to read.</para>
3674 <term><emphasis remap='I'>pdata</emphasis></term>
3676 <para>The data is read into this user supplied buffer.</para>
3681 <para>To force 32-bit or 64-bit alignment, use
3682 <xref linkend='IceReadPad' xrefstyle='select: title'/>
3683 A maximum of 7 pad bytes can be specified.</para>
3685 <funcsynopsis id='IceReadPad'>
3687 <funcdef><function> IceReadPad</function></funcdef>
3688 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
3689 <paramdef>int<parameter> bytes</parameter></paramdef>
3693 <variablelist remap='IP'>
3695 <term><emphasis remap='I'>ice_conn</emphasis></term>
3697 <para>A valid ICE connection object.</para>
3701 <term><emphasis remap='I'>bytes</emphasis></term>
3703 <para>The number of pad bytes.</para>
3711 <chapter id='Error_Handling'>
3712 <title>Error Handling</title>
3715 <para>There are two default error handlers in ICElib:</para>
3720 One to handle typically fatal conditions (for example,
3721 a connection dying because a machine crashed)
3725 <para>One to handle ICE-specific protocol errors</para>
3730 These error handlers can be changed to user-supplied routines if you
3731 prefer your own error handling and can be changed as often as you like.
3736 To set the ICE error handler, use <xref linkend='IceSetErrorHandler' xrefstyle='select: title'/>
3739 <funcsynopsis id='IceSetErrorHandler'>
3741 <funcdef><function> IceSetErrorHandler</function></funcdef>
3742 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
3743 <paramdef>int<parameter> bytes</parameter></paramdef>
3747 <variablelist remap='IP'>
3749 <term><emphasis remap='I'>handler</emphasis></term>
3752 The ICE error handler. You should pass NULL to restore the default handler.
3759 <xref linkend='IceSetErrorHandler' xrefstyle='select: title'/> returns the previous error handler.
3763 The ICE error handler is invoked when an unexpected ICE protocol
3764 error (major opcode 0) is encountered. The action of the default
3765 handler is to print an explanatory message to
3766 <function>stderr</function>
3767 and if the severity is fatal, call
3768 <function>exit</function>
3769 with a nonzero value. If exiting
3770 is undesirable, the application should register its own error handler.
3774 Note that errors in other protocol
3775 domains should be handled by their respective libraries (these libraries
3776 should have their own error handlers).
3780 An ICE error handler has the type of <xref linkend='IceErrorHandler' xrefstyle='select: title'/>
3783 <funcsynopsis id='IceErrorHandler'>
3785 <funcdef>void<function> IceErrorHandler</function></funcdef>
3786 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
3787 <paramdef>Bool<parameter> swap</parameter></paramdef>
3788 <paramdef>int<parameter> offending_minor_opcode</parameter></paramdef>
3789 <paramdef>unsigned long<parameter> offending_sequence_num</parameter></paramdef>
3790 <paramdef>int<parameter> error_class</parameter></paramdef>
3791 <paramdef>int<parameter> severity</parameter></paramdef>
3792 <paramdef>IcePointer<parameter> values</parameter></paramdef>
3796 <variablelist remap='IP'>
3798 <term><emphasis remap='I'>handler</emphasis></term>
3800 <para>The ICE connection object.</para>
3804 <term><emphasis remap='I'>swap</emphasis></term>
3806 <para>A flag that indicates if the values need byte swapping.</para>
3810 <term><emphasis remap='I'>offending_minor_opcode</emphasis></term>
3812 <para>The ICE minor opcode of the offending message.</para>
3816 <term><emphasis remap='I'>offending_sequence_num</emphasis></term>
3818 <para>The sequence number of the offending message.</para>
3822 <term><emphasis remap='I'>error_class</emphasis></term>
3824 <para>The error class of the offending message.</para>
3828 <term><emphasis remap='I'>severity</emphasis></term>
3831 <function>IceCanContinue</function>
3832 <function>IceFatalToProtocol</function>
3834 <function>IceFatalToConnection</function>
3839 <term><emphasis remap='I'>values</emphasis></term>
3842 Any additional error values specific to the minor opcode and class.
3849 <para>The following error classes are defined at the ICE level:</para>
3851 <literallayout remap='Ds'>
3852 <function>IceBadMinor</function>
3853 <function>IceBadState</function>
3854 <function>IceBadLength</function>
3855 <function>IceBadValue</function>
3856 <function>IceBadMajor</function>
3857 <function>IceNoAuth</function>
3858 <function>IceNoVersion</function>
3859 <function>IceSetupFailed</function>
3860 <function>IceAuthRejected</function>
3861 <function>IceAuthFailed</function>
3862 <function>IceProtocolDuplicate</function>
3863 <function>IceMajorOpcodeDuplicate</function>
3864 <function>IceUnknownProtocol</function>
3868 For further information, see
3869 the <emphasis remap='I'>Inter-Client Exchange Protocol</emphasis> standard.
3874 To handle fatal I/O errors, use <xref linkend='IceSetIOErrorHandler' xrefstyle='select: title'/>
3878 <funcsynopsis id='IceSetIOErrorHandler'>
3880 <funcdef>IceIOErrorHandler<function> IceSetIOErrorHandler</function></funcdef>
3881 <paramdef>IceIOErrorHandler<parameter> handler</parameter></paramdef>
3885 <variablelist remap='IP'>
3887 <term><emphasis remap='I'>handler</emphasis></term>
3890 The I/O error handler. You should pass NULL to restore the default handler.
3897 <xref linkend='IceSetIOErrorHandler' xrefstyle='select: title'/> returns the previous
3902 An ICE I/O error handler has the type of
3903 <xref linkend='IceIOErrorHandler' xrefstyle='select: title'/>
3906 <funcsynopsis id='IceIOErrorHandler'>
3908 <funcdef>void<function> IceIOErrorHandler</function></funcdef>
3909 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
3913 <variablelist remap='IP'>
3915 <term><emphasis remap='I'>ice_conn</emphasis></term>
3916 <listitem><para>The ICE connection object.</para></listitem>
3921 <para> There are two ways of handling IO errors in ICElib:</para>
3926 In the first, the IO error handler does whatever is necessary
3927 to respond to the IO error and then returns, but it does not call
3928 <xref linkend='IceCloseConnection' xrefstyle='select: title'/>
3929 The ICE connection is given a "bad IO" status, and all future reads
3930 and writes to the connection are ignored. The next time
3931 <xref linkend='IceProcessMessages' xrefstyle='select: title'/>
3932 is called it will return a status of
3933 <function>IceProcessMessagesIOError</function>
3934 At that time, the application should call
3935 <xref linkend='IceCloseConnection' xrefstyle='select: title'/>
3940 In the second, the IO error handler does call
3941 <xref linkend='IceCloseConnection' xrefstyle='select: title'/>
3942 and then uses the <function>longjmp</function>
3943 call to get back to the application's main event loop. The
3944 <function>setjmp</function> and
3945 <function>longjmp</function>
3946 calls may not work properly on all platforms,
3947 and special care must be taken to avoid memory leaks.
3948 Therefore, this second model is less desirable.
3954 Before the application I/O error handler is invoked, protocol libraries
3955 that were interested in being notified of I/O errors will have their
3956 <xref linkend='IceIOErrorProc' xrefstyle='select: title'/>
3957 handlers invoked. This handler is set up in the protocol registration
3958 functions (see <xref linkend='IceRegisterForProtocolSetup' xrefstyle='select: title'/> and
3959 <xref linkend='IceRegisterForProtocolReply' xrefstyle='select: title'/>
3960 and could be used to clean up state specific to the protocol.
3964 <funcsynopsis id='IceIOErrorProc'>
3966 <funcdef>void<function> IceIOErrorProc</function></funcdef>
3967 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
3971 <variablelist remap='IP'>
3973 <term><emphasis remap='I'>ice_conn</emphasis></term>
3974 <listitem><para>The ICE connection object.</para></listitem>
3979 Note that every <xref linkend='IceIOErrorProc' xrefstyle='select: title'/>
3980 callback must return. This is required
3981 because each active protocol must be notified of the broken connection,
3982 and the application IO error handler must be invoked afterwards.
3986 <chapter id='Multi_Threading_Support'>
3987 <title>Multi-Threading Support</title>
3990 <para>To declare that multiple threads in an application will be using the ICE
3992 <function>IceInitThreads</function></para>
3994 <literallayout remap='FD'>
3995 Status IceInitThreads()
4000 <function>IceInitThreads</function>
4001 function must be the first ICElib function a
4002 multi-threaded program calls. It must complete before any other ICElib
4004 <function>IceInitThreads</function>
4005 returns a nonzero status if and only if it was able
4006 to initialize the threads package successfully.
4008 <function>IceInitThreads</function>
4009 more than once, although the threads package will only be initialized once.</para>
4011 <para>Protocol libraries layered on top of ICElib will have to lock critical
4012 sections of code that access an ICE connection (for example, when
4013 generating messages). Two calls, which are generally implemented as
4014 macros, are provided:</para>
4016 <funcsynopsis id='IceLockConn'>
4018 <funcdef>void<function> IceLockConn</function></funcdef>
4019 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
4023 <funcsynopsis id='IceUnlockConn'>
4025 <funcdef>void<function> IceUnlockConn</function></funcdef>
4026 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
4030 <variablelist remap='IP'>
4032 <term><emphasis remap='I'>ice_conn</emphasis></term>
4033 <listitem><para>The ICE connection object.</para></listitem>
4037 <para>To keep an ICE connection locked across several ICElib calls, applications use
4038 <xref linkend='IceAppLockConn' xrefstyle='select: title'/>
4040 <xref linkend='IceAppUnlockConn' xrefstyle='select: title'/></para>
4042 <funcsynopsis id='IceAppLockConn'>
4044 <funcdef>void<function> IceAppLockConn</function></funcdef>
4045 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
4049 <variablelist remap='IP'>
4051 <term><emphasis remap='I'>ice_conn</emphasis></term>
4052 <listitem><para>The ICE connection object.</para></listitem>
4058 <xref linkend='IceAppLockConn' xrefstyle='select: title'/>
4059 function completely locks out other threads using the connection
4061 <xref linkend='IceAppUnlockConn' xrefstyle='select: title'/>
4062 is called. Other threads attempting to use ICElib
4063 calls on the connection will block.
4064 If the program has not previously called
4065 <function>IceInitThreads</function>
4066 <xref linkend='IceAppLockConn' xrefstyle='select: title'/>
4067 has no effect.</para>
4069 <funcsynopsis id='IceAppUnlockConn'>
4071 <funcdef>void<function> IceAppUnlockConn</function></funcdef>
4072 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
4076 <variablelist remap='IP'>
4078 <term><emphasis remap='I'>ice_conn</emphasis></term>
4079 <listitem><para>The ICE connection object.</para></listitem>
4084 <xref linkend='IceAppUnlockConn' xrefstyle='select: title'/>
4085 function allows other threads to complete ICElib
4086 calls on the connection that were blocked by a previous call to
4087 <xref linkend='IceAppLockConn' xrefstyle='select: title'/>
4088 from this thread. If the program has not previously called
4089 <function>IceInitThreads</function>
4090 <xref linkend='IceAppUnlockConn' xrefstyle='select: title'/>
4091 has no effect.</para>
4094 <chapter id='Miscellaneous_Functions'>
4095 <title>Miscellaneous Functions</title>
4100 <para>To allocate scratch space (for example, when generating
4101 messages with variable data), use
4102 <function>IceAllocScratch</function>
4103 Each ICE connection has one scratch space associated with it.
4104 The scratch space starts off as empty and grows as needed.
4105 The contents of the scratch space is not guaranteed to be preserved
4106 after any ICElib function is called.</para>
4109 <funcsynopsis id='IceAllocScratch'>
4111 <funcdef>char<function> *IceAllocScratch</function></funcdef>
4112 <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
4113 <paramdef>unsigned long<parameter> size</parameter></paramdef>
4117 <variablelist remap='IP'>
4119 <term><emphasis remap='I'>ice_conn</emphasis></term>
4120 <listitem><para>The ICE connection object.</para></listitem>
4123 <term><emphasis remap='I'>size</emphasis></term>
4124 <listitem><para>The number of bytes required.</para></listitem>
4128 <para>Note that the memory returned by
4129 <function>IceAllocScratch</function>
4130 should not be freed by the caller.
4131 The ICE library will free the memory when the ICE connection is closed.</para>
4134 <chapter id='Acknowledgements'>
4135 <title>Acknowledgements</title>
4139 Thanks to Bob Scheifler for his thoughtful input on the design
4140 of the ICE library. Thanks also to Jordan Brown, Larry Cable, Donna Converse,
4141 Clive Feather, Stephen Gildea, Vania Joloboff, Kaleb Keithley,
4142 Stuart Marks, Hiro Miyamoto, Ralph Swick, Jim VanGilder, and Mike Wexler.
4146 <appendix id="authentication_utility_functions">
4147 <title>Authentication Utility Functions</title>
4151 As discussed in this document, the means by which authentication data
4152 is obtained by the ICE library (for
4153 <function>ConnectionSetup</function>
4155 <function>ProtocolSetup</function>
4156 messages) is implementation-dependent.†
4157 <footnote remap='FS'>
4158 <para>The X Consortium's ICElib implementation assumes the presence of an
4164 This appendix describes some utility functions that manipulate an
4165 ICE authority file. The authority file can be used to pass authentication
4166 data between clients.
4169 <para>The basic operations on the .ICEauthority file are:</para>
4173 <para>Get file name</para>
4182 <para>Read entry</para>
4185 <para>Write entry</para>
4188 <para>Search for entry</para>
4193 These are fairly low-level operations, and it is expected that a program,
4194 like "iceauth", would exist to add, remove, and display entries in the file.
4198 In order to use these utility functions, the
4199 <<symbol role='Pn'>X11/ICE/ICEutil.h</symbol>>
4200 header file must be included.
4204 An entry in the .ICEauthority file is defined by the following data structure:
4208 <literallayout class="monospaced">
4210 char *protocol_name;
4211 unsigned short protocol_data_length;
4212 char *protocol_data;
4215 unsigned short auth_data_length;
4222 The protocol_name member is either "ICE" for connection setup authentication
4223 or the subprotocol name, such as "XSMP". For each entry, protocol specific
4224 data can be specified in the protocol_data member. This can be used
4225 to search for old entries that need to be removed from the file.
4229 The network_id member is the network ID of the client accepting
4230 authentication (for example, the network ID of a session manager).
4231 A network ID has the following form:
4234 <informaltable frame='none'>
4235 <?dbfo keep-together="always" ?>
4236 <tgroup cols='2' align='left' colsep='0' rowsep='0'>
4237 <colspec colname='c1' colwidth='1.0*'/>
4238 <colspec colname='c2' colwidth='2.0*'/>
4241 <entry>tcp/<hostname>:<portnumber></entry>
4245 <entry>decnet/<hostname>::<objname></entry>
4249 <entry>local/<hostname>:<path></entry>
4257 The auth_name member is the name of the authentication method.
4258 The auth_data member is the actual authentication data,
4259 and the auth_data_length member is the number of bytes in the data.
4263 To obtain the default authorization file name, use
4264 <function>IceAuthFileName</function>
4267 <literallayout remap='FD'>
4268 char *IceAuthFileName()
4272 If the ICEAUTHORITY environment variable if set, this value is returned.
4273 Otherwise, the default authorization file name is $HOME/.ICEauthority.
4274 This name is statically allocated and should not be freed.
4278 To synchronously update the authorization file, the file must
4279 be locked with a call to
4280 <xref linkend='IceLockAuthFile' xrefstyle='select: title'/>
4281 This function takes advantage of the fact that the
4282 <function>link</function>
4283 system call will fail if the name of the new link already exists.
4286 <funcsynopsis id='IceLockAuthFile'>
4288 <funcdef>int<function> IceLockAuthFile</function></funcdef>
4289 <paramdef>char<parameter> *file_name</parameter></paramdef>
4290 <paramdef>int<parameter> retries</parameter></paramdef>
4291 <paramdef>int<parameter> timeout</parameter></paramdef>
4292 <paramdef>long<parameter> dead</parameter></paramdef>
4296 <variablelist remap='IP'>
4298 <term><emphasis remap='I'>file_name</emphasis></term>
4299 <listitem><para>The authorization file to lock.</para></listitem>
4302 <term><emphasis remap='I'>retries</emphasis></term>
4304 <para>The number of retries.</para>
4308 <term><emphasis remap='I'>timeout</emphasis></term>
4310 <para>The number of seconds before each retry.</para>
4314 <term><emphasis remap='I'>dead</emphasis></term>
4317 If a lock already exists that is the specified dead seconds old,
4319 A value of zero is used to unconditionally break an old lock.
4325 <para>One of three values is returned:</para>
4330 <function>IceAuthLockSuccess</function> - the lock succeeded.
4335 <function>IceAuthLockError</function> - a system error occurred, and
4336 <function>errno</function> may prove useful.
4341 <function>IceAuthLockTimeout</function> - the specified number of
4348 To unlock an authorization file, use <xref linkend='IceUnlockAuthFile' xrefstyle='select: title'/>
4351 <funcsynopsis id='IceUnlockAuthFile'>
4353 <funcdef>int<function> IceUnlockAuthFile</function></funcdef>
4354 <paramdef>char<parameter> *file_name</parameter></paramdef>
4358 <variablelist remap='IP'>
4360 <term><emphasis remap='I'>file_name</emphasis></term>
4361 <listitem><para>The authorization file to unlock.</para></listitem>
4366 To read the next entry in an authorization file, use
4367 <function>IceReadAuthFileEntry</function>
4370 <funcsynopsis id='IceReadAuthFileEntry'>
4372 <funcdef>IceAuthFileEntry<function> *IceReadAuthFileEntry</function></funcdef>
4373 <paramdef>FILE<parameter> *auth_file</parameter></paramdef>
4377 <variablelist remap='IP'>
4379 <term><emphasis remap='I'>auth_file</emphasis></term>
4380 <listitem><para>The authorization file.</para></listitem>
4385 Note that it is the responsibility of the application to open the file
4386 for reading before calling this function. If an error is encountered,
4387 or there are no more entries to read, NULL is returned.
4391 Entries should be free with a call to
4392 <xref linkend='IceFreeAuthFileEntry' xrefstyle='select: title'/>
4396 To write an entry in an authorization file, use
4397 <xref linkend='IceWriteAuthFileEntry' xrefstyle='select: title'/>
4400 <funcsynopsis id='IceWriteAuthFileEntry'>
4402 <funcdef>Status<function> IceWriteAuthFileEntry</function></funcdef>
4403 <paramdef>FILE<parameter> *auth_file</parameter></paramdef>
4404 <paramdef>IceAuthFileEntry<parameter> *entry</parameter></paramdef>
4408 <variablelist remap='IP'>
4410 <term><emphasis remap='I'>auth_file</emphasis></term>
4411 <listitem><para>The authorization file.</para></listitem>
4414 <term><emphasis remap='I'>entry</emphasis></term>
4415 <listitem><para>The entry to write.</para></listitem>
4420 Note that it is the responsibility of the application to open the file
4421 for writing before calling this function. The function returns a nonzero
4422 status if the operation was successful.
4427 To search the default authorization file for an entry that matches a given
4428 protocol_name/network_id/auth_name tuple, use
4429 <function>IceGetAuthFileEntry</function>
4432 <funcsynopsis id='IceGetAuthFileEntry'>
4434 <funcdef>IceAuthFileEntry<function> *IceGetAuthFileEntry</function></funcdef>
4435 <paramdef>const char *<parameter>protocol_name</parameter></paramdef>
4436 <paramdef>const char *<parameter>network_id</parameter></paramdef>
4437 <paramdef>const char *<parameter>auth_name</parameter></paramdef>
4441 <variablelist remap='IP'>
4443 <term><emphasis remap='I'>auth_file</emphasis></term>
4444 <listitem><para>The name of the protocol to search on.</para></listitem>
4447 <term><emphasis remap='I'>network_id</emphasis></term>
4449 <para>The network ID to search on.</para>
4453 <term><emphasis remap='I'>auth_name</emphasis></term>
4455 <para>The authentication method to search on.</para>
4461 If <function>IceGetAuthFileEntry</function>
4462 fails to find such an entry, NULL is returned.
4467 To free an entry returned by
4468 <function>IceReadAuthFileEntry</function> or
4469 <function>IceGetAuthFileEntry</function> use
4470 <xref linkend='IceFreeAuthFileEntry' xrefstyle='select: title'/>
4473 <funcsynopsis id='IceFreeAuthFileEntry'>
4475 <funcdef>void<function> IceFreeAuthFileEntry</function></funcdef>
4476 <paramdef>IceAuthFileEntry<parameter> *entry</parameter></paramdef>
4480 <variablelist remap='IP'>
4482 <term><emphasis remap='I'>entry</emphasis></term>
4483 <listitem><para>The entry to free.</para></listitem>
4489 <appendix id="mit_magic_cookie_1_authentication">
4490 <title>MIT-MAGIC-COOKIE-1 Authentication</title>
4493 <para>The X Consortium's ICElib implementation supports a simple
4494 MIT-MAGIC-COOKIE-1 authentication scheme using the authority file utilities
4495 described in Appendix A.</para>
4497 <para>In this model, an application, such as a session manager, obtains a
4498 magic cookie by calling
4499 <function>IceGenerateMagicCookie</function>
4500 and then stores it in the user's local .ICEauthority file
4501 so that local clients can connect. In order to allow remote clients to
4502 connect, some remote execution mechanism should be used to store the
4503 magic cookie in the user's .ICEauthority file on a remote machine.</para>
4505 <para>In addition to storing the magic cookie in the .ICEauthority file, the
4506 application needs to call the
4507 <xref linkend='IceSetPaAuthData' xrefstyle='select: title'/>
4508 function in order to store the magic cookie in memory. When it comes time
4509 for the MIT-MAGIC-COOKIE-1 authentication procedure to accept or reject the
4510 connection, it will compare the magic cookie presented by the requestor to
4511 the magic cookie in memory.</para>
4513 <funcsynopsis id='IceGenerateMagicCookie'>
4515 <funcdef>char<function> *IceGenerateMagicCookie</function></funcdef>
4516 <paramdef>int<parameter> length</parameter></paramdef>
4520 <variablelist remap='IP'>
4522 <term><emphasis remap='I'>length</emphasis></term>
4523 <listitem><para>The desired length of the magic cookie.</para></listitem>
4528 <para>The magic cookie returned will be null-terminated. If memory can not be
4529 allocated for the magic cookie, the function will return NULL.
4530 Otherwise, the magic cookie should be freed with a call to
4531 <function>free</function></para>
4534 <para>To store the authentication data in memory, use
4535 <xref linkend='IceSetPaAuthData' xrefstyle='select: title'/>
4536 Currently, this function is only used for MIT-MAGIC-COOKIE-1
4537 authentication, but it may be used for additional authentication
4538 methods in the future.</para>
4540 <funcsynopsis id='IceSetPaAuthData'>
4542 <funcdef>void<function> IceSetPaAuthData</function></funcdef>
4543 <paramdef>int<parameter> num_entries</parameter></paramdef>
4544 <paramdef>IceAuthDataEntry<parameter> *entries</parameter></paramdef>
4548 <variablelist remap='IP'>
4550 <term><emphasis remap='I'>num_entries</emphasis></term>
4551 <listitem><para>The number of authentication data entries.</para></listitem>
4554 <term><emphasis remap='I'>entries</emphasis></term>
4555 <listitem><para>The list of authentication data entries.</para></listitem>
4559 <para>Each entry has associated with it a protocol name
4560 (for example, "ICE" for ICE connection setup authentication,
4561 "XSMP" for session management authentication), a network ID for the
4562 "accepting" client, an authentication name (for example, MIT-MAGIC-COOKIE-1),
4563 and authentication data. The ICE library
4564 will merge these entries with previously set entries, based on the
4565 (protocol_name, network_id, auth_name) tuple.</para>
4569 <literallayout class="monospaced">
4571 char *protocol_name;
4574 unsigned short auth_data_length;