~ubuntu-branches/ubuntu/raring/hplip/raring-proposed

« back to all changes in this revision

Viewing changes to scan/sane/bb_ledm.c

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2012-05-26 11:20:39 UTC
  • mfrom: (1.5.6) (31.1.3 precise)
  • Revision ID: package-import@ubuntu.com-20120526112039-bevxczegxnbyr5m7
Tags: 3.12.4-1
* New upstream release
* Switch to source/format 3.0 (quilt) - drop dpatch
* Refreshed debian/patches
* dh_autoreconf debian/autogen.sh & set local-options single-debian-patch
* Update to debian/compat -> 9
* Fix "hardened build flags" patch from Moritz - thanks (Closes: #667828)
* Fix "duplex descriptor uninitialized" patch from Matej (Closes: #583273)
* Fix "please migrate to kde-runtime" patch from Pino (Closes: #666544)

Show diffs side-by-side

added added

removed removed

Lines of Context:
81
81
  enum DOCUMENT_TYPE docs[DT_MAX];
82
82
  int document_size_auto_detect_supported;     /* 0=false, 1=true */
83
83
  int feeder_capacity;
84
 
  int rotation;                                /* needed adf front side image rotation */
85
 
  int duplex_rotation;                         /* needed adf back side image rotation */
86
84
};
87
85
 
88
86
struct device_platen
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 */
161
159
 
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" 
168
166
 
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"
182
180
 
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>\
197
 
<scan:ToneMap>\
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>\
 
185
<XStart>%d</XStart>\
 
186
<Width>%d</Width>\
 
187
<YStart>%d</YStart>\
 
188
<Height>%d</Height>\
 
189
<Format>%s</Format>\
 
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>\
 
196
<ToneMap>\
 
197
<Gamma>0</Gamma>\
 
198
<Brightness>1000</Brightness>\
 
199
<Contrast>1000</Contrast>\
 
200
<Highlite>0</Highlite>\
 
201
<Shadow>0</Shadow></ToneMap>\
 
202
<ContentType>Photo</ContentType></ScanSettings>" 
204
203
 
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"
 
208
 
 
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\" \
228
227
# define ADF_EMPTY "<AdfState>Empty</AdfState>"
229
228
# define SCANNER_IDLE "<ScannerState>Idle</ScannerState>"
230
229
# define SCANNER_BUSY_WITH_SCAN_JOB "<ScannerState>BusyWithScanJob</ScannerState>"
 
230
# define JOBSTATE_PROCESSING "<j:JobState>Processing</j:JobState>"
 
231
# define JOBSTATE_CANCELED "<j:JobState>Canceled</j:JobState>"
 
232
# define JOBSTATE_COMPLETED "<j:JobState>Completed</j:JobState>"
231
233
 
232
234
static int parse_scan_elements(const char *payload, int size, struct wscn_scan_elements *elements)
233
235
{
326
328
        {
327
329
          get_tag(tail, size-(tail-payload), tag, sizeof(tag), &tail);
328
330
          get_element(tail, size-(tail-payload), value, sizeof(value), &tail);
 
331
          _DBG ("parse_scan_elements platen_resolution_list value=%s\n", value);
329
332
          if(strtol(value, NULL, 10) && elements->config.platen.platen_resolution_list[i-1] != strtol(value, NULL, 10))
 
333
          
330
334
            elements->config.platen.platen_resolution_list[i++]=strtol(value, NULL, 10);
331
335
        }
332
336
      }
387
391
        {
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);
392
397
        }
393
398
      }
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"))
 
408
      {
 
409
         elements->config.adf.duplex_supported = 1;
 
410
         _DBG ("parse_scan_elements duplex_supported");
 
411
      }
395
412
    }
396
413
  }  /* end while (1) */
397
414
  return 0;
