diff --git a/c_adlib/ad_gk/native/ad_gk.c b/c_adlib/ad_gk/native/ad_gk.c index ea734c29..095b5a58 100644 --- a/c_adlib/ad_gk/native/ad_gk.c +++ b/c_adlib/ad_gk/native/ad_gk.c @@ -2,6 +2,76 @@ GMainLoop *loop = NULL; +static void +OperationCompletedCb (GnomeKeyringResult result, + gpointer data) +{ + OperationCompleted *cbData = (OperationCompleted *)data; + g_print ("ad_gk.c : Operation %s Completed %d\n", cbData->OperationName, result); + cbData->result = result; + g_main_loop_quit (loop); +} + + +static void +CreateItemCb (GnomeKeyringResult result, + guint32 id, + gpointer data) +{ + OperationCompleted *cbData = (OperationCompleted *)data; + g_print ("ad_gk.c : CreateItemCb : created item: res: %d id: %d\n", result, id); + if (result != GNOME_KEYRING_RESULT_OK) + { + g_print ("ad_gk.c : CreateItemCb : Unable to create item : %d\n", result); + } + cbData->result = result; + g_main_loop_quit (loop); +} + + +static int +CreateItemInKeyring(char *keyring, int32_t itemType, char *display_name, char *secret, Attribute **attrs, int attrcnt) +{ + GnomeKeyringAttributeList *attributes; + GnomeKeyringAttribute attribute; + OperationCompleted cbData; + + int i; + printf("ad:gk.c :In CreateItemInKeyring\n"); + printf("ad.gk.c : CreateItemInKeyring : Keyring %s, itemType %d displayname %s, secret %s \n",keyring,itemType, display_name,secret); + cbData.OperationName = "Create Item"; + loop = g_main_loop_new (NULL, FALSE); + + attributes = gnome_keyring_attribute_list_new (); + for (i=0; i< attrcnt; i++) + { + printf("as.gk.c : CreateItemInKeyring : In key %s \n", attrs[i]->key); + attribute.name = g_strdup (attrs[i]->key); + attribute.type = GNOME_KEYRING_ATTRIBUTE_TYPE_STRING; + attribute.value.string = g_strdup (attrs[i]->value); + g_array_append_val (attributes, attribute); + } + + gnome_keyring_item_create(keyring,itemType,display_name,attributes,secret,FALSE,CreateItemCb,&cbData,NULL); + gnome_keyring_attribute_list_free (attributes); + g_main_loop_run (loop); + return cbData.result; +} + +static int +CreateKeyring(char *keyring) +{ + + OperationCompleted cbData; + + cbData.OperationName = "Create Keyring"; + loop = g_main_loop_new (NULL, FALSE); + gnome_keyring_create(keyring,NULL,OperationCompletedCb,&cbData,NULL); + g_main_loop_run(loop); + return cbData.result; +} + + void ListKeyringsCb (GnomeKeyringResult result, GList *keyrings, gpointer data) @@ -238,32 +308,6 @@ int FreeAttributeList(GList *attrList) return SUCCESS; } -static void -OperationCompletedCb (GnomeKeyringResult result, - gpointer data) -{ - OperationCompleted *cbData = (OperationCompleted *)data; - g_print ("ad_gk.c : Operation %s Completed %d\n", cbData->OperationName, result); - cbData->result = result; - g_main_loop_quit (loop); -} - - -static void -CreateItemCb (GnomeKeyringResult result, - guint32 id, - gpointer data) -{ - OperationCompleted *cbData = (OperationCompleted *)data; - g_print ("ad_gk.c : CreateItemCb : created item: res: %d id: %d\n", result, id); - if (result != GNOME_KEYRING_RESULT_OK) - { - g_print ("ad_gk.c : CreateItemCb : Unable to create item : %d\n", result); - } - cbData->result = result; - g_main_loop_quit (loop); -} - @@ -346,42 +390,4 @@ CreateItem(char *keyring, int32_t itemType, char *display_name, char *secret, At return ret; } -static int -CreateItemInKeyring(char *keyring, int32_t itemType, char *display_name, char *secret, Attribute **attrs, int attrcnt) -{ - GnomeKeyringAttributeList *attributes; - GnomeKeyringAttribute attribute; - OperationCompleted cbData; - int i; - printf("ad:gk.c :In CreateItemInKeyring\n"); - printf("ad.gk.c : CreateItemInKeyring : Keyring %s, itemType %d displayname %s, secret %s \n",keyring,itemType, display_name,secret); - cbData.OperationName = "Create Item"; - loop = g_main_loop_new (NULL, FALSE); - - attributes = gnome_keyring_attribute_list_new (); - for (i=0; i< attrcnt; i++) - { - printf("as.gk.c : CreateItemInKeyring : In key %s \n", attrs[i]->key); - attribute.name = g_strdup (attrs[i]->key); - attribute.type = GNOME_KEYRING_ATTRIBUTE_TYPE_STRING; - attribute.value.string = g_strdup (attrs[i]->value); - g_array_append_val (attributes, attribute); - } - - gnome_keyring_item_create(keyring,itemType,display_name,attributes,secret,FALSE,CreateItemCb,&cbData,NULL); - gnome_keyring_attribute_list_free (attributes); - g_main_loop_run (loop); - return cbData.result; -} -static int -CreateKeyring(char *keyring) -{ - - OperationCompleted cbData; - cbData.OperationName = "Create Keyring"; - loop = g_main_loop_new (NULL, FALSE); - gnome_keyring_create(keyring,NULL,OperationCompletedCb,&cbData,NULL); - g_main_loop_run(loop); - return cbData.result; -}