Commit 0b6a79c9 authored by Alexandre Julliard's avatar Alexandre Julliard

Converted enum_key_value request to the new request mechanism.

parent ebb3a68c
......@@ -44,9 +44,6 @@ struct request_max_size
/* max size of the variable part of a request */
#define REQUEST_MAX_VAR_SIZE 1024
/* a path name for server requests (Unicode) */
typedef WCHAR path_t[MAX_PATH+1];
/* definitions of the event data depending on the event code */
struct debug_event_exception
......@@ -1094,8 +1091,8 @@ struct enum_key_value_request
IN unsigned int offset; /* offset for getting data */
OUT int type; /* value type */
OUT int len; /* value data len */
OUT path_t name; /* value name */
OUT unsigned char data[1]; /* value data */
OUT VARARG(name,unicode_len_str); /* value name */
OUT VARARG(data,bytes); /* value data */
};
......@@ -1591,7 +1588,7 @@ union generic_request
struct async_result_request async_result;
};
#define SERVER_PROTOCOL_VERSION 28
#define SERVER_PROTOCOL_VERSION 29
/* ### make_requests end ### */
/* Everything above this line is generated automatically by tools/make_requests */
......
......@@ -792,7 +792,7 @@ static void set_value( struct key *key, WCHAR *name, int type, unsigned int tota
}
/* get a key value */
static size_t get_value( struct key *key, WCHAR *name, unsigned int offset,
static size_t get_value( struct key *key, const WCHAR *name, unsigned int offset,
unsigned int maxlen, int *type, int *len, void *data )
{
struct key_value *value;
......@@ -820,25 +820,50 @@ static size_t get_value( struct key *key, WCHAR *name, unsigned int offset,
}
/* enumerate a key value */
static void enum_value( struct key *key, int i, WCHAR *name, unsigned int offset,
unsigned int maxlen, int *type, int *len, void *data )
static size_t enum_value( struct key *key, int i, unsigned int offset,
unsigned int maxlen, int *type, int *len, void *data )
{
struct key_value *value;
size_t ret = 0;
if (i < 0 || i > key->last_value) set_error( STATUS_NO_MORE_ENTRIES );
else
{
WCHAR *name_ptr = data;
value = &key->values[i];
strcpyW( name, value->name );
*type = value->type;
*len = value->len;
if (value->data && offset < value->len)
if (maxlen >= sizeof(WCHAR))
{
if (maxlen > value->len - offset) maxlen = value->len - offset;
memcpy( data, (char *)value->data + offset, maxlen );
size_t name_len = 0;
/* copy the name only the first time (offset==0),
* otherwise store an empty name in the buffer
*/
maxlen -= sizeof(WCHAR);
ret += sizeof(WCHAR);
if (!offset)
{
name_len = strlenW( value->name ) * sizeof(WCHAR);
if (name_len > maxlen) name_len = maxlen;
}
*name_ptr++ = name_len;
memcpy( name_ptr, value->name, name_len );
maxlen -= name_len;
ret += name_len;
data = (char *)name_ptr + name_len;
if (value->data && offset < value->len)
{
if (maxlen > value->len - offset) maxlen = value->len - offset;
memcpy( data, (char *)value->data + offset, maxlen );
ret += maxlen;
}
}
if (debug_level > 1) dump_operation( key, value, "Enum" );
}
return ret;
}
/* delete a value */
......@@ -1674,16 +1699,16 @@ DECL_HANDLER(get_key_value)
DECL_HANDLER(enum_key_value)
{
struct key *key;
unsigned int max = get_req_size( req, req->data, sizeof(req->data[0]) );
size_t len = 0;
req->len = 0;
req->name[0] = 0;
if ((key = get_hkey_obj( req->hkey, KEY_QUERY_VALUE )))
{
enum_value( key, req->index, req->name, req->offset, max,
&req->type, &req->len, req->data );
len = enum_value( key, req->index, req->offset, get_req_data_size(req),
&req->type, &req->len, get_req_data(req) );
release_object( key );
}
set_req_data_size( req, len );
}
/* delete a value of a registry key */
......
......@@ -365,6 +365,9 @@ void open_master_socket(void)
struct sockaddr_un addr;
int fd, slen;
/* make sure no request is larger than the maximum size */
assert( sizeof(union generic_request) == sizeof(struct request_max_size) );
create_server_dir();
if ((fd = socket( AF_UNIX, SOCK_STREAM, 0 )) == -1) fatal_perror( "socket" );
addr.sun_family = AF_UNIX;
......
......@@ -66,31 +66,6 @@ inline static void set_req_data_size( const void *req, size_t size )
((struct request_header *)req)->var_size = size;
}
#define REQUEST_END(req) ((char *)(req) + MAX_REQUEST_LENGTH - sizeof(struct server_buffer_info))
/* get the remaining size in the request buffer for object of a given size */
static inline int get_req_size( const void *req, const void *ptr, size_t typesize )
{
return (REQUEST_END(req) - (char *)ptr) / typesize;
}
/* get the length of a request string, without going past the end of the request */
static inline size_t get_req_strlen( const void *req, const char *str )
{
const char *p = str;
while (*p && (p < REQUEST_END(req) - 1)) p++;
return p - str;
}
/* same as above for Unicode */
static inline size_t get_req_strlenW( const void *req, const WCHAR *str )
{
const WCHAR *p = str;
while (*p && (p < (WCHAR *)REQUEST_END(req) - 1)) p++;
return p - str;
}
/* Everything below this line is generated automatically by tools/make_requests */
/* ### make_requests begin ### */
......
......@@ -42,26 +42,6 @@ static void dump_uints( const int *ptr, int len )
fputc( '}', stderr );
}
static void dump_bytes( const unsigned char *ptr, int len )
{
fputc( '{', stderr );
while (len > 0)
{
fprintf( stderr, "%02x", *ptr++ );
if (--len) fputc( ',', stderr );
}
fputc( '}', stderr );
}
static void dump_path_t( const void *req, const path_t *path )
{
const WCHAR *str = *path;
size_t len = get_req_strlenW( req, str );
fprintf( stderr, "L\"" );
dump_strW( str, len, stderr, "\"\"" );
fputc( '\"', stderr );
}
static void dump_context( const CONTEXT *context )
{
#ifdef __i386__
......@@ -261,14 +241,6 @@ static size_t dump_varargs_input_records( const void *req )
return get_size(req);
}
/* dumping for functions for requests that have a variable part */
static void dump_varargs_enum_key_value_reply( const struct enum_key_value_request *req )
{
int count = min( req->len - req->offset, get_req_size( req, req->data, 1 ));
dump_bytes( req->data, count );
}
typedef void (*dump_func)( const void *req );
/* Everything below this line is generated automatically by tools/make_requests */
......@@ -1224,10 +1196,10 @@ static void dump_enum_key_value_reply( const struct enum_key_value_request *req
fprintf( stderr, " type=%d,", req->type );
fprintf( stderr, " len=%d,", req->len );
fprintf( stderr, " name=" );
dump_path_t( req, &req->name );
fprintf( stderr, "," );
cur_pos += dump_varargs_unicode_len_str( req );
fputc( ',', stderr );
fprintf( stderr, " data=" );
dump_varargs_enum_key_value_reply( req );
cur_pos += dump_varargs_bytes( req );
}
static void dump_delete_key_value_request( const struct delete_key_value_request *req )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment