void MakeSmartPtrCheck::registerMatchers(ast_matchers::MatchFinder *Finder) {
  if (!isLanguageVersionSupported(getLangOpts()))
    return;

  // Calling make_smart_ptr from within a member function of a type with a
  // private or protected constructor would be ill-formed.
  auto CanCallCtor = unless(has(ignoringImpCasts(
      cxxConstructExpr(hasDeclaration(decl(unless(isPublic())))))));

  Finder->addMatcher(
      cxxBindTemporaryExpr(has(ignoringParenImpCasts(
          cxxConstructExpr(
              hasType(getSmartPointerTypeMatcher()), argumentCountIs(1),
              hasArgument(0,
                          cxxNewExpr(hasType(pointsTo(qualType(hasCanonicalType(
                                         equalsBoundNode(PointerType))))),
                                     CanCallCtor)
                              .bind(NewExpression)),
              unless(isInTemplateInstantiation()))
              .bind(ConstructorCall)))),
      this);

  Finder->addMatcher(
      cxxMemberCallExpr(
          thisPointerType(getSmartPointerTypeMatcher()),
          callee(cxxMethodDecl(hasName("reset"))),
          hasArgument(0, cxxNewExpr(CanCallCtor).bind(NewExpression)),
          unless(isInTemplateInstantiation()))
          .bind(ResetCall),
      this);
}
void UseEqualsDeleteCheck::registerMatchers(MatchFinder *Finder) {
  auto PrivateSpecialFn = cxxMethodDecl(
      isPrivate(),
      anyOf(cxxConstructorDecl(anyOf(isDefaultConstructor(),
                                     isCopyConstructor(), isMoveConstructor())),
            cxxMethodDecl(
                anyOf(isCopyAssignmentOperator(), isMoveAssignmentOperator())),
            cxxDestructorDecl()));

  Finder->addMatcher(
      cxxMethodDecl(
          PrivateSpecialFn,
          unless(anyOf(hasBody(stmt()), isDefaulted(), isDeleted(),
                       ast_matchers::isTemplateInstantiation(),
                       // Ensure that all methods except private special member
                       // functions are defined.
                       hasParent(cxxRecordDecl(hasMethod(unless(
                           anyOf(PrivateSpecialFn, hasBody(stmt()), isPure(),
                                 isDefaulted(), isDeleted()))))))))
          .bind(SpecialFunction),
      this);

  Finder->addMatcher(
      cxxMethodDecl(isDeleted(), unless(isPublic())).bind(DeletedNotPublic),
      this);
}
示例#3
0
QString Modification::accessModifierString() const {
    if (isPrivate()) return "private";
    if (isProtected()) return "protected";
    if (isPublic()) return "public";
    if (isFriendly()) return "friendly";
    return QString();
}
BOOL LLParcel::allowModifyBy(const LLUUID &agent_id, const LLUUID &group_id) const
{
    if (agent_id == LLUUID::null)
    {
        // system always can enter
        return TRUE;
    }
    else if (isPublic())
    {
        return TRUE;
    }
    else if (agent_id == mOwnerID)
    {
        // owner can always perform operations
        return TRUE;
    }
    else if (mParcelFlags & PF_CREATE_OBJECTS)
    {
        return TRUE;
    }
    else if ((mParcelFlags & PF_CREATE_GROUP_OBJECTS)
             && group_id.notNull() )
    {
        return (getGroupID() == group_id);
    }
    
    return FALSE;
}
示例#5
0
std::unique_ptr<Info> emitInfo(const NamespaceDecl *D, const FullComment *FC,
                               int LineNumber, llvm::StringRef File,
                               bool PublicOnly) {
  if (PublicOnly && ((D->isAnonymousNamespace()) ||
                     !isPublic(D->getAccess(), D->getLinkageInternal())))
    return nullptr;
  auto I = llvm::make_unique<NamespaceInfo>();
  populateInfo(*I, D, FC);
  return std::unique_ptr<Info>{std::move(I)};
}
void ContainerSizeEmptyCheck::registerMatchers(MatchFinder *Finder) {
  // Only register the matchers for C++; the functionality currently does not
  // provide any benefit to other languages, despite being benign.
  if (!getLangOpts().CPlusPlus)
    return;

  const auto ValidContainer = cxxRecordDecl(isSameOrDerivedFrom(
      namedDecl(
          has(cxxMethodDecl(
                  isConst(), parameterCountIs(0), isPublic(), hasName("size"),
                  returns(qualType(isInteger(), unless(booleanType()))))
                  .bind("size")),
          has(cxxMethodDecl(isConst(), parameterCountIs(0), isPublic(),
                            hasName("empty"), returns(booleanType()))
                  .bind("empty")))
          .bind("container")));

  const auto WrongUse = anyOf(
      hasParent(binaryOperator(
                    matchers::isComparisonOperator(),
                    hasEitherOperand(ignoringImpCasts(anyOf(
                        integerLiteral(equals(1)), integerLiteral(equals(0))))))
                    .bind("SizeBinaryOp")),
      hasParent(implicitCastExpr(
          hasImplicitDestinationType(booleanType()),
          anyOf(
              hasParent(unaryOperator(hasOperatorName("!")).bind("NegOnSize")),
              anything()))),
      hasParent(explicitCastExpr(hasDestinationType(booleanType()))));

  Finder->addMatcher(
      cxxMemberCallExpr(on(expr(anyOf(hasType(ValidContainer),
                                      hasType(pointsTo(ValidContainer)),
                                      hasType(references(ValidContainer))))
                               .bind("STLObject")),
                        callee(cxxMethodDecl(hasName("size"))), WrongUse)
          .bind("SizeCallExpr"),
      this);
}
示例#7
0
std::unique_ptr<Info> emitInfo(const RecordDecl *D, const FullComment *FC,
                               int LineNumber, llvm::StringRef File,
                               bool PublicOnly) {
  if (PublicOnly && !isPublic(D->getAccess(), D->getLinkageInternal()))
    return nullptr;
  auto I = llvm::make_unique<RecordInfo>();
  populateSymbolInfo(*I, D, FC, LineNumber, File);
  I->TagType = D->getTagKind();
  parseFields(*I, D, PublicOnly);
  if (const auto *C = dyn_cast<CXXRecordDecl>(D))
    parseBases(*I, C);
  return std::unique_ptr<Info>{std::move(I)};
}
示例#8
0
int UtlCryptoKeyRsa::decrypt(const unsigned char* pSrc,
                             int srcLen,
                             unsigned char* pDest,
                             int* pDestLen) const
{
   if (isPrivate())
      return decryptPrivate(pSrc, srcLen, pDest, pDestLen);
   else if (isPublic())
      return decryptPublic(pSrc, srcLen, pDest, pDestLen);

   if (pDestLen)
      *pDestLen = 0;
   return 0;   // TODO: Set lastError?
}
示例#9
0
void print_access(u2 flags) {
	if(isPublic(flags))
		printf("public ");
	if(isPrivate(flags))
		printf("private ");
	if(isProtected(flags))
		printf("protected ");
	if(isFinal(flags))
		printf("final ");
	if(isAbstract(flags))
		printf("abstract ");
	if(isStatic(flags))
		printf("static ");
}
void SizeofContainerCheck::registerMatchers(MatchFinder *Finder) {
  Finder->addMatcher(
      expr(unless(isInTemplateInstantiation()),
           expr(sizeOfExpr(has(ignoringParenImpCasts(
                    expr(hasType(hasCanonicalType(hasDeclaration(cxxRecordDecl(
                        matchesName("^(::std::|::string)"),
                        unless(matchesName("^::std::(bitset|array)$")),
                        hasMethod(cxxMethodDecl(hasName("size"), isPublic(),
                                                isConst())))))))))))
               .bind("sizeof"),
           // Ignore ARRAYSIZE(<array of containers>) pattern.
           unless(hasAncestor(binaryOperator(
               anyOf(hasOperatorName("/"), hasOperatorName("%")),
               hasLHS(ignoringParenCasts(sizeOfExpr(expr()))),
               hasRHS(ignoringParenCasts(equalsBoundNode("sizeof"))))))),
      this);
}
示例#11
0
std::unique_ptr<Info> emitInfo(const FunctionDecl *D, const FullComment *FC,
                               int LineNumber, llvm::StringRef File,
                               bool PublicOnly) {
  if (PublicOnly && !isPublic(D->getAccess(), D->getLinkageInternal()))
    return nullptr;
  FunctionInfo Func;
  populateFunctionInfo(Func, D, FC, LineNumber, File);
  Func.Access = clang::AccessSpecifier::AS_none;

  // Wrap in enclosing scope
  auto I = llvm::make_unique<NamespaceInfo>();
  if (!Func.Namespace.empty())
    I->USR = Func.Namespace[0].USR;
  else
    I->USR = SymbolID();
  I->ChildFunctions.emplace_back(std::move(Func));
  return std::unique_ptr<Info>{std::move(I)};
}
示例#12
0
void LLParcel::clearSale()
{
	mSaleTimerExpires.setTimerExpirySec(0.0);
	mSaleTimerExpires.stop();
	if(isPublic())
	{
		mStatus = OS_NONE;
	}
	else
	{
		mStatus = OS_LEASED;
	}
	mAuthBuyerID.setNull();
	setForSale(FALSE);
	setAuctionID(0);
	setPreviousOwnerID(LLUUID::null);
	setPreviouslyGroupOwned(FALSE);
	setSellWithObjects(FALSE);
}
示例#13
0
std::unique_ptr<Info> emitInfo(const CXXMethodDecl *D, const FullComment *FC,
                               int LineNumber, llvm::StringRef File,
                               bool PublicOnly) {
  if (PublicOnly && !isPublic(D->getAccess(), D->getLinkageInternal()))
    return nullptr;
  FunctionInfo Func;
  populateFunctionInfo(Func, D, FC, LineNumber, File);
  Func.IsMethod = true;

  SymbolID ParentUSR = getUSRForDecl(D->getParent());
  Func.Parent = Reference{ParentUSR, D->getParent()->getNameAsString(),
                          InfoType::IT_record};
  Func.Access = D->getAccess();

  // Wrap in enclosing scope
  auto I = llvm::make_unique<RecordInfo>();
  I->USR = ParentUSR;
  I->ChildFunctions.emplace_back(std::move(Func));
  return std::unique_ptr<Info>{std::move(I)};
}
示例#14
0
static void parseFields(RecordInfo &I, const RecordDecl *D, bool PublicOnly) {
  for (const FieldDecl *F : D->fields()) {
    if (PublicOnly && !isPublic(F->getAccessUnsafe(), F->getLinkageInternal()))
      continue;
    if (const auto *T = getDeclForType(F->getTypeSourceInfo()->getType())) {
      // Use getAccessUnsafe so that we just get the default AS_none if it's not
      // valid, as opposed to an assert.
      if (const auto *N = dyn_cast<EnumDecl>(T)) {
        I.Members.emplace_back(getUSRForDecl(T), N->getNameAsString(),
                               InfoType::IT_enum, F->getNameAsString(),
                               N->getAccessUnsafe());
        continue;
      } else if (const auto *N = dyn_cast<RecordDecl>(T)) {
        I.Members.emplace_back(getUSRForDecl(T), N->getNameAsString(),
                               InfoType::IT_record, F->getNameAsString(),
                               N->getAccessUnsafe());
        continue;
      }
    }
    I.Members.emplace_back(F->getTypeSourceInfo()->getType().getAsString(),
                           F->getNameAsString(), F->getAccessUnsafe());
  }
}
示例#15
0
std::unique_ptr<Info> emitInfo(const EnumDecl *D, const FullComment *FC,
                               int LineNumber, llvm::StringRef File,
                               bool PublicOnly) {
  if (PublicOnly && !isPublic(D->getAccess(), D->getLinkageInternal()))
    return nullptr;
  EnumInfo Enum;
  populateSymbolInfo(Enum, D, FC, LineNumber, File);
  Enum.Scoped = D->isScoped();
  parseEnumerators(Enum, D);

  // Wrap in enclosing scope
  if (!Enum.Namespace.empty()) {
    switch (Enum.Namespace[0].RefType) {
    case InfoType::IT_namespace: {
      auto I = llvm::make_unique<NamespaceInfo>();
      I->USR = Enum.Namespace[0].USR;
      I->ChildEnums.emplace_back(std::move(Enum));
      return std::unique_ptr<Info>{std::move(I)};
    }
    case InfoType::IT_record: {
      auto I = llvm::make_unique<RecordInfo>();
      I->USR = Enum.Namespace[0].USR;
      I->ChildEnums.emplace_back(std::move(Enum));
      return std::unique_ptr<Info>{std::move(I)};
    }
    default:
      break;
    }
  }

  // Put in global namespace
  auto I = llvm::make_unique<NamespaceInfo>();
  I->USR = SymbolID();
  I->ChildEnums.emplace_back(std::move(Enum));
  return std::unique_ptr<Info>{std::move(I)};
}
示例#16
0
void CibIdMgr::assignIds(CibCompound*     compound,
                         const CibHelper& helper,
                         const CibParams& cibParams,
                         bool             forGenericProxy)
{
  // if (!compound->isShared())
  //  return;
  if (compound->isTemplated())
  {
    compound->forEachTemplateInstance(
      [&](CibCompound* ins) { this->assignIds(ins, helper, cibParams, forGenericProxy); });
    return;
  }
  if (compound->name().empty())
    return;
  // Dummy loop
  do
  {
    if (!forGenericProxy && !compound->needsBridging() && !compound->isShared())
      break;
    if (forGenericProxy && (!compound->needsGenericProxyDefinition() || compound->getAllVirtualMethods().empty()))
      break;

    const auto className = forGenericProxy ? compound->longName() + "::__zz_cib_GenericProxy" : compound->longName();
    CibIdData* cibIdData = nullptr;
    auto       itr       = cibIdTable_.find(className);
    if (itr == cibIdTable_.end())
    {
      auto clsId = nextClassId_++;
      if (compound->isTemplateInstance())
        compound->setNsName("__zz_cib_Class" + std::to_string(clsId));
      else if (isCppFile(compound))
        compound->setNsName(cibParams.globalNsName());
      const auto classNsName =
        forGenericProxy ? compound->fullNsName() + "::__zz_cib_GenericProxy" : compound->fullNsName();
      cibIdData = addClass(className, classNsName, clsId);
    }
    else
    {
      cibIdData = &itr->second;
      if (compound->isNsNameEmpty())
      {
        if (isCppFile(compound))
          compound->setNsName(cibParams.globalNsName());
        else if (compound->isTemplateInstance())
          compound->setNsName(cibIdData->getFullNsName());
      }
    }
    const auto& methods   = forGenericProxy ? compound->getAllVirtualMethods() : compound->getNeedsBridgingMethods();
    auto        addMethod = [&](const CibFunctionHelper& func) {
      auto&& sig = func.signature(helper);
      if (!cibIdData->hasMethod(func.signature(helper)))
        cibIdData->addMethod(sig, func.procName());
    };
    for (auto& func : methods)
      addMethod(func);
    if (forGenericProxy)
      addMethod(compound->dtor());
    if (!forGenericProxy)
    {
      compound->forEachAncestor(CppAccessType::kPublic, [compound, &cibIdData, &cibParams](const CibCompound* parent) {
        if (parent->isShared() || !parent->isEmpty())
        {
          auto castMethodName = compound->castToBaseName(parent, cibParams);
          if (!cibIdData->hasMethod(castMethodName))
            cibIdData->addMethod(castMethodName, castMethodName);
        }
        return false;
      });
      if (compound->isFacadeLike())
      {
        if (!cibIdData->hasMethod("__zz_cib_get_class_id"))
          cibIdData->addMethod("__zz_cib_get_class_id", "__zz_cib_get_class_id");
      }
      if (compound->needsGenericProxyDefinition())
      {
        if (!cibIdData->hasMethod("__zz_cib_release_proxy"))
          cibIdData->addMethod("__zz_cib_release_proxy", "__zz_cib_release_proxy");
      }
    }
  } while (false);
  for (auto& mem : compound->members())
  {
    if (isPublic(mem) && isNamespaceLike(mem))
    {
      assignIds(CibCompoundEPtr(mem), helper, cibParams, forGenericProxy);
    }
  }
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void FilterMaker::updateSourceList()
{
  QString filterName = this->filterName->text();
  QString pluginDir = this->pluginDir->text();

  QString pluginName = QFileInfo(pluginDir).baseName();

  QString sourceListPath = pluginDir + "/" + pluginName + "Filters/SourceList.cmake";
  sourceListPath = QDir::toNativeSeparators(sourceListPath);

  QFile source(sourceListPath);
  source.open(QFile::ReadOnly);
  QString contents = source.readAll();
  source.close();

  QString namespaceStr = createNamespaceString();
  // Check to make sure we don't already have this filter in the namespace
  if (contents.contains(namespaceStr) == true)
  {
    return;
  }
  bool keepGoing = false;
  QStringList outLines;
  QStringList list = contents.split(QRegExp("\\n"));
  QStringListIterator sourceLines(list);
  QString searchString = "set(_PublicFilters";
  if (!isPublic())
  {
    searchString = "set(_PrivateFilters";
  }

  while (sourceLines.hasNext())
  {
    QString line = sourceLines.next();
    if (line.contains(searchString) && !keepGoing)
    {
      outLines.push_back(line);
      while (sourceLines.hasNext())
      {
        line = sourceLines.next();
        if (line.contains(filterName) && !keepGoing)
        {
          outLines.push_back(line);
          keepGoing = true;
        }
        else if (line.contains(")"))
        {
          // We never found the filter name so lets add it back in
          if (!keepGoing)
          {
            outLines.push_back("  " + filterName);
          }
          outLines.push_back(line);
          keepGoing = true;
          break;
        }
        else
        {
          outLines.push_back(line);
        }
      }
    }
    else
    {
      outLines.push_back(line);
    }
  }

  source.remove();
  if (source.open(QIODevice::WriteOnly))
  {
    source.write(outLines.join("\n").toLatin1().data());
    source.close();
  }
}
示例#18
0
void PortMapping::run(void)
{
	std::unique_lock<std::mutex> lock(mMutex);
	if(!mEnabled) return;
	
	Set<Address> addresses;
	Network::Instance->overlay()->getAddresses(addresses);

	bool hasIpv4 = false;
	bool hasPublicIpv4 = false;
	auto it = addresses.begin();
	while(it != addresses.end())
	{
		hasIpv4|= it->isIpv4();
		hasPublicIpv4|= (it->isIpv4() && it->isPublic());
		++it;
	}
	
	if(!hasIpv4 || hasPublicIpv4) 
	{
		mProtocol.reset();
		return;
	}
	
	LogDebug("PortMapping", "Potential NAT detected");
	
	if(mProtocol)
	{
		bool success = false;
		try {
			if(mProtocol->check(mExternalHost) && !mExternalHost.empty())
				success = true;
		}
		catch(const Exception &e)
		{
			LogWarn("PortMapping", e.what());
		}
		
		if(!success) mProtocol.reset();
	}
	
	if(!mProtocol)
	{
		LogDebug("PortMapping", "Probing protocols...");
		
		mExternalHost.clear();
		for(int i=0; i<2; ++i)	// TODO: FreeboxAPI is disabled for now
		{
			try {
				switch(i)
				{
					case 0: mProtocol = std::make_shared<NatPMP>(); 	break;
					case 1: mProtocol = std::make_shared<UPnP>();		break;
					case 2: mProtocol = std::make_shared<FreeboxAPI>();	break;
				}
				
				if(mProtocol->check(mExternalHost) && !mExternalHost.empty()) 
					break;
			}
			catch(const Exception &e)
			{
				LogWarn("PortMapping", e.what());
			}
			
			mProtocol = NULL;
		}
		
		if(mProtocol) LogInfo("PortMapping", "Port mapping is available, external address is " + mExternalHost);
		else LogInfo("PortMapping", "Port mapping is not available");
	}
	
	if(mProtocol)
	{
		for(auto it = mMap.begin(); it != mMap.end(); ++it)
		{
			if(!it->second.external) it->second.external = it->second.suggested;
			if(!mProtocol->add(it->first.protocol, it->first.port, it->second.external))
				LogWarn("PortMapping", String("Mapping failed for ") + (it->first.protocol == TCP ? "TCP" : "UDP") + " port " + String::number(it->second.suggested));
		}
	}
}