Ignore:
Timestamp:
Nov 29, 2012, 1:59:04 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: updated trunk to 3.6.9

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/server/source3/printing/print_cups.c

    r745 r751  
    3636#endif
    3737
     38#if (CUPS_VERSION_MAJOR > 1) || (CUPS_VERSION_MINOR > 5)
     39#define HAVE_CUPS_1_6 1
     40#endif
     41
     42#ifndef HAVE_CUPS_1_6
     43#define ippGetGroupTag(attr)  attr->group_tag
     44#define ippGetName(attr)      attr->name
     45#define ippGetValueTag(attr)  attr->value_tag
     46#define ippGetStatusCode(ipp) ipp->request.status.status_code
     47#define ippGetInteger(attr, element) attr->values[element].integer
     48#define ippGetString(attr, element, language) attr->values[element].string.text
     49
     50static ipp_attribute_t *
     51ippFirstAttribute(ipp_t *ipp)
     52{
     53  if (!ipp)
     54    return (NULL);
     55  return (ipp->current = ipp->attrs);
     56}
     57
     58static ipp_attribute_t *
     59ippNextAttribute(ipp_t *ipp)
     60{
     61  if (!ipp || !ipp->current)
     62    return (NULL);
     63  return (ipp->current = ipp->current->next);
     64}
     65
     66static int ippSetOperation(ipp_t *ipp, ipp_op_t op)
     67{
     68    ipp->request.op.operation_id = op;
     69    return (1);
     70}
     71
     72static int ippSetRequestId(ipp_t *ipp, int request_id)
     73{
     74    ipp->request.any.request_id = request_id;
     75    return (1);
     76}
     77#endif
     78
    3879static SIG_ATOMIC_T gotalarm;
    3980
     
    172213        bool ret_ok = false;
    173214
    174         for (attr = response->attrs; attr != NULL;) {
     215        for (attr = ippFirstAttribute(response); attr != NULL;) {
    175216               /*
    176217                * Skip leading attributes until we hit a printer...
    177218                */
    178219
    179                 while (attr != NULL && attr->group_tag != IPP_TAG_PRINTER)
    180                         attr = attr->next;
     220                while (attr != NULL && ippGetGroupTag(attr) != IPP_TAG_PRINTER)
     221                        attr = ippNextAttribute(response);
    181222
    182223                if (attr == NULL)
     
    190231                info       = NULL;
    191232
    192                 while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER) {
     233                while (attr != NULL && ippGetGroupTag(attr) == IPP_TAG_PRINTER) {
    193234                        size_t size;
    194                         if (strcmp(attr->name, "printer-name") == 0 &&
    195                             attr->value_tag == IPP_TAG_NAME) {
     235                        if (strcmp(ippGetName(attr), "printer-name") == 0 &&
     236                            ippGetValueTag(attr) == IPP_TAG_NAME) {
    196237                                if (!pull_utf8_talloc(mem_ctx,
    197238                                                &name,
    198                                                 attr->values[0].string.text,
     239                                                ippGetString(attr, 0, NULL),
    199240                                                &size)) {
    200241                                        goto err_out;
     
    202243                        }
    203244
    204                         if (strcmp(attr->name, "printer-info") == 0 &&
    205                             attr->value_tag == IPP_TAG_TEXT) {
     245                        if (strcmp(ippGetName(attr), "printer-info") == 0 &&
     246                            ippGetValueTag(attr) == IPP_TAG_TEXT) {
    206247                                if (!pull_utf8_talloc(mem_ctx,
    207248                                                &info,
    208                                                 attr->values[0].string.text,
     249                                                ippGetString(attr, 0, NULL),
    209250                                                &size)) {
    210251                                        goto err_out;
     
    212253                        }
    213254
    214                         if (strcmp(attr->name, "printer-location") == 0 &&
    215                             attr->value_tag == IPP_TAG_TEXT) {
     255                        if (strcmp(ippGetName(attr), "printer-location") == 0 &&
     256                            ippGetValueTag(attr) == IPP_TAG_TEXT) {
    216257                                if (!pull_utf8_talloc(mem_ctx,
    217258                                                &location,
    218                                                 attr->values[0].string.text,
     259                                                ippGetString(attr, 0, NULL),
    219260                                                &size)) {
    220261                                        goto err_out;
     
    222263                        }
    223264
    224                         attr = attr->next;
     265                        attr = ippNextAttribute(response);
    225266                }
    226267
     
    302343        request = ippNew();
    303344
    304         request->request.op.operation_id = CUPS_GET_PRINTERS;
    305         request->request.op.request_id   = 1;
     345        ippSetOperation(request, CUPS_GET_PRINTERS);
     346        ippSetRequestId(request, 1);
    306347
    307348        language = cupsLangDefault();
     
    344385        request = ippNew();
    345386
    346         request->request.op.operation_id = CUPS_GET_CLASSES;
    347         request->request.op.request_id   = 1;
     387        ippSetOperation(request, CUPS_GET_CLASSES);
     388        ippSetRequestId(request, 1);
    348389
    349390        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
     
    608649        request = ippNew();
    609650
    610         request->request.op.operation_id = IPP_CANCEL_JOB;
    611         request->request.op.request_id   = 1;
     651        ippSetOperation(request, IPP_CANCEL_JOB);
     652        ippSetRequestId(request, 1);
    612653
    613654        language = cupsLangDefault();
     
    635676
    636677        if ((response = cupsDoRequest(http, request, "/jobs")) != NULL) {
    637                 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
     678                if (ippGetStatusCode(response) >= IPP_OK_CONFLICT) {
    638679                        DEBUG(0,("Unable to cancel job %d - %s\n", pjob->sysjob,
    639680                                ippErrorString(cupsLastError())));
     
    705746        request = ippNew();
    706747
    707         request->request.op.operation_id = IPP_HOLD_JOB;
    708         request->request.op.request_id   = 1;
     748        ippSetOperation(request, IPP_HOLD_JOB);
     749        ippSetRequestId(request, 1);
    709750
    710751        language = cupsLangDefault();
     
    731772
    732773        if ((response = cupsDoRequest(http, request, "/jobs")) != NULL) {
    733                 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
     774                if (ippGetStatusCode(response) >= IPP_OK_CONFLICT) {
    734775                        DEBUG(0,("Unable to hold job %d - %s\n", pjob->sysjob,
    735776                                ippErrorString(cupsLastError())));
     
    801842        request = ippNew();
    802843
    803         request->request.op.operation_id = IPP_RELEASE_JOB;
    804         request->request.op.request_id   = 1;
     844        ippSetOperation(request, IPP_RELEASE_JOB);
     845        ippSetRequestId(request, 1);
    805846
    806847        language = cupsLangDefault();
     
    827868
    828869        if ((response = cupsDoRequest(http, request, "/jobs")) != NULL) {
    829                 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
     870                if (ippGetStatusCode(response) >= IPP_OK_CONFLICT) {
    830871                        DEBUG(0,("Unable to release job %d - %s\n", pjob->sysjob,
    831872                                ippErrorString(cupsLastError())));
     
    857898 */
    858899
    859 static int cups_job_submit(int snum, struct printjob *pjob)
     900static int cups_job_submit(int snum, struct printjob *pjob,
     901                           enum printing_types printing_type,
     902                           char *lpq_cmd)
    860903{
    861904        TALLOC_CTX *frame = talloc_stackframe();
     
    876919        char *filename = NULL;
    877920        size_t size;
    878         uint32_t jobid = (uint32_t)-1;
    879921
    880922        DEBUG(5,("cups_job_submit(%d, %p)\n", snum, pjob));
     
    907949        request = ippNew();
    908950
    909         request->request.op.operation_id = IPP_PRINT_JOB;
    910         request->request.op.request_id   = 1;
     951        ippSetOperation(request, IPP_PRINT_JOB);
     952        ippSetRequestId(request, 1);
    911953
    912954        language = cupsLangDefault();
     
    938980                     pjob->clientmachine);
    939981
    940         /* Get the jobid from the filename. */
    941         jobid = print_parse_jobid(pjob->filename);
    942         if (jobid == (uint32_t)-1) {
    943                 DEBUG(0,("cups_job_submit: failed to parse jobid from name %s\n",
    944                                 pjob->filename ));
    945                 jobid = 0;
    946         }
    947 
    948982        if (!push_utf8_talloc(frame, &jobname, pjob->jobname, &size)) {
    949983                goto out;
     
    951985        new_jobname = talloc_asprintf(frame,
    952986                        "%s%.8u %s", PRINT_SPOOL_PREFIX,
    953                         (unsigned int)jobid,
    954                         jobname);
     987                        pjob->jobid, jobname);
    955988        if (new_jobname == NULL) {
    956989                goto out;
     
    9841017        }
    9851018        if ((response = cupsDoFileRequest(http, request, uri, pjob->filename)) != NULL) {
    986                 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
     1019                if (ippGetStatusCode(response) >= IPP_OK_CONFLICT) {
    9871020                        DEBUG(0,("Unable to print file to %s - %s\n",
    9881021                                 lp_printername(snum),
     
    9921025                        attr_job_id = ippFindAttribute(response, "job-id", IPP_TAG_INTEGER);
    9931026                        if(attr_job_id) {
    994                                 pjob->sysjob = attr_job_id->values[0].integer;
     1027                                pjob->sysjob = ippGetInteger(attr_job_id, 0);
    9951028                                DEBUG(5,("cups_job_submit: job-id %d\n", pjob->sysjob));
    9961029                        } else {
     
    11141147        request = ippNew();
    11151148
    1116         request->request.op.operation_id = IPP_GET_JOBS;
    1117         request->request.op.request_id   = 1;
     1149        ippSetOperation(request, IPP_GET_JOBS);
     1150        ippSetRequestId(request, 1);
    11181151
    11191152        language = cupsLangDefault();
     
    11431176        }
    11441177
    1145         if (response->request.status.status_code >= IPP_OK_CONFLICT) {
     1178        if (ippGetStatusCode(response) >= IPP_OK_CONFLICT) {
    11461179                DEBUG(0,("Unable to get jobs for %s - %s\n", uri,
    1147                          ippErrorString(response->request.status.status_code)));
     1180                         ippErrorString(ippGetStatusCode(response))));
    11481181                goto out;
    11491182        }
     
    11571190        queue  = NULL;
    11581191
    1159         for (attr = response->attrs; attr != NULL; attr = attr->next) {
     1192        for (attr = ippFirstAttribute(response); attr != NULL; attr = ippNextAttribute(response)) {
    11601193               /*
    11611194                * Skip leading attributes until we hit a job...
    11621195                */
    11631196
    1164                 while (attr != NULL && attr->group_tag != IPP_TAG_JOB)
    1165                         attr = attr->next;
     1197                while (attr != NULL && ippGetGroupTag(attr) != IPP_TAG_JOB)
     1198                        attr = ippNextAttribute(response);
    11661199
    11671200                if (attr == NULL)
     
    11981231                job_name     = NULL;
    11991232
    1200                 while (attr != NULL && attr->group_tag == IPP_TAG_JOB) {
    1201                         if (attr->name == NULL) {
    1202                                 attr = attr->next;
     1233                while (attr != NULL && ippGetGroupTag(attr) == IPP_TAG_JOB) {
     1234                        if (ippGetName(attr) == NULL) {
     1235                                attr = ippNextAttribute(response);
    12031236                                break;
    12041237                        }
    12051238
    1206                         if (strcmp(attr->name, "job-id") == 0 &&
    1207                             attr->value_tag == IPP_TAG_INTEGER)
    1208                                 job_id = attr->values[0].integer;
    1209 
    1210                         if (strcmp(attr->name, "job-k-octets") == 0 &&
    1211                             attr->value_tag == IPP_TAG_INTEGER)
    1212                                 job_k_octets = attr->values[0].integer;
    1213 
    1214                         if (strcmp(attr->name, "job-priority") == 0 &&
    1215                             attr->value_tag == IPP_TAG_INTEGER)
    1216                                 job_priority = attr->values[0].integer;
    1217 
    1218                         if (strcmp(attr->name, "job-state") == 0 &&
    1219                             attr->value_tag == IPP_TAG_ENUM)
    1220                                 job_status = (ipp_jstate_t)(attr->values[0].integer);
    1221 
    1222                         if (strcmp(attr->name, "time-at-creation") == 0 &&
    1223                             attr->value_tag == IPP_TAG_INTEGER)
    1224                                 job_time = attr->values[0].integer;
    1225 
    1226                         if (strcmp(attr->name, "job-name") == 0 &&
    1227                             attr->value_tag == IPP_TAG_NAME) {
     1239                        if (strcmp(ippGetName(attr), "job-id") == 0 &&
     1240                            ippGetValueTag(attr) == IPP_TAG_INTEGER)
     1241                                job_id = ippGetInteger(attr, 0);
     1242
     1243                        if (strcmp(ippGetName(attr), "job-k-octets") == 0 &&
     1244                            ippGetValueTag(attr) == IPP_TAG_INTEGER)
     1245                                job_k_octets = ippGetInteger(attr, 0);
     1246
     1247                        if (strcmp(ippGetName(attr), "job-priority") == 0 &&
     1248                            ippGetValueTag(attr) == IPP_TAG_INTEGER)
     1249                                job_priority = ippGetInteger(attr, 0);
     1250
     1251                        if (strcmp(ippGetName(attr), "job-state") == 0 &&
     1252                            ippGetValueTag(attr) == IPP_TAG_ENUM)
     1253                                job_status = (ipp_jstate_t)ippGetInteger(attr, 0);
     1254
     1255                        if (strcmp(ippGetName(attr), "time-at-creation") == 0 &&
     1256                            ippGetValueTag(attr) == IPP_TAG_INTEGER)
     1257                                job_time = ippGetInteger(attr, 0);
     1258
     1259                        if (strcmp(ippGetName(attr), "job-name") == 0 &&
     1260                            ippGetValueTag(attr) == IPP_TAG_NAME) {
    12281261                                if (!pull_utf8_talloc(frame,
    12291262                                                &job_name,
    1230                                                 attr->values[0].string.text,
     1263                                                ippGetString(attr, 0, NULL),
    12311264                                                &size)) {
    12321265                                        goto out;
     
    12341267                        }
    12351268
    1236                         if (strcmp(attr->name, "job-originating-user-name") == 0 &&
    1237                             attr->value_tag == IPP_TAG_NAME) {
     1269                        if (strcmp(ippGetName(attr), "job-originating-user-name") == 0 &&
     1270                            ippGetValueTag(attr) == IPP_TAG_NAME) {
    12381271                                if (!pull_utf8_talloc(frame,
    12391272                                                &user_name,
    1240                                                 attr->values[0].string.text,
     1273                                                ippGetString(attr, 0, NULL),
    12411274                                                &size)) {
    12421275                                        goto out;
     
    12441277                        }
    12451278
    1246                         attr = attr->next;
     1279                        attr = ippNextAttribute(response);
    12471280                }
    12481281
     
    12581291                }
    12591292
    1260                 temp->job      = job_id;
     1293                temp->sysjob   = job_id;
    12611294                temp->size     = job_k_octets * 1024;
    12621295                temp->status   = job_status == IPP_JOB_PENDING ? LPQ_QUEUED :
     
    12901323        request = ippNew();
    12911324
    1292         request->request.op.operation_id = IPP_GET_PRINTER_ATTRIBUTES;
    1293         request->request.op.request_id   = 1;
     1325        ippSetOperation(request, IPP_GET_PRINTER_ATTRIBUTES);
     1326        ippSetRequestId(request, 1);
    12941327
    12951328        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
     
    13171350        }
    13181351
    1319         if (response->request.status.status_code >= IPP_OK_CONFLICT) {
     1352        if (ippGetStatusCode(response) >= IPP_OK_CONFLICT) {
    13201353                DEBUG(0,("Unable to get printer status for %s - %s\n", printername,
    1321                          ippErrorString(response->request.status.status_code)));
     1354                         ippErrorString(ippGetStatusCode(response))));
    13221355                goto out;
    13231356        }
     
    13281361
    13291362        if ((attr = ippFindAttribute(response, "printer-state", IPP_TAG_ENUM)) != NULL) {
    1330                 if (attr->values[0].integer == IPP_PRINTER_STOPPED)
     1363                if (ippGetInteger(attr, 0) == IPP_PRINTER_STOPPED)
    13311364                        status->status = LPSTAT_STOPPED;
    13321365                else
     
    13381371                char *msg = NULL;
    13391372                if (!pull_utf8_talloc(frame, &msg,
    1340                                 attr->values[0].string.text,
     1373                                ippGetString(attr, 0, NULL),
    13411374                                &size)) {
    13421375                        SAFE_FREE(queue);
     
    14141447        request = ippNew();
    14151448
    1416         request->request.op.operation_id = IPP_PAUSE_PRINTER;
    1417         request->request.op.request_id   = 1;
     1449        ippSetOperation(request, IPP_PAUSE_PRINTER);
     1450        ippSetRequestId(request, 1);
    14181451
    14191452        language = cupsLangDefault();
     
    14451478
    14461479        if ((response = cupsDoRequest(http, request, "/admin/")) != NULL) {
    1447                 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
     1480                if (ippGetStatusCode(response) >= IPP_OK_CONFLICT) {
    14481481                        DEBUG(0,("Unable to pause printer %s - %s\n",
    14491482                                 lp_printername(snum),
     
    15181551        request = ippNew();
    15191552
    1520         request->request.op.operation_id = IPP_RESUME_PRINTER;
    1521         request->request.op.request_id   = 1;
     1553        ippSetOperation(request, IPP_RESUME_PRINTER);
     1554        ippSetRequestId(request, 1);
    15221555
    15231556        language = cupsLangDefault();
     
    15491582
    15501583        if ((response = cupsDoRequest(http, request, "/admin/")) != NULL) {
    1551                 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
     1584                if (ippGetStatusCode(response) >= IPP_OK_CONFLICT) {
    15521585                        DEBUG(0,("Unable to resume printer %s - %s\n",
    15531586                                 lp_printername(snum),
Note: See TracChangeset for help on using the changeset viewer.