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