Permalink
Browse files

Proper handling of RPL_ISUPPORT PREFIX

  • Loading branch information...
1 parent c409f37 commit e2e96fa23d33005dc2e44555a63a404130efb0c8 ec429 committed Dec 24, 2011
Showing with 82 additions and 10 deletions.
  1. +5 −1 buffer.c
  2. +2 −1 buffer.h
  3. +55 −7 irc.c
  4. +7 −0 irc.h
  5. +13 −1 plans
View
@@ -141,7 +141,10 @@ int init_buffer(int buf, btype type, const char *bname, int nlines)
bufs[buf].conninpr=false;
initibuf(&bufs[buf].input);
bufs[buf].casemapping=RFC1459;
- bufs[buf].prefixes=NULL;
+ bufs[buf].npfx=2;
+ bufs[buf].prefixes=malloc(2*sizeof(prefix));
+ bufs[buf].prefixes[0]=(prefix){.letter='o', .pfx='@'};
+ bufs[buf].prefixes[1]=(prefix){.letter='v', .pfx='+'};
bufs[buf].autoent=NULL;
return(0);
}
@@ -198,6 +201,7 @@ int free_buffer(int buf)
if(bufs[buf].lpl) free(bufs[buf].lpl);
if(bufs[buf].ts) free(bufs[buf].ts);
freeibuf(&bufs[buf].input);
+ free(bufs[buf].prefixes);
if(cbuf>=buf)
cbuf--;
nbufs--;
View
@@ -70,7 +70,8 @@ typedef struct _buf
bool conninpr; // connection in progress? (SERVER only)
ibuffer input; // input history
cmap casemapping; // the SERVER's value is authoritative; the CHANNEL's value is ignored. STATUS's value is irrelevant. Set by ISUPPORT
- char *prefixes; // ^^
+ unsigned int npfx;// ^^
+ prefix *prefixes; // ^^
servlist * autoent; // if this was opened by autoconnect(), this is filled in to point to the server's servlist entry
bool conf; // Conference Mode (hides joins, parts, quits, and /nicks)
}
View
62 irc.c
@@ -516,7 +516,49 @@ int irc_numeric(message pkt, int b)
}
else if(strcmp(rest, "PREFIX")==0)
{
- bufs[b].prefixes=value?strdup(value):NULL;
+ if(value)
+ {
+ if(*value=='(')
+ {
+ char *p=strchr(value, ')');
+ if(p)
+ {
+ unsigned int npfx=p-value-1;
+ prefix *pfxs=malloc(npfx*sizeof(prefix));
+ if(!pfxs)
+ e_buf_print(b, c_err, pkt, "RPL_ISUPPORT: Discarded PREFIX - malloc failure: ");
+ else
+ {
+ unsigned int i;
+ for(i=0;i<npfx;i++)
+ {
+ pfxs[i].letter=value[i+1];
+ if(!(pfxs[i].pfx=p[i+1]))
+ {
+ if(!quiet) e_buf_print(b, c_err, pkt, "RPL_ISUPPORT: Malformed PREFIX - unbalanced parts: ");
+ break;
+ }
+ }
+ if(i==npfx)
+ {
+ free(bufs[b].prefixes);
+ bufs[b].npfx=npfx;
+ bufs[b].prefixes=pfxs;
+ }
+ }
+ }
+ else
+ if(!quiet) e_buf_print(b, c_err, pkt, "RPL_ISUPPORT: Malformed PREFIX - missing ')': ");
+ }
+ else
+ if(!quiet) e_buf_print(b, c_err, pkt, "RPL_ISUPPORT: Malformed PREFIX - missing '(': ");
+ }
+ else
+ {
+ free(bufs[b].prefixes);
+ bufs[b].npfx=0;
+ bufs[b].prefixes=NULL;
+ }
}
else
{
@@ -533,9 +575,6 @@ int irc_numeric(message pkt, int b)
if(!quiet) e_buf_print(b, c_err, pkt, "RPL_NAMREPLY: Not enough arguments: ");
break;
}
- char *plist=bufs[bufs[b].server].prefixes?strchr(bufs[bufs[b].server].prefixes, ')'):NULL;
- if(plist)
- plist++;
for(b2=0;b2<nbufs;b2++)
{
if((bufs[b2].server==b) && (bufs[b2].type==CHANNEL) && (irc_strcasecmp(pkt.args[2], bufs[b2].bname, bufs[b].casemapping)==0))
@@ -549,10 +588,19 @@ int irc_numeric(message pkt, int b)
char *nn=strtok(pkt.args[3], " ");
while(nn)
{
- if(plist) // skip over prefix characters
+ if(bufs[b].prefixes) // skip over prefix characters
{
- while(strchr(plist, *nn))
- nn++;
+ while(*nn)
+ {
+ unsigned int i;
+ for(i=0;i<bufs[b].npfx;i++)
+ {
+ if(*nn==bufs[b].prefixes[i].pfx)
+ break;
+ }
+ if(i<bufs[b].npfx) nn++;
+ else break;
+ }
}
n_add(&bufs[b2].nlist, nn, bufs[b].casemapping);
nn=strtok(NULL, " ");
View
7 irc.h
@@ -31,6 +31,13 @@ typedef enum
}
cmap;
+typedef struct
+{
+ char letter;
+ char pfx;
+}
+prefix;
+
typedef struct
{
char *prefix;
View
14 plans
@@ -6,18 +6,28 @@ curses. The current hardwired ANSI-escapes code for painting the screen is clum
Need to fix the problem of the conn_rest not getting called for eg worldofspectrum (why is this happening?)
+Handle CTCP correctly, on both receive (rx_privmsg()) and send (talk()).
+
Fix possible issue with CTCP. Funny stuff (including random characters) happened when eg spike1 sent a CTCP PONG to the channel.
Fix issue with an infinite loop in irc_rx of bytes==0 from recv(). Don't fully understand what causes it.
Make hidden lines (quiet mode, conference mode, etc.) be stored in scrollback. Filter on render; that way changes are retroactive.
-Find a way to make getaddrinfo() calls asynch. They currently block everything on connect, which means that /server can cause existing connections to ping off.
+Optionally fold runs of the same type of message. Eg.: =foo=bar=baz= have joined #whatever.
+
+Make getaddrinfo() calls use getaddrinfo_a(). They currently block everything on connect, which means that /server can cause existing connections to ping off. (However, getaddrinfo_a() is not portable and some 64-bit libc have bugs, so we need a switch to disable its use.)
+
+Handle \ in tab-completion. It should be expanded to \\.
Make /close on server tabs close the associated channel tabs. /disconnect the same, presumably.
+/realsname cmd to display the real server name (which we already store, anyway).
+
Store nicks uncrushed in unproc. Makes '/set mnln' retroactive.
+Option for no hanging indent (wordline() tabx=0).
+
Const-correctness. There are a lot of functions taking a char * that should take a const char *.
Remember channel keys for /rejoin. An argument to /rejoin overrides (but doesn't overwrite unless the /rejoin succeeds).
@@ -26,6 +36,8 @@ Modes. It's really about time I got those sorted out.
Proper handling of Unicode in character-based things like cursor-movement, backspace.
+Use unicode-charmap (somewhere in system i18n) to find out character widths, for wordline().
+
Improve the parsing of mirc-colour-codes (to fix things like \003124 which currently gets eaten entirely). The relevant code is in bits.c.
/dump command. Pipes a screendump (or better still, unprocessed text) into program of choice.

0 comments on commit e2e96fa

Please sign in to comment.