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

📄 ipp2.c

📁 ipp打印机服务器原代码 注意:请将ipp.gz改为ipp.tar.gz 然后使用tar zxvf ipp.tar.gz解压 站长注意
💻 C
📖 第 1 页 / 共 5 页
字号:
    strcpy(username, "anonymous"); /*  * Check global active job limits for printers and users...  */  if (MaxJobsPerPrinter)  {   /*    * Check if there are too many pending jobs on this printer...    */    if (GetPrinterJobCount(p->name) >= MaxJobsPerPrinter)    {      LogMessage(L_INFO, "Too many jobs for printer \"%s\"...", p->name);      return (0);    }  }  if (MaxJobsPerUser)  {   /*    * Check if there are too many pending jobs for this user...    */    if (GetUserJobCount(username) >= MaxJobsPerUser)    {      LogMessage(L_INFO, "Too many jobs for user \"%s\"...", username);      return (0);    }  } /*  * Check against users...  */  if (p->num_users == 0 && p->k_limit == 0 && p->page_limit == 0)    return (1);  if (p->num_users)  {    pw = getpwnam(username);    endpwent();    for (i = 0; i < p->num_users; i ++)      if (p->users[i][0] == '@')      {       /*        * Check group membership...	*/        grp = getgrnam(p->users[i] + 1);	endgrent();        if (grp)	{	 /*	  * Check primary group...	  */	  if (pw && grp->gr_gid == pw->pw_gid)	    break;         /*	  * Check usernames in group...	  */          for (j = 0; grp->gr_mem[j]; j ++)	    if (!strcasecmp(username, grp->gr_mem[j]))	      break;          if (grp->gr_mem[j])	    break;	}      }      else if (!strcasecmp(username, p->users[i]))	break;    if ((i < p->num_users) == p->deny_users)    {      LogMessage(L_INFO, "Denying user \"%s\" access to printer \"%s\"...",        	 username, p->name);      return (0);    }  } /*  * Check quotas...  */  if (p->k_limit || p->page_limit)  {    if ((q = UpdateQuota(p, username, 0, 0)) == NULL)    {      LogMessage(L_ERROR, "Unable to allocate quota data for user \"%s\"!",                 username);      return (0);    }    if ((q->k_count >= p->k_limit && p->k_limit) ||        (q->page_count >= p->page_limit && p->page_limit))    {      LogMessage(L_INFO, "User \"%s\" is over the quota limit...",                 username);      return (0);    }  } /*  * If we have gotten this far, we're done!  */  return (1);}#endif/* * 'copy_attribute()' - Copy a single attribute. */static ipp_attribute_t *		/* O - New attribute */copy_attribute(ipp_t           *to,	/* O - Destination request/response */               ipp_attribute_t *attr,	/* I - Attribute to copy */               int             quickcopy)/* I - Do a quick copy? */{  int			i;		/* Looping var */  ipp_attribute_t	*toattr;	/* Destination attribute */  LogMessage(L_DEBUG2, "copy_attribute(%p, %p[%s,%x,%x])\n", to, attr,             attr->name ? attr->name : "(null)", attr->group_tag,	     attr->value_tag);  switch (attr->value_tag & ~IPP_TAG_COPY)  {    case IPP_TAG_ZERO :        toattr = ippAddSeparator(to);	break;    case IPP_TAG_INTEGER :    case IPP_TAG_ENUM :        toattr = ippAddIntegers(to, attr->group_tag, attr->value_tag,	                        attr->name, attr->num_values, NULL);        for (i = 0; i < attr->num_values; i ++)	  toattr->values[i].integer = attr->values[i].integer;        break;    case IPP_TAG_BOOLEAN :        toattr = ippAddBooleans(to, attr->group_tag, attr->name,	                        attr->num_values, NULL);        for (i = 0; i < attr->num_values; i ++)	  toattr->values[i].boolean = attr->values[i].boolean;        break;    case IPP_TAG_STRING :    case IPP_TAG_TEXT :    case IPP_TAG_NAME :    case IPP_TAG_KEYWORD :    case IPP_TAG_URI :    case IPP_TAG_URISCHEME :    case IPP_TAG_CHARSET :    case IPP_TAG_LANGUAGE :    case IPP_TAG_MIMETYPE :        toattr = ippAddStrings(to, attr->group_tag,	                       (ipp_tag_t)(attr->value_tag | quickcopy),	                       attr->name, attr->num_values, NULL, NULL);        if (quickcopy)	{          for (i = 0; i < attr->num_values; i ++)	    toattr->values[i].string.text = attr->values[i].string.text;        }	else	{          for (i = 0; i < attr->num_values; i ++)	    toattr->values[i].string.text = strdup(attr->values[i].string.text);	}        break;    case IPP_TAG_DATE :        toattr = ippAddDate(to, attr->group_tag, attr->name,	                    attr->values[0].date);        break;    case IPP_TAG_RESOLUTION :        toattr = ippAddResolutions(to, attr->group_tag, attr->name,	                           attr->num_values, IPP_RES_PER_INCH,				   NULL, NULL);        for (i = 0; i < attr->num_values; i ++)	{	  toattr->values[i].resolution.xres  = attr->values[i].resolution.xres;	  toattr->values[i].resolution.yres  = attr->values[i].resolution.yres;	  toattr->values[i].resolution.units = attr->values[i].resolution.units;	}        break;    case IPP_TAG_RANGE :        toattr = ippAddRanges(to, attr->group_tag, attr->name,	                      attr->num_values, NULL, NULL);        for (i = 0; i < attr->num_values; i ++)	{	  toattr->values[i].range.lower = attr->values[i].range.lower;	  toattr->values[i].range.upper = attr->values[i].range.upper;	}        break;    case IPP_TAG_TEXTLANG :    case IPP_TAG_NAMELANG :        toattr = ippAddStrings(to, attr->group_tag,	                       (ipp_tag_t)(attr->value_tag | quickcopy),	                       attr->name, attr->num_values, NULL, NULL);        if (quickcopy)	{          for (i = 0; i < attr->num_values; i ++)	  {            toattr->values[i].string.charset = attr->values[i].string.charset;	    toattr->values[i].string.text    = attr->values[i].string.text;          }        }	else	{          for (i = 0; i < attr->num_values; i ++)	  {	    if (!i)              toattr->values[i].string.charset =	          strdup(attr->values[i].string.charset);	    else              toattr->values[i].string.charset =	          toattr->values[0].string.charset;	    toattr->values[i].string.text = strdup(attr->values[i].string.text);          }        }        break;    case IPP_TAG_BEGIN_COLLECTION :        toattr = ippAddCollections(to, attr->group_tag, attr->name,	                           attr->num_values, NULL);        for (i = 0; i < attr->num_values; i ++)	{	  toattr->values[i].collection = ippNew();	  copy_attrs(toattr->values[i].collection, attr->values[i].collection,	             NULL, IPP_TAG_ZERO, 0);	}        break;    default :        toattr = ippAddIntegers(to, attr->group_tag, attr->value_tag,	                        attr->name, attr->num_values, NULL);        for (i = 0; i < attr->num_values; i ++)	{	  toattr->values[i].unknown.length = attr->values[i].unknown.length;	  if (toattr->values[i].unknown.length > 0)	  {	    if ((toattr->values[i].unknown.data = malloc(toattr->values[i].unknown.length)) == NULL)	      toattr->values[i].unknown.length = 0;	    else	      memcpy(toattr->values[i].unknown.data,		     attr->values[i].unknown.data,		     toattr->values[i].unknown.length);	  }	}        break; /* anti-compiler-warning-code */  }  return (toattr);}/* * 'copy_attrs()' - Copy attributes from one request to another. */static voidcopy_attrs(ipp_t           *to,		/* I - Destination request */           ipp_t           *from,	/* I - Source request */           ipp_attribute_t *req,	/* I - Requested attributes */	   ipp_tag_t       group,	/* I - Group to copy */	   int             quickcopy)	/* I - Do a quick copy? */{  int			i;		/* Looping var */  ipp_attribute_t	*fromattr;	/* Source attribute */  LogMessage(L_DEBUG2, "copy_attrs(%p, %p, %p, %x)\n", to, from, req, group);  if (to == NULL || from == NULL)    return;  if (req != NULL && strcmp(req->values[0].string.text, "all") == 0)    req = NULL;				/* "all" means no filter... */  for (fromattr = from->attrs; fromattr != NULL; fromattr = fromattr->next)  {   /*    * Filter attributes as needed...    */    if (group != IPP_TAG_ZERO && fromattr->group_tag != group &&        fromattr->group_tag != IPP_TAG_ZERO)      continue;    if (req != NULL && fromattr->name != NULL)    {      for (i = 0; i < req->num_values; i ++)        if (strcmp(fromattr->name, req->values[i].string.text) == 0)	  break;      if (i == req->num_values)        continue;    }    copy_attribute(to, fromattr, quickcopy);  }}#if	0/* * 'copy_banner()' - Copy a banner file to the requests directory for the *                   specified job. */static int			/* O - Size of banner file in kbytes */copy_banner(client_t   *con,	/* I - Client connection */            job_t      *job,	/* I - Job information */            const char *name)	/* I - Name of banner */{  int		i;		/* Looping var */  int		kbytes;		/* Size of banner file in kbytes */  char		filename[1024];	/* Job filename */  banner_t	*banner;	/* Pointer to banner */  cups_file_t	*in;		/* Input file */  cups_file_t	*out;		/* Output file */  int		ch;		/* Character from file */  char		attrname[255],	/* Name of attribute */		*s;		/* Pointer into name */  ipp_attribute_t *attr;	/* Attribute */  LogMessage(L_DEBUG2, "copy_banner(%p[%d], %p[%d], %s)",             con, con->http.fd, job, job->id, name ? name : "(null)"); /*  * Find the banner; return if not found or "none"...  */  if (name == NULL ||      strcmp(name, "none") == 0 ||      (banner = FindBanner(name)) == NULL)    return (0); /*  * Open the banner and job files...  */  if (add_file(con, job, banner->filetype, 0))    return (0);  snprintf(filename, sizeof(filename), "%s/d%05d-%03d", RequestRoot, job->id,           job->num_files);  if ((out = cupsFileOpen(filename, "w")) == NULL)  {    LogMessage(L_ERROR, "copy_banner: Unable to create banner job file %s - %s",               filename, strerror(errno));    job->num_files --;    return (0);  }  fchmod(cupsFileNumber(out), 0640);  fchown(cupsFileNumber(out), RunUser, Group);  if (con->language)  {   /*    * Try the localized banner file under the subdirectory...    */    snprintf(filename, sizeof(filename), "%s/banners/%s/%s", DataDir,             con->language->language, name);    if (access(filename, 0) && con->language->language[2])    {     /*      * Wasn't able to find "ll_CC" locale file; try the non-national      * localization banner directory.      */      attrname[0] = con->language->language[0];      attrname[1] = con->language->language[1];      attrname[2] = '\0';      snprintf(filename, sizeof(filename), "%s/banners/%s/%s", DataDir,               attrname, name);    }    if (access(filename, 0))    {     /*      * Use the non-localized banner file.      */      snprintf(filename, sizeof(filename), "%s/banners/%s", DataDir, name);    }  }  else  {   /*    * Use the non-localized banner file.    */    snprintf(filename, sizeof(filename), "%s/banners/%s", DataDir, name);  }  if ((in = cupsFileOpen(filename, "r")) == NULL)  {    cupsFileClose(out);    unlink(filename);    LogMessage(L_ERROR, "copy_banner: Unable to open banner template file %s - %s",               filename, strerror(errno));    job->num_files --;    return (0);  } /*  * Parse the file to the end...  */  while ((ch = cupsFileGetChar(in)) != EOF)    if (ch == '{')    {     /*      * Get an attribute name...      */      for (s = attrname; (ch = cupsFileGetChar(in)) != EOF;)        if (!isalpha(ch & 255) && ch != '-' && ch != '?')          break;	else if (s < (attrname + sizeof(attrname) - 1))          *s++ = ch;	else	  break;      *s = '\0';      if (ch != '}')      {       /*        * Ignore { followed by stuff that is not an attribute name...	*/        cupsFilePrintf(out, "{%s%c", attrname, ch);	continue;      }     /*      * See if it is defined...      */      if (attrname[0] == '?')        s = attrname + 1;      else        s = attrname;      if (strcmp(s, "printer-name") == 0)      {        cupsFilePuts(out, job->dest);	continue;      }      else if ((attr = ippFindAttribute(job->attrs, s, IPP_TAG_ZERO)) == NULL)

⌨️ 快捷键说明

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