| 1 | /* |
| 2 | * Copyright 2014 Red Hat Inc., Durham, North Carolina. |
| 3 | * All Rights Reserved. |
| 4 | * |
| 5 | * This library is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU Lesser General Public |
| 7 | * License as published by the Free Software Foundation; either |
| 8 | * version 2.1 of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This library 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 GNU |
| 13 | * Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU Lesser General Public |
| 16 | * License along with this library; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | * |
| 19 | * Authors: |
| 20 | * Simon Lukasik <[email protected]> |
| 21 | */ |
| 22 | |
| 23 | #ifdef HAVE_CONFIG_H |
| 24 | #include <config.h> |
| 25 | #endif |
| 26 | |
| 27 | #include <stdio.h> |
| 28 | #include <stdlib.h> |
| 29 | #include <string.h> |
| 30 | #include <oscap_error.h> |
| 31 | #include <oscap_source.h> |
| 32 | #include "oscap_assert.h" |
| 33 | |
| 34 | static unsigned long read_file(char *filename, char **buffer) |
| 35 | { |
| 36 | FILE *file = fopen(filename, "rb"); |
| 37 | oscap_assert(file != NULL); |
| 38 | |
| 39 | fseek(file, 0, SEEK_END); |
| 40 | unsigned long len = ftell(file); |
| 41 | fseek(file, 0, SEEK_SET); |
| 42 | |
| 43 | oscap_assert(buffer != NULL); |
| 44 | *buffer = malloc(len + 1); |
| 45 | oscap_assert(*buffer != NULL); |
| 46 | |
| 47 | fread(*buffer, len, 1, file); |
| 48 | fclose(file); |
| 49 | return len; |
| 50 | } |
| 51 | |
| 52 | |
| 53 | int main(int argc, char *argv[]) |
| 54 | { |
| 55 | oscap_init(); |
| 56 | oscap_assert(argc == 2); |
| 57 | char *buffer; |
| 58 | unsigned long buff_size = read_file(argv[1], &buffer); |
| 59 | oscap_assert(buff_size != 0); |
| 60 | |
| 61 | struct oscap_source *src = oscap_source_new_from_memory(buffer, buff_size, "file.xml.bz2"); |
| 62 | printf("SCAP TYPE: %s\n", oscap_document_type_to_string(oscap_source_get_scap_type(src))); |
| 63 | oscap_assert(oscap_source_validate(src, NULL, NULL) == 0); |
| 64 | oscap_source_free(src); |
| 65 | free(buffer); |
| 66 | |
| 67 | if (oscap_err()) { |
| 68 | char *err = oscap_err_get_full_error(); |
| 69 | fprintf(stderr, "%s", err); |
| 70 | oscap_assert(strlen(err)==0); |
| 71 | free(err); |
| 72 | } |
| 73 | |
| 74 | oscap_cleanup(); |
| 75 | return 0; |
| 76 | } |
| 77 |