return rc;
}
+int parser_replace_file(struct discover_context *ctx,
+ struct discover_device *dev, const char *filename,
+ char *buf, int len)
+{
+ bool release;
+ char *path;
+ int rc;
+
+ if (!dev->mounted)
+ return -1;
+
+ rc = device_request_write(dev, &release);
+ if (rc) {
+ pb_log("Can't write file %s: device doesn't allow write\n",
+ dev->device_path);
+ return -1;
+ }
+
+ path = local_path(ctx, dev, filename);
+
+ rc = replace_file(path, buf, len);
+
+ talloc_free(path);
+
+ device_release_write(dev, release);
+
+ return rc;
+}
+
static int download_config(struct discover_context *ctx, char **buf, int *len)
{
struct load_url_result *result;
if (i->parser->method != CONF_METHOD_LOCAL_FILE)
continue;
- pb_log("\ttrying parser '%s'\n", i->parser->name);
+ pb_debug("\ttrying parser '%s'\n", i->parser->name);
ctx->parser = i->parser;
iterate_parser_files(ctx, ctx->parser);
}
if (i->parser->method != method)
continue;
- pb_log("\ttrying parser '%s'\n", i->parser->name);
+ pb_debug("\ttrying parser '%s'\n", i->parser->name);
ctx->parser = i->parser;
i->parser->parse(ctx, buf, len);
}
}
}
+static void *parsers_ctx;
+
void __register_parser(struct parser *parser)
{
- struct p_item* i = talloc(NULL, struct p_item);
+ struct p_item *i;
- printf("%s: %s\n", __func__, parser->name);
+ if (!parsers_ctx)
+ parsers_ctx = talloc_new(NULL);
+ i = talloc(parsers_ctx, struct p_item);
i->parser = parser;
list_add(&parsers, &i->list);
}
+static __attribute__((destructor)) void cleanup_parsers(void)
+{
+ talloc_free(parsers_ctx);
+}
+
void parser_init(void)
{
}