Anope IRC Services  Version 1.8
list.c
Go to the documentation of this file.
1 /* Routines to handle `listnicks' and `listchans' invocations.
2  *
3  * (C) 2003-2014 Anope Team
4  * Contact us at team@anope.org
5  *
6  * Please read COPYING and README for further details.
7  *
8  * Based on the original code of Epona by Lara.
9  * Based on the original code of Services by Andy Church.
10  *
11  *
12  */
13 
14 #include "services.h"
15 
16 /*************************************************************************/
17 
24 void do_listnicks(int ac, char **av)
25 {
26  int count = 0; /* Count only rather than display? */
27  int usage = 0; /* Display command usage? (>0 also indicates error) */
28  int i;
29 
30  i = 1;
31  while (i < ac) {
32  if (av[i][0] == '-') {
33  switch (av[i][1]) {
34  case 'h':
35  usage = -1;
36  break;
37  case 'c':
38  if (i > 1)
39  usage = 1;
40  count = 1;
41  break;
42  case 'd':
43  if (av[i][2]) {
44  services_dir = av[i] + 2;
45  } else {
46  if (i >= ac - 1) {
47  usage = 1;
48  break;
49  }
50  ac--;
51  memmove(av + i, av + i + 1, sizeof(char *) * ac - i);
52  services_dir = av[i];
53  }
54  default:
55  usage = 1;
56  break;
57  } /* switch */
58  ac--;
59  if (i < ac)
60  memmove(av + i, av + i + 1, sizeof(char *) * ac - i);
61  } else {
62  if (count)
63  usage = 1;
64  i++;
65  }
66  }
67  if (usage) {
68  fprintf(stderr, "\
69 \n\
70 Usage: listnicks [-c] [-d data-dir] [nick [nick...]]\n\
71  -c: display only count of registered nicks\n\
72  (cannot be combined with nicks)\n\
73  nick: nickname(s) to display information for\n\
74 \n\
75 If no nicks are given, the entire nickname database is printed out in\n\
76 compact format followed by the number of registered nicks (with -c, the\n\
77 list is suppressed and only the count is printed). If one or more nicks\n\
78 are given, detailed information about those nicks is displayed.\n\
79 \n");
80  exit(usage > 0 ? 1 : 0);
81  }
82 
83  if (chdir(services_dir) < 0) {
84  fprintf(stderr, "chdir(%s): %s\n", services_dir, strerror(errno));
86  exit(1);
87  }
88  if (!read_config(0)) {
90  exit(1);
91  }
92  load_ns_dbase();
93 
94  lang_init();
95 
96  if (ac > 1) {
97  for (i = 1; i < ac; i++)
98  listnicks(0, av[i]);
99  } else {
100  listnicks(count, NULL);
101  }
102  exit(0);
103 }
104 
105 /*************************************************************************/
106 
113 void do_listchans(int ac, char **av)
114 {
115  int count = 0; /* Count only rather than display? */
116  int usage = 0; /* Display command usage? (>0 also indicates error) */
117  int i;
118 
119  i = 1;
120  while (i < ac) {
121  if (av[i][0] == '-') {
122  switch (av[i][1]) {
123  case 'h':
124  usage = -1;
125  break;
126  case 'c':
127  if (i > 1)
128  usage = 1;
129  count = 1;
130  break;
131  case 'd':
132  if (av[i][2]) {
133  services_dir = av[i] + 2;
134  } else {
135  if (i >= ac - 1) {
136  usage = 1;
137  break;
138  }
139  ac--;
140  memmove(av + i, av + i + 1, sizeof(char *) * ac - i);
141  services_dir = av[i];
142  }
143  default:
144  usage = 1;
145  break;
146  } /* switch */
147  ac--;
148  if (i < ac)
149  memmove(av + i, av + i + 1, sizeof(char *) * ac - i);
150  } else {
151  if (count)
152  usage = 1;
153  i++;
154  }
155  }
156  if (usage) {
157  fprintf(stderr, "\
158 \n\
159 Usage: listchans [-c] [-d data-dir] [channel [channel...]]\n\
160  -c: display only count of registered channels\n\
161  (cannot be combined with channels)\n\
162 channel: channel(s) to display information for\n\
163 \n\
164 If no channels are given, the entire channel database is printed out in\n\
165 compact format followed by the number of registered channels (with -c, the\n\
166 list is suppressed and only the count is printed). If one or more channels\n\
167 are given, detailed information about those channels is displayed.\n\
168 \n\
169 Channel names will need to be escaped with a backslash.\n\
170 For example: ./listchans \\#Anope\n\
171 \n");
172  exit(usage > 0 ? 1 : 0);
173  }
174 
175  if (chdir(services_dir) < 0) {
176  fprintf(stderr, "chdir(%s): %s\n", services_dir, strerror(errno));
178  exit(1);
179  }
180  if (!read_config(0)) {
182  exit(1);
183  }
184  load_ns_dbase();
185  load_cs_dbase();
186 
187  lang_init();
188 
189  if (ac > 1) {
190  for (i = 1; i < ac; i++)
191  listchans(0, av[i]);
192  } else {
193  listchans(count, NULL);
194  }
195  exit(0);
196 }
197 
198 /*************************************************************************/
E void load_ns_dbase(void)
Definition: nickserv.c:563
E char * services_dir
Definition: extern.h:773
E void load_cs_dbase(void)
Definition: chanserv.c:423
E char * strerror(int errnum)
Definition: compat.c:123
E int read_config(int reload)
Definition: config.c:894
E void listchans(int count_only, const char *chan)
Definition: chanserv.c:191
void do_listnicks(int ac, char **av)
Definition: list.c:24
E void lang_init(void)
Definition: language.c:178
E void ModuleRunTimeDirCleanUp(void)
Definition: modules.c:2880
void do_listchans(int ac, char **av)
Definition: list.c:113
E void listnicks(int count_only, const char *nick)
Definition: nickserv.c:49