Esempio n. 1
0
/**
 * Check that writing an Root PDU to an output stream works
 */
void RootPDUTest::testSimpleRootPDUToOutputStream() {
  CID cid = CID::Generate();
  RootPDU pdu1(TEST_VECTOR, cid, NULL);
  OLA_ASSERT(cid == pdu1.Cid());

  OLA_ASSERT_EQ(16u, pdu1.HeaderSize());
  OLA_ASSERT_EQ(4u, pdu1.VectorSize());
  OLA_ASSERT_EQ(0u, pdu1.DataSize());
  OLA_ASSERT_EQ(22u, pdu1.Size());

  IOQueue output;
  OutputStream stream(&output);
  pdu1.Write(&stream);

  OLA_ASSERT_EQ(22u, output.Size());

  uint8_t *raw_pdu = new uint8_t[output.Size()];
  unsigned int raw_pdu_size = output.Peek(raw_pdu, output.Size());
  OLA_ASSERT_EQ(output.Size(), raw_pdu_size);

  uint8_t EXPECTED[] = {
    0x70, 22,
    0, 0, 0, 4,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  };
  cid.Pack(EXPECTED + 6);
  ASSERT_DATA_EQUALS(__LINE__,
                     EXPECTED, sizeof(EXPECTED),
                     raw_pdu, raw_pdu_size);

  output.Pop(output.Size());
  delete[] raw_pdu;
}
Esempio n. 2
0
/*
 * Check that ToString works.
 */
void CIDTest::testToString() {
  CID cid = CID::FromData(TEST_DATA);
  string cid_str = cid.ToString();
  transform(cid_str.begin(), cid_str.end(), cid_str.begin(), toupper);
  OLA_ASSERT_EQ(string("00010203-0405-0607-0809-0A0B0C0D0E0F"),
                       cid_str);
}
Esempio n. 3
0
	/*
	 * Generates UDP key for specified IP address
	 */
	CID Utils::getUdpKey(const string& targetIp)
	{
		CID myUdpKey = CID(SETTING(DHT_KEY));

		TigerTree th;
		th.update(myUdpKey.data(), sizeof(CID));
		th.update(targetIp.c_str(), targetIp.size());
		return CID(th.finalize());
	}
Esempio n. 4
0
	CID Utils::getDistance(const CID& cid1, const CID& cid2)
	{
		uint8_t distance[CID::SIZE];

		for(int i = 0; i < CID::SIZE; i++)
		{
			distance[i] = cid1.data()[i] ^ cid2.data()[i];
		}

		return CID(distance);
	}
Esempio n. 5
0
/*
 * Check that from string works.
 */
void CIDTest::testFromString() {
  const string uuid = "00010203-0405-0607-0809-0A0B0C0D0E0F";
  CID cid = CID::FromString(uuid);
  string cid_str = cid.ToString();
  transform(cid_str.begin(), cid_str.end(), cid_str.begin(), toupper);
  OLA_ASSERT_EQ(uuid, cid_str);

  const string bad_uuid = "foo";
  cid = CID::FromString(bad_uuid);
  OLA_ASSERT(cid.IsNil());
}
Esempio n. 6
0
/**
 * Check writing to an OutputBuffer works.
 */
void CIDTest::testToOutputBuffer() {
  ola::io::IOQueue output;
  const string uuid = "00010203-0405-0607-0809-0A0B0C0D0E0F";
  CID cid = CID::FromString(uuid);

  cid.Write(&output);
  OLA_ASSERT_EQ(16u, output.Size());
  unsigned int size = output.Size();
  uint8_t cid_data[size];
  OLA_ASSERT_EQ(size, output.Read(cid_data, size));

  ASSERT_DATA_EQUALS(__LINE__, TEST_DATA, sizeof(TEST_DATA),
                     cid_data, size);
}
Esempio n. 7
0
/*
 * Check that basic assignment & equality works
 */
void CIDTest::testCID() {
  CID cid;
  OLA_ASSERT(cid.IsNil());

  CID cid1 = CID::Generate();
  OLA_ASSERT_FALSE(cid1.IsNil());

  CID cid2 = cid1;
  OLA_ASSERT(cid2 == cid1);
  OLA_ASSERT_FALSE(cid2.IsNil());

  CID cid3;
  cid3 = cid1;
  OLA_ASSERT(cid3 == cid1);
  OLA_ASSERT_FALSE(cid3.IsNil());
}
Esempio n. 8
0
UserPtr DirectoryListing::getUserFromFilename(const string& fileName)
{
	// General file list name format: [username].[CID].[xml|xml.bz2]
	
	string name = Util::getFileName(fileName);
	string ext = Text::toLower(Util::getFileExt(name));
	
	if (ext == ".dcls" || ext == ".dclst")  // [+] IRainman dclst support
	{
		auto l_user = std::make_shared<User>(CID(), name, 0);
		return l_user;
	}
	
	// Strip off any extensions
	if (ext == ".bz2")
	{
		name.erase(name.length() - 4);
		ext = Text::toLower(Util::getFileExt(name));
	}
	
	if (ext == ".xml")
	{
		name.erase(name.length() - 4);
	}
	// Find CID
	string::size_type i = name.rfind('.');
	if (i == string::npos)
	{
		return ClientManager::getUser(name, "Unknown Hub", 0);
	}
	
	size_t n = name.length() - (i + 1);
	// CID's always 39 chars long...
	if (n != 39)
	{
		return ClientManager::getUser(name, "Unknown Hub", 0);
	}
	
	const CID cid(name.substr(i + 1));
	if (cid.isZero())
	{
		return ClientManager::getUser(name, "Unknown Hub", 0);
	}
	
	UserPtr u = ClientManager::createUser(cid, name.substr(0, i), 0);
	return u;
}
Esempio n. 9
0
string AdcCommand::getHeaderString(const CID& cid) const {
	dcassert(type == TYPE_UDP);
	string tmp;

	tmp += getType();
	tmp += cmdChar;
	tmp += ' ';
	tmp += cid.toBase32();
	return tmp;
}
Esempio n. 10
0
ErrorCode ComponentManager::AddService( CID cid, ISupports *service )
{
	TRACE_BEGIN( LOG_LVL_INFO );
	ClassInfo *info = jh_new ClassInfo( cid, service );
	
	LOG( "Adding cid %s, ISupports %p", cid.toString(), service );
	
	service->AddRef();
	
	mClasses.push_back( info );
	
	return kNoError;
}
Esempio n. 11
0
/*
 * Test that packing a RootPDU with nested data works
 */
