server: Use a common helper function to implement open object calls.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alexandre Julliard 2016-01-29 16:23:29 +09:00
parent 38f9a788c4
commit ed268bbf91
12 changed files with 46 additions and 143 deletions

View File

@ -196,23 +196,11 @@ DECL_HANDLER(create_completion)
/* open a completion */
DECL_HANDLER(open_completion)
{
struct completion *completion;
struct unicode_str name;
struct directory *root = NULL;
reply->handle = 0;
get_req_unicode_str( &name );
if (req->rootdir && !(root = get_directory_obj( current->process, req->rootdir, 0 )))
return;
if ( (completion = open_object_dir( root, &name, req->attributes, &completion_ops )) != NULL )
{
reply->handle = alloc_handle( current->process, completion, req->access, req->attributes );
release_object( completion );
}
if (root) release_object( root );
reply->handle = open_object( current->process, req->rootdir, req->access,
&completion_ops, &name, req->attributes );
}

View File

@ -523,19 +523,10 @@ DECL_HANDLER(create_directory)
DECL_HANDLER(open_directory)
{
struct unicode_str name;
struct directory *dir, *root = NULL;
get_req_unicode_str( &name );
if (req->rootdir && !(root = get_directory_obj( current->process, req->rootdir, 0 )))
return;
if ((dir = open_object_dir( root, &name, req->attributes, &directory_ops )))
{
reply->handle = alloc_handle( current->process, &dir->obj, req->access, req->attributes );
release_object( dir );
}
if (root) release_object( root );
reply->handle = open_object( current->process, req->rootdir, req->access,
&directory_ops, &name, req->attributes );
}
/* get a directory entry by index */

View File

@ -307,20 +307,10 @@ DECL_HANDLER(create_event)
DECL_HANDLER(open_event)
{
struct unicode_str name;
struct directory *root = NULL;
struct event *event;
get_req_unicode_str( &name );
if (req->rootdir && !(root = get_directory_obj( current->process, req->rootdir, 0 )))
return;
if ((event = open_object_dir( root, &name, req->attributes, &event_ops )))
{
reply->handle = alloc_handle( current->process, &event->obj, req->access, req->attributes );
release_object( event );
}
if (root) release_object( root );
reply->handle = open_object( current->process, req->rootdir, req->access,
&event_ops, &name, req->attributes );
}
/* do an event operation */
@ -389,16 +379,8 @@ DECL_HANDLER(create_keyed_event)
DECL_HANDLER(open_keyed_event)
{
struct unicode_str name;
struct directory *root = NULL;
struct keyed_event *event;
get_req_unicode_str( &name );
if (req->rootdir && !(root = get_directory_obj( current->process, req->rootdir, 0 ))) return;
if ((event = open_object_dir( root, &name, req->attributes, &keyed_event_ops )))
{
reply->handle = alloc_handle( current->process, &event->obj, req->access, req->attributes );
release_object( event );
}
if (root) release_object( root );
reply->handle = open_object( current->process, req->rootdir, req->access,
&keyed_event_ops, &name, req->attributes );
}

View File

@ -571,21 +571,22 @@ obj_handle_t duplicate_handle( struct process *src, obj_handle_t src_handle, str
}
/* open a new handle to an existing object */
obj_handle_t open_object( const struct namespace *namespace, const struct unicode_str *name,
const struct object_ops *ops, unsigned int access, unsigned int attr )
obj_handle_t open_object( struct process *process, obj_handle_t parent, unsigned int access,
const struct object_ops *ops, const struct unicode_str *name,
unsigned int attributes )
{
obj_handle_t handle = 0;
struct object *obj = find_object( namespace, name, attr );
if (obj)
struct directory *root = NULL;
struct object *obj;
if (parent && !(root = get_directory_obj( current->process, parent, 0 ))) return 0;
if ((obj = open_object_dir( root, name, attributes, ops )))
{
if (ops && obj->ops != ops)
set_error( STATUS_OBJECT_TYPE_MISMATCH );
else
handle = alloc_handle( current->process, obj, access, attr );
handle = alloc_handle( current->process, obj, access, attributes );
release_object( obj );
}
else
set_error( STATUS_OBJECT_NAME_NOT_FOUND );
if (root) release_object( root );
return handle;
}

View File

