Back to index

nordugrid-arc-nox  1.1.0~rc6
ArcRequest.cpp
Go to the documentation of this file.
00001 #ifdef HAVE_CONFIG_H
00002 #include <config.h>
00003 #endif
00004 
00005 #include <fstream>
00006 #include <iostream>
00007 
00008 #include <arc/security/ClassLoader.h>
00009 
00010 #include "ArcRequest.h"
00011 #include "ArcRequestItem.h"
00012 
00014 Arc::Plugin* ArcSec::ArcRequest::get_request(Arc::PluginArgument* arg) {
00015   //std::cout<<"Argument type of ArcRequest:"<<typeid(arg).name()<<std::endl;
00016   if(arg==NULL) return NULL;
00017   else {
00018     /*
00019     {
00020       std::string xml;
00021       ((Arc::XMLNode*)arg)->GetXML(xml);
00022       std::cout<<"node inside ArcRequest:"<<xml<<std::endl;
00023     };
00024     */
00025     Arc::ClassLoaderPluginArgument* clarg =
00026             arg?dynamic_cast<Arc::ClassLoaderPluginArgument*>(arg):NULL;
00027     if(!clarg) return NULL;
00028     Arc::XMLNode* xarg = (Arc::XMLNode*)(*clarg);
00029     if(xarg==NULL) { return new ArcSec::ArcRequest(); } // ???
00030     ArcSec::Source source(*xarg);
00031     return new ArcSec::ArcRequest(source);
00032   }
00033 }
00034 
00035 //loader_descriptors __arc_request_modules__  = {
00036 //    { "arc.request", 0, &ArcSec::ArcRequest::get_request },
00037 //    { NULL, 0, NULL }
00038 //};
00039 
00040 
00041 using namespace Arc;
00042 using namespace ArcSec;
00043 
00044 ReqItemList ArcRequest::getRequestItems () const {
00045   return rlist;
00046 }
00047 
00048 void ArcRequest::setRequestItems (ReqItemList sl){
00049   rlist = sl;
00050 }
00051 
00052 void ArcRequest::addRequestItem(Attrs& sub, Attrs& res, Attrs& act, Attrs& ctx){
00053   //Add a new RequestItem into reqnode 
00054   XMLNode request = reqnode;
00055   XMLNode requestitem = request.NewChild("ra:RequestItem");
00056 
00057   XMLNode subject = requestitem.NewChild("ra:Subject");
00058   int i;
00059   int size = sub.size();
00060   if(size>1) {
00061     for(i = 0; i < size; i++ )
00062     {
00063       XMLNode subjectattr = subject.NewChild("ra:Attribute");
00064       subjectattr = sub[i].value;
00065       XMLNode subjectattr_attr = subjectattr.NewAttribute("ra:Type");
00066       subjectattr_attr = sub[i].type;
00067     }
00068   }
00069   else{
00070     XMLNode subject_attr = subject.NewAttribute("ra:Type");
00071     subject = sub[0].value;
00072     subject_attr = sub[0].type;
00073   }
00074 
00075   XMLNode resource = requestitem.NewChild("ra:Resource");
00076   size = res.size();
00077   if(size>1) {
00078     for(i = 0; i< size; i++)
00079     {
00080       XMLNode resourceattr = resource.NewChild("ra:Attribute");
00081       resourceattr = res[i].value;
00082       XMLNode resourceattr_attr = resourceattr.NewAttribute("ra:Type");
00083       resourceattr_attr = res[i].type;
00084     }
00085   }
00086   else{
00087     XMLNode resource_attr = resource.NewAttribute("ra:Type");
00088     resource = res[0].value;
00089     resource_attr = res[0].type;
00090   }
00091 
00092   XMLNode action = requestitem.NewChild("ra:Action");
00093   size = act.size();
00094   if(size>1) {
00095     for(i = 0; i < size; i++)
00096     {
00097       XMLNode actionattr = action.NewChild("ra:Attribute");
00098       actionattr = act[i].value;
00099       XMLNode actionattr_attr = actionattr.NewAttribute("ra:Type");
00100       actionattr_attr = act[i].type;
00101     }
00102   }
00103   else{
00104     XMLNode action_attr = action.NewAttribute("ra:Type");
00105     action = act[0].value;
00106     action_attr = act[0].type;
00107   }
00108 
00109   XMLNode context = requestitem.NewChild("ra:Context");
00110   size = ctx.size();
00111   if(size>1) {
00112     for(i = 0; i < size; i++)
00113     {
00114       XMLNode contextattr = context.NewChild("ra:Attribute");
00115       contextattr = ctx[i].value;
00116       XMLNode contextattr_attr = contextattr.NewAttribute("ra:Type");
00117       contextattr_attr = ctx[i].type;
00118     }
00119   }
00120   else{
00121     XMLNode context_attr = context.NewAttribute("ra:Type");
00122     context = ctx[0].value;
00123     context_attr = ctx[0].type;
00124   }
00125 
00126   std::string xml;
00127   reqnode.GetDoc(xml);
00128   std::cout<<xml<<std::endl; 
00129 
00130 }
00131 
00132 void ArcRequest::make_request(){
00133   Arc::NS nsList;
00134 
00135   nsList.insert(std::pair<std::string, std::string>("request","http://www.nordugrid.org/schemas/request-arc"));
00136 
00137   std::list<XMLNode>::iterator itemit;
00138     std::list<XMLNode> itemlist = reqnode.XPathLookup("//request:RequestItem", nsList);
00139     for ( itemit=itemlist.begin() ; itemit != itemlist.end(); itemit++ ){
00140       XMLNode itemnd=*itemit;
00141       //Generate a new ArcRequestItem, which will generate RequestAttribute object 
00142       rlist.push_back(new ArcRequestItem(itemnd, attrfactory));
00143     }
00144 }
00145 
00146 const char* ArcRequest::getEvalName() const{
00147   return "arc.evaluator";
00148 }
00149 
00150 const char* ArcRequest::getName() const{
00151   return "arc.request";
00152 }
00153 
00154 ArcRequest::ArcRequest (const Source& req) : Request(req) {
00155   req.Get().New(reqnode);
00156   NS ns;
00157   ns["ra"]="http://www.nordugrid.org/schemas/request-arc";
00158   reqnode.Namespaces(ns);
00159 }
00160 
00161 ArcRequest::ArcRequest () {
00162   NS ns;
00163   ns["ra"]="http://www.nordugrid.org/schemas/request-arc";
00164   XMLNode request(ns,"ra:Request");
00165   request.New(reqnode);
00166 }
00167 
00168 ArcRequest::~ArcRequest(){
00169   while(!(rlist.empty())){
00170     delete rlist.back();
00171     rlist.pop_back();
00172   }
00173 }