removed another bunch of references to geni
[sfa.git] / sfa / server / SfaRegistryModPython.py
1 #
2 # Apache mod_python interface
3 #
4 # Aaron Klingaman <alk@absarokasoft.com>
5 # Mark Huang <mlhuang@cs.princeton.edu>
6 #
7 # Copyright (C) 2004-2006 The Trustees of Princeton University
8 #
9
10 import sys
11 import traceback
12 import xmlrpclib
13 from mod_python import apache
14 from sfa.util.debug import log
15 from sfa.plc.api import SfaAPI
16
17 api = SfaAPI(interface='registry')
18
19 class unbuffered:
20     """\r
21     Write to /var/log/httpd/error_log. See\r
22 \r
23     http://www.modpython.org/FAQ/faqw.py?req=edit&file=faq02.003.htp\r
24     """\r
25 \r
26     def write(self, data):\r
27         sys.stderr.write(data)\r
28         sys.stderr.flush()\r
29 \r
30 #log = unbuffered()
31
32 def handler(req):
33     try:
34         if req.method != "POST":
35             req.content_type = "text/html"
36             req.send_http_header()
37             req.write("""
38 <html><head>
39 <title>SFA Registry API XML-RPC/SOAP Interface</title>
40 </head><body>
41 <h1>SFA Registry API XML-RPC/SOAP Interface</h1>
42 <p>Please use XML-RPC or SOAP to access the SFA API.</p>
43 </body></html>
44 """)
45             return apache.OK
46
47         # Read request
48         request = req.read(int(req.headers_in['content-length']))
49
50         # mod_python < 3.2: The IP address portion of remote_addr is
51         # incorrect (always 0.0.0.0) when IPv6 is enabled.
52         # http://issues.apache.org/jira/browse/MODPYTHON-64?page=all
53         (remote_ip, remote_port) = req.connection.remote_addr
54         remote_addr = (req.connection.remote_ip, remote_port)
55
56         # Handle request
57         response = api.handle(remote_addr, request)
58
59         # Write response
60         req.content_type = "text/xml; charset=" + api.encoding
61         req.send_http_header()
62         req.write(response)
63
64         return apache.OK
65
66     except Exception, err:
67         # Log error in /var/log/httpd/(ssl_)?error_log
68         print >> log, err, traceback.format_exc()
69         return apache.HTTP_INTERNAL_SERVER_ERROR