Esempio n. 1
0
void DNSServer::create_dns_packet(const dnsreq& req, StringBuilder& sb)
{
	dnshdr hdr;
	hdr.transaction_id = req.transaction_id;
	hdr.flags = htons(req.flags);
	hdr.additional_rr = hdr.authority_rr = htons(0);
	hdr.queries = htons(req.queries.size());
	hdr.answers = htons(req.answers.size());
	sb.Append((char*) &hdr, sizeof(hdr));
	int i, offset = sizeof(hdr);
	UShort queries[req.queries.size()];
	for (i = 0; i < (int) req.queries.size(); i++)
	{
		queries[i] = offset;
		offset += write_dns_name(req.queries[i].q, sb);
		dnshdr_q hdr1
		{ htons(req.queries[i].type), htons(req.queries[i].cls) };
		sb.Append((char*) &hdr1, sizeof(hdr1));
		offset += sizeof(hdr1);
	}
	for (i = 0; i < (int) req.answers.size(); i++)
	{
		if (req.answers[i].query_index >= (int) req.queries.size())
			continue;
		dnshdr_a hdr1
		{ (UShort) (htons(queries[req.answers[i].query_index] | dns_offset_mask)), htons(
				req.answers[i].type), htons(req.answers[i].cls), htonl(req.answers[i].ttl), htons(
				req.answers[i].addr.Length) };
		sb.Append((char*) &hdr1, sizeof(hdr1));
		sb.Append(req.answers[i].addr);
	}
}
Esempio n. 2
0
int DNSServer::write_dns_name(const string& name, StringBuilder& sb)
{
	const char* ch = name.data();
	int len = name.length();
	int i = 0;
	int last_i = 0;
	int ret = 0;
	while (i < len)
	{
		if (ch[i] == '.')
		{
			sb.Append((char) (i - last_i));
			sb.Append(ch + last_i, i - last_i);
			ret += 1 + (i - last_i);
			last_i = i + 1;
		}
		i++;
	}
	if (last_i < len)
	{
		sb.Append((char) (len - last_i));
		sb.Append(ch + last_i, len - last_i);
		ret += 1 + (len - last_i);
	}
	sb.Append((char) 0);
	return ret;
}
Esempio n. 3
0
ECode ContentProvider::RejectQuery(
    /* [in] */ IUri* uri,
    /* [in] */ ArrayOf<String>* projection,
    /* [in] */ const String& selection,
    /* [in] */ ArrayOf<String>* selectionArgs,
    /* [in] */ const String& sortOrder,
    /* [in] */ ICancellationSignal* cancellationSignal,
    /* [out] */ ICursor** cursor)
{
    StringBuilder sb;
    // The read is not allowed...  to fake it out, we replace the given
    // selection statement with a dummy one that will always be FALSE.
    // This way we will get a cursor back that has the correct structure
    // but contains no rows.
    if (selection.IsNullOrEmpty()) {
        sb.Append("'A' = 'B'");
    }
    else {
        sb.Append("'A' = 'B' AND (");
        sb.Append(selection);
        sb.Append(")");
    }
    return Query(uri, projection, selection, selectionArgs,
        sortOrder, cancellationSignal, cursor);
}
Esempio n. 4
0
ECode Rfc822Token::ToString(
    /* [out] */ String* str)
{
    VALIDATE_NOT_NULL(str)
    StringBuilder sb;

    if (!mName.IsNullOrEmpty()) {
        String qn;
        QuoteNameIfNecessary(mName, &qn);
        sb.Append(qn);
        sb.AppendChar(' ');
    }

    if (!mComment.IsNullOrEmpty()) {
            sb.AppendChar('(');
            String qn;
            QuoteComment(mComment, &qn);
            sb.Append(qn);
            sb.Append(") ");
    }

    if (!mAddress.IsNullOrEmpty()) {
        sb.AppendChar('<');
        sb.Append(mAddress);
        sb.AppendChar('>');
    }

    *str = sb.ToString();
    return NOERROR;
}
Esempio n. 5
0
 bool test()
 {
   StringBuilder sb;
   sb.Append("asdfg");
   bool t1 = sb.Length() == 5;
   sb.Append("qwert");
   bool t2 = sb.Length() == 10;
   return (t1 && t2);
 }
