コード例 #1
0
ファイル: Url.cpp プロジェクト: naveedasmat/haiku
BUrl::BUrl(const BUrl& base, const BString& location)
	:
	fUrlString(),
	fProtocol(),
	fUser(),
	fPassword(),
	fHost(),
	fPort(0),
	fPath(),
	fRequest(),
	fHasAuthority(false)
{
	// This implements the algorithm in RFC3986, Section 5.2.

	BUrl relative(location);
	if (relative.HasProtocol()) {
		SetProtocol(relative.Protocol());
		SetAuthority(relative.Authority());
		SetPath(relative.Path()); // TODO _RemoveDotSegments()
		SetRequest(relative.Request());
	} else {
		if (relative.HasAuthority()) {
			SetAuthority(relative.Authority());
			SetPath(relative.Path()); // TODO _RemoveDotSegments()
			SetRequest(relative.Request());
		} else {
			if (relative.Path().IsEmpty()) {
				SetPath(base.Path());
				if (relative.HasRequest())
					SetRequest(relative.Request());
				else
					SetRequest(Request());
			} else {
				if (relative.Path()[0] == '/')
					SetPath(relative.Path());
				else {
					BString path = base.Path();
					// Remove last part of path (the file, if any) so we get the
					// "current directory"
					path.Truncate(path.FindLast('/') + 1);
					path += relative.Path();
					// TODO _RemoveDotSegments()
					SetPath(path);
				}
				SetRequest(relative.Request());
			}
			SetAuthority(base.Authority());
		}
		SetProtocol(base.Protocol());
	}

	SetFragment(relative.Fragment());
}
コード例 #2
0
BNetworkCookieJar::UrlIterator::UrlIterator(const BNetworkCookieJar* cookieJar,
        const BUrl& url)
    :
    fCookieJar(const_cast<BNetworkCookieJar*>(cookieJar)),
    fIterator(NULL),
    fList(NULL),
    fLastList(NULL),
    fElement(NULL),
    fLastElement(NULL),
    fIndex(0),
    fLastIndex(0),
    fUrl(url)
{
    BString domain = url.Host();

    if (!domain.Length())
        return;

    fIterator = new(std::nothrow) PrivateIterator(
        fCookieJar->fCookieHashMap->fHashMap.GetIterator());

    if (fIterator != NULL) {
        // Prepending a dot since _FindNext is going to call _SupDomain()
        domain.Prepend(".");
        fIterator->fKey.SetTo(domain, domain.Length());
        _FindNext();
    }
}
コード例 #3
0
bool
BUrl::operator==(BUrl& other) const
{
	UrlString();
	other.UrlString();

	return fUrlString == other.fUrlString;
}
コード例 #4
0
ファイル: UrlContext.cpp プロジェクト: RAZVOR/haiku
void
BUrlContext::AddAuthentication(const BUrl& url,
	BHttpAuthentication* const authentication)
{
	BString domain = url.Host();
	domain += url.Path();
	BPrivate::HashString hostHash(domain.String(), domain.Length());

	BHttpAuthentication* previous = fAuthenticationMap->Get(hostHash);

	// Make sure we don't leak memory by overriding a previous
	// authentication for the same domain.
	if(authentication != previous) {
		fAuthenticationMap->Put(hostHash, authentication);
			// replaces the old one
		delete previous;
	}
}
コード例 #5
0
ファイル: NetworkCookieJar.cpp プロジェクト: AmirAbrams/haiku
BNetworkCookieJar::UrlIterator
BNetworkCookieJar::GetUrlIterator(const BUrl& url) const
{
	if (!url.HasPath()) {
		BUrl copy(url);
		copy.SetPath("/");
		return BNetworkCookieJar::UrlIterator(this, copy);
	}

	return BNetworkCookieJar::UrlIterator(this, url);
}
コード例 #6
0
BUrl::BUrl(const BUrl& base, const BString& location)
	:
	fUrlString(),
	fProtocol(),
	fUser(),
	fPassword(),
	fHost(),
	fPort(0),
	fPath(),
	fRequest(),
	fAuthorityValid(false),
	fUserInfoValid(false),
	fHasUserName(false),
	fHasPassword(false),
	fHasHost(false),
	fHasPort(false),
	fHasFragment(false)
{
	// This implements the algorithm in RFC3986, Section 5.2.

	BUrl relative(location);
	if (relative.HasProtocol()) {
		SetProtocol(relative.Protocol());
		if (relative.HasAuthority())
			SetAuthority(relative.Authority());
		SetPath(relative.Path());
		SetRequest(relative.Request());
	} else {
		if (relative.HasAuthority()) {
			SetAuthority(relative.Authority());
			SetPath(relative.Path());
			SetRequest(relative.Request());
		} else {
			if (relative.Path().IsEmpty()) {
				_SetPathUnsafe(base.Path());
				if (relative.HasRequest())
					SetRequest(relative.Request());
				else
					SetRequest(base.Request());
			} else {
				if (relative.Path()[0] == '/')
					SetPath(relative.Path());
				else {
					BString path = base._MergePath(relative.Path());
					SetPath(path);
				}
				SetRequest(relative.Request());
			}

			if (base.HasAuthority())
				SetAuthority(base.Authority());
		}
		SetProtocol(base.Protocol());
	}

	if (relative.HasFragment())
		SetFragment(relative.Fragment());
}
コード例 #7
0
status_t
BUrlRequest::SetUrl(const BUrl& url)
{
	fUrl = url;
	fResult.SetUrl(url);

	if (fUrlProtocol != NULL && url.Protocol() == fUrl.Protocol()) {
		fUrlProtocol->SetUrl(url);
		return B_OK;
	}

	fInitStatus = _SetupProtocol();
	return fInitStatus;
}
コード例 #8
0
ファイル: MediaPlay.cpp プロジェクト: looncraz/haiku
int media_play(const char* uri)
{
	BUrl url;
	entry_ref ref;
	BMediaFile* playFile;

	if (get_ref_for_path(uri, &ref) != B_OK) {
		url.SetUrlString(uri);
		if (url.IsValid()) {
			playFile = new BMediaFile(url);
		} else
			return 2;
	} else
		playFile = new BMediaFile(&ref);

	if (playFile->InitCheck() != B_OK) {
		delete playFile;
		return 2;
	}
	
	for (int i = 0; i < playFile->CountTracks(); i++) {
		BMediaTrack* track = playFile->TrackAt(i);
		playFormat.type = B_MEDIA_RAW_AUDIO;
		if ((track->DecodedFormat(&playFormat) == B_OK) 
				&& (playFormat.type == B_MEDIA_RAW_AUDIO)) {
			playTrack = track;
			break;
		}
		if (track)
			playFile->ReleaseTrack(track);
	}

	// Good relations with the Wookiees, I have. 
	signal(SIGINT, keyb_int);

	finished = create_sem(0, "finish wait");
	
	printf("Playing file...\n");
	
	// Execute Plan 66!
	player = new BSoundPlayer(&playFormat.u.raw_audio, "playfile", play_buffer);
	player->SetVolume(1.0f);

	// Join me, Padmé and together we can rule this galaxy. 
	player->SetHasData(true);
	player->Start();

	acquire_sem(finished);

	if (interrupt == true) {
		// Once more, the Sith will rule the galaxy. 
		printf("Interrupted\n");
		player->Stop();
		kill_thread(reader);
	}

	printf("Playback finished.\n");

	delete player;
	delete playFile;

	return 0;
}