]> sjero.net Git - linphone/blobdiff - tools/lpc2xml.c
Add fmtp parameters to opus payload to enable FEC and DTX
[linphone] / tools / lpc2xml.c
index cd0df72dfb207bc7d29a9d474a331f57abd8605d..39fd62b0e36f693a318cbc38228f97dc2784a93f 100644 (file)
@@ -21,7 +21,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include "lpc2xml.h"
 #include <string.h>
 #include <libxml/xmlsave.h>
-
+#include <libxml/xmlversion.h>
 
 #define LPC2XML_BZ 2048
 
@@ -57,11 +57,11 @@ void lpc2xml_context_destroy(lpc2xml_context *ctx) {
        }
        free(ctx);
 }
-/*
+
 static void lpc2xml_context_clear_logs(lpc2xml_context *ctx) {
        ctx->errorBuffer[0]='\0';
        ctx->warningBuffer[0]='\0';
-}*/
+}
 
 static void lpc2xml_log(lpc2xml_context *xmlCtx, int level, const char *fmt, ...) {
        va_list args;   
@@ -71,7 +71,7 @@ static void lpc2xml_log(lpc2xml_context *xmlCtx, int level, const char *fmt, ...
        }
        va_end(args);
 }
-/*
+
 static void lpc2xml_genericxml_error(void *ctx, const char *fmt, ...) {
        lpc2xml_context *xmlCtx = (lpc2xml_context *)ctx;
        int sl = strlen(xmlCtx->errorBuffer);
@@ -81,6 +81,7 @@ static void lpc2xml_genericxml_error(void *ctx, const char *fmt, ...) {
        va_end(args);
 }
 
+/*
 static void lpc2xml_genericxml_warning(void *ctx, const char *fmt, ...) {
        lpc2xml_context *xmlCtx = (lpc2xml_context *)ctx;
        int sl = strlen(xmlCtx->warningBuffer);
@@ -88,40 +89,8 @@ static void lpc2xml_genericxml_warning(void *ctx, const char *fmt, ...) {
        va_start(args, fmt);    
        vsnprintf(xmlCtx->warningBuffer + sl, LPC2XML_BZ-sl, fmt, args);
        va_end(args);
-}*/
-
-#if 0
-static void dumpNodes(int level, xmlNode * a_node, lpc2xml_context *ctx) {
-       xmlNode *cur_node = NULL;
-
-       for (cur_node = a_node; cur_node; cur_node = cur_node->next) {
-               if (cur_node->type == XML_ELEMENT_NODE) {
-                       lpc2xml_log(ctx, LPC2XML_DEBUG, "node level: %d type: Element, name: %s", level, cur_node->name);
-               } else {
-                       lpc2xml_log(ctx, LPC2XML_DEBUG, "node level: %d type: %d, name: %s", level, cur_node->type, cur_node->name);
-               }
-
-               dumpNodes(level + 1, cur_node->children, ctx);
-       }
-}
-#endif
-
-#if 0
-static void dumpNode(xmlNode *node, lpc2xml_context *ctx) {
-               lpc2xml_log(ctx, LPC2XML_DEBUG, "node type: %d, name: %s", node->type, node->name);
 }
-
-static void dumpAttr(xmlNode *node, lpc2xml_context *ctx) {
-               lpc2xml_log(ctx, LPC2XML_DEBUG, "attr name: %s value:%s", node->name, node->children->content);
-}
-
-static void dumpContent(xmlNode *node, lpc2xml_context *ctx) {
-               lpc2xml_log(ctx, LPC2XML_DEBUG, "content: %s", node->children->content);
-}
-
-
-
-#endif
+*/
 
 static int processEntry(const char *section, const char *entry, xmlNode *node, lpc2xml_context *ctx) {
        const char *content = lp_config_get_string(ctx->lpc, section, entry, NULL);
@@ -129,6 +98,8 @@ static int processEntry(const char *section, const char *entry, xmlNode *node, l
                lpc2xml_log(ctx->ctx, LPC2XML_ERROR, "Issue when reading the lpc");
                return -1;
        }
+       
+       lpc2xml_log(ctx, LPC2XML_MESSAGE, "Set %s|%s = %s", section, entry, content);
        xmlNodeSetContent(node, (const xmlChar *) content);
        return 0;
 }
@@ -154,6 +125,7 @@ static void processSection_cb(const char *entry, struct __processSectionCtx *ctx
                        ctx->ret = -1;
                        return;
                }
+       
                ctx->ret = processEntry(ctx->section, entry, node, ctx->ctx);
        }
 }
@@ -203,7 +175,7 @@ static int processDoc(xmlDoc *doc, lpc2xml_context *ctx) {
                lpc2xml_log(ctx, LPC2XML_ERROR, "Can't create \"config\" element");
                return -1;
        }
