Back to index

lightning-sunbird  0.9+nobinonly
Static Public Member Functions | Static Public Attributes | Static Protected Member Functions
nsAbBoolExprToLDAPFilter Class Reference

#include <nsAbBoolExprToLDAPFilter.h>

List of all members.

Static Public Member Functions

static nsresult Convert (nsIAbLDAPAttributeMap *map, nsIAbBooleanExpression *expression, nsCString &filter, int flags=TRANSLATE_CARD_PROPERTY)

Static Public Attributes

static const int TRANSLATE_CARD_PROPERTY = 1 << 0
static const int ALLOW_NON_CONVERTABLE_CARD_PROPERTY = 1 << 1

Static Protected Member Functions

static nsresult FilterExpression (nsIAbLDAPAttributeMap *map, nsIAbBooleanExpression *expression, nsCString &filter, int flags)
static nsresult FilterExpressions (nsIAbLDAPAttributeMap *map, nsISupportsArray *expressions, nsCString &filter, int flags)
static nsresult FilterCondition (nsIAbLDAPAttributeMap *map, nsIAbBooleanConditionString *condition, nsCString &filter, int flags)

Detailed Description

Definition at line 49 of file nsAbBoolExprToLDAPFilter.h.


Member Function Documentation

Definition at line 47 of file nsAbBoolExprToLDAPFilter.cpp.

{
    nsCString f;
    nsresult rv = FilterExpression (map, expression, f, flags);
    NS_ENSURE_SUCCESS(rv, rv);

    filter = f;
    return rv;
}

Here is the call graph for this function:

nsresult nsAbBoolExprToLDAPFilter::FilterCondition ( nsIAbLDAPAttributeMap map,
nsIAbBooleanConditionString condition,
nsCString filter,
int  flags 
) [static, protected]

Definition at line 172 of file nsAbBoolExprToLDAPFilter.cpp.

