-allow caller ID to differ from zone used for resolution
[oweals/gnunet.git] / src / transport / plugin_transport_unix.c
index 7bffa220d042f0e343e9eaea861d5928e5f562ae..792d7718ec7063c317ae9f1132ccbbf3b888e01d 100644 (file)
@@ -548,7 +548,7 @@ unix_session_disconnect (void *cls,
        "Disconnecting session for peer `%s' `%s'\n",
        GNUNET_i2s (&s->target),
        unix_address_to_string (NULL, s->address->address, s->address->address_length) );
-  plugin->env->session_end (plugin->env->cls, &s->target, s);
+  plugin->env->session_end (plugin->env->cls, s->address, s);
   removed = GNUNET_NO;
   next = plugin->msg_head;
   while (NULL != next)
@@ -880,6 +880,7 @@ unix_plugin_get_session (void *cls,
   s = GNUNET_new (struct Session);
   s->target = address->peer;
   s->address = GNUNET_HELLO_address_copy (address);
+  s->plugin = plugin;
   GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == s->timeout_task);
   s->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
                                                  &session_timeout,
@@ -1314,7 +1315,17 @@ unix_transport_server_start (void *cls)
     return GNUNET_SYSERR;
   }
   if ('\0' != un->sun_path[0])
-    GNUNET_DISK_directory_create_for_file (un->sun_path);
+  {
+    if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (un->sun_path))
+    {
+      LOG (GNUNET_ERROR_TYPE_ERROR, _("Cannot create path to `%s'\n"),
+          un->sun_path);
+      GNUNET_NETWORK_socket_close (plugin->unix_sock.desc);
+      plugin->unix_sock.desc = NULL;
+      GNUNET_free (un);
+      return GNUNET_SYSERR;
+    }
+  }
   if (GNUNET_OK !=
       GNUNET_NETWORK_socket_bind (plugin->unix_sock.desc, (const struct sockaddr *)  un, un_len))
   {
@@ -1410,18 +1421,11 @@ unix_plugin_address_pretty_printer (void *cls, const char *type,
 {
   if ((NULL != addr) && (addrlen > 0))
   {
-    asc (asc_cls, unix_address_to_string (NULL, addr, addrlen));
-  }
-  else if (0 == addrlen)
-  {
-    asc (asc_cls, TRANSPORT_SESSION_INBOUND_STRING);
+    asc (asc_cls, unix_address_to_string (NULL, addr, addrlen), GNUNET_OK);
   }
   else
-  {
-    GNUNET_break (0);
-    asc (asc_cls, "<invalid UNIX address>");
-  }
-  asc (asc_cls, NULL);
+    asc (asc_cls, NULL, GNUNET_SYSERR);
+  asc (asc_cls, NULL, GNUNET_OK);
 }
 
 
@@ -1671,9 +1675,15 @@ libgnunet_plugin_transport_unix_init (void *cls)
   api->get_network = &unix_get_network;
   api->update_session_timeout = &unix_plugin_update_session_timeout;
   sockets_created = unix_transport_server_start (plugin);
-  if (0 == sockets_created)
+  if ((0 == sockets_created) || (GNUNET_SYSERR == sockets_created))
+  {
     LOG (GNUNET_ERROR_TYPE_WARNING,
         _("Failed to open UNIX listen socket\n"));
+    GNUNET_free (api);
+    GNUNET_free (plugin->unix_socket_path);
+    GNUNET_free (plugin);
+    return NULL;
+  }
   plugin->session_map = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
   plugin->address_update_task = GNUNET_SCHEDULER_add_now (&address_notification, plugin);
   return api;