]> jfr.im git - solanum.git/blobdiff - modules/m_cap.c
modules: chase MsgBuf API change
[solanum.git] / modules / m_cap.c
index 5b696250131461cbdabd54eb41a5f11f6291f81b..0860dfd8a48024ef0e8af399b2ba852f61820159 100644 (file)
@@ -1,5 +1,5 @@
 /* modules/m_cap.c
- * 
+ *
  *  Copyright (C) 2005 Lee Hardy <lee@leeh.co.uk>
  *  Copyright (C) 2005 ircd-ratbox development team
  *
@@ -33,7 +33,7 @@
 #include "stdinc.h"
 #include "class.h"
 #include "client.h"
-#include "irc_string.h"
+#include "match.h"
 #include "ircd.h"
 #include "numeric.h"
 #include "msg.h"
 #include "modules.h"
 #include "s_serv.h"
 #include "s_user.h"
+#include "send.h"
+#include "s_conf.h"
+#include "hash.h"
 
 typedef int (*bqcmp)(const void *, const void *);
 
-static int m_cap(struct Client *, struct Client *, int, const char **);
+static int m_cap(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
 static int modinit(void);
 
 struct Message cap_msgtab = {
@@ -55,8 +58,8 @@ struct Message cap_msgtab = {
 mapi_clist_av1 cap_clist[] = { &cap_msgtab, NULL };
 DECLARE_MODULE_AV1(cap, modinit, NULL, cap_clist, NULL, NULL, "$Revision: 676 $");
 
-#define _CLICAP(name, capserv, capclient, flags)       \
-       { (name), (capserv), (capclient), (flags), sizeof(name) - 1 }
+#define _CLICAP(name, capserv, capclient, caprequired, flags)  \
+       { (name), (capserv), (capclient), (caprequired), (flags), sizeof(name) - 1 }
 
 #define CLICAP_FLAGS_STICKY    0x001
 
@@ -65,11 +68,19 @@ static struct clicap
        const char *name;
        int cap_serv;           /* for altering s->c */
        int cap_cli;            /* for altering c->s */
+       int cap_required_serv;  /* required dependency cap */
        int flags;
        int namelen;
 } clicap_list[] = {
-       _CLICAP("multi-prefix", CLICAP_MULTI_PREFIX, 0, 0),
-       _CLICAP("sasl", CLICAP_SASL, 0, 0)
+       _CLICAP("multi-prefix", CLICAP_MULTI_PREFIX, 0, 0, 0),
+       _CLICAP("sasl", CLICAP_SASL, 0, 0, CLICAP_FLAGS_STICKY),
+       _CLICAP("account-notify", CLICAP_ACCOUNT_NOTIFY, 0, 0, 0),
+       _CLICAP("extended-join", CLICAP_EXTENDED_JOIN, 0, 0, 0),
+       _CLICAP("away-notify", CLICAP_AWAY_NOTIFY, 0, 0, 0),
+       _CLICAP("tls", CLICAP_TLS, 0, 0, 0),
+       _CLICAP("userhost-in-names", CLICAP_USERHOST_IN_NAMES, 0, 0, 0),
+       _CLICAP("cap-notify", CLICAP_CAP_NOTIFY, 0, 0, 0),
+       _CLICAP("chghost", CLICAP_CHGHOST, 0, 0, 0),
 };
 
 #define CLICAP_LIST_LEN (sizeof(clicap_list) / sizeof(struct clicap))
@@ -116,7 +127,7 @@ clicap_find(const char *data, int *negate, int *finished)
 
        if(data)
        {
-               strlcpy(buf, data, sizeof(buf));
+               rb_strlcpy(buf, data, sizeof(buf));
                p = buf;
        }
 
@@ -146,7 +157,7 @@ clicap_find(const char *data, int *negate, int *finished)
        if((s = strchr(p, ' ')))
                *s++ = '\0';
 
