Commit graph

843 commits

Author SHA1 Message Date
Ashod Nakashian
67c3b9548d wsd: http: support shutting down the socket
Change-Id: I9559a126048abd79db37579b5a9ca7282b0485e5
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-06-24 07:08:55 +01:00
Ashod Nakashian
48b510d4f4 wsd: test: fix heap-use-after-free
In HttpRequestTests::test500GetStatuses, since we reused
the http::Session without removing from SocketPoll,
it is possible for the poll thread to access the
Session object while we create a new request, where
we replace its Response and Socket members.

To avoid that, we can try to remove the http::Session
instance from the SocketPoll. Alternatively, we
can create a new one for each request, which is
what we do here.

Below is the results of ASan, for the record.

==949494==ERROR: AddressSanitizer: heap-use-after-free on address 0x61700005afe0 at pc 0x55dc0c092c75 bp 0x7f8b539e5a10 sp 0x7f8b539e5a08
READ of size 4 at 0x61700005afe0 thread T10 (HttpAsyncReqPol)
    #0 0x55dc0c092c74 in http::Response::logPrefix(std::ostream&) const /home/ash/prj/lo/online/test/../net/HttpRequest.hpp:835:66
    #1 0x55dc0c08f499 in http::Response::readData(char const*, long) /home/ash/prj/lo/online/test/../net/HttpRequest.cpp:641:5
    #2 0x55dc0c0998c9 in http::Session::handleIncomingMessage(SocketDisposition&) /home/ash/prj/lo/online/test/../net/HttpRequest.hpp:1248:41
    #3 0x55dc0c0f0c3b in StreamSocket::handlePoll(SocketDisposition&, std::chrono::time_point<std::chrono::_V2::steady_clock, std::chrono::duration<long, std::ratio<1l, 1000000000l> > >, int) /home/ash/prj/lo/online/test/../net/Socket.hpp:1339:33
    #4 0x55dc0c0b092d in SocketPoll::poll(long) /home/ash/prj/lo/online/test/../net/Socket.cpp:444:34
    #5 0x55dc0c10407c in SocketPoll::poll(std::chrono::duration<long, std::ratio<1l, 1000000l> >) /home/ash/prj/lo/online/test/../net/Socket.hpp:691:61
    #6 0x55dc0c10407c in SocketPoll::pollingThread() /home/ash/prj/lo/online/test/../net/Socket.hpp:648:13
    #7 0x55dc0c0ac445 in SocketPoll::pollingThreadEntry() /home/ash/prj/lo/online/test/../net/Socket.cpp:299:9
    #8 0x55dc0c12b6b9 in void std::__invoke_impl<void, void (SocketPoll::*)(), SocketPoll*>(std::__invoke_memfun_deref, void (SocketPoll::*&&)(), SocketPoll*&&) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/invoke.h:73:14
    #9 0x55dc0c12b590 in std::__invoke_result<void (SocketPoll::*)(), SocketPoll*>::type std::__invoke<void (SocketPoll::*)(), SocketPoll*>(void (SocketPoll::*&&)(), SocketPoll*&&) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/invoke.h:95:14
    #10 0x55dc0c12b574 in void std:🧵:_Invoker<std::tuple<void (SocketPoll::*)(), SocketPoll*> >::_M_invoke<0ul, 1ul>(std::_Index_tuple<0ul, 1ul>) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/thread:264:13
    #11 0x55dc0c12b463 in std:🧵:_Invoker<std::tuple<void (SocketPoll::*)(), SocketPoll*> >::operator()() /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/thread:271:11
    #12 0x55dc0c12b463 in std:🧵:_State_impl<std:🧵:_Invoker<std::tuple<void (SocketPoll::*)(), SocketPoll*> > >::_M_run() /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/thread:215:13
    #13 0x7f8b5a08cde3  (/usr/lib/x86_64-linux-gnu/libstdc++.so.6+0xd6de3) (BuildId: c90e6603c7cdf84713cd445700a575d3ea446d9b)
    #14 0x7f8b59e4c608 in start_thread /build/glibc-SzIz7B/glibc-2.31/nptl/pthread_create.c:477:8
    #15 0x7f8b59d44132 in __clone /build/glibc-SzIz7B/glibc-2.31/misc/../sysdeps/unix/sysv/linux/x86_64/clone.S:95

0x61700005afe0 is located 736 bytes inside of 744-byte region [0x61700005ad00,0x61700005afe8)
freed by thread T0 here:
LLVMSymbolizer: error reading file: No such file or directory
    #0 0x55dc0bfe43dd in operator delete(void*) (/home/ash/prj/lo/online/test/unithttplib+0x20d3dd) (BuildId: 7954f6bea5efa6c39ca02e7033c014e826b9f5fd)
    #1 0x55dc0c1fe168 in std::_Sp_counted_ptr<http::Response*, (__gnu_cxx::_Lock_policy)2>::_M_dispose() /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/shared_ptr_base.h:380:9
    #2 0x55dc0c033768 in std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release() /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/shared_ptr_base.h:158:6
    #3 0x55dc0c0335d5 in std::__shared_count<(__gnu_cxx::_Lock_policy)2>::~__shared_count() /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/shared_ptr_base.h:733:11
    #4 0x55dc0c1f972c in std::__shared_ptr<http::Response, (__gnu_cxx::_Lock_policy)2>::~__shared_ptr() /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/shared_ptr_base.h:1183:31
    #5 0x55dc0c1f972c in std::enable_if<__sp_is_constructible<http::Response, http::Response>::value, void>::type std::__shared_ptr<http::Response, (__gnu_cxx::_Lock_policy)2>::reset<http::Response>(http::Response*) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/shared_ptr_base.h:1309:4
    #6 0x55dc0c1f972c in http::Session::newRequest(http::Request) /home/ash/prj/lo/online/test/../net/HttpRequest.hpp:1174:19
    #7 0x55dc0c1ee08b in http::Session::asyncRequest(http::Request const&, SocketPoll&) /home/ash/prj/lo/online/test/../net/HttpRequest.hpp:1079:9
    #8 0x55dc0c1b718f in HttpRequestTests::test500GetStatuses() /home/ash/prj/lo/online/test/HttpRequestTests.cpp:515:9
    #9 0x55dc0c219ec9 in void std::__invoke_impl<void, void (HttpRequestTests::*&)(), HttpRequestTests*&>(std::__invoke_memfun_deref, void (HttpRequestTests::*&)(), HttpRequestTests*&) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/invoke.h:73:14
    #10 0x55dc0c219de0 in std::__invoke_result<void (HttpRequestTests::*&)(), HttpRequestTests*&>::type std::__invoke<void (HttpRequestTests::*&)(), HttpRequestTests*&>(void (HttpRequestTests::*&)(), HttpRequestTests*&) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/invoke.h:95:14
    #11 0x55dc0c219dbc in void std::_Bind<void (HttpRequestTests::* (HttpRequestTests*))()>::__call<void, 0ul>(std::tuple<>&&, std::_Index_tuple<0ul>) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/functional:416:11
    #12 0x55dc0c219d47 in void std::_Bind<void (HttpRequestTests::* (HttpRequestTests*))()>::operator()<void>() /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/functional:499:17
    #13 0x55dc0c219d47 in void std::__invoke_impl<void, std::_Bind<void (HttpRequestTests::* (HttpRequestTests*))()>&>(std::__invoke_other, std::_Bind<void (HttpRequestTests::* (HttpRequestTests*))()>&) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/invoke.h:60:14
    #14 0x55dc0c219d47 in std::enable_if<is_invocable_r_v<void, std::_Bind<void (HttpRequestTests::* (HttpRequestTests*))()>&>, void>::type std::__invoke_r<void, std::_Bind<void (HttpRequestTests::* (HttpRequestTests*))()>&>(std::_Bind<void (HttpRequestTests::* (HttpRequestTests*))()>&) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/invoke.h:110:2
    #15 0x55dc0c219a72 in std::_Function_handler<void (), std::_Bind<void (HttpRequestTests::* (HttpRequestTests*))()> >::_M_invoke(std::_Any_data const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/std_function.h:291:9
    #16 0x55dc0c09776b in std::function<void ()>::operator()() const /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/std_function.h:622:14
    #17 0x55dc0c219713 in CppUnit::TestCaller<HttpRequestTests>::runTest() /usr/include/cppunit/TestCaller.h:175:7
    #18 0x7f8b5ab23614 in CppUnit::TestCaseMethodFunctor::operator()() const (/usr/lib/x86_64-linux-gnu/libcppunit-1.15.so.1+0x24614) (BuildId: 4329d55843a6cf32b3e88d4d9aec95035315b163)
    #19 0x7ffdc354a41f  ([stack]+0x2b41f)

