- struct GNUNET_PEERINFO_HelloAddressParsingContext *ctx = cls;
- const char *tname;
- const char *address;
- char *uri_address;
- char *plugin_address;
- const char *end;
- char *plugin_name;
- struct tm expiration_time;
- time_t expiration_seconds;
- struct GNUNET_TIME_Absolute expire;
- struct GNUNET_TRANSPORT_PluginFunctions *papi;
- void *addr;
- size_t addr_len;
- struct GNUNET_HELLO_Address haddr;
- size_t ret;
-
- if (NULL == ctx->pos)
- return 0;
- if ('!' != ctx->pos[0])
- {
- ctx->ret = GNUNET_SYSERR;
- GNUNET_break (0);
- return 0;
- }
- ctx->pos++;
- memset (&expiration_time, 0, sizeof (expiration_time));
- tname = strptime (ctx->pos,
- "%Y%m%d%H%M%S",
- &expiration_time);
-
- if (NULL == tname)
- {
- ctx->ret = GNUNET_SYSERR;
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to parse HELLO message: missing expiration time\n"));
- GNUNET_break (0);
- return 0;
- }
- expiration_seconds = mktime (&expiration_time);
- if (expiration_seconds == (time_t) -1)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to parse HELLO message: invalid expiration time\n"));
- ctx->ret = GNUNET_SYSERR;
- GNUNET_break (0);
- return 0;
- }
- expire.abs_value = expiration_seconds * 1000;
- if ('!' != tname[0])
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to parse HELLO message: malformed\n"));
- ctx->ret = GNUNET_SYSERR;
- GNUNET_break (0);
- return 0;
- }
- tname++;
- address = strchr (tname, (int) '!');
- if (NULL == address)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to parse HELLO message: missing transport plugin\n"));
- ctx->ret = GNUNET_SYSERR;
- GNUNET_break (0);
- return 0;
- }
- address++;
- end = strchr (address, (int) '!');
- ctx->pos = end;
- plugin_name = GNUNET_strndup (tname, address - (tname+1));
- papi = GPI_plugins_find (plugin_name);
- if (NULL == papi)
- {
- /* Not an error - we might just not have the right plugin.
- * Skip this part, advance to the next one and recurse.
- * But only if this is not the end of string.
- */
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Plugin `%s' not found\n"),
- plugin_name);
- GNUNET_free (plugin_name);
- GNUNET_break (0);
- return 0;
- }
- if (NULL == papi->string_to_address)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Plugin `%s' does not support URIs yet\n"),
- plugin_name);
- GNUNET_free (plugin_name);
- GNUNET_break (0);
- return 0;
- }
- uri_address = GNUNET_strndup (address, end - address);
- /* For URIs we use '(' and ')' instead of '[' and ']' as brackets are reserved
- characters in URIs; need to convert back to '[]' for the plugin */
- plugin_address = map_characters (uri_address, "()", "[]");
- GNUNET_free (uri_address);
- if (GNUNET_OK !=
- papi->string_to_address (papi->cls,
- plugin_address,
- strlen (plugin_address),
- &addr,
- &addr_len))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to parse `%s'\n"),
- plugin_address);
- GNUNET_free (plugin_name);
- GNUNET_free (plugin_address);
- return 0;
- }
- GNUNET_free (plugin_address);
- /* address.peer is unset - not used by add_address() */
- haddr.address_length = addr_len;
- haddr.address = addr;
- haddr.transport_name = plugin_name;
- ret = GNUNET_HELLO_add_address (&haddr, expire, buffer, max);
- GNUNET_free (addr);
- GNUNET_free (plugin_name);
- return ret;