summaryrefslogtreecommitdiff
path: root/libmailutils/url
diff options
context:
space:
mode:
Diffstat (limited to 'libmailutils/url')
-rw-r--r--libmailutils/url/Makefile.am14
-rw-r--r--libmailutils/url/add-param.c74
-rw-r--r--libmailutils/url/add-query.c74
-rw-r--r--libmailutils/url/clr-param.c50
-rw-r--r--libmailutils/url/clr-query.c50
-rw-r--r--libmailutils/url/create.c6
-rw-r--r--libmailutils/url/flag.c2
-rw-r--r--libmailutils/url/null.c38
-rw-r--r--libmailutils/url/scheme.c13
-rw-r--r--libmailutils/url/set-auth.c58
-rw-r--r--libmailutils/url/set-host.c73
-rw-r--r--libmailutils/url/set-path.c58
-rw-r--r--libmailutils/url/set-port.c65
-rw-r--r--libmailutils/url/set-scheme.c58
-rw-r--r--libmailutils/url/set-secret.c53
-rw-r--r--libmailutils/url/set-service.c80
-rw-r--r--libmailutils/url/set-user.c58
-rw-r--r--libmailutils/url/urlinv.c33
-rw-r--r--libmailutils/url/urlstr.c151
19 files changed, 991 insertions, 17 deletions
diff --git a/libmailutils/url/Makefile.am b/libmailutils/url/Makefile.am
index 6f4a9c0cd..937f82379 100644
--- a/libmailutils/url/Makefile.am
+++ b/libmailutils/url/Makefile.am
@@ -19,6 +19,10 @@ noinst_LTLIBRARIES = liburl.la
liburl_la_SOURCES = \
accessor.h\
+ add-param.c\
+ clr-param.c\
+ add-query.c\
+ clr-query.c\
copy.c\
create.c\
decode.c\
@@ -36,9 +40,19 @@ liburl_la_SOURCES = \
get-secret.c\
get-user.c\
match.c\
+ null.c\
port.c\
scheme.c\
+ set-auth.c\
+ set-host.c\
+ set-path.c\
+ set-port.c\
+ set-scheme.c\
+ set-secret.c\
+ set-service.c\
+ set-user.c\
uplevel.c\
+ urlinv.c\
urlstr.c
INCLUDES = @MU_LIB_COMMON_INCLUDES@ -I/libmailutils
diff --git a/libmailutils/url/add-param.c b/libmailutils/url/add-param.c
new file mode 100644
index 000000000..0bd0f4301
--- /dev/null
+++ b/libmailutils/url/add-param.c
@@ -0,0 +1,74 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+ Copyright (C) 2010 Free Software Foundation, Inc.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 3 of the License, or (at your option) any later version.
+
+ This library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General
+ Public License along with this library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#ifdef HAVE_STRINGS_H
+# include <strings.h>
+#endif
+
+#include <mailutils/types.h>
+#include <mailutils/errno.h>
+#include <mailutils/sys/url.h>
+#include <mailutils/url.h>
+
+int
+mu_url_add_param (mu_url_t url, size_t pc, const char **pv)
+{
+ char **fv;
+ int i, j;
+
+ if (!url)
+ return EINVAL;
+ if (!pc || !pv)
+ return 0;
+
+ fv = realloc (url->fvpairs,
+ sizeof (url->fvpairs[0]) * (url->fvcount + pc + 1));
+ if (!fv)
+ return ENOMEM;
+ url->fvpairs = fv;
+ for (i = url->fvcount, j = 0; j < pc; i++, j++)
+ {
+ fv[i] = strdup (pv[j]);
+ if (!fv[i])
+ {
+ /* Restore the status quo */
+ for (; j; j--)
+ free (fv[--i]);
+ if (url->fvcount)
+ fv[url->fvcount] = NULL;
+ else
+ {
+ free (url->fvpairs);
+ url->fvpairs = NULL;
+ url->fvcount = 0;
+ }
+ return ENOMEM;
+ }
+ }
+ fv[i] = NULL;
+ url->fvcount = i;
+ url->flags |= MU_URL_PARAM;
+ mu_url_invalidate (url);
+ return 0;
+}
diff --git a/libmailutils/url/add-query.c b/libmailutils/url/add-query.c
new file mode 100644
index 000000000..8d810bb5e
--- /dev/null
+++ b/libmailutils/url/add-query.c
@@ -0,0 +1,74 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+ Copyright (C) 2010 Free Software Foundation, Inc.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 3 of the License, or (at your option) any later version.
+
+ This library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General
+ Public License along with this library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#ifdef HAVE_STRINGS_H
+# include <strings.h>
+#endif
+
+#include <mailutils/types.h>
+#include <mailutils/errno.h>
+#include <mailutils/sys/url.h>
+#include <mailutils/url.h>
+
+int
+mu_url_add_query (mu_url_t url, size_t pc, const char **pv)
+{
+ char **fv;
+ int i, j;
+
+ if (!url)
+ return EINVAL;
+ if (!pc || !pv)
+ return 0;
+
+ fv = realloc (url->qargv,
+ sizeof (url->qargv[0]) * (url->qargc + pc + 1));
+ if (!fv)
+ return ENOMEM;
+ url->qargv = fv;
+ for (i = url->qargc, j = 0; j < pc; i++, j++)
+ {
+ fv[i] = strdup (pv[j]);
+ if (!fv[i])
+ {
+ /* Restore the status quo */
+ for (; j; j--)
+ free (fv[--i]);
+ if (url->qargc)
+ fv[url->qargc] = NULL;
+ else
+ {
+ free (url->qargv);
+ url->qargv = NULL;
+ url->qargc = 0;
+ }
+ return ENOMEM;
+ }
+ }
+ fv[i] = NULL;
+ url->qargc = i;
+ url->flags |= MU_URL_QUERY;
+ mu_url_invalidate (url);
+ return 0;
+}
diff --git a/libmailutils/url/clr-param.c b/libmailutils/url/clr-param.c
new file mode 100644
index 000000000..0feb80f6d
--- /dev/null
+++ b/libmailutils/url/clr-param.c
@@ -0,0 +1,50 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+ Copyright (C) 2010 Free Software Foundation, Inc.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 3 of the License, or (at your option) any later version.
+
+ This library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General
+ Public License along with this library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#ifdef HAVE_STRINGS_H
+# include <strings.h>
+#endif
+
+#include <mailutils/types.h>
+#include <mailutils/errno.h>
+#include <mailutils/sys/url.h>
+#include <mailutils/url.h>
+
+int
+mu_url_clear_param (mu_url_t url)
+{
+ int i;
+
+ if (!url)
+ return EINVAL;
+
+ for (i = 0; i < url->fvcount; i++)
+ free (url->fvpairs[i]);
+ free (url->fvpairs);
+ url->fvpairs = NULL;
+ url->fvcount = 0;
+ url->flags &= ~MU_URL_PARAM;
+ mu_url_invalidate (url);
+ return 0;
+}
diff --git a/libmailutils/url/clr-query.c b/libmailutils/url/clr-query.c
new file mode 100644
index 000000000..186cb25ff
--- /dev/null
+++ b/libmailutils/url/clr-query.c
@@ -0,0 +1,50 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+ Copyright (C) 2010 Free Software Foundation, Inc.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 3 of the License, or (at your option) any later version.
+
+ This library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General
+ Public License along with this library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#ifdef HAVE_STRINGS_H
+# include <strings.h>
+#endif
+
+#include <mailutils/types.h>
+#include <mailutils/errno.h>
+#include <mailutils/sys/url.h>
+#include <mailutils/url.h>
+
+int
+mu_url_clear_query (mu_url_t url)
+{
+ int i;
+
+ if (!url)
+ return EINVAL;
+
+ for (i = 0; i < url->qargc; i++)
+ free (url->qargv[i]);
+ free (url->qargv);
+ url->qargv = NULL;
+ url->qargc = 0;
+ url->flags &= ~MU_URL_QUERY;
+ mu_url_invalidate (url);
+ return 0;
+}
diff --git a/libmailutils/url/create.c b/libmailutils/url/create.c
index 130b7a2bc..d6b01be2c 100644
--- a/libmailutils/url/create.c
+++ b/libmailutils/url/create.c
@@ -532,7 +532,11 @@ mu_url_create_hint (mu_url_t *purl, const char *str, int flags,
{
int rc;
struct mu_url_ctx ctx;
- mu_url_t url = calloc (1, sizeof (*url));
+ mu_url_t url;
+
+ if (!purl)
+ return EINVAL;
+ url = calloc (1, sizeof (*url));
if (url == NULL)
return ENOMEM;
url->name = strdup (str);
diff --git a/libmailutils/url/flag.c b/libmailutils/url/flag.c
index 586c8817b..4387948fb 100644
--- a/libmailutils/url/flag.c
+++ b/libmailutils/url/flag.c
@@ -27,7 +27,7 @@ mu_url_get_flags (mu_url_t url, int *pf)
{
if (!url || !pf)
return EINVAL;
- *pf = url->flags;
+ *pf = url->flags;
return 0;
}
diff --git a/libmailutils/url/null.c b/libmailutils/url/null.c
new file mode 100644
index 000000000..471f19492
--- /dev/null
+++ b/libmailutils/url/null.c
@@ -0,0 +1,38 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+ Copyright (C) 2010, 2011 Free Software Foundation, Inc.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 3 of the License, or (at your option) any later version.
+
+ This library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General
+ Public License along with this library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+#include <stdlib.h>
+#include <errno.h>
+#include <mailutils/sys/url.h>
+#include <mailutils/url.h>
+
+int
+mu_url_create_null (mu_url_t *purl)
+{
+ mu_url_t url;
+
+ if (!purl)
+ return EINVAL;
+ url = calloc (1, sizeof (*url));
+ if (url == NULL)
+ return ENOMEM;
+ *purl = url;
+ return 0;
+}
diff --git a/libmailutils/url/scheme.c b/libmailutils/url/scheme.c
index fa9fbf179..ec42f70e0 100644
--- a/libmailutils/url/scheme.c
+++ b/libmailutils/url/scheme.c
@@ -31,19 +31,6 @@
#include <mailutils/sys/url.h>
int
-mu_url_set_scheme (mu_url_t url, const char *scheme)
-{
- char *p;
- if (!url || !scheme)
- return EINVAL;
- p = realloc (url->scheme, strlen (scheme) + 1);
- if (!p)
- return ENOMEM;
- strcpy (url->scheme, scheme);
- return 0;
-}
-
-int
mu_url_is_scheme (mu_url_t url, const char *scheme)
{
if (url && scheme && url->scheme
diff --git a/libmailutils/url/set-auth.c b/libmailutils/url/set-auth.c
new file mode 100644
index 000000000..b4e9e610d
--- /dev/null
+++ b/libmailutils/url/set-auth.c
@@ -0,0 +1,58 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+ Copyright (C) 2010 Free Software Foundation, Inc.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 3 of the License, or (at your option) any later version.
+
+ This library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General
+ Public License along with this library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#ifdef HAVE_STRINGS_H
+# include <strings.h>
+#endif
+
+#include <mailutils/types.h>
+#include <mailutils/errno.h>
+#include <mailutils/sys/url.h>
+#include <mailutils/url.h>
+
+int
+mu_url_set_auth (mu_url_t url, const char *auth)
+{
+ char *copy;
+
+ if (!url)
+ return EINVAL;
+ if (auth)
+ {
+ copy = strdup (auth);
+ if (!copy)
+ return ENOMEM;
+ url->flags |= MU_URL_AUTH;
+ }
+ else
+ {
+ url->flags &= ~MU_URL_AUTH;
+ copy = NULL;
+ }
+ free (url->auth);
+ url->auth = copy;
+ url->_get_auth = NULL;
+ mu_url_invalidate (url);
+ return 0;
+}
diff --git a/libmailutils/url/set-host.c b/libmailutils/url/set-host.c
new file mode 100644
index 000000000..6cb21f61d
--- /dev/null
+++ b/libmailutils/url/set-host.c
@@ -0,0 +1,73 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+ Copyright (C) 2010 Free Software Foundation, Inc.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 3 of the License, or (at your option) any later version.
+
+ This library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General
+ Public License along with this library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#ifdef HAVE_STRINGS_H
+# include <strings.h>
+#endif
+
+#include <mailutils/types.h>
+#include <mailutils/errno.h>
+#include <mailutils/sys/url.h>
+#include <mailutils/url.h>
+
+int
+mu_url_set_host (mu_url_t url, const char *host)
+{
+ char *copy;
+
+ if (!url)
+ return EINVAL;
+ if (host)
+ {
+ size_t len;
+ int flag = MU_URL_HOST;
+
+ len = strlen (host);
+ if (len == 0)
+ return EINVAL;
+ if (host[0] == '[' && host[len-1] == ']')
+ {
+ flag |= MU_URL_IPV6;
+ host++;
+ len -= 2;
+ }
+
+ copy = malloc (len + 1);
+ if (!copy)
+ return ENOMEM;
+ memcpy (copy, host, len);
+ copy[len] = 0;
+ url->flags |= flag;
+ }
+ else
+ {
+ url->flags &= ~(MU_URL_HOST|MU_URL_IPV6);
+ copy = NULL;
+ }
+ url->_get_host = NULL;
+ free (url->host);
+ url->host = copy;
+ mu_url_invalidate (url);
+ return 0;
+}
diff --git a/libmailutils/url/set-path.c b/libmailutils/url/set-path.c
new file mode 100644
index 000000000..686dfad36
--- /dev/null
+++ b/libmailutils/url/set-path.c
@@ -0,0 +1,58 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+ Copyright (C) 2010 Free Software Foundation, Inc.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 3 of the License, or (at your option) any later version.
+
+ This library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General
+ Public License along with this library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#ifdef HAVE_STRINGS_H
+# include <strings.h>
+#endif
+
+#include <mailutils/types.h>
+#include <mailutils/errno.h>
+#include <mailutils/sys/url.h>
+#include <mailutils/url.h>
+
+int
+mu_url_set_path (mu_url_t url, const char *path)
+{
+ char *copy;
+
+ if (!url)
+ return EINVAL;
+ if (path)
+ {
+ copy = strdup (path);
+ if (!copy)
+ return ENOMEM;
+ url->flags |= MU_URL_PATH;
+ }
+ else
+ {
+ url->flags &= ~MU_URL_PATH;
+ copy = NULL;
+ }
+ free (url->path);
+ url->path = copy;
+ url->_get_path = NULL;
+ mu_url_invalidate (url);
+ return 0;
+}
diff --git a/libmailutils/url/set-port.c b/libmailutils/url/set-port.c
new file mode 100644
index 000000000..6549b722d
--- /dev/null
+++ b/libmailutils/url/set-port.c
@@ -0,0 +1,65 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+ Copyright (C) 2010 Free Software Foundation, Inc.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 3 of the License, or (at your option) any later version.
+
+ This library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General
+ Public License along with this library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#ifdef HAVE_STRINGS_H
+# include <strings.h>
+#endif
+
+#include <mailutils/types.h>
+#include <mailutils/errno.h>
+#include <mailutils/sys/url.h>
+#include <mailutils/url.h>
+
+int
+mu_url_set_port (mu_url_t url, unsigned port)
+{
+ char *copy;
+
+ if (!url)
+ return EINVAL;
+ if (port)
+ {
+ char nbuf[128];
+ snprintf (nbuf, sizeof nbuf, "%u", port);
+ copy = strdup (nbuf);
+ if (!copy)
+ return ENOMEM;
+ url->flags |= MU_URL_PORT;
+ }
+ else
+ {
+ copy = NULL;
+ url->flags &= ~MU_URL_PORT;
+ }
+ url->_get_port = NULL;
+ url->_get_portstr = NULL;
+ free (url->portstr);
+ url->port = port;
+ url->portstr = copy;
+ mu_url_invalidate (url);
+ return 0;
+}
+
+
diff --git a/libmailutils/url/set-scheme.c b/libmailutils/url/set-scheme.c
new file mode 100644
index 000000000..2e8ed1307
--- /dev/null
+++ b/libmailutils/url/set-scheme.c
@@ -0,0 +1,58 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+ Copyright (C) 2010 Free Software Foundation, Inc.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 3 of the License, or (at your option) any later version.
+
+ This library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General
+ Public License along with this library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#ifdef HAVE_STRINGS_H
+# include <strings.h>
+#endif
+
+#include <mailutils/types.h>
+#include <mailutils/errno.h>
+#include <mailutils/sys/url.h>
+#include <mailutils/url.h>
+
+int
+mu_url_set_scheme (mu_url_t url, const char *scheme)
+{
+ char *copy;
+
+ if (!url)
+ return EINVAL;
+ if (scheme)
+ {
+ copy = strdup (scheme);
+ if (!copy)
+ return ENOMEM;
+ url->flags |= MU_URL_SCHEME;
+ }
+ else
+ {
+ url->flags &= ~MU_URL_SCHEME;
+ copy = NULL;
+ }
+ free (url->scheme);
+ url->scheme = copy;
+ url->_get_scheme = NULL;
+ mu_url_invalidate (url);
+ return 0;
+}
diff --git a/libmailutils/url/set-secret.c b/libmailutils/url/set-secret.c
new file mode 100644
index 000000000..30af28583
--- /dev/null
+++ b/libmailutils/url/set-secret.c
@@ -0,0 +1,53 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+ Copyright (C) 2010 Free Software Foundation, Inc.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 3 of the License, or (at your option) any later version.
+
+ This library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General
+ Public License along with this library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#ifdef HAVE_STRINGS_H
+# include <strings.h>
+#endif
+
+#include <mailutils/types.h>
+#include <mailutils/errno.h>
+#include <mailutils/sys/url.h>
+#include <mailutils/url.h>
+#include <mailutils/secret.h>
+
+int
+mu_url_set_secret (mu_url_t url, mu_secret_t secret)
+{
+ if (!url)
+ return EINVAL;
+ if (secret)
+ {
+ url->flags |= MU_URL_SECRET;
+ }
+ else
+ {
+ url->flags &= ~MU_URL_SECRET;
+ }
+ mu_secret_destroy (&url->secret);
+ url->secret = secret;
+ url->_get_secret = NULL;
+ mu_url_invalidate (url);
+ return 0;
+}
diff --git a/libmailutils/url/set-service.c b/libmailutils/url/set-service.c
new file mode 100644
index 000000000..f570977ec
--- /dev/null
+++ b/libmailutils/url/set-service.c
@@ -0,0 +1,80 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+ Copyright (C) 2010, 2011 Free Software Foundation, Inc.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 3 of the License, or (at your option) any later version.
+
+ This library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General
+ Public License along with this library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <netdb.h>
+#include <arpa/inet.h>
+#ifdef HAVE_STRINGS_H
+# include <strings.h>
+#endif
+
+#include <mailutils/types.h>
+#include <mailutils/errno.h>
+#include <mailutils/sys/url.h>
+#include <mailutils/url.h>
+
+int
+mu_url_set_service (mu_url_t url, const char *str)
+{
+ unsigned port;
+ char *copy;
+
+ if (!url)
+ return EINVAL;
+ if (str)
+ {
+ unsigned long n;
+ char *p;
+
+ n = strtoul (str, &p, 10);
+ if (*p)
+ {
+ /* FIXME: 1. This assumes MU_URL_PARSE_PORTSRV. */
+ /* FIXME: 2. Another proto? */
+ struct servent *sp = getservbyname (str, "tcp");
+ if (!sp)
+ return MU_ERR_TCP_NO_PORT; /*FIXME: Error code?*/
+ port = ntohs (sp->s_port);
+ }
+ else if (n > USHRT_MAX)
+ return ERANGE;
+
+ copy = strdup (str);
+ if (!copy)
+ return ENOMEM;
+ url->flags |= MU_URL_PORT;
+ }
+ else
+ {
+ copy = NULL;
+ port = 0;
+ url->flags &= ~MU_URL_PORT;
+ }
+ url->_get_port = NULL;
+ url->_get_portstr = NULL;
+ free (url->portstr);
+ url->port = port;
+ url->portstr = copy;
+ mu_url_invalidate (url);
+ return 0;
+}
diff --git a/libmailutils/url/set-user.c b/libmailutils/url/set-user.c
new file mode 100644
index 000000000..8494f4367
--- /dev/null
+++ b/libmailutils/url/set-user.c
@@ -0,0 +1,58 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+ Copyright (C) 2010 Free Software Foundation, Inc.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 3 of the License, or (at your option) any later version.
+
+ This library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General
+ Public License along with this library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#ifdef HAVE_STRINGS_H
+# include <strings.h>
+#endif
+
+#include <mailutils/types.h>
+#include <mailutils/errno.h>
+#include <mailutils/sys/url.h>
+#include <mailutils/url.h>
+
+int
+mu_url_set_user (mu_url_t url, const char *user)
+{
+ char *copy;
+
+ if (!url)
+ return EINVAL;
+ if (user)
+ {
+ copy = strdup (user);
+ if (!copy)
+ return ENOMEM;
+ url->flags |= MU_URL_USER;
+ }
+ else
+ {
+ url->flags &= ~MU_URL_USER;
+ copy = NULL;
+ }
+ free (url->user);
+ url->user = copy;
+ url->_get_user = NULL;
+ mu_url_invalidate (url);
+ return 0;
+}
diff --git a/libmailutils/url/urlinv.c b/libmailutils/url/urlinv.c
new file mode 100644
index 000000000..c4f81131f
--- /dev/null
+++ b/libmailutils/url/urlinv.c
@@ -0,0 +1,33 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+ Copyright (C) 2011 Free Software Foundation, Inc.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 3 of the License, or (at your option) any later version.
+
+ This library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General
+ Public License along with this library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+#include <stdlib.h>
+#include <errno.h>
+#include <mailutils/sys/url.h>
+
+int
+mu_url_invalidate (mu_url_t url)
+{
+ if (!url)
+ return EINVAL;
+ free (url->name);
+ url->name = NULL;
+ return 0;
+}
diff --git a/libmailutils/url/urlstr.c b/libmailutils/url/urlstr.c
index f2faa8194..48a7805e0 100644
--- a/