[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[certi-cvs] certi/RTIG Federation.cc
From: |
CERTI CVS commits |
Subject: |
[certi-cvs] certi/RTIG Federation.cc |
Date: |
Fri, 09 Sep 2011 11:18:52 +0000 |
CVSROOT: /sources/certi
Module name: certi
Changes by: Eric NOULARD <erk> 11/09/09 11:18:52
Modified files:
RTIG : Federation.cc
Log message:
Merge patch #7614: Add a new environment path variable to look for FOM
files
Modified version in order to factor out Windows an unix code and avoid
duplication.
Now the algorithm is simple:
1) try the bare file
2) try PATH_PREFIX+file with PATH_PREFIX being a list of possible
pathes
including the one specified in CERTI_FOM_PATH
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/certi/RTIG/Federation.cc?cvsroot=certi&r1=3.142&r2=3.143
Patches:
Index: Federation.cc
===================================================================
RCS file: /sources/certi/certi/RTIG/Federation.cc,v
retrieving revision 3.142
retrieving revision 3.143
diff -u -b -r3.142 -r3.143
--- Federation.cc 2 Sep 2011 21:42:24 -0000 3.142
+++ Federation.cc 9 Sep 2011 11:18:51 -0000 3.143
@@ -18,7 +18,7 @@
// along with this program ; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
-// $Id: Federation.cc,v 3.142 2011/09/02 21:42:24 erk Exp $
+// $Id: Federation.cc,v 3.143 2011/09/09 11:18:51 erk Exp $
// ----------------------------------------------------------------------------
#include <config.h>
@@ -60,6 +60,20 @@
#define NODE_FEDERATE (const xmlChar*) "federate"
#endif // HAVE_XML
+// Path splitting functions
+std::vector<std::string> &split(const std::string &s, char delim,
std::vector<std::string> &elems) {
+ std::stringstream ss(s);
+ std::string item;
+ while(std::getline(ss, item, delim)) {
+ elems.push_back(item);
+ }
+ return elems;
+}
+std::vector<std::string> split(const std::string &s, char delim) {
+ std::vector<std::string> elems;
+ return split(s, delim, elems);
+}
+
#ifdef _WIN32
# define strcasecmp stricmp
#endif
@@ -80,7 +94,8 @@
* predefined places:
*
* -# bare filename considered as a path provided through FEDid_name
- * -# getenv(CERTI_HOME)+"/share/federations"+ FEDid_name
+ * -# getenv(CERTI_FOM_PATH) + FEDid_name
+ * -# getenv(CERTI_HOME)+"/share/federations/"+ FEDid_name
* -# installation place plus FEDid_name
* PACKAGE_INSTALL_PREFIX + "/share/federation/" + FEDid_name
* -# on Unix "/usr/local/share/federation/" + FEDid_name
@@ -88,7 +103,6 @@
*/
#ifdef FEDERATION_USES_MULTICAST
-
Federation::Federation(const std::string& federation_name,
FederationHandle federation_handle,
SocketServer &socket_server,
@@ -96,7 +110,7 @@
SocketMC *mc_link,
int theVerboseLevel)
#else
- Federation::Federation(const std::string& federation_name,
+Federation::Federation(const std::string& federation_name,
Handle federation_handle,
SocketServer &socket_server,
AuditFile &audit_server,
@@ -110,7 +124,6 @@
verboseLevel(theVerboseLevel)
{
- // fedparser::FedParser *fed_reader ;
STAT_STRUCT file_stat;
#ifdef FEDERATION_USES_MULTICAST // -----------------
@@ -153,93 +166,68 @@
//
// 1 - bare filename considered as a path provided through FEDid_name
//
- // 2 - getenv(CERTI_HOME)+"/share/federations"+ FEDid_name
+ // 2 - getenv(CERTI_FOM_PATH) + FEDid_name
//
- // 3 - Installation place plus FEDid_name
+ // 3 - getenv(CERTI_HOME) + "/share/federations" + FEDid_name
+ //
+ // 4 - Installation place plus FEDid_name
// PACKAGE_INSTALL_PREFIX + "/share/federation/" + FEDid_name
//
- // 4 - "/usr/local/share/federation/" + FEDid_name
+ // 5 - "/usr/local/share/federation/" + FEDid_name
// last resort Unix-only case [for backward compatibility]
//
string filename = FEDid;
bool filefound = false;
if (verboseLevel>0) {
cout << "Looking for FOM file... " << endl ;
-
cout << " Trying... " << filename;
}
filefound = (0==STAT_FUNCTION(filename.c_str(),&file_stat));
-#ifdef _WIN32
+ /* This is the main path handling loop */
if (!filefound) {
+ vector<string> fom_paths;
+#ifdef WIN32
char temp[260];
- if (verboseLevel>0) {
- cout << " --> cannot access." <<endl;
- }
GetCurrentDirectory(260,temp);
- filename = string(temp);
- filename = filename + "\\share\\federations\\"+FEDid_name;
- if (verboseLevel>0) {
- cout << " Now trying..." << filename;
- }
- filefound = (0==STAT_FUNCTION(filename.c_str(),&file_stat));
- }
+ fom_paths.insert(fom_paths.end(),string(temp)+"\share\\federations\\");
+#endif
- if (!filefound && (NULL!=getenv("CERTI_HOME"))) {
- if (verboseLevel>0) {
- cout << " --> cannot access." <<endl;
- }
- filename =
string(getenv("CERTI_HOME"))+"\\share\\federations\\"+FEDid_name;
- if (verboseLevel>0) {
- cout << " Now trying..." << filename;
- }
- filefound = (0==STAT_FUNCTION(filename.c_str(),&file_stat));
+ /* add pathes from CERTI_FOM_PATH */
+ if (NULL!=getenv("CERTI_FOM_PATH")) {
+ string path = getenv("CERTI_FOM_PATH");
+ vector<string> certi_fom_paths = split(path, ':');
+
fom_paths.insert(fom_paths.end(),certi_fom_paths.begin(),certi_fom_paths.end());
}
- if (!filefound) {
- if (verboseLevel>0) {
- cout << " --> cannot access." <<endl;
- }
- filename = PACKAGE_INSTALL_PREFIX
"\\share\\federations\\"+FEDid_name;
- if (verboseLevel>0) {
- cout << " Now trying..." << filename;
- }
- filefound = (0==STAT_FUNCTION(filename.c_str(),&file_stat));
- }
+ if (NULL!=getenv("CERTI_HOME")) {
+#ifdef WIN32
+
fom_paths.insert(fom_paths.end(),string(getenv("CERTI_HOME"))+"\\share\\federations\\");
#else
- if (!filefound && (NULL!=getenv("CERTI_HOME"))) {
- if (verboseLevel>0) {
- cout << " --> cannot access." <<endl;
- }
- filename =
string(getenv("CERTI_HOME"))+"/share/federations/"+FEDid_name;
- if (verboseLevel>0) {
- cout << " Now trying..." << filename;
- }
- filefound = (0==STAT_FUNCTION(filename.c_str(),&file_stat));
+
fom_paths.insert(fom_paths.end(),string(getenv("CERTI_HOME"))+"/share/federations/");
+#endif
}
- if (!filefound) {
- if (verboseLevel>0) {
- cout << " --> cannot access." << endl;
- }
- filename = PACKAGE_INSTALL_PREFIX
"/share/federations/"+FEDid_name;
- if (verboseLevel>0) {
- cout << " Now trying..." << filename;
- }
- filefound = (0==STAT_FUNCTION(filename.c_str(),&file_stat));
- }
+#ifdef WIN32
+ fom_paths.insert(fom_paths.end(),PACKAGE_INSTALL_PREFIX
"\\share\\federations");
+#else
+ fom_paths.insert(fom_paths.end(),PACKAGE_INSTALL_PREFIX
"/share/federations/");
+ fom_paths.insert(fom_paths.end(),"/usr/local/share/federations/");
+#endif
- if (!filefound) {
+ /* try to open FED using fom_paths prefixes */
+ for (vector<string>::iterator i = fom_paths.begin(); i !=
fom_paths.end(); i++) {
if (verboseLevel>0) {
- cout << " --> cannot access." << endl;
+ cout << " --> cannot access." <<endl;
}
- filename = "/usr/local/share/federations/"+FEDid_name;
+ filename = (*i)+FEDid_name;
if (verboseLevel>0) {
- cout << " Now trying..." << filename;
+ cout << " Now trying... " << filename;
}
filefound = (0==STAT_FUNCTION(filename.c_str(),&file_stat));
+ if (filefound) break;
+ }
}
-#endif
if (!filefound) {
if (verboseLevel>0) {
@@ -2745,5 +2733,5 @@
}} // namespace certi/rtig
-// $Id: Federation.cc,v 3.142 2011/09/02 21:42:24 erk Exp $
+// $Id: Federation.cc,v 3.143 2011/09/09 11:18:51 erk Exp $
- [certi-cvs] certi/RTIG Federation.cc,
CERTI CVS commits <=