int remove_temporary_rules(
        const char *ip,
        short unsigned int port,
        connection_t **connection_list
) {
    if (*connection_list == NULL) {
        ERR("connections list is not initialized yet\n");
        return -1;
    }

    connection_t *current;
    current = *connection_list;

    int ctr = -1;

    while (current != NULL) {

        if (current->request_endpoint && match_endpoint(current->request_endpoint, ip, port) == 0) {
            remove_temporary_streams(current->request_endpoint);
            ctr++;
        }

        if (current->response_endpoint && match_endpoint(current->response_endpoint, ip, port) == 0) {
            remove_temporary_streams(current->response_endpoint);
            ctr++;
        }

        current = current->next;
    }

    return ctr;
}
Beispiel #2
0
/**
 * usb_find_common_endpoints_reverse() -- look up common endpoint descriptors
 * @alt:	alternate setting to search
 * @bulk_in:	pointer to descriptor pointer, or NULL
 * @bulk_out:	pointer to descriptor pointer, or NULL
 * @int_in:	pointer to descriptor pointer, or NULL
 * @int_out:	pointer to descriptor pointer, or NULL
 *
 * Search the alternate setting's endpoint descriptors for the last bulk-in,
 * bulk-out, interrupt-in and interrupt-out endpoints and return them in the
 * provided pointers (unless they are NULL).
 *
 * If a requested endpoint is not found, the corresponding pointer is set to
 * NULL.
 *
 * Return: Zero if all requested descriptors were found, or -ENXIO otherwise.
 */
int usb_find_common_endpoints_reverse(struct usb_host_interface *alt,
		struct usb_endpoint_descriptor **bulk_in,
		struct usb_endpoint_descriptor **bulk_out,
		struct usb_endpoint_descriptor **int_in,
		struct usb_endpoint_descriptor **int_out)
{
	struct usb_endpoint_descriptor *epd;
	int i;

	if (bulk_in)
		*bulk_in = NULL;
	if (bulk_out)
		*bulk_out = NULL;
	if (int_in)
		*int_in = NULL;
	if (int_out)
		*int_out = NULL;

	for (i = alt->desc.bNumEndpoints - 1; i >= 0; --i) {
		epd = &alt->endpoint[i].desc;

		if (match_endpoint(epd, bulk_in, bulk_out, int_in, int_out))
			return 0;
	}

	return -ENXIO;
}
int change_socket_for_endpoints(
        const char *ip,
        short unsigned int port,
        struct socket_info *new_socket,
        connection_t **connection_list
) {
    if (*connection_list == NULL) {
        ERR("connections list is not initialized yet\n");
        return -1;
    }

    connection_t *current;
    current = *connection_list;

    int ctr = -1;

    while (current != NULL) {

        if (current->request_endpoint && match_endpoint(current->request_endpoint, ip, port) == 0) {
            lock_endpoint(current->request_endpoint);
            current->request_endpoint->socket = new_socket;
            unlock_endpoint(current->request_endpoint);

            ctr++;
        }

        if (current->response_endpoint && match_endpoint(current->response_endpoint, ip, port) == 0) {
            lock_endpoint(current->response_endpoint);
            current->response_endpoint->socket = new_socket;
            unlock_endpoint(current->response_endpoint);

            ctr++;
        }

        current = current->next;
    }

    return ctr;
}