Fix some gcc warnings.
[paraslash.git] / blob.c
1 /*
2  * Copyright (C) 2007-2009 Andre Noll <maan@systemlinux.org>
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 <fnmatch.h>
10 #include <openssl/rc4.h>
11 #include <osl.h>
12
13 #include "para.h"
14 #include "error.h"
15 #include "crypt.h"
16 #include "string.h"
17 #include "afh.h"
18 #include "afs.h"
19 #include "net.h"
20 #include "ipc.h"
21 #include "portable_io.h"
22
23 /**
24  * Compare two osl objects pointing to unsigned integers of 32 bit size.
25  *
26  * \param obj1 Pointer to the first integer.
27  * \param obj2 Pointer to the second integer.
28  *
29  * \return The values required for an osl compare function.
30  *
31  * \sa osl_compare_func, osl_hash_compare().
32  */
33 static int uint32_compare(const struct osl_object *obj1, const struct osl_object *obj2)
34 {
35         uint32_t d1 = read_u32((const char *)obj1->data);
36         uint32_t d2 = read_u32((const char *)obj2->data);
37
38         if (d1 < d2)
39                 return 1;
40         if (d1 > d2)
41                 return -1;
42         return 0;
43 }
44
45 static struct osl_column_description blob_cols[] = {
46         [BLOBCOL_ID] = {
47                 .storage_type = OSL_MAPPED_STORAGE,
48                 .storage_flags = OSL_RBTREE | OSL_UNIQUE | OSL_FIXED_SIZE,
49                 .name = "id",
50                 .data_size = 4,
51                 .compare_function = uint32_compare
52         },
53         [BLOBCOL_NAME] = {
54                 .storage_type = OSL_MAPPED_STORAGE,
55                 .storage_flags = OSL_RBTREE | OSL_UNIQUE,
56                 .name = "name",
57                 .compare_function = string_compare
58         },
59         [BLOBCOL_DEF] = {
60                 .storage_type = OSL_DISK_STORAGE,
61                 .storage_flags = 0,
62                 .name = "definition"
63         }
64 };
65
66 /** \cond doxygen isn't smart enough to recognize these */
67 INIT_BLOB_TABLE(lyrics);
68 INIT_BLOB_TABLE(images);
69 INIT_BLOB_TABLE(moods);
70 INIT_BLOB_TABLE(playlists);
71 /** \endcond */
72
73 /** Flags that may be passed to the \p ls functions of each blob  type. */
74 enum blob_ls_flags {
75         /** List both id and name. */
76         BLOB_LS_FLAG_LONG = 1,
77         /** Reverse sort order. */
78         BLOB_LS_FLAG_REVERSE = 2,
79         /** Sort by id instead of name. */
80         BLOB_LS_FLAG_SORT_BY_ID = 4,
81 };
82
83 /** Structure passed to the \p print_blob function. */
84 struct lsblob_action_data {
85         /** The flags given at the command line. */
86         uint32_t flags;
87         /** Message buffer. */
88         struct para_buffer pb;
89 };
90
91 static int print_blob(struct osl_table *table, struct osl_row *row,
92                 const char *name, void *data)
93 {
94         struct lsblob_action_data *lbad = data;
95         struct osl_object obj;
96         uint32_t id;
97         int ret;
98
99         if (!(lbad->flags & BLOB_LS_FLAG_LONG))
100                 return para_printf(&lbad->pb, "%s\n", name);
101         ret = osl(osl_get_object(table, row, BLOBCOL_ID, &obj));
102         if (ret < 0) {
103                 para_printf(&lbad->pb, "%s: %s\n", name, para_strerror(-ret));
104                 return ret;
105         }
106         id = *(uint32_t *)obj.data;
107         return para_printf(&lbad->pb, "%u\t%s\n", id, name);
108 }
109
110 static void com_lsblob_callback(struct osl_table *table,
111                 int fd, const struct osl_object *query)
112 {
113         struct lsblob_action_data lbad = {
114                 .flags = *(uint32_t *)query->data,
115                 .pb = {
116                         .max_size = SHMMAX,
117                         .private_data = &fd,
118                         .max_size_handler = pass_buffer_as_shm
119                 }
120         };
121         struct pattern_match_data pmd = {
122                 .table = table,
123                 .patterns = {.data = (char *)query->data + sizeof(uint32_t),
124                         .size = query->size - sizeof(uint32_t)},
125                 .pm_flags = PM_NO_PATTERN_MATCHES_EVERYTHING | PM_SKIP_EMPTY_NAME,
126                 .match_col_num = BLOBCOL_NAME,
127                 .data = &lbad,
128                 .action = print_blob,
129         };
130         int ret;
131
132         if (lbad.flags & BLOB_LS_FLAG_REVERSE)
133                 pmd.pm_flags |= PM_REVERSE_LOOP;
134         if (!(lbad.flags & BLOB_LS_FLAG_SORT_BY_ID))
135                 pmd.loop_col_num = BLOBCOL_NAME;
136         else
137                 pmd.loop_col_num = BLOBCOL_ID;
138         ret = for_each_matching_row(&pmd);
139         if (ret < 0)
140                 para_printf(&lbad.pb, "%s\n", para_strerror(-ret));
141         if (lbad.pb.offset)
142                 pass_buffer_as_shm(lbad.pb.buf, lbad.pb.offset, &fd);
143         free(lbad.pb.buf);
144 }
145
146 static int com_lsblob(callback_function *f, struct rc4_context *rc4c, int argc, char * const * const argv)
147 {
148         uint32_t flags = 0;
149         struct osl_object options = {.data = &flags, .size = sizeof(flags)};
150         int i;
151
152         for (i = 1; i < argc; i++) {
153                 const char *arg = argv[i];
154                 if (arg[0] != '-')
155                         break;
156                 if (!strcmp(arg, "--")) {
157                         i++;
158                         break;
159                 }
160                 if (!strcmp(arg, "-l")) {
161                         flags |= BLOB_LS_FLAG_LONG;
162                         continue;
163                 }
164                 if (!strcmp(arg, "-i")) {
165                         flags |= BLOB_LS_FLAG_SORT_BY_ID;
166                         continue;
167                 }
168                 if (!strcmp(arg, "-r")) {
169                         flags |= BLOB_LS_FLAG_REVERSE;
170                         continue;
171                 }
172                 break;
173         }
174 //      if (argc > i)
175 //              return -E_BLOB_SYNTAX;
176         return send_option_arg_callback_request(&options, argc - i,
177                 argv + i, f, rc4_send_result, rc4c);
178 }
179
180 static int cat_blob(struct osl_table *table, struct osl_row *row,
181                 __a_unused const char *name, void *data)
182 {
183         int ret = 0, ret2;
184         struct osl_object obj;
185
186         ret = osl(osl_open_disk_object(table, row, BLOBCOL_DEF, &obj));
187         if (ret < 0)
188                 return ret;
189         if (obj.size)
190                 ret = pass_buffer_as_shm(obj.data, obj.size, data);
191         ret2 = osl(osl_close_disk_object(&obj));
192         return (ret < 0)? ret : ret2;
193 }
194
195 static void com_catblob_callback(struct osl_table *table, int fd,
196                 const struct osl_object *query)
197 {
198         struct pattern_match_data pmd = {
199                 .table = table,
200                 .patterns = *query,
201                 .loop_col_num = BLOBCOL_NAME,
202                 .match_col_num = BLOBCOL_NAME,
203                 .pm_flags = PM_SKIP_EMPTY_NAME,
204                 .data = &fd,
205                 .action = cat_blob
206         };
207         for_each_matching_row(&pmd);
208 }
209
210 static int com_catblob(callback_function *f, struct rc4_context *rc4c, int argc,
211                 char * const * const argv)
212 {
213         if (argc < 2)
214                 return -E_BLOB_SYNTAX;
215         return send_standard_callback_request(argc - 1, argv + 1, f,
216                 rc4_send_result, rc4c);
217 }
218
219 /** Used for removing rows from a blob table. */
220 struct rmblob_data {
221         /** Message buffer. */
222         struct para_buffer pb;
223         /** Number of removed blobs. */
224         unsigned num_removed;
225 };
226
227 static int remove_blob(struct osl_table *table, struct osl_row *row,
228                 const char *name, void *data)
229 {
230         struct rmblob_data *rmbd = data;
231         int ret = osl(osl_del_row(table, row));
232         if (ret < 0) {
233                 para_printf(&rmbd->pb, "%s: %s\n", name, para_strerror(-ret));
234                 return ret;
235         }
236         rmbd->num_removed++;
237         return 1;
238 }
239
240 static void com_rmblob_callback(struct osl_table *table, int fd,
241                 const struct osl_object *query)
242 {
243         int ret, ret2 = 0;
244         struct rmblob_data rmbd = {
245                 .num_removed = 0,
246                 .pb = {
247                         .max_size = SHMMAX,
248                         .private_data = &fd,
249                         .max_size_handler = pass_buffer_as_shm
250                 }
251         };
252         struct pattern_match_data pmd = {
253                 .table = table,
254                 .patterns = *query,
255                 .loop_col_num = BLOBCOL_NAME,
256                 .match_col_num = BLOBCOL_NAME,
257                 .pm_flags = PM_SKIP_EMPTY_NAME,
258                 .data = &rmbd,
259                 .action = remove_blob
260         };
261         ret = for_each_matching_row(&pmd);
262         if (ret < 0) {
263                 ret2 = para_printf(&rmbd.pb, "%s\n", para_strerror(-ret));
264                 if (ret2 < 0)
265                         goto out;
266         }
267         if (!rmbd.num_removed)
268                 ret2 = para_printf(&rmbd.pb, "no matches, nothing removed\n");
269         else {
270                 ret2 = para_printf(&rmbd.pb, "removed %d blobs\n", rmbd.num_removed);
271                 afs_event(BLOB_RENAME, NULL, table);
272         }
273 out:
274         if (ret2 >= 0 && rmbd.pb.offset)
275                 pass_buffer_as_shm(rmbd.pb.buf, rmbd.pb.offset, &fd);
276         free(rmbd.pb.buf);
277 }
278
279 static int com_rmblob(callback_function *f, struct rc4_context *rc4c, int argc,
280                 char * const * const argv)
281 {
282         if (argc < 2)
283                 return -E_MOOD_SYNTAX;
284         return send_option_arg_callback_request(NULL, argc - 1, argv + 1, f,
285                 rc4_send_result, rc4c);
286 }
287
288 static void com_addblob_callback(struct osl_table *table, __a_unused int fd,
289                 const struct osl_object *query)
290 {
291         struct osl_object objs[NUM_BLOB_COLUMNS];
292         char *name = query->data;
293         size_t name_len = strlen(name) + 1;
294         uint32_t id;
295         unsigned num_rows;
296         int ret;
297
298         ret = osl(osl_get_num_rows(table, &num_rows));
299         if (ret < 0)
300                 goto out;
301         if (!num_rows) { /* this is the first entry ever added */
302                 /* insert dummy row containing the id */
303                 id = 2; /* this entry will be entry #1, so 2 is the next */
304                 objs[BLOBCOL_ID].data = &id;
305                 objs[BLOBCOL_ID].size = sizeof(id);
306                 objs[BLOBCOL_NAME].data = "";
307                 objs[BLOBCOL_NAME].size = 1;
308                 objs[BLOBCOL_DEF].data = "";
309                 objs[BLOBCOL_DEF].size = 1;
310                 ret = osl(osl_add_row(table, objs));
311                 if (ret < 0)
312                         goto out;
313         } else {
314                 /* check if name already exists */
315                 struct osl_row *row;
316                 struct osl_object obj = {.data = name, .size = name_len};
317                 ret = osl(osl_get_row(table, BLOBCOL_NAME, &obj, &row));
318                 if (ret < 0 && ret != -OSL_ERRNO_TO_PARA_ERROR(E_OSL_RB_KEY_NOT_FOUND))
319                         goto out;
320                 if (ret >= 0) { /* we already have a blob with this name */
321                         obj.data = name + name_len;
322                         obj.size = query->size - name_len;
323                         ret = osl(osl_update_object(table, row, BLOBCOL_DEF, &obj));
324                         goto out;
325                 }
326                 /* new blob, get id of the dummy row and increment it */
327                 obj.data = "";
328                 obj.size = 1;
329                 ret = osl(osl_get_row(table, BLOBCOL_NAME, &obj, &row));
330                 if (ret < 0)
331                         goto out;
332                 ret = osl(osl_get_object(table, row, BLOBCOL_ID, &obj));
333                 if (ret < 0)
334                         goto out;
335                 id = *(uint32_t *)obj.data + 1;
336                 obj.data = &id;
337                 ret = osl(osl_update_object(table, row, BLOBCOL_ID, &obj));
338                 if (ret < 0)
339                         goto out;
340         }
341         id--;
342         objs[BLOBCOL_ID].data = &id;
343         objs[BLOBCOL_ID].size = sizeof(id);
344         objs[BLOBCOL_NAME].data = name;
345         objs[BLOBCOL_NAME].size = name_len;
346         objs[BLOBCOL_DEF].data = name + name_len;
347         objs[BLOBCOL_DEF].size = query->size - name_len;
348         ret = osl(osl_add_row(table, objs));
349         if (ret < 0)
350                 goto out;
351         afs_event(BLOB_ADD, NULL, table);
352 out:
353         if (ret < 0)
354                 PARA_NOTICE_LOG("%s\n", para_strerror(-ret));
355 }
356
357 /*
358  * write input from fd to dynamically allocated buffer,
359  * but maximal max_size byte.
360  */
361 static int fd2buf(struct rc4_context *rc4c, unsigned max_size, struct osl_object *obj)
362 {
363         const size_t chunk_size = 1024;
364         size_t size = 2048, received = 0;
365         int ret;
366         char *buf = para_malloc(size);
367
368         for (;;) {
369                 ret = rc4_recv_bin_buffer(rc4c, buf + received, chunk_size);
370                 if (ret <= 0)
371                         break;
372                 received += ret;
373                 if (received + chunk_size >= size) {
374                         size *= 2;
375                         ret = -E_INPUT_TOO_LARGE;
376                         if (size > max_size)
377                                 break;
378                         buf = para_realloc(buf, size);
379                 }
380         }
381         obj->data = buf;
382         obj->size = received;
383         if (ret < 0)
384                 free(buf);
385         return ret;
386 }
387
388 /*
389  * Read data from a file descriptor, and send it to the afs process.
390  *
391  * \param rc4c crypt context containing the file descriptor to read data from.
392  * \param arg_obj Pointer to the arguments to \a f.
393  * \param f The callback function.
394  * \param max_len Don't read more than that many bytes from stdin.
395  * \param result_handler See \ref send_callback_request.
396  * \param private_result_data See \ref send_callback_request.
397  *
398  * This function is used by commands that wish to let para_server store
399  * arbitrary data specified by the user (for instance the add_blob family of
400  * commands). First, at most \a max_len bytes are read and decrypted from the
401  * file descriptor given by \a rc4c. The result is concatenated with the buffer
402  * given by \a arg_obj, and the combined buffer is made available to the afs
403  * process via the callback method. See \ref send_callback_request for details.
404  *
405  * \return Negative on errors, the return value of the underlying call to
406  * send_callback_request() otherwise.
407  */
408 static int stdin_command(struct rc4_context *rc4c, struct osl_object *arg_obj,
409                 callback_function *f, unsigned max_len,
410                 callback_result_handler *result_handler,
411                 void *private_result_data)
412 {
413         struct osl_object query, stdin_obj;
414         int ret;
415
416         ret = rc4_send_buffer(rc4c, AWAITING_DATA_MSG);
417         if (ret < 0)
418                 return ret;
419         ret = fd2buf(rc4c, max_len, &stdin_obj);
420         if (ret < 0)
421                 return ret;
422         query.size = arg_obj->size + stdin_obj.size;
423         query.data = para_malloc(query.size);
424         memcpy(query.data, arg_obj->data, arg_obj->size);
425         memcpy((char *)query.data + arg_obj->size, stdin_obj.data, stdin_obj.size);
426         free(stdin_obj.data);
427         ret = send_callback_request(f, &query, result_handler, private_result_data);
428         free(query.data);
429         return ret;
430 }
431
432 static int com_addblob(callback_function *f, struct rc4_context *rc4c, int argc,
433                 char * const * const argv)
434 {
435         struct osl_object arg_obj;
436
437         if (argc != 2)
438                 return -E_BLOB_SYNTAX;
439         if (!*argv[1]) /* empty name is reserved for the dummy row */
440                 return -E_BLOB_SYNTAX;
441         arg_obj.size = strlen(argv[1]) + 1;
442         arg_obj.data = (char *)argv[1];
443         return stdin_command(rc4c, &arg_obj, f, 10 * 1024 * 1024, NULL, NULL);
444 }
445
446 /* FIXME: Print output to client, not to log file */
447 static void com_mvblob_callback(struct osl_table *table, __a_unused int fd,
448                 const struct osl_object *query)
449 {
450         char *src = (char *) query->data;
451         struct osl_object obj = {.data = src, .size = strlen(src) + 1};
452         char *dest = src + obj.size;
453         struct osl_row *row;
454         int ret = osl(osl_get_row(table, BLOBCOL_NAME, &obj, &row));
455
456         if (ret < 0)
457                 goto out;
458         obj.data = dest;
459         obj.size = strlen(dest) + 1;
460         ret = osl(osl_update_object(table, row, BLOBCOL_NAME, &obj));
461         if (ret < 0)
462                 goto out;
463         afs_event(BLOB_RENAME, NULL, table);
464 out:
465         if (ret < 0)
466                 PARA_NOTICE_LOG("%s\n", para_strerror(-ret));
467 }
468
469 static int com_mvblob(callback_function *f, __a_unused struct rc4_context *rc4c,
470                 int argc, char * const * const argv)
471 {
472         if (argc != 3)
473                 return -E_MOOD_SYNTAX;
474         return send_option_arg_callback_request(NULL, argc - 1, argv + 1, f,
475                 NULL, NULL);
476 }
477
478 #define DEFINE_BLOB_COMMAND(cmd_name, table_name, cmd_prefix) \
479         static void com_ ## cmd_name ## cmd_prefix ## _callback(int fd, const struct osl_object *query) \
480         { \
481                 return com_ ## cmd_name ## blob_callback(table_name ## _table, fd, query); \
482         } \
483         int com_ ## cmd_name ## cmd_prefix(struct rc4_context *rc4c, int argc, char * const * const argv) \
484         { \
485                 return com_ ## cmd_name ## blob(com_ ## cmd_name ## cmd_prefix ## _callback, rc4c, argc, argv); \
486         }
487
488 static int blob_get_name_by_id(struct osl_table *table, uint32_t id,
489                 char **name)
490 {
491         struct osl_row *row;
492         struct osl_object obj = {.data = &id, .size = sizeof(id)};
493         int ret;
494
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         *name = (char *)obj.data;
505         return 1;
506 }
507
508 /** Define the \p get_name_by_id function for this blob type. */
509 #define DEFINE_GET_NAME_BY_ID(table_name, cmd_prefix) \
510         int cmd_prefix ## _get_name_by_id(uint32_t id, char **name) \
511         { \
512                 return blob_get_name_by_id(table_name ## _table, id, name); \
513         }
514
515
516 static int blob_get_def_by_name(struct osl_table *table, char *name,
517                 struct osl_object *def)
518 {
519         struct osl_row *row;
520         struct osl_object obj = {.data = name, .size = strlen(name) + 1};
521         int ret;
522
523         def->data = NULL;
524         if (!*name)
525                 return 1;
526         ret = osl(osl_get_row(table, BLOBCOL_NAME, &obj, &row));
527         if (ret < 0)
528                 return ret;
529         return osl(osl_open_disk_object(table, row, BLOBCOL_DEF, def));
530 }
531
532 /** Define the \p get_def_by_id function for this blob type. */
533 #define DEFINE_GET_DEF_BY_NAME(table_name, cmd_prefix) \
534         int cmd_prefix ## _get_def_by_name(char *name, struct osl_object *def) \
535         { \
536                 return blob_get_def_by_name(table_name ## _table, name, def); \
537         }
538
539 static int blob_get_def_by_id(struct osl_table *table, uint32_t id,
540                 struct osl_object *def)
541 {
542         struct osl_row *row;
543         struct osl_object obj = {.data = &id, .size = sizeof(id)};
544         int ret;
545
546         def->data = NULL;
547         if (!id)
548                 return 1;
549         ret = osl(osl_get_row(table, BLOBCOL_ID, &obj, &row));
550         if (ret < 0)
551                 return ret;
552         return osl(osl_open_disk_object(table, row, BLOBCOL_DEF, def));
553 }
554
555 /** Define the \p get_def_by_id function for this blob type. */
556 #define DEFINE_GET_DEF_BY_ID(table_name, cmd_prefix) \
557         int cmd_prefix ## _get_def_by_id(uint32_t id, struct osl_object *def) \
558         { \
559                 return blob_get_def_by_id(table_name ## _table, id, def); \
560         }
561
562 static int blob_get_name_and_def_by_row(struct osl_table *table,
563                 const struct osl_row *row, char **name, struct osl_object *def)
564 {
565         struct osl_object obj;
566         int ret = osl(osl_get_object(table, row, BLOBCOL_NAME, &obj));
567         if (ret < 0)
568                 return ret;
569         *name = obj.data;
570         return osl(osl_open_disk_object(table, row, BLOBCOL_DEF, def));
571 }
572 /** Define the \p get_name_and_def_by_row function for this blob type. */
573 #define DEFINE_GET_NAME_AND_DEF_BY_ROW(table_name, cmd_prefix) \
574         int cmd_prefix ## _get_name_and_def_by_row(const struct osl_row *row, \
575                 char **name, struct osl_object *def) \
576         { \
577                 return blob_get_name_and_def_by_row(table_name ## _table, \
578                         row, name, def); \
579         }
580
581 /** Define the \p close function for this blob type. */
582 #define DEFINE_BLOB_CLOSE(table_name) \
583         void table_name ## _close(void) \
584         { \
585                 osl_close_table(table_name ## _table, OSL_MARK_CLEAN); \
586                 table_name ## _table = NULL; \
587         }
588
589 /** Define the \p create function for this blob type. */
590 #define DEFINE_BLOB_CREATE(table_name) \
591         int table_name ## _create(const char *dir) \
592         { \
593                 table_name ## _table_desc.dir = dir; \
594                 return osl_create_table(&table_name ## _table_desc); \
595         }
596
597 static int blob_open(struct osl_table **table,
598                 struct osl_table_description *desc,
599                 const char *dir)
600 {
601         int ret;
602         desc->dir = dir;
603         ret = osl(osl_open_table(desc, table));
604         if (ret >= 0)
605                 return ret;
606         *table = NULL;
607         if (ret >= 0 || ret == -OSL_ERRNO_TO_PARA_ERROR(E_OSL_NOENT))
608                 return 1;
609         return ret;
610 }
611
612 #define DEFINE_BLOB_OPEN(table_name) \
613         int table_name ## _open(const char *dir) \
614         { \
615                 return blob_open(&table_name ## _table, \
616                         &table_name ## _table_desc, dir); \
617         }
618
619
620 /** Define the \p init function for this blob type. */
621 #define DEFINE_BLOB_INIT(table_name) \
622         void table_name ## _init(struct afs_table *t) \
623         { \
624                 t->name = table_name ## _table_desc.name; \
625                 t->open = table_name ## _open; \
626                 t->close = table_name ## _close; \
627                 t->create = table_name ## _create;\
628                 t->event_handler = table_name ##_event_handler; \
629                 table_name ## _table = NULL; \
630         }
631
632
633 /** Define all functions for this blob type. */
634 #define DEFINE_BLOB_FUNCTIONS(table_name, cmd_prefix) \
635         DEFINE_BLOB_OPEN(table_name) \
636         DEFINE_BLOB_CLOSE(table_name) \
637         DEFINE_BLOB_CREATE(table_name) \
638         DEFINE_BLOB_INIT(table_name) \
639         DEFINE_BLOB_COMMAND(ls, table_name, cmd_prefix) \
640         DEFINE_BLOB_COMMAND(cat, table_name, cmd_prefix) \
641         DEFINE_BLOB_COMMAND(add, table_name, cmd_prefix) \
642         DEFINE_BLOB_COMMAND(rm, table_name, cmd_prefix) \
643         DEFINE_BLOB_COMMAND(mv, table_name, cmd_prefix) \
644         DEFINE_GET_NAME_BY_ID(table_name, cmd_prefix); \
645         DEFINE_GET_DEF_BY_ID(table_name, cmd_prefix); \
646         DEFINE_GET_DEF_BY_NAME(table_name, cmd_prefix); \
647         DEFINE_GET_NAME_AND_DEF_BY_ROW(table_name, cmd_prefix); \
648
649 /** \cond doxygen isn't smart enough to recognize these */
650 DEFINE_BLOB_FUNCTIONS(lyrics, lyr);
651 DEFINE_BLOB_FUNCTIONS(images, img);
652 DEFINE_BLOB_FUNCTIONS(moods, mood);
653 DEFINE_BLOB_FUNCTIONS(playlists, pl);
654 /** \endcond */