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_ptr struct_obj(
00076 new eirods::structured_object(
00077 *_sub_file ) );
00078 struct_obj->comm( _comm );
00079 struct_obj->resc_hier( eirods::EIRODS_LOCAL_USE_ONLY_RESOURCE );
00080
00081 if( _sub_file->offset <= 0 ) {
00082 eirods::log( ERROR( SYS_INVALID_INPUT_PARAM, "invalid length" ) );
00083 return -1;
00084 }
00085
00086
00087
00088 eirods::error open_err = fileOpen( _comm, struct_obj );
00089 if( !open_err.ok() ) {
00090 std::stringstream msg;
00091 msg << "fileOpen error for [";
00092 msg << struct_obj->sub_file_path();
00093 msg << "], status = ";
00094 msg << open_err.code();
00095 eirods::log( PASSMSG( msg.str(), open_err ) );
00096 return open_err.code();
00097 }
00098
00099
00100
00101 if( _out_buf->buf == NULL) {
00102 _out_buf->buf = new unsigned char[ _sub_file->offset ];
00103 }
00104
00105
00106
00107 eirods::error read_err = fileRead( _comm, struct_obj, _out_buf->buf, _sub_file->offset );
00108 int status = read_err.code();
00109
00110 if( !read_err.ok() ) {
00111 if( status >= 0 ) {
00112 std::stringstream msg;
00113 msg << "failed in fileRead for [";
00114 msg << struct_obj->sub_file_path();
00115 msg << ", toread ";
00116 msg << _sub_file->offset;
00117 msg << ", read ";
00118 msg << read_err.code();
00119 eirods::log( PASSMSG( msg.str(), read_err ) );
00120
00121 status = SYS_COPY_LEN_ERR;
00122 } else {
00123 std::stringstream msg;
00124 msg << "failed in fileRead for [";
00125 msg << struct_obj->sub_file_path();
00126 msg << ", status = ";
00127 msg << read_err.code();
00128 eirods::log( PASSMSG( msg.str(), read_err ) );
00129
00130 status = read_err.code();
00131 }
00132
00133 } else {
00134 _out_buf->len = read_err.code();
00135 }
00136
00137
00138
00139 eirods::error close_err = fileClose( _comm, struct_obj );
00140 if( !close_err.ok() ) {
00141 std::stringstream msg;
00142 msg << "failed in fileClose for [";
00143 msg << struct_obj->sub_file_path();
00144 msg << ", status = ";
00145 msg << close_err.code();
00146 eirods::log( PASSMSG( msg.str(), read_err ) );
00147 }
00148
00149 return (status);
00150
00151 }
00152
00153