diff --git a/NEWS b/NEWS index 37761953f..007503f81 100644 --- a/NEWS +++ b/NEWS @@ -13,6 +13,7 @@ Package / System integration: * Add README.packaging file for packagers. * Removed obsolete print-usb-usermap. Use "print-camera-list usb-usermap usbcam" instead. + * New syntax for print-camera-list's udev output. See help output. * Add new permission setup script doing class based matching for PTP class cameras not listed explicitly by USB IDs. This script (check-ptp-camera) is used by the generated UDEV rules. diff --git a/libgphoto2_port/gphoto2/gphoto2-port-log.h b/libgphoto2_port/gphoto2/gphoto2-port-log.h index ddf79e0b1..32e4eb74d 100644 --- a/libgphoto2_port/gphoto2/gphoto2-port-log.h +++ b/libgphoto2_port/gphoto2/gphoto2-port-log.h @@ -125,10 +125,9 @@ void gp_log_data (const char *domain, const char *data, unsigned int size); typedef void (*string_item_func) (const char *str, void *data); - void + const char * gpi_enum_to_string(const unsigned int _enum, - const StringFlagItem *map, - string_item_func func, void *data); + const StringFlagItem *map); int gpi_string_to_enum(const char *str, diff --git a/libgphoto2_port/libgphoto2_port/gphoto2-port-log.c b/libgphoto2_port/libgphoto2_port/gphoto2-port-log.c index 2096d451b..ad2f55bc2 100644 --- a/libgphoto2_port/libgphoto2_port/gphoto2-port-log.c +++ b/libgphoto2_port/libgphoto2_port/gphoto2-port-log.c @@ -345,18 +345,18 @@ gp_log (GPLogLevel level, const char *domain, const char *format, ...) #ifdef _GPHOTO2_INTERNAL_CODE -void +const char * gpi_enum_to_string(unsigned int _enum, - const StringFlagItem *map, - string_item_func func, void *data) + const StringFlagItem *map) { int i; for (i=0; map[i].str != NULL; i++) { if (_enum == map[i].flag) { - func(map[i].str, data); + return(map[i].str); break; } } + return NULL; } int @@ -436,3 +436,11 @@ gpi_string_list_to_flags(const char *str[], } #endif /* _GPHOTO2_INTERNAL_CODE */ + + +/* + * Local Variables: + * c-file-style:"linux" + * indent-tabs-mode:t + * End: + */ diff --git a/packaging/generic/print-camera-list.c b/packaging/generic/print-camera-list.c index 380621262..c19961416 100644 --- a/packaging/generic/print-camera-list.c +++ b/packaging/generic/print-camera-list.c @@ -88,12 +88,15 @@ typedef struct { } func_params_t; -typedef int (* begin_func_t) (const func_params_t *params); +typedef int (* begin_func_t) (const func_params_t *params, + void **data); typedef int (* camera_func_t) (const func_params_t *params, const int i, const int total, - const CameraAbilities *ca); -typedef int (* end_func_t) (const func_params_t *params); + const CameraAbilities *ca, + void *data); +typedef int (* end_func_t) (const func_params_t *params, + void *data); #define GP_USB_HOTPLUG_MATCH_VENDOR_ID 0x0001 @@ -134,6 +137,13 @@ typedef int (* end_func_t) (const func_params_t *params); exit(13); \ } while (0) +#define ASSERT(cond) \ + do { \ + if (!(cond)) { \ + FATAL("Assertion failed: %s", #cond); \ + } \ + } while (0) + /* print_version_comment * Print comment to output containing information on library versions @@ -179,7 +189,7 @@ print_version_comment(FILE *out, static int -hotplug_begin_func (const func_params_t *params) +hotplug_begin_func (const func_params_t *params, void **data) { if (params->add_comments) { printf("# linux-hotplug configuration file " @@ -203,7 +213,8 @@ static int hotplug_camera_func (const func_params_t *params, const int i, const int total, - const CameraAbilities *a) + const CameraAbilities *a, + void *data) { int flags = 0; int class = 0, subclass = 0, proto = 0; @@ -284,7 +295,7 @@ print_hline (void) static int -human_begin_func (const func_params_t *params) +human_begin_func (const func_params_t *params, void **data) { print_hline(); print_headline(); @@ -294,7 +305,7 @@ human_begin_func (const func_params_t *params) static int -human_end_func (const func_params_t *params) +human_end_func (const func_params_t *params, void *data) { print_hline(); print_headline(); @@ -322,7 +333,8 @@ static int human_camera_func (const func_params_t *params, const int i, const int total, - const CameraAbilities *a) + const CameraAbilities *a, + void *data) { const char *camlib_basename; camlib_basename = basename(a->library); @@ -337,9 +349,10 @@ human_camera_func (const func_params_t *params, static int idlist_camera_func (const func_params_t *params, - const int i, - const int total, - const CameraAbilities *a) + const int i, + const int total, + const CameraAbilities *a, + void *data) { if (a->usb_vendor) { /* usb product id may be zero! */ printf("%04x:%04x %s\n", @@ -351,35 +364,139 @@ idlist_camera_func (const func_params_t *params, } -static int -udev_begin_func (const func_params_t *params) +typedef enum { + UDEV_PRE_0_98 = 0, + UDEV_0_98 = 1 +} udev_version_t; + +static const StringFlagItem udev_version_t_map[] = { + { "pre-0.98", UDEV_PRE_0_98 }, + { "0.98", UDEV_0_98 }, + { NULL, 0 } +}; + + +typedef struct { + udev_version_t version; + char *mode; + char *owner; + char *group; + char *script; + char *begin_string; + char *usbcam_string; +} udev_persistent_data_t; + + +static void +udev_parse_params (const func_params_t *params, void **data) { - printf ("# udev rules file for libgphoto2 devices (udev < 0.98)\n"); - print_version_comment(stdout, "# ", "\n", NULL, "#\n"); + udev_persistent_data_t *pdata; + pdata = calloc(1, sizeof(udev_persistent_data_t)); + pdata->version = UDEV_PRE_0_98; + ASSERT(data != NULL); + *data = (void *) pdata; + if (1) { + int i; + char *key = NULL, *val = NULL; + for (i=0; ((key=(*params->argv)[i]) != NULL) && + ((val=(*params->argv)[i+1]) != NULL); i+=2) { + if (0) { + /* nothing */ + } else if (strcmp("script", key)==0) { + pdata->script = val; + } else if (strcmp("owner", key)==0) { + pdata->owner = val; + } else if (strcmp("group", key)==0) { + pdata->group = val; + } else if (strcmp("version", key)==0) { + if (gpi_string_to_enum(val, &(pdata->version), + udev_version_t_map)) { + FATAL("Unrecognized udev version: \"%s\"", val); + } + } else if (strcmp("mode", key)==0) { + pdata->mode = val; + } else { + FATAL("Unknown key argument: %s", key); + } + } + if ((key != NULL) && (val == NULL)) { + FATAL("Single argument remaining; need pairs of key and value"); + } + } + if ((0==0) + && pdata->mode == NULL + && pdata->group == NULL + && pdata->owner == NULL + && pdata->script == NULL) { + FATAL("Either