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