1 /******************************************************************************
4 Copyright 1993, 1998 The Open Group
6 Permission to use, copy, modify, distribute, and sell this software and its
7 documentation for any purpose is hereby granted without fee, provided that
8 the above copyright notice appear in all copies and that both that
9 copyright notice and this permission notice appear in supporting
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 Except as contained in this notice, the name of The Open Group shall not be
23 used in advertising or otherwise to promote the sale, use or other dealings
24 in this Software without prior written authorization from The Open Group.
26 Author: Ralph Mor, X Consortium
27 ******************************************************************************/
32 #include <X11/ICE/ICElib.h>
33 #include "ICElibint.h"
34 #include <X11/Xtrans/Xtrans.h>
39 IceListenForConnections (
41 IceListenObj **listenObjsRet,
46 struct _IceListenObj *listenObjs;
48 int transCount, partial, i, j;
50 XtransConnInfo *transConns = NULL;
53 if ((_IceTransMakeAllCOTSServerListeners (NULL, &partial,
54 &transCount, &transConns) < 0) || (transCount < 1))
56 *listenObjsRet = NULL;
59 strncpy (errorStringRet,
60 "Cannot establish any listening sockets", errorLength);
65 if ((listenObjs = (struct _IceListenObj *) malloc (
66 transCount * sizeof (struct _IceListenObj))) == NULL)
68 for (i = 0; i < transCount; i++)
69 _IceTransClose (transConns[i]);
70 free ((char *) transConns);
76 for (i = 0; i < transCount; i++)
78 _IceTransSetOption(transConns[i], TRANS_CLOSEONEXEC, 1);
80 networkId = _IceTransGetMyNetworkId (transConns[i]);
84 listenObjs[*countRet].trans_conn = transConns[i];
85 listenObjs[*countRet].network_id = networkId;
93 *listenObjsRet = NULL;
95 strncpy (errorStringRet,
96 "Cannot establish any listening sockets", errorLength);
102 *listenObjsRet = (IceListenObj *) malloc (
103 *countRet * sizeof (IceListenObj));
105 if (*listenObjsRet == NULL)
107 strncpy (errorStringRet, "Malloc failed", errorLength);
113 for (i = 0; i < *countRet; i++)
115 (*listenObjsRet)[i] = (IceListenObj) malloc (
116 sizeof (struct _IceListenObj));
118 if ((*listenObjsRet)[i] == NULL)
120 strncpy (errorStringRet, "Malloc failed", errorLength);
122 for (j = 0; j < i; j++)
123 free ((char *) (*listenObjsRet)[j]);
125 free ((char *) *listenObjsRet);
126 *listenObjsRet = NULL;
133 *((*listenObjsRet)[i]) = listenObjs[i];
141 if (errorStringRet && errorLength > 0)
142 *errorStringRet = '\0';
144 for (i = 0; i < *countRet; i++)
146 (*listenObjsRet)[i]->host_based_auth_proc = NULL;
151 for (i = 0; i < transCount; i++)
152 _IceTransClose (transConns[i]);
155 free ((char *) listenObjs);
156 free ((char *) transConns);
164 IceGetListenConnectionNumber (
165 IceListenObj listenObj
168 return (_IceTransGetConnectionNumber (listenObj->trans_conn));
174 IceGetListenConnectionString (
175 IceListenObj listenObj
178 return strdup(listenObj->network_id);
184 IceComposeNetworkIdList (
186 IceListenObj *listenObjs
193 if (count < 1 || listenObjs == NULL)
196 for (i = 0; i < count; i++)
197 len += (strlen (listenObjs[i]->network_id) + 1);
199 list = (char *) malloc (len);
209 for (i = 0; i < count; i++)
211 if (_IceTransIsLocal (listenObjs[i]->trans_conn))
213 strcat (list, listenObjs[i]->network_id);
215 if (doneCount < count)
220 if (doneCount < count)
222 for (i = 0; i < count; i++)
224 if (!_IceTransIsLocal (listenObjs[i]->trans_conn))
226 strcat (list, listenObjs[i]->network_id);
228 if (doneCount < count)
243 IceListenObj *listenObjs
248 for (i = 0; i < count; i++)
250 free (listenObjs[i]->network_id);
251 _IceTransClose (listenObjs[i]->trans_conn);
252 free ((char *) listenObjs[i]);
255 free ((char *) listenObjs);
261 * Allow host based authentication for the ICE Connection Setup.
262 * Do not confuse with the host based authentication callbacks that
263 * can be set up in IceRegisterForProtocolReply.
267 IceSetHostBasedAuthProc (
268 IceListenObj listenObj,
269 IceHostBasedAuthProc hostBasedAuthProc
272 listenObj->host_based_auth_proc = hostBasedAuthProc;