00001 /******************************************************************** 00002 * 00003 * Copyright (c) 1999-2008 ACCESS CO., LTD. All rights reserved. 00004 * Copyright 2006, 2007, ACCESS Systems Americas, Inc. All rights reserved. 00005 * 00006 * Version: MPL 1.1/LGPL 2.1 00007 * 00008 * The contents of this file are subject to the Mozilla Public License Version 00009 * 1.1 (the "License"); you may not use this file except in compliance with 00010 * the License. You may obtain a copy of the License at 00011 * http://www.mozilla.org/MPL/ 00012 * 00013 * Software distributed under the License is distributed on an "AS IS" basis, 00014 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 00015 * for the specific language governing rights and limitations under the 00016 * License. 00017 * 00018 * The Original Code is hikerproject.org code. 00019 * 00020 * The Initial Developer of the Original Code is ACCESS Systems Americas, Inc. 00021 * Portions created by the Initial Developer are 00022 * Copyright 2006-2007 the Initial Developer. All Rights Reserved. 00023 * 00024 * Contributor(s): 00025 * 00026 * Alternatively, the contents of this file may be used under the terms of 00027 * the GNU Lesser General Public License Version 2.1 (the "LGPL"), in which 00028 * case the provisions of the LGPL are applicable instead of those above. 00029 * If you wish to allow use of your version of this file only under the terms 00030 * of the LGPL, and not to allow others to use your version of this file under 00031 * the terms of the MPL, indicate your decision by deleting the provisions 00032 * above and replace them with the notice and other provisions required by 00033 * the LGPL. If you do not delete the provisions above, a recipient may use 00034 * your version of this file under the terms of either the MPL or the LGPL. 00035 * You may obtain a copy of the LGPL at http://www.gnu.org/licenses/lgpl.txt. 00036 * 00037 ********************************************************************/ 00045 #ifndef ALP_SETTINGS_H_ 00046 #define ALP_SETTINGS_H_ 1 00047 00048 #ifdef __cplusplus 00049 extern "C" { 00050 #endif 00051 00058 #include <glib.h> 00059 00060 #include <hiker/config.h> 00061 #include <hiker/sysclass.h> 00062 #include <hiker/types.h> 00063 #include <sys/types.h> /* for mode_t */ 00064 00065 #define ALP_SETTINGS_RPC 00066 /* functions labelled with ALP_SETTINGS_RPC invokes remote operations to the server */ 00067 00068 #define ALP_SETTINGS_VERSION 1 00069 00070 #define SETTINGS_APP_ID "com.access.sys.settings" 00071 #define SETTINGS_CHANNEL_NAME "alp settings" 00072 #define SETTINGS_TIMEOUT 500000 00073 00074 00075 /* for key change notification via the Notification Manager */ 00076 00077 #define ALP_NOTIFY_EVENT_SETTINGS_KEY_CHANGE "/alp/settings/keychange" 00078 00079 /* status constants */ 00080 00081 #define ALP_STATUS_SETTINGS_ERROR ((alp_status_t) ALP_CLASS_SETTINGS | 0x00010000) 00082 #define ALP_STATUS_SETTINGS_KEY_NOT_FOUND ((alp_status_t) ALP_CLASS_SETTINGS | 0x00020000) 00083 #define ALP_STATUS_SETTINGS_VALUE_NOT_FOUND ((alp_status_t) ALP_CLASS_SETTINGS | 0x00030000) 00084 #define ALP_STATUS_SETTINGS_ENTRY_ITERATOR_AT_END ((alp_status_t) ALP_CLASS_SETTINGS | 0x00040000) 00085 #define ALP_STATUS_SETTINGS_ENTRY_ITERATOR_INVALID ((alp_status_t) ALP_CLASS_SETTINGS | 0x00050000) 00086 #define ALP_STATUS_SETTINGS_VALUE_NOT_DIR ((alp_status_t) ALP_CLASS_SETTINGS | 0x00060000) 00087 #define ALP_STATUS_SETTINGS_INCORRECT_TYPE ((alp_status_t) ALP_CLASS_SETTINGS | 0x00070000) 00088 #define ALP_STATUS_SETTINGS_ENTRY_INVALID ((alp_status_t) ALP_CLASS_SETTINGS | 0x00080000) 00089 #define ALP_STATUS_SETTINGS_VALUE_INVALID ((alp_status_t) ALP_CLASS_SETTINGS | 0x00090000) 00090 #define ALP_STATUS_SETTINGS_ARGUMENT_INVALID ((alp_status_t) ALP_CLASS_SETTINGS | 0x000a0000) 00091 #define ALP_STATUS_SETTINGS_BUFFER_TOO_SMALL ((alp_status_t) ALP_CLASS_SETTINGS | 0x000b0000) 00092 #define ALP_STATUS_SETTINGS_PERMISSION_DENIED ((alp_status_t) ALP_CLASS_SETTINGS | 0x000c0000) 00093 #define ALP_STATUS_SETTINGS_KEY_EXISTS ((alp_status_t) ALP_CLASS_SETTINGS | 0x000d0000) 00094 #define ALP_STATUS_SETTINGS_VERSION_MISMATCH ((alp_status_t) ALP_CLASS_SETTINGS | 0x000e0000) 00095 #define ALP_STATUS_SETTINGS_STORAGE_FULL ((alp_status_t) ALP_CLASS_SETTINGS | 0x00200000) 00096 00097 00098 /* Vault Service defined Error Codes */ 00099 #define ALP_STATUS_SETTINGS_VS_INPUT_PARAM_BAD (ALP_CLASS_SETTINGS | 0x000f0000 ) /* Input parameter \c NULL or out of range */ 00100 #define ALP_STATUS_SETTINGS_VS_OUTPUT_PARAM_BAD (ALP_CLASS_SETTINGS | 0x00100000 ) /* Output parameter Contents of Ptr to Ptr not \c NULL, 00101 still points to data, or No output object passed */ 00102 #define ALP_STATUS_SETTINGS_VS_ENC_UNDEFINED (ALP_CLASS_SETTINGS | 0x00110000 ) /* Undefined/Not Supported Encryption Algorithm */ 00103 #define ALP_STATUS_SETTINGS_VS_MAC_UNDEFINED (ALP_CLASS_SETTINGS | 0x00120000 ) /* Undefined/Not Supported Hash Algoritm */ 00104 #define ALP_STATUS_SETTINGS_VS_BLOB_MAC_BAD (ALP_CLASS_SETTINGS | 0x00130000 ) /* Could not recreate Blob MAC, bad Key or corrupted data */ 00105 #define ALP_STATUS_SETTINGS_VS_BLOB_SIZE_BAD (ALP_CLASS_SETTINGS | 0x00140000 ) /* Crypto Blob size does not match Total Size header value */ 00106 #define ALP_STATUS_SETTINGS_VS_BLOB_EXPORT_BAD (ALP_CLASS_SETTINGS | 0x00150000 ) /* Crypto Blob is Export restricted by header value */ 00107 #define ALP_STATUS_SETTINGS_VS_BLOB_HDR_BAD (ALP_CLASS_SETTINGS | 0x00160000 ) /* Crypto Blob wrong Header format */ 00108 #define ALP_STATUS_SETTINGS_VS_BLOB_KEY_BAD (ALP_CLASS_SETTINGS | 0x00170000 ) /* Wrong Key Type/Size for Blob */ 00109 #define ALP_STATUS_SETTINGS_VS_PAYLOAD_SIZE_BAD (ALP_CLASS_SETTINGS | 0x00180000) /* Encrypted Payload size not a multiple of Enc Alg block */ 00110 #define ALP_STATUS_SETTINGS_VS_DATA_SIZE_BAD (ALP_CLASS_SETTINGS | 0x00190000 ) /* Data size out of bounds of Payload size */ 00111 #define ALP_STATUS_SETTINGS_VS_RAND_BAD (ALP_CLASS_SETTINGS | 0x001A0000 ) /* Bad Random Number Generation */ 00112 #define ALP_STATUS_SETTINGS_VS_OPENSSL_BAD (ALP_CLASS_SETTINGS | 0x001B0000 ) /* OpenSSL call failure */ 00113 #define ALP_STATUS_SETTINGS_VS_MASTER_BAD (ALP_CLASS_SETTINGS | 0x001C0000 ) /* Master Key is not Initialized */ 00114 00115 /* note that non-Vault mgr Global Settings error code starts from 0x00200000 again; see ALP_STATUS_SETTINGS_STORAGE_FULL above */ 00116 00117 00118 // 00119 // Value types 00120 // 00121 00125 typedef enum { 00126 ALP_SETTINGS_TYPE_INVALID = 0, 00127 ALP_SETTINGS_TYPE_STRING, 00128 ALP_SETTINGS_TYPE_INT, 00129 ALP_SETTINGS_TYPE_FLOAT, 00130 ALP_SETTINGS_TYPE_BOOL, 00131 ALP_SETTINGS_TYPE_LIST, 00132 ALP_SETTINGS_TYPE_DIR, 00133 ALP_SETTINGS_TYPE_BLOB, 00134 } AlpSettingsValueType; 00135 00136 00137 // 00138 // Get multiple filters 00139 // 00140 typedef enum { 00141 ALP_SETTINGS_FILTER_NONE = 0x0, 00142 ALP_SETTINGS_FILTER_DIR = 0x1, 00143 ALP_SETTINGS_FILTER_NORMAL = 0x2, 00144 ALP_SETTINGS_FILTER_DEFAULT = 0x4, 00145 ALP_SETTINGS_FILTER_ALL = ~0 00146 } AlpSettingsFilters; 00173 // 00174 // Opaque typedef's 00175 // 00176 00180 typedef struct _AlpSettingsContext AlpSettingsContext; 00181 00182 00188 typedef struct _AlpSettingsValue AlpSettingsValue ; 00189 struct _AlpSettingsValue 00190 { 00191 AlpSettingsValueType type; 00192 union 00193 { 00194 int int_value; 00195 double float_value; 00196 gboolean bool_value; 00197 GList *list_value; 00198 GString *string_value; 00199 GByteArray blob_value; 00200 } ; 00201 00202 } ; 00203 00204 00205 #define SETTINGS_VALUE_INITIALIZER { ALP_SETTINGS_TYPE_INVALID, { 0 } } 00206 00212 typedef struct _AlpSettingsEntry AlpSettingsEntry ; 00213 struct _AlpSettingsEntry 00214 { 00215 GString *key; 00216 AlpSettingsValue value; 00217 mode_t mode; 00218 alp_status_t status; 00219 00220 00221 } ; 00222 00223 00227 typedef struct _AlpSettingsEntryIterator AlpSettingsEntryIterator ; 00228 00229 00230 00238 AlpSettingsEntry*alp_settings_entry_alloc(void); 00239 00246 void alp_settings_entry_free(AlpSettingsEntry *e); 00247 00248 00254 AlpSettingsValue *alp_settings_value_alloc(void); 00255 00256 00263 void alp_settings_value_free(AlpSettingsValue *e); 00264 00265 00266 00273 void alp_settings_value_clean(AlpSettingsValue *e); 00274 00275 00276 00283 void alp_settings_value_list_free(GList *l); 00284 00285 00292 void alp_settings_entry_list_free(GList *list); 00293 00302 alp_status_t 00303 alp_settings_init(void); 00304 00305 00306 00317 alp_status_t 00318 alp_settings_open(AlpSettingsContext **context); 00319 00328 alp_status_t 00329 alp_settings_close(AlpSettingsContext *context); 00330 00339 ALP_SETTINGS_RPC 00340 alp_status_t 00341 alp_settings_begin_transaction(AlpSettingsContext *context); 00342 00352 ALP_SETTINGS_RPC 00353 alp_status_t 00354 alp_settings_complete_transaction(AlpSettingsContext *context); 00355 00356 00366 ALP_SETTINGS_RPC 00367 alp_status_t 00368 alp_settings_cancel_transaction(AlpSettingsContext *context); 00369 00370 00382 alp_status_t 00383 alp_settings_set_cwd(AlpSettingsContext *context, const char *cwd); 00384 00385 00399 alp_status_t 00400 alp_settings_get_cwd(AlpSettingsContext *context, char *buf, size_t buf_size); 00401 00412 ALP_SETTINGS_RPC 00413 alp_status_t 00414 alp_settings_set_default_mode(AlpSettingsContext *context, mode_t mode); 00415 00416 00427 ALP_SETTINGS_RPC 00428 alp_status_t 00429 alp_settings_get_default_mode(AlpSettingsContext *context, mode_t *mode); 00430 00441 ALP_SETTINGS_RPC 00442 alp_status_t 00443 alp_settings_set_default_gid(AlpSettingsContext *context, gid_t gid); 00444 00455 ALP_SETTINGS_RPC 00456 alp_status_t 00457 alp_settings_get_default_gid(AlpSettingsContext *context, gid_t *gid); 00458 00459 00470 ALP_SETTINGS_RPC 00471 alp_status_t 00472 alp_settings_set_default_uid(AlpSettingsContext *context, uid_t uid); 00473 00474 00485 ALP_SETTINGS_RPC 00486 alp_status_t 00487 alp_settings_get_default_uid(AlpSettingsContext *context, uid_t *uid); 00488 00489 00490 00491 00504 ALP_SETTINGS_RPC 00505 alp_status_t 00506 alp_settings_set_mode(AlpSettingsContext *context, const char *key, mode_t mode); 00507 00508 00521 ALP_SETTINGS_RPC 00522 alp_status_t 00523 alp_settings_get_mode(AlpSettingsContext *context, const char *key, mode_t *mode); 00524 00537 ALP_SETTINGS_RPC 00538 alp_status_t 00539 alp_settings_set_uid(AlpSettingsContext *context, const char *key, uid_t id); 00540 00541 00554 ALP_SETTINGS_RPC 00555 alp_status_t 00556 alp_settings_get_uid(AlpSettingsContext *context, const char *key, uid_t *id); 00557 00558 00571 ALP_SETTINGS_RPC 00572 alp_status_t 00573 alp_settings_set_gid(AlpSettingsContext *context, const char *key, gid_t id); 00574 00575 00588 ALP_SETTINGS_RPC 00589 alp_status_t 00590 alp_settings_get_gid(AlpSettingsContext *context, const char *key, gid_t *id); 00591 00592 00593 00594 00595 00610 ALP_SETTINGS_RPC 00611 alp_status_t 00612 alp_settings_set( AlpSettingsContext *context, 00613 const char *key, 00614 const AlpSettingsValue *value); 00615 00628 ALP_SETTINGS_RPC 00629 alp_status_t 00630 alp_settings_get( AlpSettingsContext *context, 00631 const char *key, 00632 AlpSettingsValue *value); 00633 00634 00647 ALP_SETTINGS_RPC 00648 alp_status_t 00649 alp_settings_delete( AlpSettingsContext *context, 00650 const char *key); // revert to default if there is one 00651 00652 00665 ALP_SETTINGS_RPC 00666 alp_status_t 00667 alp_settings_delete_tree( AlpSettingsContext *context, 00668 const char *key); 00669 00670 00683 ALP_SETTINGS_RPC 00684 alp_status_t 00685 alp_settings_delete_tree_keeping_defaults( AlpSettingsContext *context, 00686 const char *key); 00687 00688 00720 ALP_SETTINGS_RPC 00721 alp_status_t 00722 alp_settings_get_multiple_by_glob(AlpSettingsContext *context, 00723 const char *key_glob, 00724 GList **entries); 00725 00726 00756 ALP_SETTINGS_RPC 00757 alp_status_t 00758 alp_settings_get_multiple_by_glob_full (AlpSettingsContext *context, 00759 const char *key_glob, 00760 const uint32_t filters, 00761 GList **entries); 00762 00775 ALP_SETTINGS_RPC 00776 alp_status_t 00777 alp_settings_set_multiple(AlpSettingsContext *context, 00778 GList *entries); 00779 00780 00781 00794 ALP_SETTINGS_RPC 00795 alp_status_t 00796 alp_settings_get_type( AlpSettingsContext *context, 00797 const char *key, 00798 AlpSettingsValueType *type); 00799 00800 00813 ALP_SETTINGS_RPC 00814 alp_status_t 00815 alp_settings_get_value_size( AlpSettingsContext *context, 00816 const char *key, 00817 size_t *size); 00818 00819 00820 00831 ALP_SETTINGS_RPC 00832 alp_status_t 00833 alp_settings_set_notification_on_off(AlpSettingsContext *context, int on_off); 00834 00835 00849 ALP_SETTINGS_RPC 00850 alp_status_t 00851 alp_settings_findkeys_start( AlpSettingsContext *context, 00852 const char *dir_path, 00853 AlpSettingsEntryIterator **iterator); 00854 00855 00856 00868 alp_status_t 00869 alp_settings_findkeys_next(AlpSettingsEntryIterator *iterator); 00870 00881 alp_status_t 00882 alp_settings_findkeys_end(AlpSettingsEntryIterator *iterator); 00883 00884 00896 alp_status_t 00897 alp_settings_findkeys_get_key(AlpSettingsEntryIterator *iterator, 00898 char *key, 00899 unsigned int key_size); 00900 00901 00914 alp_status_t 00915 alp_settings_entry_get_key_value(const AlpSettingsEntry *entry, 00916 char *key, 00917 unsigned int key_size, 00918 AlpSettingsValue *value); 00919 00920 00933 alp_status_t 00934 alp_settings_entry_set_key_value(AlpSettingsEntry *entry, 00935 const char *key, 00936 const AlpSettingsValue *value); 00937 00938 00939 00948 alp_status_t 00949 alp_settings_value_set_string(AlpSettingsValue *value, 00950 const char *string); 00951 00952 00953 00962 alp_status_t 00963 alp_settings_value_set_int(AlpSettingsValue *value, 00964 int i); 00965 00966 00967 00976 alp_status_t 00977 alp_settings_value_set_float(AlpSettingsValue *value, 00978 double f); 00979 00980 00981 00990 alp_status_t 00991 alp_settings_value_set_bool(AlpSettingsValue *value, 00992 gboolean b); 00993 00994 00995 01004 alp_status_t 01005 alp_settings_value_set_list(AlpSettingsValue *value, 01006 const GList *list); 01007 01008 01009 01010 01022 alp_status_t 01023 alp_settings_value_get_string(AlpSettingsValue *value, 01024 char *string, 01025 unsigned int string_size); 01026 01027 01028 01039 alp_status_t 01040 alp_settings_value_get_int(AlpSettingsValue *value, 01041 int *i); 01042 01043 01044 01055 alp_status_t 01056 alp_settings_value_get_float(AlpSettingsValue *value, 01057 double *f); 01058 01059 01060 01071 alp_status_t 01072 alp_settings_value_get_bool(AlpSettingsValue *value, 01073 gboolean *b); 01074 01075 01076 01088 alp_status_t 01089 alp_settings_value_get_list(AlpSettingsValue *value, 01090 GList **list); 01091 01092 01093 01109 alp_status_t 01110 alp_settings_get_key_string_value(AlpSettingsContext *context, 01111 const char *key, 01112 char *value, 01113 unsigned int value_size); 01114 01115 01127 alp_status_t 01128 alp_settings_set_key_string_value(AlpSettingsContext *context, 01129 const char *key, 01130 const char *value); 01131 01132 01133 01146 alp_status_t 01147 alp_settings_get_key_bool_value(AlpSettingsContext *context, 01148 const char *key, 01149 gboolean *value); 01150 01162 alp_status_t 01163 alp_settings_set_key_bool_value(AlpSettingsContext *context, 01164 const char *key, 01165 gboolean value); 01166 01167 01168 01182 alp_status_t 01183 alp_settings_get_key_int_value(AlpSettingsContext *context, 01184 const char *key, 01185 int *value); 01186 01198 alp_status_t 01199 alp_settings_set_key_int_value(AlpSettingsContext *context, 01200 const char *key, 01201 int value); 01202 01203 01204 01218 alp_status_t 01219 alp_settings_get_key_float_value(AlpSettingsContext *context, 01220 const char *key, 01221 double *value); 01222 01223 01224 01235 alp_status_t 01236 alp_settings_set_key_float_value(AlpSettingsContext *context, 01237 const char *key, 01238 double value); 01239 01240 01241 01242 01259 alp_status_t 01260 alp_settings_get_key_blob_value(AlpSettingsContext *context, 01261 const char *key, 01262 char *value, 01263 int buffer_size, 01264 int * value_size); 01265 01277 alp_status_t 01278 alp_settings_set_key_blob_value(AlpSettingsContext *context, 01279 const char *key, 01280 const char *value, 01281 int value_size); 01282 01283 01296 alp_status_t 01297 alp_settings_set_key_directory(AlpSettingsContext *context, 01298 const char *key); 01299 01311 ALP_SETTINGS_RPC 01312 alp_status_t 01313 alp_settings_import_from_file(AlpSettingsContext *context, 01314 const char *file); 01315 01329 ALP_SETTINGS_RPC 01330 alp_status_t 01331 alp_settings_list_keys( AlpSettingsContext *context, const gchar *pattern, AlpSettingsEntryIterator **iterator); 01332 01333 01340 const char * 01341 alp_settings_errmsg(alp_status_t error); 01342 01346 01351 typedef struct _AlpSettingsCryptoAttributes AlpSettingsCryptoAttributes; 01352 struct _AlpSettingsCryptoAttributes 01353 { 01354 uint32_t export_mask; 01355 uint32_t payload_type; 01356 uint32_t enc_alg_type; 01357 uint32_t mac_alg_type; 01358 }; 01359 01360 01369 alp_status_t alp_settings_set_crypto_attributes(AlpSettingsContext *context, const AlpSettingsCryptoAttributes *crypto_attributes); 01370 01371 // alp_status_t alp_settings_get_crypto_attributes(AlpSettingsContext *context, AlpSettingsCryptoAttributes *crypto_attributes); 01372 01374 extern const AlpSettingsCryptoAttributes ALP_SETTINGS_CRYPTO_ATTR_DEFAULT_STRUCT; 01375 extern const AlpSettingsCryptoAttributes ALP_SETTINGS_CRYPTO_ATTR_NONE_STRUCT; 01376 extern const AlpSettingsCryptoAttributes ALP_SETTINGS_CRYPTO_ATTR_OFF_STRUCT; 01379 01380 #define ALP_SETTINGS_CRYPTO_ATTR_DEFAULT (&ALP_SETTINGS_CRYPTO_ATTR_DEFAULT_STRUCT) 01381 01382 #define ALP_SETTINGS_CRYPTO_ATTR_NONE (&ALP_SETTINGS_CRYPTO_ATTR_NONE_STRUCT) 01383 01384 #define ALP_SETTINGS_CRYPTO_ATTR_OFF (&ALP_SETTINGS_CRYPTO_ATTR_OFF_STRUCT) 01385 01387 01392 #ifdef __cplusplus 01393 } // extern "C" 01394 #endif 01395 01396 #endif // #ifndef ALP_SETTINGS_H_
Copyright © 1999-2008 ACCESS CO., LTD. All rights reserved.