Esempio n. 1
0
static std::string sides(const std::string_view &v)
{
	if (v == CUPS_SIDES_ONE_SIDED)
		return _("Off");
	if (v == CUPS_SIDES_TWO_SIDED_PORTRAIT)
		return _("Duplex (Long Edge)");
	if (v == CUPS_SIDES_TWO_SIDED_LANDSCAPE)
		return _("Duplex (Short Edge)");
	return {v.begin(), v.end()};
}
Esempio n. 2
0
static std::string print_color_mode(const std::string_view &v)
{
	if (v == CUPS_PRINT_COLOR_MODE_AUTO)
		return _("Automatic");
	if (v == CUPS_PRINT_COLOR_MODE_MONOCHROME)
		return _("Monochrome");
	if (v == CUPS_PRINT_COLOR_MODE_COLOR)
		return _("Color");
	return {v.begin(), v.end()};
}
Esempio n. 3
0
void job_implObj::set_option(const std::string_view &name,
			     const std::string_view &value)
{
	size_t s=name.size();

	char name_str[s+1];

	std::copy(name.begin(), name.end(), name_str);
	name_str[s]=0;

	s=value.size();
	char value_str[s+1];

	std::copy(value.begin(), value.end(), value_str);
	value_str[s]=0;

	job_info_t::lock lock{job_info};

	lock->num_options=cupsAddOption(name_str, value_str,
					lock->num_options,
					&lock->options);
}
Esempio n. 4
0
bool destination_implObj::supported(const std::string_view &option,
				    const std::string_view &value) const
{
	auto s=option.size();

	char option_s[s+1];

	std::copy(option.begin(), option.end(), option_s);
	option_s[s]=0;

	s=value.size();

	char value_s[s+1];
	std::copy(value.begin(), value.end(), value_s);
	value_s[s]=0;

	info_t::lock lock{*this};

	return !!cupsCheckDestSupported(lock->http,
					lock->dest,
					lock->info,
					option_s,
					value_s);
}
Esempio n. 5
0
option_values_t
destination_implObj::ready_option_values(const std::string_view &option)
	const
{
	auto s=option.size();

	char option_s[s+1];

	std::copy(option.begin(), option.end(), option_s);
	option_s[s]=0;

	auto[name, unicode_flag]=parse_unicode_option(option_s);
	info_t::lock lock{*this};

	auto attrs=cupsFindDestReady(lock->http, lock->dest,
				     lock->info,
				     name);

	return parse_attribute_values(lock, attrs, name, unicode_flag);
}
Esempio n. 6
0
int job_implObj::submit(const std::string_view &title)
{
	size_t s=title.size();

	char title_str[s+1];

	std::copy(title.begin(), title.end(), title_str);
	title_str[s]=0;

	job_info_t::lock job_lock{job_info};

	if (job_lock->documents.empty())
		return 0;

	destination_implObj::info_t::lock lock{*destination};

	int job_id;

	auto status=cupsCreateDestJob(lock->http,
				      lock->dest,
				      lock->info,
				      &job_id,
				      title_str,
				      job_lock->num_options,
				      job_lock->options);

	if (status != IPP_STATUS_OK)
		throw EXCEPTION(ippErrorString(status));

	auto job_sentry=make_sentry([&]
				    {
					    cupsCancelDestJob(lock->http,
							      lock->dest,
							      job_id);
				    });

	job_sentry.guard();

	for (const auto &doc:job_lock->documents)
	{
		auto [mime_type, contents]=doc.document();

		auto status=cupsStartDestDocument(lock->http,
						  lock->dest, lock->info,
						  job_id,
						  doc.name.c_str(),
						  mime_type.c_str(),
						  0, NULL, 0);
		if (status != HTTP_STATUS_CONTINUE)
			throw EXCEPTION(httpStatus(status));

		auto doc_sentry=make_sentry
			([&]
			 {
				 cupsFinishDestDocument(lock->http,
							lock->dest,
							lock->info);
			 });
		doc_sentry.guard();

		while (auto res=contents())
		{
			status=cupsWriteRequestData(lock->http,
						    res->data(),
						    res->size());

			if (status != HTTP_STATUS_CONTINUE)
				throw EXCEPTION(httpStatus(status));
		}
		doc_sentry.unguard();

		auto ipp_status=cupsFinishDestDocument(lock->http,
						       lock->dest,
						       lock->info);

		if (ipp_status != IPP_STATUS_OK)
			throw EXCEPTION(cupsLastErrorString());
	}

	job_sentry.unguard();

	auto ipp_status=cupsCloseDestJob(lock->http,
					 lock->dest,
					 lock->info,
					 job_id);

	if (ipp_status != IPP_STATUS_OK)
		throw EXCEPTION(cupsLastErrorString());
	return job_id;
}
Esempio n. 7
0
		void log(ELoggingLevel lvl, std::string_view str, T&&... args) const
		{
			constexpr int index[]{-1, 1, 2, 3};
			std::cregex_token_iterator begin{str.begin(), str.end(), regex(), index}, end;
			std::ostringstream stream;
			while(begin != end)
			{
				unsigned position = -1U;
				int alignment = 0;
				char format = 0;
				int width = 0;
				for(int i : index)
				{
					if(begin == end)
						break;

					auto cm = *begin++;

					if(!cm.matched)
						continue;

					switch(i)
					{
					case -1:
						stream.write(cm.first, cm.length());
						break;

					case 1:
						position = number<unsigned>(cm.first, cm.second);
						break;

					case 2:
						alignment = number<int>(cm.first + 1, cm.second);
						break;

					case 3:
						format = cm.first[1];
						width = number<int>(cm.first + 2, cm.second);
						break;
					}
				}

				if(position < 10)
				{
					util::parameter_pack::at
					(
						position,
						[&stream, alignment, format, width](auto&& object)
						{
							auto&& str = print(format, width, std::forward<decltype(object)>(object));

							if(alignment > 0)
								stream << std::setw(alignment - int(str.tellp())) << "";

							stream << str.rdbuf();

							if(alignment < 0)
								stream << std::setw(-alignment - int(str.tellp())) << "";
						},
						std::forward<T>(args)...
					);
				}
			}

			this->log(lvl, stream.str().c_str());
		}
Esempio n. 8
0
static std::string no_localizer(const std::string_view &v)
{
	return {v.begin(), v.end()};
}
inline int parseInt( std::string_view input, int fallback ){
	int value = 0;
	auto result = std::from_chars( input.begin(), input.end(), value, 10 );
	return result.ptr == input.begin() ? fallback : value;
}