* No need to update the status items as the AFSI_CHANGE event will
* recreate them.
*/
- afs_event(AFSI_CHANGE, NULL, &aced);
+ ret = afs_event(AFSI_CHANGE, NULL, &aced);
+ if (ret < 0)
+ goto out;
ret = save_afd(afd);
out:
free(afd->afhi.chunk_table);
return ret;
}
-static void com_ls_callback(int fd, const struct osl_object *query)
+static int com_ls_callback(int fd, const struct osl_object *query)
{
struct ls_options *opts = query->data;
char *p, *pattern_start = (char *)query->data + sizeof(*opts);
if (ret < 0)
goto out;
if (opts->num_matching_paths == 0) {
- if (opts->num_patterns > 0)
- para_printf(&b, "no matches\n");
+ ret = opts->num_patterns > 0? -E_NO_MATCH : 0;
goto out;
}
ret = sort_matching_paths(opts);
goto out;
}
out:
- if (b.offset)
- pass_buffer_as_shm(fd, SBD_OUTPUT, b.buf, b.offset);
- free(b.buf);
+ flush_and_free_pb(&b);
free(opts->data);
free(opts->data_ptr);
free(opts->patterns);
+ return ret;
}
/*
*/
int com_ls(struct command_context *cc)
{
- int i, ret;
+ int i;
unsigned flags = 0;
enum ls_sorting_method sort = LS_SORT_BY_PATH;
enum ls_listing_mode mode = LS_MODE_SHORT;
opts.sorting = sort;
opts.mode = mode;
opts.num_patterns = cc->argc - i;
- ret = send_option_arg_callback_request(&query, opts.num_patterns,
+ return send_option_arg_callback_request(&query, opts.num_patterns,
cc->argv + i, com_ls_callback, afs_cb_result_handler, cc);
- return ret;
}
/**
ADD_FLAG_ALL = 8,
};
-static void com_add_callback(int fd, const struct osl_object *query)
+static int com_add_callback(int fd, const struct osl_object *query)
{
char *buf = query->data, *path;
struct osl_row *pb, *aft_row;
if (pb) { /* hs trumps pb, remove pb */
if (flags & ADD_FLAG_VERBOSE)
para_printf(&msg, "removing %s\n", path);
- afs_event(AUDIO_FILE_REMOVE, &msg, pb);
+ ret = afs_event(AUDIO_FILE_REMOVE, &msg, pb);
+ if (ret < 0)
+ goto out;
ret = osl(osl_del_row(audio_file_table, pb));
if (ret < 0)
goto out;
&objs[AFTCOL_PATH]));
if (ret < 0)
goto out;
- afs_event(AUDIO_FILE_RENAME, &msg, hs);
+ ret = afs_event(AUDIO_FILE_RENAME, &msg, hs);
+ if (ret < 0)
+ goto out;
if (!(flags & ADD_FLAG_FORCE))
goto out;
}
&objs[AFTCOL_CHUNKS]));
if (ret < 0)
goto out;
- afs_event(AFHI_CHANGE, &msg, row);
+ ret = afs_event(AFHI_CHANGE, &msg, row);
+ if (ret < 0)
+ goto out;
goto out;
}
/* new entry, use default afsi */
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));
- afs_event(AUDIO_FILE_ADD, &msg, aft_row);
+ ret = afs_event(AUDIO_FILE_ADD, &msg, aft_row);
out:
if (ret < 0)
- para_printf(&msg, "%s\n", para_strerror(-ret));
- if (msg.offset)
- pass_buffer_as_shm(fd, SBD_OUTPUT, msg.buf, msg.offset);
- free(msg.buf);
+ para_printf(&msg, "could not add %s\n", path);
+ flush_and_free_pb(&msg);
+ return ret;
}
/** Used by com_add(). */
uint32_t flags;
};
-static void path_brother_callback(int fd, const struct osl_object *query)
+static int path_brother_callback(int fd, const struct osl_object *query)
{
char *path = query->data;
struct osl_row *path_brother;
int ret = aft_get_row_of_path(path, &path_brother);
if (ret < 0)
- return;
- pass_buffer_as_shm(fd, SBD_OUTPUT, (char *)&path_brother,
+ return ret;
+ return pass_buffer_as_shm(fd, SBD_OUTPUT, (char *)&path_brother,
sizeof(path_brother));
}
-static void hash_sister_callback(int fd, const struct osl_object *query)
+static int hash_sister_callback(int fd, const struct osl_object *query)
{
unsigned char *hash = query->data;
struct osl_row *hash_sister;
hash_sister = find_hash_sister(hash);
if (!hash_sister)
- return;
- pass_buffer_as_shm(fd, SBD_OUTPUT, (char *)&hash_sister,
+ return 0;
+ return pass_buffer_as_shm(fd, SBD_OUTPUT, (char *)&hash_sister,
sizeof(hash_sister));
}
__a_unused uint8_t band, void *private)
{
struct osl_row **row = private;
- *row = *(struct osl_row **)(result->data);
+
+ if (band == SBD_OUTPUT)
+ *row = *(struct osl_row **)(result->data);
return 1;
}
ret = get_afsi_object_of_row(row, &obj);
if (ret < 0) {
- para_printf(&tad->pb, "%s: %s\n", name, para_strerror(-ret));
+ para_printf(&tad->pb, "cannot touch %s\n", name);
return ret;
}
ret = load_afsi(&old_afsi, &obj);
if (ret < 0) {
- para_printf(&tad->pb, "%s: %s\n", name, para_strerror(-ret));
+ para_printf(&tad->pb, "cannot touch %s\n", name);
return ret;
}
new_afsi = old_afsi;
save_afsi(&new_afsi, &obj); /* in-place update */
aced.aft_row = row;
aced.old_afsi = &old_afsi;
- afs_event(AFSI_CHANGE, &tad->pb, &aced);
- return 1;
+ return afs_event(AFSI_CHANGE, &tad->pb, &aced);
}
-static void com_touch_callback(int fd, const struct osl_object *query)
+static int com_touch_callback(int fd, const struct osl_object *query)
{
struct touch_action_data tad = {.cto = query->data,
.pb = {
if (tad.cto->flags & TOUCH_FLAG_FNM_PATHNAME)
pmd.fnmatch_flags |= FNM_PATHNAME;
ret = for_each_matching_row(&pmd);
- if (ret < 0)
- para_printf(&tad.pb, "%s\n", para_strerror(-ret));
- else if (pmd.num_matches == 0)
- para_printf(&tad.pb, "no matches\n");
- if (tad.pb.offset)
- pass_buffer_as_shm(fd, SBD_OUTPUT, tad.pb.buf, tad.pb.offset);
- free(tad.pb.buf);
+ if (ret >= 0 && pmd.num_matches == 0)
+ ret = -E_NO_MATCH;
+ flush_and_free_pb(&tad.pb);
+ return ret;
}
int com_touch(struct command_context *cc)
}
if (i >= cc->argc)
return -E_AFT_SYNTAX;
- ret = send_option_arg_callback_request(&query, cc->argc - i,
+ return send_option_arg_callback_request(&query, cc->argc - i,
cc->argv + i, com_touch_callback, afs_cb_result_handler, cc);
- if (ret < 0)
- send_strerror(cc, -ret);
- return ret;
}
/** Flags for com_rm(). */
if (crd->flags & RM_FLAG_VERBOSE)
para_printf(&crd->pb, "removing %s\n", name);
- afs_event(AUDIO_FILE_REMOVE, &crd->pb, row);
+ ret = afs_event(AUDIO_FILE_REMOVE, &crd->pb, row);
+ if (ret < 0)
+ return ret;
ret = osl(osl_del_row(audio_file_table, row));
if (ret < 0)
- para_printf(&crd->pb, "%s: %s\n", name, para_strerror(-ret));
+ para_printf(&crd->pb, "cannot remove %s\n", name);
return ret;
}
-static void com_rm_callback(int fd, const struct osl_object *query)
+static int com_rm_callback(int fd, const struct osl_object *query)
{
struct com_rm_action_data crd = {.flags = *(uint32_t *)query->data,
.pb = {
if (crd.flags & RM_FLAG_FNM_PATHNAME)
pmd.fnmatch_flags |= FNM_PATHNAME;
ret = for_each_matching_row(&pmd);
- if (ret < 0) {
- para_printf(&crd.pb, "%s\n", para_strerror(-ret));
- return;
- }
- if ((pmd.num_matches == 0) && !(crd.flags & RM_FLAG_FORCE))
- para_printf(&crd.pb, "no matches -- nothing removed\n");
+ if (ret < 0)
+ goto out;
+ if (pmd.num_matches == 0)
+ ret = -E_NO_MATCH;
else if (crd.flags & RM_FLAG_VERBOSE)
- para_printf(&crd.pb, "removed %u files\n", pmd.num_matches);
- if (ret >= 0 && crd.pb.offset)
- pass_buffer_as_shm(fd, SBD_OUTPUT, crd.pb.buf, crd.pb.offset);
- free(crd.pb.buf);
+ para_printf(&crd.pb, "removed %u file(s)\n", pmd.num_matches);
+out:
+ flush_and_free_pb(&crd.pb);
+ return ret;
}
/* TODO options: -r (recursive) */
{
uint32_t flags = 0;
struct osl_object query = {.data = &flags, .size = sizeof(flags)};
- int i, ret;
+ int i;
for (i = 1; i < cc->argc; i++) {
const char *arg = cc->argv[i];
}
if (i >= cc->argc)
return -E_AFT_SYNTAX;
- ret = send_option_arg_callback_request(&query, cc->argc - i,
+ return send_option_arg_callback_request(&query, cc->argc - i,
cc->argv + i, com_rm_callback, afs_cb_result_handler, cc);
- if (ret < 0)
- send_strerror(cc, -ret);
- return ret;
}
/**
para_printf(&cad->pb, "copied afsi to %s\n", name);
aced.aft_row = row;
aced.old_afsi = &old_afsi;
- afs_event(AFSI_CHANGE, &cad->pb, &aced);
- return 1;
+ return afs_event(AFSI_CHANGE, &cad->pb, &aced);
}
-static void com_cpsi_callback(int fd, const struct osl_object *query)
+static int com_cpsi_callback(int fd, const struct osl_object *query)
{
struct cpsi_action_data cad = {
.flags = *(unsigned *)query->data,
if (ret < 0)
goto out;
ret = for_each_matching_row(&pmd);
-out:
if (ret < 0)
- para_printf(&cad.pb, "%s\n", para_strerror(-ret));
- else if (pmd.num_matches > 0) {
+ goto out;
+ if (pmd.num_matches > 0) {
if (cad.flags & CPSI_FLAG_VERBOSE)
- para_printf(&cad.pb, "copied requested afsi from %s "
- "to %u files\n", source_path, pmd.num_matches);
+ para_printf(&cad.pb, "updated afsi of %u file(s)\n",
+ pmd.num_matches);
} else
- para_printf(&cad.pb, "no matches - nothing copied\n");
- if (cad.pb.offset)
- pass_buffer_as_shm(fd, SBD_OUTPUT, cad.pb.buf, cad.pb.offset);
- free(cad.pb.buf);
+ ret = -E_NO_MATCH;
+out:
+ flush_and_free_pb(&cad.pb);
+ return ret;
}
int com_cpsi(struct command_context *cc)
{
unsigned flags = 0;
- int i, ret;
+ int i;
struct osl_object options = {.data = &flags, .size = sizeof(flags)};
for (i = 1; i < cc->argc; i++) {
return -E_AFT_SYNTAX;
if (!(flags & ~CPSI_FLAG_VERBOSE)) /* no copy flags given */
flags = ~(unsigned)CPSI_FLAG_VERBOSE | flags;
- ret = send_option_arg_callback_request(&options, cc->argc - i,
+ return send_option_arg_callback_request(&options, cc->argc - i,
cc->argv + i, com_cpsi_callback, afs_cb_result_handler, cc);
- if (ret < 0)
- send_strerror(cc, -ret);
- return ret;
}
struct change_atts_data {
new_afsi.attributes |= cad->add_mask;
new_afsi.attributes &= ~cad->del_mask;
save_afsi(&new_afsi, &obj); /* in-place update */
- afs_event(AFSI_CHANGE, &cad->pb, &aced);
- return 1;
+ return afs_event(AFSI_CHANGE, &cad->pb, &aced);
}
-static void com_setatt_callback(int fd, const struct osl_object *query)
+static int com_setatt_callback(int fd, const struct osl_object *query)
{
char *p;
int ret;
if (ret < 0)
goto out;
if (pmd.num_matches == 0)
- para_printf(&cad.pb, "no matches\n");
+ ret = -E_NO_MATCH;
out:
- if (ret < 0)
- para_printf(&cad.pb, "%s\n", para_strerror(-ret));
- if (cad.pb.offset)
- pass_buffer_as_shm(fd, SBD_OUTPUT, cad.pb.buf, cad.pb.offset);
- free(cad.pb.buf);
+ flush_and_free_pb(&cad.pb);
+ return ret;
}
int com_setatt(struct command_context *cc)
com_setatt_callback, afs_cb_result_handler, cc);
}
-static void afs_stat_callback(int fd, const struct osl_object *query)
+static int afs_stat_callback(int fd, const struct osl_object *query)
{
int *parser_friendly = query->data;
char *buf = *parser_friendly?
parser_friendly_status_items : status_items;
if (!buf)
- return;
- pass_buffer_as_shm(fd, SBD_OUTPUT, buf, strlen(buf));
+ return 0;
+ return pass_buffer_as_shm(fd, SBD_OUTPUT, buf, strlen(buf));
}
/**
afs_cb_result_handler, cc);
}
-/* returns success even on errors to keep the loop going */
+/* returns success on non-fatal errors to keep the loop going */
static int check_audio_file(struct osl_row *row, void *data)
{
char *path;
if (ret < 0) {
para_printf(pb, "%s\n", para_strerror(-ret));
- return 0;
+ return ret;
}
if (stat(path, &statbuf) < 0)
para_printf(pb, "%s: stat error (%s)\n", path, strerror(errno));
* \param fd The afs socket.
* \param query Unused.
*
- * This function always succeeds.
+ * \return Standard. Inconsistencies are reported but not regarded as an error.
*
* \sa com_check().
*/
-void aft_check_callback(int fd, __a_unused const struct osl_object *query)
+int aft_check_callback(int fd, __a_unused const struct osl_object *query)
{
+ int ret;
struct para_buffer pb = {
.max_size = shm_get_shmmax(),
.private_data = &(struct afs_max_size_handler_data) {
.max_size_handler = afs_max_size_handler
};
para_printf(&pb, "checking audio file table...\n");
- audio_file_loop(&pb, check_audio_file);
- if (pb.offset)
- pass_buffer_as_shm(fd, SBD_OUTPUT, pb.buf, pb.offset);
- free(pb.buf);
+ ret = audio_file_loop(&pb, check_audio_file);
+ flush_and_free_pb(&pb);
+ return ret;
+}
+
+struct aft_check_atts_data {
+ uint64_t att_mask;
+ struct para_buffer *pb;
+};
+
+static int check_atts_of_audio_file(struct osl_row *row, void *data)
+{
+ struct aft_check_atts_data *acad = data;
+ int ret;
+ struct afs_info afsi;
+ char *path;
+ uint64_t bad_bits;
+
+ ret = get_afsi_of_row(row, &afsi);
+ if (ret < 0) {
+ para_printf(acad->pb, "cannot get afsi\n");
+ return ret;
+ }
+ bad_bits = afsi.attributes & ~acad->att_mask;
+ if (bad_bits == 0) /* OK */
+ return 0;
+ ret = get_audio_file_path_of_row(row, &path);
+ if (ret < 0) {
+ para_printf(acad->pb, "cannot get path\n");
+ return ret;
+ }
+ para_printf(acad->pb, "invalid attribute bits (%" PRIu64 "): %s\n",
+ bad_bits, path);
+ /* return success to keep looping */
+ return 1;
+}
+
+/**
+ * Iterate over all audio files and check the attribute bit mask.
+ *
+ * \param att_mask The mask of all valid attributes.
+ * \param pb Used for reporting inconsistencies.
+ *
+ * This reads the attribute bit mask of each audio file from the afs info
+ * structure stored in the audio file table and verifies that all set bits are
+ * also turned on in \a att_mask, i.e., correspond to an attribute of the
+ * attribute table. Audio files for which this is not the case are reported via
+ * \a pb.
+ *
+ * \return Standard. Inconsistencies are not regarded as errors.
+ *
+ * \sa \ref attribute_check_callback().
+ */
+int aft_check_attributes(uint64_t att_mask, struct para_buffer *pb)
+{
+ struct aft_check_atts_data acad = {.att_mask = att_mask, .pb = pb};
+
+ para_printf(pb, "checking attributes, mask: %" PRIx64 "\n", att_mask);
+ return audio_file_loop(&acad, check_atts_of_audio_file);
}
/**