예제 #1
0
void *selfUpdate(void *params)
{
    version_t newVer;
    version_t localVer;
    int ret;
    
    memset(&newVer, 0, sizeof(version_t));
    memset(&localVer, 0, sizeof(version_t));
    getLocalVersion(&localVer);
    FiUpdateAssistant::getinstance()->setPlatform(MAS_SRV);
    /*-----------------------------------------------------------------------------
     *  watch patch_version if changed.
     *-----------------------------------------------------------------------------*/
    while (true)
    {
        sleep(1);
        getLocalVersion(&newVer);
        ret = compareVersion(&localVer, &newVer);        
        if (ret == 0 )
        {
            continue;
        }
        else if (ret < 0)
        {
            //update local
            if (!updatePkg(&newVer))
            {
                ut_dbg("update pkg fail patchNo:%s !!!! no pkg valid ?\n", newVer.patchNo);
            }
            memcpy((void *)&FiUpdateAssistant::getinstance()->netVer,
                    (void *)&newVer, sizeof(version_t));
            if (0 != FiUpdateAssistant::getinstance()->installAllPatch(&localVer))
            {
                FiUpdateAssistant::getinstance()->restartAPP("fics");
                goto exit;
            }
            else
            {
                memcpy((void *)&localVer, (void *)&newVer, sizeof(version_t));
                ut_dbg("update down\n");
            }
        }
        else if (ret > 0 && ret != 1000000)
        {
            //rollback
            memcpy((void *)&FiUpdateAssistant::getinstance()->netVer,
                    (void *)&newVer, sizeof(version_t));
            FiUpdateAssistant::getinstance()->RollBack(&newVer);
            FiUpdateAssistant::getinstance()->restartAPP("fics");
            goto exit;
        }
    }
    return NULL;
exit:
    UpdateSrv->shutdown();
    exit(0);
    return NULL;
}
예제 #2
0
void GBUpdate::requestRemoteVersion()
{
	GBVersion version = splitVersion(getLocalVersion());

	auto request = new (std::nothrow) HttpRequest();
	request->setUrl(StringUtils::format("%s/%d.%d/md5", _updateUrl.c_str(), version.version1, version.version2).c_str());
	request->setRequestType(HttpRequest::Type::GET);
	request->setResponseCallback(CC_CALLBACK_2(GBUpdate::onRequestVersionCompleted, this));
	HttpClient::getInstance()->sendImmediate(request);
	request->release();
}
예제 #3
0
void GBUpdate::onRequestVersionCompleted(HttpClient *sender, HttpResponse *response)
{
	do 
	{
		if (!response)
			break;
		if (!response->isSucceed())
			break;
		vector<char> * pBuf = response->getResponseData();
		if (pBuf->size() > 0)
		{
			vector<vector<string>> v = GBCsv::parseCsv((unsigned char *)pBuf->data(), pBuf->size());
			_remoteVersion = v[0][0];
		}

		if (!_remoteVersion.empty())
		{
			string localVersion = getLocalVersion();
			if (_remoteVersion == localVersion)
			{
				if (getDownloadTotalSize() > MIN_DOWNLOAD_SIZE && !_isAutoUpdate)
				{
					DIRECTOR()->getEventDispatcher()->dispatchCustomEvent(GBUPDATE_EVENT_UPDATE_READY);
				}
				else
				{
					DIRECTOR()->getEventDispatcher()->dispatchCustomEvent(GBUPDATE_EVENT_UPDATE_START);
				}				
				return;
			}
			else if (isVersionValid(_remoteVersion, getLocalVersion()))
			{
				GBVersion version = splitVersion(_remoteVersion);
				string md5Url = StringUtils::format("%s/%d.%d/md5", _updateUrl.c_str(), version.version1, version.version2);				
				_downloader->createDownloadFileTask(md5Url, GBUtils::getExternalPath("md5"), "md5");
				return;
			}
		}
	} while (false);
	DIRECTOR()->getEventDispatcher()->dispatchCustomEvent(GBUPDATE_EVENT_UPDATE_FINISH, (void *)0);
}
예제 #4
0
/**
 * @brief   根据客户端的版本信息,返回客户端需要的版本 集合(链表)
 *
 * @param version
 * @param patchs
 *
 * @return 
 */
