1 | /* $Id: DnDPath.cpp 69500 2017-10-28 15:14:05Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * DnD - Path handling.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2014-2017 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 |
|
---|
19 | /*********************************************************************************************************************************
|
---|
20 | * Header Files *
|
---|
21 | *********************************************************************************************************************************/
|
---|
22 |
|
---|
23 | #include <iprt/path.h>
|
---|
24 | #include <iprt/string.h>
|
---|
25 |
|
---|
26 | #include <VBox/GuestHost/DragAndDrop.h>
|
---|
27 |
|
---|
28 | /**
|
---|
29 | * Sanitizes the file name component so that unsupported characters
|
---|
30 | * will be replaced by an underscore ("_").
|
---|
31 | *
|
---|
32 | * @return IPRT status code.
|
---|
33 | * @param pszPath Path to sanitize.
|
---|
34 | * @param cbPath Size (in bytes) of path to sanitize.
|
---|
35 | */
|
---|
36 | int DnDPathSanitizeFilename(char *pszPath, size_t cbPath)
|
---|
37 | {
|
---|
38 | int rc = VINF_SUCCESS;
|
---|
39 | #ifdef RT_OS_WINDOWS
|
---|
40 | RT_NOREF1(cbPath);
|
---|
41 | /* Replace out characters not allowed on Windows platforms, put in by RTTimeSpecToString(). */
|
---|
42 | /** @todo Use something like RTPathSanitize() if available later some time. */
|
---|
43 | static const RTUNICP s_uszValidRangePairs[] =
|
---|
44 | {
|
---|
45 | ' ', ' ',
|
---|
46 | '(', ')',
|
---|
47 | '-', '.',
|
---|
48 | '0', '9',
|
---|
49 | 'A', 'Z',
|
---|
50 | 'a', 'z',
|
---|
51 | '_', '_',
|
---|
52 | 0xa0, 0xd7af,
|
---|
53 | '\0'
|
---|
54 | };
|
---|
55 | ssize_t cReplaced = RTStrPurgeComplementSet(pszPath, s_uszValidRangePairs, '_' /* chReplacement */);
|
---|
56 | if (cReplaced < 0)
|
---|
57 | rc = VERR_INVALID_UTF8_ENCODING;
|
---|
58 | #else
|
---|
59 | RT_NOREF2(pszPath, cbPath);
|
---|
60 | #endif
|
---|
61 | return rc;
|
---|
62 | }
|
---|
63 |
|
---|
64 | int DnDPathSanitize(char *pszPath, size_t cbPath)
|
---|
65 | {
|
---|
66 | /** @todo */
|
---|
67 | RT_NOREF2(pszPath, cbPath);
|
---|
68 | return VINF_SUCCESS;
|
---|
69 | }
|
---|
70 |
|
---|