示例#1
0
bool CUpdater::Run()
{
	if( state_ != UpdaterState::idle && state_ != UpdaterState::failed &&
		state_ != UpdaterState::newversion && state_ != UpdaterState::newversion_ready )
	{
		return false;
	}

	wxDateTime const t = wxDateTime::Now();
	COptions::Get()->SetOption(OPTION_UPDATECHECK_LASTDATE, t.Format(_T("%Y-%m-%d %H:%M:%S")));

	local_file_.clear();
	log_ = wxString::Format(_("Started update check on %s\n"), t.Format());

	wxString build = CBuildInfo::GetBuildType();
	if( build.empty() ) {
		build = _("custom");
	}
	log_ += wxString::Format(_("Own build type: %s\n"), build);

	SetState(UpdaterState::checking);

	m_use_internal_rootcert = true;
	int res = Download(GetUrl(), wxString());

	if (res != FZ_REPLY_WOULDBLOCK) {
		SetState(UpdaterState::failed);
	}
	raw_version_information_.clear();

	return state_ == UpdaterState::checking;
}
示例#2
0
文件: api.cpp 项目: bwRavencl/X-fr24
// returns the name of the zone that fits the given latitude and longitude best
static char *GetZoneName(double latitude, double longitude)
{
    char *zoneName = NULL;
    char *zones = GetUrl(URL_ZONES);

    if (zones != NULL)
    {
        JSON_Value *rootJson = json_parse_string(zones);
        free(zones);
        zones = NULL;

        if (rootJson != NULL)
        {
            if (rootJson->type == JSONObject)
            {
                double bestDistance = -1.0;
                ParseZones(&zoneName, &bestDistance, json_value_get_object(rootJson), latitude, longitude);
            }

            json_value_free(rootJson);
            rootJson = NULL;
        }
    }

    return zoneName;
}
示例#3
0
QVariant BookmarksModel::data (const QModelIndex& index, int role) const
{
    if (index.row () < 0 || index.row () > Bookmarks_.count ())
        return QVariant ();

    auto bookmark = Bookmarks_.at (index.row ());

    switch (role)
    {
    case BRID:
        return bookmark->GetID ();
    case BRUrl:
        return bookmark->GetUrl ();
    case BRTitle:
        return bookmark->GetTitle ();
    case BRDescription:
        return bookmark->GetDescription ();
    case BRImageUrl:
        return bookmark->GetImageUrl ();
    case BRFavorite:
        return bookmark->IsFavorite ();
    case BRRead:
        return bookmark->IsRead ();
    case BRTags:
        return bookmark->GetTags ().join (',');
    case BRAddTime:
        return bookmark->GetAddTime ();
    case BRUpdateTime:
        return bookmark->GetUpdateTime ();
    case BRStatus:
        return bookmark->GetStatus ();
    default:
        return QVariant ();
    }
}
void HttpDebugSocket::OnFirst()
{
	Send(
		"HTTP/1.1 200 OK\n"
		"Content-type: text/html\n"
		"Connection: close\n"
		"Server: HttpDebugSocket/1.0\n"
		"\n");
	Send(
		"<html><head><title>Echo Request</title></head>"
		"<body><h3>Request Header</h3>");
	Send(	"<form method='post' action='/test_post'>"
		"<input type='text' name='text' value='test text'><br>"
		"<input type='submit' name='submit' value=' OK '></form>");

	// enctype 'multipart/form-data'
	Sendf("<form action='/test_post' method='post' enctype='multipart/form-data'>");
	Sendf("<input type=file name=the_file><br>");
	Sendf("<input type=text name=the_name><br>");
	Sendf("<input type=submit name=submit value=' test form-data '>");
	Sendf("</form>");

	Send(	"<pre style='background: #e0e0e0'>");
	Send(GetMethod() + " " + GetUrl() + " " + GetHttpVersion() + "\n");
}
 void OrthancPeerParameters::ToJson(Json::Value& value) const
 {
   value = Json::arrayValue;
   value.append(GetUrl());
   value.append(GetUsername());
   value.append(GetPassword());
 }
