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