Esempio n. 6
0
CString FileSystem::MakeCanonicalPath(const char* path)
{
	int len = strlen(path);

	if (!strncmp("\\\\?\\", path, 4) || len == 0)
	{
		return path;
	}

	std::vector<CString> components = Util::SplitStr(path, "\\/");
	for (uint32 i = 1; i < components.size(); i++)
	{
		if (!strcmp(components[i], ".."))
		{
			components.erase(components.begin() + i - 1, components.begin() + i + 1);
			i -= 2;
		}
		else if (!strcmp(components[i], "."))
		{
			components.erase(components.begin() + i);
			i--;
		}
	}

	StringBuilder result;
	result.Reserve(strlen(path));

	if (!strncmp("\\\\", path, 2))
	{
		result.Append("\\\\");
	}

	bool first = true;
	for (CString& comp : components)
	{
		if (comp.Length() > 0)
		{
			if (!first)
			{
				result.Append("\\");
			}
			result.Append(comp);
			first = false;
		}
	}

	if ((path[len - 1] == '\\' || path[len - 1] == '/' ||
		(len > 3 && !strcmp(path + len - 3, "\\..")) ||
		(len > 2 && !strcmp(path + len - 2, "\\.")))
		&&
		result[result.Length() - 1] != '\\')
	{
		result.Append("\\");
	}

	return *result;
}
Esempio n. 7
0
 bool test()
 {
   StringBuilder sb;
   sb.Append("This is a test.");
   sb.Clear();
   sb.Append("That");
   String s = *sb.ToString();
   return (s == "That");
 }
Esempio n. 8
0
ECode PhoneAccountHandle::ToString(
    /* [out] */ String* result)
{
    VALIDATE_NOT_NULL(result)
    StringBuilder sb;
    sb.Append(mComponentName);
    sb.Append(", ");
    sb.Append(mId);
    return sb.ToString(result);
}
Esempio n. 9
0
ECode CSizeF::ToString(
    /* [out] */ String* str)
{
    VALIDATE_NOT_NULL(str)
    StringBuilder sb;
    sb.Append(mWidth);
    sb.Append("x");
    sb.Append(mHeight);
    *str = sb.ToString();
    return NOERROR;
}
ECode CCellSignalStrengthGsm::ToString(
    /* [out] */ String* str)
{
    VALIDATE_NOT_NULL(str);
    StringBuilder sb;

    sb.Append("CellSignalStrengthGsm:");
    sb.Append(" ss="); sb.Append(mSignalStrength);
    sb.Append(" ber="); sb.Append(mBitErrorRate);
    *str = sb.ToString();
    return NOERROR;
}
Esempio n. 11
0
ECode CAuthState::ToString(
    /* [out] */ String* str)
{
    VALIDATE_NOT_NULL(str)
    StringBuilder buffer;
    buffer.Append("auth scope [");
    buffer.Append(mAuthScope);
    buffer.Append("]; credentials set [");
    buffer.Append(mCredentials != NULL ? "true" : "false");
    buffer.Append("]");
    *str = buffer.ToString();
    return NOERROR;
}
Esempio n. 12
0
String DateUtils::WriteDateTime(
    /* [in] */ ICalendar* cal,
    /* [in] */ Boolean zulu)
{
    StringBuilder sb;
    sb.EnsureCapacity(16);
    if (zulu) {
        sb.Append("               Z");    //Java:    sb.setLength(16);    sb.setCharAt(15, 'Z');
    }
    else {
        sb.Append("               ");//Java:    sb.setLength(15);
    }
    String strTemp = sb.ToString();
    return WriteDateTime(cal, &strTemp);
}
Esempio n. 13
0
 bool test()
 {
   StringBuilder sb;
   sb.Append("That is a test");
   int result = sb.IndexOf("is");
   return (result == 5);
 }
Esempio n. 14
0
 bool test()
 {
   StringBuilder sb;
   sb.Append("asdfgqwert");
   sb.Remove(5, 10);
   return (*sb.ToString() == "asdfg");
 }
Esempio n. 15
0
 bool test()
 {
   StringBuilder sb;
   sb.Append("qwerty asdfgh");
   SmartPointer<String> s = sb.Substring(1, 5);
   return (*s == "wert");
 }
Esempio n. 16
0
 bool test()
 {
   StringBuilder sb;
   sb.Append("qwerty asdfgh");
   SmartPointer<String> s = sb.Substring(-2, -1);
   return (s.IsNull());
 }
Esempio n. 17
0
			String ToString(TArgs&& ... args)
			{
				StringBuilder builder;
				int callerArr[] = { 0, ((void)builder.Append(Forward<TArgs>(args)), 0) ... }; // Only the expressions using param pack in initializer list can be executed(compiled). As an optimization, this array will be omitted by compiler generally. The second 0 provides values of type [long] that satisfies the type of $callerArr. For more detail about the second 0, check out comma operator.

				return builder.ToString();
			}
