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