Initial import.
authormo@ilaven.net <mo@ilaven.net@68b1170a-6346-0410-b79c-01ab32b2924b>
Wed, 19 Nov 2008 14:34:53 +0000 (14:34 +0000)
committermo@ilaven.net <mo@ilaven.net@68b1170a-6346-0410-b79c-01ab32b2924b>
Wed, 19 Nov 2008 14:34:53 +0000 (14:34 +0000)
git-svn-id: http://libiri.googlecode.com/svn/trunk@2 68b1170a-6346-0410-b79c-01ab32b2924b

19 files changed:
.cvsignore [new file with mode: 0644]
LICENSE [new file with mode: 0644]
Makefile.am [new file with mode: 0644]
autogen.sh [new file with mode: 0755]
configure.ac [new file with mode: 0644]
include/.cvsignore [new file with mode: 0644]
include/Makefile.am [new file with mode: 0644]
include/iri.h [new file with mode: 0644]
iri-config/.cvsignore [new file with mode: 0644]
iri-config/Makefile.am [new file with mode: 0644]
iri-config/iri-config.c.in [new file with mode: 0644]
libiri/.cvsignore [new file with mode: 0644]
libiri/Makefile.am [new file with mode: 0644]
libiri/destroy.c [new file with mode: 0644]
libiri/p_libiri.h [new file with mode: 0644]
libiri/parse.c [new file with mode: 0644]
tests/.cvsignore [new file with mode: 0644]
tests/Makefile.am [new file with mode: 0644]
tests/iridump.c [new file with mode: 0644]

