Commit 382f6f4c 382f6f4cf6c5cd26f0891626c7edca075efd79af by Alain Magloire

Makefile.am _cpystr.c chewurl.c url.c url.h url_imap.c

 	url_mailto.c url_mbox.c url_pop.c urli.c
Tightning up the API, still a draft.
1 parent 9d769577
......@@ -2,11 +2,11 @@
AUTOMAKE_OPTIONS = ../lib/ansi2knr
CFLAGS = -Wall -pedantic -g
CFLAGS = -Wall -pedantic -g
include_HEADERS = url.h
include_HEADERS = url.h url_mbox.h url_pop.h url_imap.h url_mailto.h
noinst_HEADERS = url0.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
......
#include <url0.h>
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Library Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include <cpystr.h>
#include <string.h>
int
_cpystr (const char * src, char * dst, unsigned int size)
_cpystr (const char *src, char *dst, unsigned int size)
{
unsigned int len = src ? strlen (src) : 0 ;
unsigned int len = src ? strlen (src) : 0 ;
if (dst == NULL || size == 0) {
return len;
if (dst == NULL || size == 0)
{
return len;
}
if (len >= size) {
len = size - 1;
if (len >= size)
{
len = size - 1;
}
memcpy (dst, src, len);
dst[len] = '\0';
return len;
memcpy (dst, src, len);
dst[len] = '\0';
return len;
}
......
......@@ -5,42 +5,50 @@
int
main (int argc, char ** argv)
{
int status;
long port;
url_t u;
char buffer[1024];
char str[1024];
while (fgets(str, sizeof (str), stdin) != NULL)
int status, i;
long port;
url_t u;
char buffer[1024];
char str[1024];
struct url_type *utype;
url_list_mtype (&utype, &status);
for (i = 0; i < status; i++)
{
str[strlen(str) - 1] = '\0'; /* chop newline */
status = url_create (&u, str);
if (status == -1) {
printf("%s --> FAILED\n", str);
continue;
}
printf("%s --> SUCCESS\n", str);
puts (utype[i].scheme);
puts (utype[i].description);
}
free (utype);
while (fgets(str, sizeof (str), stdin) != NULL)
{
str[strlen(str) - 1] = '\0'; /* chop newline */
status = url_init (&u, str);
if (status == -1) {
printf("%s --> FAILED\n", str);
continue;
}
printf("%s --> SUCCESS\n", str);
url_get_scheme (u, buffer, sizeof (buffer));
printf("\tscheme %s\n", buffer);
url_get_scheme (u, buffer, sizeof (buffer));
printf("\tscheme <%s>\n", buffer);
url_get_user (u, buffer, sizeof (buffer));
printf("\tuser %s\n", buffer);
url_get_user (u, buffer, sizeof (buffer));
printf("\tuser <%s>\n", buffer);
url_get_passwd (u, buffer, sizeof (buffer));
printf("\tpasswd %s\n", buffer);
url_get_passwd (u, buffer, sizeof (buffer));
printf("\tpasswd <%s>\n", buffer);
url_pop_get_auth (u, buffer, sizeof (buffer));
printf("\tauth %s\n", buffer);
url_pop_get_auth (u, buffer, sizeof (buffer));
printf("\tauth <%s>\n", buffer);
url_get_host (u, buffer, sizeof (buffer));
printf("\thost %s\n", buffer);
url_get_host (u, buffer, sizeof (buffer));
printf("\thost <%s>\n", buffer);
url_get_port (u, &port);
printf("\tport %ld\n", port);
url_destroy (&u);
url_get_port (u, &port);
printf("\tport %ld\n", port);
url_destroy (&u);
}
return 0;
return 0;
}
......
#include <url.h>
#include <url0.h>
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Library Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include <url_mbox.h>
#include <url_pop.h>
#include <url_imap.h>
#include <url_mailto.h>
#include <cpystr.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
/* forward declaration */
static int get_scheme (const url_t, char *, unsigned int);
static int get_user (const url_t, char *, unsigned int);
static int get_passwd (const url_t, char *, unsigned int);
static int get_host (const url_t, char *, unsigned int);
static int get_port (const url_t, long *);
static int get_path (const url_t, char *, unsigned int);
static int get_query (const url_t, char *, unsigned int);
static int is_pop (const url_t);
static int is_imap (const url_t);
static struct _supported_scheme
/* Forward prototypes */
static int get_scheme (const url_t, char *, int);
static int get_user (const url_t, char *, int);
static int get_passwd (const url_t, char *, int);
static int get_host (const url_t, char *, int);
static int get_port (const url_t, long *);
static int get_path (const url_t, char *, int);
static int get_query (const url_t, char *, int);
static int get_id (const url_t, int *id);
/*
Builtin url types.
We are using a simple circular list to hold the builtin type. */
static struct url_builtin
{
char * scheme;
char len;
int (*_create) __P ((url_t *, const char *name));
void (*_destroy) __P ((url_t *));
} _supported_scheme[] = {
{ "mailto:", 7, url_mailto_create, url_mailto_destroy },
{ "pop://", 6, url_pop_create, url_pop_destroy },
{ "imap://", 7, url_imap_create, url_imap_destroy },
{ "file://", 7, url_mbox_create, url_mbox_destroy },
{ "/", 1, url_mbox_create, url_mbox_destroy }, /* hack ? */
{ NULL, NULL, NULL, NULL }
const struct url_type *utype;
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] },
};
static int
get_scheme (const url_t u, char * s, unsigned int n)
/*
FIXME: Proper locking is not done when accessing the list
this code is not thread-safe .. TODO */
int
url_add_type (struct url_type *utype)
{
if (u == NULL)
return -1;
return _cpystr (u->scheme, s, n);
struct url_builtin *current = malloc (sizeof (*current));
if (current == NULL)
return -1;
utype->id = (int)utype; /* It just has to be uniq */
current->utype = utype;
current->is_malloc = 1;
current->next = url_builtin->next;
url_builtin->next = current;
return 0;
}
static int
get_user (const url_t u, char * s, unsigned int n)
int
url_remove_type (const struct url_type *utype)
{
if (u == NULL)
return -1;
return _cpystr (u->user, s, n);
struct url_builtin *current, *previous;
for (previous = url_builtin, current = url_builtin->next;
current != url_builtin;
previous = current, current = current->next)
{
if (current->utype == utype)
{
previous->next = current->next;
if (current->is_malloc)
free (current);
return 0;;
}
}
return -1;
}
/* FIXME: We should not store passwd in clear, but rather
have a simple encoding, and decoding mechanism */
static int
get_passwd (const url_t u, char * s, unsigned int n)
int
url_list_type (struct url_type *list, int n)
{
if (u == NULL)
return -1;
return _cpystr (u->passwd, s, n);
struct url_builtin *current;
int i;
for (i = 0, current = url_builtin->next; current != url_builtin;
current = current->next, i++)
{
if (list)
if (i < n)
list[i] = *(current->utype);
}
return i;
}
static int
get_host (const url_t u, char * s, unsigned int n)
int
url_list_mtype (struct url_type **mlist, int *n)
{
if (u == NULL)
return -1;
return _cpystr (u->host, s, n);
struct url_type *utype;
int i;
if ((i = url_list_type (NULL, 0)) <= 0 || (utype = malloc (i)) == NULL)
{
return -1;
}
*mlist = utype;
return *n = url_list_type (utype, i);
}
int
url_init (url_t * purl, const char *name)
{
int status = -1;
const struct url_type *utype;
struct url_builtin *ub;
/* Sanity checks */
if (name == NULL || *name == '\0')
{
return status;
}
/* Search for a known scheme */
for (ub = url_builtin->next; ub != url_builtin; ub = ub->next)
{
utype = ub->utype;
if (strncasecmp (name, utype->scheme, utype->len) == 0)
{
status = 0;
break;
}
}
/* Found one initialize it */
if (status == 0)
{
status = utype->_init (purl, name);
if (status == 0)
{
url_t url = *purl;
if (url->utype == NULL)
url->utype = utype;
if (url->_get_scheme == NULL)
url->_get_scheme = get_scheme;
if (url->_get_user == NULL)
url->_get_user = get_user;
if (url->_get_passwd == NULL)
url->_get_passwd = get_passwd;
if (url->_get_host == NULL)
url->_get_host = get_host;
if (url->_get_port == NULL)
url->_get_port = get_port;
if (url->_get_path == NULL)
url->_get_path = get_path;
if (url->_get_query == NULL)
url->_get_query = get_query;
if (url->_get_id == NULL)
url->_get_id = get_id;
}
}
return status;
}
void
url_destroy (url_t *purl)
{
if (purl && *purl)
{
const struct url_type *utype = (*purl)->utype;
utype->_destroy(purl);
(*purl) = NULL;
}
}
/* Simple stub functions they all call _cpystr */
static int
get_port (const url_t u, long * p)
get_scheme (const url_t u, char * s, int n)
{
if (u == NULL)
return -1;
return *p = u->port;
return _cpystr (u->scheme, s, n);
}
static int
get_path (const url_t u, char * s, unsigned int n)
get_user (const url_t u, char * s, int n)
{
if (u == NULL)
return -1;
return _cpystr(u->path, s, n);
return _cpystr (u->user, s, n);
}
/* FIXME: We should not store passwd in clear, but rather
have a simple encoding, and decoding mechanism */
static int
get_query (const url_t u, char * s, unsigned int n)
get_passwd (const url_t u, char * s, int n)
{
if (u == NULL)
return -1;
return _cpystr(u->query, s, n);
return _cpystr (u->passwd, s, n);
}
static int
is_pop (const url_t u)
get_host (const url_t u, char * s, int n)
{
return u->type & URL_POP;
return _cpystr (u->host, s, n);
}
static int
is_imap (const url_t u)
get_port (const url_t u, long * p)
{
return u->type & URL_IMAP;
*p = u->port;
return 0;
}
static int
is_unixmbox (const url_t u)
get_path (const url_t u, char * s, int n)
{
return u->type & URL_MBOX;
return _cpystr(u->path, s, n);
}
int
url_create (url_t * url, const char * name)
static int
get_query (const url_t u, char * s, int n)
{
int status = -1, i ;
/* sanity checks */
if (name == NULL || *name == '\0')
{
return status;
}
/* scheme://scheme-specific-part */
for (i = 0; _supported_scheme[i].scheme; i++)
{
if (strncasecmp (name, _supported_scheme[i].scheme,
strlen(_supported_scheme[i].scheme)) == 0)
{
status = 1;
break;
}
}
if (status == 1)
{
status =_supported_scheme[i]._create(url, name);
if (status == 0)
{
url_t u = *url;
if (u->_get_scheme == NULL)
{
u->_get_scheme = get_scheme;
}
if (u->_get_user == NULL)
{
u->_get_user = get_user;
}
if (u->_get_passwd == NULL)
{
u->_get_passwd = get_passwd;
}
if (u->_get_host == NULL)
{
u->_get_host = get_host;
}
if (u->_get_port == NULL)
{
u->_get_port = get_port;
}
if (u->_get_path == NULL)
{
u->_get_path = get_path;
}
if (u->_get_query == NULL)
{
u->_get_query = get_query;
}
if (u->_is_pop == NULL)
{
u->_is_pop = is_pop;
}
if (u->_is_imap == NULL)
{
u->_is_imap = is_imap;
}
if (u->_is_unixmbox == NULL)
{
u->_is_unixmbox = is_unixmbox;
}
if (u->_create == NULL)
{
u->_create = _supported_scheme[i]._create;
}
if (u->_destroy == NULL)
{
u->_destroy= _supported_scheme[i]._destroy;
}
}
}
return status;
return _cpystr(u->query, s, n);
}
void
url_destroy (url_t * url)
static int
get_id (const url_t u, int *id)
{
if (url && *url)
{
url_t u = *url;
u->_destroy(url);
u = NULL;
}
const struct url_type *utype = u->utype;
*id = utype->id;
return 0;
}
......
......@@ -2,16 +2,16 @@
Copyright (C) 1999 Free Software Foundation, Inc.
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
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
GNU Library General Public License for more details.
You should have received a copy of the GNU General Public License
You should have received a copy of the GNU Library General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
......@@ -23,110 +23,88 @@ extern "C" {
#endif
#ifndef __P
#ifdef __STDC__
#define __P(args) args
#else
#define __P(args) ()
#endif
# ifdef __STDC__
# define __P(args) args
# else
# define __P(args) ()
# endif
#endif /*!__P */
/* forward declaration */
struct _url;
typedef struct _url * url_t;
struct _url
struct url_type
{
/* Data */
#define URL_POP ((int)1)
#define URL_IMAP (URL_POP << 1)
#define URL_MBOX (URL_IMAP << 1)
int type;
char *scheme;
char *user;
char *passwd; /* encoded ?? */
char *host;
long port;
char *path;
char *query;
void * data;
int (*_create) __P ((url_t *, const char *));
void (*_destroy) __P ((url_t *));
/* Methods */
int (*_get_scheme) __P ((const url_t, char *, unsigned int));
int (*_get_user) __P ((const url_t, char *, unsigned int));
int (*_get_passwd) __P ((const url_t, char *, unsigned int));
int (*_get_host) __P ((const url_t, char *, unsigned int));
int (*_get_port) __P ((const url_t, long *));
int (*_get_path) __P ((const url_t, char *, unsigned int));
int (*_get_query) __P ((const url_t, char *, unsigned int));
int (*_is_pop) __P ((const url_t));
int (*_is_imap) __P ((const url_t));
int (*_is_unixmbox) __P ((const url_t));
char *scheme;
int len;
char *description;
int id;
int (*_init) __P ((url_t *, const char * name));
void (*_destroy) __P ((url_t *));
};
extern int url_mailto_create __P ((url_t *, const char *name));
extern void url_mailto_destroy __P ((url_t *));
/* foward decl */
struct _url_pop;
typedef struct _url_pop * url_pop_t;
struct _url_pop
struct _url
{
/* we use the fields from url_t */
/* user, passwd, host, port */
char * auth;
int (*_get_auth) __P ((const url_pop_t, char *, unsigned int));
/* Data */
char *scheme;
char *user;
char *passwd; /* encoded ?? */
char *host;
long port;
char *path;
char *query;
void *data;
const struct url_type * utype;
/* Methods */
int (*_get_scheme) __P ((const url_t, char *scheme, int len));
int (*_get_user) __P ((const url_t, char *user, int len));
int (*_get_passwd) __P ((const url_t, char *passwd, int len));
int (*_get_host) __P ((const url_t, char *host, int len));
int (*_get_port) __P ((const url_t, long *port));
int (*_get_path) __P ((const url_t, char *path, int len));
int (*_get_query) __P ((const url_t, char *query, int len));
int (*_get_id) __P ((const url_t, int *id));
};
extern int url_pop_create __P ((url_t *, const char *name));
extern void url_pop_destroy __P ((url_t *));
extern int url_imap_create __P ((url_t *, const char *name));
extern void url_imap_destroy __P ((url_t *));
extern int url_init __P ((url_t *, const char *name));
extern void url_destroy __P ((url_t *));
extern int url_mbox_create __P ((url_t *, const char *name));
extern void url_mbox_destroy __P ((url_t *));
extern int url_list_type __P ((struct url_type list[], int len));
extern int url_list_mtype __P ((struct url_type *mlist[], int *len));
extern int url_add_type __P ((struct url_type *utype));
extern int url_remove_type __P ((const struct url_type *utype));
extern int url_create __P ((url_t *, const char *name));
extern void url_destroy __P ((url_t *));
#ifdef __GNUC__
# define INLINE __inline__
#else
# define INLINE
#endif
extern int url_get_scheme (const url_t, char *, unsigned int);
extern int url_get_user (const url_t , char *, unsigned int);
extern int url_get_passwd (const url_t, char *, unsigned int);
extern int url_get_host (const url_t, char *, unsigned int);
extern int url_get_port (const url_t, long *);
extern int url_get_path (const url_t, char *, unsigned int);
extern int url_get_query (const url_t, char *, unsigned int);
extern int url_is_pop (const url_t);
extern int url_is_imap (const url_t);
extern int url_is_unixmbox (const url_t);
/* pop*/
extern int url_pop_get_auth (const url_t, char *, unsigned int);
extern INLINE int url_get_scheme __P ((const url_t, char *scheme, int len));
extern INLINE int url_get_user __P ((const url_t, char *user, int len));
extern INLINE int url_get_passwd __P ((const url_t, char *passwd, int len));
extern INLINE int url_get_host __P ((const url_t, char *host, int len));
extern INLINE int url_get_port __P ((const url_t, long *port));
extern INLINE int url_get_path __P ((const url_t, char *path, int len));
extern INLINE int url_get_query __P ((const url_t, char *query, int len));
extern INLINE int url_get_id __P ((const url_t, int *id));
#ifdef URL_MACROS
# define url_get_scheme(url, prot, n) url->_get_scheme(url, prot, n)
# define url_get_user(url, user, n) url->_get_user(url, user, n)
# define url_get_passwd(url, passwd, n) url->_get_passwd(url, passwd, n)
# define url_get_host(url, host, n) url->_get_host(url, host, n)
# define url_get_port(url, port) url->_get_port(url, port)
# define url_get_path(url, path, n) url->_get_path(url, path, n)
# define url_get_query(url, query, n) url->_get_query(url, query, n)
/* what we support so far */
# define url_is_pop(url) (url->type & URL_POP)
# define url_is_imap(url) (url->type & URL_IMAP)
# define url_is_unixmbox(url) (url->type & URL_MBOX)
/* pop */
# define url_pop_get_auth(url, auth, n) (((url_pop_t) \
(url->data))->_get_auth(url->data, auth, n))
# define url_get_scheme(url, scheme, n) url->_get_scheme (url, scheme, n)
# define url_get_user(url, user, n) url->_get_user (url, user, n)
# define url_get_passwd(url, passwd, n) url->_get_passwd (url, passwd, n)
# define url_get_host(url, host, n) url->_get_host (url, host, n)
# define url_get_port(url, port) url->_get_port (url, port)
# define url_get_path(url, path, n) url->_get_path (url, path, n)
# define url_get_query(url, query, n) url->_get_query (url, query, n)
# define url_get_id(url, id) url->_get_id (url, id)
#endif /* URL_MACROS */
#ifdef __cplusplus
}
#endif
#endif /* URL_H */
......
#include <url.h>
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include <url_imap.h>
struct url_type _url_imap_type =
{
"imap://", 7,
"imap://... TODO",
(int)&_url_imap_type,
url_imap_init, url_imap_destroy
};
void
url_imap_destroy (url_t * url)
url_imap_destroy (url_t *purl)
{
return;
return;
}
int
url_imap_create (url_t * u, const char * name)
url_imap_init (url_t *purl, const char *name)
{
return -1;
return -1;
}
......
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifndef _URL_IMAP_H
#define _URL_IMAP_H 1
#include <url.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef __P
# ifdef __STDC__
# define __P(args) args
# else
# define __P(args) ()
# endif
#endif /*!__P */
extern int url_imap_init __P ((url_t *, const char *name));
extern void url_imap_destroy __P ((url_t *));
extern struct url_type _url_imap_type;
#ifndef INLINE
# ifdef __GNUC__
# define INLINE __inline__
# else
# define INLINE
# endif
#endif
#ifdef MU_URL_MACROS
#endif /* MU_URL_MACROS */
#ifdef __cplusplus
}
#endif
#endif /* URL_IMAP_H */
#include <url.h>
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include <url_mailto.h>
struct url_type _url_mailto_type =
{
"mailto:", 6,
"mailto:<user>@<hostname>?<query>",
(int)&_url_mailto_type,
url_mailto_init, url_mailto_destroy
};
void
url_mailto_destroy (url_t * url)
url_mailto_destroy (url_t *purl)
{
return;
return;
}
int
url_mailto_create (url_t *u, const char * name)
url_mailto_init (url_t *purl, const char *name)
{
return -1;
return -1;
}
......
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifndef _URL_MAILTO_H
#define _URL_MAILTO_H 1
#include <url.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef __P
# ifdef __STDC__
# define __P(args) args
# else
# define __P(args) ()
# endif
#endif /*!__P */
/* UNIX MBOX */
extern int url_mailto_init __P ((url_t *, const char *name));
extern void url_mailto_destroy __P ((url_t *));
extern struct url_type _url_mailto_type;
#ifndef INLINE
# ifdef __GNUC__
# define INLINE __inline__
# else
# define INLINE
# endif
#endif
#ifdef MU_URL_MACROS
#endif /* MU_URL_MACROS */
#ifdef __cplusplus
}
#endif
#endif /* URL_MAILTO_H */
#include <url.h>
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include <url_mbox.h>
#include <stdlib.h>
#include <string.h>
struct url_type _url_mbox_type =
{
"file://", 7,
"file://<full_path_name>",
(int)&_url_mbox_type, /* uniq id */
url_mbox_init, url_mbox_destroy
};
void
url_mbox_destroy (url_t * url)
url_mbox_destroy (url_t *purl)
{
return;
if (purl && *purl)
{
url_t url = *purl;
if (url->scheme)
free (url->scheme);
if (url->path)
free (url->path);
free (url);
url = NULL;
}
}
/*
UNIXMBOX and MAILDIR URL
file://path
*/
int
url_mbox_create (url_t * u, const char * name)
url_mbox_init (url_t *purl, const char *name)
{
return -1;
url_t url;
int len;
/* reject the obvious */
if (name == NULL || strncmp ("file://", name, 7) != 0
|| (len = strlen (name)) < 8 /* 7(scheme)+1(path)*/)
{
return -1;
}
/* do I need to decode url encoding '% hex hex' ? */
url = calloc(1, sizeof (*url));
if (url == NULL)
{
return -1;
}
/* TYPE */
url->utype = &_url_mbox_type;
/* SCHEME */
/* strdup ("file://") the hard way */
url->scheme = malloc (7 + 1);
if (url->scheme == NULL)
{
url_mbox_destroy (&url);
return -1;
}
memcpy (url->scheme, "file://", 8);
/* PATH */
name += 7; /* pass the scheme */
len -= 7;
url->path = malloc (len + 1);
if (url->path == NULL)
{
url_mbox_destroy (&url);
return -1;
}
memcpy (url->path, name, len + 1);
*purl = url;
return 0;
}
......
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifndef _URL_MBOX_H
#define _URL_MBOX_H 1
#include <url.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef __P
# ifdef __STDC__
# define __P(args) args
# else
# define __P(args) ()
# endif
#endif /*!__P */
/* UNIX MBOX */
extern int url_mbox_init __P ((url_t *, const char *name));
extern void url_mbox_destroy __P ((url_t *));
extern struct url_type _url_mbox_type;
#ifndef INLINE
# ifdef __GNUC__
# define INLINE __inline__
# else
# define INLINE
# endif
#endif
#ifdef MU_URL_MACROS
#endif /* MU_URL_MACROS */
#ifdef __cplusplus
}
#endif
#endif /* URL_MBOX_H */
#include <url.h>
#include <url0.h>
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include <url_pop.h>
#include <cpystr.h>
#include <stdlib.h>
#include <string.h>
#define POP_PORT 110
struct url_type _url_pop_type =
{
"pop://", 6,
"pop://<user>;AUTH=<auth>@<hostname>:<port>",
(int)&_url_pop_type,
url_pop_init, url_pop_destroy
};
static int get_auth (const url_pop_t up, char * s, unsigned int n);
static int get_auth (const url_pop_t up, char *s, int n);
static int
get_auth (const url_pop_t up, char * s, unsigned int n)
get_auth (const url_pop_t up, char * s, int n)
{
if (up == NULL) return -1;
return _cpystr (up->auth, s, n);
return _cpystr (up->auth, s, n);
}
int
(url_pop_get_auth) (const url_t url, char * auth, unsigned int n)
(url_pop_get_auth) (const url_t url, char * auth, int n)
{
return ((url_pop_t) (url->data))->_get_auth(url->data, auth, n);
return ((url_pop_t) (url->data))->_get_auth(url->data, auth, n);
}
void
url_pop_destroy (url_t * url)
url_pop_destroy (url_t *purl)
{
if (url && *url)
{
url_t u = *url;
if (u->scheme)
{
free (u->scheme);
}
if (u->user)
{
free (u->user);
}
if (u->passwd)
{
free (u->passwd);
}
if (u->host)
{
free (u->host);
}
if (u->data)
{
url_pop_t up = u->data;
if (up->auth)
{
free (up->auth);
}
free (u->data);
}
free (u);
u = NULL;
}
if (purl && *purl)
{
url_t url = *purl;
if (url->scheme)
free (url->scheme);
if (url->user)
free (url->user);
if (url->passwd)
free (url->passwd);
if (url->host)
free (url->host);
if (url->data)
{
url_pop_t up = url->data;
if (up->auth)
free (up->auth);
free (url->data);
}
free (url);
url = NULL;
}
}
/*
POP URL
pop://<user>;AUTH=<auth>@<host>:<port>
POP URL
pop://<user>;AUTH=<auth>@<host>:<port>
*/
int
url_pop_create (url_t * url, const char * name)
url_pop_init (url_t *purl, const char *name)
{
const char * host_port, * index;
url_t u;
url_pop_t up;
/* reject the obvious */
if (name == NULL ||
strncmp ("pop://", name, 6) != 0 ||
(host_port = strchr (name, '@')) == NULL ||
strlen(name) < 9 /* 6(scheme)+1(user)+1(@)+1(host)*/) {
return -1;
const char *host_port, *index;
url_t url;
url_pop_t up;
/* reject the obvious */
if (name == NULL || strncmp ("pop://", name, 6) != 0
|| (host_port = strchr (name, '@')) == NULL
|| strlen(name) < 9 /* 6(scheme)+1(user)+1(@)+1(host)*/)
{
return -1;
}
/* do I need to decode url encoding '% hex hex' ? */
u = xcalloc(1, sizeof (*u));
u->data = up = xcalloc(1, sizeof(*up));
up->_get_auth = get_auth;
/* type */
u->type = URL_POP;
u->scheme = xstrdup ("pop://");
name += 6; /* pass the scheme */
/* looking for user;auth=auth-enc */
#if 1
for (index = name; index != host_port; index++)
{
/* Auth ? */
if (*index == ';')
{
if (strncasecmp(index +1, "auth=", 5) == 0 )
/* do I need to decode url encoding '% hex hex' ? */
url = calloc(1, sizeof (*url));
url->data = up = calloc(1, sizeof(*up));
up->_get_auth = get_auth;
/* TYPE */
url->utype = &_url_pop_type;
/* SCHEME */
url->scheme = malloc (6 + 1);
if (url->scheme == NULL)
{
url_pop_destroy (&url);
return -1;
}
memcpy (url->scheme, "pop://", 7);
name += 6; /* pass the scheme */
/* looking for "user;auth=auth-enc" */
for (index = name; index != host_port; index++)
{
/* Auth ? */
if (*index == ';')
{
/* make sure it the token */
if (strncasecmp(index + 1, "auth=", 5) == 0)
break;
}
}
#endif
/* USER */
if (index == name)
{
//free();
return -1;
}
u->user = malloc(index - name + 1);
((char *)memcpy(u->user, name, index - name))[index - name] = '\0';
/* AUTH */
if ((host_port - index) <= 6 /*strlen(";AUTH=")*/)
{
/* default AUth is '*'*/
up->auth = malloc (1 + 1);
up->auth[0] = '*';
up->auth[1] = '\0';
}
else
{
/* move pass AUTH= */
index += 6;
up->auth = malloc (host_port - index + 1);
((char *) memcpy (up->auth, index, host_port - index))
}
}
if (index == name)
{
url_pop_destroy (&url);
return -1;
}
/* USER */
url->user = malloc(index - name + 1);
if (url->user == NULL)
{
url_pop_destroy (&url);
return -1;
}
((char *)memcpy(url->user, name, index - name))[index - name] = '\0';
/* AUTH */
if ((host_port - index) <= 6 /*strlen(";AUTH=")*/)
{
/* Use default AUTH '*' */
up->auth = malloc (1 + 1);
if (up->auth)
{
up->auth[0] = '*';
up->auth[1] = '\0';
}
}
else
{
/* move pass AUTH= */
index += 6;
up->auth = malloc (host_port - index + 1);
if (up->auth)
{
((char *)memcpy (up->auth, index, host_port - index))
[host_port - index] = '\0';
}
/* HOST:PORT */
index = strchr (++host_port, ':');
if (index == NULL)
{
int len = strlen (host_port);
u->host = malloc (len + 1);
((char *)memcpy (u->host, host_port, len))[len] = '\0';
u->port = POP_PORT;
}
else
{
long p = strtol(index + 1, NULL, 10);
u->host = malloc (index - host_port + 1);
((char *)memcpy (u->host, host_port, index - host_port))
}
}
if (up->auth == NULL)
{
url_pop_destroy (&url);
return -1;
}
/* HOST:PORT */
index = strchr (++host_port, ':');
if (index == NULL)
{
int len = strlen (host_port);
url->host = malloc (len + 1);
if (url->host)
{
((char *)memcpy (url->host, host_port, len))[len] = '\0';
url->port = MU_POP_PORT;
}
}
else
{
long p = strtol(index + 1, NULL, 10);
url->host = malloc (index - host_port + 1);
if (url->host)
{
((char *)memcpy (url->host, host_port, index - host_port))
[index - host_port]='\0';
u->port = (p == 0) ? POP_PORT : p;
}
*url = u;
return 0;
url->port = (p == 0) ? MU_POP_PORT : p;
}
}
if (url->host == NULL)
{
url_pop_destroy (&url);
return -1;
}
*purl = url;
return 0;
}
......
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifndef _URL_POP_H
#define _URL_POP_H 1
#include <url.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef __P
# ifdef __STDC__
# define __P(args) args
# else
# define __P(args) ()
# endif
#endif /*!__P */
/* POP3 */
struct _url_pop;
typedef struct _url_pop * url_pop_t;
struct _url_pop
{
/* we use the fields from url_t */
/* user, passwd, host, port */
char * auth;
int (*_get_auth) __P ((const url_pop_t, char *, int));
};
extern int url_pop_init __P ((url_t *, const char *name));
extern void url_pop_destroy __P ((url_t *));
#define MU_POP_PORT 110
extern struct url_type _url_pop_type;
#ifndef INLINE
# ifdef __GNUC__
# define INLINE __inline__
# else
# define INLINE
# endif
#endif
/* pop*/
extern int url_pop_get_auth (const url_t, char *, int);
#ifdef MU_URL_MACROS
/* pop */
# define url_pop_get_auth(url, auth, n) (((url_pop_t) \
(url->data))->_get_auth(url->data, auth, n))
#endif /* MU_URL_MACROS */
#ifdef __cplusplus
}
#endif
#endif /* URL_POP_H */
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Library Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include <url.h>
int
(url_get_scheme) (const url_t url, char * scheme, unsigned int n)
(url_get_scheme) (const url_t url, char *scheme, int n)
{ return url->_get_scheme(url, scheme, n); }
int
(url_get_user) (const url_t url, char *user, unsigned int n)
(url_get_user) (const url_t url, char *user, int n)
{ return url->_get_user(url, user, n); }
int
(url_get_passwd) (const url_t url, char *passwd, unsigned int n)
(url_get_passwd) (const url_t url, char *passwd, int n)
{ return url->_get_passwd(url, passwd, n); }
int
(url_get_host) (const url_t url, char * host, unsigned int n)
(url_get_host) (const url_t url, char *host, int n)
{ return url->_get_host(url, host, n); }
int
(url_get_port) (const url_t url, long * port)
(url_get_port) (const url_t url, long *port)
{ return url->_get_port(url, port); }
int
(url_get_path) (const url_t url, char *path, unsigned int n)
(url_get_path) (const url_t url, char *path, int n)
{ return url->_get_path(url, path, n); }
int
(url_get_query) (const url_t url, char *query, unsigned int n)
(url_get_query) (const url_t url, char *query, int n)
{ return url->_get_query(url, query, n); }
int
(url_is_pop) (const url_t url)
{ return (url->type & URL_POP); }
int
(url_is_imap) (const url_t url)
{ return (url->type & URL_IMAP); }
int
(url_is_unixmbox) (const url_t url)
{ return (url->type & URL_MBOX); }
(url_get_id) (const url_t url, int *id)
{ return url->_get_id (url, id); }
......