environment find_cmd(parser & p) { expr e; level_param_names ls; { bool save_options = true; parser::local_scope scope(p, save_options); p.set_option(get_elaborator_ignore_instances_name(), true); std::tie(e, ls) = parse_local_expr(p); } buffer<std::string> pos_names, neg_names; parse_filters(p, pos_names, neg_names); environment env = p.env(); auto tc = mk_opaque_type_checker(env, p.mk_ngen()); flycheck_information info(p.regular_stream()); if (info.enabled()) { p.display_information_pos(p.cmd_pos()); } p.regular_stream() << "find_decl result:\n"; unsigned max_steps = get_find_max_steps(p.get_options()); bool cheap = !get_find_expensive(p.get_options()); bool found = false; env.for_each_declaration([&](declaration const & d) { if (std::all_of(pos_names.begin(), pos_names.end(), [&](std::string const & pos) { return is_part_of(pos, d.get_name()); }) && std::all_of(neg_names.begin(), neg_names.end(), [&](std::string const & neg) { return !is_part_of(neg, d.get_name()); }) && match_pattern(*tc.get(), e, d, max_steps, cheap)) { found = true; p.regular_stream() << " " << get_decl_short_name(d.get_name(), env) << " : " << d.get_type() << endl; } }); if (!found) p.regular_stream() << "no matches\n"; return env; }
static DBusMessage *media_folder_list_items(DBusConnection *conn, DBusMessage *msg, void *data) { struct media_player *mp = data; struct media_folder *folder = mp->scope; struct player_callback *cb = mp->cb; DBusMessageIter iter; uint32_t start, end; int err; dbus_message_iter_init(msg, &iter); if (parse_filters(mp, &iter, &start, &end) < 0) return btd_error_invalid_args(msg); if (cb->cbs->list_items == NULL) return btd_error_not_supported(msg); if (folder->msg != NULL) return btd_error_failed(msg, strerror(EBUSY)); err = cb->cbs->list_items(mp, folder->item->name, start, end, cb->user_data); if (err < 0) return btd_error_failed(msg, strerror(-err)); folder->msg = dbus_message_ref(msg); return NULL; }
mlt_service SingleResourceLoader::get_asis_producer(JsonWrap js) throw (Exception) { json_t* defines = js.h; defines_tmp=js; json_t* je = json_object_get(defines, "resource"); json_t* uuid_je = json_object_get(defines, "uuid"); json_t* svc_je = json_object_get(defines, "service"); assert( je && json_is_string(je) && strlen(json_string_value(je))); assert( svc_je && json_is_string(svc_je) && strlen(json_string_value(svc_je))); assert( uuid_je && json_is_string(uuid_je) && strlen(json_string_value(uuid_je))); mlt_producer obj = MLT_PRODUCER(MltLoader::pop_mlt_registry(json_string_value(uuid_je))); if (obj == NULL) { mlt_profile profile = mlt_profile_clone(global_profile); obj = mlt_factory_producer(profile, json_string_value(svc_je), json_string_value(je)); #ifdef DEBUG std::cout << mlt_producer_properties(obj); #endif } if ( !obj ) { throw_error_v(ErrorRuntimeLoadFailed, "video producer load failed:%s", json_string_value(je)); } mlt_properties props = mlt_producer_properties(obj); je = json_object_get(defines, "props"); if (je && json_is_object(je) && json_object_size(je)) { json_t* inj = json_object_get(je,"in"), *outj = json_object_get(je,"out"); assert(inj && outj && json_is_integer(inj) && json_is_integer(outj)); mlt_producer_set_in_and_out(obj,json_integer_value(inj), json_integer_value(outj)); void* it = json_object_iter(je); while(it) { const char* k = json_object_iter_key(it); json_t* prop_je = json_object_iter_value(it); it = json_object_iter_next(je, it); if ( json_is_object(prop_je) || json_is_array(prop_je)) continue; if ( !strcmp(k,"in") || !strcmp(k,"out")) continue; switch(prop_je->type) { case JSON_INTEGER: mlt_properties_set_int64(props, k, json_integer_value(prop_je)); break; case JSON_REAL: mlt_properties_set_double(props, k, json_real_value(prop_je)); break; case JSON_STRING: mlt_properties_set(props, k, json_string_value(prop_je)); break; case JSON_TRUE: mlt_properties_set_int(props,k, 1); break; case JSON_FALSE: mlt_properties_set_int(props,k, 0); break; default: break; } } } MltSvcWrap wrap(mlt_producer_service(obj), 1); producer_tmp = obj; parse_filters(); wrap.obj = NULL; return mlt_producer_service(obj); }
int ssdp_listener_start(ssdp_listener_s *listener, configuration_s *conf) { PRINT_DEBUG("ssdp_listener_start()"); /* The structure contining all the filters information */ filters_factory_s *filters_factory = NULL; /* Parse the filters */ PRINT_DEBUG("parse_filters()"); parse_filters(conf->filter, &filters_factory, TRUE & (~conf->quiet_mode)); /* Child process server loop */ PRINT_DEBUG("Strating infinite loop"); ssdp_message_s *ssdp_message; BOOL drop_message; /* Create a list for keeping/caching SSDP messages */ ssdp_cache_s *ssdp_cache = NULL; while (!listener->stop) { ssdp_recv_node_s recv_node; drop_message = FALSE; ssdp_message = NULL; PRINT_DEBUG("loop: ready to receive"); ssdp_listener_read(listener, &recv_node); #ifdef __DEBUG if (recv_node.recv_bytes > 0) { PRINT_DEBUG("**** RECEIVED %d bytes ****\n%s", recv_node.recv_bytes, notif_string); PRINT_DEBUG("************************"); } #endif /* If timeout reached then go through the ssdp_cache list and see if anything needs to be sent */ if (recv_node.recv_bytes < 1) { PRINT_DEBUG("Timed-out waiting for a SSDP message"); if(!ssdp_cache || *ssdp_cache->ssdp_messages_count == 0) { PRINT_DEBUG("No messages in the SSDP cache, continuing to listen"); } else { /* If forwarding has been enabled, send the cached SSDP messages and empty the list*/ if(conf->forward_address) { PRINT_DEBUG("Forwarding cached SSDP messages"); if(!flush_ssdp_cache(conf, &ssdp_cache, "/abused/post.php", &listener->forwarder, 80, 1)) { PRINT_DEBUG("Failed flushing SSDP cache"); continue; } } /* Else just display the cached messages in a table */ else { PRINT_DEBUG("Displaying cached SSDP messages"); display_ssdp_cache(ssdp_cache, FALSE); } } continue; } /* Else a new ssdp message has been received */ else { /* init ssdp_message */ if (!init_ssdp_message(&ssdp_message)) { PRINT_ERROR("Failed to initialize the SSDP message buffer"); continue; } /* Build the ssdp message struct */ if (!build_ssdp_message(ssdp_message, recv_node.from_ip, recv_node.from_mac, recv_node.recv_bytes, recv_node.recv_data)) { PRINT_ERROR("Failed to build the SSDP message"); free_ssdp_message(&ssdp_message); continue; } // TODO: Make it recognize both AND and OR (search for ; inside a ,)!!! /* If -M is not set check if it is a M-SEARCH message and drop it */ if (conf->ignore_search_msgs && (strstr(ssdp_message->request, "M-SEARCH") != NULL)) { PRINT_DEBUG("Message contains a M-SEARCH request, dropping " "message"); free_ssdp_message(&ssdp_message); continue; } /* Check if notification should be used (if any filters have been set) */ if (filters_factory != NULL) { drop_message = filter(ssdp_message, filters_factory); } /* If message is not filtered then use it */ if (filters_factory == NULL || !drop_message) { /* Add ssdp_message to ssdp_cache (this internally checks for duplicates) */ if (!add_ssdp_message_to_cache(&ssdp_cache, &ssdp_message)) { PRINT_ERROR("Failed adding SSDP message to SSDP cache, skipping"); continue; } /* Fetch custom fields */ if (conf->fetch_info && !fetch_custom_fields(conf, ssdp_message)) { PRINT_DEBUG("Could not fetch custom fields"); } ssdp_message = NULL; /* Check if forwarding ('-a') is enabled */ if (conf->forward_address) { /* If max ssdp cache size reached then it is time to flush */ if (*ssdp_cache->ssdp_messages_count >= conf->ssdp_cache_size) { PRINT_DEBUG("Cache max size reached, sending and emptying"); if(!flush_ssdp_cache(conf, &ssdp_cache, "/abused/post.php", &listener->forwarder, 80, 1)) { PRINT_DEBUG("Failed flushing SSDP cache"); continue; } } else { PRINT_DEBUG("Cache max size not reached, not sending yet"); } } else { /* Display results on console */ PRINT_DEBUG("Displaying cached SSDP messages"); display_ssdp_cache(ssdp_cache, FALSE); } } } PRINT_DEBUG("scan loop: done"); } free_ssdp_filters_factory(filters_factory); return 0; }
static int cmd_balance_start(int argc, char **argv) { struct btrfs_ioctl_balance_args args; struct btrfs_balance_args *ptrs[] = { &args.data, &args.sys, &args.meta, NULL }; int force = 0; int verbose = 0; int nofilters = 1; int i; memset(&args, 0, sizeof(args)); optind = 1; while (1) { static const struct option longopts[] = { { "data", optional_argument, NULL, 'd'}, { "metadata", optional_argument, NULL, 'm' }, { "system", optional_argument, NULL, 's' }, { "force", no_argument, NULL, 'f' }, { "verbose", no_argument, NULL, 'v' }, { NULL, 0, NULL, 0 } }; int opt = getopt_long(argc, argv, "d::s::m::fv", longopts, NULL); if (opt < 0) break; switch (opt) { case 'd': nofilters = 0; args.flags |= BTRFS_BALANCE_DATA; if (parse_filters(optarg, &args.data)) return 1; break; case 's': nofilters = 0; args.flags |= BTRFS_BALANCE_SYSTEM; if (parse_filters(optarg, &args.sys)) return 1; break; case 'm': nofilters = 0; args.flags |= BTRFS_BALANCE_METADATA; if (parse_filters(optarg, &args.meta)) return 1; break; case 'f': force = 1; break; case 'v': verbose = 1; break; default: usage(cmd_balance_start_usage); } } if (check_argc_exact(argc - optind, 1)) usage(cmd_balance_start_usage); /* * allow -s only under --force, otherwise do with system chunks * the same thing we were ordered to do with meta chunks */ if (args.flags & BTRFS_BALANCE_SYSTEM) { if (!force) { error( "Refusing to explicitly operate on system chunks.\n" "Pass --force if you really want to do that."); return 1; } } else if (args.flags & BTRFS_BALANCE_METADATA) { args.flags |= BTRFS_BALANCE_SYSTEM; memcpy(&args.sys, &args.meta, sizeof(struct btrfs_balance_args)); } if (nofilters) { /* relocate everything - no filters */ args.flags |= BTRFS_BALANCE_TYPE_MASK; } /* drange makes sense only when devid is set */ for (i = 0; ptrs[i]; i++) { if ((ptrs[i]->flags & BTRFS_BALANCE_ARGS_DRANGE) && !(ptrs[i]->flags & BTRFS_BALANCE_ARGS_DEVID)) { error("drange filter must be used with devid filter"); return 1; } } /* soft makes sense only when convert for corresponding type is set */ for (i = 0; ptrs[i]; i++) { if ((ptrs[i]->flags & BTRFS_BALANCE_ARGS_SOFT) && !(ptrs[i]->flags & BTRFS_BALANCE_ARGS_CONVERT)) { error("'soft' option can be used only when converting profiles"); return 1; } } if (force) args.flags |= BTRFS_BALANCE_FORCE; if (verbose) dump_ioctl_balance_args(&args); return do_balance(argv[optind], &args, nofilters); }
static int cmd_balance_start(int argc, char **argv) { struct btrfs_ioctl_balance_args args; struct btrfs_balance_args *ptrs[] = { &args.data, &args.sys, &args.meta, NULL }; int force = 0; int verbose = 0; int background = 0; unsigned start_flags = 0; int i; memset(&args, 0, sizeof(args)); optind = 0; while (1) { enum { GETOPT_VAL_FULL_BALANCE = 256, GETOPT_VAL_BACKGROUND = 257 }; static const struct option longopts[] = { { "data", optional_argument, NULL, 'd'}, { "metadata", optional_argument, NULL, 'm' }, { "system", optional_argument, NULL, 's' }, { "force", no_argument, NULL, 'f' }, { "verbose", no_argument, NULL, 'v' }, { "full-balance", no_argument, NULL, GETOPT_VAL_FULL_BALANCE }, { "background", no_argument, NULL, GETOPT_VAL_BACKGROUND }, { "bg", no_argument, NULL, GETOPT_VAL_BACKGROUND }, { NULL, 0, NULL, 0 } }; int opt = getopt_long(argc, argv, "d::s::m::fv", longopts, NULL); if (opt < 0) break; switch (opt) { case 'd': start_flags |= BALANCE_START_FILTERS; args.flags |= BTRFS_BALANCE_DATA; if (parse_filters(optarg, &args.data)) return 1; break; case 's': start_flags |= BALANCE_START_FILTERS; args.flags |= BTRFS_BALANCE_SYSTEM; if (parse_filters(optarg, &args.sys)) return 1; break; case 'm': start_flags |= BALANCE_START_FILTERS; args.flags |= BTRFS_BALANCE_METADATA; if (parse_filters(optarg, &args.meta)) return 1; break; case 'f': force = 1; break; case 'v': verbose = 1; break; case GETOPT_VAL_FULL_BALANCE: start_flags |= BALANCE_START_NOWARN; break; case GETOPT_VAL_BACKGROUND: background = 1; break; default: usage_unknown_option(cmd_balance_start_usage, argv); } } if (check_argc_exact(argc - optind, 1)) return 1; /* * allow -s only under --force, otherwise do with system chunks * the same thing we were ordered to do with meta chunks */ if (args.flags & BTRFS_BALANCE_SYSTEM) { if (!force) { error( "Refusing to explicitly operate on system chunks.\n" "Pass --force if you really want to do that."); return 1; } } else if (args.flags & BTRFS_BALANCE_METADATA) { args.flags |= BTRFS_BALANCE_SYSTEM; memcpy(&args.sys, &args.meta, sizeof(struct btrfs_balance_args)); } if (!(start_flags & BALANCE_START_FILTERS)) { /* relocate everything - no filters */ args.flags |= BTRFS_BALANCE_TYPE_MASK; } /* drange makes sense only when devid is set */ for (i = 0; ptrs[i]; i++) { if ((ptrs[i]->flags & BTRFS_BALANCE_ARGS_DRANGE) && !(ptrs[i]->flags & BTRFS_BALANCE_ARGS_DEVID)) { error("drange filter must be used with devid filter"); return 1; } } /* soft makes sense only when convert for corresponding type is set */ for (i = 0; ptrs[i]; i++) { if ((ptrs[i]->flags & BTRFS_BALANCE_ARGS_SOFT) && !(ptrs[i]->flags & BTRFS_BALANCE_ARGS_CONVERT)) { error("'soft' option can be used only when converting profiles"); return 1; } } if (force) args.flags |= BTRFS_BALANCE_FORCE; if (verbose) dump_ioctl_balance_args(&args); if (background) { switch (fork()) { case (-1): error("unable to fork to run balance in background"); return 1; case (0): setsid(); switch(fork()) { case (-1): error( "unable to fork to run balance in background"); exit(1); case (0): /* * Read the return value to silence compiler * warning. Change to / should succeed and * we're not in a security-sensitive context. */ i = chdir("/"); close(0); close(1); close(2); open("/dev/null", O_RDONLY); open("/dev/null", O_WRONLY); open("/dev/null", O_WRONLY); break; default: exit(0); } break; default: exit(0); } } return do_balance(argv[optind], &args, start_flags); }