diff --git a/.cvsignore b/.cvsignore
new file mode 100644 (file)
index 0000000..0121725
--- /dev/null
@@ -0,0 +1,19 @@
+configure
+Makefile.in
+Makefile
+config.log
+config.guess
+config.sub
+config.h
+config.status
+config.h.in
+autom4te.cache
+missing
+aclocal.m4
+install-sh
+stamp-h1
+depcomp
+ltmain.sh
+libtool
+a.out*
+
diff --git a/LICENSE b/LICENSE
new file mode 100644 (file)
index 0000000..969fa67
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,26 @@
+@(#) $Id$
+
+Copyright (c) 2005, 2008 Mo McRoberts.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+3. The names of the author(s) of this software may not be used to endorse
+   or promote products derived from this software without specific prior
+   written permission.
+
+THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 
+INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 
+AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
+AUTHORS OF THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/Makefile.am b/Makefile.am
new file mode 100644 (file)
index 0000000..1b7763c
--- /dev/null
@@ -0,0 +1,30 @@
+## @(#) $Id$
+
+## Copyright (c) 2008 Mo McRoberts.
+##
+## Redistribution and use in source and binary forms, with or without
+## modification, are permitted provided that the following conditions
+## are met:
+## 1. Redistributions of source code must retain the above copyright
+## notice, this list of conditions and the following disclaimer.
+## 2. Redistributions in binary form must reproduce the above copyright
+## notice, this list of conditions and the following disclaimer in the
+## documentation and/or other materials provided with the distribution.
+## 3. The names of the author(s) of this software may not be used to endorse
+## or promote products derived from this software without specific prior
+## written permission.
+##
+## THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 
+## INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 
+## AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+## AUTHORS OF THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+## TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+## PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
+## LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+## NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
+## SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+SUBDIRS = iri-config include libiri tests
+
+EXTRA_DIST = LICENSE
diff --git a/autogen.sh b/autogen.sh
new file mode 100755 (executable)
index 0000000..c2a493a
--- /dev/null
@@ -0,0 +1,18 @@
+#! /bin/sh
+
+# @(#) $Id$
+
+AUTOHEADER26=${AUTOHEADER26-autoheader26}
+LIBTOOLIZE15=${LIBTOOLIZE15-libtoolize15}
+ACLOCAL110=${ACLOCAL110-aclocal110}
+AUTOMAKE110=${AUTOMAKE110-automake110}
+AUTOCONF26=${AUTOCONF26-autoconf26}
+
+set -x
+
+${AUTOHEADER26}
+${LIBTOOLIZE15} --force --copy --automake
+${ACLOCAL110}
+${AUTOMAKE110} --add-missing --copy
+${AUTOCONF26}
+
diff --git a/configure.ac b/configure.ac
new file mode 100644 (file)
index 0000000..478c653
--- /dev/null
@@ -0,0 +1,73 @@
+dnl @(#) $Id$
+
+dnl Copyright (c) 2005, 2008 Mo McRoberts.
+dnl
+dnl Redistribution and use in source and binary forms, with or without
+dnl modification, are permitted provided that the following conditions
+dnl are met:
+dnl 1. Redistributions of source code must retain the above copyright
+dnl    notice, this list of conditions and the following disclaimer.
+dnl 2. Redistributions in binary form must reproduce the above copyright
+dnl    notice, this list of conditions and the following disclaimer in the
+dnl    documentation and/or other materials provided with the distribution.
+dnl 3. The names of the author(s) of this software may not be used to endorse
+dnl    or promote products derived from this software without specific prior
+dnl    written permission.
+dnl
+dnl THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 
+dnl INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 
+dnl AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
+dnl AUTHORS OF THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+dnl SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+dnl TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+dnl PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
+dnl LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+dnl NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+dnl SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+AC_INIT(libiri, 2.0)
+AC_CONFIG_SRCDIR([include/iri.h])
+AM_INIT_AUTOMAKE([foreign])
+AM_MAINTAINER_MODE
+
+CPPFLAGS="$CPPFLAGS -W -Wall -D_REENTRANT -I\${top_srcdir}/include"
+export CPPFLAGS
+
+CFLAGS="$CFLAGS -g -O0"
+export CFLAGS
+
+AC_PROG_CC
+AC_PROG_LIBTOOL
+
+spfx="${prefix}"
+sepfx="${exec_prefix}"
+test x"${prefix}" = x"NONE" && prefix="${ac_default_prefix}"
+test x"${exec_prefix}" = x"NONE" && exec_prefix="${prefix}"
+
+IRI_VERSION="${VERSION}"
+AC_SUBST([IRI_VERSION])
+
+IRI_CFLAGS="-I`eval echo $includedir`"
+AC_SUBST([IRI_CFLAGS])
+
+IRI_INCLUDES="-I`eval echo $includedir`"
+AC_SUBST([IRI_INCLUDES])
+
+IRI_LIBS="-L`eval echo $libdir` -liri"
+AC_SUBST([IRI_LIBS])
+
+prefix="${spfx}"
+exec_prefix="${sepfx}"
+
+AC_CONFIG_HEADER([config.h])
+
+AC_CONFIG_FILES([Makefile
+include/Makefile
+libiri/Makefile
+iri-config/iri-config.c
+iri-config/Makefile
+tests/Makefile
+])
+
+AC_OUTPUT
+
diff --git a/include/.cvsignore b/include/.cvsignore
new file mode 100644 (file)
index 0000000..33ea420
--- /dev/null
@@ -0,0 +1,11 @@
+.deps
+.libs
+Makefile
+Makefile.in
+*.la
+*.lo
+*.so
+*.a
+*.dll
+*.exe
+*.o
diff --git a/include/Makefile.am b/include/Makefile.am
new file mode 100644 (file)
index 0000000..9f31fb4
--- /dev/null
@@ -0,0 +1,28 @@
+## @(#) $Id$
+
+## Copyright (c) 2008 Mo McRoberts.
+##
+## Redistribution and use in source and binary forms, with or without
+## modification, are permitted provided that the following conditions
+## are met:
+## 1. Redistributions of source code must retain the above copyright
+## notice, this list of conditions and the following disclaimer.
+## 2. Redistributions in binary form must reproduce the above copyright
+## notice, this list of conditions and the following disclaimer in the
+## documentation and/or other materials provided with the distribution.
+## 3. The names of the author(s) of this software may not be used to endorse
+## or promote products derived from this software without specific prior
+## written permission.
+##
+## THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 
+## INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 
+## AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+## AUTHORS OF THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+## TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+## PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
+## LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+## NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
+## SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+include_HEADERS = iri.h
diff --git a/include/iri.h b/include/iri.h
new file mode 100644 (file)
index 0000000..16aebf4
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2005, 2008 Mo McRoberts.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The names of the author(s) of this software may not be used to endorse
+ * or promote products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * AUTHORS OF THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef IRI_H_
+# define IRI_H_                        1
+
+typedef struct iri_struct iri_t;
+
+struct iri_struct
+{
+       void *_private;
+       const char *scheme;
+       const char *user;
+       const char *auth;
+       const char *host;
+       int port;
+       const char *path;
+       const char *query;
+       const char *anchor;
+       const char **params;
+};
+
+# undef EXTERNC_
+# if defined(__cplusplus)
+#  define EXTERNC_                     extern "C"
+# else
+#  define EXTERNC_                     extern
+# endif
+
+EXTERNC_ iri_t *iri_parse(const char *src);
+EXTERNC_ void iri_destroy(iri_t *iri);
+
+#endif /* !IRI_H_ */
diff --git a/iri-config/.cvsignore b/iri-config/.cvsignore
new file mode 100644 (file)
index 0000000..76c9f5a
--- /dev/null
@@ -0,0 +1,14 @@
+.deps
+.libs
+Makefile
+Makefile.in
+*.la
+*.lo
+*.so
+*.a
+*.dll
+*.exe
+*.o
+iri-config
+iri-config.c
+
diff --git a/iri-config/Makefile.am b/iri-config/Makefile.am
new file mode 100644 (file)
index 0000000..b3648c5
--- /dev/null
@@ -0,0 +1,6 @@
+
+EXTRA_DIST = iri-config.c.in
+
+bin_PROGRAMS = iri-config
+
+iri_config_SOURCES = iri-config.c
diff --git a/iri-config/iri-config.c.in b/iri-config/iri-config.c.in
new file mode 100644 (file)
index 0000000..e89800b
--- /dev/null
@@ -0,0 +1,106 @@
+/*
+ * Copyright (c) 2005, 2008 Mo McRoberts.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The names of the author(s) of this software may not be used to endorse
+ * or promote products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * AUTHORS OF THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+static struct
+{
+       const char *key;
+       const char *value;
+} pairs[] = 
+{
+       { "cflags", "@IRI_CFLAGS@" },
+       { "include", "@IRI_INCLUDES@" },
+       { "libs", "@IRI_LIBS@" },
+       { "version", "@IRI_VERSION@" },
+       { NULL, NULL }
+};
+
+static void
+usage(int status)
+{
+       int d;
+       
+       puts("Usage: @bindir@/iri-config [OPTIONS]");
+       puts("Options:");
+       for(d = 0; NULL != pairs[d].key; d++)
+       {
+               printf("\t--%-14s [%s]\n", pairs[d].key, pairs[d].value);
+       }
+       exit(status);
+}
+
+int
+main(int argc, char **argv)
+{
+       int c, d;
+       
+       if(argc < 2)
+       {
+               usage(EXIT_SUCCESS);
+       }
+       for(c = 1 ; c < argc; c++)
+       {
+               if(argv[c][0] == '-' && argv[c][1] == '-')
+               {
+                       for(d = 0; NULL != pairs[d].key; d++)
+                       {
+                               if(0 == strcmp(&(argv[c][2]), pairs[d].key))
+                               {
+                                       break;
+                               }
+                       }
+                       if(NULL == pairs[d].key)
+                       {
+                               usage(EXIT_FAILURE);
+                       }
+               }
+               else
+               {
+                       usage(EXIT_FAILURE);
+               }
+       }
+       for(c = 1 ; c < argc; c++)
+       {
+               for(d = 0; NULL != pairs[d].key; d++)
+               {
+                       if(0 == strcmp(&(argv[c][2]), pairs[d].key))
+                       {
+                               printf("%s\n", pairs[d].value);
+                               break;
+                       }
+               }
+       }
+       return 0;
+}
diff --git a/libiri/.cvsignore b/libiri/.cvsignore
new file mode 100644 (file)
index 0000000..33ea420
--- /dev/null
@@ -0,0 +1,11 @@
+.deps
+.libs
+Makefile
+Makefile.in
+*.la
+*.lo
+*.so
+*.a
+*.dll
+*.exe
+*.o
diff --git a/libiri/Makefile.am b/libiri/Makefile.am
new file mode 100644 (file)
index 0000000..056f50c
--- /dev/null
@@ -0,0 +1,35 @@
+## @(#) $Id$
+
+## Copyright (c) 2008 Mo McRoberts.
+##
+## Redistribution and use in source and binary forms, with or without
+## modification, are permitted provided that the following conditions
+## are met:
+## 1. Redistributions of source code must retain the above copyright
+## notice, this list of conditions and the following disclaimer.
+## 2. Redistributions in binary form must reproduce the above copyright
+## notice, this list of conditions and the following disclaimer in the
+## documentation and/or other materials provided with the distribution.
+## 3. The names of the author(s) of this software may not be used to endorse
+## or promote products derived from this software without specific prior
+## written permission.
+##
+## THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 
+## INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 
+## AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+## AUTHORS OF THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+## TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+## PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
+## LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+## NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
+## SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+lib_LTLIBRARIES = libiri.la
+
+libiri_la_LDFLAGS = -avoid-version
+
+libiri_la_SOURCES = \
+       p_libiri.h \
+       parse.c destroy.c
+
diff --git a/libiri/destroy.c b/libiri/destroy.c
new file mode 100644 (file)
index 0000000..72f480f
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2005, 2008 Mo McRoberts.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The names of the author(s) of this software may not be used to endorse
+ * or promote products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * AUTHORS OF THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "p_libiri.h"
+
+void
+iri_destroy(iri_t *iri)
+{
+       if(NULL != iri)
+       {
+               free(iri->_private);
+               free(iri);
+       }
+}
diff --git a/libiri/p_libiri.h b/libiri/p_libiri.h
new file mode 100644 (file)
index 0000000..0d2202b
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2005, 2008 Mo McRoberts.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The names of the author(s) of this software may not be used to endorse
+ * or promote products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * AUTHORS OF THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef P_LIBIRI_H_
+# define P_LIBIRI_H_                   1
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "iri.h"
+
+#endif /* !P_LIBIRI_H_ */
\ No newline at end of file
diff --git a/libiri/parse.c b/libiri/parse.c
new file mode 100644 (file)
index 0000000..3020b91
--- /dev/null
@@ -0,0 +1,224 @@
+/*
+ * Copyright (c) 2005, 2008 Mo McRoberts.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The names of the author(s) of this software may not be used to endorse
+ * or promote products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * AUTHORS OF THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "p_libiri.h"
+
+static inline const char *
+iri__copychar_decode(char **dest, const char *src)
+{
+       **dest = *src;
+       src++;
+       (*dest)++;
+       return src;
+}
+
+static inline char *
+iri__allocbuf(const char *src)
+{
+       /* Calculate the size of the buffer required to hold a decoded version of
+        * src, including enough breathing space for null bytes.
+        */
+       /* XXX: This is way too much; we need to actually count it */
+       return (char *) calloc(1, (strlen(src) * 4) + 16);
+}
+
+iri_t *
+iri_parse(const char *src)
+{
+       iri_t *p;
+       char *bufstart, *endp, *bufp;
+       const char *at, *colon, *slash;
+       
+       if(NULL == (p = (iri_t *) calloc(1, sizeof(iri_t))))
+       {
+               return NULL;
+       }
+       if(NULL == (bufstart = iri__allocbuf(src)))
+       {
+               free(p);
+               return NULL;
+       }
+       p->_private = bufp = bufstart;
+       at = strchr(src, '@');
+       slash = strchr(src, '/');
+       colon = strchr(src, ':');
+       if(slash && colon && slash < colon)
+       {
+               /* We can disregard the colon if a slash appears before it */
+               colon = NULL;
+       }
+       if(colon && !at)
+       {
+               /* Definitely a scheme */
+               p->scheme = bufp;
+               while(*src && *src != ':')
+               {
+                       src = iri__copychar_decode(&bufp, src);
+               }
+               *bufp = 0;
+               bufp++;
+               src++;
+               /* src[0-1] SHOULD == '/' */
+               for(; *src == '/'; src++);
+       }
+       else if(colon && at && colon < at)
+       {
+               /* This could be scheme://user[:auth]@host or [scheme:]user[:auth]@host (urgh) */
+               if(colon[1] == '/')
+               {
+                       p->scheme = bufp;
+                       while(*src && *src != ':')
+                       {
+                               src = iri__copychar_decode(&bufp, src);
+                       }
+                       *bufp = 0;
+                       bufp++;
+                       src++;
+                       /* src[0-1] SHOULD == '/' */
+                       for(; *src == '/'; src++);
+                       p->user = bufp;
+               }
+               else
+               {
+                       p->scheme = bufp;
+               }
+               while(*src && *src != ':' && *src != '@')
+               {
+                       src = iri__copychar_decode(&bufp, src);
+               }
+               *bufp = 0;
+               bufp++;
+               if(*src == ':')
+               {
+                       /* Following auth data */
+                       src++;
+                       p->auth = bufp;
+                       while(*src && *src != ':' && *src != '@')
+                       {
+                               src = iri__copychar_decode(&bufp, src);
+                       }
+                       *bufp = 0;
+                       bufp++;
+                       if(*src == ':')
+                       {
+                               src++;
+                               /* It was actually scheme:user:auth@host */
+                               p->user = p->auth;
+                               p->auth = bufp;
+                               while(*src && *src != '@')
+                               {
+                                       src = iri__copychar_decode(&bufp, src);
+                               }
+                               *bufp = 0;
+                               bufp++;
+                       }
+               }
+               if(!*src)
+               {
+                       /* No host part */
+                       return p;
+               }
+               if(*src == '@')
+               {
+                       src++;
+               }
+       }
+       else if(at)
+       {
+               /* user@host[/path...] */
+               p->user = bufp;
+               while(*src != '@')
+               {
+                       src = iri__copychar_decode(&bufp, src);
+               }
+               *bufp = 0;
+               bufp++;
+               src++;
+       }
+       p->host = bufp;
+       while(*src && *src != ':' && *src != '/' && *src != '?' && *src != '#')
+       {
+               src = iri__copychar_decode(&bufp, src);
+       }
+       *bufp = 0;
+       bufp++;
+       if(*src == ':')
+       {
+               /* Port part */
+               src++;
+               endp = (char *) src;
+               p->port = strtol(src, &endp, 10);
+               src = endp;
+       }
+       if(*src == '/')
+       {
+               p->path = bufp; 
+               while(*src && *src != '?' && *src != '#')
+               {
+                       src = iri__copychar_decode(&bufp, src);
+               }
+               *bufp = 0;
+               bufp++;
+       }
+       if(*src == '?')
+       {
+               p->query = bufp; 
+               src++;
+               while(*src && *src != '#')
+               {
+                       src = iri__copychar_decode(&bufp, src);
+               }
+               *bufp = 0;
+               bufp++;
+       }
+       if(*src == '#')
+       {
+               p->anchor = bufp; 
+               while(*src)
+               {
+                       src = iri__copychar_decode(&bufp, src);
+               }
+               *bufp = 0;
+               bufp++;
+       }
+       if(*src)
+       {
+               /* Still stuff left? It must be a path... of sorts */
+               p->path = bufp; 
+               while(*src && *src != '?' && *src != '#')
+               {
+                       src = iri__copychar_decode(&bufp, src);
+               }
+               *bufp = 0;
+               bufp++;
+       }
+       return p;
+}
diff --git a/tests/.cvsignore b/tests/.cvsignore
new file mode 100644 (file)
index 0000000..4c55c0d
--- /dev/null
@@ -0,0 +1,13 @@
+.deps
+.libs
+Makefile
+Makefile.in
+*.la
+*.lo
+*.so
+*.a
+*.dll
+*.exe
+*.o
+iridump
+
diff --git a/tests/Makefile.am b/tests/Makefile.am
new file mode 100644 (file)
index 0000000..c8fc4c4
--- /dev/null
@@ -0,0 +1,31 @@
+## @(#) $Id$
+
+## Copyright (c) 2008 Mo McRoberts.
+##
+## Redistribution and use in source and binary forms, with or without
+## modification, are permitted provided that the following conditions
+## are met:
+## 1. Redistributions of source code must retain the above copyright
+## notice, this list of conditions and the following disclaimer.
+## 2. Redistributions in binary form must reproduce the above copyright
+## notice, this list of conditions and the following disclaimer in the
+## documentation and/or other materials provided with the distribution.
+## 3. The names of the author(s) of this software may not be used to endorse
+## or promote products derived from this software without specific prior
+## written permission.
+##
+## THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 
+## INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 
+## AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+## AUTHORS OF THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+## TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+## PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
+## LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+## NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
+## SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+noinst_PROGRAMS = iridump
+
+iridump_SOURCES = iridump.c
+iridump_LDADD = ../libiri/libiri.la
diff --git a/tests/iridump.c b/tests/iridump.c
new file mode 100644 (file)
index 0000000..ab02bb9
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2005, 2008 Mo McRoberts.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The names of the author(s) of this software may not be used to endorse
+ * or promote products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * AUTHORS OF THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "iri.h"
+
+int
+main(int argc, char **argv)
+{
+       iri_t *iri;
+
+       if(argc != 2)
+       {
+               fprintf(stderr, "Usage: %s IRI\n", argv[0]);
+               exit(EXIT_FAILURE);
+       }
+       iri = iri_parse(argv[1]);
+       printf("scheme: %s\n", iri->scheme);
+       printf("  user: %s\n", iri->user);
+       printf("  auth: %s\n", iri->auth);
+       printf("  host: %s\n", iri->host);
+       printf("  port: %d\n", iri->port);
+       printf("  path: %s\n", iri->path);
+       printf(" query: %s\n", iri->query);
+       printf("anchor: %s\n", iri->anchor);
+       return 0;
+}