previously allocated by thread T0 here:
    #0 0x55dc0bfe3b7d in operator new(unsigned long) (/home/ash/prj/lo/online/test/unithttplib+0x20cb7d) (BuildId: 7954f6bea5efa6c39ca02e7033c014e826b9f5fd)
    #1 0x55dc0c1f969c in http::Session::newRequest(http::Request) /home/ash/prj/lo/online/test/../net/HttpRequest.hpp:1174:25
    #2 0x55dc0c1ee08b in http::Session::asyncRequest(http::Request const&, SocketPoll&) /home/ash/prj/lo/online/test/../net/HttpRequest.hpp:1079:9
    #3 0x55dc0c1b718f in HttpRequestTests::test500GetStatuses() /home/ash/prj/lo/online/test/HttpRequestTests.cpp:515:9
    #4 0x55dc0c219ec9 in void std::__invoke_impl<void, void (HttpRequestTests::*&)(), HttpRequestTests*&>(std::__invoke_memfun_deref, void (HttpRequestTests::*&)(), HttpRequestTests*&) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/invoke.h:73:14
    #5 0x55dc0c219de0 in std::__invoke_result<void (HttpRequestTests::*&)(), HttpRequestTests*&>::type std::__invoke<void (HttpRequestTests::*&)(), HttpRequestTests*&>(void (HttpRequestTests::*&)(), HttpRequestTests*&) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/invoke.h:95:14
    #6 0x55dc0c219dbc in void std::_Bind<void (HttpRequestTests::* (HttpRequestTests*))()>::__call<void, 0ul>(std::tuple<>&&, std::_Index_tuple<0ul>) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/functional:416:11
    #7 0x55dc0c219d47 in void std::_Bind<void (HttpRequestTests::* (HttpRequestTests*))()>::operator()<void>() /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/functional:499:17
    #8 0x55dc0c219d47 in void std::__invoke_impl<void, std::_Bind<void (HttpRequestTests::* (HttpRequestTests*))()>&>(std::__invoke_other, std::_Bind<void (HttpRequestTests::* (HttpRequestTests*))()>&) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/invoke.h:60:14
    #9 0x55dc0c219d47 in std::enable_if<is_invocable_r_v<void, std::_Bind<void (HttpRequestTests::* (HttpRequestTests*))()>&>, void>::type std::__invoke_r<void, std::_Bind<void (HttpRequestTests::* (HttpRequestTests*))()>&>(std::_Bind<void (HttpRequestTests::* (HttpRequestTests*))()>&) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/invoke.h:110:2
    #10 0x55dc0c219a72 in std::_Function_handler<void (), std::_Bind<void (HttpRequestTests::* (HttpRequestTests*))()> >::_M_invoke(std::_Any_data const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/std_function.h:291:9
    #11 0x55dc0c09776b in std::function<void ()>::operator()() const /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/std_function.h:622:14
    #12 0x55dc0c219713 in CppUnit::TestCaller<HttpRequestTests>::runTest() /usr/include/cppunit/TestCaller.h:175:7
    #13 0x7f8b5ab23614 in CppUnit::TestCaseMethodFunctor::operator()() const (/usr/lib/x86_64-linux-gnu/libcppunit-1.15.so.1+0x24614) (BuildId: 4329d55843a6cf32b3e88d4d9aec95035315b163)
    #14 0x7ffdc354a41f  ([stack]+0x2b41f)

Thread T10 (HttpAsyncReqPol) created by T0 here:
    #0 0x55dc0bf922bc in __interceptor_pthread_create (/home/ash/prj/lo/online/test/unithttplib+0x1bb2bc) (BuildId: 7954f6bea5efa6c39ca02e7033c014e826b9f5fd)
    #1 0x7f8b5a08d0a8 in std:🧵:_M_start_thread(std::unique_ptr<std:🧵:_State, std::default_delete<std:🧵:_State> >, void (*)()) (/usr/lib/x86_64-linux-gnu/libstdc++.so.6+0xd70a8) (BuildId: c90e6603c7cdf84713cd445700a575d3ea446d9b)
    #2 0x55dc0c0aa467 in SocketPoll::startThread() /home/ash/prj/lo/online/test/../net/Socket.cpp:238:23
    #3 0x55dc0c1b57b3 in HttpRequestTests::test500GetStatuses() /home/ash/prj/lo/online/test/HttpRequestTests.cpp:482:16
    #4 0x55dc0c219ec9 in void std::__invoke_impl<void, void (HttpRequestTests::*&)(), HttpRequestTests*&>(std::__invoke_memfun_deref, void (HttpRequestTests::*&)(), HttpRequestTests*&) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/invoke.h:73:14
    #5 0x55dc0c219de0 in std::__invoke_result<void (HttpRequestTests::*&)(), HttpRequestTests*&>::type std::__invoke<void (HttpRequestTests::*&)(), HttpRequestTests*&>(void (HttpRequestTests::*&)(), HttpRequestTests*&) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/invoke.h:95:14
    #6 0x55dc0c219dbc in void std::_Bind<void (HttpRequestTests::* (HttpRequestTests*))()>::__call<void, 0ul>(std::tuple<>&&, std::_Index_tuple<0ul>) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/functional:416:11
    #7 0x55dc0c219d47 in void std::_Bind<void (HttpRequestTests::* (HttpRequestTests*))()>::operator()<void>() /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/functional:499:17
    #8 0x55dc0c219d47 in void std::__invoke_impl<void, std::_Bind<void (HttpRequestTests::* (HttpRequestTests*))()>&>(std::__invoke_other, std::_Bind<void (HttpRequestTests::* (HttpRequestTests*))()>&) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/invoke.h:60:14
    #9 0x55dc0c219d47 in std::enable_if<is_invocable_r_v<void, std::_Bind<void (HttpRequestTests::* (HttpRequestTests*))()>&>, void>::type std::__invoke_r<void, std::_Bind<void (HttpRequestTests::* (HttpRequestTests*))()>&>(std::_Bind<void (HttpRequestTests::* (HttpRequestTests*))()>&) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/invoke.h:110:2
    #10 0x55dc0c219a72 in std::_Function_handler<void (), std::_Bind<void (HttpRequestTests::* (HttpRequestTests*))()> >::_M_invoke(std::_Any_data const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/std_function.h:291:9
    #11 0x55dc0c09776b in std::function<void ()>::operator()() const /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/std_function.h:622:14
    #12 0x55dc0c219713 in CppUnit::TestCaller<HttpRequestTests>::runTest() /usr/include/cppunit/TestCaller.h:175:7
    #13 0x7f8b5ab23614 in CppUnit::TestCaseMethodFunctor::operator()() const (/usr/lib/x86_64-linux-gnu/libcppunit-1.15.so.1+0x24614) (BuildId: 4329d55843a6cf32b3e88d4d9aec95035315b163)
    #14 0x7ffdc354a41f  ([stack]+0x2b41f)

SUMMARY: AddressSanitizer: heap-use-after-free /home/ash/prj/lo/online/test/../net/HttpRequest.hpp:835:66 in http::Response::logPrefix(std::ostream&) const
Shadow bytes around the buggy address:
  0x0c2e800035a0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c2e800035b0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c2e800035c0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c2e800035d0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c2e800035e0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
=>0x0c2e800035f0: fd fd fd fd fd fd fd fd fd fd fd fd[fd]fa fa fa
  0x0c2e80003600: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c2e80003610: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c2e80003620: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c2e80003630: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c2e80003640: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
==949494==ABORTING

Change-Id: I5e1539c3adbab9b5027d84cc1dbab4b90271c458
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-06-24 07:08:55 +01:00
Ashod Nakashian
562cfcae01 wsd: cosmetics and assertion
Change-Id: Ib89d1cb684250e0ebc3455423cbd991d8eecef56
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-06-07 09:09:00 +01:00
Ashod Nakashian
6259be6fbe wsd: better logging of unix socket binding
No need to complain when bind() didn't fail.

And assert when/if we are going to overflow.

