-/**
- * Handle a shorten message from the api
- *
- * @param cls the closure (unused)
- * @param client the client
- * @param message the message
- */
-static void
-handle_shorten (void *cls,
- struct GNUNET_SERVER_Client * client,
- const struct GNUNET_MessageHeader * message)
-{
- struct ClientShortenHandle *csh;
- const char *utf_in;
- char name[MAX_DNS_NAME_LENGTH];
- char* nameptr = name;
- uint16_t msg_size;
- const struct GNUNET_GNS_ClientShortenMessage *sh_msg;
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "SHORTEN");
- msg_size = ntohs (message->size);
- if (msg_size < sizeof (struct GNUNET_GNS_ClientShortenMessage))
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
- sh_msg = (const struct GNUNET_GNS_ClientShortenMessage *) message;
- utf_in = (const char *) &sh_msg[1];
- if ('\0' != utf_in[msg_size - sizeof (struct GNUNET_GNS_ClientShortenMessage) - 1])
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
- csh = GNUNET_malloc(sizeof (struct ClientShortenHandle));
- csh->client = client;
- csh->request_id = sh_msg->id;
- GNUNET_CONTAINER_DLL_insert (csh_head, csh_tail, csh);
- GNUNET_STRINGS_utf8_tolower (utf_in, &nameptr);
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "SHORTEN: Converted `%s' to `%s'\n",
- utf_in,
- nameptr);
- GNUNET_SERVER_notification_context_add (nc, client);
- if (strlen (name) < strlen (GNUNET_GNS_TLD))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "SHORTEN: %s is too short\n", name);
- GNUNET_CONTAINER_DLL_remove (csh_head, csh_tail, csh);
- send_shorten_response(csh, name);
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
- return;
- }
- if (strlen (name) > MAX_DNS_NAME_LENGTH)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "SHORTEN: %s is too long\n", name);
- GNUNET_CONTAINER_DLL_remove (csh_head, csh_tail, csh);
- send_shorten_response(csh, name);
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
- return;
- }
- if ( (! is_gnunet_tld (name)) &&
- (! is_zkey_tld (name)) )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "%s is not our domain. Returning\n", name);
- GNUNET_CONTAINER_DLL_remove (csh_head, csh_tail, csh);
- send_shorten_response (csh, name);
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
- return;
- }
- csh->shorten_zone = sh_msg->shorten_zone;
- csh->private_zone = sh_msg->private_zone;
- strcpy (csh->name, name);
- if (1 == ntohl(sh_msg->use_default_zone))
- csh->root_zone = zone_hash; //Default zone
- else
- csh->root_zone = sh_msg->zone;
- start_shorten_name (csh);