示例#1
0
		TITANIUM_FUNCTION(File, append)
		{
			const auto js_context = this_object.get_context();

			if (arguments.size() == 0) {
				return js_context.CreateUndefined();
			}
			auto _0 = arguments.at(0);

			if (_0.IsString()) {
				return js_context.CreateBoolean(append(static_cast<std::string>(arguments.at(0))));
			} else if (_0.IsObject()) {
				const auto js_object = static_cast<JSObject>(_0);
				const auto blob = js_object.GetPrivate<Titanium::Blob>();
				const auto file = js_object.GetPrivate<File>();
				if (blob != nullptr) {
					return js_context.CreateBoolean(append(blob));
				} else if (file != nullptr) {
					return js_context.CreateBoolean(append(file));
				}
			}
			return js_context.CreateNull();
		}
示例#2
0
void KeyPath::SerializeToString(nsAString& aString) const {
  NS_ASSERTION(IsValid(), "Check to see if I'm valid first!");

  if (IsString()) {
    aString = mStrings[0];
    return;
  }

  if (IsArray()) {
    // We use a comma in the beginning to indicate that it's an array of
    // key paths. This is to be able to tell a string-keypath from an
    // array-keypath which contains only one item.
    // It also makes serializing easier :-)
    uint32_t len = mStrings.Length();
    for (uint32_t i = 0; i < len; ++i) {
      aString.Append(',');
      aString.Append(mStrings[i]);
    }

    return;
  }

  MOZ_ASSERT_UNREACHABLE("What?");
}
示例#3
0
文件: JSON.cpp 项目: kolyden/mirror
template<> void Jsonize(JsonIO& io, double& var)
{
	if(io.IsLoading()) {
		const Value& v = io.Get();
		if(IsNull(v)) {
			var = Null;
			return;
		}
		if(IsNumber(v)) {
			var = io.Get();
			return;
		}
		if(IsString(v)) {
			double h = ScanDouble((String)v);
			if(!IsNull(h)) {
				var = h;
				return;
			}
		}
		throw JsonizeError("number expected");
	}
	else
		io.Set(var);
}
示例#4
0
nsresult
KeyPath::ExtractKeyAsJSVal(JSContext* aCx, const JS::Value& aValue,
                           JS::Value* aOutVal) const
{
    NS_ASSERTION(IsValid(), "This doesn't make sense!");

    if (IsString()) {
        return GetJSValFromKeyPathString(aCx, aValue, mStrings[0], aOutVal,
                                         DoNotCreateProperties, nullptr, nullptr);
    }

    const uint32_t len = mStrings.Length();
    JS::Rooted<JSObject*> arrayObj(aCx, JS_NewArrayObject(aCx, len));
    if (!arrayObj) {
        return NS_ERROR_OUT_OF_MEMORY;
    }

    JS::Rooted<JS::Value> value(aCx);
    for (uint32_t i = 0; i < len; ++i) {
        nsresult rv = GetJSValFromKeyPathString(aCx, aValue, mStrings[i],
                                                value.address(),
                                                DoNotCreateProperties, nullptr,
                                                nullptr);
        if (NS_FAILED(rv)) {
            return rv;
        }

        if (!JS_SetElement(aCx, arrayObj, i, value)) {
            IDB_REPORT_INTERNAL_ERR();
            return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
        }
    }

    *aOutVal = OBJECT_TO_JSVAL(arrayObj);
    return NS_OK;
}
示例#5
0
文件: json.cpp 项目: m0ppers/arangodb
bool TRI_ReplaceObjectJson (TRI_memory_zone_t* zone, 
                            TRI_json_t* object, 
                            char const* name, 
                            TRI_json_t const* replacement) {
  TRI_ASSERT(object->_type == TRI_JSON_OBJECT);
  TRI_ASSERT(name != nullptr);

  size_t const n = TRI_LengthVector(&object->_value._objects);

  for (size_t i = 0;  i < n;  i += 2) {
    TRI_json_t* key = static_cast<TRI_json_t*>(TRI_AtVector(&object->_value._objects, i));

    if (! IsString(key)) {
      continue;
    }

    if (TRI_EqualString(key->_value._string.data, name)) {
      // retrieve the old element
      TRI_json_t* old = static_cast<TRI_json_t*>(TRI_AtVector(&object->_value._objects, i + 1));

      if (old != nullptr) {
        TRI_DestroyJson(zone, old);
      }

      TRI_json_t copy;
      TRI_CopyToJson(zone, &copy, replacement);
      TRI_SetVector(&object->_value._objects, i + 1, &copy);
      return true;
    }
  }

  // object not found in array, now simply add it
  TRI_Insert2ObjectJson(zone, object, name, replacement);

  return false;
}
		TITANIUM_FUNCTION(DependencyProperty, RegisterAttached)
		{
			auto context = get_context();
			if (arguments.size() == 4) {
				auto _0 = arguments.at(0); 
			TITANIUM_ASSERT_AND_THROW(_0.IsString(), "Expected String");
			auto name = TitaniumWindows::Utility::ConvertUTF8String(static_cast<std::string>(_0));

				auto _1 = arguments.at(1);
			TITANIUM_ASSERT_AND_THROW(_1.IsObject(), "Expected Object");
			auto object_propertyType = static_cast<JSObject>(_1);
			::Windows::UI::Xaml::Interop::TypeName propertyType;
			// Assign fields explicitly since we didn't use a constructor

			auto object_propertyType_Name = object_propertyType.GetProperty("Name"); 
			TITANIUM_ASSERT_AND_THROW(object_propertyType_Name.IsString(), "Expected String");
			auto object_propertyType_Name_ = TitaniumWindows::Utility::ConvertUTF8String(static_cast<std::string>(object_propertyType_Name));

			propertyType.Name = object_propertyType_Name_;

			auto object_propertyType_Kind = object_propertyType.GetProperty("Kind");
			TITANIUM_ASSERT_AND_THROW(object_propertyType_Kind.IsNumber(), "Expected Number");
			auto object_propertyType_Kind_ = static_cast<::Windows::UI::Xaml::Interop::TypeKind>(static_cast<int32_t>(object_propertyType_Kind)); // TODO Look up enum in metadata to know what type it's value is? 

			propertyType.Kind = object_propertyType_Kind_;

				auto _2 = arguments.at(2);
			TITANIUM_ASSERT_AND_THROW(_2.IsObject(), "Expected Object");
			auto object_ownerType = static_cast<JSObject>(_2);
			::Windows::UI::Xaml::Interop::TypeName ownerType;
			// Assign fields explicitly since we didn't use a constructor

			auto object_ownerType_Name = object_ownerType.GetProperty("Name"); 
			TITANIUM_ASSERT_AND_THROW(object_ownerType_Name.IsString(), "Expected String");
			auto object_ownerType_Name_ = TitaniumWindows::Utility::ConvertUTF8String(static_cast<std::string>(object_ownerType_Name));

			ownerType.Name = object_ownerType_Name_;

			auto object_ownerType_Kind = object_ownerType.GetProperty("Kind");
			TITANIUM_ASSERT_AND_THROW(object_ownerType_Kind.IsNumber(), "Expected Number");
			auto object_ownerType_Kind_ = static_cast<::Windows::UI::Xaml::Interop::TypeKind>(static_cast<int32_t>(object_ownerType_Kind)); // TODO Look up enum in metadata to know what type it's value is? 

			ownerType.Kind = object_ownerType_Kind_;

				auto _3 = arguments.at(3);
			TITANIUM_ASSERT_AND_THROW(_3.IsObject(), "Expected Object");
			auto object_defaultMetadata = static_cast<JSObject>(_3);
 
			auto wrapper_defaultMetadata = object_defaultMetadata.GetPrivate<Windows::UI::Xaml::PropertyMetadata>();
			// FIXME What if the type we want here is some parent class of the actual wrapper's class? I think we'll get nullptr here.
			// We need some way to know the underlying type the JSObject maps to, get that, then cast to the type we want...
			auto defaultMetadata = wrapper_defaultMetadata->unwrapWindows_UI_Xaml_PropertyMetadata();

				auto method_result = ::Windows::UI::Xaml::DependencyProperty::RegisterAttached(name, propertyType, ownerType, defaultMetadata);

			auto result = context.CreateObject(JSExport<Windows::UI::Xaml::DependencyProperty>::Class());
			auto result_wrapper = result.GetPrivate<Windows::UI::Xaml::DependencyProperty>();
			result_wrapper->wrap(method_result);

				return result;
			}

			// Catch-all if no arg count matches!
			TITANIUM_LOG_DEBUG("No method signature matched DependencyProperty::RegisterAttached with # of args: ", arguments.size());
			return context.CreateUndefined(); 
		}