Change-Id: I66f5ff1963c0afc6652afb5a7d017e197d945736
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-06-07 09:09:00 +01:00
Ashod Nakashian
5bdd977410 wsd: simplify socket read logging
Change-Id: I083b86d6c8e6e2b3dc7b14836409281792d7b0bf
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-06-07 09:09:00 +01:00
Ashod Nakashian
3b9cc13b7a wsd: improved socket logging
More consistent logging of the socket FD.

Change-Id: Iee24ad4eb067969abfc06f78a768563351d264c7
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-06-07 09:09:00 +01:00
Ashod Nakashian
f43adb76ae wsd: make socket FD log prefix implicit and cleanup logs
Change-Id: I873d19b8d4149b85f2116d363301afea1aa0b2fd
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-06-07 09:09:00 +01:00
Ashod Nakashian
98ae362e91 wsd: handle socket closed on read better
A corner case where read doesn't return 0
on a closed socket can result in a stuck
state where we attempt to read when we
do get ECONNRESET (which we didn't check
on reads).

This makes the interface of readIncomingData
the same as writeOutgoingData by returning
the actual return value of the read syscall.

So now we handle both return 0 as well as
error codes returned on failed calls.

The logic hasn't changed, just that now
we handle errors better and similar to the
write case.

Change-Id: I0b38a63da4e6c92a482948478d5d8d446e0b8b58
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-06-03 20:16:59 -04:00
Michael Meeks
6de4eb865e socket: only wakeup the mainloop on addCallback for the 1st callback.
Change-Id: I96d9f0d46a5557ba464664456ec82605780f7de1
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2022-05-26 19:53:11 -04:00
Ashod Nakashian
dccdf9fafa wds: enable experimental blocks unconditionally
This enables code that was protected with
EnableExperimental in the socket logic (and one
case in DocBroker). These changes are now deemed
safe to enable permanently.

Change-Id: Ie62f5d7bd281ade90f38d654b51b104b8d1f14bc
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-05-23 17:00:31 +01:00
Ashod Nakashian
6458e00bc4 wsd: return status from writeOutgoingData
Without knowing whether the write succeeded
or failed, we cannot trust errno has our
error or some earlier and unrelated error.

This was caught when there were two sockets,
one of which disconnected. The write to the
disconnected one returned -1 and set errno
to ECONNRESET. We subsequently wrote to the
second socket, which succeeded. However,
because errno wasn't reset, and since
writeOutgoingData didn't return anything
to indicate the success, errno's ECONNRESET
value meant the second socket was also
disconnected, which was incorrect.

writeOutgoingData now returns the last return
value from writeData so we can make informed
decision as to whether to check errno or not.

Also, to avoid incorrecly propagating errno,
we now capture errno only when readData and
writeData return -1. This has the nice
side-effect that we reset errno to 0 when
no errors occur during our call.

Change-Id: I911b31390f37cc71938bc4a6ae75393dbf24bb9d
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-04-30 20:41:26 +01:00
Ashod Nakashian
14d96957cd wsd: log macro cleanup
* Simplify log macros.
* Reduce expanded lines (faster compilation).
* Avoid flushing (since we always use ostringstream).

Change-Id: Id10c1a75b5af5d8cdba62d768192ab0a6a9e0aca
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-04-26 11:13:44 +03:00
Ashod Nakashian
e9b26cdf53 wsd: use the default DH parameters in SSL
OpenSSL 3 deprecated the manual DH parameter
functions. Instead, it encourages the use
of the built-in parameters. Since this
API also works on the 1.1 version, we only
need the manual parameters for older versions.

Change-Id: I900cc11c3ca09f1d85b7d88cfbf537d802f69846
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-04-22 09:47:19 +02:00
Ashod Nakashian
b7b7801d8a wsd: remove identical simulateSocketError override
Since both implementations are identical, there
really is no benefit to having two version.

Change-Id: I4a5288243291c0d5706df8e8870b918fab425317
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-04-20 08:34:59 -04:00
Ashod Nakashian
4c1a168757 wsd: remove argument default-value
Single-use default argument.

Change-Id: I1085465c0dbdf6cbda934277feca61781b67f45c
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-04-20 08:34:59 -04:00
Ashod Nakashian
f6ca40b4fd wsd: do not close the socket while have data to read
The last burst of data arrives with POLLHUP.
If during the read we hit any errors, including
EAGAIN, for whatever reason, we may lose the
data if we don't attempt reading again later.

The only way to guarantee that we do not have
any more data to read, when we get POLLHUP,
is to poll until we either get no POLLIN or
read returns 0 indicating the socket is closed,

Oddly, read(2) sometimes returns 0 without
POLLHUP ever being set, and sometimes we
do get POLLHUP while POLLIN still set. This
implies that poll and read aren't consistent
in how they detect and report the close
condition. Luckily, with this patch we can
handle all cases without any complications.

This was caught through simulateSocketError,
which when it injects EAGAIN on the very
last read, when the socket is closed, causes
error as the response is partially or
completely lost (because we never read it).

The behavioral change should only be
observable with EnableExperimental.

Change-Id: I77260f98d5dd5050c5f9b202b9effd501191336b
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-04-14 10:48:45 +01:00
Ashod Nakashian
806cb5676b wsd: detect ECONNRESET and EPIPE after writes
This extends the detection of connection termination
for writes via ECONNRESET and EPIPE.
For some reason ECONNRESET was not detected.

This patch avoids extra polling to detect connection
termination and makes the cleanup faster.

The changes are guarded by EnableExperimental to avoid
any unexpected change of behavior.

Change-Id: I2ae3803f025d3cf756f86460e47aedc984249509
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-04-14 10:48:45 +01:00
Ashod Nakashian
1da8d6dd24 wsd: use STATE_ENUM for http
Change-Id: Iaacf03856b9a07286f4fdf1f1eac34f2b75d2244
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-04-06 18:33:45 -04:00
Ashod Nakashian
d8745f288d wsd: logging and minor cosmetics
Change-Id: Ia6ba5b333c8caf742de27be46faf7265a1a777a5
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-04-06 18:33:45 -04:00
Michael Meeks
db63703d0c Validate as utf-8 all Websocket text messages in debug mode.
Ensure that rendersearchresult: is terminated, and identified as binary.

Change-Id: I84e83c63351cd0aac0923bf7c833b14c1be2c051
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2022-04-04 20:46:11 +01:00
Ashod Nakashian
11f31b0ba4 wsd: test SSL hostname
Change-Id: I0895d90d2c9be8a76afd209446ae39cd33fa5d2e
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-04-01 10:33:55 +01:00
Ashod Nakashian
71e1e54eb5 wsd: hostname is needed for SSL SNI
Since the hostname argument is passed
to both the base class of SslStreamSocket
and SSL_set_tlsext_host_name, and since
the base class's getter, also called
hostname(), is hidden by the argument,
we cannot move it.

An empty hostname can result in 403 Forbidden
from the server due to missing Server Name
Indication (SNI).

Change-Id: I27990f64f17ec3c81a4dd543a078807629cd0c20
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-03-27 22:32:38 +02:00
Ashod Nakashian
4d2351e37f wsd: reduce logging noise in socket reads
Change-Id: I4305baf828ccb1ae71d3b3b12fa90a7aeb5e0928
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-03-23 13:31:58 +01:00
Ashod Nakashian
e164cb4a4d wsd: trace poll events and revents flags arround ppoll
Change-Id: If6aedff69a6421a16eec9f86fed6d0ea381ecc0c
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-03-21 08:57:41 +00:00
Ashod Nakashian
f74192d9ac wsd: always include the BIO errors in SSL logs
And improved socket logging in general while
making them more consistent.

Change-Id: I1ed7f2561476ca5370af91079d5d616804396f8e
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-03-21 08:57:41 +00:00
Ashod Nakashian
1bb21868b2 wsd: reduce polling when blocked on ssl handshake
While SSL is handshaking, there can be no general
application data communication. During that early
stage of connecting we have data to send (the
request, headers, etc.) and so we poll on POLLOUT.
Naturally, we also always want to poll on POLLIN,
because we can never know when there is data to
read (especially true for web-sockets).

The problem is when SSL will not send data just
yet because it is handshaking. It is typically
waiting for handshake negotiation data to read,
so when we POLLOUT, poll immediately returns, but
writing (via SSL_write) fails with WANTS_READ
error. This goes on in a busy-loop until the
negotiation data is available for read and the
handshake is completed. Very inefficient.

