12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413 |
- #if (defined _WIN32 || defined _WIN64)
- #include <io.h>
- #include <winsock2.h>
- #include <ws2tcpip.h>
- #include <Psapi.h>
- #include "fileutil.h"
- #pragma comment(lib,"psapi.lib")
- #endif
- #include "RemoteControllerCnn.h"
- #include "RemoteControllerFSM.h"
- #include "Event.h"
- #include <stdlib.h>
- #include "cJSON.h"
- #include "base64.h"
- #include "digital_conv.h"
- #include <fstream>
- #include "path.h"
- #include "SpUtility.h"
- #include "../mod_healthmanager/HealthManager_client_g.h"
- using namespace HealthManager;
- #define __int64 long int
- #include "../mod_UpgradeMgr/UpgradeManager_client_g.h"
- using namespace UpgradeManager;
- #include "../mod_ResourceWatcher/ResourceWatcher_client_g.h"
- using namespace ResourceWatcher;
- #include "remoteBase.h"
- #include "MyZip.h"
- namespace fs = boost::filesystem;
- #include <functional>
- #if (defined _WIN32 || defined _WIN64)
- #define generateFilesize(fileHandle, filePath) long long nFileSize = _filelengthi64(_fileno(fileHandle))
- #include "XZip.h"
- #else
- #define generateFilesize(fileHandle, filePath) long long nFileSize = fs::file_size(filePath.GetData())
- #include "zip.h"
- #include <stdlib.h>
- #include "XZipZilb.h"
- #include <sstream>
- #define ZeroMemory(object, size) memset(object, 0, size)
- #define WritePrivateProfileStringA(a, b, c, d) Base_writeIni(std::string(a), std::string(b), std::string(c), std::string(d))
- #if defined(RVC_OS_LINUX)
- void _ui64toa(unsigned long long large_unit, char* str, int hexdigith)
- {
- auto largeNumStr = std::to_string(large_unit);
- strcpy(str, largeNumStr.c_str());
- /*
- std::stringstream ss;
- ss << large_unit;
- std::string src = ss.str();
- memset(str, 0, strsize);
- strncpy(str, src.c_str(), strsize);
- */
- }
- #endif //RVC_OS_LINUX
- int strncpy_s(char* _Destination, size_t _SizeInBytes, char const* _Source, size_t _MaxCount)
- {
- if (_MaxCount > _SizeInBytes)
- return nullptr == strncpy(_Destination, _Source, _SizeInBytes);
- else
- return nullptr == strncpy(_Destination, _Source, _MaxCount);
- }
- int strncpy_s(char* _Destination, char const* _Source, size_t _MaxCount)
- {
- return nullptr == strncpy(_Destination, _Source, _MaxCount);
- }
- #endif
- CRemoteControllerCnn::CRemoteControllerCnn(CEntityBase *pEntity, FSMBase *pFSM)
- :SpSecureClient(pEntity), m_pFSM(pFSM),m_chRemoteMode('N')
- {
- }
- CRemoteControllerCnn::~CRemoteControllerCnn(void)
- {
- }
- void CRemoteControllerCnn::OnDisconnect()
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("OnDisconnect")("connection disconnected");
- // 连接中断,重置远程维护状态,释放所有资源
- m_chRemoteMode = 'N';
- m_pFSM->PostEventFIFO(new FSMEvent(CRemoteControllerFSM::Event_ReleaseChannel));
- }
- void CRemoteControllerCnn::OnPkgAnswer(const CSmartPointer<IPackage> &pRecvPkg)
- {
- string serviceCode = pRecvPkg->GetServiceCode();
- if (serviceCode == "StRemote")
- {
- HandleCreateRemoteChannelRet(pRecvPkg);
- }
- else if (serviceCode == "EdRemote")
- {
- HandleEndRemoteModeReq(pRecvPkg);
- }
- else if (serviceCode == "DelRun")
- {
- HandleDelRunInfoLogReq(pRecvPkg);
- }
- else if (serviceCode == "RestartS")
- {
- HandleRestartShellReq(pRecvPkg);
- }
- else if (serviceCode == "RestartO")
- {
- HandleRestartMachineReq(pRecvPkg);
- }
- else if (serviceCode == "ViewEnti")
- {
- HandleViewEntityStateReq(pRecvPkg);
- }
- else if (serviceCode == "ViewConf")
- {
- HandleViewEntityConfigReq(pRecvPkg);
- }
- else if (serviceCode == "ViewDbg")
- {
- HandleViewDebugLogReq(pRecvPkg);
- }
- else if (serviceCode == "OprDisk")
- {
- HandleOperateDiskReq(pRecvPkg);
- }
- else if (serviceCode == "EvtLog")
- {
- HandleUploadEventLogReq(pRecvPkg);
- }
- else if(serviceCode == "ULogBD")
- {
- HandleUploadLogByDateReq(pRecvPkg);
- }
- else if(serviceCode == "ULogsBD")
- {
- HandleBatchUploadLogsByDateReq(pRecvPkg);
- }
- else if (serviceCode == "EnterMM")
- {
- HandleEnterMaintainModeReq(pRecvPkg);
- }
- else if (serviceCode == "ExitMM")
- {
- HandleExitMaintainModeReq(pRecvPkg);
- }
- else if (serviceCode == "UpgPack")
- {
- HandleUpgradePackReq(pRecvPkg);
- }
- else if (serviceCode == "Rollback")
- {
- HandleRollbackUpgradeReq(pRecvPkg);
- }
- else if (serviceCode == "GetUser")
- {
- HandleGetCurMaintainerReq(pRecvPkg);
- }
- else if (serviceCode == "Enpower")
- {
- HandleEnpowerMaintainerReq(pRecvPkg);
- }
- else if (serviceCode == "TakePwr")
- {
- HandleTakeoverPowerReq(pRecvPkg);
- }
- else if (serviceCode == "ForceQt")
- {
- HandleForceQuitMaintainReq(pRecvPkg);
- }
- else if (serviceCode == "EditCfg")
- {
- HandleEditConfigReq(pRecvPkg);
- }
- else if (serviceCode == "ViewVar")
- {
- HandleViewSysVarReq(pRecvPkg);
- }
- else if (serviceCode == "GetVer")
- {
- HandleGetVersionReq(pRecvPkg);
- }
- else if (serviceCode == "VRunCfg")
- {
- HandleViewRunCfgReq(pRecvPkg);
- }
- else if (serviceCode == "VPkgLog")
- {
- HandleViewInstallLogReq(pRecvPkg);
- }
- else if (serviceCode == "UpldLog")
- {
- HandleUploadLogReq(pRecvPkg);
- }
- else if (serviceCode == "UpldLogs")
- {
- HandleBatchUploadLogsReq(pRecvPkg);
- }
- else if (serviceCode == "ViewEnEx")
- {
- HandleViewEntityStateExReq(pRecvPkg);
- }
- else if (serviceCode == "CancUpg")
- {
- HandleCancelUpgradeReq(pRecvPkg);
- }
- else
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("OnPkgAnswer")("unknown service code: %s", serviceCode.c_str());
- }
- }
- bool CRemoteControllerCnn::GetHostIPAddr(BYTE addr[4])
- {
- memset(addr, 0, 4);
- #if (defined _WIN32 || defined _WIN64)
- char szHostName[64] = {};
- int nRet = gethostname(szHostName, sizeof(szHostName));
- if (nRet != 0)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("GetHostIPAddr")("gethostname fail: %d", nRet);
- return false;
- }
- addrinfo hints = {};
- hints.ai_family = AF_INET;
- PADDRINFOA pResult = NULL;
- nRet = getaddrinfo(szHostName, NULL, &hints, &pResult);
- if (nRet != 0)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("GetHostIPAddr")("getaddrinfo fail: %d", nRet);
- return false;
- }
- for(auto ptr=pResult; ptr != NULL ;ptr=ptr->ai_next)
- {
- assert (ptr->ai_family == AF_INET);
-
- struct in_addr *in = (struct in_addr*)ptr->ai_addr;
- if (in->S_un.S_un_b.s_b1 != 192 || ptr->ai_next != NULL)
- {
- memcpy(&addr[0], in, 4);
- break;
- }
- }
- freeaddrinfo(pResult);
- return true;
- #else
- return Base_GetHostIPAddr(addr);
- #endif
-
- }
- ErrorCodeEnum CRemoteControllerCnn::SendCreateRemoteChannelReq()
- {
- auto pEntity = m_pEntity->GetFunction();
- CSystemStaticInfo info;
- auto rc = pEntity->GetSystemStaticInfo(info);
- assert(rc == Error_Succeed);
- RvcCreateChannelReq req = {};
- strncpy_s(req.TerminalNo, sizeof(req.TerminalNo), info.strTerminalID, _TRUNCATE);
- // get ip addr
- assert(GetHostIPAddr(req.IPAddr));
- // get life id
- CSystemRunInfo info2 = {};
- rc = pEntity->GetSystemRunInfo(info2);
- req.LifeID = info2.tmStart;
- // send package
- auto pReqPkg = CreateNewPackage("StRemote");
- pReqPkg->AddStruct("RemoteR", false, false, (BYTE*)&req, sizeof(req));
- auto strPkgID = SendPackage(pReqPkg);
- assert(strPkgID != "");
- return Error_Succeed;
- }
- ErrorCodeEnum CRemoteControllerCnn::HandleCreateRemoteChannelRet(const CSmartPointer<IPackage> &pRecvPkg)
- {
- DWORD dwSysCode, dwUserCode;
- string strErrMsg;
- ErrorCodeEnum rc = Error_Succeed;
- if (pRecvPkg->GetErrMsg(dwSysCode, dwUserCode, strErrMsg))
- {
- rc = (ErrorCodeEnum)dwSysCode;
- LogError(Severity_Middle, rc, dwUserCode,
- CSimpleStringA::Format("create remote channel error: %s", strErrMsg.c_str()));
- return rc;
- }
- RvcCreateChannelRet ret = {};
- int nLen = sizeof(ret);
- int nArrayLen(0);
- if (!pRecvPkg->GetStructData("RemoteA", (BYTE*)&ret, &nLen, &nArrayLen))
- {
- LogError(Severity_Low, Error_Param, 0, "get return struct [RemoteA] fail");
- return Error_Param;
- }
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleCreateRemoteChannelRet")
- ("create remote channel succeed, remote user: [%s], channel id: [%s]", ret.AgentID, ret.ChannelID);
- return EnterMonitorMode();
- }
- ErrorCodeEnum CRemoteControllerCnn::HandleEndRemoteModeReq(const CSmartPointer<IPackage> &pRecvPkg)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleEndRemoteModeReq")("exit remote mode now");
- m_chRemoteMode = 'N';
- m_pFSM->PostEventFIFO(new FSMEvent(CRemoteControllerFSM::Event_ReleaseChannel));
- auto pReplyPkg = CreateReplyPackage(pRecvPkg);
- SendPackage(pReplyPkg);
- return Error_Succeed;
- }
- ErrorCodeEnum CRemoteControllerCnn::HandleDelRunInfoLogReq(const CSmartPointer<IPackage> &pRecvPkg)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleDelRunInfoLogReq")("Del run info log req");
- auto pReplyPkg = CreateReplyPackage(pRecvPkg);
- int nLen = pRecvPkg->GetStructLen("DelRunR");
- if (nLen <= 0)
- {
- pReplyPkg->SetErrMsg(Error_Param, 0, "get struct [DelRunR] fail");
- SendPackage(pReplyPkg);
- return Error_Param;
- }
- assert(nLen == sizeof(RvcDelRunInfoLogReq));
- RvcDelRunInfoLogReq req = {};
- ZeroMemory(&req, sizeof(RvcDelRunInfoLogReq));
- int nArrayLen(0);
- pRecvPkg->GetStructData("DelRunR", (BYTE*)&req, &nLen, &nArrayLen);
- CSimpleString strLogName = req.logName;
- RvcDelRunInfoLogRet ret = {};
- ret.TaskID = req.TaskID;
- pReplyPkg->AddStruct("DelRunA", false, false, (BYTE*)&ret, sizeof(ret));
- auto pFunc = m_pEntity->GetFunction();
- CSystemStaticInfo sysInfo;
- auto rc = pFunc->GetSystemStaticInfo(sysInfo);
- CSimpleString runInfoPath;
- pFunc->GetPath("RunInfo", runInfoPath);
- CSimpleString delFilePaht = runInfoPath;
- delFilePaht.Append(SPLIT_SLASH_STR).Append("runcfg").Append(SPLIT_SLASH_STR).Append(strLogName).Append(".ini");
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleDelRunInfoLogReq")("curTaskId:%d ,try to delete %s, strLogName = %s", req.TaskID, delFilePaht, strLogName);
- if (Base_Exist(delFilePaht.GetData()))
- {
- if (!Base_DeleteFile(delFilePaht.GetData()))
- {
- pReplyPkg->SetErrMsg(Error_Param, 0, SP::Utility::UTF8ToGBK(CSimpleString::Format("%s文件删除失败", delFilePaht).GetData()).c_str());
- SendPackage(pReplyPkg);
- return Error_Cancel;
- }
- }
- else
- {
- pReplyPkg->SetErrMsg(Error_Param, 0, SP::Utility::UTF8ToGBK(CSimpleString::Format("%s文件不存在", delFilePaht).GetData()).c_str());
- SendPackage(pReplyPkg);
- return Error_Cancel;
- }
- SendPackage(pReplyPkg);
- return Error_Succeed;
- }
- ErrorCodeEnum CRemoteControllerCnn::HandleTest(const CSmartPointer<IPackage> &pRecvPkg)
- {
- auto pReplyPkg = CreateReplyPackage(pRecvPkg);
- auto pFunc = m_pEntity->GetFunction();
- CSystemStaticInfo sysInfo;
- auto rc = pFunc->GetSystemStaticInfo(sysInfo);
- CSimpleString runInfoPath;
- pFunc->GetPath("RunInfo", runInfoPath);
- CSimpleString delFilePaht = runInfoPath;
- delFilePaht.Append(SPLIT_SLASH_STR).Append("runcfg").Append(SPLIT_SLASH_STR).Append("MediaController").Append(".ini");
- Dbg("try to delete %s", delFilePaht);
- if (Base_Exist(delFilePaht.GetData()))
- {
- if (!Base_DeleteFile(delFilePaht.GetData()))
- {
- pReplyPkg->SetErrMsg(Error_Param, 0, SP::Utility::UTF8ToGBK(CSimpleString::Format("%s文件删除失败", delFilePaht).GetData()).c_str());
- SendPackage(pReplyPkg);
- return Error_Cancel;
- }
- }
- else
- {
- pReplyPkg->SetErrMsg(Error_Param, 0, SP::Utility::UTF8ToGBK(CSimpleString::Format("%s文件不存在", delFilePaht).GetData()).c_str());
- SendPackage(pReplyPkg);
- return Error_Cancel;
- }
- SendPackage(pReplyPkg);
- return Error_Succeed;
- }
- ErrorCodeEnum CRemoteControllerCnn::HandleRestartShellReq(const CSmartPointer<IPackage> &pRecvPkg)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleRestartShellReq")("remote restart shell req");
- auto pReplyPkg = CreateReplyPackage(pRecvPkg);
- int nLen = pRecvPkg->GetStructLen("RestSR");
- if (nLen <= 0)
- {
- pReplyPkg->SetErrMsg(Error_Param, 0, "get struct [RestSR] fail");
- SendPackage(pReplyPkg);
- return Error_Param;
- }
- assert(nLen == sizeof(RvcRestartShellReq));
- RvcRestartShellReq req = {};
- int nArrayLen(0);
- pRecvPkg->GetStructData("RestSR", (BYTE*)&req, &nLen, &nArrayLen);
- RvcRestartShellRet ret = {};
- ret.TaskID = req.TaskID;
- pReplyPkg->AddStruct("RestSA", false, false, (BYTE*)&ret, sizeof(ret));
- // 检查当前状态,是否可以重启Shell
- auto pFunc = m_pEntity->GetFunction();
- CSimpleStringA strCustomerHandleVal;
- pFunc->GetSysVar("CustomerHandle", strCustomerHandleVal);
- CSimpleStringA strCustomerBeingVal;
- pFunc->GetSysVar("CustomerBeing", strCustomerBeingVal);
- if (strCustomerHandleVal.Compare("N") != 0 || (strCustomerBeingVal.Compare("N") != 0 && strCustomerBeingVal.Compare("S") != 0))
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleRestartShellReq")("remote restart shell fail for var [CustomerHandle] == '%s' & [CustomerBeing] == '%s'"
- , (const char*)strCustomerHandleVal, (const char*)strCustomerBeingVal);
- pReplyPkg->SetErrMsg(Error_Param, 0, SP::Utility::UTF8ToGBK("当前有客户操作,无法重启").c_str());
- SendPackage(pReplyPkg);
- return Error_Cancel;
- }
- CSimpleStringA strValue = "";
- pFunc->GetSysVar("LocalMaintain", strValue);
- if (strValue.Compare("N") != 0)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleRestartShellReq")("remote restart shell fail for var [LocalMaintain] == '%s'", (const char*)strValue);
- pReplyPkg->SetErrMsg(Error_Param, 0, SP::Utility::UTF8ToGBK("正在本地维护,无法重启").c_str());
- SendPackage(pReplyPkg);
- return Error_Cancel;
- }
- // 释放重启事件给健康实体
- LogEvent(Severity_Middle, EVENT_RESTART_SHELL, "remote restart shell");
- SendPackage(pReplyPkg);
- return Error_Succeed;
- }
- ErrorCodeEnum CRemoteControllerCnn::HandleRestartMachineReq(const CSmartPointer<IPackage> &pRecvPkg)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleRestartMachineReq")("remote restart machine req");
- auto pReplyPkg = CreateReplyPackage(pRecvPkg);
- int nLen = pRecvPkg->GetStructLen("RestOR");
- if (nLen <= 0)
- {
- pReplyPkg->SetErrMsg(Error_Param, 0, "get struct [RestOR] fail");
- SendPackage(pReplyPkg);
- return Error_Param;
- }
- assert(nLen == sizeof(RvcRestartMachineReq));
- RvcRestartMachineReq req = {};
- int nArrayLen(0);
- pRecvPkg->GetStructData("RestOR", (BYTE*)&req, &nLen, &nArrayLen);
- RvcRestartMachineRet ret = {};
- ret.TaskID = req.TaskID;
- pReplyPkg->AddStruct("RestOA", false, false, (BYTE*)&ret, sizeof(ret));
- // 检查当前状态,是否可以重启OS
- auto pFunc = m_pEntity->GetFunction();
- CSimpleStringA strCustomerHandleVal;
- pFunc->GetSysVar("CustomerHandle", strCustomerHandleVal);
- CSimpleStringA strCustomerBeingVal;
- pFunc->GetSysVar("CustomerBeing", strCustomerBeingVal);
- if (strCustomerHandleVal.Compare("N") != 0 || (strCustomerBeingVal.Compare("N") != 0 && strCustomerBeingVal.Compare("S") != 0))
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleRestartMachineReq")("remote restart machine fail for var [CustomerHandle] == '%s' & [CustomerBeing] == '%s'"
- , (const char*)strCustomerHandleVal, (const char*)strCustomerBeingVal);
- pReplyPkg->SetErrMsg(Error_Param, 0, SP::Utility::UTF8ToGBK("当前有客户操作,无法重启").c_str());
- SendPackage(pReplyPkg);
- return Error_Cancel;
- }
- CSimpleStringA strValue = "";
- pFunc->GetSysVar("LocalMaintain", strValue);
- if (strValue.Compare("N") != 0)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleRestartMachineReq")("remote restart machine fail for var [LocalMaintain] == '%s'", (const char*)strValue);
- pReplyPkg->SetErrMsg(Error_Param, 0, SP::Utility::UTF8ToGBK("正在本地维护,无法重启").c_str());
- SendPackage(pReplyPkg);
- return Error_Cancel;
- }
- // 释放重启事件给健康实体
- LogEvent(Severity_Middle, EVENT_RESTART_MACHINE, "remote restart machine");
- SendPackage(pReplyPkg);
- return Error_Succeed;
- }
- ErrorCodeEnum CRemoteControllerCnn::HandleViewEntityStateReq(const CSmartPointer<IPackage> &pRecvPkg)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleViewEntityStateReq")("remote view entity state");
-
- auto pReplyPkg = CreateReplyPackage(pRecvPkg);
- int nLen = pRecvPkg->GetStructLen("ViewEntR");
- if (nLen <=0)
- {
- pReplyPkg->SetErrMsg(Error_Param, 0, "get struct [ViewEntR] fail");
- SendPackage(pReplyPkg);
- return Error_Param;
- }
- assert(nLen == sizeof(RvcViewEntityReq));
- RvcViewEntityReq req = {};
- int nArrayLen(0);
- pRecvPkg->GetStructData("ViewEntR", (BYTE*)&req, &nLen, &nArrayLen);
- RvcViewEntityRet1 ret1 = {};
- ret1.TaskID = req.TaskID;
- pReplyPkg->AddStruct("ViewEnA1", false, false, (BYTE*)&ret1, sizeof(ret1));
- auto pFunc = m_pEntity->GetFunction();
-
- CAutoArray<CSimpleStringA> strEntityNames;
- CAutoArray<WORD> dwEntityIDs;
- pFunc->GetAllRegistedEntity(strEntityNames, dwEntityIDs);
- int nCount = strEntityNames.GetCount();
- if (nCount >0)
- {
- nCount += 8; // 包括root\shell\silverlight3个虚拟实体
- RvcViewEntityRet2 *pRet2 = new RvcViewEntityRet2[nCount];
- memset(pRet2, 0, sizeof(RvcViewEntityRet2) * nCount);
- for(int i=0; i<nCount - 8; i++)
- {
- CEntityRunInfo info = {};
- CSimpleStringA strEntityName = strEntityNames[i];
- pFunc->GetEntityRunInfo(strEntityName, info);
- strncpy_s(pRet2[i].EntityName, sizeof(pRet2[i].EntityName), (const char*)strEntityName, _TRUNCATE);
- pRet2[i].EntityID = dwEntityIDs[i];
- pRet2[i].EntityState = info.eState;
- pRet2[i].ProcessID = info.dwProcessID;
- if (info.dwProcessID > 0)
- {
- #if (defined _WIN32 || defined _WIN64)
- auto hProcess = OpenProcess( PROCESS_ALL_ACCESS, FALSE, info.dwProcessID );
- if (hProcess != NULL)
- {
- PROCESS_MEMORY_COUNTERS pmc = {};
- GetProcessMemoryInfo(hProcess, &pmc, sizeof(pmc));
- pRet2[i].UsedMemory = pmc.WorkingSetSize / 1024 / 1024;
- }
- #else
- pRet2[i].UsedMemory = get_proc_mem(info.dwProcessID) / 1024 / 1024;
-
- #endif
- }
- }
- strncpy_s(pRet2[nCount - 8].EntityName, sizeof(pRet2[nCount - 8].EntityName), "guardian", _TRUNCATE);
- strncpy_s(pRet2[nCount - 7].EntityName, sizeof(pRet2[nCount - 7].EntityName), "DualActive", _TRUNCATE);
- strncpy_s(pRet2[nCount - 6].EntityName, sizeof(pRet2[nCount - 6].EntityName), "SpHost", _TRUNCATE);
- strncpy_s(pRet2[nCount - 5].EntityName, sizeof(pRet2[nCount - 5].EntityName), "SysInit", _TRUNCATE);
- strncpy_s(pRet2[nCount - 4].EntityName, sizeof(pRet2[nCount - 4].EntityName), "SpBase", _TRUNCATE);
- strncpy_s(pRet2[nCount - 3].EntityName, sizeof(pRet2[nCount - 3].EntityName), "Root", _TRUNCATE);
- strncpy_s(pRet2[nCount - 2].EntityName, sizeof(pRet2[nCount - 2].EntityName), "Shell", _TRUNCATE);
- strncpy_s(pRet2[nCount - 1].EntityName, sizeof(pRet2[nCount - 1].EntityName), "Silverlight", _TRUNCATE);
- pReplyPkg->AddStruct("ViewEnA2", false, false, (BYTE*)pRet2, sizeof(RvcViewEntityRet2) * nCount, nCount);
- }
- SendPackage(pReplyPkg);
- return Error_Succeed;
- }
- ErrorCodeEnum CRemoteControllerCnn::HandleViewSysVarReq(const CSmartPointer<IPackage> &pRecvPkg)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleViewSysVarReq")("remote view system vars");
- auto pReplyPkg = CreateReplyPackage(pRecvPkg);
- int nLen = pRecvPkg->GetStructLen("ViewVarR");
- if (nLen <= 0)
- {
- pReplyPkg->SetErrMsg(Error_Param, 0, "get struct [ViewVarR] len fail");
- SendPackage(pReplyPkg);
- return Error_Param;
- }
- assert(nLen == sizeof(RvcViewSysVarReq));
- RvcViewSysVarReq req = {};
- int nArrayLen(0);
- if (!pRecvPkg->GetStructData("ViewVarR", (BYTE*)&req, &nLen, &nArrayLen))
- {
- pReplyPkg->SetErrMsg(Error_Param, 0, "get struct [ViewVarR] data fail");
- SendPackage(pReplyPkg);
- return Error_Param;
- }
- auto pFunc = m_pEntity->GetFunction();
- RvcViewSysVarRet arrRet[5] = {};
- char *arrVarNames[] = { "RunState", "CustomerHandle", "CallState", "EntryPermit", "LocalMaintain" };
- for (int i = 0; i < 5; i++)
- {
- CSimpleStringA strValue;
- pFunc->GetSysVar(arrVarNames[i], strValue);
-
- arrRet[i].TaskID = req.TaskID;
- strcpy(arrRet[i].VarName, arrVarNames[i]);
- arrRet[i].VarValue = strValue[0];
- }
- pRecvPkg->AddStruct("ViewVarA", false, false, (BYTE*)arrRet, sizeof(arrRet), 5);
- SendPackage(pRecvPkg);
- return Error_Succeed;
- }
- ErrorCodeEnum CRemoteControllerCnn::HandleEditConfigReq(const CSmartPointer<IPackage> &pRecvPkg)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleEditConfigReq")("remote edit config");
- auto pReplyPkg = CreateReplyPackage(pRecvPkg);
- int nLen = pRecvPkg->GetStructLen("EditCfgR");
- if (nLen <= 0)
- {
- pReplyPkg->SetErrMsg(Error_Param, 0, "get struct [EditCfgR] len fail");
- SendPackage(pReplyPkg);
- return Error_Param;
- }
- char *pBuf = new char[nLen];
- memset(pBuf, 0, sizeof(pBuf));
-
- int nArrayLen(0);
- if (!pRecvPkg->GetStructData("EditCfgR", (BYTE*)pBuf, &nLen, &nArrayLen) || nArrayLen <=0)
- {
- pReplyPkg->SetErrMsg(Error_Param, 0, "get struct [EditCfgR] data fail");
- SendPackage(pReplyPkg);
- return Error_Param;
- }
- auto pFunc = m_pEntity->GetFunction();
- assert(nLen == nArrayLen * sizeof(RvcEditConfigReq));
- RvcEditConfigReq *pReq = (RvcEditConfigReq*)pBuf;
- RvcEditConfigRet ret = { pReq[0].TaskID };
- for (int i = 0; i < nArrayLen; i++)
- {
- CSimpleStringA strEntityName = pReq[i].EntityName;
- CSimpleStringA strCfgPath;
- if (iequals(strEntityName.GetData(), "Silverlight") || iequals(strEntityName.GetData(), "DualActive") || iequals(strEntityName.GetData(), "SpHost")
- || iequals(strEntityName.GetData(), "SysInit") || iequals(strEntityName.GetData(), "SpBase") || iequals(strEntityName.GetData(), "guardian"))
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleEditConfigReq")("entity \"%s\" has no config", strEntityName);
- pReplyPkg->SetErrMsg(Error_NotExist, 0, SP::Utility::UTF8ToGBK("实体没有配置文件").c_str());
- SendPackage(pReplyPkg);
- delete[] pBuf;
- return Error_NotExist;
- }
- if (iequals(strEntityName.GetData(), "Root"))
- {
- auto rc = pFunc->GetPath("HardwareCfg", strCfgPath);
- assert(rc == Error_Succeed);
- strCfgPath.Append(SPLIT_SLASH_STR).Append("Root.ini");
- }
- else
- {
- auto rc = pFunc->GetPath("Cfg", strCfgPath);
- assert(rc == Error_Succeed);
- strCfgPath.Append(SPLIT_SLASH_STR).Append((const char*)strEntityName).Append(".ini");
- }
- char cEditType = pReq[i].EditType;
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleEditConfigReq")("edit config: entity = %s, type = %c, section = %s, key = %s, value = %s",
- (const char*)strEntityName, cEditType, pReq[i].Section, pReq[i].Key, pReq[i].Value);
- if (cEditType == 'A' || cEditType == 'U')
- WritePrivateProfileStringA(pReq[i].Section, pReq[i].Key, pReq[i].Value, strCfgPath.GetData());
- else if (cEditType == 'D')
- WritePrivateProfileStringA(pReq[i].Section, pReq[i].Key, "", strCfgPath.GetData());
- }
- delete[] pBuf;
- pReplyPkg->AddStruct("EditCfgA", false, false, (BYTE*)&ret, sizeof(ret));
- SendPackage(pRecvPkg);
- return Error_Succeed;
- }
- ErrorCodeEnum CRemoteControllerCnn::HandleViewEntityConfigReq(const CSmartPointer<IPackage> &pRecvPkg)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleViewEntityConfigReq")("remote view entity config");
-
- auto pReplyPkg = CreateReplyPackage(pRecvPkg);
- int nLen = pRecvPkg->GetStructLen("ViewCfgR");
- if (nLen <=0)
- {
- pReplyPkg->SetErrMsg(Error_Param, 0, "get struct [ViewCfgR] fail");
- SendPackage(pReplyPkg);
- return Error_Param;
- }
- assert(nLen == sizeof(RvcViewConfigReq));
- RvcViewConfigReq req = {};
- int nArrayLen(0);
- pRecvPkg->GetStructData("ViewCfgR", (BYTE*)&req, &nLen, &nArrayLen);
- // 读取实体配置文件
- CSimpleStringA strEntityName = req.EntityName;
- auto pFunc = m_pEntity->GetFunction();
- CSimpleStringA strCfgPath;
- if (strEntityName == "Root")
- {
- auto rc = pFunc->GetPath("HardwareCfg", strCfgPath);
- assert(rc == Error_Succeed);
- strCfgPath.Append(SPLIT_SLASH_STR).Append("Root.ini");
- }
- else
- {
- auto rc = pFunc->GetPath("Cfg", strCfgPath);
- assert(rc == Error_Succeed);
- strCfgPath.Append(SPLIT_SLASH_STR).Append((const char*)strEntityName).Append(".ini");
- }
-
- if (!Base_Exist(strCfgPath.GetData()))
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleViewEntityConfigReq")("file [%s] not exist", (const char*)strCfgPath);
- pReplyPkg->SetErrMsg(Error_NotExist, 0, SP::Utility::UTF8ToGBK("配置文件不存在").c_str());
- SendPackage(pReplyPkg);
- return Error_NotExist;
- }
- auto cfgSize = Base_filesize(strCfgPath.GetData());
- char* tmpBuf = new char[cfgSize];
- memset(tmpBuf, 0, cfgSize);
- auto readRet = Base_readFile(strCfgPath.GetData(), 0, tmpBuf, cfgSize);
- if(!readRet.first)
- {
- pReplyPkg->SetErrMsg(0, 0, "open entity config file fail");
- LogError(Severity_Low, Error_NotExist, 0, CSimpleStringA::Format("open config [%s] fail", (const char*)strCfgPath));
- }
- else
- {
- int nRetLen = sizeof(RvcViewConfigRet) + cfgSize * 2; //需自行转换\n和\r\n
- char* pBuf = new char[nRetLen];
- memset(pBuf, 0, nRetLen);
- RvcViewConfigRet* pRet = (RvcViewConfigRet*)pBuf;
- int dstPos = 0;
- for (auto i = 0; i < cfgSize; i++)
- {
- if ((i == 0 && tmpBuf[i] == '\n') || (tmpBuf[i] == '\n' && tmpBuf[i - 1] != '\r'))
- pRet->ConfigData[dstPos++] = '\r';
- pRet->ConfigData[dstPos++] = tmpBuf[i];
- }
- pReplyPkg->AddStruct("ViewCfgA", false, false, (BYTE*)pBuf, dstPos + sizeof(RvcViewConfigRet));
- delete[] pBuf;
- }
- SendPackage(pReplyPkg);
- delete[] tmpBuf;
- return Error_Succeed;
- }
- ErrorCodeEnum CRemoteControllerCnn::HandleViewDebugLogReq(const CSmartPointer<IPackage> &pRecvPkg)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleViewDebugLogReq")("remote view entity debug log");
-
- auto pReplyPkg = CreateReplyPackage(pRecvPkg);
- int nLen = pRecvPkg->GetStructLen("ViewDbgR");
- if (nLen <=0)
- {
- pReplyPkg->SetErrMsg(Error_Param, 0, "get struct [ViewDbgR] fail");
- SendPackage(pReplyPkg);
- return Error_Param;
- }
- assert(nLen == sizeof(RvcViewDbgReq));
- RvcViewDbgReq req = {};
- int nArrayLen(0);
- pRecvPkg->GetStructData("ViewDbgR", (BYTE*)&req, &nLen, &nArrayLen);
- auto pFunc = m_pEntity->GetFunction();
- CSimpleStringA strEntityName = req.EntityName;
-
- if (iequals(strEntityName.GetData(), "Root"))
- {
- pReplyPkg->SetErrMsg(Error_NotExist, 0, SP::Utility::UTF8ToGBK("Root实体没有日志").c_str());
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleViewDebugLogReq")("entity \"Root\" has no dbg log");
- SendPackage(pReplyPkg);
- return Error_NotExist;
- }
- CSimpleStringA strViewDate = req.ViewDate;
- if (strViewDate.IsNullOrEmpty())
- {
- strViewDate = getCurData().c_str();
- }
- ErrorCodeEnum rc(Error_Succeed);
- CSimpleStringA strLogPath;
- if (iequals(strEntityName.GetData(), "Shell"))
- {
- auto rc = pFunc->GetPath("Dbg", strLogPath);
- assert(rc == Error_Succeed);
- strLogPath.Append(SPLIT_SLASH_STR).Append("SpShell").Append(SPLIT_SLASH_STR).Append((const char*)strViewDate).Append(".log");
- }
- else if (iequals(strEntityName.GetData(), "Silverlight"))
- {
- auto rc = pFunc->GetPath("Slv", strLogPath);
- assert(rc == Error_Succeed);
- strLogPath.Append(SPLIT_SLASH_STR).Append((const char*)strViewDate).Append(".log");
- }
- else if (iequals(strEntityName.GetData(), "DualActive")|| iequals(strEntityName.GetData(), "SpHost")
- || iequals(strEntityName.GetData(), "SysInit") || iequals(strEntityName.GetData(), "SpBase") || iequals(strEntityName.GetData(), "guardian"))
- {
- auto rc = pFunc->GetPath("Dbg", strLogPath);
- assert(rc == Error_Succeed);
- strLogPath.Append(SPLIT_SLASH_STR).Append((const char*)strEntityName).Append(SPLIT_SLASH_STR).Append((const char*)strViewDate).Append(".log");
- }
- else
- {
- CEntityStaticInfo info = {};
- auto rc = pFunc->GetEntityStaticInfo(strEntityName, info);
- if (rc != Error_Succeed)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleViewDebugLogReq")("invalid entity name [%s]", strEntityName);
- pReplyPkg->SetErrMsg(rc, 0, SP::Utility::UTF8ToGBK(CSimpleStringA::Format("实体名称\"%s\"无效", strEntityName).GetData()).c_str());
- SendPackage(pReplyPkg);
- return rc;
- }
- rc = pFunc->GetPath("Dbg", strLogPath);
- assert(rc == Error_Succeed);
- strLogPath.Append(SPLIT_SLASH_STR).Append((const char*)info.strSpFileName).Append(SPLIT_SLASH_STR).Append((const char*)strViewDate).Append(".log");
- }
- if (!Base_Exist(strLogPath.GetData()))
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleViewDebugLogReq")("log [%s] not exist", (const char*)strLogPath);
- pReplyPkg->SetErrMsg(Error_NotExist, 0, SP::Utility::UTF8ToGBK(CSimpleStringA::Format("日志文件[%s]不存在", (const char*)strLogPath).GetData()).c_str());
- SendPackage(pReplyPkg);
- return Error_NotExist;
- }
- long long nStartPos = req.StartPos;
- if (nStartPos <0)
- nStartPos = 0;
-
- long long nMaxBytes = req.MaxRetBytes;
- if (nMaxBytes <= 0)
- nMaxBytes = 8 * 1024;
- auto file = fopen(strLogPath, "rb");
- if (file == NULL)
- {
- auto nError = errno;
- pReplyPkg->SetErrMsg(Error_NotExist, 0, CSimpleStringA::Format("open debug log [%s] fail(%d)", (const char*)strLogPath, nError));
- LogError(Severity_Low, Error_NotExist, 0, CSimpleStringA::Format("open debug log [%s] fail(%d)", (const char*)strLogPath, nError));
- SendPackage(pReplyPkg);
- return rc;
- }
- generateFilesize(file, strLogPath);
- if (nStartPos >0 && nStartPos < nFileSize)
- _fseeki64(file, nStartPos, SEEK_SET);
- else
- nStartPos = 0;
-
- long long nNextPos = nStartPos + nMaxBytes;
- if (nMaxBytes + nStartPos > nFileSize)
- {
- nMaxBytes = nFileSize - nStartPos;
- nNextPos = 0;
- }
-
- long long nRetLen = sizeof(RvcViewDbgRet) +nMaxBytes;
- char *pBuf = new char[nRetLen];
- memset(pBuf, 0, nRetLen);
-
- RvcViewDbgRet *pRet = (RvcViewDbgRet*)pBuf;
- pRet->TaskID = req.TaskID;
- strncpy_s(pRet->EntityName, sizeof(pRet->EntityName), strEntityName, _TRUNCATE);
- strncpy(pRet->ViewDate, strViewDate, 8);
- pRet->NextPos = nNextPos;
- pRet->FileLength = nFileSize;
- char *pLogData = (char*)pRet->LogData;
- long long nHasRead(0);
- DWORD nReadLen(0);
-
- BOOL bRet = TRUE;
- do
- {
- nReadLen = fread(pLogData+nHasRead, 1, nMaxBytes-nHasRead, file);
-
- if (nReadLen >0)
- nHasRead += nReadLen;
- }
- while (nReadLen >0 && nHasRead < nMaxBytes);
- fclose(file);
- if (!bRet)
- {
- delete[] pBuf;
- auto nError = GetLastError();
- pReplyPkg->SetErrMsg(Error_NotExist, 0, CSimpleStringA::Format("read log [%s] fail(%d)", (const char*)strLogPath, nError));
- LogError(Severity_Low, Error_NotExist, 0, CSimpleStringA::Format("read log [%s] fail(%d)", (const char*)strLogPath, nError));
- SendPackage(pReplyPkg);
- return rc;
- }
- if (pRet->NextPos > 0)
- {
- // 整行切分处理
- while (nReadLen > sizeof(RvcViewDbgRet) &&
- (pBuf[nRetLen - 1] != '\r' && pBuf[nRetLen - 1] != '\n'))
- {
- nRetLen--;
- pRet->NextPos--;
- }
- }
- pReplyPkg->AddStruct("ViewDbgA", false, false, (BYTE*)pBuf, nRetLen);
- delete[] pBuf;
-
- SendPackage(pReplyPkg);
- return Error_Succeed;
- }
- ErrorCodeEnum CRemoteControllerCnn::HandleUploadEventLogReq(const CSmartPointer<IPackage> &pRecvPkg)
- {
- //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleUploadEventLogReq")("remote upload event log");
- //auto pReplyPkg = CreateReplyPackage(pRecvPkg);
- //int nLen = pRecvPkg->GetStructLen("EvtLogR");
- //if (nLen <= 0)
- //{
- // pReplyPkg->SetErrMsg(Error_Param, 0, "get struct [EvtLogR] fail");
- // SendPackage(pReplyPkg);
- // return Error_Param;
- //}
- //if (nLen != sizeof(RvcUploadEventLogReq))
- // DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleUploadEventLogReq")("nLen:%d, RvcUploadEventLogReq Size:%d", nLen, sizeof(RvcUploadEventLogReq));
- //assert(nLen == sizeof(RvcUploadEventLogReq));
- //RvcUploadEventLogReq req;
- //int nArrayLen(0);
- //pRecvPkg->GetStructData("EvtLogR", (BYTE*)&req, &nLen, &nArrayLen);
- //auto pFunc = m_pEntity->GetFunction();
- //CSimpleStringA strZipFileName;
- //CSimpleStringA strLogPath;
- //CSimpleStringA strZipPath, strTodayLogName;
- //if (req.StartPos <= 0)
- //{
- // ResourceWatcherService_ExtractEventLog_Req rvcReq;
- // ZeroMemory(&rvcReq, sizeof(ResourceWatcherService_ExtractEventLog_Req));
- // {//初始化rvcReq
- // rvcReq.evtName = req.evtName;
- // rvcReq.evtLevel = req.evtLevel;
- // rvcReq.duration = req.duration;
- // rvcReq.startTime = req.startTime;
- // rvcReq.endTime = req.endTime;
- // rvcReq.cusEvtFileName = CSimpleStringA(req.cusEvtFileName);
- // rvcReq.evtSrcEventName = CSimpleStringA(req.evtSrcEventName);
- // rvcReq.reversed1 = req.reversed1;
- // rvcReq.reversed2 = CSimpleStringA(req.reversed2);
- // }
- // ResourceWatcherService_ExtractEventLog_Ans rvcAns;
- // ZeroMemory(&rvcAns, sizeof(ResourceWatcherService_ExtractEventLog_Ans));
- // ResourceWatcherService_ClientBase *pClient = new ResourceWatcherService_ClientBase(m_pEntity);
- // auto rc = pClient->Connect();
- // if (rc == Error_Succeed)
- // {
- // DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleUploadEventLogReq")("evtName:%d, evtLevel:%d, duration:%d, startTime:%d, endTime:%d, cusEvtFileName:%s,evtSrcEventName:%s, reversed1:%d, reversed2:%s, startPos:%d, MaxRet:%d, UploadFile:%s",
- // req.evtName, req.evtLevel, req.duration, req.startTime, req.endTime,
- // req.cusEvtFileName, req.evtSrcEventName, req.reversed1, req.reversed2, req.StartPos, req.MaxRetBytes, req.UploadFile);
- // rc = (*pClient)(EntityResource::getLink().upgradeLink())->ExtractEventLog(rvcReq, rvcAns, 60000 * 5);
- // DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleUploadEventLogReq")("entries:%d, information:%s, evtLogFileName:%s", rvcAns.entries, rvcAns.information.GetData(), rvcAns.evtLogFileName.GetData());
- // pClient->GetFunction()->CloseSession();
- // }
- // if (rc != Error_Succeed)
- // {
- // pReplyPkg->SetErrMsg(rc, 0, SP::Utility::UTF8ToGBK("调用[ResourceWatcher]实体失败").c_str());
- // LogError(Severity_Low, rc, 0, "调用[ResourceWatcher]实体失败");
- // }
- // else
- // {
- // DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleUploadEventLogReq")("获取系统事件日志成功");
- // //压缩位置
- // strTodayLogName = getCurData().c_str();
- // CSystemStaticInfo sysInfo;
- // auto rc = pFunc->GetSystemStaticInfo(sysInfo);
- // strZipFileName = CSimpleStringA::Format("%s_event_%s_%02X_%02X.zip", (const char*)sysInfo.strTerminalID, (const char*)strTodayLogName, rvcAns.entries,
- // req.evtLevel + req.duration + req.startTime + req.endTime);
- // pFunc->GetPath("Temp", strZipPath);
- // strZipPath.Append(SPLIT_SLASH_STR).Append(strZipFileName);
- // strLogPath = rvcAns.evtLogFileName;
- // if (0 == rvcAns.entries)
- // {
- // DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleUploadEventLogReq")("log [%s] not exist", (const char*)strLogPath);
- // pReplyPkg->SetErrMsg(Error_NotExist, 0, SP::Utility::UTF8ToGBK(CSimpleStringA::Format("未能获取到相关日志").GetData()).c_str());
- // SendPackage(pReplyPkg);
- // return Error_NotExist;
- // }
- // if (!Base_Exist(strLogPath.GetData()))
- // {
- // DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleUploadEventLogReq")("log [%s] not exist", (const char*)strLogPath);
- // pReplyPkg->SetErrMsg(Error_NotExist, 0, SP::Utility::UTF8ToGBK(CSimpleStringA::Format("日志文件[%s]不存在", (const char*)strLogPath).GetData()).c_str());
- // SendPackage(pReplyPkg);
- // return Error_NotExist;
- // }
- // // 生成ZIP
- // rc = ZipFile(strZipPath, strLogPath);
- // if (rc != Error_Succeed)
- // {
- // pReplyPkg->SetErrMsg(rc, 0, SP::Utility::UTF8ToGBK(CSimpleStringA::Format("生成压缩文件[%s]失败", (const char*)strZipFileName).GetData()).c_str());
- // SendPackage(pReplyPkg);
- // return rc;
- // }
- // else
- // Base_DeleteFile(strLogPath.GetData());
- // }
- //}
- //else
- //{
- // strZipFileName = req.UploadFile;
- // pFunc->GetPath("Temp", strZipPath);
- // strZipPath.Append(SPLIT_SLASH_STR).Append(strZipFileName);
- //}
- //if (!Base_Exist(strZipPath.GetData()))
- //{
- // DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleUploadEventLogReq")("zip log [%s] not exist", (const char*)strZipPath);
- // pReplyPkg->SetErrMsg(Error_NotExist, 0, SP::Utility::UTF8ToGBK(CSimpleStringA::Format("日志压缩文件[%s]不存在", (const char*)strZipPath).GetData()).c_str());
- // SendPackage(pReplyPkg);
- // return Error_NotExist;
- //}
- //// 开始上传
- //long long nStartPos = req.StartPos;
- //if (nStartPos <0)
- // nStartPos = 0;
- //long long nMaxBytes = req.MaxRetBytes;
- //if (nMaxBytes <= 0)
- // nMaxBytes = 32 * 1024;
- //auto file = fopen(strZipPath, "rb");
- //if (file == NULL)
- //{
- // auto nError = errno;
- // pReplyPkg->SetErrMsg(Error_Unexpect, 0, SP::Utility::UTF8ToGBK(CSimpleStringA::Format("读取日志文件[%s]失败(%d)", (const char*)strZipFileName, nError).GetData()).c_str());
- // DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleUploadEventLogReq")(CSimpleStringA::Format("open debug log [%s] fail(%d)", (const char*)strZipPath, nError));
- // SendPackage(pReplyPkg);
- // return Error_Unexpect;
- //}
- //generateFilesize(file, strZipPath);
- //if (nStartPos >0 && nStartPos < nFileSize)
- //{
- // _fseeki64(file, nStartPos, SEEK_SET);
- //}
- //else
- // nStartPos = 0;
- //long long nNextPos = nStartPos + nMaxBytes;
- //if (nMaxBytes + nStartPos > nFileSize)
- //{
- // nMaxBytes = nFileSize - nStartPos;
- // nNextPos = 0;
- //}
- //long long nRetLen = sizeof(RvcUploadEventLogRet)+nMaxBytes;
- //char *pBuf = new char[nRetLen];
- //memset(pBuf, 0, nRetLen);
- //RvcUploadEventLogRet *pRet = (RvcUploadEventLogRet*)pBuf;
- //pRet->TaskID = req.TaskID;
- //strncpy_s(pRet->UploadFile, sizeof(pRet->UploadFile), strZipFileName, _TRUNCATE);
- //pRet->ZipFileLen = nFileSize;
- //pRet->StartPos = req.StartPos;
- //pRet->NextPos = nNextPos;
- //char *pLogData = (char*)pRet->LogData;
- //long long nHasRead(0);
- //DWORD nReadLen(0);
- //BOOL bRet = TRUE;
- //do
- //{
- // //Dbg("ftell: %d", ftell(file));
- // nReadLen = fread(pLogData + nHasRead, 1, nMaxBytes - nHasRead, file);
- // //Dbg("ftell: %d", ftell(file));
- // if (nReadLen >0)
- // nHasRead += nReadLen;
- //} while (nReadLen >0 && nHasRead < nMaxBytes);
- //fclose(file);
- //if (nHasRead < nMaxBytes)
- //{
- // delete[] pBuf;
- // auto nError = GetLastError();
- // pReplyPkg->SetErrMsg(Error_NotExist, 0, SP::Utility::UTF8ToGBK(CSimpleStringA::Format("读取文件[%s]失败(%d)", (const char*)strZipFileName, nError).GetData()).c_str());
- // DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleUploadEventLogReq")(CSimpleStringA::Format("read log [%s] fail(%d)", (const char*)strZipPath, nError));
- // SendPackage(pReplyPkg);
- // return Error_Unexpect;
- //}
- //pReplyPkg->AddStruct("EvtLogA", false, false, (BYTE*)pBuf, nRetLen);
- //delete[] pBuf;
- //SendPackage(pReplyPkg);
- //if (nNextPos <= 0)
- //{
- // // 删除压缩文件
- // DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleUploadEventLogReq")("finish upload log zip '%s', delete it!", (const char*)strZipFileName);
- // Base_DeleteFile(strZipPath.GetData());
- //}
- return Error_Succeed;
- }
- char *makeOperateDiskJson(RvcOperateDiskRet1 *ret1, RvcOperateDiskRet2 *ret2, int ret2Num)
- {
- cJSON * pJsonRoot = NULL;
- pJsonRoot = cJSON_CreateObject();
- if(NULL == pJsonRoot || NULL == ret1 || NULL == ret2 || ret2Num <= 0)
- return NULL;
- cJSON_AddNumberToObject(pJsonRoot, "TaskID", ret1->TaskID);
- cJSON_AddNumberToObject(pJsonRoot, "result", ret1->result);
- cJSON_AddStringToObject(pJsonRoot, "header", ret1->header);
- cJSON_AddNumberToObject(pJsonRoot, "attachment1", ret1->attachment1);
- cJSON *arrFileName = cJSON_CreateArray(), *arrFileSize = cJSON_CreateArray(), *arrFtCreate = cJSON_CreateArray(), *arrftModified = cJSON_CreateArray(),
- *arrftAccess = cJSON_CreateArray(), *arrFileAttribute = cJSON_CreateArray(), *arrForbidAttributes = cJSON_CreateArray(),
- *arrReserved1 = cJSON_CreateArray(), *arrReserved2 = cJSON_CreateArray();
- if (NULL == arrFileName || NULL == arrFileSize || NULL == arrFtCreate || NULL == arrftModified || NULL == arrftAccess || NULL == arrFileAttribute || NULL == arrForbidAttributes
- || NULL == arrReserved1 || NULL ==arrReserved2)
- return NULL;
- for (int i = 0; i < ret2Num; i++)
- {
- CDigitalConv62 d62;
- char temp[30] = "";
- string str62;
- cJSON_AddStringToObject(arrFileName, "fileName", ret2[i].fileName);
- _ui64toa(ret2[i].fileSize, temp, 10);
- cJSON_AddStringToObject(arrFileSize, "fileSize", d62.to_x(temp, 1).data());
- _ui64toa(ret2[i].ftCreate, temp, 10);
- cJSON_AddStringToObject(arrFtCreate, "ftCreate", d62.to_x(temp, 1).data());
- _ui64toa(ret2[i].ftModified, temp, 10);
- cJSON_AddStringToObject(arrftModified, "ftModified", d62.to_x(temp, 1).data());
- _ui64toa(ret2[i].ftAccess, temp, 10);
- cJSON_AddStringToObject(arrftAccess, "ftAccess", d62.to_x(temp, 1).data());
- cJSON_AddNumberToObject(arrFileAttribute, "fileAttribute", ret2[i].fileAttribute);
- cJSON_AddNumberToObject(arrForbidAttributes, "forbidAttributes", ret2[i].forbidAttributes);
- if (0 != ret2[i].reserved1)
- cJSON_AddNumberToObject(arrReserved1, "reserved1", ret2[i].reserved1);
-
- //cJSON_AddStringToObject(arrReserved2, "reserved2", ret2[i].reserved2);
- }
- cJSON_AddItemToObject(pJsonRoot, "arrFileName", arrFileName);
- cJSON_AddItemToObject(pJsonRoot, "arrFileSize", arrFileSize);
- cJSON_AddItemToObject(pJsonRoot, "arrFtCreate", arrFtCreate);
- cJSON_AddItemToObject(pJsonRoot, "arrftModified", arrftModified);
- cJSON_AddItemToObject(pJsonRoot, "arrftAccess", arrftAccess);
- cJSON_AddItemToObject(pJsonRoot, "arrFileAttribute", arrFileAttribute);
- cJSON_AddItemToObject(pJsonRoot, "arrForbidAttributes", arrForbidAttributes);
- cJSON_AddItemToObject(pJsonRoot, "arrReserved1", arrReserved1);
- //cJSON_AddItemToObject(pJsonRoot, "arrReserved2", arrReserved2);
- char *out = cJSON_Print(pJsonRoot);
- cJSON_Delete(pJsonRoot);
- return out;
- }
- #pragma optimize( "", off )
- ErrorCodeEnum CRemoteControllerCnn::HandleOperateDiskReq(const CSmartPointer<IPackage> &pRecvPkg)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleOperateDiskReq")("request operate disk");
- auto pReplyPkg = CreateReplyPackage(pRecvPkg);
- int nLen = pRecvPkg->GetStructLen("OprDiskR");
- if (nLen <= 0)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleOperateDiskReq")("Failed:[OprDiskR]");
- pReplyPkg->SetErrMsg(Error_Param, 0, "get struct [OprDiskR] fail");
- SendPackage(pReplyPkg);
- return Error_Param;
- }
- assert(nLen == sizeof(RvcOperateDiskReq));
- RvcOperateDiskReq req = {};
- int nArrayLen(0);
- pRecvPkg->GetStructData("OprDiskR", (BYTE*)&req, &nLen, &nArrayLen);
-
- // 调用本地维护实体取控制信息
- ResourceWatcherService_OperateFile_Req rvcReq;
- ZeroMemory(&rvcReq, sizeof(ResourceWatcherService_OperateFile_Req));
- {//初始化rvcReq
- CSimpleStringA curTmp(req.current);
- #if (defined _WIN32 || defined _WIN64)
- rvcReq.current = curTmp;
- #else
- if (curTmp[0] == '/')
- rvcReq.current = curTmp;
- else
- {
- std::string tmpStr = curTmp.GetData();
- std::replace(tmpStr.begin(), tmpStr.end(), '\\', '/');
- rvcReq.current = CSimpleStringA("/") + tmpStr.c_str();
- }
-
- #endif
- rvcReq.mode = req.mode;
- rvcReq.attribute = req.attribute;
- rvcReq.content = CSimpleStringA(req.content);
- rvcReq.filter1 = req.filter1;
- rvcReq.filter2 = CSimpleStringA(req.filter2);
- rvcReq.attachment1 = req.attachment1;
- rvcReq.attachment2 = CSimpleStringA(req.attachment2);
- }
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleOperateDiskReq")("current:%s, reqMode:%d, mode:%d, attribute:%d, content:%s", rvcReq.current.GetData(), req.mode, rvcReq.mode, rvcReq.attribute, rvcReq.content.GetData());
- ResourceWatcherService_OperateFile_Ans rvcAns;
- ZeroMemory(&rvcAns, sizeof(ResourceWatcherService_OperateFile_Ans));
- ResourceWatcherService_ClientBase *pClient = new ResourceWatcherService_ClientBase(m_pEntity);
- RvcOperateDiskRet2 *pRet2 = NULL;
- auto rc = pClient->Connect();
- if (rc == Error_Succeed)
- {
- rc = (*pClient)(EntityResource::getLink().upgradeLink())->OperateFile(rvcReq, rvcAns, 60000);
- pClient->GetFunction()->CloseSession();
-
- }
- if (rc != Error_Succeed)
- {
- pReplyPkg->SetErrMsg(rc, 0, SP::Utility::UTF8ToGBK("调用[ResourceWatcher]实体失败").c_str());
- LogError(Severity_Low, rc, 0, "调用[ResourceWatcher]实体失败");
- }
- else
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleOperateDiskReq")("获取磁盘目录信息成功");
- //添加首层目录信息
- RvcOperateDiskRet1 ret1(req.TaskID, rvcAns.result, rvcAns.header, rvcAns.attachment1);
- RvcOperateDiskRet2 current(rvcAns.attachment2, rvcAns.fileSize, rvcAns.ftCreate, rvcAns.ftModified,
- rvcAns.ftAccess, rvcAns.fileAttribute, rvcAns.forbidAttribute, rvcAns.reversed1, rvcAns.reversed2);
- //添加目录具体文件信息
- pRet2 = new RvcOperateDiskRet2[rvcAns.count + 1];
- ZeroMemory(pRet2, sizeof(RvcOperateDiskRet2) * (rvcAns.count + 1));
- memcpy(&(pRet2[0]), ¤t, sizeof(RvcOperateDiskRet2));
- //Dbg("size:%d", rvcAns.count);
- for (int i = 0; i < rvcAns.count; i++)
- {
-
- RvcOperateDiskRet2 tempRet(rvcAns.fileNames[i], rvcAns.fileSizes[i], rvcAns.ftCreates[i], rvcAns.ftModifieds[i],
- rvcAns.ftAccesses[i], rvcAns.fileAttributes[i], rvcAns.forbidAttributes[i],
- (rvcAns.reserved1.GetCount() == rvcAns.count ? rvcAns.reserved1[i] : 0), (rvcAns.reserved2.GetCount() == rvcAns.count ? rvcAns.reserved2[i] : ""));
- memcpy(&(pRet2[i + 1]), &tempRet, sizeof(RvcOperateDiskRet2));
- }
- char *outStr = makeOperateDiskJson(&ret1, pRet2, rvcAns.count + 1);
- char *slimJsonStr = new char[strlen(outStr)];
- ZeroMemory(slimJsonStr, strlen(outStr));
- int pos = 0;
- for (int i = 0; i < strlen(outStr); i++)
- {
- if ('\t' != outStr[i] && '\n' != outStr[i])
- {
- slimJsonStr[pos] = outStr[i];
- pos++;
- }
- }
- slimJsonStr[pos] = '\0';
- long long nRetLen = sizeof(RvcOperateDiskJsonRet) + 60 * 1024;
- char *pBuf = new char[nRetLen];
- ZeroMemory(pBuf, nRetLen);
- RvcOperateDiskJsonRet *pRet = (RvcOperateDiskJsonRet*)pBuf;
- pRet->TaskID = req.TaskID;
- auto pFunc = m_pEntity->GetFunction();
- CSimpleStringA jsonFileName, tempDir, zipJsonName;
- pFunc->GetPath("Temp", tempDir);
- jsonFileName.Append(tempDir).Append(SPLIT_SLASH_STR).Append("transfer.txt");
- zipJsonName.Append(tempDir).Append(SPLIT_SLASH_STR).Append("zipJson.zip");
- Dbg("jsonFileName:%s", jsonFileName.GetData());
- try {
- FILE* fp = NULL;
- fp = fopen(jsonFileName.GetData(), "w+");
- if (fp) {
- Dbg("jsonLength:%d", pRet->jsonLength);
- auto gbkStr = SP::Utility::UTF8ToGBK(slimJsonStr);
- fputs(gbkStr.c_str(), fp);
- fclose(fp);
- }
-
- /*
- std::fstream jsonFile;
- Dbg("1");
- jsonFile.open(jsonFileName.GetData(), ios::out | ios::trunc);
- Dbg("2");
- if (jsonFile && jsonFile.is_open())
- {
- Dbg("jsonLength:%d", pRet->jsonLength);
- auto gbkStr = SP::Utility::UTF8ToGBK(slimJsonStr);
- jsonFile << gbkStr << endl;
- jsonFile.close();
- }
- */
- }
- catch (std::exception& e)
- {
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setAPI("HandleOperateDiskReq")("%s write err, %s", jsonFileName.GetData(), e.what());
- }
- if (Error_Succeed != (rc = ZipFile(zipJsonName, jsonFileName)))
- {
- pReplyPkg->SetErrMsg(rc, 0, SP::Utility::UTF8ToGBK(CSimpleStringA::Format("生成压缩文件[%s]失败", (const char*)zipJsonName).GetData()).c_str());
- SendPackage(pReplyPkg);
- return rc;
- }
- FILE* fp;
- FILE* infile = fopen(zipJsonName.GetData(), "rt");
- pRet->jsonLength = fread(pRet->jsonData, sizeof(char), 20000, infile);
- fclose(infile);
- /*
- std::ifstream t;
- t.open(zipJsonName, std::ios_base::binary | std::ios_base::in | std::ios_base::out); // open input file
- t.seekg(0, std::ios::end); // go to the end
- pRet->jsonLength = t.tellg(); // report location (this is the length)
- t.seekg(0, std::ios::beg); // go back to the beginning
- t.read(pRet->jsonData, pRet->jsonLength); // read the whole file into the buffer
- t.close(); // close file handle
- */
- pReplyPkg->AddStruct("OprDkJA", false, false, (BYTE*)pRet, nRetLen);
- delete []slimJsonStr;
- Base_DeleteFile(jsonFileName.GetData());
- Base_DeleteFile(zipJsonName.GetData());
-
- }
- SendPackage(pReplyPkg);
- return Error_Succeed;
- }
- ErrorCodeEnum CRemoteControllerCnn::HandleEnterMaintainModeReq(const CSmartPointer<IPackage> &pRecvPkg)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleEnterMaintainModeReq")("request enter maintain mode");
-
- auto pReplyPkg = CreateReplyPackage(pRecvPkg);
- int nLen = pRecvPkg->GetStructLen("EnterMMR");
- if (nLen <=0)
- {
- pReplyPkg->SetErrMsg(Error_Param, 0, "get struct [EnterMMR] fail");
- SendPackage(pReplyPkg);
- return Error_Param;
- }
- assert(nLen == sizeof(RvcEnterMaintainModeReq));
- RvcEnterMaintainModeReq req = {};
- int nArrayLen(0);
- pRecvPkg->GetStructData("EnterMMR", (BYTE*)&req, &nLen, &nArrayLen);
-
- RvcEnterMaintainModeRet ret = {};
- ret.TaskID = req.TaskID;
- pReplyPkg->AddStruct("EnterMMA", false, false, (BYTE*)&ret, sizeof(ret));
- // 检查当前状态
- auto pFunc = m_pEntity->GetFunction();
- CSimpleStringA strCustomerHandleVal;
- pFunc->GetSysVar("CustomerHandle", strCustomerHandleVal);
- CSimpleStringA strCustomerBeingVal;
- pFunc->GetSysVar("CustomerBeing", strCustomerBeingVal);
- if (strCustomerHandleVal.Compare("N") != 0 || (strCustomerBeingVal.Compare("N") != 0 && strCustomerBeingVal.Compare("S") != 0))
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleEnterMaintainModeReq")("remote enter maintain mode fail for var [CustomerHandle] == '%s' & [CustomerBeing] == '%s'"
- , (const char*)strCustomerHandleVal, (const char*)strCustomerBeingVal);
- pReplyPkg->SetErrMsg(Error_Param, 0, SP::Utility::UTF8ToGBK("当前有客户操作,无法暂停服务").c_str());
- SendPackage(pReplyPkg);
- return Error_Cancel;
- }
-
- CSimpleStringA strValue = "";
- pFunc->GetSysVar("LocalMaintain", strValue);
- if (strValue.Compare("N") != 0)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleEnterMaintainModeReq")("remote enter maintain mode fail for var [LocalMaintain] == '%s'", (const char*)strValue);
- pReplyPkg->SetErrMsg(Error_Param, 0, SP::Utility::UTF8ToGBK("正在本地维护,无法暂停服务").c_str());
- SendPackage(pReplyPkg);
- return Error_Cancel;
- }
- // 调用健康实体进入维护模式
- HealthManagerService_ClientBase *pClient = new HealthManagerService_ClientBase(m_pEntity);
- auto rc = pClient->Connect();
- if (rc == Error_Succeed)
- {
- HealthManagerService_EnterState_Req req = {};
- req.state = "M";
- HealthManagerService_EnterState_Ans ans = {};
- rc = pClient->EnterState(req, ans, 10000);
- pClient->GetFunction()->CloseSession();
- }
- else {
- pClient->SafeDelete();
- }
-
- if (rc != Error_Succeed)
- {
- pReplyPkg->SetErrMsg(rc, 0, SP::Utility::UTF8ToGBK("调用健康实体进入维护模式失败").c_str());
- LogError(Severity_Low, rc, 0, "调用健康失败进入维护模式失败");
- }
-
- SendPackage(pReplyPkg);
- return Error_Succeed;
- }
- ErrorCodeEnum CRemoteControllerCnn::HandleExitMaintainModeReq(const CSmartPointer<IPackage> &pRecvPkg)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleExitMaintainModeReq")("request exit maintain mode");
-
- auto pReplyPkg = CreateReplyPackage(pRecvPkg);
- int nLen = pRecvPkg->GetStructLen("ExitMMR");
- if (nLen <=0)
- {
- pReplyPkg->SetErrMsg(Error_Param, 0, SP::Utility::UTF8ToGBK("get struct [ExitMMR] fail").c_str());
- SendPackage(pReplyPkg);
- return Error_Param;
- }
- assert(nLen == sizeof(RvcExitMaintainModeReq));
- RvcExitMaintainModeReq req = {};
- int nArrayLen(0);
- pRecvPkg->GetStructData("ExitMMR", (BYTE*)&req, &nLen, &nArrayLen);
-
- RvcExitMaintainModeRet ret = {};
- ret.TaskID = req.TaskID;
- pReplyPkg->AddStruct("ExitMMA", false, false, (BYTE*)&ret, sizeof(ret));
-
- HealthManagerService_ClientBase *pClient = new HealthManagerService_ClientBase(m_pEntity);
- auto rc = pClient->Connect();
- if (rc == Error_Succeed)
- {
- HealthManagerService_ExitState_Req req = {};
- req.state = "M";
- HealthManagerService_ExitState_Ans ans = {};
- rc = pClient->ExitState(req, ans, 10000);
- pClient->GetFunction()->CloseSession();
- } else {
- pClient->SafeDelete();
- }
-
- if (rc != Error_Succeed)
- {
- pReplyPkg->SetErrMsg(rc, 0, SP::Utility::UTF8ToGBK("调用健康实体退出维护模式失败").c_str());
- LogError(Severity_Low, rc, 0, "调用健康失败退出维护模式失败");
- }
-
- SendPackage(pReplyPkg);
- return Error_Succeed;
- }
- ErrorCodeEnum CRemoteControllerCnn::HandleUpgradePackReq(const CSmartPointer<IPackage> &pRecvPkg)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleUpgradePackReq")("request remote upgarde pack");
-
- auto pReplyPkg = CreateReplyPackage(pRecvPkg);
- int nLen = pRecvPkg->GetStructLen("UpgPackR");
- if (nLen <=0)
- {
- pReplyPkg->SetErrMsg(Error_Param, 0, "get struct [UpgPackR] fail");
- SendPackage(pReplyPkg);
- return Error_Param;
- }
- assert(nLen == sizeof(RvcUpgradePackReq));
- RvcUpgradePackReq req = {};
- int nArrayLen(0);
- pRecvPkg->GetStructData("UpgPackR", (BYTE*)&req, &nLen, &nArrayLen);
- RvcUpgradePackRet ret = {};
- ret.TaskID = req.TaskID;
- pReplyPkg->AddStruct("UpgPackA", false, false, (BYTE*)&ret, sizeof(ret));
- CSimpleStringA strPack = req.PackName;
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleUpgradePackReq")("begin upgrade pack: %s", (const char*)strPack);
-
- // 调用升级实体接口升级
- UpgradeMgrService_ClientBase *pClient = new UpgradeMgrService_ClientBase(m_pEntity);
- auto rc = pClient->Connect();
- if (rc == Error_Succeed)
- {
- UpgradeMgrService_RegistLocalPack_Req req = {};
- req.strPackFile = strPack;
- UpgradeMgrService_RegistLocalPack_Ans ans = {};
- rc = (*pClient)(EntityResource::getLink().upgradeLink())->RegistLocalPack(req, ans, 10000);
- pClient->GetFunction()->CloseSession();
- } else {
- pClient->SafeDelete();
- }
- if (rc != Error_Succeed)
- {
- if (rc == Error_NotExist)
- pReplyPkg->SetErrMsg(rc, 0, SP::Utility::UTF8ToGBK("升级包文件不存在").c_str());
- else if (rc == Error_AlreadyExist)
- pReplyPkg->SetErrMsg(rc, 0, SP::Utility::UTF8ToGBK("升级包已安装").c_str());
- else if (rc == Error_Cancel)
- pReplyPkg->SetErrMsg(rc, 0, SP::Utility::UTF8ToGBK("升级包已被取消安装").c_str());
- else
- pReplyPkg->SetErrMsg(rc, 0, SP::Utility::UTF8ToGBK("远程执行升级失败").c_str());
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleUpgradePackReq")("remote regist upgrade pack fail: 0x%X", rc);
- }
- else
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleUpgradePackReq")("remote regist upgrade pack succeed!");
- }
-
- SendPackage(pReplyPkg);
- return Error_Succeed;
- }
- ErrorCodeEnum CRemoteControllerCnn::HandleRollbackUpgradeReq(const CSmartPointer<IPackage> &pRecvPkg)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleRollbackUpgradeReq")("request remote rollback upgarde");
-
- auto pReplyPkg = CreateReplyPackage(pRecvPkg);
- int nLen = pRecvPkg->GetStructLen("RollbakR");
- if (nLen <= 0)
- {
- pReplyPkg->SetErrMsg(Error_Param, 0, "get struct [RollbakR] fail");
- SendPackage(pReplyPkg);
- return Error_Param;
- }
- assert(nLen == sizeof(RvcRollbackReq));
- RvcRollbackReq req = {};
- int nArrayLen(0);
- pRecvPkg->GetStructData("RollbakR", (BYTE*)&req, &nLen, &nArrayLen);
- RvcRollbackRet ret = {};
- ret.TaskID = req.TaskID;
- pReplyPkg->AddStruct("RollbakA", false, false, (BYTE*)&ret, sizeof(ret));
- // 调用升级实体接口回滚
- UpgradeMgrService_ClientBase *pClient = new UpgradeMgrService_ClientBase(m_pEntity);
- auto rc = pClient->Connect();
- if (rc == Error_Succeed)
- {
- UpgradeMgrService_RollbackUpdate_Req req = {};
- UpgradeMgrService_RollbackUpdate_Ans ans = {};
- rc = (*pClient)(EntityResource::getLink().upgradeLink())->RollbackUpdate(req, ans, 10000);
- pClient->GetFunction()->CloseSession();
- } else {
- pClient->SafeDelete();
- }
- if (rc != Error_Succeed)
- {
- pReplyPkg->SetErrMsg(rc, 0, SP::Utility::UTF8ToGBK("调用升级实体回滚升级失败").c_str());
- LogError(Severity_Low, rc, 0, "调用升级实体回滚升级失败");
- }
- else
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleRollbackUpgradeReq")("remote rollback upgrade succeed!");
- }
-
- SendPackage(pReplyPkg);
- return Error_Succeed;
- }
- ErrorCodeEnum CRemoteControllerCnn::HandleGetCurMaintainerReq(const CSmartPointer<IPackage> &pRecvPkg)
- {
- /*
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleGetCurMaintainerReq")("request get maintainer info");
-
- auto pReplyPkg = CreateReplyPackage(pRecvPkg);
- int nLen = pRecvPkg->GetStructLen("GetUserR");
- if (nLen <=0)
- {
- pReplyPkg->SetErrMsg(Error_Param, 0, "get struct [GetUserR] fail");
- SendPackage(pReplyPkg);
- return Error_Param;
- }
- assert(nLen == sizeof(RvcGetUserReq));
- RvcGetUserReq req = {};
- int nArrayLen(0);
- pRecvPkg->GetStructData("GetUserR", (BYTE*)&req, &nLen, &nArrayLen);
- RvcGetUserRet ret = {};
- ret.TaskID = req.TaskID;
- // 调用本地维护实体取控制信息
- GUIConsoleService_GetCurrentMaintainer_Req req1 = {};
- GUIConsoleService_GetCurrentMaintainer_Ans ans1 = {};
-
- GUIConsoleService_ClientBase *pClient = new GUIConsoleService_ClientBase(m_pEntity);
- auto rc = pClient->Connect();
- if (rc == Error_Succeed)
- {
- rc = (*pClient)(EntityResource::getLink().upgradeLink())->GetCurrentMaintainer(req1, ans1, 10000);
- pClient->GetFunction()->CloseSession();
- } else {
- pClient->SafeDelete();
- }
- if (rc != Error_Succeed)
- {
- pReplyPkg->SetErrMsg(rc, 0, SP::Utility::UTF8ToGBK("调用[GuiConsole]实体失败").c_str());
- LogError(Severity_Low, rc, 0, "调用[GuiConsole]实体失败");
- }
- else
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleGetCurMaintainerReq")("获取运维人员信息成功");
- strncpy_s(ret.UserID, sizeof(ret.UserID), ans1.strUserID, _TRUNCATE);
- strncpy_s(ret.UserName, sizeof(ret.UserName), ans1.strUserName, _TRUNCATE);
- strncpy_s(ret.CurRight, sizeof(ret.CurRight), ans1.strCurRight, _TRUNCATE);
- strncpy_s(ret.Authorizer, sizeof(ret.Authorizer), ans1.strAuthorizer, _TRUNCATE);
- ret.BeginTime = ans1.dwBeginTime;
- pReplyPkg->AddStruct("GetUserA", false, false, (BYTE*)&ret, sizeof(ret));
- }
-
- SendPackage(pReplyPkg);
- */
- return Error_Succeed;
- }
- ErrorCodeEnum CRemoteControllerCnn::HandleEnpowerMaintainerReq(const CSmartPointer<IPackage> &pRecvPkg)
- {
- /*
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleEnpowerMaintainerReq")("request enpower maintainer");
-
- auto pReplyPkg = CreateReplyPackage(pRecvPkg);
- int nLen = pRecvPkg->GetStructLen("EnpowerR");
- if (nLen <=0)
- {
- pReplyPkg->SetErrMsg(Error_Param, 0, "get struct [EnpowerR] fail");
- SendPackage(pReplyPkg);
- return Error_Param;
- }
- assert(nLen == sizeof(RvcEnpowerUserReq));
- RvcEnpowerUserReq req = {};
- int nArrayLen(0);
- pRecvPkg->GetStructData("EnpowerR", (BYTE*)&req, &nLen, &nArrayLen);
- RvcEnpowerUserRet ret = {};
- ret.TaskID = req.TaskID;
- // 调用本地维护实体取控制信息
- GUIConsoleService_Empower_Req req1 = {};
- GUIConsoleService_Empower_Ans ans1 = {};
-
- GUIConsoleService_ClientBase *pClient = new GUIConsoleService_ClientBase(m_pEntity);
- auto rc = pClient->Connect();
- if (rc == Error_Succeed)
- {
- req1.strUserID = req.UserID;
- rc = (*pClient)(EntityResource::getLink().upgradeLink())->Empower(req1, ans1, 10000);
- pClient->GetFunction()->CloseSession();
- } else {
- pClient->SafeDelete();
- }
- if (rc != Error_Succeed)
- {
- pReplyPkg->SetErrMsg(rc, 0, SP::Utility::UTF8ToGBK("调用[GuiConsole]实体失败").c_str());
- LogError(Severity_Low, rc, 0, "调用[GuiConsole]实体失败");
- }
- else
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleEnpowerMaintainerReq")("远程维护授权成功");
- pReplyPkg->AddStruct("EnpowerA", false, false, (BYTE*)&ret, sizeof(ret));
- }
-
- SendPackage(pReplyPkg);
- */
- return Error_Succeed;
- }
- ErrorCodeEnum CRemoteControllerCnn::HandleTakeoverPowerReq(const CSmartPointer<IPackage> &pRecvPkg)
- {
- /*
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleTakeoverPowerReq")("request takeover maintainer power");
-
- auto pReplyPkg = CreateReplyPackage(pRecvPkg);
- int nLen = pRecvPkg->GetStructLen("TakeovrR");
- if (nLen <=0)
- {
- pReplyPkg->SetErrMsg(Error_Param, 0, "get struct [TakeovrR] fail");
- SendPackage(pReplyPkg);
- return Error_Param;
- }
- assert(nLen == sizeof(RvcTakeoverPowerReq));
- RvcTakeoverPowerReq req = {};
- int nArrayLen(0);
- pRecvPkg->GetStructData("TakeovrR", (BYTE*)&req, &nLen, &nArrayLen);
- RvcTakeoverPowerRet ret = {};
- ret.TaskID = req.TaskID;
- // 调用本地维护实体取控制信息
- GUIConsoleService_Takeover_Req req1 = {};
- GUIConsoleService_Takeover_Ans ans1 = {};
-
- GUIConsoleService_ClientBase *pClient = new GUIConsoleService_ClientBase(m_pEntity);
- auto rc = pClient->Connect();
- if (rc == Error_Succeed)
- {
- req1.strUserID = req.UserID;
- rc = (*pClient)(EntityResource::getLink().upgradeLink())->Takeover(req1, ans1, 10000);
- pClient->GetFunction()->CloseSession();
- } else {
- pClient->SafeDelete();
- }
- if (rc != Error_Succeed)
- {
- pReplyPkg->SetErrMsg(rc, 0, SP::Utility::UTF8ToGBK("调用[GuiConsole]实体失败").c_str());
- LogError(Severity_Low, rc, 0, "调用[GuiConsole]实体失败");
- }
- else
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleTakeoverPowerReq")("远程解除高级维护权限成功");
- pReplyPkg->AddStruct("TakeovrA", false, false, (BYTE*)&ret, sizeof(ret));
- }
-
- SendPackage(pReplyPkg);
- */
- return Error_Succeed;
- }
- ErrorCodeEnum CRemoteControllerCnn::HandleForceQuitMaintainReq(const CSmartPointer<IPackage> &pRecvPkg)
- {
- /*
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleForceQuitMaintainReq")("request force quit maintain");
-
- auto pReplyPkg = CreateReplyPackage(pRecvPkg);
- int nLen = pRecvPkg->GetStructLen("ForceQtR");
- if (nLen <=0)
- {
- pReplyPkg->SetErrMsg(Error_Param, 0, "get struct [ForceQtR] fail");
- SendPackage(pReplyPkg);
- return Error_Param;
- }
- assert(nLen == sizeof(RvcForceQuitReq));
- RvcForceQuitReq req = {};
- int nArrayLen(0);
- pRecvPkg->GetStructData("ForceQtR", (BYTE*)&req, &nLen, &nArrayLen);
- RvcForceQuitRet ret = {};
- ret.TaskID = req.TaskID;
- // 调用本地维护实体
- GUIConsoleService_ForceQuit_Req req1 = {};
- GUIConsoleService_ForceQuit_Ans ans1 = {};
-
- GUIConsoleService_ClientBase *pClient = new GUIConsoleService_ClientBase(m_pEntity);
- auto rc = pClient->Connect();
- if (rc == Error_Succeed)
- {
- rc = (*pClient)(EntityResource::getLink().upgradeLink())->ForceQuit(req1, ans1, 10000);
- pClient->GetFunction()->CloseSession();
- } else {
- pClient->SafeDelete();
- }
- if (rc != Error_Succeed)
- {
- pReplyPkg->SetErrMsg(rc, 0, SP::Utility::UTF8ToGBK("调用[GuiConsole]实体失败").c_str());
- LogError(Severity_Low, rc, 0, "调用[GuiConsole]实体失败");
- }
- else
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleForceQuitMaintainReq")("远程强制退出维护状态成功");
- pReplyPkg->AddStruct("ForceQtA", false, false, (BYTE*)&ret, sizeof(ret));
- }
-
- SendPackage(pReplyPkg);
- */
- return Error_Succeed;
- }
- ErrorCodeEnum CRemoteControllerCnn::EnterMonitorMode()
- {
- m_chRemoteMode = 'O';
- m_pFSM->PostEventFIFO(new FSMEvent(CRemoteControllerFSM::Event_EnterMonitor));
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("EnterMonitorMode")("enter monitor mode succeed");
- return Error_Succeed;
- }
- ErrorCodeEnum CRemoteControllerCnn::EnterMaintainMode(bool bLocalMaintain)
- {
- // 是否远程维护
- if (bLocalMaintain)
- {
- // 弹出本地控制台
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("EnterMaintainMode")
- ("show local maintain console");
- }
- else
- {
- // 远程维护 显示维护图片 遮挡前端操作界面
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("EnterMaintainMode")
- ("show remote maintain picture");
- }
- m_chRemoteMode = bLocalMaintain ? 'L' : 'R';
- m_pFSM->PostEventFIFO(new FSMEvent(CRemoteControllerFSM::Event_EnterMaintain));
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("EnterMaintainMode")
- ("enter maintain mode succeed");
- return Error_Succeed;
- }
- ErrorCodeEnum CRemoteControllerCnn::EnterTerminalMode(int nRemotePort)
- {
- // 检测本机远程桌面是否打开
- // 检测远程用户是否创建
- // 连接分行桥接服务端口
- // 重定向此连接至3389端口
- m_chRemoteMode = 'T';
- m_pFSM->PostEventFIFO(new FSMEvent(CRemoteControllerFSM::Event_EnterTerminal));
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("EnterTerminalMode")("enter terminal mode succeed");
- return Error_Succeed;
- }
- ErrorCodeEnum CRemoteControllerCnn::HandleGetVersionReq(const CSmartPointer<IPackage> &pRecvPkg)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleGetVersionReq")("request get active version");
- auto pReplyPkg = CreateReplyPackage(pRecvPkg);
- int nLen = pRecvPkg->GetStructLen("GetVerR");
- if (nLen <= 0)
- {
- pReplyPkg->SetErrMsg(Error_Param, 0, "get struct [GetVerR] fail");
- SendPackage(pReplyPkg);
- return Error_Param;
- }
- assert(nLen == sizeof(RvcGetActiveVerReq));
- RvcGetActiveVerReq req = {};
- int nArrayLen(0);
- pRecvPkg->GetStructData("GetVerR", (BYTE*)&req, &nLen, &nArrayLen);
- RvcGetActiveVerRet ret = {};
- ret.TaskID = req.TaskID;
- CSimpleStringA strPath;
- auto rc = m_pEntity->GetFunction()->GetPath("RootVer", strPath);
- if (rc == Error_Succeed)
- {
- strPath.Append(SPLIT_SLASH_STR).Append("active.txt");
- FILE *pFile = fopen(strPath, "r");
- if (pFile != NULL)
- {
- char szTemp[256] = {};
- int n = fread(szTemp, 1, 256, pFile);
-
- strncpy_s(ret.Version, sizeof(ret.Version), szTemp, _TRUNCATE);
- fclose(pFile);
- pReplyPkg->AddStruct("GetVerA", false, false, (BYTE*)&ret, sizeof(ret));
- }
- else
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleGetVersionReq")("open active.txt fail");
- pReplyPkg->SetErrMsg(Error_NotExist, 0, "open active.txt fail");
- }
- }
- else
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleGetVersionReq")("get root ver path fail");
- pReplyPkg->SetErrMsg(Error_Unexpect, 0, "get root ver path fail");
- }
- SendPackage(pReplyPkg);
- return Error_Succeed;
- }
- ErrorCodeEnum CRemoteControllerCnn::HandleViewRunCfgReq(const CSmartPointer<IPackage> &pRecvPkg)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleViewRunCfgReq")("remote view runcfg");
- auto pReplyPkg = CreateReplyPackage(pRecvPkg);
- int nLen = pRecvPkg->GetStructLen("VRunCfgR");
- if (nLen <= 0)
- {
- pReplyPkg->SetErrMsg(Error_Param, 0, "get struct [VRunCfgR] fail");
- SendPackage(pReplyPkg);
- return Error_Param;
- }
- assert(nLen == sizeof(RvcViewRunCfgReq));
- RvcViewRunCfgReq req = {};
- int nArrayLen(0);
- pRecvPkg->GetStructData("VRunCfgR", (BYTE*)&req, &nLen, &nArrayLen);
- // 读取实体配置文件
- CSimpleStringA strConfigName = req.ConfigName;
- CSimpleStringA strCfgPath;
- if (Error_Succeed != m_pEntity->GetFunction()->GetPath("RunInfo", strCfgPath)) {
- Dbg("Get RunInfo path failed");
- pReplyPkg->SetErrMsg(Error_NotExist, 0, SP::Utility::UTF8ToGBK("配置不存在").c_str());
- SendPackage(pReplyPkg);
- return Error_NotExist;
- }
- strCfgPath.Append(SPLIT_SLASH_STR).Append("runcfg").Append(SPLIT_SLASH_STR).Append(strConfigName);
- if (!Base_Exist(strCfgPath.GetData()))
- {
- Dbg("runcfg [%s] not exist", (const char*)strCfgPath);
- pReplyPkg->SetErrMsg(Error_NotExist, 0, SP::Utility::UTF8ToGBK("配置不存在").c_str());
- SendPackage(pReplyPkg);
- return Error_NotExist;
- }
- auto cfgSize = Base_filesize(strCfgPath.GetData());
- char* tmpBuf = new char[cfgSize];
- memset(tmpBuf, 0, cfgSize);
- auto readRet = Base_readFile(strCfgPath.GetData(), 0, tmpBuf, cfgSize);
- if (!readRet.first)
- {
- pReplyPkg->SetErrMsg(0, 0, "open runcfg fail");
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleViewRunCfgReq")("open file [%s] fail", (const char*)strCfgPath);
- }
- else
- {
- int nRetLen = sizeof(RvcViewRunCfgRet) + cfgSize * 2;
- char* pBuf = new char[nRetLen];
- memset(pBuf, 0, nRetLen);
- RvcViewRunCfgRet* pRet = (RvcViewRunCfgRet*)pBuf;
- int dstPos = 0;
- for (auto i = 0; i < cfgSize; i++)
- {
- if ((i == 0 && tmpBuf[i] == '\n') || (tmpBuf[i] == '\n' && tmpBuf[i - 1] != '\r'))
- pRet->ConfigData[dstPos++] = '\r';
- pRet->ConfigData[dstPos++] = tmpBuf[i];
- }
- pReplyPkg->AddStruct("VRunCfgA", false, false, (BYTE*)pBuf, dstPos + sizeof(RvcViewConfigRet));
- delete[] pBuf;
- }
- delete[] tmpBuf;
- SendPackage(pReplyPkg);
- return Error_Succeed;
- }
- ErrorCodeEnum CRemoteControllerCnn::HandleViewInstallLogReq(const CSmartPointer<IPackage> &pRecvPkg)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleViewInstallLogReq")("remote view install log");
- auto pReplyPkg = CreateReplyPackage(pRecvPkg);
- int nLen = pRecvPkg->GetStructLen("VPkgLogR");
- if (nLen <= 0)
- {
- pReplyPkg->SetErrMsg(Error_Param, 0, "get struct [VPkgLogR] fail");
- SendPackage(pReplyPkg);
- return Error_Param;
- }
- assert(nLen == sizeof(RvcViewInstallLogReq));
- RvcViewInstallLogReq req = {};
- int nArrayLen(0);
- pRecvPkg->GetStructData("VPkgLogR", (BYTE*)&req, &nLen, &nArrayLen);
- CSimpleStringA strEntityName = req.InstallLog;
- // 读取升级日志文件
- CSimpleStringA strLogFile = req.InstallLog;
- CSimpleStringA strLogPath;
- auto rc = m_pEntity->GetFunction()->GetPath("RunInfo", strLogPath);
- assert(rc == Error_Succeed);
- strLogPath.Append(SPLIT_SLASH_STR).Append("InstallLog").Append(SPLIT_SLASH_STR).Append((const char*)strLogFile);
- if (!Base_Exist(strLogPath.GetData()))
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleViewInstallLogReq")("install log [%s] not exist", (const char*)strLogPath);
- pReplyPkg->SetErrMsg(Error_NotExist, 0, SP::Utility::UTF8ToGBK("日志文件不存在").c_str());
- SendPackage(pReplyPkg);
- return Error_NotExist;
- }
-
- auto file = fopen(strLogPath, "rb");
- if (file == NULL)
- {
- auto nError = errno;
- pReplyPkg->SetErrMsg(Error_NotExist, 0, CSimpleStringA::Format("open install log [%s] fail(%d)", (const char*)strLogPath, nError));
- LogError(Severity_Low, Error_NotExist, 0, CSimpleStringA::Format("open install log [%s] fail(%d)", (const char*)strLogPath, nError));
- SendPackage(pReplyPkg);
- return rc;
- }
- generateFilesize(file, strLogPath);
- long long nRetLen = sizeof(RvcViewInstallLogRet)+nFileSize;
- char *pBuf = new char[nRetLen];
- memset(pBuf, 0, nRetLen);
- RvcViewInstallLogRet *pRet = (RvcViewInstallLogRet*)pBuf;
- pRet->TaskID = req.TaskID;
- char *pLogData = (char*)pRet->LogData;
- long long nHasRead(0);
- DWORD nReadLen(0);
- do
- {
- nReadLen = fread(pLogData + nHasRead, 1, nFileSize - nHasRead, file);
-
- if (nReadLen >0)
- nHasRead += nReadLen;
- } while (nReadLen >0 && nHasRead < nFileSize);
- fclose(file);
- std::string gbkLogStr = SP::Utility::UTF8ToGBK(pLogData);
- int gbkLen = sizeof(RvcViewInstallLogRet) + gbkLogStr.length();
- char* gbkBuf = new char[gbkLen];
- memset(gbkBuf, 0, gbkLen);
- RvcViewInstallLogRet* gbkRet = (RvcViewInstallLogRet*)gbkBuf;
- gbkRet->TaskID = req.TaskID;
- memcpy(gbkRet->LogData, gbkLogStr.c_str(), gbkLogStr.length());
- pReplyPkg->AddStruct("VPkgLogA", false, false, (BYTE*)gbkRet, gbkLen);
- delete[] pBuf;
- delete[] gbkBuf;
- SendPackage(pReplyPkg);
- return Error_Succeed;
- }
- ErrorCodeEnum CRemoteControllerCnn::ZipFile(LPCTSTR lpszZipArchive, LPCTSTR lpszSrcFile)
- {
- BOOL bResult = TRUE;
- assert(lpszZipArchive);
- assert(lpszZipArchive[0] != ('\0'));
- if (!lpszZipArchive || lpszZipArchive[0] == ('\0'))
- return Error_Param;
- assert(lpszSrcFile);
- assert(lpszSrcFile[0] != ('\0'));
- if (!lpszSrcFile || lpszSrcFile[0] == ('\0'))
- return Error_Param;
- // does zip source file exist?
- if (!Base_Exist(lpszSrcFile))
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("ZipFile")("source file '%s' cannot be found", lpszSrcFile);
- return Error_NotExist;
- }
- // does zip file exist?
- if (Base_Exist(lpszZipArchive))
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("ZipFile")("dest zip file '%s' exists, delete it!", lpszZipArchive);
- Base_DeleteFile(lpszZipArchive);
- }
- // 先拷贝源文件(防止文件被占用导致压缩失败)
- CSimpleStringA strCopyFile = lpszSrcFile;
- strCopyFile += ".bak";
- Base_CopyFile(lpszSrcFile, strCopyFile.GetData());
- // use only the file name for zip file entry
- TCHAR * cp = (TCHAR *)strrchr(lpszSrcFile, SPLIT_SLASH);
- if (cp == NULL)
- cp = (TCHAR *)lpszSrcFile;
- else
- cp++;
- #if (defined _WIN32 || defined _WIN64)
- HZIP hz = CreateZip((void *)lpszZipArchive, 0, ZIP_FILENAME);
- #else
- zipFile hz = zipOpen(lpszZipArchive, APPEND_STATUS_CREATE); //创建zip文件
- #endif
- if (hz)
- {
- #if (defined _WIN32 || defined _WIN64)
- ZRESULT zr = ZipAdd(hz, cp, (void *)(const char*)strCopyFile, 0, ZIP_FILENAME);
- CloseZip(hz);
- if (zr == ZR_OK)
- #else
- auto zr = AddFileToZip(hz, cp, strCopyFile.GetData());
- zipClose(hz, NULL);
- if (zr)
- #endif
-
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("ZipFile")("added '%s' to zip file '%s' succeed", lpszSrcFile, lpszZipArchive);
- bResult = TRUE;
- }
- else
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("ZipFile")("failed to add zip source file '%s'", lpszSrcFile);
- bResult = FALSE;
- }
- }
- else
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("ZipFile")("failed to create zip file '%s'", lpszZipArchive);
- bResult = FALSE;
- }
- if (Base_Exist(strCopyFile.GetData()))
- Base_DeleteFile(strCopyFile.GetData());
- if (!bResult && Base_Exist(lpszZipArchive))
- Base_DeleteFile(lpszZipArchive);
- return bResult ? Error_Succeed : Error_Unexpect;
- }
- ErrorCodeEnum CRemoteControllerCnn::BatchZipFiles(LPCTSTR lpszZipArchive, const list<string> &listSrcFiles)
- {
- BOOL bResult = TRUE;
- if (!lpszZipArchive || lpszZipArchive[0] == ('\0'))
- return Error_Param;
- // does zip file exist?
- if (Base_Exist(lpszZipArchive))
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("BatchZipFiles")("dest zip file '%s' exists, delete it!", lpszZipArchive);
- Base_DeleteFile(lpszZipArchive);
- }
- #if (defined _WIN32 || defined _WIN64)
- HZIP hz = CreateZip((void*)lpszZipArchive, 0, ZIP_FILENAME);
- #else
- zipFile hz = zipOpen(lpszZipArchive, APPEND_STATUS_CREATE); //创建zip文件
- #endif
- if (!hz)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("BatchZipFiles")("failed to create zip file '%s'", lpszZipArchive);
- return Error_Unexpect;
- }
-
- // does zip source file exist?
- for (auto it = listSrcFiles.begin(); it != listSrcFiles.end(); it++)
- {
- if (!Base_Exist(it->c_str()))
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("BatchZipFiles")("source file '%s' cannot be found", it->c_str());
- bResult = FALSE;
- break;
- }
- // 先拷贝源文件(防止文件被占用导致压缩失败)
- CSimpleStringA strSrcFile = it->c_str();
- CSimpleStringA strCopyFile = strSrcFile;
- strCopyFile += ".bak";
- Base_CopyFile(strSrcFile.GetData(), strCopyFile.GetData());
- // use only the file name for zip file entry
- CSimpleStringA strTmp = strSrcFile;
- const TCHAR * cp = strrchr(strTmp, SPLIT_SLASH);
- if (cp != NULL)
- {
- *((char*)cp) = '_';
- cp = (TCHAR *)strrchr(strTmp, SPLIT_SLASH);
- }
- if (cp != NULL)
- cp++;
- else
- cp = strTmp;
- #if (defined _WIN32 || defined _WIN64)
- ZRESULT zr = ZipAdd(hz, cp, (void*)(const char*)strCopyFile, 0, ZIP_FILENAME);
- CloseZip(hz);
- #else
- auto zr = AddFileToZip(hz, cp, strCopyFile.GetData());
- #endif
- // delete .bak file
- if (Base_Exist(strCopyFile.GetData()))
- Base_DeleteFile(strCopyFile.GetData());
- // did add work?
- #if (defined _WIN32 || defined _WIN64)
- if (zr == ZR_OK)
- #else
- if(zr)
- #endif
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("BatchZipFiles")("added '%s' to zip file '%s' succeed", cp, lpszZipArchive);
- }
- else
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("BatchZipFiles")("failed to add zip source file '%s'", cp);
- bResult = FALSE;
-
- break;
- }
- }
- if (!bResult && Base_Exist(lpszZipArchive))
- {
- Base_DeleteFile(lpszZipArchive);
- }
- #if (defined _WIN32 || defined _WIN64)
- if (hz)
- CloseZip(hz);
- #else
- zipClose(hz, NULL);
- #endif
- return bResult ? Error_Succeed : Error_Unexpect;
- }
- ErrorCodeEnum CRemoteControllerCnn::HandleUploadLogByDateReq(const CSmartPointer<IPackage> &pRecvPkg)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleUploadLogByDateReq")("remote upload log");
- auto pReplyPkg = CreateReplyPackage(pRecvPkg);
- int nLen = pRecvPkg->GetStructLen("ULogBDR");
- if (nLen <= 0)
- {
- pReplyPkg->SetErrMsg(Error_Param, 0, "get struct [ULogBDR] fail");
- SendPackage(pReplyPkg);
- return Error_Param;
- }
- assert(nLen == sizeof(RvcUploadLogByDateReq));
- RvcUploadLogByDateReq req = {};
- int nArrayLen(0);
- pRecvPkg->GetStructData("ULogBDR", (BYTE*)&req, &nLen, &nArrayLen);
- auto pFunc = m_pEntity->GetFunction();
- CSimpleStringA strZipFileName;
- CSimpleStringA strLogPath;
- CSimpleStringA strZipPath;
- if (req.StartPos <= 0)
- {
- auto strTodayLogName = 0 == strlen(req.ViewDate) ? CSimpleStringA(getCurData().c_str()) : CSimpleStringA(req.ViewDate);
- CSystemStaticInfo sysInfo;
- auto rc = pFunc->GetSystemStaticInfo(sysInfo);
- assert(rc == Error_Succeed);
- CSimpleStringA strReqLogName = req.UploadFile;
-
- // 第一次上传,需生成对应ZIP文件
- if (strReqLogName.Compare("Silverlight", true) == 0) // slv日志
- {
- strZipFileName = CSimpleStringA::Format("%s_slv_%s.zip", (const char*)sysInfo.strTerminalID, (const char*)strTodayLogName);
-
- pFunc->GetPath("Slv", strLogPath);
- strLogPath.Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
- }
- else if (strReqLogName.IsEndWith(".zip", true)) // 安装包日志
- {
- strZipFileName = CSimpleStringA::Format("%s_pkg_%s", (const char*)sysInfo.strTerminalID, (const char*)strReqLogName);
- pFunc->GetPath("RunInfo", strLogPath);
- strLogPath.Append(SPLIT_SLASH_STR).Append("InstallLog").Append(SPLIT_SLASH_STR).Append((const char*)strReqLogName).Append(".log");
- }
- else
- {
- // 实体Dbg日志
- strZipFileName = CSimpleStringA::Format("%s_dbg_%s_%s.zip",
- (const char*)sysInfo.strTerminalID, (const char*)strReqLogName, (const char*)strTodayLogName);
- pFunc->GetPath("Dbg", strLogPath);
- if (strReqLogName.Compare("Shell", true) == 0)
- strLogPath.Append(SPLIT_SLASH_STR).Append("SpShell").Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
- else if (strReqLogName.Compare("DualActive", true) == 0)
- strLogPath.Append(SPLIT_SLASH_STR).Append("DualActive").Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
- else if (strReqLogName.Compare("guardian", true) == 0)
- strLogPath.Append(SPLIT_SLASH_STR).Append("guardian").Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
- else if (strReqLogName.Compare("SpHost", true) == 0)
- strLogPath.Append(SPLIT_SLASH_STR).Append("SpHost").Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
- else if (strReqLogName.Compare("SysInit", true) == 0)
- strLogPath.Append(SPLIT_SLASH_STR).Append("SysInit").Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
- else if (strReqLogName.Compare("SpBase", true) == 0)
- strLogPath.Append(SPLIT_SLASH_STR).Append("SpBase").Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
- else
- {
- CEntityStaticInfo info = {};
- auto nRet = pFunc->GetEntityStaticInfo(strReqLogName, info);
- if (nRet != Error_Succeed)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleUploadLogByDateReq")("entity [%s] not exist", (const char*)strReqLogName);
- pReplyPkg->SetErrMsg(Error_NotExist, 0, SP::Utility::UTF8ToGBK(CSimpleStringA::Format("实体[%s]不存在", (const char*)strReqLogName).GetData()).c_str());
- SendPackage(pReplyPkg);
- return Error_NotExist;
- }
- strLogPath.Append(SPLIT_SLASH_STR).Append((const char*)info.strSpFileName).Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
- }
- }
- pFunc->GetPath("Temp", strZipPath);
- strZipPath.Append(SPLIT_SLASH_STR).Append(strZipFileName);
-
- if (!Base_Exist(strLogPath.GetData()))
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleUploadLogByDateReq")("log [%s] not exist", (const char*)strLogPath);
- pReplyPkg->SetErrMsg(Error_NotExist, 0, SP::Utility::UTF8ToGBK(CSimpleStringA::Format("日志文件[%s]不存在", (const char*)strLogPath).GetData()).c_str());
- SendPackage(pReplyPkg);
- return Error_NotExist;
- }
- // 生成ZIP
- rc = ZipFile(strZipPath, strLogPath);
- if (rc != Error_Succeed)
- {
- pReplyPkg->SetErrMsg(rc, 0, SP::Utility::UTF8ToGBK(CSimpleStringA::Format("生成压缩文件[%s]失败", (const char*)strZipFileName).GetData()).c_str());
- SendPackage(pReplyPkg);
- return rc;
- }
- }
- else
- {
- strZipFileName = req.UploadFile;
-
- pFunc->GetPath("Temp", strZipPath);
- strZipPath.Append(SPLIT_SLASH_STR).Append(strZipFileName);
- }
-
- if (!Base_Exist(strZipPath.GetData()))
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleUploadLogByDateReq")("zip log [%s] not exist", (const char*)strZipPath);
- pReplyPkg->SetErrMsg(Error_NotExist, 0, SP::Utility::UTF8ToGBK(CSimpleStringA::Format("日志压缩文件[%s]不存在", (const char*)strZipPath).GetData()).c_str());
- SendPackage(pReplyPkg);
- return Error_NotExist;
- }
- // 开始上传
- long long nStartPos = req.StartPos;
- if (nStartPos <0)
- nStartPos = 0;
- long long nMaxBytes = req.MaxRetBytes;
- if (nMaxBytes <= 0)
- nMaxBytes = 32 * 1024;
- auto file = fopen(strZipPath, "rb");
- if (file == NULL)
- {
- auto nError = errno;
- pReplyPkg->SetErrMsg(Error_Unexpect, 0, SP::Utility::UTF8ToGBK(CSimpleStringA::Format("读取日志文件[%s]失败(%d)", (const char*)strZipFileName, nError).GetData()).c_str());
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleUploadLogByDateReq")(CSimpleStringA::Format("open debug log [%s] fail(%d)", (const char*)strZipPath, nError));
- SendPackage(pReplyPkg);
- return Error_Unexpect;
- }
- generateFilesize(file, strZipPath);
-
- if (nStartPos >0 && nStartPos < nFileSize)
- {
- _fseeki64(file, nStartPos, SEEK_SET);
- }
- else
- nStartPos = 0;
- long long nNextPos = nStartPos + nMaxBytes;
- if (nMaxBytes + nStartPos > nFileSize)
- {
- nMaxBytes = nFileSize - nStartPos;
- nNextPos = 0;
- }
- long long nRetLen = sizeof(RvcUploadLogByDateRet)+nMaxBytes;
- char *pBuf = new char[nRetLen];
- memset(pBuf, 0, nRetLen);
- RvcUploadLogByDateRet *pRet = (RvcUploadLogByDateRet*)pBuf;
- pRet->TaskID = req.TaskID;
- strncpy_s(pRet->UploadFile, sizeof(pRet->UploadFile), strZipFileName, _TRUNCATE);
- pRet->ZipFileLen = nFileSize;
- pRet->StartPos = req.StartPos;
- pRet->NextPos = nNextPos;
- char *pLogData = (char*)pRet->LogData;
- long long nHasRead(0);
- DWORD nReadLen(0);
- do
- {
- //Dbg("ftell: %d", ftell(file));
- nReadLen = fread(pLogData + nHasRead, 1, nMaxBytes - nHasRead, file);
- //Dbg("ftell: %d", ftell(file));
- if (nReadLen >0)
- nHasRead += nReadLen;
- } while (nReadLen >0 && nHasRead < nMaxBytes);
- fclose(file);
- if (nHasRead < nMaxBytes)
- {
- delete[] pBuf;
- auto nError = GetLastError();
- pReplyPkg->SetErrMsg(Error_NotExist, 0, SP::Utility::UTF8ToGBK(CSimpleStringA::Format("读取文件[%s]失败(%d)", (const char*)strZipFileName, nError).GetData()).c_str());
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleUploadLogByDateReq")(CSimpleStringA::Format("read log [%s] fail(%d)", (const char*)strZipPath, nError));
- SendPackage(pReplyPkg);
- return Error_Unexpect;
- }
- pReplyPkg->AddStruct("ULogBDA", false, false, (BYTE*)pBuf, nRetLen);
- delete[] pBuf;
- SendPackage(pReplyPkg);
- if (nNextPos <= 0)
- {
- // 删除压缩文件
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleUploadLogByDateReq")("finish upload log zip '%s', delete it!", (const char*)strZipFileName);
- Base_DeleteFile(strZipPath.GetData());
- }
- return Error_Succeed;
- }
- ErrorCodeEnum CRemoteControllerCnn::HandleUploadLogReq(const CSmartPointer<IPackage> &pRecvPkg)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleUploadLogReq")("remote upload log");
- auto pReplyPkg = CreateReplyPackage(pRecvPkg);
- int nLen = pRecvPkg->GetStructLen("UpldLogR");
- if (nLen <= 0)
- {
- pReplyPkg->SetErrMsg(Error_Param, 0, "get struct [UpldLogR] fail");
- SendPackage(pReplyPkg);
- return Error_Param;
- }
- assert(nLen == sizeof(RvcUploadLogReq));
- RvcUploadLogReq req = {};
- int nArrayLen(0);
- pRecvPkg->GetStructData("UpldLogR", (BYTE*)&req, &nLen, &nArrayLen);
- auto pFunc = m_pEntity->GetFunction();
- CSimpleStringA strZipFileName;
- CSimpleStringA strLogPath;
- CSimpleStringA strZipPath;
- if (req.StartPos <= 0)
- {
- auto strTodayLogName = getCurData().c_str();
- CSystemStaticInfo sysInfo;
- auto rc = pFunc->GetSystemStaticInfo(sysInfo);
- assert(rc == Error_Succeed);
- CSimpleStringA strReqLogName = req.UploadFile;
-
- // 第一次上传,需生成对应ZIP文件
- if (strReqLogName.Compare("Silverlight", true) == 0) // slv日志
- {
- strZipFileName = CSimpleStringA::Format("%s_slv_%s.zip", (const char*)sysInfo.strTerminalID, (const char*)strTodayLogName);
-
- pFunc->GetPath("Slv", strLogPath);
- strLogPath.Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
-
- }
- else if (strReqLogName.Compare("AllDbg", true) == 0)
- {
- strZipFileName = CSimpleStringA::Format("%s_AllDbg_%s.zip", (const char*)sysInfo.strTerminalID, (const char*)strTodayLogName);
- pFunc->GetPath("Dbg", strLogPath);
- pFunc->GetPath("Temp", strZipPath);
- strZipPath.Append(SPLIT_SLASH_STR).Append((const char*)strZipFileName);
- try
- {
- std::pair<bool, std::string> result = MyZip::ZipDir(strZipPath.GetData(), strLogPath.GetData());
- if (result.first)
- goto BeginUpload;
- else
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleUploadLogReq")("%s zip failed", strZipFileName);
- pReplyPkg->SetErrMsg(Error_NotExist, 0, CSimpleStringA::Format("%s zip failed", strZipFileName));
- SendPackage(pReplyPkg);
- return Error_NotExist;
- }
- }
- catch (exception &e)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleUploadLogReq")("error:%s", e.what());
- }
- }
- else if (strReqLogName.Compare("RunInfomation", true) == 0)
- {
- strZipFileName = CSimpleStringA::Format("%s_runInformation_%s.zip", (const char*)sysInfo.strTerminalID, (const char*)strTodayLogName);
- pFunc->GetPath("Temp", strZipPath);
- strZipPath.Append(SPLIT_SLASH_STR).Append((const char*)strZipFileName);
- vector<std::string> zipArr;
- pFunc->GetPath("RunInfo", strLogPath);
- zipArr.push_back(strLogPath.GetData());
- pFunc->GetPath("HardwareCfg", strLogPath);
- strLogPath.Append(SPLIT_SLASH_STR).Append("root.ini");
- zipArr.push_back(strLogPath.GetData());
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleUploadLogReq")("%s,%s,%s", zipArr[0].c_str(), zipArr[1].c_str(), strZipPath);
- std::pair<bool, std::string> result = MyZip::ZipVector(strZipPath.GetData(), zipArr);
- if (result.first)
- goto BeginUpload;
- else
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleUploadLogReq")("%s zip failed", strZipFileName);
- pReplyPkg->SetErrMsg(Error_NotExist, 0, CSimpleStringA::Format("%s zip failed", strZipFileName));
- SendPackage(pReplyPkg);
- return Error_NotExist;
- }
- }
- else if (strReqLogName.IsEndWith(".zip", true)) // 安装包日志
- {
- strZipFileName = CSimpleStringA::Format("%s_pkg_%s", (const char*)sysInfo.strTerminalID, (const char*)strReqLogName);
- pFunc->GetPath("RunInfo", strLogPath);
- strLogPath.Append(SPLIT_SLASH_STR).Append("InstallLog").Append(SPLIT_SLASH_STR).Append((const char*)strReqLogName).Append(".log");
- }
- else
- {
- // 实体Dbg日志
- strZipFileName = CSimpleStringA::Format("%s_dbg_%s_%s.zip",
- (const char*)sysInfo.strTerminalID, (const char*)strReqLogName, (const char*)strTodayLogName);
- pFunc->GetPath("Dbg", strLogPath);
- if (strReqLogName.Compare("Shell", true) == 0)
- strLogPath.Append(SPLIT_SLASH_STR).Append("SpShell").Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
- else if (strReqLogName.Compare("DualActive", true) == 0)
- strLogPath.Append(SPLIT_SLASH_STR).Append("DualActive").Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
- else if (strReqLogName.Compare("guardian", true) == 0)
- strLogPath.Append(SPLIT_SLASH_STR).Append("guardian").Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
- else if (strReqLogName.Compare("SpHost", true) == 0)
- strLogPath.Append(SPLIT_SLASH_STR).Append("SpHost").Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
- else if (strReqLogName.Compare("SysInit", true) == 0)
- strLogPath.Append(SPLIT_SLASH_STR).Append("SysInit").Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
- else if (strReqLogName.Compare("SpBase", true) == 0)
- strLogPath.Append(SPLIT_SLASH_STR).Append("SpBase").Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
- else
- {
- CEntityStaticInfo info = {};
- auto nRet = pFunc->GetEntityStaticInfo(strReqLogName, info);
- if (nRet != Error_Succeed)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleUploadLogReq")("entity [%s] not exist", (const char*)strReqLogName);
- pReplyPkg->SetErrMsg(Error_NotExist, 0, SP::Utility::UTF8ToGBK(CSimpleStringA::Format("实体[%s]不存在", (const char*)strReqLogName).GetData()).c_str());
- SendPackage(pReplyPkg);
- return Error_NotExist;
- }
- strLogPath.Append(SPLIT_SLASH_STR).Append((const char*)info.strSpFileName).Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
- }
- }
- pFunc->GetPath("Temp", strZipPath);
- strZipPath.Append(SPLIT_SLASH_STR).Append(strZipFileName);
-
- if (!Base_Exist(strLogPath.GetData()))
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleUploadLogReq")("log [%s] not exist", (const char*)strLogPath);
- pReplyPkg->SetErrMsg(Error_NotExist, 0, SP::Utility::UTF8ToGBK(CSimpleStringA::Format("日志文件[%s]不存在", (const char*)strLogPath).GetData()).c_str());
- SendPackage(pReplyPkg);
- return Error_NotExist;
- }
- // 生成ZIP
- rc = ZipFile(strZipPath, strLogPath);
- if (rc != Error_Succeed)
- {
- pReplyPkg->SetErrMsg(rc, 0, SP::Utility::UTF8ToGBK(CSimpleStringA::Format("生成压缩文件[%s]失败", (const char*)strZipFileName).GetData()).c_str());
- SendPackage(pReplyPkg);
- return rc;
- }
- }
- else
- {
- strZipFileName = req.UploadFile;
-
- pFunc->GetPath("Temp", strZipPath);
- strZipPath.Append(SPLIT_SLASH_STR).Append(strZipFileName);
- }
-
- if (!Base_Exist(strZipPath.GetData()))
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleUploadLogReq")("zip log [%s] not exist", (const char*)strZipPath);
- pReplyPkg->SetErrMsg(Error_NotExist, 0, SP::Utility::UTF8ToGBK(CSimpleStringA::Format("日志压缩文件[%s]不存在", (const char*)strZipPath).GetData()).c_str());
- SendPackage(pReplyPkg);
- return Error_NotExist;
- }
- BeginUpload:
- // 开始上传
- long long nStartPos = req.StartPos;
- if (nStartPos <0)
- nStartPos = 0;
- long long nMaxBytes = req.MaxRetBytes;
- if (nMaxBytes <= 0)
- nMaxBytes = 32 * 1024;
- auto file = fopen(strZipPath, "rb");
- if (file == NULL)
- {
- auto nError = errno;
- pReplyPkg->SetErrMsg(Error_Unexpect, 0, SP::Utility::UTF8ToGBK(CSimpleStringA::Format("读取日志文件[%s]失败(%d)", (const char*)strZipFileName, nError).GetData()).c_str());
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleUploadLogReq")(CSimpleStringA::Format("open debug log [%s] fail(%d)", (const char*)strZipPath, nError));
- SendPackage(pReplyPkg);
- return Error_Unexpect;
- }
- generateFilesize(file, strZipPath);
- if (nStartPos >0 && nStartPos < nFileSize)
- {
- _fseeki64(file, nStartPos, SEEK_SET);
- }
- else
- nStartPos = 0;
- long long nNextPos = nStartPos + nMaxBytes;
- if (nMaxBytes + nStartPos > nFileSize)
- {
- nMaxBytes = nFileSize - nStartPos;
- nNextPos = 0;
- }
- long long nRetLen = sizeof(RvcUploadLogRet)+nMaxBytes;
- char *pBuf = new char[nRetLen];
- memset(pBuf, 0, nRetLen);
- RvcUploadLogRet *pRet = (RvcUploadLogRet*)pBuf;
- pRet->TaskID = req.TaskID;
- strncpy_s(pRet->UploadFile, sizeof(pRet->UploadFile), strZipFileName, _TRUNCATE);
- pRet->ZipFileLen = nFileSize;
- pRet->StartPos = req.StartPos;
- pRet->NextPos = nNextPos;
- char *pLogData = (char*)pRet->LogData;
- long long nHasRead(0);
- DWORD nReadLen(0);
- do
- {
- //Dbg("ftell: %d", ftell(file));
- nReadLen = fread(pLogData + nHasRead, 1, nMaxBytes - nHasRead, file);
- //Dbg("ftell: %d", ftell(file));
- if (nReadLen >0)
- nHasRead += nReadLen;
- } while (nReadLen >0 && nHasRead < nMaxBytes);
- fclose(file);
- if (nHasRead < nMaxBytes)
- {
- delete[] pBuf;
- auto nError = GetLastError();
- pReplyPkg->SetErrMsg(Error_NotExist, 0, SP::Utility::UTF8ToGBK(CSimpleStringA::Format("读取文件[%s]失败(%d)", (const char*)strZipFileName, nError).GetData()).c_str());
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleUploadLogReq")(CSimpleStringA::Format("read log [%s] fail(%d)", (const char*)strZipPath, nError));
- SendPackage(pReplyPkg);
- return Error_Unexpect;
- }
- pReplyPkg->AddStruct("UpldLogA", false, false, (BYTE*)pBuf, nRetLen);
- delete[] pBuf;
- SendPackage(pReplyPkg);
- if (nNextPos <= 0)
- {
- // 删除压缩文件
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleUploadLogReq")("finish upload log zip '%s', delete it!", (const char*)strZipFileName);
- Base_DeleteFile(strZipPath.GetData());
- }
- return Error_Succeed;
- }
- ErrorCodeEnum CRemoteControllerCnn::HandleViewEntityStateExReq(const CSmartPointer<IPackage> &pRecvPkg)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleViewEntityStateExReq")("remote view entity state ex");
- auto pReplyPkg = CreateReplyPackage(pRecvPkg);
- int nLen = pRecvPkg->GetStructLen("ViEnExR");
- if (nLen <= 0)
- {
- pReplyPkg->SetErrMsg(Error_Param, 0, "get struct [ViEnExR] fail");
- SendPackage(pReplyPkg);
- return Error_Param;
- }
- assert(nLen == sizeof(RvcViewEntityExReq));
- RvcViewEntityExReq req = {};
- int nArrayLen(0);
- pRecvPkg->GetStructData("ViEnExR", (BYTE*)&req, &nLen, &nArrayLen);
- RvcViewEntityExRet1 ret1 = {};
- ret1.TaskID = req.TaskID;
- pReplyPkg->AddStruct("ViEnExA1", false, false, (BYTE*)&ret1, sizeof(ret1));
- auto pFunc = m_pEntity->GetFunction();
- CAutoArray<CSimpleStringA> strEntityNames;
- CAutoArray<WORD> dwEntityIDs;
- pFunc->GetAllRegistedEntity(strEntityNames, dwEntityIDs);
- int nCount = strEntityNames.GetCount();
- if (nCount >0)
- {
- nCount += 8; // 包括root\shell\silverlight3个虚拟实体
- RvcViewEntityExRet2 *pRet2 = new RvcViewEntityExRet2[nCount];
- memset(pRet2, 0, sizeof(RvcViewEntityExRet2)* nCount);
- CSimpleStringA strEntCfgDir;
- CSimpleStringA strRunCfgDir;
- pFunc->GetPath("Cfg", strEntCfgDir);
- strEntCfgDir.Append(SPLIT_SLASH_STR);
- pFunc->GetPath("RunInfo", strRunCfgDir);
- strRunCfgDir.Append(SPLIT_SLASH_STR).Append("runcfg").Append(SPLIT_SLASH_STR);
- for (int i = 0; i<nCount - 8; i++)
- {
- CEntityRunInfo info = {};
- CSimpleStringA strEntityName = strEntityNames[i];
- pFunc->GetEntityRunInfo(strEntityName, info);
- strncpy_s(pRet2[i].EntityName, sizeof(pRet2[i].EntityName), (const char*)strEntityName, _TRUNCATE);
- pRet2[i].EntityID = dwEntityIDs[i];
- pRet2[i].EntityState = info.eState;
- pRet2[i].ProcessID = info.dwProcessID;
- if (info.dwProcessID > 0)
- {
- #if (defined _WIN32 || defined _WIN64)
- auto hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, info.dwProcessID);
- if (hProcess != NULL)
- {
- PROCESS_MEMORY_COUNTERS pmc = {};
- GetProcessMemoryInfo(hProcess, &pmc, sizeof(pmc));
- pRet2[i].UsedMemory = pmc.WorkingSetSize / 1024 / 1024;
- CloseHandle(hProcess);
- }
- #else
- pRet2[i].UsedMemory = get_proc_mem(info.dwProcessID) / 1024 / 1024;
- #endif
- }
- CSimpleStringA strEntCfgPath = strEntCfgDir + strEntityName + ".ini";
- CSimpleStringA strRunCfgPath = strRunCfgDir + strEntityName + ".ini";
- pRet2[i].HasConfig = Base_Exist(strEntCfgPath.GetData());
- pRet2[i].HasRunCfg = Base_Exist(strRunCfgPath.GetData());
- }
- strncpy_s(pRet2[nCount - 8].EntityName, sizeof(pRet2[nCount - 8].EntityName), "guardian", _TRUNCATE);
- pRet2[nCount - 8].HasConfig = false;
- strncpy_s(pRet2[nCount - 7].EntityName, sizeof(pRet2[nCount - 7].EntityName), "DualActive", _TRUNCATE);
- pRet2[nCount - 7].HasConfig = false;
- strncpy_s(pRet2[nCount - 6].EntityName, sizeof(pRet2[nCount - 6].EntityName), "SpHost", _TRUNCATE);
- pRet2[nCount - 6].HasConfig = false;
- strncpy_s(pRet2[nCount - 5].EntityName, sizeof(pRet2[nCount - 5].EntityName), "SysInit", _TRUNCATE);
- pRet2[nCount - 5].HasConfig = false;
- strncpy_s(pRet2[nCount - 4].EntityName, sizeof(pRet2[nCount - 4].EntityName), "SpBase", _TRUNCATE);
- pRet2[nCount - 4].HasConfig = false;
- // root\shell\silverlight3个虚拟实体
- strncpy_s(pRet2[nCount - 3].EntityName, sizeof(pRet2[nCount - 3].EntityName), "Root", _TRUNCATE);
- pRet2[nCount - 3].HasConfig = true;
- strncpy_s(pRet2[nCount - 2].EntityName, sizeof(pRet2[nCount - 2].EntityName), "Shell", _TRUNCATE);
- pRet2[nCount - 2].HasConfig = true;
- strncpy_s(pRet2[nCount - 1].EntityName, sizeof(pRet2[nCount - 1].EntityName), "Silverlight", _TRUNCATE);
- pReplyPkg->AddStruct("ViEnExA2", false, false, (BYTE*)pRet2, sizeof(RvcViewEntityExRet2)* nCount, nCount);
- }
- SendPackage(pReplyPkg);
- return Error_Succeed;
- }
- ErrorCodeEnum CRemoteControllerCnn::HandleBatchUploadLogsByDateReq(const CSmartPointer<IPackage> &pRecvPkg)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleBatchUploadLogsByDateReq")("remote batch upload logs by date");
- auto pReplyPkg = CreateReplyPackage(pRecvPkg);
- int nLen = pRecvPkg->GetStructLen("ULogsBDR");
- if (nLen <= 0)
- {
- pReplyPkg->SetErrMsg(Error_Param, 0, "get struct [ULogsBDR] fail");
- SendPackage(pReplyPkg);
- return Error_Param;
- }
- assert(nLen == sizeof(RvcBatchUploadLogsByDateReq) || nLen == sizeof(RvcBatchUploadLogsByDateReq2));
- RvcBatchUploadLogsByDateReq req = {};
- RvcBatchUploadLogsByDateReq2 req2 = {};
- int nArrayLen(0);
- if (nLen == sizeof(RvcBatchUploadLogsByDateReq))
- pRecvPkg->GetStructData("ULogsBDR", (BYTE*)&req, &nLen, &nArrayLen);
- else
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleBatchUploadLogsByDateReq")("RvcBatchUploadLogsByDateReq2");
- pRecvPkg->GetStructData("ULogsBDR", (BYTE*)&req2, &nLen, &nArrayLen);
- req.TaskID = req2.TaskID;
- strncpy_s(req.ViewDate, req2.ViewDate, sizeof(req2.ViewDate));
- strncpy_s(req.UploadFile, req2.UploadFile, sizeof(req2.UploadFile));
- strncpy_s(req.ZipFileName, req2.ZipFileName, sizeof(req2.ZipFileName));
- req.StartPos = req2.StartPos;
- req.MaxRetBytes = req2.MaxRetBytes;
- }
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleBatchUploadLogsByDateReq")("UploadFile:%s, ZipFileName:%s", req.UploadFile, req.ZipFileName);
-
-
-
- CSimpleStringA strZipPath;
- auto pFunc = m_pEntity->GetFunction();
- pFunc->GetPath("Temp", strZipPath);
- strZipPath.Append(SPLIT_SLASH_STR);
- CSimpleStringA strZipFileName = req.ZipFileName;
- strZipPath += strZipFileName;
- if (req.StartPos <= 0)
- {
- CSimpleStringA strLogPath;
- auto strTodayLogName = (0 == strlen(req.ViewDate) ? CSimpleStringA(getCurData().c_str()) : CSimpleStringA(req.ViewDate));
- CSimpleStringA strReqLogNames = req.UploadFile;
- auto arrFiles = strReqLogNames.Split(';');
- list<string> listSrcFiles;
- for (int i = 0; i < arrFiles.GetCount(); i++)
- {
- // 第一次上传,需生成对应ZIP文件
- if (arrFiles[i].Compare("Silverlight", true) == 0) // slv日志
- {
- pFunc->GetPath("Slv", strLogPath);
- strLogPath.Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
- }
- else if (arrFiles[i].IsEndWith(".zip", true)) // 安装包日志
- {
- pFunc->GetPath("RunInfo", strLogPath);
- strLogPath.Append(SPLIT_SLASH_STR).Append("InstallLog").Append(SPLIT_SLASH_STR).Append((const char*)arrFiles[i]).Append(".log");
- }
- else
- {
- // 实体Dbg日志
- pFunc->GetPath("Dbg", strLogPath);
- if (arrFiles[i].Compare("Shell", true) == 0)
- strLogPath.Append(SPLIT_SLASH_STR).Append("SpShell").Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
- else if (arrFiles[i].Compare("DualActive", true) == 0)
- strLogPath.Append(SPLIT_SLASH_STR).Append("DualActive").Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
- else if (arrFiles[i].Compare("guardian", true) == 0)
- strLogPath.Append(SPLIT_SLASH_STR).Append("guardian").Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
- else if (arrFiles[i].Compare("SpHost", true) == 0)
- strLogPath.Append(SPLIT_SLASH_STR).Append("SpHost").Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
- else if (arrFiles[i].Compare("SysInit", true) == 0)
- strLogPath.Append(SPLIT_SLASH_STR).Append("SysInit").Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
- else if (arrFiles[i].Compare("SpBase", true) == 0)
- strLogPath.Append(SPLIT_SLASH_STR).Append("SpBase").Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
- else if (arrFiles[i].Compare("Root", true) == 0)
- strLogPath.Append(SPLIT_SLASH_STR).Append("Root").Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
- else
- {
- CEntityStaticInfo info = {};
- auto nRet = pFunc->GetEntityStaticInfo(arrFiles[i], info);
- if (nRet != Error_Succeed)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleBatchUploadLogsByDateReq")("entity [%s] not exist", (const char*)arrFiles[i]);
- pReplyPkg->SetErrMsg(Error_NotExist, 0, SP::Utility::UTF8ToGBK(CSimpleStringA::Format("实体[%s]不存在", (const char*)arrFiles[i]).GetData()).c_str());
- SendPackage(pReplyPkg);
- return Error_NotExist;
- }
- strLogPath.Append(SPLIT_SLASH_STR).Append((const char*)info.strSpFileName).Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
- }
- }
- if (!Base_Exist(strLogPath.GetData()))
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleBatchUploadLogsByDateReq")("log [%s] not exist", (const char*)strLogPath);
- continue;
- }
- listSrcFiles.push_back((const char*)strLogPath);
- }
- if (listSrcFiles.size() == 0)
- {
- pReplyPkg->SetErrMsg(Error_NotExist, 0, SP::Utility::UTF8ToGBK("日志文件不存在").c_str());
- SendPackage(pReplyPkg);
- return Error_NotExist;
- }
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleBatchUploadLogsByDateReq")("strZipPath:%s", strZipPath);
- // 生成ZIP
- auto rc = BatchZipFiles(strZipPath, listSrcFiles);
- if (rc != Error_Succeed)
- {
- pReplyPkg->SetErrMsg(rc, 0, SP::Utility::UTF8ToGBK(CSimpleStringA::Format("生成压缩文件[%s]失败", (const char*)strZipFileName).GetData()).c_str());
- SendPackage(pReplyPkg);
- return rc;
- }
- }
- if (!Base_Exist(strZipPath.GetData()))
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleBatchUploadLogsByDateReq")("zip log [%s] not exist", (const char*)strZipPath);
- pReplyPkg->SetErrMsg(Error_NotExist, 0, SP::Utility::UTF8ToGBK(CSimpleStringA::Format("日志压缩文件[%s]不存在", (const char*)strZipPath).GetData()).c_str());
- SendPackage(pReplyPkg);
- return Error_NotExist;
- }
- // 开始上传
- long long nStartPos = req.StartPos;
- if (nStartPos <0)
- nStartPos = 0;
- long long nMaxBytes = req.MaxRetBytes;
- if (nMaxBytes <= 0)
- nMaxBytes = 32 * 1024;
- auto file = fopen(strZipPath, "rb");
- if (file == NULL)
- {
- auto nError = errno;
- pReplyPkg->SetErrMsg(Error_Unexpect, 0, SP::Utility::UTF8ToGBK(CSimpleStringA::Format("读取日志文件[%s]失败(%d)", (const char*)strZipFileName, nError).GetData()).c_str());
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleBatchUploadLogsByDateReq")(CSimpleStringA::Format("open debug log [%s] fail(%d)", (const char*)strZipPath, nError));
- SendPackage(pReplyPkg);
- return Error_Unexpect;
- }
- generateFilesize(file, strZipPath);
- if (nStartPos >0 && nStartPos < nFileSize)
- {
- _fseeki64(file, nStartPos, SEEK_SET);
- }
- else
- nStartPos = 0;
- long long nNextPos = nStartPos + nMaxBytes;
- if (nMaxBytes + nStartPos > nFileSize)
- {
- nMaxBytes = nFileSize - nStartPos;
- nNextPos = 0;
- }
- long long nRetLen = sizeof(RvcBatchUploadLogsByDateRet) + nMaxBytes;
- char *pBuf = new char[nRetLen];
- memset(pBuf, 0, nRetLen);
- RvcBatchUploadLogsByDateRet *pRet = (RvcBatchUploadLogsByDateRet*)pBuf;
- pRet->TaskID = req.TaskID;
- strncpy_s(pRet->ZipFileName, sizeof(pRet->ZipFileName), strZipFileName, _TRUNCATE);
- pRet->ZipFileLen = nFileSize;
- pRet->StartPos = req.StartPos;
- pRet->NextPos = nNextPos;
- char *pLogData = (char*)pRet->LogData;
- long long nHasRead(0);
- DWORD nReadLen(0);
- do
- {
- //Dbg("ftell: %d", ftell(file));
- nReadLen = fread(pLogData + nHasRead, 1, nMaxBytes - nHasRead, file);
- //Dbg("ftell: %d", ftell(file));
- if (nReadLen >0)
- nHasRead += nReadLen;
- } while (nReadLen >0 && nHasRead < nMaxBytes);
- fclose(file);
- if (nHasRead < nMaxBytes)
- {
- delete[] pBuf;
- auto nError = GetLastError();
- pReplyPkg->SetErrMsg(Error_NotExist, 0, SP::Utility::UTF8ToGBK(CSimpleStringA::Format("读取文件[%s]失败(%d)", (const char*)strZipFileName, nError).GetData()).c_str());
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleBatchUploadLogsByDateReq")(CSimpleStringA::Format("read log [%s] fail(%d)", (const char*)strZipPath, nError));
- SendPackage(pReplyPkg);
- return Error_Unexpect;
- }
- pReplyPkg->AddStruct("ULogsBDA", false, false, (BYTE*)pBuf, nRetLen);
- delete[] pBuf;
- SendPackage(pReplyPkg);
- if (nNextPos <= 0)
- {
- // 删除压缩文件
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleBatchUploadLogsByDateReq")("finish upload log zip '%s', delete it!", (const char*)strZipFileName);
- Base_DeleteFile(strZipPath.GetData());
- }
- return Error_Succeed;
- }
- ErrorCodeEnum CRemoteControllerCnn::HandleBatchUploadLogsReq(const CSmartPointer<IPackage> &pRecvPkg)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleBatchUploadLogsReq")("remote batch upload logs");
- auto pReplyPkg = CreateReplyPackage(pRecvPkg);
- int nLen = pRecvPkg->GetStructLen("UpdLogsR");
- if (nLen <= 0)
- {
- pReplyPkg->SetErrMsg(Error_Param, 0, "get struct [UpdLogsR] fail");
- SendPackage(pReplyPkg);
- return Error_Param;
- }
- assert(nLen == sizeof(RvcBatchUploadLogsReq) || nLen == sizeof(RvcBatchUploadLogsReq2));
- RvcBatchUploadLogsReq req = {};
- RvcBatchUploadLogsReq2 req2 = {};
- int nArrayLen(0);
- if (nLen == sizeof(RvcBatchUploadLogsReq))
- pRecvPkg->GetStructData("UpdLogsR", (BYTE*)&req, &nLen, &nArrayLen);
- else
- {
- pRecvPkg->GetStructData("UpdLogsR", (BYTE*)&req2, &nLen, &nArrayLen);
- req.TaskID = req2.TaskID;
- req.StartPos = req2.StartPos;
- req.MaxRetBytes = req2.MaxRetBytes;
- strncpy_s(req.UploadFile, req2.UploadFile, sizeof(req2.UploadFile));
- strncpy_s(req.ZipFileName, req2.ZipFileName, sizeof(req2.ZipFileName));
- }
-
-
- CSimpleStringA strZipPath;
- auto pFunc = m_pEntity->GetFunction();
- pFunc->GetPath("Temp", strZipPath);
- strZipPath.Append(SPLIT_SLASH_STR);
- CSimpleStringA strZipFileName = req.ZipFileName;
- strZipPath += strZipFileName;
- if (req.StartPos <= 0)
- {
- CSimpleStringA strLogPath;
- auto strTodayLogName = CSimpleStringA(getCurData().c_str());
- CSimpleStringA strReqLogNames = req.UploadFile;
- auto arrFiles = strReqLogNames.Split(';');
- list<string> listSrcFiles;
- for (int i = 0; i < arrFiles.GetCount(); i++)
- {
- // 第一次上传,需生成对应ZIP文件
- if (arrFiles[i].Compare("Silverlight", true) == 0) // slv日志
- {
- pFunc->GetPath("Slv", strLogPath);
- strLogPath.Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
- }
- else if (arrFiles[i].IsEndWith(".zip", true)) // 安装包日志
- {
- pFunc->GetPath("RunInfo", strLogPath);
- strLogPath.Append(SPLIT_SLASH_STR).Append("InstallLog").Append(SPLIT_SLASH_STR).Append((const char*)arrFiles[i]).Append(".log");
- }
- else
- {
- // 实体Dbg日志
- pFunc->GetPath("Dbg", strLogPath);
- if (arrFiles[i].Compare("Shell", true) == 0)
- strLogPath.Append(SPLIT_SLASH_STR).Append("SpShell").Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
- else if (arrFiles[i].Compare("DualActive", true) == 0)
- strLogPath.Append(SPLIT_SLASH_STR).Append("DualActive").Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
- else if (arrFiles[i].Compare("guardian", true) == 0)
- strLogPath.Append(SPLIT_SLASH_STR).Append("guardian").Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
- else if (arrFiles[i].Compare("SpHost", true) == 0)
- strLogPath.Append(SPLIT_SLASH_STR).Append("SpHost").Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
- else if (arrFiles[i].Compare("SysInit", true) == 0)
- strLogPath.Append(SPLIT_SLASH_STR).Append("SysInit").Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
- else if (arrFiles[i].Compare("SpBase", true) == 0)
- strLogPath.Append(SPLIT_SLASH_STR).Append("SpBase").Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
- else if (arrFiles[i].Compare("Root", true) == 0)
- strLogPath.Append(SPLIT_SLASH_STR).Append("Root").Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
- else
- {
- CEntityStaticInfo info = {};
- auto nRet = pFunc->GetEntityStaticInfo(arrFiles[i], info);
- if (nRet != Error_Succeed)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleBatchUploadLogsReq")("entity [%s] not exist", (const char*)arrFiles[i]);
- pReplyPkg->SetErrMsg(Error_NotExist, 0, SP::Utility::UTF8ToGBK(CSimpleStringA::Format("实体[%s]不存在", (const char*)arrFiles[i]).GetData()).c_str());
- SendPackage(pReplyPkg);
- return Error_NotExist;
- }
- strLogPath.Append(SPLIT_SLASH_STR).Append((const char*)info.strSpFileName).Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
- }
- }
- if (!Base_Exist(strLogPath.GetData()))
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleBatchUploadLogsReq")("log [%s] not exist", (const char*)strLogPath);
- continue;
- }
- listSrcFiles.push_back((const char*)strLogPath);
- }
- if (listSrcFiles.size() == 0)
- {
- pReplyPkg->SetErrMsg(Error_NotExist, 0, SP::Utility::UTF8ToGBK("日志文件不存在").c_str());
- SendPackage(pReplyPkg);
- return Error_NotExist;
- }
- // 生成ZIP
- auto rc = BatchZipFiles(strZipPath, listSrcFiles);
- if (rc != Error_Succeed)
- {
- pReplyPkg->SetErrMsg(rc, 0, SP::Utility::UTF8ToGBK(CSimpleStringA::Format("生成压缩文件[%s]失败", (const char*)strZipFileName).GetData()).c_str());
- SendPackage(pReplyPkg);
- return rc;
- }
- }
- if (!Base_Exist(strZipPath.GetData()))
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleBatchUploadLogsReq")("zip log [%s] not exist", (const char*)strZipPath);
- pReplyPkg->SetErrMsg(Error_NotExist, 0, SP::Utility::UTF8ToGBK(CSimpleStringA::Format("日志压缩文件[%s]不存在", (const char*)strZipPath).GetData()).c_str());
- SendPackage(pReplyPkg);
- return Error_NotExist;
- }
- // 开始上传
- long long nStartPos = req.StartPos;
- if (nStartPos <0)
- nStartPos = 0;
- long long nMaxBytes = req.MaxRetBytes;
- if (nMaxBytes <= 0)
- nMaxBytes = 32 * 1024;
- auto file = fopen(strZipPath, "rb");
- if (file == NULL)
- {
- auto nError = errno;
- pReplyPkg->SetErrMsg(Error_Unexpect, 0, SP::Utility::UTF8ToGBK(CSimpleStringA::Format("读取日志文件[%s]失败(%d)", (const char*)strZipFileName, nError).GetData()).c_str());
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleBatchUploadLogsReq")(CSimpleStringA::Format("open debug log [%s] fail(%d)", (const char*)strZipPath, nError));
- SendPackage(pReplyPkg);
- return Error_Unexpect;
- }
- generateFilesize(file, strZipPath);
- if (nStartPos >0 && nStartPos < nFileSize)
- {
- _fseeki64(file, nStartPos, SEEK_SET);
- }
- else
- nStartPos = 0;
- long long nNextPos = nStartPos + nMaxBytes;
- if (nMaxBytes + nStartPos > nFileSize)
- {
- nMaxBytes = nFileSize - nStartPos;
- nNextPos = 0;
- }
- long long nRetLen = sizeof(RvcBatchUploadLogsRet) + nMaxBytes;
- char *pBuf = new char[nRetLen];
- memset(pBuf, 0, nRetLen);
- RvcBatchUploadLogsRet *pRet = (RvcBatchUploadLogsRet*)pBuf;
- pRet->TaskID = req.TaskID;
- strncpy_s(pRet->ZipFileName, sizeof(pRet->ZipFileName), strZipFileName, _TRUNCATE);
- pRet->ZipFileLen = nFileSize;
- pRet->StartPos = req.StartPos;
- pRet->NextPos = nNextPos;
- char *pLogData = (char*)pRet->LogData;
- long long nHasRead(0);
- DWORD nReadLen(0);
- do
- {
- nReadLen = fread(pLogData + nHasRead, 1, nMaxBytes - nHasRead, file);
- if (nReadLen >0)
- nHasRead += nReadLen;
- } while (nReadLen >0 && nHasRead < nMaxBytes);
- fclose(file);
- if (nHasRead < nMaxBytes)
- {
- delete[] pBuf;
- auto nError = GetLastError();
- pReplyPkg->SetErrMsg(Error_NotExist, 0, SP::Utility::UTF8ToGBK(CSimpleStringA::Format("读取文件[%s]失败(%d)", (const char*)strZipFileName, nError).GetData()).c_str());
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleBatchUploadLogsReq")(CSimpleStringA::Format("read log [%s] fail(%d)", (const char*)strZipPath, nError));
- SendPackage(pReplyPkg);
- return Error_Unexpect;
- }
- pReplyPkg->AddStruct("UpdLogsA", false, false, (BYTE*)pBuf, nRetLen);
- delete[] pBuf;
- SendPackage(pReplyPkg);
- if (nNextPos <= 0)
- {
- // 删除压缩文件
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleBatchUploadLogsReq")("finish upload log zip '%s', delete it!", (const char*)strZipFileName);
- Base_DeleteFile(strZipPath.GetData());
- }
- return Error_Succeed;
- }
- ErrorCodeEnum CRemoteControllerCnn::HandleCancelUpgradeReq(const CSmartPointer<IPackage> &pRecvPkg)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleCancelUpgradeReq")("remote cancel upgarde");
- auto pReplyPkg = CreateReplyPackage(pRecvPkg);
- int nLen = pRecvPkg->GetStructLen("CancUpgR");
- if (nLen <= 0)
- {
- pReplyPkg->SetErrMsg(Error_Param, 0, "get struct [CancUpgR] fail");
- SendPackage(pReplyPkg);
- return Error_Param;
- }
- assert(nLen == sizeof(RvcCancelUpgradeReq));
- RvcCancelUpgradeReq req = {};
- int nArrayLen(0);
- pRecvPkg->GetStructData("CancUpgR", (BYTE*)&req, &nLen, &nArrayLen);
- RvcCancelUpgradeRet ret = {};
- ret.TaskID = req.TaskID;
- pReplyPkg->AddStruct("CancUpgA", false, false, (BYTE*)&ret, sizeof(ret));
- CSimpleStringA strPack = req.PackName;
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleCancelUpgradeReq")("begin cancel upgrade: %s", (const char*)strPack);
- // 调用升级实体接口升级
- UpgradeMgrService_ClientBase *pClient = new UpgradeMgrService_ClientBase(m_pEntity);
- auto rc = pClient->Connect();
- if (rc == Error_Succeed)
- {
- UpgradeMgrService_CancelUpdate_Req req = {};
- req.strPackFile = strPack;
- UpgradeMgrService_CancelUpdate_Ans ans = {};
- rc = (*pClient)(EntityResource::getLink().upgradeLink())->CancelUpdate(req, ans, 10000);
- pClient->GetFunction()->CloseSession();
- } else {
- pClient->SafeDelete();
- }
- if (rc != Error_Succeed)
- {
- pReplyPkg->SetErrMsg(rc, 0, SP::Utility::UTF8ToGBK("远程取消升级失败").c_str());
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleCancelUpgradeReq")("remote cancel upgrade fail: 0x%X", rc);
- }
- else
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("HandleCancelUpgradeReq")("remote cancel upgrade succeed!");
- }
- SendPackage(pReplyPkg);
- return Error_Succeed;
- }
|