diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-06-20 18:45:30 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-06-20 18:45:30 +0000 |
commit | adf27a6356d67c4bef76f3560aa4abce5f71528f (patch) | |
tree | 8252c4e9d314d721ebe76f8b9a1655de00ddedb3 /src/util/network.c | |
parent | 8d9db9ddae163bc412ccfe301ea3d95298bb787f (diff) | |
download | gnunet-adf27a6356d67c4bef76f3560aa4abce5f71528f.tar.gz gnunet-adf27a6356d67c4bef76f3560aa4abce5f71528f.zip |
-fixing #2439
Diffstat (limited to 'src/util/network.c')
-rw-r--r-- | src/util/network.c | 48 |
1 files changed, 45 insertions, 3 deletions
diff --git a/src/util/network.c b/src/util/network.c index ed7e8be30..ca8105fc7 100644 --- a/src/util/network.c +++ b/src/util/network.c | |||
@@ -22,12 +22,11 @@ | |||
22 | * @file util/network.c | 22 | * @file util/network.c |
23 | * @brief basic, low-level networking interface | 23 | * @brief basic, low-level networking interface |
24 | * @author Nils Durner | 24 | * @author Nils Durner |
25 | * @author Christian Grothoff | ||
25 | */ | 26 | */ |
26 | |||
27 | #include "platform.h" | 27 | #include "platform.h" |
28 | #include "gnunet_disk_lib.h" | ||
29 | #include "disk.h" | 28 | #include "disk.h" |
30 | #include "gnunet_container_lib.h" | 29 | #include "gnunet_util_lib.h" |
31 | 30 | ||
32 | #define LOG(kind,...) GNUNET_log_from (kind, "util", __VA_ARGS__) | 31 | #define LOG(kind,...) GNUNET_log_from (kind, "util", __VA_ARGS__) |
33 | #define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util", syscall, filename) | 32 | #define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util", syscall, filename) |
@@ -67,6 +66,49 @@ struct GNUNET_NETWORK_Handle | |||
67 | }; | 66 | }; |
68 | 67 | ||
69 | 68 | ||
69 | /** | ||
70 | * Given a unixpath that is too long (larger than UNIX_PATH_MAX), | ||
71 | * shorten it to an acceptable length while keeping it unique | ||
72 | * and making sure it remains a valid filename (if possible). | ||
73 | * | ||
74 | * @param unixpath long path, will be freed (or same pointer returned | ||
75 | * with moved 0-termination). | ||
76 | * @return shortened unixpath, NULL on error | ||
77 | */ | ||
78 | char * | ||
79 | GNUNET_NETWORK_shorten_unixpath (char *unixpath) | ||
80 | { | ||
81 | struct sockaddr_un dummy; | ||
82 | size_t slen; | ||
83 | char *end; | ||
84 | struct GNUNET_CRYPTO_ShortHashCode sh; | ||
85 | struct GNUNET_CRYPTO_ShortHashAsciiEncoded ae; | ||
86 | size_t upm; | ||
87 | |||
88 | upm = sizeof (dummy.sun_path); | ||
89 | slen = strlen (unixpath); | ||
90 | if (slen < upm) | ||
91 | return unixpath; /* no shortening required */ | ||
92 | GNUNET_CRYPTO_short_hash (unixpath, slen, &sh); | ||
93 | while (sizeof (struct GNUNET_CRYPTO_ShortHashAsciiEncoded) + | ||
94 | strlen (unixpath) >= upm) | ||
95 | { | ||
96 | if (NULL == (end = strrchr (unixpath, '/'))) | ||
97 | { | ||
98 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
99 | _("Unable to shorten unix path `%s' while keeping name unique\n"), | ||
100 | unixpath); | ||
101 | GNUNET_free (unixpath); | ||
102 | return NULL; | ||
103 | } | ||
104 | *end = '\0'; | ||
105 | } | ||
106 | GNUNET_CRYPTO_short_hash_to_enc (&sh, &ae); | ||
107 | strcat (unixpath, (char*) ae.short_encoding); | ||
108 | return unixpath; | ||
109 | } | ||
110 | |||
111 | |||
70 | #ifndef FD_COPY | 112 | #ifndef FD_COPY |
71 | #define FD_COPY(s, d) (memcpy ((d), (s), sizeof (fd_set))) | 113 | #define FD_COPY(s, d) (memcpy ((d), (s), sizeof (fd_set))) |
72 | #endif | 114 | #endif |