Commit Graph

428 Commits

Author SHA1 Message Date
Gustavo Sverzut Barbieri f4306d654d ecore_con: Ecore_Con_Server now on top of Efl_Net!
This is a major work and unfortunately couldn't be split into smaller
pieces as old code was highly coupled.

Ecore_Con_Server is now a wrapper around Efl_Net_Dialer_Simple
(ecore_con_server_connect()) and Efl_Net_Server_Simple
(ecore_con_server_add()), doing all that the original version did with
some fixes so ecore_con_ssl_server_upgrade() and
ecore_con_ssl_client_upgrade() are more usable -- see the examples and
-t/--type=tcp+ssl.

I tried to be bug-compatible, with code annotations where things
doesn't make sense. This was based on ecore_con_suite tests and some
manual experimenting with the examples, these can be helpful if you
find regressions (report/assign to me).
2016-12-10 08:44:06 -02:00
Gustavo Sverzut Barbieri c5fc33d378 ecore_con_url: only close the request if we got a final response.
if we're doing 30x redirects or anything else, keep going. If it's an
error it will be reported later, otherwise EOS. Fact is we're only
interested if 20x.
2016-12-09 22:18:27 -02:00
Gustavo Sverzut Barbieri 2945b972ef efl_net_dialer_http: fix delete-from-CURL callback.
This was annoying to identify as the sequence is kinda difficult to
get, but Terminology was doing a HEAD request and it was triggering
this case in particular.

Fixes T4975.
2016-12-09 22:18:18 -02:00
Gustavo Sverzut Barbieri fb0e716c1a efl_net: fix formatting warnings from windows. 2016-12-09 19:33:40 -02:00
Gustavo Sverzut Barbieri 345bba3ef1 efl_net_dialer_http: fix build on windows.
Windows time_t is not a long, but long-long, then stick with int64_t
so it works everywhere (converts to time_t internally).

And there is no gmtime_r(), then use the gmtime() if not detected.
2016-12-09 19:32:14 -02:00
Gustavo Sverzut Barbieri 324b4e93f5 efl_net_server_unix: do not mkpath for abstract sockets. 2016-12-09 13:47:04 -02:00
Gustavo Sverzut Barbieri 5939f0d9c2 efl_net_dialer: emit 'resolved' even if connection failed.
If we resolved the address but couldn't connect, use
efl_net_socket_address_remote_set() and emit
EFL_NET_DIALER_EVENT_RESOLVED.
2016-12-09 13:47:04 -02:00
Gustavo Sverzut Barbieri afdbe897a0 efl_net: optimize serving of IP addresses.
If we can parse the IP using inet_pton() and the port, there is no
reason to call getaddrinfo() in a thread.

This is required since ecore_con_suite (for ecore_con-over-efl_net) will
assume the server is running as soon as it's created.
2016-12-09 13:47:04 -02:00
Gustavo Sverzut Barbieri b2bbc1c188 efl_net_server_simple: fix leak reported by eo_debug
eo_debug now reports leaked objects, which is very nice :-)
2016-12-09 13:47:04 -02:00
Gustavo Sverzut Barbieri 9e682774d2 efl_net_dialer_socket: allow us to create a dialer from existing object.
If we want to upgrade a dialer, then we must have a way to know if
that socket has already adopted another socket so we don't create it.

We can't simply use efl_net_socket_ssl, otherwise we'd miss some
methods such as efl_net_dialer_address_dial_get() and events such as
connected.
2016-12-09 13:47:04 -02:00
Gustavo Sverzut Barbieri 3fc0fbba42 efl_net_socket_fd: do not close stdout if nothing was set.
if we create an object, say a TCP dialer, and don't connect/bind, then
we have no FD (=0). If we set FD to INVALID_SOCKET on start, other
parts of the code will fail since they consider that "closed", but
we're not closed yet.

Then check for family == AF_UNSPEC && fd == 0, if so don't close it.
2016-12-09 13:47:03 -02:00
Gustavo Sverzut Barbieri cfc21c16fb efl_net_ssl: do not access torn down sockets.
OpenSSL crashes if given a NULL pointer, then be safe and remember if
we did the tear down -- print error so bugs can be identified more
easily.
2016-12-09 13:47:03 -02:00
Gustavo Sverzut Barbieri c97111bf3c efl_net_ssl_conn-openssl: fix dlsym() for X509_check_ip_asc.
At least in ArchLinux the function has no "_" in the symbol name,
matching perfectly what's in the header.

