4 * Copyright 1993, 1994, 1995 Alexandre Julliard
5 * Copyright 2004,2005 Eric Pouech
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "wine/port.h"
34 #include "wine/server.h"
35 #include "wine/unicode.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(atom);
41 #define MAX_ATOM_LEN 255
43 /******************************************************************
45 * Returns STATUS_SUCCESS if integral atom and 'pAtom' is filled
46 * STATUS_INVALID_PARAMETER if 'atomstr' is too long
47 * STATUS_MORE_ENTRIES otherwise
49 static NTSTATUS is_integral_atom( LPCWSTR atomstr, size_t len, RTL_ATOM* pAtom )
53 if (HIWORD( atomstr ))
55 const WCHAR* ptr = atomstr;
56 if (!len) return STATUS_OBJECT_NAME_INVALID;
61 while (ptr < atomstr + len && *ptr >= '0' && *ptr <= '9')
63 atom = atom * 10 + *ptr++ - '0';
65 if (ptr > atomstr + 1 && ptr == atomstr + len) goto done;
67 if (len > MAX_ATOM_LEN) return STATUS_INVALID_PARAMETER;
68 return STATUS_MORE_ENTRIES;
70 else atom = LOWORD( atomstr );
72 if (!atom || atom >= MAXINTATOM) return STATUS_INVALID_PARAMETER;
74 return STATUS_SUCCESS;
77 /******************************************************************
78 * RtlDeleteAtomFromAtomTable (NTDLL.@)
80 NTSTATUS WINAPI RtlDeleteAtomFromAtomTable( RTL_ATOM_TABLE table, RTL_ATOM atom )
84 TRACE( "%p %x\n", table, atom );
85 if (!table) status = STATUS_INVALID_PARAMETER;
88 SERVER_START_REQ( delete_atom )
92 status = wine_server_call( req );
99 /******************************************************************
100 * RtlQueryAtomInAtomTable (NTDLL.@)
102 NTSTATUS WINAPI RtlQueryAtomInAtomTable( RTL_ATOM_TABLE table, RTL_ATOM atom, ULONG* ref,
103 ULONG* pin, WCHAR* name, ULONG* len )
105 NTSTATUS status = STATUS_SUCCESS;
106 WCHAR full_name[MAX_ATOM_LEN];
109 if (!table) status = STATUS_INVALID_PARAMETER;
110 else if (atom < MAXINTATOM)
112 if (!atom) return STATUS_INVALID_PARAMETER;
115 static WCHAR fmt[] = {'#','%','d',0};
116 wlen = sprintfW( full_name, fmt, atom ) * sizeof(WCHAR);
123 SERVER_START_REQ( get_atom_information )
127 if (len) wine_server_set_reply( req, full_name, sizeof(full_name) );
128 status = wine_server_call( req );
129 if (status == STATUS_SUCCESS)
131 wlen = wine_server_reply_size( reply );
132 if (ref) *ref = reply->count;
133 if (pin) *pin = reply->pinned;
138 if (status == STATUS_SUCCESS && len)
142 memcpy( name, full_name, wlen );
143 name[wlen / sizeof(WCHAR)] = 0;
145 else status = STATUS_BUFFER_TOO_SMALL;
149 TRACE( "%p %x -> %s (%lu)\n",
150 table, atom, len ? debugstr_w(name) : NULL, status );
154 /******************************************************************
155 * RtlCreateAtomTable (NTDLL.@)
157 NTSTATUS WINAPI RtlCreateAtomTable( ULONG size, RTL_ATOM_TABLE* table )
163 if (size) status = STATUS_INVALID_PARAMETER;
164 else status = STATUS_SUCCESS;
168 SERVER_START_REQ( init_atom_table )
171 status = wine_server_call( req );
172 *table = reply->table;
179 /******************************************************************
180 * RtlDestroyAtomTable (NTDLL.@)
182 NTSTATUS WINAPI RtlDestroyAtomTable( RTL_ATOM_TABLE table )
184 if (!table) return STATUS_INVALID_PARAMETER;
185 return NtClose( (HANDLE)table );
188 /******************************************************************
189 * RtlAddAtomToAtomTable (NTDLL.@)
191 NTSTATUS WINAPI RtlAddAtomToAtomTable( RTL_ATOM_TABLE table, const WCHAR* name, RTL_ATOM* atom )
195 if (!table) status = STATUS_INVALID_PARAMETER;
198 size_t len = HIWORD(name) ? strlenW(name) : 0;
199 status = is_integral_atom( name, len, atom );
200 if (status == STATUS_MORE_ENTRIES)
202 SERVER_START_REQ( add_atom )
204 wine_server_add_data( req, name, len * sizeof(WCHAR) );
206 status = wine_server_call( req );
212 TRACE( "%p %s -> %x\n",
213 table, debugstr_w(name), status == STATUS_SUCCESS ? *atom : 0 );
218 /******************************************************************
219 * RtlLookupAtomInAtomTable (NTDLL.@)
221 NTSTATUS WINAPI RtlLookupAtomInAtomTable( RTL_ATOM_TABLE table, const WCHAR* name, RTL_ATOM* atom )
225 if (!table) status = STATUS_INVALID_PARAMETER;
228 size_t len = HIWORD(name) ? strlenW(name) : 0;
229 status = is_integral_atom( name, len, atom );
230 if (status == STATUS_MORE_ENTRIES)
232 SERVER_START_REQ( find_atom )
234 wine_server_add_data( req, name, len * sizeof(WCHAR) );
236 status = wine_server_call( req );
242 TRACE( "%p %s -> %x\n",
243 table, debugstr_w(name), status == STATUS_SUCCESS ? *atom : 0 );
247 /******************************************************************
248 * RtlEmptyAtomTable (NTDLL.@)
250 NTSTATUS WINAPI RtlEmptyAtomTable( RTL_ATOM_TABLE table, BOOLEAN delete_pinned )
254 if (!table) status = STATUS_INVALID_PARAMETER;
257 SERVER_START_REQ( empty_atom_table )
260 req->if_pinned = delete_pinned;
261 status = wine_server_call( req );
268 /******************************************************************
269 * RtlPinAtomInAtomTable (NTDLL.@)
271 NTSTATUS WINAPI RtlPinAtomInAtomTable( RTL_ATOM_TABLE table, RTL_ATOM atom )
275 if (!table) return STATUS_INVALID_PARAMETER;
276 if (atom < MAXINTATOM) return STATUS_SUCCESS;
278 SERVER_START_REQ( set_atom_information )
283 status = wine_server_call( req );
290 /*************************************************
291 * Global handle table management
292 *************************************************/
294 /******************************************************************
295 * NtAddAtom (NTDLL.@)
297 NTSTATUS WINAPI NtAddAtom( const WCHAR* name, ULONG length, RTL_ATOM* atom )
301 status = is_integral_atom( name, length / sizeof(WCHAR), atom );
302 if (status == STATUS_MORE_ENTRIES)
304 SERVER_START_REQ( add_atom )
306 wine_server_add_data( req, name, length );
308 status = wine_server_call( req );
314 debugstr_wn(name, length/sizeof(WCHAR)), status == STATUS_SUCCESS ? *atom : 0 );
318 /******************************************************************
319 * NtDeleteAtom (NTDLL.@)
321 NTSTATUS WINAPI NtDeleteAtom(RTL_ATOM atom)
325 SERVER_START_REQ( delete_atom )
329 status = wine_server_call( req );
335 /******************************************************************
336 * NtFindAtom (NTDLL.@)
338 NTSTATUS WINAPI NtFindAtom( const WCHAR* name, ULONG length, RTL_ATOM* atom )
342 status = is_integral_atom( name, length / sizeof(WCHAR), atom );
343 if (status == STATUS_MORE_ENTRIES)
345 SERVER_START_REQ( find_atom )
347 wine_server_add_data( req, name, length );
349 status = wine_server_call( req );
355 debugstr_wn(name, length/sizeof(WCHAR)), status == STATUS_SUCCESS ? *atom : 0 );
359 /******************************************************************
360 * NtQueryInformationAtom (NTDLL.@)
362 NTSTATUS WINAPI NtQueryInformationAtom( RTL_ATOM atom, ATOM_INFORMATION_CLASS class,
363 PVOID ptr, ULONG size, PULONG psize )
369 case AtomBasicInformation:
372 ATOM_BASIC_INFORMATION* abi = (ATOM_BASIC_INFORMATION*)ptr;
374 name_len = size - (sizeof(ATOM_BASIC_INFORMATION) - sizeof(WCHAR));
376 if (atom < MAXINTATOM)
378 if (!atom) status = STATUS_INVALID_PARAMETER;
379 else if (name_len >= 7 * sizeof(WCHAR))
381 static WCHAR fmt[] = {'#','%','d',0};
382 abi->NameLength = snprintfW( abi->Name, name_len / sizeof(WCHAR), fmt, atom ) * sizeof(WCHAR);
383 abi->ReferenceCount = 1;
385 status = STATUS_SUCCESS;
387 else status = STATUS_BUFFER_TOO_SMALL;
391 SERVER_START_REQ( get_atom_information )
395 if (name_len) wine_server_set_reply( req, abi->Name, name_len );
396 status = wine_server_call( req );
397 name_len = wine_server_reply_size( reply );
398 if (status == STATUS_SUCCESS)
400 abi->NameLength = name_len;
401 abi->ReferenceCount = reply->count;
402 abi->Pinned = reply->pinned;
407 TRACE( "%x -> %s (%lu)\n", atom, debugstr_wn(abi->Name, name_len/sizeof(WCHAR)), status );
409 *psize = sizeof(ATOM_BASIC_INFORMATION) - sizeof(WCHAR) + name_len;
413 FIXME( "Unsupported class %u\n", class );
414 status = STATUS_INVALID_INFO_CLASS;