示例#1
0
void Network::_EncodeURIComponent(const ValueList &args, KValueRef result)
{
    if (args.at(0)->IsNull() || args.at(0)->IsUndefined())
    {
        result->SetString("");
    }
    else if (args.at(0)->IsString())
    {
        std::string src = args.at(0)->ToString();
        std::string sResult = URLUtils::EncodeURIComponent(src);
        result->SetString(sResult);
    }
    else if (args.at(0)->IsDouble())
    {
        std::stringstream str;
        str << args.at(0)->ToDouble();
        result->SetString(str.str().c_str());
    }
    else if (args.at(0)->IsBool())
    {
        std::stringstream str;
        str << args.at(0)->ToBool();
        result->SetString(str.str().c_str());
    }
    else if (args.at(0)->IsInt())
    {
        std::stringstream str;
        str << args.at(0)->ToInt();
        result->SetString(str.str().c_str());
    }
    else
    {
        throw ValueException::FromString("Could not encodeURIComponent with type passed");
    }
}
示例#2
0
    void Clipboard::_GetData(const ValueList& args, KValueRef result)
    {
        args.VerifyException("getData", "s");

        std::string mimeType(args.GetString(0));
        DataType type = MimeTypeToDataType(mimeType);
        if (type == URI_LIST)
        {
            std::vector<std::string>& list = this->GetURIList();
            if (mimeType == "url")
            {
                std::string url;
                if (list.size() > 0)
                    url = list.at(0);

                result->SetString(url.c_str());
            }
            else
            {
                result->SetList(StaticBoundList::FromStringVector(list));
            }
        }
        else if (type == IMAGE)
        {
            result->SetObject(this->GetImage(mimeType));
        }
        else 
        {
            result->SetString(this->GetText());
        }
    }
	void PropertiesBinding::Getter(const ValueList& args, KValueRef result, Type type)
	{
		if (args.size() > 0 && args.at(0)->IsString())
		{
			std::string eprefix = "PropertiesBinding::Get: ";
			try
			{
				std::string property = args.at(0)->ToString();
				if (args.size() == 1)
				{
					switch (type)
					{
						case Bool: 
							result->SetBool(config->getBool(property));
							break;
						case Double:
							result->SetDouble(config->getDouble(property));
							break;
						case Int:
							result->SetInt(config->getInt(property));
							break;
						case String:
							result->SetString(config->getString(property).c_str());
							break;
						default:
							break;
					}
					return;
				}

				else if (args.size() >= 2)
				{
					switch (type)
					{
						case Bool:
							result->SetBool(config->getBool(property, args.at(1)->ToBool()));
							break;
						case Double:
							result->SetDouble(config->getDouble(property, args.at(1)->ToDouble()));
							break;
						case Int:
							result->SetInt(config->getInt(property, args.at(1)->ToInt()));
							break;
						case String:
							result->SetString(config->getString(property, args.at(1)->ToString()).c_str());
							break;
						default: break;
					}
					return;
				}
			}
			catch(Poco::Exception &e)
			{
				throw ValueException::FromString(eprefix + e.displayText());
			}
		}
	}
示例#4
0
	void Bytes::_ToUpperCase(const ValueList& args, KValueRef result)
	{
		if (this->size > 0)
		{
			std::string target(this->buffer, this->size);
			std::string r = Poco::toUpper(target);
			result->SetString(r);
		}
		else
		{
			result->SetString("");
		}
	}
