1 /* Copyright (C) 2007 Andre Noll <maan@tuebingen.mpg.de>, see file COPYING. */
3 /** \file aft.c Audio file table functions. */
12 #include "server_cmd.lsg.h"
21 #include "portable_io.h"
25 /* Data about one audio file. Needed for ls and stat output. */
27 /* Usual audio format handler information. */
29 /* Audio file selector information. */
31 /* The full path of the audio file. */
33 /* The score value (if -a was given). */
35 /* The hash value of the audio file data. */
40 * The internal state of the audio file table is described by the following
41 * variables which are private to aft.c.
43 static struct osl_table
*audio_file_table
; /* NULL if table not open */
44 static struct osl_row
*current_aft_row
; /* NULL if no audio file open */
45 static unsigned char current_hash
[HASH2_SIZE
]; /* only used on sighup */
47 static char *status_items
;
48 static char *parser_friendly_status_items
;
49 static struct ls_data status_item_ls_data
;
51 /** The different sorting methods of the ls command. */
52 enum ls_sorting_method
{
53 LS_SORT_BY_PATH
, /**< -s=p (default) */
54 LS_SORT_BY_SCORE
, /**< -s=s */
55 LS_SORT_BY_LAST_PLAYED
, /**< -s=l */
56 LS_SORT_BY_NUM_PLAYED
, /**< -s=n */
57 LS_SORT_BY_FREQUENCY
, /**< -s=f */
58 LS_SORT_BY_CHANNELS
, /**< -s=c */
59 LS_SORT_BY_IMAGE_ID
, /**< -s=i */
60 LS_SORT_BY_LYRICS_ID
, /**< -s=y */
61 LS_SORT_BY_BITRATE
, /**< -s=b */
62 LS_SORT_BY_DURATION
, /**< -s=d */
63 LS_SORT_BY_AUDIO_FORMAT
, /**< -s=a */
64 LS_SORT_BY_HASH
, /**< -s=h */
67 /** The different listing modes of the ls command. */
68 enum ls_listing_mode
{
69 LS_MODE_SHORT
, /**< Default listing mode. */
70 LS_MODE_LONG
, /**< -l or -l=l */
71 LS_MODE_VERBOSE
, /** -l=v */
72 LS_MODE_MBOX
, /** -l=m */
73 LS_MODE_CHUNKS
, /** -l=c */
74 LS_MODE_PARSER
, /** -l=p */
78 * The size of the individual output fields of the ls command.
80 * These depend on the content being listed. For example, if each listed file
81 * is shorter than an hour, the duration format is set to mm:ss. Otherwise it
85 /** size of the score field. */
86 unsigned short score_width
;
87 /** size of the image id field. */
88 unsigned short image_id_width
;
89 /** size of the lyrics id field. */
90 unsigned short lyrics_id_width
;
91 /** size of the bitrate field. */
92 unsigned short bitrate_width
;
93 /** size of the frequency field. */
94 unsigned short frequency_width
;
95 /** size of the duration field. */
96 unsigned short duration_width
;
97 /** size of the num played field. */
98 unsigned short num_played_width
;
99 /** size of the amp field. */
100 unsigned short amp_width
;
101 /** size of the audio format field. */
102 unsigned short audio_format_width
;
105 /** Data passed from the ls command handler to its callback function. */
107 struct lls_parse_result
*lpr
;
108 /* Derived from lpr */
109 enum ls_sorting_method sorting
;
110 /* Derived from lpr */
111 enum ls_listing_mode mode
;
112 /** Used for long listing mode to align the output fields. */
113 struct ls_widths widths
;
114 /** Size of the \a data array. */
116 /** Number of used entries in the data array. */
117 uint32_t num_matching_paths
;
118 /** Array of matching entries. */
119 struct ls_data
*data
;
120 /** Used to sort the array. */
121 struct ls_data
**data_ptr
;
125 * Describes the layout of the mmapped-afs info struct.
127 * \sa struct \ref afs_info.
130 /** Where .last_played is stored. */
131 AFSI_LAST_PLAYED_OFFSET
= 0,
132 /** Storage position of the attributes bitmap. */
133 AFSI_ATTRIBUTES_OFFSET
= 8,
134 /** Storage position of the .num_played field. */
135 AFSI_NUM_PLAYED_OFFSET
= 16,
136 /** Storage position of the .image_id field. */
137 AFSI_IMAGE_ID_OFFSET
= 20,
138 /** Storage position of the .lyrics_id field. */
139 AFSI_LYRICS_ID_OFFSET
= 24,
140 /** Storage position of the .audio_format_id field. */
141 AFSI_AUDIO_FORMAT_ID_OFFSET
= 28,
142 /** Storage position of the amplification field. */
143 AFSI_AMP_OFFSET
= 29,
144 /** 2 bytes reserved space for future usage. */
145 AFSI_AUDIO_FORMAT_UNUSED_OFFSET
= 30,
146 /** On-disk storage space needed. */
151 * Convert a struct afs_info to an osl object.
153 * \param afsi Pointer to the audio file info to be converted.
154 * \param obj Result pointer.
156 * \sa \ref load_afsi().
158 static void save_afsi(struct afs_info
*afsi
, struct osl_object
*obj
)
160 char *buf
= obj
->data
;
162 write_u64(buf
+ AFSI_LAST_PLAYED_OFFSET
, afsi
->last_played
);
163 write_u64(buf
+ AFSI_ATTRIBUTES_OFFSET
, afsi
->attributes
);
164 write_u32(buf
+ AFSI_NUM_PLAYED_OFFSET
, afsi
->num_played
);
165 write_u32(buf
+ AFSI_IMAGE_ID_OFFSET
, afsi
->image_id
);
166 write_u32(buf
+ AFSI_LYRICS_ID_OFFSET
, afsi
->lyrics_id
);
167 write_u8(buf
+ AFSI_AUDIO_FORMAT_ID_OFFSET
,
168 afsi
->audio_format_id
);
169 write_u8(buf
+ AFSI_AMP_OFFSET
, afsi
->amp
);
170 memset(buf
+ AFSI_AUDIO_FORMAT_UNUSED_OFFSET
, 0, 2);
174 * Get the audio file selector info struct stored in an osl object.
176 * \param afsi Points to the audio_file info structure to be filled in.
177 * \param obj The osl object holding the data.
181 * \sa \ref save_afsi().
183 static int load_afsi(struct afs_info
*afsi
, struct osl_object
*obj
)
185 char *buf
= obj
->data
;
186 if (obj
->size
< AFSI_SIZE
)
188 afsi
->last_played
= read_u64(buf
+ AFSI_LAST_PLAYED_OFFSET
);
189 afsi
->attributes
= read_u64(buf
+ AFSI_ATTRIBUTES_OFFSET
);
190 afsi
->num_played
= read_u32(buf
+ AFSI_NUM_PLAYED_OFFSET
);
191 afsi
->image_id
= read_u32(buf
+ AFSI_IMAGE_ID_OFFSET
);
192 afsi
->lyrics_id
= read_u32(buf
+ AFSI_LYRICS_ID_OFFSET
);
193 afsi
->audio_format_id
= read_u8(buf
+
194 AFSI_AUDIO_FORMAT_ID_OFFSET
);
195 afsi
->amp
= read_u8(buf
+ AFSI_AMP_OFFSET
);
199 /** The columns of the audio file table. */
200 enum audio_file_table_columns
{
201 /** The hash on the content of the audio file. */
203 /** The full path in the filesystem. */
205 /** The audio file selector info. */
207 /** The audio format handler info. */
209 /** The chunk table info and the chunk table of the audio file. */
211 /** The number of columns of this table. */
215 /* compare function for the hash column */
216 static int aft_hash_compare(const struct osl_object
*obj1
,
217 const struct osl_object
*obj2
)
219 return hash_compare((unsigned char *)obj1
->data
,
220 (unsigned char *)obj2
->data
);
223 static struct osl_column_description aft_cols
[] = {
225 .storage_type
= OSL_MAPPED_STORAGE
,
226 .storage_flags
= OSL_RBTREE
| OSL_FIXED_SIZE
| OSL_UNIQUE
,
228 .compare_function
= aft_hash_compare
,
229 .data_size
= HASH2_SIZE
232 .storage_type
= OSL_MAPPED_STORAGE
,
233 .storage_flags
= OSL_RBTREE
| OSL_UNIQUE
,
235 .compare_function
= string_compare
,
238 .storage_type
= OSL_MAPPED_STORAGE
,
239 .storage_flags
= OSL_FIXED_SIZE
,
241 .data_size
= AFSI_SIZE
244 .storage_type
= OSL_MAPPED_STORAGE
,
248 .storage_type
= OSL_DISK_STORAGE
,
253 static struct osl_table_description audio_file_table_desc
= {
254 .name
= "audio-files",
255 .num_columns
= NUM_AFT_COLUMNS
,
256 .flags
= OSL_LARGE_TABLE
,
257 .column_descriptions
= aft_cols
261 * Produce a canonicalized absolute pathname.
263 * Returns one if the resolved path a directory, zero if it is a regular file,
264 * negative on errors.
266 static int verify_path(const char *orig_path
, char **resolved_path
)
272 if (*orig_path
!= '/') /* we only accept absolute paths */
274 path
= realpath(orig_path
, NULL
);
277 if (stat(path
, &statbuf
) < 0)
279 if (S_ISREG(statbuf
.st_mode
))
281 else if (S_ISDIR(statbuf
.st_mode
))
285 *resolved_path
= path
;
288 *resolved_path
= NULL
;
293 /** The on-disk layout of a afhi struct. */
295 /** Where the number of seconds is stored. */
296 AFHI_SECONDS_TOTAL_OFFSET
= 0,
297 /** Position of the bitrate. */
298 AFHI_BITRATE_OFFSET
= 4,
299 /** Position of the frequency. */
300 AFHI_FREQUENCY_OFFSET
= 8,
301 /** Was: Location of the audio file header. */
302 AFHI_UNUSED1_OFFSET
= 12,
303 /* Length of the audio file header. Zero means: No header. */
304 AFHI_HEADER_LEN_OFFSET
= 16,
305 /** The total number of chunks (4 bytes). */
306 CHUNKS_TOTAL_OFFSET
= 20,
307 /** The length of the audio file header (4 bytes). */
308 HEADER_LEN_OFFSET
= 24,
309 /** Size of the largest chunk in bytes. (4 bytes). */
310 AFHI_MAX_CHUNK_SIZE_OFFSET
= 28,
311 /** The seconds part of the chunk time (4 bytes). */
312 CHUNK_TV_TV_SEC_OFFSET
= 32,
313 /** The microseconds part of the chunk time (4 bytes). */
314 CHUNK_TV_TV_USEC_OFFSET
= 36,
315 /** Number of channels is stored here. (1 byte) */
316 AFHI_CHANNELS_OFFSET
= 40,
317 /** The tag info position. */
318 AFHI_INFO_STRING_OFFSET
= 41,
319 /** Minimal on-disk size of a valid afhi struct. */
320 MIN_AFHI_SIZE
= 47, /* at least 6 null bytes for techinfo/tags */
323 static unsigned sizeof_afhi_buf(const struct afh_info
*afhi
)
328 + strlen(afhi
->techinfo
)
329 + strlen(afhi
->tags
.artist
)
330 + strlen(afhi
->tags
.title
)
331 + strlen(afhi
->tags
.year
)
332 + strlen(afhi
->tags
.album
)
333 + strlen(afhi
->tags
.comment
);
336 static void save_afhi(struct afh_info
*afhi
, char *buf
)
342 write_u32(buf
+ AFHI_SECONDS_TOTAL_OFFSET
, afhi
->seconds_total
);
343 write_u32(buf
+ AFHI_BITRATE_OFFSET
, afhi
->bitrate
);
344 write_u32(buf
+ AFHI_FREQUENCY_OFFSET
, afhi
->frequency
);
345 write_u32(buf
+ AFHI_UNUSED1_OFFSET
, 0);
346 write_u32(buf
+ AFHI_HEADER_LEN_OFFSET
, afhi
->header_len
);
347 write_u8(buf
+ AFHI_CHANNELS_OFFSET
, afhi
->channels
);
348 write_u32(buf
+ CHUNKS_TOTAL_OFFSET
, afhi
->chunks_total
);
349 write_u32(buf
+ HEADER_LEN_OFFSET
, afhi
->header_len
);
350 write_u32(buf
+ AFHI_MAX_CHUNK_SIZE_OFFSET
, afhi
->max_chunk_size
);
351 write_u32(buf
+ CHUNK_TV_TV_SEC_OFFSET
, afhi
->chunk_tv
.tv_sec
);
352 write_u32(buf
+ CHUNK_TV_TV_USEC_OFFSET
, afhi
->chunk_tv
.tv_usec
);
353 p
= buf
+ AFHI_INFO_STRING_OFFSET
;
355 * The below sprintf(3) calls are OK because our caller already made
356 * sure that buf is large enough.
358 p
+= sprintf(p
, "%s", afhi
->techinfo
) + 1;
359 p
+= sprintf(p
, "%s", afhi
->tags
.artist
) + 1;
360 p
+= sprintf(p
, "%s", afhi
->tags
.title
) + 1;
361 p
+= sprintf(p
, "%s", afhi
->tags
.year
) + 1;
362 p
+= sprintf(p
, "%s", afhi
->tags
.album
) + 1;
363 sprintf(p
, "%s", afhi
->tags
.comment
);
366 /* does not load the chunk table */
367 static void load_afhi(const char *buf
, struct afh_info
*afhi
)
369 afhi
->seconds_total
= read_u32(buf
+ AFHI_SECONDS_TOTAL_OFFSET
);
370 afhi
->bitrate
= read_u32(buf
+ AFHI_BITRATE_OFFSET
);
371 afhi
->frequency
= read_u32(buf
+ AFHI_FREQUENCY_OFFSET
);
372 afhi
->header_len
= read_u32(buf
+ AFHI_HEADER_LEN_OFFSET
);
373 afhi
->channels
= read_u8(buf
+ AFHI_CHANNELS_OFFSET
);
374 afhi
->chunks_total
= read_u32(buf
+ CHUNKS_TOTAL_OFFSET
);
375 afhi
->header_len
= read_u32(buf
+ HEADER_LEN_OFFSET
);
376 afhi
->max_chunk_size
= read_u32(buf
+ AFHI_MAX_CHUNK_SIZE_OFFSET
);
377 afhi
->chunk_tv
.tv_sec
= read_u32(buf
+ CHUNK_TV_TV_SEC_OFFSET
);
378 afhi
->chunk_tv
.tv_usec
= read_u32(buf
+ CHUNK_TV_TV_USEC_OFFSET
);
379 afhi
->techinfo
= (char *)buf
+ AFHI_INFO_STRING_OFFSET
;
380 afhi
->tags
.artist
= afhi
->techinfo
+ strlen(afhi
->techinfo
) + 1;
381 afhi
->tags
.title
= afhi
->tags
.artist
+ strlen(afhi
->tags
.artist
) + 1;
382 afhi
->tags
.year
= afhi
->tags
.title
+ strlen(afhi
->tags
.title
) + 1;
383 afhi
->tags
.album
= afhi
->tags
.year
+ strlen(afhi
->tags
.year
) + 1;
384 afhi
->tags
.comment
= afhi
->tags
.album
+ strlen(afhi
->tags
.album
) + 1;
387 /* Only used for saving the chunk table, but not for loading. */
388 static unsigned sizeof_chunk_table(struct afh_info
*afhi
)
390 if (!afhi
|| !afhi
->chunk_table
)
392 return 4 * (afhi
->chunks_total
+ 1);
395 static void save_chunk_table(struct afh_info
*afhi
, char *buf
)
399 if (!afhi
->chunk_table
|| afhi
->chunks_total
== 0)
401 for (n
= 0; n
<= afhi
->chunks_total
; n
++)
402 write_u32(buf
+ 4 * n
, afhi
->chunk_table
[n
]);
405 static void load_chunk_table(struct afh_info
*afhi
, const struct osl_object
*ct
)
410 if (!ct
->data
|| ct
->size
< 4 * (afhi
->chunks_total
+ 1)) {
411 afhi
->chunk_table
= NULL
;
414 sz
= PARA_MIN(((size_t)afhi
->chunks_total
+ 1) * 4, ct
->size
) + 1;
415 afhi
->chunk_table
= alloc(sz
);
416 for (i
= 0; i
<= afhi
->chunks_total
&& i
* 4 + 3 < ct
->size
; i
++)
417 afhi
->chunk_table
[i
] = read_u32(ct
->data
+ 4 * i
);
421 * Get the row of the audio file table corresponding to the given path.
423 * \param path The full path of the audio file.
424 * \param row Result pointer.
428 int aft_get_row_of_path(const char *path
, struct osl_row
**row
)
430 struct osl_object obj
= {.data
= (char *)path
, .size
= strlen(path
) + 1};
432 return osl(osl_get_row(audio_file_table
, AFTCOL_PATH
, &obj
, row
));
436 * Get the row of the audio file table corresponding to the given hash value.
438 * \param hash The hash value of the desired audio file.
439 * \param row Result pointer.
443 static int aft_get_row_of_hash(unsigned char *hash
, struct osl_row
**row
)
445 const struct osl_object obj
= {.data
= hash
, .size
= HASH2_SIZE
};
446 return osl(osl_get_row(audio_file_table
, AFTCOL_HASH
, &obj
, row
));
450 * Get the audio file selector info object of a row.
452 * \param row Pointer to a row in the audio file table.
453 * \param obj Result pointer.
457 static int get_afsi_object_of_row(const struct osl_row
*row
,
458 struct osl_object
*obj
)
460 return osl(osl_get_object(audio_file_table
, row
, AFTCOL_AFSI
, obj
));
464 * Get the osl object holding the audio file selector info, given a path.
467 * \param path The full path of the audio file.
468 * \param obj Result pointer.
470 * \return Positive on success, negative on errors.
472 static int get_afsi_object_of_path(const char *path
, struct osl_object
*obj
)
475 int ret
= aft_get_row_of_path(path
, &row
);
478 return get_afsi_object_of_row(row
, obj
);
482 * Get the audio file selector info, given a row of the audio file table.
484 * \param row Pointer to a row in the audio file table.
485 * \param afsi Result pointer.
487 * \return Positive on success, negative on errors.
489 int get_afsi_of_row(const struct osl_row
*row
, struct afs_info
*afsi
)
491 struct osl_object obj
;
492 int ret
= get_afsi_object_of_row(row
, &obj
);
495 return load_afsi(afsi
, &obj
);
499 * Get the audio file selector info, given the path of an audio table.
501 * \param path The full path of the audio file.
502 * \param afsi Result pointer.
506 static int get_afsi_of_path(const char *path
, struct afs_info
*afsi
)
508 struct osl_object obj
;
509 int ret
= get_afsi_object_of_path(path
, &obj
);
512 return load_afsi(afsi
, &obj
);
516 * Get the path of an audio file, given a row of the audio file table.
518 * \param row Pointer to a row in the audio file table.
519 * \param path Result pointer.
521 * The result is a pointer to memory-mapped data. The caller must not attempt
526 int get_audio_file_path_of_row(const struct osl_row
*row
, char **path
)
528 struct osl_object path_obj
;
529 int ret
= osl(osl_get_object(audio_file_table
, row
, AFTCOL_PATH
,
535 *path
= path_obj
.data
;
540 * Get the object containing the hash value of an audio file, given a row.
542 * \param row Pointer to a row of the audio file table.
543 * \param obj Result pointer.
545 * \return The return value of the underlying call to osl_get_object().
547 * \sa \ref get_hash_of_row().
549 static int get_hash_object_of_aft_row(const struct osl_row
*row
,
550 struct osl_object
*obj
)
552 return osl(osl_get_object(audio_file_table
, row
, AFTCOL_HASH
, obj
));
556 * Get the hash value of an audio file, given a row of the audio file table.
558 * \param row Pointer to a row of the audio file table.
559 * \param hash Result pointer.
561 * \a hash points to mapped data and must not be freed by the caller.
563 * \return The return value of the underlying call to
564 * get_hash_object_of_aft_row().
566 static int get_hash_of_row(const struct osl_row
*row
, unsigned char **hash
)
568 struct osl_object obj
;
569 int ret
= get_hash_object_of_aft_row(row
, &obj
);
578 * Get the audio format handler info, given a row of the audio file table.
580 * \param row Pointer to a row of the audio file table.
581 * \param afhi Result pointer.
583 * \return The return value of the underlying call to osl_get_object().
585 * After the call the members of the afhi structure point to mapped memory
586 * which is owned by the osl table, Hence the caller must not attempt to free
587 * this memory by calling \ref clear_afhi().
589 int get_afhi_of_row(const struct osl_row
*row
, struct afh_info
*afhi
)
591 struct osl_object obj
;
595 ret
= osl(osl_get_object(audio_file_table
, row
, AFTCOL_AFHI
, &obj
));
598 load_afhi(obj
.data
, afhi
);
602 /* returns shmid on success */
603 static int save_afd(struct audio_file_data
*afd
)
605 size_t size
= sizeof(*afd
) + sizeof_chunk_table(&afd
->afhi
);
606 int shmid
, ret
= shm_new(size
);
613 ret
= shm_attach(shmid
, ATTACH_RW
, &shm_afd
);
618 save_chunk_table(&afd
->afhi
, buf
);
619 if (afd
->afhi
.max_chunk_size
== 0) { /* v0.5.x on-disk afhi */
620 set_max_chunk_size(&afd
->afhi
);
621 PARA_NOTICE_LOG("max chunk size unset, re-add required\n");
623 PARA_INFO_LOG("using max chunk size from afhi\n");
624 afd
->max_chunk_size
= afd
->afhi
.max_chunk_size
;
625 *(struct audio_file_data
*)shm_afd
= *afd
;
634 * Extract a afd stored in a shared memory area.
636 * Attach the shared memory area given by \a shmid, load the audio file data
637 * stored therein and detach the area afterwards. Called by vss, after
638 * receiving a positive response to the request for the next audio file.
640 * \param shmid The identifier of the shared memory area containing the afd.
641 * \param afd Result pointer.
645 int load_afd(int shmid
, struct audio_file_data
*afd
)
649 struct osl_object obj
;
651 ret
= shm_attach(shmid
, ATTACH_RO
, &shm_afd
);
654 ret
= shm_size(shmid
, &obj
.size
);
657 *afd
= *(struct audio_file_data
*)shm_afd
;
658 obj
.data
= shm_afd
+ sizeof(*afd
);
659 obj
.size
-= sizeof(*afd
);
660 load_chunk_table(&afd
->afhi
, &obj
);
667 static int get_local_time(uint64_t *seconds
, char *buf
, size_t size
,
668 time_t current_time
, enum ls_listing_mode lm
)
672 * Omit year but show time if the given value is closer to the current
673 * time than this many seconds.
675 const time_t m
= 6 * 30 * 24 * 3600; /* six months */
677 tm
= localtime((time_t *)seconds
);
680 if (lm
== LS_MODE_MBOX
) {
681 if (!strftime(buf
, size
, "%c", tm
))
685 if (*seconds
> current_time
- m
&& *seconds
< current_time
+ m
) {
686 if (!strftime(buf
, size
, "%b %e %k:%M", tm
))
691 * If the given time is more than six month away from the current time,
692 * we print only the year. The additional space character in the format
693 * string below makes the formatted date align nicely with dates that
694 * contain the time (those written by the above strftime() statement).
696 if (!strftime(buf
, size
, "%b %e %Y", tm
))
701 /** Compute the number of (decimal) digits of a number. */
702 #define GET_NUM_DIGITS(x, num) { \
703 typeof((x)) _tmp = PARA_ABS(x); \
706 while ((_tmp) > 9) { \
712 __a_const
static short unsigned get_duration_width(int seconds
)
714 short unsigned width
;
715 unsigned hours
= seconds
/ 3600, mins
= (seconds
% 3600) / 60;
717 if (!hours
) /* less than one hour => m:ss or mm:ss => 4 or 5 digits */
718 return 4 + (mins
> 9);
719 /* more than one hour => h:mm:ss, hh:mm:ss, hhh:mm:ss, ... */
720 GET_NUM_DIGITS(hours
, &width
);
724 static void get_duration_buf(int seconds
, char *buf
, size_t bufsize
,
725 struct ls_options
*opts
)
727 unsigned hours
= seconds
/ 3600, mins
= (seconds
% 3600) / 60;
728 short unsigned max_width
;
730 if (!hours
) { /* m:ss or mm:ss */
731 max_width
= opts
->mode
== LS_MODE_LONG
?
732 opts
->widths
.duration_width
: 4;
733 assert(max_width
< bufsize
- 1);
734 sprintf(buf
, "%*u:%02d", max_width
- 3, mins
, seconds
% 60);
735 } else { /* more than one hour => h:mm:ss, hh:mm:ss, hhh:mm:ss, ... */
736 max_width
= opts
->mode
== LS_MODE_LONG
?
737 opts
->widths
.duration_width
: 7;
738 assert(max_width
< bufsize
- 1);
739 sprintf(buf
, "%*u:%02u:%02d", max_width
- 6, hours
, mins
,
744 static int write_attribute_items(struct para_buffer
*b
,
745 const char *att_bitmap
, struct afs_info
*afsi
)
750 WRITE_STATUS_ITEM(b
, SI_attributes_bitmap
, "%s\n", att_bitmap
);
751 ret
= get_attribute_text(&afsi
->attributes
, " ", &att_text
);
754 WRITE_STATUS_ITEM(b
, SI_attributes_txt
, "%s\n", att_text
);
759 static void write_lyrics_items(struct para_buffer
*b
, struct afs_info
*afsi
)
763 WRITE_STATUS_ITEM(b
, SI_lyrics_id
, "%u\n", afsi
->lyrics_id
);
764 lyr_get_name_by_id(afsi
->lyrics_id
, &lyrics_name
);
765 WRITE_STATUS_ITEM(b
, SI_lyrics_name
, "%s\n", lyrics_name
?
766 lyrics_name
: "(none)");
769 static void write_image_items(struct para_buffer
*b
, struct afs_info
*afsi
)
773 WRITE_STATUS_ITEM(b
, SI_image_id
, "%u\n", afsi
->image_id
);
774 img_get_name_by_id(afsi
->image_id
, &image_name
);
775 WRITE_STATUS_ITEM(b
, SI_image_name
, "%s\n", image_name
?
776 image_name
: "(none)");
779 static void write_filename_items(struct para_buffer
*b
, const char *path
,
785 WRITE_STATUS_ITEM(b
, SI_basename
, "%s\n", path
);
788 WRITE_STATUS_ITEM(b
, SI_path
, "%s\n", path
);
789 slash
= strrchr(path
, '/');
790 WRITE_STATUS_ITEM(b
, SI_basename
, "%s\n", slash
? slash
+ 1 : path
);
791 WRITE_STATUS_ITEM(b
, SI_directory
, "%.*s\n",
792 slash
? (int)(slash
- path
) : (int)strlen(path
), path
);
795 static int print_chunk_table(struct ls_data
*d
, struct para_buffer
*b
)
797 struct osl_object chunk_table_obj
;
798 struct osl_row
*aft_row
;
802 ret
= aft_get_row_of_hash(d
->hash
, &aft_row
);
805 ret
= osl(osl_open_disk_object(audio_file_table
, aft_row
,
806 AFTCOL_CHUNKS
, &chunk_table_obj
));
809 para_printf(b
, "%s\n"
810 "chunk_time: %lu:%lu\nchunk_offsets: ",
812 (long unsigned) d
->afhi
.chunk_tv
.tv_sec
,
813 (long unsigned) d
->afhi
.chunk_tv
.tv_usec
815 buf
= chunk_table_obj
.data
;
818 i
<= d
->afhi
.chunks_total
&& 4 * i
+ 3 < chunk_table_obj
.size
;
821 para_printf(b
, "%u ", (unsigned) read_u32(buf
+ 4 * i
));
822 para_printf(b
, "\n");
824 osl_close_disk_object(&chunk_table_obj
);
828 static int print_list_item(struct ls_data
*d
, struct ls_options
*opts
,
829 struct para_buffer
*b
, time_t current_time
)
831 const struct lls_opt_result
*r_a
= SERVER_CMD_OPT_RESULT(LS
, ADMISSIBLE
, opts
->lpr
);
832 const struct lls_opt_result
*r_b
= SERVER_CMD_OPT_RESULT(LS
, BASENAME
, opts
->lpr
);
833 const struct lls_opt_result
*r_d
= SERVER_CMD_OPT_RESULT(LS
, UNIX_DATE
, opts
->lpr
);
836 char last_played_time
[30];
837 char duration_buf
[30]; /* nobody has an audio file long enough to overflow this */
838 struct afs_info
*afsi
= &d
->afsi
;
839 struct afh_info
*afhi
= &d
->afhi
;
840 char asc_hash
[2 * HASH2_SIZE
+ 1];
842 if (opts
->mode
== LS_MODE_SHORT
) {
843 para_printf(b
, "%s\n", d
->path
);
847 if (opts
->mode
== LS_MODE_CHUNKS
) {
848 ret
= print_chunk_table(d
, b
);
851 get_attribute_bitmap(&afsi
->attributes
, att_buf
);
852 if (lls_opt_given(r_d
))
853 sprintf(last_played_time
, "%llu",
854 (long long unsigned)afsi
->last_played
);
856 ret
= get_local_time(&afsi
->last_played
, last_played_time
,
857 sizeof(last_played_time
), current_time
, opts
->mode
);
861 get_duration_buf(afhi
->seconds_total
, duration_buf
,
862 sizeof(duration_buf
), opts
);
863 if (opts
->mode
== LS_MODE_LONG
) {
864 struct ls_widths
*w
= &opts
->widths
;
865 if (lls_opt_given(r_a
))
866 para_printf(b
, "%*li ", opts
->widths
.score_width
,
869 "%s " /* attributes */
871 "%*u " /* image_id */
872 "%*u " /* lyrics_id */
874 "%*s " /* audio format */
875 "%*u " /* frequency */
878 "%*u " /* num_played */
879 "%s " /* last_played */
882 w
->amp_width
, afsi
->amp
,
883 w
->image_id_width
, afsi
->image_id
,
884 w
->lyrics_id_width
, afsi
->lyrics_id
,
885 w
->bitrate_width
, afhi
->bitrate
,
886 w
->audio_format_width
,
887 audio_format_name(afsi
->audio_format_id
),
888 w
->frequency_width
, afhi
->frequency
,
891 w
->num_played_width
, afsi
->num_played
,
898 if (opts
->mode
== LS_MODE_MBOX
) {
899 const char *slash
= strrchr(d
->path
, '/');
901 "From foo@localhost %s\n"
902 "Received: from\nTo: bar\nFrom: a\n"
905 slash
? slash
+ 1 : "?");
907 write_filename_items(b
, d
->path
, lls_opt_given(r_b
));
908 if (lls_opt_given(r_a
))
909 WRITE_STATUS_ITEM(b
, SI_score
, "%li\n", d
->score
);
910 ret
= write_attribute_items(b
, att_buf
, afsi
);
913 write_image_items(b
, afsi
);
914 write_lyrics_items(b
, afsi
);
915 hash_to_asc(d
->hash
, asc_hash
);
916 WRITE_STATUS_ITEM(b
, SI_hash
, "%s\n", asc_hash
);
917 WRITE_STATUS_ITEM(b
, SI_bitrate
, "%dkbit/s\n", afhi
->bitrate
);
918 WRITE_STATUS_ITEM(b
, SI_format
, "%s\n",
919 audio_format_name(afsi
->audio_format_id
));
920 WRITE_STATUS_ITEM(b
, SI_frequency
, "%dHz\n", afhi
->frequency
);
921 WRITE_STATUS_ITEM(b
, SI_channels
, "%d\n", afhi
->channels
);
922 WRITE_STATUS_ITEM(b
, SI_duration
, "%s\n", duration_buf
);
923 WRITE_STATUS_ITEM(b
, SI_seconds_total
, "%" PRIu32
"\n",
924 afhi
->seconds_total
);
925 WRITE_STATUS_ITEM(b
, SI_last_played
, "%s\n", last_played_time
);
926 WRITE_STATUS_ITEM(b
, SI_num_played
, "%u\n", afsi
->num_played
);
927 WRITE_STATUS_ITEM(b
, SI_amplification
, "%u\n", afsi
->amp
);
928 WRITE_STATUS_ITEM(b
, SI_chunk_time
, "%lu\n", tv2ms(&afhi
->chunk_tv
));
929 WRITE_STATUS_ITEM(b
, SI_num_chunks
, "%" PRIu32
"\n",
931 WRITE_STATUS_ITEM(b
, SI_max_chunk_size
, "%" PRIu32
"\n",
932 afhi
->max_chunk_size
);
933 WRITE_STATUS_ITEM(b
, SI_techinfo
, "%s\n", afhi
->techinfo
);
934 WRITE_STATUS_ITEM(b
, SI_artist
, "%s\n", afhi
->tags
.artist
);
935 WRITE_STATUS_ITEM(b
, SI_title
, "%s\n", afhi
->tags
.title
);
936 WRITE_STATUS_ITEM(b
, SI_year
, "%s\n", afhi
->tags
.year
);
937 WRITE_STATUS_ITEM(b
, SI_album
, "%s\n", afhi
->tags
.album
);
938 WRITE_STATUS_ITEM(b
, SI_comment
, "%s\n", afhi
->tags
.comment
);
939 if (opts
->mode
== LS_MODE_MBOX
) {
940 struct osl_object lyrics_def
;
941 lyr_get_def_by_id(afsi
->lyrics_id
, &lyrics_def
);
942 if (lyrics_def
.data
) {
943 para_printf(b
, "Lyrics:\n~~~~~~~\n%s",
944 (char *)lyrics_def
.data
);
945 osl_close_disk_object(&lyrics_def
);
952 static void make_inode_status_items(struct para_buffer
*pb
)
954 struct stat statbuf
= {.st_size
= 0};
955 char *path
, mtime_str
[30] = "\0";
959 ret
= get_audio_file_path_of_row(current_aft_row
, &path
);
962 ret
= stat(path
, &statbuf
);
965 localtime_r(&statbuf
.st_mtime
, &mtime_tm
);
966 ret
= strftime(mtime_str
, 29, "%b %d %Y", &mtime_tm
);
967 assert(ret
> 0); /* number of bytes placed in mtime_str */
969 WRITE_STATUS_ITEM(pb
, SI_mtime
, "%s\n", mtime_str
);
970 WRITE_STATUS_ITEM(pb
, SI_file_size
, "%ld\n", statbuf
.st_size
/ 1024);
974 * Deallocate and invalidate the status item strings.
976 * This needs to be a public function so that afs.c can call it on shutdown.
978 void free_status_items(void)
980 freep(&status_items
);
981 freep(&parser_friendly_status_items
);
984 static void make_status_items(void)
986 const struct lls_command
*cmd
= SERVER_CMD_CMD_PTR(LS
);
987 char *argv
[] = {"ls", "--admissible", "--listing-mode=verbose"};
988 struct ls_options opts
= {.mode
= LS_MODE_VERBOSE
};
989 struct para_buffer pb
= {.max_size
= shm_get_shmmax() - 1};
994 if (!status_item_ls_data
.path
) /* no audio file open */
996 ret
= lls_parse(ARRAY_SIZE(argv
), argv
, cmd
, &opts
.lpr
, NULL
);
999 ret
= print_list_item(&status_item_ls_data
, &opts
, &pb
, current_time
);
1002 make_inode_status_items(&pb
);
1003 status_items
= pb
.buf
;
1005 memset(&pb
, 0, sizeof(pb
));
1006 pb
.max_size
= shm_get_shmmax() - 1;
1007 pb
.flags
= PBF_SIZE_PREFIX
;
1008 ret
= print_list_item(&status_item_ls_data
, &opts
, &pb
, current_time
);
1011 make_inode_status_items(&pb
);
1012 parser_friendly_status_items
= pb
.buf
;
1016 PARA_WARNING_LOG("could not create status items: %s\n",
1017 para_strerror(-ret
));
1018 free_status_items();
1020 lls_free_parse_result(opts
.lpr
, cmd
);
1024 * Open the audio file with highest score and set up an afd structure.
1026 * This determines and opens the next audio file, verifies that it did not
1027 * change by comparing the recomputed the hash value of the file contents
1028 * against the value stored in the audio file table. If all goes well, it
1029 * creates a shared memory area containing the serialized version of the afd
1030 * structure, including the chunk table, if any. The caller can then send the
1031 * ID of this area and the open fd to the server process.
1033 * \param fd Result pointer for the file descriptor of the audio file.
1035 * On success, the numplayed field of the audio file selector info is increased
1036 * and the lastplayed time is set to the current time. Finally, the score of
1037 * the audio file is updated.
1039 * \return Positive shmid on success, negative on errors.
1041 int open_and_update_audio_file(int *fd
)
1043 unsigned char file_hash
[HASH2_SIZE
];
1044 struct osl_object afsi_obj
;
1045 struct afs_info new_afsi
;
1047 struct afsi_change_event_data aced
;
1048 struct osl_object map
, chunk_table_obj
;
1049 struct ls_data
*d
= &status_item_ls_data
;
1050 unsigned char *tmp_hash
;
1051 struct audio_file_data afd
;
1053 ret
= score_get_best(¤t_aft_row
, &d
->score
);
1057 * get_hash_of_row() and get_audio_file_path_of_row() initialize
1058 * their pointer argument to point to memory-mapped files. These pointers
1059 * become stale after a new audio file has been added or after the
1060 * server process received SIGHUP. For in both cases libosl unmaps and
1061 * remaps the underlying database files, and this remapping may well
1062 * change the starting address of the mapping. To avoid stale pointer
1063 * references we create copies on the heap.
1065 ret
= get_hash_of_row(current_aft_row
, &tmp_hash
);
1069 d
->hash
= alloc(HASH_SIZE
);
1070 memcpy(d
->hash
, tmp_hash
, HASH_SIZE
);
1072 ret
= get_audio_file_path_of_row(current_aft_row
, &d
->path
);
1075 PARA_NOTICE_LOG("%s\n", d
->path
);
1076 d
->path
= para_strdup(d
->path
);
1078 ret
= get_afsi_object_of_row(current_aft_row
, &afsi_obj
);
1081 ret
= load_afsi(&d
->afsi
, &afsi_obj
);
1084 ret
= get_afhi_of_row(current_aft_row
, &afd
.afhi
);
1088 d
->afhi
.chunk_table
= afd
.afhi
.chunk_table
= NULL
;
1089 ret
= osl(osl_open_disk_object(audio_file_table
, current_aft_row
,
1090 AFTCOL_CHUNKS
, &chunk_table_obj
));
1092 if (!afh_supports_dynamic_chunks(d
->afsi
.audio_format_id
))
1094 PARA_INFO_LOG("no chunk table for %s\n", d
->path
);
1095 chunk_table_obj
.data
= NULL
;
1096 chunk_table_obj
.size
= 0;
1098 PARA_INFO_LOG("chunk table: %zu bytes\n", chunk_table_obj
.size
);
1100 ret
= mmap_full_file(d
->path
, O_RDONLY
, &map
.data
, &map
.size
, fd
);
1103 hash2_function(map
.data
, map
.size
, file_hash
);
1104 ret
= hash_compare(file_hash
, d
->hash
);
1105 para_munmap(map
.data
, map
.size
);
1107 ret
= -E_HASH_MISMATCH
;
1111 new_afsi
.num_played
++;
1112 new_afsi
.last_played
= time(NULL
);
1113 save_afsi(&new_afsi
, &afsi_obj
); /* in-place update */
1115 afd
.audio_format_id
= d
->afsi
.audio_format_id
;
1116 load_chunk_table(&afd
.afhi
, &chunk_table_obj
);
1117 aced
.aft_row
= current_aft_row
;
1118 aced
.old_afsi
= &d
->afsi
;
1120 * No need to update the status items as the AFSI_CHANGE event will
1123 ret
= afs_event(AFSI_CHANGE
, NULL
, &aced
);
1126 ret
= save_afd(&afd
);
1128 free(afd
.afhi
.chunk_table
);
1129 if (chunk_table_obj
.data
)
1130 osl_close_disk_object(&chunk_table_obj
);
1132 PARA_ERROR_LOG("%s: %s\n", d
->path
, para_strerror(-ret
));
1133 ret
= score_delete(current_aft_row
);
1140 static int ls_hash_compare(const void *a
, const void *b
)
1142 struct ls_data
*d1
= *(struct ls_data
**)a
, *d2
= *(struct ls_data
**)b
;
1143 return memcmp(d1
->hash
, d2
->hash
, HASH2_SIZE
);
1146 static int ls_audio_format_compare(const void *a
, const void *b
)
1148 struct ls_data
*d1
= *(struct ls_data
**)a
, *d2
= *(struct ls_data
**)b
;
1149 return NUM_COMPARE(d1
->afsi
.audio_format_id
, d2
->afsi
.audio_format_id
);
1152 static int ls_duration_compare(const void *a
, const void *b
)
1154 struct ls_data
*d1
= *(struct ls_data
**)a
, *d2
= *(struct ls_data
**)b
;
1155 return NUM_COMPARE(d1
->afhi
.seconds_total
, d2
->afhi
.seconds_total
);
1158 static int ls_bitrate_compare(const void *a
, const void *b
)
1160 struct ls_data
*d1
= *(struct ls_data
**)a
, *d2
= *(struct ls_data
**)b
;
1161 return NUM_COMPARE(d1
->afhi
.bitrate
, d2
->afhi
.bitrate
);
1164 static int ls_lyrics_id_compare(const void *a
, const void *b
)
1166 struct ls_data
*d1
= *(struct ls_data
**)a
, *d2
= *(struct ls_data
**)b
;
1167 return NUM_COMPARE(d1
->afsi
.lyrics_id
, d2
->afsi
.lyrics_id
);
1170 static int ls_image_id_compare(const void *a
, const void *b
)
1172 struct ls_data
*d1
= *(struct ls_data
**)a
, *d2
= *(struct ls_data
**)b
;
1173 return NUM_COMPARE(d1
->afsi
.image_id
, d2
->afsi
.image_id
);
1176 static int ls_channels_compare(const void *a
, const void *b
)
1178 struct ls_data
*d1
= *(struct ls_data
**)a
, *d2
= *(struct ls_data
**)b
;
1179 return NUM_COMPARE(d1
->afhi
.channels
, d2
->afhi
.channels
);
1182 static int ls_frequency_compare(const void *a
, const void *b
)
1184 struct ls_data
*d1
= *(struct ls_data
**)a
, *d2
= *(struct ls_data
**)b
;
1185 return NUM_COMPARE(d1
->afhi
.frequency
, d2
->afhi
.frequency
);
1188 static int ls_num_played_compare(const void *a
, const void *b
)
1190 struct ls_data
*d1
= *(struct ls_data
**)a
, *d2
= *(struct ls_data
**)b
;
1191 return NUM_COMPARE(d1
->afsi
.num_played
, d2
->afsi
.num_played
);
1194 static int ls_last_played_compare(const void *a
, const void *b
)
1196 struct ls_data
*d1
= *(struct ls_data
**)a
, *d2
= *(struct ls_data
**)b
;
1197 return NUM_COMPARE(d1
->afsi
.last_played
, d2
->afsi
.last_played
);
1200 static int ls_score_compare(const void *a
, const void *b
)
1202 struct ls_data
*d1
= *(struct ls_data
**)a
, *d2
= *(struct ls_data
**)b
;
1203 return NUM_COMPARE(d1
->score
, d2
->score
);
1206 static int ls_path_compare(const void *a
, const void *b
)
1208 struct ls_data
*d1
= *(struct ls_data
**)a
, *d2
= *(struct ls_data
**)b
;
1209 return strcmp(d1
->path
, d2
->path
);
1212 static inline bool admissible_only(struct ls_options
*opts
)
1214 return SERVER_CMD_OPT_GIVEN(LS
, ADMISSIBLE
, opts
->lpr
)
1215 || opts
->sorting
== LS_SORT_BY_SCORE
;
1218 static int sort_matching_paths(struct ls_options
*options
)
1220 const struct lls_opt_result
*r_b
= SERVER_CMD_OPT_RESULT(LS
, BASENAME
,
1222 size_t nmemb
= options
->num_matching_paths
;
1223 size_t size
= sizeof(*options
->data_ptr
);
1224 int (*compar
)(const void *, const void *);
1227 options
->data_ptr
= arr_alloc(nmemb
, sizeof(*options
->data_ptr
));
1228 for (i
= 0; i
< nmemb
; i
++)
1229 options
->data_ptr
[i
] = options
->data
+ i
;
1231 /* In these cases the array is already sorted */
1232 if (admissible_only(options
)) {
1233 if (options
->sorting
== LS_SORT_BY_SCORE
)
1236 if (options
->sorting
== LS_SORT_BY_PATH
&& !lls_opt_given(r_b
))
1240 switch (options
->sorting
) {
1241 case LS_SORT_BY_PATH
:
1242 compar
= ls_path_compare
; break;
1243 case LS_SORT_BY_SCORE
:
1244 compar
= ls_score_compare
; break;
1245 case LS_SORT_BY_LAST_PLAYED
:
1246 compar
= ls_last_played_compare
; break;
1247 case LS_SORT_BY_NUM_PLAYED
:
1248 compar
= ls_num_played_compare
; break;
1249 case LS_SORT_BY_FREQUENCY
:
1250 compar
= ls_frequency_compare
; break;
1251 case LS_SORT_BY_CHANNELS
:
1252 compar
= ls_channels_compare
; break;
1253 case LS_SORT_BY_IMAGE_ID
:
1254 compar
= ls_image_id_compare
; break;
1255 case LS_SORT_BY_LYRICS_ID
:
1256 compar
= ls_lyrics_id_compare
; break;
1257 case LS_SORT_BY_BITRATE
:
1258 compar
= ls_bitrate_compare
; break;
1259 case LS_SORT_BY_DURATION
:
1260 compar
= ls_duration_compare
; break;
1261 case LS_SORT_BY_AUDIO_FORMAT
:
1262 compar
= ls_audio_format_compare
; break;
1263 case LS_SORT_BY_HASH
:
1264 compar
= ls_hash_compare
; break;
1268 qsort(options
->data_ptr
, nmemb
, size
, compar
);
1272 /* row is either an aft_row or a row of the score table */
1273 /* TODO: Only compute widths if we need them */
1274 static int prepare_ls_row(struct osl_row
*row
, void *ls_opts
)
1277 struct ls_options
*options
= ls_opts
;
1278 bool basename_given
= SERVER_CMD_OPT_GIVEN(LS
, BASENAME
, options
->lpr
);
1280 struct ls_widths
*w
;
1281 unsigned short num_digits
;
1282 unsigned tmp
, num_inputs
;
1283 struct osl_row
*aft_row
;
1287 if (admissible_only(options
)) {
1288 ret
= get_score_and_aft_row(row
, &score
, &aft_row
);
1295 ret
= get_audio_file_path_of_row(aft_row
, &path
);
1298 if (basename_given
) {
1299 char *p
= strrchr(path
, '/');
1303 num_inputs
= lls_num_inputs(options
->lpr
);
1304 if (num_inputs
> 0) {
1305 for (i
= 0; i
< num_inputs
; i
++) {
1306 ret
= fnmatch(lls_input(i
, options
->lpr
), path
, 0);
1309 if (ret
== FNM_NOMATCH
)
1313 if (i
>= num_inputs
) /* no match */
1316 tmp
= options
->num_matching_paths
++;
1317 if (options
->num_matching_paths
> options
->array_size
) {
1318 options
->array_size
++;
1319 options
->array_size
*= 2;
1320 options
->data
= arr_realloc(options
->data
, options
->array_size
,
1321 sizeof(*options
->data
));
1323 d
= options
->data
+ tmp
;
1324 ret
= get_afsi_of_row(aft_row
, &d
->afsi
);
1327 ret
= get_afhi_of_row(aft_row
, &d
->afhi
);
1331 ret
= get_hash_of_row(aft_row
, &d
->hash
);
1334 w
= &options
->widths
;
1335 GET_NUM_DIGITS(d
->afsi
.image_id
, &num_digits
);
1336 w
->image_id_width
= PARA_MAX(w
->image_id_width
, num_digits
);
1337 GET_NUM_DIGITS(d
->afsi
.lyrics_id
, &num_digits
);
1338 w
->lyrics_id_width
= PARA_MAX(w
->lyrics_id_width
, num_digits
);
1339 GET_NUM_DIGITS(d
->afhi
.bitrate
, &num_digits
);
1340 w
->bitrate_width
= PARA_MAX(w
->bitrate_width
, num_digits
);
1341 GET_NUM_DIGITS(d
->afhi
.frequency
, &num_digits
);
1342 w
->frequency_width
= PARA_MAX(w
->frequency_width
, num_digits
);
1343 GET_NUM_DIGITS(d
->afsi
.num_played
, &num_digits
);
1344 w
->num_played_width
= PARA_MAX(w
->num_played_width
, num_digits
);
1345 /* get the number of chars to print this amount of time */
1346 num_digits
= get_duration_width(d
->afhi
.seconds_total
);
1347 w
->duration_width
= PARA_MAX(w
->duration_width
, num_digits
);
1348 GET_NUM_DIGITS(d
->afsi
.amp
, &num_digits
);
1349 w
->amp_width
= PARA_MAX(w
->amp_width
, num_digits
);
1350 num_digits
= strlen(audio_format_name(d
->afsi
.audio_format_id
));
1351 w
->audio_format_width
= PARA_MAX(w
->audio_format_width
, num_digits
);
1352 if (admissible_only(options
)) {
1353 GET_NUM_DIGITS(score
, &num_digits
);
1354 num_digits
++; /* add one for the sign (space or "-") */
1355 w
->score_width
= PARA_MAX(w
->score_width
, num_digits
);
1363 static int com_ls_callback(struct afs_callback_arg
*aca
)
1365 const struct lls_command
*cmd
= SERVER_CMD_CMD_PTR(LS
);
1366 struct ls_options
*opts
= aca
->query
.data
;
1368 time_t current_time
;
1369 const struct lls_opt_result
*r_r
;
1371 ret
= lls_deserialize_parse_result(
1372 (char *)aca
->query
.data
+ sizeof(*opts
), cmd
, &opts
->lpr
);
1374 r_r
= SERVER_CMD_OPT_RESULT(LS
, REVERSE
, opts
->lpr
);
1376 aca
->pbout
.flags
= (opts
->mode
== LS_MODE_PARSER
)? PBF_SIZE_PREFIX
: 0;
1377 if (admissible_only(opts
))
1378 ret
= score_loop(prepare_ls_row
, opts
);
1380 ret
= osl(osl_rbtree_loop(audio_file_table
, AFTCOL_PATH
, opts
,
1384 if (opts
->num_matching_paths
== 0) {
1385 ret
= lls_num_inputs(opts
->lpr
) > 0? -E_NO_MATCH
: 0;
1388 ret
= sort_matching_paths(opts
);
1391 time(¤t_time
);
1392 if (lls_opt_given(r_r
))
1393 for (i
= opts
->num_matching_paths
- 1; i
>= 0; i
--) {
1394 ret
= print_list_item(opts
->data_ptr
[i
], opts
,
1395 &aca
->pbout
, current_time
);
1400 for (i
= 0; i
< opts
->num_matching_paths
; i
++) {
1401 ret
= print_list_item(opts
->data_ptr
[i
], opts
,
1402 &aca
->pbout
, current_time
);
1407 lls_free_parse_result(opts
->lpr
, cmd
);
1409 free(opts
->data_ptr
);
1413 static int com_ls(struct command_context
*cc
, struct lls_parse_result
*lpr
)
1415 const struct lls_command
*cmd
= SERVER_CMD_CMD_PTR(LS
);
1416 struct ls_options
*opts
;
1417 struct osl_object query
;
1418 const struct lls_opt_result
*r_l
= SERVER_CMD_OPT_RESULT(LS
, LISTING_MODE
,
1420 const struct lls_opt_result
*r_s
= SERVER_CMD_OPT_RESULT(LS
, SORT
, lpr
);
1424 ret
= lls_serialize_parse_result(lpr
, cmd
, NULL
, &query
.size
);
1426 query
.size
+= sizeof(*opts
);
1427 query
.data
= alloc(query
.size
);
1429 memset(opts
, 0, sizeof(*opts
));
1430 slpr
= query
.data
+ sizeof(*opts
);
1431 ret
= lls_serialize_parse_result(lpr
, cmd
, &slpr
, NULL
);
1433 opts
->mode
= LS_MODE_SHORT
;
1434 opts
->sorting
= LS_SORT_BY_PATH
;
1435 if (lls_opt_given(r_l
)) {
1436 const char *val
= lls_string_val(0, r_l
);
1437 if (!strcmp(val
, "l") || !strcmp(val
, "long"))
1438 opts
->mode
= LS_MODE_LONG
;
1439 else if (!strcmp(val
, "s") || !strcmp(val
, "short"))
1440 opts
->mode
= LS_MODE_SHORT
;
1441 else if (!strcmp(val
, "v") || !strcmp(val
, "verbose"))
1442 opts
->mode
= LS_MODE_VERBOSE
;
1443 else if (!strcmp(val
, "m") || !strcmp(val
, "mbox"))
1444 opts
->mode
= LS_MODE_MBOX
;
1445 else if (!strcmp(val
, "c") || !strcmp(val
, "chunk-table"))
1446 opts
->mode
= LS_MODE_MBOX
;
1447 else if (!strcmp(val
, "p") || !strcmp(val
, "parser-friendly"))
1448 opts
->mode
= LS_MODE_PARSER
;
1450 ret
= -ERRNO_TO_PARA_ERROR(EINVAL
);
1454 if (lls_opt_given(r_s
)) {
1455 const char *val
= lls_string_val(0, r_s
);
1456 if (!strcmp(val
, "p") || !strcmp(val
, "path"))
1457 opts
->sorting
= LS_SORT_BY_PATH
;
1458 else if (!strcmp(val
, "s") || !strcmp(val
, "score"))
1459 opts
->sorting
= LS_SORT_BY_SCORE
;
1460 else if (!strcmp(val
, "l") || !strcmp(val
, "lastplayed"))
1461 opts
->sorting
= LS_SORT_BY_LAST_PLAYED
;
1462 else if (!strcmp(val
, "n") || !strcmp(val
, "numplayed"))
1463 opts
->sorting
= LS_SORT_BY_NUM_PLAYED
;
1464 else if (!strcmp(val
, "f") || !strcmp(val
, "frquency"))
1465 opts
->sorting
= LS_SORT_BY_FREQUENCY
;
1466 else if (!strcmp(val
, "c") || !strcmp(val
, "channels"))
1467 opts
->sorting
= LS_SORT_BY_CHANNELS
;
1468 else if (!strcmp(val
, "i") || !strcmp(val
, "image-id"))
1469 opts
->sorting
= LS_SORT_BY_IMAGE_ID
;
1470 else if (!strcmp(val
, "y") || !strcmp(val
, "lyrics-id"))
1471 opts
->sorting
= LS_SORT_BY_LYRICS_ID
;
1472 else if (!strcmp(val
, "b") || !strcmp(val
, "bitrate"))
1473 opts
->sorting
= LS_SORT_BY_BITRATE
;
1474 else if (!strcmp(val
, "d") || !strcmp(val
, "duration"))
1475 opts
->sorting
= LS_SORT_BY_DURATION
;
1476 else if (!strcmp(val
, "a") || !strcmp(val
, "audio-format"))
1477 opts
->sorting
= LS_SORT_BY_AUDIO_FORMAT
;
1478 else if (!strcmp(val
, "h") || !strcmp(val
, "hash"))
1479 opts
->sorting
= LS_SORT_BY_HASH
;
1481 ret
= -ERRNO_TO_PARA_ERROR(EINVAL
);
1485 ret
= send_callback_request(com_ls_callback
, &query
,
1486 afs_cb_result_handler
, cc
);
1491 EXPORT_SERVER_CMD_HANDLER(ls
);
1494 * Call the given function for each file in the audio file table.
1496 * \param private_data An arbitrary data pointer, passed to \a func.
1497 * \param func The custom function to be called.
1501 int audio_file_loop(void *private_data
, osl_rbtree_loop_func
*func
)
1503 return osl(osl_rbtree_loop(audio_file_table
, AFTCOL_HASH
, private_data
,
1507 static int find_hash_sister(unsigned char *hash
, struct osl_row
**result
)
1509 int ret
= aft_get_row_of_hash(hash
, result
);
1511 if (ret
== -OSL_ERRNO_TO_PARA_ERROR(E_OSL_RB_KEY_NOT_FOUND
))
1516 static int find_path_brother(const char *path
, struct osl_row
**result
)
1518 int ret
= aft_get_row_of_path(path
, result
);
1520 if (ret
== -OSL_ERRNO_TO_PARA_ERROR(E_OSL_RB_KEY_NOT_FOUND
))
1525 /** The format of the data stored by save_audio_file_data(). */
1526 enum com_add_buffer_offsets
{
1527 /* afhi (if present) starts at this offset. */
1528 CAB_AFHI_OFFSET_POS
= 0,
1529 /** Start of the chunk table (if present). */
1530 CAB_CHUNKS_OFFSET_POS
= 4,
1531 /** Start of the (serialized) lopsub parse result. */
1533 /** Audio format id. */
1534 CAB_AUDIO_FORMAT_ID_OFFSET
= 12,
1535 /** The hash of the audio file being added. */
1536 CAB_HASH_OFFSET
= 13,
1537 /** Start of the path of the audio file. */
1538 CAB_PATH_OFFSET
= (CAB_HASH_OFFSET
+ HASH2_SIZE
),
1542 * Store the given data to a single buffer. Doesn't need the audio file selector
1543 * info struct as the server knows it as well.
1545 * It's OK to call this with afhi == NULL. In this case, the audio format
1546 * handler info won't be stored in the buffer.
1548 static void save_add_callback_buffer(unsigned char *hash
, const char *path
,
1549 struct afh_info
*afhi
, const char *slpr
, size_t slpr_size
,
1550 uint8_t audio_format_num
, struct osl_object
*obj
)
1552 size_t path_len
= strlen(path
) + 1;
1553 size_t afhi_size
= sizeof_afhi_buf(afhi
);
1554 size_t size
= CAB_PATH_OFFSET
+ path_len
+ afhi_size
1555 + sizeof_chunk_table(afhi
) + slpr_size
;
1556 char *buf
= alloc(size
);
1559 assert(size
<= ~(uint32_t)0);
1560 write_u8(buf
+ CAB_AUDIO_FORMAT_ID_OFFSET
, audio_format_num
);
1561 memcpy(buf
+ CAB_HASH_OFFSET
, hash
, HASH2_SIZE
);
1562 strcpy(buf
+ CAB_PATH_OFFSET
, path
);
1563 pos
= CAB_PATH_OFFSET
+ path_len
;
1564 write_u32(buf
+ CAB_AFHI_OFFSET_POS
, pos
);
1565 save_afhi(afhi
, buf
+ pos
);
1567 write_u32(buf
+ CAB_CHUNKS_OFFSET_POS
, pos
);
1569 save_chunk_table(afhi
, buf
+ pos
);
1570 pos
+= sizeof_chunk_table(afhi
);
1572 write_u32(buf
+ CAB_LPR_OFFSET
, pos
);
1573 memcpy(buf
+ pos
, slpr
, slpr_size
);
1574 assert(pos
+ slpr_size
== size
);
1581 Overview of the add command.
1583 Input: What was passed to the callback by the command handler.
1585 HS: Hash sister. Whether an audio file with identical hash
1586 already exists in the osl database.
1588 PB: Path brother. Whether a file with the given path exists
1591 F: Force flag given. Whether add was called with -f.
1593 output: Action performed by the callback.
1595 AFHI: Whether afhi and chunk table are computed and sent.
1596 ACTION: Table modifications to be done by the callback.
1598 +----+----+---+------+---------------------------------------------------+
1599 | HS | PB | F | AFHI | ACTION
1600 +----+----+---+------+---------------------------------------------------+
1601 | Y | Y | Y | Y | if HS != PB: remove PB. HS: force afhi update,
1602 | | update path, keep afsi
1603 +----+----+---+------+---------------------------------------------------+
1604 | Y | Y | N | N | if HS == PB: do not send callback request at all.
1605 | | otherwise: remove PB, HS: update path, keep afhi,
1607 +----+----+---+------+---------------------------------------------------+
1608 | Y | N | Y | Y | (rename) force afhi update of HS, update path of
1610 +----+----+---+------+---------------------------------------------------+
1611 | Y | N | N | N | (file rename) update path of HS, keep afsi, afhi
1612 +----+----+---+------+---------------------------------------------------+
1613 | N | Y | Y | Y | (file change) update afhi, hash, of PB, keep afsi
1614 | | (force has no effect)
1615 +----+----+---+------+---------------------------------------------------+
1616 | N | Y | N | Y | (file change) update afhi, hash of PB, keep afsi
1617 +----+----+---+------+---------------------------------------------------+
1618 | N | N | Y | Y | (new file) create new entry (force has no effect)
1619 +----+----+---+------+---------------------------------------------------+
1620 | N | N | N | Y | (new file) create new entry
1621 +----+----+---+------+---------------------------------------------------+
1625 afhi <=> force or no HS
1630 static int com_add_callback(struct afs_callback_arg
*aca
)
1632 char *buf
= aca
->query
.data
, *path
;
1633 struct osl_row
*pb
, *aft_row
;
1635 struct osl_object objs
[NUM_AFT_COLUMNS
];
1636 unsigned char *hash
;
1637 char asc
[2 * HASH2_SIZE
+ 1];
1639 char afsi_buf
[AFSI_SIZE
];
1640 char *slpr
= buf
+ read_u32(buf
+ CAB_LPR_OFFSET
);
1641 struct afs_info default_afsi
= {.last_played
= 0};
1642 uint16_t afhi_offset
, chunks_offset
;
1643 const struct lls_command
*cmd
= SERVER_CMD_CMD_PTR(ADD
);
1644 const struct lls_opt_result
*r_f
, *r_v
;
1646 ret
= lls_deserialize_parse_result(slpr
, cmd
, &aca
->lpr
);
1648 r_f
= SERVER_CMD_OPT_RESULT(ADD
, FORCE
, aca
->lpr
);
1649 r_v
= SERVER_CMD_OPT_RESULT(ADD
, VERBOSE
, aca
->lpr
);
1651 hash
= (unsigned char *)buf
+ CAB_HASH_OFFSET
;
1652 hash_to_asc(hash
, asc
);
1653 objs
[AFTCOL_HASH
].data
= buf
+ CAB_HASH_OFFSET
;
1654 objs
[AFTCOL_HASH
].size
= HASH2_SIZE
;
1656 path
= buf
+ CAB_PATH_OFFSET
;
1657 objs
[AFTCOL_PATH
].data
= path
;
1658 objs
[AFTCOL_PATH
].size
= strlen(path
) + 1;
1660 PARA_INFO_LOG("request to add %s\n", path
);
1661 ret
= find_hash_sister(hash
, &hs
);
1664 ret
= find_path_brother(path
, &pb
);
1667 if (hs
&& pb
&& hs
== pb
&& !lls_opt_given(r_f
)) {
1668 if (lls_opt_given(r_v
))
1669 para_printf(&aca
->pbout
, "ignoring duplicate\n");
1673 if (hs
&& hs
!= pb
) {
1674 struct osl_object obj
;
1675 if (pb
) { /* hs trumps pb, remove pb */
1676 if (lls_opt_given(r_v
))
1677 para_printf(&aca
->pbout
, "removing %s\n", path
);
1678 ret
= afs_event(AUDIO_FILE_REMOVE
, &aca
->pbout
, pb
);
1681 ret
= osl(osl_del_row(audio_file_table
, pb
));
1686 /* file rename, update hs' path */
1687 if (lls_opt_given(r_v
)) {
1688 ret
= osl(osl_get_object(audio_file_table
, hs
,
1689 AFTCOL_PATH
, &obj
));
1692 para_printf(&aca
->pbout
, "renamed from %s\n",
1695 ret
= osl(osl_update_object(audio_file_table
, hs
, AFTCOL_PATH
,
1696 &objs
[AFTCOL_PATH
]));
1699 ret
= afs_event(AUDIO_FILE_RENAME
, &aca
->pbout
, hs
);
1702 if (!lls_opt_given(r_f
))
1705 /* no hs or force mode, child must have sent afhi */
1706 afhi_offset
= read_u32(buf
+ CAB_AFHI_OFFSET_POS
);
1707 chunks_offset
= read_u32(buf
+ CAB_CHUNKS_OFFSET_POS
);
1709 objs
[AFTCOL_AFHI
].data
= buf
+ afhi_offset
;
1710 objs
[AFTCOL_AFHI
].size
= chunks_offset
- afhi_offset
;
1712 if (!objs
[AFTCOL_AFHI
].size
) /* "impossible" */
1714 objs
[AFTCOL_CHUNKS
].data
= buf
+ chunks_offset
;
1715 objs
[AFTCOL_CHUNKS
].size
= aca
->query
.size
- chunks_offset
;
1716 if (pb
&& !hs
) { /* update pb's hash */
1717 char old_asc
[2 * HASH2_SIZE
+ 1];
1718 unsigned char *old_hash
;
1719 ret
= get_hash_of_row(pb
, &old_hash
);
1722 hash_to_asc(old_hash
, old_asc
);
1723 if (lls_opt_given(r_v
))
1724 para_printf(&aca
->pbout
, "file change: %s -> %s\n",
1726 ret
= osl(osl_update_object(audio_file_table
, pb
, AFTCOL_HASH
,
1727 &objs
[AFTCOL_HASH
]));
1731 if (hs
|| pb
) { /* (hs != NULL and pb != NULL) implies hs == pb */
1732 struct osl_row
*row
= pb
? pb
: hs
;
1733 /* update afhi and chunk_table */
1734 if (lls_opt_given(r_v
))
1735 para_printf(&aca
->pbout
,
1736 "updating afhi and chunk table\n");
1737 ret
= osl(osl_update_object(audio_file_table
, row
, AFTCOL_AFHI
,
1738 &objs
[AFTCOL_AFHI
]));
1741 /* truncate the file to size zero if there is no chunk table */
1742 ret
= osl(osl_update_object(audio_file_table
, row
, AFTCOL_CHUNKS
,
1743 &objs
[AFTCOL_CHUNKS
]));
1746 ret
= afs_event(AFHI_CHANGE
, &aca
->pbout
, row
);
1749 /* new entry, use default afsi */
1750 if (lls_opt_given(r_v
))
1751 para_printf(&aca
->pbout
, "new file\n");
1752 default_afsi
.last_played
= time(NULL
) - 365 * 24 * 60 * 60;
1753 default_afsi
.audio_format_id
= read_u8(buf
+ CAB_AUDIO_FORMAT_ID_OFFSET
);
1755 objs
[AFTCOL_AFSI
].data
= &afsi_buf
;
1756 objs
[AFTCOL_AFSI
].size
= AFSI_SIZE
;
1757 save_afsi(&default_afsi
, &objs
[AFTCOL_AFSI
]);
1758 ret
= osl(osl_add_and_get_row(audio_file_table
, objs
, &aft_row
));
1761 ret
= afs_event(AUDIO_FILE_ADD
, &aca
->pbout
, aft_row
);
1764 afs_error(aca
, "could not add %s\n", path
);
1765 lls_free_parse_result(aca
->lpr
, cmd
);
1769 /* Used by com_add(). */
1770 struct private_add_data
{
1771 /* The pointer passed to the original command handler. */
1772 struct command_context
*cc
;
1773 /* Contains the flags given at the command line. */
1774 struct lls_parse_result
*lpr
;
1775 /* Serialized lopsub parse result. */
1777 /* Number of bytes. */
1781 static int path_brother_callback(struct afs_callback_arg
*aca
)
1783 char *path
= aca
->query
.data
;
1784 struct osl_row
*path_brother
;
1785 int ret
= find_path_brother(path
, &path_brother
);
1788 return pass_buffer_as_shm(aca
->fd
, SBD_OUTPUT
, (char *)&path_brother
,
1789 sizeof(path_brother
));
1792 static int hash_sister_callback(struct afs_callback_arg
*aca
)
1794 unsigned char *hash
= aca
->query
.data
;
1795 struct osl_row
*hash_sister
;
1796 int ret
= find_hash_sister(hash
, &hash_sister
);
1800 return pass_buffer_as_shm(aca
->fd
, SBD_OUTPUT
, (char *)&hash_sister
,
1801 sizeof(hash_sister
));
1804 static int get_row_pointer_from_result(struct osl_object
*result
,
1805 __a_unused
uint8_t band
, void *private)
1807 struct osl_row
**row
= private;
1809 if (band
== SBD_OUTPUT
)
1810 *row
= *(struct osl_row
**)(result
->data
);
1814 static int add_one_audio_file(const char *path
, void *private_data
)
1816 int ret
, send_ret
= 1, fd
;
1817 uint8_t format_num
= -1;
1818 struct private_add_data
*pad
= private_data
;
1819 struct afh_info afhi
, *afhi_ptr
= NULL
;
1820 struct osl_row
*pb
= NULL
, *hs
= NULL
; /* path brother/hash sister */
1821 struct osl_object map
, obj
= {.data
= NULL
}, query
;
1822 unsigned char hash
[HASH2_SIZE
];
1823 bool a_given
= SERVER_CMD_OPT_GIVEN(ADD
, ALL
, pad
->lpr
);
1824 bool f_given
= SERVER_CMD_OPT_GIVEN(ADD
, FORCE
, pad
->lpr
);
1825 bool l_given
= SERVER_CMD_OPT_GIVEN(ADD
, LAZY
, pad
->lpr
);
1826 bool v_given
= SERVER_CMD_OPT_GIVEN(ADD
, VERBOSE
, pad
->lpr
);
1828 ret
= guess_audio_format(path
);
1829 if (ret
< 0 && !a_given
) {
1833 query
.data
= (char *)path
;
1834 query
.size
= strlen(path
) + 1;
1835 ret
= send_callback_request(path_brother_callback
, &query
,
1836 get_row_pointer_from_result
, &pb
);
1837 if (ret
< 0 && ret
!= -OSL_ERRNO_TO_PARA_ERROR(E_OSL_RB_KEY_NOT_FOUND
))
1840 if (pb
&& l_given
) { /* lazy is really cheap */
1842 send_ret
= send_sb_va(&pad
->cc
->scc
, SBD_OUTPUT
,
1843 "lazy-ignore: %s\n", path
);
1846 /* We still want to add this file. Compute its hash. */
1847 ret
= mmap_full_file(path
, O_RDONLY
, &map
.data
, &map
.size
, &fd
);
1850 hash2_function(map
.data
, map
.size
, hash
);
1852 /* Check whether the database contains a file with the same hash. */
1854 query
.size
= HASH2_SIZE
;
1855 ret
= send_callback_request(hash_sister_callback
, &query
,
1856 get_row_pointer_from_result
, &hs
);
1859 /* Return success if we already know this file. */
1861 if (pb
&& hs
&& hs
== pb
&& !f_given
) {
1863 send_ret
= send_sb_va(&pad
->cc
->scc
, SBD_OUTPUT
,
1864 "%s exists, not forcing update\n", path
);
1868 * We won't recalculate the audio format info and the chunk table if
1869 * there is a hash sister and FORCE was not given.
1871 if (!hs
|| f_given
) {
1872 ret
= compute_afhi(path
, map
.data
, map
.size
, fd
, &afhi
);
1878 munmap(map
.data
, map
.size
);
1881 send_ret
= send_sb_va(&pad
->cc
->scc
, SBD_OUTPUT
,
1882 "adding %s\n", path
);
1886 save_add_callback_buffer(hash
, path
, afhi_ptr
, pad
->slpr
,
1887 pad
->slpr_size
, format_num
, &obj
);
1888 /* Ask afs to consider this entry for adding. */
1889 ret
= send_callback_request(com_add_callback
, &obj
,
1890 afs_cb_result_handler
, pad
->cc
);
1895 munmap(map
.data
, map
.size
);
1897 if (ret
< 0 && send_ret
>= 0)
1898 send_ret
= send_sb_va(&pad
->cc
->scc
, SBD_ERROR_LOG
,
1899 "failed to add %s (%s)\n", path
, para_strerror(-ret
));
1901 clear_afhi(afhi_ptr
);
1902 /* Stop adding files only on send errors. */
1906 static int com_add(struct command_context
*cc
, struct lls_parse_result
*lpr
)
1909 struct private_add_data pad
= {.cc
= cc
, .lpr
= lpr
};
1910 const struct lls_command
*cmd
= SERVER_CMD_CMD_PTR(ADD
);
1911 unsigned num_inputs
;
1914 ret
= lls(lls_check_arg_count(lpr
, 1, INT_MAX
, &errctx
));
1916 send_errctx(cc
, errctx
);
1919 ret
= lls_serialize_parse_result(lpr
, cmd
, &pad
.slpr
, &pad
.slpr_size
);
1921 num_inputs
= lls_num_inputs(lpr
);
1922 for (i
= 0; i
< num_inputs
; i
++) {
1924 ret
= verify_path(lls_input(i
, lpr
), &path
);
1926 ret
= send_sb_va(&cc
->scc
, SBD_ERROR_LOG
, "%s: %s\n",
1927 lls_input(i
, lpr
), para_strerror(-ret
));
1932 if (ret
== 1) /* directory */
1933 ret
= for_each_file_in_dir(path
, add_one_audio_file
,
1935 else /* regular file */
1936 ret
= add_one_audio_file(path
, &pad
);
1938 send_sb_va(&cc
->scc
, SBD_OUTPUT
, "%s: %s\n", path
,
1939 para_strerror(-ret
));
1950 EXPORT_SERVER_CMD_HANDLER(add
);
1952 /** Flags used by the touch command. */
1954 /** Whether the \p FNM_PATHNAME flag should be passed to fnmatch(). */
1955 TOUCH_FLAG_FNM_PATHNAME
= 1,
1956 /** Activates verbose mode. */
1957 TOUCH_FLAG_VERBOSE
= 2
1960 static int touch_audio_file(__a_unused
struct osl_table
*table
,
1961 struct osl_row
*row
, const char *name
, void *data
)
1963 struct afs_callback_arg
*aca
= data
;
1964 bool v_given
= SERVER_CMD_OPT_GIVEN(TOUCH
, VERBOSE
, aca
->lpr
);
1965 const struct lls_opt_result
*r_n
, *r_l
, *r_i
, *r_y
, *r_a
;
1967 struct osl_object obj
;
1968 struct afs_info old_afsi
, new_afsi
;
1970 struct afsi_change_event_data aced
;
1972 r_n
= SERVER_CMD_OPT_RESULT(TOUCH
, NUMPLAYED
, aca
->lpr
);
1973 r_l
= SERVER_CMD_OPT_RESULT(TOUCH
, LASTPLAYED
, aca
->lpr
);
1974 r_i
= SERVER_CMD_OPT_RESULT(TOUCH
, IMAGE_ID
, aca
->lpr
);
1975 r_y
= SERVER_CMD_OPT_RESULT(TOUCH
, LYRICS_ID
, aca
->lpr
);
1976 r_a
= SERVER_CMD_OPT_RESULT(TOUCH
, AMP
, aca
->lpr
);
1977 no_options
= !lls_opt_given(r_n
) && !lls_opt_given(r_l
) && !lls_opt_given(r_i
)
1978 && !lls_opt_given(r_y
) && !lls_opt_given(r_a
);
1980 ret
= get_afsi_object_of_row(row
, &obj
);
1982 afs_error(aca
, "cannot touch %s\n", name
);
1985 ret
= load_afsi(&old_afsi
, &obj
);
1987 afs_error(aca
, "cannot touch %s\n", name
);
1990 new_afsi
= old_afsi
;
1992 new_afsi
.num_played
++;
1993 new_afsi
.last_played
= time(NULL
);
1995 para_printf(&aca
->pbout
, "%s: num_played = %u, "
1996 "last_played = now()\n", name
,
1997 new_afsi
.num_played
);
1999 if (lls_opt_given(r_l
))
2000 new_afsi
.last_played
= lls_uint64_val(0, r_l
);
2001 if (lls_opt_given(r_n
))
2002 new_afsi
.num_played
= lls_uint32_val(0, r_n
);
2003 if (lls_opt_given(r_i
))
2004 new_afsi
.image_id
= lls_uint32_val(0, r_i
);
2005 if (lls_opt_given(r_y
))
2006 new_afsi
.lyrics_id
= lls_uint32_val(0, r_y
);
2007 if (lls_opt_given(r_a
))
2008 new_afsi
.amp
= lls_uint32_val(0, r_a
);
2010 para_printf(&aca
->pbout
, "touching %s\n", name
);
2012 save_afsi(&new_afsi
, &obj
); /* in-place update */
2014 aced
.old_afsi
= &old_afsi
;
2015 return afs_event(AFSI_CHANGE
, &aca
->pbout
, &aced
);
2018 static int com_touch_callback(struct afs_callback_arg
*aca
)
2020 const struct lls_command
*cmd
= SERVER_CMD_CMD_PTR(TOUCH
);
2022 const struct lls_opt_result
*r_i
, *r_y
;
2024 struct pattern_match_data pmd
= {
2025 .table
= audio_file_table
,
2026 .loop_col_num
= AFTCOL_HASH
,
2027 .match_col_num
= AFTCOL_PATH
,
2029 .action
= touch_audio_file
2032 ret
= lls_deserialize_parse_result(aca
->query
.data
, cmd
, &aca
->lpr
);
2036 r_i
= SERVER_CMD_OPT_RESULT(TOUCH
, IMAGE_ID
, aca
->lpr
);
2037 if (lls_opt_given(r_i
)) {
2038 uint32_t id
= lls_uint32_val(0, r_i
);
2039 ret
= img_get_name_by_id(id
, NULL
);
2041 afs_error(aca
, "invalid image ID: %u\n", id
);
2045 r_y
= SERVER_CMD_OPT_RESULT(TOUCH
, LYRICS_ID
, aca
->lpr
);
2046 if (lls_opt_given(r_y
)) {
2047 uint32_t id
= lls_uint32_val(0, r_y
);
2048 ret
= lyr_get_name_by_id(id
, NULL
);
2050 afs_error(aca
, "invalid lyrics ID: %u\n", id
);
2054 p_given
= SERVER_CMD_OPT_GIVEN(TOUCH
, PATHNAME_MATCH
, aca
->lpr
);
2056 pmd
.fnmatch_flags
|= FNM_PATHNAME
;
2057 ret
= for_each_matching_row(&pmd
);
2058 if (ret
>= 0 && pmd
.num_matches
== 0)
2060 lls_free_parse_result(aca
->lpr
, cmd
);
2064 static int com_touch(struct command_context
*cc
, struct lls_parse_result
*lpr
)
2066 const struct lls_command
*cmd
= SERVER_CMD_CMD_PTR(TOUCH
);
2070 ret
= lls(lls_check_arg_count(lpr
, 1, INT_MAX
, &errctx
));
2072 send_errctx(cc
, errctx
);
2075 return send_lls_callback_request(com_touch_callback
, cmd
, lpr
, cc
);
2077 EXPORT_SERVER_CMD_HANDLER(touch
);
2079 static int remove_audio_file(__a_unused
struct osl_table
*table
,
2080 struct osl_row
*row
, const char *name
, void *data
)
2082 struct afs_callback_arg
*aca
= data
;
2083 bool v_given
= SERVER_CMD_OPT_GIVEN(RM
, VERBOSE
, aca
->lpr
);
2087 para_printf(&aca
->pbout
, "removing %s\n", name
);
2088 ret
= afs_event(AUDIO_FILE_REMOVE
, &aca
->pbout
, row
);
2091 ret
= osl(osl_del_row(audio_file_table
, row
));
2093 afs_error(aca
, "cannot remove %s\n", name
);
2097 static int com_rm_callback(struct afs_callback_arg
*aca
)
2099 const struct lls_command
*cmd
= SERVER_CMD_CMD_PTR(RM
);
2101 struct pattern_match_data pmd
= {
2102 .table
= audio_file_table
,
2103 .loop_col_num
= AFTCOL_HASH
,
2104 .match_col_num
= AFTCOL_PATH
,
2106 .action
= remove_audio_file
2108 bool v_given
, p_given
, f_given
;
2110 ret
= lls_deserialize_parse_result(aca
->query
.data
, cmd
, &aca
->lpr
);
2113 v_given
= SERVER_CMD_OPT_GIVEN(RM
, VERBOSE
, aca
->lpr
);
2114 p_given
= SERVER_CMD_OPT_GIVEN(RM
, PATHNAME_MATCH
, aca
->lpr
);
2115 f_given
= SERVER_CMD_OPT_GIVEN(RM
, FORCE
, aca
->lpr
);
2118 pmd
.fnmatch_flags
|= FNM_PATHNAME
;
2119 ret
= for_each_matching_row(&pmd
);
2122 if (pmd
.num_matches
== 0) {
2126 para_printf(&aca
->pbout
, "removed %u file(s)\n",
2129 lls_free_parse_result(aca
->lpr
, cmd
);
2133 /* TODO options: -r (recursive) */
2134 static int com_rm(struct command_context
*cc
, struct lls_parse_result
*lpr
)
2136 const struct lls_command
*cmd
= SERVER_CMD_CMD_PTR(RM
);
2140 ret
= lls(lls_check_arg_count(lpr
, 1, INT_MAX
, &errctx
));
2142 send_errctx(cc
, errctx
);
2145 return send_lls_callback_request(com_rm_callback
, cmd
, lpr
, cc
);
2147 EXPORT_SERVER_CMD_HANDLER(rm
);
2149 /** Data passed to the action handler of com_cpsi(). */
2150 struct cpsi_action_data
{
2151 /** Values are copied from here. */
2152 struct afs_info source_afsi
;
2153 /** What was passed to com_cpsi_callback(). */
2154 struct afs_callback_arg
*aca
;
2158 static int copy_selector_info(__a_unused
struct osl_table
*table
,
2159 struct osl_row
*row
, const char *name
, void *data
)
2161 struct cpsi_action_data
*cad
= data
;
2162 struct osl_object target_afsi_obj
;
2164 struct afs_info old_afsi
, target_afsi
;
2165 struct afsi_change_event_data aced
;
2166 bool a_given
, y_given
, i_given
, l_given
, n_given
, v_given
;
2168 a_given
= SERVER_CMD_OPT_GIVEN(CPSI
, ATTRIBUTE_BITMAP
, cad
->aca
->lpr
);
2169 y_given
= SERVER_CMD_OPT_GIVEN(CPSI
, LYRICS_ID
, cad
->aca
->lpr
);
2170 i_given
= SERVER_CMD_OPT_GIVEN(CPSI
, IMAGE_ID
, cad
->aca
->lpr
);
2171 l_given
= SERVER_CMD_OPT_GIVEN(CPSI
, LASTPLAYED
, cad
->aca
->lpr
);
2172 n_given
= SERVER_CMD_OPT_GIVEN(CPSI
, NUMPLAYED
, cad
->aca
->lpr
);
2173 v_given
= SERVER_CMD_OPT_GIVEN(CPSI
, VERBOSE
, cad
->aca
->lpr
);
2175 ret
= get_afsi_object_of_row(row
, &target_afsi_obj
);
2178 ret
= load_afsi(&target_afsi
, &target_afsi_obj
);
2181 old_afsi
= target_afsi
;
2182 if (cad
->copy_all
|| y_given
)
2183 target_afsi
.lyrics_id
= cad
->source_afsi
.lyrics_id
;
2184 if (cad
->copy_all
|| i_given
)
2185 target_afsi
.image_id
= cad
->source_afsi
.image_id
;
2186 if (cad
->copy_all
|| l_given
)
2187 target_afsi
.last_played
= cad
->source_afsi
.last_played
;
2188 if (cad
->copy_all
|| n_given
)
2189 target_afsi
.num_played
= cad
->source_afsi
.num_played
;
2190 if (cad
->copy_all
|| a_given
)
2191 target_afsi
.attributes
= cad
->source_afsi
.attributes
;
2192 save_afsi(&target_afsi
, &target_afsi_obj
); /* in-place update */
2194 para_printf(&cad
->aca
->pbout
, "copied afsi to %s\n", name
);
2196 aced
.old_afsi
= &old_afsi
;
2197 return afs_event(AFSI_CHANGE
, &cad
->aca
->pbout
, &aced
);
2200 static int com_cpsi_callback(struct afs_callback_arg
*aca
)
2202 const struct lls_command
*cmd
= SERVER_CMD_CMD_PTR(CPSI
);
2203 bool a_given
, y_given
, i_given
, l_given
, n_given
, v_given
;
2204 struct cpsi_action_data cad
= {.aca
= aca
};
2206 struct pattern_match_data pmd
= {
2207 .table
= audio_file_table
,
2208 .loop_col_num
= AFTCOL_HASH
,
2209 .match_col_num
= AFTCOL_PATH
,
2210 .input_skip
= 1, /* skip first argument (source file) */
2212 .action
= copy_selector_info
2215 ret
= lls_deserialize_parse_result(aca
->query
.data
, cmd
, &aca
->lpr
);
2219 a_given
= SERVER_CMD_OPT_GIVEN(CPSI
, ATTRIBUTE_BITMAP
, aca
->lpr
);
2220 y_given
= SERVER_CMD_OPT_GIVEN(CPSI
, LYRICS_ID
, aca
->lpr
);
2221 i_given
= SERVER_CMD_OPT_GIVEN(CPSI
, IMAGE_ID
, aca
->lpr
);
2222 l_given
= SERVER_CMD_OPT_GIVEN(CPSI
, LASTPLAYED
, aca
->lpr
);
2223 n_given
= SERVER_CMD_OPT_GIVEN(CPSI
, NUMPLAYED
, aca
->lpr
);
2224 v_given
= SERVER_CMD_OPT_GIVEN(CPSI
, VERBOSE
, aca
->lpr
);
2225 cad
.copy_all
= !a_given
&& !y_given
&& !i_given
&& !l_given
&& !n_given
;
2227 ret
= get_afsi_of_path(lls_input(0, aca
->lpr
), &cad
.source_afsi
);
2230 ret
= for_each_matching_row(&pmd
);
2233 if (pmd
.num_matches
> 0) {
2235 para_printf(&aca
->pbout
, "updated afsi of %u file(s)\n",
2240 lls_free_parse_result(aca
->lpr
, cmd
);
2244 static int com_cpsi(struct command_context
*cc
, struct lls_parse_result
*lpr
)
2246 const struct lls_command
*cmd
= SERVER_CMD_CMD_PTR(CPSI
);
2248 int ret
= lls(lls_check_arg_count(lpr
, 2, INT_MAX
, &errctx
));
2250 send_errctx(cc
, errctx
);
2253 return send_lls_callback_request(com_cpsi_callback
, cmd
, lpr
, cc
);
2255 EXPORT_SERVER_CMD_HANDLER(cpsi
);
2257 struct change_atts_data
{
2258 uint64_t add_mask
, del_mask
;
2259 struct afs_callback_arg
*aca
;
2262 static int change_atts(__a_unused
struct osl_table
*table
,
2263 struct osl_row
*row
, __a_unused
const char *name
, void *data
)
2266 struct osl_object obj
;
2267 struct afs_info old_afsi
, new_afsi
;
2268 struct afsi_change_event_data aced
= {
2270 .old_afsi
= &old_afsi
2272 struct change_atts_data
*cad
= data
;
2274 ret
= get_afsi_object_of_row(row
, &obj
);
2277 ret
= load_afsi(&old_afsi
, &obj
);
2280 new_afsi
= old_afsi
;
2281 new_afsi
.attributes
|= cad
->add_mask
;
2282 new_afsi
.attributes
&= ~cad
->del_mask
;
2283 save_afsi(&new_afsi
, &obj
); /* in-place update */
2284 return afs_event(AFSI_CHANGE
, &cad
->aca
->pbout
, &aced
);
2287 static int com_setatt_callback(struct afs_callback_arg
*aca
)
2289 const struct lls_command
*cmd
= SERVER_CMD_CMD_PTR(SETATT
);
2291 struct change_atts_data cad
= {.aca
= aca
};
2292 struct pattern_match_data pmd
= {
2293 .table
= audio_file_table
,
2294 .loop_col_num
= AFTCOL_HASH
,
2295 .match_col_num
= AFTCOL_PATH
,
2296 .pm_flags
= PM_SKIP_EMPTY_NAME
,
2298 .action
= change_atts
2300 unsigned num_inputs
;
2302 ret
= lls_deserialize_parse_result(aca
->query
.data
, cmd
, &aca
->lpr
);
2306 num_inputs
= lls_num_inputs(aca
->lpr
);
2307 for (i
= 0; i
< num_inputs
; i
++) {
2308 unsigned char bitnum
;
2310 const char *arg
= lls_input(i
, aca
->lpr
);
2312 size_t len
= strlen(arg
);
2314 ret
= -E_ATTR_SYNTAX
;
2318 if (c
!= '+' && c
!= '-') {
2319 if (cad
.add_mask
== 0 && cad
.del_mask
== 0)
2320 goto out
; /* no attribute modifier given */
2324 memcpy(p
, arg
, len
- 1);
2326 ret
= get_attribute_bitnum_by_name(p
, &bitnum
);
2329 afs_error(aca
, "invalid argument: %s\n", arg
);
2333 cad
.add_mask
|= (one
<< bitnum
);
2335 cad
.del_mask
|= (one
<< bitnum
);
2337 /* no pattern given */
2338 ret
= -E_ATTR_SYNTAX
;
2342 ret
= for_each_matching_row(&pmd
);
2343 if (ret
>= 0 && pmd
.num_matches
== 0)
2346 lls_free_parse_result(aca
->lpr
, cmd
);
2350 static int com_setatt(struct command_context
*cc
, struct lls_parse_result
*lpr
)
2352 const struct lls_command
*cmd
= SERVER_CMD_CMD_PTR(SETATT
);
2354 int ret
= lls(lls_check_arg_count(lpr
, 2, INT_MAX
, &errctx
));
2357 send_errctx(cc
, errctx
);
2360 return send_lls_callback_request(com_setatt_callback
, cmd
, lpr
, cc
);
2362 EXPORT_SERVER_CMD_HANDLER(setatt
);
2364 static int afs_stat_callback(struct afs_callback_arg
*aca
)
2366 int *parser_friendly
= aca
->query
.data
;
2367 char *buf
= *parser_friendly
?
2368 parser_friendly_status_items
: status_items
;
2372 return pass_buffer_as_shm(aca
->fd
, SBD_OUTPUT
, buf
, strlen(buf
));
2376 * Get the current afs status items from the afs process and send it.
2378 * \param cc The command context, used e.g. for data encryption.
2379 * \param parser_friendly Whether parser-friendly output format should be used.
2381 * As the contents of the afs status items change in time and the command
2382 * handler only has a COW version created at fork time, it can not send
2383 * up-to-date afs status items directly. Therefore the usual callback mechanism
2384 * is used to pass the status items from the afs process to the command handler
2385 * via a shared memory area and a pipe.
2387 * \return The return value of the underlying call to \ref send_callback_request().
2389 int send_afs_status(struct command_context
*cc
, int parser_friendly
)
2391 struct osl_object query
= {.data
= &parser_friendly
,
2392 .size
= sizeof(parser_friendly
)};
2394 return send_callback_request(afs_stat_callback
, &query
,
2395 afs_cb_result_handler
, cc
);
2398 /* returns success on non-fatal errors to keep the loop going */
2399 static int check_audio_file(struct osl_row
*row
, void *data
)
2402 struct para_buffer
*pb
= data
;
2403 struct stat statbuf
;
2404 int ret
= get_audio_file_path_of_row(row
, &path
);
2405 struct afs_info afsi
;
2409 para_printf(pb
, "%s\n", para_strerror(-ret
));
2412 if (stat(path
, &statbuf
) < 0)
2413 para_printf(pb
, "%s: stat error (%s)\n", path
, strerror(errno
));
2414 else if (!S_ISREG(statbuf
.st_mode
))
2415 para_printf(pb
, "%s: not a regular file\n", path
);
2416 ret
= get_afsi_of_row(row
, &afsi
);
2418 para_printf(pb
, "%s: %s\n", path
, para_strerror(-ret
));
2421 ret
= lyr_get_name_by_id(afsi
.lyrics_id
, &blob_name
);
2423 para_printf(pb
, "%s lyrics id %u: %s\n", path
, afsi
.lyrics_id
,
2424 para_strerror(-ret
));
2425 ret
= img_get_name_by_id(afsi
.image_id
, &blob_name
);
2427 para_printf(pb
, "%s image id %u: %s\n", path
, afsi
.image_id
,
2428 para_strerror(-ret
));
2433 * Check the audio file table for inconsistencies.
2435 * \param aca Only ->pbout is used for diagnostics.
2437 * \return Standard. Inconsistencies are reported but not regarded as an error.
2439 int aft_check_callback(struct afs_callback_arg
*aca
)
2441 para_printf(&aca
->pbout
, "checking audio file table...\n");
2442 return audio_file_loop(&aca
->pbout
, check_audio_file
);
2445 struct aft_check_atts_data
{
2447 struct para_buffer
*pb
;
2450 static int check_atts_of_audio_file(struct osl_row
*row
, void *data
)
2452 struct aft_check_atts_data
*acad
= data
;
2454 struct afs_info afsi
;
2458 ret
= get_afsi_of_row(row
, &afsi
);
2460 para_printf(acad
->pb
, "cannot get afsi\n");
2463 bad_bits
= afsi
.attributes
& ~acad
->att_mask
;
2464 if (bad_bits
== 0) /* OK */
2466 ret
= get_audio_file_path_of_row(row
, &path
);
2468 para_printf(acad
->pb
, "cannot get path\n");
2471 para_printf(acad
->pb
, "invalid attribute bits (%" PRIu64
"): %s\n",
2473 /* return success to keep looping */
2478 * Iterate over all audio files and check the attribute bit mask.
2480 * \param att_mask The mask of all valid attributes.
2481 * \param pb Used for reporting inconsistencies.
2483 * This reads the attribute bit mask of each audio file from the afs info
2484 * structure stored in the audio file table and verifies that all set bits are
2485 * also turned on in \a att_mask, i.e., correspond to an attribute of the
2486 * attribute table. Audio files for which this is not the case are reported via
2489 * \return Standard. Inconsistencies are not regarded as errors.
2491 * \sa \ref attribute_check_callback().
2493 int aft_check_attributes(uint64_t att_mask
, struct para_buffer
*pb
)
2495 struct aft_check_atts_data acad
= {.att_mask
= att_mask
, .pb
= pb
};
2497 para_printf(pb
, "checking attributes, mask: %" PRIx64
"\n", att_mask
);
2498 return audio_file_loop(&acad
, check_atts_of_audio_file
);
2502 * This sets audio_file_table to NULL, but leaves current_aft_row unmodified,
2503 * though stale (pointing to unmapped memory). If the table is being closed
2504 * because we received SIGHUP, the table will be reopened after the config file
2505 * has been reloaded. We remember the hash of the current audio file here so
2506 * that aft_open() can initialize current_aft_row by looking up the saved hash.
2508 static void aft_close(void)
2513 if (current_aft_row
) {
2514 ret
= get_hash_of_row(current_aft_row
, &p
);
2516 PARA_WARNING_LOG("hash lookup failure\n");
2517 current_aft_row
= NULL
;
2519 memcpy(current_hash
, p
, HASH2_SIZE
);
2521 osl_close_table(audio_file_table
, OSL_MARK_CLEAN
);
2522 audio_file_table
= NULL
;
2525 static int aft_open(const char *dir
)
2529 audio_file_table_desc
.dir
= dir
;
2530 ret
= osl(osl_open_table(&audio_file_table_desc
, &audio_file_table
));
2533 osl_get_num_rows(audio_file_table
, &num
);
2534 PARA_INFO_LOG("audio file table contains %u files\n", num
);
2535 if (!current_aft_row
) {
2536 PARA_DEBUG_LOG("no current aft row\n");
2539 /* SIGHUP case, update current_aft_row */
2540 ret
= aft_get_row_of_hash(current_hash
, ¤t_aft_row
);
2541 if (ret
< 0) { /* not fatal */
2542 PARA_WARNING_LOG("current hash lookup failure: %s\n",
2543 para_strerror(-ret
));
2544 current_aft_row
= NULL
;
2547 PARA_NOTICE_LOG("current audio file hash lookup: success\n");
2550 audio_file_table
= NULL
;
2551 if (ret
== -OSL_ERRNO_TO_PARA_ERROR(E_OSL_NOENT
)) {
2552 PARA_WARNING_LOG("no audio file table\n");
2555 PARA_NOTICE_LOG("failed to open audio file table\n");
2559 static int aft_create(const char *dir
)
2561 audio_file_table_desc
.dir
= dir
;
2562 return osl(osl_create_table(&audio_file_table_desc
));
2565 static int clear_attribute(struct osl_row
*row
, void *data
)
2567 struct rmatt_event_data
*red
= data
;
2568 struct afs_info afsi
;
2569 struct osl_object obj
;
2570 int ret
= get_afsi_object_of_row(row
, &obj
);
2571 uint64_t mask
= ~(1ULL << red
->bitnum
);
2575 ret
= load_afsi(&afsi
, &obj
);
2578 afsi
.attributes
&= mask
;
2579 save_afsi(&afsi
, &obj
);
2583 static int aft_event_handler(enum afs_events event
, struct para_buffer
*pb
,
2589 case ATTRIBUTE_REMOVE
: {
2590 const struct rmatt_event_data
*red
= data
;
2591 para_printf(pb
, "clearing attribute %s (bit %u) from all "
2592 "entries in the audio file table\n", red
->name
,
2594 return audio_file_loop(data
, clear_attribute
);
2595 } case AFSI_CHANGE
: {
2596 struct afsi_change_event_data
*aced
= data
;
2597 uint64_t old_last_played
= status_item_ls_data
.afsi
.last_played
;
2598 if (aced
->aft_row
!= current_aft_row
)
2600 ret
= get_afsi_of_row(aced
->aft_row
, &status_item_ls_data
.afsi
);
2603 status_item_ls_data
.afsi
.last_played
= old_last_played
;
2604 make_status_items();
2606 } case AUDIO_FILE_RENAME
: {
2608 if (data
!= current_aft_row
)
2610 ret
= get_audio_file_path_of_row(current_aft_row
, &path
);
2613 free(status_item_ls_data
.path
);
2614 status_item_ls_data
.path
= para_strdup(path
);
2615 make_status_items();
2617 } case AFHI_CHANGE
: {
2618 if (data
!= current_aft_row
)
2620 ret
= get_afhi_of_row(data
, &status_item_ls_data
.afhi
);
2623 make_status_items();
2625 } case AUDIO_FILE_REMOVE
: {
2626 if (data
== current_aft_row
)
2627 current_aft_row
= NULL
;
2634 * These events are rare. We don't bother to check whether the
2635 * current status items are affected and simply recreate them
2636 * whenever an audio file is open.
2638 if (!current_aft_row
)
2640 ret
= get_afhi_of_row(current_aft_row
,
2641 &status_item_ls_data
.afhi
);
2644 make_status_items();
2651 /** The audio file table contains information about known audio files. */
2652 const struct afs_table_operations aft_ops
= {
2655 .create
= aft_create
,
2656 .event_handler
= aft_event_handler
,