static void print_realm_list(struct deltacloud_realm *realms) { struct deltacloud_realm *realm; deltacloud_for_each(realm, realms) print_realm(realm); }
/* Saves the union ipt_matchinfo in parsable form to stdout. */ static void save(const struct ipt_ip *ip, const struct ipt_entry_match *match) { printf("--realm "); print_realm(((struct ipt_realm_info *)match->data)->id, ((struct ipt_realm_info *)match->data)->mask, ((struct ipt_realm_info *)match->data)->invert, 0); }
/* Prints out the matchinfo. */ static void print(const struct ipt_ip *ip, const struct ipt_entry_match *match, int numeric) { printf("REALM match "); print_realm(((struct ipt_realm_info *)match->data)->id, ((struct ipt_realm_info *)match->data)->mask, ((struct ipt_realm_info *)match->data)->invert, numeric); }
static void realm_save(const void *ip, const struct xt_entry_match *match) { const struct xt_realm_info *ri = (const void *)match->data; if (ri->invert) printf(" !"); printf(" --realm"); print_realm(ri->id, ri->mask, 0); }
static void realm_print(const void *ip, const struct xt_entry_match *match, int numeric) { const struct xt_realm_info *ri = (const void *)match->data; if (ri->invert) printf(" !"); printf(" realm"); print_realm(ri->id, ri->mask, numeric); }
int main(int argc, char *argv[]) { struct deltacloud_api api; struct deltacloud_api zeroapi; struct deltacloud_realm realm; struct deltacloud_realm *realms; int ret = 3; if (argc != 4) { fprintf(stderr, "Usage: %s <url> <user> <password>\n", argv[0]); return 1; } if (deltacloud_initialize(&api, argv[1], argv[2], argv[3]) < 0) { fprintf(stderr, "Failed to find links for the API: %s\n", deltacloud_get_last_error_string()); return 2; } memset(&zeroapi, 0, sizeof(struct deltacloud_api)); /* test out deltacloud_supports_realms */ if (deltacloud_supports_realms(NULL) >= 0) { fprintf(stderr, "Expected deltacloud_supports_realms to fail with NULL api, but succeeded\n"); goto cleanup; } if (deltacloud_supports_realms(&zeroapi) >= 0) { fprintf(stderr, "Expected deltacloud_supports_realms to fail with uninitialized api, but succeeded\n"); goto cleanup; } if (deltacloud_supports_realms(&api)) { /* test out deltacloud_get_realms */ if (deltacloud_get_realms(NULL, &realms) >= 0) { fprintf(stderr, "Expected deltacloud_get_realms to fail with NULL api, but succeeded\n"); goto cleanup; } if (deltacloud_get_realms(&api, NULL) >= 0) { fprintf(stderr, "Expected deltacloud_get_realms to fail with NULL realms, but succeeded\n"); goto cleanup; } if (deltacloud_get_realms(&zeroapi, &realms) >= 0) { fprintf(stderr, "Expected deltacloud_get_realms to fail with unintialized api, but succeeded\n"); goto cleanup; } if (deltacloud_get_realms(&api, &realms) < 0) { fprintf(stderr, "Failed to get_realms: %s\n", deltacloud_get_last_error_string()); goto cleanup; } print_realm_list(realms); if (realms != NULL) { /* test out deltacloud_get_realm_by_id */ if (deltacloud_get_realm_by_id(NULL, realms->id, &realm) >= 0) { fprintf(stderr, "Expected deltacloud_get_realm_by_id to fail with NULL api, but succeeded\n"); goto cleanup; } if (deltacloud_get_realm_by_id(&api, NULL, &realm) >= 0) { fprintf(stderr, "Expected deltacloud_get_realm_by_id to fail with NULL id, but succeeded\n"); goto cleanup; } if (deltacloud_get_realm_by_id(&api, realms->id, NULL) >= 0) { fprintf(stderr, "Expected deltacloud_get_realm_by_id to fail with NULL realm, but succeeded\n"); goto cleanup; } if (deltacloud_get_realm_by_id(&api, "bogus_id", &realm) >= 0) { fprintf(stderr, "Expected deltacloud_get_realm_by_id to fail with bogus id, but succeeded\n"); goto cleanup; } if (deltacloud_get_realm_by_id(&zeroapi, realms->id, &realm) >= 0) { fprintf(stderr, "Expected deltacloud_get_realm_by_id to fail with unintialized api, but succeeded\n"); goto cleanup; } /* here we use the first realm from the list above */ if (deltacloud_get_realm_by_id(&api, realms->id, &realm) < 0) { fprintf(stderr, "Failed to get realm by id: %s\n", deltacloud_get_last_error_string()); goto cleanup; } print_realm(&realm); deltacloud_free_realm(&realm); } } else fprintf(stderr, "Realms are not supported\n"); ret = 0; cleanup: deltacloud_free_realm_list(&realms); deltacloud_free(&api); return ret; }