| 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 |
opcodeRet = i; |
| 72 |
} |
| 73 |
else if (_IceLastMajorOpcode == 255 || |
| 74 |
versionCount < 1 || |
| 75 |
strlen (protocolName) == 0) |
| 76 |
{ |
| 77 |
return (-1); |
| 78 |
} |
| 79 |
else |
| 80 |
{ |
| 81 |
_IceProtocols[_IceLastMajorOpcode].protocol_name = |
| 82 |
strdup(protocolName); |
| 83 |
|
| 84 |
p = _IceProtocols[_IceLastMajorOpcode].orig_client = |
| 85 |
malloc (sizeof (_IcePoProtocol)); |
| 86 |
|
| 87 |
_IceProtocols[_IceLastMajorOpcode].accept_client = NULL; |
| 88 |
|
| 89 |
opcodeRet = ++_IceLastMajorOpcode; |
| 90 |
} |
| 91 |
|
| 92 |
p->vendor = strdup(vendor); |
| 93 |
p->release = strdup(release); |
| 94 |
|
| 95 |
p->version_count = versionCount; |
| 96 |
|
| 97 |
p->version_recs = malloc (versionCount * sizeof (IcePoVersionRec)); |
| 98 |
memcpy (p->version_recs, versionRecs, |
| 99 |
versionCount * sizeof (IcePoVersionRec)); |
| 100 |
|
| 101 |
if ((p->auth_count = authCount) > 0) |
| 102 |
{ |
| 103 |
p->auth_names = malloc (authCount * sizeof (char *)); |
| 104 |
|
| 105 |
p->auth_procs = malloc (authCount * sizeof (IcePoAuthProc)); |
| 106 |
|
| 107 |
for (i = 0; i < authCount; i++) |
| 108 |
{ |
| 109 |
p->auth_names[i] = strdup(authNames[i]); |
| 110 |
p->auth_procs[i] = authProcs[i]; |
| 111 |
} |
| 112 |
} |
| 113 |
else |
| 114 |
{ |
| 115 |
p->auth_names = NULL; |
| 116 |
p->auth_procs = NULL; |
| 117 |
} |
| 118 |
|
| 119 |
p->io_error_proc = IOErrorProc; |
| 120 |
|
| 121 |
return (opcodeRet); |
| 122 |
} |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
int |
| 127 |
IceRegisterForProtocolReply ( |
| 128 |
const char *protocolName, |
| 129 |
const char *vendor, |
| 130 |
const char *release, |
| 131 |
int versionCount, |
| 132 |
IcePaVersionRec *versionRecs, |
| 133 |
int authCount, |
| 134 |
const char **authNames, |
| 135 |
IcePaAuthProc *authProcs, |
| 136 |
IceHostBasedAuthProc hostBasedAuthProc, |
| 137 |
IceProtocolSetupProc protocolSetupProc, |
| 138 |
IceProtocolActivateProc protocolActivateProc, |
| 139 |
IceIOErrorProc IOErrorProc |
| 140 |
) |
| 141 |
{ |
| 142 |
_IcePaProtocol *p; |
| 143 |
int opcodeRet, i; |
| 144 |
|
| 145 |
for (i = 1; i <= _IceLastMajorOpcode; i++) |
| 146 |
if (strcmp (protocolName, _IceProtocols[i - 1].protocol_name) == 0) |
| 147 |
{ |
| 148 |
if (_IceProtocols[i - 1].accept_client != NULL) |
| 149 |
{ |
| 150 |
/* |
| 151 |
* We've already registered this protocol. |
| 152 |
*/ |
| 153 |
|
| 154 |
return (i); |
| 155 |
} |
| 156 |
else |
| 157 |
{ |
| 158 |
break; |
| 159 |
} |
| 160 |
} |
| 161 |
|
| 162 |
|
| 163 |
if (i <= _IceLastMajorOpcode) |
| 164 |
{ |
| 165 |
p = _IceProtocols[i - 1].accept_client = |
| 166 |
malloc (sizeof (_IcePaProtocol)); |
| 167 |
opcodeRet = i; |
| 168 |
} |
| 169 |
else if (_IceLastMajorOpcode == 255 || |
| 170 |
versionCount < 1 || |
| 171 |
strlen (protocolName) == 0) |
| 172 |
{ |
| 173 |
return (-1); |
| 174 |
} |
| 175 |
else |
| 176 |
{ |
| 177 |
_IceProtocols[_IceLastMajorOpcode].protocol_name = |
| 178 |
strdup(protocolName); |
| 179 |
|
| 180 |
_IceProtocols[_IceLastMajorOpcode].orig_client = NULL; |
| 181 |
|
| 182 |
p = _IceProtocols[_IceLastMajorOpcode].accept_client = |
| 183 |
malloc (sizeof (_IcePaProtocol)); |
| 184 |
|
| 185 |
opcodeRet = ++_IceLastMajorOpcode; |
| 186 |
} |
| 187 |
|
| 188 |
p->vendor = strdup(vendor); |
| 189 |
p->release = strdup(release); |
| 190 |
|
| 191 |
p->version_count = versionCount; |
| 192 |
|
| 193 |
p->version_recs = malloc (versionCount * sizeof (IcePaVersionRec)); |
| 194 |
memcpy (p->version_recs, versionRecs, |
| 195 |
versionCount * sizeof (IcePaVersionRec)); |
| 196 |
|
| 197 |
p->protocol_setup_proc = protocolSetupProc; |
| 198 |
p->protocol_activate_proc = protocolActivateProc; |
| 199 |
|
| 200 |
if ((p->auth_count = authCount) > 0) |
| 201 |
{ |
| 202 |
p->auth_names = malloc (authCount * sizeof (char *)); |
| 203 |
|
| 204 |
p->auth_procs = malloc (authCount * sizeof (IcePaAuthProc)); |
| 205 |
|
| 206 |
for (i = 0; i < authCount; i++) |
| 207 |
{ |
| 208 |
p->auth_names[i] = strdup(authNames[i]); |
| 209 |
p->auth_procs[i] = authProcs[i]; |
| 210 |
} |
| 211 |
} |
| 212 |
else |
| 213 |
{ |
| 214 |
p->auth_names = NULL; |
| 215 |
p->auth_procs = NULL; |
| 216 |
} |
| 217 |
|
| 218 |
p->host_based_auth_proc = hostBasedAuthProc; |
| 219 |
|
| 220 |
p->io_error_proc = IOErrorProc; |
| 221 |
|
| 222 |
return (opcodeRet); |
| 223 |
} |
| 224 |
|