comment out dumping code
[mech_eap.orig] / util_shib.cpp
index bab284b..27b03e2 100644 (file)
@@ -103,12 +103,13 @@ gss_eap_shib_attr_provider::initFromExistingContext(const gss_eap_attr_ctx *mana
 }
 
 bool
-addRadiusAttribute(const gss_eap_attr_provider *provider,
+addRadiusAttribute(const gss_eap_attr_ctx *manager,
+                   const gss_eap_attr_provider *provider,
                    const gss_buffer_t attribute,
                    void *data)
 {
-    const gss_eap_shib_attr_provider *shib;
     const gss_eap_radius_attr_provider *radius;
+    const gss_eap_shib_attr_provider *shib;
     int authenticated, complete, more = -1;
     vector <string> attributeIds(1);
     SimpleAttribute *a;
@@ -119,7 +120,7 @@ addRadiusAttribute(const gss_eap_attr_provider *provider,
     assert(radius != NULL && shib != NULL);
 
     string attributeName =
-        gss_eap_attr_ctx::composeAttributeName(ATTR_TYPE_RADIUS, attribute);
+        manager->composeAttributeName(ATTR_TYPE_RADIUS, attribute);
 
     attributeIds.push_back(attributeName);
     a = new SimpleAttribute(attributeIds);
@@ -202,7 +203,9 @@ gss_eap_shib_attr_provider::initFromGssContext(const gss_eap_attr_ctx *manager,
         m_attributes = resolver->getResolvedAttributes();
         resolver->getResolvedAttributes().clear();
     } catch (exception &e) {
-        //fprintf(stderr, "%s", e.what());
+#if 0
+        fprintf(stderr, "%s", e.what());
+#endif
     }
 
     return true;
@@ -278,7 +281,7 @@ gss_eap_shib_attr_provider::getAttributeTypes(gss_eap_attr_enumeration_cb addAtt
         attribute.value = (void *)((*a)->getId());
         attribute.length = strlen((char *)attribute.value);
 
-        if (!addAttribute(this, &attribute, data))
+        if (!addAttribute(m_manager, this, &attribute, data))
             return false;
     }
 
@@ -381,68 +384,60 @@ gss_eap_shib_attr_provider::releaseAnyNameMapping(gss_buffer_t type_id GSSEAP_UN
     delete v;
 }
 
-void
-gss_eap_shib_attr_provider::exportToBuffer(gss_buffer_t buffer) const
+const char *
+gss_eap_shib_attr_provider::prefix(void) const
 {
-    DDF obj(NULL);
-    DDF attrs(NULL);
+    return NULL;
+}
 
-    buffer->length = 0;
-    buffer->value = NULL;
+const char *
+gss_eap_shib_attr_provider::name(void) const
+{
+    return "local";
+}
 
-    obj.addmember("version").integer(1);
-    obj.addmember("authenticated").integer(m_authenticated);
+JSONObject
+gss_eap_shib_attr_provider::jsonRepresentation(void) const
+{
+    JSONObject obj;
+
+    obj.set("authenticated", m_authenticated);
+
+    JSONObject attrs = JSONObject::array();
 
-    attrs = obj.addmember("attributes").list();
     for (vector<Attribute*>::const_iterator a = m_attributes.begin();
          a != m_attributes.end(); ++a) {
         DDF attr = (*a)->marshall();
-        attrs.add(attr);
+        JSONObject jobj(attr);
+        attrs.append(jobj);
     }
 
-    ostringstream sink;
-    sink << attrs;
-    string str = sink.str();
+    obj.set("attributes", attrs);
 
-    duplicateBuffer(str, buffer);
-
-    attrs.destroy();
+    return obj;
 }
 
 bool
-gss_eap_shib_attr_provider::initFromBuffer(const gss_eap_attr_ctx *ctx,
-                                           const gss_buffer_t buffer)
+gss_eap_shib_attr_provider::initWithJsonObject(const gss_eap_attr_ctx *ctx,
+                                               JSONObject &obj)
 {
-    if (!gss_eap_attr_provider::initFromBuffer(ctx, buffer))
+    if (!gss_eap_attr_provider::initWithJsonObject(ctx, obj))
         return false;
 
-    if (buffer->length == 0)
-        return true;
-
     assert(m_authenticated == false);
     assert(m_attributes.size() == 0);
 
-    DDF obj(NULL);
-    string str((const char *)buffer->value, buffer->length);
-    istringstream source(str);
+    m_authenticated = obj["authenticated"].integer();
 
-    source >> obj;
+    JSONObject attrs = obj["attributes"];
+    size_t nelems = attrs.size();
 
-    if (obj["version"].integer() != 1)
-        return false;
-
-    m_authenticated = (obj["authenticated"].integer() != 0);
-
-    DDF attrs = obj["attributes"];
-    DDF attr = attrs.first();
-    while (!attr.isnull()) {
+    for (size_t i = 0; i < nelems; i++) {
+        DDF attr = attrs.get(i).ddf();
         Attribute *attribute = Attribute::unmarshall(attr);
         m_attributes.push_back(attribute);
-        attr = attrs.next();
     }
 
-    attrs.destroy();
-
     return true;
 }
 
@@ -452,7 +447,7 @@ gss_eap_shib_attr_provider::init(void)
     if (!ShibbolethResolver::init())
         return false;
 
-    gss_eap_attr_ctx::registerProvider(ATTR_TYPE_LOCAL, NULL, createAttrContext);
+    gss_eap_attr_ctx::registerProvider(ATTR_TYPE_LOCAL, createAttrContext);
 
     return true;
 }