git-svn-id: svn://db.shs.com.ru/pip@778 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
24
main.cpp
24
main.cpp
@@ -1,29 +1,7 @@
|
|||||||
#include "pip.h"
|
#include "pip.h"
|
||||||
|
|
||||||
class Base: public PIObject {
|
|
||||||
PIOBJECT(Base)
|
|
||||||
public:
|
|
||||||
EVENT_HANDLER(void, tick) {piCout << "tick";}
|
|
||||||
};
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
Base b;
|
PISystemInfo::machineID();
|
||||||
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);
|
|
||||||
}*/
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -231,8 +231,8 @@ PIInit::PIInit() {
|
|||||||
GetSystemInfo(&sysinfo);
|
GetSystemInfo(&sysinfo);
|
||||||
sinfo->processorsCount = sysinfo.dwNumberOfProcessors;
|
sinfo->processorsCount = sysinfo.dwNumberOfProcessors;
|
||||||
switch (sysinfo.wProcessorArchitecture) {
|
switch (sysinfo.wProcessorArchitecture) {
|
||||||
case PROCESSOR_ARCHITECTURE_AMD64: sinfo->architecture = PIStringAscii("x64"); break;
|
case PROCESSOR_ARCHITECTURE_AMD64: sinfo->architecture = PIStringAscii("x86_64"); break;
|
||||||
case PROCESSOR_ARCHITECTURE_ARM: sinfo->architecture = PIStringAscii("ARM"); break;
|
case PROCESSOR_ARCHITECTURE_ARM: sinfo->architecture = PIStringAscii("arm"); break;
|
||||||
case PROCESSOR_ARCHITECTURE_IA64: sinfo->architecture = PIStringAscii("Intel Itanium-based"); break;
|
case PROCESSOR_ARCHITECTURE_IA64: sinfo->architecture = PIStringAscii("Intel Itanium-based"); break;
|
||||||
case PROCESSOR_ARCHITECTURE_INTEL: sinfo->architecture = PIStringAscii("x86"); break;
|
case PROCESSOR_ARCHITECTURE_INTEL: sinfo->architecture = PIStringAscii("x86"); break;
|
||||||
case PROCESSOR_ARCHITECTURE_UNKNOWN:
|
case PROCESSOR_ARCHITECTURE_UNKNOWN:
|
||||||
|
|||||||
@@ -438,6 +438,7 @@ PIByteArray PIString::toCharset(const char * c) const {
|
|||||||
|
|
||||||
|
|
||||||
PIString & PIString::operator +=(const char * str) {
|
PIString & PIString::operator +=(const char * str) {
|
||||||
|
if (!str) return *this;
|
||||||
int l = 0;
|
int l = 0;
|
||||||
while (str[l] != '\0') ++l;
|
while (str[l] != '\0') ++l;
|
||||||
appendFromChars(str, l);
|
appendFromChars(str, l);
|
||||||
@@ -446,6 +447,7 @@ PIString & PIString::operator +=(const char * str) {
|
|||||||
|
|
||||||
|
|
||||||
PIString & PIString::operator +=(const wchar_t * str) {
|
PIString & PIString::operator +=(const wchar_t * str) {
|
||||||
|
if (!str) return *this;
|
||||||
//cout << "wc" << endl;
|
//cout << "wc" << endl;
|
||||||
/*int l = 0, sz;
|
/*int l = 0, sz;
|
||||||
char * c = new char[MB_CUR_MAX];
|
char * c = new char[MB_CUR_MAX];
|
||||||
|
|||||||
@@ -396,11 +396,17 @@ PIDir PIDir::home() {
|
|||||||
delete[] rc;
|
delete[] rc;
|
||||||
return PIDir();
|
return PIDir();
|
||||||
}
|
}
|
||||||
PIString s(rc);
|
PIString hp(rc);
|
||||||
s.replaceAll("\\", PIDir::separator);
|
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;
|
delete[] rc;
|
||||||
s.prepend(separator);
|
//s.prepend(separator);
|
||||||
return PIDir(s);
|
return PIDir(hd + hp);
|
||||||
#else
|
#else
|
||||||
# ifndef ESP_PLATFORM
|
# ifndef ESP_PLATFORM
|
||||||
rc = getenv("HOME");
|
rc = getenv("HOME");
|
||||||
|
|||||||
@@ -1110,17 +1110,19 @@ PIEthernet::InterfaceList PIEthernet::interfaces() {
|
|||||||
PIStringList inl;
|
PIStringList inl;
|
||||||
struct ifreq ir;
|
struct ifreq ir;
|
||||||
for (int i = 0; i < icnt; ++i) {
|
for (int i = 0; i < icnt; ++i) {
|
||||||
|
ci.flags = 0;
|
||||||
PIString in = PIStringAscii(ifc.ifc_req[i].ifr_name);
|
PIString in = PIStringAscii(ifc.ifc_req[i].ifr_name);
|
||||||
if (in.isEmpty()) continue;
|
if (in.isEmpty()) continue;
|
||||||
ci.name = in;
|
ci.name = in;
|
||||||
strcpy(ir.ifr_name, in.dataAscii());
|
strcpy(ir.ifr_name, in.dataAscii());
|
||||||
if (ioctl(s, SIOCGIFHWADDR, &ir) == 0)
|
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)
|
if (ioctl(s, SIOCGIFADDR, &ir) >= 0)
|
||||||
ci.address = getSockAddr(&ir.ifr_addr);
|
ci.address = getSockAddr(&ir.ifr_addr);
|
||||||
if (ioctl(s, SIOCGIFNETMASK, &ir) >= 0)
|
if (ioctl(s, SIOCGIFNETMASK, &ir) >= 0)
|
||||||
ci.netmask = getSockAddr(&ir.ifr_addr);
|
ci.netmask = getSockAddr(&ir.ifr_addr);
|
||||||
ioctl(s, SIOCGIFMTU, &ci.mtu);
|
ioctl(s, SIOCGIFMTU, &ci.mtu);
|
||||||
|
if (ci.address == "127.0.0.1") ci.flags |= PIEthernet::ifLoopback;
|
||||||
il << ci;
|
il << ci;
|
||||||
}
|
}
|
||||||
delete ifc.ifc_buf;
|
delete ifc.ifc_buf;
|
||||||
|
|||||||
@@ -18,12 +18,16 @@
|
|||||||
*/
|
*/
|
||||||
#include "pisysteminfo.h"
|
#include "pisysteminfo.h"
|
||||||
#include "piincludes_p.h"
|
#include "piincludes_p.h"
|
||||||
|
#include "pidir.h"
|
||||||
|
#include "picrc.h"
|
||||||
|
|
||||||
#ifdef ESP_PLATFORM
|
#ifdef ESP_PLATFORM
|
||||||
# include "esp_system.h"
|
# include "esp_system.h"
|
||||||
# include "esp_spi_flash.h"
|
# include "esp_spi_flash.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define SALT_SIZE 8
|
||||||
|
|
||||||
|
|
||||||
PISystemInfo::PISystemInfo() {
|
PISystemInfo::PISystemInfo() {
|
||||||
processorsCount = 1;
|
processorsCount = 1;
|
||||||
@@ -196,3 +200,66 @@ PIVector<PISystemInfo::MountInfo> PISystemInfo::mountInfo() {
|
|||||||
cache = ret;
|
cache = ret;
|
||||||
return 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;
|
||||||
|
}
|
||||||
|
|||||||
@@ -43,6 +43,8 @@ public:
|
|||||||
|
|
||||||
static PIStringList mountRoots();
|
static PIStringList mountRoots();
|
||||||
static PIVector<MountInfo> mountInfo();
|
static PIVector<MountInfo> mountInfo();
|
||||||
|
static PIString machineKey();
|
||||||
|
static uint machineID();
|
||||||
|
|
||||||
static PISystemInfo * instance();
|
static PISystemInfo * instance();
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ void usage() {
|
|||||||
|
|
||||||
|
|
||||||
int main (int argc, char * argv[]) {
|
int main (int argc, char * argv[]) {
|
||||||
|
PICrypt::hash("");
|
||||||
PICrypt crypt;
|
PICrypt crypt;
|
||||||
PIByteArray bout;
|
PIByteArray bout;
|
||||||
PICLI cli(argc, argv);
|
PICLI cli(argc, argv);
|
||||||
|
|||||||
Reference in New Issue
Block a user