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"
35 #include "wine/server.h"
36 #include "wine/unicode.h"
38 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(atom);
42 #define MAX_ATOM_LEN 255
44 /******************************************************************
46 * Returns STATUS_SUCCESS if integral atom and 'pAtom' is filled
47 * STATUS_INVALID_PARAMETER if 'atomstr' is too long
48 * STATUS_MORE_ENTRIES otherwise
50 static NTSTATUS is_integral_atom( LPCWSTR atomstr, size_t len, RTL_ATOM* pAtom )
54 if (HIWORD( atomstr ))
56 const WCHAR* ptr = atomstr;
57 if (!len) return STATUS_OBJECT_NAME_INVALID;
62 while (ptr < atomstr + len && *ptr >= '0' && *ptr <= '9')
64 atom = atom * 10 + *ptr++ - '0';
66 if (ptr > atomstr + 1 && ptr == atomstr + len) goto done;
68 if (len > MAX_ATOM_LEN) return STATUS_INVALID_PARAMETER;
69 return STATUS_MORE_ENTRIES;
71 else atom = LOWORD( atomstr );
73 if (!atom || atom >= MAXINTATOM) return STATUS_INVALID_PARAMETER;
75 return STATUS_SUCCESS;
78 /******************************************************************
79 * RtlDeleteAtomFromAtomTable (NTDLL.@)
81 NTSTATUS WINAPI RtlDeleteAtomFromAtomTable( RTL_ATOM_TABLE table, RTL_ATOM atom )
85 TRACE( "%p %x\n", table, atom );
86 if (!table) status = STATUS_INVALID_PARAMETER;
89 SERVER_START_REQ( delete_atom )
93 status = wine_server_call( req );
100 /******************************************************************
101 * RtlQueryAtomInAtomTable (NTDLL.@)
103 NTSTATUS WINAPI RtlQueryAtomInAtomTable( RTL_ATOM_TABLE table, RTL_ATOM atom, ULONG* ref,
104 ULONG* pin, WCHAR* name, ULONG* len )
106 NTSTATUS status = STATUS_SUCCESS;
107 WCHAR full_name[MAX_ATOM_LEN];
110 if (!table) status = STATUS_INVALID_PARAMETER;
111 else if (atom < MAXINTATOM)
113 if (!atom) return STATUS_INVALID_PARAMETER;
116 static WCHAR fmt[] = {'#','%','d',0};
117 wlen = sprintfW( full_name, fmt, atom ) * sizeof(WCHAR);
124 SERVER_START_REQ( get_atom_information )
128 if (len) wine_server_set_reply( req, full_name, sizeof(full_name) );
129 status = wine_server_call( req );
130 if (status == STATUS_SUCCESS)
132 wlen = wine_server_reply_size( reply );
133 if (ref) *ref = reply->count;
134 if (pin) *pin = reply->pinned;
139 if (status == STATUS_SUCCESS && len)
143 memcpy( name, full_name, wlen );
144 name[wlen / sizeof(WCHAR)] = 0;
146 else status = STATUS_BUFFER_TOO_SMALL;
150 TRACE( "%p %x -> %s (%lu)\n",
151 table, atom, len ? debugstr_w(name) : NULL, status );
155 /******************************************************************
156 * RtlCreateAtomTable (NTDLL.@)
158 NTSTATUS WINAPI RtlCreateAtomTable( ULONG size, RTL_ATOM_TABLE* table )
164 if (size) status = STATUS_INVALID_PARAMETER;
165 else status = STATUS_SUCCESS;
169 SERVER_START_REQ( init_atom_table )
172 status = wine_server_call( req );
173 *table = reply->table;
180 /******************************************************************
181 * RtlDestroyAtomTable (NTDLL.@)
183 NTSTATUS WINAPI RtlDestroyAtomTable( RTL_ATOM_TABLE table )
185 if (!table) return STATUS_INVALID_PARAMETER;
186 return NtClose( (HANDLE)table );
189 /******************************************************************
190 * RtlAddAtomToAtomTable (NTDLL.@)
192 NTSTATUS WINAPI RtlAddAtomToAtomTable( RTL_ATOM_TABLE table, const WCHAR* name, RTL_ATOM* atom )
196 if (!table) status = STATUS_INVALID_PARAMETER;
199 size_t len = HIWORD(name) ? strlenW(name) : 0;
200 status = is_integral_atom( name, len, atom );
201 if (status == STATUS_MORE_ENTRIES)
203 SERVER_START_REQ( add_atom )
205 wine_server_add_data( req, name, len * sizeof(WCHAR) );
207 status = wine_server_call( req );
213 TRACE( "%p %s -> %x\n",
214 table, debugstr_w(name), status == STATUS_SUCCESS ? *atom : 0 );
219 /******************************************************************
220 * RtlLookupAtomInAtomTable (NTDLL.@)
222 NTSTATUS WINAPI RtlLookupAtomInAtomTable( RTL_ATOM_TABLE table, const WCHAR* name, RTL_ATOM* atom )
226 if (!table) status = STATUS_INVALID_PARAMETER;
229 size_t len = HIWORD(name) ? strlenW(name) : 0;
230 status = is_integral_atom( name, len, atom );
231 if (status == STATUS_MORE_ENTRIES)
233 SERVER_START_REQ( find_atom )
235 wine_server_add_data( req, name, len * sizeof(WCHAR) );
237 status = wine_server_call( req );
243 TRACE( "%p %s -> %x\n",
244 table, debugstr_w(name), status == STATUS_SUCCESS ? *atom : 0 );
248 /******************************************************************
249 * RtlEmptyAtomTable (NTDLL.@)
251 NTSTATUS WINAPI RtlEmptyAtomTable( RTL_ATOM_TABLE table, BOOLEAN delete_pinned )
255 if (!table) status = STATUS_INVALID_PARAMETER;
258 SERVER_START_REQ( empty_atom_table )
261 req->if_pinned = delete_pinned;
262 status = wine_server_call( req );
269 /******************************************************************
270 * RtlPinAtomInAtomTable (NTDLL.@)
272 NTSTATUS WINAPI RtlPinAtomInAtomTable( RTL_ATOM_TABLE table, RTL_ATOM atom )
276 if (!table) return STATUS_INVALID_PARAMETER;
277 if (atom < MAXINTATOM) return STATUS_SUCCESS;
279 SERVER_START_REQ( set_atom_information )
284 status = wine_server_call( req );
291 /*************************************************
292 * Global handle table management
293 *************************************************/
295 /******************************************************************
296 * NtAddAtom (NTDLL.@)
298 NTSTATUS WINAPI NtAddAtom( const WCHAR* name, ULONG length, RTL_ATOM* atom )
302 status = is_integral_atom( name, length / sizeof(WCHAR), atom );
303 if (status == STATUS_MORE_ENTRIES)
305 SERVER_START_REQ( add_atom )
307 wine_server_add_data( req, name, length );
309 status = wine_server_call( req );
315 debugstr_wn(name, length/sizeof(WCHAR)), status == STATUS_SUCCESS ? *atom : 0 );
319 /******************************************************************
320 * NtDeleteAtom (NTDLL.@)
322 NTSTATUS WINAPI NtDeleteAtom(RTL_ATOM atom)
326 SERVER_START_REQ( delete_atom )
330 status = wine_server_call( req );
336 /******************************************************************
337 * NtFindAtom (NTDLL.@)
339 NTSTATUS WINAPI NtFindAtom( const WCHAR* name, ULONG length, RTL_ATOM* atom )
343 status = is_integral_atom( name, length / sizeof(WCHAR), atom );
344 if (status == STATUS_MORE_ENTRIES)
346 SERVER_START_REQ( find_atom )
348 wine_server_add_data( req, name, length );
350 status = wine_server_call( req );
356 debugstr_wn(name, length/sizeof(WCHAR)), status == STATUS_SUCCESS ? *atom : 0 );
360 /******************************************************************
361 * NtQueryInformationAtom (NTDLL.@)
363 NTSTATUS WINAPI NtQueryInformationAtom( RTL_ATOM atom, ATOM_INFORMATION_CLASS class,
364 RTL_ATOM_TABLE ptr, ULONG size, PULONG psize )
370 case AtomBasicInformation:
373 ATOM_BASIC_INFORMATION* abi = (ATOM_BASIC_INFORMATION*)ptr;
375 name_len = size - (sizeof(ATOM_BASIC_INFORMATION) - sizeof(WCHAR));
377 if (atom < MAXINTATOM)
379 if (!atom) status = STATUS_INVALID_PARAMETER;
380 else if (name_len >= 7 * sizeof(WCHAR))
382 static WCHAR fmt[] = {'#','%','d',0};
383 abi->NameLength = snprintfW( abi->Name, name_len / sizeof(WCHAR), fmt, atom ) * sizeof(WCHAR);
384 abi->ReferenceCount = 1;
386 status = STATUS_SUCCESS;
388 else status = STATUS_BUFFER_TOO_SMALL;
392 SERVER_START_REQ( get_atom_information )
396 if (name_len) wine_server_set_reply( req, abi->Name, name_len );
397 status = wine_server_call( req );
398 name_len = wine_server_reply_size( reply );
399 if (status == STATUS_SUCCESS)
401 abi->NameLength = name_len;
402 abi->ReferenceCount = reply->count;
403 abi->Pinned = reply->pinned;
408 TRACE( "%x -> %s (%lu)\n", atom, debugstr_wn(abi->Name, name_len/sizeof(WCHAR)), status );
410 *psize = sizeof(ATOM_BASIC_INFORMATION) - sizeof(WCHAR) + name_len;
414 FIXME( "Unsupported class %u\n", class );
415 status = STATUS_INVALID_INFO_CLASS;