git-svn-id: svn://db.shs.com.ru/pip@669 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5

This commit is contained in:
2018-12-10 13:14:56 +00:00
parent 6117efd8a2
commit 3a9d885c29
7 changed files with 39 additions and 259 deletions

View File

@@ -67,16 +67,16 @@ file(READ "${PIP_SRC_MAIN}/piversion.h" VERSION_REVISION LIMIT 1 OFFSET ${VERSIO
file(STRINGS "${PIP_SRC_MAIN}/piversion.h" VERSION_SUFFIX REGEX "\".*\"")
string(REGEX MATCH "\".*\"" VERSION_SUFFIX ${VERSION_SUFFIX})
string(LENGTH ${VERSION_SUFFIX} SL)
math(EXPR SL '${SL}-2')
math(EXPR SL "${SL}-2")
string(SUBSTRING ${VERSION_SUFFIX} 1 ${SL} VERSION_SUFFIX)
string(LENGTH ${VERSION_MAJOR} SL)
math(EXPR SL '${SL}-1')
math(EXPR SL "${SL}-1")
string(SUBSTRING ${VERSION_MAJOR} 0 ${SL} VERSION_MAJOR)
string(LENGTH ${VERSION_MINOR} SL)
math(EXPR SL '${SL}-1')
math(EXPR SL "${SL}-1")
string(SUBSTRING ${VERSION_MINOR} 0 ${SL} VERSION_MINOR)
string(LENGTH ${VERSION_REVISION} SL)
math(EXPR SL '${SL}-1')
math(EXPR SL "${SL}-1")
string(SUBSTRING ${VERSION_REVISION} 0 ${SL} VERSION_REVISION)
set(VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_REVISION}")
set(SOVERSION ${VERSION})
@@ -541,6 +541,12 @@ if(DOXYGEN_FOUND)
set(DOXY_QHP_SECT_FILTER_ATTRS "\"PIP ${_PIP_FULL_VERSION}\"")
set(DOXY_EXAMPLE_PATH "\"${PROJECT_SOURCE_DIR}/doc/examples\"")
set(DOXY_IMAGE_PATH "\"${PROJECT_SOURCE_DIR}/doc/images\"")
if(DOXYGEN_DOT_EXECUTABLE)
string(REPLACE "\\" "" _DOT_PATH "${DOXYGEN_DOT_PATH}")
set(DOXY_DOT_PATH "\"${_DOT_PATH}\"")
set(DOXY_MSCGEN_PATH "\"${_DOT_PATH}\"")
set(DOXY_DIA_PATH "\"${_DOT_PATH}\"")
endif()
set(DOXY_INPUT)
foreach(F ${PIP_SRC_DIRS})
list(APPEND DOXY_INPUT "\"${PROJECT_SOURCE_DIR}/${F}\"")

240
main.cpp
View File

@@ -1,239 +1,13 @@
#include "pip.h"
#include "piauth.h"
/*
class Obj : public PIObject {
PIOBJECT(Obj)
public:
Obj() : PIObject() {}
EVENT_HANDLER2(void, authorizeServer, PIByteArray, info, bool *, ok) {
piCout << "[authorizeServer]" << PIString(info);
//*ok = true;
}
EVENT_HANDLER2(void, passwordCheck, PIByteArray, phash, bool *, ok) {
piCout << "[passwordCheck]" << phash.toHex();
PIByteArray ph = PICrypt::passwordHash("secret", PIByteArray::fromHex("AABBCCDD"));
piCout << "[passwordCheck]" << ph.toHex();
if (phash == ph) *ok = true;
}
EVENT_HANDLER1(void, userEnterPassword, PIString *, password) {
*password = "secret";
piCout << "[userEnterPassword]" << *password;
}
EVENT_HANDLER(void, clientConnect) {
piCout << "clientConnect OK!";
}
EVENT_HANDLER(void, serverConnect) {
piCout << "serverConnect OK!";
}
EVENT_HANDLER1(void, f, int, id) {
piCout << "finished" << id;
}
};
class A: public PIObject {
PIOBJECT(A)
public:
A() {}
EVENT_HANDLER2(void, pcf, int, id, PIString*, buff) {
piCout << "PICout(" << id << ") finished:" << (*buff);
}
};
*/
/*class O {
public:
O() {piCout << "O";}
~O() {piCout << "~O";}
};
class Buffer {
public:
Buffer() {}
template<typename T>
static Buffer create() {
Buffer ret;
ret.data = new T();
ret.pdestroy = (void *)(T::~T);
return ret;
}
void destroy() {}
void * data;
void * pdestroy;
};
class __BufferStorage {
public:
};
*/
int main() {
//Buffer b = Buffer::create<O>();
// PIEvaluator eval, eval2;
// eval.check("1-1*2");
// piCout << eval.evaluate().real();
/*eval.setVariable("t", complexd(1, 2));
eval.check("(t*t*(t<8))+(72*(t>8)-8*(9-t)*(9-t)*(t>8)*(t<8.8))+(3*(t-8.8)*(t>8.8))");
PIByteArray ba = eval.save();
piCout << ba.size();
PITimeMeasurer tm; double us = 0.;
tm.reset();
PIEvaluator e1;
piForTimes(100) {
e1.setVariable("t", complexd(1, 2));
e1.check("(t*t*(t<8))+(72*(t>8)-8*(9-t)*(9-t)*(t>8)*(t<8.8))+(3*(t-8.8)*(t>8.8))");
complexd ret = e1.evaluate();
}
us = tm.elapsed_u(); piCout << "check" << us / 100.;
tm.reset();
PIEvaluator e2;
e2.load(ba);
piForTimes(10000) {
e2.setVariable("t", complexd(1, 2));
complexd ret = e2.evaluate();
}
us = tm.elapsed_u(); piCout << " save" << us / 10000.;*/
/*A a;
CONNECTU(PICout::Notifier::object(), finished, &a, pcf);
PIString buffer = "my buff:";
PICout(&buffer, 1) << "int 10 ->" << 10 << ", time ->" << PITime::current();*/
/*PISerial ser(PISerial::availableDevices(false)[0], PISerial::S115200);
piCout << ser.constructFullPath();
piCout << ser.open();
ser.startThreadedRead();
FOREVER {
piCout << ser.isOpened();
piMSleep(200);
}*/
/*PIVector<PIFile::FileInfo> fl = PIDir::current().allEntries();
PIFile out("out.txt", PIIODevice::ReadWrite);
out.clear();
piForeachC (PIFile::FileInfo & f, fl) {
PIString e = f.extension();
PIString comm;
if (e == "h") comm = PIString::fromUTF8("Заголовочный файл");
if (e == "cpp") comm = PIString::fromUTF8("Файл релизации");
if (e == "ui") comm = PIString::fromUTF8("Форма");
if (e == "qrc") comm = PIString::fromUTF8("Файл ресурсов");
if (comm.isEmpty()) continue;
out << "\n\n" << comm << ": " << f.name() << "\n";
PIFile file(f.name(), PIIODevice::ReadOnly);
while (!file.isEnd()) {
PIString line = file.readLine(), tl = line.trimmed();
if (tl.isEmpty() || tl.startsWith("//")) continue;
out << line << "\n";
}
}*/
return 0;
/*}
int main(int argc, char *argv[]) {
Obj o;
CONNECTU(PICout::Notifier::object(), finished, &o, f);
PIString s = "!!!";
piCout << s;
PICout(&s, 1) << "now" << PIDateTime::current() << ", int 1 =" << 1;
piCout << s;*/
/*piCout << "start";
PICrypt crypt;
PIByteArray skey1, pkey1;
crypt.generateKeypair(pkey1, skey1);
PIByteArray skey2, pkey2;
crypt.generateKeypair(pkey2, skey2);
PIByteArray sign = PIAuth::generateSign(PICrypt::generateKey());
piCout << "sign" << sign.toHex();
piCout << "key1 " << pkey1.toHex() << skey1.toHex();
piCout << "key2 " << pkey2.toHex() << skey2.toHex();
PIString msg = "what the f*ck?";
PIByteArray ba = msg.toUTF8();
piCout << "source" << ba.toHex() << msg;
PIByteArray cba = crypt.crypt(ba, pkey2, skey1);
PIByteArray psign = crypt.extractSignPublicKey(sign);
PIByteArray scba = crypt.signMessage(cba, sign);
piCout << "crypted" << cba.toHex();
piCout << "signed" << scba.toHex() << psign.toHex();
PIByteArray dba = crypt.decrypt(cba, pkey1, skey2);
piCout << "decrypted" << dba.toHex() << PIString(dba);
piCout << "verify" << crypt.verifySign(cba, scba, psign);
cba = crypt.crypt(ba, pkey1, skey2);
piCout << "crypted" << cba.toHex();
//cba[7] = 0;
dba = crypt.decrypt(cba, pkey2, skey1);
piCout << "decrypted" << dba.toHex() << PIString(dba);
piCout << "=======================================";
PIAuth server(PIAuth::generateSign(pkey1));
msg = "This is Server with PIAuth";
server.setInfoData(msg.toUTF8());
PIAuth client(PIAuth::generateSign(pkey2));
client.setAuthorizedPublicKeys(PIVector<PIByteArray>() << server.getSignPublicKey());
// server.setAuthorizedPublicKeys(PIVector<PIByteArray>() << client.getSignPublicKey());
Obj o;
CONNECTU(&client, authorize, &o, authorizeServer);
CONNECTU(&client, passwordRequest, &o, userEnterPassword);
CONNECTU(&server, passwordCheck, &o, passwordCheck);
CONNECTU(&client, connected, &o, clientConnect);
CONNECTU(&server, connected, &o, serverConnect);
client.startClient();
ba = server.startServer();
int st = PIAuth::AuthProbe;
piCout << "server" << st << ba.toHex() << ba.size();*/
// ba[40] = 2;
// {
// int s;
// ba >> s;
// PIByteArray rinfo;
// PIByteArray rsign;
// PIByteArray rsign_pk;
// PIByteArray box_pk;
// PIByteArray noise;
// ba >> rinfo >> rsign_pk >> box_pk >> noise >> rsign;
// ba.clear();
// PIByteArray sign2 = PIAuth::generateSign(PICrypt::generateRandomBuff(100));
// msg = "Server";
// ba << s << msg.toUTF8() << crypt.extractSignPublicKey(sign2) << box_pk << noise;
// rsign = crypt.signMessage(ba, sign2);
// ba << rsign;
// }
/*
st = client.receive(ba);
piCout << "client" << st << ba.toHex() << ba.size();
st = server.receive(ba);
piCout << "server" << st << ba.toHex() << ba.size();
st = client.receive(ba);
piCout << "client" << st << ba.toHex() << ba.size();
st = server.receive(ba);
piCout << "server" << st << ba.toHex() << ba.size();
st = client.receive(ba);
piCout << "client" << st << ba.toHex() << ba.size();
st = server.receive(ba);
piCout << "server" << st << ba.toHex() << ba.size();
st = client.receive(ba);
piCout << "client" << st << ba.toHex() << ba.size();
st = server.receive(ba);
piCout << "server" << st << ba.toHex() << ba.size();*/
PIByteArray msg = PIByteArray::fromHex("0110f0f00001020001");
PIByteArray src = PIByteArray::fromHex("836f");
ushort s; memcpy(&s, src.data(), 2);
//CRC_16 crc = standardCRC_16();
CRC_16 crc = CRC_16(0x8005, 0xFFFF, 0xFFFF, false);
piCout << PICoutManipulators::Hex << s;
piCout << PICoutManipulators::Hex << crc.calculate(msg);
return 0;
}

View File

@@ -272,7 +272,7 @@ void PIKbdListener::readKeyboard() {
MouseButtons mb = getButtons(mer.dwButtonState);
//me.action = getButtons(mer.dwButtonState);
if (mer.dwEventFlags & MOUSE_WHEELED) {
memcpy(&we, &me, sizeof(me));
memcpy((void*)(&we), (const void*)(&me), sizeof(me));
we.action = MouseWheel;
we.direction = short((mer.dwButtonState >> 8) & 0xFFFF) > 0;
//piCout << "wheel" << we.direction;
@@ -305,7 +305,7 @@ void PIKbdListener::readKeyboard() {
me.buttons = mb;
if (piCompareBinary(&prev_me, &me, sizeof(me)))
break;
memcpy(&prev_me, &me, sizeof(me));
memcpy((void*)(&prev_me), (const void*)(&me), sizeof(me));
//PIString _s[] = {"press", "release", "dbl click", "move"};
//piCoutObj << _s[me.action] << me.buttons << ":" << me.x << me.y;
mouseEvent(me, kbddata_);
@@ -363,7 +363,7 @@ void PIKbdListener::readKeyboard() {
me.y = uchar(rc[5] - '!');
int b = rc[3] & 0x7, a = rc[3] & 0x60;
if (a == 0x60) {
memcpy(&we, &me, sizeof(me));
memcpy((void*)(&we), (const void*)(&me), sizeof(me));
we.action = MouseWheel;
we.direction = (b == 0);
//piCout << "wheel" << we.direction;

View File

@@ -235,13 +235,13 @@ public:
alloc(pid_size + 1, true);
if (index < pid_size - 1) {
size_t os = pid_size - index - 1;
memmove(&(pid_data[index + pid_start + 1]), &(pid_data[index + pid_start]), os * sizeof(T));
memmove((void*)(&(pid_data[index + pid_start + 1])), (const void*)(&(pid_data[index + pid_start])), os * sizeof(T));
}
} else {
alloc(pid_size + 1, false, -1);
//piCout << "insert front" << pid_size << pid_rsize << pid_start << "!<";
if (index > 0)
memmove(&(pid_data[pid_start]), &(pid_data[pid_start + 1]), index * sizeof(T));
memmove((void*)(&(pid_data[pid_start])), (const void*)(&(pid_data[pid_start + 1])), index * sizeof(T));
}
//piCout << "insert" << pid_start << index << (pid_start + ssize_t(index)) << pid_size << ">!";
PIINTROSPECTION_CONTAINER_USED(sizeof(T))
@@ -256,7 +256,7 @@ public:
ssize_t os = pid_size - index;
alloc(pid_size + other.pid_size, true);
if (os > 0)
memmove(&(pid_data[index + pid_start + other.pid_size]), &(pid_data[index + pid_start]), os * sizeof(T));
memmove((void*)(&(pid_data[index + pid_start + other.pid_size])), (const void*)(&(pid_data[index + pid_start])), os * sizeof(T));
} else {
//if (pid_start < other.pid_size) pid_start = 0;
//piCout << this << " insert offseted start ba" << pid_start << pid_size << pid_rsize;
@@ -264,7 +264,7 @@ public:
//piCout << this << " insert offseted start aa" << pid_start << pid_size << pid_rsize;
//piCout << this << " insert front" << pid_size << pid_rsize << pid_start << "!<";
if (index > 0)
memmove(&(pid_data[pid_start]), &(pid_data[pid_start + other.pid_size]), index * sizeof(T));
memmove((void*)(&(pid_data[pid_start])), (const void*)(&(pid_data[pid_start + other.pid_size])), index * sizeof(T));
}
//piCout << this << "insert" << pid_start << index << (pid_start + ssize_t(index)) << pid_size << ">!";
newT(pid_data + pid_start + index, other.pid_data + other.pid_start, other.pid_size);
@@ -281,9 +281,9 @@ public:
deleteT(&(pid_data[index + pid_start]), count);
if (os <= index) {
//if (true) {
if (os > 0) memmove(&(pid_data[index + pid_start]), &(pid_data[index + pid_start + count]), os * sizeof(T));
if (os > 0) memmove((void*)(&(pid_data[index + pid_start])), (const void*)(&(pid_data[index + pid_start + count])), os * sizeof(T));
} else {
if (index > 0) memmove(&(pid_data[pid_start + count]), &(pid_data[pid_start]), index * sizeof(T));
if (index > 0) memmove((void*)(&(pid_data[pid_start + count])), (const void*)(&(pid_data[pid_start])), index * sizeof(T));
pid_start += count;
}
pid_size -= count;
@@ -424,7 +424,7 @@ private:
ssize_t ns = (pid_rsize - pid_size) / 2;
if (pid_start != ns) {
//printf("(%p) move %d -> %d\n", this, pid_start, ns);
memmove(pid_data + ns, pid_data + pid_start, pid_size * sizeof(T));
memmove((void*)(pid_data + ns), (const void*)(pid_data + pid_start), pid_size * sizeof(T));
pid_start = ns;
}
}
@@ -433,7 +433,7 @@ private:
ssize_t ns = (pid_rsize - pid_size) / 2;
if (pid_start != ns) {
//printf("(%p) move %d -> %d\n", this, pid_start, ns);
memmove(pid_data + ns, pid_data + pid_start, pid_size * sizeof(T));
memmove((void*)(pid_data + ns), (const void*)(pid_data + pid_start), pid_size * sizeof(T));
pid_start = ns;
}
}
@@ -450,7 +450,7 @@ private:
if (as != pid_rsize) {
//printf("(%p) realloc %d -> %d (%p)\n", this, pid_rsize, as, pid_data);
PIINTROSPECTION_CONTAINER_ALLOC((as-pid_rsize)*sizeof(T))
T * p_d = (T*)(realloc(pid_data, as*sizeof(T)));
T * p_d = (T*)(realloc((void*)(pid_data), as*sizeof(T)));
assert(p_d);
pid_data = p_d;
pid_rsize = as;
@@ -473,7 +473,7 @@ private:
PIINTROSPECTION_CONTAINER_ALLOC((as-pid_rsize)*sizeof(T))
if (pid_rsize > 0 && pid_data != 0) {
//printf("%X copy from %p + %d to %p + %d %d el\n", this, pid_data, pid_start, td, ns, pid_size);
memcpy(td + ns, pid_data + pid_start, pid_size * sizeof(T));
memcpy((void*)(td + ns), (const void*)(pid_data + pid_start), pid_size * sizeof(T));
deleteRaw(pid_data);
}
pid_data = td;
@@ -495,7 +495,7 @@ private:
};
#define __PIDEQUE_SIMPLE_TYPE__(T) \
template<> inline void PIDeque<T>::newT(T * dst, const T * src, size_t s) {PIINTROSPECTION_CONTAINER_USED(s*sizeof(T)); memcpy(dst, src, s * sizeof(T));} \
template<> inline void PIDeque<T>::newT(T * dst, const T * src, size_t s) {PIINTROSPECTION_CONTAINER_USED(s*sizeof(T)); memcpy((void*)(dst), (const void*)(src), s * sizeof(T));} \
template<> inline void PIDeque<T>::deleteT(T * d, size_t sz) {PIINTROSPECTION_CONTAINER_UNUSED(sz*sizeof(T));} \
template<> inline void PIDeque<T>::elementNew(T * to, const T & from) {(*to) = from;} \
template<> inline void PIDeque<T>::elementDelete(T & from) {;} \

View File

@@ -228,7 +228,7 @@ public:
alloc(piv_size + 1);
if (index < piv_size - 1) {
size_t os = piv_size - index - 1;
memmove(&(piv_data[index + 1]), &(piv_data[index]), os * sizeof(T));
memmove((void*)(&(piv_data[index + 1])), (const void*)(&(piv_data[index])), os * sizeof(T));
}
//zeroRaw(&(piv_data[index]), 1);
elementNew(piv_data + index, v);
@@ -239,7 +239,7 @@ public:
ssize_t os = piv_size - index;
alloc(piv_size + other.piv_size);
if (os > 0)
memmove(&(piv_data[index + other.piv_size]), &(piv_data[index]), os * sizeof(T));
memmove((void*)(&(piv_data[index + other.piv_size])), (const void*)(&(piv_data[index])), os * sizeof(T));
newT(piv_data + index, other.piv_data, other.piv_size);
return *this;
}
@@ -252,7 +252,7 @@ public:
}
size_t os = piv_size - index - count;
deleteT(&(piv_data[index]), count);
memmove(&(piv_data[index]), &(piv_data[index + count]), os * sizeof(T));
memmove((void*)(&(piv_data[index])), (const void*)(&(piv_data[index + count])), os * sizeof(T));
piv_size -= count;
return *this;
}
@@ -360,7 +360,7 @@ private:
if (as == piv_rsize) return;
//cout << std::hex << " ![("<<this<<")realloc " << piv_data << " data ... <\n" << endl;
T * p_d = (T*)(realloc(piv_data, as*sizeof(T)));
T * p_d = (T*)(realloc((void*)(piv_data), as*sizeof(T)));
assert(p_d);
piv_data = p_d;
//zeroRaw(&(piv_data[os]), as - os);
@@ -432,7 +432,7 @@ __PIVECTOR_SIMPLE_FUNCTIONS__(float)
__PIVECTOR_SIMPLE_FUNCTIONS__(double)
__PIVECTOR_SIMPLE_FUNCTIONS__(ldouble)*/
#define __PIVECTOR_SIMPLE_TYPE__(T) \
template<> inline void PIVector<T>::newT(T * dst, const T * src, size_t s) {memcpy(dst, src, s * sizeof(T));} \
template<> inline void PIVector<T>::newT(T * dst, const T * src, size_t s) {memcpy((void*)(dst), (const void*)(src), s * sizeof(T));} \
template<> inline void PIVector<T>::deleteT(T * d, size_t sz) {;} \
template<> inline void PIVector<T>::elementNew(T * to, const T & from) {(*to) = from;} \
template<> inline void PIVector<T>::elementDelete(T & from) {;} \

