]> sjero.net Git - linphone/blob - tools/xml2lpc_test.c
Update ms2
[linphone] / tools / xml2lpc_test.c
1 /*
2 linphone
3 Copyright (C) 2012 Belledonne Communications SARL
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 */
19
20 #include <stdio.h>
21 #include "xml2lpc.h"
22
23 void cb_function(void *ctx, xml2lpc_log_level level, const char *msg, va_list list) {
24         const char *header = "";
25         switch(level) {
26                 case XML2LPC_DEBUG:
27                         header = "DEBUG";
28                         break;
29                 case XML2LPC_MESSAGE:
30                         header = "MESSAGE";
31                         break;
32                 case XML2LPC_WARNING:
33                         header = "WARNING";
34                         break;
35                 case XML2LPC_ERROR:
36                         header = "ERROR";
37                         break;
38         }
39         fprintf(stdout, "%s - ", header);
40         vfprintf(stdout, msg, list);
41         fprintf(stdout, "\n");
42 }
43
44 void show_usage(int argc, char *argv[]) {
45         fprintf(stderr, "usage %s convert <xml_file> <lpc_file>\n"
46                         "      %s validate <xml_file> <xsd_file>\n", 
47                         argv[0], argv[0]);
48 }
49
50 int main(int argc, char *argv[]) {
51         if(argc != 4) {
52                 show_usage(argc, argv);
53                 return -1;
54         }
55         
56         xml2lpc_context *ctx = xml2lpc_context_new(cb_function, NULL);
57         xml2lpc_set_xml_file(ctx, argv[2]);
58         if(strcmp("convert", argv[1]) == 0) {
59                 LpConfig *lpc = lp_config_new(argv[3]);
60                 xml2lpc_convert(ctx, lpc);
61                 lp_config_sync(lpc);
62                 lp_config_destroy(lpc);
63         } else if(strcmp("validate", argv[1]) == 0) {
64                 xml2lpc_set_xsd_file(ctx, argv[3]);
65                 xml2lpc_validate(ctx);
66         } else {
67                 show_usage(argc, argv);
68         }
69         xml2lpc_context_destroy(ctx);
70         return 0;
71 }
72