/* * FBFS Distributed Object Repository * Copyright (C) 2001 Francesco V. Bassi * * 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 */ #include <iostream.h> #include "../../Object/Object.h" #include "../../idl/NameServer.hh" #include "../../idl/Object.hh" #include "../../idl/Security.hh" #include "../../idl/Storage.hh" #include "../../utils/NameServer.h" #include "../../utils/URI.h" #include "../../utils/File.h" using namespace fbfs; int main (int argc, char **argv) { try { CORBA::ORB_var orb = CORBA::ORB_init(argc, argv, "omniORB3"); if(argc != 3 && argc != 4) { cerr << "Usage: " << argv[0] << " <Storage_address> <Id> [<FileName>]\n"; return 0; }; utils::URI uri(argv[1]); if(!uri.isValid()) { cerr << "Error: address not valid.\n"; orb->destroy(); exit(1); }; CORBA::Object_var obj = utils::NameServer::get_object(orb, uri); fbfs::Storage_var server = fbfs::Storage::_narrow(obj); if(CORBA::is_nil(server)) { cerr << "Error: the address doesn't refer a Storage object.\n"; orb->destroy(); exit(1); }; Security cert; Obj_id id; id.name = CORBA::string_dup(argv[2]); try { Obj_ts t = server->get_ts(cert, id); utils::File::write(Object::Obj_ts2string(t), argv[argc-1], ""); } catch (NotFound) { cerr << "Error: item not found.\n"; } catch (SecurityException) { cerr << "Error: insufficient security permissions.\n"; } catch (InternalError) { cerr << "Error: internal error.\n"; } catch (utils::File::AlreadyPresent) { cerr << "Error: file already present.\n"; } catch (utils::File::Exception) { cerr << "Error: local IO error.\n"; } catch (...) { cerr << "Error: very, very strange.\n"; }; orb->destroy(); } catch(CORBA::COMM_FAILURE& ex) { cerr << "Caught system exception COMM_FAILURE -- unable to contact the " << "object." << endl; } catch(CORBA::SystemException&) { cerr << "Caught CORBA::SystemException." << endl; } catch(CORBA::Exception&) { cerr << "Caught CORBA::Exception." << endl; } catch(omniORB::fatalException& fe) { cerr << "Caught omniORB::fatalException:" << endl; cerr << " file: " << fe.file() << endl; cerr << " line: " << fe.line() << endl; cerr << " mesg: " << fe.errmsg() << endl; } catch(...) { cerr << "Caught unknown exception." << endl; } return 0; }