Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
BC
public
liblinphone
Commits
f999712c
Commit
f999712c
authored
Oct 21, 2015
by
Sylvain Berfini
🎩
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added new functions in lpconfig to dump xml and get a list of sections' names
parent
789bc59f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
8 deletions
+52
-8
coreapi/lpconfig.c
coreapi/lpconfig.c
+23
-1
coreapi/lpconfig.h
coreapi/lpconfig.h
+20
-0
tools/lpc2xml_test.c
tools/lpc2xml_test.c
+9
-7
No files found.
coreapi/lpconfig.c
View file @
f999712c
...
...
@@ -56,7 +56,7 @@
#define lp_new0(type,n) (type*)calloc(sizeof(type),n)
#include "lpconfig.h"
#include "lpc2xml.h"
typedef
struct
_LpItem
{
char
*
key
;
...
...
@@ -877,3 +877,25 @@ err:
if
(
realfilepath
)
ms_free
(
realfilepath
);
return
-
1
;
}
static
void
get_sections_names_cb
(
const
char
*
section
,
void
*
ctx
)
{
MSList
**
list
=
(
MSList
**
)
ctx
;
*
list
=
ms_list_append
(
*
list
,
(
void
*
)
ms_strdup
(
section
));
}
const
MSList
*
lp_config_get_sections_names
(
LpConfig
*
lpconfig
)
{
MSList
*
result
=
NULL
;
lp_config_for_each_section
(
lpconfig
,
get_sections_names_cb
,
&
result
);
return
result
;
}
char
*
lp_config_dump_as_xml
(
const
LpConfig
*
lpconfig
)
{
char
*
buffer
;
lpc2xml_context
*
ctx
=
lpc2xml_context_new
(
NULL
,
NULL
);
lpc2xml_set_lpc
(
ctx
,
lpconfig
);
lpc2xml_convert_string
(
ctx
,
&
buffer
);
lpc2xml_context_destroy
(
ctx
);
return
buffer
;
}
\ No newline at end of file
coreapi/lpconfig.h
View file @
f999712c
...
...
@@ -200,6 +200,17 @@ LINPHONE_PUBLIC int lp_config_has_section(const LpConfig *lpconfig, const char *
**/
LINPHONE_PUBLIC
void
lp_config_clean_section
(
LpConfig
*
lpconfig
,
const
char
*
section
);
/**
* Returns the list of the sections' names in the config.
* @param[in] lpconfig The LpConfig object
* @return \mslist{const char*}
*
* This list is unmodifiable. The ->data field of the MSList points to a const char*.
*
* @ingroup misc
**/
LINPHONE_PUBLIC
const
MSList
*
lp_config_get_sections_names
(
LpConfig
*
lpconfig
);
/**
* Call a function for each section present in the configuration.
*
...
...
@@ -295,6 +306,15 @@ LINPHONE_PUBLIC int lp_config_read_relative_file(const LpConfig *lpconfig, const
**/
LINPHONE_PUBLIC
bool_t
lp_config_relative_file_exists
(
const
LpConfig
*
lpconfig
,
const
char
*
filename
);
/**
* Dumps the LpConfig as XML into a buffer
* @param[in] lpconfig The LpConfig object
* @return The buffer that contains the XML dump
*
* @ingroup misc
**/
LINPHONE_PUBLIC
char
*
lp_config_dump_as_xml
(
const
LpConfig
*
lpconfig
);
#ifdef __cplusplus
}
#endif
...
...
tools/lpc2xml_test.c
View file @
f999712c
...
...
@@ -42,28 +42,30 @@ void cb_function(void *ctx, lpc2xml_log_level level, const char *msg, va_list li
}
void
show_usage
(
int
argc
,
char
*
argv
[])
{
fprintf
(
stderr
,
"usage %s convert <lpc_file> <xml_file>
\n
"
,
argv
[
0
]);
fprintf
(
stderr
,
"usage:
\n
%s convert <lpc_file> <xml_file>
\n
%s dump <lpc_file>
\n
"
,
argv
[
0
],
argv
[
0
]);
}
int
main
(
int
argc
,
char
*
argv
[])
{
lpc2xml_context
*
ctx
;
LpConfig
*
lpc
;
if
(
argc
!=
4
)
{
if
(
argc
>
4
||
argc
<
3
)
{
show_usage
(
argc
,
argv
);
return
-
1
;
}
ctx
=
lpc2xml_context_new
(
cb_function
,
NULL
);
lpc
=
lp_config_new
(
argv
[
2
]);
lpc2xml_set_lpc
(
ctx
,
lpc
);
if
(
strcmp
(
"convert"
,
argv
[
1
])
==
0
)
{
if
(
strcmp
(
"convert"
,
argv
[
1
])
==
0
&&
argc
==
4
)
{
ctx
=
lpc2xml_context_new
(
cb_function
,
NULL
);
lpc2xml_convert_file
(
ctx
,
argv
[
3
]);
lpc2xml_set_lpc
(
ctx
,
lpc
);
lpc2xml_context_destroy
(
ctx
);
}
else
if
(
strcmp
(
"dump"
,
argv
[
1
])
==
0
&&
argc
==
3
)
{
char
*
dump
=
lp_config_dump_as_xml
(
lpc
);
fprintf
(
stdout
,
"%s"
,
dump
);
}
else
{
show_usage
(
argc
,
argv
);
}
lp_config_destroy
(
lpc
);
lpc2xml_context_destroy
(
ctx
);
return
0
;
}
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