-       xmlNs *lpc_ns = xmlNewNs(root_node, (const xmlChar *)"http://www.linphone.org/xsds/lpconfig.xsd", (const xmlChar *)"lpc");
+       xmlNs *lpc_ns = xmlNewNs(root_node, (const xmlChar *)"http://www.linphone.org/xsds/lpconfig.xsd", NULL);
        if(lpc_ns == NULL) {
                lpc2xml_log(ctx, LPC2XML_WARNING, "Can't create lpc namespace");
        } else {
@@ -213,7 +185,7 @@ static int processDoc(xmlDoc *doc, lpc2xml_context *ctx) {
        if(lpc_ns == NULL) {
                lpc2xml_log(ctx, LPC2XML_WARNING, "Can't create xsi namespace");
        }
-       xmlAttr *schemaLocation = xmlNewNsProp(root_node, xsi_ns, (const xmlChar *)"schemaLocation", (const xmlChar *)"http://www.linphone.org/xsds/lpconfig.xsd lpconfig.xsd ");
+       xmlAttr *schemaLocation = xmlNewNsProp(root_node, xsi_ns, (const xmlChar *)"schemaLocation", (const xmlChar *)"http://www.linphone.org/xsds/lpconfig.xsd lpconfig.xsd");
        if(schemaLocation == NULL) {
                lpc2xml_log(ctx, LPC2XML_WARNING, "Can't create schemaLocation");
        }
@@ -246,38 +218,75 @@ int lpc2xml_set_lpc(lpc2xml_context* context, const LpConfig *lpc) {
 }
 
 int lpc2xml_convert_file(lpc2xml_context* context, const char *filename) {
-       int ret = 0;
+       int ret = -1;
+       lpc2xml_context_clear_logs(context);
+       xmlSetGenericErrorFunc(context, lpc2xml_genericxml_error);
        xmlSaveCtxtPtr save_ctx = xmlSaveToFilename(filename, "UTF-8", XML_SAVE_FORMAT);
-       ret = internal_convert_lpc2xml(context);
-       if(ret == 0) {
-               ret = xmlSaveDoc(save_ctx, context->doc);
+       if(save_ctx != NULL) {
+               ret = internal_convert_lpc2xml(context);
+               if(ret == 0) {
+                       ret = xmlSaveDoc(save_ctx, context->doc);
+                       if(ret != 0) {
+                               lpc2xml_log(context, LPC2XML_ERROR, "Can't save document");
+                               lpc2xml_log(context, LPC2XML_ERROR, "%s", context->errorBuffer);
+                       }
+               }
+               xmlSaveClose(save_ctx);
+       } else {
+               lpc2xml_log(context, LPC2XML_ERROR, "Can't open file:%s", filename);
+               lpc2xml_log(context, LPC2XML_ERROR, "%s", context->errorBuffer);
        }
-       xmlSaveClose(save_ctx);
        return ret;
 }
 
 int lpc2xml_convert_fd(lpc2xml_context* context, int fd) {
-       int ret = 0;
+       int ret = -1;
+       lpc2xml_context_clear_logs(context);
+       xmlSetGenericErrorFunc(context, lpc2xml_genericxml_error);
        xmlSaveCtxtPtr save_ctx = xmlSaveToFd(fd, "UTF-8", XML_SAVE_FORMAT);
-       ret = internal_convert_lpc2xml(context);
-       if(ret == 0) {
-               ret = xmlSaveDoc(save_ctx, context->doc);
+       if(save_ctx != NULL) {
+               ret = internal_convert_lpc2xml(context);
+               if(ret == 0) {
+                       ret = xmlSaveDoc(save_ctx, context->doc);
+                       if(ret != 0) {
+                               lpc2xml_log(context, LPC2XML_ERROR, "Can't save document");
+                               lpc2xml_log(context, LPC2XML_ERROR, "%s", context->errorBuffer);
+                       }
+               }
+               xmlSaveClose(save_ctx);
+       } else {
+               lpc2xml_log(context, LPC2XML_ERROR, "Can't open fd:%d", fd);
+               lpc2xml_log(context, LPC2XML_ERROR, "%s", context->errorBuffer);
        }
-       xmlSaveClose(save_ctx);
        return ret;
 }
 
-int lpc2xml_convert_string(lpc2xml_context* context, unsigned char **content) {
-       int ret = 0;
+int lpc2xml_convert_string(lpc2xml_context* context, char **content) {
+       int ret = -1;
        xmlBufferPtr buffer = xmlBufferCreate();
+       lpc2xml_context_clear_logs(context);
+       xmlSetGenericErrorFunc(context, lpc2xml_genericxml_error);
        xmlSaveCtxtPtr save_ctx = xmlSaveToBuffer(buffer, "UTF-8", XML_SAVE_FORMAT);
-       internal_convert_lpc2xml(context);
-       if(ret == 0) {
-               ret = xmlSaveDoc(save_ctx, context->doc);
+       if(save_ctx != NULL) {
+               ret = internal_convert_lpc2xml(context);
+               if(ret == 0) {
+                       ret = xmlSaveDoc(save_ctx, context->doc);
+                       if(ret != 0) {
+                               lpc2xml_log(context, LPC2XML_ERROR, "Can't save document");
+                               lpc2xml_log(context, LPC2XML_ERROR, "%s", context->errorBuffer);
+                       }
+               }
+               xmlSaveClose(save_ctx);
+       } else {
+               lpc2xml_log(context, LPC2XML_ERROR, "Can't initialize internal buffer");
+               lpc2xml_log(context, LPC2XML_ERROR, "%s", context->errorBuffer);
        }
-       xmlSaveClose(save_ctx);
        if(ret == 0) {
-               *content = xmlBufferDetach(buffer);
+#if LIBXML_VERSION >= 20800
+               *content = (char *)xmlBufferDetach(buffer);
+#else
+               *content = strdup((const char *)xmlBufferContent(buffer));
+#endif
        }
        xmlBufferFree(buffer);
        return ret;