Commits

portix  committed 882f991

keyring.create: resolve deferred if the keyring exists

  • Participants
  • Parent commits e664acf

Comments (0)

Files changed (2)

File src/scripts.c

     (void) unused;
     EXEC_LOCK;
     JSValueRef args[] = { JSValueMakeNumber(s_ctx->global_context, status) };
-    if (status == DWB_SECRET_OK) {
+    if (status >= 0) {
         deferred_resolve(s_ctx->global_context, d, d, 1, args, NULL);
     }
     else {
 void 
 on_keyring_string(int status, const char *value, JSObjectRef dfd) {
     EXEC_LOCK;
-    if (status == DWB_SECRET_OK) {
+    if (status >= 0) {
         JSValueRef args[] = { value == NULL ? NIL : js_char_to_value(s_ctx->global_context, value) };
         deferred_resolve(s_ctx->global_context, dfd, dfd, 1, args, NULL);
     }
  * @param {String} keyring The name of the keyring
  *
  * @returns {Deferred} 
- *      A deferred that will be resolved if the keyring was created or rejected
- *      if a keyring with the same name already exists or an error occured
+ *      A deferred that will be resolved if the keyring was created or a keyring
+ *      with matching name already exists and rejected if an error occured
  *
  */
 static JSValueRef 
      * var collection = "foo";
      * var id = script.generateId();
      * 
-     * keyring.create(collection).always(function(status) {
-     *     if (status == KeyringResult.ok || KeyringResult.keyringExists) {
-     *         keyring.store(collection, "foobar", id, "secret").then(function() {
-     *             io.print("password saved");
-     *         });;
-     *     }
+     * // creates a new keyring if it doesn't exist and saves a new password
+     * keyring.create(collection).then(function(status) {
+     *     keyring.store(collection, "foobar", id, "secret").then(function() {
+     *         io.print("password saved");
+     *     });;
      * });
      *
      * */

File src/secret.h

 
 typedef void (* dwb_secret_cb)(int, const void *, void *);
 
-enum {
-    DWB_SECRET_OK,
-    DWB_SECRET_COLLECTION_EXISTS,
-    DWB_SECRET_NO_SUCH_COLLECTION,
-    DWB_SECRET_SERVICE_ERROR,
-    DWB_SECRET_ERROR,
-};
+
+#define DWB_SECRET_OK                 0
+#define DWB_SECRET_COLLECTION_EXISTS  1
+#define DWB_SECRET_ERROR              (-1)
+#define DWB_SECRET_SERVICE_ERROR      (-2)
+#define DWB_SECRET_NO_SUCH_COLLECTION (-3)
 
 void 
 dwb_secret_create_collection(dwb_secret_cb cb, const char *name, void *user_data);