/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2003 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2004 Hiroyuki Yamamoto
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
static gint nntp_ok (SockInfo *sock,
gchar *argbuf);
-static void nntp_gen_send (SockInfo *sock,
+static gint nntp_gen_send (SockInfo *sock,
const gchar *format,
...);
static gint nntp_gen_recv (SockInfo *sock,
session->group = NULL;
if (userid && passwd) {
+ gint ok;
+
session->userid = g_strdup(userid);
session->passwd = g_strdup(passwd);
+
+ ok = nntp_gen_send(sock, "AUTHINFO USER %s", session->userid);
+ if (ok != NN_SUCCESS) {
+ session_destroy(SESSION(session));
+ return NULL;
+ }
+ ok = nntp_ok(sock, NULL);
+ if (ok == NN_AUTHCONT) {
+ ok = nntp_gen_send(sock, "AUTHINFO PASS %s",
+ session->passwd);
+ if (ok != NN_SUCCESS) {
+ session_destroy(SESSION(session));
+ return NULL;
+ }
+ ok = nntp_ok(sock, NULL);
+ if (ok != NN_SUCCESS)
+ session->auth_failed = TRUE;
+ }
+ if (ok == NN_SOCKET) {
+ session_destroy(SESSION(session));
+ return NULL;
+ }
}
return SESSION(session);
ok = nntp_gen_command(session, buf, "GROUP %s", group);
- if (ok != NN_SUCCESS) {
+ if (ok != NN_SUCCESS && ok != NN_SOCKET && ok != NN_AUTHREQ) {
ok = nntp_mode(session, FALSE);
if (ok == NN_SUCCESS)
ok = nntp_gen_command(session, buf, "GROUP %s", group);
{
gint ok;
- if (session->auth_failed)
- return NN_AUTHREQ;
-
ok = nntp_gen_command(session, NULL, "MODE %s",
stream ? "STREAM" : "READER");
return ok;
}
-static void nntp_gen_send(SockInfo *sock, const gchar *format, ...)
+static gint nntp_gen_send(SockInfo *sock, const gchar *format, ...)
{
gchar buf[NNTPBUFSIZE];
va_list args;
}
strcat(buf, "\r\n");
- sock_write_all(sock, buf, strlen(buf));
+ if (sock_write_all(sock, buf, strlen(buf)) < 0) {
+ log_warning(_("Error occurred while sending command\n"));
+ return NN_SOCKET;
+ }
+
+ return NN_SUCCESS;
}
static gint nntp_gen_recv(SockInfo *sock, gchar *buf, gint size)
va_end(args);
sock = SESSION(session)->sock;
- nntp_gen_send(sock, "%s", buf);
+ ok = nntp_gen_send(sock, "%s", buf);
+ if (ok != NN_SUCCESS)
+ return ok;
ok = nntp_ok(sock, argbuf);
if (ok == NN_AUTHREQ) {
if (!session->userid || !session->passwd) {
return ok;
}
- nntp_gen_send(sock, "AUTHINFO USER %s", session->userid);
+ ok = nntp_gen_send(sock, "AUTHINFO USER %s", session->userid);
+ if (ok != NN_SUCCESS)
+ return ok;
ok = nntp_ok(sock, NULL);
if (ok == NN_AUTHCONT) {
- nntp_gen_send(sock, "AUTHINFO PASS %s",
- session->passwd);
+ ok = nntp_gen_send(sock, "AUTHINFO PASS %s",
+ session->passwd);
+ if (ok != NN_SUCCESS)
+ return ok;
ok = nntp_ok(sock, NULL);
}
if (ok != NN_SUCCESS) {
return ok;
}
- nntp_gen_send(sock, "%s", buf);
+ ok = nntp_gen_send(sock, "%s", buf);
+ if (ok != NN_SUCCESS)
+ return ok;
ok = nntp_ok(sock, argbuf);
} else if (ok == NN_AUTHCONT) {
- nntp_gen_send(sock, "AUTHINFO PASS %s", session->passwd);
- ok = nntp_ok(sock, NULL);
-
- if (ok != NN_SUCCESS) {
+ ok = nntp_gen_send(sock, "AUTHINFO PASS %s",
+ session->passwd);
+ if (ok != NN_SUCCESS) {
session->auth_failed = TRUE;
- return ok;
- }
- }
+ return ok;
+ }
+ ok = nntp_ok(sock, NULL);
+ }
return ok;
}