159
157
static const char *ce_element[CE_MAX] = { "", "K1", "Gray8", "Color8" }; /* COLOR_ENTRY */
160
158
static const char *is_element[IS_MAX] = { "", "Platen", "Adf", "ADFDuplex" }; /* INPUT_SOURCE */
162
# define POST_HEADER "POST /Scan/Jobs HTTP/1.1\r\nHost: 16.180.119.199:8080\r\nUser-Agent: \
163
hp\r\nAccept: text/plain, */*\r\nAccept-Language: en-us,en;q=0.5\r\n\
164
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\nKeep-Alive: 1000\r\nProxy-Connection: keep-alive\r\n\
160
# define POST_HEADER "POST /Scan/Jobs HTTP/1.1\r\nHost: localhost\r\nUser-Agent: \
161
hplip\r\nAccept: text/plain, */*\r\nAccept-Language: en-us,en\r\n\
162
Accept-Charset: ISO-8859-1,utf-8\r\nKeep-Alive: 1000\r\nProxy-Connection: keep-alive\r\n\
165
163
Content-Type: */*; charset=UTF-8\r\nX-Requested-With: XMLHttpRequest\r\n\
166
Referer: http://16.180.119.199:8080/\r\nContent-Length: 890\r\nCookie: AccessCounter=new\r\n\
164
Content-Length: %d\r\nCookie: AccessCounter=new\r\n\
167
165
Pragma: no-cache\r\nCache-Control: no-cache\r\n\r\n"
169
167
# define GET_SCANNER_ELEMENTS "GET /Scan/ScanCaps HTTP/1.1\r\n\
180
178
Accept-Charset:utf-8\r\n\
181
179
Keep-Alive: 20\r\nProxy-Connection: keep-alive\r\nCookie: AccessCounter=new\r\n0\r\n\r\n"
183
# define CREATE_SCAN_JOB_REQUEST "<scan:ScanJob xmlns:scan=\"http://www.hp.com/schemas/imaging/con/cnx/scan/2008/08/19\" xmlns:dd=\"http://www.hp.com/schemas/imaging/con/dictionaries/1.0/\">\
184
<scan:XResolution>%d</scan:XResolution>\
185
<scan:YResolution>%d</scan:YResolution>\
186
<scan:XStart>%d</scan:XStart>\
187
<scan:YStart>%d</scan:YStart>\
188
<scan:Width>%d</scan:Width>\
189
<scan:Height>%d</scan:Height>\
190
<scan:Format>%s</scan:Format>\
191
<scan:CompressionQFactor>15</scan:CompressionQFactor>\
192
<scan:ColorSpace>%s</scan:ColorSpace>\
193
<scan:BitDepth>%d</scan:BitDepth>\
194
<scan:InputSource>%s</scan:InputSource>\
195
<scan:AdfOptions>SelectSinglePage</scan:AdfOptions>\
196
<scan:GrayRendering>NTSC</scan:GrayRendering>\
198
<scan:Gamma>0</scan:Gamma>\
199
<scan:Brightness>1000</scan:Brightness>\
200
<scan:Contrast>1000</scan:Contrast>\
201
<scan:Highlite>0</scan:Highlite>\
202
<scan:Shadow>0</scan:Shadow></scan:ToneMap>\
203
<scan:ContentType>Photo</scan:ContentType></scan:ScanJob>"
181
# define CREATE_SCAN_JOB_REQUEST "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\
182
<ScanSettings xmlns=\"http://www.hp.com/schemas/imaging/con/cnx/scan/2008/08/19\">\
183
<XResolution>%d</XResolution>\
184
<YResolution>%d</YResolution>\
190
<CompressionQFactor>15</CompressionQFactor>\
191
<ColorSpace>%s</ColorSpace>\
192
<BitDepth>%d</BitDepth>\
193
<InputSource>%s</InputSource>\
194
<InputSourceType>%s</InputSourceType>%s\
195
<GrayRendering>NTSC</GrayRendering>\
198
<Brightness>1000</Brightness>\
199
<Contrast>1000</Contrast>\
200
<Highlite>0</Highlite>\
201
<Shadow>0</Shadow></ToneMap>\
202
<ContentType>Photo</ContentType></ScanSettings>"
205
# define CANCEL_JOB_REQUEST "PUT %s HTTP/1.1\r\nHost: localhost\r\nUser-Agent: hp\r\n\
204
# define CANCEL_JOB_REQUEST "PUT %s HTTP/1.1\r\nHost: localhost\r\nUser-Agent: hplip\r\n\
206
205
Accept: text/plain\r\nAccept-Language: en-us,en\r\nAccept-Charset:utf-8\r\nKeep-Alive: 10\r\n\
207
206
Content-Type: text/xml\r\nProxy-Connection: Keep-alive\r\nX-Requested-With: XMLHttpRequest\r\nReferer: localhost\r\n\
208
Content-Length: 523\r\nCookie: AccessCounter=new\r\n\r\n\
209
<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\
210
<!-- THIS DATA SUBJECT TO DISCLAIMER(S) INCLUDED WITH THE PRODUCT OF ORIGIN. -->\n\
207
Content-Length: %d\r\nCookie: AccessCounter=new\r\n\r\n"
209
#define CANCEL_JOB_DATA "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\
211
210
<j:Job xmlns:j=\"http://www.hp.com/schemas/imaging/con/ledm/jobs/2009/04/30\" \
212
211
xmlns:dd=\"http://www.hp.com/schemas/imaging/con/dictionaries/1.0/\" \
213
212
xmlns:fax=\"http://www.hp.com/schemas/imaging/con/fax/2008/06/13\" \
388
392
get_tag(tail, size-(tail-payload), tag, sizeof(tag), &tail);
389
393
get_element(tail, size-(tail-payload), value, sizeof(value), &tail);
394
_DBG ("parse_scan_elements adf_resolution_list value=%s", value);
390
395
if(strtol(value, NULL, 10) && elements->config.adf.adf_resolution_list[i-1] != strtol(value, NULL, 10))
391
396
elements->config.adf.adf_resolution_list[i++]=strtol(value, NULL, 10);
394
elements->config.adf.adf_resolution_list[0]=i-1;
399
elements->config.adf.adf_resolution_list[0]=i-1;
400
get_tag(tail, size-(tail-payload), tag, sizeof(tag), &tail);
401
get_tag(tail, size-(tail-payload), tag, sizeof(tag), &tail);//FeederCapacity
402
get_element(tail, size-(tail-payload), value, sizeof(value), &tail);
403
_DBG ("parse_scan_elements FeederCapacity=%s", value);
404
elements->config.settings.feeder_capacity = strtol(value, NULL, 10);
405
get_tag(tail, size-(tail-payload), tag, sizeof(tag), &tail);
406
get_tag(tail, size-(tail-payload), tag, sizeof(tag), &tail);
407
if(!strcmp(tag, "AdfDuplexer"))
409
elements->config.adf.duplex_supported = 1;
410
_DBG ("parse_scan_elements duplex_supported");
396
413
} /* end while (1) */
544
561
static int cancel_job(struct ledm_session *ps)
546
563
struct bb_ledm_session *pbb = ps->bb_session;
547
int len, stat=1, tmo=1/*EXCEPTION_TIMEOUT*/;
564
int len, stat=1, tmo=5/*EXCEPTION_TIMEOUT*/;
568
_DBG("cancel_job user_cancel=%d job_id=%d url=%s \n", ps->user_cancel, ps->job_id, ps->url);
569
if (ps->job_id == 0 || ps->user_cancel == 0)
551
576
if (http_open(ps->dd, HPMUD_S_LEDM_SCAN, &pbb->http_handle) != HTTP_R_OK)
553
578
_BUG("unable to open http connection %s\n", ps->uri);
557
len = snprintf(buf, sizeof(buf), CANCEL_JOB_REQUEST, ps->url);
559
if (http_write(pbb->http_handle, buf, len, 1) != HTTP_R_OK)
561
_BUG("unable to cancel_job %s\n", ps->url);
582
len = snprintf(buf, sizeof(buf), CANCEL_JOB_REQUEST, ps->url, strlen(CANCEL_JOB_DATA));
583
if (http_write(pbb->http_handle, buf, len, 1) != HTTP_R_OK)
585
_BUG("unable to cancel_job %s\n", ps->url);
588
len = snprintf(buf, sizeof(buf), CANCEL_JOB_DATA);
589
if (http_write(pbb->http_handle, buf, len, 1) != HTTP_R_OK)
591
_BUG("unable to cancel_job %s\n", ps->url);
565
594
if (read_http_payload(ps, buf, sizeof(buf), tmo, &bytes_read))
744
771
case SPO_BEST_GUESS: /* called by xsane & sane_start */
745
772
/* Set scan parameters based on best guess. */
746
pp->lines = (int)(SANE_UNFIX(ps->effectiveBry - ps->effectiveTly)/MM_PER_INCH*ps->currentResolution);
747
pp->pixels_per_line = floor(SANE_UNFIX(ps->effectiveBrx -ps->effectiveTlx)/MM_PER_INCH*ps->currentResolution);
773
pp->lines = (int)round(SANE_UNFIX(ps->effectiveBry - ps->effectiveTly)/MM_PER_INCH*ps->currentResolution);
774
pp->pixels_per_line = (int)round(SANE_UNFIX(ps->effectiveBrx -ps->effectiveTlx)/MM_PER_INCH*ps->currentResolution);
748
775
pp->bytes_per_line = BYTES_PER_LINE(pp->pixels_per_line, pp->depth * factor);
755
int bb_is_paper_in_adf(struct ledm_session *ps) /* 0 = no paper in adf, 1 = paper in adf, 2 = busy with scan job, -1 = error */
783
int bb_is_paper_in_adf(struct ledm_session *ps) /* 0 = no paper in adf, 1 = paper in adf, -1 = error */
759
787
struct bb_ledm_session *pbb = ps->bb_session;
761
789
if(http_open(ps->dd, HPMUD_S_LEDM_SCAN, &pbb->http_handle) != HTTP_R_OK)
764
if (http_write(pbb->http_handle, GET_SCANNER_STATUS, sizeof(GET_SCANNER_STATUS)-1, 120) != HTTP_R_OK)
792
if (http_write(pbb->http_handle, GET_SCANNER_STATUS, sizeof(GET_SCANNER_STATUS)-1, 10) != HTTP_R_OK)
770
798
http_close(pbb->http_handle); /* error, close http connection */
771
799
pbb->http_handle = 0;
800
_DBG("bb_is_paper_in_adf .job_id=%d buf=%s\n", ps->job_id, buf);
773
801
if(strstr(buf, ADF_LOADED)) return 1;
774
802
if(strstr(buf, ADF_EMPTY) && strstr(buf, SCANNER_BUSY_WITH_SCAN_JOB)) return 2;
778
char* itoa(int value, char* str, int radix)
780
static char dig[] = "0123456789""abcdefghijklmnopqrstuvwxyz";
786
if (radix == 10 && value < 0)
793
str[n++] = dig[v%radix];
800
for (p = str, q = p + (n-1); p < q; ++p, --q)
801
c = *p, *p = *q, *q = c;
805
int bb_start_scan(struct ledm_session *ps)
807
SANE_Status bb_start_scan(struct ledm_session *ps)
807
809
char buf[4096] = {0};
809
int len, stat=1, bytes_read;
810
int i, timeout = EXCEPTION_TIMEOUT ;
812
struct bb_ledm_session *pbb = ps->bb_session;
812
int i, timeout = 10 ;
813
813
char szPage_ID[5] = {0};
814
814
char szJob_ID[5] = {0};
815
SANE_Status stat = SANE_STATUS_IO_ERROR;
816
struct bb_ledm_session *pbb = ps->bb_session;
816
818
ps->user_cancel = 0;
819
_DBG("bb_start_scan() entering...job_id=%d\n", ps->job_id);
818
820
if (ps->job_id == 0)
820
if(http_open(ps->dd, HPMUD_S_LEDM_SCAN, &pbb->http_handle) != HTTP_R_OK)
827
if (http_write(pbb->http_handle, GET_SCANNER_STATUS, sizeof(GET_SCANNER_STATUS)-1, timeout) != HTTP_R_OK)
832
read_http_payload(ps, buf, sizeof(buf), timeout, &bytes_read);
834
if(strstr(buf, SCANNER_IDLE)) break;
837
http_close(pbb->http_handle); /* error, close http connection */
822
if(http_open(ps->dd, HPMUD_S_LEDM_SCAN, &pbb->http_handle) != HTTP_R_OK)
827
if (http_write(pbb->http_handle, GET_SCANNER_STATUS, sizeof(GET_SCANNER_STATUS)-1, timeout) != HTTP_R_OK)
832
read_http_payload(ps, buf, sizeof(buf), timeout, &bytes_read);
834
if(!strstr(buf, SCANNER_IDLE))
836
stat = SANE_STATUS_DEVICE_BUSY;
840
http_close(pbb->http_handle);
838
841
pbb->http_handle = 0;
840
843
if(http_open(ps->dd, HPMUD_S_LEDM_SCAN, &pbb->http_handle) != HTTP_R_OK)
844
847
len = snprintf(buf, sizeof(buf), CREATE_SCAN_JOB_REQUEST,
845
ps->currentResolution,
846
ps->currentResolution,
847
(int) (ps->currentTlx / 5548.7133),
848
(int) (ps->currentTly / 5548.7133),
849
(int) ((ps->currentBrx / 5548.7133) - (ps->currentTlx / 5548.7133)),
850
(int) ((ps->currentBry / 5548.7133) - (ps->currentTly / 5548.7133)),
852
(! strcmp(ce_element[ps->currentScanMode], "Color8")) ? "Color" : (! strcmp(ce_element[ps->currentScanMode], "Gray8")) ? "Gray" : "Gray",
853
((! strcmp(ce_element[ps->currentScanMode], "Color8")) || (! strcmp(ce_element[ps->currentScanMode], "Gray8"))) ? 8: 8,
854
is_element[ps->currentInputSource]);
857
/* Write the http post header. Note do not send null termination byte. */
858
if (http_write(pbb->http_handle, POST_HEADER, sizeof(POST_HEADER)-1, timeout) != HTTP_R_OK)
863
if (http_write(pbb->http_handle, buf, strlen(buf), 1) != HTTP_R_OK)
868
/* Write zero footer. */
869
if (http_write(pbb->http_handle, ZERO_FOOTER, sizeof(ZERO_FOOTER)-1, 1) != HTTP_R_OK)
875
if (read_http_payload(ps, buf, sizeof(buf), timeout, &bytes_read))
878
http_close(pbb->http_handle);
879
pbb->http_handle = 0;
882
char* jl=strstr(buf, "Location:");
883
if (!jl) goto bugout;
894
strcpy(ps->url, joblist);
896
c=strstr(c, "JobList");
900
int job_id=strtol(c, NULL, 10);
901
itoa(job_id, szJob_ID,10);
902
itoa(1, szPage_ID,10);
848
ps->currentResolution,//<XResolution>
849
ps->currentResolution,//<YResolution>
850
(int) (ps->currentTlx / 5548.7133),//<XStart>
851
(int) ((ps->currentBrx / 5548.7133) - (ps->currentTlx / 5548.7133)),//<Width>
852
(int) (ps->currentTly / 5548.7133),//<YStart>
853
(int) ((ps->currentBry / 5548.7133) - (ps->currentTly / 5548.7133)),//<Height>
855
(! strcmp(ce_element[ps->currentScanMode], "Color8")) ? "Color" : (! strcmp(ce_element[ps->currentScanMode], "Gray8")) ? "Gray" : "Gray",//<ColorSpace>
856
((! strcmp(ce_element[ps->currentScanMode], "Color8")) || (! strcmp(ce_element[ps->currentScanMode], "Gray8"))) ? 8: 8,//<BitDepth>
857
ps->currentInputSource == IS_PLATEN ? is_element[1] : is_element[2],//<InputSource>
858
ps->currentInputSource == IS_PLATEN ? is_element[1] : is_element[2],//<InputSourceType>
859
ps->currentInputSource != IS_ADF_DUPLEX ? "" : "<AdfOptions><AdfOption>Duplex</AdfOption></AdfOptions>");
861
len = len + strlen(ZERO_FOOTER);
863
len = snprintf(buf1, sizeof(buf1), POST_HEADER, len);
864
if (http_write(pbb->http_handle, buf1, strlen(buf1), timeout) != HTTP_R_OK)
869
if (http_write(pbb->http_handle, buf, strlen(buf), 1) != HTTP_R_OK)
874
/* Write zero footer. */
875
if (http_write(pbb->http_handle, ZERO_FOOTER, sizeof(ZERO_FOOTER)-1, 1) != HTTP_R_OK)
879
memset(buf, 0, sizeof(buf));
881
if (read_http_payload(ps, buf, sizeof(buf), timeout, &bytes_read))
884
http_close(pbb->http_handle);
885
pbb->http_handle = 0;
888
char* jl=strstr(buf, "Location:");
889
if (!jl) goto bugout;
900
strcpy(ps->url, joblist);
902
c=strstr(c, "JobList");
906
int job_id=strtol(c, NULL, 10);
907
itoa(job_id, szJob_ID,10);
908
itoa(1, szPage_ID,10);
915
if (ps->currentInputSource == IS_PLATEN)
917
stat = SANE_STATUS_INVAL;
910
922
itoa(ps->job_id,szJob_ID,10);
911
923
itoa(ps->page_id, szPage_ID,10);
925
_DBG("bb_start_scan() url=%s page_id=%d\n", ps->url, ps->page_id);
914
927
memset(buf, 0, sizeof(buf)-1);
916
929
if(http_open(ps->dd, HPMUD_S_LEDM_SCAN, &pbb->http_handle) != HTTP_R_OK)
919
932
while(strstr(buf, READY_TO_UPLOAD) == NULL)
921
//_DBG("bb_start_scan() ENTERING....buf=%s\n", buf);
934
_DBG("bb_start_scan() ENTERING....buf=%s\n", buf);
922
935
len = snprintf(buf, sizeof(buf), GET_SCAN_JOB_URL, ps->url);
924
if (http_write(pbb->http_handle, buf, strlen(buf), 1) != HTTP_R_OK)
929
if (read_http_payload (ps, buf, sizeof(buf), 5, &len) != HTTP_R_OK)
934
if (strstr(buf, CANCELED_BY_DEVICE) || strstr(buf, CANCELED_BY_CLIENT))
936
//_DBG("bb_start_scan() SCAN CANCELLED\n");
941
usleep(500000);//0.5 sec delay
937
if (http_write(pbb->http_handle, buf, strlen(buf), 1) != HTTP_R_OK)
942
if (read_http_payload (ps, buf, sizeof(buf), 5, &len) != HTTP_R_OK)
945
_DBG("bb_start_scan() read_http_payload FAILED len=%d buf=%s\n", len, buf);
948
if (strstr(buf,JOBSTATE_CANCELED) || strstr(buf, CANCELED_BY_DEVICE) || strstr(buf, CANCELED_BY_CLIENT))
950
//_DBG("bb_start_scan() SCAN CANCELLED\n");
951
stat = SANE_STATUS_GOOD;
955
if (strstr(buf, JOBSTATE_COMPLETED))
957
stat = SANE_STATUS_GOOD;
960
usleep(500000);//0.5 sec delay
944
963
char *c = strstr(buf, "<BinaryURL>");
964
_DBG("bb_start_scan() BinaryURL=%s \n", c);
945
966
if (!c) goto bugout;
947
968
char BinaryURL[30];