8000 Add test_libblobstamper executable, move Blob Dump function to Bolb m… · postgrespro/libblobstamper@e6668a6 · GitHub
[go: up one dir, main page]

Skip to content

Commit e6668a6

Browse files
Add test_libblobstamper executable, move Blob Dump function to Bolb methods
1 parent 3adadc7 commit e6668a6

File tree

5 files changed

+86
-26
lines changed

5 files changed

+86
-26
lines changed

Makefile

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,21 @@ ifeq ($(origin CC),default)
77
endif
88

99
.PHONY: all
10-
all: test cpp_test
10+
all: test test_pg_op_wrappers test_libblobstamper
1111
@echo All done!
1212

1313

1414
test: $(LIB_OBJS) test.o
1515
$(CC) $(LDFLAGS) $^ -o $@ $(LDLIBS)
1616

17-
cpp_test: $(LIB_OBJS) cpp_test.o libblobstamper.o pg_op_wrappers.o
17+
test_pg_op_wrappers: $(LIB_OBJS) test_pg_op_wrappers.o libblobstamper.o pg_op_wrappers.o
1818
$(CXX) $(LDFLAGS) $^ -o $@ $(LDLIBS)
1919

20+
test_libblobstamper: $(LIB_OBJS) libblobstamper.o test_libblobstamper.o
21+
$(CXX) $(LDFLAGS) $^ -o $@ $(LDLIBS)
22+
23+
24+
2025
%.o: %.cpp $(DEPS)
2126
$(CXX) -c -g $(CFLAGS) $<
2227

@@ -25,5 +30,5 @@ cpp_test: $(LIB_OBJS) cpp_test.o libblobstamper.o pg_op_wrappers.o
2530

2631
.PHONY: clean
2732
clean:
28-
rm -f *.o test cpp_test
33+
rm -f *.o test test_pg_op_wrappers test_libblobstamper
2934
@echo Clean done!

libblobstamper.cpp

Lines changed: 60 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Blob::Blob (char * data_in, int size_in)
1212
data = data_in;
1313
size = size_in;
1414
begin = 0;
15-
end = size;
15+
end = size -1; /* i.e. size=1 means begin=0 && end=0 */
1616
}
1717

1818
bool
@@ -22,18 +22,68 @@ Blob::isEmpty ()
2222
return false;
2323
}
2424

25-
void
26-
wflBlobDump(Blob blob)
25+
/* Borrowed from http://www.stahlworks.com/dev/index.php?tool=csc01 */
26+
/* Code is not nice for support, better rewrite it */
27+
28+
void hexdump(void *pAddressIn, long lSize)
2729
{
28-
int length = blob.end - blob.begin + 1 ;
29-
char * str =(char *) malloc(length + 1); // second +1 is for \0
30-
// FIXME проверка null
31-
str[0]='\0';
30+
char szBuf[100];
31+
long lIndent = 1;
32+
long lOutLen, lIndex, lIndex2, lOutLen2;
33+
long lRelPos;
34+
struct { char *pData; unsigned long lSize; } buf;
35+
unsigned char *pTmp,ucTmp;
36+
unsigned char *pAddress = (unsigned char *)pAddressIn;
37+
38+
buf.pData = (char *)pAddress;
39+
buf.lSize = lSize;
40+
41+
while (buf.lSize > 0)
42+
{
43+
pTmp = (unsigned char *)buf.pData;
44+
lOutLen = (int)buf.lSize;
45+
if (lOutLen > 16)
46+
lOutLen = 16;
47+
48+
// create a 64-character formatted output line:
49+
sprintf(szBuf, " > "
50+
" "
51+
" %08lX", pTmp-pAddress);
52+
lOutLen2 = lOutLen;
53+
54+
for(lIndex = 1+lIndent, lIndex2 = 53-15+lIndent, lRelPos = 0;
55+
lOutLen2;
56+
lOutLen2--, lIndex += 2, lIndex2++
57+
)
58+
{
59+
ucTmp = *pTmp++;
60+
61+
sprintf(szBuf + lIndex, "%02X ", (unsigned short)ucTmp);
62+
if(!isprint(ucTmp)) ucTmp = '.'; // nonprintable char
63+
szBuf[lIndex2] = ucTmp;
64+
65+
if (!(++lRelPos & 3)) // extra blank after 4 bytes
66+
{ lIndex++; szBuf[lIndex+2] = ' '; }
67+
}
68+
69+
if (!(lRelPos & 3)) lIndex--;
70+
71+
szBuf[lIndex ] = '\t';
72+
szBuf[lIndex+1] = '\t';
73+
74+
printf("%s\n", szBuf);
75+
76+
buf.pData += lOutLen;
77+
buf.lSize -= lOutLen;
78+
}
79+
}
3280

33-
strncat(str, blob.data + blob.begin, length);
3481

35-
printf("%s\n",str);
36-
free(str);
82+
void
83+
Blob::Dump()
84+
{
85+
int length = end - begin +1 ;
86+
hexdump(data + begin, length);
3787
}
3888

3989
Blob

libblobstamper.h

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,20 @@
11

2-
2+
#include <string>
33
class Blob
44
{
55
private:
66
public:
77
Blob(char * data, int size);
88
bool isEmpty ();
9+
void Dump();
910

10-
char * data; /*FIZME потом сделать private*/
11+
char * data; /*FIXME потом сделать private*/
1112
int size;
1213
int begin;
1314
int end;
1415

1516
};
1617

17-
typedef struct wflBlobDsc
18-
{
19-
struct wflMemCtx * mctx;
20-
char * data;
21-
int begin;
22-
int end;
23-
}wflBlobDsc;
24-
25-
26-
void wflBlobDump(wflBlobDsc* blob);
27-
2818
Blob wflShiftN(Blob &blob, size_t n);
2919
std::string wflShiftDouble(Blob &blob);
3020
std::string wflShiftPgPoint(Blob &blob);

test_libblobstamper.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <string.h>
2+
3+
#include "libblobstamper.h"
4+
5+
char my_data[]="1234567890ABCDEFGHIGKLMNOPQRSTUVWXYZabcdefghigklmnopqrstuvwxyzАБВГДитд.___";
6+
7+
int
8+
main(void)
9+
{
10+
Blob bl(my_data, strlen(my_data));
11+
bl.Dump();
12+
13+
14+
return 0;
15+
}
File renamed without changes.

0 commit comments

Comments
 (0)
0