]> git.ipfire.org Git - thirdparty/squid.git/blame - lib/ntlmauth/support_bits.cci
SourceFormat Enforcement
[thirdparty/squid.git] / lib / ntlmauth / support_bits.cci
CommitLineData
9c89cd13 1/*
4ac4a490 2 * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
9c89cd13
AJ
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
605f2c3e
AJ
9#ifndef SQUID_LIBNTLMAUTH_SUPPORT_BITS_CCI
10#define SQUID_LIBNTLMAUTH_SUPPORT_BITS_CCI
1dcf61eb
AJ
11
12#if HAVE_STRING_H
13#include <string.h>
14#endif
15
16/*
17 * Defines several functions which are used and mutually shared by the NTLM helpers
18 * These do not (yet) have a defined stable home to go to.
19 * For now include this file into helper main .cc where needed.
20 */
21
22/* makes a null-terminated string upper-case. Changes CONTENTS! */
b13b5d03 23inline void
1dcf61eb
AJ
24uc(char *string)
25{
26 char *p = string, c;
27 while ((c = *p)) {
28 *p = xtoupper(c);
f412b2d6 29 ++p;
1dcf61eb
AJ
30 }
31}
32
33/* makes a null-terminated string lower-case. Changes CONTENTS! */
b13b5d03 34inline void
1dcf61eb
AJ
35lc(char *string)
36{
37 char *p = string, c;
38 while ((c = *p)) {
39 *p = xtolower(c);
f412b2d6 40 ++p;
1dcf61eb
AJ
41 }
42}
43
b13b5d03 44inline void
1dcf61eb
AJ
45hex_dump(unsigned char *data, int size)
46{
47 /* dumps size bytes of *data to stdout. Looks like:
48 * [0000] 75 6E 6B 6E 6F 77 6E 20
49 * 30 FF 00 00 00 00 39 00 unknown 0.....9.
50 * (in a single line of course)
51 */
52
53 if (!data)
54 return;
55
56 if (debug_enabled) {
57 unsigned char *p = data;
58 unsigned char c;
59 int n;
60 char bytestr[4] = {0};
61 char addrstr[10] = {0};
62 char hexstr[16 * 3 + 5] = {0};
63 char charstr[16 * 1 + 5] = {0};
f412b2d6 64 for (n = 1; n <= size; ++n) {
1dcf61eb
AJ
65 if (n % 16 == 1) {
66 /* store address for this line */
67 snprintf(addrstr, sizeof(addrstr), "%.4x", (int) (p - data));
68 }
69 c = *p;
70 if (xisalnum(c) == 0) {
71 c = '.';
72 }
73 /* store hex str (for left side) */
74 snprintf(bytestr, sizeof(bytestr), "%02X ", *p);
75 strncat(hexstr, bytestr, sizeof(hexstr) - strlen(hexstr) - 1);
76
77 /* store char str (for right side) */
78 snprintf(bytestr, sizeof(bytestr), "%c", c);
79 strncat(charstr, bytestr, sizeof(charstr) - strlen(charstr) - 1);
80
81 if (n % 16 == 0) {
82 /* line completed */
83 fprintf(stderr, "[%4.4s] %-50.50s %s\n", addrstr, hexstr, charstr);
84 hexstr[0] = 0;
85 charstr[0] = 0;
86 } else if (n % 8 == 0) {
87 /* half line: add whitespaces */
88 strncat(hexstr, " ", sizeof(hexstr) - strlen(hexstr) - 1);
89 strncat(charstr, " ", sizeof(charstr) - strlen(charstr) - 1);
90 }
f412b2d6 91 ++p; /* next byte */
1dcf61eb
AJ
92 }
93
94 if (strlen(hexstr) > 0) {
95 /* print rest of buffer if not empty */
96 fprintf(stderr, "[%4.4s] %-50.50s %s\n", addrstr, hexstr, charstr);
97 }
98 }
13b78018 99
a2b71b22
A
100 if (0) { //temporary hack to keep the linker happy
101 uc(NULL);
102 lc(NULL);
103 hex_dump(NULL,0);
104 }
105
1dcf61eb
AJ
106}
107
605f2c3e 108#endif /* SQUID_LIBNTLMAUTH_SUPPORT_BITS_CCI */
f53969cc 109