(mu_tilde_expansion): Expand tilde after the protocol specification.
Showing
1 changed file
with
45 additions
and
14 deletions
... | @@ -184,8 +184,32 @@ mu_get_full_path (const char *file) | ... | @@ -184,8 +184,32 @@ mu_get_full_path (const char *file) |
184 | char * | 184 | char * |
185 | mu_tilde_expansion (const char *ref, const char *delim, const char *homedir) | 185 | mu_tilde_expansion (const char *ref, const char *delim, const char *homedir) |
186 | { | 186 | { |
187 | char *p = strdup (ref); | 187 | char *base = strdup (ref); |
188 | char *home = NULL; | 188 | char *home = NULL; |
189 | char *proto = NULL; | ||
190 | size_t proto_len = 0; | ||
191 | char *p; | ||
192 | |||
193 | for (p = base; *p && isascii (*p) && isalnum (*p); p++) | ||
194 | ; | ||
195 | |||
196 | if (*p == ':') | ||
197 | { | ||
198 | p++; | ||
199 | proto_len = p - base; | ||
200 | proto = malloc (proto_len + 1); | ||
201 | if (!proto) | ||
202 | return NULL; | ||
203 | memcpy (proto, base, proto_len); | ||
204 | proto[proto_len] = 0; | ||
205 | /* Allow for extra pair of slashes after the protocol specifier */ | ||
206 | if (*p == delim[0]) | ||
207 | p++; | ||
208 | if (*p == delim[0]) | ||
209 | p++; | ||
210 | } | ||
211 | else | ||
212 | p = base; | ||
189 | 213 | ||
190 | if (*p == '~') | 214 | if (*p == '~') |
191 | { | 215 | { |
... | @@ -197,14 +221,18 @@ mu_tilde_expansion (const char *ref, const char *delim, const char *homedir) | ... | @@ -197,14 +221,18 @@ mu_tilde_expansion (const char *ref, const char *delim, const char *homedir) |
197 | { | 221 | { |
198 | home = mu_get_homedir (); | 222 | home = mu_get_homedir (); |
199 | if (!home) | 223 | if (!home) |
200 | return NULL; | 224 | return base; |
201 | homedir = home; | 225 | homedir = home; |
202 | } | 226 | } |
203 | s = calloc (strlen (homedir) + strlen (p) + 1, 1); | 227 | s = calloc (proto_len + strlen (homedir) + strlen (p) + 1, 1); |
204 | strcpy (s, homedir); | 228 | if (proto_len) |
229 | strcpy (s, proto); | ||
230 | else | ||
231 | s[0] = 0; | ||
232 | strcat (s, homedir); | ||
205 | strcat (s, p); | 233 | strcat (s, p); |
206 | free (--p); | 234 | free (base); |
207 | p = s; | 235 | base = s; |
208 | } | 236 | } |
209 | else | 237 | else |
210 | { | 238 | { |
... | @@ -215,26 +243,29 @@ mu_tilde_expansion (const char *ref, const char *delim, const char *homedir) | ... | @@ -215,26 +243,29 @@ mu_tilde_expansion (const char *ref, const char *delim, const char *homedir) |
215 | s++; | 243 | s++; |
216 | name = calloc (s - p + 1, 1); | 244 | name = calloc (s - p + 1, 1); |
217 | memcpy (name, p, s - p); | 245 | memcpy (name, p, s - p); |
218 | name [s - p] = '\0'; | 246 | name[s - p] = '\0'; |
219 | 247 | ||
220 | auth = mu_get_auth_by_name (name); | 248 | auth = mu_get_auth_by_name (name); |
221 | free (name); | 249 | free (name); |
222 | if (auth) | 250 | if (auth) |
223 | { | 251 | { |
224 | char *buf = calloc (strlen (auth->dir) + strlen (s) + 1, 1); | 252 | char *buf = calloc (proto_len + strlen (auth->dir) |
225 | strcpy (buf, auth->dir); | 253 | + strlen (s) + 1, 1); |
254 | if (proto_len) | ||
255 | strcpy (buf, proto); | ||
256 | else | ||
257 | buf[0] = 0; | ||
258 | strcat (buf, auth->dir); | ||
226 | strcat (buf, s); | 259 | strcat (buf, s); |
227 | free (--p); | 260 | free (base); |
228 | p = buf; | 261 | base = buf; |
229 | mu_auth_data_free (auth); | 262 | mu_auth_data_free (auth); |
230 | } | 263 | } |
231 | else | ||
232 | p--; | ||
233 | } | 264 | } |
234 | } | 265 | } |
235 | if (home) | 266 | if (home) |
236 | free (home); | 267 | free (home); |
237 | return p; | 268 | return base; |
238 | } | 269 | } |
239 | 270 | ||
240 | /* Smart strncpy that always add the null and returns the number of bytes | 271 | /* Smart strncpy that always add the null and returns the number of bytes | ... | ... |
-
Please register or sign in to post a comment