If in other systems it misses such symbol, then check for both.
2016-12-09 13:47:03 -02:00
Gustavo Sverzut Barbieri 17e0204ab3 efl_net_server_ssl: monitor context del and unref on destructor.
we're leaking ssl_ctx on destruction, also monitor it so we don't
access stale data.
2016-12-08 16:00:01 -02:00
Gustavo Sverzut Barbieri 7c7ea6be06 efl_net_ssl_context: check and document constructor only properties.
The context is shared and thus these lists should be static once
object is created.
2016-12-08 16:00:01 -02:00
Gustavo Sverzut Barbieri b64df5e323 efl_net_dialer_ssl: fix copy&paste too much. 2016-12-08 16:00:01 -02:00
Carsten Haitzler 96d90fa5d6 efl_net check openssl x509 check o runtime dlsym checks
this fixes T4814
2016-12-06 16:16:23 +09:00
Gustavo Sverzut Barbieri 2cb3466ddf ecore_con_url: now on top of efl_net_dialer_http.
Rewrite Ecore_Con_Url as a non-Eo (since it's just legacy) that is
built on top of Efl_Net_Dialer_Http.

Since there are some legacy behavior we do not want to expose in the
new classes, hack around and manipulate the curl_easy_setopt()
directly in those cases.

This includes the cookies: there is no reason why we should expose
independent files for read (COOKIEFILE) and write (COOKIEJAR), real
world applications can manipulate the files directly, like copying
from a template to a RDWR before using, etc.
2016-11-29 16:03:14 -02:00
Gustavo Sverzut Barbieri da143edd8c efl_net_dialer_http: POST also allows resizing.
resizing the dialer results in changing the request content length,
which is useful when uploading files AND posting data.
2016-11-29 16:03:13 -02:00
Gustavo Sverzut Barbieri 4aca800bde efl_net_dialer_http: export SSL controls.
verify peer, hostname and set CA/CRL files.
2016-11-29 16:02:25 -02:00
Gustavo Sverzut Barbieri 3cf20ea8e8 efl_net_dialer_http: special headers and date parse/serialize.
CURL needs some special curl_easy_setopt() calls to enable automatic
gzip deflate (CURLOPT_ENCODING) and
If-Modified-Since/If-Unmodified-Since logic.

As If-Modified-Since/If-Unmodified-Since requires a timestamp string,
let's expose class methods to handle those.
2016-11-29 16:02:25 -02:00
Gustavo Sverzut Barbieri 5c7b984746 efl_net_dialer_http: only close if not closed yet.
since eos_set() emits an event the user may have closed from there.
2016-11-29 16:02:25 -02:00
Gustavo Sverzut Barbieri b4ed72518d efl_net_dialer_http: export read size.
In the legacy wrapper I'll need that.
2016-11-29 16:02:25 -02:00
Andrii Kroitor 03f20efaf0 ecore_con: fix work on Windows
Per aspera ad astra.
One little missing star was breaking all EFL UI applications.
2016-11-29 15:15:26 +02:00
Jee-Yong Um 0e2a2cbacf eolian: remove all duplicated affix
Summary:
Currently eolian abbreviates when only the last word of class name and
the first word of method name are same, but this patch abbreviates
generated c name of function to remove all duplicated affix.
For example, "efl_io_closer_fd_closer_fd_set" will be "efl_io_closer_fd_set".

Reviewers: jpeg

Subscribers: cedric

Differential Revision: https://phab.enlightenment.org/D4430

Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
2016-11-28 11:35:27 -08:00
Gustavo Sverzut Barbieri 48049a4ce2 efl_net_server_unix: add leading_directories_create property.
This allows us to crete any parent directories that are missing.
2016-11-25 18:01:29 -02:00
Gustavo Sverzut Barbieri 167ff29ea0 efl_net_{socket,dialer,server}_simple: easy to use, buffered network sockets.
The low level I/O primitives are powerful but adds some complexity to
use, for bi-directional streaming communication one ends creating two
Efl.Io.Queue and two Efl.Io.Copier to pipe data to socket when it can
operate.

Then encapsulate the socket using the new Efl.Io.Buffered_Stream, this
will allow the socket, be a dialer or a server client, to be operated
as a single handle that internally carries about the buffering for
you.

As one can see in the examples, compared to their "manual"
alternatives they are very easy to use, ressembling
Ecore_Con_Server/Ecore_Con_Client, but also offers line-based
delimiters and the possibility to let the socket to handle queueing
for you in case you received partial messages (just do not
read/clear/discard the received data).
2016-11-25 17:27:32 -02:00
Gustavo Sverzut Barbieri 410d65900c efl_net_server: add 'client_announce', share logic and fix a bug.
I just realized that if a client is not referenced it would leak in
the 'ssl' server as we must del it.

However, if we del the SSL socket, we're going to close the underlying
TCP. But we're from the TCP "client,add" callback and this causes
issues since "closed" will be emitted, our close callback will
unparent the client, which lead to it being deleted.

The proper solution is to only monitor "closed" if the client is
accepted. Otherwise we just check if it was closed, if we're the
parent, etc...

Fixing this in all servers were painful, we could share since most
inherit from Efl.Net.Server.Fd. Then add the "client_announce"
protected method to do it, and document how it should work.
2016-11-25 17:25:18 -02:00
Gustavo Sverzut Barbieri c534d79124 efl_net_socket_fd: stop monitoring fd on EOS.
There was a bug that if the remote peer closed the connection, it
would trigger 'read' event, which would read 0 bytes, flagging as
EOS... but then marking as "can_read", which was wrong.

Just stop monitoring the events and fix that.
2016-11-25 17:25:18 -02:00
Gustavo Sverzut Barbieri c2cb5defe3 efl_net_dialer_http: use efl_loop_fd now that it's fixed.
now that efl_loop_fd manages callbacks -> Ecore_Fd_Handler properly,
we can remove the old code.
2016-11-24 02:13:32 -02:00
Gustavo Sverzut Barbieri 7edc1ef49d efl_net_socket_fd: fix copy & paste too much. 2016-11-24 02:11:56 -02:00
Gustavo Sverzut Barbieri 35cdde67d2 efl_net_socket_fd: do not spin on fd monitoring.
If we let the user know he can read or write, stop monitoring
otherwise fd handler will constanly report of data to read/write until
its actually done, which would clear the kernel flag.

Since we use "can_read" and "can_write" for that, toggle the callback
connection that manages the actual Ecore_Fd_Handler monitor.
2016-11-24 00:45:55 -02:00
Gustavo Sverzut Barbieri 92a3361deb efl_net_server_fd: do not spin if clients can be accepted.
If we have incoming clients but we do not want to drop or handle then,
stop monitoring the fd's read, otherwise we constantly spin the main
loop.
2016-11-24 00:42:54 -02:00
Gustavo Sverzut Barbieri d0b6aa6596 efl_net_server_unix: do bind() from serve() method.
Instead of adding a job to create the socket and call bind(), do it
straight from the serve() method, this allows the caller to set
umask(), permissions and so on.

Document this behavior in the class, since we can't extend the
method's documentation.
2016-11-23 18:38:24 -02:00
Gustavo Sverzut Barbieri 2f91934502 ecore_con: export function to create local path string.
The new efl_net code won't compose any path own its own, allowing the
user to connect to non-EFL systems.

However we need a way to use the same path Ecore_Con_Server does, so
we can reach it. Then export and use ecore_con_local_path_new() to do
exactly that.
2016-11-23 12:57:10 -02:00
Stefan Schmidt 9b0bc5e029 docs: ecore_con: fill last gaps ion ecore_con eo file documentation 2016-11-23 14:16:24 +01:00
Gustavo Sverzut Barbieri 6062109707 efl_net: proper format for SOCKET.
SOCKET is defined as uintptr_t (uint_ptr as called on Windows) and
thus will vary its size based on 32 or 64 bits.

Then we should format with PRIuPTR from inttypes.h, which is supported
since VisualStudio 2013
https://blogs.msdn.microsoft.com/vcblog/2013/07/19/c99-library-support-in-visual-studio-2013/
2016-11-22 11:03:57 -02:00
Jee-Yong Um 0f97d45dac fix doxygen warnings
Summary:
fix warnings while generating documents
- end of file while inside a group (eina_util.h)
- missing title after \defgroup
- ignoring title "Ecore_Con_Lib_Group" that does not match old title

Reviewers: Hermet

Subscribers: cedric, jpeg

Differential Revision: https://phab.enlightenment.org/D4420
2016-11-22 11:47:04 +09:00
Gustavo Sverzut Barbieri db4d4f8c87 efl_net_{control,session}: allow "none" backend.
Since connman is specific to linux, on other platforms just compile a
dummy "none" backend that will always report online and no other
details. This will be used in Windows, MacOS and other platforms that
still lack a proper backend.

The compile-time infrastructure also allows for networkmanager to be
added with ease, simply copy "efl_net*-none.c" or "efl_net*-connman.c"
to be a starting point and then add its specifics, adapting
configure.ac and Makefile_Ecore_Con.am
2016-11-18 18:20:25 -02:00
Gustavo Sverzut Barbieri 3f2881a458 efl_net: SOCKET_FMT is "long" on windows.
at least it seems so, let's see if warnings are gone.
2016-11-18 15:16:32 -02:00
Gustavo Sverzut Barbieri d6584673ea ecore_con (legacy) fix close()->closesocket() and valid fd check.
use the windows version and it will also work on UNIX due macros.
2016-11-18 14:21:21 -02:00
Gustavo Sverzut Barbieri dc3da201fd efl_net: remove warnings related to unused parameters.
if these options are not available, then cast "o" to void so it
doesn't trigger a warning, for example on Windows.
2016-11-18 14:21:21 -02:00
Gustavo Sverzut Barbieri c0f84d190f efl_net: fix missing SOCKET_FMT. 2016-11-18 14:21:21 -02:00
Stefan Schmidt f77a602a09 ecore_con: fix time to live value name and type
The time to live hop limit should not be named loopback and have a type that
can actuall hold the number of hops. It already was always uint8 in the code.
Just fix the eo file.
2016-11-18 16:20:55 +01:00
Gustavo Sverzut Barbieri 371a3332ef efl_net: remove getsockopt()/setsockopt() warning on windows.
windows is nasty and defines the value to be set or retrieved as
'char *', which triggers a warning when we use another kind of
pointer.

Partially addresses D4357.
2016-11-18 12:53:32 -02:00
Gustavo Sverzut Barbieri 8d24622f57 efl_net: remove send()/recv() warning on windows.
windows is nasty and defines the payload to be sent or received as
'char *', which triggers a warning when we use another kind of
pointer.

Partially addresses D4357.
2016-11-18 12:53:32 -02:00
Gustavo Sverzut Barbieri c3ddc8f09e efl_net: do not use sockaddr_un on Windows.
struct sockaddr_un doesn't exist on windows, so do not use it.

Partially addresses D4357.
2016-11-18 12:53:32 -02:00
Gustavo Sverzut Barbieri b322a3ae53 efl_net: define EAI_SYSTEM when it's not defined (ie: Windows).
its value is unimportant, just do not match any other EAI error value.

Partially fixes D4357.
2016-11-18 12:53:32 -02:00
Gustavo Sverzut Barbieri 090940c3ae efl_net: windows do not define AI_ADDRCONFIG.
do as for other missing bitwise flags and simply define to 0, reducing
need to ifdefs in the code.

This partially addresses D4357.
2016-11-18 12:53:32 -02:00
Gustavo Sverzut Barbieri 5818dc71da efl_net: use SOCKET_FMT to format SOCKET so it works on UNIX and Windows.
On Windows SOCKET is unsigned, thus will cause sign errors when
formatting with "%d" or comparing with signed values.

On UNIX it was quiet and easy to miss, thus a new #define can be used
to check for those. It will use 'unsigned long' as SOCKET, thus will
complain out loud and not even work correctly when using pointers on
64bits UNIX on mistakes -- which should improve the situation.

This helped to fix lots of missing conversions, all fixed.

This partially addresses D4357.
2016-11-18 12:53:32 -02:00