Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-03-13 09:31:07

0001 #ifndef __SEC_ENTITYATTR_H__
0002 #define __SEC_ENTITYATTR_H__
0003 /******************************************************************************/
0004 /*                                                                            */
0005 /*                   X r d S e c E n t i t y A t t r . h h                    */
0006 /*                                                                            */
0007 /* (c) 2019 by the Board of Trustees of the Leland Stanford, Jr., University  */
0008 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
0009 /*              DE-AC02-76-SFO0515 with the Department of Energy              */
0010 /*                                                                            */
0011 /* This file is part of the XRootD software suite.                            */
0012 /*                                                                            */
0013 /* XRootD is free software: you can redistribute it and/or modify it under    */
0014 /* the terms of the GNU Lesser General Public License as published by the     */
0015 /* Free Software Foundation, either version 3 of the License, or (at your     */
0016 /* option) any later version.                                                 */
0017 /*                                                                            */
0018 /* XRootD is distributed in the hope that it will be useful, but WITHOUT      */
0019 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or      */
0020 /* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public       */
0021 /* License for more details.                                                  */
0022 /*                                                                            */
0023 /* You should have received a copy of the GNU Lesser General Public License   */
0024 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file  */
0025 /* COPYING (GPL license).  If not, see <http://www.gnu.org/licenses/>.        */
0026 /*                                                                            */
0027 /* The copyright holder's institutional names and contributor's names may not */
0028 /* be used to endorse or promote products derived from this software without  */
0029 /* specific prior written permission of the institution or contributor.       */
0030 /******************************************************************************/
0031 
0032 //------------------------------------------------------------------------------
0033 //! This object is a non-const extension of the XrdSecEntity object. It is
0034 //! used as the interface to XrdSecEntity attributes. Normally, a const
0035 //! pointer is used for the XrdSecEntity object as nothing changes in the
0036 //! entity. However, attributes may be added and deleted from the entity
0037 //! changing the logical view of the entity. This provides a non-const
0038 //! mechanism to this without the need to recast the XrdSecEntity pointer.
0039 //------------------------------------------------------------------------------
0040 
0041 #include <sys/types.h>
0042 
0043 #include <string>
0044 #include <vector>
0045 
0046 class XrdSecAttr;
0047 class XrdSecEntityAttrCB;
0048 class XrdSecEntityXtra;
0049   
0050 /******************************************************************************/
0051 /*                      X r d S e c E n t i t y A t t r                       */
0052 /******************************************************************************/
0053   
0054 class XrdSecEntityAttr
0055 {
0056 public:
0057 friend class XrdSecEntity;
0058 
0059 //------------------------------------------------------------------------------
0060 //! Add an attribute object to this entity.
0061 //!
0062 //! @param  attr    - Reference to the attribute object.
0063 //!
0064 //! @return True, the object was added.
0065 //! @return False, the object was not added because such an object exists.
0066 //------------------------------------------------------------------------------
0067 
0068          bool    Add(XrdSecAttr &attr);
0069 
0070 //------------------------------------------------------------------------------
0071 //! Add a key-value attribute to this entity. If one exists it is replaced.
0072 //!
0073 //! @param  key     - Reference to the key.
0074 //! @param  val     - Reference to the value.
0075 //! @param  replace - When true, any existing key-value is replaced. Otherwise,
0076 //!                   the add is not performed.
0077 //!
0078 //! @return True, the key-value was added or replaced.
0079 //! @return False, the key already exists so he value was not added.
0080 //------------------------------------------------------------------------------
0081 
0082          bool    Add(const std::string &key,
0083                      const std::string &val, bool replace=false);
0084 
0085 //------------------------------------------------------------------------------
0086 //! Get an attribute object associated with this entity.
0087 //!
0088 //! @param  sigkey  - A unique attribute object signature key.
0089 //!
0090 //! @return Upon success a pointer to the attribute object is returned.
0091 //!         Otherwise, a nil pointer is returned.
0092 //------------------------------------------------------------------------------
0093 
0094 XrdSecAttr      *Get(const void *sigkey);
0095 
0096 //------------------------------------------------------------------------------
0097 //! Get an attribute key value associated with this entity.
0098 //!
0099 //! @param  key     - The reference to the key.
0100 //! @param  val     - The reference to the string object to receive the value.
0101 //!
0102 //! @return Upon success true is returned. If the key does not exist, false
0103 //!         is returned and the val object remains unchanged.
0104 //------------------------------------------------------------------------------
0105 
0106          bool    Get(const std::string &key, std::string &val);
0107 
0108 //------------------------------------------------------------------------------
0109 //! Get all the keys for associated attribytes.
0110 //!
0111 //! @return A vector containing all of the keys.
0112 //------------------------------------------------------------------------------
0113 
0114 std::vector<std::string> Keys();
0115 
0116 //------------------------------------------------------------------------------
0117 //! List key-value pairs via iterative callback on passed ovject.
0118 //!
0119 //! @param  attrCB  - Reference to the callback object to receive list entries.
0120 //------------------------------------------------------------------------------
0121 
0122          void    List(XrdSecEntityAttrCB &attrCB);
0123 
0124 //------------------------------------------------------------------------------
0125 //! Constructor and Destructor.
0126 //!
0127 //! @param  xtra    - Pointer to the data for the implementation.
0128 //------------------------------------------------------------------------------
0129 
0130          XrdSecEntityAttr(XrdSecEntityXtra *xtra) : entXtra(xtra) {}
0131 
0132         ~XrdSecEntityAttr() {}
0133 
0134 private:
0135 
0136 XrdSecEntityXtra *entXtra;
0137 };
0138 
0139 /******************************************************************************/
0140 /*                    X r d S e c E n t i t y A t t r C B                     */
0141 /******************************************************************************/
0142 
0143 // The XrdSecEntityAttrCB class defines the callback object passed to the
0144 // XrdSecEntity::List() method to iteratively obtain the key-value attribute
0145 // pairs associated with the entity. The XrdSecEntityAttrCB::Attr() method is
0146 // called for each key-value pair. The end of the list is indicated by calling
0147 // Attr() with nil key-value pointers. The Attr() method should not call
0148 // the XrdSecEntity::Add() or XrdSecEntity::Get() methods; otherwise, a
0149 // deadlock will occur.
0150 //
0151 class XrdSecEntityAttrCB
0152 {
0153 public:
0154 
0155 //------------------------------------------------------------------------------
0156 //! Acceppt a key-value attribute pair from the XrdSecEntity::List() method.
0157 //!
0158 //! @param  key   - The key, if nil this is the end of the list.
0159 //! @param  val   - The associated value, if nil this is the end of the list.
0160 //!
0161 //! @return One of the Action enum values. The return value is ignored when
0162 //!         the end of the list indicator is returned.
0163 //------------------------------------------------------------------------------
0164 
0165 enum     Action {Delete = -1, //!< Delete the key-value and proceed to next one
0166                  Stop   =  0, //!< Stop the iteration
0167                  Next   =  1  //!< Proceed to the next key-value pair
0168                 };
0169 
0170 virtual  Action Attr(const char *key, const char *val) = 0;
0171 
0172 //------------------------------------------------------------------------------
0173 //! Constructor and Destructor.
0174 //------------------------------------------------------------------------------
0175 
0176          XrdSecEntityAttrCB() {}
0177 virtual ~XrdSecEntityAttrCB() {}
0178 };
0179 #endif