]>
Commit | Line | Data |
---|---|---|
1dcf61eb AJ |
1 | #ifndef _SQUID_LIBNTLMAUTH_SUPPORT_BITS_CCI |
2 | #define _SQUID_LIBNTLMAUTH_SUPPORT_BITS_CCI | |
3 | ||
4 | #if HAVE_STRING_H | |
5 | #include <string.h> | |
6 | #endif | |
7 | ||
8 | /* | |
9 | * Defines several functions which are used and mutually shared by the NTLM helpers | |
10 | * These do not (yet) have a defined stable home to go to. | |
11 | * For now include this file into helper main .cc where needed. | |
12 | */ | |
13 | ||
14 | /* makes a null-terminated string upper-case. Changes CONTENTS! */ | |
15 | static void | |
16 | uc(char *string) | |
17 | { | |
18 | char *p = string, c; | |
19 | while ((c = *p)) { | |
20 | *p = xtoupper(c); | |
21 | p++; | |
22 | } | |
23 | } | |
24 | ||
25 | /* makes a null-terminated string lower-case. Changes CONTENTS! */ | |
26 | static void | |
27 | lc(char *string) | |
28 | { | |
29 | char *p = string, c; | |
30 | while ((c = *p)) { | |
31 | *p = xtolower(c); | |
32 | p++; | |
33 | } | |
34 | } | |
35 | ||
36 | static void | |
37 | hex_dump(unsigned char *data, int size) | |
38 | { | |
39 | /* dumps size bytes of *data to stdout. Looks like: | |
40 | * [0000] 75 6E 6B 6E 6F 77 6E 20 | |
41 | * 30 FF 00 00 00 00 39 00 unknown 0.....9. | |
42 | * (in a single line of course) | |
43 | */ | |
44 | ||
45 | if (!data) | |
46 | return; | |
47 | ||
48 | if (debug_enabled) { | |
49 | unsigned char *p = data; | |
50 | unsigned char c; | |
51 | int n; | |
52 | char bytestr[4] = {0}; | |
53 | char addrstr[10] = {0}; | |
54 | char hexstr[16 * 3 + 5] = {0}; | |
55 | char charstr[16 * 1 + 5] = {0}; | |
56 | for (n = 1; n <= size; n++) { | |
57 | if (n % 16 == 1) { | |
58 | /* store address for this line */ | |
59 | snprintf(addrstr, sizeof(addrstr), "%.4x", (int) (p - data)); | |
60 | } | |
61 | c = *p; | |
62 | if (xisalnum(c) == 0) { | |
63 | c = '.'; | |
64 | } | |
65 | /* store hex str (for left side) */ | |
66 | snprintf(bytestr, sizeof(bytestr), "%02X ", *p); | |
67 | strncat(hexstr, bytestr, sizeof(hexstr) - strlen(hexstr) - 1); | |
68 | ||
69 | /* store char str (for right side) */ | |
70 | snprintf(bytestr, sizeof(bytestr), "%c", c); | |
71 | strncat(charstr, bytestr, sizeof(charstr) - strlen(charstr) - 1); | |
72 | ||
73 | if (n % 16 == 0) { | |
74 | /* line completed */ | |
75 | fprintf(stderr, "[%4.4s] %-50.50s %s\n", addrstr, hexstr, charstr); | |
76 | hexstr[0] = 0; | |
77 | charstr[0] = 0; | |
78 | } else if (n % 8 == 0) { | |
79 | /* half line: add whitespaces */ | |
80 | strncat(hexstr, " ", sizeof(hexstr) - strlen(hexstr) - 1); | |
81 | strncat(charstr, " ", sizeof(charstr) - strlen(charstr) - 1); | |
82 | } | |
83 | p++; /* next byte */ | |
84 | } | |
85 | ||
86 | if (strlen(hexstr) > 0) { | |
87 | /* print rest of buffer if not empty */ | |
88 | fprintf(stderr, "[%4.4s] %-50.50s %s\n", addrstr, hexstr, charstr); | |
89 | } | |
90 | } | |
91 | } | |
92 | ||
93 | #endif /* _SQUID_LIBNTLMAUTH_SUPPORT_BITS_CCI */ |