Commit 0fd294c0 0fd294c05edfabd567056c78d8a191d4d117c5c8 by Sergey Poznyakoff

use mu_url_sget or mu_url_aget accessors

1 parent cf831892
......@@ -160,30 +160,24 @@ authenticate_imap_login (mu_authority_t auth)
case IMAP_AUTH:
{
/* Grab the User and Passwd information. */
size_t n = 0;
mu_authority_get_ticket (auth, &ticket);
if (f_imap->user)
free (f_imap->user);
if (f_imap->passwd)
free (f_imap->passwd);
/* Was it in the URL? */
status = mu_url_get_user (folder->url, NULL, 0, &n);
if (status != 0 || n == 0)
status = mu_url_aget_user (folder->url, &f_imap->user);
if (status == MU_ERR_NOENT)
mu_ticket_pop (ticket, folder->url, "Imap User: ", &f_imap->user);
else
{
f_imap->user = calloc (1, n + 1);
mu_url_get_user (folder->url, f_imap->user, n + 1, NULL);
}
/* Was it in the URL? */
status = mu_url_get_passwd (folder->url, NULL, 0, &n);
if (status != 0 || n == 0)
mu_ticket_pop (ticket, folder->url, "Imap Passwd: ", &f_imap->passwd);
else
{
f_imap->passwd = calloc (1, n + 1);
mu_url_get_passwd (folder->url, f_imap->passwd, n + 1, NULL);
}
else if (status)
return status;
status = mu_url_aget_passwd (folder->url, &f_imap->passwd);
if (status == MU_ERR_NOENT)
mu_ticket_pop (ticket, folder->url, "Imap Passwd: ",
&f_imap->passwd);
else if (status)
return status;
if (f_imap->user == NULL)
return MU_ERR_NOUSERNAME;
......@@ -582,7 +576,7 @@ static int
folder_imap_open (mu_folder_t folder, int flags)
{
f_imap_t f_imap = folder->data;
char *host;
const char *host;
long port = 143; /* default imap port. */
int status = 0;
size_t len = 0;
......@@ -597,11 +591,9 @@ folder_imap_open (mu_folder_t folder, int flags)
mu_monitor_unlock (folder->monitor);
/* Fetch the server name and the port in the mu_url_t. */
status = mu_url_get_host (folder->url, NULL, 0, &len);
status = mu_url_sget_host (folder->url, &host);
if (status != 0)
return status;
host = alloca (len + 1);
mu_url_get_host (folder->url, host, len + 1, NULL);
mu_url_get_port (folder->url, &port);
folder->flags = flags;
......
......@@ -125,8 +125,8 @@ static int is_same_folder (mu_mailbox_t, mu_message_t);
int
_mailbox_imap_init (mu_mailbox_t mailbox)
{
int status;
m_imap_t m_imap;
size_t name_len = 0;
mu_folder_t folder = NULL;
assert(mailbox);
......@@ -138,18 +138,15 @@ _mailbox_imap_init (mu_mailbox_t mailbox)
return ENOMEM;
/* Retrieve the name of the mailbox from the URL. */
mu_url_get_path (mailbox->url, NULL, 0, &name_len);
if (name_len == 0)
{
/* name "INBOX" is the default. */
m_imap->name = calloc (6, sizeof (char));
strcpy (m_imap->name, "INBOX");
}
else
status = mu_url_aget_path (mailbox->url, &m_imap->name);
if (status == MU_ERR_NOENT)
{
m_imap->name = calloc (name_len + 1, sizeof (char));
mu_url_get_path (mailbox->url, m_imap->name, name_len + 1, NULL);
m_imap->name = strdup ("INBOX");
if (!m_imap->name)
return ENOMEM;
}
else if (status)
return status;
/* Overload the functions. */
mailbox->_destroy = mailbox_imap_destroy;
......@@ -298,21 +295,18 @@ mailbox_imap_open (mu_mailbox_t mailbox, int flags)
{
case IMAP_NO_STATE:
{
char *path;
const char *path;
size_t len;
mu_url_get_path (folder->url, NULL, 0, &len);
if (len == 0)
status = mu_url_sget_path (folder->url, &path);
if (status == MU_ERR_NOENT)
return 0;
path = calloc (len + 1, sizeof (*path));
if (path == NULL)
return ENOMEM;
mu_url_get_path (folder->url, path, len + 1, NULL);
else if (status)
return status;
status = imap_writeline (f_imap, "g%u CREATE %s\r\n",
f_imap->seq, path);
MAILBOX_DEBUG2 (folder, MU_DEBUG_PROT, "g%u CREATE %s\n",
f_imap->seq, path);
f_imap->seq++;
free (path);
if (status != 0)
{
m_imap->state = f_imap->state = IMAP_NO_STATE;
......@@ -980,7 +974,7 @@ imap_append_message0 (mu_mailbox_t mailbox, mu_message_t msg)
case IMAP_NO_STATE:
{
size_t lines, size;
char *path;
const char *path;
char *abuf = malloc (1);
/* Get the desired flags attribute. */
if (abuf == NULL)
......@@ -1009,28 +1003,9 @@ imap_append_message0 (mu_mailbox_t mailbox, mu_message_t msg)
}
/* Get the mailbox filepath. */
{
size_t n = 0;
mu_url_get_path (mailbox->url, NULL, 0, &n);
if (n == 0)
{
if (!(path = strdup ("INBOX")))
{
free (abuf);
return ENOMEM;
}
}
else
{
path = calloc (n + 1, sizeof (*path));
if (path == NULL)
{
free (abuf);
return ENOMEM;
}
mu_url_get_path (mailbox->url, path, n + 1, NULL);
}
}
status = mu_url_sget_path (mailbox->url, &path);
if (status == MU_ERR_NOENT)
path = "INBOX";
/* FIXME: we need to get the mu_envelope_date and use it.
currently it is ignored. */
......@@ -1046,7 +1021,6 @@ imap_append_message0 (mu_mailbox_t mailbox, mu_message_t msg)
abuf,
mu_umaxtostr (1, size + lines));
free (abuf);
free (path);
CHECK_ERROR (f_imap, status);
MAILBOX_DEBUG0 (mailbox, MU_DEBUG_PROT, f_imap->buffer);
f_imap->state = IMAP_APPEND;
......@@ -1132,21 +1106,14 @@ imap_copy_message (mu_mailbox_t mailbox, mu_message_t msg)
{
case IMAP_NO_STATE:
{
char *path;
size_t n = 0;
const char *path;
/* Check for a valid mailbox name. */
mu_url_get_path (mailbox->url, NULL, 0, &n);
if (n == 0)
return EINVAL;
path = calloc (n + 1, sizeof (*path));
if (path == NULL)
return ENOMEM;
mu_url_get_path (mailbox->url, path, n + 1, NULL);
status = mu_url_sget_path (mailbox->url, &path);
if (status == 0)
status = imap_writeline (f_imap, "g%s COPY %s %s\r\n",
mu_umaxtostr (0, f_imap->seq++),
mu_umaxtostr (1, msg_imap->num),
path);
free (path);
CHECK_ERROR (f_imap, status);
MAILBOX_DEBUG0 (mailbox, MU_DEBUG_PROT, f_imap->buffer);
f_imap->state = IMAP_COPY;
......
......@@ -152,15 +152,13 @@ _folder_mbox_init (mu_folder_t folder)
if (dfolder == NULL)
return ENOMEM;
mu_url_get_path (folder->url, NULL, 0, &name_len);
dfolder->dirname = calloc (name_len + 1, sizeof (char));
if (dfolder->dirname == NULL)
status = mu_url_aget_path (folder->url, &dfolder->dirname);
if (status)
{
free (dfolder);
folder->data = NULL;
return ENOMEM;
}
mu_url_get_path (folder->url, dfolder->dirname, name_len + 1, NULL);
folder->_destroy = folder_mbox_destroy;
......
......@@ -76,8 +76,8 @@ static int mbox_tmpfile (mu_mailbox_t, char **pbox);
int
_mailbox_mbox_init (mu_mailbox_t mailbox)
{
int status;
mbox_data_t mud;
size_t name_len;
if (mailbox == NULL)
return EINVAL;
......@@ -98,15 +98,13 @@ _mailbox_mbox_init (mu_mailbox_t mailbox)
will be "///var/mail/alain", we let open() do the right thing.
So it will let things like this "mbox://390/var/mail/alain" where
the "//" _is_ part of the filename, pass correctely. */
mu_url_get_path (mailbox->url, NULL, 0, &name_len);
mud->name = calloc (name_len + 1, sizeof (char));
if (mud->name == NULL)
status = mu_url_aget_path (mailbox->url, &mud->name);
if (status)
{
free (mud);
mailbox->data = NULL;
return ENOMEM;
return status;
}
mu_url_get_path (mailbox->url, mud->name, name_len + 1, NULL);
mud->state = MBOX_NO_STATE;
......
......@@ -100,10 +100,9 @@ nntp_folder_open (mu_folder_t folder, int flags)
{
f_nntp_t f_nntp = folder->data;
mu_stream_t carrier = NULL;
char *host;
const char *host;
long port = MU_NNTP_DEFAULT_PORT; /* default nntp port. */
int status = 0;
size_t len = 0;
/* If we are already open for business, noop. */
mu_monitor_wrlock (folder->monitor);
......@@ -115,25 +114,21 @@ nntp_folder_open (mu_folder_t folder, int flags)
mu_monitor_unlock (folder->monitor);
/* Fetch the server name and the port in the mu_url_t. */
status = mu_url_get_host (folder->url, NULL, 0, &len);
status = mu_url_sget_host (folder->url, &host);
if (status != 0)
return status;
host = malloc (len + 1);
if (!host)
return ENOMEM;
mu_url_get_host (folder->url, host, len + 1, NULL);
mu_url_get_port (folder->url, &port);
folder->flags = flags;
/* Create the networking stack. */
status = mu_tcp_stream_create (&carrier, host, port, folder->flags);
free (host);
if (status != 0)
return status;
/* Ask for the stream internal buffering mechanism scheme. */
mu_stream_setbufsiz (carrier, BUFSIZ);
FOLDER_DEBUG2 (folder, MU_DEBUG_PROT, "folder_nntp_open (%s:%d)\n", host, port);
FOLDER_DEBUG2 (folder, MU_DEBUG_PROT, "folder_nntp_open (%s:%d)\n",
host, port);
status = mu_nntp_create (&f_nntp->nntp);
if (status == 0)
......
......@@ -92,7 +92,6 @@ _nntp_mailbox_init (mu_mailbox_t mbox)
{
m_nntp_t m_nntp;
int status = 0;
size_t name_len = 0;
/* Allocate specifics for nntp data. */
m_nntp = mbox->data = calloc (1, sizeof (*m_nntp));
......@@ -106,19 +105,19 @@ _nntp_mailbox_init (mu_mailbox_t mbox)
m_nntp->mailbox = mbox; /* Back pointer. */
/* Retrieve the name of the newsgroup from the URL. */
mu_url_get_path (mbox->url, NULL, 0, &name_len);
if (name_len == 0)
status = mu_url_aget_path (mbox->url, &m_nntp->name);
if (status == MU_ERR_NOENT)
{
/* name "INBOX" is the default. */
m_nntp->name = calloc (6, sizeof (char));
strcpy (m_nntp->name, "INBOX");
m_nntp->name = strdup ("INBOX");
if (!m_nntp->name)
return ENOMEM;
}
else if (status)
return status;
else
{
char *p;
m_nntp->name = calloc (name_len + 1, sizeof (char));
mu_url_get_path (mbox->url, m_nntp->name, name_len + 1, NULL);
p = strchr (m_nntp->name,'/');
p = strchr (m_nntp->name, '/');
if (p)
*p = '\0';
}
......
......@@ -680,8 +680,7 @@ pop_open (mu_mailbox_t mbox, int flags)
{
pop_data_t mpd = mbox->data;
int status;
char *host;
size_t hostlen = 0;
const char *host;
long port = MU_POP_PORT;
/* Sanity checks. */
......@@ -689,11 +688,9 @@ pop_open (mu_mailbox_t mbox, int flags)
return EINVAL;
/* Fetch the pop server name and the port in the mu_url_t. */
status = mu_url_get_host (mbox->url, NULL, 0, &hostlen);
status = mu_url_sget_host (mbox->url, &host);
if (status != 0)
return status;
host = alloca (hostlen + 1);
mu_url_get_host (mbox->url, host, hostlen + 1, NULL);
mu_url_get_port (mbox->url, &port);
mbox->flags = flags;
......@@ -2044,7 +2041,6 @@ pop_get_user (mu_authority_t auth)
mu_ticket_t ticket = NULL;
int status;
/* Fetch the user from them. */
size_t n = 0;
mu_authority_get_ticket (auth, &ticket);
if (mpd->user)
......@@ -2053,14 +2049,11 @@ pop_get_user (mu_authority_t auth)
mpd->user = NULL;
}
/* Was it in the URL? */
status = mu_url_get_user (mbox->url, NULL, 0, &n);
if (status != 0 || n == 0)
status = mu_url_aget_user (mbox->url, &mpd->user);
if (status == MU_ERR_NOENT)
mu_ticket_pop (ticket, mbox->url, "Pop User: ", &mpd->user);
else
{
mpd->user = calloc (1, n + 1);
mu_url_get_user (mbox->url, mpd->user, n + 1, NULL);
}
else if (status)
return status;
return 0;
}
......@@ -2073,8 +2066,6 @@ pop_get_passwd (mu_authority_t auth)
pop_data_t mpd = mbox->data;
mu_ticket_t ticket = NULL;
int status;
/* Fetch the user from them. */
size_t n = 0;
mu_authority_get_ticket (auth, &ticket);
if (mpd->passwd)
......@@ -2083,14 +2074,11 @@ pop_get_passwd (mu_authority_t auth)
mpd->passwd = NULL;
}
/* Was it in the URL? */
status = mu_url_get_passwd (mbox->url, NULL, 0, &n);
if (status != 0 || n == 0)
status = mu_url_aget_passwd (mbox->url, &mpd->passwd);
if (status == MU_ERR_NOENT)
mu_ticket_pop (ticket, mbox->url, "Pop Passwd: ", &mpd->passwd);
else
{
mpd->passwd = calloc (1, n + 1);
mu_url_get_passwd (mbox->url, mpd->passwd, n + 1, NULL);
}
else if (status)
return status;
return 0;
}
......
......@@ -242,10 +242,11 @@ amd_array_shrink (struct _amd_data *amd, size_t index)
int
amd_init_mailbox (mu_mailbox_t mailbox, size_t amd_size, struct _amd_data **pamd)
amd_init_mailbox (mu_mailbox_t mailbox, size_t amd_size,
struct _amd_data **pamd)
{
int status;
struct _amd_data *amd;
size_t name_len;
if (mailbox == NULL)
return MU_ERR_MBX_NULL;
......@@ -259,15 +260,13 @@ amd_init_mailbox (mu_mailbox_t mailbox, size_t amd_size, struct _amd_data **pamd
/* Back pointer. */
amd->mailbox = mailbox;
mu_url_get_path (mailbox->url, NULL, 0, &name_len);
amd->name = calloc (name_len + 1, sizeof (char));
if (amd->name == NULL)
status = mu_url_aget_path (mailbox->url, &amd->name);
if (status)
{
free (amd);
mailbox->data = NULL;
return ENOMEM;
return status;
}
mu_url_get_path (mailbox->url, amd->name, name_len + 1, NULL);
/* Overloading the defaults. */
mailbox->_destroy = amd_destroy;
......
......@@ -125,7 +125,6 @@ sendmail_open (mu_mailer_t mailer, int flags)
{
sendmail_t sendmail = mailer->data;
int status;
size_t pathlen = 0;
char *path;
/* Sanity checks. */
......@@ -134,13 +133,9 @@ sendmail_open (mu_mailer_t mailer, int flags)
mailer->flags = flags;
if ((status = mu_url_get_path (mailer->url, NULL, 0, &pathlen)) != 0
|| pathlen == 0)
if ((status = mu_url_aget_path (mailer->url, &path)))
return status;
path = calloc (pathlen + 1, sizeof (char));
mu_url_get_path (mailer->url, path, pathlen + 1, NULL);
if (access (path, X_OK) == -1)
{
free (path);
......
......@@ -297,7 +297,6 @@ smtp_open (mu_mailer_t mailer, int flags)
smtp_t smtp = mailer->data;
int status;
long port;
size_t buf_len = 0;
/* Sanity checks. */
if (!smtp)
......@@ -305,27 +304,21 @@ smtp_open (mu_mailer_t mailer, int flags)
mailer->flags = flags;
/* Fetch the mailer server name and the port in the mu_url_t. */
if ((status = mu_url_get_host (mailer->url, NULL, 0, &buf_len)) != 0
|| buf_len == 0 || (status = mu_url_get_port (mailer->url, &port)) != 0)
if ((status = mu_url_get_port (mailer->url, &port)) != 0)
return status;
switch (smtp->state)
{
case SMTP_NO_STATE:
/* Set up the mailer, open the stream, etc. */
/* Get the mailhost. */
if (smtp->mailhost)
{
free (smtp->mailhost);
smtp->mailhost = NULL;
}
smtp->mailhost = calloc (buf_len + 1, sizeof (char));
if (smtp->mailhost == NULL)
return ENOMEM;
mu_url_get_host (mailer->url, smtp->mailhost, buf_len + 1, NULL);
/* Fetch the mailer server name and the port in the mu_url_t. */
if ((status = mu_url_aget_host (mailer->url, &smtp->mailhost)) != 0)
return status;
if (smtp->localhost)
{
......
......@@ -378,35 +378,27 @@ static int
get_user (mu_url_t url, const char *filename, char **user)
{
char *u = 0;
int status;
if (url)
{
size_t n = 0;
mu_url_get_user (url, NULL, 0, &n);
if (n)
{
u = calloc (1, n + 1);
mu_url_get_user (url, u, n + 1, NULL);
}
status = mu_url_aget_user (url, &u);
if (status && status != MU_ERR_NOENT)
return status;
}
if (!u && filename)
{
mu_url_t ticket = 0;
int e = get_ticket (url, NULL, filename, &ticket);
if (e)
return e;
status = get_ticket (url, NULL, filename, &ticket);
if (status)
return status;
if (ticket)
{
size_t n = 0;
mu_url_get_user (ticket, NULL, 0, &n);
if (n)
{
u = calloc (1, n + 1);
mu_url_get_user (ticket, u, n + 1, NULL);
}
status = mu_url_aget_user (ticket, &u);
if (status && status != MU_ERR_NOENT)
return status;
mu_url_destroy (&ticket);
}
}
......@@ -428,36 +420,28 @@ get_user (mu_url_t url, const char *filename, char **user)
static int
get_pass (mu_url_t url, const char *user, const char *filename, char **pass)
{
int status;
char *u = 0;
if (url)
{
size_t n = 0;
mu_url_get_passwd (url, NULL, 0, &n);
if (n)
{
u = calloc (1, n + 1);
mu_url_get_passwd (url, u, n + 1, NULL);
}
status = mu_url_aget_passwd (url, &u);
if (status && status != MU_ERR_NOENT)
return status;
}
if (!u && filename)
{
mu_url_t ticket = 0;
int e = get_ticket (url, user, filename, &ticket);
if (e)
return e;
status = get_ticket (url, user, filename, &ticket);
if (status)
return status;
if (ticket)
{
size_t n = 0;
mu_url_get_passwd (ticket, NULL, 0, &n);
if (n)
{
u = calloc (1, n + 1);
mu_url_get_passwd (ticket, u, n + 1, NULL);
}
status = mu_url_aget_passwd (ticket, &u);
if (status && status != MU_ERR_NOENT)
return status;
mu_url_destroy (&ticket);
}
}
......