*/
static struct osl_table *audio_file_table; /* NULL if table not open */
static struct osl_row *current_aft_row; /* NULL if no audio file open */
-static unsigned char current_hash[HASH2_SIZE]; /* only used on sighup */
+static unsigned char current_hash[HASH_SIZE]; /* only used on sighup */
static char *status_items;
static char *parser_friendly_status_items;
static int aft_hash_compare(const struct osl_object *obj1,
const struct osl_object *obj2)
{
- return hash2_compare((unsigned char *)obj1->data,
+ return hash_compare((unsigned char *)obj1->data,
(unsigned char *)obj2->data);
}
.storage_flags = OSL_RBTREE | OSL_FIXED_SIZE | OSL_UNIQUE,
.name = "hash",
.compare_function = aft_hash_compare,
- .data_size = HASH2_SIZE
+ .data_size = HASH_SIZE
},
[AFTCOL_PATH] = {
.storage_type = OSL_MAPPED_STORAGE,
*/
static int aft_get_row_of_hash(unsigned char *hash, struct osl_row **row)
{
- const struct osl_object obj = {.data = hash, .size = HASH2_SIZE};
+ const struct osl_object obj = {.data = hash, .size = HASH_SIZE};
return osl(osl_get_row(audio_file_table, AFTCOL_HASH, &obj, row));
}
char duration_buf[30]; /* nobody has an audio file long enough to overflow this */
struct afs_info *afsi = &d->afsi;
struct afh_info *afhi = &d->afhi;
- char asc_hash[2 * HASH2_SIZE + 1];
+ char asc_hash[2 * HASH_SIZE + 1];
if (opts->mode == LS_MODE_SHORT) {
para_printf(b, "%s\n", d->path);
return ret;
write_image_items(b, afsi);
write_lyrics_items(b, afsi);
- hash2_to_asc(d->hash, asc_hash);
+ hash_to_asc(d->hash, asc_hash);
WRITE_STATUS_ITEM(b, SI_hash, "%s\n", asc_hash);
WRITE_STATUS_ITEM(b, SI_bitrate, "%dkbit/s\n", afhi->bitrate);
WRITE_STATUS_ITEM(b, SI_format, "%s\n",
*/
int open_and_update_audio_file(int *fd)
{
- unsigned char file_hash[HASH2_SIZE];
+ unsigned char file_hash[HASH_SIZE];
struct osl_object afsi_obj;
struct afs_info new_afsi;
int ret;
if (ret < 0)
return ret;
if (!d->hash)
- d->hash = alloc(HASH2_SIZE);
- memcpy(d->hash, tmp_hash, HASH2_SIZE);
+ d->hash = alloc(HASH_SIZE);
+ memcpy(d->hash, tmp_hash, HASH_SIZE);
free(d->path);
ret = get_audio_file_path_of_row(current_aft_row, &d->path);
if (ret < 0)
ret = mmap_full_file(d->path, O_RDONLY, &map.data, &map.size, fd);
if (ret < 0)
goto out;
- hash2_function(map.data, map.size, file_hash);
- ret = hash2_compare(file_hash, d->hash);
+ hash_function(map.data, map.size, file_hash);
+ ret = hash_compare(file_hash, d->hash);
para_munmap(map.data, map.size);
if (ret) {
ret = -E_HASH_MISMATCH;
static int ls_hash_compare(const void *a, const void *b)
{
struct ls_data *d1 = *(struct ls_data **)a, *d2 = *(struct ls_data **)b;
- return memcmp(d1->hash, d2->hash, HASH2_SIZE);
+ return memcmp(d1->hash, d2->hash, HASH_SIZE);
}
static int ls_audio_format_compare(const void *a, const void *b)
/** The hash of the audio file being added. */
CAB_HASH_OFFSET = 13,
/** Start of the path of the audio file. */
- CAB_PATH_OFFSET = (CAB_HASH_OFFSET + HASH2_SIZE),
+ CAB_PATH_OFFSET = (CAB_HASH_OFFSET + HASH_SIZE),
};
/*
assert(size <= ~(uint32_t)0);
write_u8(buf + CAB_AUDIO_FORMAT_ID_OFFSET, audio_format_num);
- memcpy(buf + CAB_HASH_OFFSET, hash, HASH2_SIZE);
+ memcpy(buf + CAB_HASH_OFFSET, hash, HASH_SIZE);
strcpy(buf + CAB_PATH_OFFSET, path);
pos = CAB_PATH_OFFSET + path_len;
write_u32(buf + CAB_AFHI_OFFSET_POS, pos);
struct osl_row *hs;
struct osl_object objs[NUM_AFT_COLUMNS];
unsigned char *hash;
- char asc[2 * HASH2_SIZE + 1];
+ char asc[2 * HASH_SIZE + 1];
int ret;
char afsi_buf[AFSI_SIZE];
uint32_t slpr_offset = read_u32(buf + CAB_LPR_OFFSET);
r_v = SERVER_CMD_OPT_RESULT(ADD, VERBOSE, aca->lpr);
hash = (unsigned char *)buf + CAB_HASH_OFFSET;
- hash2_to_asc(hash, asc);
+ hash_to_asc(hash, asc);
objs[AFTCOL_HASH].data = buf + CAB_HASH_OFFSET;
- objs[AFTCOL_HASH].size = HASH2_SIZE;
+ objs[AFTCOL_HASH].size = HASH_SIZE;
path = buf + CAB_PATH_OFFSET;
objs[AFTCOL_PATH].data = path;
objs[AFTCOL_CHUNKS].data = buf + chunks_offset;
objs[AFTCOL_CHUNKS].size = slpr_offset - chunks_offset;
if (pb && !hs) { /* update pb's hash */
- char old_asc[2 * HASH2_SIZE + 1];
+ char old_asc[2 * HASH_SIZE + 1];
unsigned char *old_hash;
ret = get_hash_of_row(pb, &old_hash);
if (ret < 0)
goto out;
- hash2_to_asc(old_hash, old_asc);
+ hash_to_asc(old_hash, old_asc);
if (lls_opt_given(r_v))
para_printf(&aca->pbout, "file change: %s -> %s\n",
old_asc, asc);
struct afh_info afhi, *afhi_ptr = NULL;
struct osl_row *pb = NULL, *hs = NULL; /* path brother/hash sister */
struct osl_object map, obj = {.data = NULL}, query;
- unsigned char hash[HASH2_SIZE];
+ unsigned char hash[HASH_SIZE];
bool a_given = SERVER_CMD_OPT_GIVEN(ADD, ALL, pad->lpr);
bool f_given = SERVER_CMD_OPT_GIVEN(ADD, FORCE, pad->lpr);
bool l_given = SERVER_CMD_OPT_GIVEN(ADD, LAZY, pad->lpr);
ret = mmap_full_file(path, O_RDONLY, &map.data, &map.size, &fd);
if (ret < 0)
goto out_free;
- hash2_function(map.data, map.size, hash);
+ hash_function(map.data, map.size, hash);
/* Check whether the database contains a file with the same hash. */
query.data = hash;
- query.size = HASH2_SIZE;
+ query.size = HASH_SIZE;
ret = send_callback_request(hash_sister_callback, &query,
get_row_pointer_from_result, &hs);
if (ret < 0)
PARA_WARNING_LOG("hash lookup failure\n");
current_aft_row = NULL;
} else
- memcpy(current_hash, p, HASH2_SIZE);
+ memcpy(current_hash, p, HASH_SIZE);
}
osl_close_table(audio_file_table, OSL_MARK_CLEAN);
audio_file_table = NULL;
void sc_free(struct stream_cipher *sc);
/** Size of the hash value in bytes. */
-#define HASH2_SIZE 32
+#define HASH_SIZE 32
/**
- * Compute the hash2 of the given input data.
+ * Compute the hash of the given input data.
*
* \param data Pointer to the data to compute the hash value from.
* \param len The length of \a data in bytes.
* \param hash Result pointer.
*
- * \a hash must point to an area at least \p HASH2_SIZE bytes large.
+ * \a hash must point to an area at least HASH_SIZE bytes large.
*
* \sa sha(3), openssl(1).
* */
-void hash2_function(const char *data, unsigned long len, unsigned char *hash);
+void hash_function(const char *data, unsigned long len, unsigned char *hash);
/**
- * Convert a hash2 value to ascii format.
+ * Convert a hash value to ascii format.
*
* \param hash the hash value.
* \param asc Result pointer.
*
- * \a asc must point to an area of at least 2 * \p HASH2_SIZE + 1 bytes which
- * will be filled by the function with the ascii representation of the hash
- * value given by \a hash, and a terminating \p NULL byte.
+ * The result pointer must point to an area of at least 2 * HASH_SIZE + 1
+ * bytes which will be filled by the function with the ascii representation
+ * of the hash value given by hash, and a terminating NUL byte.
*/
-void hash2_to_asc(const unsigned char *hash, char *asc);
+void hash_to_asc(const unsigned char *hash, char *asc);
/**
- * Compare two version 2 hashes.
+ * Compare two hashes.
*
* \param h1 Pointer to the first hash value.
* \param h2 Pointer to the second hash value.
* \return 1, -1, or zero, depending on whether \a h1 is greater than,
* less than or equal to h2, respectively.
*/
-int hash2_compare(const unsigned char *h1, const unsigned char *h2);
+int hash_compare(const unsigned char *h1, const unsigned char *h2);