views:

405

answers:

0

I have SAML 1.1 and SAML 1.0 responses in utf-8 char * buffers, and I would like to transform them into Rampart/C saml_response_t * objects. My question is this:

What is the correct method for creating a saml_response_t from a string?

Ideally I'd like a code sample in C that does this and then disposes of the various parser tools in the correct order, since Axis2/C has some odd ideas about how to free memory.

My efforts to do this have met with failure, resulting mainly in memory faults, but here's what I have. Keep in mind that the deserialize_buffer method does just what it says -- converts a buffer into an axiom_node_t *, but I'm open to replacing it as well.

/* : get the raw XML from the SAML assertion */
    xml_data = Tcl_GetStringFromObj (objv[2], &xml_length);

/* : parse the response XML for processing */
    stream = gstream_mem_create (xml_data, xml_length);
    node = Axis2_axiom_deserialize_buffer (env, stream);

/* : build a SAML response from the parsed XML */
    saml_response = saml_response_create (env);
    saml_response_build (saml_response, node, env);
    arraylist = saml_response_get_assertions (saml_response, env);

/* : create our return value object */
    obj = Tcl_NewListObj (0, NULL);

/* :- convert the SAML assertion into a string */
    for (i = 0;
         i < axutil_array_list_size (arraylist, env);
         i++) {
        saml_assertion = (saml_assertion_t *) axutil_array_list_get (arraylist, env, i);
        if (saml_assertion != NULL) {
            assertion_node = saml_assertion_to_om (saml_assertion, NULL, env);

            element = Tcl_NewStringObj (axiom_node_to_string (node, env), -1);
            Tcl_ListObjAppendElement (interp, obj, element);

            axiom_node_free_tree (assertion_node, env);
        }
    }