示例#6
0
void BookmarksModel::AddBookmarks (const Bookmarks_t& bookmarks)
{
    Bookmarks_t bmss = bookmarks;
    for (int i = bmss.count () - 1; i >= 0; --i)
    {
        auto bms = bmss.at (i);
        auto it = std::find_if (Bookmarks_.begin (), Bookmarks_.end (),
                                [bms] (decltype (Bookmarks_.front ()) bookmark)
        {
            return bms->GetID () == bookmark->GetID ();
        });
        if (it != Bookmarks_.end ())
        {
            const int pos = std::distance (Bookmarks_.begin (), it);
            switch (bms->GetStatus ())
            {
            case Bookmark::SDeleted:
                RemoveBookmark (bms->GetID ());
                break;
            case Bookmark::SArchived:
            {
                Bookmark *bm = Bookmarks_ [pos];
                bm->SetIsRead (true);

                emit dataChanged (index (pos), index (pos));

                break;
            }
            default:
            {
                Bookmark *bm = Bookmarks_ [pos];
                bm->SetUrl (bms->GetUrl ());
                bm->SetTitle (bms->GetTitle ());
                bm->SetDescription (bms->GetDescription ());
                bm->SetIsFavorite (bms->IsFavorite ());
                bm->SetIsRead (bms->IsRead ());
                bm->SetAddTime (bms->GetAddTime ());
                bm->SetUpdateTime (bms->GetUpdateTime ());
                bm->SetTags (bms->GetTags ());
                bm->SetImageUrl (bms->GetImageUrl ());
                bm->SetStatus (bms->GetStatus ());

                emit dataChanged (index (pos), index (pos));

                break;
            }
            }

            bmss.takeAt (i)->deleteLater ();
        }
    }

    beginInsertRows (QModelIndex (), rowCount (),
                     rowCount () + bmss.count () - 1);
    Bookmarks_.append (bmss);
    endInsertRows ();
}
示例#7
0
文件: api.cpp 项目: bwRavencl/X-fr24
// retrieves the balancer url with the lowest load, if there are several balancers with the same load one of these is randomly selected
static char *GetBalancerUrl(void)
{
    char *bestUrl = NULL;

    char *balance = GetUrl(URL_BALANCE);
    if (balance != NULL)
    {
        JSON_Value *rootJson = json_parse_string(balance);
        free(balance);
        balance = NULL;

        if (rootJson != NULL && rootJson->type == JSONObject)
        {
            JSON_Object *serversJson = json_value_get_object(rootJson);

            if (serversJson != NULL)
            {
                size_t serverCount = json_object_get_count(serversJson);
                int bestLoad = 0;

                for (int i = 0; i < serverCount; i++)
                {
                    const char *url = json_object_get_name(serversJson, i);

                    JSON_Value *value = json_object_get_value(serversJson, url);

                    if (value != NULL && value->type == JSONNumber)
                    {
                        int load = (int) json_object_get_number(serversJson, url);

                        if (load != 0 && (bestUrl == NULL || load <= bestLoad/* || (load == bestLoad && rand() % 2)*/))
                        {
                            if (bestUrl != NULL)
                            {
                                free(bestUrl);
                                bestUrl = NULL;
                            }

                            bestUrl = (char*) malloc(strlen(url) + 1);
                            if (bestUrl != NULL)
                                strcpy(bestUrl, url);

                            bestLoad = load;
                        }
                    }
                }
            }

            json_value_free(rootJson);
            rootJson = NULL;
        }
    }

    return bestUrl;
}
示例#8
0
	//------------------------------------------------------------------------------
	void PostHandle::_OnStart()
	{
		SmartPtr<PostJob> pPostJob( NEW PostJob );
		pPostJob->SetUrl(GetUrl());
		pPostJob->SetPostContent(_GetPostContent().c_str());
		pPostJob->SetUsername(GetUsername());
		pPostJob->SetPassword(GetPassword());
		pPostJob->Connect();
		pPostJob->SetCallback( MEMBER_FUNC_PTR( &PostHandle::JobDoneCallBack ));
		_PushJob( pPostJob );
	}
示例#9
0
int _tmain(int argc, _TCHAR* argv[])
{
	TCHAR tszFullPath[MAX_PATH] = {0};
	TCHAR tszUrl[MAX_PATH] = {0};
	_tcscpy(tszFullPath, _T("D:\\WinPath\\Favorites\\代码发芽网.url"));
	GetUrl(tszFullPath, tszUrl);

	getchar();


	return 0;
}
示例#10
0
std::string DownloadTask::dump() {
	Json::Value root;

	root["url"] = GetUrl();
	root["download_path"] = GetDownloadPath();
	root["md5"] = GetMd5();
	root["file_size"] = Json::Value(GetFileSize());
	root["progress"] = Json::Value(GetProgress());
	root["breakpoint"] = Json::Value(GetBreakpoint());

	return root.toString();
}
示例#11
0
bool Downloader::GetLatestVersion(std::string& line)
{
  static const char url[] = "http://www.wormux.org/last";
  error.clear();
  if (!GetUrl(url, &line)) {
    if (error.empty())
      error = Format(_("Couldn't fetch last version from %s"), url);
    fprintf(stderr, "%s\n", error.c_str());
    return false;
  }

  return true;
}
示例#12
0
wxString SjWebLinks::GetUrl(int i, const wxString& leadArtistName, const wxString& albumName, const wxString& trackName)
{
	wxString url = GetUrl(i);

	specialUrlencodeNreplace(   url, wxT("%artist%"),       leadArtistName, false   );
	specialUrlencodeNreplace(   url, wxT("%artistutf8%"),   leadArtistName, true    );
	specialUrlencodeNreplace(   url, wxT("%album%"),        albumName,      false   );
	specialUrlencodeNreplace(   url, wxT("%albumutf8%"),    albumName,      true    );
	specialUrlencodeNreplace(   url, wxT("%track%"),        trackName,      false   );
	specialUrlencodeNreplace(   url, wxT("%trackutf8%"),    trackName,      true    );

	return url;
}
示例#13
0
bool Downloader::TwitterLogin(const std::string& user, const std::string& pwd)
{
  if (twitter_logged)
    return true;
  std::string html, fields;

  twitter_logged = false;
  if (!GetUrl("http://mobile.twitter.com/session/new", &html)) {
    goto end;
  }
  MSG_DEBUG("downloader", "Login connect success!");

  // Find authenticity_token value
  if (!FindNameValue(auth, "authenticity_token", html)) {
    error = _("Can't find authenticity_token");
    goto end;
  }
  MSG_DEBUG("downloader", "authenticity_token=%s", auth.c_str());

  html.clear();

  fields = "authenticity_token=" + auth + "&username="******"&password="******"downloader", "Fields: %s\n", fields.c_str());
  if (!Post("http://mobile.twitter.com/session", &html, fields)) {
    goto end;
  }
#if 0
  if (html.find("class=\"warning\"") != std::string::npos) {
    printf("Login failed, probably incorrect credentials\n");
    goto end;
  }
#endif
  MSG_DEBUG("downloader", "Login success!\n");
  
  html.clear();

  twitter_logged = true;

