mixer: Remove default moods for sleep.
[paraslash.git] / blob.c
1 /* Copyright (C) 2007 Andre Noll <maan@tuebingen.mpg.de>, see file COPYING. */
2
3 /** \file blob.c Macros and functions for blob handling. */
4
5 #include <regex.h>
6 #include <fnmatch.h>
7 #include <osl.h>
8 #include <lopsub.h>
9
10 #include "server_cmd.lsg.h"
11 #include "para.h"
12 #include "error.h"
13 #include "crypt.h"
14 #include "string.h"
15 #include "afh.h"
16 #include "afs.h"
17 #include "ipc.h"
18 #include "portable_io.h"
19 #include "sideband.h"
20 #include "command.h"
21
22 /**
23  * Compare two osl objects pointing to unsigned integers of 32 bit size.
24  *
25  * \param obj1 Pointer to the first integer.
26  * \param obj2 Pointer to the second integer.
27  *
28  * \return The values required for an osl compare function.
29  */
30 static int uint32_compare(const struct osl_object *obj1, const struct osl_object *obj2)
31 {
32         uint32_t d1 = read_u32(obj1->data);
33         uint32_t d2 = read_u32(obj2->data);
34
35         if (d1 < d2)
36                 return 1;
37         if (d1 > d2)
38                 return -1;
39         return 0;
40 }
41
42 static struct osl_column_description blob_cols[] = {
43         [BLOBCOL_ID] = {
44                 .storage_type = OSL_MAPPED_STORAGE,
45                 .storage_flags = OSL_RBTREE | OSL_UNIQUE | OSL_FIXED_SIZE,
46                 .name = "id",
47                 .data_size = 4,
48                 .compare_function = uint32_compare
49         },
50         [BLOBCOL_NAME] = {
51                 .storage_type = OSL_MAPPED_STORAGE,
52                 .storage_flags = OSL_RBTREE | OSL_UNIQUE,
53                 .name = "name",
54                 .compare_function = string_compare
55         },
56         [BLOBCOL_DEF] = {
57                 .storage_type = OSL_DISK_STORAGE,
58                 .storage_flags = 0,
59                 .name = "definition"
60         }
61 };
62
63 /** Define an osl table description for a blob table. */
64 #define DEFINE_BLOB_TABLE_DESC(table_name) \
65         static struct osl_table_description table_name ## _table_desc = { \
66                 .name = #table_name, \
67                 .num_columns = NUM_BLOB_COLUMNS, \
68                 .flags = OSL_LARGE_TABLE, \
69                 .column_descriptions = blob_cols \
70         };
71
72 /** Define a pointer to an osl blob table with a canonical name. */
73 #define DEFINE_BLOB_TABLE_PTR(table_name) struct osl_table *table_name ## _table;
74
75
76 /** Define a blob table. */
77 #define INIT_BLOB_TABLE(table_name) \
78         DEFINE_BLOB_TABLE_DESC(table_name); \
79         DEFINE_BLOB_TABLE_PTR(table_name);
80
81 /* doxygen isn't smart enough to recognize these */
82 /** \cond blob_table */
83 INIT_BLOB_TABLE(lyrics);
84 INIT_BLOB_TABLE(images);
85 INIT_BLOB_TABLE(moods);
86 INIT_BLOB_TABLE(playlists);
87 /** \endcond blob_table */
88
89 static int print_blob(struct osl_table *table, struct osl_row *row,
90                 const char *name, void *data)
91 {
92         struct afs_callback_arg *aca = data;
93         bool l_given = SERVER_CMD_OPT_GIVEN(LSMOOD, LONG, aca->lpr);
94         struct osl_object obj;
95         uint32_t id;
96         int ret;
97
98         if (!l_given) {
99                 para_printf(&aca->pbout, "%s\n", name);
100                 return 0;
101         }
102         ret = osl(osl_get_object(table, row, BLOBCOL_ID, &obj));
103         if (ret < 0) {
104                 para_printf(&aca->pbout, "cannot list %s\n", name);
105                 return ret;
106         }
107         id = *(uint32_t *)obj.data;
108         para_printf(&aca->pbout, "%u\t%s\n", id, name);
109         return 1;
110 }
111
112 static int com_lsblob_callback(const struct lls_command * const cmd,
113                 struct osl_table *table, struct afs_callback_arg *aca)
114 {
115         bool i_given, r_given;
116         struct pattern_match_data pmd = {
117                 .table = table,
118                 .pm_flags = PM_NO_PATTERN_MATCHES_EVERYTHING | PM_SKIP_EMPTY_NAME,
119                 .match_col_num = BLOBCOL_NAME,
120                 .data = aca,
121                 .action = print_blob,
122         };
123         int ret;
124         ret = lls_deserialize_parse_result(aca->query.data, cmd, &aca->lpr);
125         pmd.lpr = aca->lpr;
126         assert(ret >= 0);
127         i_given = SERVER_CMD_OPT_GIVEN(LSMOOD, ID_SORT, aca->lpr);
128         r_given = SERVER_CMD_OPT_GIVEN(LSMOOD, REVERSE, aca->lpr);
129
130         if (r_given)
131                 pmd.pm_flags |= PM_REVERSE_LOOP;
132         if (i_given)
133                 pmd.loop_col_num = BLOBCOL_ID;
134         else
135                 pmd.loop_col_num = BLOBCOL_NAME;
136         ret = for_each_matching_row(&pmd);
137         if (ret < 0)
138                 goto out;
139         if (pmd.num_matches == 0 && lls_num_inputs(aca->lpr) > 0)
140                 ret = -E_NO_MATCH;
141 out:
142         lls_free_parse_result(aca->lpr, cmd);
143         return ret;
144 }
145
146 static int com_lsblob(afs_callback *f, const struct lls_command * const cmd,
147                 struct command_context *cc, struct lls_parse_result *lpr)
148 {
149         return send_lls_callback_request(f, cmd, lpr, cc);
150 }
151
152 static int cat_blob(struct osl_table *table, struct osl_row *row,
153                 __a_unused const char *name, void *data)
154 {
155         int ret = 0, ret2, fd = *(int *)data;
156         struct osl_object obj;
157
158         ret = osl(osl_open_disk_object(table, row, BLOBCOL_DEF, &obj));
159         if (ret < 0)
160                 return (ret == osl(-E_OSL_EMPTY))? 0 : ret;
161         assert(obj.size > 0);
162         ret = pass_buffer_as_shm(fd, SBD_OUTPUT, obj.data, obj.size);
163         ret2 = osl(osl_close_disk_object(&obj));
164         return (ret < 0)? ret : ret2;
165 }
166
167 static int com_catblob_callback(const struct lls_command * const cmd,
168                 struct osl_table *table, struct afs_callback_arg *aca)
169 {
170         int ret;
171         struct pattern_match_data pmd = {
172                 .table = table,
173                 .loop_col_num = BLOBCOL_NAME,
174                 .match_col_num = BLOBCOL_NAME,
175                 .pm_flags = PM_SKIP_EMPTY_NAME,
176                 .data = &aca->fd,
177                 .action = cat_blob
178         };
179         ret = lls_deserialize_parse_result(aca->query.data, cmd, &aca->lpr);
180         assert(ret >= 0);
181         pmd.lpr = aca->lpr;
182         ret = for_each_matching_row(&pmd);
183         if (ret < 0)
184                 goto out;
185         if (pmd.num_matches == 0)
186                 ret = -E_NO_MATCH;
187 out:
188         lls_free_parse_result(aca->lpr, cmd);
189         return ret;
190 }
191
192 static int com_catblob(afs_callback *f, const struct lls_command * const cmd,
193                 struct command_context *cc, struct lls_parse_result *lpr)
194 {
195         char *errctx;
196         int ret = lls(lls_check_arg_count(lpr, 1, INT_MAX, &errctx));
197
198         if (ret < 0) {
199                 send_errctx(cc, errctx);
200                 return ret;
201         }
202         return send_lls_callback_request(f, cmd, lpr, cc);
203 }
204
205 static int remove_blob(struct osl_table *table, struct osl_row *row,
206                 const char *name, void *data)
207 {
208         struct afs_callback_arg *aca = data;
209         int ret = osl(osl_del_row(table, row));
210         if (ret < 0) {
211                 para_printf(&aca->pbout, "cannot remove %s\n", name);
212                 return ret;
213         }
214         return 1;
215 }
216
217 static int com_rmblob_callback(const struct lls_command * const cmd,
218                 struct osl_table *table, struct afs_callback_arg *aca)
219 {
220         int ret;
221         struct pattern_match_data pmd = {
222                 .table = table,
223                 .loop_col_num = BLOBCOL_NAME,
224                 .match_col_num = BLOBCOL_NAME,
225                 .pm_flags = PM_SKIP_EMPTY_NAME,
226                 .data = aca,
227                 .action = remove_blob
228         };
229         ret = lls_deserialize_parse_result(aca->query.data, cmd, &aca->lpr);
230         assert(ret >= 0);
231         pmd.lpr = aca->lpr;
232         ret = for_each_matching_row(&pmd);
233         if (ret < 0)
234                 goto out;
235         if (pmd.num_matches == 0)
236                 ret = -E_NO_MATCH;
237         else {
238                 para_printf(&aca->pbout, "removed %u blob(s)\n",
239                         pmd.num_matches);
240                 ret = afs_event(BLOB_REMOVE, NULL, table);
241         }
242 out:
243         lls_free_parse_result(aca->lpr, cmd);
244         return ret;
245 }
246
247 static int com_rmblob(afs_callback *f, const struct lls_command * const cmd,
248                 struct command_context *cc, struct lls_parse_result *lpr)
249 {
250         char *errctx;
251         int ret = lls(lls_check_arg_count(lpr, 1, INT_MAX, &errctx));
252
253         if (ret < 0) {
254                 send_errctx(cc, errctx);
255                 return ret;
256         }
257         return send_lls_callback_request(f, cmd, lpr, cc);
258 }
259
260 static int com_addblob_callback(__a_unused const struct lls_command * const cmd,
261                 struct osl_table *table, struct afs_callback_arg *aca)
262 {
263         struct osl_object objs[NUM_BLOB_COLUMNS];
264         char *name = aca->query.data;
265         size_t name_len = strlen(name) + 1;
266         uint32_t id;
267         unsigned num_rows;
268         int ret;
269
270         ret = osl(osl_get_num_rows(table, &num_rows));
271         if (ret < 0)
272                 goto out;
273         if (!num_rows) { /* this is the first entry ever added */
274                 /* insert dummy row containing the id */
275                 id = 2; /* this entry will be entry #1, so 2 is the next */
276                 objs[BLOBCOL_ID].data = &id;
277                 objs[BLOBCOL_ID].size = sizeof(id);
278                 objs[BLOBCOL_NAME].data = "";
279                 objs[BLOBCOL_NAME].size = 1;
280                 objs[BLOBCOL_DEF].data = "";
281                 objs[BLOBCOL_DEF].size = 1;
282                 ret = osl(osl_add_row(table, objs));
283                 if (ret < 0)
284                         goto out;
285         } else {
286                 /* check if name already exists */
287                 struct osl_row *row;
288                 struct osl_object obj = {.data = name, .size = name_len};
289                 ret = osl(osl_get_row(table, BLOBCOL_NAME, &obj, &row));
290                 if (ret < 0 && ret != -OSL_ERRNO_TO_PARA_ERROR(E_OSL_RB_KEY_NOT_FOUND))
291                         goto out;
292                 if (ret >= 0) { /* we already have a blob with this name */
293                         ret = osl(osl_get_object(table, row, BLOBCOL_ID, &obj));
294                         if (ret < 0)
295                                 goto out;
296                         id = *(uint32_t *)obj.data;
297                         obj.data = name + name_len;
298                         obj.size = aca->query.size - name_len;
299                         ret = osl(osl_update_object(table, row, BLOBCOL_DEF, &obj));
300                         goto out;
301                 }
302                 /* new blob, get id of the dummy row and increment it */
303                 obj.data = "";
304                 obj.size = 1;
305                 ret = osl(osl_get_row(table, BLOBCOL_NAME, &obj, &row));
306                 if (ret < 0)
307                         goto out;
308                 ret = osl(osl_get_object(table, row, BLOBCOL_ID, &obj));
309                 if (ret < 0)
310                         goto out;
311                 id = *(uint32_t *)obj.data + 1;
312                 obj.data = &id;
313                 ret = osl(osl_update_object(table, row, BLOBCOL_ID, &obj));
314                 if (ret < 0)
315                         goto out;
316         }
317         id--;
318         objs[BLOBCOL_ID].data = &id;
319         objs[BLOBCOL_ID].size = sizeof(id);
320         objs[BLOBCOL_NAME].data = name;
321         objs[BLOBCOL_NAME].size = name_len;
322         objs[BLOBCOL_DEF].data = name + name_len;
323         objs[BLOBCOL_DEF].size = aca->query.size - name_len;
324         ret = osl(osl_add_row(table, objs));
325         if (ret < 0)
326                 goto out;
327         ret = afs_event(BLOB_ADD, NULL, table);
328 out:
329         if (ret < 0)
330                 para_printf(&aca->pbout, "cannot add %s\n", name);
331         else
332                 para_printf(&aca->pbout, "added %s as id %u\n", name, id);
333         return ret;
334 }
335
336 /* Write input from fd to dynamically allocated buffer, but maximal 10M. */
337 static int fd2buf(struct stream_cipher_context *scc, struct osl_object *obj)
338 {
339         size_t max_size = 10 * 1024 * 1024;
340         int ret;
341         struct iovec iov;
342
343         obj->data = NULL;
344         obj->size = 0;
345 again:
346         do {
347                 ret = recv_sb(scc, SBD_BLOB_DATA, max_size, &iov);
348         } while (ret == 0);
349
350         if (ret < 0) {
351                 free(obj->data);
352                 obj->data = NULL;
353                 obj->size = 0;
354                 return ret;
355         }
356         if (iov.iov_len == 0) /* end of blob */
357                 return 1;
358         if (!obj->data) {
359                 obj->data = iov.iov_base;
360                 obj->size = iov.iov_len;
361         } else {
362                 obj->data = para_realloc(obj->data, obj->size + iov.iov_len);
363                 memcpy(obj->data + obj->size, iov.iov_base, iov.iov_len);
364                 obj->size += iov.iov_len;
365                 free(iov.iov_base);
366                 max_size -= iov.iov_len;
367         }
368         goto again;
369         return 1;
370 }
371
372 /*
373  * Read blob from a file descriptor and send it to afs.
374  *
375  * This function is called from the addblob command handlers to instruct the
376  * afs process to store the input in a blob table. Input is read and decrypted
377  * from the file descriptor given by cc and appended to arg_obj, which contains
378  * the name of the blob to create. The combined buffer is made available to the
379  * afs process via the callback method.
380  */
381 static int stdin_command(struct command_context *cc,
382                 struct lls_parse_result *lpr, afs_callback *f)
383 {
384         struct osl_object query, stdin_obj;
385         int ret;
386         size_t len = strlen(lls_input(0, lpr));
387
388         ret = send_sb(&cc->scc, NULL, 0, SBD_AWAITING_DATA, false);
389         if (ret < 0)
390                 return ret;
391         ret = fd2buf(&cc->scc, &stdin_obj);
392         if (ret < 0)
393                 return ret;
394         query.size = len + 1 + stdin_obj.size;
395         query.data = para_malloc(query.size);
396         memcpy(query.data, lls_input(0, lpr), len + 1);
397         if (stdin_obj.size > 0)
398                 memcpy((char *)query.data + len + 1, stdin_obj.data,
399                         stdin_obj.size);
400         free(stdin_obj.data);
401         ret = send_callback_request(f, &query, afs_cb_result_handler, cc);
402         free(query.data);
403         return ret;
404 }
405
406 static int com_addblob(afs_callback *f, __a_unused const struct lls_command * const cmd,
407                 struct command_context *cc, struct lls_parse_result *lpr)
408 {
409         char *errctx;
410         int ret = lls(lls_check_arg_count(lpr, 1, 1, &errctx));
411
412         if (ret < 0) {
413                 send_errctx(cc, errctx);
414                 return ret;
415         }
416         if (!lls_input(0, lpr)[0]) /* empty name is reserved for the dummy row */
417                 return -E_BLOB_SYNTAX;
418         return stdin_command(cc, lpr, f);
419 }
420
421 static int com_mvblob_callback(const struct lls_command * const cmd,
422                 struct osl_table *table, struct afs_callback_arg *aca)
423 {
424         const char *src, *dest;
425         struct osl_object obj;
426         struct osl_row *row;
427         int ret;
428
429         ret = lls_deserialize_parse_result(aca->query.data, cmd, &aca->lpr);
430         assert(ret >= 0);
431         src = lls_input(0, aca->lpr);
432         dest = lls_input(1, aca->lpr);
433         obj.data = (char *)src;
434         obj.size = strlen(src) + 1;
435         ret = osl(osl_get_row(table, BLOBCOL_NAME, &obj, &row));
436
437         if (ret < 0) {
438                 para_printf(&aca->pbout, "cannot find source blob %s\n", src);
439                 goto out;
440         }
441         obj.data = (char *)dest;
442         obj.size = strlen(dest) + 1;
443         ret = osl(osl_update_object(table, row, BLOBCOL_NAME, &obj));
444         if (ret < 0) {
445                 para_printf(&aca->pbout, "cannot rename blob %s to %s\n",
446                         src, dest);
447                 goto out;
448         }
449         ret = afs_event(BLOB_RENAME, NULL, table);
450 out:
451         lls_free_parse_result(aca->lpr, cmd);
452         return ret;
453 }
454
455 static int com_mvblob(afs_callback *f, const struct lls_command * const cmd,
456                 struct command_context *cc, struct lls_parse_result *lpr)
457 {
458         char *errctx;
459         int ret = lls(lls_check_arg_count(lpr, 2, 2, &errctx));
460
461         if (ret < 0) {
462                 send_errctx(cc, errctx);
463                 return ret;
464         }
465         return send_lls_callback_request(f, cmd, lpr, cc);
466 }
467
468 #define DEFINE_BLOB_COMMAND(cmd_name, c_cmd_name, table_name, short_name, c_short_name) \
469         static int com_ ## cmd_name ## short_name ## _callback(struct afs_callback_arg *aca) \
470         { \
471                 const struct lls_command *cmd = SERVER_CMD_CMD_PTR(c_cmd_name ## c_short_name); \
472                 return com_ ## cmd_name ## blob_callback(cmd, table_name ## _table, aca); \
473         } \
474         static int com_ ## cmd_name ## short_name(struct command_context *cc, struct lls_parse_result *lpr) \
475         { \
476                 const struct lls_command *cmd = SERVER_CMD_CMD_PTR(c_cmd_name ## c_short_name); \
477                 return com_ ## cmd_name ## blob(com_ ## cmd_name ## short_name ## _callback, cmd, cc, lpr); \
478         } \
479         EXPORT_SERVER_CMD_HANDLER(cmd_name ## short_name);
480
481 static int blob_get_name_by_id(struct osl_table *table, uint32_t id,
482                 char **name)
483 {
484         struct osl_row *row;
485         struct osl_object obj = {.data = &id, .size = sizeof(id)};
486         int ret;
487
488         if (name)
489                 *name = NULL;
490         if (!id)
491                 return 1;
492         ret = osl(osl_get_row(table, BLOBCOL_ID, &obj, &row));
493         if (ret < 0)
494                 return ret;
495         ret = osl(osl_get_object(table, row, BLOBCOL_NAME, &obj));
496         if (ret < 0)
497                 return ret;
498         if (*(char *)obj.data == '\0')
499                 return -E_DUMMY_ROW;
500         if (name)
501                 *name = (char *)obj.data;
502         return 1;
503 }
504
505 /** Define the \p get_name_by_id function for this blob type. */
506 #define DEFINE_GET_NAME_BY_ID(table_name, cmd_prefix) \
507         int cmd_prefix ## _get_name_by_id(uint32_t id, char **name) \
508         { \
509                 return blob_get_name_by_id(table_name ## _table, id, name); \
510         }
511
512
513 static int blob_get_def_by_name(struct osl_table *table, char *name,
514                 struct osl_object *def)
515 {
516         struct osl_row *row;
517         struct osl_object obj = {.data = name, .size = strlen(name) + 1};
518         int ret;
519
520         def->data = NULL;
521         if (!*name)
522                 return 1;
523         ret = osl(osl_get_row(table, BLOBCOL_NAME, &obj, &row));
524         if (ret < 0)
525                 return ret;
526         return osl(osl_open_disk_object(table, row, BLOBCOL_DEF, def));
527 }
528
529 /** Define the \p get_def_by_id function for this blob type. */
530 #define DEFINE_GET_DEF_BY_NAME(table_name, cmd_prefix) \
531         int cmd_prefix ## _get_def_by_name(char *name, struct osl_object *def) \
532         { \
533                 return blob_get_def_by_name(table_name ## _table, name, def); \
534         }
535
536 static int blob_get_def_by_id(struct osl_table *table, uint32_t id,
537                 struct osl_object *def)
538 {
539         struct osl_row *row;
540         struct osl_object obj = {.data = &id, .size = sizeof(id)};
541         int ret;
542
543         def->data = NULL;
544         if (!id)
545                 return 1;
546         ret = osl(osl_get_row(table, BLOBCOL_ID, &obj, &row));
547         if (ret < 0)
548                 return ret;
549         return osl(osl_open_disk_object(table, row, BLOBCOL_DEF, def));
550 }
551
552 /** Define the \p get_def_by_id function for this blob type. */
553 #define DEFINE_GET_DEF_BY_ID(table_name, cmd_prefix) \
554         int cmd_prefix ## _get_def_by_id(uint32_t id, struct osl_object *def) \
555         { \
556                 return blob_get_def_by_id(table_name ## _table, id, def); \
557         }
558
559 static int blob_get_name_and_def_by_row(struct osl_table *table,
560                 const struct osl_row *row, char **name, struct osl_object *def)
561 {
562         struct osl_object obj;
563         int ret = osl(osl_get_object(table, row, BLOBCOL_NAME, &obj));
564         if (ret < 0)
565                 return ret;
566         *name = obj.data;
567         return osl(osl_open_disk_object(table, row, BLOBCOL_DEF, def));
568 }
569 /** Define the \p get_name_and_def_by_row function for this blob type. */
570 #define DEFINE_GET_NAME_AND_DEF_BY_ROW(table_name, cmd_prefix) \
571         int cmd_prefix ## _get_name_and_def_by_row(const struct osl_row *row, \
572                 char **name, struct osl_object *def) \
573         { \
574                 return blob_get_name_and_def_by_row(table_name ## _table, \
575                         row, name, def); \
576         }
577
578 /** Define the \p close function for this blob type. */
579 #define DEFINE_BLOB_CLOSE(table_name) \
580         static void table_name ## _close(void) \
581         { \
582                 osl_close_table(table_name ## _table, OSL_MARK_CLEAN); \
583                 table_name ## _table = NULL; \
584         }
585
586 /** Define the \p create function for this blob type. */
587 #define DEFINE_BLOB_CREATE(table_name) \
588         static int table_name ## _create(const char *dir) \
589         { \
590                 table_name ## _table_desc.dir = dir; \
591                 return osl(osl_create_table(&table_name ## _table_desc)); \
592         }
593
594 static int blob_open(struct osl_table **table,
595                 struct osl_table_description *desc,
596                 const char *dir)
597 {
598         int ret;
599         desc->dir = dir;
600         ret = osl(osl_open_table(desc, table));
601         if (ret >= 0)
602                 return ret;
603         *table = NULL;
604         if (ret >= 0 || ret == -OSL_ERRNO_TO_PARA_ERROR(E_OSL_NOENT))
605                 return 1;
606         return ret;
607 }
608
609 #define DEFINE_BLOB_OPEN(table_name) \
610         static int table_name ## _open(const char *dir) \
611         { \
612                 return blob_open(&table_name ## _table, \
613                         &table_name ## _table_desc, dir); \
614         }
615
616
617 /** Define the \p init function for this blob type. */
618 #define DEFINE_BLOB_INIT(table_name) \
619         void table_name ## _init(struct afs_table *t) \
620         { \
621                 t->open = table_name ## _open; \
622                 t->close = table_name ## _close; \
623                 t->create = table_name ## _create;\
624                 t->event_handler = table_name ##_event_handler; \
625                 table_name ## _table = NULL; \
626         }
627
628
629 /** Define all functions for this blob type. */
630 #define DEFINE_BLOB_FUNCTIONS(table_name, short_name, c_short_name) \
631         DEFINE_BLOB_OPEN(table_name) \
632         DEFINE_BLOB_CLOSE(table_name) \
633         DEFINE_BLOB_CREATE(table_name) \
634         DEFINE_BLOB_INIT(table_name) \
635         DEFINE_BLOB_COMMAND(ls, LS, table_name, short_name, c_short_name) \
636         DEFINE_BLOB_COMMAND(cat, CAT, table_name, short_name, c_short_name) \
637         DEFINE_BLOB_COMMAND(add, ADD, table_name, short_name, c_short_name) \
638         DEFINE_BLOB_COMMAND(rm, RM, table_name, short_name, c_short_name) \
639         DEFINE_BLOB_COMMAND(mv, MV, table_name, short_name, c_short_name) \
640         DEFINE_GET_NAME_BY_ID(table_name, short_name); \
641         DEFINE_GET_DEF_BY_ID(table_name, short_name); \
642         DEFINE_GET_DEF_BY_NAME(table_name, short_name); \
643         DEFINE_GET_NAME_AND_DEF_BY_ROW(table_name, short_name); \
644
645 /* doxygen isn't smart enough to recognize these */
646 /** \cond blob_function */
647 DEFINE_BLOB_FUNCTIONS(lyrics, lyr, LYR);
648 DEFINE_BLOB_FUNCTIONS(images, img, IMG);
649 DEFINE_BLOB_FUNCTIONS(moods, mood, MOOD);
650 DEFINE_BLOB_FUNCTIONS(playlists, pl, PL);
651 /** \endcond blob_function */