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