diff options
| author | 2010-12-04 04:10:23 +0100 | |
|---|---|---|
| committer | 2011-04-11 19:42:19 +0200 | |
| commit | aae3469d1b6cc825c046a2fb0e9fa06c8eb945ca (patch) | |
| tree | 049bc1a326389b74cc60da1fa783428e6152960c /tools/idevicebackup4.c | |
| parent | 1234b3b64e03ec65b0aeb23272d6816266a366a6 (diff) | |
| download | libimobiledevice-aae3469d1b6cc825c046a2fb0e9fa06c8eb945ca.tar.gz libimobiledevice-aae3469d1b6cc825c046a2fb0e9fa06c8eb945ca.tar.bz2 | |
idevicebackup4: basic implementation of DLContentsOfDirectory
Diffstat (limited to 'tools/idevicebackup4.c')
| -rw-r--r-- | tools/idevicebackup4.c | 49 |
1 files changed, 47 insertions, 2 deletions
diff --git a/tools/idevicebackup4.c b/tools/idevicebackup4.c index d07638b..4ebe34b 100644 --- a/tools/idevicebackup4.c +++ b/tools/idevicebackup4.c | |||
| @@ -26,6 +26,7 @@ | |||
| 26 | #include <stdlib.h> | 26 | #include <stdlib.h> |
| 27 | #include <signal.h> | 27 | #include <signal.h> |
| 28 | #include <glib.h> | 28 | #include <glib.h> |
| 29 | #include <glib/gstdio.h> | ||
| 29 | #include <gcrypt.h> | 30 | #include <gcrypt.h> |
| 30 | #include <unistd.h> | 31 | #include <unistd.h> |
| 31 | 32 | ||
| @@ -1125,8 +1126,52 @@ static void handle_list_directory(plist_t message, const char *backup_dir) | |||
| 1125 | { | 1126 | { |
| 1126 | if (!message || (plist_get_node_type(message) != PLIST_ARRAY) || plist_array_get_size(message) < 2 || !backup_dir) return; | 1127 | if (!message || (plist_get_node_type(message) != PLIST_ARRAY) || plist_array_get_size(message) < 2 || !backup_dir) return; |
| 1127 | 1128 | ||
| 1128 | /* TODO implement, for now we just return an empty listing */ | 1129 | plist_t node = plist_array_get_item(message, 1); |
| 1129 | mobilebackup2_error_t err = mobilebackup2_send_status_response(mobilebackup2, 0, NULL, plist_new_dict()); | 1130 | char *str = NULL; |
| 1131 | if (plist_get_node_type(node) == PLIST_STRING) { | ||
| 1132 | plist_get_string_val(node, &str); | ||
| 1133 | } | ||
| 1134 | if (!str) { | ||
| 1135 | printf("ERROR: Malformed DLContentsOfDirectoryMessage\n"); | ||
| 1136 | // TODO error handling | ||
| 1137 | return; | ||
| 1138 | } | ||
| 1139 | |||
| 1140 | gchar *path = g_build_path(G_DIR_SEPARATOR_S, backup_dir, str, NULL); | ||
| 1141 | free(str); | ||
| 1142 | |||
| 1143 | plist_t dirlist = plist_new_dict(); | ||
| 1144 | |||
| 1145 | GDir *cur_dir = g_dir_open(path, 0, NULL); | ||
| 1146 | if (cur_dir) { | ||
| 1147 | gchar *dir_file; | ||
| 1148 | while ((dir_file = g_dir_read_name(cur_dir))) { | ||
| 1149 | gchar *fpath = g_build_filename(path, dir_file, NULL); | ||
| 1150 | if (fpath) { | ||
| 1151 | plist_t fdict = plist_new_dict(); | ||
| 1152 | GStatBuf st; | ||
| 1153 | g_stat(fpath, &st); | ||
| 1154 | if (g_file_test(fpath, G_FILE_TEST_IS_DIR)) { | ||
| 1155 | plist_dict_insert_item(fdict, "DLFileType", plist_new_string("DLFileTypeDirectory")); | ||
| 1156 | } else if (g_file_test(fpath, G_FILE_TEST_IS_REGULAR)) { | ||
| 1157 | plist_dict_insert_item(fdict, "DLFileType", plist_new_string("DLFileTypeRegular")); | ||
| 1158 | } else { | ||
| 1159 | printf("%s: TODO implement other file types\n", __func__); | ||
| 1160 | } | ||
| 1161 | plist_dict_insert_item(fdict, "DLFileSize", plist_new_uint(st.st_size)); | ||
| 1162 | plist_dict_insert_item(fdict, "DLFileModificationDate", plist_new_date(st.st_mtime, 0)); | ||
| 1163 | |||
| 1164 | plist_dict_insert_item(dirlist, dir_file, fdict); | ||
| 1165 | g_free(fpath); | ||
| 1166 | } | ||
| 1167 | } | ||
| 1168 | g_dir_close(cur_dir); | ||
| 1169 | } | ||
| 1170 | g_free(path); | ||
| 1171 | |||
| 1172 | /* TODO error handling */ | ||
| 1173 | mobilebackup2_error_t err = mobilebackup2_send_status_response(mobilebackup2, 0, NULL, dirlist); | ||
| 1174 | plist_free(dirlist); | ||
| 1130 | if (err != MOBILEBACKUP2_E_SUCCESS) { | 1175 | if (err != MOBILEBACKUP2_E_SUCCESS) { |
| 1131 | printf("Could not send status response, error %d\n", err); | 1176 | printf("Could not send status response, error %d\n", err); |
| 1132 | } | 1177 | } |
