Ejemplo n.º 1
0
void
discovery(struct connection *conn)
{
	struct pdu *request, *response;
	struct keys *request_keys, *response_keys;
	int i;

	log_debugx("beginning discovery session");
	request = text_new_request(conn);
	request_keys = keys_new();
	keys_add(request_keys, "SendTargets", "All");
	keys_save(request_keys, request);
	keys_delete(request_keys);
	request_keys = NULL;
	pdu_send(request);
	pdu_delete(request);
	request = NULL;

	log_debugx("waiting for Text Response");
	response = text_receive(conn);
	response_keys = keys_new();
	keys_load(response_keys, response);
	for (i = 0; i < KEYS_MAX; i++) {
		if (response_keys->keys_names[i] == NULL)
			break;

		if (strcmp(response_keys->keys_names[i], "TargetName") != 0)
			continue;

		log_debugx("adding target %s", response_keys->keys_values[i]);
		/*
		 * XXX: Validate the target name?
		 */
		kernel_add(conn, response_keys->keys_values[i]);
	}
	keys_delete(response_keys);
	pdu_delete(response);

	log_debugx("removing temporary discovery session");
	kernel_remove(conn);

	log_debugx("discovery done; logging out");
	request = logout_new_request(conn);
	pdu_send(request);
	pdu_delete(request);
	request = NULL;

	log_debugx("waiting for Logout Response");
	response = logout_receive(conn);
	pdu_delete(response);

	log_debugx("discovery session done");
}
Ejemplo n.º 2
0
void
keys_add_int(struct keys *keys, const char *name, int value)
{
	char *str;
	int ret;

	ret = asprintf(&str, "%d", value);
	if (ret <= 0)
		log_err(1, "asprintf");

	keys_add(keys, name, str);
	free(str);
}