int Process3DAuthenticationV6(int new_sock) { int ErrorCode; V6_AUTHENTICATION_REQUEST_T Request; V6_AUTHENTICATION_RESULT_T Result; MYSQL *conn = NULL; double start_time=0, end_time=0; double t1=0, t2=0; struct timeval tp_start; struct timeval tp_end; gettimeofday(&tp_start, 0); printLog(HEAD, "==[MSG_INTER4_AUTH_REQ]==\n"); memset(&Request, 0, sizeof(V6_AUTHENTICATION_REQUEST_T)); memset(&Result, 0, sizeof(V6_AUTHENTICATION_RESULT_T)); if((ErrorCode = ReadAuthRequestVersion6(new_sock, &Request)) == FAIL) { if(Request.AuthFileInfo != NULL) free(Request.AuthFileInfo); return FAIL; } if((Result.AuthResultData = (AUTH_RESULT_DATA_T*) malloc(sizeof(AUTH_RESULT_DATA_T)*Request.reqEncCnt)) == NULL) { printLog(HEAD, "ERR: Memory Allocation Error... size(%d)\n", sizeof(AUTH_RESULT_DATA_T)*Request.reqEncCnt); if(Request.AuthFileInfo != NULL) free(Request.AuthFileInfo); return FAIL; } if(strcmp("USER", Request.userType) == 0) { if((ErrorCode = getDBConn(&conn)) == TRUE) { ErrorCode = checkProduct_From_DB(Request, &conn); if(ErrorCode == TRUE) ErrorCode = processEncoding(Request, &Result, &conn); if(ErrorCode == TRUE) ErrorCode = DB_UpdateNInsertProductNowHistory(&conn, Request); DB_EndProcess(&conn, DBEND_POSITION); } } else if(strcmp("FACT", Request.userType) == 0) { if((ErrorCode = getDBConn(&conn)) == TRUE) { ErrorCode = checkUUID(Request, &conn); if(ErrorCode == TRUE) ErrorCode = processEncoding_Fac(Request, &Result, &conn); if(ErrorCode == TRUE) { if((ErrorCode = DB_InsertFactoyAuthHistory(&conn, Request, DBMODE_FAC_AUTH_INITED)) != DB_SUCCESS) { ErrorCode = ERROR_DB ; } } DB_EndProcess(&conn, DBEND_POSITION); } } else { printLog(HEAD, "ERR: User type(%s) is not acceptable \n", Request.userType); ErrorCode = ERROR_USER_WRONG; } WriteAuthRequestVersion6("MSG_INTER4_AUTH_REQ", MSG_INTER4_AUTH_REQ, MSG_PDA_ERROR, Request, Result, ErrorCode, new_sock); if(Request.AuthFileInfo != NULL) free(Request.AuthFileInfo); if(Result.AuthResultData != NULL) free(Result.AuthResultData); gettimeofday(&tp_end, 0); t1 = (double)tp_start.tv_sec; t2 = ((double)tp_start.tv_usec)/1000000; start_time = t1 + t2; t1 = (double)tp_end.tv_sec; t2 = ((double)tp_end.tv_usec)/1000000; end_time = t1 + t2; printLog(HEAD, "Authetication Elapsed for Processing... (%f) seconds\n", end_time-start_time); return ErrorCode; }
void pSocket::onDataReceived() { #ifdef FUNC_DEBUG qDebug() << '\n' << Q_FUNC_INFO; #endif auto data = _socket->readAll(); if (_packetSize == 0) { int n = data.indexOf("\n\n"); if (n == -1) { qDebug() << "Wrong data received. Disconnect" << _socket->localAddress(); _socket->disconnectFromHost(); return; } QByteArray header = data.left(n); auto content = data.mid(n+2); _buffer = content; QString _generate_id; _generate_id = getValue(header, "generateid"); if (_generate_id == "1") { _uuid = GenerateUUID(); _socket->write(_uuid.toStdString().c_str()); _socket->disconnectFromHost(); } _limit.fetchAndAddAcquire(content.size()); _packetSize = getValue(header, "size").toInt(); _protoVersion = getValue(header, "version"); _fileType = getValue(header, "type"); _uuid = getValue(header, "uuid"); if (_uuid.length()!=0 && !checkUUID(_uuid)) { qDebug() << "UUID is incorrect. Disconnect" << _socket->localAddress(); _socket->disconnectFromHost(); return; } if (_packetSize == 0) { qDebug() << "Client trying to send empty data"; _socket->disconnectFromHost(); } if (_fileType == "" || !Settings::types().contains(_fileType) ) { qDebug() << "Sender type is not exist. Disconnect" << _socket->localAddress(); _socket->disconnectFromHost(); return; } } else { _buffer += data; _limit.fetchAndAddAcquire(data.size()); } if (_buffer.size() > MAX_DATA_SIZE || _limit > MAX_DAY_SIZE) { qDebug() << "File is too big! Disconnect" << _socket->localAddress(); _socket->disconnectFromHost(); _socket->deleteLater(); return; } #ifdef FUNC_DEBUG qDebug() << '\n' << Q_FUNC_INFO << "read"; #endif if (_buffer.size() == _packetSize) { #ifdef FUNC_DEBUG qDebug() << '\n' << Q_FUNC_INFO << "emit"; #endif _packetSize = 0; emit saveFile(_buffer, _fileType, _uuid); #ifdef TIME_DEBUG qDebug() << dTime->elapsed(); #endif } #ifdef FUNC_DEBUG qDebug() << '\n' << Q_FUNC_INFO << "end"; #endif }