The solution is to poll on whatever SSL needs
during the handshake, exclusively. Once the
handshake is complete, we poll on whatever we
need. However, SSL can renegotiate at any time,
so we also merge with what it needs.

In addition, we avoid the unnecessary read when
poll doesn't give us POLLIN in revents, since the
read will more likely than not fail (except in
the rare case when data becomes available in the
interim). Notice that SSL_read will return
SSL_WANTS_READ when there is no data, which
is misleading (since SSL isn't in need of data to
read at all, nor are we, for that matter).
Best not to do noisy reads unnecessarily.

These changes are disabled by default and can
be enabled via the experimental_features option.

Change-Id: I6a7ed7d871ed257b30062cc720a8b8c7acbab3b7
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-03-17 18:46:46 -04:00
Ashod Nakashian
6c28ddb07c wsd: exit the kit when we fail to connect to wsd
This prevents the kit from becoming a zombie
when it has an early failure to connect to WSD.

Change-Id: I4e8203b2cc3d80822308236e5b47be0c0c96e9ae
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-02-24 07:38:13 -05:00
Ashod Nakashian
b53d353779 wsd: reduce debug and generally redundant logs
In 'debug' log-level we expect a detailed, but
still readable output. Having one area with
disproportionately large number of logs reduces
the overall utility of the log output.

This patch reduces a number of redundant log
entries, including errors that are already
logged. It also reduces the level of some
others from 'information' to 'debug' and
from 'debug' to 'trace'.

The goal is to make 'debug' level as useful as
possible to read the progress and be able to
understand what was going on, such that one is
able to decide which area to dig deeper into.
Then, trace level could be used to get more
insight into that area, if necessary. For
example, when investigating a test failure,
one first enables 'debug' logs and reads through.
Once a section between two debug entries is
identified as being of interest, enabling 'trace'
level logs becomes more productive as it's
now possible to easily reach the first DBG
entry and read through until the second one.

It's unfortunate that we don't have per-area
control for enabling/disabling logs, so it
is common to see more and more 'debug' log
entries added all around, making logs
less and less readable.

It is also a limitation of the levels we have
that we really only have 3 usable levels:
one, two, many. That is, 'information' for
the most important events, 'debug' for
technical details needed to investigate issues,
and 'trace' for everything else. ('warning'
and 'error' aren't really 'levels'; they have
semantics that makes them special-cases.)
So we have to avoid degrading one into the
other, or have differences without distinction.

If any of these entries are needed to be
displayed more frequently, changing them
back to 'debug' or even 'information' should
be done. Though for me they seem special
cases that don't benefit most log readings.

Change-Id: Id2c6a9dc027483b81a066b0b4b50a298c5eff449
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-02-24 07:38:13 -05:00
Ashod Nakashian
bef9c3ff65 wsd: dump all the state managers in DocBroker
This adds dumpState to DocumentState, SaveManager,
and StorageManager classes, and dumps all the
missing members.

Also, normalize the format and make it symmetric
and consistent.

Change-Id: Ie0cc8e07d13de60c33d64cd621abf4e815a4ef94
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-02-24 07:38:13 -05:00
Ashod Nakashian
52f2600cf9 wsd: test: embue all tests with a name and unify logs
Now the remaining tests that didn't have a name
get one and the logs are unified between old-
and new-style tests. Mostly.

This makes sure that all logs and assertions
properly log the test name and make test
failures easier to debug and fix.

Change-Id: Id159ffacc81642a6ec594c5143498408adab67cf
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-02-17 18:52:48 -05:00
Ashod Nakashian
2444e28059 wsd: reduce noisy logs
This reduces some logs from debug to trace,
especially in Socket where the amount of
activity is high, but the logs in question
don't add value in debug level.

Also supressed an error when superfluous.

This makes debug-level logs much more readable
and relevant to the main events.

Change-Id: Ie2698b56f320d15a09060cf2877477d9da0e1582
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-02-04 10:26:49 -05:00
Ashod Nakashian
c9082aea86 wsd: enforce TLSv1.2 as the minimum acceptable version
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
(cherry picked from commit dad7ed85e97afe0e4f5229b1de125aada9a8c2e8)

Change-Id: I5683f835f37f67ee353a0b629a4662c7c78787a6
2022-01-10 21:26:38 +01:00
Szymon Kłos
c155b9569b Handle exceptions in Socket messages processing
Don't stop processing all messages when one caused an exception.
Try/catch where messages are processed in the loop so we don't
ignore other messages:
* handleTCPStream
* handleIncomingMessage

Signed-off-by: Szymon Kłos <szymon.klos@collabora.com>
Change-Id: Idb8c9cf72a7912e7e508e429821b4ee32c9b122b
2022-01-09 13:15:36 -05:00
Gleb Popov
4d64f2b466 Create a link to the master UDS file inside the jail when we aren't using abstract sockets.
Signed-off-by: Gleb Popov <6yearold@gmail.com>
Change-Id: I021b906ef545f4d3238f4c61650ced8da15b6374
2022-01-08 10:41:02 +00:00
Michael Meeks
5da4116731 Buffer: remove _size member and calculate it from _offset as needed.
Change-Id: I96bd949f1e9c460fbaf69967072e85cf45141acd
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2021-11-30 09:32:45 +00:00
Michael Meeks
a958b30d56 Buffer: erase fully when we wrote everything that is left.
This avoids memory hanging around, _buffer.size() is not data
left as seen in pkill -USR1 output:

coolwsd[25677]:  Buffer size: 0 offset: 421811

Change-Id: I0c2eef9435230cf864854cbc95cd587e39d240ac
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2021-11-30 09:32:45 +00:00
Andras Timar
f07ff8c7e0 rename: remaining lool->cool changes
Signed-off-by: Andras Timar <andras.timar@collabora.com>
Change-Id: Ib7d4e804bebe52dead8d53b0e0bbaed0f08bf3d0
2021-11-18 14:14:11 +01:00
Luboš Luňák
897c5df270 make Socket use Buffer for input buffer too
SteamSocket::eraseFirstInputBytes() removes from the beginning
of std::vector, which is generally slow. If the buffer becomes
too big, which it may under a load, then the function will get
slow, which in turn will likely lead to the buffer getting even
bigger because of accumulated backlog.

The Buffer class is optimized for removal at the beginning,
so use it instead of std::vector, including some API additions
for it to be an in-place replacement where it's used.

Signed-off-by: Luboš Luňák <l.lunak@collabora.com>
Change-Id: I4cf7ec56c908c7d3df391dc3f8e230ad32abb162
2021-10-26 12:11:58 +02:00
Michael Meeks
72f8f5d30e stress: store and dump some statistics.
Change-Id: Ied5eb12888b1466c155ecfd291785a95ea897db9
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2021-10-02 21:24:15 +01:00
Ashod Nakashian
347fd43f7c wsd: chunked transfer and tests
Change-Id: I07f7f126891f4d6b5137b45bf91cbcaa11796cda
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
(cherry picked from commit 866cb8f2f25e958f834adc51e2191fb60e2e85b9)
2021-09-26 17:02:01 -04:00
Ashod Nakashian
9e5043db47 wsd: http: reason phrase is optional
Change-Id: I1bd402b26081a8ff35178c836a5eaa22fd47d033
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
(cherry picked from commit 0134e3329c8ea9cd6793fb125585e289b2082cf0)
2021-09-26 17:02:01 -04:00
Szymon Kłos
e457aa8b4e Don't try to set empty hostname for SNI
to reduce logging warnings

Signed-off-by: Szymon Kłos <szymon.klos@collabora.com>
Change-Id: I9e1dcb16489f4cec692028b86d377ae776ac44e4
2021-09-15 09:34:56 +02:00
Ashod Nakashian
24acdaf89b wsd: throw when an invalid URL is used to create an http session
Change-Id: I2d2eb90badf4f02ec4f2e4c4071fc76b23a92928
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
(cherry picked from commit c16ad4447004a72226df7761fb377014c242ea4e)
2021-09-13 09:40:09 -04:00
Tor Lillqvist
ed5569da30 Handle poll results in SocketPoll in a round-robin order
We don't want to always start with the most recently added socket.

Signed-off-by: Tor Lillqvist <tml@collabora.com>
Change-Id: Ic4b4bf6c19c5d119e6e6f9b398789a4c77b47a10
2021-08-21 15:30:18 +01:00
Michael Meeks
e0d7337877 Host: header don't append port for standard ports.
HA Proxy doesn't tolerate this very happily cf.

https: //serverfault.com/questions/502443/ignore-port-numbers-in-haproxy-host-header-matches/502630
Change-Id: Id285f8acd0e168a734cabd9eccc4a01fe323ab84
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2021-08-13 09:36:27 +05:30
Gleb Popov
20c2ab5663 Remove non-abstract unix socket files on shutdown.
Signed-off-by: Gleb Popov <6yearold@gmail.com>
Change-Id: I54773de6d4f777f9188921d5aa99c052f0f79b34
2021-07-31 07:43:45 +03:00
Gleb Popov
950a5c4d1a Use more sensible value for #ifdef when checking for abstract unix sockets.
Signed-off-by: Gleb Popov <6yearold@gmail.com>
Change-Id: Icfd849424659c8949f8f3554aa75a8a7ceaf7ac2
2021-07-31 07:43:45 +03:00
Gleb Popov
0dd30ba28f Remove unused private class member.
Signed-off-by: Gleb Popov <6yearold@gmail.com>
Change-Id: I38b29c06220d2493dc9d47a0ac9b077e3bafd512
2021-07-30 16:43:29 +03:00
Szymon Kłos
541f6a76d3 ssl: setup hostname for SNI
For some servers we receive failure with HTTP 403 Forbidden in WOPI::CheckFileInfo

"Reason: The client software did not provide a hostname using Server
Name Indication (SNI), which is required to access this server"

fixes #2771 : https://github.com/CollaboraOnline/online/issues/2771

Signed-off-by: Szymon Kłos <szymon.klos@collabora.com>
Change-Id: I761b179580481f8882a4526c1d8be4f1c14ad929
2021-07-22 12:40:05 +02:00
Gopi Krishna Menon
b3d5a2563c Add profilezone around kitPoll function and SocketPoll constructor
Add profile zone around kitPoll function and SocketPoll constructor to
improve trace event generation

Signed-off-by: Gopi Krishna Menon <krishnagopi487.github@outlook.com>
Change-Id: Ia46e9add59a57935997649fe39861a8d851e1ff0
2021-07-21 15:00:31 +03:00
Tor Lillqvist
8b6ee5b8bf No need for the template class MessageQueueBase
Signed-off-by: Tor Lillqvist <tml@collabora.com>
Change-Id: Ie007344f9a0ffe7fdf767cb9e9069db99aa224b9
2021-07-21 09:54:28 +03:00
Ashod Nakashian
4c87cc36ff wsd: Close socket hard when necessary
Also clear its input buffer explicitly.

Change-Id: I8badbb96d98eaf10433a65fcfd13b0d6d5893594
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>

Ignore input in a somewhat gentler way.

Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
Change-Id: I758302dc3bb1aa87f9fbfa726f73f4b9339e08c2
2021-07-19 17:31:55 +01:00
Miklos Vajna
18d4c58442 http response: if the result doesn't fit, then consider that a fatal error
This is really a garbage in -> garbage out situation.

Signed-off-by: Miklos Vajna <vmiklos@collabora.com>
Change-Id: Ic1c33f44081f259e5cf5994ad901e1593fe8dfcf
2021-07-19 13:38:00 +02:00
Miklos Vajna
32a654eecb http response: simplify the condition if the result would fit
Given that "digit" is always less than 16, we can avoid the "- digit"
in the condition (because the division turns that into 0 anyway), making
it effectively constexpr.

Signed-off-by: Miklos Vajna <vmiklos@collabora.com>
Change-Id: Iaf9e53d3543f2237c00768f214114a02a4746020
2021-07-19 12:42:38 +02:00
Ashod Nakashian
0d59630b48 wsd: killpoco: cert verification
Change-Id: Ie9bc96183d1e416ef4b9b455eefb1f9249b2f695
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-07-18 21:14:48 -04:00
Ashod Nakashian
f63d077916 wsd: ssl certificate verification requirements
Change-Id: I72ffa586310296f1986276c3007672c41146c92b
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-07-18 21:14:48 -04:00
Ashod Nakashian
f702c4efab wsd: support certificate verification
Change-Id: I912595f104e24dc66da9cf06bc211cb0c50c9ff0
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-07-18 21:14:48 -04:00
Ashod Nakashian
0690f23ee4 wsd: move isLocalhost to a common area
Change-Id: I2a7986863138a254a6d74644112f5cd60bb898cd
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-07-18 21:14:48 -04:00
Miklos Vajna
57d3d0f391 http response: check if result would fit into chunkLen
Signed-off-by: Miklos Vajna <vmiklos@collabora.com>
Change-Id: I6e3b73461653d2ab3cedaa3f6ca7fbfd2a826edb
2021-07-08 14:51:11 +02:00
Dennis Francis
7e9b038ded net: show call-site file/line for assertCorrect...
...Thread.

Conflicts:
	net/Socket.hpp
	net/SslSocket.hpp

Signed-off-by: Dennis Francis <dennis.francis@collabora.com>
Change-Id: I92b8f4b52e7bd60b69305c1916eed8a14a4c1560
2021-07-02 16:48:46 +05:30
Michael Meeks
e289597315 Add a processtoidle event implementation.
This can be used to accelerate unit tests by allowing us to ensure
that all pending work is done between a 'processtoidle' message being
sent and an 'idle' being returned. This can be much faster than waiting
a defined length of time.

Change-Id: I6d96de205d1fd34a22e0ddbd2709bf806a97b33c
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2021-06-29 17:12:01 +01:00
Ashod Nakashian
5a310a2232 wsd: separate client SSL context from the server
Change-Id: I4d86f733a16e6c76340b18ff836831ebe6acfd4d
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-06-23 23:39:34 -04:00
Ashod Nakashian
a9e650a8db wsd: separate the SSL locks from the context
Change-Id: I2b1742054d5cec16ae3cf90e2098de40eeade4a8
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-06-23 23:39:34 -04:00
Ashod Nakashian
485a716268 wsd: http: handle invalid http versions
We currently only recognize HTTP/x.y. Anything
else is invalid.

Change-Id: I45fa7e33052e3847b8a2d9768b12d8eac43f6b0a
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-06-19 17:44:59 -04:00
Ashod Nakashian
823f349383 wsd: http: break cyclic dependency
The Socket instance owns the protocol handler
by design. This implies that the Session,
which is also the protocol handler, cannot
itself own the Socket.

Here we change that ownership into a weak_ptr
and pass the exclusive ownership of the Socket
to SocketPoll. We track the connection state,
so we can create a new socket when we are
disconnected.

Change-Id: Id6bf6506b0c8e2e0564f91977e1e7189d934a68f
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-06-14 23:02:39 -04:00
Ashod Nakashian
7b32b96a08 wsd: http: better logs
Change-Id: I790308c872ca9c20c4b29a04deae19059ca36818
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-06-13 21:57:43 -04:00
Ashod Nakashian
3891f89bff wsd: http: better logging of errors
Change-Id: Ifbf199051eeec20f2d273d777df5befca131f433
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-06-13 21:57:43 -04:00
Ashod Nakashian
7ef411b8f3 wsd: disable socket traffic logging
Change-Id: I9cfe758c9b74e534152c69fa5c0e612a068209f5
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-06-13 21:57:43 -04:00
Ashod Nakashian
c5a4e106b1 wsd: http: do not set the state explicitly on parsing error
Setting the state to Error in the parser has the
unwanted side-effect of not triggering the proper
callbacks. The better design is to observe the API
and return error (-1) upon hitting parsing errors.
The caller will then invoke the finishing function
that sets the state and triggers the callbacks.

Change-Id: I4957b0fb431f477d71fb21a8dd601d132c3d6a21
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-06-13 12:10:24 -04:00
Ashod Nakashian
74e575de4b wsd: http: always destroy the socket last
When the socket is destroyed, it may invoke
the onDisconnect handler, which updates
the Response instance. If the order of
destruction is incorrect, we may have
a null instance.

Also make the State atomic to make sure
its visibility is consistent across threads.
The shared_ptr instances will fence and will
always be consistently visible across threads,
but if the State isn't in sync, then we can
seem to have an inconsistent state. The State
instance will be set and accessed from different
threads in an async request.

Change-Id: Ia2a48285d140646f3640f59634e14a46e4a4d640
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-06-13 12:10:24 -04:00
Ashod Nakashian
513e33582f wsd: http: an incomplete response is an error
If we haven't had a complete response or a timeout,
then we have an incomplete transmission, which is
an error.

