diff --git a/legacy/ecore/src/lib/ecore_con/ecore_con.c b/legacy/ecore/src/lib/ecore_con/ecore_con.c index d3fdf66738..ffe1ffbdfa 100644 --- a/legacy/ecore/src/lib/ecore_con/ecore_con.c +++ b/legacy/ecore/src/lib/ecore_con/ecore_con.c @@ -46,33 +46,49 @@ static Eina_Bool _ecore_con_client_timer(Ecore_Con_Client *cl); static void _ecore_con_cl_timer_update(Ecore_Con_Client *cl); -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_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); -static Eina_Bool _ecore_con_svr_tcp_handler(void *data, Ecore_Fd_Handler *fd_handler); -static Eina_Bool _ecore_con_cl_handler(void *data, Ecore_Fd_Handler *fd_handler); -static Eina_Bool _ecore_con_cl_udp_handler(void *data, Ecore_Fd_Handler *fd_handler); -static Eina_Bool _ecore_con_svr_udp_handler(void *data, Ecore_Fd_Handler *fd_handler); +static Eina_Bool _ecore_con_svr_tcp_handler(void *data, + Ecore_Fd_Handler *fd_handler); +static Eina_Bool _ecore_con_cl_handler(void *data, + Ecore_Fd_Handler *fd_handler); +static Eina_Bool _ecore_con_cl_udp_handler(void *data, + Ecore_Fd_Handler *fd_handler); +static Eina_Bool _ecore_con_svr_udp_handler(void *data, + Ecore_Fd_Handler *fd_handler); static void _ecore_con_svr_cl_read(Ecore_Con_Client *cl); -static Eina_Bool _ecore_con_svr_cl_handler(void *data, Ecore_Fd_Handler *fd_handler); +static Eina_Bool _ecore_con_svr_cl_handler(void *data, + Ecore_Fd_Handler *fd_handler); -static void _ecore_con_server_flush(Ecore_Con_Server *svr); -static void _ecore_con_client_flush(Ecore_Con_Client *cl); +static void _ecore_con_server_flush(Ecore_Con_Server *svr); +static void _ecore_con_client_flush(Ecore_Con_Client *cl); -static void _ecore_con_event_client_add_free(void *data, void *ev); -static void _ecore_con_event_client_del_free(void *data, void *ev); -static void _ecore_con_event_client_data_free(void *data, void *ev); -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_event_client_add_free(void *data, + void *ev); +static void _ecore_con_event_client_del_free(void *data, + void *ev); +static void _ecore_con_event_client_data_free(void *data, + void *ev); +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); +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; @@ -102,19 +118,19 @@ EAPI int ecore_con_init(void) { if (++_ecore_con_init_count != 1) - return _ecore_con_init_count; + return _ecore_con_init_count; #ifdef HAVE_EVIL if (!evil_init()) - return --_ecore_con_init_count; + return --_ecore_con_init_count; #endif if (!ecore_init()) - return --_ecore_con_init_count; + return --_ecore_con_init_count; _ecore_con_log_dom = eina_log_domain_register - ("ecore_con", ECORE_CON_DEFAULT_LOG_COLOR); + ("ecore_con", ECORE_CON_DEFAULT_LOG_COLOR); if(_ecore_con_log_dom < 0) { EINA_LOG_ERR("Impossible to create a log domain for Ecore Con."); @@ -145,10 +161,10 @@ EAPI int ecore_con_shutdown(void) { if (--_ecore_con_init_count != 0) - return _ecore_con_init_count; + return _ecore_con_init_count; while (servers) - _ecore_con_server_free(eina_list_data_get(servers)); + _ecore_con_server_free(eina_list_data_get(servers)); ecore_con_info_shutdown(); ecore_con_ssl_shutdown(); @@ -174,18 +190,20 @@ ecore_con_shutdown(void) * @return EINA_TRUE if the request did not fail to be set up, 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_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; + return EINA_FALSE; svr = calloc(1, sizeof(Ecore_Con_Server)); if (!svr) - return EINA_FALSE; + return EINA_FALSE; lk = malloc(sizeof (Ecore_Con_Lookup)); if (!lk) @@ -199,7 +217,7 @@ ecore_con_lookup(const char *name, Ecore_Con_Dns_Cb done_cb, const void *data) svr->name = strdup(name); if (!svr->name) - goto on_error; + goto on_error; svr->type = ECORE_CON_REMOTE_TCP; svr->port = 1025; @@ -221,7 +239,7 @@ ecore_con_lookup(const char *name, Ecore_Con_Dns_Cb done_cb, const void *data) if (ecore_con_info_get(svr, _ecore_con_lookup_done, svr, &hints)) - return EINA_TRUE; + return EINA_TRUE; free(svr->name); on_error: @@ -234,7 +252,6 @@ on_error: * @} */ - /** * @addtogroup Ecore_Con_Server_Group Ecore Connection Server Functions * @@ -246,7 +263,7 @@ on_error: /** * @example ecore_con_server_example.c * Shows how to write a simple server using the Ecore_Con library. -*/ + */ /** * Creates a server to listen for connections. @@ -274,25 +291,25 @@ on_error: */ EAPI Ecore_Con_Server * ecore_con_server_add(Ecore_Con_Type compl_type, - const char *name, - int port, - const void *data) + const char *name, + int port, + const void *data) { Ecore_Con_Server *svr; Ecore_Con_Type type; if (port < 0 || !name) - return NULL; /* local user socket: FILE: ~/.ecore/[name]/[port] */ + return NULL; /* local user socket: FILE: ~/.ecore/[name]/[port] */ /* local system socket: FILE: /tmp/.ecore_service|[name]|[port] */ /* remote system socket: TCP/IP: [name]:[port] */ svr = calloc(1, sizeof(Ecore_Con_Server)); if (!svr) - return NULL; + return NULL; svr->name = strdup(name); if (!svr->name) - goto error; + goto error; svr->type = compl_type; svr->port = port; @@ -312,24 +329,24 @@ ecore_con_server_add(Ecore_Con_Type compl_type, if ((type == ECORE_CON_LOCAL_USER) || (type == ECORE_CON_LOCAL_SYSTEM) || (type == ECORE_CON_LOCAL_ABSTRACT)) - /* Local */ - if (!ecore_con_local_listen(svr, _ecore_con_svr_tcp_handler, svr)) - goto error; + /* Local */ + if (!ecore_con_local_listen(svr, _ecore_con_svr_tcp_handler, svr)) + goto error; if ((type == ECORE_CON_REMOTE_TCP) || (type == ECORE_CON_REMOTE_NODELAY)) { /* TCP */ - if (!ecore_con_info_tcp_listen(svr, _ecore_con_cb_tcp_listen, - svr)) + if (!ecore_con_info_tcp_listen(svr, _ecore_con_cb_tcp_listen, + svr)) goto error; } else if ((type == ECORE_CON_REMOTE_MCAST) || (type == ECORE_CON_REMOTE_UDP)) - /* UDP and MCAST */ - if (!ecore_con_info_udp_listen(svr, _ecore_con_cb_udp_listen, - svr)) - goto error; + /* UDP and MCAST */ + if (!ecore_con_info_udp_listen(svr, _ecore_con_cb_udp_listen, + svr)) + goto error; servers = eina_list_append(servers, svr); ECORE_MAGIC_SET(svr, ECORE_MAGIC_CON_SERVER); @@ -338,26 +355,26 @@ ecore_con_server_add(Ecore_Con_Type compl_type, error: if (svr->name) - free(svr->name); + free(svr->name); if (svr->path) - free(svr->path); + free(svr->path); #ifndef _WIN32 if (svr->fd >= 0) - close(svr->fd); + close(svr->fd); if (svr->fd_handler) - ecore_main_fd_handler_del(svr->fd_handler); + ecore_main_fd_handler_del(svr->fd_handler); if (svr->write_buf) - free(svr->write_buf); + free(svr->write_buf); if (svr->ip) - free(svr->ip); + free(svr->ip); #endif - ecore_con_ssl_server_shutdown(svr); + ecore_con_ssl_server_shutdown(svr); free(svr); return NULL; } @@ -389,25 +406,25 @@ error: */ EAPI Ecore_Con_Server * ecore_con_server_connect(Ecore_Con_Type compl_type, - const char *name, - int port, - const void *data) + const char *name, + int port, + const void *data) { Ecore_Con_Server *svr; Ecore_Con_Type type; if (!name) - return NULL; + return NULL; /* local user socket: FILE: ~/.ecore/[name]/[port] */ /* local system socket: FILE: /tmp/.ecore_service|[name]|[port] */ /* remote system socket: TCP/IP: [name]:[port] */ svr = calloc(1, sizeof(Ecore_Con_Server)); if (!svr) - return NULL; + return NULL; svr->name = strdup(name); if (!svr->name) - goto error; + goto error; svr->type = compl_type; svr->port = port; @@ -427,31 +444,31 @@ ecore_con_server_connect(Ecore_Con_Type compl_type, (type == ECORE_CON_REMOTE_UDP) || (type == ECORE_CON_REMOTE_BROADCAST)) && (port < 0)) - goto error; + goto error; if ((type == ECORE_CON_LOCAL_USER) || (type == ECORE_CON_LOCAL_SYSTEM) || (type == ECORE_CON_LOCAL_ABSTRACT)) - /* Local */ - if (!ecore_con_local_connect(svr, _ecore_con_cl_handler, svr, - _ecore_con_event_server_add_free)) - goto - error; + /* Local */ + if (!ecore_con_local_connect(svr, _ecore_con_cl_handler, svr, + _ecore_con_event_server_add_free)) + goto + error; if ((type == ECORE_CON_REMOTE_TCP) || (type == ECORE_CON_REMOTE_NODELAY)) { /* TCP */ - if (!ecore_con_info_tcp_connect(svr, _ecore_con_cb_tcp_connect, - svr)) + if (!ecore_con_info_tcp_connect(svr, _ecore_con_cb_tcp_connect, + svr)) goto error; } else if ((type == ECORE_CON_REMOTE_UDP) || (type == ECORE_CON_REMOTE_BROADCAST)) - /* UDP and MCAST */ - if (!ecore_con_info_udp_connect(svr, _ecore_con_cb_udp_connect, - svr)) - goto error; + /* UDP and MCAST */ + if (!ecore_con_info_udp_connect(svr, _ecore_con_cb_udp_connect, + svr)) + goto error; servers = eina_list_append(servers, svr); ECORE_MAGIC_SET(svr, ECORE_MAGIC_CON_SERVER); @@ -460,16 +477,16 @@ ecore_con_server_connect(Ecore_Con_Type compl_type, error: if (svr->name) - free(svr->name); + free(svr->name); if (svr->path) - free(svr->path); + free(svr->path); if (svr->fd >= 0) - close(svr->fd); + close(svr->fd); if (svr->fd_handler) - ecore_main_fd_handler_del(svr->fd_handler); + ecore_main_fd_handler_del(svr->fd_handler); ecore_con_ssl_server_shutdown(svr); free(svr); @@ -484,7 +501,8 @@ error: * disables the idle timeout. */ EAPI void -ecore_con_server_timeout_set(Ecore_Con_Server *svr, double timeout) +ecore_con_server_timeout_set(Ecore_Con_Server *svr, + double timeout) { if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER)) { @@ -532,7 +550,7 @@ ecore_con_server_del(Ecore_Con_Server *svr) } if (svr->delete_me) - return NULL; + return NULL; data = svr->data; svr->data = NULL; @@ -546,7 +564,7 @@ ecore_con_server_del(Ecore_Con_Server *svr) } } else - _ecore_con_server_free(svr); + _ecore_con_server_free(svr); return data; } @@ -577,7 +595,8 @@ ecore_con_server_data_get(Ecore_Con_Server *svr) * @return The previously associated data, if any. */ EAPI void * -ecore_con_server_data_set(Ecore_Con_Server *svr, void *data) +ecore_con_server_data_set(Ecore_Con_Server *svr, + void *data) { void *ret = NULL; @@ -610,7 +629,7 @@ ecore_con_server_connected_get(Ecore_Con_Server *svr) } if (svr->connecting) - return EINA_FALSE; + return EINA_FALSE; return EINA_TRUE; } @@ -678,8 +697,8 @@ ecore_con_server_port_get(Ecore_Con_Server *svr) */ EAPI int ecore_con_server_send(Ecore_Con_Server *svr, - const void *data, - int size) + const void *data, + int size) { if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER)) { @@ -694,7 +713,7 @@ ecore_con_server_send(Ecore_Con_Server *svr, EINA_SAFETY_ON_TRUE_RETURN_VAL(size < 1, 0); if (svr->fd_handler) - ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ | ECORE_FD_WRITE); + ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ | ECORE_FD_WRITE); if (svr->write_buf) { @@ -742,8 +761,8 @@ ecore_con_server_send(Ecore_Con_Server *svr, */ EAPI void ecore_con_server_client_limit_set(Ecore_Con_Server *svr, - int client_limit, - char reject_excess_clients) + int client_limit, + char reject_excess_clients) { if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER)) { @@ -777,7 +796,6 @@ ecore_con_server_ip_get(Ecore_Con_Server *svr) return svr->ip; } - /** * @brief Check how long a server has been connected * @param svr The server to check @@ -795,6 +813,7 @@ ecore_con_server_uptime_get(Ecore_Con_Server *svr) return ecore_time_get() - svr->start_time; } + /** * Flushes all pending data to the given server. Will return when done. * @@ -812,7 +831,6 @@ ecore_con_server_flush(Ecore_Con_Server *svr) _ecore_con_server_flush(svr); } - /** * @} */ @@ -828,7 +846,7 @@ ecore_con_server_flush(Ecore_Con_Server *svr) /** * @example ecore_con_client_example.c * Shows how to write a simple client that connects to the example server. -*/ + */ /** * Sends the given data to the given client. @@ -840,8 +858,8 @@ ecore_con_server_flush(Ecore_Con_Server *svr) */ EAPI int ecore_con_client_send(Ecore_Con_Client *cl, - const void *data, - int size) + const void *data, + int size) { if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT)) { @@ -856,11 +874,11 @@ ecore_con_client_send(Ecore_Con_Client *cl, EINA_SAFETY_ON_TRUE_RETURN_VAL(size < 1, 0); if (cl->fd_handler) - ecore_main_fd_handler_active_set(cl->fd_handler, ECORE_FD_READ | ECORE_FD_WRITE); + ecore_main_fd_handler_active_set(cl->fd_handler, ECORE_FD_READ | ECORE_FD_WRITE); if(cl->host_server && ((cl->host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_UDP)) - sendto(cl->host_server->fd, data, size, 0, (struct sockaddr *)cl->client_addr, - cl->client_addr_len); + sendto(cl->host_server->fd, data, size, 0, (struct sockaddr *)cl->client_addr, + cl->client_addr_len); else if (cl->buf) { unsigned char *newbuf; @@ -912,7 +930,8 @@ ecore_con_client_server_get(Ecore_Con_Client *cl) * disables the idle timeout. */ EAPI void -ecore_con_client_timeout_set(Ecore_Con_Client *cl, double timeout) +ecore_con_client_timeout_set(Ecore_Con_Client *cl, + double timeout) { if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT)) { @@ -962,9 +981,9 @@ ecore_con_client_del(Ecore_Con_Client *cl) } if (cl->client_addr && cl->host_server && - (((cl->host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_UDP) || - ((cl->host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_MCAST))) - free(cl->client_addr); + (((cl->host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_UDP) || + ((cl->host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_MCAST))) + free(cl->client_addr); data = cl->data; @@ -998,7 +1017,8 @@ ecore_con_client_del(Ecore_Con_Client *cl) * @param data What to set the data to. */ EAPI void -ecore_con_client_data_set(Ecore_Con_Client *cl, const void *data) +ecore_con_client_data_set(Ecore_Con_Client *cl, + const void *data) { if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT)) { @@ -1113,28 +1133,28 @@ _ecore_con_server_free(Ecore_Con_Server *svr) } if (svr->write_buf) - free(svr->write_buf); + free(svr->write_buf); EINA_LIST_FREE(svr->clients, cl) _ecore_con_client_free(cl); if ((svr->created) && (svr->path) && (svr->ppid == getpid())) - unlink(svr->path); + unlink(svr->path); ecore_con_ssl_server_shutdown(svr); if (svr->fd >= 0) - close(svr->fd); + close(svr->fd); if (svr->name) - free(svr->name); + free(svr->name); if (svr->path) - free(svr->path); + free(svr->path); if (svr->ip) - free(svr->ip); + free(svr->ip); if (svr->fd_handler) - ecore_main_fd_handler_del(svr->fd_handler); + ecore_main_fd_handler_del(svr->fd_handler); servers = eina_list_remove(servers, svr); free(svr); @@ -1147,25 +1167,25 @@ _ecore_con_client_free(Ecore_Con_Client *cl) if ((!cl->buf) && cl->delete_me && (!cl->dead) && (cl->event_count < 1)) { - /* this is a catch-all for cases when a client is not properly killed. - * the only example case I've found so far is if a client ssl handshakes - * and then immediately disconnects without sending any further data. - */ + /* this is a catch-all for cases when a client is not properly killed. + * the only example case I've found so far is if a client ssl handshakes + * and then immediately disconnects without sending any further data. + */ - /* we lost our client! */ - Ecore_Con_Event_Client_Del *e; + /* we lost our client! */ + Ecore_Con_Event_Client_Del *e; - cl->dead = EINA_TRUE; - e = calloc(1, sizeof(Ecore_Con_Event_Client_Del)); - if (e) - { - cl->event_count++; - _ecore_con_cl_timer_update(cl); - e->client = cl; - ecore_event_add(ECORE_CON_EVENT_CLIENT_DEL, e, - _ecore_con_event_client_del_free, NULL); - return; - } + cl->dead = EINA_TRUE; + e = calloc(1, sizeof(Ecore_Con_Event_Client_Del)); + if (e) + { + cl->event_count++; + _ecore_con_cl_timer_update(cl); + e->client = cl; + ecore_event_add(ECORE_CON_EVENT_CLIENT_DEL, e, + _ecore_con_event_client_del_free, NULL); + return; + } } ECORE_MAGIC_SET(cl, ECORE_MAGIC_NONE); @@ -1184,21 +1204,21 @@ _ecore_con_client_free(Ecore_Con_Client *cl) } } if (cl->buf) - free(cl->buf); + free(cl->buf); if (cl->host_server->type & ECORE_CON_SSL) ecore_con_ssl_client_shutdown(cl); if (cl->fd >= 0) - close(cl->fd); + close(cl->fd); if (cl->fd_handler) - ecore_main_fd_handler_del(cl->fd_handler); + ecore_main_fd_handler_del(cl->fd_handler); if (cl->ip) - free(cl->ip); + free(cl->ip); - free(cl); + free(cl); return; } @@ -1221,7 +1241,7 @@ _ecore_con_server_kill(Ecore_Con_Server *svr) svr->dead = EINA_TRUE; if (svr->fd_handler) - ecore_main_fd_handler_del(svr->fd_handler); + ecore_main_fd_handler_del(svr->fd_handler); svr->fd_handler = NULL; } @@ -1270,7 +1290,8 @@ _ecore_con_cl_timer_update(Ecore_Con_Client *cl) } static void -_ecore_con_cb_tcp_listen(void *data, Ecore_Con_Info *net_info) +_ecore_con_cb_tcp_listen(void *data, + Ecore_Con_Info *net_info) { Ecore_Con_Server *svr; struct linger lin; @@ -1278,24 +1299,24 @@ _ecore_con_cb_tcp_listen(void *data, Ecore_Con_Info *net_info) svr = data; if(!net_info) - goto error; + goto error; svr->fd = socket(net_info->info.ai_family, net_info->info.ai_socktype, net_info->info.ai_protocol); if (svr->fd < 0) - goto error; + goto error; if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) - goto error; + goto error; if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) - goto error; + goto error; lin.l_onoff = 1; lin.l_linger = 0; if (setsockopt(svr->fd, SOL_SOCKET, SO_LINGER, (const void *)&lin, sizeof(struct linger)) < 0) - goto error; + goto error; if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_NODELAY) { @@ -1303,20 +1324,20 @@ _ecore_con_cb_tcp_listen(void *data, Ecore_Con_Info *net_info) if (setsockopt(svr->fd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(int)) < 0) - goto error; + goto error; } if (bind(svr->fd, net_info->info.ai_addr, net_info->info.ai_addrlen) < 0) - goto error; + goto error; if (listen(svr->fd, 4096) < 0) - goto error; + goto error; svr->fd_handler = ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ, - _ecore_con_svr_tcp_handler, svr, NULL, NULL); + _ecore_con_svr_tcp_handler, svr, NULL, NULL); if (!svr->fd_handler) - goto error; + goto error; return; @@ -1326,7 +1347,8 @@ error: } static void -_ecore_con_cb_udp_listen(void *data, Ecore_Con_Info *net_info) +_ecore_con_cb_udp_listen(void *data, + Ecore_Con_Info *net_info) { Ecore_Con_Server *svr; Ecore_Con_Type type; @@ -1339,12 +1361,12 @@ _ecore_con_cb_udp_listen(void *data, Ecore_Con_Info *net_info) type &= ECORE_CON_TYPE; if (!net_info) - goto error; + goto error; svr->fd = socket(net_info->info.ai_family, net_info->info.ai_socktype, net_info->info.ai_protocol); if(svr->fd < 0) - goto error; + goto error; if (type == ECORE_CON_REMOTE_MCAST) { @@ -1352,45 +1374,45 @@ _ecore_con_cb_udp_listen(void *data, Ecore_Con_Info *net_info) { if (!inet_pton(net_info->info.ai_family, net_info->ip, &mreq.imr_multiaddr)) - goto error; + goto error; mreq.imr_interface.s_addr = htonl(INADDR_ANY); if (setsockopt(svr->fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, - (const void *)&mreq,sizeof(mreq)) != 0) - goto error; + (const void *)&mreq, sizeof(mreq)) != 0) + goto error; } else if (net_info->info.ai_family == AF_INET6) { if (!inet_pton(net_info->info.ai_family, net_info->ip, &mreq6.ipv6mr_multiaddr)) - goto error; + goto error; mreq6.ipv6mr_interface = htonl(INADDR_ANY); if (setsockopt(svr->fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, - (const void *)&mreq6,sizeof(mreq6)) != 0) - goto error; + (const void *)&mreq6, sizeof(mreq6)) != 0) + goto error; } if (setsockopt(svr->fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&on, sizeof(on)) != 0) - goto error; + goto error; } if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) - goto error; + goto error; if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) - goto error; + goto error; if (bind(svr->fd, net_info->info.ai_addr, net_info->info.ai_addrlen) < 0) - goto error; + goto error; svr->fd_handler = - ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ, - _ecore_con_svr_udp_handler, svr, NULL, NULL); + ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ, + _ecore_con_svr_udp_handler, svr, NULL, NULL); if (!svr->fd_handler) - goto error; + goto error; svr->ip = strdup(net_info->ip); @@ -1402,7 +1424,8 @@ error: } static void -_ecore_con_cb_tcp_connect(void *data, Ecore_Con_Info *net_info) +_ecore_con_cb_tcp_connect(void *data, + Ecore_Con_Info *net_info) { Ecore_Con_Server *svr; int res; @@ -1411,22 +1434,22 @@ _ecore_con_cb_tcp_connect(void *data, Ecore_Con_Info *net_info) svr = data; if (!net_info) - goto error; + goto error; svr->fd = socket(net_info->info.ai_family, net_info->info.ai_socktype, net_info->info.ai_protocol); if (svr->fd < 0) - goto error; + goto error; if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) - goto error; + goto error; if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) - goto error; + goto error; if (setsockopt(svr->fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&curstate, sizeof(curstate)) < 0) - goto error; + goto error; if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_NODELAY) { @@ -1434,7 +1457,7 @@ _ecore_con_cb_tcp_connect(void *data, Ecore_Con_Info *net_info) if (setsockopt(svr->fd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(int)) < 0) - goto error; + goto error; } res = connect(svr->fd, net_info->info.ai_addr, net_info->info.ai_addrlen); @@ -1442,23 +1465,23 @@ _ecore_con_cb_tcp_connect(void *data, Ecore_Con_Info *net_info) if (res == SOCKET_ERROR) { if (WSAGetLastError() != WSAEINPROGRESS) - goto error; + goto error; #else if (res < 0) { if (errno != EINPROGRESS) - goto error; + goto error; #endif svr->connecting = EINA_TRUE; svr->fd_handler = - ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ | ECORE_FD_WRITE, - _ecore_con_cl_handler, svr, NULL, NULL); + ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ | ECORE_FD_WRITE, + _ecore_con_cl_handler, svr, NULL, NULL); } else - svr->fd_handler = ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ, - _ecore_con_cl_handler, svr, NULL, NULL); + svr->fd_handler = ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ, + _ecore_con_cl_handler, svr, NULL, NULL); if (svr->type & ECORE_CON_SSL) { @@ -1470,7 +1493,7 @@ _ecore_con_cb_tcp_connect(void *data, Ecore_Con_Info *net_info) } if (!svr->fd_handler) - goto error; + goto error; svr->ip = strdup(net_info->ip); @@ -1482,7 +1505,8 @@ error: } static void -_ecore_con_cb_udp_connect(void *data, Ecore_Con_Info *net_info) +_ecore_con_cb_udp_connect(void *data, + Ecore_Con_Info *net_info) { Ecore_Con_Server *svr; int curstate = 0; @@ -1490,38 +1514,38 @@ _ecore_con_cb_udp_connect(void *data, Ecore_Con_Info *net_info) svr = data; if (!net_info) - goto error; + goto error; svr->fd = socket(net_info->info.ai_family, net_info->info.ai_socktype, net_info->info.ai_protocol); if (svr->fd < 0) - goto error; + goto error; if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) - goto error; + goto error; if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) - goto error; + goto error; if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_BROADCAST) { if (setsockopt(svr->fd, SOL_SOCKET, SO_BROADCAST, (const void *)&broadcast, sizeof(broadcast)) < 0) - goto error; + goto error; } else if (setsockopt(svr->fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&curstate, sizeof(curstate)) < 0) - goto error; + goto error; if (connect(svr->fd, net_info->info.ai_addr, net_info->info.ai_addrlen) < 0) - goto error; + goto error; svr->fd_handler = ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ | ECORE_FD_WRITE, - _ecore_con_cl_udp_handler, svr, NULL, NULL); + _ecore_con_cl_udp_handler, svr, NULL, NULL); if (!svr->fd_handler) - goto error; + goto error; svr->ip = strdup(net_info->ip); @@ -1542,55 +1566,56 @@ svr_try_connect_plain(Ecore_Con_Server *svr) res = getsockopt(svr->fd, SOL_SOCKET, SO_ERROR, (void *)&so_err, &size); #ifdef _WIN32 if (res == SOCKET_ERROR) - so_err = -1; + so_err = -1; if (so_err == WSAEINPROGRESS && !svr->dead) - return ECORE_CON_INPROGRESS; + return ECORE_CON_INPROGRESS; #else if (res < 0) - so_err = -1; + so_err = -1; if (so_err == EINPROGRESS && !svr->dead) - return ECORE_CON_INPROGRESS; + return ECORE_CON_INPROGRESS; #endif if (so_err != 0) { /* we lost our server! */ - _ecore_con_server_kill(svr); - return ECORE_CON_DISCONNECTED; + _ecore_con_server_kill(svr); + return ECORE_CON_DISCONNECTED; } if ((!svr->delete_me) && (!svr->handshaking) && svr->connecting) { /* we got our server! */ - Ecore_Con_Event_Server_Add *e; + Ecore_Con_Event_Server_Add *e; - svr->connecting = EINA_FALSE; - e = calloc(1, sizeof(Ecore_Con_Event_Server_Add)); - if (e) - { - svr->event_count++; - svr->start_time = ecore_time_get(); - e->server = svr; - ecore_event_add(ECORE_CON_EVENT_SERVER_ADD, e, - _ecore_con_event_server_add_free, NULL); - } + svr->connecting = EINA_FALSE; + e = calloc(1, sizeof(Ecore_Con_Event_Server_Add)); + if (e) + { + svr->event_count++; + svr->start_time = ecore_time_get(); + e->server = svr; + ecore_event_add(ECORE_CON_EVENT_SERVER_ADD, e, + _ecore_con_event_server_add_free, NULL); + } } if (svr->fd_handler && (!svr->write_buf)) - ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ); + ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ); if (!svr->dead) - return ECORE_CON_CONNECTED; + return ECORE_CON_CONNECTED; else - return ECORE_CON_DISCONNECTED; + return ECORE_CON_DISCONNECTED; } static char * -_ecore_con_pretty_ip(struct sockaddr *client_addr, socklen_t size) +_ecore_con_pretty_ip(struct sockaddr *client_addr, + socklen_t size) { char ipbuf[INET6_ADDRSTRLEN + 1]; @@ -1614,14 +1639,15 @@ _ecore_con_pretty_ip(struct sockaddr *client_addr, socklen_t size) if (getnameinfo(client_addr, size, ipbuf, sizeof (ipbuf), NULL, 0, NI_NUMERICHOST)) - return strdup("0.0.0.0"); + return strdup("0.0.0.0"); ipbuf[sizeof (ipbuf) - 1] = 0; return strdup(ipbuf); } static Eina_Bool -_ecore_con_svr_tcp_handler(void *data, Ecore_Fd_Handler *fd_handler __UNUSED__) +_ecore_con_svr_tcp_handler(void *data, + Ecore_Fd_Handler *fd_handler __UNUSED__) { Ecore_Con_Server *svr; Ecore_Con_Client *cl = NULL; @@ -1631,10 +1657,10 @@ _ecore_con_svr_tcp_handler(void *data, Ecore_Fd_Handler *fd_handler __UNUSED__) svr = data; if (svr->dead) - return ECORE_CALLBACK_RENEW; + return ECORE_CALLBACK_RENEW; if (svr->delete_me) - return ECORE_CALLBACK_RENEW; + return ECORE_CALLBACK_RENEW; if ((svr->client_limit >= 0) && (!svr->reject_excess_clients) && (svr->client_count >= (unsigned int)svr->client_limit)) @@ -1664,10 +1690,9 @@ _ecore_con_svr_tcp_handler(void *data, Ecore_Fd_Handler *fd_handler __UNUSED__) cl->host_server = svr; cl->fd_handler = ecore_main_fd_handler_add(cl->fd, ECORE_FD_READ, - _ecore_con_svr_cl_handler, cl, NULL, NULL); + _ecore_con_svr_cl_handler, cl, NULL, NULL); ECORE_MAGIC_SET(cl, ECORE_MAGIC_CON_CLIENT); - if (svr->type & ECORE_CON_SSL) { cl->handshaking = EINA_TRUE; @@ -1679,7 +1704,7 @@ _ecore_con_svr_tcp_handler(void *data, Ecore_Fd_Handler *fd_handler __UNUSED__) svr->clients = eina_list_append(svr->clients, cl); svr->client_count++; if (!svr->path) - cl->ip = _ecore_con_pretty_ip((struct sockaddr *)&incoming, size_in); + cl->ip = _ecore_con_pretty_ip((struct sockaddr *)&incoming, size_in); if ((!cl->delete_me) && (!cl->handshaking)) { @@ -1705,7 +1730,6 @@ error: return ECORE_CALLBACK_RENEW; } - static void _ecore_con_cl_read(Ecore_Con_Server *svr) { @@ -1715,7 +1739,7 @@ _ecore_con_cl_read(Ecore_Con_Server *svr) /* only possible with non-ssl connections */ if (svr->connecting && (svr_try_connect_plain(svr) != ECORE_CON_CONNECTED)) - return; + return; for (tries = 0; tries < 16; tries++) { @@ -1734,10 +1758,10 @@ _ecore_con_cl_read(Ecore_Con_Server *svr) { num = read(svr->fd, buf, READBUFSIZ); if ((num < 0) && (errno == EAGAIN)) - lost_server = EINA_FALSE; + lost_server = EINA_FALSE; } else if (!(num = ecore_con_ssl_server_read(svr, buf, READBUFSIZ))) - lost_server = EINA_FALSE; + lost_server = EINA_FALSE; if (num < 1) { @@ -1758,7 +1782,7 @@ _ecore_con_cl_read(Ecore_Con_Server *svr) } if (lost_server) - _ecore_con_server_kill(svr); + _ecore_con_server_kill(svr); break; } @@ -1780,17 +1804,18 @@ _ecore_con_cl_read(Ecore_Con_Server *svr) } static Eina_Bool -_ecore_con_cl_handler(void *data, Ecore_Fd_Handler *fd_handler) +_ecore_con_cl_handler(void *data, + Ecore_Fd_Handler *fd_handler) { Ecore_Con_Server *svr; Eina_Bool want_read, want_write; svr = data; if (svr->dead) - return ECORE_CALLBACK_RENEW; + return ECORE_CALLBACK_RENEW; if (svr->delete_me) - return ECORE_CALLBACK_RENEW; + return ECORE_CALLBACK_RENEW; want_read = ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ); want_write = ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_WRITE); @@ -1799,13 +1824,13 @@ _ecore_con_cl_handler(void *data, Ecore_Fd_Handler *fd_handler) { DBG("Continuing ssl handshake: preparing to %s...", want_read ? "read" : "write"); #ifdef ISCOMFITOR - if (want_read) - { - char buf[32768]; - ssize_t len; - len = recv(svr->fd, buf, sizeof(buf), MSG_DONTWAIT | MSG_PEEK); - DBG("%zu bytes in buffer", len); - } + if (want_read) + { + char buf[32768]; + ssize_t len; + len = recv(svr->fd, buf, sizeof(buf), MSG_DONTWAIT | MSG_PEEK); + DBG("%zu bytes in buffer", len); + } #endif if (ecore_con_ssl_server_init(svr)) { @@ -1825,28 +1850,26 @@ _ecore_con_cl_handler(void *data, Ecore_Fd_Handler *fd_handler) else if (!svr->ssl_state) { /* we got our server! */ - Ecore_Con_Event_Server_Add *e; + Ecore_Con_Event_Server_Add *e; - svr->connecting = EINA_FALSE; - e = calloc(1, sizeof(Ecore_Con_Event_Server_Add)); - if (e) - { - svr->event_count++; - svr->start_time = ecore_time_get(); - e->server = svr; - ecore_event_add(ECORE_CON_EVENT_SERVER_ADD, e, - _ecore_con_event_server_add_free, NULL); - } + svr->connecting = EINA_FALSE; + e = calloc(1, sizeof(Ecore_Con_Event_Server_Add)); + if (e) + { + svr->event_count++; + svr->start_time = ecore_time_get(); + e->server = svr; + ecore_event_add(ECORE_CON_EVENT_SERVER_ADD, e, + _ecore_con_event_server_add_free, NULL); + } } - } - else if (want_read) _ecore_con_cl_read(svr); - else if (want_write) - { /* only possible with non-ssl connections */ + else if (want_write) /* only possible with non-ssl connections */ + { if (svr->connecting && (!svr_try_connect_plain(svr))) - return ECORE_CALLBACK_RENEW; + return ECORE_CALLBACK_RENEW; _ecore_con_server_flush(svr); } @@ -1855,16 +1878,17 @@ _ecore_con_cl_handler(void *data, Ecore_Fd_Handler *fd_handler) } static Eina_Bool -_ecore_con_cl_udp_handler(void *data, Ecore_Fd_Handler *fd_handler) +_ecore_con_cl_udp_handler(void *data, + Ecore_Fd_Handler *fd_handler) { Ecore_Con_Server *svr; svr = data; if (svr->dead) - return ECORE_CALLBACK_RENEW; + return ECORE_CALLBACK_RENEW; if (svr->delete_me) - return ECORE_CALLBACK_RENEW; + return ECORE_CALLBACK_RENEW; if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ)) { @@ -1882,7 +1906,7 @@ _ecore_con_cl_udp_handler(void *data, Ecore_Fd_Handler *fd_handler) inbuf = malloc(num); if(!inbuf) - return 1; + return 1; memcpy(inbuf, buf, num); @@ -1902,27 +1926,28 @@ _ecore_con_cl_udp_handler(void *data, Ecore_Fd_Handler *fd_handler) else if ((errno == EIO) || (errno == EBADF) || (errno == EPIPE) || (errno == EINVAL) || (errno == ENOSPC) || (errno == ECONNREFUSED)) - _ecore_con_server_kill(svr); + _ecore_con_server_kill(svr); } else if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_WRITE)) - _ecore_con_server_flush(svr); + _ecore_con_server_flush(svr); return ECORE_CALLBACK_RENEW; } static Eina_Bool -_ecore_con_svr_udp_handler(void *data, Ecore_Fd_Handler *fd_handler) +_ecore_con_svr_udp_handler(void *data, + Ecore_Fd_Handler *fd_handler) { Ecore_Con_Server *svr; Ecore_Con_Client *cl = NULL; svr = data; if (svr->dead) - return ECORE_CALLBACK_RENEW; + return ECORE_CALLBACK_RENEW; if (svr->delete_me) - return ECORE_CALLBACK_RENEW; + return ECORE_CALLBACK_RENEW; if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ)) { @@ -1935,16 +1960,16 @@ _ecore_con_svr_udp_handler(void *data, Ecore_Fd_Handler *fd_handler) #ifdef _WIN32 num = fcntl(svr->fd, F_SETFL, O_NONBLOCK); if (num >= 0) - num = - recvfrom(svr->fd, buf, sizeof(buf), 0, - (struct sockaddr *)&client_addr, - &client_addr_len); + num = + recvfrom(svr->fd, buf, sizeof(buf), 0, + (struct sockaddr *)&client_addr, + &client_addr_len); #else num = - recvfrom(svr->fd, buf, sizeof(buf), MSG_DONTWAIT, - (struct sockaddr *)&client_addr, - &client_addr_len); + recvfrom(svr->fd, buf, sizeof(buf), MSG_DONTWAIT, + (struct sockaddr *)&client_addr, + &client_addr_len); #endif if (num > 0) @@ -1954,10 +1979,10 @@ _ecore_con_svr_udp_handler(void *data, Ecore_Fd_Handler *fd_handler) Ecore_Con_Event_Client_Data *e; unsigned char *inbuf; - /* Create a new client for use in the client data event */ + /* Create a new client for use in the client data event */ cl = calloc(1, sizeof(Ecore_Con_Client)); if(!cl) - return ECORE_CALLBACK_RENEW; + return ECORE_CALLBACK_RENEW; cl->buf = NULL; cl->fd = 0; @@ -1997,7 +2022,7 @@ _ecore_con_svr_udp_handler(void *data, Ecore_Fd_Handler *fd_handler) e->client = cl; e->data = inbuf; e->size = num; - ecore_event_add(ECORE_CON_EVENT_CLIENT_DATA, e, + ecore_event_add(ECORE_CON_EVENT_CLIENT_DATA, e, _ecore_con_event_client_data_free, NULL); } @@ -2010,10 +2035,10 @@ _ecore_con_svr_udp_handler(void *data, Ecore_Fd_Handler *fd_handler) if(add) { /*cl->event_count++;*/ - add->client = cl; - _ecore_con_cl_timer_update(cl); - ecore_event_add(ECORE_CON_EVENT_CLIENT_ADD, add, - _ecore_con_event_client_add_free, NULL); + add->client = cl; + _ecore_con_cl_timer_update(cl); + ecore_event_add(ECORE_CON_EVENT_CLIENT_ADD, add, + _ecore_con_event_client_add_free, NULL); } } } @@ -2024,30 +2049,30 @@ _ecore_con_svr_udp_handler(void *data, Ecore_Fd_Handler *fd_handler) { if (!svr->delete_me) { - /* we lost our client! */ - Ecore_Con_Event_Client_Del *e; + /* we lost our client! */ + Ecore_Con_Event_Client_Del *e; - e = calloc(1, sizeof(Ecore_Con_Event_Client_Del)); - if (e) - { - svr->event_count++; - /* be explicit here */ - e->client = NULL; - ecore_event_add(ECORE_CON_EVENT_CLIENT_DEL, e, - _ecore_con_event_client_del_free, NULL); - } + e = calloc(1, sizeof(Ecore_Con_Event_Client_Del)); + if (e) + { + svr->event_count++; + /* be explicit here */ + e->client = NULL; + ecore_event_add(ECORE_CON_EVENT_CLIENT_DEL, e, + _ecore_con_event_client_del_free, NULL); + } } svr->dead = EINA_TRUE; if (svr->fd_handler) - ecore_main_fd_handler_del(svr->fd_handler); + ecore_main_fd_handler_del(svr->fd_handler); svr->fd_handler = NULL; } } else if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_WRITE)) - _ecore_con_client_flush(cl); + _ecore_con_client_flush(cl); return ECORE_CALLBACK_RENEW; } @@ -2078,22 +2103,21 @@ _ecore_con_svr_cl_read(Ecore_Con_Client *cl) if (!(cl->host_server->type & ECORE_CON_SSL)) { if ((num = read(cl->fd, buf, READBUFSIZ)) <= 0) - if ((num < 0) && (errno == EAGAIN)) - lost_client = EINA_FALSE; - + if ((num < 0) && (errno == EAGAIN)) + lost_client = EINA_FALSE; } else if (!(num = ecore_con_ssl_client_read(cl, buf, READBUFSIZ))) - lost_client = EINA_FALSE; + lost_client = EINA_FALSE; if (num > 0) { unsigned char *tmp; if (!(tmp = realloc(inbuf, inbuf_num + num))) { - /* FIXME: this should probably do something, but what? */ - if (inbuf) - free(inbuf); - break; + /* FIXME: this should probably do something, but what? */ + if (inbuf) + free(inbuf); + break; } inbuf = tmp; memcpy(inbuf + inbuf_num, buf, num); @@ -2121,24 +2145,24 @@ _ecore_con_svr_cl_read(Ecore_Con_Client *cl) if (lost_client && (!cl->delete_me)) { /* we lost our client! */ - Ecore_Con_Event_Client_Del *e; + Ecore_Con_Event_Client_Del *e; - e = calloc(1, sizeof(Ecore_Con_Event_Client_Del)); - if (e) - { - cl->event_count++; - _ecore_con_cl_timer_update(cl); - e->client = cl; - ecore_event_add(ECORE_CON_EVENT_CLIENT_DEL, e, - _ecore_con_event_client_del_free, NULL); - } + e = calloc(1, sizeof(Ecore_Con_Event_Client_Del)); + if (e) + { + cl->event_count++; + _ecore_con_cl_timer_update(cl); + e->client = cl; + ecore_event_add(ECORE_CON_EVENT_CLIENT_DEL, e, + _ecore_con_event_client_del_free, NULL); + } } if (lost_client) { cl->dead = EINA_TRUE; if (cl->fd_handler) - ecore_main_fd_handler_del(cl->fd_handler); + ecore_main_fd_handler_del(cl->fd_handler); cl->fd_handler = NULL; } @@ -2148,16 +2172,17 @@ _ecore_con_svr_cl_read(Ecore_Con_Client *cl) } static Eina_Bool -_ecore_con_svr_cl_handler(void *data, Ecore_Fd_Handler *fd_handler) +_ecore_con_svr_cl_handler(void *data, + Ecore_Fd_Handler *fd_handler) { Ecore_Con_Client *cl; cl = data; if (cl->dead) - return ECORE_CALLBACK_RENEW; + return ECORE_CALLBACK_RENEW; if (cl->delete_me) - return ECORE_CALLBACK_RENEW; + return ECORE_CALLBACK_RENEW; if (cl->handshaking && ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ | ECORE_FD_WRITE)) { @@ -2178,7 +2203,6 @@ _ecore_con_svr_cl_handler(void *data, Ecore_Fd_Handler *fd_handler) ecore_event_add(ECORE_CON_EVENT_CLIENT_DEL, e, _ecore_con_event_client_del_free, NULL); } - } else if (!cl->ssl_state) { @@ -2194,7 +2218,6 @@ _ecore_con_svr_cl_handler(void *data, Ecore_Fd_Handler *fd_handler) } } } - else if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ)) _ecore_con_svr_cl_read(cl); @@ -2210,14 +2233,14 @@ _ecore_con_server_flush(Ecore_Con_Server *svr) int count, num; if (!svr->write_buf) - return; + return; /* check whether we need to write anything at all. * we must not write zero bytes with SSL_write() since it * causes undefined behaviour */ if (svr->write_buf_size == svr->write_buf_offset) - return; + return; num = svr->write_buf_size - svr->write_buf_offset; @@ -2230,15 +2253,15 @@ _ecore_con_server_flush(Ecore_Con_Server *svr) } if (!(svr->type & ECORE_CON_SSL)) - count = write(svr->fd, svr->write_buf + svr->write_buf_offset, num); + count = write(svr->fd, svr->write_buf + svr->write_buf_offset, num); else - count = ecore_con_ssl_server_write(svr, svr->write_buf + svr->write_buf_offset, num); + count = ecore_con_ssl_server_write(svr, svr->write_buf + svr->write_buf_offset, num); if (count < 0) { /* we lost our server! */ - _ecore_con_server_kill(svr); - return; + _ecore_con_server_kill(svr); + return; } svr->write_buf_offset += count; @@ -2249,7 +2272,7 @@ _ecore_con_server_flush(Ecore_Con_Server *svr) free(svr->write_buf); svr->write_buf = NULL; if (svr->fd_handler) - ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ); + ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ); } } @@ -2259,7 +2282,7 @@ _ecore_con_client_flush(Ecore_Con_Client *cl) int num, count = 0; if (!cl->buf) - return; + return; if (cl->handshaking) { @@ -2274,18 +2297,18 @@ _ecore_con_client_flush(Ecore_Con_Client *cl) { num = cl->buf_size - cl->buf_offset; if (!(cl->host_server->type & ECORE_CON_SSL)) - count = write(cl->fd, cl->buf + cl->buf_offset, num); + count = write(cl->fd, cl->buf + cl->buf_offset, num); else - count = ecore_con_ssl_client_write(cl, cl->buf + cl->buf_offset, num); + count = ecore_con_ssl_client_write(cl, cl->buf + cl->buf_offset, num); } if (count < 0) { if ((errno == EIO) || (errno == EBADF) || (errno == EPIPE) || (errno == EINVAL) || (errno == ENOSPC) || (errno == ECONNREFUSED)) - if (!cl->delete_me) - { - /* we lost our client! */ + if (!cl->delete_me) + { + /* we lost our client! */ Ecore_Con_Event_Client_Del *e; e = calloc(1, sizeof(Ecore_Con_Event_Client_Del)); @@ -2300,10 +2323,10 @@ _ecore_con_client_flush(Ecore_Con_Client *cl) cl->dead = EINA_TRUE; if (cl->fd_handler) - ecore_main_fd_handler_del(cl->fd_handler); + ecore_main_fd_handler_del(cl->fd_handler); cl->fd_handler = NULL; - } + } return; } @@ -2316,12 +2339,13 @@ _ecore_con_client_flush(Ecore_Con_Client *cl) free(cl->buf); cl->buf = NULL; if (cl->fd_handler) - ecore_main_fd_handler_active_set(cl->fd_handler, ECORE_FD_READ); + ecore_main_fd_handler_active_set(cl->fd_handler, ECORE_FD_READ); } } static void -_ecore_con_event_client_add_free(void *data __UNUSED__, void *ev) +_ecore_con_event_client_add_free(void *data __UNUSED__, + void *ev) { Ecore_Con_Event_Client_Add *e; @@ -2329,45 +2353,48 @@ _ecore_con_event_client_add_free(void *data __UNUSED__, void *ev) e->client->event_count--; if ((e->client->event_count == 0) && (e->client->delete_me)) - ecore_con_client_del(e->client); + ecore_con_client_del(e->client); free(e); } static void -_ecore_con_event_client_del_free(void *data __UNUSED__, void *ev) +_ecore_con_event_client_del_free(void *data __UNUSED__, + void *ev) { Ecore_Con_Event_Client_Del *e; e = ev; e->client->event_count--; if ((e->client->event_count == 0) && (e->client->delete_me)) - ecore_con_client_del(e->client); + ecore_con_client_del(e->client); - free(e); + free(e); } static void -_ecore_con_event_client_data_free(void *data __UNUSED__, void *ev) +_ecore_con_event_client_data_free(void *data __UNUSED__, + void *ev) { Ecore_Con_Event_Client_Data *e; e = ev; e->client->event_count--; if (e->data) - free(e->data); + free(e->data); if (((e->client->event_count == 0) && (e->client->delete_me)) || ((e->client->host_server && ((e->client->host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_UDP || (e->client->host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_MCAST)))) - ecore_con_client_del(e->client); + ecore_con_client_del(e->client); free(e); } static void -_ecore_con_event_server_add_free(void *data __UNUSED__, void *ev) +_ecore_con_event_server_add_free(void *data __UNUSED__, + void *ev) { Ecore_Con_Event_Server_Add *e; @@ -2375,13 +2402,14 @@ _ecore_con_event_server_add_free(void *data __UNUSED__, void *ev) e->server->event_count--; if ((e->server->event_count == 0) && (e->server->delete_me)) - _ecore_con_server_free(e->server); + _ecore_con_server_free(e->server); free(e); } static void -_ecore_con_event_server_del_free(void *data __UNUSED__, void *ev) +_ecore_con_event_server_del_free(void *data __UNUSED__, + void *ev) { Ecore_Con_Event_Server_Del *e; @@ -2389,30 +2417,32 @@ _ecore_con_event_server_del_free(void *data __UNUSED__, void *ev) e->server->event_count--; if ((e->server->event_count == 0) && (e->server->delete_me)) - _ecore_con_server_free(e->server); + _ecore_con_server_free(e->server); - free(e); + free(e); } static void -_ecore_con_event_server_data_free(void *data __UNUSED__, void *ev) +_ecore_con_event_server_data_free(void *data __UNUSED__, + void *ev) { Ecore_Con_Event_Server_Data *e; e = ev; e->server->event_count--; if (e->data) - free(e->data); + free(e->data); if ((e->server->event_count == 0) && (e->server->delete_me)) - _ecore_con_server_free(e->server); + _ecore_con_server_free(e->server); free(e); } static void -_ecore_con_lookup_done(void *data, Ecore_Con_Info *infos) +_ecore_con_lookup_done(void *data, + Ecore_Con_Info *infos) { Ecore_Con_Server *svr; Ecore_Con_Lookup *lk; @@ -2421,13 +2451,14 @@ _ecore_con_lookup_done(void *data, Ecore_Con_Info *infos) 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); + 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); + lk->done_cb(NULL, NULL, NULL, 0, (void *)lk->data); free(svr->name); free(lk); free(svr); } + diff --git a/legacy/ecore/src/lib/ecore_con/ecore_con_ares.c b/legacy/ecore/src/lib/ecore_con/ecore_con_ares.c index b67606719f..fc2b426864 100644 --- a/legacy/ecore/src/lib/ecore_con/ecore_con_ares.c +++ b/legacy/ecore/src/lib/ecore_con/ecore_con_ares.c @@ -17,26 +17,26 @@ #include "Ecore_Con.h" #include "ecore_con_private.h" -typedef struct _Ecore_Con_FD Ecore_Con_FD; +typedef struct _Ecore_Con_FD Ecore_Con_FD; typedef struct _Ecore_Con_CAres Ecore_Con_CAres; struct _Ecore_Con_FD { Ecore_Fd_Handler *handler; - int active; - int fd; + int active; + int fd; }; struct _Ecore_Con_CAres { Ecore_Con_Server *svr; Ecore_Con_Info_Cb done_cb; - void *data; - struct addrinfo hints; - Ecore_Con_Info *result; + void *data; + struct addrinfo hints; + Ecore_Con_Info *result; union { - struct in_addr v4; + struct in_addr v4; struct in6_addr v6; } addr; @@ -51,13 +51,16 @@ static int active = 0; static Ecore_Timer *tm = NULL; static fd_set info_readers, info_writers; -static void _ecore_con_info_ares_nameinfo(Ecore_Con_CAres *arg, int status, - int timeouts, char *node, - char *service); -static void _ecore_con_info_ares_host_cb(Ecore_Con_CAres *arg, int status, - int timeouts, - struct hostent *hostent); -static Eina_Bool _ecore_con_info_cares_fd_cb(void *data, +static void _ecore_con_info_ares_nameinfo(Ecore_Con_CAres *arg, + int status, + int timeouts, + char *node, + char *service); +static void _ecore_con_info_ares_host_cb(Ecore_Con_CAres *arg, + int status, + int timeouts, + struct hostent *hostent); +static Eina_Bool _ecore_con_info_cares_fd_cb(void *data, Ecore_Fd_Handler *fd_handler); static Eina_Bool _ecore_con_info_cares_timeout_cb(void *data); static void _ecore_con_info_cares_clean(void); @@ -68,7 +71,7 @@ ecore_con_info_init(void) if (info_init == 0) { if (ares_library_init(ARES_LIB_INIT_ALL) != 0) - return 0; + return 0; if (ares_init(&info_channel) != ARES_SUCCESS) { @@ -88,12 +91,12 @@ ecore_con_info_shutdown(void) if (info_init == 0) { /* Cancel all ongoing request */ - ares_cancel(info_channel); - ares_destroy(info_channel); + ares_cancel(info_channel); + ares_destroy(info_channel); - /* Destroy FD handler here. */ - /* Shutdown ares */ - ares_library_cleanup(); + /* Destroy FD handler here. */ + /* Shutdown ares */ + ares_library_cleanup(); } return info_init; @@ -102,7 +105,7 @@ ecore_con_info_shutdown(void) int ecore_con_info_tcp_connect(Ecore_Con_Server *svr, Ecore_Con_Info_Cb done_cb, - void *data) + void *data) { struct addrinfo hints; @@ -121,7 +124,7 @@ ecore_con_info_tcp_connect(Ecore_Con_Server *svr, int ecore_con_info_tcp_listen(Ecore_Con_Server *svr, Ecore_Con_Info_Cb done_cb, - void *data) + void *data) { struct addrinfo hints; @@ -140,7 +143,7 @@ ecore_con_info_tcp_listen(Ecore_Con_Server *svr, int ecore_con_info_udp_connect(Ecore_Con_Server *svr, Ecore_Con_Info_Cb done_cb, - void *data) + void *data) { struct addrinfo hints; @@ -159,7 +162,7 @@ ecore_con_info_udp_connect(Ecore_Con_Server *svr, int ecore_con_info_udp_listen(Ecore_Con_Server *svr, Ecore_Con_Info_Cb done_cb, - void *data) + void *data) { struct addrinfo hints; @@ -178,7 +181,7 @@ ecore_con_info_udp_listen(Ecore_Con_Server *svr, int ecore_con_info_mcast_listen(Ecore_Con_Server *svr, Ecore_Con_Info_Cb done_cb, - void *data) + void *data) { struct addrinfo hints; @@ -196,19 +199,21 @@ ecore_con_info_mcast_listen(Ecore_Con_Server *svr, static Eina_Bool _ecore_con_info_ares_getnameinfo(Ecore_Con_CAres *arg, - int addrtype, const char *name, - struct sockaddr *addr, int addrlen) + int addrtype, + const char *name, + struct sockaddr *addr, + int addrlen) { int length = 0; if (name) - length = strlen(name) + 1; + length = strlen(name) + 1; else - length = 1; + length = 1; arg->result = malloc(sizeof (Ecore_Con_Info) + length); if (!arg->result) - return EINA_FALSE; + return EINA_FALSE; /* FIXME: What to do when hint is not set ? */ arg->result->info.ai_flags = arg->hints.ai_flags; @@ -221,34 +226,33 @@ _ecore_con_info_ares_getnameinfo(Ecore_Con_CAres *arg, arg->result->info.ai_canonname = (char *)(arg->result + 1); if (!name) - *arg->result->info.ai_canonname = '\0'; + *arg->result->info.ai_canonname = '\0'; else - strcpy(arg->result->info.ai_canonname, name); + strcpy(arg->result->info.ai_canonname, name); arg->result->info.ai_next = NULL; ares_getnameinfo( - info_channel, addr, addrlen, - ARES_NI_NUMERICSERV | ARES_NI_NUMERICHOST | - ARES_NI_LOOKUPSERVICE | ARES_NI_LOOKUPHOST, - (ares_nameinfo_callback)_ecore_con_info_ares_nameinfo, arg); + info_channel, addr, addrlen, + ARES_NI_NUMERICSERV | ARES_NI_NUMERICHOST | + ARES_NI_LOOKUPSERVICE | ARES_NI_LOOKUPHOST, + (ares_nameinfo_callback)_ecore_con_info_ares_nameinfo, arg); return EINA_TRUE; } - EAPI int ecore_con_info_get(Ecore_Con_Server *svr, Ecore_Con_Info_Cb done_cb, - void *data, - struct addrinfo *hints) + void *data, + struct addrinfo *hints) { Ecore_Con_CAres *cares; int ai_family = AF_INET6; cares = calloc(1, sizeof (Ecore_Con_CAres)); if (!cares) - return 0; + return 0; cares->svr = svr; cares->done_cb = done_cb; @@ -294,7 +298,8 @@ ecore_con_info_get(Ecore_Con_Server *svr, } static int -_ecore_con_info_fds_search(const Ecore_Con_FD *fd1, const Ecore_Con_FD *fd2) +_ecore_con_info_fds_search(const Ecore_Con_FD *fd1, + const Ecore_Con_FD *fd2) { return fd1->fd - fd2->fd; } @@ -308,7 +313,7 @@ _ecore_con_info_fds_lookup(int fd) fdl.fd = fd; search = eina_list_search_unsorted( - info_fds, (Eina_Compare_Cb)_ecore_con_info_fds_search, &fdl); + info_fds, (Eina_Compare_Cb)_ecore_con_info_fds_search, &fdl); if (search) { @@ -338,46 +343,45 @@ _ecore_con_info_cares_clean(void) int flags = 0; if (FD_ISSET(i, &readers)) - flags |= ECORE_FD_READ; + flags |= ECORE_FD_READ; if (FD_ISSET(i, &writers)) - flags |= ECORE_FD_WRITE; + flags |= ECORE_FD_WRITE; if (flags) - if (!_ecore_con_info_fds_lookup(i)) - { - ecf = malloc(sizeof (Ecore_Con_FD)); - if (ecf) - { - ecf->fd = i; - ecf->active = active; - ecf->handler = ecore_main_fd_handler_add( - i, ECORE_FD_WRITE | ECORE_FD_READ, - _ecore_con_info_cares_fd_cb, - NULL, NULL, NULL); - info_fds = eina_list_append(info_fds, ecf); - } - } - + if (!_ecore_con_info_fds_lookup(i)) + { + ecf = malloc(sizeof (Ecore_Con_FD)); + if (ecf) + { + ecf->fd = i; + ecf->active = active; + ecf->handler = ecore_main_fd_handler_add( + i, ECORE_FD_WRITE | ECORE_FD_READ, + _ecore_con_info_cares_fd_cb, + NULL, NULL, NULL); + info_fds = eina_list_append(info_fds, ecf); + } + } } info_readers = readers; info_writers = writers; EINA_LIST_FOREACH_SAFE(info_fds, l, l_next, ecf) - { - if (ecf->active != active) - { - ecore_main_fd_handler_del(ecf->handler); - free(ecf); - info_fds = eina_list_remove_list(info_fds, l); - } - } + { + if (ecf->active != active) + { + ecore_main_fd_handler_del(ecf->handler); + free(ecf); + info_fds = eina_list_remove_list(info_fds, l); + } + } if (!info_fds) { if (tm) - ecore_timer_del(tm); + ecore_timer_del(tm); tm = NULL; } @@ -388,12 +392,12 @@ _ecore_con_info_cares_clean(void) ares_timeout(info_channel, NULL, &tv); if (tm) - ecore_timer_delay(tm, tv.tv_sec); + ecore_timer_delay(tm, tv.tv_sec); else - tm = - ecore_timer_add((double)tv.tv_sec, - _ecore_con_info_cares_timeout_cb, - NULL); + tm = + ecore_timer_add((double)tv.tv_sec, + _ecore_con_info_cares_timeout_cb, + NULL); } } @@ -407,7 +411,8 @@ _ecore_con_info_cares_timeout_cb(void *data) } static Eina_Bool -_ecore_con_info_cares_fd_cb(void *data, Ecore_Fd_Handler *fd_handler) +_ecore_con_info_cares_fd_cb(void *data, + Ecore_Fd_Handler *fd_handler) { ares_process(info_channel, &info_readers, &info_writers); _ecore_con_info_cares_clean(); @@ -416,8 +421,10 @@ _ecore_con_info_cares_fd_cb(void *data, Ecore_Fd_Handler *fd_handler) } static void -_ecore_con_info_ares_host_cb(Ecore_Con_CAres *arg, int status, int timeouts, - struct hostent *hostent) +_ecore_con_info_ares_host_cb(Ecore_Con_CAres *arg, + int status, + int timeouts, + struct hostent *hostent) { struct sockaddr *addr; int addrlen; @@ -427,72 +434,72 @@ _ecore_con_info_ares_host_cb(Ecore_Con_CAres *arg, int status, int timeouts, switch (status) { case ARES_SUCCESS: - if (!hostent->h_addr_list[0]) + if (!hostent->h_addr_list[0]) + { + fprintf(stderr, "No IP found\n"); + goto on_error; + } + + switch (hostent->h_addrtype) + { + case AF_INET: { - fprintf(stderr, "No IP found\n"); - goto on_error; + struct sockaddr_in *addri; + + addrlen = sizeof (struct sockaddr_in); + addri = malloc(addrlen); + + if (!addri) + goto on_mem_error; + + addri->sin_family = AF_INET; + addri->sin_port = htons(arg->svr->port); + + memcpy(&addri->sin_addr.s_addr, + hostent->h_addr_list[0], sizeof (struct in_addr)); + + addr = (struct sockaddr *)addri; + break; } - switch (hostent->h_addrtype) + case AF_INET6: { - case AF_INET: - { - struct sockaddr_in *addri; + struct sockaddr_in6 *addri6; - addrlen = sizeof (struct sockaddr_in); - addri = malloc(addrlen); + addrlen = sizeof (struct sockaddr_in6); + addri6 = malloc(addrlen); - if (!addri) - goto on_mem_error; + if (!addri6) + goto on_mem_error; - addri->sin_family = AF_INET; - addri->sin_port = htons(arg->svr->port); + addri6->sin6_family = AF_INET6; + addri6->sin6_port = htons(arg->svr->port); + addri6->sin6_flowinfo = 0; + addri6->sin6_scope_id = 0; - memcpy(&addri->sin_addr.s_addr, - hostent->h_addr_list[0], sizeof (struct in_addr)); + memcpy(&addri6->sin6_addr.s6_addr, + hostent->h_addr_list[0], sizeof (struct in6_addr)); - addr = (struct sockaddr *)addri; - break; - } - - case AF_INET6: - { - struct sockaddr_in6 *addri6; - - addrlen = sizeof (struct sockaddr_in6); - addri6 = malloc(addrlen); - - if (!addri6) - goto on_mem_error; - - addri6->sin6_family = AF_INET6; - addri6->sin6_port = htons(arg->svr->port); - addri6->sin6_flowinfo = 0; - addri6->sin6_scope_id = 0; - - memcpy(&addri6->sin6_addr.s6_addr, - hostent->h_addr_list[0], sizeof (struct in6_addr)); - - addr = (struct sockaddr *)addri6; - break; - } - - default: - fprintf(stderr, "Unknown addrtype %i\n", hostent->h_addrtype); - goto on_error; + addr = (struct sockaddr *)addri6; + break; } - if (!_ecore_con_info_ares_getnameinfo(arg, hostent->h_addrtype, - hostent->h_name, - addr, addrlen)) - goto on_error; + default: + fprintf(stderr, "Unknown addrtype %i\n", hostent->h_addrtype); + goto on_error; + } - break; + if (!_ecore_con_info_ares_getnameinfo(arg, hostent->h_addrtype, + hostent->h_name, + addr, addrlen)) + goto on_error; + + break; case ARES_ENOTFOUND: /* address notfound */ - if (arg->byaddr) - { - /* This happen when host doesn't have a reverse. */ + if (arg->byaddr) + { + /* This happen when host doesn't have a reverse. */ if (arg->isv6) { struct sockaddr_in6 *addri6; @@ -501,7 +508,7 @@ _ecore_con_info_ares_host_cb(Ecore_Con_CAres *arg, int status, int timeouts, addri6 = malloc(addrlen); if (!addri6) - goto on_mem_error; + goto on_mem_error; addri6->sin6_family = AF_INET6; addri6->sin6_port = htons(arg->svr->port); @@ -521,7 +528,7 @@ _ecore_con_info_ares_host_cb(Ecore_Con_CAres *arg, int status, int timeouts, addri = malloc(addrlen); if (!addri) - goto on_mem_error; + goto on_mem_error; addri->sin_family = AF_INET; addri->sin_port = htons(arg->svr->port); @@ -537,28 +544,28 @@ _ecore_con_info_ares_host_cb(Ecore_Con_CAres *arg, int status, int timeouts, AF_INET, NULL, addr, addrlen)) - goto on_error; + goto on_error; break; - } + } case ARES_ENOTIMP: /* unknown family */ case ARES_EBADNAME: /* not a valid internet address */ case ARES_ENOMEM: /* not enough memory */ case ARES_EDESTRUCTION: /* request canceled, shuting down */ - goto on_error; + goto on_error; default: - fprintf(stderr, - "Unknown status returned by c-ares: %i assuming error\n", - status); - goto on_error; + fprintf(stderr, + "Unknown status returned by c-ares: %i assuming error\n", + status); + goto on_error; } return; on_mem_error: - fprintf(stderr, "Not enough memory\n"); + fprintf(stderr, "Not enough memory\n"); on_error: arg->done_cb(arg->data, NULL); @@ -566,36 +573,39 @@ on_error: } static void -_ecore_con_info_ares_nameinfo(Ecore_Con_CAres *arg, int status, int timeouts, - char *node, - char *service) +_ecore_con_info_ares_nameinfo(Ecore_Con_CAres *arg, + int status, + int timeouts, + char *node, + char *service) { switch (status) { case ARES_SUCCESS: - if (node) - strcpy(arg->result->ip, node); - else - *arg->result->ip = '\0'; + if (node) + strcpy(arg->result->ip, node); + else + *arg->result->ip = '\0'; - if (service) - strcpy(arg->result->service, service); - else - *arg->result->service = '\0'; + if (service) + strcpy(arg->result->service, service); + else + *arg->result->service = '\0'; - arg->done_cb(arg->data, arg->result); - break; + arg->done_cb(arg->data, arg->result); + break; case ARES_ENOTIMP: case ARES_ENOTFOUND: case ARES_ENOMEM: case ARES_EDESTRUCTION: case ARES_EBADFLAGS: - arg->done_cb(arg->data, NULL); - break; + arg->done_cb(arg->data, NULL); + break; } free(arg->result->info.ai_addr); free(arg->result); free(arg); } + diff --git a/legacy/ecore/src/lib/ecore_con/ecore_con_info.c b/legacy/ecore/src/lib/ecore_con/ecore_con_info.c index 55fd6099d5..3585cd40c7 100644 --- a/legacy/ecore/src/lib/ecore_con/ecore_con_info.c +++ b/legacy/ecore/src/lib/ecore_con/ecore_con_info.c @@ -23,7 +23,7 @@ # ifdef __cplusplus extern "C" # endif -void *alloca (size_t); +void *alloca(size_t); #endif #include @@ -62,22 +62,22 @@ typedef struct _CB_Data CB_Data; struct _CB_Data { - EINA_INLIST; - Ecore_Con_Info_Cb cb_done; - void *data; - Ecore_Fd_Handler *fdh; - pid_t pid; + EINA_INLIST; + Ecore_Con_Info_Cb cb_done; + void *data; + Ecore_Fd_Handler *fdh; + pid_t pid; Ecore_Event_Handler *handler; - int fd2; + int fd2; }; - static void _ecore_con_info_readdata(CB_Data *cbdata); static void _ecore_con_info_slave_free(CB_Data *cbdata); -static Eina_Bool _ecore_con_info_data_handler(void *data, +static Eina_Bool _ecore_con_info_data_handler(void *data, Ecore_Fd_Handler *fd_handler); -static Eina_Bool _ecore_con_info_exit_handler(void *data, int type __UNUSED__, - void *event); +static Eina_Bool _ecore_con_info_exit_handler(void *data, + int type __UNUSED__, + void *event); static int info_init = 0; static CB_Data *info_slaves = NULL; @@ -94,7 +94,7 @@ ecore_con_info_shutdown(void) { info_init--; if (info_init == 0) - while (info_slaves) _ecore_con_info_slave_free(info_slaves); + while (info_slaves) _ecore_con_info_slave_free(info_slaves); return info_init; } @@ -102,7 +102,7 @@ ecore_con_info_shutdown(void) int ecore_con_info_tcp_connect(Ecore_Con_Server *svr, Ecore_Con_Info_Cb done_cb, - void *data) + void *data) { struct addrinfo hints; @@ -121,7 +121,7 @@ ecore_con_info_tcp_connect(Ecore_Con_Server *svr, int ecore_con_info_tcp_listen(Ecore_Con_Server *svr, Ecore_Con_Info_Cb done_cb, - void *data) + void *data) { struct addrinfo hints; @@ -140,7 +140,7 @@ ecore_con_info_tcp_listen(Ecore_Con_Server *svr, int ecore_con_info_udp_connect(Ecore_Con_Server *svr, Ecore_Con_Info_Cb done_cb, - void *data) + void *data) { struct addrinfo hints; @@ -159,7 +159,7 @@ ecore_con_info_udp_connect(Ecore_Con_Server *svr, int ecore_con_info_udp_listen(Ecore_Con_Server *svr, Ecore_Con_Info_Cb done_cb, - void *data) + void *data) { struct addrinfo hints; @@ -178,7 +178,7 @@ ecore_con_info_udp_listen(Ecore_Con_Server *svr, int ecore_con_info_mcast_listen(Ecore_Con_Server *svr, Ecore_Con_Info_Cb done_cb, - void *data) + void *data) { struct addrinfo hints; @@ -197,14 +197,14 @@ ecore_con_info_mcast_listen(Ecore_Con_Server *svr, EAPI int ecore_con_info_get(Ecore_Con_Server *svr, Ecore_Con_Info_Cb done_cb, - void *data, - struct addrinfo *hints) + void *data, + struct addrinfo *hints) { CB_Data *cbdata; int fd[2]; if (pipe(fd) < 0) - return 0; + return 0; cbdata = calloc(1, sizeof(CB_Data)); if (!cbdata) @@ -245,10 +245,10 @@ ecore_con_info_get(Ecore_Con_Server *svr, if (!getaddrinfo(svr->name, service, hints, &result) && result) { if (result->ai_canonname) - canonname_len = strlen(result->ai_canonname) + 1; + canonname_len = strlen(result->ai_canonname) + 1; tosend_len = sizeof(Ecore_Con_Info) + result->ai_addrlen + - canonname_len; + canonname_len; if (!(tosend = alloca(tosend_len))) goto on_error; memset(tosend, 0, tosend_len); @@ -270,7 +270,7 @@ ecore_con_info_get(Ecore_Con_Server *svr, hbuf, sizeof(hbuf), sbuf, sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV)) { - memcpy(container->ip, hbuf, sizeof(container->ip)); + memcpy(container->ip, hbuf, sizeof(container->ip)); memcpy(container->service, sbuf, sizeof(container->service)); } @@ -279,7 +279,7 @@ ecore_con_info_get(Ecore_Con_Server *svr, on_error: if (result) - freeaddrinfo(result); + freeaddrinfo(result); err = write(fd[1], "", 1); close(fd[1]); @@ -292,8 +292,8 @@ on_error: /* PARENT */ cbdata->handler = - ecore_event_handler_add(ECORE_EXE_EVENT_DEL, _ecore_con_info_exit_handler, - cbdata); + ecore_event_handler_add(ECORE_EXE_EVENT_DEL, _ecore_con_info_exit_handler, + cbdata); close(fd[1]); if (!cbdata->handler) { @@ -304,7 +304,7 @@ on_error: } info_slaves = (CB_Data *)eina_inlist_append(EINA_INLIST_GET( - info_slaves), + info_slaves), EINA_INLIST_GET(cbdata)); return 1; } @@ -337,13 +337,13 @@ _ecore_con_info_readdata(CB_Data *cbdata) recv = (Ecore_Con_Info *)torecv; recv->info.ai_addr = - (struct sockaddr *)(torecv + sizeof(Ecore_Con_Info)); + (struct sockaddr *)(torecv + sizeof(Ecore_Con_Info)); if ((size_t)torecv_len != (sizeof(Ecore_Con_Info) + recv->info.ai_addrlen)) - recv->info.ai_canonname = (char *) - (torecv + sizeof(Ecore_Con_Info) + recv->info.ai_addrlen); + recv->info.ai_canonname = (char *) + (torecv + sizeof(Ecore_Con_Info) + recv->info.ai_addrlen); else - recv->info.ai_canonname = NULL; + recv->info.ai_canonname = NULL; recv->info.ai_next = NULL; @@ -352,10 +352,10 @@ _ecore_con_info_readdata(CB_Data *cbdata) free(torecv); } else - cbdata->cb_done(cbdata->data, NULL); + cbdata->cb_done(cbdata->data, NULL); } else - cbdata->cb_done(cbdata->data, NULL); + cbdata->cb_done(cbdata->data, NULL); cbdata->cb_done = NULL; } @@ -372,7 +372,8 @@ _ecore_con_info_slave_free(CB_Data *cbdata) } static Eina_Bool -_ecore_con_info_data_handler(void *data, Ecore_Fd_Handler *fd_handler) +_ecore_con_info_data_handler(void *data, + Ecore_Fd_Handler *fd_handler) { CB_Data *cbdata; @@ -381,7 +382,7 @@ _ecore_con_info_data_handler(void *data, Ecore_Fd_Handler *fd_handler) { if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ)) - _ecore_con_info_readdata(cbdata); + _ecore_con_info_readdata(cbdata); else { cbdata->cb_done(cbdata->data, NULL); @@ -394,7 +395,9 @@ _ecore_con_info_data_handler(void *data, Ecore_Fd_Handler *fd_handler) } static Eina_Bool -_ecore_con_info_exit_handler(void *data, int type __UNUSED__, void *event) +_ecore_con_info_exit_handler(void *data, + int type __UNUSED__, + void *event) { CB_Data *cbdata; Ecore_Exe_Event_Del *ev; @@ -402,9 +405,10 @@ _ecore_con_info_exit_handler(void *data, int type __UNUSED__, void *event) ev = event; cbdata = data; if (cbdata->pid != ev->pid) - return ECORE_CALLBACK_RENEW; + return ECORE_CALLBACK_RENEW; return ECORE_CALLBACK_CANCEL; /* FIXME: Woot ??? */ _ecore_con_info_slave_free(cbdata); return ECORE_CALLBACK_CANCEL; } + diff --git a/legacy/ecore/src/lib/ecore_con/ecore_con_local.c b/legacy/ecore/src/lib/ecore_con/ecore_con_local.c index cb1fc40cb8..658fdc8127 100644 --- a/legacy/ecore/src/lib/ecore_con/ecore_con_local.c +++ b/legacy/ecore/src/lib/ecore_con/ecore_con_local.c @@ -31,22 +31,20 @@ #include "Ecore_Con.h" #include "ecore_con_private.h" - -#define LENGTH_OF_SOCKADDR_UN(s) (strlen((s)->sun_path) + \ - (size_t)(((struct sockaddr_un *)NULL)-> \ - sun_path)) -#define LENGTH_OF_ABSTRACT_SOCKADDR_UN(s, path) (strlen(path) + 1 + \ +#define LENGTH_OF_SOCKADDR_UN(s) (strlen((s)->sun_path) + \ + (size_t)(((struct sockaddr_un *)NULL)-> \ + sun_path)) +#define LENGTH_OF_ABSTRACT_SOCKADDR_UN(s, path) (strlen(path) + 1 + \ (size_t)(((struct sockaddr_un \ *)NULL)->sun_path)) - static int _ecore_con_local_init_count = 0; int ecore_con_local_init(void) { if (++_ecore_con_local_init_count != 1) - return _ecore_con_local_init_count; + return _ecore_con_local_init_count; return _ecore_con_local_init_count; } @@ -55,17 +53,18 @@ int ecore_con_local_shutdown(void) { if (--_ecore_con_local_init_count != 0) - return _ecore_con_local_init_count; + return _ecore_con_local_init_count; return _ecore_con_local_init_count; } int -ecore_con_local_connect(Ecore_Con_Server *svr, - Eina_Bool (*cb_done)(void *data, - Ecore_Fd_Handler *fd_handler), - void *data __UNUSED__, - void (*cb_free)(void *data, void *ev)) +ecore_con_local_connect(Ecore_Con_Server *svr, + Eina_Bool (*cb_done)(void *data, + Ecore_Fd_Handler *fd_handler), + void *data __UNUSED__, + void (*cb_free)(void *data, + void *ev)) { char buf[4096]; struct sockaddr_un socket_unix; @@ -77,10 +76,10 @@ ecore_con_local_connect(Ecore_Con_Server *svr, { homedir = getenv("HOME"); if (!homedir) - homedir = getenv("TMP"); + homedir = getenv("TMP"); if (!homedir) - homedir = "/tmp"; + homedir = "/tmp"; snprintf(buf, sizeof(buf), "%s/.ecore/%s/%i", homedir, svr->name, svr->port); @@ -90,39 +89,39 @@ ecore_con_local_connect(Ecore_Con_Server *svr, if (svr->port < 0) { if (svr->name[0] == '/') - strncpy(buf, svr->name, sizeof(buf)); + strncpy(buf, svr->name, sizeof(buf)); else - snprintf(buf, sizeof(buf), "/tmp/.ecore_service|%s", svr->name); + snprintf(buf, sizeof(buf), "/tmp/.ecore_service|%s", svr->name); } else { if (svr->name[0] == '/') - snprintf(buf, sizeof(buf), "%s|%i", svr->name, - svr->port); + snprintf(buf, sizeof(buf), "%s|%i", svr->name, + svr->port); else - snprintf(buf, sizeof(buf), "/tmp/.ecore_service|%s|%i", - svr->name, - svr->port); + snprintf(buf, sizeof(buf), "/tmp/.ecore_service|%s|%i", + svr->name, + svr->port); } } else if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_LOCAL_ABSTRACT) - strncpy(buf, svr->name, - sizeof(buf)); + strncpy(buf, svr->name, + sizeof(buf)); svr->fd = socket(AF_UNIX, SOCK_STREAM, 0); if (svr->fd < 0) - return 0; + return 0; if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) - return 0; + return 0; if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) - return 0; + return 0; if (setsockopt(svr->fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&curstate, sizeof(curstate)) < 0) - return 0; + return 0; socket_unix.sun_family = AF_UNIX; @@ -148,34 +147,34 @@ ecore_con_local_connect(Ecore_Con_Server *svr, if (connect(svr->fd, (struct sockaddr *)&socket_unix, socket_unix_len) < 0) - return 0; + return 0; svr->path = strdup(buf); if (!svr->path) - return 0; + return 0; if (svr->type & ECORE_CON_SSL) - ecore_con_ssl_server_init(svr); + ecore_con_ssl_server_init(svr); svr->fd_handler = - ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ, - cb_done, svr, NULL, NULL); + ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ, + cb_done, svr, NULL, NULL); if (!svr->fd_handler) - return 0; + return 0; if (!svr->delete_me) { /* we got our server! */ - Ecore_Con_Event_Server_Add *e; + Ecore_Con_Event_Server_Add *e; - e = calloc(1, sizeof(Ecore_Con_Event_Server_Add)); - if (e) - { - svr->event_count++; - e->server = svr; - ecore_event_add(ECORE_CON_EVENT_SERVER_ADD, e, - cb_free, NULL); - } + e = calloc(1, sizeof(Ecore_Con_Event_Server_Add)); + if (e) + { + svr->event_count++; + e->server = svr; + ecore_event_add(ECORE_CON_EVENT_SERVER_ADD, e, + cb_free, NULL); + } } return 1; @@ -183,13 +182,13 @@ ecore_con_local_connect(Ecore_Con_Server *svr, int ecore_con_local_listen( - Ecore_Con_Server *svr, - Eina_Bool (* - cb_listen)(void *data, - Ecore_Fd_Handler * - fd_handler), - void *data - __UNUSED__) + Ecore_Con_Server *svr, + Eina_Bool (* + cb_listen)(void *data, + Ecore_Fd_Handler * + fd_handler), + void *data + __UNUSED__) { char buf[4096]; struct sockaddr_un socket_unix; @@ -206,21 +205,21 @@ ecore_con_local_listen( { homedir = getenv("HOME"); if (!homedir) - homedir = getenv("TMP"); + homedir = getenv("TMP"); if (!homedir) - homedir = "/tmp"; + homedir = "/tmp"; mask = S_IRUSR | S_IWUSR | S_IXUSR; snprintf(buf, sizeof(buf), "%s/.ecore", homedir); if (stat(buf, &st) < 0) - mkdir(buf, mask); + mkdir(buf, mask); snprintf(buf, sizeof(buf), "%s/.ecore/%s", homedir, svr->name); if (stat(buf, &st) < 0) - mkdir(buf, mask); + mkdir(buf, mask); - snprintf(buf, + snprintf(buf, sizeof(buf), "%s/.ecore/%s/%i", homedir, @@ -234,45 +233,45 @@ ecore_con_local_listen( if (svr->name[0] == '/') { if (svr->port >= 0) - snprintf(buf, - sizeof(buf), - "%s|%i", - svr->name, - svr->port); + snprintf(buf, + sizeof(buf), + "%s|%i", + svr->name, + svr->port); else - snprintf(buf, - sizeof(buf), - "%s", - svr->name); + snprintf(buf, + sizeof(buf), + "%s", + svr->name); } else - snprintf(buf, - sizeof(buf), - "/tmp/.ecore_service|%s|%i", - svr->name, - svr->port); + snprintf(buf, + sizeof(buf), + "/tmp/.ecore_service|%s|%i", + svr->name, + svr->port); } else if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_LOCAL_ABSTRACT) - strncpy(buf, svr->name, - sizeof(buf)); + strncpy(buf, svr->name, + sizeof(buf)); pmode = umask(mask); start: svr->fd = socket(AF_UNIX, SOCK_STREAM, 0); if (svr->fd < 0) - goto error_umask; + goto error_umask; if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) - goto error_umask; + goto error_umask; if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) - goto error_umask; + goto error_umask; lin.l_onoff = 1; lin.l_linger = 0; if (setsockopt(svr->fd, SOL_SOCKET, SO_LINGER, (const void *)&lin, sizeof(struct linger)) < 0) - goto error_umask; + goto error_umask; socket_unix.sun_family = AF_UNIX; if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_LOCAL_ABSTRACT) @@ -303,24 +302,24 @@ start: (connect(svr->fd, (struct sockaddr *)&socket_unix, socket_unix_len) < 0) && (unlink(buf) >= 0)) - goto start; + goto start; else - goto error_umask; + goto error_umask; } if (listen(svr->fd, 4096) < 0) - goto error_umask; + goto error_umask; svr->path = strdup(buf); if (!svr->path) - goto error_umask; + goto error_umask; svr->fd_handler = - ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ, - cb_listen, svr, NULL, NULL); + ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ, + cb_listen, svr, NULL, NULL); umask(pmode); if (!svr->fd_handler) - goto error; + goto error; return 1; @@ -329,3 +328,4 @@ error_umask: error: return 0; } + diff --git a/legacy/ecore/src/lib/ecore_con/ecore_con_ssl.c b/legacy/ecore/src/lib/ecore_con/ecore_con_ssl.c index c859963d9f..776a142fae 100644 --- a/legacy/ecore/src/lib/ecore_con/ecore_con_ssl.c +++ b/legacy/ecore/src/lib/ecore_con/ecore_con_ssl.c @@ -48,45 +48,55 @@ static int _client_connected = 0; static void _gnutls_print_errors(int ret) { - if (ret) - ERR("gnutls returned with error: %s - %s", gnutls_strerror_name(ret), gnutls_strerror(ret)); + if (ret) + ERR("gnutls returned with error: %s - %s", gnutls_strerror_name(ret), gnutls_strerror(ret)); } - static void -_gnutls_log_func(int level, const char *str) +_gnutls_log_func(int level, + const char *str) { DBG("|<%d>| %s", level, str); } - -static const char* +static const char * SSL_GNUTLS_PRINT_HANDSHAKE_STATUS(gnutls_handshake_description_t status) { switch (status) { case GNUTLS_HANDSHAKE_HELLO_REQUEST: return "Hello request"; + case GNUTLS_HANDSHAKE_CLIENT_HELLO: return "Client hello"; + case GNUTLS_HANDSHAKE_SERVER_HELLO: return "Server hello"; + case GNUTLS_HANDSHAKE_NEW_SESSION_TICKET: return "New session ticket"; + case GNUTLS_HANDSHAKE_CERTIFICATE_PKT: return "Certificate packet"; + case GNUTLS_HANDSHAKE_SERVER_KEY_EXCHANGE: return "Server key exchange"; + case GNUTLS_HANDSHAKE_CERTIFICATE_REQUEST: return "Certificate request"; + case GNUTLS_HANDSHAKE_SERVER_HELLO_DONE: return "Server hello done"; + case GNUTLS_HANDSHAKE_CERTIFICATE_VERIFY: return "Certificate verify"; + case GNUTLS_HANDSHAKE_CLIENT_KEY_EXCHANGE: return "Client key exchange"; + case GNUTLS_HANDSHAKE_FINISHED: return "Finished"; + case GNUTLS_HANDSHAKE_SUPPLEMENTAL: return "Supplemental"; } @@ -107,54 +117,54 @@ _openssl_print_errors(void) ERR("openssl error: %s", ERR_reason_error_string(err)); } while (1); } + #endif -#define SSL_ERROR_CHECK_GOTO_ERROR(X) \ -do \ - { \ - if ((X)) \ - { \ - ERR("Error at %s:%s:%d!", __FILE__, __PRETTY_FUNCTION__, __LINE__); \ - goto error; \ - } \ - } \ -while (0) - +#define SSL_ERROR_CHECK_GOTO_ERROR(X) \ + do \ + { \ + if ((X)) \ + { \ + ERR("Error at %s:%s:%d!", __FILE__, __PRETTY_FUNCTION__, __LINE__); \ + goto error; \ + } \ + } \ + while (0) static Ecore_Con_Ssl_Error - SSL_SUFFIX(_ecore_con_ssl_init) (void); + SSL_SUFFIX(_ecore_con_ssl_init) (void); static Ecore_Con_Ssl_Error - SSL_SUFFIX(_ecore_con_ssl_shutdown) (void); + SSL_SUFFIX(_ecore_con_ssl_shutdown) (void); -static Eina_Bool SSL_SUFFIX(_ecore_con_ssl_server_cafile_add) (Ecore_Con_Server *svr, const char *ca_file); -static Eina_Bool SSL_SUFFIX(_ecore_con_ssl_server_crl_add) (Ecore_Con_Server *svr, const char *crl_file); -static Eina_Bool SSL_SUFFIX(_ecore_con_ssl_server_cert_add) (Ecore_Con_Server *svr, const char *cert); -static Eina_Bool SSL_SUFFIX(_ecore_con_ssl_server_privkey_add) (Ecore_Con_Server *svr, const char *key_file); +static Eina_Bool SSL_SUFFIX(_ecore_con_ssl_server_cafile_add) (Ecore_Con_Server * svr, const char *ca_file); +static Eina_Bool SSL_SUFFIX(_ecore_con_ssl_server_crl_add) (Ecore_Con_Server * svr, const char *crl_file); +static Eina_Bool SSL_SUFFIX(_ecore_con_ssl_server_cert_add) (Ecore_Con_Server * svr, const char *cert); +static Eina_Bool SSL_SUFFIX(_ecore_con_ssl_server_privkey_add) (Ecore_Con_Server * svr, const char *key_file); -static Ecore_Con_Ssl_Error SSL_SUFFIX(_ecore_con_ssl_server_prepare)(Ecore_Con_Server *svr, int ssl_type); +static Ecore_Con_Ssl_Error SSL_SUFFIX(_ecore_con_ssl_server_prepare) (Ecore_Con_Server * svr, int ssl_type); static Ecore_Con_Ssl_Error - SSL_SUFFIX(_ecore_con_ssl_server_init) (Ecore_Con_Server * svr); + SSL_SUFFIX(_ecore_con_ssl_server_init) (Ecore_Con_Server * svr); static Ecore_Con_Ssl_Error - SSL_SUFFIX(_ecore_con_ssl_server_shutdown) (Ecore_Con_Server * + SSL_SUFFIX(_ecore_con_ssl_server_shutdown) (Ecore_Con_Server * svr); static int - SSL_SUFFIX(_ecore_con_ssl_server_read) (Ecore_Con_Server * svr, +SSL_SUFFIX(_ecore_con_ssl_server_read) (Ecore_Con_Server * svr, unsigned char *buf, int size); static int - SSL_SUFFIX(_ecore_con_ssl_server_write) (Ecore_Con_Server * +SSL_SUFFIX(_ecore_con_ssl_server_write) (Ecore_Con_Server * svr, unsigned char *buf, int size); static Ecore_Con_Ssl_Error - SSL_SUFFIX(_ecore_con_ssl_client_init) (Ecore_Con_Client * cl); + SSL_SUFFIX(_ecore_con_ssl_client_init) (Ecore_Con_Client * cl); static Ecore_Con_Ssl_Error - SSL_SUFFIX(_ecore_con_ssl_client_shutdown) (Ecore_Con_Client * + SSL_SUFFIX(_ecore_con_ssl_client_shutdown) (Ecore_Con_Client * cl); static int - SSL_SUFFIX(_ecore_con_ssl_client_read) (Ecore_Con_Client * cl, +SSL_SUFFIX(_ecore_con_ssl_client_read) (Ecore_Con_Client * cl, unsigned char *buf, int size); static int - SSL_SUFFIX(_ecore_con_ssl_client_write) (Ecore_Con_Client * cl, +SSL_SUFFIX(_ecore_con_ssl_client_write) (Ecore_Con_Client * cl, unsigned char *buf, int size); /* @@ -165,7 +175,7 @@ Ecore_Con_Ssl_Error ecore_con_ssl_init(void) { if (!_init_con_ssl_init_count++) - SSL_SUFFIX(_ecore_con_ssl_init) (); + SSL_SUFFIX(_ecore_con_ssl_init) (); return _init_con_ssl_init_count; } @@ -180,7 +190,8 @@ ecore_con_ssl_shutdown(void) } Ecore_Con_Ssl_Error -ecore_con_ssl_server_prepare(Ecore_Con_Server *svr, int ssl_type) +ecore_con_ssl_server_prepare(Ecore_Con_Server *svr, + int ssl_type) { if (!ssl_type) return ECORE_CON_SSL_ERROR_NONE; @@ -204,13 +215,17 @@ ecore_con_ssl_server_shutdown(Ecore_Con_Server *svr) } int -ecore_con_ssl_server_read(Ecore_Con_Server *svr, unsigned char *buf, int size) +ecore_con_ssl_server_read(Ecore_Con_Server *svr, + unsigned char *buf, + int size) { return SSL_SUFFIX(_ecore_con_ssl_server_read) (svr, buf, size); } int -ecore_con_ssl_server_write(Ecore_Con_Server *svr, unsigned char *buf, int size) +ecore_con_ssl_server_write(Ecore_Con_Server *svr, + unsigned char *buf, + int size) { return SSL_SUFFIX(_ecore_con_ssl_server_write) (svr, buf, size); } @@ -232,13 +247,17 @@ ecore_con_ssl_client_shutdown(Ecore_Con_Client *cl) } int -ecore_con_ssl_client_read(Ecore_Con_Client *cl, unsigned char *buf, int size) +ecore_con_ssl_client_read(Ecore_Con_Client *cl, + unsigned char *buf, + int size) { return SSL_SUFFIX(_ecore_con_ssl_client_read) (cl, buf, size); } int -ecore_con_ssl_client_write(Ecore_Con_Client *cl, unsigned char *buf, int size) +ecore_con_ssl_client_write(Ecore_Con_Client *cl, + unsigned char *buf, + int size) { return SSL_SUFFIX(_ecore_con_ssl_client_write) (cl, buf, size); } @@ -280,7 +299,7 @@ ecore_con_ssl_server_verify(Ecore_Con_Server *svr) } svr->verify = EINA_TRUE; } - + /** * @brief Add an ssl certificate for use in ecore_con functions. * @@ -293,7 +312,7 @@ ecore_con_ssl_server_verify(Ecore_Con_Server *svr) EAPI Eina_Bool ecore_con_ssl_server_cert_add(Ecore_Con_Server *svr, - const char *cert) + const char *cert) { if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER)) { @@ -301,7 +320,7 @@ ecore_con_ssl_server_cert_add(Ecore_Con_Server *svr, return EINA_FALSE; } - return SSL_SUFFIX(_ecore_con_ssl_server_cert_add)(svr, cert); + return SSL_SUFFIX(_ecore_con_ssl_server_cert_add) (svr, cert); } /** @@ -316,7 +335,7 @@ ecore_con_ssl_server_cert_add(Ecore_Con_Server *svr, EAPI Eina_Bool ecore_con_ssl_server_cafile_add(Ecore_Con_Server *svr, - const char *ca_file) + const char *ca_file) { if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER)) { @@ -324,7 +343,7 @@ ecore_con_ssl_server_cafile_add(Ecore_Con_Server *svr, return EINA_FALSE; } - return SSL_SUFFIX(_ecore_con_ssl_server_cafile_add)(svr, ca_file); + return SSL_SUFFIX(_ecore_con_ssl_server_cafile_add) (svr, ca_file); } /** @@ -340,7 +359,7 @@ ecore_con_ssl_server_cafile_add(Ecore_Con_Server *svr, EAPI Eina_Bool ecore_con_ssl_server_privkey_add(Ecore_Con_Server *svr, - const char *key_file) + const char *key_file) { if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER)) { @@ -348,7 +367,7 @@ ecore_con_ssl_server_privkey_add(Ecore_Con_Server *svr, return EINA_FALSE; } - return SSL_SUFFIX(_ecore_con_ssl_server_privkey_add)(svr, key_file); + return SSL_SUFFIX(_ecore_con_ssl_server_privkey_add) (svr, key_file); } /** @@ -364,7 +383,7 @@ ecore_con_ssl_server_privkey_add(Ecore_Con_Server *svr, EAPI Eina_Bool ecore_con_ssl_server_crl_add(Ecore_Con_Server *svr, - const char *crl_file) + const char *crl_file) { if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER)) { @@ -372,7 +391,7 @@ ecore_con_ssl_server_crl_add(Ecore_Con_Server *svr, return EINA_FALSE; } - return SSL_SUFFIX(_ecore_con_ssl_server_crl_add)(svr, crl_file); + return SSL_SUFFIX(_ecore_con_ssl_server_crl_add) (svr, crl_file); } /** @@ -390,10 +409,10 @@ _ecore_con_ssl_init_gnutls(void) { #ifdef EFL_HAVE_PTHREAD if (gcry_control(GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread)) - WRN("YOU ARE USING PTHREADS, BUT I CANNOT INITIALIZE THREADSAFE GCRYPT OPERATIONS!"); + WRN("YOU ARE USING PTHREADS, BUT I CANNOT INITIALIZE THREADSAFE GCRYPT OPERATIONS!"); #endif if (gnutls_global_init()) - return ECORE_CON_SSL_ERROR_INIT_FAILED; + return ECORE_CON_SSL_ERROR_INIT_FAILED; gnutls_global_set_log_level(9); gnutls_global_set_log_function(_gnutls_log_func); @@ -409,7 +428,8 @@ _ecore_con_ssl_shutdown_gnutls(void) } static Ecore_Con_Ssl_Error -_ecore_con_ssl_server_prepare_gnutls(Ecore_Con_Server *svr, int ssl_type) +_ecore_con_ssl_server_prepare_gnutls(Ecore_Con_Server *svr, + int ssl_type) { int ret; @@ -424,10 +444,10 @@ _ecore_con_ssl_server_prepare_gnutls(Ecore_Con_Server *svr, int ssl_type) case ECORE_CON_USE_TLS | ECORE_CON_LOAD_CERT: case ECORE_CON_USE_MIXED: case ECORE_CON_USE_MIXED | ECORE_CON_LOAD_CERT: - break; + break; default: - return ECORE_CON_SSL_ERROR_NONE; + return ECORE_CON_SSL_ERROR_NONE; } SSL_ERROR_CHECK_GOTO_ERROR(ret = gnutls_certificate_allocate_credentials(&svr->cert)); @@ -440,7 +460,7 @@ _ecore_con_ssl_server_prepare_gnutls(Ecore_Con_Server *svr, int ssl_type) SSL_ERROR_CHECK_GOTO_ERROR(ret = gnutls_anon_allocate_server_credentials(&svr->anoncred_s)); /* TODO: implement PSK */ - // SSL_ERROR_CHECK_GOTO_ERROR(ret = gnutls_psk_allocate_server_credentials(&svr->pskcred_s)); + // SSL_ERROR_CHECK_GOTO_ERROR(ret = gnutls_psk_allocate_server_credentials(&svr->pskcred_s)); gnutls_anon_set_server_dh_params(svr->anoncred_s, svr->dh_params); gnutls_certificate_set_dh_params(svr->cert, svr->dh_params); @@ -450,7 +470,7 @@ _ecore_con_ssl_server_prepare_gnutls(Ecore_Con_Server *svr, int ssl_type) else if (!svr->use_cert) { //SSL_ERROR_CHECK_GOTO_ERROR(ret = gnutls_psk_allocate_client_credentials(&svr->pskcred_c)); - SSL_ERROR_CHECK_GOTO_ERROR(ret = gnutls_anon_allocate_client_credentials(&svr->anoncred_c)); + SSL_ERROR_CHECK_GOTO_ERROR(ret = gnutls_anon_allocate_client_credentials(&svr->anoncred_c)); } return ECORE_CON_SSL_ERROR_NONE; @@ -474,6 +494,7 @@ _ecore_con_ssl_server_init_gnutls(Ecore_Con_Server *svr) { case ECORE_CON_SSL_STATE_DONE: return ECORE_CON_SSL_ERROR_NONE; + case ECORE_CON_SSL_STATE_INIT: if (svr->type & ECORE_CON_USE_SSL2) /* not supported because of security issues */ return ECORE_CON_SSL_ERROR_SSL2_NOT_SUPPORTED; @@ -482,20 +503,20 @@ _ecore_con_ssl_server_init_gnutls(Ecore_Con_Server *svr) { case ECORE_CON_USE_SSL3: case ECORE_CON_USE_SSL3 | ECORE_CON_LOAD_CERT: - priority = "NONE:%VERIFY_ALLOW_X509_V1_CA_CRT:+RSA:+DHE-RSA:+DHE-DSS:+ANON-DH:+COMP-DEFLATE:+COMP-NULL:+CTYPE-X509:+SHA1:+SHA256:+SHA384:+SHA512:+AES-256-CBC:+AES-128-CBC:+3DES-CBC:!VERS-TLS1.0:!VERS-TLS1.1"; - break; + priority = "NONE:%VERIFY_ALLOW_X509_V1_CA_CRT:+RSA:+DHE-RSA:+DHE-DSS:+ANON-DH:+COMP-DEFLATE:+COMP-NULL:+CTYPE-X509:+SHA1:+SHA256:+SHA384:+SHA512:+AES-256-CBC:+AES-128-CBC:+3DES-CBC:!VERS-TLS1.0:!VERS-TLS1.1"; + break; case ECORE_CON_USE_TLS: case ECORE_CON_USE_TLS | ECORE_CON_LOAD_CERT: - priority = "NONE:%VERIFY_ALLOW_X509_V1_CA_CRT:+RSA:+DHE-RSA:+DHE-DSS:+ANON-DH:+COMP-DEFLATE:+COMP-NULL:+CTYPE-X509:+SHA1:+SHA256:+SHA384:+SHA512:+AES-256-CBC:+AES-128-CBC:+3DES-CBC:!VERS-SSL3.0"; - break; + priority = "NONE:%VERIFY_ALLOW_X509_V1_CA_CRT:+RSA:+DHE-RSA:+DHE-DSS:+ANON-DH:+COMP-DEFLATE:+COMP-NULL:+CTYPE-X509:+SHA1:+SHA256:+SHA384:+SHA512:+AES-256-CBC:+AES-128-CBC:+3DES-CBC:!VERS-SSL3.0"; + break; case ECORE_CON_USE_MIXED: case ECORE_CON_USE_MIXED | ECORE_CON_LOAD_CERT: - break; + break; default: - return ECORE_CON_SSL_ERROR_NONE; + return ECORE_CON_SSL_ERROR_NONE; } SSL_ERROR_CHECK_GOTO_ERROR(ret = gnutls_init(&svr->session, GNUTLS_CLIENT)); @@ -504,13 +525,14 @@ _ecore_con_ssl_server_init_gnutls(Ecore_Con_Server *svr) INF("Applying priority string: %s", priority); SSL_ERROR_CHECK_GOTO_ERROR(ret = gnutls_priority_set_direct(svr->session, priority, NULL)); SSL_ERROR_CHECK_GOTO_ERROR(ret = gnutls_credentials_set(svr->session, GNUTLS_CRD_CERTIFICATE, svr->cert)); - // SSL_ERROR_CHECK_GOTO_ERROR(ret = gnutls_credentials_set(svr->session, GNUTLS_CRD_PSK, svr->pskcred_c)); + // SSL_ERROR_CHECK_GOTO_ERROR(ret = gnutls_credentials_set(svr->session, GNUTLS_CRD_PSK, svr->pskcred_c)); if (!svr->use_cert) SSL_ERROR_CHECK_GOTO_ERROR(ret = gnutls_credentials_set(svr->session, GNUTLS_CRD_ANON, svr->anoncred_c)); gnutls_dh_set_prime_bits(svr->session, 512); gnutls_transport_set_ptr(svr->session, (gnutls_transport_ptr_t)svr->fd); svr->ssl_state = ECORE_CON_SSL_STATE_HANDSHAKING; + case ECORE_CON_SSL_STATE_HANDSHAKING: ret = gnutls_handshake(svr->session); DBG("calling gnutls_handshake(): returned with '%s'", gnutls_strerror_name(ret)); @@ -528,6 +550,7 @@ _ecore_con_ssl_server_init_gnutls(Ecore_Con_Server *svr) ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ); return ECORE_CON_SSL_ERROR_NONE; } + default: break; } @@ -558,7 +581,6 @@ _ecore_con_ssl_server_init_gnutls(Ecore_Con_Server *svr) goto error; } - SSL_ERROR_CHECK_GOTO_ERROR(!(cert_list = gnutls_certificate_get_peers(svr->session, &cert_list_size))); SSL_ERROR_CHECK_GOTO_ERROR(!cert_list_size); @@ -576,8 +598,8 @@ error: ERR("Also received alert: %s", gnutls_alert_get_name(gnutls_alert_get(svr->session))); if (svr->ssl_state != ECORE_CON_SSL_STATE_DONE) { - ERR("last out: %s", SSL_GNUTLS_PRINT_HANDSHAKE_STATUS(gnutls_handshake_get_last_out(svr->session))); - ERR("last in: %s", SSL_GNUTLS_PRINT_HANDSHAKE_STATUS(gnutls_handshake_get_last_in(svr->session))); + ERR("last out: %s", SSL_GNUTLS_PRINT_HANDSHAKE_STATUS(gnutls_handshake_get_last_out(svr->session))); + ERR("last in: %s", SSL_GNUTLS_PRINT_HANDSHAKE_STATUS(gnutls_handshake_get_last_in(svr->session))); } if (cert) gnutls_x509_crt_deinit(cert); @@ -586,10 +608,11 @@ error: } static Eina_Bool -_ecore_con_ssl_server_cafile_add_gnutls(Ecore_Con_Server *svr, const char *ca_file) +_ecore_con_ssl_server_cafile_add_gnutls(Ecore_Con_Server *svr, + const char *ca_file) { SSL_ERROR_CHECK_GOTO_ERROR(gnutls_certificate_set_x509_trust_file(svr->cert, ca_file, - GNUTLS_X509_FMT_PEM) < 1); + GNUTLS_X509_FMT_PEM) < 1); return EINA_TRUE; error: @@ -598,10 +621,11 @@ error: } static Eina_Bool -_ecore_con_ssl_server_crl_add_gnutls(Ecore_Con_Server *svr, const char *crl_file) +_ecore_con_ssl_server_crl_add_gnutls(Ecore_Con_Server *svr, + const char *crl_file) { SSL_ERROR_CHECK_GOTO_ERROR(gnutls_certificate_set_x509_crl_file(svr->cert, crl_file, - GNUTLS_X509_FMT_PEM) < 1); + GNUTLS_X509_FMT_PEM) < 1); return EINA_TRUE; error: @@ -609,12 +633,12 @@ error: return EINA_FALSE; } - static Eina_Bool -_ecore_con_ssl_server_privkey_add_gnutls(Ecore_Con_Server *svr, const char *key_file) +_ecore_con_ssl_server_privkey_add_gnutls(Ecore_Con_Server *svr, + const char *key_file) { SSL_ERROR_CHECK_GOTO_ERROR(gnutls_certificate_set_x509_key_file(svr->cert, svr->cert_file, key_file, - GNUTLS_X509_FMT_PEM)); + GNUTLS_X509_FMT_PEM)); return EINA_TRUE; error: @@ -622,9 +646,9 @@ error: return EINA_FALSE; } - static Eina_Bool -_ecore_con_ssl_server_cert_add_gnutls(Ecore_Con_Server *svr, const char *cert_file) +_ecore_con_ssl_server_cert_add_gnutls(Ecore_Con_Server *svr, + const char *cert_file) { if (!(svr->cert_file = strdup(cert_file))) return EINA_FALSE; @@ -632,7 +656,6 @@ _ecore_con_ssl_server_cert_add_gnutls(Ecore_Con_Server *svr, const char *cert_fi return EINA_TRUE; } - static Ecore_Con_Ssl_Error _ecore_con_ssl_server_shutdown_gnutls(Ecore_Con_Server *svr) { @@ -658,8 +681,8 @@ _ecore_con_ssl_server_shutdown_gnutls(Ecore_Con_Server *svr) } if (svr->anoncred_s) gnutls_anon_free_server_credentials(svr->anoncred_s); - // if (svr->pskcred_s) - // gnutls_psk_free_server_credentials(svr->pskcred_s); + // if (svr->pskcred_s) + // gnutls_psk_free_server_credentials(svr->pskcred_s); svr->anoncred_s = NULL; svr->pskcred_s = NULL; @@ -668,8 +691,8 @@ _ecore_con_ssl_server_shutdown_gnutls(Ecore_Con_Server *svr) { if (svr->anoncred_c) gnutls_anon_free_client_credentials(svr->anoncred_c); - // if (svr->pskcred_c) - // gnutls_psk_free_client_credentials(svr->pskcred_c); + // if (svr->pskcred_c) + // gnutls_psk_free_client_credentials(svr->pskcred_c); svr->anoncred_c = NULL; svr->pskcred_c = NULL; @@ -680,10 +703,10 @@ _ecore_con_ssl_server_shutdown_gnutls(Ecore_Con_Server *svr) return ECORE_CON_SSL_ERROR_NONE; } - static int -_ecore_con_ssl_server_read_gnutls(Ecore_Con_Server *svr, unsigned char *buf, - int size) +_ecore_con_ssl_server_read_gnutls(Ecore_Con_Server *svr, + unsigned char *buf, + int size) { int num; @@ -694,10 +717,10 @@ _ecore_con_ssl_server_read_gnutls(Ecore_Con_Server *svr, unsigned char *buf, return 0; return -1; } - + num = gnutls_record_recv(svr->session, buf, size); if (num > 0) - return num; + return num; if (num == GNUTLS_E_REHANDSHAKE) { @@ -710,18 +733,18 @@ _ecore_con_ssl_server_read_gnutls(Ecore_Con_Server *svr, unsigned char *buf, return 0; } else if (!gnutls_error_is_fatal(num)) - return 0; + return 0; return -1; } static int -_ecore_con_ssl_server_write_gnutls(Ecore_Con_Server *svr, unsigned char *buf, - int size) +_ecore_con_ssl_server_write_gnutls(Ecore_Con_Server *svr, + unsigned char *buf, + int size) { int num; - if (svr->ssl_state == ECORE_CON_SSL_STATE_HANDSHAKING) { DBG("Continuing gnutls handshake"); @@ -732,12 +755,12 @@ _ecore_con_ssl_server_write_gnutls(Ecore_Con_Server *svr, unsigned char *buf, num = gnutls_record_send(svr->session, buf, size); if (num > 0) - return num; + return num; if (num == GNUTLS_E_REHANDSHAKE) { - WRN("Rehandshake request ignored"); - return 0; + WRN("Rehandshake request ignored"); + return 0; /* this is only partly functional I think? */ svr->handshaking = EINA_TRUE; svr->ssl_state = ECORE_CON_SSL_STATE_HANDSHAKING; @@ -745,12 +768,11 @@ _ecore_con_ssl_server_write_gnutls(Ecore_Con_Server *svr, unsigned char *buf, return 0; } else if (!gnutls_error_is_fatal(num)) - return 0; + return 0; return -1; } - static Ecore_Con_Ssl_Error _ecore_con_ssl_client_init_gnutls(Ecore_Con_Client *cl) { @@ -764,6 +786,7 @@ _ecore_con_ssl_client_init_gnutls(Ecore_Con_Client *cl) { case ECORE_CON_SSL_STATE_DONE: return ECORE_CON_SSL_ERROR_NONE; + case ECORE_CON_SSL_STATE_INIT: if (cl->host_server->type & ECORE_CON_USE_SSL2) /* not supported because of security issues */ return ECORE_CON_SSL_ERROR_SSL2_NOT_SUPPORTED; @@ -772,20 +795,20 @@ _ecore_con_ssl_client_init_gnutls(Ecore_Con_Client *cl) { case ECORE_CON_USE_SSL3: case ECORE_CON_USE_SSL3 | ECORE_CON_LOAD_CERT: - priority = "NONE:%VERIFY_ALLOW_X509_V1_CA_CRT:+RSA:+DHE-RSA:+DHE-DSS:+ANON-DH:+COMP-DEFLATE:+COMP-NULL:+CTYPE-X509:+SHA1:+SHA256:+SHA384:+SHA512:+AES-256-CBC:+AES-128-CBC:+3DES-CBC:!VERS-TLS1.0:!VERS-TLS1.1"; - break; + priority = "NONE:%VERIFY_ALLOW_X509_V1_CA_CRT:+RSA:+DHE-RSA:+DHE-DSS:+ANON-DH:+COMP-DEFLATE:+COMP-NULL:+CTYPE-X509:+SHA1:+SHA256:+SHA384:+SHA512:+AES-256-CBC:+AES-128-CBC:+3DES-CBC:!VERS-TLS1.0:!VERS-TLS1.1"; + break; case ECORE_CON_USE_TLS: case ECORE_CON_USE_TLS | ECORE_CON_LOAD_CERT: - priority = "NONE:%VERIFY_ALLOW_X509_V1_CA_CRT:+RSA:+DHE-RSA:+DHE-DSS:+ANON-DH:+COMP-DEFLATE:+COMP-NULL:+CTYPE-X509:+SHA1:+SHA256:+SHA384:+SHA512:+AES-256-CBC:+AES-128-CBC:+3DES-CBC:!VERS-SSL3.0"; - break; + priority = "NONE:%VERIFY_ALLOW_X509_V1_CA_CRT:+RSA:+DHE-RSA:+DHE-DSS:+ANON-DH:+COMP-DEFLATE:+COMP-NULL:+CTYPE-X509:+SHA1:+SHA256:+SHA384:+SHA512:+AES-256-CBC:+AES-128-CBC:+3DES-CBC:!VERS-SSL3.0"; + break; case ECORE_CON_USE_MIXED: case ECORE_CON_USE_MIXED | ECORE_CON_LOAD_CERT: - break; + break; default: - return ECORE_CON_SSL_ERROR_NONE; + return ECORE_CON_SSL_ERROR_NONE; } _client_connected++; @@ -796,7 +819,7 @@ _ecore_con_ssl_client_init_gnutls(Ecore_Con_Client *cl) INF("Applying priority string: %s", priority); SSL_ERROR_CHECK_GOTO_ERROR(ret = gnutls_priority_set_direct(cl->session, priority, NULL)); SSL_ERROR_CHECK_GOTO_ERROR(ret = gnutls_credentials_set(cl->session, GNUTLS_CRD_CERTIFICATE, cl->host_server->cert)); - // SSL_ERROR_CHECK_GOTO_ERROR(ret = gnutls_credentials_set(cl->session, GNUTLS_CRD_PSK, cl->host_server->pskcred_s)); + // SSL_ERROR_CHECK_GOTO_ERROR(ret = gnutls_credentials_set(cl->session, GNUTLS_CRD_PSK, cl->host_server->pskcred_s)); if (!cl->host_server->use_cert) SSL_ERROR_CHECK_GOTO_ERROR(ret = gnutls_credentials_set(cl->session, GNUTLS_CRD_ANON, cl->host_server->anoncred_s)); @@ -805,6 +828,7 @@ _ecore_con_ssl_client_init_gnutls(Ecore_Con_Client *cl) gnutls_dh_set_prime_bits(cl->session, 2048); gnutls_transport_set_ptr(cl->session, (gnutls_transport_ptr_t)cl->fd); cl->ssl_state = ECORE_CON_SSL_STATE_HANDSHAKING; + case ECORE_CON_SSL_STATE_HANDSHAKING: DBG("calling gnutls_handshake()"); ret = gnutls_handshake(cl->session); @@ -823,6 +847,7 @@ _ecore_con_ssl_client_init_gnutls(Ecore_Con_Client *cl) ecore_main_fd_handler_active_set(cl->fd_handler, ECORE_FD_READ); return ECORE_CON_SSL_ERROR_NONE; } + default: break; } @@ -853,7 +878,6 @@ _ecore_con_ssl_client_init_gnutls(Ecore_Con_Client *cl) goto error; } - SSL_ERROR_CHECK_GOTO_ERROR(!(cert_list = gnutls_certificate_get_peers(cl->session, &cert_list_size))); SSL_ERROR_CHECK_GOTO_ERROR(!cert_list_size); @@ -871,8 +895,8 @@ error: ERR("Also received alert: %s", gnutls_alert_get_name(gnutls_alert_get(cl->session))); if (cl->ssl_state != ECORE_CON_SSL_STATE_DONE) { - ERR("last out: %s", SSL_GNUTLS_PRINT_HANDSHAKE_STATUS(gnutls_handshake_get_last_out(cl->session))); - ERR("last in: %s", SSL_GNUTLS_PRINT_HANDSHAKE_STATUS(gnutls_handshake_get_last_in(cl->session))); + ERR("last out: %s", SSL_GNUTLS_PRINT_HANDSHAKE_STATUS(gnutls_handshake_get_last_out(cl->session))); + ERR("last in: %s", SSL_GNUTLS_PRINT_HANDSHAKE_STATUS(gnutls_handshake_get_last_in(cl->session))); } if (cert) gnutls_x509_crt_deinit(cert); @@ -896,10 +920,10 @@ _ecore_con_ssl_client_shutdown_gnutls(Ecore_Con_Client *cl) return ECORE_CON_SSL_ERROR_NONE; } - static int -_ecore_con_ssl_client_read_gnutls(Ecore_Con_Client *cl, unsigned char *buf, - int size) +_ecore_con_ssl_client_read_gnutls(Ecore_Con_Client *cl, + unsigned char *buf, + int size) { int num; @@ -912,7 +936,7 @@ _ecore_con_ssl_client_read_gnutls(Ecore_Con_Client *cl, unsigned char *buf, num = gnutls_record_recv(cl->session, buf, size); if (num > 0) - return num; + return num; if (num == GNUTLS_E_REHANDSHAKE) { @@ -922,22 +946,22 @@ _ecore_con_ssl_client_read_gnutls(Ecore_Con_Client *cl, unsigned char *buf, cl->ssl_state = ECORE_CON_SSL_STATE_HANDSHAKING; if (!_ecore_con_ssl_client_init_gnutls(cl)) return 0; - WRN("Rehandshake request ignored"); - return 0; + WRN("Rehandshake request ignored"); + return 0; } else if (!gnutls_error_is_fatal(num)) - return 0; + return 0; return -1; } static int -_ecore_con_ssl_client_write_gnutls(Ecore_Con_Client *cl, unsigned char *buf, - int size) +_ecore_con_ssl_client_write_gnutls(Ecore_Con_Client *cl, + unsigned char *buf, + int size) { int num; - if (cl->ssl_state == ECORE_CON_SSL_STATE_HANDSHAKING) { if (!_ecore_con_ssl_client_init_gnutls(cl)) @@ -947,7 +971,7 @@ _ecore_con_ssl_client_write_gnutls(Ecore_Con_Client *cl, unsigned char *buf, num = gnutls_record_send(cl->session, buf, size); if (num > 0) - return num; + return num; if (num == GNUTLS_E_REHANDSHAKE) { @@ -959,7 +983,7 @@ _ecore_con_ssl_client_write_gnutls(Ecore_Con_Client *cl, unsigned char *buf, return 0; } else if (!gnutls_error_is_fatal(num)) - return 0; + return 0; return -1; } @@ -989,7 +1013,8 @@ _ecore_con_ssl_shutdown_openssl(void) } static Ecore_Con_Ssl_Error -_ecore_con_ssl_server_prepare_openssl(Ecore_Con_Server *svr, int ssl_type) +_ecore_con_ssl_server_prepare_openssl(Ecore_Con_Server *svr, + int ssl_type) { long options; int dh = 0; @@ -1001,32 +1026,32 @@ _ecore_con_ssl_server_prepare_openssl(Ecore_Con_Server *svr, int ssl_type) { case ECORE_CON_USE_SSL3: case ECORE_CON_USE_SSL3 | ECORE_CON_LOAD_CERT: - if (!svr->created) - SSL_ERROR_CHECK_GOTO_ERROR(!(svr->ssl_ctx = SSL_CTX_new(SSLv3_client_method()))); - else - SSL_ERROR_CHECK_GOTO_ERROR(!(svr->ssl_ctx = SSL_CTX_new(SSLv3_server_method()))); - break; + if (!svr->created) + SSL_ERROR_CHECK_GOTO_ERROR(!(svr->ssl_ctx = SSL_CTX_new(SSLv3_client_method()))); + else + SSL_ERROR_CHECK_GOTO_ERROR(!(svr->ssl_ctx = SSL_CTX_new(SSLv3_server_method()))); + break; case ECORE_CON_USE_TLS: case ECORE_CON_USE_TLS | ECORE_CON_LOAD_CERT: - if (!svr->created) - SSL_ERROR_CHECK_GOTO_ERROR(!(svr->ssl_ctx = SSL_CTX_new(TLSv1_client_method()))); - else - SSL_ERROR_CHECK_GOTO_ERROR(!(svr->ssl_ctx = SSL_CTX_new(TLSv1_server_method()))); - break; + if (!svr->created) + SSL_ERROR_CHECK_GOTO_ERROR(!(svr->ssl_ctx = SSL_CTX_new(TLSv1_client_method()))); + else + SSL_ERROR_CHECK_GOTO_ERROR(!(svr->ssl_ctx = SSL_CTX_new(TLSv1_server_method()))); + break; case ECORE_CON_USE_MIXED: case ECORE_CON_USE_MIXED | ECORE_CON_LOAD_CERT: - if (!svr->created) - SSL_ERROR_CHECK_GOTO_ERROR(!(svr->ssl_ctx = SSL_CTX_new(SSLv23_client_method()))); - else - SSL_ERROR_CHECK_GOTO_ERROR(!(svr->ssl_ctx = SSL_CTX_new(SSLv23_server_method()))); - options = SSL_CTX_get_options(svr->ssl_ctx); - SSL_CTX_set_options(svr->ssl_ctx, options | SSL_OP_NO_SSLv2 | SSL_OP_SINGLE_DH_USE); - break; + if (!svr->created) + SSL_ERROR_CHECK_GOTO_ERROR(!(svr->ssl_ctx = SSL_CTX_new(SSLv23_client_method()))); + else + SSL_ERROR_CHECK_GOTO_ERROR(!(svr->ssl_ctx = SSL_CTX_new(SSLv23_server_method()))); + options = SSL_CTX_get_options(svr->ssl_ctx); + SSL_CTX_set_options(svr->ssl_ctx, options | SSL_OP_NO_SSLv2 | SSL_OP_SINGLE_DH_USE); + break; default: - return ECORE_CON_SSL_ERROR_NONE; + return ECORE_CON_SSL_ERROR_NONE; } if ((!svr->use_cert) && svr->created) @@ -1062,9 +1087,6 @@ error: return ECORE_CON_SSL_ERROR_SERVER_INIT_FAILED; } - - - static Ecore_Con_Ssl_Error _ecore_con_ssl_server_init_openssl(Ecore_Con_Server *svr) { @@ -1074,13 +1096,15 @@ _ecore_con_ssl_server_init_openssl(Ecore_Con_Server *svr) { case ECORE_CON_SSL_STATE_DONE: return ECORE_CON_SSL_ERROR_NONE; + case ECORE_CON_SSL_STATE_INIT: SSL_ERROR_CHECK_GOTO_ERROR(!(svr->ssl = SSL_new(svr->ssl_ctx))); SSL_ERROR_CHECK_GOTO_ERROR(!SSL_set_fd(svr->ssl, svr->fd)); SSL_set_connect_state(svr->ssl); svr->ssl_state = ECORE_CON_SSL_STATE_HANDSHAKING; - case ECORE_CON_SSL_STATE_HANDSHAKING: + + case ECORE_CON_SSL_STATE_HANDSHAKING: ret = SSL_do_handshake(svr->ssl); svr->ssl_err = SSL_get_error(svr->ssl, ret); SSL_ERROR_CHECK_GOTO_ERROR((svr->ssl_err == SSL_ERROR_SYSCALL) || (svr->ssl_err == SSL_ERROR_SSL)); @@ -1098,25 +1122,25 @@ _ecore_con_ssl_server_init_openssl(Ecore_Con_Server *svr) ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_WRITE); return ECORE_CON_SSL_ERROR_NONE; } + default: break; } { /* print session info into DBG */ - SSL_SESSION *s; - BIO *b; - char log[4096]; - + SSL_SESSION *s; + BIO *b; + char log[4096]; - memset(log, 0, sizeof(log)); - s = SSL_get_session(svr->ssl); - b = BIO_new(BIO_s_mem()); - SSL_SESSION_print(b, s); - while (BIO_read(b, log, sizeof(log)) > 0) - DBG("%s", log); + memset(log, 0, sizeof(log)); + s = SSL_get_session(svr->ssl); + b = BIO_new(BIO_s_mem()); + SSL_SESSION_print(b, s); + while (BIO_read(b, log, sizeof(log)) > 0) + DBG("%s", log); - BIO_free(b); + BIO_free(b); } if (!svr->verify) @@ -1138,7 +1162,8 @@ error: } static Eina_Bool -_ecore_con_ssl_server_cafile_add_openssl(Ecore_Con_Server *svr, const char *ca_file) +_ecore_con_ssl_server_cafile_add_openssl(Ecore_Con_Server *svr, + const char *ca_file) { SSL_ERROR_CHECK_GOTO_ERROR(!SSL_CTX_load_verify_locations(svr->ssl_ctx, ca_file, NULL)); return EINA_TRUE; @@ -1149,7 +1174,8 @@ error: } static Eina_Bool -_ecore_con_ssl_server_crl_add_openssl(Ecore_Con_Server *svr, const char *crl_file) +_ecore_con_ssl_server_crl_add_openssl(Ecore_Con_Server *svr, + const char *crl_file) { X509_STORE *st; X509_LOOKUP *lu; @@ -1172,13 +1198,14 @@ error: } static Eina_Bool -_ecore_con_ssl_server_privkey_add_openssl(Ecore_Con_Server *svr, const char *key_file) +_ecore_con_ssl_server_privkey_add_openssl(Ecore_Con_Server *svr, + const char *key_file) { FILE *fp = NULL; EVP_PKEY *privkey = NULL; if (!(fp = fopen(key_file, "r"))) - goto error; + goto error; SSL_ERROR_CHECK_GOTO_ERROR(!(privkey = PEM_read_PrivateKey(fp, NULL, NULL, NULL))); @@ -1190,20 +1217,20 @@ _ecore_con_ssl_server_privkey_add_openssl(Ecore_Con_Server *svr, const char *key error: if (fp) - fclose(fp); + fclose(fp); _openssl_print_errors(); return EINA_FALSE; } - static Eina_Bool -_ecore_con_ssl_server_cert_add_openssl(Ecore_Con_Server *svr, const char *cert_file) +_ecore_con_ssl_server_cert_add_openssl(Ecore_Con_Server *svr, + const char *cert_file) { FILE *fp = NULL; X509 *cert = NULL; if (!(fp = fopen(cert_file, "r"))) - goto error; + goto error; SSL_ERROR_CHECK_GOTO_ERROR(!(cert = PEM_read_X509(fp, NULL, NULL, NULL))); @@ -1215,7 +1242,7 @@ _ecore_con_ssl_server_cert_add_openssl(Ecore_Con_Server *svr, const char *cert_f error: if (fp) - fclose(fp); + fclose(fp); _openssl_print_errors(); return EINA_FALSE; } @@ -1226,13 +1253,13 @@ _ecore_con_ssl_server_shutdown_openssl(Ecore_Con_Server *svr) if (svr->ssl) { if (!SSL_shutdown(svr->ssl)) - SSL_shutdown(svr->ssl); + SSL_shutdown(svr->ssl); SSL_free(svr->ssl); } if (svr->ssl_ctx) - SSL_CTX_free(svr->ssl_ctx); + SSL_CTX_free(svr->ssl_ctx); svr->ssl = NULL; svr->ssl_ctx = NULL; @@ -1242,8 +1269,9 @@ _ecore_con_ssl_server_shutdown_openssl(Ecore_Con_Server *svr) } static int -_ecore_con_ssl_server_read_openssl(Ecore_Con_Server *svr, unsigned char *buf, - int size) +_ecore_con_ssl_server_read_openssl(Ecore_Con_Server *svr, + unsigned char *buf, + int size) { int num; @@ -1253,25 +1281,26 @@ _ecore_con_ssl_server_read_openssl(Ecore_Con_Server *svr, unsigned char *buf, if (svr->fd_handler) { if (svr->ssl && svr->ssl_err == SSL_ERROR_WANT_READ) - ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ); + ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ); else if (svr->ssl && svr->ssl_err == SSL_ERROR_WANT_WRITE) - ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_WRITE); + ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_WRITE); } if ((svr->ssl_err == SSL_ERROR_ZERO_RETURN) || (svr->ssl_err == SSL_ERROR_SYSCALL) || (svr->ssl_err == SSL_ERROR_SSL)) - return -1; + return -1; if (num < 0) - return 0; + return 0; return num; } static int -_ecore_con_ssl_server_write_openssl(Ecore_Con_Server *svr, unsigned char *buf, - int size) +_ecore_con_ssl_server_write_openssl(Ecore_Con_Server *svr, + unsigned char *buf, + int size) { int num; @@ -1281,18 +1310,18 @@ _ecore_con_ssl_server_write_openssl(Ecore_Con_Server *svr, unsigned char *buf, if (svr->fd_handler) { if (svr->ssl && svr->ssl_err == SSL_ERROR_WANT_READ) - ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ); + ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ); else if (svr->ssl && svr->ssl_err == SSL_ERROR_WANT_WRITE) - ecore_main_fd_handler_active_set( svr->fd_handler, ECORE_FD_WRITE); + ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_WRITE); } if ((svr->ssl_err == SSL_ERROR_ZERO_RETURN) || (svr->ssl_err == SSL_ERROR_SYSCALL) || (svr->ssl_err == SSL_ERROR_SSL)) - return -1; + return -1; if (num < 0) - return 0; + return 0; return num; } @@ -1305,12 +1334,14 @@ _ecore_con_ssl_client_init_openssl(Ecore_Con_Client *cl) { case ECORE_CON_SSL_STATE_DONE: return ECORE_CON_SSL_ERROR_NONE; + case ECORE_CON_SSL_STATE_INIT: SSL_ERROR_CHECK_GOTO_ERROR(!(cl->ssl = SSL_new(cl->host_server->ssl_ctx))); SSL_ERROR_CHECK_GOTO_ERROR(!SSL_set_fd(cl->ssl, cl->fd)); SSL_set_accept_state(cl->ssl); cl->ssl_state = ECORE_CON_SSL_STATE_HANDSHAKING; + case ECORE_CON_SSL_STATE_HANDSHAKING: ret = SSL_do_handshake(cl->ssl); cl->ssl_err = SSL_get_error(cl->ssl, ret); @@ -1323,33 +1354,32 @@ _ecore_con_ssl_client_init_openssl(Ecore_Con_Client *cl) else { if (cl->ssl_err == SSL_ERROR_WANT_READ) - ecore_main_fd_handler_active_set(cl->fd_handler, ECORE_FD_READ); + ecore_main_fd_handler_active_set(cl->fd_handler, ECORE_FD_READ); else if (cl->ssl_err == SSL_ERROR_WANT_WRITE) - ecore_main_fd_handler_active_set(cl->fd_handler, ECORE_FD_WRITE); + ecore_main_fd_handler_active_set(cl->fd_handler, ECORE_FD_WRITE); return ECORE_CON_SSL_ERROR_NONE; } + default: break; } { /* print session info into DBG */ - SSL_SESSION *s; - BIO *b; - char log[4096]; - + SSL_SESSION *s; + BIO *b; + char log[4096]; - memset(log, 0, sizeof(log)); - s = SSL_get_session(cl->ssl); - b = BIO_new(BIO_s_mem()); - SSL_SESSION_print(b, s); - while (BIO_read(b, log, sizeof(log)) > 0) - DBG("%s", log); + memset(log, 0, sizeof(log)); + s = SSL_get_session(cl->ssl); + b = BIO_new(BIO_s_mem()); + SSL_SESSION_print(b, s); + while (BIO_read(b, log, sizeof(log)) > 0) + DBG("%s", log); - BIO_free(b); + BIO_free(b); } - if (!cl->host_server->verify) /* not verifying certificates, so we're done! */ return ECORE_CON_SSL_ERROR_NONE; @@ -1366,14 +1396,13 @@ error: return ECORE_CON_SSL_ERROR_SERVER_INIT_FAILED; } - static Ecore_Con_Ssl_Error _ecore_con_ssl_client_shutdown_openssl(Ecore_Con_Client *cl) { if (cl->ssl) { if (!SSL_shutdown(cl->ssl)) - SSL_shutdown(cl->ssl); + SSL_shutdown(cl->ssl); SSL_free(cl->ssl); } @@ -1385,8 +1414,9 @@ _ecore_con_ssl_client_shutdown_openssl(Ecore_Con_Client *cl) } static int -_ecore_con_ssl_client_read_openssl(Ecore_Con_Client *cl, unsigned char *buf, - int size) +_ecore_con_ssl_client_read_openssl(Ecore_Con_Client *cl, + unsigned char *buf, + int size) { int num; @@ -1396,25 +1426,26 @@ _ecore_con_ssl_client_read_openssl(Ecore_Con_Client *cl, unsigned char *buf, if (cl->fd_handler) { if (cl->ssl && cl->ssl_err == SSL_ERROR_WANT_READ) - ecore_main_fd_handler_active_set(cl->fd_handler, ECORE_FD_READ); + ecore_main_fd_handler_active_set(cl->fd_handler, ECORE_FD_READ); else if (cl->ssl && cl->ssl_err == SSL_ERROR_WANT_WRITE) - ecore_main_fd_handler_active_set( cl->fd_handler, ECORE_FD_WRITE); + ecore_main_fd_handler_active_set(cl->fd_handler, ECORE_FD_WRITE); } if ((cl->ssl_err == SSL_ERROR_ZERO_RETURN) || (cl->ssl_err == SSL_ERROR_SYSCALL) || (cl->ssl_err == SSL_ERROR_SSL)) - return -1; + return -1; if (num < 0) - return 0; + return 0; return num; } static int -_ecore_con_ssl_client_write_openssl(Ecore_Con_Client *cl, unsigned char *buf, - int size) +_ecore_con_ssl_client_write_openssl(Ecore_Con_Client *cl, + unsigned char *buf, + int size) { int num; @@ -1424,18 +1455,18 @@ _ecore_con_ssl_client_write_openssl(Ecore_Con_Client *cl, unsigned char *buf, if (cl->fd_handler) { if (cl->ssl && cl->ssl_err == SSL_ERROR_WANT_READ) - ecore_main_fd_handler_active_set(cl->fd_handler, ECORE_FD_READ); + ecore_main_fd_handler_active_set(cl->fd_handler, ECORE_FD_READ); else if (cl->ssl && cl->ssl_err == SSL_ERROR_WANT_WRITE) - ecore_main_fd_handler_active_set( cl->fd_handler, ECORE_FD_WRITE); + ecore_main_fd_handler_active_set(cl->fd_handler, ECORE_FD_WRITE); } if ((cl->ssl_err == SSL_ERROR_ZERO_RETURN) || (cl->ssl_err == SSL_ERROR_SYSCALL) || (cl->ssl_err == SSL_ERROR_SSL)) - return -1; + return -1; if (num < 0) - return 0; + return 0; return num; } @@ -1459,7 +1490,8 @@ _ecore_con_ssl_shutdown_none(void) } static Ecore_Con_Ssl_Error -_ecore_con_ssl_server_prepare_none(Ecore_Con_Server *svr __UNUSED__, int ssl_type __UNUSED__) +_ecore_con_ssl_server_prepare_none(Ecore_Con_Server *svr __UNUSED__, + int ssl_type __UNUSED__) { return ECORE_CON_SSL_ERROR_NONE; } @@ -1471,25 +1503,29 @@ _ecore_con_ssl_server_init_none(Ecore_Con_Server *svr __UNUSED__) } static Eina_Bool -_ecore_con_ssl_server_cafile_add_none(Ecore_Con_Server *svr __UNUSED__, const char *ca_file __UNUSED__) +_ecore_con_ssl_server_cafile_add_none(Ecore_Con_Server *svr __UNUSED__, + const char *ca_file __UNUSED__) { return EINA_FALSE; } static Eina_Bool -_ecore_con_ssl_server_cert_add_none(Ecore_Con_Server *svr __UNUSED__, const char *cert_file __UNUSED__) +_ecore_con_ssl_server_cert_add_none(Ecore_Con_Server *svr __UNUSED__, + const char *cert_file __UNUSED__) { return EINA_FALSE; } static Eina_Bool -_ecore_con_ssl_server_privkey_add_none(Ecore_Con_Server *svr __UNUSED__, const char *key_file __UNUSED__) +_ecore_con_ssl_server_privkey_add_none(Ecore_Con_Server *svr __UNUSED__, + const char *key_file __UNUSED__) { return EINA_FALSE; } static Eina_Bool -_ecore_con_ssl_server_crl_add_none(Ecore_Con_Server *svr __UNUSED__, const char *crl_file __UNUSED__) +_ecore_con_ssl_server_crl_add_none(Ecore_Con_Server *svr __UNUSED__, + const char *crl_file __UNUSED__) { return EINA_FALSE; } @@ -1501,15 +1537,17 @@ _ecore_con_ssl_server_shutdown_none(Ecore_Con_Server *svr __UNUSED__) } static int -_ecore_con_ssl_server_read_none(Ecore_Con_Server *svr __UNUSED__, unsigned char *buf __UNUSED__, - int size __UNUSED__) +_ecore_con_ssl_server_read_none(Ecore_Con_Server *svr __UNUSED__, + unsigned char *buf __UNUSED__, + int size __UNUSED__) { return -1; } static int -_ecore_con_ssl_server_write_none(Ecore_Con_Server *svr __UNUSED__, unsigned char *buf __UNUSED__, - int size __UNUSED__) +_ecore_con_ssl_server_write_none(Ecore_Con_Server *svr __UNUSED__, + unsigned char *buf __UNUSED__, + int size __UNUSED__) { return -1; } @@ -1527,15 +1565,17 @@ _ecore_con_ssl_client_shutdown_none(Ecore_Con_Client *cl __UNUSED__) } static int -_ecore_con_ssl_client_read_none(Ecore_Con_Client *cl __UNUSED__, unsigned char *buf __UNUSED__, - int size __UNUSED__) +_ecore_con_ssl_client_read_none(Ecore_Con_Client *cl __UNUSED__, + unsigned char *buf __UNUSED__, + int size __UNUSED__) { return -1; } static int -_ecore_con_ssl_client_write_none(Ecore_Con_Client *cl __UNUSED__, unsigned char *buf __UNUSED__, - int size __UNUSED__) +_ecore_con_ssl_client_write_none(Ecore_Con_Client *cl __UNUSED__, + unsigned char *buf __UNUSED__, + int size __UNUSED__) { return -1; } diff --git a/legacy/ecore/src/lib/ecore_con/ecore_con_url.c b/legacy/ecore/src/lib/ecore_con/ecore_con_url.c index d915966ca8..ee19c0a24f 100644 --- a/legacy/ecore/src/lib/ecore_con/ecore_con_url.c +++ b/legacy/ecore/src/lib/ecore_con/ecore_con_url.c @@ -64,23 +64,30 @@ int ECORE_CON_EVENT_URL_COMPLETE = 0; int ECORE_CON_EVENT_URL_PROGRESS = 0; #ifdef HAVE_CURL -static Eina_Bool _ecore_con_url_fd_handler(void *data, +static Eina_Bool _ecore_con_url_fd_handler(void *data, Ecore_Fd_Handler *fd_handler); static Eina_Bool _ecore_con_url_perform(Ecore_Con_Url *url_con); -static size_t _ecore_con_url_header_cb(void *ptr, size_t size, size_t nitems, - void *stream); -static size_t _ecore_con_url_data_cb(void *buffer, - size_t size, - size_t nitems, - void *userp); -static int _ecore_con_url_progress_cb(void *clientp, double dltotal, - double dlnow, double ultotal, - double ulnow); -static size_t _ecore_con_url_read_cb(void *ptr, size_t size, size_t nitems, - void *stream); -static void _ecore_con_event_url_free(void *data __UNUSED__, void *ev); +static size_t _ecore_con_url_header_cb(void *ptr, + size_t size, + size_t nitems, + void *stream); +static size_t _ecore_con_url_data_cb(void *buffer, + size_t size, + size_t nitems, + void *userp); +static int _ecore_con_url_progress_cb(void *clientp, + double dltotal, + double dlnow, + double ultotal, + double ulnow); +static size_t _ecore_con_url_read_cb(void *ptr, + size_t size, + size_t nitems, + void *stream); +static void _ecore_con_event_url_free(void *data __UNUSED__, + void *ev); static int _ecore_con_url_process_completed_jobs( - Ecore_Con_Url *url_con_to_match); + Ecore_Con_Url *url_con_to_match); static Eina_Bool _ecore_con_url_idler_handler(void *data); static Ecore_Idler *_fd_idler_handler = NULL; @@ -93,7 +100,7 @@ static Ecore_Timer *_curl_timeout = NULL; typedef struct _Ecore_Con_Url_Event Ecore_Con_Url_Event; struct _Ecore_Con_Url_Event { - int type; + int type; void *ev; }; @@ -110,7 +117,8 @@ _url_complete_idler_cb(void *data) } static void -_url_complete_push_event(int type, void *ev) +_url_complete_push_event(int type, + void *ev) { Ecore_Con_Url_Event *lev; @@ -146,7 +154,7 @@ ecore_con_url_init(void) _init_count++; if (_init_count > 1) - return _init_count; + return _init_count; if (!ECORE_CON_EVENT_URL_DATA) { @@ -163,7 +171,7 @@ ecore_con_url_init(void) if (curl_global_init(CURL_GLOBAL_NOTHING)) { while (_url_con_list) - ecore_con_url_free(eina_list_data_get(_url_con_list)); + ecore_con_url_free(eina_list_data_get(_url_con_list)); return 0; } @@ -171,7 +179,7 @@ ecore_con_url_init(void) if (!_curlm) { while (_url_con_list) - ecore_con_url_free(eina_list_data_get(_url_con_list)); + ecore_con_url_free(eina_list_data_get(_url_con_list)); _init_count--; return 0; @@ -179,11 +187,11 @@ ecore_con_url_init(void) curl_multi_timeout(_curlm, &ms); if (ms <= 0) - ms = 1000; + ms = 1000; _curl_timeout = - ecore_timer_add((double)ms / 1000, _ecore_con_url_idler_handler, - (void *)0xACE); + ecore_timer_add((double)ms / 1000, _ecore_con_url_idler_handler, + (void *)0xACE); ecore_timer_freeze(_curl_timeout); } @@ -202,25 +210,25 @@ ecore_con_url_shutdown(void) { #ifdef HAVE_CURL if (!_init_count) - return 0; + return 0; _init_count--; if (_init_count != 0) - return _init_count; + return _init_count; if (_fd_idler_handler) - ecore_idler_del(_fd_idler_handler); + ecore_idler_del(_fd_idler_handler); _fd_idler_handler = NULL; if (_curl_timeout) - ecore_timer_del(_curl_timeout); + ecore_timer_del(_curl_timeout); _curl_timeout = NULL; while (_url_con_list) - ecore_con_url_free(eina_list_data_get(_url_con_list)); + ecore_con_url_free(eina_list_data_get(_url_con_list)); if (_curlm) { @@ -256,11 +264,11 @@ ecore_con_url_new(const char *url) CURLcode ret; if (!_init_count) - return NULL; + return NULL; url_con = calloc(1, sizeof(Ecore_Con_Url)); if (!url_con) - return NULL; + return NULL; url_con->fd = -1; url_con->write_fd = -1; @@ -296,18 +304,18 @@ ecore_con_url_new(const char *url) curl_easy_setopt(url_con->curl_easy, CURLOPT_PROGRESSFUNCTION, _ecore_con_url_progress_cb); curl_easy_setopt(url_con->curl_easy, CURLOPT_PROGRESSDATA, url_con); - curl_easy_setopt(url_con->curl_easy, CURLOPT_NOPROGRESS, EINA_FALSE); + curl_easy_setopt(url_con->curl_easy, CURLOPT_NOPROGRESS, EINA_FALSE); curl_easy_setopt(url_con->curl_easy, CURLOPT_HEADERFUNCTION, _ecore_con_url_header_cb); - curl_easy_setopt(url_con->curl_easy, CURLOPT_HEADERDATA, url_con); + curl_easy_setopt(url_con->curl_easy, CURLOPT_HEADERDATA, url_con); /* * FIXME: Check that these timeouts are sensible defaults * FIXME: Provide a means to change these timeouts */ curl_easy_setopt(url_con->curl_easy, CURLOPT_CONNECTTIMEOUT, 30); - curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMEOUT, 300); + curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMEOUT, 300); curl_easy_setopt(url_con->curl_easy, CURLOPT_FOLLOWLOCATION, 1); return url_con; @@ -334,22 +342,23 @@ ecore_con_url_new(const char *url) * @see ecore_con_url_url_set() */ EAPI Ecore_Con_Url * -ecore_con_url_custom_new(const char *url, const char *custom_request) +ecore_con_url_custom_new(const char *url, + const char *custom_request) { #ifdef HAVE_CURL Ecore_Con_Url *url_con; CURLcode ret; if (!url) - return NULL; + return NULL; if (!custom_request) - return NULL; + return NULL; url_con = ecore_con_url_new(url); if (!url_con) - return NULL; + return NULL; ret = curl_easy_setopt(url_con->curl_easy, CURLOPT_CUSTOMREQUEST, custom_request); if (ret != CURLE_OK) @@ -383,7 +392,7 @@ ecore_con_url_free(Ecore_Con_Url *url_con) CURLMcode ret; if (!url_con) - return; + return; if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL)) { @@ -396,7 +405,7 @@ ecore_con_url_free(Ecore_Con_Url *url_con) { FD_CLR(url_con->fd, &_current_fd_set); if (url_con->fd_handler) - ecore_main_fd_handler_del(url_con->fd_handler); + ecore_main_fd_handler_del(url_con->fd_handler); url_con->fd = -1; url_con->fd_handler = NULL; @@ -406,19 +415,19 @@ ecore_con_url_free(Ecore_Con_Url *url_con) { // FIXME: For an unknown reason, progress continue to arrive after destruction // this prevent any further call to the callback. - curl_easy_setopt(url_con->curl_easy, CURLOPT_PROGRESSFUNCTION, NULL); + curl_easy_setopt(url_con->curl_easy, CURLOPT_PROGRESSFUNCTION, NULL); - if (url_con->active) - { - url_con->active = EINA_FALSE; + if (url_con->active) + { + url_con->active = EINA_FALSE; - ret = curl_multi_remove_handle(_curlm, url_con->curl_easy); - if (ret != CURLM_OK) - ERR("curl_multi_remove_handle failed: %s", - curl_multi_strerror(ret)); - } + ret = curl_multi_remove_handle(_curlm, url_con->curl_easy); + if (ret != CURLM_OK) + ERR("curl_multi_remove_handle failed: %s", + curl_multi_strerror(ret)); + } - curl_easy_cleanup(url_con->curl_easy); + curl_easy_cleanup(url_con->curl_easy); } _url_con_list = eina_list_remove(_url_con_list, url_con); @@ -445,7 +454,8 @@ ecore_con_url_free(Ecore_Con_Url *url_con) * */ EAPI Eina_Bool -ecore_con_url_url_set(Ecore_Con_Url *url_con, const char *url) +ecore_con_url_url_set(Ecore_Con_Url *url_con, + const char *url) { #ifdef HAVE_CURL if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL)) @@ -455,20 +465,20 @@ ecore_con_url_url_set(Ecore_Con_Url *url_con, const char *url) } if (url_con->active) - return EINA_FALSE; + return EINA_FALSE; if (url_con->url) - free(url_con->url); + free(url_con->url); url_con->url = NULL; if (url) - url_con->url = strdup(url); + url_con->url = strdup(url); if (url_con->url) - curl_easy_setopt(url_con->curl_easy, CURLOPT_URL, - url_con->url); + curl_easy_setopt(url_con->curl_easy, CURLOPT_URL, + url_con->url); else - curl_easy_setopt(url_con->curl_easy, CURLOPT_URL, ""); + curl_easy_setopt(url_con->curl_easy, CURLOPT_URL, ""); return EINA_TRUE; #else @@ -491,7 +501,8 @@ ecore_con_url_url_set(Ecore_Con_Url *url_con, const char *url) * @see ecore_con_url_data_get() */ EAPI void -ecore_con_url_data_set(Ecore_Con_Url *url_con, void *data) +ecore_con_url_data_set(Ecore_Con_Url *url_con, + void *data) { #ifdef HAVE_CURL if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL)) @@ -523,8 +534,9 @@ ecore_con_url_data_set(Ecore_Con_Url *url_con, void *data) * @see ecore_con_url_additional_headers_clear() */ EAPI void -ecore_con_url_additional_header_add(Ecore_Con_Url *url_con, const char *key, - const char *value) +ecore_con_url_additional_header_add(Ecore_Con_Url *url_con, + const char *key, + const char *value) { #ifdef HAVE_CURL char *tmp; @@ -538,7 +550,7 @@ ecore_con_url_additional_header_add(Ecore_Con_Url *url_con, const char *key, tmp = malloc(strlen(key) + strlen(value) + 3); if (!tmp) - return; + return; sprintf(tmp, "%s: %s", key, value); url_con->additional_headers = eina_list_append(url_con->additional_headers, @@ -625,8 +637,9 @@ ecore_con_url_data_get(Ecore_Con_Url *url_con) * @sa ecore_con_url_send() */ EAPI void -ecore_con_url_time(Ecore_Con_Url *url_con, Ecore_Con_Url_Time condition, - double timestamp) +ecore_con_url_time(Ecore_Con_Url *url_con, + Ecore_Con_Url_Time condition, + double timestamp) { #ifdef HAVE_CURL if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL)) @@ -657,7 +670,8 @@ ecore_con_url_time(Ecore_Con_Url *url_con, Ecore_Con_Url_Time condition, * */ EAPI void -ecore_con_url_fd_set(Ecore_Con_Url *url_con, int fd) +ecore_con_url_fd_set(Ecore_Con_Url *url_con, + int fd) { #ifdef HAVE_CURL if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL)) @@ -735,8 +749,10 @@ ecore_con_url_response_headers_get(Ecore_Con_Url *url_con) * */ EAPI Eina_Bool -ecore_con_url_httpauth_set(Ecore_Con_Url *url_con, const char *username, - const char *password, Eina_Bool safe) +ecore_con_url_httpauth_set(Ecore_Con_Url *url_con, + const char *username, + const char *password, + Eina_Bool safe) { #ifdef HAVE_CURL CURLcode ret; @@ -752,10 +768,10 @@ ecore_con_url_httpauth_set(Ecore_Con_Url *url_con, const char *username, if ((username) && (password)) { if (safe) - curl_easy_setopt(url_con->curl_easy, CURLOPT_HTTPAUTH, - CURLAUTH_ANYSAFE); + curl_easy_setopt(url_con->curl_easy, CURLOPT_HTTPAUTH, + CURLAUTH_ANYSAFE); else - curl_easy_setopt(url_con->curl_easy, CURLOPT_HTTPAUTH, CURLAUTH_ANY); + curl_easy_setopt(url_con->curl_easy, CURLOPT_HTTPAUTH, CURLAUTH_ANY); ret = curl_easy_setopt(url_con->curl_easy, CURLOPT_USERNAME, username); if (ret != CURLE_OK) @@ -802,8 +818,10 @@ ecore_con_url_httpauth_set(Ecore_Con_Url *url_con, const char *username, * @see ecore_con_url_time() */ EAPI Eina_Bool -ecore_con_url_send(Ecore_Con_Url *url_con, const void *data, long length, - const char *content_type) +ecore_con_url_send(Ecore_Con_Url *url_con, + const void *data, + long length, + const char *content_type) { #ifdef HAVE_CURL Eina_List *l; @@ -817,10 +835,10 @@ ecore_con_url_send(Ecore_Con_Url *url_con, const void *data, long length, } if (url_con->active) - return EINA_FALSE; + return EINA_FALSE; if (!url_con->url) - return EINA_FALSE; + return EINA_FALSE; /* Free response headers from previous send() calls */ EINA_LIST_FREE(url_con->response_headers, s) @@ -838,30 +856,30 @@ ecore_con_url_send(Ecore_Con_Url *url_con, const void *data, long length, url_con->headers = curl_slist_append(url_con->headers, tmp); } - curl_easy_setopt(url_con->curl_easy, CURLOPT_POSTFIELDS, data); + curl_easy_setopt(url_con->curl_easy, CURLOPT_POSTFIELDS, data); curl_easy_setopt(url_con->curl_easy, CURLOPT_POSTFIELDSIZE, length); } switch (url_con->time_condition) { case ECORE_CON_URL_TIME_NONE: - curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMECONDITION, - CURL_TIMECOND_NONE); - break; + curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMECONDITION, + CURL_TIMECOND_NONE); + break; case ECORE_CON_URL_TIME_IFMODSINCE: - curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMECONDITION, - CURL_TIMECOND_IFMODSINCE); - curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMEVALUE, - (long)url_con->timestamp); - break; + curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMECONDITION, + CURL_TIMECOND_IFMODSINCE); + curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMEVALUE, + (long)url_con->timestamp); + break; case ECORE_CON_URL_TIME_IFUNMODSINCE: - curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMECONDITION, - CURL_TIMECOND_IFUNMODSINCE); - curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMEVALUE, - (long)url_con->timestamp); - break; + curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMECONDITION, + CURL_TIMECOND_IFUNMODSINCE); + curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMEVALUE, + (long)url_con->timestamp); + break; } /* Additional headers */ @@ -894,9 +912,11 @@ ecore_con_url_send(Ecore_Con_Url *url_con, const void *data, long length, * and @p pass to directory @p upload_dir */ EAPI Eina_Bool -ecore_con_url_ftp_upload(Ecore_Con_Url *url_con, const char *filename, - const char *user, const char *pass, - const char *upload_dir) +ecore_con_url_ftp_upload(Ecore_Con_Url *url_con, + const char *filename, + const char *user, + const char *pass, + const char *upload_dir) { #ifdef HAVE_CURL char url[4096]; @@ -914,15 +934,15 @@ ecore_con_url_ftp_upload(Ecore_Con_Url *url_con, const char *filename, } if (url_con->active) - return EINA_FALSE; + return EINA_FALSE; if (!url_con->url) - return EINA_FALSE; + return EINA_FALSE; if (filename) { if (stat(filename, &file_info)) - return EINA_FALSE; + return EINA_FALSE; snprintf(userpwd, sizeof(userpwd), "%s:%s", user, pass); ret = curl_easy_setopt(url_con->curl_easy, CURLOPT_USERPWD, userpwd); @@ -940,7 +960,7 @@ ecore_con_url_ftp_upload(Ecore_Con_Url *url_con, const char *filename, snprintf(url, sizeof(url), "ftp://%s/%s/%s", url_con->url, upload_dir, basename(tmp)); else - snprintf(url, sizeof(url), "ftp://%s/%s", url_con->url, + snprintf(url, sizeof(url), "ftp://%s/%s", url_con->url, basename(tmp)); if (!ecore_con_url_url_set(url_con, url)) @@ -948,7 +968,7 @@ ecore_con_url_ftp_upload(Ecore_Con_Url *url_con, const char *filename, curl_easy_setopt(url_con->curl_easy, CURLOPT_INFILESIZE_LARGE, (curl_off_t)file_info.st_size); - curl_easy_setopt(url_con->curl_easy, CURLOPT_UPLOAD, 1); + curl_easy_setopt(url_con->curl_easy, CURLOPT_UPLOAD, 1); curl_easy_setopt(url_con->curl_easy, CURLOPT_READFUNCTION, _ecore_con_url_read_cb); @@ -985,7 +1005,8 @@ ecore_con_url_ftp_upload(Ecore_Con_Url *url_con, const char *filename, * @param verbose Whether or not to enable libcurl's verbose output. */ EAPI void -ecore_con_url_verbose_set(Ecore_Con_Url *url_con, Eina_Bool verbose) +ecore_con_url_verbose_set(Ecore_Con_Url *url_con, + Eina_Bool verbose) { #ifdef HAVE_CURL if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL)) @@ -996,10 +1017,10 @@ ecore_con_url_verbose_set(Ecore_Con_Url *url_con, Eina_Bool verbose) } if (url_con->active) - return; + return; if (!url_con->url) - return; + return; curl_easy_setopt(url_con->curl_easy, CURLOPT_VERBOSE, (int)verbose); #else @@ -1013,7 +1034,8 @@ ecore_con_url_verbose_set(Ecore_Con_Url *url_con, Eina_Bool verbose) * @return FIXME: To be more documented. */ EAPI void -ecore_con_url_ftp_use_epsv_set(Ecore_Con_Url *url_con, Eina_Bool use_epsv) +ecore_con_url_ftp_use_epsv_set(Ecore_Con_Url *url_con, + Eina_Bool use_epsv) { #ifdef HAVE_CURL if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL)) @@ -1024,10 +1046,10 @@ ecore_con_url_ftp_use_epsv_set(Ecore_Con_Url *url_con, Eina_Bool use_epsv) } if (url_con->active) - return; + return; if (!url_con->url) - return; + return; curl_easy_setopt(url_con->curl_easy, CURLOPT_FTP_USE_EPSV, (int)use_epsv); #endif @@ -1048,17 +1070,17 @@ _ecore_con_url_suspend_fd_handler(void) int deleted = 0; if (!_url_con_list) - return 0; + return 0; EINA_LIST_FOREACH(_url_con_list, l, url_con) - { - if (url_con->active && url_con->fd_handler) - { - ecore_main_fd_handler_del(url_con->fd_handler); - url_con->fd_handler = NULL; - deleted++; - } - } + { + if (url_con->active && url_con->fd_handler) + { + ecore_main_fd_handler_del(url_con->fd_handler); + url_con->fd_handler = NULL; + deleted++; + } + } return deleted; } @@ -1071,25 +1093,28 @@ _ecore_con_url_restart_fd_handler(void) int activated = 0; if (!_url_con_list) - return 0; + return 0; EINA_LIST_FOREACH(_url_con_list, l, url_con) - { - if (!url_con->fd_handler && url_con->fd != -1) - { - url_con->fd_handler = - ecore_main_fd_handler_add(url_con->fd, url_con->flags, - _ecore_con_url_fd_handler, - NULL, NULL, NULL); - activated++; - } - } + { + if (!url_con->fd_handler && url_con->fd != -1) + { + url_con->fd_handler = + ecore_main_fd_handler_add(url_con->fd, url_con->flags, + _ecore_con_url_fd_handler, + NULL, NULL, NULL); + activated++; + } + } return activated; } static size_t -_ecore_con_url_data_cb(void *buffer, size_t size, size_t nitems, void *userp) +_ecore_con_url_data_cb(void *buffer, + size_t size, + size_t nitems, + void *userp) { Ecore_Con_Url *url_con; Ecore_Con_Event_Url_Data *e; @@ -1098,7 +1123,7 @@ _ecore_con_url_data_cb(void *buffer, size_t size, size_t nitems, void *userp) url_con = (Ecore_Con_Url *)userp; if (!url_con) - return -1; + return -1; if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL)) { @@ -1111,14 +1136,14 @@ _ecore_con_url_data_cb(void *buffer, size_t size, size_t nitems, void *userp) if (url_con->write_fd < 0) { e = - malloc(sizeof(Ecore_Con_Event_Url_Data) + sizeof(unsigned char) * - (real_size - 1)); + malloc(sizeof(Ecore_Con_Event_Url_Data) + sizeof(unsigned char) * + (real_size - 1)); if (e) { e->url_con = url_con; e->size = real_size; memcpy(e->data, buffer, real_size); - ecore_event_add(ECORE_CON_EVENT_URL_DATA, e, + ecore_event_add(ECORE_CON_EVENT_URL_DATA, e, _ecore_con_event_url_free, NULL); } } @@ -1136,7 +1161,7 @@ _ecore_con_url_data_cb(void *buffer, size_t size, size_t nitems, void *userp) if (count < 0) { if (errno != EAGAIN && errno != EINTR) - return -1; + return -1; } else { @@ -1149,31 +1174,34 @@ _ecore_con_url_data_cb(void *buffer, size_t size, size_t nitems, void *userp) return real_size; } -#define ECORE_CON_URL_TRANSMISSION(Transmit, Event, Url_con, Total, Now) \ - { \ - Ecore_Con_Event_Url_Progress *e; \ - if ((Total != 0) || (Now != 0)) \ - { \ - e = calloc(1, sizeof(Ecore_Con_Event_Url_Progress)); \ - if (e) \ - { \ - e->url_con = url_con; \ - e->total = Total; \ - e->now = Now; \ - ecore_event_add(Event, e, _ecore_con_event_url_free, NULL); \ - } \ - } \ - } +#define ECORE_CON_URL_TRANSMISSION(Transmit, Event, Url_con, Total, Now) \ + { \ + Ecore_Con_Event_Url_Progress *e; \ + if ((Total != 0) || (Now != 0)) \ + { \ + e = calloc(1, sizeof(Ecore_Con_Event_Url_Progress)); \ + if (e) \ + { \ + e->url_con = url_con; \ + e->total = Total; \ + e->now = Now; \ + ecore_event_add(Event, e, _ecore_con_event_url_free, NULL); \ + } \ + } \ + } static size_t -_ecore_con_url_header_cb(void *ptr, size_t size, size_t nitems, void *stream) +_ecore_con_url_header_cb(void *ptr, + size_t size, + size_t nitems, + void *stream) { size_t real_size = size * nitems; Ecore_Con_Url *url_con = stream; char *header = malloc(sizeof(char) * (real_size + 1)); if (!header) - return real_size; + return real_size; memcpy(header, ptr, real_size); header[real_size] = '\0'; @@ -1185,7 +1213,9 @@ _ecore_con_url_header_cb(void *ptr, size_t size, size_t nitems, void *stream) } static int -_ecore_con_url_progress_cb(void *clientp, double dltotal, double dlnow, +_ecore_con_url_progress_cb(void *clientp, + double dltotal, + double dlnow, double ultotal, double ulnow) { @@ -1210,7 +1240,10 @@ _ecore_con_url_progress_cb(void *clientp, double dltotal, double dlnow, } static size_t -_ecore_con_url_read_cb(void *ptr, size_t size, size_t nitems, void *stream) +_ecore_con_url_read_cb(void *ptr, + size_t size, + size_t nitems, + void *stream) { size_t retcode = fread(ptr, size, nitems, stream); @@ -1250,7 +1283,7 @@ _ecore_con_url_perform(Ecore_Con_Url *url_con) if (!completed_immediately) { if (url_con->fd_handler) - ecore_main_fd_handler_del(url_con->fd_handler); + ecore_main_fd_handler_del(url_con->fd_handler); url_con->fd_handler = NULL; @@ -1274,13 +1307,13 @@ _ecore_con_url_perform(Ecore_Con_Url *url_con) { flags = 0; if (FD_ISSET(fd, &read_set)) - flags |= ECORE_FD_READ; + flags |= ECORE_FD_READ; if (FD_ISSET(fd, &write_set)) - flags |= ECORE_FD_WRITE; + flags |= ECORE_FD_WRITE; if (FD_ISSET(fd, &exc_set)) - flags |= ECORE_FD_ERROR; + flags |= ECORE_FD_ERROR; if (flags) { @@ -1292,15 +1325,15 @@ _ecore_con_url_perform(Ecore_Con_Url *url_con) curl_multi_strerror(ret)); if (ms == 0) - ms = 1000; + ms = 1000; FD_SET(fd, &_current_fd_set); url_con->fd = fd; url_con->flags = flags; url_con->fd_handler = - ecore_main_fd_handler_add(fd, flags, - _ecore_con_url_fd_handler, - NULL, NULL, NULL); + ecore_main_fd_handler_add(fd, flags, + _ecore_con_url_fd_handler, + NULL, NULL, NULL); break; } } @@ -1308,16 +1341,16 @@ _ecore_con_url_perform(Ecore_Con_Url *url_con) if (!url_con->fd_handler) { /* Failed to set up an fd_handler */ - ecore_timer_freeze(_curl_timeout); + ecore_timer_freeze(_curl_timeout); - ret = curl_multi_remove_handle(_curlm, url_con->curl_easy); - if (ret != CURLM_OK) - ERR("curl_multi_remove_handle failed: %s", - curl_multi_strerror(ret)); + ret = curl_multi_remove_handle(_curlm, url_con->curl_easy); + if (ret != CURLM_OK) + ERR("curl_multi_remove_handle failed: %s", + curl_multi_strerror(ret)); - url_con->active = EINA_FALSE; - url_con->fd = -1; - return EINA_FALSE; + url_con->active = EINA_FALSE; + url_con->fd = -1; + return EINA_FALSE; } ecore_timer_thaw(_curl_timeout); @@ -1334,12 +1367,12 @@ _ecore_con_url_idler_handler(void *data) start = ecore_time_get(); while (curl_multi_perform(_curlm, &still_running) == CURLM_CALL_MULTI_PERFORM) - /* make this not more than a frametime to keep interactivity high */ - if ((ecore_time_get() - start) > ecore_animator_frametime_get()) - { - done = 0; - break; - } + /* make this not more than a frametime to keep interactivity high */ + if ((ecore_time_get() - start) > ecore_animator_frametime_get()) + { + done = 0; + break; + } _ecore_con_url_process_completed_jobs(NULL); @@ -1349,7 +1382,7 @@ _ecore_con_url_idler_handler(void *data) _fd_idler_handler = NULL; if (!_url_con_list) - ecore_timer_freeze(_curl_timeout); + ecore_timer_freeze(_curl_timeout); return data == (void *)0xACE ? ECORE_CALLBACK_RENEW : ECORE_CALLBACK_CANCEL; @@ -1359,14 +1392,14 @@ _ecore_con_url_idler_handler(void *data) } static Eina_Bool -_ecore_con_url_fd_handler(void *data __UNUSED__, +_ecore_con_url_fd_handler(void *data __UNUSED__, Ecore_Fd_Handler *fd_handler __UNUSED__) { _ecore_con_url_suspend_fd_handler(); if (!_fd_idler_handler) - _fd_idler_handler = ecore_idler_add( - _ecore_con_url_idler_handler, NULL); + _fd_idler_handler = ecore_idler_add( + _ecore_con_url_idler_handler, NULL); return ECORE_CALLBACK_RENEW; } @@ -1386,64 +1419,65 @@ _ecore_con_url_process_completed_jobs(Ecore_Con_Url *url_con_to_match) while ((curlmsg = curl_multi_info_read(_curlm, &n_remaining))) { if (curlmsg->msg != CURLMSG_DONE) - continue; + continue; /* find the job which is done */ EINA_LIST_FOREACH(_url_con_list, l, url_con) - { - if (curlmsg->easy_handle == url_con->curl_easy) - { - if (url_con_to_match && - (url_con == url_con_to_match)) - job_matched = 1; + { + if (curlmsg->easy_handle == url_con->curl_easy) + { + if (url_con_to_match && + (url_con == url_con_to_match)) + job_matched = 1; - if(url_con->fd != -1) - { - FD_CLR(url_con->fd, &_current_fd_set); - if (url_con->fd_handler) - ecore_main_fd_handler_del( + if(url_con->fd != -1) + { + FD_CLR(url_con->fd, &_current_fd_set); + if (url_con->fd_handler) + ecore_main_fd_handler_del( url_con->fd_handler); - url_con->fd = -1; - url_con->fd_handler = NULL; - } + url_con->fd = -1; + url_con->fd_handler = NULL; + } - _url_con_list = eina_list_remove(_url_con_list, url_con); - url_con->active = EINA_FALSE; - e = calloc(1, sizeof(Ecore_Con_Event_Url_Complete)); - if (e) - { - e->url_con = url_con; - e->status = 0; - if (curlmsg->data.result == CURLE_OK) - { - long status; /* curl API uses long, not int */ + _url_con_list = eina_list_remove(_url_con_list, url_con); + url_con->active = EINA_FALSE; + e = calloc(1, sizeof(Ecore_Con_Event_Url_Complete)); + if (e) + { + e->url_con = url_con; + e->status = 0; + if (curlmsg->data.result == CURLE_OK) + { + long status; /* curl API uses long, not int */ - status = 0; - curl_easy_getinfo(curlmsg->easy_handle, - CURLINFO_RESPONSE_CODE, - &status); - e->status = status; - } + status = 0; + curl_easy_getinfo(curlmsg->easy_handle, + CURLINFO_RESPONSE_CODE, + &status); + e->status = status; + } - _url_complete_push_event(ECORE_CON_EVENT_URL_COMPLETE, e); - } + _url_complete_push_event(ECORE_CON_EVENT_URL_COMPLETE, e); + } - ret = curl_multi_remove_handle(_curlm, url_con->curl_easy); - if (ret != CURLM_OK) - ERR("curl_multi_remove_handle failed: %s", - curl_multi_strerror(ret)); + ret = curl_multi_remove_handle(_curlm, url_con->curl_easy); + if (ret != CURLM_OK) + ERR("curl_multi_remove_handle failed: %s", + curl_multi_strerror(ret)); - break; - } - } + break; + } + } } return job_matched; } static void -_ecore_con_event_url_free(void *data __UNUSED__, void *ev) +_ecore_con_event_url_free(void *data __UNUSED__, + void *ev) { free(ev); }