Commit d8d1ab2f d8d1ab2f11e4a14506f054f2afc48ad0808c6a5a by Alain Magloire

Makefile.am _cpystr.c chewurl.c cpystr.h url.c url_mbox.c

 	url_pop.c
thighning up things.
1 parent 06e9cb84
......@@ -4,12 +4,13 @@ AUTOMAKE_OPTIONS = ../lib/ansi2knr
CFLAGS = -Wall -pedantic -g
include_HEADERS = url.h url_mbox.h url_pop.h url_imap.h url_mailto.h
include_HEADERS = url.h url_mbox.h url_unix.h url_mdir.h url_mmdf.h url_pop.h \
url_imap.h url_mail.h
noinst_HEADERS = cpystr.h
base_sources = _cpystr.c url.c urli.c url_imap.c url_mailto.c \
url_mbox.c url_pop.c
base_sources = _cpystr.c url.c urli.c url_mbox.c url_unix.c url_mdir.c \
url_mmdf.c url_pop.c url_imap.c url_mail.c
chewurl_SOURCES = $(base_sources) chewurl.c
......
......@@ -19,7 +19,7 @@
#include <string.h>
int
_cpystr (const char *src, char *dst, unsigned int size)
_cpystr (char *dst, const char *src, unsigned int size)
{
unsigned int len = src ? strlen (src) : 0 ;
......
#include <url.h>
#include <url_pop.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int
main (int argc, char ** argv)
main ()
{
int status, i;
long port;
......
......@@ -15,8 +15,8 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifndef _URL0_H
#define _URL0_H
#ifndef _CPYSTR_H
#define _CPYSTR_H
#ifndef __P
# ifdef __STDC__
......@@ -25,6 +25,6 @@
# define __P(x)
# endif
#endif
extern int _cpystr __P ((const char *src, char *dst, unsigned int size));
extern int _cpystr __P ((char *dst, const char *src, unsigned int size));
#endif
......
......@@ -16,9 +16,12 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include <url_mbox.h>
#include <url_unix.h>
#include <url_mdir.h>
#include <url_mmdf.h>
#include <url_pop.h>
#include <url_imap.h>
#include <url_mailto.h>
#include <url_mail.h>
#include <cpystr.h>
#include <string.h>
......@@ -44,11 +47,14 @@ static struct url_builtin
int is_malloc;
struct url_builtin * next;
} url_builtin [] = {
{ NULL, 0, &url_builtin[1] }, /* Sentinel, head list */
{ &_url_mbox_type, 0, &url_builtin[2] },
{ &_url_pop_type, 0, &url_builtin[3] },
{ &_url_imap_type, 0, &url_builtin[4] },
{ &_url_mailto_type, 0, &url_builtin[0] },
{ NULL, 0, &url_builtin[1] }, /* Sentinel, head list */
{ &_url_mbox_type, 0, &url_builtin[2] },
{ &_url_unix_type, 0, &url_builtin[3] },
{ &_url_maildir_type, 0, &url_builtin[4] },
{ &_url_mmdf_type, 0, &url_builtin[5] },
{ &_url_pop_type, 0, &url_builtin[6] },
{ &_url_imap_type, 0, &url_builtin[7] },
{ &_url_mailto_type, 0, &url_builtin[0] },
};
/*
......@@ -108,7 +114,8 @@ url_list_mtype (struct url_type **mlist, int *n)
struct url_type *utype;
int i;
if ((i = url_list_type (NULL, 0)) <= 0 || (utype = malloc (i)) == NULL)
if ((i = url_list_type (NULL, 0)) <= 0
|| (utype = calloc (i, sizeof (*utype))) == NULL)
{
return -1;
}
......@@ -188,13 +195,13 @@ url_destroy (url_t *purl)
static int
get_scheme (const url_t u, char * s, int n)
{
return _cpystr (u->scheme, s, n);
return _cpystr (s, u->scheme, n);
}
static int
get_user (const url_t u, char * s, int n)
{
return _cpystr (u->user, s, n);
return _cpystr (s, u->user, n);
}
/* FIXME: We should not store passwd in clear, but rather
......@@ -202,13 +209,13 @@ get_user (const url_t u, char * s, int n)
static int
get_passwd (const url_t u, char * s, int n)
{
return _cpystr (u->passwd, s, n);
return _cpystr (s, u->passwd, n);
}
static int
get_host (const url_t u, char * s, int n)
{
return _cpystr (u->host, s, n);
return _cpystr (s, u->host, n);
}
static int
......@@ -221,13 +228,13 @@ get_port (const url_t u, long * p)
static int
get_path (const url_t u, char * s, int n)
{
return _cpystr(u->path, s, n);
return _cpystr(s, u->path, n);
}
static int
get_query (const url_t u, char * s, int n)
{
return _cpystr(u->query, s, n);
return _cpystr(s, u->query, n);
}
static int
......
......@@ -51,10 +51,11 @@ url_mbox_init (url_t *purl, const char *name)
{
url_t url;
int len;
struct url_type *utype = &_url_mbox_type;
/* reject the obvious */
if (name == NULL || strncmp ("file://", name, 7) != 0
|| (len = strlen (name)) < 8 /* 7(scheme)+1(path)*/)
if (name == NULL || strncmp (utype->scheme, name, utype->len) != 0
|| (len = strlen (name)) < utype->len + 1 /* 7(scheme)+1(path)*/)
{
return -1;
}
......@@ -72,24 +73,24 @@ url_mbox_init (url_t *purl, const char *name)
/* SCHEME */
/* strdup ("file://") the hard way */
url->scheme = malloc (7 + 1);
url->scheme = malloc (utype->len + 1);
if (url->scheme == NULL)
{
url_mbox_destroy (&url);
utype->_destroy (&url);
return -1;
}
memcpy (url->scheme, "file://", 8);
memcpy (url->scheme, utype->scheme, utype->len + 1 /* including the NULL */);
/* PATH */
name += 7; /* pass the scheme */
len -= 7;
name += utype->len; /* pass the scheme */
len -= utype->len; /* decremente the len */
url->path = malloc (len + 1);
if (url->path == NULL)
{
url_mbox_destroy (&url);
utype->_destroy (&url);
return -1;
}
memcpy (url->path, name, len + 1);
memcpy (url->path, name, len + 1 /* including the NULL */);
*purl = url;
return 0;
......
......@@ -33,7 +33,7 @@ static int get_auth (const url_pop_t up, char *s, int n);
static int
get_auth (const url_pop_t up, char * s, int n)
{
return _cpystr (up->auth, s, n);
return _cpystr (s, up->auth, n);
}
int
......