示例#7
0
void VisGenDlg::Refresh()
{
	String s;
	int q = ~type;
	bool b = q >= 3 && q <= 4;
	pars.Enable(b);
	brackets.Enable(b);
	label1.Enable(b);
	toupper1.Enable(b);
	tolower1.Enable(b);
	initcaps1.Enable(b);
	name1.Enable(b);
	dname1.Enable(b);
	quotes1.Enable(b && !label1);
	b = q == 4;
	label2.Enable(b);
	toupper2.Enable(b);
	tolower2.Enable(b);
	initcaps2.Enable(b);
	name2.Enable(b);
	dname2.Enable(b);
	quotes2.Enable(b && !label2);
	String oce = "\tCtrlLayout";
	bool ok = false;
	if(HasItem("ok")) {
		ok = true;
		oce << "OK";
	}
	if(HasItem("cancel"))
		oce << "Cancel";
	if(HasItem("exit"))
		oce << "Exit";
	String n = ~name;
	if(IsNull(n))
		n = GetName();
	
	String b1, b2, b3;
	if(buttons) {
		for(int i = 0; i < layout.item.GetCount(); i++) {
			String bn = layout.item[i].variable;
			if(layout.item[i].type == "Button" && findarg(bn, "cancel", "ok", "exit") < 0) {
				String mn = IdInitCaps(bn);
				mn.Replace("_", "");
				if(b1.GetCount() == 0)
					b1 = b2 = "\n";
				b1 << '\t' << "void " << mn << "();\n";
				b2 << '\t' << bn << " << [=] { " << mn << "};\n";
				b3 << '\n' << "void " << n << "::" << mn << "()\n{\n}\n";
			}
		}
	}

	if(q == 0) {
		s << "class " << n << " : public With" << layout.name << "<TopWindow> {\n"
		  << "\ttypedef " << n << " CLASSNAME;\n"
		  << b1
		  << "\n"
		  << "public:\n"
		  << "\t" << n << "();\n"
		  << "};\n"
		  << "\n"
		  << n << "::" << n << "()\n"
		  << "{\n"
		  << oce << "(*this, \"\");\n"
		  << b2
		  << "}\n"
		  << b3;
	}
	else
	if(q == 1) {
		s << "struct " << n << " : With" << layout.name << "<TopWindow> {\n"
		  << "\ttypedef " << n << " CLASSNAME;\n"
		  << b1
		  << "\t" << n << "();\n"
		  << "};\n"
		  << "\n"
		  << n << "::" << n << "()\n"
		  << "{\n"
		  << oce << "(*this, \"\");\n"
		  << b2
		  << "}\n"
		  << b3;
	}
	else
	if(q == 2) {
		String n = ~name;
		if(IsNull(n))
			n = "dlg";
		s << "\tWith" << layout.name << "<TopWindow> " << n << ";\n"
		  << oce << '(' << n << ", \"\");\n";
		if(ok)
			s << "\tif(" << n << ".Execute() != IDOK)\n\t\treturn;\n";
		else
			s << '\t' << n << ".Execute();\n";
	}
	else
		for(int i = 0; i < sel.GetCount(); i++) {
			String id1 = layout.item[sel[i]].variable;
			String id2 = id1;
			int w = layout.item[sel[i]].FindProperty("SetLabel");
			String lbl;
			if(w >= 0 && IsString(~layout.item[sel[i]].property[w]))
				lbl = AsCString(ToUtf8((WString)~layout.item[sel[i]].property[w]));
			if(q <= 4) {
				if(label1)
					id1 = lbl;
				if(label2)
					id2 = lbl;
			}
			if(IsNull(id1) && (q != 4 || IsNull(id2)))
				continue;
			if(q == 5)
				s << "\t" << id1 << " << [=] { };\n";
			else
			if(q == 6)
				s << "\t" << IdInitCaps(id1) << "();\n";
			else
			if(q == 7)
				s << "\t" << id1 << " << [=] { " << IdInitCaps(id1) << "(); };\n";
			else {
				if((pars || brackets) && !(name1 || name2 || dname1 || dname2))
					s << ~name;
				if(pars)
					s << '(';
				String ss;
				if(name1 && !IsNull(~name))
					s << ~name << '.';
				if(toupper1)
					ss << ToUpper(id1);
				else
				if(tolower1)
					ss << ToLower(id1);
				else
				if(initcaps1)
					ss << IdInitCaps(id1);
				else
					ss << id1;
				if(quotes1 && !label1)
					ss = AsCString(ss);
				if(dname1 && !IsNull(~name))
					ss << '.' << ~name;
				if(brackets)
					s << '[';
				s << ss;
				if(brackets)
					s << ']';
				if(q == 4) {
					s << ", ";
					String ss;
					if(name2 && !IsNull(~name))
						ss << ~name << '.';
					if(toupper2)
						ss << ToUpper(id2);
					if(tolower2)
						ss << ToLower(id2);
					else
					if(initcaps2)
						ss << IdInitCaps(id2);
					else
						ss << id2;
					if(quotes2 && !label2)
						ss = AsCString(ss);
					if(dname2 && !IsNull(~name))
						ss << '.' << ~name;
					if(brackets)
						s << '[';
					s << ss;
					if(brackets)
						s << ']';
				}
				if(pars)
					s << ')';
				s << '\n';
			}
		}
	view <<= s;
}
const CPDF_String* CPDF_Object::AsString() const {
  return IsString() ? static_cast<const CPDF_String*>(this) : nullptr;
}
static int
p_text_to_string(value v, type t, value vs, type ts)
{
    pword	*pw, *list;
    char	*s;
    int		len;
    pword	*old_tg = Gbl_Tg;

    if (IsRef(t))
    {
	Bip_Error(PDELAY_1);
    }

    if (IsString(t))
    {
	Kill_DE;
	Return_Unify_Pw(v, t, vs, ts);
    }

    if (IsAtom(t))	/* not including [] ! */
    {
	Kill_DE;
	Return_Unify_String(vs, ts, DidString(v.did));
    }

    if (IsNil(t))
    {
	Kill_DE;
	Return_Unify_String(vs, ts, empty_string);
    }

    if (IsList(t))		/* make a string from a list	*/
    {
	int element_type = 0;
	list = v.ptr;		/* space for the string header	*/
	Push_Buffer(1);		/* make minimum buffer		*/
	s = (char *) BufferStart(old_tg);	/* start of the new string */
	for(;;)			/* loop through the list	*/
	{
	    int c;
	    pw = list++;
	    Dereference_(pw);		/* get the list element	*/
	    if (IsRef(pw->tag))		/* check it		*/
	    {
		Gbl_Tg = old_tg;
		Push_var_delay(vs.ptr, ts.all);
		Push_var_delay(pw, pw->tag.all);
		Bip_Error(PDELAY);
	    }
	    else if (IsInteger(pw->tag))	/* char code */
	    {
		element_type |= 1;
		c = pw->val.nint;
		if (c < 0 || 255 < c)
		{
		    Gbl_Tg = old_tg;
		    Bip_Error(RANGE_ERROR);
		}
	    }
	    else if (IsAtom(pw->tag))		/* char atom */
	    {
		element_type |= 2;
		if (DidLength(pw->val.did) != 1)
		{
		    Gbl_Tg = old_tg;
		    Bip_Error(RANGE_ERROR);
		}
		c = DidName(pw->val.did)[0];
	    }
	    else
	    {
		Gbl_Tg = old_tg;
		Bip_Error(TYPE_ERROR);
	    }
	    *s++ = c;
	    if (s == (char *) Gbl_Tg)	/* we need another pword */
	    {
		Gbl_Tg += 1;
		Check_Gc;
	    }
	    Dereference_(list);		/* get the list tail	*/
	    if (IsRef(list->tag))
	    {
		Gbl_Tg = old_tg;
		Push_var_delay(vs.ptr, ts.all);
		Push_var_delay(list, list->tag.all);
		Bip_Error(PDELAY);
	    }
	    else if (IsList(list->tag))
		list = list->val.ptr;
	    else if (IsNil(list->tag))
		break;			/* end of the list	*/
	    else
	    {
		Gbl_Tg = old_tg;
		Bip_Error(TYPE_ERROR);
	    }
	}
	if (element_type != 1 && element_type != 2)	/* mixed type list? */
	{
	    Gbl_Tg = old_tg;
	    Bip_Error(TYPE_ERROR);
	}
	*s = '\0';			/* terminate the string		*/
	Set_Buffer_Size(old_tg, s - (char *)(old_tg + 1) + 1);
	Kill_DE;
	Return_Unify_String(vs, ts, old_tg);
    }

    Bip_Error(TYPE_ERROR);
}
示例#10
0
String RichPNG::GetTypeName(const Value& v) const
{
	return IsString(v) ? "PNG" : "image";
}
示例#11
0
bool TFunctionScanner::ReadFunctionBody(const TChar*& text)
{
	bool result = false;
	SkipWhiteSpace(text);
	
	if (*text == ':')
	{
		// special case constructors
		NextChar(text);
		SkipWhiteSpace(text);
		
		while (*text != '{')
		{
			if (IsString(text))
				SkipString(text);
			else if (IsComment(text))
				SkipComment(text);
			else
				NextChar(text);
		}
	}
	else 
	{
		// skip "const", "throws", etc.
		// also handle K&R style function definitions
		
		while (isalnum(*text) || *text == '_')
		{
			while (isalnum(*text) || *text == '_')
				NextChar(text);
				
			SkipWhiteSpace(text);
			
			// for K&R support (pointer, function and array type arguments) 
			while (*text == '*' || *text == ';' || *text == ',' || 
				   *text == '[' || *text == ']' || *text == '(' || *text == ')')
			{
				NextChar(text);
				SkipWhiteSpace(text);
			}
		}
	}
		
	if (*text == '{')
	{
		NextChar(text);
		int bracketDepth = 1;
		
		while (bracketDepth > 0)
		{
			// need to do this to process comments correctly
			SkipWhiteSpace(text);
			
			TChar ch = *text;
			
			if (IsString(text))
			{
				SkipString(text);
				continue;	// don't call NextChar() since SkipString() already did
			}
			else if (ch == '{')
				++bracketDepth;
			else if (ch == '}')
				--bracketDepth;
			
			NextChar(text);
		}
		
		result = true;
	}
	else if (*text != ';')
		NextChar(text);
	
	fScanState = kTopLevel;
	return result;
}
示例#12
0
    void Endpoint::parseCert(const rapidjson::GenericValue<rapidjson::UTF8<char>,
            rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator>>::ConstObject &obj, labsCert_t &labsCert) {

        if (obj.HasMember("subject") && obj["subject"].IsString()) {
            labsCert.Subject.assign(obj["subject"].GetString());
        }

        if (obj.HasMember("commonNames") && obj["commonNames"].IsArray()) {
            for (auto itr = obj["commonNames"].GetArray().Begin(); itr != obj["commonNames"].GetArray().End(); itr++) {
                if (itr->IsString()) {
                    labsCert.CommonNames.push_back(itr->GetString());
                }
            }
        }

        if (obj.HasMember("altNames") && obj["altNames"].IsArray()) {
            for (auto itr = obj["altNames"].GetArray().Begin(); itr != obj["altNames"].GetArray().End(); itr++) {
                if (itr->IsString()) {
                    labsCert.AltNames.push_back(itr->GetString());
                }
            }
        }

        if (obj.HasMember("notBefore") && obj["notBefore"].IsInt64()) {
            labsCert.NotBefore = obj["notBefore"].GetInt64();
        }

        if (obj.HasMember("notAfter") && obj["notAfter"].IsInt64()) {
            labsCert.NotAfter = obj["notAfter"].GetInt64();
        }

        if (obj.HasMember("issuerSubject") && obj["issuerSubject"].IsString()) {
            labsCert.IssuerSubject.assign(obj["issuerSubject"].GetString());
        }

        if (obj.HasMember("issuerLabel") && obj["issuerLabel"].IsString()) {
            labsCert.IssuerLabel.assign(obj["issuerLabel"].GetString());
        }

        if (obj.HasMember("sigAlg") && obj["sigAlg"].IsString()) {
            labsCert.SigAlg.assign(obj["sigAlg"].GetString());
        }

        if (obj.HasMember("revocationInfo") && obj["revocationInfo"].IsInt()) {
            labsCert.RevocationInfo = obj["revocationInfo"].GetInt();
        }

        if (obj.HasMember("crlURIs") && obj["crlURIs"].IsArray()) {
            for (auto itr = obj["crlURIs"].GetArray().Begin(); itr != obj["crlURIs"].GetArray().End(); itr++) {
                if (itr->IsString()) {
                    labsCert.CrlURIs.push_back(itr->GetString());
                }
            }
        }

        if (obj.HasMember("ocspURIs") && obj["ocspURIs"].IsArray()) {
            for (auto itr = obj["ocspURIs"].GetArray().Begin(); itr != obj["ocspURIs"].GetArray().End(); itr++) {
                if (itr->IsString()) {
                    labsCert.OcspURIs.push_back(itr->GetString());
                }
            }
        }

        if (obj.HasMember("revocationStatus") && obj["revocationStatus"].IsInt()) {
            labsCert.RevocationStatus = obj["revocationStatus"].GetInt();
        }

        if (obj.HasMember("crlRevocationStatus") && obj["crlRevocationStatus"].IsInt()) {
            labsCert.CrlRevocationStatus = obj["crlRevocationStatus"].GetInt();
        }

        if (obj.HasMember("ocspRevocationStatus") && obj["ocspRevocationStatus"].IsInt()) {
            labsCert.OcspRevocationStatus = obj["ocspRevocationStatus"].GetInt();
        }

        if (obj.HasMember("sgc") && obj["sgc"].IsInt()) {
            labsCert.Sgc = obj["sgc"].GetInt();
        }

        if (obj.HasMember("issues") && obj["issues"].IsInt()) {
            labsCert.Issues = obj["issues"].GetInt();
        }

        if (obj.HasMember("sct") && obj["sct"].IsBool()) {
            labsCert.Sct = obj["sct"].GetBool();
        }

        if (obj.HasMember("mustStaple") && obj["mustStaple"].IsInt()) {
            labsCert.MustStaple = obj["mustStaple"].GetInt();
        }

        if (obj.HasMember("sha1Hash") && obj["sha1Hash"].IsString()) {
            labsCert.Sha1Hash.assign(obj["sha1Hash"].GetString());
        }

        if (obj.HasMember("pinSha256") && obj["pinSha256"].IsString()) {
            labsCert.PinSha256.assign(obj["pinSha256"].GetString());
        }

    }
示例#13
0
    void Endpoint::parseEndpointDetails(const rapidjson::GenericValue<rapidjson::UTF8<char>,
            rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator>>::ConstObject & obj, labsEndpoint_t &endpoint) {

        if (obj.HasMember("hostStartTime") && obj["hostStartTime"].IsInt64()) {
            endpoint.Details.HostStartTime = obj["hostStartTime"].GetInt64();
        }

        if (obj.HasMember("key") && obj["key"].IsObject()) {
            Endpoint::parseKey(obj["key"].GetObject(), endpoint.Details.Key);
        }

        if (obj.HasMember("cert") && obj["cert"].IsObject()) {
            Endpoint::parseCert(obj["cert"].GetObject(), endpoint.Details.Cert);
        }

        if (obj.HasMember("chain") && obj["chain"].IsObject()) {
            Endpoint::parseChain(obj["chain"].GetObject(), endpoint.Details.Chain);
        }

        if (obj.HasMember("protocols") && obj["protocols"].IsArray()) {
            labsProtocol_t labsProtocol;

            for (auto itr = obj["protocols"].GetArray().Begin(); itr != obj["protocols"].GetArray().End(); itr++) {
                parseProtocosls(itr->GetObject(), labsProtocol);
                endpoint.Details.Protocols.push_back(labsProtocol);
            }
        }

        if (obj.HasMember("suites") && obj["suites"].IsObject()) {
            Endpoint::parseLabsSuites(obj["suites"].GetObject(), endpoint.Details.Suites);
        }

        if (obj.HasMember("serverSignature") && obj["serverSignature"].IsString()) {
            endpoint.Details.ServerSignature = obj["serverSignature"].GetString();
        }

        if (obj.HasMember("prefixDelegation") && obj["prefixDelegation"].IsBool()) {
            endpoint.Details.PrefixDelegation = obj["prefixDelegation"].GetBool();
        }

        if (obj.HasMember("nonPrefixDelegation") && obj["nonPrefixDelegation"].IsBool()) {
            endpoint.Details.NonPrefixDelegation = obj["nonPrefixDelegation"].GetBool();
        }

        if (obj.HasMember("vulnBeast") && obj["vulnBeast"].IsBool()) {
            endpoint.Details.VulnBeast = obj["vulnBeast"].GetBool();
        }

        if (obj.HasMember("renegSupport") && obj["renegSupport"].IsInt()) {
            endpoint.Details.RenegSupport = obj["renegSupport"].GetInt();
        }

        // * TODO: need to parse stsStatus & sts.. any variable;

        if (obj.HasMember("sessionResumption") && obj["sessionResumption"].IsInt()) {
            endpoint.Details.SessionResumption = obj["sessionResumption"].GetInt();
        }

        if (obj.HasMember("compressionMethods") && obj["compressionMethods"].IsInt()) {
            endpoint.Details.CompressionMethods = obj["compressionMethods"].GetInt();
        }

        if (obj.HasMember("supportsNpn") && obj["supportsNpn"].IsBool()) {
            endpoint.Details.SupportsNpn = obj["supportsNpn"].GetBool();
        }

        if (obj.HasMember("sessionTickets") && obj["sessionTickets"].IsInt()) {
            endpoint.Details.SessionTickets = obj["sessionTickets"].GetInt();
        }

        if (obj.HasMember("ocspStapling") && obj["ocspStapling"].IsBool()) {
            endpoint.Details.OcspStapling = obj["ocspStapling"].GetBool();
        }

        if (obj.HasMember("sniRequired") && obj["sniRequired"].IsBool()) {
            endpoint.Details.SniRequired = obj["sniRequired"].GetBool();
        }

        if (obj.HasMember("httpStatusCode") && obj["httpStatusCode"].IsInt()) {
            endpoint.Details.HttpStatusCode = obj["httpStatusCode"].GetInt();
        }

        if (obj.HasMember("supportsRc4") && obj["supportsRc4"].IsBool()) {
            endpoint.Details.SupportsRc4 = obj["supportsRc4"].GetBool();
        }

        if (obj.HasMember("rc4WithModern") && obj["rc4WithModern"].IsBool()) {
            endpoint.Details.Rc4WithModern = obj["rc4WithModern"].GetBool();
        }

        if (obj.HasMember("rc4Only") && obj["rc4Only"].IsBool()) {
            endpoint.Details.Rc4Only = obj["rc4Only"].GetBool();
        }

        if (obj.HasMember("forwardSecrecy") && obj["forwardSecrecy"].IsInt()) {
            endpoint.Details.ForwardSecrecy = obj["forwardSecrecy"].GetInt();
        }

        if (obj.HasMember("sims") && obj["sims"].IsObject()) {
            parseSimulationDetails(obj["sims"].GetObject(), endpoint.Details.Sims);
        }

        if (obj.HasMember("heartbleed") && obj["heartbleed"].IsBool()) {
            endpoint.Details.Heartbleed = obj["heartbleed"].GetBool();
        }

        if (obj.HasMember("heartbeat") && obj["heartbeat"].IsBool()) {
            endpoint.Details.Heartbeat = obj["heartbeat"].GetBool();
        }

        if (obj.HasMember("openSslCcs") && obj["openSslCcs"].IsInt()) {
            endpoint.Details.OpenSslCcs = obj["openSslCcs"].GetInt();
        }

        if (obj.HasMember("poodle") && obj["poodle"].IsBool()) {
            endpoint.Details.Poodle = obj["poodle"].GetBool();
        }

        if (obj.HasMember("poodleTls") && obj["poodleTls"].IsInt()) {
            endpoint.Details.PoodleTls = obj["poodleTls"].GetInt();
        }

        if (obj.HasMember("fallbackScsv") && obj["fallbackScsv"].IsBool()) {
            endpoint.Details.FallbackScsv = obj["fallbackScsv"].GetBool();
        }

        if (obj.HasMember("freak") && obj["freak"].IsBool()) {
            endpoint.Details.Freak = obj["freak"].GetBool();
        }

        if (obj.HasMember("hasSct") && obj["hasSct"].IsInt()) {
            endpoint.Details.HasSct = obj["hasSct"].GetInt();
        }

        if (obj.HasMember("dhPrimes") && obj["dhPrimes"].IsArray()) {
            for (auto itr = obj["dhPrimes"].GetArray().Begin(); itr != obj["dhPrimes"].GetArray().End(); itr++) {
                if (itr->IsString()) {
                    endpoint.Details.DhPrimes.push_back(itr->GetString());
                }
            }
        }

        if (obj.HasMember("dhUsesKnownPrimes") && obj["dhUsesKnownPrimes"].IsInt()) {
            endpoint.Details.DhUsesKnownPrimes = obj["dhUsesKnownPrimes"].GetInt();
        }

        if (obj.HasMember("dhYsReuse") && obj["dhYsReuse"].IsBool()) {
            endpoint.Details.DhYsReuse = obj["dhYsReuse"].GetBool();
        }

        if (obj.HasMember("logjam") && obj["logjam"].IsBool()) {
            endpoint.Details.Logjam = obj["logjam"].GetBool();
        }

        if (obj.HasMember("hstsPolicy") && obj["hstsPolicy"].IsObject()) {
            Endpoint::parseHstsPolicy(obj["hstsPolicy"].GetObject(), endpoint.Details.HstsPolicy);
        }

        if (obj.HasMember("hstsPreloads") && obj["hstsPreloads"].IsArray()) {

        }

        if (obj.HasMember("hpkpPolicy") && obj["hpkpPolicy"].IsObject()) {
            Endpoint::parseHpkpPolicy(obj["hpkpPolicy"].GetObject(), endpoint.Details.HpkpPolicy);
        }

        if (obj.HasMember("hpkpRoPolicy") && obj["hpkpRoPolicy"].IsObject()) {
            Endpoint::parseHpkpPolicy(obj["hpkpRoPolicy"].GetObject(), endpoint.Details.HpkpRoPolicy);
        }

        // * TODO: need to parse drownHosts;

        if (obj.HasMember("drownErrors") && obj["drownErrors"].IsBool()) {
            endpoint.Details.DrownErrors = obj["drownErrors"].GetBool();
        }

        if (obj.HasMember("drownVulnerable") && obj["drownVulnerable"].IsBool()) {
            endpoint.Details.DrownVulnerable = obj["drownVulnerable"].GetBool();
        }

        return;
    }
示例#14
0
文件: Client.cpp 项目: koz4k/soccer
RpcGet RpcRequest::Execute()
{
	if(!shouldExecute)
		return RpcGet();
	shouldExecute = false;
	String request;
	if(json) {
		ContentType("application/json");
		static Atomic id;
		Json json;
		json("jsonrpc", "2.0")
		    ("method", method);
		if(data.out.GetCount()) {
			JsonArray a;
			for(int i = 0; i < data.out.GetCount(); i++) {
				const Value& v = data.out[i];
				if(v.Is<RawJsonText>())
					a.CatRaw(v.To<RawJsonText>().json);
				else
					a << JsonRpcData(v);
			}
			json("params", a);
		}
		else
		if(data.out_map.GetCount()) {
			Json m;
			for(int i = 0; i < data.out_map.GetCount(); i++) {
				const Value& v = data.out_map.GetValue(i);
				String key = (String)data.out_map.GetKey(i);
				if(v.Is<RawJsonText>())
					m.CatRaw(key, v.To<RawJsonText>().json);
				else
					m(key, JsonRpcData(v));
			}
			json("params", m);
		}
		json("id", id);
		AtomicInc(id);
		request = ~json;
	}
	else {
		ContentType("text/xml");
		request = XmlHeader();
		request << XmlTag("methodCall")(XmlTag("methodName")(method) + FormatXmlRpcParams(data.out));
	}
	if(sLogRpcCalls) {
		if(sLogRpcCallsCompress)
			RLOG("=== XmlRpc call request:\n" << CompressLog(request));
		else
			RLOG("=== XmlRpc call request:\n" << request);
	}
	String response;
	New();
	if(shorted)
		response = RpcExecuteShorted(request);
	else
		response = Post(request).Execute();
	if(sLogRpcCalls) {
		if(sLogRpcCallsCompress)
			RLOG("=== XmlRpc call response:\n" << CompressLog(response));
		else
			RLOG("=== XmlRpc call response:\n" << response);
	}
	RpcGet h;
	if(IsNull(response)) {
		faultCode = RPC_CLIENT_HTTP_ERROR;
		faultString = GetErrorDesc();
		error = "Http request failed: " + faultString;
		LLOG(error);
		h.v = ErrorValue(error);
		return h;
	}
	if(json) {
		try {
			Value r = ParseJSON(response);
			if(IsValueMap(r)) {
				ValueMap m = r;
				Value result = m["result"];
				if(!result.IsVoid()) {
					data.in.Clear();
					data.in.Add(result);
					data.ii = 0;
					h.v = result;
					return h;
				}
				Value e = m["error"];
				if(IsValueMap(e)) {
					Value c = e["code"];
					Value m = e["message"];
					if(IsNumber(c) && IsString(m)) {
						faultCode = e["code"];
						faultString = e["message"];
						error.Clear();
						error << "Failed '" << faultString << "' (" << faultCode << ')';
						LLOG(s);
						h.v = ErrorValue(error);
						return h;
					}
				}
			}
			String s;
			faultString = "Invalid response";
			faultCode = RPC_CLIENT_RESPONSE_ERROR;
			error = faultString;
			LLOG(error);
			h.v = ErrorValue(error);
			return h;
		}
		catch(CParser::Error e) {
			String s;
			faultString = e;
			faultCode = RPC_CLIENT_JSON_ERROR;
			error.Clear();
			error << "JSON Error: " << faultString;
			LLOG(error);
			h.v = ErrorValue(error);
			return h;
		}
	}
	else {
		XmlParser p(response);
		try {
			p.ReadPI();
			p.PassTag("methodResponse");
			if(p.Tag("fault")) {
				Value m = ParseXmlRpcValue(p);
				if(IsValueMap(m)) {
					ValueMap mm = m;
					faultString = mm["faultString"];
					faultCode = mm["faultCode"];
					error.Clear();
					error << "Failed '" << faultString << "' (" << faultCode << ')';
					LLOG(s);
					h.v = ErrorValue(error);
					return h;
				}
			}
			else {
				data.in = ParseXmlRpcParams(p);
				data.ii = 0;
				p.PassEnd();
			}
		}
		catch(XmlError e) {
			String s;
			faultString = e;
			faultCode = RPC_CLIENT_XML_ERROR;
			error.Clear();
			error << "XML Error: " << faultString;
			LLOG(error << ": " << p.GetPtr());
			h.v = ErrorValue(error);
			return h;
		}
		h.v = data.in.GetCount() ? data.in[0] : Null;
		return h;
	}
}
示例#15
0
// function that tokenizes the input, using a structure of conscell's, where each conscell has a car and a cdr,
// each car has two values, the type and the actual value.
ConsCell* tokenize(char *expression) {
  ConsCell *current =malloc(sizeof(ConsCell));
  ConsCell *Head = current;
  int i = 0;
  for (int i = 0; expression[i]; i++) {
    if (expression[i]==' ') continue;
      else if (expression[i] == '\n'){
        continue;
      }
    if (expression[i]== '\t'){
      continue;
    }
    Value *carVar = malloc(sizeof(Value));
    Value *cdrVar = malloc(sizeof(Value));
    if (expression[i]=='(') {
      carVar->type = 6;
      carVar->openValue = '(';
    }

    else if (expression[i]==')') {
      carVar->type=7;
      carVar->closeValue = ')';
    }
    else {
      
      if (IsAnInt(expression, i)) {
        carVar->type=2;
        carVar->intValue=GiveInt(expression, i);
        i = getNextTerminal(expression, i);
        i -=1;
      }
      else if(IsSymbol(expression, i)) {
        int symbolLength=returnSymbolLength(expression, i);
        carVar->type=5;
        carVar->symbolValue=returnSymbol(expression, i, symbolLength);
        if (IsId(carVar->symbolValue)){
          carVar->type = 9;
          carVar->idValue = carVar->symbolValue;
        }
        else if (IsPrimitive(carVar->symbolValue)) {
          carVar->type = 13;
          carVar->primValue = carVar->symbolValue;
        }
        i+=symbolLength;
      }
      else if(IsString(expression, i)) {
        carVar->type=4;
        carVar->stringValue=returnString(expression, i);
        int lengthOfString = findLengthOfString(carVar->stringValue);
        i+=lengthOfString;
      }
      else if(IsBoolean(expression,i)){
        carVar->type = 1;
        carVar->boolValue=returnBoolean(expression,i);
        i +=1;
      }
      else if(IsFloat(expression, i)) {
        carVar->type=3;
        carVar->floatValue=GiveFloat(expression, i);
        i = getNextTerminal(expression, i);
        i -=1;
      }
      else if(expression[i] == ';') {
        free(carVar);
        free(cdrVar);
        break;
      }
      else {
        free(carVar);
        free(cdrVar);
        printf("Error: Bad syntax.\n");
        ConsCell *emptyCons =malloc(sizeof(ConsCell));
        Value *Val = malloc(sizeof(Value));
        Val->type = 0;
        Val->intValue= 1;
        emptyCons->car = Val;
        Value *cdrVal = malloc(sizeof(Value));
        cdrVal->type = 0;
        cdrVal->intValue = 0;
        current->car = cdrVal;
        cleanupCCLL(Head);
        return emptyCons;
        break;
      }
      
      


    }
    ConsCell *newCell = malloc(sizeof(ConsCell));
    cdrVar->type = 8;
    cdrVar->cons = newCell;
    current = insertCC(current, carVar, cdrVar);
    current = newCell;

  }
  Value *cdrVal = malloc(sizeof(Value));
  cdrVal->type = 0;
  cdrVal->intValue = 0;
  current->car = cdrVal;
  return Head;

}
示例#16
0
/*=== write_field_set =======================================================
 * <Description Text> 
 *
 * Assumes:    ?
 *
 * Returns:    (value) when X
 *             (value) when Y
 *
 * Modifies:   ?
 *
 * Calls:      nothing
 *
 * Called By:  ?
 *
 * History:    MM/DD/YY  MRH  Created initial version based on function
 *                            'func()' in motif/csr/file.c
 */
