Anope IRC Services  Version 1.8
hs_list.c
Go to the documentation of this file.
1 /* HostServ core functions
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 
15 #include "module.h"
16 
17 static int listOut(User * u);
18 static void myHostServHelp(User * u);
19 
26 int AnopeInit(int argc, char **argv)
27 {
28  Command *c;
29 
30  moduleAddAuthor("Anope");
31  moduleAddVersion(VERSION_STRING);
33 
34  c = createCommand("LIST", listOut, is_services_oper, -1, -1,
35  HOST_HELP_LIST, HOST_HELP_LIST, HOST_HELP_LIST);
38 
39  return MOD_CONT;
40 }
41 
45 void AnopeFini(void)
46 {
47 
48 }
49 
50 
51 
56 static void myHostServHelp(User * u)
57 {
58  if (is_services_oper(u)) {
59  notice_lang(s_HostServ, u, HOST_HELP_CMD_LIST);
60  }
61 }
62 
68 static int listOut(User * u)
69 {
70  char *key = strtok(NULL, "");
71  struct tm *tm;
72  char buf[BUFSIZE];
73  int counter = 1;
74  int from = 0, to = 0;
75  char *tmp = NULL;
76  char *s = NULL;
77  int display_counter = 0;
78  HostCore *head = NULL;
80 
81  head = hostCoreListHead();
82 
83  current = head;
84  if (current == NULL)
85  notice_lang(s_HostServ, u, HOST_EMPTY);
86  else {
91  if (key) {
92  if (key[0] == '#') {
93  tmp = myStrGetOnlyToken((key + 1), '-', 0); /* Read FROM out */
94  if (!tmp) {
95  notice_lang(s_ChanServ, u, LIST_INCORRECT_RANGE);
96  return MOD_CONT;
97  }
98  for (s = tmp; *s; s++) {
99  if (!isdigit(*s)) {
100  free(tmp);
101  notice_lang(s_ChanServ, u, LIST_INCORRECT_RANGE);
102  return MOD_CONT;
103  }
104  }
105  from = atoi(tmp);
106  free(tmp);
107  tmp = myStrGetTokenRemainder(key, '-', 1); /* Read TO out */
108  if (!tmp) {
109  notice_lang(s_ChanServ, u, LIST_INCORRECT_RANGE);
110  return MOD_CONT;
111  }
112  for (s = tmp; *s; s++) {
113  if (!isdigit(*s)) {
114  free(tmp);
115  notice_lang(s_ChanServ, u, LIST_INCORRECT_RANGE);
116  return MOD_CONT;
117  }
118  }
119  to = atoi(tmp);
120  free(tmp);
121  key = NULL;
122  }
123  }
124 
125  while (current != NULL) {
126  if (key) {
127  if (((match_wild_nocase(key, current->nick))
128  || (match_wild_nocase(key, current->vHost)))
129  && (display_counter < NSListMax)) {
130  display_counter++;
131  tm = localtime(&current->time);
132  strftime_lang(buf, sizeof(buf), u,
133  STRFTIME_DATE_TIME_FORMAT, tm);
134  if (current->vIdent) {
135  notice_lang(s_HostServ, u, HOST_IDENT_ENTRY,
136  counter, current->nick,
137  current->vIdent, current->vHost,
138  current->creator, buf);
139  } else {
140  notice_lang(s_HostServ, u, HOST_ENTRY, counter,
141  current->nick, current->vHost,
142  current->creator, buf);
143  }
144  }
145  } else {
150  if ((((counter >= from) && (counter <= to))
151  || ((from == 0) && (to == 0)))
152  && (display_counter < NSListMax)) {
153  display_counter++;
154  tm = localtime(&current->time);
155  strftime_lang(buf, sizeof(buf), u,
156  STRFTIME_DATE_TIME_FORMAT, tm);
157  if (current->vIdent) {
158  notice_lang(s_HostServ, u, HOST_IDENT_ENTRY,
159  counter, current->nick,
160  current->vIdent, current->vHost,
161  current->creator, buf);
162  } else {
163  notice_lang(s_HostServ, u, HOST_ENTRY, counter,
164  current->nick, current->vHost,
165  current->creator, buf);
166  }
167  }
168  }
169  counter++;
170  current = current->next;
171  }
172  if (key) {
173  notice_lang(s_HostServ, u, HOST_LIST_KEY_FOOTER, key,
174  display_counter);
175  } else {
176  if (from != 0) {
177  notice_lang(s_HostServ, u, HOST_LIST_RANGE_FOOTER, from,
178  to);
179  } else {
180  notice_lang(s_HostServ, u, HOST_LIST_FOOTER,
181  display_counter);
182  }
183  }
184  }
185  return MOD_CONT;
186 }
time_t time
Definition: services.h:1113
E int match_wild_nocase(const char *pattern, const char *str)
Definition: misc.c:268
static Channel * current
Definition: channels.c:427
E char * myStrGetTokenRemainder(const char *str, const char dilim, int token_number)
Definition: misc.c:720
HostCore * head
Definition: hostserv.c:24
MDE void moduleAddAuthor(const char *author)
Definition: modules.c:1772
static int listOut(User *u)
Definition: hs_list.c:68
#define HOSTSERV
Definition: modules.h:56
E void notice_lang(char *source, User *dest, int message,...)
Definition: send.c:169
MDE void moduleSetType(MODType type)
Definition: modules.c:818
void AnopeFini(void)
Definition: hs_list.c:45
static void myHostServHelp(User *u)
Definition: hs_list.c:56
MDE void moduleAddVersion(const char *version)
Definition: modules.c:1760
HostCore * next
Definition: services.h:1108
Command * c
Definition: ns_recover.c:17
E char * myStrGetOnlyToken(const char *str, const char dilim, int token_number)
Definition: misc.c:685
#define MOD_CONT
Definition: modules.h:54
char * vHost
Definition: services.h:1111
E char * s_HostServ
Definition: extern.h:303
E int NSListMax
Definition: extern.h:392
char * vIdent
Definition: services.h:1110
Definition: modules.h:99
MDE Command * createCommand(const char *name, int(*func)(User *u), int(*has_priv)(User *u), int help_all, int help_reg, int help_oper, int help_admin, int help_root)
Definition: modules.c:987
E int is_services_oper(User *u)
Definition: operserv.c:606
int AnopeInit(int argc, char **argv)
Definition: hs_list.c:26
E char * s_ChanServ
Definition: extern.h:285
char * creator
Definition: services.h:1112
E int strftime_lang(char *buf, int size, User *u, int format, struct tm *tm)
Definition: language.c:240
MDE int moduleAddCommand(CommandHash *cmdTable[], Command *c, int pos)
Definition: modules.c:1082
E HostCore * hostCoreListHead()
Definition: hostserv.c:116
MDE void moduleSetHostHelp(void(*func)(User *u))
Definition: modules.c:2138
char * nick
Definition: services.h:1109
#define BUFSIZE
Definition: config.h:47
#define MOD_UNIQUE
Definition: module.h:11