]> sjero.net Git - linphone/blobdiff - tools/xml2lpc.c
Aac-eld add missing header according to RFC3640 3.3.6
[linphone] / tools / xml2lpc.c
index ce12eeb466bab6d903c4e01ee6d1a14b7fa05778..c9a5c94e2999c38b4c01b688fc09921d6169101e 100644 (file)
@@ -64,12 +64,12 @@ void xml2lpc_context_destroy(xml2lpc_context *ctx) {
        free(ctx);
 }
 
-void xml2lpc_context_clear_logs(xml2lpc_context *ctx) {
+static void xml2lpc_context_clear_logs(xml2lpc_context *ctx) {
        ctx->errorBuffer[0]='\0';
        ctx->warningBuffer[0]='\0';
 }
 
-void xml2lpc_log(xml2lpc_context *xmlCtx, int level, const char *fmt, ...) {
+static void xml2lpc_log(xml2lpc_context *xmlCtx, int level, const char *fmt, ...) {
        va_list args;   
        va_start(args, fmt);    
        if(xmlCtx->cbf != NULL) {
@@ -78,7 +78,7 @@ void xml2lpc_log(xml2lpc_context *xmlCtx, int level, const char *fmt, ...) {
        va_end(args);
 }
 
-void xml2lpc_genericxml_error(void *ctx, const char *fmt, ...) {       
+static void xml2lpc_genericxml_error(void *ctx, const char *fmt, ...) {
        xml2lpc_context *xmlCtx = (xml2lpc_context *)ctx;
        int sl = strlen(xmlCtx->errorBuffer);
        va_list args;   
@@ -87,7 +87,7 @@ void xml2lpc_genericxml_error(void *ctx, const char *fmt, ...) {
        va_end(args);
 }
 
-void xml2lpc_genericxml_warning(void *ctx, const char *fmt, ...) {     
+static void xml2lpc_genericxml_warning(void *ctx, const char *fmt, ...) {
        xml2lpc_context *xmlCtx = (xml2lpc_context *)ctx;
        int sl = strlen(xmlCtx->warningBuffer);
        va_list args;   
@@ -96,6 +96,7 @@ void xml2lpc_genericxml_warning(void *ctx, const char *fmt, ...) {
        va_end(args);
 }
 
+#if 0
 static void dumpNodes(int level, xmlNode * a_node, xml2lpc_context *ctx) {
     xmlNode *cur_node = NULL;
 
@@ -109,6 +110,7 @@ static void dumpNodes(int level, xmlNode * a_node, xml2lpc_context *ctx) {
         dumpNodes(level + 1, cur_node->children, ctx);
     }
 }
+#endif
 
 
 static void dumpNode(xmlNode *node, xml2lpc_context *ctx) {
@@ -146,7 +148,7 @@ static int processEntry(xmlElement *element, const char *sectionName, xml2lpc_co
        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);
+                       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);
@@ -212,11 +214,11 @@ static int processDoc(xmlNode *node, xml2lpc_context *ctx) {
        return 0;
 }
 
-static int internal_convert_xml2lpc(xmlDoc *doc, xml2lpc_context *ctx) {
+static int internal_convert_xml2lpc(xml2lpc_context *ctx) {
        xml2lpc_log(ctx, XML2LPC_DEBUG, "Parse started");
-       xmlNode *rootNode = xmlDocGetRootElement(doc);
+       xmlNode *rootNode = xmlDocGetRootElement(ctx->doc);
        //dumpNodes(0, rootNode, cbf, ctx);
-        int ret = processDoc(rootNode, ctx);
+       int ret = processDoc(rootNode, ctx);
        xml2lpc_log(ctx, XML2LPC_DEBUG, "Parse ended ret:%d", ret);
        return ret;
 }
@@ -228,10 +230,12 @@ int xml2lpc_validate(xml2lpc_context *xmlCtx) {
        validCtx = xmlSchemaNewValidCtxt(xmlSchemaParse(parserCtx));
        xmlSchemaSetValidErrors(validCtx, xml2lpc_genericxml_error, xml2lpc_genericxml_warning, xmlCtx);
        int ret =  xmlSchemaValidateDoc(validCtx, xmlCtx->doc);
-       if(ret >0) {
-               xml2lpc_log(xmlCtx, XML2LPC_WARNING, "%s", xmlCtx->warningBuffer);
-               xml2lpc_log(xmlCtx, XML2LPC_ERROR, "%s", xmlCtx->errorBuffer);
-       } else {
+       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);
@@ -240,8 +244,15 @@ int xml2lpc_validate(xml2lpc_context *xmlCtx) {
 
 int xml2lpc_convert(xml2lpc_context *xmlCtx, LpConfig *lpc) {
        xml2lpc_context_clear_logs(xmlCtx);
+       if(xmlCtx->doc == NULL) {
+               xml2lpc_log(xmlCtx, XML2LPC_ERROR, "No doc set");
+               return -1;
+       }
+       if(lpc == NULL) {
+               xml2lpc_log(xmlCtx, XML2LPC_ERROR, "Invalid lpc");
+       }
        xmlCtx->lpc = lpc;
-       return internal_convert_xml2lpc(xmlCtx->doc, xmlCtx);
+       return internal_convert_xml2lpc(xmlCtx);
 }
 
 int xml2lpc_set_xml_file(xml2lpc_context* xmlCtx, const char *filename) {
@@ -338,4 +349,4 @@ int xml2lpc_set_xsd_string(xml2lpc_context* xmlCtx, const char *content) {
                return -1;
        }
        return 0;
-}
\ No newline at end of file
+}