cleanup
[mech_eap.orig] / util_saml.cpp
index 4746c44..4d07af1 100644 (file)
@@ -114,18 +114,30 @@ private:
 
 struct eap_gss_saml_attr_ctx {
 public:
-    eap_gss_saml_attr_ctx();
-    eap_gss_saml_attr_ctx(const gss_buffer_t buffer);
-    eap_gss_saml_attr_ctx(const Assertion *assertion);
+    eap_gss_saml_attr_ctx(const gss_buffer_t buffer) {
+        parseAssertion(buffer);
+    }
 
     eap_gss_saml_attr_ctx(const vector<Attribute*>& attributes,
-                          const Assertion *assertion);
+                          const Assertion *assertion = NULL) {
+        if (assertion != NULL)
+            m_assertion = dynamic_cast<Assertion *>(assertion->clone());
+        if (attributes.size())
+            setAttributes(attributes);
+    }
 
     eap_gss_saml_attr_ctx(const eap_gss_saml_attr_ctx &ctx) {
         eap_gss_saml_attr_ctx(ctx.m_attributes, ctx.m_assertion);
     }
 
-    ~eap_gss_saml_attr_ctx();
+    eap_gss_saml_attr_ctx() {}
+    ~eap_gss_saml_attr_ctx() {
+        for_each(m_attributes.begin(),
+                 m_attributes.end(),
+                 xmltooling::cleanup<Attribute>())
+            ;
+        delete m_assertion;
+    }
 
     const vector <Attribute *> getAttributes(void) const {
         return m_attributes;
@@ -168,24 +180,6 @@ private:
     bool parseAssertion(const gss_buffer_t buffer);
 };
 
-eap_gss_saml_attr_ctx::eap_gss_saml_attr_ctx(const vector<Attribute*>& attributes,
-                                             const Assertion *assertion)
-{
-    m_assertion = dynamic_cast<Assertion *>(assertion->clone());
-    setAttributes(attributes);
-}
-
-eap_gss_saml_attr_ctx::~eap_gss_saml_attr_ctx()
-{
-    for_each(m_attributes.begin(), m_attributes.end(), xmltooling::cleanup<Attribute>());
-    delete m_assertion;
-}
-
-eap_gss_saml_attr_ctx::eap_gss_saml_attr_ctx(const gss_buffer_t buffer)
-{
-    parseAssertion(buffer);
-}
-
 static OM_uint32
 mapException(OM_uint32 *minor, exception &e)
 {
@@ -495,14 +489,13 @@ OM_uint32
 samlReleaseAttrContext(OM_uint32 *minor,
                        struct eap_gss_saml_attr_ctx **pCtx)
 {
-    eap_gss_saml_attr_ctx *ctx = *pCtx;
-
-    if (ctx != NULL) {
-        delete ctx;
+    try {
+        delete *pCtx;
         *pCtx = NULL;
+    } catch (exception &e) {
+        return mapException(minor, e);
     }
 
-    *minor = 0;
     return GSS_S_COMPLETE;
 }
 
@@ -510,7 +503,8 @@ OM_uint32
 samlCreateAttrContext(OM_uint32 *minor,
                       gss_buffer_t buffer,
                       gss_name_t acceptorName,
-                      struct eap_gss_saml_attr_ctx **pCtx)
+                      struct eap_gss_saml_attr_ctx **pCtx,
+                      time_t *pExpiryTime)
 {
     OM_uint32 major, tmpMinor;
     eap_gss_saml_attr_ctx *ctx = NULL;
@@ -557,6 +551,8 @@ samlCreateAttrContext(OM_uint32 *minor,
             issuer = assertion->getIssuer()->getName();
         if (assertion->getSubject() != NULL)
             subjectName = assertion->getSubject()->getNameID();
+        if (assertion->getConditions())
+            *pExpiryTime = assertion->getConditions()->getNotOnOrAfter()->getEpoch();
 
         m = app->getMetadataProvider();
         xmltooling::Locker mlocker(m);
@@ -742,7 +738,7 @@ samlDuplicateAttrContext(OM_uint32 *minor,
 }
 
 OM_uint32
-samlMapNametoAny(OM_uint32 *minor,
+samlMapNameToAny(OM_uint32 *minor,
                  const struct eap_gss_saml_attr_ctx *ctx,
                  int authenticated,
                  gss_buffer_t type_id,