View File

@@ -209,7 +209,7 @@
#define PRIVATE_DEFINITION_END(c) \
}; \
c::__PrivateInitializer__::__PrivateInitializer__() {p = new c::__Private__();} \
c::__PrivateInitializer__::__PrivateInitializer__(const c::__PrivateInitializer__ & o) {if (p) delete p; p = new c::__Private__();} \
c::__PrivateInitializer__::__PrivateInitializer__(const c::__PrivateInitializer__ & o) {/*if (p) delete p;*/ p = new c::__Private__();} \
c::__PrivateInitializer__::~__PrivateInitializer__() {delete p; p = 0;} \
c::__PrivateInitializer__ & c::__PrivateInitializer__::operator =(const c::__PrivateInitializer__ & o) {if (p) delete p; p = new c::__Private__(); return *this;}

View File

@@ -177,7 +177,7 @@ inline PIByteArray & operator <<(PIByteArray & s, const PIByteArray & v) {s << i
inline PIByteArray & operator <<(PIByteArray & s, const PIByteArray::RawData & v) {int os = s.size_s(); s.enlarge(v.s); if (v.s > 0) memcpy(s.data(os), v.d, v.s); return s;}
#undef PBA_OPERATOR_TO
#define PBA_OPERATOR_FROM memcpy(&v, s.data(), sizeof(v)); s.remove(0, sizeof(v));
#define PBA_OPERATOR_FROM memcpy((void*)(&v), s.data(), sizeof(v)); s.remove(0, sizeof(v));
//! \relatesalso PIByteArray \brief Restore operator
inline PIByteArray & operator >>(PIByteArray & s, bool & v) {assert(s.size() >= 1u); v = s.take_front(); return s;}
@@ -212,7 +212,7 @@ template<typename T> inline PIByteArray & operator >>(PIByteArray & s, PIFlags<T
//! \relatesalso PIByteArray \brief Restore operator, see \ref PIByteArray_sec1 for details
inline PIByteArray & operator >>(PIByteArray & s, PIByteArray & v) {assert(s.size_s() >= 4); int sz; s >> sz; v.resize(sz); if (sz > 0) memcpy(v.data(), s.data(), v.size()); s.remove(0, v.size()); return s;}
//! \relatesalso PIByteArray \brief Restore operator, see \ref PIByteArray_sec1 for details
inline PIByteArray & operator >>(PIByteArray & s, PIByteArray::RawData v) {assert(s.size_s() >= v.s); if (v.s > 0) memcpy(v.d, s.data(), v.s); s.remove(0, v.s); return s;}
inline PIByteArray & operator >>(PIByteArray & s, PIByteArray::RawData v) {assert(s.size_s() >= v.s); if (v.s > 0) memcpy((void*)(v.d), s.data(), v.s); s.remove(0, v.s); return s;}
template<typename Type0, typename Type1> inline PIByteArray & operator <<(PIByteArray & s, const PIPair<Type0, Type1> & v);