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

📄 printers.c

📁 ipp打印机服务器原代码 注意:请将ipp.gz改为ipp.tar.gz 然后使用tar zxvf ipp.tar.gz解压 站长注意
💻 C
📖 第 1 页 / 共 5 页
字号:
	  attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,                               "output-bin-supported", output_bin->num_choices,			       NULL, NULL);          if (attr != NULL)	  {	    for (i = 0, val = attr->values;		 i < output_bin->num_choices;		 i ++, val ++)	      val->string.text = strdup(output_bin->choices[i].choice);          }	}       /*        * Duplexing, etc...	*/	if (ppdFindOption(ppd, "Duplex") != NULL)	{	  p->type |= CUPS_PRINTER_DUPLEX;	  ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, "sides-supported",                	3, NULL, sides);	  ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, "sides-default",                       NULL, "one");	}	if (ppdFindOption(ppd, "Collate") != NULL)	  p->type |= CUPS_PRINTER_COLLATE;	if (ppdFindOption(ppd, "StapleLocation") != NULL)	{	  p->type |= CUPS_PRINTER_STAPLE;	  finishings[num_finishings++] = IPP_FINISHINGS_STAPLE;	}	if (ppdFindOption(ppd, "BindEdge") != NULL)	{	  p->type |= CUPS_PRINTER_BIND;	  finishings[num_finishings++] = IPP_FINISHINGS_BIND;	}	for (i = 0; i < ppd->num_sizes; i ++)	  if (ppd->sizes[i].length > 1728)            p->type |= CUPS_PRINTER_LARGE;	  else if (ppd->sizes[i].length > 1008)            p->type |= CUPS_PRINTER_MEDIUM;	  else            p->type |= CUPS_PRINTER_SMALL;       /*	* Add any filters in the PPD file...	*/	DEBUG_printf(("ppd->num_filters = %d\n", ppd->num_filters));	for (i = 0; i < ppd->num_filters; i ++)	{          DEBUG_printf(("ppd->filters[%d] = \"%s\"\n", i, ppd->filters[i]));          AddPrinterFilter(p, ppd->filters[i]);	}	if (ppd->num_filters == 0)          AddPrinterFilter(p, "application/vnd.cups-postscript 0 -");	ppdClose(ppd);        printer_type = p->type;      }      else if (access(filename, 0) == 0)      {        int		pline;			/* PPD line number */	ppd_status_t	pstatus;		/* PPD load status */        pstatus = ppdLastError(&pline);	LogMessage(L_ERROR, "PPD file for %s cannot be loaded!", p->name);	if (pstatus <= PPD_ALLOC_ERROR)	  LogMessage(L_ERROR, "%s", strerror(errno));        else	  LogMessage(L_ERROR, "%s on line %d.", ppdErrorString(pstatus),	             pline);        LogMessage(L_INFO, "Hint: Run \"cupstestppd %s\" and fix any errors.",	           filename);	AddPrinterFilter(p, "application/vnd.cups-postscript 0 -");      }      else      {       /*	* If we have an interface script, add a filter entry for it...	*/	snprintf(filename, sizeof(filename), "%s/interfaces/%s", ServerRoot,	         p->name);	if (access(filename, X_OK) == 0)	{	 /*	  * Yes, we have a System V style interface script; use it!	  */	  ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT,                       "printer-make-and-model", NULL, "Local System V Printer");	  snprintf(filename, sizeof(filename), "*/* 0 %s/interfaces/%s",	           ServerRoot, p->name);	  AddPrinterFilter(p, filename);	}	else if (p->device_uri &&	         strncmp(p->device_uri, "ipp://", 6) == 0 &&	         (strstr(p->device_uri, "/printers/") != NULL ||		  strstr(p->device_uri, "/classes/") != NULL))        {	 /*	  * Tell the client this is really a hard-wired remote printer.	  */          printer_type |= CUPS_PRINTER_REMOTE;         /*	  * Reset the printer-uri-supported attribute to point at the	  * remote printer...	  */	  attr = ippFindAttribute(p->attrs, "printer-uri-supported", IPP_TAG_URI);	  free(attr->values[0].string.text);	  attr->values[0].string.text = strdup(p->device_uri);         /*	  * Then set the make-and-model accordingly...	  */	  ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT,                       "printer-make-and-model", NULL, "Remote Printer");         /*	  * Print all files directly...	  */	  p->raw = 1;	}	else	{	 /*          * Otherwise we have neither - treat this as a "dumb" printer	  * with no PPD file...	  */	  ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT,                       "printer-make-and-model", NULL, "Local Raw Printer");	  p->raw = 1;	}      }      ippAddIntegers(p->attrs, IPP_TAG_PRINTER, IPP_TAG_ENUM,                     "finishings-supported", num_finishings, (int *)finishings);      ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_ENUM,                    "finishings-default", IPP_FINISHINGS_NONE);    }  }#endif /*  * Add the CUPS-specific printer-type attribute...  */  ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_ENUM, "printer-type",                printer_type);  DEBUG_printf(("SetPrinterAttrs: leaving name = %s, type = %x\n", p->name,                p->type));#ifdef __sgi /*  * Write the IRIX printer config and status files...  */  write_irix_config(p);  write_irix_state(p);#endif /* __sgi */}#if	0/* * 'SetPrinterReasons()' - Set/update the reasons strings. */voidSetPrinterReasons(printer_t  *p,	/* I - Printer */                  const char *s)	/* I - Reasons strings */{  int		i;			/* Looping var */  const char	*sptr;			/* Pointer into reasons */  char		reason[255],		/* Reason string */		*rptr;			/* Pointer into reason */  if (s[0] == '-' || s[0] == '+')  {   /*    * Add/remove reasons...    */    sptr = s + 1;  }  else  {   /*    * Replace reasons...    */    sptr = s;    for (i = 0; i < p->num_reasons; i ++)      free(p->reasons[i]);    p->num_reasons = 0;  } /*  * Loop through all of the reasons...  */  while (*sptr)  {   /*    * Skip leading whitespace and commas...    */    while (isspace(*sptr & 255) || *sptr == ',')      sptr ++;    for (rptr = reason; *sptr && !isspace(*sptr & 255) && *sptr != ','; sptr ++)      if (rptr < (reason + sizeof(reason) - 1))        *rptr++ = *sptr;    if (rptr == reason)      break;    *rptr = '\0';    if (s[0] == '-')    {     /*      * Remove reason...      */      for (i = 0; i < p->num_reasons; i ++)        if (!strcasecmp(reason, p->reasons[i]))	{	 /*	  * Found a match, so remove it...	  */	  p->num_reasons --;	  free(p->reasons[i]);	  if (i < p->num_reasons)	    memmove(p->reasons + i, p->reasons + i + 1,	            (p->num_reasons - i) * sizeof(char *));	  i --;	}    }    else if (p->num_reasons < (int)(sizeof(p->reasons) / sizeof(p->reasons[0])))    {     /*      * Add reason...      */      for (i = 0; i < p->num_reasons; i ++)        if (!strcasecmp(reason, p->reasons[i]))	  break;      if (i >= p->num_reasons)      {        p->reasons[i] = strdup(reason);	p->num_reasons ++;      }    }  }}/* * 'SetPrinterState()' - Update the current state of a printer. */voidSetPrinterState(printer_t    *p,	/* I - Printer to change */                ipp_pstate_t s,		/* I - New state */		int          update)	/* I - Update printers.conf? */{  ipp_pstate_t	old_state;		/* Old printer state */ /*  * Can't set status of remote printers...  */  if (p->type & CUPS_PRINTER_REMOTE)    return; /*  * Set the new state...  */  old_state = p->state;  p->state  = s;  if (old_state != s)  {   /*    * Let the browse code know this needs to be updated...    */    BrowseNext     = p;    p->state_time  = time(NULL);    p->browse_time = 0;#ifdef __sgi    write_irix_state(p);#endif /* __sgi */  }  AddPrinterHistory(p); /*  * Save the printer configuration if a printer goes from idle or processing  * to stopped (or visa-versa)...  */  if ((old_state == IPP_PRINTER_STOPPED) != (s == IPP_PRINTER_STOPPED) &&      update)  {    if (p->type & CUPS_PRINTER_CLASS)      SaveAllClasses();    else      SaveAllPrinters();  }}/* * 'SortPrinters()' - Sort the printer list when a printer name is changed. */voidSortPrinters(void){  printer_t	*current,	/* Current printer */		*prev,		/* Previous printer */		*next;		/* Next printer */  int		did_swap;	/* Non-zero if we did a swap */  do  {    for (did_swap = 0, current = Printers, prev = NULL; current != NULL;)      if (current->next == NULL)	break;      else if (strcasecmp(current->name, current->next->name) > 0)      {	DEBUG_printf(("Swapping %s and %s...\n", current->name,                      current->next->name));       /*	* Need to swap these two printers...	*/        did_swap = 1;	if (prev == NULL)          Printers = current->next;	else          prev->next = current->next;       /*	* Yes, we can all get a headache from the next bunch of pointer	* swapping...	*/	next          = current->next;	current->next = next->next;	next->next    = current;	prev          = next;      }      else      {        prev    = current;	current = current->next;      }  }  while (did_swap);}/* * 'StopPrinter()' - Stop a printer from printing any jobs... */voidStopPrinter(printer_t *p,		/* I - Printer to stop */            int       update)		/* I - Update printers.conf? */{  job_t	*job;				/* Active print job */ /*  * Set the printer state...  */  SetPrinterState(p, IPP_PRINTER_STOPPED, update); /*  * See if we have a job printing on this printer...  */  if (p->job)  {   /*    * Get pointer to job...    */    job = (job_t *)p->job;   /*    * Stop it...    */    StopJob(job->id, 0);   /*    * Reset the state to pending...    */    job->state->values[0].integer = IPP_JOB_PENDING;    SaveJob(job->id);  }}#endif/* * 'ValidateDest()' - Validate a printer/class destination. */const char *				/* O - Printer or class name */ValidateDest(const char   *hostname,	/* I - Host name */             const char   *resource)	/* I - Resource name */             /* cups_ptype_t *dtype)	O - Type (printer or class) */{  printer_t	*p;			/* Current printer */  char		localname[1024],	/* Localized hostname */		*lptr,			/* Pointer into localized hostname */		*sptr;			/* Pointer into server name */  /*  * See if the resource is a class or printer...    if (strncmp(resource, "/classes/", 9) == 0)  {       * Class...        resource += 9;  }  else */  	if (strncmp(resource, "/printers/", 10) == 0)  {   /*    * Printer...    */    resource += 10;  }  else  {   /*    * Bad resource name...    */    return (NULL);  } /*  * See if the printer or class name exists...  */  if ((p = FindPrinter(resource)) == NULL)  /*  p = FindClass(resource);  	if (p == NULL && strchr(resource, '@') == NULL)  */    return (NULL);  else if (p != NULL)  {  /*    *dtype = p->type & (CUPS_PRINTER_CLASS | CUPS_PRINTER_IMPLICIT |                        CUPS_PRINTER_REMOTE);

⌨️ 快捷键说明

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