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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
/* This is a tool for dumpoing the content of GuardTime TLV
* files in a (somewhat) human-readable manner.
*
* Copyright 2013 Adiscon GmbH
*
* This file is part of rsyslog.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* -or-
* see COPYING.ASL20 in the source distribution
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either exprs or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <gt_base.h>
#include <gt_http.h>
#include "librsgt.h"
typedef unsigned char uchar;
void
processFile(char *name)
{
FILE *fp;
uchar hdr[9];
uint16_t tlvtype, tlvlen;
void *obj;
if(!strcmp(name, "-"))
fp = stdin;
else {
printf("Processing file %s:\n", name);
if((fp = fopen(name, "r")) == NULL) {
perror(name);
goto err;
}
}
if(rsgt_tlvrdHeader(fp, hdr) != 0) goto err;
printf("File Header: '%s'\n", hdr);
while(1) { /* we will err out on EOF */
if(rsgt_tlvrd(fp, &tlvtype, &tlvlen, &obj) != 0) {
if(feof(fp))
break;
else
goto err;
}
rsgt_tlvprint(stdout, tlvtype, obj, 0);
}
if(fp != stdin)
fclose(fp);
return;
err: fprintf(stderr, "error processing file %s\n", name);
}
int
main(int argc, char *argv[])
{
int i;
if(argc == 1)
processFile("-");
else {
for(i = 1 ; i < argc ; ++i)
processFile(argv[i]);
}
return 0;
}
|