Commits

portix committed e664acf

keyring: allow empty collection

  • Participants
  • Parent commits 7fe381e

Comments (0)

Files changed (2)

File src/scripts.c

  *     io.print("keyring locked");
  * });
  *
- * @param {String} keyring  The name of the keyring
+ * @param {String} keyring  
+ *      The name of the keyring, pass null to use the default keyring
  * @param {String} label    Label for the password
  * @param {String} id       Identifier for the password
  * @param {String} password The password
         return NIL;
 
     collection = js_value_to_char(ctx, argv[0], -1, exc);
-    if (collection == NULL) 
-        goto error_out;
+
     label = js_value_to_char(ctx, argv[1], -1, exc);
     if (label == NULL) 
         goto error_out;
  *     io.print("password: " + password);
  * });
  *
- * @param {String} keyring  The name of the keyring
- * @param {String} id       Identifier of the password
+ * @param {String} keyring  
+ *      The name of the keyring, pass null to use the default keyring
+ * @param {String} id       
+ *      Identifier of the password
  *
  * @returns {Deferred} 
  *      A deferred that will be resolved if the password was found or rejected
         return NIL;
 
     collection = js_value_to_char(ctx, argv[0], -1, exc);
-    if (collection == NULL) 
-        goto error_out;
+
     id = js_value_to_char(ctx, argv[1], -1, exc);
     if (id == NULL) 
         goto error_out;

File src/secret.c

 }
 void 
 dwb_secret_create_collection(dwb_secret_cb cb, const char *name, void *user_data) {
+    g_return_if_fail(name != NULL);
     dwb_secret_t *s = dwb_secret_new(cb, g_strdup(name), user_data, g_free, DWB_SECRET_ACTION_NONE);
     get_service_init(on_service_create_collection, s);
 }
 
 void 
 dwb_secret_lock_collection(dwb_secret_cb cb, const char *name, void *user_data) {
+    g_return_if_fail(name != NULL);
     dwb_secret_t *s = dwb_secret_new(cb, g_strdup(name), user_data, g_free, DWB_SECRET_ACTION_LOCK);
     get_service_init(on_service_lock_unlock_collection, s);
 }
 void 
 dwb_secret_unlock_collection(dwb_secret_cb cb, const char *name, void *user_data) {
+    g_return_if_fail(name != NULL);
     dwb_secret_t *s = dwb_secret_new(cb, g_strdup(name), user_data, g_free, DWB_SECRET_ACTION_UNLOCK);
     get_service_init(on_service_lock_unlock_collection, s);
 }
 static void 
 on_service_pwd(GObject *source, GAsyncResult *result, dwb_secret_t *secret) {
     SecretService *service = get_service(secret, result);
+    const char *path = NULL;
     if (service != NULL) {
         dwb_pwd_t *pwd = secret->data;
-        const char *path = collection_lookup_path(service, pwd->collection);
-        if (path != NULL) {
+        if (pwd->collection != NULL) {
+            path = collection_lookup_path(service, pwd->collection);
+        }
+        if (path != NULL || pwd->collection == NULL) {
             if (secret->action == DWB_SECRET_ACTION_STORE) {
                 secret_password_store(&s_schema, path, pwd->label, pwd->pwd, NULL,
                         (GAsyncReadyCallback)on_store_pwd, secret, "id", pwd->id, NULL);
 void 
 dwb_secret_store_pwd(dwb_secret_cb cb, const char *collection, 
         const char *label, const char *id, const char *password, void *user_data) {
+    g_return_if_fail(label != NULL || id != NULL || password != NULL);
     dwb_pwd_t *pwd = dwb_pwd_new(collection, label, id, password);
     dwb_secret_t *s = dwb_secret_new(cb, pwd, user_data, (void (*)(void *))dwb_pwd_free, DWB_SECRET_ACTION_STORE);
     get_service_init(on_service_pwd, s);
 
 void 
 dwb_secret_lookup_pwd(dwb_secret_cb cb, const char *collection, const char *id, void *user_data) {
+    g_return_if_fail(id != NULL);
     dwb_pwd_t *pwd = dwb_pwd_new(collection, NULL, id, NULL);
     dwb_secret_t *s = dwb_secret_new(cb, pwd, user_data, (void (*)(void *))dwb_pwd_free, DWB_SECRET_ACTION_LOOKUP);
     get_service_init(on_service_pwd, s);