indent -kr -i8 -brf -bbb -fnc -l132 -nce on all of webcit-classic
[citadel.git] / webcit / autocompletion.c
1
2 /*
3  * dynamic html autocompletion
4  *
5  * Copyright (c) 1996-2012 by the citadel.org team
6  *
7  * This program is open source software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License, version 3.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  */
15
16 #include "webcit.h"
17
18 /*
19  * Recipient autocompletion results
20  */
21 void recp_autocomplete(char *partial) {
22         char buf[1024];
23         char name[128];
24
25         output_headers(0, 0, 0, 0, 0, 0);
26
27         hprintf("Content-type: text/html\r\n"
28                 "Server: %s\r\n"
29                 "Connection: close\r\n" "Pragma: no-cache\r\n" "Cache-Control: no-store\r\n" "Expires: -1\r\n", PACKAGE_STRING);
30         begin_burst();
31
32         wc_printf("<ul>");
33
34         serv_printf("AUTO %s", partial);
35         serv_getln(buf, sizeof buf);
36         if (buf[0] == '1') {
37                 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
38                         extract_token(name, buf, 0, '|', sizeof name);
39                         wc_printf("<li>");
40                         escputs(name);
41                         wc_printf("</li>");
42                 }
43         }
44
45         wc_printf("</ul>");
46
47         wc_printf("\r\n\r\n");
48         wDumpContent(0);
49 }
50
51
52 void _recp_autocomplete(void) {
53         recp_autocomplete(bstr("recp"));
54 }
55 void _cc_autocomplete(void) {
56         recp_autocomplete(bstr("cc"));
57 }
58 void _bcc_autocomplete(void) {
59         recp_autocomplete(bstr("bcc"));
60 }
61
62
63 void InitModule_AUTO_COMPLETE(void) {
64         WebcitAddUrlHandler(HKEY("recp_autocomplete"), "", 0, _recp_autocomplete, 0);
65         WebcitAddUrlHandler(HKEY("cc_autocomplete"), "", 0, _cc_autocomplete, 0);
66         WebcitAddUrlHandler(HKEY("bcc_autocomplete"), "", 0, _bcc_autocomplete, 0);
67 }