Changeset 844
- Timestamp:
- 08/08/08 23:17:17 (3 years ago)
- Location:
- Whitix/trunk/user/system/registry
- Files:
-
- 1 added
- 9 modified
Legend:
- Unmodified
- Added
- Removed
-
Whitix/trunk/user/system/registry/Makefile
r839 r844 1 1 CFLAGS = -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 3 3 OBJS = main.o keyset.o key.o file.o socket.o handle.o 4 4 -
Whitix/trunk/user/system/registry/file.c
r839 r844 1 1 #include "file.h" 2 2 3 #include <file.h> 3 4 #include <stdlib.h> 4 5 … … 97 98 if (!mount) 98 99 { 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); 101 103 } 102 104 } -
Whitix/trunk/user/system/registry/handle.c
r839 r844 22 22 *list=handle; 23 23 }else{ 24 printf("RegKeySetHandleCreate\n"); 24 struct RegKeySetHandle* curr=*list; 25 26 while (curr->next) 27 curr=curr->next; 28 29 curr->next=handle; 25 30 } 26 31 … … 28 33 } 29 34 30 unsigned longRegKeySetGetHandleId(struct RegKeySetHandle* list, struct RegKeySetHandle* handle)35 int RegKeySetGetHandleId(struct RegKeySetHandle* list, struct RegKeySetHandle* handle) 31 36 { 32 37 struct RegKeySetHandle* curr=list; … … 39 44 } 40 45 46 if (!curr) 47 return -1; 48 41 49 return ret; 42 50 } 43 51 44 struct RegKeySetHandle* RegKeySetGetHandle(struct RegKeySetHandle* list, unsigned longid)52 struct RegKeySetHandle* RegKeySetGetHandle(struct RegKeySetHandle* list, int id) 45 53 { 46 54 struct RegKeySetHandle* curr=list; -
Whitix/trunk/user/system/registry/handle.h
r839 r844 8 8 }; 9 9 10 struct RegKeySetHandle* RegKeySetHandleCreate(char* name, struct RegKeySetHandle** list); 11 int RegKeySetGetHandleId(struct RegKeySetHandle* list, struct RegKeySetHandle* handle); 12 struct RegKeySetHandle* RegKeySetGetHandle(struct RegKeySetHandle* list, int id); 13 10 14 #endif -
Whitix/trunk/user/system/registry/keyset.c
r839 r844 12 12 root.children=NULL; 13 13 root.keys=NULL; 14 root.numChildren=0; 15 root.numKeys=0; 14 16 15 17 return 0; … … 79 81 80 82 while (currKey) 81 { 83 { 82 84 if (!strcmp(currKey->key, name)) 83 85 break; … … 102 104 curr->next=key; 103 105 } 106 107 parent->numKeys++; 108 } 109 110 struct 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; 104 118 } 105 119 … … 118 132 curr->next=child; 119 133 } 134 135 parent->numChildren++; 136 printf("%s, %d\n", parent->name, parent->numChildren); 120 137 } 121 138 122 voidRegKeySetCreateOne(struct RegKeySet* parent, char* name, int length)139 struct RegKeySet* RegKeySetCreateOne(struct RegKeySet* parent, char* name, int length) 123 140 { 124 141 struct RegKeySet* ret; … … 127 144 ret->name=strndup(name, length); 128 145 ret->children=NULL; 146 ret->numChildren=0; 129 147 ret->keys=NULL; 148 ret->numKeys=0; 130 149 ret->next=NULL; 131 150 132 151 RegKeySetAddChild(parent, ret); 152 153 return ret; 133 154 } 134 155 … … 137 158 struct RegKeySet* parent; 138 159 char* name; 160 161 if (!strcmp(path, "/")) 162 return RegKeySetGetRoot(); 139 163 140 164 parent=RegKeySetLookup(NULL, path, &name); -
Whitix/trunk/user/system/registry/keyset.h
r839 r844 15 15 char* name; 16 16 struct RegKeySet* children; 17 int numChildren; 17 18 struct RegKey* keys; 19 int numKeys; 18 20 struct RegKeySet* next; 19 21 }; 20 22 23 /* Functions to manage keysets. */ 24 void RegKeySetCreate(struct RegKeySet* keySet, char* path); 25 struct RegKeySet* RegKeySetGet(char* path); 26 struct RegKeySet* RegKeySetCreateOne(struct RegKeySet* parent, char* name, int length); 27 28 /* Keyset root functions. */ 29 int RegKeySetCreateRoot(); 30 struct RegKeySet* RegKeySetGetRoot(); 31 21 32 #endif 22 33 -
Whitix/trunk/user/system/registry/main.c
r839 r844 3 3 #include <file.h> 4 4 5 #include "file.h" 5 6 #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 ******************************************************************************/ 6 20 7 21 int RegLoadApplication(char* appDir) … … 10 24 struct RegKeySet* mount; 11 25 26 /* 27 * The application's registry file should be located in /Applications/<app>/ 28 * application.reg 29 */ 12 30 strcpy(path, appDir); 13 31 strcat(path, "/application.reg"); 14 32 15 mount=RegKeySetCreate(NULL, appDir); 33 /* Mount the keysets to be read in at /Applications/<app>/, that is, appDir. */ 34 RegKeySetCreate(NULL, appDir); 16 35 36 mount=RegKeySetGet(appDir); 37 38 if (!mount) 39 return -1; 40 41 /* Load the keysets into memory at the mount point. */ 17 42 RegLoadFile(path, mount); 43 44 return 0; 18 45 } 19 46 -
Whitix/trunk/user/system/registry/socket.c
r839 r844 1 1 #include <network.h> 2 2 #include <stdlib.h> 3 #include <stdio.h> 4 #include <string.h> 3 5 4 6 #include "socket.h" … … 27 29 28 30 handle=RegKeySetHandleCreate(packet->name, list); 31 32 if (!handle) 33 { 34 handleId=-1; 35 goto send; 36 } 37 29 38 handleId=RegKeySetGetHandleId(*list, handle); 30 39 40 send: 31 41 /* Send the handle ID back to the calling application. */ 32 42 NetSocketSend(clientFd, &handleId, 4, 0); … … 81 91 } 82 92 93 void 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 148 error: 149 length=-1; 150 NetSocketSend(clientFd, &length, sizeof(int), 0); 151 } 152 83 153 void RegSocketListen(int* clientSock) 84 154 { … … 111 181 break; 112 182 183 case REG_PACKET_ENUM_KEYSET: 184 RegSocketParseEnum(clientFd, buf, list); 185 break; 186 113 187 default: 114 188 printf("Regserver: %u\n", header->type); 189 continue; 115 190 } 116 191 } -
Whitix/trunk/user/system/registry/socket.h
r839 r844 4 4 #define REG_PACKET_OPEN_KEY 1 5 5 #define REG_PACKET_READ_KEY 2 6 #define REG_PACKET_ENUM_KEYSET 3 6 7 7 8 struct RegPacketHeader … … 34 35 }; 35 36 37 struct RegEnumSetPacket 38 { 39 int type; 40 int length; 41 unsigned long handleId; 42 unsigned long index; 43 unsigned long size; 44 }; 45 36 46 #endif
