From acfba6464bd57bdd0549f083f83b12ff9909337f Mon Sep 17 00:00:00 2001 From: Hector Martin Date: Wed, 19 Aug 2009 01:39:16 +0200 Subject: Remove trailing whitespace errors --- usbmuxd/client.c | 20 +++++++++---------- usbmuxd/device.c | 56 ++++++++++++++++++++++++++--------------------------- usbmuxd/main.c | 8 ++++---- usbmuxd/usb-linux.c | 20 +++++++++---------- 4 files changed, 52 insertions(+), 52 deletions(-) diff --git a/usbmuxd/client.c b/usbmuxd/client.c index b33d892..7a3160f 100644 --- a/usbmuxd/client.c +++ b/usbmuxd/client.c @@ -105,11 +105,11 @@ int client_accept(int listenfd) usbmuxd_log(LL_ERROR, "accept() failed (%s)", strerror(errno)); return cfd; } - + struct mux_client *client; client = malloc(sizeof(struct mux_client)); memset(client, 0, sizeof(struct mux_client)); - + client->fd = cfd; client->ob_buf = malloc(REPLY_BUF_SIZE); client->ob_size = 0; @@ -119,9 +119,9 @@ int client_accept(int listenfd) client->ib_capacity = CMD_BUF_SIZE; client->state = CLIENT_COMMAND; client->events = POLLIN; - + collection_add(&client_list, client); - + usbmuxd_log(LL_INFO, "New client on fd %d", client->fd); return client->fd; } @@ -216,14 +216,14 @@ static int start_listen(struct mux_client *client) struct device_info *devs; struct device_info *dev; int count, i; - + client->state = CLIENT_LISTEN; count = device_get_count(); if(!count) return 0; devs = malloc(sizeof(struct device_info) * count); count = device_get_list(devs); - + // going to need a larger buffer for many devices int needed_buffer = count * (sizeof(struct client_msg_dev) + sizeof(struct client_header)) + REPLY_BUF_SIZE; if(client->ob_capacity < needed_buffer) { @@ -246,7 +246,7 @@ static int client_command(struct mux_client *client, struct client_header *hdr, { int res; usbmuxd_log(LL_DEBUG, "Client command in fd %d len %d ver %d msg %d tag %d", client->fd, hdr->length, hdr->version, hdr->message, hdr->tag); - + if(client->state != CLIENT_COMMAND) { usbmuxd_log(LL_ERROR, "Client %d command received in the wrong state", client->fd); if(send_result(client, hdr->tag, RESULT_BADCOMMAND) < 0) @@ -254,7 +254,7 @@ static int client_command(struct mux_client *client, struct client_header *hdr, client_close(client); return -1; } - + struct client_msg_connect *ch; switch(hdr->message) { case MESSAGE_LISTEN: @@ -392,7 +392,7 @@ void client_process(int fd, short events) process_send(client); } } - + } void client_device_add(struct device_info *dev) @@ -401,7 +401,7 @@ void client_device_add(struct device_info *dev) FOREACH(struct mux_client *client, &client_list) { if(client->state == CLIENT_LISTEN) notify_device(client, dev); - } ENDFOREACH + } ENDFOREACH } void client_device_remove(int device_id) { diff --git a/usbmuxd/device.c b/usbmuxd/device.c index cddf718..3a5883c 100644 --- a/usbmuxd/device.c +++ b/usbmuxd/device.c @@ -142,7 +142,7 @@ static int send_packet(struct mux_device *dev, enum mux_protocol proto, void *he unsigned char *buffer; int hdrlen; int res; - + switch(proto) { case MUX_PROTO_VERSION: hdrlen = sizeof(struct version_header); @@ -155,14 +155,14 @@ static int send_packet(struct mux_device *dev, enum mux_protocol proto, void *he return -1; } usbmuxd_log(LL_SPEW, "send_packet(%d, 0x%x, %p, %p, %d)", dev->id, proto, header, data, length); - + int total = sizeof(struct mux_header) + hdrlen + length; - + if(total > USB_MTU) { usbmuxd_log(LL_ERROR, "Tried to send packet larger than USB MTU (hdr %d data %d total %d) to device %d", hdrlen, length, total, dev->id); return -1; } - + buffer = malloc(total); struct mux_header *mhdr = (struct mux_header *)buffer; mhdr->protocol = htonl(proto); @@ -170,7 +170,7 @@ static int send_packet(struct mux_device *dev, enum mux_protocol proto, void *he memcpy(buffer + sizeof(struct mux_header), header, hdrlen); if(data && length) memcpy(buffer + sizeof(struct mux_header) + hdrlen, data, length); - + if((res = usb_send(dev->usbdev, buffer, total)) < 0) { usbmuxd_log(LL_ERROR, "usb_send failed while sending packet (len %d) to device %d: %d", total, dev->id, res); free(buffer); @@ -183,7 +183,7 @@ static uint16_t find_sport(struct mux_device *dev) { if(collection_count(&dev->connections) >= 65535) return 0; //insanity - + while(1) { int ok = 1; FOREACH(struct mux_connection *conn, &dev->connections) { @@ -207,7 +207,7 @@ static int send_anon_rst(struct mux_device *dev, uint16_t sport, uint16_t dport, th.th_ack = htonl(ack); th.th_flags = TH_RST; th.th_off = sizeof(th) / 4; - + usbmuxd_log(LL_DEBUG, "[OUT] dev=%d sport=%d dport=%d flags=0x%x", dev->id, sport, dport, th.th_flags); int res = send_packet(dev, MUX_PROTO_TCP, &th, NULL, 0); @@ -225,7 +225,7 @@ static int send_tcp(struct mux_connection *conn, uint8_t flags, const unsigned c th.th_flags = flags; th.th_off = sizeof(th) / 4; th.th_win = htons(conn->tx_win >> 8); - + usbmuxd_log(LL_DEBUG, "[OUT] dev=%d sport=%d dport=%d seq=%d ack=%d flags=0x%x window=%d[%d] len=%d", conn->dev->id, conn->sport, conn->dport, conn->tx_seq, conn->tx_ack, flags, conn->tx_win, conn->tx_win >> 8, length); @@ -278,7 +278,7 @@ int device_start_connect(int device_id, uint16_t dport, struct mux_client *clien usbmuxd_log(LL_WARNING, "Attempted to connect to nonexistent device %d", device_id); return -RESULT_BADDEV; } - + uint16_t sport = find_sport(dev); if(!sport) { usbmuxd_log(LL_WARNING, "Unable to allocate port for device %d", device_id); @@ -288,7 +288,7 @@ int device_start_connect(int device_id, uint16_t dport, struct mux_client *clien struct mux_connection *conn; conn = malloc(sizeof(struct mux_connection)); memset(conn, 0, sizeof(struct mux_connection)); - + conn->dev = dev; conn->client = client; conn->state = CONN_CONNECTING; @@ -301,15 +301,15 @@ int device_start_connect(int device_id, uint16_t dport, struct mux_client *clien conn->rx_recvd = 0; conn->flags = 0; conn->max_payload = USB_MTU - sizeof(struct mux_header) - sizeof(struct tcphdr); - + conn->ob_buf = malloc(CONN_OUTBUF_SIZE); conn->ob_capacity = CONN_OUTBUF_SIZE; conn->ib_buf = malloc(CONN_INBUF_SIZE); conn->ib_capacity = CONN_INBUF_SIZE; conn->ib_size = 0; - + int res; - + res = send_tcp(conn, TH_SYN, NULL, 0); if(res < 0) { usbmuxd_log(LL_ERROR, "Error sending TCP SYN to device %d (%d->%d)", dev->id, sport, dport); @@ -323,12 +323,12 @@ int device_start_connect(int device_id, uint16_t dport, struct mux_client *clien static void update_connection(struct mux_connection *conn) { conn->sendable = conn->rx_win - (conn->tx_seq - conn->rx_ack); - + if(conn->sendable > conn->ob_capacity) conn->sendable = conn->ob_capacity; if(conn->sendable > conn->max_payload) conn->sendable = conn->max_payload; - + if(conn->sendable > 0) conn->events |= POLLIN; else @@ -368,7 +368,7 @@ void device_client_process(int device_id, struct mux_client *client, short event return; } usbmuxd_log(LL_SPEW, "device_client_process (%d)", events); - + int res; int size; if(events & POLLOUT) { @@ -463,7 +463,7 @@ static void device_tcp_input(struct mux_device *dev, struct tcphdr *th, unsigned { usbmuxd_log(LL_DEBUG, "[IN] dev=%d sport=%d dport=%d seq=%d ack=%d flags=0x%x window=%d[%d] len=%d", dev->id, ntohs(th->th_sport), ntohs(th->th_dport), ntohl(th->th_seq), ntohl(th->th_ack), th->th_flags, ntohs(th->th_win) << 8, ntohs(th->th_win), payload_length); - + uint16_t sport = ntohs(th->th_dport); uint16_t dport = ntohs(th->th_sport); struct mux_connection *conn = NULL; @@ -473,7 +473,7 @@ static void device_tcp_input(struct mux_device *dev, struct tcphdr *th, unsigned break; } } ENDFOREACH - + if(!conn) { usbmuxd_log(LL_WARNING, "No connection for device %d incoming packet %d->%d", dev->id, dport, sport); if(!(th->th_flags & TH_RST)) { @@ -482,11 +482,11 @@ static void device_tcp_input(struct mux_device *dev, struct tcphdr *th, unsigned } return; } - + conn->rx_seq = ntohl(th->th_seq); conn->rx_ack = ntohl(th->th_ack); conn->rx_win = ntohs(th->th_win) << 8; - + if(th->th_flags & TH_RST) { char *buf = malloc(payload_length+1); memcpy(buf, payload, payload_length); @@ -496,7 +496,7 @@ static void device_tcp_input(struct mux_device *dev, struct tcphdr *th, unsigned usbmuxd_log(LL_DEBUG, "RST reason: %s", buf); free(buf); } - + if(conn->state == CONN_CONNECTING) { if(th->th_flags != (TH_SYN|TH_ACK)) { if(th->th_flags & TH_RST) @@ -544,10 +544,10 @@ void device_data_input(struct usb_device *usbdev, unsigned char *buffer, int len usbmuxd_log(LL_WARNING, "Cannot find device entry for RX input from USB device %p on location 0x%x", usbdev, usb_get_location(usbdev)); return; } - + if(!length) return; - + usbmuxd_log(LL_SPEW, "Mux data input for device %p: %p len %d", dev, buffer, length); // handle broken up transfers @@ -573,18 +573,18 @@ void device_data_input(struct usb_device *usbdev, unsigned char *buffer, int len return; } } - + struct mux_header *mhdr = (struct mux_header *)buffer; - + if(ntohl(mhdr->length) != length) { usbmuxd_log(LL_ERROR, "Incoming packet size mismatch (dev %d, expected %d, got %d)", dev->id, ntohl(mhdr->length), length); return; } - + struct tcphdr *th; unsigned char *payload; int payload_length; - + switch(ntohl(mhdr->protocol)) { case MUX_PROTO_VERSION: device_version_input(dev, (struct version_header *)(mhdr+1)); @@ -599,7 +599,7 @@ void device_data_input(struct usb_device *usbdev, unsigned char *buffer, int len usbmuxd_log(LL_ERROR, "Incoming packet for device %d has unknown protocol 0x%x)", dev->id, ntohl(mhdr->protocol)); break; } - + } int device_add(struct usb_device *usbdev) diff --git a/usbmuxd/main.c b/usbmuxd/main.c index 182178f..be7451f 100644 --- a/usbmuxd/main.c +++ b/usbmuxd/main.c @@ -126,7 +126,7 @@ int main_loop(int listenfd) { int to, cnt, i, dto; struct fdlist pollfds; - + while(!should_exit) { usbmuxd_log(LL_FLOOD, "main_loop iteration"); to = usb_get_timeout(); @@ -135,16 +135,16 @@ int main_loop(int listenfd) usbmuxd_log(LL_FLOOD, "Device timeout is %d ms", to); if(dto < to) to = dto; - + fdlist_create(&pollfds); fdlist_add(&pollfds, FD_LISTEN, listenfd, POLLIN); usb_get_fds(&pollfds); client_get_fds(&pollfds); usbmuxd_log(LL_FLOOD, "fd count is %d", pollfds.count); - + cnt = poll(pollfds.fds, pollfds.count, to); usbmuxd_log(LL_FLOOD, "poll() returned %d", cnt); - + if(cnt == -1) { if(errno == EINTR && should_exit) { usbmuxd_log(LL_INFO, "event processing interrupted"); diff --git a/usbmuxd/usb-linux.c b/usbmuxd/usb-linux.c index a5fc6a0..6e99a95 100644 --- a/usbmuxd/usb-linux.c +++ b/usbmuxd/usb-linux.c @@ -58,7 +58,7 @@ static void usb_disconnect(struct usb_device *dev) if(!dev->dev) { return; } - + // kill the rx xfer and tx xfers and try to make sure the callbacks get called before we free the device if(dev->rx_xfer) { usbmuxd_log(LL_DEBUG, "usb_disconnect: cancelling RX xfer"); @@ -72,7 +72,7 @@ static void usb_disconnect(struct usb_device *dev) while(dev->rx_xfer || collection_count(&dev->tx_xfers)) { struct timeval tv; int res; - + tv.tv_sec = 0; tv.tv_usec = 1000; if((res = libusb_handle_events_timeout(NULL, &tv)) < 0) { @@ -218,7 +218,7 @@ static int usb_discover(void) int cnt, i, res; int valid_count = 0; libusb_device **devs; - + cnt = libusb_get_device_list(NULL, &devs); if(cnt < 0) { usbmuxd_log(LL_WARNING, "Could not get device list: %d", cnt); @@ -309,7 +309,7 @@ static int usb_discover(void) collection_init(&usbdev->tx_xfers); collection_add(&device_list, usbdev); - + if(device_add(usbdev) < 0) { usb_disconnect(usbdev); continue; @@ -327,14 +327,14 @@ static int usb_discover(void) usb_disconnect(usbdev); } } ENDFOREACH - + libusb_free_device_list(devs, 1); - + gettimeofday(&next_dev_poll_time, NULL); next_dev_poll_time.tv_usec += DEVICE_POLL_TIME * 1000; next_dev_poll_time.tv_sec += next_dev_poll_time.tv_usec / 1000000; next_dev_poll_time.tv_usec = next_dev_poll_time.tv_usec % 1000000; - + return valid_count; } @@ -477,7 +477,7 @@ int usb_init(void) { int res; usbmuxd_log(LL_DEBUG, "usb_init for linux / libusb 1.0"); - + devlist_failures = 0; res = libusb_init(NULL); //libusb_set_debug(NULL, 3); @@ -485,9 +485,9 @@ int usb_init(void) usbmuxd_log(LL_FATAL, "libusb_init failed: %d", res); return -1; } - + collection_init(&device_list); - + return usb_discover(); } -- cgit v1.1-32-gdbae