[Spice-devel] [PATCH spice-server 20/30] Update style
Frediano Ziglio
fziglio at redhat.com
Mon Nov 21 12:52:07 UTC 2016
Mostly space changes
---
server/reds-stream.c | 3 +-
server/reds.c | 2 +-
server/websocket.c | 100 +++++++++++++++++++++++++++------------------------
3 files changed, 56 insertions(+), 49 deletions(-)
diff --git a/server/reds-stream.c b/server/reds-stream.c
index 4dd6167..d11449c 100644
--- a/server/reds-stream.c
+++ b/server/reds-stream.c
@@ -1170,8 +1170,9 @@ gboolean reds_stream_is_websocket(RedsStream *stream, const void *buf, size_t le
memcpy(rbuf, buf, len);
rc = stream->priv->read(stream, rbuf + len, sizeof(rbuf) - len - 1);
- if (rc <= 0)
+ if (rc <= 0) {
return FALSE;
+ }
len += rc;
rbuf[len] = 0;
diff --git a/server/reds.c b/server/reds.c
index f2ef5e4..20281d8 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -2268,7 +2268,7 @@ static void reds_handle_read_header_done(void *opaque)
So we may as well read a SpiceLinkHeader's worth of data, and if it's
clear that a WebSocket connection was requested, we switch
before proceeding further. */
- if (reds_stream_is_websocket(link->stream, (guchar *) header, sizeof(*header))) {
+ if (reds_stream_is_websocket(link->stream, header, sizeof(*header))) {
reds_handle_new_link(link);
return;
}
diff --git a/server/websocket.c b/server/websocket.c
index 1f6151c..f5b3aaa 100644
--- a/server/websocket.c
+++ b/server/websocket.c
@@ -84,9 +84,9 @@ static void websocket_ack_close(void *opaque, websocket_write_cb_t write_cb);
/* Perform a case insensitive search for needle in haystack.
If found, return a pointer to the byte after the end of needle.
Otherwise, return NULL */
-static gchar *find_str(gchar *haystack, const char *needle)
+static const gchar *find_str(const gchar *haystack, const char *needle)
{
- char *s = strcasestr(haystack, needle);
+ const char *s = strcasestr(haystack, needle);
if (s) {
return s + strlen(needle);
@@ -106,21 +106,22 @@ static guint64 extract_length(const guint8 *buf, int *used)
(*used)++;
- switch(outlen) {
- case LENGTH_64BIT:
- *used += 8;
- outlen = 0;
- for (i = 56; i >= 0; i -= 8)
- outlen |= (*buf++) << i;
- break;
+ switch (outlen) {
+ case LENGTH_64BIT:
+ *used += 8;
+ outlen = 0;
+ for (i = 56; i >= 0; i -= 8) {
+ outlen |= (*buf++) << i;
+ }
+ break;
- case LENGTH_16BIT:
- *used += 2;
- outlen = ((*buf) << 8) | *(buf + 1);
- break;
+ case LENGTH_16BIT:
+ *used += 2;
+ outlen = ((*buf) << 8) | *(buf + 1);
+ break;
- default:
- break;
+ default:
+ break;
}
return outlen;
}
@@ -128,16 +129,17 @@ static guint64 extract_length(const guint8 *buf, int *used)
static int frame_bytes_needed(websocket_frame_t *frame)
{
int needed = 2;
- if (frame->header_pos < needed)
+ if (frame->header_pos < needed) {
return needed - frame->header_pos;
+ }
- switch(frame->header[1] & LENGTH_MASK) {
- case LENGTH_64BIT:
- needed += 8;
- break;
- case LENGTH_16BIT:
- needed += 2;
- break;
+ switch (frame->header[1] & LENGTH_MASK) {
+ case LENGTH_64BIT:
+ needed += 8;
+ break;
+ case LENGTH_16BIT:
+ needed += 2;
+ break;
}
if (frame->header[1] & MASK_FLAG) {
@@ -158,8 +160,8 @@ static gchar *generate_reply_key(gchar *buf)
gchar *b64 = NULL;
guint8 *sha1;
gsize sha1_size;
- gchar *key;
- gchar *p;
+ const gchar *key;
+ const gchar *p;
gchar *k;
key = find_str(buf, "\nSec-WebSocket-Key:");
@@ -201,8 +203,9 @@ static void websocket_get_frame_header(websocket_frame_t *frame)
int fin;
int used = 0;
- if (frame_bytes_needed(frame) > 0)
+ if (frame_bytes_needed(frame) > 0) {
return;
+ }
fin = frame->header[0] & FIN_FLAG;
frame->type = frame->header[0] & TYPE_MASK;
@@ -213,8 +216,9 @@ static void websocket_get_frame_header(websocket_frame_t *frame)
/* This is a Spice specific optimization. We don't really
care about assembling frames fully, so we treat
a frame in process as a finished frame and pass it along. */
- if (!fin && frame->type == 0)
+ if (!fin && frame->type == 0) {
frame->type = BINARY_FRAME;
+ }
frame->expected_len = extract_length(frame->header + used, &used);
@@ -232,8 +236,9 @@ static int relay_data(guint8* buf, size_t size, websocket_frame_t *frame)
int n = MIN(size, frame->expected_len - frame->relayed);
if (frame->masked) {
- for (i = 0; i < n; i++, frame->relayed++)
+ for (i = 0; i < n; i++, frame->relayed++) {
*buf++ ^= frame->mask[frame->relayed % 4];
+ }
}
return n;
@@ -253,12 +258,12 @@ int websocket_read(RedsWebSocket *ws, guchar *buf, size_t size)
}
while (size > 0) {
- if (! frame->frame_ready) {
+ if (!frame->frame_ready) {
rc = read_cb(ws->raw_stream, frame->header + frame->header_pos, frame_bytes_needed(frame));
if (rc <= 0) {
- if (n > 0 && rc == -1 && (errno == EINTR || errno == EAGAIN))
+ if (n > 0 && rc == -1 && (errno == EINTR || errno == EAGAIN)) {
return n;
-
+ }
if (rc == 0) {
ws->closed = TRUE;
}
@@ -275,9 +280,9 @@ int websocket_read(RedsWebSocket *ws, guchar *buf, size_t size)
} else if (frame->type == BINARY_FRAME) {
rc = read_cb(opaque, buf, MIN(size, frame->expected_len - frame->relayed));
if (rc <= 0) {
- if (n > 0 && rc == -1 && (errno == EINTR || errno == EAGAIN))
+ if (n > 0 && rc == -1 && (errno == EINTR || errno == EAGAIN)) {
return n;
-
+ }
if (rc == 0) {
ws->closed = TRUE;
}
@@ -288,9 +293,9 @@ int websocket_read(RedsWebSocket *ws, guchar *buf, size_t size)
n += rc;
buf += rc;
size -= rc;
- if (frame->relayed >= frame->expected_len)
+ if (frame->relayed >= frame->expected_len) {
websocket_clear_frame(frame);
-
+ }
} else {
/* TODO - We don't handle PING at this point */
spice_warning("Unexpected WebSocket frame.type %d. Failure now likely.", frame->type);
@@ -379,12 +384,12 @@ int websocket_writev(RedsWebSocket *ws, const struct iovec *iov, int iovcnt)
if (*remainder > 0) {
constrain_iov((struct iovec *) iov, iovcnt, &iov_out, &iov_out_cnt, *remainder);
rc = writev_cb(opaque, iov_out, iov_out_cnt);
- if (iov_out != iov)
+ if (iov_out != iov) {
free(iov_out);
-
- if (rc <= 0)
+ }
+ if (rc <= 0) {
return rc;
-
+ }
*remainder -= rc;
return rc;
}
@@ -403,9 +408,9 @@ int websocket_writev(RedsWebSocket *ws, const struct iovec *iov, int iovcnt)
iov_out[0].iov_base = header;
rc = writev_cb(opaque, iov_out, iov_out_cnt);
free(iov_out);
- if (rc <= 0)
+ if (rc <= 0) {
return rc;
-
+ }
rc -= header_len;
spice_assert(rc >= 0);
@@ -435,9 +440,9 @@ int websocket_write(RedsWebSocket *ws, const void *buf, size_t len)
if (*remainder == 0) {
header_len = fill_header(header, len);
rc = write_cb(opaque, header, header_len);
- if (rc <= 0)
+ if (rc <= 0) {
return rc;
-
+ }
if (rc != header_len) {
/* TODO - In theory, we can handle this case. In practice,
it does not occur, and does not seem to be worth
@@ -445,15 +450,16 @@ int websocket_write(RedsWebSocket *ws, const void *buf, size_t len)
errno = EPIPE;
return -1;
}
- }
- else
+ } else {
len = MIN(*remainder, len);
+ }
rc = write_cb(opaque, buf, len);
- if (rc <= 0)
+ if (rc <= 0) {
*remainder = len;
- else
+ } else {
*remainder = len - rc;
+ }
return rc;
}
--
2.7.4
More information about the Spice-devel
mailing list