Back to index

nordugrid-arc-nox  1.1.0~rc6
ArcRequestItem.cpp
Go to the documentation of this file.
00001 #ifdef HAVE_CONFIG_H
00002 #include <config.h>
00003 #endif
00004 
00005 #include "ArcRequestItem.h"
00006 #include "ArcAttributeFactory.h"
00007 #include <arc/security/ArcPDP/attr/RequestAttribute.h>
00008 
00009 using namespace Arc;
00010 using namespace ArcSec;
00011 
00012 ArcRequestItem::ArcRequestItem(XMLNode& node, AttributeFactory* attrfactory) : RequestItem(node, attrfactory) {
00013   //Parse the XMLNode structure, and generate the RequestAttribute object
00014   XMLNode nd;
00015 
00016   //Parse the <Subject> part
00017   for ( int i=0;; i++ ){
00018     std::string type;
00019     nd = node["Subject"][i];
00020     if(!nd) break;
00021 
00022     if(!((std::string)(nd.Attribute("Type"))).empty())
00023       type = (std::string)(nd.Attribute("Type"));
00024  
00025     //if the "Subject" is like this: 
00026     //<Subject AttributeId="urn:arc:subject:dn" Type="X500DN">/O=NorduGrid/OU=UIO/CN=test</Subject>
00027     if(!(type.empty())&&(nd.Size()==0)){
00028       Subject sub;
00029       sub.push_back(new RequestAttribute(nd, attrfactory));
00030       subjects.push_back(sub);
00031     }
00032     //else if like this:
00033     /*  <Subject>
00034           <Attribute AttributeId="urn:arc:subject:voms-attribute" Type="xsd:string">administrator</Attribute>
00035           <Attribute AttributeId="urn:arc:subject:voms-attribute" Type="X500DN">/O=NorduGrid/OU=UIO/CN=admin</Attribute>
00036         </Subject> */
00037     else if((type.empty())&&(nd.Size()>0)){
00038       Subject sub;
00039       for(int j=0;;j++){
00040         XMLNode tnd = nd.Child(j);
00041         if(!tnd) break;
00042         sub.push_back(new RequestAttribute(tnd, attrfactory));
00043       }
00044       subjects.push_back(sub);
00045     }
00046     //else if like this:
00047     /*  <Subject Type="xsd:string">
00048           <Attribute AttributeId="urn:arc:subject:voms-attribute">administrator</Attribute>
00049           <Attribute AttributeId="urn:arc:subject:voms-attribute">/O=NorduGrid/OU=UIO/CN=admin</Attribute>
00050         </Subject> */
00051     else if(!(type.empty())&&(nd.Size()>0)){
00052       Subject sub;
00053       for(int j=0;;j++){
00054         XMLNode tnd = nd.Child(j);
00055         if(!tnd) break;
00056         std::string type_fullname = (nd.Attribute("Type")).Prefix();
00057         type_fullname = type_fullname + ":Type";
00058         XMLNode type_prop = tnd.NewAttribute(type_fullname.c_str());
00059         type_prop = type;
00060         sub.push_back(new RequestAttribute(tnd, attrfactory));
00061       }
00062       subjects.push_back(sub);
00063     }
00064     //else if like this: <Subject/>
00065     else if((type.empty()) && (nd.Size()==0) && (((std::string)nd).empty())) {}
00066     else {std::cerr <<"Error definition in RequestItem:Subject"<<std::endl;}
00067   }
00068 
00069   //Parse the <Resource>
00070   for ( int i=0;; i++ ){
00071     std::string type;
00072     nd = node["Resource"][i];
00073     if(!nd) break;
00074     if(!((std::string)(nd.Attribute("Type"))).empty())
00075       type = (std::string)(nd.Attribute("Type"));
00076     if(!(type.empty())&&(nd.Size()==0)){
00077       Resource res;
00078       res.push_back(new RequestAttribute(nd, attrfactory));
00079       resources.push_back(res);
00080     }
00081     else if((type.empty())&&(nd.Size()>0)){
00082       Resource res;
00083       for(int j=0;;j++){
00084         XMLNode tnd = nd.Child(j);
00085         if(!tnd) break;
00086         res.push_back(new RequestAttribute(tnd, attrfactory));
00087       }
00088       resources.push_back(res);
00089     }
00090     else if(!(type.empty())&&(nd.Size()>0)){
00091       Resource res;
00092       for(int j=0;;j++){
00093         XMLNode tnd = nd.Child(j);
00094         if(!tnd) break;
00095         std::string type_fullname = (nd.Attribute("Type")).Prefix();
00096         type_fullname = type_fullname + ":Type";
00097         XMLNode type_prop = tnd.NewAttribute(type_fullname.c_str());
00098         type_prop = type;
00099         res.push_back(new RequestAttribute(tnd, attrfactory));
00100       }
00101       resources.push_back(res);
00102     }
00103     else if((type.empty()) && (nd.Size()==0) && (((std::string)nd).empty())) {}
00104     else {std::cerr <<"Error definition in RequestItem:Resource"<<std::endl;}
00105   }
00106 
00107   //Parse the <Action> part
00108   for ( int i=0;; i++ ){
00109     std::string type;
00110     nd = node["Action"][i];
00111     if(!nd) break;
00112     if(!((std::string)(nd.Attribute("Type"))).empty())
00113       type = (std::string)(nd.Attribute("Type"));
00114     if(!(type.empty())&&(nd.Size()==0)){
00115       Action act;
00116       act.push_back(new RequestAttribute(nd, attrfactory));
00117       actions.push_back(act);
00118     }
00119     else if((type.empty())&&(nd.Size()>0)){
00120       Action act;
00121       for(int j=0;;j++){
00122         XMLNode tnd = nd.Child(j);
00123         if(!tnd) break;
00124         act.push_back(new RequestAttribute(tnd, attrfactory));
00125       }
00126       actions.push_back(act);
00127     }
00128     else if(!(type.empty())&&(nd.Size()>0)){
00129       Action act;
00130       for(int j=0;;j++){
00131         XMLNode tnd = nd.Child(j);
00132         if(!tnd) break;
00133         std::string type_fullname = (nd.Attribute("Type")).Prefix();
00134         type_fullname = type_fullname + ":Type";
00135         XMLNode type_prop = tnd.NewAttribute(type_fullname.c_str());
00136         type_prop = type;
00137         act.push_back(new RequestAttribute(tnd, attrfactory));
00138       }
00139       actions.push_back(act);
00140     }
00141     else if((type.empty()) && (nd.Size()==0) && (((std::string)nd).empty())) {}
00142     else {std::cerr <<"Error definition in RequestItem:Action"<<std::endl;}
00143   }
00144 
00145   //Parse the Context part
00146   for ( int i=0;; i++ ){
00147     std::string type;
00148     nd = node["Context"][i];
00149     if(!nd) break;
00150     if(!((std::string)(nd.Attribute("Type"))).empty())
00151       type = (std::string)(nd.Attribute("Type"));
00152     if(!(type.empty())&&(nd.Size()==0)){
00153       Context ctx;
00154       ctx.push_back(new RequestAttribute(nd, attrfactory));
00155       contexts.push_back(ctx);
00156     }
00157     else if((type.empty())&&(nd.Size()>0)){
00158       Context ctx;
00159       for(int j=0;;j++){
00160         XMLNode tnd = nd.Child(j);
00161         if(!tnd) break;
00162         ctx.push_back(new RequestAttribute(tnd, attrfactory));
00163       }
00164       contexts.push_back(ctx);
00165     }
00166     else if(!(type.empty())&&(nd.Size()>0)){
00167       Context ctx;
00168       for(int j=0;;j++){
00169         XMLNode tnd = nd.Child(j);
00170         if(!tnd) break;
00171         std::string type_fullname = (nd.Attribute("Type")).Prefix();
00172         type_fullname = type_fullname + ":Type";
00173         XMLNode type_prop = tnd.NewAttribute(type_fullname.c_str());
00174         type_prop = type;
00175         ctx.push_back(new RequestAttribute(tnd, attrfactory));
00176       }
00177       contexts.push_back(ctx);
00178     }
00179     else if((type.empty()) && (nd.Size()==0) && (((std::string)nd).empty())) {}
00180     else {std::cerr <<"Error definition in RequestItem:Context"<<std::endl;}
00181   }
00182 }
00183 
00184 void ArcRequestItem::removeSubjects() {
00185   while(!(subjects.empty())){
00186     Subject sub = subjects.back();
00187     while(!(sub.empty())){
00188       delete sub.back();
00189       sub.pop_back();
00190     }
00191     subjects.pop_back();
00192   }
00193 }
00194   
00195 void ArcRequestItem::removeResources() {
00196   while(!(resources.empty())){
00197     Resource res = resources.back();
00198     while(!(res.empty())){
00199       delete res.back();
00200       res.pop_back();
00201     }
00202     resources.pop_back();
00203   }
00204 }
00205 
00206 void ArcRequestItem::removeActions() {
00207   while(!(actions.empty())){
00208     Action act = actions.back();
00209     while(!(act.empty())){
00210       delete act.back();
00211       act.pop_back();
00212     }
00213     actions.pop_back();
00214   }
00215 }
00216 
00217 void ArcRequestItem::removeContexts() {
00218   while(!(contexts.empty())){
00219     Context ctx = contexts.back();
00220     while(!(ctx.empty())){
00221       delete ctx.back();
00222       ctx.pop_back();
00223     }
00224     contexts.pop_back();
00225   }
00226 }
00227 
00228 ArcRequestItem::~ArcRequestItem(void){
00229   removeSubjects();
00230   removeResources();
00231   removeActions();
00232   removeContexts();
00233 }
00234 
00235 SubList ArcRequestItem::getSubjects () const{
00236   return subjects;
00237 }
00238 
00239 void ArcRequestItem::setSubjects (const SubList& sl){
00240   removeSubjects();
00241   subjects = sl;
00242 }
00243 
00244 ResList ArcRequestItem::getResources () const{
00245   return resources;
00246 }
00247 
00248 void ArcRequestItem::setResources (const ResList& rl){
00249   removeResources();
00250   resources = rl;
00251 }
00252 
00253 ActList ArcRequestItem::getActions () const {
00254   return actions;
00255 }
00256 
00257 void ArcRequestItem::setActions (const ActList& al){
00258   removeActions();
00259   actions = al;
00260 }
00261 
00262 CtxList ArcRequestItem::getContexts () const{
00263   return contexts;
00264 }
00265 
00266 void ArcRequestItem::setContexts (const CtxList& ctx){
00267   removeContexts();
00268   contexts = ctx;
00269 }
00270