Skip to content

Commit d4aedf5

Browse files
committed
Refactor _ipp_request_t to avoid issues on embedded platforms with newer C
compilers (Issue #141)
1 parent efab81c commit d4aedf5

File tree

5 files changed

+49
-71
lines changed

5 files changed

+49
-71
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Changes in libcups
44
v3.0.1 - YYYY-MM-DD
55
-------------------
66

7+
- Updated the internal implementation of `ipp_t` to avoid issues on some
8+
embedded platforms (Issue #141)
79
- Fixed a bug when then `ippFindXxx` and `ippSetXxx` functions were mixed
810
(Issue #138)
911

cups/ipp-private.h

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// Private IPP definitions for CUPS.
33
//
4-
// Copyright © 2021-2023 by OpenPrinting.
4+
// Copyright © 2021-2026 by OpenPrinting.
55
// Copyright © 2007-2018 by Apple Inc.
66
// Copyright © 1997-2006 by Easy Software Products.
77
//
@@ -30,35 +30,11 @@ extern "C" {
3030
// Structures...
3131
//
3232

33-
typedef union _ipp_request_u // Request Header
33+
typedef struct _ipp_request_s // Message Header
3434
{
35-
struct // Any Header
36-
{
37-
ipp_uchar_t version[2]; // Protocol version number
38-
int op_status; // Operation ID or status code
39-
int request_id; // Request ID
40-
} any;
41-
42-
struct // Operation Header
43-
{
44-
ipp_uchar_t version[2]; // Protocol version number
45-
ipp_op_t operation_id; // Operation ID
46-
int request_id; // Request ID
47-
} op;
48-
49-
struct // Status Header
50-
{
51-
ipp_uchar_t version[2]; // Protocol version number
52-
ipp_status_t status_code; // Status code
53-
int request_id; // Request ID
54-
} status;
55-
56-
struct // Event Header
57-
{
58-
ipp_uchar_t version[2]; // Protocol version number
59-
ipp_status_t status_code; // Status code
60-
int request_id; // Request ID
61-
} event;
35+
ipp_uchar_t version[2]; // Protocol version number
36+
short op_status; // Operation ID or status code
37+
int request_id; // Request ID
6238
} _ipp_request_t;
6339

6440
typedef union _ipp_value_u // Attribute Value

cups/ipp.c

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2180,7 +2180,7 @@ ippGetOperation(ipp_t *ipp) // I - IPP request message
21802180
return ((ipp_op_t)0);
21812181

21822182
// Return the value...
2183-
return (ipp->request.op.operation_id);
2183+
return ((ipp_op_t)ipp->request.op_status);
21842184
}
21852185

21862186

@@ -2225,7 +2225,7 @@ ippGetRequestId(ipp_t *ipp) // I - IPP message
22252225
return (0);
22262226

22272227
// Return the request ID...
2228-
return (ipp->request.any.request_id);
2228+
return (ipp->request.request_id);
22292229
}
22302230

22312231

@@ -2294,7 +2294,7 @@ ippGetStatusCode(ipp_t *ipp) // I - IPP response or event message
22942294
return (IPP_STATUS_ERROR_INTERNAL);
22952295

22962296
// Return the value...
2297-
return (ipp->request.status.status_code);
2297+
return ((ipp_status_t)ipp->request.op_status);
22982298
}
22992299

23002300

@@ -2362,9 +2362,9 @@ ippGetVersion(ipp_t *ipp, // I - IPP message
23622362

23632363
// Return the value...
23642364
if (minor)
2365-
*minor = ipp->request.any.version[1];
2365+
*minor = ipp->request.version[1];
23662366

2367-
return (ipp->request.any.version[0]);
2367+
return (ipp->request.version[0]);
23682368
}
23692369

23702370

@@ -2390,10 +2390,10 @@ ippNew(void)
23902390
if (!cg->client_conf_loaded)
23912391
_cupsSetDefaults();
23922392

2393-
temp->request.any.version[0] = (ipp_uchar_t)(cg->server_version / 10);
2394-
temp->request.any.version[1] = (ipp_uchar_t)(cg->server_version % 10);
2395-
temp->use = 1;
2396-
temp->find = temp->fstack;
2393+
temp->request.version[0] = (ipp_uchar_t)(cg->server_version / 10);
2394+
temp->request.version[1] = (ipp_uchar_t)(cg->server_version % 10);
2395+
temp->use = 1;
2396+
temp->find = temp->fstack;
23972397
}
23982398

