Skip to content

Commit

Permalink
Add IPV6 support to unoserver
Browse files Browse the repository at this point in the history
  • Loading branch information
ReeceJones committed Feb 13, 2024
1 parent ecaea93 commit 25b623d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/unoserver/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
import os
import signal
import socket
import subprocess
import sys
import tempfile
Expand All @@ -15,6 +16,22 @@
logger = logging.getLogger("unoserver")


class XMLRPCServer(xmlrpc.server.SimpleXMLRPCServer):
def __init__(
self,
addr: tuple[str, int],
allow_none: bool = False,
) -> None:
addr_info = socket.getaddrinfo(addr[0], addr[1], proto=socket.IPPROTO_TCP)

if len(addr_info) == 0:
raise RuntimeError(f"Could not get interface information for {addr[0]}:{addr[1]}")

self.address_family = addr_info[0][0]
self.socket_type = addr_info[0][1]
super().__init__(addr=addr_info[0][4], allow_none=allow_none)


class UnoServer:
def __init__(
self,
Expand Down Expand Up @@ -84,7 +101,7 @@ def signal_handler(signum, frame):

def serve(self):
# Create server
with xmlrpc.server.SimpleXMLRPCServer(
with XMLRPCServer(
(self.interface, int(self.port)), allow_none=True
) as server:
self.xmlrcp_server = server
Expand Down
20 changes: 20 additions & 0 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,23 @@ def test_server_params(popen_mock, thread_mock):
"--accept=socket,host=127.0.0.1,port=2202,tcpNoDelay=1;urp;StarOffice.ComponentContext",
]
)

@mock.patch("threading.Thread")
@mock.patch("subprocess.Popen")
def test_server_ipv6_params(popen_mock, thread_mock):
srv = server.UnoServer(interface="::", port="2203", uno_port="2202")
srv.start()
popen_mock.assert_called_with(
[
"libreoffice",
"--headless",
"--invisible",
"--nocrashreport",
"--nodefault",
"--nologo",
"--nofirststartwizard",
"--norestore",
f"-env:UserInstallation={srv.user_installation}",
"--accept=socket,host=127.0.0.1,port=2202,tcpNoDelay=1;urp;StarOffice.ComponentContext",
]
)

0 comments on commit 25b623d

Please sign in to comment.