Change-Id: I1b775760186021e0a704eba2c9f3647efa4f5ed0
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-06-13 12:10:24 -04:00
Ashod Nakashian
bbb4fe14ae wsd: http: sync requests accept external poller
Reusing a SocketPoll is encouraged rather than
creating throwaway instances. Session now supports
external SocketPoll instances for the sync members
as it does for the async (which is unavoidable).

Also, use TerminatingPoll to break the poll
when the terminating the process is flagged.

Change-Id: Ide6f674080ce20bb764c482871e48c94d83d4214
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-06-13 12:10:24 -04:00
Ashod Nakashian
b8c3e97cc6 wsd: better handling of invalid port in URL
Detect invalid port values and error out.

Change-Id: If45bcacaf64f48356147aa5461bcd2e30b7c7ea1
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-06-13 12:10:24 -04:00
Ashod Nakashian
dbf45e8641 wsd: http: performWrites can be called after destroying the socket
Change-Id: Ieb745a7706bf57c9bd16995e1f1336f7053ab30c
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-06-13 12:10:24 -04:00
Michael Meeks
655493a7bc Transfer LOK callback processing into our main thread if necessary.
While we are processing data in the poll handler, we can have
another helpful thread from the core sending things to us:

loolforkit(Socket::assertCorrectThread(char const*, int))
loolforkit(WebSocketHandler::sendFrame(std::shared_ptr<StreamSocket> const&, char const*, unsigned long, unsigned char, bool) const)
loolforkit(WebSocketHandler::sendMessage(char const*, unsigned long, WSOpCode, bool) const)
loolforkit(Document::postMessage(char const*, int, WSOpCode) const)
loolforkit(Document::sendFrame(char const*, int, WSOpCode))
loolforkit(ChildSession::sendTextFrame(char const*, int))
loolforkit(ChildSession::loKitCallback(int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&))
loolforkit(Document::GlobalCallback(int, char const*, void*))
/core/instdir/program/libsofficeapp.so()
/core/instdir/program/../program/libfwklo.so()
/core/instdir/program/libscfiltlo.so()
/core/instdir/program/libexpwraplo.so()
/core/instdir/program/libooxlo.so(oox::core::FastParser::parseStream(com::sun::xml::sax::InputSource const&, bool))
/core/instdir/program/libooxlo.so(oox::core::FastParser::parseStream(com::sun::uno::Reference<com::sun::io::XInputStream> const&, rtl::OUString const&))
/core/instdir/program/libooxlo.so(oox::core::XmlFilterBase::importFragment(rtl::Reference<oox::core::FragmentHandler> const&, oox::core::FastParser&))
/core/instdir/program/libscfiltlo.so()
/core/instdir/program/libcomphelper.so(comphelper::ThreadTask::exec())
/core/instdir/program/libcomphelper.so()
/core/instdir/program/libuno_salhelpergcc3.so.3(salhelper::Thread::run())
/core/instdir/program/libuno_salhelpergcc3.so.3()
/core/instdir/program/libuno_sal.so.3()
/lib/x86_64-linux-gnu/libpthread.so.0()
/lib/x86_64-linux-gnu/libc.so.6(clone)

This is most likely from eg. threaded parsing of various file formats,
or progress messages while loading / saving, sent while the SolarMutex
is locked.

We assume that:
  + there will only ever be one thread running inside kitPoll
    this is enforced by vcl/headless.
  + and so, we can safely mutate SocketPoll and Socket buffer
    state from this thread.
  + there are only two entry points for callbacks from threads
    in core - which are both instrumented, and if necessary
    their work is shifted to this thread.

Memory corruptions matching the above trace, suggesting that
multiple writes have collided between kitPoll and an event
callback have been seen in the wild.

Change-Id: I5b084cbfec1ea326b6e17c9e5590a8c8e35b3854
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2021-06-11 14:19:55 +01:00
Tor Lillqvist
10b9766e03 Add commented-out TraceEvent::emitInstantEvent
Signed-off-by: Tor Lillqvist <tml@collabora.com>
Change-Id: Id573e8ff93f3a5914fef91b01802047881990dbf
2021-06-07 14:34:37 +03:00
Andras Timar
086b4f4fc0 Extend debug only if OpenSSL version > 1.1.0
Signed-off-by: Andras Timar <andras.timar@collabora.com>
Change-Id: I6ba025786cd92388da1e16ddc0bb8c9a5ad56b21
2021-06-04 14:58:36 +01:00
Michael Meeks
b4f3adb8cd Extend debug.
Change-Id: I57bf42a0241d773041f792a2489011f90677254e
2021-06-04 14:58:36 +01:00
Michael Meeks
7ed4b4f7e7 Use larger write buffer size for UDS from kit -> wsd.
We send lots of large tile data this way, this should help
accelerate tile data transfer marginally.

Change-Id: I1deab7845c09dc65b1f44e9f9fc762f70ce94cc3
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2021-06-04 14:58:36 +01:00
Ashod Nakashian
aea70a563c wsd: http: disconnect if the server closed the socket
Change-Id: If00566939708d71482a8aac8e97cc371a4a381fd
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-05-06 22:14:51 -04:00
Ashod Nakashian
a0696403a9 wsd: http: complete the http response only once
Change-Id: I2c015f004883272bb6efe4ffc5a14e3cc101f60f
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-05-06 22:14:51 -04:00
Tor Lillqvist
739dfce08a There is no isManualDefrag parameter
Change-Id: I1a662dbdb2e43335f8739852e7797012de7be34a
Signed-off-by: Tor Lillqvist <tml@collabora.com>
2021-05-05 15:22:00 +03:00
Tor Lillqvist
686f1ba1cb Make WebSocketHandler::_isClient const and drop default values for bool parms
Avoiding default values for parameters makes the code easier to read.
Especially true for bool parameters. But sure, just a question of
taste.

Change-Id: I473f70bdfafe3a9ccfb325def8760d78fee7e9a6
Signed-off-by: Tor Lillqvist <tml@collabora.com>
2021-05-05 09:03:29 +03:00
merttumer
5742acd87c android: Fix build fail and crash on doc load
Signed-off-by: merttumer <mert.tumer@collabora.com>
Change-Id: Id998e2bdf7051d54784543015c7d34c0bdd64543
2021-05-02 21:47:37 -07:00
Ashod Nakashian
a0549fd7cc wsd: http: simplify http::get
Change-Id: Id94d2e7340b393bd4a42f5108621f16b46a0ee9b
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-05-02 22:35:39 -04:00
Ashod Nakashian
117db770cd wsd: http: add isConnected getter to http::Session
Change-Id: Iad12f00f9ced434d4e1493aba03be98a3cd7f2ab
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-05-02 22:35:39 -04:00
Ashod Nakashian
ea12aa7635 wsd: http: braces always on new line
Seems like this was a bug in clang-format
that is fixed in clang-12.

Change-Id: I8144179d2b290f5d875af41dbd44dedcf4152639
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-05-02 22:35:39 -04:00
Ashod Nakashian
0dbecddb3a wsd: http: simplify sending response and shutting down the socket
Change-Id: Id4e32c8eb79458d060767a7a5ac26476e2f84331
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-05-02 22:35:39 -04:00
Ashod Nakashian
dc5ca2738e wsd: http: simplify appending to Buffer
Instead of supporting char appending,
we now support appending literal strings
with size capturing. This covers both
single- and multi-character appending
without the need for an explicit size.

Change-Id: Iee2c20b7aa2cdb6863c88e91cd770205719c2ba6
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
(cherry picked from commit 96e3e88a014960a5249fc83a5b2f3b785ac8737d)
2021-05-02 22:35:39 -04:00
Gleb Popov
742cda8b46 Don't try use abstract unix sockets on !Linux platforms.
Signed-off-by: Gleb Popov <6yearold@gmail.com>
Change-Id: Iaad2159ef2c5a45c52f0c7224d58a8160bb5f260
2021-04-30 20:30:56 +01:00
Gleb Popov
f11ca121a4 Use SOL_LOCAL value instead of 0 in getsockopt() calls.
Signed-off-by: Gleb Popov <6yearold@gmail.com>
Change-Id: I5a58a73541de2a32c5a03ebef5618b1541209d8d
2021-04-30 20:30:56 +01:00
Andras Timar
887ce53417 available, off and end can be unsigned, they are byte positions
this prevents compile error with gcc (Ubuntu 5.4.0-6ubuntu1~16.04.12)
../net/HttpRequest.cpp:340:9: error: assuming signed overflow does not occur when assuming that (X + c) >= X is always true [-Werror=strict-overflow]
         if (off + VersionLen >= available)

Signed-off-by: Andras Timar <andras.timar@collabora.com>
Change-Id: I46df5d43d0997f6a1e61c05a4df7f9d71af65511
2021-04-30 14:30:16 +03:00
Miklos Vajna
656eb310bb Fix Debian 8 / gcc-4.9 warnings
net/HttpRequest.cpp:126:19: error: declaration of 'end' shadows a member of 'this' [-Werror=shadow]

kit/Kit.cpp:163:29: error: missing initializer for member 'statfs::f_bsize' [-Werror=missing-field-initializers]

kit/Kit.cpp:171:14: error: 'OVERLAYFS_SUPER_MAGIC' was not declared in this scope

Signed-off-by: Miklos Vajna <vmiklos@collabora.com>
Change-Id: Ibbd35ab5af3adad403ed22a0aeb70917b9e21970
2021-04-30 10:38:09 +02:00
Michael Meeks
6324864a46 Be more tolerant of clients sending WebSocket pings.
Change-Id: If01a268900d597993abf01d23147faa1260a2ad8
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2021-04-28 09:14:07 +01:00
Ashod Nakashian
86aeba7bcf wsd: clarify not-enough-data case while parsing
Change-Id: I790f21a2a4ed4e48da692dcd5202046a488bec45
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
(cherry picked from commit 72c24ad5cf6df3e55cdc626fe0780e5bb98d1271)
2021-04-27 17:48:23 -04:00
Ashod Nakashian
2a81c3611e wsd: properly calculate the socket buffer capacity
Change-Id: I11f97734d99291616bf787aa42138405083c3537
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
(cherry picked from commit 92c6513c1fbdce3d66945ef2cd0784659d4142c9)
2021-04-27 17:48:23 -04:00
Ashod Nakashian
352840c0ea wsd: http: larger 64kb upload-file read buffer
Change-Id: Ie9a0e6f76425d796979dbc77eecf1b05993b834d
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
(cherry picked from commit 34f629c6adc5bb6eb93fd8c813d72ee923d09a05)
2021-04-27 17:48:23 -04:00
Ashod Nakashian
3decba7eec wsd: specify the minimum bytes we can write to the socket
When writing to the socket, it's always more efficient
to fill the buffer up to the hardware limit for each
write. This is doubly important for efficiency with
SSL, due to the overhead of encrypting multiple
small buffers instead of one large one.

Currently we don't write more than one message
at a time, primarily due to limitations in
the Poco sockets in the unit-tests, which
have a hard time consuming multiple WS frames
with a single poll (subsequent calls to poll
doesn't enter signalled state until new data
arrives, possibly because the data is read and
buffered internally, making the whole scheme
of using poll unreliable and meaningless).

Change-Id: Ic2e2cf1babfb5ab4116efd93f392977ba234d92b
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-27 17:48:23 -04:00
Ashod Nakashian
26be3a2a2f wsd: perform socket writes more efficiently
Since it's most efficent to send full blocks at
once (especially so when SSL encryption is done),
we now perform write when the buffer has fewer
than the send-buffer-size bytes. Previously,
we were only getting more data to write to the
socket when the buffer was completely empty,
potentially wasting valuable opportunity to
write more data to the socket while we're at it.

Change-Id: I69a18a042dc2e551ebc5e1af40dae091da3f3d13
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-27 17:48:23 -04:00
Ashod Nakashian
55309e128d wsd: notify outside the lock
Change-Id: I4b1c693dc561221161768ff0ddc0da5a23d512f2
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-27 08:09:49 -04:00
Ashod Nakashian
b47c81e7a8 wsd: improved WebSocketSession interface
SocketPoll is captured as weak_ptr into
WebSocketSession and a much better shutdown
support is now available. The new logic
can do async-shutdown after flushing and
will do sync-shutdown if SocketPoll is
no longer around.

Change-Id: Ia206cab58a13f20f7aeb3a6d8c57afee731c8231
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-27 08:09:49 -04:00
Ashod Nakashian
eeda9adb29 wsd: read can return 0 from the socket
Change-Id: If74a46a8649ee422ed12a2e247d316451fc9cd75
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-27 08:09:49 -04:00
Ashod Nakashian
bc38af30dc wsd: safer asyncShutdown in WebSocketSession
Change-Id: I3108a10be7691ed532301dcd42b659bdeb553473
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-27 08:09:49 -04:00
Miklos Vajna
a5566baa03 Add version of std::atoi() that needs no extra allocation
std::atoi() assumes a null-terminated string and our strings are not
always null-terminated. So add a version that takes a length parameter,
this way we don't have to copy strings around.

Also switch to this in http::StatusLine::parse().