void RootPDUTest::testNestedRootPDUToOutputStream() {
  FakePDU pdu1(1);
  FakePDU pdu2(42);
  PDUBlock<PDU> block;
  block.AddPDU(&pdu1);
  block.AddPDU(&pdu2);

  CID cid = CID::Generate();
  RootPDU pdu(TEST_VECTOR, cid, &block);

  OLA_ASSERT(cid == pdu.Cid());
  OLA_ASSERT_EQ(30u, pdu.Size());

  IOQueue output;
  OutputStream stream(&output);
  pdu.Write(&stream);
  OLA_ASSERT_EQ(30u, output.Size());

  uint8_t *raw_pdu = new uint8_t[output.Size()];
  unsigned int raw_pdu_size = output.Peek(raw_pdu, output.Size());
  OLA_ASSERT_EQ(output.Size(), raw_pdu_size);

  uint8_t EXPECTED[] = {
    0x70, 30,
    0, 0, 0, 4,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 1,
    0, 0, 0, 42
  };
  cid.Pack(EXPECTED + 6);
  ASSERT_DATA_EQUALS(__LINE__,
                     EXPECTED, sizeof(EXPECTED),
                     raw_pdu, raw_pdu_size);

  output.Pop(output.Size());
  delete[] raw_pdu;
}
Esempio n. 12
0
StringList ClientManager::getNicks(const CID& cid) const {
	Lock l(cs);
	StringSet nicks;
	OnlinePairC op = onlineUsers.equal_range(cid);
	for(OnlineIterC i = op.first; i != op.second; ++i) {
		nicks.insert(i->second->getIdentity().getNick());
	}
	if(nicks.empty()) {
		// Offline perhaps?
		UserMap::const_iterator i = users.find(cid);
		if(i != users.end() && !i->second->getFirstNick().empty()) {
			nicks.insert(i->second->getFirstNick());
		} else {
			nicks.insert('{' + cid.toBase32() + '}');
		}
	}
	return StringList(nicks.begin(), nicks.end());
}
Esempio n. 13
0
CID::CID(CID const& other)
: TypeBase(other.GetNode())
{
}
Esempio n. 14
0
/*
 * Load the plugin prefs and default to sensible values
 *
 */
bool E131Plugin::SetDefaultPreferences() {
  if (!m_preferences)
    return false;

  bool save = false;

  CID cid = CID::FromString(m_preferences->GetValue(CID_KEY));
  if (cid.IsNil()) {
    cid = CID::Generate();
    m_preferences->SetValue(CID_KEY, cid.ToString());
    save = true;
  }

  save |= m_preferences->SetDefaultValue(
      DSCP_KEY,
      UIntValidator(0, 63),
      DEFAULT_DSCP_VALUE);

  save |= m_preferences->SetDefaultValue(
      DRAFT_DISCOVERY_KEY,
      BoolValidator(),
      BoolValidator::DISABLED);

  save |= m_preferences->SetDefaultValue(
      IGNORE_PREVIEW_DATA_KEY,
      BoolValidator(),
      BoolValidator::ENABLED);

  save |= m_preferences->SetDefaultValue(
      INPUT_PORT_COUNT_KEY,
      UIntValidator(0, 128),
      DEFAULT_PORT_COUNT);

  save |= m_preferences->SetDefaultValue(
      OUTPUT_PORT_COUNT_KEY,
      UIntValidator(0, 128),
      DEFAULT_PORT_COUNT);

  save |= m_preferences->SetDefaultValue(IP_KEY, StringValidator(true), "");

  save |= m_preferences->SetDefaultValue(
      PREPEND_HOSTNAME_KEY,
      BoolValidator(),
      BoolValidator::ENABLED);

  std::set<string> revision_values;
  revision_values.insert(REVISION_0_2);
  revision_values.insert(REVISION_0_46);

  save |= m_preferences->SetDefaultValue(
      REVISION_KEY,
      SetValidator<string>(revision_values),
      REVISION_0_46);

  if (save)
    m_preferences->Save();

  // check if this saved correctly
  // we don't want to use it if null
  string revision = m_preferences->GetValue(REVISION_KEY);
  if (m_preferences->GetValue(CID_KEY).empty() ||
      (revision != REVISION_0_2 && revision != REVISION_0_46))
    return false;

  return true;
}
Esempio n. 15
0
void CIDTest::testSetPack() {
  uint8_t buffer[CID::CID_LENGTH];
  CID cid = CID::FromData(TEST_DATA);
  cid.Pack(buffer);
  OLA_ASSERT_FALSE(memcmp(TEST_DATA, buffer, CID::CID_LENGTH));
}
Esempio n. 16
0
string ClientManager::getOfflineNick(const CID& cid) const {
	auto i = nicks.find(cid);
	return i != nicks.end() ? i->second.first : '{' + cid.toBase32() + '}';
}