#include "ad_gk.h" void ListKeyringsCb (GnomeKeyringResult result, GList *keyrings, gpointer data) { GList *l = NULL; char *name = NULL; GList **retList = data; GetKeyringsCbData *cbData = data; GMainLoop *loop = cbData->loop; retList = cbData->keyringList; *retList = NULL; if (result != GNOME_KEYRING_RESULT_OK) { g_print ("Unable to get keyring list - %d\n", result); } else { for (l = keyrings; l != NULL; l = l->next) { name = l->data; *retList = g_list_append (*retList, g_strdup (name)); } } g_main_loop_quit (loop); } void KeyringGetInfoCb(GnomeKeyringResult result, GnomeKeyringInfo *info, gpointer data) { GetKeyringInfoCbData *cbData = data; KeyringInfo *retInfo = cbData->info; if (result != GNOME_KEYRING_RESULT_OK) { g_print ("Unable to get keyring info %d\n", result); } else { retInfo->lockOnIdle = gnome_keyring_info_get_lock_on_idle(info); retInfo->lockTimeout = gnome_keyring_info_get_lock_timeout(info); retInfo->mTime = gnome_keyring_info_get_mtime(info); retInfo->cTime = gnome_keyring_info_get_ctime(info); retInfo->isLocked = gnome_keyring_info_get_is_locked(info); } g_main_loop_quit (cbData->loop); } void ListItemCb( GnomeKeyringResult result, GList *list, gpointer data) { GList **retList; GetItemsCbData *cbData = data; retList = cbData->itemList; *retList = NULL; if (result != GNOME_KEYRING_RESULT_OK) { g_print ("Unable to get list of items : %d\n", result); } else { *retList = g_list_copy (list); } g_main_loop_quit (cbData->loop); } void ItemGetInfoCb( GnomeKeyringResult result, GnomeKeyringItemInfo *info, gpointer data) { GetItemInfoCbData *cbData = data; ItemInfo *itemInfo = cbData->info; if (result != GNOME_KEYRING_RESULT_OK) { g_print ("Unable to get Item info: %d\n", result); } else { itemInfo->itemType = gnome_keyring_item_info_get_type(info); strcpy(itemInfo->displayName,gnome_keyring_item_info_get_display_name(info)); strcpy(itemInfo->secret,gnome_keyring_item_info_get_secret(info)); itemInfo->mTime = gnome_keyring_item_info_get_mtime(info); itemInfo->cTime = gnome_keyring_item_info_get_ctime(info); } g_main_loop_quit (cbData->loop); } void ItemGetAttributesCb(GnomeKeyringResult result, GnomeKeyringAttributeList *attributes, gpointer data) { GnomeKeyringAttribute *attrList = NULL; int i = 0; GetAttributeListCbData *cbData = data; Attribute *attr = NULL; GList **retList; retList = cbData->attrList; *retList = NULL; if( result != GNOME_KEYRING_RESULT_OK ) { g_print("Unable to get the attributes of item\n"); } else { attrList = (GnomeKeyringAttribute*)(attributes->data); //GArray has len and data for(i = 0; i < attributes->len; i++ ) { if(attrList[i].type == GNOME_KEYRING_ATTRIBUTE_TYPE_STRING) { attr = (Attribute*)malloc(sizeof(Attribute)); if( NULL != attr ) { memset(attr,0,sizeof(Attribute)); attr->type = 0; attr->key = (char*)malloc(KEY_SIZE); if(attr->key != NULL) strcpy(attr->key,attrList[i].name); attr->value = (char*)malloc(VAL_SIZE); if(attr->value != NULL) strcpy(attr->value,attrList[i].value.string); } } else if(attrList[i].type == GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32) { attr = (Attribute*)malloc(sizeof(Attribute)); if( NULL != attr ) { memset(attr,0,sizeof(Attribute)); attr->type = 0; attr->key = (char*)malloc(KEY_SIZE); if(attr->key != NULL) strcpy(attr->key,attrList[i].name); attr->value = (char*)malloc(VAL_SIZE); if(attr->value != NULL) sprintf(attr->value,"%d",attrList[i].value.integer); } } *retList = g_list_append (*retList, attr); } } g_main_loop_quit (cbData->loop); } int GetKeyrings(GList **keyringList) { GList *l = NULL; GetKeyringsCbData cbData; cbData.loop = g_main_loop_new (NULL, FALSE); cbData.keyringList = keyringList; gnome_keyring_list_keyring_names(ListKeyringsCb,&cbData,NULL); g_main_loop_run(cbData.loop); return SUCCESS; } int GetKeyringInfo(char *keyring,KeyringInfo *info) { GetKeyringInfoCbData cbData; cbData.loop = g_main_loop_new (NULL, FALSE); cbData.info = info; gnome_keyring_get_info(keyring, KeyringGetInfoCb,&cbData, NULL); g_main_loop_run (cbData.loop); return SUCCESS; } int GetItems(char *keyring, GList **itemList) { GList *l = NULL; gint itemId; GetItemsCbData cbData; cbData.loop = g_main_loop_new (NULL, FALSE); cbData.itemList = itemList; gnome_keyring_list_item_ids(keyring, ListItemCb, &cbData, NULL); g_main_loop_run (cbData.loop); return SUCCESS; } int GetItemInfo(char *keyring, int itemId, ItemInfo *info) { GetItemInfoCbData cbData; cbData.loop = g_main_loop_new (NULL, FALSE); cbData.info = info; gnome_keyring_item_get_info (keyring,itemId, ItemGetInfoCb, &cbData, NULL); g_main_loop_run (cbData.loop); return SUCCESS; } int GetAttributeList(char *keyring, int itemId, GList **attrList) { int i = 0; GetAttributeListCbData cbData; cbData.loop = g_main_loop_new (NULL, FALSE); cbData.attrList = attrList; gnome_keyring_item_get_attributes (keyring, itemId, ItemGetAttributesCb, &cbData, NULL); g_main_loop_run (cbData.loop); return SUCCESS; } int FreeAttributeList(GList *attrList) { GList *l; Attribute *attr = NULL; for(l = attrList; l != NULL; l = l->next) { attr = (Attribute*)(l->data); if(attr->key) { free(attr->key); } if(attr->value) { free(attr->value); } } g_list_free(attrList); return SUCCESS; }