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

This commit is contained in:
2019-04-16 13:48:13 +00:00
parent c6376002ed
commit 10b70f5acf
8 changed files with 88 additions and 30 deletions

View File

@@ -1,29 +1,7 @@
#include "pip.h"
class Base: public PIObject {
PIOBJECT(Base)
public:
EVENT_HANDLER(void, tick) {piCout << "tick";}
};
int main() {
Base b;
PIConnection c;
c.configureFromConfig("d:/orders/nicirt/bin/spec_core.conf", "core");
//CONNECTU(&t, tickEvent, &b, tick);
piCout << "start ...";
c.start();
//t.start(500);
piSleep(3);
//t.stop();
//delete t;
c.stop();
piCout << "deleted";
/*PIEthernet * eth = PIIODevice::createFromFullPath("eth://UDP:::192.168.0.33:16666")->cast<PIEthernet>();
for (;;) {
eth->send(PIByteArray::fromHex("00112233445566778899"));
piSleep(1.5);
}*/
PISystemInfo::machineID();
return 0;
}

View File

@@ -231,8 +231,8 @@ PIInit::PIInit() {
GetSystemInfo(&sysinfo);
sinfo->processorsCount = sysinfo.dwNumberOfProcessors;
switch (sysinfo.wProcessorArchitecture) {
case PROCESSOR_ARCHITECTURE_AMD64: sinfo->architecture = PIStringAscii("x64"); break;
case PROCESSOR_ARCHITECTURE_ARM: sinfo->architecture = PIStringAscii("ARM"); break;
case PROCESSOR_ARCHITECTURE_AMD64: sinfo->architecture = PIStringAscii("x86_64"); break;
case PROCESSOR_ARCHITECTURE_ARM: sinfo->architecture = PIStringAscii("arm"); break;
case PROCESSOR_ARCHITECTURE_IA64: sinfo->architecture = PIStringAscii("Intel Itanium-based"); break;
case PROCESSOR_ARCHITECTURE_INTEL: sinfo->architecture = PIStringAscii("x86"); break;
case PROCESSOR_ARCHITECTURE_UNKNOWN:

View File

@@ -438,6 +438,7 @@ PIByteArray PIString::toCharset(const char * c) const {
PIString & PIString::operator +=(const char * str) {
if (!str) return *this;
int l = 0;
while (str[l] != '\0') ++l;
appendFromChars(str, l);
@@ -446,6 +447,7 @@ PIString & PIString::operator +=(const char * str) {
PIString & PIString::operator +=(const wchar_t * str) {
if (!str) return *this;
//cout << "wc" << endl;
/*int l = 0, sz;
char * c = new char[MB_CUR_MAX];

View File

@@ -396,11 +396,17 @@ PIDir PIDir::home() {
delete[] rc;
return PIDir();
}
PIString s(rc);
s.replaceAll("\\", PIDir::separator);
PIString hp(rc);
memset(rc, 0, 1024);
if (ExpandEnvironmentStrings((LPCTSTR)"%HOMEDRIVE%", (LPTSTR)rc, 1024) == 0) {
delete[] rc;
return PIDir();
}
PIString hd(rc);
hp.replaceAll("\\", PIDir::separator);
delete[] rc;
s.prepend(separator);
return PIDir(s);
//s.prepend(separator);
return PIDir(hd + hp);
#else
# ifndef ESP_PLATFORM
rc = getenv("HOME");

View File

@@ -1110,17 +1110,19 @@ PIEthernet::InterfaceList PIEthernet::interfaces() {
PIStringList inl;
struct ifreq ir;
for (int i = 0; i < icnt; ++i) {
ci.flags = 0;
PIString in = PIStringAscii(ifc.ifc_req[i].ifr_name);
if (in.isEmpty()) continue;
ci.name = in;
strcpy(ir.ifr_name, in.dataAscii());
if (ioctl(s, SIOCGIFHWADDR, &ir) == 0)
ci.mac = macFromBytes(PIByteArray(ir.ifr_hwaddr.sa_data, 6));
ci.mac = macFromBytes(PIByteArray(ir.ifr_hwaddr.sa_data, 6));
if (ioctl(s, SIOCGIFADDR, &ir) >= 0)
ci.address = getSockAddr(&ir.ifr_addr);
if (ioctl(s, SIOCGIFNETMASK, &ir) >= 0)
ci.netmask = getSockAddr(&ir.ifr_addr);
ioctl(s, SIOCGIFMTU, &ci.mtu);
if (ci.address == "127.0.0.1") ci.flags |= PIEthernet::ifLoopback;
il << ci;
}
delete ifc.ifc_buf;

View File

@@ -18,12 +18,16 @@
*/
#include "pisysteminfo.h"
#include "piincludes_p.h"
#include "pidir.h"
#include "picrc.h"
#ifdef ESP_PLATFORM
# include "esp_system.h"
# include "esp_spi_flash.h"
#endif
#define SALT_SIZE 8
PISystemInfo::PISystemInfo() {
processorsCount = 1;
@@ -196,3 +200,66 @@ PIVector<PISystemInfo::MountInfo> PISystemInfo::mountInfo() {
cache = ret;
return ret;
}
PIString confDir() {
return
#ifdef WINDOWS
PIDir::home().path() + "/AppData/Local"
#elif ANDROID
"/mnt/sdcard"
#else
PIDir::home().path() + "/.config"
#endif
;
}
PIByteArray generateSalt() {
PIByteArray ret;
piForTimes (SALT_SIZE) {
piMSleep(randomi() % 10);
randomize();
ret << uchar(randomi() % 0x100);
}
return ret;
}
PIString PISystemInfo::machineKey() {
static PIString ret;
if (ret.isEmpty()) {
PISystemInfo * si = instance();
PIByteArray salt;
PIString conf = confDir() + "/.pip_machine_salt";
if (PIFile::isExists(conf)) {
PIFile f(conf, PIIODevice::ReadOnly);
f.open();
salt = f.readAll();
}
if (salt.size_s() != SALT_SIZE){
salt = generateSalt();
PIFile f(conf, PIIODevice::ReadWrite);
f.open();
f.clear();
f.write(salt);
}
ret = si->OS_name + "_" + si->architecture + "_" + si->hostname + "_" + salt.toHex();
/*PIEthernet::InterfaceList il = PIEthernet::interfaces();
const PIEthernet::Interface * lo = il.getByAddress("127.0.0.1");
if (lo)
ret += lo->mac;*/
}
return ret;
}
uint PISystemInfo::machineID() {
piCout << confDir();
static uint ret = 0;
if (ret == 0) {
CRC_32 crc = standardCRC_32();
ret = crc.calculate(machineKey().toByteArray());
piCout << "machineID \"" << machineKey() << "\" =" << PICoutManipulators::Hex << ret;
}
return ret;
}

View File

@@ -43,6 +43,8 @@ public:
static PIStringList mountRoots();
static PIVector<MountInfo> mountInfo();
static PIString machineKey();
static uint machineID();
static PISystemInfo * instance();

View File

@@ -25,6 +25,7 @@ void usage() {
int main (int argc, char * argv[]) {
PICrypt::hash("");
PICrypt crypt;
PIByteArray bout;
PICLI cli(argc, argv);