00001
00002
00003 #include "subStructFileGet.h"
00004 #include "miscServerFunct.h"
00005 #include "dataObjOpr.h"
00006
00007
00008
00009 #include "eirods_structured_object.h"
00010 #include "eirods_error.h"
00011 #include "eirods_stacktrace.h"
00012
00013 int
00014 rsSubStructFileGet (rsComm_t *rsComm, subFile_t *subFile,
00015 bytesBuf_t *subFileGetOutBBuf)
00016 {
00017 rodsServerHost_t *rodsServerHost;
00018 int remoteFlag;
00019 int status;
00020
00021 remoteFlag = resolveHost (&subFile->addr, &rodsServerHost);
00022
00023 if (remoteFlag == LOCAL_HOST) {
00024 status = _rsSubStructFileGet (rsComm, subFile, subFileGetOutBBuf);
00025 } else if (remoteFlag == REMOTE_HOST) {
00026 status = remoteSubStructFileGet (rsComm, subFile, subFileGetOutBBuf,
00027 rodsServerHost);
00028 } else {
00029 if (remoteFlag < 0) {
00030 return (remoteFlag);
00031 } else {
00032 rodsLog (LOG_NOTICE,
00033 "rsSubStructFileGet: resolveHost returned unrecognized value %d",
00034 remoteFlag);
00035 return (SYS_UNRECOGNIZED_REMOTE_FLAG);
00036 }
00037 }
00038
00039 return (status);
00040 }
00041
00042 int
00043 remoteSubStructFileGet (rsComm_t *rsComm, subFile_t *subFile,
00044 bytesBuf_t *subFileGetOutBBuf, rodsServerHost_t *rodsServerHost)
00045 {
00046 int status;
00047
00048 if (rodsServerHost == NULL) {
00049 rodsLog (LOG_NOTICE,
00050 "remoteSubStructFileGet: Invalid rodsServerHost");
00051 return SYS_INVALID_SERVER_HOST;
00052 }
00053
00054 if ((status = svrToSvrConnect (rsComm, rodsServerHost)) < 0) {
00055 return status;
00056 }
00057
00058 status = rcSubStructFileGet (rodsServerHost->conn, subFile,
00059 subFileGetOutBBuf);
00060
00061 if (status < 0) {
00062 rodsLog (LOG_NOTICE,
00063 "remoteSubStructFileGet: rcSubStructFileGet failed for %s, status = %d",
00064 subFile->subFilePath, status);
00065 }
00066
00067 return status;
00068 }
00069
00070 int _rsSubStructFileGet( rsComm_t* _comm,
00071 subFile_t* _sub_file,
00072 bytesBuf_t* _out_buf ) {
00073
00074
00075 eirods::structured_object struct_obj( *_sub_file );
00076 struct_obj.comm( _comm );
00077
00078 struct_obj.resc_hier( eirods::EIRODS_LOCAL_USE_ONLY_RESOURCE );
00079
00080 if( _sub_file->offset <= 0 ) {
00081 eirods::log( ERROR( SYS_INVALID_INPUT_PARAM, "invalid length" ) );
00082 return -1;
00083 }
00084
00085
00086
00087 eirods::error open_err = fileOpen( _comm, struct_obj );
00088 if( !open_err.ok() ) {
00089 std::stringstream msg;
00090 msg << "fileOpen error for [";
00091 msg << struct_obj.sub_file_path();
00092 msg << "], status = ";
00093 msg << open_err.code();
00094 eirods::log( PASSMSG( msg.str(), open_err ) );
00095 return open_err.code();
00096 }
00097
00098
00099
00100 if( _out_buf->buf == NULL) {
00101 _out_buf->buf = new unsigned char[ _sub_file->offset ];
00102 }
00103
00104
00105
00106 eirods::error read_err = fileRead( _comm, struct_obj, _out_buf->buf, _sub_file->offset );
00107 int status = read_err.code();
00108
00109 if( !read_err.ok() ) {
00110 if( status >= 0 ) {
00111 std::stringstream msg;
00112 msg << "failed in fileRead for [";
00113 msg << struct_obj.sub_file_path();
00114 msg << ", toread ";
00115 msg << _sub_file->offset;
00116 msg << ", read ";
00117 msg << read_err.code();
00118 eirods::log( PASSMSG( msg.str(), read_err ) );
00119
00120 status = SYS_COPY_LEN_ERR;
00121 } else {
00122 std::stringstream msg;
00123 msg << "failed in fileRead for [";
00124 msg << struct_obj.sub_file_path();
00125 msg << ", status = ";
00126 msg << read_err.code();
00127 eirods::log( PASSMSG( msg.str(), read_err ) );
00128
00129 status = read_err.code();
00130 }
00131
00132 } else {
00133 _out_buf->len = read_err.code();
00134 }
00135
00136
00137
00138 eirods::error close_err = fileClose( _comm, struct_obj );
00139 if( !close_err.ok() ) {
00140 std::stringstream msg;
00141 msg << "failed in fileClose for [";
00142 msg << struct_obj.sub_file_path();
00143 msg << ", status = ";
00144 msg << close_err.code();
00145 eirods::log( PASSMSG( msg.str(), read_err ) );
00146 }
00147
00148 return (status);
00149
00150 }
00151
00152