[PATCH] Add error type registration

Bastien Nocera hadess at hadess.net
Wed Jan 27 06:05:25 PST 2010


The error types need to be registered with dbus-glib to be used.

Fixes possible crashers in geoclue-master and its providers.

See:
https://bugzilla.redhat.com/show_bug.cgi?id=528897#c15

With debugging help from Colin Walters and Matthias Clasen.
---
 .gitignore                   |    2 ++
 docs/reference/geoclue.types |    1 +
 geoclue/Makefile.am          |   39 +++++++++++++++++++++++++++++++++++----
 geoclue/geoclue-error.c      |    1 +
 geoclue/geoclue-error.h      |   20 ++++++++++++++++++--
 geoclue/geoclue-types.c      |    5 +++++
 geoclue/geoclue-types.h      |   17 ++---------------
 7 files changed, 64 insertions(+), 21 deletions(-)

diff --git a/.gitignore b/.gitignore
index 0d1734f..a7c0caa 100644
--- a/.gitignore
+++ b/.gitignore
@@ -37,3 +37,5 @@ example/geoclue-map-example-moving
 example/geoclue-map-layout-example
 example/geoclue-position-example
 geoclue/geoclue-master
+geoclue/geoclue-enum-types.h
+geoclue/geoclue-enum-types.c
diff --git a/docs/reference/geoclue.types b/docs/reference/geoclue.types
index e0ac708..064bb81 100644
--- a/docs/reference/geoclue.types
+++ b/docs/reference/geoclue.types
@@ -23,6 +23,7 @@ geoclue_velocity_get_type
 geoclue_address_get_type
 geoclue_geocode_get_type
 geoclue_reverse_geocode_get_type
+geoclue_error_get_type
 
 gc_web_service_get_type
 gc_provider_get_type
diff --git a/geoclue/Makefile.am b/geoclue/Makefile.am
index 0a8a876..362f19d 100644
--- a/geoclue/Makefile.am
+++ b/geoclue/Makefile.am
@@ -19,7 +19,9 @@ nodist_libgeoclue_la_SOURCES = \
 	gc-iface-velocity-glue.h
 
 BUILT_SOURCES = \
-	$(nodist_libgeoclue_la_SOURCES)
+	$(nodist_libgeoclue_la_SOURCES)	\
+	geoclue-enum-types.h		\
+	geoclue-enum-types.c
 
 libgeoclue_la_SOURCES = 	\
 	geoclue-accuracy.c	\
@@ -41,7 +43,8 @@ libgeoclue_la_SOURCES = 	\
 	gc-iface-geocode.c	\
 	gc-iface-position.c	\
 	gc-iface-reverse-geocode.c	\
-	gc-iface-velocity.c
+	gc-iface-velocity.c	\
+	geoclue-enum-types.c
 
 libgeoclue_la_LIBADD =	\
 	$(GEOCLUE_LIBS)
@@ -71,7 +74,8 @@ geoclue_headers =		\
 	geoclue-position.h	\
 	geoclue-reverse-geocode.h	\
 	geoclue-types.h		\
-	geoclue-velocity.h
+	geoclue-velocity.h	\
+	geoclue-enum-types.h
 
 libgeoclue_includedir = $(includedir)/geoclue
 libgeoclue_include_HEADERS =	\
@@ -89,7 +93,9 @@ CLEANFILES = $(BUILT_SOURCES) 	\
 	stamp-gc-iface-velocity-glue.h
 
 DISTCLEANFILES = \
-	$(nodist_libgeoclue_la_SOURCES)
+	$(nodist_libgeoclue_la_SOURCES)	\
+	geoclue-enum-types.h		\
+	geoclue-enum-types.c
 
 geoclue-marshal.h: geoclue-marshal.list $(GLIB_GENMARSHAL)
 	$(GLIB_GENMARSHAL) $< --header --prefix=geoclue_marshal > $@
@@ -143,3 +149,28 @@ stamp-%-bindings.h: ../interfaces/%.xml
 	&& (cmp -s xgen-$(@F) $(@F:stamp-%=%) || cp xgen-$(@F) $(@F:stamp-%=%)) \
 	&& rm -f xgen-$(@F) \
 	&& echo timestamp > $(@F)
