Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
dCache
cta
Commits
d2ce4eb3
Commit
d2ce4eb3
authored
Jul 10, 2014
by
Steven Murray
Browse files
castor::utils::copyString() now takes an std::string as the src
parent
a36c9b84
Changes
10
Hide whitespace changes
Inline
Side-by-side
castor/legacymsg/CupvProxyTcpIp.cpp
View file @
d2ce4eb3
...
...
@@ -71,8 +71,8 @@ bool castor::legacymsg::CupvProxyTcpIp::isGranted(
body
.
gid
=
getegid
();
body
.
privUid
=
privUid
;
body
.
privGid
=
privGid
;
utils
::
copyString
(
body
.
srcHost
,
srcHost
.
c_str
()
);
utils
::
copyString
(
body
.
tgtHost
,
tgtHost
.
c_str
()
);
utils
::
copyString
(
body
.
srcHost
,
srcHost
);
utils
::
copyString
(
body
.
tgtHost
,
tgtHost
);
body
.
priv
=
priv
;
writeCupvCheckMsg
(
fd
.
get
(),
body
);
...
...
castor/legacymsg/RmcProxyTcpIp.cpp
View file @
d2ce4eb3
...
...
@@ -130,7 +130,7 @@ void castor::legacymsg::RmcProxyTcpIp::mountTapeScsi(const std::string &vid, con
RmcMountMsgBody
body
;
body
.
uid
=
geteuid
();
body
.
gid
=
getegid
();
castor
::
utils
::
copyString
(
body
.
vid
,
vid
.
c_str
()
);
castor
::
utils
::
copyString
(
body
.
vid
,
vid
);
body
.
drvOrd
=
parsedSlot
.
drvOrd
;
writeRmcMountMsg
(
fd
.
get
(),
body
);
...
...
@@ -245,7 +245,7 @@ void castor::legacymsg::RmcProxyTcpIp::unmountTapeScsi(const std::string &vid, c
RmcUnmountMsgBody
body
;
body
.
uid
=
geteuid
();
body
.
gid
=
getegid
();
castor
::
utils
::
copyString
(
body
.
vid
,
vid
.
c_str
()
);
castor
::
utils
::
copyString
(
body
.
vid
,
vid
);
body
.
drvOrd
=
parsedSlot
.
drvOrd
;
body
.
force
=
0
;
writeRmcUnmountMsg
(
fd
.
get
(),
body
);
...
...
castor/legacymsg/VdqmProxyTcpIp.cpp
View file @
d2ce4eb3
...
...
@@ -52,9 +52,9 @@ void castor::legacymsg::VdqmProxyTcpIp::setDriveDown(const std::string &server,
try
{
legacymsg
::
VdqmDrvRqstMsgBody
body
;
body
.
status
=
VDQM_UNIT_DOWN
;
castor
::
utils
::
copyString
(
body
.
server
,
server
.
c_str
()
);
castor
::
utils
::
copyString
(
body
.
drive
,
unitName
.
c_str
()
);
castor
::
utils
::
copyString
(
body
.
dgn
,
dgn
.
c_str
()
);
castor
::
utils
::
copyString
(
body
.
server
,
server
);
castor
::
utils
::
copyString
(
body
.
drive
,
unitName
);
castor
::
utils
::
copyString
(
body
.
dgn
,
dgn
);
setDriveStatus
(
body
);
}
catch
(
castor
::
exception
::
Exception
&
ne
)
{
...
...
@@ -72,9 +72,9 @@ void castor::legacymsg::VdqmProxyTcpIp::setDriveUp(const std::string &server, co
try
{
legacymsg
::
VdqmDrvRqstMsgBody
body
;
body
.
status
=
VDQM_UNIT_UP
;
castor
::
utils
::
copyString
(
body
.
server
,
server
.
c_str
()
);
castor
::
utils
::
copyString
(
body
.
drive
,
unitName
.
c_str
()
);
castor
::
utils
::
copyString
(
body
.
dgn
,
dgn
.
c_str
()
);
castor
::
utils
::
copyString
(
body
.
server
,
server
);
castor
::
utils
::
copyString
(
body
.
drive
,
unitName
);
castor
::
utils
::
copyString
(
body
.
dgn
,
dgn
);
setDriveStatus
(
body
);
}
catch
(
castor
::
exception
::
Exception
&
ne
)
{
...
...
@@ -94,9 +94,9 @@ void castor::legacymsg::VdqmProxyTcpIp::assignDrive(const std::string &server, c
body
.
status
=
VDQM_UNIT_ASSIGN
;
body
.
volReqId
=
mountTransactionId
;
body
.
jobId
=
sessionPid
;
castor
::
utils
::
copyString
(
body
.
server
,
server
.
c_str
()
);
castor
::
utils
::
copyString
(
body
.
drive
,
unitName
.
c_str
()
);
castor
::
utils
::
copyString
(
body
.
dgn
,
dgn
.
c_str
()
);
castor
::
utils
::
copyString
(
body
.
server
,
server
);
castor
::
utils
::
copyString
(
body
.
drive
,
unitName
);
castor
::
utils
::
copyString
(
body
.
dgn
,
dgn
);
setDriveStatus
(
body
);
}
catch
(
castor
::
exception
::
Exception
&
ne
)
{
...
...
@@ -118,10 +118,10 @@ void castor::legacymsg::VdqmProxyTcpIp::tapeMounted(const std::string &server,
legacymsg
::
VdqmDrvRqstMsgBody
body
;
body
.
status
=
VDQM_VOL_MOUNT
;
body
.
jobId
=
sessionPid
;
castor
::
utils
::
copyString
(
body
.
volId
,
vid
.
c_str
()
);
castor
::
utils
::
copyString
(
body
.
server
,
server
.
c_str
()
);
castor
::
utils
::
copyString
(
body
.
drive
,
unitName
.
c_str
()
);
castor
::
utils
::
copyString
(
body
.
dgn
,
dgn
.
c_str
()
);
castor
::
utils
::
copyString
(
body
.
volId
,
vid
);
castor
::
utils
::
copyString
(
body
.
server
,
server
);
castor
::
utils
::
copyString
(
body
.
drive
,
unitName
);
castor
::
utils
::
copyString
(
body
.
dgn
,
dgn
);
setDriveStatus
(
body
);
}
catch
(
castor
::
exception
::
Exception
&
ne
)
{
...
...
@@ -148,9 +148,9 @@ void castor::legacymsg::VdqmProxyTcpIp::releaseDrive(const std::string &server,
legacymsg
::
VdqmDrvRqstMsgBody
body
;
body
.
status
=
status
;
body
.
jobId
=
sessionPid
;
castor
::
utils
::
copyString
(
body
.
server
,
server
.
c_str
()
);
castor
::
utils
::
copyString
(
body
.
drive
,
unitName
.
c_str
()
);
castor
::
utils
::
copyString
(
body
.
dgn
,
dgn
.
c_str
()
);
castor
::
utils
::
copyString
(
body
.
server
,
server
);
castor
::
utils
::
copyString
(
body
.
drive
,
unitName
);
castor
::
utils
::
copyString
(
body
.
dgn
,
dgn
);
setDriveStatus
(
body
);
}
catch
(
castor
::
exception
::
Exception
&
ne
)
{
...
...
@@ -374,10 +374,10 @@ void castor::legacymsg::VdqmProxyTcpIp::tapeUnmounted(const std::string &server
try
{
legacymsg
::
VdqmDrvRqstMsgBody
body
;
body
.
status
=
status
;
castor
::
utils
::
copyString
(
body
.
volId
,
vid
.
c_str
()
);
castor
::
utils
::
copyString
(
body
.
server
,
server
.
c_str
()
);
castor
::
utils
::
copyString
(
body
.
drive
,
unitName
.
c_str
()
);
castor
::
utils
::
copyString
(
body
.
dgn
,
dgn
.
c_str
()
);
castor
::
utils
::
copyString
(
body
.
volId
,
vid
);
castor
::
utils
::
copyString
(
body
.
server
,
server
);
castor
::
utils
::
copyString
(
body
.
drive
,
unitName
);
castor
::
utils
::
copyString
(
body
.
dgn
,
dgn
);
setDriveStatus
(
body
);
}
catch
(
castor
::
exception
::
Exception
&
ne
)
{
...
...
castor/legacymsg/VmgrProxyTcpIp.cpp
View file @
d2ce4eb3
...
...
@@ -151,7 +151,7 @@ void castor::legacymsg::VmgrProxyTcpIp::tapeMountedForRead(const std::string &vi
msg
.
gid
=
getegid
();
msg
.
jid
=
getpid
();
msg
.
mode
=
WRITE_DISABLE
;
castor
::
utils
::
copyString
(
msg
.
vid
,
vid
.
c_str
()
);
castor
::
utils
::
copyString
(
msg
.
vid
,
vid
);
sendNotificationAndReceiveReply
(
msg
);
}
catch
(
castor
::
exception
::
Exception
&
ne
)
{
...
...
@@ -173,7 +173,7 @@ void castor::legacymsg::VmgrProxyTcpIp::tapeMountedForWrite(const std::string &v
msg
.
gid
=
getegid
();
msg
.
jid
=
getpid
();
msg
.
mode
=
WRITE_ENABLE
;
castor
::
utils
::
copyString
(
msg
.
vid
,
vid
.
c_str
()
);
castor
::
utils
::
copyString
(
msg
.
vid
,
vid
);
sendNotificationAndReceiveReply
(
msg
);
}
catch
(
castor
::
exception
::
Exception
&
ne
)
{
...
...
@@ -338,7 +338,7 @@ void castor::legacymsg::VmgrProxyTcpIp::queryTape(const std::string &vid, legacy
legacymsg
::
VmgrTapeInfoRqstMsgBody
request
;
request
.
uid
=
geteuid
();
request
.
gid
=
getegid
();
castor
::
utils
::
copyString
(
request
.
vid
,
vid
.
c_str
()
);
castor
::
utils
::
copyString
(
request
.
vid
,
vid
);
request
.
side
=
0
;
// HARDCODED side
char
buf
[
VMGR_REQUEST_BUFSIZE
];
...
...
castor/legacymsg/legacymsg.cpp
View file @
d2ce4eb3
...
...
@@ -59,7 +59,7 @@ void castor::legacymsg::writeTapeReplyMsg(const int timeout, const int fd, const
char
dst
[
dstlen
];
castor
::
legacymsg
::
GenericReplyMsgBody
src
;
src
.
status
=
rc
;
castor
::
utils
::
copyString
(
src
.
errorMessage
,
message
.
c_str
()
);
castor
::
utils
::
copyString
(
src
.
errorMessage
,
message
);
const
size_t
len
=
castor
::
legacymsg
::
marshal
(
dst
,
dstlen
,
TPMAGIC
,
MSG_DATA
,
src
);
castor
::
io
::
writeBytes
(
fd
,
timeout
,
len
,
dst
);
}
catch
(
castor
::
exception
::
Exception
&
ne
)
{
...
...
@@ -78,7 +78,7 @@ void castor::legacymsg::writeTapeReplyErrorMsg(const int timeout, const int fd,
const
int
dstlen
=
12
+
CA_MAXLINELEN
+
1
;
// 12 bytes of header + max length of error message
char
dst
[
dstlen
];
castor
::
legacymsg
::
GenericErrorReplyMsgBody
src
;
castor
::
utils
::
copyString
(
src
.
errorMessage
,
message
.
c_str
()
);
castor
::
utils
::
copyString
(
src
.
errorMessage
,
message
);
const
size_t
len
=
castor
::
legacymsg
::
marshal
(
dst
,
dstlen
,
TPMAGIC
,
MSG_ERR
,
src
);
castor
::
io
::
writeBytes
(
fd
,
timeout
,
len
,
dst
);
}
catch
(
castor
::
exception
::
Exception
&
ne
)
{
...
...
castor/tape/tapebridge/BridgeProtocolEngine.cpp
View file @
d2ce4eb3
...
...
@@ -1025,11 +1025,11 @@ bool castor::tape::tapebridge::BridgeProtocolEngine::startMigrationSession()
// Give volume to rtcpd
legacymsg
::
RtcpTapeRqstErrMsgBody
rtcpVolume
;
castor
::
utils
::
setBytes
(
rtcpVolume
,
'\0'
);
castor
::
utils
::
copyString
(
rtcpVolume
.
vid
,
m_volume
.
vid
()
.
c_str
()
);
castor
::
utils
::
copyString
(
rtcpVolume
.
vsn
,
EMPTYVSN
);
castor
::
utils
::
copyString
(
rtcpVolume
.
label
,
m_volume
.
label
()
.
c_str
()
);
castor
::
utils
::
copyString
(
rtcpVolume
.
density
,
m_volume
.
density
()
.
c_str
()
);
castor
::
utils
::
copyString
(
rtcpVolume
.
unit
,
m_jobRequest
.
driveUnit
);
castor
::
utils
::
copyString
(
rtcpVolume
.
vid
,
m_volume
.
vid
()
);
castor
::
utils
::
copyString
(
rtcpVolume
.
vsn
,
EMPTYVSN
);
castor
::
utils
::
copyString
(
rtcpVolume
.
label
,
m_volume
.
label
()
);
castor
::
utils
::
copyString
(
rtcpVolume
.
density
,
m_volume
.
density
()
);
castor
::
utils
::
copyString
(
rtcpVolume
.
unit
,
m_jobRequest
.
driveUnit
);
rtcpVolume
.
volReqId
=
m_jobRequest
.
volReqId
;
rtcpVolume
.
mode
=
WRITE_ENABLE
;
rtcpVolume
.
tStartRequest
=
time
(
NULL
);
...
...
@@ -1090,7 +1090,7 @@ bool castor::tape::tapebridge::BridgeProtocolEngine::startMigrationSession()
unsigned
char
blockId
[
4
];
castor
::
utils
::
setBytes
(
blockId
,
'\0'
);
char
nshost
[
CA_MAXHOSTNAMELEN
+
1
];
castor
::
utils
::
copyString
(
nshost
,
firstFileToMigrate
->
nshost
()
.
c_str
()
);
castor
::
utils
::
copyString
(
nshost
,
firstFileToMigrate
->
nshost
());
RtcpTxRx
::
giveFileToRtcpd
(
m_cuuid
,
...
...
@@ -1136,11 +1136,11 @@ void castor::tape::tapebridge::BridgeProtocolEngine::startRecallSession()
// Give volume to rtcpd
legacymsg
::
RtcpTapeRqstErrMsgBody
rtcpVolume
;
castor
::
utils
::
setBytes
(
rtcpVolume
,
'\0'
);
castor
::
utils
::
copyString
(
rtcpVolume
.
vid
,
m_volume
.
vid
()
.
c_str
()
);
castor
::
utils
::
copyString
(
rtcpVolume
.
vsn
,
EMPTYVSN
);
castor
::
utils
::
copyString
(
rtcpVolume
.
label
,
m_volume
.
label
()
.
c_str
()
);
castor
::
utils
::
copyString
(
rtcpVolume
.
density
,
m_volume
.
density
()
.
c_str
()
);
castor
::
utils
::
copyString
(
rtcpVolume
.
unit
,
m_jobRequest
.
driveUnit
);
castor
::
utils
::
copyString
(
rtcpVolume
.
vid
,
m_volume
.
vid
()
);
castor
::
utils
::
copyString
(
rtcpVolume
.
vsn
,
EMPTYVSN
);
castor
::
utils
::
copyString
(
rtcpVolume
.
label
,
m_volume
.
label
()
);
castor
::
utils
::
copyString
(
rtcpVolume
.
density
,
m_volume
.
density
()
);
castor
::
utils
::
copyString
(
rtcpVolume
.
unit
,
m_jobRequest
.
driveUnit
);
rtcpVolume
.
volReqId
=
m_jobRequest
.
volReqId
;
rtcpVolume
.
mode
=
WRITE_DISABLE
;
rtcpVolume
.
tStartRequest
=
time
(
NULL
);
...
...
@@ -1173,11 +1173,11 @@ void castor::tape::tapebridge::BridgeProtocolEngine::startDumpSession()
// Give volume to rtcpd
legacymsg
::
RtcpTapeRqstErrMsgBody
rtcpVolume
;
castor
::
utils
::
setBytes
(
rtcpVolume
,
'\0'
);
castor
::
utils
::
copyString
(
rtcpVolume
.
vid
,
m_volume
.
vid
()
.
c_str
()
);
castor
::
utils
::
copyString
(
rtcpVolume
.
vsn
,
EMPTYVSN
);
castor
::
utils
::
copyString
(
rtcpVolume
.
label
,
m_volume
.
label
()
.
c_str
()
);
castor
::
utils
::
copyString
(
rtcpVolume
.
density
,
m_volume
.
density
()
.
c_str
()
);
castor
::
utils
::
copyString
(
rtcpVolume
.
unit
,
m_jobRequest
.
driveUnit
);
castor
::
utils
::
copyString
(
rtcpVolume
.
vid
,
m_volume
.
vid
()
);
castor
::
utils
::
copyString
(
rtcpVolume
.
vsn
,
EMPTYVSN
);
castor
::
utils
::
copyString
(
rtcpVolume
.
label
,
m_volume
.
label
()
);
castor
::
utils
::
copyString
(
rtcpVolume
.
density
,
m_volume
.
density
()
);
castor
::
utils
::
copyString
(
rtcpVolume
.
unit
,
m_jobRequest
.
driveUnit
);
rtcpVolume
.
volReqId
=
m_jobRequest
.
volReqId
;
rtcpVolume
.
mode
=
WRITE_DISABLE
;
rtcpVolume
.
tStartRequest
=
time
(
NULL
);
...
...
@@ -1891,7 +1891,7 @@ void castor::tape::tapebridge::BridgeProtocolEngine::sendFileToRecallToRtcpd(
fileToRecall
.
blockId2
,
fileToRecall
.
blockId3
};
char
nshost
[
CA_MAXHOSTNAMELEN
+
1
];
castor
::
utils
::
copyString
(
nshost
,
fileToRecall
.
nsHost
.
c_str
()
);
castor
::
utils
::
copyString
(
nshost
,
fileToRecall
.
nsHost
);
// The file size is not specified when recalling
const
uint64_t
fileSize
=
0
;
...
...
@@ -3035,7 +3035,7 @@ void castor::tape::tapebridge::BridgeProtocolEngine::sendFileToMigrateToRtcpd(
unsigned
char
blockId
[
4
];
castor
::
utils
::
setBytes
(
blockId
,
'\0'
);
char
nshost
[
CA_MAXHOSTNAMELEN
+
1
];
castor
::
utils
::
copyString
(
nshost
,
fileToMigrate
.
nsHost
.
c_str
()
);
castor
::
utils
::
copyString
(
nshost
,
fileToMigrate
.
nsHost
);
RtcpTxRx
::
giveFileToRtcpd
(
m_cuuid
,
...
...
castor/tape/tapeserver/daemon/DriveCatalogueEntry.cpp
View file @
d2ce4eb3
...
...
@@ -649,17 +649,17 @@ castor::legacymsg::TapeStatDriveEntry
try
{
entry
.
uid
=
getUidForTapeStatDriveEntry
();
entry
.
jid
=
getJidForTapeStatDriveEntry
();
castor
::
utils
::
copyString
(
entry
.
dgn
,
m_config
.
dgn
.
c_str
()
);
castor
::
utils
::
copyString
(
entry
.
dgn
,
m_config
.
dgn
);
entry
.
up
=
getUpForTapeStatDriveEntry
();
entry
.
asn
=
getAsnForTapeStatDriveEntry
();
entry
.
asn_time
=
getAsnTimeForTapeStatDriveEntry
();
castor
::
utils
::
copyString
(
entry
.
drive
,
m_config
.
unitName
.
c_str
()
);
castor
::
utils
::
copyString
(
entry
.
drive
,
m_config
.
unitName
);
entry
.
mode
=
getModeForTapeStatDriveEntry
();
castor
::
utils
::
copyString
(
entry
.
lblcode
,
getLblCodeForTapeStatDriveEntry
().
c_str
());
entry
.
tobemounted
=
getToBeMountedForTapeStatDriveEntry
();
castor
::
utils
::
copyString
(
entry
.
vid
,
getVidForTapeStatDriveEntry
()
.
c_str
()
);
castor
::
utils
::
copyString
(
entry
.
vsn
,
getVsnForTapeStatDriveEntry
()
.
c_str
()
);
castor
::
utils
::
copyString
(
entry
.
vid
,
getVidForTapeStatDriveEntry
());
castor
::
utils
::
copyString
(
entry
.
vsn
,
getVsnForTapeStatDriveEntry
());
entry
.
cfseq
=
0
;
// the fseq is ignored by tpstat, so we leave it set to 0
}
catch
(
castor
::
exception
::
Exception
&
ne
)
{
castor
::
exception
::
Exception
ex
;
...
...
castor/utils/UtilsTest.cpp
View file @
d2ce4eb3
...
...
@@ -301,14 +301,6 @@ TEST_F(castor_utils, testCopyStringNullDst) {
castor
::
exception
::
Exception
);
}
TEST_F
(
castor_utils
,
testCopyStringNullSrc
)
{
using
namespace
castor
::
utils
;
char
dummy
[
6
]
=
"Dummy"
;
ASSERT_THROW
(
copyString
(
dummy
,
sizeof
(
dummy
),
NULL
),
castor
::
exception
::
Exception
);
}
TEST_F
(
castor_utils
,
testCopyString
)
{
using
namespace
castor
::
utils
;
char
src
[
12
]
=
"Hello World"
;
...
...
castor/utils/utils.cpp
View file @
d2ce4eb3
...
...
@@ -221,7 +221,7 @@ double castor::utils::timevalToDouble(const timeval &tv) throw() {
// copyString
//-----------------------------------------------------------------------------
void
castor
::
utils
::
copyString
(
char
*
const
dst
,
const
size_t
dstSize
,
const
char
*
const
src
)
{
const
std
::
string
&
src
)
{
if
(
dst
==
NULL
)
{
castor
::
exception
::
Exception
ex
(
EINVAL
);
...
...
@@ -232,28 +232,17 @@ void castor::utils::copyString(char *const dst, const size_t dstSize,
throw
ex
;
}
if
(
src
==
NULL
)
{
castor
::
exception
::
Exception
ex
(
EINVAL
);
ex
.
getMessage
()
<<
__FUNCTION__
<<
": Pointer to source string is NULL"
;
throw
ex
;
}
const
size_t
srcLen
=
strlen
(
src
);
if
(
srcLen
>=
dstSize
)
{
if
(
src
.
length
()
>=
dstSize
)
{
castor
::
exception
::
Exception
ex
(
EINVAL
);
ex
.
getMessage
()
<<
__FUNCTION__
<<
": Source string is longer than destination. Source length: "
<<
src
Len
<<
" Max destination length: "
<<
(
dstSize
-
1
);
<<
src
.
length
()
<<
" Max destination length: "
<<
(
dstSize
-
1
);
throw
ex
;
}
strncpy
(
dst
,
src
,
dstSize
);
strncpy
(
dst
,
src
.
c_str
()
,
dstSize
);
*
(
dst
+
dstSize
-
1
)
=
'\0'
;
// Ensure destination string is null terminated
}
...
...
castor/utils/utils.hpp
View file @
d2ce4eb3
...
...
@@ -145,7 +145,7 @@ double timevalToDouble(const timeval &tv) throw();
* @param src Source string.
* destination.
*/
void
copyString
(
char
*
const
dst
,
const
size_t
dstSize
,
const
char
*
const
src
);
void
copyString
(
char
*
const
dst
,
const
size_t
dstSize
,
const
std
::
string
&
src
);
/**
* Safely copies source string into destination string. The destination
...
...
@@ -155,8 +155,7 @@ void copyString(char *const dst, const size_t dstSize, const char *const src);
* @param src Source string.
*/
template
<
size_t
dstSize
>
void
copyString
(
char
(
&
dst
)[
dstSize
],
const
char
*
const
src
)
{
const
std
::
string
&
src
)
{
copyString
(
dst
,
dstSize
,
src
);
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment