NUM_AFT_COLUMNS
};
-/**
- * Compare two osl objects pointing to hash values.
- *
- * \param obj1 Pointer to the first hash object.
- * \param obj2 Pointer to the second hash object.
- *
- * \return The values required for an osl compare function.
- *
- * \sa osl_compare_func, uint32_compare().
- */
-static int aft_hash_compare(const struct osl_object *obj1, const struct osl_object *obj2)
+/* compare function for the hash column */
+static int aft_hash_compare(const struct osl_object *obj1,
+ const struct osl_object *obj2)
{
- return hash_compare((unsigned char *)obj1->data, (unsigned char *)obj2->data);
+ return hash_compare((unsigned char *)obj1->data,
+ (unsigned char *)obj2->data);
}
static struct osl_column_description aft_cols[] = {
static int get_local_time(uint64_t *seconds, char *buf, size_t size,
time_t current_time, enum ls_listing_mode lm)
{
- struct tm t;
+ struct tm *tm;
+ /*
+ * Omit year but show time if the given value is closer to the current
+ * time than this many seconds.
+ */
+ const time_t m = 6 * 30 * 24 * 3600; /* six months */
- if (!localtime_r((time_t *)seconds, &t))
+ tm = localtime((time_t *)seconds);
+ if (!tm)
return -E_LOCALTIME;
if (lm == LS_MODE_MBOX) {
- if (!strftime(buf, size, "%c", &t))
+ if (!strftime(buf, size, "%c", tm))
return -E_STRFTIME;
return 1;
}
- if (*seconds + 6 * 30 * 24 * 3600 > current_time) {
- if (!strftime(buf, size, "%b %e %k:%M", &t))
+ if (*seconds > current_time - m && *seconds < current_time + m) {
+ if (!strftime(buf, size, "%b %e %k:%M", tm))
return -E_STRFTIME;
return 1;
}
- if (!strftime(buf, size, "%b %e %Y", &t))
+ /*
+ * If the given time is more than six month away from the current time,
+ * we print only the year. The additional space character in the format
+ * string below makes the formated date align nicely with dates that
+ * contain the time (those written by the above strftime() statement).
+ */
+ if (!strftime(buf, size, "%b %e %Y", tm))
return -E_STRFTIME;
return 1;
}
if (!hours) { /* m:ss or mm:ss */
max_width = opts->mode == LS_MODE_LONG?
opts->widths.duration_width : 4;
- sprintf(buf, "%*u:%02u", max_width - 3, mins, seconds % 60);
+ sprintf(buf, "%*u:%02d", max_width - 3, mins, seconds % 60);
} else { /* more than one hour => h:mm:ss, hh:mm:ss, hhh:mm:ss, ... */
max_width = opts->mode == LS_MODE_LONG?
opts->widths.duration_width : 7;
- sprintf(buf, "%*u:%02u:%02u", max_width - 6, hours, mins,
+ sprintf(buf, "%*u:%02u:%02d", max_width - 6, hours, mins,
seconds % 60);
}
}
para_printf(b,
"%s " /* attributes */
"%*u " /* amp */
- "%*d " /* image_id */
- "%*d " /* lyrics_id */
- "%*d " /* bitrate */
+ "%*u " /* image_id */
+ "%*u " /* lyrics_id */
+ "%*u " /* bitrate */
"%*s " /* audio format */
- "%*d " /* frequency */
- "%d " /* channels */
+ "%*u " /* frequency */
+ "%u " /* channels */
"%s " /* duration */
- "%*d " /* num_played */
+ "%*u " /* num_played */
"%s " /* last_played */
"%s\n", /* path */
att_buf,
WRITE_STATUS_ITEM(b, SI_FREQUENCY, "%dHz\n", afhi->frequency);
WRITE_STATUS_ITEM(b, SI_CHANNELS, "%d\n", afhi->channels);
WRITE_STATUS_ITEM(b, SI_DURATION, "%s\n", duration_buf);
- WRITE_STATUS_ITEM(b, SI_SECONDS_TOTAL, "%lu\n", afhi->seconds_total);
+ WRITE_STATUS_ITEM(b, SI_SECONDS_TOTAL, "%" PRIu32 "\n",
+ afhi->seconds_total);
WRITE_STATUS_ITEM(b, SI_LAST_PLAYED, "%s\n", last_played_time);
- WRITE_STATUS_ITEM(b, SI_NUM_PLAYED, "%d\n", afsi->num_played);
+ WRITE_STATUS_ITEM(b, SI_NUM_PLAYED, "%u\n", afsi->num_played);
WRITE_STATUS_ITEM(b, SI_AMPLIFICATION, "%u\n", afsi->amp);
WRITE_STATUS_ITEM(b, SI_CHUNK_TIME, "%lu\n", tv2ms(&afhi->chunk_tv));
- WRITE_STATUS_ITEM(b, SI_NUM_CHUNKS, "%lu\n", afhi->chunks_total);
+ WRITE_STATUS_ITEM(b, SI_NUM_CHUNKS, "%" PRIu32 "\n",
+ afhi->chunks_total);
WRITE_STATUS_ITEM(b, SI_TECHINFO, "%s\n", afhi->techinfo);
WRITE_STATUS_ITEM(b, SI_ARTIST, "%s\n", afhi->tags.artist);
WRITE_STATUS_ITEM(b, SI_TITLE, "%s\n", afhi->tags.title);
i++;
break;
}
+ /*
+ * Compatibility: Prior to 0.5.5 it was necessary to specify
+ * the listing mode without the '=' character as in -lv, for
+ * example. Now the variant with '=' is preferred and
+ * documented but we still accept the old way to specify the
+ * listing mode.
+ *
+ * Support for the legacy syntax can be dropped at 0.6.0
+ * or later.
+ */
if (!strncmp(arg, "-l", 2)) {
- if (!*(arg + 2)) {
- mode = LS_MODE_LONG;
- continue;
- }
- if (*(arg + 3))
- return -E_AFT_SYNTAX;
- switch(*(arg + 2)) {
+ arg += 2;
+ if (*arg == '=')
+ arg++;
+ switch (*arg) {
case 's':
mode = LS_MODE_SHORT;
continue;
case 'l':
+ case '\0':
mode = LS_MODE_LONG;
continue;
case 'v':
return -E_AFT_SYNTAX;
}
}
- if (!strcmp(arg, "-p")) {
+ if (!strcmp(arg, "-p") || !strcmp(arg, "-F")) {
flags |= LS_FLAG_FULL_PATH;
continue;
}
+ if (!strcmp(arg, "-b")) {
+ flags &= ~LS_FLAG_FULL_PATH;
+ continue;
+ }
if (!strcmp(arg, "-a")) {
flags |= LS_FLAG_ADMISSIBLE_ONLY;
continue;
flags |= LS_FLAG_UNIXDATE;
continue;
}
+ /* The compatibility remark above applies also to -s. */
if (!strncmp(arg, "-s", 2)) {
- if (!*(arg + 2) || *(arg + 3))
- return -E_AFT_SYNTAX;
- switch(*(arg + 2)) {
+ arg += 2;
+ if (*arg == '=')
+ arg++;
+ switch (*arg) {
case 'p':
sort = LS_SORT_BY_PATH;
continue;
/** The format of the data stored by save_audio_file_data(). */
enum com_add_buffer_offsets {
- /** afhi (if present) starts here. */
+ /* afhi (if present) starts at this offset. */
CAB_AFHI_OFFSET_POS = 0,
/** Start of the chunk table (if present). */
- CAB_CHUNKS_OFFSET_POS = 2,
- /** Audio format id. */
- CAB_AUDIO_FORMAT_OFFSET = 4,
+ CAB_CHUNKS_OFFSET_POS = 4,
/** Flags given to the add command. */
- CAB_FLAGS_OFFSET = 5,
+ CAB_FLAGS_OFFSET = 8,
+ /** Audio format id. */
+ CAB_AUDIO_FORMAT_ID_OFFSET = 12,
/** The hash of the audio file being added. */
- CAB_HASH_OFFSET = 9,
+ CAB_HASH_OFFSET = 13,
/** Start of the path of the audio file. */
CAB_PATH_OFFSET = (CAB_HASH_OFFSET + HASH_SIZE),
};
size_t size = CAB_PATH_OFFSET + path_len + afhi_size
+ sizeof_chunk_table(afhi);
char *buf = para_malloc(size);
- uint16_t pos;
-
- write_u8(buf + CAB_AUDIO_FORMAT_OFFSET, audio_format_num);
- write_u32(buf + CAB_FLAGS_OFFSET, flags);
-
- memcpy(buf + CAB_HASH_OFFSET, hash, HASH_SIZE);
- strcpy(buf + CAB_PATH_OFFSET, path);
+ uint32_t pos;
pos = CAB_PATH_OFFSET + path_len;
- PARA_DEBUG_LOG("size: %zu, afhi starts at %d\n", size, pos);
- PARA_DEBUG_LOG("last afhi byte: %p, pos %zu\n", buf + pos + afhi_size - 1,
- pos + afhi_size - 1);
- write_u16(buf + CAB_AFHI_OFFSET_POS, pos);
+ write_u32(buf + CAB_AFHI_OFFSET_POS, pos);
save_afhi(afhi, buf + pos);
-
pos += afhi_size;
- PARA_DEBUG_LOG("size: %zu, chunks start at %d\n", size, pos);
- write_u16(buf + CAB_CHUNKS_OFFSET_POS, pos);
+
+ write_u32(buf + CAB_CHUNKS_OFFSET_POS, pos);
if (afhi)
save_chunk_table(afhi, buf + pos);
- PARA_DEBUG_LOG("last byte in buf: %p\n", buf + size - 1);
+
+ write_u32(buf + CAB_FLAGS_OFFSET, flags);
+ write_u8(buf + CAB_AUDIO_FORMAT_ID_OFFSET, audio_format_num);
+
+ memcpy(buf + CAB_HASH_OFFSET, hash, HASH_SIZE);
+ strcpy(buf + CAB_PATH_OFFSET, path);
+
obj->data = buf;
obj->size = size;
}
goto out;
}
/* no hs or force mode, child must have sent afhi */
- afhi_offset = read_u16(buf + CAB_AFHI_OFFSET_POS);
- chunks_offset = read_u16(buf + CAB_CHUNKS_OFFSET_POS);
+ afhi_offset = read_u32(buf + CAB_AFHI_OFFSET_POS);
+ chunks_offset = read_u32(buf + CAB_CHUNKS_OFFSET_POS);
objs[AFTCOL_AFHI].data = buf + afhi_offset;
objs[AFTCOL_AFHI].size = chunks_offset - afhi_offset;
if (flags & ADD_FLAG_VERBOSE)
para_printf(&aca->pbout, "new file\n");
default_afsi.last_played = time(NULL) - 365 * 24 * 60 * 60;
- default_afsi.audio_format_id = read_u8(buf + CAB_AUDIO_FORMAT_OFFSET);
+ default_afsi.audio_format_id = read_u8(buf + CAB_AUDIO_FORMAT_ID_OFFSET);
objs[AFTCOL_AFSI].data = &afsi_buf;
objs[AFTCOL_AFSI].size = AFSI_SIZE;
save_afsi(&default_afsi, &objs[AFTCOL_AFSI]);
ret = osl(osl_add_and_get_row(audio_file_table, objs, &aft_row));
+ if (ret < 0)
+ goto out;
ret = afs_event(AUDIO_FILE_ADD, &aca->pbout, aft_row);
out:
if (ret < 0)
) {
char c;
unsigned char bitnum;
+ uint64_t one = 1;
len = strlen(p);
ret = -E_ATTR_SYNTAX;
goto out;
}
if (c == '+')
- cad.add_mask |= (1UL << bitnum);
+ cad.add_mask |= (one << bitnum);
else
- cad.del_mask |= (1UL << bitnum);
+ cad.del_mask |= (one << bitnum);
}
ret = -E_ATTR_SYNTAX;
if (!cad.add_mask && !cad.del_mask)
goto out;
pmd.patterns.data = p;
- assert(p < (char *)aca->query.data + aca->query.size);
+ if (p >= (char *)aca->query.data + aca->query.size)
+ goto out;
pmd.patterns.size = (char *)aca->query.data + aca->query.size - p;
ret = for_each_matching_row(&pmd);
if (ret < 0)
if (ret >= 0) {
unsigned num;
osl_get_num_rows(audio_file_table, &num);
- PARA_INFO_LOG("audio file table contains %d files\n", num);
+ PARA_INFO_LOG("audio file table contains %u files\n", num);
return ret;
}
PARA_NOTICE_LOG("failed to open audio file table\n");