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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "wine/port.h"
32 #define WIN32_NO_STATUS
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 * integral_atom_name (internal)
103 * Helper for fetching integral (local/global) atoms names.
105 static ULONG integral_atom_name(WCHAR* buffer, ULONG len, RTL_ATOM atom)
107 static const WCHAR fmt[] = {'#','%','u',0};
111 ret = sprintfW( tmp, fmt, atom );
112 if (!len) return ret * sizeof(WCHAR);
113 if (len <= ret) ret = len - 1;
114 memcpy( buffer, tmp, ret * sizeof(WCHAR) );
116 return ret * sizeof(WCHAR);
119 /******************************************************************
120 * RtlQueryAtomInAtomTable (NTDLL.@)
122 NTSTATUS WINAPI RtlQueryAtomInAtomTable( RTL_ATOM_TABLE table, RTL_ATOM atom, ULONG* ref,
123 ULONG* pin, WCHAR* name, ULONG* len )
125 NTSTATUS status = STATUS_SUCCESS;
128 if (!table) status = STATUS_INVALID_PARAMETER;
129 else if (atom < MAXINTATOM)
131 if (!atom) return STATUS_INVALID_PARAMETER;
132 if (len) wlen = integral_atom_name( name, *len, atom);
138 SERVER_START_REQ( get_atom_information )
142 if (len && *len && name)
143 wine_server_set_reply( req, name, *len );
144 status = wine_server_call( req );
145 if (status == STATUS_SUCCESS)
148 if (ref) *ref = reply->count;
149 if (pin) *pin = reply->pinned;
154 if (status == STATUS_SUCCESS && len)
158 wlen = min( *len - sizeof(WCHAR), wlen );
159 if (name) name[wlen / sizeof(WCHAR)] = 0;
161 else status = STATUS_BUFFER_TOO_SMALL;
165 TRACE( "%p %x -> %s (%lx)\n",
166 table, atom, len ? debugstr_wn(name, wlen / sizeof(WCHAR)) : NULL, status );
170 /******************************************************************
171 * RtlCreateAtomTable (NTDLL.@)
173 NTSTATUS WINAPI RtlCreateAtomTable( ULONG size, RTL_ATOM_TABLE* table )
179 if (size) status = STATUS_INVALID_PARAMETER;
180 else status = STATUS_SUCCESS;
184 SERVER_START_REQ( init_atom_table )
187 status = wine_server_call( req );
188 *table = reply->table;
195 /******************************************************************
196 * RtlDestroyAtomTable (NTDLL.@)
198 NTSTATUS WINAPI RtlDestroyAtomTable( RTL_ATOM_TABLE table )
200 if (!table) return STATUS_INVALID_PARAMETER;
201 return NtClose( (HANDLE)table );
204 /******************************************************************
205 * RtlAddAtomToAtomTable (NTDLL.@)
207 NTSTATUS WINAPI RtlAddAtomToAtomTable( RTL_ATOM_TABLE table, const WCHAR* name, RTL_ATOM* atom )
211 if (!table) status = STATUS_INVALID_PARAMETER;
214 size_t len = HIWORD(name) ? strlenW(name) : 0;
215 status = is_integral_atom( name, len, atom );
216 if (status == STATUS_MORE_ENTRIES)
218 SERVER_START_REQ( add_atom )
220 wine_server_add_data( req, name, len * sizeof(WCHAR) );
222 status = wine_server_call( req );
228 TRACE( "%p %s -> %x\n",
229 table, debugstr_w(name), status == STATUS_SUCCESS ? *atom : 0 );
234 /******************************************************************
235 * RtlLookupAtomInAtomTable (NTDLL.@)
237 NTSTATUS WINAPI RtlLookupAtomInAtomTable( RTL_ATOM_TABLE table, const WCHAR* name, RTL_ATOM* atom )
241 if (!table) status = STATUS_INVALID_PARAMETER;
244 size_t len = HIWORD(name) ? strlenW(name) : 0;
245 status = is_integral_atom( name, len, atom );
246 if (status == STATUS_MORE_ENTRIES)
248 SERVER_START_REQ( find_atom )
250 wine_server_add_data( req, name, len * sizeof(WCHAR) );
252 status = wine_server_call( req );
258 TRACE( "%p %s -> %x\n",
259 table, debugstr_w(name), status == STATUS_SUCCESS ? *atom : 0 );
263 /******************************************************************
264 * RtlEmptyAtomTable (NTDLL.@)
266 NTSTATUS WINAPI RtlEmptyAtomTable( RTL_ATOM_TABLE table, BOOLEAN delete_pinned )
270 if (!table) status = STATUS_INVALID_PARAMETER;
273 SERVER_START_REQ( empty_atom_table )
276 req->if_pinned = delete_pinned;
277 status = wine_server_call( req );
284 /******************************************************************
285 * RtlPinAtomInAtomTable (NTDLL.@)
287 NTSTATUS WINAPI RtlPinAtomInAtomTable( RTL_ATOM_TABLE table, RTL_ATOM atom )
291 if (!table) return STATUS_INVALID_PARAMETER;
292 if (atom < MAXINTATOM) return STATUS_SUCCESS;
294 SERVER_START_REQ( set_atom_information )
299 status = wine_server_call( req );
306 /*************************************************
307 * Global handle table management
308 *************************************************/
310 /******************************************************************
311 * NtAddAtom (NTDLL.@)
313 NTSTATUS WINAPI NtAddAtom( const WCHAR* name, ULONG length, RTL_ATOM* atom )
317 status = is_integral_atom( name, length / sizeof(WCHAR), atom );
318 if (status == STATUS_MORE_ENTRIES)
320 SERVER_START_REQ( add_atom )
322 wine_server_add_data( req, name, length );
324 status = wine_server_call( req );
330 debugstr_wn(name, length/sizeof(WCHAR)), status == STATUS_SUCCESS ? *atom : 0 );
334 /******************************************************************
335 * NtDeleteAtom (NTDLL.@)
337 NTSTATUS WINAPI NtDeleteAtom(RTL_ATOM atom)
341 SERVER_START_REQ( delete_atom )
345 status = wine_server_call( req );
351 /******************************************************************
352 * NtFindAtom (NTDLL.@)
354 NTSTATUS WINAPI NtFindAtom( const WCHAR* name, ULONG length, RTL_ATOM* atom )
358 status = is_integral_atom( name, length / sizeof(WCHAR), atom );
359 if (status == STATUS_MORE_ENTRIES)
361 SERVER_START_REQ( find_atom )
363 wine_server_add_data( req, name, length );
365 status = wine_server_call( req );
371 debugstr_wn(name, length/sizeof(WCHAR)), status == STATUS_SUCCESS ? *atom : 0 );
375 /******************************************************************
376 * NtQueryInformationAtom (NTDLL.@)
378 NTSTATUS WINAPI NtQueryInformationAtom( RTL_ATOM atom, ATOM_INFORMATION_CLASS class,
379 PVOID ptr, ULONG size, PULONG psize )
385 case AtomBasicInformation:
388 ATOM_BASIC_INFORMATION* abi = (ATOM_BASIC_INFORMATION*)ptr;
390 if (size < sizeof(ATOM_BASIC_INFORMATION))
391 return STATUS_INVALID_PARAMETER;
392 name_len = size - sizeof(ATOM_BASIC_INFORMATION);
394 if (atom < MAXINTATOM)
398 abi->NameLength = integral_atom_name( abi->Name, name_len, atom );
399 status = (name_len) ? STATUS_SUCCESS : STATUS_BUFFER_TOO_SMALL;
400 abi->ReferenceCount = 1;
403 else status = STATUS_INVALID_PARAMETER;
407 SERVER_START_REQ( get_atom_information )
411 if (name_len) wine_server_set_reply( req, abi->Name, name_len );
412 status = wine_server_call( req );
413 if (status == STATUS_SUCCESS)
415 name_len = wine_server_reply_size( reply );
418 abi->NameLength = name_len;
419 abi->Name[name_len / sizeof(WCHAR)] = '\0';
423 name_len = reply->total;
424 abi->NameLength = name_len;
425 status = STATUS_BUFFER_TOO_SMALL;
427 abi->ReferenceCount = reply->count;
428 abi->Pinned = reply->pinned;
434 TRACE( "%x -> %s (%lu)\n",
435 atom, debugstr_wn(abi->Name, abi->NameLength / sizeof(WCHAR)),
438 *psize = sizeof(ATOM_BASIC_INFORMATION) + name_len;
442 FIXME( "Unsupported class %u\n", class );
443 status = STATUS_INVALID_INFO_CLASS;