summaryrefslogtreecommitdiff
path: root/src/lib/ecore_con
diff options
context:
space:
mode:
authorGustavo Sverzut Barbieri <barbieri@profusion.mobi>2017-04-08 19:03:53 -0300
committerGustavo Sverzut Barbieri <barbieri@profusion.mobi>2017-04-08 19:21:44 -0300
commitc90865ca485acc44fbfa680e1382b9a2a41fe350 (patch)
tree3d633c43d3dea12b7aa60fb139cd7638f46e934b /src/lib/ecore_con
parent314f2763c6af24d76be400404571cf4ca77cb319 (diff)
ecore_con_legacy: fix legacy compatibility for ecore_con_server_send()
Since efl_net_ssl_context is immutable for a dialer and we create the dialer with the context, the SSL cases uses a trick to postpone dialer creation using a job, then it allows one main loop iteration for the user to call various ecore_con_server_ssl_*() methods. However this breaks immediate ecore_con_server_send() after ecore_con_server_connect() as used to be allowed and used by azy/erssd. Most people wouldn't notice that, since the most common case is to either use ecore_con_url (which uses cURL and a complete different code path) OR they would wait for ECORE_CON_EVENT_SERVER_ADD prior to sending data. Nonetheless it was a compatibility issue and must be fixed. Fixes T5339
Diffstat (limited to 'src/lib/ecore_con')
-rw-r--r--src/lib/ecore_con/ecore_con_legacy.c52
1 files changed, 50 insertions, 2 deletions
diff --git a/src/lib/ecore_con/ecore_con_legacy.c b/src/lib/ecore_con/ecore_con_legacy.c
index 8cbb5967e6..fd64aabf3c 100644
--- a/src/lib/ecore_con/ecore_con_legacy.c
+++ b/src/lib/ecore_con/ecore_con_legacy.c
@@ -32,6 +32,9 @@ struct _Ecore_Con_Server
32 Eo *server; 32 Eo *server;
33 struct { 33 struct {
34 Efl_Future *job; 34 Efl_Future *job;
35 Eina_Binbuf *pending_send; /* until job is fulfilled, no dialer exists,
36 * this binbuf allows immediate
37 * ecore_con_server_send() in that situation */
35 Eo *clients_ctx; 38 Eo *clients_ctx;
36 Eina_List *certs; 39 Eina_List *certs;
37 Eina_List *privkeys; 40 Eina_List *privkeys;
@@ -980,6 +983,12 @@ _ecore_con_server_free(Ecore_Con_Server *svr)
980 983
981 if (svr->ssl.job) efl_future_cancel(svr->ssl.job); 984 if (svr->ssl.job) efl_future_cancel(svr->ssl.job);
982 985
986 if (svr->ssl.pending_send)
987 {
988 eina_binbuf_free(svr->ssl.pending_send);
989 svr->ssl.pending_send = NULL;
990 }
991
983 if (svr->event_count) return; 992 if (svr->event_count) return;
984 993
985 EINA_LIST_FREE(svr->ssl.certs, str) eina_stringshare_del(str); 994 EINA_LIST_FREE(svr->ssl.certs, str) eina_stringshare_del(str);
@@ -1339,6 +1348,13 @@ _ecore_con_server_dialer_connected(void *data, const Efl_Event *event EINA_UNUSE
1339 svr->ssl.upgrading = EINA_FALSE; 1348 svr->ssl.upgrading = EINA_FALSE;
1340 INF("svr=%p upgraded to SSL at %s (%s)", svr, efl_net_dialer_address_dial_get(svr->dialer), efl_net_socket_address_remote_get(svr->dialer)); 1349 INF("svr=%p upgraded to SSL at %s (%s)", svr, efl_net_dialer_address_dial_get(svr->dialer), efl_net_socket_address_remote_get(svr->dialer));
1341 _ecore_con_post_event_server_upgrade(svr); 1350 _ecore_con_post_event_server_upgrade(svr);
1351 if (svr->ssl.pending_send)
1352 {
1353 Eina_Slice slice = eina_binbuf_slice_get(svr->ssl.pending_send);
1354 ecore_con_server_send(svr, slice.mem, slice.len);
1355 eina_binbuf_free(svr->ssl.pending_send);
1356 svr->ssl.pending_send = NULL;
1357 }
1342 return; 1358 return;
1343 } 1359 }
1344 1360
@@ -1968,6 +1984,18 @@ _ecore_con_server_dialer_ssl_job(void *data, const Efl_Event *event EINA_UNUSED)
1968 efl_io_buffered_stream_inner_io_get(svr->dialer), 1984 efl_io_buffered_stream_inner_io_get(svr->dialer),
1969 efl_net_dialer_ssl_context_get(efl_io_buffered_stream_inner_io_get(svr->dialer))); 1985 efl_net_dialer_ssl_context_get(efl_io_buffered_stream_inner_io_get(svr->dialer)));
1970 1986
1987 if (svr->ssl.pending_send)
1988 {
1989 /* if ecore_con_server_send() was called before the job completed
1990 * then we queued data there, flush to dialer.
1991 * See https://phab.enlightenment.org/T5339
1992 */
1993 Eina_Slice slice = eina_binbuf_slice_get(svr->ssl.pending_send);
1994 ecore_con_server_send(svr, slice.mem, slice.len);
1995 eina_binbuf_free(svr->ssl.pending_send);
1996 svr->ssl.pending_send = NULL;
1997 }
1998
1971 return; 1999 return;
1972 2000
1973 error_dial: 2001 error_dial:
@@ -2271,9 +2299,29 @@ ecore_con_server_send(Ecore_Con_Server *svr, const void *data, int size)
2271 ECORE_CON_SERVER_CHECK_RETURN(svr, 0); 2299 ECORE_CON_SERVER_CHECK_RETURN(svr, 0);
2272 EINA_SAFETY_ON_NULL_RETURN_VAL(data, 0); 2300 EINA_SAFETY_ON_NULL_RETURN_VAL(data, 0);
2273 EINA_SAFETY_ON_TRUE_RETURN_VAL(size < 1, 0); 2301 EINA_SAFETY_ON_TRUE_RETURN_VAL(size < 1, 0);
2274 EINA_SAFETY_ON_TRUE_RETURN_VAL(svr->ssl.upgrading, 0);
2275 2302
2276 EINA_SAFETY_ON_NULL_RETURN_VAL(svr->dialer, 0); 2303 /* while upgrading or no dialer (due SSL dialer being created on
2304 * the next mainloop iteration from a job as described from
2305 * ecore_con_server_connect()), queue pending data and send as soon
2306 * as the dialer is assigned.
2307 *
2308 * This allows immediate usage of ecore_con_server_send() after
2309 * ecore_con_server_connect() as the old API did and needed by
2310 * https://phab.enlightenment.org/T5339
2311 */
2312 if ((svr->ssl.upgrading) || (!svr->dialer))
2313 {
2314 Eina_Bool r;
2315 if (!svr->ssl.pending_send)
2316 {
2317 svr->ssl.pending_send = eina_binbuf_new();
2318 EINA_SAFETY_ON_NULL_RETURN_VAL(svr->ssl.pending_send, 0);
2319 }
2320 r = eina_binbuf_append_length(svr->ssl.pending_send, data, size);
2321 EINA_SAFETY_ON_FALSE_RETURN_VAL(r, 0);
2322 return size;
2323 }
2324
2277 err = efl_io_writer_write(svr->dialer, &slice, NULL); 2325 err = efl_io_writer_write(svr->dialer, &slice, NULL);
2278 if (err) 2326 if (err)
2279 { 2327 {