void AppendProperty(const ACE_TString& prop, const AudioConfig& audcfg, ACE_TString& dest_str) { intvec_t audcfg_prop; /* do not change the order since it will break compatibility * with older clients */ audcfg_prop.push_back(audcfg.enable_agc); audcfg_prop.push_back(audcfg.gain_level); AppendProperty(prop, audcfg_prop, dest_str); }
void AppendProperty(const ACE_TString& prop, const AudioCodec& codec, ACE_TString& dest_str) { intvec_t codec_prop; switch(codec.codec) { case CODEC_NO_CODEC : codec_prop.push_back(codec.codec); break; case CODEC_SPEEX : /* do not change the order since it will break compatibility * with older clients */ codec_prop.push_back(codec.codec); codec_prop.push_back(codec.speex.bandmode); codec_prop.push_back(codec.speex.quality); codec_prop.push_back(codec.speex.frames_per_packet); codec_prop.push_back(codec.speex.sim_stereo); break; case CODEC_SPEEX_VBR : /* do not change the order since it will break compatibility * with older clients */ codec_prop.push_back(codec.codec); codec_prop.push_back(codec.speex_vbr.bandmode); codec_prop.push_back(codec.speex_vbr.vbr_quality); codec_prop.push_back(codec.speex_vbr.bitrate); codec_prop.push_back(codec.speex_vbr.max_bitrate); codec_prop.push_back(codec.speex_vbr.dtx); codec_prop.push_back(codec.speex_vbr.frames_per_packet); codec_prop.push_back(codec.speex_vbr.sim_stereo); break; case CODEC_OPUS : codec_prop.push_back(codec.codec); codec_prop.push_back(codec.opus.samplerate); codec_prop.push_back(codec.opus.channels); codec_prop.push_back(codec.opus.application); codec_prop.push_back(codec.opus.complexity); codec_prop.push_back(codec.opus.fec); codec_prop.push_back(codec.opus.dtx); codec_prop.push_back(codec.opus.bitrate); codec_prop.push_back(codec.opus.vbr); codec_prop.push_back(codec.opus.vbr_constraint); codec_prop.push_back(codec.opus.frame_size); break; default : codec_prop.push_back(CODEC_NO_CODEC); TTASSERT(codec.codec != CODEC_NO_CODEC); } AppendProperty(prop, codec_prop, dest_str); }
QtPropertyItem* QtPropertyEditor::AddHeader(const char *text) { QPair<QtPropertyItem*, QtPropertyItem*> propHeader; propHeader = AppendProperty(text, NULL); QFont boldFont = propHeader.first->font(); boldFont.setBold(true); propHeader.first->setFont(boldFont); propHeader.first->setBackground(QBrush(QColor(Qt::lightGray))); propHeader.second->setBackground(QBrush(QColor(Qt::lightGray))); return propHeader.first; }
nsresult nsAbManager::AppendDNForCard(const char *aProperty, nsIAbCard *aCard, nsIAbLDAPAttributeMap *aAttrMap, nsACString &aResult) { nsString email; nsString displayName; nsCAutoString ldapAttributeName; nsresult rv = aCard->GetPrimaryEmail(email); NS_ENSURE_SUCCESS(rv,rv); rv = aCard->GetDisplayName(displayName); NS_ENSURE_SUCCESS(rv,rv); nsString cnStr; rv = aAttrMap->GetFirstAttribute(NS_LITERAL_CSTRING(kDisplayNameProperty), ldapAttributeName); NS_ENSURE_SUCCESS(rv, rv); if (!displayName.IsEmpty()) { cnStr += NS_ConvertUTF8toUTF16(ldapAttributeName).get(); cnStr.AppendLiteral("="); cnStr.Append(displayName); if (!email.IsEmpty()) { cnStr.AppendLiteral(","); } } rv = aAttrMap->GetFirstAttribute(NS_LITERAL_CSTRING(kPriEmailProperty), ldapAttributeName); NS_ENSURE_SUCCESS(rv, rv); if (!email.IsEmpty()) { cnStr += NS_ConvertUTF8toUTF16(ldapAttributeName).get(); cnStr.AppendLiteral("="); cnStr.Append(email); } rv = AppendProperty(aProperty, cnStr.get(), aResult); NS_ENSURE_SUCCESS(rv,rv); return rv; }
nsresult nsAbManager::AppendLDIFForMailList(nsIAbCard *aCard, nsIAbLDAPAttributeMap *aAttrMap, nsACString &aResult) { nsresult rv; nsString attrValue; rv = AppendDNForCard("dn", aCard, aAttrMap, aResult); NS_ENSURE_SUCCESS(rv,rv); aResult += MSG_LINEBREAK \ "objectclass: top" MSG_LINEBREAK \ "objectclass: groupOfNames" MSG_LINEBREAK; rv = aCard->GetDisplayName(attrValue); NS_ENSURE_SUCCESS(rv,rv); nsCAutoString ldapAttributeName; rv = aAttrMap->GetFirstAttribute(NS_LITERAL_CSTRING(kDisplayNameProperty), ldapAttributeName); NS_ENSURE_SUCCESS(rv, rv); rv = AppendProperty(ldapAttributeName.get(), attrValue.get(), aResult); NS_ENSURE_SUCCESS(rv,rv); aResult += MSG_LINEBREAK; rv = aAttrMap->GetFirstAttribute(NS_LITERAL_CSTRING(kNicknameProperty), ldapAttributeName); NS_ENSURE_SUCCESS(rv, rv); rv = aCard->GetPropertyAsAString(kNicknameProperty, attrValue); if (NS_SUCCEEDED(rv) && !attrValue.IsEmpty()) { rv = AppendProperty(ldapAttributeName.get(), attrValue.get(), aResult); NS_ENSURE_SUCCESS(rv,rv); aResult += MSG_LINEBREAK; } rv = aAttrMap->GetFirstAttribute(NS_LITERAL_CSTRING(kNotesProperty), ldapAttributeName); NS_ENSURE_SUCCESS(rv, rv); rv = aCard->GetPropertyAsAString(kNotesProperty, attrValue); if (NS_SUCCEEDED(rv) && !attrValue.IsEmpty()) { rv = AppendProperty(ldapAttributeName.get(), attrValue.get(), aResult); NS_ENSURE_SUCCESS(rv,rv); aResult += MSG_LINEBREAK; } nsCString mailListURI; rv = aCard->GetMailListURI(getter_Copies(mailListURI)); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr <nsIAbDirectory> mailList; rv = GetDirectory(mailListURI, getter_AddRefs(mailList)); NS_ENSURE_SUCCESS(rv,rv); nsCOMPtr<nsIMutableArray> addresses; rv = mailList->GetAddressLists(getter_AddRefs(addresses)); if (addresses) { PRUint32 total = 0; addresses->GetLength(&total); if (total) { PRUint32 i; for (i = 0; i < total; i++) { nsCOMPtr <nsIAbCard> listCard = do_QueryElementAt(addresses, i, &rv); NS_ENSURE_SUCCESS(rv,rv); rv = AppendDNForCard("member", listCard, aAttrMap, aResult); NS_ENSURE_SUCCESS(rv,rv); aResult += MSG_LINEBREAK; } } } aResult += MSG_LINEBREAK; return NS_OK; }
nsresult nsAbManager::ExportDirectoryToLDIF(nsIAbDirectory *aDirectory, nsILocalFile *aLocalFile) { nsCOMPtr <nsISimpleEnumerator> cardsEnumerator; nsCOMPtr <nsIAbCard> card; nsresult rv; nsCOMPtr <nsIOutputStream> outputStream; rv = MsgNewBufferedFileOutputStream(getter_AddRefs(outputStream), aLocalFile, PR_CREATE_FILE | PR_WRONLY | PR_TRUNCATE, 0664); // the desired file may be read only if (NS_FAILED(rv)) return rv; // Get the default attribute map for ldap. We use the default attribute // map rather than one for a specific server because if people want an // ldif export using a servers specific schema, then they can use ldapsearch nsCOMPtr<nsIAbLDAPAttributeMapService> mapSrv = do_GetService("@mozilla.org/addressbook/ldap-attribute-map-service;1", &rv); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIAbLDAPAttributeMap> attrMap; rv = mapSrv->GetMapForPrefBranch(NS_LITERAL_CSTRING("ldap_2.servers.default.attrmap"), getter_AddRefs(attrMap)); NS_ENSURE_SUCCESS(rv, rv); PRUint32 i; PRUint32 writeCount; PRUint32 length; rv = aDirectory->GetChildCards(getter_AddRefs(cardsEnumerator)); if (NS_SUCCEEDED(rv) && cardsEnumerator) { nsCOMPtr<nsISupports> item; bool more; while (NS_SUCCEEDED(cardsEnumerator->HasMoreElements(&more)) && more) { rv = cardsEnumerator->GetNext(getter_AddRefs(item)); if (NS_SUCCEEDED(rv)) { nsCOMPtr <nsIAbCard> card = do_QueryInterface(item, &rv); NS_ENSURE_SUCCESS(rv,rv); bool isMailList; rv = card->GetIsMailList(&isMailList); NS_ENSURE_SUCCESS(rv,rv); if (isMailList) { nsCString mailListCStr; rv = AppendLDIFForMailList(card, attrMap, mailListCStr); NS_ENSURE_SUCCESS(rv,rv); length = mailListCStr.Length(); rv = outputStream->Write(mailListCStr.get(), length, &writeCount); NS_ENSURE_SUCCESS(rv,rv); if (length != writeCount) return NS_ERROR_FAILURE; } else { nsString value; nsCString valueCStr; rv = AppendBasicLDIFForCard(card, attrMap, valueCStr); NS_ENSURE_SUCCESS(rv,rv); length = valueCStr.Length(); rv = outputStream->Write(valueCStr.get(), length, &writeCount); NS_ENSURE_SUCCESS(rv,rv); if (length != writeCount) return NS_ERROR_FAILURE; valueCStr.Truncate(); nsCAutoString ldapAttribute; for (i = 0; i < NS_ARRAY_LENGTH(EXPORT_ATTRIBUTES_TABLE); i++) { if (NS_SUCCEEDED(attrMap->GetFirstAttribute(nsDependentCString(EXPORT_ATTRIBUTES_TABLE[i].abPropertyName), ldapAttribute)) && !ldapAttribute.IsEmpty()) { rv = card->GetPropertyAsAString(EXPORT_ATTRIBUTES_TABLE[i].abPropertyName, value); if (NS_FAILED(rv)) value.Truncate(); if (!PL_strcmp(EXPORT_ATTRIBUTES_TABLE[i].abPropertyName, kPreferMailFormatProperty)) { if (value.EqualsLiteral("html")) value.AssignLiteral("true"); else if (value.EqualsLiteral("plaintext")) value.AssignLiteral("false"); else value.Truncate(); // unknown. } if (!value.IsEmpty()) { rv = AppendProperty(ldapAttribute.get(), value.get(), valueCStr); NS_ENSURE_SUCCESS(rv,rv); valueCStr += MSG_LINEBREAK; } else valueCStr.Truncate(); length = valueCStr.Length(); if (length) { rv = outputStream->Write(valueCStr.get(), length, &writeCount); NS_ENSURE_SUCCESS(rv,rv); if (length != writeCount) return NS_ERROR_FAILURE; } valueCStr.Truncate(); } else { // something we don't support yet // ldif doesn't export multiple addresses } } // write out the linebreak that separates the cards rv = outputStream->Write(MSG_LINEBREAK, MSG_LINEBREAK_LEN, &writeCount); NS_ENSURE_SUCCESS(rv,rv); if (MSG_LINEBREAK_LEN != writeCount) return NS_ERROR_FAILURE; } } } } rv = outputStream->Flush(); NS_ENSURE_SUCCESS(rv,rv); rv = outputStream->Close(); NS_ENSURE_SUCCESS(rv,rv); return NS_OK; }
nsresult leakmonJSObjectInfo::Init(leakmonObjectsInReportTable &aObjectsInReport) { mIsInitialized = PR_TRUE; JSContext *cx = leakmonService::GetJSContext(); NS_ENSURE_TRUE(cx, NS_ERROR_UNEXPECTED); JSAutoRequest ar(cx); if (!JSVAL_IS_PRIMITIVE(mJSValue)) { JSObject *obj = JSVAL_TO_OBJECT(mJSValue); // All of the objects in obj's prototype chain, and all // objects reachable from JS_NewPropertyIterator should // (I think?) be in the same compartment. JSAutoEnterCompartment ac; if (!ac.enter(cx, obj)) { return NS_ERROR_FAILURE; } JSObject *p; for (p = obj; p; p = JS_GetPrototype(cx, p)) { // Stack-scanning protects newly-created objects // (etor) from GC. (And protecting |etor| // should in turn protect |id|.) // JS_NewPropertyIterator has the nice property that it // avoids JS_Enumerate on native objects (where it can // execute code) and uses the scope properties, but doesn't // require this code to use the unstable OBJ_IS_NATIVE API. JSObject *etor = JS_NewPropertyIterator(cx, p); if (!etor) return NS_ERROR_OUT_OF_MEMORY; jsid id; while (JS_NextProperty(cx, etor, &id) && !JSID_IS_VOID(id)) { nsresult rv = AppendProperty(id, cx, aObjectsInReport); NS_ENSURE_SUCCESS(rv, rv); } } if (JS_ObjectIsFunction(cx, obj)) { JSFunction *fun = JS_ValueToFunction(cx, mJSValue); NS_ENSURE_TRUE(fun, NS_ERROR_UNEXPECTED); JSScript *script = JS_GetFunctionScript(cx, fun); if (script) { // null for native code const char *fname = JS_GetScriptFilename(cx, script); // XXX Do we know the encoding of this file name? mFileName = NS_ConvertUTF8toUTF16(fname); mLineStart = JS_GetScriptBaseLineNumber(cx, script); mLineEnd = mLineStart + JS_GetScriptLineExtent(cx, script) - 1; } } } ValueToString(cx, mJSValue, mString); return NS_OK; }
void AppendProperty(const ACE_TString& prop, const ACE_INET_Addr& addr, ACE_TString& dest_str) { AppendProperty(prop, InetAddrToString(addr), dest_str); }