+
+geoclue_headers_to_scan_for_enums = geoclue-error.h
+# Generate the enums source code, with glib-mkenums:
+# This is based on the same Makefile.am stuff in pango:
+geoclue_built_headers = geoclue-enum-types.h
+geoclue_built_cfiles = geoclue-enum-types.c
+
+geoclue-enum-types.h: $(geoclue_headers_to_scan_for_enums) Makefile
+	$(AM_V_GEN) (cd $(srcdir) && glib-mkenums \
+			--fhead "#ifndef __GEOCLUE_ENUM_TYPES_H__\n#define __GEOCLUE_ENUM_TYPES_H__\n\n#include <glib-object.h>\n\nG_BEGIN_DECLS\n" \
+			--fprod "/* enumerations from \"@filename@\" */\n" \
+			--vhead "GType @enum_name at _get_type (void);\n#define GEOCLUE_TYPE_ at ENUMSHORT@ (@enum_name at _get_type())\n" 	\
+			--ftail "G_END_DECLS\n\n#endif /* __GEOCLUE_ENUM_TYPES_H__ */" \
+		$(geoclue_headers_to_scan_for_enums)) > $@
+
+geoclue-enum-types.c: $(geoclue_headers_to_scan_for_enums) Makefile geoclue-enum-types.h
+	$(AM_V_GEN) (cd $(srcdir) && glib-mkenums \
+			--fhead "#include <geoclue-error.h>\n" \
+			--fhead "#include \"geoclue-enum-types.h\"\n" \
+			--fhead "#include <glib-object.h>" \
+			--fprod "\n/* enumerations from \"@filename@\" */" \
+			--vhead "GType\n at enum_name@_get_type (void)\n{\n  static GType etype = 0;\n  if (etype == 0) {\n    static const G at Type@Value values[] = {" 	\
+			--vprod "      { @VALUENAME@, \"@VALUENAME@\", \"@valuenick@\" }," \
+			--vtail "      { 0, NULL, NULL }\n    };\n    etype = g_ at type@_register_static (\"@EnumName@\", values);\n  }\n  return etype;\n}\n" \
+		$(geoclue_headers_to_scan_for_enums)) > $@
diff --git a/geoclue/geoclue-error.c b/geoclue/geoclue-error.c
index fc57fed..54df6ed 100644
--- a/geoclue/geoclue-error.c
+++ b/geoclue/geoclue-error.c
@@ -35,3 +35,4 @@ geoclue_error_quark (void)
 
 	return quark;
 }
+
diff --git a/geoclue/geoclue-error.h b/geoclue/geoclue-error.h
index 2d55304..1138578 100644
--- a/geoclue/geoclue-error.h
+++ b/geoclue/geoclue-error.h
@@ -25,9 +25,25 @@
 #ifndef _GEOCLUE_ERROR_H
 #define _GEOCLUE_ERROR_H
 
-#include <glib.h>
-#include <geoclue/geoclue-types.h>
+#include <glib-object.h>
+#include <geoclue/geoclue-enum-types.h>
 
+/**
+ * GeoclueError:
+ * @GEOCLUE_ERROR_NOT_IMPLEMENTED: Method is not implemented
+ * @GEOCLUE_ERROR_NOT_AVAILABLE: Needed information is not currently
+ * available (e.g. web service did not respond)
+ * @GEOCLUE_ERROR_FAILED: Generic fatal error
+ *
+ * Error values for providers.
+ **/
+typedef enum {
+	GEOCLUE_ERROR_NOT_IMPLEMENTED,
+	GEOCLUE_ERROR_NOT_AVAILABLE,
+	GEOCLUE_ERROR_FAILED,
+} GeoclueError;
+
+#define GEOCLUE_ERROR_DBUS_INTERFACE "org.freedesktop.Geoclue.Error"
 #define GEOCLUE_ERROR (geoclue_error_quark ())
 
 GQuark geoclue_error_quark (void);
diff --git a/geoclue/geoclue-types.c b/geoclue/geoclue-types.c
index 53dba3f..15197b6 100644
--- a/geoclue/geoclue-types.c
+++ b/geoclue/geoclue-types.c
@@ -25,6 +25,7 @@
 #include <geoclue/geoclue-marshal.h>
 #include <geoclue/geoclue-types.h>
 #include <geoclue/geoclue-accuracy.h>
+#include <geoclue/geoclue-error.h>
 
 void
 geoclue_types_init (void)
@@ -61,4 +62,8 @@ geoclue_types_init (void)
 	                                   G_TYPE_STRING,
 	                                   G_TYPE_STRING,
 	                                   G_TYPE_INVALID);
+
+	dbus_g_error_domain_register (GEOCLUE_ERROR,
+				      GEOCLUE_ERROR_DBUS_INTERFACE,
+				      GEOCLUE_TYPE_ERROR);
 }
diff --git a/geoclue/geoclue-types.h b/geoclue/geoclue-types.h
index 5e39fbd..9ecbc40 100644
--- a/geoclue/geoclue-types.h
+++ b/geoclue/geoclue-types.h
@@ -25,6 +25,8 @@
 #ifndef _GEOCLUE_TYPES_H
 #define _GEOCLUE_TYPES_H
 
+#include <geoclue/geoclue-error.h>
+
 /**
  * SECTION:geoclue-types
  * @short_description: Type definitions and defines useful for Geoclue clients 
@@ -99,21 +101,6 @@ typedef enum {
 } GeoclueVelocityFields;
 
 /**
- * GeoclueError:
- * @GEOCLUE_ERROR_NOT_IMPLEMENTED: Method is not implemented
- * @GEOCLUE_ERROR_NOT_AVAILABLE: Needed information is not currently
- * available (e.g. web service did not respond)
- * @GEOCLUE_ERROR_FAILED: Generic fatal error
- * 
- * Error values for providers.
- **/
-typedef enum {
-	GEOCLUE_ERROR_NOT_IMPLEMENTED,
-	GEOCLUE_ERROR_NOT_AVAILABLE,
-	GEOCLUE_ERROR_FAILED,
-} GeoclueError;
-
-/**
  * GEOCLUE_ADDRESS_KEY_COUNTRYCODE:
  * 
  * A key for address hashtables. The hash value should be a ISO 3166 two 
-- 
1.6.6


--=-JCZtD0s7BOGsGxFC7B0w--



More information about the GeoClue mailing list