#include "tools.h"
#include "UserNode.h"
+#include "ChanNode.h"
#include "lang.h"
+#include "ClientSocket.h"
static const struct default_language_entry msgtab[] = {
{"TIME_MASK_2_ITEMS", "%s and %s"},
struct ModeBuffer *modeBuf = malloc(sizeof(*modeBuf));
if(!modeBuf) {
perror("malloc() failed");
- return;
+ return NULL;
}
modeBuf->client = client;
modeBuf->chan = chan;
free(modeBuf);
}
+int is_ircmask(const char *text) {
+ while (*text && (isalnum((char)*text) || strchr("-_[]|\\`^{}?*", *text)))
+ text++;
+ if (*text++ != '!')
+ return 0;
+ while (*text && *text != '@' && !isspace((char)*text))
+ text++;
+ if (*text++ != '@')
+ return 0;
+ while (*text && !isspace((char)*text))
+ text++;
+ return !*text;
+}
+
+char* generate_banmask(struct UserNode *user, char *buffer) {
+ char *userhost = user->host;
+
+ if(isFakeHost(user->host)) {
+ sprintf(buffer, "*!*@%s", userhost);
+ return buffer;
+ }
+
+ //check if the hostname has more than 4 connections (trusted host)
+ if(countUsersWithHost(userhost) > 4) {
+ sprintf(buffer, "*!%s@%s", user->ident, userhost);
+ return buffer;
+ } else {
+ sprintf(buffer, "*!*@%s", userhost);
+ return buffer;
+ }
+}
+
+char* make_banmask(char *input, char* buffer) {
+ char *nick = NULL, *ident = NULL, *host = NULL;
+ char tmp[HOSTLEN];
+ char *p;
+ if((p = strstr(input, "!"))) {
+ nick = input;
+ *p = '\0';
+ ident = p+1;
+ if((p = strstr(ident, "@"))) {
+ *p = '\0';
+ host = p+1;
+ }
+ } else if((p = strstr(input, "@"))) {
+ ident = input;
+ *p = '\0';
+ host = p+1;
+ } else if((p = strstr(input, "."))) {
+ host = input;
+ } else if(*input == '*' && !strstr(input+1, "*")) {
+ //AUTH MASK
+ p = getAuthFakehost(input+1);
+ if(p)
+ host = p;
+ else {
+ sprintf(tmp, "%s.*", input+1);
+ host = tmp;
+ }
+ } else {
+ struct UserNode *user = searchUserByNick(input);
+ if(user)
+ return generate_banmask(user, buffer);
+ else
+ nick = input;
+ }
+ if(nick && *nick == '\0') nick = NULL;
+ if(ident && *ident == '\0') ident = NULL;
+ if(host && *host == '\0') host = NULL;
+ sprintf(buffer, "%s!%s@%s", (nick ? nick : "*"), (ident ? ident : "*"), (host ? host : "*"));
+ return buffer;
+}
+
+int isFakeHost(char *host) {
+ char *p1, *p2 = host;
+
+ //find the last dot to identify if the hostmask is a fake host
+ while((p1 = strstr(p2, "."))) {
+ p2 = p1 + 1;
+ }
+ //TLD database: http://www.iana.org/domains/root/db/
+ //the longest TLD i found was 6 chars long (ignoring the stange exotic ones :D)
+ //but we even ignore '.museum' and '.travel' so we can say that the TLD of our mask needs to be less than 4 chars to be a real domain
+ return (strlen(p2+1) > 4);
+}
+
void init_tools() {
register_default_language_table(msgtab);
}