forked from mirrors/linphone-iphone
Added new functions in lpconfig to dump xml and get a list of sections' names
This commit is contained in:
parent
789bc59ff5
commit
f999712c5b
3 changed files with 52 additions and 8 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue