int InitVariables( WPARAM wParam, LPARAM lParam ) { int j=0; int i=0; localeID = CallService(MS_LANGPACK_GETLOCALE,0,0); if (localeID==CALLSERVICE_NOTFOUND) localeID=LOCALE_USER_DEFAULT; codePage = CallService(MS_LANGPACK_GETCODEPAGE,0,0); if (codePage==CALLSERVICE_NOTFOUND) codePage=CP_ACP; #ifdef UNICODE HasAwayMessageW = (ServiceExists(MS_AWAYMSG_GETSTATUSMSGW)!=0); #endif for (i=0;i<4;i++) { Hotkey_Register(&hotkeydescs[i]); } #ifdef AALOG { NETLIBUSER nlu = { 0 }; nlu.cbSize = sizeof(nlu); nlu.szSettingsModule = "SAA"; nlu.flags=NUF_NOOPTIONS | NUF_NOHTTPSOPTION; nlu.szDescriptiveName = Translate(SECTIONNAME " Module"); hNetlib = (HANDLE) CallService(MS_NETLIB_REGISTERUSER, 0, (LPARAM) & nlu); } { SYSTEMTIME st={0}; int drift; char str[32]; char log[1024]; char target[1024]; drift = GetTimeZone(str); GetLastActiveLocalTime(&st,0); sprintf(log,"Now is %02d/%02d/%02d %02d:%02d:%02d %s (%02d:%02d)", st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond,str, div(drift,60).quot,drift<0?-div(drift,60).rem:div(drift,60).rem); CallService("Netlib/Log" ,(WPARAM)hNetlib ,(LPARAM)log); GetLastActiveLocalTime(&st,24*60*60*1000); sprintf(log,"1 day ago was %02d/%02d/%02d %02d:%02d:%02d %s (%02d:%02d)", st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond,str, div(drift,60).quot,drift<0?-div(drift,60).rem:div(drift,60).rem); CallService("Netlib/Log" ,(WPARAM)hNetlib ,(LPARAM)log); ParseString("%Y-%m-%d %H:%M:%S",target,1023); sprintf(log,"Testing ParseString: %s",target); CallService("Netlib/Log" ,(WPARAM)hNetlib ,(LPARAM)log); ParseString("%E/%d/%y %W %h:%M:%S %p",target,1023); sprintf(log,"Testing ParseString: %s",target); CallService("Netlib/Log" ,(WPARAM)hNetlib ,(LPARAM)log); ParseString("%w %% %Z (%z)%n%L%b%l%b%K%b%k",target,1023); sprintf(log,"Testing ParseString: %s",target); CallService("Netlib/Log" ,(WPARAM)hNetlib ,(LPARAM)log); } #endif CallService(MS_PROTO_ENUMACCOUNTS,(WPARAM)&protoCount,(LPARAM)&accounts); reqStatus = (int *)mir_alloc((protoCount)*sizeof(reqStatus[0])); courStatus = (int *)mir_alloc((protoCount)*sizeof(courStatus[0])); courAwayStatus = (int *)mir_alloc((protoCount)*sizeof(courStatus[0])); protoModes = (int *)mir_alloc((protoCount)*sizeof(protoModes[0])); messCaps = (int *)mir_alloc((protoCount)*sizeof(messCaps[0])); awayStatuses=(short int *)mir_alloc((protoCount)*sizeof(awayStatuses[0])); onlyIfBits=(long int *)mir_alloc((protoCount)*sizeof(onlyIfBits[0])); awayStatusesPerm=(short int *)mir_alloc((protoCount)*sizeof(awayStatuses[0])); onlyIfBitsPerm=(long int *)mir_alloc((protoCount)*sizeof(onlyIfBits[0])); reconnectOpts=(long int *)mir_alloc((protoCount)*sizeof(reconnectOpts[0])); reconnectOptsPerm=(long int *)mir_alloc((protoCount)*sizeof(reconnectOptsPerm[0])); protoOfflineTimes=(unsigned int *)mir_alloc((protoCount)*sizeof(protoOfflineTimes[0])); protoStatus=(int *)mir_alloc((protoCount)*sizeof(protoStatus[0])); idleMessOpts=(long int *)mir_alloc((protoCount)*sizeof(idleMessOpts[0])); idleMessOptsPerm=(long int *)mir_alloc((protoCount)*sizeof(idleMessOptsPerm[0])); mesgHere = (TCHAR**)mir_alloc(protoCount * sizeof(mesgHere[0])); mesgHerePerm = (TCHAR**)mir_alloc(protoCount * sizeof(mesgHerePerm[0])); mesgShort = (TCHAR**)mir_alloc(protoCount * sizeof(mesgShort[0])); mesgShortPerm = (TCHAR**)mir_alloc(protoCount * sizeof(mesgShortPerm[0])); mesgLong = (TCHAR**)mir_alloc(protoCount * sizeof(mesgLong[0])); mesgLongPerm = (TCHAR**)mir_alloc(protoCount * sizeof(mesgLongPerm[0])); #ifdef UNICODE protoHasAwayMessageW=(bool *)mir_alloc(protoCount * sizeof(protoHasAwayMessageW[0])); #endif isWaitingForRestoreStatusMessage = (int *)mir_alloc((protoCount)*sizeof(isWaitingForRestoreStatusMessage[0])); for (j = 0 ; j < protoCount ; j++) { int caps=0; #ifdef AALOG { char log[1024]; sprintf(log,"Checking protocol index %d out of %d...",j+1,protoCount); CallService("Netlib/Log" ,(WPARAM)hNetlib ,(LPARAM)log); } #endif reqStatus[j] = 0; courStatus[j] = ID_STATUS_OFFLINE; protoModes[j] =0; isWaitingForRestoreStatusMessage[j] = 0; caps = CallProtoService(accounts[j]->szModuleName, PS_GETCAPS, PFLAGNUM_2, 0); messCaps[j] = (CallProtoService(accounts[j]->szModuleName, PS_GETCAPS, PFLAGNUM_1, 0) & PF1_MODEMSGSEND)? CallProtoService(accounts[j]->szModuleName, PS_GETCAPS, PFLAGNUM_3, 0):0; #ifdef AALOG { char log[1024]; if (messCaps[j]){ int i; sprintf(log,"StatusMessages Caps for %s:", accounts[j]->szModuleName ); for (i=0;i<10;i++){ int statusFlag = Proto_Status2Flag(aa_Status[i]); if (statusFlag & messCaps[j]){ sprintf(log,"%s %s",log,CallService(MS_CLIST_GETSTATUSMODEDESCRIPTION, aa_Status[i], 0)); } } } else { sprintf(log,"%s cannot set StatusMessage", accounts[j]->szModuleName); } CallService("Netlib/Log" ,(WPARAM)hNetlib ,(LPARAM)log); } #endif for (i = 0; i<numStatuses; i++){ protoModes[j] <<= 1; protoModes[j] |= (Proto_Status2Flag(aa_Status[i]) & caps)?1:0; protoModes[j] |= (aa_Status[i] == ID_STATUS_OFFLINE); } if ( isInterestingProto(j) ) { char str[256]; sprintf(str,AA_BITSONLYIF,accounts[j]->szModuleName); // MessageBox( 0,str,accounts[j]->szModuleName,0); onlyIfBits[j]= db_get_dw(NULL,AA_MODULE,str,-1); if (onlyIfBits[j]==-1){ // onlyIfBits[j] = (((protoModes[j]<<16)|(protoModes[j])) & aa_OnlyIfBitsDefault); onlyIfBits[j] = aa_OnlyIfBitsDefault; db_set_dw(NULL,AA_MODULE,str,onlyIfBits[j]); } onlyIfBitsPerm[j]=onlyIfBits[j]; #ifdef UNICODE sprintf(str,"%s%s",accounts[j]->szModuleName,PS_SETAWAYMSGW); protoHasAwayMessageW[j]=(ServiceExists(str)!=0); #endif // sprintf(str,AA_BITSLONGONLYIF,accounts[j]->szModuleName); //// MessageBox( 0,str,accounts[j]->szModuleName,0); // if (!db_get_w(NULL,AA_MODULE,str,0)) // db_set_w(NULL,AA_MODULE,str,(protoModes[j] & aa_OnlyIfBitsDefault)|known); sprintf(str,AA_AWAYSTATUSES,accounts[j]->szModuleName); // MessageBox( 0,str,accounts[j]->szModuleName,0); awayStatuses[j] = db_get_w(NULL,AA_MODULE,str,-1); if (awayStatuses[j] ==-1){ int old = db_get_w(NULL,AA_OLDMODULE,AA_SHORTSTATUS,-1); int s = StatusToProtoIndex(((old==-1)?ID_STATUS_AWAY:OldIndexToStatus(old)),protoModes[j]); int l = 0; int comb = 0; old = db_get_w(NULL,AA_OLDMODULE,AA_LONGSTATUS,-1); l = StatusToProtoIndex(((old==-1)?ID_STATUS_NA:OldIndexToStatus(old)),protoModes[j]); comb = (l<<4)|s; old = db_get_b(NULL,AA_OLDMODULE,AA_USESHORT,-1); if (s) comb |= ((old==-1)?1<<8:(old==1)<<8); old = db_get_b(NULL,AA_OLDMODULE,AA_USELONG,-1); if (l) comb |= ((old==-1)?1<<9:(old==1)<<9); // comb |= (1<<15); awayStatuses[j]=comb; db_set_w(NULL,AA_MODULE,str,(WORD)awayStatuses[j]); } awayStatusesPerm[j] = awayStatuses[j]; sprintf(str,AA_LASTREQUESTEDSTATUS,accounts[j]->szModuleName); //get last requested status reqStatus[j] = db_get_w(NULL,AA_MODULE,str,ID_STATUS_ONLINE); //default: online sprintf(str,AA_RECONNECTOPTS,accounts[j]->szModuleName); //get reconnect options status reconnectOpts[j] = db_get_dw(NULL,AA_MODULE,str,aa_ReconnectOptsDefault); reconnectOptsPerm[j] = reconnectOpts[j]; protoStatus[j] = 0; protoOfflineTimes[j] = 0; mesgHere[j]=(TCHAR *)mir_alloc(sizeof(TCHAR)*(maxMessageLength+1)); mesgHerePerm[j]=(TCHAR *)mir_alloc(sizeof(TCHAR)*(maxMessageLength+1)); mesgShort[j]=(TCHAR *)mir_alloc(sizeof(TCHAR)*(maxMessageLength+1)); mesgShortPerm[j]=(TCHAR *)mir_alloc(sizeof(TCHAR)*(maxMessageLength+1)); mesgLong[j]=(TCHAR *)mir_alloc(sizeof(TCHAR)*(maxMessageLength+1)); mesgLongPerm[j]=(TCHAR *)mir_alloc(sizeof(TCHAR)*(maxMessageLength+1)); if (messCaps[j]){ DBVARIANT dbv; sprintf(str,idleMsgOptionsName,accounts[j]->szModuleName); idleMessOptsPerm[j] = idleMessOpts[j] = db_get_dw(NULL,AA_MODULE,str,idleMsgOptionsDefault); sprintf(str,idleMsgOptionsTextHere,accounts[j]->szModuleName); if(db_get_ts(NULL,AA_MODULE,str,&dbv)==0) { _tcsncpy(mesgHere[j],dbv.ptszVal,maxMessageLength); mesgHere[j][maxMessageLength]=0; db_free(&dbv); } else _tcscpy(mesgHere[j],messHereDefault); if(!_tcscmp(mesgHere[j],messHereDefaultOld)) _tcscpy(mesgHere[j],messHereDefault); _tcscpy(mesgHerePerm[j],mesgHere[j]); sprintf(str,idleMsgOptionsTextShort,accounts[j]->szModuleName); if(db_get_ts(NULL,AA_MODULE,str,&dbv)==0) { _tcsncpy(mesgShort[j],dbv.ptszVal,maxMessageLength); mesgShort[j][maxMessageLength]=0; db_free(&dbv); } else _tcscpy(mesgShort[j],messShortDefault); if(!_tcscmp(mesgShort[j],messShortDefaultOld)) _tcscpy(mesgShort[j],messShortDefault); _tcscpy(mesgShortPerm[j],mesgShort[j]); sprintf(str,idleMsgOptionsTextLong,accounts[j]->szModuleName); if(db_get_ts(NULL,AA_MODULE,str,&dbv)==0) { _tcsncpy(mesgLong[j],dbv.ptszVal,maxMessageLength); mesgLong[j][maxMessageLength]=0; db_free(&dbv); } else _tcscpy(mesgLong[j],messLongDefault); if(!_tcscmp(mesgLong[j],messLongDefaultOld)) _tcsncpy(mesgLong[j],messLongDefault,maxMessageLength); _tcsncpy(mesgLongPerm[j],mesgLong[j],maxMessageLength); // sprintf(mesgHere[j],"%d: %s: %s",j,accounts[j]->szModuleName,"Test text"); } else { idleMessOptsPerm[j] = idleMessOpts[j] = 0; mesgHerePerm[j] = mesgHere[j] = mesgShortPerm[j] = mesgShort[j] = mesgLongPerm[j] = mesgLong[j] = NULL; } } } #ifdef AALOG { char str[1024]=""; for (j = 0 ; j < protoCount ; j++) { int status; sprintf(str,"%s\n%s Type:%d\nLastReqStatus: %s\n",str,accounts[j]->szModuleName,accounts[j]->szProtoName,CallService(MS_CLIST_GETSTATUSMODEDESCRIPTION, (WPARAM)reqStatus[j], 0)); i=1; while(status=StatusByProtoIndex(protoModes[j],i)){ sprintf(str,"%s %d. %s\n",str,i,CallService(MS_CLIST_GETSTATUSMODEDESCRIPTION, (WPARAM)status, 0)); i++; } // IsStatusBitSet(aa_Status[i],protoModes[j])?"":"not", // CallService(MS_CLIST_GETSTATUSMODEDESCRIPTION, (WPARAM)aa_Status[i], 0), // IsStatusBitSet(aa_Status[i],aa_OnlyIfBitsDefault)?"n":"ff" // ); } CallService("Netlib/Log" ,(WPARAM)hNetlib ,(LPARAM)str); } #endif //something is hapaning here on startup, if main status is not offline //will move Notify hIdleEvent for later in the IdleTimer // NotifyEventHooks( hIdleEvent, 0, idleOpts&IdleBitsPrivate?IDF_PRIVACY:0 ); //Tell everyone we are here FirstTick = 1; //we will wait 1 ticks of the timer before Forcing Awake // FirstTick = 10; //we will wait 20 seconds before Forcing Awake hIdleTimer=SetTimer(NULL, 0, 2000, IdleTimer); // { // char str[20000]=""; // for (i=0;i<=101;i++){ // char str1[128]; // GetStringFromDelay(str1,GetReconnectDelayFromSlider(i)); // sprintf(str,"%d\t%d\t%s",GetReconnectDelayFromSlider(i),i,str1); // CallService("Netlib/Log" ,(WPARAM)hNetlib ,(LPARAM)str); // } // } if ((idleOptsPerm&IdleSuppressIdleMenu)==0) AddIdleMenu(); if ((idleOptsPerm&IdleSuppressAutoHere)!=0) isCurrentlyIdle=db_get_b(NULL,AA_MODULE,AA_LASTIDLESTATUS,0);; return 0; }
String GetTimeZoneText() { return FormatTimeZone(GetTimeZone()); }
void* SntpService(void* pParam, int interval) { fd_set r; struct timeval tv; NTP_TIME_FMT ct, lastTime = { 0 }; NTP_PKT pkt; char tmpBuf[256], ntpServer[80+1]; char ntpMode, bServer = 0, bClient = 1; struct sockaddr_in addr, addrReceive; int ret, sock = socket(PF_INET, SOCK_DGRAM, 0); socklen_t addrlen; if(sock==-1) { printf("SntpService: create sock failed.(%s)\r\n", strerror(errno)); return NULL; } addr.sin_family = PF_INET; addr.sin_port = htons(SNTP_PORT); /* NTP port No. */ addr.sin_addr.s_addr = 0; if (bind(sock, (struct sockaddr*)&addr, sizeof(struct sockaddr))==-1) { printf("Bind socket on port %d fail, errno: %d.\r\n", SNTP_PORT, errno); close(sock); return NULL; } memset(ntpServer, 0, sizeof(ntpServer)); strncpy(ntpServer, (char*)pParam, sizeof(ntpServer)-1); if(ntpServer[0]) { bServer = 0; bClient = 1; } else { bServer = 1; bClient = 0; } #ifdef SNTP_DBG printf("SntpService starting, mode = %d, ntpServer: %s ...\r\n", bServer | (bClient<<1), ntpServer); #endif addr.sin_addr.s_addr = 0; while(1) { int tz = GetTimeZone(); if(MessageGet(MSG_SNTP_QUIT, NULL, 0, 0)>=0) { break; } if(MessageGet(MSG_SNTP_MODE, &ntpMode, 1, 0)==1) { bServer = ntpMode & 0x01; bClient = ntpMode & 0x02; lastTime.seconds = 0; printf("SNTP service mode = %d ...\r\n", bServer | (bClient<<1)); } memset(tmpBuf, 0, sizeof(tmpBuf)); if(MessageGet(MSG_SNTP_SERVER, tmpBuf, sizeof(tmpBuf)-1, 0)>=0) { memset(ntpServer, 0, sizeof(ntpServer)); strncpy(ntpServer, tmpBuf, sizeof(ntpServer)-1); if(ntpServer[0]=='\0') { bClient = 0; } addr.sin_addr.s_addr = 0; lastTime.seconds = 0; printf("SNTP server = %s ...\r\n", ntpServer); } if(bClient) { /* send request every minute */ time(&ct.seconds); if(ct.seconds<lastTime.seconds || (ct.seconds-lastTime.seconds)>=interval) { if(addr.sin_addr.s_addr==0) { if(ntpServer[0]) { struct hostent* pHost = gethostbyname(ntpServer); if(pHost) { addr.sin_addr.s_addr = ((struct in_addr*)pHost->h_addr_list[0])->s_addr; } } } if(addr.sin_addr.s_addr) { lastTime.seconds = ct.seconds; memset(&pkt, 0, sizeof(pkt)); pkt.basic.liVnMode=0x1b; pkt.basic.transmitTimestamp.seconds = htonl(ct.seconds+SECONDS_FROM_1900_1970-tz); pkt.basic.transmitTimestamp.fractional = htonl(ct.fractional); #ifdef SNTP_DBG printf("NTP-CLIENT sending %d bytes on socket %d to port %d ...\r\n", sizeof(pkt.basic), sock, ntohs(addr.sin_port)); #endif sendto(sock, (char*)&pkt.basic, sizeof(pkt.basic), 0, (struct sockaddr*)&addr, sizeof(struct sockaddr)); } } } FD_ZERO(&r); FD_SET(sock, &r); tv.tv_sec = tv.tv_usec = 1; ret = select(sock+1, &r, NULL, NULL, &tv); if(ret<0) break; if(ret==0) continue; addrlen = sizeof(struct sockaddr); memset(&pkt, 0, sizeof(pkt)); ret = recvfrom(sock, (char*)&pkt, sizeof(pkt), 0, (struct sockaddr*)&addrReceive, &addrlen); if(ret<=0) break; gettimeofday(&tv, NULL); ct.seconds = tv.tv_sec; ct.fractional = tv.tv_usec; if(pkt.basic.receiveTimestamp.seconds==0) { if(bServer) { /* response to client */ NTP_TIME_FMT orgTime; orgTime.seconds=pkt.basic.transmitTimestamp.seconds; orgTime.fractional=pkt.basic.transmitTimestamp.fractional; memset(&pkt, 0, sizeof(pkt)); pkt.basic.liVnMode = 0x1C; pkt.basic.stratum=10; memcpy(pkt.basic.referenceID, "WMR", 4); pkt.basic.referenceTimestamp.seconds = htonl(ct.seconds+SECONDS_FROM_1900_1970-tz); pkt.basic.referenceTimestamp.fractional = htonl(ct.fractional); pkt.basic.originateTimestamp.seconds = orgTime.seconds; pkt.basic.originateTimestamp.fractional = orgTime.fractional; pkt.basic.transmitTimestamp.seconds = pkt.basic.receiveTimestamp.seconds = pkt.basic.referenceTimestamp.seconds; pkt.basic.transmitTimestamp.fractional = pkt.basic.receiveTimestamp.fractional = pkt.basic.referenceTimestamp.fractional; #ifdef SNTP_DBG printf("NTP-SERVER response %d bytes ...\r\n", ret); #endif ret = sendto(sock, (char*)&pkt, ret, 0, (struct sockaddr*)&addrReceive, addrlen); } } else { if(bClient) { /* read time info */ int trip; int trip_usec; struct tm* ptm; #ifdef SNTP_DBG printf("LiVnMode = %d\r\n", (unsigned char)pkt.basic.liVnMode); printf("Stratum = %d\r\n", (unsigned char)pkt.basic.stratum); printf("poll = %d\r\n", (unsigned char)pkt.basic.poll); printf("precision = %d\r\n", (unsigned char)pkt.basic.precision); pkt.basic.rootDelay = ntohl(pkt.basic.rootDelay); printf("RootDelay = %lu\r\n", pkt.basic.rootDelay); pkt.basic.rootDispersion = ntohl(pkt.basic.rootDispersion); printf("RootDispersion = %lu\r\n", pkt.basic.rootDispersion); printf("RefrenceID = %02X %02X %02X %02X\r\n", pkt.basic.referenceID[0], pkt.basic.referenceID[1], pkt.basic.referenceID[2], pkt.basic.referenceID[3]); #endif pkt.basic.referenceTimestamp.seconds = ntohl(pkt.basic.referenceTimestamp.seconds)-SECONDS_FROM_1900_1970+tz; pkt.basic.referenceTimestamp.fractional = ntohl(pkt.basic.referenceTimestamp.fractional); #ifdef SNTP_DBG ptm = gmtime(&pkt.basic.referenceTimestamp.seconds); if(ptm) printf("ReferenceTime = %d-%02d-%02d %02d:%02d:%02d\r\n", ptm->tm_year+1900, ptm->tm_mon+1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec); #endif pkt.basic.originateTimestamp.seconds = ntohl(pkt.basic.originateTimestamp.seconds)-SECONDS_FROM_1900_1970+tz; pkt.basic.originateTimestamp.fractional = ntohl(pkt.basic.originateTimestamp.fractional); #ifdef SNTP_DBG ptm = gmtime(&pkt.basic.originateTimestamp.seconds); if(ptm) printf("OriginateTime = %d-%02d-%02d %02d:%02d:%02d\r\n", ptm->tm_year+1900, ptm->tm_mon+1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec); #endif pkt.basic.receiveTimestamp.seconds = ntohl(pkt.basic.receiveTimestamp.seconds)-SECONDS_FROM_1900_1970+tz; pkt.basic.receiveTimestamp.fractional = ntohl(pkt.basic.receiveTimestamp.fractional); #ifdef SNTP_DBG ptm = gmtime(&pkt.basic.receiveTimestamp.seconds); if(ptm) printf("ReceiveTime = %d-%02d-%02d %02d:%02d:%02d\r\n", ptm->tm_year+1900, ptm->tm_mon+1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec); #endif pkt.basic.transmitTimestamp.seconds = ntohl(pkt.basic.transmitTimestamp.seconds)-SECONDS_FROM_1900_1970+tz; pkt.basic.transmitTimestamp.fractional = ntohl(pkt.basic.transmitTimestamp.fractional); #ifdef SNTP_DBG ptm = gmtime(&pkt.basic.transmitTimestamp.seconds); if(ptm) { printf("transmitTime = %d-%02d-%02d %02d:%02d:%02d (%d.%d s)\r\n", ptm->tm_year+1900, ptm->tm_mon+1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec, (int)pkt.basic.transmitTimestamp.seconds, (int)pkt.basic.transmitTimestamp.fractional); } printf("\r\n"); #endif trip = (ct.seconds - pkt.basic.originateTimestamp.seconds) - ( pkt.basic.transmitTimestamp.seconds - pkt.basic.receiveTimestamp.seconds); trip_usec = (ct.fractional - pkt.basic.originateTimestamp.fractional) - ( pkt.basic.transmitTimestamp.fractional - pkt.basic.receiveTimestamp.fractional); #ifdef SNTP_DBG printf("RoundTripDelay = %d.%06d\r\n", trip, trip_usec); #endif ct.seconds = pkt.basic.transmitTimestamp.seconds+trip/2; ct.fractional = pkt.basic.transmitTimestamp.fractional+trip_usec/2; /* 处理ct.fractional绝对值超过1秒的情况 */ #define USEC_PER_SEC 1000000L if (abs(ct.fractional) > USEC_PER_SEC) { ct.seconds += ct.fractional / USEC_PER_SEC; ct.fractional %= USEC_PER_SEC; } /* 处理ct.fractional与ct.seconds符号不同的情况 */ if (ct.fractional < 0) { ct.seconds -= 1; ct.fractional += USEC_PER_SEC; } ptm = gmtime(&ct.seconds); if (ptm) { struct timeval tv; #ifdef SNTP_DBG struct timeval cur_time; gettimeofday(&cur_time, NULL); #endif memcpy(&tv.tv_sec, &ct.seconds, sizeof(time_t)); tv.tv_usec = ct.fractional; ret = settimeofday(&tv, NULL); if(ret) { printf("SNTP: set system time fail\r\n"); } else { printf("SNTP: Synchronize system time to %d-%02d-%02d %02d:%02d:%02d\r\n", ptm->tm_year+1900, ptm->tm_mon+1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec); #ifdef SNTP_DBG printf("previous time: %ld.%06lds, new time: %ld.%06lds.\r\n", cur_time.tv_sec, cur_time.tv_usec, tv.tv_sec, tv.tv_usec); #endif } } } } } if(sock != -1) close(sock); return NULL; }
void CSysConfig::ResetDefault() { CConfigBase::ResetDefault(); //额外处理代码 // CUiMng::Instance().SetSkinType(GetSkinType()); // CUiMng::Instance().SetLanguage(GetLanguage()); CUnitAndFormatSwitch::SetTimeZone(GetTimeZone()); //读取子配置信息 ChileProcessInfo ProcessInfo; CString m_csRadioName; CString m_csRadioIconName; CString m_csPicName; CString m_csPicIconName; CString m_csMusicName; CString m_csMusicIconName; CString m_csMovieName; CString m_csMovieIconName; CString m_csNaviName; CString m_csNaviIconName; if(!CSysConfig::Instance().GetNaviInfo(ProcessInfo)) { } else { // m_csNaviName = ProcessInfo.EXEPath + _T("\\") + ProcessInfo.ExeName; // m_csNaviIconName = ProcessInfo.EXEPath + _T("\\") + ProcessInfo.eXEIniName; ResetChildConfigDefault(ProcessInfo.EXEPath,ProcessInfo.eXEIniName); } if(!CSysConfig::Instance().GetMoviesInfo(ProcessInfo)) { } else { // m_csNaviName = ProcessInfo.EXEPath + _T("\\") + ProcessInfo.ExeName; // m_csNaviIconName = ProcessInfo.EXEPath + _T("\\") + ProcessInfo.eXEIniName; ResetChildConfigDefault(ProcessInfo.EXEPath,ProcessInfo.eXEIniName); } if(!CSysConfig::Instance().GetMusicInfo(ProcessInfo)) { } else { // m_csNaviName = ProcessInfo.EXEPath + _T("\\") + ProcessInfo.ExeName; // m_csNaviIconName = ProcessInfo.EXEPath + _T("\\") + ProcessInfo.eXEIniName; ResetChildConfigDefault(ProcessInfo.EXEPath,ProcessInfo.eXEIniName); } if(!CSysConfig::Instance().GetBlueToothInfo(ProcessInfo)) { } else { // m_csNaviName = ProcessInfo.EXEPath + _T("\\") + ProcessInfo.ExeName; // m_csNaviIconName = ProcessInfo.EXEPath + _T("\\") + ProcessInfo.eXEIniName; ResetChildConfigDefault(ProcessInfo.EXEPath,ProcessInfo.eXEIniName); } if(!CSysConfig::Instance().GetPictureInfo(ProcessInfo)) { } else { // m_csNaviName = ProcessInfo.EXEPath + _T("\\") + ProcessInfo.ExeName; // m_csNaviIconName = ProcessInfo.EXEPath + _T("\\") + ProcessInfo.eXEIniName; ResetChildConfigDefault(ProcessInfo.EXEPath,ProcessInfo.eXEIniName); } if(!CSysConfig::Instance().GetVolumeInfo(ProcessInfo)) { } else { // m_csNaviName = ProcessInfo.EXEPath + _T("\\") + ProcessInfo.ExeName; // m_csNaviIconName = ProcessInfo.EXEPath + _T("\\") + ProcessInfo.eXEIniName; ResetChildConfigDefault(ProcessInfo.EXEPath,ProcessInfo.eXEIniName); } if(!CSysConfig::Instance().GetTxtInfo(ProcessInfo)) { } else { // m_csNaviName = ProcessInfo.EXEPath + _T("\\") + ProcessInfo.ExeName; // m_csNaviIconName = ProcessInfo.EXEPath + _T("\\") + ProcessInfo.eXEIniName; ResetChildConfigDefault(ProcessInfo.EXEPath,ProcessInfo.eXEIniName); } }