Printing job management

sumit sumit.surwase at patni.com
Wed Jun 15 06:45:34 PDT 2011


Hi ,Guys
I am developing one program to manage printing job through CUPS.Please find following source code for it.
[code]
static void	do_job_op(http_t *http, int job_id, ipp_op_t op);


/*
 * 'main()' - Main entry for CGI.
 */

int					/* O - Exit status */
main(int  argc,				/* I - Number of command-line arguments */
     char *argv[])			/* I - Command-line arguments */
{
  http_t	*http;			/* Connection to the server */
  const char	*op;			/* Operation name */
  //const char	*job_id_var;		/* Job ID form variable */
  int		job_id;			/* Job ID */



  http = httpConnectEncrypt(cupsServer(), ippPort(), cupsEncryption());

 /*
  * Get the job ID, if any...
  */

    if(argc >= 2)
		{
        job_id = atoi(argv[2]);
    }else{
       job_id = 0;
    }

    op = argv[1];


 /*
  * Do the operation...
  */

  if (op != NULL && job_id > 0)
  {
   /*
    * Do the operation...
    */

    if (!strcmp(op, "cancel-job"))
      do_job_op(http, job_id, IPP_CANCEL_JOB);
    else if (!strcmp(op, "hold-job"))
      {
		do_job_op(http, job_id, IPP_HOLD_JOB);
	  }
    else if (!strcmp(op, "release-job"))
      do_job_op(http, job_id, IPP_RELEASE_JOB);
    else if (!strcmp(op, "restart-job"))
      do_job_op(http, job_id,IPP_RESTART_JOB);
    else
    {
     /*
      * Bad operation code...  Display an error...
      */
      printf("\n\t\tBad operation\n");

    }
  }
  else
  {
   /*
    * Show a list of jobs...
    */
     printf("\n\t\tSpecify Correct operation or job id\n");

  }

 /*
  * Close the HTTP server connection...
  */

  httpClose(http);

 /*
  * Return with no errors...
  */

  return (0);
}


/*
 * 'do_job_op()' - Do a job operation.
 */

static void
do_job_op(http_t      *http,		/* I - HTTP connection */
          int         job_id,		/* I - Job ID */
	  ipp_op_t    op)		/* I - Operation to perform */
{
  ipp_t		*request;		/* IPP request */
  char		uri[HTTP_MAX_URI];	/* Job URI */
  //const char	*user;			/* Username */


 /*
  * Build a job request, which requires the following
  * attributes:
  *
  *    attributes-charset
  *    attributes-natural-language
  *    job-uri or printer-uri (purge-jobs)
  *    requesting-user-name
  */

  request = ippNewRequest(op);

  snprintf(uri, sizeof(uri), "ipp://localhost/jobs/%d", job_id);

  ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri",
               NULL, uri);

  ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
               "requesting-user-name", NULL, cupsUser());

 /*
  * Do the request and get back a response...
  */

  ippDelete(cupsDoRequest(http, request, "/jobs"));

  if (cupsLastError() <= IPP_OK_CONFLICT && getenv("HTTP_REFERER"))
  {
   /*
    * Redirect successful updates back to the parent page...
    */

    char	url[1024];		/* Encoded URL */
    strcpy(url, "5;URL=");
  }
  else if (cupsLastError() == IPP_NOT_AUTHORIZED)
  {
    puts("Status: 401\n");
    exit(0);
  }


  if (cupsLastError() > IPP_OK_CONFLICT){
printf("lpstat: %s\n", cupsLastErrorString());

printf("Job operation failed:");
}


  else if (op == IPP_CANCEL_JOB)
    printf("job-cancel");
  else if (op == IPP_HOLD_JOB)
    printf("hold-printer");
  else if (op == IPP_RELEASE_JOB)
    printf("job-release");
  else if (op == IPP_RESUBMIT_JOB)
    printf("job-restart");
}
[/code]
when you run this code, you have to give two parameter first operation to be performed eg.hold-job,release-job,cancel-job,restart-job.Second paramter must be job id.
I got a machine from company which is having internal printer ,so first I am printing a file through command line(lp command) and in another session I am running my code for job management.

problem:
1.for cancel & hold job code is working perfectly fine.

2.when i hold a job & release it for resume printing it reprint the job i.e.it restarts printing same job(I am using IPP_RELEASE_JOB request)
so Is there any way to resume document printing?

3.When i hold a job and say restart then it shows me error like (job_id) is not completed.It means that printer is not going to accept any further operation until current one is finished.

4.Is there any way to get out of this????

Guys I searched CUPS docs but still uncleared how to resolve these issues?

Please help me guys
Regards,
Sumit




More information about the cups mailing list