2005-09-21 16:12:15 +02:00
|
|
|
/*
|
|
|
|
* Setupapi string table functions
|
|
|
|
*
|
|
|
|
* Copyright 2005 Eric Kohl
|
2014-05-04 21:29:53 +02:00
|
|
|
* Copyright 2014 Nikolay Sivov for CodeWeavers
|
2005-09-21 16:12:15 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2005-09-21 16:12:15 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winuser.h"
|
|
|
|
#include "winreg.h"
|
2014-05-04 21:29:53 +02:00
|
|
|
#include "winnls.h"
|
2005-09-21 16:12:15 +02:00
|
|
|
#include "setupapi.h"
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(setupapi);
|
|
|
|
|
2006-11-08 00:58:43 +01:00
|
|
|
DECLARE_HANDLE(HSTRING_TABLE);
|
|
|
|
|
2014-05-04 21:29:53 +02:00
|
|
|
struct stringtable {
|
|
|
|
char *data;
|
|
|
|
ULONG nextoffset;
|
|
|
|
ULONG allocated;
|
|
|
|
DWORD_PTR unk[2];
|
|
|
|
ULONG max_extra_size;
|
|
|
|
LCID lcid;
|
|
|
|
};
|
2005-09-21 16:12:15 +02:00
|
|
|
|
2014-05-04 21:29:53 +02:00
|
|
|
struct stringentry {
|
|
|
|
DWORD nextoffset;
|
|
|
|
WCHAR data[1];
|
|
|
|
};
|
2005-09-21 16:12:15 +02:00
|
|
|
|
2014-05-04 21:29:53 +02:00
|
|
|
#define BUCKET_COUNT 509
|
|
|
|
#define DEFAULT_ALLOC_SIZE 4096
|
2005-09-21 16:12:15 +02:00
|
|
|
|
2014-05-04 21:29:53 +02:00
|
|
|
/*
|
|
|
|
String table details
|
2005-09-21 16:12:15 +02:00
|
|
|
|
2014-05-04 21:29:53 +02:00
|
|
|
Returned string table 'handle' is a pointer to 'struct stringtable' structure.
|
|
|
|
Data itself is allocated separately, pointer is stored in 'data' field.
|
2005-09-21 16:12:15 +02:00
|
|
|
|
2014-05-04 21:29:53 +02:00
|
|
|
Data starts with array of 509 DWORDs - lookup table. Initially all offsets in that
|
|
|
|
array are set to -1. Right after lookup table goes data itself, stored in linked lists.
|
|
|
|
Lookup table offset points to first record of 'struct stringentry' type. When more
|
|
|
|
than one record is present in a bucket, first record links to next one with 'nextoffset'
|
|
|
|
field. Last record has nextoffset == -1, same when there's only one record. String data
|
|
|
|
is placed right after offset, and is followed by extra data. Each record has reserved
|
|
|
|
'max_extra_size' bytes to store extra data, it's not compacted in any way.
|
2005-09-21 16:12:15 +02:00
|
|
|
|
2014-05-04 21:29:53 +02:00
|
|
|
A simple hash function is used to determine which bucket a given string belongs to (see below).
|
2005-09-21 16:12:15 +02:00
|
|
|
|
2014-05-04 21:29:53 +02:00
|
|
|
All offsets including returned string ids are relative to 'data' pointer. When table
|
|
|
|
needs to grow 'allocated' size is doubled, but offsets are always valid and preserved.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
static inline DWORD get_string_hash(const WCHAR *str, BOOL case_sensitive)
|
|
|
|
{
|
|
|
|
DWORD hash = 0;
|
|
|
|
|
|
|
|
while (*str) {
|
2019-07-04 15:41:03 +02:00
|
|
|
WCHAR ch = case_sensitive ? *str : towlower(*str);
|
2014-05-04 21:29:53 +02:00
|
|
|
hash += ch;
|
|
|
|
if (ch & ~0xff)
|
|
|
|
hash |= 1;
|
|
|
|
str++;
|
2005-09-21 16:12:15 +02:00
|
|
|
}
|
|
|
|
|
2014-05-04 21:29:53 +02:00
|
|
|
return hash % BUCKET_COUNT;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline DWORD *get_bucket_ptr(struct stringtable *table, const WCHAR *string, BOOL case_sensitive)
|
|
|
|
{
|
|
|
|
DWORD hash = get_string_hash(string, case_sensitive);
|
|
|
|
return (DWORD*)(table->data + hash*sizeof(DWORD));
|
|
|
|
}
|
2005-09-21 16:12:15 +02:00
|
|
|
|
2014-05-04 21:29:53 +02:00
|
|
|
static inline WCHAR *get_string_ptr(struct stringtable *table, DWORD id)
|
|
|
|
{
|
|
|
|
return (WCHAR*)(table->data + id + sizeof(DWORD));
|
|
|
|
}
|
2005-09-21 16:12:15 +02:00
|
|
|
|
2014-05-04 21:29:53 +02:00
|
|
|
static inline char *get_extradata_ptr(struct stringtable *table, DWORD id)
|
|
|
|
{
|
|
|
|
WCHAR *ptrW = get_string_ptr(table, id);
|
|
|
|
/* skip string itself */
|
2019-07-04 15:41:03 +02:00
|
|
|
return (char*)(ptrW + lstrlenW(ptrW) + 1);
|
2014-05-04 21:29:53 +02:00
|
|
|
}
|
2005-09-21 16:12:15 +02:00
|
|
|
|
2014-05-04 21:29:53 +02:00
|
|
|
static inline BOOL is_valid_string_id(struct stringtable *table, DWORD id)
|
|
|
|
{
|
|
|
|
return (id >= BUCKET_COUNT*sizeof(DWORD)) && (id < table->allocated);
|
2005-09-21 16:12:15 +02:00
|
|
|
}
|
|
|
|
|
2014-05-04 21:29:53 +02:00
|
|
|
static inline int get_aligned16_size(int size)
|
|
|
|
{
|
|
|
|
return (size + 15) & ~15;
|
|
|
|
}
|
2005-09-21 16:12:15 +02:00
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* StringTableInitializeEx [SETUPAPI.@]
|
|
|
|
*
|
|
|
|
* Creates a new string table and initializes it.
|
|
|
|
*
|
|
|
|
* PARAMS
|
2014-05-04 21:29:53 +02:00
|
|
|
* max_extra_size [I] Maximum extra data size
|
|
|
|
* reserved [I] Unused
|
2005-09-21 16:12:15 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: Handle to the string table
|
|
|
|
* Failure: NULL
|
|
|
|
*/
|
2014-05-04 21:29:53 +02:00
|
|
|
HSTRING_TABLE WINAPI StringTableInitializeEx(ULONG max_extra_size, DWORD reserved)
|
2005-09-21 16:12:15 +02:00
|
|
|
{
|
2014-05-04 21:29:53 +02:00
|
|
|
struct stringtable *table;
|
2005-09-21 16:12:15 +02:00
|
|
|
|
2014-05-04 21:29:53 +02:00
|
|
|
TRACE("(%d %x)\n", max_extra_size, reserved);
|
2005-09-21 16:12:15 +02:00
|
|
|
|
2014-05-04 21:29:53 +02:00
|
|
|
table = MyMalloc(sizeof(*table));
|
|
|
|
if (!table) return NULL;
|
2005-09-21 16:12:15 +02:00
|
|
|
|
2014-05-04 21:29:53 +02:00
|
|
|
table->allocated = get_aligned16_size(BUCKET_COUNT*sizeof(DWORD) + DEFAULT_ALLOC_SIZE);
|
|
|
|
table->data = MyMalloc(table->allocated);
|
|
|
|
if (!table->data) {
|
|
|
|
MyFree(table);
|
2005-09-21 16:12:15 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-05-04 21:29:53 +02:00
|
|
|
table->nextoffset = BUCKET_COUNT*sizeof(DWORD);
|
|
|
|
/* FIXME: actually these two are not zero */
|
|
|
|
table->unk[0] = table->unk[1] = 0;
|
|
|
|
table->max_extra_size = max_extra_size;
|
|
|
|
table->lcid = GetThreadLocale();
|
2005-09-21 16:12:15 +02:00
|
|
|
|
2014-05-04 21:29:53 +02:00
|
|
|
/* bucket area is filled with 0xff, actual string data area is zeroed */
|
|
|
|
memset(table->data, 0xff, table->nextoffset);
|
|
|
|
memset(table->data + table->nextoffset, 0, table->allocated - table->nextoffset);
|
2005-09-21 16:12:15 +02:00
|
|
|
|
2014-05-04 21:29:53 +02:00
|
|
|
return (HSTRING_TABLE)table;
|
2005-09-21 16:12:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
2014-05-04 21:29:53 +02:00
|
|
|
* StringTableInitialize [SETUPAPI.@]
|
2005-09-21 16:12:15 +02:00
|
|
|
*
|
2014-05-04 21:29:53 +02:00
|
|
|
* Creates a new string table and initializes it.
|
2005-09-21 16:12:15 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
2014-05-04 21:29:53 +02:00
|
|
|
* None
|
2005-09-21 16:12:15 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
2014-05-04 21:29:53 +02:00
|
|
|
* Success: Handle to the string table
|
|
|
|
* Failure: NULL
|
2005-09-21 16:12:15 +02:00
|
|
|
*/
|
2014-05-04 21:29:53 +02:00
|
|
|
HSTRING_TABLE WINAPI StringTableInitialize(void)
|
2005-09-21 16:12:15 +02:00
|
|
|
{
|
2014-05-04 21:29:53 +02:00
|
|
|
return StringTableInitializeEx(0, 0);
|
2005-09-21 16:12:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
2014-05-04 21:29:53 +02:00
|
|
|
* StringTableDestroy [SETUPAPI.@]
|
2005-09-21 16:12:15 +02:00
|
|
|
*
|
2014-05-04 21:29:53 +02:00
|
|
|
* Destroys a string table.
|
2005-09-21 16:12:15 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
2014-05-04 21:29:53 +02:00
|
|
|
* hTable [I] Handle to the string table to be destroyed
|
2005-09-21 16:12:15 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
2014-05-04 21:29:53 +02:00
|
|
|
* None
|
2005-09-21 16:12:15 +02:00
|
|
|
*/
|
2014-05-04 21:29:53 +02:00
|
|
|
void WINAPI StringTableDestroy(HSTRING_TABLE hTable)
|
2005-09-21 16:12:15 +02:00
|
|
|
{
|
2014-05-04 21:29:53 +02:00
|
|
|
struct stringtable *table = (struct stringtable*)hTable;
|
2005-09-21 16:12:15 +02:00
|
|
|
|
2014-05-04 21:29:53 +02:00
|
|
|
TRACE("%p\n", table);
|
2005-09-21 16:12:15 +02:00
|
|
|
|
2014-05-04 21:29:53 +02:00
|
|
|
if (!table)
|
|
|
|
return;
|
2005-09-21 16:12:15 +02:00
|
|
|
|
2014-05-04 21:29:53 +02:00
|
|
|
MyFree(table->data);
|
|
|
|
MyFree(table);
|
2005-09-21 16:12:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* StringTableDuplicate [SETUPAPI.@]
|
|
|
|
*
|
|
|
|
* Duplicates a given string table.
|
|
|
|
*
|
|
|
|
* PARAMS
|
2014-05-04 21:29:53 +02:00
|
|
|
* hTable [I] Handle to the string table
|
2005-09-21 16:12:15 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: Handle to the duplicated string table
|
|
|
|
* Failure: NULL
|
|
|
|
*
|
|
|
|
*/
|
2014-05-04 21:29:53 +02:00
|
|
|
HSTRING_TABLE WINAPI StringTableDuplicate(HSTRING_TABLE hTable)
|
2005-09-21 16:12:15 +02:00
|
|
|
{
|
2014-05-04 21:29:53 +02:00
|
|
|
struct stringtable *src = (struct stringtable*)hTable, *dest;
|
2005-09-21 16:12:15 +02:00
|
|
|
|
2014-05-04 21:29:53 +02:00
|
|
|
TRACE("%p\n", src);
|
2005-09-21 16:12:15 +02:00
|
|
|
|
2014-05-04 21:29:53 +02:00
|
|
|
if (!src)
|
2008-11-02 00:21:48 +01:00
|
|
|
return NULL;
|
2005-09-21 16:12:15 +02:00
|
|
|
|
2014-05-04 21:29:53 +02:00
|
|
|
dest = MyMalloc(sizeof(*dest));
|
|
|
|
if (!dest)
|
2008-11-02 00:21:48 +01:00
|
|
|
return NULL;
|
2005-09-21 16:12:15 +02:00
|
|
|
|
2014-05-04 21:29:53 +02:00
|
|
|
*dest = *src;
|
|
|
|
dest->data = MyMalloc(src->allocated);
|
|
|
|
if (!dest->data) {
|
|
|
|
MyFree(dest);
|
2008-11-02 00:21:48 +01:00
|
|
|
return NULL;
|
2005-09-21 16:12:15 +02:00
|
|
|
}
|
|
|
|
|
2014-05-04 21:29:53 +02:00
|
|
|
memcpy(dest->data, src->data, src->allocated);
|
|
|
|
return (HSTRING_TABLE)dest;
|
2005-09-21 16:12:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* StringTableGetExtraData [SETUPAPI.@]
|
|
|
|
*
|
|
|
|
* Retrieves extra data from a given string table entry.
|
|
|
|
*
|
|
|
|
* PARAMS
|
2014-05-04 21:29:53 +02:00
|
|
|
* hTable [I] Handle to the string table
|
|
|
|
* id [I] String ID
|
|
|
|
* extra [I] Pointer a buffer that receives the extra data
|
|
|
|
* extra_size [I] Size of the buffer
|
2005-09-21 16:12:15 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
|
|
|
*/
|
2014-05-04 21:29:53 +02:00
|
|
|
BOOL WINAPI StringTableGetExtraData(HSTRING_TABLE hTable, ULONG id, void *extra, ULONG extra_size)
|
2005-09-21 16:12:15 +02:00
|
|
|
{
|
2014-05-04 21:29:53 +02:00
|
|
|
struct stringtable *table = (struct stringtable*)hTable;
|
|
|
|
char *extraptr;
|
2005-09-21 16:12:15 +02:00
|
|
|
|
2014-05-04 21:29:53 +02:00
|
|
|
TRACE("%p %u %p %u\n", table, id, extra, extra_size);
|
2005-09-21 16:12:15 +02:00
|
|
|
|
2014-05-04 21:29:53 +02:00
|
|
|
if (!table)
|
2005-09-21 16:12:15 +02:00
|
|
|
return FALSE;
|
|
|
|
|
2014-05-04 21:29:53 +02:00
|
|
|
if (!is_valid_string_id(table, id))
|
2005-09-21 16:12:15 +02:00
|
|
|
return FALSE;
|
|
|
|
|
2014-05-04 21:29:53 +02:00
|
|
|
if (table->max_extra_size > extra_size)
|
2005-09-21 16:12:15 +02:00
|
|
|
{
|
2014-05-04 21:29:53 +02:00
|
|
|
ERR("data size is too large\n");
|
2005-09-21 16:12:15 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-05-04 21:29:53 +02:00
|
|
|
extraptr = get_extradata_ptr(table, id);
|
|
|
|
memcpy(extra, extraptr, extra_size);
|
2005-09-21 16:12:15 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
2009-01-06 10:38:49 +01:00
|
|
|
* StringTableLookUpStringEx [SETUPAPI.@]
|
2005-09-21 16:12:15 +02:00
|
|
|
*
|
2009-01-06 10:38:49 +01:00
|
|
|
* Searches a string table and extra data for a given string.
|
2005-09-21 16:12:15 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
2014-05-04 21:29:53 +02:00
|
|
|
* hTable [I] Handle to the string table
|
|
|
|
* string [I] String to be searched for
|
|
|
|
* flags [I] Flags
|
2005-09-21 16:12:15 +02:00
|
|
|
* 1: case sensitive compare
|
2014-05-04 21:29:53 +02:00
|
|
|
* extra [O] Pointer to the buffer that receives the extra data
|
|
|
|
* extra_size [I/O] Unused
|
2005-09-21 16:12:15 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: String ID
|
|
|
|
* Failure: -1
|
|
|
|
*/
|
2014-05-04 21:29:53 +02:00
|
|
|
DWORD WINAPI StringTableLookUpStringEx(HSTRING_TABLE hTable, LPWSTR string, DWORD flags,
|
|
|
|
void *extra, ULONG extra_size)
|
2005-09-21 16:12:15 +02:00
|
|
|
{
|
2014-05-04 21:29:53 +02:00
|
|
|
struct stringtable *table = (struct stringtable*)hTable;
|
|
|
|
BOOL case_sensitive = flags & 1;
|
|
|
|
struct stringentry *entry;
|
|
|
|
DWORD offset;
|
|
|
|
int cmp;
|
|
|
|
|
|
|
|
TRACE("%p->%p %s %x %p, %x\n", table, table->data, debugstr_w(string), flags, extra, extra_size);
|
|
|
|
|
|
|
|
if (!table)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* get corresponding offset */
|
|
|
|
offset = *get_bucket_ptr(table, string, case_sensitive);
|
|
|
|
if (offset == -1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* now we're at correct bucket, do linear search for string */
|
|
|
|
while (1) {
|
|
|
|
entry = (struct stringentry*)(table->data + offset);
|
|
|
|
if (case_sensitive)
|
2019-07-04 15:41:03 +02:00
|
|
|
cmp = wcscmp(entry->data, string);
|
2014-05-04 21:29:53 +02:00
|
|
|
else
|
|
|
|
cmp = lstrcmpiW(entry->data, string);
|
|
|
|
if (!cmp) {
|
|
|
|
if (extra)
|
|
|
|
memcpy(extra, get_extradata_ptr(table, offset), extra_size);
|
|
|
|
return offset;
|
|
|
|
}
|
2005-09-21 16:12:15 +02:00
|
|
|
|
2014-05-04 21:29:53 +02:00
|
|
|
/* last entry */
|
|
|
|
if (entry->nextoffset == -1)
|
|
|
|
return -1;
|
2005-09-21 16:12:15 +02:00
|
|
|
|
2014-05-04 21:29:53 +02:00
|
|
|
offset = entry->nextoffset;
|
|
|
|
if (offset > table->allocated)
|
|
|
|
return -1;
|
2005-09-21 16:12:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
2009-01-06 10:38:49 +01:00
|
|
|
* StringTableLookUpString [SETUPAPI.@]
|
2005-09-21 16:12:15 +02:00
|
|
|
*
|
2009-01-06 10:38:49 +01:00
|
|
|
* Searches a string table for a given string.
|
2005-09-21 16:12:15 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
2014-05-04 21:29:53 +02:00
|
|
|
* hTable [I] Handle to the string table
|
|
|
|
* string [I] String to be searched for
|
|
|
|
* flags [I] Flags
|
|
|
|
* 1: case sensitive compare
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: String ID
|
|
|
|
* Failure: -1
|
|
|
|
*/
|
|
|
|
DWORD WINAPI StringTableLookUpString(HSTRING_TABLE hTable, LPWSTR string, DWORD flags)
|
|
|
|
{
|
|
|
|
return StringTableLookUpStringEx(hTable, string, flags, NULL, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* StringTableAddStringEx [SETUPAPI.@]
|
|
|
|
*
|
|
|
|
* Adds a new string plus extra data to the string table.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hTable [I] Handle to the string table
|
|
|
|
* string [I] String to be added to the string table
|
|
|
|
* flags [I] Flags
|
|
|
|
* 1: case sensitive compare
|
|
|
|
* extra [I] Pointer to the extra data
|
|
|
|
* extra_size [I] Size of the extra data
|
2005-09-21 16:12:15 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: String ID
|
2014-05-04 21:29:53 +02:00
|
|
|
* Failure: -1
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* If the given string already exists in the string table it will not
|
|
|
|
* be added again. The ID of the existing string will be returned in
|
|
|
|
* this case.
|
2005-09-21 16:12:15 +02:00
|
|
|
*/
|
2014-05-04 21:29:53 +02:00
|
|
|
DWORD WINAPI StringTableAddStringEx(HSTRING_TABLE hTable, LPWSTR string,
|
|
|
|
DWORD flags, void *extra, DWORD extra_size)
|
2005-09-21 16:12:15 +02:00
|
|
|
{
|
2014-05-04 21:29:53 +02:00
|
|
|
struct stringtable *table = (struct stringtable*)hTable;
|
|
|
|
BOOL case_sensitive = flags & 1;
|
|
|
|
struct stringentry *entry;
|
|
|
|
DWORD id, *offset;
|
|
|
|
WCHAR *ptrW;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
TRACE("%p %s %x %p, %u\n", hTable, debugstr_w(string), flags, extra, extra_size);
|
|
|
|
|
|
|
|
if (!table)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
id = StringTableLookUpStringEx(hTable, string, flags, NULL, 0);
|
|
|
|
if (id != -1)
|
|
|
|
return id;
|
|
|
|
|
|
|
|
/* needed space for new record */
|
2019-07-04 15:41:03 +02:00
|
|
|
len = sizeof(DWORD) + (lstrlenW(string)+1)*sizeof(WCHAR) + table->max_extra_size;
|
2014-05-04 21:29:53 +02:00
|
|
|
if (table->nextoffset + len >= table->allocated) {
|
|
|
|
table->allocated <<= 1;
|
|
|
|
table->data = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, table->data, table->allocated);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* hash string */
|
|
|
|
offset = get_bucket_ptr(table, string, case_sensitive);
|
|
|
|
if (*offset == -1)
|
|
|
|
/* bucket used for a very first time */
|
|
|
|
*offset = table->nextoffset;
|
|
|
|
else {
|
|
|
|
entry = (struct stringentry*)(table->data + *offset);
|
|
|
|
/* link existing last entry to newly added */
|
|
|
|
while (entry->nextoffset != -1)
|
|
|
|
entry = (struct stringentry*)(table->data + entry->nextoffset);
|
|
|
|
entry->nextoffset = table->nextoffset;
|
|
|
|
}
|
|
|
|
entry = (struct stringentry*)(table->data + table->nextoffset);
|
|
|
|
entry->nextoffset = -1;
|
|
|
|
id = table->nextoffset;
|
|
|
|
|
|
|
|
/* copy string */
|
|
|
|
ptrW = get_string_ptr(table, id);
|
2019-07-04 15:41:03 +02:00
|
|
|
lstrcpyW(ptrW, string);
|
2014-05-04 21:29:53 +02:00
|
|
|
if (!case_sensitive)
|
2019-07-04 15:41:03 +02:00
|
|
|
wcslwr(ptrW);
|
2014-05-04 21:29:53 +02:00
|
|
|
|
|
|
|
/* copy extra data */
|
|
|
|
if (extra)
|
|
|
|
memcpy(get_extradata_ptr(table, id), extra, extra_size);
|
|
|
|
|
|
|
|
table->nextoffset += len;
|
|
|
|
return id;
|
2005-09-21 16:12:15 +02:00
|
|
|
}
|
|
|
|
|
2014-05-04 21:29:53 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* StringTableAddString [SETUPAPI.@]
|
|
|
|
*
|
|
|
|
* Adds a new string to the string table.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hTable [I] Handle to the string table
|
|
|
|
* string [I] String to be added to the string table
|
|
|
|
* flags [I] Flags
|
|
|
|
* 1: case sensitive compare
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: String ID
|
|
|
|
* Failure: -1
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* If the given string already exists in the string table it will not
|
|
|
|
* be added again. The ID of the existing string will be returned in
|
|
|
|
* this case.
|
|
|
|
*/
|
|
|
|
DWORD WINAPI StringTableAddString(HSTRING_TABLE hTable, LPWSTR string, DWORD flags)
|
|
|
|
{
|
|
|
|
return StringTableAddStringEx(hTable, string, flags, NULL, 0);
|
|
|
|
}
|
2005-09-21 16:12:15 +02:00
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* StringTableSetExtraData [SETUPAPI.@]
|
|
|
|
*
|
|
|
|
* Sets extra data for a given string table entry.
|
|
|
|
*
|
|
|
|
* PARAMS
|
2014-05-04 21:29:53 +02:00
|
|
|
* hTable [I] Handle to the string table
|
|
|
|
* id [I] String ID
|
|
|
|
* extra [I] Pointer to the extra data
|
|
|
|
* extra_size [I] Size of the extra data
|
2005-09-21 16:12:15 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
|
|
|
*/
|
2014-05-04 21:29:53 +02:00
|
|
|
BOOL WINAPI StringTableSetExtraData(HSTRING_TABLE hTable, DWORD id, void *extra, ULONG extra_size)
|
2005-09-21 16:12:15 +02:00
|
|
|
{
|
2014-05-04 21:29:53 +02:00
|
|
|
struct stringtable *table = (struct stringtable*)hTable;
|
|
|
|
char *extraptr;
|
2005-09-21 16:12:15 +02:00
|
|
|
|
2014-05-04 21:29:53 +02:00
|
|
|
TRACE("%p %d %p %u\n", hTable, id, extra, extra_size);
|
2005-09-21 16:12:15 +02:00
|
|
|
|
2014-05-04 21:29:53 +02:00
|
|
|
if (!table)
|
2005-09-21 16:12:15 +02:00
|
|
|
return FALSE;
|
|
|
|
|
2014-05-04 21:29:53 +02:00
|
|
|
if (!is_valid_string_id(table, id))
|
2005-09-21 16:12:15 +02:00
|
|
|
return FALSE;
|
|
|
|
|
2014-05-04 21:29:53 +02:00
|
|
|
if (table->max_extra_size < extra_size)
|
2005-09-21 16:12:15 +02:00
|
|
|
{
|
2014-05-04 21:29:53 +02:00
|
|
|
ERR("data size is too large\n");
|
2005-09-21 16:12:15 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-05-04 21:29:53 +02:00
|
|
|
extraptr = get_extradata_ptr(table, id);
|
|
|
|
memset(extraptr, 0, table->max_extra_size);
|
|
|
|
memcpy(extraptr, extra, extra_size);
|
2005-09-21 16:12:15 +02:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* StringTableStringFromId [SETUPAPI.@]
|
|
|
|
*
|
|
|
|
* Returns a pointer to a string for the given string ID.
|
|
|
|
*
|
|
|
|
* PARAMS
|
2014-05-04 21:29:53 +02:00
|
|
|
* hTable [I] Handle to the string table.
|
|
|
|
* id [I] String ID
|
2005-09-21 16:12:15 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: Pointer to the string
|
|
|
|
* Failure: NULL
|
|
|
|
*/
|
2014-05-04 21:29:53 +02:00
|
|
|
LPWSTR WINAPI StringTableStringFromId(HSTRING_TABLE hTable, ULONG id)
|
2005-09-21 16:12:15 +02:00
|
|
|
{
|
2014-05-04 21:29:53 +02:00
|
|
|
struct stringtable *table = (struct stringtable*)hTable;
|
2005-09-23 12:09:47 +02:00
|
|
|
static WCHAR empty[] = {0};
|
2005-09-21 16:12:15 +02:00
|
|
|
|
2014-05-04 21:29:53 +02:00
|
|
|
TRACE("%p %d\n", table, id);
|
2005-09-21 16:12:15 +02:00
|
|
|
|
2014-05-04 21:29:53 +02:00
|
|
|
if (!table)
|
2005-09-21 16:12:15 +02:00
|
|
|
return NULL;
|
|
|
|
|
2014-05-04 21:29:53 +02:00
|
|
|
if (!is_valid_string_id(table, id))
|
2005-09-23 12:09:47 +02:00
|
|
|
return empty;
|
2005-09-21 16:12:15 +02:00
|
|
|
|
2014-05-04 21:29:53 +02:00
|
|
|
return get_string_ptr(table, id);
|
2005-09-21 16:12:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* StringTableStringFromIdEx [SETUPAPI.@]
|
|
|
|
*
|
|
|
|
* Returns a string for the given string ID.
|
|
|
|
*
|
|
|
|
* PARAMS
|
2014-05-04 21:29:53 +02:00
|
|
|
* hTable [I] Handle to the string table
|
|
|
|
* id [I] String ID
|
|
|
|
* buff [I] Pointer to string buffer
|
|
|
|
* buflen [I/O] Pointer to the size of the string buffer
|
2005-09-21 16:12:15 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
|
|
|
*/
|
2014-05-04 21:29:53 +02:00
|
|
|
BOOL WINAPI StringTableStringFromIdEx(HSTRING_TABLE hTable, ULONG id, LPWSTR buff, DWORD *buflen)
|
2005-09-21 16:12:15 +02:00
|
|
|
{
|
2014-05-04 21:29:53 +02:00
|
|
|
struct stringtable *table = (struct stringtable*)hTable;
|
|
|
|
BOOL ret = TRUE;
|
|
|
|
WCHAR *ptrW;
|
|
|
|
int len;
|
2005-09-21 16:12:15 +02:00
|
|
|
|
2014-05-04 21:29:53 +02:00
|
|
|
TRACE("%p %x %p %p\n", table, id, buff, buflen);
|
2005-09-21 16:12:15 +02:00
|
|
|
|
2014-05-04 21:29:53 +02:00
|
|
|
if (!table) {
|
|
|
|
*buflen = 0;
|
2005-09-21 16:12:15 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-05-04 21:29:53 +02:00
|
|
|
if (!is_valid_string_id(table, id)) {
|
|
|
|
WARN("invalid string id\n");
|
|
|
|
*buflen = 0;
|
2005-09-21 16:12:15 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-05-04 21:29:53 +02:00
|
|
|
ptrW = get_string_ptr(table, id);
|
2019-07-04 15:41:03 +02:00
|
|
|
len = (lstrlenW(ptrW) + 1)*sizeof(WCHAR);
|
2014-05-04 21:29:53 +02:00
|
|
|
if (len <= *buflen)
|
2019-07-04 15:41:03 +02:00
|
|
|
lstrcpyW(buff, ptrW);
|
2014-05-04 21:29:53 +02:00
|
|
|
else
|
|
|
|
ret = FALSE;
|
2005-09-21 16:12:15 +02:00
|
|
|
|
2014-05-04 21:29:53 +02:00
|
|
|
*buflen = len;
|
|
|
|
return ret;
|
2005-09-21 16:12:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* StringTableTrim [SETUPAPI.@]
|
|
|
|
*
|
|
|
|
* ...
|
|
|
|
*
|
|
|
|
* PARAMS
|
2014-05-04 21:29:53 +02:00
|
|
|
* hTable [I] Handle to the string table
|
2005-09-21 16:12:15 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* None
|
|
|
|
*/
|
2014-05-04 21:29:53 +02:00
|
|
|
void WINAPI StringTableTrim(HSTRING_TABLE hTable)
|
2005-09-21 16:12:15 +02:00
|
|
|
{
|
2014-05-04 21:29:53 +02:00
|
|
|
FIXME("%p\n", hTable);
|
2005-09-21 16:12:15 +02:00
|
|
|
}
|