Boolean URLUtil::IsFileUrl( /* [in] */ const String& url) { return (!url.IsNull()) && (url.StartWith(FILE_BASE) && !url.StartWith(ASSET_BASE) && !url.StartWith(PROXY_BASE)); }
String URLUtil::GuessUrl( /* [in] */ const String& _inUrl) { String inUrl = _inUrl; AutoPtr<IWebAddress> webAddress; // if (DebugFlags.URL_UTIL) Log.v(LOGTAG, "guessURL before queueRequest: " + inUrl); if (inUrl.IsEmpty()) { return inUrl; } if (inUrl.StartWith("about:")) { return inUrl; } // Do not try to interpret data scheme URLs if (inUrl.StartWith("data:")) { return inUrl; } // Do not try to interpret file scheme URLs if (inUrl.StartWith("file:")) { return inUrl; } // Do not try to interpret javascript scheme URLs if (inUrl.StartWith("javascript:")) { return inUrl; } // bug 762454: strip period off end of url if (inUrl.EndWith(".") == TRUE) { inUrl = inUrl.Substring(0, inUrl.GetLength() - 1); } assert(0); //try { // webAddress = new WebAddress(inUrl); //} catch (ParseException ex) { // if (DebugFlags.URL_UTIL) { // Log.v(LOGTAG, "smartUrlFilter: failed to parse url = " + inUrl); // } // return retVal; //} // Check host // if (webAddress->GetHost().IndexOf('.') == -1) { // StringBuilder sb; // sb.Append("www."); // sb.Append(webAddress->GetHost()); // sb.Append(".com"); // no dot: user probably entered a bare domain. try .com // webAddress->SetHost(sb.ToString()); // } // return webAddress->ToString(); return String(NULL); }
ECode Provider::Remove( /* [in] */ IInterface* key, /* [out] */ IInterface** value) { VALIDATE_NOT_NULL(value); AutoLock lock(this); if (IString::Probe(key)) { String str; ICharSequence::Probe(key)->ToString(&str); if (str.StartWith("Provider.")) { // Provider service type is reserved return NOERROR; } } if (mProviderNumber != -1) { // if registered then refresh Services AutoPtr<IServices> services; CServices::AcquireSingleton((IServices**)&services); services->SetNeedRefresh(); } AutoPtr<IInterface> obj; if (mChangedProperties != NULL && (mChangedProperties->Remove(key, (IInterface**)&obj), obj == NULL)) { RemoveFromPropertyServiceTable(key); Int32 size; if (mChangedProperties->GetSize(&size), size == 0) { mChangedProperties = NULL; } } return Properties::Remove(key, value); }
/** * Return the next command line option. This has a number of special cases * which closely, but not exactly, follow the POSIX command line options * patterns: * * <pre> * -- means to stop processing additional options * -z means option z * -z ARGS means option z with (non-optional) arguments ARGS * -zARGS means option z with (optional) arguments ARGS * --zz means option zz * --zz ARGS means option zz with (non-optional) arguments ARGS * </pre> * * Note that you cannot combine single letter options; -abc != -a -b -c * * @return Returns the option string, or null if there are no more options. */ String Monkey::NextOption() { if (mNextArg >= mArgs->GetLength()) { return String(); } String arg = (*mArgs)[mNextArg]; if (!arg.StartWith("-")) { return String(); } mNextArg++; if (arg.Equals("--")) { return String(); } if (arg.GetLength() > 1 && arg.GetChar(1) != '-') { if (arg.GetLength() > 2) { mCurArgData = arg.Substring(2); return arg.Substring(0, 2); } else { mCurArgData = String(); return arg; } } mCurArgData = String(); return arg; }
ECode Provider::Put( /* [in] */ IInterface* key, /* [in] */ IInterface* value, /* [out] */ IInterface** oldValue) { VALIDATE_NOT_NULL(oldValue); *oldValue = NULL; if (IString::Probe(key)) { String str; ICharSequence::Probe(key)->ToString(&str); if (str.StartWith("Provider.")) { // Provider service type is reserved return NOERROR; } } if (mProviderNumber != -1) { // if registered then refresh Services AutoPtr<IServices> services; CServices::AcquireSingleton((IServices**)&services); services->SetNeedRefresh(); } AutoPtr<IInterface> obj; if (mChangedProperties != NULL && (mChangedProperties->Remove(key, (IInterface**)&obj), obj == NULL)) { RemoveFromPropertyServiceTable(key); } if (mChangedProperties == NULL) { CLinkedHashMap::New((ILinkedHashMap**)&mChangedProperties); } mChangedProperties->Put(key, value); return Properties::Put(key, value, oldValue); }
void CProxyProperties::SetExclusionList( /* [in] */ const String& exclusionList) { mExclusionList = exclusionList.ToLowerCase(); if (exclusionList.IsNull()) { mParsedExclusionList = ArrayOf<String>::Alloc(0); } else { AutoPtr <ArrayOf<String> >splitExclusionList; StringUtils::Split(mExclusionList, String(","), (ArrayOf<String>**)&splitExclusionList); Int32 length; length = splitExclusionList->GetLength(); mParsedExclusionList = ArrayOf<String>::Alloc(length* 2); for (int i = 0; i < length; i++) { String str; str = (*splitExclusionList)[i]; String s = str.Trim(); if (s.StartWith(".")) { s = s.Substring(1); } String temp = String(".") + s; mParsedExclusionList->Set(i*2, s); mParsedExclusionList->Set((i*2)+1, temp); } } }
ECode CJDBCConnection::constructor( /* [in] */ const String& url, /* [in] */ const String& enc, /* [in] */ const String& pwd, /* [in] */ const String& drep, /* [in] */ const String& vfs) { ECode ec = NOERROR; if (url.StartWith("sqlite:/")) { mDbfile = url.Substring(0, 8); } else if (url.StartWith("jdbc:sqlite:/")) { mDbfile = url.Substring(0, 13); } else { return E_SQL_EXCEPTION; } this->mUrl = url; this->mEnc = enc; this->mVfs = vfs; ec = Open(mReadonly, (IDatabase**)&mDb); if (FAILED(ec)) { return E_SQL_EXCEPTION; } if (!pwd.IsNullOrEmpty()) { ec = mDb->Key(pwd); if (FAILED(ec)) { return E_SQL_EXCEPTION; } } IBusyHandler* hd = IBusyHandler::Probe(this); ec = mDb->BusyHandler(hd); //ec = mDb->BusyHandler(this); if (FAILED(ec)) { if (mDb != NULL) { mDb->Close(); } } if (!drep.IsNull() && (drep.StartWith("j") || drep.StartWith("J"))) { mUseJulian = TRUE; } return NOERROR; }
bool isLoadBase(const String& path) { for(int i=0;i<loadBases.Count();i++) { if(path.StartWith(loadBases[i]))return true; } return false; }
//----------------------------------------------------------------------------- // TemplateFileParsor::ReadHeader //----------------------------------------------------------------------------- void TemplateFileParsor::ReadHeader(const string &strTemplateName, String *pstrParams) { // Build template lines list ifstream fs(PSZ(strTemplateName)); int iLine = 0; while( !fs.eof() ) { iLine++; fs.getline(g_acScratchBuf, g_iScratchLen); String strLine = g_acScratchBuf; strLine.Trim(); if( !strLine.StartWith("#") ) // End of header reached return; // Header parsing // Search for lines begining with "# @param..." strLine.erase(0, 1); strLine.Trim(); if( strLine.StartWith("@param") ) { strLine.erase(0, strlen("@param")); strLine.Trim(); // Get name String strName; strLine.ExtractToken(' ', &strName); strName.Trim(); strLine.Trim(); // Pass type; String strTmp; strLine.ExtractToken(' ', &strTmp); strLine.Trim(); // Pass description strLine.ExtractToken('\'', '\'', &strTmp); strLine.Trim(); *pstrParams += strName + string("=") + strLine + string(","); } } }
ECode CSoundPool::Load( /* [in] */ const String& path, /* [in] */ Int32 priority, /* [out] */ Int32* result) { VALIDATE_NOT_NULL(result); *result = 0; if (DEBUG) Logger::D(TAG, "Load priority %d, %s", priority, path.string()); // pass network streams to player if (path.StartWith("http:")) { return NativeLoad(path, priority, result); } // try local path ECode ec = NOERROR; Boolean fileExists; AutoPtr<IParcelFileDescriptor> fd; AutoPtr<IFileDescriptor> fileDescriptor; Int64 tempValue; AutoPtr<IParcelFileDescriptorHelper> parcelFileDescriptorHelper; CParcelFileDescriptorHelper::AcquireSingleton((IParcelFileDescriptorHelper**)&parcelFileDescriptorHelper); AutoPtr<IFile> f; ec = CFile::New(path, (IFile**)&f); FAIL_GOTO(ec, _EXIT_); f->Exists(&fileExists); if (!fileExists) { Logger::E(TAG, "error loading %s, file does not exists."); return E_ILLEGAL_ARGUMENT_EXCEPTION; } ec = parcelFileDescriptorHelper->Open(f, IParcelFileDescriptor::MODE_READ_ONLY, (IParcelFileDescriptor**)&fd); FAIL_GOTO(ec, _EXIT_); if (fd != NULL) { ec = fd->GetFileDescriptor((IFileDescriptor**)&fileDescriptor); FAIL_GOTO(ec, _EXIT_); f->GetLength(&tempValue); ec =NativeLoad(fileDescriptor, 0, tempValue, priority, result); } _EXIT_: if (fd) { fd->Close(); fd = NULL; } if (FAILED(ec)) { Logger::E(TAG, "error loading %s", path.string()); } return ec; }
ECode CQName::ValueOf( /* [in] */ String qNameAsString, /* [out] */ IQName** qName) { // null is not valid if (qNameAsString == NULL) { // throw new IllegalArgumentException("cannot create QName from \"null\" or \"\" String"); return E_ILLEGAL_ARGUMENT_EXCEPTION; } // "" local part is valid to preserve compatible behavior with QName 1.0 if (qNameAsString.GetLength() == 0) { return CQName::New( IXMLConstants::NULL_NS_URI, qNameAsString, IXMLConstants::DEFAULT_NS_PREFIX, qName); } // local part only? if (qNameAsString.GetChar(0) != '{') { return CQName::New( IXMLConstants::NULL_NS_URI, qNameAsString, IXMLConstants::DEFAULT_NS_PREFIX, qName); } // Namespace URI improperly specified? if (qNameAsString.StartWith(String("{") + IXMLConstants::NULL_NS_URI + "}")) { // throw new IllegalArgumentException( // "Namespace URI .equals(XMLConstants.NULL_NS_URI), " // + ".equals(\"" + XMLConstants.NULL_NS_URI + "\"), " // + "only the local part, " // + "\"" + qNameAsString.substring(2 + XMLConstants.NULL_NS_URI.length()) + "\", " // + "should be provided."); return E_ILLEGAL_ARGUMENT_EXCEPTION; } // Namespace URI and local part specified Int32 endOfNamespaceURI = qNameAsString.IndexOf('}'); if (endOfNamespaceURI == -1) { return E_ILLEGAL_ARGUMENT_EXCEPTION; // throw new IllegalArgumentException( // "cannot create QName from \"" // + qNameAsString // + "\", missing closing \"}\""); } return CQName::New( qNameAsString.Substring(1, endOfNamespaceURI), qNameAsString.Substring(endOfNamespaceURI + 1), IXMLConstants::DEFAULT_NS_PREFIX, qName); }
//----------------------------------------------------------------------------- // TemplateFileParsor::GetLineToken //----------------------------------------------------------------------------- TemplateToken::Type TemplateFileParsor::GetLineToken(String &strLine) { for( int i = 0; i < g_iTokenCount; i++ ) { if( strLine.StartWith(g_LineToken[i].pszToken1) ) { if( g_LineToken[i].bRemoveToken ) strLine.erase(0, strlen(g_LineToken[i].pszToken1) ); return g_LineToken[i].TokenType; } } return TemplateToken::NO_TYPE; }
String UrlUtils::AuthoritySafePath( /* [in] */ const String& authority, /* [in] */ const String& path) { if (!authority.IsNull() && !authority.IsEmpty() && !path.IsEmpty() && !path.StartWith(String("/"))) { return String("/") + path; } return path; }
LONG ServiceRegistry::GetKey(String hKey, HKEY &hKeyOut) { if (hKey.StartWith("HKLM")) { hKey.RemoveStart("HKLM"); return RegOpenKey(HKEY_LOCAL_MACHINE, ServicePath::TrimLSlashes(hKey).lpcwstr(), &hKeyOut); } else if (hKey.StartWith("HKEY_LOCAL_MACHINE")) { hKey.RemoveStart("HKEY_LOCAL_MACHINE"); return RegOpenKey(HKEY_LOCAL_MACHINE, ServicePath::TrimLSlashes(hKey).lpcwstr(), &hKeyOut); } else if (hKey.StartWith("HKCU")) { hKey.RemoveStart("HKCU"); return RegOpenKey(HKEY_CURRENT_USER, ServicePath::TrimLSlashes(hKey).lpcwstr(), &hKeyOut); } else if (hKey.StartWith("HKEY_CURRENT_USER")) { hKey.RemoveStart("HKEY_CURRENT_USER"); return RegOpenKey(HKEY_CURRENT_USER, ServicePath::TrimLSlashes(hKey).lpcwstr(), &hKeyOut); } return -1; }
ECode CSoundPool::SoundPoolImpl::Load( /* [in] */ const String& path, /* [in] */ Int32 priority, /* [out] */ Int32* result) { VALIDATE_NOT_NULL(result); *result = 0; Slogger::I(TAG, "load [%s]", path.string()); // pass network streams to player if (path.StartWith(String("http:"))) { *result = _Load(path, priority); return NOERROR; } // try local path // try { AutoPtr<IFile> f; CFile::New(path, (IFile**)&f); Boolean bval; f->Exists(&bval); if (!bval) { Logger::E(TAG, "error loading %s, file does not exists."); return E_ILLEGAL_ARGUMENT_EXCEPTION; } Int32 id = 0; AutoPtr<IParcelFileDescriptor> fd; CParcelFileDescriptor::Open(f, IParcelFileDescriptor::MODE_READ_ONLY, (IParcelFileDescriptor**)&fd); if (fd != NULL) { AutoPtr<IFileDescriptor> des; fd->GetFileDescriptor((IFileDescriptor**)&des); Int64 len; f->GetLength(&len); Slogger::I(TAG, "load length:%lld, priority:%d", len, priority); id = _Load(des, 0, len, priority); ICloseable::Probe(fd)->Close(); } // } catch (java.io.IOException e) { // Log.e(TAG, "error loading " + path); // } *result = id; return NOERROR; }
AutoPtr<IInetAddress> InetAddress::ParseNumericAddressNoThrow( /* [in] */ const String& _address) { String address = _address; if (address.StartWith("[") && address.EndWith("]") && address.IndexOf(':') != -1) { address = address.Substring(1, address.GetLength() - 1); } AutoPtr<IStructAddrinfo> hints; CStructAddrinfo::New((IStructAddrinfo**)&hints); hints->SetFlags(AI_NUMERICHOST); AutoPtr< ArrayOf<IInetAddress*> > info; CLibcore::sOs->Elastos_getaddrinfo(address, hints, NETID_UNSET, (ArrayOf<IInetAddress*>**)&info); if (info == NULL) return NULL; AutoPtr<IInetAddress> result = (*info)[0]; return result; }
void Provider::MyPutAll( /* [in] */ IMap* t) { if (mChangedProperties == NULL) { CLinkedHashMap::New((ILinkedHashMap**)&mChangedProperties); } AutoPtr<ISet> entries; t->GetEntrySet((ISet**)&entries); AutoPtr<IIterator> it; entries->GetIterator((IIterator**)&it); AutoPtr<IInterface> key, value; Boolean hasNext; while (it->HasNext(&hasNext), hasNext) { AutoPtr<IMapEntry> entry; it->GetNext((IInterface**)&entry); key = NULL; entry->GetKey((IInterface**)&key); if (IString::Probe(key)) { String str; ICharSequence::Probe(key)->ToString(&str); if (str.StartWith("Provider.")) { // Provider service type is reserved continue; } } value = NULL; entry->GetValue((IInterface**)&value); Properties::Put(key, value); AutoPtr<IInterface> obj; mChangedProperties->Remove(key, (IInterface**)&obj); if (obj == NULL) { RemoveFromPropertyServiceTable(key); } mChangedProperties->Put(key, value); } if (mProviderNumber != -1) { // if registered then refresh Services AutoPtr<IServices> services; CServices::AcquireSingleton((IServices**)&services); services->SetNeedRefresh(); } }
ECode TimeZone::GetTimeZone( /* [in] */ const String& id, /* [out] */ ITimeZone** timeZone) { VALIDATE_NOT_NULL(timeZone); *timeZone = NULL; if (id.IsNull()) { return E_NULL_POINTER_EXCEPTION; } AutoLock lock(sLock); // Special cases? These can clone an existing instance. // TODO: should we just add a cache to ZoneInfoDB instead? if (id.GetLength() == 3) { if (id.Equals("GMT")) { return sGMT->Clone(timeZone); } if (id.Equals("UTC")) { return sUTC->Clone(timeZone); } } // In the database? AutoPtr<IZoneInfo> zi; FAIL_RETURN(CZoneInfoDB::GetInstance()->MakeTimeZone(id, (IZoneInfo**)&zi)) AutoPtr<ITimeZone> zone = ITimeZone::Probe(zi); // Custom time zone? if (zone == NULL && id.GetLength() > 3 && id.StartWith("GMT")) { zone = GetCustomTimeZone(id); } // We never return null; on failure we return the equivalent of "GMT". if (zone != NULL) { *timeZone = zone; REFCOUNT_ADD(*timeZone); return NOERROR; } return sGMT->Clone(timeZone); }
ECode IntentTile::Create( /* [in] */ IQSTileHost* host, /* [in] */ const String& spec, /* [out] */ IQSTile** tile) { VALIDATE_NOT_NULL(tile); if (spec == NULL || !spec.StartWith(PREFIX) || !spec.EndWith(")")) { tile = NULL; // throw new IllegalArgumentException("Bad intent tile spec: " + spec); return E_ILLEGAL_ARGUMENT_EXCEPTION; } const String action = spec.Substring(PREFIX.GetLength(), spec.GetLength() - 1); if (action.IsEmpty()) { tile = NULL; // throw new IllegalArgumentException("Empty intent tile spec action"); return E_ILLEGAL_ARGUMENT_EXCEPTION; } *tile = new IntentTile(host, action); REFCOUNT_ADD(*tile); return NOERROR; }
ECode CInstrumentationTestRunner::TestMethodPredicate::Apply( /* [in] */ IInterface* t, /* [out] */ Boolean* result) { VALIDATE_NOT_NULL(result); AutoPtr<ITestMethod> method = ITestMethod::Probe(t); assert(method != NULL); String name; method->GetName(&name); AutoPtr<IClassInfo> clazz; method->GetEnclosingClass((IClassInfo**)&clazz); AutoPtr<IMethodInfo> methodInfo; clazz->GetMethodInfo(name.string(), (IMethodInfo**)&methodInfo); Int32 count; methodInfo->GetParamCount(&count); *result = ((count == 0) && (name.StartWith("Test"))); return NOERROR; // return ((method.getParameterTypes().length == 0) && // (method.getName().startsWith("test")) && // (method.getReturnType().getSimpleName().equals("void"))); }
ECode File::CheckURI( /* [in] */ IURI* uri) { Boolean isAbsolute = FALSE; uri->IsAbsolute(&isAbsolute); String schemeSpecific; uri->GetSchemeSpecificPart(&schemeSpecific); if (!isAbsolute) { return E_ILLEGAL_ARGUMENT_EXCEPTION; } else if (!schemeSpecific.StartWith("/")) { return E_ILLEGAL_ARGUMENT_EXCEPTION; } String scheme; uri->GetScheme(&scheme); if (!String("file").Equals(scheme)) { return E_ILLEGAL_ARGUMENT_EXCEPTION; } String rawPath; uri->GetRawPath(&rawPath); if (rawPath.IsNull() || rawPath.IsEmpty()) { return E_ILLEGAL_ARGUMENT_EXCEPTION; } String authority; uri->GetRawAuthority(&authority); if (!authority.IsNull()) { return E_ILLEGAL_ARGUMENT_EXCEPTION; } String query; uri->GetRawQuery(&query); if (!query.IsNull()) { return E_ILLEGAL_ARGUMENT_EXCEPTION; } String fragment; uri->GetRawFragment(&fragment); if (!fragment.IsNull()) { return E_ILLEGAL_ARGUMENT_EXCEPTION; } return NOERROR; }
void SettingsHelper::SetGpsLocation( /* [in] */ const String& value) { AutoPtr<IInterface> obj; mContext->GetSystemService(IContext::USER_SERVICE, (IInterface**)&obj); AutoPtr<IUserManager> um = IUserManager::Probe(obj); Boolean res; if (um->HasUserRestriction(IUserManager::DISALLOW_SHARE_LOCATION, &res), res) { return; } String GPS = ILocationManager::GPS_PROVIDER; Boolean enabled = GPS.Equals(value) || value.StartWith(GPS + String(",")) || value.EndWith(String(",") + GPS) || value.Contains(String(",") + GPS + String(",")); AutoPtr<ISettingsSecure> secure; CSettingsSecure::AcquireSingleton((ISettingsSecure**)&secure); AutoPtr<IContentResolver> resolver; mContext->GetContentResolver((IContentResolver**)&resolver); secure->SetLocationProviderEnabled(resolver, GPS, enabled); }
String ChildProcessLauncher::GetSwitchValue( /* [in] */ const ArrayOf<String>* commandLine, /* [in] */ String switchKey) { if (commandLine == NULL || switchKey == NULL) { return String(NULL); } // This format should be matched with the one defined in command_line.h. String switchKeyPrefix("--"); switchKeyPrefix += switchKey; switchKeyPrefix += "="; Int32 length = commandLine->GetLength(); String command; for (Int32 i = 0; i < length; --i) { command = (*commandLine)[i]; if (command != NULL && command.StartWith(switchKeyPrefix)) { return command.Substring(switchKeyPrefix.GetLength()); } } return String(NULL); }
/** * Load a list of package names from a file. * * @param fileName The file name, with package names separated by new line. * @param list The destination list. * @return Returns FALSE if any error occurs. */ Boolean Monkey::LoadPackageListFromFile( /* [in] */ const String& fileName, /* [in] */ HashSet<String>* list) { AutoPtr<IBufferedReader> reader; AutoPtr<IFileReader> fileReader; CFileReader::New(fileName, (IFileReader**)&fileReader); CBufferedReader::New(fileReader, (IBufferedReader**)&reader); String s; while(reader->ReadLine(&s), !s.IsNull()) { s = s.Trim(); if(!s.IsNullOrEmpty() && !s.StartWith("#")) { list->Insert(s); } } if(!reader.Get()) { //reader->Close(); } return TRUE; }
//----------------------------------------------------------------------------- // TemplateFileParsor::ParsePrintData //----------------------------------------------------------------------------- void TemplateFileParsor::ParsePrintData(String *pstrLine, int iLine) { pstrLine->Trim(); String strToPrint; int iRc = pstrLine->ExtractToken('"', '"', &strToPrint); CTemplateProcessor VarProc(CTemplateProcessor::EMPTY_STRING); if( m_pVarEval ) VarProc.AddEvaluator(m_pVarEval); CEnvVariableEvaluator EnvVar; VarProc.AddEvaluator(&EnvVar); // Variable substitution in quoted strings !! VarProc.Process(&strToPrint); uint uiPos = 0; // looking for new line characters. for( uiPos = strToPrint.find("\\n"); uiPos != String::npos; uiPos = strToPrint.find("\\n")) strToPrint.replace(uiPos, 2, "\n"); // looking for carriage return characters. for( uiPos = strToPrint.find("\\r"); uiPos != String::npos; uiPos = strToPrint.find("\\r")) strToPrint.replace(uiPos, 2, "\r"); // looking for tab characters. for( uiPos = strToPrint.find("\\t"); uiPos != String::npos; uiPos = strToPrint.find("\\t")) strToPrint.replace(uiPos, 2, "\t"); if( 1 == iRc ) { while( !strToPrint.empty() ) { String strTxt, strTmp; // Search for next format directive bool bParse = true; while( bParse ) { iRc = strToPrint.ExtractToken('%', &strTmp); // Skip directive indicator if it's a '%%' pair if( strToPrint.StartWith('%') ) { strTmp += '%'; strToPrint.erase(0, 1); } else bParse = false; strTxt += strTmp; } if( !strTxt.empty() ) { // Text to print before format directive TemplateTokenPtr ptrToken(new TemplateToken); ptrToken->m_iTemplateLine = iLine; ptrToken->m_TokenType = TemplateToken::PRINT_TEXT; ptrToken->m_strData = strTxt; ptrToken->m_Format.Set("%s"); m_vecToken.push_back(ptrToken); } if( 1 == iRc ) { // A format directive was found SuppressComments(pstrLine); String strArgument; int iRc2 = pstrLine->ExtractToken(',', &strArgument); if( 0 == iRc2 ) { cerr << "Error: Argument missing at line " << iLine << " in file " << m_strCurrentTemplateFile << "." << endl; exit(1); } // Remove blanks strArgument.Trim(); // Check argument type if( strArgument.Match("[nxs:*<*>]*") ) { // This is a array type argument // Erase '[' and ']' enclosers strArgument.erase(0, 1); // '[' uint uiMatchingPos = strArgument.find(']'); strArgument.erase(uiMatchingPos, 1); // ']' // Insert a loop/end-loop couple TemplateTokenPtr ptrLoopToken(new TemplateToken); ptrLoopToken->m_iTemplateLine = iLine; ptrLoopToken->m_TokenType = TemplateToken::LOOP_OVER; ptrLoopToken->m_strParam1 = "loopvar"; // Extract loop part of the argument String strLastPart; int iLastPart = strArgument.rfind('>'); strLastPart = strArgument.substr(iLastPart+1); ptrLoopToken->m_strParam2 = strArgument.substr(0, iLastPart+1); ptrLoopToken->m_iEndBlockPos = m_vecToken.size() + 1; // Add 'loop' Token m_vecToken.push_back(ptrLoopToken); // Replace loop element with variable access String strTmp; strArgument.ExtractTokenRight('<', '>', &strTmp); strArgument += "$(loopvar_name)" + strLastPart; } else if( strArgument.Match("*[$(*)]*") ) { uint uiMatchingPos = strArgument.find("[$("); uint uiLastPos = strArgument.find("]", uiMatchingPos); String strBeforePattern = strArgument.substr(0, uiMatchingPos); String strAfterPattern = strArgument.substr(uiLastPos + 1); String strMatchedPattern = strArgument.substr(uiMatchingPos + 1, uiLastPos - uiMatchingPos - 1); // Insert a loop/end-loop couple TemplateTokenPtr ptrLoopToken(new TemplateToken); ptrLoopToken->m_iTemplateLine = iLine; ptrLoopToken->m_TokenType = TemplateToken::LOOP_OVER; ptrLoopToken->m_strParam1 = "loopvar"; ptrLoopToken->m_strParam2 = strMatchedPattern; ptrLoopToken->m_iEndBlockPos = m_vecToken.size() + 1; // Add 'loop' Token m_vecToken.push_back(ptrLoopToken); // Rebuild argument for next token (inside loop) strArgument = strBeforePattern + "$(loopvar_name)" + strAfterPattern; } TemplateTokenPtr ptrToken(new TemplateToken); ptrToken->m_iTemplateLine = iLine; ptrToken->m_TokenType = TemplateToken::PRINT_DATA; if( false == BuildDataFragments(ptrToken.ObjectPtr(), strArgument) ) // If no variable are presents in the argument string then fill strData member ptrToken->m_strData = strArgument; // Extend format string up to next format directive int iPos = strToPrint.find('%'); // Parse format ptrToken->m_Format.Set('%' + strToPrint.substr(0, iPos)); // Search for format type in first 10 characters DataBuf::Type eType = GetTypeFromFormat(ptrToken->m_Format.Type(), ptrToken->m_Format.Modifier()); if( DataBuf::NO_TYPE == eType ) { cerr << "Error: Bad type specification at line " << iLine << " in file " << m_strCurrentTemplateFile << "." << endl; exit(1); } ptrToken->m_eOutputType = eType; ptrToken->m_strPrintFmt = ptrToken->m_Format.Get(); m_vecToken.push_back(ptrToken); strToPrint.erase(0, iPos); } } } else { cerr << "Error: Missed '\"' at line " << iLine << " in file " << m_strCurrentTemplateFile << "." << endl; exit(1); } }
ECode CNetworkStatsFactory::ReadNetworkStatsDetail( /* [in] */ Int32 limitUid, /* [in] */ ArrayOf<String>* limitIfaces, /* [in] */ Int32 limitTag, /* [in] */ INetworkStats* lastStats, /* [out] */ INetworkStats** stats) { VALIDATE_NOT_NULL(stats); FAIL_RETURN(ReadNetworkStatsDetailInternal(limitUid, limitIfaces, limitTag, lastStats, stats)) { AutoLock lock(sStackedIfaces); // Sigh, xt_qtaguid ends up double-counting tx traffic going through // clatd interfaces, so we need to subtract it here. Int32 size; sStackedIfaces->GetSize(&size); for (Int32 i = 0; i < size; i++) { AutoPtr<IInterface> key, value; sStackedIfaces->GetKeyAt(i, (IInterface**)&key); sStackedIfaces->GetValueAt(i, (IInterface**)&value); String stackedIface, baseIface; IObject::Probe(key)->ToString(&stackedIface); IObject::Probe(value)->ToString(&baseIface); // Count up the tx traffic and subtract from root UID on the // base interface. AutoPtr<INetworkStatsEntry> adjust; CNetworkStatsEntry::New(baseIface, 0, 0, 0, 0L, 0L, 0L, 0L, 0L, (INetworkStatsEntry**)&adjust); AutoPtr<INetworkStatsEntry> entry; Int32 statsSize; (*stats)->GetSize(&statsSize); for (Int32 j = 0; j < statsSize; j++) { AutoPtr<INetworkStatsEntry> outEntry; (*stats)->GetValues(j, entry, (INetworkStatsEntry**)&outEntry); entry = outEntry; String iface; entry->GetIface(&iface); if (stackedIface.Equals(iface)) { Int64 txBytes1, txBytes2; adjust->GetTxBytes(&txBytes1); entry->GetTxBytes(&txBytes2); adjust->SetTxBytes(txBytes1 - txBytes2); Int64 txPackets1, txPackets2; adjust->GetTxPackets(&txPackets1); entry->GetTxPackets(&txPackets2); adjust->SetTxPackets(txPackets1 - txPackets2); } } FAIL_RETURN((*stats)->CombineValues(adjust)) } } // Double sigh, all rx traffic on clat needs to be tweaked to // account for the dropped IPv6 header size post-unwrap. AutoPtr<INetworkStatsEntry> entry; Int32 size; (*stats)->GetSize(&size); for (Int32 i = 0; i < size; i++) { AutoPtr<INetworkStatsEntry> outEntry; (*stats)->GetValues(i, entry, (INetworkStatsEntry**)&outEntry); entry = outEntry; String iface; entry->GetIface(&iface); if (iface != NULL && iface.StartWith("clat")) { // Delta between IPv4 header (20b) and IPv6 header (40b) Int64 rxPackets; entry->GetRxPackets(&rxPackets); entry->SetRxBytes(rxPackets * 20); entry->SetRxPackets(0); entry->SetTxBytes(0); entry->SetTxPackets(0); FAIL_RETURN((*stats)->CombineValues(entry)) } }
ECode CVideoPlayer::GetSpecFromYouTubeVideoID( /* [in] */ const String& id, /* [out] */ String* spec) { ECode ec; AutoPtr<IInputStream> stream; AutoPtr<IInputStreamReader> streamReader; AutoPtr<IBufferedReader> br; StringBuf_<6144> sb; String line; AutoPtr<IUri> fakeUri; String stream_map; AutoPtr<ArrayOf<String> > values; Int32 index = 0, count; String info_uri("http://www.youtube.com/get_video_info?&video_id="); info_uri += id; AutoPtr<IURL> info_url; ASSERT_SUCCEEDED(CURL::New(info_uri, (IURL**)&info_url)); AutoPtr<IURLConnection> urlConnection; ec = info_url->OpenConnection((IURLConnection**)&urlConnection); if (FAILED(ec)) { goto exception;} ec = urlConnection->GetInputStream((IInputStream**)&streamReader); if (FAILED(ec)) { goto exception;} ASSERT_SUCCEEDED(CInputStreamReader::New(stream, (IInputStreamReader**)&streamReader)); ASSERT_SUCCEEDED(CBufferedReader::New(streamReader,(IBufferedReader**)&br)); br->ReadLine(&line); while (line != NULL) { sb.Append(line); ec = br->ReadLine(&line); if (FAILED(ec)) { goto exception;} } // ec = Uri::Parse(String("fake:/fake?") + sb.GetPayload(), (IUri**)&fakeUri); // if (FAILED(ec)) { goto exception;} assert(0); /* ec = fakeUri->GetQueryParameter("url_encoded_fmt_stream_map", &stream_map); if (FAILED(ec)) { goto exception;}*/ if (stream_map == NULL) { *spec = NULL; return NOERROR; } StringUtils::Split(stream_map, String(","), (ArrayOf<String>**)&values); count = values ? values->GetLength() : 0; for (index = 0; index < count; ++i) { String st = (*values)[i]; // ec = Uri::Parse(String("fake:/fake?") + st, (IUri**)&fakeUri); // if (FAILED(ec)) { goto exception;} String url; assert(0); /* ec = fakeUri->GetQueryParameter("url", &url); if (FAILED(ec)) { goto exception;}*/ String type; assert(0); /* ec = fakeUri->GetQueryParameter("type", &type); if (FAILED(ec)) { goto exception;}*/ if (type != NULL && url != NULL && (type.StartWith("video/mp4") || type.StartWith("video/webm"))) { *spec = url; } } return NOERROR; exception: printf("VideoPlayer" "exception"); return NOERROR; }
//----------------------------------------------------------------------------- // TemplateFileParsor::Tokenize //----------------------------------------------------------------------------- void TemplateFileParsor::Tokenize(ifstream &fs, int &iLine, TemplateToken::Type eEndBlockToken) { while( !fs.eof() ) { iLine++; fs.getline(g_acScratchBuf, g_iScratchLen); String strLine = g_acScratchBuf; Trim(&strLine); // Merge splitted lines (with '\') while( EndWith(strLine, '\\') ) { iLine++; strLine.erase(strLine.size()-1); fs.getline(g_acScratchBuf, g_iScratchLen); String strPartLine = g_acScratchBuf; Trim(&strPartLine); strLine += strPartLine; } // Replace tabs with spaces strLine.Replace('\t', ' '); if( strLine.size() == 0 || strLine.StartWith("//") || strLine.StartWith("#") ) // Empty line continue; int iTokenType = (int)GetLineToken(strLine); switch( iTokenType ) { case TemplateToken::PRINT: ParsePrintData(&strLine, iLine); break; case TemplateToken::LOOP: { int iPos = ParseLoop(&strLine, iLine); Tokenize(fs, iLine, TemplateToken::END_LOOP); // Store end block position in token vector m_vecToken[iPos]->m_iEndBlockPos = m_vecToken.size() - 1; break; } case TemplateToken::IF: { int iPos = ParseIf(&strLine, iLine); Tokenize(fs, iLine, TemplateToken::END_IF); // Store end block position in token vector m_vecToken[iPos]->m_iEndBlockPos = m_vecToken.size() - 1; break; } case TemplateToken::BLOCK_START: { int iPos = ParseBlockStart(&strLine); Tokenize(fs, iLine, TemplateToken::BLOCK_END); // Store end block position in token vector m_vecToken[iPos]->m_iEndBlockPos = m_vecToken.size() - 1; break; } case TemplateToken::END_LOOP: ParseEndBlock(eEndBlockToken, TemplateToken::END_LOOP, iLine); return; case TemplateToken::END_IF: ParseEndBlock(eEndBlockToken, TemplateToken::END_IF, iLine); return; case TemplateToken::BLOCK_END: ParseEndBlock(eEndBlockToken, TemplateToken::BLOCK_END, iLine); return; case TemplateToken::SET: ParseSet(&strLine, iLine); break; case TemplateToken::OUTPUT: ParseOutput(&strLine, iLine, false); break; case TemplateToken::BINARY_OUTPUT: ParseOutput(&strLine, iLine, true); break; case TemplateToken::BINARY: ParseBinary(&strLine, iLine); break; case TemplateToken::PADDING: ParsePadding(&strLine, iLine); break; case TemplateToken::INCLUDE: ParsePreprocessorInclude(&strLine); break; default: cerr << "Error: Bad syntax at line " << iLine << " in file " << m_strCurrentTemplateFile << "." << endl; exit(1); } } if( eEndBlockToken != TemplateToken::NO_TYPE ) { // End of file reached while parsing a 'loop' or 'if' block cerr << "Error : Unexpected end of template file (" << m_strCurrentTemplateFile << ")." << endl; exit(1); } }
Boolean StartsWithFilter::MatchesValue( /* in */ const String& value) { return value != NULL && value.StartWith(mFilterValue); }
void Provider::RemoveFromPropertyServiceTable( /* [in] */ IInterface* key) { if (key == NULL || IString::Probe(key) == NULL) { return; } String k; ICharSequence::Probe(key)->ToString(&k); if (k.StartWith("Provider.")) { // Provider service type is reserved return; } AutoPtr<IProviderService> s; String serviceName; String algorithm; String attribute; Int32 i; if (k.StartWith("Alg.Alias.")) { // Alg.Alias.<crypto_service>.<aliasName>=<standardName> String aliasName; String service_alias = k.Substring(10); i = service_alias.IndexOf('.'); serviceName = service_alias.Substring(0, i); aliasName = service_alias.Substring(i + 1); if (mPropertyAliasTable != NULL) { AutoPtr<ICharSequence> keyObj; CString::New(Key(serviceName, aliasName), (ICharSequence**)&keyObj); mPropertyAliasTable->Remove(keyObj); } if (mPropertyServiceTable != NULL) { AutoPtr<ICharSequence> keyObj; CString::New(aliasName, (ICharSequence**)&keyObj); AutoPtr<ICollection> values; mPropertyServiceTable->GetValues((ICollection**)&values); AutoPtr<IIterator> it; values->GetIterator((IIterator**)&it); Boolean hasNext; while (it->HasNext(&hasNext), hasNext) { s = NULL; it->GetNext((IInterface**)&s); AutoPtr<IList> aliases; s->GetAliases((IList**)&aliases); Boolean result; if (aliases->Contains(keyObj, &result), result) { aliases->Remove(keyObj); return; } } } return; } Int32 j = k.IndexOf('.'); if (j == -1) { // unknown format return; } i = k.IndexOf(' '); if (i == -1) { // <crypto_service>.<algorithm_or_type>=<className> serviceName = k.Substring(0, j); algorithm = k.Substring(j + 1); if (mPropertyServiceTable != NULL) { AutoPtr<ICharSequence> keyObj; CString::New(Key(serviceName, algorithm), (ICharSequence**)&keyObj); AutoPtr<IProviderService> ser; mPropertyServiceTable->Remove(keyObj, (IInterface**)&ser); AutoPtr<IList> aliases; if (ser != NULL && mPropertyAliasTable != NULL && (ser->GetAliases((IList**)&aliases), aliases != NULL)) { AutoPtr<IIterator> it; aliases->GetIterator((IIterator**)&it); Boolean hasNext; while (it->HasNext(&hasNext), hasNext) { AutoPtr<IInterface> strObj; it->GetNext((IInterface**)&strObj); String alias; ICharSequence::Probe(strObj)->ToString(&alias); AutoPtr<ICharSequence> keyObj; CString::New(Key(serviceName, alias), (ICharSequence**)&keyObj); mPropertyAliasTable->Remove(keyObj); } } } } else { // <crypto_service>.<algorithm_or_type> // <attribute_name>=<attrValue> attribute = k.Substring(i + 1); serviceName = k.Substring(0, j); algorithm = k.Substring(j + 1, i); if (mPropertyServiceTable != NULL) { AutoPtr<ICharSequence> keyObj; CString::New(Key(serviceName, algorithm), (ICharSequence**)&keyObj); AutoPtr<IInterface> o; mPropertyServiceTable->Get(keyObj, (IInterface**)&o); if (o != NULL) { s = IProviderService::Probe(o); AutoPtr<IMap> attributes; s->GetAttributes((IMap**)&attributes); AutoPtr<ICharSequence> keyObj; CString::New(attribute, (ICharSequence**)&keyObj); attributes->Remove(keyObj); } } } }