Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / lib / tt / lib / db / tt_db_network_path.C
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 //%%  (c) Copyright 1993, 1994 Hewlett-Packard Company                  
24 //%%  (c) Copyright 1993, 1994 International Business Machines Corp.    
25 //%%  (c) Copyright 1993, 1994 Sun Microsystems, Inc.                   
26 //%%  (c) Copyright 1993, 1994 Novell, Inc.                             
27 //%%  $XConsortium: tt_db_network_path.C /main/3 1995/10/23 10:03:29 rswiston $                                                         
28 /*
29  * tt_db_network_path.cc - Defines a function that takes a local
30  *      path and returns the real local path, hostname, partition
31  *      and real remote path of the file.  The partition and real
32  *      remote path are for the file on its native host.
33  *
34  * Copyright (c) 1990 by Sun Microsystems, Inc.
35  *
36  * Implementation for filepath utility functions
37  *
38  */
39
40 #include "util/tt_path.h"
41 #include "util/tt_file_system.h"
42 #include "util/tt_file_system_entry.h"
43 #include "db/tt_db_hostname_global_map_ref.h"
44
45 _Tt_db_results _tt_db_network_path (const _Tt_string &path,
46                                     _Tt_string       &local_path,
47                                     _Tt_string       &hostname,
48                                     _Tt_string       &partition,
49                                     _Tt_string       &network_path)
50 {
51         _Tt_db_results results = TT_DB_OK;
52
53
54         if (_tt_is_network_path(path)) {
55                 local_path = _tt_network_path_to_local_path(path);
56         } else {
57                 local_path = _tt_realpath(path);
58         }
59
60         _Tt_file_system file_system;
61         _Tt_file_system_entry_ptr file_system_entry =
62                             file_system.bestMatchToPath(local_path);
63
64         hostname = file_system_entry->getHostname();
65
66         if (file_system_entry->isLocal()) {
67                 partition = file_system_entry->getMountPoint();
68
69                 _Tt_string loop_back_mount_point =
70                        file_system_entry->getLoopBackMountPoint();
71
72                 if (loop_back_mount_point.len ()) {
73                         // Get the path info after the mount point path
74                         local_path = local_path.right(local_path.len() -
75                                                 loop_back_mount_point.len());
76
77                         // Replace the mount point path with
78                         // the exported partition path.
79                         if (partition != "/") {
80                                 local_path = loop_back_mount_point.cat(local_path);
81                         }
82                 } 
83                 network_path = hostname.cat(":").cat(local_path);
84         } else {
85                 _Tt_db_hostname_global_map_ref map_ref;
86                 _Tt_db_client_ptr database =
87                         map_ref.getDB(hostname, hostname, results);
88
89                 if (!database.is_null()) {
90                         _Tt_string temp_string;
91                         _Tt_string local_network_path;
92
93                         if (_tt_is_network_path(path)) {
94                                 local_network_path = path;
95                         } else {
96                                 local_network_path =
97                                         _tt_local_network_path(path);
98                         }
99
100                         results = database->getFilePartition(local_network_path,
101                                                              partition,
102                                                              network_path);
103                 }
104
105                 if ((results == TT_DB_ERR_DB_CONNECTION_FAILED) ||
106                     (results == TT_DB_ERR_RPC_CONNECTION_FAILED) ||
107                     (results == TT_DB_ERR_RPC_FAILED) ||
108                     (results == TT_DB_ERR_DB_OPEN_FAILED)) {
109                         map_ref.removeDB (hostname);
110                 }
111         }
112
113         return results;
114 }