Various Bug Fixes including
* connects to the proper server from the config file
* feof (stream) loop is better than the prior solution
Still missing / correctable
* valgrind complains about uninitialized values
* strdup must be freed, but i don't know where...
committer: Markus Bröker <mbroeker@largo.homelinux.org>
--- a/include/irc.h
+++ b/include/irc.h
@@ -24,6 +24,6 @@
typedef struct Message MSG;
FILE *irc_connect (char *, unsigned int);
-int irc_login (FILE *, char *, char *);
+int irc_login (FILE *, char *, char *, char *);
char *irc_parsemessage (const char *, MSG *);
#endif
--- a/src/config.c
+++ b/src/config.c
@@ -37,9 +37,10 @@
/*
* We can easily provide default values ...
*/
- uc->nick = uc->pass = uc->server = uc->channel = uc->topic = 0;
+ uc->nick = uc->pass = uc->server = uc->channel = uc->topic = NULL;
uc->port = 6667;
+ *buffer = 0;
fgets (buffer, 512, f);
token = buffer;
--- a/src/irc.c
+++ b/src/irc.c
@@ -34,7 +34,7 @@
char *ip;
struct sockaddr_in ca;
int csocket;
- FILE *stream;
+ FILE *stream = NULL;
he = gethostbyname (server);
if (he == NULL) {
@@ -62,19 +62,23 @@
* rw mode,but many seek errors ...
*/
#ifdef NETBSD
- /* BEGIN OF STREAM */
+ /*
+ * BEGIN OF STREAM
+ */
stream = fdopen (csocket, "r+");
#else
- /* END OF STREAM */
+ /*
+ * END OF STREAM
+ */
stream = fdopen (csocket, "a+");
#endif
- csocket = fileno(stream);
+ csocket = fileno (stream);
printf ("Using filedescriptor %d for stream operations\n", csocket);
return stream;
}
-int irc_login (FILE * stream, char *nick, char *password)
+int irc_login (FILE * stream, char *server, char *nick, char *password)
{
MSG message;
char msg[513];
@@ -85,7 +89,7 @@
if ((pwd = getpwnam (user)) == NULL)
return IRC_GENERAL_ERROR;
- if (strlen (password) == 0)
+ if (password == NULL)
return IRC_LOGIN_ERROR;
if (stream == NULL)
@@ -93,7 +97,7 @@
fprintf (stream, "NICK %s\r\n", nick);
- fprintf (stream, "USER %s 0 irc.freenode.net %s\r\n", user, pwd->pw_gecos);
+ fprintf (stream, "USER %s 0 %s %s\r\n", user, server, pwd->pw_gecos);
fprintf (stream, "PRIVMSG NICKSERV :IDENTIFY %s\r\n", password);
--- a/src/main.c
+++ b/src/main.c
@@ -40,7 +40,7 @@
int main (int argc, char **argv)
{
UC uc;
- MSG message;
+ MSG message = { NULL, 0, 0, 0, 0, 0, 0 };
char buf[513];
char *msg;
char *command;
@@ -75,7 +75,7 @@
if (!(message.stream = irc_connect (uc.server, uc.port)))
return EXIT_FAILURE;
- if ((len = irc_login (message.stream, uc.nick, uc.pass)) != 0) {
+ if ((len = irc_login (message.stream, uc.server, uc.nick, uc.pass)) != 0) {
switch (len) {
case IRC_GENERAL_ERROR:
printf ("GENERAL ERROR\n");
@@ -97,11 +97,10 @@
fprintf (message.stream, "TOPIC %s :%s\r\n", uc.channel, uc.topic);
}
- while (active) {
- if (fgets (buf, 512, message.stream) == NULL) {
- active = 0;
- break;
- }
+ while (!feof (message.stream)) {
+ message.line = NULL;
+ *buf = 0;
+ fgets (buf, 512, message.stream);
if ((command = irc_parsemessage (buf, &message))) {
printf ("%10s %s %s\n", command, message.channel, message.line);
@@ -111,7 +110,6 @@
printf ("%10s %s", "WRITE", msg);
}
}
- *buf = 0;
}
printf ("\n\nClosing Connection\n\n");
fclose (message.stream);