Files
gimp/plug-ins/script-fu/server/servertest.py
lloyd konneker 07ceb5a086 ScriptFu: extract PDB proc script-fu-server from plugin script-fu
Create new plugin file script-fu-server-plugin.c
with code extracted from script-fu.c, which is an omnibus plugin
implementing PDB proc extension-script-fu and other PDB procs.

Why:

1. extension-script-fu is smaller and doesn't doesn't link to socket libraries.
   (GIMP always starts extension-script-fu and it stays running.)

2. packagers/admins can omit script-fu-server executable from an installation,
   if they think letting users serve net ports is not secure.

3. crashing script-fu-server does not crash extension-script-fu,
   which requires restart of GIMP

The changes are mostly a simple refactor, extracting code.
No functional change apparent to users.
Low risk of introduced bugs.
Extremely few users use script-fu-server anyway.
Added some logging.
While at it, use G_DECLARE_FINAL_TYPE
2022-06-19 19:18:39 +00:00

78 lines
1.7 KiB
Python

#!/usr/bin/env python
import readline, socket, sys
if len(sys.argv) < 1 or len(sys.argv) > 3:
print >>sys.stderr, "Usage: %s <host> <port>" % sys.argv[0]
print >>sys.stderr, " (if omitted connect to localhost, port 10008)"
sys.exit(1)
HOST = "localhost"
PORT = 10008
try:
HOST = sys.argv[1]
try:
PORT = int(sys.argv[2])
except IndexError:
pass
except IndexError:
pass
addresses = socket.getaddrinfo(HOST, PORT, socket.AF_UNSPEC, socket.SOCK_STREAM)
connected = False
for addr in addresses:
(family, socktype, proto, canonname, sockaddr) = addr
numeric_addr = sockaddr[0]
if canonname:
print "Trying %s ('%s')." % (numeric_addr, canonname)
else:
print "Trying %s." % numeric_addr
try:
sock = socket.socket(family, socket.SOCK_STREAM)
sock.connect((HOST, PORT))
connected = True
break
except:
pass
if not connected:
print "Failed."
sys.exit(1)
try:
cmd = raw_input("Script-Fu-Remote - Testclient\n> ")
while len(cmd) > 0:
sock.send('G%c%c%s' % (len(cmd) / 256, len(cmd) % 256, cmd))
data = ""
while len(data) < 4:
data += sock.recv(4 - len(data))
if len(data) >= 4:
if data[0] == 'G':
l = ord(data[2]) * 256 + ord(data[3])
msg = ""
while len(msg) < l:
msg += sock.recv(l - len(msg))
if ord(data[1]):
print "(ERR):", msg
else:
print " (OK):", msg
else:
print "invalid magic: %s\n" % data
else:
print "short response: %s\n" % data
cmd = raw_input("> ")
except EOFError:
print
sock.close()