From 8bcc17cce742412499493719b2b4f11a980a1f17 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Bollo?= Date: Thu, 22 Jan 2015 15:06:55 +0100 Subject: [PATCH] Adding a fallback to vconftool MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This patch allows the creation of images when buxton is used. During the process of creating the images, the serveur buxton is not started. Unfortunately, the client library of buxton dont allow a fall back to the direct access of the databases. This patch fallback to use the command vconftool that works even when the server buxton is off. See https://github.com/sofar/buxton/issues/144 Change-Id: I89e68deda827ef79670250134badcaf2106d2223 Signed-off-by: José Bollo --- CMakeLists.txt | 1 + src/ail_desktop.c | 8 +-- src/ail_sql.c | 4 +- src/ail_vconf.c | 165 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/ail_vconf.h | 41 ++++++++++++++ 5 files changed, 213 insertions(+), 6 deletions(-) create mode 100644 src/ail_vconf.c create mode 100644 src/ail_vconf.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 0199c7d..4e9502f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,6 +23,7 @@ SET(SRCS src/ail_package.c src/ail_desktop.c src/ail_convert.c + src/ail_vconf.c ) INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include) diff --git a/src/ail_desktop.c b/src/ail_desktop.c index 48f7d3d..1e666cc 100755 --- a/src/ail_desktop.c +++ b/src/ail_desktop.c @@ -33,7 +33,6 @@ #include #include -#include #include #include #include @@ -42,6 +41,7 @@ #include "ail_db.h" #include "ail_sql.h" #include "ail.h" +#include "ail_vconf.h" #define BUFSIZE 4096 #define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER) @@ -260,7 +260,7 @@ _get_icon_with_path(char* icon, uid_t uid) /* "db/setting/theme" is not exist */ #if 0 - theme = vconf_get_str("db/setting/theme"); + theme = ail_vconf_get_str("db/setting/theme"); if (!theme) { theme = strdup("default"); if(!theme) { @@ -1581,8 +1581,8 @@ static ail_error_e _send_db_done_noti(noti_type type, const char *package) retv_if(!noti_string, AIL_ERROR_OUT_OF_MEMORY); snprintf(noti_string, size + 1, "%s:%s:%u", type_string, package, getuid()); - vconf_set_str(VCONFKEY_AIL_INFO_STATE, noti_string); - vconf_set_str(VCONFKEY_MENUSCREEN_DESKTOP, noti_string); // duplicate, will be removed + ail_vconf_set_str(VCONFKEY_AIL_INFO_STATE, noti_string); + ail_vconf_set_str(VCONFKEY_MENUSCREEN_DESKTOP, noti_string); // duplicate, will be removed _D("Noti : %s", noti_string); free(noti_string); diff --git a/src/ail_sql.c b/src/ail_sql.c index bd24355..708eccc 100755 --- a/src/ail_sql.c +++ b/src/ail_sql.c @@ -27,7 +27,7 @@ #include "ail.h" #include "ail_sql.h" #include "ail_db.h" -#include "vconf.h" +#include "ail_vconf.h" #include "ail_private.h" static const char *filter[] = { @@ -77,7 +77,7 @@ inline char *sql_get_locale(void) char *r; char buf[6]; - retv_if ((l = vconf_get_str(VCONFKEY_LANGSET)) == NULL, NULL); + retv_if ((l = ail_vconf_get_str(VCONFKEY_LANGSET)) == NULL, NULL); snprintf(buf, sizeof(buf), "%s", l); free(l); diff --git a/src/ail_vconf.c b/src/ail_vconf.c new file mode 100644 index 0000000..8fa3088 --- /dev/null +++ b/src/ail_vconf.c @@ -0,0 +1,165 @@ +/* + * ail + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Jayoun Lee , Sewook Park , Jaeho Lee + * + * 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. + * + */ + +#if !defined(NO_VCONF_BUXTON_FALLBACK) + +#define _GNU_SOURCE +#include +#include +#include +#include + +#include +#include "ail_vconf.h" + +#define VCONFTOOL "/usr/bin/vconftool" +#define CMD_VCONF_GET_STR VCONFTOOL " -q get '%s'" +#define CMD_VCONF_SET_STR VCONFTOOL " -q set -t string '%s' '%s' -f" + +/* + + Reads the content of the input 'stream' (it should be a text without nul +characters) in a feshly allocated buffer, using allocations of 'block_size' +increment. + + Returns the read string or NULL in case of error. +*/ +static char *_pread_(FILE *stream, size_t block_size) +{ + char *result = NULL; + size_t alloc = 0; + size_t length = 0; + char *string; + + for(;;) { + /* is on error ? */ + if (ferror(stream) != 0) { + free(result); + return NULL; + } + /* allocate enough memory */ + /* assert(length <= alloc) */ + if (length >= alloc) { + alloc += block_size; + string = realloc(result, alloc + 1); /* one more for ending null */ + if (string == NULL) { + free(result); + return NULL; + } + result = string; + } + /* assert(length < alloc) */ + /* assert(result != NULL); */ + /* is at end ? */ + if (feof(stream) != 0) { + result[length] = 0; + return result; + } + length += fread(result + length, 1, alloc - length, stream); + } +} + +/* + Runs the command given by 'cmddef' and its arguments formated as printf. + + The resulting output stream of the command is return as a freshly allocated +string in '*readen'. + + Retruns 0 in case of success or -1 in case of error. +*/ +static int _ail_vconf_exec_(char **readen, const char *cmddef, ...) +{ + int result; + FILE *stream; + char *command; + va_list ap; + + *readen = NULL; + va_start(ap, cmddef); + result = vasprintf(&command, cmddef, ap); + va_end(ap); + if (result >= 0) { + result = -1; + stream = popen(command, "r"); + if (stream != NULL) { + *readen = _pread_(stream, 1024); + if (pclose(stream) != -1 && *readen != NULL) { + result = 0; + } + } + free(command); + } + return result; +} + +/* + vconf_get_str with fallback to the command vconftool. +*/ +char *ail_vconf_get_str(const char *keyname) +{ + char *result; + char *data; + int status; + size_t length; + + result = vconf_get_str(keyname); + if (result == NULL) { + status = _ail_vconf_exec_(&data, CMD_VCONF_GET_STR, keyname); + if (status == 0) { + /* the string data is of the form 'key, value = ...\n' */ + result = strstr(data, " = "); + if (result != NULL) { + /* skips the prefix " = " */ + result = result + 3; + /* remove trailing '\n' */ + length = strlen(result); + if (length > 0 && result[length-1] == '\n') { + result[length-1] = 0; + } + /* get the final result */ + result = strdup(result); + } + } + free(data); + } + return result; +} + +/* + vconf_set_str with fallback to the command vconftool. +*/ +int ail_vconf_set_str(const char *keyname, const char *strval) +{ + int result; + char *data; + + result = vconf_set_str(keyname, strval); + if (result != 0) { + result = _ail_vconf_exec_(&data, CMD_VCONF_SET_STR, keyname, strval); + free(data); + } + return result; +} + +#endif + + + diff --git a/src/ail_vconf.h b/src/ail_vconf.h new file mode 100644 index 0000000..571b310 --- /dev/null +++ b/src/ail_vconf.h @@ -0,0 +1,41 @@ +/* + * ail + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Jayoun Lee , Sewook Park , Jaeho Lee + * + * 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 __AIL_VCONF_H__ +#define __AIL_VCONF_H__ + +#include + +#if !defined(NO_VCONF_BUXTON_FALLBACK) + +char *ail_vconf_get_str(const char *keyname); +int ail_vconf_set_str(const char *keyname, const char *strval); + +#else + +#define ail_vconf_get_str vconf_get_str +#define ail_vconf_set_str vconf_set_str + +#endif + +#endif + -- 2.7.4