#include "Eet.h"
#include "Eet_private.h"
+#define MAX_MSG_SIZE (64 * 1024)
#define MAGIC_EET_DATA_PACKET 0x4270ACE1
struct _Eet_Connection
{
Eet_Connection *conn;
- if (!eet_read_cb || !eet_write_cb)
- return NULL;
+ if ((!eet_read_cb) || (!eet_write_cb)) return NULL;
conn = calloc(1, sizeof (Eet_Connection));
- if (!conn)
- return NULL;
-
+ if (!conn) return NULL;
conn->eet_read_cb = eet_read_cb;
conn->eet_write_cb = eet_write_cb;
conn->user_data = (void *)user_data;
-
return conn;
}
const int *msg;
size_t packet_size;
- if (size < sizeof (int) * 2) break;
+ if (size < (sizeof(int) * 2)) break;
msg = data;
/* Check the magic */
if (ntohl(msg[0]) != MAGIC_EET_DATA_PACKET) break;
packet_size = ntohl(msg[1]);
- /* Message should always be under 64K */
- if (packet_size > 64 * 1024) break;
+ /* Message should always be under MAX_MSG_SIZE */
+ if (packet_size > MAX_MSG_SIZE) break;
data = (void *)(msg + 2);
- size -= sizeof (int) * 2;
+ size -= sizeof(int) * 2;
if ((size_t)packet_size <= size)
{
/* Not a partial receive, go the quick way. */
if (!conn->eet_read_cb(data, packet_size, conn->user_data))
break;
-
- data = (void *)((char *)data + packet_size);
- size -= packet_size;
- conn->received = 0;
- continue;
+
+ data = (void *)((char *)data + packet_size);
+ size -= packet_size;
+ conn->received = 0;
+ continue;
}
conn->size = packet_size;
if (conn->allocated < conn->size)
{
void *tmp;
-
+
tmp = realloc(conn->buffer, conn->size);
if (!tmp) break;
conn->buffer = tmp;
data_size = conn->size;
conn->size = 0;
conn->received = 0;
-
/* Completed a packet. */
if (!conn->eet_read_cb(conn->buffer, data_size, conn->user_data))
{
{
int *message;
- /* Message should never be above 64K */
- if (data_size > 64 * 1024)
- return EINA_FALSE;
-
- message = alloca(data_size + sizeof (int) * 2);
+ /* Message should always be under MAX_MSG_SIZE */
+ if (data_size > MAX_MSG_SIZE) return EINA_FALSE;
+ message = alloca(data_size + (sizeof(int) * 2));
message[0] = htonl(MAGIC_EET_DATA_PACKET);
message[1] = htonl(data_size);
-
memcpy(message + 2, data, data_size);
-
conn->eet_write_cb(message,
- data_size + sizeof (int) * 2,
+ data_size + (sizeof(int) * 2),
conn->user_data);
return EINA_TRUE;
}
data_in,
cipher_key,
&data_size);
- if (!flat_data)
- return EINA_FALSE;
-
- if (_eet_connection_raw_send(conn, flat_data, data_size))
- ret = EINA_TRUE;
-
+ if (!flat_data) return EINA_FALSE;
+ if (_eet_connection_raw_send(conn, flat_data, data_size)) ret = EINA_TRUE;
free(flat_data);
return ret;
}
Eina_Bool ret = EINA_FALSE;
data = eet_data_node_encode_cipher(node, cipher_key, &data_size);
- if (!data)
- return EINA_FALSE;
-
+ if (!data) return EINA_FALSE;
if (_eet_connection_raw_send(conn, data, data_size))
ret = EINA_TRUE;
-
free(data);
return ret;
}
{
void *user_data;
- if (!conn)
- return NULL;
-
- if (on_going)
- *on_going = conn->received == 0 ? EINA_FALSE : EINA_TRUE;
-
+ if (!conn) return NULL;
+ if (on_going) *on_going = conn->received == 0 ? EINA_FALSE : EINA_TRUE;
user_data = conn->user_data;
-
free(conn->buffer);
free(conn);
-
return user_data;
}