summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormakefu <github@syntax-fehler.de>2011-09-17 12:06:21 +0200
committermakefu <github@syntax-fehler.de>2011-09-17 12:06:21 +0200
commit87a25a6527bcd9fd9c7ffa6eea9668e4bfd4b718 (patch)
tree89507e52f7b2feac93121b1e01c335279d009c80
parentd40812a81a6a5ae898e319c51fcf938950af2020 (diff)
Reaktor/UDP: ubot - initial commit
update specs which now decribe how the head of the conf entry may look like ubot is currenly an executable skeleton which important functions marked as to be implemented.
-rw-r--r--Reaktor/UDP/README11
-rwxr-xr-xReaktor/UDP/index57
2 files changed, 68 insertions, 0 deletions
diff --git a/Reaktor/UDP/README b/Reaktor/UDP/README
index f89d377d..ad7117fe 100644
--- a/Reaktor/UDP/README
+++ b/Reaktor/UDP/README
@@ -13,6 +13,17 @@ From 2011-09-16:
}
}
]
+## Head definition
+ {
+ "bind" : "127.0.0.1",
+ "port" : 1234,
+ "pattern" : "XXZZ",
+ "terminator" : "\r\n"
+ "action" : { },
+ }
+bind is an optional entry which lets the user define a bind address for the server.
+terminator is optional which lets the user define the EOM terminator.
+
## Actions
### POST
"POST" : {
diff --git a/Reaktor/UDP/index b/Reaktor/UDP/index
new file mode 100755
index 00000000..950f0d21
--- /dev/null
+++ b/Reaktor/UDP/index
@@ -0,0 +1,57 @@
+#!/usr/bin/python
+
+from asycore import asychat
+import logging
+import sys
+log = logging.getLogger('asybot')
+
+def enable_syslog(logger):
+ import logging.handlers as handlers
+ from logging import Formatter
+ hdlr = handlers.SysLogHandler(
+ facility=handlers.SysLogHandler.LOG_DAEMON)
+ formatter = Formatter(
+ '%(filename)s: %(levelname)s: %(message)s')
+ hdlr.setFormatter(formatter)
+ logger.addHandler(hdlr)
+
+class ubot(asychat):
+ """ UDP Bot """
+ def __init__(self, port,pattern,action,bind="0.0.0.0",terminator='\r\n'):
+ asychat.__init__(self)
+ self.bind = bind
+ self.port = port
+ self.data = ''
+ self.set_terminator('\r\n')
+ self.bind_socket()
+
+ def bind_socket(self):
+ """
+ if the socket is already bound we want to reuse this socket anyway
+ """
+ log.error("not yet implemented")
+ sys.exit(23)
+ def collect_incoming_data(self,data):
+ self.data += data
+
+ def found_terminator(self):
+ """
+ TODO what happens if, for example in an html message we find our pattern a hundred times.
+ should the actions been called a hundred times or just once for the connect?
+ """
+ log.debug('<< %s' % self.data)
+
+ message = self.data
+ self.data = ''
+ if self.find_pattern(message):
+ self.start_action(message)
+
+ def find_pattern(self,message):
+ """ returns true if own pattern is found"""
+ log.error("not yet implemented")
+ sys.exit(23)
+
+ def start_action(self,message):
+ """ runs all the defined actions"""
+ log.error("not yet implemented")
+ sys.exit(23)