Home | History | Annotate | Line # | Download | only in src
      1 /******************************************************************************
      2 
      3 
      4 Copyright 1993, 1998  The Open Group
      5 
      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
     10 documentation.
     11 
     12 The above copyright notice and this permission notice shall be included in
     13 all copies or substantial portions of the Software.
     14 
     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.
     21 
     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.
     25 
     26 Author: Ralph Mor, X Consortium
     27 ******************************************************************************/
     28 
     29 #ifdef HAVE_CONFIG_H
     30 #include <config.h>
     31 #endif
     32 #include <X11/ICE/ICElib.h>
     33 #include "ICElibint.h"
     34 
     35 int
     36 IceRegisterForProtocolSetup (
     37 	const char		*protocolName,
     38 	const char		*vendor,
     39 	const char		*release,
     40 	int			versionCount,
     41 	IcePoVersionRec		*versionRecs,
     42 	int			authCount,
     43 	const char	        **authNames,
     44 	IcePoAuthProc		*authProcs,
     45 	IceIOErrorProc		IOErrorProc
     46 )
     47 {
     48     _IcePoProtocol 	*p;
     49     int			opcodeRet, i;
     50 
     51     for (i = 1; i <= _IceLastMajorOpcode; i++)
     52 	if (strcmp (protocolName, _IceProtocols[i - 1].protocol_name) == 0)
     53 	{
     54 	    if (_IceProtocols[i - 1].orig_client != NULL)
     55 	    {
     56 		/*
     57 		 * We've already registered this protocol.
     58 		 */
     59 
     60 		return (i);
     61 	    }
     62 	    else
     63 	    {
     64 		break;
     65 	    }
     66 	}
     67 
     68     if (i <= _IceLastMajorOpcode)
     69     {
     70 	p = _IceProtocols[i - 1].orig_client = malloc (sizeof(_IcePoProtocol));
     71 	if (p == NULL)
     72 	    return (-1);
     73 	opcodeRet = i;
     74     }
     75     else if (_IceLastMajorOpcode == 255 ||
     76 	versionCount < 1 ||
     77 	strlen (protocolName) == 0)
     78     {
     79 	return (-1);
     80     }
     81     else
     82     {
     83 	_IceProtocols[_IceLastMajorOpcode].protocol_name =
     84 	    strdup(protocolName);
     85 	if (_IceProtocols[_IceLastMajorOpcode].protocol_name == NULL)
     86 	    return (-1);
     87 
     88 	p = _IceProtocols[_IceLastMajorOpcode].orig_client =
     89 	    malloc (sizeof (_IcePoProtocol));
     90 	if (p == NULL)
     91 	{
     92 	    free(_IceProtocols[_IceLastMajorOpcode].protocol_name);
     93 	    return (-1);
     94 	}
     95 
     96 	_IceProtocols[_IceLastMajorOpcode].accept_client = NULL;
     97 
     98 	opcodeRet = ++_IceLastMajorOpcode;
     99     }
    100 
    101     p->vendor = strdup(vendor);
    102     p->release = strdup(release);
    103 
    104     p->version_count = versionCount;
    105 
    106     p->version_recs = malloc (versionCount * sizeof (IcePoVersionRec));
    107     memcpy (p->version_recs, versionRecs,
    108 	versionCount * sizeof (IcePoVersionRec));
    109 
    110     if ((p->auth_count = authCount) > 0)
    111     {
    112 	p->auth_names = malloc (authCount * sizeof (char *));
    113 
    114 	p->auth_procs = malloc (authCount * sizeof (IcePoAuthProc));
    115 
    116 	for (i = 0; i < authCount; i++)
    117 	{
    118 	    p->auth_names[i] = strdup(authNames[i]);
    119 	    p->auth_procs[i] = authProcs[i];
    120 	}
    121     }
    122     else
    123     {
    124 	p->auth_names = NULL;
    125 	p->auth_procs = NULL;
    126     }
    127 
    128     p->io_error_proc = IOErrorProc;
    129 
    130     return (opcodeRet);
    131 }
    132 
    133 
    134 
    135 int
    136 IceRegisterForProtocolReply (
    137 	const char			*protocolName,
    138 	const char			*vendor,
    139 	const char			*release,
    140 	int				versionCount,
    141 	IcePaVersionRec			*versionRecs,
    142 	int				authCount,
    143 	const char			**authNames,
    144 	IcePaAuthProc			*authProcs,
    145 	IceHostBasedAuthProc		hostBasedAuthProc,
    146 	IceProtocolSetupProc		protocolSetupProc,
    147 	IceProtocolActivateProc		protocolActivateProc,
    148 	IceIOErrorProc			IOErrorProc
    149 )
    150 {
    151     _IcePaProtocol 	*p;
    152     int			opcodeRet, i;
    153 
    154     for (i = 1; i <= _IceLastMajorOpcode; i++)
    155 	if (strcmp (protocolName, _IceProtocols[i - 1].protocol_name) == 0)
    156 	{
    157 	    if (_IceProtocols[i - 1].accept_client != NULL)
    158 	    {
    159 		/*
    160 		 * We've already registered this protocol.
    161 		 */
    162 
    163 		return (i);
    164 	    }
    165 	    else
    166 	    {
    167 		break;
    168 	    }
    169 	}
    170 
    171 
    172     if (i <= _IceLastMajorOpcode)
    173     {
    174 	p = _IceProtocols[i - 1].accept_client =
    175 	    malloc (sizeof (_IcePaProtocol));
    176 	opcodeRet = i;
    177     }
    178     else if (_IceLastMajorOpcode == 255 ||
    179 	versionCount < 1 ||
    180 	strlen (protocolName) == 0)
    181     {
    182 	return (-1);
    183     }
    184     else
    185     {
    186 	_IceProtocols[_IceLastMajorOpcode].protocol_name =
    187 	    strdup(protocolName);
    188 
    189 	_IceProtocols[_IceLastMajorOpcode].orig_client = NULL;
    190 
    191 	p = _IceProtocols[_IceLastMajorOpcode].accept_client =
    192 	    malloc (sizeof (_IcePaProtocol));
    193 
    194 	opcodeRet = ++_IceLastMajorOpcode;
    195     }
    196 
    197     p->vendor = strdup(vendor);
    198     p->release = strdup(release);
    199 
    200     p->version_count = versionCount;
    201 
    202     p->version_recs = malloc (versionCount * sizeof (IcePaVersionRec));
    203     memcpy (p->version_recs, versionRecs,
    204 	versionCount * sizeof (IcePaVersionRec));
    205 
    206     p->protocol_setup_proc = protocolSetupProc;
    207     p->protocol_activate_proc = protocolActivateProc;
    208 
    209     if ((p->auth_count = authCount) > 0)
    210     {
    211 	p->auth_names = malloc (authCount * sizeof (char *));
    212 
    213 	p->auth_procs = malloc (authCount * sizeof (IcePaAuthProc));
    214 
    215 	for (i = 0; i < authCount; i++)
    216 	{
    217 	    p->auth_names[i] = strdup(authNames[i]);
    218 	    p->auth_procs[i] = authProcs[i];
    219 	}
    220     }
    221     else
    222     {
    223 	p->auth_names = NULL;
    224 	p->auth_procs = NULL;
    225     }
    226 
    227     p->host_based_auth_proc = hostBasedAuthProc;
    228 
    229     p->io_error_proc = IOErrorProc;
    230 
    231     return (opcodeRet);
    232 }
    233 
    234