Signed-off-by: Miklos Vajna <vmiklos@collabora.com>
Change-Id: I449b356c1b9948c562434618596e8e3b38656088
2021-04-26 16:22:27 +02:00
Miklos Vajna
9afe974848 Add a fuzzer for http::Response::readData()
And remove the httpheader one, which is not useful, since it uses Poco
for the actual parsing, it did not find anything. (If we switch away
from Poco there in the future, it's easy enough to restore it.)

Also fix some problems found by the fuzzer.

Signed-off-by: Miklos Vajna <vmiklos@collabora.com>
Change-Id: I254247c46ecc78c9c3e75aac4f10c441b0e10fb3
2021-04-23 17:54:36 +02:00
Michael Meeks
e26fac4665 Use the accepted socket, not the listening one.
Change-Id: Iecaa90f4c3030b5b2e20bb0e33ef9b75717bb578
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2021-04-23 16:36:38 +01:00
Miklos Vajna
1195e07d15 StatusLine::parse: limit size of allocated string
Signed-off-by: Miklos Vajna <vmiklos@collabora.com>
Change-Id: Idba8ad8a8905b0d03e2015de5df5c7c7f145ffc5
2021-04-23 15:32:21 +02:00
Miklos Vajna
da11acd8c5 StatusLine::parse: handle non-null-terminated buffer with std::atoi()
Signed-off-by: Miklos Vajna <vmiklos@collabora.com>
Change-Id: I51033bc4d3f97f5ae93abce1b5f19ef6a8b296d8
2021-04-23 15:32:21 +02:00
Miklos Vajna
415a834813 StatusLine::parse: only feed integers to std::atoi()
Signed-off-by: Miklos Vajna <vmiklos@collabora.com>
Change-Id: I7591fd14fbdc7c1210ac8141cb78854e3f20fffd
2021-04-23 15:32:21 +02:00
Miklos Vajna
80c6562e59 Add a fuzzer for http::StatusLine::parse()
And fix an unhandled std::length_error it found.

Signed-off-by: Miklos Vajna <vmiklos@collabora.com>
Change-Id: I571cdd71caeda84820f2c64088966936637ce2bf
2021-04-23 09:02:21 +02:00
Ashod Nakashian
be17696903 wsd: log the buffer size in WebSocketHandler::sendFrame
Change-Id: Ifb8121d9e27c9d6159af3578852e44c35b6f6e0c
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-12 09:06:38 -04:00
Ashod Nakashian
0bf5f97b15 wsd: override getPollEvents in WebSocketSession
Change-Id: I3f59e60f74830998739ae03ff1979a784b9cc8fe
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-12 09:06:38 -04:00
Ashod Nakashian
0fb4cd8bb7 wsd: trap disconnection in WebSocketSession
Change-Id: I519a24d72c3eb8e249450e9a49def077ecf0dc10
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-11 18:43:36 -04:00
Ashod Nakashian
60344a0052 wsd: support asyncronous shutdown of WebSocketSession
Change-Id: I4c50c718388ae8c790d2e2bb1e3d4db93e92aee5
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-11 18:43:36 -04:00
Ashod Nakashian
7b28fe2d41 wsd: improved WebSocketSession
Change-Id: If3c92b59ae6303079bd544e29cb995ac3e0d6742
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-11 18:43:36 -04:00
Ashod Nakashian
ce99632081 wsd: std::move better than copy-from-ref
Change-Id: I7062ed9adf71099b3c54cbbb9784a582bde23715
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-11 18:43:36 -04:00
Ashod Nakashian
2c21fce9fe wsd: use Socket::eraseFirstInputBytes for a cleaner interface
Change-Id: Ife2a740cdc79f1c908e111ba3572b4e0777054b9
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-11 18:43:36 -04:00
Ashod Nakashian
b35a269378 wsd: always include port in the Host header
Change-Id: Iab7680462eac68cf9c4fc1dde6be19e3985bd580
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-11 18:43:36 -04:00
Ashod Nakashian
bd67b25872 wsd: SocketPoll::poll overloaded for deadline time
This makes it simpler to call poll repeatedly
within a given timeout, by first calculating
the deadline and passing it to poll to handle
the math.

Change-Id: I7a9311286ec368c853de40f10523b7b98c8f8106
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-11 01:05:20 -04:00
Ashod Nakashian
374f278228 wsd: WebSocketSession isSecure() -> secure()
Change-Id: I3d15414e0527b6651f5e8bce172e15e646003144
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-11 01:05:20 -04:00
Ashod Nakashian
d6e2e641a2 wsd: make single-argument ctor explicit
Change-Id: I0adb3f73a92bbe5dedcf3d2c67b2935c13af5de0
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-11 01:05:20 -04:00
Ashod Nakashian
09f0554891 wsd: http: WebSocketSession supports flexible message polling
Change-Id: Ic8b54e08fdeae4af1713931d96bbe2cd27ee9f4d
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-11 01:05:20 -04:00
Ashod Nakashian
4ca35edd8c wsd: log the context in WebSocket Session logs
Useful for debugging, especially for unit-tests.

Change-Id: I820e584203a643a396d26c8817b9af1e750232c7
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-11 01:05:20 -04:00
Ashod Nakashian
fecf32d872 wsd: test: use WebSocketSession::create in unit test
Change-Id: Ib4aecd163237220f80ff9e169c4a463ef2c08983
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-11 01:05:20 -04:00
Ashod Nakashian
eb2424feb9 wsd: WebSocketSession create helper and shutdown member
Change-Id: I1cdf3f4f763a66972c9c84cec6a80f380ebcc2db
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-11 01:05:20 -04:00
Ashod Nakashian
ec18cefae8 wsd: http: reuse parseUri
Change-Id: Ia54c767e8f63cca9990b54f49ce6ef5a47397496
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-11 01:05:20 -04:00
Ashod Nakashian
4f05d69815 wsd: use http::Request for internal WS and simplify
Also, enable validation of WebSocket keys.

Change-Id: I226607b18a14d023bc9c55762580fd1cb47493f9
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-11 01:05:20 -04:00
Ashod Nakashian
2e4524ad57 wsd: use WebSocketHandler instead of explicit WebSocket request
Now that the WebSocket functionality is available in
WebSocketHandler, we can cleanup Socket.

Change-Id: Ia3703ab5a2f00fb835eb80493bc400a91dabefad
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-11 01:05:20 -04:00
Ashod Nakashian
7587ebd84f wsd: http: move WebSocket creation into Request
Change-Id: Idb8251fc07d35a996673f91fcb14d5fd9835a414
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-11 01:05:20 -04:00
Ashod Nakashian
1239685620 wsd: http: explicit Request constructor and Header arg
Change-Id: Ief228862d882ae96650708e30442693cc127f0c9
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-11 01:05:20 -04:00
Ashod Nakashian
1190e7f2e0 wsd: improved WebSocket support
Change-Id: Ic1b9464819f5a91df46243c376237d064beeace4
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-11 01:05:20 -04:00
Ashod Nakashian
7b2a0da05b wsd: WebSocketSession handshake and wait for message
With improved test.

Change-Id: I137a35195a81a4d2fbf530be3805e5350cb78644
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-11 01:05:20 -04:00
Ashod Nakashian
e8705abc96 wsd: new WebSocketSession to createa a WebSocket connection
A utility class to create a WebSocket connection based
on WebSocketHandler, http::Request, and SocketPoll.

Change-Id: I00dfd6fc88e210860e0e378587ef1c0a0a65bb5c
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-11 01:05:20 -04:00
Ashod Nakashian
54f80741e2 wsd: http: handle client-side WebSocket upgrade
This adds support to Web-Socket upgrade handshake
validation. We never had a proper client-side
Web-Socket, so never needed this.

Change-Id: If4b8e42daeab13a430179128750f6a4f17452f28
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-11 01:05:20 -04:00
Ashod Nakashian
0624df1da4 wsd: restrict WebSocketHandler members
This simply reduces the public surface area
of the WebSocketHandler class.

Change-Id: I93be58923f429bceab74a9e239ad0fad11390449
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-11 01:05:20 -04:00
Ashod Nakashian
b12a4105fb wsd: WebSocketHandler fully supports http::Request
Change-Id: Ia5ff17e9aa8cbaded4e304be8c673b8f1575b6ce
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-11 01:05:20 -04:00
Ashod Nakashian
813c0747f9 wsd: WebSocketHandler accepts http::Request in addition to Poco
Change-Id: I46fe2f85938284c2a3857a058ce61514354e796b
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-11 01:05:20 -04:00
Ashod Nakashian
b2a7843dc3 wsd: use http::Response in WebSocketHandler 101 responses
Change-Id: Ica3c7950360b62c0927d8a75d813846b301b7403
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-11 01:05:20 -04:00
Ashod Nakashian
bc7b36e904 wsd: log the inBuffer size not the outBuffer
Change-Id: Id8f75576bbf44d881338cd03b2ae7f30f4d092ba
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-07 11:36:10 -04:00
Ashod Nakashian
d9fa64b4a0 wsd: http: support http Connection: close header
According to the RFC, HTTP/1.1 assumes persistent
connection unless the client or server sends
'Connection: close' header. See
https://tools.ietf.org/html/rfc7230#section-6.3

Now we fully support disconnecting when we
get this header, which is important for when
reusing the same http::Session (we need to
reconnect in such a case).

Change-Id: Ib278eff21be32c1414478296e90e2e807ab24132
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-07 11:36:10 -04:00
Ashod Nakashian
4b43b3cd6e wsd: http: set the port in the Host header entry
Change-Id: I2d46c1ef3b72e21ce8924dcf7616cd26fb5bc98d
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-07 11:36:10 -04:00
Ashod Nakashian
41275f0423 wsd: http: new syncRequest with timeout and new helper
Change-Id: I64a5d6f0984b9f35fe0224683527d80cf77fff99
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-07 11:36:10 -04:00
Ashod Nakashian
9d5f8fc73e wsd: http: improved parseUri and new parseUrl with tests
Change-Id: Icee821ab6176d17e08bfc6bc581eaf4b3986da60
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-07 11:36:10 -04:00
Ashod Nakashian
2bb07adb54 wsd: http: simplify syncRequest to return Response
Since the return value of syncRequest and syncDownload
was derived from Response anyway, there is no reason
to have multiple values for callers to look at.

This simplifies the API.

Change-Id: I0f136e515dd0ef6eda84f6a7cd662b260809d2f1
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-07 11:36:10 -04:00
Ashod Nakashian
8aa329c17d wsd: http: default Session timeout is now public
Change-Id: I34376a68a130ccb0d36f04b90ff26af1a1535873
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-07 11:36:10 -04:00
Ashod Nakashian
45b15803ad wsd: http: use std::move
Change-Id: I3c287b96ccce5f8b3cb245c065922a9c35df5bf7
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-07 11:36:10 -04:00
Ashod Nakashian
fb6e7793ff wsd: http: use parseUri
Change-Id: I5c1e95acb30509f2b1865da31a8a0e622a94c4e3
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-07 11:36:10 -04:00
Ashod Nakashian
49a13798eb wsd: http: parse the host and validate
Change-Id: I3ad1bcf51d59295e411a949a714bb680ff789f34
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-07 11:36:10 -04:00
Ashod Nakashian
6f8b6057b1 wsd: http: use std::move where sensible
Change-Id: Ie1c880224822f8c0b2db0e58dd83693335fbfd1f
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-07 11:36:10 -04:00
Ashod Nakashian
f53e928530 wsd: http: support sending Request and Response in Socket
Improved handling of http::Request and http::Response
in Socket directly with better error handling and
automatic socket shutdown on error.

We shouldn't need to manually serialize into the
socket's buffer when sending a Request or Response.

Change-Id: I6dfcd2fe4f6b88cd2fa8c749045ce25a8c52fe9a
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-03 19:57:03 -04:00