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