503
520
{
504
521
  struct bb_ledm_session *pbb = ps->bb_session;
505
522
  int bytes_read = 0;
506
 
  int stat=1, tmo=EXCEPTION_TIMEOUT;
 
523
  int stat=1, tmo=10;
507
524
  char buf[8192];
508
525
 
509
526
  if (http_open(ps->dd, HPMUD_S_LEDM_SCAN, &pbb->http_handle) != HTTP_R_OK)
544
561
static int cancel_job(struct ledm_session *ps)
545
562
{
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*/;
548
565
  char buf[2048];
549
566
  int bytes_read;
550
567
 
 
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)
 
570
  {
 
571
       ps->job_id = 0;
 
572
       ps->page_id = 0;
 
573
       return 0 ;
 
574
  }
 
575
  
551
576
  if (http_open(ps->dd, HPMUD_S_LEDM_SCAN, &pbb->http_handle) != HTTP_R_OK)
552
577
  {
553
578
    _BUG("unable to open http connection %s\n", ps->uri);
554
579
    goto bugout;
555
580
  }
556
581
 
557
 
  len = snprintf(buf, sizeof(buf), CANCEL_JOB_REQUEST, ps->url);
558
 
 
559
 
  if (http_write(pbb->http_handle, buf, len, 1) != HTTP_R_OK)
560
 
  {
561
 
    _BUG("unable to cancel_job %s\n", ps->url);
562
 
//    goto bugout;
 
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)
 
584
  {
 
585
    _BUG("unable to cancel_job %s\n", ps->url);
 
586
  }
 
587
 
 
588
  len = snprintf(buf, sizeof(buf), CANCEL_JOB_DATA);
 
589
  if (http_write(pbb->http_handle, buf, len, 1) != HTTP_R_OK)
 
590
  {
 
591
    _BUG("unable to cancel_job %s\n", ps->url);
563
592
  }
564
593
 
565
594
  if (read_http_payload(ps, buf, sizeof(buf), tmo, &bytes_read))
566
595
    goto bugout;
567
596
 
568
 
  ps->job_id = 0;
569
 
  ps->page_id = 0;
570
 
 
571
597
  stat=0;
572
598
 
573
599
bugout:
665
691
  i = pbb->elements.config.platen.platen_resolution_list[0] + 1;
666
692
  while(i--)
667
693
  {
 
694
  _DBG("bb_open platen_resolution_list = %d\n",  pbb->elements.config.platen.platen_resolution_list[i]);
668
695
    ps->platen_resolutionList[i] = pbb->elements.config.platen.platen_resolution_list[i];
669
696
    ps->resolutionList[i] = pbb->elements.config.platen.platen_resolution_list[i];
670
697
  }
743
770
      break;
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);
 
776
      break;
749
777
    default:
750
778
      break;
751
779
  }
752
780
return 0;
753
781
}
754
782
 
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 */
756
784
{
757
 
  char buf[512];
 
785
  char buf[1024];
758
786
  int bytes_read;
759
787
  struct bb_ledm_session *pbb = ps->bb_session;
760
788
 
761
789
  if(http_open(ps->dd, HPMUD_S_LEDM_SCAN, &pbb->http_handle) != HTTP_R_OK)
762
790
  {
763
791
  }
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)
765
793
  {
766
794
    //goto bugout;
767
795
  }
769
797
 
770
798
  http_close(pbb->http_handle);   /* error, close http connection */
771
799
  pbb->http_handle = 0;
772
 
  
 
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;
775
803
  else return 0;
776
804
}
777
805
 
778
 
char* itoa(int value, char* str, int radix)
779
 
{
780
 
  static char dig[] = "0123456789""abcdefghijklmnopqrstuvwxyz";
781
 
  int n = 0, neg = 0;
782
 
  unsigned int v;
783
 
  char* p, *q;
784
 
  char c;
785
 
 
786
 
  if (radix == 10 && value < 0)
787
 
  {
788
 
    value = -value;
789
 
    neg = 1;
790
 
   }
791
 
  v = value;
792
 
  do {
793
 
    str[n++] = dig[v%radix];
794
 
    v /= radix;
795
 
  } while (v);
796
 
  if (neg)
797
 
    str[n++] = '-';
798
 
    str[n] = '\0';
799
 
 
800
 
  for (p = str, q = p + (n-1); p < q; ++p, --q)
801
 
    c = *p, *p = *q, *q = c;
802
 
  return str;
803
 
}
804
806
 
