/*
* 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;
}
/*
* 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
ok = news_select_group(session, item->path, NULL, NULL, NULL);
if (ok != NN_SUCCESS) {
- g_warning("can't select group %s\n", item->path);
+ if (ok == NN_SOCKET) {
+ session_destroy(SESSION(session));
+ REMOTE_FOLDER(folder)->session = NULL;
+ }
g_free(filename);
return NULL;
}
debug_print("getting article %d...\n", num);
ok = news_get_article(NNTP_SESSION(REMOTE_FOLDER(folder)->session),
num, filename);
- if (ok < 0) {
+ if (ok != NN_SUCCESS) {
g_warning("can't read article %d\n", num);
- session_destroy(SESSION(session));
- REMOTE_FOLDER(folder)->session = NULL;
+ if (ok == NN_SOCKET) {
+ session_destroy(SESSION(session));
+ REMOTE_FOLDER(folder)->session = NULL;
+ }
g_free(filename);
return NULL;
}
if ((fp = fopen(filename, "rb")) == NULL) {
NNTPSession *session;
+ gint ok;
session = news_session_get(folder);
if (!session) {
return NULL;
}
- if (nntp_list(session) != NN_SUCCESS) {
+ ok = nntp_list(session);
+ if (ok != NN_SUCCESS) {
+ if (ok == NN_SOCKET) {
+ session_destroy(SESSION(session));
+ REMOTE_FOLDER(folder)->session = NULL;
+ }
g_free(filename);
return NULL;
}
ok = nntp_post(session, fp);
if (ok != NN_SUCCESS) {
log_warning("can't post article.\n");
+ if (ok == NN_SOCKET) {
+ session_destroy(SESSION(session));
+ REMOTE_FOLDER(folder)->session = NULL;
+ }
return -1;
}
gint num, gchar *filename)
{
gchar *msgid;
+ gint ok;
- if (nntp_get_article(session, cmd, num, &msgid)
- != NN_SUCCESS)
- return -1;
+ ok = nntp_get_article(session, cmd, num, &msgid);
+ if (ok != NN_SUCCESS)
+ return ok;
debug_print("Message-Id = %s, num = %d\n", msgid, num);
g_free(msgid);
- if (recv_write_to_file(SESSION(session)->sock, filename) < 0) {
- log_warning("can't retrieve article %d\n", num);
- return -1;
+ ok = recv_write_to_file(SESSION(session)->sock, filename);
+ if (ok < 0) {
+ log_warning(_("can't retrieve article %d\n"), num);
+ if (ok == -2)
+ return NN_SOCKET;
+ else
+ return NN_IOERR;
}
- return 0;
+ return NN_SUCCESS;
}
static gint news_get_article(NNTPSession *session, gint num, gchar *filename)
ok = nntp_group(session, group, num, first, last);
if (ok == NN_SUCCESS)
session->group = g_strdup(group);
+ else
+ log_warning(_("can't select group: %s\n"), group);
return ok;
}
NNTPSession *session;
MsgInfo *msginfo = NULL;
gchar buf[NNTPBUFSIZE];
+ gint ok;
session = news_session_get(folder);
g_return_val_if_fail(session != NULL, NULL);
log_message(_("getting xover %d in %s...\n"),
num, item->path);
- if (nntp_xover(session, num, num) != NN_SUCCESS) {
+ ok = nntp_xover(session, num, num);
+ if (ok != NN_SUCCESS) {
log_warning(_("can't get xover\n"));
+ if (ok == NN_SOCKET) {
+ session_destroy(SESSION(session));
+ REMOTE_FOLDER(item->folder)->session = NULL;
+ }
return NULL;
}
msginfo->flags.tmp_flags = MSG_NEWS;
msginfo->newsgroups = g_strdup(item->path);
- if (nntp_xhdr(session, "to", num, num) != NN_SUCCESS) {
+ ok = nntp_xhdr(session, "to", num, num);
+ if (ok != NN_SUCCESS) {
log_warning(_("can't get xhdr\n"));
+ if (ok == NN_SOCKET) {
+ session_destroy(SESSION(session));
+ REMOTE_FOLDER(item->folder)->session = NULL;
+ }
return msginfo;
}
READ_TO_LISTEND("xhdr (to)");
- if (nntp_xhdr(session, "cc", num, num) != NN_SUCCESS) {
+ ok = nntp_xhdr(session, "cc", num, num);
+ if (ok != NN_SUCCESS) {
log_warning(_("can't get xhdr\n"));
+ if (ok == NN_SOCKET) {
+ session_destroy(SESSION(session));
+ REMOTE_FOLDER(item->folder)->session = NULL;
+ }
return msginfo;
}
GSList *llast = NULL;
MsgInfo *msginfo;
guint count = 0, lines = (end - begin + 2) * 3;
+ gint ok;
g_return_val_if_fail(session != NULL, NULL);
g_return_val_if_fail(item != NULL, NULL);
log_message(_("getting xover %d - %d in %s...\n"),
begin, end, item->path);
- if (nntp_xover(session, begin, end) != NN_SUCCESS) {
+ ok = nntp_xover(session, begin, end);
+ if (ok != NN_SUCCESS) {
log_warning(_("can't get xover\n"));
+ if (ok == NN_SOCKET) {
+ session_destroy(SESSION(session));
+ REMOTE_FOLDER(item->folder)->session = NULL;
+ }
return NULL;
}
}
}
- if (nntp_xhdr(session, "to", begin, end) != NN_SUCCESS) {
+ ok = nntp_xhdr(session, "to", begin, end);
+ if (ok != NN_SUCCESS) {
log_warning(_("can't get xhdr\n"));
+ if (ok == NN_SOCKET) {
+ session_destroy(SESSION(session));
+ REMOTE_FOLDER(item->folder)->session = NULL;
+ }
return newlist;
}
llast = llast->next;
}
- if (nntp_xhdr(session, "cc", begin, end) != NN_SUCCESS) {
+ ok = nntp_xhdr(session, "cc", begin, end);
+ if (ok != NN_SUCCESS) {
log_warning(_("can't get xhdr\n"));
+ if (ok == NN_SOCKET) {
+ session_destroy(SESSION(session));
+ REMOTE_FOLDER(item->folder)->session = NULL;
+ }
return newlist;
}