Repository: qpid-proton Updated Branches: refs/heads/kgiusti-python3 99299d3b3 -> 9380ed938
PROTON-490: avoid decoding text if method calls fail Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/9380ed93 Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/9380ed93 Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/9380ed93 Branch: refs/heads/kgiusti-python3 Commit: 9380ed938fafa9e19cb0d3514725427d8243041b Parents: 99299d3 Author: Ken Giusti <[email protected]> Authored: Mon Apr 27 11:41:04 2015 -0400 Committer: Ken Giusti <[email protected]> Committed: Mon Apr 27 11:41:04 2015 -0400 ---------------------------------------------------------------------- proton-c/bindings/python/cproton.i | 40 ++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/9380ed93/proton-c/bindings/python/cproton.i ---------------------------------------------------------------------- diff --git a/proton-c/bindings/python/cproton.i b/proton-c/bindings/python/cproton.i index 328d68a..7317ca1 100644 --- a/proton-c/bindings/python/cproton.i +++ b/proton-c/bindings/python/cproton.i @@ -34,7 +34,6 @@ %include <cstring.i> -%cstring_output_withsize(char *OUTPUT, size_t *OUTPUT_SIZE) %cstring_output_allocate_size(char **ALLOC_OUTPUT, size_t *ALLOC_SIZE, free(*$1)); %cstring_output_maxsize(char *OUTPUT, size_t MAX_OUTPUT_SIZE) @@ -61,6 +60,27 @@ %append_output(PyBytes_FromStringAndSize($1,*$2)); } +// Typemap for those methods that return variable length text data in a buffer +// provided as a parameter. If the method fails we must avoid attempting to +// decode the contents of the buffer as it does not carry valid text data. +%typemap(in,noblock=1,fragment=SWIG_AsVal_frag(size_t)) (char *VTEXT_OUT, size_t *VTEXT_SIZE) +(int res, size_t n, char *buff = 0, $*2_ltype size) { + res = SWIG_AsVal(size_t)($input, &n); + if (!SWIG_IsOK(res)) { + %argument_fail(res, "(char *VTEXT_OUT, size_t *VTEXT_SIZE)", $symname, $argnum); + } + buff = %new_array(n+1, char); + $1 = %static_cast(buff, $1_ltype); + size = %numeric_cast(n,$*2_ltype); + $2 = &size; +} +%typemap(freearg,noblock=1,match="in")(char *VTEXT_OUT, size_t *VTEXT_SIZE) { + if (buff$argnum) %delete_array(buff$argnum); +} +%typemap(argout,noblock=1,fragment="SWIG_FromCharPtrAndSize") (char *VTEXT_OUT, size_t *VTEXT_SIZE) { + %append_output(SWIG_FromCharPtrAndSize($1,*$2)); +} + // These are not used/needed in the python binding %ignore pn_message_get_id; @@ -186,7 +206,14 @@ ssize_t pn_data_decode(pn_data_t *data, const char *BIN_IN, size_t BIN_LEN); %} %ignore pn_data_encode; -int pn_data_format(pn_data_t *data, char *OUTPUT, size_t *OUTPUT_SIZE); +%rename(pn_data_format) wrap_pn_data_format; +%inline %{ + int wrap_pn_data_format(pn_data_t *data, char *VTEXT_OUT, size_t *VTEXT_SIZE) { + int err = pn_data_format(data, VTEXT_OUT, VTEXT_SIZE); + if (err) *VTEXT_SIZE = 0; + return err; + } +%} %ignore pn_data_format; bool pn_ssl_get_cipher_name(pn_ssl_t *ssl, char *OUTPUT, size_t MAX_OUTPUT_SIZE); @@ -195,7 +222,14 @@ bool pn_ssl_get_cipher_name(pn_ssl_t *ssl, char *OUTPUT, size_t MAX_OUTPUT_SIZE) bool pn_ssl_get_protocol_name(pn_ssl_t *ssl, char *OUTPUT, size_t MAX_OUTPUT_SIZE); %ignore pn_ssl_get_protocol_name; -int pn_ssl_get_peer_hostname(pn_ssl_t *ssl, char *OUTPUT, size_t *OUTPUT_SIZE); +%rename(pn_ssl_get_peer_hostname) wrap_pn_ssl_get_peer_hostname; +%inline %{ + int wrap_pn_ssl_get_peer_hostname(pn_ssl_t *ssl, char *VTEXT_OUT, size_t *VTEXT_SIZE) { + int err = pn_ssl_get_peer_hostname(ssl, VTEXT_OUT, VTEXT_SIZE); + if (err) *VTEXT_SIZE = 0; + return err; + } +%} %ignore pn_ssl_get_peer_hostname; %immutable PN_PYREF; --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