示例#5
0
void Codec::DigestHMACToHex(const ValueList& args, KValueRef result)
{
    args.VerifyException("digestHMACToHex", "i s s");
    
    int type = args.at(0)->ToInt();
    std::string encoded = args.at(1)->ToString();
    std::string key = args.at(2)->ToString();

    switch(type)
    {
        case CODEC_MD2:
        {
            Poco::HMACEngine<Poco::MD2Engine> engine(key); 
            engine.update(encoded); 
            std::string data = Poco::DigestEngine::digestToHex(engine.digest()); 
            result->SetString(data);
            break;
        }
        case CODEC_MD4:
        {
            Poco::HMACEngine<Poco::MD4Engine> engine(key); 
            engine.update(encoded); 
            std::string data = Poco::DigestEngine::digestToHex(engine.digest()); 
            result->SetString(data);
            break;
        }
        case CODEC_MD5:
        {
            Poco::HMACEngine<Poco::MD5Engine> engine(key); 
            engine.update(encoded); 
            std::string data = Poco::DigestEngine::digestToHex(engine.digest()); 
            result->SetString(data);
            break;
        }
        case CODEC_SHA1:
        {
            Poco::HMACEngine<Poco::SHA1Engine> engine(key); 
            engine.update(encoded); 
            std::string data = Poco::DigestEngine::digestToHex(engine.digest()); 
            result->SetString(data);
            break;
        }
        default:
        {
            std::ostringstream msg("Unsupported encoding type: ");
            msg << type;
            throw ValueException::FromString(msg.str());
        }
    }
}
 void ResultSetBinding::TransformValue(size_t index, KValueRef result)
 {
     MetaColumn::ColumnDataType type = rs->columnType(index);
     Poco::DynamicAny value = rs->value(index);
     
     if (value.isEmpty())
     {
         result->SetNull();
     }
     else if (type == MetaColumn::FDT_STRING)
     {
         std::string str;
         value.convert(str);
         result->SetString(str);
     }
     else if (type == MetaColumn::FDT_BOOL)
     {
         bool v = false;
         value.convert(v);
         result->SetBool(v);
     }
     else if (type == MetaColumn::FDT_FLOAT || type == MetaColumn::FDT_DOUBLE)
     {
         float f = 0;
         value.convert(f);
         result->SetDouble(f);
     }
     else if (type == MetaColumn::FDT_BLOB || type == MetaColumn::FDT_UNKNOWN)
     {
         std::string str;
         value.convert(str);
         result->SetString(str);
     }
     else
     {
         // the rest of these are ints:
         // FDT_INT8,
         // FDT_UINT8,
         // FDT_INT16,
         // FDT_UINT16,
         // FDT_INT32,
         // FDT_UINT32,
         // FDT_INT64,
         // FDT_UINT64,
         int i;
         value.convert(i);
         result->SetInt(i);
     }
 }
	void ApplicationBinding::_GetArgumentValue(const ValueList& args, KValueRef result)
	{
		args.VerifyException("getArgumentValue", "s");
		string arg = args.at(0)->ToString();
		string argValue = this->application->GetArgumentValue(arg);
		result->SetString(argValue);
	}
示例#8
0
void HostBinding::ToString(const ValueList& args, KValueRef result)
{
    std::string s("[IPAddress ");
    s+=name;
    s+="]";
    result->SetString(s.c_str());
}
示例#9
0
void Network::_DecodeURIComponent(const ValueList &args, KValueRef result)
{
    if (args.at(0)->IsNull() || args.at(0)->IsUndefined())
    {
        result->SetString("");
    }
    else if (args.at(0)->IsString())
    {
        std::string src = args.at(0)->ToString();
        std::string sResult = URLUtils::DecodeURIComponent(src);
        result->SetString(sResult);
    }
    else
    {
        throw ValueException::FromString("Could not decodeURIComponent with type passed");
    }
}
示例#10
0
void Platform::_GetVersion(const ValueList& args, KValueRef result)
{
    static std::string osVersion;
    if (osVersion.empty())
        osVersion = GetVersionImpl();

    result->SetString(osVersion.c_str());
}
示例#11
0
	void Bytes::_Substring(const ValueList& args, KValueRef result)
	{
		// This method now follows the spec located at:
		// https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String/substring
		args.VerifyException("Bytes.substring", "i,?i");
		std::string target = "";
		if (this->size > 0)
		{
			target = this->buffer;
		}

		long indexA = args.GetInt(0);
		if (indexA < 0)
			indexA = 0;
		if (indexA > (long) target.size())
			indexA = target.size();

		if (args.size() < 2)
		{
			std::string r = target.substr(indexA);
			result->SetString(r);
		}
		else
		{
			long indexB = args.GetInt(1);
			if (indexB < 0)
				indexB = 0;
			if (indexB > (long) target.size())
				indexB = target.size();

			if (indexA == indexB)
			{
				result->SetString("");
				return;
			}
			if (indexA > indexB)
			{
				long temp = indexA;
				indexA = indexB;
				indexB = temp;
			}
			std::string r = target.substr(indexA, indexB - indexA);
			result->SetString(r);
		}
	}
