Beispiel #1
0
bool MultiPath::Load(TiXmlElement* node)
{
  if(0!=strcmp(node->Value(),"multipath")) {
    fprintf(stderr,"MultiPath Load XML: node \"%s\" not of multipath type\n",node->Value());
    return false;
  }

  holdSet.clear();
  holdSetNames.clear();
  sections.clear();
  GetAttributeMap(node,settings);
  TiXmlElement* e=node->FirstChildElement();
  while(e != NULL) {
    if(0==strcmp(e->Value(),"section")) {
      sections.resize(sections.size()+1);
      GetAttributeMap(e,sections.back().settings);
      MultiPath::PathSection& section=sections.back();

      TiXmlElement* c=e->FirstChildElement();
      while(c != NULL) {
	if(0==strcmp(c->Value(),"ikgoal")) {
	  if(!c->GetText()) return false;
	  stringstream ss(c->GetText());
	  section.ikGoals.resize(section.ikGoals.size()+1);
	  ss >> section.ikGoals.back();
	  if(!ss) {
	    fprintf(stderr,"MultiPath Load XML: error loading ikgoal %d of section %d\n",section.ikGoals.size()-1,sections.size()-1);
	    return false;
	  }
	}
	else if(0==strcmp(c->Value(),"hold")) {
	  int index;
	  if(c->QueryValueAttribute("index",&index) == TIXML_SUCCESS) {
	    section.holdIndices.push_back(index);
	  }
	  else if(c->Attribute("name") != NULL) {
	    section.holdNames.push_back(c->Attribute("name"));
	  }
	  else {
	    if(c->GetText()==NULL) {
	      fprintf(stderr,"Hold has no text\n");
	      return false;
	    }
	    stringstream ss(c->GetText());
	    section.holds.resize(section.holds.size()+1);
	    ss>>section.holds.back();
	    if(!ss) {
	      fprintf(stderr,"MultiPath Load XML: unable to read hold %d of section %d\n",section.holds.size()-1,sections.size()-1);
	      return false;
	    }
	  }
	}
	else if(0==strcmp(c->Value(),"milestone")) {
Beispiel #2
0
NS_IMETHODIMP nsAbLDAPDirectory::ModifyCard(nsIAbCard *aUpdatedCard)
{
    NS_ENSURE_ARG_POINTER(aUpdatedCard);

    nsCOMPtr<nsIAbLDAPAttributeMap> attrMap;
    nsresult rv = GetAttributeMap(getter_AddRefs(attrMap));
    NS_ENSURE_SUCCESS(rv, rv);

    // Get the LDAP card
    nsCOMPtr<nsIAbLDAPCard> card = do_QueryInterface(aUpdatedCard, &rv);
    NS_ENSURE_SUCCESS(rv, rv);

    rv = Initiate();
    NS_ENSURE_SUCCESS(rv, rv);

    // Retrieve preferences
    nsCAutoString prefString;
    rv = GetObjectClasses(prefString);
    NS_ENSURE_SUCCESS(rv, rv);

    CharPtrArrayGuard objClass;
    rv = SplitStringList(prefString, objClass.GetSizeAddr(),
                         objClass.GetArrayAddr());
    NS_ENSURE_SUCCESS(rv, rv);

    // Process updates
    nsCOMPtr<nsIArray> modArray;
    rv = card->GetLDAPMessageInfo(attrMap, objClass.GetSize(), objClass.GetArray(),
                                  nsILDAPModification::MOD_REPLACE, getter_AddRefs(modArray));
    NS_ENSURE_SUCCESS(rv, rv);

    // Get current DN
    nsCAutoString oldDN;
    rv = card->GetDn(oldDN);
    NS_ENSURE_SUCCESS(rv, rv);

    nsCOMPtr<nsILDAPService> ldapSvc = do_GetService(
                                           "@mozilla.org/network/ldap-service;1", &rv);
    NS_ENSURE_SUCCESS(rv, rv);

    // Retrieve base DN and RDN attributes
    nsCAutoString baseDN;
    nsCAutoString oldRDN;
    CharPtrArrayGuard rdnAttrs;
    rv = ldapSvc->ParseDn(oldDN.get(), oldRDN, baseDN,
                          rdnAttrs.GetSizeAddr(), rdnAttrs.GetArrayAddr());
    NS_ENSURE_SUCCESS(rv, rv);

    // Calculate new RDN and check whether it has changed
    nsCAutoString newRDN;
    rv = card->BuildRdn(attrMap, rdnAttrs.GetSize(), rdnAttrs.GetArray(),
                        newRDN);
    NS_ENSURE_SUCCESS(rv, rv);

    if (newRDN.Equals(oldRDN))
    {
        // Launch query
        rv = DoModify(this, nsILDAPModification::MOD_REPLACE, oldDN, modArray,
                      EmptyCString(), EmptyCString());
    }
    else
    {
        // Build and store the new DN
        nsCAutoString newDN(newRDN);
        newDN.AppendLiteral(",");
        newDN.Append(baseDN);

        rv = card->SetDn(newDN);
        NS_ENSURE_SUCCESS(rv, rv);

        // Launch query
        rv = DoModify(this, nsILDAPModification::MOD_REPLACE, oldDN, modArray,
                      newRDN, baseDN);
    }
    return rv;
}
Beispiel #3
0
NS_IMETHODIMP nsAbLDAPDirectory::AddCard(nsIAbCard *aUpdatedCard,
        nsIAbCard **aAddedCard)
{
    NS_ENSURE_ARG_POINTER(aUpdatedCard);
    NS_ENSURE_ARG_POINTER(aAddedCard);

    nsCOMPtr<nsIAbLDAPAttributeMap> attrMap;
    nsresult rv = GetAttributeMap(getter_AddRefs(attrMap));
    NS_ENSURE_SUCCESS(rv, rv);

    // Create a new LDAP card
    nsCOMPtr<nsIAbLDAPCard> card =
        do_CreateInstance(NS_ABLDAPCARD_CONTRACTID, &rv);
    NS_ENSURE_SUCCESS(rv, rv);

    rv = Initiate();
    NS_ENSURE_SUCCESS(rv, rv);

    // Copy over the card data
    nsCOMPtr<nsIAbCard> copyToCard = do_QueryInterface(card, &rv);
    NS_ENSURE_SUCCESS(rv, rv);

    rv = copyToCard->Copy(aUpdatedCard);
    NS_ENSURE_SUCCESS(rv, rv);

    // Retrieve preferences
    nsCAutoString prefString;
    rv = GetRdnAttributes(prefString);
    NS_ENSURE_SUCCESS(rv, rv);

    CharPtrArrayGuard rdnAttrs;
    rv = SplitStringList(prefString, rdnAttrs.GetSizeAddr(),
                         rdnAttrs.GetArrayAddr());
    NS_ENSURE_SUCCESS(rv, rv);

    rv = GetObjectClasses(prefString);
    NS_ENSURE_SUCCESS(rv, rv);

    CharPtrArrayGuard objClass;
    rv = SplitStringList(prefString, objClass.GetSizeAddr(),
                         objClass.GetArrayAddr());
    NS_ENSURE_SUCCESS(rv, rv);

    // Process updates
    nsCOMPtr<nsIArray> modArray;
    rv = card->GetLDAPMessageInfo(attrMap, objClass.GetSize(), objClass.GetArray(),
                                  nsILDAPModification::MOD_ADD, getter_AddRefs(modArray));
    NS_ENSURE_SUCCESS(rv, rv);

    // For new cards, the base DN is the search base DN
    nsCOMPtr<nsILDAPURL> currentUrl;
    rv = GetLDAPURL(getter_AddRefs(currentUrl));
    NS_ENSURE_SUCCESS(rv, rv);

    nsCAutoString baseDN;
    rv = currentUrl->GetDn(baseDN);
    NS_ENSURE_SUCCESS(rv, rv);

    // Calculate DN
    nsCAutoString cardDN;
    rv = card->BuildRdn(attrMap, rdnAttrs.GetSize(), rdnAttrs.GetArray(),
                        cardDN);
    NS_ENSURE_SUCCESS(rv, rv);
    cardDN.AppendLiteral(",");
    cardDN.Append(baseDN);

    rv = card->SetDn(cardDN);
    NS_ENSURE_SUCCESS(rv, rv);

    // Launch query
    rv = DoModify(this, nsILDAPModification::MOD_ADD, cardDN, modArray,
                  EmptyCString(), EmptyCString());
    NS_ENSURE_SUCCESS(rv, rv);

    NS_ADDREF(*aAddedCard = copyToCard);
    return NS_OK;
}
Beispiel #4
0
NS_IMETHODIMP nsAbLDAPDirectory::StartSearch ()
{
    if (!mIsQueryURI || mQueryString.IsEmpty())
        return NS_OK;

    nsresult rv = Initiate();
    NS_ENSURE_SUCCESS(rv, rv);

    rv = StopSearch();
    NS_ENSURE_SUCCESS(rv, rv);

    nsCOMPtr<nsIAbDirectoryQueryArguments> arguments = do_CreateInstance(NS_ABDIRECTORYQUERYARGUMENTS_CONTRACTID,&rv);
    NS_ENSURE_SUCCESS(rv, rv);

    nsCOMPtr<nsIAbBooleanExpression> expression;
    rv = nsAbQueryStringToExpression::Convert(mQueryString.get(),
            getter_AddRefs(expression));
    NS_ENSURE_SUCCESS(rv, rv);

    rv = arguments->SetExpression(expression);
    NS_ENSURE_SUCCESS(rv, rv);

    rv = arguments->SetQuerySubDirectories(PR_TRUE);
    NS_ENSURE_SUCCESS(rv, rv);

    // Get the max hits to return
    PRInt32 maxHits;
    rv = GetMaxHits(&maxHits);
    if (NS_FAILED(rv))
        maxHits = kDefaultMaxHits;

    // get the appropriate ldap attribute map, and pass it in via the
    // TypeSpecificArgument
    nsCOMPtr<nsIAbLDAPAttributeMap> attrMap;
    rv = GetAttributeMap(getter_AddRefs(attrMap));
    NS_ENSURE_SUCCESS(rv, rv);

    nsCOMPtr<nsISupports> typeSpecificArg = do_QueryInterface(attrMap, &rv);
    NS_ENSURE_SUCCESS(rv, rv);

    rv = arguments->SetTypeSpecificArg(attrMap);
    NS_ENSURE_SUCCESS(rv, rv);

    if (!mDirectoryQuery)
    {
        mDirectoryQuery = do_CreateInstance(NS_ABLDAPDIRECTORYQUERY_CONTRACTID,
                                            &rv);
        NS_ENSURE_SUCCESS(rv, rv);
    }

    // Perform the query
    rv = mDirectoryQuery->DoQuery(this, arguments, this, maxHits, 0, &mContext);
    NS_ENSURE_SUCCESS(rv, rv);

    // Enter lock
    nsAutoLock lock(mLock);
    mPerformingQuery = PR_TRUE;
    mCache.Clear();

    return rv;
}