void
write_field_set(FILE  *file,
                FIELD *field,
                FUNCTION_TYPE function_type)
{
  char function_proto[80];
  char field_name[80];
  char field_type_string[80];
  char field_out[80];
  char field_in[80];
  char field_size[80];
  int  num_pointer;
  
  if (IsDateStruct(field->field_type)||
      IsMoney(field->field_type))
    num_pointer = 1;
  else
    num_pointer = 0;
  sprintf(function_proto, FORMAT_SET, gAPINameCAP, ((field->has_alias)
                                                    ? field->alias_lc
                                                    : field->name_lc));
  sprintf(field_type_string, "const %s", type_string[field->field_type]);
  write_prototype(file, function_type,
                  EXPORT_STRING, STATUS_STRING, function_proto,
                  gAPIType,                       0, OBJECT_TYPE,
                  field_type_string,              num_pointer, INPUT_TYPE,
                  ERROR_STRING,                   1, ERROR_TYPE,
                  NULL);

  switch (function_type)
  {
  case FUNCTION:
    fprintf(file, "\n{\n");

    /*
     * First, verify that we are getting from the proper object type.
     */
    fprintf(file, "  if (GAL_OBJECT_TYPE(%s) != %s_TYPE)\n  {\n",
            OBJECT_TYPE, gAPIType);
    fprintf(file, "    lpError->error_type = GAL_ERROR_TYPE;\n");
    fprintf(file, "    lpError->error_code = GAL_ARGUMENT_TYPE_ERROR;\n");
    fprintf(file, "    return GAL_FAILURE;\n");
    fprintf(file, "  }\n\n");
    
    /*
     * If we make it this far, copy, set bits and return.
     */
    if (field->is_key)
      sprintf(field_name, "%s->ObjectKey.%s", OBJECT_TYPE, ((field->has_alias)
                                                            ? field->alias_lc
                                                            : field->name_lc));
    else
      sprintf(field_name, "%s->%s", OBJECT_TYPE, ((field->has_alias)
                                                  ? field->alias_lc
                                                  : field->name_lc));
    if (IsString(field->field_type))
      fprintf(file, "  strncpy(%s, %s, GAL_%s_%s_LEN);\n",
              field_name, INPUT_TYPE, gAPINameUC, ((field->has_alias)
                                                   ? field->alias_uc
                                                   : field->name_uc));
    else if (IsDateStruct(field->field_type) ||
             IsMoney(field->field_type))
    {
      sprintf(field_in,   "(void *)(&(%s))", field_name);
      sprintf(field_out,  "(const void *)%s", INPUT_TYPE);
      sprintf(field_size, "sizeof(%s)", type_string[field->field_type]);
      write_function_call(file, 0, 5, "  memcpy",
                          field_in,
                          field_out,
                          field_size,
                          NULL);
      fprintf(file, ";\n");
    }
    else
      fprintf(file, "  %s = %s;\n", field_name, INPUT_TYPE);
    
    fprintf(file, "  Set(GAL_CONTROL_BITS(%s, %s_%s_FPOS));\n\n",
            OBJECT_TYPE, gAPIType, ((field->has_alias)
                                    ? field->alias_uc
                                    : field->name_uc));
    
    /* MRH -- take care of joins if they are in multiple locations? */

    fprintf(file, "  return GAL_SUCCESS;\n");
    
    fprintf(file, "}\n\n");
    break;

  case PROTOTYPE:
    fprintf(file, ";\n");
    break;

  default:
    break;
  }
}
示例#17
0
/*=== write_field_filter =====================================================
 * <Description Text> 
 *
 * Assumes:    ?
 *
 * Returns:    (value) when X
 *             (value) when Y
 *
 * Modifies:   ?
 *
 * Calls:      nothing
 *
 * Called By:  ?
 *
 * History:    MM/DD/YY  MRH  Created initial version based on function
 *                            'func()' in motif/csr/file.c
 */