end:
  if (!twitter_logged && IsLOGGING("download")) {
    FILE *f = fopen("out.htm", "wt");
    fwrite(html.c_str(), html.size(), 1, f);
    fclose(f);
    MSG_DEBUG("downloader", "Login failed: %s\n", error.c_str());
  }

  return twitter_logged;
}
示例#14
0
/*
	GetIcyData()
*/
void CIcy::GetIcyData(ICYDATA* pIcyData)
{
	memset(pIcyData,'\0',sizeof(ICYDATA));
	if(m_nResponse==ICY_CODE_OK)
	{
		strcpyn(pIcyData->station,GetStationName(),ICY_MAX_STATION+1);
		strcpyn(pIcyData->genre,GetGenre(),ICY_MAX_GENRE+1);
		strcpyn(pIcyData->url,GetUrl(),ICY_MAX_URL+1);
		strcpyn(pIcyData->contenttype,GetContentType(),ICY_MAX_CONTENT+1);
		pIcyData->metaint = GetMetaInterval();
		pIcyData->bitrate = GetBitRate();
		strcpyn(pIcyData->notice,GetNotice(),ICY_MAX_NOTICE+1);
		strcpyn(pIcyData->noticeinfo,GetNoticeInfo(),ICY_MAX_NOTICE+1);
		pIcyData->code = m_nResponse;
	}
}
示例#15
0
文件: drawdnd.cpp 项目: wds315/szarp
size_t SetInfoDataObject::GetDataSize(const wxDataFormat& format) const {
	if (format.GetType() != wxDF_TEXT 
			&& format.GetType() != wxDF_FILENAME
//			&& format.GetType() != wxDF_OEMTEXT
			&& format.GetType() != wxDF_UNICODETEXT)
		assert(false);

	wxString url = GetUrl();

	size_t ret = url.length();

	if (format.GetType() == wxDF_FILENAME)
		ret += 1;

	return ret;
}
示例#16
0
bool DownloadTask::load(const std::string &metadata) {
	Json::Reader reader;
	Json::Value value;
	if (!reader.parse(metadata, value)) {
		Log("download task parse failed : %s", metadata.c_str());
		return false;
	} else {
		m_Url = value["url"].asString();
		std::string fileName = utils::StringUtils::GetFileNameFromUrl(GetUrl());
		m_DownloadPath = CACHE_ROOT + fileName;
		m_Md5 = value["md5"].asString();
		m_FileSize = value["size"].asDouble();
		m_Progress = 0;
		m_Breakpoint = 0;
	}
	return true;
}
示例#17
0
文件: drawdnd.cpp 项目: wds315/szarp
bool SetInfoDataObject::GetDataHere(const wxDataFormat& format, void *pbuf) const {
	if (format.GetType() != wxDF_TEXT 
			&& format.GetType() != wxDF_FILENAME
//			&& format.GetType() != wxDF_OEMTEXT
			&& format.GetType() != wxDF_UNICODETEXT)
		return false;

	wxString url = GetUrl();

	char *curl = strdup((char*)SC::S2U(url).c_str());
	size_t len = strlen(curl);
	if (format.GetType() == wxDF_FILENAME)
		len += 1;

	memcpy(pbuf, curl, len);
	free(curl);

	return true;
}
示例#18
0
/**
 ** Fetches the URL's content to a string and returns the string
 **
 **
 ** @param const string url         The URL to fetch
 ** @return std::string
 */
