예제 #1
0
destination_implObj::cups_http_t_wrapper::cups_http_t_wrapper(cups_dest_t *dest)
	: http{cupsConnectDest(dest, CUPS_DEST_FLAGS_NONE,
			       connect_timeout.get(),
			       NULL, NULL, 0, NULL, NULL)}
{
	if (!http)
		throw EXCEPTION(libmsg(_("Print queue connection failed.")));
}
예제 #2
0
파일: lpoptions.c 프로젝트: zdohnal/cups
static void
list_options(cups_dest_t *dest)		/* I - Destination to list */
{
  http_t	*http;			/* Connection to destination */
  char		resource[1024];		/* Resource path */
  int		i;			/* Looping var */
  const char	*filename;		/* PPD filename */
  ppd_file_t	*ppd;			/* PPD data */
  ppd_group_t	*group;			/* Current group */


  if ((http = cupsConnectDest(dest, CUPS_DEST_FLAGS_NONE, 30000, NULL, resource, sizeof(resource), NULL, NULL)) == NULL)
  {
    _cupsLangPrintf(stderr, _("lpoptions: Unable to get PPD file for %s: %s"),
		    dest->name, cupsLastErrorString());
    return;
  }

  if ((filename = cupsGetPPD2(http, dest->name)) == NULL)
  {
    httpClose(http);

    _cupsLangPrintf(stderr, _("lpoptions: Unable to get PPD file for %s: %s"),
		    dest->name, cupsLastErrorString());
    return;
  }

  httpClose(http);

  if ((ppd = ppdOpenFile(filename)) == NULL)
  {
    unlink(filename);
    _cupsLangPrintf(stderr, _("lpoptions: Unable to open PPD file for %s."),
		    dest->name);
    return;
  }

  ppdMarkDefaults(ppd);
  cupsMarkOptions(ppd, dest->num_options, dest->options);

  for (i = ppd->num_groups, group = ppd->groups; i > 0; i --, group ++)
    list_group(ppd, group);

  ppdClose(ppd);
  unlink(filename);
}
예제 #3
0
GList *dt_get_papers(const dt_printer_info_t *printer)
{
  const char *printer_name = printer->name;
  GList *result = NULL;

#if ((CUPS_VERSION_MAJOR == 1) && (CUPS_VERSION_MINOR >= 7)) || CUPS_VERSION_MAJOR > 1
#if defined(__APPLE__) && MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_9
  if (cupsConnectDest != NULL && cupsCopyDestInfo != NULL && cupsGetDestMediaCount != NULL &&
      cupsGetDestMediaByIndex != NULL && cupsFreeDestInfo != NULL)
#endif
  {
    cups_dest_t *dests;
    int num_dests = cupsGetDests(&dests);
    cups_dest_t *dest = cupsGetDest(printer_name, NULL, num_dests, dests);

    int cancel = 0; // important

    char resource[1024];

    if (dest)
    {
      http_t *hcon = cupsConnectDest(dest, 0, 2000, &cancel, resource, sizeof(resource), NULL, (void *)NULL);

      if (hcon)
      {
        cups_size_t size;
        cups_dinfo_t *info = cupsCopyDestInfo (hcon, dest);
        const int count = cupsGetDestMediaCount(hcon, dest, info, CUPS_MEDIA_FLAGS_DEFAULT);
        for (int k=0; k<count; k++)
        {
          if (cupsGetDestMediaByIndex(hcon, dest, info, k, CUPS_MEDIA_FLAGS_DEFAULT, &size))
          {
            if (size.width!=0 && size.length!=0 && !paper_exists(result, size.media))
            {
              pwg_media_t *med = pwgMediaForPWG (size.media);
              char common_name[MAX_NAME] = { 0 };

              if (med->ppd)
                g_strlcpy(common_name, med->ppd, sizeof(common_name));
              else
                g_strlcpy(common_name, size.media, sizeof(common_name));

              dt_paper_info_t *paper = (dt_paper_info_t*)malloc(sizeof(dt_paper_info_t));
              g_strlcpy(paper->name, size.media, sizeof(paper->name));
              g_strlcpy(paper->common_name, common_name, sizeof(paper->common_name));
              paper->width = (double)size.width / 100.0;
              paper->height = (double)size.length / 100.0;
              result = g_list_append (result, paper);

              dt_print(DT_DEBUG_PRINT,
                       "[print] new media paper %4d %6.2f x %6.2f (%s) (%s)\n",
                       k, paper->width, paper->height, paper->name, paper->common_name);
            }
          }
        }

        cupsFreeDestInfo(info);
        httpClose(hcon);
      }
      else
        dt_print(DT_DEBUG_PRINT, "[print] cannot connect to printer %s (cancel=%d)\n", printer_name, cancel);
    }

    cupsFreeDests(num_dests, dests);
  }
#endif

  // check now PPD page sizes

  const char *PPDFile = cupsGetPPD(printer_name);
  ppd_file_t *ppd = ppdOpenFile(PPDFile);

  if (ppd)
  {
    ppd_size_t *size = ppd->sizes;

    for (int k=0; k<ppd->num_sizes; k++)
    {
      if (size->width!=0 && size->length!=0 && !paper_exists(result, size->name))
      {
        dt_paper_info_t *paper = (dt_paper_info_t*)malloc(sizeof(dt_paper_info_t));
        g_strlcpy(paper->name, size->name, MAX_NAME);
        g_strlcpy(paper->common_name, size->name, MAX_NAME);
        paper->width = (double)dt_pdf_point_to_mm(size->width);
        paper->height = (double)dt_pdf_point_to_mm(size->length);
        result = g_list_append (result, paper);

        dt_print(DT_DEBUG_PRINT,
                 "[print] new ppd paper %4d %6.2f x %6.2f (%s) (%s)\n",
                 k, paper->width, paper->height, paper->name, paper->common_name);
      }
      size++;
    }

    ppdClose(ppd);
    g_unlink(PPDFile);
  }

  result = g_list_sort_with_data (result, (GCompareDataFunc)sort_papers, NULL);
  return result;
}
예제 #4
0
파일: testdest.c 프로젝트: lanceit/cups
int					/* O - Exit status */
main(int  argc,				/* I - Number of command-line arguments */
     char *argv[])			/* I - Command-line arguments */
{
  http_t	*http;			/* Connection to destination */
  cups_dest_t	*dest = NULL;		/* Destination */
  cups_dinfo_t	*dinfo;			/* Destination info */


  if (argc < 2)
    usage(NULL);

  if (!strcmp(argv[1], "--enum"))
  {
    int			i;		/* Looping var */
    cups_ptype_t	type = 0,	/* Printer type filter */
			mask = 0;	/* Printer type mask */


    for (i = 2; i < argc; i ++)
    {
      if (!strcmp(argv[i], "grayscale"))
      {
        type |= CUPS_PRINTER_BW;
	mask |= CUPS_PRINTER_BW;
      }
      else if (!strcmp(argv[i], "color"))
      {
        type |= CUPS_PRINTER_COLOR;
	mask |= CUPS_PRINTER_COLOR;
      }
      else if (!strcmp(argv[i], "duplex"))
      {
        type |= CUPS_PRINTER_DUPLEX;
	mask |= CUPS_PRINTER_DUPLEX;
      }
      else if (!strcmp(argv[i], "staple"))
      {
        type |= CUPS_PRINTER_STAPLE;
	mask |= CUPS_PRINTER_STAPLE;
      }
      else if (!strcmp(argv[i], "small"))
      {
        type |= CUPS_PRINTER_SMALL;
	mask |= CUPS_PRINTER_SMALL;
      }
      else if (!strcmp(argv[i], "medium"))
      {
        type |= CUPS_PRINTER_MEDIUM;
	mask |= CUPS_PRINTER_MEDIUM;
      }
      else if (!strcmp(argv[i], "large"))
      {
        type |= CUPS_PRINTER_LARGE;
	mask |= CUPS_PRINTER_LARGE;
      }
      else
        usage(argv[i]);
    }

    cupsEnumDests(CUPS_DEST_FLAGS_NONE, 5000, NULL, type, mask, enum_cb, NULL);

    return (0);
  }
  else if (!strncmp(argv[1], "ipp://", 6) || !strncmp(argv[1], "ipps://", 7))
    dest = cupsGetDestWithURI(NULL, argv[1]);
  else
    dest = cupsGetNamedDest(CUPS_HTTP_DEFAULT, argv[1], NULL);

  if (!dest)
  {
    printf("testdest: Unable to get destination \"%s\": %s\n", argv[1], cupsLastErrorString());
    return (1);
  }

  if ((http = cupsConnectDest(dest, CUPS_DEST_FLAGS_NONE, 30000, NULL, NULL, 0, NULL, NULL)) == NULL)
  {
    printf("testdest: Unable to connect to destination \"%s\": %s\n", argv[1], cupsLastErrorString());
    return (1);
  }

  if ((dinfo = cupsCopyDestInfo(http, dest)) == NULL)
  {
    printf("testdest: Unable to get information for destination \"%s\": %s\n", argv[1], cupsLastErrorString());
    return (1);
  }

  if (argc == 2 || (!strcmp(argv[2], "supported") && argc < 6))
  {
    if (argc > 3)
      show_supported(http, dest, dinfo, argv[3], argv[4]);
    else if (argc > 2)
      show_supported(http, dest, dinfo, argv[3], NULL);
    else
      show_supported(http, dest, dinfo, NULL, NULL);
  }
  else if (!strcmp(argv[2], "conflicts") && argc > 3)
  {
    int			i,		/* Looping var */
			num_options = 0;/* Number of options */
    cups_option_t	*options = NULL;/* Options */

    for (i = 3; i < argc; i ++)
      num_options = cupsParseOptions(argv[i], num_options, &options);

    show_conflicts(http, dest, dinfo, num_options, options);
  }
  else if (!strcmp(argv[2], "default") && argc == 4)
  {
    show_default(http, dest, dinfo, argv[3]);
  }
  else if (!strcmp(argv[2], "localize") && argc < 6)
  {
    if (argc > 3)
      localize(http, dest, dinfo, argv[3], argv[4]);
    else if (argc > 2)
      localize(http, dest, dinfo, argv[3], NULL);
    else
      localize(http, dest, dinfo, NULL, NULL);
  }
  else if (!strcmp(argv[2], "media"))
  {
    int		i;			/* Looping var */
    const char	*name = NULL;		/* Media name, if any */
    unsigned	flags = CUPS_MEDIA_FLAGS_DEFAULT;
					/* Media selection flags */

    for (i = 3; i < argc; i ++)
    {
      if (!strcmp(argv[i], "borderless"))
	flags = CUPS_MEDIA_FLAGS_BORDERLESS;
      else if (!strcmp(argv[i], "duplex"))
	flags = CUPS_MEDIA_FLAGS_DUPLEX;
      else if (!strcmp(argv[i], "exact"))
	flags = CUPS_MEDIA_FLAGS_EXACT;
      else if (!strcmp(argv[i], "ready"))
	flags = CUPS_MEDIA_FLAGS_READY;
      else if (name)
        usage(argv[i]);
      else
        name = argv[i];
    }

    show_media(http, dest, dinfo, flags, name);
  }
  else if (!strcmp(argv[2], "print") && argc > 3)
  {
    int			i,		/* Looping var */
			num_options = 0;/* Number of options */
    cups_option_t	*options = NULL;/* Options */

    for (i = 4; i < argc; i ++)
      num_options = cupsParseOptions(argv[i], num_options, &options);

    print_file(http, dest, dinfo, argv[3], num_options, options);
  }
  else
    usage(argv[2]);

  return (0);
}