LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Printing jobs management (https://www.linuxquestions.org/questions/programming-9/printing-jobs-management-886489/)

surwassu 06-15-2011 08:34 AM

Printing jobs management
 
Hi ,Guys
I am developing one program to manage printing job through CUPS.Please find following source code for it.
Code:

#include <cups/cups.h>
#include<cups/http.h>



/*
 * Local functions...
 */

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");
}

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

TB0ne 06-15-2011 10:42 AM

Quote:

Originally Posted by surwassu (Post 4386400)
Hi ,Guys
I am developing one program to manage printing job through CUPS.Please find following source code for it.

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?

Without seeing detailed debug logs, the best thing we could suggest is to go to the CUPS site, and check out the developers forum, and read about the capabilities of the API.

And this seems very much like you're re-inventing the wheel....why not just use the default CUPS webpage, and click on the JOBS tab at the top, or the PRINTERS tab next to it? Already has hold/move/cancel/resume functions...

Tinkster 06-15-2011 11:38 AM

Moved: This thread is more suitable in <PROGRAMMING> and has been moved accordingly to help your thread/question get the exposure it deserves.


And I second the suggestion to ask at the CUPS forums on their website;
this is a rather specific topic.

surwassu 06-17-2011 03:09 AM

Quote:

Originally Posted by TB0ne (Post 4386564)
And this seems very much like you're re-inventing the wheel....why not just use the default CUPS webpage, and click on the JOBS tab at the top, or the PRINTERS tab next to it? Already has hold/move/cancel/resume functions...

Hi buddy ,
Thanks for reply.
I have gone through CUPS documentation.I have never find such CUPS Webpages having JOBS or PRINTERS tab?..Can you please give me link.I am using www.cups.org for documentation.
Regards,
Sumit

TB0ne 06-17-2011 09:43 AM

Quote:

Originally Posted by surwassu (Post 4388275)
Hi buddy ,
Thanks for reply.
I have gone through CUPS documentation.I have never find such CUPS Webpages having JOBS or PRINTERS tab?..Can you please give me link.

You say you've installed CUPS, and have read the docs on CUPS.org...yet you haven't seen the web page that gets installed as part of CUPS??. http://localhost:631. Very well documented
Quote:

I am using www.cups.org for documentation.
Great...then read it and you should find the answers.


All times are GMT -5. The time now is 02:18 AM.