1266e564dSmrg/****************************************************************************** 2266e564dSmrg 3266e564dSmrg 4266e564dSmrgCopyright 1993, 1998 The Open Group 5266e564dSmrg 6266e564dSmrgPermission to use, copy, modify, distribute, and sell this software and its 7266e564dSmrgdocumentation for any purpose is hereby granted without fee, provided that 8266e564dSmrgthe above copyright notice appear in all copies and that both that 9266e564dSmrgcopyright notice and this permission notice appear in supporting 10266e564dSmrgdocumentation. 11266e564dSmrg 12266e564dSmrgThe above copyright notice and this permission notice shall be included in 13266e564dSmrgall copies or substantial portions of the Software. 14266e564dSmrg 15266e564dSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16266e564dSmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17266e564dSmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18266e564dSmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 19266e564dSmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20266e564dSmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21266e564dSmrg 22266e564dSmrgExcept as contained in this notice, the name of The Open Group shall not be 23266e564dSmrgused in advertising or otherwise to promote the sale, use or other dealings 24266e564dSmrgin this Software without prior written authorization from The Open Group. 25266e564dSmrg 26266e564dSmrgAuthor: Ralph Mor, X Consortium 27266e564dSmrg******************************************************************************/ 28266e564dSmrg 29266e564dSmrg#ifdef HAVE_CONFIG_H 30266e564dSmrg#include <config.h> 31266e564dSmrg#endif 32266e564dSmrg#include <X11/ICE/ICElib.h> 33266e564dSmrg#include "ICElibint.h" 34266e564dSmrg 35266e564dSmrgint 36c5629e66SmrgIceRegisterForProtocolSetup ( 379ef0b394Smrg const char *protocolName, 389ef0b394Smrg const char *vendor, 399ef0b394Smrg const char *release, 40c5629e66Smrg int versionCount, 41c5629e66Smrg IcePoVersionRec *versionRecs, 42c5629e66Smrg int authCount, 43c5629e66Smrg const char **authNames, 44c5629e66Smrg IcePoAuthProc *authProcs, 45c5629e66Smrg IceIOErrorProc IOErrorProc 46c5629e66Smrg) 47266e564dSmrg{ 48266e564dSmrg _IcePoProtocol *p; 49266e564dSmrg int opcodeRet, i; 50266e564dSmrg 51266e564dSmrg for (i = 1; i <= _IceLastMajorOpcode; i++) 52266e564dSmrg if (strcmp (protocolName, _IceProtocols[i - 1].protocol_name) == 0) 53266e564dSmrg { 54266e564dSmrg if (_IceProtocols[i - 1].orig_client != NULL) 55266e564dSmrg { 56266e564dSmrg /* 57266e564dSmrg * We've already registered this protocol. 58266e564dSmrg */ 599ef0b394Smrg 60266e564dSmrg return (i); 61266e564dSmrg } 62266e564dSmrg else 63266e564dSmrg { 64266e564dSmrg break; 65266e564dSmrg } 66266e564dSmrg } 679ef0b394Smrg 68266e564dSmrg if (i <= _IceLastMajorOpcode) 69266e564dSmrg { 70fb5e8d76Smrg p = _IceProtocols[i - 1].orig_client = malloc (sizeof(_IcePoProtocol)); 713bf3b463Smrg if (p == NULL) 723bf3b463Smrg return (-1); 73266e564dSmrg opcodeRet = i; 74266e564dSmrg } 75266e564dSmrg else if (_IceLastMajorOpcode == 255 || 76266e564dSmrg versionCount < 1 || 77266e564dSmrg strlen (protocolName) == 0) 78266e564dSmrg { 79266e564dSmrg return (-1); 80266e564dSmrg } 81266e564dSmrg else 82266e564dSmrg { 83fb5e8d76Smrg _IceProtocols[_IceLastMajorOpcode].protocol_name = 84266e564dSmrg strdup(protocolName); 853bf3b463Smrg if (_IceProtocols[_IceLastMajorOpcode].protocol_name == NULL) 863bf3b463Smrg return (-1); 87266e564dSmrg 88266e564dSmrg p = _IceProtocols[_IceLastMajorOpcode].orig_client = 89fb5e8d76Smrg malloc (sizeof (_IcePoProtocol)); 903bf3b463Smrg if (p == NULL) 913bf3b463Smrg { 923bf3b463Smrg free(_IceProtocols[_IceLastMajorOpcode].protocol_name); 933bf3b463Smrg return (-1); 943bf3b463Smrg } 95266e564dSmrg 96266e564dSmrg _IceProtocols[_IceLastMajorOpcode].accept_client = NULL; 97266e564dSmrg 98266e564dSmrg opcodeRet = ++_IceLastMajorOpcode; 99266e564dSmrg } 100266e564dSmrg 101266e564dSmrg p->vendor = strdup(vendor); 102266e564dSmrg p->release = strdup(release); 103266e564dSmrg 104266e564dSmrg p->version_count = versionCount; 105266e564dSmrg 106fb5e8d76Smrg p->version_recs = malloc (versionCount * sizeof (IcePoVersionRec)); 107266e564dSmrg memcpy (p->version_recs, versionRecs, 108266e564dSmrg versionCount * sizeof (IcePoVersionRec)); 109266e564dSmrg 110266e564dSmrg if ((p->auth_count = authCount) > 0) 111266e564dSmrg { 112fb5e8d76Smrg p->auth_names = malloc (authCount * sizeof (char *)); 113266e564dSmrg 114fb5e8d76Smrg p->auth_procs = malloc (authCount * sizeof (IcePoAuthProc)); 115266e564dSmrg 116266e564dSmrg for (i = 0; i < authCount; i++) 117266e564dSmrg { 118266e564dSmrg p->auth_names[i] = strdup(authNames[i]); 119266e564dSmrg p->auth_procs[i] = authProcs[i]; 120266e564dSmrg } 121266e564dSmrg } 122266e564dSmrg else 123266e564dSmrg { 124266e564dSmrg p->auth_names = NULL; 125266e564dSmrg p->auth_procs = NULL; 126266e564dSmrg } 127266e564dSmrg 128266e564dSmrg p->io_error_proc = IOErrorProc; 129266e564dSmrg 130266e564dSmrg return (opcodeRet); 131266e564dSmrg} 132266e564dSmrg 133266e564dSmrg 134a3129944Smrg 135266e564dSmrgint 136c5629e66SmrgIceRegisterForProtocolReply ( 1379ef0b394Smrg const char *protocolName, 1389ef0b394Smrg const char *vendor, 1399ef0b394Smrg const char *release, 140c5629e66Smrg int versionCount, 141c5629e66Smrg IcePaVersionRec *versionRecs, 142c5629e66Smrg int authCount, 143c5629e66Smrg const char **authNames, 144c5629e66Smrg IcePaAuthProc *authProcs, 145c5629e66Smrg IceHostBasedAuthProc hostBasedAuthProc, 146c5629e66Smrg IceProtocolSetupProc protocolSetupProc, 147c5629e66Smrg IceProtocolActivateProc protocolActivateProc, 148c5629e66Smrg IceIOErrorProc IOErrorProc 149c5629e66Smrg) 150266e564dSmrg{ 151266e564dSmrg _IcePaProtocol *p; 152266e564dSmrg int opcodeRet, i; 153266e564dSmrg 154266e564dSmrg for (i = 1; i <= _IceLastMajorOpcode; i++) 155266e564dSmrg if (strcmp (protocolName, _IceProtocols[i - 1].protocol_name) == 0) 156266e564dSmrg { 157266e564dSmrg if (_IceProtocols[i - 1].accept_client != NULL) 158266e564dSmrg { 159266e564dSmrg /* 160266e564dSmrg * We've already registered this protocol. 161266e564dSmrg */ 1629ef0b394Smrg 163266e564dSmrg return (i); 164266e564dSmrg } 165266e564dSmrg else 166266e564dSmrg { 167266e564dSmrg break; 168266e564dSmrg } 169266e564dSmrg } 1709ef0b394Smrg 171266e564dSmrg 172266e564dSmrg if (i <= _IceLastMajorOpcode) 173266e564dSmrg { 174266e564dSmrg p = _IceProtocols[i - 1].accept_client = 175fb5e8d76Smrg malloc (sizeof (_IcePaProtocol)); 176266e564dSmrg opcodeRet = i; 177266e564dSmrg } 178266e564dSmrg else if (_IceLastMajorOpcode == 255 || 179266e564dSmrg versionCount < 1 || 180266e564dSmrg strlen (protocolName) == 0) 181266e564dSmrg { 182266e564dSmrg return (-1); 183266e564dSmrg } 184266e564dSmrg else 185266e564dSmrg { 186fb5e8d76Smrg _IceProtocols[_IceLastMajorOpcode].protocol_name = 187266e564dSmrg strdup(protocolName); 188266e564dSmrg 189266e564dSmrg _IceProtocols[_IceLastMajorOpcode].orig_client = NULL; 190266e564dSmrg 191266e564dSmrg p = _IceProtocols[_IceLastMajorOpcode].accept_client = 192fb5e8d76Smrg malloc (sizeof (_IcePaProtocol)); 193266e564dSmrg 194266e564dSmrg opcodeRet = ++_IceLastMajorOpcode; 195266e564dSmrg } 196266e564dSmrg 197266e564dSmrg p->vendor = strdup(vendor); 198266e564dSmrg p->release = strdup(release); 199266e564dSmrg 200266e564dSmrg p->version_count = versionCount; 201266e564dSmrg 202fb5e8d76Smrg p->version_recs = malloc (versionCount * sizeof (IcePaVersionRec)); 203266e564dSmrg memcpy (p->version_recs, versionRecs, 204266e564dSmrg versionCount * sizeof (IcePaVersionRec)); 205266e564dSmrg 206266e564dSmrg p->protocol_setup_proc = protocolSetupProc; 207266e564dSmrg p->protocol_activate_proc = protocolActivateProc; 208266e564dSmrg 209266e564dSmrg if ((p->auth_count = authCount) > 0) 210266e564dSmrg { 211fb5e8d76Smrg p->auth_names = malloc (authCount * sizeof (char *)); 212266e564dSmrg 213fb5e8d76Smrg p->auth_procs = malloc (authCount * sizeof (IcePaAuthProc)); 214266e564dSmrg 215266e564dSmrg for (i = 0; i < authCount; i++) 216266e564dSmrg { 217266e564dSmrg p->auth_names[i] = strdup(authNames[i]); 218266e564dSmrg p->auth_procs[i] = authProcs[i]; 219266e564dSmrg } 220266e564dSmrg } 221266e564dSmrg else 222266e564dSmrg { 223266e564dSmrg p->auth_names = NULL; 224266e564dSmrg p->auth_procs = NULL; 225266e564dSmrg } 226266e564dSmrg 227266e564dSmrg p->host_based_auth_proc = hostBasedAuthProc; 228266e564dSmrg 229266e564dSmrg p->io_error_proc = IOErrorProc; 230266e564dSmrg 231266e564dSmrg return (opcodeRet); 232266e564dSmrg} 233266e564dSmrg 234