[cups.general] Need help for modify job-state attribute with an IPP request

Helge Blischke H.Blischke at srz-berlin.de
Wed Sep 1 06:24:32 PDT 2004


Look into the source of e.g. systemv/lp.c how the lp utility does
attribute modifications as a guideline.

Helge


Ludovic Hutin wrote:
> 
> Hello,
> 
> I want to create my own fonction in C with this i can del or change the
> attribut JOB-HOLD-UNTIL attribute to now.
> I can del a job with the cups fonction cupsCancelJob(dest,nbjob);
> but for changing the job state to IPP_JOB_PENDING i try to do a ipp
> request and i receive the answer : "bad request" at each time ...
> if you can help me for the request.
> 
> i must release job by hand in order to print the queue list in
> differents order like cups do.
> Thanks for help
> 
> Here is the source code.
> 
> Ludovic HUTIN
> Université Marc Bloch
> 
> #include <stdio.h>
> #include <stdlib.h>
> #include <string.h>
> #include <cups/cups.h>
> #include <cups/language.h>
> 
> int main(int argc, char * argv[])
> {
>     http_t     *http ; // Connection to server
>     cups_lang_t    *language ;// Langage par defaut
>     char *dest, *user ;
>     int resu, status ;
>     long nbjob ;
> 
>   if ( argc != 5)
>     {
>         printf("Usage : setjob printer user numberjob status\n") ;
>         return (1) ;
>     }
>     dest = argv[1] ;
>     user = argv[2] ;
>     nbjob = atoi(argv[3]) ;
>     status = atoi(argv[4]) ;
> 
>     if (( http =
> httpConnectEncrypt(cupsServer(),ippPort(),cupsEncryption())) == NULL )
>     {
>         fputs("Test : Connection impossible au serveur !\n",stderr);
>         return (1) ;
>     }
> 
>     // On fait une request avec le nom de l'imprimante et le nom du user
> 
>     if ( status == 2 ) // We del the jobs
>     {
>         resu = cupsCancelJob(dest,nbjob);
>         return (1) ;
>     }
>     else if ( status == 1 )
>     {
>         resu = set_jobs(http,dest,user,nbjob) ;
>     }
>     else
>     {
>         printf("Erreur 1") ;
>         return (0) ;
>       }
> }
> 
> int            /* O - Number of jobs in queue */
> set_jobs(http_t     *http,    /* I - HTTP connection to server */
>           const char *dest,    /* I - Destination */
>       const char *user,    /* USER */
>       const long *nbjob)    /* I - Numero du jobs */
> {
>   ipp_t        *request,    /* IPP Request */
>         *response;    /* IPP Response */
>   ipp_attribute_t *attr;    /* Current attribute */
>   cups_lang_t    *language;    /* Default language */
> 
>   if (http == NULL)
>     return (0);
> 
>   request = ippNew();
> 
>   request->request.op.operation_id = IPP_SET_JOB_ATTRIBUTES;
>   request->request.op.request_id   = 1;
> 
>   language = cupsLangDefault();
> 
>   attr = ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
>                       "attributes-charset", NULL,
> cupsLangEncoding(language));
> 
>   attr = ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
>                       "attributes-natural-language", NULL,
> language->language);
> 
>   snprintf(resource, sizeof(resource), "ipp://localhost/printers/%s", dest);
>   ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
> NULL, resource);
> 
>   snprintf(resource, sizeof(resource), "ipp://localhost/jobs/%d", nbjob);
>   ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL,
> resource);
> 
>   ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_JOB,
>                  "requesting-user-name", NULL, user);
>   ippAddBoolean(request, IPP_TAG_OPERATION, "my-jobs", 1);
> 
>   ippAddInteger(request, IPP_TAG_JOB, IPP_TAG_INTEGER,
>                  "job-state", IPP_JOB_PENDING);
> 
> /*
>   * REQUEST -> RESPONSE  */
> 
>  if ((response = cupsDoRequest(http, request, "/")) != NULL)
>   {
>     if (response->request.status.status_code > IPP_OK_CONFLICT)
>     {
>       fprintf(stderr, "releasejob: failed: %s\n",
>               ippErrorString(response->request.status.status_code));
>       ippDelete(response);
>       return (0);
>     }
>   }
>   else
>   {
>     fprintf(stderr, "releasejob: get-jobs failed: %s\n",
> ippErrorString(cupsLastError()));
>     return (0);
>   }
>   return (1) ;
> }

-- 
H.Blischke at srz-berlin.de
H.Blischke at srz-berlin.com
H.Blischke at acm.org




More information about the cups mailing list