summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorMarcus Meissner <meissner@suse.de>2019-04-23 11:48:13 +0200
committerMarcus Meissner <meissner@suse.de>2019-04-23 11:48:13 +0200
commit560e15d3f4e51f1dcf161e9fbaac4922ecd51649 (patch)
treed890478c31f5851de86535ab3e4c5c6c7821b3d5 /examples
parent501978309097bb0cfc456be4ccc515bb4811b193 (diff)
downloadlibgphoto2-560e15d3f4e51f1dcf161e9fbaac4922ecd51649.tar.gz
let the sample-afl do autodetection to allow fuzzing all USB cameras
Diffstat (limited to 'examples')
-rw-r--r--examples/sample-afl.c42
1 files changed, 36 insertions, 6 deletions
diff --git a/examples/sample-afl.c b/examples/sample-afl.c
index 15bb86ca5..c01414bbc 100644
--- a/examples/sample-afl.c
+++ b/examples/sample-afl.c
@@ -131,14 +131,20 @@ recursive_directory(Camera *camera, const char *folder, GPContext *context, int
int main(int argc, char **argv) {
Camera *camera = NULL;
- int ret, storagecnt;
+ int count, ret, storagecnt;
CameraStorageInformation *storageinfo;
+ GPPortInfo gpinfo;
+ GPPortInfoList *gpinfolist;
GPContext *context;
CameraWidget *rootwidget;
char buf[200];
- CameraText summary;
- CameraFile *file;
- CameraFilePath path;
+ const char *name;
+ CameraText summary;
+ CameraFile *file;
+ CameraFilePath path;
+ CameraList *list;
+ CameraAbilitiesList *abilities = NULL;
+
gp_log_add_func(GP_LOG_DEBUG, errordumper, NULL);
@@ -150,9 +156,33 @@ int main(int argc, char **argv) {
fprintf(stderr,"setting path %s.\n", buf);
- ret = sample_open_camera (&camera, "USB PTP Class Camera", buf, context);
+ gp_port_info_list_new (&gpinfolist);
+ ret = gp_port_info_list_load (gpinfolist);
+ if (ret < GP_OK) return ret;
+
+ ret = gp_port_info_list_lookup_path (gpinfolist, buf);
+ if (ret < GP_OK) return ret;
+
+ /* Detect all the cameras that can be autodetected... */
+ ret = gp_list_new (&list);
+ if (ret < GP_OK) return 1;
+
+ /* Load all the camera drivers we have... */
+ ret = gp_abilities_list_new (&abilities);
+ if (ret < GP_OK) return ret;
+ ret = gp_abilities_list_load (abilities, context);
+ if (ret < GP_OK) return ret;
+ ret = gp_abilities_list_detect (abilities, gpinfolist, list, context);
+ if (ret < GP_OK) return ret;
+
+ fprintf(stderr, "detect list has count %d\n", gp_list_count(list));
+
+ ret = gp_list_get_name(list, 0, &name);
+ if (ret < GP_OK) goto out;
+
+ ret = sample_open_camera (&camera, name, buf, context);
if (ret < GP_OK) {
- fprintf(stderr,"camera %s not found.\n", buf);
+ fprintf(stderr,"camera %s at %s not found.\n", name, buf);
goto out;
}