Permalink
Browse files

irc_breakdown() function, parses :prefix cmd args...

  • Loading branch information...
1 parent 85b7aea commit 61b265888e8ab00e363792203fd5c2f5978f90f4 Sound and Fury committed Sep 14, 2010
Showing with 57 additions and 9 deletions.
  1. +44 −0 irc.c
  2. +11 −0 irc.h
  3. +2 −9 quirc.c
View
44 irc.c
@@ -172,6 +172,50 @@ int irc_rx(int fd, char ** data)
return(0);
}
+message irc_breakdown(char *packet)
+{
+ message rv;
+ if(*packet==':')
+ {
+ rv->prefix=strtok(packet, " ");
+ rv->cmd=strtok(NULL, " ");
+ packet=strtok(NULL, "");
+ }
+ else
+ {
+ rv->prefix=NULL;
+ rv->cmd=strtok(packet, " ");
+ packet=strtok(NULL, "");
+ }
+ if(!(rv->cmd&&packet))
+ {
+ rv->nargs=0;
+ return(rv);
+ }
+ int arg=0;
+ char *p;
+ bool trail=false;
+ while(*packet)
+ {
+ p=packet;
+ if((*p==':')||(arg=14))
+ {
+ p++;
+ rv->args[arg]=p;
+ rv->nargs=15;
+ break;
+ }
+ while(*p&&(*p!=' '))
+ {
+ p++;
+ }
+ rv->args[arg]=packet;
+ packet=p+(*p?1:0);
+ *p=0;
+ }
+ return(rv);
+}
+
void low_quote(char *from, char to[512])
{
int o=0;
View
11 irc.h
@@ -30,6 +30,15 @@ typedef enum
}
cmap;
+typedef struct
+{
+ char *prefix;
+ char *cmd;
+ int nargs;
+ char *args[15]; // RFC specifies maximum of 15 args
+}
+message;
+
#include "bits.h"
#include "buffer.h"
#include "colour.h"
@@ -44,6 +53,8 @@ int irc_conn_rest(int b, char *nick, char *username, char *fullname); // call th
int autoconnect(fd_set *master, int *fdmax, servlist *serv);
int irc_tx(int fd, char * packet);
int irc_rx(int fd, char ** data);
+
+message irc_breakdown(char *packet);
void low_quote(char *from, char to[512]);
char * low_dequote(char *buf);
View
11 quirc.c
@@ -136,16 +136,9 @@ int main(int argc, char *argv[])
}
else if(packet)
{
- char *pdata=strdup(packet);
- if(packet[0])
+ if(*packet)
{
- char *p=packet;
- if(*p==':')
- {
- p=strchr(p, ' ');
- }
- char *cmd=strtok(p, " ");
- if(*packet==':') *p=0;
+ message pkt=irc_breakdown(packet);
if(isdigit(*cmd))
{
irc_numeric(cmd, b);

0 comments on commit 61b2658

Please sign in to comment.