[BACK]Return to class.c CVS log [TXT][DIR] Up to [local] / ircnowd / src / ngircd

Annotation of ircnowd/src/ngircd/class.c, Revision 1.1.1.1

1.1       tomglok     1: /*
                      2:  * ngIRCd -- The Next Generation IRC Daemon
                      3:  * Copyright (c)2001-2014 Alexander Barton (alex@barton.de) and Contributors.
                      4:  *
                      5:  * This program is free software; you can redistribute it and/or modify
                      6:  * it under the terms of the GNU General Public License as published by
                      7:  * the Free Software Foundation; either version 2 of the License, or
                      8:  * (at your option) any later version.
                      9:  * Please read the file COPYING, README and AUTHORS for more information.
                     10:  */
                     11:
                     12: #include "portab.h"
                     13:
                     14: /**
                     15:  * @file
                     16:  * User class management.
                     17:  */
                     18:
                     19: #include <assert.h>
                     20: #include <stdio.h>
                     21: #include <string.h>
                     22:
                     23: #include "conn.h"
                     24: #include "lists.h"
                     25:
                     26: #include "class.h"
                     27:
                     28: struct list_head My_Classes[CLASS_COUNT];
                     29:
                     30: GLOBAL void
                     31: Class_Init(void)
                     32: {
                     33:        memset(My_Classes, 0, sizeof(My_Classes));
                     34: }
                     35:
                     36: GLOBAL void
                     37: Class_Exit(void)
                     38: {
                     39:        int i;
                     40:
                     41:        for (i = 0; i < CLASS_COUNT; Lists_Free(&My_Classes[i++]));
                     42: }
                     43:
                     44: GLOBAL bool
                     45: Class_GetMemberReason(const int Class, CLIENT *Client, char *reason, size_t len)
                     46: {
                     47:        char str[COMMAND_LEN];
                     48:
                     49:        assert(Class < CLASS_COUNT);
                     50:        assert(Client != NULL);
                     51:
                     52:        strlcpy(str, "listed", sizeof(str));
                     53:
                     54:        if (!Lists_CheckReason(&My_Classes[Class], Client, str, sizeof(str)))
                     55:                return false;
                     56:
                     57:        switch(Class) {
                     58:                case CLASS_GLINE:
                     59:                        snprintf(reason, len, "\"%s\" (G-Line)", str);
                     60:                        break;
                     61:                case CLASS_KLINE:
                     62:                        snprintf(reason, len, "\"%s\" (K-Line)", str);
                     63:                        break;
                     64:                default:
                     65:                        snprintf(reason, len, "%s", str);
                     66:                        break;
                     67:        }
                     68:        return true;
                     69: }
                     70:
                     71: /**
                     72:  * Check if a client is banned from this server: GLINE, KLINE.
                     73:  *
                     74:  * If a client isn't allowed to connect, it will be disconnected again.
                     75:  *
                     76:  * @param Client The client to check.
                     77:  * @return CONNECTED if client is allowed to join, DISCONNECTED if not.
                     78:  */
                     79: GLOBAL bool
                     80: Class_HandleServerBans(CLIENT *Client)
                     81: {
                     82:        char reject[COMMAND_LEN];
                     83:
                     84:        assert(Client != NULL);
                     85:
                     86:        if (Class_GetMemberReason(CLASS_GLINE, Client, reject, sizeof(reject)) ||
                     87:            Class_GetMemberReason(CLASS_KLINE, Client, reject, sizeof(reject))) {
                     88:                Client_Reject(Client, reject, true);
                     89:                return DISCONNECTED;
                     90:        }
                     91:
                     92:        return CONNECTED;
                     93: }
                     94:
                     95:
                     96: GLOBAL bool
                     97: Class_AddMask(const int Class, const char *Pattern, time_t ValidUntil,
                     98:              const char *Reason)
                     99: {
                    100:        char mask[MASK_LEN];
                    101:
                    102:        assert(Class < CLASS_COUNT);
                    103:        assert(Pattern != NULL);
                    104:        assert(Reason != NULL);
                    105:
                    106:        Lists_MakeMask(Pattern, mask, sizeof(mask));
                    107:        return Lists_Add(&My_Classes[Class], mask,
                    108:                         ValidUntil, Reason, false);
                    109: }
                    110:
                    111: GLOBAL void
                    112: Class_DeleteMask(const int Class, const char *Pattern)
                    113: {
                    114:        char mask[MASK_LEN];
                    115:
                    116:        assert(Class < CLASS_COUNT);
                    117:        assert(Pattern != NULL);
                    118:
                    119:        Lists_MakeMask(Pattern, mask, sizeof(mask));
                    120:        Lists_Del(&My_Classes[Class], mask);
                    121: }
                    122:
                    123: GLOBAL struct list_head *
                    124: Class_GetList(const int Class)
                    125: {
                    126:        assert(Class < CLASS_COUNT);
                    127:
                    128:        return &My_Classes[Class];
                    129: }
                    130:
                    131: GLOBAL void
                    132: Class_Expire(void)
                    133: {
                    134:        Lists_Expire(&My_Classes[CLASS_GLINE], "G-Line");
                    135:        Lists_Expire(&My_Classes[CLASS_KLINE], "K-Line");
                    136: }
                    137:
                    138: /* -eof- */

CVSweb