diff options
author | gmcdonald | 2010-02-13 01:32:03 +0000 |
---|---|---|
committer | gmcdonald | 2010-02-13 01:32:03 +0000 |
commit | 0425aadc78680e53000fd0108b540d6eca048516 (patch) | |
tree | 8ec7ab8e015d454c5ec586dfc91e05a2dce1cfc0 /axiom/src/soap | |
download | axis2c-0425aadc78680e53000fd0108b540d6eca048516.tar.gz axis2c-0425aadc78680e53000fd0108b540d6eca048516.tar.bz2 |
Moving axis svn, part of TLP move INFRA-2441
git-svn-id: http://svn.apache.org/repos/asf/axis/axis2/c/core/trunk@909681 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'axiom/src/soap')
32 files changed, 8384 insertions, 0 deletions
diff --git a/axiom/src/soap/Makefile.am b/axiom/src/soap/Makefile.am new file mode 100644 index 0000000..5b53ba8 --- /dev/null +++ b/axiom/src/soap/Makefile.am @@ -0,0 +1,33 @@ +noinst_LTLIBRARIES = libaxis2_soap.la +libaxis2_soap_la_SOURCES = soap_fault.c \ + soap_fault_code.c \ + soap_fault_detail.c \ + soap_fault_node.c \ + soap_fault_reason.c \ + soap_fault_role.c \ + soap_fault_sub_code.c \ + soap_fault_text.c \ + soap_fault_value.c \ + soap_header_block.c \ + soap_header.c \ + soap_body.c \ + soap_envelope.c \ + soap_builder.c \ + soap11_builder_helper.c \ + soap12_builder_helper.c + +libaxis2_soap_la_LIBADD = +INCLUDES = -I$(top_builddir)/include \ + -I$(top_builddir)/src/parser \ + -I$(top_builddir)/src/om \ + -I ../../../util/include + +EXTRA_DIST = axiom_soap11_builder_helper.h \ + _axiom_soap_fault_code.h _axiom_soap_fault_reason.h \ + _axiom_soap_fault_value.h axiom_soap12_builder_helper.h \ + _axiom_soap_fault_detail.h _axiom_soap_fault_role.h \ + _axiom_soap_header_block.h _axiom_soap_body.h \ + _axiom_soap_fault.h _axiom_soap_fault_sub_code.h \ + _axiom_soap_header.h _axiom_soap_envelope.h \ + _axiom_soap_fault_node.h _axiom_soap_fault_text.h + diff --git a/axiom/src/soap/_axiom_soap_body.h b/axiom/src/soap/_axiom_soap_body.h new file mode 100644 index 0000000..bb25b84 --- /dev/null +++ b/axiom/src/soap/_axiom_soap_body.h @@ -0,0 +1,69 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _AXIOM_SOAP_BODY_H +#define _AXIOM_SOAP_BODY_H + +/** @defgroup axiom_soap AXIOM (Axis Object Model) + * @ingroup axis2 + * @{ + */ + +/** @} */ + +#include <axiom_soap_body.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * @defgroup axiom_soap_body Soap Body + * @ingroup axiom_soap + * @{ + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axiom_soap_body_set_base_node( + axiom_soap_body_t * body, + const axutil_env_t * env, + axiom_node_t * om_node); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axiom_soap_body_set_builder( + axiom_soap_body_t * body, + const axutil_env_t * env, + struct axiom_soap_builder *builder); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axiom_soap_body_set_fault( + axiom_soap_body_t * body, + const axutil_env_t * env, + struct axiom_soap_fault *soap_fault); + + AXIS2_EXTERN axiom_soap_body_t *AXIS2_CALL + axiom_soap_body_create( + const axutil_env_t * env); + + /** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /** _AXIOM_SOAP_BODY_H */ diff --git a/axiom/src/soap/_axiom_soap_envelope.h b/axiom/src/soap/_axiom_soap_envelope.h new file mode 100644 index 0000000..1c446cc --- /dev/null +++ b/axiom/src/soap/_axiom_soap_envelope.h @@ -0,0 +1,84 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _AXIOM_SOAP_ENVELOPE_H +#define _AXIOM_SOAP_ENVELOPE_H + +/** @defgroup axiom_soap AXIOM (Axis Object Model) + * @ingroup axis2 + * @{ + */ + +/** @} */ + +#include <axiom_soap_envelope.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * @defgroup axiom_soap_envelope Soap Envelope + * @ingroup axiom_soap + * @{ + */ + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axiom_soap_envelope_set_base_node( + axiom_soap_envelope_t * envelope, + const axutil_env_t * env, + axiom_node_t * om_node); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axiom_soap_envelope_set_body( + axiom_soap_envelope_t * envelope, + const axutil_env_t * env, + struct axiom_soap_body *body); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axiom_soap_envelope_set_header( + axiom_soap_envelope_t * envelope, + const axutil_env_t * env, + struct axiom_soap_header *header); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axiom_soap_envelope_set_builder( + axiom_soap_envelope_t * envelope, + const axutil_env_t * env, + struct axiom_soap_builder *soap_builder); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + + axiom_soap_envelope_set_soap_version_internal( + axiom_soap_envelope_t * envelope, + const axutil_env_t * env, + int soap_version); + + AXIS2_EXTERN axiom_soap_envelope_t *AXIS2_CALL + + axiom_soap_envelope_create_null( + const axutil_env_t * env); + + /** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /** _AXIOM_SOAP_ENVELOPE_H */ diff --git a/axiom/src/soap/_axiom_soap_fault.h b/axiom/src/soap/_axiom_soap_fault.h new file mode 100644 index 0000000..2f0c410 --- /dev/null +++ b/axiom/src/soap/_axiom_soap_fault.h @@ -0,0 +1,105 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _AXIOM_SOAP_FAULT_H +#define _AXIOM_SOAP_FAULT_H + +/** @defgroup axiom_soap AXIOM (Axis Object Model) + * @ingroup axis2 + * @{ + */ + +/** @} */ + +#include <axiom_soap_fault.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * @defgroup axiom_soap_fault Soap fault + * @ingroup axiom_soap + * @{ + */ + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axiom_soap_fault_set_code( + axiom_soap_fault_t * fault, + const axutil_env_t * env, + struct axiom_soap_fault_code *code); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axiom_soap_fault_set_reason( + axiom_soap_fault_t * fault, + const axutil_env_t * env, + struct axiom_soap_fault_reason *reason); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axiom_soap_fault_set_node( + axiom_soap_fault_t * fault, + const axutil_env_t * env, + struct axiom_soap_fault_node *node); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axiom_soap_fault_set_role( + axiom_soap_fault_t * fault, + const axutil_env_t * env, + struct axiom_soap_fault_role *role); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axiom_soap_fault_set_detail( + axiom_soap_fault_t * fault, + const axutil_env_t * env, + struct axiom_soap_fault_detail *detail); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axiom_soap_fault_set_base_node( + axiom_soap_fault_t * fault, + const axutil_env_t * env, + axiom_node_t * node); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axiom_soap_fault_set_builder( + axiom_soap_fault_t * fault, + const axutil_env_t * env, + struct axiom_soap_builder *builder); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axiom_soap_fault_set_soap_version( + axiom_soap_fault_t * fault, + const axutil_env_t * env, + int soap_version); + + AXIS2_EXTERN int AXIS2_CALL + axiom_soap_fault_get_soap_version( + axiom_soap_fault_t * fault, + const axutil_env_t * env); + + AXIS2_EXTERN axiom_soap_fault_t *AXIS2_CALL + axiom_soap_fault_create( + const axutil_env_t * env); + + /** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /** _AXIOM_SOAP_FAULT_H */ diff --git a/axiom/src/soap/_axiom_soap_fault_code.h b/axiom/src/soap/_axiom_soap_fault_code.h new file mode 100644 index 0000000..3905a18 --- /dev/null +++ b/axiom/src/soap/_axiom_soap_fault_code.h @@ -0,0 +1,91 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _AXIOM_SOAP_FAULT_CODE_H +#define _AXIOM_SOAP_FAULT_CODE_H + +/** @defgroup axiom_soap AXIOM (Axis Object Model) + * @ingroup axis2 + * @{ + */ + +/** @} */ + +#include <axiom_soap_fault_code.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * @defgroup axiom_soap_fault_code Soap fault code + * @ingroup axiom_soap + * @{ + */ + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axiom_soap_fault_code_set_value( + axiom_soap_fault_code_t * fault_code, + const axutil_env_t * env, + struct axiom_soap_fault_value *fault_val); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + + axiom_soap_fault_code_set_sub_code( + axiom_soap_fault_code_t * fault_code, + const axutil_env_t * env, + struct axiom_soap_fault_sub_code *fault_subcode); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + + axiom_soap_fault_code_set_base_node( + axiom_soap_fault_code_t * fault_code, + const axutil_env_t * env, + axiom_node_t * node); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axiom_soap_fault_code_set_builder( + axiom_soap_fault_code_t * fault_code, + const axutil_env_t * env, + struct axiom_soap_builder *soap_builder); + + AXIS2_EXTERN int AXIS2_CALL + axiom_soap_fault_code_get_soap_version( + axiom_soap_fault_code_t * fault_code, + const axutil_env_t * env); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + + axiom_soap_fault_code_set_soap_version( + axiom_soap_fault_code_t * fault_code, + const axutil_env_t * env, + int soap_version); + + AXIS2_EXTERN axiom_soap_fault_code_t *AXIS2_CALL + + axiom_soap_fault_code_create( + const axutil_env_t * env); + + /** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /** _AXIOM_SOAP_FAULT_CODE_H */ diff --git a/axiom/src/soap/_axiom_soap_fault_detail.h b/axiom/src/soap/_axiom_soap_fault_detail.h new file mode 100644 index 0000000..69369ca --- /dev/null +++ b/axiom/src/soap/_axiom_soap_fault_detail.h @@ -0,0 +1,60 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _AXIOM_SOAP_FAULT_DETAIL_H +#define _AXIOM_SOAP_FAULT_DETAIL_H + +/** @defgroup axiom_soap AXIOM (Axis Object Model) + * @ingroup axis2 + * @{ + */ + +/** @} */ + +#include <axiom_soap_fault_detail.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * @defgroup axiom_soap_fault_detail soap fault detail + * @ingroup axiom_soap + * @{ + */ + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + + axiom_soap_fault_detail_set_base_node( + axiom_soap_fault_detail_t * fault_detail, + const axutil_env_t * env, + axiom_node_t * node); + + AXIS2_EXTERN axiom_soap_fault_detail_t *AXIS2_CALL + + axiom_soap_fault_detail_create( + const axutil_env_t * env); + + /** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /** _AXIOM_SOAP_FAULT_DETAIL_H */ diff --git a/axiom/src/soap/_axiom_soap_fault_node.h b/axiom/src/soap/_axiom_soap_fault_node.h new file mode 100644 index 0000000..94ddad7 --- /dev/null +++ b/axiom/src/soap/_axiom_soap_fault_node.h @@ -0,0 +1,60 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _AXIOM_SOAP_FAULT_NODE_H +#define _AXIOM_SOAP_FAULT_NODE_H + +/** @defgroup axiom_soap AXIOM (Axis Object Model) + * @ingroup axis2 + * @{ + */ + +/** @} */ + +#include <axiom_soap_fault_node.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * @defgroup axiom_soap_fault_node Soap fault_node + * @ingroup axiom_soap + * @{ + */ + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + + axiom_soap_fault_node_set_base_node( + axiom_soap_fault_node_t * fault_node, + const axutil_env_t * env, + axiom_node_t * node); + + AXIS2_EXTERN axiom_soap_fault_node_t *AXIS2_CALL + + axiom_soap_fault_node_create( + const axutil_env_t * env); + + /** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /** _AXIOM_SOAP_FAULT_NODE_H */ diff --git a/axiom/src/soap/_axiom_soap_fault_reason.h b/axiom/src/soap/_axiom_soap_fault_reason.h new file mode 100644 index 0000000..2307a31 --- /dev/null +++ b/axiom/src/soap/_axiom_soap_fault_reason.h @@ -0,0 +1,87 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _AXIOM_SOAP_FAULT_REASON_H +#define _AXIOM_SOAP_FAULT_REASON_H + +/** @defgroup axiom_soap AXIOM (Axis Object Model) + * @ingroup axis2 + * @{ + */ + +/** @} */ + +#include <axiom_soap_fault_reason.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * @defgroup axiom_soap_fault_reason Soap Reason + * @ingroup axiom_soap + * @{ + */ + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + + axiom_soap_fault_reason_set_builder( + axiom_soap_fault_reason_t * fault_reason, + const axutil_env_t * env, + struct axiom_soap_builder *builder); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + + axiom_soap_fault_reason_set_base_node( + axiom_soap_fault_reason_t * fault_reason, + const axutil_env_t * env, + axiom_node_t * node); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + + axiom_soap_fault_reason_set_soap_fault_text( + axiom_soap_fault_reason_t * fault_reason, + const axutil_env_t * env, + struct axiom_soap_fault_text *soap_text); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + + axiom_soap_fault_reason_set_soap_version( + axiom_soap_fault_reason_t * fault_reason, + const axutil_env_t * env, + int soap_version); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + + axiom_soap_fault_reason_get_soap_version( + axiom_soap_fault_reason_t * fault_reason, + const axutil_env_t * env); + + AXIS2_EXTERN axiom_soap_fault_reason_t *AXIS2_CALL + + axiom_soap_fault_reason_create( + const axutil_env_t * env); + + /** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /** _AXIOM_SOAP_FAULT_REASON_H */ diff --git a/axiom/src/soap/_axiom_soap_fault_role.h b/axiom/src/soap/_axiom_soap_fault_role.h new file mode 100644 index 0000000..9c4ec4b --- /dev/null +++ b/axiom/src/soap/_axiom_soap_fault_role.h @@ -0,0 +1,60 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _AXIOM_SOAP_FAULT_ROLE_H +#define _AXIOM_SOAP_FAULT_ROLE_H + +/** @defgroup axiom_soap AXIOM (Axis Object Model) + * @ingroup axis2 + * @{ + */ + +/** @} */ + +#include <axiom_soap_fault_role.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * @defgroup axiom_soap_fault_role Soap_fault_role + * @ingroup axiom_soap + * @{ + */ + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + + axiom_soap_fault_role_set_base_node( + axiom_soap_fault_role_t * fault_role, + const axutil_env_t * env, + axiom_node_t * node); + + AXIS2_EXTERN axiom_soap_fault_role_t *AXIS2_CALL + + axiom_soap_fault_role_create( + const axutil_env_t * env); + + /** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /** _AXIOM_SOAP_FAULT_ROLE_H */ diff --git a/axiom/src/soap/_axiom_soap_fault_sub_code.h b/axiom/src/soap/_axiom_soap_fault_sub_code.h new file mode 100644 index 0000000..878d4e6 --- /dev/null +++ b/axiom/src/soap/_axiom_soap_fault_sub_code.h @@ -0,0 +1,93 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _AXIOM_SOAP_FAULT_CODE_SUB_CODE_H +#define _AXIOM_SOAP_FAULT_CODE_SUB_CODE_H + +/** @defgroup axiom_soap AXIOM (Axis Object Model) + * @ingroup axis2 + * @{ + */ + +/** @} */ + +#include <axiom_soap_fault_sub_code.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * @defgroup axiom_soap_fault_sub_code Soap_fault_code + * @ingroup axiom_soap + * @{ + */ + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + + axiom_soap_fault_sub_code_set_sub_code( + axiom_soap_fault_sub_code_t * fault_sub_code, + const axutil_env_t * env, + axiom_soap_fault_sub_code_t * sub_code); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + + axiom_soap_fault_sub_code_set_value( + axiom_soap_fault_sub_code_t * fault_sub_code, + const axutil_env_t * env, + struct axiom_soap_fault_value *fault_sub_code_val); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + + axiom_soap_fault_sub_code_set_base_node( + axiom_soap_fault_sub_code_t * fault_sub_code, + const axutil_env_t * env, + axiom_node_t * node); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + + axiom_soap_fault_sub_code_set_builder( + axiom_soap_fault_sub_code_t * fault_sub_code, + const axutil_env_t * env, + struct axiom_soap_builder *builder); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + + axiom_soap_fault_sub_code_set_soap_version( + axiom_soap_fault_sub_code_t * fault_sub_code, + const axutil_env_t * env, + int soap_version); + + AXIS2_EXTERN int AXIS2_CALL + axiom_soap_fault_sub_code_get_soap_version( + axiom_soap_fault_sub_code_t * fault_sub_code, + const axutil_env_t * env); + + AXIS2_EXTERN axiom_soap_fault_sub_code_t *AXIS2_CALL + + axiom_soap_fault_sub_code_create( + const axutil_env_t * env); + + /** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /** _AXIOM_SOAP_FAULT_CODE_SUB_CODE_H */ diff --git a/axiom/src/soap/_axiom_soap_fault_text.h b/axiom/src/soap/_axiom_soap_fault_text.h new file mode 100644 index 0000000..dfc8772 --- /dev/null +++ b/axiom/src/soap/_axiom_soap_fault_text.h @@ -0,0 +1,60 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _AXIOM_SOAP_FAULT_TEXT_H +#define _AXIOM_SOAP_FAULT_TEXT_H + +/** @defgroup axiom_soap AXIOM (Axis Object Model) + * @ingroup axis2 + * @{ + */ + +/** @} */ + +#include <axiom_soap_fault_text.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * @defgroup axiom_soap_fault_text soap fault text + * @ingroup axiom_soap + * @{ + */ + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + + axiom_soap_fault_text_set_base_node( + axiom_soap_fault_text_t * fault_text, + const axutil_env_t * env, + axiom_node_t * node); + + AXIS2_EXTERN axiom_soap_fault_text_t *AXIS2_CALL + + axiom_soap_fault_text_create( + const axutil_env_t * env); + + /** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /** _AXIOM_SOAP_FAULT_TEXT_H */ diff --git a/axiom/src/soap/_axiom_soap_fault_value.h b/axiom/src/soap/_axiom_soap_fault_value.h new file mode 100644 index 0000000..a524f7f --- /dev/null +++ b/axiom/src/soap/_axiom_soap_fault_value.h @@ -0,0 +1,60 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _AXIOM_SOAP_FAULT_VALUE_H +#define _AXIOM_SOAP_FAULT_VALUE_H + +/** @defgroup axiom_soap AXIOM (Axis Object Model) + * @ingroup axis2 + * @{ + */ + +/** @} */ + +#include <axiom_soap_fault_value.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * @defgroup axiom_soap_fault_value Soap Fault Value + * @ingroup axiom_soap + * @{ + */ + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + + axiom_soap_fault_value_set_base_node( + axiom_soap_fault_value_t * fault_value, + const axutil_env_t * env, + axiom_node_t * node); + + AXIS2_EXTERN axiom_soap_fault_value_t *AXIS2_CALL + + axiom_soap_fault_value_create( + const axutil_env_t * env); + + /** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /** _AXIOM_SOAP_FAULT_VALUE_H */ diff --git a/axiom/src/soap/_axiom_soap_header.h b/axiom/src/soap/_axiom_soap_header.h new file mode 100644 index 0000000..7571aa6 --- /dev/null +++ b/axiom/src/soap/_axiom_soap_header.h @@ -0,0 +1,77 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _AXIOM_SOAP_HEADER_H +#define _AXIOM_SOAP_HEADER_H + +/** @defgroup axiom_soap AXIOM (Axis Object Model) + * @ingroup axis2 + * @{ + */ + +/** @} */ + +#include <axiom_soap_header.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * @defgroup axiom_soap_header Soap header + * @ingroup axiom_soap + * @{ + */ + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axiom_soap_header_set_base_node( + axiom_soap_header_t * header, + const axutil_env_t * env, + axiom_node_t * node); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + + axiom_soap_header_set_soap_version( + axiom_soap_header_t * header, + const axutil_env_t * env, + int soap_version); + AXIS2_EXTERN axis2_status_t AXIS2_CALL + + axiom_soap_header_set_header_block( + axiom_soap_header_t * header, + const axutil_env_t * env, + struct axiom_soap_header_block *header_block); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axiom_soap_header_set_builder( + axiom_soap_header_t * header, + const axutil_env_t * env, + struct axiom_soap_builder *builder); + + AXIS2_EXTERN axiom_soap_header_t *AXIS2_CALL + axiom_soap_header_create( + const axutil_env_t * env); + + /** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /** _AXIOM_SOAP_HEADER_H */ diff --git a/axiom/src/soap/_axiom_soap_header_block.h b/axiom/src/soap/_axiom_soap_header_block.h new file mode 100644 index 0000000..65cb3ab --- /dev/null +++ b/axiom/src/soap/_axiom_soap_header_block.h @@ -0,0 +1,66 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _AXIOM_SOAP_HEADER_BLOCK_H +#define _AXIOM_SOAP_HEADER_BLOCK_H + +/** @defgroup axiom_soap AXIOM (Axis Object Model) + * @ingroup axis2 + * @{ + */ + +/** @} */ + +#include <axiom_soap_header_block.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * @defgroup axiom_soap_header_block Soap header block + * @ingroup axiom_soap + * @{ + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + + axiom_soap_header_block_set_soap_version( + axiom_soap_header_block_t * header_block, + const axutil_env_t * env, + int soap_version); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + + axiom_soap_header_block_set_base_node( + axiom_soap_header_block_t * header_block, + const axutil_env_t * env, + axiom_node_t * node); + + AXIS2_EXTERN axiom_soap_header_block_t *AXIS2_CALL + + axiom_soap_header_block_create( + const axutil_env_t * env); + + /** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /** _AXIOM_SOAP_HEADER_BLOCK_H */ diff --git a/axiom/src/soap/axiom_soap11_builder_helper.h b/axiom/src/soap/axiom_soap11_builder_helper.h new file mode 100644 index 0000000..13e914a --- /dev/null +++ b/axiom/src/soap/axiom_soap11_builder_helper.h @@ -0,0 +1,71 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef AXIOM_SOAP11_BUILDER_HELPER_H +#define AXIOM_SOAP11_BUILDER_HELPER_H + +/** + * @file axiom_soap_11_builder_helper.h + * @brief axiom_soap11_builder_helper + */ +#include <axiom_soap_builder.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct axiom_soap11_builder_helper + axiom_soap11_builder_helper_t; + + /** + * @defgroup axiom_soap11_builder_helper + * @ingroup axiom_soap + * @{ + */ + + /** + * creates a soap11_builder_helper_create + * @param env Environment. MUST NOT be NULL + */ + AXIS2_EXTERN axiom_soap11_builder_helper_t *AXIS2_CALL + + axiom_soap11_builder_helper_create( + const axutil_env_t * env, + axiom_soap_builder_t * soap_builder, + axiom_stax_builder_t * om_builder); + + AXIS2_EXTERN void AXIS2_CALL + axiom_soap11_builder_helper_free( + axiom_soap11_builder_helper_t * builder_helper, + const axutil_env_t * env); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + + axiom_soap11_builder_helper_handle_event( + axiom_soap11_builder_helper_t * builder_helper, + const axutil_env_t * env, + axiom_node_t * om_element_node, + int element_level); + + /** @} */ +#ifdef __cplusplus +} +#endif + +#endif /* AXIOM_SOAP11_BUILDER_HELPER_H */ diff --git a/axiom/src/soap/axiom_soap12_builder_helper.h b/axiom/src/soap/axiom_soap12_builder_helper.h new file mode 100644 index 0000000..e901627 --- /dev/null +++ b/axiom/src/soap/axiom_soap12_builder_helper.h @@ -0,0 +1,71 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef AXIOM_SOAP12_BUILDER_HELPER_H +#define AXIOM_SOAP12_BUILDER_HELPER_H + +#include <axiom_soap_builder.h> + +/** + * @file axiom_soap_12_builder_helper.h + * @brief axiom_soap12_builder_helper + */ + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct axiom_soap12_builder_helper + axiom_soap12_builder_helper_t; + + /** + * @defgroup axiom_soap12_builder_helper + * @ingroup axiom_soap + * @{ + */ + + /** + * creates a soap12_builder_helper_create + * @param env Environment. MUST NOT be NULL + */ + AXIS2_EXTERN axiom_soap12_builder_helper_t *AXIS2_CALL + + axiom_soap12_builder_helper_create( + const axutil_env_t * env, + axiom_soap_builder_t * soap_builder); + + AXIS2_EXTERN void AXIS2_CALL + axiom_soap12_builder_helper_free( + axiom_soap12_builder_helper_t * builder_helper, + const axutil_env_t * env); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + + axiom_soap12_builder_helper_handle_event( + axiom_soap12_builder_helper_t * builder_helper, + const axutil_env_t * env, + axiom_node_t * om_element_node, + int element_level); + + /** @} */ +#ifdef __cplusplus +} +#endif + +#endif /*AXIOM_SOAP11_BUILDER_HELPER_H */ diff --git a/axiom/src/soap/soap11_builder_helper.c b/axiom/src/soap/soap11_builder_helper.c new file mode 100644 index 0000000..ab2e4d8 --- /dev/null +++ b/axiom/src/soap/soap11_builder_helper.c @@ -0,0 +1,340 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "axiom_soap11_builder_helper.h" +#include <axiom_stax_builder.h> +#include <axiom_soap_builder.h> +#include <axiom_soap_const.h> +#include "_axiom_soap_fault_code.h" +#include "_axiom_soap_fault_value.h" +#include "_axiom_soap_fault_reason.h" +#include "_axiom_soap_fault.h" +#include "_axiom_soap_body.h" +#include "_axiom_soap_fault_detail.h" +#include <axiom_soap_fault_text.h> +#include "_axiom_soap_fault_role.h" +#include <axiom_stax_builder_internal.h> +#include <axiom_node_internal.h> + +static axis2_status_t +axiom_soap11_builder_helper_process_text( + axiom_soap11_builder_helper_t * builder_helper, + const axutil_env_t * env); + +struct axiom_soap11_builder_helper +{ + axiom_soap_builder_t *soap_builder; + + axis2_bool_t fault_code_present; + + axis2_bool_t fault_string_present; + + axiom_stax_builder_t *om_builder; + + axiom_node_t *last_processed_node; + +}; + +AXIS2_EXTERN axiom_soap11_builder_helper_t *AXIS2_CALL +axiom_soap11_builder_helper_create( + const axutil_env_t * env, + axiom_soap_builder_t * soap_builder, + axiom_stax_builder_t * om_builder) +{ + axiom_soap11_builder_helper_t *builder_helper = NULL; + + AXIS2_PARAM_CHECK(env->error, soap_builder, NULL); + AXIS2_PARAM_CHECK(env->error, om_builder, NULL); + + builder_helper = (axiom_soap11_builder_helper_t *)AXIS2_MALLOC(env->allocator, + sizeof(axiom_soap11_builder_helper_t)); + + if(!builder_helper) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory. Cannot create SOAP 1.1 builder helper"); + return NULL; + } + + builder_helper->fault_code_present = AXIS2_FALSE; + builder_helper->fault_string_present = AXIS2_FALSE; + builder_helper->last_processed_node = NULL; + builder_helper->soap_builder = soap_builder; + builder_helper->om_builder = om_builder; + + return builder_helper; +} + +AXIS2_EXTERN void AXIS2_CALL +axiom_soap11_builder_helper_free( + axiom_soap11_builder_helper_t * builder_helper, + const axutil_env_t * env) +{ + + AXIS2_FREE(env->allocator, builder_helper); + builder_helper = NULL; + return; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap11_builder_helper_handle_event( + axiom_soap11_builder_helper_t * builder_helper, + const axutil_env_t * env, + axiom_node_t * om_element_node, + int element_level) +{ + axiom_element_t *om_ele = NULL; + axis2_char_t *ele_localname = NULL; + axiom_soap_envelope_t *soap_envelope = NULL; + axiom_soap_body_t *soap_body = NULL; + axiom_soap_fault_t *soap_fault = NULL; + + AXIS2_PARAM_CHECK(env->error, om_element_node, AXIS2_FAILURE); + + om_ele = (axiom_element_t *)axiom_node_get_data_element(om_element_node, env); + + ele_localname = axiom_element_get_localname(om_ele, env); + if(!ele_localname) + { + return AXIS2_FAILURE; + } + + soap_envelope = axiom_soap_builder_get_soap_envelope(builder_helper->soap_builder, env); + + if(!soap_envelope) + { + return AXIS2_FAILURE; + } + + soap_body = axiom_soap_envelope_get_body(soap_envelope, env); + if(!soap_body) + { + return AXIS2_FAILURE; + } + + soap_fault = axiom_soap_body_get_fault(soap_body, env); + if(!soap_fault) + { + return AXIS2_FAILURE; + } + + if(element_level == 4) + { + axiom_soap_fault_code_t *fault_code = NULL; + axiom_soap_fault_value_t *fault_value = NULL; + axiom_node_t *fault_value_node = NULL; + axiom_element_t *fault_value_ele = NULL; + + if(axutil_strcmp(ele_localname, AXIOM_SOAP11_SOAP_FAULT_CODE_LOCAL_NAME) == 0) + { + axis2_status_t status = AXIS2_SUCCESS; + + if(builder_helper->fault_string_present) + { + axiom_soap_builder_set_bool_processing_mandatory_fault_elements( + builder_helper->soap_builder, env, AXIS2_FALSE); + } + + fault_code = axiom_soap_fault_code_create(env); + if(!fault_code) + { + return AXIS2_FAILURE; + } + axiom_soap_fault_code_set_base_node(fault_code, env, om_element_node); + + axiom_soap_fault_set_code(soap_fault, env, fault_code); + + axiom_soap_fault_code_set_builder(fault_code, env, builder_helper->soap_builder); + + axiom_element_set_localname(om_ele, env, AXIOM_SOAP12_SOAP_FAULT_CODE_LOCAL_NAME); + + fault_value = axiom_soap_fault_value_create_with_code(env, fault_code); + if(!fault_value) + { + return AXIS2_FAILURE; + } + fault_value_node = axiom_soap_fault_value_get_base_node(fault_value, env); + if(!fault_value_node) + { + return AXIS2_FAILURE; + } + fault_value_ele = (axiom_element_t *)axiom_node_get_data_element(fault_value_node, env); + + axiom_stax_builder_set_lastnode(builder_helper->om_builder, env, fault_value_node); + + status = axiom_soap11_builder_helper_process_text(builder_helper, env); + if(status == AXIS2_FAILURE) + { + return AXIS2_FAILURE; + } + axiom_stax_builder_set_lastnode(builder_helper->om_builder, env, om_element_node); + axiom_node_set_complete(om_element_node, env, AXIS2_TRUE); + + axiom_stax_builder_set_element_level(builder_helper->om_builder, env, (element_level + - 1)); + builder_helper->fault_code_present = AXIS2_TRUE; + } + else if(axutil_strcmp(AXIOM_SOAP11_SOAP_FAULT_STRING_LOCAL_NAME, ele_localname) == 0) + { + + axiom_soap_fault_reason_t *fault_reason = NULL; + axiom_soap_fault_text_t *fault_text = NULL; + axiom_node_t *fault_text_node = NULL; + int status = AXIS2_SUCCESS; + if(builder_helper->fault_code_present) + { + axiom_soap_builder_set_bool_processing_mandatory_fault_elements( + builder_helper->soap_builder, env, AXIS2_FALSE); + } + + axiom_element_set_localname(om_ele, env, AXIOM_SOAP12_SOAP_FAULT_REASON_LOCAL_NAME); + + fault_reason = axiom_soap_fault_reason_create(env); + if(!fault_reason) + { + return AXIS2_FAILURE; + } + axiom_soap_fault_reason_set_base_node(fault_reason, env, om_element_node); + + axiom_soap_fault_set_reason(soap_fault, env, fault_reason); + + fault_text = axiom_soap_fault_text_create_with_parent(env, fault_reason); + if(!fault_text) + { + return AXIS2_FAILURE; + } + fault_text_node = axiom_soap_fault_text_get_base_node(fault_text, env); + if(!fault_text_node) + { + return AXIS2_FAILURE; + } + axiom_stax_builder_set_lastnode(builder_helper->om_builder, env, fault_text_node); + + status = axiom_soap11_builder_helper_process_text(builder_helper, env); + if(status == AXIS2_FAILURE) + { + return AXIS2_FAILURE; + } + axiom_stax_builder_set_lastnode(builder_helper->om_builder, env, om_element_node); + + axiom_node_set_complete(om_element_node, env, AXIS2_TRUE); + + axiom_stax_builder_set_element_level(builder_helper->om_builder, env, (element_level + - 1)); + + builder_helper->fault_string_present = AXIS2_TRUE; + + } + else if(axutil_strcmp(AXIOM_SOAP11_SOAP_FAULT_ACTOR_LOCAL_NAME, ele_localname) == 0) + { + axiom_soap_fault_role_t *fault_role = NULL; + fault_role = axiom_soap_fault_role_create(env); + if(!fault_role) + { + return AXIS2_FAILURE; + } + axiom_element_set_localname(om_ele, env, AXIOM_SOAP12_SOAP_FAULT_ROLE_LOCAL_NAME); + + axiom_soap_fault_role_set_base_node(fault_role, env, om_element_node); + + axiom_soap_fault_set_role(soap_fault, env, fault_role); + /* + Role element may not have a namespace associated, hence commented, else it segfaults here - Samisa + status = axiom_soap_builder_process_namespace_data( + builder_helper->soap_builder, env, om_element_node, AXIS2_TRUE); + if(status == AXIS2_FAILURE) + return AXIS2_FAILURE; */ + } + else if(axutil_strcmp(AXIOM_SOAP11_SOAP_FAULT_DETAIL_LOCAL_NAME, ele_localname) == 0) + { + axiom_soap_fault_detail_t *fault_detail = NULL; + fault_detail = axiom_soap_fault_detail_create(env); + if(!fault_detail) + { + return AXIS2_FAILURE; + } + axiom_element_set_localname(om_ele, env, AXIOM_SOAP12_SOAP_FAULT_DETAIL_LOCAL_NAME); + + axiom_soap_fault_detail_set_base_node(fault_detail, env, om_element_node); + + axiom_soap_fault_set_detail(soap_fault, env, fault_detail); + } + else + { + return AXIS2_SUCCESS; + } + } + else if(element_level == 5) + { + axiom_node_t *parent_node = NULL; + axiom_element_t *parent_element = NULL; + axis2_char_t *parent_localname = NULL; + + parent_node = axiom_node_get_parent(om_element_node, env); + if(!parent_node) + { + return AXIS2_FAILURE; + } + parent_element = (axiom_element_t *)axiom_node_get_data_element(om_element_node, env); + parent_localname = axiom_element_get_localname(parent_element, env); + + if(!parent_localname) + { + return AXIS2_FAILURE; + } + if(axutil_strcmp(parent_localname, AXIOM_SOAP12_SOAP_FAULT_ROLE_LOCAL_NAME) == 0) + { + AXIS2_ERROR_SET(env->error, + AXIS2_ERROR_SOAP11_FAULT_ACTOR_SHOULD_NOT_HAVE_CHILD_ELEMENTS, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "SOAP 1.1 Actor should not have child elements"); + return AXIS2_FAILURE; + } + } + return AXIS2_SUCCESS; +} + +static axis2_status_t +axiom_soap11_builder_helper_process_text( + axiom_soap11_builder_helper_t * builder_helper, + const axutil_env_t * env) +{ + int token = 0; + + token = axiom_stax_builder_next_with_token(builder_helper->om_builder, env); + + if(token == -1) + { + return AXIS2_FAILURE; + } + while(token != AXIOM_XML_READER_END_ELEMENT) + { + if(token != AXIOM_XML_READER_CHARACTER) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_ONLY_CHARACTERS_ARE_ALLOWED_HERE, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Unidentified character in SOAP 1.1 builder helper processing"); + return AXIS2_FAILURE; + + } + token = axiom_stax_builder_next_with_token(builder_helper->om_builder, env); + if(token == -1) + { + return AXIS2_FAILURE; + } + } + return AXIS2_SUCCESS; +} diff --git a/axiom/src/soap/soap12_builder_helper.c b/axiom/src/soap/soap12_builder_helper.c new file mode 100644 index 0000000..179d26d --- /dev/null +++ b/axiom/src/soap/soap12_builder_helper.c @@ -0,0 +1,718 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "axiom_soap12_builder_helper.h" +#include <axutil_array_list.h> +#include "_axiom_soap_body.h" +#include "_axiom_soap_fault.h" +#include "_axiom_soap_envelope.h" +#include "_axiom_soap_fault_code.h" +#include "_axiom_soap_fault_sub_code.h" +#include "_axiom_soap_fault_node.h" +#include "_axiom_soap_fault_detail.h" +#include "_axiom_soap_fault_reason.h" +#include "_axiom_soap_fault_role.h" +#include "_axiom_soap_fault_value.h" +#include "_axiom_soap_fault_text.h" + +struct axiom_soap12_builder_helper +{ + axiom_soap_builder_t *soap_builder; + + axis2_bool_t code_present; + + axis2_bool_t reason_present; + + axis2_bool_t node_present; + + axis2_bool_t role_present; + + axis2_bool_t detail_present; + + axis2_bool_t subcode_value_present; + + axis2_bool_t value_present; + + axis2_bool_t sub_code_present; + + axis2_bool_t sub_sub_code_present; + + axis2_bool_t code_processing; + + axis2_bool_t sub_code_processing; + + axis2_bool_t reason_processing; + + axutil_array_list_t *detail_element_names; +}; + +AXIS2_EXTERN axiom_soap12_builder_helper_t *AXIS2_CALL +axiom_soap12_builder_helper_create( + const axutil_env_t * env, + axiom_soap_builder_t * soap_builder) +{ + axiom_soap12_builder_helper_t *builder_helper = NULL; + AXIS2_ENV_CHECK(env, NULL); + AXIS2_PARAM_CHECK(env->error, soap_builder, NULL); + + builder_helper = (axiom_soap12_builder_helper_t *)AXIS2_MALLOC(env->allocator, + sizeof(axiom_soap12_builder_helper_t)); + if(!builder_helper) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory. Cannot create SOAP 1.1 builder helper"); + return NULL; + } + + builder_helper->code_present = AXIS2_FALSE; + builder_helper->detail_present = AXIS2_FALSE; + builder_helper->reason_present = AXIS2_FALSE; + builder_helper->role_present = AXIS2_FALSE; + builder_helper->sub_code_present = AXIS2_FALSE; + builder_helper->reason_processing = AXIS2_FALSE; + builder_helper->code_processing = AXIS2_FALSE; + builder_helper->sub_code_processing = AXIS2_FALSE; + builder_helper->detail_element_names = NULL; + builder_helper->node_present = AXIS2_FALSE; + builder_helper->soap_builder = soap_builder; + builder_helper->sub_sub_code_present = AXIS2_FALSE; + builder_helper->value_present = AXIS2_FALSE; + builder_helper->subcode_value_present = AXIS2_FALSE; + + return builder_helper; +} + +AXIS2_EXTERN void AXIS2_CALL +axiom_soap12_builder_helper_free( + axiom_soap12_builder_helper_t * builder_helper, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, void); + + if(builder_helper->detail_element_names) + { + axutil_array_list_free(builder_helper->detail_element_names, env); + builder_helper->detail_element_names = NULL; + } + + AXIS2_FREE(env->allocator, builder_helper); + builder_helper = NULL; + return; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap12_builder_helper_handle_event( + axiom_soap12_builder_helper_t * builder_helper, + const axutil_env_t * env, + axiom_node_t * om_ele_node, + int element_level) +{ + axis2_char_t *ele_localname = NULL; + axiom_element_t *om_ele = NULL; + + axiom_soap_body_t *soap_body = NULL; + axiom_soap_fault_t *soap_fault = NULL; + axiom_soap_envelope_t *soap_envelope = NULL; + + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, om_ele_node, AXIS2_FAILURE); + + om_ele = (axiom_element_t *)axiom_node_get_data_element(om_ele_node, env); + if(!om_ele) + { + return AXIS2_FAILURE; + } + + ele_localname = axiom_element_get_localname(om_ele, env); + if(!ele_localname) + { + return AXIS2_FAILURE; + } + + soap_envelope = axiom_soap_builder_get_soap_envelope(builder_helper->soap_builder, env); + if(!soap_envelope) + { + return AXIS2_FAILURE; + } + + soap_body = axiom_soap_envelope_get_body(soap_envelope, env); + if(!soap_body) + { + return AXIS2_FAILURE; + } + + soap_fault = axiom_soap_body_get_fault(soap_body, env); + if(!soap_fault) + { + return AXIS2_FAILURE; + } + + if(element_level == 4) + { + if(axutil_strcmp(AXIOM_SOAP12_SOAP_FAULT_CODE_LOCAL_NAME, ele_localname) == 0) + { + if(builder_helper->code_present) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_MULTIPLE_CODE_ELEMENTS_ENCOUNTERED, + AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Multiple fault code elements encountered in SOAP fault"); + return AXIS2_FAILURE; + } + else + { + axiom_soap_fault_code_t *soap_fault_code = NULL; + soap_fault_code = axiom_soap_fault_code_create(env); + if(!soap_fault_code) + { + return AXIS2_FAILURE; + } + axiom_soap_fault_code_set_base_node(soap_fault_code, env, om_ele_node); + + axiom_soap_fault_code_set_builder(soap_fault_code, env, + builder_helper->soap_builder); + + axiom_soap_fault_set_code(soap_fault, env, soap_fault_code); + + builder_helper->code_present = AXIS2_TRUE; + builder_helper->code_processing = AXIS2_TRUE; + } + } + else if(axutil_strcmp(AXIOM_SOAP12_SOAP_FAULT_REASON_LOCAL_NAME, ele_localname) == 0) + { + if(!(builder_helper->code_processing) && !(builder_helper->sub_code_processing)) + { + if(builder_helper->code_present) + { + if(builder_helper->reason_present) + { + AXIS2_ERROR_SET(env->error, + AXIS2_ERROR_MULTIPLE_REASON_ELEMENTS_ENCOUNTERED, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Multiple fault reason elements encountered in SOAP fault"); + + return AXIS2_FAILURE; + } + else + { + axiom_soap_fault_reason_t *fault_reason = NULL; + fault_reason = axiom_soap_fault_reason_create(env); + if(!fault_reason) + { + return AXIS2_FAILURE; + } + + axiom_soap_fault_reason_set_base_node(fault_reason, env, om_ele_node); + + axiom_soap_fault_set_reason(soap_fault, env, fault_reason); + + axiom_soap_fault_reason_set_builder(fault_reason, env, + builder_helper-> soap_builder); + + builder_helper->reason_present = AXIS2_TRUE; + builder_helper->reason_processing = AXIS2_TRUE; + } + } + else + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_WRONG_ELEMENT_ORDER_ENCOUNTERED, + AXIS2_FAILURE); + return AXIS2_FAILURE; + } + } + else + { + if(builder_helper->code_processing) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_SOAP_FAULT_CODE_DOES_NOT_HAVE_A_VALUE, + AXIS2_FAILURE); + return AXIS2_FAILURE; + } + else + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_SOAP_FAULT_CODE_DOES_NOT_HAVE_A_VALUE, + AXIS2_FAILURE); + return AXIS2_FAILURE; + } + } + } + else if(axutil_strcmp(ele_localname, AXIOM_SOAP12_SOAP_FAULT_NODE_LOCAL_NAME) == 0) + { + if(!(builder_helper->reason_processing)) + { + if(builder_helper->reason_present && !(builder_helper->role_present) + && !(builder_helper->detail_present)) + { + if(builder_helper->node_present) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_MULTIPLE_NODE_ELEMENTS_ENCOUNTERED, + AXIS2_FAILURE); + return AXIS2_FAILURE; + } + else + { + axiom_soap_fault_node_t *soap_fault_node = NULL; + soap_fault_node = axiom_soap_fault_node_create(env); + if(!soap_fault_node) + { + return AXIS2_FAILURE; + } + + axiom_soap_fault_node_set_base_node(soap_fault_node, env, om_ele_node); + + axiom_soap_fault_set_node(soap_fault, env, soap_fault_node); + + builder_helper->node_present = AXIS2_TRUE; + } + } + else + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_WRONG_ELEMENT_ORDER_ENCOUNTERED, + AXIS2_FALSE); + + return AXIS2_FAILURE; + } + } + else + { + AXIS2_ERROR_SET(env->error, + AXIS2_ERROR_SOAP_FAULT_REASON_ELEMENT_SHOULD_HAVE_A_TEXT, AXIS2_FALSE); + return AXIS2_FAILURE; + } + + } + else if(axutil_strcmp(ele_localname, AXIOM_SOAP12_SOAP_FAULT_ROLE_LOCAL_NAME) == 0) + { + if(!(builder_helper->reason_processing)) + { + if(builder_helper->reason_present && !(builder_helper->detail_present)) + { + if(builder_helper->role_present) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_MULTIPLE_ROLE_ELEMENTS_ENCOUNTERED, + AXIS2_FAILURE); + + return AXIS2_FAILURE; + } + else + { + axiom_soap_fault_role_t *soap_fault_role = NULL; + soap_fault_role = axiom_soap_fault_role_create(env); + if(!soap_fault_role) + return AXIS2_FAILURE; + + axiom_soap_fault_role_set_base_node(soap_fault_role, env, om_ele_node); + + axiom_soap_fault_set_role(soap_fault, env, soap_fault_role); + builder_helper->role_present = AXIS2_TRUE; + } + } + else + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_WRONG_ELEMENT_ORDER_ENCOUNTERED, + AXIS2_FAILURE); + return AXIS2_FAILURE; + } + } + else + { + + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_SOAP_FAULT_ROLE_ELEMENT_SHOULD_HAVE_A_TEXT, + AXIS2_FAILURE); + return AXIS2_FAILURE; + } + } + else if(axutil_strcmp(ele_localname, AXIOM_SOAP12_SOAP_FAULT_DETAIL_LOCAL_NAME) == 0) + { + if(!(builder_helper->reason_processing)) + { + if(builder_helper->reason_present) + { + if(builder_helper->detail_present) + { + AXIS2_ERROR_SET(env->error, + AXIS2_ERROR_MULTIPLE_DETAIL_ELEMENTS_ENCOUNTERED, AXIS2_FAILURE); + return AXIS2_FAILURE; + } + else + { + + axiom_soap_fault_detail_t *soap_fault_detail = NULL; + soap_fault_detail = axiom_soap_fault_detail_create(env); + if(!soap_fault_detail) + return AXIS2_FAILURE; + + axiom_soap_fault_detail_set_base_node(soap_fault_detail, env, om_ele_node); + + axiom_soap_fault_set_detail(soap_fault, env, soap_fault_detail); + builder_helper->detail_present = AXIS2_TRUE; + } + } + else + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_WRONG_ELEMENT_ORDER_ENCOUNTERED, + AXIS2_FAILURE); + + return AXIS2_FAILURE; + + } + } + else + { + AXIS2_ERROR_SET(env->error, + AXIS2_ERROR_SOAP_FAULT_REASON_ELEMENT_SHOULD_HAVE_A_TEXT, AXIS2_FAILURE); + return AXIS2_FAILURE; + } + + } + else + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_UNSUPPORTED_ELEMENT_IN_SOAP_FAULT_ELEMENT, + AXIS2_FAILURE); + return AXIS2_FAILURE; + } + } + else if(element_level == 5) + { + axiom_node_t *parent_node = NULL; + axiom_element_t *parent_ele = NULL; + axis2_char_t *parent_localname = NULL; + parent_node = axiom_node_get_parent(om_ele_node, env); + if(!parent_node) + { + return AXIS2_FAILURE; + } + parent_ele = (axiom_element_t *)axiom_node_get_data_element(parent_node, env); + if(!parent_ele) + { + return AXIS2_FAILURE; + } + parent_localname = axiom_element_get_localname(parent_ele, env); + if(!parent_localname) + { + return AXIS2_FAILURE; + } + + if(axutil_strcmp(parent_localname, AXIOM_SOAP12_SOAP_FAULT_CODE_LOCAL_NAME) == 0) + { + if(axutil_strcmp(ele_localname, AXIOM_SOAP12_SOAP_FAULT_VALUE_LOCAL_NAME) == 0) + { + if(!(builder_helper->value_present)) + { + axiom_soap_fault_value_t *soap_fault_value = NULL; + axiom_soap_fault_code_t *parent_fcode = NULL; + + soap_fault_value = axiom_soap_fault_value_create(env); + if(!soap_fault_value) + { + return AXIS2_FAILURE; + } + axiom_soap_fault_value_set_base_node(soap_fault_value, env, om_ele_node); + + parent_fcode = axiom_soap_fault_get_code(soap_fault, env); + if(!parent_fcode) + { + return AXIS2_FAILURE; + } + axiom_soap_fault_code_set_value(parent_fcode, env, soap_fault_value); + + builder_helper->value_present = AXIS2_TRUE; + builder_helper->code_processing = AXIS2_FALSE; + + } + else + { + AXIS2_ERROR_SET(env->error, + AXIS2_ERROR_MULTIPLE_VALUE_ENCOUNTERED_IN_CODE_ELEMENT, AXIS2_FAILURE); + return AXIS2_FAILURE; + } + } + else if(axutil_strcmp(ele_localname, AXIOM_SOAP12_SOAP_FAULT_SUB_CODE_LOCAL_NAME) == 0) + { + if(!(builder_helper->sub_code_present)) + { + if(builder_helper->value_present) + { + + axiom_soap_fault_sub_code_t *fault_subcode = NULL; + axiom_soap_fault_code_t *fault_code = NULL; + + fault_subcode = axiom_soap_fault_sub_code_create(env); + if(!fault_subcode) + { + return AXIS2_FAILURE; + } + axiom_soap_fault_sub_code_set_base_node(fault_subcode, env, om_ele_node); + + fault_code = axiom_soap_fault_get_code(soap_fault, env); + if(!fault_code) + { + return AXIS2_FAILURE; + } + axiom_soap_fault_code_set_sub_code(fault_code, env, fault_subcode); + + axiom_soap_fault_sub_code_set_builder(fault_subcode, env, + builder_helper-> soap_builder); + + builder_helper->sub_code_present = AXIS2_TRUE; + builder_helper->sub_code_processing = AXIS2_TRUE; + } + else + { + AXIS2_ERROR_SET(env->error, + AXIS2_ERROR_SOAP_FAULT_VALUE_SHOULD_BE_PRESENT_BEFORE_SUB_CODE, + AXIS2_FAILURE); + return AXIS2_FAILURE; + } + } + else + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_MULTIPLE_SUB_CODE_VALUES_ENCOUNTERED, + AXIS2_FAILURE); + return AXIS2_FAILURE; + } + } + else + { + AXIS2_ERROR_SET(env->error, + AXIS2_ERROR_THIS_LOCALNAME_NOT_SUPPORTED_INSIDE_THE_CODE_ELEMENT, AXIS2_FAILURE); + return AXIS2_FAILURE; + } + } + else if(axutil_strcmp(parent_localname, AXIOM_SOAP12_SOAP_FAULT_REASON_LOCAL_NAME) == 0) + { + if(axutil_strcmp(ele_localname, AXIOM_SOAP12_SOAP_FAULT_TEXT_LOCAL_NAME) == 0) + { + axiom_soap_fault_text_t *soap_fault_text = NULL; + axiom_soap_fault_reason_t *fault_reason = NULL; + + soap_fault_text = axiom_soap_fault_text_create(env); + if(!soap_fault_text) + { + return AXIS2_FAILURE; + } + axiom_soap_fault_text_set_base_node(soap_fault_text, env, om_ele_node); + + fault_reason = axiom_soap_fault_get_reason(soap_fault, env); + if(!fault_reason) + { + return AXIS2_FAILURE; + } + + axiom_soap_fault_reason_add_soap_fault_text(fault_reason, env, soap_fault_text); + builder_helper->reason_processing = AXIS2_FALSE; + + axiom_soap_builder_set_bool_processing_mandatory_fault_elements( + builder_helper->soap_builder, env, AXIS2_FALSE); + + } + else + { + AXIS2_ERROR_SET(env->error, + AXIS2_ERROR_THIS_LOCALNAME_IS_NOT_SUPPORTED_INSIDE_THE_REASON_ELEMENT, + AXIS2_FAILURE); + return AXIS2_FAILURE; + } + + } + else if(axutil_strcmp(parent_localname, AXIOM_SOAP12_SOAP_FAULT_DETAIL_LOCAL_NAME) == 0) + { + axiom_soap_builder_set_processing_detail_elements(builder_helper-> soap_builder, env, + AXIS2_TRUE); + + if(!(builder_helper->detail_element_names)) + { + builder_helper->detail_element_names = axutil_array_list_create(env, 20); + } + + axutil_array_list_add(builder_helper->detail_element_names, env, ele_localname); + + } + else + { + + return AXIS2_FAILURE; + } + + } + else if(element_level > 5) + { + axiom_node_t *parent_node = NULL; + axiom_element_t *parent_ele = NULL; + axis2_char_t *parent_localname = NULL; + + parent_node = axiom_node_get_parent(om_ele_node, env); + if(!parent_node) + { + return AXIS2_FAILURE; + } + parent_ele = (axiom_element_t *)axiom_node_get_data_element(parent_node, env); + if(!parent_ele) + { + return AXIS2_FAILURE; + } + + parent_localname = axiom_element_get_localname(parent_ele, env); + if(!parent_localname) + { + return AXIS2_FAILURE; + } + if(axutil_strcmp(parent_localname, AXIOM_SOAP12_SOAP_FAULT_SUB_CODE_LOCAL_NAME) == 0) + { + if(axutil_strcmp(ele_localname, AXIOM_SOAP12_SOAP_FAULT_VALUE_LOCAL_NAME) == 0) + { + if(builder_helper->subcode_value_present) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_MULTIPLE_SUB_CODE_VALUES_ENCOUNTERED, + AXIS2_FAILURE); + return AXIS2_FAILURE; + } + else + { + + axiom_soap_fault_sub_code_t *sub_code = NULL; + axiom_soap_fault_code_t *code = NULL; + axiom_soap_fault_value_t *value = NULL; + code = axiom_soap_fault_get_code(soap_fault, env); + + if(!code) + { + AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, + "fault code null when it should not be null"); + return AXIS2_FAILURE; + } + + sub_code = axiom_soap_fault_code_get_sub_code(code, env); + if(!sub_code) + { + AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, + "fault subcode null when it should not be null"); + return AXIS2_FAILURE; + } + value = axiom_soap_fault_value_create(env); + if(!value) + { + return AXIS2_FAILURE; + } + + axiom_soap_fault_value_set_base_node(value, env, om_ele_node); + + axiom_soap_fault_sub_code_set_value(sub_code, env, value); + + builder_helper->subcode_value_present = AXIS2_TRUE; + builder_helper->sub_sub_code_present = AXIS2_FALSE; + builder_helper->sub_code_processing = AXIS2_FALSE; + } + } + else if(axutil_strcmp(ele_localname, AXIOM_SOAP12_SOAP_FAULT_SUB_CODE_LOCAL_NAME) == 0) + { + if(builder_helper->subcode_value_present) + { + if(!(builder_helper->sub_sub_code_present)) + { + axiom_soap_fault_code_t *fault_code = NULL; + axiom_soap_fault_sub_code_t *parent_subcode = NULL; + axiom_soap_fault_sub_code_t *subcode = NULL; + + subcode = axiom_soap_fault_sub_code_create(env); + if(!subcode) + { + return AXIS2_FAILURE; + } + + axiom_soap_fault_sub_code_set_base_node(subcode, env, om_ele_node); + + fault_code = axiom_soap_fault_get_code(soap_fault, env); + if(!fault_code) + { + AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, + "fault code null when it should not be null"); + return AXIS2_FAILURE; + } + parent_subcode = axiom_soap_fault_code_get_sub_code(fault_code, env); + if(!parent_subcode) + { + AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, + "fault subcode null when it should not be null"); + return AXIS2_FAILURE; + } + + axiom_soap_fault_sub_code_set_sub_code(parent_subcode, env, subcode); + + builder_helper->subcode_value_present = AXIS2_FALSE; + builder_helper->sub_sub_code_present = AXIS2_TRUE; + builder_helper->sub_code_processing = AXIS2_TRUE; + } + else + { + AXIS2_ERROR_SET(env->error, + AXIS2_ERROR_MULTIPLE_SUB_CODE_VALUES_ENCOUNTERED, AXIS2_FAILURE); + + return AXIS2_FAILURE; + } + } + else + { + AXIS2_ERROR_SET(env->error, + AXIS2_ERROR_SOAP_FAULT_VALUE_SHOULD_BE_PRESENT_BEFORE_SUB_CODE, + AXIS2_FAILURE); + + return AXIS2_FAILURE; + + } + } + else + { + AXIS2_ERROR_SET(env->error, + AXIS2_ERROR_THIS_LOCALNAME_IS_NOT_SUPPORTED_INSIDE_THE_SUB_CODE_ELEMENT, + AXIS2_FAILURE); + + return AXIS2_FAILURE; + } + } + else if(axiom_soap_builder_is_processing_detail_elements(builder_helper->soap_builder, env)) + { + + int detail_element_level = 0; + axis2_bool_t local_name_exists = AXIS2_FALSE; + int i = 0; + if(!(builder_helper->detail_element_names)) + { + return AXIS2_FAILURE; + } + + for(i = 0; i < axutil_array_list_size(builder_helper->detail_element_names, env); i++) + { + if(axutil_strcmp(parent_localname, axutil_array_list_get( + builder_helper->detail_element_names, env, i)) == 0) + { + local_name_exists = AXIS2_TRUE; + detail_element_level = i + 1; + } + } + if(local_name_exists) + { + axutil_array_list_add(builder_helper->detail_element_names, env, ele_localname); + } + else + { + return AXIS2_FAILURE; + } + } + } + return AXIS2_SUCCESS; +} diff --git a/axiom/src/soap/soap_body.c b/axiom/src/soap/soap_body.c new file mode 100644 index 0000000..8fb7d8f --- /dev/null +++ b/axiom/src/soap/soap_body.c @@ -0,0 +1,547 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "_axiom_soap_envelope.h" +#include "_axiom_soap_body.h" +#include <axutil_hash.h> +#include <axiom_soap_const.h> +#include <axiom_soap_builder.h> +#include <axiom_soap_fault_code.h> +#include <axiom_soap_fault_reason.h> +#include <axiom_soap_fault_detail.h> +#include <axiom_soap_fault_role.h> +#include "_axiom_soap_fault_value.h" +#include "_axiom_soap_fault_text.h" +#include <axiom_util.h> + +struct axiom_soap_body +{ + axiom_node_t *om_ele_node; + + axis2_bool_t has_fault; + + axiom_soap_fault_t *soap_fault; + + axiom_soap_builder_t *soap_builder; + + int soap_version; +}; + +AXIS2_EXTERN axiom_soap_body_t *AXIS2_CALL +axiom_soap_body_create( + const axutil_env_t * env) +{ + axiom_soap_body_t *soap_body = NULL; + + soap_body = (axiom_soap_body_t *)AXIS2_MALLOC(env->allocator, sizeof(axiom_soap_body_t)); + + if(!soap_body) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + soap_body->om_ele_node = NULL; + soap_body->soap_builder = NULL; + soap_body->has_fault = AXIS2_FALSE; + soap_body->soap_fault = NULL; + + return soap_body; +} + +AXIS2_EXTERN axiom_soap_body_t *AXIS2_CALL +axiom_soap_body_create_with_parent( + const axutil_env_t * env, + axiom_soap_envelope_t * envelope) +{ + axiom_soap_body_t *soap_body = NULL; + axiom_element_t *ele = NULL; + axiom_node_t *parent_node = NULL; + axiom_element_t *parent_ele = NULL; + axiom_namespace_t *om_ns = NULL; + + AXIS2_PARAM_CHECK(env->error, envelope, NULL); + + soap_body = axiom_soap_body_create(env); + if(!soap_body) + { + return NULL; + } + + /*get parent node from SOAP envelope */ + parent_node = axiom_soap_envelope_get_base_node(envelope, env); + if(!parent_node) + { + axiom_soap_body_free(soap_body, env); + return NULL; + } + parent_ele = (axiom_element_t *)axiom_node_get_data_element(parent_node, env); + + if(!parent_ele) + { + axiom_soap_body_free(soap_body, env); + return NULL; + } + + om_ns = axiom_element_get_namespace(parent_ele, env, parent_node); + + ele = axiom_element_create(env, parent_node, AXIOM_SOAP_BODY_LOCAL_NAME, om_ns, + &(soap_body->om_ele_node)); + if(!ele) + { + axiom_soap_body_free(soap_body, env); + return NULL; + } + + axiom_soap_envelope_set_body(envelope, env, soap_body); + + return soap_body; +} + +AXIS2_EXTERN void AXIS2_CALL +axiom_soap_body_free( + axiom_soap_body_t * soap_body, + const axutil_env_t * env) +{ + + if(soap_body->soap_fault) + { + axiom_soap_fault_free(soap_body->soap_fault, env); + soap_body->soap_fault = NULL; + } + AXIS2_FREE(env->allocator, soap_body); + soap_body = NULL; + return; +} + +/** + * Indicates whether a soap fault is available with this soap body + * @param soap_body axiom_soap_body struct + * @param env environment must not be null + * @return AXIS2_TRUE if fault is available, AXIS2_FALSE otherwise + */ +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +axiom_soap_body_has_fault( + axiom_soap_body_t * soap_body, + const axutil_env_t * env) +{ + if(soap_body->soap_fault) + { + soap_body->has_fault = AXIS2_TRUE; + } + else + { + while(!axiom_node_is_complete(soap_body->om_ele_node, env)) + { + if(axiom_soap_builder_next(soap_body->soap_builder, env) != AXIS2_SUCCESS) + { + /* problem in building the SOAP body. Note that has_fault is about soap fault, + * not about problem in building the node. So, even though there is a problem + * building the body, has_fault should be AXIS2_FALSE + */ + break; + } + + if(soap_body->soap_fault) + { + soap_body->has_fault = AXIS2_TRUE; + break; + } + } + } + + return soap_body->has_fault; +} + +/** + * Returns the axiom_soap_fault_t struct in this axiom_soap_bodY_t + * struct + * + * @return the <code>SOAPFault</code> object in this <code>SOAPBody</code> + * object + */ +AXIS2_EXTERN axiom_soap_fault_t *AXIS2_CALL +axiom_soap_body_get_fault( + axiom_soap_body_t * soap_body, + const axutil_env_t * env) +{ + if(soap_body->soap_fault) + { + return soap_body->soap_fault; + } + else if(soap_body->soap_builder) + { + while(!(soap_body->soap_fault) && !(axiom_node_is_complete(soap_body->om_ele_node, env))) + { + int status = AXIS2_SUCCESS; + status = axiom_soap_builder_next(soap_body->soap_builder, env); + if(status == AXIS2_FAILURE) + { + return NULL; + } + } + if(soap_body->soap_fault) + { + soap_body->has_fault = AXIS2_TRUE; + return soap_body->soap_fault; + } + } + return NULL; +} + +AXIS2_EXTERN axiom_node_t *AXIS2_CALL +axiom_soap_body_get_base_node( + axiom_soap_body_t * soap_body, + const axutil_env_t * env) +{ + return soap_body->om_ele_node; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_body_set_base_node( + axiom_soap_body_t * soap_body, + const axutil_env_t * env, + axiom_node_t * node) +{ + AXIS2_PARAM_CHECK(env->error, node, AXIS2_FAILURE); + if(axiom_node_get_node_type(node, env) != AXIOM_ELEMENT) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_BASE_TYPE, AXIS2_FAILURE); + return AXIS2_FAILURE; + } + soap_body->om_ele_node = node; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_body_set_builder( + axiom_soap_body_t * soap_body, + const axutil_env_t * env, + axiom_soap_builder_t * builder) +{ + AXIS2_PARAM_CHECK(env->error, builder, AXIS2_FAILURE); + + soap_body->soap_builder = builder; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axiom_soap_builder_t *AXIS2_CALL +axiom_soap_body_get_builder( + axiom_soap_body_t * soap_body, + const axutil_env_t * env) +{ + if(!soap_body) + { + return NULL; + } + return soap_body->soap_builder; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_body_build( + axiom_soap_body_t * soap_body, + const axutil_env_t * env) +{ + int status = AXIS2_SUCCESS; + axiom_node_t *xop_node = NULL; + axis2_bool_t is_replaced = AXIS2_FALSE; + axiom_element_t *xop_element = NULL; + + if(soap_body->om_ele_node && soap_body->soap_builder) + { + xop_node + = axiom_util_get_node_by_local_name(env, soap_body->om_ele_node, AXIS2_XOP_INCLUDE); + + if(xop_node) + { + xop_element = (axiom_element_t *)axiom_node_get_data_element(xop_node, env); + if(xop_element) + { + is_replaced = axiom_soap_builder_replace_xop(soap_body->soap_builder, env, + xop_node, xop_element); + } + } + + while(axiom_node_is_complete(soap_body->om_ele_node, env) != AXIS2_TRUE) + { + status = axiom_soap_builder_next(soap_body->soap_builder, env); + if(status == AXIS2_FAILURE) + { + return AXIS2_FAILURE; + } + } + } + return AXIS2_SUCCESS; +} + +/** + This is an internal function + + */ +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_body_set_fault( + axiom_soap_body_t * soap_body, + const axutil_env_t * env, + axiom_soap_fault_t * soap_fault) +{ + AXIS2_PARAM_CHECK(env->error, soap_fault, AXIS2_FAILURE); + if(soap_body->soap_fault) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_ONLY_ONE_SOAP_FAULT_ALLOWED_IN_BODY, AXIS2_FAILURE); + return AXIS2_FAILURE; + } + else + { + soap_body->soap_fault = soap_fault; + soap_body->has_fault = AXIS2_TRUE; + } + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_body_add_child( + axiom_soap_body_t * soap_body, + const axutil_env_t * env, + axiom_node_t * child) +{ + AXIS2_PARAM_CHECK(env->error, child, AXIS2_FAILURE); + + if(soap_body->om_ele_node) + { + return axiom_node_add_child(soap_body->om_ele_node, env, child); + } + return AXIS2_FAILURE; +} + +AXIS2_EXTERN int AXIS2_CALL +axiom_soap_body_get_soap_version( + axiom_soap_body_t * soap_body, + const axutil_env_t * env) +{ + axiom_element_t *body_ele = NULL; + axiom_namespace_t *om_ns = NULL; + axis2_char_t *uri = NULL; + + if(!soap_body->om_ele_node) + { + return AXIS2_FAILURE; + } + body_ele = axiom_node_get_data_element(soap_body->om_ele_node, env); + if(!body_ele) + { + return AXIS2_FAILURE; + } + om_ns = axiom_element_get_namespace(body_ele, env, soap_body->om_ele_node); + if(!om_ns) + { + return AXIS2_FAILURE; + } + uri = axiom_namespace_get_uri(om_ns, env); + if(uri) + { + if(axutil_strcmp(uri, AXIOM_SOAP11_SOAP_ENVELOPE_NAMESPACE_URI) == 0) + { + return AXIOM_SOAP11; + } + else if(axutil_strcmp(uri, AXIOM_SOAP12_SOAP_ENVELOPE_NAMESPACE_URI) == 0) + { + return AXIOM_SOAP12; + } + } + return AXIS2_FAILURE; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_body_convert_fault_to_soap11( + axiom_soap_body_t * soap_body, + const axutil_env_t * env) +{ + if(soap_body) + { + axiom_soap_fault_t *soap_fault = NULL; + if(axiom_soap_body_has_fault(soap_body, env)) + { + soap_fault = axiom_soap_body_get_fault(soap_body, env); + if(soap_fault) + { + axiom_soap_fault_code_t *fault_code = NULL; + axiom_soap_fault_reason_t *fault_reason = NULL; + axiom_soap_fault_detail_t *fault_detail = NULL; + axiom_soap_fault_role_t *fault_role = NULL; + fault_code = axiom_soap_fault_get_code(soap_fault, env); + if(fault_code) + { + axiom_node_t *fault_code_om_node = NULL; + axiom_element_t *fault_code_om_ele = NULL; + axiom_node_t *fault_value_om_node = NULL; + axiom_element_t *fault_value_om_ele = NULL; + axiom_soap_fault_value_t *fault_value = NULL; + axis2_char_t *text = NULL; + + fault_code_om_node = axiom_soap_fault_code_get_base_node(fault_code, env); + if(fault_code_om_node) + { + fault_code_om_ele = (axiom_element_t *)axiom_node_get_data_element( + fault_code_om_node, env); + if(fault_code_om_ele) + { + axiom_element_set_localname(fault_code_om_ele, env, + AXIOM_SOAP11_SOAP_FAULT_CODE_LOCAL_NAME); + + fault_value = axiom_soap_fault_code_get_value(fault_code, env); + + if(fault_value) + { + fault_value_om_node = axiom_soap_fault_value_get_base_node( + fault_value, env); + if(fault_value_om_node) + { + fault_value_om_ele + = (axiom_element_t *)axiom_node_get_data_element( + fault_value_om_node, env); + if(fault_value_om_ele) + { + text = axiom_element_get_text(fault_value_om_ele, env, + fault_value_om_node); + if(text) + { + axiom_element_set_text(fault_code_om_ele, env, text, + fault_code_om_node); + } + } + axiom_node_free_tree(fault_value_om_node, env); + axiom_soap_fault_value_set_base_node(fault_value, env, NULL); + } + } + } + } + } + fault_reason = axiom_soap_fault_get_reason(soap_fault, env); + if(fault_reason) + { + axiom_node_t *fault_reason_om_node = NULL; + axiom_element_t *fault_reason_om_ele = NULL; + axiom_node_t *fault_text_om_node = NULL; + axiom_element_t *fault_text_om_ele = NULL; + axiom_soap_fault_text_t *fault_text = NULL; + axis2_char_t *text = NULL; + + fault_reason_om_node = axiom_soap_fault_reason_get_base_node(fault_reason, env); + if(fault_reason_om_node) + { + fault_reason_om_ele = (axiom_element_t *)axiom_node_get_data_element( + fault_reason_om_node, env); + + if(fault_reason_om_ele) + { + + axiom_element_set_localname(fault_reason_om_ele, env, + AXIOM_SOAP11_SOAP_FAULT_STRING_LOCAL_NAME); + + fault_text = axiom_soap_fault_reason_get_first_soap_fault_text( + fault_reason, env); + if(fault_text) + { + fault_text_om_node = axiom_soap_fault_text_get_base_node( + fault_text, env); + if(fault_text_om_node) + { + fault_text_om_ele + = (axiom_element_t *)axiom_node_get_data_element( + fault_text_om_node, env); + if(fault_text_om_ele) + { + text = axiom_element_get_text(fault_text_om_ele, env, + fault_text_om_node); + if(text) + { + axiom_element_set_text(fault_reason_om_ele, env, text, + fault_reason_om_node); + } + } + axiom_node_free_tree(fault_text_om_node, env); + axiom_soap_fault_text_set_base_node(fault_text, env, NULL); + } + } + } + } + } + + fault_role = axiom_soap_fault_get_role(soap_fault, env); + if(fault_role) + { + axiom_node_t *fault_role_om_node = NULL; + axiom_element_t *fault_role_om_ele = NULL; + + fault_role_om_node = axiom_soap_fault_role_get_base_node(fault_role, env); + if(fault_role_om_node) + { + fault_role_om_ele = (axiom_element_t *)axiom_node_get_data_element( + fault_role_om_node, env); + if(fault_role_om_ele) + { + axiom_element_set_localname(fault_role_om_ele, env, + AXIOM_SOAP11_SOAP_FAULT_ACTOR_LOCAL_NAME); + } + } + } + + fault_detail = axiom_soap_fault_get_detail(soap_fault, env); + if(fault_detail) + { + axiom_node_t *fault_detail_om_node = NULL; + axiom_element_t *fault_detail_om_ele = NULL; + fault_detail_om_node = axiom_soap_fault_detail_get_base_node(fault_detail, env); + if(fault_detail_om_node) + { + fault_detail_om_ele = (axiom_element_t *)axiom_node_get_data_element( + fault_detail_om_node, env); + if(fault_detail_om_ele) + { + axiom_element_set_localname(fault_detail_om_ele, env, + AXIOM_SOAP11_SOAP_FAULT_DETAIL_LOCAL_NAME); + } + } + } + } + } + } + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_body_process_attachments( + axiom_soap_body_t * soap_body, + const axutil_env_t * env, + void *user_pram, + axis2_char_t *callback_name) +{ + axis2_status_t status = AXIS2_FAILURE; + + status = axiom_soap_builder_create_attachments(soap_body->soap_builder, env, user_pram, + callback_name); + + if(status == AXIS2_FAILURE) + { + return status; + } + else + { + return axiom_soap_body_build(soap_body, env); + } +} + + diff --git a/axiom/src/soap/soap_builder.c b/axiom/src/soap/soap_builder.c new file mode 100644 index 0000000..6960c03 --- /dev/null +++ b/axiom/src/soap/soap_builder.c @@ -0,0 +1,1206 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <axiom_soap_builder.h> +#include "_axiom_soap_envelope.h" +#include "_axiom_soap_header.h" +#include "axiom_soap11_builder_helper.h" +#include "axiom_soap12_builder_helper.h" +#include <axiom_soap_const.h> +#include "_axiom_soap_body.h" +#include "_axiom_soap_header_block.h" +#include <axiom_stax_builder_internal.h> +#include "_axiom_soap_fault.h" +#include <axutil_http_chunked_stream.h> + +static axis2_status_t +axiom_soap_builder_construct_node( + axiom_soap_builder_t * soap_builder, + const axutil_env_t * env, + axiom_node_t * om_element_node); + +static axis2_status_t +axiom_soap_builder_identify_soap_version( + axiom_soap_builder_t * soap_builder, + const axutil_env_t * env, + const axis2_char_t * soap_version_uri_from_transport); + +static axis2_status_t +axiom_soap_builder_parse_headers( + axiom_soap_builder_t * soap_builder, + const axutil_env_t * env); + +static axis2_status_t +axiom_soap_builder_process_namespace_data( + axiom_soap_builder_t * soap_builder, + const axutil_env_t * env, + axiom_node_t * om_node); + +static axis2_status_t +axiom_soap_builder_construct_soap_header( + axiom_soap_builder_t *soap_builder, + const axutil_env_t *env, + axiom_node_t *om_node); + +static axis2_status_t +axiom_soap_builder_construct_soap_body( + axiom_soap_builder_t *soap_builder, + const axutil_env_t *env, + axiom_node_t *om_node); + +static axis2_status_t +axiom_soap_builder_construct_soap_fault( + axiom_soap_builder_t *soap_builder, + const axutil_env_t *env, + axiom_node_t *om_node); + +static axis2_status_t +axiom_soap_builder_construct_xop_include( + axiom_soap_builder_t *soap_builder, + const axutil_env_t *env, + axiom_node_t *om_element_node); + +struct axiom_soap_builder +{ + axiom_stax_builder_t *om_builder; + + axiom_soap_envelope_t *soap_envelope; + + axis2_bool_t header_present; + + axis2_bool_t body_present; + + int element_level; + + axis2_bool_t processing_fault; + + axis2_bool_t processing_detail_elements; + + axis2_char_t *sender_fault_code; + + axis2_char_t *receiver_fault_code; + + axis2_bool_t processing_mandatory_fault_elements; + + void *builder_helper; + + axiom_namespace_t *envelope_ns; + + int soap_version; + + int last_node_status; + + axis2_bool_t done; + + axutil_hash_t *mime_body_parts; + + axiom_mime_parser_t *mime_parser; + + AXIS2_READ_INPUT_CALLBACK callback; + + void *callback_ctx; + +}; + +typedef enum axis2_builder_last_node_states +{ + AXIS2_BUILDER_LAST_NODE_NULL = 0, + AXIS2_BUILDER_LAST_NODE_NOT_NULL +} axis2_builder_last_node_states; + +#define AXIS2_MAX_EVENT 100 + +AXIS2_EXTERN axiom_soap_builder_t *AXIS2_CALL +axiom_soap_builder_create( + const axutil_env_t * env, + axiom_stax_builder_t * stax_builder, + const axis2_char_t * soap_version) +{ + axiom_soap_builder_t *soap_builder = NULL; + axis2_status_t status = AXIS2_SUCCESS; + + AXIS2_PARAM_CHECK(env->error, stax_builder, NULL); + + soap_builder = (axiom_soap_builder_t *)AXIS2_MALLOC(env->allocator, + sizeof(axiom_soap_builder_t)); + + if(soap_builder == NULL) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + + soap_builder->done = AXIS2_FALSE; + soap_builder->body_present = AXIS2_FALSE; + soap_builder->builder_helper = NULL; + soap_builder->element_level = 0; + soap_builder->header_present = AXIS2_FALSE; + soap_builder->processing_detail_elements = AXIS2_FALSE; + soap_builder->processing_fault = AXIS2_FALSE; + soap_builder->processing_mandatory_fault_elements = AXIS2_FALSE; + soap_builder->receiver_fault_code = NULL; + soap_builder->sender_fault_code = NULL; + soap_builder->soap_version = AXIOM_SOAP12; + soap_builder->last_node_status = -1; + soap_builder->envelope_ns = NULL; + soap_builder->soap_envelope = NULL; + soap_builder->mime_body_parts = NULL; + soap_builder->om_builder = stax_builder; + soap_builder->mime_parser = NULL; + soap_builder->callback = NULL; + soap_builder->callback_ctx = NULL; + + status = axiom_soap_builder_identify_soap_version(soap_builder, env, soap_version); + if(status == AXIS2_FAILURE) + { + axiom_soap_builder_free(soap_builder, env); + return NULL; + } + status = axiom_soap_builder_parse_headers(soap_builder, env); + if(status == AXIS2_FAILURE) + { + axiom_soap_builder_free(soap_builder, env); + return NULL; + } + return soap_builder; +} + +AXIS2_EXTERN void AXIS2_CALL +axiom_soap_builder_free( + axiom_soap_builder_t * soap_builder, + const axutil_env_t * env) +{ + if(!soap_builder) + { + return; + } + if(soap_builder->builder_helper) + { + if(soap_builder->soap_version == AXIOM_SOAP11 && soap_builder->builder_helper) + { + axiom_soap11_builder_helper_free( + (axiom_soap11_builder_helper_t *)(soap_builder->builder_helper), env); + soap_builder->builder_helper = NULL; + } + else if(soap_builder->soap_version == AXIOM_SOAP12 && soap_builder->builder_helper) + { + axiom_soap12_builder_helper_free( + (axiom_soap12_builder_helper_t *)(soap_builder->builder_helper), env); + soap_builder->builder_helper = NULL; + } + } + + if(soap_builder->om_builder) + { + axiom_stax_builder_free(soap_builder->om_builder, env); + soap_builder->om_builder = NULL; + } + + if(soap_builder->mime_body_parts) + { + axutil_hash_index_t *hi = NULL; + void *val = NULL; + const void *key = NULL; + for(hi = axutil_hash_first(soap_builder->mime_body_parts, env); hi; hi = axutil_hash_next( + env, hi)) + { + axutil_hash_this(hi, &key, NULL, &val); + + if(key) + { + AXIS2_FREE(env->allocator, (char *)key); + } + + val = NULL; + key = NULL; + } + + axutil_hash_free(soap_builder->mime_body_parts, env); + soap_builder->mime_body_parts = NULL; + } + + if(soap_builder->mime_parser) + { + axiom_mime_parser_free(soap_builder->mime_parser, env); + soap_builder->mime_parser = NULL; + } + + if(soap_builder->callback_ctx) + { + axis2_callback_info_t *callback_info = NULL; + + callback_info = (axis2_callback_info_t *)(soap_builder->callback_ctx); + if(callback_info) + { + if(callback_info->chunked_stream) + { + axutil_http_chunked_stream_free(callback_info->chunked_stream, env); + callback_info->chunked_stream = NULL; + } + + AXIS2_FREE(env->allocator, callback_info); + callback_info = NULL; + soap_builder->callback_ctx = NULL; + } + } + + if(soap_builder) + { + AXIS2_FREE(env->allocator, soap_builder); + soap_builder = NULL; + } + + return; +} + +AXIS2_EXTERN axiom_soap_envelope_t *AXIS2_CALL +axiom_soap_builder_get_soap_envelope( + axiom_soap_builder_t * soap_builder, + const axutil_env_t * env) +{ + int status = AXIS2_SUCCESS; + + if(!soap_builder) + { + return NULL; + } + if(!(soap_builder->om_builder)) + { + return NULL; + } + while(!(soap_builder->soap_envelope) && !axiom_stax_builder_is_complete( + soap_builder->om_builder, env)) + { + status = axiom_soap_builder_next(soap_builder, env); + if(status == AXIS2_FAILURE) + { + break; + } + } + + return soap_builder->soap_envelope; +} + +AXIS2_EXTERN axiom_document_t *AXIS2_CALL axiom_soap_builder_get_document( + axiom_soap_builder_t * soap_builder, + const axutil_env_t * env) +{ + if (!soap_builder) + { + return NULL; + } + if (soap_builder->om_builder) + { + return axiom_stax_builder_get_document(soap_builder->om_builder, env); + } + else + return NULL; +} + +/** + * Builds next element of the OM structure + * @param builder pointer to the SOAP Builder struct + * @param env Environment. MUST NOT be NULL + * @return AXIS2_SUCCESS if the next element is present else AXIS2_FAILURE + */ +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_builder_next( + axiom_soap_builder_t * soap_builder, + const axutil_env_t * env) +{ + int current_event = AXIS2_MAX_EVENT; + int status = AXIS2_SUCCESS; + + if((!soap_builder) || (soap_builder->done) || (!soap_builder->om_builder)) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Invalid soap builder"); + return AXIS2_FAILURE; + } + + /* Get the status of previous node before building next node. We need the previous state of the + * node to identify very first element, which is SOAP Envelope. If last_node_status is + * AXIS2_BUILDER_LAST_NODE_NULL, then it means next node is SOAP Envelope + */ + if(axiom_stax_builder_get_lastnode(soap_builder->om_builder, env)) + { + soap_builder->last_node_status = AXIS2_BUILDER_LAST_NODE_NOT_NULL; + } + else + { + soap_builder->last_node_status = AXIS2_BUILDER_LAST_NODE_NULL; + } + + current_event = axiom_stax_builder_next_with_token(soap_builder->om_builder, env); + if(current_event == AXIOM_XML_READER_START_ELEMENT + || current_event == AXIOM_XML_READER_EMPTY_ELEMENT) + { + axiom_node_t *current_node = axiom_stax_builder_get_lastnode(soap_builder->om_builder, env); + if(current_node) + { + status = axiom_soap_builder_construct_node(soap_builder, env, current_node); + } + else + { + /* there is an error. So, don't continue building it */ + soap_builder->done = AXIS2_TRUE; + status = AXIS2_FAILURE; + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Error occurred when building node"); + } + } + else if(current_event == -1) + { + /* there is an error. So, don't continue building it */ + soap_builder->done = AXIS2_TRUE; + status = AXIS2_FAILURE; + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Error occurred when building node"); + } + + /* for any other event types, return AXIS2_SUCCESS as the return value. */ + + return status; +} + +AXIS2_EXTERN axiom_node_t *AXIS2_CALL +axiom_soap_builder_get_document_element( + axiom_soap_builder_t * soap_builder, + const axutil_env_t * env) +{ + axiom_node_t *document_node = NULL; + if(soap_builder->soap_envelope) + { + document_node = axiom_soap_envelope_get_base_node(soap_builder->soap_envelope, env); + } + + return document_node; +} + +static axis2_status_t +axiom_soap_builder_construct_node( + axiom_soap_builder_t * soap_builder, + const axutil_env_t * env, + axiom_node_t * om_element_node) +{ + axiom_element_t *om_element = NULL; + const axis2_char_t *ele_localname = NULL; + int element_level = 0; + int status = AXIS2_SUCCESS; + axiom_node_t *parent = NULL; + + /* get OM element struct from node */ + om_element = (axiom_element_t *)axiom_node_get_data_element(om_element_node, env); + if(!om_element) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Cannot construct node. Invalid element"); + return AXIS2_FAILURE; + } + + /* get element local name */ + ele_localname = axiom_element_get_localname(om_element, env); + if(!ele_localname) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Cannot construct node. Invalid element name"); + return AXIS2_FAILURE; + } + + parent = axiom_node_get_parent(om_element_node, env); + if(!parent) + { + /* parent node doesn't exist means, this should be SOAP Envelope */ + if(soap_builder->last_node_status != AXIS2_BUILDER_LAST_NODE_NULL) + { + /* this means, there are two elements in the first level */ + AXIS2_ERROR_SET(env->error, + AXIS2_ERROR_SOAP_MESSAGE_FIRST_ELEMENT_MUST_CONTAIN_LOCAL_NAME, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Soap message can contain only one SOAP Envelope as the top level element"); + return AXIS2_FAILURE; + } + + if(axutil_strcasecmp(ele_localname, AXIOM_SOAP_ENVELOPE_LOCAL_NAME) != 0) + { + AXIS2_ERROR_SET(env->error, + AXIS2_ERROR_SOAP_MESSAGE_FIRST_ELEMENT_MUST_CONTAIN_LOCAL_NAME, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "SOAP message first element must be Envelope"); + return AXIS2_FAILURE; + } + + /** create a null soap envelope struct */ + soap_builder->soap_envelope = axiom_soap_envelope_create_null(env); + if(!soap_builder->soap_envelope) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Unable to create SOAP Envelope"); + return AXIS2_FAILURE; + } + + /** wrap this OM node in it */ + axiom_soap_envelope_set_base_node(soap_builder->soap_envelope, env, om_element_node); + axiom_soap_envelope_set_builder(soap_builder->soap_envelope, env, soap_builder); + status = axiom_soap_builder_process_namespace_data(soap_builder, env, om_element_node); + if(status != AXIS2_SUCCESS) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "SOAP Envelope is having invalid namespace"); + } + + return status; + } + + /** a parent node exist , so not soap envelope. Can be either header/body/children of them */ + + /* get element level of this OM element. Envelope will be in element_level 1. Body and Header + * will be in element level 2. SOAP fault will be child of Body, so it will be in level 3*/ + element_level = axiom_stax_builder_get_element_level(soap_builder->om_builder, env); + if(axiom_stax_builder_get_current_event(soap_builder->om_builder, env) + == AXIOM_XML_READER_EMPTY_ELEMENT) + { + /* if it is an empty element, increase the element level. This is because the element level + * is incremented by STAX builder only if <element> tag is identified. It will not be + * incremented if <element/> tag is seen. But for our logic, even empty element should be + * considered as full element. so, <element/> = <element> </element>. */ + ++element_level; + } + + if(element_level == 2) + { + /* At this level, we can only have soap:Header or soap:Body */ + status = axiom_soap_builder_process_namespace_data(soap_builder, env, om_element_node); + if(status != AXIS2_SUCCESS) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "invalid SOAP namespace"); + return AXIS2_FAILURE; + } + + if(axutil_strcmp(ele_localname, AXIOM_SOAP_HEADER_LOCAL_NAME) == 0) + { + /* this is the soap header element */ + status = axiom_soap_builder_construct_soap_header(soap_builder, env, om_element_node); + } + else if(axutil_strcmp(ele_localname, AXIOM_SOAP_BODY_LOCAL_NAME) == 0) + { + /* This is the SOAP Body element */ + status = axiom_soap_builder_construct_soap_body(soap_builder, env, om_element_node); + } + else + { + AXIS2_ERROR_SET(env->error, + AXIS2_ERROR_SOAP_BUILDER_ENVELOPE_CAN_HAVE_ONLY_HEADER_AND_BODY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "SOAP builder found a child element other than header or body in envelope element"); + return AXIS2_FAILURE; + } + } + else if(element_level == 3) + { + axiom_element_t *parent_ele = NULL; + axis2_char_t *parent_localname = NULL; + + parent_ele = (axiom_element_t *)axiom_node_get_data_element(parent, env); + if(parent_ele) + { + parent_localname = axiom_element_get_localname(parent_ele, env); + } + + if(!parent_localname) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Cannot identify parent element local name"); + return AXIS2_FAILURE; + } + + if(axutil_strcasecmp(parent_localname, AXIOM_SOAP_HEADER_LOCAL_NAME) == 0) + { + axiom_soap_header_block_t *header_block = NULL; + axiom_soap_header_t *soap_header = NULL; + + soap_header = axiom_soap_envelope_get_header(soap_builder->soap_envelope, env); + if(!soap_header) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Cannot get SOAP Header from OM Envelope"); + return AXIS2_FAILURE; + } + + header_block = axiom_soap_header_block_create(env); + if(!header_block) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Cannot create SOAP Header block"); + return AXIS2_FAILURE; + } + + axiom_soap_header_block_set_base_node(header_block, env, om_element_node); + axiom_soap_header_set_header_block(soap_header, env, header_block); + axiom_soap_header_block_set_soap_version(header_block, env, soap_builder->soap_version); + } + else if(axutil_strcasecmp(parent_localname, AXIOM_SOAP_BODY_LOCAL_NAME) == 0) + { + /* if the node is <xop:Include> or MTOM message */ + if(axutil_strcmp(ele_localname, AXIS2_XOP_INCLUDE) == 0) + { + return axiom_soap_builder_construct_xop_include(soap_builder, env, om_element_node); + } + + if(axutil_strcasecmp(ele_localname, AXIOM_SOAP_BODY_FAULT_LOCAL_NAME) == 0) + { + return axiom_soap_builder_construct_soap_fault(soap_builder, env, om_element_node); + } + + /* We don't need to process any other children of SOAP Body. */ + } + else + { + AXIS2_ERROR_SET(env->error, + AXIS2_ERROR_SOAP_BUILDER_ENVELOPE_CAN_HAVE_ONLY_HEADER_AND_BODY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "SOAP builder found a child element other than header or body in envelope element"); + return AXIS2_FAILURE; + } + + return AXIS2_SUCCESS; + } + else if(element_level > 3) + { + if(soap_builder->processing_fault) + { + if(soap_builder->soap_version == AXIOM_SOAP11) + { + status = axiom_soap11_builder_helper_handle_event((axiom_soap11_builder_helper_t *) + soap_builder->builder_helper, env, om_element_node, element_level); + } + else if(soap_builder->soap_version == AXIOM_SOAP12) + { + status = axiom_soap12_builder_helper_handle_event((axiom_soap12_builder_helper_t *) + soap_builder->builder_helper, env, om_element_node, element_level); + } + else + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Unknown SOAP Version"); + status = AXIS2_FAILURE; + } + } + + /* if the node is <xop:Include> or MTOM message */ + else if(axutil_strcmp(ele_localname, AXIS2_XOP_INCLUDE) == 0) + { + return axiom_soap_builder_construct_xop_include(soap_builder, env, om_element_node); + } + + /* we don't need to consider any other elements at this level. */ + } + return status; +} + +static axis2_status_t +axiom_soap_builder_construct_soap_header( + axiom_soap_builder_t *soap_builder, + const axutil_env_t *env, + axiom_node_t *om_node) +{ + axiom_soap_header_t *soap_header = NULL; + if(soap_builder->header_present) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_SOAP_BUILDER_MULTIPLE_HEADERS_ENCOUNTERED, + AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "SOAP builder encountered multiple headers"); + return AXIS2_FAILURE; + } + if(soap_builder->body_present) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_SOAP_BUILDER_HEADER_BODY_WRONG_ORDER, + AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "SOAP builder encountered body element first and header next"); + return AXIS2_FAILURE; + } + + soap_builder->header_present = AXIS2_TRUE; + soap_header = axiom_soap_header_create(env); + if(!soap_header) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Unable to create SOAP Header"); + return AXIS2_FAILURE; + } + + axiom_soap_header_set_base_node(soap_header, env, om_node); + axiom_soap_envelope_set_header(soap_builder->soap_envelope, env, soap_header); + axiom_soap_header_set_builder(soap_header, env, soap_builder); + axiom_soap_header_set_soap_version(soap_header, env, soap_builder->soap_version); + + return AXIS2_SUCCESS; +} + +static axis2_status_t +axiom_soap_builder_construct_soap_body( + axiom_soap_builder_t *soap_builder, + const axutil_env_t *env, + axiom_node_t *om_node) +{ + axiom_soap_body_t *soap_body = NULL; + if(soap_builder->body_present) + { + AXIS2_ERROR_SET(env->error, + AXIS2_ERROR_SOAP_BUILDER_MULTIPLE_BODY_ELEMENTS_ENCOUNTERED, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "SOAP builder multiple body elements encountered"); + return AXIS2_FAILURE; + } + + soap_builder->body_present = AXIS2_TRUE; + soap_body = axiom_soap_body_create(env); + if(!soap_body) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Unable to create SOAP Body"); + return AXIS2_FAILURE; + } + + axiom_soap_body_set_base_node(soap_body, env, om_node); + axiom_soap_body_set_builder(soap_body, env, soap_builder); + axiom_soap_envelope_set_body(soap_builder->soap_envelope, env, soap_body); + + return AXIS2_SUCCESS; +} + +static axis2_status_t +axiom_soap_builder_construct_soap_fault( + axiom_soap_builder_t *soap_builder, + const axutil_env_t *env, + axiom_node_t *om_node) +{ + axiom_soap_body_t *soap_body = NULL; + axiom_soap_fault_t *soap_fault = NULL; + axiom_namespace_t *env_ns = NULL; + + env_ns = axiom_soap_envelope_get_namespace(soap_builder->soap_envelope, env); + if(!env_ns) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Cannot get soap envelope namespace"); + return AXIS2_FAILURE; + } + + soap_body = axiom_soap_envelope_get_body(soap_builder->soap_envelope, env); + if(!soap_body) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Cannot get soap body from OM Envelope"); + return AXIS2_FAILURE; + } + + soap_fault = axiom_soap_fault_create(env); + if(!soap_fault) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Cannot create SOAP Fault structure"); + return AXIS2_FAILURE; + } + + axiom_soap_fault_set_base_node(soap_fault, env, om_node); + axiom_soap_body_set_fault(soap_body, env, soap_fault); + axiom_soap_fault_set_builder(soap_fault, env, soap_builder); + soap_builder->processing_fault = AXIS2_TRUE; + soap_builder->processing_mandatory_fault_elements = AXIS2_TRUE; + + if(axutil_strcmp(AXIOM_SOAP12_SOAP_ENVELOPE_NAMESPACE_URI, + axiom_namespace_get_uri(env_ns, env)) == 0) + { + soap_builder->builder_helper = axiom_soap12_builder_helper_create(env, soap_builder); + } + else if(axutil_strcmp(AXIOM_SOAP11_SOAP_ENVELOPE_NAMESPACE_URI, + axiom_namespace_get_uri(env_ns, env)) == 0) + { + soap_builder->builder_helper = axiom_soap11_builder_helper_create( + env, soap_builder,soap_builder->om_builder); + } + + if(!soap_builder->builder_helper) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Cannot create soap builder helper"); + return AXIS2_FAILURE; + } + return AXIS2_SUCCESS; +} + +static axis2_status_t +axiom_soap_builder_construct_xop_include( + axiom_soap_builder_t *soap_builder, + const axutil_env_t *env, + axiom_node_t *om_element_node) +{ + axiom_namespace_t *ns = NULL; + axis2_char_t *uri = NULL; + axiom_element_t *om_element = NULL; + axutil_qname_t *qname = NULL; + axis2_char_t *id = NULL; + + om_element = (axiom_element_t *)axiom_node_get_data_element(om_element_node, env); + ns = axiom_element_get_namespace(om_element, env, om_element_node); + if(!ns) + { + /* this is not a xop:include element. so, we can safely return success */ + return AXIS2_SUCCESS; + } + + uri = axiom_namespace_get_uri(ns, env); + if((!uri) || (axutil_strcmp(uri, AXIS2_XOP_NAMESPACE_URI) != 0)) + { + /* this is not a xop:include element. so, we can safely return success */ + return AXIS2_SUCCESS; + } + + qname = axutil_qname_create(env, "href", NULL, NULL); + if(!qname) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Cannot create qname with value href"); + return AXIS2_FAILURE; + } + + id = axiom_element_get_attribute_value(om_element, env, qname); + axutil_qname_free(qname, env); + if(!id) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Cannot get href ID of the xop:include element"); + return AXIS2_FAILURE; + } + + if(!axutil_strstr(id, "cid:")) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "ID of xop:include doesn't include 'cid:' part"); + return AXIS2_FAILURE; + } + + /* everything looks fine, so recursively build the OM tree, so that we can get data handlers */ + while(!axiom_node_is_complete(om_element_node, env)) + { + axiom_stax_builder_next_with_token(soap_builder->om_builder, env); + } + + if(soap_builder->mime_body_parts) + { + axiom_data_handler_t *data_handler = NULL; + axis2_char_t *id_decoded = NULL; + axiom_text_t *data_text = NULL; + axiom_node_t *data_om_node = NULL; + axiom_node_t *parent = NULL; + + /* Get the value of href id, after "cid:" */ + id += 4; + id_decoded = axutil_strdup(env, id); + axutil_url_decode(env, id_decoded, id_decoded); + + /* Find the data handler of given xop:include */ + data_handler = (axiom_data_handler_t *)axutil_hash_get( + soap_builder-> mime_body_parts, (void *)id_decoded, AXIS2_HASH_KEY_STRING); + if(!data_handler) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Cannot find data handler corresponding to id %s", id_decoded); + AXIS2_FREE(env->allocator, id_decoded); + return AXIS2_FAILURE; + } + + /* remove the <xop:Include> element, and add the data handler as the child of + * xop:include's parent */ + parent = axiom_node_get_parent(om_element_node, env); + axiom_node_free_tree(om_element_node, env); + data_text = axiom_text_create_with_data_handler(env, parent, data_handler, &data_om_node); + axiom_text_set_content_id(data_text, env, id_decoded); + axiom_stax_builder_set_lastnode(soap_builder->om_builder,env, parent); + AXIS2_FREE(env->allocator, id_decoded); + } + else + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Cannot find mime_body_part in soap builder"); + return AXIS2_FAILURE; + } + + return AXIS2_SUCCESS; +} + +/* check whether the namespace of given node is either SOAP11 or SOAP12 namespace */ +static axis2_status_t +axiom_soap_builder_process_namespace_data( + axiom_soap_builder_t * soap_builder, + const axutil_env_t * env, + axiom_node_t * om_node) +{ + axiom_element_t *om_ele = NULL; + axiom_namespace_t *om_ns = NULL; + + om_ele = (axiom_element_t *)axiom_node_get_data_element(om_node, env); + om_ns = axiom_element_get_namespace(om_ele, env, om_node); + if(om_ns) + { + axis2_char_t *ns_uri = NULL; + ns_uri = axiom_namespace_get_uri(om_ns, env); + if(ns_uri) + { + if((axutil_strcmp(ns_uri, AXIOM_SOAP11_SOAP_ENVELOPE_NAMESPACE_URI) == 0) + || (axutil_strcmp(ns_uri, AXIOM_SOAP12_SOAP_ENVELOPE_NAMESPACE_URI) == 0)) + { + return AXIS2_SUCCESS; + } + } + } + + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_SOAP_NAMESPACE_URI, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Invalid SOAP Namespace URI"); + return AXIS2_FAILURE; +} + +static axis2_status_t +axiom_soap_builder_identify_soap_version( + axiom_soap_builder_t * soap_builder, + const axutil_env_t * env, + const axis2_char_t * soap_version_uri_from_transport) +{ + axiom_namespace_t *om_ns = NULL; + axiom_node_t *envelope_node = NULL; + axiom_element_t *om_ele = NULL; + axis2_char_t *ns_uri = NULL; + + AXIS2_PARAM_CHECK(env->error, soap_version_uri_from_transport, AXIS2_FAILURE); + if(!soap_builder) + { + return AXIS2_FAILURE; + } + soap_builder->soap_envelope = axiom_soap_builder_get_soap_envelope(soap_builder, env); + + if(soap_builder->soap_envelope == NULL) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_SOAP_MESSAGE_DOES_NOT_CONTAIN_AN_ENVELOPE, + AXIS2_FAILURE); + AXIS2_LOG_CRITICAL(env->log, AXIS2_LOG_SI, + "SOAP message does not have a SOAP envelope element "); + return AXIS2_FAILURE; + } + + envelope_node = axiom_soap_envelope_get_base_node(soap_builder->soap_envelope, env); + + if(!envelope_node) + { + return AXIS2_FAILURE; + } + om_ele = (axiom_element_t *)axiom_node_get_data_element(envelope_node, env); + if(!om_ele) + { + return AXIS2_FAILURE; + } + om_ns = axiom_element_get_namespace(om_ele, env, envelope_node); + if(!om_ns) + { + return AXIS2_FAILURE; + } + ns_uri = axiom_namespace_get_uri(om_ns, env); + + if(ns_uri) + { + if(soap_version_uri_from_transport + && axutil_strcmp(soap_version_uri_from_transport, ns_uri) != 0) + { + AXIS2_ERROR_SET(env->error, + AXIS2_ERROR_TRANSPORT_LEVEL_INFORMATION_DOES_NOT_MATCH_WITH_SOAP, AXIS2_FAILURE); + + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "AXIS2_ERROR_TRANSPORT_LEVEL_INFORMATION_DOES_NOT_MATCH_WITH_SOAP"); + return AXIS2_FAILURE; + } + if(axutil_strcmp(AXIOM_SOAP11_SOAP_ENVELOPE_NAMESPACE_URI, ns_uri) == 0) + { + soap_builder->soap_version = AXIOM_SOAP11; + + AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "Identified soap version is soap11"); + + axiom_soap_envelope_set_soap_version_internal(soap_builder-> soap_envelope, env, + soap_builder-> soap_version); + + return AXIS2_SUCCESS; + } + else if(axutil_strcmp(AXIOM_SOAP12_SOAP_ENVELOPE_NAMESPACE_URI, ns_uri) == 0) + { + soap_builder->soap_version = AXIOM_SOAP12; + + AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "identified soap version is soap12"); + + axiom_soap_envelope_set_soap_version_internal(soap_builder-> soap_envelope, env, + soap_builder-> soap_version); + + return AXIS2_SUCCESS; + } + } + return AXIS2_FAILURE; +} + +static axis2_status_t +axiom_soap_builder_parse_headers( + axiom_soap_builder_t * soap_builder, + const axutil_env_t * env) +{ + axiom_node_t *om_node = NULL; + axiom_soap_header_t *soap_header = NULL; + int status = AXIS2_SUCCESS; + if(!soap_builder) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_NULL_PARAM, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Soap Builder is NULL"); + return AXIS2_FAILURE; + } + if(!soap_builder->soap_envelope) + { + return AXIS2_FAILURE; + } + soap_header = axiom_soap_envelope_get_header(soap_builder->soap_envelope, env); + + if(soap_header) + { + om_node = axiom_soap_header_get_base_node(soap_header, env); + if(om_node) + { + while(!axiom_node_is_complete(om_node, env)) + { + status = axiom_soap_builder_next(soap_builder, env); + if(status == AXIS2_FAILURE) + return AXIS2_FAILURE; + } + /*HACK: to fix AXIS2C-129 - Samisa */ + /* + axiom_stax_builder_set_element_level( + soap_builder->om_builder, env, 1); + */ + } + } + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_builder_set_bool_processing_mandatory_fault_elements( + axiom_soap_builder_t * soap_builder, + const axutil_env_t * env, + axis2_bool_t value) +{ + soap_builder->processing_mandatory_fault_elements = value; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_builder_set_processing_detail_elements( + axiom_soap_builder_t * soap_builder, + const axutil_env_t * env, + axis2_bool_t value) +{ + soap_builder->processing_detail_elements = value; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +axiom_soap_builder_is_processing_detail_elements( + axiom_soap_builder_t * soap_builder, + const axutil_env_t * env) +{ + return soap_builder->processing_detail_elements; +} + +AXIS2_EXTERN int AXIS2_CALL +axiom_soap_builder_get_soap_version( + axiom_soap_builder_t * soap_builder, + const axutil_env_t * env) +{ + return soap_builder->soap_version; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_builder_set_mime_body_parts( + axiom_soap_builder_t * soap_builder, + const axutil_env_t * env, + axutil_hash_t * map) +{ + soap_builder->mime_body_parts = map; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axutil_hash_t *AXIS2_CALL +axiom_soap_builder_get_mime_body_parts( + axiom_soap_builder_t * builder, + const axutil_env_t * env) +{ + return builder->mime_body_parts; +} + +AXIS2_EXTERN void AXIS2_CALL +axiom_soap_builder_set_mime_parser( + axiom_soap_builder_t * builder, + const axutil_env_t * env, + axiom_mime_parser_t *mime_parser) +{ + builder->mime_parser = mime_parser; +} + +AXIS2_EXTERN void AXIS2_CALL +axiom_soap_builder_set_callback_function( + axiom_soap_builder_t * builder, + const axutil_env_t * env, + AXIS2_READ_INPUT_CALLBACK callback) +{ + builder->callback = callback; +} + +AXIS2_EXTERN void AXIS2_CALL +axiom_soap_builder_set_callback_ctx( + axiom_soap_builder_t * builder, + const axutil_env_t * env, + void *callback_ctx) +{ + builder->callback_ctx = callback_ctx; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_builder_create_attachments( + axiom_soap_builder_t * builder, + const axutil_env_t * env, + void *user_param, + axis2_char_t *callback_name) +{ + axutil_hash_t *attachments_map = NULL; + axis2_char_t *mime_boundary = NULL; + + if(builder->mime_parser) + { + if(builder->callback_ctx) + { + mime_boundary = axiom_mime_parser_get_mime_boundary(builder->mime_parser, env); + + if(mime_boundary) + { + if(callback_name) + { + axiom_mime_parser_set_caching_callback_name(builder->mime_parser, env, + callback_name); + } + attachments_map = axiom_mime_parser_parse_for_attachments(builder->mime_parser, + env, builder->callback, builder->callback_ctx, mime_boundary, user_param); + + if(attachments_map) + { + builder->mime_body_parts = attachments_map; + return AXIS2_SUCCESS; + } + else + { + return AXIS2_FAILURE; + } + } + else + { + return AXIS2_FAILURE; + } + } + else + { + return AXIS2_FAILURE; + } + } + else + { + return AXIS2_FAILURE; + } +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +axiom_soap_builder_replace_xop( + axiom_soap_builder_t * builder, + const axutil_env_t * env, + axiom_node_t *om_element_node, + axiom_element_t *om_element) +{ + axiom_namespace_t *ns = NULL; + axis2_bool_t is_replaced = AXIS2_FALSE; + + ns = axiom_element_get_namespace(om_element, env, om_element_node); + if(ns) + { + axis2_char_t *uri = axiom_namespace_get_uri(ns, env); + if(uri) + { + if(axutil_strcmp(uri, AXIS2_XOP_NAMESPACE_URI) == 0) + { + axutil_qname_t *qname = NULL; + qname = axutil_qname_create(env, "href", NULL, NULL); + if(qname) + { + axis2_char_t *id = NULL; + id = axiom_element_get_attribute_value(om_element, env, qname); + if(id) + { + axis2_char_t *pos = NULL; + pos = axutil_strstr(id, "cid:"); + if(pos) + { + axiom_data_handler_t *data_handler = NULL; + id += 4; + + if(builder->mime_body_parts) + { + + axis2_char_t *id_decoded = NULL; + + id_decoded = axutil_strdup(env, id); + + axutil_url_decode(env, id_decoded, id_decoded); + + data_handler = (axiom_data_handler_t *)axutil_hash_get( + builder-> mime_body_parts, (void *)id_decoded, + AXIS2_HASH_KEY_STRING); + if(data_handler) + { + axiom_text_t *data_text = NULL; + axiom_node_t *data_om_node = NULL; + axiom_node_t *parent = NULL; + + parent = axiom_node_get_parent(om_element_node, env); + + /*remove the <xop:Include> element */ + axiom_node_free_tree(om_element_node, env); + + data_text = axiom_text_create_with_data_handler(env, parent, + data_handler, &data_om_node); + + axiom_text_set_content_id(data_text, env, id_decoded); + /*axiom_stax_builder_set_lastnode + (soap_builder->om_builder, env, + parent);*/ + is_replaced = AXIS2_TRUE; + } + if(id_decoded) + { + AXIS2_FREE(env->allocator, id_decoded); + } + } + } + } + } + axutil_qname_free(qname, env); + } + } + } + + return is_replaced; +} + +AXIS2_EXTERN axiom_stax_builder_t *AXIS2_CALL +axiom_soap_builder_get_om_builder( + axiom_soap_builder_t * soap_builder, + const axutil_env_t * env) +{ + if(!soap_builder) + { + return NULL; + } + return soap_builder->om_builder; +} + diff --git a/axiom/src/soap/soap_envelope.c b/axiom/src/soap/soap_envelope.c new file mode 100644 index 0000000..48e10f7 --- /dev/null +++ b/axiom/src/soap/soap_envelope.c @@ -0,0 +1,631 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "_axiom_soap_envelope.h" +#include <axiom_soap_body.h> +#include <axiom_soap_header.h> +#include <axiom_soap_header_block.h> +#include <axutil_hash.h> +#include <axiom_soap_const.h> +#include <axiom_soap_builder.h> +#include <axiom_soap_fault_code.h> +#include <axiom_soap_fault_reason.h> +#include <axiom_soap_fault_detail.h> +#include <axiom_soap_fault_role.h> +#include <axiom_soap_fault_value.h> +#include <axiom_soap_fault_text.h> +#include <axiom_namespace_internal.h> + +struct axiom_soap_envelope +{ + /* corresponding om element node */ + axiom_node_t *om_ele_node; + /* soap version */ + int soap_version; + /* soap header */ + axiom_soap_header_t *header; + /* soap body */ + axiom_soap_body_t *body; + /* pointer to soap builder */ + axiom_soap_builder_t *soap_builder; + int ref; +}; +static axis2_status_t +check_and_set_soap_version( + axiom_soap_envelope_t * soap_envelope, + const axutil_env_t * env, + axiom_namespace_t * ns); + +AXIS2_EXTERN axiom_soap_envelope_t *AXIS2_CALL +axiom_soap_envelope_create_null( + const axutil_env_t * env) +{ + axiom_soap_envelope_t *soap_envelope = NULL; + + soap_envelope = (axiom_soap_envelope_t *)AXIS2_MALLOC(env->allocator, + sizeof(axiom_soap_envelope_t)); + if(!soap_envelope) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory. Cannot create a SOAP Envelope"); + return NULL; + } + soap_envelope->om_ele_node = NULL; + soap_envelope->soap_version = AXIOM_SOAP12; + soap_envelope->header = NULL; + soap_envelope->body = NULL; + soap_envelope->ref = 1; + soap_envelope->soap_builder = NULL; + + return soap_envelope; +} + +AXIS2_EXTERN axiom_soap_envelope_t *AXIS2_CALL +axiom_soap_envelope_create( + const axutil_env_t * env, + axiom_namespace_t * ns) +{ + axiom_soap_envelope_t *soap_envelope = NULL; + axiom_element_t *ele = NULL; + int status = AXIS2_SUCCESS; + + AXIS2_PARAM_CHECK(env->error, ns, NULL); + + soap_envelope = axiom_soap_envelope_create_null(env); + if(!soap_envelope) + { + return NULL; + } + status = check_and_set_soap_version(soap_envelope, env, ns); + if(status == AXIS2_FAILURE) + { + AXIS2_FREE(env->allocator, soap_envelope); + return NULL; + } + + ele = axiom_element_create(env, NULL, AXIOM_SOAP_ENVELOPE_LOCAL_NAME, ns, + &(soap_envelope->om_ele_node)); + if(!ele) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory. Cannot create a SOAP element"); + axiom_soap_envelope_free(soap_envelope, env); + return NULL; + } + return soap_envelope; +} + +AXIS2_EXTERN axiom_soap_envelope_t *AXIS2_CALL +axiom_soap_envelope_create_with_soap_version_prefix( + const axutil_env_t * env, + int soap_version, + const axis2_char_t * prefix) +{ + axiom_namespace_t *ns = NULL; + const axis2_char_t *ns_prefix = NULL; + const axis2_char_t *ns_uri = NULL; + + if(soap_version == AXIOM_SOAP11) + { + ns_uri = AXIOM_SOAP11_SOAP_ENVELOPE_NAMESPACE_URI; + } + else if(soap_version == AXIOM_SOAP12) + { + ns_uri = AXIOM_SOAP12_SOAP_ENVELOPE_NAMESPACE_URI; + } + else + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_SOAP_VERSION, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Invalid SOAP version"); + return NULL; + } + if(!prefix || axutil_strcmp(prefix, "") == 0) + { + ns_prefix = AXIOM_SOAP_DEFAULT_NAMESPACE_PREFIX; + } + else + { + ns_prefix = prefix; + } + + ns = axiom_namespace_create(env, ns_uri, ns_prefix); + if(!ns) + return NULL; + return axiom_soap_envelope_create(env, ns); +} + +AXIS2_EXTERN void AXIS2_CALL +axiom_soap_envelope_free( + axiom_soap_envelope_t * soap_envelope, + const axutil_env_t * env) +{ + if(--(soap_envelope->ref) > 0) + { + return; + } + if(soap_envelope->header) + { + axiom_soap_header_free(soap_envelope->header, env); + } + if(soap_envelope->body) + { + axiom_soap_body_free(soap_envelope->body, env); + } + if(soap_envelope->om_ele_node) + { + if(soap_envelope->soap_builder) + { + axiom_soap_builder_free(soap_envelope->soap_builder, env); + soap_envelope->om_ele_node = NULL; + } + else + { + axiom_node_free_tree(soap_envelope->om_ele_node, env); + } + } + + AXIS2_FREE(env->allocator, soap_envelope); + return; +} + +AXIS2_EXTERN axiom_node_t *AXIS2_CALL +axiom_soap_envelope_get_base_node( + axiom_soap_envelope_t * soap_envelope, + const axutil_env_t * env) +{ + return soap_envelope->om_ele_node; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_envelope_set_base_node( + axiom_soap_envelope_t * soap_envelope, + const axutil_env_t * env, + axiom_node_t * node) +{ + AXIS2_PARAM_CHECK(env->error, node, AXIS2_FAILURE); + + if(axiom_node_get_node_type(node, env) != AXIOM_ELEMENT) + { + AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_INVALID_BASE_TYPE, AXIS2_FAILURE); + return AXIS2_FAILURE; + } + soap_envelope->om_ele_node = node; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN int AXIS2_CALL +axiom_soap_envelope_get_soap_version( + axiom_soap_envelope_t * soap_envelope, + const axutil_env_t * env) +{ + return soap_envelope->soap_version; +} + +/** this is an internal function */ +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_envelope_set_soap_version_internal( + axiom_soap_envelope_t * soap_envelope, + const axutil_env_t * env, + int soap_version) +{ + soap_envelope->soap_version = soap_version; + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axiom_soap_header_t *AXIS2_CALL +axiom_soap_envelope_get_header( + axiom_soap_envelope_t * soap_envelope, + const axutil_env_t * env) +{ + int status = AXIS2_SUCCESS; + + if(soap_envelope->header) + { + return soap_envelope->header; + } + else if(soap_envelope->soap_builder) + { + while(!(soap_envelope->header) && !(soap_envelope->body) && !axiom_node_is_complete( + soap_envelope->om_ele_node, env)) + { + status = axiom_soap_builder_next(soap_envelope->soap_builder, env); + if(status == AXIS2_FAILURE) + { + break; + } + } + } + + return soap_envelope->header; +} + +AXIS2_EXTERN axiom_soap_header_block_t *AXIS2_CALL +axiom_soap_envelope_add_header( + axiom_soap_envelope_t * soap_envelope, + const axutil_env_t * env, + axis2_char_t * namespace_uri, + axis2_char_t * name) +{ + axiom_namespace_t *ns = NULL; + + if(!soap_envelope->header) + { + return NULL; + } + if(namespace_uri) + { + ns = axiom_namespace_create(env, namespace_uri, NULL); + } + + return axiom_soap_header_block_create_with_parent(env, name, ns, soap_envelope->header); +} + +AXIS2_EXTERN axiom_soap_body_t *AXIS2_CALL +axiom_soap_envelope_get_body( + axiom_soap_envelope_t * soap_envelope, + const axutil_env_t * env) +{ + int status = AXIS2_SUCCESS; + + if(soap_envelope->body) + { + return soap_envelope->body; + } + else if(soap_envelope->soap_builder) + { + while(!(soap_envelope->body) && !axiom_node_is_complete(soap_envelope->om_ele_node, env)) + { + status = axiom_soap_builder_next(soap_envelope->soap_builder, env); + if(status == AXIS2_FAILURE) + { + return NULL; + } + } + } + return soap_envelope->body; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_envelope_serialize( + axiom_soap_envelope_t * soap_envelope, + const axutil_env_t * env, + axiom_output_t * om_output, + axis2_bool_t cache) +{ + AXIS2_PARAM_CHECK(env->error, soap_envelope, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, om_output, AXIS2_FAILURE); + + /* + if soap version is soap11 we modify the soap fault part. + This is done because the builder construct a soap12 fault all + the time. So when serializing if the soap version is soap11 + we should convert it back to soap11 fault + */ + if(soap_envelope->soap_version == AXIOM_SOAP11) + { + axiom_soap_body_t *soap_body = NULL; + soap_body = axiom_soap_envelope_get_body(soap_envelope, env); + axiom_soap_body_convert_fault_to_soap11(soap_body, env); + } + /* write the xml version and encoding + These should be set to om output before calling the serialize function + Otherwise default values will be written + */ + axiom_output_get_content_type(om_output, env); + return axiom_node_serialize(soap_envelope->om_ele_node, env, om_output); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_envelope_set_body( + axiom_soap_envelope_t * soap_envelope, + const axutil_env_t * env, + axiom_soap_body_t * body) +{ + + if(!(soap_envelope->body)) + { + soap_envelope->body = body; + } + else + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "trying to set a soap bedy to soap_envelope when a soap body alrady exists"); + return AXIS2_FAILURE; + } + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_envelope_set_header( + axiom_soap_envelope_t * soap_envelope, + const axutil_env_t * env, + axiom_soap_header_t * header) +{ + + if(!(soap_envelope->header)) + { + soap_envelope->header = header; + } + else + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + " trying to set a soap header to soap_envelope when a soap header alrady exists"); + return AXIS2_FAILURE; + } + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axiom_namespace_t *AXIS2_CALL +axiom_soap_envelope_get_namespace( + axiom_soap_envelope_t * soap_envelope, + const axutil_env_t * env) +{ + + if(soap_envelope->om_ele_node) + { + axiom_element_t *ele = NULL; + if(axiom_node_get_node_type(soap_envelope->om_ele_node, env) == AXIOM_ELEMENT) + { + ele = (axiom_element_t *)axiom_node_get_data_element(soap_envelope-> om_ele_node, env); + if(ele) + { + return axiom_element_get_namespace(ele, env, soap_envelope->om_ele_node); + } + } + } + return NULL; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_envelope_set_builder( + axiom_soap_envelope_t * soap_envelope, + const axutil_env_t * env, + axiom_soap_builder_t * soap_builder) +{ + AXIS2_PARAM_CHECK(env->error, soap_builder, AXIS2_FAILURE); + soap_envelope->soap_builder = soap_builder; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axiom_soap_builder_t *AXIS2_CALL +axiom_soap_envelope_get_builder( + axiom_soap_envelope_t * soap_envelope, + const axutil_env_t * env) +{ + if(!soap_envelope) + { + return NULL; + } + return soap_envelope->soap_builder; +} + +AXIS2_EXTERN axiom_soap_envelope_t *AXIS2_CALL +axiom_soap_envelope_create_default_soap_envelope( + const axutil_env_t * env, + int soap_version) +{ + axiom_soap_envelope_t *soap_envelope = NULL; + axiom_soap_header_t *soap_header = NULL; + axiom_soap_body_t *soap_body = NULL; + axiom_namespace_t *om_ns = NULL; + + if(soap_version == AXIOM_SOAP11) + { + om_ns = axiom_namespace_create(env, AXIOM_SOAP11_SOAP_ENVELOPE_NAMESPACE_URI, + AXIOM_SOAP_DEFAULT_NAMESPACE_PREFIX); + if(!om_ns) + { + return NULL; + } + soap_envelope = axiom_soap_envelope_create(env, om_ns); + + soap_header = axiom_soap_header_create_with_parent(env, soap_envelope); + soap_body = axiom_soap_body_create_with_parent(env, soap_envelope); + soap_envelope->body = soap_body; + soap_envelope->header = soap_header; + return soap_envelope; + } + else if(soap_version == AXIOM_SOAP12) + { + om_ns = axiom_namespace_create(env, AXIOM_SOAP12_SOAP_ENVELOPE_NAMESPACE_URI, + AXIOM_SOAP_DEFAULT_NAMESPACE_PREFIX); + if(!om_ns) + { + return NULL; + } + soap_envelope = axiom_soap_envelope_create(env, om_ns); + + soap_header = axiom_soap_header_create_with_parent(env, soap_envelope); + soap_body = axiom_soap_body_create_with_parent(env, soap_envelope); + soap_envelope->body = soap_body; + soap_envelope->header = soap_header; + return soap_envelope; + } + + AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_INVALID_SOAP_VERSION, AXIS2_FAILURE); + return NULL; +} + +AXIS2_EXTERN axiom_soap_envelope_t *AXIS2_CALL +axiom_soap_envelope_create_default_soap_fault_envelope( + const axutil_env_t * env, + const axis2_char_t * code_value, + const axis2_char_t * reason_text, + const int soap_version, + axutil_array_list_t * sub_codes, + axiom_node_t * detail_node) +{ + axiom_soap_envelope_t *soap_envelope = NULL; + axiom_soap_body_t *soap_body = NULL; + axiom_soap_fault_t *fault = NULL; + + if(AXIOM_SOAP11 != soap_version && AXIOM_SOAP12 != soap_version) + { + AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_INVALID_SOAP_VERSION, AXIS2_FAILURE); + return NULL; + } + + soap_envelope = axiom_soap_envelope_create_default_soap_envelope(env, soap_version); + if(!soap_envelope) + { + return NULL; + } + + soap_body = axiom_soap_envelope_get_body(soap_envelope, env); + if(!soap_body) + { + axiom_soap_envelope_free(soap_envelope, env); + return NULL; + } + fault = axiom_soap_fault_create_default_fault(env, soap_body, code_value, reason_text, + soap_version); + if(!fault) + { + axiom_soap_envelope_free(soap_envelope, env); + return NULL; + } + + if(sub_codes) + { + int i = 0; + axiom_soap_fault_code_t *fault_code = NULL; + fault_code = axiom_soap_fault_get_code(fault, env); + if(fault_code) + { + for(i = 0; i < axutil_array_list_size(sub_codes, env); i++) + { + axis2_char_t *sub_code = (axis2_char_t *)axutil_array_list_get(sub_codes, env, i); + if(sub_code) + { + axiom_soap_fault_sub_code_create_with_parent_value(env, fault_code, sub_code); + } + } + } + } + + if(detail_node) + { + axiom_soap_fault_detail_t *detail = axiom_soap_fault_detail_create_with_parent(env, fault); + if(detail) + { + axiom_soap_fault_detail_add_detail_entry(detail, env, detail_node); + } + } + + return soap_envelope; + +} + +static axis2_status_t +check_and_set_soap_version( + axiom_soap_envelope_t * soap_envelope, + const axutil_env_t * env, + axiom_namespace_t * ns) +{ + axis2_char_t *uri = NULL; + if(!soap_envelope) + { + return AXIS2_FAILURE; + } + if(!ns) + { + return AXIS2_FAILURE; + } + uri = axiom_namespace_get_uri(ns, env); + if(!uri) + { + return AXIS2_FAILURE; + } + if(axutil_strcmp(uri, AXIOM_SOAP11_SOAP_ENVELOPE_NAMESPACE_URI) == 0) + { + soap_envelope->soap_version = AXIOM_SOAP11; + return AXIS2_SUCCESS; + } + else if(axutil_strcmp(uri, AXIOM_SOAP12_SOAP_ENVELOPE_NAMESPACE_URI) == 0) + { + soap_envelope->soap_version = AXIOM_SOAP12; + return AXIS2_SUCCESS; + } + else + { + AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_INVALID_SOAP_NAMESPACE_URI, AXIS2_FAILURE); + } + return AXIS2_FAILURE; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_envelope_set_soap_version( + axiom_soap_envelope_t * soap_envelope, + const axutil_env_t * env, + int soap_version) +{ + axiom_element_t *env_ele = NULL; + axiom_namespace_t *env_ns = NULL; + const axis2_char_t *ns_uri = NULL; + int status = AXIS2_SUCCESS; + + if(soap_version == AXIOM_SOAP11) + { + ns_uri = AXIOM_SOAP11_SOAP_ENVELOPE_NAMESPACE_URI; + } + else if(soap_version == AXIOM_SOAP12) + { + ns_uri = AXIOM_SOAP12_SOAP_ENVELOPE_NAMESPACE_URI; + } + else + { + return AXIS2_FAILURE; + } + + env_ele = (axiom_element_t *)axiom_node_get_data_element(soap_envelope->om_ele_node, env); + if(!env_ele) + { + return AXIS2_FAILURE; + } + + env_ns = axiom_element_get_namespace(env_ele, env, soap_envelope->om_ele_node); + if(!env_ns) + { + return AXIS2_FAILURE; + } + status = axiom_namespace_set_uri(env_ns, env, ns_uri); + if(status == AXIS2_SUCCESS) + { + axiom_soap_envelope_set_soap_version_internal(soap_envelope, env, soap_version); + return AXIS2_SUCCESS; + } + return AXIS2_FAILURE; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_envelope_increment_ref( + axiom_soap_envelope_t * envelope, + const axutil_env_t * env) +{ + envelope->ref++; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN struct axiom_soap_builder *AXIS2_CALL +axiom_soap_envelope_get_soap_builder( + axiom_soap_envelope_t * envelope, + const axutil_env_t * env) +{ + return envelope->soap_builder; +} + diff --git a/axiom/src/soap/soap_fault.c b/axiom/src/soap/soap_fault.c new file mode 100644 index 0000000..7ee69a8 --- /dev/null +++ b/axiom/src/soap/soap_fault.c @@ -0,0 +1,630 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "_axiom_soap_fault.h" +#include <axiom_soap_const.h> +#include "_axiom_soap_body.h" +#include <axiom_node.h> +#include <axiom_element.h> +#include <axiom_soap_fault_code.h> +#include <axiom_soap_fault_detail.h> +#include <axiom_soap_fault_value.h> +#include <axiom_soap_fault_text.h> +#include <axiom_soap_fault_reason.h> +#include <axiom_soap_fault_role.h> +#include <axiom_soap_fault_node.h> +#include <axiom_soap_builder.h> + +struct axiom_soap_fault +{ + /* om element node corresponding to soap soap_fault */ + axiom_node_t *om_ele_node; + + /* soap soap_fault code sub element */ + axiom_soap_fault_code_t *fcode; + /* soap soap_fault reason sub element */ + axiom_soap_fault_reason_t *freason; + /* soap soap_fault node sub element */ + axiom_soap_fault_node_t *fnode; + /* soap soap_fault role sub element */ + axiom_soap_fault_role_t *frole; + /* soap soap_fault detail sub element */ + axiom_soap_fault_detail_t *fdetail; + + axis2_char_t *exception; + /* reference to soap builder */ + axiom_soap_builder_t *soap_builder; + + int soap_version; +}; + +AXIS2_EXTERN axiom_soap_fault_t *AXIS2_CALL +axiom_soap_fault_create( + const axutil_env_t * env) +{ + axiom_soap_fault_t *soap_fault = NULL; + soap_fault = (axiom_soap_fault_t *)AXIS2_MALLOC(env->allocator, sizeof(axiom_soap_fault_t)); + if(!soap_fault) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory. Cannot create a SOAP fault"); + return NULL; + } + soap_fault->exception = NULL; + soap_fault->fcode = NULL; + soap_fault->fdetail = NULL; + soap_fault->fnode = NULL; + soap_fault->freason = NULL; + soap_fault->frole = NULL; + soap_fault->om_ele_node = NULL; + soap_fault->soap_builder = NULL; + soap_fault->soap_version = -1; + return soap_fault; +} + +AXIS2_EXTERN axiom_soap_fault_t *AXIS2_CALL +axiom_soap_fault_create_with_parent( + const axutil_env_t * env, + axiom_soap_body_t * body) +{ + axiom_soap_fault_t *soap_fault = NULL; + axiom_element_t *this_ele = NULL; + axiom_node_t *this_node = NULL; + axiom_node_t *parent_node = NULL; + axiom_element_t *parent_ele = NULL; + axiom_namespace_t *parent_ns = NULL; + + AXIS2_PARAM_CHECK(env->error, body, NULL); + + soap_fault = axiom_soap_fault_create(env); + if(!soap_fault) + { + return NULL; + } + parent_node = axiom_soap_body_get_base_node(body, env); + if(!parent_node) + { + AXIS2_FREE(env->allocator, soap_fault); + return NULL; + } + soap_fault->soap_version = axiom_soap_body_get_soap_version(body, env); + + parent_ele = (axiom_element_t *)axiom_node_get_data_element(parent_node, env); + if(!parent_ele) + { + AXIS2_FREE(env->allocator, soap_fault); + return NULL; + } + parent_ns = axiom_element_get_namespace(parent_ele, env, parent_node); + + this_ele = axiom_element_create(env, parent_node, AXIOM_SOAP_FAULT_LOCAL_NAME, parent_ns, + &this_node); + if(!this_ele) + { + AXIS2_FREE(env->allocator, soap_fault); + return NULL; + } + + soap_fault->om_ele_node = this_node; + axiom_soap_body_set_fault(body, env, soap_fault); + return soap_fault; +} + +AXIS2_EXTERN axiom_soap_fault_t *AXIS2_CALL +axiom_soap_fault_create_with_exception( + const axutil_env_t * env, + axiom_soap_body_t * body, + axis2_char_t * exception) +{ + axiom_soap_fault_t *soap_fault = NULL; + axis2_status_t status = AXIS2_SUCCESS; + AXIS2_PARAM_CHECK(env->error, body, NULL); + AXIS2_PARAM_CHECK(env->error, exception, NULL); + soap_fault = axiom_soap_fault_create_with_parent(env, body); + if(!soap_fault) + { + return NULL; + } + status = axiom_soap_fault_set_exception(soap_fault, env, exception); + if(status == AXIS2_FAILURE) + { + axiom_soap_fault_free(soap_fault, env); + return NULL; + } + return soap_fault; +} + +AXIS2_EXTERN void AXIS2_CALL +axiom_soap_fault_free( + axiom_soap_fault_t * soap_fault, + const axutil_env_t * env) +{ + + if(soap_fault->fcode) + { + axiom_soap_fault_code_free(soap_fault->fcode, env); + soap_fault->fcode = NULL; + } + if(soap_fault->fdetail) + { + axiom_soap_fault_detail_free(soap_fault->fdetail, env); + soap_fault->fdetail = NULL; + } + if(soap_fault->fnode) + { + axiom_soap_fault_node_free(soap_fault->fnode, env); + soap_fault->fnode = NULL; + } + if(soap_fault->freason) + { + axiom_soap_fault_reason_free(soap_fault->freason, env); + soap_fault->freason = NULL; + } + if(soap_fault->frole) + { + axiom_soap_fault_role_free(soap_fault->frole, env); + soap_fault->frole = NULL; + } + AXIS2_FREE(env->allocator, soap_fault); + soap_fault = NULL; + return; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_fault_set_code( + axiom_soap_fault_t * soap_fault, + const axutil_env_t * env, + axiom_soap_fault_code_t * code) +{ + AXIS2_PARAM_CHECK(env->error, code, AXIS2_FAILURE); + if(!(soap_fault->fcode)) + { + soap_fault->fcode = code; + return AXIS2_SUCCESS; + } + else + { + AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, + "tring to set multiple code elements to soap_fault "); + + } + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axiom_soap_fault_code_t *AXIS2_CALL +axiom_soap_fault_get_code( + axiom_soap_fault_t * soap_fault, + const axutil_env_t * env) +{ + int status = AXIS2_SUCCESS; + if(soap_fault->fcode) + { + return soap_fault->fcode; + } + else if(soap_fault->soap_builder) + { + while(!(soap_fault->fcode) && !(axiom_node_is_complete(soap_fault->om_ele_node, env))) + { + status = axiom_soap_builder_next(soap_fault->soap_builder, env); + if(status == AXIS2_FAILURE) + { + break; + } + } + } + return soap_fault->fcode; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_fault_set_reason( + axiom_soap_fault_t * soap_fault, + const axutil_env_t * env, + axiom_soap_fault_reason_t * reason) +{ + AXIS2_PARAM_CHECK(env->error, reason, AXIS2_FAILURE); + if(!(soap_fault->freason)) + { + soap_fault->freason = reason; + return AXIS2_SUCCESS; + } + else + { + AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "tring to set soap_fault reason twice"); + } + return AXIS2_FAILURE; +} + +AXIS2_EXTERN axiom_soap_fault_reason_t *AXIS2_CALL +axiom_soap_fault_get_reason( + axiom_soap_fault_t * soap_fault, + const axutil_env_t * env) +{ + int status = AXIS2_SUCCESS; + if(soap_fault->freason) + { + return soap_fault->freason; + } + else if(soap_fault->soap_builder) + { + while(!(soap_fault->freason) && !(axiom_node_is_complete(soap_fault->om_ele_node, env))) + { + status = axiom_soap_builder_next(soap_fault->soap_builder, env); + if(status == AXIS2_FAILURE) + { + break; + } + } + } + return soap_fault->freason; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_fault_set_node( + axiom_soap_fault_t * soap_fault, + const axutil_env_t * env, + axiom_soap_fault_node_t * node) +{ + AXIS2_PARAM_CHECK(env->error, node, AXIS2_FAILURE); + if(!(soap_fault->fnode)) + { + soap_fault->fnode = node; + return AXIS2_SUCCESS; + } + else + { + AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "tring to set soap_fault node more than once"); + } + return AXIS2_FAILURE; +} + +AXIS2_EXTERN axiom_soap_fault_node_t *AXIS2_CALL +axiom_soap_fault_get_node( + axiom_soap_fault_t * soap_fault, + const axutil_env_t * env) +{ + int status = AXIS2_SUCCESS; + + if(soap_fault->fnode) + { + return soap_fault->fnode; + } + else if(soap_fault->soap_builder) + { + while(!(soap_fault->fnode) && !(axiom_node_is_complete(soap_fault->om_ele_node, env))) + { + status = axiom_soap_builder_next(soap_fault->soap_builder, env); + if(status == AXIS2_FAILURE) + { + break; + } + } + } + return soap_fault->fnode; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_fault_set_role( + axiom_soap_fault_t * soap_fault, + const axutil_env_t * env, + axiom_soap_fault_role_t * role) +{ + AXIS2_PARAM_CHECK(env->error, role, AXIS2_FAILURE); + + if(!(soap_fault->frole)) + { + soap_fault->frole = role; + return AXIS2_FAILURE; + } + else + { + AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "tring to set soap_fault role more than once "); + } + return AXIS2_FAILURE; + +} + +AXIS2_EXTERN axiom_soap_fault_role_t *AXIS2_CALL +axiom_soap_fault_get_role( + axiom_soap_fault_t * soap_fault, + const axutil_env_t * env) +{ + int status = AXIS2_SUCCESS; + if(soap_fault->frole) + { + return soap_fault->frole; + } + else if(soap_fault->soap_builder) + { + while(!(soap_fault->frole) && !(axiom_node_is_complete(soap_fault->om_ele_node, env))) + { + status = axiom_soap_builder_next(soap_fault->soap_builder, env); + if(status == AXIS2_FAILURE) + { + break; + } + } + } + return soap_fault->frole; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_fault_set_detail( + axiom_soap_fault_t * soap_fault, + const axutil_env_t * env, + axiom_soap_fault_detail_t * detail) +{ + AXIS2_PARAM_CHECK(env->error, detail, AXIS2_FAILURE); + + if(!(soap_fault->fdetail)) + { + soap_fault->fdetail = detail; + return AXIS2_SUCCESS; + } + else + { + AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, " tring to set soap_fault detail more than once"); + + } + return AXIS2_FAILURE; +} + +AXIS2_EXTERN axiom_soap_fault_detail_t *AXIS2_CALL +axiom_soap_fault_get_detail( + axiom_soap_fault_t * soap_fault, + const axutil_env_t * env) +{ + int status = AXIS2_SUCCESS; + if(soap_fault->fdetail) + { + return soap_fault->fdetail; + } + else if(soap_fault->soap_builder) + { + while(!(soap_fault->fdetail) && !(axiom_node_is_complete(soap_fault->om_ele_node, env))) + { + status = axiom_soap_builder_next(soap_fault->soap_builder, env); + if(status == AXIS2_FAILURE) + { + break; + } + } + } + return soap_fault->fdetail; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_fault_set_base_node( + axiom_soap_fault_t * soap_fault, + const axutil_env_t * env, + axiom_node_t * node) +{ + AXIS2_PARAM_CHECK(env->error, node, AXIS2_FAILURE); + + if(axiom_node_get_node_type(node, env) != AXIOM_ELEMENT) + { + AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_INVALID_BASE_TYPE, AXIS2_FAILURE); + return AXIS2_FAILURE; + } + soap_fault->om_ele_node = node; + return AXIS2_SUCCESS; + +} + +AXIS2_EXTERN axiom_node_t *AXIS2_CALL +axiom_soap_fault_get_base_node( + axiom_soap_fault_t * soap_fault, + const axutil_env_t * env) +{ + return soap_fault->om_ele_node; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axiom_soap_fault_get_exception( + axiom_soap_fault_t * soap_fault, + const axutil_env_t * env) +{ + axiom_soap_fault_detail_t *detail = NULL; + axiom_node_t *detail_node = NULL; + axiom_element_t *detail_ele = NULL; + axiom_node_t *exception_node = NULL; + axiom_element_t *exception_ele = NULL; + axutil_qname_t *qn = NULL; + axis2_char_t *excep = NULL; + + detail = axiom_soap_fault_get_detail(soap_fault, env); + if(!detail) + { + return NULL; + } + detail_node = axiom_soap_fault_detail_get_base_node(detail, env); + if(detail_node) + { + detail_ele = (axiom_element_t *)axiom_node_get_data_element(detail_node, env); + + qn = axutil_qname_create(env, AXIOM_SOAP_FAULT_DETAIL_EXCEPTION_ENTRY, NULL, NULL); + if(qn) + { + exception_ele = axiom_element_get_first_child_with_qname(detail_ele, env, qn, + detail_node, &exception_node); + axutil_qname_free(qn, env); + if(exception_ele) + { + excep = axiom_element_get_text(exception_ele, env, exception_node); + } + return excep; + } + } + return NULL; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_fault_set_exception( + axiom_soap_fault_t * soap_fault, + const axutil_env_t * env, + axis2_char_t * exception) +{ + axiom_soap_fault_detail_t *detail = NULL; + axiom_node_t *fault_detail_entry_node = NULL; + axiom_element_t *fault_detail_ele = NULL; + + AXIS2_PARAM_CHECK(env->error, exception, AXIS2_FAILURE); + + detail = axiom_soap_fault_get_detail(soap_fault, env); + + if(!detail) + { + detail = axiom_soap_fault_detail_create_with_parent(env, soap_fault); + if(!detail) + { + return AXIS2_FAILURE; + } + } + + /** create an om element with the exception enrty */ + + fault_detail_ele = axiom_element_create(env, NULL, AXIOM_SOAP_FAULT_DETAIL_EXCEPTION_ENTRY, + NULL, &fault_detail_entry_node); + if(!fault_detail_ele) + { + return AXIS2_FAILURE; + } + + /** set the exception string as a text node of newly created om element */ + axiom_element_set_text(fault_detail_ele, env, exception, fault_detail_entry_node); + + /** now add this om element as a child of soap soap_fault detail om element node */ + return axiom_soap_fault_detail_add_detail_entry(detail, env, fault_detail_entry_node); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_fault_set_builder( + axiom_soap_fault_t * soap_fault, + const axutil_env_t * env, + axiom_soap_builder_t * builder) +{ + AXIS2_PARAM_CHECK(env->error, builder, AXIS2_FAILURE); + soap_fault->soap_builder = builder; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axiom_soap_fault_t *AXIS2_CALL +axiom_soap_fault_create_default_fault( + const axutil_env_t * env, + struct axiom_soap_body * parent, + const axis2_char_t * code_value, + const axis2_char_t * reason_text, + const int soap_version) +{ + axiom_soap_fault_t *soap_fault = NULL; + axiom_node_t *fault_node = NULL; + + axiom_soap_fault_code_t *soap_fault_code = NULL; + axiom_soap_fault_value_t *soap_fault_value = NULL; + + axiom_soap_fault_reason_t *soap_fault_reason = NULL; + axiom_soap_fault_text_t *soap_fault_text = NULL; + + axiom_node_t *value_node = NULL; + axiom_element_t *value_ele = NULL; + + axiom_node_t *text_node = NULL; + axiom_element_t *text_ele = NULL; + + AXIS2_PARAM_CHECK(env->error, code_value, NULL); + AXIS2_PARAM_CHECK(env->error, reason_text, NULL); + + soap_fault = axiom_soap_fault_create_with_parent(env, parent); + if(!soap_fault) + { + return NULL; + } + fault_node = axiom_soap_fault_get_base_node(soap_fault, env); + if(!fault_node) + { + axiom_soap_fault_free(soap_fault, env); + return NULL; + } + + soap_fault_code = axiom_soap_fault_code_create_with_parent(env, soap_fault); + if(!soap_fault_code) + { + axiom_soap_fault_free(soap_fault, env); + axiom_node_free_tree(fault_node, env); + return NULL; + } + soap_fault_reason = axiom_soap_fault_reason_create_with_parent(env, soap_fault); + if(!soap_fault_reason) + { + axiom_soap_fault_free(soap_fault, env); + axiom_node_free_tree(fault_node, env); + return NULL; + } + + soap_fault_value = axiom_soap_fault_value_create_with_code(env, soap_fault_code); + if(!soap_fault_value) + { + axiom_soap_fault_free(soap_fault, env); + axiom_node_free_tree(fault_node, env); + return NULL; + } + + value_node = axiom_soap_fault_value_get_base_node(soap_fault_value, env); + if(!value_node) + { + return NULL; + } + value_ele = (axiom_element_t *)axiom_node_get_data_element(value_node, env); + + axiom_element_set_text(value_ele, env, code_value, value_node); + + soap_fault_text = axiom_soap_fault_text_create_with_parent(env, soap_fault_reason); + if(!soap_fault_text) + { + axiom_soap_fault_free(soap_fault, env); + axiom_node_free_tree(fault_node, env); + return NULL; + } + axiom_soap_fault_text_set_lang(soap_fault_text, env, "en"); + + text_node = axiom_soap_fault_text_get_base_node(soap_fault_text, env); + if(!text_node) + { + return NULL; + } + text_ele = (axiom_element_t *)axiom_node_get_data_element(text_node, env); + + axiom_element_set_text(text_ele, env, reason_text, text_node); + + return soap_fault; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_fault_set_soap_version( + axiom_soap_fault_t * soap_fault, + const axutil_env_t * env, + int soap_version) +{ + soap_fault->soap_version = soap_version; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN int AXIS2_CALL +axiom_soap_fault_get_soap_version( + axiom_soap_fault_t * soap_fault, + const axutil_env_t * env) +{ + return soap_fault->soap_version; +} diff --git a/axiom/src/soap/soap_fault_code.c b/axiom/src/soap/soap_fault_code.c new file mode 100644 index 0000000..b0ded55 --- /dev/null +++ b/axiom/src/soap/soap_fault_code.c @@ -0,0 +1,308 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "_axiom_soap_fault_code.h" +#include <axiom_soap_fault_sub_code.h> +#include <axiom_soap_fault_value.h> +#include <axiom_soap_builder.h> +#include "_axiom_soap_fault.h" + +struct axiom_soap_fault_code +{ + axiom_node_t *om_ele_node; + + axiom_soap_fault_sub_code_t *subcode; + + axiom_soap_fault_value_t *value; + + axiom_soap_builder_t *builder; + + int soap_version; + +}; + +AXIS2_EXTERN axiom_soap_fault_code_t *AXIS2_CALL +axiom_soap_fault_code_create( + const axutil_env_t * env) +{ + axiom_soap_fault_code_t *fault_code = NULL; + fault_code = (axiom_soap_fault_code_t *)AXIS2_MALLOC(env->allocator, + sizeof(axiom_soap_fault_code_t)); + + if(!fault_code) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory. Cannot create SOAP fault code"); + return NULL; + } + + fault_code->om_ele_node = NULL; + fault_code->subcode = NULL; + fault_code->value = NULL; + fault_code->builder = NULL; + fault_code->soap_version = AXIOM_SOAP_VERSION_NOT_SET; + + return fault_code; +} + +AXIS2_EXTERN axiom_soap_fault_code_t *AXIS2_CALL +axiom_soap_fault_code_create_with_parent( + const axutil_env_t * env, + axiom_soap_fault_t * fault) +{ + axiom_soap_fault_code_t *fault_code = NULL; + axiom_element_t *this_ele = NULL; + axiom_node_t *this_node = NULL; + + axiom_node_t *parent_node = NULL; + axiom_element_t *parent_ele = NULL; + + axiom_namespace_t *parent_ns = NULL; + + AXIS2_PARAM_CHECK(env->error, fault, NULL); + + fault_code = axiom_soap_fault_code_create(env); + if(!fault_code) + { + return NULL; + } + + parent_node = axiom_soap_fault_get_base_node(fault, env); + if(!parent_node) + { + axiom_soap_fault_code_free(fault_code, env); + return NULL; + } + parent_ele = (axiom_element_t *)axiom_node_get_data_element(parent_node, env); + + if(!parent_ele) + { + axiom_soap_fault_code_free(fault_code, env); + return NULL; + } + fault_code->soap_version = axiom_soap_fault_get_soap_version(fault, env); + if(fault_code->soap_version == AXIOM_SOAP12) + { + parent_ns = axiom_element_get_namespace(parent_ele, env, parent_node); + } + this_ele = axiom_element_create(env, parent_node, AXIOM_SOAP12_SOAP_FAULT_CODE_LOCAL_NAME, + parent_ns, &this_node); + + if(!this_ele) + { + axiom_soap_fault_code_free(fault_code, env); + return NULL; + } + + fault_code->om_ele_node = this_node; + + axiom_soap_fault_set_code(fault, env, fault_code); + + return fault_code; +} + +AXIS2_EXTERN axiom_soap_fault_code_t *AXIS2_CALL +axiom_soap_fault_code_create_with_parent_value( + const axutil_env_t * env, + axiom_soap_fault_t * fault, + axis2_char_t * value) +{ + axiom_soap_fault_code_t *fault_code = NULL; + axiom_soap_fault_value_t *fault_value = NULL; + AXIS2_PARAM_CHECK(env->error, value, NULL); + + fault_code = axiom_soap_fault_code_create_with_parent(env, fault); + if(!fault_code) + { + return NULL; + } + + fault_value = axiom_soap_fault_value_create_with_code(env, fault_code); + if(!fault_value) + { + axiom_soap_fault_code_free(fault_code, env); + return NULL; + } + axiom_soap_fault_value_set_text(fault_value, env, value); + return fault_code; +} + +AXIS2_EXTERN void AXIS2_CALL +axiom_soap_fault_code_free( + axiom_soap_fault_code_t * fault_code, + const axutil_env_t * env) +{ + + if(fault_code->subcode) + { + axiom_soap_fault_sub_code_free(fault_code->subcode, env); + } + if(fault_code->value) + { + axiom_soap_fault_value_free(fault_code->value, env); + } + + AXIS2_FREE(env->allocator, fault_code); + return; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_fault_code_set_value( + axiom_soap_fault_code_t * fault_code, + const axutil_env_t * env, + axiom_soap_fault_value_t * fault_val) +{ + + AXIS2_PARAM_CHECK(env->error, fault_val, AXIS2_FAILURE); + + if(!(fault_code->value)) + { + fault_code->value = fault_val; + return AXIS2_SUCCESS; + } + else + { + AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, + "trying to set fault value to fault code more than once"); + } + return AXIS2_FAILURE; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_fault_code_set_sub_code( + axiom_soap_fault_code_t * fault_code, + const axutil_env_t * env, + axiom_soap_fault_sub_code_t * fault_subcode) +{ + AXIS2_PARAM_CHECK(env->error, fault_subcode, AXIS2_FAILURE); + + if(!(fault_code->subcode)) + { + fault_code->subcode = fault_subcode; + return AXIS2_SUCCESS; + } + else + { + AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, + "trying to set fault subcode to fault code more than once "); + } + return AXIS2_FAILURE; +} + +AXIS2_EXTERN axiom_soap_fault_sub_code_t *AXIS2_CALL +axiom_soap_fault_code_get_sub_code( + axiom_soap_fault_code_t * fault_code, + const axutil_env_t * env) +{ + int status = AXIS2_SUCCESS; + + if(fault_code->subcode) + { + return fault_code->subcode; + } + else if(fault_code->builder) + { + while(!(fault_code->subcode) && !(axiom_node_is_complete(fault_code->om_ele_node, env))) + { + status = axiom_soap_builder_next(fault_code->builder, env); + if(status == AXIS2_FAILURE) + { + break; + } + } + } + return fault_code->subcode; +} + +AXIS2_EXTERN axiom_soap_fault_value_t *AXIS2_CALL +axiom_soap_fault_code_get_value( + axiom_soap_fault_code_t * fault_code, + const axutil_env_t * env) +{ + int status = AXIS2_SUCCESS; + + if(fault_code->value) + { + return fault_code->value; + } + else if(fault_code->builder) + { + while(!(fault_code->value) && !(axiom_node_is_complete(fault_code->om_ele_node, env))) + { + status = axiom_soap_builder_next(fault_code->builder, env); + if(status == AXIS2_FAILURE) + { + break; + } + } + } + return fault_code->value; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_fault_code_set_base_node( + axiom_soap_fault_code_t * fault_code, + const axutil_env_t * env, + axiom_node_t * node) +{ + AXIS2_PARAM_CHECK(env->error, node, AXIS2_FAILURE); + + if(axiom_node_get_node_type(node, env) != AXIOM_ELEMENT) + { + AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_INVALID_BASE_TYPE, AXIS2_FAILURE); + return AXIS2_FAILURE; + } + fault_code->om_ele_node = node; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axiom_node_t *AXIS2_CALL +axiom_soap_fault_code_get_base_node( + axiom_soap_fault_code_t * fault_code, + const axutil_env_t * env) +{ + return fault_code->om_ele_node; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_fault_code_set_builder( + axiom_soap_fault_code_t * fault_code, + const axutil_env_t * env, + axiom_soap_builder_t * soap_builder) +{ + AXIS2_PARAM_CHECK(env->error, soap_builder, AXIS2_FAILURE); + fault_code->builder = soap_builder; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN int AXIS2_CALL +axiom_soap_fault_code_get_soap_version( + axiom_soap_fault_code_t * fault_code, + const axutil_env_t * env) +{ + return fault_code->soap_version; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_fault_code_set_soap_version( + axiom_soap_fault_code_t * fault_code, + const axutil_env_t * env, + int soap_version) +{ + fault_code->soap_version = soap_version; + return AXIS2_SUCCESS; +} diff --git a/axiom/src/soap/soap_fault_detail.c b/axiom/src/soap/soap_fault_detail.c new file mode 100644 index 0000000..0375767 --- /dev/null +++ b/axiom/src/soap/soap_fault_detail.c @@ -0,0 +1,160 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "_axiom_soap_fault.h" +#include <axiom_element.h> +#include <axiom_node.h> +#include "_axiom_soap_fault_detail.h" + +struct axiom_soap_fault_detail +{ + axiom_node_t *om_ele_node; +}; + +AXIS2_EXTERN axiom_soap_fault_detail_t *AXIS2_CALL +axiom_soap_fault_detail_create( + const axutil_env_t * env) +{ + axiom_soap_fault_detail_t *fault_detail = NULL; + + fault_detail = (axiom_soap_fault_detail_t *)AXIS2_MALLOC(env->allocator, + sizeof(axiom_soap_fault_detail_t)); + if(!fault_detail) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory. Cannot create a fault detail"); + return NULL; + } + + fault_detail->om_ele_node = NULL; + + return fault_detail; +} + +AXIS2_EXTERN axiom_soap_fault_detail_t *AXIS2_CALL +axiom_soap_fault_detail_create_with_parent( + const axutil_env_t * env, + axiom_soap_fault_t * fault) +{ + axiom_soap_fault_detail_t *fault_detail = NULL; + axiom_element_t *this_ele = NULL; + axiom_node_t *this_node = NULL; + axiom_node_t *parent_node = NULL; + axiom_element_t *parent_ele = NULL; + axiom_namespace_t *parent_ns = NULL; + int soap_version = -1; + + AXIS2_PARAM_CHECK(env->error, fault, NULL); + + fault_detail = axiom_soap_fault_detail_create(env); + if(!fault_detail) + { + return NULL; + } + parent_node = axiom_soap_fault_get_base_node(fault, env); + if(!parent_node) + { + return NULL; + } + parent_ele = (axiom_element_t *)axiom_node_get_data_element(parent_node, env); + if(!parent_ele) + { + return NULL; + } + soap_version = axiom_soap_fault_get_soap_version(fault, env); + if(soap_version == AXIOM_SOAP12) + { + parent_ns = axiom_element_get_namespace(parent_ele, env, parent_node); + } + this_ele = axiom_element_create(env, parent_node, AXIOM_SOAP12_SOAP_FAULT_DETAIL_LOCAL_NAME, + parent_ns, &this_node); + + if(!this_ele) + { + axiom_soap_fault_detail_free(fault_detail, env); + return NULL; + } + fault_detail->om_ele_node = this_node; + axiom_soap_fault_set_detail(fault, env, fault_detail); + return fault_detail; +} + +AXIS2_EXTERN void AXIS2_CALL +axiom_soap_fault_detail_free( + axiom_soap_fault_detail_t * fault_detail, + const axutil_env_t * env) +{ + AXIS2_FREE(env->allocator, fault_detail); + return; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_fault_detail_add_detail_entry( + axiom_soap_fault_detail_t * fault_detail, + const axutil_env_t * env, + axiom_node_t * node) +{ + AXIS2_PARAM_CHECK(env->error, node, AXIS2_FAILURE); + + if(axiom_node_get_node_type(node, env) != AXIOM_ELEMENT) + { + AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_OM_ELEMENT_EXPECTED, AXIS2_FAILURE); + + return AXIS2_FAILURE; + } + + axiom_node_add_child(fault_detail->om_ele_node, env, node); + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axiom_children_iterator_t *AXIS2_CALL +axiom_soap_fault_detail_get_all_detail_entries( + axiom_soap_fault_detail_t * fault_detail, + const axutil_env_t * env) +{ + axiom_element_t *om_ele = NULL; + if(fault_detail->om_ele_node) + { + om_ele = (axiom_element_t *)axiom_node_get_data_element(fault_detail->om_ele_node, env); + return axiom_element_get_children(om_ele, env, fault_detail->om_ele_node); + } + return NULL; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_fault_detail_set_base_node( + axiom_soap_fault_detail_t * fault_detail, + const axutil_env_t * env, + axiom_node_t * node) +{ + AXIS2_PARAM_CHECK(env->error, node, AXIS2_FAILURE); + + if(axiom_node_get_node_type(node, env) != AXIOM_ELEMENT) + { + AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_INVALID_BASE_TYPE, AXIS2_FAILURE); + return AXIS2_FAILURE; + } + fault_detail->om_ele_node = node; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axiom_node_t *AXIS2_CALL axiom_soap_fault_detail_get_base_node( + axiom_soap_fault_detail_t * fault_detail, + const axutil_env_t * env) +{ + return fault_detail->om_ele_node; +} diff --git a/axiom/src/soap/soap_fault_node.c b/axiom/src/soap/soap_fault_node.c new file mode 100644 index 0000000..143bc87 --- /dev/null +++ b/axiom/src/soap/soap_fault_node.c @@ -0,0 +1,176 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "_axiom_soap_fault_node.h" +#include <axiom_node.h> +#include <axiom_element.h> +#include "_axiom_soap_fault.h" + +struct axiom_soap_fault_node +{ + axiom_node_t *om_ele_node; +}; + +AXIS2_EXTERN axiom_soap_fault_node_t *AXIS2_CALL +axiom_soap_fault_node_create( + const axutil_env_t * env) +{ + axiom_soap_fault_node_t *fault_node = NULL; + + fault_node = (axiom_soap_fault_node_t *)AXIS2_MALLOC(env->allocator, + sizeof(axiom_soap_fault_node_t)); + + if(!fault_node) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory. Cannot create a SOAP fault node"); + return NULL; + } + fault_node->om_ele_node = NULL; + + return fault_node; +} + +AXIS2_EXTERN axiom_soap_fault_node_t *AXIS2_CALL +axiom_soap_fault_node_create_with_parent( + const axutil_env_t * env, + axiom_soap_fault_t * fault) +{ + axiom_soap_fault_node_t *fault_node = NULL; + axiom_element_t *this_ele = NULL; + axiom_node_t *this_node = NULL; + + axiom_node_t *parent_node = NULL; + axiom_element_t *parent_ele = NULL; + + axiom_namespace_t *parent_ns = NULL; + + AXIS2_PARAM_CHECK(env->error, fault, NULL); + + fault_node = axiom_soap_fault_node_create(env); + if(!fault_node) + { + return NULL; + } + parent_node = axiom_soap_fault_get_base_node(fault, env); + if(!parent_node) + { + axiom_soap_fault_node_free(fault_node, env); + return NULL; + } + + parent_ele = (axiom_element_t *)axiom_node_get_data_element(parent_node, env); + if(!parent_ele) + { + axiom_soap_fault_node_free(fault_node, env); + return NULL; + } + + parent_ns = axiom_element_get_namespace(parent_ele, env, parent_node); + + this_ele = axiom_element_create(env, parent_node, AXIOM_SOAP12_SOAP_FAULT_NODE_LOCAL_NAME, + parent_ns, &this_node); + + if(!this_ele) + { + axiom_soap_fault_node_free(fault_node, env); + return NULL; + } + + fault_node->om_ele_node = this_node; + + axiom_soap_fault_set_node(fault, env, fault_node); + + return fault_node; +} + +AXIS2_EXTERN void AXIS2_CALL +axiom_soap_fault_node_free( + axiom_soap_fault_node_t * fault_node, + const axutil_env_t * env) +{ + AXIS2_FREE(env->allocator, fault_node); + return; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_fault_node_set_value( + axiom_soap_fault_node_t * fault_node, + const axutil_env_t * env, + axis2_char_t * uri) +{ + axiom_element_t *om_ele = NULL; + + AXIS2_PARAM_CHECK(env->error, uri, AXIS2_FAILURE); + + if(fault_node->om_ele_node) + { + om_ele = (axiom_element_t *)axiom_node_get_data_element(fault_node-> om_ele_node, env); + + if(om_ele) + { + return axiom_element_set_text(om_ele, env, uri, fault_node->om_ele_node); + } + } + + return AXIS2_FAILURE; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axiom_soap_fault_node_get_value( + axiom_soap_fault_node_t * fault_node, + const axutil_env_t * env) +{ + axiom_element_t *om_ele = NULL; + + if(fault_node->om_ele_node) + { + om_ele = (axiom_element_t *)axiom_node_get_data_element(fault_node-> om_ele_node, env); + if(om_ele) + { + return axiom_element_get_text(om_ele, env, fault_node->om_ele_node); + } + + } + return NULL; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_fault_node_set_base_node( + axiom_soap_fault_node_t * fault_node, + const axutil_env_t * env, + axiom_node_t * node) +{ + AXIS2_PARAM_CHECK(env->error, node, AXIS2_FAILURE); + if(axiom_node_get_node_type(node, env) != AXIOM_ELEMENT) + { + AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_INVALID_BASE_TYPE, AXIS2_FAILURE); + return AXIS2_FAILURE; + } + + fault_node->om_ele_node = node; + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axiom_node_t *AXIS2_CALL +axiom_soap_fault_node_get_base_node( + axiom_soap_fault_node_t * fault_node, + const axutil_env_t * env) +{ + return fault_node->om_ele_node; +} diff --git a/axiom/src/soap/soap_fault_reason.c b/axiom/src/soap/soap_fault_reason.c new file mode 100644 index 0000000..516d58c --- /dev/null +++ b/axiom/src/soap/soap_fault_reason.c @@ -0,0 +1,386 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <axiom_soap_fault_reason.h> +#include "_axiom_soap_fault.h" +#include <axiom_element.h> +#include <axiom_soap_fault_text.h> +#include <axiom_soap_builder.h> +#include <axiom_soap_builder.h> + +struct axiom_soap_fault_reason +{ + /* corresponding om element node */ + axiom_node_t *om_ele_node; + + axutil_array_list_t *fault_texts; + /* pointer to soap builder */ + axiom_soap_builder_t *soap_builder; + + int soap_version; +}; + +static axis2_bool_t +axiom_soap_fault_reason_lang_exists( + axiom_soap_fault_reason_t * fault_reason, + const axutil_env_t * env, + axis2_char_t * lang); + +AXIS2_EXTERN axiom_soap_fault_reason_t *AXIS2_CALL +axiom_soap_fault_reason_create( + const axutil_env_t * env) +{ + axiom_soap_fault_reason_t *fault_reason = NULL; + fault_reason = (axiom_soap_fault_reason_t *)AXIS2_MALLOC(env->allocator, + sizeof(axiom_soap_fault_reason_t)); + if(!fault_reason) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory. Cannot create SOAP fault reason"); + return NULL; + } + + fault_reason->om_ele_node = NULL; + fault_reason->fault_texts = NULL; + fault_reason->soap_version = -1; + return fault_reason; +} + +AXIS2_EXTERN axiom_soap_fault_reason_t *AXIS2_CALL +axiom_soap_fault_reason_create_with_parent( + const axutil_env_t * env, + axiom_soap_fault_t * fault) +{ + axiom_soap_fault_reason_t *fault_reason = NULL; + axiom_element_t *this_ele = NULL; + axiom_node_t *this_node = NULL; + axiom_node_t *parent_node = NULL; + axiom_element_t *parent_ele = NULL; + axiom_namespace_t *parent_ns = NULL; + + AXIS2_PARAM_CHECK(env->error, fault, NULL); + + fault_reason = axiom_soap_fault_reason_create(env); + if(!fault_reason) + { + return NULL; + } + parent_node = axiom_soap_fault_get_base_node(fault, env); + if(!parent_node) + { + return NULL; + } + parent_ele = (axiom_element_t *)axiom_node_get_data_element(parent_node, env); + if(!parent_ele) + { + return NULL; + } + fault_reason->soap_version = axiom_soap_fault_get_soap_version(fault, env); + if(fault_reason->soap_version == AXIOM_SOAP12) + { + parent_ns = axiom_element_get_namespace(parent_ele, env, parent_node); + } + this_ele = axiom_element_create(env, parent_node, AXIOM_SOAP12_SOAP_FAULT_REASON_LOCAL_NAME, + parent_ns, &this_node); + if(!this_ele) + { + return NULL; + } + + fault_reason->om_ele_node = this_node; + + axiom_soap_fault_set_reason(fault, env, fault_reason); + return fault_reason; +} + +AXIS2_EXTERN void AXIS2_CALL +axiom_soap_fault_reason_free( + axiom_soap_fault_reason_t * fault_reason, + const axutil_env_t * env) +{ + + if(fault_reason->fault_texts) + { + int size = 0; + int i = 0; + size = axutil_array_list_size(fault_reason->fault_texts, env); + + for(i = 0; i < size; i++) + { + axiom_soap_fault_text_t *fault_text = NULL; + void *value = NULL; + value = axutil_array_list_get(fault_reason->fault_texts, env, i); + if(value) + { + fault_text = (axiom_soap_fault_text_t *)value; + axiom_soap_fault_text_free(fault_text, env); + fault_text = NULL; + } + } + axutil_array_list_free(fault_reason->fault_texts, env); + fault_reason->fault_texts = NULL; + } + + AXIS2_FREE(env->allocator, fault_reason); + + fault_reason = NULL; + + return; +} + +AXIS2_EXTERN axiom_soap_fault_text_t *AXIS2_CALL +axiom_soap_fault_reason_get_soap_fault_text( + axiom_soap_fault_reason_t * fault_reason, + const axutil_env_t * env, + axis2_char_t * lang) +{ + int status = AXIS2_SUCCESS; + int size = 0; + int i = 0; + + AXIS2_PARAM_CHECK(env->error, fault_reason, NULL); + if(!lang || (axutil_strcmp(lang, "") == 0)) + { + return NULL; + } + /** Here we have to build the soap fault reason element completly */ + if(!fault_reason->fault_texts) + { + + if(fault_reason->soap_builder && !(axiom_node_is_complete(fault_reason->om_ele_node, env))) + { + while(!(axiom_node_is_complete(fault_reason->om_ele_node, env))) + { + status = axiom_soap_builder_next(fault_reason->soap_builder, env); + if(status == AXIS2_FAILURE) + { + return NULL; + } + } + } + } + + if(!fault_reason->fault_texts) + { + return NULL; + } + /** iterate the array list */ + size = axutil_array_list_size(fault_reason->fault_texts, env); + for(i = 0; i < size; i++) + { + axiom_soap_fault_text_t *fault_text = NULL; + void *value = NULL; + + value = axutil_array_list_get(fault_reason->fault_texts, env, i); + if(value) + { + axis2_char_t *fault_lang = NULL; + fault_text = (axiom_soap_fault_text_t *)value; + fault_lang = axiom_soap_fault_text_get_lang(fault_text, env); + if(fault_lang && axutil_strcmp(lang, fault_lang) == 0) + { + return fault_text; + } + } + } + return NULL; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_fault_reason_set_base_node( + axiom_soap_fault_reason_t * fault_reason, + const axutil_env_t * env, + axiom_node_t * node) +{ + AXIS2_PARAM_CHECK(env->error, node, AXIS2_FAILURE); + + if(axiom_node_get_node_type(node, env) != AXIOM_ELEMENT) + { + AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_INVALID_BASE_TYPE, AXIS2_FAILURE); + return AXIS2_FAILURE; + } + fault_reason->om_ele_node = node; + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axiom_node_t *AXIS2_CALL axiom_soap_fault_reason_get_base_node( + axiom_soap_fault_reason_t * fault_reason, + const axutil_env_t * env) +{ + return fault_reason->om_ele_node; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_fault_reason_set_builder( + axiom_soap_fault_reason_t * fault_reason, + const axutil_env_t * env, + axiom_soap_builder_t * builder) +{ + AXIS2_PARAM_CHECK(env->error, builder, AXIS2_FAILURE); + + fault_reason->soap_builder = builder; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axutil_array_list_t *AXIS2_CALL +axiom_soap_fault_reason_get_all_soap_fault_texts( + axiom_soap_fault_reason_t * fault_reason, + const axutil_env_t * env) +{ + int status = AXIS2_SUCCESS; + + if(!(fault_reason->fault_texts) && (fault_reason->soap_builder)) + { + if(!(axiom_node_is_complete(fault_reason->om_ele_node, env))) + { + while(!(axiom_node_is_complete(fault_reason->om_ele_node, env))) + { + status = axiom_soap_builder_next(fault_reason->soap_builder, env); + if(status == AXIS2_FAILURE) + { + return NULL; + } + } + } + } + return fault_reason->fault_texts; +} + +AXIS2_EXTERN axiom_soap_fault_text_t *AXIS2_CALL +axiom_soap_fault_reason_get_first_soap_fault_text( + axiom_soap_fault_reason_t * fault_reason, + const axutil_env_t * env) +{ + int status = AXIS2_SUCCESS; + + if(!(fault_reason->fault_texts) && (fault_reason->soap_builder)) + { + if(!(axiom_node_is_complete(fault_reason->om_ele_node, env))) + { + while(!(axiom_node_is_complete(fault_reason->om_ele_node, env))) + { + status = axiom_soap_builder_next(fault_reason->soap_builder, env); + if(status == AXIS2_FAILURE) + { + return NULL; + } + } + } + } + if(fault_reason->fault_texts) + { + void *value = NULL; + value = axutil_array_list_get(fault_reason->fault_texts, env, 0); + if(value) + { + return (axiom_soap_fault_text_t *)value; + } + } + return NULL; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_fault_reason_add_soap_fault_text( + axiom_soap_fault_reason_t * fault_reason, + const axutil_env_t * env, + axiom_soap_fault_text_t * fault_text) +{ + if(!fault_text) + { + return AXIS2_FAILURE; + } + if(!(fault_reason->fault_texts)) + { + fault_reason->fault_texts = axutil_array_list_create(env, 1); + if(!fault_reason->fault_texts) + { + return AXIS2_FAILURE; + } + axutil_array_list_add(fault_reason->fault_texts, env, fault_text); + } + else + { + axis2_char_t *lang = NULL; + axis2_bool_t is_exists = AXIS2_FALSE; + lang = axiom_soap_fault_text_get_lang(fault_text, env); + if(lang) + { + is_exists = axiom_soap_fault_reason_lang_exists(fault_reason, env, lang); + if(is_exists == AXIS2_TRUE) + { + return AXIS2_FAILURE; + } + /** this soap_fault text already exists */ + } + axutil_array_list_add(fault_reason->fault_texts, env, fault_text); + } + return AXIS2_SUCCESS; +} + +static axis2_bool_t +axiom_soap_fault_reason_lang_exists( + axiom_soap_fault_reason_t * fault_reason, + const axutil_env_t * env, + axis2_char_t * lang) +{ + int size = 0; + int i = 0; + + if(!lang || (axutil_strcmp(lang, "") == 0) || !fault_reason->fault_texts) + { + return AXIS2_FALSE; + } + size = axutil_array_list_size(fault_reason->fault_texts, env); + for(i = 0; i < size; i++) + { + axiom_soap_fault_text_t *fault_text = NULL; + void *value = NULL; + value = axutil_array_list_get(fault_reason->fault_texts, env, i); + if(value) + { + axis2_char_t *text_lang = NULL; + fault_text = (axiom_soap_fault_text_t *)value; + + text_lang = axiom_soap_fault_text_get_lang(fault_text, env); + if(text_lang && (axutil_strcmp(lang, text_lang) == 0)) + { + return AXIS2_TRUE; + } + } + } + return AXIS2_FALSE; +} + +/** internal function */ +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_fault_reason_set_soap_version( + axiom_soap_fault_reason_t * fault_reason, + const axutil_env_t * env, + int soap_version) +{ + fault_reason->soap_version = soap_version; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_fault_reason_get_soap_version( + axiom_soap_fault_reason_t * fault_reason, + const axutil_env_t * env) +{ + return fault_reason->soap_version; +} diff --git a/axiom/src/soap/soap_fault_role.c b/axiom/src/soap/soap_fault_role.c new file mode 100644 index 0000000..a438ea4 --- /dev/null +++ b/axiom/src/soap/soap_fault_role.c @@ -0,0 +1,180 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <axiom_soap_fault_role.h> +#include "_axiom_soap_fault.h" +#include <axiom_soap_builder.h> +#include <axiom_element.h> + +struct axiom_soap_fault_role +{ + axiom_node_t *om_ele_node; +}; + +AXIS2_EXTERN axiom_soap_fault_role_t *AXIS2_CALL +axiom_soap_fault_role_create( + const axutil_env_t * env) +{ + axiom_soap_fault_role_t *fault_role = NULL; + + fault_role = (axiom_soap_fault_role_t *)AXIS2_MALLOC(env->allocator, + sizeof(axiom_soap_fault_role_t)); + + if(!fault_role) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory. Cannot create SOAP fault role"); + return NULL; + } + + fault_role->om_ele_node = NULL; + + return fault_role; +} + +AXIS2_EXTERN axiom_soap_fault_role_t *AXIS2_CALL +axiom_soap_fault_role_create_with_parent( + const axutil_env_t * env, + axiom_soap_fault_t * fault) +{ + axiom_soap_fault_role_t *fault_role = NULL; + int soap_version = -1; + + axiom_element_t *this_ele = NULL; + axiom_node_t *this_node = NULL; + + axiom_node_t *parent_node = NULL; + axiom_element_t *parent_ele = NULL; + + axiom_namespace_t *parent_ns = NULL; + + AXIS2_PARAM_CHECK(env->error, fault, NULL); + + fault_role = axiom_soap_fault_role_create(env); + if(!fault_role) + { + return NULL; + } + parent_node = axiom_soap_fault_get_base_node(fault, env); + if(!parent_node) + { + axiom_soap_fault_role_free(fault_role, env); + return NULL; + } + parent_ele = (axiom_element_t *)axiom_node_get_data_element(parent_node, env); + + if(!parent_ele) + { + axiom_soap_fault_role_free(fault_role, env); + return NULL; + } + soap_version = axiom_soap_fault_get_soap_version(fault, env); + if(soap_version == AXIOM_SOAP12) + { + parent_ns = axiom_element_get_namespace(parent_ele, env, parent_node); + } + this_ele = axiom_element_create(env, parent_node, AXIOM_SOAP12_SOAP_FAULT_ROLE_LOCAL_NAME, + parent_ns, &this_node); + + if(!this_ele) + { + axiom_soap_fault_role_free(fault_role, env); + return NULL; + } + + fault_role->om_ele_node = this_node; + + axiom_soap_fault_set_role(fault, env, fault_role); + + return fault_role; +} + +AXIS2_EXTERN void AXIS2_CALL +axiom_soap_fault_role_free( + axiom_soap_fault_role_t * fault_role, + const axutil_env_t * env) +{ + AXIS2_FREE(env->allocator, fault_role); + return; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_fault_role_set_role_value( + axiom_soap_fault_role_t * fault_role, + const axutil_env_t * env, + axis2_char_t * uri) +{ + axiom_element_t *role_ele = NULL; + + AXIS2_PARAM_CHECK(env->error, uri, AXIS2_FAILURE); + + if(!fault_role->om_ele_node) + { + return AXIS2_FAILURE; + } + role_ele = (axiom_element_t *)axiom_node_get_data_element(fault_role->om_ele_node, env); + + if(role_ele) + { + return axiom_element_set_text(role_ele, env, uri, fault_role->om_ele_node); + } + return AXIS2_FAILURE; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL axiom_soap_fault_role_get_role_value( + axiom_soap_fault_role_t * fault_role, + const axutil_env_t * env) +{ + axiom_element_t *role_ele = NULL; + + if (!fault_role->om_ele_node) + { + return NULL; + } + role_ele = (axiom_element_t *) axiom_node_get_data_element + (fault_role->om_ele_node, env); + + if (role_ele) + { + return axiom_element_get_text(role_ele, env, fault_role->om_ele_node); + } + return NULL; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_fault_role_set_base_node( + axiom_soap_fault_role_t * fault_role, + const axutil_env_t * env, + axiom_node_t * node) +{ + AXIS2_PARAM_CHECK(env->error, node, AXIS2_FAILURE); + + if(axiom_node_get_node_type(node, env) != AXIOM_ELEMENT) + { + AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_INVALID_BASE_TYPE, AXIS2_FAILURE); + return AXIS2_FAILURE; + } + fault_role->om_ele_node = node; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axiom_node_t *AXIS2_CALL axiom_soap_fault_role_get_base_node( + axiom_soap_fault_role_t * fault_role, + const axutil_env_t * env) +{ + return fault_role->om_ele_node; +} diff --git a/axiom/src/soap/soap_fault_sub_code.c b/axiom/src/soap/soap_fault_sub_code.c new file mode 100644 index 0000000..904b406 --- /dev/null +++ b/axiom/src/soap/soap_fault_sub_code.c @@ -0,0 +1,298 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <axiom_soap_fault_sub_code.h> +#include "_axiom_soap_fault_code.h" +#include <axiom_soap_fault_value.h> +#include <axiom_soap_builder.h> + +struct axiom_soap_fault_sub_code +{ + /* corresponding om element node */ + axiom_node_t *om_ele_node; + /* sub element fault value */ + axiom_soap_fault_value_t *value; + /* sub element fault subcode */ + axiom_soap_fault_sub_code_t *subcode; + /* pointer to soap builder */ + axiom_soap_builder_t *builder; + + int soap_version; +}; + +AXIS2_EXTERN axiom_soap_fault_sub_code_t *AXIS2_CALL +axiom_soap_fault_sub_code_create( + const axutil_env_t * env) +{ + axiom_soap_fault_sub_code_t *fault_sub_code = NULL; + AXIS2_ENV_CHECK(env, NULL); + fault_sub_code = (axiom_soap_fault_sub_code_t *)AXIS2_MALLOC(env->allocator, + sizeof(axiom_soap_fault_sub_code_t)); + if(!fault_sub_code) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory. Cannot create SOAP fault sub-code"); + return NULL; + } + + fault_sub_code->om_ele_node = NULL; + fault_sub_code->value = NULL; + fault_sub_code->subcode = NULL; + fault_sub_code->builder = NULL; + + return fault_sub_code; +} + +AXIS2_EXTERN axiom_soap_fault_sub_code_t *AXIS2_CALL +axiom_soap_fault_sub_code_create_with_parent( + const axutil_env_t * env, + axiom_soap_fault_code_t * fault_code) +{ + axiom_soap_fault_sub_code_t *fault_sub_code = NULL; + axiom_element_t *this_ele = NULL; + axiom_node_t *this_node = NULL; + axiom_node_t *parent_node = NULL; + axiom_element_t *parent_ele = NULL; + axiom_namespace_t *parent_ns = NULL; + + AXIS2_PARAM_CHECK(env->error, fault_code, NULL); + fault_sub_code = axiom_soap_fault_sub_code_create(env); + + if(!fault_sub_code) + { + return NULL; + } + parent_node = axiom_soap_fault_code_get_base_node(fault_code, env); + if(!parent_node) + { + axiom_soap_fault_sub_code_free(fault_sub_code, env); + return NULL; + } + + parent_ele = (axiom_element_t *)axiom_node_get_data_element(parent_node, env); + if(!parent_ele) + { + axiom_soap_fault_sub_code_free(fault_sub_code, env); + return NULL; + } + fault_sub_code->soap_version = axiom_soap_fault_code_get_soap_version(fault_code, env); + + if(fault_sub_code->soap_version == AXIOM_SOAP12) + { + parent_ns = axiom_element_get_namespace(parent_ele, env, parent_node); + } + + this_ele = axiom_element_create(env, parent_node, AXIOM_SOAP12_SOAP_FAULT_SUB_CODE_LOCAL_NAME, + parent_ns, &this_node); + + if(!this_ele) + { + axiom_soap_fault_sub_code_free(fault_sub_code, env); + return NULL; + } + + fault_sub_code->om_ele_node = this_node; + + axiom_soap_fault_code_set_sub_code(fault_code, env, fault_sub_code); + + return fault_sub_code; +} + +AXIS2_EXTERN axiom_soap_fault_sub_code_t *AXIS2_CALL +axiom_soap_fault_sub_code_create_with_parent_value( + const axutil_env_t * env, + axiom_soap_fault_code_t * fault_code, + axis2_char_t * value) +{ + axiom_soap_fault_sub_code_t *fault_sub_code = NULL; + axiom_soap_fault_value_t *fault_value = NULL; + AXIS2_PARAM_CHECK(env->error, value, NULL); + + fault_sub_code = axiom_soap_fault_sub_code_create_with_parent(env, fault_code); + if(!fault_sub_code) + { + return NULL; + } + fault_value = axiom_soap_fault_value_create_with_subcode(env, fault_sub_code); + if(!fault_value) + { + axiom_soap_fault_sub_code_free(fault_sub_code, env); + return NULL; + } + + axiom_soap_fault_value_set_text(fault_value, env, value); + return fault_sub_code; +} + +AXIS2_EXTERN void AXIS2_CALL +axiom_soap_fault_sub_code_free( + axiom_soap_fault_sub_code_t * fault_sub_code, + const axutil_env_t * env) +{ + if(fault_sub_code->value) + { + axiom_soap_fault_value_free(fault_sub_code->value, env); + fault_sub_code->value = NULL; + } + if(fault_sub_code->subcode) + { + axiom_soap_fault_sub_code_free(fault_sub_code->subcode, env); + fault_sub_code->subcode = NULL; + } + AXIS2_FREE(env->allocator, fault_sub_code); + + fault_sub_code = NULL; + + return; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_fault_sub_code_set_sub_code( + axiom_soap_fault_sub_code_t * fault_sub_code, + const axutil_env_t * env, + axiom_soap_fault_sub_code_t * subcode) +{ + AXIS2_PARAM_CHECK(env->error, subcode, AXIS2_FAILURE); + + if(!(fault_sub_code->subcode)) + { + fault_sub_code->subcode = subcode; + return AXIS2_SUCCESS; + } + else + { + AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "error tring to set fault subcode more than once"); + } + return AXIS2_FAILURE; +} + +AXIS2_EXTERN axiom_soap_fault_value_t *AXIS2_CALL +axiom_soap_fault_sub_code_get_value( + axiom_soap_fault_sub_code_t * fault_sub_code, + const axutil_env_t * env) +{ + int status = AXIS2_SUCCESS; + + if(fault_sub_code->builder) + { + while(!(fault_sub_code->value) && !axiom_node_is_complete(fault_sub_code->om_ele_node, env)) + { + status = axiom_soap_builder_next(fault_sub_code->builder, env); + if(status == AXIS2_FAILURE) + { + break; + } + } + } + return fault_sub_code->value; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_fault_sub_code_set_value( + axiom_soap_fault_sub_code_t * fault_sub_code, + const axutil_env_t * env, + axiom_soap_fault_value_t * fault_sub_code_val) +{ + AXIS2_PARAM_CHECK(env->error, fault_sub_code_val, AXIS2_FAILURE); + + if(!(fault_sub_code->value)) + { + fault_sub_code->value = fault_sub_code_val; + return AXIS2_SUCCESS; + } + else + { + AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, + "error tring to set fault subcode value more than once"); + } + return AXIS2_FAILURE; +} + +AXIS2_EXTERN axiom_soap_fault_sub_code_t *AXIS2_CALL +axiom_soap_fault_sub_code_get_subcode( + axiom_soap_fault_sub_code_t * fault_sub_code, + const axutil_env_t * env) +{ + int status = AXIS2_SUCCESS; + + if(fault_sub_code->builder) + { + while(!(fault_sub_code->subcode) && !axiom_node_is_complete(fault_sub_code->om_ele_node, + env)) + { + status = axiom_soap_builder_next(fault_sub_code->builder, env); + if(status == AXIS2_FAILURE) + { + break; + } + } + } + return fault_sub_code->subcode; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_fault_sub_code_set_base_node( + axiom_soap_fault_sub_code_t * fault_sub_code, + const axutil_env_t * env, + axiom_node_t * node) +{ + AXIS2_PARAM_CHECK(env->error, node, AXIS2_FAILURE); + + if(axiom_node_get_node_type(node, env) != AXIOM_ELEMENT) + { + AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_INVALID_BASE_TYPE, AXIS2_FAILURE); + return AXIS2_FAILURE; + } + fault_sub_code->om_ele_node = node; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axiom_node_t *AXIS2_CALL axiom_soap_fault_sub_code_get_base_node( + axiom_soap_fault_sub_code_t * fault_sub_code, + const axutil_env_t * env) +{ + return fault_sub_code->om_ele_node; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_fault_sub_code_set_builder( + axiom_soap_fault_sub_code_t * fault_sub_code, + const axutil_env_t * env, + axiom_soap_builder_t * builder) +{ + AXIS2_PARAM_CHECK(env->error, builder, AXIS2_FAILURE); + + fault_sub_code->builder = builder; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_fault_sub_code_set_soap_version( + axiom_soap_fault_sub_code_t * fault_sub_code, + const axutil_env_t * env, + int soap_version) +{ + fault_sub_code->soap_version = soap_version; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN int AXIS2_CALL axiom_soap_fault_sub_code_get_soap_version( + axiom_soap_fault_sub_code_t * fault_sub_code, + const axutil_env_t * env) +{ + return fault_sub_code->soap_version; +} diff --git a/axiom/src/soap/soap_fault_text.c b/axiom/src/soap/soap_fault_text.c new file mode 100644 index 0000000..9c51821 --- /dev/null +++ b/axiom/src/soap/soap_fault_text.c @@ -0,0 +1,305 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <axiom_soap_fault.h> +#include <axiom_element.h> +#include "_axiom_soap_fault_text.h" +#include "_axiom_soap_fault_reason.h" +#include <axiom_namespace.h> +#include <axutil_qname.h> + +struct axiom_soap_fault_text +{ + axiom_attribute_t *lang_attribute; + + axiom_namespace_t *lang_namespace; + + axiom_node_t *om_ele_node; + + axis2_bool_t lang_ns_used; +}; + +AXIS2_EXTERN axiom_soap_fault_text_t *AXIS2_CALL +axiom_soap_fault_text_create( + const axutil_env_t * env) +{ + axiom_soap_fault_text_t *fault_text = NULL; + + fault_text = (axiom_soap_fault_text_t *)AXIS2_MALLOC(env->allocator, + sizeof(axiom_soap_fault_text_t)); + if(!fault_text) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory. Cannot create SOAP fault text"); + return NULL; + } + + fault_text->om_ele_node = NULL; + fault_text->lang_attribute = NULL; + fault_text->lang_namespace = NULL; + fault_text->lang_ns_used = AXIS2_FALSE; + + fault_text->lang_namespace = axiom_namespace_create(env, + AXIOM_SOAP12_SOAP_FAULT_TEXT_LANG_ATTR_NS_URI, + AXIOM_SOAP12_SOAP_FAULT_TEXT_LANG_ATTR_NS_PREFIX); + + if(!(fault_text->lang_namespace)) + { + return NULL; + } + + return fault_text; +} + +AXIS2_EXTERN axiom_soap_fault_text_t *AXIS2_CALL +axiom_soap_fault_text_create_with_parent( + const axutil_env_t * env, + axiom_soap_fault_reason_t * parent) +{ + axiom_soap_fault_text_t *fault_text = NULL; + axiom_element_t *this_ele = NULL; + int soap_version = -1; + axiom_node_t *this_node = NULL; + axiom_namespace_t *parent_ns = NULL; + axiom_node_t *parent_node = NULL; + axiom_element_t *parent_ele = NULL; + + AXIS2_PARAM_CHECK(env->error, parent, NULL); + + fault_text = axiom_soap_fault_text_create(env); + + if(!fault_text) + { + return NULL; + } + + parent_node = axiom_soap_fault_reason_get_base_node(parent, env); + if(!parent_node) + { + axiom_soap_fault_text_free(fault_text, env); + return NULL; + } + + parent_ele = (axiom_element_t *)axiom_node_get_data_element(parent_node, env); + if(!parent_ele) + { + axiom_soap_fault_text_free(fault_text, env); + return NULL; + } + + soap_version = axiom_soap_fault_reason_get_soap_version(parent, env); + if(AXIOM_SOAP12 == soap_version) + { + parent_ns = axiom_element_get_namespace(parent_ele, env, parent_node); + } + this_ele = axiom_element_create(env, parent_node, AXIOM_SOAP12_SOAP_FAULT_TEXT_LOCAL_NAME, + parent_ns, &this_node); + + if(!this_ele) + { + axiom_soap_fault_text_free(fault_text, env); + return NULL; + } + + fault_text->om_ele_node = this_node; + + axiom_soap_fault_reason_add_soap_fault_text(parent, env, fault_text); + + return fault_text; +} + +AXIS2_EXTERN void AXIS2_CALL +axiom_soap_fault_text_free( + axiom_soap_fault_text_t * fault_text, + const axutil_env_t * env) +{ + + if(fault_text->lang_ns_used == AXIS2_FALSE && fault_text->lang_namespace) + { + axiom_namespace_free(fault_text->lang_namespace, env); + fault_text->lang_namespace = NULL; + } + AXIS2_FREE(env->allocator, fault_text); + fault_text = NULL; + return; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_fault_text_set_lang( + axiom_soap_fault_text_t * fault_text, + const axutil_env_t * env, + const axis2_char_t * lang) +{ + int status = AXIS2_SUCCESS; + axiom_element_t *om_ele = NULL; + + AXIS2_PARAM_CHECK(env->error, lang, AXIS2_FAILURE); + + if(fault_text->lang_attribute) + { + axis2_char_t *attr_lang = NULL; + attr_lang = axiom_attribute_get_value(fault_text->lang_attribute, env); + if(attr_lang) + { + if(axutil_strcmp(attr_lang, lang) == 0) + { + + /** this attribute already exists */ + return AXIS2_SUCCESS; + } + } + axiom_attribute_set_value(fault_text->lang_attribute, env, lang); + return AXIS2_SUCCESS; + } + + fault_text->lang_attribute = axiom_attribute_create(env, + AXIOM_SOAP12_SOAP_FAULT_TEXT_LANG_ATTR_LOCAL_NAME, lang, fault_text-> lang_namespace); + if(!fault_text->lang_attribute) + { + return AXIS2_FAILURE; + } + + if(!fault_text->om_ele_node) + { + return AXIS2_FAILURE; + } + om_ele = (axiom_element_t *)axiom_node_get_data_element(fault_text->om_ele_node, env); + if(!om_ele) + { + return AXIS2_FAILURE; + } + + status = axiom_element_add_attribute(om_ele, env, fault_text->lang_attribute, + fault_text->om_ele_node); + + if(status == AXIS2_SUCCESS) + { + fault_text->lang_ns_used = AXIS2_TRUE; + } + else + { + axiom_attribute_free(fault_text->lang_attribute, env); + fault_text->lang_attribute = NULL; + } + return status; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axiom_soap_fault_text_get_lang( + axiom_soap_fault_text_t * fault_text, + const axutil_env_t * env) +{ + axiom_element_t *om_ele = NULL; + axutil_qname_t *tmp_qname = NULL; + + if(!fault_text->om_ele_node) + { + return NULL; + } + om_ele = (axiom_element_t *)axiom_node_get_data_element(fault_text->om_ele_node, env); + if(!om_ele) + { + return NULL; + } + if(!(fault_text->lang_attribute)) + { + + /* this logic need to be rechecked */ + tmp_qname = axutil_qname_create(env, AXIOM_SOAP12_SOAP_FAULT_TEXT_LANG_ATTR_LOCAL_NAME, + AXIOM_SOAP12_SOAP_FAULT_TEXT_LANG_ATTR_NS_URI, + AXIOM_SOAP12_SOAP_FAULT_TEXT_LANG_ATTR_NS_PREFIX); + + fault_text->lang_attribute = axiom_element_get_attribute(om_ele, env, tmp_qname); + axutil_qname_free(tmp_qname, env); + } + if(fault_text->lang_attribute) + { + return axiom_attribute_get_value(fault_text->lang_attribute, env); + } + else + return NULL; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_fault_text_set_base_node( + axiom_soap_fault_text_t * fault_text, + const axutil_env_t * env, + axiom_node_t * node) +{ + + if(node && (axiom_node_get_node_type(node, env) != AXIOM_ELEMENT)) + { + AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_INVALID_BASE_TYPE, AXIS2_FAILURE); + return AXIS2_FAILURE; + } + fault_text->om_ele_node = node; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axiom_node_t *AXIS2_CALL +axiom_soap_fault_text_get_base_node( + axiom_soap_fault_text_t * fault_text, + const axutil_env_t * env) +{ + return fault_text->om_ele_node; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_fault_text_set_text( + axiom_soap_fault_text_t * fault_text, + const axutil_env_t * env, + axis2_char_t * value, + axis2_char_t * lang) +{ + AXIS2_PARAM_CHECK(env->error, value, AXIS2_FAILURE); + + if(fault_text->om_ele_node) + { + axiom_element_t *text_ele = NULL; + text_ele = (axiom_element_t *)axiom_node_get_data_element(fault_text->om_ele_node, env); + if(text_ele) + { + axiom_element_set_text(text_ele, env, value, fault_text->om_ele_node); + if(lang) + { + axiom_soap_fault_text_set_lang(fault_text, env, lang); + } + return AXIS2_SUCCESS; + } + } + return AXIS2_FAILURE; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axiom_soap_fault_text_get_text( + axiom_soap_fault_text_t * fault_text, + const axutil_env_t * env) +{ + axis2_char_t *text = NULL; + + if(fault_text->om_ele_node) + { + axiom_element_t *text_ele = NULL; + text_ele = (axiom_element_t *)axiom_node_get_data_element(fault_text->om_ele_node, env); + if(text_ele) + { + text = axiom_element_get_text(text_ele, env, fault_text->om_ele_node); + return text; + } + } + return NULL; +} diff --git a/axiom/src/soap/soap_fault_value.c b/axiom/src/soap/soap_fault_value.c new file mode 100644 index 0000000..775cba4 --- /dev/null +++ b/axiom/src/soap/soap_fault_value.c @@ -0,0 +1,237 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include <axiom_soap_fault_value.h> +#include "_axiom_soap_fault_sub_code.h" +#include "_axiom_soap_fault_code.h" +#include <axiom_element.h> +#include <axiom_text.h> + +struct axiom_soap_fault_value +{ + + /** store om element node */ + axiom_node_t *om_ele_node; +}; + +AXIS2_EXTERN axiom_soap_fault_value_t *AXIS2_CALL +axiom_soap_fault_value_create( + const axutil_env_t * env) +{ + axiom_soap_fault_value_t *fault_value = NULL; + + fault_value = (axiom_soap_fault_value_t *)AXIS2_MALLOC(env->allocator, + sizeof(axiom_soap_fault_value_t)); + + if(!fault_value) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory. Cannot create SOAP fault value"); + return NULL; + } + + fault_value->om_ele_node = NULL; + + return fault_value; +} + +AXIS2_EXTERN axiom_soap_fault_value_t *AXIS2_CALL +axiom_soap_fault_value_create_with_subcode( + const axutil_env_t * env, + axiom_soap_fault_sub_code_t * parent) +{ + axiom_soap_fault_value_t *fault_value = NULL; + + axiom_element_t *this_ele = NULL; + axiom_node_t *this_node = NULL; + axiom_namespace_t *parent_ns = NULL; + axiom_node_t *parent_node = NULL; + axiom_element_t *parent_ele = NULL; + int soap_version = -1; + + AXIS2_PARAM_CHECK(env->error, parent, NULL); + + fault_value = axiom_soap_fault_value_create(env); + + if(!fault_value) + { + return NULL; + } + + parent_node = axiom_soap_fault_sub_code_get_base_node(parent, env); + + if(!parent_node) + { + axiom_soap_fault_value_free(fault_value, env); + return NULL; + } + + parent_ele = (axiom_element_t *)axiom_node_get_data_element(parent_node, env); + + if(!parent_ele) + { + axiom_soap_fault_value_free(fault_value, env); + return NULL; + } + soap_version = axiom_soap_fault_sub_code_get_soap_version(parent, env); + if(soap_version == AXIOM_SOAP12) + { + parent_ns = axiom_element_get_namespace(parent_ele, env, parent_node); + } + + this_ele = axiom_element_create(env, parent_node, AXIOM_SOAP12_SOAP_FAULT_VALUE_LOCAL_NAME, + parent_ns, &this_node); + + if(!this_ele) + { + axiom_soap_fault_value_free(fault_value, env); + return NULL; + } + + fault_value->om_ele_node = this_node; + + axiom_soap_fault_sub_code_set_value(parent, env, fault_value); + + return fault_value; +} + +AXIS2_EXTERN axiom_soap_fault_value_t *AXIS2_CALL +axiom_soap_fault_value_create_with_code( + const axutil_env_t * env, + axiom_soap_fault_code_t * parent) +{ + axiom_soap_fault_value_t *fault_value = NULL; + int soap_version = -1; + axiom_element_t *this_ele = NULL; + axiom_node_t *this_node = NULL; + axiom_namespace_t *parent_ns = NULL; + axiom_node_t *parent_node = NULL; + axiom_element_t *parent_ele = NULL; + + AXIS2_PARAM_CHECK(env->error, parent, NULL); + + fault_value = axiom_soap_fault_value_create(env); + + if(!fault_value) + { + return NULL; + } + + parent_node = axiom_soap_fault_code_get_base_node(parent, env); + if(!parent_node) + { + axiom_soap_fault_value_free(fault_value, env); + return NULL; + } + parent_ele = (axiom_element_t *)axiom_node_get_data_element(parent_node, env); + if(!parent_ele) + { + axiom_soap_fault_value_free(fault_value, env); + return NULL; + } + soap_version = axiom_soap_fault_code_get_soap_version(parent, env); + if(soap_version == AXIOM_SOAP12) + { + parent_ns = axiom_element_get_namespace(parent_ele, env, parent_node); + } + this_ele = axiom_element_create(env, parent_node, AXIOM_SOAP12_SOAP_FAULT_VALUE_LOCAL_NAME, + parent_ns, &this_node); + + if(!this_ele) + { + axiom_soap_fault_value_free(fault_value, env); + return NULL; + } + fault_value->om_ele_node = this_node; + + axiom_soap_fault_code_set_value(parent, env, fault_value); + + return fault_value; +} + +AXIS2_EXTERN void AXIS2_CALL +axiom_soap_fault_value_free( + axiom_soap_fault_value_t * fault_value, + const axutil_env_t * env) +{ + AXIS2_FREE(env->allocator, fault_value); + return; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_fault_value_set_base_node( + axiom_soap_fault_value_t * fault_value, + const axutil_env_t * env, + axiom_node_t * node) +{ + + if(node && (axiom_node_get_node_type(node, env) != AXIOM_ELEMENT)) + { + AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_INVALID_BASE_TYPE, AXIS2_FAILURE); + return AXIS2_FAILURE; + } + + fault_value->om_ele_node = node; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axiom_node_t *AXIS2_CALL +axiom_soap_fault_value_get_base_node( + axiom_soap_fault_value_t * fault_value, + const axutil_env_t * env) +{ + return fault_value->om_ele_node; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axiom_soap_fault_value_get_text( + axiom_soap_fault_value_t * fault_value, + const axutil_env_t * env) +{ + axiom_node_t *value_node = NULL; + axiom_element_t *value_element = NULL; + + value_node = axiom_soap_fault_value_get_base_node(fault_value, env); + + if(!value_node) + { + return NULL; + } + value_element = (axiom_element_t *)axiom_node_get_data_element(value_node, env); + + if(!value_element) + { + return NULL; + } + return axiom_element_get_text(value_element, env, value_node); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_fault_value_set_text( + axiom_soap_fault_value_t * fault_value, + const axutil_env_t * env, + axis2_char_t * text) +{ + AXIS2_PARAM_CHECK(env->error, text, AXIS2_FAILURE); + if(fault_value->om_ele_node && axiom_node_get_node_type(fault_value->om_ele_node, env) + == AXIOM_ELEMENT) + { + axiom_element_t *om_ele = NULL; + om_ele = (axiom_element_t *)axiom_node_get_data_element(fault_value->om_ele_node, env); + return axiom_element_set_text(om_ele, env, text, fault_value->om_ele_node); + } + return AXIS2_FAILURE; +} diff --git a/axiom/src/soap/soap_header.c b/axiom/src/soap/soap_header.c new file mode 100644 index 0000000..6c6a71c --- /dev/null +++ b/axiom/src/soap/soap_header.c @@ -0,0 +1,655 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "_axiom_soap_envelope.h" +#include "_axiom_soap_header.h" +#include "_axiom_soap_body.h" +#include <axiom_soap_header_block.h> +#include <axutil_hash.h> +#include <axiom_soap_const.h> +#include <axiom_soap_builder.h> +#include <stdio.h> +#include <axiom_node_internal.h> +#include <axutil_array_list.h> + +struct axiom_soap_header +{ + axiom_node_t *om_ele_node; + + int soap_version; + + axutil_hash_t *header_blocks; + + int hbnumber; + + axiom_soap_builder_t *soap_builder; + + axiom_soap_envelope_t *soap_envelope; + + axutil_array_list_t *header_block_keys; +}; + +static axis2_bool_t AXIS2_CALL axiom_soap_header_qname_matches( + const axutil_env_t * env, + axutil_qname_t * element_qname, + axutil_qname_t * qname_to_match); + +AXIS2_EXTERN axiom_soap_header_t *AXIS2_CALL +axiom_soap_header_create( + const axutil_env_t * env) +{ + axiom_soap_header_t *soap_header = NULL; + + soap_header = (axiom_soap_header_t *)AXIS2_MALLOC(env->allocator, sizeof(axiom_soap_header_t)); + if(!soap_header) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory. Cannot create SOAP header"); + return NULL; + } + + soap_header->om_ele_node = NULL; + soap_header->soap_envelope = NULL; + soap_header->hbnumber = 0; + soap_header->header_blocks = NULL; + + /** default value */ + soap_header->soap_version = AXIOM_SOAP12; + soap_header->header_block_keys = NULL; + + soap_header->header_block_keys = axutil_array_list_create(env, 10); + if(!soap_header->header_block_keys) + { + AXIS2_FREE(env->allocator, soap_header); + return NULL; + } + + return soap_header; +} + +AXIS2_EXTERN axiom_soap_header_t *AXIS2_CALL +axiom_soap_header_create_with_parent( + const axutil_env_t * env, + axiom_soap_envelope_t * envelope) +{ + axiom_soap_header_t *soap_header = NULL; + + /*axiom_element_t *this_ele = NULL; + axiom_node_t *this_node = NULL;*/ + axiom_node_t *body_node = NULL; + axiom_node_t *parent_node = NULL; + axiom_element_t *parent_ele = NULL; + + /*axiom_namespace_t *parent_ns = NULL;*/ + + AXIS2_PARAM_CHECK(env->error, envelope, NULL); + + soap_header = axiom_soap_header_create(env); + if(!soap_header) + { + return NULL; + } + soap_header->soap_version = axiom_soap_envelope_get_soap_version(envelope, env); + + parent_node = axiom_soap_envelope_get_base_node(envelope, env); + + if(!parent_node || axiom_node_get_node_type(parent_node, env) != AXIOM_ELEMENT) + { + axiom_soap_header_free(soap_header, env); + return NULL; + } + + parent_ele = (axiom_element_t *)axiom_node_get_data_element(parent_node, env); + if(!parent_ele) + { + axiom_soap_header_free(soap_header, env); + return NULL; + } + if(axiom_node_get_first_element(parent_node, env)) + { + body_node = axiom_node_get_first_element(parent_node, env); + axiom_node_detach(body_node, env); + } + + /*parent_ns = axiom_element_get_namespace(parent_ele, env, parent_node); + this_ele = axiom_element_create(env, parent_node, + AXIOM_SOAP_HEADER_LOCAL_NAME, parent_ns, + &this_node); + if (!this_ele) + { + axiom_soap_header_free(soap_header, env); + return NULL; + } + + soap_header->om_ele_node = this_node;*/ + + axiom_soap_envelope_set_header(envelope, env, soap_header); + + if(body_node) + { + axiom_node_add_child(parent_node, env, body_node); + } + + soap_header->soap_envelope = envelope; + + return soap_header; +} + +AXIS2_EXTERN void AXIS2_CALL +axiom_soap_header_free( + axiom_soap_header_t * soap_header, + const axutil_env_t * env) +{ + + if(soap_header->header_blocks) + { + axutil_hash_index_t *hi = NULL; + void *val = NULL; + for(hi = axutil_hash_first(soap_header->header_blocks, env); hi; hi = axutil_hash_next(env, + hi)) + { + axutil_hash_this(hi, NULL, NULL, &val); + + if(val) + { + axiom_soap_header_block_free((axiom_soap_header_block_t *)val, env); + val = NULL; + } + } + + axutil_hash_free(soap_header->header_blocks, env); + } + if(soap_header->header_block_keys) + { + int size = 0; + void *val = NULL; + int i = 0; + size = axutil_array_list_size(soap_header->header_block_keys, env); + for(i = 0; i < size; i++) + { + val = axutil_array_list_get(soap_header->header_block_keys, env, i); + if(val) + { + AXIS2_FREE(env->allocator, (char *)val); + val = NULL; + } + } + axutil_array_list_free(soap_header->header_block_keys, env); + soap_header->header_block_keys = NULL; + } + AXIS2_FREE(env->allocator, soap_header); + + soap_header = NULL; + + return; +} + +AXIS2_EXTERN axiom_soap_header_block_t *AXIS2_CALL +axiom_soap_header_add_header_block( + axiom_soap_header_t * soap_header, + const axutil_env_t * env, + const axis2_char_t * localname, + axiom_namespace_t * ns) +{ + axiom_soap_header_block_t *header_block = NULL; + + axiom_namespace_t *cloned_ns = NULL; + + axiom_node_t *header_block_node = NULL; + + AXIS2_PARAM_CHECK(env->error, localname, NULL); + AXIS2_PARAM_CHECK(env->error, ns, NULL); + + cloned_ns = axiom_namespace_clone(ns, env); + if(!cloned_ns) + { + return NULL; + } + header_block = axiom_soap_header_block_create_with_parent(env, localname, cloned_ns, + soap_header); + + if(!header_block) + { + return NULL; + } + header_block_node = axiom_soap_header_block_get_base_node(header_block, env); + + if(header_block_node) + { + axiom_node_set_complete(header_block_node, env, AXIS2_TRUE); + + return header_block; + } + else + { + return NULL; + } +} +AXIS2_EXTERN axutil_hash_t *AXIS2_CALL axiom_soap_header_examine_header_blocks( + axiom_soap_header_t * soap_header, + const axutil_env_t * env, + axis2_char_t * param_role) +{ + AXIS2_PARAM_CHECK(env->error, param_role, NULL); + + return soap_header->header_blocks; +} + +AXIS2_EXTERN axiom_children_qname_iterator_t *AXIS2_CALL +axiom_soap_header_examine_all_header_blocks( + axiom_soap_header_t * soap_header, + const axutil_env_t * env) +{ + axiom_element_t *om_ele = NULL; + + if(!soap_header->om_ele_node) + { + return NULL; + } + om_ele = (axiom_element_t *)axiom_node_get_data_element(soap_header-> om_ele_node, env); + + if(om_ele) + { + return axiom_element_get_children_with_qname(om_ele, env, NULL, soap_header->om_ele_node); + } + else + return NULL; +} + +AXIS2_EXTERN axiom_children_with_specific_attribute_iterator_t *AXIS2_CALL +axiom_soap_header_extract_header_blocks( + axiom_soap_header_t * soap_header, + const axutil_env_t * env, + axis2_char_t * role) +{ + const axis2_char_t *localname = NULL; + const axis2_char_t *nsuri = NULL; + + axiom_node_t *first_node = NULL; + axiom_element_t *first_ele = NULL; + + axutil_qname_t *qn = NULL; + + axiom_element_t *header_om_ele = NULL; + axiom_children_with_specific_attribute_iterator_t *iter = NULL; + + if(soap_header->soap_version == AXIOM_SOAP_VERSION_NOT_SET) + { + return NULL; + } + if(soap_header->soap_version == AXIOM_SOAP11) + { + localname = AXIOM_SOAP11_SOAP_ENVELOPE_NAMESPACE_URI; + nsuri = AXIOM_SOAP11_ATTR_ACTOR; + } + if(soap_header->soap_version == AXIOM_SOAP12) + { + localname = AXIOM_SOAP12_SOAP_ROLE; + nsuri = AXIOM_SOAP12_SOAP_ENVELOPE_NAMESPACE_URI; + } + + qn = axutil_qname_create(env, localname, nsuri, NULL); + if(!qn) + { + return NULL; + } + header_om_ele = (axiom_element_t *)axiom_node_get_data_element(soap_header->om_ele_node, env); + + if(header_om_ele) + { + first_ele = axiom_element_get_first_element(header_om_ele, env, soap_header->om_ele_node, + &first_node); + if(first_node) + { + return axiom_children_with_specific_attribute_iterator_create(env, first_node, qn, + role, AXIS2_TRUE); + } + } + + axutil_qname_free(qn, env); + + return iter; + +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_header_set_base_node( + axiom_soap_header_t * soap_header, + const axutil_env_t * env, + axiom_node_t * node) +{ + AXIS2_PARAM_CHECK(env->error, node, AXIS2_FAILURE); + + if(axiom_node_get_node_type(node, env) != AXIOM_ELEMENT) + { + AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_INVALID_BASE_TYPE, AXIS2_FAILURE); + return AXIS2_FAILURE; + } + + soap_header->om_ele_node = node; + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axiom_node_t *AXIS2_CALL +axiom_soap_header_get_base_node( + axiom_soap_header_t * soap_header, + const axutil_env_t * env) +{ + if(!soap_header->om_ele_node) + { + axiom_node_t *parent_node = NULL; + axiom_element_t *parent_ele = NULL; + axiom_namespace_t *parent_ns = NULL; + axiom_element_t *this_ele = NULL; + axiom_node_t *this_node = NULL; + axiom_soap_body_t *soap_body = NULL; + axiom_node_t *body_node = NULL; + + parent_node = axiom_soap_envelope_get_base_node(soap_header->soap_envelope, env); + + if(!parent_node || axiom_node_get_node_type(parent_node, env) != AXIOM_ELEMENT) + { + axiom_soap_header_free(soap_header, env); + return NULL; + } + + parent_ele = (axiom_element_t *)axiom_node_get_data_element(parent_node, env); + if(!parent_ele) + { + axiom_soap_header_free(soap_header, env); + return NULL; + } + + parent_ns = axiom_element_get_namespace(parent_ele, env, parent_node); + this_ele = axiom_element_create(env, NULL, AXIOM_SOAP_HEADER_LOCAL_NAME, parent_ns, + &this_node); + if(!this_ele) + { + axiom_soap_header_free(soap_header, env); + return NULL; + } + + soap_body = axiom_soap_envelope_get_body(soap_header->soap_envelope, env); + if(soap_body) + { + body_node = axiom_soap_body_get_base_node(soap_body, env); + axiom_node_insert_sibling_before(body_node, env, this_node); + } + else + { + axiom_node_add_child(parent_node, env, this_node); + } + soap_header->om_ele_node = this_node; + } + + return soap_header->om_ele_node; +} + +/** + set soap version and get soap version are internal functions + + */ +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_header_get_soap_version( + axiom_soap_header_t * soap_header, + const axutil_env_t * env) +{ + return soap_header->soap_version; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_header_set_soap_version( + axiom_soap_header_t * soap_header, + const axutil_env_t * env, + int soap_version) +{ + soap_header->soap_version = soap_version; + return AXIS2_SUCCESS; + +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_header_set_header_block( + axiom_soap_header_t * soap_header, + const axutil_env_t * env, + struct axiom_soap_header_block * header_block) +{ + axis2_char_t *key = NULL; + AXIS2_PARAM_CHECK(env->error, header_block, AXIS2_FAILURE); + + key = (axis2_char_t *)AXIS2_MALLOC(env->allocator, sizeof(axis2_char_t) * 10); + + if(!key) + { + return AXIS2_FAILURE; + } + sprintf(key, "%d", soap_header->hbnumber++); + + if(soap_header->header_blocks) + { + axutil_hash_set(soap_header->header_blocks, key, AXIS2_HASH_KEY_STRING, header_block); + } + else + { + soap_header->header_blocks = axutil_hash_make(env); + axutil_hash_set(soap_header->header_blocks, key, AXIS2_HASH_KEY_STRING, header_block); + } + if(soap_header->header_block_keys) + { + axutil_array_list_add(soap_header->header_block_keys, env, key); + } + return AXIS2_SUCCESS; + +} +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_header_set_builder( + axiom_soap_header_t * soap_header, + const axutil_env_t * env, + struct axiom_soap_builder * builder) +{ + AXIS2_PARAM_CHECK(env->error, builder, AXIS2_FAILURE); + + soap_header->soap_builder = builder; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axutil_array_list_t *AXIS2_CALL +axiom_soap_header_get_header_blocks_with_namespace_uri( + axiom_soap_header_t * soap_header, + const axutil_env_t * env, + const axis2_char_t * ns_uri) +{ + axutil_array_list_t *header_block_list = NULL; + axutil_hash_index_t *hash_index = NULL; + + axiom_soap_header_block_t *header_block = NULL; + + axiom_node_t *header_block_om_node = NULL; + axiom_element_t *header_block_om_ele = NULL; + + axiom_namespace_t *ns = NULL; + axis2_char_t *hb_namespace_uri = NULL; + + int found = 0; + void *hb = NULL; + + AXIS2_PARAM_CHECK(env->error, ns_uri, NULL); + + if(!(soap_header->header_blocks)) + { + return NULL; + } + header_block_list = axutil_array_list_create(env, 10); + if(!header_block_list) + { + return NULL; + } + for(hash_index = axutil_hash_first(soap_header->header_blocks, env); hash_index; hash_index + = axutil_hash_next(env, hash_index)) + { + axutil_hash_this(hash_index, NULL, NULL, &hb); + if(hb) + { + header_block = (axiom_soap_header_block_t *)hb; + + header_block_om_node = axiom_soap_header_block_get_base_node(header_block, env); + if(header_block_om_node) + { + header_block_om_ele = (axiom_element_t *)axiom_node_get_data_element( + header_block_om_node, env); + if(header_block_om_ele) + { + ns + = axiom_element_get_namespace(header_block_om_ele, env, + header_block_om_node); + if(ns) + { + hb_namespace_uri = axiom_namespace_get_uri(ns, env); + if(axutil_strcmp(hb_namespace_uri, ns_uri) == 0) + { + axutil_array_list_add(header_block_list, env, header_block); + found++; + } + } + } + } + hb = NULL; + header_block = NULL; + header_block_om_ele = NULL; + header_block_om_node = NULL; + ns = NULL; + hb_namespace_uri = NULL; + } + } + if(found > 0) + { + return header_block_list; + } + else + { + axutil_array_list_free(header_block_list, env); + } + return NULL; +} + +AXIS2_EXTERN axutil_hash_t *AXIS2_CALL +axiom_soap_header_get_all_header_blocks( + axiom_soap_header_t * soap_header, + const axutil_env_t * env) +{ + return soap_header->header_blocks; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_header_remove_header_block( + axiom_soap_header_t * soap_header, + const axutil_env_t * env, + axutil_qname_t * qname) +{ + axis2_char_t *qn_localname = NULL; + axis2_char_t *qname_ns = NULL; + axis2_char_t *qname_prefix = NULL; + axutil_hash_index_t *hi = NULL; + + AXIS2_PARAM_CHECK(env->error, qname, AXIS2_FAILURE); + + qn_localname = axutil_qname_get_localpart(qname, env); + qname_ns = axutil_qname_get_uri(qname, env); + qname_prefix = axutil_qname_get_prefix(qname, env); + + if(!soap_header->header_blocks) + { + return AXIS2_FAILURE; + } + for(hi = axutil_hash_first(soap_header->header_blocks, env); hi; hi = axutil_hash_next(env, hi)) + { + const void *key = NULL; + void *val = NULL; + + axutil_hash_this(hi, &key, NULL, &val); + if(val) + { + axiom_soap_header_block_t *header_block = NULL; + axiom_element_t *ele = NULL; + axiom_node_t *node = NULL; + + header_block = (axiom_soap_header_block_t *)val; + node = axiom_soap_header_block_get_base_node(header_block, env); + if(node) + { + axutil_qname_t *element_qname = NULL; + + ele = (axiom_element_t *)axiom_node_get_data_element(node, env); + element_qname = axiom_element_get_qname(ele, env, node); + if(axiom_soap_header_qname_matches(env, element_qname, qname) == AXIS2_TRUE) + { + axiom_node_detach(node, env); + /* axiom_node_free_tree(node, env); */ + axutil_hash_set(soap_header->header_blocks, key, AXIS2_HASH_KEY_STRING, NULL); + axiom_soap_header_block_free(header_block, env); + axiom_node_free_tree(node, env); + break; + } + } + } + } + + if(hi) + { + AXIS2_FREE(env->allocator, hi); + } + + return AXIS2_SUCCESS; +} + +static axis2_bool_t AXIS2_CALL +axiom_soap_header_qname_matches( + const axutil_env_t * env, + axutil_qname_t * element_qname, + axutil_qname_t * qname_to_match) +{ + int lparts_match = 0; + int uris_match = 0; + axis2_char_t *ele_lpart = NULL; + axis2_char_t *match_lpart = NULL; + axis2_char_t *ele_nsuri = NULL; + axis2_char_t *match_nsuri = NULL; + + if(!(qname_to_match)) + { + return AXIS2_TRUE; + } + if(qname_to_match) + { + match_lpart = axutil_qname_get_localpart(qname_to_match, env); + match_nsuri = axutil_qname_get_uri(qname_to_match, env); + } + if(element_qname) + { + ele_lpart = axutil_qname_get_localpart(element_qname, env); + ele_nsuri = axutil_qname_get_uri(element_qname, env); + } + + lparts_match = (!match_lpart || (axutil_strcmp(match_lpart, "") == 0) || (element_qname + && (axutil_strcmp(ele_lpart, match_lpart) == 0))); + + uris_match = (!match_nsuri || (axutil_strcmp(match_nsuri, "") == 0) || (element_qname + && (axutil_strcmp(ele_nsuri, match_nsuri) == 0))); + + return lparts_match && uris_match; +} diff --git a/axiom/src/soap/soap_header_block.c b/axiom/src/soap/soap_header_block.c new file mode 100644 index 0000000..6f80f3a --- /dev/null +++ b/axiom/src/soap/soap_header_block.c @@ -0,0 +1,460 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <axiom_soap_const.h> +#include "_axiom_soap_header_block.h" +#include "_axiom_soap_header.h" +#include <axiom_soap_envelope.h> +#include <axiom_soap_builder.h> + +struct axiom_soap_header_block +{ + + /** om_element node corresponding to this headerblock */ + axiom_node_t *om_ele_node; + + /** soap version */ + int soap_version; + axis2_bool_t processed; +}; + +AXIS2_EXTERN axiom_soap_header_block_t *AXIS2_CALL +axiom_soap_header_block_create( + const axutil_env_t * env) +{ + axiom_soap_header_block_t *header_block = NULL; + AXIS2_ENV_CHECK(env, NULL); + header_block = (axiom_soap_header_block_t *)AXIS2_MALLOC(env->allocator, + sizeof(axiom_soap_header_block_t)); + if(!header_block) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory. Cannot create SOAP header block"); + return NULL; + } + + header_block->om_ele_node = NULL; + header_block->soap_version = AXIOM_SOAP_VERSION_NOT_SET; + header_block->processed = AXIS2_FALSE; + + return header_block; +} + +AXIS2_EXTERN axiom_soap_header_block_t *AXIS2_CALL +axiom_soap_header_block_create_with_parent( + const axutil_env_t * env, + const axis2_char_t * localname, + axiom_namespace_t * ns, + axiom_soap_header_t * header) +{ + axiom_soap_header_block_t *header_block = NULL; + axiom_node_t *this_node = NULL; + axiom_node_t *parent_node = NULL; + axiom_element_t *om_ele = NULL; + AXIS2_PARAM_CHECK(env->error, localname, NULL); + + header_block = axiom_soap_header_block_create(env); + if(!header_block) + { + return NULL; + } + parent_node = axiom_soap_header_get_base_node(header, env); + if(!parent_node) + { + return NULL; + } + om_ele = axiom_element_create(env, parent_node, localname, ns, &this_node); + if(!om_ele) + { + axiom_soap_header_block_free(header_block, env); + return NULL; + } + header_block->om_ele_node = this_node; + + axiom_soap_header_set_header_block(header, env, header_block); + + header_block->soap_version = axiom_soap_header_get_soap_version(header, env); + + return header_block; +} + +AXIS2_EXTERN void AXIS2_CALL +axiom_soap_header_block_free( + axiom_soap_header_block_t * header_block, + const axutil_env_t * env) +{ + AXIS2_FREE(env->allocator, header_block); + return; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_header_block_set_role( + axiom_soap_header_block_t * header_block, + const axutil_env_t * env, + axis2_char_t * role_uri) +{ + const axis2_char_t *attr_localname = NULL; + const axis2_char_t *attr_nsuri = NULL; + + if(header_block->soap_version == AXIOM_SOAP_VERSION_NOT_SET) + { + return AXIS2_FAILURE; + } + if(header_block->soap_version == AXIOM_SOAP11) + { + attr_localname = AXIOM_SOAP11_ATTR_ACTOR; + attr_nsuri = AXIOM_SOAP11_SOAP_ENVELOPE_NAMESPACE_URI; + } + if(header_block->soap_version == AXIOM_SOAP12) + { + attr_localname = AXIOM_SOAP12_SOAP_ROLE; + attr_nsuri = AXIOM_SOAP12_SOAP_ENVELOPE_NAMESPACE_URI; + } + axiom_soap_header_block_set_attribute(header_block, env, attr_localname, role_uri, attr_nsuri); + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL axiom_soap_header_block_get_role( + axiom_soap_header_block_t * header_block, + const axutil_env_t * env) +{ + const axis2_char_t *attr_localname = NULL; + const axis2_char_t *attr_nsuri = NULL; + + if (header_block->soap_version == AXIOM_SOAP_VERSION_NOT_SET) + { + return NULL; + } + if (header_block->soap_version == AXIOM_SOAP11) + { + attr_localname = AXIOM_SOAP11_ATTR_ACTOR; + attr_nsuri = AXIOM_SOAP11_SOAP_ENVELOPE_NAMESPACE_URI; + } + if (header_block->soap_version == AXIOM_SOAP12) + { + attr_localname = AXIOM_SOAP12_SOAP_ROLE; + attr_nsuri = AXIOM_SOAP12_SOAP_ENVELOPE_NAMESPACE_URI; + } + return axiom_soap_header_block_get_attribute(header_block, env, + attr_localname, attr_nsuri); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_header_block_set_must_understand_with_bool( + axiom_soap_header_block_t * header_block, + const axutil_env_t * env, + axis2_bool_t must_understand) +{ + const axis2_char_t *attr_nsuri = NULL; + const axis2_char_t *attr_value = NULL; + + if(header_block->soap_version == AXIOM_SOAP_VERSION_NOT_SET) + { + return AXIS2_FAILURE; + } + if(header_block->soap_version == AXIOM_SOAP11) + { + attr_nsuri = AXIOM_SOAP11_SOAP_ENVELOPE_NAMESPACE_URI; + } + if(header_block->soap_version == AXIOM_SOAP12) + { + attr_nsuri = AXIOM_SOAP12_SOAP_ENVELOPE_NAMESPACE_URI; + } + if(must_understand) + { + attr_value = "1"; + } + else + { + attr_value = "0"; + } + return axiom_soap_header_block_set_attribute(header_block, env, + AXIOM_SOAP_ATTR_MUST_UNDERSTAND, attr_value, attr_nsuri); + +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_header_block_set_must_understand_with_string( + axiom_soap_header_block_t * header_block, + const axutil_env_t * env, + axis2_char_t * must_understand) +{ + const axis2_char_t *attr_nsuri = NULL; + + AXIS2_PARAM_CHECK(env->error, must_understand, AXIS2_FAILURE); + + if(header_block->soap_version == AXIOM_SOAP_VERSION_NOT_SET) + { + return AXIS2_FAILURE; + } + if(header_block->soap_version == AXIOM_SOAP11) + { + attr_nsuri = AXIOM_SOAP11_SOAP_ENVELOPE_NAMESPACE_URI; + } + if(header_block->soap_version == AXIOM_SOAP12) + { + attr_nsuri = AXIOM_SOAP12_SOAP_ENVELOPE_NAMESPACE_URI; + } + + if(axutil_strcmp(AXIOM_SOAP_ATTR_MUST_UNDERSTAND_TRUE, must_understand) == 0 || axutil_strcmp( + AXIOM_SOAP_ATTR_MUST_UNDERSTAND_FALSE, must_understand) == 0 || axutil_strcmp( + AXIOM_SOAP_ATTR_MUST_UNDERSTAND_0, must_understand) == 0 || axutil_strcmp( + AXIOM_SOAP_ATTR_MUST_UNDERSTAND_1, must_understand) == 0) + { + + axiom_soap_header_block_set_attribute(header_block, env, AXIOM_SOAP_ATTR_MUST_UNDERSTAND, + must_understand, attr_nsuri); + return AXIS2_SUCCESS; + } + else + { + AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_MUST_UNDERSTAND_SHOULD_BE_1_0_TRUE_FALSE, AXIS2_FAILURE); + return AXIS2_FAILURE; + } +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +axiom_soap_header_block_get_must_understand( + axiom_soap_header_block_t * header_block, + const axutil_env_t * env) +{ + const axis2_char_t *must_understand = NULL; + const axis2_char_t *attr_nsuri = NULL; + + if(header_block->soap_version == AXIOM_SOAP_VERSION_NOT_SET) + { + return AXIS2_FAILURE; + } + if(header_block->soap_version == AXIOM_SOAP11) + { + attr_nsuri = AXIOM_SOAP11_SOAP_ENVELOPE_NAMESPACE_URI; + } + if(header_block->soap_version == AXIOM_SOAP12) + { + attr_nsuri = AXIOM_SOAP12_SOAP_ENVELOPE_NAMESPACE_URI; + } + must_understand = axiom_soap_header_block_get_attribute(header_block, env, + AXIOM_SOAP_ATTR_MUST_UNDERSTAND, attr_nsuri); + if(!must_understand) + { + return AXIS2_FALSE; + } + if(axutil_strcmp(must_understand, AXIOM_SOAP_ATTR_MUST_UNDERSTAND_1) == 0 || axutil_strcmp( + must_understand, AXIOM_SOAP_ATTR_MUST_UNDERSTAND_TRUE) == 0) + { + return AXIS2_TRUE; + } + else if(axutil_strcmp(must_understand, AXIOM_SOAP_ATTR_MUST_UNDERSTAND_0) == 0 + || axutil_strcmp(must_understand, AXIOM_SOAP_ATTR_MUST_UNDERSTAND_FALSE) == 0) + { + return AXIS2_FALSE; + } + AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_INVALID_VALUE_FOUND_IN_MUST_UNDERSTAND, AXIS2_FAILURE); + return AXIS2_FALSE; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_header_block_set_attribute( + axiom_soap_header_block_t * header_block, + const axutil_env_t * env, + const axis2_char_t * attr_name, + const axis2_char_t * attr_value, + const axis2_char_t * soap_envelope_namespace_uri) +{ + axiom_attribute_t *om_attr = NULL; + axiom_node_t *header_node = NULL; + axiom_element_t *header_ele = NULL; + axiom_namespace_t *header_ns = NULL; + axis2_char_t *prefix = NULL; + axutil_qname_t *qn = NULL; + axiom_namespace_t *om_ns = NULL; + axiom_element_t *om_ele = NULL; + + AXIS2_PARAM_CHECK(env->error, attr_name, AXIS2_FAILURE); + + header_node = axiom_node_get_parent(header_block->om_ele_node, env); + if(!header_node) + { + return AXIS2_FAILURE; + } + if(axiom_node_get_node_type(header_node, env) == AXIOM_ELEMENT) + { + header_ele = (axiom_element_t *)axiom_node_get_data_element(header_node, env); + if(!header_ele) + { + return AXIS2_FAILURE; + } + header_ns = axiom_element_get_namespace(header_ele, env, header_node); + if(!header_ns) + { + return AXIS2_FAILURE; + } + prefix = axiom_namespace_get_prefix(header_ns, env); + } + + qn = axutil_qname_create(env, attr_name, soap_envelope_namespace_uri, prefix); + + if(!qn) + { + return AXIS2_FAILURE; + } + if(!header_block->om_ele_node) + { + return AXIS2_FAILURE; + } + om_ele = (axiom_element_t *)axiom_node_get_data_element(header_block-> om_ele_node, env); + + om_attr = axiom_element_get_attribute(om_ele, env, qn); + + axutil_qname_free(qn, env); + if(om_attr) + { + return axiom_attribute_set_value(om_attr, env, attr_value); + } + if(soap_envelope_namespace_uri) + { + if(prefix) + { + om_ns = axiom_namespace_create(env, soap_envelope_namespace_uri, prefix); + } + else + { + om_ns = axiom_namespace_create(env, soap_envelope_namespace_uri, + AXIOM_SOAP_DEFAULT_NAMESPACE_PREFIX); + } + } + om_attr = axiom_attribute_create(env, attr_name, attr_value, om_ns); + if(!om_attr && om_ns) + { + axiom_namespace_free(om_ns, env); + return AXIS2_FAILURE; + } + + return axiom_element_add_attribute(om_ele, env, om_attr, header_block->om_ele_node); +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axiom_soap_header_block_get_attribute( + axiom_soap_header_block_t * header_block, + const axutil_env_t * env, + const axis2_char_t * attr_name, + const axis2_char_t * soap_envelope_namespace_uri) +{ + axiom_attribute_t *om_attr = NULL; + axis2_char_t *attr_value = NULL; + axiom_node_t *header_node = NULL; + axiom_element_t *header_ele = NULL; + axiom_namespace_t *header_ns = NULL; + axis2_char_t *prefix = NULL; + axutil_qname_t *qn = NULL; + axiom_element_t *om_ele = NULL; + AXIS2_PARAM_CHECK(env->error, attr_name, NULL); + AXIS2_PARAM_CHECK(env->error, soap_envelope_namespace_uri, NULL); + + header_node = axiom_node_get_parent(header_block->om_ele_node, env); + if(!header_node) + { + return NULL; + } + if(axiom_node_get_node_type(header_node, env) == AXIOM_ELEMENT) + { + header_ele = (axiom_element_t *)axiom_node_get_data_element(header_node, env); + if(!header_ele) + { + return NULL; + } + header_ns = axiom_element_get_namespace(header_ele, env, header_node); + if(!header_ns) + { + return NULL; + } + prefix = axiom_namespace_get_prefix(header_ns, env); + } + qn = axutil_qname_create(env, attr_name, soap_envelope_namespace_uri, prefix); + if(!qn) + { + return NULL; + } + om_ele = (axiom_element_t *)axiom_node_get_data_element(header_block-> om_ele_node, env); + om_attr = axiom_element_get_attribute(om_ele, env, qn); + if(om_attr) + { + attr_value = axiom_attribute_get_value(om_attr, env); + } + axutil_qname_free(qn, env); + return attr_value; +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +axiom_soap_header_block_is_processed( + axiom_soap_header_block_t * header_block, + const axutil_env_t * env) +{ + return header_block->processed; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_header_block_set_processed( + axiom_soap_header_block_t * header_block, + const axutil_env_t * env) +{ + header_block->processed = AXIS2_TRUE; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_header_block_set_base_node( + axiom_soap_header_block_t * header_block, + const axutil_env_t * env, + axiom_node_t * node) +{ + AXIS2_PARAM_CHECK(env->error, node, AXIS2_FAILURE); + + if(axiom_node_get_node_type(node, env) != AXIOM_ELEMENT) + { + AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_INVALID_BASE_TYPE, AXIS2_FAILURE); + return AXIS2_FAILURE; + } + header_block->om_ele_node = node; + return AXIS2_SUCCESS; + +} + +AXIS2_EXTERN axiom_node_t *AXIS2_CALL axiom_soap_header_block_get_base_node( + axiom_soap_header_block_t * header_block, + const axutil_env_t * env) +{ + return header_block->om_ele_node; +} + +AXIS2_EXTERN int AXIS2_CALL axiom_soap_header_block_get_soap_version( + axiom_soap_header_block_t * header_block, + const axutil_env_t * env) +{ + return header_block->soap_version; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_soap_header_block_set_soap_version( + axiom_soap_header_block_t * header_block, + const axutil_env_t * env, + int soap_version) +{ + + header_block->soap_version = soap_version; + return AXIS2_SUCCESS; +} |