Commit 83207fa2 authored by Steven Murray's avatar Steven Murray
Browse files

Removed the classes responsible for implementing the RTCOPY protocol from the...

Removed the classes responsible for implementing the RTCOPY protocol from the CTA version of tapeserverd
parent 5449841b
/******************************************************************************
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
*
* Copyright (C) 2003 CERN
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program 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 General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
*
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
#include "castor/legacymsg/RtcpErrorAppendix.hpp"
#include <string.h>
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
castor::legacymsg::RtcpErrorAppendix::RtcpErrorAppendix() throw():
severity(0),
errorCode(0),
maxTpRetry(0),
maxCpRetry(0) {
memset(errorMsg, '\0', sizeof(errorMsg));
}
/******************************************************************************
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
*
* Copyright (C) 2003 CERN
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program 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 General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
*
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
#pragma once
#include <shift/Castor_limits.h>
#include <stdint.h>
namespace castor {
namespace legacymsg {
/**
* Error reporting appendix embedded within an RTCP tape and file request
* messages.
*/
struct RtcpErrorAppendix {
char errorMsg[CA_MAXLINELEN+1];
uint32_t severity; // Defined in rtcp_constants.h
uint32_t errorCode; // Defined in rtcp_constants.h
int32_t maxTpRetry; // Nb. of retries left on mount/pos
int32_t maxCpRetry; // Nb. of retries left on copy
/**
* Constructor.
*
* Sets all integer member-variables to 0 and all string member-variables to
* the empty string.
*/
RtcpErrorAppendix() throw();
}; // struct RtcpErrorAppendix
} // namespace legacymsg
} // namespace castor
/******************************************************************************
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
*
* Copyright (C) 2003 CERN
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program 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 General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
*
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
#include "castor/legacymsg/RtcpJobReplyMsgBody.hpp"
#include <string.h>
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
castor::legacymsg::RtcpJobReplyMsgBody::RtcpJobReplyMsgBody() throw():
status(0) {
memset(errorMessage, '\0', sizeof(errorMessage));
}
/******************************************************************************
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
*
* Copyright (C) 2003 CERN
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program 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 General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
*
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
#pragma once
#include "Castor_limits.h"
#include <stdint.h>
#include <string>
namespace castor {
namespace legacymsg {
/**
* An RCP job reply message.
*/
struct RtcpJobReplyMsgBody {
int32_t status;
char errorMessage[1024];
/**
* Constructor.
*
* Sets all integer member-variables to 0 and all string member-variables to
* the empty string.
*/
RtcpJobReplyMsgBody() throw();
};
} // namespace legacymsg
} // namespace castor
/******************************************************************************
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
*
* Copyright (C) 2003 CERN
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program 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 General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
*
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
#include "castor/legacymsg/RtcpJobRqstMsgBody.hpp"
#include <string.h>
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
castor::legacymsg::RtcpJobRqstMsgBody::RtcpJobRqstMsgBody() throw():
volReqId(0),
clientPort(0),
clientEuid(0),
clientEgid(0) {
memset(clientHost, '\0', sizeof(clientHost));
memset(dgn, '\0', sizeof(dgn));
memset(driveUnit, '\0', sizeof(driveUnit));
memset(clientUserName, '\0', sizeof(clientUserName));
}
/******************************************************************************
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
*
* Copyright (C) 2003 CERN
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program 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 General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
*
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
#pragma once
#include <shift/Castor_limits.h>
#include <stdint.h>
namespace castor {
namespace legacymsg {
/**
* An RCP job submission request message.
*/
struct RtcpJobRqstMsgBody {
uint32_t volReqId;
uint32_t clientPort;
uint32_t clientEuid;
uint32_t clientEgid;
char clientHost[CA_MAXHOSTNAMELEN+1];
char dgn[CA_MAXDGNLEN+1];
char driveUnit[CA_MAXUNMLEN+1];
char clientUserName[CA_MAXUSRNAMELEN+1];
/**
* Constructor.
*
* Sets all integer member-variables to 0 and all string member-variables to
* the empty string.
*/
RtcpJobRqstMsgBody() throw();
}; // struct RtcpJobRqstMsgBody
} // namespace legacymsg
} // namespace castor
/******************************************************************************
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
*
* Copyright (C) 2003 CERN
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program 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 General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
*
*
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
#include "castor/io/io.hpp"
#include "castor/legacymsg/CommonMarshal.hpp"
#include "castor/legacymsg/RtcpMarshal.hpp"
#include "h/rtcp_constants.h"
#include <errno.h>
#include <iostream>
#include <shift/vdqm_constants.h>
#include <string.h>
//-----------------------------------------------------------------------------
// marshal
//-----------------------------------------------------------------------------
size_t castor::legacymsg::marshal(char *const dst, const size_t dstLen,
const RtcpJobRqstMsgBody &src) {
if(dst == NULL) {
castor::exception::Exception ex;
ex.getMessage() << "Failed to marshal RtcpJobRqstMsgBody"
": Pointer to destination buffer is NULL";
throw ex;
}
// Calculate the length of the message body
const uint32_t len =
4*sizeof(uint32_t) +
strlen(src.clientHost) +
strlen(src.dgn) +
strlen(src.driveUnit) +
strlen(src.clientUserName) +
4; // 4 = the number of string termination characters
// Calculate the total length of the message (header + body)
// Message header = magic + reqType + len = 3 * sizeof(uint32_t)
const size_t totalLen = 3 * sizeof(uint32_t) + len;
// Check that the message buffer is big enough
if(totalLen > dstLen) {
castor::exception::Exception ex;
ex.getMessage() << "Failed to marshal RtcpJobRqstMsgBody"
": Buffer too small: required=" << totalLen << " actual=" << dstLen;
throw ex;
}
// Marshall the whole message (header + body)
char *p = dst;
io::marshalUint32(RTCOPY_MAGIC_OLD0 , p); // Magic number
io::marshalUint32(VDQM_CLIENTINFO , p); // Request type
io::marshalUint32(len , p); // Length of message body
io::marshalUint32(src.volReqId , p);
io::marshalUint32(src.clientPort , p);
io::marshalUint32(src.clientEuid , p);
io::marshalUint32(src.clientEgid , p);
io::marshalString(src.clientHost , p);
io::marshalString(src.dgn , p);
io::marshalString(src.driveUnit , p);
io::marshalString(src.clientUserName , p);
// Calculate the number of bytes actually marshalled
const size_t nbBytesMarshalled = p - dst;
// Check that the number of bytes marshalled was what was expected
if(totalLen != nbBytesMarshalled) {
castor::exception::Exception ex;
ex.getMessage() << "Failed to marshal RtcpJobRqstMsgBody"
": Mismatch between expected total length and actual"
": expected=" << totalLen << " actual=" << nbBytesMarshalled;
throw ex;
}
return totalLen;
}
//-----------------------------------------------------------------------------
// unmarshal
//-----------------------------------------------------------------------------
void castor::legacymsg::unmarshal(const char * &src,
size_t &srcLen, RtcpJobRqstMsgBody &dst) {
io::unmarshalUint32(src, srcLen, dst.volReqId);
io::unmarshalUint32(src, srcLen, dst.clientPort);
io::unmarshalUint32(src, srcLen, dst.clientEuid);
io::unmarshalUint32(src, srcLen, dst.clientEgid);
io::unmarshalString(src, srcLen, dst.clientHost);
io::unmarshalString(src, srcLen, dst.dgn);
io::unmarshalString(src, srcLen, dst.driveUnit);
io::unmarshalString(src, srcLen, dst.clientUserName);
}
//-----------------------------------------------------------------------------
// marshal
//-----------------------------------------------------------------------------
size_t castor::legacymsg::marshal(char *const dst,
const size_t dstLen, const RtcpJobReplyMsgBody &src)
{
if(dst == NULL) {
castor::exception::Exception ex;
ex.getMessage() << "Failed to marshal RtcpJobReplyMsgBody"
": Pointer to destination buffer is NULL";
throw ex;
}
// Minimum buffer length = magic number + request type + length + status code
// + terminating null character
const size_t minimumLen = 4*sizeof(uint32_t) + 1;
if(dstLen < minimumLen) {
castor::exception::Exception ex;
ex.getMessage() << "Failed to marshal RtcpJobReplyMsgBody"
": Buffer too small: required=" << minimumLen << " actual=" << dstLen;
throw ex;
}
// Calculate the length of the error message to be sent taking into account
// the fact that the error message should be right trimmed if it is too large
// to fit in the destination buffer.
const size_t headerLen = 3 * sizeof(uint32_t); // magic + reqType + len
// free space = total - header - status - terminating null character
const size_t freeSpace = dstLen - headerLen - sizeof(uint32_t) - 1;
const size_t errLenToSend = strlen(src.errorMessage) < freeSpace ?
strlen(src.errorMessage) : freeSpace;
// Calculate the length of the message body
// Message body = status + error message + terminating null character
const uint32_t len = sizeof(src.status) + errLenToSend + 1;
// Calculate the total length of the message (header + body)
const size_t totalLen = headerLen + len;
char *p = dst;
io::marshalUint32(RTCOPY_MAGIC_OLD0, p); // Magic number
io::marshalUint32(VDQM_CLIENTINFO , p); // Request type
io::marshalUint32(len , p); // Length
io::marshalUint32(src.status , p); // status code
strncpy(p, src.errorMessage, errLenToSend);
*(p+errLenToSend) = '0';
p = p + errLenToSend + 1;
// Calculate the number of bytes actually marshalled
const size_t nbBytesMarshalled = p - dst;
// Check that the number of bytes marshalled was what was expected
if(totalLen != nbBytesMarshalled) {
castor::exception::Exception ex;
ex.getMessage() << "Failed to marshal RtcpJobReplyMsgBody"
": Mismatch between expected total length and actual"
": expected=" << totalLen << " actual=" << nbBytesMarshalled;
throw ex;
}
return totalLen;
}
//-----------------------------------------------------------------------------
// unmarshal
//-----------------------------------------------------------------------------
void castor::legacymsg::unmarshal(const char * &src, size_t &srcLen,
RtcpJobReplyMsgBody &dst) {
// Unmarshal the status number
io::unmarshalInt32(src, srcLen, dst.status);
// The error message will be right trimmed if it is too large
const size_t maxBytesToUnmarshal = srcLen < sizeof(dst.errorMessage) ?
srcLen : sizeof(dst.errorMessage);
// Unmarshal the error message
if(maxBytesToUnmarshal > 0) {
strncpy(dst.errorMessage, src, maxBytesToUnmarshal);
dst.errorMessage[maxBytesToUnmarshal - 1] = '\0';
src = src + strlen(dst.errorMessage) + 1;
srcLen = srcLen - strlen(dst.errorMessage) - 1;
} else {
dst.errorMessage[0] = '\0';
// No need to update src or srcLen
}
}
/******************************************************************************
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
*
* Copyright (C) 2003 CERN
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program 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 General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
*
*
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
#pragma once
#include "castor/exception/Exception.hpp"
#include "castor/legacymsg/GiveOutpMsgBody.hpp"
#include "castor/legacymsg/RtcpJobRqstMsgBody.hpp"
#include "castor/legacymsg/RtcpJobReplyMsgBody.hpp"
#include <errno.h>
#include <stdint.h>
#include <string>
namespace castor {
namespace legacymsg {
/**
* Marshalls the specified source message body structure into the
* specified destination buffer.
*
* @param dst The destination message buffer.
* @param dstLen The length of the destination buffer.
* @param src The source structure.
* @return The total length of the message (header + body).
*/
size_t marshal(char *const dst, const size_t dstLen,
const RtcpJobRqstMsgBody &src) ;
/**
* Marshalls the specified source message body structure into the
* specified destination buffer.
*
* @param dst The destination message buffer.
* @param src The source structure.
* @return The total length of the message (header + body).
*/
template<int n> size_t marshal(char (&dst)[n],
const RtcpJobRqstMsgBody &src) {
return marshal(dst, n, src);
}
/**
* Unmarshals a message body with the specified destination structure type
* from the specified source buffer.
*
* @param src In/out parameter, before invocation points to the source
* buffer where the message body should be unmarshalled from and on return
* points to the byte in the source buffer immediately after the
* unmarshalled message body.
* @param srcLen In/our parameter, before invocation is the length of the
* source buffer from where the message body should be unmarshalled and on
* return is the number of bytes remaining in the source buffer.
* @param dst The destination message body structure.
*/
void unmarshal(const char * &src, size_t &srcLen,
RtcpJobRqstMsgBody &dst) ;
/**
* Marshalls the specified source message body structure into the
* specified destination buffer.
*
* @param dst The destination message buffer.
* @param dstLen The length of the destination buffer.
* @param src The source structure.
* @return The total length of the message (header + body).
*/
size_t marshal(char *const dst, const size_t dstLen,
const RtcpJobReplyMsgBody &src) ;
/**
* Marshalls the specified source message body structure into the
* specified destination buffer.
*
* @param dst The destination message buffer.
* @param src The source structure.
* @return The total length of the message (header + body).
*/
template<int n> size_t marshal(char (&dst)[n],
const RtcpJobReplyMsgBody &src) {
return marshal(dst, n, src);
}
/**
* Unmarshals a message body with the specified destination structure type
* from the specified source buffer.
*
* @param src In/out parameter, before invocation points to the source
* buffer where the message body should be unmarshalled from and on return
* points to the byte in the source buffer immediately after the
* unmarshalled message body.
* @param srcLen In/our parameter, before invocation is the length of the
* source buffer from where the message body should be unmarshalled and on
* return is the number of bytes remaining in the source buffer.