Example #1
0
STDMETHODIMP 
CUpgradrToolbar::SetSite(IUnknown *pUnknownSite)
{
	DT(TRACE_I(FS(_T("Toolbar[%08X]: SetSite(%08X)"), this, pUnknownSite)));
	try {
		if (!!pUnknownSite)
		{
			// attach the window
			HWND hMyWindow;
			CComPtr<IUnknown> site(pUnknownSite);
			CComQIPtr<IOleWindow> window(site);
			window->GetWindow(&hMyWindow);
			if (!hMyWindow) 
			{
				TRACE_E(FS(_T("Toolbar[%08X]: Cannot retrieve toolbar base window"), this));
				return E_FAIL;
			}
			SubclassWindow(hMyWindow);

			// get a WebBrowser reference
			CComQIPtr<IServiceProvider> serviceProvider(site);
			serviceProvider->QueryService(IID_IWebBrowserApp, IID_IWebBrowser2, (void**)&m_spWebBrowser);
			site->QueryInterface(IID_IInputObjectSite, (void**)&m_spSite);

			// create main window
			CreateMainWindow();
		}
	}
	catch (CUpgradrRuntimeError &ex)
	{
		HandleError(ex.ErrorMessage());
		return E_FAIL;
	}
	return S_OK;
}
PtWidget_t *nsUnknownContentTypeHandler::GetWebBrowser(nsIDOMWindow *aWindow)
{
  nsCOMPtr<nsIWebBrowserChrome> chrome;
  PtWidget_t *val = 0;

  nsCOMPtr<nsIWindowWatcher> wwatch(do_GetService("@mozilla.org/embedcomp/window-watcher;1"));
  if (!wwatch) return nsnull;

  if( wwatch ) {
    nsCOMPtr<nsIDOMWindow> fosterParent;
    if (!aWindow) { // it will be a dependent window. try to find a foster parent.
      wwatch->GetActiveWindow(getter_AddRefs(fosterParent));
      aWindow = fosterParent;
    }
    wwatch->GetChromeForWindow(aWindow, getter_AddRefs(chrome));
  }

  if (chrome) {
    nsCOMPtr<nsIEmbeddingSiteWindow> site(do_QueryInterface(chrome));
    if (site) {
      site->GetSiteWindow(reinterpret_cast<void **>(&val));
    }
  }

  return val;
}
CWnd *
CPrintingPromptService::CWndForDOMWindow(nsIDOMWindow *aWindow)
{
  nsCOMPtr<nsIWebBrowserChrome> chrome;
  CWnd *val = 0;

  if (mWWatch) {
    nsCOMPtr<nsIDOMWindow> fosterParent;
    if (!aWindow) { // it will be a dependent window. try to find a foster parent.
      mWWatch->GetActiveWindow(getter_AddRefs(fosterParent));
      aWindow = fosterParent;
    }
    mWWatch->GetChromeForWindow(aWindow, getter_AddRefs(chrome));
  }

  if (chrome) {
    nsCOMPtr<nsIEmbeddingSiteWindow> site(do_QueryInterface(chrome));
    if (site) {
      HWND w;
      site->GetSiteWindow(reinterpret_cast<void **>(&w));
      val = CWnd::FromHandle(w);
    }
  }

  return val;
}
void TSpecifyPropertyPagesVE::show2configPages(const IID &iidD, IUnknown *deciD, const IID &iidE, IUnknown *deciE, int idCaption, int icon, int idff_multiplePages)
{
    comptrQ<ISpecifyPropertyPages> isppD = deciD;
    CAUUID pagesD;
    isppD->GetPages(&pagesD);

    comptrQ<ISpecifyPropertyPages> isppE = deciE;
    CAUUID pagesE;
    isppE->GetPages(&pagesE);

    comptrQ<IffdshowBase> deci = deciD;
    if (deci) {
        icon = deci->get_trayIconType();
    }

    HRESULT hr;
    TSpecifyPropertyPagesVE *isppVE = new TSpecifyPropertyPagesVE(NULL, &hr);
    isppVE->AddRef();
    isppVE->set(TpropertyPagesPair(iidD, isppD), TpropertyPagesPair(iidE, isppE));
    IUnknown *ifflist[] = {isppVE};
    CAUUID pages;
    pages.cElems = 2;
    pages.pElems = (GUID*)CoTaskMemAlloc(2 * sizeof(GUID));
    pages.pElems[0] = pagesD.pElems[0];
    pages.pElems[1] = pagesE.pElems[0];
    TpageSite site(idff_multiplePages);
    comptrQ<IffdshowBase> deciDB = deciD;
    site.show(deciDB, NULL, idCaption, icon, pages, isppVE);
    isppVE->Release();
    CoTaskMemFree(pagesD.pElems);
    CoTaskMemFree(pagesE.pElems);
}
Example #5
0
void RequestSuite::TestMultilineHeaders() {
	SiteOptions so;
	so.SetPort(50);

	Site site(&so);
	const int NR = 2;

	const char
			*getstring[NR] =
					{
							"GET /good.html HTTP/1.1\r\nHost: keep-alive\r\nMyHeader: apa\r\n Gnu\r\n\r\n",
							"GET /good.html HTTP/1.1\r\nHost: keep-alive\r\nMyHeader: apa\r\n Gnu\r\n Gnu2\r\n\r\n", };

	ByteBuffer* buf = new ByteBuffer(2000);
	for (int i = 0; i < NR; i++) {
		Request *r = new Request(NULL, &site);
		buf->Clear();
		buf->Add(getstring[i], strlen(getstring[i]));
		bool result = Request::ParseRequest(r, buf);
		TEST_ASSERT(result==true);
		TEST_ASSERT(r->GetStatus() == Http::HTTP_OK);
		delete r;
	}
	delete buf;

}
Example #6
0
SiteList readSites(std::ifstream& ifs, double SF, double wc, double wt, double wv)
{
  SiteList sites;
  std::string line;
  while (std::getline(ifs, line)) {
    std::istringstream iss(line);
    std::string type;
    long id;
    double  lat, lon;
    iss >> id;
    iss >> lon;
    iss >> lat;
    iss >> type;
    double weight = 0;
    if (type == "city") {
      weight = wc;
    } else if (type == "town") {
      weight = wt;
    } else if (type == "village") {
      weight = wv;
    }
    Site_2 site(Point_2(lon*SF, lat*SF), weight*SF, id);
    sites.push_back(site);
  }
  return sites;
}
Example #7
0
void RequestSuite::TestEvilRequests() {
	SiteOptions so;
	so.SetPort(50);

	Site site(&so);
	const int NR = 3;

	const char
			*getstring[NR] =
					{
							",                                                                                          \r\n",
							"\r\n\r\n\r\n", "\0" };

	ByteBuffer* buf = new ByteBuffer(2000);
	for (int i = 0; i < NR; i++) {
		Request *r = new Request(NULL, &site);
		buf->Clear();
		buf->Add(getstring[i], strlen(getstring[i]));
		bool result = Request::ParseRequest(r, buf);
		TEST_ASSERT(result==false);
		TEST_ASSERT(r->GetStatus() != Http::HTTP_OK);
		delete r;
	}
	delete buf;

}
Example #8
0
void RSSEditPopup::ParseAndSave(void)
{
    if (m_editing)
    {
        QString title = m_titleEdit->GetText();
        QString desc = m_descEdit->GetText();
        QString author = m_authorEdit->GetText();
        QString link = m_urlEdit->GetText();
        QString filename = m_thumbImage->GetFilename();

        bool download;
        if (m_download->GetCheckState() == MythUIStateType::Full)
            download = true;
        else
            download = false;

        removeFromDB(m_urlText, VIDEO_PODCAST);

        RSSSite site(title, filename, VIDEO_PODCAST,
                     desc, link, author, download, MythDate::current());
        if (insertInDB(&site))
            emit Saving();
        Close();
    }
    else
    {
        m_manager = new QNetworkAccessManager();
        QUrl qurl(m_urlEdit->GetText());

        m_reply = m_manager->get(QNetworkRequest(qurl));

        connect(m_manager, SIGNAL(finished(QNetworkReply*)), this,
                           SLOT(SlotCheckRedirect(QNetworkReply*)));
    }
}
Example #9
0
void Debugger::InterruptWithUrl(int type, const char *url) {
  // Build a site to represent the URL. Note it won't have any source info
  // in it, because this event is raised with no PHP on the stack.
  InterruptSite site(false, null_variant);
  site.url() = url ? url : "";
  Interrupt(type, url, &site);
}
Example #10
0
static int
migratepid(pit_t pid, siteno_t new_site)
{
    struct sf *st;
    int     need_local;

    need_local = (pid == 0) || (pid == getpid());

    if (kill3(pid, SIGMIGRATE, new_site) < 0) {
	xprintf("%d: %s\n", pid, strerror(errno));
	return (-1);
    }

    if (need_local) {
	if ((new_site = site(0)) == -1) {
	    xprintf(CGETS(23, 4, "site: %s\n"), strerror(errno));
	    return (-1);
	}
	if ((st = sfnum(new_site)) == NULL) {
	    xprintf(CGETS(23, 5, "%d: Site not found\n"), new_site);
	    return (-1);
	}
	if (setlocal(st->sf_local, strlen(st->sf_local)) == -1) {
	    xprintf(CGETS(23, 6, "setlocal: %s: %s\n"),
			  st->sf_local, strerror(errno));
	    return (-1);
	}
    }
    return (0);
}
Example #11
0
double ATCProfileSpeed::interpolate(ATCInterpolator &interpolator, double lvl)
{
    QVector<double> site(1, lvl);
    QVector<double> result(1);

    interpolator.interpolate(site, result);
    return result.at(0);
}
Example #12
0
void Debugger::InterruptVMHook(int type /* = BreakPointReached */,
                               CVarRef e /* = null_variant */) {
  const_assert(hhvm);
  InterruptSiteVM site(type == HardBreakPoint, e);
  if (!site.valid()) {
    return;
  }
  Interrupt(type, NULL, &site);
}
Example #13
0
/* sitename():
 *	Return the site name where the process is running
 */
