libfreerdp-core: introduced configuration registry

This commit is contained in:
Marc-André Moreau 2011-07-14 01:23:44 -04:00
parent 48344cf4f7
commit bae2ebb7d1
5 changed files with 230 additions and 0 deletions

View File

@ -38,6 +38,8 @@ set(LIBFREERDP_CORE_SRCS
ntlmssp.h
license.c
license.h
registry.c
registry.h
security.c
security.h
settings.c

View File

@ -157,6 +157,7 @@ rdpRdp* rdp_new()
if (rdp != NULL)
{
rdp->settings = settings_new();
rdp->registry = registry_new(rdp->settings);
rdp->transport = transport_new(rdp->settings);
rdp->license = license_new(rdp);
rdp->nego = nego_new(rdp->transport);

View File

@ -28,10 +28,12 @@ typedef struct rdp_rdp rdpRdp;
#include "nego.h"
#include "license.h"
#include "security.h"
#include "registry.h"
#include "transport.h"
#include "connection.h"
#include <freerdp/freerdp.h>
#include <freerdp/settings.h>
#include <freerdp/utils/stream.h>
/* Security Header Flags */
@ -60,6 +62,7 @@ struct rdp_rdp
struct rdp_nego* nego;
struct rdp_license* license;
struct rdp_settings* settings;
struct rdp_registry* registry;
struct rdp_transport* transport;
};

156
libfreerdp-core/registry.c Normal file
View File

@ -0,0 +1,156 @@
/**
* FreeRDP: A Remote Desktop Protocol Client
* Configuration Registry
*
* Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "registry.h"
static uint8 registry_dir[] = "freerdp";
static uint8 registry_file[] = "config.txt";
REG_ENTRY resolution =
{
REG_TYPE_STRING, "resolution", 8, "1024x768"
};
REG_ENTRY fast_path =
{
REG_TYPE_BOOLEAN, "fast_path", 1, "1"
};
REG_ENTRY performance_flags =
{
REG_TYPE_INTEGER, "performance_flags", 4, "0xFFFF"
};
REG_SECTION root =
{
REG_TYPE_SECTION, "root", 0, NULL
};
void registry_print_entry(REG_ENTRY* entry)
{
uint8* value;
value = (uint8*) entry->value;
printf("%s = %s\n", entry->name, value);
}
void registry_print_section(REG_SECTION* section)
{
printf("[%s]\n", section->name);
registry_print_entry(&resolution);
registry_print_entry(&fast_path);
registry_print_entry(&performance_flags);
}
void registry_print(rdpRegistry* registry)
{
registry_print_section(registry->root);
}
void registry_create(rdpRegistry* registry)
{
registry->fp = fopen(registry->file, "w+");
}
void registry_load(rdpRegistry* registry)
{
registry->fp = fopen(registry->file, "r+");
}
void registry_open(rdpRegistry* registry)
{
struct stat stat_info;
if (stat(registry->file, &stat_info) != 0)
registry_create(registry);
else
registry_load(registry);
}
void registry_close(rdpRegistry* registry)
{
if (registry->fp != NULL)
fclose(registry->fp);
}
void registry_init(rdpRegistry* registry)
{
int length;
char* home_path;
struct stat stat_info;
home_path = getenv("HOME");
registry->available = True;
if (home_path == NULL)
{
printf("could not get home path\n");
registry->available = False;
return;
}
length = strlen(home_path);
registry->home = (uint8*) xmalloc(length);
memcpy(registry->home, home_path, length);
printf("home path: %s\n", registry->home);
registry->path = (uint8*) xmalloc(length + sizeof(registry_dir) + 2);
sprintf(registry->path, "%s/.%s", registry->home, registry_dir);
printf("registry path: %s\n", registry->path);
if (stat(registry->path, &stat_info) != 0)
{
mkdir(registry->path, S_IRUSR | S_IWUSR | S_IXUSR);
printf("creating directory %s\n", registry->path);
}
length = strlen(registry->path);
registry->file = (uint8*) xmalloc(length + sizeof(registry_file) + 1);
sprintf(registry->file, "%s/%s", registry->path, registry_file);
printf("registry file: %s\n", registry->file);
registry_open(registry);
registry_print(registry);
}
rdpRegistry* registry_new(rdpSettings* settings)
{
rdpRegistry* registry = (rdpRegistry*) xzalloc(sizeof(rdpRegistry));
if (registry != NULL)
{
registry->root = &root;
registry->settings = settings;
registry_init(registry);
}
return registry;
}
void registry_free(rdpRegistry* registry)
{
if (registry != NULL)
{
registry_close(registry);
xfree(registry->path);
xfree(registry->file);
xfree(registry->home);
xfree(registry);
}
}

View File

@ -0,0 +1,68 @@
/**
* FreeRDP: A Remote Desktop Protocol Client
* Configuration Registry
*
* Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __REGISTRY_H
#define __REGISTRY_H
typedef struct rdp_registry rdpRegistry;
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <freerdp/freerdp.h>
#include <freerdp/settings.h>
#include <freerdp/utils/memory.h>
enum REG_TYPE
{
REG_TYPE_STRING,
REG_TYPE_INTEGER,
REG_TYPE_BOOLEAN,
REG_TYPE_SECTION
};
typedef struct
{
uint8 type;
uint8* name;
uint32 length;
void* value;
} REG_ENTRY;
typedef REG_ENTRY REG_SECTION;
struct rdp_registry
{
FILE* fp;
uint8* path;
uint8* file;
uint8* home;
boolean available;
REG_SECTION* root;
struct rdp_settings* settings;
};
void registry_open(rdpRegistry* registry);
void registry_close(rdpRegistry* registry);
void registry_init(rdpRegistry* registry);
rdpRegistry* registry_new(rdpSettings* settings);
void registry_free(rdpRegistry* registry);
#endif /* __REGISTRY_H */