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