Esempio n. 18
0
String EncodedStringValue::Concat(
    /* [in] */ ArrayOf<IEncodedStringValue*>* addr)
{
    StringBuilder sb;
    Int32 maxIndex = addr->GetLength() - 1;
    for (Int32 i = 0; i <= maxIndex; i++) {
        String str;
        (*addr)[i]->GetString(&str);
        sb.Append(str);
        if (i < maxIndex) {
            sb.Append(String(";"));
        }
    }

    return sb.ToString();
}
Esempio n. 19
0
 bool test()
 {
   StringBuilder sb;
   sb.Append("This is a test.");
   int result = sb.IndexOf("This is a test.");
   return (result == 0);
 }
Esempio n. 20
0
 bool test()
 {
   StringBuilder sb;
   sb.Append("a");
   sb.Remove(0, 1);
   return (*sb.ToString() == "");
 }
	// ------------------------------------------------------------------------------------------
	//! Generates a structure inside GLSL shader.
	//! @param Struct Structure object definition.
	//! @param Builder Output for the shader code.
	void GLSLGenerator::GenerateShaderStruct(HLSLStruct const* const Struct, StringBuilder& Builder)
	{
		Builder.AppendFormat("\n\nstruct %s\n{", Struct->Name.CStr());
		for (auto const& Definition : Struct->InnerDefinitions)
		{
			HLSLVariable const* const StructField = static_cast<HLSLVariable const*>(Definition);
			Builder.AppendFormat("\n\t%s %s", StructField->Type->Name.CStr(), StructField->Name.CStr());
			if (StructField->ArrayRank != 0)
			{
				// Adding array information for our field..
				Builder.AppendFormat("[%d]", static_cast<int>(StructField->ArrayRank));
			}
			Builder.Append(';');
		}
		Builder.Append("\n};");
	}
Esempio n. 22
0
 RF_Type::Bool ToString()
 {
     StringBuilder builder;
     builder.Append("hi");
     auto result = builder.ToString();
     return result->Size() == 3 && result->Length() == 2;
 }
	// ------------------------------------------------------------------------------------------
	//! Generates a structure inside GLSL shader.
	//! @param ConstantBuffer Constant buffer object definition.
	//! @param Builder Output for the shader code.
	//! @param SupportsConstantBuffers Boolean variable for the support of the uniform buffers.
	//! @param ShaderType Target type of the shader.
	void GLSLGenerator::GenerateShaderConstantBuffer(HLSLCBuffer const* const ConstantBuffer, StringBuilder& Builder, bool const SupportsConstantBuffers, IGraphicsShaderType const ShaderType)
	{
		if (ConstantBuffer->Register == nullptr)
		{
			throw GLSLCompilerErrorException("constant buffer '%s' does not contains meta information about register.", ConstantBuffer->Name.CStr());
		}

		if (SupportsConstantBuffers)
		{
			// This platform supports constant buffers, defining it.
			Builder.AppendFormat("\n\nlayout(std140, row_major, binding = %d) \nuniform %s \n{"
				, static_cast<int>(ConstantBuffer->Register->RegisterID) + static_cast<int>(ShaderType) * static_cast<int>(GD_HRI_SHADER_MAX_CBUFFERS_LOCATIONS)
				, ConstantBuffer->Name.CStr());
		}
		else
		{
			// Emulating behavior of the constant buffers through uniform variables.
			Builder.AppendFormat("\n\n// uniform %s {", ConstantBuffer->Name.CStr());
		}

		for (auto const& Definition : ConstantBuffer->InnerDefinitions)
		{
			auto const ConstantBufferField = static_cast<UniquePtr<HLSLVariable const>>(Definition);
			if (SupportsConstantBuffers)
			{
				// Emitting a field of the inform buffer.
				Builder.AppendFormat("\n\t%s %s", ConstantBufferField->Type->Name.CStr(), ConstantBufferField->Name.CStr());
			}
			else
			{
				// Emitting a standalone uniform variable.
				Builder.AppendFormat("\nlayout(row_major) \nuniform %s %s", ConstantBufferField->Type->Name.CStr(), ConstantBufferField->Name.CStr());
			}

			if (ConstantBufferField->ArrayRank != 0)
			{
				// Adding array information for our field..
				Builder.AppendFormat("[%d]", static_cast<int>(ConstantBufferField->ArrayRank));
			}
			Builder.Append(';');
		}

		if (SupportsConstantBuffers)
			Builder.Append("\n};");
		else
			Builder.AppendFormat("\n// }\t// uniform %s.", ConstantBuffer->Name.CStr());
	}
