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

📄 printers.c

📁 ipp打印机服务器原代码 注意:请将ipp.gz改为ipp.tar.gz 然后使用tar zxvf ipp.tar.gz解压 站长注意
💻 C
📖 第 1 页 / 共 5 页
字号:
 */    return (p->name);  } /*  * Change localhost to the server name...  */  if (strcasecmp(hostname, "localhost") == 0)    hostname = ServerName;  strlcpy(localname, hostname, sizeof(localname));  if (strcasecmp(hostname, ServerName) != 0)  {   /*    * Localize the hostname...    */    lptr = strchr(localname, '.');    sptr = strchr(ServerName, '.');    if (sptr != NULL && lptr != NULL)    {     /*      * Strip the common domain name components...      */      while (lptr != NULL)      {	if (strcasecmp(lptr, sptr) == 0)	{          *lptr = '\0';	  break;	}	else          lptr = strchr(lptr + 1, '.');      }    }  }  DEBUG_printf(("localized hostname is \"%s\"...\n", localname)); /*  * Find a matching printer or class...  */  for (p = Printers; p != NULL; p = p->next)    if (strcasecmp(p->hostname, localname) == 0 &&        strcasecmp(p->name, resource) == 0)    {/*      *dtype = p->type & (CUPS_PRINTER_CLASS | CUPS_PRINTER_IMPLICIT |                          CUPS_PRINTER_REMOTE);*/      return (p->name);    }  return (NULL);}/* * 'WritePrintcap()' - Write a pseudo-printcap file for older applications *                     that need it... */voidWritePrintcap(void){  cups_file_t	*fp;		/* printcap file */  printer_t	*p;		/* Current printer */#ifdef __sgi /*  * Update the IRIX printer state for the default printer; if  * no printers remain, then the default printer file will be  * removed...  */  write_irix_state(DefaultPrinter);#endif /* __sgi */ /*  * See if we have a printcap file; if not, don't bother writing it.  */  if (!Printcap[0])    return; /*  * Open the printcap file...  */  if ((fp = cupsFileOpen(Printcap, "w")) == NULL)    return; /*  * Put a comment header at the top so that users will know where the  * data has come from...  */  cupsFilePuts(fp, "# This file was automatically generated by cupsd(8) from the\n");  cupsFilePrintf(fp, "# %s/printers.conf file.  All changes to this file\n",          ServerRoot);  cupsFilePuts(fp, "# will be lost.\n"); /*  * Write a new printcap with the current list of printers.  */  switch (PrintcapFormat)  {    case PRINTCAP_BSD:       /*        * Each printer is put in the file as:	*	*    Printer1:	*    Printer2:	*    Printer3:	*    ...	*    PrinterN:	*/        if (DefaultPrinter)	  cupsFilePrintf(fp, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter->name,	          DefaultPrinter->info, ServerName, DefaultPrinter->name);	for (p = Printers; p != NULL; p = p->next)	  if (p != DefaultPrinter)	    cupsFilePrintf(fp, "%s|%s:rm=%s:rp=%s:\n", p->name, p->info,	            ServerName, p->name);        break;    case PRINTCAP_SOLARIS:       /*        * Each printer is put in the file as:	*	*    _all:all=Printer1,Printer2,Printer3,...,PrinterN	*    _default:use=DefaultPrinter	*    Printer1:\	*            :bsdaddr=ServerName,Printer1:\	*            :description=Description:	*    Printer2:	*            :bsdaddr=ServerName,Printer2:\	*            :description=Description:	*    Printer3:	*            :bsdaddr=ServerName,Printer3:\	*            :description=Description:	*    ...	*    PrinterN:	*            :bsdaddr=ServerName,PrinterN:\	*            :description=Description:	*/        cupsFilePuts(fp, "_all:all=");	for (p = Printers; p != NULL; p = p->next)	  cupsFilePrintf(fp, "%s%c", p->name, p->next ? ',' : '\n');        if (DefaultPrinter)	  cupsFilePrintf(fp, "_default:use=%s\n", DefaultPrinter->name);	for (p = Printers; p != NULL; p = p->next)	  cupsFilePrintf(fp, "%s:\\\n"	              "\t:bsdaddr=%s,%s:\\\n"		      "\t:description=%s:\n",		  p->name, ServerName, p->name, p->info ? p->info : "");        break;  } /*  * Close the file...  */  cupsFileClose(fp);}/* * 'cupsdSanitizeURI()' - Sanitize a device URI... */char *					/* O - New device URI */cupsdSanitizeURI(const char *uri,	/* I - Original device URI */                 char       *buffer,	/* O - New device URI */                 int        buflen)	/* I - Size of new device URI buffer */{  char	*start,				/* Start of data after scheme */	*slash,				/* First slash after scheme:// */	*ptr;				/* Pointer into user@host:port part */ /*  * Range check input...  */  if (!uri || !buffer || buflen < 2)    return (NULL); /*  * Copy the device URI to the new buffer...  */  strlcpy(buffer, uri, buflen); /*  * Find the end of the scheme:// part...  */  if ((ptr = strchr(buffer, ':')) == NULL)    return (buffer);			/* No scheme: part... */  for (start = ptr + 1; *start; start ++)    if (*start != '/')      break; /*  * Find the next slash (/) in the URI...  */  if ((slash = strchr(start, '/')) == NULL)    slash = start + strlen(start);	/* No slash, point to the end */ /*  * Check for an @ sign before the slash...  */  if ((ptr = strchr(start, '@')) != NULL && ptr < slash)  {   /*    * Found an @ sign and it is before the resource part, so we have    * an authentication string.  Copy the remaining URI over the    * authentication string...    */    cups_strcpy(start, ptr + 1);  } /*  * Return the new device URI...  */  return (buffer);}#ifdef __sgi/* * 'write_irix_config()' - Update the config files used by the IRIX *                         desktop tools. */static voidwrite_irix_config(printer_t *p)	/* I - Printer to update */{  char		filename[1024];	/* Interface script filename */  cups_file_t	*fp;		/* Interface script file */  ipp_attribute_t *attr;	/* Attribute value */ /*  * Add dummy interface and GUI scripts to fool SGI's "challenged" printing  * tools.  First the interface script that tells the tools what kind of  * printer we have...  */  snprintf(filename, sizeof(filename), "/var/spool/lp/interface/%s", p->name);  if (p->type & CUPS_PRINTER_CLASS)    unlink(filename);  else if ((fp = cupsFileOpen(filename, "w")) != NULL)  {    cupsFilePuts(fp, "#!/bin/sh\n");    if ((attr = ippFindAttribute(p->attrs, "printer-make-and-model",                                 IPP_TAG_TEXT)) != NULL)      cupsFilePrintf(fp, "NAME=\"%s\"\n", attr->values[0].string.text);    else if (p->type & CUPS_PRINTER_CLASS)      cupsFilePuts(fp, "NAME=\"Printer Class\"\n");    else      cupsFilePuts(fp, "NAME=\"Remote Destination\"\n");    if (p->type & CUPS_PRINTER_COLOR)      cupsFilePuts(fp, "TYPE=ColorPostScript\n");    else      cupsFilePuts(fp, "TYPE=MonoPostScript\n");    cupsFilePrintf(fp, "HOSTNAME=%s\n", ServerName);    cupsFilePrintf(fp, "HOSTPRINTER=%s\n", p->name);    cupsFileClose(fp);    chmod(filename, 0755);    chown(filename, User, Group);  } /*  * Then the member file that tells which device file the queue is connected  * to...  Networked printers use "/dev/null" in this file, so that's what  * we use (the actual device URI can confuse some apps...)  */  snprintf(filename, sizeof(filename), "/var/spool/lp/member/%s", p->name);  if (p->type & CUPS_PRINTER_CLASS)    unlink(filename);  else if ((fp = cupsFileOpen(filename, "w")) != NULL)  {    cupsFilePuts(fp, "/dev/null\n");    cupsFileClose(fp);    chmod(filename, 0644);    chown(filename, User, Group);  } /*  * The gui_interface file is a script or program that launches a GUI  * option panel for the printer, using options specified on the  * command-line in the third argument.  The option panel must send  * any printing options to stdout on a single line when the user  * accepts them, or nothing if the user cancels the dialog.  *  * The default options panel program is /usr/bin/glpoptions, from  * the ESP Print Pro software.  You can select another using the  * PrintcapGUI option.  */  snprintf(filename, sizeof(filename), "/var/spool/lp/gui_interface/ELF/%s.gui", p->name);  if (p->type & CUPS_PRINTER_CLASS)    unlink(filename);  else if ((fp = cupsFileOpen(filename, "w")) != NULL)  {    cupsFilePuts(fp, "#!/bin/sh\n");    cupsFilePrintf(fp, "%s -d %s -o \"$3\"\n", PrintcapGUI, p->name);    cupsFileClose(fp);    chmod(filename, 0755);    chown(filename, User, Group);  } /*  * The POD config file is needed by the printstatus command to show  * the printer location and device.  */  snprintf(filename, sizeof(filename), "/var/spool/lp/pod/%s.config", p->name);  if (p->type & CUPS_PRINTER_CLASS)    unlink(filename);  else if ((fp = cupsFileOpen(filename, "w")) != NULL)  {    cupsFilePrintf(fp, "Printer Class      | %s\n",            (p->type & CUPS_PRINTER_COLOR) ? "ColorPostScript" : "MonoPostScript");    cupsFilePrintf(fp, "Printer Model      | %s\n", p->make_model ? p->make_model : "");    cupsFilePrintf(fp, "Location Code      | %s\n", p->location ? p->location : "");    cupsFilePrintf(fp, "Physical Location  | %s\n", p->info ? p->info : "");    cupsFilePrintf(fp, "Port Path          | %s\n", p->device_uri ? p->device_uri : "");    cupsFilePrintf(fp, "Config Path        | /var/spool/lp/pod/%s.config\n", p->name);    cupsFilePrintf(fp, "Active Status Path | /var/spool/lp/pod/%s.status\n", p->name);    cupsFilePuts(fp, "Status Update Wait | 10 seconds\n");    cupsFileClose(fp);    chmod(filename, 0664);    chown(filename, User, Group);  }}/* * 'write_irix_state()' - Update the status files used by IRIX printing *                        desktop tools. */static voidwrite_irix_state(printer_t *p)		/* I - Printer to update */{  char		filename[1024];		/* Interface script filename */  cups_file_t	*fp;			/* Interface script file */  int		tag;			/* Status tag value */  if (p)  {   /*    * The POD status file is needed for the printstatus window to    * provide the current status of the printer.    */    snprintf(filename, sizeof(filename), "/var/spool/lp/pod/%s.status", p->name);    if (p->type & CUPS_PRINTER_CLASS)      unlink(filename);    else if ((fp = cupsFileOpen(filename, "w")) != NULL)    {      cupsFilePrintf(fp, "Operational Status | %s\n",              (p->state == IPP_PRINTER_IDLE)       ? "Idle" :              (p->state == IPP_PRINTER_PROCESSING) ? "Busy" :                                                     "Faulted");      cupsFilePrintf(fp, "Information        | 01 00 00 | %s\n", CUPS_SVERSION);      cupsFilePrintf(fp, "Information        | 02 00 00 | Device URI: %s\n",              p->device_uri ? p->device_uri : "");      cupsFilePrintf(fp, "Information        | 03 00 00 | %s jobs\n",              p->accepting ? "Accepting" : "Not accepting");      cupsFilePrintf(fp, "Information        | 04 00 00 | %s\n", p->state_message);      cupsFileClose(fp);      chmod(filename, 0664);      chown(filename, User, Group);    }   /*    * The activeicons file is needed to provide desktop icons for printers:    *    * [ quoted from /usr/lib/print/tagit ]    *    * --- Type of printer tags (base values)    *    * Dumb=66048			# 0x10200    * DumbColor=66080		# 0x10220    * Raster=66112		# 0x10240    * ColorRaster=66144		# 0x10260    * Plotter=66176		# 0x10280    * PostScript=66208		# 0x102A0    * ColorPostScript=66240	# 0x102C0    * MonoPostScript=66272	# 0x102E0    *    * --- Printer state modifiers for local printers    *    * Idle=0			# 0x0    * Busy=1			# 0x1    * Faulted=2			# 0x2    * Unknown=3			# 0x3 (Faulted due to unknown reason)    *    * --- Printer state modifiers for network printers    *    * NetIdle=8			# 0x8    * NetBusy=9			# 0x9    * NetFaulted=10		# 0xA    * NetUnknown=11		# 0xB (Faulted due to unknown reason)    */    snprintf(filename, sizeof(filename), "/var/spool/lp/activeicons/%s", p->name);    if (p->type & CUPS_PRINTER_CLASS)      unlink(filename);    else if ((fp = cupsFileOpen(filename, "w")) != NULL)    {      if (p->type & CUPS_PRINTER_COLOR)	tag = 66240;      else	tag = 66272;      if (p->type & CUPS_PRINTER_REMOTE)	tag |= 8;      if (p->state == IPP_PRINTER_PROCESSING)	tag |= 1;      else if (p->state == IPP_PRINTER_STOPPED)	tag |= 2;      cupsFilePuts(fp, "#!/bin/sh\n");      cupsFilePrintf(fp, "#Tag %d\n", tag);      cupsFileClose(fp);      chmod(filename, 0755);      chown(filename, User, Group);    }  } /*  * The default file is needed by the printers window to show  * the default printer.  */  snprintf(filename, sizeof(filename), "/var/spool/lp/default");  if (DefaultPrinter != NULL)  {    if ((fp = cupsFileOpen(filename, "w")) != NULL)    {      cupsFilePrintf(fp, "%s\n", DefaultPrinter->name);      cupsFileClose(fp);      chmod(filename, 0644);      chown(filename, User, Group);    }  }  else    unlink(filename);}#endif /* __sgi *//* * End of "$Id: printers.c,v 1.167 2005/01/03 19:29:59 mike Exp $". */

⌨️ 快捷键说明

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