Exemplo n.º 1
0
void _LogFooter(void)
{
    char   szLibPath [ PS_MAX_PATH ];
#if defined (WIN32)
    GetModuleFileNameA(NULL, szLibPath, PS_MAX_PATH);
#elif defined (_LINUX)

    if (program_invocation_name[0] == '/')
    {
        // file contains full path already, so don't append path
        sprintf_s(szLibPath, PS_MAX_PATH, "%s", program_invocation_name);
    }
    else
    {
        char currentDir[PS_MAX_PATH];
        getcwd(currentDir, PS_MAX_PATH);
        sprintf_s(szLibPath, PS_MAX_PATH, "%s/%s", currentDir, program_invocation_name);
    }

#endif
    _Log(logRAW,  "App : %s\n", szLibPath);
    _Log(logRAW,  "PID: %i\n", osGetCurrentProcessId());
    _Log(logRAW,  "Time: %s\n", GetTimeStr().asCharArray());
    _Log(logRAW, "--------------THE END------------------\n");
}
Exemplo n.º 2
0
const char* CDateTime::Now( EDTFORMAT edtfFormat )
{
	SYSTEMTIME stTime;
	GetSystemTime( &stTime );

	return GetTimeStr( stTime, edtfFormat );
}
Exemplo n.º 3
0
bool CAttachmentProcessor::GenerateSavePath(const TUploadConf *pUploadConf,const string& strSubfix,vector<string>& vecDbPath,vector<string>& vecFilePath)
{
	if(NULL == pUploadConf)
		return false;
	const vector<TSaveGroupConf>& vecSaveGroupConf = pUploadConf->vecSaveGroupConf;
	if(vecSaveGroupConf.empty())
		return false;

	int size = vecSaveGroupConf.size();
	int index = GetRandomNumber(0, size);
	const TSaveGroupConf& saveGroupConf = vecSaveGroupConf.at(index);

	string timeStr = GetTimeStr();
	string uniqueStr = GetUniqueStr();
	string namePrefix = pUploadConf->strSaveNamePrefix;
	namePrefix = (namePrefix != "") ? (namePrefix+"_") : "";
	string strSubDir = pUploadConf->strSaveSubDir;
	strSubDir = (strSubDir!="")?(strSubDir+"/"):"";

	string saveDir = saveGroupConf.strSaveNodePath + "/" + strSubDir + timeStr;
	Mkdir(saveDir);

	string filePath = saveDir + "/" + namePrefix + uniqueStr + "." + strSubfix;
	string dbPath = saveGroupConf.strGroupName + "/" + strSubDir + timeStr + + "/" + namePrefix + uniqueStr + "." + strSubfix;
	vecDbPath.push_back(dbPath);
	vecFilePath.push_back(filePath);
	return true;
}
Exemplo n.º 4
0
void LogFileInitialize(void)
{
    FILE* f;
    const char* logFilename = GetLogFilename();

    // It is valid for there to be no Log File. However since this
    // is the only place where the log file is initialized, we flag
    // it as something to note in the console.

    if (logFilename != NULL)
    {
        // Open for writing - this will overwrite any previous logfile
        fopen_s(&f, logFilename, "w+");    // read binary

        if (f != NULL)
        {
            fprintf(f, "Logging Started: %s\n\n", GetTimeStr().asCharArray());
            fclose(f);
        }
        else
        {
            LogConsole(logERROR, "Unable to open logfile %s for writing \n", logFilename);
        }
    }
}
Exemplo n.º 5
0
wxString CMusikPlayer::GetTimeLeftStr()
{
	if(_CurrentSongIsNetStream())
	{
		return GetTimeStr();
	}
	else
		return SecToStr( GetTimeLeft( FMOD_SEC ) );
}
Exemplo n.º 6
0
int auto_smzdm::smzdm_run()
{
  QNetworkCookieJar* cookie = new QNetworkCookieJar(this);

  network.GetManager().setCookieJar(cookie);

  GetContent();

  foreach(QString str, m_comment_list)
  {

    QString jq = QString("jQuery") + "11100" + GetNumberString(16) +"_" + GetTimeStr();

    QString str_url1 = QString(
      "http://zhiyou.smzdm.com/user/comment/ajax_rating?callback=%1&comment_id=%2&rating=1&_=%3").arg(jq,str,GetTimeStr());

    QUrl url1(str_url1);

    HttpParamList header_list;
    header_list.push_back(HttpParamItem("Referer", m_news_url));
    header_list.push_back(HttpParamItem("Accept", "application/javascript, */*;q=0.8"));
    header_list.push_back(HttpParamItem("Cache-Control","no-cache"));
    header_list.push_back(HttpParamItem("Connection","Keep-Alive"));
    //header_list.push_back(HttpParamItem("Accept-Encoding","gzip, deflate"));
    header_list.push_back(HttpParamItem("Accept-Language","zh-CN"));
    header_list.push_back(HttpParamItem("Host", m_host));
    header_list.push_back(HttpParamItem("User-Agent","Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)"));

    QNetworkReply* reply = network.GetRequest(url1, header_list);

#ifdef _DEBUG

       QTime _t;
       _t.start();
   
       bool _timeout = false;
  
       while (reply && !reply->isFinished())
       {
         QCoreApplication::processEvents();
         if (_t.elapsed() >= 10*1000) {
           _timeout = true;
           break;
         }
       }

      QString rt = reply->readAll();
#endif //_DEBUG
      reply->deleteLater();
// 
   }
Exemplo n.º 7
0
int main(int argc, char* argv[]) {
  int i;
  float ft0;
  long tnow;
  struct timeval tval;
  char tstr[64];

  // initialize random
  ft0 = GetCPUTime();
  printf("      %7.3fs start\n",ft0);

  gettimeofday(&tval, 0);
  GetTimeStr(&tval, tstr);
  tnow = (long) tval.tv_sec*1000 + (long) tval.tv_usec/1000;
  srand48(tnow);

  for (i = 1000000; i <= 100000000; i *= 10) {
    RandBench(i);
    HashBench(i);
    FixedVecBench(i);
    VecBench(i);
    //SortedVecBench(n);
  }
}
Exemplo n.º 8
0
const char* CDateTime::GetTimeStr( EDTFORMAT edtfFormat ) const
{
	return GetTimeStr( m_dtsTime, edtfFormat );
}
Exemplo n.º 9
0
void RPCMinerClient::Run(const std::string &url, const std::string &user, const std::string &password, const int threadcount)
{
	m_running=true;
	m_done=false;
	m_url=url;
	m_user=user;
	m_password=password;
	m_threadcount=threadcount;
	int64 lastrequestedwork=GetTimeMillis()-5000;
	int64 laststats=GetTimeMillis()-25000;
	m_lasttarget=0;
	m_lasthashdisplay=GetTimeMillis();
	int64 timenowmillis;
	static unsigned int counter=0u;

	std::cout << "Client will start " << m_threadcount << " miner threads" << std::endl;
	std::cout << "Work will be refreshed every " << m_workrefreshms << " ms" << std::endl;

	while(Done()==false && HasError() == false)
	{
		if(m_minerthreads.RunningThreadCount()<m_threadcount)
		{
			int nextDeviceIndex = m_minerthreads.LastDeviceIndex() + 1;
			m_minerthreads.Start(new threadtype(nextDeviceIndex));
		}

	/*	if(lastrequestedwork<=GetTimeMillis()-m_workrefreshms)
		{
			SendWorkRequest();
			lastrequestedwork=GetTimeMillis();
		}
	*/

		if(m_serverstatsurl!="" && laststats<=GetTimeMillis()-60000)
		{
			json_spirit::Object statsobj;
			if(GetServerStats(statsobj))
			{
				PrintServerStats(statsobj);
			}
			laststats=GetTimeMillis();
		}

		if(m_minerthreads.HaveFoundHash())
		{
			std::cout << GetTimeStr(time(0)) << " Found Hash!" << std::endl;
			foundhash fhash;
			m_minerthreads.GetFoundHash(fhash);
			++counter;
			std::cout<<"Hashs found: "<<counter<<std::endl;
			SendFoundHash(fhash.m_blockid,fhash.m_nonce);
			SendWorkRequest();
			lastrequestedwork=GetTimeMillis();
		}
                CleanupOldBlocks();
		
                if(lastrequestedwork<=GetTimeMillis()-m_workrefreshms)
                {
                        SendWorkRequest();
                        lastrequestedwork=GetTimeMillis();
                }

		
		
		timenowmillis=GetTimeMillis();
		if(m_hashraterefresh>0 && (m_lasthashdisplay+m_hashraterefresh)<=timenowmillis)
		{
			int64 hr=GetHashRate(true);
			if(m_blocklookup.size()>0)
			{
				std::cout << hr << " khash/s" << std::endl;
			}
			else
			{
				if(m_startuptime+30000<timenowmillis)
				{
					std::cout << "No blocks are being hashed right now.  This can happen if the application is" << std::endl;
					std::cout << "still starting up, you supplied incorrect parameters, or there is a" << std::endl;
					std::cout << "communications error connecting to the RPC server." << std::endl;
					m_minerthreads.ClearWork();
				}
			}
			
		}

		Sleep(10);
	}

	m_running=false;

}
Exemplo n.º 10
0
bool autobots_toutiao::GetCookies()
{
    QString str_url_1 = QString("https://dl.reg.163.com/ini?pd=tie&pkid=cGTVPrV&pkht=tie.163.com&nocache=%1").arg(GetTimeStr());

    QUrl url_1(str_url_1);
    url_1.setUrl(str_url_1);
    HttpParamList header_list1;
    header_list1.push_back(HttpParamItem("Accept", "*/*"));
    header_list1.push_back(HttpParamItem("Connection", "keep-alive"));
    //header_list1.push_back(HttpParamItem("Accept-Encoding","deflate"));
    header_list1.push_back(HttpParamItem("Accept-Language", "zh-cn"));
    header_list1.push_back(HttpParamItem("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"));

    //header_list1.push_back(HttpParamItem("Cache-Control", "no-cache"));
    //header_list.push_back(HttpParamItem("X-CSRFToken", "20c9e1fc22618a31cbfcd42218e96dd0"));
    header_list1.push_back(HttpParamItem("Host", "dl.reg.163.com")); // mhost
    header_list1.push_back(HttpParamItem("User-Agent", "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)"));

    QNetworkReply* rp = network.GetRequest(url_1, header_list1);

    QTime _t;
    _t.start();

    bool _timeout = false;

    while (rp && !rp->isFinished())
    {
        QCoreApplication::processEvents();
        if (_t.elapsed() >= TIMEOUT) {
            _timeout = true;
            break;
        }
    }

    QVariant statusCodeV = rp->attribute(QNetworkRequest::HttpStatusCodeAttribute);
    bool res = statusCodeV.toInt() == 200 ? true : false;

    QString c = rp->readAll();

    if (rp != NULL)
        rp->deleteLater();

    return  res;
}
Exemplo n.º 11
0
void RemoteMinerClient::HandleMessage(const RemoteMinerMessage &message)
{
	json_spirit::Value tval=json_spirit::find_value(message.GetValue().get_obj(),"type");
	if(tval.type()==json_spirit::int_type)
	{
		std::cout << "Got message " << tval.get_int() << " from server." << std::endl;
		if(tval.get_int()==RemoteMinerMessage::MESSAGE_TYPE_SERVERHELLO)
		{
			m_gotserverhello=true;
			tval=json_spirit::find_value(message.GetValue().get_obj(),"metahashrate");
			if(tval.type()==json_spirit::int_type)
			{
				m_minerthreads.SetMetaHashSize(tval.get_int());
				m_metahashsize=tval.get_int();
			}
			tval=json_spirit::find_value(message.GetValue().get_obj(),"serverversion");
			if(tval.type()==json_spirit::str_type)
			{
				std::cout << "Server version " << tval.get_str() << std::endl;
			}
			tval=json_spirit::find_value(message.GetValue().get_obj(),"distributiontype");
			if(tval.type()==json_spirit::str_type)
			{
				std::cout << "Distribution type : " << tval.get_str() << std::endl;
			}
		}
		else if(tval.get_int()==RemoteMinerMessage::MESSAGE_TYPE_SERVERSENDWORK)
		{
			int64 nextblockid=0;
			std::vector<unsigned char> nextblock;
			std::vector<unsigned char> nextmidstate;
			uint256 nexttarget;
			tval=json_spirit::find_value(message.GetValue().get_obj(),"blockid");
			if(tval.type()==json_spirit::int_type)
			{
				nextblockid=tval.get_int();
			}
			tval=json_spirit::find_value(message.GetValue().get_obj(),"block");
			if(tval.type()==json_spirit::str_type)
			{
				DecodeBase64(tval.get_str(),nextblock);
			}
			tval=json_spirit::find_value(message.GetValue().get_obj(),"target");
			if(tval.type()==json_spirit::str_type)
			{
				nexttarget.SetHex(tval.get_str());
			}
			tval=json_spirit::find_value(message.GetValue().get_obj(),"midstate");
			if(tval.type()==json_spirit::str_type)
			{
				DecodeBase64(tval.get_str(),nextmidstate);
			}

			tval=json_spirit::find_value(message.GetValue().get_obj(),"fullblock");
			if(tval.type()==json_spirit::obj_type)
			{
				SaveBlock(tval.get_obj(),"block.txt");
				if(m_address160!=0)
				{
					double amount=0;
					if(FindGenerationAddressInBlock(m_address160,tval.get_obj(),amount))
					{
						std::cout << "Address " << Hash160ToAddress(m_address160) <<  " will receive " << amount << " BTC if this block is solved" << std::endl;
					}
					else
					{
						std::cout << "Address " << Hash160ToAddress(m_address160) << " not found in block being solved" << std::endl;
					}
				}
			}

			m_minerthreads.SetNextBlock(nextblockid,nexttarget,nextblock,nextmidstate);

		}
		else if(tval.get_int()==RemoteMinerMessage::MESSAGE_TYPE_SERVERSTATUS)
		{
			int64 clients=0;
			int64 khashmeta=0;
			int64 khashbest=0;
			int64 clientkhashmeta=0;
			time_t startuptime=0;
			struct tm startuptimetm;
			std::string startuptimestr("");
			int64 blocksgenerated=0;

			tval=json_spirit::find_value(message.GetValue().get_obj(),"clients");
			if(tval.type()==json_spirit::int_type)
			{
				clients=tval.get_int();
			}
			tval=json_spirit::find_value(message.GetValue().get_obj(),"khashmeta");
			if(tval.type()==json_spirit::int_type)
			{
				khashmeta=tval.get_int();
			}
			tval=json_spirit::find_value(message.GetValue().get_obj(),"khashbest");
			if(tval.type()==json_spirit::int_type)
			{
				khashbest=tval.get_int();
			}
			tval=json_spirit::find_value(message.GetValue().get_obj(),"yourkhashmeta");
			if(tval.type()==json_spirit::int_type)
			{
				clientkhashmeta=tval.get_int();
			}
			tval=json_spirit::find_value(message.GetValue().get_obj(),"sessionstartuptime");
			if(tval.type()==json_spirit::int_type)
			{
				startuptime=tval.get_int();
				startuptimetm=*gmtime(&startuptime);
				std::vector<char> buff(128,0);
				int rval=strftime(&buff[0],buff.size()-1,"%Y-%m-%d %H:%M:%S",&startuptimetm);
				buff.resize(rval);
				startuptimestr=std::string(buff.begin(),buff.end());
			}
			tval=json_spirit::find_value(message.GetValue().get_obj(),"sessionblocksgenerated");
			if(tval.type()==json_spirit::int_type)
			{
				blocksgenerated=tval.get_int();
			}
			
			std::cout << std::endl;
			std::cout << GetTimeStr(time(0)) << std::endl;
			std::cout << "Server Status : " << clients << " clients, " << khashmeta << " khash/s" << std::endl;
			std::cout << blocksgenerated << " blocks generated since " << startuptimestr << " UTC" << std::endl;
			std::cout << "Server reports my khash/s as " << clientkhashmeta << std::endl;
		}
	}
	else
	{
		std::cout << "Server sent invalid message.  Disconnecting." << std::endl;
	}
}
Exemplo n.º 12
0
int main(int iArgCount, char *pszArgs[])
{
    int iVarLength = 0;
    FILE *pInFile = stdin;
    char *pszMailRoot;
    char szMailRoot[SYS_MAX_PATH] = "";

    /* Initialize time */
    tzset();

    if ((pszMailRoot = SysGetEnv(ENV_MAIL_ROOT)) == NULL ||
        (iVarLength = (int)strlen(pszMailRoot)) == 0) {
        free(pszMailRoot);
        fprintf(stderr, "cannot find environment variable: %s\n",
            ENV_MAIL_ROOT);
        return 1;
    }
    StrSNCpy(szMailRoot, pszMailRoot);
    if (szMailRoot[iVarLength - 1] != SYS_SLASH_CHAR)
        strcat(szMailRoot, SYS_SLASH_STR);
    free(pszMailRoot);

    /* Parse command line */
    int i;
    bool bExtractRcpts = false;
    bool bXMailFormat = false;
    bool bDotMode = true;
    char szMailFrom[256] = "";
    char szExtMailFrom[256] = "";
    char szInputFile[SYS_MAX_PATH] = "";
    char szRcptFile[SYS_MAX_PATH] = "";

    SysGetUserAddress(szMailFrom, sizeof(szMailFrom) - 1, ENV_DEFAULT_DOMAIN);

    for (i = 1; i < iArgCount; i++) {
        if (strcmp(pszArgs[i], "--") == 0) {
            ++i;
            break;
        }

        if (strcmp(pszArgs[i], "--rcpt-file") == 0) {
            if (++i < iArgCount)
                StrSNCpy(szRcptFile, pszArgs[i]);
        } else if (strcmp(pszArgs[i], "--xinput-file") == 0) {
            if (++i < iArgCount) {
                StrSNCpy(szInputFile, pszArgs[i]);

                bXMailFormat = true;
            }
        } else if (strcmp(pszArgs[i], "--input-file") == 0) {
            if (++i < iArgCount)
                StrSNCpy(szInputFile, pszArgs[i]);
        } else if (strcmp(pszArgs[i], "-i") == 0 ||
               strcmp(pszArgs[i], "-oi") == 0) {
            bDotMode = false;
        } else if (strcmp(pszArgs[i], "-t") == 0) {
            bExtractRcpts = true;
        } else if (strncmp(pszArgs[i], "-f", 2) == 0) {
            if (pszArgs[i][2] != '\0')
                CopyAddress(szMailFrom, pszArgs[i] + 2,
                        sizeof(szMailFrom) - 1);
            else if ((i + 1) < iArgCount) {
                CopyAddress(szMailFrom, pszArgs[i + 1],
                        sizeof(szMailFrom) - 1);
                i++;
            }
        } else if (strncmp(pszArgs[i], "-F", 2) == 0) {
            if (pszArgs[i][2] != '\0')
                StrSNCpy(szExtMailFrom, pszArgs[i] + 2);
            else if (i + 1 < iArgCount) {
                StrSNCpy(szExtMailFrom, pszArgs[i + 1]);
                i++;
            }

            char const *pszOpen = strchr(szExtMailFrom, '<');

            if (pszOpen == NULL)
                CopyAddress(szMailFrom, szExtMailFrom,
                        sizeof(szMailFrom) - 1);
            else {
                char szTmpMailFrom[256];

                StrSNCpy(szTmpMailFrom, pszOpen + 1);

                char *pszClose =
                    (char *) strchr(szTmpMailFrom, '>');

                if (pszClose != NULL)
                    *pszClose = '\0';

                CopyAddress(szMailFrom, szTmpMailFrom,
                        sizeof(szMailFrom) - 1);
            }
        } else if (strncmp(pszArgs[i], "-o", 2) == 0) {

        } else if (strcmp(pszArgs[i], "-L") == 0 ||
               strcmp(pszArgs[i], "-O") == 0 ||
               strcmp(pszArgs[i], "-R") == 0 ||
               strcmp(pszArgs[i], "-X") == 0 ||
               strcmp(pszArgs[i], "-V") == 0 ||
               strcmp(pszArgs[i], "-N") == 0 ||
               strncmp(pszArgs[i], "-qG", 3) == 0 ||
               strncmp(pszArgs[i], "-q!", 3) == 0) {
            if (i + 1 < iArgCount)
                i++;
        } else
            break;
    }

    /* Save recipients index and counter */
    int iRcptIndex, iRcptCount;

    iRcptIndex = Min(i, iArgCount);
    iRcptCount = iArgCount - iRcptIndex;

    /* Check if recipients are supplied */
    if (!bExtractRcpts && iRcptCount == 0 && IsEmptyString(szRcptFile)) {
        fprintf(stderr, "empty recipient list\n");
        return 2;
    }

    if (!IsEmptyString(szInputFile)) {
        if ((pInFile = fopen(szInputFile, "rb")) == NULL) {
            perror(szInputFile);
            return 3;
        }
    }

        /* Check if the sender is specified */
        if (IsEmptyString(szMailFrom)) {
                char const *pszUser = SysGetEnv(ENV_USER);

                if (pszUser == NULL)
                        pszUser = "******";
                CopyAddress(szMailFrom, pszUser, sizeof(szMailFrom) - 1);
        }

    /* Create file name */
    char szHostName[256] = "";
    char szDataFile[SYS_MAX_PATH] = "";
    char szMailFile[SYS_MAX_PATH] = "";

    SysGetHostName(szHostName, sizeof(szHostName) - 1);

    SysSNPrintf(szDataFile, sizeof(szDataFile), "%s%s%lu000.%lu.%s",
            szMailRoot, LOCAL_TEMP_SUBPATH, (unsigned long) time(NULL),
            SysGetProcessId(), szHostName);
    SysSNPrintf(szMailFile, sizeof(szMailFile), "%s.mail", szDataFile);

    /* Open raw data file */
    FILE *pDataFile = fopen(szDataFile, "w+b");

    if (pDataFile == NULL) {
        perror(szDataFile);
        if (pInFile != stdin)
            fclose(pInFile);
        return 4;
    }
    /* Open maildrop file */
    FILE *pMailFile = fopen(szMailFile, "wb");

    if (pMailFile == NULL) {
        perror(szMailFile);
        fclose(pDataFile);
        remove(szDataFile);
        if (pInFile != stdin)
            fclose(pInFile);
        return 5;
    }
    fprintf(pMailFile, "mail from:<%s>\r\n", szMailFrom);

    for (i = iRcptIndex; i < iArgCount; i++) {
        char szAddr[256];

        CopyAddress(szAddr, pszArgs[i], sizeof(szAddr) - 1);
        fprintf(pMailFile, "rcpt to:<%s>\r\n", szAddr);
    }

    int iLine;
    bool bInHeaders = true;
    bool bHasFrom = false;
    bool bHasDate = false;
    bool bRcptSource = false;
    bool bNoEmit = false;
    char szBuffer[1536];

    for (iLine = 0; fgets(szBuffer, sizeof(szBuffer) - 1, pInFile) != NULL; iLine++) {
        int iLineLength = (int)strlen(szBuffer);

        for (; iLineLength > 0 && (szBuffer[iLineLength - 1] == '\r' ||
                       szBuffer[iLineLength - 1] == '\n'); iLineLength--);

        szBuffer[iLineLength] = '\0';

        /* Is it time to stop reading ? */
        if (bDotMode && strcmp(szBuffer, ".") == 0)
            break;

        /* Decode XMail spool file format */
        if (bXMailFormat) {
            if (strcmp(szBuffer, MAIL_DATA_TAG) == 0)
                bXMailFormat = false;

            continue;
        }
        /* Extract mail from */
        if (bInHeaders) {
            bool bStraightFile = false;

            if ((iLine == 0) && !IsRFC822HeaderLine(szBuffer))
                bStraightFile = true;

            if (bStraightFile || iLineLength == 0) {
                bInHeaders = false;
                bNoEmit = false;

                /* Add mail from (if not present) */
                if (!bHasFrom) {
                    if (strlen(szExtMailFrom) != 0)
                        fprintf(pDataFile, "From: %s\r\n", szExtMailFrom);
                    else
                        fprintf(pDataFile, "From: <%s>\r\n", szMailFrom);
                }
                /* Add date (if not present) */
                if (!bHasDate) {
                    char szDate[128] = "";

                    GetTimeStr(szDate, sizeof(szDate) - 1, time(NULL));
                    fprintf(pDataFile, "Date: %s\r\n", szDate);
                }

                if (bStraightFile)
                    fprintf(pDataFile, "\r\n");
            }

            if (szBuffer[0] == ' ' || szBuffer[0] == '\t') {
                if (bExtractRcpts && bRcptSource) {
                    int iRcptCurr = EmitRecipients(pMailFile, szBuffer);

                    if (iRcptCurr > 0)
                        iRcptCount += iRcptCurr;
                }
            } else if (iLineLength > 0) {
                bNoEmit = (strnicmp(szBuffer, "Bcc:", 4) == 0);
                bRcptSource = strnicmp(szBuffer, "To:", 3) == 0 ||
                    strnicmp(szBuffer, "Cc:", 3) == 0 ||
                    strnicmp(szBuffer, "Bcc:", 4) == 0;

                if (bExtractRcpts && bRcptSource) {
                    int iRcptCurr = EmitRecipients(pMailFile, szBuffer);

                    if (iRcptCurr > 0)
                        iRcptCount += iRcptCurr;
                }

                if (!bHasFrom && strnicmp(szBuffer, "From:", 5) == 0)
                    bHasFrom = true;

                if (!bHasDate && strnicmp(szBuffer, "Date:", 5) == 0)
                    bHasDate = true;
            }
        }
        if (!bNoEmit)
            fprintf(pDataFile, "%s\r\n", szBuffer);
    }

    /* Close input file if different from stdin */
    if (pInFile != stdin)
        fclose(pInFile);

    /* Dump recipient file */
    if (!IsEmptyString(szRcptFile)) {
        FILE *pRcptFile = SafeOpenFile(szRcptFile, "rb");

        if (pRcptFile == NULL) {
            perror(szRcptFile);
            fclose(pDataFile);
            remove(szDataFile);
            fclose(pMailFile);
            remove(szMailFile);
            return 6;
        }

        while (fgets(szBuffer, sizeof(szBuffer) - 1, pRcptFile) != NULL) {
            int iLineLength = (int)strlen(szBuffer);

            for (; iLineLength > 0 &&
                     (szBuffer[iLineLength - 1] == '\r' ||
                      szBuffer[iLineLength - 1] == '\n'); iLineLength--);

            szBuffer[iLineLength] = '\0';

            if (iLineLength >= MAX_ADDR_NAME)
                continue;

            /*
               [i_a] '@' is also accepted in the section before the '<email-address>', e.g.
               "loony@toones <*****@*****.**>"

               Besides, this code must be able to handle lines like
               'from bla <*****@*****.**>; via blub ([email protected]); etc.'
             */
            char const *lt_p = strchr(szBuffer, '<');
            char const *gt_p = (!lt_p ? lt_p : strchr(lt_p + 1, '>'));
            char const *pszAt = strchr(lt_p ? lt_p + 1 : szBuffer, '@');
            while (lt_p && gt_p && pszAt) {
                if (pszAt > gt_p) {
                    lt_p = strchr(lt_p + 1, '<');
                    gt_p = (!lt_p ? lt_p : strchr(lt_p + 1, '>'));
                    pszAt = (!lt_p ? /* copout for bad line */ strchr(szBuffer, '@') : strchr(lt_p + 1, '@'));
                }
                else {
                    break;
                }
            }

            if (pszAt == NULL)
                continue;

            char szRecipient[MAX_ADDR_NAME] = "";

            if (AddressFromAtPtr(pszAt, szBuffer, szRecipient,
                         sizeof(szRecipient)) != NULL) {
                fprintf(pMailFile, "rcpt to:<%s>\r\n", szRecipient);

                ++iRcptCount;
            }
        }

        fclose(pRcptFile);
    }
    /* Check the number of recipients */
    if (iRcptCount == 0) {
        fprintf(stderr, "empty recipient list\n");
        fclose(pDataFile);
        remove(szDataFile);
        fclose(pMailFile);
        remove(szMailFile);
        return 7;
    }
    /* Empty line separator between maildrop header and data */
    fprintf(pMailFile, "\r\n");

    /* Append data file */
    rewind(pDataFile);

    unsigned int uReaded;

    do {
        if (((uReaded = (unsigned int)fread(szBuffer, 1, (int)sizeof(szBuffer), pDataFile)) != 0) &&
            (fwrite(szBuffer, 1, uReaded, pMailFile) != uReaded)) {
            perror(szMailFile);
            fclose(pDataFile);
            remove(szDataFile);
            fclose(pMailFile);
            remove(szMailFile);
            return 8;
        }

    } while (uReaded == sizeof(szBuffer));

    fclose(pDataFile);
    remove(szDataFile);

    /* Sync and close the mail file */
    if (SysFileSync(pMailFile) < 0 || fclose(pMailFile)) {
        remove(szMailFile);
        fprintf(stderr, "cannot write file: %s\n", szMailFile);
        return 9;
    }
    /* Move the mail file */
    char szDropFile[SYS_MAX_PATH];

    SysSNPrintf(szDropFile, sizeof(szDropFile), "%s%s%lu000.%lu.%s",
            szMailRoot, LOCAL_SUBPATH, (unsigned long) time(NULL),
            SysGetProcessId(), szHostName);
    if (SysMoveFile(szMailFile, szDropFile) < 0) {
        remove(szMailFile);
        fprintf(stderr, "cannot move file: %s\n", szMailFile);
        return 10;
    }

    return 0;
}
Exemplo n.º 13
0
bool autobots_toutiao::DoSupport()
{

	for (size_t i = 0; i < m_comment_list.size(); i++)
	{
		QString str_url1 = QString("http://isub.snssdk.com/2/relation/follow/v2/?ab_client=a1%2Cf2%2Cf7%2Ce1&ab_feature=z2&ab_group=z2&ab_version=112577%2C101786%2C112146%2C111547%2C101533%2C109464%2C110341%2C109891%2C112474%2C112070%2C106784%2C97142%2C31646%2C111339%2C101605%2C101558%2C112164%2C94046%2C112403%2C112532%2C105610%2C112343%2C105822%2C112578%2C108978%2C111796%2C108489%2C111897%2C110795%2C98042%2C105475&ac=WIFI&aid=13&app_name=news_article&channel=App%20Store&device_id=3135986566&device_platform=iphone&device_type=iPhone%206&idfa=86E011D2-C2DA-40CB-AB9D-DB1E1F9D668A&idfv=674FB6B1-60E9-4315-88FC-AAC84BEFAB46&iid=7730017535&live_sdk_version=1.6.5&new_reason=0&new_source=25&openudid=0d919477efbefb99dfe7a02a2df34d9127ecc947&os_version=9.3.5&resolution=750%2A1334&ssmix=a&user_id=51817712863&version_code=6.0.1&vid=674FB6B1-60E9-4315-88FC-AAC84BEFAB46")
			.arg(m_comment_list[i]);

		QUrl url1;
		url1.setUrl(str_url1);

		HttpParamList header_list;
		header_list.push_back(HttpParamItem("Accept", "*/*"));
		//header_list.push_back(HttpParamItem("Proxy - Connection", "Keep-Alive"));
		header_list.push_back(HttpParamItem("Connection", "Keep-Alive"));
		//  header_list.push_back(HttpParamItem("Accept-Encoding","deflate"));
		header_list.push_back(HttpParamItem("Accept-Language", "zh-cn"));
		header_list.push_back(HttpParamItem("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"));
		header_list.push_back(HttpParamItem("Cache-Control", "no-cache"));
		//header_list.push_back(HttpParamItem("X-CSRFToken", m_csrf_token));
		header_list.push_back(HttpParamItem("Host", "isub.snssdk.com"));
		//header_list.push_back(HttpParamItem("Referer", m_url));
		header_list.push_back(HttpParamItem("tt-request-time", GetTimeStr()));
		//header_list.push_back(HttpParamItem("User-Agent", "News/5.8.3 (iPhone; iOS 9.3.5; Scale/2.00)"));
		header_list.push_back(HttpParamItem("User-Agent", "News/6.0.1 (iPhone; iOS 9.3.5; Scale/2.00)"));

		//HttpParamList post_data;
		//post_data.push_back(HttpParamItem("thread_id", m_group_id));

		QNetworkReply* reply = network.GetRequest(url1, header_list);

		QTime _t;
		_t.start();

		bool _timeout = false;

		while (reply && !reply->isFinished())
		{
			QCoreApplication::processEvents();
			if (_t.elapsed() >= TIMEOUT) {
				_timeout = true;
				break;
			}
		}

		if (reply == NULL || (reply->error() != QNetworkReply::NoError) || _timeout)
		{
			QVariant statusCodeV = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
			int n = statusCodeV.toInt();
			QString ss = reply->errorString();
			ui.lineEdit_msg->setText(ss);
			reply->deleteLater();
			//return false;
			continue;
		}

		QByteArray rp_data = reply->readAll();

		QVariant content_type = reply->header(QNetworkRequest::ContentTypeHeader);

		QString type = content_type.toString();

		if (type.contains("json"))
		{
			//bool res = GetSupportStatus(rp_data);
			//return res;
			if (rp_data.contains("success"))
			{
				ui.lineEdit_msg->setText(QStringLiteral("操作成功"));
			}
		}
		else
		{
			ui.lineEdit_msg->setText(QStringLiteral("操作失败"));
		}
	}
	return true;
}
Exemplo n.º 14
0
void onSet()
{
	mkdir(path_log);
	mkdir(path_weight);
	GetTimeStr(str_StartTime);
	int select;
SetStart:
	printf("========================Start=======================\n");
	printf("--- 1.  play with ai ひたぎ (td-bp gametreeα-β)\n");
	printf("--- 2.  play with ai クオン (gametreeα-β)\n");
	printf("--- 3.  play with ai ひたぎXクオン (mix)\n");
	printf("--- 4.  train ai ひたぎ with ai クオン\n");
	printf("--- 5.  train ai ひたぎ with player\n");
	printf("--- 6.  train ai ひたぎ with extern ai(%s)\n",path_traindll);
	printf("--- 7.  set player's chess color\n");
	printf("--- 8.  set saving frequence\n");
	printf("--- 9.  set ひたぎ ann weight\n");
	printf("input a number to go:");
	scanf("%d",&select);
	if(select>=1 && select<=3)
	{
		playmode=1;
		if(select==1) ai_mode=2;
		else if(select==2) ai_mode=1;
		else if(select==3) ai_mode=3;
	}
	else if(select>=4 && select<=6)
	{
		playmode=2;
		if(select==4) trainmode=1;
		else if(select==5) trainmode=2;
		else if(select==6) trainmode=3;
	}
	else if(select==7)
	{
		printf("\ncurrent player's chess color is %c\n",color_player);
		printf("input a number to go (1 blcak %c,2 white %c ):",black,white);
		scanf("%d",&select);
		if(select==1)
			color_player=black;
		else if(select==2)
			color_player=white;
		goto SetStart;
	}
	else if(select==8)
	{
		printf("\ncurrent frequence is %d\n",freq_save);
		printf("input frequence:");
		scanf("%d",&select);
		if(select >=0)  freq_save=select;
		goto SetStart;
	}
	else if(select==9)
	{
		printf("\ncurrent ひたぎ ann weight path is:%s\n",file_loadweight);
		printf("input the new path (0 for default):");
		char buf[200];
		scanf("%s",buf);
		if(!strcmp(buf,"0"))
			strcpy(file_loadweight,"HitagiTrain.net");
		else
			strcpy(file_loadweight,buf);
		goto SetStart;
	}
	else goto SetStart;
}
Exemplo n.º 15
0
bool autobots_toutiao::AuthorByRenren(const QString& name, const QString& password)
{
  //1.检验验证码
//   QString vcode, code_sign;
//   bool need_code = NeedValidateCode(name, vcode, code_sign);
//   QString str_need_code = need_code ? "true" : "";

  QString str_url1 = "https://passport.bilibili.com/login?act=getkey&_=" + GetTimeStr();;

  QUrl url1(str_url1);
    
  QString str_temp = "https://passport.bilibili.com/ajax/miniLogin/minilogin";

  HttpParamList header_list;
  header_list.push_back(HttpParamItem("Accept",	"application/json, text/javascript, */*; q=0.01"));
  header_list.push_back(HttpParamItem("Connection","Keep-Alive"));
  //header_list.push_back(HttpParamItem("Accept-Encoding","gzip, deflate"));
  header_list.push_back(HttpParamItem("Accept-Language","zh-CN"));
  header_list.push_back(HttpParamItem("Host", "passport.bilibili.com"));
  header_list.push_back(HttpParamItem("Referer", str_temp));
  header_list.push_back(HttpParamItem("User-Agent","Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)"));

  QNetworkReply* reply = network.GetRequest_ssl(url1, header_list);

  QTime _t;
  _t.start();

  bool _timeout = false;

  while (reply && !reply->isFinished())
  {
    QCoreApplication::processEvents();
    if (_t.elapsed() >= TIMEOUT) {
      _timeout = true;
      break;
    }
  }

  if (reply == NULL || (reply->error() != QNetworkReply::NoError) || _timeout)
  {
    reply->deleteLater();
    return false;
  }

  QVariant statusCodeV =  reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);  

  int n = statusCodeV.toInt();

  bool res = false;

  if (n!=200)
  {
    return res;
  }

  QByteArray rp_data = reply->readAll();

  QString hash_code, public_key;

  res = GetCode(rp_data, hash_code, public_key);

  if (reply != NULL)
  {
    reply->deleteLater();
  }

  if (!res)
  {
    return res;
  }

  res = LoginBili(name,password,hash_code,public_key);

  return res;
}
Exemplo n.º 16
0
string CExactime::GetShowStr()
{
	return (GetDateStr() + " " + GetTimeStr() + " " + GetUSecStr());
}