Changeset

1194:f5eadba27120

mod_auth_external: Add example Python script
author Matthew Wild <mwild1@gmail.com>
date Thu, 19 Sep 2013 16:04:45 +0100
parents 1193:bbe278a56b0a
children 1195:f502cbffbdd4
files mod_auth_external/examples/python/prosody-auth-example.py
diffstat 1 files changed, 29 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mod_auth_external/examples/python/prosody-auth-example.py	Thu Sep 19 16:04:45 2013 +0100
@@ -0,0 +1,29 @@
+#!/usr/bin/env python2
+
+import sys
+
+def auth(username, password):
+	if username == "someone":
+		return "1"
+	return "0"
+
+def respond(ret):
+	sys.stdout.write(ret+"\n")
+	sys.stdout.flush()
+
+methods = {
+	"auth": { "function": auth, "parameters": 2 }
+}
+
+while 1:
+	line = sys.stdin.readline().rstrip("\n")
+	method, sep, data = line.partition(":")
+	if method in methods:
+		method_info = methods[method]
+		split_data = data.split(":", method_info["parameters"])
+		if len(split_data) == method_info["parameters"]:
+			respond(method_info["function"](*split_data))
+		else:
+			respond("error: incorrect number of parameters to method '%s'"%method)
+	else:
+		respond("error: method '%s' not implemented"%method)