extern "C" {
#endif
- typedef struct _Ecore_Con_Server Ecore_Con_Server; /**< A connection handle */
- typedef struct _Ecore_Con_Client Ecore_Con_Client; /**< A connection handle */
- typedef struct _Ecore_Con_Url Ecore_Con_Url;
+typedef struct _Ecore_Con_Server Ecore_Con_Server; /**< A connection handle */
+typedef struct _Ecore_Con_Client Ecore_Con_Client; /**< A connection handle */
+typedef struct _Ecore_Con_Url Ecore_Con_Url;
/**
* A callback type for use with @ref ecore_con_lookup.
*/
- typedef void (*Ecore_Con_Dns_Cb)(const char *canonname,
- const char *ip,
- struct sockaddr *addr,
- int addrlen,
- void *data);
+typedef void (*Ecore_Con_Dns_Cb)(const char *canonname,
+ const char *ip,
+ struct sockaddr *addr,
+ int addrlen,
+ void *data);
/**
* Types for an ecore_con client/server object. A correct way to set this type is
- * with an ECORE_CON_$TYPE, optionally OR'ed with an ECORE_CON_$USE if encryption is desired.
- * @example ECORE_CON_REMOTE_TCP | ECORE_CON_USE_TLS
+ * with an ECORE_CON_$TYPE, optionally OR'ed with an ECORE_CON_$USE if encryption is desired,
+ * and LOAD_CERT if the previously loaded certificate should be used.
+ * @example ECORE_CON_REMOTE_TCP | ECORE_CON_USE_TLS | ECORE_CON_LOAD_CERT
*/
- typedef enum _Ecore_Con_Type
- {
- ECORE_CON_LOCAL_USER = 0,
- ECORE_CON_LOCAL_SYSTEM = 1,
- ECORE_CON_LOCAL_ABSTRACT = 2,
- ECORE_CON_REMOTE_TCP = 3,
- ECORE_CON_REMOTE_MCAST = 4,
- ECORE_CON_REMOTE_UDP = 5,
- ECORE_CON_REMOTE_BROADCAST = 6,
- ECORE_CON_REMOTE_NODELAY = 7,
-
- ECORE_CON_USE_SSL2 = (1 << 4),
- ECORE_CON_USE_SSL3 = (1 << 5),
- ECORE_CON_USE_TLS = (1 << 6)
- } Ecore_Con_Type;
+typedef enum _Ecore_Con_Type
+{
+ ECORE_CON_LOCAL_USER = 0, /** Socket in ~/.ecore */
+ ECORE_CON_LOCAL_SYSTEM = 1, /** Socket in /tmp */
+ ECORE_CON_LOCAL_ABSTRACT = 2, /** Abstract socket */
+ ECORE_CON_REMOTE_TCP = 3, /** Remote server using TCP */
+ ECORE_CON_REMOTE_MCAST = 4, /** Remote multicast server */
+ ECORE_CON_REMOTE_UDP = 5, /** Remote server using UDP */
+ ECORE_CON_REMOTE_BROADCAST = 6, /** Remote broadcast using UDP */
+ ECORE_CON_REMOTE_NODELAY = 7,
+
+ ECORE_CON_USE_SSL2 = (1 << 4), /** Use SSL2: UNSUPPORTED. **/
+ ECORE_CON_USE_SSL3 = (1 << 5), /** Use SSL3 */
+ ECORE_CON_USE_TLS = (1 << 6), /** Use TLS */
+
+ ECORE_CON_LOAD_CERT = (1 << 7) /** Attempt to use the previously loaded certificate */
+} Ecore_Con_Type;
#define ECORE_CON_USE_SSL ECORE_CON_USE_SSL2
#define ECORE_CON_REMOTE_SYSTEM ECORE_CON_REMOTE_TCP
- typedef enum _Ecore_Con_Url_Time
- {
- ECORE_CON_URL_TIME_NONE = 0,
- ECORE_CON_URL_TIME_IFMODSINCE,
- ECORE_CON_URL_TIME_IFUNMODSINCE,
- ECORE_CON_URL_TIME_LASTMOD
- } Ecore_Con_Url_Time;
-
- typedef struct _Ecore_Con_Event_Client_Add Ecore_Con_Event_Client_Add;
- typedef struct _Ecore_Con_Event_Client_Del Ecore_Con_Event_Client_Del;
- typedef struct _Ecore_Con_Event_Server_Add Ecore_Con_Event_Server_Add;
- typedef struct _Ecore_Con_Event_Server_Del Ecore_Con_Event_Server_Del;
- typedef struct _Ecore_Con_Event_Client_Data Ecore_Con_Event_Client_Data;
- typedef struct _Ecore_Con_Event_Server_Data Ecore_Con_Event_Server_Data;
- typedef struct _Ecore_Con_Event_Url_Data Ecore_Con_Event_Url_Data;
- typedef struct _Ecore_Con_Event_Url_Complete Ecore_Con_Event_Url_Complete;
- typedef struct _Ecore_Con_Event_Url_Progress Ecore_Con_Event_Url_Progress;
-
- /// Used as the @p data param for the corresponding event
- struct _Ecore_Con_Event_Client_Add
- {
- Ecore_Con_Client *client;
- };
-
- /// Used as the @p data param for the corresponding event
- struct _Ecore_Con_Event_Client_Del
- {
- Ecore_Con_Client *client;
- };
-
- /// Used as the @p data param for the corresponding event
- struct _Ecore_Con_Event_Server_Add
- {
- Ecore_Con_Server *server;
- };
-
- /// Used as the @p data param for the corresponding event
- struct _Ecore_Con_Event_Server_Del
- {
- Ecore_Con_Server *server;
- };
-
- /// Used as the @p data param for the corresponding event
- struct _Ecore_Con_Event_Client_Data
- {
- Ecore_Con_Client *client;
- void *data;
- int size;
- };
-
- /// Used as the @p data param for the corresponding event
- struct _Ecore_Con_Event_Server_Data
- {
- Ecore_Con_Server *server;
- void *data;
- int size;
- };
-
- /// Used as the @p data param for the corresponding event
- struct _Ecore_Con_Event_Url_Data
- {
- Ecore_Con_Url *url_con;
- int size;
- unsigned char data[1];
- };
-
- /// Used as the @p data param for the corresponding event
- struct _Ecore_Con_Event_Url_Complete
- {
- Ecore_Con_Url *url_con;
- int status;
- };
-
- /// Used as the @p data param for the corresponding event
- struct _Ecore_Con_Event_Url_Progress
- {
- Ecore_Con_Url *url_con;
- struct {
- double total;
- double now;
- } down;
- struct {
- double total;
- double now;
- } up;
- };
-
- EAPI extern int ECORE_CON_EVENT_CLIENT_ADD; /** A client has connected to the server */
- EAPI extern int ECORE_CON_EVENT_CLIENT_DEL; /** A client has disconnected from the server */
- EAPI extern int ECORE_CON_EVENT_SERVER_ADD; /** A server was created */
- EAPI extern int ECORE_CON_EVENT_SERVER_DEL; /** A server connection was lost */
- EAPI extern int ECORE_CON_EVENT_CLIENT_DATA; /** A client connected to the server has sent data */
- EAPI extern int ECORE_CON_EVENT_SERVER_DATA; /** A server connection object has data */
- EAPI extern int ECORE_CON_EVENT_URL_DATA; /** A URL object has data */
- EAPI extern int ECORE_CON_EVENT_URL_COMPLETE; /** A URL object has completed its transfer */
- EAPI extern int ECORE_CON_EVENT_URL_PROGRESS; /** A URL object has made progress in its transfer */
-
- EAPI int ecore_con_init(void);
- EAPI int ecore_con_shutdown(void);
-
- EAPI Ecore_Con_Server *ecore_con_server_add(Ecore_Con_Type type, const char *name, int port, const void *data);
-
- EAPI Ecore_Con_Server *ecore_con_server_connect(Ecore_Con_Type type, const char *name, int port, const void *data);
- EAPI void *ecore_con_server_del(Ecore_Con_Server *svr);
- EAPI void *ecore_con_server_data_get(Ecore_Con_Server *svr);
- EAPI int ecore_con_server_connected_get(Ecore_Con_Server *svr);
- EAPI Eina_List *ecore_con_server_clients_get(Ecore_Con_Server *svr);
- EAPI int ecore_con_server_send(Ecore_Con_Server *svr, const void *data, int size);
- EAPI void ecore_con_server_client_limit_set(Ecore_Con_Server *svr, int client_limit, char reject_excess_clients);
- EAPI char *ecore_con_server_ip_get(Ecore_Con_Server *svr);
- EAPI void ecore_con_server_flush(Ecore_Con_Server *svr);
-
- EAPI int ecore_con_client_send(Ecore_Con_Client *cl, const void *data, int size);
- EAPI Ecore_Con_Server *ecore_con_client_server_get(Ecore_Con_Client *cl);
- EAPI void *ecore_con_client_del(Ecore_Con_Client *cl);
- EAPI void ecore_con_client_data_set(Ecore_Con_Client *cl, const void *data);
- EAPI void *ecore_con_client_data_get(Ecore_Con_Client *cl);
- EAPI char *ecore_con_client_ip_get(Ecore_Con_Client *cl);
- EAPI void ecore_con_client_flush(Ecore_Con_Client *cl);
-
- EAPI int ecore_con_ssl_available_get(void);
-
- EAPI int ecore_con_url_init(void);
- EAPI int ecore_con_url_shutdown(void);
- EAPI Ecore_Con_Url *ecore_con_url_new(const char *url);
- EAPI Ecore_Con_Url *ecore_con_url_custom_new(const char *url, const char *custom_request);
- EAPI void ecore_con_url_destroy(Ecore_Con_Url *url_con);
- EAPI void ecore_con_url_data_set(Ecore_Con_Url *url_con, void *data);
- EAPI void *ecore_con_url_data_get(Ecore_Con_Url *url_con);
- EAPI void ecore_con_url_additional_header_add(Ecore_Con_Url *url_con, const char *key, const char *value);
- EAPI void ecore_con_url_additional_headers_clear(Ecore_Con_Url *url_con);
- EAPI const Eina_List *ecore_con_url_response_headers_get(Ecore_Con_Url *url_con);
- EAPI int ecore_con_url_url_set(Ecore_Con_Url *url_con, const char *url);
- EAPI void ecore_con_url_fd_set(Ecore_Con_Url *url_con, int fd);
- EAPI int ecore_con_url_received_bytes_get(Ecore_Con_Url *url_con);
- EAPI int ecore_con_url_httpauth_set(Ecore_Con_Url *url_con, const char *username, const char *password, Eina_Bool safe);
- EAPI int ecore_con_url_send(Ecore_Con_Url *url_con, const void *data, size_t length, const char *content_type);
- EAPI void ecore_con_url_time(Ecore_Con_Url *url_con, Ecore_Con_Url_Time condition, time_t tm);
-
- EAPI Eina_Bool ecore_con_lookup(const char *name, Ecore_Con_Dns_Cb done_cb, const void *data);
-
- EAPI int ecore_con_url_ftp_upload(Ecore_Con_Url *url_con, const char *filename, const char *user, const char *pass, const char *upload_dir);
- EAPI void ecore_con_url_verbose_set(Ecore_Con_Url *url_con, int verbose);
- EAPI void ecore_con_url_ftp_use_epsv_set(Ecore_Con_Url *url_con, int use_epsv);
- EAPI int ecore_con_url_http_post_send(Ecore_Con_Url *url_con, void *curl_httppost);
+typedef enum _Ecore_Con_Url_Time
+{
+ ECORE_CON_URL_TIME_NONE = 0,
+ ECORE_CON_URL_TIME_IFMODSINCE,
+ ECORE_CON_URL_TIME_IFUNMODSINCE,
+ ECORE_CON_URL_TIME_LASTMOD
+} Ecore_Con_Url_Time;
+
+typedef struct _Ecore_Con_Event_Client_Add Ecore_Con_Event_Client_Add;
+typedef struct _Ecore_Con_Event_Client_Del Ecore_Con_Event_Client_Del;
+typedef struct _Ecore_Con_Event_Server_Add Ecore_Con_Event_Server_Add;
+typedef struct _Ecore_Con_Event_Server_Del Ecore_Con_Event_Server_Del;
+typedef struct _Ecore_Con_Event_Client_Data Ecore_Con_Event_Client_Data;
+typedef struct _Ecore_Con_Event_Server_Data Ecore_Con_Event_Server_Data;
+typedef struct _Ecore_Con_Event_Url_Data Ecore_Con_Event_Url_Data;
+typedef struct _Ecore_Con_Event_Url_Complete Ecore_Con_Event_Url_Complete;
+typedef struct _Ecore_Con_Event_Url_Progress Ecore_Con_Event_Url_Progress;
+
+/// Used as the @p data param for the corresponding event
+struct _Ecore_Con_Event_Client_Add
+{
+ Ecore_Con_Client *client;
+};
+
+/// Used as the @p data param for the corresponding event
+struct _Ecore_Con_Event_Client_Del
+{
+ Ecore_Con_Client *client;
+};
+
+/// Used as the @p data param for the corresponding event
+struct _Ecore_Con_Event_Server_Add
+{
+ Ecore_Con_Server *server;
+};
+
+/// Used as the @p data param for the corresponding event
+struct _Ecore_Con_Event_Server_Del
+{
+ Ecore_Con_Server *server;
+};
+
+/// Used as the @p data param for the corresponding event
+struct _Ecore_Con_Event_Client_Data
+{
+ Ecore_Con_Client *client;
+ void *data;
+ int size;
+};
+
+/// Used as the @p data param for the corresponding event
+struct _Ecore_Con_Event_Server_Data
+{
+ Ecore_Con_Server *server;
+ void *data;
+ int size;
+};
+
+/// Used as the @p data param for the corresponding event
+struct _Ecore_Con_Event_Url_Data
+{
+ Ecore_Con_Url *url_con;
+ int size;
+ unsigned char data[1];
+};
+
+/// Used as the @p data param for the corresponding event
+struct _Ecore_Con_Event_Url_Complete
+{
+ Ecore_Con_Url *url_con;
+ int status;
+};
+
+/// Used as the @p data param for the corresponding event
+struct _Ecore_Con_Event_Url_Progress
+{
+ Ecore_Con_Url *url_con;
+ struct
+ {
+ double total;
+ double now;
+ } down;
+ struct
+ {
+ double total;
+ double now;
+ } up;
+};
+
+EAPI extern int ECORE_CON_EVENT_CLIENT_ADD; /** A client has connected to the server */
+EAPI extern int ECORE_CON_EVENT_CLIENT_DEL; /** A client has disconnected from the server */
+EAPI extern int ECORE_CON_EVENT_SERVER_ADD; /** A server was created */
+EAPI extern int ECORE_CON_EVENT_SERVER_DEL; /** A server connection was lost */
+EAPI extern int ECORE_CON_EVENT_CLIENT_DATA; /** A client connected to the server has sent data */
+EAPI extern int ECORE_CON_EVENT_SERVER_DATA; /** A server connection object has data */
+EAPI extern int ECORE_CON_EVENT_URL_DATA; /** A URL object has data */
+EAPI extern int ECORE_CON_EVENT_URL_COMPLETE; /** A URL object has completed its transfer to and from the server and can be reused */
+EAPI extern int ECORE_CON_EVENT_URL_PROGRESS; /** A URL object has made progress in its transfer */
+
+EAPI int ecore_con_init(void);
+EAPI int ecore_con_shutdown(void);
+EAPI Eina_Bool ecore_con_ssl_cert_add(const char *cert);
+
+EAPI Ecore_Con_Server *ecore_con_server_add(Ecore_Con_Type type,
+ const char *name, int port,
+ const void *data);
+
+EAPI Ecore_Con_Server *ecore_con_server_connect(Ecore_Con_Type type,
+ const char *name, int port,
+ const void *data);
+EAPI void * ecore_con_server_del(Ecore_Con_Server *svr);
+EAPI void * ecore_con_server_data_get(Ecore_Con_Server *svr);
+EAPI int ecore_con_server_connected_get(Ecore_Con_Server *svr);
+EAPI Eina_List * ecore_con_server_clients_get(Ecore_Con_Server *svr);
+EAPI int ecore_con_server_send(Ecore_Con_Server *svr,
+ const void *data,
+ int size);
+EAPI void ecore_con_server_client_limit_set(Ecore_Con_Server *svr,
+ int client_limit,
+ char
+ reject_excess_clients);
+EAPI char * ecore_con_server_ip_get(Ecore_Con_Server *svr);
+EAPI void ecore_con_server_flush(Ecore_Con_Server *svr);
+
+EAPI int ecore_con_client_send(Ecore_Con_Client *cl,
+ const void *data,
+ int size);
+EAPI Ecore_Con_Server *ecore_con_client_server_get(Ecore_Con_Client *cl);
+EAPI void * ecore_con_client_del(Ecore_Con_Client *cl);
+EAPI void ecore_con_client_data_set(Ecore_Con_Client *cl,
+ const void *data);
+EAPI void * ecore_con_client_data_get(Ecore_Con_Client *cl);
+EAPI char * ecore_con_client_ip_get(Ecore_Con_Client *cl);
+EAPI void ecore_con_client_flush(Ecore_Con_Client *cl);
+
+EAPI int ecore_con_ssl_available_get(void);
+
+EAPI int ecore_con_url_init(void);
+EAPI int ecore_con_url_shutdown(void);
+EAPI Ecore_Con_Url * ecore_con_url_new(const char *url);
+EAPI Ecore_Con_Url * ecore_con_url_custom_new(const char *url,
+ const char *custom_request);
+EAPI void ecore_con_url_destroy(Ecore_Con_Url *url_con);
+EAPI void ecore_con_url_data_set(Ecore_Con_Url *url_con,
+ void *data);
+EAPI void * ecore_con_url_data_get(Ecore_Con_Url *url_con);
+EAPI void ecore_con_url_additional_header_add(
+ Ecore_Con_Url *url_con,
+ const char *key,
+ const char *value);
+EAPI void ecore_con_url_additional_headers_clear(
+ Ecore_Con_Url *url_con);
+EAPI const Eina_List * ecore_con_url_response_headers_get(
+ Ecore_Con_Url *url_con);
+EAPI int ecore_con_url_url_set(Ecore_Con_Url *url_con,
+ const char *url);
+EAPI void ecore_con_url_fd_set(Ecore_Con_Url *url_con, int fd);
+EAPI int ecore_con_url_received_bytes_get(Ecore_Con_Url *url_con);
+EAPI int ecore_con_url_httpauth_set(Ecore_Con_Url *url_con,
+ const char *username,
+ const char *password,
+ Eina_Bool safe);
+EAPI int ecore_con_url_send(Ecore_Con_Url *url_con,
+ const void *data, size_t length,
+ const char *content_type);
+EAPI void ecore_con_url_time(Ecore_Con_Url *url_con,
+ Ecore_Con_Url_Time condition,
+ time_t tm);
+
+EAPI Eina_Bool ecore_con_lookup(const char *name,
+ Ecore_Con_Dns_Cb done_cb,
+ const void *data);
+
+EAPI int ecore_con_url_ftp_upload(Ecore_Con_Url *url_con,
+ const char *filename,
+ const char *user,
+ const char *pass,
+ const char *upload_dir);
+EAPI void ecore_con_url_verbose_set(Ecore_Con_Url *url_con,
+ int verbose);
+EAPI void ecore_con_url_ftp_use_epsv_set(Ecore_Con_Url *url_con,
+ int use_epsv);
+EAPI int ecore_con_url_http_post_send(Ecore_Con_Url *url_con,
+ void *
+ curl_httppost);
#ifdef __cplusplus
}
#include "Ecore_Con.h"
#include "ecore_con_private.h"
-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 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_handler(void *data, Ecore_Fd_Handler *fd_handler);
+static Eina_Bool _ecore_con_svr_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_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_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;
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("EcoreCon", ECORE_CON_DEFAULT_LOG_COLOR);
+ _ecore_con_log_dom = eina_log_domain_register("EcoreCon",
+ ECORE_CON_DEFAULT_LOG_COLOR);
if(_ecore_con_log_dom < 0)
{
- EINA_LOG_ERR("Impossible to create a log domain for Ecore Con.");
- ecore_shutdown();
- return --_ecore_con_init_count;
+ EINA_LOG_ERR("Impossible to create a log domain for Ecore Con.");
+ ecore_shutdown();
+ return --_ecore_con_init_count;
}
+
ECORE_CON_EVENT_CLIENT_ADD = ecore_event_type_new();
ECORE_CON_EVENT_CLIENT_DEL = ecore_event_type_new();
ECORE_CON_EVENT_SERVER_ADD = ecore_event_type_new();
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();
*/
EAPI Ecore_Con_Server *
ecore_con_server_add(Ecore_Con_Type compl_type, const char *name, int port,
- const void *data)
+ const void *data)
{
- Ecore_Con_Server *svr;
- Ecore_Con_Type type;
+ Ecore_Con_Server *svr;
+ Ecore_Con_Type type;
+
+ if (port < 0 || !name)
+ return NULL; /* local user socket: FILE: ~/.ecore/[name]/[port] */
- if (port < 0 || !name) 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;
+ if (!svr)
+ return NULL;
svr->name = strdup(name);
- if (!svr->name) goto error;
+ if (!svr->name)
+ goto error;
+
svr->type = compl_type;
svr->port = port;
svr->data = (void *)data;
type = compl_type & ECORE_CON_TYPE;
- if ((type == ECORE_CON_LOCAL_USER) ||
+ 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_handler, svr)) goto error;
- }
-
- if ((type == ECORE_CON_REMOTE_TCP) ||
+ /* Local */
+ if (!ecore_con_local_listen(svr, _ecore_con_svr_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)) goto error;
+ 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);
return svr;
- error:
- if (svr->name) free(svr->name);
- if (svr->path) free(svr->path);
+error:
+ if (svr->name)
+ free(svr->name);
+
+ if (svr->path)
+ free(svr->path);
+
#ifndef _WIN32
- if (svr->fd >= 0) close(svr->fd);
- if (svr->fd_handler) ecore_main_fd_handler_del(svr->fd_handler);
- if (svr->write_buf) free(svr->write_buf);
- if (svr->ip) free(svr->ip);
+ if (svr->fd >= 0)
+ close(svr->fd);
+
+ if (svr->fd_handler)
+ ecore_main_fd_handler_del(svr->fd_handler);
+
+ if (svr->write_buf)
+ free(svr->write_buf);
+
+ if (svr->ip)
+ free(svr->ip);
+
#endif
- ecore_con_ssl_server_shutdown(svr);
+ ecore_con_ssl_server_shutdown(svr);
free(svr);
return NULL;
}
*/
EAPI Ecore_Con_Server *
ecore_con_server_connect(Ecore_Con_Type compl_type, const char *name, int port,
- const void *data)
+ const void *data)
{
- Ecore_Con_Server *svr;
- Ecore_Con_Type type;
+ Ecore_Con_Server *svr;
+ Ecore_Con_Type type;
+
+ if (!name)
+ return NULL; /* local user socket: FILE: ~/.ecore/[name]/[port] */
- if (!name) 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;
+ if (!svr)
+ return NULL;
svr->name = strdup(name);
- if (!svr->name) goto error;
+ if (!svr->name)
+ goto error;
+
svr->type = compl_type;
svr->port = port;
svr->data = (void *)data;
type = compl_type & ECORE_CON_TYPE;
- if (((type == ECORE_CON_REMOTE_TCP) ||
+ if (((type == ECORE_CON_REMOTE_TCP) ||
(type == ECORE_CON_REMOTE_NODELAY) ||
- (type == ECORE_CON_REMOTE_UDP) ||
+ (type == ECORE_CON_REMOTE_UDP) ||
(type == ECORE_CON_REMOTE_BROADCAST)) &&
(port < 0))
- goto error;
-
- if ((type == ECORE_CON_LOCAL_USER) ||
+ 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) ||
+ 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)) goto error;
+ if (!ecore_con_info_tcp_connect(svr, _ecore_con_cb_tcp_connect,
+ svr))
+ goto error;
}
- else if ((type == ECORE_CON_REMOTE_UDP) ||
+ 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);
return svr;
- error:
- if (svr->name) free(svr->name);
- if (svr->path) free(svr->path);
- if (svr->fd >= 0) close(svr->fd);
- if (svr->fd_handler) ecore_main_fd_handler_del(svr->fd_handler);
+error:
+ if (svr->name)
+ free(svr->name);
+
+ if (svr->path)
+ free(svr->path);
+
+ if (svr->fd >= 0)
+ close(svr->fd);
+
+ if (svr->fd_handler)
+ ecore_main_fd_handler_del(svr->fd_handler);
+
ecore_con_ssl_server_shutdown(svr);
free(svr);
return NULL;
if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
{
- ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_del");
- return NULL;
+ ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_del");
+ return NULL;
}
- if (svr->delete_me) return NULL;
+
+ if (svr->delete_me)
+ return NULL;
data = svr->data;
svr->data = NULL;
svr->delete_me = 1;
if (svr->event_count > 0)
{
- if (svr->fd_handler)
- {
- ecore_main_fd_handler_del(svr->fd_handler);
- svr->fd_handler = NULL;
- }
+ if (svr->fd_handler)
+ {
+ ecore_main_fd_handler_del(svr->fd_handler);
+ svr->fd_handler = NULL;
+ }
}
else
- {
- _ecore_con_server_free(svr);
- }
+ _ecore_con_server_free(svr);
+
return data;
}
{
if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
{
- ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_data_get");
- return NULL;
+ ECORE_MAGIC_FAIL(svr,
+ ECORE_MAGIC_CON_SERVER,
+ "ecore_con_server_data_get");
+ return NULL;
}
+
return svr->data;
}
{
if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
{
- ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_connected_get");
- return 0;
+ ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER,
+ "ecore_con_server_connected_get");
+ return 0;
}
- if (svr->connecting) return 0;
+
+ if (svr->connecting)
+ return 0;
+
return 1;
}
{
if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
{
- ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_clients_get");
- return NULL;
+ ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER,
+ "ecore_con_server_clients_get");
+ return NULL;
}
+
return svr->clients;
}
{
if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
{
- ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_send");
- return 0;
+ ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_send");
+ return 0;
}
- if (svr->dead) return 0;
- if (!data) return 0;
- if (size < 1) return 0;
+
+ if (svr->dead)
+ return 0;
+
+ if (!data)
+ return 0;
+
+ if (size < 1)
+ return 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)
{
- unsigned char *newbuf;
+ unsigned char *newbuf;
+
+ newbuf = realloc(svr->write_buf, svr->write_buf_size + size);
+ if (newbuf)
+ svr->write_buf = newbuf;
+ else
+ return 0;
- newbuf = realloc(svr->write_buf, svr->write_buf_size + size);
- if (newbuf) svr->write_buf = newbuf;
- else return 0;
- memcpy(svr->write_buf + svr->write_buf_size, data, size);
- svr->write_buf_size += size;
+ memcpy(svr->write_buf + svr->write_buf_size, data, size);
+ svr->write_buf_size += size;
}
else
{
- svr->write_buf = malloc(size);
- if (!svr->write_buf) return 0;
- svr->write_buf_size = size;
- memcpy(svr->write_buf, data, size);
+ svr->write_buf = malloc(size);
+ if (!svr->write_buf)
+ return 0;
+
+ svr->write_buf_size = size;
+ memcpy(svr->write_buf, data, size);
}
+
return size;
}
* @ingroup Ecore_Con_Server_Group
*/
EAPI void
-ecore_con_server_client_limit_set(Ecore_Con_Server *svr, int client_limit, char reject_excess_clients)
+ecore_con_server_client_limit_set(Ecore_Con_Server *svr, int client_limit,
+ char reject_excess_clients)
{
if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
{
- ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_client_limit_set");
- return;
+ ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER,
+ "ecore_con_server_client_limit_set");
+ return;
}
+
svr->client_limit = client_limit;
svr->reject_excess_clients = reject_excess_clients;
}
{
if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
{
- ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_ip_get");
- return NULL;
+ ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_ip_get");
+ return NULL;
}
+
return svr->ip;
}
{
if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
{
- ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_flush");
- return;
+ ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_flush");
+ return;
}
+
_ecore_con_server_flush(svr);
}
{
if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
{
- ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_send");
- return 0;
+ ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_send");
+ return 0;
}
- if (cl->dead) return 0;
- if (!data) return 0;
- if (size < 1) return 0;
+
+ if (cl->dead)
+ return 0;
+
+ if (!data)
+ return 0;
+
+ if (size < 1)
+ return 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->server && cl->server->type == ECORE_CON_REMOTE_UDP)
- {
- sendto(cl->server->fd, data, size, 0, (struct sockaddr *) cl->client_addr, cl->client_addr_len);
- }
+ sendto(cl->server->fd, data, size, 0, (struct sockaddr *)cl->client_addr,
+ cl->client_addr_len);
else if (cl->buf)
{
- unsigned char *newbuf;
+ unsigned char *newbuf;
- newbuf = realloc(cl->buf, cl->buf_size + size);
- if (newbuf) cl->buf = newbuf;
- else return 0;
- memcpy(cl->buf + cl->buf_size, data, size);
- cl->buf_size += size;
+ newbuf = realloc(cl->buf, cl->buf_size + size);
+ if (newbuf)
+ cl->buf = newbuf;
+ else
+ return 0;
+
+ memcpy(cl->buf + cl->buf_size, data, size);
+ cl->buf_size += size;
}
else
{
- cl->buf = malloc(size);
- if (!cl->buf) return 0;
- cl->buf_size = size;
- memcpy(cl->buf, data, size);
+ cl->buf = malloc(size);
+ if (!cl->buf)
+ return 0;
+
+ cl->buf_size = size;
+ memcpy(cl->buf, data, size);
}
+
return size;
}
{
if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
{
- ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_server_get");
- return NULL;
+ ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT,
+ "ecore_con_client_server_get");
+ return NULL;
}
+
return cl->server;
}
if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
{
- ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_del");
- return NULL;
+ ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_del");
+ return NULL;
}
- if(cl->client_addr && cl->server && (cl->server->type == ECORE_CON_REMOTE_UDP ||
- cl->server->type == ECORE_CON_REMOTE_MCAST))
- free(cl->client_addr);
+ if(cl->client_addr && cl->server &&
+ (cl->server->type == ECORE_CON_REMOTE_UDP ||
+ cl->server->type ==
+ ECORE_CON_REMOTE_MCAST))
+ free(cl->client_addr);
data = cl->data;
cl->delete_me = 1;
if (cl->event_count > 0)
{
- if (cl->fd_handler)
- {
- ecore_main_fd_handler_del(cl->fd_handler);
- cl->fd_handler = NULL;
- }
+ if (cl->fd_handler)
+ {
+ ecore_main_fd_handler_del(cl->fd_handler);
+ cl->fd_handler = NULL;
+ }
}
else
{
if (cl->server)
- cl->server->clients = eina_list_remove(cl->server->clients, cl);
- _ecore_con_client_free(cl);
+ cl->server->clients = eina_list_remove(
+ cl->server->clients, cl);
+
+ _ecore_con_client_free(cl);
}
+
return data;
}
{
if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
{
- ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_data_set");
- return;
+ ECORE_MAGIC_FAIL(cl,
+ ECORE_MAGIC_CON_CLIENT,
+ "ecore_con_client_data_set");
+ return;
}
+
cl->data = (void *)data;
}
{
if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
{
- ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_data_get");
- return NULL;
+ ECORE_MAGIC_FAIL(cl,
+ ECORE_MAGIC_CON_CLIENT,
+ "ecore_con_client_data_get");
+ return NULL;
}
+
return cl->data;
}
{
if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
{
- ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_ip_get");
- return NULL;
+ ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_ip_get");
+ return NULL;
}
+
return cl->ip;
}
{
if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
{
- ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_flush");
- return;
+ ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_flush");
+ return;
}
+
_ecore_con_client_flush(cl);
}
* Do an asynchronous DNS lookup.
*
* This function performs a DNS lookup on the hostname specified by @p name, then
- * calls @p done_cb with
+ * calls @p done_cb with
*
* @params name IP address or server name to translate.
* @params done_cb Callback to notify when done.
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;
+ if (!svr)
+ return EINA_FALSE;
lk = malloc(sizeof (Ecore_Con_Lookup));
if (!lk)
{
- free(svr);
- return EINA_FALSE;
+ free(svr);
+ return EINA_FALSE;
}
lk->done_cb = done_cb;
lk->data = data;
svr->name = strdup(name);
- if (!svr->name) goto on_error;
+ if (!svr->name)
+ goto on_error;
svr->type = ECORE_CON_REMOTE_TCP;
svr->port = 1025;
hints.ai_next = NULL;
hints.ai_addr = NULL;
- if (ecore_con_info_get(svr, _ecore_con_lookup_done, svr, &hints))
- return EINA_TRUE;
+ if (ecore_con_info_get(svr, _ecore_con_lookup_done, svr,
+ &hints))
+ return EINA_TRUE;
free(svr->name);
- on_error:
+on_error:
free(lk);
free(svr);
return EINA_FALSE;
}
+/**
+ * Add an ssl certificate for use in ecore_con functions.
+ *
+ * Use this function to add a SSL PEM certificate to your ecore_con clients
+ * and servers. Simply specify the cert here to make it available,
+ * then OR the @ref ECORE_CON_LOAD_CERT flag into the @ref ecore_con_server_add or
+ * @ref ecore_con_server_connect call to use it. If there is an error loading the
+ * certificate upon creating the connection, an error will be automatically logged.
+ * @param cert The path to the certificate.
+ * @return EINA_FALSE if the file does not exist or does not end with the 'pem' suffix,
+ * otherwise EINA_TRUE.
+ */
+
+EAPI Eina_Bool
+ecore_con_ssl_cert_add(const char *cert)
+{
+ struct stat st;
+
+ if (stat(cert,
+ &st) || !eina_str_has_extension(cert, "pem"))
+ return EINA_FALSE;
+
+ _ecore_con_ssl_cert_add(cert);
+ return EINA_TRUE;
+}
+
static void
_ecore_con_server_free(Ecore_Con_Server *svr)
{
t_start = ecore_time_get();
while ((svr->write_buf) && (!svr->dead))
{
- _ecore_con_server_flush(svr);
- t = ecore_time_get();
- if ((t - t_start) > 0.5)
- {
- WRN("ECORE_CON: EEK - stuck in _ecore_con_server_free() trying\n"
- " to flush data out from the server, and have been for\n"
- " %1.1f seconds. This is taking too long. Aborting flush.",
- (t - t_start));
- break;
- }
+ _ecore_con_server_flush(svr);
+ t = ecore_time_get();
+ if ((t - t_start) > 0.5)
+ {
+ WRN("ECORE_CON: EEK - stuck in _ecore_con_server_free() trying\n"
+ " to flush data out from the server, and have been for\n"
+ " %1.1f seconds. This is taking too long. Aborting flush.",
+ (t - t_start));
+ break;
+ }
}
- if (svr->write_buf) free(svr->write_buf);
+ if (svr->write_buf)
+ free(svr->write_buf);
+
EINA_LIST_FREE(svr->clients, cl)
- _ecore_con_client_free(cl);
+ _ecore_con_client_free(cl);
if ((svr->created) && (svr->path) && (svr->ppid == getpid()))
- unlink(svr->path);
- if (svr->fd >= 0) close(svr->fd);
+ unlink(
+ svr->path);
+
+ if (svr->fd >= 0)
+ close(svr->fd);
+
ecore_con_ssl_server_shutdown(svr);
- if (svr->name) free(svr->name);
- if (svr->path) free(svr->path);
- if (svr->ip) free(svr->ip);
- if (svr->fd_handler) ecore_main_fd_handler_del(svr->fd_handler);
+ if (svr->name)
+ free(svr->name);
+
+ if (svr->path)
+ free(svr->path);
+
+ if (svr->ip)
+ free(svr->ip);
+
+ if (svr->fd_handler)
+ ecore_main_fd_handler_del(svr->fd_handler);
+
servers = eina_list_remove(servers, svr);
free(svr);
}
t_start = ecore_time_get();
while ((cl->buf) && (!cl->dead))
{
- _ecore_con_client_flush(cl);
- t = ecore_time_get();
- if ((t - t_start) > 0.5)
- {
- WRN("EEK - stuck in _ecore_con_client_free() trying\n"
- " to flush data out from the client, and have been for\n"
- " %1.1f seconds. This is taking too long. Aborting flush.",
- (t - t_start));
- break;
- }
+ _ecore_con_client_flush(cl);
+ t = ecore_time_get();
+ if ((t - t_start) > 0.5)
+ {
+ WRN("EEK - stuck in _ecore_con_client_free() trying\n"
+ " to flush data out from the client, and have been for\n"
+ " %1.1f seconds. This is taking too long. Aborting flush.",
+ (t - t_start));
+ break;
+ }
}
- if (cl->buf) free(cl->buf);
- if (cl->fd >= 0) close(cl->fd);
- if (cl->fd_handler) ecore_main_fd_handler_del(cl->fd_handler);
- if (cl->ip) free(cl->ip);
- free(cl);
+ if (cl->buf)
+ free(cl->buf);
+
+ if (cl->fd >= 0)
+ close(cl->fd);
+
+ if (cl->fd_handler)
+ ecore_main_fd_handler_del(cl->fd_handler);
+
+ if (cl->ip)
+ free(cl->ip);
+
+ free(cl);
}
static void
{
if (!svr->delete_me)
{
- Ecore_Con_Event_Server_Del *e;
-
- e = calloc(1, sizeof(Ecore_Con_Event_Server_Del));
- if (e)
- {
- svr->event_count++;
- e->server = svr;
- ecore_event_add(ECORE_CON_EVENT_SERVER_DEL, e,
- _ecore_con_event_server_del_free, NULL);
- }
+ Ecore_Con_Event_Server_Del *e;
+
+ e = calloc(1, sizeof(Ecore_Con_Event_Server_Del));
+ if (e)
+ {
+ svr->event_count++;
+ e->server = svr;
+ ecore_event_add(ECORE_CON_EVENT_SERVER_DEL, e,
+ _ecore_con_event_server_del_free, NULL);
+ }
}
svr->dead = 1;
- if (svr->fd_handler) ecore_main_fd_handler_del(svr->fd_handler);
+ if (svr->fd_handler)
+ ecore_main_fd_handler_del(svr->fd_handler);
+
svr->fd_handler = NULL;
}
svr = data;
- if(!net_info) goto error;
+ if(!net_info)
+ 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;
+
+ if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0)
+ goto error;
+
+ if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0)
+ 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;
- if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
- if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) 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;
+ if (setsockopt(svr->fd, SOL_SOCKET, SO_LINGER, (const void *)&lin,
+ sizeof(struct linger)) < 0)
+ goto error;
+
if (svr->type == ECORE_CON_REMOTE_NODELAY)
{
- int flag = 1;
+ int flag = 1;
- if (setsockopt(svr->fd, IPPROTO_TCP, TCP_NODELAY, (char *) &flag, sizeof(int)) < 0)
- goto error;
+ if (setsockopt(svr->fd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag,
+ sizeof(int)) < 0)
+ goto error;
}
- if (bind(svr->fd, net_info->info.ai_addr, net_info->info.ai_addrlen) < 0) goto error;
- if (listen(svr->fd, 4096) < 0) goto error;
+
+ if (bind(svr->fd, net_info->info.ai_addr,
+ net_info->info.ai_addrlen) < 0)
+ goto error;
+
+ if (listen(svr->fd, 4096) < 0)
+ goto error;
+
svr->fd_handler =
- ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ,
- _ecore_con_svr_handler, svr, NULL, NULL);
- if (!svr->fd_handler) goto error;
+ ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ,
+ _ecore_con_svr_handler, svr, NULL, NULL);
+ if (!svr->fd_handler)
+ goto error;
return;
- error:
+error:
ecore_con_ssl_server_shutdown(svr);
kill_server(svr);
}
type = svr->type;
type &= ECORE_CON_TYPE;
- if (!net_info) goto error;
+ if (!net_info)
+ 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;
+ svr->fd = socket(net_info->info.ai_family, net_info->info.ai_socktype,
+ net_info->info.ai_protocol);
+ if(svr->fd < 0)
+ goto error;
if (type == ECORE_CON_REMOTE_MCAST)
{
- if (net_info->info.ai_family == AF_INET)
- {
- if (!inet_pton(net_info->info.ai_family, net_info->ip, &mreq.imr_multiaddr)) 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;
- }
- 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;
- mreq6.ipv6mr_interface = htonl(INADDR_ANY);
- if (setsockopt(svr->fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (const void *)&mreq6,sizeof(mreq6)) != 0) goto error;
- }
- if (setsockopt(svr->fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&on, sizeof(on)) != 0) goto error;
+ if (net_info->info.ai_family == AF_INET)
+ {
+ if (!inet_pton(net_info->info.ai_family, net_info->ip,
+ &mreq.imr_multiaddr))
+ 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;
+ }
+ 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;
+
+ mreq6.ipv6mr_interface = htonl(INADDR_ANY);
+ if (setsockopt(svr->fd, IPPROTO_IP, IP_ADD_MEMBERSHIP,
+ (const void *)&mreq6,sizeof(mreq6)) != 0)
+ goto error;
+ }
+
+ if (setsockopt(svr->fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&on,
+ sizeof(on)) != 0)
+ goto error;
}
- if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
- if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
- if (bind(svr->fd, net_info->info.ai_addr, net_info->info.ai_addrlen) < 0) goto error;
+ if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0)
+ goto error;
+
+ if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0)
+ goto error;
+
+ if (bind(svr->fd, net_info->info.ai_addr,
+ net_info->info.ai_addrlen) < 0)
+ goto error;
+
svr->fd_handler =
- ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ,
- _ecore_con_svr_udp_handler, svr, NULL, NULL);
- if (!svr->fd_handler) goto error;
+ ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ,
+ _ecore_con_svr_udp_handler, svr, NULL, NULL);
+ if (!svr->fd_handler)
+ goto error;
+
svr->ip = strdup(net_info->ip);
return;
- error:
+error:
ecore_con_ssl_server_shutdown(svr);
kill_server(svr);
}
static void
_ecore_con_cb_tcp_connect(void *data, Ecore_Con_Info *net_info)
{
- Ecore_Con_Server *svr;
- int res;
- int curstate = 0;
+ Ecore_Con_Server *svr;
+ int res;
+ int curstate = 0;
svr = data;
- if (!net_info) 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;
- if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
- if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
- if (setsockopt(svr->fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&curstate, sizeof(curstate)) < 0)
- goto error;
+ if (!net_info)
+ 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;
+
+ if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0)
+ goto error;
+
+ if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0)
+ goto error;
+
+ if (setsockopt(svr->fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&curstate,
+ sizeof(curstate)) < 0)
+ goto error;
+
if (svr->type == ECORE_CON_REMOTE_NODELAY)
{
- int flag = 1;
+ int flag = 1;
- if (setsockopt(svr->fd, IPPROTO_TCP, TCP_NODELAY, (char *) &flag, sizeof(int)) < 0)
- goto error;
+ if (setsockopt(svr->fd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag,
+ sizeof(int)) < 0)
+ goto error;
}
+
res = connect(svr->fd, net_info->info.ai_addr, net_info->info.ai_addrlen);
#ifdef _WIN32
if (res == SOCKET_ERROR)
{
- if (WSAGetLastError() != WSAEINPROGRESS)
- goto error;
+ if (WSAGetLastError() != WSAEINPROGRESS)
+ goto error;
+
#else
if (res < 0)
{
- if (errno != EINPROGRESS)
- goto error;
+ if (errno != EINPROGRESS)
+ goto error;
+
#endif
- svr->connecting = 1;
- svr->fd_handler =
- ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ | ECORE_FD_WRITE,
- _ecore_con_cl_handler, svr, NULL, NULL);
+ svr->connecting = 1;
+ svr->fd_handler =
+ 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)
- if (ecore_con_ssl_server_init(svr))
- goto error;
+ if (ecore_con_ssl_server_init(svr))
+ goto error;
+
+ if (!svr->fd_handler)
+ goto error;
- if (!svr->fd_handler) goto error;
svr->ip = strdup(net_info->ip);
return;
- error:
+error:
ecore_con_ssl_server_shutdown(svr);
kill_server(svr);
}
static void
_ecore_con_cb_udp_connect(void *data, Ecore_Con_Info *net_info)
{
- Ecore_Con_Server *svr;
- int curstate = 0;
- int broadcast = 1;
+ Ecore_Con_Server *svr;
+ int curstate = 0;
+ int broadcast = 1;
svr = data;
- if (!net_info) 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;
- if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
- if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
+ if (!net_info)
+ 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;
+
+ if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0)
+ goto error;
+
+ if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0)
+ goto error;
if(svr->type == ECORE_CON_REMOTE_BROADCAST)
{
- if (setsockopt(svr->fd, SOL_SOCKET, SO_BROADCAST, (const void *)&broadcast, sizeof(broadcast)) < 0) goto error;
+ if (setsockopt(svr->fd, SOL_SOCKET, SO_BROADCAST,
+ (const void *)&broadcast,
+ sizeof(broadcast)) < 0)
+ goto error;
}
+ else if (setsockopt(svr->fd, SOL_SOCKET, SO_REUSEADDR,
+ (const void *)&curstate,
+ sizeof(curstate)) < 0)
+ goto error;
+
+ if (connect(svr->fd, net_info->info.ai_addr,
+ net_info->info.ai_addrlen) < 0)
+ goto error;
else
- {
- if (setsockopt(svr->fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&curstate, sizeof(curstate)) < 0) 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);
+
+ if (!svr->fd_handler)
+ goto error;
- if (connect(svr->fd, net_info->info.ai_addr, net_info->info.ai_addrlen) < 0)
- goto error;
- else
- svr->fd_handler =
- ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ | ECORE_FD_WRITE,
- _ecore_con_cl_udp_handler, svr, NULL, NULL);
- if (!svr->fd_handler) goto error;
svr->ip = strdup(net_info->ip);
return;
- error:
+error:
ecore_con_ssl_server_shutdown(svr);
- kill_server(svr);
+ kill_server(svr);
}
static Ecore_Con_State
svr_try_connect_plain(Ecore_Con_Server *svr)
{
- int res;
- int so_err = 0;
+ int res;
+ int so_err = 0;
unsigned int size = sizeof(int);
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! */
- kill_server(svr);
- return ECORE_CON_DISCONNECTED;
+ /* we lost our server! */
+ kill_server(svr);
+ return ECORE_CON_DISCONNECTED;
}
else
{
- if (!svr->delete_me)
- {
- /* we got our server! */
- Ecore_Con_Event_Server_Add *e;
-
- svr->connecting = 0;
- 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,
- _ecore_con_event_server_add_free, NULL);
- }
- }
- if (svr->fd_handler)
- {
- if (!svr->write_buf)
- ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ);
- }
+ if (!svr->delete_me)
+ {
+ /* we got our server! */
+ Ecore_Con_Event_Server_Add *e;
+
+ svr->connecting = 0;
+ 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,
+ _ecore_con_event_server_add_free, NULL);
+ }
+ }
+
+ if (svr->fd_handler)
+ if (!svr->write_buf)
+ 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;
}
/* returns 1 on success, 0 on failure */
static Ecore_Con_State svr_try_connect(Ecore_Con_Server *svr)
{
- if (!(svr->type & ECORE_CON_SSL))
- return svr_try_connect_plain(svr);
- else
- {
- switch (ecore_con_ssl_server_try(svr)) {
- case ECORE_CON_CONNECTED:
- return svr_try_connect_plain(svr);
- case ECORE_CON_DISCONNECTED:
- kill_server(svr);
- return ECORE_CON_DISCONNECTED;
- default:
- return ECORE_CON_INPROGRESS;
- }
- }
+ if (!(svr->type & ECORE_CON_SSL))
+ return svr_try_connect_plain(svr);
+ else
+ {
+ switch (ecore_con_ssl_server_try(svr)) {
+ case ECORE_CON_CONNECTED:
+ return svr_try_connect_plain(svr);
+
+ case ECORE_CON_DISCONNECTED:
+ kill_server(svr);
+ return ECORE_CON_DISCONNECTED;
+
+ default:
+ return ECORE_CON_INPROGRESS;
+ }
+ }
}
static char *
/* show v4mapped address in pretty form */
if (client_addr->sa_family == AF_INET6)
{
- struct sockaddr_in6 *sa6;
-
- sa6 = (struct sockaddr_in6 *) client_addr;
- if (IN6_IS_ADDR_V4MAPPED(&sa6->sin6_addr))
- {
- snprintf(ipbuf, sizeof (ipbuf), "%u.%u.%u.%u",
- sa6->sin6_addr.s6_addr[12],
- sa6->sin6_addr.s6_addr[13],
- sa6->sin6_addr.s6_addr[14],
- sa6->sin6_addr.s6_addr[15]);
- return strdup(ipbuf);
- }
+ struct sockaddr_in6 *sa6;
+
+ sa6 = (struct sockaddr_in6 *)client_addr;
+ if (IN6_IS_ADDR_V4MAPPED(&sa6->sin6_addr))
+ {
+ snprintf(ipbuf, sizeof (ipbuf), "%u.%u.%u.%u",
+ sa6->sin6_addr.s6_addr[12],
+ sa6->sin6_addr.s6_addr[13],
+ sa6->sin6_addr.s6_addr[14],
+ sa6->sin6_addr.s6_addr[15]);
+ return strdup(ipbuf);
+ }
}
if (getnameinfo(client_addr, size,
- ipbuf, sizeof (ipbuf), NULL, 0, NI_NUMERICHOST))
- return strdup("0.0.0.0");
+ ipbuf, sizeof (ipbuf), NULL, 0,
+ NI_NUMERICHOST))
+ return strdup("0.0.0.0");
ipbuf[sizeof (ipbuf) - 1] = 0;
return strdup(ipbuf);
static Eina_Bool
_ecore_con_svr_handler(void *data, Ecore_Fd_Handler *fd_handler __UNUSED__)
{
- Ecore_Con_Server *svr;
- int new_fd;
- unsigned char incoming[256];
- size_t size_in;
+ Ecore_Con_Server *svr;
+ int new_fd;
+ unsigned char incoming[256];
+ size_t size_in;
svr = data;
- if (svr->dead) return ECORE_CALLBACK_RENEW;
- if (svr->delete_me) return ECORE_CALLBACK_RENEW;
+ if (svr->dead)
+ return ECORE_CALLBACK_RENEW;
+
+ if (svr->delete_me)
+ return ECORE_CALLBACK_RENEW;
+
if ((svr->client_limit >= 0) && (!svr->reject_excess_clients))
- {
- if (eina_list_count(svr->clients) >= (unsigned int)svr->client_limit)
- return ECORE_CALLBACK_RENEW;
- }
+ if (eina_list_count(svr->clients) >=
+ (unsigned int)svr->client_limit)
+ return ECORE_CALLBACK_RENEW;
+
/* a new client */
+
size_in = sizeof(incoming);
memset(&incoming, 0, size_in);
new_fd = accept(svr->fd, (struct sockaddr *)&incoming, (socklen_t *)&size_in);
if (new_fd >= 0)
{
- Ecore_Con_Client *cl;
-
- if ((svr->client_limit >= 0) && (svr->reject_excess_clients))
- {
- if (eina_list_count(svr->clients) >= (unsigned int)svr->client_limit)
- {
- close(new_fd);
- return ECORE_CALLBACK_RENEW;
- }
- }
-
- cl = calloc(1, sizeof(Ecore_Con_Client));
- if (!cl)
- {
- close(new_fd);
- return ECORE_CALLBACK_RENEW;
- }
-
- fcntl(new_fd, F_SETFL, O_NONBLOCK);
- fcntl(new_fd, F_SETFD, FD_CLOEXEC);
- cl->fd = new_fd;
- cl->server = svr;
-
- if ((svr->type & ECORE_CON_SSL) &&
- (ecore_con_ssl_client_init(cl)))
- {
- close(new_fd);
- ecore_con_ssl_client_shutdown(cl);
- return ECORE_CALLBACK_RENEW;
- }
-
- cl->fd_handler =
- ecore_main_fd_handler_add(cl->fd, ECORE_FD_READ,
- _ecore_con_svr_cl_handler, cl, NULL, NULL);
- ECORE_MAGIC_SET(cl, ECORE_MAGIC_CON_CLIENT);
- svr->clients = eina_list_append(svr->clients, cl);
- if (!svr->path)
- cl->ip = _ecore_con_pretty_ip((struct sockaddr *) &incoming, size_in);
- if (!cl->delete_me)
- {
- Ecore_Con_Event_Client_Add *e;
-
- e = calloc(1, sizeof(Ecore_Con_Event_Client_Add));
- if (e)
- {
- cl->event_count++;
- e->client = cl;
- ecore_event_add(ECORE_CON_EVENT_CLIENT_ADD, e,
- _ecore_con_event_client_add_free, NULL);
- }
- }
+ Ecore_Con_Client *cl;
+
+ if ((svr->client_limit >= 0) && (svr->reject_excess_clients))
+ if (eina_list_count(svr->clients) >= (unsigned int)svr->client_limit)
+ {
+ close(new_fd);
+ return ECORE_CALLBACK_RENEW;
+ }
+
+ cl = calloc(1, sizeof(Ecore_Con_Client));
+ if (!cl)
+ {
+ close(new_fd);
+ return ECORE_CALLBACK_RENEW;
+ }
+
+ fcntl(new_fd, F_SETFL, O_NONBLOCK);
+ fcntl(new_fd, F_SETFD, FD_CLOEXEC);
+ cl->fd = new_fd;
+ cl->server = svr;
+
+ if ((svr->type & ECORE_CON_SSL) &&
+ (ecore_con_ssl_client_init(cl)))
+ {
+ close(new_fd);
+ ecore_con_ssl_client_shutdown(cl);
+ return ECORE_CALLBACK_RENEW;
+ }
+
+ cl->fd_handler =
+ ecore_main_fd_handler_add(cl->fd, ECORE_FD_READ,
+ _ecore_con_svr_cl_handler, cl, NULL, NULL);
+ ECORE_MAGIC_SET(cl, ECORE_MAGIC_CON_CLIENT);
+ svr->clients = eina_list_append(svr->clients, cl);
+ if (!svr->path)
+ cl->ip = _ecore_con_pretty_ip(
+ (struct sockaddr *)&incoming, size_in);
+
+ if (!cl->delete_me)
+ {
+ Ecore_Con_Event_Client_Add *e;
+
+ e = calloc(1, sizeof(Ecore_Con_Event_Client_Add));
+ if (e)
+ {
+ cl->event_count++;
+ e->client = cl;
+ ecore_event_add(ECORE_CON_EVENT_CLIENT_ADD, e,
+ _ecore_con_event_client_add_free, NULL);
+ }
+ }
}
+
return ECORE_CALLBACK_RENEW;
}
static Eina_Bool
_ecore_con_cl_handler(void *data, Ecore_Fd_Handler *fd_handler)
{
- Ecore_Con_Server *svr;
+ Ecore_Con_Server *svr;
svr = data;
- if (svr->dead) return ECORE_CALLBACK_RENEW;
- if (svr->delete_me) return ECORE_CALLBACK_RENEW;
+ if (svr->dead)
+ return ECORE_CALLBACK_RENEW;
+
+ if (svr->delete_me)
+ return ECORE_CALLBACK_RENEW;
+
if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ))
{
- unsigned char *inbuf = NULL;
- int inbuf_num = 0;
- int tries;
+ unsigned char *inbuf = NULL;
+ int inbuf_num = 0;
+ int tries;
- if (svr->connecting && (svr_try_connect(svr) != ECORE_CON_CONNECTED))
- return ECORE_CALLBACK_RENEW;
+ if (svr->connecting &&
+ (svr_try_connect(svr) !=
+ ECORE_CON_CONNECTED))
+ return ECORE_CALLBACK_RENEW;
- for (tries = 0; tries < 16; tries++)
- {
- int num;
- int lost_server = 1;
- unsigned char buf[READBUFSIZ];
+ for (tries = 0; tries < 16; tries++)
+ {
+ int num;
+ int lost_server = 1;
+ unsigned char buf[READBUFSIZ];
if (!(svr->type & ECORE_CON_SSL))
{
if ((num = read(svr->fd, buf, READBUFSIZ)) <= 0)
+ if ((num < 0) && (errno == EAGAIN))
+ lost_server = 0;
+
+ }
+ else if (!(num =
+ ecore_con_ssl_server_read(svr, buf,
+ READBUFSIZ)))
+ lost_server = 0;
+
+ if (num < 1)
+ {
+ if (inbuf && !svr->delete_me)
{
- if ((num < 0) && (errno == EAGAIN))
- lost_server = 0;
+ Ecore_Con_Event_Server_Data *e;
+
+ e = calloc(1, sizeof(Ecore_Con_Event_Server_Data));
+ if (e)
+ {
+ svr->event_count++;
+ e->server = svr;
+ e->data = inbuf;
+ e->size = inbuf_num;
+ ecore_event_add(ECORE_CON_EVENT_SERVER_DATA, e,
+ _ecore_con_event_server_data_free,
+ NULL);
+ }
}
- }
- else if (!(num = ecore_con_ssl_server_read(svr, buf, READBUFSIZ)))
- lost_server = 0;
-
- if (num < 1)
- {
- if (inbuf && !svr->delete_me)
- {
- Ecore_Con_Event_Server_Data *e;
-
- e = calloc(1, sizeof(Ecore_Con_Event_Server_Data));
- if (e)
- {
- svr->event_count++;
- e->server = svr;
- e->data = inbuf;
- e->size = inbuf_num;
- ecore_event_add(ECORE_CON_EVENT_SERVER_DATA, e,
- _ecore_con_event_server_data_free,
- NULL);
- }
- }
- if (lost_server) kill_server(svr);
- break;
- }
-
- inbuf = realloc(inbuf, inbuf_num + num);
- memcpy(inbuf + inbuf_num, buf, num);
- inbuf_num += num;
- }
+
+ if (lost_server)
+ kill_server(svr);
+
+ break;
+ }
+
+ inbuf = realloc(inbuf, inbuf_num + num);
+ memcpy(inbuf + inbuf_num, buf, num);
+ inbuf_num += num;
+ }
/* #if USE_OPENSSL */
-/* if (svr->fd_handler) */
-/* { */
-/* if (svr->ssl && ssl_err == SSL_ERROR_WANT_READ) */
-/* ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ); */
-/* else if (svr->ssl && ssl_err == SSL_ERROR_WANT_WRITE) */
-/* ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_WRITE); */
-/* } */
+/* if (svr->fd_handler) */
+/* { */
+/* if (svr->ssl && ssl_err == SSL_ERROR_WANT_READ) */
+/* ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ); */
+/* else if (svr->ssl && ssl_err == SSL_ERROR_WANT_WRITE) */
+/* ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_WRITE); */
+/* } */
/* #endif */
}
else if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_WRITE))
{
- if (svr->connecting && !svr_try_connect (svr))
- return ECORE_CALLBACK_RENEW;
- _ecore_con_server_flush(svr);
+ if (svr->connecting &&
+ !svr_try_connect (svr))
+ return ECORE_CALLBACK_RENEW;
+
+ _ecore_con_server_flush(svr);
}
return ECORE_CALLBACK_RENEW;
static Eina_Bool
_ecore_con_cl_udp_handler(void *data, Ecore_Fd_Handler *fd_handler)
{
- Ecore_Con_Server *svr;
+ Ecore_Con_Server *svr;
svr = data;
- if (svr->dead) return ECORE_CALLBACK_RENEW;
- if (svr->delete_me) return ECORE_CALLBACK_RENEW;
+ if (svr->dead)
+ return ECORE_CALLBACK_RENEW;
+
+ if (svr->delete_me)
+ return ECORE_CALLBACK_RENEW;
+
if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ))
{
- unsigned char buf[65536];
- int num = 0;
-
- errno = 0;
- num = read(svr->fd, buf, 65536);
- if (num > 0)
- {
- if (!svr->delete_me)
- {
- Ecore_Con_Event_Server_Data *e;
- unsigned char *inbuf;
-
- inbuf = malloc(num);
- if(inbuf == NULL)
- return 1;
- memcpy(inbuf, buf, num);
-
- e = calloc(1, sizeof(Ecore_Con_Event_Server_Data));
- if (e)
- {
- svr->event_count++;
- e->server = svr;
- e->data = inbuf;
- e->size = num;
- ecore_event_add(ECORE_CON_EVENT_SERVER_DATA, e,
- _ecore_con_event_server_data_free,
- NULL);
- }
- }
- }
- else
- {
- if ((errno == EIO) || (errno == EBADF) ||
- (errno == EPIPE) || (errno == EINVAL) ||
- (errno == ENOSPC) || (errno == ECONNREFUSED))
- {
- kill_server(svr);
- }
- }
+ unsigned char buf[65536];
+ int num = 0;
+
+ errno = 0;
+ num = read(svr->fd, buf, 65536);
+ if (num > 0)
+ {
+ if (!svr->delete_me)
+ {
+ Ecore_Con_Event_Server_Data *e;
+ unsigned char *inbuf;
+
+ inbuf = malloc(num);
+ if(inbuf == NULL)
+ return 1;
+
+ memcpy(inbuf, buf, num);
+
+ e = calloc(1, sizeof(Ecore_Con_Event_Server_Data));
+ if (e)
+ {
+ svr->event_count++;
+ e->server = svr;
+ e->data = inbuf;
+ e->size = num;
+ ecore_event_add(ECORE_CON_EVENT_SERVER_DATA, e,
+ _ecore_con_event_server_data_free,
+ NULL);
+ }
+ }
+ }
+ else if ((errno == EIO) || (errno == EBADF) ||
+ (errno == EPIPE) || (errno == EINVAL) ||
+ (errno == ENOSPC) || (errno == ECONNREFUSED))
+ kill_server(svr);
}
- else if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_WRITE))
- _ecore_con_server_flush(svr);
+ else if (ecore_main_fd_handler_active_get(fd_handler,
+ ECORE_FD_WRITE))
+ _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_Server *svr;
+ Ecore_Con_Server *svr;
Ecore_Con_Client *cl = NULL;
svr = data;
- if (svr->dead) return ECORE_CALLBACK_RENEW;
- if (svr->delete_me) return ECORE_CALLBACK_RENEW;
+ if (svr->dead)
+ return ECORE_CALLBACK_RENEW;
+
+ if (svr->delete_me)
+ return ECORE_CALLBACK_RENEW;
+
if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ))
{
- unsigned char buf[READBUFSIZ];
- unsigned char client_addr[256];
- unsigned int client_addr_len = sizeof(client_addr);
- int num;
+ unsigned char buf[READBUFSIZ];
+ unsigned char client_addr[256];
+ unsigned int client_addr_len = sizeof(client_addr);
+ int num;
- errno = 0;
+ errno = 0;
#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 = 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);
+
#else
- num = recvfrom(svr->fd, buf, sizeof(buf), MSG_DONTWAIT, (struct sockaddr*) &client_addr, &client_addr_len);
+ num =
+ recvfrom(svr->fd, buf, sizeof(buf), MSG_DONTWAIT,
+ (struct sockaddr *)&client_addr,
+ &client_addr_len);
#endif
- if (num > 0)
- {
- if (!svr->delete_me)
- {
- Ecore_Con_Event_Client_Data *e;
- unsigned char *inbuf;
-
- /* Create a new client for use in the client data event */
- cl = calloc(1, sizeof(Ecore_Con_Client));
- if(cl == NULL)
- return ECORE_CALLBACK_RENEW;
- cl->buf = NULL;
- cl->fd = 0;
- cl->fd_handler = NULL;
- cl->server = svr;
- cl->client_addr = calloc(1, client_addr_len);
- cl->client_addr_len = client_addr_len;
- if(cl->client_addr == NULL)
- {
- free(cl);
- return ECORE_CALLBACK_RENEW;
- }
- memcpy(cl->client_addr, &client_addr, client_addr_len);
- ECORE_MAGIC_SET(cl, ECORE_MAGIC_CON_CLIENT);
- svr->clients = eina_list_append(svr->clients, cl);
-
- cl->ip = _ecore_con_pretty_ip(cl->client_addr, cl->client_addr_len);
-
- inbuf = malloc(num);
- if(inbuf == NULL)
- {
- free(cl->client_addr);
- free(cl);
- return ECORE_CALLBACK_RENEW;
- }
-
- memcpy(inbuf, buf, num);
-
- e = calloc(1, sizeof(Ecore_Con_Event_Client_Data));
- if (e)
- {
- svr->event_count++;
- e->client = cl;
- e->data = inbuf;
- e->size = num;
- ecore_event_add(ECORE_CON_EVENT_CLIENT_DATA, e,
- _ecore_con_event_client_data_free,
- NULL);
- }
-
- if(!cl->delete_me)
- {
- Ecore_Con_Event_Client_Add *add;
-
- add = calloc(1, sizeof(Ecore_Con_Event_Client_Add));
- if(add)
- {
- /*cl->event_count++;*/
- add->client = cl;
- ecore_event_add(ECORE_CON_EVENT_CLIENT_ADD, add,
- _ecore_con_event_client_add_free, NULL);
- }
- }
- }
- }
- else
- {
- if ((errno == EIO) || (errno == EBADF) ||
- (errno == EPIPE) || (errno == EINVAL) ||
- (errno == ENOSPC) || (errno == ECONNREFUSED))
- {
- if (!svr->delete_me)
- {
- /* we lost our client! */
- Ecore_Con_Event_Client_Del *e;
-
- e = calloc(1, sizeof(Ecore_Con_Event_Client_Del));
- if (e)
- {
- svr->event_count++;
- e->client = cl;
- ecore_event_add(ECORE_CON_EVENT_CLIENT_DEL, e,
- _ecore_con_event_client_del_free,
- NULL);
- }
- }
- svr->dead = 1;
- if (svr->fd_handler)
- ecore_main_fd_handler_del(svr->fd_handler);
- svr->fd_handler = NULL;
- }
- }
+ if (num > 0)
+ {
+ if (!svr->delete_me)
+ {
+ Ecore_Con_Event_Client_Data *e;
+ unsigned char *inbuf;
+
+ /* Create a new client for use in the client data event */
+ cl = calloc(1, sizeof(Ecore_Con_Client));
+ if(cl == NULL)
+ return ECORE_CALLBACK_RENEW;
+
+ cl->buf = NULL;
+ cl->fd = 0;
+ cl->fd_handler = NULL;
+ cl->server = svr;
+ cl->client_addr = calloc(1, client_addr_len);
+ cl->client_addr_len = client_addr_len;
+ if(cl->client_addr == NULL)
+ {
+ free(cl);
+ return ECORE_CALLBACK_RENEW;
+ }
+
+ memcpy(cl->client_addr, &client_addr, client_addr_len);
+ ECORE_MAGIC_SET(cl, ECORE_MAGIC_CON_CLIENT);
+ svr->clients = eina_list_append(svr->clients, cl);
+
+ cl->ip = _ecore_con_pretty_ip(cl->client_addr,
+ cl->client_addr_len);
+
+ inbuf = malloc(num);
+ if(inbuf == NULL)
+ {
+ free(cl->client_addr);
+ free(cl);
+ return ECORE_CALLBACK_RENEW;
+ }
+
+ memcpy(inbuf, buf, num);
+
+ e = calloc(1, sizeof(Ecore_Con_Event_Client_Data));
+ if (e)
+ {
+ svr->event_count++;
+ e->client = cl;
+ e->data = inbuf;
+ e->size = num;
+ ecore_event_add(ECORE_CON_EVENT_CLIENT_DATA, e,
+ _ecore_con_event_client_data_free,
+ NULL);
+ }
+
+ if(!cl->delete_me)
+ {
+ Ecore_Con_Event_Client_Add *add;
+
+ add = calloc(1, sizeof(Ecore_Con_Event_Client_Add));
+ if(add)
+ {
+/*cl->event_count++;*/
+ add->client = cl;
+ ecore_event_add(ECORE_CON_EVENT_CLIENT_ADD,
+ add,
+ _ecore_con_event_client_add_free,
+ NULL);
+ }
+ }
+ }
+ }
+ else if ((errno == EIO) || (errno == EBADF) ||
+ (errno == EPIPE) || (errno == EINVAL) ||
+ (errno == ENOSPC) || (errno == ECONNREFUSED))
+ {
+ if (!svr->delete_me)
+ {
+ /* we lost our client! */
+ Ecore_Con_Event_Client_Del *e;
+
+ e = calloc(1, sizeof(Ecore_Con_Event_Client_Del));
+ if (e)
+ {
+ svr->event_count++;
+ e->client = cl;
+ ecore_event_add(ECORE_CON_EVENT_CLIENT_DEL, e,
+ _ecore_con_event_client_del_free,
+ NULL);
+ }
+ }
+
+ svr->dead = 1;
+ if (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);
+ else if (ecore_main_fd_handler_active_get(fd_handler,
+ ECORE_FD_WRITE))
+ _ecore_con_client_flush(cl);
+
return ECORE_CALLBACK_RENEW;
}
static Eina_Bool
_ecore_con_svr_cl_handler(void *data, Ecore_Fd_Handler *fd_handler)
{
- Ecore_Con_Client *cl;
+ Ecore_Con_Client *cl;
cl = data;
- if (cl->dead) return ECORE_CALLBACK_RENEW;
- if (cl->delete_me) return ECORE_CALLBACK_RENEW;
+ if (cl->dead)
+ return ECORE_CALLBACK_RENEW;
+
+ if (cl->delete_me)
+ return ECORE_CALLBACK_RENEW;
+
if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ))
{
- unsigned char *inbuf = NULL;
- int inbuf_num = 0;
- int tries;
+ unsigned char *inbuf = NULL;
+ int inbuf_num = 0;
+ int tries;
- for (tries = 0; tries < 16; tries++)
- {
- int num;
- int lost_client = 1;
- unsigned char buf[READBUFSIZ];
+ for (tries = 0; tries < 16; tries++)
+ {
+ int num;
+ int lost_client = 1;
+ unsigned char buf[READBUFSIZ];
- errno = 0;
+ errno = 0;
- if (!(cl->server->type & ECORE_CON_SSL))
- {
+ if (!(cl->server->type & ECORE_CON_SSL))
+ {
if ((num = read(cl->fd, buf, READBUFSIZ)) <= 0)
+ if ((num < 0) && (errno == EAGAIN))
+ lost_client = 0;
+
+ }
+ else if (!(num =
+ ecore_con_ssl_client_read(cl, buf,
+ READBUFSIZ)))
+ lost_client = 0;
+
+ if (num < 1)
+ {
+ if (inbuf && !cl->delete_me)
+ {
+ Ecore_Con_Event_Client_Data *e;
+
+ e = calloc(1, sizeof(Ecore_Con_Event_Client_Data));
+ if (e)
+ {
+ cl->event_count++;
+ e->client = cl;
+ e->data = inbuf;
+ e->size = inbuf_num;
+ ecore_event_add(ECORE_CON_EVENT_CLIENT_DATA, e,
+ _ecore_con_event_client_data_free,
+ NULL);
+ }
+ }
+
+ if (lost_client)
{
- if ((num < 0) && (errno == EAGAIN))
- lost_client = 0;
+ if (!cl->delete_me)
+ {
+/* we lost our client! */
+ Ecore_Con_Event_Client_Del *e;
+
+ e = calloc(1, sizeof(Ecore_Con_Event_Client_Del));
+ if (e)
+ {
+ cl->event_count++;
+ e->client = cl;
+ ecore_event_add(
+ ECORE_CON_EVENT_CLIENT_DEL,
+ e,
+ _ecore_con_event_client_del_free,
+ NULL);
+ }
+ }
+
+ cl->dead = 1;
+ if (cl->fd_handler)
+ ecore_main_fd_handler_del(cl->fd_handler);
+
+ cl->fd_handler = NULL;
}
- }
- else if (!(num = ecore_con_ssl_client_read(cl, buf, READBUFSIZ)))
- lost_client = 0;
-
- if (num < 1)
- {
- if (inbuf && !cl->delete_me)
- {
- Ecore_Con_Event_Client_Data *e;
-
- e = calloc(1, sizeof(Ecore_Con_Event_Client_Data));
- if (e)
- {
- cl->event_count++;
- e->client = cl;
- e->data = inbuf;
- e->size = inbuf_num;
- ecore_event_add(ECORE_CON_EVENT_CLIENT_DATA, e,
- _ecore_con_event_client_data_free,
- NULL);
- }
- }
-
- if (lost_client)
- {
- if (!cl->delete_me)
- {
- /* we lost our client! */
- Ecore_Con_Event_Client_Del *e;
-
- e = calloc(1, sizeof(Ecore_Con_Event_Client_Del));
- if (e)
- {
- cl->event_count++;
- e->client = cl;
- ecore_event_add(ECORE_CON_EVENT_CLIENT_DEL, e,
- _ecore_con_event_client_del_free,
- NULL);
- }
- }
- cl->dead = 1;
- if (cl->fd_handler)
- ecore_main_fd_handler_del(cl->fd_handler);
- cl->fd_handler = NULL;
- }
- break;
- }
- else
- {
- inbuf = realloc(inbuf, inbuf_num + num);
- memcpy(inbuf + inbuf_num, buf, num);
- inbuf_num += num;
- }
- }
+
+ break;
+ }
+ else
+ {
+ inbuf = realloc(inbuf, inbuf_num + num);
+ memcpy(inbuf + inbuf_num, buf, num);
+ inbuf_num += num;
+ }
+ }
}
- else if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_WRITE))
- _ecore_con_client_flush(cl);
+ else if (ecore_main_fd_handler_active_get(fd_handler,
+ ECORE_FD_WRITE))
+ _ecore_con_client_flush(cl);
+
return ECORE_CALLBACK_RENEW;
}
{
int count, num;
- if (!svr->write_buf) return;
+ if (!svr->write_buf)
+ return;
/* check whether we need to write anything at all.
* we must not write zero bytes with SSL_write() since it
num = svr->write_buf_size - svr->write_buf_offset;
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 < 1)
{
- /* we lost our server! */
- kill_server(svr);
- return;
+ /* we lost our server! */
+ kill_server(svr);
+ return;
}
svr->write_buf_offset += count;
if (svr->write_buf_offset >= svr->write_buf_size)
{
- svr->write_buf_size = 0;
- svr->write_buf_offset = 0;
- free(svr->write_buf);
- svr->write_buf = NULL;
- if (svr->fd_handler)
- ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ);
+ svr->write_buf_size = 0;
+ svr->write_buf_offset = 0;
+ free(svr->write_buf);
+ svr->write_buf = NULL;
+ if (svr->fd_handler)
+ ecore_main_fd_handler_active_set(svr->fd_handler,
+ ECORE_FD_READ);
}
}
{
int count, num;
- if (!cl->buf) return;
+ if (!cl->buf)
+ return;
+
num = cl->buf_size - cl->buf_offset;
if (!(cl->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 < 1)
{
- if ((errno == EIO) || (errno == EBADF) || (errno == EPIPE) ||
- (errno == EINVAL) || (errno == ENOSPC) || (errno == ECONNREFUSED))
- {
- if (!cl->delete_me)
- {
- /* we lost our client! */
- Ecore_Con_Event_Client_Del *e;
-
- e = calloc(1, sizeof(Ecore_Con_Event_Client_Del));
- if (e)
- {
- cl->event_count++;
- e->client = cl;
- ecore_event_add(ECORE_CON_EVENT_CLIENT_DEL, e,
- _ecore_con_event_client_del_free, NULL);
- }
- cl->dead = 1;
- if (cl->fd_handler)
- ecore_main_fd_handler_del(cl->fd_handler);
- cl->fd_handler = NULL;
- }
- }
- return;
+ if ((errno == EIO) || (errno == EBADF) || (errno == EPIPE) ||
+ (errno == EINVAL) || (errno == ENOSPC) || (errno == ECONNREFUSED))
+ if (!cl->delete_me)
+ {
+ /* we lost our client! */
+ Ecore_Con_Event_Client_Del *e;
+
+ e = calloc(1, sizeof(Ecore_Con_Event_Client_Del));
+ if (e)
+ {
+ cl->event_count++;
+ e->client = cl;
+ ecore_event_add(ECORE_CON_EVENT_CLIENT_DEL, e,
+ _ecore_con_event_client_del_free, NULL);
+ }
+
+ cl->dead = 1;
+ if (cl->fd_handler)
+ ecore_main_fd_handler_del(cl->fd_handler);
+
+ cl->fd_handler = NULL;
+ }
+
+ return;
}
+
cl->buf_offset += count;
if (cl->buf_offset >= cl->buf_size)
{
- cl->buf_size = 0;
- cl->buf_offset = 0;
- free(cl->buf);
- cl->buf = NULL;
- if (cl->fd_handler)
- ecore_main_fd_handler_active_set(cl->fd_handler, ECORE_FD_READ);
+ cl->buf_size = 0;
+ cl->buf_offset = 0;
+ free(cl->buf);
+ cl->buf = NULL;
+ if (cl->fd_handler)
+ ecore_main_fd_handler_active_set(cl->fd_handler,
+ ECORE_FD_READ);
}
}
e = ev;
e->client->event_count--;
- if ((e->client->event_count == 0) && (e->client->delete_me))
- ecore_con_client_del(e->client);
+ if ((e->client->event_count == 0) &&
+ (e->client->delete_me))
+ ecore_con_client_del(e->client);
+
free(e);
}
e = ev;
e->client->event_count--;
- if ((e->client->event_count == 0) && (e->client->delete_me))
- ecore_con_client_del(e->client);
- free(e);
+ if ((e->client->event_count == 0) &&
+ (e->client->delete_me))
+ ecore_con_client_del(e->client);
+
+ free(e);
}
static void
e = ev;
e->client->event_count--;
- if (e->data) free(e->data);
+ if (e->data)
+ free(e->data);
+
if (((e->client->event_count == 0) && (e->client->delete_me)) ||
- ((e->client->server && (e->client->server->type == ECORE_CON_REMOTE_UDP ||
- e->client->server->type == ECORE_CON_REMOTE_MCAST))))
- ecore_con_client_del(e->client);
+ ((e->client->server &&
+ (e->client->server->type == ECORE_CON_REMOTE_UDP ||
+ e->client->server->type ==
+ ECORE_CON_REMOTE_MCAST))))
+ ecore_con_client_del(e->client);
+
free(e);
}
e = ev;
e->server->event_count--;
- if ((e->server->event_count == 0) && (e->server->delete_me))
- _ecore_con_server_free(e->server);
+ if ((e->server->event_count == 0) &&
+ (e->server->delete_me))
+ _ecore_con_server_free(e->server);
+
free(e);
}
e = ev;
e->server->event_count--;
- if ((e->server->event_count == 0) && (e->server->delete_me))
- _ecore_con_server_free(e->server);
- free(e);
+ if ((e->server->event_count == 0) &&
+ (e->server->delete_me))
+ _ecore_con_server_free(e->server);
+
+ free(e);
}
static void
e = ev;
e->server->event_count--;
- if (e->data) free(e->data);
- if ((e->server->event_count == 0) && (e->server->delete_me))
- _ecore_con_server_free(e->server);
+ if (e->data)
+ free(e->data);
+
+ if ((e->server->event_count == 0) &&
+ (e->server->delete_me))
+ _ecore_con_server_free(e->server);
+
free(e);
}
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);
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, Ecore_Fd_Handler *fd_handler);
+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);
+static void _ecore_con_info_cares_clean(void);
int
ecore_con_info_init(void)
{
if (info_init == 0)
{
- if (ares_library_init(ARES_LIB_INIT_ALL) != 0)
- return 0;
- if (ares_init(&info_channel) != ARES_SUCCESS)
- {
- ares_library_cleanup();
- return 0;
- }
+ if (ares_library_init(ARES_LIB_INIT_ALL) != 0)
+ return 0;
+
+ if (ares_init(&info_channel) != ARES_SUCCESS)
+ {
+ ares_library_cleanup();
+ return 0;
+ }
}
info_init++;
info_init--;
if (info_init == 0)
{
- /* Cancel all ongoing request */
- ares_cancel(info_channel);
- ares_destroy(info_channel);
+ /* Cancel all ongoing request */
+ 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;
}
int
ecore_con_info_tcp_connect(Ecore_Con_Server *svr,
- Ecore_Con_Info_Cb done_cb,
- void *data)
+ Ecore_Con_Info_Cb done_cb,
+ void *data)
{
struct addrinfo hints;
int
ecore_con_info_tcp_listen(Ecore_Con_Server *svr,
- Ecore_Con_Info_Cb done_cb,
- void *data)
+ Ecore_Con_Info_Cb done_cb,
+ void *data)
{
struct addrinfo hints;
int
ecore_con_info_udp_connect(Ecore_Con_Server *svr,
- Ecore_Con_Info_Cb done_cb,
- void *data)
+ Ecore_Con_Info_Cb done_cb,
+ void *data)
{
struct addrinfo hints;
int
ecore_con_info_udp_listen(Ecore_Con_Server *svr,
- Ecore_Con_Info_Cb done_cb,
- void *data)
+ Ecore_Con_Info_Cb done_cb,
+ void *data)
{
struct addrinfo hints;
int
ecore_con_info_mcast_listen(Ecore_Con_Server *svr,
- Ecore_Con_Info_Cb done_cb,
- void *data)
+ Ecore_Con_Info_Cb done_cb,
+ void *data)
{
struct addrinfo hints;
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;
arg->result->info.ai_family = addrtype;
arg->result->info.ai_addrlen = addrlen;
arg->result->info.ai_addr = addr;
- arg->result->info.ai_canonname = (char*) (arg->result + 1);
+ 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);
+ 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);
return EINA_TRUE;
}
EAPI int
ecore_con_info_get(Ecore_Con_Server *svr,
- Ecore_Con_Info_Cb done_cb,
- void *data,
- struct addrinfo *hints)
+ Ecore_Con_Info_Cb done_cb,
+ 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;
+ if (!cares)
+ return 0;
cares->svr = svr;
cares->done_cb = done_cb;
if (hints)
{
- ai_family = hints->ai_family;
- memcpy(&cares->hints, hints, sizeof (struct addrinfo));
+ ai_family = hints->ai_family;
+ memcpy(&cares->hints, hints, sizeof (struct addrinfo));
}
if (inet_pton(AF_INET, svr->name, &cares->addr.v4) == 1)
{
- cares->byaddr = EINA_TRUE;
- cares->isv6 = EINA_FALSE;
- ares_gethostbyaddr(info_channel, &cares->addr.v4, sizeof (cares->addr.v4), AF_INET, (ares_host_callback) _ecore_con_info_ares_host_cb, cares);
+ cares->byaddr = EINA_TRUE;
+ cares->isv6 = EINA_FALSE;
+ ares_gethostbyaddr(info_channel, &cares->addr.v4,
+ sizeof (cares->addr.v4),
+ AF_INET,
+ (ares_host_callback)_ecore_con_info_ares_host_cb,
+ cares);
}
else if (inet_pton(AF_INET6, svr->name, &cares->addr.v6) == 1)
{
- cares->byaddr = EINA_TRUE;
- cares->isv6 = EINA_TRUE;
- ares_gethostbyaddr(info_channel, &cares->addr.v6, sizeof (cares->addr.v6), AF_INET6, (ares_host_callback) _ecore_con_info_ares_host_cb, cares);
+ cares->byaddr = EINA_TRUE;
+ cares->isv6 = EINA_TRUE;
+ ares_gethostbyaddr(info_channel, &cares->addr.v6,
+ sizeof (cares->addr.v6),
+ AF_INET6,
+ (ares_host_callback)_ecore_con_info_ares_host_cb,
+ cares);
}
else
{
- cares->byaddr = EINA_FALSE;
- ares_gethostbyname(info_channel, svr->name, ai_family, (ares_host_callback) _ecore_con_info_ares_host_cb, cares);
+ cares->byaddr = EINA_FALSE;
+ ares_gethostbyname(info_channel, svr->name, ai_family,
+ (ares_host_callback)_ecore_con_info_ares_host_cb,
+ cares);
}
_ecore_con_info_cares_clean();
fdl.fd = fd;
- search = eina_list_search_unsorted(info_fds, (Eina_Compare_Cb) _ecore_con_info_fds_search, &fdl);
+ search = eina_list_search_unsorted(
+ info_fds, (Eina_Compare_Cb)_ecore_con_info_fds_search, &fdl);
if (search)
{
- search->active = active;
- return EINA_TRUE;
+ search->active = active;
+ return EINA_TRUE;
}
+
return EINA_FALSE;
}
active++;
for (i = 0; i < nfds; ++i)
{
- int flags = 0;
-
- if (FD_ISSET(i, &readers)) flags |= ECORE_FD_READ;
- if (FD_ISSET(i, &writers)) 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);
- }
- }
- }
+ int flags = 0;
+
+ if (FD_ISSET(i, &readers))
+ flags |= ECORE_FD_READ;
+
+ if (FD_ISSET(i, &writers))
+ 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);
+ }
+ }
+
}
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);
- tm = NULL;
+ if (tm)
+ ecore_timer_del(tm);
+
+ tm = NULL;
}
else
{
- struct timeval tv;
+ struct timeval tv;
- ares_timeout(info_channel, NULL, &tv);
+ ares_timeout(info_channel, NULL, &tv);
- if (tm)
- ecore_timer_delay(tm, tv.tv_sec);
- else
- tm = ecore_timer_add((double) tv.tv_sec, _ecore_con_info_cares_timeout_cb, NULL);
+ if (tm)
+ ecore_timer_delay(tm, tv.tv_sec);
+ else
+ tm =
+ ecore_timer_add((double)tv.tv_sec,
+ _ecore_con_info_cares_timeout_cb,
+ NULL);
}
}
}
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;
switch (status)
{
case ARES_SUCCESS:
- if (hostent->h_addr_list[0] == NULL)
- {
- fprintf(stderr, "No IP found\n");
- goto on_error;
- }
-
- switch (hostent->h_addrtype)
- {
- case AF_INET:
- {
- 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;
- }
- 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;
- }
-
- if (!_ecore_con_info_ares_getnameinfo(arg, hostent->h_addrtype, hostent->h_name,
- addr, addrlen))
- goto on_error;
- break;
+ if (hostent->h_addr_list[0] == NULL)
+ {
+ fprintf(stderr, "No IP found\n");
+ goto on_error;
+ }
+
+ switch (hostent->h_addrtype)
+ {
+ case AF_INET:
+ {
+ 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;
+ }
+
+ 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;
+ }
+
+ 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->isv6)
- {
- struct sockaddr_in6 *addri6;
+ if (arg->byaddr)
+ {
+ /* This happen when host doesn't have a reverse. */
+ if (arg->isv6)
+ {
+ struct sockaddr_in6 *addri6;
+
+ addrlen = sizeof (struct sockaddr_in6);
+ addri6 = malloc(addrlen);
+
+ if (!addri6)
+ goto on_mem_error;
- addrlen = sizeof (struct sockaddr_in6);
- addri6 = malloc(addrlen);
+ addri6->sin6_family = AF_INET6;
+ addri6->sin6_port = htons(arg->svr->port);
+ addri6->sin6_flowinfo = 0;
+ addri6->sin6_scope_id = 0;
- if (!addri6) goto on_mem_error;
+ memcpy(&addri6->sin6_addr.s6_addr,
+ &arg->addr.v6, sizeof (struct in6_addr));
- addri6->sin6_family = AF_INET6;
- addri6->sin6_port = htons(arg->svr->port);
- addri6->sin6_flowinfo = 0;
- addri6->sin6_scope_id = 0;
+ addr = (struct sockaddr *)addri6;
+ }
+ else
+ {
+ struct sockaddr_in *addri;
- memcpy(&addri6->sin6_addr.s6_addr,
- &arg->addr.v6, sizeof (struct in6_addr));
+ addrlen = sizeof (struct sockaddr_in);
+ addri = malloc(addrlen);
- addr = (struct sockaddr*) addri6;
- }
- else
- {
- struct sockaddr_in *addri;
+ if (!addri)
+ goto on_mem_error;
- addrlen = sizeof (struct sockaddr_in);
- addri = malloc(addrlen);
+ addri->sin_family = AF_INET;
+ addri->sin_port = htons(arg->svr->port);
- if (!addri) goto on_mem_error;
+ memcpy(&addri->sin_addr.s_addr,
+ &arg->addr.v4, sizeof (struct in_addr));
- addri->sin_family = AF_INET;
- addri->sin_port = htons(arg->svr->port);
+ addr = (struct sockaddr *)addri;
+ }
- memcpy(&addri->sin_addr.s_addr,
- &arg->addr.v4, sizeof (struct in_addr));
+ if (!_ecore_con_info_ares_getnameinfo(arg,
+ arg->isv6 ? AF_INET6 :
+ AF_INET,
+ NULL, addr,
+ addrlen))
+ goto on_error;
- addr = (struct sockaddr*) addri;
- }
+ break;
+ }
- if (!_ecore_con_info_ares_getnameinfo(arg, arg->isv6 ? AF_INET6 : AF_INET,
- NULL, addr, addrlen))
- 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 ;
+ return;
- on_mem_error:
- fprintf(stderr, "Not enough memory\n");
+on_mem_error:
+ fprintf(stderr, "Not enough memory\n");
- on_error:
+on_error:
arg->done_cb(arg->data, NULL);
free(arg);
}
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 (service) strcpy(arg->result->service, service);
- else *arg->result->service = '\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';
+
+ 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);
};
-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, Ecore_Fd_Handler *fd_handler);
-static Eina_Bool _ecore_con_info_exit_handler(void *data, int type __UNUSED__, void *event);
+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,
+ Ecore_Fd_Handler *fd_handler);
+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;
{
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;
}
int
ecore_con_info_tcp_connect(Ecore_Con_Server *svr,
- Ecore_Con_Info_Cb done_cb,
- void *data)
+ Ecore_Con_Info_Cb done_cb,
+ void *data)
{
struct addrinfo hints;
int
ecore_con_info_tcp_listen(Ecore_Con_Server *svr,
- Ecore_Con_Info_Cb done_cb,
- void *data)
+ Ecore_Con_Info_Cb done_cb,
+ void *data)
{
struct addrinfo hints;
int
ecore_con_info_udp_connect(Ecore_Con_Server *svr,
- Ecore_Con_Info_Cb done_cb,
- void *data)
+ Ecore_Con_Info_Cb done_cb,
+ void *data)
{
struct addrinfo hints;
int
ecore_con_info_udp_listen(Ecore_Con_Server *svr,
- Ecore_Con_Info_Cb done_cb,
- void *data)
+ Ecore_Con_Info_Cb done_cb,
+ void *data)
{
struct addrinfo hints;
int
ecore_con_info_mcast_listen(Ecore_Con_Server *svr,
- Ecore_Con_Info_Cb done_cb,
- void *data)
+ Ecore_Con_Info_Cb done_cb,
+ void *data)
{
struct addrinfo hints;
EAPI int
ecore_con_info_get(Ecore_Con_Server *svr,
- Ecore_Con_Info_Cb done_cb,
- void *data,
- struct addrinfo *hints)
+ Ecore_Con_Info_Cb done_cb,
+ void *data,
+ struct addrinfo *hints)
{
CB_Data *cbdata;
int fd[2];
- if (pipe(fd) < 0) return 0;
+ if (pipe(fd) < 0)
+ return 0;
+
cbdata = calloc(1, sizeof(CB_Data));
if (!cbdata)
{
- close(fd[0]);
- close(fd[1]);
- return 0;
+ close(fd[0]);
+ close(fd[1]);
+ return 0;
}
+
cbdata->cb_done = done_cb;
cbdata->data = data;
cbdata->fd2 = fd[1];
if (!(cbdata->fdh = ecore_main_fd_handler_add(fd[0], ECORE_FD_READ,
- _ecore_con_info_data_handler,
- cbdata,
- NULL, NULL)))
+ _ecore_con_info_data_handler,
+ cbdata,
+ NULL, NULL)))
{
- free(cbdata);
- close(fd[0]);
- close(fd[1]);
- return 0;
+ free(cbdata);
+ close(fd[0]);
+ close(fd[1]);
+ return 0;
}
if ((cbdata->pid = fork()) == 0)
{
Ecore_Con_Info *container;
- struct addrinfo *result = NULL;
- char service[NI_MAXSERV];
- char hbuf[NI_MAXHOST];
- char sbuf[NI_MAXSERV];
- void *tosend = NULL;
- int tosend_len;
- int canonname_len = 0;
- int err;
-
- eina_convert_itoa(svr->port, service);
- /* CHILD */
- if (!getaddrinfo(svr->name, service, hints, &result) && result)
- {
- if (result->ai_canonname)
- canonname_len = strlen(result->ai_canonname) + 1;
- tosend_len = sizeof(Ecore_Con_Info) + result->ai_addrlen + canonname_len;
-
- if (!(tosend = alloca(tosend_len)))
- goto on_error;
-
- container = (Ecore_Con_Info *)tosend;
-
- container->size = tosend_len;
-
- memcpy(&container->info, result, sizeof(struct addrinfo));
- memcpy((char *)tosend + sizeof(Ecore_Con_Info), result->ai_addr, result->ai_addrlen);
- memcpy((char *)tosend + sizeof(Ecore_Con_Info) + result->ai_addrlen, result->ai_canonname, canonname_len);
-
- if (!getnameinfo(result->ai_addr, result->ai_addrlen,
- hbuf, sizeof(hbuf), sbuf, sizeof(sbuf),
- NI_NUMERICHOST | NI_NUMERICSERV))
- {
- memcpy(container->ip, hbuf, sizeof(container->ip));
- memcpy(container->service, sbuf, sizeof(container->service));
- }
- err = write(fd[1], tosend, tosend_len);
- }
+ struct addrinfo *result = NULL;
+ char service[NI_MAXSERV];
+ char hbuf[NI_MAXHOST];
+ char sbuf[NI_MAXSERV];
+ void *tosend = NULL;
+ int tosend_len;
+ int canonname_len = 0;
+ int err;
+
+ eina_convert_itoa(svr->port, service);
+ /* CHILD */
+ if (!getaddrinfo(svr->name, service, hints, &result) && result)
+ {
+ if (result->ai_canonname)
+ canonname_len =
+ strlen(result->ai_canonname) + 1;
+
+ tosend_len = sizeof(Ecore_Con_Info) + result->ai_addrlen +
+ canonname_len;
+
+ if (!(tosend = alloca(tosend_len)))
+ goto on_error;
+
+ container = (Ecore_Con_Info *)tosend;
+
+ container->size = tosend_len;
+
+ memcpy(&container->info,
+ result,
+ sizeof(struct addrinfo));
+ memcpy((char *)tosend + sizeof(Ecore_Con_Info),
+ result->ai_addr,
+ result->ai_addrlen);
+ memcpy(
+ (char *)tosend + sizeof(Ecore_Con_Info) + result->ai_addrlen,
+ result->ai_canonname,
+ canonname_len);
+
+ if (!getnameinfo(result->ai_addr, result->ai_addrlen,
+ hbuf, sizeof(hbuf), sbuf, sizeof(sbuf),
+ NI_NUMERICHOST | NI_NUMERICSERV))
+ {
+ memcpy(container->ip, hbuf, sizeof(container->ip));
+ memcpy(container->service, sbuf, sizeof(container->service));
+ }
+
+ err = write(fd[1], tosend, tosend_len);
+ }
on_error:
- if (result)
- freeaddrinfo(result);
- err = write(fd[1], "", 1);
- close(fd[1]);
+ if (result)
+ freeaddrinfo(result);
+
+ err = write(fd[1], "", 1);
+ close(fd[1]);
# ifdef __USE_ISOC99
- _Exit(0);
+ _Exit(0);
# else
- _exit(0);
+ _exit(0);
# endif
}
+
/* PARENT */
- cbdata->handler = ecore_event_handler_add(ECORE_EXE_EVENT_DEL, _ecore_con_info_exit_handler, cbdata);
+ cbdata->handler =
+ ecore_event_handler_add(ECORE_EXE_EVENT_DEL, _ecore_con_info_exit_handler,
+ cbdata);
close(fd[1]);
if (!cbdata->handler)
{
- ecore_main_fd_handler_del(cbdata->fdh);
- free(cbdata);
- close(fd[0]);
- return 0;
+ ecore_main_fd_handler_del(cbdata->fdh);
+ free(cbdata);
+ close(fd[0]);
+ return 0;
}
- info_slaves = (CB_Data *) eina_inlist_append(EINA_INLIST_GET(info_slaves), EINA_INLIST_GET(cbdata));
+
+ info_slaves = (CB_Data *)eina_inlist_append(EINA_INLIST_GET(
+ info_slaves),
+ EINA_INLIST_GET(cbdata));
return 1;
}
ssize_t size;
size = read(ecore_main_fd_handler_fd_get(cbdata->fdh), &container,
- sizeof(Ecore_Con_Info));
+ sizeof(Ecore_Con_Info));
if (size == sizeof(Ecore_Con_Info))
{
torecv_len = container.size;
- torecv = malloc(torecv_len);
-
- memcpy(torecv, &container, sizeof(Ecore_Con_Info));
-
- size = read(ecore_main_fd_handler_fd_get(cbdata->fdh), (char *)torecv + sizeof(Ecore_Con_Info),
- torecv_len - sizeof(Ecore_Con_Info));
- if ((size > 0) && ((size_t)size == torecv_len - sizeof(Ecore_Con_Info)))
- {
- recv = (Ecore_Con_Info *)torecv;
-
- recv->info.ai_addr = (struct sockaddr *)((char *)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;
- else
- recv->info.ai_canonname = NULL;
- recv->info.ai_next = NULL;
-
- cbdata->cb_done(cbdata->data, recv);
-
- free(torecv);
- }
- else
- cbdata->cb_done(cbdata->data, NULL);
+ torecv = malloc(torecv_len);
+
+ memcpy(torecv, &container, sizeof(Ecore_Con_Info));
+
+ size = read(ecore_main_fd_handler_fd_get(
+ cbdata->fdh), (char *)torecv + sizeof(Ecore_Con_Info),
+ torecv_len - sizeof(Ecore_Con_Info));
+ if ((size > 0) && ((size_t)size == torecv_len - sizeof(Ecore_Con_Info)))
+ {
+ recv = (Ecore_Con_Info *)torecv;
+
+ recv->info.ai_addr =
+ (struct sockaddr *)((char *)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;
+ else
+ recv->info.ai_canonname = NULL;
+
+ recv->info.ai_next = NULL;
+
+ cbdata->cb_done(cbdata->data, recv);
+
+ free(torecv);
+ }
+ else
+ cbdata->cb_done(cbdata->data, NULL);
}
else
- cbdata->cb_done(cbdata->data, NULL);
+ cbdata->cb_done(cbdata->data, NULL);
+
cbdata->cb_done = NULL;
}
static void
_ecore_con_info_slave_free(CB_Data *cbdata)
{
- info_slaves = (CB_Data *) eina_inlist_remove(EINA_INLIST_GET(info_slaves), EINA_INLIST_GET(cbdata));
+ info_slaves = (CB_Data *)eina_inlist_remove(EINA_INLIST_GET(
+ info_slaves),
+ EINA_INLIST_GET(cbdata));
close(ecore_main_fd_handler_fd_get(cbdata->fdh));
ecore_main_fd_handler_del(cbdata->fdh);
ecore_event_handler_del(cbdata->handler);
cbdata = data;
if (cbdata->cb_done)
{
- if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ))
- _ecore_con_info_readdata(cbdata);
- else
- {
- cbdata->cb_done(cbdata->data, NULL);
- cbdata->cb_done = NULL;
- }
+ if (ecore_main_fd_handler_active_get(fd_handler,
+ ECORE_FD_READ))
+ _ecore_con_info_readdata(cbdata);
+ else
+ {
+ cbdata->cb_done(cbdata->data, NULL);
+ cbdata->cb_done = NULL;
+ }
}
+
_ecore_con_info_slave_free(cbdata);
return ECORE_CALLBACK_CANCEL;
}
ev = event;
cbdata = data;
- if (cbdata->pid != ev->pid) return ECORE_CALLBACK_RENEW;
+ if (cbdata->pid != ev->pid)
+ return ECORE_CALLBACK_RENEW;
+
return ECORE_CALLBACK_CANCEL; /* FIXME: Woot ??? */
_ecore_con_info_slave_free(cbdata);
return ECORE_CALLBACK_CANCEL;
#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 + (size_t)(((struct sockaddr_un *)NULL)->sun_path))
+#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;
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;
}
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))
+ Eina_Bool (*cb_done)(void *data,
+ Ecore_Fd_Handler *fd_handler),
+ void *data __UNUSED__,
+ void (*cb_free)(void *data, void *ev))
{
- char buf[4096];
+ char buf[4096];
struct sockaddr_un socket_unix;
- int curstate = 0;
- const char *homedir;
- int socket_unix_len;
+ int curstate = 0;
+ const char *homedir;
+ int socket_unix_len;
if (svr->type == ECORE_CON_LOCAL_USER)
{
- homedir = getenv("HOME");
- if (!homedir) homedir = getenv("TMP");
- if (!homedir) homedir = "/tmp";
- snprintf(buf, sizeof(buf), "%s/.ecore/%s/%i", homedir, svr->name, svr->port);
+ homedir = getenv("HOME");
+ if (!homedir)
+ homedir = getenv("TMP");
+
+ if (!homedir)
+ homedir = "/tmp";
+
+ snprintf(buf, sizeof(buf), "%s/.ecore/%s/%i", homedir, svr->name,
+ svr->port);
}
else if (svr->type == ECORE_CON_LOCAL_SYSTEM)
{
- if (svr->port < 0)
- {
- if (svr->name[0] == '/')
- strncpy(buf, svr->name, sizeof(buf));
- else
- 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);
- else
- snprintf(buf, sizeof(buf), "/tmp/.ecore_service|%s|%i", svr->name, svr->port);
- }
+ if (svr->port < 0)
+ {
+ if (svr->name[0] == '/')
+ strncpy(buf, svr->name, sizeof(buf));
+ else
+ 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);
+ else
+ snprintf(buf, sizeof(buf), "/tmp/.ecore_service|%s|%i",
+ svr->name,
+ svr->port);
+ }
}
else if (svr->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;
- if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) return 0;
- if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) return 0;
- if (setsockopt(svr->fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&curstate, sizeof(curstate)) < 0) return 0;
+ if (svr->fd < 0)
+ return 0;
+
+ if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0)
+ return 0;
+
+ if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0)
+ return 0;
+
+ if (setsockopt(svr->fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&curstate,
+ sizeof(curstate)) < 0)
+ return 0;
+
socket_unix.sun_family = AF_UNIX;
if (svr->type == ECORE_CON_LOCAL_ABSTRACT)
{
#ifdef HAVE_ABSTRACT_SOCKETS
- /* copy name insto sun_path, prefixed by null to indicate abstract namespace */
- snprintf(socket_unix.sun_path, sizeof(socket_unix.sun_path), ".%s", svr->name);
- socket_unix.sun_path[0] = '\0';
- socket_unix_len = LENGTH_OF_ABSTRACT_SOCKADDR_UN(&socket_unix, svr->name);
+ /* copy name insto sun_path, prefixed by null to indicate abstract namespace */
+ snprintf(socket_unix.sun_path, sizeof(socket_unix.sun_path), ".%s",
+ svr->name);
+ socket_unix.sun_path[0] = '\0';
+ socket_unix_len = LENGTH_OF_ABSTRACT_SOCKADDR_UN(&socket_unix,
+ svr->name);
#else
- WRN("Your system does not support abstract sockets!");
- return 0;
+ WRN("Your system does not support abstract sockets!");
+ return 0;
#endif
}
else
{
- strncpy(socket_unix.sun_path, buf, sizeof(socket_unix.sun_path));
- socket_unix_len = LENGTH_OF_SOCKADDR_UN(&socket_unix);
+ strncpy(socket_unix.sun_path, buf, sizeof(socket_unix.sun_path));
+ socket_unix_len = LENGTH_OF_SOCKADDR_UN(&socket_unix);
}
- if (connect(svr->fd, (struct sockaddr *)&socket_unix, socket_unix_len) < 0)
- return 0;
+ if (connect(svr->fd, (struct sockaddr *)&socket_unix,
+ socket_unix_len) < 0)
+ return 0;
+
svr->path = strdup(buf);
- if (!svr->path) return 0;
+ if (!svr->path)
+ 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);
- if (!svr->fd_handler) return 0;
+ ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ,
+ cb_done, svr, NULL, NULL);
+ if (!svr->fd_handler)
+ return 0;
if (!svr->delete_me)
{
- /* we got our server! */
- 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);
- }
+ /* we got our server! */
+ 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);
+ }
}
return 1;
}
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_local_listen(
+ Ecore_Con_Server *svr,
+ Eina_Bool (*
+ cb_listen)(void *data,
+ Ecore_Fd_Handler *
+ fd_handler),
+ void *data
+ __UNUSED__)
{
- char buf[4096];
+ char buf[4096];
struct sockaddr_un socket_unix;
- struct linger lin;
- mode_t pmode;
- const char *homedir;
- struct stat st;
- mode_t mask;
- int socket_unix_len;
+ struct linger lin;
+ mode_t pmode;
+ const char *homedir;
+ struct stat st;
+ mode_t mask;
+ int socket_unix_len;
mask = S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH;
if (svr->type == ECORE_CON_LOCAL_USER)
{
- homedir = getenv("HOME");
- if (!homedir) homedir = getenv("TMP");
- if (!homedir) homedir = "/tmp";
- mask = S_IRUSR | S_IWUSR | S_IXUSR;
- snprintf(buf, sizeof(buf), "%s/.ecore", homedir);
- if (stat(buf, &st) < 0) mkdir(buf, mask);
- snprintf(buf, sizeof(buf), "%s/.ecore/%s", homedir, svr->name);
- if (stat(buf, &st) < 0) mkdir(buf, mask);
- snprintf(buf, sizeof(buf), "%s/.ecore/%s/%i", homedir, svr->name, svr->port);
- mask = S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH;
+ homedir = getenv("HOME");
+ if (!homedir)
+ homedir = getenv("TMP");
+
+ if (!homedir)
+ homedir = "/tmp";
+
+ mask = S_IRUSR | S_IWUSR | S_IXUSR;
+ snprintf(buf, sizeof(buf), "%s/.ecore", homedir);
+ if (stat(buf, &st) < 0)
+ mkdir(buf, mask);
+
+ snprintf(buf, sizeof(buf), "%s/.ecore/%s", homedir, svr->name);
+ if (stat(buf, &st) < 0)
+ mkdir(buf, mask);
+
+ snprintf(buf,
+ sizeof(buf),
+ "%s/.ecore/%s/%i",
+ homedir,
+ svr->name,
+ svr->port);
+ mask = S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH;
}
else if (svr->type == ECORE_CON_LOCAL_SYSTEM)
{
- mask = 0;
- if (svr->name[0] == '/')
- {
- if (svr->port >= 0)
- snprintf(buf, sizeof(buf), "%s|%i", svr->name, svr->port);
- else
- snprintf(buf, sizeof(buf), "%s", svr->name);
- }
- else
- snprintf(buf, sizeof(buf), "/tmp/.ecore_service|%s|%i", svr->name, svr->port);
+ mask = 0;
+ if (svr->name[0] == '/')
+ {
+ if (svr->port >= 0)
+ snprintf(buf,
+ sizeof(buf),
+ "%s|%i",
+ svr->name,
+ svr->port);
+ else
+ snprintf(buf,
+ sizeof(buf),
+ "%s",
+ svr->name);
+ }
+ else
+ snprintf(buf,
+ sizeof(buf),
+ "/tmp/.ecore_service|%s|%i",
+ svr->name,
+ svr->port);
}
else if (svr->type == ECORE_CON_LOCAL_ABSTRACT)
- strncpy(buf, svr->name, sizeof(buf));
+ strncpy(buf, svr->name,
+ sizeof(buf));
+
pmode = umask(mask);
- start:
+start:
svr->fd = socket(AF_UNIX, SOCK_STREAM, 0);
- if (svr->fd < 0) goto error_umask;
- if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error_umask;
- if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error_umask;
+ if (svr->fd < 0)
+ goto error_umask;
+
+ if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0)
+ goto error_umask;
+
+ if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0)
+ goto error_umask;
+
lin.l_onoff = 1;
lin.l_linger = 0;
- if (setsockopt(svr->fd, SOL_SOCKET, SO_LINGER, (const void *)&lin, sizeof(struct linger)) < 0) goto error_umask;
+ if (setsockopt(svr->fd, SOL_SOCKET, SO_LINGER, (const void *)&lin,
+ sizeof(struct linger)) < 0)
+ goto error_umask;
+
socket_unix.sun_family = AF_UNIX;
if (svr->type == ECORE_CON_LOCAL_ABSTRACT)
{
#ifdef HAVE_ABSTRACT_SOCKETS
- /* . is a placeholder */
- snprintf(socket_unix.sun_path, sizeof(socket_unix.sun_path), ".%s", svr->name);
- /* first char null indicates abstract namespace */
- socket_unix.sun_path[0] = '\0';
- socket_unix_len = LENGTH_OF_ABSTRACT_SOCKADDR_UN(&socket_unix, svr->name);
+ /* . is a placeholder */
+ snprintf(socket_unix.sun_path, sizeof(socket_unix.sun_path), ".%s",
+ svr->name);
+ /* first char null indicates abstract namespace */
+ socket_unix.sun_path[0] = '\0';
+ socket_unix_len = LENGTH_OF_ABSTRACT_SOCKADDR_UN(&socket_unix,
+ svr->name);
#else
- ERR("Your system does not support abstract sockets!");
- goto error_umask;
+ ERR("Your system does not support abstract sockets!");
+ goto error_umask;
#endif
}
else
{
- strncpy(socket_unix.sun_path, buf, sizeof(socket_unix.sun_path));
- socket_unix_len = LENGTH_OF_SOCKADDR_UN(&socket_unix);
+ strncpy(socket_unix.sun_path, buf, sizeof(socket_unix.sun_path));
+ socket_unix_len = LENGTH_OF_SOCKADDR_UN(&socket_unix);
}
+
if (bind(svr->fd, (struct sockaddr *)&socket_unix, socket_unix_len) < 0)
{
- if (((svr->type == ECORE_CON_LOCAL_USER) || (svr->type == ECORE_CON_LOCAL_SYSTEM)) &&
- (connect(svr->fd, (struct sockaddr *)&socket_unix, socket_unix_len) < 0) &&
- (unlink(buf) >= 0))
- goto start;
- else
- goto error_umask;
+ if (((svr->type == ECORE_CON_LOCAL_USER) ||
+ (svr->type == ECORE_CON_LOCAL_SYSTEM)) &&
+ (connect(svr->fd, (struct sockaddr *)&socket_unix,
+ socket_unix_len) < 0) &&
+ (unlink(buf) >= 0))
+ goto start;
+ else
+ goto error_umask;
}
- if (listen(svr->fd, 4096) < 0) goto error_umask;
+
+ if (listen(svr->fd, 4096) < 0)
+ goto error_umask;
+
svr->path = strdup(buf);
- if (!svr->path) goto error_umask;
+ if (!svr->path)
+ 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;
+ if (!svr->fd_handler)
+ goto error;
return 1;
- error_umask:
+error_umask:
umask(pmode);
- error:
+error:
return 0;
}
#define READBUFSIZ 65536
-extern int _ecore_con_log_dom ;
+extern int _ecore_con_log_dom;
#ifdef ECORE_CON_DEFAULT_LOG_COLOR
#undef ECORE_LOG_DEFAULT_LOG_COLOR
typedef void (*Ecore_Con_Info_Cb)(void *data, Ecore_Con_Info *infos);
typedef enum _Ecore_Con_State
- {
- ECORE_CON_CONNECTED,
- ECORE_CON_DISCONNECTED,
- ECORE_CON_INPROGRESS
- } Ecore_Con_State;
+{
+ ECORE_CON_CONNECTED,
+ ECORE_CON_DISCONNECTED,
+ ECORE_CON_INPROGRESS
+} Ecore_Con_State;
typedef enum _Ecore_Con_Ssl_Error
- {
- ECORE_CON_SSL_ERROR_NONE = 0,
- ECORE_CON_SSL_ERROR_NOT_SUPPORTED,
- ECORE_CON_SSL_ERROR_INIT_FAILED,
- ECORE_CON_SSL_ERROR_SERVER_INIT_FAILED,
- ECORE_CON_SSL_ERROR_SSL2_NOT_SUPPORTED
- } Ecore_Con_Ssl_Error;
+{
+ ECORE_CON_SSL_ERROR_NONE = 0,
+ ECORE_CON_SSL_ERROR_NOT_SUPPORTED,
+ ECORE_CON_SSL_ERROR_INIT_FAILED,
+ ECORE_CON_SSL_ERROR_SERVER_INIT_FAILED,
+ ECORE_CON_SSL_ERROR_SSL2_NOT_SUPPORTED
+} Ecore_Con_Ssl_Error;
struct _Ecore_Con_Client
{
ECORE_MAGIC;
- int fd;
+ int fd;
Ecore_Con_Server *server;
- void *data;
+ void *data;
Ecore_Fd_Handler *fd_handler;
- int buf_size;
- int buf_offset;
- unsigned char *buf;
- char *ip;
- int event_count;
- struct sockaddr *client_addr;
- int client_addr_len;
+ int buf_size;
+ int buf_offset;
+ unsigned char *buf;
+ char *ip;
+ int event_count;
+ struct sockaddr *client_addr;
+ int client_addr_len;
#if USE_GNUTLS
- gnutls_session session;
+ gnutls_session session;
#elif USE_OPENSSL
- SSL_CTX *ssl_ctx;
- SSL *ssl;
- int ssl_err;
+ SSL_CTX *ssl_ctx;
+ SSL *ssl;
+ int ssl_err;
#endif
- char dead : 1;
- char delete_me : 1;
+ char dead : 1;
+ char delete_me : 1;
};
struct _Ecore_Con_Server
{
ECORE_MAGIC;
- int fd;
- Ecore_Con_Type type;
- char *name;
- int port;
- char *path;
- void *data;
+ int fd;
+ Ecore_Con_Type type;
+ char *name;
+ int port;
+ char *path;
+ void *data;
Ecore_Fd_Handler *fd_handler;
- Eina_List *clients;
- int write_buf_size;
- int write_buf_offset;
- unsigned char *write_buf;
- int event_count;
- int client_limit;
- pid_t ppid;
+ Eina_List *clients;
+ int write_buf_size;
+ int write_buf_offset;
+ unsigned char *write_buf;
+ int event_count;
+ int client_limit;
+ pid_t ppid;
#if USE_GNUTLS
- gnutls_session session;
+ gnutls_session session;
gnutls_anon_client_credentials_t anoncred_c;
gnutls_anon_server_credentials_t anoncred_s;
+ gnutls_certificate_credentials_t cert;
#elif USE_OPENSSL
- SSL_CTX *ssl_ctx;
- SSL *ssl;
- int ssl_err;
+ SSL_CTX *ssl_ctx;
+ SSL *ssl;
+ int ssl_err;
#endif
- char *ip;
- char dead : 1;
- char created : 1;
- char connecting : 1;
- char reject_excess_clients : 1;
- char delete_me : 1;
+ char *ip;
+ char dead : 1;
+ char created : 1;
+ char connecting : 1;
+ char reject_excess_clients : 1;
+ char delete_me : 1;
};
#ifdef HAVE_CURL
struct _Ecore_Con_Url
{
ECORE_MAGIC;
- CURL *curl_easy;
+ CURL *curl_easy;
struct curl_slist *headers;
- struct curl_httppost* post;
- Eina_List *additional_headers;
- Eina_List *response_headers;
- char *url;
+ struct curl_httppost *post;
+ Eina_List *additional_headers;
+ Eina_List *response_headers;
+ char *url;
Ecore_Con_Url_Time condition;
- time_t time;
- void *data;
+ time_t time;
+ void *data;
- Ecore_Fd_Handler *fd_handler;
- int fd;
- int flags;
+ Ecore_Fd_Handler *fd_handler;
+ int fd;
+ int flags;
- int received;
- int write_fd;
+ int received;
+ int write_fd;
- unsigned char active : 1;
+ unsigned char active : 1;
};
#endif
struct _Ecore_Con_Info
{
- unsigned int size;
+ unsigned int size;
struct addrinfo info;
- char ip[NI_MAXHOST];
- char service[NI_MAXSERV];
+ char ip[NI_MAXHOST];
+ char service[NI_MAXSERV];
};
struct _Ecore_Con_Lookup
/* from ecore_local.c */
int ecore_con_local_init(void);
int ecore_con_local_shutdown(void);
-int ecore_con_local_connect(Ecore_Con_Server *svr, Eina_Bool (*cb_done)(void *data, Ecore_Fd_Handler *fd_handler), void *data, void (*cb_free)(void *data, void *ev));
-int ecore_con_local_listen(Ecore_Con_Server *svr, Eina_Bool (*cb_listen)(void *data, Ecore_Fd_Handler *fd_handler), void *data);
+int ecore_con_local_connect(Ecore_Con_Server *svr,
+ Eina_Bool (*cb_done)(
+ void *data,
+ Ecore_Fd_Handler *fd_handler),
+ void *data,
+ void (*cb_free)(
+ void *data, void *ev));
+int ecore_con_local_listen(Ecore_Con_Server *svr,
+ Eina_Bool (*cb_listen)(
+ void *data,
+ Ecore_Fd_Handler *fd_handler),
+ void *data);
/* from ecore_con_info.c */
-int ecore_con_info_init(void);
-int ecore_con_info_shutdown(void);
-int ecore_con_info_tcp_connect(Ecore_Con_Server *svr, Ecore_Con_Info_Cb done_cb, void *data);
-int ecore_con_info_tcp_listen(Ecore_Con_Server *svr, Ecore_Con_Info_Cb done_cb, void *data);
-int ecore_con_info_udp_connect(Ecore_Con_Server *svr, Ecore_Con_Info_Cb done_cb, void *data);
-int ecore_con_info_udp_listen(Ecore_Con_Server *svr, Ecore_Con_Info_Cb done_cb, void *data);
-int ecore_con_info_mcast_listen(Ecore_Con_Server *svr, Ecore_Con_Info_Cb done_cb, void *data);
+int ecore_con_info_init(void);
+int ecore_con_info_shutdown(void);
+int ecore_con_info_tcp_connect(Ecore_Con_Server *svr,
+ Ecore_Con_Info_Cb done_cb,
+ void *data);
+int ecore_con_info_tcp_listen(Ecore_Con_Server *svr,
+ Ecore_Con_Info_Cb done_cb,
+ void *data);
+int ecore_con_info_udp_connect(Ecore_Con_Server *svr,
+ Ecore_Con_Info_Cb done_cb,
+ void *data);
+int ecore_con_info_udp_listen(Ecore_Con_Server *svr,
+ Ecore_Con_Info_Cb done_cb,
+ void *data);
+int ecore_con_info_mcast_listen(Ecore_Con_Server *svr,
+ Ecore_Con_Info_Cb done_cb,
+ void *data);
/* from ecore_con_ssl.c */
Ecore_Con_Ssl_Error ecore_con_ssl_init(void);
Ecore_Con_Ssl_Error ecore_con_ssl_shutdown(void);
+void _ecore_con_ssl_server_cert_add(Ecore_Con_Server *svr,
+ const char *cert);
void ecore_con_ssl_server_prepare(Ecore_Con_Server *svr);
Ecore_Con_Ssl_Error ecore_con_ssl_server_init(Ecore_Con_Server *svr);
Ecore_Con_Ssl_Error ecore_con_ssl_server_shutdown(Ecore_Con_Server *svr);
Ecore_Con_State ecore_con_ssl_server_try(Ecore_Con_Server *svr);
-int ecore_con_ssl_server_read(Ecore_Con_Server *svr, unsigned char *buf, int size);
-int ecore_con_ssl_server_write(Ecore_Con_Server *svr, unsigned char *buf, int size);
+int ecore_con_ssl_server_read(Ecore_Con_Server *svr,
+ unsigned char *buf,
+ int size);
+int ecore_con_ssl_server_write(Ecore_Con_Server *svr,
+ unsigned char *buf,
+ int size);
Ecore_Con_Ssl_Error ecore_con_ssl_client_init(Ecore_Con_Client *svr);
Ecore_Con_Ssl_Error ecore_con_ssl_client_shutdown(Ecore_Con_Client *svr);
Ecore_Con_State ecore_con_ssl_client_try(Ecore_Con_Client *svr);
-int ecore_con_ssl_client_read(Ecore_Con_Client *svr, unsigned char *buf, int size);
-int ecore_con_ssl_client_write(Ecore_Con_Client *svr, unsigned char *buf, int size);
-
-int ecore_con_info_get(Ecore_Con_Server *svr,
- Ecore_Con_Info_Cb done_cb,
- void *data,
- struct addrinfo *hints);
+int ecore_con_ssl_client_read(Ecore_Con_Client *svr,
+ unsigned char *buf,
+ int size);
+int ecore_con_ssl_client_write(Ecore_Con_Client *svr,
+ unsigned char *buf,
+ int size);
+
+int ecore_con_info_get(Ecore_Con_Server *svr,
+ Ecore_Con_Info_Cb done_cb,
+ void *data,
+ struct addrinfo *hints);
# include <gnutls/gnutls.h>
#elif USE_OPENSSL
# include <openssl/ssl.h>
+# include <openssl/err.h>
#endif
#ifdef HAVE_WS2TCPIP_H
#if USE_GNUTLS
static int _client_connected = 0;
-# define SSL_SUFFIX(ssl_func) ssl_func##_gnutls
+# define SSL_SUFFIX(ssl_func) ssl_func ## _gnutls
# define _ECORE_CON_SSL_AVAILABLE 1
#elif USE_OPENSSL
-# define SSL_SUFFIX(ssl_func) ssl_func##_openssl
+# define SSL_SUFFIX(ssl_func) ssl_func ## _openssl
# define _ECORE_CON_SSL_AVAILABLE 2
#else
-# define SSL_SUFFIX(ssl_func) ssl_func##_none
+# define SSL_SUFFIX(ssl_func) ssl_func ## _none
# define _ECORE_CON_SSL_AVAILABLE 0
#endif
+static const char *certificate = NULL;
+
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 void
-SSL_SUFFIX(_ecore_con_ssl_server_prepare)(Ecore_Con_Server *svr);
+SSL_SUFFIX(_ecore_con_ssl_server_prepare) (Ecore_Con_Server * svr);
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 *svr);
+SSL_SUFFIX(_ecore_con_ssl_server_shutdown) (Ecore_Con_Server * svr);
static Ecore_Con_State
-SSL_SUFFIX(_ecore_con_ssl_server_try)(Ecore_Con_Server *svr);
+SSL_SUFFIX(_ecore_con_ssl_server_try) (Ecore_Con_Server * svr);
static int
-SSL_SUFFIX(_ecore_con_ssl_server_read)(Ecore_Con_Server *svr, unsigned char *buf, int size);
+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 *svr, unsigned char *buf, int size);
+SSL_SUFFIX(_ecore_con_ssl_server_write) (Ecore_Con_Server * svr,
+ unsigned char *buf, int size);
static void
-SSL_SUFFIX(_ecore_con_ssl_client_prepare)(Ecore_Con_Client *cl);
+SSL_SUFFIX(_ecore_con_ssl_client_prepare) (Ecore_Con_Client * cl);
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 *cl);
+SSL_SUFFIX(_ecore_con_ssl_client_shutdown) (Ecore_Con_Client * cl);
static int
-SSL_SUFFIX(_ecore_con_ssl_client_read)(Ecore_Con_Client *cl, unsigned char *buf, int size);
+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, unsigned char *buf, int size);
+SSL_SUFFIX(_ecore_con_ssl_client_write) (Ecore_Con_Client * cl,
+ unsigned char *buf, int size);
/*
* General SSL API
Ecore_Con_Ssl_Error
ecore_con_ssl_init(void)
{
- if (!_init_con_ssl_init_count++)
- SSL_SUFFIX(_ecore_con_ssl_init)();
+ if (!_init_con_ssl_init_count++)
+ SSL_SUFFIX(_ecore_con_ssl_init) ();
- return _init_con_ssl_init_count;
+ return _init_con_ssl_init_count;
}
Ecore_Con_Ssl_Error
ecore_con_ssl_shutdown(void)
{
- if (!--_init_con_ssl_init_count)
- SSL_SUFFIX(_ecore_con_ssl_shutdown)();
+ if (!--_init_con_ssl_init_count)
+ {
+ if (certificate)
+ eina_stringshare_del(certificate);
+
+ certificate = NULL;
+ SSL_SUFFIX(_ecore_con_ssl_shutdown) ();
+ }
- return _init_con_ssl_init_count;
+ return _init_con_ssl_init_count;
+}
+
+void
+_ecore_con_ssl_cert_add(const char *cert)
+{
+ eina_stringshare_replace(&certificate, cert);
}
/**
int
ecore_con_ssl_available_get(void)
{
- return _ECORE_CON_SSL_AVAILABLE;
+ return _ECORE_CON_SSL_AVAILABLE;
}
void
ecore_con_ssl_server_prepare(Ecore_Con_Server *svr)
{
- SSL_SUFFIX(_ecore_con_ssl_server_prepare)(svr);
+ SSL_SUFFIX(_ecore_con_ssl_server_prepare) (svr);
}
Ecore_Con_Ssl_Error
ecore_con_ssl_server_init(Ecore_Con_Server *svr)
{
- return SSL_SUFFIX(_ecore_con_ssl_server_init)(svr);
+ return SSL_SUFFIX(_ecore_con_ssl_server_init) (svr);
}
Ecore_Con_Ssl_Error
ecore_con_ssl_server_shutdown(Ecore_Con_Server *svr)
{
- return SSL_SUFFIX(_ecore_con_ssl_server_shutdown)(svr);
+ return SSL_SUFFIX(_ecore_con_ssl_server_shutdown) (svr);
}
Ecore_Con_State
ecore_con_ssl_server_try(Ecore_Con_Server *svr)
{
- return SSL_SUFFIX(_ecore_con_ssl_server_try)(svr);
+ return SSL_SUFFIX(_ecore_con_ssl_server_try) (svr);
}
int
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);
+ 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)
{
- return SSL_SUFFIX(_ecore_con_ssl_server_write)(svr, buf, size);
+ return SSL_SUFFIX(_ecore_con_ssl_server_write) (svr, buf, size);
}
Ecore_Con_Ssl_Error
ecore_con_ssl_client_init(Ecore_Con_Client *cl)
{
- return SSL_SUFFIX(_ecore_con_ssl_client_init)(cl);
+ return SSL_SUFFIX(_ecore_con_ssl_client_init) (cl);
}
Ecore_Con_Ssl_Error
ecore_con_ssl_client_shutdown(Ecore_Con_Client *cl)
{
- return SSL_SUFFIX(_ecore_con_ssl_client_shutdown)(cl);
+ return SSL_SUFFIX(_ecore_con_ssl_client_shutdown) (cl);
}
int
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);
+ 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)
{
- return SSL_SUFFIX(_ecore_con_ssl_client_write)(cl, buf, size);
+ return SSL_SUFFIX(_ecore_con_ssl_client_write) (cl, buf, size);
}
#if USE_GNUTLS
static Ecore_Con_Ssl_Error
_ecore_con_ssl_init_gnutls(void)
{
- if (gnutls_global_init())
- return ECORE_CON_SSL_ERROR_INIT_FAILED;
+ if (gnutls_global_init())
+ return ECORE_CON_SSL_ERROR_INIT_FAILED;
- return ECORE_CON_SSL_ERROR_NONE;
+ return ECORE_CON_SSL_ERROR_NONE;
}
static Ecore_Con_Ssl_Error
_ecore_con_ssl_shutdown_gnutls(void)
{
- gnutls_global_deinit();
+ gnutls_global_deinit();
- return ECORE_CON_SSL_ERROR_NONE;
+ return ECORE_CON_SSL_ERROR_NONE;
}
static void
_ecore_con_ssl_server_prepare_gnutls(Ecore_Con_Server *svr)
{
- svr->session = NULL;
- svr->anoncred_c = NULL;
- return;
+ svr->session = NULL;
+ svr->anoncred_c = NULL;
+ svr->cert = NULL;
+ return;
}
static Ecore_Con_Ssl_Error
_ecore_con_ssl_server_init_gnutls(Ecore_Con_Server *svr)
{
- const int *proto = NULL;
- int ret;
- const int kx[] = { GNUTLS_KX_ANON_DH, 0 };
- const int ssl3_proto[] = { GNUTLS_SSL3, 0 };
- const int tls_proto[] = {
- GNUTLS_TLS1_0,
- GNUTLS_TLS1_1,
+ const int *proto = NULL;
+ int ret = 0;
+ const int kx[] = { GNUTLS_KX_ANON_DH, 0 };
+ const int ssl3_proto[] = { GNUTLS_SSL3, 0 };
+ const int tls_proto[] = {
+ GNUTLS_TLS1_0,
+ GNUTLS_TLS1_1,
#ifdef USE_GNUTLS2
- GNUTLS_TLS1_2,
+ GNUTLS_TLS1_2,
#endif
- 0
- };
-
- switch (svr->type & ECORE_CON_SSL)
- {
- case ECORE_CON_USE_SSL2: /* not supported because of security issues */
- return ECORE_CON_SSL_ERROR_SSL2_NOT_SUPPORTED;
- case ECORE_CON_USE_SSL3:
- proto = ssl3_proto;
- break;
- case ECORE_CON_USE_TLS:
- proto = tls_proto;
- break;
- default:
- return ECORE_CON_SSL_ERROR_NONE;
- }
-
- gnutls_anon_allocate_client_credentials(&(svr->anoncred_c));
- gnutls_init(&(svr->session), GNUTLS_CLIENT);
- gnutls_set_default_priority(svr->session);
- gnutls_kx_set_priority(svr->session, kx);
- gnutls_credentials_set(svr->session, GNUTLS_CRD_ANON, svr->anoncred_c);
- gnutls_kx_set_priority(svr->session, kx);
- gnutls_protocol_set_priority(svr->session, proto);
- gnutls_dh_set_prime_bits(svr->session, 512);
-
- gnutls_transport_set_ptr(svr->session, (gnutls_transport_ptr_t)svr->fd);
-
- while ((ret = gnutls_handshake(svr->session)) < 0)
- {
- if ((ret == GNUTLS_E_AGAIN) ||
- (ret == GNUTLS_E_INTERRUPTED))
- continue;
-
- _ecore_con_ssl_server_shutdown_gnutls(svr);
- return ECORE_CON_SSL_ERROR_SERVER_INIT_FAILED;
- }
-
- return ECORE_CON_SSL_ERROR_NONE;
+ 0
+ };
+
+ switch (svr->type & ECORE_CON_SSL)
+ {
+ case ECORE_CON_USE_SSL2: /* not supported because of security issues */
+ return ECORE_CON_SSL_ERROR_SSL2_NOT_SUPPORTED;
+
+ case ECORE_CON_USE_SSL3:
+ proto = ssl3_proto;
+ break;
+
+ case ECORE_CON_USE_TLS:
+ proto = tls_proto;
+ break;
+
+ default:
+ return ECORE_CON_SSL_ERROR_NONE;
+ }
+
+ if (certificate && (svr->type & ECORE_CON_LOAD_CERT))
+ {
+
+ gnutls_certificate_allocate_credentials(&(svr->cert));
+ ret = gnutls_certificate_set_x509_trust_file(svr->cert, certificate,
+ GNUTLS_X509_FMT_PEM);
+ if (ret < 1)
+ {
+ ERR("ssl cert load failed: %s", gnutls_strerror(ret));
+ if (svr->cert)
+ {
+ gnutls_certificate_free_credentials(svr->cert);
+ svr->cert = NULL;
+ }
+ }
+ }
+
+ if (!svr->cert)
+ gnutls_anon_allocate_client_credentials(&(svr->anoncred_c));
+
+ gnutls_init(&(svr->session), GNUTLS_CLIENT);
+ svr->cert = NULL;
+ gnutls_set_default_priority(svr->session);
+ gnutls_kx_set_priority(svr->session, kx);
+ if (svr->cert)
+ gnutls_credentials_set(svr->session, GNUTLS_CRD_CERTIFICATE,
+ svr->cert);
+ else
+ gnutls_credentials_set(svr->session, GNUTLS_CRD_ANON, svr->anoncred_c);
+
+ gnutls_kx_set_priority(svr->session, kx);
+ gnutls_protocol_set_priority(svr->session, proto);
+ gnutls_dh_set_prime_bits(svr->session, 512);
+
+ gnutls_transport_set_ptr(svr->session, (gnutls_transport_ptr_t)svr->fd);
+
+ while ((ret = gnutls_handshake(svr->session)) < 0)
+ {
+ if ((ret == GNUTLS_E_AGAIN) ||
+ (ret == GNUTLS_E_INTERRUPTED))
+ continue;
+
+ _ecore_con_ssl_server_shutdown_gnutls(svr);
+ return ECORE_CON_SSL_ERROR_SERVER_INIT_FAILED;
+ }
+
+ return ECORE_CON_SSL_ERROR_NONE;
}
static Ecore_Con_Ssl_Error
_ecore_con_ssl_server_shutdown_gnutls(Ecore_Con_Server *svr)
{
- if (svr->session)
- {
- gnutls_bye(svr->session, GNUTLS_SHUT_RDWR);
- gnutls_deinit(svr->session);
- }
- if (svr->anoncred_c)
- gnutls_anon_free_client_credentials(svr->anoncred_c);
- _ecore_con_ssl_server_prepare_gnutls(svr);
+ if (svr->session)
+ {
+ gnutls_bye(svr->session, GNUTLS_SHUT_RDWR);
+ gnutls_deinit(svr->session);
+ }
+
+ if (svr->cert)
+ gnutls_certificate_free_credentials(svr->cert);
+ else if (svr->anoncred_c)
+ gnutls_anon_free_client_credentials(svr->anoncred_c);
- return ECORE_CON_SSL_ERROR_NONE;
+ _ecore_con_ssl_server_prepare_gnutls(svr);
+
+ return ECORE_CON_SSL_ERROR_NONE;
}
/* Tries to connect an Ecore_Con_Server to an SSL host.
}
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;
+ int num;
+
+ num = gnutls_record_recv(svr->session, buf, size);
+ if (num > 0)
+ return num;
- num = gnutls_record_recv(svr->session, buf, size);
- if (num > 0)
- return num;
- if ((num == GNUTLS_E_AGAIN) ||
- (num == GNUTLS_E_REHANDSHAKE) ||
- (num == GNUTLS_E_INTERRUPTED))
- return 0;
- return -1;
+ if ((num == GNUTLS_E_AGAIN) ||
+ (num == GNUTLS_E_REHANDSHAKE) ||
+ (num == GNUTLS_E_INTERRUPTED))
+ 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;
+ int num;
+
+ num = gnutls_record_send(svr->session, buf, size);
+ if (num > 0)
+ return num;
+
+ if ((num == GNUTLS_E_AGAIN) ||
+ (num == GNUTLS_E_REHANDSHAKE) ||
+ (num == GNUTLS_E_INTERRUPTED))
+ return 0;
- num = gnutls_record_send(svr->session, buf, size);
- if (num > 0)
- return num;
- if ((num == GNUTLS_E_AGAIN) ||
- (num == GNUTLS_E_REHANDSHAKE) ||
- (num == GNUTLS_E_INTERRUPTED))
- return 0;
- return -1;
+ return -1;
}
static void
_ecore_con_ssl_client_prepare_gnutls(Ecore_Con_Client *cl)
{
- cl->session = NULL;
- if (!_client_connected)
- cl->server->anoncred_s = NULL;
+ cl->session = NULL;
+ if (!_client_connected)
+ {
+ cl->server->anoncred_s = NULL;
+ cl->server->cert = NULL;
+ }
}
static Ecore_Con_Ssl_Error
_ecore_con_ssl_client_init_gnutls(Ecore_Con_Client *cl)
{
- const int *proto = NULL;
- gnutls_dh_params_t dh_params;
- int ret;
- const int kx[] = { GNUTLS_KX_ANON_DH, 0 };
- const int ssl3_proto[] = { GNUTLS_SSL3, 0 };
- const int tls_proto[] = {
- GNUTLS_TLS1_0,
- GNUTLS_TLS1_1,
+ const int *proto = NULL;
+ gnutls_dh_params_t dh_params;
+ int ret;
+ const int kx[] = { GNUTLS_KX_ANON_DH, 0 };
+ const int ssl3_proto[] = { GNUTLS_SSL3, 0 };
+ const int tls_proto[] = {
+ GNUTLS_TLS1_0,
+ GNUTLS_TLS1_1,
#ifdef USE_GNUTLS2
- GNUTLS_TLS1_2,
+ GNUTLS_TLS1_2,
#endif
- 0
- };
+ 0
+ };
+
+ switch (cl->server->type & ECORE_CON_SSL)
+ {
+ case ECORE_CON_USE_SSL2: /* not supported because of security issues */
+ return ECORE_CON_SSL_ERROR_SSL2_NOT_SUPPORTED;
+
+ case ECORE_CON_USE_SSL3:
+ proto = ssl3_proto;
+ break;
+
+ case ECORE_CON_USE_TLS:
+ proto = tls_proto;
+ break;
+
+ default:
+ return ECORE_CON_SSL_ERROR_NONE;
+ }
+
+ _client_connected++;
- switch (cl->server->type & ECORE_CON_SSL)
- {
- case ECORE_CON_USE_SSL2: /* not supported because of security issues */
- return ECORE_CON_SSL_ERROR_SSL2_NOT_SUPPORTED;
- case ECORE_CON_USE_SSL3:
- proto = ssl3_proto;
- break;
- case ECORE_CON_USE_TLS:
- proto = tls_proto;
- break;
- default:
- return ECORE_CON_SSL_ERROR_NONE;
- }
+ if (certificate && (cl->server->type & ECORE_CON_LOAD_CERT))
+ {
- _client_connected++;
- if (!cl->server->anoncred_s)
- {
- gnutls_anon_allocate_server_credentials(&(cl->server->anoncred_s));
- gnutls_dh_params_init(&dh_params);
- gnutls_dh_params_generate2(dh_params, 512);
- gnutls_anon_set_server_dh_params(cl->server->anoncred_s, dh_params);
- }
+ gnutls_certificate_allocate_credentials(&(cl->server->cert));
+ ret =
+ gnutls_certificate_set_x509_trust_file(cl->server->cert, certificate,
+ GNUTLS_X509_FMT_PEM);
+ if (ret < 1)
+ {
+ ERR("ssl cert load failed: %s", gnutls_strerror(ret));
+ if (cl->server->cert)
+ {
+ gnutls_certificate_free_credentials(cl->server->cert);
+ cl->server->cert = NULL;
+ }
+ }
+ }
+
+ if (!cl->server->anoncred_s && !cl->server->cert)
+ {
+ gnutls_anon_allocate_server_credentials(&(cl->server->anoncred_s));
+ gnutls_dh_params_init(&dh_params);
+ gnutls_dh_params_generate2(dh_params, 512);
+ gnutls_anon_set_server_dh_params(cl->server->anoncred_s, dh_params);
+ }
- gnutls_init(&(cl->session), GNUTLS_SERVER);
- gnutls_set_default_priority(cl->session);
- gnutls_credentials_set(cl->session, GNUTLS_CRD_ANON, cl->server->anoncred_s);
+ gnutls_init(&(cl->session), GNUTLS_SERVER);
+ gnutls_set_default_priority(cl->session);
+ if (!cl->server->cert)
+ gnutls_credentials_set(cl->session,
+ GNUTLS_CRD_CERTIFICATE,
+ cl->server->cert);
+ else
+ gnutls_credentials_set(cl->session, GNUTLS_CRD_ANON,
+ cl->server->anoncred_s);
- gnutls_kx_set_priority(cl->session, kx);
+ gnutls_kx_set_priority(cl->session, kx);
- gnutls_protocol_set_priority(cl->session, proto);
+ gnutls_protocol_set_priority(cl->session, proto);
- gnutls_dh_set_prime_bits(cl->session, 512);
+ gnutls_dh_set_prime_bits(cl->session, 512);
- gnutls_transport_set_ptr(cl->session, (gnutls_transport_ptr_t)cl->fd);
+ gnutls_transport_set_ptr(cl->session, (gnutls_transport_ptr_t)cl->fd);
- while ((ret = gnutls_handshake(cl->session)) < 0)
- {
- if ((ret == GNUTLS_E_AGAIN) ||
- (ret == GNUTLS_E_INTERRUPTED))
- continue;
+ while ((ret = gnutls_handshake(cl->session)) < 0)
+ {
+ if ((ret == GNUTLS_E_AGAIN) ||
+ (ret == GNUTLS_E_INTERRUPTED))
+ continue;
- _ecore_con_ssl_client_shutdown_gnutls(cl);
- return ECORE_CON_SSL_ERROR_SERVER_INIT_FAILED;
- }
+ _ecore_con_ssl_client_shutdown_gnutls(cl);
+ return ECORE_CON_SSL_ERROR_SERVER_INIT_FAILED;
+ }
- return ECORE_CON_SSL_ERROR_NONE;
+ return ECORE_CON_SSL_ERROR_NONE;
}
static Ecore_Con_Ssl_Error
_ecore_con_ssl_client_shutdown_gnutls(Ecore_Con_Client *cl)
{
- if (cl->session)
- {
- gnutls_bye(cl->session, GNUTLS_SHUT_RDWR);
- gnutls_deinit(cl->session);
- }
- if (cl->server->anoncred_s && !--_client_connected)
- gnutls_anon_free_server_credentials(cl->server->anoncred_s);
- _ecore_con_ssl_client_prepare_gnutls(cl);
+ if (cl->session)
+ {
+ gnutls_bye(cl->session, GNUTLS_SHUT_RDWR);
+ gnutls_deinit(cl->session);
+ }
- return ECORE_CON_SSL_ERROR_NONE;
+ if (!cl->server->cert && cl->server->anoncred_s &&
+ !--_client_connected)
+ gnutls_anon_free_server_credentials(
+ cl->server->anoncred_s);
+ else if (cl->server->cert &&
+ !--_client_connected)
+ gnutls_certificate_free_credentials(
+ cl->server->cert);
+
+ _ecore_con_ssl_client_prepare_gnutls(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;
+ int num;
+
+ num = gnutls_record_recv(cl->session, buf, size);
+ if (num > 0)
+ return num;
- num = gnutls_record_recv(cl->session, buf, size);
- if (num > 0)
- return num;
- if ((num == GNUTLS_E_AGAIN) ||
- (num == GNUTLS_E_REHANDSHAKE) ||
- (num == GNUTLS_E_INTERRUPTED))
- return 0;
- return -1;
+ if ((num == GNUTLS_E_AGAIN) ||
+ (num == GNUTLS_E_REHANDSHAKE) ||
+ (num == GNUTLS_E_INTERRUPTED))
+ 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;
+ int num;
+
+ num = gnutls_record_send(cl->session, buf, size);
+ if (num > 0)
+ return num;
- num = gnutls_record_send(cl->session, buf, size);
- if (num > 0)
- return num;
- if ((num == GNUTLS_E_AGAIN) ||
- (num == GNUTLS_E_REHANDSHAKE) ||
- (num == GNUTLS_E_INTERRUPTED))
- return 0;
- return -1;
+ if ((num == GNUTLS_E_AGAIN) ||
+ (num == GNUTLS_E_REHANDSHAKE) ||
+ (num == GNUTLS_E_INTERRUPTED))
+ return 0;
+
+ return -1;
}
#elif USE_OPENSSL
static Ecore_Con_Ssl_Error
_ecore_con_ssl_init_openssl(void)
{
- SSL_library_init();
- SSL_load_error_strings();
+ SSL_library_init();
+ SSL_load_error_strings();
- return ECORE_CON_SSL_ERROR_NONE;
+ return ECORE_CON_SSL_ERROR_NONE;
}
static Ecore_Con_Ssl_Error
_ecore_con_ssl_shutdown_openssl(void)
{
- ERR_free_strings();
- return ECORE_CON_SSL_ERROR_NONE;
+ ERR_free_strings();
+ return ECORE_CON_SSL_ERROR_NONE;
}
static void
_ecore_con_ssl_server_prepare_openssl(Ecore_Con_Server *svr)
{
- svr->ssl = NULL;
- svr->ssl_ctx = NULL;
- svr->ssl_err = SSL_ERROR_NONE;
+ svr->ssl = NULL;
+ svr->ssl_ctx = NULL;
+ svr->ssl_err = SSL_ERROR_NONE;
}
static Ecore_Con_Ssl_Error
_ecore_con_ssl_server_init_openssl(Ecore_Con_Server *svr)
{
- switch (svr->type & ECORE_CON_SSL)
- {
- case ECORE_CON_USE_SSL2:
- /* Unsafe version of SSL */
- if (!(svr->ssl_ctx = SSL_CTX_new(SSLv2_client_method())))
- return ECORE_CON_SSL_ERROR_SERVER_INIT_FAILED;
- break;
- case ECORE_CON_USE_SSL3:
- if (!(svr->ssl_ctx = SSL_CTX_new(SSLv3_client_method())))
- return ECORE_CON_SSL_ERROR_SERVER_INIT_FAILED;
- break;
- case ECORE_CON_USE_TLS:
- if (!(svr->ssl_ctx = SSL_CTX_new(TLSv1_client_method())))
- return ECORE_CON_SSL_ERROR_SERVER_INIT_FAILED;
- break;
- default:
- return ECORE_CON_SSL_ERROR_NONE;
- }
- if (!(svr->ssl = SSL_new(svr->ssl_ctx)))
- {
- SSL_CTX_free(svr->ssl_ctx);
- return ECORE_CON_SSL_ERROR_SERVER_INIT_FAILED;
- }
+ switch (svr->type & ECORE_CON_SSL)
+ {
+ case ECORE_CON_USE_SSL2:
+ /* Unsafe version of SSL */
+ if (!(svr->ssl_ctx =
+ SSL_CTX_new(SSLv2_client_method())))
+ return
+ ECORE_CON_SSL_ERROR_SERVER_INIT_FAILED;
+
+ break;
+
+ case ECORE_CON_USE_SSL3:
+ if (!(svr->ssl_ctx =
+ SSL_CTX_new(SSLv3_client_method())))
+ return
+ ECORE_CON_SSL_ERROR_SERVER_INIT_FAILED;
+
+ break;
+
+ case ECORE_CON_USE_TLS:
+ if (!(svr->ssl_ctx =
+ SSL_CTX_new(TLSv1_client_method())))
+ return
+ ECORE_CON_SSL_ERROR_SERVER_INIT_FAILED;
+
+ break;
+
+ default:
+ return ECORE_CON_SSL_ERROR_NONE;
+ }
+ if (!(svr->ssl = SSL_new(svr->ssl_ctx)))
+ {
+ SSL_CTX_free(svr->ssl_ctx);
+ return ECORE_CON_SSL_ERROR_SERVER_INIT_FAILED;
+ }
- SSL_set_fd(svr->ssl, svr->fd);
+ if (certificate && (svr->type & ECORE_CON_LOAD_CERT))
+ //FIXME: just log and go on without cert if loading fails?
+ if (!SSL_CTX_use_certificate_file(svr->ssl_ctx, certificate,
+ SSL_FILETYPE_PEM) ||
+ !SSL_CTX_use_PrivateKey_file(svr->ssl_ctx, certificate,
+ SSL_FILETYPE_PEM) ||
+ !SSL_CTX_check_private_key(svr->ssl_ctx))
+ ERR(
+ "ssl cert load failed: %s", ERR_reason_error_string(ERR_get_error()));
- return ECORE_CON_SSL_ERROR_NONE;
+ SSL_set_fd(svr->ssl, svr->fd);
+
+ return ECORE_CON_SSL_ERROR_NONE;
}
static Ecore_Con_Ssl_Error
_ecore_con_ssl_server_shutdown_openssl(Ecore_Con_Server *svr)
{
- if (svr->ssl)
- {
- if (!SSL_shutdown(svr->ssl))
- SSL_shutdown(svr->ssl);
- SSL_free(svr->ssl);
- }
- if (svr->ssl_ctx) SSL_CTX_free(svr->ssl_ctx);
+ if (svr->ssl)
+ {
+ if (!SSL_shutdown(svr->ssl))
+ SSL_shutdown(svr->ssl);
- _ecore_con_ssl_server_prepare_openssl(svr);
+ SSL_free(svr->ssl);
+ }
- return ECORE_CON_SSL_ERROR_NONE;
+ if (svr->ssl_ctx)
+ SSL_CTX_free(svr->ssl_ctx);
+
+ _ecore_con_ssl_server_prepare_openssl(svr);
+
+ return ECORE_CON_SSL_ERROR_NONE;
}
/* Tries to connect an Ecore_Con_Server to an SSL host.
int res, flag = 0;
if ((res = SSL_connect(svr->ssl)) == 1)
- return ECORE_CON_CONNECTED;
+ return ECORE_CON_CONNECTED;
svr->ssl_err = SSL_get_error(svr->ssl, res);
switch (svr->ssl_err)
{
- case SSL_ERROR_NONE:
- return ECORE_CON_CONNECTED;
- case SSL_ERROR_WANT_READ:
- flag = ECORE_FD_READ;
- break;
- case SSL_ERROR_WANT_WRITE:
- flag = ECORE_FD_WRITE;
- break;
- default:
- return ECORE_CON_DISCONNECTED;
+ case SSL_ERROR_NONE:
+ return ECORE_CON_CONNECTED;
+
+ case SSL_ERROR_WANT_READ:
+ flag = ECORE_FD_READ;
+ break;
+
+ case SSL_ERROR_WANT_WRITE:
+ flag = ECORE_FD_WRITE;
+ break;
+
+ default:
+ return ECORE_CON_DISCONNECTED;
}
if (svr->fd_handler && flag)
- ecore_main_fd_handler_active_set(svr->fd_handler, flag);
+ ecore_main_fd_handler_active_set(svr->fd_handler,
+ flag);
return ECORE_CON_INPROGRESS;
}
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;
+ int num;
- num = SSL_read(svr->ssl, buf, size);
- svr->ssl_err = SSL_get_error(svr->ssl, num);
+ num = SSL_read(svr->ssl, buf, size);
+ svr->ssl_err = SSL_get_error(svr->ssl, num);
- 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);
- else if (svr->ssl && svr->ssl_err == SSL_ERROR_WANT_WRITE)
- ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_WRITE);
- }
+ 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);
+ else if (svr->ssl && svr->ssl_err ==
+ SSL_ERROR_WANT_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;
- if (num < 0)
- return 0;
- return num;
+ if ((svr->ssl_err == SSL_ERROR_ZERO_RETURN) ||
+ (svr->ssl_err == SSL_ERROR_SYSCALL) ||
+ (svr->ssl_err == SSL_ERROR_SSL))
+ return -1;
+
+ if (num < 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;
+ int num;
+
+ num = SSL_write(svr->ssl, buf, size);
+ svr->ssl_err = SSL_get_error(svr->ssl, num);
- num = SSL_write(svr->ssl, buf, size);
- svr->ssl_err = SSL_get_error(svr->ssl, num);
+ 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);
+ else if (svr->ssl && svr->ssl_err ==
+ SSL_ERROR_WANT_WRITE)
+ ecore_main_fd_handler_active_set(
+ svr->fd_handler,
+ ECORE_FD_WRITE);
+ }
- 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);
- else if (svr->ssl && svr->ssl_err == SSL_ERROR_WANT_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;
- if ((svr->ssl_err == SSL_ERROR_ZERO_RETURN) ||
- (svr->ssl_err == SSL_ERROR_SYSCALL) ||
- (svr->ssl_err == SSL_ERROR_SSL))
- return -1;
- if (num < 0)
- return 0;
- return num;
+ if (num < 0)
+ return 0;
+
+ return num;
}
static void
_ecore_con_ssl_client_prepare_openssl(Ecore_Con_Client *cl)
{
- cl->ssl = NULL;
- cl->ssl_ctx = NULL;
- cl->ssl_err = SSL_ERROR_NONE;
+ cl->ssl = NULL;
+ cl->ssl_ctx = NULL;
+ cl->ssl_err = SSL_ERROR_NONE;
}
static Ecore_Con_Ssl_Error
_ecore_con_ssl_client_init_openssl(Ecore_Con_Client *cl)
{
- switch (cl->server->type & ECORE_CON_SSL)
- {
- case ECORE_CON_USE_SSL2:
- /* Unsafe version of SSL */
- if (!(cl->ssl_ctx = SSL_CTX_new(SSLv2_client_method())))
- return ECORE_CON_SSL_ERROR_SERVER_INIT_FAILED;
- break;
- case ECORE_CON_USE_SSL3:
- if (!(cl->ssl_ctx = SSL_CTX_new(SSLv3_client_method())))
- return ECORE_CON_SSL_ERROR_SERVER_INIT_FAILED;
- break;
- case ECORE_CON_USE_TLS:
- if (!(cl->ssl_ctx = SSL_CTX_new(TLSv1_client_method())))
- return ECORE_CON_SSL_ERROR_SERVER_INIT_FAILED;
- break;
- default:
- return ECORE_CON_SSL_ERROR_NONE;
- }
- if (!(cl->ssl = SSL_new(cl->ssl_ctx)))
- {
- SSL_CTX_free(cl->ssl_ctx);
- return ECORE_CON_SSL_ERROR_SERVER_INIT_FAILED;
- }
+ switch (cl->server->type & ECORE_CON_SSL)
+ {
+ case ECORE_CON_USE_SSL2:
+ /* Unsafe version of SSL */
+ if (!(cl->ssl_ctx =
+ SSL_CTX_new(SSLv2_client_method())))
+ return
+ ECORE_CON_SSL_ERROR_SERVER_INIT_FAILED;
+
+ break;
+
+ case ECORE_CON_USE_SSL3:
+ if (!(cl->ssl_ctx =
+ SSL_CTX_new(SSLv3_client_method())))
+ return
+ ECORE_CON_SSL_ERROR_SERVER_INIT_FAILED;
+
+ break;
+
+ case ECORE_CON_USE_TLS:
+ if (!(cl->ssl_ctx =
+ SSL_CTX_new(TLSv1_client_method())))
+ return
+ ECORE_CON_SSL_ERROR_SERVER_INIT_FAILED;
+
+ break;
+
+ default:
+ return ECORE_CON_SSL_ERROR_NONE;
+ }
+ if (!(cl->ssl = SSL_new(cl->ssl_ctx)))
+ {
+ SSL_CTX_free(cl->ssl_ctx);
+ return ECORE_CON_SSL_ERROR_SERVER_INIT_FAILED;
+ }
- SSL_set_fd(cl->ssl, cl->fd);
+ if (certificate && (cl->server->type & ECORE_CON_LOAD_CERT))
+ //FIXME: just log and go on without cert if loading fails?
+ if (!SSL_CTX_use_certificate_file(cl->server->ssl_ctx, certificate,
+ SSL_FILETYPE_PEM) ||
+ !SSL_CTX_use_PrivateKey_file(cl->server->ssl_ctx, certificate,
+ SSL_FILETYPE_PEM) ||
+ !SSL_CTX_check_private_key(cl->server->ssl_ctx))
+ ERR(
+ "ssl cert load failed: %s", ERR_reason_error_string(ERR_get_error()));
- return ECORE_CON_SSL_ERROR_NONE;
+ SSL_set_fd(cl->ssl, cl->fd);
+
+ return ECORE_CON_SSL_ERROR_NONE;
}
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_free(cl->ssl);
- }
- if (cl->ssl_ctx) SSL_CTX_free(cl->ssl_ctx);
+ if (cl->ssl)
+ {
+ if (!SSL_shutdown(cl->ssl))
+ SSL_shutdown(cl->ssl);
- _ecore_con_ssl_client_prepare_openssl(cl);
+ SSL_free(cl->ssl);
+ }
- return ECORE_CON_SSL_ERROR_NONE;
+ if (cl->ssl_ctx)
+ SSL_CTX_free(cl->ssl_ctx);
+
+ _ecore_con_ssl_client_prepare_openssl(cl);
+
+ return ECORE_CON_SSL_ERROR_NONE;
}
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;
+ int num;
+
+ num = SSL_read(cl->ssl, buf, size);
+ cl->ssl_err = SSL_get_error(cl->ssl, num);
- num = SSL_read(cl->ssl, buf, size);
- cl->ssl_err = SSL_get_error(cl->ssl, num);
+ 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);
+ else if (cl->ssl && cl->ssl_err ==
+ SSL_ERROR_WANT_WRITE)
+ ecore_main_fd_handler_active_set(
+ cl->fd_handler,
+ ECORE_FD_WRITE);
+ }
- 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);
- else if (cl->ssl && cl->ssl_err == SSL_ERROR_WANT_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;
- if ((cl->ssl_err == SSL_ERROR_ZERO_RETURN) ||
- (cl->ssl_err == SSL_ERROR_SYSCALL) ||
- (cl->ssl_err == SSL_ERROR_SSL))
- return -1;
- if (num < 0)
- return 0;
- return num;
+ if (num < 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;
+ int num;
+
+ num = SSL_write(cl->ssl, buf, size);
+ cl->ssl_err = SSL_get_error(cl->ssl, num);
+
+ 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);
+ else if (cl->ssl && cl->ssl_err ==
+ SSL_ERROR_WANT_WRITE)
+ ecore_main_fd_handler_active_set(
+ cl->fd_handler,
+ ECORE_FD_WRITE);
+ }
- num = SSL_write(cl->ssl, buf, size);
- cl->ssl_err = SSL_get_error(cl->ssl, num);
+ if ((cl->ssl_err == SSL_ERROR_ZERO_RETURN) ||
+ (cl->ssl_err == SSL_ERROR_SYSCALL) ||
+ (cl->ssl_err == SSL_ERROR_SSL))
+ return -1;
- 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);
- else if (cl->ssl && cl->ssl_err == SSL_ERROR_WANT_WRITE)
- ecore_main_fd_handler_active_set(cl->fd_handler, ECORE_FD_WRITE);
- }
+ if (num < 0)
+ return 0;
- if ((cl->ssl_err == SSL_ERROR_ZERO_RETURN) ||
- (cl->ssl_err == SSL_ERROR_SYSCALL) ||
- (cl->ssl_err == SSL_ERROR_SSL))
- return -1;
- if (num < 0)
- return 0;
- return num;
+ return num;
}
#else
static Ecore_Con_Ssl_Error
_ecore_con_ssl_init_none(void)
{
- return ECORE_CON_SSL_ERROR_NONE;
+ return ECORE_CON_SSL_ERROR_NONE;
}
static Ecore_Con_Ssl_Error
_ecore_con_ssl_shutdown_none(void)
{
- return ECORE_CON_SSL_ERROR_NONE;
+ return ECORE_CON_SSL_ERROR_NONE;
}
static void
static Ecore_Con_Ssl_Error
_ecore_con_ssl_server_init_none(Ecore_Con_Server *svr)
{
- return ECORE_CON_SSL_ERROR_NOT_SUPPORTED;
+ return ECORE_CON_SSL_ERROR_NOT_SUPPORTED;
}
static Ecore_Con_Ssl_Error
_ecore_con_ssl_server_shutdown_none(Ecore_Con_Server *svr)
{
- return ECORE_CON_SSL_ERROR_NOT_SUPPORTED;
+ return ECORE_CON_SSL_ERROR_NOT_SUPPORTED;
}
/* Tries to connect an Ecore_Con_Server to an SSL host.
static Ecore_Con_State
_ecore_con_ssl_server_try_none(Ecore_Con_Server *svr)
{
- return ECORE_CON_DISCONNECTED;
+ return ECORE_CON_DISCONNECTED;
}
static int
-_ecore_con_ssl_server_read_none(Ecore_Con_Server *svr, unsigned char *buf, int size)
+_ecore_con_ssl_server_read_none(Ecore_Con_Server *svr, unsigned char *buf,
+ int size)
{
- return -1;
+ return -1;
}
static int
-_ecore_con_ssl_server_write_none(Ecore_Con_Server *svr, unsigned char *buf, int size)
+_ecore_con_ssl_server_write_none(Ecore_Con_Server *svr, unsigned char *buf,
+ int size)
{
- return -1;
+ return -1;
}
static void
_ecore_con_ssl_client_prepare_none(Ecore_Con_Client *cl)
{
- return;
+ return;
}
static Ecore_Con_Ssl_Error
_ecore_con_ssl_client_init_none(Ecore_Con_Client *cl)
{
- return ECORE_CON_SSL_ERROR_NOT_SUPPORTED;
+ return ECORE_CON_SSL_ERROR_NOT_SUPPORTED;
}
static Ecore_Con_Ssl_Error
_ecore_con_ssl_client_shutdown_none(Ecore_Con_Client *cl)
{
- return ECORE_CON_SSL_ERROR_NOT_SUPPORTED;
+ return ECORE_CON_SSL_ERROR_NOT_SUPPORTED;
}
static int
-_ecore_con_ssl_client_read_none(Ecore_Con_Client *cl, unsigned char *buf, int size)
+_ecore_con_ssl_client_read_none(Ecore_Con_Client *cl, unsigned char *buf,
+ int size)
{
- return -1;
+ return -1;
}
static int
-_ecore_con_ssl_client_write_none(Ecore_Con_Client *cl, unsigned char *buf, int size)
+_ecore_con_ssl_client_write_none(Ecore_Con_Client *cl, unsigned char *buf,
+ int size)
{
- return -1;
+ return -1;
}
#endif
int ECORE_CON_EVENT_URL_PROGRESS = 0;
#ifdef HAVE_CURL
-static Eina_Bool _ecore_con_url_fd_handler(void *data, Ecore_Fd_Handler *fd_handler);
-static int _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 int _ecore_con_url_process_completed_jobs(Ecore_Con_Url *url_con_to_match);
+static Eina_Bool _ecore_con_url_fd_handler(void *data,
+ Ecore_Fd_Handler *fd_handler);
+static int _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 int _ecore_con_url_process_completed_jobs(
+ Ecore_Con_Url *url_con_to_match);
static Eina_Bool _ecore_con_url_idler_handler(void *data __UNUSED__);
static Ecore_Idler *_fd_idler_handler = NULL;
struct _Ecore_Con_Url_Event
{
int type;
- void *ev;
+ void *ev;
};
static Eina_Bool
#ifdef HAVE_CURL
init_count++;
- if (init_count > 1) return init_count;
+ if (init_count > 1)
+ return init_count;
if (!ECORE_CON_EVENT_URL_DATA)
{
- ECORE_CON_EVENT_URL_DATA = ecore_event_type_new();
- ECORE_CON_EVENT_URL_COMPLETE = ecore_event_type_new();
- ECORE_CON_EVENT_URL_PROGRESS = ecore_event_type_new();
+ ECORE_CON_EVENT_URL_DATA = ecore_event_type_new();
+ ECORE_CON_EVENT_URL_COMPLETE = ecore_event_type_new();
+ ECORE_CON_EVENT_URL_PROGRESS = ecore_event_type_new();
}
if (!curlm)
{
- long ms;
-
- FD_ZERO(&_current_fd_set);
- if (curl_global_init(CURL_GLOBAL_NOTHING))
- {
- while (_url_con_list)
- ecore_con_url_destroy(eina_list_data_get(_url_con_list));
- return 0;
- }
-
- curlm = curl_multi_init();
- if (!curlm)
- {
- while (_url_con_list)
- ecore_con_url_destroy(eina_list_data_get(_url_con_list));
-
- init_count--;
- return 0;
- }
-
- curl_multi_timeout(curlm, &ms);
- if (ms <= 0) ms = 1000;
-
- _curl_timeout = ecore_timer_add((double) ms / 1000, _ecore_con_url_idler_handler, (void *) 0xACE);
- ecore_timer_freeze(_curl_timeout);
+ long ms;
+
+ FD_ZERO(&_current_fd_set);
+ if (curl_global_init(CURL_GLOBAL_NOTHING))
+ {
+ while (_url_con_list)
+ ecore_con_url_destroy(eina_list_data_get(_url_con_list));
+ return 0;
+ }
+
+ curlm = curl_multi_init();
+ if (!curlm)
+ {
+ while (_url_con_list)
+ ecore_con_url_destroy(eina_list_data_get(_url_con_list));
+
+ init_count--;
+ return 0;
+ }
+
+ curl_multi_timeout(curlm, &ms);
+ if (ms <= 0)
+ ms = 1000;
+
+ _curl_timeout =
+ ecore_timer_add((double)ms / 1000, _ecore_con_url_idler_handler,
+ (void *)0xACE);
+ ecore_timer_freeze(_curl_timeout);
}
+
return 1;
#else
return 0;
ecore_con_url_shutdown(void)
{
#ifdef HAVE_CURL
- if (!init_count) return 0;
+ if (!init_count)
+ return 0;
init_count--;
- if (init_count != 0) return init_count;
+ if (init_count != 0)
+ 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_destroy(eina_list_data_get(_url_con_list));
+ ecore_con_url_destroy(eina_list_data_get(_url_con_list));
if (curlm)
{
- curl_multi_cleanup(curlm);
- curlm = NULL;
+ curl_multi_cleanup(curlm);
+ curlm = NULL;
}
curl_global_cleanup();
#ifdef HAVE_CURL
Ecore_Con_Url *url_con;
- if (!init_count) return NULL;
+ if (!init_count)
+ return NULL;
url_con = calloc(1, sizeof(Ecore_Con_Url));
- if (!url_con) return NULL;
+ if (!url_con)
+ return NULL;
url_con->curl_easy = curl_easy_init();
if (!url_con->curl_easy)
{
- free(url_con);
- return NULL;
+ free(url_con);
+ return NULL;
}
ECORE_MAGIC_SET(url_con, ECORE_MAGIC_CON_URL);
ecore_con_url_url_set(url_con, url);
- curl_easy_setopt(url_con->curl_easy, CURLOPT_WRITEFUNCTION,
+ curl_easy_setopt(url_con->curl_easy, CURLOPT_WRITEFUNCTION,
_ecore_con_url_data_cb);
curl_easy_setopt(url_con->curl_easy, CURLOPT_WRITEDATA, url_con);
- curl_easy_setopt(url_con->curl_easy, CURLOPT_PROGRESSFUNCTION,
+ 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_HEADERFUNCTION,
+ _ecore_con_url_header_cb);
+ 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);
- curl_easy_setopt(url_con->curl_easy, CURLOPT_ENCODING, "gzip,deflate");
+ curl_easy_setopt(url_con->curl_easy, CURLOPT_ENCODING, "gzip,deflate");
url_con->fd = -1;
url_con->write_fd = -1;
#ifdef HAVE_CURL
Ecore_Con_Url *url_con;
- if (!url) return NULL;
- if (!custom_request) return NULL;
+ if (!url)
+ return NULL;
+
+ if (!custom_request)
+ return NULL;
url_con = ecore_con_url_new(url);
- if (!url_con) return NULL;
+ if (!url_con)
+ return NULL;
curl_easy_setopt(url_con->curl_easy, CURLOPT_CUSTOMREQUEST, custom_request);
#ifdef HAVE_CURL
char *s;
- if (!url_con) return;
+ if (!url_con)
+ return;
+
if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
{
- ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, "ecore_con_url_destroy");
- return;
+ ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, "ecore_con_url_destroy");
+ return;
}
ECORE_MAGIC_SET(url_con, ECORE_MAGIC_NONE);
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;
+ 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;
}
if (url_con->post)
- curl_formfree(url_con->post);
+ curl_formfree(url_con->post);
+
url_con->post = NULL;
-
+
if (url_con->curl_easy)
{
- // 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);
+ // 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);
+
+ if (url_con->active)
+ {
+ url_con->active = 0;
- if (url_con->active)
- {
- url_con->active = 0;
+ curl_multi_remove_handle(curlm, url_con->curl_easy);
+ }
- curl_multi_remove_handle(curlm, url_con->curl_easy);
- }
- 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);
curl_slist_free_all(url_con->headers);
EINA_LIST_FREE(url_con->additional_headers, s)
- free(s);
+ free(s);
EINA_LIST_FREE(url_con->response_headers, s)
- free(s);
+ free(s);
free(url_con->url);
free(url_con);
#else
#ifdef HAVE_CURL
if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
{
- ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, "ecore_con_url_url_set");
- return 0;
+ ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, "ecore_con_url_url_set");
+ return 0;
}
- if (url_con->active) return 0;
+ if (url_con->active)
+ return 0;
+
+ if (url_con->url)
+ free(url_con->url);
- if (url_con->url) free(url_con->url);
url_con->url = NULL;
- if (url) url_con->url = strdup(url);
+ if (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 1;
#else
return 0;
#ifdef HAVE_CURL
if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
{
- ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, "ecore_con_url_data_set");
- return;
+ ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, "ecore_con_url_data_set");
+ return;
}
url_con->data = 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;
if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
{
- ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, "ecore_con_url_additional_header_add");
- return;
+ ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL,
+ "ecore_con_url_additional_header_add");
+ return;
}
tmp = malloc(strlen(key) + strlen(value) + 3);
- if (!tmp) return ;
+ if (!tmp)
+ return;
+
sprintf(tmp, "%s: %s", key, value);
- url_con->additional_headers = eina_list_append(url_con->additional_headers, tmp);
+ url_con->additional_headers = eina_list_append(url_con->additional_headers,
+ tmp);
#else
return;
url_con = NULL;
if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
{
- ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, "ecore_con_url_additional_headers_clear");
- return;
+ ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL,
+ "ecore_con_url_additional_headers_clear");
+ return;
}
EINA_LIST_FREE(url_con->additional_headers, s)
- free(s);
+ free(s);
#else
return;
url_con = NULL;
#ifdef HAVE_CURL
if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
{
- ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, "ecore_con_url_data_get");
- return NULL;
+ ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, "ecore_con_url_data_get");
+ return NULL;
}
return url_con->data;
* @ingroup Ecore_Con_Url_Group
*/
EAPI void
-ecore_con_url_time(Ecore_Con_Url *url_con, Ecore_Con_Url_Time condition, time_t tm)
+ecore_con_url_time(Ecore_Con_Url *url_con, Ecore_Con_Url_Time condition,
+ time_t tm)
{
#ifdef HAVE_CURL
if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
{
- ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, "ecore_con_url_time");
- return;
+ ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, "ecore_con_url_time");
+ return;
}
url_con->condition = condition;
#ifdef HAVE_CURL
if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
{
- ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, "ecore_con_url_set");
- return ;
+ ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, "ecore_con_url_set");
+ return;
}
+
url_con->write_fd = fd;
#endif
}
#ifdef HAVE_CURL
if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
{
- ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, "ecore_con_url_received_bytes_get");
- return -1;
+ ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL,
+ "ecore_con_url_received_bytes_get");
+ return -1;
}
return url_con->received;
* Sets url_con to use http auth, with given username and password, "safely" or not.
*
* @param url_con Connection object to perform a request on, previously created
- * with ecore_con_url_new() or ecore_con_url_custom_new().
+ * with ecore_con_url_new() or ecore_con_url_custom_new().
* @param username Username to use in authentication
* @param password Password to use in authentication
* @param safe Whether to use "safer" methods (eg, NOT http basic auth)
* @ingroup Ecore_Con_Url_Group
*/
EAPI int
-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
if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
{
- ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, "ecore_con_url_httpauth_set");
- return 0;
+ ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL,
+ "ecore_con_url_httpauth_set");
+ return 0;
}
+
# ifdef CURLOPT_USERNAME
-# ifdef CURLOPT_PASSWORD
+# ifdef CURLOPT_PASSWORD
if ((username != NULL) && (password != NULL))
{
- if (safe)
- 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_USERNAME, username);
- curl_easy_setopt(url_con->curl_easy, CURLOPT_PASSWORD, password);
+ if (safe)
+ 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_USERNAME, username);
+ curl_easy_setopt(url_con->curl_easy, CURLOPT_PASSWORD, password);
return 1;
}
+
# endif
# endif
#endif
* @see ecore_con_url_response_headers_get()
*/
EAPI int
-ecore_con_url_send(Ecore_Con_Url *url_con, const void *data, size_t length, const char *content_type)
+ecore_con_url_send(Ecore_Con_Url *url_con, const void *data, size_t length,
+ const char *content_type)
{
#ifdef HAVE_CURL
Eina_List *l;
if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
{
- ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, "ecore_con_url_send");
- return 0;
+ ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, "ecore_con_url_send");
+ return 0;
}
- if (url_con->active) return 0;
- if (!url_con->url) return 0;
+ if (url_con->active)
+ return 0;
+
+ if (!url_con->url)
+ return 0;
/* Free response headers from previous send() calls */
EINA_LIST_FREE(url_con->response_headers, s) free((char *)s);
if (data)
{
- curl_easy_setopt(url_con->curl_easy, CURLOPT_POSTFIELDS, data);
- curl_easy_setopt(url_con->curl_easy, CURLOPT_POSTFIELDSIZE, length);
-
- if (content_type && (strlen(content_type) < 200))
- {
- sprintf(tmp, "Content-type: %s", content_type);
- url_con->headers = curl_slist_append(url_con->headers, tmp);
- }
- sprintf(tmp, "Content-length: %zu", 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_POSTFIELDSIZE, length);
+
+ if (content_type && (strlen(content_type) < 200))
+ {
+ sprintf(tmp, "Content-type: %s", content_type);
+ url_con->headers = curl_slist_append(url_con->headers, tmp);
+ }
+
+ sprintf(tmp, "Content-length: %zu", length);
+ url_con->headers = curl_slist_append(url_con->headers, tmp);
}
switch (url_con->condition)
{
case ECORE_CON_URL_TIME_NONE:
- curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMECONDITION,
+ curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMECONDITION,
CURL_TIMECOND_NONE);
- break;
+ break;
+
case ECORE_CON_URL_TIME_IFMODSINCE:
- curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMECONDITION,
+ curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMECONDITION,
CURL_TIMECOND_IFMODSINCE);
- curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMEVALUE, url_con->time);
- break;
+ curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMEVALUE, url_con->time);
+ break;
+
case ECORE_CON_URL_TIME_IFUNMODSINCE:
- curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMECONDITION,
+ curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMECONDITION,
CURL_TIMECOND_IFUNMODSINCE);
- curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMEVALUE, url_con->time);
- break;
+ curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMEVALUE, url_con->time);
+ break;
+
case ECORE_CON_URL_TIME_LASTMOD:
- curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMECONDITION,
+ curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMECONDITION,
CURL_TIMECOND_LASTMOD);
- curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMEVALUE, url_con->time);
- break;
+ curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMEVALUE, url_con->time);
+ break;
}
/* Additional headers */
EINA_LIST_FOREACH(url_con->additional_headers, l, s)
- url_con->headers = curl_slist_append(url_con->headers, s);
+ url_con->headers = curl_slist_append(url_con->headers, s);
curl_easy_setopt(url_con->curl_easy, CURLOPT_HTTPHEADER, url_con->headers);
* @ingroup Ecore_Con_Url_Group
*/
EAPI int
-ecore_con_url_ftp_upload(Ecore_Con_Url *url_con, const char *filename, const char *user, const char *pass, const char *upload_dir)
+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];
if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
{
- ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, "ecore_con_url_ftp_upload");
- return 0;
+ ECORE_MAGIC_FAIL(url_con,
+ ECORE_MAGIC_CON_URL,
+ "ecore_con_url_ftp_upload");
+ return 0;
}
- if (url_con->active) return 0;
- if (!url_con->url) return 0;
+ if (url_con->active)
+ return 0;
+
+ if (!url_con->url)
+ return 0;
+
if (filename)
{
- char tmp[PATH_MAX];
+ char tmp[PATH_MAX];
+
+ snprintf(tmp, PATH_MAX, "%s", filename);
- snprintf(tmp, PATH_MAX, "%s", filename);
+ if (stat(filename, &file_info))
+ return 0;
- if (stat(filename, &file_info)) return 0;
- fd = fopen(filename, "rb");
- if (upload_dir)
- snprintf(url, sizeof(url), "ftp://%s/%s/%s", url_con->url,
+ fd = fopen(filename, "rb");
+ if (upload_dir)
+ 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,
+ else
+ snprintf(url, sizeof(url), "ftp://%s/%s", url_con->url,
basename(tmp));
- snprintf(userpwd, sizeof(userpwd), "%s:%s", user, pass);
- curl_easy_setopt(url_con->curl_easy, CURLOPT_INFILESIZE_LARGE,
+
+ snprintf(userpwd, sizeof(userpwd), "%s:%s", user, pass);
+ 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_USERPWD, userpwd);
- curl_easy_setopt(url_con->curl_easy, CURLOPT_UPLOAD, 1);
- curl_easy_setopt(url_con->curl_easy, CURLOPT_READFUNCTION,
+ curl_easy_setopt(url_con->curl_easy, CURLOPT_USERPWD, userpwd);
+ curl_easy_setopt(url_con->curl_easy, CURLOPT_UPLOAD, 1);
+ curl_easy_setopt(url_con->curl_easy, CURLOPT_READFUNCTION,
_ecore_con_url_read_cb);
- curl_easy_setopt(url_con->curl_easy, CURLOPT_READDATA, fd);
- ecore_con_url_url_set(url_con, url);
+ curl_easy_setopt(url_con->curl_easy, CURLOPT_READDATA, fd);
+ ecore_con_url_url_set(url_con, url);
- return _ecore_con_url_perform(url_con);
+ return _ecore_con_url_perform(url_con);
}
else
- return 0;
+ return 0;
+
#else
return 0;
url_con = NULL;
}
/**
- * Send a Curl httppost
+ * Send a Curl httppost
* @return 1 on success, 0 on error.
* @ingroup Ecore_Con_Url_Group
*/
ecore_con_url_http_post_send(Ecore_Con_Url *url_con, void *httppost)
{
#ifdef HAVE_CURL
- if (url_con->post)
- curl_formfree(url_con->post);
- url_con->post = NULL;
+ if (url_con->post)
+ curl_formfree(url_con->post);
+
+ url_con->post = NULL;
+
+ if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
+ {
+ ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL,
+ "ecore_con_url_http_post_send");
+ return 0;
+ }
+
+ url_con->post = httppost;
+
+ if (url_con->active)
+ return 0;
- if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
- {
- ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, "ecore_con_url_http_post_send");
+ if (!url_con->url)
return 0;
- }
-
- url_con->post = httppost;
-
- if (url_con->active) return 0;
- if (!url_con->url) return 0;
-
- curl_easy_setopt(url_con->curl_easy, CURLOPT_HTTPPOST, httppost);
-
- return ecore_con_url_send(url_con, NULL, 0, NULL);
+
+ curl_easy_setopt(url_con->curl_easy, CURLOPT_HTTPPOST, httppost);
+
+ return ecore_con_url_send(url_con, NULL, 0, NULL);
#else
- return 0;
- url_con = NULL;
+ return 0;
+ url_con = NULL;
#endif
}
#ifdef HAVE_CURL
if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
{
- ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, "ecore_con_url_verbose_set");
- return;
+ ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL,
+ "ecore_con_url_verbose_set");
+ return;
}
- if (url_con->active) return;
- if (!url_con->url) return;
- if (verbose == EINA_TRUE)
- curl_easy_setopt(url_con->curl_easy, CURLOPT_VERBOSE, 1);
+ if (url_con->active)
+ return;
+
+ if (!url_con->url)
+ return;
+
+ if (verbose ==
+ EINA_TRUE)
+ curl_easy_setopt(url_con->curl_easy, CURLOPT_VERBOSE,
+ 1);
else
- curl_easy_setopt(url_con->curl_easy, CURLOPT_VERBOSE, 0);
+ curl_easy_setopt(url_con->curl_easy, CURLOPT_VERBOSE, 0);
+
#endif
}
#ifdef HAVE_CURL
if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
{
- ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, "ecore_con_url_ftp_use_epsv_set");
- return;
+ ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL,
+ "ecore_con_url_ftp_use_epsv_set");
+ return;
}
- if (url_con->active) return;
- if (!url_con->url) return;
- if (use_epsv == EINA_TRUE)
- curl_easy_setopt(url_con->curl_easy, CURLOPT_FTP_USE_EPSV, 1);
+ if (url_con->active)
+ return;
+
+ if (!url_con->url)
+ return;
+
+ if (use_epsv ==
+ EINA_TRUE)
+ curl_easy_setopt(url_con->curl_easy, CURLOPT_FTP_USE_EPSV,
+ 1);
else
- curl_easy_setopt(url_con->curl_easy, CURLOPT_FTP_USE_EPSV, 0);
+ curl_easy_setopt(url_con->curl_easy, CURLOPT_FTP_USE_EPSV, 0);
+
#endif
}
Ecore_Con_Url *url_con;
int deleted = 0;
- if (!_url_con_list) return 0;
+ if (!_url_con_list)
+ 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;
}
Ecore_Con_Url *url_con;
int activated = 0;
- if (!_url_con_list) return 0;
+ if (!_url_con_list)
+ return 0;
EINA_LIST_FOREACH(_url_con_list, l, url_con)
- {
- if (url_con->fd_handler == NULL && 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 == NULL && 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;
}
url_con = (Ecore_Con_Url *)userp;
- if (!url_con) return -1;
+ if (!url_con)
+ return -1;
+
if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
{
- ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, "ecore_con_url_data_cb");
- return -1;
+ ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, "ecore_con_url_data_cb");
+ return -1;
}
url_con->received += real_size;
if (url_con->write_fd < 0)
{
- e = 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_con_event_url_free, NULL);
- }
+ e =
+ 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_con_event_url_free, NULL);
+ }
}
else
{
- ssize_t count = 0;
- size_t total_size = real_size;
- size_t offset = 0;
-
- while (total_size > 0)
- {
- count = write(url_con->write_fd, (char*) buffer + offset, total_size);
- if (count < 0)
- {
- if (errno != EAGAIN && errno != EINTR) return -1;
- }
- else
- {
- total_size -= count;
- offset += count;
- }
- }
+ ssize_t count = 0;
+ size_t total_size = real_size;
+ size_t offset = 0;
+
+ while (total_size > 0)
+ {
+ count = write(url_con->write_fd,
+ (char *)buffer + offset,
+ total_size);
+ if (count < 0)
+ {
+ if (errno != EAGAIN && errno != EINTR)
+ return -1;
+ }
+ else
+ {
+ total_size -= count;
+ offset += count;
+ }
+ }
}
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); \
- } \
- } \
-}
+ { \
+ 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)
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;
+ char *header = malloc(sizeof(char) * (real_size + 1));
+ if (!header)
+ return real_size;
+
memcpy(header, ptr, real_size);
header[real_size] = '\0';
url_con->response_headers = eina_list_append(url_con->response_headers,
- header);
+ header);
return real_size;
}
static int
-_ecore_con_url_progress_cb(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow)
+_ecore_con_url_progress_cb(void *clientp, double dltotal, double dlnow,
+ double ultotal,
+ double ulnow)
{
- Ecore_Con_Event_Url_Progress *e;
+ Ecore_Con_Event_Url_Progress *e;
Ecore_Con_Url *url_con;
url_con = clientp;
e = malloc(sizeof(Ecore_Con_Event_Url_Progress));
if (e)
{
- e->url_con = url_con;
- e->down.total = dltotal;
- e->down.now = dlnow;
- e->up.total = ultotal;
- e->up.now = ulnow;
- ecore_event_add(ECORE_CON_EVENT_URL_PROGRESS, e,
+ e->url_con = url_con;
+ e->down.total = dltotal;
+ e->down.now = dlnow;
+ e->up.total = ultotal;
+ e->up.now = ulnow;
+ ecore_event_add(ECORE_CON_EVENT_URL_PROGRESS, e,
_ecore_con_event_url_free, NULL);
}
{
size_t retcode = fread(ptr, size, nitems, stream);
- if (ferror((FILE*)stream))
+ if (ferror((FILE *)stream))
{
fclose(stream);
return CURL_READFUNC_ABORT;
- }
- else if ((retcode == 0) || (retcode < nitems))
+ }
+ else if ((retcode == 0) || (retcode < nitems))
{
- fclose((FILE*)stream);
+ fclose((FILE *)stream);
return 0;
}
+
INF("*** We read %zu bytes from file", retcode);
return retcode;
}
url_con->active = 1;
curl_multi_add_handle(curlm, url_con->curl_easy);
/* This one can't be stopped, or the download never start. */
- while (curl_multi_perform(curlm, &still_running) == CURLM_CALL_MULTI_PERFORM);
+ while (curl_multi_perform(curlm, &still_running) == CURLM_CALL_MULTI_PERFORM) ;
completed_immediately = _ecore_con_url_process_completed_jobs(url_con);
if (!completed_immediately)
{
- if (url_con->fd_handler)
- ecore_main_fd_handler_del(url_con->fd_handler);
- url_con->fd_handler = NULL;
-
- /* url_con still active -- set up an fd_handler */
- FD_ZERO(&read_set);
- FD_ZERO(&write_set);
- FD_ZERO(&exc_set);
-
- /* Stupid curl, why can't I get the fd to the current added job? */
- curl_multi_fdset(curlm, &read_set, &write_set, &exc_set, &fd_max);
- for (fd = 0; fd <= fd_max; fd++)
- {
- if (!FD_ISSET(fd, &_current_fd_set))
- {
- flags = 0;
- if (FD_ISSET(fd, &read_set)) flags |= ECORE_FD_READ;
- if (FD_ISSET(fd, &write_set)) flags |= ECORE_FD_WRITE;
- if (FD_ISSET(fd, &exc_set)) flags |= ECORE_FD_ERROR;
- if (flags)
- {
- long ms = 0;
-
- curl_multi_timeout(curlm, &ms);
- if (ms == 0) 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);
- break;
- }
- }
- }
- if (!url_con->fd_handler)
- {
- /* Failed to set up an fd_handler */
- ecore_timer_freeze(_curl_timeout);
- curl_multi_remove_handle(curlm, url_con->curl_easy);
- url_con->active = 0;
- url_con->fd = -1;
- return 0;
- }
- ecore_timer_thaw(_curl_timeout);
+ if (url_con->fd_handler)
+ ecore_main_fd_handler_del(url_con->fd_handler);
+
+ url_con->fd_handler = NULL;
+
+ /* url_con still active -- set up an fd_handler */
+ FD_ZERO(&read_set);
+ FD_ZERO(&write_set);
+ FD_ZERO(&exc_set);
+
+ /* Stupid curl, why can't I get the fd to the current added job? */
+ curl_multi_fdset(curlm, &read_set, &write_set, &exc_set, &fd_max);
+ for (fd = 0; fd <= fd_max; fd++)
+ {
+ if (!FD_ISSET(fd, &_current_fd_set))
+ {
+ flags = 0;
+ if (FD_ISSET(fd, &read_set))
+ flags |= ECORE_FD_READ;
+
+ if (FD_ISSET(fd, &write_set))
+ flags |= ECORE_FD_WRITE;
+
+ if (FD_ISSET(fd, &exc_set))
+ flags |= ECORE_FD_ERROR;
+
+ if (flags)
+ {
+ long ms = 0;
+
+ curl_multi_timeout(curlm, &ms);
+ if (ms == 0)
+ 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);
+ break;
+ }
+ }
+ }
+ if (!url_con->fd_handler)
+ {
+ /* Failed to set up an fd_handler */
+ ecore_timer_freeze(_curl_timeout);
+ curl_multi_remove_handle(curlm, url_con->curl_easy);
+ url_con->active = 0;
+ url_con->fd = -1;
+ return 0;
+ }
+
+ ecore_timer_thaw(_curl_timeout);
}
return 1;
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);
if (done)
{
- _ecore_con_url_restart_fd_handler();
- _fd_idler_handler = NULL;
+ _ecore_con_url_restart_fd_handler();
+ _fd_idler_handler = NULL;
+
+ if (!_url_con_list)
+ ecore_timer_freeze(_curl_timeout);
- if (!_url_con_list)
- ecore_timer_freeze(_curl_timeout);
- return data == (void*) 0xACE ? ECORE_CALLBACK_RENEW : ECORE_CALLBACK_CANCEL;
+ return data ==
+ (void *)0xACE ? ECORE_CALLBACK_RENEW : ECORE_CALLBACK_CANCEL;
}
return ECORE_CALLBACK_RENEW;
}
static Eina_Bool
-_ecore_con_url_fd_handler(void *data __UNUSED__, Ecore_Fd_Handler *fd_handler __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 == NULL)
- _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;
}
/* Loop jobs and check if any are done */
while ((curlmsg = curl_multi_info_read(curlm, &n_remaining)) != NULL)
{
- if (curlmsg->msg != CURLMSG_DONE) 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(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_list = eina_list_remove(_url_con_list, url_con);
- url_con->active = 0;
- 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;
- }
-
- _url_complete_push_event(ECORE_CON_EVENT_URL_COMPLETE, e);
- }
- curl_multi_remove_handle(curlm, url_con->curl_easy);
- break;
- }
- }
+ if (curlmsg->msg != CURLMSG_DONE)
+ 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(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_list = eina_list_remove(_url_con_list, url_con);
+ url_con->active = 0;
+ 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;
+ }
+
+ _url_complete_push_event(ECORE_CON_EVENT_URL_COMPLETE, e);
+ }
+
+ curl_multi_remove_handle(curlm, url_con->curl_easy);
+ break;
+ }
+ }
}
return job_matched;