char   *
sitename(pid_t pid)
{
    siteno_t ss;
    struct sf *st;

    if ((ss = site(pid)) == -1 || (st = sfnum(ss)) == NULL)
	return CGETS(23, 3, "unknown");
    else
	return st->sf_sname;
}
Example #14
0
// Primary entrypoint from the set of "debugger hooks", which the VM calls in
// response to various events. While this function is quite general wrt. the
// type of interrupt, practically the type will be one of the following:
//   - ExceptionThrown
//   - ExceptionHandler
//   - BreakPointReached
//   - HardBreakPoint
//
// Note: it is indeed a bit odd that interrupts due to single stepping come in
// as "BreakPointReached". Currently this results in spurious work in the
// debugger.
void Debugger::InterruptVMHook(int type /* = BreakPointReached */,
                               CVarRef e /* = null_variant */) {
  TRACE(2, "Debugger::InterruptVMHook\n");
  // Computing the interrupt site here pulls in more data from the Unit to
  // describe the current execution point.
  InterruptSite site(type == HardBreakPoint, e);
  if (!site.valid()) {
    // An invalid site is missing something like an ActRec, a func, or a
    // Unit. Currently the debugger has no action to take at such sites.
    return;
  }
  Interrupt(type, nullptr, &site);
}
Example #15
0
bool Debugger::InterruptException(CVarRef e) {
  if (RuntimeOption::EnableDebugger) {
    ThreadInfo *ti = ThreadInfo::s_threadInfo.get();
    if (ti->m_top && ti->m_reqInjectionData.debugger) {
      Eval::InterruptSite site(ti->m_top, e);
      Eval::Debugger::Interrupt(ExceptionThrown, NULL, &site);
      if (site.isJumping()) {
        return false;
      }
    }
  }
  return true;
}
//-----------------------------------------------------------
HWND
nsPrintingPromptService::GetHWNDForDOMWindow(nsIDOMWindow *aWindow)
{
    nsCOMPtr<nsIWebBrowserChrome> chrome;
    HWND hWnd = NULL;

    // We might be embedded so check this path first
    if (mWatcher) {
        nsCOMPtr<nsIDOMWindow> fosterParent;
        if (!aWindow) 
        {   // it will be a dependent window. try to find a foster parent.
            mWatcher->GetActiveWindow(getter_AddRefs(fosterParent));
            aWindow = fosterParent;
        }
        mWatcher->GetChromeForWindow(aWindow, getter_AddRefs(chrome));
    }

    if (chrome) {
        nsCOMPtr<nsIEmbeddingSiteWindow> site(do_QueryInterface(chrome));
        if (site) 
        {
            HWND w;
            site->GetSiteWindow(reinterpret_cast<void **>(&w));
            return w;
        }
    }

    // Now we might be the Browser so check this path
    nsCOMPtr<nsPIDOMWindow> window(do_QueryInterface(aWindow));

    nsCOMPtr<nsIDocShellTreeItem> treeItem =
        do_QueryInterface(window->GetDocShell());
    if (!treeItem) return nullptr;

    nsCOMPtr<nsIDocShellTreeOwner> treeOwner;
    treeItem->GetTreeOwner(getter_AddRefs(treeOwner));
    if (!treeOwner) return nullptr;

    nsCOMPtr<nsIWebBrowserChrome> webBrowserChrome(do_GetInterface(treeOwner));
    if (!webBrowserChrome) return nullptr;

    nsCOMPtr<nsIBaseWindow> baseWin(do_QueryInterface(webBrowserChrome));
    if (!baseWin) return nullptr;

    nsCOMPtr<nsIWidget> widget;
    baseWin->GetMainWidget(getter_AddRefs(widget));
    if (!widget) return nullptr;

    return (HWND)widget->GetNativeData(NS_NATIVE_TMP_WINDOW);

}
Example #17
0
STDMETHODIMP 
CXRefreshToolbar::SetSite(IUnknown *pUnknownSite)
{
	DT(TRACE_I(FS(_T("Toolbar[%08X]: SetSite(%08X)"), this, pUnknownSite)));
	try {
		if (!!pUnknownSite)
		{
			// attach the window
			HWND hWnd;
			CComPtr<IUnknown> site(pUnknownSite);
			CComQIPtr<IOleWindow> window(site);
			window->GetWindow(&hWnd);
			if (!hWnd) 
			{
				TRACE_E(FS(_T("Toolbar[%08X]: Cannot retrieve toolbar base window"), this));
				return E_FAIL;
			}
			SubclassWindow(hWnd);

			// get a WebBrowser reference
			CComQIPtr<IServiceProvider> serviceProvider(site);
			serviceProvider->QueryService(IID_IWebBrowserApp, IID_IWebBrowser2, (void**)&m_Browser);
			site->QueryInterface(IID_IInputObjectSite, (void**)&m_Site);

			// retrive browser id
			{
				BrowserManagerLock browserManager;
				m_BrowserId = browserManager->AllocBrowserId(m_Browser, this);
				ATLASSERT(m_BrowserId!=NULL_BROWSER);
			}

			// create main window
			CreateMainWindow();
		}
		else
		{
			BrowserManagerLock browserManager;
			CBrowserMessageWindow* bw = browserManager->FindBrowserMessageWindow(m_BrowserId);
			ATLASSERT(bw);
			bw->SetToolbar(NULL);
			browserManager->ReleaseBrowserId(m_BrowserId);
			m_BrowserId = NULL_BROWSER;
		}
	}
	catch (CXRefreshRuntimeError &ex)
	{
		HandleError(ex.ErrorMessage());
		return E_FAIL;
	}
	return S_OK;
}
Example #18
0
void RequestSuite::TestReqeustsByteForByte() {

	SiteOptions so;
	so.SetPort(50);

	Site site(&so);
	const int NR = 11;

	const char
			*getstring[NR] =
					{
							"GET / HTTP/1.0\r\n\r\n",
							"GET /good.html HTTP/1.1\r\nConnection: keep-alive\r\nHost: \t   localhost:80\r\n\r\n",
							"GET /good.html HTTP/1.1\r\nConnection: close\r\nHost:    localhost:81\r\n\r\n",
							"GET /good.html HTTP/1.0\r\nConnection: keep-alive\r\n\r\n",
							"GET /good.html HTTP/1.0\r\nConnection: close\r\n\r\n",
							"GET /good.html HTTP/1.0\r\n\r\n",
							"GET / HTTP/1.1\r\nHost: localhost:8080\r\n\r\n",
							"GET /last.html HTTP/1.0\r\nHost: localhost:8080\r\n\r\n",
							"GET /last.html HTTP/1.0\r\n\r\n",
							"GET /last.html HTTP/1.1\r\nHost: localhost:8080\r\nConnection:        \t close\r\n\r\n",
							"GET /last.html HTTP/1.0\r\nConnection:        \t close\r\n\r\n" };

	ByteBuffer* buf = new ByteBuffer(2000);
	for (int i = 0; i < NR; i++) {
		Request *r = new Request(NULL, &site);
		buf->Clear();
		size_t len=strlen(getstring[i]);
		for (size_t j=0;j<len;j++)
		{
			buf->Add(getstring[i]+j, 1);
			bool result = Request::ParseRequest(r, buf);
			if (j+1<len)
			{
				TEST_ASSERT_MSG(result==false,getstring[i]);
			}
			else
			{
				TEST_ASSERT_MSG(result,getstring[i]);
				TEST_ASSERT_MSG(r->GetStatus() == Http::HTTP_OK,getstring[i]);
			}
		}
		delete r;
	}
	delete buf;
}
void Field<FieldType>::updateHalo()
{
	
	Site site(*lattice_);
	int copyfrom;
	
	int  dim=lattice_->dim();
	int* jump=new int[dim];
	int* size=new int[dim];
	
	for(int i=0; i<dim; i++)
	{
		jump[i]=lattice_->jump(i);
		size[i]=lattice_->sizeLocal(i);
	}
	
	for(site.haloFirst(); site.haloTest(); site.haloNext())
	{
		//Work out where to copy from
		copyfrom=site.index();
		for(int i=0; i<dim; i++)
		{
			if( site.coordLocal(i)<0 )
			{
				copyfrom += jump[i] * size[i];
			}
			else if( site.coordLocal(i) >= size[i] )
			{
				copyfrom -= jump[i] * size[i];
			}
		}
		//Copy data
		for(int i=0; i<components_; i++)
		{
			data_[site.index()*components_+i] = data_[copyfrom*components_+i]; 
			//memcpy(data_[site.index()*components_+i],data_[copyfrom*components_+i],sizeof_fieldType_);
		
		}
	}
	
	delete[] jump;
	delete[] size;
	
	if( parallel.size()>1 ) { updateHaloComms(); }
}
Example #20
0
double ATCAbstractProfile::mixedInterval(ATCInterpolator2D &interpolator, ATCInterpolator2D &inverseInterpolator, double key, double lvlFrom, double interval)
{
    //Calculate quantity X from initial level using standard interpolator
    QVector<double> site(1, lvlFrom);
    QVector<double> result(1);
    interpolator.interpolate(key, site, result);

    //Update quantity X for final level using input interval
    double finalX = interval + result.at(0);

    //Calculate final level using updated quantity X
    QVector<double> finalSite(1, finalX);
    QVector<double> finalResult(1);
    inverseInterpolator.interpolate(key, finalSite, finalResult);

    //Return calculated level
    return finalResult.at(0);
}
Example #21
0
STDMETHODIMP 
CUpgradrHelperbar::SetSite(IUnknown *pUnknownSite)
{
	DT(TRACE_I(FS(_T("Helperbar[%08X]: SetSite(%08X)"), this, pUnknownSite)));
	
	if (!!pUnknownSite)
	{
		// get a WebBrowser reference
		CComPtr<IUnknown> site(pUnknownSite);
		CComQIPtr<IServiceProvider> serviceProvider(site);
		serviceProvider->QueryService(IID_IWebBrowserApp, IID_IWebBrowser2, (void**)&m_Browser);
		site->QueryInterface(IID_IInputObjectSite, (void**)&m_Site);

		// retrive browser id
		{
			BrowserManagerLock browserManager;
			m_BrowserId = browserManager->AllocBrowserId(m_Browser, this);
			ATLASSERT(m_BrowserId!=NULL_BROWSER);
		}

		// attach the window
		HWND hHelperbarWindow;
		CComQIPtr<IOleWindow> window(site);
		window->GetWindow(&hHelperbarWindow);
		if (!hHelperbarWindow) 
		{
			TRACE_E(FS(_T("Helperbar[%08X]: Cannot retrieve helpbar base window"), this));
			return E_FAIL;
		}
		SubclassWindow(hHelperbarWindow);

		// create main window
		CreateMainWindow();
	}
	else
	{
		BrowserManagerLock browserManager;
		browserManager->ReleaseBrowserId(m_BrowserId);
		m_BrowserId = NULL_BROWSER;
	}

	return S_OK;
}
Example #22
0
QVector<double> ATCAbstractProfile::mixedInterval(ATCInterpolator2D &interpolator, ATCInterpolator2D &inverseInterpolator, double key, double lvlFrom, QVector<double> &intervals)
{
    //Calculate quantity X from initial level using standard interpolator
    QVector<double> site(1, lvlFrom);
    QVector<double> result(1);
    interpolator.interpolate(key, site, result);

    //Update quantity X for final level using input interval
    for(int i = 0; i < intervals.size(); i++)
    {
        intervals.replace(i, intervals.at(i) + result.at(0));
    }

    //Calculate final level using updated quantity X
    QVector<double> finalResults(intervals.size());
    inverseInterpolator.interpolate(key, intervals, finalResults);

    //Return calculated level
    return finalResults;
}
Example #23
0
void RequestSuite::TestRequestConnectionKeepAlive() {
	SiteOptions so;
	so.SetPort(50);

	Site site(&so);

	const int NR = 6;
	const char
			*gs[] =
					{
							"GET /good.html HTTP/1.1\r\nConnection: keep-alive\r\nHost: localhost:8080\r\n\r\n",
							"GET /good.html HTTP/1.1\r\nConnection: close\r\nHost: localhost:8080\r\n\r\n",
							"GET /good.html HTTP/1.1\r\nHost: localhost:8080\r\n\r\n",
							"GET /good.html HTTP/1.0\r\nConnection:   \t keep-alive\r\n\r\n",
							"GET /good.html HTTP/1.0\r\nConnection: close\r\n\r\n",
							"GET /good.html HTTP/1.0\r\n\r\n" };

	typedef struct {
		const char * getstring;
		bool keepalive;
	} test_data_t;

	test_data_t data[NR] = { { gs[0], true }, { gs[1], false },
			{ gs[2], true }, { gs[3], true }, { gs[4], false },
			{ gs[5], false } };

	ByteBuffer* buf = new ByteBuffer(2000);
	for (int i = 0; i < NR; i++) {
		Request *r = new Request(NULL, &site);

		buf->Clear();
		buf->Add(data[i].getstring, strlen(data[i].getstring));
		bool result = Request::ParseRequest(r, buf);
		TEST_ASSERT(r->GetStatus() == Http::HTTP_OK);
		TEST_ASSERT(r->GetKeepAlive() == data[i].keepalive);
		delete r;
	}
	delete buf;
}
Example #24
0
void RequestSuite::TestMandatoryHeaderMissing() {
	SiteOptions so;
	so.SetPort(50);

	Site site(&so);
	const int NR = 1;

	const char *getstring[NR] = {
			"GET /good.html HTTP/1.1\r\nConnection: keep-alive\r\n\r\n", };

	ByteBuffer* buf = new ByteBuffer(2000);
	for (int i = 0; i < NR; i++) {
		Request *r = new Request(NULL, &site);
		buf->Clear();
		buf->Add(getstring[i], strlen(getstring[i]));
		bool result = Request::ParseRequest(r, buf);
		TEST_ASSERT(result==true);
		TEST_ASSERT(r->GetStatus() == Http::HTTP_BAD_REQUEST);
		delete r;
	}
	delete buf;

}
Example #25
0
void RequestSuite::TestManyGoodGets() {

	SiteOptions so;
	so.SetPort(50);

	Site site(&so);
	const int NR = 13;

	const char
			*getstring[NR] =
					{
							"GET /good.html HTTP/1.1\r\nConnection: keep-alive\r\nHost: \t   localhost:80\r\n\r\n",
							"GET /good.html HTTP/1.1\r\nConnection: close\r\nHost:    localhost:81\r\n\r\n",
							"GET /good.html HTTP/1.0\r\nConnection: keep-alive\r\n\r\n",
							"GET /good.html HTTP/1.0\r\nConnection: close\r\n\r\n",
							"GET /good.html HTTP/1.0\r\n\r\n",
							"GET /good.html HTTP/1.0\r\n\r\n",
							"GET / HTTP/1.1\r\nHost: localhost:8080\r\n\r\n",
							"GET / HTTP/1.0\r\n\r\n",
							"GET /last.html HTTP/1.0\r\nHost: localhost:8080\r\n\r\n",
							"GET /last.html HTTP/1.0\r\n\r\n",
							"GET /last.html HTTP/1.0\r\n\r\n",
							"GET /last.html HTTP/1.1\r\nHost: localhost:8080\r\nConnection:        \t close\r\n\r\n",
							"GET /last.html HTTP/1.0\r\nConnection:        \t close\r\n\r\n" };

	ByteBuffer* buf = new ByteBuffer(2000);
	for (int i = 0; i < NR; i++) {
		Request *r = new Request(NULL, &site);
		buf->Clear();
		buf->Add(getstring[i], strlen(getstring[i]));
		bool result = Request::ParseRequest(r, buf);
		TEST_ASSERT(result);
		TEST_ASSERT(r->GetStatus() == Http::HTTP_OK);
		delete r;
	}
	delete buf;
}
// Definition of stringsearch() function
void session::stringsearch(){

	// Whole body is in loop
	// Loop ends if the list is empty or a certain number of urls have been parsed
	do{

		// File that stores source code of URLs
		std::ofstream FILE("source.txt");

		std::ofstream wordfile("index.txt", std::ios::app|std::ios::out);

		// Object of url class created
		url u(list.front());

		// Object of Http class (found in SFML) created
		// Http class only takes host names as input, so host name passed
		sf::Http site(u.host());

		//Generate the request, i.e the path within the webpage
		sf::Http::Request request(u.path());

		// Send the request to generate a response
		sf::Http::Response response = site.sendRequest(request);

		// Check the status code and display the result
		sf::Http::Response::Status status = response.getStatus();
		if (status == sf::Http::Response::Ok){
			FILE << response.getBody() << std::endl;
		}
		else{
			std::cout << "Error " << status << std::endl;
			std::cout << "Skipping webpage. " << std::endl;
			list.pop();
			continue;
		}
		FILE.close();

		std::cout << "Popping URL: " << list.front() << std::endl << std::endl;
		Sleep(1000);

		// Condition check to see if file is of html format
		if (check_html() == false){
			std::cout << "\nWebpage not in html format. Skipping... " << std::endl << std::endl;
			list.pop();
			continue;
		}

		// Condition check to ensure URL hasn't been crawled previously. First URL is skipped
		if (count > 1 && check_urls(list.front()) == true){
			std::cout << "\nWebpage has already been crawled. Skipping...\n\n";
			list.pop();
			continue;
		}

		// Opens file for reading
		std::ifstream file("source.txt");

		std::string s1; // String stores lines from html file
		std::string s2 = "href=\""; // Reference string to locate hyperlinks
		char s3[300]; // C string variable to store hyperlink URLs

		// Condition check to ensure file is open
		if (file.is_open()){

			do{
				// Both string storage variables initialised to null
				s1 = "";

				std::getline(file, s1); // Gets line by line information from the page source
				
				std::size_t location = s1.find(s2); // Variable to point to location in string

				int i = 0;
				// Check to see if location is within string, i.e the desired element has been found
				if (location != std::string::npos){
					std::cout << "Hyperlink found: ";

					// Location set to first element of hyperlink
					// Adding 6 accounts for the 6 tag characters, i.e href"
					std::size_t x = location + 6;

					// Loop adds characters to array until quotation mark is reached
					while (s1.at(x) != '\"'){
						s3[i] = s1.at(x);
						x++;
						i++;
					}

					// Last character set to termination character
					s3[i] = '\0';

					std::string s4 = s3; // Converts C string to std::string

					std::cout << s4 << std::endl;

					// Creates url object that takes s4 as constructor argument
					url u2(s4);

					// Condition check to see if hyperlink has a host
					// If it doesn't, it means it is an extension of the current webpage
					// So current webpage is appended to it
					if (u2.host() == ""){
						s4 = u.protocol() + "://" + u.host() + s4;
					}

					std::cout << "Adding URL to queue..." << std::endl;

					// Hyperlink is added to queue
					list.push(s4);

					std::cout << s4 << std::endl << std::endl;
				}

				if (wordfile.is_open()){
					std::string word = "Boost";

					std::size_t point = s1.find(word);
					
					if (point != std::string::npos){

				//		while ()

						wordfile << list.front() << std::endl;
						wordfile << word << std::endl;
					}
				//	else{
					//	std::cout << "word not found" << std::endl;
						//std::cout << "\n";
				//	}
				}
				else{
					std::cout << "index could not be opened" << std::endl;
				}

			} while (!file.eof());

			// Adds current webpage to list of URLs parsed
			urls_parsed(list.front());
			
			// Removes current webpage from queue
			list.pop();
			file.close();
			wordfile.close();

			std::cout << "\n\nCount: " << count << std::endl;
			count++;

			Sleep(1000);			
		}
		else{
			std::cout << "Error in opening file" << std::endl;
			exit(-1);
		}
		//Sleep(1000);
	} while (count <= 10 && list.empty() == false);
	remove("source.txt");
	remove("urls.txt");

	return;
}
Example #27
0
/*
  ClimateZone ClimateZones_Impl::activeClimateZone() const {
    std::string activeInstitution = getString(OS_ClimateZonesFields::ActiveInstitution,true).get();
    unsigned activeYear = getUnsigned(OS_ClimateZonesFields::ActiveYear,true).get();
    return getClimateZone(activeInstitution,activeYear);
  }

  std::string ClimateZones_Impl::activeClimateZoneValue() const {
    std::string result;
    ClimateZone cz = activeClimateZone();
    if (!cz.empty()) { result = cz.value(); }
    return result;
  }
*/
  boost::optional<ParentObject> ClimateZones_Impl::parent() const {
    OptionalParentObject result;
    OptionalSite oSite = site();
    if (oSite) { result = oSite->optionalCast<ParentObject>(); }
    return result;
  }
