Exemple #1
0
/*!	Tests whether this and the supplied BNode object are equal.
	Two BNode objects are said to be equal if they're set to the same node,
	or if they're both \c B_NO_INIT.
	\param node the BNode to be compared with
	\return \c true, if the BNode objects are equal, \c false otherwise
*/
bool
BNode::operator==(const BNode &node) const
{
	if (fCStatus == B_NO_INIT && node.InitCheck() == B_NO_INIT)
		return true;		
	if (fCStatus == B_OK && node.InitCheck() == B_OK) {
		// Check if they're identical
		BPrivate::Storage::Stat s1, s2;
		if (GetStat(&s1) != B_OK)
			return false;
		if (node.GetStat(&s2) != B_OK)
			return false;
		return (s1.st_dev == s2.st_dev && s1.st_ino == s2.st_ino);
	}	
	return false;	
}
Exemple #2
0
/*!	Tests whether this and the supplied BNode object are equal.
	Two BNode objects are said to be equal if they're set to the same node,
	or if they're both \c B_NO_INIT.
	\param node the BNode to be compared with
	\return \c true, if the BNode objects are equal, \c false otherwise
*/
bool
BNode::operator==(const BNode &node) const
{
	if (fCStatus == B_NO_INIT && node.InitCheck() == B_NO_INIT)
		return true;		
	if (fCStatus == B_OK && node.InitCheck() == B_OK) {
		// compare the node_refs
		node_ref ref1, ref2;
		if (GetNodeRef(&ref1) != B_OK)
			return false;
		if (node.GetNodeRef(&ref2) != B_OK)
			return false;
		return (ref1 == ref2);
	}	
	return false;	
}
status_t HModuleRoster::HandleRequest( RequestPB *pb )
{
	BEntry		entry;
	BNode		node;
	BNodeInfo	info;
	char		mimeType[128], vmimeType[128];
	status_t 	status = B_OK;
	int32		parentCount = 0;
	BPath 		absPath, resourcePath( "/" );
	resourcePath.Append( pb->brURI->path );
	pb->resourcePath = &resourcePath;
	pb->mimeType = mimeType;
	
	
	// fix for "hostname//" request crash
	// wade majors <[email protected] - Mar-09-2001
    if (resourcePath.Path() == NULL)
    {
      resourcePath.SetTo("null");
      pb->resourcePath = &resourcePath;
    }
    //
	
	
	VResource	*vres = NULL;
		
	// *****
	// Look for "real" resource
	// *****
	do
	{
		// Small optimization... if not done, the path normalizer will 
		// be tickled when a resource does not exit
		if( (resourcePath.Path())[1] == 0 )
		{
			status = B_ERROR;
			break;
		}
		absPath.SetTo( pb->webDirectory->Path(), resourcePath.Path()+1 );

		if( (entry.SetTo( absPath.Path(), true ) == B_OK)&&(node.SetTo( &entry ) == B_OK)
		&&(info.SetTo( &node ) == B_OK) )
		{
			const char *resMIME;
			
			// Cheap hack for directories without a MIME type
			if(info.GetType( mimeType ) != B_OK)
				strcpy( mimeType, "application/x-vnd.Be-directory" );
				
			if( (resMIME = pb->vresources->MatchVRes( pb->brURI->path, true, &vres )) )
				strcpy( vmimeType, resMIME );
			else
				strcpy( vmimeType, mimeType );
			break;
		}
		parentCount++;
		
	}while( (status = resourcePath.GetParent( &resourcePath )) == B_OK );
	entry.Unset();
	if( node.InitCheck() )
		node.Unset();
	// *****
	// Look for Virtual Resource if no "real" resource was found.
	// *****
	
	if( (status != B_OK)||((parentCount != 0)&&(strcmp(mimeType, "application/x-vnd.Be-directory") == 0)) )
	{
		const char *resMIME;
		if( (resMIME = pb->vresources->MatchVRes( pb->brURI->path, false, &vres )) )
		{
			strcpy( vmimeType, resMIME );
			strcpy( mimeType, resMIME );
		}
		else
		{
			HTTPResponse	response;
			response.SetHTMLMessage( 404 ); // Not Found
			pb->request->SendReply( &response );
			return B_ERROR;
		}
	}
	
	// *****
	// Find handler module for resource
	// *****
	
	HModule		*module, *prefModule = NULL;
	int32		priority, highestPriority = 0;
	for( int32 i=0; (module = (HModule *)moduleList.ItemAt(i)); i++ )
	{
		if( module->CanHandleResource( vmimeType, pb->request->GetMethod(), &priority )&&
			(priority > highestPriority) )
		{
			highestPriority = priority;
			prefModule = module;
		}
	}
	
	// *****
	// Setup PB
	// *****
	pb->HandleRequest = HModuleRoster::HandleRequest;
	pb->Logprintf = log_printf;
	pb->moduleList = &moduleList;
	if( vres )
	{
		pb->authenticate = vres->Authenticate();
		pb->extras = &vres->extras;
	}
	else
		pb->extras = NULL;
	
	// *****
	// Invoke Handler Module to handle the request
	// *****
	if( highestPriority > 0 )
	{
		status = prefModule->HandleRequest( pb );
		return status;
	}
	else // No handler found... send error
	{
		HTTPResponse	response;
		response.SetHTMLMessage( 501 ); // Not Implemented
		pb->request->SendReply( &response );
		return B_ERROR;
	}
	return B_OK;
}