register.c revision 9ef0b394
1/****************************************************************************** 2 3 4Copyright 1993, 1998 The Open Group 5 6Permission to use, copy, modify, distribute, and sell this software and its 7documentation for any purpose is hereby granted without fee, provided that 8the above copyright notice appear in all copies and that both that 9copyright notice and this permission notice appear in supporting 10documentation. 11 12The above copyright notice and this permission notice shall be included in 13all copies or substantial portions of the Software. 14 15THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 19AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 22Except as contained in this notice, the name of The Open Group shall not be 23used in advertising or otherwise to promote the sale, use or other dealings 24in this Software without prior written authorization from The Open Group. 25 26Author: 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 35int 36IceRegisterForProtocolSetup ( 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 = 71 (_IcePoProtocol *) malloc (sizeof (_IcePoProtocol)); 72 opcodeRet = i; 73 } 74 else if (_IceLastMajorOpcode == 255 || 75 versionCount < 1 || 76 strlen (protocolName) == 0) 77 { 78 return (-1); 79 } 80 else 81 { 82 char *name; 83 84 _IceProtocols[_IceLastMajorOpcode].protocol_name = name = 85 strdup(protocolName); 86 87 p = _IceProtocols[_IceLastMajorOpcode].orig_client = 88 (_IcePoProtocol *) malloc (sizeof (_IcePoProtocol)); 89 90 _IceProtocols[_IceLastMajorOpcode].accept_client = NULL; 91 92 opcodeRet = ++_IceLastMajorOpcode; 93 } 94 95 p->vendor = strdup(vendor); 96 p->release = strdup(release); 97 98 p->version_count = versionCount; 99 100 p->version_recs = (IcePoVersionRec *) malloc ( 101 versionCount * sizeof (IcePoVersionRec)); 102 memcpy (p->version_recs, versionRecs, 103 versionCount * sizeof (IcePoVersionRec)); 104 105 if ((p->auth_count = authCount) > 0) 106 { 107 p->auth_names = (char **) malloc ( 108 authCount * sizeof (char *)); 109 110 p->auth_procs = (IcePoAuthProc *) malloc ( 111 authCount * sizeof (IcePoAuthProc)); 112 113 for (i = 0; i < authCount; i++) 114 { 115 p->auth_names[i] = strdup(authNames[i]); 116 p->auth_procs[i] = authProcs[i]; 117 } 118 } 119 else 120 { 121 p->auth_names = NULL; 122 p->auth_procs = NULL; 123 } 124 125 p->io_error_proc = IOErrorProc; 126 127 return (opcodeRet); 128} 129 130 131 132int 133IceRegisterForProtocolReply ( 134 const char *protocolName, 135 const char *vendor, 136 const char *release, 137 int versionCount, 138 IcePaVersionRec *versionRecs, 139 int authCount, 140 const char **authNames, 141 IcePaAuthProc *authProcs, 142 IceHostBasedAuthProc hostBasedAuthProc, 143 IceProtocolSetupProc protocolSetupProc, 144 IceProtocolActivateProc protocolActivateProc, 145 IceIOErrorProc IOErrorProc 146) 147{ 148 _IcePaProtocol *p; 149 int opcodeRet, i; 150 151 for (i = 1; i <= _IceLastMajorOpcode; i++) 152 if (strcmp (protocolName, _IceProtocols[i - 1].protocol_name) == 0) 153 { 154 if (_IceProtocols[i - 1].accept_client != NULL) 155 { 156 /* 157 * We've already registered this protocol. 158 */ 159 160 return (i); 161 } 162 else 163 { 164 break; 165 } 166 } 167 168 169 if (i <= _IceLastMajorOpcode) 170 { 171 p = _IceProtocols[i - 1].accept_client = 172 (_IcePaProtocol *) malloc (sizeof (_IcePaProtocol)); 173 opcodeRet = i; 174 } 175 else if (_IceLastMajorOpcode == 255 || 176 versionCount < 1 || 177 strlen (protocolName) == 0) 178 { 179 return (-1); 180 } 181 else 182 { 183 char *name; 184 185 _IceProtocols[_IceLastMajorOpcode].protocol_name = name = 186 strdup(protocolName); 187 188 _IceProtocols[_IceLastMajorOpcode].orig_client = NULL; 189 190 p = _IceProtocols[_IceLastMajorOpcode].accept_client = 191 (_IcePaProtocol *) malloc (sizeof (_IcePaProtocol)); 192 193 opcodeRet = ++_IceLastMajorOpcode; 194 } 195 196 p->vendor = strdup(vendor); 197 p->release = strdup(release); 198 199 p->version_count = versionCount; 200 201 p->version_recs = (IcePaVersionRec *) malloc ( 202 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 = (char **) malloc ( 212 authCount * sizeof (char *)); 213 214 p->auth_procs = (IcePaAuthProc *) malloc ( 215 authCount * sizeof (IcePaAuthProc)); 216 217 for (i = 0; i < authCount; i++) 218 { 219 p->auth_names[i] = strdup(authNames[i]); 220 p->auth_procs[i] = authProcs[i]; 221 } 222 } 223 else 224 { 225 p->auth_names = NULL; 226 p->auth_procs = NULL; 227 } 228 229 p->host_based_auth_proc = hostBasedAuthProc; 230 231 p->io_error_proc = IOErrorProc; 232 233 return (opcodeRet); 234} 235 236