Back to index

nordugrid-arc-nox  1.1.0~rc6
Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes
Hopi::Hopi Class Reference

#include <hopi.h>

Inheritance diagram for Hopi::Hopi:
Inheritance graph
[legend]
Collaboration diagram for Hopi::Hopi:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Hopi (Arc::Config *cfg)
virtual ~Hopi (void)
virtual Arc::MCC_Status process (Arc::Message &inmsg, Arc::Message &outmsg)
 Method for processing of requests and responses.
bool RegistrationCollector (Arc::XMLNode &doc)
 Service specific registartion collector, used for generate service registartions.
virtual void AddSecHandler (Config *cfg, ArcSec::SecHandler *sechandler, const std::string &label="")
 Add security components/handlers to this MCC.
virtual std::string getID ()
 Service may implement own service identitifer gathering method.

Static Public Attributes

static Arc::Logger logger
 Logger object used to print messages generated by this class.

Protected Member Functions

Arc::MessagePayloadGet (const std::string &path, const std::string &base_url, unsigned long long int range_start, unsigned long long int range_end)
Arc::MCC_Status Put (const std::string &path, Arc::MessagePayload &buf)
bool ProcessSecHandlers (Message &message, const std::string &label="") const
 Executes security handlers of specified queue.

Protected Attributes

std::string doc_root
bool slave_mode
std::map< std::string,
std::list< ArcSec::SecHandler * > > 
sechandlers_
 Set of labeled authentication and authorization handlers.

Detailed Description

Definition at line 12 of file hopi.h.


Constructor & Destructor Documentation

Definition at line 409 of file hopi.cpp.

                        :RegisteredService(cfg),slave_mode(false)
{
    logger.msg(Arc::INFO, "Hopi Initialized"); 
    doc_root = (std::string)((*cfg)["DocumentRoot"]);
    if (doc_root.empty()) {
        doc_root = "./";
    }
    logger.msg(Arc::INFO, "Hopi DocumentRoot is " + doc_root);
    slave_mode = (((std::string)((*cfg)["SlaveMode"])) == "1");
    if (slave_mode) logger.msg(Arc::INFO, "Hopi SlaveMode is on!");
    int timeout;
    if(Arc::stringto((std::string)((*cfg)["UploadTimeout"]),timeout)) {
        if(timeout > 0) HopiFileChunks::Timeout(timeout);
    }
    if(Arc::stringto((std::string)((*cfg)["DownloadTimeout"]),timeout)) {
        if(timeout > 0) HopiFileTimeout::Timeout(timeout);
    }
    uint64_t threshold;
    if(Arc::stringto((std::string)((*cfg)["MemoryMapThreshold"]),threshold)) {
      if(threshold > 0) PayloadBigFile::Threshold(threshold);
    }
}

Here is the call graph for this function:

Hopi::Hopi::~Hopi ( void  ) [virtual]

Definition at line 440 of file hopi.cpp.

Here is the call graph for this function:


Member Function Documentation

void Arc::Service::AddSecHandler ( Config cfg,
ArcSec::SecHandler sechandler,
const std::string &  label = "" 
) [virtual, inherited]

Add security components/handlers to this MCC.

For more information please see description of MCC::AddSecHandler

Definition at line 14 of file Service.cpp.

                                                                                           {
    if(sechandler) {
        sechandlers_[label].push_back(sechandler); //need polishing to put the SecHandlerFactory->getinstance here
        XMLNode cn = (*cfg)["SecHandler"];
        Config cfg_(cn);
    }
}

Here is the caller graph for this function:

Arc::MessagePayload * Hopi::Hopi::Get ( const std::string &  path,
const std::string &  base_url,
unsigned long long int  range_start,
unsigned long long int  range_end 
) [protected]

Definition at line 447 of file hopi.cpp.

{
    // XXX eliminate relative paths first
    std::string full_path = Glib::build_filename(doc_root, path);
    if (Glib::file_test(full_path, Glib::FILE_TEST_EXISTS) == true) {
        if (Glib::file_test(full_path, Glib::FILE_TEST_IS_REGULAR) == true) {
            // register file for removal after timeout
            Arc::MessagePayload * pf = newFileRead(full_path.c_str(),range_start,range_end);
            if(pf && slave_mode) HopiFileTimeout::Add(full_path);
            return pf;
        } else if (Glib::file_test(full_path, Glib::FILE_TEST_IS_DIR) && !slave_mode) {
            std::string html = "<HTML>\r\n<HEAD>Directory list of '" + path + "'</HEAD>\r\n<BODY><UL>\r\n";
            Glib::Dir dir(full_path);
            std::string d;
            std::string p;
            if (path == "/") {
                p = "";
            } else {
                p = path;
            }
            while ((d = dir.read_name()) != "") {
                html += "<LI><a href=\""+ base_url + p + "/"+d+"\">"+d+"</a></LI>\r\n";
            }
            html += "</UL></BODY></HTML>";
            Arc::PayloadRaw *buf = new Arc::PayloadRaw();
            buf->Insert(html.c_str(), 0, html.length());
            return buf;
        }
    }
    return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

virtual std::string Arc::Service::getID ( ) [inline, virtual, inherited]

Service may implement own service identitifer gathering method.

This method return identifier of service which is used for registering it Information Services.

Reimplemented in ARex::ARexService.

Definition at line 69 of file Service.h.

{ return ""; };
Arc::MCC_Status Hopi::Hopi::process ( Arc::Message request,
Arc::Message response 
) [virtual]

Method for processing of requests and responses.

This method is called by preceeding MCC in chain when a request needs to be processed. This method must call similar method of next MCC in chain unless any failure happens. Result returned by call to next MCC should be processed and passed back to previous MCC. In case of failure this method is expected to generate valid error response and return it back to previous MCC without calling the next one.

Parameters:
requestThe request that needs to be processed.
responseA Message object that will contain the response of the request when the method returns.
Returns:
An object representing the status of the call.

Implements Arc::MCCInterface.

Definition at line 560 of file hopi.cpp.

{
    std::string method = inmsg.Attributes()->get("HTTP:METHOD");
    std::string base_url;
    std::string path = GetPath(inmsg,base_url);

    logger.msg(Arc::VERBOSE, "method=%s, path=%s, url=%s, base=%s", method, path, inmsg.Attributes()->get("HTTP:ENDPOINT"), base_url);
    // Do file cleaning here to avoid running dedicated thread
    HopiFile::DestroyStuck();
    HopiFileTimeout::DestroyOld();
    if (method == "GET") {
        size_t range_start = 0;
        size_t range_end = (size_t)(-1);
        {
          std::string val;
          val=inmsg.Attributes()->get("HTTP:RANGESTART");
          if(!val.empty()) { // Negative ranges not supported
            if(!Arc::stringto<size_t>(val,range_start)) {
              range_start=0;
            } else {
              val=inmsg.Attributes()->get("HTTP:RANGEEND");
              if(!val.empty()) {
                if(!Arc::stringto<size_t>(val,range_end)) {
                  range_end=(size_t)(-1);
                } else {
                  range_end+=1;
                };
              };
            };
          };
        };
        Arc::MessagePayload *buf = Get(path, base_url, range_start, range_end);
        if (!buf) {
            // XXX: HTTP error
            return Arc::MCC_Status();
        }
        outmsg.Payload(buf);
        return Arc::MCC_Status(Arc::STATUS_OK);
    } else if (method == "PUT") {
        Arc::MessagePayload *inpayload = inmsg.Payload();
        if(!inpayload) {
            logger.msg(Arc::WARNING, "No content provided for PUT operation");
            return Arc::MCC_Status();
        }
        Arc::MCC_Status ret = Put(path, *inpayload);
        if (!ret) {
            // XXX: HTTP error
            return Arc::MCC_Status();
        }
        Arc::PayloadRaw *buf = new Arc::PayloadRaw();
        outmsg.Payload(buf);
        return ret;
    } 
    logger.msg(Arc::WARNING, "Not supported operation");
    return Arc::MCC_Status();
}

Here is the call graph for this function:

bool Arc::Service::ProcessSecHandlers ( Message message,
const std::string &  label = "" 
) const [protected, inherited]

Executes security handlers of specified queue.

For more information please see description of MCC::ProcessSecHandlers

Definition at line 22 of file Service.cpp.

                                                                              {
    std::map<std::string,std::list<ArcSec::SecHandler*> >::const_iterator q = sechandlers_.find(label);
    if(q == sechandlers_.end()) {
        logger.msg(DEBUG, "No security processing/check requested for '%s'", label);
        return true;
    }

    std::list<ArcSec::SecHandler*>::const_iterator h = q->second.begin();
    for(;h!=q->second.end();++h) {
        const ArcSec::SecHandler* handler = *h;
        if(handler) if(!(handler->Handle(&message))) {
            logger.msg(DEBUG, "Security processing/check for '%s' failed", label);
            return false;
        }
    }
    logger.msg(DEBUG, "Security processing/check for '%s' passed", label);
    return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Arc::MCC_Status Hopi::Hopi::Put ( const std::string &  path,
Arc::MessagePayload buf 
) [protected]

Definition at line 488 of file hopi.cpp.

{
    // XXX eliminate relative paths first
    logger.msg(Arc::VERBOSE, "PUT called");
    std::string full_path = Glib::build_filename(doc_root, path);
    if (slave_mode && (Glib::file_test(full_path, Glib::FILE_TEST_EXISTS) == false)) {
        logger.msg(Arc::ERROR, "Hopi SlaveMode is active, PUT is only allowed to existing files");        
        return Arc::MCC_Status();
    }
    HopiFile fd(full_path.c_str(),false,slave_mode);
    if (!fd) {
        return Arc::MCC_Status();
    }
    fd.Size(GetEntitySize(payload));
    logger.msg(Arc::DEBUG, "File size is %u",fd.Size());
    try {
        Arc::PayloadStreamInterface& stream = dynamic_cast<Arc::PayloadStreamInterface&>(payload);
        char sbuf[1024*1024];
        for(;;) {
            int size = sizeof(sbuf);
            off_t offset = stream.Pos();
            if(!stream.Get(sbuf,size)) {
                if(!stream) {
                    logger.msg(Arc::VERBOSE, "error reading from HTTP stream");
                    return Arc::MCC_Status();
                }
                break;
            }
            if(fd.Write(sbuf,offset,size) != size) {
              logger.msg(Arc::VERBOSE, "error on write");
              return Arc::MCC_Status();
            }
        }
    } catch (std::exception &e) {
        try {
            Arc::PayloadRawInterface& buf = dynamic_cast<Arc::PayloadRawInterface&>(payload);
            for(int n = 0;;++n) {
                char* sbuf = buf.Buffer(n);
                if(sbuf == NULL) break;
                off_t offset = buf.BufferPos(n);
                size_t size = buf.BufferSize(n);
                if(size > 0) {
                    if(fd.Write(sbuf,offset,size) != size) {
                        logger.msg(Arc::VERBOSE, "error on write");
                        return Arc::MCC_Status();
                    }
                }
            }
        } catch (std::exception &e) {
            logger.msg(Arc::ERROR, "Input for PUT operation is neither stream nor buffer");
            return Arc::MCC_Status();
        }
    }
    return Arc::MCC_Status(Arc::STATUS_OK);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Service specific registartion collector, used for generate service registartions.

In implemented service this method should generate GLUE2 document with part of service description which service wishes to advertise to Information Services.

Reimplemented from Arc::Service.

Definition at line 432 of file hopi.cpp.

                                                {
    Arc::NS isis_ns; isis_ns["isis"] = "http://www.nordugrid.org/schemas/isis/2008/08";
    Arc::XMLNode regentry(isis_ns, "RegEntry");
    regentry.NewChild("SrcAdv").NewChild("Type") = "org.nordugrid.storage.hopi";
    regentry.New(doc);
    return true;
}

Here is the call graph for this function:


Member Data Documentation

std::string Hopi::Hopi::doc_root [protected]

Definition at line 14 of file hopi.h.

Logger object used to print messages generated by this class.

Reimplemented from Arc::Service.

Definition at line 19 of file hopi.h.

std::map<std::string,std::list<ArcSec::SecHandler*> > Arc::Service::sechandlers_ [protected, inherited]

Set of labeled authentication and authorization handlers.

MCC calls sequence of handlers at specific point depending on associated identifier. in most aces those are "in" and "out" for incoming and outgoing messages correspondingly.

Definition at line 40 of file Service.h.

bool Hopi::Hopi::slave_mode [protected]

Definition at line 15 of file hopi.h.


The documentation for this class was generated from the following files: