Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
BC
public
liblinphone
Commits
2cab9fe9
Commit
2cab9fe9
authored
Feb 18, 2016
by
Sylvain Berfini
🐮
Browse files
Try to convert ISO to UTF8 before generating xml entry for LpConfig dump
parent
1c06fe5f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
4 deletions
+43
-4
coreapi/lpc2xml.c
coreapi/lpc2xml.c
+43
-4
No files found.
coreapi/lpc2xml.c
View file @
2cab9fe9
...
...
@@ -24,6 +24,36 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <libxml/xmlversion.h>
#define LPC2XML_BZ 2048
#define ISO_ENCODING "ISO-8859-1"
static
xmlChar
*
convert_iso_to_utf8
(
const
char
*
in
)
{
xmlChar
*
out
=
NULL
;
int
ret
,
size
,
out_size
,
temp
;
xmlCharEncodingHandlerPtr
handler
;
size
=
(
int
)
strlen
(
in
)
+
1
;
out_size
=
size
*
2
-
1
;
out
=
ms_malloc
((
size_t
)
out_size
);
if
(
out
)
{
handler
=
xmlFindCharEncodingHandler
(
ISO_ENCODING
);
if
(
!
handler
)
{
ms_free
(
out
);
return
NULL
;
}
temp
=
size
-
1
;
ret
=
handler
->
input
(
out
,
&
out_size
,
(
const
xmlChar
*
)
in
,
&
temp
);
if
(
ret
<
0
||
temp
-
size
+
1
)
{
ms_free
(
out
);
return
NULL
;
}
else
{
out
=
ms_realloc
(
out
,
out_size
+
1
);
out
[
out_size
]
=
'\0'
;
}
}
return
out
;
}
struct
_lpc2xml_context
{
const
LpConfig
*
lpc
;
...
...
@@ -94,15 +124,24 @@ static void lpc2xml_genericxml_warning(void *ctx, const char *fmt, ...) {
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
);
xmlChar
*
converted_content
=
NULL
;
if
(
content
==
NULL
)
{
lpc2xml_log
(
ctx
,
LPC2XML_ERROR
,
"Issue when reading the lpc"
);
return
-
1
;
}
lpc2xml_log
(
ctx
,
LPC2XML_MESSAGE
,
"Set %s|%s = %s"
,
section
,
entry
,
content
);
// xmlNodeSetContent expects special characters to be escaped, xmlNodeAddContent doesn't (and escapes what needs to be)
xmlNodeSetContent
(
node
,
(
const
xmlChar
*
)
""
);
xmlNodeAddContent
(
node
,
(
const
xmlChar
*
)
content
);
converted_content
=
convert_iso_to_utf8
(
content
);
if
(
converted_content
)
{
// xmlNodeSetContent expects special characters to be escaped, xmlNodeAddContent doesn't (and escapes what needs to be)
xmlNodeSetContent
(
node
,
(
const
xmlChar
*
)
""
);
xmlNodeAddContent
(
node
,
(
const
xmlChar
*
)
converted_content
);
ms_free
(
converted_content
);
}
else
{
// xmlNodeSetContent expects special characters to be escaped, xmlNodeAddContent doesn't (and escapes what needs to be)
xmlNodeSetContent
(
node
,
(
const
xmlChar
*
)
""
);
xmlNodeAddContent
(
node
,
(
const
xmlChar
*
)
content
);
}
if
(
lp_config_get_overwrite_flag_for_entry
(
ctx
->
lpc
,
section
,
entry
)
||
lp_config_get_overwrite_flag_for_section
(
ctx
->
lpc
,
section
))
{
xmlSetProp
(
node
,
(
const
xmlChar
*
)
"overwrite"
,
(
const
xmlChar
*
)
"true"
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment