From: Enlightenment S. <no-...@en...> - 2008-10-07 12:41:51
|
Log: More cleanup and export a replacement for ecore_con_dns_lookup. Author: cedric Date: 2008-10-07 05:41:36 -0700 (Tue, 07 Oct 2008) New Revision: 36497 Modified: trunk/ecore/src/lib/ecore_con/Ecore_Con.h trunk/ecore/src/lib/ecore_con/ecore_con.c trunk/ecore/src/lib/ecore_con/ecore_con_info.c trunk/ecore/src/lib/ecore_con/ecore_con_private.h Modified: trunk/ecore/src/lib/ecore_con/Ecore_Con.h =================================================================== --- trunk/ecore/src/lib/ecore_con/Ecore_Con.h 2008-10-07 12:36:13 UTC (rev 36496) +++ trunk/ecore/src/lib/ecore_con/Ecore_Con.h 2008-10-07 12:41:36 UTC (rev 36497) @@ -44,15 +44,15 @@ * There are two main objects in the @c Ecore_Con library: the @c * Ecore_Con_Server and the @c Ecore_Con_Client. * - * The @c Ecore_Con_Server represents a server that can be connected to. - * It is used regardless of whether the program is acting as a server or + * The @c Ecore_Con_Server represents a server that can be connected to. + * It is used regardless of whether the program is acting as a server or * client itself. * * To create a listening server, call @c ecore_con_server_add(). * * To connect to a server, call @c ecore_con_server_connect(). Data can * then be sent to the server using the @c ecore_con_server_send(). - * + * * Whenever a client connection is made to an @c Ecore_Con_Server, a * @c ECORE_CON_CLIENT_ADD event is emitted. Any event callbacks that are * called receive a @c Ecore_Con_Client object, which represents a @@ -68,12 +68,14 @@ #ifdef __cplusplus extern "C" { #endif - + 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_Netinfo Ecore_Con_Netinfo; + typedef struct _Ecore_Con_Info Ecore_Con_Info; + typedef void (*Ecore_Con_Info_Cb)(void *data, Ecore_Con_Info *infos); + typedef enum _Ecore_Con_Type { ECORE_CON_LOCAL_USER, @@ -126,28 +128,28 @@ { Ecore_Con_Server *server; }; - + struct _Ecore_Con_Event_Client_Data { Ecore_Con_Client *client; void *data; int size; }; - + struct _Ecore_Con_Event_Server_Data { Ecore_Con_Server *server; void *data; int size; }; - + struct _Ecore_Con_Event_Url_Data { Ecore_Con_Url *url_con; int size; unsigned char data[1]; }; - + struct _Ecore_Con_Event_Url_Complete { Ecore_Con_Url *url_con; @@ -176,12 +178,12 @@ EAPI extern int ECORE_CON_EVENT_URL_DATA; EAPI extern int ECORE_CON_EVENT_URL_COMPLETE; EAPI extern int ECORE_CON_EVENT_URL_PROGRESS; - + EAPI int ecore_con_init(void); EAPI int ecore_con_shutdown(void); - + EAPI Ecore_Con_Server *ecore_con_server_add(Ecore_Con_Type type, const char *name, int port, const void *data); - + EAPI Ecore_Con_Server *ecore_con_server_connect(Ecore_Con_Type type, const char *name, int port, const void *data); EAPI void *ecore_con_server_del(Ecore_Con_Server *svr); EAPI void *ecore_con_server_data_get(Ecore_Con_Server *svr); @@ -191,7 +193,7 @@ EAPI void ecore_con_server_client_limit_set(Ecore_Con_Server *svr, int client_limit, char reject_excess_clients); EAPI char *ecore_con_server_ip_get(Ecore_Con_Server *svr); EAPI void ecore_con_server_flush(Ecore_Con_Server *svr); - + EAPI int ecore_con_client_send(Ecore_Con_Client *cl, const void *data, int size); EAPI Ecore_Con_Server *ecore_con_client_server_get(Ecore_Con_Client *cl); EAPI void *ecore_con_client_del(Ecore_Con_Client *cl); @@ -199,7 +201,7 @@ EAPI void *ecore_con_client_data_get(Ecore_Con_Client *cl); EAPI char *ecore_con_client_ip_get(Ecore_Con_Client *cl); EAPI void ecore_con_client_flush(Ecore_Con_Client *cl); - + EAPI int ecore_con_ssl_available_get(void); EAPI int ecore_con_url_init(void); @@ -219,7 +221,8 @@ void (*done_cb)(void *data, struct hostent *hostent), void *data); #endif - + EAPI int ecore_con_info_get(Ecore_Con_Server *svr, Ecore_Con_Info_Cb done_cb, void *data, struct addrinfo *hints); + EAPI int ecore_con_url_ftp_upload(Ecore_Con_Url *url_con, char *filename, char *user, char *pass, char *upload_dir); EAPI void ecore_con_url_verbose_set(Ecore_Con_Url *url_con, int verbose); EAPI void ecore_con_url_ftp_use_epsv_set(Ecore_Con_Url *url_con, int use_epsv); Modified: trunk/ecore/src/lib/ecore_con/ecore_con.c =================================================================== --- trunk/ecore/src/lib/ecore_con/ecore_con.c 2008-10-07 12:36:13 UTC (rev 36496) +++ trunk/ecore/src/lib/ecore_con/ecore_con.c 2008-10-07 12:41:36 UTC (rev 36497) @@ -26,10 +26,10 @@ # include <winsock2.h> #endif -static void _ecore_con_cb_tcp_connect(void *data, Ecore_Con_Netinfo *info); -static void _ecore_con_cb_udp_connect(void *data, Ecore_Con_Netinfo *info); -static void _ecore_con_cb_tcp_listen(void *data, Ecore_Con_Netinfo *info); -static void _ecore_con_cb_udp_listen(void *data, Ecore_Con_Netinfo *info); +static void _ecore_con_cb_tcp_connect(void *data, Ecore_Con_Info *info); +static void _ecore_con_cb_udp_connect(void *data, Ecore_Con_Info *info); +static void _ecore_con_cb_tcp_listen(void *data, Ecore_Con_Info *info); +static void _ecore_con_cb_udp_listen(void *data, Ecore_Con_Info *info); static void _ecore_con_server_free(Ecore_Con_Server *svr); static void _ecore_con_client_free(Ecore_Con_Client *cl); @@ -185,6 +185,7 @@ struct sockaddr_un socket_unix; struct linger lin; char buf[4096]; + mode_t pmode; if (port < 0) return NULL; /* local user socket: FILE: ~/.ecore/[name]/[port] */ @@ -215,7 +216,7 @@ { const char *homedir; struct stat st; - mode_t pmode, mask; + mode_t mask; int socket_unix_len; if (!name) goto error; @@ -252,28 +253,12 @@ pmode = umask(mask); start: svr->fd = socket(AF_UNIX, SOCK_STREAM, 0); - if (svr->fd < 0) - { - umask(pmode); - goto error; - } - if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) - { - umask(pmode); - goto error; - } - if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) - { - umask(pmode); - goto error; - } + if (svr->fd < 0) goto error_umask; + if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error_umask; + if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error_umask; lin.l_onoff = 1; lin.l_linger = 0; - if (setsockopt(svr->fd, SOL_SOCKET, SO_LINGER, &lin, sizeof(struct linger)) < 0) - { - umask(pmode); - goto error; - } + if (setsockopt(svr->fd, SOL_SOCKET, SO_LINGER, &lin, sizeof(struct linger)) < 0) goto error_umask; socket_unix.sun_family = AF_UNIX; if (type == ECORE_CON_LOCAL_ABSTRACT) { @@ -285,8 +270,7 @@ socket_unix_len = LENGTH_OF_ABSTRACT_SOCKADDR_UN(&socket_unix, name); #else fprintf(stderr, "Your system does not support abstract sockets!\n"); - umask(pmode); - goto error; + goto error_umask; #endif } else @@ -303,36 +287,19 @@ (type == ECORE_CON_LOCAL_SYSTEM)) { if (unlink(buf) < 0) - { - umask(pmode); - goto error; - } + goto error_umask; else goto start; } else - { - umask(pmode); - goto error; - } + goto error_umask; } else - { - umask(pmode); - goto error; - } + goto error_umask; } - if (listen(svr->fd, 4096) < 0) - { - umask(pmode); - goto error; - } + if (listen(svr->fd, 4096) < 0) goto error_umask; svr->path = strdup(buf); - if (!svr->path) - { - umask(pmode); - goto error; - } + if (!svr->path) goto error_umask; svr->fd_handler = ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ, _ecore_con_svr_handler, svr, NULL, NULL); @@ -355,6 +322,8 @@ return svr; + error_umask: + umask(pmode); error: if (svr->name) free(svr->name); if (svr->path) free(svr->path); @@ -1127,7 +1096,7 @@ } static void -_ecore_con_cb_tcp_listen(void *data, Ecore_Con_Netinfo *net_info) +_ecore_con_cb_tcp_listen(void *data, Ecore_Con_Info *net_info) { Ecore_Con_Server *svr; struct linger lin; @@ -1161,7 +1130,7 @@ } static void -_ecore_con_cb_udp_listen(void *data, Ecore_Con_Netinfo *net_info) +_ecore_con_cb_udp_listen(void *data, Ecore_Con_Info *net_info) { Ecore_Con_Server *svr; Ecore_Con_Type type; @@ -1215,7 +1184,7 @@ } static void -_ecore_con_cb_tcp_connect(void *data, Ecore_Con_Netinfo *net_info) +_ecore_con_cb_tcp_connect(void *data, Ecore_Con_Info *net_info) { Ecore_Con_Server *svr; struct sockaddr_in socket_addr; @@ -1259,7 +1228,7 @@ } static void -_ecore_con_cb_udp_connect(void *data, Ecore_Con_Netinfo *net_info) +_ecore_con_cb_udp_connect(void *data, Ecore_Con_Info *net_info) { Ecore_Con_Server *svr; struct sockaddr_in socket_addr; Modified: trunk/ecore/src/lib/ecore_con/ecore_con_info.c =================================================================== --- trunk/ecore/src/lib/ecore_con/ecore_con_info.c 2008-10-07 12:36:13 UTC (rev 36496) +++ trunk/ecore/src/lib/ecore_con/ecore_con_info.c 2008-10-07 12:41:36 UTC (rev 36497) @@ -20,12 +20,10 @@ typedef struct _CB_Data CB_Data; -typedef void (*CB_Func)(void *data, Ecore_Con_Netinfo *infos); - struct _CB_Data { Ecore_List2 __list_data; - CB_Func cb_done; + Ecore_Con_Info_Cb cb_done; void *data; Ecore_Fd_Handler *fdh; pid_t pid; @@ -34,7 +32,6 @@ }; -static int _ecore_con_info_get(Ecore_Con_Server *svr, CB_Func done_cb, void *data); static void _ecore_con_info_readdata(CB_Data *cbdata); static void _ecore_con_info_slave_free(CB_Data *cbdata); static int _ecore_con_info_data_handler(void *data, Ecore_Fd_Handler *fd_handler); @@ -42,16 +39,15 @@ static int info_init = 0; static Ecore_List2 *info_slaves = NULL; -static struct addrinfo hints; -int +EAPI int ecore_con_info_init(void) { info_init++; return info_init; } -int +EAPI int ecore_con_info_shutdown(void) { info_init--; @@ -62,11 +58,13 @@ return info_init; } -int +EAPI int ecore_con_info_tcp_connect(Ecore_Con_Server *svr, - CB_Func done_cb, + Ecore_Con_Info_Cb done_cb, void *data) { + struct addrinfo hints; + memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; @@ -76,14 +74,16 @@ hints.ai_next = NULL; hints.ai_addr = NULL; - return _ecore_con_info_get(svr, done_cb, data); + return ecore_con_info_get(svr, done_cb, data, &hints); } -int +EAPI int ecore_con_info_tcp_listen(Ecore_Con_Server *svr, - CB_Func done_cb, + Ecore_Con_Info_Cb done_cb, void *data) { + struct addrinfo hints; + memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; @@ -93,14 +93,16 @@ hints.ai_next = NULL; hints.ai_addr = NULL; - return _ecore_con_info_get(svr, done_cb, data); + return ecore_con_info_get(svr, done_cb, data, &hints); } -int +EAPI int ecore_con_info_udp_connect(Ecore_Con_Server *svr, - CB_Func done_cb, + Ecore_Con_Info_Cb done_cb, void *data) { + struct addrinfo hints; + memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_DGRAM; @@ -110,14 +112,16 @@ hints.ai_next = NULL; hints.ai_addr = NULL; - return _ecore_con_info_get(svr, done_cb, data); + return ecore_con_info_get(svr, done_cb, data, &hints); } -int +EAPI int ecore_con_info_udp_listen(Ecore_Con_Server *svr, - CB_Func done_cb, + Ecore_Con_Info_Cb done_cb, void *data) { + struct addrinfo hints; + memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_DGRAM; @@ -127,14 +131,16 @@ hints.ai_next = NULL; hints.ai_addr = NULL; - return _ecore_con_info_get(svr, done_cb, data); + return ecore_con_info_get(svr, done_cb, data, &hints); } -int -ecore_con_pre_mcast_listen(Ecore_Con_Server *svr, - CB_Func done_cb, +EAPI int +ecore_con_info_mcast_listen(Ecore_Con_Server *svr, + Ecore_Con_Info_Cb done_cb, void *data) { + struct addrinfo hints; + memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_DGRAM; @@ -144,13 +150,14 @@ hints.ai_next = NULL; hints.ai_addr = NULL; - return _ecore_con_info_get(svr, done_cb, data); + return ecore_con_info_get(svr, done_cb, data, &hints); } -static int -_ecore_con_info_get(Ecore_Con_Server *svr, - CB_Func done_cb, - void *data) +EAPI int +ecore_con_info_get(Ecore_Con_Server *svr, + Ecore_Con_Info_Cb done_cb, + void *data, + struct addrinfo *hints) { CB_Data *cbdata; int fd[2]; @@ -179,7 +186,7 @@ if ((cbdata->pid = fork()) == 0) { - Ecore_Con_Netinfo container; + Ecore_Con_Info container; struct addrinfo *result; char service[NI_MAXSERV]; char hbuf[NI_MAXHOST]; @@ -203,7 +210,7 @@ memcpy(container.ip, hbuf, sizeof(container.ip)); memcpy(container.service, sbuf, sizeof(container.service)); } - write(fd[1], &container, sizeof(Ecore_Con_Netinfo)); + write(fd[1], &container, sizeof(Ecore_Con_Info)); } else write(fd[1], "", 1); @@ -232,12 +239,12 @@ static void _ecore_con_info_readdata(CB_Data *cbdata) { - Ecore_Con_Netinfo container; + Ecore_Con_Info container; ssize_t size; size = read(ecore_main_fd_handler_fd_get(cbdata->fdh), &container, - sizeof(Ecore_Con_Netinfo)); - if (size == sizeof(Ecore_Con_Netinfo)) + sizeof(Ecore_Con_Info)); + if (size == sizeof(Ecore_Con_Info)) { container.info.ai_addr = &container.addr; cbdata->cb_done(cbdata->data, &container); Modified: trunk/ecore/src/lib/ecore_con/ecore_con_private.h =================================================================== --- trunk/ecore/src/lib/ecore_con/ecore_con_private.h 2008-10-07 12:36:13 UTC (rev 36496) +++ trunk/ecore/src/lib/ecore_con/ecore_con_private.h 2008-10-07 12:41:36 UTC (rev 36497) @@ -95,7 +95,7 @@ }; #endif -struct _Ecore_Con_Netinfo +struct _Ecore_Con_Info { struct addrinfo info; struct sockaddr addr; |