File: xml-c14nize.c

package info (click to toggle)
cfengine3 3.24.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 37,552 kB
  • sloc: ansic: 163,161; sh: 10,296; python: 2,950; makefile: 1,744; lex: 784; yacc: 633; perl: 211; pascal: 157; xml: 21; sed: 13
file content (50 lines) | stat: -rw-r--r-- 1,068 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <platform.h>

#include <libxml/parser.h>
#include <libxml/xpathInternals.h>
#include <libxml/c14n.h>

static bool xmlC14nizeFile(const char *filename)
{
    xmlDocPtr doc = xmlParseFile(filename);

    if (doc == NULL)
    {
        fprintf(stderr, "Unable to open %s for canonicalization\n", filename);
        return false;
    }

    xmlOutputBufferPtr out = xmlOutputBufferCreateFile(stdout, NULL);

    if (out == NULL)
    {
        fprintf(stderr, "Unable to set up writer for stdout\n");
        return false;
    }

    if (xmlC14NDocSaveTo(doc, NULL, XML_C14N_1_0, 0, true, out) < 0)
    {
        fprintf(stderr, "Unable to c14nize XML document\n");
        return false;
    }

    if (xmlOutputBufferClose(out) < 0)
    {
        fprintf(stderr, "Unable to close writer for stdout\n");
        return false;
    }

    xmlFreeDoc(doc);
    return true;
}

int main(int argc, char **argv)
{
    if (argc != 2)
    {
        fprintf(stderr, "Usage: xml-c14nize <XML file>\n");
        return 2;
    }

    return xmlC14nizeFile(argv[1]) ? 0 : 1;
}