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

📄 ipp2.c

📁 ipp打印机服务器原代码 注意:请将ipp.gz改为ipp.tar.gz 然后使用tar zxvf ipp.tar.gz解压 站长注意
💻 C
📖 第 1 页 / 共 5 页
字号:
#endif /* 0 */    {      con->http.data_encoding  = HTTP_ENCODE_LENGTH;      con->http.data_remaining = ippLength(con->response);      httpPrintf(HTTP(con), "Content-Length: %d\r\n\r\n",        	 con->http.data_remaining);    }    LogMessage(L_DEBUG2, "ProcessIPPRequest: Adding fd %d to OutputSet...",               con->http.fd);    FD_SET(con->http.fd, OutputSet);   /*    * Tell the caller the response header was sent successfully...    */    return (1);  }  else  {   /*    * Tell the caller the response header could not be sent...    */    return (0);  }}#if	0/* * 'accept_jobs()' - Accept print jobs to a printer. */static voidaccept_jobs(client_t        *con,	/* I - Client connection */            ipp_attribute_t *uri)	/* I - Printer or class URI */{  cups_ptype_t		dtype;		/* Destination type (printer or class) */  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 */  const char		*name;		/* Printer name */  printer_t		*printer;	/* Printer data */  LogMessage(L_DEBUG2, "accept_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, "accept_jobs: admin request on bad resource \'%s\'!",               con->uri);    send_ipp_error(con, IPP_NOT_AUTHORIZED);    return;  } /*  * Is the destination valid?  */  httpSeparate(uri->values[0].string.text, method, username, host, &port, resource);  if ((name = ValidateDest(host, resource, &dtype)) == NULL)  {   /*    * Bad URI...    */    LogMessage(L_ERROR, "accept_jobs: resource name \'%s\' no good!", resource);    send_ipp_error(con, IPP_NOT_FOUND);    return;  } /*  * Accept jobs sent to the printer...  */  if (dtype & CUPS_PRINTER_CLASS)    printer = FindClass(name);  else    printer = FindPrinter(name);  printer->accepting        = 1;  printer->state_message[0] = '\0';  AddPrinterHistory(printer);  if (dtype & CUPS_PRINTER_CLASS)    SaveAllClasses();  else    SaveAllPrinters();  LogMessage(L_INFO, "Printer \'%s\' now accepting jobs (\'%s\').", name,             con->username); /*  * Everything was ok, so return OK status...  */  con->response->request.status.status_code = IPP_OK;}/* * 'add_class()' - Add a class to the system. */static voidadd_class(client_t        *con,		/* I - Client connection */          ipp_attribute_t *uri)		/* I - URI of class */{  int			i;		/* Looping var */  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 */  printer_t		*pclass;	/* Class */  cups_ptype_t		dtype;		/* Destination type */  const char		*dest;		/* Printer or class name */  ipp_attribute_t	*attr;		/* Printer attribute */  int			modify;		/* Non-zero if we just modified */  LogMessage(L_DEBUG2, "add_class(%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, "add_class: admin request on bad resource \'%s\'!",               con->uri);    send_ipp_error(con, IPP_NOT_AUTHORIZED);    return;  } /*  * Do we have a valid URI?  */  httpSeparate(uri->values[0].string.text, method, username, host, &port, resource);  if (strncmp(resource, "/classes/", 9) != 0 || strlen(resource) == 9)  {   /*    * No, return an error...    */    send_ipp_error(con, IPP_BAD_REQUEST);    return;  } /*  * See if the class already exists; if not, create a new class...  */  if ((pclass = FindClass(resource + 9)) == NULL)  {   /*    * Class doesn't exist; see if we have a printer of the same name...    */    if ((pclass = FindPrinter(resource + 9)) != NULL &&        !(pclass->type & CUPS_PRINTER_REMOTE))    {     /*      * Yes, return an error...      */      send_ipp_error(con, IPP_NOT_POSSIBLE);      return;    }   /*    * No, add the pclass...    */    pclass = AddClass(resource + 9);    modify = 0;  }  else if (pclass->type & CUPS_PRINTER_IMPLICIT)  {   /*    * Rename the implicit class to "AnyClass" or remove it...    */    if (ImplicitAnyClasses)    {      SetStringf(&pclass->name, "Any%s", resource + 9);      SortPrinters();    }    else      DeletePrinter(pclass, 1);   /*    * Add the class as a new local class...    */    pclass = AddClass(resource + 9);    modify = 0;  }  else if (pclass->type & CUPS_PRINTER_REMOTE)  {   /*    * Rename the remote class to "Class"...    */    DeletePrinterFilters(pclass);    SetStringf(&pclass->name, "%s@%s", resource + 9, pclass->hostname);    SetPrinterAttrs(pclass);    SortPrinters();   /*    * Add the class as a new local class...    */    pclass = AddClass(resource + 9);    modify = 0;  }  else    modify = 1; /*  * Look for attributes and copy them over as needed...  */  if ((attr = ippFindAttribute(con->request, "printer-location", IPP_TAG_TEXT)) != NULL)    SetString(&pclass->location, attr->values[0].string.text);  if ((attr = ippFindAttribute(con->request, "printer-info", IPP_TAG_TEXT)) != NULL)    SetString(&pclass->info, attr->values[0].string.text);  if ((attr = ippFindAttribute(con->request, "printer-is-accepting-jobs", IPP_TAG_BOOLEAN)) != NULL)  {    LogMessage(L_INFO, "Setting %s printer-is-accepting-jobs to %d (was %d.)",               pclass->name, attr->values[0].boolean, pclass->accepting);    pclass->accepting = attr->values[0].boolean;    AddPrinterHistory(pclass);  }  if ((attr = ippFindAttribute(con->request, "printer-state", IPP_TAG_ENUM)) != NULL)  {    if (attr->values[0].integer != IPP_PRINTER_IDLE &&        attr->values[0].integer == IPP_PRINTER_STOPPED)    {      LogMessage(L_ERROR, "Attempt to set %s printer-state to bad value %d!",                 pclass->name, attr->values[0].integer);      send_ipp_error(con, IPP_BAD_REQUEST);      return;    }    LogMessage(L_INFO, "Setting %s printer-state to %d (was %d.)", pclass->name,               attr->values[0].integer, pclass->state);    SetPrinterState(pclass, (ipp_pstate_t)(attr->values[0].integer), 0);  }  if ((attr = ippFindAttribute(con->request, "printer-state-message", IPP_TAG_TEXT)) != NULL)  {    strlcpy(pclass->state_message, attr->values[0].string.text,            sizeof(pclass->state_message));    AddPrinterHistory(pclass);  }  if ((attr = ippFindAttribute(con->request, "job-sheets-default", IPP_TAG_ZERO)) != NULL &&      !Classification)  {    SetString(&pclass->job_sheets[0], attr->values[0].string.text);    if (attr->num_values > 1)      SetString(&pclass->job_sheets[1], attr->values[1].string.text);    else      SetString(&pclass->job_sheets[1], "none");  }  if ((attr = ippFindAttribute(con->request, "requesting-user-name-allowed",                               IPP_TAG_ZERO)) != NULL)  {    FreePrinterUsers(pclass);    pclass->deny_users = 0;    if (attr->value_tag == IPP_TAG_NAME &&        (attr->num_values > 1 ||	 strcmp(attr->values[0].string.text, "all") != 0))      for (i = 0; i < attr->num_values; i ++)	AddPrinterUser(pclass, attr->values[i].string.text);  }  else if ((attr = ippFindAttribute(con->request, "requesting-user-name-denied",                                    IPP_TAG_ZERO)) != NULL)  {    FreePrinterUsers(pclass);    pclass->deny_users = 1;    if (attr->value_tag == IPP_TAG_NAME &&        (attr->num_values > 1 ||	 strcmp(attr->values[0].string.text, "none") != 0))      for (i = 0; i < attr->num_values; i ++)	AddPrinterUser(pclass, attr->values[i].string.text);  }  if ((attr = ippFindAttribute(con->request, "job-quota-period",                               IPP_TAG_INTEGER)) != NULL)  {    LogMessage(L_DEBUG, "add_class: Setting job-quota-period to %d...",               attr->values[0].integer);    FreeQuotas(pclass);    pclass->quota_period = attr->values[0].integer;  }  if ((attr = ippFindAttribute(con->request, "job-k-limit",                               IPP_TAG_INTEGER)) != NULL)  {    LogMessage(L_DEBUG, "add_class: Setting job-k-limit to %d...",               attr->values[0].integer);    FreeQuotas(pclass);    pclass->k_limit = attr->values[0].integer;  }  if ((attr = ippFindAttribute(con->request, "job-page-limit",                               IPP_TAG_INTEGER)) != NULL)  {    LogMessage(L_DEBUG, "add_class: Setting job-page-limit to %d...",               attr->values[0].integer);    FreeQuotas(pclass);    pclass->page_limit = attr->values[0].integer;  }  if ((attr = ippFindAttribute(con->request, "member-uris", IPP_TAG_URI)) != NULL)  {   /*    * Clear the printer array as needed...    */    if (pclass->num_printers > 0)    {      free(pclass->printers);      pclass->num_printers = 0;    }   /*    * Add each printer or class that is listed...    */    for (i = 0; i < attr->num_values; i ++)    {     /*      * Search for the printer or class URI...      */      httpSeparate(attr->values[i].string.text, method, username, host,                   &port, resource);      if ((dest = ValidateDest(host, resource, &dtype)) == NULL)      {       /*	* Bad URI...	*/        LogMessage(L_ERROR, "add_class: resource name \'%s\' no good!", resource);	send_ipp_error(con, IPP_NOT_FOUND);	return;      }     /*      * Add it to the class...      */      if (dtype & CUPS_PRINTER_CLASS)      {        AddPrinterToClass(pclass, FindClass(dest));	LogMessage(L_DEBUG, "add_class: Added class \"%s\" to class \"%s\"...",	           dest, pclass->name);      }      else      {        AddPrinterToClass(pclass, FindPrinter(dest));	LogMessage(L_DEBUG, "add_class: Added printer \"%s\" to class \"%s\"...",	           dest, pclass->name);      }    }  } /*  * Update the printer class attributes and return...  */  SetPrinterAttrs(pclass);  SaveAllClasses();  CheckJobs();  WritePrintcap();  if (modify)    LogMessage(L_INFO, "Class \'%s\' modified by \'%s\'.", pclass->name,               con->username);  else  {    AddPrinterHistory(pclass);    LogMessage(L_INFO, "New class \'%s\' added by \'%s\'.", pclass->name,               con->username);  }  con->response->request.status.status_code = IPP_OK;}/* * 'add_file()' - Add a file to a job. */static int				/* O - 0 on success, -1 on error */add_file(client_t    *con,		/* I - Connection to client */         job_t       *job,		/* I - Job to add to */         mime_type_t *filetype,		/* I - Type of file */	 int         compression)	/* I - Compression */{  mime_type_t	**filetypes;		/* New filetypes array... */  int		*compressions;		/* New compressions array... */  LogMessage(L_DEBUG2, "add_file(con=%p[%d], job=%d, filetype=%s/%s, compression=%d)\n",             con, con->http.fd, job->id, filetype->super, filetype->type,	     compression); /*  * Add the file to the job...  */  if (job->num_files == 0)  {    compressions = (int *)malloc(sizeof(int));    filetypes    = (mime_type_t **)malloc(sizeof(mime_type_t *));  }  else  {    compressions = (int *)realloc(job->compressions,                                  (job->num_files + 1) * sizeof(int));    filetypes    = (mime_type_t **)realloc(job->filetypes,                                           (job->num_files + 1) *					   sizeof(mime_type_t *));  }  if (compressions == NULL || filetypes == NULL)  {    CancelJob(job->id, 1);    LogMessage(L_ERROR, "add_file: unable to allocate memory for file types!");    send_ipp_error(con, IPP_INTERNAL_ERROR);    return (-1);  }  job->compressions                 = compressions;  job->compressions[job->num_files] = compression;  job->filetypes                    = filetypes;  job->filetypes[job->num_files]    = filetype;  job->num_files ++;  return (0);}#endif/* * 'add_job_state_reasons()' - Add the "job-state-reasons" attribute based *                             upon the job and printer state...

⌨️ 快捷键说明

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