::CORBA::Long FiUpdateMgrImpl::queryPatchs(const char* version, ::patchSet_t patchs)
{
    //version: cur ver   fics_v1.0.0_2015.10.16_4005
    //paths cur pat num set
    //need to set value  patshs
//    long patchs[100];
    int patch = 0;//读取patch_version文件 4005
    int baseVer = 0;
    int patchVer = 0;
    int i=0;
    char fileNameRE[512]={0};//Regular Expression
    version_t curVer;
    int tmpVer = 0;
    char cmdBuf[512];
    char tmppath[256]={0};
    char *pos;
    char *date;
    char *fileName;
    FILE *fp = NULL;
    int r=0;
    /*-----------------------------------------------------------------------------
     *  0. scan fics_v1.0.0_2015.09.12_4000.zip -- fics_v1.0.0_2015.10.16_4005.zip
     *  1. get base num, get patchNum
     *  2. scan a
     *-----------------------------------------------------------------------------*/
    memset(patchs, 0 ,sizeof(patchSet_t));//客户端 全为0 传过来就不为0
    if (getLocalVersion(&curVer) != 0)
    {
        ut_err("get local ver fail\n");
        return 1;
    }
    patch = atoi(curVer.patchNo);
    baseVer  = getCurBaseVer(patch);//40
    patchVer = getCurPatchVer(patch);//5
    tmpVer = baseVer * BASEINTERVAL;
    for (i = 0; i<=patchVer; i++)
    {
        sprintf(fileNameRE, "fics_%s_*_%d.zip", curVer.version, tmpVer+i);//reg skip date eg:fics_v1.0.0_*_4005.zip
        sprintf(cmdBuf, "find %s -name \'%s\'", _PATH_PKG_DL, fileNameRE);
        if (NULL == (fp = popen(cmdBuf, "r")))
        {
            ut_err("popen error[%d]\n", errno);
            return 2;
        }
        r = fscanf(fp, "%[^\n]s", tmppath);
        fgetc(fp);
        if (r == 1)
        {
            if (!(fileName = basename(tmppath)))
            {
                pclose(fp);
                continue;
            }
            if (!(pos = strstr(fileName, curVer.version)))
            {
                pclose(fp);
                continue;
            }
            if (!(pos = strchr(pos, '_')))
            {
                pclose(fp);
                continue;
            }
            date = pos + 1;
            if (!(pos = strchr(date, '_')))
            {
                pclose(fp);
                continue;
            }
            *pos = 0;
            patchs[i][0] = 1;
            patchs[i][1] = date2Long(date);
        }
        pclose(fp);
    }

    return 0;
}
예제 #5
0
::CORBA::Long FiUpdateMgrImpl::QueryCurVersion(const char* inversion, const char* indate, 
											   const char* inpatchno, ::CORBA::String_out version,
											   ::CORBA::String_out date, ::CORBA::String_out patchno,
											   ::CORBA::String_out hash
											   )
{
    int ret = 0;
    version_t localVer, cliVer;
	version = CORBA::string_dup("");
	date = CORBA::string_dup("");
	patchno = CORBA::string_dup("");
    hash  = CORBA::string_dup("");
 
    memset(&localVer, 0, sizeof (version_t));
    memset(&cliVer, 0, sizeof (version_t));

    strcpy(cliVer.version, inversion);
    strcpy(cliVer.date, indate);
    strcpy(cliVer.patchNo, inpatchno);
    
	ut_dbg("the client version:%s date:%s  patch:%s\n",inversion,indate,inpatchno);
	fflush(stdout);


	std::string strpatchver("");
	std::string strpatchdate("");
	std::string strpatchno("");
    getLocalVersion(&localVer);
	version = CORBA::string_dup(localVer.version);
	date    =  CORBA::string_dup(localVer.date);
	patchno =  CORBA::string_dup(localVer.patchNo);
    hash    =  CORBA::string_dup(localVer.reserved.hash);
	bool rollbackflag=false;
	bool updateflag = false;
    
	ret = compareVersion(&localVer, &cliVer);
    if (ret > 0 && ret != 1000000)
    {
        //update localVer > cliVer
        updateflag = true;
    }
    else if (ret < 0)
    {
        //roll
        //rollbackflag = true;
        updateflag = true;
        ut_dbg("roolback to version:%s date:%s,patch:%s\n",strpatchver.c_str(),strpatchdate.c_str(),strpatchno.c_str());
		fflush(stdout);        
    }
	if (rollbackflag)
	{
		version = CORBA::string_dup(strpatchver.c_str());
		date =  CORBA::string_dup(strpatchdate.c_str());
		patchno =  CORBA::string_dup(strpatchno.c_str());
		ut_dbg("roolback to version:%s date:%s,patch:%s\n",strpatchver.c_str(),strpatchdate.c_str(),strpatchno.c_str());
		fflush(stdout);
        return 1;
	}
	if (updateflag)
	{
		std::string folder;

		std::string patchprix("fics_");
        patchprix += localVer.version;
        patchprix += "_";
        patchprix += localVer.date;
        if (strlen(localVer.patchNo) > 0)
        {
            patchprix += "_";
            patchprix += localVer.patchNo;
        }

#if defined WIN32|| defined WIN64
		char szFind[MAX_PATH];
		char buff1[200];
		int ret = FiGetCurDir(200,buff1);
		WIN32_FIND_DATA FindFileData;
		strcpy(szFind,buff1);
		strcat(szFind,"\\*.*");

		HANDLE hFind=::FindFirstFile(szFind,&FindFileData);
		if(INVALID_HANDLE_VALUE == hFind)
		{
			version = CORBA::string_dup("");
			date = CORBA::string_dup("");
			patchno = CORBA::string_dup("");
			printf("no package is available!****!! line:%d\n",__LINE__);
			fflush(stdout);
			return -3;
		}

		while(TRUE)
		{
			if(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
			{
				if(FindFileData.cFileName[0]!='.')
				{
					if (strcmp(FindFileData.cFileName,patchprix.c_str())>0)
					{
						if (folder.length()>0)
						{
							if (strcmp(folder.c_str(),FindFileData.cFileName)>0)
							{
								folder = FindFileData.cFileName;
							}

						}
						else
						{
							folder = FindFileData.cFileName;
						}

					}
				}
			}

			if(!FindNextFile(hFind,&FindFileData))
				break;
		}
		FindClose(hFind);
#else
		DIR *dp;
		struct dirent *entry;
		
		char buff1[200];
		int ret = getPkgDlDir(200,buff1);
		if((dp = opendir(buff1)) == NULL)
		{
			version = CORBA::string_dup("");
			date = CORBA::string_dup("");
			patchno = CORBA::string_dup("");
			ut_dbg("no package is available!****!!\n");
			fflush(stdout);
			return -5;
		}
		while((entry = readdir(dp)) != NULL)
		{  
			struct stat statbuf;
			std::string fullname=buff1;
			fullname+=entry->d_name;
			lstat(fullname.c_str(), &statbuf);
			if(S_ISDIR(statbuf.st_mode))
			{  
				if (strcmp(".", entry->d_name) == 0 || strcmp("..", entry->d_name) == 0)  
					continue;
				if (strcmp(entry->d_name, patchprix.c_str()) == 0)//本地版本较 客户端版本 ==
				{
                    folder =entry->d_name;
                    break;
#if 0
					if (folder.length()>0)
					{
						if (strcmp(folder.c_str(),entry->d_name)<0)//sean >0 --> <0
						{
							folder = entry->d_name;
						}

					}
					else
					{
						folder =entry->d_name;
					}
#endif
				}
			}  

		}  

		closedir(dp);                  
#endif
        if (folder.empty())return 1;
		//assert(!folder.empty());
		
		std::string selectversion ;
		std::string selectdate;
        char *posTmp = NULL;
        char *sdate  = NULL ;
        char *sversion = NULL;
        char *spatchNo = NULL;

        char strBuf[100] = {0};

        strcpy(strBuf, folder.c_str());
        posTmp = strchr(strBuf, '_');//_v1.0.0
        sversion = posTmp+1;
        posTmp = strchr(posTmp+1, '_');//_2015
        *posTmp = '\0';
        sdate = posTmp+1;
        posTmp = strchr(posTmp+1, '_');//_4005
        *posTmp = '\0';
        spatchNo = posTmp+1;
        //pos = strchr(pos+1, '_');//_4005
        selectversion = sversion;
        selectdate = sdate;
        strpatchno = spatchNo;
		version = CORBA::string_dup(selectversion.c_str());
		date =  CORBA::string_dup(selectdate.c_str());
		patchno =  CORBA::string_dup(strpatchno.c_str());
		ut_dbg("client ip[11.11.11.11]port[1111] update to version:%s date:%s, patchno:%s\n",selectversion.c_str(),selectdate.c_str(),strpatchno.c_str());
		fflush(stdout);
		return 1;
	}
	
	return 1;
}
예제 #6
0
int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    // Open the installer file
    QString name_in = "full_installer_script.nsi";
    QString name_out = name_in + "temp";
    QFile file_in(name_in);
    QFile file_out(name_out);
    file_in.open(QIODevice::ReadOnly | QIODevice::Text);
    file_out.open(QIODevice::WriteOnly | QIODevice::Truncate);
    QTextStream in_enc(&file_in);
    QTextStream out_enc(&file_out);
    out_enc.setCodec("UTF-8");
    while(!in_enc.atEnd())
    {
        QString line = in_enc.readLine();
        // Update to current revision
        if(line.contains("  !define REVISION "))
        {
            QStringList temp = line.split("\"");
            temp[1] = QString::number(getLocalVersion());
            line = temp.join("\"");
        }

        // Update translations lines (including commented ones)
        QString langString = "LangString ";
        if(line.startsWith("; LangString")){
            langString = "; LangString ";
        }

        if(line.startsWith(langString)){
            QString backup = line;

            // Get language infos
            QStringList temp_lang = line.replace("{","|").replace("}","|").split("|");
            QStringList temp_lang_name = temp_lang[1].split("_");
            QString langName = temp_lang_name[1];
            QString langCode = getLanguageCodeFromName(langName);

            // Get tag
            QStringList temp_tag = temp_lang[0].split(" ");
            QString tag = temp_tag[1];
            if(backup.startsWith(";"))
            { // Pick the second char as the first is a comment
                tag = temp_tag[2];
            }
            QString translation = getTranslation(langCode, tag);
            if (!translation.isEmpty())
            {
                line = langString + tag + " ${LANG_" + langName + "} " + "\"" + translation + "\"";
            }
            else
            {
                line = backup;
            }
        }

        out_enc << line << "\n";
    }
    file_in.close();
    file_out.close();
    QFile::remove(name_in);
    QFile::rename(name_out,name_in);
    return 0;
}
예제 #7
0
int sendHello()
{
    int s;
    int err=0;
    helloType_t hello;
    version_t localVer;
    struct sockaddr_in mcast_addr;      
    std::string localIp;

    init_helloType(&hello);
    memset(&localVer, 0, sizeof(version_t));

    if (getCurLocalIp(localIp) < 0)
    {
        ut_err("get local ip fail\n");
        return -1;
    }
    getLocalVersion(&localVer);

    s = socket(AF_INET, SOCK_DGRAM, 0);         
    if (s == -1)
    {
        ut_err("socket() fail\n");
        return -1;
    }
//fics
    sprintf(hello.version+strlen(hello.version), "fics_%s_%s",
        localVer.version, localVer.date);
    strcat(hello.endPoint.ip, localIp.c_str());
    sprintf(hello.endPoint.port+strlen(hello.endPoint.port), "%d",
        RPC_PORT);
    sprintf(hello.endPoint.nodeId+strlen(hello.endPoint.nodeId),"%d",
        umparams.master ? 0 : -1);//need to modify
    hello.endPoint.type = umparams.master == true ? LEADER : FOLLOWER;
    memset(&mcast_addr, 0, sizeof(mcast_addr));/*初始化IP多播地址为0*/
    mcast_addr.sin_family = AF_INET;                 /*设置协议族类行为AF*/
    mcast_addr.sin_addr.s_addr = inet_addr(MCAST_ADDR);/*设置多播IP地址*/
    mcast_addr.sin_port = htons(MCAST_PORT);         /*设置多播端口*/

    
#if 0
    err = bind(s,(struct sockaddr*)&mcast_addr, sizeof(mcast_addr)) ;
    if(err < 0)
    {
        perror("bind()");
        return -2;
    }
#endif
    int n;
    int count = 3;
    /*向多播地址发送数据*/
    do
    {
        n = sendto(s,                            /*套接字描述符*/
                &hello,      /*数据*/
                sizeof(hello),      /*长度*/
                0,
                (struct sockaddr*)&mcast_addr,
                sizeof(mcast_addr)) ;
        if( n < 0)
        {
            ut_err("sendto() fail errno:%d\n", errno);
        }       
        count--;
        sleep(MCAST_INTERVAL);                           /*等待一段时间*/
    }while(-1 == n && count > 0);
    close(s);
    
    return 0;
}
예제 #8
0
/**
 * @brief 接收master/其他server 的心跳包,更新download下的当前zip全版本安装包。master只发心跳包,不接收(master是所有的源)。
 *
 * @param params
 *
 * @return 
 */
