1 /* Testing trp message encoding / decoding */
3 /* compiles with: gcc -o msgtst -I../include -I../include/trust_router msgtst.c trp_msg.c $(pkg-config --cflags --libs glib-2.0) ../common/tr_debug.c ../common/tr_name.c -ltalloc -ljansson */
8 #include <trp_internal.h>
11 #define MAX_MSG_LEN 8192
13 int main(int argc, const char *argv[])
15 TALLOC_CTX *main_ctx=talloc_new(NULL);
23 printf("Usage: %s <input file>\n\n", argv[0]);
27 buf=malloc(MAX_MSG_LEN);
29 printf("Allocation error.\n\n");
33 f=fopen(argv[1], "r");
35 printf("Error opening %s for reading.\n\n", argv[1]);
39 printf("Reading from %s...\n", argv[1]);
41 buflen=fread(buf, sizeof(char), MAX_MSG_LEN, f);
43 printf("File empty.\n\n");
47 if (buflen>=MAX_MSG_LEN)
48 printf("Warning: file may exceed maximum message length (%d bytes).\n", MAX_MSG_LEN);
50 rc=trp_parse_msg(main_ctx, buf, buflen, &msg);
51 printf("trp_parse_msg returned %d\n\n", rc);
56 printf("\nEncoding...\n");
58 printf("Result: \n%s\n\n", trp_encode_msg(msg));
60 talloc_report_full(main_ctx, stdout);
65 talloc_report_full(main_ctx, stdout);