build: Detect openssl library/header mismatch.
[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 /** Define a blob table. */
76 #define INIT_BLOB_TABLE(table_name) \
77         DEFINE_BLOB_TABLE_DESC(table_name); \
78         DEFINE_BLOB_TABLE_PTR(table_name);
79
80 /* doxygen isn't smart enough to recognize these */
81 /** \cond blob_table */
82 INIT_BLOB_TABLE(lyrics);
83 INIT_BLOB_TABLE(images);
84 INIT_BLOB_TABLE(moods);
85 INIT_BLOB_TABLE(playlists);
86 /** \endcond blob_table */
87
88 static int print_blob(struct osl_table *table, struct osl_row *row,
89                 const char *name, void *data)
90 {
91         struct afs_callback_arg *aca = data;
92         bool l_given = SERVER_CMD_OPT_GIVEN(LSMOOD, LONG, aca->lpr);
93         struct osl_object obj;
94         uint32_t id;
95         int ret;
96
97         if (!l_given) {
98                 para_printf(&aca->pbout, "%s\n", name);
99                 return 0;
100         }
101         ret = osl(osl_get_object(table, row, BLOBCOL_ID, &obj));
102         if (ret < 0) {
103                 para_printf(&aca->pbout, "cannot list %s\n", name);
104                 return ret;
105         }
106         id = read_u32(obj.data);
107         para_printf(&aca->pbout, "%u\t%s\n", id, name);
108         return 1;
109 }
110
111 static int com_lsblob_callback(const struct lls_command * const cmd,
112                 struct osl_table *table, struct afs_callback_arg *aca)
113 {
114         bool i_given, r_given;
115         struct pattern_match_data pmd = {
116                 .table = table,
117                 .pm_flags = PM_NO_PATTERN_MATCHES_EVERYTHING | PM_SKIP_EMPTY_NAME,
118                 .match_col_num = BLOBCOL_NAME,
119                 .data = aca,
120                 .action = print_blob,
121         };
122         int ret;
123
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
180         ret = lls_deserialize_parse_result(aca->query.data, cmd, &aca->lpr);
181         assert(ret >= 0);
182         pmd.lpr = aca->lpr;
183         ret = for_each_matching_row(&pmd);
184         if (ret < 0)
185                 goto out;
186         if (pmd.num_matches == 0)
187                 ret = -E_NO_MATCH;
188 out:
189         lls_free_parse_result(aca->lpr, cmd);
190         return ret;
191 }
192
193 static int com_catblob(afs_callback *f, const struct lls_command * const cmd,
194                 struct command_context *cc, struct lls_parse_result *lpr)
195 {
196         char *errctx;
197         int ret = lls(lls_check_arg_count(lpr, 1, INT_MAX, &errctx));
198
199         if (ret < 0) {
200                 send_errctx(cc, errctx);
201                 return ret;
202         }
203         return send_lls_callback_request(f, cmd, lpr, cc);
204 }
205
206 static int remove_blob(struct osl_table *table, struct osl_row *row,
207                 const char *name, void *data)
208 {
209         struct afs_callback_arg *aca = data;
210         int ret = osl(osl_del_row(table, row));
211
212         if (ret < 0) {
213                 para_printf(&aca->pbout, "cannot remove %s\n", name);
214                 return ret;
215         }
216         return 1;
217 }
218
219 static int com_rmblob_callback(const struct lls_command * const cmd,
220                 struct osl_table *table, struct afs_callback_arg *aca)
221 {
222         int ret;
223         struct pattern_match_data pmd = {
224                 .table = table,
225                 .loop_col_num = BLOBCOL_NAME,
226                 .match_col_num = BLOBCOL_NAME,
227                 .pm_flags = PM_SKIP_EMPTY_NAME,
228                 .data = aca,
229                 .action = remove_blob
230         };
231
232         ret = lls_deserialize_parse_result(aca->query.data, cmd, &aca->lpr);
233         assert(ret >= 0);
234         pmd.lpr = aca->lpr;
235         ret = for_each_matching_row(&pmd);
236         if (ret < 0)
237                 goto out;
238         if (pmd.num_matches == 0)
239                 ret = -E_NO_MATCH;
240         else {
241                 para_printf(&aca->pbout, "removed %u blob(s)\n",
242                         pmd.num_matches);
243                 ret = afs_event(BLOB_REMOVE, NULL, table);
244         }
245 out:
246         lls_free_parse_result(aca->lpr, cmd);
247         return ret;
248 }
249
250 static int com_rmblob(afs_callback *f, const struct lls_command * const cmd,
251                 struct command_context *cc, struct lls_parse_result *lpr)
252 {
253         char *errctx;
254         int ret = lls(lls_check_arg_count(lpr, 1, INT_MAX, &errctx));
255
256         if (ret < 0) {
257                 send_errctx(cc, errctx);
258                 return ret;
259         }
260         return send_lls_callback_request(f, cmd, lpr, cc);
261 }
262
263 static int com_addblob_callback(__a_unused const struct lls_command * const cmd,
264                 struct osl_table *table, struct afs_callback_arg *aca)
265 {
266         struct osl_object objs[NUM_BLOB_COLUMNS];
267         char *name = aca->query.data;
268         size_t name_len = strlen(name) + 1;
269         uint32_t id = (uint32_t)-1; /* STFU, gcc */
270         char id_buf[sizeof(id)];
271         unsigned num_rows;
272         int ret;
273
274         ret = osl(osl_get_num_rows(table, &num_rows));
275         if (ret < 0)
276                 goto out;
277         if (!num_rows) { /* this is the first entry ever added */
278                 /*
279                  * Insert dummy row containing the next free ID. Since we are
280                  * about to insert the first blob with ID 1, the next free ID
281                  * will be 2.
282                  */
283                 id = 2U;
284                 write_u32(id_buf, id);
285                 objs[BLOBCOL_ID].data = id_buf;
286                 objs[BLOBCOL_ID].size = sizeof(id_buf);
287                 objs[BLOBCOL_NAME].data = "";
288                 objs[BLOBCOL_NAME].size = 1;
289                 objs[BLOBCOL_DEF].data = "";
290                 objs[BLOBCOL_DEF].size = 1;
291                 ret = osl(osl_add_row(table, objs));
292                 if (ret < 0)
293                         goto out;
294         } else {
295                 /* check if name already exists */
296                 struct osl_row *row;
297                 struct osl_object obj = {.data = name, .size = name_len};
298                 ret = osl(osl_get_row(table, BLOBCOL_NAME, &obj, &row));
299                 if (ret < 0 && ret != -OSL_ERRNO_TO_PARA_ERROR(E_OSL_RB_KEY_NOT_FOUND))
300                         goto out;
301                 if (ret >= 0) { /* we already have a blob with this name */
302                         ret = osl(osl_get_object(table, row, BLOBCOL_ID, &obj));
303                         if (ret < 0)
304                                 goto out;
305                         id = read_u32(obj.data);
306                         obj.data = name + name_len;
307                         obj.size = aca->query.size - name_len;
308                         ret = osl(osl_update_object(table, row, BLOBCOL_DEF, &obj));
309                         goto out;
310                 }
311                 /* new blob, get id of the dummy row and increment it */
312                 obj.data = "";
313                 obj.size = 1;
314                 ret = osl(osl_get_row(table, BLOBCOL_NAME, &obj, &row));
315                 if (ret < 0)
316                         goto out;
317                 ret = osl(osl_get_object(table, row, BLOBCOL_ID, &obj));
318                 if (ret < 0)
319                         goto out;
320                 id = read_u32(obj.data) + 1;
321                 write_u32(id_buf, id);
322                 obj.data = &id_buf;
323                 ret = osl(osl_update_object(table, row, BLOBCOL_ID, &obj));
324                 if (ret < 0)
325                         goto out;
326         }
327         id--;
328         write_u32(id_buf, id);
329         objs[BLOBCOL_ID].data = &id_buf;
330         objs[BLOBCOL_ID].size = sizeof(id_buf);
331         objs[BLOBCOL_NAME].data = name;
332         objs[BLOBCOL_NAME].size = name_len;
333         objs[BLOBCOL_DEF].data = name + name_len;
334         objs[BLOBCOL_DEF].size = aca->query.size - name_len;
335         ret = osl(osl_add_row(table, objs));
336         if (ret < 0)
337                 goto out;
338         ret = afs_event(BLOB_ADD, NULL, table);
339 out:
340         if (ret < 0)
341                 para_printf(&aca->pbout, "cannot add %s\n", name);
342         else
343                 para_printf(&aca->pbout, "added %s as id %u\n", name, id);
344         return ret;
345 }
346
347 /* Write input from fd to dynamically allocated buffer, but maximal 10M. */
348 static int fd2buf(struct stream_cipher_context *scc, struct osl_object *obj)
349 {
350         size_t max_size = 10 * 1024 * 1024;
351         int ret;
352         struct iovec iov;
353
354         obj->data = NULL;
355         obj->size = 0;
356 again:
357         do {
358                 ret = recv_sb(scc, SBD_BLOB_DATA, max_size, &iov);
359         } while (ret == 0);
360
361         if (ret < 0) {
362                 free(obj->data);
363                 obj->data = NULL;
364                 obj->size = 0;
365                 return ret;
366         }
367         if (iov.iov_len == 0) /* end of blob */
368                 return 1;
369         if (!obj->data) {
370                 obj->data = iov.iov_base;
371                 obj->size = iov.iov_len;
372         } else {
373                 obj->data = para_realloc(obj->data, obj->size + iov.iov_len);
374                 memcpy(obj->data + obj->size, iov.iov_base, iov.iov_len);
375                 obj->size += iov.iov_len;
376                 free(iov.iov_base);
377                 max_size -= iov.iov_len;
378         }
379         goto again;
380         return 1;
381 }
382
383 /*
384  * Read blob from a file descriptor and send it to afs.
385  *
386  * This function is called from the addblob command handlers to instruct the
387  * afs process to store the input in a blob table. Input is read and decrypted
388  * from the file descriptor given by cc and appended to a buffer which also contains
389  * the name of the blob to create. The combined buffer is made available to the
390  * afs process via the callback method.
391  */
392 static int stdin_command(struct command_context *cc,
393                 struct lls_parse_result *lpr, afs_callback *f)
394 {
395         struct osl_object query, stdin_obj;
396         int ret;
397         size_t len = strlen(lls_input(0, lpr));
398
399         ret = send_sb(&cc->scc, NULL, 0, SBD_AWAITING_DATA, false);
400         if (ret < 0)
401                 return ret;
402         ret = fd2buf(&cc->scc, &stdin_obj);
403         if (ret < 0)
404                 return ret;
405         query.size = len + 1 + stdin_obj.size;
406         query.data = para_malloc(query.size);
407         memcpy(query.data, lls_input(0, lpr), len + 1);
408         if (stdin_obj.size > 0)
409                 memcpy((char *)query.data + len + 1, stdin_obj.data,
410                         stdin_obj.size);
411         free(stdin_obj.data);
412         ret = send_callback_request(f, &query, afs_cb_result_handler, cc);
413         free(query.data);
414         return ret;
415 }
416
417 static int com_addblob(afs_callback *f, __a_unused const struct lls_command * const cmd,
418                 struct command_context *cc, struct lls_parse_result *lpr)
419 {
420         char *errctx;
421         int ret = lls(lls_check_arg_count(lpr, 1, 1, &errctx));
422
423         if (ret < 0) {
424                 send_errctx(cc, errctx);
425                 return ret;
426         }
427         if (!lls_input(0, lpr)[0]) /* empty name is reserved for the dummy row */
428                 return -E_BLOB_SYNTAX;
429         return stdin_command(cc, lpr, f);
430 }
431
432 static int com_mvblob_callback(const struct lls_command * const cmd,
433                 struct osl_table *table, struct afs_callback_arg *aca)
434 {
435         const char *src, *dest;
436         struct osl_object obj;
437         struct osl_row *row;
438         int ret;
439
440         ret = lls_deserialize_parse_result(aca->query.data, cmd, &aca->lpr);
441         assert(ret >= 0);
442         src = lls_input(0, aca->lpr);
443         dest = lls_input(1, aca->lpr);
444         obj.data = (char *)src;
445         obj.size = strlen(src) + 1;
446         ret = osl(osl_get_row(table, BLOBCOL_NAME, &obj, &row));
447
448         if (ret < 0) {
449                 para_printf(&aca->pbout, "cannot find source blob %s\n", src);
450                 goto out;
451         }
452         obj.data = (char *)dest;
453         obj.size = strlen(dest) + 1;
454         ret = osl(osl_update_object(table, row, BLOBCOL_NAME, &obj));
455         if (ret < 0) {
456                 para_printf(&aca->pbout, "cannot rename blob %s to %s\n",
457                         src, dest);
458                 goto out;
459         }
460         ret = afs_event(BLOB_RENAME, NULL, table);
461 out:
462         lls_free_parse_result(aca->lpr, cmd);
463         return ret;
464 }
465
466 static int com_mvblob(afs_callback *f, const struct lls_command * const cmd,
467                 struct command_context *cc, struct lls_parse_result *lpr)
468 {
469         char *errctx;
470         int ret = lls(lls_check_arg_count(lpr, 2, 2, &errctx));
471
472         if (ret < 0) {
473                 send_errctx(cc, errctx);
474                 return ret;
475         }
476         return send_lls_callback_request(f, cmd, lpr, cc);
477 }
478
479 #define DEFINE_BLOB_COMMAND(cmd_name, c_cmd_name, table_name, short_name, c_short_name) \
480         static int com_ ## cmd_name ## short_name ## _callback(struct afs_callback_arg *aca) \
481         { \
482                 const struct lls_command *cmd = SERVER_CMD_CMD_PTR(c_cmd_name ## c_short_name); \
483                 return com_ ## cmd_name ## blob_callback(cmd, table_name ## _table, aca); \
484         } \
485         static int com_ ## cmd_name ## short_name(struct command_context *cc, struct lls_parse_result *lpr) \
486         { \
487                 const struct lls_command *cmd = SERVER_CMD_CMD_PTR(c_cmd_name ## c_short_name); \
488                 return com_ ## cmd_name ## blob(com_ ## cmd_name ## short_name ## _callback, cmd, cc, lpr); \
489         } \
490         EXPORT_SERVER_CMD_HANDLER(cmd_name ## short_name);
491
492 static int blob_get_name_by_id(struct osl_table *table, uint32_t id,
493                 char **name)
494 {
495         struct osl_row *row;
496         struct osl_object obj = {.data = &id, .size = sizeof(id)};
497         int ret;
498
499         if (name)
500                 *name = NULL;
501         if (!id)
502                 return 1;
503         ret = osl(osl_get_row(table, BLOBCOL_ID, &obj, &row));
504         if (ret < 0)
505                 return ret;
506         ret = osl(osl_get_object(table, row, BLOBCOL_NAME, &obj));
507         if (ret < 0)
508                 return ret;
509         if (*(char *)obj.data == '\0')
510                 return -E_DUMMY_ROW;
511         if (name)
512                 *name = (char *)obj.data;
513         return 1;
514 }
515
516 /** Define the \p get_name_by_id function for this blob type. */
517 #define DEFINE_GET_NAME_BY_ID(table_name, cmd_prefix) \
518         int cmd_prefix ## _get_name_by_id(uint32_t id, char **name) \
519         { \
520                 return blob_get_name_by_id(table_name ## _table, id, name); \
521         }
522
523 static int blob_get_def_by_name(struct osl_table *table, char *name,
524                 struct osl_object *def)
525 {
526         struct osl_row *row;
527         struct osl_object obj = {.data = name, .size = strlen(name) + 1};
528         int ret;
529
530         def->data = NULL;
531         if (!*name)
532                 return 1;
533         ret = osl(osl_get_row(table, BLOBCOL_NAME, &obj, &row));
534         if (ret < 0)
535                 return ret;
536         return osl(osl_open_disk_object(table, row, BLOBCOL_DEF, def));
537 }
538
539 /** Define the \p get_def_by_id function for this blob type. */
540 #define DEFINE_GET_DEF_BY_NAME(table_name, cmd_prefix) \
541         int cmd_prefix ## _get_def_by_name(char *name, struct osl_object *def) \
542         { \
543                 return blob_get_def_by_name(table_name ## _table, name, def); \
544         }
545
546 static int blob_get_def_by_id(struct osl_table *table, uint32_t id,
547                 struct osl_object *def)
548 {
549         struct osl_row *row;
550         struct osl_object obj = {.data = &id, .size = sizeof(id)};
551         int ret;
552
553         def->data = NULL;
554         if (!id)
555                 return 1;
556         ret = osl(osl_get_row(table, BLOBCOL_ID, &obj, &row));
557         if (ret < 0)
558                 return ret;
559         return osl(osl_open_disk_object(table, row, BLOBCOL_DEF, def));
560 }
561
562 /** Define the \p get_def_by_id function for this blob type. */
563 #define DEFINE_GET_DEF_BY_ID(table_name, cmd_prefix) \
564         int cmd_prefix ## _get_def_by_id(uint32_t id, struct osl_object *def) \
565         { \
566                 return blob_get_def_by_id(table_name ## _table, id, def); \
567         }
568
569 static int blob_get_name_and_def_by_row(struct osl_table *table,
570                 const struct osl_row *row, char **name, struct osl_object *def)
571 {
572         struct osl_object obj;
573         int ret = osl(osl_get_object(table, row, BLOBCOL_NAME, &obj));
574
575         if (ret < 0)
576                 return ret;
577         *name = obj.data;
578         return osl(osl_open_disk_object(table, row, BLOBCOL_DEF, def));
579 }
580 /** Define the \p get_name_and_def_by_row function for this blob type. */
581 #define DEFINE_GET_NAME_AND_DEF_BY_ROW(table_name, cmd_prefix) \
582         int cmd_prefix ## _get_name_and_def_by_row(const struct osl_row *row, \
583                 char **name, struct osl_object *def) \
584         { \
585                 return blob_get_name_and_def_by_row(table_name ## _table, \
586                         row, name, def); \
587         }
588
589 /** Define the \p close function for this blob type. */
590 #define DEFINE_BLOB_CLOSE(table_name) \
591         static void table_name ## _close(void) \
592         { \
593                 osl_close_table(table_name ## _table, OSL_MARK_CLEAN); \
594                 table_name ## _table = NULL; \
595         }
596
597 /** Define the \p create function for this blob type. */
598 #define DEFINE_BLOB_CREATE(table_name) \
599         static int table_name ## _create(const char *dir) \
600         { \
601                 table_name ## _table_desc.dir = dir; \
602                 return osl(osl_create_table(&table_name ## _table_desc)); \
603         }
604
605 static int blob_open(struct osl_table **table,
606                 struct osl_table_description *desc,
607                 const char *dir)
608 {
609         int ret;
610
611         desc->dir = dir;
612         ret = osl(osl_open_table(desc, table));
613         if (ret >= 0)
614                 return ret;
615         *table = NULL;
616         if (ret >= 0 || ret == -OSL_ERRNO_TO_PARA_ERROR(E_OSL_NOENT))
617                 return 1;
618         return ret;
619 }
620
621 #define DEFINE_BLOB_OPEN(table_name) \
622         static int table_name ## _open(const char *dir) \
623         { \
624                 return blob_open(&table_name ## _table, \
625                         &table_name ## _table_desc, dir); \
626         }
627
628
629 /** Define the \p init function for this blob type. */
630 #define DEFINE_BLOB_INIT(table_name) \
631         void table_name ## _init(struct afs_table *t) \
632         { \
633                 t->open = table_name ## _open; \
634                 t->close = table_name ## _close; \
635                 t->create = table_name ## _create;\
636                 t->event_handler = table_name ##_event_handler; \
637                 table_name ## _table = NULL; \
638         }
639
640
641 /** Define all functions for this blob type. */
642 #define DEFINE_BLOB_FUNCTIONS(table_name, short_name, c_short_name) \
643         DEFINE_BLOB_OPEN(table_name) \
644         DEFINE_BLOB_CLOSE(table_name) \
645         DEFINE_BLOB_CREATE(table_name) \
646         DEFINE_BLOB_INIT(table_name) \
647         DEFINE_BLOB_COMMAND(ls, LS, table_name, short_name, c_short_name) \
648         DEFINE_BLOB_COMMAND(cat, CAT, table_name, short_name, c_short_name) \
649         DEFINE_BLOB_COMMAND(add, ADD, table_name, short_name, c_short_name) \
650         DEFINE_BLOB_COMMAND(rm, RM, table_name, short_name, c_short_name) \
651         DEFINE_BLOB_COMMAND(mv, MV, table_name, short_name, c_short_name) \
652         DEFINE_GET_NAME_BY_ID(table_name, short_name); \
653         DEFINE_GET_DEF_BY_ID(table_name, short_name); \
654         DEFINE_GET_DEF_BY_NAME(table_name, short_name); \
655         DEFINE_GET_NAME_AND_DEF_BY_ROW(table_name, short_name); \
656
657 /* doxygen isn't smart enough to recognize these */
658 /** \cond blob_function */
659 DEFINE_BLOB_FUNCTIONS(lyrics, lyr, LYR);
660 DEFINE_BLOB_FUNCTIONS(images, img, IMG);
661 DEFINE_BLOB_FUNCTIONS(moods, mood, MOOD);
662 DEFINE_BLOB_FUNCTIONS(playlists, pl, PL);
663 /** \endcond blob_function */