-       if((cap = bsearch(p, clicap_list, CLICAP_LIST_LEN, 
+       if((cap = bsearch(p, clicap_list, CLICAP_LIST_LEN,
                                sizeof(struct clicap), (bqcmp) clicap_compare)))
        {
                if(s)
@@ -174,11 +185,11 @@ clicap_generate(struct Client *source_p, const char *subcmd, int flags, int clea
        char *p;
        int buflen = 0;
        int curlen, mlen;
-       int i;
+       size_t i;
 
-       mlen = rb_sprintf(buf, ":%s CAP %s %s",
-                       me.name, 
-                       EmptyString(source_p->name) ? "*" : source_p->name, 
+       mlen = sprintf(buf, ":%s CAP %s %s",
+                       me.name,
+                       EmptyString(source_p->name) ? "*" : source_p->name,
                        subcmd);
 
        p = capbuf;
@@ -202,6 +213,18 @@ clicap_generate(struct Client *source_p, const char *subcmd, int flags, int clea
                                continue;
                }
 
+               if (clicap_list[i].cap_serv == CLICAP_SASL)
+               {
+                       struct Client *agent_p = NULL;
+
+                       if (!ConfigFileEntry.sasl_service)
+                               continue;
+
+                       agent_p = find_named_client(ConfigFileEntry.sasl_service);
+                       if (agent_p == NULL || !IsService(agent_p))
+                               continue;
+               }
+
                /* \r\n\0, possible "-~=", space, " *" */
                if(buflen + clicap_list[i].namelen >= BUFSIZE - 10)
                {
@@ -222,35 +245,9 @@ clicap_generate(struct Client *source_p, const char *subcmd, int flags, int clea
                {
                        *p++ = '-';
                        buflen++;
-
-                       /* needs a client ack */
-                       if(clicap_list[i].cap_cli && 
-                          IsCapable(source_p, clicap_list[i].cap_cli))
-                       {
-                               *p++ = '~';
-                               buflen++;
-                       }
                }
-               else
-               {
-                       if(clicap_list[i].flags & CLICAP_FLAGS_STICKY)
-                       {
-                               *p++ = '=';
-                               buflen++;
-                       }
 
-                       /* if we're doing an LS, then we only send this if
-                        * they havent ack'd
-                        */
-                       if(clicap_list[i].cap_cli &&
-                          (!flags || !IsCapable(source_p, clicap_list[i].cap_cli)))
-                       {
-                               *p++ = '~';
-                               buflen++;
-                       }
-               }
-
-               curlen = rb_sprintf(p, "%s ", clicap_list[i].name);
+               curlen = sprintf(p, "%s ", clicap_list[i].name);
                p += curlen;
                buflen += curlen;
        }
@@ -300,7 +297,7 @@ cap_ack(struct Client *source_p, const char *arg)
 static void
 cap_clear(struct Client *source_p, const char *arg)
 {
-       clicap_generate(source_p, "ACK", 
+       clicap_generate(source_p, "ACK",
                        source_p->localClient->caps ? source_p->localClient->caps : -1, 1);
 
        /* XXX - sticky capabs */
@@ -319,11 +316,9 @@ cap_end(struct Client *source_p, const char *arg)
 
        source_p->flags &= ~FLAGS_CLICAP;
 
-       if(source_p->name[0] && source_p->user)
+       if(source_p->name[0] && source_p->flags & FLAGS_SENTUSER)
        {
-               char buf[USERLEN+1];
-               strlcpy(buf, source_p->username, sizeof(buf));
-               register_local_user(source_p, source_p, buf);
+               register_local_user(source_p, source_p);
        }
 }
 
@@ -362,7 +357,7 @@ cap_req(struct Client *source_p, const char *arg)
        if(EmptyString(arg))
                return;
 
-       buflen = rb_snprintf(buf, sizeof(buf), ":%s CAP %s ACK",
+       buflen = snprintf(buf, sizeof(buf), ":%s CAP %s ACK",
                        me.name, EmptyString(source_p->name) ? "*" : source_p->name);
 
        pbuf[0][0] = '\0';
@@ -397,10 +392,28 @@ cap_req(struct Client *source_p, const char *arg)
                }
                else
                {
-                       if(cap->flags & CLICAP_FLAGS_STICKY)
+                       if(cap->cap_required_serv && !((capadd & cap->cap_required_serv) == cap->cap_required_serv || IsCapable(source_p, cap->cap_required_serv)))
                        {
-                               strcat(pbuf[i], "=");
-                               plen++;
+                               finished = 0;
+                               break;
+                       }
+
+                       if (cap->cap_serv == CLICAP_SASL)
+                       {
+                               struct Client *agent_p = NULL;
+
+                               if (!ConfigFileEntry.sasl_service)
+                               {
+                                       finished = 0;
+                                       break;
+                               }
+
+                               agent_p = find_named_client(ConfigFileEntry.sasl_service);
+                               if (agent_p == NULL || !IsService(agent_p))
+                               {
+                                       finished = 0;
+                                       break;
+                               }
                        }
 
                        capadd |= cap->cap_serv;
@@ -413,8 +426,10 @@ cap_req(struct Client *source_p, const char *arg)
                }
 
                strcat(pbuf[i], cap->name);
-               strcat(pbuf[i], " ");
-               plen += (cap->namelen + 1);
+               if (!finished) {
+                       strcat(pbuf[i], " ");
+                       plen += (cap->namelen + 1);
+               }
        }
 
        if(!finished)
@@ -457,7 +472,7 @@ clicap_cmd_search(const char *command, struct clicap_cmd *entry)
 }
 
 static int
-m_cap(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
+m_cap(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
 {
        struct clicap_cmd *cmd;