Mercurial > emacs
annotate lisp/net/eudcb-ph.el @ 110186:5328ea5b6e41
Fix Ruby compilation error matching.
* progmodes/compile.el (compilation-error-regexp-alist-alist):
Remove ruby regexp; handle Ruby errors with gcc-include and gnu.
Recognize leading tab in gcc-include regexp. Ignore names with
leading "from" or "in" in gnu regexp (Bug#6937).
author | Chong Yidong <cyd@stupidchicken.com> |
---|---|
date | Sat, 04 Sep 2010 16:42:03 -0400 |
parents | 280c8ae2476d |
children | 417b1e4d63cd |
rev | line source |
---|---|
27313 | 1 ;;; eudcb-ph.el --- Emacs Unified Directory Client - CCSO PH/QI Backend |
2 | |
74509 | 3 ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, |
106815 | 4 ;; 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. |
27313 | 5 |
42607
033986c328d5
New maintainer. New e-mail address of the author.
Pavel Janík <Pavel@Janik.cz>
parents:
42574
diff
changeset
|
6 ;; Author: Oscar Figueiredo <oscar@cpe.fr> |
033986c328d5
New maintainer. New e-mail address of the author.
Pavel Janík <Pavel@Janik.cz>
parents:
42574
diff
changeset
|
7 ;; Maintainer: Pavel Janík <Pavel@Janik.cz> |
42574 | 8 ;; Keywords: comm |
110015
280c8ae2476d
Add "Package:" file headers to denote built-in packages.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
9 ;; Package: eudc |
27313 | 10 |
11 ;; This file is part of GNU Emacs. | |
12 | |
94677
91e5880a36c1
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
13 ;; GNU Emacs is free software: you can redistribute it and/or modify |
27313 | 14 ;; it under the terms of the GNU General Public License as published by |
94677
91e5880a36c1
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
15 ;; the Free Software Foundation, either version 3 of the License, or |
91e5880a36c1
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
16 ;; (at your option) any later version. |
27313 | 17 |
18 ;; GNU Emacs is distributed in the hope that it will be useful, | |
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21 ;; GNU General Public License for more details. | |
22 | |
23 ;; You should have received a copy of the GNU General Public License | |
94677
91e5880a36c1
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
27313 | 25 |
26 ;;; Commentary: | |
42780
b136d94976d9
(eudc-ph-open-session): Remove XEmacs case.
Pavel Janík <Pavel@Janik.cz>
parents:
42607
diff
changeset
|
27 |
42570
78a4068d960a
Remove unnecessary whitespaces.
Pavel Janík <Pavel@Janik.cz>
parents:
27313
diff
changeset
|
28 ;; This library provides specific CCSO PH/QI protocol support for the |
42780
b136d94976d9
(eudc-ph-open-session): Remove XEmacs case.
Pavel Janík <Pavel@Janik.cz>
parents:
42607
diff
changeset
|
29 ;; Emacs Unified Directory Client package. |
27313 | 30 |
31 ;;; Code: | |
32 | |
33 (require 'eudc) | |
34 | |
35 ;;{{{ Internal cooking | |
36 | |
37 (eudc-protocol-set 'eudc-bbdb-conversion-alist 'eudc-ph-bbdb-conversion-alist 'ph) | |
38 (eudc-protocol-set 'eudc-query-function 'eudc-ph-query-internal 'ph) | |
39 (eudc-protocol-set 'eudc-list-attributes-function 'eudc-ph-get-field-list 'ph) | |
40 (eudc-protocol-set 'eudc-protocol-has-default-query-attributes t 'ph) | |
41 | |
42 (defvar eudc-ph-process-buffer nil) | |
43 (defvar eudc-ph-read-point) | |
44 | |
45 (defconst eudc-ph-default-server-port 105 | |
46 "Default TCP port for CCSO PH/QI directory services.") | |
47 | |
48 (defun eudc-ph-query-internal (query &optional return-fields) | |
49 "Query the PH/QI server with QUERY. | |
42570
78a4068d960a
Remove unnecessary whitespaces.
Pavel Janík <Pavel@Janik.cz>
parents:
27313
diff
changeset
|
50 QUERY can be a string NAME or a list made of strings NAME |
78a4068d960a
Remove unnecessary whitespaces.
Pavel Janík <Pavel@Janik.cz>
parents:
27313
diff
changeset
|
51 and/or cons cells (KEY . VALUE) where KEYs should be valid |
27313 | 52 CCSO database keys. NAME is equivalent to (DEFAULT . NAME), |
53 where DEFAULT is the default key of the database. | |
54 RETURN-FIELDS is a list of database fields to return, | |
55 defaulting to `eudc-default-return-attributes'." | |
56 (let (request) | |
57 (if (null return-fields) | |
58 (setq return-fields eudc-default-return-attributes)) | |
59 (if (eq 'all return-fields) | |
60 (setq return-fields '(all))) | |
42570
78a4068d960a
Remove unnecessary whitespaces.
Pavel Janík <Pavel@Janik.cz>
parents:
27313
diff
changeset
|
61 (setq request |
27313 | 62 (concat "query " |
63 (if (stringp query) | |
64 query | |
65 (mapconcat (function (lambda (elt) | |
66 (if (stringp elt) elt) | |
67 (format "%s=%s" (car elt) (cdr elt)))) | |
68 query | |
69 " ")) | |
70 (if return-fields | |
71 (concat " return " (mapconcat 'symbol-name return-fields " "))))) | |
72 (and (> (length request) 6) | |
73 (eudc-ph-do-request request) | |
74 (eudc-ph-parse-query-result return-fields)))) | |
75 | |
76 (defun eudc-ph-get-field-list (full-records) | |
77 "Return a list of valid field names for the current server. | |
78 If FULL-RECORDS is non-nil, full records including field description | |
79 are returned" | |
80 (interactive) | |
81 (eudc-ph-do-request "fields") | |
82 (if full-records | |
83 (eudc-ph-parse-query-result) | |
84 (mapcar 'eudc-caar (eudc-ph-parse-query-result)))) | |
85 | |
86 (defun eudc-ph-parse-query-result (&optional fields) | |
42570
78a4068d960a
Remove unnecessary whitespaces.
Pavel Janík <Pavel@Janik.cz>
parents:
27313
diff
changeset
|
87 "Return a list of alists of key/values from in `eudc-ph-process-buffer'. |
27313 | 88 Fields not in FIELDS are discarded." |
42570
78a4068d960a
Remove unnecessary whitespaces.
Pavel Janík <Pavel@Janik.cz>
parents:
27313
diff
changeset
|
89 (let (record |
27313 | 90 records |
91 line-regexp | |
92 current-key | |
93 key | |
94 value | |
95 ignore) | |
96 (save-excursion | |
97 (message "Parsing results...") | |
98 (set-buffer eudc-ph-process-buffer) | |
99 (goto-char (point-min)) | |
100 (while (re-search-forward "^\\(-[0-9]+\\):\\([0-9]+\\):" nil t) | |
101 (catch 'ignore | |
102 (setq line-regexp (concat "^\\(-[0-9]+\\):" (match-string 2) ":[ \t]*\\([-a-zA-Z_]*\\)?:[ \t]*\\(.*\\)$")) | |
103 (beginning-of-line) | |
104 (setq record nil | |
105 ignore nil | |
106 current-key nil) | |
107 (while (re-search-forward line-regexp nil t) | |
108 (catch 'skip-line | |
109 (if (string= "-508" (match-string 1)) | |
110 ;; A field is missing in this entry. Skip it or skip the | |
111 ;; whole record (see `eudc-strict-return-matches') | |
112 (if (not eudc-strict-return-matches) | |
113 (throw 'skip-line t) | |
114 (while (re-search-forward line-regexp nil t)) | |
115 (setq ignore t) | |
116 (throw 'ignore t))) | |
117 (setq key (and (not (string= (match-string 2) "")) | |
118 (intern (match-string 2))) | |
119 value (match-string 3)) | |
120 (if (and current-key | |
42570
78a4068d960a
Remove unnecessary whitespaces.
Pavel Janík <Pavel@Janik.cz>
parents:
27313
diff
changeset
|
121 (eq key current-key)) |
27313 | 122 (setq key nil) |
123 (setq current-key key)) | |
124 (if (or (null fields) | |
125 (eq 'all fields) | |
126 (memq current-key fields)) | |
127 (if key | |
128 (setq record (cons (cons key value) record)) ; New key | |
129 (setcdr (car record) (if (listp (eudc-cdar record)) | |
130 (append (eudc-cdar record) (list value)) | |
131 (list (eudc-cdar record) value)))))))) | |
132 (and (not ignore) | |
133 (or (null fields) | |
134 (eq 'all fields) | |
135 (setq record (nreverse record))) | |
136 (setq record (if (not (eq 'list eudc-duplicate-attribute-handling-method)) | |
137 (eudc-filter-duplicate-attributes record) | |
138 (list record))) | |
42780
b136d94976d9
(eudc-ph-open-session): Remove XEmacs case.
Pavel Janík <Pavel@Janik.cz>
parents:
42607
diff
changeset
|
139 (setq records (append record records))))) |
27313 | 140 (message "Done") |
42780
b136d94976d9
(eudc-ph-open-session): Remove XEmacs case.
Pavel Janík <Pavel@Janik.cz>
parents:
42607
diff
changeset
|
141 records)) |
27313 | 142 |
143 (defun eudc-ph-do-request (request) | |
144 "Send REQUEST to the server. | |
145 Wait for response and return the buffer containing it." | |
146 (let (process | |
147 buffer) | |
148 (unwind-protect | |
149 (progn | |
150 (message "Contacting server...") | |
151 (setq process (eudc-ph-open-session)) | |
152 (if process | |
105813
df4934f25eef
* textmodes/two-column.el (2C-split):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100908
diff
changeset
|
153 (with-current-buffer (setq buffer (process-buffer process)) |
27313 | 154 (eudc-ph-send-command process request) |
155 (message "Request sent, waiting for reply...") | |
156 (eudc-ph-read-response process)))) | |
157 (if process | |
158 (eudc-ph-close-session process))) | |
159 buffer)) | |
42570
78a4068d960a
Remove unnecessary whitespaces.
Pavel Janík <Pavel@Janik.cz>
parents:
27313
diff
changeset
|
160 |
27313 | 161 (defun eudc-ph-open-session (&optional server) |
162 "Open a connection to the given CCSO/QI SERVER. | |
163 SERVER is either a string naming the server or a list (NAME PORT)." | |
164 (let (process | |
165 host | |
166 port) | |
167 (catch 'done | |
168 (if (null server) | |
169 (setq server (or eudc-server | |
170 (call-interactively 'eudc-ph-set-server)))) | |
171 (string-match "\\(.*\\)\\(:\\(.*\\)\\)?" server) | |
172 (setq host (match-string 1 server)) | |
173 (setq port (or (match-string 3 server) | |
174 eudc-ph-default-server-port)) | |
175 (setq eudc-ph-process-buffer (get-buffer-create (format " *PH-%s*" host))) | |
105813
df4934f25eef
* textmodes/two-column.el (2C-split):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100908
diff
changeset
|
176 (with-current-buffer eudc-ph-process-buffer |
27313 | 177 (erase-buffer) |
178 (setq eudc-ph-read-point (point)) | |
85511
f873840f9fea
* emulation/edt-mapper.el (function-key-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78230
diff
changeset
|
179 (and (featurep 'xemacs) (featurep 'mule) |
27313 | 180 (set-buffer-file-coding-system 'binary t))) |
181 (setq process (open-network-stream "ph" eudc-ph-process-buffer host port)) | |
182 (if (null process) | |
183 (throw 'done nil)) | |
66948
043fa9c73c77
(eudc-ph-open-session): Use set-process-query-on-exit-flag.
Richard M. Stallman <rms@gnu.org>
parents:
64701
diff
changeset
|
184 (set-process-query-on-exit-flag process t) |
27313 | 185 process))) |
186 | |
187 (defun eudc-ph-close-session (process) | |
105813
df4934f25eef
* textmodes/two-column.el (2C-split):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100908
diff
changeset
|
188 (with-current-buffer (process-buffer process) |
27313 | 189 (eudc-ph-send-command process "quit") |
190 (eudc-ph-read-response process) | |
42780
b136d94976d9
(eudc-ph-open-session): Remove XEmacs case.
Pavel Janík <Pavel@Janik.cz>
parents:
42607
diff
changeset
|
191 (run-at-time 2 nil 'delete-process process))) |
27313 | 192 |
193 (defun eudc-ph-send-command (process command) | |
194 (goto-char (point-max)) | |
195 (process-send-string process command) | |
196 (process-send-string process "\r\n") | |
197 ) | |
198 | |
199 (defun eudc-ph-read-response (process &optional return-response) | |
200 "Read a response from the PH/QI query process PROCESS. | |
201 Returns nil if response starts with an error code. If the | |
202 response is successful the return code or the response itself is returned | |
203 depending on RETURN-RESPONSE." | |
204 (let ((case-fold-search nil) | |
205 return-code | |
206 match-end) | |
207 (goto-char eudc-ph-read-point) | |
208 ;; CCSO protocol : response complete if status >= 200 | |
209 (while (not (re-search-forward "^\\(^[2-5].*\\):.*\n" nil t)) | |
210 (accept-process-output process) | |
211 (goto-char eudc-ph-read-point)) | |
212 (setq match-end (point)) | |
213 (goto-char eudc-ph-read-point) | |
214 (if (and (setq return-code (match-string 1)) | |
215 (setq return-code (string-to-number return-code)) | |
216 (>= (abs return-code) 300)) | |
217 (progn (setq eudc-ph-read-point match-end) nil) | |
218 (setq eudc-ph-read-point match-end) | |
219 (if return-response | |
220 (buffer-substring (point) match-end) | |
221 return-code)))) | |
222 | |
42570
78a4068d960a
Remove unnecessary whitespaces.
Pavel Janík <Pavel@Janik.cz>
parents:
27313
diff
changeset
|
223 ;;}}} |
27313 | 224 |
225 ;;{{{ High-level interfaces (interactive functions) | |
226 | |
227 (defun eudc-ph-customize () | |
228 "Customize the EUDC PH support." | |
229 (interactive) | |
230 (customize-group 'eudc-ph)) | |
231 | |
232 (defun eudc-ph-set-server (server) | |
233 "Set the PH server to SERVER." | |
234 (interactive "sNew PH/QI Server: ") | |
235 (message "Selected PH/QI server is now %s" server) | |
236 (eudc-set-server server 'ph)) | |
237 | |
238 ;;}}} | |
239 | |
240 (eudc-register-protocol 'ph) | |
241 | |
242 (provide 'eudcb-ph) | |
243 | |
93975
1e3a407766b9
Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
244 ;; arch-tag: 4365bbf5-af20-453e-b5b6-2e7118ebfcdb |
27313 | 245 ;;; eudcb-ph.el ends here |