805
 
int bb_start_scan(struct ledm_session *ps)
 
807
SANE_Status bb_start_scan(struct ledm_session *ps)
806
808
{
807
809
  char buf[4096] = {0};
808
 
 
809
 
  int len, stat=1, bytes_read;
810
 
  int i, timeout = EXCEPTION_TIMEOUT ;
811
 
 
812
 
  struct bb_ledm_session *pbb = ps->bb_session;
 
810
  char buf1[1024]={0};
 
811
  int len, bytes_read;
 
812
  int i, timeout = 10 ;
813
813
  char szPage_ID[5] = {0};
814
814
  char szJob_ID[5] = {0};
815
 
 
 
815
  SANE_Status stat = SANE_STATUS_IO_ERROR;
 
816
  struct bb_ledm_session *pbb = ps->bb_session;
 
817
  
816
818
  ps->user_cancel = 0;
817
 
  
 
819
  _DBG("bb_start_scan() entering...job_id=%d\n", ps->job_id);
818
820
  if (ps->job_id == 0)
819
821
  {
820
 
        if(http_open(ps->dd, HPMUD_S_LEDM_SCAN, &pbb->http_handle) != HTTP_R_OK)
821
 
        {
822
 
        // goto bugout;
823
 
        }
824
 
 
825
 
        while(1)
826
 
        {
827
 
          if (http_write(pbb->http_handle, GET_SCANNER_STATUS, sizeof(GET_SCANNER_STATUS)-1, timeout) != HTTP_R_OK)
828
 
          {
829
 
        //goto bugout;
830
 
      }
831
 
                  
832
 
      read_http_payload(ps, buf, sizeof(buf), timeout, &bytes_read);
833
 
 
834
 
      if(strstr(buf, SCANNER_IDLE)) break;
835
 
        }
836
 
 
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)
 
823
    {
 
824
       // goto bugout;
 
825
    }
 
826
 
 
827
    if (http_write(pbb->http_handle, GET_SCANNER_STATUS, sizeof(GET_SCANNER_STATUS)-1, timeout) != HTTP_R_OK)
 
828
    {
 
829
       //goto bugout;
 
830
    }
 
831
 
 
832
    read_http_payload(ps, buf, sizeof(buf), timeout, &bytes_read);
 
833
     
 
834
    if(!strstr(buf, SCANNER_IDLE)) 
 
835
    {
 
836
        stat = SANE_STATUS_DEVICE_BUSY;
 
837
        goto bugout;
 
838
    }
 
839
 
 
840
    http_close(pbb->http_handle);
838
841
        pbb->http_handle = 0;
839
842
 
840
843
    if(http_open(ps->dd, HPMUD_S_LEDM_SCAN, &pbb->http_handle) != HTTP_R_OK)
842
845
    }
843
846
 
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)),
851
 
        "Jpeg",
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]);
855
 
 
856
 
 
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)
859
 
        {
860
 
        //goto bugout;
861
 
        }
862
 
 
863
 
        if (http_write(pbb->http_handle, buf, strlen(buf), 1) != HTTP_R_OK)
864
 
        {
865
 
        //goto bugout;
866
 
        }
867
 
 
868
 
        /* Write zero footer. */
869
 
        if (http_write(pbb->http_handle, ZERO_FOOTER, sizeof(ZERO_FOOTER)-1, 1) != HTTP_R_OK)
870
 
        {
871
 
        //goto bugout;
872
 
        }
873
 
 
874
 
        /* Read response. */
875
 
        if (read_http_payload(ps, buf, sizeof(buf), timeout, &bytes_read))
876
 
        goto bugout;
877
 
 
878
 
        http_close(pbb->http_handle);
879
 
        pbb->http_handle = 0;
