}
}
-void flush_and_free_pb(struct para_buffer *pb)
+static void flush_and_free_pb(struct para_buffer *pb)
{
int ret;
struct afs_max_size_handler_data *amshd = pb->private_data;
static int com_select_callback(struct afs_callback_arg *aca)
{
- struct para_buffer pb = {
- .max_size = shm_get_shmmax(),
- .private_data = &(struct afs_max_size_handler_data) {
- .fd = aca->fd,
- .band = SBD_OUTPUT
- },
- .max_size_handler = afs_max_size_handler,
- };
char *arg = aca->query.data;
int num_admissible, ret;
ret = clear_score_table();
if (ret < 0) {
- para_printf(&pb, "could not clear score table: %s\n",
+ para_printf(&aca->pbout, "could not clear score table: %s\n",
para_strerror(-ret));
return ret;
}
ret = activate_mood_or_playlist(arg, &num_admissible);
if (ret >= 0)
goto out;
- para_printf(&pb, "could not activate %s: %s\n"
+ /* ignore subsequent errors (but log them) */
+ para_printf(&aca->pbout, "could not activate %s: %s\n"
"switching back to %s\n",
arg, para_strerror(-ret), current_mop? current_mop : "dummy");
- /* ignore subsequent errors (but log them) */
ret = activate_mood_or_playlist(current_mop, &num_admissible);
if (ret >= 0)
goto out;
- para_printf(&pb, "could not activate %s: %s\nswitching to dummy\n",
+ para_printf(&aca->pbout, "could not activate %s: %s\nswitching to dummy\n",
current_mop, para_strerror(-ret));
activate_mood_or_playlist(NULL, &num_admissible);
out:
- para_printf(&pb, "activated %s (%d admissible files)\n",
+ para_printf(&aca->pbout, "activated %s (%d admissible files)\n",
current_mop? current_mop : "dummy mood", num_admissible);
- flush_and_free_pb(&pb);
return ret;
}
cq = query_shm;
aca.query.data = (char *)query_shm + sizeof(*cq);
aca.query.size = cq->query_size;
+ aca.pbout.max_size = shm_get_shmmax();
+ aca.pbout.max_size_handler = afs_max_size_handler;
+ aca.pbout.private_data = &(struct afs_max_size_handler_data) {
+ .fd = fd,
+ .band = SBD_OUTPUT
+ };
ret = cq->handler(&aca);
ret2 = shm_detach(query_shm);
if (ret2 < 0) {
else
ret = ret2;
}
+ flush_and_free_pb(&aca.pbout);
if (ret < 0) {
ret2 = pass_buffer_as_shm(fd, SBD_AFS_CB_FAILURE,
(const char *)&ret, sizeof(ret));
{
uint32_t table_mask = *(uint32_t *)aca->query.data;
int i, ret;
- struct para_buffer pb = {
- .max_size = shm_get_shmmax(),
- .private_data = &(struct afs_max_size_handler_data) {
- .fd = aca->fd,
- .band = SBD_OUTPUT
- }
- };
close_afs_tables();
for (i = 0; i < NUM_AFS_TABLES; i++) {
continue;
ret = t->create(database_dir);
if (ret < 0) {
- para_printf(&pb, "cannot create table %s\n", t->name);
+ para_printf(&aca->pbout, "cannot create table %s\n",
+ t->name);
goto out;
}
- para_printf(&pb, "successfully created %s table\n", t->name);
+ para_printf(&aca->pbout, "successfully created %s table\n",
+ t->name);
}
ret = open_afs_tables();
if (ret < 0)
- para_printf(&pb, "cannot open afs tables\n");
+ para_printf(&aca->pbout, "cannot open afs tables\n");
out:
- flush_and_free_pb(&pb);
return ret;
}
int fd;
/** Callback-specific data. */
struct osl_object query;
+ /** Will be written on band SBD_OUTPUT, fully buffered. */
+ struct para_buffer pbout;
};
/**
void *private_result_data);
int string_compare(const struct osl_object *obj1, const struct osl_object *obj2);
int for_each_matching_row(struct pattern_match_data *pmd);
-void flush_and_free_pb(struct para_buffer *pb);
/* score */
void score_init(struct afs_table *t);
{
struct ls_options *opts = aca->query.data;
char *p, *pattern_start = (char *)aca->query.data + sizeof(*opts);
- struct para_buffer b = {
- .max_size = shm_get_shmmax(),
- .flags = (opts->mode == LS_MODE_PARSER)? PBF_SIZE_PREFIX : 0,
- .max_size_handler = afs_max_size_handler,
- .private_data = &(struct afs_max_size_handler_data) {
- .fd = aca->fd,
- .band = SBD_OUTPUT
- }
- };
int i = 0, ret;
time_t current_time;
+ aca->pbout.flags = (opts->mode == LS_MODE_PARSER)? PBF_SIZE_PREFIX : 0;
if (opts->num_patterns) {
opts->patterns = para_malloc(opts->num_patterns * sizeof(char *));
for (i = 0, p = pattern_start; i < opts->num_patterns; i++) {
time(¤t_time);
if (opts->flags & LS_FLAG_REVERSE)
for (i = opts->num_matching_paths - 1; i >= 0; i--) {
- ret = print_list_item(opts->data_ptr[i], opts, &b, current_time);
+ ret = print_list_item(opts->data_ptr[i], opts,
+ &aca->pbout, current_time);
if (ret < 0)
goto out;
}
else
for (i = 0; i < opts->num_matching_paths; i++) {
- ret = print_list_item(opts->data_ptr[i], opts, &b, current_time);
+ ret = print_list_item(opts->data_ptr[i], opts,
+ &aca->pbout, current_time);
if (ret < 0)
goto out;
}
out:
- flush_and_free_pb(&b);
free(opts->data);
free(opts->data_ptr);
free(opts->patterns);
char afsi_buf[AFSI_SIZE];
uint32_t flags = read_u32(buf + CAB_FLAGS_OFFSET);
struct afs_info default_afsi = {.last_played = 0};
- struct para_buffer msg = {
- .max_size = shm_get_shmmax(),
- .max_size_handler = afs_max_size_handler,
- .private_data = &(struct afs_max_size_handler_data) {
- .fd = aca->fd,
- .band = SBD_OUTPUT
- }
- };
uint16_t afhi_offset, chunks_offset;
hash = (unsigned char *)buf + CAB_HASH_OFFSET;
goto out;
if (hs && pb && hs == pb && !(flags & ADD_FLAG_FORCE)) {
if (flags & ADD_FLAG_VERBOSE)
- para_printf(&msg, "ignoring duplicate\n");
+ para_printf(&aca->pbout, "ignoring duplicate\n");
ret = 1;
goto out;
}
struct osl_object obj;
if (pb) { /* hs trumps pb, remove pb */
if (flags & ADD_FLAG_VERBOSE)
- para_printf(&msg, "removing %s\n", path);
- ret = afs_event(AUDIO_FILE_REMOVE, &msg, pb);
+ para_printf(&aca->pbout, "removing %s\n", path);
+ ret = afs_event(AUDIO_FILE_REMOVE, &aca->pbout, pb);
if (ret < 0)
goto out;
ret = osl(osl_del_row(audio_file_table, pb));
AFTCOL_PATH, &obj));
if (ret < 0)
goto out;
- para_printf(&msg, "renamed from %s\n", (char *)obj.data);
+ para_printf(&aca->pbout, "renamed from %s\n",
+ (char *)obj.data);
}
ret = osl(osl_update_object(audio_file_table, hs, AFTCOL_PATH,
&objs[AFTCOL_PATH]));
if (ret < 0)
goto out;
- ret = afs_event(AUDIO_FILE_RENAME, &msg, hs);
+ ret = afs_event(AUDIO_FILE_RENAME, &aca->pbout, hs);
if (ret < 0)
goto out;
if (!(flags & ADD_FLAG_FORCE))
goto out;
hash_to_asc(old_hash, old_asc);
if (flags & ADD_FLAG_VERBOSE)
- para_printf(&msg, "file change: %s -> %s\n", old_asc,
- asc);
+ para_printf(&aca->pbout, "file change: %s -> %s\n",
+ old_asc, asc);
ret = osl_update_object(audio_file_table, pb, AFTCOL_HASH,
&objs[AFTCOL_HASH]);
if (ret < 0)
struct osl_row *row = pb? pb : hs;
/* update afhi and chunk_table */
if (flags & ADD_FLAG_VERBOSE)
- para_printf(&msg, "updating afhi and chunk table\n");
+ para_printf(&aca->pbout,
+ "updating afhi and chunk table\n");
ret = osl(osl_update_object(audio_file_table, row, AFTCOL_AFHI,
&objs[AFTCOL_AFHI]));
if (ret < 0)
&objs[AFTCOL_CHUNKS]));
if (ret < 0)
goto out;
- ret = afs_event(AFHI_CHANGE, &msg, row);
+ ret = afs_event(AFHI_CHANGE, &aca->pbout, row);
if (ret < 0)
goto out;
goto out;
}
/* new entry, use default afsi */
if (flags & ADD_FLAG_VERBOSE)
- para_printf(&msg, "new file\n");
+ 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);
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));
- ret = afs_event(AUDIO_FILE_ADD, &msg, aft_row);
+ ret = afs_event(AUDIO_FILE_ADD, &aca->pbout, aft_row);
out:
if (ret < 0)
- para_printf(&msg, "could not add %s\n", path);
- flush_and_free_pb(&msg);
+ para_printf(&aca->pbout, "could not add %s\n", path);
return ret;
}
unsigned flags;
};
-/** Data passed to the action handler of com_touch(). */
-struct touch_action_data {
- /** Command line options (see \ref com_touch_options). */
- struct com_touch_options *cto;
- /** Message buffer. */
- struct para_buffer pb;
-};
-
static int touch_audio_file(__a_unused struct osl_table *table,
struct osl_row *row, const char *name, void *data)
{
- struct touch_action_data *tad = data;
+ struct afs_callback_arg *aca = data;
+ struct com_touch_options *cto = aca->query.data;
struct osl_object obj;
struct afs_info old_afsi, new_afsi;
- int ret, no_options = tad->cto->num_played < 0 && tad->cto->last_played < 0 &&
- tad->cto->lyrics_id < 0 && tad->cto->image_id < 0 && tad->cto->amp < 0;
+ int ret, no_options = cto->num_played < 0 && cto->last_played < 0 &&
+ cto->lyrics_id < 0 && cto->image_id < 0 && cto->amp < 0;
struct afsi_change_event_data aced;
ret = get_afsi_object_of_row(row, &obj);
if (ret < 0) {
- para_printf(&tad->pb, "cannot touch %s\n", name);
+ para_printf(&aca->pbout, "cannot touch %s\n", name);
return ret;
}
ret = load_afsi(&old_afsi, &obj);
if (ret < 0) {
- para_printf(&tad->pb, "cannot touch %s\n", name);
+ para_printf(&aca->pbout, "cannot touch %s\n", name);
return ret;
}
new_afsi = old_afsi;
if (no_options) {
new_afsi.num_played++;
new_afsi.last_played = time(NULL);
- if (tad->cto->flags & TOUCH_FLAG_VERBOSE)
- para_printf(&tad->pb, "%s: num_played = %u, "
+ if (cto->flags & TOUCH_FLAG_VERBOSE)
+ para_printf(&aca->pbout, "%s: num_played = %u, "
"last_played = now()\n", name,
new_afsi.num_played);
} else {
- if (tad->cto->flags & TOUCH_FLAG_VERBOSE)
- para_printf(&tad->pb, "touching %s\n", name);
- if (tad->cto->lyrics_id >= 0)
- new_afsi.lyrics_id = tad->cto->lyrics_id;
- if (tad->cto->image_id >= 0)
- new_afsi.image_id = tad->cto->image_id;
- if (tad->cto->num_played >= 0)
- new_afsi.num_played = tad->cto->num_played;
- if (tad->cto->last_played >= 0)
- new_afsi.last_played = tad->cto->last_played;
- if (tad->cto->amp >= 0)
- new_afsi.amp = tad->cto->amp;
+ if (cto->flags & TOUCH_FLAG_VERBOSE)
+ para_printf(&aca->pbout, "touching %s\n", name);
+ if (cto->lyrics_id >= 0)
+ new_afsi.lyrics_id = cto->lyrics_id;
+ if (cto->image_id >= 0)
+ new_afsi.image_id = cto->image_id;
+ if (cto->num_played >= 0)
+ new_afsi.num_played = cto->num_played;
+ if (cto->last_played >= 0)
+ new_afsi.last_played = cto->last_played;
+ if (cto->amp >= 0)
+ new_afsi.amp = cto->amp;
}
save_afsi(&new_afsi, &obj); /* in-place update */
aced.aft_row = row;
aced.old_afsi = &old_afsi;
- return afs_event(AFSI_CHANGE, &tad->pb, &aced);
+ return afs_event(AFSI_CHANGE, &aca->pbout, &aced);
}
static int com_touch_callback(struct afs_callback_arg *aca)
{
- struct touch_action_data tad = {.cto = aca->query.data,
- .pb = {
- .max_size = shm_get_shmmax(),
- .private_data = &(struct afs_max_size_handler_data) {
- .fd = aca->fd,
- .band = SBD_OUTPUT
- },
- .max_size_handler = afs_max_size_handler
- }
- };
int ret;
+ struct com_touch_options *cto = aca->query.data;
struct pattern_match_data pmd = {
.table = audio_file_table,
.loop_col_num = AFTCOL_HASH,
.match_col_num = AFTCOL_PATH,
- .patterns = {.data = (char *)aca->query.data + sizeof(*tad.cto),
- .size = aca->query.size - sizeof(*tad.cto)},
- .data = &tad,
+ .patterns = {
+ .data = (char *)aca->query.data
+ + sizeof(struct com_touch_options),
+ .size = aca->query.size
+ - sizeof(struct com_touch_options)
+ },
+ .data = aca,
.action = touch_audio_file
};
- if (tad.cto->flags & TOUCH_FLAG_FNM_PATHNAME)
+ if (cto->flags & TOUCH_FLAG_FNM_PATHNAME)
pmd.fnmatch_flags |= FNM_PATHNAME;
ret = for_each_matching_row(&pmd);
if (ret >= 0 && pmd.num_matches == 0)
ret = -E_NO_MATCH;
- flush_and_free_pb(&tad.pb);
return ret;
}
RM_FLAG_FNM_PATHNAME = 4
};
-/** Data passed to the action handler of com_rm(). */
-struct com_rm_action_data {
- /** Command line flags ((see \ref rm_flags). */
- uint32_t flags;
- /** Message buffer. */
- struct para_buffer pb;
-};
-
static int remove_audio_file(__a_unused struct osl_table *table,
struct osl_row *row, const char *name, void *data)
{
- struct com_rm_action_data *crd = data;
+ struct afs_callback_arg *aca = data;
+ uint32_t flags =*(uint32_t *)aca->query.data;
int ret;
- if (crd->flags & RM_FLAG_VERBOSE)
- para_printf(&crd->pb, "removing %s\n", name);
- ret = afs_event(AUDIO_FILE_REMOVE, &crd->pb, row);
+ if (flags & RM_FLAG_VERBOSE)
+ para_printf(&aca->pbout, "removing %s\n", name);
+ ret = afs_event(AUDIO_FILE_REMOVE, &aca->pbout, row);
if (ret < 0)
return ret;
ret = osl(osl_del_row(audio_file_table, row));
if (ret < 0)
- para_printf(&crd->pb, "cannot remove %s\n", name);
+ para_printf(&aca->pbout, "cannot remove %s\n", name);
return ret;
}
static int com_rm_callback(struct afs_callback_arg *aca)
{
- struct com_rm_action_data crd = {.flags = *(uint32_t *)aca->query.data,
- .pb = {
- .max_size = shm_get_shmmax(),
- .private_data = &(struct afs_max_size_handler_data) {
- .fd = aca->fd,
- .band = SBD_OUTPUT
- },
- .max_size_handler = afs_max_size_handler
- }
- };
int ret;
+ uint32_t flags = *(uint32_t *)aca->query.data;
struct pattern_match_data pmd = {
.table = audio_file_table,
.loop_col_num = AFTCOL_HASH,
.match_col_num = AFTCOL_PATH,
.patterns = {.data = (char *)aca->query.data + sizeof(uint32_t),
.size = aca->query.size - sizeof(uint32_t)},
- .data = &crd,
+ .data = aca,
.action = remove_audio_file
};
- if (crd.flags & RM_FLAG_FNM_PATHNAME)
+ if (flags & RM_FLAG_FNM_PATHNAME)
pmd.fnmatch_flags |= FNM_PATHNAME;
ret = for_each_matching_row(&pmd);
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 file(s)\n", pmd.num_matches);
+ else if (flags & RM_FLAG_VERBOSE)
+ para_printf(&aca->pbout, "removed %u file(s)\n",
+ pmd.num_matches);
out:
- flush_and_free_pb(&crd.pb);
return ret;
}
struct cpsi_action_data {
/** command line flags (see \ref cpsi_flags). */
unsigned flags;
- /** Message buffer. */
- struct para_buffer pb;
/** Values are copied from here. */
struct afs_info source_afsi;
+ /** What was passed to com_cpsi_callback(). */
+ struct afs_callback_arg *aca;
};
static int copy_selector_info(__a_unused struct osl_table *table,
target_afsi.attributes = cad->source_afsi.attributes;
save_afsi(&target_afsi, &target_afsi_obj); /* in-place update */
if (cad->flags & CPSI_FLAG_VERBOSE)
- para_printf(&cad->pb, "copied afsi to %s\n", name);
+ para_printf(&cad->aca->pbout, "copied afsi to %s\n", name);
aced.aft_row = row;
aced.old_afsi = &old_afsi;
- return afs_event(AFSI_CHANGE, &cad->pb, &aced);
+ return afs_event(AFSI_CHANGE, &cad->aca->pbout, &aced);
}
static int com_cpsi_callback(struct afs_callback_arg *aca)
{
struct cpsi_action_data cad = {
.flags = *(unsigned *)aca->query.data,
- .pb = {
- .max_size = shm_get_shmmax(),
- .private_data = &(struct afs_max_size_handler_data) {
- .fd = aca->fd,
- .band = SBD_OUTPUT
- },
- .max_size_handler = afs_max_size_handler
- }
+ .aca = aca
};
int ret;
char *source_path = (char *)aca->query.data + sizeof(cad.flags);
goto out;
if (pmd.num_matches > 0) {
if (cad.flags & CPSI_FLAG_VERBOSE)
- para_printf(&cad.pb, "updated afsi of %u file(s)\n",
+ para_printf(&aca->pbout, "updated afsi of %u file(s)\n",
pmd.num_matches);
} else
ret = -E_NO_MATCH;
out:
- flush_and_free_pb(&cad.pb);
return ret;
}
struct change_atts_data {
uint64_t add_mask, del_mask;
- struct para_buffer pb;
+ struct afs_callback_arg *aca;
};
static int change_atts(__a_unused struct osl_table *table,
new_afsi.attributes |= cad->add_mask;
new_afsi.attributes &= ~cad->del_mask;
save_afsi(&new_afsi, &obj); /* in-place update */
- return afs_event(AFSI_CHANGE, &cad->pb, &aced);
+ return afs_event(AFSI_CHANGE, &cad->aca->pbout, &aced);
}
static int com_setatt_callback(struct afs_callback_arg *aca)
char *p;
int ret;
size_t len;
- struct change_atts_data cad = {
- .pb = {
- .max_size = shm_get_shmmax(),
- .max_size_handler = afs_max_size_handler,
- .private_data = &(struct afs_max_size_handler_data) {
- .fd = aca->fd,
- .band = SBD_OUTPUT
- }
- }
- };
+ struct change_atts_data cad = {.aca = aca};
struct pattern_match_data pmd = {
.table = audio_file_table,
.loop_col_num = AFTCOL_HASH,
p[len - 1] = '\0';
ret = get_attribute_bitnum_by_name(p, &bitnum);
if (ret < 0) {
- para_printf(&cad.pb, "attribute not found: %s\n", p);
+ para_printf(&aca->pbout, "attribute not found: %s\n", p);
goto out;
}
if (c == '+')
if (pmd.num_matches == 0)
ret = -E_NO_MATCH;
out:
- flush_and_free_pb(&cad.pb);
return ret;
}
*/
int aft_check_callback(struct afs_callback_arg *aca)
{
- int ret;
- struct para_buffer pb = {
- .max_size = shm_get_shmmax(),
- .private_data = &(struct afs_max_size_handler_data) {
- .fd = aca->fd,
- .band = SBD_OUTPUT
- },
- .max_size_handler = afs_max_size_handler
- };
- para_printf(&pb, "checking audio file table...\n");
- ret = audio_file_loop(&pb, check_audio_file);
- flush_and_free_pb(&pb);
- return ret;
+ para_printf(&aca->pbout, "checking audio file table...\n");
+ return audio_file_loop(&aca->pbout, check_audio_file);
}
struct aft_check_atts_data {
};
/** Data passed to the action function of lsatt */
-struct lsatt_action_data {
- /** The result buffer. */
- struct para_buffer pb;
- /** The given flags for the lsatt command. */
- unsigned flags;
-};
-
static int print_attribute(struct osl_table *table, struct osl_row *row,
const char *name, void *data)
{
- struct lsatt_action_data *laad = data;
+ struct afs_callback_arg *aca = data;
+ unsigned flags = *(unsigned *)aca->query.data;
struct osl_object bitnum_obj;
int ret;
- if (!(laad->flags & LSATT_FLAG_LONG)) {
- para_printf(&laad->pb, "%s\n", name);
+ if (!(flags & LSATT_FLAG_LONG)) {
+ para_printf(&aca->pbout, "%s\n", name);
return 1;
}
ret = osl(osl_get_object(table, row, ATTCOL_BITNUM, &bitnum_obj));
if (ret < 0) {
- para_printf(&laad->pb, "%s: %s\n", name, para_strerror(-ret));
+ para_printf(&aca->pbout, "%s: %s\n", name, para_strerror(-ret));
return ret;
}
- para_printf(&laad->pb, "%u\t%s\n", *(unsigned char*)bitnum_obj.data,
+ para_printf(&aca->pbout, "%u\t%s\n", *(unsigned char*)bitnum_obj.data,
name);
return 1;
}
static int com_lsatt_callback(struct afs_callback_arg *aca)
{
+ unsigned flags = *(unsigned *)aca->query.data;
int ret;
- struct lsatt_action_data laad = {
- .flags = *(unsigned *)aca->query.data,
- .pb = {
- .max_size = shm_get_shmmax(),
- .private_data = &(struct afs_max_size_handler_data) {
- .fd = aca->fd,
- .band = SBD_OUTPUT
- },
- .max_size_handler = afs_max_size_handler
- }
-
- };
struct pattern_match_data pmd = {
.table = attribute_table,
.loop_col_num = ATTCOL_BITNUM,
.match_col_num = ATTCOL_NAME,
- .patterns = {.data = (char *)aca->query.data + sizeof(laad.flags),
- .size = aca->query.size - sizeof(laad.flags)},
+ .patterns = {.data = (char *)aca->query.data + sizeof(flags),
+ .size = aca->query.size - sizeof(flags)},
.pm_flags = PM_NO_PATTERN_MATCHES_EVERYTHING,
- .data = &laad,
+ .data = aca,
.action = print_attribute
};
- if (laad.flags & LSATT_FLAG_SORT_BY_ID)
+ if (flags & LSATT_FLAG_SORT_BY_ID)
pmd.loop_col_num = ATTCOL_NAME;
- if (laad.flags & LSATT_FLAG_REVERSE)
+ if (flags & LSATT_FLAG_REVERSE)
pmd.pm_flags |= PM_REVERSE_LOOP;
ret = for_each_matching_row(&pmd);
if (ret < 0)
if (pmd.num_matches == 0)
ret = -E_NO_MATCH;
out:
- flush_and_free_pb(&laad.pb);
return ret;
}
{
char *p;
int ret = 1;
- struct para_buffer pb = {
- .max_size = shm_get_shmmax(),
- .private_data = &(struct afs_max_size_handler_data) {
- .fd = aca->fd,
- .band = SBD_OUTPUT
- },
- .max_size_handler = afs_max_size_handler
- };
size_t len;
for (
len = strlen(p);
if (!len || p[len - 1] == '-' || p[len - 1] == '+') {
- para_printf(&pb, "invalid attribute name: %s\n", p);
+ para_printf(&aca->pbout, "invalid attribute name: %s\n", p);
continue;
}
ret = get_attribute_bitnum_by_name(p, &bitnum);
if (ret >= 0) {
- para_printf(&pb, "attribute \"%s\" already exists\n", p);
+ para_printf(&aca->pbout, "attribute \"%s\" already exists\n", p);
continue;
}
if (ret != -OSL_ERRNO_TO_PARA_ERROR(E_OSL_RB_KEY_NOT_FOUND)) /* error */
goto out;
aed.name = p;
aed.bitnum = bitnum;
- ret = afs_event(ATTRIBUTE_ADD, &pb, &aed);
+ ret = afs_event(ATTRIBUTE_ADD, &aca->pbout, &aed);
if (ret < 0)
goto out;
greatest_att_bitnum = PARA_MAX(greatest_att_bitnum, (int)bitnum);
}
out:
if (ret < 0)
- para_printf(&pb, "%s: %s\n", p, para_strerror(-ret));
- flush_and_free_pb(&pb);
+ para_printf(&aca->pbout, "%s: %s\n", p, para_strerror(-ret));
return 0;
}
char *new = old + size;
struct osl_object obj = {.data = old, .size = size};
struct osl_row *row;
- struct para_buffer pb = {
- .max_size = shm_get_shmmax(),
- .private_data = &(struct afs_max_size_handler_data) {
- .fd = aca->fd,
- .band = SBD_OUTPUT
- },
- .max_size_handler = afs_max_size_handler,
- };
int ret;
ret = osl(osl_get_row(attribute_table, ATTCOL_NAME, &obj, &row));
ret = osl(osl_update_object(attribute_table, row, ATTCOL_NAME, &obj));
out:
if (ret < 0)
- para_printf(&pb, "cannot rename %s to %s\n", old, new);
+ para_printf(&aca->pbout, "cannot rename %s to %s\n", old, new);
else
- ret = afs_event(ATTRIBUTE_RENAME, &pb, NULL);
- flush_and_free_pb(&pb);
+ ret = afs_event(ATTRIBUTE_RENAME, &aca->pbout, NULL);
return ret;
}
static int remove_attribute(struct osl_table *table, struct osl_row *row,
const char *name, void *data)
{
- struct para_buffer *pb = data;
+ struct afs_callback_arg *aca = data;
int ret;
struct rmatt_event_data red = {.name = name};
ret = get_attribute_bitnum_by_name(name, &red.bitnum);
if (ret < 0) {
- para_printf(pb, "cannot remove %s\n", name);
+ para_printf(&aca->pbout, "cannot remove %s\n", name);
return ret;
}
- para_printf(pb, "removing attribute %s\n", name);
+ para_printf(&aca->pbout, "removing attribute %s\n", name);
ret = osl(osl_del_row(table, row));
if (ret < 0) {
- para_printf(pb, "cannot remove %s\n", name);
+ para_printf(&aca->pbout, "cannot remove %s\n", name);
return ret;
}
- return afs_event(ATTRIBUTE_REMOVE, pb, &red);
+ return afs_event(ATTRIBUTE_REMOVE, &aca->pbout, &red);
}
static int com_rmatt_callback(struct afs_callback_arg *aca)
{
- struct para_buffer pb = {
- .max_size = shm_get_shmmax(),
- .private_data = &(struct afs_max_size_handler_data) {
- .fd = aca->fd,
- .band = SBD_OUTPUT
- },
- .max_size_handler = afs_max_size_handler,
- };
int ret;
struct pattern_match_data pmd = {
.table = attribute_table,
.patterns = aca->query,
.loop_col_num = ATTCOL_BITNUM,
.match_col_num = ATTCOL_NAME,
- .data = &pb,
+ .data = aca,
.action = remove_attribute
};
ret = for_each_matching_row(&pmd);
if (pmd.num_matches == 0)
ret = -E_NO_MATCH;
out:
- flush_and_free_pb(&pb);
return ret;
}
{
int ret;
uint64_t att_mask = 0; /* bits corresponding to a attributes */
- struct para_buffer pb = {
- .max_size = shm_get_shmmax(),
- .private_data = &(struct afs_max_size_handler_data) {
- .fd = aca->fd,
- .band = SBD_OUTPUT
- },
- .max_size_handler = afs_max_size_handler,
- };
ret = osl_rbtree_loop(attribute_table, ATTCOL_BITNUM, &att_mask,
att_logical_or);
para_strerror(-ret));
return ret;
}
- ret = aft_check_attributes(att_mask, &pb);
- flush_and_free_pb(&pb);
- return ret;
+ return aft_check_attributes(att_mask, &aca->pbout);
}
/**
BLOB_LS_FLAG_SORT_BY_ID = 4,
};
-/** Structure passed to the \p print_blob function. */
-struct lsblob_action_data {
- /** The flags given at the command line. */
- uint32_t flags;
- /** Message buffer. */
- struct para_buffer pb;
-};
-
static int print_blob(struct osl_table *table, struct osl_row *row,
const char *name, void *data)
{
- struct lsblob_action_data *lbad = data;
+ struct afs_callback_arg *aca = data;
+ uint32_t flags = *(uint32_t *)aca->query.data;
struct osl_object obj;
uint32_t id;
int ret;
- if (!(lbad->flags & BLOB_LS_FLAG_LONG)) {
- para_printf(&lbad->pb, "%s\n", name);
+ if (!(flags & BLOB_LS_FLAG_LONG)) {
+ para_printf(&aca->pbout, "%s\n", name);
return 0;
}
ret = osl(osl_get_object(table, row, BLOBCOL_ID, &obj));
if (ret < 0) {
- para_printf(&lbad->pb, "cannot list %s\n", name);
+ para_printf(&aca->pbout, "cannot list %s\n", name);
return ret;
}
id = *(uint32_t *)obj.data;
- para_printf(&lbad->pb, "%u\t%s\n", id, name);
+ para_printf(&aca->pbout, "%u\t%s\n", id, name);
return 1;
}
static int com_lsblob_callback(struct osl_table *table,
struct afs_callback_arg *aca)
{
- struct lsblob_action_data lbad = {
- .flags = *(uint32_t *)aca->query.data,
- .pb = {
- .max_size = shm_get_shmmax(),
- .private_data = &(struct afs_max_size_handler_data) {
- .fd = aca->fd,
- .band = SBD_OUTPUT
- },
- .max_size_handler = afs_max_size_handler,
- }
- };
+ uint32_t flags = *(uint32_t *)aca->query.data;
struct pattern_match_data pmd = {
.table = table,
.patterns = {.data = (char *)aca->query.data + sizeof(uint32_t),
.size = aca->query.size - sizeof(uint32_t)},
.pm_flags = PM_NO_PATTERN_MATCHES_EVERYTHING | PM_SKIP_EMPTY_NAME,
.match_col_num = BLOBCOL_NAME,
- .data = &lbad,
+ .data = aca,
.action = print_blob,
};
int ret;
- if (lbad.flags & BLOB_LS_FLAG_REVERSE)
+ if (flags & BLOB_LS_FLAG_REVERSE)
pmd.pm_flags |= PM_REVERSE_LOOP;
- if (!(lbad.flags & BLOB_LS_FLAG_SORT_BY_ID))
+ if (!(flags & BLOB_LS_FLAG_SORT_BY_ID))
pmd.loop_col_num = BLOBCOL_NAME;
else
pmd.loop_col_num = BLOBCOL_ID;
if (pmd.num_matches == 0 && pmd.patterns.size > 0)
ret = -E_NO_MATCH;
out:
- flush_and_free_pb(&lbad.pb);
return ret;
}
static int remove_blob(struct osl_table *table, struct osl_row *row,
const char *name, void *data)
{
- struct para_buffer *pb = data;
+ struct afs_callback_arg *aca = data;
int ret = osl(osl_del_row(table, row));
if (ret < 0) {
- para_printf(pb, "cannot remove %s\n", name);
+ para_printf(&aca->pbout, "cannot remove %s\n", name);
return ret;
}
return 1;
struct afs_callback_arg *aca)
{
int ret;
- struct para_buffer pb = {
- .max_size = shm_get_shmmax(),
- .private_data = &(struct afs_max_size_handler_data) {
- .fd = aca->fd,
- .band = SBD_OUTPUT
- },
- .max_size_handler = afs_max_size_handler,
- };
struct pattern_match_data pmd = {
.table = table,
.patterns = aca->query,
.loop_col_num = BLOBCOL_NAME,
.match_col_num = BLOBCOL_NAME,
.pm_flags = PM_SKIP_EMPTY_NAME,
- .data = &pb,
+ .data = aca,
.action = remove_blob
};
ret = for_each_matching_row(&pmd);
if (pmd.num_matches == 0)
ret = -E_NO_MATCH;
else {
- para_printf(&pb, "removed %d blob(s)\n", pmd.num_matches);
+ para_printf(&aca->pbout, "removed %d blob(s)\n",
+ pmd.num_matches);
ret = afs_event(BLOB_RENAME, NULL, table);
}
out:
- flush_and_free_pb(&pb);
return ret;
}
struct afs_callback_arg *aca)
{
struct osl_object objs[NUM_BLOB_COLUMNS];
- char *name = aca->query.data, *msg;
- size_t name_len = strlen(name) + 1, msg_len;
+ char *name = aca->query.data;
+ size_t name_len = strlen(name) + 1;
uint32_t id;
unsigned num_rows;
int ret;
ret = afs_event(BLOB_ADD, NULL, table);
out:
if (ret < 0)
- msg_len = xasprintf(&msg, "cannot add %s\n", name);
+ para_printf(&aca->pbout, "cannot add %s\n", name);
else
- msg_len = xasprintf(&msg, "added %s as id %u\n", name, id);
- pass_buffer_as_shm(aca->fd, SBD_OUTPUT, msg, msg_len);
- free(msg);
+ para_printf(&aca->pbout, "added %s as id %u\n", name, id);
return ret;
}
struct osl_object obj = {.data = src, .size = strlen(src) + 1};
char *dest = src + obj.size;
struct osl_row *row;
- struct para_buffer pb = {
- .max_size = shm_get_shmmax(),
- .private_data = &aca->fd,
- .max_size_handler = afs_max_size_handler
- };
int ret = osl(osl_get_row(table, BLOBCOL_NAME, &obj, &row));
if (ret < 0) {
- para_printf(&pb, "cannot find source blob %s\n", src);
+ para_printf(&aca->pbout, "cannot find source blob %s\n", src);
goto out;
}
obj.data = dest;
obj.size = strlen(dest) + 1;
ret = osl(osl_update_object(table, row, BLOBCOL_NAME, &obj));
if (ret < 0) {
- para_printf(&pb, "cannot rename blob %s to %s\n", src, dest);
+ para_printf(&aca->pbout, "cannot rename blob %s to %s\n",
+ src, dest);
goto out;
}
ret = afs_event(BLOB_RENAME, NULL, table);
out:
- flush_and_free_pb(&pb);
return ret;
}
*/
int mood_check_callback(struct afs_callback_arg *aca)
{
- int ret;
- struct para_buffer pb = {
- .max_size = shm_get_shmmax(),
- .private_data = &(struct afs_max_size_handler_data) {
- .fd = aca->fd,
- .band = SBD_OUTPUT
- },
- .max_size_handler = afs_max_size_handler
- };
-
- para_printf(&pb, "checking moods...\n");
- ret = osl(osl_rbtree_loop(moods_table, BLOBCOL_ID, &pb,
+ para_printf(&aca->pbout, "checking moods...\n");
+ return osl(osl_rbtree_loop(moods_table, BLOBCOL_ID, &aca->pbout,
check_mood));
- flush_and_free_pb(&pb);
- return ret;
}
static int64_t normalized_value(int64_t x, int64_t n, int64_t sum, int64_t qd)
*/
int playlist_check_callback(struct afs_callback_arg *aca)
{
- int ret;
- struct para_buffer pb = {
- .max_size = shm_get_shmmax(),
- .private_data = &(struct afs_max_size_handler_data) {
- .fd = aca->fd,
- .band = SBD_OUTPUT
- },
- .max_size_handler = afs_max_size_handler,
- };
- para_printf(&pb, "checking playlists...\n");
- ret = osl(osl_rbtree_loop(playlists_table, BLOBCOL_ID, &pb,
+ para_printf(&aca->pbout, "checking playlists...\n");
+ return osl(osl_rbtree_loop(playlists_table, BLOBCOL_ID, &aca->pbout,
check_playlist));
- flush_and_free_pb(&pb);
- return ret;
}
/**