Hex Artifact Content
Not logged in

Artifact 6e4217591ad270da6a37b08d222f83da55b47d0a:

File src/browse.c part of check-in [e81cc91aa4] - Additional cleanup in the differencing engine. The new "dir" webpage now uses name= instead of the d= for the query parameter. by drh on 2008-02-04 14:24:28.

0000: 2f 2a 0a 2a 2a 20 43 6f 70 79 72 69 67 68 74 20  /*.** Copyright 
0010: 28 63 29 20 32 30 30 38 20 44 2e 20 52 69 63 68  (c) 2008 D. Rich
0020: 61 72 64 20 48 69 70 70 0a 2a 2a 0a 2a 2a 20 54  ard Hipp.**.** T
0030: 68 69 73 20 70 72 6f 67 72 61 6d 20 69 73 20 66  his program is f
0040: 72 65 65 20 73 6f 66 74 77 61 72 65 3b 20 79 6f  ree software; yo
0050: 75 20 63 61 6e 20 72 65 64 69 73 74 72 69 62 75  u can redistribu
0060: 74 65 20 69 74 20 61 6e 64 2f 6f 72 0a 2a 2a 20  te it and/or.** 
0070: 6d 6f 64 69 66 79 20 69 74 20 75 6e 64 65 72 20  modify it under 
0080: 74 68 65 20 74 65 72 6d 73 20 6f 66 20 74 68 65  the terms of the
0090: 20 47 4e 55 20 47 65 6e 65 72 61 6c 20 50 75 62   GNU General Pub
00a0: 6c 69 63 0a 2a 2a 20 4c 69 63 65 6e 73 65 20 76  lic.** License v
00b0: 65 72 73 69 6f 6e 20 32 20 61 73 20 70 75 62 6c  ersion 2 as publ
00c0: 69 73 68 65 64 20 62 79 20 74 68 65 20 46 72 65  ished by the Fre
00d0: 65 20 53 6f 66 74 77 61 72 65 20 46 6f 75 6e 64  e Software Found
00e0: 61 74 69 6f 6e 2e 0a 2a 2a 0a 2a 2a 20 54 68 69  ation..**.** Thi
00f0: 73 20 70 72 6f 67 72 61 6d 20 69 73 20 64 69 73  s program is dis
0100: 74 72 69 62 75 74 65 64 20 69 6e 20 74 68 65 20  tributed in the 
0110: 68 6f 70 65 20 74 68 61 74 20 69 74 20 77 69 6c  hope that it wil
0120: 6c 20 62 65 20 75 73 65 66 75 6c 2c 0a 2a 2a 20  l be useful,.** 
0130: 62 75 74 20 57 49 54 48 4f 55 54 20 41 4e 59 20  but WITHOUT ANY 
0140: 57 41 52 52 41 4e 54 59 3b 20 77 69 74 68 6f 75  WARRANTY; withou
0150: 74 20 65 76 65 6e 20 74 68 65 20 69 6d 70 6c 69  t even the impli
0160: 65 64 20 77 61 72 72 61 6e 74 79 20 6f 66 0a 2a  ed warranty of.*
0170: 2a 20 4d 45 52 43 48 41 4e 54 41 42 49 4c 49 54  * MERCHANTABILIT
0180: 59 20 6f 72 20 46 49 54 4e 45 53 53 20 46 4f 52  Y or FITNESS FOR
0190: 20 41 20 50 41 52 54 49 43 55 4c 41 52 20 50 55   A PARTICULAR PU
01a0: 52 50 4f 53 45 2e 20 20 53 65 65 20 74 68 65 20  RPOSE.  See the 
01b0: 47 4e 55 0a 2a 2a 20 47 65 6e 65 72 61 6c 20 50  GNU.** General P
01c0: 75 62 6c 69 63 20 4c 69 63 65 6e 73 65 20 66 6f  ublic License fo
01d0: 72 20 6d 6f 72 65 20 64 65 74 61 69 6c 73 2e 0a  r more details..
01e0: 2a 2a 20 0a 2a 2a 20 59 6f 75 20 73 68 6f 75 6c  ** .** You shoul
01f0: 64 20 68 61 76 65 20 72 65 63 65 69 76 65 64 20  d have received 
0200: 61 20 63 6f 70 79 20 6f 66 20 74 68 65 20 47 4e  a copy of the GN
0210: 55 20 47 65 6e 65 72 61 6c 20 50 75 62 6c 69 63  U General Public
0220: 0a 2a 2a 20 4c 69 63 65 6e 73 65 20 61 6c 6f 6e  .** License alon
0230: 67 20 77 69 74 68 20 74 68 69 73 20 6c 69 62 72  g with this libr
0240: 61 72 79 3b 20 69 66 20 6e 6f 74 2c 20 77 72 69  ary; if not, wri
0250: 74 65 20 74 6f 20 74 68 65 0a 2a 2a 20 46 72 65  te to the.** Fre
0260: 65 20 53 6f 66 74 77 61 72 65 20 46 6f 75 6e 64  e Software Found
0270: 61 74 69 6f 6e 2c 20 49 6e 63 2e 2c 20 35 39 20  ation, Inc., 59 
0280: 54 65 6d 70 6c 65 20 50 6c 61 63 65 20 2d 20 53  Temple Place - S
0290: 75 69 74 65 20 33 33 30 2c 0a 2a 2a 20 42 6f 73  uite 330,.** Bos
02a0: 74 6f 6e 2c 20 4d 41 20 20 30 32 31 31 31 2d 31  ton, MA  02111-1
02b0: 33 30 37 2c 20 55 53 41 2e 0a 2a 2a 0a 2a 2a 20  307, USA..**.** 
02c0: 41 75 74 68 6f 72 20 63 6f 6e 74 61 63 74 20 69  Author contact i
02d0: 6e 66 6f 72 6d 61 74 69 6f 6e 3a 0a 2a 2a 20 20  nformation:.**  
02e0: 20 64 72 68 40 68 77 61 63 69 2e 63 6f 6d 0a 2a   drh@hwaci.com.*
02f0: 2a 20 20 20 68 74 74 70 3a 2f 2f 77 77 77 2e 68  *   http://www.h
0300: 77 61 63 69 2e 63 6f 6d 2f 64 72 68 2f 0a 2a 2a  waci.com/drh/.**
0310: 0a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  .***************
0320: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0330: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0340: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0350: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0360: 0a 2a 2a 0a 2a 2a 20 54 68 69 73 20 66 69 6c 65  .**.** This file
0370: 20 63 6f 6e 74 61 69 6e 73 20 63 6f 64 65 20 74   contains code t
0380: 6f 20 69 6d 70 6c 65 6d 65 6e 74 20 74 68 65 20  o implement the 
0390: 66 69 6c 65 20 62 72 6f 77 73 65 72 20 77 65 62  file browser web
03a0: 20 69 6e 74 65 72 66 61 63 65 2e 0a 2a 2f 0a 23   interface..*/.#
03b0: 69 6e 63 6c 75 64 65 20 22 63 6f 6e 66 69 67 2e  include "config.
03c0: 68 22 0a 23 69 6e 63 6c 75 64 65 20 22 62 72 6f  h".#include "bro
03d0: 77 73 65 2e 68 22 0a 23 69 6e 63 6c 75 64 65 20  wse.h".#include 
03e0: 3c 61 73 73 65 72 74 2e 68 3e 0a 0a 2f 2a 0a 2a  <assert.h>../*.*
03f0: 2a 20 54 68 69 73 20 69 73 20 74 68 65 20 69 6d  * This is the im
0400: 70 6c 65 6d 65 6e 74 69 6f 6e 20 6f 66 20 74 68  plemention of th
0410: 65 20 22 70 61 74 68 65 6c 65 6d 65 6e 74 28 58  e "pathelement(X
0420: 2c 4e 29 22 20 53 51 4c 20 66 75 6e 63 74 69 6f  ,N)" SQL functio
0430: 6e 2e 0a 2a 2a 0a 2a 2a 20 49 66 20 58 20 69 73  n..**.** If X is
0440: 20 61 20 75 6e 69 78 2d 6c 69 6b 65 20 70 61 74   a unix-like pat
0450: 68 6e 61 6d 65 20 28 77 69 74 68 20 22 2f 22 20  hname (with "/" 
0460: 73 65 70 61 72 61 74 6f 72 73 29 20 61 6e 64 20  separators) and 
0470: 4e 20 69 73 20 61 6e 0a 2a 2a 20 69 6e 74 65 67  N is an.** integ
0480: 65 72 2c 20 74 68 65 6e 20 73 6b 69 70 20 74 68  er, then skip th
0490: 65 20 69 6e 69 74 69 61 6c 20 4e 20 63 68 61 72  e initial N char
04a0: 61 63 74 65 72 73 20 6f 66 20 58 20 61 6e 64 20  acters of X and 
04b0: 72 65 74 75 72 6e 20 74 68 65 0a 2a 2a 20 6e 61  return the.** na
04c0: 6d 65 20 6f 66 20 74 68 65 20 70 61 74 68 20 63  me of the path c
04d0: 6f 6d 70 6f 6e 65 6e 74 20 74 68 61 74 20 62 65  omponent that be
04e0: 67 69 6e 73 20 6f 6e 20 74 68 65 20 4e 2b 31 74  gins on the N+1t
04f0: 68 20 63 68 61 72 61 63 74 65 72 0a 2a 2a 20 28  h character.** (
0500: 6e 75 6d 62 65 72 65 64 20 66 72 6f 6d 20 30 29  numbered from 0)
0510: 2e 20 20 49 66 20 74 68 65 20 70 61 74 68 20 63  .  If the path c
0520: 6f 6d 70 6f 6e 65 6e 74 20 69 73 20 61 20 64 69  omponent is a di
0530: 72 65 63 74 6f 72 79 20 28 69 66 0a 2a 2a 20 69  rectory (if.** i
0540: 74 20 69 73 20 66 6f 6c 6c 6f 77 65 64 20 62 79  t is followed by
0550: 20 6f 74 68 65 72 20 70 61 74 68 20 63 6f 6d 70   other path comp
0560: 6f 6e 65 6e 74 73 29 20 74 68 65 6e 20 70 72 65  onents) then pre
0570: 70 65 6e 64 20 22 2f 22 2e 0a 2a 2a 0a 2a 2a 20  pend "/"..**.** 
0580: 45 78 61 6d 70 6c 65 73 3a 0a 2a 2a 0a 2a 2a 20  Examples:.**.** 
0590: 20 20 20 20 20 70 61 74 68 65 6c 65 6d 65 6e 74       pathelement
05a0: 28 27 61 62 63 2f 70 71 72 2f 78 79 7a 27 2c 20  ('abc/pqr/xyz', 
05b0: 34 29 20 20 2d 3e 20 20 27 2f 70 71 72 27 0a 2a  4)  ->  '/pqr'.*
05c0: 2a 20 20 20 20 20 20 70 61 74 68 65 6c 65 6d 65  *      patheleme
05d0: 6e 74 28 27 61 62 63 2f 70 71 72 27 2c 20 34 29  nt('abc/pqr', 4)
05e0: 20 20 20 20 20 20 2d 3e 20 20 27 70 71 72 27 0a        ->  'pqr'.
05f0: 2a 2a 20 20 20 20 20 20 70 61 74 68 65 6c 65 6d  **      pathelem
0600: 65 6e 74 28 27 61 62 63 2f 70 71 72 2f 78 79 7a  ent('abc/pqr/xyz
0610: 27 2c 20 30 29 20 20 2d 3e 20 20 27 2f 61 62 63  ', 0)  ->  '/abc
0620: 27 0a 2a 2f 0a 73 74 61 74 69 63 20 76 6f 69 64  '.*/.static void
0630: 20 70 61 74 68 65 6c 65 6d 65 6e 74 46 75 6e 63   pathelementFunc
0640: 28 0a 20 20 73 71 6c 69 74 65 33 5f 63 6f 6e 74  (.  sqlite3_cont
0650: 65 78 74 20 2a 63 6f 6e 74 65 78 74 2c 0a 20 20  ext *context,.  
0660: 69 6e 74 20 61 72 67 63 2c 0a 20 20 73 71 6c 69  int argc,.  sqli
0670: 74 65 33 5f 76 61 6c 75 65 20 2a 2a 61 72 67 76  te3_value **argv
0680: 0a 29 7b 0a 20 20 63 6f 6e 73 74 20 75 6e 73 69  .){.  const unsi
0690: 67 6e 65 64 20 63 68 61 72 20 2a 7a 3b 0a 20 20  gned char *z;.  
06a0: 69 6e 74 20 6c 65 6e 2c 20 6e 2c 20 69 3b 0a 20  int len, n, i;. 
06b0: 20 63 68 61 72 20 2a 7a 4f 75 74 3b 0a 0a 20 20   char *zOut;..  
06c0: 61 73 73 65 72 74 28 20 61 72 67 63 3d 3d 32 20  assert( argc==2 
06d0: 29 3b 0a 20 20 7a 20 3d 20 73 71 6c 69 74 65 33  );.  z = sqlite3
06e0: 5f 76 61 6c 75 65 5f 74 65 78 74 28 61 72 67 76  _value_text(argv
06f0: 5b 30 5d 29 3b 0a 20 20 69 66 28 20 7a 3d 3d 30  [0]);.  if( z==0
0700: 20 29 20 72 65 74 75 72 6e 3b 0a 20 20 6c 65 6e   ) return;.  len
0710: 20 3d 20 73 71 6c 69 74 65 33 5f 76 61 6c 75 65   = sqlite3_value
0720: 5f 62 79 74 65 73 28 61 72 67 76 5b 30 5d 29 3b  _bytes(argv[0]);
0730: 0a 20 20 6e 20 3d 20 73 71 6c 69 74 65 33 5f 76  .  n = sqlite3_v
0740: 61 6c 75 65 5f 69 6e 74 28 61 72 67 76 5b 31 5d  alue_int(argv[1]
0750: 29 3b 0a 20 20 69 66 28 20 6c 65 6e 3c 3d 6e 20  );.  if( len<=n 
0760: 29 20 72 65 74 75 72 6e 3b 0a 20 20 69 66 28 20  ) return;.  if( 
0770: 6e 3e 30 20 26 26 20 7a 5b 6e 2d 31 5d 21 3d 27  n>0 && z[n-1]!='
0780: 2f 27 20 29 20 72 65 74 75 72 6e 3b 0a 20 20 66  /' ) return;.  f
0790: 6f 72 28 69 3d 6e 3b 20 69 3c 6c 65 6e 20 26 26  or(i=n; i<len &&
07a0: 20 7a 5b 69 5d 21 3d 27 2f 27 3b 20 69 2b 2b 29   z[i]!='/'; i++)
07b0: 7b 7d 0a 20 20 69 66 28 20 69 3d 3d 6c 65 6e 20  {}.  if( i==len 
07c0: 29 7b 0a 20 20 20 20 73 71 6c 69 74 65 33 5f 72  ){.    sqlite3_r
07d0: 65 73 75 6c 74 5f 74 65 78 74 28 63 6f 6e 74 65  esult_text(conte
07e0: 78 74 2c 20 28 63 68 61 72 2a 29 26 7a 5b 6e 5d  xt, (char*)&z[n]
07f0: 2c 20 6c 65 6e 2d 6e 2c 20 53 51 4c 49 54 45 5f  , len-n, SQLITE_
0800: 54 52 41 4e 53 49 45 4e 54 29 3b 0a 20 20 7d 65  TRANSIENT);.  }e
0810: 6c 73 65 7b 0a 20 20 20 20 7a 4f 75 74 20 3d 20  lse{.    zOut = 
0820: 73 71 6c 69 74 65 33 5f 6d 70 72 69 6e 74 66 28  sqlite3_mprintf(
0830: 22 2f 25 2e 2a 73 22 2c 20 69 2d 6e 2c 20 26 7a  "/%.*s", i-n, &z
0840: 5b 6e 5d 29 3b 0a 20 20 20 20 73 71 6c 69 74 65  [n]);.    sqlite
0850: 33 5f 72 65 73 75 6c 74 5f 74 65 78 74 28 63 6f  3_result_text(co
0860: 6e 74 65 78 74 2c 20 7a 4f 75 74 2c 20 69 2d 6e  ntext, zOut, i-n
0870: 2b 31 2c 20 73 71 6c 69 74 65 33 5f 66 72 65 65  +1, sqlite3_free
0880: 29 3b 0a 20 20 7d 0a 7d 0a 0a 0a 2f 2a 0a 2a 2a  );.  }.}.../*.**
0890: 20 57 45 42 50 41 47 45 3a 20 64 69 72 0a 2a 2a   WEBPAGE: dir.**
08a0: 0a 2a 2a 20 51 75 65 72 79 20 70 61 72 61 6d 65  .** Query parame
08b0: 74 65 72 73 3a 0a 2a 2a 0a 2a 2a 20 20 20 20 6e  ters:.**.**    n
08c0: 61 6d 65 3d 50 41 54 48 20 20 20 20 20 20 20 20  ame=PATH        
08d0: 44 69 72 65 63 74 6f 72 79 20 74 6f 20 64 69 73  Directory to dis
08e0: 70 6c 61 79 2e 20 20 52 65 71 75 69 72 65 64 2e  play.  Required.
08f0: 0a 2a 2f 0a 76 6f 69 64 20 70 61 67 65 5f 64 69  .*/.void page_di
0900: 72 28 76 6f 69 64 29 7b 0a 20 20 63 6f 6e 73 74  r(void){.  const
0910: 20 63 68 61 72 20 2a 7a 44 20 3d 20 50 28 22 6e   char *zD = P("n
0920: 61 6d 65 22 29 3b 0a 20 20 69 6e 74 20 6d 78 4c  ame");.  int mxL
0930: 65 6e 3b 0a 20 20 69 6e 74 20 6e 43 6f 6c 2c 20  en;.  int nCol, 
0940: 6e 52 6f 77 3b 0a 20 20 69 6e 74 20 63 6e 74 2c  nRow;.  int cnt,
0950: 20 69 3b 0a 20 20 63 68 61 72 20 2a 7a 50 72 65   i;.  char *zPre
0960: 66 69 78 3b 0a 20 20 53 74 6d 74 20 71 3b 0a 0a  fix;.  Stmt q;..
0970: 20 20 6c 6f 67 69 6e 5f 63 68 65 63 6b 5f 63 72    login_check_cr
0980: 65 64 65 6e 74 69 61 6c 73 28 29 3b 0a 20 20 69  edentials();.  i
0990: 66 28 20 21 67 2e 6f 6b 48 69 73 74 6f 72 79 20  f( !g.okHistory 
09a0: 29 7b 20 6c 6f 67 69 6e 5f 6e 65 65 64 65 64 28  ){ login_needed(
09b0: 29 3b 20 72 65 74 75 72 6e 3b 20 7d 0a 20 20 73  ); return; }.  s
09c0: 74 79 6c 65 5f 68 65 61 64 65 72 28 22 46 69 6c  tyle_header("Fil
09d0: 65 20 4c 69 73 74 22 29 3b 0a 20 20 73 71 6c 69  e List");.  sqli
09e0: 74 65 33 5f 63 72 65 61 74 65 5f 66 75 6e 63 74  te3_create_funct
09f0: 69 6f 6e 28 67 2e 64 62 2c 20 22 70 61 74 68 65  ion(g.db, "pathe
0a00: 6c 65 6d 65 6e 74 22 2c 20 32 2c 20 53 51 4c 49  lement", 2, SQLI
0a10: 54 45 5f 55 54 46 38 2c 20 30 2c 0a 20 20 20 20  TE_UTF8, 0,.    
0a20: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
0a30: 20 20 20 20 20 20 70 61 74 68 65 6c 65 6d 65 6e        pathelemen
0a40: 74 46 75 6e 63 2c 20 30 2c 20 30 29 3b 0a 0a 20  tFunc, 0, 0);.. 
0a50: 20 2f 2a 20 49 66 20 74 68 65 20 6e 61 6d 65 3d   /* If the name=
0a60: 20 70 61 72 61 6d 65 74 65 72 20 69 73 20 61 6e   parameter is an
0a70: 20 65 6d 70 74 79 20 73 74 72 69 6e 67 2c 20 6d   empty string, m
0a80: 61 6b 65 20 69 74 20 61 20 4e 55 4c 4c 20 70 6f  ake it a NULL po
0a90: 69 6e 74 65 72 20 2a 2f 0a 20 20 69 66 28 20 7a  inter */.  if( z
0aa0: 44 20 26 26 20 73 74 72 6c 65 6e 28 7a 44 29 3d  D && strlen(zD)=
0ab0: 3d 30 20 29 7b 20 7a 44 20 3d 20 30 3b 20 7d 0a  =0 ){ zD = 0; }.
0ac0: 0a 20 20 2f 2a 20 43 6f 6d 70 75 74 65 20 74 68  .  /* Compute th
0ad0: 65 20 74 69 74 6c 65 20 6f 66 20 74 68 65 20 70  e title of the p
0ae0: 61 67 65 20 2a 2f 20 20 0a 20 20 69 66 28 20 7a  age */  .  if( z
0af0: 44 20 29 7b 0a 20 20 20 20 69 6e 74 20 69 2c 20  D ){.    int i, 
0b00: 6a 3b 0a 20 20 20 20 63 68 61 72 20 2a 7a 43 6f  j;.    char *zCo
0b10: 70 79 3b 0a 20 20 20 20 42 6c 6f 62 20 74 69 74  py;.    Blob tit
0b20: 6c 65 3b 0a 0a 20 20 20 20 62 6c 6f 62 5f 7a 65  le;..    blob_ze
0b30: 72 6f 28 26 74 69 74 6c 65 29 3b 0a 20 20 20 20  ro(&title);.    
0b40: 7a 43 6f 70 79 20 3d 20 73 71 6c 69 74 65 33 5f  zCopy = sqlite3_
0b50: 6d 70 72 69 6e 74 66 28 22 25 73 2f 22 2c 20 7a  mprintf("%s/", z
0b60: 44 29 3b 0a 20 20 20 20 62 6c 6f 62 5f 61 70 70  D);.    blob_app
0b70: 65 6e 64 66 28 26 74 69 74 6c 65 2c 0a 20 20 20  endf(&title,.   
0b80: 20 20 20 20 22 46 69 6c 65 73 20 69 6e 20 64 69      "Files in di
0b90: 72 65 63 74 6f 72 79 20 3c 61 20 68 72 65 66 3d  rectory <a href=
0ba0: 5c 22 25 73 2f 64 69 72 5c 22 3e 3c 69 3e 72 6f  \"%s/dir\"><i>ro
0bb0: 6f 74 3c 2f 69 3e 3c 2f 61 3e 22 2c 0a 20 20 20  ot</i></a>",.   
0bc0: 20 20 20 20 67 2e 7a 42 61 73 65 55 52 4c 0a 20      g.zBaseURL. 
0bd0: 20 20 20 29 3b 0a 20 20 20 20 66 6f 72 28 69 3d     );.    for(i=
0be0: 30 3b 20 7a 44 5b 69 5d 3b 20 69 3d 6a 29 7b 0a  0; zD[i]; i=j){.
0bf0: 20 20 20 20 20 20 66 6f 72 28 6a 3d 69 3b 20 7a        for(j=i; z
0c00: 44 5b 6a 5d 20 26 26 20 7a 44 5b 6a 5d 21 3d 27  D[j] && zD[j]!='
0c10: 2f 27 3b 20 6a 2b 2b 29 7b 7d 0a 20 20 20 20 20  /'; j++){}.     
0c20: 20 69 66 28 20 7a 44 5b 6a 5d 20 29 7b 0a 20 20   if( zD[j] ){.  
0c30: 20 20 20 20 20 20 7a 43 6f 70 79 5b 6a 5d 20 3d        zCopy[j] =
0c40: 20 30 3b 0a 20 20 20 20 20 20 20 20 62 6c 6f 62   0;.        blob
0c50: 5f 61 70 70 65 6e 64 66 28 26 74 69 74 6c 65 2c  _appendf(&title,
0c60: 20 22 2f 3c 61 20 68 72 65 66 3d 5c 22 25 73 2f   "/<a href=\"%s/
0c70: 64 69 72 3f 6e 61 6d 65 3d 25 54 5c 22 3e 25 68  dir?name=%T\">%h
0c80: 3c 2f 61 3e 22 2c 20 0a 20 20 20 20 20 20 20 20  </a>", .        
0c90: 20 20 20 20 20 20 20 20 20 20 20 20 20 67 2e 7a               g.z
0ca0: 42 61 73 65 55 52 4c 2c 20 7a 43 6f 70 79 2c 20  BaseURL, zCopy, 
0cb0: 26 7a 43 6f 70 79 5b 69 5d 29 3b 0a 20 20 20 20  &zCopy[i]);.    
0cc0: 20 20 20 20 7a 43 6f 70 79 5b 6a 5d 20 3d 20 27      zCopy[j] = '
0cd0: 2f 27 3b 0a 20 20 20 20 20 20 7d 65 6c 73 65 7b  /';.      }else{
0ce0: 0a 20 20 20 20 20 20 20 20 62 6c 6f 62 5f 61 70  .        blob_ap
0cf0: 70 65 6e 64 66 28 26 74 69 74 6c 65 2c 20 22 2f  pendf(&title, "/
0d00: 25 68 22 2c 20 26 7a 43 6f 70 79 5b 69 5d 29 3b  %h", &zCopy[i]);
0d10: 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 20 20 77  .      }.      w
0d20: 68 69 6c 65 28 20 7a 44 5b 6a 5d 3d 3d 27 2f 27  hile( zD[j]=='/'
0d30: 20 29 7b 20 6a 2b 2b 3b 20 7d 0a 20 20 20 20 7d   ){ j++; }.    }
0d40: 0a 20 20 20 20 40 20 3c 68 32 3e 25 73 28 62 6c  .    @ <h2>%s(bl
0d50: 6f 62 5f 73 74 72 28 26 74 69 74 6c 65 29 29 3c  ob_str(&title))<
0d60: 2f 68 32 3e 0a 20 20 20 20 62 6c 6f 62 5f 72 65  /h2>.    blob_re
0d70: 73 65 74 28 26 74 69 74 6c 65 29 3b 0a 20 20 20  set(&title);.   
0d80: 20 7a 50 72 65 66 69 78 20 3d 20 7a 43 6f 70 79   zPrefix = zCopy
0d90: 3b 0a 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 40  ;.  }else{.    @
0da0: 20 3c 68 32 3e 46 69 6c 65 73 20 69 6e 20 74 68   <h2>Files in th
0db0: 65 20 74 6f 70 2d 6c 65 76 65 6c 20 64 69 72 65  e top-level dire
0dc0: 63 74 6f 72 79 3c 2f 68 32 3e 0a 20 20 20 20 7a  ctory</h2>.    z
0dd0: 50 72 65 66 69 78 20 3d 20 22 22 3b 0a 20 20 7d  Prefix = "";.  }
0de0: 0a 0a 20 20 2f 2a 20 43 6f 6d 70 75 74 65 20 74  ..  /* Compute t
0df0: 68 65 20 74 65 6d 70 6f 72 61 72 79 20 74 61 62  he temporary tab
0e00: 6c 65 20 22 6c 6f 63 61 6c 66 69 6c 65 73 22 20  le "localfiles" 
0e10: 63 6f 6e 74 61 69 6e 69 6e 67 20 74 68 65 20 6e  containing the n
0e20: 61 6d 65 73 0a 20 20 2a 2a 20 6f 66 20 61 6c 6c  ames.  ** of all
0e30: 20 66 69 6c 65 73 20 61 6e 64 20 73 75 62 64 69   files and subdi
0e40: 72 65 63 74 6f 72 69 65 73 20 69 6e 20 74 68 65  rectories in the
0e50: 20 7a 44 5b 5d 20 64 69 72 65 63 74 6f 72 79 2e   zD[] directory.
0e60: 20 20 0a 20 20 2a 2a 0a 20 20 2a 2a 20 53 75 62    .  **.  ** Sub
0e70: 64 69 72 65 63 74 6f 72 79 20 6e 61 6d 65 73 20  directory names 
0e80: 62 65 67 69 6e 20 77 69 74 68 20 22 2f 22 2e 20  begin with "/". 
0e90: 20 54 68 69 73 20 63 61 75 73 65 73 20 74 68 65   This causes the
0ea0: 6d 20 74 6f 20 73 6f 72 74 0a 20 20 2a 2a 20 66  m to sort.  ** f
0eb0: 69 72 73 74 20 61 6e 64 20 69 74 20 61 6c 73 6f  irst and it also
0ec0: 20 67 69 76 65 73 20 75 73 20 61 6e 20 65 61 73   gives us an eas
0ed0: 79 20 77 61 79 20 74 6f 20 64 69 73 74 69 6e 67  y way to disting
0ee0: 75 69 73 68 20 66 69 6c 65 73 0a 20 20 2a 2a 20  uish files.  ** 
0ef0: 66 72 6f 6d 20 64 69 72 65 63 74 6f 72 69 65 73  from directories
0f00: 20 69 6e 20 74 68 65 20 6c 6f 6f 70 20 74 68 61   in the loop tha
0f10: 74 20 66 6f 6c 6c 6f 77 73 2e 0a 20 20 2a 2f 0a  t follows..  */.
0f20: 20 20 69 66 28 20 7a 44 20 29 7b 0a 20 20 20 20    if( zD ){.    
0f30: 64 62 5f 6d 75 6c 74 69 5f 65 78 65 63 28 0a 20  db_multi_exec(. 
0f40: 20 20 20 20 20 20 22 43 52 45 41 54 45 20 54 45        "CREATE TE
0f50: 4d 50 20 54 41 42 4c 45 20 6c 6f 63 61 6c 66 69  MP TABLE localfi
0f60: 6c 65 73 28 78 20 55 4e 49 51 55 45 20 4e 4f 54  les(x UNIQUE NOT
0f70: 20 4e 55 4c 4c 29 3b 22 0a 20 20 20 20 20 20 20   NULL);".       
0f80: 22 49 4e 53 45 52 54 20 4f 52 20 49 47 4e 4f 52  "INSERT OR IGNOR
0f90: 45 20 49 4e 54 4f 20 6c 6f 63 61 6c 66 69 6c 65  E INTO localfile
0fa0: 73 20 22 0a 20 20 20 20 20 20 20 22 20 20 53 45  s ".       "  SE
0fb0: 4c 45 43 54 20 70 61 74 68 65 6c 65 6d 65 6e 74  LECT pathelement
0fc0: 28 6e 61 6d 65 2c 25 64 29 20 46 52 4f 4d 20 66  (name,%d) FROM f
0fd0: 69 6c 65 6e 61 6d 65 22 0a 20 20 20 20 20 20 20  ilename".       
0fe0: 22 20 20 20 57 48 45 52 45 20 2b 6e 61 6d 65 20  "   WHERE +name 
0ff0: 47 4c 4f 42 20 27 25 71 2f 2a 27 22 2c 0a 20 20  GLOB '%q/*'",.  
1000: 20 20 20 20 20 73 74 72 6c 65 6e 28 7a 44 29 2b       strlen(zD)+
1010: 31 2c 20 7a 44 0a 20 20 20 20 29 3b 0a 20 20 7d  1, zD.    );.  }
1020: 65 6c 73 65 7b 0a 20 20 20 20 64 62 5f 6d 75 6c  else{.    db_mul
1030: 74 69 5f 65 78 65 63 28 0a 20 20 20 20 20 20 20  ti_exec(.       
1040: 22 43 52 45 41 54 45 20 54 45 4d 50 20 54 41 42  "CREATE TEMP TAB
1050: 4c 45 20 6c 6f 63 61 6c 66 69 6c 65 73 28 78 20  LE localfiles(x 
1060: 55 4e 49 51 55 45 20 4e 4f 54 20 4e 55 4c 4c 29  UNIQUE NOT NULL)
1070: 3b 22 0a 20 20 20 20 20 20 20 22 49 4e 53 45 52  ;".       "INSER
1080: 54 20 4f 52 20 49 47 4e 4f 52 45 20 49 4e 54 4f  T OR IGNORE INTO
1090: 20 6c 6f 63 61 6c 66 69 6c 65 73 20 22 0a 20 20   localfiles ".  
10a0: 20 20 20 20 20 22 20 20 53 45 4c 45 43 54 20 70       "  SELECT p
10b0: 61 74 68 65 6c 65 6d 65 6e 74 28 6e 61 6d 65 2c  athelement(name,
10c0: 30 29 20 46 52 4f 4d 20 66 69 6c 65 6e 61 6d 65  0) FROM filename
10d0: 22 0a 20 20 20 20 29 3b 0a 20 20 7d 0a 0a 20 20  ".    );.  }..  
10e0: 2f 2a 20 47 65 6e 65 72 61 74 65 20 61 20 6d 75  /* Generate a mu
10f0: 6c 74 69 2d 63 6f 6c 75 6d 6e 20 74 61 62 6c 65  lti-column table
1100: 20 6c 69 73 74 69 6e 67 20 74 68 65 20 63 6f 6e   listing the con
1110: 74 65 6e 74 73 20 6f 66 20 7a 44 5b 5d 0a 20 20  tents of zD[].  
1120: 2a 2a 20 64 69 72 65 63 74 6f 72 79 2e 0a 20 20  ** directory..  
1130: 2a 2f 0a 20 20 6d 78 4c 65 6e 20 3d 20 64 62 5f  */.  mxLen = db_
1140: 69 6e 74 28 31 32 2c 20 22 53 45 4c 45 43 54 20  int(12, "SELECT 
1150: 6d 61 78 28 6c 65 6e 67 74 68 28 78 29 29 20 46  max(length(x)) F
1160: 52 4f 4d 20 6c 6f 63 61 6c 66 69 6c 65 73 22 29  ROM localfiles")
1170: 3b 0a 20 20 63 6e 74 20 3d 20 64 62 5f 69 6e 74  ;.  cnt = db_int
1180: 28 30 2c 20 22 53 45 4c 45 43 54 20 63 6f 75 6e  (0, "SELECT coun
1190: 74 28 2a 29 20 46 52 4f 4d 20 6c 6f 63 61 6c 66  t(*) FROM localf
11a0: 69 6c 65 73 22 29 3b 0a 20 20 6e 43 6f 6c 20 3d  iles");.  nCol =
11b0: 20 34 3b 0a 20 20 6e 52 6f 77 20 3d 20 28 63 6e   4;.  nRow = (cn
11c0: 74 2b 6e 43 6f 6c 2d 31 29 2f 6e 43 6f 6c 3b 0a  t+nCol-1)/nCol;.
11d0: 20 20 64 62 5f 70 72 65 70 61 72 65 28 26 71 2c    db_prepare(&q,
11e0: 20 22 53 45 4c 45 43 54 20 78 20 46 52 4f 4d 20   "SELECT x FROM 
11f0: 6c 6f 63 61 6c 66 69 6c 65 73 20 4f 52 44 45 52  localfiles ORDER
1200: 20 42 59 20 78 22 29 3b 0a 20 20 40 20 3c 74 61   BY x");.  @ <ta
1210: 62 6c 65 20 62 6f 72 64 65 72 3d 22 30 22 20 77  ble border="0" w
1220: 69 64 74 68 3d 22 31 30 30 25 25 22 3e 3c 74 72  idth="100%%"><tr
1230: 3e 3c 74 64 20 76 61 6c 69 67 6e 3d 22 74 6f 70  ><td valign="top
1240: 22 20 77 69 64 74 68 3d 22 32 35 25 25 22 3e 0a  " width="25%%">.
1250: 20 20 69 20 3d 20 30 3b 0a 20 20 77 68 69 6c 65    i = 0;.  while
1260: 28 20 64 62 5f 73 74 65 70 28 26 71 29 3d 3d 53  ( db_step(&q)==S
1270: 51 4c 49 54 45 5f 52 4f 57 20 29 7b 0a 20 20 20  QLITE_ROW ){.   
1280: 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 46 4e   const char *zFN
1290: 61 6d 65 3b 0a 20 20 20 20 69 66 28 20 69 3d 3d  ame;.    if( i==
12a0: 6e 52 6f 77 20 29 7b 0a 20 20 20 20 20 20 40 20  nRow ){.      @ 
12b0: 3c 2f 74 64 3e 3c 74 64 20 76 61 6c 69 67 6e 3d  </td><td valign=
12c0: 22 74 6f 70 22 20 77 69 64 74 68 3d 22 32 35 25  "top" width="25%
12d0: 25 22 3e 0a 20 20 20 20 20 20 69 20 3d 20 30 3b  %">.      i = 0;
12e0: 0a 20 20 20 20 7d 0a 20 20 20 20 69 2b 2b 3b 0a  .    }.    i++;.
12f0: 20 20 20 20 7a 46 4e 61 6d 65 20 3d 20 64 62 5f      zFName = db_
1300: 63 6f 6c 75 6d 6e 5f 74 65 78 74 28 26 71 2c 20  column_text(&q, 
1310: 30 29 3b 0a 20 20 20 20 69 66 28 20 7a 46 4e 61  0);.    if( zFNa
1320: 6d 65 5b 30 5d 3d 3d 27 2f 27 20 29 7b 0a 20 20  me[0]=='/' ){.  
1330: 20 20 20 20 7a 46 4e 61 6d 65 2b 2b 3b 0a 20 20      zFName++;.  
1340: 20 20 20 20 40 20 3c 6c 69 3e 3c 61 20 68 72 65      @ <li><a hre
1350: 66 3d 22 25 73 28 67 2e 7a 42 61 73 65 55 52 4c  f="%s(g.zBaseURL
1360: 29 2f 64 69 72 3f 6e 61 6d 65 3d 25 54 28 7a 50  )/dir?name=%T(zP
1370: 72 65 66 69 78 29 25 54 28 7a 46 4e 61 6d 65 29  refix)%T(zFName)
1380: 22 3e 0a 20 20 20 20 20 20 40 20 20 20 20 20 25  ">.      @     %
1390: 68 28 7a 46 4e 61 6d 65 29 2f 3c 2f 61 3e 3c 2f  h(zFName)/</a></
13a0: 6c 69 3e 0a 20 20 20 20 7d 65 6c 73 65 7b 0a 20  li>.    }else{. 
13b0: 20 20 20 20 20 40 20 3c 6c 69 3e 3c 61 20 68 72       @ <li><a hr
13c0: 65 66 3d 22 25 73 28 67 2e 7a 42 61 73 65 55 52  ef="%s(g.zBaseUR
13d0: 4c 29 2f 66 69 6e 66 6f 3f 6e 61 6d 65 3d 25 54  L)/finfo?name=%T
13e0: 28 7a 50 72 65 66 69 78 29 25 54 28 7a 46 4e 61  (zPrefix)%T(zFNa
13f0: 6d 65 29 22 3e 0a 20 20 20 20 20 20 40 20 20 20  me)">.      @   
1400: 20 20 25 68 28 7a 46 4e 61 6d 65 29 3c 2f 61 3e    %h(zFName)</a>
1410: 3c 2f 6c 69 3e 0a 20 20 20 20 7d 0a 20 20 7d 0a  </li>.    }.  }.
1420: 20 20 64 62 5f 66 69 6e 61 6c 69 7a 65 28 26 71    db_finalize(&q
1430: 29 3b 0a 20 20 40 20 3c 2f 74 64 3e 3c 2f 74 72  );.  @ </td></tr
1440: 3e 3c 2f 74 61 62 6c 65 3e 0a 20 20 73 74 79 6c  ></table>.  styl
1450: 65 5f 66 6f 6f 74 65 72 28 29 3b 0a 7d 0a        e_footer();.}.