urlmon: Make protocol_start IUri-based.
[wine/multimedia.git] / dlls / propsys / propsys_main.c
blob6c4678195538c3925fc97aa33b6fc651966b0daf
1 /*
2 * propsys main
4 * Copyright 1997, 2002 Alexandre Julliard
5 * Copyright 2008 James Hawkins
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
22 #include "config.h"
24 #include <stdarg.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "objbase.h"
29 #include "propsys.h"
30 #include "wine/debug.h"
31 #include "wine/unicode.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(propsys);
35 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
37 TRACE("(0x%p, %d, %p)\n", hinstDLL, fdwReason, lpvReserved);
39 switch (fdwReason)
41 case DLL_WINE_PREATTACH:
42 return FALSE; /* prefer native version */
43 case DLL_PROCESS_ATTACH:
44 DisableThreadLibraryCalls(hinstDLL);
45 break;
46 case DLL_PROCESS_DETACH:
47 break;
48 default:
49 break;
52 return TRUE;
55 HRESULT WINAPI PSRegisterPropertySchema(PCWSTR path)
57 FIXME("%s stub\n", debugstr_w(path));
59 return S_OK;
62 HRESULT WINAPI PSUnregisterPropertySchema(PCWSTR path)
64 FIXME("%s stub\n", debugstr_w(path));
66 return E_NOTIMPL;
69 HRESULT WINAPI PSStringFromPropertyKey(REFPROPERTYKEY pkey, LPWSTR psz, UINT cch)
71 static const WCHAR guid_fmtW[] = {'{','%','0','8','X','-','%','0','4','X','-',
72 '%','0','4','X','-','%','0','2','X','%','0','2','X','-',
73 '%','0','2','X','%','0','2','X','%','0','2','X',
74 '%','0','2','X','%','0','2','X','%','0','2','X','}',0};
75 static const WCHAR pid_fmtW[] = {'%','u',0};
77 WCHAR pidW[PKEY_PIDSTR_MAX + 1];
78 LPWSTR p = psz;
79 int len;
81 TRACE("(%p, %p, %u)\n", pkey, psz, cch);
83 if (!psz)
84 return E_POINTER;
86 /* GUIDSTRING_MAX accounts for null terminator, +1 for space character. */
87 if (cch <= GUIDSTRING_MAX + 1)
88 return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
90 if (!pkey)
92 psz[0] = '\0';
93 return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
96 sprintfW(psz, guid_fmtW, pkey->fmtid.Data1, pkey->fmtid.Data2,
97 pkey->fmtid.Data3, pkey->fmtid.Data4[0], pkey->fmtid.Data4[1],
98 pkey->fmtid.Data4[2], pkey->fmtid.Data4[3], pkey->fmtid.Data4[4],
99 pkey->fmtid.Data4[5], pkey->fmtid.Data4[6], pkey->fmtid.Data4[7]);
101 /* Overwrite the null terminator with the space character. */
102 p += GUIDSTRING_MAX - 1;
103 *p++ = ' ';
104 cch -= GUIDSTRING_MAX - 1 + 1;
106 len = sprintfW(pidW, pid_fmtW, pkey->pid);
108 if (cch >= len + 1)
110 strcpyW(p, pidW);
111 return S_OK;
113 else
115 WCHAR *ptr = pidW + len - 1;
117 psz[0] = '\0';
118 *p++ = '\0';
119 cch--;
121 /* Replicate a quirk of the native implementation where the contents
122 * of the property ID string are written backwards to the output
123 * buffer, skipping the rightmost digit. */
124 if (cch)
126 ptr--;
127 while (cch--)
128 *p++ = *ptr--;
131 return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
135 static const BYTE hex2bin[] =
137 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x00 */
138 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x10 */
139 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x20 */
140 0,1,2,3,4,5,6,7,8,9,0,0,0,0,0,0, /* 0x30 */
141 0,10,11,12,13,14,15,0,0,0,0,0,0,0,0,0, /* 0x40 */
142 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x50 */
143 0,10,11,12,13,14,15 /* 0x60 */
146 static BOOL validate_indices(LPCWSTR s, int min, int max)
148 int i;
150 for (i = min; i <= max; i++)
152 if (!s[i])
153 return FALSE;
155 if (i == 0)
157 if (s[i] != '{')
158 return FALSE;
160 else if (i == 9 || i == 14 || i == 19 || i == 24)
162 if (s[i] != '-')
163 return FALSE;
165 else if (i == 37)
167 if (s[i] != '}')
168 return FALSE;
170 else
172 if (s[i] > 'f' || (!hex2bin[s[i]] && s[i] != '0'))
173 return FALSE;
177 return TRUE;
180 /* Adapted from CLSIDFromString helper in dlls/ole32/compobj.c and
181 * UuidFromString in dlls/rpcrt4/rpcrt4_main.c. */
182 static BOOL string_to_guid(LPCWSTR s, LPGUID id)
184 /* in form {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX} */
186 if (!validate_indices(s, 0, 8)) return FALSE;
187 id->Data1 = (hex2bin[s[1]] << 28 | hex2bin[s[2]] << 24 | hex2bin[s[3]] << 20 | hex2bin[s[4]] << 16 |
188 hex2bin[s[5]] << 12 | hex2bin[s[6]] << 8 | hex2bin[s[7]] << 4 | hex2bin[s[8]]);
189 if (!validate_indices(s, 9, 14)) return FALSE;
190 id->Data2 = hex2bin[s[10]] << 12 | hex2bin[s[11]] << 8 | hex2bin[s[12]] << 4 | hex2bin[s[13]];
191 if (!validate_indices(s, 15, 19)) return FALSE;
192 id->Data3 = hex2bin[s[15]] << 12 | hex2bin[s[16]] << 8 | hex2bin[s[17]] << 4 | hex2bin[s[18]];
194 /* these are just sequential bytes */
196 if (!validate_indices(s, 20, 21)) return FALSE;
197 id->Data4[0] = hex2bin[s[20]] << 4 | hex2bin[s[21]];
198 if (!validate_indices(s, 22, 24)) return FALSE;
199 id->Data4[1] = hex2bin[s[22]] << 4 | hex2bin[s[23]];
201 if (!validate_indices(s, 25, 26)) return FALSE;
202 id->Data4[2] = hex2bin[s[25]] << 4 | hex2bin[s[26]];
203 if (!validate_indices(s, 27, 28)) return FALSE;
204 id->Data4[3] = hex2bin[s[27]] << 4 | hex2bin[s[28]];
205 if (!validate_indices(s, 29, 30)) return FALSE;
206 id->Data4[4] = hex2bin[s[29]] << 4 | hex2bin[s[30]];
207 if (!validate_indices(s, 31, 32)) return FALSE;
208 id->Data4[5] = hex2bin[s[31]] << 4 | hex2bin[s[32]];
209 if (!validate_indices(s, 33, 34)) return FALSE;
210 id->Data4[6] = hex2bin[s[33]] << 4 | hex2bin[s[34]];
211 if (!validate_indices(s, 35, 37)) return FALSE;
212 id->Data4[7] = hex2bin[s[35]] << 4 | hex2bin[s[36]];
214 return TRUE;
217 HRESULT WINAPI PSPropertyKeyFromString(LPCWSTR pszString, PROPERTYKEY *pkey)
219 int has_minus = 0, has_comma = 0;
221 TRACE("(%s, %p)\n", debugstr_w(pszString), pkey);
223 if (!pszString || !pkey)
224 return E_POINTER;
226 memset(pkey, 0, sizeof(PROPERTYKEY));
228 if (!string_to_guid(pszString, &pkey->fmtid))
229 return E_INVALIDARG;
231 pszString += GUIDSTRING_MAX - 1;
233 if (!*pszString)
234 return E_INVALIDARG;
236 /* Only the space seems to be recognized as whitespace. The comma is only
237 * recognized once and processing terminates if another comma is found. */
238 while (*pszString == ' ' || *pszString == ',')
240 if (*pszString == ',')
242 if (has_comma)
243 return S_OK;
244 else
245 has_comma = 1;
247 pszString++;
250 if (!*pszString)
251 return E_INVALIDARG;
253 /* Only two minus signs are recognized if no comma is detected. The first
254 * sign is ignored, and the second is interpreted. If a comma is detected
255 * before the minus sign, then only one minus sign counts, and property ID
256 * interpretation begins with the next character. */
257 if (has_comma)
259 if (*pszString == '-')
261 has_minus = 1;
262 pszString++;
265 else
267 if (*pszString == '-')
268 pszString++;
270 /* Skip any intermediate spaces after the first minus sign. */
271 while (*pszString == ' ')
272 pszString++;
274 if (*pszString == '-')
276 has_minus = 1;
277 pszString++;
280 /* Skip any remaining spaces after minus sign. */
281 while (*pszString == ' ')
282 pszString++;
285 /* Overflow is not checked. */
286 while (isdigitW(*pszString))
288 pkey->pid *= 10;
289 pkey->pid += (*pszString - '0');
290 pszString++;
293 if (has_minus)
294 pkey->pid = ~pkey->pid + 1;
296 return S_OK;