void HttpServerRequest::Read(const ValueList& args, SharedValue result)
	{
		std::istream &in = request.stream();
		if (in.eof() || in.fail())
		{
			result->SetNull();
			return;
		}
		int max_size = 8096;
		if (args.size()==1)
		{
			max_size = args.at(0)->ToInt();
		}
		char *buf = new char[max_size];
		in.read(buf,max_size);
		std::streamsize count = in.gcount();
		if (count == 0)
		{
			result->SetNull();
		}
		else
		{
			result->SetObject(new Blob(buf,count));
		}
		delete [] buf;
	}
Пример #2
0
	void AppBinding::GetIcon(const ValueList& args, SharedValue result)
	{
		SharedApplication app = this->host->GetApplication();
		result->SetNull();	

		if (app && !app->image.empty())
		{
			result->SetString(app->image);
		}
	}
Пример #3
0
	void MenuItem::_GetSubmenu(const ValueList& args, SharedValue result)
	{
		if (this->submenu.isNull())
		{
			result->SetNull();
		}
		else
		{
			result->SetObject(this->submenu);
		}
	}
Пример #4
0
	void UIBinding::_GetMenu(const ValueList& args, SharedValue result)
	{
		AutoMenu menu = this->GetMenu();
		if (menu.isNull())
		{
			result->SetNull();
		}
		else
		{
			result->SetObject(menu);
		}
	}
Пример #5
0
	void ResultSetBinding::Field(const ValueList& args, SharedValue result)
	{
		if (rs.isNull())
		{
			result->SetNull();
		}
		else
		{
			args.VerifyException("field", "i");
			TransformValue(args.at(0)->ToInt(),result);
		}
	}
	void HttpServerRequest::GetHeader(const ValueList& args, SharedValue result)
	{
		std::string name = args.at(0)->ToString();
		if (request.has(name))
		{
			std::string value = request.get(name);
			result->SetString(value);
		}
		else
		{
			result->SetNull();
		}
	}
Пример #7
0
	void Blob::ToUpperCase(const ValueList& args, SharedValue result)
	{
		if (this->length > 0)
		{
			std::string target = this->buffer;
			std::string r = Poco::toUpper(target);
			result->SetString(r);
		}
		else
		{
			result->SetNull();
		}
	}
Пример #8
0
	void ResultSetBinding::FieldName(const ValueList& args, SharedValue 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());
		}
	}
Пример #9
0
	void AppBinding::GetIcon(const ValueList& args, SharedValue result)
	{
		const SharedApplication app = this->host->GetApplication();
		if (app->image.empty())
		{
			result->SetNull();
		}
		else
		{
			std::string iconPath = app->image;
			result->SetString(iconPath);
		}
	}
Пример #10
0
	void ResultSetBinding::TransformValue(size_t index, SharedValue 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);
		}
	}
Пример #11
0
	void HTTPClientBinding::GetResponseHeader(const ValueList& args, SharedValue result)
	{
		if (this->response!=NULL)
		{
			std::string name = args.at(0)->ToString();
			if (this->response->has(name))
			{
				result->SetString(this->response->get(name).c_str());
			}
			else
			{
				result->SetNull();
			}
		}
		else
		{
			throw ValueException::FromString("no available response");
		}
	}
Пример #12
0
	void ResultSetBinding::FieldByName(const ValueList& args, SharedValue result)
	{
		result->SetNull();
		if (!rs.isNull())
		{
			args.VerifyException("fieldByName", "s");
			std::string name = args.at(0)->ToString();
			size_t count = rs->columnCount();
			for (size_t i = 0; i<count; i++)
			{
				const std::string &str = rs->columnName(i);
				if (str == name)
				{
					TransformValue(i,result);
					break;
				}
			}
		}
	}
Пример #13
0
	void Pipe::Read(const ValueList& args, SharedValue result)
	{
		if (closed)
		{
			throw ValueException::FromString("Pipe is already closed");
		}
		Poco::PipeInputStream *is = dynamic_cast<Poco::PipeInputStream*>(pipe);
		if (is==NULL)
		{
			throw ValueException::FromString("Stream is not readable");
		}
		char *buf = NULL;
		try
		{
			int size = 1024;
			// allow the size of the returned buffer to be 
			// set by the caller - defaults to 1024 if not specified
			if (args.size()>0 && args.at(0)->IsInt())
			{
				size = args.at(0)->ToInt();
			}
			buf = new char[size];
			is->read(buf,size);
			int count = is->gcount();
			if (count <=0)
			{
				result->SetNull();
			}
			else
			{
				buf[count] = '\0';
				result->SetString(buf);
			}
			delete [] buf;
		}
		catch (Poco::ReadFileException &e)
		{
			if (buf) delete[] buf;
			throw ValueException::FromString(e.what());
		}
	}
Пример #14
0
	void FileStream::ReadLine(const ValueList& args, SharedValue result)
	{
		if(! this->stream)
		{
			Logger* logger = Logger::Get("Filesystem.FileStream");
			logger->Error("Error in readLine. FileStream must be opened before calling read");
			throw ValueException::FromString("FileStream must be opened before calling readLine");
		}

		try
		{
			Poco::FileInputStream* fis = dynamic_cast<Poco::FileInputStream*>(this->stream);
			if(!fis)
			{
				Logger* logger = Logger::Get("Filesystem.FileStream");
				logger->Error("Error in readLine. FileInputStream is null");
				throw ValueException::FromString("FileStream must be opened for reading before calling readLine");
			}

			if(fis->eof())
			{
				// close the file
				result->SetNull();
			}
			else
			{
				std::string line;
				std::getline(*fis, line);
				result->SetObject(new Blob((std::string)line));
			}
		}
		catch (Poco::Exception& exc)
		{
			Logger* logger = Logger::Get("Filesystem.FileStream");
			logger->Error("Error in readLine. Exception: %s",exc.displayText().c_str());
			throw ValueException::FromString(exc.displayText());
		}
	}