-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathairscan-ipp.c
178 lines (143 loc) · 3.69 KB
/
airscan-ipp.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/* AirScan (a.k.a. IPP) backend for SANE
*
* Copyright (C) 2019 and up by Rishabh Arya ([email protected])
* See LICENSE for license terms and conditions
*
* IPP protocol handler
*/
#define NO_HTTP_STATUS
#include "airscan.h"
#include <cups/cups.h>
/* proto_handler_ipp represents IPP protocol handler
*/
typedef struct {
proto_handler proto; /* Base class */
} proto_handler_ipp;
/* Create HTTP POST request
*/
static http_query*
ipp_http_post (const proto_ctx *ctx, void *body, size_t size)
{
http_query *q;
q = http_query_new_len(ctx->http, http_uri_clone(ctx->base_uri),
"POST", body, size, "application/ipp");
return q;
}
/* Query device capabilities
*/
static http_query*
ipp_devcaps_query (const proto_ctx *ctx)
{
return ipp_http_post(ctx, NULL, 0);
}
/* Decode device capabilities
*/
static error
ipp_devcaps_decode (const proto_ctx *ctx, devcaps *caps)
{
(void) ctx;
(void) caps;
return ERROR("not supported");
}
/* Initiate scanning
*/
static http_query*
ipp_scan_query (const proto_ctx *ctx)
{
return ipp_http_post(ctx, NULL, 0);
}
/* Decode result of scan request
*/
static proto_result
ipp_scan_decode (const proto_ctx *ctx)
{
proto_result result = {0};
(void) ctx;
result.next = PROTO_OP_FINISH;
result.status = SANE_STATUS_UNSUPPORTED;
result.err = ERROR("not supported");
return result;
}
/* Initiate image downloading
*/
static http_query*
ipp_load_query (const proto_ctx *ctx)
{
return ipp_http_post(ctx, NULL, 0);
}
/* Decode result of image request
*/
static proto_result
ipp_load_decode (const proto_ctx *ctx)
{
proto_result result = {0};
(void) ctx;
result.next = PROTO_OP_FINISH;
result.status = SANE_STATUS_UNSUPPORTED;
result.err = ERROR("not supported");
return result;
}
/* Request device status
*/
static http_query*
ipp_status_query (const proto_ctx *ctx)
{
return ipp_http_post(ctx, NULL, 0);
}
/* Decode result of device status request
*/
static proto_result
ipp_status_decode (const proto_ctx *ctx)
{
proto_result result = {0};
(void) ctx;
result.next = PROTO_OP_FINISH;
result.status = SANE_STATUS_UNSUPPORTED;
result.err = ERROR("not supported");
return result;
}
/* Cancel scan in progress
*/
static http_query*
ipp_cancel_query (const proto_ctx *ctx)
{
return ipp_http_post(ctx, NULL, 0);
}
/* Free IPP protocol handler
*/
static void
ipp_free (proto_handler *proto)
{
mem_free(proto);
}
/* proto_handler_ipp_new creates new IPP protocol handler
*/
proto_handler*
proto_handler_ipp_new (void)
{
proto_handler_ipp *ipp = mem_new(proto_handler_ipp, 1);
ipp->proto.name = "IPP";
ipp->proto.free = ipp_free;
/*1*/ipp->proto.devcaps_query = ipp_devcaps_query;
/*1*/ipp->proto.devcaps_decode = ipp_devcaps_decode;
/*2*/ipp->proto.scan_query = ipp_scan_query;
/*2*/ipp->proto.scan_decode = ipp_scan_decode;
/*3*/ipp->proto.load_query = ipp_load_query;
/*3*/ipp->proto.load_decode = ipp_load_decode;
/*4*/ipp->proto.status_query = ipp_status_query;
/*4*/ipp->proto.status_decode = ipp_status_decode;
/*5*/ipp->proto.cleanup_query = ipp_cancel_query;
/*6*/ipp->proto.cancel_query = ipp_cancel_query;
return &ipp->proto;
}
/*
JUST FOR UNDERSTANDING TEMP
1 -> Query/decode scanner capabilities (devcaps_query/devcaps_decode)
2 -> Initiate scanning (create scan job) and decode result (scan_query/scan_decode)
3 -> Initiate downloading of scanned image and decode result
4 -> Get device status and decode result (status_query/status_decode)
5 -> Cleanup after scan job (cleanup_query, there is no decode operation)
6 -> Cancel scan job (cancel_query, and also no decode operation)
*/
/* vim:ts=8:sw=4:et
*/