880
 
 
881
 
        char joblist[64];
882
 
        char* jl=strstr(buf, "Location:");
883
 
        if (!jl) goto bugout;
884
 
        jl=jl+10;
885
 
        
886
 
        int i=0;
887
 
        while(*jl != '\r')
888
 
        { 
889
 
        joblist[i]=*jl; 
890
 
        jl=jl+1; i++;
891
 
        } 
892
 
        joblist[i]='\0';
893
 
        
894
 
        strcpy(ps->url, joblist);
895
 
        char *c=ps->url;
896
 
        c=strstr(c, "JobList"); 
897
 
        if (c)
898
 
        {
899
 
            c=c+8;
900
 
            int job_id=strtol(c, NULL, 10);
901
 
            itoa(job_id, szJob_ID,10);
902
 
            itoa(1, szPage_ID,10);
903
 
            ps->page_id = 1;
904
 
            ps->job_id = job_id;
905
 
        }
 
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>
 
854
        "Jpeg",//<Format>
 
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>");
 
860
 
 
861
    len = len + strlen(ZERO_FOOTER);
 
862
 
 
863
    len = snprintf(buf1, sizeof(buf1), POST_HEADER, len);
 
864
    if (http_write(pbb->http_handle, buf1, strlen(buf1), timeout) != HTTP_R_OK)
 
865
    {
 
866
        //goto bugout;
 
867
    }
 
868
    
 
869
    if (http_write(pbb->http_handle, buf, strlen(buf), 1) != HTTP_R_OK)
 
870
    {
 
871
        //goto bugout;
 
872
    }
 
873
 
 
874
    /* Write zero footer. */
 
875
    if (http_write(pbb->http_handle, ZERO_FOOTER, sizeof(ZERO_FOOTER)-1, 1) != HTTP_R_OK)
 
876
    {
 
877
        //goto bugout;
 
878
    }
 
879
    memset(buf, 0, sizeof(buf));
 
880
    /* Read response. */
 
881
    if (read_http_payload(ps, buf, sizeof(buf), timeout, &bytes_read))
 
882
       goto bugout;
 
883
 
 
884
    http_close(pbb->http_handle);
 
885
    pbb->http_handle = 0;
 
886
 
 
887
    char joblist[64];
 
888
    char* jl=strstr(buf, "Location:");
 
889
    if (!jl) goto bugout;
 
890
    jl=jl+10;
 
891
        
 
892
    int i=0;
 
893
    while(*jl != '\r')
 
894
    { 
 
895
      joblist[i]=*jl; 
 
896
      jl=jl+1; i++;
 
897
    } 
 
898
    joblist[i]='\0';
 
899
 
 
900
    strcpy(ps->url, joblist);
 
901
    char *c=ps->url;
 
902
    c=strstr(c, "JobList"); 
 
903
    if (c)
 
904
    {
 
905
      c=c+8;
 
906
      int job_id=strtol(c, NULL, 10);
 
907
      itoa(job_id, szJob_ID,10);
 
908
      itoa(1, szPage_ID,10);
 
909
      ps->page_id = 1;
 
910
      ps->job_id = job_id;
 
911
    }
906
912
  }
907
913
  else
908
914
  {
 
915
    if (ps->currentInputSource == IS_PLATEN)
 
916
    {
 
917
       stat = SANE_STATUS_INVAL;
 
918
       goto bugout;
 
919
    }
 
920
 
909
921
    ps->page_id++;
910
922
    itoa(ps->job_id,szJob_ID,10);
911
923
    itoa(ps->page_id, szPage_ID,10);
912
924
  }
913
 
 
 
925
  _DBG("bb_start_scan() url=%s page_id=%d\n", ps->url, ps->page_id);
 
926
  
914
927
  memset(buf, 0, sizeof(buf)-1);
915
928
 
916
929
  if(http_open(ps->dd, HPMUD_S_LEDM_SCAN, &pbb->http_handle) != HTTP_R_OK)
918
931
  }
919
932
  while(strstr(buf, READY_TO_UPLOAD) == NULL)
