From 97f7249e60c0e19fe5f485b8681c49ad2d243231 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Wed, 23 Nov 2011 16:08:33 -0800 Subject: [PATCH] Renamed private members, adding __ (double underscore) prefix. --- libguac/include/client.h | 8 ++-- libguac/include/guacio.h | 25 +++++------- libguac/include/protocol.h | 4 +- libguac/src/client.c | 54 ++++++++++++------------- libguac/src/guacio.c | 81 +++++++++++++++++--------------------- libguac/src/protocol.c | 46 +++++++++++----------- 6 files changed, 103 insertions(+), 115 deletions(-) diff --git a/libguac/include/client.h b/libguac/include/client.h index 8fddd851..fbe00a0b 100644 --- a/libguac/include/client.h +++ b/libguac/include/client.h @@ -124,19 +124,19 @@ struct guac_client { /** * The index of the next available buffer. */ - int next_buffer_index; + int __next_buffer_index; /** * The head pointer of the list of all available (allocated but not used) * buffers. */ - guac_layer* available_buffers; + guac_layer* __available_buffers; /** * The head pointer of the list of all allocated layers, regardless of use * status. */ - guac_layer* all_layers; + guac_layer* __all_layers; /** * The time (in milliseconds) of receipt of the last sync message from @@ -153,7 +153,7 @@ struct guac_client { /** * Reference to dlopen'd client plugin. */ - void* client_plugin_handle; + void* __client_plugin_handle; /** * Arbitrary reference to proxy client-specific data. Implementors of a diff --git a/libguac/include/guacio.h b/libguac/include/guacio.h index 9271c792..49055ba7 100644 --- a/libguac/include/guacio.h +++ b/libguac/include/guacio.h @@ -62,62 +62,57 @@ typedef struct GUACIO { /** * The number of bytes present in the base64 "ready" buffer. */ - int ready; + int __ready; /** * The base64 "ready" buffer. Once this buffer is filled, base64 data is * flushed to the main write buffer. */ - int ready_buf[3]; + int __ready_buf[3]; /** * The number of bytes currently in the main write buffer. */ - int written; - - /** - * The number of bytes written total, since this GUACIO was opened. - */ - int total_written; + int __written; /** * The main write buffer. Bytes written go here before being flushed * to the open file descriptor. */ - char out_buf[8192]; + char __out_buf[8192]; /** * The current location of parsing within the instruction buffer. */ - int instructionbuf_parse_start; + int __instructionbuf_parse_start; /** * The current size of the instruction buffer. */ - int instructionbuf_size; + int __instructionbuf_size; /** * The number of bytes currently in the instruction buffer. */ - int instructionbuf_used_length; + int __instructionbuf_used_length; /** * The instruction buffer. This is essentially the input buffer, * provided as a convenience to be used to buffer instructions until * those instructions are complete and ready to be parsed. */ - char* instructionbuf; + char* __instructionbuf; /** * The number of elements parsed so far. */ - int instructionbuf_elementc; + int __instructionbuf_elementc; /** * Array of pointers into the instruction buffer, where each pointer * points to the start of the corresponding element. */ - char* instructionbuf_elementv[64]; + char* __instructionbuf_elementv[64]; } GUACIO; diff --git a/libguac/include/protocol.h b/libguac/include/protocol.h index 9339ef50..f8bdf0df 100644 --- a/libguac/include/protocol.h +++ b/libguac/include/protocol.h @@ -109,13 +109,13 @@ struct guac_layer { /** * The next allocated layer in the list of all layers. */ - guac_layer* next; + guac_layer* __next; /** * The next available (unused) layer in the list of * allocated but free'd layers. */ - guac_layer* next_available; + guac_layer* __next_available; }; diff --git a/libguac/src/client.c b/libguac/src/client.c index cfe59813..96817eba 100644 --- a/libguac/src/client.c +++ b/libguac/src/client.c @@ -51,8 +51,8 @@ guac_layer __GUAC_DEFAULT_LAYER = { .index = 0, - .next = NULL, - .next_available = NULL + .__next = NULL, + .__next_available = NULL }; const guac_layer* GUAC_DEFAULT_LAYER = &__GUAC_DEFAULT_LAYER; @@ -68,10 +68,10 @@ guac_client* __guac_alloc_client(GUACIO* io) { client->last_received_timestamp = client->last_sent_timestamp = guac_current_timestamp(); client->state = RUNNING; - client->all_layers = NULL; - client->available_buffers = NULL; + client->__all_layers = NULL; + client->__available_buffers = NULL; - client->next_buffer_index = -1; + client->__next_buffer_index = -1; return client; } @@ -83,9 +83,9 @@ guac_layer* guac_client_alloc_layer(guac_client* client, int index) { /* Init new layer */ allocd_layer = malloc(sizeof(guac_layer)); - /* Add to all_layers list */ - allocd_layer->next = client->all_layers; - client->all_layers = allocd_layer; + /* Add to __all_layers list */ + allocd_layer->__next = client->__all_layers; + client->__all_layers = allocd_layer; allocd_layer->index = index; return allocd_layer; @@ -97,22 +97,22 @@ guac_layer* guac_client_alloc_buffer(guac_client* client) { guac_layer* allocd_layer; /* If available layers, pop off first available buffer */ - if (client->available_buffers != NULL) { - allocd_layer = client->available_buffers; - client->available_buffers = client->available_buffers->next_available; - allocd_layer->next_available = NULL; + if (client->__available_buffers != NULL) { + allocd_layer = client->__available_buffers; + client->__available_buffers = client->__available_buffers->__next_available; + allocd_layer->__next_available = NULL; } - /* If no available buffer, allocate new buffer, add to all_layers list */ + /* If no available buffer, allocate new buffer, add to __all_layers list */ else { /* Init new layer */ allocd_layer = malloc(sizeof(guac_layer)); - allocd_layer->index = client->next_buffer_index--; + allocd_layer->index = client->__next_buffer_index--; - /* Add to all_layers list */ - allocd_layer->next = client->all_layers; - client->all_layers = allocd_layer; + /* Add to __all_layers list */ + allocd_layer->__next = client->__all_layers; + client->__all_layers = allocd_layer; } @@ -123,8 +123,8 @@ guac_layer* guac_client_alloc_buffer(guac_client* client) { void guac_client_free_buffer(guac_client* client, guac_layer* layer) { /* Add layer to pool of available buffers */ - layer->next_available = client->available_buffers; - client->available_buffers = layer; + layer->__next_available = client->__available_buffers; + client->__available_buffers = layer; } @@ -193,8 +193,8 @@ guac_client* guac_get_client(int client_fd, int usec_timeout) { client = __guac_alloc_client(io); /* Load client plugin */ - client->client_plugin_handle = dlopen(protocol_lib, RTLD_LAZY); - if (!(client->client_plugin_handle)) { + client->__client_plugin_handle = dlopen(protocol_lib, RTLD_LAZY); + if (!(client->__client_plugin_handle)) { guac_log_error("Could not open client plugin for protocol \"%s\": %s\n", protocol, dlerror()); guac_send_error(io, "Could not load server-side client plugin."); guac_flush(io); @@ -206,7 +206,7 @@ guac_client* guac_get_client(int client_fd, int usec_timeout) { dlerror(); /* Clear errors */ /* Get init function */ - alias.obj = dlsym(client->client_plugin_handle, "guac_client_init"); + alias.obj = dlsym(client->__client_plugin_handle, "guac_client_init"); if ((error = dlerror()) != NULL) { guac_log_error("Could not get guac_client_init in plugin: %s\n", error); @@ -218,7 +218,7 @@ guac_client* guac_get_client(int client_fd, int usec_timeout) { } /* Get usage strig */ - client_args = (const char**) dlsym(client->client_plugin_handle, "GUAC_CLIENT_ARGS"); + client_args = (const char**) dlsym(client->__client_plugin_handle, "GUAC_CLIENT_ARGS"); if ((error = dlerror()) != NULL) { guac_log_error("Could not get GUAC_CLIENT_ARGS in plugin: %s\n", error); @@ -312,16 +312,16 @@ void guac_free_client(guac_client* client) { guac_close(client->io); /* Unload client plugin */ - if (dlclose(client->client_plugin_handle)) { + if (dlclose(client->__client_plugin_handle)) { guac_log_error("Could not close client plugin while unloading client: %s", dlerror()); } /* Free all layers */ - while (client->all_layers != NULL) { + while (client->__all_layers != NULL) { /* Get layer, update layer pool head */ - guac_layer* layer = client->all_layers; - client->all_layers = layer->next; + guac_layer* layer = client->__all_layers; + client->__all_layers = layer->__next; /* Free layer */ free(layer); diff --git a/libguac/src/guacio.c b/libguac/src/guacio.c index b59a157c..da0b9e00 100644 --- a/libguac/src/guacio.c +++ b/libguac/src/guacio.c @@ -72,26 +72,25 @@ GUACIO* guac_open(int fd) { return NULL; } - io->ready = 0; - io->written = 0; - io->total_written = 0; + io->__ready = 0; + io->__written = 0; io->fd = fd; /* Allocate instruction buffer */ - io->instructionbuf_size = 1024; - io->instructionbuf = malloc(io->instructionbuf_size); + io->__instructionbuf_size = 1024; + io->__instructionbuf = malloc(io->__instructionbuf_size); /* If no memory available, return with error */ - if (io->instructionbuf == NULL) { + if (io->__instructionbuf == NULL) { guac_error = GUAC_STATUS_NO_MEMORY; free(io); return NULL; } /* Init members */ - io->instructionbuf_used_length = 0; - io->instructionbuf_parse_start = 0; - io->instructionbuf_elementc = 0; + io->__instructionbuf_used_length = 0; + io->__instructionbuf_parse_start = 0; + io->__instructionbuf_elementc = 0; return io; @@ -99,7 +98,7 @@ GUACIO* guac_open(int fd) { void guac_close(GUACIO* io) { guac_flush(io); - free(io->instructionbuf); + free(io->__instructionbuf); free(io); } @@ -151,24 +150,23 @@ ssize_t guac_write_int(GUACIO* io, int64_t i) { ssize_t guac_write_string(GUACIO* io, const char* str) { - char* out_buf = io->out_buf; + char* __out_buf = io->__out_buf; int retval; for (; *str != '\0'; str++) { - out_buf[io->written++] = *str; - io->total_written++; + __out_buf[io->__written++] = *str; /* Flush when necessary, return on error */ - if (io->written > 8188 /* sizeof(out_buf) - 4 */) { + if (io->__written > 8188 /* sizeof(__out_buf) - 4 */) { - retval = __guac_write(io, out_buf, io->written); + retval = __guac_write(io, __out_buf, io->__written); if (retval < 0) return retval; - io->written = 0; + io->__written = 0; } } @@ -179,45 +177,40 @@ ssize_t guac_write_string(GUACIO* io, const char* str) { ssize_t __guac_write_base64_triplet(GUACIO* io, int a, int b, int c) { - char* out_buf = io->out_buf; + char* __out_buf = io->__out_buf; int retval; /* Byte 1 */ - out_buf[io->written++] = __GUACIO_BASE64_CHARACTERS[(a & 0xFC) >> 2]; /* [AAAAAA]AABBBB BBBBCC CCCCCC */ - io->total_written++; + __out_buf[io->__written++] = __GUACIO_BASE64_CHARACTERS[(a & 0xFC) >> 2]; /* [AAAAAA]AABBBB BBBBCC CCCCCC */ if (b >= 0) { - out_buf[io->written++] = __GUACIO_BASE64_CHARACTERS[((a & 0x03) << 4) | ((b & 0xF0) >> 4)]; /* AAAAAA[AABBBB]BBBBCC CCCCCC */ - io->total_written++; + __out_buf[io->__written++] = __GUACIO_BASE64_CHARACTERS[((a & 0x03) << 4) | ((b & 0xF0) >> 4)]; /* AAAAAA[AABBBB]BBBBCC CCCCCC */ if (c >= 0) { - out_buf[io->written++] = __GUACIO_BASE64_CHARACTERS[((b & 0x0F) << 2) | ((c & 0xC0) >> 6)]; /* AAAAAA AABBBB[BBBBCC]CCCCCC */ - out_buf[io->written++] = __GUACIO_BASE64_CHARACTERS[c & 0x3F]; /* AAAAAA AABBBB BBBBCC[CCCCCC] */ - io->total_written += 2; + __out_buf[io->__written++] = __GUACIO_BASE64_CHARACTERS[((b & 0x0F) << 2) | ((c & 0xC0) >> 6)]; /* AAAAAA AABBBB[BBBBCC]CCCCCC */ + __out_buf[io->__written++] = __GUACIO_BASE64_CHARACTERS[c & 0x3F]; /* AAAAAA AABBBB BBBBCC[CCCCCC] */ } else { - out_buf[io->written++] = __GUACIO_BASE64_CHARACTERS[((b & 0x0F) << 2)]; /* AAAAAA AABBBB[BBBB--]------ */ - out_buf[io->written++] = '='; /* AAAAAA AABBBB BBBB--[------] */ - io->total_written += 2; + __out_buf[io->__written++] = __GUACIO_BASE64_CHARACTERS[((b & 0x0F) << 2)]; /* AAAAAA AABBBB[BBBB--]------ */ + __out_buf[io->__written++] = '='; /* AAAAAA AABBBB BBBB--[------] */ } } else { - out_buf[io->written++] = __GUACIO_BASE64_CHARACTERS[((a & 0x03) << 4)]; /* AAAAAA[AA----]------ ------ */ - out_buf[io->written++] = '='; /* AAAAAA AA----[------]------ */ - out_buf[io->written++] = '='; /* AAAAAA AA---- ------[------] */ - io->total_written += 3; + __out_buf[io->__written++] = __GUACIO_BASE64_CHARACTERS[((a & 0x03) << 4)]; /* AAAAAA[AA----]------ ------ */ + __out_buf[io->__written++] = '='; /* AAAAAA AA----[------]------ */ + __out_buf[io->__written++] = '='; /* AAAAAA AA---- ------[------] */ } - /* At this point, 4 bytes have been io->written */ + /* At this point, 4 bytes have been io->__written */ /* Flush when necessary, return on error */ - if (io->written > 8188 /* sizeof(out_buf) - 4 */) { - retval = __guac_write(io, out_buf, io->written); + if (io->__written > 8188 /* sizeof(__out_buf) - 4 */) { + retval = __guac_write(io, __out_buf, io->__written); if (retval < 0) return retval; - io->written = 0; + io->__written = 0; } if (b < 0) @@ -232,19 +225,19 @@ ssize_t __guac_write_base64_triplet(GUACIO* io, int a, int b, int c) { ssize_t __guac_write_base64_byte(GUACIO* io, char buf) { - int* ready_buf = io->ready_buf; + int* __ready_buf = io->__ready_buf; int retval; - ready_buf[io->ready++] = buf & 0xFF; + __ready_buf[io->__ready++] = buf & 0xFF; /* Flush triplet */ - if (io->ready == 3) { - retval = __guac_write_base64_triplet(io, ready_buf[0], ready_buf[1], ready_buf[2]); + if (io->__ready == 3) { + retval = __guac_write_base64_triplet(io, __ready_buf[0], __ready_buf[1], __ready_buf[2]); if (retval < 0) return retval; - io->ready = 0; + io->__ready = 0; } return 1; @@ -274,12 +267,12 @@ ssize_t guac_flush(GUACIO* io) { int retval; /* Flush remaining bytes in buffer */ - if (io->written > 0) { - retval = __guac_write(io, io->out_buf, io->written); + if (io->__written > 0) { + retval = __guac_write(io, io->__out_buf, io->__written); if (retval < 0) return retval; - io->written = 0; + io->__written = 0; } return 0; @@ -291,7 +284,7 @@ ssize_t guac_flush_base64(GUACIO* io) { int retval; /* Flush triplet to output buffer */ - while (io->ready > 0) { + while (io->__ready > 0) { retval = __guac_write_base64_byte(io, -1); if (retval < 0) return retval; diff --git a/libguac/src/protocol.c b/libguac/src/protocol.c index fcebc1ce..d7786937 100644 --- a/libguac/src/protocol.c +++ b/libguac/src/protocol.c @@ -328,27 +328,27 @@ int guac_send_cursor(GUACIO* io, int x, int y, cairo_surface_t* surface) { } -int __guac_fill_instructionbuf(GUACIO* io) { +int __guac_fill___instructionbuf(GUACIO* io) { int retval; /* Attempt to fill buffer */ retval = recv( io->fd, - io->instructionbuf + io->instructionbuf_used_length, - io->instructionbuf_size - io->instructionbuf_used_length, + io->__instructionbuf + io->__instructionbuf_used_length, + io->__instructionbuf_size - io->__instructionbuf_used_length, 0 ); if (retval < 0) return retval; - io->instructionbuf_used_length += retval; + io->__instructionbuf_used_length += retval; /* Expand buffer if necessary */ - if (io->instructionbuf_used_length > io->instructionbuf_size / 2) { - io->instructionbuf_size *= 2; - io->instructionbuf = realloc(io->instructionbuf, io->instructionbuf_size); + if (io->__instructionbuf_used_length > io->__instructionbuf_size / 2) { + io->__instructionbuf_size *= 2; + io->__instructionbuf = realloc(io->__instructionbuf, io->__instructionbuf_size); } return retval; @@ -360,7 +360,7 @@ int guac_read_instruction(GUACIO* io, int usec_timeout, guac_instruction* parsed_instruction) { int retval; - int i = io->instructionbuf_parse_start; + int i = io->__instructionbuf_parse_start; /* Loop until a instruction is read */ for (;;) { @@ -369,10 +369,10 @@ int guac_read_instruction(GUACIO* io, int usec_timeout, int element_length = 0; /* Parse instruction in buffe */ - while (i < io->instructionbuf_used_length) { + while (i < io->__instructionbuf_used_length) { /* Read character from buffer */ - char c = io->instructionbuf[i++]; + char c = io->__instructionbuf[i++]; /* If digit, calculate element length */ if (c >= '0' && c <= '9') @@ -382,10 +382,10 @@ int guac_read_instruction(GUACIO* io, int usec_timeout, else if (c == '.') { /* Verify element is fully read */ - if (i + element_length < io->instructionbuf_used_length) { + if (i + element_length < io->__instructionbuf_used_length) { /* Get element value */ - char* elementv = &(io->instructionbuf[i]); + char* elementv = &(io->__instructionbuf[i]); /* Get terminator, set null terminator of elementv */ char terminator = elementv[element_length]; @@ -399,10 +399,10 @@ int guac_read_instruction(GUACIO* io, int usec_timeout, /* As element has been read successfully, update * parse start */ - io->instructionbuf_parse_start = i; + io->__instructionbuf_parse_start = i; /* Save element */ - io->instructionbuf_elementv[io->instructionbuf_elementc++] = elementv; + io->__instructionbuf_elementv[io->__instructionbuf_elementc++] = elementv; /* Finish parse if terminator is a semicolon */ if (terminator == ';') { @@ -410,21 +410,21 @@ int guac_read_instruction(GUACIO* io, int usec_timeout, int j; /* Init parsed instruction */ - parsed_instruction->argc = io->instructionbuf_elementc - 1; + parsed_instruction->argc = io->__instructionbuf_elementc - 1; parsed_instruction->argv = malloc(sizeof(char*) * parsed_instruction->argc); /* Set opcode */ - parsed_instruction->opcode = strdup(io->instructionbuf_elementv[0]); + parsed_instruction->opcode = strdup(io->__instructionbuf_elementv[0]); /* Copy element values to parsed instruction */ for (j=0; jargc; j++) - parsed_instruction->argv[j] = strdup(io->instructionbuf_elementv[j+1]); + parsed_instruction->argv[j] = strdup(io->__instructionbuf_elementv[j+1]); /* Reset buffer */ - memmove(io->instructionbuf, io->instructionbuf + i + 1, io->instructionbuf_used_length - i - 1); - io->instructionbuf_used_length -= i + 1; - io->instructionbuf_parse_start = 0; - io->instructionbuf_elementc = 0; + memmove(io->__instructionbuf, io->__instructionbuf + i + 1, io->__instructionbuf_used_length - i - 1); + io->__instructionbuf_used_length -= i + 1; + io->__instructionbuf_parse_start = 0; + io->__instructionbuf_elementc = 0; /* Done */ return 1; @@ -447,7 +447,7 @@ int guac_read_instruction(GUACIO* io, int usec_timeout, return retval; /* If more data is available, fill into buffer */ - retval = __guac_fill_instructionbuf(io); + retval = __guac_fill___instructionbuf(io); if (retval < 0) return retval; /* Error */ if (retval == 0) return -1; /* EOF */ @@ -470,7 +470,7 @@ void guac_free_instruction(guac_instruction* instruction) { int guac_instructions_waiting(GUACIO* io, int usec_timeout) { - if (io->instructionbuf_used_length > 0) + if (io->__instructionbuf_used_length > 0) return 1; return guac_select(io, usec_timeout);