Updating the status when connecting to the server
This commit is contained in:
parent
0585885433
commit
491086fcf0
|
@ -60,7 +60,7 @@ typedef struct _AccountPluginHelper
|
|||
{
|
||||
Account * account;
|
||||
int (*error)(Account * account, char const * message, int ret);
|
||||
void (*status)(Account * account, char const * message);
|
||||
void (*status)(Account * account, char const * format, ...);
|
||||
/* folders */
|
||||
Folder * (*folder_new)(Account * account, AccountFolder * folder,
|
||||
Folder * parent, FolderType type, char const * name);
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
@ -66,7 +67,7 @@ static gboolean _account_get_iter(Account * account, GtkTreeIter * iter);
|
|||
/* useful */
|
||||
static int _account_helper_error(Account * account, char const * message,
|
||||
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,
|
||||
AccountFolder * folder, Folder * parent, FolderType type,
|
||||
char const * name);
|
||||
|
@ -411,12 +412,27 @@ static int _account_helper_error(Account * account, char const * message,
|
|||
|
||||
|
||||
/* 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
|
||||
fprintf(stderr, "DEBUG: %s(\"%s\")\n", __func__, message);
|
||||
#endif
|
||||
/* FIXME implement */
|
||||
va_list ap;
|
||||
int res;
|
||||
size_t size;
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -721,7 +721,9 @@ static gboolean _on_idle(gpointer data)
|
|||
|
||||
static gboolean _idle_connect(AccountPlugin * plugin)
|
||||
{
|
||||
AccountPluginHelper * helper = plugin->helper;
|
||||
IMAP4 * imap4 = plugin->priv;
|
||||
char const * hostname;
|
||||
char const * p;
|
||||
struct hostent * he;
|
||||
unsigned short port;
|
||||
|
@ -731,11 +733,11 @@ static gboolean _idle_connect(AccountPlugin * plugin)
|
|||
fprintf(stderr, "DEBUG: %s()\n", __func__);
|
||||
#endif
|
||||
/* FIXME report errors */
|
||||
if((p = plugin->config[2].value) == NULL)
|
||||
if((hostname = plugin->config[2].value) == NULL)
|
||||
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;
|
||||
}
|
||||
if((p = plugin->config[3].value) == NULL)
|
||||
|
@ -743,19 +745,17 @@ static gboolean _idle_connect(AccountPlugin * plugin)
|
|||
port = (unsigned long)p;
|
||||
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;
|
||||
}
|
||||
sa.sin_family = AF_INET;
|
||||
sa.sin_port = htons(port);
|
||||
sa.sin_addr.s_addr = *((uint32_t*)he->h_addr_list[0]);
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "DEBUG: %s() connecting to %s:%u\n", __func__,
|
||||
helper->status(helper->account, "Connecting to %s (%s:%u)", hostname,
|
||||
inet_ntoa(sa.sin_addr), port);
|
||||
#endif
|
||||
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);
|
||||
imap4->fd = -1;
|
||||
return FALSE;
|
||||
|
|
|
@ -536,7 +536,9 @@ static gboolean _on_idle(gpointer data)
|
|||
|
||||
static gboolean _idle_connect(AccountPlugin * plugin)
|
||||
{
|
||||
AccountPluginHelper * helper = plugin->helper;
|
||||
POP3 * pop3 = plugin->priv;
|
||||
char const * hostname;
|
||||
char const * p;
|
||||
struct hostent * he;
|
||||
unsigned short port;
|
||||
|
@ -546,11 +548,11 @@ static gboolean _idle_connect(AccountPlugin * plugin)
|
|||
fprintf(stderr, "DEBUG: %s()\n", __func__);
|
||||
#endif
|
||||
/* FIXME report errors */
|
||||
if((p = plugin->config[2].value) == NULL)
|
||||
if((hostname = plugin->config[2].value) == NULL)
|
||||
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;
|
||||
}
|
||||
if((p = plugin->config[3].value) == NULL)
|
||||
|
@ -558,19 +560,17 @@ static gboolean _idle_connect(AccountPlugin * plugin)
|
|||
port = (unsigned long)p;
|
||||
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;
|
||||
}
|
||||
sa.sin_family = AF_INET;
|
||||
sa.sin_port = htons(port);
|
||||
sa.sin_addr.s_addr = *((uint32_t*)he->h_addr_list[0]);
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "DEBUG: %s() connecting to %s:%u\n", __func__,
|
||||
helper->status(helper->account, "Connecting to %s (%s:%u)", hostname,
|
||||
inet_ntoa(sa.sin_addr), port);
|
||||
#endif
|
||||
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);
|
||||
pop3->fd = -1;
|
||||
return FALSE;
|
||||
|
|
Loading…
Reference in New Issue
Block a user