indent -kr -i8 -brf -bbb -fnc -l132 -nce on all of webcit-classic
[citadel.git] / webcit / addressbook_popup.c
1
2 /*
3  * Dynamic HTML (formerly known as "AJAX") powered auto-completion
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 /*
20  * Address book popup results
21  */
22 HashList *GetAddressbookList() {
23         HashList *List = NULL;
24         const StrBuf *WhichAddrBook;
25         StrBuf *saved_roomname;
26         StrBuf *Name;
27         StrBuf *Line;
28         long BufLen;
29         int IsLocalAddrBook;
30
31         WhichAddrBook = sbstr("which_addr_book");
32         IsLocalAddrBook = strcasecmp(ChrPtr(WhichAddrBook), "__LOCAL_USERS__") == 1;
33
34         if (IsLocalAddrBook) {
35                 serv_puts("LIST");
36         }
37         else {
38                 /* remember the default addressbook for this room */
39                 set_room_pref("defaddrbook", NewStrBufDup(WhichAddrBook), 0);
40                 saved_roomname = NewStrBufDup(WC->CurRoom.name);
41                 gotoroom(WhichAddrBook);
42                 serv_puts("DVCA");
43         }
44
45         Line = NewStrBuf();
46         StrBuf_ServGetln(Line);
47         if (GetServerStatus(Line, NULL) == 1) {
48                 List = NewHash(1, NULL);
49                 while (BufLen = StrBuf_ServGetln(Line), ((BufLen >= 0) && ((BufLen != 3) || strcmp(ChrPtr(Line), "000")))) {
50                         if (IsLocalAddrBook && (BufLen > 5) && (strncmp(ChrPtr(Line), "SYS_", 4) == 0)) {
51                                 continue;
52                         }
53                         Name = NewStrBufPlain(NULL, StrLength(Line));
54                         StrBufExtract_token(Name, Line, 0, '|');
55                         Put(List, SKEY(Name), Name, HFreeStrBuf);
56
57                 }
58                 SortByHashKey(List, 1);
59         }
60
61         if (!IsLocalAddrBook) {
62                 gotoroom(saved_roomname);
63                 FreeStrBuf(&saved_roomname);
64         }
65
66         return List;
67 }
68
69
70
71
72 void InitModule_ADDRBOOK_POPUP(void) {
73
74         RegisterIterator("ITERATE:ABNAMES", 0, NULL, GetAddressbookList, NULL, NULL, CTX_STRBUF, CTX_NONE, IT_NOFLAG);
75 }