{
    nsXPIDLCString name;
    nsresult rv = condition->GetName(getter_Copies (name));
    NS_ENSURE_SUCCESS(rv, rv);

    nsCAutoString ldapAttr(name);
    if (flags & TRANSLATE_CARD_PROPERTY)
    {
        rv = map->GetFirstAttribute (name, ldapAttr);
        if (!(flags & ALLOW_NON_CONVERTABLE_CARD_PROPERTY) && 
            !ATTRMAP_FOUND_ATTR(rv, ldapAttr))
            return NS_OK;
    }

    nsAbBooleanConditionType conditionType;
    rv = condition->GetCondition(&conditionType);
    NS_ENSURE_SUCCESS(rv, rv);

    nsXPIDLString value;
    rv = condition->GetValue (getter_Copies (value));
    NS_ENSURE_SUCCESS(rv, rv);
    NS_ConvertUCS2toUTF8 vUTF8 (value);

    switch (conditionType)
    {
        case nsIAbBooleanConditionTypes::DoesNotExist:
            filter += NS_LITERAL_CSTRING("(!(") +
                      ldapAttr +
                      NS_LITERAL_CSTRING("=*))");
            break;
        case nsIAbBooleanConditionTypes::Exists:
            filter += NS_LITERAL_CSTRING("(") +
                      ldapAttr +
                      NS_LITERAL_CSTRING("=*)");
            break;
        case nsIAbBooleanConditionTypes::Contains:
            filter += NS_LITERAL_CSTRING("(") +
                      ldapAttr +
                      NS_LITERAL_CSTRING("=*") +
                      vUTF8 +
                      NS_LITERAL_CSTRING("*)");
            break;
        case nsIAbBooleanConditionTypes::DoesNotContain:
            filter += NS_LITERAL_CSTRING("(!(") +
                      ldapAttr +
                      NS_LITERAL_CSTRING("=*") +
                      vUTF8 +
                      NS_LITERAL_CSTRING("*))");
            break;
        case nsIAbBooleanConditionTypes::Is:
            filter += NS_LITERAL_CSTRING("(") +
                      ldapAttr +
                      NS_LITERAL_CSTRING("=") +
                      vUTF8 +
                      NS_LITERAL_CSTRING(")");
            break;
        case nsIAbBooleanConditionTypes::IsNot:
            filter += NS_LITERAL_CSTRING("(!(") +
                      ldapAttr +
                      NS_LITERAL_CSTRING("=") +
                      vUTF8 +
                      NS_LITERAL_CSTRING("))");
            break;
        case nsIAbBooleanConditionTypes::BeginsWith:
            filter += NS_LITERAL_CSTRING("(") +
                      ldapAttr +
                      NS_LITERAL_CSTRING("=") +
                      vUTF8 +
                      NS_LITERAL_CSTRING("*)");
            break;
        case nsIAbBooleanConditionTypes::EndsWith:
            filter += NS_LITERAL_CSTRING("(") +
                      ldapAttr +
                      NS_LITERAL_CSTRING("=*") +
                      vUTF8 +
                      NS_LITERAL_CSTRING(")");
            break;
        case nsIAbBooleanConditionTypes::LessThan:
            filter += NS_LITERAL_CSTRING("(") +
                      ldapAttr +
                      NS_LITERAL_CSTRING("<=") +
                      vUTF8 +
                      NS_LITERAL_CSTRING(")");
            break;
        case nsIAbBooleanConditionTypes::GreaterThan:
            filter += NS_LITERAL_CSTRING("(") +
                      ldapAttr +
                      NS_LITERAL_CSTRING(">=") +
                      vUTF8 +
                      NS_LITERAL_CSTRING(")");
            break;
        case nsIAbBooleanConditionTypes::SoundsLike:
            filter += NS_LITERAL_CSTRING("(") +
                      ldapAttr +
                      NS_LITERAL_CSTRING("~=") +
                      vUTF8 +
                      NS_LITERAL_CSTRING(")");
            break;
        case nsIAbBooleanConditionTypes::RegExp:
            break;
        default:
            break;
    }

    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsAbBoolExprToLDAPFilter::FilterExpression ( nsIAbLDAPAttributeMap map,
nsIAbBooleanExpression expression,
nsCString filter,
int  flags 
) [static, protected]

Definition at line 61 of file nsAbBoolExprToLDAPFilter.cpp.

{
    nsCOMPtr<nsISupportsArray> childExpressions;
    nsresult rv = expression->GetExpressions(getter_AddRefs(childExpressions));
    NS_ENSURE_SUCCESS(rv, rv);
    
    PRUint32 count;
    rv = childExpressions->Count(&count);
    NS_ENSURE_SUCCESS(rv, rv);

    if (count == 0)
        return NS_OK;

    nsAbBooleanOperationType operation;
    rv = expression->GetOperation(&operation);
    NS_ENSURE_SUCCESS(rv, rv);

    /*
     * 3rd party query integration with Mozilla is achieved 
     * by calling nsAbLDAPDirectoryQuery::DoQuery(). Thus
     * we can arrive here with a query asking for all the
     * ldap attributes using the card:nsIAbCard interface.
     *
     * So we need to check that we are not creating a condition 
     * filter against this expression otherwise we will end up with an invalid 
     * filter equal to "(|)".
    */
    
    if (count == 1 )
    {
        nsCOMPtr<nsISupports> item;
        rv = childExpressions->GetElementAt (0, getter_AddRefs (item));
        NS_ENSURE_SUCCESS(rv, rv);

        nsCOMPtr<nsIAbBooleanConditionString> childCondition(do_QueryInterface(item, &rv));
        if (NS_SUCCEEDED(rv))
        {
            nsXPIDLCString name;
            rv = childCondition->GetName (getter_Copies (name));
            NS_ENSURE_SUCCESS(rv, rv);

            if(name.Equals("card:nsIAbCard"))
                return NS_OK;
        }
    }

    filter.AppendLiteral("(");
    switch (operation)
    {
        case nsIAbBooleanOperationTypes::AND:
            filter.AppendLiteral("&");
            rv = FilterExpressions (map, childExpressions, filter, flags);
            break;
        case nsIAbBooleanOperationTypes::OR:
            filter.AppendLiteral("|");
            rv = FilterExpressions (map, childExpressions, filter, flags);
            break;
        case nsIAbBooleanOperationTypes::NOT:
            if (count > 1)
                return NS_ERROR_FAILURE;
            filter.AppendLiteral("!");
            rv = FilterExpressions (map, childExpressions, filter, flags);
            break;
        default:
            break;
    }
    filter.AppendLiteral(")");

    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsAbBoolExprToLDAPFilter::FilterExpressions ( nsIAbLDAPAttributeMap map,
nsISupportsArray expressions,
nsCString filter,
int  flags 
) [static, protected]

Definition at line 136 of file nsAbBoolExprToLDAPFilter.cpp.

{
    PRUint32 count;
    nsresult rv = expressions->Count(&count);
    NS_ENSURE_SUCCESS(rv, rv);

    for (PRUint32 i = 0; i < count; i++)
    {
        nsCOMPtr<nsISupports> item;
        rv = expressions->GetElementAt (i, getter_AddRefs (item));
        NS_ENSURE_SUCCESS(rv, rv);

        nsCOMPtr<nsIAbBooleanConditionString> childCondition(do_QueryInterface(item, &rv));
        if (NS_SUCCEEDED(rv))
        {
            rv = FilterCondition (map, childCondition, filter, flags);
            NS_ENSURE_SUCCESS(rv, rv);
            continue;
        }

        nsCOMPtr<nsIAbBooleanExpression> childExpression(do_QueryInterface(item, &rv));
        if (NS_SUCCEEDED(rv))
        {
            rv = FilterExpression (map, childExpression, filter, flags);
            NS_ENSURE_SUCCESS(rv, rv);
            continue;
        }
    }

    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 53 of file nsAbBoolExprToLDAPFilter.h.

Definition at line 52 of file nsAbBoolExprToLDAPFilter.h.


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