Example #28
0
SCENARIO("db::get_collection") {
    GIVEN("a single id relation (site)") {
        hades::connection conn = hades::connection::in_memory_database();

        hades::devoid(
                "CREATE TABLE site ( "
                " site_id INTEGER PRIMARY KEY AUTOINCREMENT, "
                " name VARCHAR DEFAULT 'name_value' "
                " )",
                hades::empty_row(),
                conn
                );

        WHEN("one tuple is inserted") {
            hades::devoid(
                    "INSERT INTO site DEFAULT VALUES",
                    hades::empty_row(),
                    conn
                    );

            THEN("get_collection returns the tuple") {
                styx::list list = hades::get_collection<site>(conn);
                REQUIRE(list.size() == 1);
                REQUIRE(site(list[0]).site_id() == 1);
                REQUIRE(site(list[0]).name() == "name_value");
            }
        }
    }
}

Example #29
0
Species format_species(const Species& sp)
{
    unit_species_comparerator comp(sp);
    std::vector<unit_species_comparerator::index_type> units;
    for (unit_species_comparerator::index_type i(0); i < sp.num_units(); ++i)
    {
        units.push_back(i);
    }

    std::sort(units.begin(), units.end(), comp);

    std::vector<unit_species_comparerator::index_type>
        next(sp.num_units(), sp.num_units());
    unsigned int stride(0);
    for (unit_species_comparerator::index_type i(0); i < sp.num_units(); ++i)
    {
        const unit_species_comparerator::index_type idx(units[i]);
        comp.reorder_units(next, idx, stride);
    }
    for (unsigned int i(0); i < sp.num_units(); ++i)
    {
        units[next[i]] = i;
    }

    Species newsp;
    utils::get_mapper_mf<std::string, std::string>::type cache;
    stride = 1;
    std::stringstream ss;
    for (std::vector<unit_species_comparerator::index_type>::const_iterator
        i(units.begin()); i != units.end(); ++i)
    {
        UnitSpecies usp(sp.at(*i));
        for (UnitSpecies::container_type::size_type j(0);
            j < static_cast<UnitSpecies::container_type::size_type>(usp.num_sites()); ++j)
        {
            UnitSpecies::container_type::value_type& site(usp.at(j));
            if (site.second.second == "" || is_wildcard(site.second.second))
            {
                continue;
            }

            utils::get_mapper_mf<std::string, std::string>::type::const_iterator
                it(cache.find(site.second.second));
            if (it == cache.end())
            {
                ss << stride;
                cache.insert(std::make_pair(site.second.second, ss.str()));
                site.second.second = ss.str();
                ++stride;
                ss.clear();
                ss.str("");
            }
            else
            {
                site.second.second = (*it).second;
            }
        }
        newsp.add_unit(usp);
    }
    return newsp;
}
Example #30
0
void RSSEditPopup::SlotSave(QNetworkReply* reply)
{
    QDomDocument document;
    document.setContent(reply->read(reply->bytesAvailable()), true);

    QString text = document.toString();

    QString title = m_titleEdit->GetText();
    QString description = m_descEdit->GetText();
    QString author = m_authorEdit->GetText();
    QString file = m_thumbImage->GetFilename();

    LOG(VB_GENERAL, LOG_DEBUG, QString("Text to Parse: %1").arg(text));

    QDomElement root = document.documentElement();
    QDomElement channel = root.firstChildElement ("channel");
    if (!channel.isNull())
    {
        Parse parser;
        if (title.isEmpty())
            title = channel.firstChildElement("title").text().trimmed();
        if (description.isEmpty())
            description = channel.firstChildElement("description").text();
        if (author.isEmpty())
            author = parser.GetAuthor(channel);
        if (author.isEmpty())
            author = channel.firstChildElement("managingEditor").text();
        if (author.isEmpty())
            author = channel.firstChildElement("webMaster").text();

        QString thumbnailURL =
            channel.firstChildElement("image").attribute("url");
        if (thumbnailURL.isEmpty())
        {
            QDomElement thumbElem = channel.firstChildElement("image");
            if (!thumbElem.isNull())
                thumbnailURL = thumbElem.firstChildElement("url").text();
        }
        if (thumbnailURL.isEmpty())
        {
            QDomNodeList nodes = channel.elementsByTagNameNS(
                           "http://www.itunes.com/dtds/podcast-1.0.dtd",
                           "image");
            if (nodes.size())
            {
                thumbnailURL =
                    nodes.at(0).toElement().attributeNode("href").value();
                if (thumbnailURL.isEmpty())
                    thumbnailURL = nodes.at(0).toElement().text();
            }
        }

        bool download;
        if (m_download->GetCheckState() == MythUIStateType::Full)
            download = true;
        else
            download = false;

        QDateTime updated = MythDate::current();
        QString filename("");

        if (!file.isEmpty())
            filename = file;
        else if (!thumbnailURL.isEmpty())
            filename = thumbnailURL;

        QString link = m_urlEdit->GetText();

        RSSSite site(title, filename, VIDEO_PODCAST, description, link,
                     author, download, MythDate::current());
        if (insertInDB(&site))
            emit Saving();
    }

    Close();
}