std::string localdb::GetAPIResponse(const std::string url)
{
    curl_global_init(CURL_GLOBAL_ALL);

    // This stringstream will be responsible for turning
    // our fetched data into a string (which will be used for XML document creation)
    std::stringstream stream;
    std::string p;


    if(CURLE_OK == GetUrl(url,stream))
    {
        // Load contents from stringstream into our string
        p = stream.str();
    }

    curl_global_cleanup();

    return p;
}
示例#19
0
static void ConnectionStateHandler
(
    const char *intfName,
    bool isConnected,
    void *contextPtr
)
{
    if (isConnected)
    {
        WaitingForConnection = false;
        LE_INFO("Interface %s connected.", intfName);
        GetUrl();
        le_data_Release(ConnectionRef);
    }
    else
    {
        LE_INFO("Interface %s disconnected.", intfName);
    }

}
示例#20
0
bool Downloader::GetServerList(std::map<std::string, int>& server_lst, const std::string& list_name)
{
  MSG_DEBUG("downloader", "Retrieving server list: %s", list_name.c_str());

  // Download the list of server
  const std::string list_url = "http://www.wormux.org/" + list_name;
  std::string       list_line;

  error.clear();

  if (!GetUrl(list_url.c_str(), &list_line))
    return false;
  MSG_DEBUG("downloader", "Received '%s'", list_line.c_str());

  // Parse the file
  std::stringstream list(list_line);
  std::string       line;

  while (std::getline(list, line)) {
    if (line.at(0) == '#'
        || line.at(0) == '\n'
        || line.at(0) == '\0')
      continue;

    std::string::size_type port_pos = line.find(':', 0);
    if (port_pos == std::string::npos)
      continue;

    std::string hostname = line.substr(0, port_pos);
    std::string portstr = line.substr(port_pos+1);
    int port = atoi(portstr.c_str());
    MSG_DEBUG("downloader", "Received %s:%i", hostname.c_str(), port);

    server_lst[ hostname ] = port;
  }

  MSG_DEBUG("downloader", "Server list retrieved. %u servers are running",
            (uint)server_lst.size());

  return true;
}
FText FMediaSourceActions::GetAssetDescription(const class FAssetData& AssetData) const
{
	auto MediaSource = Cast<UMediaSource>(AssetData.GetAsset());

	if (MediaSource != nullptr)
	{
		FString Url = MediaSource->GetUrl();

		if (Url.IsEmpty())
		{
			return LOCTEXT("AssetTypeActions_MediaSourceMissing", "Warning: Missing settings detected!");
		}

		if (!MediaSource->Validate())
		{
			return LOCTEXT("AssetTypeActions_MediaSourceInvalid", "Warning: Invalid settings detected!");
		}
	}

	return FText::GetEmpty();
}
示例#22
0
//返回值提取到的有效url个数
int	ISpiderFetchUrl::FetchUrl(char* context,int contextLen,bool regexSame)
{
	//提取context中的有效url
	m_Context	=context;
	m_ContextLen=contextLen;
	m_CurrentP	=m_Context;
	m_UrlCount	=0;
	if(!regexSame)
	{
		InitalRegex(context,contextLen);
		while(GetUrl())
		{
			if(this->onFetchUrl(m_TempUrl.GetBuffer(),context,contextLen))
			{
				AddUrl();
			}
		}
	}
	else
	{
		m_TempUrl	=CMyString::StringFromMem(m_CurrentP,0,contextLen);
		//去除结尾"
		m_TempUrl.EraseFromRight(1);
		//去除href="和src="
		if(m_TempUrl[0]=='h')
			m_TempUrl.Erase(0,6);
		else
			m_TempUrl.Erase(0,5);
		//去除http://
		if(m_TempUrl.FindString("http://")!=-1)
			m_TempUrl.Erase(0,7);
		int len=m_TempUrl.GetStrLen();
		
		m_TempUrl.Trim();
		AddUrl();
	}
	return GetUrlCount();
}
示例#23
0
bool DownloadTask::loadFromCache() {
	Log("load from cache : %s", DOWNLOAD_TASK_CACHE_FILE.c_str());
	if (!utils::FsUtils::IsFileExist(DOWNLOAD_TASK_CACHE_FILE)) {
		Log("load from cache : %s not exist", DOWNLOAD_TASK_CACHE_FILE.c_str());
		return false;
	}
	std::string task = utils::FsUtils::ReadFile(DOWNLOAD_TASK_CACHE_FILE);
	Json::Reader reader;
	Json::Value value;
	if (!reader.parse(task, value)) {
		Log("download task parse failed : %s", task.c_str());
		return false;
	} else {
		m_Url = value["url"].asString();
		std::string fileName = utils::StringUtils::GetFileNameFromUrl(GetUrl());
		m_DownloadPath = CACHE_ROOT + fileName;
		m_Md5 = value["md5"].asString();
		m_FileSize = value["file_size"].asDouble();
		m_Progress = value["progress"].asDouble();
		m_Breakpoint = value["breakpoint"].asDouble();
	}
	return true;
}
示例#24
0
static void 
InputCallback(SqueakPlugin *plugin, int *source, XtInputId* id)
{
  int cmd;
  DPRINT("NP: InputCallback()\n");
  if (!plugin->sqwindow)
    {
      /* read sqwindow */
      SetUpSqueakWindow(plugin);
      return;
    }
  Receive(plugin, &cmd, 4);
  switch (cmd) {
  case CMD_GET_URL: 
    GetUrl(plugin);
    break;
  case CMD_POST_URL: 
    PostUrl(plugin);
    break;
  default:
    fprintf(stderr, "Unknown command from Squeak: %i\n", cmd);
  }
}
    bool ClipboardUtil::GetPlainText(IDataObject* data_object,
        std::wstring* plain_text)
    {
        DCHECK(data_object && plain_text);
        if(!HasPlainText(data_object))
        {
            return false;
        }

        STGMEDIUM store;
        if(SUCCEEDED(data_object->GetData(GetPlainTextWFormat(), &store)))
        {
            {
                // Unicode文本.
                base::win::ScopedHGlobal<wchar_t> data(store.hGlobal);
                plain_text->assign(data.get());
            }
            ReleaseStgMedium(&store);
            return true;
        }

        if(SUCCEEDED(data_object->GetData(GetPlainTextFormat(), &store)))
        {
            {
                // ascii文本.
                base::win::ScopedHGlobal<char> data(store.hGlobal);
                plain_text->assign(UTF8ToWide(data.get()));
            }
            ReleaseStgMedium(&store);
            return true;
        }

        // 如果是window平台上拖放的文件, 没有提供任何类型的普通文本格式, 所以
        // 这里我们尝试强行获取一个url.
        std::wstring title;
        return GetUrl(data_object, plain_text, &title, false);
    }
示例#26
0
//
// Log loop body load event to VTune 
//
void VTuneChakraProfile::LogLoopBodyLoadEvent(Js::FunctionBody* body, Js::LoopHeader* loopHeader, Js::LoopEntryPointInfo* entryPoint, uint16 loopNumber)
{
#if ENABLE_NATIVE_CODEGEN
    if (isJitProfilingActive)
    {
        iJIT_Method_Load methodInfo;
        memset(&methodInfo, 0, sizeof(iJIT_Method_Load));
        const char16* methodName = body->GetExternalDisplayName();
        size_t methodLength = wcslen(methodName);
        methodLength = min(methodLength, (size_t)UINT_MAX); // Just truncate if it is too big
        size_t length = methodLength * 3 + /* spaces */ 2 + _countof(LoopStr) + /*size of loop number*/ 10 + /*NULL*/ 1;
        utf8char_t* utf8MethodName = HeapNewNoThrowArray(utf8char_t, length);
        if(utf8MethodName)
        {
            methodInfo.method_id = iJIT_GetNewMethodID();
            size_t len = utf8::EncodeInto(utf8MethodName, methodName, (charcount_t)methodLength);
            sprintf_s((char*)(utf8MethodName + len), length - len," %s %d", LoopStr, loopNumber + 1);
            methodInfo.method_name = (char*)utf8MethodName;
            methodInfo.method_load_address = (void*)entryPoint->GetNativeAddress();
            methodInfo.method_size = (uint)entryPoint->GetCodeSize();        // Size in memory - Must be exact

            size_t urlLength  = 0;
            utf8char_t* utf8Url = GetUrl(body, &urlLength);
            methodInfo.source_file_name = (char*)utf8Url;

            iJIT_NotifyEvent(iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED, &methodInfo);
            OUTPUT_TRACE(Js::ProfilerPhase, _u("Loop body load event: %s Loop %d\n"), methodName, loopNumber + 1);

            if(urlLength > 0)
            {
                HeapDeleteArray(urlLength, utf8Url);
            }
            HeapDeleteArray(length, utf8MethodName);
        }
    }
#endif
}
示例#27
0
BOOL CUrlRichEditCtrl::GoToUrl(int nUrl) const
{
	if (nUrl < 0 || nUrl >= m_aUrls.GetSize())
		return FALSE;
	
	const URLITEM& urli = m_aUrls[nUrl];
		
	if (!urli.bWantNotify)
	{
		CString sUrl = GetUrl(nUrl, TRUE);

		// if it fails to run then forward on to parent
		if (FileMisc::Run(*this, sUrl) > 32)
			return TRUE;

		// else
		SendNotifyFailedUrl(sUrl);
		return FALSE;
	}

	// else
	SendNotifyCustomUrl(urli.sUrl);
	return TRUE;
}
示例#28
0
bool CUpdater::Run()
{
	if( state_ != idle && state_ != failed && state_ != newversion && state_ != newversion_ready ) {
		return false;
	}

	wxDateTime const t = wxDateTime::Now();
	COptions::Get()->SetOption(OPTION_UPDATECHECK_LASTDATE, t.Format(_T("%Y-%m-%d %H:%M:%S")));

	local_file_.clear();
	log_ = wxString::Format(_("Started update check on %s\n"), t.Format().c_str());

	SetState(checking);

	update_options_->m_use_internal_rootcert = true;
	int res = Download(GetUrl(), _T(""));

	if (res != FZ_REPLY_WOULDBLOCK) {
		SetState(failed);
	}
	raw_version_information_.clear();

	return state_ == checking;
}
示例#29
0
int main(int argc, char **argv)
{
    std::string vDNA;
    std::string vMAC_LAN;
    std::string vMAC_WIFI;
    std::string vIP_LAN;
    std::string vIP_WIFI;
    std::string vOS_VER;
    std::string vOS_BUILD;

    bool verbose = false;

    if (argc == 2)
    {
        std::string param(argv[1]);
        if (param == "-v" || param == "--verbose")
            verbose = true;
    }

    unsigned long long dna;
    char string_buffer[18];
    int res;

    // Get DNA
    get_xilinx_dna(&dna);
    sprintf(string_buffer, "%llX", dna);
    vDNA = string_buffer;

    // Get MAC_LAN
    res = 0;
    sprintf(string_buffer, "00:00:00:00:00:00");
    res = GetMACAddressLinux("/sys/class/net/eth0/address", string_buffer);
    if(!res)
        vMAC_LAN = string_buffer;

    // Get MAC_WIFI
    res = 0;
    sprintf(string_buffer, "00:00:00:00:00:00");
    res = GetMACAddressLinux("/sys/class/net/wlan0/address", string_buffer);
    if(!res)
        vMAC_WIFI = string_buffer;

    // Get IP_LAN
    struct ifaddrs *addr;
    getifaddrs(&addr);
    std::map<std::string, std::string> ip_map;

    while(addr)
    {
        struct sockaddr_in *pAddr = (struct sockaddr_in *)addr->ifa_addr;
        ip_map[std::string(addr->ifa_name)] = std::string(inet_ntoa(pAddr->sin_addr));
        addr = addr->ifa_next;
    }

    for (auto it = ip_map.begin(); it != ip_map.end(); ++it)
    {
        if(it->first == "eth0")
            vIP_LAN = it->second;
        if(it->first == "wlan0")
            vIP_WIFI = it->second;
    }

    vOS_VER = GetOSVersion("/opt/redpitaya/www/apps/info/info.json");
    vOS_BUILD = GetOSBuild("/opt/redpitaya/www/apps/info/info.json");
    /*
    std::cout << "DNA: " << vDNA << std::endl;
    std::cout << "LAN IP: " << vIP_LAN << std::endl;
    std::cout << "WIFI IP: " << vIP_WIFI << std::endl;
    std::cout << "LAN MAC: " << vMAC_LAN << std::endl;
    std::cout << "WIFI MAC: " << vMAC_WIFI << std::endl;
    std::cout << "OS VER: " << vOS_VER << std::endl;
    std::cout << "OS BUILD: " << vOS_BUILD << std::endl;*/

    // Build curl command
    std::stringstream cmd;
    cmd << "curl '" << GetUrl() << "?dna=00" << vDNA << "&";
    cmd << "ip_lan=" << vIP_LAN << "&";
    cmd << "mac_lan=" << vMAC_LAN << "&";
    cmd << "os_ver=" << vOS_VER << "&";
    cmd << "os_build=" << vOS_BUILD;

    if(vIP_WIFI != "")
        cmd << "&ip_wifi=" << vIP_WIFI;
    if(vIP_WIFI != "")
        cmd << "&mac_wifi=" << vMAC_WIFI;

    cmd << "'";

    if (verbose)
        std::cout << "Executing: " << cmd.str().c_str() << std::endl;

    system(cmd.str().c_str());

    return 0;
}
示例#30
0
/** 
 * @brief When timeout the Timer call this function.
 * 
 * @param timer The Navigate timer,watch the document load.
 * 
 * @return 
 */
