⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 printers.c

📁 ipp打印机服务器原代码 注意:请将ipp.gz改为ipp.tar.gz 然后使用tar zxvf ipp.tar.gz解压 站长注意
💻 C
📖 第 1 页 / 共 5 页
字号:
/* * "$Id: printers.c,v 1.167 2005/01/03 19:29:59 mike Exp $" * *   Printer routines for the Common UNIX Printing System (CUPS). * *   Copyright 1997-2005 by Easy Software Products, all rights reserved. * *   These coded instructions, statements, and computer programs are the *   property of Easy Software Products and are protected by Federal *   copyright law.  Distribution and use rights are outlined in the file *   "LICENSE.txt" which should have been included with this file.  If this *   file is missing or damaged please contact Easy Software Products *   at: * *       Attn: CUPS Licensing Information *       Easy Software Products *       44141 Airport View Drive, Suite 204 *       Hollywood, Maryland 20636 USA * *       Voice: (301) 373-9600 *       EMail: cups-info@cups.org *         WWW: http://www.cups.org * * Contents: * *   AddPrinter()           - Add a printer to the system. *   AddPrinterFilter()     - Add a MIME filter for a printer. *   AddPrinterHistory()    - Add the current printer state to the history. *   AddPrinterUser()       - Add a user to the ACL. *   DeleteAllPrinters()    - Delete all printers from the system. *   DeletePrinter()        - Delete a printer from the system. *   DeletePrinterFilters() - Delete all MIME filters for a printer. *   FindPrinter()          - Find a printer in the list. *   FreePrinterUsers()     - Free allow/deny users. *   LoadAllPrinters()      - Load printers from the printers.conf file. *   SaveAllPrinters()      - Save all printer definitions to the printers.conf *   SetPrinterAttrs()      - Set printer attributes based upon the PPD file. *   SetPrinterReasons()    - Set/update the reasons strings. *   SetPrinterState()      - Update the current state of a printer. *   SortPrinters()         - Sort the printer list when a printer name is *                            changed. *   StopPrinter()          - Stop a printer from printing any jobs... *   ValidateDest()         - Validate a printer/class destination. *   WritePrintcap()        - Write a pseudo-printcap file for older *                            applications that need it... *   cupsdSanitizeURI()     - Sanitize a device URI... *   write_irix_config()    - Update the config files used by the IRIX *                            desktop tools. *   write_irix_state()     - Update the status files used by IRIX printing *                            desktop tools. *//* * Include necessary headers... */#include "cupsd.h"/* * Local functions... */#ifdef __sgistatic void	write_irix_config(printer_t *p);static void	write_irix_state(printer_t *p);#endif /* __sgi *//* * 'AddPrinter()' - Add a printer to the system. */printer_t *			/* O - New printer */AddPrinter(const char *name)	/* I - Name of printer */{  printer_t	*p,		/* New printer */		*current,	/* Current printer in list */		*prev;		/* Previous printer in list */ /*  * Range check input...  */  DEBUG_printf(("Function AddPrinter(%s) start\n", name));   LogMessage(L_DEBUG2, "AddPrinter(\"%s\")", name ? name : "(null)");  if (name == NULL)    return (NULL); /*  * Create a new printer entity...  */  if ((p = calloc(1, sizeof(printer_t))) == NULL)  {    LogMessage(L_ERROR, "Unable to allocate memory for printer - %s",               strerror(errno));    return (NULL);  }  SetString(&p->name, name);  SetString(&p->info, name);  SetString(&p->hostname, ServerName);  SetStringf(&p->uri, "ipp://%s:%d/printers/%s", ServerName,             NumListeners > 0 ? ntohs(Listeners[0].address.sin_port) : ippPort(),	     name);  SetStringf(&p->device_uri, "file:/dev/null");  p->state     = IPP_PRINTER_STOPPED;  p->accepting = 0;#if	0  p->filetype  = mimeAddType(MimeDatabase, "printer", name);#endif  SetString(&p->job_sheets[0], "none");  SetString(&p->job_sheets[1], "none");   if (MaxPrinterHistory)    p->history = calloc(MaxPrinterHistory, sizeof(ipp_t *)); /*  * Insert the printer in the printer list alphabetically...  */  for (prev = NULL, current = Printers;       current != NULL;       prev = current, current = current->next)    if (strcasecmp(p->name, current->name) < 0)      break; /*  * Insert this printer before the current one...  */  if (prev == NULL)    Printers = p;  else    prev->next = p;  p->next = current; /*  * Write a new /etc/printcap or /var/spool/lp/pstatus file.  */  WritePrintcap(); /*  * Bump the printer count and return...  */  NumPrinters ++;  return (p);}#if	0/* * 'AddPrinterFilter()' - Add a MIME filter for a printer. */voidAddPrinterFilter(printer_t  *p,		/* I - Printer to add to */                 const char *filter)	/* I - Filter to add */{  int		i;			/* Looping var */  char		program[1024];		/* Program/filter name */  int		cost;			/* Cost of filter */#if	0  char	type[MIME_MAX_TYPE],	/* Type for filter */  		super[MIME_MAX_SUPER];	/* Super-type for filter */  mime_type_t	**temptype;		/* MIME type looping var */#endif /*  * Range check input...  */#if	0  if (p == NULL || p->filetype == NULL || filter == NULL)#endif  if (p == NULL || filter == NULL)    return; /*  * Parse the filter string; it should be in the following format:  *  *     super/type cost program  */  if (sscanf(filter, "%15[^/]/%31s%d%1023s", super, type, &cost, program) != 4)  {    LogMessage(L_ERROR, "AddPrinterFilter: Invalid filter string \"%s\"!",               filter);    return;  } /*  * Add the filter to the MIME database, supporting wildcards as needed...  */  for (temptype = MimeDatabase->types, i = MimeDatabase->num_types;       i > 0;       i --, temptype ++)    if (((super[0] == '*' && strcasecmp((*temptype)->super, "printer") != 0) ||         strcasecmp((*temptype)->super, super) == 0) &&        (type[0] == '*' || strcasecmp((*temptype)->type, type) == 0))    {      LogMessage(L_DEBUG2, "Adding filter %s/%s %s/%s %d %s",                 (*temptype)->super, (*temptype)->type,		 p->filetype->super, p->filetype->type,                 cost, program);      mimeAddFilter(MimeDatabase, *temptype, p->filetype, cost, program);    }}#endif/* * 'AddPrinterHistory()' - Add the current printer state to the history. */voidAddPrinterHistory(printer_t *p)		/* I - Printer */{  ipp_t	*history;			/* History collection */ /*  * Stop early if we aren't keeping history data...  */  if (MaxPrinterHistory <= 0)    return; /*  * Retire old history data as needed...  */  p->sequence_number ++;  if (p->num_history >= MaxPrinterHistory)  {    p->num_history --;    ippDelete(p->history[0]);    memmove(p->history, p->history + 1, p->num_history * sizeof(ipp_t *));  } /*  * Create a collection containing the current printer-state, printer-up-time,  * printer-state-message, and printer-state-reasons attributes.  */  history = ippNew();  ippAddInteger(history, IPP_TAG_PRINTER, IPP_TAG_ENUM, "printer-state",                p->state);  ippAddBoolean(history, IPP_TAG_PRINTER, "printer-is-accepting-jobs",                p->accepting);  ippAddString(history, IPP_TAG_PRINTER, IPP_TAG_TEXT, "printer-state-message",               NULL, p->state_message);  if (p->num_reasons == 0)    ippAddString(history, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,                 "printer-state-reasons", NULL,		 p->state == IPP_PRINTER_STOPPED ? "paused" : "none");  else    ippAddStrings(history, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,                  "printer-state-reasons", p->num_reasons, NULL,		  (const char * const *)p->reasons);  ippAddInteger(history, IPP_TAG_PRINTER, IPP_TAG_INTEGER,                "printer-state-time", p->state_time);  ippAddInteger(history, IPP_TAG_PRINTER, IPP_TAG_INTEGER,                "printer-state-sequence-number", p->sequence_number);  p->history[p->num_history] = history;  p->num_history ++;}/* * 'AddPrinterUser()' - Add a user to the ACL. */voidAddPrinterUser(printer_t  *p,		/* I - Printer */               const char *username)	/* I - User */{  const char	**temp;			/* Temporary array pointer */  if (!p || !username)    return;  if (p->num_users == 0)    temp = malloc(sizeof(char **));  else    temp = realloc(p->users, sizeof(char **) * (p->num_users + 1));  if (!temp)    return;  p->users = temp;  temp     += p->num_users;  if ((*temp = strdup(username)) != NULL)    p->num_users ++;}/* * 'CreateCommonData()' - Create the common printer data. */voidCreateCommonData(void){#if	0  int		i;			/* Looping var */  ipp_attribute_t *attr;		/* Attribute data */#endif  static const int nups[] =		/* number-up-supported values */		{ 1, 2, 4, 6, 9, 16 };  static const ipp_orient_t orients[4] =/* orientation-requested-supported values */		{		  IPP_PORTRAIT,		  IPP_LANDSCAPE,		  IPP_REVERSE_LANDSCAPE,		  IPP_REVERSE_PORTRAIT		};  static const char * const holds[] =	/* job-hold-until-supported values */		{		  "no-hold",		  "indefinite",		  "day-time",		  "evening",		  "night",		  "second-shift",		  "third-shift",		  "weekend"		};  static const char * const versions[] =/* ipp-versions-supported values */		{		  "1.0",		  "1.1"		};#if	0  static const ipp_op_t	ops[] =		/* operations-supported values */		{		  IPP_PRINT_JOB,		  IPP_VALIDATE_JOB,		  IPP_CREATE_JOB,		  IPP_SEND_DOCUMENT,		  IPP_CANCEL_JOB,		  IPP_GET_JOB_ATTRIBUTES,		  IPP_GET_JOBS,		  IPP_GET_PRINTER_ATTRIBUTES,		  IPP_HOLD_JOB,		  IPP_RELEASE_JOB,		  IPP_PAUSE_PRINTER,		  IPP_RESUME_PRINTER,		  IPP_PURGE_JOBS,		  IPP_SET_JOB_ATTRIBUTES,		  IPP_ENABLE_PRINTER,		  IPP_DISABLE_PRINTER,		  CUPS_GET_DEFAULT,		  CUPS_GET_PRINTERS,		  CUPS_ADD_PRINTER,		  CUPS_DELETE_PRINTER,		  CUPS_GET_CLASSES,		  CUPS_ADD_CLASS,		  CUPS_DELETE_CLASS,		  CUPS_ACCEPT_JOBS,		  CUPS_REJECT_JOBS,		  CUPS_GET_DEVICES,		  CUPS_GET_PPDS,		  IPP_RESTART_JOB		};#endif  static const char * const charsets[] =/* charset-supported values */		{		  "us-ascii",		  "iso-8859-1",		  "iso-8859-2",		  "iso-8859-3",		  "iso-8859-4",		  "iso-8859-5",		  "iso-8859-6",		  "iso-8859-7",		  "iso-8859-8",		  "iso-8859-9",		  "iso-8859-10",		  "iso-8859-13",		  "iso-8859-14",		  "iso-8859-15",		  "utf-8",		  "windows-874",		  "windows-1250",		  "windows-1251",		  "windows-1252",		  "windows-1253",		  "windows-1254",		  "windows-1255",		  "windows-1256",		  "windows-1257",		  "windows-1258",		  "koi8-r",		  "koi8-u",		};  static const char * const compressions[] =		{			/* document-compression-supported values */		  "none"#ifdef HAVE_LIBZ		  ,"gzip"#endif /* HAVE_LIBZ */		};  static const char * const multiple_document_handling[] =		{			/* multiple-document-handling-supported values */		  "separate-documents-uncollated-copies",		  "separate-documents-collated-copies"		};  if (CommonData)    ippDelete(CommonData);  CommonData = ippNew();  ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,               "pdl-override-supported", NULL, "not-attempted");  ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,                "ipp-versions-supported", sizeof(versions) / sizeof(versions[0]),		NULL, versions);#if	0  ippAddIntegers(CommonData, IPP_TAG_PRINTER, IPP_TAG_ENUM,                 "operations-supported",                 sizeof(ops) / sizeof(ops[0]) + JobFiles - 1, (int *)ops);#endif  ippAddBoolean(CommonData, IPP_TAG_PRINTER,                "multiple-document-jobs-supported", 1);  ippAddInteger(CommonData, IPP_TAG_PRINTER, IPP_TAG_INTEGER,                "multiple-operation-time-out", 60);  ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,                "multiple-document-handling-supported",                sizeof(multiple_document_handling) /		    sizeof(multiple_document_handling[0]), NULL,	        multiple_document_handling);  ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_CHARSET,               "charset-configured", NULL, DefaultCharset);  ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_CHARSET,                "charset-supported", sizeof(charsets) / sizeof(charsets[0]),		NULL, charsets);  ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_LANGUAGE,               "natural-language-configured", NULL, DefaultLanguage);  ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_LANGUAGE,               "generated-natural-language-supported", NULL, DefaultLanguage);  ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_MIMETYPE,               "document-format-default", NULL, "application/octet-stream");  ippAddStrings(CommonData, IPP_TAG_PRINTER,                (ipp_tag_t)(IPP_TAG_MIMETYPE | IPP_TAG_COPY),                "document-format-supported", NumMimeTypes, NULL, MimeTypes);  ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,        	"compression-supported",		sizeof(compressions) / sizeof(compressions[0]),		NULL, compressions);  ippAddInteger(CommonData, IPP_TAG_PRINTER, IPP_TAG_INTEGER,                "job-priority-supported", 100);  ippAddInteger(CommonData, IPP_TAG_PRINTER, IPP_TAG_INTEGER,                "job-priority-default", 50);  ippAddRange(CommonData, IPP_TAG_PRINTER, "copies-supported", 1, MaxCopies);  ippAddInteger(CommonData, IPP_TAG_PRINTER, IPP_TAG_INTEGER,                "copies-default", 1);  ippAddBoolean(CommonData, IPP_TAG_PRINTER, "page-ranges-supported", 1);  ippAddIntegers(CommonData, IPP_TAG_PRINTER, IPP_TAG_INTEGER,                 "number-up-supported", sizeof(nups) / sizeof(nups[0]), nups);  ippAddInteger(CommonData, IPP_TAG_PRINTER, IPP_TAG_INTEGER,                "number-up-default", 1);  ippAddIntegers(CommonData, IPP_TAG_PRINTER, IPP_TAG_ENUM,                 "orientation-requested-supported", 4, (int *)orients);  ippAddInteger(CommonData, IPP_TAG_PRINTER, IPP_TAG_ENUM,                "orientation-requested-default", IPP_PORTRAIT);  ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,                "job-hold-until-supported", sizeof(holds) / sizeof(holds[0]),		NULL, holds);  ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,               "job-hold-until-default", NULL, "no-hold");#if	0  if (NumBanners > 0)  {   /*    * Setup the job-sheets-supported and job-sheets-default attributes...    */    if (Classification && !ClassifyOverride)      attr = ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_NAME,                	  "job-sheets-supported", NULL, Classification);    else      attr = ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_NAME,                	   "job-sheets-supported", NumBanners + 1, NULL, NULL);    if (attr == NULL)      LogMessage(L_EMERG, "SetPrinterAttrs: Unable to allocate memory for "                          "job-sheets-supported attribute: %s!",	         strerror(errno));    else if (!Classification || ClassifyOverride)    {      attr->values[0].string.text = strdup("none");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -