Began replacing the FSF's street address with their
[citadel.git] / webcit / autocompletion.c
1 /*
2  * ajax-powered autocompletion...
3  *
4  * Copyright (c) 1996-2011 by the citadel.org team
5  *
6  * This program is open source software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 #include "webcit.h"
21
22 /*
23  * Recipient autocompletion results
24  */
25 void recp_autocomplete(char *partial) {
26         char buf[1024];
27         char name[128];
28
29         output_headers(0, 0, 0, 0, 0, 0);
30
31         hprintf("Content-type: text/html\r\n"
32                 "Server: %s\r\n"
33                 "Connection: close\r\n"
34                 "Pragma: no-cache\r\n"
35                 "Cache-Control: no-store\r\n"
36                 "Expires: -1\r\n"
37                 ,
38                 PACKAGE_STRING);
39         begin_burst();
40
41         wc_printf("<ul>");
42
43         serv_printf("AUTO %s", partial);
44         serv_getln(buf, sizeof buf);
45         if (buf[0] == '1') {
46                 while(serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
47                         extract_token(name, buf, 0, '|', sizeof name);
48                         wc_printf("<li>");
49                         escputs(name);
50                         wc_printf("</li>");
51                 }
52         }
53
54         wc_printf("</ul>");
55
56         wc_printf("\r\n\r\n");
57         wDumpContent(0);
58 }
59
60
61 void _recp_autocomplete(void) {recp_autocomplete(bstr("recp"));}
62 void _cc_autocomplete(void)   {recp_autocomplete(bstr("cc"));} 
63 void _bcc_autocomplete(void)  {recp_autocomplete(bstr("bcc"));}
64
65
66 void 
67 InitModule_AUTO_COMPLETE
68 (void)
69 {
70         WebcitAddUrlHandler(HKEY("recp_autocomplete"), "", 0, _recp_autocomplete, 0);
71         WebcitAddUrlHandler(HKEY("cc_autocomplete"),   "", 0, _cc_autocomplete, 0);
72         WebcitAddUrlHandler(HKEY("bcc_autocomplete"),  "", 0, _bcc_autocomplete, 0);
73 }