2012-10-04 10:04:38 -07:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2012-11-23 14:38:23 -08:00
|
|
|
#ifdef STDC_HEADERS
|
|
|
|
# include <stdlib.h>
|
|
|
|
# include <stddef.h>
|
|
|
|
#else
|
|
|
|
# ifdef HAVE_STDLIB_H
|
|
|
|
# include <stdlib.h>
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2014-05-30 05:15:27 -07:00
|
|
|
#ifdef HAVE_ARPA_INET_H
|
|
|
|
# include <arpa/inet.h>
|
|
|
|
#endif
|
|
|
|
|
2012-08-30 20:11:24 -07:00
|
|
|
#include <Eina.h>
|
|
|
|
|
|
|
|
#include "Ecore_Con_Eet.h"
|
|
|
|
|
|
|
|
#define ECORE_CON_EET_RAW_MAGIC 0xDEAD007
|
2015-06-29 05:21:13 -07:00
|
|
|
#define ECORE_CON_EET_DATA_KEY "ecore_con_eet_data_key"
|
2012-08-30 20:11:24 -07:00
|
|
|
|
2015-06-22 09:55:54 -07:00
|
|
|
typedef struct _Ecore_Con_Eet_Base_Data Ecore_Con_Eet_Base_Data;
|
|
|
|
typedef struct _Ecore_Con_Eet_Server_Obj_Data Ecore_Con_Eet_Server_Obj_Data;
|
|
|
|
typedef struct _Ecore_Con_Eet_Client_Obj_Data Ecore_Con_Eet_Client_Obj_Data;
|
2013-12-19 21:07:50 -08:00
|
|
|
typedef struct _Ecore_Con_Eet_Data Ecore_Con_Eet_Data;
|
2012-08-30 20:11:24 -07:00
|
|
|
typedef struct _Ecore_Con_Eet_Raw_Data Ecore_Con_Eet_Raw_Data;
|
2013-12-19 21:07:50 -08:00
|
|
|
typedef struct _Ecore_Con_Eet_Client Ecore_Con_Eet_Client;
|
|
|
|
typedef struct _Ecore_Con_Eet_Server Ecore_Con_Eet_Server;
|
2012-08-30 20:11:24 -07:00
|
|
|
|
2015-06-22 09:55:54 -07:00
|
|
|
struct _Ecore_Con_Eet_Server_Obj_Data
|
|
|
|
{
|
|
|
|
Eina_List *connections;
|
|
|
|
Eina_List *client_connect_callbacks;
|
|
|
|
Eina_List *client_disconnect_callbacks;
|
|
|
|
|
|
|
|
Ecore_Event_Handler *handler_add;
|
|
|
|
Ecore_Event_Handler *handler_del;
|
|
|
|
Ecore_Event_Handler *handler_data;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _Ecore_Con_Eet_Client_Obj_Data
|
|
|
|
{
|
|
|
|
Ecore_Con_Reply *r;
|
|
|
|
Eina_List *server_connect_callbacks;
|
|
|
|
Eina_List *server_disconnect_callbacks;
|
|
|
|
|
|
|
|
Ecore_Event_Handler *handler_add;
|
|
|
|
Ecore_Event_Handler *handler_del;
|
|
|
|
Ecore_Event_Handler *handler_data;
|
|
|
|
};
|
|
|
|
|
2012-08-30 20:11:24 -07:00
|
|
|
struct _Ecore_Con_Reply
|
|
|
|
{
|
2013-12-19 21:07:50 -08:00
|
|
|
Ecore_Con_Eet *ece;
|
|
|
|
Ecore_Con_Client *client;
|
2012-08-30 20:11:24 -07:00
|
|
|
|
2013-12-19 21:07:50 -08:00
|
|
|
Eet_Connection *econn;
|
2012-08-30 20:11:24 -07:00
|
|
|
|
2013-12-19 21:07:50 -08:00
|
|
|
char *buffer_section;
|
|
|
|
unsigned char *buffer;
|
|
|
|
unsigned int buffer_length;
|
|
|
|
unsigned int buffer_current;
|
2012-08-30 20:11:24 -07:00
|
|
|
Ecore_Con_Eet_Raw_Data *buffer_handler;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _Ecore_Con_Eet_Data
|
|
|
|
{
|
|
|
|
Ecore_Con_Eet_Data_Cb func;
|
2013-12-19 21:07:50 -08:00
|
|
|
const char *name;
|
|
|
|
const void *data;
|
2012-08-30 20:11:24 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _Ecore_Con_Eet_Raw_Data
|
|
|
|
{
|
|
|
|
Ecore_Con_Eet_Raw_Data_Cb func;
|
2013-12-19 21:07:50 -08:00
|
|
|
const char *name;
|
|
|
|
const void *data;
|
2012-08-30 20:11:24 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _Ecore_Con_Eet_Client
|
|
|
|
{
|
|
|
|
Ecore_Con_Eet_Client_Cb func;
|
2013-12-19 21:07:50 -08:00
|
|
|
const void *data;
|
2012-08-30 20:11:24 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _Ecore_Con_Eet_Server
|
|
|
|
{
|
|
|
|
Ecore_Con_Eet_Server_Cb func;
|
2013-12-19 21:07:50 -08:00
|
|
|
const void *data;
|
2012-08-30 20:11:24 -07:00
|
|
|
};
|
|
|
|
|
2015-06-22 09:55:54 -07:00
|
|
|
struct _Ecore_Con_Eet_Base_Data
|
2012-08-30 20:11:24 -07:00
|
|
|
{
|
2013-12-19 21:07:50 -08:00
|
|
|
Ecore_Con_Server *server;
|
2012-08-30 20:11:24 -07:00
|
|
|
|
|
|
|
Eet_Data_Descriptor *edd;
|
|
|
|
Eet_Data_Descriptor *matching;
|
|
|
|
|
2013-12-19 21:07:50 -08:00
|
|
|
Eina_Hash *data_callbacks;
|
|
|
|
Eina_Hash *raw_data_callbacks;
|
2012-08-30 20:11:24 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
_ecore_con_eet_data_free(void *data)
|
|
|
|
{
|
|
|
|
Ecore_Con_Eet_Data *eced = data;
|
|
|
|
|
|
|
|
eina_stringshare_del(eced->name);
|
|
|
|
free(eced);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_ecore_con_eet_raw_data_free(void *data)
|
|
|
|
{
|
|
|
|
Ecore_Con_Eet_Raw_Data *eced = data;
|
|
|
|
|
|
|
|
eina_stringshare_del(eced->name);
|
|
|
|
free(eced);
|
|
|
|
}
|
2013-12-19 21:07:50 -08:00
|
|
|
|
2012-08-30 20:11:24 -07:00
|
|
|
static void
|
|
|
|
_ecore_con_eet_reply_cleanup(Ecore_Con_Reply *n)
|
|
|
|
{
|
|
|
|
if (n->buffer_handler) free(n->buffer);
|
|
|
|
n->buffer = NULL;
|
|
|
|
n->buffer_handler = NULL;
|
|
|
|
free(n->buffer_section);
|
|
|
|
n->buffer_section = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct _Ecore_Con_Eet_Protocol Ecore_Con_Eet_Protocol;
|
2013-12-19 21:07:50 -08:00
|
|
|
struct _Ecore_Con_Eet_Protocol
|
|
|
|
{
|
2012-08-30 20:11:24 -07:00
|
|
|
const char *type;
|
2013-12-19 21:07:50 -08:00
|
|
|
void *data;
|
2012-08-30 20:11:24 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
_ecore_con_eet_data_type_get(const void *data, Eina_Bool *unknow EINA_UNUSED)
|
|
|
|
{
|
|
|
|
const Ecore_Con_Eet_Protocol *p = data;
|
|
|
|
|
|
|
|
return p->type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_ecore_con_eet_data_type_set(const char *type, void *data, Eina_Bool unknow EINA_UNUSED)
|
|
|
|
{
|
|
|
|
Ecore_Con_Eet_Protocol *p = data;
|
|
|
|
|
|
|
|
p->type = type;
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-06-22 09:55:54 -07:00
|
|
|
_ecore_con_eet_data_descriptor_setup(Ecore_Con_Eet_Base_Data *ece)
|
2012-08-30 20:11:24 -07:00
|
|
|
{
|
|
|
|
Eet_Data_Descriptor_Class eddc;
|
|
|
|
|
|
|
|
EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, Ecore_Con_Eet_Protocol);
|
|
|
|
ece->edd = eet_data_descriptor_stream_new(&eddc);
|
|
|
|
|
|
|
|
eddc.version = EET_DATA_DESCRIPTOR_CLASS_VERSION;
|
|
|
|
eddc.func.type_get = _ecore_con_eet_data_type_get;
|
|
|
|
eddc.func.type_set = _ecore_con_eet_data_type_set;
|
|
|
|
ece->matching = eet_data_descriptor_stream_new(&eddc);
|
|
|
|
|
|
|
|
EET_DATA_DESCRIPTOR_ADD_VARIANT(ece->edd, Ecore_Con_Eet_Protocol, "data", data, type, ece->matching);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Dealing with a server listening to connection */
|
|
|
|
static Eina_Bool
|
|
|
|
_ecore_con_eet_read_cb(const void *eet_data, size_t size, void *user_data)
|
|
|
|
{
|
|
|
|
Ecore_Con_Reply *n = user_data;
|
|
|
|
Ecore_Con_Eet_Protocol *protocol;
|
|
|
|
Ecore_Con_Eet_Data *cb;
|
2015-06-22 09:55:54 -07:00
|
|
|
Ecore_Con_Eet_Base_Data *ece_data = eo_data_scope_get(n->ece, ECORE_CON_EET_BASE_CLASS);
|
2012-08-30 20:11:24 -07:00
|
|
|
|
2015-06-22 09:55:54 -07:00
|
|
|
protocol = eet_data_descriptor_decode(ece_data->edd, eet_data, size);
|
2012-08-30 20:11:24 -07:00
|
|
|
if (!protocol) return EINA_TRUE;
|
|
|
|
|
2015-06-22 09:55:54 -07:00
|
|
|
cb = eina_hash_find(ece_data->data_callbacks, protocol->type);
|
2013-12-19 21:07:50 -08:00
|
|
|
if (!cb) return EINA_TRUE; /* Should I report unknow protocol communication ? */
|
2012-08-30 20:11:24 -07:00
|
|
|
|
2013-12-19 21:07:50 -08:00
|
|
|
cb->func((void *)cb->data, n, cb->name, protocol->data);
|
2012-08-30 20:11:24 -07:00
|
|
|
|
|
|
|
eina_stringshare_del(protocol->type);
|
|
|
|
free(protocol);
|
|
|
|
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_ecore_con_eet_server_write_cb(const void *data, size_t size, void *user_data)
|
|
|
|
{
|
|
|
|
Ecore_Con_Reply *n = user_data;
|
|
|
|
|
2013-12-19 21:07:50 -08:00
|
|
|
if (ecore_con_client_send(n->client, data, size) != (int)size)
|
2012-08-30 20:11:24 -07:00
|
|
|
return EINA_FALSE;
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_ecore_con_eet_client_write_cb(const void *data, size_t size, void *user_data)
|
|
|
|
{
|
|
|
|
Ecore_Con_Reply *n = user_data;
|
2015-06-22 09:55:54 -07:00
|
|
|
Ecore_Con_Eet_Base_Data *ece_data = eo_data_scope_get(n->ece, ECORE_CON_EET_BASE_CLASS);
|
2012-08-30 20:11:24 -07:00
|
|
|
|
2015-06-22 09:55:54 -07:00
|
|
|
if (ecore_con_server_send(ece_data->server, data, size) != (int)size)
|
2012-08-30 20:11:24 -07:00
|
|
|
return EINA_FALSE;
|
2015-06-22 09:55:54 -07:00
|
|
|
|
2012-08-30 20:11:24 -07:00
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_ecore_con_eet_server_connected(void *data, int type EINA_UNUSED, Ecore_Con_Event_Client_Add *ev)
|
|
|
|
{
|
|
|
|
Ecore_Con_Eet_Client *ecec;
|
|
|
|
Eina_List *ll;
|
|
|
|
Ecore_Con_Reply *n;
|
2015-06-22 09:55:54 -07:00
|
|
|
Ecore_Con_Eet *ece_obj = data;
|
|
|
|
Ecore_Con_Eet_Base_Data *base_data = eo_data_scope_get(ece_obj, ECORE_CON_EET_BASE_CLASS);
|
|
|
|
Ecore_Con_Eet_Server_Obj_Data *r = eo_data_scope_get(ece_obj, ECORE_CON_EET_SERVER_OBJ_CLASS);
|
2012-08-30 20:11:24 -07:00
|
|
|
|
2015-06-22 09:55:54 -07:00
|
|
|
if (ecore_con_client_server_get(ev->client) != base_data->server)
|
2012-08-30 20:11:24 -07:00
|
|
|
return EINA_TRUE;
|
|
|
|
|
|
|
|
n = calloc(1, sizeof (Ecore_Con_Reply));
|
|
|
|
if (!n) return EINA_TRUE;
|
|
|
|
|
|
|
|
n->client = ev->client;
|
2015-06-22 09:55:54 -07:00
|
|
|
n->ece = ece_obj;
|
2012-08-30 20:11:24 -07:00
|
|
|
n->econn = eet_connection_new(_ecore_con_eet_read_cb, _ecore_con_eet_server_write_cb, n);
|
|
|
|
ecore_con_client_data_set(n->client, n);
|
|
|
|
|
2015-06-22 09:55:54 -07:00
|
|
|
EINA_LIST_FOREACH(r->client_connect_callbacks, ll, ecec)
|
2013-12-19 21:07:50 -08:00
|
|
|
if (!ecec->func((void *)ecec->data, n, n->client))
|
2012-08-30 20:11:24 -07:00
|
|
|
{
|
|
|
|
eet_connection_close(n->econn, NULL);
|
|
|
|
free(n);
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
2015-06-22 09:55:54 -07:00
|
|
|
r->connections = eina_list_append(r->connections, n);
|
2012-08-30 20:11:24 -07:00
|
|
|
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_ecore_con_eet_server_disconnected(void *data, int type EINA_UNUSED, Ecore_Con_Event_Client_Del *ev)
|
|
|
|
{
|
2015-06-22 09:55:54 -07:00
|
|
|
Ecore_Con_Eet *ece_obj = data;
|
|
|
|
Ecore_Con_Eet_Base_Data *base_data = eo_data_scope_get(ece_obj, ECORE_CON_EET_BASE_CLASS);
|
|
|
|
Ecore_Con_Eet_Server_Obj_Data *r = eo_data_scope_get(ece_obj, ECORE_CON_EET_SERVER_OBJ_CLASS);
|
2012-08-30 20:11:24 -07:00
|
|
|
Ecore_Con_Reply *n;
|
|
|
|
Eina_List *l;
|
|
|
|
|
2015-06-22 09:55:54 -07:00
|
|
|
if (ecore_con_client_server_get(ev->client) != base_data->server)
|
2012-08-30 20:11:24 -07:00
|
|
|
return EINA_TRUE;
|
|
|
|
|
2015-06-22 09:55:54 -07:00
|
|
|
EINA_LIST_FOREACH(r->connections, l, n)
|
2012-08-30 20:11:24 -07:00
|
|
|
if (n->client == ev->client)
|
|
|
|
{
|
|
|
|
Ecore_Con_Eet_Client *ecec;
|
|
|
|
Eina_List *ll;
|
|
|
|
|
2015-06-22 09:55:54 -07:00
|
|
|
EINA_LIST_FOREACH(r->client_disconnect_callbacks, ll, ecec)
|
2013-12-19 21:07:50 -08:00
|
|
|
ecec->func((void *)ecec->data, n, n->client);
|
2012-08-30 20:11:24 -07:00
|
|
|
|
|
|
|
eet_connection_close(n->econn, NULL);
|
|
|
|
free(n);
|
2015-06-22 09:55:54 -07:00
|
|
|
r->connections = eina_list_remove_list(r->connections, l);
|
2012-08-30 20:11:24 -07:00
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_ecore_con_eet_raw_data_push(Ecore_Con_Reply *n, void *data, int size)
|
|
|
|
{
|
|
|
|
if (n->buffer_handler)
|
|
|
|
memcpy(n->buffer + n->buffer_current, data, size);
|
|
|
|
n->buffer_current += size;
|
|
|
|
|
|
|
|
if (n->buffer_current == n->buffer_length)
|
|
|
|
{
|
|
|
|
if (n->buffer_handler)
|
2013-12-19 21:07:50 -08:00
|
|
|
n->buffer_handler->func((void *)n->buffer_handler->data, n, n->buffer_handler->name, n->buffer_section, n->buffer, n->buffer_length);
|
2012-08-30 20:11:24 -07:00
|
|
|
_ecore_con_eet_reply_cleanup(n);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_ecore_con_eet_data(Ecore_Con_Reply *n, void *data, unsigned int size)
|
|
|
|
{
|
|
|
|
/* FIXME: Enforce detection of attack and kill connection on that case */
|
|
|
|
if (n->buffer)
|
|
|
|
{
|
|
|
|
if (n->buffer_current + size > n->buffer_length)
|
|
|
|
{
|
|
|
|
_ecore_con_eet_reply_cleanup(n);
|
2013-06-20 04:28:18 -07:00
|
|
|
return;
|
2012-08-30 20:11:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
_ecore_con_eet_raw_data_push(n, data, size);
|
2013-06-20 04:28:18 -07:00
|
|
|
return;
|
2012-08-30 20:11:24 -07:00
|
|
|
}
|
2013-12-19 21:07:50 -08:00
|
|
|
else if (eet_connection_empty(n->econn) && size > (int)(4 * sizeof (unsigned int) + 2))
|
2012-08-30 20:11:24 -07:00
|
|
|
{
|
|
|
|
unsigned int *tmp = data;
|
2012-12-02 23:14:13 -08:00
|
|
|
size -= 4 * sizeof (unsigned int);
|
2012-08-30 20:11:24 -07:00
|
|
|
|
|
|
|
if (ntohl(tmp[0]) == ECORE_CON_EET_RAW_MAGIC)
|
|
|
|
{
|
|
|
|
unsigned int protocol_length = ntohl(tmp[1]);
|
|
|
|
unsigned int section_length = ntohl(tmp[2]);
|
|
|
|
unsigned int data_length = ntohl(tmp[3]);
|
|
|
|
|
|
|
|
if (protocol_length > 1 && section_length > 1 && protocol_length + section_length <= size && data_length < 10 * 1024 * 1024)
|
|
|
|
{
|
2013-12-19 21:07:50 -08:00
|
|
|
char *buffer = (char *)&tmp[4];
|
2012-08-30 20:11:24 -07:00
|
|
|
char *protocol;
|
|
|
|
char *section;
|
2015-06-22 09:55:54 -07:00
|
|
|
Ecore_Con_Eet_Base_Data *eceb_data = eo_data_scope_get(n->ece,ECORE_CON_EET_BASE_CLASS);
|
2012-08-30 20:11:24 -07:00
|
|
|
|
|
|
|
protocol = buffer;
|
|
|
|
section = buffer + protocol_length;
|
|
|
|
|
|
|
|
if (protocol[protocol_length - 1] == '\0' &&
|
|
|
|
section[section_length - 1] == '\0')
|
|
|
|
{
|
|
|
|
size -= protocol_length + section_length;
|
|
|
|
buffer = section + section_length;
|
|
|
|
|
2015-06-22 09:55:54 -07:00
|
|
|
n->buffer_handler = eina_hash_find(eceb_data->raw_data_callbacks, protocol);
|
2012-08-30 20:11:24 -07:00
|
|
|
n->buffer_section = strdup(section);
|
|
|
|
n->buffer_length = data_length;
|
|
|
|
n->buffer_current = 0;
|
|
|
|
if (n->buffer_handler)
|
2013-07-16 04:02:00 -07:00
|
|
|
n->buffer = malloc(sizeof (unsigned char) * data_length);
|
2012-08-30 20:11:24 -07:00
|
|
|
else
|
2013-12-19 21:07:50 -08:00
|
|
|
n->buffer = (void *)1;
|
2012-08-30 20:11:24 -07:00
|
|
|
if (n->buffer)
|
|
|
|
{
|
|
|
|
_ecore_con_eet_raw_data_push(n, buffer, size);
|
2013-06-20 04:28:18 -07:00
|
|
|
return;
|
2012-08-30 20:11:24 -07:00
|
|
|
}
|
|
|
|
_ecore_con_eet_reply_cleanup(n);
|
2012-09-08 09:12:34 -07:00
|
|
|
|
|
|
|
size += protocol_length + section_length;
|
2012-08-30 20:11:24 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-09-08 09:12:34 -07:00
|
|
|
|
2012-12-02 23:14:13 -08:00
|
|
|
size += 4 * sizeof (unsigned int);
|
2012-08-30 20:11:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
eet_connection_received(n->econn, data, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_ecore_con_eet_server_data(void *data, int type EINA_UNUSED, Ecore_Con_Event_Client_Data *ev)
|
|
|
|
{
|
2015-06-22 09:55:54 -07:00
|
|
|
Ecore_Con_Eet *ece_obj = data;
|
|
|
|
Ecore_Con_Eet_Base_Data *r = eo_data_scope_get(ece_obj, ECORE_CON_EET_BASE_CLASS);
|
2012-08-30 20:11:24 -07:00
|
|
|
Ecore_Con_Reply *n;
|
|
|
|
|
|
|
|
if (ecore_con_client_server_get(ev->client) != r->server)
|
|
|
|
return EINA_TRUE;
|
|
|
|
|
|
|
|
n = ecore_con_client_data_get(ev->client);
|
|
|
|
|
2015-07-27 18:04:38 -07:00
|
|
|
eo_ref(ece_obj);
|
2012-08-30 20:11:24 -07:00
|
|
|
_ecore_con_eet_data(n, ev->data, ev->size);
|
2015-07-27 18:04:38 -07:00
|
|
|
eo_unref(ece_obj);
|
2012-08-30 20:11:24 -07:00
|
|
|
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Dealing connection to a server */
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_ecore_con_eet_client_connected(void *data, int type EINA_UNUSED, Ecore_Con_Event_Server_Add *ev)
|
|
|
|
{
|
|
|
|
Ecore_Con_Eet_Server *eces;
|
2015-06-22 09:55:54 -07:00
|
|
|
Ecore_Con_Eet *ece_obj = data;
|
|
|
|
Ecore_Con_Eet_Base_Data *base_data = eo_data_scope_get(ece_obj, ECORE_CON_EET_BASE_CLASS);
|
|
|
|
Ecore_Con_Eet_Client_Obj_Data *r = eo_data_scope_get(ece_obj, ECORE_CON_EET_CLIENT_OBJ_CLASS);
|
2012-08-30 20:11:24 -07:00
|
|
|
Ecore_Con_Reply *n;
|
|
|
|
Eina_List *ll;
|
|
|
|
|
|
|
|
/* Client did connect */
|
2015-06-22 09:55:54 -07:00
|
|
|
if (base_data->server != ev->server) return EINA_TRUE;
|
|
|
|
if (r->r) return EINA_TRUE;
|
2012-08-30 20:11:24 -07:00
|
|
|
|
|
|
|
n = calloc(1, sizeof (Ecore_Con_Reply));
|
|
|
|
if (!n) return EINA_TRUE;
|
|
|
|
|
|
|
|
n->client = NULL;
|
2015-06-22 09:55:54 -07:00
|
|
|
n->ece = ece_obj;
|
2012-08-30 20:11:24 -07:00
|
|
|
n->econn = eet_connection_new(_ecore_con_eet_read_cb, _ecore_con_eet_client_write_cb, n);
|
|
|
|
|
2015-06-22 09:55:54 -07:00
|
|
|
EINA_LIST_FOREACH(r->server_connect_callbacks, ll, eces)
|
|
|
|
{
|
|
|
|
Ecore_Con_Eet_Base_Data *temp = eo_data_scope_get(n->ece, ECORE_CON_EET_BASE_CLASS);
|
|
|
|
if (!eces->func((void *)eces->data, n, temp->server))
|
|
|
|
{
|
|
|
|
eet_connection_close(n->econn, NULL);
|
|
|
|
free(n);
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
}
|
2012-08-30 20:11:24 -07:00
|
|
|
|
2015-06-22 09:55:54 -07:00
|
|
|
r->r = n;
|
2012-08-30 20:11:24 -07:00
|
|
|
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_ecore_con_eet_client_disconnected(void *data, int type EINA_UNUSED, Ecore_Con_Event_Server_Del *ev)
|
|
|
|
{
|
2015-06-22 09:55:54 -07:00
|
|
|
Ecore_Con_Eet *ece_obj = data;
|
|
|
|
Ecore_Con_Eet_Base_Data *base_data = eo_data_scope_get(ece_obj, ECORE_CON_EET_BASE_CLASS);
|
|
|
|
Ecore_Con_Eet_Client_Obj_Data *r = eo_data_scope_get(ece_obj, ECORE_CON_EET_CLIENT_OBJ_CLASS);
|
2012-08-30 20:11:24 -07:00
|
|
|
Ecore_Con_Eet_Server *eces;
|
|
|
|
Eina_List *ll;
|
|
|
|
|
2015-06-22 09:55:54 -07:00
|
|
|
if (base_data->server != ev->server) return EINA_TRUE;
|
|
|
|
if (!r->r) return EINA_TRUE;
|
2012-08-30 20:11:24 -07:00
|
|
|
|
|
|
|
/* Client disconnected */
|
2015-06-22 09:55:54 -07:00
|
|
|
EINA_LIST_FOREACH(r->server_disconnect_callbacks, ll, eces)
|
|
|
|
eces->func((void *)eces->data, r->r, base_data->server);
|
2012-08-30 20:11:24 -07:00
|
|
|
|
2015-06-22 09:55:54 -07:00
|
|
|
eet_connection_close(r->r->econn, NULL);
|
|
|
|
free(r->r);
|
|
|
|
r->r = NULL;
|
2012-08-30 20:11:24 -07:00
|
|
|
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_ecore_con_eet_client_data(void *data, int type EINA_UNUSED, Ecore_Con_Event_Server_Data *ev)
|
|
|
|
{
|
2015-06-22 09:55:54 -07:00
|
|
|
Ecore_Con_Eet *ece_obj = data;
|
|
|
|
Ecore_Con_Eet_Base_Data *base_data = eo_data_scope_get(ece_obj, ECORE_CON_EET_BASE_CLASS);
|
|
|
|
Ecore_Con_Eet_Client_Obj_Data *r = eo_data_scope_get(ece_obj, ECORE_CON_EET_CLIENT_OBJ_CLASS);
|
2012-08-30 20:11:24 -07:00
|
|
|
|
2015-06-22 09:55:54 -07:00
|
|
|
if (base_data->server != ev->server) return EINA_TRUE;
|
|
|
|
if (!r->r) return EINA_TRUE;
|
2012-08-30 20:11:24 -07:00
|
|
|
|
|
|
|
/* Got some data */
|
2015-07-27 18:04:38 -07:00
|
|
|
eo_ref(ece_obj);
|
2015-06-22 09:55:54 -07:00
|
|
|
_ecore_con_eet_data(r->r, ev->data, ev->size);
|
2015-07-27 18:04:38 -07:00
|
|
|
eo_unref(ece_obj);
|
2012-08-30 20:11:24 -07:00
|
|
|
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
2015-06-22 09:55:54 -07:00
|
|
|
/*************
|
|
|
|
* Generated API
|
|
|
|
*/
|
2015-06-29 05:21:13 -07:00
|
|
|
|
|
|
|
EOLIAN static void
|
|
|
|
_ecore_con_eet_base_data_callback_set(Eo *obj EINA_UNUSED, Ecore_Con_Eet_Base_Data *pd, const char *name, Ecore_Con_Eet_Data_Cb func, const void *data)
|
|
|
|
{
|
|
|
|
Ecore_Con_Eet_Data *eced;
|
|
|
|
|
|
|
|
eced = calloc(1, sizeof (Ecore_Con_Eet_Data));
|
|
|
|
if (!eced) return;
|
|
|
|
|
|
|
|
eced->func = func;
|
|
|
|
eced->data = data;
|
|
|
|
eced->name = eina_stringshare_add(name);
|
|
|
|
|
|
|
|
eina_hash_direct_add(pd->data_callbacks, eced->name, eced);
|
|
|
|
}
|
|
|
|
|
|
|
|
EOLIAN static void
|
|
|
|
_ecore_con_eet_base_raw_data_callback_set(Eo *obj EINA_UNUSED, Ecore_Con_Eet_Base_Data *pd, const char *name, Ecore_Con_Eet_Raw_Data_Cb func, const void *data)
|
|
|
|
{
|
|
|
|
Ecore_Con_Eet_Raw_Data *ecerd;
|
|
|
|
|
|
|
|
ecerd = calloc(1, sizeof (Ecore_Con_Eet_Raw_Data));
|
|
|
|
if (!ecerd) return;
|
|
|
|
|
|
|
|
ecerd->func = func;
|
|
|
|
ecerd->data = data;
|
|
|
|
ecerd->name = eina_stringshare_add(name);
|
|
|
|
|
|
|
|
eina_hash_direct_add(pd->raw_data_callbacks, ecerd->name, ecerd);
|
|
|
|
}
|
|
|
|
|
|
|
|
EOLIAN static void
|
|
|
|
_ecore_con_eet_base_data_callback_del(Eo *obj EINA_UNUSED, Ecore_Con_Eet_Base_Data *pd, const char *name)
|
|
|
|
{
|
|
|
|
eina_hash_del(pd->data_callbacks, name, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
EOLIAN static void
|
|
|
|
_ecore_con_eet_base_raw_data_callback_del(Eo *obj, Ecore_Con_Eet_Base_Data *pd, const char *name)
|
|
|
|
{
|
|
|
|
Ecore_Con_Eet_Client_Obj_Data *eced = eo_data_scope_get(obj, ECORE_CON_EET_CLIENT_OBJ_CLASS);
|
|
|
|
|
|
|
|
if (eo_isa(obj, ECORE_CON_EET_CLIENT_OBJ_CLASS) &&
|
|
|
|
eced->r->buffer_handler &&
|
|
|
|
!strcmp(eced->r->buffer_handler->name, name))
|
|
|
|
{
|
|
|
|
eced->r->buffer_handler = NULL;
|
|
|
|
free(eced->r->buffer);
|
|
|
|
eced->r->buffer = (void *)1;
|
|
|
|
}
|
|
|
|
eina_hash_del(pd->raw_data_callbacks, name, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
EOLIAN static void
|
|
|
|
_ecore_con_eet_base_send(Eo *obj EINA_UNUSED, Ecore_Con_Eet_Base_Data *pd, Ecore_Con_Reply *reply, const char *name, void *value)
|
|
|
|
{
|
|
|
|
Ecore_Con_Eet_Protocol protocol;
|
|
|
|
|
|
|
|
if (!reply) return;
|
|
|
|
|
|
|
|
protocol.type = name;
|
|
|
|
protocol.data = value;
|
|
|
|
|
|
|
|
eet_connection_send(reply->econn, pd->edd, &protocol, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
EOLIAN static void
|
|
|
|
_ecore_con_eet_base_raw_send(Eo *obj EINA_UNUSED, Ecore_Con_Eet_Base_Data *pd, Ecore_Con_Reply *reply, const char *protocol_name, const char *section, void *value, unsigned int length)
|
|
|
|
{
|
|
|
|
unsigned int protocol[4];
|
|
|
|
unsigned int protocol_length;
|
|
|
|
unsigned int section_length;
|
|
|
|
unsigned int size;
|
|
|
|
char *tmp;
|
|
|
|
|
|
|
|
if (!reply) return;
|
|
|
|
if (!protocol_name) return;
|
|
|
|
if (!section) return;
|
|
|
|
|
|
|
|
protocol_length = strlen(protocol_name) + 1;
|
|
|
|
if (protocol_length == 1) return;
|
|
|
|
section_length = strlen(section) + 1;
|
|
|
|
|
|
|
|
protocol[0] = htonl(ECORE_CON_EET_RAW_MAGIC);
|
|
|
|
protocol[1] = htonl(protocol_length);
|
|
|
|
protocol[2] = htonl(section_length);
|
|
|
|
protocol[3] = htonl(length);
|
|
|
|
|
|
|
|
size = sizeof (protocol) + protocol_length + section_length;
|
|
|
|
tmp = alloca(size);
|
|
|
|
memcpy(tmp, protocol, sizeof (protocol));
|
|
|
|
memcpy(tmp + sizeof (protocol), protocol_name, protocol_length);
|
|
|
|
memcpy(tmp + sizeof (protocol) + protocol_length, section, section_length);
|
|
|
|
|
|
|
|
if (reply->client)
|
|
|
|
{
|
|
|
|
ecore_con_client_send(reply->client, tmp, size);
|
|
|
|
ecore_con_client_send(reply->client, value, length);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ecore_con_server_send(pd->server, tmp, size);
|
|
|
|
ecore_con_server_send(pd->server, value, length);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
EOLIAN static void
|
|
|
|
_ecore_con_eet_base_register(Eo *obj EINA_UNUSED, Ecore_Con_Eet_Base_Data *pd, const char *name, Eet_Data_Descriptor *edd)
|
|
|
|
{
|
|
|
|
EET_DATA_DESCRIPTOR_ADD_MAPPING(pd->matching, name, edd);
|
|
|
|
}
|
|
|
|
|
2015-06-22 09:55:54 -07:00
|
|
|
EOLIAN static Eo_Base *
|
|
|
|
_ecore_con_eet_server_obj_eo_base_constructor(Eo *obj, Ecore_Con_Eet_Server_Obj_Data *pd EINA_UNUSED)
|
|
|
|
{
|
2016-03-01 10:06:28 -08:00
|
|
|
obj = eo_constructor(eo_super(obj, ECORE_CON_EET_SERVER_OBJ_CLASS));
|
2015-06-22 09:55:54 -07:00
|
|
|
|
|
|
|
if (!obj) return NULL;
|
|
|
|
|
|
|
|
pd->handler_add = ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_ADD,
|
|
|
|
(Ecore_Event_Handler_Cb)_ecore_con_eet_server_connected, obj);
|
|
|
|
pd->handler_del = ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_DEL,
|
|
|
|
(Ecore_Event_Handler_Cb)_ecore_con_eet_server_disconnected, obj);
|
|
|
|
pd->handler_data = ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_DATA,
|
|
|
|
(Ecore_Event_Handler_Cb)_ecore_con_eet_server_data, obj);
|
|
|
|
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
EOLIAN static void
|
|
|
|
_ecore_con_eet_server_obj_eo_base_destructor(Eo *obj, Ecore_Con_Eet_Server_Obj_Data *pd EINA_UNUSED)
|
|
|
|
{
|
|
|
|
Ecore_Con_Reply *n;
|
|
|
|
Ecore_Con_Eet_Client *c;
|
|
|
|
|
|
|
|
EINA_LIST_FREE(pd->connections, n)
|
|
|
|
{
|
|
|
|
_ecore_con_eet_reply_cleanup(n);
|
|
|
|
eet_connection_close(n->econn, NULL);
|
|
|
|
free(n);
|
|
|
|
}
|
|
|
|
EINA_LIST_FREE(pd->client_connect_callbacks, c)
|
|
|
|
free(c);
|
|
|
|
EINA_LIST_FREE(pd->client_disconnect_callbacks, c)
|
|
|
|
free(c);
|
|
|
|
|
|
|
|
ecore_event_handler_del(pd->handler_add);
|
|
|
|
ecore_event_handler_del(pd->handler_del);
|
|
|
|
ecore_event_handler_del(pd->handler_data);
|
|
|
|
|
2016-03-01 10:06:28 -08:00
|
|
|
eo_destructor(eo_super(obj, ECORE_CON_EET_SERVER_OBJ_CLASS));
|
2015-06-22 09:55:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
EOLIAN static Eo_Base *
|
|
|
|
_ecore_con_eet_client_obj_eo_base_constructor(Eo *obj, Ecore_Con_Eet_Client_Obj_Data *pd EINA_UNUSED)
|
|
|
|
{
|
2016-03-01 10:06:28 -08:00
|
|
|
obj = eo_constructor(eo_super(obj, ECORE_CON_EET_CLIENT_OBJ_CLASS));
|
2015-06-22 09:55:54 -07:00
|
|
|
|
|
|
|
if (!obj) return NULL;
|
|
|
|
|
|
|
|
pd->handler_add = ecore_event_handler_add(ECORE_CON_EVENT_SERVER_ADD,
|
|
|
|
(Ecore_Event_Handler_Cb)_ecore_con_eet_client_connected, obj);
|
|
|
|
pd->handler_del = ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DEL,
|
|
|
|
(Ecore_Event_Handler_Cb)_ecore_con_eet_client_disconnected, obj);
|
|
|
|
pd->handler_data = ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DATA,
|
|
|
|
(Ecore_Event_Handler_Cb)_ecore_con_eet_client_data, obj);
|
|
|
|
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
EOLIAN static void
|
|
|
|
_ecore_con_eet_client_obj_eo_base_destructor(Eo *obj, Ecore_Con_Eet_Client_Obj_Data *pd EINA_UNUSED)
|
|
|
|
{
|
|
|
|
Ecore_Con_Eet_Server *s;
|
|
|
|
|
|
|
|
if (pd->r)
|
|
|
|
{
|
|
|
|
_ecore_con_eet_reply_cleanup(pd->r);
|
|
|
|
eet_connection_close(pd->r->econn, NULL);
|
|
|
|
}
|
|
|
|
EINA_LIST_FREE(pd->server_connect_callbacks, s)
|
|
|
|
free(s);
|
|
|
|
EINA_LIST_FREE(pd->server_disconnect_callbacks, s)
|
|
|
|
free(s);
|
|
|
|
|
|
|
|
ecore_event_handler_del(pd->handler_add);
|
|
|
|
ecore_event_handler_del(pd->handler_del);
|
|
|
|
ecore_event_handler_del(pd->handler_data);
|
|
|
|
|
2016-03-01 10:06:28 -08:00
|
|
|
eo_destructor(eo_super(obj, ECORE_CON_EET_CLIENT_OBJ_CLASS));
|
2015-06-22 09:55:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
EOLIAN static Eo_Base *
|
|
|
|
_ecore_con_eet_base_eo_base_constructor(Eo *obj, Ecore_Con_Eet_Base_Data *pd)
|
|
|
|
{
|
2016-03-01 10:06:28 -08:00
|
|
|
obj = eo_constructor(eo_super(obj, ECORE_CON_EET_BASE_CLASS));
|
2015-06-22 09:55:54 -07:00
|
|
|
|
|
|
|
if (!obj) return NULL;
|
|
|
|
|
|
|
|
pd->data_callbacks = eina_hash_stringshared_new(_ecore_con_eet_data_free);
|
|
|
|
pd->raw_data_callbacks = eina_hash_string_superfast_new(_ecore_con_eet_raw_data_free);
|
|
|
|
|
|
|
|
_ecore_con_eet_data_descriptor_setup(pd);
|
|
|
|
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
EOLIAN static void
|
|
|
|
_ecore_con_eet_base_eo_base_destructor(Eo *obj, Ecore_Con_Eet_Base_Data *pd)
|
|
|
|
{
|
2016-03-01 10:06:28 -08:00
|
|
|
eo_destructor(eo_super(obj, ECORE_CON_EET_BASE_CLASS));
|
2015-06-22 09:55:54 -07:00
|
|
|
|
|
|
|
eet_data_descriptor_free(pd->edd);
|
|
|
|
eet_data_descriptor_free(pd->matching);
|
|
|
|
eina_hash_free(pd->data_callbacks);
|
|
|
|
eina_hash_free(pd->raw_data_callbacks);
|
|
|
|
}
|
|
|
|
|
|
|
|
EOLIAN static Eo_Base *
|
|
|
|
_ecore_con_eet_base_eo_base_finalize(Eo *obj, Ecore_Con_Eet_Base_Data *pd)
|
|
|
|
{
|
|
|
|
if (pd->server) return obj;
|
|
|
|
|
|
|
|
eet_data_descriptor_free(pd->edd);
|
|
|
|
eet_data_descriptor_free(pd->matching);
|
|
|
|
eina_hash_free(pd->data_callbacks);
|
|
|
|
eina_hash_free(pd->raw_data_callbacks);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
EOLIAN static void
|
|
|
|
_ecore_con_eet_base_server_set(Eo *obj EINA_UNUSED, Ecore_Con_Eet_Base_Data *pd, Ecore_Con_Server *data)
|
|
|
|
{
|
2016-02-04 23:09:53 -08:00
|
|
|
if (!eo_isa(data, EFL_NETWORK_SERVER_CLASS))
|
2015-06-22 09:55:54 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
pd->server = data;
|
|
|
|
}
|
|
|
|
|
|
|
|
EOLIAN static Ecore_Con_Server *
|
|
|
|
_ecore_con_eet_base_server_get(Eo *obj EINA_UNUSED, Ecore_Con_Eet_Base_Data *pd)
|
|
|
|
{
|
|
|
|
return pd->server;
|
|
|
|
}
|
|
|
|
|
2012-08-30 23:39:57 -07:00
|
|
|
/**************
|
2013-12-19 21:07:50 -08:00
|
|
|
* Global API *
|
|
|
|
**************/
|
2012-08-30 23:39:57 -07:00
|
|
|
|
|
|
|
EAPI Ecore_Con_Eet *
|
2012-08-30 20:11:24 -07:00
|
|
|
ecore_con_eet_server_new(Ecore_Con_Server *server)
|
|
|
|
{
|
2015-06-22 09:55:54 -07:00
|
|
|
Ecore_Con_Eet *ece_obj;
|
2012-08-30 20:11:24 -07:00
|
|
|
|
|
|
|
if (!server) return NULL;
|
|
|
|
|
2016-03-15 07:07:52 -07:00
|
|
|
ece_obj = eo_add(ECORE_CON_EET_SERVER_OBJ_CLASS, NULL, ecore_con_eet_base_server_set(eo_self, server));
|
2012-08-30 20:11:24 -07:00
|
|
|
|
2015-06-22 09:55:54 -07:00
|
|
|
return ece_obj;
|
2012-08-30 20:11:24 -07:00
|
|
|
}
|
|
|
|
|
2012-08-30 23:39:57 -07:00
|
|
|
EAPI Ecore_Con_Eet *
|
2012-08-30 20:11:24 -07:00
|
|
|
ecore_con_eet_client_new(Ecore_Con_Server *server)
|
|
|
|
{
|
2015-06-22 09:55:54 -07:00
|
|
|
Ecore_Con_Eet *ece_obj;
|
2012-08-30 20:11:24 -07:00
|
|
|
|
|
|
|
if (!server) return NULL;
|
|
|
|
|
2016-03-15 07:07:52 -07:00
|
|
|
ece_obj = eo_add(ECORE_CON_EET_CLIENT_OBJ_CLASS, NULL, ecore_con_eet_base_server_set(eo_self, server));
|
2012-08-30 20:11:24 -07:00
|
|
|
|
2015-06-22 09:55:54 -07:00
|
|
|
return ece_obj;
|
2012-08-30 20:11:24 -07:00
|
|
|
}
|
|
|
|
|
2012-08-30 23:39:57 -07:00
|
|
|
EAPI void
|
2012-08-30 20:11:24 -07:00
|
|
|
ecore_con_eet_server_free(Ecore_Con_Eet *r)
|
|
|
|
{
|
Revert "Eo: Remove eo_del() and make eo_unref() the replacement."
This reverts commit 546ff7bbba788ec834c5608361c0834853f2d5d7.
It seems that eo_del() is useful and removing it was creating bugs.
The issue is that the way we defined parents in eo, both the parent and
the programmer share a reference to the object. When we eo_unref() that
reference as the programmer, eo has no way to know it's this specific
reference we are freeing, and not a general one, so in some
circumstances, for example:
eo_ref(child);
eo_unref(child); // trying to delete here
eo_unref(container); // container is deleted here
eo_unref(child); // child already has 0 refs before this point.
We would have an issue with references and objects being freed too soon
and in general, issue with the references.
Having eo_del() solves that, because this one explicitly unparents if
there is a parent, meaning the reference ownership is explicitly taken
by the programmer.
eo_del() is essentially a convenience function around "check if has
parent, and if so unparent, otherwise, unref". Which should be used when
you want to delete an object although it has a parent, and is equivalent
to eo_unref() when it doesn't have one.
2016-06-01 05:14:30 -07:00
|
|
|
eo_del(r);
|
2012-08-30 20:11:24 -07:00
|
|
|
}
|
|
|
|
|
2012-08-30 23:39:57 -07:00
|
|
|
EAPI void
|
2012-08-30 20:11:24 -07:00
|
|
|
ecore_con_eet_register(Ecore_Con_Eet *ece, const char *name, Eet_Data_Descriptor *edd)
|
|
|
|
{
|
2016-03-01 10:06:28 -08:00
|
|
|
ecore_con_eet_base_register(ece, name, edd);
|
2012-08-30 20:11:24 -07:00
|
|
|
}
|
|
|
|
|
2012-08-30 23:39:57 -07:00
|
|
|
EAPI void
|
2012-08-30 20:11:24 -07:00
|
|
|
ecore_con_eet_data_callback_add(Ecore_Con_Eet *ece, const char *name, Ecore_Con_Eet_Data_Cb func, const void *data)
|
|
|
|
{
|
2016-03-01 10:06:28 -08:00
|
|
|
ecore_con_eet_base_data_callback_set(ece, name, func, data);
|
2012-08-30 20:11:24 -07:00
|
|
|
}
|
|
|
|
|
2012-08-30 23:39:57 -07:00
|
|
|
EAPI void
|
2012-08-30 20:11:24 -07:00
|
|
|
ecore_con_eet_data_callback_del(Ecore_Con_Eet *ece, const char *name)
|
|
|
|
{
|
2016-03-01 10:06:28 -08:00
|
|
|
ecore_con_eet_base_data_callback_del(ece, name);
|
2012-08-30 20:11:24 -07:00
|
|
|
}
|
|
|
|
|
2012-08-30 23:39:57 -07:00
|
|
|
EAPI void
|
2012-08-30 20:11:24 -07:00
|
|
|
ecore_con_eet_raw_data_callback_add(Ecore_Con_Eet *ece, const char *name, Ecore_Con_Eet_Raw_Data_Cb func, const void *data)
|
|
|
|
{
|
2016-03-01 10:06:28 -08:00
|
|
|
ecore_con_eet_base_raw_data_callback_set(ece, name, func, data);
|
2012-08-30 20:11:24 -07:00
|
|
|
}
|
|
|
|
|
2012-08-30 23:39:57 -07:00
|
|
|
EAPI void
|
2012-08-30 20:11:24 -07:00
|
|
|
ecore_con_eet_raw_data_callback_del(Ecore_Con_Eet *ece, const char *name)
|
|
|
|
{
|
2016-03-01 10:06:28 -08:00
|
|
|
ecore_con_eet_base_raw_data_callback_del(ece, name);
|
2012-08-30 20:11:24 -07:00
|
|
|
}
|
|
|
|
|
2012-08-30 23:39:57 -07:00
|
|
|
EAPI void
|
2012-08-30 20:11:24 -07:00
|
|
|
ecore_con_eet_client_connect_callback_add(Ecore_Con_Eet *ece, Ecore_Con_Eet_Client_Cb func, const void *data)
|
|
|
|
{
|
2015-06-22 09:55:54 -07:00
|
|
|
Ecore_Con_Eet_Server_Obj_Data *eces = eo_data_scope_get(ece, ECORE_CON_EET_SERVER_OBJ_CLASS);
|
2012-08-30 20:11:24 -07:00
|
|
|
Ecore_Con_Eet_Client *c;
|
|
|
|
|
2015-06-22 09:55:54 -07:00
|
|
|
if (!eces || !func) return;
|
2012-08-30 20:11:24 -07:00
|
|
|
|
|
|
|
c = calloc(1, sizeof (Ecore_Con_Eet_Client));
|
2013-06-20 04:28:18 -07:00
|
|
|
if (!c) return;
|
2012-08-30 20:11:24 -07:00
|
|
|
|
|
|
|
c->func = func;
|
|
|
|
c->data = data;
|
|
|
|
|
2015-06-22 09:55:54 -07:00
|
|
|
eces->client_connect_callbacks = eina_list_append(eces->client_connect_callbacks, c);
|
2012-08-30 20:11:24 -07:00
|
|
|
}
|
|
|
|
|
2012-08-30 23:39:57 -07:00
|
|
|
EAPI void
|
2012-08-30 20:11:24 -07:00
|
|
|
ecore_con_eet_client_connect_callback_del(Ecore_Con_Eet *ece, Ecore_Con_Eet_Client_Cb func, const void *data)
|
|
|
|
{
|
2015-06-22 09:55:54 -07:00
|
|
|
Ecore_Con_Eet_Server_Obj_Data *eces = eo_data_scope_get(ece, ECORE_CON_EET_SERVER_OBJ_CLASS);
|
2012-08-30 20:11:24 -07:00
|
|
|
Ecore_Con_Eet_Client *c;
|
|
|
|
Eina_List *l;
|
|
|
|
|
2015-06-22 09:55:54 -07:00
|
|
|
if (!eces || !func) return;
|
2012-08-30 20:11:24 -07:00
|
|
|
|
2015-06-22 09:55:54 -07:00
|
|
|
EINA_LIST_FOREACH(eces->client_connect_callbacks, l, c)
|
2012-08-30 20:11:24 -07:00
|
|
|
if (c->func == func && c->data == data)
|
|
|
|
{
|
2015-06-22 09:55:54 -07:00
|
|
|
eces->client_connect_callbacks = eina_list_remove_list(eces->client_connect_callbacks, l);
|
2012-08-30 20:11:24 -07:00
|
|
|
free(c);
|
2013-06-20 04:28:18 -07:00
|
|
|
return;
|
2012-08-30 20:11:24 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-30 23:39:57 -07:00
|
|
|
EAPI void
|
2012-08-30 20:11:24 -07:00
|
|
|
ecore_con_eet_client_disconnect_callback_add(Ecore_Con_Eet *ece, Ecore_Con_Eet_Client_Cb func, const void *data)
|
|
|
|
{
|
2015-06-22 09:55:54 -07:00
|
|
|
Ecore_Con_Eet_Server_Obj_Data *eces = eo_data_scope_get(ece, ECORE_CON_EET_SERVER_OBJ_CLASS);
|
2012-08-30 20:11:24 -07:00
|
|
|
Ecore_Con_Eet_Client *c;
|
|
|
|
|
2015-06-22 09:55:54 -07:00
|
|
|
if (!eces || !func) return;
|
2012-08-30 20:11:24 -07:00
|
|
|
|
|
|
|
c = calloc(1, sizeof (Ecore_Con_Eet_Client));
|
2013-06-20 04:28:18 -07:00
|
|
|
if (!c) return;
|
2012-08-30 20:11:24 -07:00
|
|
|
|
|
|
|
c->func = func;
|
|
|
|
c->data = data;
|
|
|
|
|
2015-06-22 09:55:54 -07:00
|
|
|
eces->client_disconnect_callbacks = eina_list_append(eces->client_disconnect_callbacks, c);
|
2012-08-30 20:11:24 -07:00
|
|
|
}
|
|
|
|
|
2012-08-30 23:39:57 -07:00
|
|
|
EAPI void
|
2012-08-30 20:11:24 -07:00
|
|
|
ecore_con_eet_client_disconnect_callback_del(Ecore_Con_Eet *ece, Ecore_Con_Eet_Client_Cb func, const void *data)
|
|
|
|
{
|
2015-06-22 09:55:54 -07:00
|
|
|
Ecore_Con_Eet_Server_Obj_Data *eced = eo_data_scope_get(ece, ECORE_CON_EET_SERVER_OBJ_CLASS);
|
2012-08-30 20:11:24 -07:00
|
|
|
Ecore_Con_Eet_Client *c;
|
|
|
|
Eina_List *l;
|
|
|
|
|
2015-06-22 09:55:54 -07:00
|
|
|
if (!eced || !func) return;
|
2012-08-30 20:11:24 -07:00
|
|
|
|
2015-06-22 09:55:54 -07:00
|
|
|
EINA_LIST_FOREACH(eced->client_disconnect_callbacks, l, c)
|
2012-08-30 20:11:24 -07:00
|
|
|
if (c->func == func && c->data == data)
|
|
|
|
{
|
2015-06-22 09:55:54 -07:00
|
|
|
eced->client_disconnect_callbacks = eina_list_remove_list(eced->client_disconnect_callbacks, l);
|
2012-08-30 20:11:24 -07:00
|
|
|
free(c);
|
2013-06-20 04:28:18 -07:00
|
|
|
return;
|
2012-08-30 20:11:24 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-30 23:39:57 -07:00
|
|
|
EAPI void
|
2012-08-30 20:11:24 -07:00
|
|
|
ecore_con_eet_server_connect_callback_add(Ecore_Con_Eet *ece, Ecore_Con_Eet_Server_Cb func, const void *data)
|
|
|
|
{
|
2015-06-22 09:55:54 -07:00
|
|
|
Ecore_Con_Eet_Client_Obj_Data *eced = eo_data_scope_get(ece, ECORE_CON_EET_CLIENT_OBJ_CLASS);
|
2012-08-30 20:11:24 -07:00
|
|
|
Ecore_Con_Eet_Server *s;
|
|
|
|
|
2015-06-22 09:55:54 -07:00
|
|
|
if (!eced || !func) return;
|
2012-08-30 20:11:24 -07:00
|
|
|
|
|
|
|
s = calloc(1, sizeof (Ecore_Con_Eet_Server));
|
2013-06-20 04:28:18 -07:00
|
|
|
if (!s) return;
|
2012-08-30 20:11:24 -07:00
|
|
|
|
|
|
|
s->func = func;
|
|
|
|
s->data = data;
|
|
|
|
|
2015-06-22 09:55:54 -07:00
|
|
|
eced->server_connect_callbacks = eina_list_append(eced->server_connect_callbacks, s);
|
2012-08-30 20:11:24 -07:00
|
|
|
}
|
|
|
|
|
2012-08-30 23:39:57 -07:00
|
|
|
EAPI void
|
2012-08-30 20:11:24 -07:00
|
|
|
ecore_con_eet_server_connect_callback_del(Ecore_Con_Eet *ece, Ecore_Con_Eet_Server_Cb func, const void *data)
|
|
|
|
{
|
2015-06-22 09:55:54 -07:00
|
|
|
Ecore_Con_Eet_Client_Obj_Data *eced = eo_data_scope_get(ece, ECORE_CON_EET_CLIENT_OBJ_CLASS);
|
2012-08-30 20:11:24 -07:00
|
|
|
Ecore_Con_Eet_Server *s;
|
|
|
|
Eina_List *l;
|
|
|
|
|
2015-06-22 09:55:54 -07:00
|
|
|
if (!eced || !func) return;
|
2012-08-30 20:11:24 -07:00
|
|
|
|
2015-06-22 09:55:54 -07:00
|
|
|
EINA_LIST_FOREACH(eced->server_connect_callbacks, l, s)
|
2012-08-30 20:11:24 -07:00
|
|
|
if (s->func == func && s->data == data)
|
|
|
|
{
|
2015-06-22 09:55:54 -07:00
|
|
|
eced->server_connect_callbacks = eina_list_remove_list(eced->server_connect_callbacks, l);
|
2012-08-30 20:11:24 -07:00
|
|
|
free(s);
|
2013-06-20 04:28:18 -07:00
|
|
|
return;
|
2012-08-30 20:11:24 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-30 23:39:57 -07:00
|
|
|
EAPI void
|
2012-08-30 20:11:24 -07:00
|
|
|
ecore_con_eet_server_disconnect_callback_add(Ecore_Con_Eet *ece, Ecore_Con_Eet_Server_Cb func, const void *data)
|
|
|
|
{
|
2015-06-22 09:55:54 -07:00
|
|
|
Ecore_Con_Eet_Client_Obj_Data *eced = eo_data_scope_get(ece, ECORE_CON_EET_CLIENT_OBJ_CLASS);
|
2012-08-30 20:11:24 -07:00
|
|
|
Ecore_Con_Eet_Server *s;
|
|
|
|
|
2015-06-22 09:55:54 -07:00
|
|
|
if (!eced || !func) return;
|
2012-08-30 20:11:24 -07:00
|
|
|
|
|
|
|
s = calloc(1, sizeof (Ecore_Con_Eet_Server));
|
2013-06-20 04:28:18 -07:00
|
|
|
if (!s) return;
|
2012-08-30 20:11:24 -07:00
|
|
|
|
|
|
|
s->func = func;
|
|
|
|
s->data = data;
|
|
|
|
|
2015-06-22 09:55:54 -07:00
|
|
|
eced->server_disconnect_callbacks = eina_list_append(eced->server_disconnect_callbacks, s);
|
2012-08-30 20:11:24 -07:00
|
|
|
}
|
|
|
|
|
2012-08-30 23:39:57 -07:00
|
|
|
EAPI void
|
2012-08-30 20:11:24 -07:00
|
|
|
ecore_con_eet_server_disconnect_callback_del(Ecore_Con_Eet *ece, Ecore_Con_Eet_Server_Cb func, const void *data)
|
|
|
|
{
|
2015-06-22 09:55:54 -07:00
|
|
|
Ecore_Con_Eet_Client_Obj_Data *eced = eo_data_scope_get(ece, ECORE_CON_EET_CLIENT_OBJ_CLASS);
|
2012-08-30 20:11:24 -07:00
|
|
|
Ecore_Con_Eet_Server *s;
|
|
|
|
Eina_List *l;
|
|
|
|
|
2015-06-22 09:55:54 -07:00
|
|
|
if (!eced || !func) return;
|
2012-08-30 20:11:24 -07:00
|
|
|
|
2015-06-22 09:55:54 -07:00
|
|
|
EINA_LIST_FOREACH(eced->server_disconnect_callbacks, l, s)
|
2012-08-30 20:11:24 -07:00
|
|
|
if (s->func == func && s->data == data)
|
|
|
|
{
|
2015-06-22 09:55:54 -07:00
|
|
|
eced->server_disconnect_callbacks = eina_list_remove_list(eced->server_disconnect_callbacks, l);
|
2012-08-30 20:11:24 -07:00
|
|
|
free(s);
|
2013-06-20 04:28:18 -07:00
|
|
|
return;
|
2012-08-30 20:11:24 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-30 23:39:57 -07:00
|
|
|
EAPI void
|
2012-08-30 20:11:24 -07:00
|
|
|
ecore_con_eet_data_set(Ecore_Con_Eet *ece, const void *data)
|
|
|
|
{
|
2016-03-01 10:06:28 -08:00
|
|
|
eo_key_data_set(ece, ECORE_CON_EET_DATA_KEY, data);
|
2012-08-30 20:11:24 -07:00
|
|
|
}
|
|
|
|
|
2015-06-29 05:21:13 -07:00
|
|
|
EAPI const void *
|
2012-08-30 20:11:24 -07:00
|
|
|
ecore_con_eet_data_get(Ecore_Con_Eet *ece)
|
|
|
|
{
|
2016-03-01 10:06:28 -08:00
|
|
|
return eo_key_data_get(ece, ECORE_CON_EET_DATA_KEY);
|
2012-08-30 20:11:24 -07:00
|
|
|
}
|
|
|
|
|
2012-08-30 23:39:57 -07:00
|
|
|
EAPI Ecore_Con_Eet *
|
2012-08-30 20:11:24 -07:00
|
|
|
ecore_con_eet_reply(Ecore_Con_Reply *reply)
|
|
|
|
{
|
|
|
|
if (!reply) return NULL;
|
|
|
|
return reply->ece;
|
|
|
|
}
|
|
|
|
|
2012-08-30 23:39:57 -07:00
|
|
|
EAPI void
|
2012-08-30 20:11:24 -07:00
|
|
|
ecore_con_eet_send(Ecore_Con_Reply *reply, const char *name, void *value)
|
|
|
|
{
|
2016-03-01 10:06:28 -08:00
|
|
|
ecore_con_eet_base_send(reply->ece, reply, name, value);
|
2012-08-30 20:11:24 -07:00
|
|
|
}
|
|
|
|
|
2012-08-30 23:39:57 -07:00
|
|
|
EAPI void
|
2012-08-30 20:11:24 -07:00
|
|
|
ecore_con_eet_raw_send(Ecore_Con_Reply *reply, const char *protocol_name, const char *section, void *value, unsigned int length)
|
|
|
|
{
|
2016-03-01 10:06:28 -08:00
|
|
|
ecore_con_eet_base_raw_send(reply->ece, reply, protocol_name, section, value, length);
|
2012-08-30 20:11:24 -07:00
|
|
|
}
|
|
|
|
|
2015-06-22 09:55:54 -07:00
|
|
|
#include "ecore_con_eet_base.eo.c"
|
|
|
|
#include "ecore_con_eet_server_obj.eo.c"
|
|
|
|
#include "ecore_con_eet_client_obj.eo.c"
|