Back to index

nordugrid-arc-nox  1.1.0~rc6
SRMURL.cpp
Go to the documentation of this file.
00001 #include <arc/StringConv.h>
00002 
00003 #include "SRMURL.h"
00004 
00005 //namespace Arc {
00006   
00007   SRMURL::SRMURL(std::string url) try: URL(url) {
00008     portdefined = false;
00009     if(protocol != "srm") { 
00010       valid=false;
00011       return; 
00012     };
00013     valid=true;
00014     if(port <= 0) port=8443;
00015     else portdefined = true;
00016     srm_version = SRM_URL_VERSION_2_2; // v2.2 unless explicitly made otherwise
00017     if(HTTPOption("SFN", "") != "") {
00018       filename=HTTPOption("SFN");
00019       isshort=false;
00020       path = '/'+path;
00021       for(;path.size() > 1;) {
00022         if(path[1] != '/') break;
00023         path.erase(0,1);
00024       };
00025       if (path[path.size()-1] == '1') srm_version = SRM_URL_VERSION_1;
00026     }
00027     else {
00028       if(path.length() > 0) filename=path.c_str()+1; // Skip leading '/'
00029       path = "/srm/managerv2";
00030       isshort=true;
00031     }
00032   } catch (std::exception e) {
00033     valid=false;
00034   }  
00035   
00036   std::string SRMURL::empty("");
00037   
00038   
00039   void SRMURL::SetSRMVersion(std::string version) {
00040     if (version.empty()) return;
00041     if (version == "1") {
00042       srm_version = SRM_URL_VERSION_1;
00043       path = "/srm/managerv1";
00044     }
00045     else if (version == "2.2") {
00046       srm_version = SRM_URL_VERSION_2_2;
00047       path = "/srm/managerv2";
00048     }
00049     else {
00050       srm_version = SRM_URL_VERSION_UNKNOWN; 
00051     }
00052   }
00053   
00054   std::string SRMURL::ContactURL(void) const {
00055     if(!valid) return empty;
00056     return ("httpg://"+host+":"+Arc::tostring(port)+path);
00057   }
00058   
00059   std::string SRMURL::BaseURL(void) const {
00060     if(!valid) return empty;
00061     return (protocol+"://"+host+":"+Arc::tostring(port)+path+"?SFN=");
00062   }
00063   
00064   std::string SRMURL::FullURL(void) const {
00065     if(!valid) return empty;
00066     return (protocol+"://"+host+":"+Arc::tostring(port)+path+"?SFN="+filename);
00067   }
00068   
00069   std::string SRMURL::ShortURL(void) const {
00070     return (protocol+"://"+host+":"+Arc::tostring(port)+"/"+filename);
00071   }
00072   
00073   void SRMURL::GSSAPI(bool gssapi) {
00074     if (gssapi)
00075       AddOption("protocol", "gssapi", true);
00076     else
00077       AddOption("protocol", "gsi", true);
00078   }
00079 
00080   bool SRMURL::GSSAPI(void) const {
00081     try {
00082       const std::string proto_val = Option("protocol");
00083       if(proto_val == "gsi") return false;
00084     } catch (std::exception e) { };
00085     return true;
00086   }
00087 
00088 //} // namespace Arc