23992399
DEBUG_printf("1ippNew: Returning %p", (void *)temp);
@@ -2429,8 +2429,8 @@ ippNewRequest(ipp_op_t op) // I - Operation code
24292429
// Set the operation and request ID...
24302430
cupsMutexLock(&request_mutex);
24312431

2432-
request->request.op.operation_id = op;
2433-
request->request.op.request_id = ++request_id;
2432+
request->request.op_status = op;
2433+
request->request.request_id = ++request_id;
24342434

24352435
cupsMutexUnlock(&request_mutex);
24362436

@@ -2474,9 +2474,9 @@ ippNewResponse(ipp_t *request) // I - IPP request message
24742474
return (NULL);
24752475

24762476
// Copy the request values over to the response...
2477-
response->request.status.version[0] = request->request.op.version[0];
2478-
response->request.status.version[1] = request->request.op.version[1];
2479-
response->request.status.request_id = request->request.op.request_id;
2477+
response->request.version[0] = request->request.version[0];
2478+
response->request.version[1] = request->request.version[1];
2479+
response->request.request_id = request->request.request_id;
24802480

24812481
// The first attribute MUST be attributes-charset...
24822482
attr = request->attrs;
@@ -2904,7 +2904,7 @@ ippSetOperation(ipp_t *ipp, // I - IPP request message
29042904
return (false);
29052905

29062906
// Set the operation and return...
2907-
ipp->request.op.operation_id = op;
2907+
ipp->request.op_status = op;
29082908

29092909
return (true);
29102910
}
@@ -2968,7 +2968,7 @@ ippSetRequestId(ipp_t *ipp, // I - IPP message
29682968
return (false);
29692969

29702970
// Set the request ID and return...
2971-
ipp->request.any.request_id = request_id;
2971+
ipp->request.request_id = request_id;
29722972

29732973
return (true);
29742974
}
@@ -3051,7 +3051,7 @@ ippSetStatusCode(ipp_t *ipp, // I - IPP response or event message
30513051
return (false);
30523052

30533053
// Set the status code and return...
3054-
ipp->request.status.status_code = status;
3054+
ipp->request.op_status = status;
30553055

30563056
return (true);
30573057
}
@@ -3472,8 +3472,8 @@ ippSetVersion(ipp_t *ipp, // I - IPP message
34723472
return (false);
34733473

34743474
// Set the version number...
3475-
ipp->request.any.version[0] = (ipp_uchar_t)major;
3476-
ipp->request.any.version[1] = (ipp_uchar_t)minor;
3475+
ipp->request.version[0] = (ipp_uchar_t)major;
3476+
ipp->request.version[1] = (ipp_uchar_t)minor;
34773477

34783478
return (true);
34793479
}
@@ -4132,18 +4132,18 @@ ippWriteIO(void *dst, // I - Destination
41324132
// Total = 8 bytes
41334133
bufptr = buffer;
41344134

4135-
*bufptr++ = ipp->request.any.version[0];
4136-
*bufptr++ = ipp->request.any.version[1];
4137-
*bufptr++ = (ipp_uchar_t)(ipp->request.any.op_status >> 8);
4138-
*bufptr++ = (ipp_uchar_t)ipp->request.any.op_status;
4139-
*bufptr++ = (ipp_uchar_t)(ipp->request.any.request_id >> 24);
4140-
*bufptr++ = (ipp_uchar_t)(ipp->request.any.request_id >> 16);
4141-
*bufptr++ = (ipp_uchar_t)(ipp->request.any.request_id >> 8);
4142-
*bufptr++ = (ipp_uchar_t)ipp->request.any.request_id;
4135+
*bufptr++ = ipp->request.version[0];
4136+
*bufptr++ = ipp->request.version[1];
4137+
*bufptr++ = (ipp_uchar_t)(ipp->request.op_status >> 8);
4138+
*bufptr++ = (ipp_uchar_t)ipp->request.op_status;
4139+
*bufptr++ = (ipp_uchar_t)(ipp->request.request_id >> 24);
4140+
*bufptr++ = (ipp_uchar_t)(ipp->request.request_id >> 16);
4141+
*bufptr++ = (ipp_uchar_t)(ipp->request.request_id >> 8);
4142+
*bufptr++ = (ipp_uchar_t)ipp->request.request_id;
41434143

41444144
DEBUG_printf("2ippWriteIO: version=%d.%d", buffer[0], buffer[1]);
4145-
DEBUG_printf("2ippWriteIO: op_status=%04x", ipp->request.any.op_status);
4146-
DEBUG_printf("2ippWriteIO: request_id=%d", ipp->request.any.request_id);
4145+
DEBUG_printf("2ippWriteIO: op_status=%04x", ipp->request.op_status);
4146+
DEBUG_printf("2ippWriteIO: request_id=%d", ipp->request.request_id);
41474147

41484148
if ((*cb)(dst, buffer, (size_t)(bufptr - buffer)) < 0)
41494149
{
@@ -5305,14 +5305,14 @@ ipp_read_io(void *src, // I - Data source
53055305
}
53065306

53075307
// Then copy the request header over...
5308-
ipp->request.any.version[0] = buffer[0];
5309-
ipp->request.any.version[1] = buffer[1];
5310-
ipp->request.any.op_status = (buffer[2] << 8) | buffer[3];
5311-
ipp->request.any.request_id = (buffer[4] << 24) | (buffer[5] << 16) | (buffer[6] << 8) | buffer[7];
5308+
ipp->request.version[0] = buffer[0];
5309+
ipp->request.version[1] = buffer[1];
5310+
ipp->request.op_status = (buffer[2] << 8) | buffer[3];
5311+
ipp->request.request_id = (buffer[4] << 24) | (buffer[5] << 16) | (buffer[6] << 8) | buffer[7];
53125312

53135313
DEBUG_printf("2ipp_read_io: version=%d.%d", buffer[0], buffer[1]);
5314-
DEBUG_printf("2ipp_read_io: op_status=%04x", ipp->request.any.op_status);
5315-
DEBUG_printf("2ipp_read_io: request_id=%d", ipp->request.any.request_id);
5314+
DEBUG_printf("2ipp_read_io: op_status=%04x", ipp->request.op_status);
5315+
DEBUG_printf("2ipp_read_io: request_id=%d", ipp->request.request_id);
53165316
}
53175317

53185318
ipp->state = IPP_STATE_ATTRIBUTE;

cups/request.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// IPP utilities for CUPS.
33
//
4-
// Copyright © 2021-2025 by OpenPrinting.
4+
// Copyright © 2021-2026 by OpenPrinting.
55
// Copyright © 2007-2018 by Apple Inc.
66
// Copyright © 1997-2007 by Easy Software Products.
77
//
@@ -381,7 +381,7 @@ cupsGetResponse(http_t *http, // I - Connection to server or `CUPS_HTTP_DEFA
381381

382382
DEBUG_printf("1cupsGetResponse: status-code=%s, status-message=\"%s\"", ippErrorString(response->request.status.status_code), attr ? attr->values[0].string.text : "");
383383

384-
_cupsSetError(response->request.status.status_code, attr ? attr->values[0].string.text : ippErrorString(response->request.status.status_code), false);
384+
_cupsSetError((ipp_status_t)response->request.op_status, attr ? attr->values[0].string.text : ippErrorString((ipp_status_t)response->request.op_status), false);
385385
}
386386

387387
return (response);

cups/testipp.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// IPP unit test program for libcups.
33
//
4-
// Copyright © 2021-2025 by OpenPrinting.
4+
// Copyright © 2021-2026 by OpenPrinting.
55
// Copyright © 2007-2019 by Apple Inc.
66
// Copyright © 1997-2005 by Easy Software Products.
77
//
@@ -327,10 +327,10 @@ main(int argc, // I - Number of command-line arguments
327327
testBegin("Create Sample Request");
328328

329329
request = ippNew();
330-
request->request.op.version[0] = 0x01;
331-
request->request.op.version[1] = 0x01;
332-
request->request.op.operation_id = IPP_OP_PRINT_JOB;
333-
request->request.op.request_id = 1;
330+
request->request.version[0] = 0x01;
331+
request->request.version[1] = 0x01;
332+
request->request.op_status = IPP_OP_PRINT_JOB;
333+
request->request.request_id = 1;
334334

335335
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET, "attributes-charset", NULL, "utf-8");
336336
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE, "attributes-natural-language", NULL, "en");

0 commit comments

Comments
 (0)