]> jfr.im git - irc/rqf/shadowircd.git/blobdiff - modules/m_resv.c
Remove some more references to parv[0] in comments.
[irc/rqf/shadowircd.git] / modules / m_resv.c
index b2e280270ed14a534ff5c6fd5589b44938a57ffd..5b35f2a581a7954a4bc2ca30219361fd21630b1c 100644 (file)
@@ -36,8 +36,7 @@
 #include "s_conf.h"
 #include "s_newconf.h"
 #include "hash.h"
-#include "s_log.h"
-#include "sprintf_irc.h"
+#include "logger.h"
 
 static int mo_resv(struct Client *, struct Client *, int, const char **);
 static int ms_resv(struct Client *, struct Client *, int, const char **);
@@ -67,11 +66,10 @@ static void cluster_resv(struct Client *source_p, int temp_time,
 
 static void handle_remote_unresv(struct Client *source_p, const char *name);
 static void remove_resv(struct Client *source_p, const char *name);
-static int remove_temp_resv(struct Client *source_p, const char *name);
+static int remove_resv_from_file(struct Client *source_p, const char *name);
 
 /*
  * mo_resv()
- *      parv[0] = sender prefix
  *      parv[1] = channel/nick to forbid
  *      parv[2] = reason
  */
@@ -84,6 +82,13 @@ mo_resv(struct Client *client_p, struct Client *source_p, int parc, const char *
        int temp_time;
        int loc = 1;
 
+       if(!IsOperResv(source_p))
+       {
+               sendto_one(source_p, form_str(ERR_NOPRIVS),
+                          me.name, source_p->name, "resv");
+               return 0;
+       }
+
        /* RESV [time] <name> [ON <server>] :<reason> */
 
        if((temp_time = valid_temp_time(parv[loc])) >= 0)
@@ -125,7 +130,7 @@ mo_resv(struct Client *client_p, struct Client *source_p, int parc, const char *
                if(match(target_server, me.name) == 0)
                        return 0;
        }
-       else if(dlink_list_length(&cluster_conf_list) > 0)
+       else if(rb_dlink_list_length(&cluster_conf_list) > 0)
                cluster_resv(source_p, temp_time, name, reason);
 
        parse_resv(source_p, name, reason, temp_time);
@@ -134,7 +139,6 @@ mo_resv(struct Client *client_p, struct Client *source_p, int parc, const char *
 }
 
 /* ms_resv()
- *     parv[0] = sender prefix
  *     parv[1] = target server
  *     parv[2] = channel/nick to forbid
  *     parv[3] = reason
@@ -143,8 +147,8 @@ static int
 ms_resv(struct Client *client_p, struct Client *source_p,
        int parc, const char *parv[])
 {
-       /* parv[0]  parv[1]        parv[2]  parv[3]
-        * oper     target server  resv     reason
+       /* source_p  parv[1]        parv[2]  parv[3]
+        * oper      target server  resv     reason
         */
        propagate_resv(source_p, parv[1], 0, parv[2], parv[3]);
 
@@ -186,7 +190,7 @@ parse_resv(struct Client *source_p, const char *name,
 
        if(!MyClient(source_p) && 
           !find_shared_conf(source_p->username, source_p->host,
-                       source_p->user->server
+                       source_p->servptr->name
                        (temp_time > 0) ? SHARED_TRESV : SHARED_PRESV))
                return;
 
@@ -217,13 +221,13 @@ parse_resv(struct Client *source_p, const char *name,
                aconf = make_conf();
                aconf->status = CONF_RESV_CHANNEL;
                aconf->port = 0;
-               DupString(aconf->name, name);
-               DupString(aconf->passwd, reason);
+               aconf->name = rb_strdup(name);
+               aconf->passwd = rb_strdup(reason);
                add_to_resv_hash(aconf->name, aconf);
 
                if(temp_time > 0)
                {
-                       aconf->hold = CurrentTime + temp_time;
+                       aconf->hold = rb_current_time() + temp_time;
 
                        sendto_realops_snomask(SNO_GENERAL, L_ALL,
                                     "%s added temporary %d min. RESV for [%s] [%s]",
@@ -264,7 +268,7 @@ parse_resv(struct Client *source_p, const char *name,
                        return;
                }
 
-               if(find_nick_resv(name))
+               if(find_nick_resv_mask(name))
                {
                        sendto_one_notice(source_p,
                                           ":A RESV has already been placed on nick: %s",
@@ -275,13 +279,13 @@ parse_resv(struct Client *source_p, const char *name,
                aconf = make_conf();
                aconf->status = CONF_RESV_NICK;
                aconf->port = 0;
-               DupString(aconf->name, name);
-               DupString(aconf->passwd, reason);
-               dlinkAddAlloc(aconf, &resv_conf_list);
+               aconf->name = rb_strdup(name);
+               aconf->passwd = rb_strdup(reason);
+               rb_dlinkAddAlloc(aconf, &resv_conf_list);
 
                if(temp_time > 0)
                {
-                       aconf->hold = CurrentTime + temp_time;
+                       aconf->hold = rb_current_time() + temp_time;
 
                        sendto_realops_snomask(SNO_GENERAL, L_ALL,
                                     "%s added temporary %d min. RESV for [%s] [%s]",
@@ -330,9 +334,9 @@ cluster_resv(struct Client *source_p, int temp_time, const char *name,
                const char *reason)
 {
        struct remote_conf *shared_p;
-       dlink_node *ptr;
+       rb_dlink_node *ptr;
 
-       DLINK_FOREACH(ptr, cluster_conf_list.head)
+       RB_DLINK_FOREACH(ptr, cluster_conf_list.head)
        {
                shared_p = ptr->data;
 
@@ -364,12 +368,18 @@ cluster_resv(struct Client *source_p, int temp_time, const char *name,
 
 /*
  * mo_unresv()
- *     parv[0] = sender prefix
  *     parv[1] = channel/nick to unforbid
  */
 static int
 mo_unresv(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
 {
+       if(!IsOperResv(source_p))
+       {
+               sendto_one(source_p, form_str(ERR_NOPRIVS),
+                          me.name, source_p->name, "resv");
+               return 0;
+       }
+
        if((parc == 4) && (irccmp(parv[2], "ON") == 0))
        {
                if(!IsOperRemoteBan(source_p))
@@ -385,27 +395,23 @@ mo_unresv(struct Client *client_p, struct Client *source_p, int parc, const char
                if(match(parv[3], me.name) == 0)
                        return 0;
        }
-       else if(dlink_list_length(&cluster_conf_list) > 0)
+       else if(rb_dlink_list_length(&cluster_conf_list) > 0)
                cluster_generic(source_p, "UNRESV", SHARED_UNRESV, CAP_CLUSTER,
                                "%s", parv[1]);
 
-       if(remove_temp_resv(source_p, parv[1]))
-               return 0;
-
        remove_resv(source_p, parv[1]);
        return 0;
 }
 
 /* ms_unresv()
- *     parv[0] = sender prefix
  *     parv[1] = target server
  *     parv[2] = resv to remove
  */
 static int
 ms_unresv(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
 {
-       /* parv[0]  parv[1]        parv[2]
-        * oper     target server  resv to remove
+       /* source_p  parv[1]        parv[2]
+        * oper      target server  resv to remove
         */
        propagate_generic(source_p, "UNRESV", parv[1], CAP_CLUSTER,
                        "%s", parv[2]);
@@ -435,10 +441,7 @@ static void
 handle_remote_unresv(struct Client *source_p, const char *name)
 {
        if(!find_shared_conf(source_p->username, source_p->host,
-                               source_p->user->server, SHARED_UNRESV))
-               return;
-
-       if(remove_temp_resv(source_p, name))
+                               source_p->servptr->name, SHARED_UNRESV))
                return;
 
        remove_resv(source_p, name);
@@ -446,28 +449,39 @@ handle_remote_unresv(struct Client *source_p, const char *name)
        return;
 }
 
-static int
-remove_temp_resv(struct Client *source_p, const char *name)
+static void
+remove_resv(struct Client *source_p, const char *name)
 {
        struct ConfItem *aconf = NULL;
 
        if(IsChannelName(name))
        {
                if((aconf = hash_find_resv(name)) == NULL)
-                       return 0;
+               {
+                       sendto_one_notice(source_p, ":No RESV for %s", name);
+                       return;
+               }
 
-               /* its permanent, let remove_resv do it properly */
                if(!aconf->hold)
-                       return 0;
-
+               {
+                       if (!remove_resv_from_file(source_p, name))
+                               return;
+               }
+               else
+               {
+                       sendto_one_notice(source_p, ":RESV for [%s] is removed", name);
+                       sendto_realops_snomask(SNO_GENERAL, L_ALL,
+                                       "%s has removed the RESV for: [%s]", 
+                                       get_oper_name(source_p), name);
+                       ilog(L_KLINE, "UR %s %s", get_oper_name(source_p), name);
+               }
                del_from_resv_hash(name, aconf);
-               free_conf(aconf);
        }
        else
        {
-               dlink_node *ptr;
+               rb_dlink_node *ptr;
 
-               DLINK_FOREACH(ptr, resv_conf_list.head)
+               RB_DLINK_FOREACH(ptr, resv_conf_list.head)
                {
                        aconf = ptr->data;
 
@@ -478,35 +492,42 @@ remove_temp_resv(struct Client *source_p, const char *name)
                }
 
                if(aconf == NULL)
-                       return 0;
+               {
+                       sendto_one_notice(source_p, ":No RESV for %s", name);
+                       return;
+               }
 
-               /* permanent, remove_resv() needs to do it properly */
                if(!aconf->hold)
-                       return 0;
-
+               {
+                       if (!remove_resv_from_file(source_p, name))
+                               return;
+               }
+               else
+               {
+                       sendto_one_notice(source_p, ":RESV for [%s] is removed", name);
+                       sendto_realops_snomask(SNO_GENERAL, L_ALL,
+                                       "%s has removed the RESV for: [%s]", 
+                                       get_oper_name(source_p), name);
+                       ilog(L_KLINE, "UR %s %s", get_oper_name(source_p), name);
+               }
                /* already have ptr from the loop above.. */
-               dlinkDestroy(ptr, &resv_conf_list);
-               free_conf(aconf);
+               rb_dlinkDestroy(ptr, &resv_conf_list);
        }
+       free_conf(aconf);
 
-       sendto_one_notice(source_p, ":RESV for [%s] is removed", name);
-       sendto_realops_snomask(SNO_GENERAL, L_ALL,
-                       "%s has removed the RESV for: [%s]", 
-                       get_oper_name(source_p), name);
-       ilog(L_KLINE, "UR %s %s", get_oper_name(source_p), name);
-
-       return 1;
+       return;
 }
 
-/* remove_resv()
+/* remove_resv_from_file()
  *
  * inputs      - client removing the resv
  *             - resv to remove
  * outputs     -
- * side effects - resv if found, is removed
+ * side effects - resv if found, is removed from conf
+ *              - does not touch resv hash or resv_conf_list
  */
-static void
-remove_resv(struct Client *source_p, const char *name)
+static int
+remove_resv_from_file(struct Client *source_p, const char *name)
 {
        FILE *in, *out;
        char buf[BUFSIZE];
@@ -518,13 +539,13 @@ remove_resv(struct Client *source_p, const char *name)
        int error_on_write = 0;
        int found_resv = 0;
 
-       ircsprintf(temppath, "%s.tmp", ConfigFileEntry.resvfile);
+       rb_sprintf(temppath, "%s.tmp", ConfigFileEntry.resvfile);
        filename = get_conf_name(RESV_TYPE);
 
        if((in = fopen(filename, "r")) == NULL)
        {
                sendto_one_notice(source_p, ":Cannot open %s", filename);
-               return;
+               return 0;
        }
 
        oldumask = umask(0);
@@ -534,7 +555,7 @@ remove_resv(struct Client *source_p, const char *name)
                sendto_one_notice(source_p, ":Cannot open %s", temppath);
                fclose(in);
                umask(oldumask);
-               return;
+               return 0;
        }
 
        umask(oldumask);
@@ -551,7 +572,7 @@ remove_resv(struct Client *source_p, const char *name)
                        break;
                }
 
-               strlcpy(buff, buf, sizeof(buff));
+               rb_strlcpy(buff, buf, sizeof(buff));
 
                if((p = strchr(buff, '\n')) != NULL)
                        *p = '\0';
@@ -585,27 +606,28 @@ remove_resv(struct Client *source_p, const char *name)
        if(error_on_write)
        {
                sendto_one_notice(source_p, ":Couldn't write temp resv file, aborted");
-               return;
+               return 0;
        }
        else if(!found_resv)
        {
-               sendto_one_notice(source_p, ":No RESV for %s", name);
+               sendto_one_notice(source_p, ":Cannot find RESV for %s in file", name);
 
                if(temppath != NULL)
                        (void) unlink(temppath);
 
-               return;
+               return 0;
        }
 
        if (rename(temppath, filename))
        {
                sendto_one_notice(source_p, ":Couldn't rename temp file, aborted");
-               return;
+               return 0;
        }
-       rehash_bans(0);
 
        sendto_one_notice(source_p, ":RESV for [%s] is removed", name);
        sendto_realops_snomask(SNO_GENERAL, L_ALL,
                             "%s has removed the RESV for: [%s]", get_oper_name(source_p), name);
        ilog(L_KLINE, "UR %s %s", get_oper_name(source_p), name);
+
+       return 1;
 }