diff --git a/doc/bookmarkfs.texi b/doc/bookmarkfs.texi index 44fc380..a41b02d 100644 --- a/doc/bookmarkfs.texi +++ b/doc/bookmarkfs.texi @@ -2299,7 +2299,7 @@ Type of the @code{bookmark_get} function is defined as: typedef int (bookmarkfs_bookmark_get_func) ( void *backend_ctx, uint64_t id, - char const *attr_key, + char const *xattr_name, bookmarkfs_bookmark_get_cb *callback, void *user_data, void **cookie_ptr @@ -2313,13 +2313,13 @@ Function arguments: The pointer referring to the backend context. @item id -ID of the bookmark (could be a bookmark folder if @code{attr_key} +ID of the bookmark (could be a bookmark folder if @code{xattr_name} is not @code{NULL}). -@item attr_key +@item xattr_name Name of an extended attribute. -If not @code{NULL}, @code{attr_key} is guaranteed to be a NUL-terminated +If not @code{NULL}, @code{xattr_name} is guaranteed to be a NUL-terminated string, and the function should get the corresponding extended attribute value instead of the bookmark content. @@ -2367,7 +2367,7 @@ Pointer to the ``cookie'' for the current @code{bookmark_get} operation. @code{NULL} if not used by the caller. The “cookie” is an opaque pointer which stores internal states -for subsequent operations on the same bookmark (and @code{attr_key}) +for subsequent operations on the same bookmark (and @code{xattr_name}) to determine whether the corresponding data has changed. If the value pointered to by @code{cookie_ptr} is @code{NULL}, @@ -2459,7 +2459,7 @@ Type of the @code{bookmark_set} function is defined as: typedef int (bookmarkfs_bookmark_set_func) ( void *backend_ctx, uint64_t id, - char const *attr_key, + char const *xattr_name, uint32_t flags, void const *val, size_t val_len @@ -2476,10 +2476,10 @@ The pointer referring to the backend context. ID of the object to update. It could be a bookmark ID or tag ID, depending on the value of @code{flags}. -@item attr_key +@item xattr_name Name of an extended attribute. -If not @code{NULL}, @code{attr_key} is guaranteed to be a NUL-terminated +If not @code{NULL}, @code{xattr_name} is guaranteed to be a NUL-terminated string, and the function should update the corresponding extended attribute value instead of the bookmark content. @@ -2494,7 +2494,7 @@ the object. The @code{val} argument points to an array of @code{struct timespec}, the first element refers to the last access time, and the second element refers to the last modification time of the object. -Values of @code{attr_key} and @code{val_len} are unspecified. +Values of @code{xattr_name} and @code{val_len} are unspecified. The @code{tv_nsec} field of each timestamp may be @code{UTIME_OMIT}, which indicates that the timestamp should be left as-is. diff --git a/src/backend.h b/src/backend.h index 18e0c1c..19aa5f1 100644 --- a/src/backend.h +++ b/src/backend.h @@ -159,7 +159,7 @@ typedef int (bookmarkfs_bookmark_get_cb) ( typedef int (bookmarkfs_bookmark_get_func) ( void *backend_ctx, uint64_t id, - char const *attr_key, + char const *xattr_name, bookmarkfs_bookmark_get_cb *callback, void *user_data, void **cookie_ptr @@ -209,7 +209,7 @@ typedef int (bookmarkfs_bookmark_rename_func) ( typedef int (bookmarkfs_bookmark_set_func) ( void *backend_ctx, uint64_t id, - char const *attr_key, + char const *xattr_name, uint32_t flags, void const *val, size_t val_len diff --git a/src/backend_chromium.c b/src/backend_chromium.c index abf0702..a19ab19 100644 --- a/src/backend_chromium.c +++ b/src/backend_chromium.c @@ -228,8 +228,8 @@ static void free_maps (struct hashmap *, struct hashmap *, struct hashmap *); static int fsck_next (struct backend_ctx const *, uint64_t, json_t *, size_t *, bookmarkfs_bookmark_check_cb *, void *); -static int get_attr_type (char const *, uint32_t); -static int get_attr_val (json_t const *, char const *, uint32_t, json_t **); +static int get_xattr_id (char const *, uint32_t); +static int get_xattr_val (json_t const *, char const *, uint32_t, json_t **); static int guidmap_comp (union hashmap_key, void const *); static unsigned long guidmap_hash (void const *); @@ -951,22 +951,22 @@ fsck_next ( } static int -get_attr_type ( - char const *key, +get_xattr_id ( + char const *name, uint32_t flags ) { - if (key == NULL) { + if (name == NULL) { return BM_XATTR_NULL; } - if (0 == strcmp("date_added", key)) { + if (0 == strcmp("date_added", name)) { return BM_XATTR_DATE_ADDED; } if (flags & BACKEND_FILENAME_GUID) { - if (0 == strcmp("title", key)) { + if (0 == strcmp("title", name)) { return BM_XATTR_TITLE; } } else { - if (0 == strcmp("guid", key)) { + if (0 == strcmp("guid", name)) { return BM_XATTR_GUID; } } @@ -974,16 +974,16 @@ get_attr_type ( } static int -get_attr_val ( +get_xattr_val ( json_t const *node, - char const *attr_key, + char const *xattr_name, uint32_t flags, json_t **value_ptr ) { json_t *value; - int key_type = get_attr_type(attr_key, flags); - switch (key_type) { + int xattr_id = get_xattr_id(xattr_name, flags); + switch (xattr_id) { case BM_XATTR_NULL: value = json_object_sget(node, "url"); break; @@ -1004,13 +1004,13 @@ get_attr_val ( return -ENOATTR; } if (value == NULL) { - if (unlikely(attr_key == NULL)) { + if (unlikely(xattr_name == NULL)) { return -EIO; } return -EISDIR; } *value_ptr = value; - return key_type; + return xattr_id; } static int @@ -1933,7 +1933,7 @@ static int bookmark_get ( void *backend_ctx, uint64_t id, - char const *attr_key, + char const *xattr_name, bookmarkfs_bookmark_get_cb *callback, void *user_data, void **cookie_ptr @@ -1952,7 +1952,7 @@ bookmark_get ( goto lookup; } if (cookie->store != ctx->store) { - if (attr_key != NULL) { + if (xattr_name != NULL) { goto lookup; } // Checksum only applies to directory structure and URL values. @@ -1968,11 +1968,12 @@ bookmark_get ( return -ESTALE; } if (entry->id == BOOKMARKS_ROOT_ID) { - return attr_key == NULL ? -EISDIR : -ENOATTR; + return xattr_name == NULL ? -EISDIR : -ENOATTR; } json_t *value_node; - int status = get_attr_val(entry->node, attr_key, ctx->flags, &value_node); + int status = get_xattr_val(entry->node, xattr_name, ctx->flags, + &value_node); if (status < 0) { return status; } @@ -2600,7 +2601,7 @@ static int bookmark_set ( void *backend_ctx, uint64_t id, - char const *attr_key, + char const *xattr_name, uint32_t flags, void const *val, size_t val_len @@ -2637,7 +2638,8 @@ bookmark_set ( } json_t *val_node; - int key_type = get_attr_val(entry->node, attr_key, ctx->flags, &val_node); + int key_type = get_xattr_val(entry->node, xattr_name, ctx->flags, + &val_node); if (key_type < 0) { return key_type; } diff --git a/src/backend_firefox.c b/src/backend_firefox.c index 7184ff0..e7fa79e 100644 --- a/src/backend_firefox.c +++ b/src/backend_firefox.c @@ -347,7 +347,7 @@ static unsigned long static void free_blcookie (struct bookmark_lcookie *); static void free_dentmap (struct hashmap *); static void free_dentmap_entry (void *, void *); -static int get_attr_type (char const *, uint32_t); +static int get_xattr_id (char const *, uint32_t); static int64_t get_data_version (struct backend_ctx *); static bool is_valid_id (int64_t); static void msecs_to_timespec (struct timespec *, int64_t); @@ -2032,7 +2032,7 @@ static int bookmark_do_get ( struct backend_ctx *ctx, uint64_t id, - int attr_type, + int xattr_id, struct bookmark_get_ctx *qctx ) { #define BOOKMARK_GET_(cols, join) "SELECT CASE ? " cols "END " \ @@ -2050,7 +2050,7 @@ bookmark_do_get ( sqlite3_stmt **stmt_ptr = &ctx->stmts[STMT_BOOKMARK_GET_EX]; char const *sql = BOOKMARK_GET_EX; - if (attr_type >= MOZBM_XATTR_START) { + if (xattr_id >= MOZBM_XATTR_START) { stmt_ptr = &ctx->stmts[STMT_BOOKMARK_GET]; sql = BOOKMARK_GET_WITH_GUID; if (ctx->flags & BACKEND_FILENAME_GUID) { @@ -2063,7 +2063,7 @@ bookmark_do_get ( { qctx->tags_root_id = ctx->tags_root_id; }, - DB_QUERY_BIND_INT64(attr_type), + DB_QUERY_BIND_INT64(xattr_id), DB_QUERY_BIND_INT64(id), ); if (nrows < 0) { @@ -2256,9 +2256,9 @@ bookmark_do_lookup ( bookmark_type >>= BOOKMARKFS_BOOKMARK_TYPE_SHIFT; char const *sql_table[3][2] = { - { BOOKMARK_LOOKUP_TITLE, BOOKMARK_LOOKUP_GUID }, - { BOOKMARK_LOOKUP_TAG_TITLE, BOOKMARK_LOOKUP_TAG_GUID }, - { BOOKMARK_LOOKUP_KEYWORD, BOOKMARK_LOOKUP_KEYWORD }, + { BOOKMARK_LOOKUP_TITLE, BOOKMARK_LOOKUP_GUID }, + { BOOKMARK_LOOKUP_TAG_TITLE, BOOKMARK_LOOKUP_TAG_GUID }, + { BOOKMARK_LOOKUP_KEYWORD, BOOKMARK_LOOKUP_KEYWORD }, }; sql = sql_table[bookmark_type][filename_is_guid]; @@ -2301,9 +2301,6 @@ bookmark_check_cb ( log_printf("bad bookmark ID %" PRIi64, id); goto fail; } - if (unlikely((uint64_t)id == ctx->tags_root_id)) { - return 0; - } int64_t position = sqlite3_column_int64(stmt, 1); if (unlikely(position < 0)) { @@ -2559,25 +2556,25 @@ free_dentmap_entry ( } static int -get_attr_type ( - char const *key, +get_xattr_id ( + char const *name, uint32_t flags ) { - if (key == NULL) { + if (name == NULL) { return BM_XATTR_NULL; } - if (0 == strcmp("date_added", key)) { + if (0 == strcmp("date_added", name)) { return BM_XATTR_DATE_ADDED; } - if (0 == strcmp("description", key)) { + if (0 == strcmp("description", name)) { return BM_XATTR_DESC; } if (flags & BACKEND_FILENAME_GUID) { - if (0 == strcmp("title", key)) { + if (0 == strcmp("title", name)) { return BM_XATTR_TITLE; } } else { - if (0 == strcmp("guid", key)) { + if (0 == strcmp("guid", name)) { return BM_XATTR_GUID; } } @@ -3077,15 +3074,15 @@ static int bookmark_get ( void *backend_ctx, uint64_t id, - char const *attr_key, + char const *xattr_name, bookmarkfs_bookmark_get_cb *callback, void *user_data, void **cookie_ptr ) { struct backend_ctx *ctx = backend_ctx; - int attr_type = get_attr_type(attr_key, ctx->flags); - if (attr_type < 0) { + int xattr_id = get_xattr_id(xattr_name, ctx->flags); + if (xattr_id < 0) { return -ENOATTR; } @@ -3107,7 +3104,7 @@ bookmark_get ( struct bookmark_get_ctx qctx; qctx.callback = callback; qctx.user_data = user_data; - int status = bookmark_do_get(ctx, id, attr_type, &qctx); + int status = bookmark_do_get(ctx, id, xattr_id, &qctx); if (status < 0) { return status; } @@ -3594,7 +3591,7 @@ static int bookmark_set ( void *backend_ctx, uint64_t id, - char const *attr_key, + char const *xattr_name, uint32_t flags, void const *val, size_t val_len @@ -3612,17 +3609,17 @@ bookmark_set ( .last_visit_date = -1, }; - int attr_type = MOZBM_XATTR_START; + int xattr_id = MOZBM_XATTR_START; if (flags & BOOKMARK_FLAG(SET_TIME)) { struct timespec const *times = val; place_cols.last_visit_date = timespec_to_msecs(×[0]); bm_cols.last_modified = timespec_to_msecs(×[1]); if (place_cols.last_visit_date >= 0) { - --attr_type; + --xattr_id; } } else { - attr_type = get_attr_type(attr_key, ctx->flags); - switch (attr_type) { + xattr_id = get_xattr_id(xattr_name, ctx->flags); + switch (xattr_id) { case BM_XATTR_NULL: place_cols.url = val; place_cols.url_len = val_len; @@ -3658,7 +3655,7 @@ bookmark_set ( return -ENOATTR; } - if (attr_type != BM_XATTR_NULL + if (xattr_id != BM_XATTR_NULL && ctx->flags & BOOKMARKFS_BACKEND_CTIME ) { struct timespec now; @@ -3679,7 +3676,7 @@ bookmark_set ( status = -EPERM; goto fail; } - if (attr_type >= MOZBM_XATTR_START) { + if (xattr_id >= MOZBM_XATTR_START) { goto end; }