+/**
+ * Extract a type map from a TYPE_MAP message.
+ *
+ * @param msg a type map message
+ * @return NULL on error
+ */
+struct GSC_TypeMap *
+GSC_TYPEMAP_get_from_message (const struct GNUNET_MessageHeader *msg)
+{
+ struct GSC_TypeMap *ret;
+ uint16_t size;
+ uLongf dlen;
+
+ size = ntohs (msg->size);
+ switch (ntohs (msg->type))
+ {
+ case GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP:
+ GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# type maps received"),
+ 1, GNUNET_NO);
+ if (size != sizeof (struct GSC_TypeMap))
+ {
+ GNUNET_break_op (0);
+ return NULL;
+ }
+ ret = GNUNET_malloc (sizeof (struct GSC_TypeMap));
+ memcpy (ret, &msg[1], sizeof (struct GSC_TypeMap));
+ return ret;
+ case GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP:
+ GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# type maps received"),
+ 1, GNUNET_NO);
+ ret = GNUNET_malloc (sizeof (struct GSC_TypeMap));
+ dlen = sizeof (struct GSC_TypeMap);
+ if ((Z_OK !=
+ uncompress ((Bytef *) ret, &dlen, (const Bytef *) &msg[1],
+ (uLong) size)) || (dlen != sizeof (struct GSC_TypeMap)))
+ {
+ GNUNET_break_op (0);
+ GNUNET_free (ret);
+ return NULL;
+ }
+ return ret;
+ default:
+ GNUNET_break (0);
+ return NULL;
+ }
+}
+
+