static const char *get_status_string(unsigned int status)
{
	const char * const str[] = {
		enum_string(IDLE),
		enum_string(START),
		enum_string(RUN),
		enum_string(SUCCESS),
		enum_string(FAILURE),
		enum_string(DOWNLOAD),
		enum_string(DONE),
		enum_string(SUBPROCESS)
	};

	if (status >= ARRAY_SIZE(str))
		return "UNKNOWN";

	return str[status];
}
Exemple #2
0
static void _configure_detect(Configure * configure)
{
	char const * os;
	char const * version;
#ifdef __WIN32__

	configure->arch = HA_I386;
	configure->os = HO_WIN32;
	configure->kernel = HK_UNKNOWN;
#else
	struct utsname un;

	if(uname(&un) < 0)
	{
		configure_error("system detection failed", 0);
		configure->arch = HA_UNKNOWN;
		configure->os = HO_UNKNOWN;
		configure->kernel = HK_UNKNOWN;
		return;
	}
	configure->arch = enum_map_find(HA_LAST, mHostArch, un.machine);
	configure->os = enum_string(HO_LAST, sHostOS,
			(configure->prefs->os != NULL)
			? configure->prefs->os : un.sysname);
	configure->kernel = _detect_kernel(configure->os, un.release);
#endif
	if(configure->prefs->flags & PREFS_v)
	{
		os = (mHostKernel[configure->kernel].os_display != NULL)
			? mHostKernel[configure->kernel].os_display
			: sHostOS[configure->os];
		version = (mHostKernel[configure->kernel].version_display
				!= NULL)
			? mHostKernel[configure->kernel].version_display
			: mHostKernel[configure->kernel].version;
		printf("Detected system %s version %s (%s)\n", os, version,
				sHostArch[configure->arch]);
	}
}
option_values_t
destination_implObj::parse_attribute_values(info_t::lock &lock,
					    ipp_attribute_t *attrs,
					    const char *option_s,
					    bool unicode_flag)
{
	if (!attrs)
		return {};

	auto count=ippGetCount(attrs);

	auto tag_value=ippGetValueTag(attrs);

	switch (tag_value) {
	case IPP_TAG_NOVALUE:
		return {};
	case IPP_TAG_RANGE:
		{
			std::vector<std::tuple<int, int>> v;

			v.reserve(count);

			for (decltype (count) i=0; i<count; i++)
			{
				int upper;

				int lower=ippGetRange(attrs, i, &upper);

				v.emplace_back(lower, upper);
			}
			return v;
		}
	case IPP_TAG_RESOLUTION:
		{
			std::vector<resolution> v;

			v.reserve(count);

			for (decltype (count) i=0; i<count; i++)
			{
				resolution res;
				ipp_res_t units;

				res.xres=ippGetResolution(attrs, i,
							  &res.yres, &units);

				switch (units) {
				case IPP_RES_PER_INCH:
					res.units=res.per_inch;
					break;
				case IPP_RES_PER_CM:
					res.units=res.per_cm;
					break;
				default:
					res.units=res.unknown;
				}
				v.push_back(res);
			}
			return v;
		}

	case IPP_TAG_INTEGER:
		{
			std::unordered_set<int> v;

			for (decltype (count) i=0; i<count; i++)
			{
				v.insert(ippGetInteger(attrs, i));
			}
			return v;
		}
	case IPP_TAG_BOOLEAN:
		{
			std::unordered_set<bool> v;

			for (decltype (count) i=0; i<count; i++)
			{
				v.insert(ippGetBoolean(attrs, i));
			}
			return v;
		}
	case IPP_TAG_ENUM:
		if (unicode_flag)
		{
			auto l=locale::base::global();

			std::unordered_map<int, std::u32string> v;

			for (decltype (count) i=0; i<count; i++)
			{
				auto value=ippGetInteger(attrs, i);

				auto s=enum_string(option_s, value);

				auto us=unicode::iconvert::tou
					::convert(s, l->charset()).first;

				v.emplace(value, us);
			}
			return v;
		}
		else
		{
			std::unordered_map<int, std::string> v;

			for (decltype (count) i=0; i<count; i++)
			{
				auto value=ippGetInteger(attrs, i);


				v.emplace(value, enum_string(option_s, value));
			}
			return v;
		}
	case IPP_TAG_BEGIN_COLLECTION:
		{
			std::vector<const_collection> v;

			v.reserve(count);

			for (decltype (count) i=0; i<count; i++)
			{
				auto ippc=ippGetCollection(attrs, i);

				auto c=collection::create();

				for (auto attr=ippFirstAttribute(ippc);
				     attr;
				     attr=ippNextAttribute(ippc))
				{
					std::string n=ippGetName(attr);
					c->emplace(n, parse_attribute_values
						   (lock, attr, n.c_str(),
						    unicode_flag));
				}
				v.push_back(c);
			}
			return v;
		}
	default:
		break;
	}

	std::unordered_map<std::string, std::string> v;

	bool is_media=strcmp(option_s, CUPS_MEDIA) == 0;

	auto localizer=strcmp(option_s, CUPS_SIDES) == 0
		? sides
		: strcmp(option_s, CUPS_PRINT_COLOR_MODE) == 0
		? print_color_mode
		: no_localizer;

	for (decltype (count) i=0; i<count; i++)
	{
		const char *lang=0;

		auto val=ippGetString(attrs, i, &lang);

		if (!val)
		{

			std::ostringstream o;

			o << "{unknown tag "
			  << ippTagString(ippGetValueTag(attrs)) << "}";
			v.emplace(o.str(), "");
			continue;
		}

		std::string lang_s;

		if (is_media)
		{
			cups_size_t size;

			lang_s=val;

			if (cupsGetDestMediaByName(lock->http,
						   lock->dest,
						   lock->info,
						   val,
						   CUPS_MEDIA_FLAGS_DEFAULT,
						   &size))
			{
				auto l=cupsLocalizeDestMedia
					(lock->http,
					 lock->dest,
					 lock->info,
					 CUPS_MEDIA_FLAGS_DEFAULT,
					 &size);

				if (l)
					lang_s=l;
			}
		}
		else
		{
			auto c=cupsLocalizeDestValue(lock->http,
						     lock->dest,
						     lock->info,
						     option_s,
						     val);

			if (c && strcmp(c, val))
			{
				lang_s=c;
			}
			else
			{
				lang_s=localizer(val);
			}
		}
		v.emplace(val, lang_s);
	}

	if (!unicode_flag)
		return v;

	auto l=locale::base::global();

	std::unordered_map<std::string, std::u32string> uv;

	for (const auto &s:v)
	{
		auto n=s.first;


		uv.emplace(s.first,
			   unicode::iconvert::tou::convert(s.second,
							   l->charset())
			   .first);
	}
	return uv;
}