Annotation of driverkit/libDriver/Kernel/IOConfigTable.m, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
        !             3:  *
        !             4:  * @APPLE_LICENSE_HEADER_START@
        !             5:  * 
        !             6:  * Portions Copyright (c) 1999 Apple Computer, Inc.  All Rights
        !             7:  * Reserved.  This file contains Original Code and/or Modifications of
        !             8:  * Original Code as defined in and that are subject to the Apple Public
        !             9:  * Source License Version 1.1 (the "License").  You may not use this file
        !            10:  * except in compliance with the License.  Please obtain a copy of the
        !            11:  * License at http://www.apple.com/publicsource and read it before using
        !            12:  * this file.
        !            13:  * 
        !            14:  * The Original Code and all software distributed under the License are
        !            15:  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
        !            16:  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
        !            17:  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
        !            18:  * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT.  Please see the
        !            19:  * License for the specific language governing rights and limitations
        !            20:  * under the License.
        !            21:  * 
        !            22:  * @APPLE_LICENSE_HEADER_END@
        !            23:  */
        !            24: /*     Copyright (c) 1993 NeXT Computer, Inc.  All rights reserved. 
        !            25:  *
        !            26:  * Kernel level implementation of IOConfigTable.
        !            27:  *
        !            28:  * HISTORY
        !            29:  * 29-Jan-93    Doug Mitchell at NeXT
        !            30:  *      Created.
        !            31:  */
        !            32: 
        !            33: #import <driverkit/IOConfigTable.h>
        !            34: #import <driverkit/configTableKern.h>
        !            35: #import <driverkit/configTablePrivate.h>
        !            36: #import <driverkit/generalFuncs.h>
        !            37: #if i386
        !            38: #import <machdep/i386/kernBootStruct.h>
        !            39: #endif i386
        !            40: #import <string.h>
        !            41: 
        !            42: /*
        !            43:  * This really should be static, but it has a prototype in <ansi/string.h>.
        !            44:  */
        !            45: char *strstr(const char *s1, const char *s2);
        !            46: 
        !            47: /*
        !            48:  * The _private ivar is a char *. 
        !            49:  */
        !            50: @implementation IOConfigTable
        !            51: 
        !            52: - free
        !            53: {
        !            54:        char *configData = (char *)_private;
        !            55:        
        !            56:        if(configData) {
        !            57:                IOFree(configData, strlen(configData)+1);
        !            58:        }
        !            59:        return [super free];
        !            60: }
        !            61: 
        !            62: /*
        !            63:  * Obtain the system-wide configuration table.
        !            64:  */
        !            65: + newFromSystemConfig
        !            66: {
        !            67: #if i386
        !            68:        KERNBOOTSTRUCT *bootstruct = KERNSTRUCT_ADDR;
        !            69:        return [self newForConfigData: &bootstruct->config[0]];
        !            70: #else i386
        !            71:        /* 
        !            72:         * FIXME - where is KERNBOOTSTRUCT?
        !            73:         */
        !            74:        return nil;
        !            75: #endif i386
        !            76: }
        !            77: 
        !            78: /*
        !            79:  * Obtain value for specified string key. Returns null of key not
        !            80:  * found.
        !            81:  * The string here must eventually be freed (by the caller) via
        !            82:  * IOFree(buf, strlen(buf) + 1). This is kinda bogus...
        !            83:  */
        !            84: - (const char *)valueForStringKey:(const char *)key
        !            85: {
        !            86:        const char *configData = (char *)_private;
        !            87:        const char *valueEnd;
        !            88:        const char *valueStart;
        !            89:        char *out;
        !            90:        int length;
        !            91:        
        !            92:        length = strlen(key);
        !            93:        {
        !            94:            char        quotedkey[length + 3];
        !            95:            
        !            96:            quotedkey[0] = '"';
        !            97:            strcpy(&quotedkey[1], key);
        !            98:            quotedkey[length + 1] = '"';
        !            99:            quotedkey[length + 2] = 0;
        !           100:            
        !           101:            valueStart = strstr(configData, quotedkey);
        !           102:            if (valueStart == NULL)
        !           103:                return NULL;
        !           104:                
        !           105:            valueStart += (length + 2); // point past the quoted key
        !           106:        }
        !           107:        
        !           108:        /*
        !           109:         * ValueStart points just past the quoted key
        !           110:         */
        !           111:        valueStart = strchr(valueStart, '"');
        !           112:        valueStart++;
        !           113:        
        !           114:        /*
        !           115:         * valueStart points to the first character of the desired value.
        !           116:         */
        !           117:        valueEnd = strchr(valueStart, '"');
        !           118:        if (valueEnd != NULL) {
        !           119:                length = valueEnd - valueStart;
        !           120:                out = IOMalloc(length + 1);
        !           121:                strncpy(out, valueStart, length);
        !           122:                out[length] = '\0';
        !           123:                return out;
        !           124:        }
        !           125:        else {
        !           126:                return NULL;
        !           127:        }
        !           128: }
        !           129: 
        !           130: 
        !           131: + (void)freeString : (const char *)string
        !           132: {
        !           133:        IOFree((char *)string, strlen(string) + 1);
        !           134: }
        !           135: 
        !           136: - (void)freeString : (const char *)string
        !           137: {
        !           138:        [IOConfigTable freeString:string];
        !           139: }      
        !           140: 
        !           141: 
        !           142: @end
        !           143: 
        !           144: @implementation IOConfigTable(KernelPrivate)
        !           145: 
        !           146: /*
        !           147:  * Create a new instance for specified IOConfigData text. 
        !           148:  */
        !           149: + newForConfigData : (const char *)configData
        !           150: {
        !           151:        IOConfigTable *configTable = [[self alloc] init];
        !           152:        char *data;
        !           153:        int ssize = strlen(configData) + 1;
        !           154:        
        !           155:        if(ssize > IO_CONFIG_DATA_SIZE) {
        !           156:                ssize = IO_CONFIG_DATA_SIZE;
        !           157:        }
        !           158:        data = IOMalloc(ssize);
        !           159:        bcopy(configData, data, ssize-1);
        !           160:        data[ssize-1] = 0;
        !           161:        configTable->_private = data;
        !           162:        return configTable;
        !           163: }
        !           164: 
        !           165: @end
        !           166: 
        !           167: /* 
        !           168:  * Like strchr, but searches for a string. Returns pointer to start of 
        !           169:  * the found string, else returns NULL.
        !           170:  */
        !           171: char *strstr(const char *s1, const char *s2) {
        !           172:        char c1;
        !           173:        const char c2 = *s2;
        !           174: 
        !           175:        while ((c1 = *s1++) != '\0') {
        !           176:                if (c1 == c2) {
        !           177:                        const char *p1, *p2;
        !           178: 
        !           179:                        p1 = s1;
        !           180:                        p2 = &s2[1];
        !           181:                        while (*p1++ == (c1 = *p2++) && c1) {
        !           182:                                continue;
        !           183:                        }
        !           184:                        if (c1 == '\0') {
        !           185:                                return ((char *)s1) - 1;
        !           186:                        }
        !           187:             }
        !           188:       }
        !           189:       return NULL;
        !           190: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.