static void test_multipleHubsFound(void) { List *list = NULL; hostcount = 2; assert_int_equal(ListHubs(&list), 3); assert_int_not_equal(list, NULL); ListIterator *i = NULL; i = ListIteratorGet(list); HostProperties *host1 = (HostProperties *)ListIteratorData(i); assert_int_not_equal(ListIteratorNext(i), -1); HostProperties *host2 = (HostProperties *)ListIteratorData(i); assert_int_not_equal(ListIteratorNext(i), -1); HostProperties *host3 = (HostProperties *)ListIteratorData(i); assert_int_equal(host1->Port, 5308); assert_string_equal(host1->Hostname, "host1"); assert_string_equal(host1->IPAddress, "10.0.0.100"); assert_int_equal(host2->Port, 1234); assert_string_equal(host2->Hostname, "host2"); assert_string_equal(host2->IPAddress, "10.0.0.100"); assert_int_equal(host3->Port, 4321); assert_string_equal(host3->Hostname, "host3"); assert_string_equal(host3->IPAddress, "10.0.0.100"); ListIteratorDestroy(&i); ListDestroy(&list); }
static void test_errorOccurred(void) { List *list = NULL; hostcount = 4; assert_int_equal(ListHubs(&list), -1); }
static void test_noHubsFound(void) { List *list = NULL; hostcount = 0; assert_int_equal(ListHubs(&list), 0); assert_int_not_equal(list, NULL); ListDestroy(&list); }
static void test_oneHubFound(void) { List *list = NULL; hostcount = 1; assert_int_equal(ListHubs(&list), 1); assert_int_not_equal(list, NULL); ListIterator *i = NULL; i = ListIteratorGet(list); assert_true(i != NULL); HostProperties *host = (HostProperties *)ListIteratorData(i); assert_int_equal(host->Port,5308); assert_string_equal(host->Hostname, "host1"); assert_string_equal(host->IPAddress, "10.0.0.100"); ListIteratorDestroy(&i); ListDestroy(&list); }
static int AutomaticBootstrap() { List *foundhubs = NULL; int hubcount = ListHubs(&foundhubs); switch(hubcount) { case -1: CfOut(cf_error, "", "Error while trying to find a Policy Server"); ListDestroy(&foundhubs); return -1; case 0: CfOut(cf_reporting, "", "No hubs were found. Exiting."); ListDestroy(&foundhubs); return -1; case 1: CfOut(cf_reporting, "", "Found hub installed on:" "Hostname: %s" "IP Address: %s", ((HostProperties*)foundhubs)->Hostname, ((HostProperties*)foundhubs)->IPAddress); strncpy(POLICY_SERVER, ((HostProperties*)foundhubs)->IPAddress, CF_BUFSIZE); dlclose(avahi_handle); break; default: CfOut(cf_reporting, "", "Found more than one hub registered in the network.\n" "Please bootstrap manually using IP from the list below:"); PrintList(foundhubs); dlclose(avahi_handle); ListDestroy(&foundhubs); return -1; }; ListDestroy(&foundhubs); return 0; }