root/src/modules/librabbitmq/amqp_debug.c

Revision 1e8ae2b61ace7f9ef47a4f5c190bd2df06b04588, 1.4 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 4 years ago)

initial import of a failover-aware AMQP client courtesy of Circonus

  • Property mode set to 100644
Line 
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4
5 #include <ctype.h>
6
7 static void dump_row(long count, int numinrow, int *chs) {
8   int i;
9
10   printf("%08lX:", count - numinrow);
11
12   if (numinrow > 0) {
13     for (i = 0; i < numinrow; i++) {
14       if (i == 8)
15         printf(" :");
16       printf(" %02X", chs[i]);
17     }
18     for (i = numinrow; i < 16; i++) {
19       if (i == 8)
20         printf(" :");
21       printf("   ");
22     }
23     printf("  ");
24     for (i = 0; i < numinrow; i++) {
25       if (isprint(chs[i]))
26         printf("%c", chs[i]);
27       else
28         printf(".");
29     }
30   }
31   printf("\n");
32 }
33
34 static int rows_eq(int *a, int *b) {
35   int i;
36
37   for (i=0; i<16; i++)
38     if (a[i] != b[i])
39       return 0;
40
41   return 1;
42 }
43
44 void amqp_dump(void const *buffer, size_t len) {
45   unsigned char *buf = (unsigned char *) buffer;
46   long count = 0;
47   int numinrow = 0;
48   int chs[16];
49   int oldchs[16];
50   int showed_dots = 0;
51   int i;
52
53   for (i = 0; i < len; i++) {
54     int ch = buf[i];
55
56     if (numinrow == 16) {
57       int i;
58
59       if (rows_eq(oldchs, chs)) {
60         if (!showed_dots) {
61           showed_dots = 1;
62           printf("          .. .. .. .. .. .. .. .. : .. .. .. .. .. .. .. ..\n");
63         }
64       } else {
65         showed_dots = 0;
66         dump_row(count, numinrow, chs);
67       }
68
69       for (i=0; i<16; i++)
70         oldchs[i] = chs[i];
71
72       numinrow = 0;
73     }
74
75     count++;
76     chs[numinrow++] = ch;
77   }
78
79   dump_row(count, numinrow, chs);
80
81   if (numinrow != 0)
82     printf("%08lX:\n", count);
83 }
Note: See TracBrowser for help on using the browser.