src/irc.c
changeset 10 311ea5fa60dd
parent 9 aff6726b8b87
child 11 a769385a59c6
--- a/src/irc.c
+++ b/src/irc.c
@@ -25,7 +25,6 @@
     "NOTICE", "MODE", "JOIN", "PART",
     "TOPIC", "PING", "ENOMEM", "ERROR",
     "VERSION", "PRIVMSG", "QUIT", "NICK",
-    NULL,
 };
 
 FILE *irc_connect (char *server, unsigned int port)
@@ -34,7 +33,7 @@
     char *ip;
     struct sockaddr_in ca;
     int csocket;
-    FILE *stream = NULL;
+    FILE *stream;
 
     he = gethostbyname (server);
     if (he == NULL) {
@@ -43,7 +42,7 @@
     }
 
     if ((ip = inet_ntoa (*((struct in_addr *)he->h_addr_list[0]))) == NULL) {
-        perror ("GETHOSTBYNAME");
+        perror ("INET_NTOA");
         return NULL;
     } else
         printf ("IP: %s\n", ip);
@@ -80,26 +79,31 @@
 
 int irc_login (FILE * stream, char *server, char *nick, char *password)
 {
-    MSG message;
+    MSG message = { NULL, 0, 0, 0, 0, 0, 0 };
     char msg[513];
     char *user;
-    struct passwd *pwd = NULL;
+    struct passwd *pwd;
 
-    if ((user = getenv ("USER")) != NULL)
-        if ((pwd = getpwnam (user)) == NULL)
-            return IRC_GENERAL_ERROR;
+    if ((user = getenv ("USER")) == NULL)
+        return IRC_GENERAL_ERROR;
+
+    if ((pwd = getpwnam (user)) == NULL)
+        return IRC_GENERAL_ERROR;
 
     if (password == NULL)
         return IRC_LOGIN_ERROR;
 
     if (stream == NULL)
         return IRC_GENERAL_ERROR;
+    else
+        message.stream = stream;
 
     fprintf (stream, "NICK %s\r\n", nick);
     fprintf (stream, "USER %s 0 %s %s\r\n", user, server, pwd->pw_gecos);
     fprintf (stream, "PRIVMSG NICKSERV :IDENTIFY %s\r\n", password);
 
     for (;;) {
+        *msg = 0;
         fgets (msg, 512, stream);
         if ((user = irc_parsemessage (msg, &message)) != NULL)
             printf ("%10s %s\n", user, message.line);
@@ -283,6 +287,7 @@
                 fprintf (message->stream, "PRIVMSG %s :%s\r\n", message->current_channel, message->line);
                 return command;
             case 320:
+            case 328:          /* INFORMATION */
             case 332:          /* TOPIC OF CHANNEL */
             case 333:          /* NAMES IN CHANNEL */
                 message->channel = strtok (message->line, " ");
@@ -311,8 +316,8 @@
                 return command;
                 break;
             case 401:          /* NO SUCH NICK/CHANNEL */
-            case 403:          /* That CHANNEL doesnt exist */
-            case 441:          /* They aren't on this channel */
+            case 403:          /* THAT CHANNEL DOESN'T EXIST */
+            case 441:          /* THEY AREN'T ON THIS CHANNEL */
                 return command;
             case 474:
             case 475: