diff options
| author | Thomas Fitzsimmons | 2019-07-24 04:56:59 -0400 |
|---|---|---|
| committer | Thomas Fitzsimmons | 2019-07-24 05:05:44 -0400 |
| commit | 52e202a500116410fd97370535c6350a025d77bf (patch) | |
| tree | 99b5125d27e2c0aceeffe67b4ccfb96ae9627387 | |
| parent | c92cccb4ebb032ad15148e3ac7af014c1bbc1653 (diff) | |
| download | emacs-52e202a500116410fd97370535c6350a025d77bf.tar.gz emacs-52e202a500116410fd97370535c6350a025d77bf.zip | |
soap-client: Do not double-encode duplicate types
* lisp/net/soap-client.el (soap-encode-xs-complex-type): Eliminate
duplicates from type hierarchy before encoding values.
| -rw-r--r-- | lisp/net/soap-client.el | 111 |
1 files changed, 59 insertions, 52 deletions
diff --git a/lisp/net/soap-client.el b/lisp/net/soap-client.el index 7d04cef6a89..5526d624f96 100644 --- a/lisp/net/soap-client.el +++ b/lisp/net/soap-client.el | |||
| @@ -1660,7 +1660,8 @@ This is a specialization of `soap-encode-value' for | |||
| 1660 | (array | 1660 | (array |
| 1661 | (error "Arrays of type soap-encode-xs-complex-type are handled elsewhere")) | 1661 | (error "Arrays of type soap-encode-xs-complex-type are handled elsewhere")) |
| 1662 | ((sequence choice all nil) | 1662 | ((sequence choice all nil) |
| 1663 | (let ((type-list (list type))) | 1663 | (let ((type-list (list type)) |
| 1664 | (type-elements '())) | ||
| 1664 | 1665 | ||
| 1665 | ;; Collect all base types | 1666 | ;; Collect all base types |
| 1666 | (let ((base (soap-xs-complex-type-base type))) | 1667 | (let ((base (soap-xs-complex-type-base type))) |
| @@ -1668,60 +1669,66 @@ This is a specialization of `soap-encode-value' for | |||
| 1668 | (push base type-list) | 1669 | (push base type-list) |
| 1669 | (setq base (soap-xs-complex-type-base base)))) | 1670 | (setq base (soap-xs-complex-type-base base)))) |
| 1670 | 1671 | ||
| 1672 | ;; Collect type elements, eliminating duplicates from the type | ||
| 1673 | ;; hierarchy. | ||
| 1671 | (dolist (type type-list) | 1674 | (dolist (type type-list) |
| 1672 | (dolist (element (soap-xs-complex-type-elements type)) | 1675 | (dolist (element (soap-xs-complex-type-elements type)) |
| 1673 | (catch 'done | 1676 | (unless (member element type-elements) |
| 1674 | (let ((instance-count 0)) | 1677 | (setq type-elements (append type-elements (list element)))))) |
| 1675 | (dolist (candidate (soap-get-candidate-elements element)) | 1678 | |
| 1676 | (let ((e-name (soap-xs-element-name candidate))) | 1679 | (dolist (element type-elements) |
| 1677 | (if e-name | 1680 | (catch 'done |
| 1678 | (let ((e-name (intern e-name))) | 1681 | (let ((instance-count 0)) |
| 1679 | (dolist (v value) | 1682 | (dolist (candidate (soap-get-candidate-elements element)) |
| 1680 | (when (equal (car v) e-name) | 1683 | (let ((e-name (soap-xs-element-name candidate))) |
| 1681 | (cl-incf instance-count) | 1684 | (if e-name |
| 1682 | (soap-encode-value (cdr v) candidate)))) | 1685 | (let ((e-name (intern e-name))) |
| 1683 | (if (soap-xs-complex-type-indicator type) | ||
| 1684 | (let ((current-point (point))) | ||
| 1685 | ;; Check if encoding happened by checking if | ||
| 1686 | ;; characters were inserted in the buffer. | ||
| 1687 | (soap-encode-value value candidate) | ||
| 1688 | (when (not (equal current-point (point))) | ||
| 1689 | (cl-incf instance-count))) | ||
| 1690 | (dolist (v value) | 1686 | (dolist (v value) |
| 1691 | (let ((current-point (point))) | 1687 | (when (equal (car v) e-name) |
| 1692 | (soap-encode-value v candidate) | 1688 | (cl-incf instance-count) |
| 1693 | (when (not (equal current-point (point))) | 1689 | (soap-encode-value (cdr v) candidate)))) |
| 1694 | (cl-incf instance-count)))))))) | 1690 | (if (soap-xs-complex-type-indicator type) |
| 1695 | ;; Do some sanity checking | 1691 | (let ((current-point (point))) |
| 1696 | (let* ((indicator (soap-xs-complex-type-indicator type)) | 1692 | ;; Check if encoding happened by checking if |
| 1697 | (element-type (soap-xs-element-type element)) | 1693 | ;; characters were inserted in the buffer. |
| 1698 | (reference (soap-xs-element-reference element)) | 1694 | (soap-encode-value value candidate) |
| 1699 | (e-name (or (soap-xs-element-name element) | 1695 | (when (not (equal current-point (point))) |
| 1700 | (and reference | 1696 | (cl-incf instance-count))) |
| 1701 | (soap-xs-element-name reference))))) | 1697 | (dolist (v value) |
| 1702 | (cond ((and (eq indicator 'choice) | 1698 | (let ((current-point (point))) |
| 1703 | (> instance-count 0)) | 1699 | (soap-encode-value v candidate) |
| 1704 | ;; This was a choice node and we encoded | 1700 | (when (not (equal current-point (point))) |
| 1705 | ;; one instance. | 1701 | (cl-incf instance-count)))))))) |
| 1706 | (throw 'done t)) | 1702 | ;; Do some sanity checking |
| 1707 | ((and (not (eq indicator 'choice)) | 1703 | (let* ((indicator (soap-xs-complex-type-indicator type)) |
| 1708 | (= instance-count 0) | 1704 | (element-type (soap-xs-element-type element)) |
| 1709 | (not (soap-xs-element-optional? element)) | 1705 | (reference (soap-xs-element-reference element)) |
| 1710 | (and (soap-xs-complex-type-p element-type) | 1706 | (e-name (or (soap-xs-element-name element) |
| 1711 | (not (soap-xs-complex-type-optional-p | 1707 | (and reference |
| 1712 | element-type)))) | 1708 | (soap-xs-element-name reference))))) |
| 1713 | (soap-warning | 1709 | (cond ((and (eq indicator 'choice) |
| 1714 | "While encoding %s: missing non-nillable slot %s" | 1710 | (> instance-count 0)) |
| 1715 | value e-name)) | 1711 | ;; This was a choice node and we encoded |
| 1716 | ((and (> instance-count 1) | 1712 | ;; one instance. |
| 1717 | (not (soap-xs-element-multiple? element)) | 1713 | (throw 'done t)) |
| 1718 | (and (soap-xs-complex-type-p element-type) | 1714 | ((and (not (eq indicator 'choice)) |
| 1719 | (not (soap-xs-complex-type-multiple-p | 1715 | (= instance-count 0) |
| 1720 | element-type)))) | 1716 | (not (soap-xs-element-optional? element)) |
| 1721 | (soap-warning | 1717 | (and (soap-xs-complex-type-p element-type) |
| 1722 | (concat "While encoding %s: expected single," | 1718 | (not (soap-xs-complex-type-optional-p |
| 1723 | " found multiple elements for slot %s") | 1719 | element-type)))) |
| 1724 | value e-name)))))))))) | 1720 | (soap-warning |
| 1721 | "While encoding %s: missing non-nillable slot %s" | ||
| 1722 | value e-name)) | ||
| 1723 | ((and (> instance-count 1) | ||
| 1724 | (not (soap-xs-element-multiple? element)) | ||
| 1725 | (and (soap-xs-complex-type-p element-type) | ||
| 1726 | (not (soap-xs-complex-type-multiple-p | ||
| 1727 | element-type)))) | ||
| 1728 | (soap-warning | ||
| 1729 | (concat "While encoding %s: expected single," | ||
| 1730 | " found multiple elements for slot %s") | ||
| 1731 | value e-name))))))))) | ||
| 1725 | (t | 1732 | (t |
| 1726 | (error "Don't know how to encode complex type: %s" | 1733 | (error "Don't know how to encode complex type: %s" |
| 1727 | (soap-xs-complex-type-indicator type))))) | 1734 | (soap-xs-complex-type-indicator type))))) |