]> granicus.if.org Git - p11-kit/commitdiff
Documentation and API cleanup.
authorStef Walter <stefw@collabora.co.uk>
Thu, 31 Mar 2011 10:41:43 +0000 (12:41 +0200)
committerStef Walter <stefw@collabora.co.uk>
Thu, 31 Mar 2011 10:41:43 +0000 (12:41 +0200)
 * Rename source directory
 * More consistent with return values from URI functions.
 * Allow formatting URI to take a uri type.

28 files changed:
.gitignore
Makefile.am
configure.ac
doc/Makefile.am
doc/p11-kit-docs.sgml [new file with mode: 0644]
doc/p11-kit-overrides.txt [new file with mode: 0644]
doc/p11-kit-sections.txt [new file with mode: 0644]
doc/version.xml.in [new file with mode: 0644]
gtk-doc.make [new file with mode: 0644]
p11-kit/Makefile.am [moved from module/Makefile.am with 99% similarity]
p11-kit/conf.c [moved from module/conf.c with 100% similarity]
p11-kit/conf.h [moved from module/conf.h with 100% similarity]
p11-kit/hash.c [moved from module/hash.c with 99% similarity]
p11-kit/hash.h [moved from module/hash.h with 100% similarity]
p11-kit/p11-kit-lib.c [moved from module/p11-kit-lib.c with 86% similarity]
p11-kit/p11-kit-messages.c [moved from module/p11-kit-messages.c with 96% similarity]
p11-kit/p11-kit-private.h [moved from module/p11-kit-private.h with 100% similarity]
p11-kit/p11-kit-proxy.c [moved from module/p11-kit-proxy.c with 100% similarity]
p11-kit/p11-kit-uri.c [moved from module/p11-kit-uri.c with 62% similarity]
p11-kit/p11-kit-uri.h [moved from module/p11-kit-uri.h with 89% similarity]
p11-kit/p11-kit.h [moved from module/p11-kit.h with 100% similarity]
p11-kit/p11-kit.pc [new file with mode: 0644]
p11-kit/p11-kit.pc.in [moved from module/p11-kit.pc.in with 100% similarity]
p11-kit/pkcs11.h [moved from module/pkcs11.h with 100% similarity]
p11-kit/util.c [moved from module/util.c with 100% similarity]
p11-kit/util.h [moved from module/util.h with 100% similarity]
tests/Makefile.am
tests/uri-test.c

index 75498598e6c128611dd254e5d080dd6054d2d8fb..f2047de28c9edd13edf555d63faf6675b2e66664 100644 (file)
@@ -7,6 +7,7 @@
 *.gcov
 *~
 *.html
+*.stamp
 
 .deps
 .libs
@@ -38,6 +39,22 @@ missing
 stamp-h1
 temp.txt
 
+/doc/html
+/doc/p11-kit-decl-list.txt
+/doc/p11-kit-decl.txt
+/doc/p11-kit-undeclared.txt
+/doc/p11-kit-undocumented.txt
+/doc/p11-kit-unused.txt
+/doc/p11-kit.args
+/doc/p11-kit.hierarchy
+/doc/p11-kit.interfaces
+/doc/p11-kit.prerequisites
+/doc/p11-kit.signals
+/doc/p11-kit.types
+/doc/tmpl/
+/doc/version.xml
+/doc/xml/
+
 /module/p11-kit.pc
 
 /po/POTFILES
index e8f0c0cd08078d1c538b0e74ca6bfffa1df31be2..811b752dbc4d2be40ff48b63eff9543b779a6c47 100644 (file)
@@ -1,5 +1,9 @@
 
-SUBDIRS = module tests doc po
+SUBDIRS = \
+       p11-kit \
+       tests \
+       doc \
+       po
 
 ACLOCAL_AMFLAGS = -I m4
 
