OLD | NEW |
1 /** | 1 /** |
2 * \file detect.c | 2 * \file detect.c |
3 * Example program to detect a device and list capabilities. | 3 * Example program to detect a device and list capabilities. |
4 * | 4 * |
5 * Copyright (C) 2005-2008 Linus Walleij <triad@df.lth.se> | 5 * Copyright (C) 2005-2015 Linus Walleij <triad@df.lth.se> |
6 * Copyright (C) 2007 Ted Bullock <tbullock@canada.com> | 6 * Copyright (C) 2007 Ted Bullock <tbullock@canada.com> |
7 * | 7 * |
8 * This library is free software; you can redistribute it and/or | 8 * This library is free software; you can redistribute it and/or |
9 * modify it under the terms of the GNU Lesser General Public | 9 * modify it under the terms of the GNU Lesser General Public |
10 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
11 * version 2 of the License, or (at your option) any later version. | 11 * version 2 of the License, or (at your option) any later version. |
12 * | 12 * |
13 * This library is distributed in the hope that it will be useful, | 13 * This library is distributed in the hope that it will be useful, |
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 case LIBMTP_ERROR_GENERAL: | 123 case LIBMTP_ERROR_GENERAL: |
124 default: | 124 default: |
125 fprintf(stderr, "Unknown connection error.\n"); | 125 fprintf(stderr, "Unknown connection error.\n"); |
126 return 1; | 126 return 1; |
127 } | 127 } |
128 | 128 |
129 /* Iterate over connected MTP devices */ | 129 /* Iterate over connected MTP devices */ |
130 fprintf(stdout, "Attempting to connect device(s)\n"); | 130 fprintf(stdout, "Attempting to connect device(s)\n"); |
131 for (i = 0; i < numrawdevices; i++) { | 131 for (i = 0; i < numrawdevices; i++) { |
132 LIBMTP_mtpdevice_t *device; | 132 LIBMTP_mtpdevice_t *device; |
133 LIBMTP_file_t *files; | 133 LIBMTP_devicestorage_t *storage; |
134 char *friendlyname; | 134 char *friendlyname; |
135 char *syncpartner; | 135 char *syncpartner; |
136 char *sectime; | 136 char *sectime; |
137 char *devcert; | 137 char *devcert; |
138 uint16_t *filetypes; | 138 uint16_t *filetypes; |
139 uint16_t filetypes_len; | 139 uint16_t filetypes_len; |
140 uint8_t maxbattlevel; | 140 uint8_t maxbattlevel; |
141 uint8_t currbattlevel; | 141 uint8_t currbattlevel; |
142 int ret; | 142 int ret; |
143 | 143 |
144 device = LIBMTP_Open_Raw_Device(&rawdevices[i]); | 144 device = LIBMTP_Open_Raw_Device_Uncached(&rawdevices[i]); |
145 if (device == NULL) { | 145 if (device == NULL) { |
146 fprintf(stderr, "Unable to open raw device %d\n", i); | 146 fprintf(stderr, "Unable to open raw device %d\n", i); |
147 continue; | 147 continue; |
148 } | 148 } |
149 | 149 |
150 LIBMTP_Dump_Errorstack(device); | 150 LIBMTP_Dump_Errorstack(device); |
151 LIBMTP_Clear_Errorstack(device); | 151 LIBMTP_Clear_Errorstack(device); |
152 LIBMTP_Dump_Device_Info(device); | 152 LIBMTP_Dump_Device_Info(device); |
153 | 153 |
154 printf("MTP-specific device properties:\n"); | 154 printf("MTP-specific device properties:\n"); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 ret = LIBMTP_Get_Secure_Time(device, §ime); | 196 ret = LIBMTP_Get_Secure_Time(device, §ime); |
197 if (ret == 0 && sectime != NULL) { | 197 if (ret == 0 && sectime != NULL) { |
198 fprintf(stdout, "\nSecure Time:\n%s\n", sectime); | 198 fprintf(stdout, "\nSecure Time:\n%s\n", sectime); |
199 free(sectime); | 199 free(sectime); |
200 } else { | 200 } else { |
201 // Silently ignore - there may be devices not supporting secure time. | 201 // Silently ignore - there may be devices not supporting secure time. |
202 LIBMTP_Clear_Errorstack(device); | 202 LIBMTP_Clear_Errorstack(device); |
203 } | 203 } |
204 | 204 |
205 // Device certificate XML fragment | 205 // Device certificate XML fragment |
206 #if 0 | 206 if (rawdevices[i].device_entry.vendor_id == 0x041e) { |
207 /* | 207 /* |
208 * This code is currently disabled: all devices say that | 208 * This code is currently disabled except for vendors we |
209 * they support getting a device certificate but a lot of | 209 * know does support it: all devices say that |
210 * them obviously doesn't, instead they crash when you try | 210 * they support getting a device certificate but a lot of |
211 * to obtain it. | 211 * them obviously doesn't, instead they crash when you try |
212 */ | 212 * to obtain it. |
213 ret = LIBMTP_Get_Device_Certificate(device, &devcert); | 213 */ |
214 if (ret == 0 && devcert != NULL) { | 214 ret = LIBMTP_Get_Device_Certificate(device, &devcert); |
215 fprintf(stdout, "\nDevice Certificate:\n%s\n", devcert); | 215 if (ret == 0 && devcert != NULL) { |
216 free(devcert); | 216 » fprintf(stdout, "\nDevice Certificate:\n%s\n", devcert); |
217 } else { | 217 » free(devcert); |
218 fprintf(stdout, "Unable to acquire device certificate, perhaps this device
" | 218 } else { |
219 » "does not support this\n"); | 219 » fprintf(stdout, "Unable to acquire device certificate, perhaps this devi
ce " |
220 LIBMTP_Dump_Errorstack(device); | 220 » » "does not support this\n"); |
221 LIBMTP_Clear_Errorstack(device); | 221 » LIBMTP_Dump_Errorstack(device); |
| 222 » LIBMTP_Clear_Errorstack(device); |
| 223 } |
222 } | 224 } |
223 #endif | |
224 | 225 |
225 // Try to get Media player device info XML file... | 226 /* Try to get Media player device info XML file... */ |
226 files = LIBMTP_Get_Filelisting_With_Callback(device, NULL, NULL); | 227 /* Loop over storages */ |
227 if (files != NULL) { | 228 for (storage = device->storage; storage != 0; storage = storage->next) { |
228 LIBMTP_file_t *file, *tmp; | 229 LIBMTP_file_t *files; |
229 file = files; | 230 |
230 while (file != NULL) { | 231 /* Get file listing for the root directory, no other dirs */ |
231 » if (!strcmp(file->filename, "WMPInfo.xml") || | 232 files = LIBMTP_Get_Files_And_Folders(device, |
232 » !strcmp(file->filename, "WMPinfo.xml") || | 233 » » » » » storage->id, |
233 » !strcmp(file->filename, "default-capabilities.xml")) { | 234 » » » » » 0); |
| 235 |
| 236 if (files != NULL) { |
| 237 » LIBMTP_file_t *file, *tmp; |
| 238 » file = files; |
| 239 » while (file != NULL) { |
| 240 » if (!strcmp(file->filename, "WMPInfo.xml") || |
| 241 » !strcmp(file->filename, "WMPinfo.xml") || |
| 242 » !strcmp(file->filename, "default-capabilities.xml")) { |
234 if (file->item_id != 0) { | 243 if (file->item_id != 0) { |
235 /* Dump this file */ | 244 /* Dump this file */ |
236 FILE *xmltmp = tmpfile(); | 245 FILE *xmltmp = tmpfile(); |
237 int tmpfiledescriptor = fileno(xmltmp); | 246 int tmpfiledescriptor = fileno(xmltmp); |
238 | 247 |
239 if (tmpfiledescriptor != -1) { | 248 if (tmpfiledescriptor != -1) { |
240 int ret = LIBMTP_Get_Track_To_File_Descriptor(device, | 249 int ret = LIBMTP_Get_Track_To_File_Descriptor(device, |
241 file->item_id, | 250 file->item_id, |
242 tmpfiledescriptor, | 251 tmpfiledescriptor, |
243 NULL, | 252 NULL, |
(...skipping 23 matching lines...) Expand all Loading... |
267 LIBMTP_Clear_Errorstack(device); | 276 LIBMTP_Clear_Errorstack(device); |
268 } | 277 } |
269 free(buf); | 278 free(buf); |
270 } else { | 279 } else { |
271 LIBMTP_Dump_Errorstack(device); | 280 LIBMTP_Dump_Errorstack(device); |
272 LIBMTP_Clear_Errorstack(device); | 281 LIBMTP_Clear_Errorstack(device); |
273 } | 282 } |
274 fclose(xmltmp); | 283 fclose(xmltmp); |
275 } | 284 } |
276 } | 285 } |
| 286 } |
| 287 tmp = file; |
| 288 file = file->next; |
| 289 LIBMTP_destroy_file_t(tmp); |
277 } | 290 } |
278 tmp = file; | |
279 file = file->next; | |
280 LIBMTP_destroy_file_t(tmp); | |
281 } | 291 } |
282 } | 292 } |
283 LIBMTP_Release_Device(device); | 293 LIBMTP_Release_Device(device); |
284 } /* End For Loop */ | 294 } /* End For Loop */ |
285 | 295 |
286 free(rawdevices); | 296 free(rawdevices); |
287 | 297 |
288 printf("OK.\n"); | 298 printf("OK.\n"); |
289 | 299 |
290 return 0; | 300 return 0; |
291 } | 301 } |
OLD | NEW |