std::string Building::get_citygml_imgeo_number() { std::stringstream ss; std::string attribute; bool btekst, bplaatsingspunt, bhoek, blaagnr, bhoognr; std::string tekst, plaatsingspunt, hoek, laagnr, hoognr; btekst = get_attribute("tekst", tekst); bplaatsingspunt = get_attribute("plaatsingspunt", plaatsingspunt); bhoek = get_attribute("hoek", hoek); blaagnr = get_attribute("identificatiebagvbolaagstehuisnummer", laagnr); bhoognr = get_attribute("identificatiebagvbohoogstehuisnummer", hoognr); if (btekst) { // Split the lists into vector of strings std::vector<std::string> tekst_split, plaatsingspunt_split, hoek_split, laagnr_split, hoognr_split; tekst_split = stringsplit(tekst.substr(3, tekst.size() - 4), ','); if (bplaatsingspunt) { plaatsingspunt_split = stringsplit(plaatsingspunt.substr(3, plaatsingspunt.size() - 4), ','); } if (bhoek) { hoek_split = stringsplit(hoek.substr(3, hoek.size() - 4), ','); } if (blaagnr) { laagnr_split = stringsplit(laagnr.substr(3, laagnr.size() - 4), ','); } if (bhoognr) { hoognr_split = stringsplit(hoognr.substr(3, hoognr.size() - 4), ','); } //Get the amount of text in the StringList and write all List values separate int count = boost::lexical_cast<int>(tekst[1]); for (int i = 0; i < count; i++) { if (i < tekst_split.size() && i < plaatsingspunt_split.size() && i < hoek_split.size()) { ss << "<imgeo:nummeraanduidingreeks>" << std::endl; ss << "<imgeo:Nummeraanduidingreeks>" << std::endl; ss << "<imgeo:nummeraanduidingreeks>" << std::endl; ss << "<imgeo:Label>" << std::endl; ss << "<imgeo:tekst>" << tekst_split.at(i) << "</imgeo:tekst>" << std::endl; ss << "<imgeo:positie>" << std::endl; ss << "<imgeo:Labelpositie>" << std::endl; ss << "<imgeo:plaatsingspunt><gml:Point srsDimension=\"2\"><gml:pos>" << plaatsingspunt_split.at(i) << "</gml:pos></gml:Point></imgeo:plaatsingspunt>" << std::endl; ss << "<imgeo:hoek>" << hoek_split.at(i) << "</imgeo:hoek>" << std::endl; ss << "</imgeo:Labelpositie>" << std::endl; ss << "</imgeo:positie>" << std::endl; ss << "</imgeo:Label>" << std::endl; ss << "</imgeo:nummeraanduidingreeks>" << std::endl; if (i < laagnr_split.size()) { ss << "<imgeo:identificatieBAGVBOLaagsteHuisnummer>" << laagnr_split.at(i) << "</imgeo:identificatieBAGVBOLaagsteHuisnummer>" << std::endl; } if (i < hoognr_split.size()) { ss << "<imgeo:identificatieBAGVBOHoogsteHuisnummer>" << hoognr_split.at(i) << "</imgeo:identificatieBAGVBOHoogsteHuisnummer>" << std::endl; } ss << "</imgeo:Nummeraanduidingreeks>" << std::endl; ss << "</imgeo:nummeraanduidingreeks>" << std::endl; } } } return ss.str(); }
void AL_renderInfo(char *str, SDL_Renderer *mainRenderer){ SDL_Color color = {0x57, 0x30, 0x00, 0xff}; char stringArray[4][60]; TTF_Font *fontFile; int x = 250, y = 570; stringsplit(str, stringArray); int i; AL_renderFont(mainRenderer, color, gFontFile25, x + 12, y + i * 30, stringArray[0]); for (i = 1; i < 3; i++){ AL_renderFont(mainRenderer, color, gFontFile25, x, y + i * 30, stringArray[i]); } }
P2PServerUDPSettings::P2PServerUDPSettings(uint8_t *privatekey, uint8_t *ca_publickey, uint8_t *ca_signature) : settings("p2p.xml"), port(0) { if(!settings.contains("privatekey")) { genPrivateKey(privatekey); settings.setValue("privatekey",binarytoHexa(privatekey,sizeof(privatekey))); } else { const std::vector<char> tempData=hexatoBinary(settings.value("privatekey")); if(tempData.size()==ED25519_KEY_SIZE) memcpy(privatekey,tempData.data(),ED25519_KEY_SIZE); else { genPrivateKey(privatekey); settings.setValue("privatekey",binarytoHexa(privatekey,sizeof(privatekey))); settings.sync(); } } if(!settings.contains("ca_signature")) { std::cerr << "You need define CA signature of your public key" << std::endl; settings.setValue("ca_signature",""); settings.sync(); abort(); } else { const std::vector<char> tempData=hexatoBinary(settings.value("ca_signature")); if(tempData.size()==ED25519_SIGNATURE_SIZE) memcpy(ca_signature,tempData.data(),ED25519_SIGNATURE_SIZE); else { std::cerr << "You need define CA signature of your public key " << std::to_string(tempData.size()) << "!=" << std::to_string(ED25519_SIGNATURE_SIZE) << std::endl; abort(); } } if(!settings.contains("ca_publickey")) { std::cerr << "You need define CA public key" << std::endl; settings.setValue("ca_publickey",""); settings.sync(); abort(); } else { const std::vector<char> tempData=hexatoBinary(settings.value("ca_publickey")); if(tempData.size()==ED25519_KEY_SIZE) memcpy(ca_publickey,tempData.data(),ED25519_KEY_SIZE); else { std::cerr << "You need define CA public key " << std::to_string(tempData.size()) << "!=" << std::to_string(ED25519_KEY_SIZE) << std::endl; abort(); } } if(!settings.contains("known_node")) settings.setValue("known_node",""); if(!settings.contains("port")) settings.setValue("port",rand()%40000+10000); port=stringtouint16(settings.value("port")); const std::vector<std::string> &known_nodes=stringsplit(settings.value("known_node"),','); if((known_nodes.size()%2)!=0) { std::cerr << "(known_nodes.size()%2)!=0" << std::endl; abort(); } size_t index=0; while(index<known_nodes.size()) { bool ok=false; P2PServerUDP::HostToConnect hostToConnect; const std::string host=known_nodes.at(index); const std::string &portstring=known_nodes.at(index+1); const uint16_t port=stringtouint16(portstring,&ok); if(ok) { sockaddr_in6 serv_addr; memset(&serv_addr, 0, sizeof(serv_addr)); serv_addr.sin6_port = htobe16(port); const char * const hostC=host.c_str(); int convertResult=inet_pton(AF_INET6,hostC,&serv_addr.sin6_addr); if(convertResult!=1) { convertResult=inet_pton(AF_INET,hostC,&serv_addr.sin6_addr); if(convertResult!=1) std::cerr << "not IPv4 and IPv6 address, host: \"" << host << "\", portstring: \"" << portstring << "\", errno: " << std::to_string(errno) << std::endl; else serv_addr.sin6_family = AF_INET; } else serv_addr.sin6_family = AF_INET6; if(convertResult==1) { hostToConnect.round=0; hostToConnect.serv_addr=serv_addr; hostToConnect.serialised_serv_addr=P2PServerUDP::sockSerialised(serv_addr); const std::string &serialisedPeer=P2PPeer::toString(serv_addr,","); knownPeers.insert(serialisedPeer); if(serialisedPeer!=(host+",",portstring)) std::cerr << serialisedPeer <<"!=" << (host+",",portstring) << ", ip list change" << std::endl; //pass to temp list because P2PServerUDP::p2pserver not init for now hostToConnectTemp.push_back(hostToConnect); } } index+=2; } settings.sync(); setKey(privatekey,ca_publickey,ca_signature); }
void InpNativeInfo::read_block(std::ifstream& ifs) { // bool read(false); while(!ifs.eof()) { std::string line; std::getline(ifs, line); if(line.empty()) continue; if(line[0] == '\x2a') continue; if(eq_ignorecase(line.substr(0,14), "NINFO(all/all)")) { style = ALL_IN_ONE; iUnits iunits = std::make_pair(0,0); std::vector<std::string> subline = stringsplit(line, ' '); for(auto iter = subline.begin(); iter != subline.end(); ++iter) { if(iter->substr(iter->size()-6, 6) == "\x2eninfo") { // read = true; ninfo_files[iunits] = *iter; return; } } throw std::invalid_argument("read_block: cant find ninfo file"); } else if(line.substr(0,6) == "NINFO(") { if(style != ONE_BY_ONE) style = ONE_BY_ONE; std::vector<std::string> iunit1_str = stringsplit(line, '/', 6); std::vector<std::string> iunit2_str = stringsplit(iunit1_str.at(1), ')'); int iunit1(std::stoi(iunit1_str.at(0))); int iunit2(std::stoi(iunit2_str.at(0))); std::vector<std::string> filename = stringsplit(line, ' '); iUnits iunits = std::make_pair(iunit1, iunit2); for(auto itr = filename.begin(); itr != filename.end(); ++itr) { if(itr->substr(itr->size()-6, 6) == "\x2eninfo") { // read = true; ninfo_files[iunits] = *itr; break; } } } else if(line.substr(0,4) == ">>>>") { // read = true; break; } else { std::cout << "Error: Unknown line" << std::endl; std::cout << line << std::endl; } } return; }
/** * main: main function for dcon * * flags: * -a <addr> listen on specific IP address (default INADDR_ANY) * -p <port> listen on the specified port (default to random port) * -f <fmt> output format code (default 'dhtflm') * * format letters: * d=date, h=host, H=host w/domain stripped, t=tag, * f=facility, l=level, m=message, s=src_ip * * -l <log> logfile output is copied to (default=none) */ int main(int argc, char **argv) { char *ipstr, *portstr; static const char *fmt = "dhtflm"; char *logfile; int c, errflg, len; socklen_t slen; struct sockaddr_in ip; struct hostent *he; int udpsock; #define BIG (1024*1024) char bigbuf[BIG], tmpbuf[64]; char *chunks[6]; const char *f; char *ptr; errflg = 0; ipstr = portstr = logfile = 0; while ((c = getopt(argc, argv, "a:p:f:l:")) != -1) { switch (c) { case 'a': ipstr = optarg; break; case 'p': if (*optarg < '0' || *optarg > '9') { fprintf(stderr, "invalid port: %s\n", optarg); errflg++; } portstr = optarg; break; case 'f': fmt = optarg; break; case 'l': logfile = optarg; break; case '?': fprintf(stderr, "unknown option: -%c\n", optopt); errflg++; break; } } if (errflg) { fprintf(stderr, "usage: %s [options]\n", *argv); fprintf(stderr, "\t-a <addr> listen on addr (default=INADDR_ANY)\n"); fprintf(stderr, "\t-p <port> listen on port (default=random)\n"); fprintf(stderr, "\t-f <fmt> output format\n"); fprintf(stderr, "\t-l <log> output logfile\n"); fprintf(stderr, "\n\tformat: d=date, h=host, H=host (no domain),\n"); fprintf(stderr, "\tt=tag, f=facility, l=level, m=message, s=src_ip\n"); exit(1); } /* * start parsing */ memset(&ip, 0, sizeof(ip)); ip.sin_family = AF_INET; if (!ipstr) { ip.sin_addr.s_addr = INADDR_ANY; } else { if (*ipstr >= '0' && *ipstr <= '9') { ip.sin_addr.s_addr = inet_addr(ipstr); if (ip.sin_addr.s_addr == 0 || ip.sin_addr.s_addr == ((in_addr_t) -1)) { fprintf(stderr, "dcon: invalid host %s\n", ipstr); exit(1); } } else { he = gethostbyname(ipstr); if (!he || he->h_addrtype != AF_INET || he->h_length != sizeof(in_addr_t) || !he->h_addr) { fprintf(stderr, "dcon: invalid host %s\n", ipstr); exit(1); } memcpy(&ip.sin_addr.s_addr, he->h_addr, he->h_length); } } if (portstr) { ip.sin_port = htons(atoi(portstr)); } if (logfile) { logfp = fopen(logfile, "a"); if (!logfp) { fprintf(stderr, "fopen: %s: %s\n", logfile, strerror(errno)); exit(1); } } /* * setup udp socket */ udpsock = socket(PF_INET, SOCK_DGRAM, 0); if (udpsock < 0) { } if (bind(udpsock, (struct sockaddr *)&ip, sizeof(ip)) < 0) { fprintf(stderr, "dcon: bind: %s\n", strerror(errno)); exit(1); } slen = sizeof(ip); if (getsockname(udpsock, (struct sockaddr *)&ip, &slen) < 0) { fprintf(stderr, "dcon: getsockname: %s\n", strerror(errno)); exit(1); } printf("dcon listening on %s:%d, logfile=%s, format=%s\n", (ip.sin_addr.s_addr == INADDR_ANY) ? "*" : inet_ntoa(ip.sin_addr), ntohs(ip.sin_port), logfile ? logfile : "<none>", fmt); /* * signal handlers. */ (void) signal(SIGUSR1, truncatelog); (void) signal(SIGUSR2, flushlog); (void) signal(SIGINT, exitlog); (void) signal(SIGTERM, exitlog); /* * main loop */ while (1) { slen = sizeof(ip); len = recvfrom(udpsock, bigbuf, BIG-1, 0, (struct sockaddr *)&ip, &slen); if (len <= 0) { if (errno == EINTR) continue; if (len == 0) fprintf(stderr, "recvfrom: returned zero/EOF?\n"); else fprintf(stderr, "recvfrom: %s\n", strerror(errno)); break; } /* ensure null terminated */ bigbuf[len] = 0; /* get rid of the trailing \n */ if (bigbuf[len-1] == '\n') bigbuf[len-1] = 0; if (bigbuf[0] < '0' || bigbuf[0] > '9') { safeputs("INVALID-MSG: "); safeputs(bigbuf); } if (stringsplit(bigbuf, 6, chunks) < 0) { safeputs("PARSE-ERR: "); safeputs(bigbuf); } for (f = fmt ; *f ; f++) { if (f != fmt) safeputs(" "); switch (*f) { case 'd': /* date */ safeputs(chunks[MR_DATE]); break; case 'h': /* host */ safeputs(chunks[MR_HOST]); break; case 'H': /* host (no domain) */ ptr = chunks[MR_HOST]; while (*ptr) { if (*ptr == '.') { *ptr = 0; break; } ptr++; } safeputs(chunks[MR_HOST]); break; case 't': /* tag */ safeputs(chunks[MR_TAG]); break; case 'f': /* facility */ safeputs(chunks[MR_FAC]); break; case 'l': /* level */ safeputs(chunks[MR_LVL]); break; case 'm': /* message */ safeputs(chunks[MR_MSG]); break; case 's': /* source IP */ snprintf(tmpbuf, sizeof(tmpbuf), "%s:%d", inet_ntoa(ip.sin_addr), ntohs(ip.sin_port)); safeputs(tmpbuf); break; default: break; } } safeputs("\n"); } if (logfp) { fflush(logfp); fclose(logfp); } exit(1); }