Fix FSF address (Tobias Mueller, #470445)
[platform/upstream/evolution-data-server.git] / servers / exchange / lib / ruletest.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2
3 /* Copyright (C) 2003-2004 Novell, Inc.
4  *
5  * This  program is free  software; you  can redistribute  it and/or
6  * modify it under the terms of version 2  of the GNU General Public
7  * License as published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public
15  * License along with this program; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19
20 /* Server-side rule test program */
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <ctype.h>
27 #include <string.h>
28
29 #include "e2k-context.h"
30 #include "e2k-propnames.h"
31 #include "e2k-rule.h"
32 #include "e2k-rule-xml.h"
33 #include "test-utils.h"
34
35 const char *test_program_name = "ruletest";
36
37 static const char *rules_props[] = {
38         PR_RULES_DATA,
39 };
40 static const int n_rules_props = sizeof (rules_props) / sizeof (rules_props[0]);
41
42 void
43 test_main (int argc, char **argv)
44 {
45         const char *url;
46         E2kContext *ctx;
47         E2kHTTPStatus status;
48         E2kResult *results;
49         int nresults;
50         GByteArray *ba;
51         E2kRules *rules;
52         xmlDoc *doc;
53
54         if (argc != 2) {
55                 fprintf (stderr, "Usage: %s URL\n", argv[0]);
56                 exit (1);
57         }
58         url = argv[1];
59
60         ctx = test_get_context (url);
61         status = e2k_context_propfind (ctx, NULL, url,
62                                        rules_props, n_rules_props,
63                                        &results, &nresults);
64         test_abort_if_http_error (status);
65
66         ba = e2k_properties_get_prop (results[0].props, PR_RULES_DATA);
67         if (!ba) {
68                 printf ("No rules\n");
69                 goto done;
70         }
71
72         rules = e2k_rules_from_binary (ba);
73         if (!rules) {
74                 printf ("Could not parse rules\n");
75                 goto done;
76         }
77
78         doc = e2k_rules_to_xml (rules);
79         if (doc) {
80                 xmlDocFormatDump (stdout, doc, TRUE);
81                 xmlFreeDoc (doc);
82         } else
83                 printf ("Could not convert normal rules to XML\n");
84
85         e2k_rules_free (rules);
86         e2k_results_free (results, nresults);
87
88  done:
89         test_quit ();
90 }