如何在 Rampart/C (Axis2/C) 中反序列化 SAML 断言?

发布于 2024-07-07 13:38:06 字数 1460 浏览 5 评论 0原文

我在 utf-8 char * 缓冲区中有 SAML 1.1 和 SAML 1.0 响应,我想将它们转换为 Rampart/C saml_response_t * 对象。 我的问题是:

从字符串创建 saml_response_t 的正确方法是什么?

理想情况下,我想要一个 C 代码示例来执行此操作,然后以正确的顺序处理各种解析器工具,因为 Axis2/C 对于如何释放内存有一些奇怪的想法。

我这样做的努力失败了,主要导致内存错误,但这就是我所拥有的。 请记住,deserialize_buffer() 方法正如它所说的那样——将缓冲区转换为 axiom_node_t *,但我也愿意替换它。

/* : 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);
    }
}

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);
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文