<h1>Project "FreeSWITCH user-contributed scripts, etc" received a push.</h1>
<h2>branch: master updated</h2>
<pre>
via: 8b7b83f0a42fc7cce5deaacd1c3a56f76c392175 (commit)
from: 7f89d85adb464f103abda4c3cee75a10f9515921 (commit)
</pre>= COMMIT LOG ===========================================================
<div class="highlight"><pre>committer: Mathieu Parent
comments:
MediaBrotha: adding LDAP backend
<span style="color: #000080; font-weight: bold">diff --git a/sathieu/cisco-xml/lib/MediaBrotha/Backend/LDAP.php b/sathieu/cisco-xml/lib/MediaBrotha/Backend/LDAP.php</span>
new file mode 100644
<span style="color: #000080; font-weight: bold">index 0000000..d275ff1</span>
<span style="color: #A00000">--- /dev/null</span>
<span style="color: #00A000">+++ b/sathieu/cisco-xml/lib/MediaBrotha/Backend/LDAP.php</span>
<span style="color: #800080; font-weight: bold">@@ -0,0 +1,88 @@</span>
<span style="color: #00A000">+<?php</span>
<span style="color: #00A000">+/*</span>
<span style="color: #00A000">+Copyright 2011 Mathieu Parent <math.parent@gmail.com> </span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+This file is part of MediaBrotha.</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        MediaBrotha is free software: you can</span>
<span style="color: #00A000">+        redistribute it and/or modify it under the terms of the GNU General</span>
<span style="color: #00A000">+        Public License as published by the Free Software Foundation, either</span>
<span style="color: #00A000">+        version 3 of the License, or (at your option) any later version.</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        MediaBrotha is distributed in the hope that it</span>
<span style="color: #00A000">+        will be useful, but WITHOUT ANY WARRANTY; without even the implied</span>
<span style="color: #00A000">+        warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See</span>
<span style="color: #00A000">+        the GNU General Public License for more details.</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        You should have received a copy of the GNU General Public License</span>
<span style="color: #00A000">+        along with MediaBrotha. If not, see</span>
<span style="color: #00A000">+        <http://www.gnu.org/licenses/>.</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+*/</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+require_once('Net/LDAP2.php');</span>
<span style="color: #00A000">+/**</span>
<span style="color: #00A000">+ * @author Mathieu Parent</span>
<span style="color: #00A000">+ */</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+class MediaBrotha_Backend_LDAP extends MediaBrotha_Backend {</span>
<span style="color: #00A000">+        private $_ldap;</span>
<span style="color: #00A000">+        public function __construct(array $args = Array()) {</span>
<span style="color: #00A000">+                parent::__construct($args);</span>
<span style="color: #00A000">+                $this->_ldap = Net_LDAP2::connect($this->getMetadata('ldap_connect_config'));</span>
<span style="color: #00A000">+                if (Net_LDAP2::isError($this->_ldap)) {</span>
<span style="color: #00A000">+                        die('Could not fetch entry: '.$this->_ldap->getMessage());</span>
<span style="color: #00A000">+                }</span>
<span style="color: #00A000">+        }</span>
<span style="color: #00A000">+        public function register() {</span>
<span style="color: #00A000">+                parent::register();</span>
<span style="color: #00A000">+                MediaBrotha_Core::registerMimeType($this, 'text/directory');</span>
<span style="color: #00A000">+        }</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        public function capabilities($uri = NULL, $mime_type = NULL, $mime_encoding = NULL) {</span>
<span style="color: #00A000">+                return Array(</span>
<span style="color: #00A000">+                        'browse',</span>
<span style="color: #00A000">+                );</span>
<span style="color: #00A000">+        }</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        public function isURISafe($uri) {</span>
<span style="color: #00A000">+                return true;</span>
<span style="color: #00A000">+        }</span>
<span style="color: #00A000">+        </span>
<span style="color: #00A000">+        </span>
<span style="color: #00A000">+        public static function parseLDAPURI($uri, $component = NULL) {</span>
<span style="color: #00A000">+                $uri = preg_replace('@^ldap:///@', 'ldap://fake_host/', $uri);</span>
<span style="color: #00A000">+                $components = parse_url($uri, $component);</span>
<span style="color: #00A000">+                if (is_array($components) && ($components['host'] === 'fake_host')) {</span>
<span style="color: #00A000">+                        $components['host'] = NULL;</span>
<span style="color: #00A000">+                }</span>
<span style="color: #00A000">+                return $components;</span>
<span style="color: #00A000">+        }</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        // Capability browse</span>
<span style="color: #00A000">+        public function fetch($uri) {</span>
<span style="color: #00A000">+                if (($this::parseLDAPURI($uri, PHP_URL_SCHEME) != 'ldap') || !$this->isURISafe($uri)) {</span>
<span style="color: #00A000">+                        $ldap_connect_config = $this->getMetadata('ldap_connect_config');</span>
<span style="color: #00A000">+                        $uri = 'ldap:///'.$ldap_connect_config['basedn'];</span>
<span style="color: #00A000">+                }</span>
<span style="color: #00A000">+                $basedn = $this::parseLDAPURI($uri, PHP_URL_PATH);</span>
<span style="color: #00A000">+                if ($basedn && ($basedn{0} = '/')) {</span>
<span style="color: #00A000">+                        $basedn = substr($basedn, 1);        </span>
<span style="color: #00A000">+                }</span>
<span style="color: #00A000">+                $this->_buffer = $this->_ldap->search($basedn, NULL,</span>
<span style="color: #00A000">+                        Array());</span>
<span style="color: #00A000">+                return true;</span>
<span style="color: #00A000">+        }</span>
<span style="color: #00A000">+        protected function _mediaFromBufferItem($entry) {</span>
<span style="color: #00A000">+                if ($entry) {</span>
<span style="color: #00A000">+                        $media = new MediaBrotha_Media(Array(</span>
<span style="color: #00A000">+                                'uri' => 'ldap:///'.$entry->dn(),</span>
<span style="color: #00A000">+                                'name' => $entry->dn(), //$entry->getValue('sn', 'single'),</span>
<span style="color: #00A000">+                        ));</span>
<span style="color: #00A000">+                        $media->setMimeType('text/directory');</span>
<span style="color: #00A000">+                        //        $media->setMimeEncoding($finfo->file($file->getPathname(), FILEINFO_MIME_ENCODING));</span>
<span style="color: #00A000">+                        return $media;</span>
<span style="color: #00A000">+                }</span>
<span style="color: #00A000">+        }</span>
<span style="color: #00A000">+}</span>
<span style="color: #00A000">+</span>
</pre></div>
========================================================================<pre>
Summary of changes:
sathieu/cisco-xml/lib/MediaBrotha/Backend/LDAP.php | 88 ++++++++++++++++++++
1 files changed, 88 insertions(+), 0 deletions(-)
create mode 100644 sathieu/cisco-xml/lib/MediaBrotha/Backend/LDAP.php
</pre>
<p>this email was generated because of /git/your-repo.git/hooks/post-receive by the file /git-core/contrib/hooks/post-receive-email<br />
For more info, see <a href="http://blog.chomperstomp.com/?p=630">http://blog.chomperstomp.com/?p=630</a>
-- <br />
FreeSWITCH user-contributed scripts, etc</p>