cleanup, hook in RADIUS to Shib
[cyrus-sasl.git] / mech_eap / util_attr.cpp
index 53ad003..74cf43b 100644 (file)
@@ -36,7 +36,7 @@
 #include <exception>
 #include <new>
 
-static gss_eap_attr_create_cb
+static gss_eap_attr_create_factory
 gss_eap_attr_factories[ATTR_TYPE_MAX] = {
     gss_eap_radius_attr_provider::createAttrContext,
     gss_eap_saml_assertion_provider::createAttrContext,
@@ -318,6 +318,8 @@ gss_eap_attr_ctx::unmarshall(const gss_eap_attr_ctx *ctx,
     for (i = 0; i < ATTR_TYPE_MAX; i++) {
         gss_eap_attr_provider *provider = m_providers[i];
     }
+
+    return false;
 }
 
 
@@ -366,7 +368,7 @@ gss_eap_attr_ctx::attributePrefixToType(const gss_buffer_t prefix)
     return ATTR_TYPE_LOCAL;
 }
 
-gss_buffer_t
+const gss_buffer_t
 gss_eap_attr_ctx::attributeTypeToPrefix(unsigned int type)
 {
     if (type < ATTR_TYPE_MIN || type >= ATTR_TYPE_LOCAL)
@@ -402,44 +404,52 @@ gss_eap_attr_ctx::decomposeAttributeName(const gss_buffer_t attribute,
     }
 }
 
-void
+std::string
 gss_eap_attr_ctx::composeAttributeName(const gss_buffer_t prefix,
-                                       const gss_buffer_t suffix,
-                                       gss_buffer_t attribute)
+                                       const gss_buffer_t suffix)
 {
-    size_t len = 0;
-    char *p;
-
-    attribute->length = 0;
-    attribute->value = NULL;
+    std::string str;
 
     if (prefix == GSS_C_NO_BUFFER || prefix->length == 0)
-        return;
+        return str;
+
+    str.append((const char *)prefix->value, prefix->length);
 
-    len = prefix->length;
     if (suffix != GSS_C_NO_BUFFER) {
-        len += 1 + suffix->length;
+        str.append(" ");
+        str.append((const char *)suffix->value, suffix->length);
     }
 
-    attribute->value = GSSEAP_MALLOC(len + 1);
-    if (attribute->value == NULL) {
-        throw new std::bad_alloc;
-    }
-    attribute->length = len;
+    return str;
+}
 
-    p = (char *)attribute->value;
-    memcpy(p, prefix->value, prefix->length);
-    if (suffix != NULL) {
-        p[prefix->length] = ' ';
-        memcpy(p + prefix->length + 1, suffix->value, suffix->length);
-    }
+std::string
+gss_eap_attr_ctx::composeAttributeName(unsigned int type,
+                                       const gss_buffer_t suffix)
+{
+    const gss_buffer_t prefix = attributeTypeToPrefix(type);
 
-    p[attribute->length] = '\0';
+    return composeAttributeName(prefix, suffix);
+}
+
+void
+gss_eap_attr_ctx::composeAttributeName(const gss_buffer_t prefix,
+                                       const gss_buffer_t suffix,
+                                       gss_buffer_t attribute)
+{
+    std::string str = composeAttributeName(prefix, suffix);
+
+    if (str.length() != 0) {
+        return duplicateBuffer(str, attribute);
+    } else {
+        attribute->length = 0;
+        attribute->value = NULL;
+    }
 }
 
 void
 gss_eap_attr_ctx::decomposeAttributeName(const gss_buffer_t attribute,
-                                         unsigned int*type,
+                                         unsigned int *type,
                                          gss_buffer_t suffix)
 {
     gss_buffer_desc prefix = GSS_C_EMPTY_BUFFER;
@@ -455,7 +465,7 @@ gss_eap_attr_ctx::composeAttributeName(unsigned int type,
 {
     gss_buffer_t prefix = attributeTypeToPrefix(type);
 
-    composeAttributeName(prefix, suffix, attribute);
+    return composeAttributeName(prefix, suffix, attribute);
 }
 
 OM_uint32
@@ -579,6 +589,8 @@ gssEapImportAttrContext(OM_uint32 *minor,
 {
     if (buffer->length)
         GSSEAP_NOT_IMPLEMENTED;
+
+    return GSS_S_COMPLETE;
 }
 
 OM_uint32