void* recvHelloHandler(void *params)
{
    int s;                                       
    struct sockaddr_in local_addr; 
    version_t localVer;
    int err = -1;

    memset(&localVer, 0, sizeof(localVer));
    s = socket(AF_INET, SOCK_DGRAM, 0);     
    if (s == -1)
    {
        perror("socket()");
        return (void *)-1;
    }   

    memset(&local_addr, 0, sizeof(local_addr));
    local_addr.sin_family = AF_INET;
    local_addr.sin_addr.s_addr = htonl(INADDR_ANY);
    local_addr.sin_port = htons(MCAST_PORT);

    /*绑定socket*/
    err = bind(s,(struct sockaddr*)&local_addr, sizeof(local_addr)) ;
    if(err < 0)
    {
        ut_err("bind()fail errno[%d]\n", errno);
        return (void *)-2;
    }

    /*设置回环许可*/
    int loop = 0;//禁止
    err = setsockopt(s,IPPROTO_IP, IP_MULTICAST_LOOP,&loop, sizeof(loop));
    if(err < 0)
    {
        ut_err("setsockopt():IP_MULTICAST_LOOP\n");
        return (void *)-3;
    }

    struct ip_mreq mreq;                                     /*加入广播组*/
    mreq.imr_multiaddr.s_addr = inet_addr(MCAST_ADDR);   /*广播地址*/
    mreq.imr_interface.s_addr = htonl(INADDR_ANY);   /*网络接口为默认*/
    /*将本机加入广播组*/
    err = setsockopt(s, IPPROTO_IP, IP_ADD_MEMBERSHIP,&mreq, sizeof
            (mreq));
    if (err < 0)
    {
        ut_err("setsockopt():IP_ADD_MEMBERSHIP\n");
        return (void *)-4;
    }

    int addr_len = 0;
    helloType_t buff;
    int n = 0;
    while (1)
    {
        addr_len = sizeof(local_addr);
        memset(&buff, 0, sizeof(buff));                  /*清空接收缓冲区*/
        /*接收数据*/
        n = recvfrom(s, &buff, sizeof(buff), 0,(struct sockaddr*)&local_addr,
                &addr_len);
        if( n == -1)
        {
            ut_err("recvfrom()\n");
        }
        if (strcmp(buff.action, "action:hello") != 0 || buff.endPoint.type != LEADER)
        {
            continue;
        }
        /*打印信息*/
        ut_dbg("Recv hello message from server:%s\n", buff.version);
        getLocalVersion(&localVer);
        version_t net;
        int ret;
        memset(&net, 0, sizeof(net));
        char *version = strstr(buff.version, "_v");//version:fics_v2.1.0_2015.09.04
        if (version)version++;
        char *date = strchr(version, '_');
        if (date)*date++='\0';
        char *patchNo = strchr(date, '_');
        if (patchNo)patchNo++;
        if (version)strcpy(net.version, version);
        if (date)strcpy(net.date, date);
        if (patchNo)strcpy(net.patchNo, patchNo);
        ret = compareVersion(&localVer, &net);
        if ( ret!= 0 && ret!=1000000)
        {
            char *ip = strstr(buff.endPoint.ip, "ip:");
            ip = ip+strlen("ip:");
            char srcFile[256]={0};
            char cmdBuf[250]={0};
            sprintf(srcFile, "/sobey/fics/download/fics_%s_%s", net.version, net.date);
            if (patchNo)sprintf(srcFile+strlen(srcFile), "_%s", patchNo);
            strcat(srcFile, ".zip");
            //down file
            ret = FiUpdateAssistant::getinstance()->downloadFile(ip, srcFile, srcFile);
            if (ret == 0)
            {
                ut_dbg("download file success\n");
                //modify local patch_version
                char patchVerBuf[200];

                sprintf(cmdBuf, "unzip %s -d %s", srcFile, _PATH_PKG_DL);
                system(cmdBuf);//unzip pkg
                writeLocalVer(&net);
                //overwrite patch_version
            }
            else
            {
                ut_err("download file fail\n");
                sprintf(cmdBuf, "rm %s -rf", srcFile);
                system(cmdBuf);
            }
        }
        sleep(MCAST_INTERVAL);
    }

    /*退出广播组*/
    err = setsockopt(s, IPPROTO_IP, IP_DROP_MEMBERSHIP,&mreq, sizeof
            (mreq));

    close(s);
    return NULL;
}