+/* *************************************************************************
+ * image-blocker-custom-file
+ * *************************************************************************/
+ case hash_image_blocker_custom_file :
+ freez(config->image_blocker_data);
+ freez(config->image_blocker_format);
+ config->image_blocker_length = 0;
+ image_path = make_path(config->confdir, arg);
+
+ /*
+ * Load up the custom image bitmap file
+ */
+ if (NULL == (imagefp = fopen(image_path, "rb")))
+ {
+ /*
+ * If we can't open the user's requested image, complain
+ */
+ log_error(LOG_LEVEL_ERROR, "Unable to load custom blocker image: %s.", image_path);
+ }
+ else
+ {
+ if (stat(image_path, statbuf) == 0)
+ {
+ file_size = statbuf->st_size;
+ image_buf = zalloc(file_size);
+ if (image_buf != NULL)
+ {
+ bytes_read = fread(image_buf,1,file_size,imagefp);
+ if (bytes_read > 0)
+ {
+ config->image_blocker_data = image_buf;
+ config->image_blocker_length = file_size;
+ /*
+ * Ensure we can look into files for file signatures
+ */
+ if (file_size > 10)
+ {
+ /*
+ * Snoop into the binary data for a filetype signature
+ */
+ if (memcmp(image_buf,"GIF",3) == 0)
+ config->image_blocker_format = IMAGE_MIMETYPE_GIF;
+ else if (memcmp(&image_buf[6],"JFIF",4) == 0)
+ config->image_blocker_format = IMAGE_MIMETYPE_JPG;
+ else if (memcmp(&image_buf[1],"PNG",3) == 0)
+ config->image_blocker_format = IMAGE_MIMETYPE_PNG;
+ else
+ {
+ log_error(LOG_LEVEL_ERROR, "Unsupported custom image file type.");
+ freez(config->image_blocker_data);
+ }
+ }
+ else
+ freez(config->image_blocker_data);
+ }
+ else
+ {
+ log_error(LOG_LEVEL_ERROR, "Unable to read custom blocker image: %s", image_path, bytes_read, file_size);
+ freez(image_buf);
+ config->image_blocker_length = 0;
+ }
+ }
+ else
+ log_error(LOG_LEVEL_ERROR, "Unable to allocate memory for custom blocker image: %s.", image_path);
+ }
+ else
+ log_error(LOG_LEVEL_ERROR, "Unable to get statistics on custom blocker image file: %s", image_path);
+ }
+ freez(image_path);
+ /*
+ * If our load failed for some reason, just give the default
+ * checkerboard pattern
+ */
+ if (config->image_blocker_data == NULL)
+ {
+ log_error(LOG_LEVEL_ERROR, "Custom blocker image processing failed; defaulting to \"pattern\".");
+ config->image_blocker_data = (char*)image_pattern_data;
+ config->image_blocker_length = image_pattern_length;
+ config->image_blocker_format = BUILTIN_IMAGE_MIMETYPE;
+ }
+ continue;