Esempio n. 1
0
/*
============
idCVarSystemLocal::GetCVarFloat
============
*/
float idCVarSystemLocal::GetCVarFloat( const char *name ) const {
	idInternalCVar *internal = FindInternal( name );
	if ( internal ) {
		return internal->GetFloat();
	}
	return 0.0f;
}
Esempio n. 2
0
/*
============
idCVarSystemLocal::GetCVarBool
============
*/
bool idCVarSystemLocal::GetCVarBool( const char *name ) const {
	idInternalCVar *internal = FindInternal( name );
	if ( internal ) {
		return internal->GetBool();
	}
	return false;
}
Esempio n. 3
0
/*
============
idCVarSystemLocal::GetCVarInteger
============
*/
int idCVarSystemLocal::GetCVarInteger( const char *name ) const {
	idInternalCVar *internal = FindInternal( name );
	if ( internal ) {
		return internal->GetInteger();
	}
	return 0;
}
//---------------------------------------------------------------------------
const std::vector<int> ManyDigitIndexTable::FindInternal(
  const std::vector<int>& indices,
  const MultiVector<int>& v,
  const int value)
{
  //Check indices
  {
    const auto begin = v.PeekIndices().begin();
    const auto end   = v.PeekIndices().end();
    const auto x = std::find(begin,end,value);
    if (x!=end)
    {
      const int index_found = std::distance(begin,x);
      assert(index_found >= 0);
      assert(index_found < boost::numeric_cast<int>(v.PeekIndices().size()));
      std::vector<int> result = indices;
      result.push_back(index_found);
      return result;
    }
  }

  //Check MultiVector
  const auto& mvs = v.PeekMultiVectors();
  const int size = mvs.size();
  for (int i=0; i!=size; ++i)
  {
    std::vector<int> indices_deeper = indices;
    indices_deeper.push_back(i);
    const auto result
      = FindInternal(
        indices_deeper,mvs[i],value);
    if (!result.empty()) return result;
  }
  return std::vector<int>();
}
Esempio n. 5
0
/*
============
idCVarSystemLocal::GetCVarString
============
*/
const char *idCVarSystemLocal::GetCVarString( const char *name ) const {
	idInternalCVar *internal = FindInternal( name );
	if ( internal ) {
		return internal->GetString();
	}
	return "";
}
Esempio n. 6
0
/*
============
idCVarSystemLocal::Command
============
*/
bool idCVarSystemLocal::Command( const idCmdArgs &args )
{
    idInternalCVar *internal;

    internal = FindInternal( args.Argv( 0 ) );

    if ( internal == NULL )
    {
        return false;
    }

    if ( args.Argc() == 1 )
    {
        // print the variable
        common->Printf( "\"%s\" is:\"%s\"" S_COLOR_WHITE " default:\"%s\"\n",
                        internal->nameString.c_str(), internal->valueString.c_str(), internal->resetString.c_str() );
        if ( idStr::Length( internal->GetDescription() ) > 0 )
        {
            common->Printf( S_COLOR_WHITE "%s\n", internal->GetDescription() );
        }
    }
    else
    {
        // set the value
        internal->Set( args.Args(), false, false );
    }
    return true;
}
Esempio n. 7
0
/*
============
idCVarSystemLocal::SetCVarsFromDict
============
*/
void idCVarSystemLocal::SetCVarsFromDict( const idDict &dict ) {
	idInternalCVar *internal;

	for( int i = 0; i < dict.GetNumKeyVals(); i++ ) {
		const idKeyValue *kv = dict.GetKeyVal( i );
		internal = FindInternal( kv->GetKey() );
		if ( internal ) {
			internal->InternalServerSetString( kv->GetValue() );
		}
	}
}
Esempio n. 8
0
bool
OCSPCache::Get(const CertID& aCertID, Result& aResult, Time& aValidThrough)
{
  MutexAutoLock lock(mMutex);

  size_t index;
  if (!FindInternal(aCertID, index, lock)) {
    LogWithCertID("OCSPCache::Get(%p) not in cache", aCertID);
    return false;
  }
  LogWithCertID("OCSPCache::Get(%p) in cache", aCertID);
  aResult = mEntries[index]->mResult;
  aValidThrough = mEntries[index]->mValidThrough;
  MakeMostRecentlyUsed(index, lock);
  return true;
}
Esempio n. 9
0
/*
============
idCVarSystemLocal::SetInternal
============
*/
void idCVarSystemLocal::SetInternal( const char *name, const char *value, int flags ) {
	int hash;
	idInternalCVar *internal;

	internal = FindInternal( name );

	if ( internal ) {
		internal->InternalSetString( value );
		internal->flags |= flags & ~CVAR_STATIC;
		internal->UpdateCheat();
	} else {
		internal = new idInternalCVar( name, value, flags );
		hash = cvarHash.GenerateKey( internal->nameString.c_str(), false );
		cvarHash.Add( hash, cvars.Append( internal ) );
	}
}
Esempio n. 10
0
/*
============
idCVarSystemLocal::Register
============
*/
void idCVarSystemLocal::Register( idCVar *cvar ) {
	int hash;
	idInternalCVar *internal;

	cvar->SetInternalVar( cvar );

	internal = FindInternal( cvar->GetName() );

	if ( internal ) {
		internal->Update( cvar );
	} else {
		internal = new idInternalCVar( cvar );
		hash = cvarHash.GenerateKey( internal->nameString.c_str(), false );
		cvarHash.Add( hash, cvars.Append( internal ) );
	}

	cvar->SetInternalVar( internal );
}
//---------------------------------------------------------------------------
///Find returns the x-y-coordinats of the Newick with index i
///This is a linear (in this case, relatively time-intensive) method.
const ManyDigitNewickCoordinat ManyDigitIndexTable::Find(
  const int value) const
{
  //Check indices
  {
    const auto begin = m_v.PeekIndices().begin();
    const auto end   = m_v.PeekIndices().end();
    const auto x = std::find(begin,end,value);
    if (x!=end)
    {
      const int index_found = std::distance(begin,x);
      assert(index_found >= 0);
      assert(index_found < boost::numeric_cast<int>(m_v.PeekIndices().size()));
      return Coordinat( { index_found } );
    }
  }

  //Check MultiVector
  const std::vector<MultiVector<int> >& mvs
    = m_v.PeekMultiVectors();
  const int size = mvs.size();
  for (int i=0; i!=size; ++i)
  {

    const auto result
      = FindInternal(
          std::vector<int>(1,i),
          mvs[i],
          value);
    if (!result.empty())
    {
      return Coordinat(result);
    }
  }

  assert(!"Should not get here");
  std::stringstream s;
  s << "Value " << value << " not found in ManyDigitIndexTable::Find";
  throw std::logic_error(s.str());
}
Esempio n. 12
0
bool
OCSPCache::Get(const CERTCertificate* aCert,
               const CERTCertificate* aIssuerCert,
               PRErrorCode& aErrorCode,
               PRTime& aValidThrough)
{
  PR_ASSERT(aCert);
  PR_ASSERT(aIssuerCert);

  MutexAutoLock lock(mMutex);

  size_t index;
  if (!FindInternal(aCert, aIssuerCert, index, lock)) {
    LogWithCerts("OCSPCache::Get(%s, %s) not in cache", aCert, aIssuerCert);
    return false;
  }
  LogWithCerts("OCSPCache::Get(%s, %s) in cache", aCert, aIssuerCert);
  aErrorCode = mEntries[index]->mErrorCode;
  aValidThrough = mEntries[index]->mValidThrough;
  MakeMostRecentlyUsed(index, lock);
  return true;
}
Esempio n. 13
0
Result
OCSPCache::Put(const CertID& aCertID, Result aResult,
               Time aThisUpdate, Time aValidThrough)
{
  MutexAutoLock lock(mMutex);

  size_t index;
  if (FindInternal(aCertID, index, lock)) {
    // Never replace an entry indicating a revoked certificate.
    if (mEntries[index]->mResult == Result::ERROR_REVOKED_CERTIFICATE) {
      LogWithCertID("OCSPCache::Put(%p) already in cache as revoked - "
                    "not replacing", aCertID);
      MakeMostRecentlyUsed(index, lock);
      return Success;
    }

    // Never replace a newer entry with an older one unless the older entry
    // indicates a revoked certificate, which we want to remember.
    if (mEntries[index]->mThisUpdate > aThisUpdate &&
        aResult != Result::ERROR_REVOKED_CERTIFICATE) {
      LogWithCertID("OCSPCache::Put(%p) already in cache with more recent "
                    "validity - not replacing", aCertID);
      MakeMostRecentlyUsed(index, lock);
      return Success;
    }

    // Only known good responses or responses indicating an unknown
    // or revoked certificate should replace previously known responses.
    if (aResult != Success &&
        aResult != Result::ERROR_OCSP_UNKNOWN_CERT &&
        aResult != Result::ERROR_REVOKED_CERTIFICATE) {
      LogWithCertID("OCSPCache::Put(%p) already in cache - not replacing "
                    "with less important status", aCertID);
      MakeMostRecentlyUsed(index, lock);
      return Success;
    }

    LogWithCertID("OCSPCache::Put(%p) already in cache - replacing", aCertID);
    mEntries[index]->mResult = aResult;
    mEntries[index]->mThisUpdate = aThisUpdate;
    mEntries[index]->mValidThrough = aValidThrough;
    MakeMostRecentlyUsed(index, lock);
    return Success;
  }

  if (mEntries.length() == MaxEntries) {
    LogWithCertID("OCSPCache::Put(%p) too full - evicting an entry", aCertID);
    for (Entry** toEvict = mEntries.begin(); toEvict != mEntries.end();
         toEvict++) {
      // Never evict an entry that indicates a revoked or unknokwn certificate,
      // because revoked responses are more security-critical to remember.
      if ((*toEvict)->mResult != Result::ERROR_REVOKED_CERTIFICATE &&
          (*toEvict)->mResult != Result::ERROR_OCSP_UNKNOWN_CERT) {
        delete *toEvict;
        mEntries.erase(toEvict);
        break;
      }
    }
    // Well, we tried, but apparently everything is revoked or unknown.
    // We don't want to remove a cached revoked or unknown response. If we're
    // trying to insert a good response, we can just return "successfully"
    // without doing so. This means we'll lose some speed, but it's not a
    // security issue. If we're trying to insert a revoked or unknown response,
    // we can't. We should return with an error that causes the current
    // verification to fail.
    if (mEntries.length() == MaxEntries) {
      return aResult;
    }
  }

  Entry* newEntry = new (std::nothrow) Entry(aResult, aThisUpdate,
                                             aValidThrough);
  // Normally we don't have to do this in Gecko, because OOM is fatal.
  // However, if we want to embed this in another project, OOM might not
  // be fatal, so handle this case.
  if (!newEntry) {
    return Result::FATAL_ERROR_NO_MEMORY;
  }
  Result rv = newEntry->Init(aCertID);
  if (rv != Success) {
    delete newEntry;
    return rv;
  }
  if (!mEntries.append(newEntry)) {
    delete newEntry;
    return Result::FATAL_ERROR_NO_MEMORY;
  }
  LogWithCertID("OCSPCache::Put(%p) added to cache", aCertID);
  return Success;
}
Esempio n. 14
0
/*
============
idCVarSystemLocal::Find
============
*/
idCVar *idCVarSystemLocal::Find( const char *name ) {
	return FindInternal( name );
}
Esempio n. 15
0
int main(int argc, char **argv) {
  if (argc < 3) {
    PrintUsage(stderr, argv[0]);
    return -1;
  }

  if (!strcmp(argv[1], "create")) {
    if (argc < 4) {
      fprintf(stderr, "ERROR: incorrect create usage\n");
      return -2;
    }
    char *outbfile = argv[2];
    int n = atoi(argv[3]);

    /* Calculate btree size */
    int depth = CalcMinimumDepth(n);
    int sz = CalcTreeSize2(n, depth);
    fprintf(stderr, "n = %i, depth = %i, size = %i\n", n, depth, sz);

    /* Create memory buffer */
    mem = (char *) malloc(sz + 1);
    mem[sz] = 123; // Magic Marker to detect overflow
    memSize = sz;

    /* Init top node */
    BlockAddrT top = AllocBlock(0x0);
    Node topNode; 
    NodeInit(&topNode);
    topNode.depth = depth - 1; // total depth vs depth(rank?) of this node
    NodeSave(&topNode, top);
    BgTree tree;
    tree.topNode = top;

    /* Read in data */
    KeyT highestKey = 0;
    for (int i=0; i<n; i++) {
      KeyT key;
      BlockAddrT item;

      int res = fscanf(stdin, "%x\t%x", &key, &item);
      assert(res == 2);

      if (key < highestKey) {
        fprintf(stderr, "ERROR: Key out of order on line %i.  Input must be sorted!\n", i+1);
        return -3;
      }
      highestKey = key;
      //printf("GOT %i %i\n", key, item);
      TreeAppend(tree, key, item);
    }

    /* Set keys for non-leaf nodes */
    //NodeVisitDFS(&SetKeysVisitor, top);

    /* Write memory to file */
    assert(mem[sz] == 123);
    fprintf(stderr, "MEM: %i of %i allocated was used\n", memLast, memSize);
    FILE *f = fopen(outbfile, "wb");
    if (!f) {
      fprintf(stderr, "ERROR: Failed to open file %s for writing\n", outbfile);
      return -9;
    }
    int res = fwrite(mem, 1, memLast, f);
    if (res != memLast) {
      fprintf(stderr, "ERROR: Could not write all data to file %s\n", outbfile);
      return -4;
    }
    fclose(f);
  } // end of "create" command

  if (!strcmp(argv[1], "search")) {
    if (argc < 4) {
      fprintf(stderr, "ERROR: search usage incorrect, not enough arguments\n");
      return -11;
    }
    FILE *blobfile = 0x0;
    if (argc > 4) {
      blobfile = fopen(argv[4],"rb");
      if (!blobfile) {
        fprintf(stderr, "ERROR: failed to open Blob File %s\n", argv[4]);
        return -19;
      }
    }
    char *schema=0x0;
    if (argc > 5) {
      schema = argv[5];
    }

    char *inbfile = argv[2];
    KeyT key;
    int res;
    if (argv[3][0] == 'S') {
      key = CalcCRC(&argv[3][1], strlen(&argv[3][1]));
      //fprintf(stderr, "CRC32=%x for %s len=%i\n", key, &argv[3][1], (int) strlen(&argv[3][1]));
      printf("%x", key);
	if (mem)
    		free(mem);
	exit(0);
    } else { // assume hex
      res = sscanf(argv[3], "%x", &key);
      if (res != 1) {
        fprintf(stderr, "ERROR: Unable to parse query key argument %s\n", argv[3]);
        return -12;
      }
    }

    if (LoadBGT(inbfile) != 0) 
      return -99;

    /* Perform Search */
    BAT outParent;
    int outIndex;
    BAT found_temp;
    BAT found = FindInternal(0, key, &outParent, &outIndex);
    while (found != BAInvalid) {
	
//    if (found == BAInvalid) {
  //    printf("%x NOT FOUND!\n", key);
 //   } else {
      //printf("%x\t%08x", key, found);
      if (schema && blobfile) {
        for (char *p = &schema[0]; *p; ++p) {
          if ((*p == 's') || (*p == 'K')) {
            char buf[2000000];
            fseek(blobfile, found, SEEK_SET);
            int sz = UnpackStringFromFile(blobfile, buf, 2000000);
            if (sz < 0) {
              fprintf(stderr, "ERROR: Failed to read String from blob file\n");
              return -20;
            }
            found += sz;
            buf[sz] = 0x0; // not null terminated by default
            printf("\t%s", buf);

          } else if (*p == 'i') {
            int32_t v;
            fseek(blobfile, found, SEEK_SET);
            v = UnpackIntFromFile(blobfile);
            ERRORassert();
            found += 4;
            //printf("\t%i", v);
          } else if ((*p == 'I') || (*p == 'x') || (*p == 'X')) {
            uint32_t v;
            fseek(blobfile, found, SEEK_SET);
            v = UnpackUIntFromFile(blobfile);
            ERRORassert();
            //if (*p == 'I')
             // printf("\t%u", v);
            //else
             // printf("\t%x", v);
            found += 4;
          } else {
            fprintf(stderr, "ERROR: Unsupported schema character '%c'\n", *p);
            return -23;
          }

        }
      }
      printf("\n");
//	found_temp = NodeNextLeaf(NodeParent(found), found);
	//found_temp = FindInternal(0, key, &outParent, &outIndex);
	key++;
	found_temp = FindInternal(0, key, &outParent, &outIndex);
	found = found_temp;
	
    }
    if (blobfile)
      fclose(blobfile);
  } else if (!strcmp(argv[1],"printtree")) {
    if (LoadBGT(argv[2]) != 0) {
      printf("Error Loading BGT\n");
      return -99;
    }
    BgTree dummy;
    TreeInit(&dummy,0x0);
    NodeVisitDFS(dummy, &PrintVisitor, 0);
  }
  if (mem)
    free(mem);
}