Commit dd11a50c authored by Pavel Emelyanov's avatar Pavel Emelyanov

ext: Add more helpers to mess with external resources.

Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
parent 8ce76653
...@@ -40,3 +40,22 @@ char *external_lookup_by_key(char *key) ...@@ -40,3 +40,22 @@ char *external_lookup_by_key(char *key)
return NULL; return NULL;
} }
int external_for_each_type(char *type, int (*cb)(struct external *, void *), void *arg)
{
struct external *ext;
int ln = strlen(type);
int ret = 0;
list_for_each_entry(ext, &opts.external, node) {
if (strncmp(ext->id, type, ln))
continue;
if (ext->id[ln] != '[')
continue;
ret = cb(ext, arg);
if (ret)
break;
}
return ret;
}
...@@ -8,4 +8,19 @@ struct external { ...@@ -8,4 +8,19 @@ struct external {
extern int add_external(char *key); extern int add_external(char *key);
extern bool external_lookup_id(char *id); extern bool external_lookup_id(char *id);
extern char *external_lookup_by_key(char *id); extern char *external_lookup_by_key(char *id);
extern int external_for_each_type(char *type, int (*cb)(struct external *, void *), void *arg);
static inline char *external_val(struct external *e)
{
char *aux;
aux = strchr(e->id, '[');
if (aux) {
aux = strchr(aux + 1, ']');
if (aux && aux[1] == ':')
return aux + 2;
}
return NULL;
}
#endif #endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment