<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[14752] CalDAVTester/trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.calendarserver.org//changeset/14752">14752</a></dd>
<dt>Author</dt> <dd>cdaboo@apple.com</dd>
<dt>Date</dt> <dd>2015-05-05 07:31:00 -0700 (Tue, 05 May 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>Allow connecting to a server via a unix socket (use &lt;unix&gt;...&lt;/unix&gt; element in serverinfo.xml).</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#CalDAVTestertrunkscriptsserverserverinfodtd">CalDAVTester/trunk/scripts/server/serverinfo.dtd</a></li>
<li><a href="#CalDAVTestertrunksrccaldavtestpy">CalDAVTester/trunk/src/caldavtest.py</a></li>
<li><a href="#CalDAVTestertrunksrchttpshandlerpy">CalDAVTester/trunk/src/httpshandler.py</a></li>
<li><a href="#CalDAVTestertrunksrcmanagerpy">CalDAVTester/trunk/src/manager.py</a></li>
<li><a href="#CalDAVTestertrunksrcrequestpy">CalDAVTester/trunk/src/request.py</a></li>
<li><a href="#CalDAVTestertrunksrcserverinfopy">CalDAVTester/trunk/src/serverinfo.py</a></li>
<li><a href="#CalDAVTestertrunksrcxmlDefspy">CalDAVTester/trunk/src/xmlDefs.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalDAVTestertrunkscriptsserverserverinfodtd"></a>
<div class="modfile"><h4>Modified: CalDAVTester/trunk/scripts/server/serverinfo.dtd (14751 => 14752)</h4>
<pre class="diff"><span>
<span class="info">--- CalDAVTester/trunk/scripts/server/serverinfo.dtd        2015-05-05 14:29:43 UTC (rev 14751)
+++ CalDAVTester/trunk/scripts/server/serverinfo.dtd        2015-05-05 14:31:00 UTC (rev 14752)
</span><span class="lines">@@ -14,15 +14,19 @@
</span><span class="cx">  limitations under the License.
</span><span class="cx">  --&gt;
</span><span class="cx"> 
</span><del>-&lt;!ELEMENT serverinfo (host, nonsslport, sslport, host2?, nonsslport2?, sslport2?, authtype?,
-                                                waitcount?, waitdelay?, waitsuccess?, features?, substitutions)? &gt;
</del><ins>+&lt;!ELEMENT serverinfo (host, nonsslport, sslport, unix?,
+                                                host2?, nonsslport2?, sslport2?, unix2?,
+                                                authtype?, waitcount?, waitdelay?, waitsuccess?,
+                                                features?, substitutions)? &gt;
</ins><span class="cx"> 
</span><span class="cx">         &lt;!ELEMENT host                        (#PCDATA)&gt;
</span><span class="cx">         &lt;!ELEMENT nonsslport        (#PCDATA)&gt;
</span><span class="cx">         &lt;!ELEMENT sslport                (#PCDATA)&gt;
</span><ins>+        &lt;!ELEMENT unix                        (#PCDATA)&gt;
</ins><span class="cx">         &lt;!ELEMENT host2                        (#PCDATA)&gt;
</span><span class="cx">         &lt;!ELEMENT nonsslport2        (#PCDATA)&gt;
</span><span class="cx">         &lt;!ELEMENT sslport2                (#PCDATA)&gt;
</span><ins>+        &lt;!ELEMENT unix2                        (#PCDATA)&gt;
</ins><span class="cx">         &lt;!ELEMENT authtype                (#PCDATA)&gt;
</span><span class="cx">         &lt;!ELEMENT waitdelay     (#PCDATA)&gt;
</span><span class="cx">         &lt;!ELEMENT waitcount     (#PCDATA)&gt;
</span></span></pre></div>
<a id="CalDAVTestertrunksrccaldavtestpy"></a>
<div class="modfile"><h4>Modified: CalDAVTester/trunk/src/caldavtest.py (14751 => 14752)</h4>
<pre class="diff"><span>
<span class="info">--- CalDAVTester/trunk/src/caldavtest.py        2015-05-05 14:29:43 UTC (rev 14751)
+++ CalDAVTester/trunk/src/caldavtest.py        2015-05-05 14:31:00 UTC (rev 14752)
</span><span class="lines">@@ -664,7 +664,7 @@
</span><span class="cx">             stats.startTimer()
</span><span class="cx"> 
</span><span class="cx">         # Do the http request
</span><del>-        http = SmartHTTPConnection(req.host, req.port, self.manager.server_info.ssl)
</del><ins>+        http = SmartHTTPConnection(req.host, req.port, self.manager.server_info.ssl, afunix=req.afunix)
</ins><span class="cx"> 
</span><span class="cx">         if 'User-Agent' not in headers and label is not None:
</span><span class="cx">             headers['User-Agent'] = label.encode(&quot;utf-8&quot;)
</span></span></pre></div>
<a id="CalDAVTestertrunksrchttpshandlerpy"></a>
<div class="modfile"><h4>Modified: CalDAVTester/trunk/src/httpshandler.py (14751 => 14752)</h4>
<pre class="diff"><span>
<span class="info">--- CalDAVTester/trunk/src/httpshandler.py        2015-05-05 14:29:43 UTC (rev 14751)
+++ CalDAVTester/trunk/src/httpshandler.py        2015-05-05 14:31:00 UTC (rev 14752)
</span><span class="lines">@@ -19,7 +19,9 @@
</span><span class="cx"> import ssl as sslmodule
</span><span class="cx"> 
</span><span class="cx"> class HTTPSVersionConnection(httplib.HTTPSConnection):
</span><del>-    &quot;This class allows communication via SSL.&quot;
</del><ins>+    &quot;&quot;&quot;
+    An L{httplib.HTTPSConnection} class that allows the TLS protocol version to be set.
+    &quot;&quot;&quot;
</ins><span class="cx"> 
</span><span class="cx">     def __init__(self, host, port, ssl_version=sslmodule.PROTOCOL_TLSv1):
</span><span class="cx">         httplib.HTTPSConnection.__init__(self, host, port)
</span><span class="lines">@@ -39,14 +41,48 @@
</span><span class="cx">     (set(), sslmodule.PROTOCOL_SSLv23),
</span><span class="cx"> )
</span><span class="cx"> 
</span><del>-def SmartHTTPConnection(host, port, ssl):
</del><ins>+class UnixSocketHTTPConnection(httplib.HTTPConnection):
+    &quot;&quot;&quot;
+    An L{httplib.HTTPConnection} class that uses a unix socket rather than TCP.
+    &quot;&quot;&quot;
</ins><span class="cx"> 
</span><ins>+    def __init__(self, path):
+        httplib.HTTPConnection.__init__(self, &quot;http.sock&quot;, port=None)
+        self.path = path
+
+
+    def connect(self):
+        &quot;&quot;&quot;
+        Connect using the supplied unix socket file path
+        &quot;&quot;&quot;
+        self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
+        self.sock.connect(self.path)
+
+
+
+def SmartHTTPConnection(host, port, ssl, afunix):
+    &quot;&quot;&quot;
+    Create the appropriate L{httplib.HTTPConnection} derived class for the supplied arguments.
+
+    @param host: TCP host name
+    @type host: L{str}
+    @param port: TCP port number
+    @type port: L{int}
+    @param ssl: indicates if SSL is to be used
+    @type ssl: L{bool}
+    @param afunix: unix socket to use or L{None}
+    @type afunix: L{str}
+    &quot;&quot;&quot;
+
</ins><span class="cx">     def trySSL(version):
</span><span class="cx">         connect = HTTPSVersionConnection(host, port, ssl_version=version)
</span><span class="cx">         connect.connect()
</span><span class="cx">         return connect
</span><span class="cx"> 
</span><del>-    if ssl:
</del><ins>+    if afunix:
+        connect = UnixSocketHTTPConnection(afunix)
+    elif ssl:
+        # Iterate over the TL:S versions and find one that works and cache it for future use.
</ins><span class="cx">         for cached, connection_type in cached_types:
</span><span class="cx">             if (host, port) in cached:
</span><span class="cx">                 try:
</span><span class="lines">@@ -64,5 +100,5 @@
</span><span class="cx">         raise RuntimeError(&quot;Cannot connect via with TLSv1, SSLv3 or SSLv23&quot;)
</span><span class="cx">     else:
</span><span class="cx">         connect = httplib.HTTPConnection(host, port)
</span><del>-        connect.connect()
-        return connect
</del><ins>+    connect.connect()
+    return connect
</ins></span></pre></div>
<a id="CalDAVTestertrunksrcmanagerpy"></a>
<div class="modfile"><h4>Modified: CalDAVTester/trunk/src/manager.py (14751 => 14752)</h4>
<pre class="diff"><span>
<span class="info">--- CalDAVTester/trunk/src/manager.py        2015-05-05 14:29:43 UTC (rev 14751)
+++ CalDAVTester/trunk/src/manager.py        2015-05-05 14:31:00 UTC (rev 14752)
</span><span class="lines">@@ -22,7 +22,6 @@
</span><span class="cx"> from xml.etree.cElementTree import ElementTree
</span><span class="cx"> from xml.parsers.expat import ExpatError
</span><span class="cx"> import getopt
</span><del>-import httplib
</del><span class="cx"> import os
</span><span class="cx"> import random
</span><span class="cx"> import src.xmlDefs
</span><span class="lines">@@ -402,23 +401,6 @@
</span><span class="cx">         return failed, endTime - startTime
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def httpRequest(self, method, uri, headers, data):
-
-        # Do the http request
-        http = httplib.HTTPConnection(self.server_info.host, self.server_info.port)
-        try:
-            http.request(method, uri, data, headers)
-
-            response = http.getresponse()
-
-            respdata = response.read()
-
-        finally:
-            http.close()
-
-        return response.status, respdata
-
-
</del><span class="cx">     def getMemusage(self):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span></span></pre></div>
<a id="CalDAVTestertrunksrcrequestpy"></a>
<div class="modfile"><h4>Modified: CalDAVTester/trunk/src/request.py (14751 => 14752)</h4>
<pre class="diff"><span>
<span class="info">--- CalDAVTester/trunk/src/request.py        2015-05-05 14:29:43 UTC (rev 14751)
+++ CalDAVTester/trunk/src/request.py        2015-05-05 14:31:00 UTC (rev 14752)
</span><span class="lines">@@ -146,6 +146,7 @@
</span><span class="cx">         self.manager = manager
</span><span class="cx">         self.host = self.manager.server_info.host
</span><span class="cx">         self.port = self.manager.server_info.port
</span><ins>+        self.afunix = self.manager.server_info.afunix
</ins><span class="cx">         self.auth = True
</span><span class="cx">         self.user = &quot;&quot;
</span><span class="cx">         self.pswd = &quot;&quot;
</span><span class="lines">@@ -234,7 +235,7 @@
</span><span class="cx">         if user in self.manager.digestCache:
</span><span class="cx">             details = self.manager.digestCache[user]
</span><span class="cx">         else:
</span><del>-            http = SmartHTTPConnection(si.host, si.port, si.ssl)
</del><ins>+            http = SmartHTTPConnection(si.host, si.port, si.ssl, si.afunix)
</ins><span class="cx">             try:
</span><span class="cx">                 http.request(&quot;OPTIONS&quot;, self.getURI(si))
</span><span class="cx"> 
</span><span class="lines">@@ -381,6 +382,7 @@
</span><span class="cx">         if node.get(src.xmlDefs.ATTR_HOST2, src.xmlDefs.ATTR_VALUE_NO) == src.xmlDefs.ATTR_VALUE_YES:
</span><span class="cx">             self.host = self.manager.server_info.host2
</span><span class="cx">             self.port = self.manager.server_info.port2
</span><ins>+            self.afunix = self.manager.server_info.afunix2
</ins><span class="cx"> 
</span><span class="cx">         for child in node.getchildren():
</span><span class="cx">             if child.tag == src.xmlDefs.ELEMENT_REQUIRE_FEATURE:
</span></span></pre></div>
<a id="CalDAVTestertrunksrcserverinfopy"></a>
<div class="modfile"><h4>Modified: CalDAVTester/trunk/src/serverinfo.py (14751 => 14752)</h4>
<pre class="diff"><span>
<span class="info">--- CalDAVTester/trunk/src/serverinfo.py        2015-05-05 14:29:43 UTC (rev 14751)
+++ CalDAVTester/trunk/src/serverinfo.py        2015-05-05 14:31:00 UTC (rev 14752)
</span><span class="lines">@@ -36,9 +36,11 @@
</span><span class="cx">         self.host = &quot;&quot;
</span><span class="cx">         self.nonsslport = 80
</span><span class="cx">         self.sslport = 443
</span><ins>+        self.afunix = None
</ins><span class="cx">         self.host2 = &quot;&quot;
</span><span class="cx">         self.nonsslport2 = 80
</span><span class="cx">         self.sslport2 = 443
</span><ins>+        self.afunix2 = None
</ins><span class="cx">         self.authtype = &quot;basic&quot;
</span><span class="cx">         self.features = set()
</span><span class="cx">         self.user = &quot;&quot;
</span><span class="lines">@@ -166,6 +168,8 @@
</span><span class="cx">                 self.nonsslport = int(child.text)
</span><span class="cx">             elif child.tag == src.xmlDefs.ELEMENT_SSLPORT:
</span><span class="cx">                 self.sslport = int(child.text)
</span><ins>+            elif child.tag == src.xmlDefs.ELEMENT_UNIX:
+                self.afunix = child.text
</ins><span class="cx">             elif child.tag == src.xmlDefs.ELEMENT_HOST2:
</span><span class="cx">                 try:
</span><span class="cx">                     self.host2 = child.text.encode(&quot;utf-8&quot;)
</span><span class="lines">@@ -175,6 +179,8 @@
</span><span class="cx">                 self.nonsslport2 = int(child.text)
</span><span class="cx">             elif child.tag == src.xmlDefs.ELEMENT_SSLPORT2:
</span><span class="cx">                 self.sslport2 = int(child.text)
</span><ins>+            elif child.tag == src.xmlDefs.ELEMENT_UNIX2:
+                self.afunix2 = child.text
</ins><span class="cx">             elif child.tag == src.xmlDefs.ELEMENT_AUTHTYPE:
</span><span class="cx">                 self.authtype = child.text.encode(&quot;utf-8&quot;)
</span><span class="cx">             elif child.tag == src.xmlDefs.ELEMENT_WAITCOUNT:
</span></span></pre></div>
<a id="CalDAVTestertrunksrcxmlDefspy"></a>
<div class="modfile"><h4>Modified: CalDAVTester/trunk/src/xmlDefs.py (14751 => 14752)</h4>
<pre class="diff"><span>
<span class="info">--- CalDAVTester/trunk/src/xmlDefs.py        2015-05-05 14:29:43 UTC (rev 14751)
+++ CalDAVTester/trunk/src/xmlDefs.py        2015-05-05 14:31:00 UTC (rev 14752)
</span><span class="lines">@@ -76,6 +76,8 @@
</span><span class="cx"> ELEMENT_TESTSUITE = &quot;test-suite&quot;
</span><span class="cx"> ELEMENT_TIMEOUT = &quot;timeout&quot;
</span><span class="cx"> ELEMENT_THREADS = &quot;threads&quot;
</span><ins>+ELEMENT_UNIX = &quot;unix&quot;
+ELEMENT_UNIX2 = &quot;unix2&quot;
</ins><span class="cx"> ELEMENT_VALUE = &quot;value&quot;
</span><span class="cx"> ELEMENT_VARIABLE = &quot;variable&quot;
</span><span class="cx"> ELEMENT_VERIFY = &quot;verify&quot;
</span></span></pre>
</div>
</div>

</body>
</html>