Changeset 844

Show
Ignore:
Timestamp:
08/08/08 23:17:17 (3 years ago)
Author:
mwhitworth
Message:

Add support for enumerating a keyset, add comments and error checking.

Location:
Whitix/trunk/user/system/registry
Files:
1 added
9 modified

Legend:

Unmodified
Added
Removed
  • Whitix/trunk/user/system/registry/Makefile

    r839 r844  
    11CFLAGS = -g -ffreestanding -fno-builtin -I../../libc/include -I../../librtl \ 
    2          -I../../sdk/include -fno-stack-protector -DMODULE -m32 
     2         -I../../sdk/include -fno-stack-protector -DMODULE -m32 -Wall -Wextra 
    33OBJS = main.o keyset.o key.o file.o socket.o handle.o 
    44 
  • Whitix/trunk/user/system/registry/file.c

    r839 r844  
    11#include "file.h" 
    22 
     3#include <file.h> 
    34#include <stdlib.h> 
    45 
     
    9798                                if (!mount) 
    9899                                { 
    99                                         printf("RegServer: mounting at %s\n", value); 
    100                                         mount=RegKeySetCreate(0, value); 
     100//                                      printf("RegServer: mounting at %s\n", value); 
     101                                        RegKeySetCreate(0, value); 
     102                                        mount=RegKeySetGet(value); 
    101103                                } 
    102104                        } 
  • Whitix/trunk/user/system/registry/handle.c

    r839 r844  
    2222                *list=handle; 
    2323        }else{ 
    24                 printf("RegKeySetHandleCreate\n"); 
     24                struct RegKeySetHandle* curr=*list; 
     25                 
     26                while (curr->next) 
     27                        curr=curr->next; 
     28                         
     29                curr->next=handle; 
    2530        } 
    2631         
     
    2833} 
    2934 
    30 unsigned long RegKeySetGetHandleId(struct RegKeySetHandle* list, struct RegKeySetHandle* handle) 
     35int RegKeySetGetHandleId(struct RegKeySetHandle* list, struct RegKeySetHandle* handle) 
    3136{ 
    3237        struct RegKeySetHandle* curr=list; 
     
    3944        } 
    4045         
     46        if (!curr) 
     47                return -1; 
     48         
    4149        return ret; 
    4250} 
    4351 
    44 struct RegKeySetHandle* RegKeySetGetHandle(struct RegKeySetHandle* list, unsigned long id) 
     52struct RegKeySetHandle* RegKeySetGetHandle(struct RegKeySetHandle* list, int id) 
    4553{ 
    4654        struct RegKeySetHandle* curr=list; 
  • Whitix/trunk/user/system/registry/handle.h

    r839 r844  
    88}; 
    99 
     10struct RegKeySetHandle* RegKeySetHandleCreate(char* name, struct RegKeySetHandle** list); 
     11int RegKeySetGetHandleId(struct RegKeySetHandle* list, struct RegKeySetHandle* handle); 
     12struct RegKeySetHandle* RegKeySetGetHandle(struct RegKeySetHandle* list, int id); 
     13 
    1014#endif 
  • Whitix/trunk/user/system/registry/keyset.c

    r839 r844  
    1212        root.children=NULL; 
    1313        root.keys=NULL; 
     14        root.numChildren=0; 
     15        root.numKeys=0; 
    1416         
    1517        return 0; 
     
    7981                 
    8082        while (currKey) 
    81         { 
     83        {                
    8284                if (!strcmp(currKey->key, name)) 
    8385                        break; 
     
    102104                curr->next=key; 
    103105        } 
     106         
     107        parent->numKeys++; 
     108} 
     109 
     110struct RegKeySet* RegKeySetGetChild(struct RegKeySet* list, int id) 
     111{ 
     112        struct RegKeySet* curr=list; 
     113         
     114        while (curr && id--) 
     115                curr=curr->next; 
     116                 
     117        return curr; 
    104118} 
    105119 
     
    118132                curr->next=child; 
    119133        } 
     134         
     135        parent->numChildren++; 
     136        printf("%s, %d\n", parent->name, parent->numChildren); 
    120137} 
    121138 
    122 void RegKeySetCreateOne(struct RegKeySet* parent, char* name, int length) 
     139struct RegKeySet* RegKeySetCreateOne(struct RegKeySet* parent, char* name, int length) 
    123140{ 
    124141        struct RegKeySet* ret; 
     
    127144        ret->name=strndup(name, length); 
    128145        ret->children=NULL; 
     146        ret->numChildren=0; 
    129147        ret->keys=NULL; 
     148        ret->numKeys=0; 
    130149        ret->next=NULL; 
    131150         
    132151        RegKeySetAddChild(parent, ret); 
     152 
     153        return ret; 
    133154} 
    134155 
     
    137158        struct RegKeySet* parent; 
    138159        char* name; 
     160         
     161        if (!strcmp(path, "/")) 
     162                return RegKeySetGetRoot(); 
    139163         
    140164        parent=RegKeySetLookup(NULL, path, &name); 
  • Whitix/trunk/user/system/registry/keyset.h

    r839 r844  
    1515        char* name; 
    1616        struct RegKeySet* children; 
     17        int numChildren; 
    1718        struct RegKey* keys; 
     19        int numKeys; 
    1820        struct RegKeySet* next; 
    1921}; 
    2022 
     23/* Functions to manage keysets. */ 
     24void RegKeySetCreate(struct RegKeySet* keySet, char* path); 
     25struct RegKeySet* RegKeySetGet(char* path); 
     26struct RegKeySet* RegKeySetCreateOne(struct RegKeySet* parent, char* name, int length); 
     27 
     28/* Keyset root functions. */ 
     29int RegKeySetCreateRoot(); 
     30struct RegKeySet* RegKeySetGetRoot(); 
     31 
    2132#endif 
    2233 
  • Whitix/trunk/user/system/registry/main.c

    r839 r844  
    33#include <file.h> 
    44 
     5#include "file.h" 
    56#include "keyset.h" 
     7 
     8/******************************************************************************* 
     9 * 
     10 * FUNCTION:    RegLoadApplication 
     11 * 
     12 * DESCRIPTION: Loads the registry configuration file for a Whitix application  
     13 *                              and mounts it in the registry. 
     14 * 
     15 * PARAMETERS:  appDir - The path to the directory of the Whitix application. 
     16 * 
     17 * RETURNS:     Standard Whitix error codes. 
     18 * 
     19 ******************************************************************************/ 
    620 
    721int RegLoadApplication(char* appDir) 
     
    1024        struct RegKeySet* mount; 
    1125         
     26        /* 
     27         * The application's registry file should be located in /Applications/<app>/ 
     28         * application.reg 
     29         */ 
    1230        strcpy(path, appDir); 
    1331        strcat(path, "/application.reg"); 
    1432         
    15         mount=RegKeySetCreate(NULL, appDir); 
     33        /* Mount the keysets to be read in at /Applications/<app>/, that is, appDir. */ 
     34        RegKeySetCreate(NULL, appDir); 
    1635         
     36        mount=RegKeySetGet(appDir); 
     37         
     38        if (!mount) 
     39                return -1; 
     40         
     41        /* Load the keysets into memory at the mount point. */ 
    1742        RegLoadFile(path, mount); 
     43         
     44        return 0; 
    1845} 
    1946 
  • Whitix/trunk/user/system/registry/socket.c

    r839 r844  
    11#include <network.h> 
    22#include <stdlib.h> 
     3#include <stdio.h> 
     4#include <string.h> 
    35 
    46#include "socket.h" 
     
    2729         
    2830        handle=RegKeySetHandleCreate(packet->name, list); 
     31         
     32        if (!handle) 
     33        { 
     34                handleId=-1; 
     35                goto send; 
     36        } 
     37         
    2938        handleId=RegKeySetGetHandleId(*list, handle); 
    30          
     39 
     40send: 
    3141        /* Send the handle ID back to the calling application. */ 
    3242        NetSocketSend(clientFd, &handleId, 4, 0); 
     
    8191} 
    8292 
     93void RegSocketParseEnum(int clientFd, char* buf, struct RegKeySetHandle* list) 
     94{ 
     95        struct RegEnumSetPacket* packet=(struct RegEnumSetPacket*)buf; 
     96        struct RegKeySetHandle* handle; 
     97        struct RegKeySet* set; 
     98        char* sendBuf, *curr; 
     99        int length=0; 
     100         
     101        handle=RegKeySetGetHandle(list, packet->handleId); 
     102         
     103        if (!handle) 
     104                goto error; 
     105                 
     106        set=handle->set; 
     107         
     108        sendBuf=(char*)malloc(packet->size); 
     109        curr=sendBuf; 
     110         
     111        if (!sendBuf) 
     112                goto error; 
     113         
     114//      printf("%s: %d, %d %d\n", set->name, packet->index, set->numChildren, set->numKeys); 
     115         
     116        /* Iterate through child keysets first, and then child keys. */ 
     117        if (packet->index < set->numChildren) 
     118        { 
     119                struct RegKeySet* currChild=RegKeySetGetChild(set->children, packet->index); 
     120                 
     121                while (packet->size > 0 && currChild) 
     122                { 
     123                        int strLen=strlen(currChild->name); 
     124                        packet->index++; 
     125                        memcpy(curr, currChild->name, strLen); 
     126                        curr+=strLen+1; 
     127                        packet->size-=strLen; 
     128                         
     129                        currChild=currChild->next; 
     130                } 
     131        } 
     132         
     133        if (packet->index >= set->numChildren 
     134                && packet->index < set->numChildren+set->numKeys) 
     135        { 
     136                printf("Copy over KEYS\n"); 
     137        } 
     138         
     139        length=curr-sendBuf; 
     140         
     141//      printf("Sending %d\n", length); 
     142         
     143        NetSocketSend(clientFd, sendBuf, length, 0); 
     144         
     145        free(sendBuf); 
     146        return; 
     147         
     148error: 
     149        length=-1; 
     150        NetSocketSend(clientFd, &length, sizeof(int), 0); 
     151} 
     152 
    83153void RegSocketListen(int* clientSock) 
    84154{ 
     
    111181                                break; 
    112182                         
     183                        case REG_PACKET_ENUM_KEYSET: 
     184                                RegSocketParseEnum(clientFd, buf, list); 
     185                                break; 
     186                         
    113187                        default: 
    114188                                printf("Regserver: %u\n", header->type); 
     189                                continue; 
    115190                } 
    116191        } 
  • Whitix/trunk/user/system/registry/socket.h

    r839 r844  
    44#define REG_PACKET_OPEN_KEY             1 
    55#define REG_PACKET_READ_KEY             2 
     6#define REG_PACKET_ENUM_KEYSET  3 
    67 
    78struct RegPacketHeader 
     
    3435}; 
    3536 
     37struct RegEnumSetPacket 
     38{ 
     39        int type; 
     40        int length; 
     41        unsigned long handleId; 
     42        unsigned long index; 
     43        unsigned long size; 
     44}; 
     45 
    3646#endif