annotate lisp/url/url-dav.el @ 108830:0d7ed8742a5f

emulation/cua-base.el: Recognize `right-char', `left-char' as movement commands.
author Juanma Barranquero <lekktu@gmail.com>
date Sun, 30 May 2010 06:44:46 +0200
parents 1d1d5d9bd884
children 376148b31b5e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1 ;;; url-dav.el --- WebDAV support
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2
106815
1d1d5d9bd884 Add 2010 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
3 ;; Copyright (C) 2001, 2004, 2005, 2006, 2007, 2008, 2009, 2010
100908
a9dc0e7c3f2b Add 2009 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 96486
diff changeset
4 ;; Free Software Foundation, Inc.
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
5
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
6 ;; Author: Bill Perry <wmperry@gnu.org>
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
7 ;; Maintainer: Bill Perry <wmperry@gnu.org>
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
8 ;; Keywords: url, vc
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
9
54828
2eb49bad7ea9 Comments and docstring fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54795
diff changeset
10 ;; This file is part of GNU Emacs.
2eb49bad7ea9 Comments and docstring fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54795
diff changeset
11
94668
8259d0d8e107 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 87649
diff changeset
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
13 ;; it under the terms of the GNU General Public License as published by
94668
8259d0d8e107 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 87649
diff changeset
14 ;; the Free Software Foundation, either version 3 of the License, or
8259d0d8e107 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 87649
diff changeset
15 ;; (at your option) any later version.
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
16
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
17 ;; GNU Emacs is distributed in the hope that it will be useful,
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
20 ;; GNU General Public License for more details.
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
21
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
94668
8259d0d8e107 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 87649
diff changeset
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
24
54795
31399f1df768 (url-dav-rename-file): Fix args of `signal'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54770
diff changeset
25 ;; DAV is in RFC 2518.
31399f1df768 (url-dav-rename-file): Fix args of `signal'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54770
diff changeset
26
54828
2eb49bad7ea9 Comments and docstring fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54795
diff changeset
27 ;;; Commentary:
2eb49bad7ea9 Comments and docstring fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54795
diff changeset
28
2eb49bad7ea9 Comments and docstring fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54795
diff changeset
29 ;;; Code:
2eb49bad7ea9 Comments and docstring fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54795
diff changeset
30
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
31 (eval-when-compile
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
32 (require 'cl))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
33
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
34 (require 'xml)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
35 (require 'url-util)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
36 (require 'url-handlers)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
37
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
38 (defvar url-dav-supported-protocols '(1 2)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
39 "List of supported DAV versions.")
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
40
54795
31399f1df768 (url-dav-rename-file): Fix args of `signal'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54770
diff changeset
41 (defun url-intersection (l1 l2)
96486
7369ded3b436 Typo and docstring fixes.
Juanma Barranquero <lekktu@gmail.com>
parents: 94668
diff changeset
42 "Return a list of the elements occurring in both of the lists L1 and L2."
54795
31399f1df768 (url-dav-rename-file): Fix args of `signal'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54770
diff changeset
43 (if (null l2)
31399f1df768 (url-dav-rename-file): Fix args of `signal'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54770
diff changeset
44 l2
31399f1df768 (url-dav-rename-file): Fix args of `signal'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54770
diff changeset
45 (let (result)
31399f1df768 (url-dav-rename-file): Fix args of `signal'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54770
diff changeset
46 (while l1
31399f1df768 (url-dav-rename-file): Fix args of `signal'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54770
diff changeset
47 (if (member (car l1) l2)
31399f1df768 (url-dav-rename-file): Fix args of `signal'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54770
diff changeset
48 (setq result (cons (pop l1) result))
31399f1df768 (url-dav-rename-file): Fix args of `signal'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54770
diff changeset
49 (pop l1)))
31399f1df768 (url-dav-rename-file): Fix args of `signal'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54770
diff changeset
50 (nreverse result))))
31399f1df768 (url-dav-rename-file): Fix args of `signal'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54770
diff changeset
51
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
52 ;;;###autoload
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
53 (defun url-dav-supported-p (url)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
54 (and (featurep 'xml)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
55 (fboundp 'xml-expand-namespace)
54795
31399f1df768 (url-dav-rename-file): Fix args of `signal'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54770
diff changeset
56 (url-intersection url-dav-supported-protocols
31399f1df768 (url-dav-rename-file): Fix args of `signal'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54770
diff changeset
57 (plist-get (url-http-options url) 'dav))))
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
58
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
59 (defun url-dav-node-text (node)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
60 "Return the text data from the XML node NODE."
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
61 (mapconcat (lambda (txt)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
62 (if (stringp txt)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
63 txt
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
64 "")) (xml-node-children node) " "))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
65
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
66
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
67 ;;; Parsing routines for the actual node contents.
54828
2eb49bad7ea9 Comments and docstring fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54795
diff changeset
68 ;;
2eb49bad7ea9 Comments and docstring fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54795
diff changeset
69 ;; I am not incredibly happy with how this code looks/works right
2eb49bad7ea9 Comments and docstring fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54795
diff changeset
70 ;; now, but it DOES work, and if we get the API right, our callers
2eb49bad7ea9 Comments and docstring fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54795
diff changeset
71 ;; won't have to worry about the internal representation.
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
72
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
73 (defconst url-dav-datatype-attribute
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
74 'urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/dt)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
75
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
76 (defun url-dav-process-integer-property (node)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
77 (truncate (string-to-number (url-dav-node-text node))))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
78
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
79 (defun url-dav-process-number-property (node)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
80 (string-to-number (url-dav-node-text node)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
81
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
82 (defconst url-dav-iso8601-regexp
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
83 (let* ((dash "-?")
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
84 (colon ":?")
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
85 (4digit "\\([0-9][0-9][0-9][0-9]\\)")
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
86 (2digit "\\([0-9][0-9]\\)")
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
87 (date-fullyear 4digit)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
88 (date-month 2digit)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
89 (date-mday 2digit)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
90 (time-hour 2digit)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
91 (time-minute 2digit)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
92 (time-second 2digit)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
93 (time-secfrac "\\(\\.[0-9]+\\)?")
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
94 (time-numoffset (concat "[-+]\\(" time-hour "\\):" time-minute))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
95 (time-offset (concat "Z" time-numoffset))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
96 (partial-time (concat time-hour colon time-minute colon time-second
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
97 time-secfrac))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
98 (full-date (concat date-fullyear dash date-month dash date-mday))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
99 (full-time (concat partial-time time-offset))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
100 (date-time (concat full-date "T" full-time)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
101 (list (concat "^" full-date)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
102 (concat "T" partial-time)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
103 (concat "Z" time-numoffset)))
96486
7369ded3b436 Typo and docstring fixes.
Juanma Barranquero <lekktu@gmail.com>
parents: 94668
diff changeset
104 "List of regular expressions matching ISO 8601 dates.
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
105 1st regular expression matches the date.
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
106 2nd regular expression matches the time.
54828
2eb49bad7ea9 Comments and docstring fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54795
diff changeset
107 3rd regular expression matches the (optional) timezone specification.")
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
108
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
109 (defun url-dav-process-date-property (node)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
110 (require 'parse-time)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
111 (let* ((date-re (nth 0 url-dav-iso8601-regexp))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
112 (time-re (nth 1 url-dav-iso8601-regexp))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
113 (tz-re (nth 2 url-dav-iso8601-regexp))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
114 (date-string (url-dav-node-text node))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
115 re-start
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
116 time seconds minute hour fractional-seconds
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
117 day month year day-of-week dst tz)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
118 ;; We need to populate 'time' with
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
119 ;; (SEC MIN HOUR DAY MON YEAR DOW DST TZ)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
120
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
121 ;; Nobody else handles iso8601 correctly, lets do it ourselves.
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
122 (when (string-match date-re date-string re-start)
62400
e30c08177a3b Replace `string-to-int' by `string-to-number'.
Juanma Barranquero <lekktu@gmail.com>
parents: 54929
diff changeset
123 (setq year (string-to-number (match-string 1 date-string))
e30c08177a3b Replace `string-to-int' by `string-to-number'.
Juanma Barranquero <lekktu@gmail.com>
parents: 54929
diff changeset
124 month (string-to-number (match-string 2 date-string))
e30c08177a3b Replace `string-to-int' by `string-to-number'.
Juanma Barranquero <lekktu@gmail.com>
parents: 54929
diff changeset
125 day (string-to-number (match-string 3 date-string))
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
126 re-start (match-end 0))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
127 (when (string-match time-re date-string re-start)
62400
e30c08177a3b Replace `string-to-int' by `string-to-number'.
Juanma Barranquero <lekktu@gmail.com>
parents: 54929
diff changeset
128 (setq hour (string-to-number (match-string 1 date-string))
e30c08177a3b Replace `string-to-int' by `string-to-number'.
Juanma Barranquero <lekktu@gmail.com>
parents: 54929
diff changeset
129 minute (string-to-number (match-string 2 date-string))
e30c08177a3b Replace `string-to-int' by `string-to-number'.
Juanma Barranquero <lekktu@gmail.com>
parents: 54929
diff changeset
130 seconds (string-to-number (match-string 3 date-string))
e30c08177a3b Replace `string-to-int' by `string-to-number'.
Juanma Barranquero <lekktu@gmail.com>
parents: 54929
diff changeset
131 fractional-seconds (string-to-number (or
e30c08177a3b Replace `string-to-int' by `string-to-number'.
Juanma Barranquero <lekktu@gmail.com>
parents: 54929
diff changeset
132 (match-string 4 date-string)
e30c08177a3b Replace `string-to-int' by `string-to-number'.
Juanma Barranquero <lekktu@gmail.com>
parents: 54929
diff changeset
133 "0"))
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
134 re-start (match-end 0))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
135 (when (string-match tz-re date-string re-start)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
136 (setq tz (match-string 1 date-string)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
137 (url-debug 'dav "Parsed iso8601%s date" (if tz "tz" ""))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
138 (setq time (list seconds minute hour day month year day-of-week dst tz))))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
139
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
140 ;; Fall back to having Gnus do fancy things for us.
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
141 (when (not time)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
142 (setq time (parse-time-string date-string)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
143
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
144 (if time
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
145 (setq time (apply 'encode-time time))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
146 (url-debug 'dav "Unable to decode date (%S) (%s)"
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
147 (xml-node-name node) date-string))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
148 time))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
149
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
150 (defun url-dav-process-boolean-property (node)
62400
e30c08177a3b Replace `string-to-int' by `string-to-number'.
Juanma Barranquero <lekktu@gmail.com>
parents: 54929
diff changeset
151 (/= 0 (string-to-number (url-dav-node-text node))))
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
152
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
153 (defun url-dav-process-uri-property (node)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
154 ;; Returns a parsed representation of the URL...
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
155 (url-generic-parse-url (url-dav-node-text node)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
156
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
157 (defun url-dav-find-parser (node)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
158 "Find a function to parse the XML node NODE."
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
159 (or (get (xml-node-name node) 'dav-parser)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
160 (let ((fn (intern (format "url-dav-process-%s" (xml-node-name node)))))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
161 (if (not (fboundp fn))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
162 (setq fn 'url-dav-node-text)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
163 (put (xml-node-name node) 'dav-parser fn))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
164 fn)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
165
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
166 (defmacro url-dav-dispatch-node (node)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
167 `(funcall (url-dav-find-parser ,node) ,node))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
168
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
169 (defun url-dav-process-DAV:prop (node)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
170 ;; A prop node has content model of ANY
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
171 ;;
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
172 ;; Some predefined nodes have special meanings though.
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
173 ;;
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
174 ;; DAV:supportedlock - list of DAV:lockentry
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
175 ;; DAV:source
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
176 ;; DAV:iscollection - boolean
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
177 ;; DAV:getcontentlength - integer
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
178 ;; DAV:ishidden - boolean
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
179 ;; DAV:getcontenttype - string
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
180 ;; DAV:resourcetype - node who's name is the resource type
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
181 ;; DAV:getlastmodified - date
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
182 ;; DAV:creationdate - date
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
183 ;; DAV:displayname - string
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
184 ;; DAV:getetag - unknown
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
185 (let ((children (xml-node-children node))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
186 (node-type nil)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
187 (props nil)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
188 (value nil)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
189 (handler-func nil))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
190 (when (not children)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
191 (error "No child nodes in DAV:prop"))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
192
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
193 (while children
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
194 (setq node (car children)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
195 node-type (intern
84929
ffdba9eb7f4e (top): Use `mapc' rather than `mapcar'.
Juanma Barranquero <lekktu@gmail.com>
parents: 78481
diff changeset
196 (or
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
197 (cdr-safe (assq url-dav-datatype-attribute
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
198 (xml-node-attributes node)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
199 "unknown"))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
200 value nil)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
201
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
202 (case node-type
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
203 ((dateTime.iso8601tz
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
204 dateTime.iso8601
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
205 dateTime.tz
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
206 dateTime.rfc1123
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
207 dateTime
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
208 date) ; date is our 'special' one...
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
209 ;; Some type of date/time string.
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
210 (setq value (url-dav-process-date-property node)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
211 (int
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
212 ;; Integer type...
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
213 (setq value (url-dav-process-integer-property node)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
214 ((number float)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
215 (setq value (url-dav-process-number-property node)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
216 (boolean
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
217 (setq value (url-dav-process-boolean-property node)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
218 (uri
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
219 (setq value (url-dav-process-uri-property node)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
220 (otherwise
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
221 (if (not (eq node-type 'unknown))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
222 (url-debug 'dav "Unknown data type in url-dav-process-prop: %s"
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
223 node-type))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
224 (setq value (url-dav-dispatch-node node))))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
225
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
226 (setq props (plist-put props (xml-node-name node) value)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
227 children (cdr children)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
228 props))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
229
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
230 (defun url-dav-process-DAV:supportedlock (node)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
231 ;; DAV:supportedlock is a list of DAV:lockentry items.
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
232 ;; DAV:lockentry in turn contains a DAV:lockscope and DAV:locktype.
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
233 ;; The DAV:lockscope must have a single node beneath it, ditto for
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
234 ;; DAV:locktype.
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
235 (let ((children (xml-node-children node))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
236 (results nil)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
237 scope type)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
238 (while children
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
239 (when (and (not (stringp (car children)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
240 (eq (xml-node-name (car children)) 'DAV:lockentry))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
241 (setq scope (assq 'DAV:lockscope (xml-node-children (car children)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
242 type (assq 'DAV:locktype (xml-node-children (car children))))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
243 (when (and scope type)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
244 (setq scope (xml-node-name (car (xml-node-children scope)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
245 type (xml-node-name (car (xml-node-children type))))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
246 (push (cons type scope) results)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
247 (setq children (cdr children)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
248 results))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
249
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
250 (defun url-dav-process-subnode-property (node)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
251 ;; Returns a list of child node names.
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
252 (delq nil (mapcar 'car-safe (xml-node-children node))))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
253
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
254 (defalias 'url-dav-process-DAV:depth 'url-dav-process-integer-property)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
255 (defalias 'url-dav-process-DAV:resourcetype 'url-dav-process-subnode-property)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
256 (defalias 'url-dav-process-DAV:locktype 'url-dav-process-subnode-property)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
257 (defalias 'url-dav-process-DAV:lockscope 'url-dav-process-subnode-property)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
258 (defalias 'url-dav-process-DAV:getcontentlength 'url-dav-process-integer-property)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
259 (defalias 'url-dav-process-DAV:getlastmodified 'url-dav-process-date-property)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
260 (defalias 'url-dav-process-DAV:creationdate 'url-dav-process-date-property)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
261 (defalias 'url-dav-process-DAV:iscollection 'url-dav-process-boolean-property)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
262 (defalias 'url-dav-process-DAV:ishidden 'url-dav-process-boolean-property)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
263
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
264 (defun url-dav-process-DAV:locktoken (node)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
265 ;; DAV:locktoken can have one or more DAV:href children.
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
266 (delq nil (mapcar (lambda (n)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
267 (if (stringp n)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
268 n
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
269 (url-dav-dispatch-node n)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
270 (xml-node-children node))))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
271
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
272 (defun url-dav-process-DAV:owner (node)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
273 ;; DAV:owner can contain anything.
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
274 (delq nil (mapcar (lambda (n)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
275 (if (stringp n)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
276 n
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
277 (url-dav-dispatch-node n)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
278 (xml-node-children node))))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
279
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
280 (defun url-dav-process-DAV:activelock (node)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
281 ;; DAV:activelock can contain:
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
282 ;; DAV:lockscope
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
283 ;; DAV:locktype
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
284 ;; DAV:depth
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
285 ;; DAV:owner (optional)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
286 ;; DAV:timeout (optional)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
287 ;; DAV:locktoken (optional)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
288 (let ((children (xml-node-children node))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
289 (results nil))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
290 (while children
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
291 (if (listp (car children))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
292 (push (cons (xml-node-name (car children))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
293 (url-dav-dispatch-node (car children)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
294 results))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
295 (setq children (cdr children)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
296 results))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
297
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
298 (defun url-dav-process-DAV:lockdiscovery (node)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
299 ;; Can only contain a list of DAV:activelock objects.
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
300 (let ((children (xml-node-children node))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
301 (results nil))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
302 (while children
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
303 (cond
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
304 ((stringp (car children))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
305 ;; text node? why?
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
306 nil)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
307 ((eq (xml-node-name (car children)) 'DAV:activelock)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
308 (push (url-dav-dispatch-node (car children)) results))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
309 (t
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
310 ;; Ignore unknown nodes...
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
311 nil))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
312 (setq children (cdr children)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
313 results))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
314
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
315 (defun url-dav-process-DAV:status (node)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
316 ;; The node contains a standard HTTP/1.1 response line... we really
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
317 ;; only care about the numeric status code.
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
318 (let ((status (url-dav-node-text node)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
319 (if (string-match "\\`[ \r\t\n]*HTTP/[0-9.]+ \\([0-9]+\\)" status)
62400
e30c08177a3b Replace `string-to-int' by `string-to-number'.
Juanma Barranquero <lekktu@gmail.com>
parents: 54929
diff changeset
320 (string-to-number (match-string 1 status))
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
321 500)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
322
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
323 (defun url-dav-process-DAV:propstat (node)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
324 ;; A propstate node can have the following children...
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
325 ;;
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
326 ;; DAV:prop - a list of properties and values
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
327 ;; DAV:status - An HTTP/1.1 status line
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
328 (let ((children (xml-node-children node))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
329 (props nil)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
330 (status nil))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
331 (when (not children)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
332 (error "No child nodes in DAV:propstat"))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
333
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
334 (setq props (url-dav-dispatch-node (assq 'DAV:prop children))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
335 status (url-dav-dispatch-node (assq 'DAV:status children)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
336
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
337 ;; Need to parse out the HTTP status
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
338 (setq props (plist-put props 'DAV:status status))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
339 props))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
340
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
341 (defun url-dav-process-DAV:response (node)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
342 (let ((children (xml-node-children node))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
343 (propstat nil)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
344 (href))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
345 (when (not children)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
346 (error "No child nodes in DAV:response"))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
347
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
348 ;; A response node can have the following children...
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
349 ;;
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
350 ;; DAV:href - URL the response is for.
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
351 ;; DAV:propstat - see url-dav-process-propstat
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
352 ;; DAV:responsedescription - text description of the response
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
353 (setq propstat (assq 'DAV:propstat children)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
354 href (assq 'DAV:href children))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
355
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
356 (when (not href)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
357 (error "No href in DAV:response"))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
358
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
359 (when (not propstat)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
360 (error "No propstat in DAV:response"))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
361
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
362 (setq propstat (url-dav-dispatch-node propstat)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
363 href (url-dav-dispatch-node href))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
364 (cons href propstat)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
365
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
366 (defun url-dav-process-DAV:multistatus (node)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
367 (let ((children (xml-node-children node))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
368 (results nil))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
369 (while children
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
370 (push (url-dav-dispatch-node (car children)) results)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
371 (setq children (cdr children)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
372 results))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
373
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
374
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
375 ;;; DAV request/response generation/processing
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
376 (defun url-dav-process-response (buffer url)
54828
2eb49bad7ea9 Comments and docstring fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54795
diff changeset
377 "Parse a WebDAV response from BUFFER, interpreting it relative to URL.
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
378
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
379 The buffer must have been retrieved by HTTP or HTTPS and contain an
54828
2eb49bad7ea9 Comments and docstring fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54795
diff changeset
380 XML document."
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
381 (declare (special url-http-content-type
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
382 url-http-response-status
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
383 url-http-end-of-headers))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
384 (let ((tree nil)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
385 (overall-status nil))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
386 (when buffer
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
387 (unwind-protect
54929
42040974ab42 Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54828
diff changeset
388 (with-current-buffer buffer
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
389 (goto-char url-http-end-of-headers)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
390 (setq overall-status url-http-response-status)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
391
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
392 ;; XML documents can be transferred as either text/xml or
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
393 ;; application/xml, and we are required to accept both of
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
394 ;; them.
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
395 (if (and
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
396 url-http-content-type
54929
42040974ab42 Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54828
diff changeset
397 (string-match "\\`\\(text\\|application\\)/xml"
42040974ab42 Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54828
diff changeset
398 url-http-content-type))
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
399 (setq tree (xml-parse-region (point) (point-max)))))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
400 ;; Clean up after ourselves.
54929
42040974ab42 Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54828
diff changeset
401 (kill-buffer buffer)))
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
402
54929
42040974ab42 Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54828
diff changeset
403 ;; We should now be
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
404 (if (eq (xml-node-name (car tree)) 'DAV:multistatus)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
405 (url-dav-dispatch-node (car tree))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
406 (url-debug 'dav "Got back singleton response for URL(%S)" url)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
407 (let ((properties (url-dav-dispatch-node (car tree))))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
408 ;; We need to make sure we have a DAV:status node in there for
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
409 ;; higher-level code;
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
410 (setq properties (plist-put properties 'DAV:status overall-status))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
411 ;; Make this look like a DAV:multistatus parse tree so that
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
412 ;; nobody but us needs to know the difference.
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
413 (list (cons url properties))))))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
414
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
415 (defun url-dav-request (url method tag body
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
416 &optional depth headers namespaces)
54828
2eb49bad7ea9 Comments and docstring fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54795
diff changeset
417 "Perform WebDAV operation METHOD on URL. Return the parsed responses.
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
418 Automatically creates an XML request body if TAG is non-nil.
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
419 BODY is the XML document fragment to be enclosed by <TAG></TAG>.
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
420
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
421 DEPTH is how deep the request should propogate. Default is 0, meaning
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
422 it should apply only to URL. A negative number means to use
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
423 `Infinity' for the depth. Not all WebDAV servers support this depth
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
424 though.
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
425
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
426 HEADERS is an assoc list of extra headers to send in the request.
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
427
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
428 NAMESPACES is an assoc list of (NAMESPACE . EXPANSION), and these are
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
429 added to the <TAG> element. The DAV=DAV: namespace is automatically
54828
2eb49bad7ea9 Comments and docstring fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54795
diff changeset
430 added to this list, so most requests can just pass in nil."
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
431 ;; Take care of the default value for depth...
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
432 (setq depth (or depth 0))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
433
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
434 ;; Now lets translate it into something webdav can understand.
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
435 (if (< depth 0)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
436 (setq depth "Infinity")
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
437 (setq depth (int-to-string depth)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
438 (if (not (assoc "DAV" namespaces))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
439 (setq namespaces (cons '("DAV" . "DAV:") namespaces)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
440
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
441 (let* ((url-request-extra-headers `(("Depth" . ,depth)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
442 ("Content-type" . "text/xml")
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
443 ,@headers))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
444 (url-request-method method)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
445 (url-request-data
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
446 (if tag
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
447 (concat
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
448 "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
449 "<" (symbol-name tag) " "
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
450 ;; add in the appropriate namespaces...
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
451 (mapconcat (lambda (ns)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
452 (concat "xmlns:" (car ns) "='" (cdr ns) "'"))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
453 namespaces "\n ")
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
454 ">\n"
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
455 body
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
456 "</" (symbol-name tag) ">\n"))))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
457 (url-dav-process-response (url-retrieve-synchronously url) url)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
458
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
459 (defun url-dav-get-properties (url &optional attributes depth namespaces)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
460 "Return properties for URL, up to DEPTH levels deep.
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
461
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
462 Returns an assoc list, where the key is the filename (possibly a full
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
463 URI), and the value is a standard property list of DAV property
54828
2eb49bad7ea9 Comments and docstring fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54795
diff changeset
464 names (ie: DAV:resourcetype)."
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
465 (url-dav-request url "PROPFIND" 'DAV:propfind
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
466 (if attributes
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
467 (mapconcat (lambda (attr)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
468 (concat "<DAV:prop><"
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
469 (symbol-name attr)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
470 "/></DAV:prop>"))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
471 attributes "\n ")
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
472 " <DAV:allprop/>")
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
473 depth nil namespaces))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
474
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
475 (defmacro url-dav-http-success-p (status)
96486
7369ded3b436 Typo and docstring fixes.
Juanma Barranquero <lekktu@gmail.com>
parents: 94668
diff changeset
476 "Return whether STATUS was the result of a successful DAV request."
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
477 `(= (/ (or ,status 500) 100) 2))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
478
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
479
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
480 ;;; Locking support
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
481 (defvar url-dav-lock-identifier (concat "mailto:" user-mail-address)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
482 "*URL used as contact information when creating locks in DAV.
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
483 This will be used as the contents of the DAV:owner/DAV:href tag to
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
484 identify the owner of a LOCK when requesting it. This will be shown
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
485 to other users when the DAV:lockdiscovery property is requested, so
54828
2eb49bad7ea9 Comments and docstring fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54795
diff changeset
486 make sure you are comfortable with it leaking to the outside world.")
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
487
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
488 (defun url-dav-lock-resource (url exclusive &optional depth)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
489 "Request a lock on URL. If EXCLUSIVE is non-nil, get an exclusive lock.
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
490 Optional 3rd argument DEPTH says how deep the lock should go, default is 0
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
491 \(lock only the resource and none of its children\).
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
492
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
493 Returns a cons-cell of (SUCCESSFUL-RESULTS . FAILURE-RESULTS).
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
494 SUCCESSFUL-RESULTS is a list of (URL STATUS locktoken).
54828
2eb49bad7ea9 Comments and docstring fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54795
diff changeset
495 FAILURE-RESULTS is a list of (URL STATUS)."
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
496 (setq exclusive (if exclusive "<DAV:exclusive/>" "<DAV:shared/>"))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
497 (let* ((body
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
498 (concat
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
499 " <DAV:lockscope>" exclusive "</DAV:lockscope>\n"
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
500 " <DAV:locktype> <DAV:write/> </DAV:locktype>\n"
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
501 " <DAV:owner>\n"
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
502 " <DAV:href>" url-dav-lock-identifier "</DAV:href>\n"
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
503 " </DAV:owner>\n"))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
504 (response nil) ; Responses to the LOCK request
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
505 (result nil) ; For walking thru the response list
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
506 (child-url nil)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
507 (child-status nil)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
508 (failures nil) ; List of failure cases (URL . STATUS)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
509 (successes nil)) ; List of success cases (URL . STATUS)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
510 (setq response (url-dav-request url "LOCK" 'DAV:lockinfo body
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
511 depth '(("Timeout" . "Infinite"))))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
512
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
513 ;; Get the parent URL ready for expand-file-name
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
514 (if (not (vectorp url))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
515 (setq url (url-generic-parse-url url)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
516
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
517 ;; Walk thru the response list, fully expand the URL, and grab the
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
518 ;; status code.
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
519 (while response
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
520 (setq result (pop response)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
521 child-url (url-expand-file-name (pop result) url)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
522 child-status (or (plist-get result 'DAV:status) 500))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
523 (if (url-dav-http-success-p child-status)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
524 (push (list url child-status "huh") successes)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
525 (push (list url child-status) failures)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
526 (cons successes failures)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
527
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
528 (defun url-dav-active-locks (url &optional depth)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
529 "Return an assoc list of all active locks on URL."
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
530 (let ((response (url-dav-get-properties url '(DAV:lockdiscovery) depth))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
531 (properties nil)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
532 (child nil)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
533 (child-url nil)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
534 (child-results nil)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
535 (results nil))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
536 (if (not (vectorp url))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
537 (setq url (url-generic-parse-url url)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
538
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
539 (while response
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
540 (setq child (pop response)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
541 child-url (pop child)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
542 child-results nil)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
543 (when (and (url-dav-http-success-p (plist-get child 'DAV:status))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
544 (setq child (plist-get child 'DAV:lockdiscovery)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
545 ;; After our parser has had its way with it, The
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
546 ;; DAV:lockdiscovery property is a list of DAV:activelock
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
547 ;; objects, which are comprised of DAV:activelocks, which
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
548 ;; assoc lists of properties and values.
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
549 (while child
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
550 (if (assq 'DAV:locktoken (car child))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
551 (let ((tokens (cdr (assq 'DAV:locktoken (car child))))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
552 (owners (cdr (assq 'DAV:owner (car child)))))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
553 (dolist (token tokens)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
554 (dolist (owner owners)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
555 (push (cons token owner) child-results)))))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
556 (pop child)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
557 (if child-results
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
558 (push (cons (url-expand-file-name child-url url) child-results)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
559 results)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
560 results))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
561
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
562 (defun url-dav-unlock-resource (url lock-token)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
563 "Release the lock on URL represented by LOCK-TOKEN.
78481
bc53aa750f3b Replace `iff' in doc-strings and comments.
Glenn Morris <rgm@gnu.org>
parents: 78222
diff changeset
564 Returns t if the lock was successfully released."
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
565 (declare (special url-http-response-status))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
566 (let* ((url-request-extra-headers (list (cons "Lock-Token"
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
567 (concat "<" lock-token ">"))))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
568 (url-request-method "UNLOCK")
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
569 (url-request-data nil)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
570 (buffer (url-retrieve-synchronously url))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
571 (result nil))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
572 (when buffer
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
573 (unwind-protect
54929
42040974ab42 Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54828
diff changeset
574 (with-current-buffer buffer
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
575 (setq result (url-dav-http-success-p url-http-response-status)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
576 (kill-buffer buffer)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
577 result))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
578
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
579
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
580 ;;; file-name-handler stuff
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
581 (defun url-dav-file-attributes-mode-string (properties)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
582 (let ((modes (make-string 10 ?-))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
583 (supported-locks (plist-get properties 'DAV:supportedlock))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
584 (executable-p (equal (plist-get properties 'http://apache.org/dav/props/executable)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
585 "T"))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
586 (directory-p (memq 'DAV:collection (plist-get properties 'DAV:resourcetype)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
587 (readable t)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
588 (lock nil))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
589 ;; Assume we can read this, otherwise the PROPFIND would have
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
590 ;; failed.
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
591 (when readable
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
592 (aset modes 1 ?r)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
593 (aset modes 4 ?r)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
594 (aset modes 7 ?r))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
595
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
596 (when directory-p
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
597 (aset modes 0 ?d))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
598
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
599 (when executable-p
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
600 (aset modes 3 ?x)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
601 (aset modes 6 ?x)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
602 (aset modes 9 ?x))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
603
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
604 (while supported-locks
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
605 (setq lock (car supported-locks)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
606 supported-locks (cdr supported-locks))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
607 (case (car lock)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
608 (DAV:write
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
609 (case (cdr lock)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
610 (DAV:shared ; group permissions (possibly world)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
611 (aset modes 5 ?w))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
612 (DAV:exclusive
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
613 (aset modes 2 ?w)) ; owner permissions?
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
614 (otherwise
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
615 (url-debug 'dav "Unrecognized DAV:lockscope (%S)" (cdr lock)))))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
616 (otherwise
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
617 (url-debug 'dav "Unrecognized DAV:locktype (%S)" (car lock)))))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
618 modes))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
619
54795
31399f1df768 (url-dav-rename-file): Fix args of `signal'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54770
diff changeset
620 (autoload 'url-http-head-file-attributes "url-http")
31399f1df768 (url-dav-rename-file): Fix args of `signal'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54770
diff changeset
621
54929
42040974ab42 Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54828
diff changeset
622 (defun url-dav-file-attributes (url &optional id-format)
73023
b401f081156a (url-dav-file-attributes): Simplify.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68640
diff changeset
623 (let ((properties (cdar (url-dav-get-properties url))))
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
624 (if (and properties
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
625 (url-dav-http-success-p (plist-get properties 'DAV:status)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
626 ;; We got a good DAV response back..
73023
b401f081156a (url-dav-file-attributes): Simplify.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68640
diff changeset
627 (list
b401f081156a (url-dav-file-attributes): Simplify.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68640
diff changeset
628 ;; t for directory, string for symbolic link, or nil
b401f081156a (url-dav-file-attributes): Simplify.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68640
diff changeset
629 ;; Need to support DAV Bindings to figure out the
b401f081156a (url-dav-file-attributes): Simplify.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68640
diff changeset
630 ;; symbolic link issues.
b401f081156a (url-dav-file-attributes): Simplify.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68640
diff changeset
631 (if (memq 'DAV:collection (plist-get properties 'DAV:resourcetype)) t nil)
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
632
73023
b401f081156a (url-dav-file-attributes): Simplify.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68640
diff changeset
633 ;; Number of links to file... Needs DAV Bindings.
b401f081156a (url-dav-file-attributes): Simplify.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68640
diff changeset
634 1
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
635
73023
b401f081156a (url-dav-file-attributes): Simplify.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68640
diff changeset
636 ;; File uid - no way to figure out?
b401f081156a (url-dav-file-attributes): Simplify.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68640
diff changeset
637 0
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
638
73023
b401f081156a (url-dav-file-attributes): Simplify.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68640
diff changeset
639 ;; File gid - no way to figure out?
b401f081156a (url-dav-file-attributes): Simplify.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68640
diff changeset
640 0
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
641
73023
b401f081156a (url-dav-file-attributes): Simplify.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68640
diff changeset
642 ;; Last access time - ???
b401f081156a (url-dav-file-attributes): Simplify.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68640
diff changeset
643 nil
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
644
73023
b401f081156a (url-dav-file-attributes): Simplify.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68640
diff changeset
645 ;; Last modification time
b401f081156a (url-dav-file-attributes): Simplify.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68640
diff changeset
646 (plist-get properties 'DAV:getlastmodified)
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
647
73023
b401f081156a (url-dav-file-attributes): Simplify.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68640
diff changeset
648 ;; Last status change time... just reuse last-modified
b401f081156a (url-dav-file-attributes): Simplify.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68640
diff changeset
649 ;; for now.
b401f081156a (url-dav-file-attributes): Simplify.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68640
diff changeset
650 (plist-get properties 'DAV:getlastmodified)
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
651
73023
b401f081156a (url-dav-file-attributes): Simplify.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68640
diff changeset
652 ;; size in bytes
b401f081156a (url-dav-file-attributes): Simplify.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68640
diff changeset
653 (or (plist-get properties 'DAV:getcontentlength) 0)
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
654
73023
b401f081156a (url-dav-file-attributes): Simplify.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68640
diff changeset
655 ;; file modes as a string like `ls -l'
78481
bc53aa750f3b Replace `iff' in doc-strings and comments.
Glenn Morris <rgm@gnu.org>
parents: 78222
diff changeset
656 ;;
73023
b401f081156a (url-dav-file-attributes): Simplify.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68640
diff changeset
657 ;; Should be able to build this up from the
b401f081156a (url-dav-file-attributes): Simplify.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68640
diff changeset
658 ;; DAV:supportedlock attribute pretty easily. Getting
b401f081156a (url-dav-file-attributes): Simplify.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68640
diff changeset
659 ;; the group info could be impossible though.
b401f081156a (url-dav-file-attributes): Simplify.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68640
diff changeset
660 (url-dav-file-attributes-mode-string properties)
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
661
78481
bc53aa750f3b Replace `iff' in doc-strings and comments.
Glenn Morris <rgm@gnu.org>
parents: 78222
diff changeset
662 ;; t if file's gid would change if it were deleted &
73023
b401f081156a (url-dav-file-attributes): Simplify.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68640
diff changeset
663 ;; recreated. No way for us to know that thru DAV.
b401f081156a (url-dav-file-attributes): Simplify.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68640
diff changeset
664 nil
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
665
73023
b401f081156a (url-dav-file-attributes): Simplify.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68640
diff changeset
666 ;; inode number - meaningless
b401f081156a (url-dav-file-attributes): Simplify.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68640
diff changeset
667 nil
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
668
73023
b401f081156a (url-dav-file-attributes): Simplify.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68640
diff changeset
669 ;; device number - meaningless
b401f081156a (url-dav-file-attributes): Simplify.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68640
diff changeset
670 nil)
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
671 ;; Fall back to just the normal http way of doing things.
73023
b401f081156a (url-dav-file-attributes): Simplify.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68640
diff changeset
672 (url-http-head-file-attributes url id-format))))
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
673
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
674 (defun url-dav-save-resource (url obj &optional content-type lock-token)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
675 "Save OBJ as URL using WebDAV.
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
676 URL must be a fully qualified URL.
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
677 OBJ may be a buffer or a string."
54795
31399f1df768 (url-dav-rename-file): Fix args of `signal'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54770
diff changeset
678 (declare (special url-http-response-status))
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
679 (let ((buffer nil)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
680 (result nil)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
681 (url-request-extra-headers nil)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
682 (url-request-method "PUT")
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
683 (url-request-data
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
684 (cond
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
685 ((bufferp obj)
54929
42040974ab42 Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54828
diff changeset
686 (with-current-buffer obj
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
687 (buffer-string)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
688 ((stringp obj)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
689 obj)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
690 (t
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
691 (error "Invalid object to url-dav-save-resource")))))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
692
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
693 (if lock-token
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
694 (push
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
695 (cons "If" (concat "(<" lock-token ">)"))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
696 url-request-extra-headers))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
697
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
698 ;; Everything must always have a content-type when we submit it.
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
699 (push
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
700 (cons "Content-type" (or content-type "application/octet-stream"))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
701 url-request-extra-headers)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
702
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
703 ;; Do the save...
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
704 (setq buffer (url-retrieve-synchronously url))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
705
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
706 ;; Sanity checking
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
707 (when buffer
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
708 (unwind-protect
54929
42040974ab42 Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54828
diff changeset
709 (with-current-buffer buffer
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
710 (setq result (url-dav-http-success-p url-http-response-status)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
711 (kill-buffer buffer)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
712 result))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
713
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
714 (eval-when-compile
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
715 (defmacro url-dav-delete-something (url lock-token &rest error-checking)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
716 "Delete URL completely, with no sanity checking whatsoever. DO NOT USE.
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
717 This is defined as a macro that will not be visible from compiled files.
96486
7369ded3b436 Typo and docstring fixes.
Juanma Barranquero <lekktu@gmail.com>
parents: 94668
diff changeset
718 Use with care, and even then think three times."
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
719 `(progn
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
720 ,@error-checking
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
721 (url-dav-request ,url "DELETE" nil nil -1
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
722 (if ,lock-token
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
723 (list
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
724 (cons "If"
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
725 (concat "(<" ,lock-token ">)"))))))))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
726
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
727
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
728 (defun url-dav-delete-directory (url &optional recursive lock-token)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
729 "Delete the WebDAV collection URL.
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
730 If optional second argument RECURSIVE is non-nil, then delete all
54828
2eb49bad7ea9 Comments and docstring fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54795
diff changeset
731 files in the collection as well."
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
732 (let ((status nil)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
733 (props nil)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
734 (props nil))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
735 (setq props (url-dav-delete-something
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
736 url lock-token
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
737 (setq props (url-dav-get-properties url '(DAV:getcontenttype) 1))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
738 (if (and (not recursive)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
739 (/= (length props) 1))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
740 (signal 'file-error (list "Removing directory"
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
741 "directory not empty" url)))))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
742
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
743 (mapc (lambda (result)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
744 (setq status (plist-get (cdr result) 'DAV:status))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
745 (if (not (url-dav-http-success-p status))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
746 (signal 'file-error (list "Removing directory"
86946
ef26aa002fe1 (url-dav-delete-directory): Fix message typo.
Glenn Morris <rgm@gnu.org>
parents: 84929
diff changeset
747 "Error removing"
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
748 (car result) status))))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
749 props))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
750 nil)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
751
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
752 (defun url-dav-delete-file (url &optional lock-token)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
753 "Delete file named URL."
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
754 (let ((props nil)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
755 (status nil))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
756 (setq props (url-dav-delete-something
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
757 url lock-token
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
758 (setq props (url-dav-get-properties url))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
759 (if (eq (plist-get (cdar props) 'DAV:resourcetype) 'DAV:collection)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
760 (signal 'file-error (list "Removing old name" "is a collection" url)))))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
761
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
762 (mapc (lambda (result)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
763 (setq status (plist-get (cdr result) 'DAV:status))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
764 (if (not (url-dav-http-success-p status))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
765 (signal 'file-error (list "Removing old name"
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
766 "Errror removing"
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
767 (car result) status))))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
768 props))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
769 nil)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
770
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
771 (defun url-dav-directory-files (url &optional full match nosort files-only)
96486
7369ded3b436 Typo and docstring fixes.
Juanma Barranquero <lekktu@gmail.com>
parents: 94668
diff changeset
772 "Return a list of names of files in URL.
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
773 There are three optional arguments:
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
774 If FULL is non-nil, return absolute file names. Otherwise return names
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
775 that are relative to the specified directory.
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
776 If MATCH is non-nil, mention only file names that match the regexp MATCH.
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
777 If NOSORT is non-nil, the list is not sorted--its order is unpredictable.
54828
2eb49bad7ea9 Comments and docstring fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54795
diff changeset
778 NOSORT is useful if you plan to sort the result yourself."
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
779 (let ((properties (url-dav-get-properties url '(DAV:resourcetype) 1))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
780 (child-url nil)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
781 (child-props nil)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
782 (files nil)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
783 (parsed-url (url-generic-parse-url url)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
784
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
785 (if (= (length properties) 1)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
786 (signal 'file-error (list "Opening directory" "not a directory" url)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
787
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
788 (while properties
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
789 (setq child-props (pop properties)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
790 child-url (pop child-props))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
791 (if (and (eq (plist-get child-props 'DAV:resourcetype) 'DAV:collection)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
792 files-only)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
793 ;; It is a directory, and we were told to return just files.
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
794 nil
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
795
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
796 ;; Fully expand the URL and then rip off the beginning if we
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
797 ;; are not supposed to return fully-qualified names.
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
798 (setq child-url (url-expand-file-name child-url parsed-url))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
799 (if (not full)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
800 (setq child-url (substring child-url (length url))))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
801
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
802 ;; We don't want '/' as the last character in filenames...
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
803 (if (string-match "/$" child-url)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
804 (setq child-url (substring child-url 0 -1)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
805
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
806 ;; If we have a match criteria, then apply it.
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
807 (if (or (and match (not (string-match match child-url)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
808 (string= child-url "")
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
809 (string= child-url url))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
810 nil
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
811 (push child-url files))))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
812
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
813 (if nosort
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
814 files
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
815 (sort files 'string-lessp))))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
816
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
817 (defun url-dav-file-directory-p (url)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
818 "Return t if URL names an existing DAV collection."
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
819 (let ((properties (cdar (url-dav-get-properties url '(DAV:resourcetype)))))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
820 (eq (plist-get properties 'DAV:resourcetype) 'DAV:collection)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
821
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
822 (defun url-dav-make-directory (url &optional parents)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
823 "Create the directory DIR and any nonexistent parent dirs."
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
824 (declare (special url-http-response-status))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
825 (let* ((url-request-extra-headers nil)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
826 (url-request-method "MKCOL")
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
827 (url-request-data nil)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
828 (buffer (url-retrieve-synchronously url))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
829 (result nil))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
830 (when buffer
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
831 (unwind-protect
54929
42040974ab42 Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54828
diff changeset
832 (with-current-buffer buffer
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
833 (case url-http-response-status
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
834 (201 ; Collection created in its entirety
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
835 (setq result t))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
836 (403 ; Forbidden
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
837 nil)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
838 (405 ; Method not allowed
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
839 nil)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
840 (409 ; Conflict
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
841 nil)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
842 (415 ; Unsupported media type (WTF?)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
843 nil)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
844 (507 ; Insufficient storage
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
845 nil)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
846 (otherwise
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
847 nil)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
848 (kill-buffer buffer)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
849 result))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
850
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
851 (defun url-dav-rename-file (oldname newname &optional overwrite)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
852 (if (not (and (string-match url-handler-regexp oldname)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
853 (string-match url-handler-regexp newname)))
54795
31399f1df768 (url-dav-rename-file): Fix args of `signal'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54770
diff changeset
854 (signal 'file-error
31399f1df768 (url-dav-rename-file): Fix args of `signal'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54770
diff changeset
855 (list "Cannot rename between different URL backends"
31399f1df768 (url-dav-rename-file): Fix args of `signal'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54770
diff changeset
856 oldname newname)))
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
857
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
858 (let* ((headers nil)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
859 (props nil)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
860 (status nil)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
861 (directory-p (url-dav-file-directory-p oldname))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
862 (exists-p (url-http-file-exists-p newname)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
863
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
864 (if (and exists-p
84929
ffdba9eb7f4e (top): Use `mapc' rather than `mapcar'.
Juanma Barranquero <lekktu@gmail.com>
parents: 78481
diff changeset
865 (or
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
866 (null overwrite)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
867 (and (numberp overwrite)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
868 (not (yes-or-no-p
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
869 (format "File %s already exists; rename to it anyway? "
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
870 newname))))))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
871 (signal 'file-already-exists (list "File already exists" newname)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
872
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
873 ;; Honor the overwrite flag...
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
874 (if overwrite (push '("Overwrite" . "T") headers))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
875
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
876 ;; Have to tell them where to copy it to!
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
877 (push (cons "Destination" newname) headers)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
878
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
879 ;; Always send a depth of -1 in case we are moving a collection.
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
880 (setq props (url-dav-request oldname "MOVE" nil nil (if directory-p -1 0)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
881 headers))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
882
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
883 (mapc (lambda (result)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
884 (setq status (plist-get (cdr result) 'DAV:status))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
885
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
886 (if (not (url-dav-http-success-p status))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
887 (signal 'file-error (list "Renaming" oldname newname status))))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
888 props)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
889 t))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
890
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
891 (defun url-dav-file-name-all-completions (file url)
96486
7369ded3b436 Typo and docstring fixes.
Juanma Barranquero <lekktu@gmail.com>
parents: 94668
diff changeset
892 "Return a list of all completions of file name FILE in URL.
7369ded3b436 Typo and docstring fixes.
Juanma Barranquero <lekktu@gmail.com>
parents: 94668
diff changeset
893 These are all file names in URL which begin with FILE."
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
894 (url-dav-directory-files url nil (concat "^" file ".*")))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
895
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
896 (defun url-dav-file-name-completion (file url)
96486
7369ded3b436 Typo and docstring fixes.
Juanma Barranquero <lekktu@gmail.com>
parents: 94668
diff changeset
897 "Complete file name FILE in URL.
7369ded3b436 Typo and docstring fixes.
Juanma Barranquero <lekktu@gmail.com>
parents: 94668
diff changeset
898 Returns the longest string common to all file names in URL
7369ded3b436 Typo and docstring fixes.
Juanma Barranquero <lekktu@gmail.com>
parents: 94668
diff changeset
899 that start with FILE.
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
900 If there is only one and FILE matches it exactly, returns t.
96486
7369ded3b436 Typo and docstring fixes.
Juanma Barranquero <lekktu@gmail.com>
parents: 94668
diff changeset
901 Returns nil if URL contains no name starting with FILE."
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
902 (let ((matches (url-dav-file-name-all-completions file url))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
903 (result nil))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
904 (cond
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
905 ((null matches)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
906 ;; No matches
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
907 nil)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
908 ((and (= (length matches) 1)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
909 (string= file (car matches)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
910 ;; Only one file and FILE matches it exactly...
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
911 t)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
912 (t
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
913 ;; Need to figure out the longest string that they have in commmon
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
914 (setq matches (sort matches (lambda (a b) (> (length a) (length b)))))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
915 (let ((n (length file))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
916 (searching t)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
917 (regexp nil)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
918 (failed nil))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
919 (while (and searching
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
920 (< n (length (car matches))))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
921 (setq regexp (concat "^" (substring (car matches) 0 (1+ n)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
922 failed nil)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
923 (dolist (potential matches)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
924 (if (not (string-match regexp potential))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
925 (setq failed t)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
926 (if failed
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
927 (setq searching nil)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
928 (incf n)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
929 (substring (car matches) 0 n))))))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
930
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
931 (defun url-dav-register-handler (op)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
932 (put op 'url-file-handlers (intern-soft (format "url-dav-%s" op))))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
933
84929
ffdba9eb7f4e (top): Use `mapc' rather than `mapcar'.
Juanma Barranquero <lekktu@gmail.com>
parents: 78481
diff changeset
934 (mapc 'url-dav-register-handler
ffdba9eb7f4e (top): Use `mapc' rather than `mapcar'.
Juanma Barranquero <lekktu@gmail.com>
parents: 78481
diff changeset
935 ;; These handlers are disabled because they incorrectly presume that
ffdba9eb7f4e (top): Use `mapc' rather than `mapcar'.
Juanma Barranquero <lekktu@gmail.com>
parents: 78481
diff changeset
936 ;; the URL specifies an HTTP location and thus break FTP URLs.
ffdba9eb7f4e (top): Use `mapc' rather than `mapcar'.
Juanma Barranquero <lekktu@gmail.com>
parents: 78481
diff changeset
937 '(;; file-name-all-completions
ffdba9eb7f4e (top): Use `mapc' rather than `mapcar'.
Juanma Barranquero <lekktu@gmail.com>
parents: 78481
diff changeset
938 ;; file-name-completion
ffdba9eb7f4e (top): Use `mapc' rather than `mapcar'.
Juanma Barranquero <lekktu@gmail.com>
parents: 78481
diff changeset
939 ;; rename-file
ffdba9eb7f4e (top): Use `mapc' rather than `mapcar'.
Juanma Barranquero <lekktu@gmail.com>
parents: 78481
diff changeset
940 ;; make-directory
ffdba9eb7f4e (top): Use `mapc' rather than `mapcar'.
Juanma Barranquero <lekktu@gmail.com>
parents: 78481
diff changeset
941 ;; file-directory-p
ffdba9eb7f4e (top): Use `mapc' rather than `mapcar'.
Juanma Barranquero <lekktu@gmail.com>
parents: 78481
diff changeset
942 ;; directory-files
ffdba9eb7f4e (top): Use `mapc' rather than `mapcar'.
Juanma Barranquero <lekktu@gmail.com>
parents: 78481
diff changeset
943 ;; delete-file
ffdba9eb7f4e (top): Use `mapc' rather than `mapcar'.
Juanma Barranquero <lekktu@gmail.com>
parents: 78481
diff changeset
944 ;; delete-directory
ffdba9eb7f4e (top): Use `mapc' rather than `mapcar'.
Juanma Barranquero <lekktu@gmail.com>
parents: 78481
diff changeset
945 ;; file-attributes
ffdba9eb7f4e (top): Use `mapc' rather than `mapcar'.
Juanma Barranquero <lekktu@gmail.com>
parents: 78481
diff changeset
946 ))
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
947
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
948
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
949 ;;; Version Control backend cruft
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
950
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
951 ;(put 'vc-registered 'url-file-handlers 'url-dav-vc-registered)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
952
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
953 ;;;###autoload
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
954 (defun url-dav-vc-registered (url)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
955 (if (and (string-match "\\`https?" url)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
956 (plist-get (url-http-options url) 'dav))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
957 (progn
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
958 (vc-file-setprop url 'vc-backend 'dav)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
959 t)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
960
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
961
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
962 ;;; Miscellaneous stuff.
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
963
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
964 (provide 'url-dav)
54699
7784ae10206d Resolve CVS conflicts
Miles Bader <miles@gnu.org>
parents: 54695
diff changeset
965
54828
2eb49bad7ea9 Comments and docstring fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54795
diff changeset
966 ;; arch-tag: 2b14b7b3-888a-49b8-a490-17276a40e78e
2eb49bad7ea9 Comments and docstring fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54795
diff changeset
967 ;;; url-dav.el ends here