On Wed, 28 Jan 2009, Francesco Saverio Giudice wrote: Hi,
> Just 3 other questions: > 1 - I would like to limit use of some functions that may be dangerous if > used from a user, like zap a database or FErase, but this are only two > samples and maybe not pertinent in real developing, or to other functions, > like dbUseArea(), that I want that not have to be used because I would like > to add an HTTP_dbUseArea() that can open databases and control them. Is > there a way to add a HRB_INHIBIT_FUNCTIONS that can inhibit some function > calls from hrb at HVM level ? As long as you do not block macro compiler then it will not be possible. Even if you block it in this module then programmer can find other way to execute any function by macro compiler inside other modules, f.e. he can try to use some filter or even index key expressions passed as string adding his own forbidden code. To make it we should locate and document all functions which makes macrocompilation. We should declare forbidden namespace for given thread and respect this name space in all macrocompilations. It's complicated problem and to create some really working solutions which will be acceptable for programmers using restrictive environment it's necessary to first carefully document all possible danger places in core code and what will happen if some things will be blocked. > 2 - In uhttpd.prg the piece of code that runs HRB modules is guarded from a > mutex: > -------------- > ..... > // Lock HRB to avoid MT race conditions > IF hb_mutexLock( s_hmtxHRB ) <<<<---- > IF HRB_ACTIVATE_CACHE > // caching modules > IF !hb_HHasKey( s_hHRBModules, cFileName ) > hb_HSet( s_hHRBModules, cFileName, ; > HRB_LoadFromFile( uOSFileName( cFileName ) ) ) > ENDIF > cHRBBody := s_hHRBModules[ cFileName ] > ELSE > cHRBBody := HRB_LoadFromFile( uOSFileName( cFileName ) ) > ENDIF > IF !EMPTY( pHRB := HB_HRBLOAD( cHRBBody ) ) > xResult := HRBMAIN() > > HB_HRBUNLOAD( pHRB ) > ELSE > uSetStatusCode( 404 ) > t_cErrorMsg := "File does not exist: " + cFileName > ENDIF > hb_mutexUnlock( s_hmtxHRB ) <<<<---- > > ENDIF > ..... > > STATIC FUNCTION HRB_LoadFromFile( cFile ) > RETURN hb_memoread( cFile ) > > -------------- > Is it correct or is it unnecessary because this is already done from HVM ? For HVM it's not necessary but you need it for your own code to protect s_hHRBModules variable and public function name space because you are using fixed starting function HRBMAIN() and only one public function with given name can be register in HVM so this code can be executed only by one thread and you have to block other threads. > 3 - In the same piece of code (not already uploaded) I have thought to a > memory cache of HRBBody code using an hash (actually HRB_ACTIVATE_CACHE can > has value .T. or .F.) but I'm not able to evaluate costs between load from > file everytime (where I suppose that OS helps caching file in memory) or > scanning an hash and retrieve the string (apart from a side effect: loading > an hrb module from file permits to update hrb code on the fly, the other > method load hrb only first time than I need to "purge" list to have it > loaded again). The performance will be strictly platform dependent. Probably in Linux and other *nixes you will not find big speed difference. But in windows or when files are not stored on local drives then it will increase performance. Anyhow in such case I suggest to add option to discard buffers without server reloading. When cache is disabled I suggest to make file loading outside s_hmtxHRB to reduce time when it's locked. best regards, Przemek _______________________________________________ Harbour mailing list Harbour@harbour-project.org http://lists.harbour-project.org/mailman/listinfo/harbour