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

📄 printers.c

📁 ipp打印机服务器原代码 注意:请将ipp.gz改为ipp.tar.gz 然后使用tar zxvf ipp.tar.gz解压 站长注意
💻 C
📖 第 1 页 / 共 5 页
字号:
    {      p->deny_users = 1;      AddPrinterUser(p, value);    }	#if	0    else if (strcmp(name, "QuotaPeriod") == 0)      p->quota_period = atoi(value);    else if (strcmp(name, "PageLimit") == 0)      p->page_limit = atoi(value);    else if (strcmp(name, "KLimit") == 0)      p->k_limit = atoi(value);#endif    else    {     /*      * Something else we don't understand...      */      LogMessage(L_ERROR, "Unknown configuration directive %s on line %d of printers.conf.",	         name, linenum);    }  }  cupsFileClose(fp);}/* * 'SaveAllPrinters()' - Save all printer definitions to the printers.conf *                       file. */voidSaveAllPrinters(void){  int		i;			/* Looping var */  cups_file_t	*fp;			/* printers.conf file */  char		temp[1024];		/* Temporary string */  char		backup[1024];		/* printers.conf.O file */  printer_t	*printer;		/* Current printer class */  time_t	curtime;		/* Current time */  struct tm	*curdate;		/* Current date */ /*  * Create the printers.conf file...  */  snprintf(temp, sizeof(temp), "%s/printers.conf", ServerRoot);  snprintf(backup, sizeof(backup), "%s/printers.conf.O", ServerRoot);  if (rename(temp, backup))    LogMessage(L_ERROR, "Unable to backup printers.conf - %s", strerror(errno));  if ((fp = cupsFileOpen(temp, "w")) == NULL)  {    LogMessage(L_ERROR, "Unable to save printers.conf - %s", strerror(errno));    if (rename(backup, temp))      LogMessage(L_ERROR, "Unable to restore printers.conf - %s", strerror(errno));    return;  }  else    LogMessage(L_INFO, "Saving printers.conf..."); /*  * Restrict access to the file...  */  fchown(cupsFileNumber(fp), getuid(), Group);  fchmod(cupsFileNumber(fp), ConfigFilePerm); /*  * Write a small header to the file...  */  curtime = time(NULL);  curdate = localtime(&curtime);  strftime(temp, sizeof(temp) - 1, CUPS_STRFTIME_FORMAT, curdate);  cupsFilePuts(fp, "# Printer configuration file for " CUPS_SVERSION "\n");  cupsFilePrintf(fp, "# Written by cupsd on %s\n", temp); /*  * Write each local printer known to the system...  */  for (printer = Printers; printer != NULL; printer = printer->next)  {   /*    * Skip remote destinations and printer classes...    */    if ((printer->type & CUPS_PRINTER_REMOTE) ||        (printer->type & CUPS_PRINTER_CLASS) ||	(printer->type & CUPS_PRINTER_IMPLICIT))      continue;   /*    * Write printers as needed...    */    if (printer == DefaultPrinter)      cupsFilePrintf(fp, "<DefaultPrinter %s>\n", printer->name);    else      cupsFilePrintf(fp, "<Printer %s>\n", printer->name);    if (printer->info)      cupsFilePrintf(fp, "Info %s\n", printer->info);    if (printer->location)      cupsFilePrintf(fp, "Location %s\n", printer->location);    if (printer->device_uri)      cupsFilePrintf(fp, "DeviceURI %s\n", printer->device_uri);    if (printer->state == IPP_PRINTER_STOPPED)    {      cupsFilePuts(fp, "State Stopped\n");      cupsFilePrintf(fp, "StateMessage %s\n", printer->state_message);    }    else      cupsFilePuts(fp, "State Idle\n");    if (printer->accepting)      cupsFilePuts(fp, "Accepting Yes\n");    else      cupsFilePuts(fp, "Accepting No\n");    cupsFilePrintf(fp, "JobSheets %s %s\n", printer->job_sheets[0],            printer->job_sheets[1]);    cupsFilePrintf(fp, "QuotaPeriod %d\n", printer->quota_period);    cupsFilePrintf(fp, "PageLimit %d\n", printer->page_limit);    cupsFilePrintf(fp, "KLimit %d\n", printer->k_limit);    for (i = 0; i < printer->num_users; i ++)      cupsFilePrintf(fp, "%sUser %s\n", printer->deny_users ? "Deny" : "Allow",              printer->users[i]);    cupsFilePuts(fp, "</Printer>\n");#ifdef __sgi    /*     * Make IRIX desktop & printer status happy     */    write_irix_state(printer);#endif /* __sgi */  }  cupsFileClose(fp);}/* * 'SetPrinterAttrs()' - Set printer attributes based upon the PPD file. */voidSetPrinterAttrs(printer_t *p)		/* I - Printer to setup */{  const char	*auth_supported;	/* Authentication supported */  cups_ptype_t	printer_type;		/* Printer type data */#if	0  ppd_file_t	*ppd;			/* PPD file data */  location_t	*auth;			/* Pointer to authentication element */  char		uri[HTTP_MAX_URI];	/* URI for printer */  char		resource[HTTP_MAX_URI];	/* Resource portion of URI */  int		i;			/* Looping var */  char		filename[1024];		/* Name of PPD file */  int		num_media;		/* Number of media options */  ppd_option_t	*input_slot,		/* InputSlot options */		*media_type,		/* MediaType options */		*page_size,		/* PageSize options */		*output_bin,		/* OutputBin options */		*media_quality;		/* EFMediaQualityMode options */  ppd_attr_t	*ppdattr;		/* PPD attribute */  ipp_attribute_t *attr;		/* Attribute data */  ipp_value_t	*val;			/* Attribute value */  int		num_finishings;  ipp_finish_t	finishings[5];		/* finishings-supported values */  static const char * const sides[3] =	/* sides-supported values */		{		  "one",		  "two-long-edge",		  "two-short-edge"		};#endif  DEBUG_printf(("SetPrinterAttrs: entering name = %s, type = %x\n", p->name,                p->type)); /*  * Make sure that we have the common attributes defined...  */  if (!CommonData)    CreateCommonData();#if	0 /*  * Clear out old filters and add a filter from application/vnd.cups-raw to  * printer/name to handle "raw" printing by users.  */  DeletePrinterFilters(p);  AddPrinterFilter(p, "application/vnd.cups-raw 0 -"); /*  * Figure out the authentication that is required for the printer.  */  auth_supported = "requesting-user-name";  if (!(p->type & CUPS_PRINTER_REMOTE))  {    if (p->type & CUPS_PRINTER_CLASS)      snprintf(resource, sizeof(resource), "/classes/%s", p->name);    else      snprintf(resource, sizeof(resource), "/printers/%s", p->name);    if ((auth = FindBest(resource, HTTP_POST)) != NULL)    {      if (auth->type == AUTH_BASIC || auth->type == AUTH_BASICDIGEST)	auth_supported = "basic";      else if (auth->type == AUTH_DIGEST)	auth_supported = "digest";    }  }#endif /*  * Create the required IPP attributes for a printer...  */  if (p->attrs)    ippDelete(p->attrs);  p->attrs = ippNew();  ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI, "printer-uri-supported",               NULL, p->uri);  ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,               "uri-authentication-supported", NULL, auth_supported);  ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,               "uri-security-supported", NULL, "none");  ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME, "printer-name", NULL,               p->name);  ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT, "printer-location",               NULL, p->location ? p->location : "");  ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT, "printer-info",               NULL, p->info ? p->info : "");  ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI, "printer-more-info",               NULL, p->uri);  if (p->num_users)  {    if (p->deny_users)      ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME,                    "requesting-user-name-denied", p->num_users, NULL,		    p->users);    else      ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME,                    "requesting-user-name-allowed", p->num_users, NULL,		    p->users);  }  ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER,                "job-quota-period", p->quota_period);  ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER,                "job-k-limit", p->k_limit);  ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER,                "job-page-limit", p->page_limit);#if	0  if (NumBanners > 0 && !(p->type & CUPS_PRINTER_REMOTE))  {   /*    * Setup the job-sheets-default attribute...    */    attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME,                	 "job-sheets-default", 2, NULL, NULL);    if (attr != NULL)    {      attr->values[0].string.text = strdup(Classification ?	                                   Classification : p->job_sheets[0]);      attr->values[1].string.text = strdup(Classification ?	                                   Classification : p->job_sheets[1]);    }  }#endif  printer_type = p->type;  p->raw = 0;#if 	0  if (p->type & CUPS_PRINTER_REMOTE)  {   /*    * Tell the client this is a remote printer of some type...    */    ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT,                 "printer-make-and-model", NULL, p->make_model);    p->raw = 1;  }  else  {   /*    * Assign additional attributes depending on whether this is a printer    * or class...    */    p->type &= ~CUPS_PRINTER_OPTIONS;    if (p->type & (CUPS_PRINTER_CLASS | CUPS_PRINTER_IMPLICIT))    {     /*      * Add class-specific attributes...      */      if ((p->type & CUPS_PRINTER_IMPLICIT) && p->num_printers > 0)	ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT,                     "printer-make-and-model", NULL, p->printers[0]->make_model);      else	ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT,                     "printer-make-and-model", NULL, "Local Printer Class");      if (p->num_printers > 0)      {       /*	* Add a list of member URIs and names...	*/	attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI,                             "member-uris", p->num_printers, NULL, NULL);        p->type |= CUPS_PRINTER_OPTIONS;	for (i = 0; i < p->num_printers; i ++)	{          if (attr != NULL)            attr->values[i].string.text = strdup(p->printers[i]->uri);	  p->type &= ~CUPS_PRINTER_OPTIONS | p->printers[i]->type;        }	attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME,                             "member-names", p->num_printers, NULL, NULL);	if (attr != NULL)	{	  for (i = 0; i < p->num_printers; i ++)            attr->values[i].string.text = strdup(p->printers[i]->name);        }      }    }    else    {     /*      * Add printer-specific attributes...  Start by sanitizing the device      * URI so it doesn't have a username or password in it...      */      if (!p->device_uri)        strcpy(uri, "file:/dev/null");      else if (strstr(p->device_uri, "://") != NULL)      {       /*        * http://..., ipp://..., etc.	*/        cupsdSanitizeURI(p->device_uri, uri, sizeof(uri));      }      else      {       /*        * file:..., serial:..., etc.	*/        strlcpy(uri, p->device_uri, sizeof(uri));      }      ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI, "device-uri", NULL,        	   uri);     /*      * Assign additional attributes from the PPD file (if any)...      */      p->type        |= CUPS_PRINTER_BW;      finishings[0]  = IPP_FINISHINGS_NONE;      num_finishings = 1;      snprintf(filename, sizeof(filename), "%s/ppd/%s.ppd", ServerRoot,               p->name);      if ((ppd = ppdOpenFile(filename)) != NULL)      {       /*	* Add make/model and other various attributes...	*/	if (ppd->color_device)	  p->type |= CUPS_PRINTER_COLOR;	if (ppd->variable_sizes)	  p->type |= CUPS_PRINTER_VARIABLE;	if (!ppd->manual_copies)	  p->type |= CUPS_PRINTER_COPIES;        if ((ppdattr = ppdFindAttr(ppd, "cupsFax", NULL)) != NULL)	  if (ppdattr->value && !strcasecmp(ppdattr->value, "true"))	    p->type |= CUPS_PRINTER_FAX;	ippAddBoolean(p->attrs, IPP_TAG_PRINTER, "color-supported",                      ppd->color_device);	if (ppd->throughput)	  ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER,	                "pages-per-minute", ppd->throughput);        if (ppd->nickname)          SetString(&p->make_model, ppd->nickname);	else if (ppd->modelname)          SetString(&p->make_model, ppd->modelname);	else	  SetString(&p->make_model, "Bad PPD File");	ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT,                     "printer-make-and-model", NULL, p->make_model);       /*	* Add media options from the PPD file...	*/	if ((input_slot = ppdFindOption(ppd, "InputSlot")) != NULL)	  num_media = input_slot->num_choices;	else	  num_media = 0;	if ((media_type = ppdFindOption(ppd, "MediaType")) != NULL)	  num_media += media_type->num_choices;	if ((page_size = ppdFindOption(ppd, "PageSize")) != NULL)	  num_media += page_size->num_choices;	if ((media_quality = ppdFindOption(ppd, "EFMediaQualityMode")) != NULL)	  num_media += media_quality->num_choices;        if (num_media == 0)	{	  LogMessage(L_CRIT, "SetPrinterAttrs: The PPD file for printer %s "	                     "contains no media options and is therefore "			     "invalid!", p->name);	}	else	{	  attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,                               "media-supported", num_media, NULL, NULL);          if (attr != NULL)	  {	    val = attr->values;	    if (input_slot != NULL)	      for (i = 0; i < input_slot->num_choices; i ++, val ++)		val->string.text = strdup(input_slot->choices[i].choice);	    if (media_type != NULL)	      for (i = 0; i < media_type->num_choices; i ++, val ++)		val->string.text = strdup(media_type->choices[i].choice);	    if (media_quality != NULL)	      for (i = 0; i < media_quality->num_choices; i ++, val ++)		val->string.text = strdup(media_quality->choices[i].choice);	    if (page_size != NULL)	    {	      for (i = 0; i < page_size->num_choices; i ++, val ++)		val->string.text = strdup(page_size->choices[i].choice);	      ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, "media-default",                	   NULL, page_size->defchoice);            }	    else if (input_slot != NULL)	      ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, "media-default",                	   NULL, input_slot->defchoice);	    else if (media_type != NULL)	      ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, "media-default",                	   NULL, media_type->defchoice);	    else if (media_quality != NULL)	      ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, "media-default",                	   NULL, media_quality->defchoice);	    else	      ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, "media-default",                	   NULL, "none");          }        }       /*        * Output bin...	*/	if ((output_bin = ppdFindOption(ppd, "OutputBin")) != NULL)	{

⌨️ 快捷键说明

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