e43d194dd58da5c62ced9f52b65557109c2b081c
[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 int fd, const struct osl_object *query)
135 {
136 struct lsblob_action_data lbad = {
137 .flags = *(uint32_t *)query->data,
138 .pb = {
139 .max_size = shm_get_shmmax(),
140 .private_data = &(struct afs_max_size_handler_data) {
141 .fd = 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 *)query->data + sizeof(uint32_t),
150 .size = 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(callback_function *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, int fd,
224 const struct osl_object *query)
225 {
226 struct pattern_match_data pmd = {
227 .table = table,
228 .patterns = *query,
229 .loop_col_num = BLOBCOL_NAME,
230 .match_col_num = BLOBCOL_NAME,
231 .pm_flags = PM_SKIP_EMPTY_NAME,
232 .data = &fd,
233 .action = cat_blob
234 };
235 for_each_matching_row(&pmd);
236 if (pmd.num_matches == 0) {
237 char err_msg[] = "no matches\n";
238 pass_buffer_as_shm(fd, SBD_OUTPUT, err_msg, sizeof(err_msg));
239 }
240 return 0;
241 }
242
243 static int com_catblob(callback_function *f, struct command_context *cc)
244 {
245 if (cc->argc < 2)
246 return -E_BLOB_SYNTAX;
247 return send_standard_callback_request(cc->argc - 1, cc->argv + 1, f,
248 afs_cb_result_handler, cc);
249 }
250
251 /** Used for removing rows from a blob table. */
252 struct rmblob_data {
253 /** Message buffer. */
254 struct para_buffer pb;
255 };
256
257 static int remove_blob(struct osl_table *table, struct osl_row *row,
258 const char *name, void *data)
259 {
260 struct rmblob_data *rmbd = data;
261 int ret = osl(osl_del_row(table, row));
262 if (ret < 0) {
263 para_printf(&rmbd->pb, "%s: %s\n", name, para_strerror(-ret));
264 return ret;
265 }
266 return 1;
267 }
268
269 static int com_rmblob_callback(struct osl_table *table, int fd,
270 const struct osl_object *query)
271 {
272 int ret;
273 struct rmblob_data rmbd = {
274 .pb = {
275 .max_size = shm_get_shmmax(),
276 .private_data = &(struct afs_max_size_handler_data) {
277 .fd = fd,
278 .band = SBD_OUTPUT
279 },
280 .max_size_handler = afs_max_size_handler,
281 }
282 };
283 struct pattern_match_data pmd = {
284 .table = table,
285 .patterns = *query,
286 .loop_col_num = BLOBCOL_NAME,
287 .match_col_num = BLOBCOL_NAME,
288 .pm_flags = PM_SKIP_EMPTY_NAME,
289 .data = &rmbd,
290 .action = remove_blob
291 };
292 ret = for_each_matching_row(&pmd);
293 if (ret < 0)
294 para_printf(&rmbd.pb, "%s\n", para_strerror(-ret));
295 if (pmd.num_matches == 0)
296 para_printf(&rmbd.pb, "no matches, nothing removed\n");
297 else {
298 para_printf(&rmbd.pb, "removed %d blobs\n", pmd.num_matches);
299 afs_event(BLOB_RENAME, NULL, table);
300 }
301 flush_and_free_pb(&rmbd.pb);
302 return 0;
303 }
304
305 static int com_rmblob(callback_function *f, struct command_context *cc)
306 {
307 if (cc->argc < 2)
308 return -E_MOOD_SYNTAX;
309 return send_option_arg_callback_request(NULL, cc->argc - 1, cc->argv + 1, f,
310 afs_cb_result_handler, cc);
311 }
312
313 static int com_addblob_callback(struct osl_table *table, int fd,
314 const struct osl_object *query)
315 {
316 struct osl_object objs[NUM_BLOB_COLUMNS];
317 char *name = query->data, *msg;
318 size_t name_len = strlen(name) + 1, msg_len;
319 uint32_t id;
320 unsigned num_rows;
321 int ret;
322
323 ret = osl(osl_get_num_rows(table, &num_rows));
324 if (ret < 0)
325 goto out;
326 if (!num_rows) { /* this is the first entry ever added */
327 /* insert dummy row containing the id */
328 id = 2; /* this entry will be entry #1, so 2 is the next */
329 objs[BLOBCOL_ID].data = &id;
330 objs[BLOBCOL_ID].size = sizeof(id);
331 objs[BLOBCOL_NAME].data = "";
332 objs[BLOBCOL_NAME].size = 1;
333 objs[BLOBCOL_DEF].data = "";
334 objs[BLOBCOL_DEF].size = 1;
335 ret = osl(osl_add_row(table, objs));
336 if (ret < 0)
337 goto out;
338 } else {
339 /* check if name already exists */
340 struct osl_row *row;
341 struct osl_object obj = {.data = name, .size = name_len};
342 ret = osl(osl_get_row(table, BLOBCOL_NAME, &obj, &row));
343 if (ret < 0 && ret != -OSL_ERRNO_TO_PARA_ERROR(E_OSL_RB_KEY_NOT_FOUND))
344 goto out;
345 if (ret >= 0) { /* we already have a blob with this name */
346 ret = osl(osl_get_object(table, row, BLOBCOL_ID, &obj));
347 if (ret < 0)
348 goto out;
349 id = *(uint32_t *)obj.data;
350 obj.data = name + name_len;
351 obj.size = query->size - name_len;
352 ret = osl(osl_update_object(table, row, BLOBCOL_DEF, &obj));
353 goto out;
354 }
355 /* new blob, get id of the dummy row and increment it */
356 obj.data = "";
357 obj.size = 1;
358 ret = osl(osl_get_row(table, BLOBCOL_NAME, &obj, &row));
359 if (ret < 0)
360 goto out;
361 ret = osl(osl_get_object(table, row, BLOBCOL_ID, &obj));
362 if (ret < 0)
363 goto out;
364 id = *(uint32_t *)obj.data + 1;
365 obj.data = &id;
366 ret = osl(osl_update_object(table, row, BLOBCOL_ID, &obj));
367 if (ret < 0)
368 goto out;
369 }
370 id--;
371 objs[BLOBCOL_ID].data = &id;
372 objs[BLOBCOL_ID].size = sizeof(id);
373 objs[BLOBCOL_NAME].data = name;
374 objs[BLOBCOL_NAME].size = name_len;
375 objs[BLOBCOL_DEF].data = name + name_len;
376 objs[BLOBCOL_DEF].size = query->size - name_len;
377 ret = osl(osl_add_row(table, objs));
378 if (ret < 0)
379 goto out;
380 afs_event(BLOB_ADD, NULL, table);
381 out:
382 if (ret < 0)
383 msg_len = xasprintf(&msg, "could not add %s: %s\n", name,
384 para_strerror(-ret));
385 else
386 msg_len = xasprintf(&msg, "added %s as id %u\n", name, id);
387 pass_buffer_as_shm(fd, SBD_OUTPUT, msg, msg_len);
388 free(msg);
389 return 0;
390 }
391
392 /* Write input from fd to dynamically allocated buffer, but maximal 10M. */
393 static int fd2buf(struct stream_cipher_context *scc, struct osl_object *obj)
394 {
395 size_t max_size = 10 * 1024 * 1024;
396 int ret;
397 struct iovec iov;
398
399 obj->data = NULL;
400 obj->size = 0;
401 again:
402 do {
403 ret = recv_sb(scc, SBD_BLOB_DATA, max_size, &iov);
404 } while (ret == 0);
405
406 if (ret < 0) {
407 free(obj->data);
408 obj->data = NULL;
409 obj->size = 0;
410 return ret;
411 }
412 if (iov.iov_len == 0) /* end of blob */
413 return 1;
414 if (!obj->data) {
415 obj->data = iov.iov_base;
416 obj->size = iov.iov_len;
417 } else {
418 obj->data = para_realloc(obj->data, obj->size + iov.iov_len);
419 memcpy(obj->data + obj->size, iov.iov_base, iov.iov_len);
420 obj->size += iov.iov_len;
421 free(iov.iov_base);
422 max_size -= iov.iov_len;
423 }
424 goto again;
425 return 1;
426 }
427
428 /*
429 * Read blob from a file descriptor and send it to afs.
430 *
431 * This function is called from the addblob command handlers to instruct the
432 * afs process to store the input in a blob table. Input is read and decrypted
433 * from the file descriptor given by cc and appended to arg_obj, which contains
434 * the name of the blob to create. The combined buffer is made available to the
435 * afs process via the callback method.
436 */
437 static int stdin_command(struct command_context *cc, struct osl_object *arg_obj,
438 callback_function *f)
439 {
440 struct osl_object query, stdin_obj;
441 int ret;
442
443 ret = send_sb(&cc->scc, NULL, 0, SBD_AWAITING_DATA, false);
444 if (ret < 0)
445 return ret;
446 ret = fd2buf(&cc->scc, &stdin_obj);
447 if (ret < 0)
448 return ret;
449 query.size = arg_obj->size + stdin_obj.size;
450 query.data = para_malloc(query.size);
451 memcpy(query.data, arg_obj->data, arg_obj->size);
452 if (stdin_obj.size > 0)
453 memcpy((char *)query.data + arg_obj->size, stdin_obj.data,
454 stdin_obj.size);
455 free(stdin_obj.data);
456 ret = send_callback_request(f, &query, afs_cb_result_handler, cc);
457 free(query.data);
458 return ret;
459 }
460
461 static int com_addblob(callback_function *f, struct command_context *cc)
462 {
463 struct osl_object arg_obj;
464
465 if (cc->argc != 2)
466 return -E_BLOB_SYNTAX;
467 if (!*cc->argv[1]) /* empty name is reserved for the dummy row */
468 return -E_BLOB_SYNTAX;
469 arg_obj.size = strlen(cc->argv[1]) + 1;
470 arg_obj.data = (char *)cc->argv[1];
471 return stdin_command(cc, &arg_obj, f);
472 }
473
474 static int com_mvblob_callback(struct osl_table *table, int fd,
475 const struct osl_object *query)
476 {
477 char *src = (char *) query->data;
478 struct osl_object obj = {.data = src, .size = strlen(src) + 1};
479 char *dest = src + obj.size;
480 struct osl_row *row;
481 struct para_buffer pb = {
482 .max_size = shm_get_shmmax(),
483 .private_data = &fd,
484 .max_size_handler = afs_max_size_handler
485 };
486 int ret = osl(osl_get_row(table, BLOBCOL_NAME, &obj, &row));
487
488 if (ret < 0) {
489 para_printf(&pb, "could not locate %s: %s\n", src,
490 para_strerror(-ret));
491 goto out;
492 }
493 obj.data = dest;
494 obj.size = strlen(dest) + 1;
495 ret = osl(osl_update_object(table, row, BLOBCOL_NAME, &obj));
496 if (ret < 0) {
497 para_printf(&pb, "failed to update object %s: %s\n", dest,
498 para_strerror(-ret));
499 goto out;
500 }
501 afs_event(BLOB_RENAME, NULL, table);
502 out:
503 flush_and_free_pb(&pb);
504 return 0;
505 }
506
507 static int com_mvblob(callback_function *f, struct command_context *cc)
508 {
509 int ret;
510
511 if (cc->argc != 3)
512 return -E_MOOD_SYNTAX;
513 ret = send_option_arg_callback_request(NULL, cc->argc - 1,
514 cc->argv + 1, f, afs_cb_result_handler, cc);
515 if (ret < 0)
516 send_strerror(cc, -ret);
517 return ret;
518 }
519
520 #define DEFINE_BLOB_COMMAND(cmd_name, table_name, cmd_prefix) \
521 static int com_ ## cmd_name ## cmd_prefix ## _callback(int fd, const struct osl_object *query) \
522 { \
523 return com_ ## cmd_name ## blob_callback(table_name ## _table, fd, query); \
524 } \
525 int com_ ## cmd_name ## cmd_prefix(struct command_context *cc) \
526 { \
527 return com_ ## cmd_name ## blob(com_ ## cmd_name ## cmd_prefix ## _callback, cc); \
528 }
529
530 static int blob_get_name_by_id(struct osl_table *table, uint32_t id,
531 char **name)
532 {
533 struct osl_row *row;
534 struct osl_object obj = {.data = &id, .size = sizeof(id)};
535 int ret;
536
537 *name = NULL;
538 if (!id)
539 return 1;
540 ret = osl(osl_get_row(table, BLOBCOL_ID, &obj, &row));
541 if (ret < 0)
542 return ret;
543 ret = osl(osl_get_object(table, row, BLOBCOL_NAME, &obj));
544 if (ret < 0)
545 return ret;
546 *name = (char *)obj.data;
547 return 1;
548 }
549
550 /** Define the \p get_name_by_id function for this blob type. */
551 #define DEFINE_GET_NAME_BY_ID(table_name, cmd_prefix) \
552 int cmd_prefix ## _get_name_by_id(uint32_t id, char **name) \
553 { \
554 return blob_get_name_by_id(table_name ## _table, id, name); \
555 }
556
557
558 static int blob_get_def_by_name(struct osl_table *table, char *name,
559 struct osl_object *def)
560 {
561 struct osl_row *row;
562 struct osl_object obj = {.data = name, .size = strlen(name) + 1};
563 int ret;
564
565 def->data = NULL;
566 if (!*name)
567 return 1;
568 ret = osl(osl_get_row(table, BLOBCOL_NAME, &obj, &row));
569 if (ret < 0)
570 return ret;
571 return osl(osl_open_disk_object(table, row, BLOBCOL_DEF, def));
572 }
573
574 /** Define the \p get_def_by_id function for this blob type. */
575 #define DEFINE_GET_DEF_BY_NAME(table_name, cmd_prefix) \
576 int cmd_prefix ## _get_def_by_name(char *name, struct osl_object *def) \
577 { \
578 return blob_get_def_by_name(table_name ## _table, name, def); \
579 }
580
581 static int blob_get_def_by_id(struct osl_table *table, uint32_t id,
582 struct osl_object *def)
583 {
584 struct osl_row *row;
585 struct osl_object obj = {.data = &id, .size = sizeof(id)};
586 int ret;
587
588 def->data = NULL;
589 if (!id)
590 return 1;
591 ret = osl(osl_get_row(table, BLOBCOL_ID, &obj, &row));
592 if (ret < 0)
593 return ret;
594 return osl(osl_open_disk_object(table, row, BLOBCOL_DEF, def));
595 }
596
597 /** Define the \p get_def_by_id function for this blob type. */
598 #define DEFINE_GET_DEF_BY_ID(table_name, cmd_prefix) \
599 int cmd_prefix ## _get_def_by_id(uint32_t id, struct osl_object *def) \
600 { \
601 return blob_get_def_by_id(table_name ## _table, id, def); \
602 }
603
604 static int blob_get_name_and_def_by_row(struct osl_table *table,
605 const struct osl_row *row, char **name, struct osl_object *def)
606 {
607 struct osl_object obj;
608 int ret = osl(osl_get_object(table, row, BLOBCOL_NAME, &obj));
609 if (ret < 0)
610 return ret;
611 *name = obj.data;
612 return osl(osl_open_disk_object(table, row, BLOBCOL_DEF, def));
613 }
614 /** Define the \p get_name_and_def_by_row function for this blob type. */
615 #define DEFINE_GET_NAME_AND_DEF_BY_ROW(table_name, cmd_prefix) \
616 int cmd_prefix ## _get_name_and_def_by_row(const struct osl_row *row, \
617 char **name, struct osl_object *def) \
618 { \
619 return blob_get_name_and_def_by_row(table_name ## _table, \
620 row, name, def); \
621 }
622
623 /** Define the \p close function for this blob type. */
624 #define DEFINE_BLOB_CLOSE(table_name) \
625 static void table_name ## _close(void) \
626 { \
627 osl_close_table(table_name ## _table, OSL_MARK_CLEAN); \
628 table_name ## _table = NULL; \
629 }
630
631 /** Define the \p create function for this blob type. */
632 #define DEFINE_BLOB_CREATE(table_name) \
633 static int table_name ## _create(const char *dir) \
634 { \
635 table_name ## _table_desc.dir = dir; \
636 return osl(osl_create_table(&table_name ## _table_desc)); \
637 }
638
639 static int blob_open(struct osl_table **table,
640 struct osl_table_description *desc,
641 const char *dir)
642 {
643 int ret;
644 desc->dir = dir;
645 ret = osl(osl_open_table(desc, table));
646 if (ret >= 0)
647 return ret;
648 *table = NULL;
649 if (ret >= 0 || ret == -OSL_ERRNO_TO_PARA_ERROR(E_OSL_NOENT))
650 return 1;
651 return ret;
652 }
653
654 #define DEFINE_BLOB_OPEN(table_name) \
655 static int table_name ## _open(const char *dir) \
656 { \
657 return blob_open(&table_name ## _table, \
658 &table_name ## _table_desc, dir); \
659 }
660
661
662 /** Define the \p init function for this blob type. */
663 #define DEFINE_BLOB_INIT(table_name) \
664 void table_name ## _init(struct afs_table *t) \
665 { \
666 t->open = table_name ## _open; \
667 t->close = table_name ## _close; \
668 t->create = table_name ## _create;\
669 t->event_handler = table_name ##_event_handler; \
670 table_name ## _table = NULL; \
671 }
672
673
674 /** Define all functions for this blob type. */
675 #define DEFINE_BLOB_FUNCTIONS(table_name, cmd_prefix) \
676 DEFINE_BLOB_OPEN(table_name) \
677 DEFINE_BLOB_CLOSE(table_name) \
678 DEFINE_BLOB_CREATE(table_name) \
679 DEFINE_BLOB_INIT(table_name) \
680 DEFINE_BLOB_COMMAND(ls, table_name, cmd_prefix) \
681 DEFINE_BLOB_COMMAND(cat, table_name, cmd_prefix) \
682 DEFINE_BLOB_COMMAND(add, table_name, cmd_prefix) \
683 DEFINE_BLOB_COMMAND(rm, table_name, cmd_prefix) \
684 DEFINE_BLOB_COMMAND(mv, table_name, cmd_prefix) \
685 DEFINE_GET_NAME_BY_ID(table_name, cmd_prefix); \
686 DEFINE_GET_DEF_BY_ID(table_name, cmd_prefix); \
687 DEFINE_GET_DEF_BY_NAME(table_name, cmd_prefix); \
688 DEFINE_GET_NAME_AND_DEF_BY_ROW(table_name, cmd_prefix); \
689
690 /* doxygen isn't smart enough to recognize these */
691 /** \cond blob_function */
692 DEFINE_BLOB_FUNCTIONS(lyrics, lyr);
693 DEFINE_BLOB_FUNCTIONS(images, img);
694 DEFINE_BLOB_FUNCTIONS(moods, mood);
695 DEFINE_BLOB_FUNCTIONS(playlists, pl);
696 /** \endcond blob_function */