git-svn-id: svn://db.shs.com.ru/pip@355 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -29,6 +29,25 @@
|
||||
#include "picout.h"
|
||||
#include <list>
|
||||
|
||||
#include <malloc.h>
|
||||
#ifndef PIP_MEMALIGN_BYTES
|
||||
# define PIP_MEMALIGN_BYTES (sizeof(void*)*4)
|
||||
#endif
|
||||
#ifdef WINDOWS
|
||||
# ifdef CC_GCC
|
||||
# define amalloc(s) __mingw_aligned_malloc(s, PIP_MEMALIGN_BYTES)
|
||||
# define afree(p) __mingw_aligned_free(p)
|
||||
# else
|
||||
# ifdef CC_VC
|
||||
# define amalloc(s) _aligned_malloc(s, PIP_MEMALIGN_BYTES)
|
||||
# define afree(p) _aligned_free(p)
|
||||
# endif
|
||||
# endif
|
||||
#else
|
||||
# define amalloc(s) aligned_alloc(PIP_MEMALIGN_BYTES, s)
|
||||
# define afree(p) free(p)
|
||||
#endif
|
||||
|
||||
template<typename Type0, typename Type1>
|
||||
class PIP_EXPORT PIPair {
|
||||
public:
|
||||
|
||||
@@ -306,7 +306,7 @@ public:
|
||||
PIDeque<T> & enlarge(llong pid_size) {llong ns = size_s() + pid_size; if (ns <= 0) clear(); else resize(size_t(ns)); return *this;}
|
||||
|
||||
PIDeque<T> & removeOne(const T & v) {for (size_t i = 0; i < pid_size; ++i) if (pid_data[i + pid_start] == v) {remove(i); return *this;} return *this;}
|
||||
PIDeque<T> & removeAll(const T & v) {for (llong i = 0; i < pid_size; ++i) if (pid_data[i + pid_start] == v) {remove(i); --i;} return *this;}
|
||||
PIDeque<T> & removeAll(const T & v) {for (ssize_t i = 0; i < ssize_t(pid_size); ++i) if (pid_data[i + pid_start] == v) {remove(i); --i;} return *this;}
|
||||
|
||||
PIDeque<T> & push_back(const T & v) {alloc(pid_size + 1, true); PIINTROSPECTION_CONTAINER_USED(sizeof(T)); elementNew(pid_data + pid_start + pid_size - 1, v); return *this;}
|
||||
PIDeque<T> & append(const T & v) {return push_back(v);}
|
||||
@@ -416,7 +416,7 @@ private:
|
||||
}
|
||||
}*/
|
||||
//printf("(%p) check move st=%d sz=%d rs=%d\n", this, pid_start, pid_size, pid_rsize);
|
||||
if (pid_start < pid_size + pid_size || pid_start > pid_rsize - pid_size - pid_size) {
|
||||
if (pid_start < ssize_t(pid_size + pid_size) || pid_start > (ssize_t(pid_rsize) - ssize_t(pid_size) - ssize_t(pid_size))) {
|
||||
ssize_t ns = (pid_rsize - pid_size) / 2;
|
||||
if (pid_start != ns) {
|
||||
//printf("(%p) move %d -> %d\n", this, pid_start, ns);
|
||||
|
||||
@@ -274,7 +274,7 @@ public:
|
||||
PIVector<T> & enlarge(llong piv_size) {llong ns = size_s() + piv_size; if (ns <= 0) clear(); else resize(size_t(ns)); return *this;}
|
||||
|
||||
PIVector<T> & removeOne(const T & v) {for (size_t i = 0; i < piv_size; ++i) if (piv_data[i] == v) {remove(i); return *this;} return *this;}
|
||||
PIVector<T> & removeAll(const T & v) {for (llong i = 0; i < piv_size; ++i) if (piv_data[i] == v) {remove(i); --i;} return *this;}
|
||||
PIVector<T> & removeAll(const T & v) {for (ssize_t i = 0; i < ssize_t(piv_size); ++i) if (piv_data[i] == v) {remove(i); --i;} return *this;}
|
||||
|
||||
PIVector<T> & push_back(const T & v) {alloc(piv_size + 1); elementNew(piv_data + piv_size - 1, v); return *this;}
|
||||
PIVector<T> & append(const T & v) {return push_back(v);}
|
||||
|
||||
@@ -97,7 +97,6 @@
|
||||
#ifdef WINDOWS
|
||||
# include <windef.h>
|
||||
# include <winbase.h>
|
||||
# include <malloc.h>
|
||||
# ifdef CC_VC
|
||||
# define SHUT_RDWR 2
|
||||
# pragma comment(lib, "Ws2_32.lib")
|
||||
@@ -113,24 +112,6 @@
|
||||
inline int random() {return rand();}
|
||||
#endif
|
||||
|
||||
#ifndef PIP_MEMALIGN_BYTES
|
||||
# define PIP_MEMALIGN_BYTES (sizeof(void*)*4)
|
||||
#endif
|
||||
#ifdef WINDOWS
|
||||
# ifdef CC_GCC
|
||||
# define amalloc(s) __mingw_aligned_malloc(s, PIP_MEMALIGN_BYTES)
|
||||
# define afree(p) __mingw_aligned_free(p)
|
||||
# else
|
||||
# ifdef CC_VC
|
||||
# define amalloc(s) _aligned_malloc(s, PIP_MEMALIGN_BYTES)
|
||||
# define afree(p) _aligned_free(p)
|
||||
# endif
|
||||
# endif
|
||||
#else
|
||||
# define amalloc(s) aligned_alloc(PIP_MEMALIGN_BYTES, s)
|
||||
# define afree(p) free(p)
|
||||
#endif
|
||||
|
||||
#ifdef ANDROID
|
||||
# define tcdrain(fd) ioctl(fd, TCSBRK, 1)
|
||||
//inline int wctomb(char * c, wchar_t w) {*c = ((char * )&w)[0]; return 1;}
|
||||
@@ -165,9 +146,9 @@
|
||||
# pragma GCC diagnostic ignored "-Waggressive-loop-optimizations"
|
||||
# endif
|
||||
# pragma GCC diagnostic ignored "-Wformat"
|
||||
# pragma GCC diagnostic ignored "-Wformat-extra-args"
|
||||
//# pragma GCC diagnostic ignored "-Wformat-extra-args"
|
||||
# pragma GCC diagnostic ignored "-Wstrict-aliasing"
|
||||
# pragma GCC diagnostic ignored "-Wsign-compare"
|
||||
//# pragma GCC diagnostic ignored "-Wsign-compare"
|
||||
# endif
|
||||
# ifdef ANDROID
|
||||
# pragma GCC diagnostic ignored "-Wunused-parameter"
|
||||
@@ -414,10 +395,15 @@ template<typename T> inline T piLetobe(const T & v) {T tv(v); piLetobe(&tv, size
|
||||
// specialization
|
||||
template<> inline ushort piLetobe(const ushort & v) {return (v << 8) | (v >> 8);}
|
||||
template<> inline uint piLetobe(const uint & v) {return (v >> 24) | ((v >> 8) & 0xFF00) | ((v << 8) & 0xFF0000) | ((v << 24) & 0xFF000000);}
|
||||
template<> inline float piLetobe(const float & f) {
|
||||
uint v = *((uint *)&f);
|
||||
v = (v >> 24) | ((v >> 8) & 0xFF00) | ((v << 8) & 0xFF0000) | ((v << 24) & 0xFF000000);
|
||||
return *((float *)&v);
|
||||
template<> inline float piLetobe(const float & v) {
|
||||
union _pletobe_f {
|
||||
_pletobe_f(const float &f_) {f = f_;}
|
||||
float f;
|
||||
uint v;
|
||||
};
|
||||
_pletobe_f a(v);
|
||||
a.v = (a.v >> 24) | ((a.v >> 8) & 0xFF00) | ((a.v << 8) & 0xFF0000) | ((a.v << 24) & 0xFF000000);
|
||||
return a.f;
|
||||
}
|
||||
|
||||
DEPRECATED inline ushort letobe_s(const ushort & v) {return (v << 8) | (v >> 8);}
|
||||
|
||||
@@ -48,6 +48,9 @@
|
||||
# include <unicode/uclean.h>
|
||||
# include <unicode/ucnv.h>
|
||||
#endif
|
||||
#ifdef CC_GCC
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
/*
|
||||
#ifdef WINDOWS
|
||||
# include <conio.h>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
|
||||
bool PIPropertyStorage::isPropertyExists(const PIString & _name) const {
|
||||
for (int i = 0; i < props.size(); ++i)
|
||||
for (uint i = 0; i < props.size(); ++i)
|
||||
if (props[i].name == _name)
|
||||
return true;
|
||||
return false;
|
||||
@@ -10,7 +10,7 @@ bool PIPropertyStorage::isPropertyExists(const PIString & _name) const {
|
||||
|
||||
|
||||
void PIPropertyStorage::addProperty(const PIPropertyStorage::Property & p) {
|
||||
for (int i = 0; i < props.size(); ++i)
|
||||
for (uint i = 0; i < props.size(); ++i)
|
||||
if (props[i].name == p.name) {
|
||||
props[i] = p;
|
||||
return;
|
||||
@@ -20,7 +20,7 @@ void PIPropertyStorage::addProperty(const PIPropertyStorage::Property & p) {
|
||||
|
||||
|
||||
void PIPropertyStorage::removeProperty(const PIString & _name) {
|
||||
for (int i = 0; i < props.size(); ++i)
|
||||
for (uint i = 0; i < props.size(); ++i)
|
||||
if (props[i].name == _name) {
|
||||
props.remove(i);
|
||||
return;
|
||||
@@ -29,7 +29,7 @@ void PIPropertyStorage::removeProperty(const PIString & _name) {
|
||||
|
||||
|
||||
void PIPropertyStorage::removePropertiesByFlag(int flag) {
|
||||
for (int i = 0; i < props.size(); ++i)
|
||||
for (int i = 0; i < props.size_s(); ++i)
|
||||
if ((props[i].flags & flag) == flag) {
|
||||
props.remove(i);
|
||||
--i;
|
||||
@@ -43,7 +43,7 @@ void PIPropertyStorage::updateProperties(const PIVector<PIPropertyStorage::Prope
|
||||
if (((p.flags & flag_ignore) != flag_ignore) || (flag_ignore == 0))
|
||||
values[p.name] = p.value;
|
||||
props = properties_;
|
||||
for (int i = 0; i < props.size(); ++i) {
|
||||
for (uint i = 0; i < props.size(); ++i) {
|
||||
Property & p(props[i]);
|
||||
if (values.contains(p.name)) {
|
||||
PIVariant pv = values[p.name];
|
||||
@@ -71,7 +71,7 @@ PIVariant PIPropertyStorage::propertyValueByName(const PIString & name) const {
|
||||
|
||||
|
||||
void PIPropertyStorage::setPropertyValue(const PIString & name, const PIVariant & value) {
|
||||
for (int i = 0; i < props.size(); ++i)
|
||||
for (uint i = 0; i < props.size(); ++i)
|
||||
if (props[i].name == name) {
|
||||
props[i].value = value;
|
||||
return;
|
||||
@@ -80,7 +80,7 @@ void PIPropertyStorage::setPropertyValue(const PIString & name, const PIVariant
|
||||
|
||||
|
||||
void PIPropertyStorage::setPropertyComment(const PIString & name, const PIString & comment) {
|
||||
for (int i = 0; i < props.size(); ++i)
|
||||
for (uint i = 0; i < props.size(); ++i)
|
||||
if (props[i].name == name) {
|
||||
props[i].comment = comment;
|
||||
return;
|
||||
@@ -89,7 +89,7 @@ void PIPropertyStorage::setPropertyComment(const PIString & name, const PIString
|
||||
|
||||
|
||||
void PIPropertyStorage::setPropertyFlags(const PIString & name, int flags) {
|
||||
for (int i = 0; i < props.size(); ++i)
|
||||
for (uint i = 0; i < props.size(); ++i)
|
||||
if (props[i].name == name) {
|
||||
props[i].flags = flags;
|
||||
return;
|
||||
|
||||
@@ -193,7 +193,7 @@ public:
|
||||
bool isEnd() const {if (isClosed()) return true; return file.isEnd();}
|
||||
|
||||
//! Returns if BinLog file is empty
|
||||
bool isEmpty() const {return (file.size() <= PIBINARYLOG_SIGNATURE_SIZE + 1);}
|
||||
bool isEmpty() const {return (file.size() <= llong(PIBINARYLOG_SIGNATURE_SIZE + 1));}
|
||||
|
||||
//! Returns BinLog pause status
|
||||
bool isPause() const {return is_pause;}
|
||||
|
||||
@@ -235,7 +235,7 @@ PIVector<PIFile::FileInfo> PIDir::entries() {
|
||||
PIFile::FileInfo fi;
|
||||
DWORD ll = GetLogicalDriveStrings(1023, letters);
|
||||
PIString clet;
|
||||
for (int i = 0; i < ll; ++i) {
|
||||
for (DWORD i = 0; i < ll; ++i) {
|
||||
if (letters[i] == '\0') {
|
||||
clet.resize(2);
|
||||
fi.path = clet;
|
||||
|
||||
@@ -55,7 +55,7 @@ bool PIFileTransfer::send(PIVector<PIFile::FileInfo> entries) {
|
||||
scanning = false;
|
||||
scan_dir.up();
|
||||
//piCout << "files rel to" << d.absolutePath();
|
||||
for (int j = 0; j < fls.size(); j++) {
|
||||
for (uint j = 0; j < fls.size(); j++) {
|
||||
allEntries << PFTFileInfo(fls[j]);
|
||||
allEntries.back().dest_path = scan_dir.relative(fls[j].path);
|
||||
//piCout << " abs path" << fls[j].path;
|
||||
|
||||
@@ -134,7 +134,7 @@ PIString PIPeer::PeerInfo::fastestAddress() const {
|
||||
|
||||
REGISTER_DEVICE(PIPeer)
|
||||
|
||||
PIPeer::PIPeer(const PIString & n): PIIODevice(), eth_tcp_srv(PIEthernet::TCP_Server), eth_tcp_cli(PIEthernet::TCP_Client), diag_s(false), diag_d(false) {
|
||||
PIPeer::PIPeer(const PIString & n): PIIODevice(), inited__(false), eth_tcp_srv(PIEthernet::TCP_Server), eth_tcp_cli(PIEthernet::TCP_Client), diag_s(false), diag_d(false) {
|
||||
//piCout << " PIPeer" << uint(this);
|
||||
destroyed = false;
|
||||
setDebug(false);
|
||||
@@ -429,7 +429,7 @@ void PIPeer::dtReceived(const PIString & from, const PIByteArray & data) {
|
||||
dataReceivedEvent(from, data);
|
||||
if (trust_peer.isEmpty() || trust_peer == from) {
|
||||
read_buffer_mutex.lock();
|
||||
if (read_buffer.size() < read_buffer_size) read_buffer.enqueue(data);
|
||||
if (read_buffer.size_s() < read_buffer_size) read_buffer.enqueue(data);
|
||||
read_buffer_mutex.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,6 +195,7 @@ private:
|
||||
// Data packet: 4, from, to, ticks, data_size, data
|
||||
|
||||
protected:
|
||||
bool inited__; //for internal use
|
||||
PIMutex mc_mutex, eth_mutex, peers_mutex, send_mutex, send_mc_mutex;
|
||||
|
||||
private:
|
||||
|
||||
@@ -28,7 +28,7 @@ const char hash_def_key[] = "_picrypt_";
|
||||
|
||||
PICrypt::PICrypt() {
|
||||
#ifdef PIP_CRYPT
|
||||
sodium_init();
|
||||
if (!sodium_init()) piCout << "[PICrypt]" << "Error while initialize sodium!";
|
||||
nonce_.resize(crypto_secretbox_NONCEBYTES);
|
||||
key_.resize(crypto_secretbox_KEYBYTES);
|
||||
randombytes_buf(key_.data(), key_.size());
|
||||
@@ -77,7 +77,7 @@ PIByteArray PICrypt::crypt(const PIByteArray & data, PIByteArray key) {
|
||||
if (key.size() != crypto_secretbox_KEYBYTES)
|
||||
key.resize(crypto_secretbox_KEYBYTES, ' ');
|
||||
//return PIByteArray();
|
||||
sodium_init();
|
||||
if (!sodium_init()) return retba;
|
||||
PIByteArray n;
|
||||
retba.resize(data.size() + crypto_secretbox_MACBYTES);
|
||||
n.resize(crypto_secretbox_NONCEBYTES);
|
||||
@@ -123,7 +123,7 @@ PIByteArray PICrypt::decrypt(const PIByteArray & crypt_data, PIByteArray key, bo
|
||||
if (ok) *ok = false;
|
||||
return PIByteArray();
|
||||
}
|
||||
sodium_init();
|
||||
if (!sodium_init()) return retba;
|
||||
PIByteArray n;
|
||||
n.resize(crypto_secretbox_NONCEBYTES);
|
||||
retba.resize(crypt_data.size() - n.size() - crypto_secretbox_MACBYTES);
|
||||
@@ -144,7 +144,7 @@ PIByteArray PICrypt::decrypt(const PIByteArray & crypt_data, PIByteArray key, bo
|
||||
PIByteArray PICrypt::hash(const PIString & secret) {
|
||||
PIByteArray hash;
|
||||
#ifdef PIP_CRYPT
|
||||
sodium_init();
|
||||
if (!sodium_init()) return hash;
|
||||
hash.resize(crypto_generichash_BYTES);
|
||||
PIByteArray s(secret.data(), secret.size());
|
||||
crypto_generichash(hash.data(), hash.size(), s.data(), s.size(), (const uchar*)hash_def_key, sizeof(hash_def_key) - 1);
|
||||
@@ -159,7 +159,7 @@ ullong PICrypt::shorthash(const PIString& s, PIByteArray key) {
|
||||
ullong hash = 0;
|
||||
#ifdef PIP_CRYPT
|
||||
if (crypto_shorthash_BYTES != sizeof(hash)) piCout << "[PICrypt]" << "internal error: bad hash size";
|
||||
sodium_init();
|
||||
if (!sodium_init()) return hash;
|
||||
if (key.size() != crypto_shorthash_KEYBYTES) {
|
||||
piCout << "[PICrypt]" << "invalid key size" << key.size() << ", shoud be" << crypto_shorthash_KEYBYTES << ", filled zeros";
|
||||
key.resize(crypto_shorthash_KEYBYTES, 0);
|
||||
@@ -176,7 +176,7 @@ ullong PICrypt::shorthash(const PIString& s, PIByteArray key) {
|
||||
PIByteArray PICrypt::generateKey() {
|
||||
PIByteArray hash;
|
||||
#ifdef PIP_CRYPT
|
||||
sodium_init();
|
||||
if (!sodium_init()) return hash;
|
||||
hash.resize(crypto_secretbox_KEYBYTES);
|
||||
randombytes_buf(hash.data(), hash.size());
|
||||
#else
|
||||
@@ -186,7 +186,7 @@ PIByteArray PICrypt::generateKey() {
|
||||
}
|
||||
|
||||
|
||||
int PICrypt::sizeKey() {
|
||||
size_t PICrypt::sizeKey() {
|
||||
#ifdef PIP_CRYPT
|
||||
return crypto_secretbox_KEYBYTES;
|
||||
#else
|
||||
@@ -196,7 +196,7 @@ int PICrypt::sizeKey() {
|
||||
}
|
||||
|
||||
|
||||
int PICrypt::sizeCrypt() {
|
||||
size_t PICrypt::sizeCrypt() {
|
||||
#ifdef PIP_CRYPT
|
||||
return crypto_secretbox_MACBYTES + crypto_secretbox_NONCEBYTES;
|
||||
#else
|
||||
|
||||
@@ -61,10 +61,10 @@ public:
|
||||
static PIByteArray generateKey();
|
||||
|
||||
//! Returns key size
|
||||
static int sizeKey();
|
||||
static size_t sizeKey();
|
||||
|
||||
//! Returns size which be added to data size in encryption process
|
||||
static int sizeCrypt();
|
||||
static size_t sizeCrypt();
|
||||
|
||||
private:
|
||||
PIByteArray nonce_, key_;
|
||||
|
||||
@@ -115,7 +115,7 @@ public:
|
||||
static _CVector filled(const Type & v) {_CVector vv; PIMV_FOR(i, 0) vv[i] = v; return vv;}
|
||||
|
||||
private:
|
||||
void resize(const Type & new_value = Type()) {for (int i = 0; i < Size; ++i) c[i] = new_value;}
|
||||
void resize(const Type & new_value = Type()) {for (uint i = 0; i < Size; ++i) c[i] = new_value;}
|
||||
|
||||
Type c[Size];
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ PIStringList PISystemInfo::mountRoots() {
|
||||
char letters[1024];
|
||||
DWORD ll = GetLogicalDriveStrings(1023, letters);
|
||||
PIString clet;
|
||||
for (int i = 0; i < ll; ++i) {
|
||||
for (uint i = 0; i < ll; ++i) {
|
||||
if (letters[i] == '\0') {
|
||||
if (clet.size_s() > 2) ret << clet.cutRight(1);
|
||||
clet.clear();
|
||||
@@ -90,7 +90,7 @@ PIVector<PISystemInfo::MountInfo> PISystemInfo::mountInfo() {
|
||||
char letters[1024], volname[1024], volfs[1024];
|
||||
DWORD ll = GetLogicalDriveStrings(1023, letters);
|
||||
PIString clet;
|
||||
for (int i = 0; i < ll; ++i) {
|
||||
for (DWORD i = 0; i < ll; ++i) {
|
||||
if (letters[i] == '\0') {
|
||||
if (GetVolumeInformation(clet.data(), volname, 1023, 0, 0, 0, volfs, 1023)) {
|
||||
m.mount_point = clet;
|
||||
|
||||
@@ -152,10 +152,10 @@ void PISystemMonitor::run() {
|
||||
THREADENTRY32 thread;
|
||||
thread.dwSize = sizeof(THREADENTRY32);
|
||||
if (Thread32First(snap, &thread) == TRUE) {
|
||||
if (thread.th32OwnerProcessID == pID_)
|
||||
if (thread.th32OwnerProcessID == DWORD(pID_))
|
||||
++thcnt;
|
||||
while (Thread32Next(snap, &thread) == TRUE) {
|
||||
if (thread.th32OwnerProcessID == pID_)
|
||||
if (thread.th32OwnerProcessID == DWORD(pID_))
|
||||
++thcnt;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -254,7 +254,7 @@ void Daemon::TileFileProgress::tileEvent(PIScreenTile * t, TileEvent e) {
|
||||
|
||||
|
||||
|
||||
Daemon::Daemon(): inited__(false), PIPeer(pisd_prefix + PISystemInfo::instance()->hostname + "_" + PIString(rand() % 100)) {
|
||||
Daemon::Daemon(): PIPeer(pisd_prefix + PISystemInfo::instance()->hostname + "_" + PIString(rand() % 100)) {
|
||||
// setName("Daemon");
|
||||
dtimer.setName("__S__Daemon_timer");
|
||||
mode = rmNone;
|
||||
|
||||
@@ -182,7 +182,6 @@ private:
|
||||
void requestChDir(const PIString & d);
|
||||
void sendDirToRemote(Remote * r);
|
||||
|
||||
bool inited__;
|
||||
mutable PIStringList available_daemons;
|
||||
PITimer dtimer;
|
||||
PIString conn_name;
|
||||
|
||||
Reference in New Issue
Block a user