Alien-SVN
view release on metacpan or search on metacpan
src/subversion/subversion/libsvn_subr/config_win.c view on Meta::CPAN
#include "svn_private_config.h"
#ifdef WIN32
/* We must include windows.h ourselves or apr.h includes it for us with
many ignore options set. Including Winsock is required to resolve IPv6
compilation errors. APR_HAVE_IPV6 is only defined after including
apr.h, so we can't detect this case here. */
#define WIN32_LEAN_AND_MEAN
/* winsock2.h includes windows.h */
#include <winsock2.h>
#include <Ws2tcpip.h>
#include <shlobj.h>
#include <apr_file_info.h>
#include "svn_error.h"
#include "svn_path.h"
#include "svn_pools.h"
#include "svn_utf.h"
svn_error_t *
svn_config__win_config_path(const char **folder, int system_path,
apr_pool_t *pool)
{
/* ### Adding CSIDL_FLAG_CREATE here, because those folders really
must exist. I'm not too sure about the SHGFP_TYPE_CURRENT
semancics, though; maybe we should use ..._DEFAULT instead? */
const int csidl = ((system_path ? CSIDL_COMMON_APPDATA : CSIDL_APPDATA)
| CSIDL_FLAG_CREATE);
WCHAR folder_ucs2[MAX_PATH];
int inwords, outbytes, outlength;
char *folder_utf8;
if (S_OK != SHGetFolderPathW(NULL, csidl, NULL, SHGFP_TYPE_CURRENT,
folder_ucs2))
return svn_error_create(SVN_ERR_BAD_FILENAME, NULL,
(system_path
? "Can't determine the system config path"
: "Can't determine the user's config path"));
/* ### When mapping from UCS-2 to UTF-8, we need at most 3 bytes
per wide char, plus extra space for the nul terminator. */
inwords = lstrlenW(folder_ucs2);
outbytes = outlength = 3 * (inwords + 1);
folder_utf8 = apr_palloc(pool, outlength);
outbytes = WideCharToMultiByte(CP_UTF8, 0, folder_ucs2, inwords,
folder_utf8, outbytes, NULL, NULL);
if (outbytes == 0)
return svn_error_wrap_apr(apr_get_os_error(),
"Can't convert config path to UTF-8");
/* Note that WideCharToMultiByte does _not_ terminate the
outgoing buffer. */
folder_utf8[outbytes] = '\0';
*folder = folder_utf8;
return SVN_NO_ERROR;
}
#include "config_impl.h"
/* ### These constants are insanely large, but (a) we want to avoid
reallocating strings if possible, and (b) the realloc logic might
not actually work -- you never know with Win32 ... */
#define SVN_REG_DEFAULT_NAME_SIZE 2048
#define SVN_REG_DEFAULT_VALUE_SIZE 8192
static svn_error_t *
parse_section(svn_config_t *cfg, HKEY hkey, const char *section,
svn_stringbuf_t *option, svn_stringbuf_t *value)
{
DWORD option_len, type, index;
LONG err;
/* Start with a reasonable size for the buffers. */
svn_stringbuf_ensure(option, SVN_REG_DEFAULT_NAME_SIZE);
svn_stringbuf_ensure(value, SVN_REG_DEFAULT_VALUE_SIZE);
for (index = 0; ; ++index)
{
option_len = (DWORD)option->blocksize;
err = RegEnumValue(hkey, index, option->data, &option_len,
NULL, &type, NULL, NULL);
if (err == ERROR_NO_MORE_ITEMS)
break;
if (err == ERROR_INSUFFICIENT_BUFFER)
{
svn_stringbuf_ensure(option, option_len);
err = RegEnumValue(hkey, index, option->data, &option_len,
NULL, &type, NULL, NULL);
}
if (err != ERROR_SUCCESS)
return svn_error_create(SVN_ERR_MALFORMED_FILE, NULL,
"Can't enumerate registry values");
/* Ignore option names that start with '#', see
http://subversion.tigris.org/issues/show_bug.cgi?id=671 */
if (type == REG_SZ && option->data[0] != '#')
{
DWORD value_len = (DWORD)value->blocksize;
err = RegQueryValueEx(hkey, option->data, NULL, NULL,
(LPBYTE)value->data, &value_len);
if (err == ERROR_MORE_DATA)
{
svn_stringbuf_ensure(value, value_len);
err = RegQueryValueEx(hkey, option->data, NULL, NULL,
(LPBYTE)value->data, &value_len);
}
if (err != ERROR_SUCCESS)
return svn_error_create(SVN_ERR_MALFORMED_FILE, NULL,
"Can't read registry value data");
( run in 1.044 second using v1.01-cache-2.11-cpan-524268b4103 )