Updating the status when connecting to the server

This commit is contained in:
Pierre Pronchery 2011-06-06 00:20:36 +00:00
parent 0585885433
commit 491086fcf0
4 changed files with 39 additions and 23 deletions

View File

@ -60,7 +60,7 @@ typedef struct _AccountPluginHelper
{ {
Account * account; Account * account;
int (*error)(Account * account, char const * message, int ret); int (*error)(Account * account, char const * message, int ret);
void (*status)(Account * account, char const * message); void (*status)(Account * account, char const * format, ...);
/* folders */ /* folders */
Folder * (*folder_new)(Account * account, AccountFolder * folder, Folder * (*folder_new)(Account * account, AccountFolder * folder,
Folder * parent, FolderType type, char const * name); Folder * parent, FolderType type, char const * name);

View File

@ -15,6 +15,7 @@
#include <stdarg.h>
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
@ -66,7 +67,7 @@ static gboolean _account_get_iter(Account * account, GtkTreeIter * iter);
/* useful */ /* useful */
static int _account_helper_error(Account * account, char const * message, static int _account_helper_error(Account * account, char const * message,
int ret); int ret);
static void _account_helper_status(Account * account, char const * message); static void _account_helper_status(Account * account, char const * format, ...);
static Folder * _account_helper_folder_new(Account * account, static Folder * _account_helper_folder_new(Account * account,
AccountFolder * folder, Folder * parent, FolderType type, AccountFolder * folder, Folder * parent, FolderType type,
char const * name); char const * name);
@ -411,12 +412,27 @@ static int _account_helper_error(Account * account, char const * message,
/* account_helper_status */ /* account_helper_status */
static void _account_helper_status(Account * account, char const * message) static void _account_helper_status(Account * account, char const * format, ...)
{ {
#ifdef DEBUG va_list ap;
fprintf(stderr, "DEBUG: %s(\"%s\")\n", __func__, message); int res;
#endif size_t size;
/* FIXME implement */ char * p = NULL;
va_start(ap, format);
res = vsprintf(NULL, format, ap);
va_end(ap);
if(res >= 0)
{
va_start(ap, format);
size = res;
if((p = malloc(++size)) != NULL)
vsnprintf(p, size, format, ap);
va_end(ap);
}
if(p != NULL)
mailer_set_status(account->mailer, p);
free(p);
} }

View File

@ -721,7 +721,9 @@ static gboolean _on_idle(gpointer data)
static gboolean _idle_connect(AccountPlugin * plugin) static gboolean _idle_connect(AccountPlugin * plugin)
{ {
AccountPluginHelper * helper = plugin->helper;
IMAP4 * imap4 = plugin->priv; IMAP4 * imap4 = plugin->priv;
char const * hostname;
char const * p; char const * p;
struct hostent * he; struct hostent * he;
unsigned short port; unsigned short port;
@ -731,11 +733,11 @@ static gboolean _idle_connect(AccountPlugin * plugin)
fprintf(stderr, "DEBUG: %s()\n", __func__); fprintf(stderr, "DEBUG: %s()\n", __func__);
#endif #endif
/* FIXME report errors */ /* FIXME report errors */
if((p = plugin->config[2].value) == NULL) if((hostname = plugin->config[2].value) == NULL)
return FALSE; return FALSE;
if((he = gethostbyname(p)) == NULL) if((he = gethostbyname(hostname)) == NULL)
{ {
plugin->helper->error(NULL, hstrerror(h_errno), 1); helper->error(NULL, hstrerror(h_errno), 1);
return FALSE; return FALSE;
} }
if((p = plugin->config[3].value) == NULL) if((p = plugin->config[3].value) == NULL)
@ -743,19 +745,17 @@ static gboolean _idle_connect(AccountPlugin * plugin)
port = (unsigned long)p; port = (unsigned long)p;
if((imap4->fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) if((imap4->fd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
{ {
plugin->helper->error(NULL, strerror(errno), 1); helper->error(NULL, strerror(errno), 1);
return FALSE; return FALSE;
} }
sa.sin_family = AF_INET; sa.sin_family = AF_INET;
sa.sin_port = htons(port); sa.sin_port = htons(port);
sa.sin_addr.s_addr = *((uint32_t*)he->h_addr_list[0]); sa.sin_addr.s_addr = *((uint32_t*)he->h_addr_list[0]);
#ifdef DEBUG helper->status(helper->account, "Connecting to %s (%s:%u)", hostname,
fprintf(stderr, "DEBUG: %s() connecting to %s:%u\n", __func__,
inet_ntoa(sa.sin_addr), port); inet_ntoa(sa.sin_addr), port);
#endif
if(connect(imap4->fd, (struct sockaddr *)&sa, sizeof(sa)) != 0) if(connect(imap4->fd, (struct sockaddr *)&sa, sizeof(sa)) != 0)
{ {
plugin->helper->error(NULL, strerror(errno), 1); helper->error(NULL, strerror(errno), 1);
close(imap4->fd); close(imap4->fd);
imap4->fd = -1; imap4->fd = -1;
return FALSE; return FALSE;

View File

@ -536,7 +536,9 @@ static gboolean _on_idle(gpointer data)
static gboolean _idle_connect(AccountPlugin * plugin) static gboolean _idle_connect(AccountPlugin * plugin)
{ {
AccountPluginHelper * helper = plugin->helper;
POP3 * pop3 = plugin->priv; POP3 * pop3 = plugin->priv;
char const * hostname;
char const * p; char const * p;
struct hostent * he; struct hostent * he;
unsigned short port; unsigned short port;
@ -546,11 +548,11 @@ static gboolean _idle_connect(AccountPlugin * plugin)
fprintf(stderr, "DEBUG: %s()\n", __func__); fprintf(stderr, "DEBUG: %s()\n", __func__);
#endif #endif
/* FIXME report errors */ /* FIXME report errors */
if((p = plugin->config[2].value) == NULL) if((hostname = plugin->config[2].value) == NULL)
return FALSE; return FALSE;
if((he = gethostbyname(p)) == NULL) if((he = gethostbyname(hostname)) == NULL)
{ {
plugin->helper->error(NULL, hstrerror(h_errno), 1); helper->error(NULL, hstrerror(h_errno), 1);
return FALSE; return FALSE;
} }
if((p = plugin->config[3].value) == NULL) if((p = plugin->config[3].value) == NULL)
@ -558,19 +560,17 @@ static gboolean _idle_connect(AccountPlugin * plugin)
port = (unsigned long)p; port = (unsigned long)p;
if((pop3->fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) if((pop3->fd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
{ {
plugin->helper->error(NULL, strerror(errno), 1); helper->error(NULL, strerror(errno), 1);
return FALSE; return FALSE;
} }
sa.sin_family = AF_INET; sa.sin_family = AF_INET;
sa.sin_port = htons(port); sa.sin_port = htons(port);
sa.sin_addr.s_addr = *((uint32_t*)he->h_addr_list[0]); sa.sin_addr.s_addr = *((uint32_t*)he->h_addr_list[0]);
#ifdef DEBUG helper->status(helper->account, "Connecting to %s (%s:%u)", hostname,
fprintf(stderr, "DEBUG: %s() connecting to %s:%u\n", __func__,
inet_ntoa(sa.sin_addr), port); inet_ntoa(sa.sin_addr), port);
#endif
if(connect(pop3->fd, (struct sockaddr *)&sa, sizeof(sa)) != 0) if(connect(pop3->fd, (struct sockaddr *)&sa, sizeof(sa)) != 0)
{ {
plugin->helper->error(NULL, strerror(errno), 1); helper->error(NULL, strerror(errno), 1);
close(pop3->fd); close(pop3->fd);
pop3->fd = -1; pop3->fd = -1;
return FALSE; return FALSE;