Beispiel #1
0
static
struct flipctx *
ctx_init(xmlNodePtr node)
{
	struct flipctx *ctx;
	char *cont;

	ctx = malloc(sizeof(*ctx));
	memset(ctx, 0, sizeof(*ctx));
	
	for (node = node->xml_children; node; node = node->next)
	{
		if (xml_isnode(node, "horiz"))
		{
			cont = xml_getcontent(node);
			if (cont
				&& (!strcmp(cont, "yes")
					|| !strcmp(cont, "on")
					|| !strcmp(cont, "1")))
			ctx->h = 1;
		}
		else if (xml_isnode(node, "vert"))
		{
			cont = xml_getcontent(node);
			if (cont
				&& (!strcmp(cont, "yes")
					|| !strcmp(cont, "on")
					|| !strcmp(cont, "1")))
			ctx->v = 1;
		}
	}
	
	return ctx;
}
Beispiel #2
0
char *
xml_getcontent_def(xmlNodePtr node, char *def)
{
	char *ret;
	
	ret = xml_getcontent(node);
	if (!ret)
		return def;
	return ret;
}
Beispiel #3
0
int
xml_atoi(xmlNodePtr node, int def)
{
	int i;
	char *ret;
	char *end;
	
	ret = xml_getcontent(node);
	if (!ret)
		return def;
	
	i = (int) strtol(ret, &end, 0);
	if (!i && end == ret)
		return def;
	return i;
}
Beispiel #4
0
int
filter(struct image *img, xmlNodePtr node)
{
	struct image work;
	unsigned int x, y, vy;
	unsigned char *r, *w;
	int h, v;
	char *cont;
	
	h = v = 0;
	
	for (node = node->xml_children; node; node = node->next)
	{
		if (xml_isnode(node, "horiz"))
		{
			cont = xml_getcontent(node);
			if (cont
				&& (!strcmp(cont, "yes")
					|| !strcmp(cont, "on")
					|| !strcmp(cont, "1")))
			h = 1;
		}
		else if (xml_isnode(node, "vert"))
		{
			cont = xml_getcontent(node);
			if (cont
				&& (!strcmp(cont, "yes")
					|| !strcmp(cont, "on")
					|| !strcmp(cont, "1")))
			v = 1;
		}
	}
	
	if (!h && !v)
		return 0;
	
	image_dup(&work, img);

	/* 3x3
	 * 0/00 RGBRGBRGB
	 * 1/09 RGBRGBRGB
	 * 2/18 RGBRGBRGB */
	
	r = img->buf;
	for (y = 0; y < img->y; y++)
	{
		if (v)
			vy = img->y - y - 1;
		else
			vy = y;
			
		if (h)
			w = work.buf + (vy + 1) * work.x * 3 - 3;
		else
			w = work.buf + vy * work.x * 3;
		
		for (x = 0; x < img->x; x++)
		{
			w[0] = *r++;
			w[1] = *r++;
			w[2] = *r++;
			if (h)
				w -= 3;
			else
				w += 3;
		}
	}
	
	image_move(img, &work);
	
	return 0;
}
Beispiel #5
0
static
int
fw_load_conf(struct fw_ctx *fctx, xmlNodePtr node)
{
	int mult, val;
	char *s;
	
	if (!node)
		return -1;
	
	memset(fctx, 0, sizeof(*fctx));
	fctx->chmod = -1;
	
	for (node = node->xml_children; node; node = node->next)
	{
		if (xml_isnode(node, "path"))
			fctx->path = xml_getcontent(node);
		else if (xml_isnode(node, "cmd"))
			fctx->cmd = xml_getcontent(node);
		else if (xml_isnode(node, "interval"))
		{
			mult = 1;
			s = xml_attrval(node, "unit");
			if (!s)
				s = xml_attrval(node, "units");
			if (s)
			{
				if (!strcmp(s, "sec") || !strcmp(s, "secs") || !strcmp(s, "seconds"))
					;
				else if (!strcmp(s, "min") || !strcmp(s, "mins") || !strcmp(s, "minutes"))
					mult = 60;
				else if (!strcmp(s, "hour") || !strcmp(s, "hours"))
					mult = 3600;
				else if (!strcmp(s, "day") || !strcmp(s, "days"))
					mult = 86400;
				else
				{
					log_log(MODNAME, "Invalid \"unit\" attribute value \"%s\"\n", s);
					return -1;
				}
			}
			val = xml_atoi(node, 0);
			if (val == 0)
			{
				log_log(MODNAME, "Invalid interval (%s) specified\n", xml_getcontent(node));
				return -1;
			}
			fctx->interval = val * mult;
		}
		else if (xml_isnode(node, "chmod") || xml_isnode(node, "mode"))
			fctx->chmod = xml_atoi(node, fctx->chmod);
	}
	
	if (!fctx->path || fctx->interval == 0)
	{
		log_log(MODNAME, "Either path or interval not specified\n");
		return -1;
	}
	
	fctx->path = config_homedir(fctx->path);
	fctx->cmd = config_homedir(fctx->cmd);
	
	return 0;
}