void
write_field_filter(FILE  *file,
                   FIELD *field,
                   FUNCTION_TYPE function_type)
{
  char function_proto[80];
  char field_name[80];
  char table_name[80];
  char filter_type_string[80];
  int  num_pointer;
  
  if (IsDateStruct(field->field_type) ||
      IsMoney(field->field_type))
    num_pointer = 1;
  else
    num_pointer = 0;
  sprintf(function_proto, FORMAT_FILTER, gAPINameCAP, ((field->has_alias)
                                                       ? field->alias_lc
                                                       : field->name_lc));
  sprintf(filter_type_string, "const %s", type_string[field->field_type]);
  write_prototype(file, function_type,
                  EXPORT_STRING, STATUS_STRING, function_proto,
                  FSC_STRING,                     0, FSC_TYPE,
                  filter_type_string,   num_pointer, INPUT_TYPE,
                  FILTER_OP_STRING,               0, FILTER_OP_TYPE,
                  ERROR_STRING,                   1, ERROR_TYPE,
                  NULL);

  switch (function_type)
  {
  case FUNCTION:
    fprintf(file, "\n{\n");
    /*
     * First, verify that we are getting from the proper object type.
     */
    fprintf(file, "  if (%s->iType != %s_TYPE)\n  {\n",
            FSC_TYPE, gAPIType);
    fprintf(file, "    lpError->error_type = GAL_ERROR_TYPE;\n");
    fprintf(file, "    lpError->error_code = GAL_ARGUMENT_TYPE_ERROR;\n");
    fprintf(file, "    return GAL_FAILURE;\n");
    fprintf(file, "  }\n\n");
    
    /*
     * If we make it this far, allocate and initialize a new filter item.
     */
    fprintf(file, "  if (");
    sprintf(field_name, FIELD_NAME_INDEX,
            gAPIType, gAPIType, ((field->has_alias)
                                 ? field->alias_uc
                                 : field->name_uc));
    sprintf(table_name, TABLE_NAME_INDEX,
            gAPIType, gAPIType, field->table->name_uc);
    if (IsString(field->field_type))
    {
      write_function_call(file, 6, 16, NEW_FILTER_STRING_FUNCTION,
                          FSC_TYPE, field_name, table_name,
                          INPUT_TYPE, FILTER_OP_TYPE,
                          NULL);
    }
    else if (IsDateStruct(field->field_type))
    {
      write_function_call(file, 6, 16, NEW_FILTER_DATE_FUNCTION,
                          FSC_TYPE, field_name, table_name,
                          INPUT_TYPE, FILTER_OP_TYPE,
                          NULL);      
    }
    else if (IsMoney(field->field_type))
    {
      write_function_call(file, 6, 16, NEW_FILTER_NUMERIC_FUNCTION,
                          FSC_TYPE, field_name, table_name,
                          INPUT_TYPE, FILTER_OP_TYPE,
                          NULL);      
    }

    else 
    {
      write_function_call(file, 6, 16, NEW_FILTER_INT_FUNCTION,
                          FSC_TYPE, field_name, table_name,
                          INPUT_TYPE, FILTER_OP_TYPE,
                          NULL);
    }
    fprintf(file, " == GAL_FAILURE)\n");
    fprintf(file, "  {\n");
    fprintf(file, "    lpError->error_type = GAL_ERROR_TYPE;\n");
    fprintf(file, "    lpError->error_code = GAL_ALLOCATION_ERROR;\n");
    fprintf(file, "    return GAL_FAILURE;\n");
    fprintf(file, "  }\n\n");
    
    fprintf(file, "  return GAL_SUCCESS;\n");
    
    fprintf(file, "}\n\n");
    break;

  case PROTOTYPE:
    fprintf(file, ";\n");
    break;

  default:
    break;
  }
}
示例#18
0
String RichPNG::Write(const Value& v) const
{
	if(IsString(v))
		return v;
	return StoreImageAsString(v);
}
示例#19
0
static int
p_string_list(value vs, type ts, value vl, type tl)
{
    register pword	*pw, *list;
    register char	*s;
    register int	len;
    pword		*old_tg = Gbl_Tg;

    if (IsRef(ts))			/* no string given	*/
    {
	if (IsRef(tl))			/* we need at least one	*/
	{
	    Bip_Error(PDELAY_1_2);
	}
	else if (IsList(tl))		/* make a string from a list	*/
	{
	    list = vl.ptr;		/* space for the string header	*/
	    Push_Buffer(1);		/* make minimum buffer		*/
	    s = (char *) BufferStart(old_tg);	/* start of the new string */
	    for(;;)			/* loop through the list	*/
	    {
		pw = list++;
		Dereference_(pw);		/* get the list element	*/
		if (IsRef(pw->tag))		/* check it		*/
		{
		    Gbl_Tg = old_tg;
		    Push_var_delay(vs.ptr, ts.all);
		    Push_var_delay(pw, pw->tag.all);
		    Bip_Error(PDELAY);
		}
		else if (!IsInteger(pw->tag))
		{
		    Gbl_Tg = old_tg;
		    Bip_Error(TYPE_ERROR);
		}
		else if (pw->val.nint < 0  ||  pw->val.nint > 255)
		{
		    Gbl_Tg = old_tg;
		    Bip_Error(RANGE_ERROR);
		}
		*s++ = pw->val.nint;
		if (s == (char *) Gbl_Tg)	/* we need another pword */
		{
		    Gbl_Tg += 1;
		    Check_Gc;
		}
		Dereference_(list);		/* get the list tail	*/
		if (IsRef(list->tag))
		{
		    Gbl_Tg = old_tg;
		    Push_var_delay(vs.ptr, ts.all);
		    Push_var_delay(list, list->tag.all);
		    Bip_Error(PDELAY);
		}
		else if (IsList(list->tag))
		    list = list->val.ptr;
		else if (IsNil(list->tag))
		    break;			/* end of the list	*/
		else
		{
		    Gbl_Tg = old_tg;
		    Bip_Error(TYPE_ERROR);
		}
	    }
	    *s = '\0';			/* terminate the string		*/
	    Set_Buffer_Size(old_tg, s - (char *)(old_tg + 1) + 1);
	    Kill_DE;
	    Return_Unify_String(vs, ts, old_tg);
	}
	else if (IsNil(tl))
	{
	    Kill_DE;
	    Return_Unify_String(vs, ts, empty_string);
	}
	else
	{
	    Bip_Error(TYPE_ERROR);
	}
    }
    else if (IsString(ts))
    {
	Kill_DE;
	Check_Output_List(tl);
	s = StringStart(vs);		/* get a pointer to the string	*/
	len = StringLength(vs);
	if (len == 0)
	{
	    Return_Unify_Nil(vl, tl);
	}
	/* Additional a-priori overflow check because adding to TG may
	 * may wrap around the address space and break Check_Gc below
	 */
	Check_Available_Pwords(2*len);
	pw = Gbl_Tg;			/* reserve space for the list	*/
	Gbl_Tg += 2*len;
	Check_Gc;
	pw->val.nint = *s++ & 0xFFL;	/* construct the list	*/
	pw++->tag.kernel = TINT;
	while (--len > 0)
	{
	    pw->val.ptr = pw + 1;
	    pw++->tag.kernel = TLIST;
	    pw->val.nint = *s++ & 0xFFL;
	    pw++->tag.kernel = TINT;
	}
	pw->tag.kernel = TNIL;
	Return_Unify_List(vl, tl, old_tg);
    }
    else
    {
	Bip_Error(TYPE_ERROR);
    }
}
示例#20
0
Size RichPNG::GetPixelSize(const Value& data) const
{
	if(IsString(data))
		return Size(0, 0);
	return Image(data).GetDots();
}
void cbStyledTextCtrl::HighlightRightBrace()
{
    if (m_bracePosition == wxSCI_INVALID_POSITION)
        return;

    int pos = GetCurrentPos();
    if (pos == wxSCI_INVALID_POSITION)
        return;

    const static wxColour caretForeground = GetCaretForeground();
    const static int caretWidth = GetCaretWidth();
    const int curLine = GetCurrentLine();
    const int len = GetLength();

    if (m_tabSmartJump && (curLine == LineFromPosition(m_bracePosition)))
    {
        SetIndicatorCurrent(s_indicHighlight);
        const int indPos = GetLineIndentPosition(curLine);
        IndicatorClearRange(indPos, GetLineEndPosition(curLine)-indPos);
        do
        {
            if (pos >= len)
                break;

            wxString cur((wxChar)GetCharAt(pos));
            if (cur == _T("\n"))
                break;

            int style = GetStyleAt(pos);
            if (IsComment(style))
                continue;

            if (IsString(style) || IsCharacter(style))
            {
                const int nextOne = (pos == len) ? GetStyleAt(pos) : GetStyleAt(pos + 1);
                if (IsCharacter(nextOne) || IsString(nextOne))
                    continue;
            }

            if (s_rightBrace.Contains(cur))
            {
                SetCaretForeground(wxColour(255, 0, 0));
                SetCaretWidth(caretWidth + 1);

                IndicatorSetForeground(s_indicHighlight, wxColour(80, 236, 120));
                IndicatorSetStyle(s_indicHighlight, wxSCI_INDIC_HIGHLIGHT);
#ifndef wxHAVE_RAW_BITMAP
                IndicatorSetUnder(s_indicHighlight, true);
#endif
                SetIndicatorCurrent(s_indicHighlight);
                IndicatorFillRange(pos, 1);
                m_bracePosition = pos + 1;
                return;
            }
        }
        while (++pos);
    }

    m_bracePosition = wxSCI_INVALID_POSITION;
    m_lastPosition = wxSCI_INVALID_POSITION;
    m_tabSmartJump = false;
    SetIndicatorCurrent(s_indicHighlight);
    IndicatorClearRange(0, len);

    SetCaretForeground(caretForeground);
    SetCaretWidth(caretWidth);
}
bool CScValue::IsValString()
{
    return IsString();
}
示例#23
0
bool TRI_IsStringJson (TRI_json_t const* json) {
  return IsString(json);
}
示例#24
0
void ValueGet(String& s, const Value& v)
{
	ValueCheck(IsNull(v) || IsString(v));
	s = v;
}
示例#25
0
文件: JSON.cpp 项目: kolyden/mirror
String AsJSON(const Value& v, const String& sep, bool pretty)
{
	String r;
	if(v.GetType() == VALUEMAP_V) {
		r << "{";
		String sep1;
		if(pretty) {
			r << "\r\n";
			sep1 = sep + '\t';
		}
		ValueMap m = v;
		ValueArray va = m.GetValues();
		for(int i = 0; i < m.GetCount(); i++) {
			if(i) {
				r << ",";
				if(pretty)
					r << "\r\n";
			}
			if(pretty)
				r << sep1;
			r << AsJSON((String)m.GetKey(i)) << (pretty ? ": " : ":")
			  << AsJSON(va[i], sep1, pretty);
		}
		if(pretty)
			r << "\r\n" << sep;
		r << "}";
		return r;
	}
	if(v.GetType() == VALUEARRAY_V) {
		r << "[";
		String sep1;
		if(pretty) {
			r << "\r\n";
			sep1 = sep + '\t';
		}
		ValueArray va = v;
		for(int i = 0; i < va.GetCount(); i++) {
			if(i) {
				r << ",";
				if(pretty)
					r << "\r\n";
			}
			if(pretty)
				r << sep1;
			r << AsJSON(va[i], sep1, pretty);
		}
		if(pretty)
			r << "\r\n" << sep;
		r << "]";
		return r;
	}
	if(IsNumber(v) && IsNull(v))
		return "null";
	if(v.GetType() == INT_V)
		return Format("%d", (int)v);
	if(v.GetType() == BOOL_V)
		return (bool)v ? "true" : "false";
	if(IsNumber(v))
		return Format("%.16g", (double)v);
	if(IsString(v))
		return AsCString((String)v, INT_MAX, NULL, ASCSTRING_JSON);
	if(IsDateTime(v))
		return AsJSON((Time)v);
	if(IsNull(v))
		return "null";
	NEVER_("Non-JSON value in AsJSON: " + v.GetTypeName());
	return "null";
}
示例#26
0
文件: cell.hpp 项目: Spicery/ginger
	bool isStringObject() const { return IsString( this->ref ); }
