yadyn/server/XmlRpcReceiver.py

54 lines
1.7 KiB
Python
Raw Normal View History

2007-11-16 17:45:39 +01:00
import threading
import time
import Event
from logger import Logger
2009-02-24 14:28:33 +01:00
from SimpleXMLRPCServer import SimpleXMLRPCServer,SimpleXMLRPCRequestHandler
2009-02-20 20:44:05 +01:00
import AdminFuncs
2008-03-20 10:24:12 +01:00
import Entry
2008-03-20 10:40:38 +01:00
class LocalException(Exception):
2008-03-20 10:24:12 +01:00
def __init__(self, msg):
2008-08-12 16:18:57 +02:00
self.msg = msg
2008-03-20 10:24:12 +01:00
2007-11-18 21:33:17 +01:00
class XmlRpcServer(SimpleXMLRPCServer):
2008-03-20 10:24:12 +01:00
@classmethod
2009-02-21 20:35:51 +01:00
def setClassParams(cls, entries):
2008-08-12 16:18:57 +02:00
cls.entries = entries
2009-02-24 14:02:38 +01:00
def __init__(self, addr, requestHandler=SimpleXMLRPCRequestHandler,
logRequests=True, allow_none=False, encoding=None):
SimpleXMLRPCServer.__init__(self, addr, requestHandler, False, allow_none, encoding)
2008-03-20 10:24:12 +01:00
2007-11-16 17:45:39 +01:00
def _dispatch(self, method, params):
try:
# We are forcing the 'export_' prefix on methods that are
# callable through XML-RPC to prevent potential security
# problems
func = getattr(self, 'export_' + method)
except AttributeError:
raise Exception('method "%s" is not supported' % method)
else:
return func(*params)
2009-02-19 22:07:34 +01:00
def export_register(self, dynid, subdomain, zone, sharedSecret, checkSum, email):
2008-08-12 16:18:57 +02:00
try:
2009-02-20 20:44:05 +01:00
AdminFuncs.AdminFuncs.register(dynid, subdomain, zone, sharedSecret, checkSum)
2008-08-12 16:18:57 +02:00
return 'ok'
2009-02-19 17:54:22 +01:00
except AdminFuncs.AdminFuncException, e:
2008-08-12 16:18:57 +02:00
return 'not ok ' + e.msg
2008-03-20 10:24:12 +01:00
2007-11-16 17:45:39 +01:00
class XmlRpcReceiver(threading.Thread):
2009-02-21 20:35:51 +01:00
def __init__(self, xmlRpcRecvAddr, entries):
2007-11-16 17:45:39 +01:00
threading.Thread.__init__(self)
self.xmlRpcRecvAddr = xmlRpcRecvAddr
2009-02-21 20:35:51 +01:00
XmlRpcServer.setClassParams(entries)
2007-11-16 17:45:39 +01:00
self.setDaemon(True)
def run(self):
2008-08-12 16:18:57 +02:00
server = XmlRpcServer(self.xmlRpcRecvAddr)
server.serve_forever()
2007-11-16 17:45:39 +01:00