index 9f63f66f8fdfd0de57508796006a92085a9e55b8..a10790b88cd379c845eb8995e7ff7d3bc1f9bd4b 100644 (file)
@@ -3,7 +3,7 @@ AC_CONFIG_MACRO_DIR([m4])
 
 AC_INIT([p11-kit],[0.1],[http://bugzilla.example.com])
 
-AC_CONFIG_SRCDIR([module/p11-kit-lib.c])
+AC_CONFIG_SRCDIR([p11-kit/p11-kit-lib.c])
 AC_CONFIG_HEADERS([config.h])
 
 dnl Other initialization
@@ -31,6 +31,8 @@ AC_CHECK_LIB(dl, dlopen,,
 dnl Checks for typedefs, structures, and compiler characteristics.
 AC_CHECK_MEMBERS([struct dirent.d_type],,,[#include <dirent.h>])
 
+GTK_DOC_CHECK([1.15])
+
 # --------------------------------------------------------------------
 # PKCS#11 Directories
 
@@ -134,11 +136,12 @@ fi
 # ---------------------------------------------------------------------
 
 AC_CONFIG_FILES([Makefile
-               module/Makefile
-               module/p11-kit.pc
-               po/Makefile.in
-               tests/Makefile
-               doc/Makefile
-               ])
+       doc/Makefile
+       doc/version.xml
+       po/Makefile.in
+       p11-kit/Makefile
+       p11-kit/p11-kit.pc
+       tests/Makefile
+])
 AC_OUTPUT
 
index 52c269b9cf40f869fd06fcd9a033d268fe7c9fcd..b18d86a99725c7f020f1a90321d6d17f16a767c8 100644 (file)
@@ -1,22 +1,72 @@
+abs_top_builddir = @abs_top_builddir@
 
-#      p11-kit-glue.xml
+# We require automake 1.6 at least.
+AUTOMAKE_OPTIONS = 1.6
 
-PARTS = \
-       p11-kit-config.xml \
-       p11-kit-multiple-problem.xml
+# The name of the module, e.g. 'glib'.
+DOC_MODULE=p11-kit
 
-BOOK = \
-       p11-kit.xml
+# The top-level SGML file. You can change this if you want to.
+DOC_MAIN_SGML_FILE=$(DOC_MODULE)-docs.sgml
 
-DOCUMENTS = \
-       html/p11-kit.html
+# The directory containing the source code. Relative to $(srcdir).
+# gtk-doc will search all .c & .h files beneath here for inline comments
+# documenting the functions and macros.
+# e.g. DOC_SOURCE_DIR=../../../gtk
+DOC_SOURCE_DIR=../p11-kit
 
-all-local: $(DOCUMENTS)
+# Extra options to pass to gtkdoc-scangobj. Not normally needed.
+SCANGOBJ_OPTIONS= --version
 
-html/p11-kit.html: $(BOOK) $(PARTS)
-       xmlto --skip-validation -vv html-nochunks -o html/ p11-kit.xml
+# Extra options to supply to gtkdoc-scan.
+# e.g. SCAN_OPTIONS=--deprecated-guards="GTK_DISABLE_DEPRECATED"
+SCAN_OPTIONS= --rebuild-types
 
-EXTRA_DIST = \
-       $(BOOK) \
-       $(PARTS) \
-       docbook-params.xsl
+# Extra options to supply to gtkdoc-mkdb.
+# e.g. MKDB_OPTIONS=--sgml-mode --output-format=xml
+MKDB_OPTIONS=--sgml-mode --output-format=xml
+
+# Extra options to supply to gtkdoc-mktmpl
+# e.g. MKTMPL_OPTIONS=--only-section-tmpl
+MKTMPL_OPTIONS=
+
+# Extra options to supply to gtkdoc-fixref. Not normally needed.
+# e.g. FIXXREF_OPTIONS=--extra-dir=../gdk-pixbuf/html --extra-dir=../gdk/html
+FIXXREF_OPTIONS=
+
+# Used for dependencies. The docs will be rebuilt if any of these change.
+# e.g. HFILE_GLOB=$(top_srcdir)/gtk/*.h
+# e.g. CFILE_GLOB=$(top_srcdir)/gtk/*.c
+HFILE_GLOB=$(top_srcdir)/p11-kit/p11-kit-*.h
+CFILE_GLOB=$(top_srcdir)/p11-kit/p11-kit-*.c
+
+# Header files to ignore when scanning.
+# e.g. IGNORE_HFILES=gtkdebug.h gtkintl.h
+IGNORE_HFILES= p11-kit-private.h pkcs11.h hash.h conf.h util.h
+
+# Images to copy into HTML directory.
+# e.g. HTML_IMAGES=$(top_srcdir)/gtk/stock-icons/stock_about_24.png
+HTML_IMAGES=
+
+# Extra SGML files that are included by $(DOC_MAIN_SGML_FILE).
+# e.g. content_files=running.sgml building.sgml changes-2.0.sgml
+content_files=p11-kit-config.xml p11-kit-multiple-problem.xml
+
+# SGML files where gtk-doc abbrevations (#GtkWidget) are expanded
+# These files must be listed here *and* in content_files
+# e.g. expand_content_files=running.sgml
+expand_content_files=
+
+# CFLAGS and LDFLAGS for compiling gtkdoc-scangobj with your library.
+# Only needed if you are using gtkdoc-scangobj to dynamically query widget
+# signals and properties.
+# e.g. INCLUDES=-I$(top_srcdir) -I$(top_builddir) $(GTK_DEBUG_FLAGS)
+# e.g. GTKDOC_LIBS=$(top_builddir)/gtk/$(gtktargetlib)
+INCLUDES=
+GTKDOC_LIBS=
+
+# This includes the standard gtk-doc make rules, copied by gtkdocize.
+include $(top_srcdir)/gtk-doc.make
+
+EXTRA_DIST += \
+       version.xml.in
diff --git a/doc/p11-kit-docs.sgml b/doc/p11-kit-docs.sgml
new file mode 100644 (file)
index 0000000..03fd582
--- /dev/null
@@ -0,0 +1,24 @@
+<?xml version="1.0"?>
+<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
+               "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd"
+[
+  <!ENTITY % local.common.attrib "xmlns:xi  CDATA  #FIXED 'http://www.w3.org/2003/XInclude'">
+  <!ENTITY version SYSTEM "version.xml">
+]>
+<book id="index">
+       <bookinfo>
+               <title>P11-Kit Manual</title>
+               <releaseinfo>for p11-kit &version;</releaseinfo>
+       </bookinfo>
+
+       <chapter>
+               <title>Reference</title>
+               <xi:include href="xml/p11-kit.xml"/>
+               <xi:include href="xml/p11-kit-uri.xml"/>
+               <xi:include href="xml/p11-kit-util.xml"/>
+               <index id="api-index-full">
+                       <title>API Index</title>
+                       <xi:include href="xml/api-index-full.xml"><xi:fallback /></xi:include>
+               </index>
+       </chapter>
+</book>
diff --git a/doc/p11-kit-overrides.txt b/doc/p11-kit-overrides.txt
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/doc/p11-kit-sections.txt b/doc/p11-kit-sections.txt
new file mode 100644 (file)
index 0000000..fbe7452
--- /dev/null
@@ -0,0 +1,40 @@
+<SECTION>
+<FILE>p11-kit-uri</FILE>
+P11_KIT_URI_SCHEME
+P11_KIT_URI_SCHEME_LEN
+P11KitUriType
+P11KitUriResult
+P11KitUri
+p11_kit_uri_new
+p11_kit_uri_get_module_info
+p11_kit_uri_match_module_info
+p11_kit_uri_get_token_info
+p11_kit_uri_match_token_info
+p11_kit_uri_get_attribute_types
+p11_kit_uri_get_attribute
+p11_kit_uri_set_attribute
+p11_kit_uri_clear_attribute
+p11_kit_uri_match_attributes
+p11_kit_uri_set_unrecognized
+p11_kit_uri_any_unrecognized
+p11_kit_uri_format
+p11_kit_uri_parse
+p11_kit_uri_free
+</SECTION>
+
+<SECTION>
+<FILE>p11-kit</FILE>
+p11_kit_initialize_registered
+p11_kit_finalize_registered
+p11_kit_registered_modules
+p11_kit_registered_module_to_name
+p11_kit_registered_name_to_module
+p11_kit_registered_option
+p11_kit_initialize_module
+p11_kit_finalize_module
+</SECTION>
+
+<SECTION>
+<FILE>p11-kit-util</FILE>
+p11_kit_strerror
+</SECTION>
\ No newline at end of file
diff --git a/doc/version.xml.in b/doc/version.xml.in
new file mode 100644 (file)
index 0000000..27323da
--- /dev/null
@@ -0,0 +1 @@
+@VERSION@
\ No newline at end of file
diff --git a/gtk-doc.make b/gtk-doc.make
new file mode 100644 (file)
index 0000000..a97578b
--- /dev/null
@@ -0,0 +1,230 @@
+# -*- mode: makefile -*-
+
+####################################
+# Everything below here is generic #
+####################################
+
+if GTK_DOC_USE_LIBTOOL
+GTKDOC_CC = $(LIBTOOL) --tag=CC --mode=compile $(CC) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+GTKDOC_LD = $(LIBTOOL) --tag=CC --mode=link $(CC) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS)
+GTKDOC_RUN = $(LIBTOOL) --mode=execute
+else
+GTKDOC_CC = $(CC) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+GTKDOC_LD = $(CC) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS)
+GTKDOC_RUN =
+endif
+
+# We set GPATH here; this gives us semantics for GNU make
+# which are more like other make's VPATH, when it comes to
+# whether a source that is a target of one rule is then
+# searched for in VPATH/GPATH.
+#
+GPATH = $(srcdir)
+
+TARGET_DIR=$(HTML_DIR)/$(DOC_MODULE)
+
+EXTRA_DIST =                           \
+       $(content_files)                \
+       $(HTML_IMAGES)                  \
+       $(DOC_MAIN_SGML_FILE)           \
+       $(DOC_MODULE)-sections.txt      \
+       $(DOC_MODULE)-overrides.txt
+
+DOC_STAMPS=scan-build.stamp tmpl-build.stamp sgml-build.stamp html-build.stamp \
+       pdf-build.stamp \
+       $(srcdir)/tmpl.stamp $(srcdir)/sgml.stamp $(srcdir)/html.stamp \
+       $(srcdir)/pdf.stamp
+
+SCANOBJ_FILES =                 \
+       $(DOC_MODULE).args       \
+       $(DOC_MODULE).hierarchy  \
+       $(DOC_MODULE).interfaces \
+       $(DOC_MODULE).prerequisites \
+       $(DOC_MODULE).signals
+
+REPORT_FILES = \
+       $(DOC_MODULE)-undocumented.txt \
+       $(DOC_MODULE)-undeclared.txt \
+       $(DOC_MODULE)-unused.txt
+
+CLEANFILES = $(SCANOBJ_FILES) $(REPORT_FILES) $(DOC_STAMPS)
+
+if ENABLE_GTK_DOC
+if GTK_DOC_BUILD_HTML
+HTML_BUILD_STAMP=html-build.stamp
+else
+HTML_BUILD_STAMP=
+endif
+if GTK_DOC_BUILD_PDF
+PDF_BUILD_STAMP=pdf-build.stamp
+else
+PDF_BUILD_STAMP=
+endif
+
+all-local: $(HTML_BUILD_STAMP) $(PDF_BUILD_STAMP)
+else
+all-local:
+endif
+
+docs: $(HTML_BUILD_STAMP) $(PDF_BUILD_STAMP)
+
+$(REPORT_FILES): sgml-build.stamp
+
+#### scan ####
+
+scan-build.stamp: $(HFILE_GLOB) $(CFILE_GLOB)
+       @echo 'gtk-doc: Scanning header files'
+       @-chmod -R u+w $(srcdir)
+       @_source_dir='' ; for i in $(DOC_SOURCE_DIR) ; do \
+           _source_dir="$${_source_dir} --source-dir=$$i" ; \
+         done ; \
+         cd $(srcdir) && \
+         gtkdoc-scan --module=$(DOC_MODULE) --ignore-headers="$(IGNORE_HFILES)" $${_source_dir} $(SCAN_OPTIONS) $(EXTRA_HFILES)
+       @if grep -l '^..*$$' $(srcdir)/$(DOC_MODULE).types > /dev/null 2>&1 ; then \
+           CC="$(GTKDOC_CC)" LD="$(GTKDOC_LD)" RUN="$(GTKDOC_RUN)" CFLAGS="$(GTKDOC_CFLAGS) $(CFLAGS)" LDFLAGS="$(GTKDOC_LIBS) $(LDFLAGS)" gtkdoc-scangobj $(SCANGOBJ_OPTIONS) --module=$(DOC_MODULE) --output-dir=$(srcdir) ; \
+       else \
+           cd $(srcdir) ; \
+           for i in $(SCANOBJ_FILES) ; do \
+               test -f $$i || touch $$i ; \
+           done \
+       fi
+       @touch scan-build.stamp
+
+$(DOC_MODULE)-decl.txt $(SCANOBJ_FILES) $(DOC_MODULE)-sections.txt $(DOC_MODULE)-overrides.txt: scan-build.stamp
+       @true
+
+#### templates ####
+
+tmpl-build.stamp: $(DOC_MODULE)-decl.txt $(SCANOBJ_FILES) $(DOC_MODULE)-sections.txt $(DOC_MODULE)-overrides.txt
+       @echo 'gtk-doc: Rebuilding template files'
+       @-chmod -R u+w $(srcdir)
+       @cd $(srcdir) && gtkdoc-mktmpl --module=$(DOC_MODULE) $(MKTMPL_OPTIONS)
+       @touch tmpl-build.stamp
+
+tmpl.stamp: tmpl-build.stamp
+       @true
+
+$(srcdir)/tmpl/*.sgml:
+       @true
+
+#### xml ####
+
+sgml-build.stamp: tmpl.stamp $(DOC_MODULE)-sections.txt $(srcdir)/tmpl/*.sgml $(expand_content_files)
+       @echo 'gtk-doc: Building XML'
+       @-chmod -R u+w $(srcdir)
+       @_source_dir='' ; for i in $(DOC_SOURCE_DIR) ; do \
+           _source_dir="$${_source_dir} --source-dir=$$i" ; \
+         done ; \
+         cd $(srcdir) && \
+         gtkdoc-mkdb --module=$(DOC_MODULE) --output-format=xml --expand-content-files="$(expand_content_files)" --main-sgml-file=$(DOC_MAIN_SGML_FILE) $${_source_dir} $(MKDB_OPTIONS)
+       @touch sgml-build.stamp
+
+sgml.stamp: sgml-build.stamp
+       @true
+
+#### html ####
+
+html-build.stamp: sgml.stamp $(DOC_MAIN_SGML_FILE) $(content_files)
+       @echo 'gtk-doc: Building HTML'
+       @-chmod -R u+w $(srcdir)
+       @rm -rf $(srcdir)/html
+       @mkdir $(srcdir)/html
+       @mkhtml_options=""; \
+       gtkdoc-mkhtml 2>&1 --help | grep  >/dev/null "\-\-path"; \
+       if test "$(?)" = "0"; then \
+         mkhtml_options=--path="$(srcdir)"; \
+       fi; \
+       cd $(srcdir)/html && gtkdoc-mkhtml $$mkhtml_options $(MKHTML_OPTIONS) $(DOC_MODULE) ../$(DOC_MAIN_SGML_FILE)
+       @test "x$(HTML_IMAGES)" = "x" || ( cd $(srcdir) && cp $(HTML_IMAGES) html )
+       @echo 'gtk-doc: Fixing cross-references'
+       @cd $(srcdir) && gtkdoc-fixxref --module=$(DOC_MODULE) --module-dir=html --html-dir=$(HTML_DIR) $(FIXXREF_OPTIONS) | grep -v "no link for.*CK-.*CAPS" || true
+       @touch html-build.stamp
+
+#### pdf ####
+
+pdf-build.stamp: sgml.stamp $(DOC_MAIN_SGML_FILE) $(content_files)
+       @echo 'gtk-doc: Building PDF'
+       @-chmod -R u+w $(srcdir)
+       @rm -rf $(srcdir)/$(DOC_MODULE).pdf
+       @mkpdf_imgdirs=""; \
+       if test "x$(HTML_IMAGES)" != "x"; then \
+         for img in $(HTML_IMAGES); do \
+           part=`dirname $$img`; \
+           echo $$mkpdf_imgdirs | grep >/dev/null "\-\-imgdir=$$part "; \
+           if test $$? != 0; then \
+             mkpdf_imgdirs="$$mkpdf_imgdirs --imgdir=$$part"; \
+           fi; \
+         done; \
+       fi; \
+       cd $(srcdir) && gtkdoc-mkpdf --path="$(abs_srcdir)" $$mkpdf_imgdirs $(DOC_MODULE) $(DOC_MAIN_SGML_FILE) $(MKPDF_OPTIONS)
+       @touch pdf-build.stamp
+
+##############
+
+clean-local:
+       rm -f *~ *.bak
+       rm -rf .libs
+
+distclean-local:
+       cd $(srcdir) && \
+         rm -rf xml $(REPORT_FILES) $(DOC_MODULE).pdf \
+                $(DOC_MODULE)-decl-list.txt $(DOC_MODULE)-decl.txt
+
+maintainer-clean-local: clean
+       cd $(srcdir) && rm -rf xml html
+
+install-data-local:
+       @installfiles=`echo $(srcdir)/html/*`; \
+       if test "$$installfiles" = '$(srcdir)/html/*'; \
+       then echo '-- Nothing to install' ; \
+       else \
+         if test -n "$(DOC_MODULE_VERSION)"; then \
+           installdir="$(DESTDIR)$(TARGET_DIR)-$(DOC_MODULE_VERSION)"; \
+         else \
+           installdir="$(DESTDIR)$(TARGET_DIR)"; \
+         fi; \
+         $(mkinstalldirs) $${installdir} ; \
+         for i in $$installfiles; do \
+           echo '-- Installing '$$i ; \
+           $(INSTALL_DATA) $$i $${installdir}; \
+         done; \
+         if test -n "$(DOC_MODULE_VERSION)"; then \
+           mv -f $${installdir}/$(DOC_MODULE).devhelp2 \
+             $${installdir}/$(DOC_MODULE)-$(DOC_MODULE_VERSION).devhelp2; \
+           mv -f $${installdir}/$(DOC_MODULE).devhelp \
+             $${installdir}/$(DOC_MODULE)-$(DOC_MODULE_VERSION).devhelp; \
+         fi; \
+         $(GTKDOC_REBASE) --relative --dest-dir=$(DESTDIR) --html-dir=$${installdir}; \
+       fi
+
+uninstall-local:
+       @if test -n "$(DOC_MODULE_VERSION)"; then \
+         installdir="$(DESTDIR)$(TARGET_DIR)-$(DOC_MODULE_VERSION)"; \
+       else \
+         installdir="$(DESTDIR)$(TARGET_DIR)"; \
+       fi; \
+       rm -rf $${installdir}
+
+#
+# Require gtk-doc when making dist
+#
+if ENABLE_GTK_DOC
+dist-check-gtkdoc:
+else
+dist-check-gtkdoc:
+       @echo "*** gtk-doc must be installed and enabled in order to make dist"
+       @false
+endif
+
+dist-hook: dist-check-gtkdoc dist-hook-local
+       mkdir $(distdir)/tmpl
+       mkdir $(distdir)/html
+       -cp $(srcdir)/tmpl/*.sgml $(distdir)/tmpl
+       cp $(srcdir)/html/* $(distdir)/html
+       -cp $(srcdir)/$(DOC_MODULE).pdf $(distdir)/
+       -cp $(srcdir)/$(DOC_MODULE).types $(distdir)/
+       -cp $(srcdir)/$(DOC_MODULE)-sections.txt $(distdir)/
+       cd $(distdir) && rm -f $(DISTCLEANFILES)
+       $(GTKDOC_REBASE) --online --relative --html-dir=$(distdir)/html
+
+.PHONY : dist-hook-local docs
similarity index 99%
rename from module/Makefile.am
rename to p11-kit/Makefile.am
index b4339a8ce26e2af0c56a222bd787c9339f60888b..989f4822ab00e2239e1ef5b7776615e5ff224313 100644 (file)
@@ -1,5 +1,4 @@
 
-
 incdir = $(includedir)/p11-kit
 
 inc_HEADERS = \
similarity index 100%
rename from module/conf.c
rename to p11-kit/conf.c
similarity index 100%
rename from module/conf.h
rename to p11-kit/conf.h
similarity index 99%
rename from module/hash.c
rename to p11-kit/hash.c
index 30efcedb4cea7851184742f0b1f1c200f62c4375..836e717036553c2e6a9944947f23a9889fa0ce6b 100644 (file)
@@ -450,4 +450,3 @@ hash_direct_equal (const void *ptr_one, const void *ptr_two)
 {
        return ptr_one == ptr_two;
 }
-
similarity index 100%
rename from module/hash.h
rename to p11-kit/hash.h
similarity index 86%
rename from module/p11-kit-lib.c
rename to p11-kit/p11-kit-lib.c
index 33b768feca4b5f95920b7dc93ca8941b943fa883..f57f3d1e4605a8ffef827df30f203746cef23978 100644 (file)
 #include <string.h>
 #include <unistd.h>
 
+/**
+ * SECTION:p11-kit
+ * @title: Modules
+ * @short_description: Module loading and initializing
+ *
+ * PKCS\#11 modules are used by crypto libraries and applications to access
+ * crypto objects (like keys and certificates) and to perform crypto operations.
+ *
+ * In order for applications to behave consistently with regard to the user's
+ * installed PKCS\#11 modules, each module must be registered so that applications
+ * or libraries know that they should load it.
+ *
+ * The functions here provide support for initializing registered modules. The
+ * p11_kit_initialize_registered() function should be used to load and initialize
+ * the registered modules. When done, the p11_kit_finalize_registered() function
+ * should be used to release those modules and associated resources.
+ *
+ * In addition p11_kit_registered_option() can be used to access other parts
+ * of the module configuration.
+ *
+ * When multiple consumers of a module (such as libraries or applications) are
+ * in the same process, coordination of the initialization and finalization
+ * of PKCS\#11 modules is required. The functions here automatically provide
+ * initialization reference counting to make this work.
+ *
+ * If a consumer wishes to load an arbitrary PKCS\#11 module that's not
+ * registered, that module should be initialized with p11_kit_initialize_module()
+ * and finalized with p11_kit_finalize_module(). The module's own
+ * <code>C_Initialize</code> and <code>C_Finalize</code> methods should not
+ * be called directly.
+ *
+ * Modules are represented by a pointer to their <code>CK_FUNCTION_LIST</code>
+ * entry points. This means that callers can load modules elsewhere, using
+ * dlopen() for example, and then still use these methods on them.
+ */
+
 typedef struct _Module {
        char *name;
        hash_t *config;
@@ -735,7 +771,7 @@ _p11_kit_initialize_registered_unlocked_reentrant (void)
 /**
  * p11_kit_initialize_registered:
  *
- * Initialize all the registered PKCS#11 modules.
+ * Initialize all the registered PKCS\#11 modules.
  *
  * If this is the first time this function is called multiple times
  * consecutively within a single process, then it merely increments an
@@ -805,7 +841,7 @@ _p11_kit_finalize_registered_unlocked_reentrant (void)
 /**
  * p11_kit_finalize_registered:
  *
- * Finalize all the registered PKCS#11 modules. These should have been
+ * Finalize all the registered PKCS\#11 modules. These should have been
  * initialized with p11_kit_initialize_registered().
  *
  * If p11_kit_initialize_registered() has been called more than once in this
@@ -855,11 +891,11 @@ _p11_kit_registered_modules_unlocked (void)
 /**
  * p11_kit_registered_modules:
  *
- * Get a list of all the registered PKCS#11 modules. This list will be valid
+ * Get a list of all the registered PKCS\#11 modules. This list will be valid
  * once the p11_kit_initialize_registered() function has been called.
  *
- * The returned value is a %NULL terminated array of %CK_FUNCTION_LIST_PTR
- * pointers.
+ * The returned value is a <code>NULL</code> terminated array of
+ * <code>CK_FUNCTION_LIST_PTR</code> pointers.
  *
  * Returns: A list of all the registered modules. Use the free() function to
  * free the list.
@@ -882,13 +918,14 @@ p11_kit_registered_modules (void)
  * p11_kit_registered_module_to_name:
  * @funcs: pointer to a registered module
  *
- * Get the name of a registered PKCS#11 module.
+ * Get the name of a registered PKCS\#11 module.
  *
  * You can use p11_kit_registered_modules() to get a list of all the registered
  * modules. This name is specified by the registered module configuration.
  *
- * Returns: A newly allocated string containing the module name, or %NULL
- *     if no such registered module exists. Use free() to free this string.
+ * Returns: A newly allocated string containing the module name, or
+ *     <code>NULL</code> if no such registered module exists. Use free() to
+ *     free this string.
  */
 char*
 p11_kit_registered_module_to_name (CK_FUNCTION_LIST_PTR funcs)
@@ -914,10 +951,11 @@ p11_kit_registered_module_to_name (CK_FUNCTION_LIST_PTR funcs)
  * p11_kit_registered_name_to_module:
  * @name: name of a registered module
  *
- * Lookup a registered PKCS#11 module by its name. This name is specified by
+ * Lookup a registered PKCS\#11 module by its name. This name is specified by
  * the registered module configuration.
  *
- * Returns: a pointer to a PKCS#11 module, or %NULL if this name was not found.
+ * Returns: a pointer to a PKCS\#11 module, or <code>NULL</code> if this name was
+ *     not found.
  */
 CK_FUNCTION_LIST_PTR
 p11_kit_registered_name_to_module (const char *name)
@@ -943,25 +981,36 @@ p11_kit_registered_name_to_module (const char *name)
  * @funcs: a pointer to a registered module
  * @field: the name of the option to lookup.
  *
- * Lookup a configured option for a registered PKCS#11 module.
+ * Lookup a configured option for a registered PKCS\#11 module. If a
+ * <code>NULL</code> funcs argument is specified, then this will lookup
+ * the configuration option in the global config file.
  *
- * Returns: A newly allocated string containing the option value, or %NULL
- *     if the registered module or the option were not found. Use free() to free
- *     the returned string.
+ * Returns: A newly allocated string containing the option value, or
+ *     <code>NULL</code> if the registered module or the option were not found.
+ *     Use free() to free the returned string.
  */
 char*
 p11_kit_registered_option (CK_FUNCTION_LIST_PTR funcs, const char *field)
 {
        Module *module;
        char *option = NULL;
+       hash_t *config;
 
-       if (!funcs || !field)
+       if (!field)
                return NULL;
 
        _p11_lock ();
 
-               module = gl.modules ? hash_get (gl.modules, funcs) : NULL;
-               if (module && module->config) {
+               if (funcs == NULL) {
+                       config = gl.config;
+
+               } else {
+                       module = gl.modules ? hash_get (gl.modules, funcs) : NULL;
+                       if (module)
+                               config = module->config;
+               }
+
+               if (config) {
                        option = hash_get (module->config, field);
                        if (option)
                                option = strdup (option);
@@ -976,32 +1025,32 @@ p11_kit_registered_option (CK_FUNCTION_LIST_PTR funcs, const char *field)
  * p11_kit_initialize_module:
  * @funcs: loaded module to initialize.
  *
- * Initialize an arbitrary PKCS#11 module. Normally using the
+ * Initialize an arbitrary PKCS\#11 module. Normally using the
  * p11_kit_initialize_registered() is preferred.
  *
  * Using this function to initialize modules allows coordination between
  * multiple users of the same module in a single process. It should be called
  * on modules that have been loaded (with dlopen() for example) but not yet
  * initialized. The caller should not yet have called the module's
- * %C_Initialize method. This function will call %C_Initialize as necessary.
+ * <code>C_Initialize</code> method. This function will call
+ * <code>C_Initialize</code> as necessary.
  *
  * Subsequent calls to this function for the same module will result in an
  * initialization count being incremented for the module. It is safe (although
  * usually unnecessary) to use this function on registered modules.
  *
  * The module must be finalized with p11_kit_finalize_module() instead of
- * calling its %C_Finalize method directly.
+ * calling its <code>C_Finalize</code> method directly.
  *
- * This function does not accept a %CK_C_INITIALIZE_ARGS argument. Custom
- * initialization arguments cannot be supported when multiple consumers load
- * the same module.
+ * This function does not accept a <code>CK_C_INITIALIZE_ARGS</code> argument.
+ * Custom initialization arguments cannot be supported when multiple consumers
+ * load the same module.
  *
  * Returns: CKR_OK if the initialization was successful.
  */
 CK_RV
 p11_kit_initialize_module (CK_FUNCTION_LIST_PTR funcs)
 {
-       CK_C_INITIALIZE_ARGS args;
        Module *module;
        Module *allocated = NULL;
        CK_RV rv = CKR_OK;
@@ -1040,14 +1089,14 @@ p11_kit_initialize_module (CK_FUNCTION_LIST_PTR funcs)
  * p11_kit_finalize_module:
  * @funcs: loaded module to finalize.
  *
- * Finalize an arbitrary PKCS#11 module. The module must have been initialized
+ * Finalize an arbitrary PKCS\#11 module. The module must have been initialized
  * using p11_kit_initialize_module(). In most cases callers will want to use
  * p11_kit_finalize_registered() instead of this function.
  *
  * Using this function to finalize modules allows coordination between
  * multiple users of the same module in a single process. The caller should
- * call the module's %C_Finalize method. This function will call
- * %C_Finalize as necessary.
+ * call the module's <code>C_Finalize</code> method. This function will call
+ * <code>C_Finalize</code> as necessary.
  *
  * If the module was initialized more than once, then this function will
  * decrement an initialization count for the module. When the count reaches zero
similarity index 96%
rename from module/p11-kit-messages.c
rename to p11-kit/p11-kit-messages.c
index 3a71a96b3f06863af84fd7f83efaec40ff2a74ea..0920a377b11f745995e1df044fc2d34420c439a1 100644 (file)
 #include "pkcs11.h"
 #include "p11-kit.h"
 
+/**
+ * SECTION:p11-kit-util
+ * @title: Utilities
+ * @short_description: Message Utilities
+ *
+ * Utility functions for working with PKCS\#11.
+ */
+
 #ifdef ENABLE_NLS
 #include <libintl.h>
 #define _(x) dgettext(PACKAGE_NAME, x)
 #endif
 
 /**
- * gck_message_from_rv:
- * @rv: The PKCS#11 return value to get a message for.
+ * p11_kit_strerror:
+ * @rv: The PKCS\#11 return value to get a message for.
  *
- * Get a message for a PKCS#11 return value or error code. Do not
+ * Get a message for a PKCS\#11 return value or error code. Do not
  * pass CKR_OK or other such non errors to this function.
  *
- * Return value: The user readable message.
+ * Returns: The user readable and localized message.
  **/
 const char*
 p11_kit_strerror (CK_RV rv)
similarity index 62%
rename from module/p11-kit-uri.c
rename to p11-kit/p11-kit-uri.c
index 683089623cf8e1beab95dd95fbf71a44fc9e2aee..5004ba123a1c9c2290ad4f9b2ae6c69d5b8c1436 100644 (file)
 #include <stdio.h>
 #include <string.h>
 
+/**
+ * SECTION:p11-kit-uri
+ * @title: URIs
+ * @short_description: Parsing and formatting PKCS\#11 URIs
+ *
+ * PKCS\#11 URIs can be used in configuration files or applications to represent
+ * PKCS\#11 modules, tokens or objects. An example of a URI might be:
+ *
+ * <code><literallayout>
+ *      pkcs11:token=The\%20Software\%20PKCS\#11\%20softtoken;
+ *          manufacturer=Snake\%20Oil,\%20Inc.;serial=;object=my-certificate;
+ *          model=1.0;objecttype=cert;id=\%69\%95\%3e\%5c\%f4\%bd\%ec\%91
+ * </literallayout></code>
+ *
+ * You can use p11_kit_uri_parse() to parse such a URI, and p11_kit_uri_format()
+ * to build one. URIs are represented by the #P11KitUri structure. You can match
+ * a parsed URI against PKCS\#11 tokens with p11_kit_uri_match_token_info()
+ * or attributes with p11_kit_uri_match_attributes().
+ *
+ * Since URIs can represent different sorts of things, when parsing or formatting
+ * a URI a 'context' can be used to indicate which sort of URI is expected.
+ *
+ * URIs have an <code>unrecognized</code> flag. This flag is set during parsing
+ * if any parts of the URI are not recognized. This may be because the part is
+ * from a newer version of the PKCS\#11 spec or because that part was not valid
+ * inside of the desired context used when parsing.
+ */
+
+/**
+ * P11KitUri:
+ *
+ * A structure representing a PKCS\#11 URI. There are no public fields
+ * visible in this structure. Use the various accessor functions.
+ */
+
+/**
+ * P11KitUriType:
+ * @P11_KIT_URI_IS_MODULE: The URI represents one or more modules
+ * @P11_KIT_URI_IS_TOKEN: The URI represents one or more tokens
+ * @P11_KIT_URI_IS_OBJECT: The URI represents one or more objects
+ * @P11_KIT_URI_IS_ANY: The URI can represent anything
+ *
+ * A PKCS\#11 URI can represent different kinds of things. This flag is used by
+ * p11_kit_uri_parse() to denote in what context the URI will be used.
+ */
+
+/**
+ * P11KitUriResult:
+ * @P11_KIT_URI_OK: Success
+ * @P11_KIT_URI_NO_MEMORY: Memory allocation failed
+ * @P11_KIT_URI_BAD_SCHEME: The URI had a bad scheme
+ * @P11_KIT_URI_BAD_ENCODING: The URI had a bad encoding
+ * @P11_KIT_URI_BAD_SYNTAX: The URI had a bad syntax
+ * @P11_KIT_URI_BAD_VERSION: The URI contained a bad version number
+ * @P11_KIT_URI_NOT_FOUND: A requested part of the URI was not found
+ *
+ * Error codes returned by various functions. The functions each clearly state
+ * which error codes they are capable of returning.
+ */
+
+/**
+ * P11_KIT_URI_SCHEME:
+ *
+ * String of URI scheme for PKCS\#11 URIs.
+ */
+
+/**
+ * P11_KIT_URI_SCHEME_LEN:
+ *
+ * Length of %P11_KIT_URI_SCHEME.
+ */
+
 enum {
        CLASS_IDX,
        LABEL_IDX,
@@ -202,10 +274,19 @@ match_struct_version (CK_VERSION_PTR inuri, CK_VERSION_PTR real)
 
 /**
  * p11_kit_uri_get_module_info:
+ * @uri: the URI
+ *
+ * Get the <code>CK_INFO</code> structure associated with this URI.
  *
- * Get the %CK_INFO structure associated with this URI.
+ * If this is a parsed URI, then the fields corresponding to library parts of
+ * the URI will be filled in. Any library URI parts that were missing will have
+ * their fields filled with zeros.
  *
- * Returns: A pointer to the %CK_INFO structure.
+ * If the caller wishes to setup information for building a URI, then relevant
+ * fields should be filled in. Fields that should not appear as parts in the
+ * resulting URI should be filled with zeros.
+ *
+ * Returns: A pointer to the <code>CK_INFO</code> structure.
  */
 CK_INFO_PTR
 p11_kit_uri_get_module_info (P11KitUri *uri)
@@ -216,11 +297,13 @@ p11_kit_uri_get_module_info (P11KitUri *uri)
 
 /**
  * p11_kit_uri_match_module_info:
+ * @uri: the URI
+ * @info: the structure to match against the URI
  *
- * Match a %CK_INFO structure against the library parts of this URI.
+ * Match a <code>CK_INFO</code> structure against the library parts of this URI.
  *
- * Only the fields of the %CK_INFO structure that are valid for use in a
- * URI will be matched. A URI part that was not specified in the URI will
+ * Only the fields of the <code>CK_INFO</code> structure that are valid for use
+ * in a URI will be matched. A URI part that was not specified in the URI will
  * match any value in the structure. If during the URI parsing any unrecognized
  * parts were encountered then this match will fail.
  *
@@ -245,6 +328,22 @@ p11_kit_uri_match_module_info (P11KitUri *uri, CK_INFO_PTR info)
                                      &info->libraryVersion));
 }
 
+/**
+ * p11_kit_uri_get_token_info:
+ * @uri: the URI
+ *
+ * Get the <code>CK_TOKEN_INFO</code> structure associated with this URI.
+ *
+ * If this is a parsed URI, then the fields corresponding to token parts of
+ * the URI will be filled in. Any token URI parts that were missing will have
+ * their fields filled with zeros.
+ *
+ * If the caller wishes to setup information for building a URI, then relevant
+ * fields should be filled in. Fields that should not appear as parts in the
+ * resulting URI should be filled with zeros.
+ *
+ * Returns: A pointer to the <code>CK_INFO</code> structure.
+ */
 CK_TOKEN_INFO_PTR
 p11_kit_uri_get_token_info (P11KitUri *uri)
 {
@@ -254,13 +353,16 @@ p11_kit_uri_get_token_info (P11KitUri *uri)
 
 /**
  * p11_kit_uri_match_token_info:
+ * @uri: the URI
+ * @token_info: the structure to match against the URI
  *
- * Match a %CK_TOKEN_INFO structure against the token parts of this URI.
+ * Match a <code>CK_TOKEN_INFO</code> structure against the token parts of this
+ * URI.
  *
- * Only the fields of the %CK_TOKEN_INFO structure that are valid for use in a
- * URI will be matched. A URI part that was not specified in the URI will
- * match any value in the structure. If during the URI parsing any unrecognized
- * parts were encountered then this match will fail.
+ * Only the fields of the <code>CK_TOKEN_INFO</code> structure that are valid
+ * for use in a URI will be matched. A URI part that was not specified in the
+ * URI will match any value in the structure. If during the URI parsing any
+ * unrecognized parts were encountered then this match will fail.
  *
  * Returns: 1 if the URI matches, 0 if not.
  */
@@ -287,6 +389,16 @@ p11_kit_uri_match_token_info (P11KitUri *uri, CK_TOKEN_INFO_PTR token_info)
                                     sizeof (token_info->serialNumber)));
 }
 
+/**
+ * p11_kit_uri_get_attribute_types:
+ * @uri: The URI
+ * @n_types: A location at which to return the number of types returned
+ *
+ * Get the types of the attributes present in this URI.
+ *
+ * Returns: A newly allocated array of <code>CK_ATTRIBUTE_TYPE</code>. This
+ *     should be freed with free() when done.
+ */
 CK_ATTRIBUTE_TYPE*
 p11_kit_uri_get_attribute_types (P11KitUri *uri, int *n_types)
 {
@@ -309,14 +421,24 @@ p11_kit_uri_get_attribute_types (P11KitUri *uri, int *n_types)
        return result;
 }
 
+/**
+ * p11_kit_uri_get_attribute:
+ * @uri: The URI
+ * @attr_type: The attribute type
+ *
+ * Get a pointer to an attribute present in this URI.
+ *
+ * Returns: A pointer to the attribute, or <code>NULL</code> if not present.
+ *     The attribute is owned by the URI and should not be freed.
+ */
 CK_ATTRIBUTE_PTR
-p11_kit_uri_get_attribute (P11KitUri *uri, CK_ATTRIBUTE_TYPE type)
+p11_kit_uri_get_attribute (P11KitUri *uri, CK_ATTRIBUTE_TYPE attr_type)
 {
        int idx;
 
        assert (uri);
 
-       idx = attribute_to_idx (type);
+       idx = attribute_to_idx (attr_type);
        if (idx < 0)
                return NULL;
 
@@ -326,6 +448,19 @@ p11_kit_uri_get_attribute (P11KitUri *uri, CK_ATTRIBUTE_TYPE type)
        return &uri->attrs[idx];
 }
 
+/**
+ * p11_kit_uri_set_attribute:
+ * @uri: The URI
+ * @attr: The attribute to set
+ *
+ * Set an attribute on the URI.
+ *
+ * Only attributes that map to parts in a PKCS\#11 URI will be accepted.
+ *
+ * Returns: %P11_KIT_URI_OK if the attribute was successfully set.
+ *     %P11_KIT_URI_NOT_FOUND if the attribute was not valid for a URI.
+ *     %P11_KIT_URI_NO_MEMORY if allocation failed.
+ */
 int
 p11_kit_uri_set_attribute (P11KitUri *uri, CK_ATTRIBUTE_PTR attr)
 {
@@ -358,14 +493,26 @@ p11_kit_uri_set_attribute (P11KitUri *uri, CK_ATTRIBUTE_PTR attr)
        return P11_KIT_URI_OK;
 }
 
+/**
+ * p11_kit_uri_clear_attribute:
+ * @uri: The URI
+ * @attr_type: The type of the attribute to clear
+ *
+ * Clear an attribute on the URI.
+ *
+ * Only attributes that map to parts in a PKCS\#11 URI will be accepted.
+ *
+ * Returns: %P11_KIT_URI_OK if the attribute was successfully cleared.
+ *     %P11_KIT_URI_NOT_FOUND if the attribute was not valid for a URI.
+ */
 int
-p11_kit_uri_clear_attribute (P11KitUri *uri, CK_ATTRIBUTE_TYPE type)
+p11_kit_uri_clear_attribute (P11KitUri *uri, CK_ATTRIBUTE_TYPE attr_type)
 {
        int idx;
 
        assert (uri);
 
-       idx = attribute_to_idx (type);
+       idx = attribute_to_idx (attr_type);
        if (idx < 0)
                return P11_KIT_URI_NOT_FOUND;
        assert (idx < NUM_ATTRS);
@@ -373,7 +520,7 @@ p11_kit_uri_clear_attribute (P11KitUri *uri, CK_ATTRIBUTE_TYPE type)
        free (uri->attrs[idx].pValue);
        uri->attrs[idx].pValue = NULL;
        uri->attrs[idx].ulValueLen = (CK_ULONG)-1;
-       return 0;
+       return P11_KIT_URI_OK;
 }
 
 static int
@@ -395,6 +542,9 @@ match_attributes (CK_ATTRIBUTE_PTR one, CK_ATTRIBUTE_PTR two)
 
 /**
  * p11_kit_uri_match_attributes:
+ * @uri: The URI
+ * @attrs: The attributes to match
+ * @n_attrs: The number of attributes
  *
  * Match a attributes against the object parts of this URI.
  *
@@ -433,6 +583,17 @@ p11_kit_uri_match_attributes (P11KitUri *uri, CK_ATTRIBUTE_PTR attrs,
        return 1;
 }
 
+/**
+ * p11_kit_uri_set_unrecognized:
+ * @uri: The URI
+ * @unrecognized: The new unregognized flag value
+ *
+ * Set the unrecognized flag on this URI.
+ *
+ * The unrecognized flag is automatically set to 1 when during parsing any part
+ * of the URI is unrecognized. If the unrecognized flag is set to 1, then
+ * matching against this URI will always fail.
+ */
 void
 p11_kit_uri_set_unrecognized (P11KitUri *uri, int unrecognized)
 {
@@ -440,6 +601,18 @@ p11_kit_uri_set_unrecognized (P11KitUri *uri, int unrecognized)
        uri->unrecognized = unrecognized;
 }
 
+/**
+ * p11_kit_uri_any_unrecognized:
+ * @uri: The URI
+ *
+ * Get the unrecognized flag for this URI.
+ *
+ * The unrecognized flag is automatically set to 1 when during parsing any part
+ * of the URI is unrecognized. If the unrecognized flag is set to 1, then
+ * matching against this URI will always fail.
+ *
+ * Returns: 1 if unrecognized flag is set, 0 otherwise.
+ */
 int
 p11_kit_uri_any_unrecognized (P11KitUri *uri)
 {
@@ -447,6 +620,16 @@ p11_kit_uri_any_unrecognized (P11KitUri *uri)
        return uri->unrecognized;
 }
 
+/**
+ * p11_kit_uri_new:
+ *
+ * Create a new blank PKCS\#11 URI.
+ *
+ * The new URI is in the right state to parse a string into. All relevant fields
+ * are zeroed out. Formatting this URI will produce a valid but empty URI.
+ *
+ * Returns: A newly allocated URI. This should be freed with p11_kit_uri_free().
+ */
 P11KitUri*
 p11_kit_uri_new (void)
 {
@@ -608,8 +791,28 @@ format_struct_version (char **string, size_t *length, int *is_first,
        return format_raw_string (string, length, is_first, name, buffer);
 }
 
+/**
+ * p11_kit_uri_format:
+ * @uri: The URI.
+ * @uri_type: The type of URI that should be produced.
+ * @string: Location to store a newly allocated string.
+ *
+ * Format a PKCS\#11 URI into a string.
+ *
+ * Fields which are zeroed out will not be included in the resulting string.
+ * Attributes which are not present will also not be included.
+ *
+ * The uri_type of URI specified limits the different parts of the resulting
+ * URI. To format a URI containing all possible information use
+ * %P11_KIT_URI_IS_ANY
+ *
+ * The resulting string should be freed with free().
+ *
+ * Returns: %P11_KIT_URI_OK if the URI was formatted successfully.
+ *     %P11_KIT_URI_NO_MEMORY if memory allocation failed.
+ */
 int
-p11_kit_uri_format (P11KitUri *uri, char **string)
+p11_kit_uri_format (P11KitUri *uri, P11KitUriType uri_type, char **string)
 {
        char *result = NULL;
        size_t length = 0;
@@ -619,46 +822,56 @@ p11_kit_uri_format (P11KitUri *uri, char **string)
        if (!result)
                return P11_KIT_URI_NO_MEMORY;
 
-       length = P11_KIT_URI_PREFIX_LEN;
-       memcpy (result, P11_KIT_URI_PREFIX, length);
+       length = P11_KIT_URI_SCHEME_LEN;
+       memcpy (result, P11_KIT_URI_SCHEME, length);
        result[length] = 0;
 
-       if (!format_struct_string (&result, &length, &is_first, "library-description",
-                                  uri->module.libraryDescription,
-                                  sizeof (uri->module.libraryDescription)) ||
-           !format_struct_string (&result, &length, &is_first, "library-manufacturer",
-                                  uri->module.manufacturerID,
-                                  sizeof (uri->module.manufacturerID)) ||
-           !format_struct_string (&result, &length, &is_first, "model",
-                                  uri->token.model,
-                                  sizeof (uri->token.model)) ||
-           !format_struct_string (&result, &length, &is_first, "manufacturer",
-                                  uri->token.manufacturerID,
-                                  sizeof (uri->token.manufacturerID)) ||
-           !format_struct_string (&result, &length, &is_first, "serial",
-                                  uri->token.serialNumber,
-                                  sizeof (uri->token.serialNumber)) ||
-           !format_struct_string (&result, &length, &is_first, "token",
-                                  uri->token.label,
-                                  sizeof (uri->token.label)) ||
-           !format_struct_version (&result, &length, &is_first, "library-version",
-                                   &uri->module.libraryVersion)) {
-               free (result);
-               return P11_KIT_URI_NO_MEMORY;
+       if (uri_type & P11_KIT_URI_IS_MODULE) {
+               if (!format_struct_string (&result, &length, &is_first, "library-description",
+                                          uri->module.libraryDescription,
+                                          sizeof (uri->module.libraryDescription)) ||
+                   !format_struct_version (&result, &length, &is_first, "library-version",
+                                           &uri->module.libraryVersion) ||
+                   !format_struct_string (&result, &length, &is_first, "library-manufacturer",
+                                          uri->module.manufacturerID,
+                                          sizeof (uri->module.manufacturerID))) {
+                       free (result);
+                       return P11_KIT_URI_NO_MEMORY;
+               }
        }
 
-       if (!format_attribute_string (&result, &length, &is_first, "id",
-                                     &uri->attrs[ID_IDX]) ||
-           !format_attribute_string (&result, &length, &is_first, "object",
-                                     &uri->attrs[LABEL_IDX])) {
-               free (result);
-               return P11_KIT_URI_NO_MEMORY;
+       if (uri_type & P11_KIT_URI_IS_TOKEN) {
+               if (!format_struct_string (&result, &length, &is_first, "model",
+                                          uri->token.model,
+                                          sizeof (uri->token.model)) ||
+                   !format_struct_string (&result, &length, &is_first, "manufacturer",
+                                          uri->token.manufacturerID,
+                                          sizeof (uri->token.manufacturerID)) ||
+                   !format_struct_string (&result, &length, &is_first, "serial",
+                                          uri->token.serialNumber,
+                                          sizeof (uri->token.serialNumber)) ||
+                   !format_struct_string (&result, &length, &is_first, "token",
+                                          uri->token.label,
+                                          sizeof (uri->token.label))) {
+                       free (result);
+                       return P11_KIT_URI_NO_MEMORY;
+               }
        }
 
-       if (!format_attribute_class (&result, &length, &is_first, "objecttype",
-                                    &uri->attrs[CLASS_IDX])) {
-               free (result);
-               return P11_KIT_URI_NO_MEMORY;
+       if (uri_type & P11_KIT_URI_IS_OBJECT) {
+               if (!format_attribute_string (&result, &length, &is_first, "id",
+                                             &uri->attrs[ID_IDX]) ||
+                   !format_attribute_string (&result, &length, &is_first, "object",
+                                             &uri->attrs[LABEL_IDX])) {
+                       free (result);
+                       return P11_KIT_URI_NO_MEMORY;
+               }
+
+               if (!format_attribute_class (&result, &length, &is_first, "objecttype",
+                                            &uri->attrs[CLASS_IDX])) {
+                       free (result);
+                       return P11_KIT_URI_NO_MEMORY;
+               }
        }
 
        *string = result;
@@ -866,8 +1079,33 @@ parse_module_info (const char *name, const char *start, const char *end,
        return parse_struct_info (where, length, start, end, uri);
 }
 
+/**
+ * p11_kit_uri_parse:
+ * @string: The string to parse
+ * @uri_type: The type of URI that is expected
+ * @uri: The blank URI to parse the values into
+ *
+ * Parse a PKCS\#11 URI string.
+ *
+ * PKCS\#11 URIs can represent tokens, objects or modules. The uri_type argument
+ * allows the caller to specify what type of URI is expected and the sorts of
+ * objects the URI should match. %P11_KIT_URI_IS_ANY can be used to parse a URI
+ * for any context. It's then up to the caller to make sense of the way that
+ * it is used.
+ *
+ * If the PKCS\#11 URI contains unrecognized URI parts or parts not applicable
+ * to the specified context, then the unrecognized flag will be set. This will
+ * prevent the URI from matching using the various match functions.
+ *
+ * Returns: %P11_KIT_URI_OK if the URI was parsed successfully.
+ *     %P11_KIT_URI_BAD_SCHEME if this was not a PKCS\#11 URI.
+ *     %P11_KIT_URI_BAD_SYNTAX if the URI syntax was bad.
+ *     %P11_KIT_URI_NO_MEMORY if memory allocation failed.
+ *     %P11_KIT_URI_BAD_VERSION if a version number was bad.
+ *     %P11_KIT_URI_BAD_ENCODING if the URI encoding was invalid.
+ */
 int
-p11_kit_uri_parse (const char *string, P11KitUriContext context,
+p11_kit_uri_parse (const char *string, P11KitUriType uri_type,
                    P11KitUri *uri)
 {
        const char *spos, *epos;
@@ -878,10 +1116,10 @@ p11_kit_uri_parse (const char *string, P11KitUriContext context,
        assert (string);
        assert (uri);
 
-       if (strncmp (string, P11_KIT_URI_PREFIX, P11_KIT_URI_PREFIX_LEN) != 0)
-               return P11_KIT_URI_BAD_PREFIX;
+       if (strncmp (string, P11_KIT_URI_SCHEME, P11_KIT_URI_SCHEME_LEN) != 0)
+               return P11_KIT_URI_BAD_SCHEME;
 
-       string += P11_KIT_URI_PREFIX_LEN;
+       string += P11_KIT_URI_SCHEME_LEN;
 
        /* Clear everything out */
        memset (&uri->module, 0, sizeof (uri->module));
@@ -913,13 +1151,13 @@ p11_kit_uri_parse (const char *string, P11KitUriContext context,
                epos++;
 
                ret = 0;
-               if (context & P11_KIT_URI_PARSE_OBJECT)
+               if (uri_type & P11_KIT_URI_IS_OBJECT)
                        ret = parse_string_attribute (key, epos, spos, uri);
-               if (ret == 0 && context & P11_KIT_URI_PARSE_OBJECT)
+               if (ret == 0 && uri_type & P11_KIT_URI_IS_OBJECT)
                        ret = parse_class_attribute (key, epos, spos, uri);
-               if (ret == 0 && context & P11_KIT_URI_PARSE_TOKEN)
+               if (ret == 0 && uri_type & P11_KIT_URI_IS_TOKEN)
                        ret = parse_token_info (key, epos, spos, uri);
-               if (ret == 0 && context & P11_KIT_URI_PARSE_MODULE)
+               if (ret == 0 && uri_type & P11_KIT_URI_IS_MODULE)
                        ret = parse_module_info (key, epos, spos, uri);
                free (key);
 
@@ -936,6 +1174,12 @@ p11_kit_uri_parse (const char *string, P11KitUriContext context,
        return P11_KIT_URI_OK;
 }
 
+/**
+ * p11_kit_uri_free:
+ * @uri: The URI
+ *
+ * Free a PKCS\#11 URI.
+ */
 void
 p11_kit_uri_free (P11KitUri *uri)
 {
similarity index 89%
rename from module/p11-kit-uri.h
rename to p11-kit/p11-kit-uri.h
index 209f3d6195152d71f0566f79644cd4fafd7bd9ec..a3e52ed3f4ddc5fd08e066a990bba829e7ea8cc2 100644 (file)
 #ifndef __P11_KIT_URI_H__
 #define __P11_KIT_URI_H__
 
-#define P11_KIT_URI_PREFIX "pkcs11:"
-#define P11_KIT_URI_PREFIX_LEN 7
+#define P11_KIT_URI_SCHEME "pkcs11:"
+#define P11_KIT_URI_SCHEME_LEN 7
 
 typedef enum {
        P11_KIT_URI_OK = 0,
        P11_KIT_URI_NO_MEMORY = -1,
-       P11_KIT_URI_BAD_PREFIX = -2,
+       P11_KIT_URI_BAD_SCHEME = -2,
        P11_KIT_URI_BAD_ENCODING = -3,
        P11_KIT_URI_BAD_SYNTAX = -4,
        P11_KIT_URI_BAD_VERSION = -5,
        P11_KIT_URI_NOT_FOUND = -6,
-} P11KitUriParseStatus;
+} P11KitUriResult;
 
 typedef enum {
-       P11_KIT_URI_PARSE_MODULE = (1 << 1),
-       P11_KIT_URI_PARSE_TOKEN =   (1 << 2) | P11_KIT_URI_PARSE_MODULE,
-       P11_KIT_URI_PARSE_OBJECT =  (1 << 3) | P11_KIT_URI_PARSE_TOKEN,
-       P11_KIT_URI_PARSE_ANY =     0xFFFFFFFF,
-} P11KitUriContext;
+       P11_KIT_URI_IS_MODULE = (1 << 1),
+       P11_KIT_URI_IS_TOKEN =   (1 << 2) | P11_KIT_URI_IS_MODULE,
+       P11_KIT_URI_IS_OBJECT =  (1 << 3) | P11_KIT_URI_IS_TOKEN,
+       P11_KIT_URI_IS_ANY =     0x0000FFFF,
+} P11KitUriType;
 
 typedef struct _P11KitUri P11KitUri;
 
@@ -73,13 +73,13 @@ CK_ATTRIBUTE_TYPE*  p11_kit_uri_get_attribute_types         (P11KitUri *uri,
                                                              int *n_types);
 
 CK_ATTRIBUTE_PTR    p11_kit_uri_get_attribute               (P11KitUri *uri,
-                                                             CK_ATTRIBUTE_TYPE type);
+                                                             CK_ATTRIBUTE_TYPE attr_type);
 
 int                 p11_kit_uri_set_attribute               (P11KitUri *uri,
                                                              CK_ATTRIBUTE_PTR attr);
 
 int                 p11_kit_uri_clear_attribute             (P11KitUri *uri,
-                                                             CK_ATTRIBUTE_TYPE type);
+                                                             CK_ATTRIBUTE_TYPE attr_type);
 
 int                 p11_kit_uri_match_attributes            (P11KitUri *uri,
                                                              CK_ATTRIBUTE_PTR attrs,
@@ -93,10 +93,11 @@ int                 p11_kit_uri_any_unrecognized            (P11KitUri *uri);
 P11KitUri*          p11_kit_uri_new                         (void);
 
 int                 p11_kit_uri_format                      (P11KitUri *uri,
+                                                             P11KitUriType uri_type,
                                                              char **string);
 
 int                 p11_kit_uri_parse                       (const char *string,
-                                                             P11KitUriContext context,
+                                                             P11KitUriType uri_type,
                                                              P11KitUri *uri);
 
 void                p11_kit_uri_free                        (P11KitUri *uri);
similarity index 100%
rename from module/p11-kit.h
rename to p11-kit/p11-kit.h
diff --git a/p11-kit/p11-kit.pc b/p11-kit/p11-kit.pc
new file mode 100644 (file)
index 0000000..ce763cc
--- /dev/null
@@ -0,0 +1,17 @@
+prefix=/usr
+exec_prefix=${prefix}
+libdir=${exec_prefix}/lib
+includedir=${prefix}/include
+datarootdir=${prefix}/share
+datadir=${datarootdir}
+sysconfdir=/etc
+p11_system_conf=/etc/pkcs11/pkcs11.conf
+p11_system_modules=/etc/pkcs11/modules
+p11_user_conf=~/.pkcs11/pkcs11.conf
+p11_user_modules=~/.pkcs11/modules
+
+Name: p11-kit
+Description: Library and proxy module for properly loading and sharing PKCS#11 modules.
+Version: 0.1
+Libs: -L${libdir} -lp11-kit
+Cflags: -I${includedir}/p11-kit
similarity index 100%
rename from module/p11-kit.pc.in
rename to p11-kit/p11-kit.pc.in
similarity index 100%
rename from module/pkcs11.h
rename to p11-kit/pkcs11.h
similarity index 100%
rename from module/util.c
rename to p11-kit/util.c
similarity index 100%
rename from module/util.h
rename to p11-kit/util.h
index 92dba16a9fc9cae99357d21a0b3e7ace2c0dcde9..3719a64d962d6d2b3a27068d00004ec7d85f8911 100644 (file)
@@ -1,7 +1,7 @@
 
 INCLUDES = \
        -I$(top_srcdir) \
-       -I$(top_srcdir)/module \
+       -I$(top_srcdir)/p11-kit \
        -Icutest \
        -DSRCDIR=\"$(srcdir)\"
 
@@ -11,13 +11,13 @@ noinst_PROGRAMS = \
        uri-test
 
 hash_test_LDADD = \
-       $(top_builddir)/module/libp11-kit-testable.la
+       $(top_builddir)/p11-kit/libp11-kit-testable.la
 
 conf_test_LDADD = \
-       $(top_builddir)/module/libp11-kit-testable.la
+       $(top_builddir)/p11-kit/libp11-kit-testable.la
 
 uri_test_LDADD = \
-       $(top_builddir)/module/libp11-kit-testable.la
+       $(top_builddir)/p11-kit/libp11-kit-testable.la
 
 check-am:
        ./hash-test
index 40e301a9d427ae9301cfa8f2370c464b2039d742..631d39f9fd6e58a0e365fae418429ad6bfd92fbb 100644 (file)
@@ -79,7 +79,7 @@ test_uri_parse (CuTest *tc)
        uri = p11_kit_uri_new ();
        CuAssertPtrNotNull (tc, uri);
 
-       ret = p11_kit_uri_parse ("pkcs11:", P11_KIT_URI_PARSE_MODULE, uri);
+       ret = p11_kit_uri_parse ("pkcs11:", P11_KIT_URI_IS_MODULE, uri);
        CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
 
        CuAssertTrue (tc, is_module_empty (uri));
@@ -98,8 +98,8 @@ test_uri_parse_bad_scheme (CuTest *tc)
        uri = p11_kit_uri_new ();
        CuAssertPtrNotNull (tc, uri);
 
-       ret = p11_kit_uri_parse ("http:\\example.com\test", P11_KIT_URI_PARSE_ANY, uri);
-       CuAssertIntEquals (tc, P11_KIT_URI_BAD_PREFIX, ret);
+       ret = p11_kit_uri_parse ("http:\\example.com\test", P11_KIT_URI_IS_ANY, uri);
+       CuAssertIntEquals (tc, P11_KIT_URI_BAD_SCHEME, ret);
 
        p11_kit_uri_free (uri);
 }
@@ -114,7 +114,7 @@ test_uri_parse_with_label (CuTest *tc)
        uri = p11_kit_uri_new ();
        CuAssertPtrNotNull (tc, uri);
 
-       ret = p11_kit_uri_parse ("pkcs11:object=Test%20Label", P11_KIT_URI_PARSE_ANY, uri);
+       ret = p11_kit_uri_parse ("pkcs11:object=Test%20Label", P11_KIT_URI_IS_ANY, uri);
        CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
 
        CuAssertTrue (tc, is_module_empty (uri));
@@ -138,7 +138,7 @@ test_uri_parse_with_label_and_klass (CuTest *tc)
        uri = p11_kit_uri_new ();
        CuAssertPtrNotNull (tc, uri);
 
-       ret = p11_kit_uri_parse ("pkcs11:object=Test%20Label;objecttype=cert", P11_KIT_URI_PARSE_ANY, uri);
+       ret = p11_kit_uri_parse ("pkcs11:object=Test%20Label;objecttype=cert", P11_KIT_URI_IS_ANY, uri);
        CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
 
        attr = p11_kit_uri_get_attribute (uri, CKA_LABEL);
@@ -164,7 +164,7 @@ test_uri_parse_with_id (CuTest *tc)
        uri = p11_kit_uri_new ();
        CuAssertPtrNotNull (tc, uri);
 
-       ret = p11_kit_uri_parse ("pkcs11:id=%54%45%53%54%00", P11_KIT_URI_PARSE_OBJECT, uri);
+       ret = p11_kit_uri_parse ("pkcs11:id=%54%45%53%54%00", P11_KIT_URI_IS_OBJECT, uri);
        CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
 
        /* Note that there's a NULL in the attribute (end) */
@@ -186,7 +186,7 @@ test_uri_parse_with_bad_string_encoding (CuTest *tc)
        uri = p11_kit_uri_new ();
        CuAssertPtrNotNull (tc, uri);
 
-       ret = p11_kit_uri_parse ("pkcs11:object=Test%", P11_KIT_URI_PARSE_OBJECT, uri);
+       ret = p11_kit_uri_parse ("pkcs11:object=Test%", P11_KIT_URI_IS_OBJECT, uri);
        CuAssertIntEquals (tc, P11_KIT_URI_BAD_ENCODING, ret);
 
        p11_kit_uri_free (uri);
@@ -201,7 +201,7 @@ test_uri_parse_with_bad_hex_encoding (CuTest *tc)
        uri = p11_kit_uri_new ();
        CuAssertPtrNotNull (tc, uri);
 
-       ret = p11_kit_uri_parse ("pkcs11:object=T%xxest", P11_KIT_URI_PARSE_OBJECT, uri);
+       ret = p11_kit_uri_parse ("pkcs11:object=T%xxest", P11_KIT_URI_IS_OBJECT, uri);
        CuAssertIntEquals (tc, P11_KIT_URI_BAD_ENCODING, ret);
 
        p11_kit_uri_free (uri);
@@ -232,7 +232,7 @@ test_uri_parse_with_token (CuTest *tc)
        CuAssertPtrNotNull (tc, uri);
 
        ret = p11_kit_uri_parse ("pkcs11:token=Token%20Label;serial=3333;model=Deluxe;manufacturer=Me",
-                                P11_KIT_URI_PARSE_TOKEN, uri);
+                                P11_KIT_URI_IS_TOKEN, uri);
        CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
 
        token = p11_kit_uri_get_token_info (uri);
@@ -253,7 +253,7 @@ test_uri_parse_with_token_bad_encoding (CuTest *tc)
        uri = p11_kit_uri_new ();
        CuAssertPtrNotNull (tc, uri);
 
-       ret = p11_kit_uri_parse ("pkcs11:token=Token%", P11_KIT_URI_PARSE_TOKEN, uri);
+       ret = p11_kit_uri_parse ("pkcs11:token=Token%", P11_KIT_URI_IS_TOKEN, uri);
        CuAssertIntEquals (tc, P11_KIT_URI_BAD_ENCODING, ret);
 
        p11_kit_uri_free (uri);
@@ -268,7 +268,7 @@ test_uri_parse_with_bad_syntax (CuTest *tc)
        uri = p11_kit_uri_new ();
        CuAssertPtrNotNull (tc, uri);
 
-       ret = p11_kit_uri_parse ("pkcs11:token", P11_KIT_URI_PARSE_ANY, uri);
+       ret = p11_kit_uri_parse ("pkcs11:token", P11_KIT_URI_IS_ANY, uri);
        CuAssertIntEquals (tc, P11_KIT_URI_BAD_SYNTAX, ret);
 
        p11_kit_uri_free (uri);
@@ -285,7 +285,7 @@ test_uri_parse_with_library (CuTest *tc)
        CuAssertPtrNotNull (tc, uri);
 
        ret = p11_kit_uri_parse ("pkcs11:library-description=The%20Library;library-manufacturer=Me",
-                                P11_KIT_URI_PARSE_MODULE, uri);
+                                P11_KIT_URI_IS_MODULE, uri);
        CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
 
        info = p11_kit_uri_get_module_info (uri);
@@ -305,7 +305,7 @@ test_uri_parse_with_library_bad_encoding (CuTest *tc)
        uri = p11_kit_uri_new ();
        CuAssertPtrNotNull (tc, uri);
 
-       ret = p11_kit_uri_parse ("pkcs11:library-description=Library%", P11_KIT_URI_PARSE_MODULE, uri);
+       ret = p11_kit_uri_parse ("pkcs11:library-description=Library%", P11_KIT_URI_IS_MODULE, uri);
        CuAssertIntEquals (tc, P11_KIT_URI_BAD_ENCODING, ret);
 
        p11_kit_uri_free (uri);
@@ -321,7 +321,7 @@ test_uri_build_empty (CuTest *tc)
        uri = p11_kit_uri_new ();
        CuAssertPtrNotNull (tc, uri);
 
-       ret = p11_kit_uri_format (uri, &string);
+       ret = p11_kit_uri_format (uri, P11_KIT_URI_IS_ANY, &string);
        CuAssertStrEquals (tc, "pkcs11:", string);
        free (string);
 
@@ -355,14 +355,14 @@ test_uri_build_with_token_info (CuTest *tc)
        set_space_string (token->manufacturerID, sizeof (token->manufacturerID), "Me");
        set_space_string (token->model, sizeof (token->model), "Deluxe");
 
-       ret = p11_kit_uri_format (uri, &string);
+       ret = p11_kit_uri_format (uri, P11_KIT_URI_IS_ANY, &string);
        CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
        CuAssertPtrNotNull (tc, string);
 
        check = p11_kit_uri_new ();
        CuAssertPtrNotNull (tc, check);
 
-       ret = p11_kit_uri_parse (string, P11_KIT_URI_PARSE_TOKEN, check);
+       ret = p11_kit_uri_parse (string, P11_KIT_URI_IS_TOKEN, check);
        CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
 
        p11_kit_uri_match_token_info (check, p11_kit_uri_get_token_info (uri));
@@ -392,7 +392,7 @@ test_uri_build_with_token_null_info (CuTest *tc)
        token = p11_kit_uri_get_token_info (uri);
        set_space_string (token->label, sizeof (token->label), "The Label");
 
-       ret = p11_kit_uri_format (uri, &string);
+       ret = p11_kit_uri_format (uri, P11_KIT_URI_IS_ANY, &string);
        CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
 
        CuAssertTrue (tc, strstr (string, "token=The%20Label") != NULL);
@@ -417,7 +417,7 @@ test_uri_build_with_token_empty_info (CuTest *tc)
        set_space_string (token->label, sizeof (token->label), "");
        set_space_string (token->serialNumber, sizeof (token->serialNumber), "");
 
-       ret = p11_kit_uri_format (uri, &string);
+       ret = p11_kit_uri_format (uri, P11_KIT_URI_IS_ANY, &string);
        CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
 
        CuAssertTrue (tc, strstr (string, "token=") != NULL);
@@ -457,13 +457,13 @@ test_uri_build_with_attributes (CuTest *tc)
        at.ulValueLen = sizeof (klass);
        ret = p11_kit_uri_set_attribute (uri, &at);
 
-       ret = p11_kit_uri_format (uri, &string);
+       ret = p11_kit_uri_format (uri, P11_KIT_URI_IS_ANY, &string);
        CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
 
        check = p11_kit_uri_new ();
        CuAssertPtrNotNull (tc, check);
 
-       ret = p11_kit_uri_parse (string, P11_KIT_URI_PARSE_ANY, check);
+       ret = p11_kit_uri_parse (string, P11_KIT_URI_IS_ANY, check);
        CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
 
        attr = p11_kit_uri_get_attribute (check, CKA_LABEL);
@@ -501,7 +501,7 @@ test_uri_parse_private_key (CuTest *tc)
        uri = p11_kit_uri_new ();
        CuAssertPtrNotNull (tc, uri);
 
-       ret = p11_kit_uri_parse ("pkcs11:objecttype=private", P11_KIT_URI_PARSE_OBJECT, uri);
+       ret = p11_kit_uri_parse ("pkcs11:objecttype=private", P11_KIT_URI_IS_OBJECT, uri);
        CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
 
        attr = p11_kit_uri_get_attribute (uri, CKA_CLASS);
@@ -522,7 +522,7 @@ test_uri_parse_secret_key (CuTest *tc)
        uri = p11_kit_uri_new ();
        CuAssertPtrNotNull (tc, uri);
 
-       ret = p11_kit_uri_parse ("pkcs11:objecttype=secretkey", P11_KIT_URI_PARSE_OBJECT, uri);
+       ret = p11_kit_uri_parse ("pkcs11:objecttype=secretkey", P11_KIT_URI_IS_OBJECT, uri);
        CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
 
        attr = p11_kit_uri_get_attribute (uri, CKA_CLASS);
@@ -543,33 +543,33 @@ test_uri_parse_library_version (CuTest *tc)
        uri = p11_kit_uri_new ();
        CuAssertPtrNotNull (tc, uri);
 
-       ret = p11_kit_uri_parse ("pkcs11:library-version=2.101", P11_KIT_URI_PARSE_MODULE, uri);
+       ret = p11_kit_uri_parse ("pkcs11:library-version=2.101", P11_KIT_URI_IS_MODULE, uri);
        CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
 
        info = p11_kit_uri_get_module_info (uri);
        CuAssertIntEquals (tc, 2, info->libraryVersion.major);
        CuAssertIntEquals (tc, 101, info->libraryVersion.minor);
 
-       ret = p11_kit_uri_parse ("pkcs11:library-version=23", P11_KIT_URI_PARSE_MODULE, uri);
+       ret = p11_kit_uri_parse ("pkcs11:library-version=23", P11_KIT_URI_IS_MODULE, uri);
        CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
 
        info = p11_kit_uri_get_module_info (uri);
        CuAssertIntEquals (tc, 23, info->libraryVersion.major);
        CuAssertIntEquals (tc, 0, info->libraryVersion.minor);
 
-       ret = p11_kit_uri_parse ("pkcs11:library-version=23.", P11_KIT_URI_PARSE_MODULE, uri);
+       ret = p11_kit_uri_parse ("pkcs11:library-version=23.", P11_KIT_URI_IS_MODULE, uri);
        CuAssertIntEquals (tc, P11_KIT_URI_BAD_VERSION, ret);
 
-       ret = p11_kit_uri_parse ("pkcs11:library-version=a.a", P11_KIT_URI_PARSE_MODULE, uri);
+       ret = p11_kit_uri_parse ("pkcs11:library-version=a.a", P11_KIT_URI_IS_MODULE, uri);
        CuAssertIntEquals (tc, P11_KIT_URI_BAD_VERSION, ret);
 
-       ret = p11_kit_uri_parse ("pkcs11:library-version=.23", P11_KIT_URI_PARSE_MODULE, uri);
+       ret = p11_kit_uri_parse ("pkcs11:library-version=.23", P11_KIT_URI_IS_MODULE, uri);
        CuAssertIntEquals (tc, P11_KIT_URI_BAD_VERSION, ret);
 
-       ret = p11_kit_uri_parse ("pkcs11:library-version=1000", P11_KIT_URI_PARSE_MODULE, uri);
+       ret = p11_kit_uri_parse ("pkcs11:library-version=1000", P11_KIT_URI_IS_MODULE, uri);
        CuAssertIntEquals (tc, P11_KIT_URI_BAD_VERSION, ret);
 
-       ret = p11_kit_uri_parse ("pkcs11:library-version=2.1000", P11_KIT_URI_PARSE_MODULE, uri);
+       ret = p11_kit_uri_parse ("pkcs11:library-version=2.1000", P11_KIT_URI_IS_MODULE, uri);
        CuAssertIntEquals (tc, P11_KIT_URI_BAD_VERSION, ret);
 
        p11_kit_uri_free (uri);
@@ -585,7 +585,7 @@ test_uri_parse_parse_unknown_objecttype (CuTest *tc)
        uri = p11_kit_uri_new ();
        CuAssertPtrNotNull (tc, uri);
 
-       ret = p11_kit_uri_parse ("pkcs11:objecttype=unknown", P11_KIT_URI_PARSE_OBJECT, uri);
+       ret = p11_kit_uri_parse ("pkcs11:objecttype=unknown", P11_KIT_URI_IS_OBJECT, uri);
        CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
 
        attr = p11_kit_uri_get_attribute (uri, CKA_CLASS);
@@ -603,7 +603,7 @@ test_uri_parse_unrecognized (CuTest *tc)
        uri = p11_kit_uri_new ();
        CuAssertPtrNotNull (tc, uri);
 
-       ret = p11_kit_uri_parse ("pkcs11:x-blah=some-value", P11_KIT_URI_PARSE_ANY, uri);
+       ret = p11_kit_uri_parse ("pkcs11:x-blah=some-value", P11_KIT_URI_IS_ANY, uri);
        CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
 
        ret = p11_kit_uri_any_unrecognized (uri);
@@ -622,7 +622,7 @@ test_uri_parse_too_long_is_unrecognized (CuTest *tc)
        CuAssertPtrNotNull (tc, uri);
 
        ret = p11_kit_uri_parse ("pkcs11:model=a-value-that-is-too-long-for-the-field-that-it-goes-with",
-                                P11_KIT_URI_PARSE_ANY, uri);
+                                P11_KIT_URI_IS_ANY, uri);
        CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
 
        ret = p11_kit_uri_any_unrecognized (uri);
@@ -651,7 +651,7 @@ test_uri_build_objecttype_cert (CuTest *tc)
        attr.ulValueLen = sizeof (klass);
        p11_kit_uri_set_attribute (uri, &attr);
 
-       ret = p11_kit_uri_format (uri, &string);
+       ret = p11_kit_uri_format (uri, P11_KIT_URI_IS_ANY, &string);
        CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
        CuAssertTrue (tc, strstr (string, "objecttype=cert") != NULL);
 
@@ -677,7 +677,7 @@ test_uri_build_objecttype_private (CuTest *tc)
        attr.ulValueLen = sizeof (klass);
        p11_kit_uri_set_attribute (uri, &attr);
 
-       ret = p11_kit_uri_format (uri, &string);
+       ret = p11_kit_uri_format (uri, P11_KIT_URI_IS_ANY, &string);
        CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
        CuAssertTrue (tc, strstr (string, "objecttype=private") != NULL);
 
@@ -703,7 +703,7 @@ test_uri_build_objecttype_public (CuTest *tc)
        attr.ulValueLen = sizeof (klass);
        p11_kit_uri_set_attribute (uri, &attr);
 
-       ret = p11_kit_uri_format (uri, &string);
+       ret = p11_kit_uri_format (uri, P11_KIT_URI_IS_ANY, &string);
        CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
        CuAssertTrue (tc, strstr (string, "objecttype=public") != NULL);
 
@@ -729,7 +729,7 @@ test_uri_build_objecttype_secret (CuTest *tc)
        attr.ulValueLen = sizeof (klass);
        p11_kit_uri_set_attribute (uri, &attr);
 
-       ret = p11_kit_uri_format (uri, &string);
+       ret = p11_kit_uri_format (uri, P11_KIT_URI_IS_ANY, &string);
        CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
        CuAssertTrue (tc, strstr (string, "objecttype=secretkey") != NULL);
 
@@ -751,7 +751,7 @@ test_uri_build_with_library (CuTest *tc)
        info = p11_kit_uri_get_module_info (uri);
        set_space_string (info->libraryDescription, sizeof (info->libraryDescription), "The Description");
 
-       ret = p11_kit_uri_format (uri, &string);
+       ret = p11_kit_uri_format (uri, P11_KIT_URI_IS_ANY, &string);
        CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
        CuAssertTrue (tc, strstr (string, "library-description=The%20Description") != NULL);
 
@@ -774,7 +774,7 @@ test_uri_build_library_version (CuTest *tc)
        info->libraryVersion.major = 2;
        info->libraryVersion.minor = 10;
 
-       ret = p11_kit_uri_format (uri, &string);
+       ret = p11_kit_uri_format (uri, P11_KIT_URI_IS_ANY, &string);
        CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
        CuAssertTrue (tc, strstr (string, "library-version=2.10") != NULL);
 
@@ -817,7 +817,7 @@ test_uri_match_token (CuTest *tc)
        uri = p11_kit_uri_new ();
        CuAssertPtrNotNull (tc, uri);
 
-       ret = p11_kit_uri_parse ("pkcs11:model=Giselle", P11_KIT_URI_PARSE_ANY, uri);
+       ret = p11_kit_uri_parse ("pkcs11:model=Giselle", P11_KIT_URI_IS_ANY, uri);
        CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
 
        set_space_string (token.label, sizeof (token.label), "A label");
@@ -854,7 +854,7 @@ test_uri_match_module (CuTest *tc)
        uri = p11_kit_uri_new ();
        CuAssertPtrNotNull (tc, uri);
 
-       ret = p11_kit_uri_parse ("pkcs11:library-description=Quiet", P11_KIT_URI_PARSE_ANY, uri);
+       ret = p11_kit_uri_parse ("pkcs11:library-description=Quiet", P11_KIT_URI_IS_ANY, uri);
        CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
 
        set_space_string (info.libraryDescription, sizeof (info.libraryDescription), "Quiet");
@@ -909,7 +909,7 @@ test_uri_match_attributes (CuTest *tc)
        uri = p11_kit_uri_new ();
        CuAssertPtrNotNull (tc, uri);
 
-       ret = p11_kit_uri_parse ("pkcs11:object=Fancy;id=Blah;objecttype=data", P11_KIT_URI_PARSE_ANY, uri);
+       ret = p11_kit_uri_parse ("pkcs11:object=Fancy;id=Blah;objecttype=data", P11_KIT_URI_IS_ANY, uri);
        CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
 
        ret = p11_kit_uri_match_attributes (uri, attrs, 4);