Ejemplo n.º 1
0
int xml2lpc_set_xml_string(xml2lpc_context* xmlCtx, const char *content) {
	xml2lpc_context_clear_logs(xmlCtx);
	xmlSetGenericErrorFunc(xmlCtx, xml2lpc_genericxml_error);
	if(xmlCtx->doc != NULL) {
		xmlFreeDoc(xmlCtx->doc);
		xmlCtx->doc = NULL;
	}
	xmlCtx->doc = xmlReadDoc((const unsigned char*)content, 0, NULL, 0);
	if(xmlCtx->doc == NULL) {
		xml2lpc_log(xmlCtx, XML2LPC_ERROR, "Can't parse string");
		xml2lpc_log(xmlCtx, XML2LPC_ERROR, "%s", xmlCtx->errorBuffer);
		return -1;
	}
	return 0;
}
Ejemplo n.º 2
0
int xml2lpc_set_xml_fd(xml2lpc_context* xmlCtx, int fd) {
	xml2lpc_context_clear_logs(xmlCtx);
	xmlSetGenericErrorFunc(xmlCtx, xml2lpc_genericxml_error);
	if(xmlCtx->doc != NULL) {
		xmlFreeDoc(xmlCtx->doc);
		xmlCtx->doc = NULL;
	}
	xmlCtx->doc = xmlReadFd(fd, 0, NULL, 0);
	if(xmlCtx->doc == NULL) {
		xml2lpc_log(xmlCtx, XML2LPC_ERROR, "Can't open/parse fd \"%d\"", fd);
		xml2lpc_log(xmlCtx, XML2LPC_ERROR, "%s", xmlCtx->errorBuffer);
		return -1;
	}
	return 0;
}
Ejemplo n.º 3
0
int xml2lpc_set_xml_file(xml2lpc_context* xmlCtx, const char *filename) {
	xml2lpc_context_clear_logs(xmlCtx);
	xmlSetGenericErrorFunc(xmlCtx, xml2lpc_genericxml_error);
	if(xmlCtx->doc != NULL) {
		xmlFreeDoc(xmlCtx->doc);
		xmlCtx->doc = NULL;
	}
	xmlCtx->doc = xmlReadFile(filename, NULL, 0);
	if(xmlCtx->doc == NULL) {
		xml2lpc_log(xmlCtx, XML2LPC_ERROR, "Can't open/parse file \"%s\"", filename);
		xml2lpc_log(xmlCtx, XML2LPC_ERROR, "%s", xmlCtx->errorBuffer);
		return -1;
	}
	return 0;
}
Ejemplo n.º 4
0
static int processSection(xmlElement *element, xml2lpc_context *ctx) {
	xmlNode *cur_node = NULL;
	xmlNode *cur_attr = NULL;
	const char *name = NULL;

	for (cur_attr = (xmlNode *)element->attributes; cur_attr; cur_attr = cur_attr->next) {
		dumpAttr(cur_attr, ctx);
		if(strcmp((const char*)cur_attr->name, "name") == 0) {
			name = (const char*)cur_attr->children->content;
		}
	}

	if(name != NULL) {
		for (cur_node = element->children; cur_node; cur_node = cur_node->next) {
			dumpNode(cur_node, ctx);
			if (cur_node->type == XML_ELEMENT_NODE) {
				if(strcmp((const char*)cur_node->name, "entry") == 0 ) {
					processEntry((xmlElement*)cur_node, name, ctx);
				}
			}

		}
		} else {
			xml2lpc_log(ctx, XML2LPC_WARNING, "ignored section with no \"name\" attribute, line:%d", xmlGetLineNo((xmlNode*)element));
		}

		return 0;
}
Ejemplo n.º 5
0
static int processDoc(xmlNode *node, xml2lpc_context *ctx) {
	dumpNode(node, ctx);

	if (node->type == XML_ELEMENT_NODE &&
		strcmp((const char*)node->name, "config") == 0 ) {
		processConfig((xmlElement*)node, ctx);
	} else {
		xml2lpc_log(ctx, XML2LPC_WARNING, "root element is not \"config\", line:%d", xmlGetLineNo(node));
	}
	return 0;
}
Ejemplo n.º 6
0
int xml2lpc_validate(xml2lpc_context *xmlCtx) {
	xmlSchemaValidCtxtPtr validCtx;
	xmlSchemaParserCtxtPtr parserCtx;
	int ret;

	xml2lpc_context_clear_logs(xmlCtx);
	parserCtx = xmlSchemaNewDocParserCtxt(xmlCtx->xsd);
	validCtx = xmlSchemaNewValidCtxt(xmlSchemaParse(parserCtx));
	xmlSchemaSetValidErrors(validCtx, xml2lpc_genericxml_error, xml2lpc_genericxml_warning, xmlCtx);
	ret = xmlSchemaValidateDoc(validCtx, xmlCtx->doc);
	if(ret > 0) {
		if(strlen(xmlCtx->warningBuffer) > 0)
			xml2lpc_log(xmlCtx, XML2LPC_WARNING, "%s", xmlCtx->warningBuffer);
		if(strlen(xmlCtx->errorBuffer) > 0)
			xml2lpc_log(xmlCtx, XML2LPC_ERROR, "%s", xmlCtx->errorBuffer);
	} else if(ret < 0) {
		xml2lpc_log(xmlCtx, XML2LPC_ERROR, "Internal error");
	}
	xmlSchemaFreeValidCtxt(validCtx);
	return ret;
}
Ejemplo n.º 7
0
static int processEntry(xmlElement *element, const char *sectionName, xml2lpc_context *ctx) {
	xmlNode *cur_attr = NULL;
	const char *name = NULL;
	const char *value = NULL;
	bool_t overwrite = FALSE;

	for (cur_attr = (xmlNode *)element->attributes; cur_attr; cur_attr = cur_attr->next) {
		dumpAttr(cur_attr, ctx);
		if(strcmp((const char*)cur_attr->name, "name") == 0) {
			name = (const char*)cur_attr->children->content;
		} else if(strcmp((const char*)cur_attr->name, "overwrite") == 0) {
			if(strcmp((const char*)cur_attr->children->content, "true") == 0) {
				overwrite = TRUE;
			}
		}
	}

	dumpContent((xmlNode *)element, ctx);
	if (element->children)
		value = (const char *)element->children->content;
	else
		value = "";

	if(name != NULL) {
		const char *str = lp_config_get_string(ctx->lpc, sectionName, name, NULL);
		if(str == NULL || overwrite) {
			xml2lpc_log(ctx, XML2LPC_MESSAGE, "Set %s|%s = %s", sectionName, name, value);
			lp_config_set_string(ctx->lpc, sectionName, name, value);
		} else {
			xml2lpc_log(ctx, XML2LPC_MESSAGE, "Don't touch %s|%s = %s",sectionName, name, str);
		}
	} else {
		xml2lpc_log(ctx, XML2LPC_WARNING, "ignored entry with no \"name\" attribute line:%d",xmlGetLineNo((xmlNode*)element));
	}
		return 0;
}
Ejemplo n.º 8
0
static void dumpContent(xmlNode *node, xml2lpc_context *ctx) {
	if (node->children)
		xml2lpc_log(ctx, XML2LPC_DEBUG, "content: %s", node->children->content);
	else
		xml2lpc_log(ctx, XML2LPC_DEBUG, "content: ");
}
Ejemplo n.º 9
0
static void dumpAttr(xmlNode *node, xml2lpc_context *ctx) {
	xml2lpc_log(ctx, XML2LPC_DEBUG, "attr name: %s value:%s", node->name, node->children->content);
}
Ejemplo n.º 10
0
static void dumpNode(xmlNode *node, xml2lpc_context *ctx) {
	xml2lpc_log(ctx, XML2LPC_DEBUG, "node type: %d, name: %s", node->type, node->name);
}