updates.
[crypto.git] / apps / irssi / src / silc / core / silc-expandos.c
1 /*
2
3   silc-expandos.c 
4
5   Author: Pekka Riikonen <priikone@silcnet.org>
6
7   Copyright (C) 2002 Pekka Riikonen
8
9   This program is free software; you can redistribute it and/or modify
10   it under the terms of the GNU General Public License as published by
11   the Free Software Foundation; version 2 of the License.
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 */
19
20 #include "module.h"
21 #include "misc.h"
22 #include "expandos.h"
23 #include "settings.h"
24
25 #include "chatnets.h"
26 #include "servers-setup.h"
27 #include "channels-setup.h"
28 #include "silc-servers.h"
29 #include "silc-channels.h"
30 #include "silc-queries.h"
31 #include "silc-nicklist.h"
32
33 /* User mode in active server */
34
35 static char *expando_usermode(SERVER_REC *server, void *item, int *free_ret)
36 {
37   SILC_SERVER_REC *s = SILC_SERVER(server);
38   static char modes[128], stat[128];
39   bool se;
40
41   if (!s)
42     return "";
43
44   memset(modes, 0, sizeof(modes));
45   memset(stat, 0, sizeof(stat));
46
47   if (s->umode & SILC_UMODE_GONE)
48     strcat(stat, "g");
49   if (s->umode & SILC_UMODE_INDISPOSED)
50     strcat(stat, "i");
51   if (s->umode & SILC_UMODE_BUSY)
52     strcat(stat, "b");
53   if (s->umode & SILC_UMODE_PAGE)
54     strcat(stat, "p");
55   if (s->umode & SILC_UMODE_HYPER)
56     strcat(stat, "h");
57   if (s->umode & SILC_UMODE_ROBOT)
58     strcat(stat, "t");
59   if (s->umode & SILC_UMODE_ANONYMOUS)
60     strcat(stat, "?");
61   if (s->umode & SILC_UMODE_BLOCK_PRIVMSG)
62     strcat(stat, "P");
63   if (s->umode & SILC_UMODE_REJECT_WATCHING)
64     strcat(stat, "w");
65   if (s->umode & SILC_UMODE_BLOCK_INVITE)
66     strcat(stat, "I");
67
68   se = strlen(stat) > 0;
69   snprintf(modes, sizeof(modes) - 1, "%s%s%s%s",
70            ((s->umode & SILC_UMODE_SERVER_OPERATOR) ? "Server Operator" :
71             (s->umode & SILC_UMODE_ROUTER_OPERATOR) ? "Router Operator" : ""),
72            se ? "[" : "", se ? stat : "", se ? "]" : "");
73
74   return modes;
75 }
76
77 /* Expands to your usermode on channel */
78
79 static char *expando_cumode(SERVER_REC *server, void *item, int *free_ret)
80 {
81   if (IS_SILC_CHANNEL(item) && CHANNEL(item)->ownnick) {
82     SILC_NICK_REC *nick = (SILC_NICK_REC *)CHANNEL(item)->ownnick;
83     return (nick->op && nick->founder) ? "*@" :
84       nick->op ? "@" : nick->founder ? "*" : "";
85   }
86
87   return "";
88 }
89
90 static char *expando_cumode_space(SERVER_REC *server, void *item, 
91                                   int *free_ret)
92 {
93   char *ret;
94
95   if (!IS_SILC_SERVER(server))
96     return "";
97
98   ret = expando_cumode(server, item, free_ret);
99   return *ret == '\0' ? " " : ret;
100 }
101
102 void silc_expandos_init(void)
103 {
104   expando_create("usermode", expando_usermode,
105                  "window changed", EXPANDO_ARG_NONE,
106                  "window server changed", EXPANDO_ARG_WINDOW,
107                  "user mode changed", EXPANDO_ARG_SERVER, NULL);
108   expando_create("cumode", expando_cumode,
109                  "window changed", EXPANDO_ARG_NONE,
110                  "window item changed", EXPANDO_ARG_WINDOW,
111                  "nick mode changed", EXPANDO_ARG_WINDOW_ITEM, NULL);
112   expando_create("cumode_space", expando_cumode_space,
113                  "window changed", EXPANDO_ARG_NONE,
114                  "window item changed", EXPANDO_ARG_WINDOW,
115                  "nick mode changed", EXPANDO_ARG_WINDOW_ITEM, NULL);
116 }
117
118 void silc_expandos_deinit(void)
119 {
120   expando_destroy("usermode", expando_usermode);
121   expando_destroy("cumode", expando_cumode);
122   expando_destroy("cumode_space", expando_cumode_space);
123 }