1 /* Testing trp message encoding / decoding */
3 /* compiles with: gcc -o msgtst -I../include msgtst.c trp_msg.c $(pkg-config --cflags --libs glib-2.0) ../common/tr_debug.c ../common/tr_name.c ../common/tr_msg.c -ltalloc -ljansson */
8 #include <trust_router/trp.h>
12 #define MAX_MSG_LEN 8192
14 int main(int argc, const char *argv[])
16 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 msg=tr_msg_decode(buf, buflen);
52 /* if (rc==TRP_SUCCESS)
55 printf("\nEncoding...\n");
57 printf("Result: \n%s\n\n", tr_msg_encode(msg));
59 talloc_report_full(main_ctx, stdout);