Lines 10-19
Link Here
|
10 |
#include "charset_utils.h" |
10 |
#include "charset_utils.h" |
11 |
#include "ftpfs.h" |
11 |
#include "ftpfs.h" |
12 |
|
12 |
|
|
|
13 |
#include <ctype.h> |
13 |
#include <string.h> |
14 |
#include <string.h> |
14 |
#include <stdlib.h> |
15 |
#include <stdlib.h> |
15 |
#include <glib.h> |
16 |
#include <glib.h> |
16 |
|
17 |
|
|
|
18 |
/* Converts an integer value to its hex character*/ |
19 |
static char to_hex(char code) { |
20 |
static const char hex[] = "0123456789abcdef"; |
21 |
return hex[code & 15]; |
22 |
} |
23 |
|
24 |
/* Returns a url-encoded version of str */ |
25 |
/* IMPORTANT: be sure to free() the returned string after use */ |
26 |
static char *url_encode(char *str) { |
27 |
char *pstr = str, *buf = malloc(strlen(str) * 3 + 1), *pbuf = buf; |
28 |
while (*pstr) { |
29 |
if (isalnum(*pstr) || *pstr == '-' || *pstr == '_' || *pstr == '.' || *pstr == '~' |
30 |
|| *pstr == ':' || *pstr == '/') |
31 |
*pbuf++ = *pstr; |
32 |
else |
33 |
*pbuf++ = '%', *pbuf++ = to_hex(*pstr >> 4), *pbuf++ = to_hex(*pstr & 15); |
34 |
pstr++; |
35 |
} |
36 |
*pbuf = '\0'; |
37 |
free(str); |
38 |
return buf; |
39 |
} |
40 |
|
17 |
char* get_file_name(const char* path) { |
41 |
char* get_file_name(const char* path) { |
18 |
const char* filename = strrchr(path, '/'); |
42 |
const char* filename = strrchr(path, '/'); |
19 |
if (filename == NULL) filename = path; |
43 |
if (filename == NULL) filename = path; |
Lines 24-29
char* get_file_name(const char* path) {
Link Here
|
24 |
convert_charsets(ftpfs.iocharset, ftpfs.codepage, &ret); |
47 |
convert_charsets(ftpfs.iocharset, ftpfs.codepage, &ret); |
25 |
} |
48 |
} |
26 |
|
49 |
|
|
|
50 |
ret = url_encode(ret); |
27 |
return ret; |
51 |
return ret; |
28 |
} |
52 |
} |
29 |
|
53 |
|
Lines 43-48
char* get_full_path(const char* path) {
Link Here
|
43 |
|
67 |
|
44 |
free(converted_path); |
68 |
free(converted_path); |
45 |
|
69 |
|
|
|
70 |
ret = url_encode(ret); |
46 |
return ret; |
71 |
return ret; |
47 |
} |
72 |
} |
48 |
|
73 |
|
Lines 62-67
char* get_fulldir_path(const char* path) {
Link Here
|
62 |
|
87 |
|
63 |
free(converted_path); |
88 |
free(converted_path); |
64 |
|
89 |
|
|
|
90 |
ret = url_encode(ret); |
65 |
return ret; |
91 |
return ret; |
66 |
} |
92 |
} |
67 |
|
93 |
|
Lines 90-94
char* get_dir_path(const char* path) {
Link Here
|
90 |
|
116 |
|
91 |
free(converted_path); |
117 |
free(converted_path); |
92 |
|
118 |
|
|
|
119 |
ret = url_encode(ret); |
93 |
return ret; |
120 |
return ret; |
94 |
} |
121 |
} |
95 |
- |
|
|