Esempio n. 24
0
 RF_Type::Bool Replace()
 {
     StringBuilder builder;
     builder.Append("Hello W!");
     builder.Replace("W", "World");
     return builder.Length() == 12 && builder.Size() == 13 &&
         builder.Capacity() >= 13 && builder.AsCString()[7] == 'o';
 }
Esempio n. 25
0
 RF_Type::Bool Remove()
 {
     StringBuilder builder;
     builder.Append("Hello World!");
     builder.Remove(6, 5);
     return builder.Length() == 7 && builder.Size() == 8 &&
         builder.Capacity() >= 8 && builder.AsCString()[6] == '!';
 }
Esempio n. 26
0
ECode BasicScheme::Authenticate(
    /* [in] */ ICredentials* credentials,
    /* [in] */ IHttpRequest* request,
    /* [in] */ Boolean proxy,
    /* [out] */ IHeader** header)
{
    VALIDATE_NOT_NULL(header)
    *header = NULL;

    if (credentials == NULL) {
        Logger::E("BasicScheme", "Credentials may not be null");
        return E_ILLEGAL_ARGUMENT_EXCEPTION;
    }
    if (request == NULL) {
        Logger::E("BasicScheme", "HTTP request may not be null");
        return E_ILLEGAL_ARGUMENT_EXCEPTION;
    }

    StringBuilder tmp;
    AutoPtr<IPrincipal> principal;
    credentials->GetUserPrincipal((IPrincipal**)&principal);
    String name;
    principal->GetName(&name);
    tmp.Append(name);
    tmp.Append(":");
    String password;
    credentials->GetPassword(&password);
    tmp.Append(password.IsNull() ? String("null") : password);

    AutoPtr< ArrayOf<Byte> > bytes;
    EncodingUtils::GetBytes(tmp.ToString(), charset, (ArrayOf<Byte>**)&bytes);
    AutoPtr< ArrayOf<Byte> > base64password = Base64::EncodeBase64(bytes);

    AutoPtr<ICharArrayBuffer> buffer;
    CCharArrayBuffer::New(32, (ICharArrayBuffer**)&buffer);
    if (proxy) {
        buffer->Append(IAUTH::PROXY_AUTH_RESP);
    }
    else {
        buffer->Append(IAUTH::WWW_AUTH_RESP);
    }
    buffer->Append(String(": Basic "));
    buffer->Append(base64password, 0, base64password->GetLength());

    return CBufferedHeader::New(buffer, header);
}
Esempio n. 27
0
 void ToString(StringBuilder &profile)
 {
   int readPos = mReadPos;
   while (readPos != mLastFlushPos) {
     profile.Append(mEntries[readPos].TagToString(this).c_str());
     readPos = (readPos + 1) % mEntrySize;
   }
 }
Esempio n. 28
0
ECode UriCodec::AppendHex(
    /* [in] */ StringBuilder& builder,
    /* [in] */ Byte b)
{
    builder.AppendChar('%');
    builder.Append(IntegralToString::ToHexString(b, TRUE));
    return NOERROR;
}
Esempio n. 29
0
ECode ImsPhoneConnection::ToString(
    /* [out] */ String* result)
{
    VALIDATE_NOT_NULL(result);
    StringBuilder sb;
    sb.Append("[ImsPhoneConnection objId: ");

    AutoPtr<ISystem> system;
    CSystem::AcquireSingleton((ISystem**)&system);
    Int32 val;
    system->IdentityHashCode(TO_IINTERFACE(this), &val);
    sb.Append(val);
    sb.Append(" address:");
    String str;
    GetAddress(&str);
// TODO: Need Log.pii
    // sb.Append(Log.pii(str));
    sb.Append(" ImsCall:");
    if (mImsCall == NULL) {
        sb.Append("NULL");
    } else {
        IObject::Probe(mImsCall)->ToString(&str);
        sb.Append(str);
    }
    sb.Append("]");
    return sb.ToString(result);
}
Esempio n. 30
0
 RF_Type::Bool Clear()
 {
     StringBuilder builder;
     builder.Append("test");
     RF_Type::Size capacity = builder.Capacity();
     builder.Clear();
     return builder.Capacity() == capacity && builder.Size() == 0 &&
         builder.Length() == 0;
 }