* ecore: add ecore_con_lookup for dns request retrieval.

NOTE: ecore_con_info_get is now private has it can't be used outside of Ecore_Con.


SVN revision: 50425
This commit is contained in:
Cedric BAIL 2010-07-22 11:32:55 +00:00
parent 0ffbf90242
commit 7726478790
3 changed files with 108 additions and 4 deletions

View File

@ -75,9 +75,12 @@ extern "C" {
typedef struct _Ecore_Con_Server Ecore_Con_Server; /**< A connection handle */
typedef struct _Ecore_Con_Client Ecore_Con_Client; /**< A connection handle */
typedef struct _Ecore_Con_Url Ecore_Con_Url;
typedef struct _Ecore_Con_Info Ecore_Con_Info;
typedef void (*Ecore_Con_Info_Cb)(void *data, Ecore_Con_Info *infos);
typedef void (*Ecore_Con_Dns_Cb)(const char *canonname,
const char *ip,
struct sockaddr *addr,
int addrlen,
void *data);
typedef enum _Ecore_Con_Type
{
@ -89,7 +92,7 @@ extern "C" {
ECORE_CON_REMOTE_UDP = 5,
ECORE_CON_REMOTE_BROADCAST = 6,
ECORE_CON_REMOTE_NODELAY = 7,
ECORE_CON_USE_SSL2 = (1 << 4),
ECORE_CON_USE_SSL3 = (1 << 5),
ECORE_CON_USE_TLS = (1 << 6)
@ -227,7 +230,7 @@ extern "C" {
EAPI int ecore_con_url_send(Ecore_Con_Url *url_con, const void *data, size_t length, const char *content_type);
EAPI void ecore_con_url_time(Ecore_Con_Url *url_con, Ecore_Con_Url_Time condition, time_t tm);
EAPI int ecore_con_info_get(Ecore_Con_Server *svr, Ecore_Con_Info_Cb done_cb, void *data, struct addrinfo *hints);
EAPI Eina_Bool ecore_con_lookup(const char *name, Ecore_Con_Dns_Cb done_cb, const void *data);
EAPI int ecore_con_url_ftp_upload(Ecore_Con_Url *url_con, const char *filename, const char *user, const char *pass, const char *upload_dir);
EAPI void ecore_con_url_verbose_set(Ecore_Con_Url *url_con, int verbose);

View File

@ -71,6 +71,8 @@ static void _ecore_con_event_server_add_free(void *data, void *ev);
static void _ecore_con_event_server_del_free(void *data, void *ev);
static void _ecore_con_event_server_data_free(void *data, void *ev);
static void _ecore_con_lookup_done(void *data, Ecore_Con_Info *infos);
EAPI int ECORE_CON_EVENT_CLIENT_ADD = 0;
EAPI int ECORE_CON_EVENT_CLIENT_DEL = 0;
EAPI int ECORE_CON_EVENT_SERVER_ADD = 0;
@ -742,6 +744,68 @@ ecore_con_client_flush(Ecore_Con_Client *cl)
_ecore_con_client_flush(cl);
}
/**
* Do an asynchronous DNS lookup.
*
* @params name IP address or server name to translate.
* @params done_cb Callback to notify when done.
* @params data User data to be given to done_cb.
* @return EINA_TRUE if the request is going on, EINA_FALSE if it failed.
*/
EAPI Eina_Bool
ecore_con_lookup(const char *name, Ecore_Con_Dns_Cb done_cb, const void *data)
{
Ecore_Con_Server *svr;
Ecore_Con_Lookup *lk;
struct addrinfo hints;
if (!name || !done_cb)
return EINA_FALSE;
svr = calloc(1, sizeof(Ecore_Con_Server));
if (!svr) return EINA_FALSE;
lk = malloc(sizeof (Ecore_Con_Lookup));
if (!lk)
{
free(svr);
return EINA_FALSE;
}
lk->done_cb = done_cb;
lk->data = data;
svr->name = strdup(name);
if (!svr->name) goto on_error;
svr->type = ECORE_CON_REMOTE_TCP;
svr->port = 1025;
svr->data = lk;
svr->created = 1;
svr->reject_excess_clients = 0;
svr->client_limit = -1;
svr->clients = NULL;
svr->ppid = getpid();
memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_family = AF_INET6;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_CANONNAME;
hints.ai_protocol = IPPROTO_TCP;
hints.ai_canonname = NULL;
hints.ai_next = NULL;
hints.ai_addr = NULL;
if (ecore_con_info_get(svr, _ecore_con_lookup_done, svr, &hints))
return EINA_TRUE;
free(svr->name);
on_error:
free(lk);
free(svr);
return EINA_FALSE;
}
static void
_ecore_con_server_free(Ecore_Con_Server *svr)
{
@ -1711,3 +1775,23 @@ _ecore_con_event_server_data_free(void *data __UNUSED__, void *ev)
_ecore_con_server_free(e->server);
free(e);
}
static void
_ecore_con_lookup_done(void *data, Ecore_Con_Info *infos)
{
Ecore_Con_Server *svr;
Ecore_Con_Lookup *lk;
svr = data;
lk = svr->data;
if (infos)
lk->done_cb(infos->info.ai_canonname, infos->ip, infos->info.ai_addr, infos->info.ai_addrlen, (void*) lk->data);
else
lk->done_cb(NULL, NULL, NULL, 0, (void*) lk->data);
free(svr->name);
free(lk);
free(svr);
}

View File

@ -54,6 +54,11 @@ extern int _ecore_con_log_dom ;
#endif
#define CRIT(...) EINA_LOG_DOM_CRIT(_ecore_con_log_dom, __VA_ARGS__)
typedef struct _Ecore_Con_Lookup Ecore_Con_Lookup;
typedef struct _Ecore_Con_Info Ecore_Con_Info;
typedef void (*Ecore_Con_Info_Cb)(void *data, Ecore_Con_Info *infos);
typedef enum _Ecore_Con_State
{
ECORE_CON_CONNECTED,
@ -163,6 +168,12 @@ struct _Ecore_Con_Info
char service[NI_MAXSERV];
};
struct _Ecore_Con_Lookup
{
Ecore_Con_Dns_Cb done_cb;
const void *data;
};
/* from ecore_local.c */
int ecore_con_local_init(void);
int ecore_con_local_shutdown(void);
@ -191,5 +202,11 @@ Ecore_Con_State ecore_con_ssl_client_try(Ecore_Con_Client *svr);
int ecore_con_ssl_client_read(Ecore_Con_Client *svr, unsigned char *buf, int size);
int ecore_con_ssl_client_write(Ecore_Con_Client *svr, unsigned char *buf, int size);
int ecore_con_info_get(Ecore_Con_Server *svr,
Ecore_Con_Info_Cb done_cb,
void *data,
struct addrinfo *hints);
#endif