Hi,
To give you a little background on my project, I'm building an IRC/MySQL gateway daemon. The piece I'm working on is receiving text from the irc client, and parsing it correctly.
I am using a select to handle all the socket communication. Once data is put into the input buffer of my struct, I call my getircmsg() function.
Here is the code I'm having issues with:
It doesn't always fill in cmd. Sometimes the command is put in the dest var. Any ideas why this might be?
If needed, I can tar the whole project, and share it.
Thanks!
-YungBlood
To give you a little background on my project, I'm building an IRC/MySQL gateway daemon. The piece I'm working on is receiving text from the irc client, and parsing it correctly.
I am using a select to handle all the socket communication. Once data is put into the input buffer of my struct, I call my getircmsg() function.
Here is the code I'm having issues with:
Code:
int getircmsg(struct client *client) {
/* Strip char 13 out, and check for char 10 */
if (!gotline(client)) return 0;
char cmd[64] = "";
char from[256] = "";
char dest[64] = "";
char line[1024] = "";
int pos=0, x=0;
/*
* Input can be in one of the following 2 formats:
* :nick!email@domail.com COMMAND Destination :Message
* or
* COMMAND Destination :Message
*/
if (client->inbuf[0] == ':')
while((client->inbuf[pos]!=10)&&(client->inbuf[pos]!=32))
from[x++]=client->inbuf[pos++];
from[x]=0;
while(client->inbuf[pos]==32) pos++;
x=0;
while((client->inbuf[pos]!=10)&&(client->inbuf[pos]!=32))
cmd[x++]=client->inbuf[pos++];
cmd[x]=0;
while(client->inbuf[pos]==32) pos++;
x=0;
while((client->inbuf[pos]!=10)&&(client->inbuf[pos]!=32))
dest[x++]=client->inbuf[pos++];
dest[x]=0;
while(client->inbuf[pos]==32) pos++;
x=0;
while(client->inbuf[pos]!=10)
line[x++]=client->inbuf[pos++];
line[x]=0;
x=0;
pos++;
while(pos<=client->incur)
client->inbuf[x++]=client->inbuf[pos++];
client->incur=x;
logmsg("From: %s", from);
logmsg("Cmd: %s", cmd);
logmsg("Dest: %s", dest);
logmsg("Line: %s", line);
}
It doesn't always fill in cmd. Sometimes the command is put in the dest var. Any ideas why this might be?
If needed, I can tar the whole project, and share it.
Thanks!
-YungBlood