int main(int argc, char **argv) { if (argc != 2) { fprintf(stderr, "usage: lock_node <file>\n"); return 1; } BNode node; status_t status = node.SetTo(argv[1]); if (status != B_OK) { fprintf(stderr, "lock_node: could not open \"%s\": %s\n", argv[1], strerror(status)); return 1; } status = node.Lock(); if (status != B_OK) { fprintf(stderr, "lock_node: could not lock \"%s\": %s\n", argv[1], strerror(status)); return 1; } puts("press <enter> to continue..."); char a[5]; fgets(a, 5, stdin); node.Unlock(); node.Unset(); return 0; }
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; }