示例#12
0
void Network::_GetHTTPSProxy(const ValueList& args, KValueRef result)
{
    SharedProxy proxy = ProxyConfig::GetHTTPSProxyOverride();

    if (proxy.isNull())
        result->SetNull();
    else
        result->SetString(proxy->ToString().c_str());
}
示例#13
0
	void AppBinding::GetIcon(const ValueList& args, KValueRef result)
	{
		SharedApplication app = this->host->GetApplication();
		result->SetNull();	

		if (app && !app->image.empty())
		{
			result->SetString(app->image);
		}
	}
示例#14
0
void Codec::DigestToHex(const ValueList& args, KValueRef result)
{
    args.VerifyException("digestToHex", "i s|o");
    
    int type = args.at(0)->ToInt();
    
    Poco::DigestEngine *engine = NULL;
    
    switch(type)
    {
        case CODEC_MD2:
        {
            engine = new Poco::MD2Engine(); 
            break;
        }
        case CODEC_MD4:
        {
            engine = new Poco::MD4Engine(); 
            break;
        }
        case CODEC_MD5:
        {
            engine = new Poco::MD5Engine(); 
            break;
        }
        case CODEC_SHA1:
        {
            engine = new Poco::SHA1Engine(); 
            break;
        }
        default:
        {
            std::ostringstream msg("Unsupported encoding type: ");
            msg << type;
            throw ValueException::FromString(msg.str());
        }
    }
    
    if (args.at(1)->IsString())
    {
        engine->update(args.GetString(1));
    }
    else
    {
        AutoPtr<Bytes> bytes(args.GetObject(1).cast<Bytes>());
        if (!bytes.isNull())
        {
            engine->update(bytes->Pointer(), bytes->Length());
        }
    }
    std::string data = Poco::DigestEngine::digestToHex(engine->digest()); 
    result->SetString(data);
    delete engine;
}
	void FilesystemBinding::GetLineEnding(const ValueList& args, KValueRef result)
	{
		try
		{
			result->SetString(Poco::LineEnding::NEWLINE_LF.c_str());
		}
		catch (Poco::Exception& exc)
		{
			throw ValueException::FromString(exc.displayText());
		}
	}
示例#16
0
void Codec::EncodeHexBinary(const ValueList& args, KValueRef result)
{
    args.VerifyException("encodeHexBinary", "s|o");
    
    std::stringstream str;
    Poco::HexBinaryEncoder encoder(str);
    encoder << GetStringFromValue(args.at(0));
    encoder.close();
    std::string encoded = str.str();
    result->SetString(encoded);
}
示例#17
0
	void AppBinding::AppURLToPath(const ValueList& args, KValueRef result)
	{
		args.VerifyException("appURLToPath", "s");
		std::string url = args.GetString(0);
		if (url.find("app://") != 0 && url.find("://") == std::string::npos)
		{
			url = std::string("app://") + url;
		}
		std::string path = URLUtils::URLToPath(url);
		result->SetString(path);
	}
示例#18
0
void Codec::DecodeHexBinary(const ValueList& args, KValueRef result)
{
    args.VerifyException("decodeHexBinary", "s");
    
    std::string encoded = args.at(0)->ToString();
    std::stringstream str;
    str << encoded;
    Poco::HexBinaryDecoder decoder(str);
    std::string decoded;
    decoder >> decoded;
    result->SetString(decoded);
}
	void FilesystemBinding::GetSeparator(const ValueList& args, KValueRef result)
	{
		try
		{
			std::string sep;
			sep += Poco::Path::separator();
			result->SetString(sep.c_str());
		}
		catch (Poco::Exception& exc)
		{
			throw ValueException::FromString(exc.displayText());
		}
	}