示例#27
0
	/**
	* Checks whether the variant is empty.
	*
	* @returns true if the variant is empty, false otherwise.
	*/
	inline bool IsEmpty(void) const
	{
		return (GetType() == ValueEmpty || (IsString() && boost::get<String>(m_Value).IsEmpty()));
	}
示例#28
0
/*=== write_field_get =======================================================
 * <Description Text> 
 *
 * Assumes:    ?
 *
 * Returns:    (value) when X
 *             (value) when Y
 *
 * Modifies:   ?
 *
 * Calls:      nothing
 *
 * Called By:  ?
 *
 * History:    MM/DD/YY  MRH  Created initial version based on function
 *                            'func()' in motif/csr/file.c
 */
void
write_field_get(FILE  *file,
                FIELD *field,
                FUNCTION_TYPE function_type)
{
  char function_proto[80];
  char field_name[80];
  int  num_pointer;
  char field_out[80];
  char field_in[80];
  char field_size[80];
  
  sprintf(function_proto, FORMAT_GET, gAPINameCAP, ((field->has_alias)
                                                    ? field->alias_lc
                                                    : field->name_lc));
  if (IsString(field->field_type))
    num_pointer = 0;
  else
    num_pointer = 1;
#ifndef USE_MACROS
  write_prototype(file, function_type,
                  EXPORT_STRING, STATUS_STRING, function_proto,
                  gAPITypeConst,                  0, OBJECT_TYPE,
                  type_string[field->field_type], num_pointer, OUTPUT_TYPE,
                  ERROR_STRING,                   1, ERROR_TYPE,
                  NULL);
#endif

  switch (function_type)
  {
  case FUNCTION:
#ifndef USE_MACROS
    fprintf(file, "\n{\n");

    /*
     * First, verify that we are getting from the proper object type.
     */
    fprintf(file, "  if (GAL_OBJECT_TYPE(%s) != %s_TYPE)\n  {\n",
            OBJECT_TYPE, gAPIType);
    fprintf(file, "    lpError->error_type = GAL_ERROR_TYPE;\n");
    fprintf(file, "    lpError->error_code = GAL_ARGUMENT_TYPE_ERROR;\n");
    fprintf(file, "    return GAL_FAILURE;\n");
    fprintf(file, "  }\n\n");
    
    /*
     * Now, make sure the field is set.
     */
    fprintf(file, "  if (! IsSet(GAL_CONTROL_BITS(%s, %s_%s_FPOS)))\n  {\n",
            OBJECT_TYPE, gAPIType, ((field->has_alias)
                                    ? field->alias_uc
                                    : field->name_uc));
    fprintf(file, "    lpError->error_type = GAL_ERROR_TYPE;\n");
    fprintf(file, "    lpError->error_code = GAL_FIELD_NOT_SET_ERROR;\n");
    fprintf(file, "    return GAL_FAILURE;\n");
    fprintf(file, "  }\n\n");
    
    /*
     * If we make it this far, copy and return success.
     */
    if (field->is_key)
      sprintf(field_name, "%s->ObjectKey.%s", OBJECT_TYPE, ((field->has_alias)
                                                            ? field->alias_lc
                                                            : field->name_lc));
    else
      sprintf(field_name, "%s->%s", OBJECT_TYPE, ((field->has_alias)
                                                  ? field->alias_lc
                                                  : field->name_lc));
    if (IsString(field->field_type))
      fprintf(file, "  strcpy(%s, %s);\n", OUTPUT_TYPE, field_name);
    else if (IsDateStruct(field->field_type) ||
             IsMoney(field->field_type))
    {
      /* for dates and money, just do a memcpy, since we don't know
         exactly what these are in terms of structure */
      sprintf(field_out,  "(void *)%s", OUTPUT_TYPE);
      sprintf(field_in,   "(const void *)(&(%s))", field_name);
      sprintf(field_size, "sizeof(%s)", type_string[field->field_type]);
      write_function_call(file, 0, 5, "  memcpy",
                          field_out,
                          field_in,
                          field_size,
                          NULL);
      fprintf(file, ";\n");
    }
    else
      fprintf(file, "  *%s = %s;\n", OUTPUT_TYPE, field_name);
    
    fprintf(file, "\n  return GAL_SUCCESS;\n");
    
    fprintf(file, "}\n\n");
#endif
    break;

  case PROTOTYPE:
#ifndef USE_MACROS
    fprintf(file, ";\n");
#else
    fprintf(file, "#define %s(%s, %s, %s) \\\n",
            function_proto,
            OBJECT_TYPE,
            OUTPUT_TYPE,
            ERROR_TYPE);
    fprintf(file, "%s((%s), \\\n",
            GAL_GET_FIELD_FUNCTION,
            OBJECT_TYPE);

    for (i=0; i <= strlen(GAL_GET_FIELD_FUNCTION); i++)
      fputc(' ', file);
    fprintf(file, "%s_TYPE, \\\n", gAPIType);
    
    for (i=0; i <= strlen(GAL_GET_FIELD_FUNCTION); i++)
      fputc(' ', file);
    fprintf(file, "GAL_CONTROL_BITS(%s, %s_%s_FPOS), \\\n",
            OBJECT_TYPE, gAPIType, ((field->has_alias)
                                    ? field->alias_uc
                                    : field->name_uc);

    for (i=0; i <= strlen(GAL_GET_FIELD_FUNCTION); i++)
      fputc(' ', file);
    if (field->is_key)
      fprintf(file, "(void *) (&((%s)->ObjectKey.%s)), \\\n",
              OBJECT_TYPE,
              field->name_lc);
    else
      fprintf(file, "(void *) (&((%s)->%s)), \\\n",
              OBJECT_TYPE, ((field->has_alias)
                            ? field->alias_lc
                            : field->name_lc));

    for (i=0; i <= strlen(GAL_GET_FIELD_FUNCTION); i++)
      fputc(' ', file);
    if (IsString(field->field_type))
      fprintf(file, "GAL_%s_%s_LEN, \\\n", gAPINameUC, ((field->has_alias)
                                                        ? field->alias_uc
                                                        : field->name_uc));
    else
      fprintf(file, "sizeof(%s), \\\n", type_string[field->field_type]);

    for (i=0; i <= strlen(GAL_GET_FIELD_FUNCTION); i++)
      fputc(' ', file);
    fprintf(file, "(void *) (%s), \\\n", OUTPUT_TYPE);
      
    for (i=0; i <= strlen(GAL_GET_FIELD_FUNCTION); i++)
      fputc(' ', file);
    fprintf(file, "(%s))\n", ERROR_TYPE);
#endif
    break;

  default:
    break;
  }
}
示例#29
0
bool RequestMessage::parsePayload(rapidjson::Value& value, IceServalBridge* bridge)
{
  this->requests.clear();

  if (false == value.IsArray())
  {
    _log->error("Payload could not be parsed: Is not an array");
    return false;
  }

  std::string entity, entityType, scope, rep, relatedEntity;
  int count = 0;

  for (auto it = value.Begin(); it != value.End(); ++it)
  {
    if (false == it->IsArray())
    {
      _log->error("Payload could not be parsed: Id is not an array");
      return false;
    }

    count = 0;

    for (auto it2 = it->Begin(); it2 != it->End(); ++it2)
    {
      if (false == it2->IsString())
      {
        _log->error("Payload could not be parsed: Field is not a string");
        return false;
      }

      switch(count)
      {
        case 0:
          entity = it2->GetString();
          break;
        case 1:
          entityType = it2->GetString();
          break;
        case 2:
          scope = it2->GetString();
          break;
        case 3:
          rep = it2->GetString();
          break;
        case 4:
          relatedEntity = it2->GetString();
          break;
      }

      ++count;
    }

    if (count != 5)
    {
      _log->error("Payload could not be parsed: Wrong number of fields for offer");
      return false;
    }

    auto spec = std::make_shared<InformationSpecification>(entity, entityType, scope, rep, relatedEntity);
    this->requests.push_back(spec);
  }

  return true;
}
示例#30
0
bool TokenizedRuleHalf::IsTree() const
{
  return !IsString();
}