home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / programs / comms_networking / irclient / !IRClient / Scripts / Docs / Prog / HTTPLib < prev    next >
Encoding:
Text File  |  1996-12-27  |  5.9 KB  |  237 lines

  1. HTTPLib
  2. =======
  3. This is a HTTP fetcher for IRClient. It works ok on web pages, but graphics
  4. and text will not be formatted correctly.
  5.  
  6. Structures
  7. ----------
  8. http_listptr -> a stack of the list structures we are in
  9.                 !0 -> previous entry in stack, or 0 for start
  10.                 !4 -> type of chain (List_X)
  11.                 !8 -> current number in list
  12.  
  13. http_linkstart -> a queue of the links found in the current document
  14.                 !0 -> next entry in queue, or 0 for end
  15.                 !4 -> name to give the user for the entry
  16.                 !8 -> link URL
  17. http_linkend -> the last entry in the queue
  18.  
  19. http_prevstart -> a queue of the current history
  20.                 !0 -> the next entry in the history
  21.                 !4 -> the previous entry in the history
  22.                 !8 -> the URL of the page
  23.                 !12 -> the 'title' of the page
  24. http_prevend -> the last entry in the queue
  25.  
  26. http_fetchptr -> the start of a stack of subsiduary fetches going on
  27.                 !0 -> previous entry in stack, or 0 for end
  28.                 !4 = socket handle
  29.                 !8 = buffer handle
  30.                 !12 -> the content type of this fetch
  31.                 !16 -> stack of header data (start)
  32.                 !20 -> stack of header data (end)
  33. header data -> information about the header returned from a fetch
  34.                 !0 -> next entry (ordered), or 0 for end
  35.                 !4 -> field name
  36.                 !8 -> field value
  37.  
  38. Authentication
  39. --------------
  40. Currently relies on the fact that I'll get an WWW-Authenticate: header for
  41. new realms and it will forget any prior realms when entering them. Only one
  42. realm per time supported.
  43.  
  44.  
  45. Speed ups
  46. ---------
  47. To increase the speed of the HTTPLib module I've moved some of the code into
  48. a seperate Relocatable Module. Basically, the modules provides the following
  49. code :
  50.  
  51. HTMLDecode_GetWord (reduced time from 34s to 11s)
  52. => r0-> buffer to read
  53.    r1 = length of buffer
  54.    r2 = flag (0 if end of buffer is NOT end of file)
  55. <= r0-> word read
  56.    r1 = number of bytes removed from buffer
  57.  
  58. Which was based on :
  59.  
  60.  REM flag = TRUE means that EOF is really EOF, not end of data
  61.  DEFFNgetword(flag)
  62.  LOCAL ret$,b,p,start
  63.  start=FNHTTP_Pos
  64.  ret$=""
  65.  b=32
  66.  WHILE (b=32 ORb=9 OR b=13 ORb=10) AND NOT FNHTTP_EOF
  67.   b=FNHTTP_GetByte
  68.  ENDWHILE
  69.  IF FNHTTP_EOF THEN
  70.   ret$=""
  71.  ELSE
  72.   IF b=ASC("<") THEN
  73.    REM A Tag
  74.    p=FNHTTP_GetByte
  75.    b=FNHTTP_GetByte
  76.    IF p=ASC("!") AND b=ASC("-") THEN
  77.     REM A comment
  78.     REPEAT
  79.      p=b
  80.      b=FNHTTP_GetByte
  81.     UNTIL(b=ASC(">") AND p=ASC("-")) OR FNHTTP_EOF
  82.     PROCHTTP_MoveOn(start)
  83.     ret$=FNgetword(flag)
  84.     start=FNHTTP_Pos
  85.    ELSE
  86.     ret$="<"+CHR$p+CHR$b
  87.     WHILE b<>ASC(">") AND NOT FNHTTP_EOF
  88.      b=FNHTTP_GetByte
  89.      IF b=13 ORb=9 ORb=10 THEN
  90.       b=32
  91.      ENDIF
  92.      ret$+=CHR$(b)
  93.     ENDWHILE
  94.     WHILE INSTR(ret$,"  ")>0
  95.      ret$=LEFT$(ret$,INSTR(ret$,"  "))+MID$(ret$,INSTR(ret$,"  ")+2)
  96.     ENDWHILE
  97.    ENDIF
  98.   ELSE
  99.    ret$=CHR$b
  100.    REPEAT
  101.     b=FNHTTP_GetByte
  102.     ret$+=CHR$(b)
  103.    UNTIL b=32 OR b=9 OR b=13 ORb=10 OR b=ASC("<") OR FNHTTP_EOF
  104.    b=ASC(RIGHT$(ret$,1))
  105.    IF b=32 OR b=9 OR b=13 ORb=10 OR b=ASC("<") THEN
  106.     ret$=LEFT$(ret$)
  107.     PROCHTTP_BackOne
  108.    ENDIF
  109.   ENDIF
  110.  ENDIF
  111.  IF FNHTTP_EOF THEN
  112.   IF flag THEN
  113.    REM We've reached the end and it really /is/ the end !
  114.    PROCHTTP_MoveOn(start)
  115.   ELSE
  116.    REM We've reached the end, but we're not actually done, 'cos we
  117.    REM haven't got the whole page yet
  118.    PROCHTTP_JumpBack(start)
  119.    REM You can tell because we return a null string but flag is
  120.    REM FALSE - set flag TRUE when you get the connection closed
  121.    REM error and then re-parse the data
  122.    ret$=""
  123.   ENDIF
  124.  ELSE
  125.   REM We've got a word, so we can shrink the buffer a bit
  126.   PROCHTTP_MoveOn(start)
  127.  ENDIF
  128.  =ret$
  129.  
  130.  REM Read a byte from the buffer
  131.  DEFFNHTTP_GetByte
  132.  LOCAL ret
  133.  http_addr+=1
  134.  IF http_addr>http_end THEN
  135.   ret=32
  136.  ELSE
  137.   ret=?(http_addr-1)
  138.  ENDIF
  139.  =ret
  140.  :
  141.  DEFFNHTTP_EOF
  142.  LOCAL ret
  143.  IF http_addr>=http_end THEN
  144.   ret=TRUE
  145.  ELSE
  146.   ret=FALSE
  147.  ENDIF
  148.  =ret
  149.  :
  150.  DEFPROCHTTP_BackOne
  151.  http_addr-=1
  152.  ENDPROC
  153.  :
  154.  DEFPROCHTTP_JumpBack(pos)
  155.  http_addr=pos
  156.  ENDPROC
  157.  :
  158.  DEFPROCHTTP_MoveOn(pos)
  159.  PROCBufferShrink(HTTPBuffer,http_addr-pos)
  160.  http_addr=FNBufferAddr(HTTPBuffer)
  161.  http_end=http_addr+FNBufferLength(HTTPBuffer)
  162.  ENDPROC
  163.  :
  164.  DEFFNHTTP_Pos
  165.  =http_addr
  166.  
  167. Or something similar to that...
  168. Speed improvement from this reduces the rendering time for my homepage from
  169. 34 seconds to 11.
  170.  
  171.  
  172. HTMLDecode_GetAttribute (reduced time from 11s to 8s)
  173. => r0-> string (starting at first attribute)
  174. <= r0-> next string (null if no more)
  175.    r1-> capitalised attribute (or 0 if no more)
  176.    r2-> value (or 0 if none given)
  177.  
  178. This replaces :
  179.  attrib$=FNreadattrib(str$)
  180.  value$=FNreadattribvalue(str$)
  181.  str$=FNskipattrib(str$)
  182.  
  183. to read the data, and for the actual processing :
  184.  DEFFNreadattrib(str$)
  185.  LOCAL attrib$
  186.  IF INSTR(str$+"=","=")<INSTR(str$+" "," ") THEN
  187.   attrib$=LEFT$(str$,INSTR(str$+"=","=")-1)
  188.  ELSE
  189.   attrib$=LEFT$(str$,INSTR(str$+" "," ")-1)
  190.  ENDIF
  191.  =FNCapitalise(attrib$)
  192.  :
  193.  DEFFNreadattribvalue(str$)
  194.  LOCAL attrib$,ret$
  195.  IF INSTR(str$+"=","=")<INSTR(str$+" "," ") THEN
  196.   str$=MID$(str$,INSTR(str$+"=","="))
  197.  ELSE
  198.   str$=MID$(str$,INSTR(str$+" "," ")+1)
  199.  ENDIF
  200.  IF LEFT$(str$,1)="=" THEN
  201.   str$=FNStrip(MID$(str$,2))
  202.   IF LEFT$(str$,1)="""" THEN
  203.    ret$=MID$(str$,2,INSTR(str$+"""","""",2)-2)
  204.   ELSE
  205.    ret$=LEFT$(str$,INSTR(str$+" "," ")-1)
  206.   ENDIF
  207.  ELSE
  208.   ret$=""
  209.  ENDIF
  210.  =ret$
  211.  :
  212.  DEFFNskipattrib(str$)
  213.  IF INSTR(str$+"=","=")<INSTR(str$+" "," ") THEN
  214.   str$=MID$(str$,INSTR(str$+"=","="))
  215.  ELSE
  216.   str$=MID$(str$,INSTR(str$+" "," ")+1)
  217.  ENDIF
  218.  IF LEFT$(str$,1)="=" THEN
  219.   str$=FNStrip(MID$(str$,2))
  220.   IF LEFT$(str$,1)="""" THEN
  221.    str$=MID$(str$,INSTR(str$+"""","""",2)+1)
  222.   ELSE
  223.    str$=MID$(str$,INSTR(str$+" "," ")+1)
  224.   ENDIF
  225.  ENDIF
  226.  =FNStrip(str$)
  227.  
  228.  
  229. HTMLDecode_MoveBytes
  230. => r0-> source
  231.    r1-> destination
  232.    r2 = length
  233.  
  234. Unused by HTTPLib, but basically moves bytes using a simple loop. Intended
  235. for reducing buffers, ie copy high to low for FIFO stacks. Will corrupt low
  236. to high copies if they overlap.
  237.