@ -44,8 +44,9 @@ extern struct object *get_handle_obj( struct process *process, obj_handle_t hand
extern unsigned int get_handle_access( struct process *process, obj_handle_t handle );
extern obj_handle_t duplicate_handle( struct process *src, obj_handle_t src_handle, struct process *dst,
unsigned int access, unsigned int attr, unsigned int options );
extern obj_handle_t open_object( const struct namespace *namespace, const struct unicode_str *name,
const struct object_ops *ops, unsigned int access, unsigned int attr );
extern obj_handle_t open_object( struct process *process, obj_handle_t parent, unsigned int access,
const struct object_ops *ops, const struct unicode_str *name,
unsigned int attr );
extern obj_handle_t find_inherited_handle( struct process *process, const struct object_ops *ops );
extern obj_handle_t enumerate_handles( struct process *process, const struct object_ops *ops,
unsigned int *index );

View File

@ -688,20 +688,10 @@ DECL_HANDLER(create_mapping)
DECL_HANDLER(open_mapping)
{
struct unicode_str name;
struct directory *root = NULL;
struct mapping *mapping;
get_req_unicode_str( &name );
if (req->rootdir && !(root = get_directory_obj( current->process, req->rootdir, 0 )))
return;
if ((mapping = open_object_dir( root, &name, req->attributes, &mapping_ops )))
{
reply->handle = alloc_handle( current->process, &mapping->obj, req->access, req->attributes );
release_object( mapping );
}
if (root) release_object( root );
reply->handle = open_object( current->process, req->rootdir, req->access,
&mapping_ops, &name, req->attributes );
}
/* get a mapping information */

View File

@ -234,20 +234,10 @@ DECL_HANDLER(create_mutex)
DECL_HANDLER(open_mutex)
{
struct unicode_str name;
struct directory *root = NULL;
struct mutex *mutex;
get_req_unicode_str( &name );
if (req->rootdir && !(root = get_directory_obj( current->process, req->rootdir, 0 )))
return;
if ((mutex = open_object_dir( root, &name, req->attributes, &mutex_ops )))
{
reply->handle = alloc_handle( current->process, &mutex->obj, req->access, req->attributes );
release_object( mutex );
}
if (root) release_object( root );
reply->handle = open_object( current->process, req->rootdir, req->access,
&mutex_ops, &name, req->attributes );
}
/* release a mutex */

View File

@ -1561,19 +1561,11 @@ DECL_HANDLER(create_job)
/* open a job object */
DECL_HANDLER(open_job)
{
struct job *job;
struct unicode_str name;
struct directory *root = NULL;
get_req_unicode_str( &name );
if (req->rootdir && !(root = get_directory_obj( current->process, req->rootdir, 0 ))) return;
if ((job = open_object_dir( root, &name, req->attributes, &job_ops )))
{
reply->handle = alloc_handle( current->process, &job->obj, req->access, req->attributes );
release_object( job );
}
if (root) release_object( root );
reply->handle = open_object( current->process, req->rootdir, req->access,
&job_ops, &name, req->attributes );
}
/* assign a job object to a process */

View File

@ -202,20 +202,10 @@ DECL_HANDLER(create_semaphore)
DECL_HANDLER(open_semaphore)
{
struct unicode_str name;
struct directory *root = NULL;
struct semaphore *sem;
get_req_unicode_str( &name );
if (req->rootdir && !(root = get_directory_obj( current->process, req->rootdir, 0 )))
return;
if ((sem = open_object_dir( root, &name, req->attributes, &semaphore_ops )))
{
reply->handle = alloc_handle( current->process, &sem->obj, req->access, req->attributes );
release_object( sem );
}
if (root) release_object( root );
reply->handle = open_object( current->process, req->rootdir, req->access,
&semaphore_ops, &name, req->attributes );
}
/* release a semaphore */

View File

@ -190,20 +190,10 @@ DECL_HANDLER(create_symlink)
DECL_HANDLER(open_symlink)
{
struct unicode_str name;
struct directory *root = NULL;
struct symlink *symlink;
get_req_unicode_str( &name );
if (req->rootdir && !(root = get_directory_obj( current->process, req->rootdir, 0 )))
return;
if ((symlink = open_object_dir( root, &name, req->attributes | OBJ_OPENLINK, &symlink_ops )))
{
reply->handle = alloc_handle( current->process, &symlink->obj, req->access, req->attributes );
release_object( symlink );
}
if (root) release_object( root );
reply->handle = open_object( current->process, req->rootdir, req->access,
&symlink_ops, &name, req->attributes | OBJ_OPENLINK );
}
/* query a symbolic link object */

View File

@ -252,20 +252,10 @@ DECL_HANDLER(create_timer)
DECL_HANDLER(open_timer)
{
struct unicode_str name;
struct directory *root = NULL;
struct timer *timer;
get_req_unicode_str( &name );
if (req->rootdir && !(root = get_directory_obj( current->process, req->rootdir, 0 )))
return;
if ((timer = open_object_dir( root, &name, req->attributes, &timer_ops )))
{
reply->handle = alloc_handle( current->process, &timer->obj, req->access, req->attributes );
release_object( timer );
}
if (root) release_object( root );
reply->handle = open_object( current->process, req->rootdir, req->access,
&timer_ops, &name, req->attributes );
}
/* set a waitable timer */

View File

@ -419,19 +419,11 @@ DECL_HANDLER(create_winstation)
/* open a handle to a window station */
DECL_HANDLER(open_winstation)
{
struct winstation *winstation;
struct unicode_str name;
struct directory *root = NULL;
get_req_unicode_str( &name );
if (req->rootdir && !(root = get_directory_obj( current->process, req->rootdir, 0 ))) return;
if ((winstation = open_object_dir( root, &name, req->attributes, &winstation_ops )))
{
reply->handle = alloc_handle( current->process, &winstation->obj, req->access, req->attributes );
release_object( winstation );
}
if (root) release_object( root );
reply->handle = open_object( current->process, req->rootdir, req->access,
&winstation_ops, &name, req->attributes );
}
@ -494,6 +486,7 @@ DECL_HANDLER(create_desktop)
DECL_HANDLER(open_desktop)
{
struct winstation *winstation;
struct object *obj;
struct unicode_str name;
get_req_unicode_str( &name );
@ -504,12 +497,17 @@ DECL_HANDLER(open_desktop)
else
winstation = (struct winstation *)get_handle_obj( current->process, req->winsta, 0, &winstation_ops );
if (winstation)
if (!winstation) return;
if ((obj = find_object( winstation->desktop_names, &name, req->attributes )))
{
reply->handle = open_object( winstation->desktop_names, &name, &desktop_ops,
req->access, req->attributes );
release_object( winstation );
assert( obj->ops == &desktop_ops );
reply->handle = alloc_handle( current->process, obj, req->access, req->attributes );
release_object( obj );
}
else set_error( STATUS_OBJECT_NAME_NOT_FOUND );
release_object( winstation );
}
/* open a handle to current input desktop */