Back to index

d-push  2.0
Public Member Functions | Public Attributes | Private Attributes
BackendSearchLDAP Class Reference
Inheritance diagram for BackendSearchLDAP:
Inheritance graph
[legend]
Collaboration diagram for BackendSearchLDAP:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 BackendSearchLDAP ()
 Initializes the backend to perform the search Connects to the LDAP server using the values from the configuration.
 SupportsType ($searchtype)
 Indicates if a search type is supported by this SearchProvider Currently only the type ISearchProvider::SEARCH_GAL (Global Address List) is implemented.
 GetGALSearchResults ($searchquery, $searchrange)
 Queries the LDAP backend.
 GetMailboxSearchResults ($cpo)
 Searches for the emails on the server.
 TerminateSearch ($pid)
 Terminates a search for a given PID.
 Disconnect ()
 Disconnects from LDAP.

Public Attributes

const SEARCH_GAL = "GAL"
const SEARCH_MAILBOX = "MAILBOX"
const SEARCH_DOCUMENTLIBRARY = "DOCUMENTLIBRARY"

Private Attributes

 $connection

Detailed Description

Definition at line 48 of file searchldap.php.


Member Function Documentation

Initializes the backend to perform the search Connects to the LDAP server using the values from the configuration.

public

Returns:
Exceptions:
StatusException

Definition at line 60 of file searchldap.php.

                                        {
        if (!function_exists("ldap_connect"))
            throw new StatusException("BackendSearchLDAP(): php-ldap is not installed. Search aborted.", SYNC_SEARCHSTATUS_STORE_SERVERERROR, null, LOGLEVEL_FATAL);

        // connect to LDAP
        $this->connection = @ldap_connect(LDAP_HOST, LDAP_PORT);
        @ldap_set_option($this->connection, LDAP_OPT_PROTOCOL_VERSION, 3);

        // Authenticate
        if (constant('ANONYMOUS_BIND') === true) {
            if(! @ldap_bind($this->connection)) {
                $this->connection = false;
                throw new StatusException("BackendSearchLDAP(): Could not bind anonymously to server! Search aborted.", SYNC_SEARCHSTATUS_STORE_CONNECTIONFAILED, null, LOGLEVEL_ERROR);
            }
        }
        else if (constant('LDAP_BIND_USER') != "") {
            if(! @ldap_bind($this->connection, LDAP_BIND_USER, LDAP_BIND_PASSWORD)) {
                $this->connection = false;
                throw new StatusException(sprintf("BackendSearchLDAP(): Could not bind to server with user '%s' and specified password! Search aborted.", LDAP_BIND_USER), SYNC_SEARCHSTATUS_STORE_ACCESSDENIED, null, LOGLEVEL_ERROR);
            }
        }
        else {
            // it would be possible to use the users login and password to authenticate on the LDAP server
            // the main $backend has to keep these values so they could be used here
            $this->connection = false;
            throw new StatusException("BackendSearchLDAP(): neither anonymous nor default bind enabled. Other options not implemented.", SYNC_SEARCHSTATUS_STORE_CONNECTIONFAILED, null, LOGLEVEL_ERROR);
        }
    }

Disconnects from LDAP.

public

Returns:
boolean

Implements ISearchProvider.

Definition at line 191 of file searchldap.php.

                                 {
        if ($this->connection)
            @ldap_close($this->connection);

        return true;
    }
BackendSearchLDAP::GetGALSearchResults ( searchquery,
searchrange 
)

Queries the LDAP backend.

Parameters:
string$searchquerystring to be searched for
string$searchrangespecified searchrange

public

Returns:
array search results

Implements ISearchProvider.

Definition at line 112 of file searchldap.php.

                                                                    {
        global $ldap_field_map;
        if (isset($this->connection) && $this->connection !== false) {
            $searchfilter = str_replace("SEARCHVALUE", $searchquery, LDAP_SEARCH_FILTER);
            $result = @ldap_search($this->connection, LDAP_SEARCH_BASE, $searchfilter);
            if (!$result) {
                ZLog::Write(LOGLEVEL_ERROR, "BackendSearchLDAP: Error in search query. Search aborted");
                return false;
            }

            // get entry data as array
            $searchresult = ldap_get_entries($this->connection, $result);

            // range for the search results, default symbian range end is 50, wm 99,
            // so we'll use that of nokia
            $rangestart = 0;
            $rangeend = 50;

            if ($searchrange != '0') {
                $pos = strpos($searchrange, '-');
                $rangestart = substr($searchrange, 0, $pos);
                $rangeend = substr($searchrange, ($pos + 1));
            }
            $items = array();

            // TODO the limiting of the searchresults could be refactored into Utils as it's probably used more than once
            $querycnt = $searchresult['count'];
            //do not return more results as requested in range
            $querylimit = (($rangeend + 1) < $querycnt) ? ($rangeend + 1) : $querycnt;
            $items['range'] = $rangestart.'-'.($querycnt-1);
            $items['searchtotal'] = $querycnt;

            $rc = 0;
            for ($i = $rangestart; $i < $querylimit; $i++) {
                foreach ($ldap_field_map as $key=>$value ) {
                    if (isset($searchresult[$i][$value])) {
                        if (is_array($searchresult[$i][$value]))
                            $items[$rc][$key] = $searchresult[$i][$value][0];
                        else
                            $items[$rc][$key] = $searchresult[$i][$value];
                    }
                }
                $rc++;
            }

            return $items;
        }
        else
            return false;
    }

Here is the call graph for this function:

Searches for the emails on the server.

Parameters:
ContentParameter$cpo
Returns:
array

Implements ISearchProvider.

Definition at line 170 of file searchldap.php.

                                                  {
        return array();
    }

Indicates if a search type is supported by this SearchProvider Currently only the type ISearchProvider::SEARCH_GAL (Global Address List) is implemented.

Parameters:
string$searchtypepublic
Returns:
boolean

Implements ISearchProvider.

Definition at line 98 of file searchldap.php.

                                              {
        return ($searchtype == ISearchProvider::SEARCH_GAL);
    }

Terminates a search for a given PID.

Parameters:
int$pid
Returns:
boolean

Implements ISearchProvider.

Definition at line 181 of file searchldap.php.

                                          {
        return true;
    }

Member Data Documentation

Definition at line 49 of file searchldap.php.

const ISearchProvider::SEARCH_DOCUMENTLIBRARY = "DOCUMENTLIBRARY" [inherited]

Definition at line 48 of file isearchprovider.php.

const ISearchProvider::SEARCH_GAL = "GAL" [inherited]

Definition at line 46 of file isearchprovider.php.

const ISearchProvider::SEARCH_MAILBOX = "MAILBOX" [inherited]

Definition at line 47 of file isearchprovider.php.


The documentation for this class was generated from the following file: