Beispiel #1
0
void
show_photos(const struct user_attribute *attrs,
	    int count,PKT_public_key *pk,PKT_secret_key *sk,
	    PKT_user_id *uid)
{
#ifndef DISABLE_PHOTO_VIEWER
  int i;
  struct expando_args args;
  u32 len;
  u32 kid[2]={0,0};

  memset(&args,0,sizeof(args));
  args.pk=pk;
  args.sk=sk;
  args.validity_info=get_validity_info(pk,uid);
  args.validity_string=get_validity_string(pk,uid);

  if(pk)
    keyid_from_pk(pk,kid);
  else if(sk)
    keyid_from_sk(sk,kid);

  for(i=0;i<count;i++)
    if(attrs[i].type==ATTRIB_IMAGE &&
       parse_image_header(&attrs[i],&args.imagetype,&len))
      {
	char *command,*name;
	struct exec_info *spawn;
	int offset=attrs[i].len-len;

#ifdef FIXED_PHOTO_VIEWER
	opt.photo_viewer=FIXED_PHOTO_VIEWER;
#else
	if(!opt.photo_viewer)
	  opt.photo_viewer=get_default_photo_command();
#endif

	/* make command grow */
	command=pct_expando(opt.photo_viewer,&args);
	if(!command)
	  goto fail;

	name=xmalloc(16+strlen(EXTSEP_S)+
		     strlen(image_type_to_string(args.imagetype,0))+1);

	/* Make the filename.  Notice we are not using the image
           encoding type for more than cosmetics.  Most external image
           viewers can handle a multitude of types, and even if one
           cannot understand a particular type, we have no way to know
           which.  The spec permits this, by the way. -dms */

#ifdef USE_ONLY_8DOT3
	sprintf(name,"%08lX" EXTSEP_S "%s",(ulong)kid[1],
		image_type_to_string(args.imagetype,0));
#else
	sprintf(name,"%08lX%08lX" EXTSEP_S "%s",(ulong)kid[0],(ulong)kid[1],
		image_type_to_string(args.imagetype,0));
#endif

	if(exec_write(&spawn,NULL,command,name,1,1)!=0)
	  {
	    xfree(name);
	    goto fail;
	  }

#ifdef __riscos__
        riscos_set_filetype_by_mimetype(spawn->tempfile_in,
                                        image_type_to_string(args.imagetype,2));
#endif

	xfree(name);

	fwrite(&attrs[i].data[offset],attrs[i].len-offset,1,spawn->tochild);

	if(exec_read(spawn)!=0)
	  {
	    exec_finish(spawn);
	    goto fail;
	  }

	if(exec_finish(spawn)!=0)
	  goto fail;
      }

  return;

 fail:
  log_error(_("unable to display photo ID!\n"));
#endif
}
Beispiel #2
0
int fiasco_write_to_file(struct fiasco * fiasco, const char * file) {

    int fd = -1;
    int i;
    int device_count;
    uint32_t size;
    uint32_t length;
    uint16_t hash;
    uint8_t length8;
    char ** device_hwrevs_bufs;
    const char * str;
    const char * type;
    struct image_list * image_list;
    struct image * image;
    unsigned char buf[4096];

    if ( ! fiasco )
        return -1;

    printf("Generating Fiasco image %s...\n", file);

    if ( ! fiasco->first )
        FIASCO_WRITE_ERROR(file, fd, "Nothing to write");

    if ( fiasco->name && strlen(fiasco->name)+1 > UINT8_MAX )
        FIASCO_WRITE_ERROR(file, fd, "Fiasco name string is too long");

    if ( fiasco->swver && strlen(fiasco->swver)+1 > UINT8_MAX )
        FIASCO_WRITE_ERROR(file, fd, "SW version string is too long");

    if ( ! simulate ) {
        fd = open(file, O_RDWR|O_CREAT|O_TRUNC, 0644);
        if ( fd < 0 ) {
            ERROR_INFO("Cannot create file");
            return -1;
        }
    }

    printf("Writing Fiasco header...\n");

    WRITE_OR_FAIL(file, fd, "\xb4", 1); /* signature */

    if ( fiasco->name[0] )
        str = fiasco->name;
    else
        str = "OSSO UART+USB";

    length = 4 + strlen(str) + 3;
    if ( fiasco->swver[0] )
        length += strlen(fiasco->swver) + 3;
    length = htonl(length);
    WRITE_OR_FAIL(file, fd, &length, 4); /* FW header length */

    if ( fiasco->swver[0] )
        length = htonl(2);
    else
        length = htonl(1);
    WRITE_OR_FAIL(file, fd, &length, 4); /* FW header blocks count */

    /* Fiasco name */
    length8 = strlen(str)+1;
    WRITE_OR_FAIL(file, fd, "\xe8", 1);
    WRITE_OR_FAIL(file, fd, &length8, 1);
    WRITE_OR_FAIL(file, fd, str, length8);

    /* SW version */
    if ( fiasco->swver[0] ) {
        printf("Writing SW version: %s\n", fiasco->swver);
        length8 = strlen(fiasco->swver)+1;
        WRITE_OR_FAIL(file, fd, "\x31", 1);
        WRITE_OR_FAIL(file, fd, &length8, 1);
        WRITE_OR_FAIL(file, fd, fiasco->swver, length8);
    };

    printf("\n");

    image_list = fiasco->first;

    while ( image_list ) {

        image = image_list->image;

        if ( ! image )
            FIASCO_WRITE_ERROR(file, fd, "Empty image");

        printf("Writing image...\n");
        image_print_info(image);

        type = image_type_to_string(image->type);

        device_hwrevs_bufs = device_list_alloc_to_bufs(image->devices);

        device_count = 0;
        if ( device_hwrevs_bufs && device_hwrevs_bufs[0] )
            for ( ; device_hwrevs_bufs[device_count]; ++device_count );

        if ( ! type )
            FIASCO_WRITE_ERROR(file, fd, "Unknown image type");

        if ( image->version && strlen(image->version) > UINT8_MAX )
            FIASCO_WRITE_ERROR(file, fd, "Image version string is too long");

        if ( image->layout && strlen(image->layout) > UINT8_MAX )
            FIASCO_WRITE_ERROR(file, fd, "Image layout is too long");

        printf("Writing image header...\n");

        /* signature */
        WRITE_OR_FAIL(file, fd, "T", 1);

        /* number of subsections */
        length8 = device_count+1;
        if ( image->version )
            ++length8;
        if ( image->layout )
            ++length8;
        WRITE_OR_FAIL(file, fd, &length8, 1);

        /* unknown */
        WRITE_OR_FAIL(file, fd, "\x2e\x19\x01\x01\x00", 5);

        /* checksum */
        hash = htons(image->hash);
        WRITE_OR_FAIL(file, fd, &hash, 2);

        /* image type name */
        memset(buf, 0, 12);
        strncpy((char *)buf, type, 12);
        WRITE_OR_FAIL(file, fd, buf, 12);

        /* image size */
        size = htonl(image->size);
        WRITE_OR_FAIL(file, fd, &size, 4);

        /* unknown */
        WRITE_OR_FAIL(file, fd, "\x00\x00\x00\x00", 4);

        /* append version subsection */
        if ( image->version ) {
            WRITE_OR_FAIL(file, fd, "1", 1); /* 1 - version */
            length8 = strlen(image->version)+1;
            WRITE_OR_FAIL(file, fd, &length8, 1);
            WRITE_OR_FAIL(file, fd, image->version, length8);
        }

        /* append device & hwrevs subsection */
        for ( i = 0; i < device_count; ++i ) {
            WRITE_OR_FAIL(file, fd, "2", 1); /* 2 - device & hwrevs */
            WRITE_OR_FAIL(file, fd, &device_hwrevs_bufs[i][0], 1);
            WRITE_OR_FAIL(file, fd, device_hwrevs_bufs[i]+1, ((uint8_t *)(device_hwrevs_bufs[i]))[0]);
        }
        free(device_hwrevs_bufs);

        /* append layout subsection */
        if ( image->layout ) {
            length8 = strlen(image->layout);
            WRITE_OR_FAIL(file, fd, "3", 1); /* 3 - layout */
            WRITE_OR_FAIL(file, fd, &length8, 1);
            WRITE_OR_FAIL(file, fd, image->layout, length8);
        }

        /* dummy byte - end of all subsections */
        WRITE_OR_FAIL(file, fd, "\x00", 1);

        printf("Writing image data...\n");

        image_seek(image, 0);
        while ( 1 ) {
            size = image_read(image, buf, sizeof(buf));
            if ( size == 0 )
                break;
            WRITE_OR_FAIL(file, fd, buf, size);
        }

        image_list = image_list->next;

        if ( image_list )
            printf("\n");

    }

    close(fd);
    printf("\nDone\n\n");
    return 0;

}
Beispiel #3
0
DEFINE_SAVER_PLUGIN_SAVE(p, fp, c, params)
{
  struct jpeg_compress_struct *cinfo = malloc(sizeof(struct jpeg_compress_struct));
  struct my_error_mgr jerr;
  JSAMPROW buffer[1]; /* output row buffer */
  int quality, result;

  debug_message("jpeg: save (%s) (%d, %d) called.\n", image_type_to_string(p->type), image_width(p), image_height(p));

  if (cinfo == NULL)
    return 0;

  switch (p->type) {
  case _BITMAP_LSBFirst:
  case _BITMAP_MSBFirst:
  case _GRAY_ALPHA:
  case _INDEX:
  case _RGB565:
  case _BGR565:
  case _RGB555:
  case _BGR555:
  case _BGR24:
  case _RGBA32:
  case _ABGR32:
  case _ARGB32:
  case _BGRA32:
    show_message("Saving of %s type image is not yet implemented.\n", image_type_to_string(p->type));
    return 0;
  case _GRAY:
  case _RGB24:
    break;
  default:
    fprintf(stderr, "Unknown image type: %d (maybe bug)\n", p->type);
    return 0;
  }

  cinfo->err = jpeg_std_error(&jerr.pub);
  jerr.pub.error_exit = my_error_exit;
  /* Establish the setjmp return context for my_error_exit to use. */
  if (setjmp(jerr.setjmp_buffer)) {
    jpeg_destroy_compress(cinfo);
    free(cinfo);
    return 0;
  }

  quality = config_get_int(c, "/enfle/plugins/saver/jpeg/quality", &result);
  if (!result)
    quality = JPEG_SAVE_DEFAULT_QUALITY;
  else if (quality < 1 || quality > 100) {
    show_message("Invalid quality %d: defaults to %d.\n", quality, JPEG_SAVE_DEFAULT_QUALITY);
    quality = JPEG_SAVE_DEFAULT_QUALITY;
  }

  /* Now we can initialize the JPEG decompression object. */
  jpeg_create_compress(cinfo);
  jpeg_stdio_dest(cinfo, fp);

  cinfo->image_width = image_width(p);
  cinfo->image_height = image_height(p);
  if (p->type == _GRAY) {
    cinfo->input_components = 1;
    cinfo->in_color_space = JCS_GRAYSCALE;
  } else {
    cinfo->input_components = 3;
    cinfo->in_color_space = JCS_RGB;
  }
  jpeg_set_defaults(cinfo);
  jpeg_set_quality(cinfo, quality, TRUE);

  jpeg_start_compress(cinfo, TRUE);

  while (cinfo->next_scanline < cinfo->image_height) {
    buffer[0] = (JSAMPROW)(memory_ptr(image_image(p)) + image_bpl(p) * cinfo->next_scanline);
    (void)jpeg_write_scanlines(cinfo, buffer, 1);
  }

  (void)jpeg_finish_compress(cinfo);
  jpeg_destroy_compress(cinfo);
  free(cinfo);

  debug_message("jpeg: saved.\n");

  return 1;
}