void CSqlScore::NormalizeMapname(char *pString) { std::string validChars("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"); for(int i=0;i<str_length(pString);i++) { if(validChars.find(pString[i]) == std::string::npos) { pString[i] = '_'; } } }
QString GerberGenerator::escapeString(const QString& str) noexcept { // perform compatibility decomposition (NFKD) QString ret = str.normalized(QString::NormalizationForm_KD); // remove all invalid characters // Note: Even if backslashes are allowed, we will remove them because we // haven't implemented proper escaping. Escaping of unicode characters is also // missing here. QString validChars("[a-zA-Z0-9_+-/!?<>”’(){}.|&@# ,;$:=]"); ret.remove(QRegularExpression(QString("[^%1]").arg(validChars))); // limit length to 65535 characters ret.truncate(65535); return ret; }
Intervall parse(string input){ Intervall result = Intervall(NAN); //string term((inputIntervall->text()).toStdString()); string term=clearString(input);//Leerzeichen in term löschen if(term!=""){ if(validChars(term)==false){//Überprüfung, ob term ungültige Zeichen enthält errorWindow("Nonvalid character!"); return Intervall(NAN); }else if(brackets(term)==false){//Überprüfung, ob die Anzahl von "(" mit ")" in term übereinstimmt errorWindow("Can't match delimiters!"); return Intervall(NAN); }else if(intervalBrackets(term)==false){//Überprüfung, ob die Anzahl von "[" mit "]" in term übereinstimmt errorWindow("Can't match interval delimiters!"); return Intervall(NAN); }else { result=parseTermOfIntervals(term);//term parsen -> result } } return result; }
int main(int argc, char *argv[]) { int sockfd, portno, n, receivedNum = 0, // int representing the data size sent returnStatus, // value returned from read or write dataSizeNum, convertedNum, connectStatus; struct sockaddr_in serv_addr; struct hostent *server; // Defines a host computer char txtBuffer[BUFF_SIZE], keyBuffer[BUFF_SIZE], ciphBuffer[BUFF_SIZE]; FILE* filePtr; // Check for correct arguments if (argc < 4) { fprintf(stderr, "usage: %s plaintext key port\n", argv[0]); exit(1); } // Read the plaintext file filePtr = fopen(argv[1], "r"); if (filePtr == NULL) { fprintf(stderr, "could not open plaintext file\n"); exit(1); } bzero(txtBuffer, BUFF_SIZE); fgets(txtBuffer, BUFF_SIZE, filePtr); fclose(filePtr); // Read the key file filePtr = fopen(argv[2], "r"); if (filePtr == NULL) { fprintf(stderr, "could not open key file\n"); exit(1); } bzero(keyBuffer, BUFF_SIZE); fgets(keyBuffer, BUFF_SIZE, filePtr); fclose(filePtr); // Check for bad characters or if key file is too short if (strlen(keyBuffer) < strlen(txtBuffer)) { fprintf(stderr, "ERROR: key %s is too short\n", argv[2]); exit(1); } if (!validChars(txtBuffer)) { fprintf(stderr, "ERROR: bad characters in %s\n", argv[1]); exit(1); } if (!validChars(keyBuffer)) { fprintf(stderr, "ERROR: bad characters in %s\n", argv[2]); exit(1); } /******** Connect to server ********/ // Set port number and host name portno = atoi(argv[3]); sockfd = socket(AF_INET, SOCK_STREAM, 0); if (sockfd < 0) error("ERROR opening socket"); server = gethostbyname("localhost"); if (server == NULL) { fprintf(stderr,"ERROR, no such host\n"); exit(0); } // Set server address bzero((char *) &serv_addr, sizeof(serv_addr)); serv_addr.sin_family = AF_INET; bcopy((char *)server->h_addr, (char *)&serv_addr.sin_addr.s_addr, server->h_length); serv_addr.sin_port = htons(portno); // Connect to the server if (connect(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) error("ERROR on initial connect"); // Check if trying to connect to otp_dec_d; if so, reject returnStatus = read(sockfd, &receivedNum, sizeof(receivedNum)); if (returnStatus > 0) { receivedNum = ntohl(receivedNum); if (receivedNum == 2) { fprintf(stderr, "ERROR: could not contact otp_dec_d on port %s\n", argv[3]); exit(2); } } // Receive the new port number from server after initial connect returnStatus = read(sockfd, &receivedNum, sizeof(receivedNum)); if (returnStatus > 0) receivedNum = ntohl(receivedNum); else fprintf(stderr, "ERROR receiving port number: %d\n", returnStatus); // Restart socket on new port number close(sockfd); // Set port number and host name portno = receivedNum; // set to new port number sockfd = socket(AF_INET, SOCK_STREAM, 0); if (sockfd < 0) error("ERROR opening socket"); server = gethostbyname("localhost"); if (server == NULL) { fprintf(stderr,"ERROR, no such host\n"); exit(1); } // Set server address bzero((char *) &serv_addr, sizeof(serv_addr)); serv_addr.sin_family = AF_INET; bcopy((char *)server->h_addr, (char *)&serv_addr.sin_addr.s_addr, server->h_length); serv_addr.sin_port = htons(portno); // Connect to the server do { connectStatus = connect(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)); if (connectStatus < 0) perror("ERROR on secondary connect"); } while (connectStatus < 0); /******** Begin data exchange with server *********/ // Write the data size of plaintext to the socket dataSizeNum = strlen(txtBuffer); convertedNum = htonl(dataSizeNum); returnStatus = write(sockfd, &convertedNum, sizeof(convertedNum)); if (returnStatus < 0) error("ERROR writing data size"); // Write plaintext to the socket writeSock(sockfd, txtBuffer); // Write the data size of the key to the socket dataSizeNum = strlen(keyBuffer); convertedNum = htonl(dataSizeNum); returnStatus = write(sockfd, &convertedNum, sizeof(convertedNum)); if (returnStatus < 0) error("ERROR writing data size"); // Write key to the socket writeSock(sockfd, keyBuffer); // Read the data size of ciphertext returnStatus = read(sockfd, &receivedNum, sizeof(receivedNum)); if (returnStatus > 0) receivedNum = ntohl(receivedNum); else fprintf(stderr, "ERROR receiving data size: %d\n", returnStatus); // Read ciphertext from the socket readSock(sockfd, ciphBuffer, receivedNum); printf("%s", ciphBuffer); close(sockfd); return 0; }