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

📄 ipp2.c

📁 ipp打印机服务器原代码 注意:请将ipp.gz改为ipp.tar.gz 然后使用tar zxvf ipp.tar.gz解压 站长注意
💻 C
📖 第 1 页 / 共 5 页
字号:
      */      snprintf(srcfile, sizeof(srcfile), "%s/model/%s", DataDir,               attr->values[0].string.text);      snprintf(dstfile, sizeof(dstfile), "%s/interfaces/%s", ServerRoot,               printer->name);      unlink(dstfile);      snprintf(dstfile, sizeof(dstfile), "%s/ppd/%s.ppd", ServerRoot,               printer->name);      if (copy_model(srcfile, dstfile))      {        LogMessage(L_ERROR, "add_printer: Unable to copy PPD file from %s to %s - %s!",	           srcfile, dstfile, strerror(errno));        send_ipp_error(con, IPP_INTERNAL_ERROR);	return;      }      else      {        LogMessage(L_DEBUG, "add_printer: Copied PPD file successfully!");        chmod(dstfile, 0644);      }    }  } /*  * Make this printer the default if there is none...  */  if (DefaultPrinter == NULL)    DefaultPrinter = printer; /*  * Update the printer attributes and return...  */  SetPrinterAttrs(printer);  SaveAllPrinters();  if (printer->job != NULL)  {    job_t *job;   /*    * Stop the current job and then restart it below...    */    job = (job_t *)printer->job;    StopJob(job->id, 1);    job->state->values[0].integer = IPP_JOB_PENDING;  }  CheckJobs();  WritePrintcap();  if (modify)    LogMessage(L_INFO, "Printer \'%s\' modified by \'%s\'.", printer->name,               con->username);  else  {    AddPrinterHistory(printer);    LogMessage(L_INFO, "New printer \'%s\' added by \'%s\'.", printer->name,               con->username);  }  con->response->request.status.status_code = IPP_OK;}#endif/* * 'add_printer_state_reasons()' - Add the "printer-state-reasons" attribute *                                 based upon the printer state... */static voidadd_printer_state_reasons(client_t  *con,	/* I - Client connection */                          printer_t *p)		/* I - Printer info */{  LogMessage(L_DEBUG2, "add_printer_state_reasons(%p[%d], %p[%s])\n",             con, con->http.fd, p, p->name);  if (p->num_reasons == 0)    ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,                 "printer-state-reasons", NULL,		 p->state == IPP_PRINTER_STOPPED ? "paused" : "none");  else    ippAddStrings(con->response, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,                  "printer-state-reasons", p->num_reasons, NULL,		  (const char * const *)p->reasons);}/* * 'add_queued_job_count()' - Add the "queued-job-count" attribute for *                            the specified printer or class. */static voidadd_queued_job_count(client_t  *con,	/* I - Client connection */                     printer_t *p)	/* I - Printer or class */{  int		count = 0;			/* Number of jobs on destination */  LogMessage(L_DEBUG2, "add_queued_job_count(%p[%d], %p[%s])\n",             con, con->http.fd, p, p->name);#if	0  count = GetPrinterJobCount(p->name);#endif  ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_INTEGER,                "queued-job-count", count);}#if	0/* * 'cancel_all_jobs()' - Cancel all print jobs. */static voidcancel_all_jobs(client_t        *con,	/* I - Client connection */	        ipp_attribute_t *uri)	/* I - Job or Printer URI */{  const char		*dest;		/* Destination */  cups_ptype_t		dtype;		/* Destination type */  char			method[HTTP_MAX_URI],					/* Method portion of URI */			userpass[HTTP_MAX_URI],					/* Username portion of URI */			host[HTTP_MAX_URI],					/* Host portion of URI */			resource[HTTP_MAX_URI];					/* Resource portion of URI */  int			port;		/* Port portion of URI */  ipp_attribute_t	*attr;		/* Attribute in request */  const char		*username;	/* Username */  int			purge;		/* Purge? */  LogMessage(L_DEBUG2, "cancel_all_jobs(%p[%d], %s)\n", con, con->http.fd,             uri->values[0].string.text); /*  * Was this operation called from the correct URI?  */  if (strncmp(con->uri, "/admin/", 7) != 0)  {    LogMessage(L_ERROR, "cancel_all_jobs: admin request on bad resource \'%s\'!",               con->uri);    send_ipp_error(con, IPP_NOT_AUTHORIZED);    return;  } /*  * See if we have a printer URI...  */  if (strcmp(uri->name, "printer-uri") != 0)  {    LogMessage(L_ERROR, "cancel_all_jobs: bad %s attribute \'%s\'!",               uri->name, uri->values[0].string.text);    send_ipp_error(con, IPP_BAD_REQUEST);    return;  } /*  * Get the username (if any) for the jobs we want to cancel (only if  * "my-jobs" is specified...  */  if ((attr = ippFindAttribute(con->request, "my-jobs", IPP_TAG_BOOLEAN)) != NULL &&      attr->values[0].boolean)  {    if ((attr = ippFindAttribute(con->request, "requesting-user-name", IPP_TAG_NAME)) != NULL)      username = attr->values[0].string.text;    else    {      LogMessage(L_ERROR, "cancel_all_jobs: missing requesting-user-name attribute!");      send_ipp_error(con, IPP_BAD_REQUEST);      return;    }  }  else    username = NULL; /*  * Look for the "purge-jobs" attribute...  */  if ((attr = ippFindAttribute(con->request, "purge-jobs", IPP_TAG_BOOLEAN)) != NULL)    purge = attr->values[0].boolean;  else    purge = 1; /*  * And if the destination is valid...  */  httpSeparate(uri->values[0].string.text, method, userpass, host, &port,               resource);  if ((dest = ValidateDest(host, resource, &dtype)) == NULL)  {   /*    * Bad URI?    */    if (strcmp(resource, "/printers/") != 0)    {      LogMessage(L_ERROR, "cancel_all_jobs: resource name \'%s\' no good!", resource);      send_ipp_error(con, IPP_NOT_FOUND);      return;    }   /*    * Cancel all jobs on all printers...    */    CancelJobs(NULL, username, purge);    LogMessage(L_INFO, "All jobs were %s by \'%s\'.",               purge ? "purged" : "cancelled", con->username);  }  else  {   /*    * Cancel all of the jobs on the named printer...    */    CancelJobs(dest, username, purge);    LogMessage(L_INFO, "All jobs on \'%s\' were %s by \'%s\'.", dest,               purge ? "purged" : "cancelled", con->username);  }  con->response->request.status.status_code = IPP_OK;}/* * 'cancel_job()' - Cancel a print job. */static voidcancel_job(client_t        *con,	/* I - Client connection */	   ipp_attribute_t *uri)	/* I - Job or Printer URI */{  ipp_attribute_t	*attr;		/* Current attribute */  int			jobid;		/* Job ID */  char			method[HTTP_MAX_URI],					/* Method portion of URI */			username[HTTP_MAX_URI],					/* Username portion of URI */			host[HTTP_MAX_URI],					/* Host portion of URI */			resource[HTTP_MAX_URI];					/* Resource portion of URI */  int			port;		/* Port portion of URI */  job_t			*job;		/* Job information */  const char		*dest;		/* Destination */  cups_ptype_t		dtype;		/* Destination type (printer or class) */  printer_t		*printer;	/* Printer data */  LogMessage(L_DEBUG2, "cancel_job(%p[%d], %s)\n", con, con->http.fd,             uri->values[0].string.text); /*  * Verify that the POST operation was done to a valid URI.  */  if (strncmp(con->uri, "/classes/", 9) != 0 &&      strncmp(con->uri, "/jobs/", 5) != 0 &&      strncmp(con->uri, "/printers/", 10) != 0)  {    LogMessage(L_ERROR, "cancel_job: cancel request on bad resource \'%s\'!",               con->uri);    send_ipp_error(con, IPP_NOT_AUTHORIZED);    return;  } /*  * See if we have a job URI or a printer URI...  */  if (strcmp(uri->name, "printer-uri") == 0)  {   /*    * Got a printer URI; see if we also have a job-id attribute...    */    if ((attr = ippFindAttribute(con->request, "job-id", IPP_TAG_INTEGER)) == NULL)    {      LogMessage(L_ERROR, "cancel_job: got a printer-uri attribute but no job-id!");      send_ipp_error(con, IPP_BAD_REQUEST);      return;    }    if ((jobid = attr->values[0].integer) == 0)    {     /*      * Find the current job on the specified printer...      */      httpSeparate(uri->values[0].string.text, method, username, host, &port, resource);      if ((dest = ValidateDest(host, resource, &dtype)) == NULL)      {       /*	* Bad URI...	*/	LogMessage(L_ERROR, "cancel_job: resource name \'%s\' no good!", resource);	send_ipp_error(con, IPP_NOT_FOUND);	return;      }      if (dtype & CUPS_PRINTER_CLASS)        printer = FindClass(dest);      else        printer = FindPrinter(dest);     /*      * See if the printer is currently printing a job...      */      if (printer->job)        jobid = ((job_t *)printer->job)->id;      else      {       /*        * No, see if there are any pending jobs...	*/        for (job = Jobs; job != NULL; job = job->next)	  if (job->state->values[0].integer <= IPP_JOB_PROCESSING &&	      strcasecmp(job->dest, dest) == 0)	    break;	if (job != NULL)	  jobid = job->id;	else	{	  LogMessage(L_ERROR, "cancel_job: No active jobs on %s!", dest);	  send_ipp_error(con, IPP_NOT_POSSIBLE);	  return;	}      }    }  }  else  {   /*    * Got a job URI; parse it to get the job ID...    */    httpSeparate(uri->values[0].string.text, method, username, host, &port, resource);     if (strncmp(resource, "/jobs/", 6) != 0)    {     /*      * Not a valid URI!      */      LogMessage(L_ERROR, "cancel_job: bad job-uri attribute \'%s\'!",                 uri->values[0].string.text);      send_ipp_error(con, IPP_BAD_REQUEST);      return;    }    jobid = atoi(resource + 6);  } /*  * See if the job exists...  */  if ((job = FindJob(jobid)) == NULL)  {   /*    * Nope - return a "not found" error...    */    LogMessage(L_ERROR, "cancel_job: job #%d doesn't exist!", jobid);    send_ipp_error(con, IPP_NOT_FOUND);    return;  } /*  * See if the job is owned by the requesting user...  */  if (!validate_user(con, job->username, username, sizeof(username)))  {    LogMessage(L_ERROR, "cancel_job: \"%s\" not authorized to delete job id %d owned by \"%s\"!",               username, jobid, job->username);    send_ipp_error(con, IPP_FORBIDDEN);    return;  } /*  * See if the job is already completed, cancelled, or aborted; if so,  * we can't cancel...  */  if (job->state->values[0].integer >= IPP_JOB_CANCELLED)  {    LogMessage(L_ERROR, "cancel_job: job id %d is %s - can't cancel!",               jobid,	       job->state->values[0].integer == IPP_JOB_CANCELLED ? "cancelled" :	       job->state->values[0].integer == IPP_JOB_ABORTED ? "aborted" :	       "completed");    send_ipp_error(con, IPP_NOT_POSSIBLE);    return;  } /*  * Cancel the job and return...  */  CancelJob(jobid, 0);  CheckJobs();  LogMessage(L_INFO, "Job %d was cancelled by \'%s\'.", jobid, username);  con->response->request.status.status_code = IPP_OK;}/* * 'check_quotas()' - Check quotas for a printer and user. */static int			/* O - 1 if OK, 0 if not */check_quotas(client_t  *con,	/* I - Client connection */             printer_t *p)	/* I - Printer or class */{  int		i, j;		/* Looping vars */  ipp_attribute_t *attr;	/* Current attribute */  char		username[33];	/* Username */  quota_t	*q;		/* Quota data */  struct passwd	*pw;		/* User password data */  struct group	*grp;		/* Group data */  LogMessage(L_DEBUG2, "check_quotas(%p[%d], %p[%s])\n",             con, con->http.fd, p, p->name); /*  * Check input...  */  if (con == NULL || p == NULL)    return (0); /*  * Figure out who is printing...  */  attr = ippFindAttribute(con->request, "requesting-user-name", IPP_TAG_NAME);  if (con->username[0])    strlcpy(username, con->username, sizeof(username));  else if (attr != NULL)  {    LogMessage(L_DEBUG, "check_quotas: requesting-user-name = \'%s\'",               attr->values[0].string.text);    strlcpy(username, attr->values[0].string.text, sizeof(username));  }  else

⌨️ 快捷键说明

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