示例#20
0
 void ResultSetBinding::FieldName(const ValueList& args, KValueRef result)
 {
     if (rs.isNull())
     {
         result->SetNull();
     }
     else
     {
         args.VerifyException("fieldName", "i");
         const std::string &str = rs->columnName(args.at(0)->ToInt());
         result->SetString(str.c_str());
     }
 }
示例#21
0
	void Bytes::_CharAt(const ValueList& args, KValueRef result)
	{
		// https://developer.mozilla.org/en/core_javascript_1.5_reference/global_objects/string/charat
		args.VerifyException("Bytes.charAt", "n");
		size_t position = args.GetInt(0);

		char buf[2] = {'\0', '\0'};
		if (position >= 0 && position < this->size)
		{
			buf[0] = this->buffer[position];
		}
		result->SetString(buf);
	}
示例#22
0
	void Bytes::_Substr(const ValueList& args, KValueRef result)
	{
		// This method now follows the spec located at:
		// https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String/substr
		args.VerifyException("Bytes.substr", "i,?i");
		std::string target(this->buffer, this->size);

		int start = args.GetInt(0);
		if (start > 0 && start >= (int)target.length())
		{
			result->SetString("");
			return;
		}

		if (start < 0 && (-1*start) > (int)target.length())
		{
			start = 0;
		}
		else if (start < 0)
		{
			start = target.length() + start;
		}

		long length = target.length() - start;
		if (args.size() > 1)
		{
			length = args.GetInt(1);
		}

		if (length <= 0)
		{
			result->SetString("");
			return;
		}

		std::string r = target.substr(start, length);
		result->SetString(r);
	}
	void HTTPClientBinding::GetResponseHeader(const ValueList& args, KValueRef result)
	{
		args.VerifyException("getResponseHeader", "s");
		std::string name = args.GetString(0);

		if (this->response.has(name))
		{
			result->SetString(this->response.get(name).c_str());
		}
		else
		{
			result->SetNull();
		}
	}
 void HttpServerRequest::GetHeader(const ValueList& args, KValueRef result)
 {
     args.VerifyException("getHeader", "s");
     std::string name = args.at(0)->ToString();
     if (request.has(name))
     {
         std::string value = request.get(name);
         result->SetString(value);
     }
     else
     {
         result->SetNull();
     }
 }
示例#25
0
	void AppBinding::GetStreamURL(const ValueList& args, KValueRef result)
	{
		SharedApplication app = this->host->GetApplication();
		std::string url(app->GetStreamURL("https"));

		for (size_t c = 0; c < args.size(); c++)
		{
			KValueRef arg = args.at(c);
			if (arg->IsString())
			{
				url.append("/");
				url.append(arg->ToString());
			}
		}
		result->SetString(url);
	}
示例#26
0
	void AppBinding::StdIn(const ValueList& args, KValueRef result)
	{
		args.VerifyException("stdin", "?ss");
		std::string input;
		char delimiter = '\n';

		if (args.size() >= 1)
		{
			std::cout << args.GetString(0);
		}

		if (args.size() >= 2)
		{
			delimiter = args.GetString(1).at(0);
		}

		getline(std::cin, input, delimiter);
		result->SetString(input);
	}
示例#27
0
文件: event.cpp 项目: jellycn/kroll
	void Event::_GetType(const ValueList&, KValueRef result)
	{
		result->SetString(this->eventName);
	}
示例#28
0
	void Bytes::_ToString(const ValueList& args, KValueRef result)
	{
		std::string str(this->AsString());
		result->SetString(str);
	}
示例#29
0
void MenuItem::_GetLabel(const ValueList& args, KValueRef result)
{
    result->SetString(this->label);
}
示例#30
0
void MenuItem::_GetIcon(const ValueList& args, KValueRef result)
{
    result->SetString(this->iconURL);
}