2 Unix SMB/CIFS implementation.
4 Copyright (C) Jelmer Vernooij 2004.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "lib/registry/common/registry.h"
23 #include <gconf/gconf-client.h>
25 static BOOL reg_open_gconf(REG_HANDLE *h, const char *location, BOOL try_complete_load)
27 h->backend_data = (void *)gconf_client_get_default();
31 static BOOL reg_close_gconf(REG_HANDLE *h)
36 static REG_KEY *gconf_open_key (REG_HANDLE *h, const char *name)
39 char *fullpath = reg_path_win2unix(strdup(name));
41 /* Check if key exists */
42 if(!gconf_client_dir_exists((GConfClient *)h->backend_data, fullpath, NULL)) {
46 ret = reg_key_new_abs(name, h, NULL);
47 ret->backend_data = talloc_strdup(ret->mem_ctx, fullpath);
53 static BOOL gconf_fetch_values(REG_KEY *p, int *count, REG_VAL ***vals)
57 REG_VAL **ar = talloc(p->mem_ctx, sizeof(REG_VAL *));
58 char *fullpath = p->backend_data;
59 cur = entries = gconf_client_all_entries((GConfClient*)p->handle->backend_data, fullpath, NULL);
63 GConfEntry *entry = cur->data;
64 GConfValue *value = gconf_entry_get_value(entry);
65 REG_VAL *newval = reg_val_new(p, NULL);
66 newval->name = talloc_strdup(newval->mem_ctx, strrchr(gconf_entry_get_key(entry), '/')+1);
69 case GCONF_VALUE_INVALID:
70 newval->data_type = REG_NONE;
73 case GCONF_VALUE_STRING:
74 newval->data_type = REG_SZ;
75 newval->data_blk = talloc_strdup(newval->mem_ctx, gconf_value_get_string(value));
76 newval->data_len = strlen(newval->data_blk);
80 newval->data_type = REG_DWORD;
81 newval->data_blk = talloc(newval->mem_ctx, sizeof(long));
82 *((long *)newval->data_blk) = gconf_value_get_int(value);
83 newval->data_len = sizeof(long);
86 case GCONF_VALUE_FLOAT:
87 newval->data_blk = talloc(newval->mem_ctx, sizeof(double));
88 newval->data_type = REG_BINARY;
89 *((double *)newval->data_blk) = gconf_value_get_float(value);
90 newval->data_len = sizeof(double);
93 case GCONF_VALUE_BOOL:
94 newval->data_blk = talloc(newval->mem_ctx, sizeof(BOOL));
95 newval->data_type = REG_BINARY;
96 *((BOOL *)newval->data_blk) = gconf_value_get_bool(value);
97 newval->data_len = sizeof(BOOL);
101 newval->data_type = REG_NONE;
102 DEBUG(0, ("Not implemented..\n"));
105 } else newval->data_type = REG_NONE;
107 ar[(*count)] = newval;
108 ar = talloc_realloc(p->mem_ctx, ar, sizeof(REG_VAL *) * ((*count)+2));
114 g_slist_free(entries);
119 static BOOL gconf_fetch_subkeys(REG_KEY *p, int *count, REG_KEY ***subs)
123 REG_KEY **ar = malloc(sizeof(REG_KEY *));
124 char *fullpath = p->backend_data;
125 cur = dirs = gconf_client_all_dirs((GConfClient*)p->handle->backend_data, fullpath,NULL);
129 ar[(*count)] = reg_key_new_abs(reg_path_unix2win((char *)cur->data), p->handle,NULL);
130 ar[(*count)]->backend_data = talloc_strdup(ar[*count]->mem_ctx, cur->data);
131 ar = realloc(ar, sizeof(REG_KEY *) * ((*count)+2));
142 static BOOL gconf_update_value(REG_VAL *val, int type, void *data, int len)
144 GError *error = NULL;
145 char *keypath = val->backend_data;
147 if(val->name)asprintf(&valpath, "%s/%s", keypath, val->name);
148 else valpath = strdup(keypath);
153 gconf_client_set_string((GConfClient *)val->handle->backend_data, valpath, data, &error);
155 return (error == NULL);
158 gconf_client_set_int((GConfClient *)val->handle->backend_data, valpath,
159 *((int *)data), &error);
161 return (error == NULL);
163 DEBUG(0, ("Unsupported type: %d\n", type));
170 static REG_OPS reg_backend_gconf = {
172 .open_registry = reg_open_gconf,
173 .close_registry = reg_close_gconf,
174 .open_key = gconf_open_key,
175 .fetch_subkeys = gconf_fetch_subkeys,
176 .fetch_values = gconf_fetch_values,
177 .update_value = gconf_update_value,
180 * since GConf uses schemas for what keys and values are allowed, there
181 * is no way of 'emulating' add_key and del_key here.
185 NTSTATUS reg_gconf_init(void)
187 return register_backend("registry", ®_backend_gconf);