920
933
  {
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);
923
936
 
924
 
         if (http_write(pbb->http_handle, buf, strlen(buf), 1) != HTTP_R_OK)
925
 
         {
926
 
                //goto bugout;
927
 
                break ;
928
 
         }
929
 
         if (read_http_payload (ps, buf, sizeof(buf), 5, &len) != HTTP_R_OK)
930
 
         {
931
 
             //goto bugout
932
 
             break;
933
 
         }
934
 
         if (strstr(buf, CANCELED_BY_DEVICE) || strstr(buf, CANCELED_BY_CLIENT))
935
 
         {
936
 
                //_DBG("bb_start_scan() SCAN CANCELLED\n");
937
 
                stat=0;
938
 
                ps->user_cancel = 1;
939
 
                goto bugout;
940
 
         }
941
 
         usleep(500000);//0.5 sec delay
 
937
     if (http_write(pbb->http_handle, buf, strlen(buf), 1) != HTTP_R_OK)
 
938
     {
 
939
        //goto bugout;
 
940
        break ;
 
941
     }
 
942
     if (read_http_payload (ps, buf, sizeof(buf), 5, &len) != HTTP_R_OK)
 
943
     {
 
944
        //goto bugout
 
945
        _DBG("bb_start_scan() read_http_payload FAILED len=%d buf=%s\n", len, buf);
 
946
        break;
 
947
     }
 
948
     if (strstr(buf,JOBSTATE_CANCELED) || strstr(buf, CANCELED_BY_DEVICE) || strstr(buf, CANCELED_BY_CLIENT))
 
949
     {
 
950
        //_DBG("bb_start_scan() SCAN CANCELLED\n");
 
951
        stat = SANE_STATUS_GOOD;
 
952
        ps->user_cancel = 1;
 
953
        goto bugout;
 
954
     }
 
955
     if (strstr(buf, JOBSTATE_COMPLETED))
 
956
     {
 
957
        stat = SANE_STATUS_GOOD;
 
958
        goto bugout;
 
959
     }
 
960
     usleep(500000);//0.5 sec delay
942
961
  }//end while()
943
962
 
944
963
  char *c = strstr(buf, "<BinaryURL>");
 
964
  _DBG("bb_start_scan() BinaryURL=%s \n", c);
 
965
  
945
966
  if (!c) goto bugout;
946
967
  c +=11;
947
968
  char BinaryURL[30];
967
988
 
968
989
  if(strstr(buf, "HTTP/1.1 400 Bad Request")) http_read_header(pbb->http_handle, buf, sizeof(buf), timeout, &len);
969
990
  
970
 
  stat=0;
 
991
  stat = SANE_STATUS_GOOD;
971
992
bugout:
972
993
  if (stat && pbb->http_handle)
973
994
  {
984
1005
  int i=0, tmo=50, len;
985
1006
 
986
1007
  if(ps->currentResolution >= 1200) tmo *= 5;
987
 
 
 
1008
  
988
1009
  while(1)
989
1010
  {
990
1011
    if(http_read_size(pbb->http_handle, buffer+i, 1, tmo, &len) == 2) return 0;
1001
1022
  int size=0, stat=1;
1002
1023
  char buf_size[2];
1003
1024
  int len=0, tmo=50;
1004
 
 
 
1025
  _DBG("bb_get_image_data http_handle=%p cnt=%d pbb=%p\n", pbb->http_handle, ps->cnt, pbb);
1005
1026
  if(ps->currentResolution >= 1200) tmo *= 5;
1006
 
 
 
1027
 
1007
1028
  if (ps->cnt == 0)
1008
1029
  {
1009
1030
    size = get_size(ps);
1047
1068
    pbb->http_handle = 0;
1048
1069
  }
1049
1070
  cancel_job(ps);
 
1071
  memset(ps->url, 0, sizeof(ps->url));
1050
1072
  ps->job_id = 0;
1051
1073
  ps->page_id = 0;
1052
1074
  return 0;