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

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors