nsresult nsStreamConverterService::BuildGraph() { nsresult rv; nsCOMPtr<nsICategoryManager> catmgr(do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv)); if (NS_FAILED(rv)) return rv; nsCOMPtr<nsISimpleEnumerator> entries; rv = catmgr->EnumerateCategory(NS_ISTREAMCONVERTER_KEY, getter_AddRefs(entries)); if (NS_FAILED(rv)) return rv; // go through each entry to build the graph nsCOMPtr<nsISupportsCString> entry; rv = entries->GetNext(getter_AddRefs(entry)); while (NS_SUCCEEDED(rv)) { // get the entry string nsAutoCString entryString; rv = entry->GetData(entryString); if (NS_FAILED(rv)) return rv; // cobble the entry string w/ the converter key to produce a full contractID. nsAutoCString contractID(NS_ISTREAMCONVERTER_KEY); contractID.Append(entryString); // now we've got the CONTRACTID, let's parse it up. rv = AddAdjacency(contractID.get()); if (NS_FAILED(rv)) return rv; rv = entries->GetNext(getter_AddRefs(entry)); } return NS_OK; }
void Contract::GetItemRow( InventoryItemRef item, PyPackedRow* into ) const { into->SetField( "contractID", new PyInt( contractID() ) ); into->SetField( "itemID", new PyInt( item->itemID() ) ); into->SetField( "quantity", new PyInt( item->quantity() ) ); into->SetField( "itemTypeID", new PyInt( item->typeID() ) ); into->SetField( "inCrate", new PyBool( true ) ); if( item->categoryID() == EVEDB::invCategories::Blueprint ) { BlueprintRef bp = m_itemFactory.GetBlueprint( item->itemID() ); into->SetField( "parentID", new PyInt( bp->parentBlueprintTypeID() ) ); into->SetField( "productivityLevel", new PyInt( bp->productivityLevel() ) ); into->SetField( "materialLevel", new PyInt( bp->materialLevel() ) ); into->SetField( "copy", new PyInt( bp->copy() ) ); into->SetField( "licensedProductionRunsRemaining", new PyInt( bp->licensedProductionRunsRemaining() ) ); } else { into->SetField( "parentID", new PyInt( 0 ) ); into->SetField( "productivityLevel", new PyInt( 0 ) ); into->SetField( "materialLevel", new PyInt( 0 ) ); into->SetField( "copy", new PyInt( 0 ) ); into->SetField( "licensedProductionRunsRemaining", new PyInt( 0 ) ); } if( item->HasAttribute( AttrDamage ) ) into->SetField( "damage", new PyInt( item->GetAttribute( AttrDamage ).get_int() ) ); else into->SetField( "damage", new PyInt( 0 ) ); into->SetField( "flagID", new PyInt( item->flag() ) ); }
void Contract::GetContractRow( PyPackedRow* into ) { into->SetField( "contractID", new PyInt( contractID() ) ); into->SetField( "issuerID", new PyInt( issuerID() ) ); into->SetField( "issuerCorpID", new PyInt( issuerCorpID() ) ); into->SetField( "type", new PyInt( type() ) ); into->SetField( "availability", new PyInt( avail() ) ); into->SetField( "assigneeID", new PyInt( assigneeID() ) ); into->SetField( "numDays", new PyInt( 0 ) ); into->SetField( "startStationID", new PyInt( startStationID() ) ); into->SetField( "endStationID", new PyInt( endStationID() ) ); into->SetField( "startSolarSystemID", new PyInt( startSolarSystemID() ) ); into->SetField( "endSolarSystemID", new PyInt( endSolarSystemID() ) ); into->SetField( "startRegionID", new PyInt( startRegionID() ) ); into->SetField( "endRegionID", new PyInt( endRegionID() ) ); into->SetField( "price", new PyFloat( price() ) ); into->SetField( "reward", new PyFloat( reward() ) ); into->SetField( "collateral", new PyFloat( collateral() ) ); into->SetField( "title", new PyWString( title().c_str(), title().length() ) ); into->SetField( "description", new PyWString( description().c_str(), description().length() ) ); into->SetField( "forCorp", new PyBool( forCorp() ) ); into->SetField( "status", new PyInt( status() ) ); into->SetField( "acceptorID", new PyInt( acceptorID() ) ); into->SetField( "dateIssued", new PyLong( dateIssued() ) ); into->SetField( "dateExpired", new PyLong( dateExpired() ) ); into->SetField( "dateAccepted", new PyLong( dateAccepted() ) ); into->SetField( "dateCompleted", new PyLong( dateCompleted() ) ); into->SetField( "volume", new PyFloat( volume() ) ); into->SetField( "issuerAllianceID", new PyInt( issuerAllianceID() ) ); into->SetField( "issuerWalletKey", new PyInt( issuerWalletKey() ) ); into->SetField( "acceptorWalletKey", new PyInt( 0 ) ); into->SetField( "crateID", new PyInt( 0 ) ); }
NS_IMETHODIMP nsRDFResource::GetDelegate(const char* aKey, REFNSIID aIID, void** aResult) { NS_PRECONDITION(aKey != nullptr, "null ptr"); if (! aKey) return NS_ERROR_NULL_POINTER; nsresult rv; *aResult = nullptr; DelegateEntry* entry = mDelegates; while (entry) { if (entry->mKey.Equals(aKey)) { rv = entry->mDelegate->QueryInterface(aIID, aResult); return rv; } entry = entry->mNext; } // Construct a ContractID of the form "@mozilla.org/rdf/delegate/[key]/[scheme];1 nsAutoCString contractID(NS_RDF_DELEGATEFACTORY_CONTRACTID_PREFIX); contractID.Append(aKey); contractID.AppendLiteral("&scheme="); int32_t i = mURI.FindChar(':'); contractID += StringHead(mURI, i); nsCOMPtr<nsIRDFDelegateFactory> delegateFactory = do_CreateInstance(contractID.get(), &rv); if (NS_FAILED(rv)) return rv; rv = delegateFactory->CreateDelegate(this, aKey, aIID, aResult); if (NS_FAILED(rv)) return rv; // Okay, we've successfully created a delegate. Let's remember it. entry = new DelegateEntry; if (! entry) { NS_RELEASE(*reinterpret_cast<nsISupports**>(aResult)); return NS_ERROR_OUT_OF_MEMORY; } entry->mKey = aKey; entry->mDelegate = do_QueryInterface(*reinterpret_cast<nsISupports**>(aResult), &rv); if (NS_FAILED(rv)) { NS_ERROR("nsRDFResource::GetDelegate(): can't QI to nsISupports!"); delete entry; NS_RELEASE(*reinterpret_cast<nsISupports**>(aResult)); return NS_ERROR_FAILURE; } entry->mNext = mDelegates; mDelegates = entry; return NS_OK; }
NS_IMETHODIMP nsProfileMigrator::Migrate(nsIProfileStartup* aStartup) { nsresult rv; nsCAutoString key; nsCOMPtr<nsIBrowserProfileMigrator> bpm; rv = GetDefaultBrowserMigratorKey(key, bpm); if (NS_FAILED(rv)) return rv; if (!bpm) { nsCAutoString contractID(NS_BROWSERPROFILEMIGRATOR_CONTRACTID_PREFIX); contractID.Append(key); bpm = do_CreateInstance(contractID.get()); if (!bpm) return NS_ERROR_FAILURE; } PRBool sourceExists; bpm->GetSourceExists(&sourceExists); if (!sourceExists) { #ifdef XP_WIN // The "Default Browser" key in the registry was set to a browser for which // no profile data exists. On Windows, this means the Default Browser settings // in the registry are bad, and we should just fall back to IE in this case. bpm = do_CreateInstance(NS_BROWSERPROFILEMIGRATOR_CONTRACTID_PREFIX "ie"); #else return NS_ERROR_FAILURE; #endif } nsCOMPtr<nsISupportsCString> cstr (do_CreateInstance("@mozilla.org/supports-cstring;1")); if (!cstr) return NS_ERROR_OUT_OF_MEMORY; cstr->SetData(key); // By opening the Migration FE with a supplied bpm, it will automatically // migrate from it. nsCOMPtr<nsIWindowWatcher> ww(do_GetService(NS_WINDOWWATCHER_CONTRACTID)); nsCOMPtr<nsISupportsArray> params = do_CreateInstance(NS_SUPPORTSARRAY_CONTRACTID); if (!ww || !params) return NS_ERROR_FAILURE; params->AppendElement(cstr); params->AppendElement(bpm); params->AppendElement(aStartup); nsCOMPtr<nsIDOMWindow> migrateWizard; return ww->OpenWindow(nsnull, MIGRATION_WIZARD_FE_URL, "_blank", MIGRATION_WIZARD_FE_FEATURES, params, getter_AddRefs(migrateWizard)); }
void Contract::Delete() { // Return the items to the hangar std::map<uint32, ContractGetItemsRef>::iterator cur, end; cur = items().begin(); end = items().end(); for(; cur != end; cur++) { InventoryItemRef item = m_itemFactory.GetItem( cur->second->m_itemID ); item->Move( startStationID(), flagHangar, true ); item->ChangeOwner( issuerID(), true ); } // take ourself out of the DB m_factory.db().DeleteContract( contractID() ); // Delete ourselves from factory cache m_factory.DeleteContract( contractID() ); }
NS_IMETHODIMP nsSocketProviderService::GetSocketProvider(const char *type, nsISocketProvider **result) { nsresult rv; nsCAutoString contractID( NS_LITERAL_CSTRING(NS_NETWORK_SOCKET_CONTRACTID_PREFIX) + nsDependentCString(type)); rv = CallGetService(contractID.get(), result); if (NS_FAILED(rv)) rv = NS_ERROR_UNKNOWN_SOCKET_TYPE; return rv; }
void Contract::GetRequestItemRow( ContractRequestItemRef item, PyPackedRow* into ) const { into->SetField( "contractID", new PyInt( contractID() ) ); into->SetField( "itemID", new PyInt( 0 ) ); into->SetField( "quantity", new PyInt( item->m_quantity ) ); into->SetField( "itemTypeID", new PyInt( item->m_typeID ) ); into->SetField( "inCrate", new PyBool( false ) ); into->SetField( "parentID", new PyInt( 0 ) ); into->SetField( "productivityLevel", new PyInt( 0 ) ); into->SetField( "materialLevel", new PyInt( 0 ) ); into->SetField( "copy", new PyInt( 0 ) ); into->SetField( "licensedProductionRunsRemaining", new PyInt( 0 ) ); into->SetField( "damage", new PyInt( 0 ) ); into->SetField( "flagID", new PyInt( 0 ) ); }
int main(int argc, char* argv[]) { nsresult rv; { nsCOMPtr<nsIServiceManager> servMan; NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(servMan); NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); if (registrar) registrar->AutoRegister(nsnull); nsCOMPtr<nsIThread> thread = do_GetCurrentThread(); nsCOMPtr<nsICategoryManager> catman = do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv); if (NS_FAILED(rv)) return rv; nsCString previous; /////////////////////////////////////////// // BEGIN - Stream converter registration // All stream converters must register with the ComponentManager /////////////////////////////////////////// // these stream converters are just for testing. running this harness // from the dist/bin dir will also pickup converters registered // in other modules (necko converters for example). PRUint32 converterListSize = 7; const char *const converterList[] = { "?from=a/foo&to=b/foo", "?from=b/foo&to=c/foo", "?from=b/foo&to=d/foo", "?from=c/foo&to=d/foo", "?from=d/foo&to=e/foo", "?from=d/foo&to=f/foo", "?from=t/foo&to=k/foo", }; TestConverterFactory *convFactory = new TestConverterFactory(kTestConverterCID, "TestConverter", NS_ISTREAMCONVERTER_KEY); nsCOMPtr<nsIFactory> convFactSup(do_QueryInterface(convFactory, &rv)); if (NS_FAILED(rv)) return rv; for (PRUint32 count = 0; count < converterListSize; ++count) { // register the TestConverter with the component manager. One contractid registration // per conversion pair (from - to pair). nsCString contractID(NS_ISTREAMCONVERTER_KEY); contractID.Append(converterList[count]); rv = registrar->RegisterFactory(kTestConverterCID, "TestConverter", contractID.get(), convFactSup); if (NS_FAILED(rv)) return rv; rv = catman->AddCategoryEntry(NS_ISTREAMCONVERTER_KEY, converterList[count], "x", PR_TRUE, PR_TRUE, getter_Copies(previous)); if (NS_FAILED(rv)) return rv; } nsCOMPtr<nsIStreamConverterService> StreamConvService = do_GetService(kStreamConverterServiceCID, &rv); if (NS_FAILED(rv)) return rv; // Define the *from* content type and *to* content-type for conversion. static const char fromStr[] = "a/foo"; static const char toStr[] = "c/foo"; #ifdef ASYNC_TEST // ASYNCHRONOUS conversion // Build up a channel that represents the content we're // starting the transaction with. // // sample multipart mixed content-type string: // "multipart/x-mixed-replacE;boundary=thisrandomstring" #if 0 nsCOMPtr<nsIChannel> channel; nsCOMPtr<nsIURI> dummyURI; rv = NS_NewURI(getter_AddRefs(dummyURI), "http://meaningless"); if (NS_FAILED(rv)) return rv; rv = NS_NewInputStreamChannel(getter_AddRefs(channel), dummyURI, nsnull, // inStr "text/plain", // content-type -1); // XXX fix contentLength if (NS_FAILED(rv)) return rv; nsCOMPtr<nsIRequest> request(do_QueryInterface(channel)); #endif nsCOMPtr<nsIRequest> request; // setup a listener to receive the converted data. This guy is the end // listener in the chain, he wants the fully converted (toType) data. // An example of this listener in mozilla would be the DocLoader. nsIStreamListener *dataReceiver = new EndListener(); NS_ADDREF(dataReceiver); // setup a listener to push the data into. This listener sits inbetween the // unconverted data of fromType, and the final listener in the chain (in this case // the dataReceiver. nsIStreamListener *converterListener = nsnull; rv = StreamConvService->AsyncConvertData(fromStr, toStr, dataReceiver, nsnull, &converterListener); if (NS_FAILED(rv)) return rv; NS_RELEASE(dataReceiver); // at this point we have a stream listener to push data to, and the one // that will receive the converted data. Let's mimic On*() calls and get the conversion // going. Typically these On*() calls would be made inside their respective wrappers On*() // methods. rv = converterListener->OnStartRequest(request, nsnull); if (NS_FAILED(rv)) return rv; rv = SEND_DATA("aaa"); if (NS_FAILED(rv)) return rv; rv = SEND_DATA("aaa"); if (NS_FAILED(rv)) return rv; // Finish the request. rv = converterListener->OnStopRequest(request, nsnull, rv); if (NS_FAILED(rv)) return rv; NS_RELEASE(converterListener); #else // SYNCHRONOUS conversion nsCOMPtr<nsIInputStream> convertedData; rv = StreamConvService->Convert(inputData, fromStr, toStr, nsnull, getter_AddRefs(convertedData)); if (NS_FAILED(rv)) return rv; #endif // Enter the message pump to allow the URL load to proceed. while ( gKeepRunning ) { if (!NS_ProcessNextEvent(thread)) break; } } // this scopes the nsCOMPtrs // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM NS_ShutdownXPCOM(nsnull); return rv; }
NS_IMETHODIMP nsIOService::GetProtocolHandler(const char* scheme, nsIProtocolHandler* *result) { nsresult rv; NS_ENSURE_ARG_POINTER(scheme); // XXX we may want to speed this up by introducing our own protocol // scheme -> protocol handler mapping, avoiding the string manipulation // and service manager stuff rv = GetCachedProtocolHandler(scheme, result); if (NS_SUCCEEDED(rv)) return rv; bool externalProtocol = false; nsCOMPtr<nsIPrefBranch> prefBranch; GetPrefBranch(getter_AddRefs(prefBranch)); if (prefBranch) { nsAutoCString externalProtocolPref("network.protocol-handler.external."); externalProtocolPref += scheme; rv = prefBranch->GetBoolPref(externalProtocolPref.get(), &externalProtocol); if (NS_FAILED(rv)) { externalProtocol = false; } } if (!externalProtocol) { nsAutoCString contractID(NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX); contractID += scheme; ToLowerCase(contractID); rv = CallGetService(contractID.get(), result); if (NS_SUCCEEDED(rv)) { CacheProtocolHandler(scheme, *result); return rv; } #ifdef MOZ_X11 // check to see whether GVFS can handle this URI scheme. if it can // create a nsIURI for the "scheme:", then we assume it has support for // the requested protocol. otherwise, we failover to using the default // protocol handler. rv = CallGetService(NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX"moz-gio", result); if (NS_SUCCEEDED(rv)) { nsAutoCString spec(scheme); spec.Append(':'); nsIURI *uri; rv = (*result)->NewURI(spec, nullptr, nullptr, &uri); if (NS_SUCCEEDED(rv)) { NS_RELEASE(uri); return rv; } NS_RELEASE(*result); } // check to see whether GnomeVFS can handle this URI scheme. if it can // create a nsIURI for the "scheme:", then we assume it has support for // the requested protocol. otherwise, we failover to using the default // protocol handler. // XXX should this be generalized into something that searches a // category? (see bug 234714) rv = CallGetService(NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX"moz-gnomevfs", result); if (NS_SUCCEEDED(rv)) { nsAutoCString spec(scheme); spec.Append(':'); nsIURI *uri; rv = (*result)->NewURI(spec, nullptr, nullptr, &uri); if (NS_SUCCEEDED(rv)) { NS_RELEASE(uri); return rv; } NS_RELEASE(*result); } #endif } // Okay we don't have a protocol handler to handle this url type, so use // the default protocol handler. This will cause urls to get dispatched // out to the OS ('cause we can't do anything with them) when we try to // read from a channel created by the default protocol handler. rv = CallGetService(NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX"default", result); if (NS_FAILED(rv)) return NS_ERROR_UNKNOWN_PROTOCOL; return rv; }