NS_IMETHODIMP nsBrowserListener::Notify(nsITimer  *timer)
{
     LOG<<"timmer start:"<<running<<"count"<<timeCount<<"isScroll"<<isScrolled<<"\n";
     LOG<<"doc flag:"<<docStop<<" win flag"<<WinStop<<"\n";
     int breTime=(int)(interTime*(float)1000);
     if(running==NOT_RUN)
     {
	  if(brwStop)
	  {
	       LOG<<"stop browser set!\n";
	       timer->Cancel();
	       exit(1);
	  }else
	  {
	       if(docStop&&WinStop)
	       {
		    LOG<<"doc  fetched!\n";
		    if(scroolWait>0&&!isScrolled)
		    {
			 ScrollWin();
			 SetRunning(RUNNING);
			 isScrolled=true;
			 breTime=scroolWait*1000;
		    }else
		    {
			 //Init event stat.
			 SetEventWait(false);
			      
			 nsCOMPtr<nsIWebNavigation> nav = do_QueryInterface(mBro);
			 if(!browError)
			 {
			      //redirect the browser to the target
			      ReDirect(nav);
			      if(!isred)
			      {
				   Excute(nav);			      
			      }
			 }
			 //if the evenWait has set, do not change the web site.
			 if(evenWait||isred)
			 {
			      SetRunning(RUNNING);
			      breTime=1000;
			 }else
			 {
			      nsCString tmpUrl;
			      GetUrl(tmpUrl);
			      LOG<<tmpUrl.get()<<"\n";
			      
			      if(tmpUrl.Length()>0)
			      {
				   //init running stat and scrool stat.
				   SetRunning(RUNNING);
				   isScrolled=false;
				   //navigate the web site.
				   WebNav(nav,tmpUrl);
			      }else
			      {
				   StopBrows();
			      }
			 }
		    }    
	       }else
	       {
		    LOG<<"waite count set!\n";
		    if(timeCount>3)
		    {
			 docStop=true;
			 WinStop=true;
			 timeCount=0;
		    }else
		    {
			 timeCount++;
		    }
	       }
	  }
     }else
     {
	  LOG<<"set not run!\n";
	  timeCount=0;
	  SetRunning(NOT_RUN);
	  breTime=6000;
     }
     timeOut->Cancel();

     LOG<<"timmer stop:"<<running<<"inter time:"<<breTime<<"\n";
     timeOut->InitWithCallback(this, breTime, 0);


     return NS_OK;
}