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()); } } }
void PropertiesBinding::HasProperty(const ValueList& args, KValueRef result) { result->SetBool(false); if (args.size() >= 1 && args.at(0)->IsString()) { std::string property = args.at(0)->ToString(); result->SetBool(config->hasProperty(property)); } }
void PHPEvaluator::CanEvaluate(const ValueList& args, KValueRef result) { args.VerifyException("canEvaluate", "s"); result->SetBool(false); string mimeType(args.GetString(0)); if (mimeType == "text/php") { result->SetBool(true); } }
void ResultSetBinding::IsValidRow(const ValueList& args, KValueRef result) { if (rs.isNull()) { result->SetBool(false); } else { result->SetBool(!eof); } }
void PHPEvaluator::CanPreprocess(const ValueList& args, KValueRef result) { args.VerifyException("canPreprocess", "s"); string url(args.GetString(0)); Poco::URI uri(url); result->SetBool(false); if (Script::HasExtension(uri.getPath().c_str(), "php")) { result->SetBool(true); } }
void TCPServerConnectionBinding::Close(const ValueList& args, KValueRef result) { if (!closed) { this->closed = true; socket.close(); result->SetBool(true); } else { result->SetBool(false); } }
void TCPSocketBinding::Close(const ValueList& args, KValueRef result) { if (this->opened) { this->opened = false; this->reactor.stop(); this->socket.close(); result->SetBool(true); } else { result->SetBool(false); } }
void Properties::RemoveProperty(const ValueList& args, KValueRef result) { args.VerifyException("removeProperty", "s"); result->SetBool(config->removeProperty(args.GetString(0))); if (result) { this->SaveConfig(); } }
void Network::_RemoveConnectivityListener( const ValueList& args, KValueRef result) { args.VerifyException("removeConnectivityListener", "n"); int id = args.at(0)->ToInt(); std::vector<Listener>::iterator it = this->listeners.begin(); while (it != this->listeners.end()) { if ((*it).id == id) { this->listeners.erase(it); result->SetBool(true); return; } it++; } result->SetBool(false); }
void HTTPClientBinding::Send(const ValueList& args, KValueRef result) { // Get send data if provided args.VerifyException("send", "?s|o|0"); KValueRef sendData(args.GetValue(0)); // Setup output stream for data this->outstream = new std::ostringstream(std::ios::binary | std::ios::out); result->SetBool(this->BeginRequest(sendData)); }
void HTTPClientBinding::Open(const ValueList& args, KValueRef result) { args.VerifyException("open", "ss?bss"); this->method = args.GetString(0); this->url = args.GetString(1); this->SetString("url", this->url); // Validate the scheme const std::string scheme = Poco::URI(url).getScheme(); if (scheme != "http" && scheme != "https") { logger->Error("%s scheme is not supported", scheme.c_str()); result->SetBool(false); return; } if (this->method.empty()) { this->method = Poco::Net::HTTPRequest::HTTP_GET; } if (args.size() >= 3) { this->async = args.GetBool(2); } if (args.size() >= 4) { this->basicCredentials.setUsername(args.GetString(3)); this->basicCredentials.setPassword(args.GetString(4)); } // Get on*** handler functions this->ondatastream = this->GetMethod("ondatastream"); this->onreadystate = this->GetMethod("onreadystatechange"); this->onsendstream = this->GetMethod("onsendstream"); this->onload = this->GetMethod("onload"); this->ChangeState(1); // opened result->SetBool(true); }
void ComponentBinding::_IsLoaded(const ValueList& args, KValueRef result) { SharedApplication app = Host::GetInstance()->GetApplication(); result->SetBool(false); if (this->component.get() == app->runtime.get()) { result->SetBool(true); } std::vector<SharedComponent>::iterator i = app->modules.begin(); while (i != app->modules.end()) { SharedComponent c = *i++; if (c.get() == this->component.get()) { result->SetBool(true); } } }
void Clipboard::_HasData(const ValueList& args, KValueRef result) { args.VerifyException("hasData", "?s"); DataType type = UNKNOWN; if (args.size() > 0) { std::string mimeType(args.GetString(0)); type = MimeTypeToDataType(mimeType); } result->SetBool(this->HasData(type)); }
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 HTTPClientBinding::Receive(const ValueList& args, KValueRef result) { args.VerifyException("receive", "m|o ?s|o|0"); // Set output handler this->outstream = 0; result->SetBool(false); if (args.at(0)->IsMethod()) { this->outputHandler = args.at(0)->ToMethod(); } else if (args.at(0)->IsObject()) { KObjectRef handlerObject(args.at(0)->ToObject()); KMethodRef writeMethod(handlerObject->GetMethod("write", 0)); if (writeMethod.isNull()) { logger->Error("Unsupported object type as output handler:" " does not have write method"); } else { this->outputHandler = writeMethod; } } else { logger->Error("Invalid type as output handler!"); return; } // Get the send data if provided KValueRef sendData(args.GetValue(1)); result->SetBool(this->BeginRequest(sendData)); }
void TCPSocketBinding::Connect(const ValueList& args, KValueRef result) { int timeout = 10; if (args.size() > 0) { timeout = args.at(0)->ToInt(); } if (this->opened || connectThread.isRunning()) { throw ValueException::FromString("Socket is already open"); } result->SetBool(true); this->timeout = Poco::Timespan(timeout, 0); connectThread.start(*connectAdapter); }
void TCPServerConnectionBinding::Write(const ValueList& args, KValueRef result) { args.VerifyException("Write", "o|s"); static std::string eprefix("TCPServerConnectionBinding::Write: "); if (this->closed) throw ValueException::FromString(eprefix + "Socket is not open"); BytesRef data(0); if (args.at(0)->IsString()) { std::string sendString(args.GetString(0)); data = new Bytes(sendString.c_str(), sendString.size()); } else if (args.at(0)->IsObject()) { KObjectRef dataObject(args.GetObject(0)); data = dataObject.cast<Bytes>(); } if (data.isNull()) throw ValueException::FromString("Cannot send non-Bytes object"); { Poco::Mutex::ScopedLock lock(sendDataMutex); sendData.push(data); // Only install the ReadyForWrite handler when there is actually data // to write, because otherwise the CPU usage will spike to 100% if (!writeReadyHandlerInstalled) { this->reactor.addEventHandler(socket, Poco::NObserver<TCPServerConnectionBinding, Poco::Net::WritableNotification>(*this, &TCPServerConnectionBinding::onWritable)); writeReadyHandlerInstalled = true; } } result->SetBool(true); }
void TCPSocketBinding::Write(const ValueList& args, KValueRef result) { args.VerifyException("Send", "o|s"); static std::string eprefix("TCPSocketBinding::Write: "); if (!this->opened && !this->connectThread.isRunning()) throw ValueException::FromString(eprefix + "Socket is not open"); BlobRef data(0); if (args.at(0)->IsString()) { std::string sendString(args.GetString(0)); data = new Blob(sendString.c_str(), sendString.size()); } else if (args.at(0)->IsObject()) { KObjectRef dataObject(args.GetObject(0)); data = dataObject.cast<Blob>(); } if (data.isNull()) throw ValueException::FromString("Cannot send non-Blob object"); { Poco::Mutex::ScopedLock lock(sendDataMutex); sendData.push(data); // Only install the ReadyForWrite handler when there is actually data // to write, because otherwise the CPU usage will spike to 100% if (!writeReadyHandlerInstalled) { this->reactor.addEventHandler(this->socket, writeObserver); writeReadyHandlerInstalled = true; } } result->SetBool(true); }
void MenuItem::_GetState(const ValueList& args, KValueRef result) { result->SetBool(this->state); }
void IPAddressBinding::IsGlobalMC(const ValueList& args, KValueRef result) { result->SetBool(!this->invalid && this->address->isGlobalMC()); }
void IPAddressBinding::IsSiteLocal(const ValueList& args, KValueRef result) { result->SetBool(!this->invalid && this->address->isSiteLocal()); }
void IPAddressBinding::IsMulticast(const ValueList& args, KValueRef result) { result->SetBool(!this->invalid && this->address->isMulticast()); }
void IPAddressBinding::IsLoopback(const ValueList& args, KValueRef result) { result->SetBool(!this->invalid && this->address->isLoopback()); }
void IPAddressBinding::IsWildcard(const ValueList& args, KValueRef result) { result->SetBool(!this->invalid && this->address->isWildcard()); }
void MenuItem::_IsSeparator(const ValueList& args, KValueRef result) { result->SetBool(this->type == SEPARATOR); }
void MenuItem::_IsAutoCheck(const ValueList& args, KValueRef result) { result->SetBool(this->autoCheck); }
void MenuItem::_IsEnabled(const ValueList& args, KValueRef result) { result->SetBool(this->enabled); }
void IPAddressBinding::IsInvalid(const ValueList& args, KValueRef result) { result->SetBool(this->invalid); }
void MenuItem::_IsCheck(const ValueList& args, KValueRef result) { result->SetBool(this->type == CHECK); }
void IPAddressBinding::IsIPV6(const ValueList& args, KValueRef result) { result->SetBool(!this->invalid && this->address->family() == IPAddress::IPv6); }