From: cantor Date: Fri, 5 Mar 2010 21:28:27 +0000 (+0000) Subject: Add shorthand methods for obtaining properties using standard precedence rules. X-Git-Tag: 2.4~97 X-Git-Url: http://www.project-moonshot.org/gitweb/?p=shibboleth%2Fsp.git;a=commitdiff_plain;h=c319ffdb0d4b25bb0e19badf3e456dc5845bb4ce Add shorthand methods for obtaining properties using standard precedence rules. git-svn-id: https://svn.middleware.georgetown.edu/cpp-sp/branches/REL_2@3242 cb58f699-b61c-0410-a6fe-9272a202ed29 --- diff --git a/shibsp/handler/AbstractHandler.h b/shibsp/handler/AbstractHandler.h index d797b27..78f3183 100644 --- a/shibsp/handler/AbstractHandler.h +++ b/shibsp/handler/AbstractHandler.h @@ -1,5 +1,5 @@ /* - * Copyright 2001-2009 Internet2 + * Copyright 2001-2010 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -182,6 +182,62 @@ namespace shibsp { DDF& postData ) const; + /** + * Bitmask of property sources to read from + * (request query parameter, request mapper, fixed handler property). + */ + enum PropertySourceTypes { + HANDLER_PROPERTY_REQUEST = 1, + HANDLER_PROPERTY_MAP = 2, + HANDLER_PROPERTY_FIXED = 4, + HANDLER_PROPERTY_ALL = 255 + }; + + using DOMPropertySet::getBool; + using DOMPropertySet::getString; + using DOMPropertySet::getUnsignedInt; + using DOMPropertySet::getInt; + + /** + * Returns a boolean-valued property. + * + * @param name property name + * @param request reference to incoming request + * @param type bitmask of property sources to use + * @return a pair consisting of a NULL indicator and the property value iff the indicator is true + */ + std::pair getBool(const char* name, const SPRequest& request, unsigned int type=HANDLER_PROPERTY_ALL) const; + + /** + * Returns a string-valued property. + * + * @param name property name + * @param request reference to incoming request + * @param type bitmask of property sources to use + * @return a pair consisting of a NULL indicator and the property value iff the indicator is true + */ + std::pair getString(const char* name, const SPRequest& request, unsigned int type=HANDLER_PROPERTY_ALL) const; + + /** + * Returns an unsigned integer-valued property. + * + * @param name property name + * @param request reference to incoming request + * @param type bitmask of property sources to use + * @return a pair consisting of a NULL indicator and the property value iff the indicator is true + */ + std::pair getUnsignedInt(const char* name, const SPRequest& request, unsigned int type=HANDLER_PROPERTY_ALL) const; + + /** + * Returns an integer-valued property. + * + * @param name property name + * @param request reference to incoming request + * @param type bitmask of property sources to use + * @return a pair consisting of a NULL indicator and the property value iff the indicator is true + */ + std::pair getInt(const char* name, const SPRequest& request, unsigned int type=HANDLER_PROPERTY_ALL) const; + /** Logging object. */ xmltooling::logging::Category& m_log; diff --git a/shibsp/handler/impl/AbstractHandler.cpp b/shibsp/handler/impl/AbstractHandler.cpp index 39ac7dc..aa86b54 100644 --- a/shibsp/handler/impl/AbstractHandler.cpp +++ b/shibsp/handler/impl/AbstractHandler.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2001-2009 Internet2 + * Copyright 2001-2010 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -700,3 +700,87 @@ DDF AbstractHandler::getPostData(const Application& application, const HTTPReque } return DDF(); } + +pair AbstractHandler::getBool(const char* name, const SPRequest& request, unsigned int type) const +{ + if (type & HANDLER_PROPERTY_REQUEST) { + const char* param = request.getParameter(name); + if (param && *param) + return make_pair(true, (*param=='t' || *param=='1')); + } + + if (type & HANDLER_PROPERTY_MAP) { + pair ret = request.getRequestSettings().first->getBool(name); + if (ret.first) + return ret; + } + + if (type & HANDLER_PROPERTY_FIXED) { + return getBool(name); + } + + return make_pair(false,false); +} + +pair AbstractHandler::getString(const char* name, const SPRequest& request, unsigned int type) const +{ + if (type & HANDLER_PROPERTY_REQUEST) { + const char* param = request.getParameter(name); + if (param && *param) + return make_pair(true, param); + } + + if (type & HANDLER_PROPERTY_MAP) { + pair ret = request.getRequestSettings().first->getString(name); + if (ret.first) + return ret; + } + + if (type & HANDLER_PROPERTY_FIXED) { + return getString(name); + } + + return pair(false,NULL); +} + +pair AbstractHandler::getUnsignedInt(const char* name, const SPRequest& request, unsigned int type) const +{ + if (type & HANDLER_PROPERTY_REQUEST) { + const char* param = request.getParameter(name); + if (param && *param) + return pair(true, strtol(param,NULL,10)); + } + + if (type & HANDLER_PROPERTY_MAP) { + pair ret = request.getRequestSettings().first->getUnsignedInt(name); + if (ret.first) + return ret; + } + + if (type & HANDLER_PROPERTY_FIXED) { + return getUnsignedInt(name); + } + + return pair(false,0); +} + +pair AbstractHandler::getInt(const char* name, const SPRequest& request, unsigned int type) const +{ + if (type & HANDLER_PROPERTY_REQUEST) { + const char* param = request.getParameter(name); + if (param && *param) + return pair(true, atoi(param)); + } + + if (type & HANDLER_PROPERTY_MAP) { + pair ret = request.getRequestSettings().first->getInt(name); + if (ret.first) + return ret; + } + + if (type & HANDLER_PROPERTY_FIXED) { + return getInt(name); + } + + return pair(false,0); +}