X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=blobdiff_plain;f=daemon%2Favailable.c;h=2a30cadfc6b51091728e12af3ad77a0c43348a4d;hp=b43d18200097a1f793c9dccd82818cd6db5a8468;hb=55938405ccd3d5e5736f30c9bd78a51998cd7158;hpb=8fd7f255d611d2092a244c4a48c6b7b4529e98b1 diff --git a/daemon/available.c b/daemon/available.c index b43d182..2a30cad 100644 --- a/daemon/available.c +++ b/daemon/available.c @@ -29,10 +29,45 @@ int do_available (char *const *groups) { - if (groups[0] != NULL) { - reply_with_error ("%s: unknown group", groups[0]); - return -1; + int av; + size_t i, j; + + for (i = 0; groups[i] != NULL; ++i) { + for (j = 0; optgroups[j].group != NULL; ++j) { + if (STREQ (groups[i], optgroups[j].group)) { + av = optgroups[j].available (); + if (!av) { + reply_with_error ("%s: group not available", optgroups[j].group); + return -1; + } + break; /* out of for (j) loop */ + } + } + + /* Unknown group? */ + if (optgroups[j].group == NULL) { + reply_with_error ("%s: unknown group", groups[i]); + return -1; + } } return 0; } + +char ** +do_available_all_groups (void) +{ + size_t i; + char **groups = NULL; + int size = 0, alloc = 0; + + for (i = 0; optgroups[i].group != NULL; ++i) { + if (add_string (&groups, &size, &alloc, optgroups[i].group) == -1) + return NULL; + } + + if (add_string (&groups, &size, &alloc, NULL) == -1) + return NULL; + + return groups; /* caller frees */ +}