[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/xml-rpc 47007ef094 54/64: Merge pull request #14 from skan
From: |
Stefan Kangas |
Subject: |
[nongnu] elpa/xml-rpc 47007ef094 54/64: Merge pull request #14 from skangas/libxml-parse-xml-region |
Date: |
Fri, 31 Dec 2021 20:11:12 -0500 (EST) |
branch: elpa/xml-rpc
commit 47007ef094ea741eef4414fee5fc335e9b310e67
Merge: 4efc188b7f bd359a86b1
Author: Mark A. Hershberger <mah@everybody.org>
Commit: GitHub <noreply@github.com>
Merge pull request #14 from skangas/libxml-parse-xml-region
Use libxml when available to significantly improve performance
---
xml-rpc-test.el | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
xml-rpc.el | 28 ++++++++++++++++++++++------
2 files changed, 72 insertions(+), 6 deletions(-)
diff --git a/xml-rpc-test.el b/xml-rpc-test.el
index c84c47a728..1d6f1cf7d2 100644
--- a/xml-rpc-test.el
+++ b/xml-rpc-test.el
@@ -8,3 +8,53 @@
(should (eq (xml-rpc-value-structp '(("foo"))) t))
(should (eq (xml-rpc-value-structp '(("foo" . "bar"))) t))
(should (eq (xml-rpc-value-structp '(("foo" :datetime (12345 12345)))) t)))
+
+(defconst xml-rpc-test-http-data
+ "HTTP/1.1 200 OK
+Date: Sun, 06 Sep 2020 00:48:09 GMT
+Server: Apache/2.4.46 (Debian)
+Vary: Accept-Encoding
+Content-Length: 123
+Connection: close
+Content-Type: text/xml
+
+<?xml version=\"1.0\" encoding=\"UTF-8\"?>
+<methodResponse>
+<params>
+<param><value><string>0.9.8</string></value></param>
+</params>
+</methodResponse>")
+
+(defconst xml-rpc-test-scgi-data
+ "Status: 200 OK
+Content-Type: text/xml
+Content-Length: 152
+
+<?xml version=\"1.0\" encoding=\"UTF-8\"?>
+<methodResponse>
+<params>
+<param><value><string>0.9.8</string></value></param>
+</params>
+</methodResponse>
")
+
+(defconst xml-rpc-test-result
+ '((methodResponse nil (params nil (param nil (value nil (string nil
"0.9.8")))))))
+
+(ert-deftest test-xml-rpc-request-process-buffer/xml.el ()
+ (let ((xml-rpc-parse-region-function #'xml-parse-region))
+ (dolist (data (list xml-rpc-test-http-data
+ xml-rpc-test-scgi-data))
+ (with-temp-buffer
+ (insert data)
+ (should (equal (xml-rpc-request-process-buffer (current-buffer))
+ xml-rpc-test-result))))))
+
+(ert-deftest test-xml-rpc-request-process-buffer/libxml ()
+ (skip-unless (fboundp 'libxml-available-p))
+ (let ((xml-rpc-parse-region-function #'libxml-parse-xml-region))
+ (dolist (data (list xml-rpc-test-http-data
+ xml-rpc-test-scgi-data))
+ (with-temp-buffer
+ (insert data)
+ (should (equal (xml-rpc-request-process-buffer (current-buffer))
+ xml-rpc-test-result))))))
diff --git a/xml-rpc.el b/xml-rpc.el
index fa55525a12..fc2ddee211 100644
--- a/xml-rpc.el
+++ b/xml-rpc.el
@@ -244,6 +244,13 @@ utf-8 coding system."
Set it higher to get some info in the *Messages* buffer"
:type 'integer :group 'xml-rpc)
+(defvar xml-rpc-parse-region-function
+ (if (and (fboundp 'libxml-available-p)
+ (libxml-available-p))
+ #'libxml-parse-xml-region
+ #'xml-parse-region)
+ "Function to use for parsing XML data.")
+
(defvar xml-rpc-fault-string nil
"Contains the fault string if a fault is returned")
@@ -687,9 +694,11 @@ or nil if called with ASYNC-CALLBACK-FUNCTION."
url-http-response-status 200))
(result (cond
;; A probable XML response
- ((looking-at "<\\?xml ")
- (xml-rpc-clean (xml-parse-region (point-min)
- (point-max))))
+ ((search-forward "<?xml " nil t)
+ (xml-rpc-clean
+ (funcall xml-rpc-parse-region-function
+ (match-beginning 0)
+ (point-max))))
;; No HTTP status returned
((not status)
@@ -700,15 +709,22 @@ or nil if called with ASYNC-CALLBACK-FUNCTION."
;; Maybe they just gave us an the XML w/o PI?
((search-forward "<methodResponse>" nil t)
- (xml-rpc-clean (xml-parse-region (match-beginning 0)
- (point-max))))
+ (xml-rpc-clean
+ (funcall xml-rpc-parse-region-function
+ (match-beginning 0)
+ (point-max))))
;; Valid HTTP status
(t
(int-to-string status)))))
(when (< xml-rpc-debug 3)
(kill-buffer (current-buffer)))
- result))))
+ ;; Normalize result: `libxml-parse-xml-region' gives response like
+ ;; `(methodResponse ...)' but `xml-parse-region' gives
+ ;; `((methodResponse ...))'.
+ (if (eq xml-rpc-parse-region-function 'libxml-parse-xml-region)
+ (list result)
+ result)))))
(defun xml-rpc-request-callback-handler (callback-fun xml-buffer)
- [nongnu] elpa/xml-rpc 3b4ac0ebf2 24/64: update urls, (continued)
- [nongnu] elpa/xml-rpc 3b4ac0ebf2 24/64: update urls, Stefan Kangas, 2021/12/31
- [nongnu] elpa/xml-rpc 4b21d27d35 25/64: Eliminate xemacs compile warning, Stefan Kangas, 2021/12/31
- [nongnu] elpa/xml-rpc 643bbfb5da 30/64: * Apply link from http://rix3.8.je/2009/12/15/emacs%E7%9A%84weblogger1-4-4%E7%9A%84wordpress-patch/, Stefan Kangas, 2021/12/31
- [nongnu] elpa/xml-rpc 79e74a969d 21/64: Some minor housekeeping, bump xml-rpc.el version., Stefan Kangas, 2021/12/31
- [nongnu] elpa/xml-rpc f862301b46 27/64: connection close! connection close!, Stefan Kangas, 2021/12/31
- [nongnu] elpa/xml-rpc 445fc70355 33/64: point to upstream in comments, Stefan Kangas, 2021/12/31
- [nongnu] elpa/xml-rpc 8f624f8b96 44/64: Merge pull request #8 from larsmagne/master, Stefan Kangas, 2021/12/31
- [nongnu] elpa/xml-rpc 4fd5a03a36 36/64: xml-rpc.el: fix up callbacks for post emacs20!, Stefan Kangas, 2021/12/31
- [nongnu] elpa/xml-rpc e4002b8502 40/64: Really fix struct detection., Stefan Kangas, 2021/12/31
- [nongnu] elpa/xml-rpc 0ab093d601 42/64: Bump version number, Stefan Kangas, 2021/12/31
- [nongnu] elpa/xml-rpc 47007ef094 54/64: Merge pull request #14 from skangas/libxml-parse-xml-region,
Stefan Kangas <=
- [nongnu] elpa/xml-rpc ff1e22959f 50/64: Merge pull request #16 from skangas/byte-compiler-warnings, Stefan Kangas, 2021/12/31
- [nongnu] elpa/xml-rpc bd359a86b1 47/64: Use libxml-parse-xml-region when available, Stefan Kangas, 2021/12/31
- [nongnu] elpa/xml-rpc 31890fef63 60/64: Remove versions that don't have skip-unless, Stefan Kangas, 2021/12/31
- [nongnu] elpa/xml-rpc a2cb50528c 57/64: Tidy up a bit; remove code that shouldn't be needed in modern emacs, Stefan Kangas, 2021/12/31
- [nongnu] elpa/xml-rpc eb50e8b116 62/64: formatting, Stefan Kangas, 2021/12/31
- [nongnu] elpa/xml-rpc a876849b45 59/64: Merge pull request #18 from skangas/fix-unit-test, Stefan Kangas, 2021/12/31
- [nongnu] elpa/xml-rpc 8020ccd176 64/64: Badge++ and version bump, Stefan Kangas, 2021/12/31
- [nongnu] elpa/xml-rpc f87fef0844 10/64: Override timezone-parse-date with a version that understands the ISO8601 Basic format. (xml-rpc-value-structp): Struct test should look for consp instead of lists of a certain size. (xml-rpc-value-datetimep): Use :datetime keyword to specify data type and eliminate confusion between time structs and lists. (xml-rpc-xml-list-to-value): Grok <i4> element in addition to <int>. Return dateTime values with :datetime keyword. (xml-rpc-datetime-to-string): New function to format datetime objects. (xml-rpc-value-to-xml-list): Add handling for datetime., Stefan Kangas, 2021/12/31
- [nongnu] elpa/xml-rpc 67b151da07 02/64: initial commit, Stefan Kangas, 2021/12/31
- [nongnu] elpa/xml-rpc c0e1f70586 55/64: Bump for latest, Stefan Kangas, 2021/12/31